|
@@ -0,0 +1,620 @@
|
|
|
+function report_salesman_commission(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportSalesmanCommissionWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportSalesmanCommissionWidget',
|
|
|
+ rowsData: [],
|
|
|
+ content: [],
|
|
|
+
|
|
|
+ events: {
|
|
|
+ 'click #toolbar > button': 'clickOnAction',
|
|
|
+ 'click #generate': 'fetchGenerate',
|
|
|
+ 'change #current-company': 'updateSelections',
|
|
|
+ 'change #current-store': 'updateUsers',
|
|
|
+ },
|
|
|
+
|
|
|
+ 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();
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull: function(dato) {
|
|
|
+ var valor = "";
|
|
|
+ if (dato) {
|
|
|
+ valor = dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ checkModel: function(model) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.IrModuleModule, function(item) {
|
|
|
+ return item.name === model
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchInitial: function() {
|
|
|
+ var self = this;
|
|
|
+ self.fetchResUser().then(function(ResUser) {
|
|
|
+ return ResUser;
|
|
|
+ }).then(function(ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ if (ResUser.length > 0) {
|
|
|
+ self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
|
|
|
+ _.each(ResUser, function(item) {
|
|
|
+ self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.user').css('display', 'none');
|
|
|
+ }
|
|
|
+
|
|
|
+ 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.fetchAccountPeriod();
|
|
|
+ }).then(function(AccountPeriod) {
|
|
|
+ self.AccountPeriod = AccountPeriod;
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
+ _.each(AccountPeriod, function(item) {
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+
|
|
|
+ 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.fetchAccountJournal().then(function(AccountJournal) {
|
|
|
+ return AccountJournal;
|
|
|
+ }).then(function(AccountJournal) {
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
+ return self.fetchAccountInvoice();
|
|
|
+ }).then(function(AccountInvoice) {
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fetchCommission();
|
|
|
+ }).then(function(Commission) {
|
|
|
+ self.Commission = Commission;
|
|
|
+ return self.fetchResUser();
|
|
|
+ }).then(function(ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountJournal: function() {
|
|
|
+ var self = this;
|
|
|
+ var domain = [
|
|
|
+ ['active', '=', true],
|
|
|
+ ['type', '=', 'sale']
|
|
|
+ ];
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
+ return AccountJournal.call('getAccountJournal', [domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ USER
|
|
|
+ =====================================================================*/
|
|
|
+ fetchResUser: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', 'store_id'];
|
|
|
+ var user = self.$el.find('#current-user').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+
|
|
|
+ var domain = [
|
|
|
+ ['active', '=', true]
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(store && store != 9999999){
|
|
|
+ domain.push(['store_id','=', parseInt(store)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user && user != 9999999) {
|
|
|
+ domain.push(['id', '=', parseInt(user)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var ResUser = new model.web.Model('res.users');
|
|
|
+ ResUser.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES COMPANY
|
|
|
+ ====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES STORE
|
|
|
+ ====================================================================*/
|
|
|
+ fetchResStore: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field = ['id', 'name', 'company_id'];
|
|
|
+ var ResStore = new model.web.Model('res.store');
|
|
|
+ ResStore.query(field).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ ACCOUNT PERIOD
|
|
|
+ =====================================================================*/
|
|
|
+ fetchAccountPeriod: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var domain = [
|
|
|
+ ['special', '=', false]
|
|
|
+ ];
|
|
|
+ var field = ['id', 'name', 'date_start', 'date_stop', 'company_id'];
|
|
|
+ var AccountPeriod = new model.web.Model('account.period');
|
|
|
+ AccountPeriod.query(field).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES CURRENCY
|
|
|
+ ====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ ACCOUNT INVOICE
|
|
|
+ ====================================================================*/
|
|
|
+
|
|
|
+ fetchAccountInvoice: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+
|
|
|
+ if (store && store != 9999999) {
|
|
|
+ var journal_ids = _.map(_.filter(self.AccountJournal, function(item) {
|
|
|
+ return item.store_ids[0] == store;
|
|
|
+ }), function(map) {
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ var journal_ids = _.flatten(_.map(self.AccountJournal, function(item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ var domain = [
|
|
|
+ ['state', 'in', ['open', 'paid']],
|
|
|
+ ['type', '=', 'out_invoice'],
|
|
|
+ ['journal_id', 'in', journal_ids],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ domain.push(['company_id', '=', parseInt(company)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (period && period != 9999999) {
|
|
|
+ domain.push(['period_id', '=', parseInt(period)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var field =['id', 'number', 'state','type','amount_total','user_id','company_id','period_id','date_invoice','journal_id', 'credito','contado'];
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ AccountInvoice.query(field).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchCommission: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'store_id', 'sale_type', 'sale_commission'];
|
|
|
+ var domain = [];
|
|
|
+ var Commission = new model.web.Model('salesman.commission');
|
|
|
+ Commission.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ UPDATE SELECTIONS
|
|
|
+ ====================================================================*/
|
|
|
+ updateSelections: function() {
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ if (company != 9999999) {
|
|
|
+ /*===================
|
|
|
+ STORE SELECTION
|
|
|
+ ===================*/
|
|
|
+ var 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>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*====================
|
|
|
+ PERIOD SELECTION
|
|
|
+ ====================*/
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
+ _.each(self.AccountPeriod, function(item) {
|
|
|
+ if (parseFloat(company) == item.company_id[0]) {
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ /*===================
|
|
|
+ STORE SELECTION
|
|
|
+ ===================*/
|
|
|
+ var 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>');
|
|
|
+ });
|
|
|
+ /*====================
|
|
|
+ PERIOD SELECTION
|
|
|
+ ====================*/
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todas los periodos</option>');
|
|
|
+ _.each(self.AccountPeriod, function(item) {
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateUsers: function() {
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ if (store != 9999999) {
|
|
|
+ var user = self.$el.find('#current-user').empty();
|
|
|
+ self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
|
|
|
+ _.each(self.ResUser, function(item) {
|
|
|
+ if (parseFloat(store) == item.store_id[0]) {
|
|
|
+ self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ var user = self.$el.find('#current-user').empty();
|
|
|
+ self.$el.find('#current-user').append('<option value="9999999">Todos los usuarios</option>');
|
|
|
+ _.each(self.ResUser, function(item) {
|
|
|
+ self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES COMPANY
|
|
|
+ ====================================================================*/
|
|
|
+ getResCompany: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCompany, function(item) {
|
|
|
+ return item.id == id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES CURRENCY BASE
|
|
|
+ ====================================================================*/
|
|
|
+ getResCurrency: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency, function(item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountInvoice: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountInvoice, function(item) {
|
|
|
+ return item.user_id[0] === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getCommission: function(type) {
|
|
|
+ var self = this;
|
|
|
+ return _.map(_.filter(self.Commission, function(item) {
|
|
|
+ return item.sale_type == type
|
|
|
+ }), function(map){
|
|
|
+ return map.sale_commission;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ BUILD
|
|
|
+ ====================================================================*/
|
|
|
+ BuildTable: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var x= 9999999;
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ var store = $('#current-store').val();
|
|
|
+
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ var ResCompany = self.getResCompany(company).shift();
|
|
|
+ var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ } else {
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ };
|
|
|
+
|
|
|
+ var ResUser = self.ResUser;
|
|
|
+ _.each(ResUser, function(i) {
|
|
|
+
|
|
|
+ var suma_credito = 0;
|
|
|
+ var suma_contado = 0;
|
|
|
+ var credito_commission = 0;
|
|
|
+ var contado_commission = 0;
|
|
|
+
|
|
|
+ var credito_amount = self.getCommission("credito");
|
|
|
+ var contado_amount = self.getCommission("contado");
|
|
|
+
|
|
|
+ var AccountInvoice = self.getAccountInvoice(i.id);
|
|
|
+ _.each(AccountInvoice, function(item){
|
|
|
+ if (item.credito == true){
|
|
|
+ suma_credito = suma_credito + item.amount_total;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.contado == true){
|
|
|
+ suma_contado = suma_contado + item.amount_total;
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ credito_commission = suma_credito * (credito_amount[0]/100);
|
|
|
+ contado_commission = suma_contado * (contado_amount[0]/100);
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ user : i.name,
|
|
|
+
|
|
|
+ suma_credito : accounting.formatMoney(suma_credito, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ suma_contado : accounting.formatMoney(suma_contado, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ credito_commission : accounting.formatMoney(credito_commission, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ contado_commission : accounting.formatMoney(contado_commission, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+
|
|
|
+ suma_credito_no_format : self.valorNull(suma_credito),
|
|
|
+ suma_contado_no_format : self.valorNull(suma_contado),
|
|
|
+ credito_commission_no_format : self.valorNull(credito_commission),
|
|
|
+ contado_commission_no_format : self.valorNull(contado_commission),
|
|
|
+
|
|
|
+ decimal_places: CurrencyBase.decimal_places,
|
|
|
+ thousands_separator: CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator: CurrencyBase.decimal_separator,
|
|
|
+ });
|
|
|
+ })
|
|
|
+
|
|
|
+ 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();
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ LOAD BOOTSTRAP TABLE
|
|
|
+ ====================================================================*/
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRINT PDF
|
|
|
+ ====================================================================*/
|
|
|
+ clickOnAction: function(e) {
|
|
|
+ var self = this;
|
|
|
+ var ResCompany;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ ResCompany = self.getResCompany(company).shift();
|
|
|
+ var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ } else {
|
|
|
+ ResCompany = self.ResCompany[0];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ var getColumns = [];
|
|
|
+ var rows = [];
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var column = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var row = table.bootstrapTable('getData');
|
|
|
+
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var suma_credito = creditoFormatter(row);
|
|
|
+ var suma_contado = contadoFormatter(row);
|
|
|
+ var credito_commission = creditoCommissionFormatter(row);
|
|
|
+ var contado_commission = contadoCommissionFormatter(row);
|
|
|
+
|
|
|
+ row.push({
|
|
|
+ user: 'Totales',
|
|
|
+ suma_contado: suma_contado,
|
|
|
+ contado_commission: contado_commission,
|
|
|
+ suma_credito: suma_credito,
|
|
|
+ credito_commission: credito_commission,
|
|
|
+ })
|
|
|
+ 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 = 'Comisión por vendedor.';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'comision_por_vendedor_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ user: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ suma_contado: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ contado_commission: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ suma_credito: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ contado_commission: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ 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 user = self.$el.find('#current-user').val();
|
|
|
+ var period = self.$el.find('#current-period').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 (user && user != 9999999) {
|
|
|
+ var ResUser = _.filter(self.ResUser, function(item) {
|
|
|
+ return item.id == user;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Usuario',
|
|
|
+ value: ResUser[0].name,
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ if (period && period != 9999999) {
|
|
|
+ var AccountPeriod = _.filter(self.AccountPeriod, function(item) {
|
|
|
+ return item.id == period;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Periodo',
|
|
|
+ value: AccountPeriod[0].name,
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ return filter;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|