Ver Fonte

Informes para golden Car]

Rodney Enciso Arias há 7 anos atrás
pai
commit
1bef38bba4

BIN
__init__.pyc


BIN
controllers.pyc


BIN
models.pyc


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

@@ -39,6 +39,11 @@ function configuration_reporting (instance, widget) {
                 title: 'Listado de productos',
                 description: 'Permite visualizar un listado de productos activos.',
                 action: 'ReportStockProduct'
+            },
+            {
+                title: 'Facturas de Cliente',
+                description: 'Permite visualizar un listado de facturas.',
+                action: 'ReportWorks'
             }
         ],
         start: function () {

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

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

+ 495 - 0
static/src/js/reports/report_invoices.js

@@ -0,0 +1,495 @@
+function report_works (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportWorksWidget = reporting.Base.extend({
+        template: 'ReportWorks',
+        invoice: [],
+        Currency:[],
+        resCurrency :[],
+        resCompany:[],
+        accountJournal:[],
+        supplier:[],
+        content:[],
+        rowsData :[],
+        // 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
+        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.fetchCarCar().then(function(CarCar) {
+                return CarCar;
+            }).then(function(CarCar){
+                self.CarCar = CarCar;
+                return self.fetchCarWorkShop();
+            }).then(function (CarWorkShop){
+                self.CarWorkShop = CarWorkShop;
+                return self.fetchAccountInvoice();
+            }).then(function(AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchCarService();
+            }).then(function(CarService){
+                self.CarService = CarService;
+                // 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;
+            }
+        },
+
+        fetchCarCar: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var CarCar = new instance.web.Model('car.car');
+            CarCar.query(['id', 'name','policy','partner_id','agent_id','date_in']).filter([['task_ids','!=', false]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            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){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchAccountInvoice: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var AccountInvoice = new instance.web.Model('account.invoice');
+            AccountInvoice.query(['id', 'number','amount_total','residual','work_invoice_id','state']).filter().all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchCarService: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var CarService = new instance.web.Model('car.service');
+            CarService.query(['id','name','secure_id']).filter().all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // Verificar si los Valores no son nulos
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            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();
+        //         }
+        //     });
+        // },
+
+        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;
+                }
+
+                if (task[0].state == 'waiting' ) {
+                    state = 'No Facturado';
+                } else {
+                    state = 'Facturado';
+                }
+                
+                data.push({
+                    id : item.id,
+                    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,
+                    state : state,
+                    pay_amount : pay_amount,
+                    secure_amount : secure_amount,
+                    particular_amount : particular_amount
+                });
+            });
+            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 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];
+            //     });
+            // }
+            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){
+            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);
+                }
+            }
+            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 : ""
+                        });
+            }
+            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 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();
+
+            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'},
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de gastos de '+ sucusal, 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('Facturas de cliente.pdf')
+        },
+    });
+}

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

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportWorks">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Trabajos Realizados</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">Exportar a 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="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="state">Estado</th>
+                        <th data-field="pay_amount">Valor Entregado</th>
+                    </tr>
+                </thead>
+            </table>
+        </div>
+    </t>
+</template>

+ 1 - 0
templates.xml

@@ -19,6 +19,7 @@
                 <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" />
 
             </xpath>
         </template>