|  | @@ -0,0 +1,612 @@
 | 
	
		
			
				|  |  | +function report_bank_movements (reporting){
 | 
	
		
			
				|  |  | +    "use strict";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    var instance = openerp;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    reporting.ReportBankMovementsWidget = reporting.Base.extend({
 | 
	
		
			
				|  |  | +        template: 'ReportBankMovements',
 | 
	
		
			
				|  |  | +        content:[],
 | 
	
		
			
				|  |  | +        rowsData :[],
 | 
	
		
			
				|  |  | +        events:{
 | 
	
		
			
				|  |  | +            'click #toolbar > button' : 'clickOnAction',
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            'click #X' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #A' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #B' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #C' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #D' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #Z' : 'factSearch',
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            'click #Y' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #sale' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #purchase' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #expense' : 'factSearch',
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            'click #W' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #open' : 'factSearch',
 | 
	
		
			
				|  |  | +            'click #paid' : 'factSearch',
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            'change #from' : 'factSearch',
 | 
	
		
			
				|  |  | +            'change #to' : 'factSearch',
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            'click-row.bs.table #table ' : 'clickAnalysisDetail',
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        init : function(parent){
 | 
	
		
			
				|  |  | +            this._super(parent);
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        start: function () {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var table = this.$el.find('#table');
 | 
	
		
			
				|  |  | +            table.bootstrapTable({data : self.rowsData});
 | 
	
		
			
				|  |  | +            this.fecthFecha();
 | 
	
		
			
				|  |  | +            this.submitForm();
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        clickAnalysisDetail: function(e, row, $element, field){
 | 
	
		
			
				|  |  | +            if (field == 'number'){
 | 
	
		
			
				|  |  | +                this.do_action({
 | 
	
		
			
				|  |  | +                    name:"Factura de proveedor",
 | 
	
		
			
				|  |  | +                    type: 'ir.actions.act_window',
 | 
	
		
			
				|  |  | +                    res_model: "account.invoice",
 | 
	
		
			
				|  |  | +                    views: [[false,'form']],
 | 
	
		
			
				|  |  | +                    target: 'new',
 | 
	
		
			
				|  |  | +                    domain: [['type', '=', 'in_invoice'],['id','=', row.id]],
 | 
	
		
			
				|  |  | +                    context: {},
 | 
	
		
			
				|  |  | +                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
 | 
	
		
			
				|  |  | +                    res_id: row.id,
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (field == 'partner'){
 | 
	
		
			
				|  |  | +                this.do_action({
 | 
	
		
			
				|  |  | +                    name:"Registro",
 | 
	
		
			
				|  |  | +                    type: 'ir.actions.act_window',
 | 
	
		
			
				|  |  | +                    res_model: "res.partner",
 | 
	
		
			
				|  |  | +                    views: [[false,'form']],
 | 
	
		
			
				|  |  | +                    target: 'new',
 | 
	
		
			
				|  |  | +                    domain: [['id','=', row.partner_id]],
 | 
	
		
			
				|  |  | +                    context: {},
 | 
	
		
			
				|  |  | +                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
 | 
	
		
			
				|  |  | +                    res_id: row.partner_id,
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            e.stopImmediatePropagation();
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        submitForm: function () {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            self.fetchAccountInvoice().then(function(AccountInvoice) {
 | 
	
		
			
				|  |  | +                return AccountInvoice;
 | 
	
		
			
				|  |  | +            }).then(function (AccountInvoice) {
 | 
	
		
			
				|  |  | +                self.AccountInvoice = AccountInvoice;
 | 
	
		
			
				|  |  | +            //     return self.fecthResStore();
 | 
	
		
			
				|  |  | +            // }).then(function(ResStore){
 | 
	
		
			
				|  |  | +            //     self.ResStore = ResStore;
 | 
	
		
			
				|  |  | +            //     self.$el.find('#current-store').append('<option value="9999999">Todas las SUC.</option>');
 | 
	
		
			
				|  |  | +            //     _.each(ResStore,function(item){
 | 
	
		
			
				|  |  | +            //         self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
 | 
	
		
			
				|  |  | +            //     });
 | 
	
		
			
				|  |  | +                 return self.fecthAccountJournal();
 | 
	
		
			
				|  |  | +            }).then(function(AccountJournal){
 | 
	
		
			
				|  |  | +                self.AccountJournal = AccountJournal;
 | 
	
		
			
				|  |  | +                return self.fetchResPartner();
 | 
	
		
			
				|  |  | +            }).then(function(ResPartner){
 | 
	
		
			
				|  |  | +                self.ResPartner = ResPartner;
 | 
	
		
			
				|  |  | +                self.search();
 | 
	
		
			
				|  |  | +                return self.BuildTable();
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        fecthFecha: function() {
 | 
	
		
			
				|  |  | +            var to;
 | 
	
		
			
				|  |  | +            var dateFormat1 = "mm/dd/yy",
 | 
	
		
			
				|  |  | +            from = $( "#from" )
 | 
	
		
			
				|  |  | +            .datepicker({
 | 
	
		
			
				|  |  | +                dateFormat: "dd/mm/yy",
 | 
	
		
			
				|  |  | +                changeMonth: true,
 | 
	
		
			
				|  |  | +                numberOfMonths: 1,
 | 
	
		
			
				|  |  | +            })
 | 
	
		
			
				|  |  | +            .on( "change", function() {
 | 
	
		
			
				|  |  | +                to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            to = $( "#to" ).datepicker({
 | 
	
		
			
				|  |  | +                dateFormat: "dd/mm/yy",
 | 
	
		
			
				|  |  | +                defaultDate: "+7d",
 | 
	
		
			
				|  |  | +                changeMonth: true,
 | 
	
		
			
				|  |  | +                numberOfMonths: 1,
 | 
	
		
			
				|  |  | +            })
 | 
	
		
			
				|  |  | +            .on( "change", function() {
 | 
	
		
			
				|  |  | +                from.datepicker( "option", "maxDate", getDate(this));
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            function getDate( element ) {
 | 
	
		
			
				|  |  | +                var fechaSel =element.value.split('/');
 | 
	
		
			
				|  |  | +                var date;
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  | +                    date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
 | 
	
		
			
				|  |  | +                } catch( error ) {
 | 
	
		
			
				|  |  | +                    date = null;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                return date;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // fecthResStore: function(){
 | 
	
		
			
				|  |  | +        //     var self = this;
 | 
	
		
			
				|  |  | +        //     var defer = $.Deferred();
 | 
	
		
			
				|  |  | +        //     var field=['id', 'name'];
 | 
	
		
			
				|  |  | +        //     var ResStore = new instance.web.Model('res.store');
 | 
	
		
			
				|  |  | +        //     ResStore.query(field).all().then(function(results){
 | 
	
		
			
				|  |  | +        //         defer.resolve(results);
 | 
	
		
			
				|  |  | +        //     });
 | 
	
		
			
				|  |  | +        //     return defer;
 | 
	
		
			
				|  |  | +        // },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        fecthAccountJournal: function(){
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var defer = $.Deferred();
 | 
	
		
			
				|  |  | +            var field = ['id', 'name'];
 | 
	
		
			
				|  |  | +            var domain = [['active','=',true],['type','in',['sale','purchase']]];
 | 
	
		
			
				|  |  | +            var AccountJournal = new instance.web.Model('account.journal');
 | 
	
		
			
				|  |  | +            AccountJournal.query(field).filter(domain).all().then(function(results){
 | 
	
		
			
				|  |  | +                defer.resolve(results);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            return defer;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        fetchAccountInvoice: function () {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var filter = [['type','not in',['in_refund','out_refund']],['state','in',['open','paid']]];
 | 
	
		
			
				|  |  | +            var field = ['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id','type','residual'];
 | 
	
		
			
				|  |  | +            var defer = $.Deferred();
 | 
	
		
			
				|  |  | +            var AccountInvoice = new instance.web.Model('account.invoice');
 | 
	
		
			
				|  |  | +            AccountInvoice.query(field).filter(filter).all().then(function (results) {
 | 
	
		
			
				|  |  | +                defer.resolve(results);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            return defer;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        fetchResPartner: function() {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var defer = $.Deferred();
 | 
	
		
			
				|  |  | +            var ResPartner = new instance.web.Model('res.partner');
 | 
	
		
			
				|  |  | +            ResPartner.query(['id', 'name', 'ruc', 'active']).filter([['active', '=', true]]).all().then(function (results) {
 | 
	
		
			
				|  |  | +                defer.resolve(results);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            return defer;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        valorNull:function(dato){
 | 
	
		
			
				|  |  | +            var valor ="";
 | 
	
		
			
				|  |  | +            if (dato){
 | 
	
		
			
				|  |  | +                valor=dato;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return valor;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        search: function () {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var results = self.ResPartner;
 | 
	
		
			
				|  |  | +            results = _.map(results, function (item) {
 | 
	
		
			
				|  |  | +                return {
 | 
	
		
			
				|  |  | +                        label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
 | 
	
		
			
				|  |  | +                        value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            self.$('#partner').autocomplete({
 | 
	
		
			
				|  |  | +                source: results,
 | 
	
		
			
				|  |  | +                minLength:0,
 | 
	
		
			
				|  |  | +                search: function(event, ui) {
 | 
	
		
			
				|  |  | +                    if (!(self.$('#partner').val())){
 | 
	
		
			
				|  |  | +                        self.factSearch();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                },
 | 
	
		
			
				|  |  | +                close: function( event, ui ) {
 | 
	
		
			
				|  |  | +                        self.factSearch();
 | 
	
		
			
				|  |  | +                },
 | 
	
		
			
				|  |  | +                select: function(event, ui) {
 | 
	
		
			
				|  |  | +                    self.factSearch();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        getAccountJournal: function (id) {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            return _.filter(self.AccountJournal,function (item) {
 | 
	
		
			
				|  |  | +                return item.id === id;
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        BuildTable: function(){
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var data = [];
 | 
	
		
			
				|  |  | +            var AccountInvoice = self.AccountInvoice;
 | 
	
		
			
				|  |  | +            var amount_total_num;
 | 
	
		
			
				|  |  | +            var entry;
 | 
	
		
			
				|  |  | +            var egress;
 | 
	
		
			
				|  |  | +            var to_receive;
 | 
	
		
			
				|  |  | +            var to_pay;
 | 
	
		
			
				|  |  | +            var entry_num;
 | 
	
		
			
				|  |  | +            var egress_num;
 | 
	
		
			
				|  |  | +            var to_receive_num;
 | 
	
		
			
				|  |  | +            var to_pay_num;
 | 
	
		
			
				|  |  | +            var invoice_type;
 | 
	
		
			
				|  |  | +            _.each(AccountInvoice, function(item){
 | 
	
		
			
				|  |  | +                if (item.type == 'out_invoice') {
 | 
	
		
			
				|  |  | +                    entry = item.amount_total - item.residual;
 | 
	
		
			
				|  |  | +                    egress = 0;
 | 
	
		
			
				|  |  | +                    to_receive = item.residual;
 | 
	
		
			
				|  |  | +                    to_pay = 0;
 | 
	
		
			
				|  |  | +                    invoice_type = 'sale';
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    entry = 0;
 | 
	
		
			
				|  |  | +                    egress = item.amount_total - item.residual;
 | 
	
		
			
				|  |  | +                    to_receive = 0;
 | 
	
		
			
				|  |  | +                    to_pay = item.residual;
 | 
	
		
			
				|  |  | +                    if (item.origin == false) {
 | 
	
		
			
				|  |  | +                        invoice_type = 'expense';
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        invoice_type = 'purchase';
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                // var store_id = self.getAccountJournal(item.journal_id[0]);
 | 
	
		
			
				|  |  | +                // if(store_id.length > 0){
 | 
	
		
			
				|  |  | +                    data.push({
 | 
	
		
			
				|  |  | +                        id : item.id,
 | 
	
		
			
				|  |  | +                        number: item.number,
 | 
	
		
			
				|  |  | +                        partner: item.partner_id[1],
 | 
	
		
			
				|  |  | +                        date_invoice: moment(item.date_invoice).format("DD/MM/YYYY"),
 | 
	
		
			
				|  |  | +                        user: item.user_id[1],
 | 
	
		
			
				|  |  | +                        amount_total: accounting.formatNumber(item.amount_total,0,".",","),
 | 
	
		
			
				|  |  | +                        entry: accounting.formatNumber(entry,0,".",","),
 | 
	
		
			
				|  |  | +                        egress: accounting.formatNumber(egress,0,".",","),
 | 
	
		
			
				|  |  | +                        to_receive: accounting.formatNumber(to_receive,0,".",","),
 | 
	
		
			
				|  |  | +                        to_pay: accounting.formatNumber(to_pay,0,".",","),
 | 
	
		
			
				|  |  | +                        state: item.state,
 | 
	
		
			
				|  |  | +                        invoice_type: invoice_type,
 | 
	
		
			
				|  |  | +                        date: item.date_invoice,
 | 
	
		
			
				|  |  | +                        journal_id : item.journal_id[0],
 | 
	
		
			
				|  |  | +                        currency_id : item.currency_id[0],
 | 
	
		
			
				|  |  | +                        partner_id : item.partner_id[0],
 | 
	
		
			
				|  |  | +                        amount_total_num: item.amount_total,
 | 
	
		
			
				|  |  | +                        entry_num: entry,
 | 
	
		
			
				|  |  | +                        egress_num: egress,
 | 
	
		
			
				|  |  | +                        to_receive_num: to_receive,
 | 
	
		
			
				|  |  | +                        to_pay_num: to_pay,
 | 
	
		
			
				|  |  | +                        // store_id: store_id[0].store_ids[0],
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  | +                // }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            self.content = data;
 | 
	
		
			
				|  |  | +            this.loadTable(data);
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        factSearch: function(){
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var hoy = moment().format('YYYY-MM-DD');
 | 
	
		
			
				|  |  | +            var desde = this.$el.find('#from').val();
 | 
	
		
			
				|  |  | +            var hasta = this.$el.find('#to').val();
 | 
	
		
			
				|  |  | +            var partner = this.$el.find('#partner').val().split('-');
 | 
	
		
			
				|  |  | +            // var store = this.$el.find('#current-store').val();
 | 
	
		
			
				|  |  | +            var content = self.content;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if ($('#A').is(":checked")){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.date == hoy;
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#B').is(":checked")){
 | 
	
		
			
				|  |  | +                var date = hoy.split('-');
 | 
	
		
			
				|  |  | +                var ayer = date[2] - 1;
 | 
	
		
			
				|  |  | +                date.splice(2,0);
 | 
	
		
			
				|  |  | +                if(date[2] < 10){
 | 
	
		
			
				|  |  | +                    date[2] = '0'+ayer;
 | 
	
		
			
				|  |  | +                }else{
 | 
	
		
			
				|  |  | +                    date[2] = ayer;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.date == date[0]+'-'+date[1]+'-'+date[2];
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#C').is(":checked")){
 | 
	
		
			
				|  |  | +                var date = hoy.split('-');
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    var mes = inv.date.split('-');
 | 
	
		
			
				|  |  | +                    return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#D').is(":checked")){
 | 
	
		
			
				|  |  | +                var date = hoy.split('-');
 | 
	
		
			
				|  |  | +                var mes = date[1] - 1;
 | 
	
		
			
				|  |  | +                var year;
 | 
	
		
			
				|  |  | +                date.splice(1,0);
 | 
	
		
			
				|  |  | +                if(date[1] == 1){
 | 
	
		
			
				|  |  | +                    date[1] = '12';
 | 
	
		
			
				|  |  | +                    year = date[0] - 1;
 | 
	
		
			
				|  |  | +                    date[0] = year;
 | 
	
		
			
				|  |  | +                }else{
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    if(date[1] < 10){
 | 
	
		
			
				|  |  | +                        date[1] = '0'+mes;
 | 
	
		
			
				|  |  | +                    }else{
 | 
	
		
			
				|  |  | +                        date[1] = mes;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    var mes = inv.date.split('-');
 | 
	
		
			
				|  |  | +                    return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#Z').is(":checked")){
 | 
	
		
			
				|  |  | +                $('#datepicker').css('display','block');
 | 
	
		
			
				|  |  | +                if (desde.length > 0){
 | 
	
		
			
				|  |  | +                    var date= desde.split('/');
 | 
	
		
			
				|  |  | +                    content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                        return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (hasta.length > 0){
 | 
	
		
			
				|  |  | +                    var date= hasta.split('/');
 | 
	
		
			
				|  |  | +                    content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                        return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                $('#datepicker').css('display','none');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if ($('#sale').is(":checked")){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.invoice_type == 'sale';
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#purchase').is(":checked")){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.invoice_type == 'purchase';
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#expense').is(":checked")){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.invoice_type == 'expense';
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#open').is(":checked")){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.state == 'open';
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($('#paid').is(":checked")){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function (inv){
 | 
	
		
			
				|  |  | +                    return inv.state == 'paid';
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (partner != ""){
 | 
	
		
			
				|  |  | +                content = _.filter(content, function(inv){
 | 
	
		
			
				|  |  | +                    return inv.partner_id == partner[0];
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // if(store != 9999999){
 | 
	
		
			
				|  |  | +            //     content=_.filter(content, function (inv){
 | 
	
		
			
				|  |  | +            //         return inv.store_id == store
 | 
	
		
			
				|  |  | +            //     });
 | 
	
		
			
				|  |  | +            // }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var amount_entry_num = _.reduce(_.map(content,function(map){
 | 
	
		
			
				|  |  | +                return(map.entry_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var amount_egress_num = _.reduce(_.map(content,function(map){
 | 
	
		
			
				|  |  | +                return(map.egress_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var amount_to_receive_num = _.reduce(_.map(content,function(map){
 | 
	
		
			
				|  |  | +                return(map.to_receive_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var amount_to_pay_num = _.reduce(_.map(content,function(map){
 | 
	
		
			
				|  |  | +                return(map.to_pay_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            content.push({
 | 
	
		
			
				|  |  | +                number: "Total",
 | 
	
		
			
				|  |  | +                entry: accounting.formatNumber(amount_entry_num,0,".",","),
 | 
	
		
			
				|  |  | +                egress: accounting.formatNumber(amount_egress_num,0,".",","),
 | 
	
		
			
				|  |  | +                to_receive: accounting.formatNumber(amount_to_receive_num,0,".",","),
 | 
	
		
			
				|  |  | +                to_pay: accounting.formatNumber(amount_to_pay_num,0,".",","),
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            self.loadTable(content)
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        loadTable:function(rowsTable){
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            self.rowsData = rowsTable;
 | 
	
		
			
				|  |  | +            var table = this.$el.find('#table');
 | 
	
		
			
				|  |  | +            table.bootstrapTable('load',rowsTable);
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        getObjectPdf: function(rowsTable){
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var rowsPdf=[];
 | 
	
		
			
				|  |  | +            var rows=[];
 | 
	
		
			
				|  |  | +            var rows = self.rowsData;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var amount_total_num = _.reduce(_.map(rows,function(map){
 | 
	
		
			
				|  |  | +                return(map.amount_total_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var entry_num = _.reduce(_.map(rows,function(map){
 | 
	
		
			
				|  |  | +                return(map.entry_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var egress_num = _.reduce(_.map(rows,function(map){
 | 
	
		
			
				|  |  | +                return(map.egress_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +            var to_receive_num = _.reduce(_.map(rows,function(map){
 | 
	
		
			
				|  |  | +                return(map.to_receive_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +            var to_pay_num = _.reduce(_.map(rows,function(map){
 | 
	
		
			
				|  |  | +                return(map.to_pay_num);
 | 
	
		
			
				|  |  | +            }),function(memo, num){
 | 
	
		
			
				|  |  | +                return memo + num;
 | 
	
		
			
				|  |  | +            },0);
 | 
	
		
			
				|  |  | +            if (rows.length > 0){
 | 
	
		
			
				|  |  | +                rows.push({
 | 
	
		
			
				|  |  | +                    number : 'Totales',
 | 
	
		
			
				|  |  | +                    partner : '',
 | 
	
		
			
				|  |  | +                    date : '',
 | 
	
		
			
				|  |  | +                    user : '',
 | 
	
		
			
				|  |  | +                    amount_total: accounting.formatNumber(amount_total_num,0,".",","),
 | 
	
		
			
				|  |  | +                    entry: accounting.formatNumber(entry_num,0,".",","),
 | 
	
		
			
				|  |  | +                    egress: accounting.formatNumber(egress_num,0,".",","),
 | 
	
		
			
				|  |  | +                    to_receive: accounting.formatNumber(to_receive_num,0,".",","),
 | 
	
		
			
				|  |  | +                    to_pay: accounting.formatNumber(to_pay_num,0,".",","),
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return rows;
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        clickOnAction: function (e) {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var rowsNew;
 | 
	
		
			
				|  |  | +            var action = self.$el.find(e.target).val();
 | 
	
		
			
				|  |  | +            var table = self.$el.find("#table");
 | 
	
		
			
				|  |  | +            var data2 = table.bootstrapTable('getVisibleColumns');
 | 
	
		
			
				|  |  | +            var getColumns=[];
 | 
	
		
			
				|  |  | +            var rows=[];
 | 
	
		
			
				|  |  | +            rowsNew = self.getObjectPdf();
 | 
	
		
			
				|  |  | +            if (action === 'pdf') {
 | 
	
		
			
				|  |  | +                var dataNEW = _.map(data2, function (val){
 | 
	
		
			
				|  |  | +                    return val.field;
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                _.each(rowsNew,function (item){
 | 
	
		
			
				|  |  | +                    rows.push(_.pick(item, dataNEW));
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                _.each(_.map(data2,function(val){
 | 
	
		
			
				|  |  | +                        return val;
 | 
	
		
			
				|  |  | +                    }), function(item){
 | 
	
		
			
				|  |  | +                            getColumns.push([{
 | 
	
		
			
				|  |  | +                                        title: item.title,
 | 
	
		
			
				|  |  | +                                        dataKey: item.field
 | 
	
		
			
				|  |  | +                                    }]);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                this.drawPDF(_.flatten(getColumns),rows);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        drawPDF: function (getColumns,rows) {
 | 
	
		
			
				|  |  | +            var self = this;
 | 
	
		
			
				|  |  | +            var hoy = moment().format('DD/MM/YYYY');
 | 
	
		
			
				|  |  | +            var desde =(this.$el.find('#from').val());
 | 
	
		
			
				|  |  | +            var hasta =(this.$el.find('#to').val());
 | 
	
		
			
				|  |  | +            var totalPagesExp = "{total_pages_count_string}";
 | 
	
		
			
				|  |  | +            var pdfDoc = new jsPDF('l');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            pdfDoc.autoTable(getColumns, rows, {
 | 
	
		
			
				|  |  | +                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
 | 
	
		
			
				|  |  | +                columnStyles: {
 | 
	
		
			
				|  |  | +                    number : {columnWidth: '8px'},
 | 
	
		
			
				|  |  | +                    partner : {columnWidth: '8px'},
 | 
	
		
			
				|  |  | +                    date : {columnWidth: '8px'},
 | 
	
		
			
				|  |  | +                    user : {columnWidth: '6px'},
 | 
	
		
			
				|  |  | +                    entry: {halign:'right',columnWidth: '11px'},
 | 
	
		
			
				|  |  | +                    egress: {halign:'right',columnWidth: '9px'},
 | 
	
		
			
				|  |  | +                    to_receive: {halign:'right',columnWidth: '9px'},
 | 
	
		
			
				|  |  | +                    to_pay: {halign:'right',columnWidth: '8px'},
 | 
	
		
			
				|  |  | +                    amount_total: {halign:'right',columnWidth: '11px'},
 | 
	
		
			
				|  |  | +                },
 | 
	
		
			
				|  |  | +                margin: { top: 20, horizontal: 7},
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                addPageContent: function (data) {
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontSize(12);
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontStyle('bold');
 | 
	
		
			
				|  |  | +                    pdfDoc.setTextColor(40);
 | 
	
		
			
				|  |  | +                    pdfDoc.text('Histórico de Facturas', 80, 10);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    var tipo = '';
 | 
	
		
			
				|  |  | +                    if ($('#Y').is(":checked")){
 | 
	
		
			
				|  |  | +                        tipo = tipo.concat(' Tipo de factura : Todas las facturas' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#sale').is(":checked")){
 | 
	
		
			
				|  |  | +                        tipo = tipo.concat(' Tipo de factura : Ventas' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#purchase').is(":checked")){
 | 
	
		
			
				|  |  | +                        tipo = tipo.concat(' Tipo de factura : Compras' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#expense').is(":checked")){
 | 
	
		
			
				|  |  | +                        tipo = tipo.concat(' Tipo de factura : Gastos' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontSize(9);
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontStyle('normal');
 | 
	
		
			
				|  |  | +                    pdfDoc.setTextColor(40)
 | 
	
		
			
				|  |  | +                    pdfDoc.text(6,14,tipo);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    var fecha = '';
 | 
	
		
			
				|  |  | +                    if ($('#X').is(":checked")){
 | 
	
		
			
				|  |  | +                        fecha = fecha.concat(' Filtro de fecha : Sin Filtros' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#A').is(":checked")){
 | 
	
		
			
				|  |  | +                        fecha = fecha.concat(' Filtro de fecha : Hoy' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#B').is(":checked")){
 | 
	
		
			
				|  |  | +                        fecha = fecha.concat(' Filtro de fecha : Ayer' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#C').is(":checked")){
 | 
	
		
			
				|  |  | +                        fecha = fecha.concat(' Filtro de fecha : Mes Actual' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#D').is(":checked")){
 | 
	
		
			
				|  |  | +                        fecha = fecha.concat(' Filtro de fecha : Mes Pasado' );
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if ($('#Z').is(":checked")){
 | 
	
		
			
				|  |  | +                        if(desde.length > 0 || hasta.length > 0){
 | 
	
		
			
				|  |  | +                            if(desde){
 | 
	
		
			
				|  |  | +                                fecha=fecha.concat(' Desde: '+ desde);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                            if (hasta){
 | 
	
		
			
				|  |  | +                                fecha=fecha.concat(' Hasta: '+ hasta);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontSize(9);
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontStyle('normal');
 | 
	
		
			
				|  |  | +                    pdfDoc.setTextColor(40)
 | 
	
		
			
				|  |  | +                    pdfDoc.text(6,18,fecha);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontSize(9);
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontStyle('normal');
 | 
	
		
			
				|  |  | +                    pdfDoc.setTextColor(40)
 | 
	
		
			
				|  |  | +                    pdfDoc.text(150,14," Fecha de Expedición: " + hoy);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    var str = " Pagina  " + data.pageCount;
 | 
	
		
			
				|  |  | +                    if (typeof pdfDoc.putTotalPages === 'function') {
 | 
	
		
			
				|  |  | +                        str = str + " de " + totalPagesExp
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontSize(9);
 | 
	
		
			
				|  |  | +                    pdfDoc.setFontStyle('normal');
 | 
	
		
			
				|  |  | +                    pdfDoc.setTextColor(40);
 | 
	
		
			
				|  |  | +                    pdfDoc.text(175,pdfDoc.internal.pageSize.height - 5,str);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            if (typeof pdfDoc.putTotalPages === 'function') {
 | 
	
		
			
				|  |  | +                pdfDoc.putTotalPages(totalPagesExp);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            pdfDoc.save('Histórico de Movimiento de Banco.pdf')
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +}
 |