ソースを参照

[ADD] Balance de sumas y saldos

Rodney Enciso Arias 7 年 前
コミット
f84f7f59af

+ 5 - 0
static/src/js/configuration_reporting.js

@@ -44,6 +44,11 @@ function configuration_reporting (instance, widget) {
                 title: 'Informe de trabajos',
                 description: 'Permite visualizar los trabajos facturados y no facturados.',
                 action: 'ReportWorks'
+            },
+            {
+                title: 'Balance de sumas y saldos',
+                description: 'Permite visualizar un balance de Ingreso y Egreso',
+                action: 'ReportBalance'
             }
         ],
         start: function () {

+ 1 - 0
static/src/js/main.js

@@ -14,6 +14,7 @@ openerp.eiru_reporting = function (instance) {
     report_puchases(reporting);
     report_expenses(reporting);
     report_works(reporting);
+    report_balance(reporting);
     // report_stock_location(reporting);
     report_stock_product(reporting);
 

+ 395 - 0
static/src/js/reports/report_balance.js

@@ -0,0 +1,395 @@
+function report_balance (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportBalanceWidget = reporting.Base.extend({
+        template: 'ReportBalance',
+        invoice: [],
+        Currency:[],
+        resCurrency :[],
+        resCompany:[],
+        accountJournal:[],
+        supplier:[],
+        content:[],
+        rowsData :[],
+        // event
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'change #from' : 'factSearch',
+            'change #to' : 'factSearch',
+            'click-row.bs.table #table ' : 'ckickAnalysisDetail',
+        },
+        // Initil
+        init : function(parent){
+            this._super(parent);
+        },
+        // start
+        start: function () {
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        // Analisis Detallado
+        ckickAnalysisDetail: function(e, row, $element,field){
+            if (field == 'number'){
+                this.do_action({
+                    name:"Registro del Cliente",
+                    type: 'ir.actions.act_window',
+                    res_model: "res.partner",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.id,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        // Consultar
+        submitForm: function () {
+            var self = this;
+            self.fetchAccountInvoice().then(function(AccountInvoice) {
+                return AccountInvoice;
+            }).then(function(AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner; 
+                self.search();
+                return self.buildTable();
+                
+            });
+        },
+        // Fecha
+        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;
+            }
+        },
+        fetchAccountInvoice: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var AccountInvoice = new instance.web.Model('account.invoice');
+            AccountInvoice.query(['id','number','partner_id','amount_total','residual','state','date_invoice','type']).filter([['state','in',['open','paid']]]).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']).filter([['active','=',true],['customer','=',true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        
+        // Buscador
+        search: function () {
+            var self = this;
+            var results = self.ResPartner;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.name,
+                        value: item.id + '-'+ item.name
+                }
+            });
+            self.$('#customer').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#customer').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+        buildTable: function(){
+            var self = this;
+            var invoice = self.AccountInvoice;
+            var entry;
+            var egress;
+            var to_receive;
+            var to_pay;
+            var data = [];
+            _.each(invoice, function(item){
+                if (item.type == 'out_invoice') {
+                    entry = item.amount_total - item.residual;
+                    egress = 0;
+                    to_receive = item.residual;
+                    to_pay = 0;
+                } else {
+                    entry = 0;
+                    egress = item.amount_total - item.residual;
+                    to_receive = 0;
+                    to_pay = item.residual;
+                }  
+                data.push({
+                    id : item.id,
+                    number : item.number,
+                    partner : item.partner_id[1],
+                    partner_id : item.partner_id[0],
+                    date_invoice : moment(item.date_invoice).format("DD/MM/YYYY"),
+                    date : item.date_invoice,
+                    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,".",","),
+                    
+                    intamount_total : item.amount_total,
+                    intentry : entry,
+                    integress : egress,
+                    intreceive : to_receive,
+                    intpay : to_pay,
+                });
+            });
+            self.content = data;
+            this.loadTable(data);
+        },
+        // Buscar
+        factSearch: function(){
+            var self = this;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var customer= this.$el.find('#customer').val().split('-');
+            var content = self.content;
+            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]);
+                });
+            }
+            if (customer != ""){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == customer[0];
+                });
+            }
+            self.loadTable(content)
+        },
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load',rowsTable);
+        },
+        getObjetPdf: function(){
+            var self = this;
+            var rows=[];
+            var data = self.content;
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            var customer= this.$el.find('#customer').val().split('-');
+            if (desde.length > 0){
+                var date= desde.split('/');
+                data = _.filter(data, function (inv){
+                    return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            if (hasta.length > 0){
+                var date= desde.split('/');
+                data = _.filter(data, function (inv){
+                    return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            if (customer != ""){
+                data = _.filter(data, function(inv){
+                    return inv.partner_id == customer[0];
+                });
+            }
+            rows = data;
+
+            // Valor de la Factura
+            var intamount_total = _.reduce(_.map(data,function(map){
+                return(map.intamount_total);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            // Ingreso
+            var intentry = _.reduce(_.map(data,function(map){
+                return(map.intentry);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            // Egreso
+            var integress = _.reduce(_.map(data,function(map){
+                return(map.integress);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            // Monto a Cobrar
+            var intreceive = _.reduce(_.map(data,function(map){
+                return(map.intreceive);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            var intpay = _.reduce(_.map(data,function(map){
+                return(map.intpay);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            rows.push({
+                id : '',
+                number : 'Totales',
+                partner : '',
+                partner_id : '',
+                date_invoice : '',
+                date : '',
+                amount_total : accounting.formatNumber(intamount_total,0,".",","),
+                entry : accounting.formatNumber(intentry,0,".",","),
+                egress : accounting.formatNumber(integress,0,".",","),
+                to_receive : accounting.formatNumber(intreceive,0,".",","),
+                to_pay : accounting.formatNumber(intpay,0,".",","),
+                
+                intamount_total : 0,
+                intentry : 0,
+                integress : 0,
+                intreceive : 0,
+                intpay : 0,
+            });
+            return rows;
+        },
+        // imprimir PDF
+        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.getObjetPdf();
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){
+                    return val.field;
+                });
+                _.each(rowsNew,function (item){
+                    rows.push(_.pick(item, dataNEW));
+                });
+                // Obtener los nombre de la Cabezera
+                _.each(_.map(data2,function(val){
+                        return val;
+                    }), function(item){
+                    getColumns.push([{
+                        title: item.title,
+                        dataKey: item.field
+                    }]);
+                });
+                this.drawPDF(_.flatten(getColumns),rows);
+            }
+        },
+
+        // Generar pdfDoc
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            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'},
+                    partner_id : {columnWidth: '8px'},
+                    date_invoice : {columnWidth: '8px'},
+                    date : {columnWidth: '8px'},
+                    amount_total : {halign:'right',columnWidth: '8px'},
+                    entry : {halign:'right',columnWidth: '8px'},
+                    egress : {halign:'right',columnWidth: '8px'},
+                    to_receive : {halign:'right',columnWidth: '8px'},
+                    to_pay : {halign:'right',columnWidth: '8px'},
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Balance de Sumas y Saldos', data.settings.margin.left, 10);
+
+                    if(desde.length > 0 || hasta.length > 0){
+                        var fecha='';
+                        if(desde){
+                            fecha=fecha.concat(' Desde '+ desde);
+                        }
+                        if (hasta){
+                            fecha=fecha.concat(' Hasta '+ hasta);
+                        }
+                        pdfDoc.setFontSize(10);
+                        pdfDoc.setFontStyle('bold');
+                        pdfDoc.setTextColor(40)
+                        pdfDoc.text(fecha, data.settings.margin.left,14);
+                    }
+                    // FOOTER
+                    var str = "Pagina  " + data.pageCount;
+                    // Total page number plugin only available in jspdf v1.0+
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
+                    }
+            });
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            pdfDoc.save('Balance de Sumas y Saldos.pdf')
+        },
+    });
+}

+ 7 - 6
static/src/js/reports/report_invoices.js → static/src/js/reports/report_works.js

@@ -16,11 +16,8 @@ function report_works (reporting){
         // event
         events:{
             'click #toolbar > button' : 'clickOnAction',
-            'change #current-journal' : 'factSearch',
-            'change #current-currency' : 'factSearch',
             'change #from' : 'factSearch',
             'change #to' : 'factSearch',
-            'click  #volver_btn' : 'volver',
             'click-row.bs.table #table ' : 'ckickAnalysisDetail',
         },
         // Initil
@@ -245,6 +242,7 @@ function report_works (reporting){
                     car : item.name[1],
                     agent : self.valorNull(item.agent_id[1]),
                     date_in : moment(item.date_in).format("DD/MM/YYYY"),
+                    date : item.date_in,
                     secure_amount : accounting.formatNumber(secure_amount,0,".",","),
                     particular_amount : accounting.formatNumber(particular_amount,0,".",","),
                     state : state,
@@ -264,19 +262,22 @@ function report_works (reporting){
         factSearch: function(){
             var self = this;
             var desde =this.$el.find('#from').val();
+            console.log(desde);
             var hasta =this.$el.find('#to').val();
             var customer= this.$el.find('#customer').val().split('-');
             var content = self.content;
+            console.log(content[0].date_in);
             if (desde.length > 0){
                 var date= desde.split('/');
                 content = _.filter(content, function (inv){
-                    return inv.date_in >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    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_in <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    // return inv.date <= hasta;
                 });
             }
             if (customer != ""){
@@ -443,7 +444,7 @@ function report_works (reporting){
             if (typeof pdfDoc.putTotalPages === 'function') {
                 pdfDoc.putTotalPages(totalPagesExp);
             }
-            pdfDoc.save('Historico de Trabajos.pdf')
+            pdfDoc.save('Informe de Trabajos.pdf')
         },
     });
 }

+ 49 - 0
static/src/reports/report_balance.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportBalance">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Balance de Sumas y Saldos</h1>
+                <div id="volver"></div>
+            </div>
+            <div id="toolbar">
+
+                <label for="from">Desde: </label>
+                <input type="text"  id="from" name="from"/>
+
+                <label for="to" >Hasta: </label>
+                <input type="text"  id="to" name="to" />
+
+                <label for="customer">Cliente:</label>
+                <input id="customer" type="text" class="ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+
+                <button class="oe_button oe_form_button oe_highlight btn-block" value="pdf">PDF</button>
+                
+            </div>
+            <table id="table" class="table_paint_first_row"
+                data-pagination="true"
+                data-toggle="table"
+                data-reorderable-columns="true"
+                data-toolbar="#toolbar"
+                data-show-columns="true"
+                data-buttons-class="oe_button oe_form_button oe_highlight"
+                data-height="auto"
+                data-classes="table table-hover table-condensed"
+                data-row-style="rowStyle"
+                data-search="true">
+                <thead>
+                    <tr>
+                        <th data-field="number" data-sortable="true">Factura</th>
+                        <th data-field="partner" data-sortable="true">Cliente / Proveedor</th>
+                        <th data-field="date_invoice" data-sortable="true">Fecha</th>
+                        <th data-field="amount_total" data-sortable="true" data-align="right">Valor</th>
+                        <th data-field="entry" data-sortable="true" data-align="right">Ingreso</th>
+                        <th data-field="egress" data-sortable="true" data-align="right">Egreso</th>
+                        <th data-field="to_receive" data-sortable="true" data-align="right">A Cobrar</th>
+                        <th data-field="to_pay" data-sortable="true" data-align="right">A Pagar</th>
+                    </tr>
+                </thead>
+            </table>
+        </div>
+    </t>
+</template>

+ 0 - 0
static/src/reports/report_invoices.xml → static/src/reports/report_works.xml


+ 2 - 2
templates.xml

@@ -19,8 +19,8 @@
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_expenses.js" />
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_location.js" />
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_product.js" />
-                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_invoices.js" />
-
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_works.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_balance.js" />
             </xpath>
         </template>