소스 검색

[ADD] informe de trabajos

Rodney Enciso Arias 7 년 전
부모
커밋
5d47cad935
3개의 변경된 파일191개의 추가작업 그리고 235개의 파일을 삭제
  1. 2 2
      static/src/js/configuration_reporting.js
  2. 180 226
      static/src/js/reports/report_invoices.js
  3. 9 7
      static/src/reports/report_invoices.xml

+ 2 - 2
static/src/js/configuration_reporting.js

@@ -41,8 +41,8 @@ function configuration_reporting (instance, widget) {
                 action: 'ReportStockProduct'
             },
             {
-                title: 'Facturas de Cliente',
-                description: 'Permite visualizar un listado de facturas.',
+                title: 'Informe de trabajos',
+                description: 'Permite visualizar los trabajos facturados y no facturados.',
                 action: 'ReportWorks'
             }
         ],

+ 180 - 226
static/src/js/reports/report_invoices.js

@@ -36,24 +36,22 @@ function report_works (reporting){
             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();
-        // },
-
-
+        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;
@@ -70,10 +68,14 @@ function report_works (reporting){
                 return self.fetchCarService();
             }).then(function(CarService){
                 self.CarService = CarService;
-                // return self.buildTable();
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner; 
+                self.search();
+                return self.buildTable();
+                
             });
         },
-
         // Fecha
         fecthFecha: function() {
             var to;
@@ -108,7 +110,6 @@ function report_works (reporting){
                 return date;
             }
         },
-
         fetchCarCar: function () {
             var self = this;
             var defer = $.Deferred();
@@ -118,17 +119,15 @@ function report_works (reporting){
             });
             return defer;
         },
-
         fetchCarWorkShop: function () {
             var self = this;
             var defer = $.Deferred();
             var CarWorkShop = new instance.web.Model('car.workshop');
-            CarWorkShop.query(['id', 'name','vehicle_id']).filter().all().then(function(results){
+            CarWorkShop.query(['id', 'name','vehicle_id','state']).filter().all().then(function(results){
                 defer.resolve(results);
             });
             return defer;
         },
-
         fetchAccountInvoice: function () {
             var self = this;
             var defer = $.Deferred();
@@ -138,7 +137,6 @@ function report_works (reporting){
             });
             return defer;
         },
-
         fetchCarService: function () {
             var self = this;
             var defer = $.Deferred();
@@ -148,8 +146,15 @@ function report_works (reporting){
             });
             return defer;
         },
-
-        // Verificar si los Valores no son nulos
+        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){
@@ -157,252 +162,199 @@ function report_works (reporting){
             }
             return valor;
         },
-
         // Buscador
-        // inicializarBuscadorsup: function () {
-        //     var self = this;
-        //     var results = self.supplier;
-        //     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.$('#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();
-        //         }
-        //     });
-        // },
-
+        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();
+                }
+            });
+        },
         getCarWorkShop : function(id){
             var self = this;
             return _.filter(self.CarWorkShop, function(item){
                 return item.vehicle_id[0] == id;
             });
         },
-
         getAccountInvoice : function(id){
             var self = this;
             return _.filter(self.AccountInvoice, function(item){
                 return item.work_invoice_id[0] == id;
             });
         },
-
         getCarService : function(id){
             var self = this;
             return _.filter(self.CarService, function(item){
                 return item.id == id;
             });
         },
