|
@@ -0,0 +1,876 @@
|
|
|
+function report_payslip_egreso(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportPayslipEgresoWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportPayslipEgreso',
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+ modules: ['hr'],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-store' : 'updateJournalSelections',
|
|
|
+ 'change #current-date' : 'ShowDateRange',
|
|
|
+ 'click .print-report':'clickOnAction',
|
|
|
+ },
|
|
|
+
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ var date = new model.eiru_reports.ReportDatePickerWidget(self);
|
|
|
+ date.fecthFecha();
|
|
|
+ this.fetchInitial();
|
|
|
+ },
|
|
|
+
|
|
|
+ checkModel : function(model){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.IrModuleModule,function(item){
|
|
|
+ return item.name === model;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor = "";
|
|
|
+ if (dato){
|
|
|
+ valor = dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ ShowDateRange : function(){
|
|
|
+ var self = this;
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ if(date == 'range'){
|
|
|
+ self.$el.find('.datepicker').css('display','block');
|
|
|
+ }
|
|
|
+ if(date != 'range'){
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function() {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function(IrModuleModule) {
|
|
|
+ return IrModuleModule;
|
|
|
+ }).then(function(IrModuleModule) {
|
|
|
+ self.IrModuleModule = IrModuleModule;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function(ResCompany) {
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
+ if (ResCompany.length > 1) {
|
|
|
+ self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
|
|
|
+ _.each(ResCompany, function(item) {
|
|
|
+ self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.company').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchResStore();
|
|
|
+ }).then(function(ResStore) {
|
|
|
+ self.ResStore = ResStore;
|
|
|
+ if (ResStore.length > 1) {
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(ResStore, function(item) {
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.store').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchHrEmployee();
|
|
|
+ }).then(function(HrEmployee) {
|
|
|
+ self.HrEmployee = HrEmployee;
|
|
|
+ if (HrEmployee.length > 1) {
|
|
|
+ self.$el.find('#current-employee').append('<option value="9999999">Todos los funcionarios</option>');
|
|
|
+ _.each(HrEmployee, function(item) {
|
|
|
+ self.$el.find('#current-employee').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.employee').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchHrPayrollStructure();
|
|
|
+ }).then(function(HrPayrollStructure) {
|
|
|
+ self.HrPayrollStructure = HrPayrollStructure;
|
|
|
+ if (HrPayrollStructure.length > 1) {
|
|
|
+ self.$el.find('#current-structure').append('<option value="9999999">Todos los tipos</option>');
|
|
|
+ _.each(HrPayrollStructure, function(item) {
|
|
|
+ self.$el.find('#current-structure').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.structure').css('display', 'none');
|
|
|
+ }
|
|
|
+ // return self.fetchAccountPeriod();
|
|
|
+ // }).then(function(AccountPeriod){
|
|
|
+ // self.AccountPeriod = AccountPeriod;
|
|
|
+ // if (AccountPeriod.length > 1) {
|
|
|
+ // self.$el.find('#current-period').append('<option value="9999999">Todos los períodos</option>');
|
|
|
+ // _.each(AccountPeriod, function(item) {
|
|
|
+ // self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // self.$el.find('.period').css('display', 'none');
|
|
|
+ // }
|
|
|
+ return self.fetchAccountVoucher();
|
|
|
+ }).then(function (AccountVoucher) {
|
|
|
+ self.AccountVoucher = AccountVoucher;
|
|
|
+ return self.fetchAccountInvoice();
|
|
|
+ }).then(function(AccountInvoice){
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fetchAccountJournal();
|
|
|
+ }).then(function (AccountJournal) {
|
|
|
+ self.AccountJournal =AccountJournal;
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todos los pagos</option>');
|
|
|
+ _.each(AccountJournal, function (item) {
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fetchHrPayslipLine();
|
|
|
+ }).then(function(HrPayslipLine) {
|
|
|
+ self.HrPayslipLine = HrPayslipLine;
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency) {
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ });
|
|
|
+ self.$el.find('#generate').css('display', 'inline');
|
|
|
+ return;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchGenerate: function() {
|
|
|
+ var self = this;
|
|
|
+ self.$el.find('.search-form').block({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$el.find('.report-form').block({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.fetchHrPayslip().then(function(HrPayslip){
|
|
|
+ return HrPayslip;
|
|
|
+ }).then(function(HrPayslip){
|
|
|
+ self.HrPayslip = HrPayslip;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthIrModuleModule: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['name', 'id'];
|
|
|
+ var domain = [
|
|
|
+ ['state', '=', 'installed'],
|
|
|
+ ['name', 'in', self.modules]
|
|
|
+ ];
|
|
|
+ var IrModuleModule = new model.web.Model('ir.module.module');
|
|
|
+ IrModuleModule.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ })
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getAmount: function(line_ids, code) {
|
|
|
+ var self = this;
|
|
|
+ var amount = 0;
|
|
|
+ amount = _.map(_.filter(self.HrPayslipLine, function(a) {
|
|
|
+ return _.find(line_ids, function(b) {
|
|
|
+ return b === a.id && a.code == code;
|
|
|
+ });
|
|
|
+ }), function(map) {
|
|
|
+ return map.total;
|
|
|
+ });
|
|
|
+
|
|
|
+ if(amount.length == 0){
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return amount[0];
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchResCompany: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new model.web.Model('res.company');
|
|
|
+ var field = ['id', 'name', 'currency_id', 'logo'];
|
|
|
+ currency.query(field).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // fetchIntialSQL: function() {
|
|
|
+ // var self = this;
|
|
|
+ // var data = $.get('/report-filter-data');
|
|
|
+ // return data;
|
|
|
+ // },
|
|
|
+ //
|
|
|
+ // fetchDataSQL: function() {
|
|
|
+ // var self = this;
|
|
|
+ // var data = $.get('/report-supplier-account-voucher');
|
|
|
+ // return data;
|
|
|
+ // },
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ UPDATE SELECTIONS
|
|
|
+ ====================================================================*/
|
|
|
+ updateSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var store;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ if(company != 9999999){
|
|
|
+ store = self.$el.find('#current-store').empty();
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ store = self.$el.find('#current-store').empty();
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateJournalSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var journal;
|
|
|
+ var AccountJournal = _.flatten(_.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.type == 'cash' || item.type == 'bank';
|
|
|
+ }));
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ if(store != 9999999){
|
|
|
+ self.$el.find('#current-journal').empty();
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todos los métodos de pago</option>');
|
|
|
+ _.each(AccountJournal,function(item){
|
|
|
+ if(item.store_id == store){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ journal = self.$el.find('#current-journal').empty();
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todos los métodos de pago</option>');
|
|
|
+ _.each(AccountJournal,function(item){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountVoucher:function(number) {
|
|
|
+ var self = this;
|
|
|
+ var content = self.AccountVoucher;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+
|
|
|
+ content = _.filter(content,function (item) {
|
|
|
+ return item.reference == number;
|
|
|
+ })
|
|
|
+
|
|
|
+ if((store && store == 9999999)||(company && company == 9999999)){
|
|
|
+ var store_ids = _.flatten(_.map(self.ResStore, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.company_id == company;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(store && store != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.store_id == store;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.journal_id == journal;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date && date != 9999999){
|
|
|
+ if(date == 'range'){
|
|
|
+ if(desde){
|
|
|
+ date = desde.split('/');
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') >= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(hasta){
|
|
|
+ date = hasta.split('/');
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') <= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') === today;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date).format('YYYY-MM-DD') === yesterday;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date).format('YYYY-MM') === currentMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date).format('YYYY-MM') === lastMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountVoucher: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var AccountVoucher = new model.web.Model('account.voucher');
|
|
|
+ AccountVoucher.query(['id', 'number','reference','partner_id','journal_id','amount','date','number','type']).filter([['state', '=', 'posted']]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ // fetchAccountInvoice: function () {
|
|
|
+ // var self = this;
|
|
|
+ // var defer = $.Deferred();
|
|
|
+ // var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ // AccountInvoice.query(['id','number']).filter(['type', '=', 'out_invoice'],[['state', 'in', ['open','paid']]]).all().then(function(results){
|
|
|
+ // defer.resolve(results);
|
|
|
+ // });
|
|
|
+ // return defer;
|
|
|
+ // },
|
|
|
+
|
|
|
+ // Invoice (FACTURAS)
|
|
|
+ fetchAccountInvoice: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var filter =[['state', 'in',['open','paid']],['type', '=', 'in_invoice']];
|
|
|
+
|
|
|
+ var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice'];
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ AccountInvoice.query(field).filter(filter).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCompany: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCompany, function(item) {
|
|
|
+ return item.id == id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResStore: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var store = new model.web.Model('res.store');
|
|
|
+ var field = ['id', 'name', 'company_id'];
|
|
|
+ store.query(field).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCurrency: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
+ var domain = [
|
|
|
+ ['active', '=', true]
|
|
|
+ ];
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCurrency: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency, function(item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchHrEmployee: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var employee = new model.web.Model('hr.employee');
|
|
|
+ var field = ['id', 'name','store_id'];
|
|
|
+ employee.query(field).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountJournal: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
+ AccountJournal.query(['id','name']).filter([['active','=',true],['type', 'in', ['bank','cash']]]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchHrPayrollStructure: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var structure = new model.web.Model('hr.payroll.structure');
|
|
|
+ var field = ['id', 'name'];
|
|
|
+ structure.query(field).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchHrPayslipLine: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var line = new model.web.Model('hr.payslip.line');
|
|
|
+ var domain = [
|
|
|
+ ['code', '=', "NET"]
|
|
|
+ ];
|
|
|
+
|
|
|
+ var field = ['id', 'name', 'code', 'slip_id', 'total'];
|
|
|
+ line.query(field).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchHrPayslip: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+ var domain = [['state', 'in', ['done','paid']]];
|
|
|
+
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ domain.push(['company_id', '=', parseInt(company)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (store && store != 9999999) {
|
|
|
+ domain.push(['employee_id.store_id', '=', parseInt(store)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state && state != 9999999) {
|
|
|
+ domain.push(['state', '=', state]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (period && period != 9999999){
|
|
|
+ domain.push(['period_id','=', parseInt(period)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var fields = [
|
|
|
+ 'id',
|
|
|
+ 'employee_id',
|
|
|
+ 'name',
|
|
|
+ 'number',
|
|
|
+ 'date_to',
|
|
|
+ 'contract_id',
|
|
|
+ 'struct_id',
|
|
|
+ 'state',
|
|
|
+ 'line_ids',
|
|
|
+ ];
|
|
|
+ var HrPayslip = new model.web.Model('hr.payslip');
|
|
|
+ HrPayslip.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getHrPayslip:function(id) {
|
|
|
+ var self = this;
|
|
|
+ var content = self.HrPayslip;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+
|
|
|
+ content = _.filter(content,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ })
|
|
|
+
|
|
|
+ if((store && store == 9999999)||(company && company == 9999999)){
|
|
|
+ var store_ids = _.flatten(_.map(self.ResStore, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.company_id == company;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(store && store != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.store_id == store;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.journal_id == journal;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date && date != 9999999){
|
|
|
+ if(date == 'range'){
|
|
|
+ if(desde){
|
|
|
+ date = desde.split('/');
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date_to).format('YYYY-MM-DD') >= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(hasta){
|
|
|
+ date = hasta.split('/');
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date_to).format('YYYY-MM-DD') <= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date_to).format('YYYY-MM-DD') === today;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date_to).format('YYYY-MM-DD') === yesterday;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date_to).format('YYYY-MM') === currentMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return moment(inv.date_to).format('YYYY-MM') === lastMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ // getHrPayslip: function (id){
|
|
|
+ // return _.find(this.HrPayslip, function (inv) {
|
|
|
+ // return _.contains(inv.id, id);
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ var data = [];
|
|
|
+
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
+
|
|
|
+ var AccountInvoice = self.AccountInvoice;
|
|
|
+
|
|
|
+
|
|
|
+ _.each(AccountInvoice, function(each){
|
|
|
+
|
|
|
+ var AccountVoucher = self.getAccountVoucher(each.number);
|
|
|
+
|
|
|
+ _.each(AccountVoucher, function(item){
|
|
|
+
|
|
|
+ var amount = item.amount;
|
|
|
+ if(item.currency_id != null){
|
|
|
+ amount = amount + '(' + item.amount + ')';
|
|
|
+ }
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ id:item.id,
|
|
|
+ date:moment(item.date).format('DD/MM/YYYY'),
|
|
|
+ name:item.reference,
|
|
|
+ // reference:item.reference,
|
|
|
+ total:accounting.formatMoney(amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ /*
|
|
|
+ =======================
|
|
|
+ NO FORMAT
|
|
|
+ =======================
|
|
|
+ */
|
|
|
+ date_no_format: moment(item.date).format('YYYY-MM-DD'),
|
|
|
+ total_no_format:item.amount,
|
|
|
+ /*
|
|
|
+ =======================
|
|
|
+ FOOTER
|
|
|
+ =======================
|
|
|
+ */
|
|
|
+ decimal_places:CurrencyBase.decimal_places,
|
|
|
+ thousands_separator:CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator:CurrencyBase.decimal_separator,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ var HrPayslipline = self.HrPayslipLine;
|
|
|
+
|
|
|
+ var total_neto = 0;
|
|
|
+
|
|
|
+
|
|
|
+ _.each(HrPayslipline, function(item) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // console.log(item);
|
|
|
+
|
|
|
+ var hrpayslip = self.getHrPayslip(item.slip_id[0]);
|
|
|
+
|
|
|
+ _.each(hrpayslip, function(index) {
|
|
|
+
|
|
|
+ if (hrpayslip.state == 'done') {
|
|
|
+ var state = 'Hecho';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hrpayslip.state == 'paid') {
|
|
|
+ var state = 'Pagado';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ id:item.id,
|
|
|
+ name: item.slip_id[1],
|
|
|
+ date: moment(index.date_to).format("DD/MM/YYYY"),
|
|
|
+ date_no_format: index.date_to,
|
|
|
+ total : accounting.formatMoney(item.total,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ total_no_format : item.total,
|
|
|
+
|
|
|
+ decimal_places:CurrencyBase.decimal_places,
|
|
|
+ thousands_separator:CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator:CurrencyBase.decimal_separator,
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ data.sort(function (a, b) {
|
|
|
+ if (a.date_no_format > b.date_no_format) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (a.date_no_format < b.date_no_format) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+ self.content = data;
|
|
|
+ self.loadTable(data);
|
|
|
+ self.$el.find('.report-form').css('display','block');
|
|
|
+ self.$el.find('.search-form').unblock();
|
|
|
+ self.$el.find('.report-form').unblock();
|
|
|
+ },
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var ResCompany;
|
|
|
+ var CurrencyBase;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ var ResCompany = self.getResCompany(company).shift();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ var ResCompany = self.ResCompany[0];
|
|
|
+ }
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var column = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var row = table.bootstrapTable('getData');
|
|
|
+
|
|
|
+ var total = TotalFooter(row);
|
|
|
+ // var total = totalFormatter(row);
|
|
|
+ row.push({
|
|
|
+ date:'Totales',
|
|
|
+ total:total,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var data = _.map(column, function (val){
|
|
|
+ return val.field;
|
|
|
+ });
|
|
|
+ _.each(_.map(column,function(val){
|
|
|
+ return val;
|
|
|
+ }), function(item){
|
|
|
+ getColumns.push([{
|
|
|
+ title: item.title,
|
|
|
+ dataKey: item.field
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ CONFIGURACION DEL PDF
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var pdf_title = 'Egresos con egresos y nóminas.';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'egresosconegresosynominas';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ date:{columnWidth: 20, halign:'center'},
|
|
|
+ name:{columnWidth: 'auto', halign:'center'},
|
|
|
+ total:{columnWidth: 20, halign:'right'},
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var filter = self.getFilter();
|
|
|
+ var pdf = new model.eiru_reports.ReportPdfWidget(self);
|
|
|
+ pdf.drawPDF(
|
|
|
+ _.flatten(getColumns),
|
|
|
+ row,
|
|
|
+ ResCompany,
|
|
|
+ pdf_title,
|
|
|
+ pdf_type,
|
|
|
+ pdf_name,
|
|
|
+ pdf_columnStyles,
|
|
|
+ filter
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getFilter: function(){
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+ var filter = [];
|
|
|
+ if(company && company != 9999999){
|
|
|
+ var ResCompany = _.filter(self.ResCompany, function(item){
|
|
|
+ return item.id == company;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title:'Empresa',
|
|
|
+ value: ResCompany[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(store && store != 9999999){
|
|
|
+ var ResStore = _.filter(self.ResStore,function (item) {
|
|
|
+ return item.id == store;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Sucursal',
|
|
|
+ value: ResStore[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ var AccountJournal = _.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.id == journal;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Método de pago',
|
|
|
+ value: AccountJournal[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(date && date != 9999999){
|
|
|
+ moment.locale('es', {
|
|
|
+ months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
|
|
|
+ });
|
|
|
+
|
|
|
+ if(date == 'range'){
|
|
|
+ filter.push({
|
|
|
+ title: 'Fecha',
|
|
|
+ value: desde +' al '+hasta,
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ var fecha;
|
|
|
+ if(date == 'today'){
|
|
|
+ fecha = moment().format('DD/MM/YYYY');
|
|
|
+ }
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ fecha = moment().add(-1,'days').format('DD/MM/YYYY');
|
|
|
+ }
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ fecha = moment().format('MMMM/YYYY');
|
|
|
+ }
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ fecha = moment().add(-1,'months').format('MMMM/YYYY');
|
|
|
+ }
|
|
|
+ filter.push({
|
|
|
+ title: 'Fecha',
|
|
|
+ value: fecha,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|