|
@@ -0,0 +1,737 @@
|
|
|
+function report_delivery_baco(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportDeliveryWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportDeliveryWidget',
|
|
|
+ rowsData: [],
|
|
|
+ content: [],
|
|
|
+ modules: ['point_of_sale'],
|
|
|
+
|
|
|
+ events: {
|
|
|
+ 'click #toolbar > button': 'clickOnAction',
|
|
|
+ 'click #generate': 'fetchGenerate',
|
|
|
+ 'change #current-company': 'updateSelections',
|
|
|
+ 'change #current-period': 'updatePeriodSelections',
|
|
|
+ 'change #current-date': 'ShowDateRange',
|
|
|
+ },
|
|
|
+
|
|
|
+ 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
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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.fetchResUser();
|
|
|
+ }).then(function(ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ self.fecthCheckType();
|
|
|
+ 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.fetchPosOrder();
|
|
|
+ }).then(function(PosOrder) {
|
|
|
+ self.PosOrder = PosOrder;
|
|
|
+ return self.fetchDelivery();
|
|
|
+ }).then(function(Delivery) {
|
|
|
+ self.Delivery = Delivery;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ IR MODULE
|
|
|
+ =====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ Check type
|
|
|
+ =====================================================================*/
|
|
|
+ fecthCheckType: function() {
|
|
|
+ var self = this;
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+ if (modules.length == 0) {
|
|
|
+ self.$el.find('.type').css('display', 'none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ 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 domain = [
|
|
|
+ ['active', '=', true]
|
|
|
+ ];
|
|
|
+ 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', 'is_delivery','delivery_type'];
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ AccountInvoice.query(field).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ fetchPosOrder: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var type = $('#current-type').val();
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+ if (type && modules.length > 0) {
|
|
|
+ if (type != 'sale') {
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var company = self.$el.find('#current-company').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();
|
|
|
+ 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', 'not in', ['draft', 'cancel']],
|
|
|
+ ['sale_journal', 'in', journal_ids],
|
|
|
+ ];
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ domain.push(['company_id', '=', parseInt(company)]);
|
|
|
+ }
|
|
|
+ if (journal && journal != 9999999) {
|
|
|
+ domain.push(['sale_journal', '=', parseInt(journal)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (date && date != 9999999) {
|
|
|
+ if (date == 'range') {
|
|
|
+ if (desde) {
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = (date[2] + "-" + date[1] + "-" + date[0]);
|
|
|
+ domain.push(['date_order', '>=', date]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (date == 'today') {
|
|
|
+ var today = moment().format('YYYY-MM-DD 00:00:00');
|
|
|
+ domain.push(['date_order', '>=', today]);
|
|
|
+ }
|
|
|
+ if (date == 'yesterday') {
|
|
|
+ var yesterday = moment().add(-1, 'days').format('YYYY-MM-DD 00:00:00');
|
|
|
+ domain.push(['date_order', '>=', yesterday]);
|
|
|
+ }
|
|
|
+ if (date == 'currentMonth') {
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ domain.push(['date_order', 'like', currentMonth]);
|
|
|
+ }
|
|
|
+ if (date == 'lastMonth') {
|
|
|
+ var lastMonth = moment().add(-1, 'months').format('YYYY-MM');
|
|
|
+ domain.push(['date_order', 'like', lastMonth]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var PosOrder = new model.web.Model('account.invoice');
|
|
|
+ return PosOrder.call('getPosOrder', [domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ var PosOrder = [];
|
|
|
+ return PosOrder;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchDelivery: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'store_id', 'delivery_type', 'amount'];
|
|
|
+ var domain = [];
|
|
|
+ var Delivery = new model.web.Model('delivery.check');
|
|
|
+ Delivery.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>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ updatePeriodSelections: function() {
|
|
|
+ var self = this;
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ if (period != 9999999) {
|
|
|
+ self.$el.find('#current-date').val(9999999);
|
|
|
+ self.$el.find('#current-date').prop('disabled', 'disabled');
|
|
|
+ self.$el.find('.datepicker').css('display', 'none');
|
|
|
+ } else {
|
|
|
+ self.$el.find('#current-date').prop('disabled', false);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ getResUser: function(id) {
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var content = self.ResUser;
|
|
|
+
|
|
|
+ if(store && store != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.store_id[0] == store;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ getDelivery: function(type, store) {
|
|
|
+ var self = this;
|
|
|
+ return _.map(_.filter(self.Delivery, function(item) {
|
|
|
+ return item.delivery_type == type && item.store_id[0] == store;
|
|
|
+ }), function(map){
|
|
|
+ return map.amount;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ BUILD
|
|
|
+ ====================================================================*/
|
|
|
+ BuildTable: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var company = $('#current-company').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();
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ==========================================
|
|
|
+ RECORRER PRODUCTOS
|
|
|
+ ==========================================
|
|
|
+ */
|
|
|
+ var ResUser = self.getResUser();
|
|
|
+ _.each(ResUser, function(i) {
|
|
|
+
|
|
|
+
|
|
|
+ var suma_local = 0;
|
|
|
+ var suma_envio = 0;
|
|
|
+ var local_amount = 0;
|
|
|
+ var envio_amount = 0;
|
|
|
+
|
|
|
+ var local_delivery_amount = self.getDelivery("local", i.store_id[0]);
|
|
|
+ var envio_delivery_amount = self.getDelivery("envio", i.store_id[0]);
|
|
|
+
|
|
|
+ var AccountInvoice = self.getAccountInvoice(i.id);
|
|
|
+ _.each(AccountInvoice, function(item){
|
|
|
+
|
|
|
+ if (item.is_delivery == true && item.delivery_type == "local"){
|
|
|
+ suma_local = suma_local + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.is_delivery == true && item.delivery_type == "envio"){
|
|
|
+ suma_envio = suma_envio + 1;
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ local_amount = suma_local * local_delivery_amount[0];
|
|
|
+ envio_amount = suma_envio * envio_delivery_amount[0];
|
|
|
+
|
|
|
+ console.log(local_amount);
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ user : i.name,
|
|
|
+ suma_local : suma_local,
|
|
|
+ suma_envio : suma_envio,
|
|
|
+
|
|
|
+ local_amount : accounting.formatMoney(local_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ envio_amount : accounting.formatMoney(envio_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+
|
|
|
+ local_amount_no_format : self.valorNull(local_amount),
|
|
|
+ envio_amount_no_format : self.valorNull(envio_amount),
|
|
|
+
|
|
|
+ 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');
|
|
|
+
|
|
|
+
|
|
|
+ // impresion por categorias
|
|
|
+
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var suma_local = localFormatter(row);
|
|
|
+ var suma_envio = envioFormatter(row);
|
|
|
+ var local_amount = localAmountFormatter(row);
|
|
|
+ var envio_amount = envioAmountFormatter(row);
|
|
|
+
|
|
|
+ row.push({
|
|
|
+ user: 'Totales',
|
|
|
+ suma_local: suma_local,
|
|
|
+ suma_envio: suma_envio,
|
|
|
+ local_amount: local_amount,
|
|
|
+ envio_amount: envio_amount,
|
|
|
+ })
|
|
|
+ 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 delivery.';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'comision_por_delivery_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ user: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ suma_local: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ suma_envio: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ local_amount: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ envio_amount: {
|
|
|
+ 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 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 (period && period != 9999999) {
|
|
|
+ var AccountPeriod = _.filter(self.AccountPeriod, function(item) {
|
|
|
+ return item.id == period;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Periodo',
|
|
|
+ value: AccountPeriod[0].name,
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ return filter;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|