-
         buildTable: function(){
             var self = this;
-            console.log(this);
             var CarCar = self.CarCar;
             var task;
             var invoice;
-            var pay_amount;
             var state;
             var data = [];
-            var secure_amount;
-            var particular_amount;
             var car;
             _.each(CarCar, function(item){
                 task = self.getCarWorkShop(item.id);
                 car = self.getCarService(item.name[0])
-                pay_amount = 0;
-                
-                if(task.length > 0){
-                    invoice = self.getAccountInvoice(task[0].id);
-                    pay_amount = invoice[0].residual;
-                }
-                
-                if (item.policy) {
-                    secure_amount = task[0].amount_total
-                    particular_amount = 0;
-                }else{
-                    secure_amount = 0;
-                    particular_amount = task[0].amount_total;
+                var pay_amount = 0;
+                var collect_pay = 0;
+                var secure_amount = 0;
+                var particular_amount = 0;
+                invoice = self.getAccountInvoice(task[0].id);
+                if(invoice.length>0){
+                    if (item.policy) {
+                        secure_amount = invoice[0].amount_total;
+                        particular_amount = 0;
+                    }else{
+                        secure_amount = 0;
+                        particular_amount = invoice[0].amount_total;
+                    }
+                    pay_amount = invoice[0].amount_total - invoice[0].residual;
+                    collect_pay = invoice[0].residual;
                 }
-
-                if (task[0].state == 'waiting' ) {
+                if (task[0].state === 'waiting') {
                     state = 'No Facturado';
                 } else {
                     state = 'Facturado';
-                }
-                
+                }      
                 data.push({
                     id : item.id,
+                    customer_id : item.partner_id[0],
                     customer : item.partner_id[1],
                     car : item.name[1],
-                    agent : item.agent_id[1],
-                    secure : car[0].secure_id[1],
-                    date_in : item.date_in,
+                    agent : self.valorNull(item.agent_id[1]),
+                    date_in : moment(item.date_in).format("DD/MM/YYYY"),
+                    secure_amount : accounting.formatNumber(secure_amount,0,".",","),
+                    particular_amount : accounting.formatNumber(particular_amount,0,".",","),
                     state : state,
-                    pay_amount : pay_amount,
-                    secure_amount : secure_amount,
-                    particular_amount : particular_amount
+                    pay_amount : accounting.formatNumber(pay_amount,0,".",","),
+                    collect : accounting.formatNumber(collect_pay,0,".",","),
+                    intsecure_amount : secure_amount,
+                    intparticular_amount : particular_amount,
+                    intpay_amount : pay_amount,
+                    intcollect : collect_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 suc =this.$el.find('#current-journal').val();
-            var currency =this.$el.find('#current-currency').val();
-            var prov= this.$el.find('#customer').val().split('-');
+            var customer= this.$el.find('#customer').val().split('-');
             var content = self.content;
-            // Buscar por Sucursales
-            // if (suc != 9999999){
-            //     content=_.filter(content, function (inv){
-            //         return inv.journal_id == suc;
-            //     });
-            // }
-            // Buscar por fecha Desde
-            // if (desde.length > 0){
-            //     var date= desde.split('/');
-            //     content = _.filter(content, function (inv){
-            //         return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
-            //     });
-            // }
-            // Buscar por Fechas Hasta
-            // if (hasta.length > 0){
-            //     var date= hasta.split('/');
-            //     content = _.filter(content, function (inv){
-            //         return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
-            //     });
-            // }
-            // Busacar por moneda
-            // if(currency != 9999999){
-            //     content = _.filter(content,function(inv){
-            //         return inv.currency_id == currency;
-            //     });
-            // }
-            // Busacara por proveedor
-            // if (prov != ""){
-            //     content = _.filter(content, function(inv){
-            //         return inv.partner_id == prov[0];
-            //     });
-            // }
+            if (desde.length > 0){
+                var date= desde.split('/');
+                content = _.filter(content, function (inv){
+                    return inv.date_in >= (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]);
+                });
+            }
+            if (customer != ""){
+                content = _.filter(content, function(inv){
+                    return inv.customer_id == customer[0];
+                });
+            }
             self.loadTable(content)
         },
-        
-        // cargara la tabla
         loadTable:function(rowsTable){
             var self = this;
             self.rowsData = rowsTable;
             var table = this.$el.find('#table');
             table.bootstrapTable('load',rowsTable);
         },
-        
-        // Obtener Invoice por Monedad
-        getInvoice : function(currency_id){
-            var self = this;
-            return _.filter(self.rowsData, function(item){
-                return item.currency_id === currency_id;
-            });
-        },
-        
-        // Crear Objete PDF
-        getObjetPdf: function(rowsTable){
+        getObjetPdf: function(){
             var self = this;
-            var rowsPdf=[];
             var rows=[];
-            var itemCurrecy;
-            var itenRow;
-            var item;
-            var curreRate;
-            var amount_total=0;
-            var amount=0;
-            var company = _.map(self.resCompany,function(map){return map.currency_id[1]});
-
-            for (var i = 0; i < self.resCurrency.length; i++) {
-                itemCurrecy = self.resCurrency[i];
-                itenRow = self.getInvoice(itemCurrecy.id);
-                rowsPdf=[];
-                if (itenRow.length > 0){
-                    rowsPdf.push({number: itemCurrecy.name, supplier_invoice_number: "", partner: "", date: "", date_invoice: "", user: "", currency: "", amount_total: "", journal_id : "", currency_id : "", partner_id : ""});
-                    _.each(itenRow, function(item){
-                        rowsPdf.push({
-                                    number: item.number,
-                                    supplier_invoice_number: self.valorNull(item.supplier_invoice_number),
-                                    partner: item.partner,
-                                    date: moment(item.date_invoice).format("DD/MM/YYYY"),
-                                    date_invoice: item.date_invoice,
-                                    user: item.user,
-                                    currency: item.currency,
-                                    amount_total: accounting.formatNumber((item.amount),2,".",","),
-                                    amount: item.amount,
-                                    journal_id : item.journal_id,
-                                    currency_id : item.currency_id,
-                                    partner_id : item.partner_id
-                                });
-                    });
-                    curreRate = self.getCurrency(itemCurrecy.id);
-                    if (!curreRate){
-                        curreRate={};
-                        curreRate.rate=1;
-                    }
-                    amount_total= _.reduce(_.map(itenRow,function(map){
-                                    return(map.amount);
-                            }),function(memo, num){
-                                return memo + num;
-                            },0);
-                    amount = amount+(amount_total/curreRate.rate);
-                    rowsPdf.push({
-                            number: "Sub - Total "+itemCurrecy.name,
-                            supplier_invoice_number: "",
-                            partner: "",
-                            date: "",
-                            date_invoice: "",
-                            user: "",
-                            currency: "",
-                            amount_total: accounting.formatNumber((amount_total),2,".",","),
-                            journal_id : "",
-                            currency_id : "",
-                            partner_id : ""
-                        });
-                }
-                if (rowsPdf.length >0){
-                    rows = rows.concat(rowsPdf);
-                }
+            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_in >= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
             }
-            if (rows.length > 0){
-                rows.push({
-                            number: "Total en "+company,
-                            supplier_invoice_number: "",
-                            partner: "",
-                            date: "",
-                            date_invoice: "",
-                            user: "",
-                            currency: "",
-                            amount_total: accounting.formatNumber((amount),2,".",","),
-                            journal_id : "",
-                            currency_id : "",
-                            partner_id : ""
-                        });
+            if (hasta.length > 0){
+                var date= desde.split('/');
+                data = _.filter(data, function (inv){
+                    return inv.date_in <= (date[2]+"-"+date[1]+"-"+date[0]);
+                });
+            }
+            if (customer != ""){
+                data = _.filter(data, function(inv){
+                    return inv.customer_id == customer[0];
+                });
             }
+            rows = data;
+            // valor Aseguradora
+            var secure_total = _.reduce(_.map(data,function(map){
+                return(map.intsecure_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            // valor Particular
+            var particular_total = _.reduce(_.map(data,function(map){
+                return(map.intparticular_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            // Monto ya cobrado
+            var pay_total = _.reduce(_.map(data,function(map){
+                return(map.intpay_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            // Monto a Cobrar
+            var collect_total = _.reduce(_.map(data,function(map){
+                return(map.intcollect);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            rows.push({
+                id : '',
+                customer : 'Totales',
+                car : '',
+                agent : '',
+                date_in : '',
+                secure_amount : accounting.formatNumber(secure_total,0,".",","),
+                particular_amount : accounting.formatNumber(particular_total,0,".",","),
+                state : '',
+                pay_amount : accounting.formatNumber(pay_total,0,".",","),
+                collect : accounting.formatNumber(collect_total,0,".",",")
+            });
             return rows;
         },
-
-
-
         // imprimir PDF
         clickOnAction: function (e) {
             var self = this;
@@ -424,33 +376,35 @@ function report_works (reporting){
                 _.each(_.map(data2,function(val){
                         return val;
                     }), function(item){
-                            getColumns.push([{
-                                        title: item.title,
-                                        dataKey: item.field
-                                    }]);
+                    getColumns.push([{
+                        title: item.title,
+                        dataKey: item.field
+                    }]);
                 });
                 this.drawPDF(_.flatten(getColumns),rows);
             }
         },
+
         // Generar pdfDoc
         drawPDF: function (getColumns,rows) {
             var self = this;
-            var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
             var desde =(this.$el.find('#from').val());
             var hasta =(this.$el.find('#to').val());
             var totalPagesExp = "{total_pages_count_string}";
-            var pdfDoc = new jsPDF();
+            var pdfDoc = new jsPDF('l');
 
             pdfDoc.autoTable(getColumns, rows, {
                 styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
                 columnStyles: {
-                    number : {columnWidth: '8px'},
-                    supplier_invoice_number : {columnWidth: '8px'},
-                    partner : {columnWidth: '8px'},
-                    date : {columnWidth: '8px'},
-                    user : {columnWidth: '8px'},
-                    currency : {columnWidth: '8px'},
-                    amount_total: {halign:'right',columnWidth: '8px'},
+                    customer : {columnWidth: '8px'},
+                    car : {columnWidth: '8px'},
+                    agent : {columnWidth: '8px'},
+                    date_in : {columnWidth: '5px'},
+                    secure_amount : {columnWidth: '8px'},
+                    particular_amount : {columnWidth: '8px'},
+                    state: {halign:'right',columnWidth: '8px'},
+                    pay_amount: {halign:'right',columnWidth: '8px'},
+                    collect: {halign:'right',columnWidth: '8px'},
                 },
                 margin: { top: 16, horizontal: 7},
 
@@ -458,15 +412,15 @@ function report_works (reporting){
                     pdfDoc.setFontSize(12);
                     pdfDoc.setFontStyle('bold');
                     pdfDoc.setTextColor(40);
-                    pdfDoc.text('Histórico de gastos de '+ sucusal, data.settings.margin.left, 10);
+                    pdfDoc.text('Histórico de trabajos ', data.settings.margin.left, 10);
 
                     if(desde.length > 0 || hasta.length > 0){
                         var fecha='';
                         if(desde){
-                            fecha=fecha.concat(' Desde '+desde);
+                            fecha=fecha.concat(' Desde '+ desde);
                         }
                         if (hasta){
-                            fecha=fecha.concat(' Hasta '+hasta);
+                            fecha=fecha.concat(' Hasta '+ hasta);
                         }
                         pdfDoc.setFontSize(10);
                         pdfDoc.setFontStyle('bold');
@@ -489,7 +443,7 @@ function report_works (reporting){
             if (typeof pdfDoc.putTotalPages === 'function') {
                 pdfDoc.putTotalPages(totalPagesExp);
             }
-            pdfDoc.save('Facturas de cliente.pdf')
+            pdfDoc.save('Historico de Trabajos.pdf')
         },
     });
 }

+ 9 - 7
static/src/reports/report_invoices.xml

@@ -17,7 +17,8 @@
                 <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">Exportar a PDF</button>
+                <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"
@@ -34,13 +35,14 @@
                     <tr>
                         <th data-field="customer" data-sortable="true">Cliente</th>
                         <th data-field="car">Vehiculo</th>
-                        <th data-field="agent">Agente</th>
-                        <th data-field="secure">Aseguradora</th>
-                        <th data-field="date_in">Fecha</th>
-                        <th data-field="secure_amount">Valor Aseguradora</th>
-                        <th data-field="particular_amount">Valor Particular</th>
+                        <th data-field="agent">Aseguradora / Agente</th>
+                        <!-- <th data-field="secure">Aseguradora</th> -->
+                        <th data-field="date_in">Fecha de Ingreso</th>
+                        <th data-field="secure_amount" data-sortable="true" data-align="right">Valor Aseguradora</th>
+                        <th data-field="particular_amount" data-sortable="true" data-align="right">Valor Particular</th>
                         <th data-field="state">Estado</th>
-                        <th data-field="pay_amount">Valor Entregado</th>
+                        <th data-field="pay_amount" data-sortable="true" data-align="right">Valor Entregado</th>
+                        <th data-field="collect" data-sortable="true" data-align="right">Por Cobrar</th>
                     </tr>
                 </thead>
             </table>