|
@@ -0,0 +1,633 @@
|
|
|
+function report_seller(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportSellerWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportSeller',
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-store' : 'updateJournalSelections',
|
|
|
+ '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;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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.fetchResCompany().then(function (ResCompany) {
|
|
|
+ return ResCompany;
|
|
|
+ }).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.fetchAccountJournal();
|
|
|
+ }).then(function(AccountJournal){
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
+ if(AccountJournal.length > 0){
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todos los vendedores</option>');
|
|
|
+ _.each(AccountJournal,function(item){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.journal').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.fetchAccountInvoiceLine();
|
|
|
+ }).then(function (AccountInvoiceLine){
|
|
|
+ self.AccountInvoiceLine = AccountInvoiceLine;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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 JOURNAL
|
|
|
+ ====================================================================*/
|
|
|
+ fetchAccountJournal: function(){
|
|
|
+ var self = this;
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var domain = [['active','=',true],['type','=','sale']];
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ domain.push(['id','=',parseInt(journal)]);
|
|
|
+ }
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
+ return AccountJournal.call('getAccountJournal',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ 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 store = self.$el.find('#current-store').val();
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var company = self.$el.find('#current-company').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 == 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)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date && date != 9999999){
|
|
|
+
|
|
|
+ if(desde){
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ domain.push(['date_invoice','>=',date]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(hasta){
|
|
|
+ var date = hasta.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ domain.push(['date_invoice','<=',date]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ domain.push(['date_invoice','=',today]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ domain.push(['date_invoice','=',yesterday]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ domain.push(['date_invoice','like',currentMonth]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ domain.push(['date_invoice','like',lastMonth]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ return AccountInvoice.call('getAccountInvoiceDental',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ ACCOUNT INVOICE LINE
|
|
|
+ ====================================================================*/
|
|
|
+ fetchAccountInvoiceLine: function () {
|
|
|
+ var self = this;
|
|
|
+ var invoice_ids = _.flatten(_.map(self.AccountInvoice, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var domain = [
|
|
|
+ ['invoice_id','in',invoice_ids],
|
|
|
+ ];
|
|
|
+ var AccountInvoiceLine = new model.web.Model('account.invoice.line');
|
|
|
+ return AccountInvoiceLine.call('getAccountInvoiceLineDental',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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 sucursellers</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 sucursellers</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>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateJournalSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ if(store != 9999999){
|
|
|
+ /*=============================
|
|
|
+ ACCOUNT JOURNAL SELECTION
|
|
|
+ =============================*/
|
|
|
+ var journal = self.$el.find('#current-journal').empty();
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
+ _.each(self.AccountJournal,function(item){
|
|
|
+ if(parseFloat(store) == item.store_ids){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*=============================
|
|
|
+ ACCOUNT JOURNAL SELECTION
|
|
|
+ =============================*/
|
|
|
+ var journal = self.$el.find('#current-journal').empty();
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
+ _.each(self.AccountJournal,function(item){
|
|
|
+ self.$el.find('#current-journal').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;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET ACCOUNT INVOICE
|
|
|
+ ====================================================================*/
|
|
|
+ getAccountInvoice: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountInvoice,function (item) {
|
|
|
+ return item.journal_id[0] === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET ACCOUNT INVOICE LINE
|
|
|
+ ====================================================================*/
|
|
|
+ getAccountInvoiceLine: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.AccountInvoiceLine, function(item){
|
|
|
+ return item.invoice_id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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();
|
|
|
+ };
|
|
|
+
|
|
|
+ var AccountJournal = self.AccountJournal;
|
|
|
+ _.each(AccountJournal,function(item) {
|
|
|
+ var total_cash = 0;
|
|
|
+ var total_credit = 0;
|
|
|
+ var total_amount = 0;
|
|
|
+ var total_cost = 0;
|
|
|
+ var utility = 0;
|
|
|
+ var cost_percent = 0;
|
|
|
+ var sale_percent = 0;
|
|
|
+
|
|
|
+ var AccountInvoice = self.getAccountInvoice(item.id);
|
|
|
+ _.each(AccountInvoice,function(item2) {
|
|
|
+
|
|
|
+ if(item2.payment_term.id && item2.payment_term.check_credit == true){
|
|
|
+ total_credit = total_credit + item2.amount_total;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ total_cash = total_cash + item2.amount_total;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var AccountInvoiceLine = self.getAccountInvoiceLine(item2.id);
|
|
|
+ _.each(AccountInvoiceLine, function(line_item){
|
|
|
+ total_cost = total_cost + (line_item.product_id.standard_price * line_item.quantity);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ total_amount = total_cash + total_credit;
|
|
|
+ utility = total_amount - total_cost;
|
|
|
+ cost_percent = utility * 100 / total_cost;
|
|
|
+ sale_percent = utility * 100 / total_amount;
|
|
|
+
|
|
|
+ if(total_amount > 0){
|
|
|
+
|
|
|
+ data.push({
|
|
|
+
|
|
|
+ id: item.id,
|
|
|
+ name: item.name,
|
|
|
+ total_cash : accounting.formatMoney(total_cash,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total_credit : accounting.formatMoney(total_credit,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total_amount : accounting.formatMoney(total_amount,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total_cost : accounting.formatMoney(total_cost,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ utility : accounting.formatMoney(utility,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ cost_percent : accounting.formatNumber(cost_percent,2,".",",") + ' %',
|
|
|
+ sale_percent : accounting.formatNumber(sale_percent,2,".",",") + ' %',
|
|
|
+
|
|
|
+ /*=======================
|
|
|
+ VALORES SIN FORMATEAR
|
|
|
+ =======================*/
|
|
|
+ total_cash_no_format : total_cash,
|
|
|
+ total_credit_no_format : total_credit,
|
|
|
+ total_amount_no_format : total_amount,
|
|
|
+ total_cost_no_format : total_cost,
|
|
|
+ utility_no_format : utility,
|
|
|
+ cost_percent_no_format : cost_percent,
|
|
|
+ sale_percent_no_format : sale_percent,
|
|
|
+
|
|
|
+
|
|
|
+ /*==============================
|
|
|
+ TOTAL FOOTER CONFIGURATION
|
|
|
+ ==============================*/
|
|
|
+ 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');
|
|
|
+
|
|
|
+ var cash_total = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.total_cash_no_format;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var credit_total = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.total_credit_no_format;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var total_amount = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.total_amount_no_format;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var total_cost = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.total_cost_no_format;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var total_utility = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.utility_no_format;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var total_cost_percent = total_utility * 100 / total_cost;
|
|
|
+ var total_sale_percent = total_utility * 100 / total_amount;
|
|
|
+
|
|
|
+ row.push({
|
|
|
+ name: 'Totales',
|
|
|
+ total_cash: accounting.formatMoney(cash_total, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total_credit: accounting.formatMoney(credit_total, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total_amount: accounting.formatMoney(total_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total_cost: accounting.formatMoney(total_cost, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ utility: accounting.formatMoney(total_utility, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ cost_percent: accounting.formatNumber(total_cost_percent,2,CurrencyBase.thousands_separator, CurrencyBase.decimal_separator) + ' %',
|
|
|
+ sale_percent: accounting.formatNumber(total_sale_percent,2,CurrencyBase.thousands_separator, CurrencyBase.decimal_separator) + ' %',
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ 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 = 'Venta/Costo/Utilidad por vendedores';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'venta_costo_utilidad_por_vendedores_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ name : {columnWidth: 30, halign:'left'},
|
|
|
+ total_cash : {columnWidth: 25, halign:'right'},
|
|
|
+ total_credit : {columnWidth: 25, halign:'right'},
|
|
|
+ total_amount : {columnWidth: 25, halign:'right'},
|
|
|
+ total_cost : {columnWidth: 25, halign:'right'},
|
|
|
+ utility : {columnWidth: 25, halign:'right'},
|
|
|
+ cost_percent : {columnWidth: 20, halign:'right'},
|
|
|
+ sale_percent : {columnWidth: 20, halign:'right'},
|
|
|
+
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var pdf = new model.eiru_reports.ReportPdfWidget(self);
|
|
|
+ pdf.drawPDF(
|
|
|
+ _.flatten(getColumns),
|
|
|
+ row,
|
|
|
+ ResCompany,
|
|
|
+ pdf_title,
|
|
|
+ pdf_type,
|
|
|
+ pdf_name,
|
|
|
+ pdf_columnStyles,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|