Browse Source

ADD FIX Actualización de eiru reporting filtros y nuevos reportes

Sebas 7 years ago
parent
commit
f0281a0412
47 changed files with 10214 additions and 211 deletions
  1. BIN
      __init__.pyc
  2. BIN
      controllers.pyc
  3. BIN
      models.pyc
  4. 63 14
      static/src/js/configuration_reporting.js
  5. 24 7
      static/src/js/main.js
  6. 422 0
      static/src/js/reports/report_balance.js
  7. 488 0
      static/src/js/reports/report_crm.js
  8. 93 29
      static/src/js/reports/report_expenses.js
  9. 655 0
      static/src/js/reports/report_expenses_invoice_analysis.js
  10. 512 0
      static/src/js/reports/report_invoice_balance.js
  11. 1 0
      static/src/js/reports/report_invoice_utility.js
  12. 482 0
      static/src/js/reports/report_mensajecrm.js
  13. 512 0
      static/src/js/reports/report_phonecall.js
  14. 486 0
      static/src/js/reports/report_project.js
  15. 1 1
      static/src/js/reports/report_puchases.js
  16. 614 0
      static/src/js/reports/report_purchases_invoice_analysis.js
  17. 98 30
      static/src/js/reports/report_resumen_egresos.js
  18. 126 51
      static/src/js/reports/report_resumen_ingresos.js
  19. 356 0
      static/src/js/reports/report_sales.js
  20. 668 0
      static/src/js/reports/report_sales_invoice_analysis.js
  21. 319 0
      static/src/js/reports/report_stock.js
  22. 493 0
      static/src/js/reports/report_stock_move.js
  23. 448 0
      static/src/js/reports/report_vouchers.js
  24. 561 0
      static/src/js/reports/report_works.js
  25. 445 0
      static/src/js/reports/reporting_account.js
  26. 443 0
      static/src/js/reports/reporting_accountpending.js
  27. 99 0
      static/src/reports/report_balance.xml
  28. 111 0
      static/src/reports/report_crm.xml
  29. 67 16
      static/src/reports/report_expenses.xml
  30. 104 0
      static/src/reports/report_expenses_invoice_analysis.xml
  31. 139 0
      static/src/reports/report_invoice_balance.xml
  32. 95 0
      static/src/reports/report_mensajecrm.xml
  33. 96 0
      static/src/reports/report_phonecall.xml
  34. 95 0
      static/src/reports/report_project.xml
  35. 111 0
      static/src/reports/report_purchases_invoice_analysis.xml
  36. 62 13
      static/src/reports/report_resumen_egresos.xml
  37. 93 43
      static/src/reports/report_resumen_ingresos.xml
  38. 96 0
      static/src/reports/report_sales.xml
  39. 104 0
      static/src/reports/report_sales_invoice_analysis.xml
  40. 60 0
      static/src/reports/report_stock.xml
  41. 111 0
      static/src/reports/report_stock_move.xml
  42. 0 1
      static/src/reports/report_stock_product.xml
  43. 116 0
      static/src/reports/report_vouchers.xml
  44. 101 0
      static/src/reports/report_works.xml
  45. 101 0
      static/src/reports/reporting_account.xml
  46. 102 0
      static/src/reports/reporting_accountpending.xml
  47. 41 6
      templates.xml

BIN
__init__.pyc


BIN
controllers.pyc


BIN
models.pyc


+ 63 - 14
static/src/js/configuration_reporting.js

@@ -2,8 +2,6 @@ function configuration_reporting (instance, widget) {
     "use strict";
     var widgets = widget;
 
-
-
     widget.ReportingWidget = instance.Widget.extend({
         template: 'EiruReporting',
         events: {
@@ -21,25 +19,76 @@ function configuration_reporting (instance, widget) {
                 action: 'ReportResumenEngreso'
             },
             {
-                title: 'Utilidad de facturas detalladas',
-                description: 'Permite visualizar la ganancia de cada ítem de las facturas detalladamente.',
-                action: 'ReportInvoiceUtility'
+               title: 'Balance de sumas y saldos',
+               description: 'Permite visualizar un balance de Ingreso y Egreso',
+               action: 'ReportBalance'
+            },
+            {
+                title: 'Histórico de Pagos',
+                description: 'Permite visualizar de todos los pagos.',
+                action: 'ReportVoucher'
+            },
+            {
+                title: 'Histórico de Facturas',
+                description: 'Permite visualizar las facturas',
+                action: 'ReportInvoiceBalance'
+            },
+            {
+                title: 'Análisis de Ventas',
+                description: 'Permite realizar un analisis de las facturas de venta.',
+                action: 'ReportSaleInvoiceAnalysis'
+            },
+            {
+                title: 'Informe de Trabajos',
+                description: 'Permite visualizar los trabajos facturados y no facturados.',
+                action: 'ReportWorks'
+            },
+            {
+                title: 'Análisis de Compras y Gastos',
+                description: 'Permite realizar un analisis de las facturas de compra y de gastos',
+                action: 'ReportPurchaseInvoiceAnalysis'
             },
             {
-                title: 'Histórico de compras',
-                description: 'Permite visualizar un histórico de compras realizado por la empresa.',
-                action: 'AllPurchases'
+                title: 'Análisis de Stock',
+                description: 'Permite realizar un analisis de los productos disponibles en el stock.',
+                action: 'ReportStock'
             },
             {
-                title: 'Histórico de gastos',
-                description: 'Permite visualizar un histórico de gastos realizado por la empresa.',
-                action: 'ReposrtExpenses'
+                title: 'Análisis de Movimientos de Stock',
+                description: 'Permite realizar un analisis de los productos disponibles en el stock.',
+                action: 'ReportStockMove'
             },
             {
-                title: 'Listado de productos',
-                description: 'Permite visualizar un listado de productos activos.',
-                action: 'ReportStockProduct'
+                title: 'Histórico de Llamadas CRM',
+                description: 'Permite visualizar las llamadas CRM',
+                action: 'ReportPhoneCall'
+            },
+            {
+                title: 'Histórico CRM',
+                description: 'Permite visualizar un histórico de CRM realizado por la empresa.',
+                action: 'ReportCrm'
+            },
+            {
+                title: 'Histórico Mensaje CRM',
+                description: 'Permite visualizar un histórico de mensaje realizado por la empresa.',
+                action: 'ReportMensajeCrm'
+            },
+            {
+                title: 'Listado de Cuentas Vencidas a Cobrar',
+                description: 'Permite visualizar un listado de cuentas vencidas a cobrar.',
+                action: 'ReportingAccount'
+            },
+            {
+                title: 'Listado de Cuentas a Cobrar',
+                description: 'Permite visualizar un listado de cuentas a cobrar.',
+                action: 'ReportingAccountPending'
+            },
+            {
+                title: 'Listado de Proyectos',
+                description: 'Permite visualizar un listado de proyectos.',
+                action: 'ReportProject'
             }
+
         ],
         start: function () {
         },

+ 24 - 7
static/src/js/main.js

@@ -7,15 +7,32 @@ openerp.eiru_reporting = function (instance) {
     reporting_base(instance,reporting);
     configuration_reporting(instance,reporting);
 
+
     // Lista de Reporte
-    report_invoice_utility(reporting);
-    report_resumen_engreso(reporting);
-    report_resumen_ingresos(reporting);
-    report_puchases(reporting);
-    report_expenses(reporting);
-    // report_stock_location(reporting);
-    report_stock_product(reporting);
+    try {
+
+        report_resumen_ingresos(reporting);
+        report_resumen_egresos(reporting);
+        report_vouchers(reporting);
+        report_invoice_balance(reporting);
+        report_sales_invoice_analysis(reporting);
+        report_purchases_invoice_analysis(reporting);
+        report_stock(reporting);
+        report_stock_move(reporting);
+        report_crm(reporting);
+        report_mensajecrm(reporting);
+        report_phonecall(reporting);
+        report_project(reporting);
+        reporting_account(reporting);
+        reporting_accountpending(reporting);
+        report_balance(reporting);
+        report_works(reporting);
+
+    } catch (e) {
+
+        // ignorar error
 
+    }
 
     instance.web.client_actions.add('eiru_reporting.action_report', 'instance.eiru_reporting.ReportingWidget');
 }

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

@@ -0,0 +1,422 @@
+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',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+            '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:"Factura",
+                    type: 'ir.actions.act_window',
+                    res_model: "account.invoice",
+                    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]]).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 hoy = moment().format('YYYY-MM-DD');
+            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 ($('#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);
+                date[2] = '0'+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;
+                date.splice(1,0);
+                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 (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=[];
+            rows = self.rowsData;
+
+            // Valor de la Factura
+            var intamount_total = _.reduce(_.map(rows,function(map){
+                return(map.intamount_total);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            // Ingreso
+            var intentry = _.reduce(_.map(rows,function(map){
+                return(map.intentry);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            // Egreso
+            var integress = _.reduce(_.map(rows,function(map){
+                return(map.integress);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            // Monto a Cobrar
+            var intreceive = _.reduce(_.map(rows,function(map){
+                return(map.intreceive);
+            }),function(memo, num){
+                return memo + num;
+            },0); 
+            var intpay = _.reduce(_.map(rows,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')
+        },
+    });
+}

+ 488 - 0
static/src/js/reports/report_crm.js

@@ -0,0 +1,488 @@
+function report_crm(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportCrmWidget = reporting.Base.extend({
+        template:'ReportCrm',
+        AccountVoucher: [],
+        content:[],
+        rowsData :[],
+        modules:[],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #opportunity' : 'factSearch',
+            'click #lead' : 'factSearch',
+            'click #Z' : 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click #customer' : '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();
+        },
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'description'){
+                this.do_action({
+                    name:"CRM",
+                    type: 'ir.actions.act_window',
+                    res_model: "crm.lead",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['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.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fetchCrm();
+            }).then(function (AccountVoucher) {
+                self.AccountVoucher = AccountVoucher;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        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;
+            }
+        },
+
+        fetchCrm: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('crm');
+            //
+            if (modules.length <= 0){
+                self.showMensaje('crm');
+                return defer;
+            }
+            var AccountVoucher = new instance.web.Model('crm.lead');
+            AccountVoucher.query(['id', 'partner_id', 'name', 'description', 'create_date', 'user_id', 'stage_id', 'type']).filter([['active', '=', true]]).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]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getAccountVoucher: function (id) {
+            var self = this;
+            return _.filter(self.AccountVoucher,function (item) {
+                return item.id == id;
+            });
+        },
+
+        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();
+                }
+            });
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var AccountVoucher = self.AccountVoucher;
+            var invoice;
+            var data = [];
+            var crm_type;
+
+            _.each(AccountVoucher, function(item){
+                if (item.type == 'lead') {
+                    crm_type = 'lead';
+                } else {
+                    crm_type = 'opportunity';
+                }
+
+                invoice = self.getAccountVoucher(item.id).shift();
+                data.push({
+                  id : item.id,
+                  name : self.valorNull(item.name),
+                  description: self.valorNull(item.description),
+                  partner: item.partner_id[1],
+                  create_date: moment(item.create_date).format("DD/MM/YYYY"),
+                  date: moment(item.create_date).format("YYYY-MM-DD"),
+                  user: item.user_id[1],
+                  crm_type: crm_type,
+                  stage: item.stage_id[1],
+                  partner_id : item.partner_id[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 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 ($('#lead').is(":checked")){
+                content = _.filter(content, function (inv){
+                    return inv.crm_type == 'lead';
+                });
+            }
+            if ($('#opportunity').is(":checked")){
+                content = _.filter(content, function (inv){
+                    return inv.crm_type == 'opportunity';
+                });
+            }
+
+             if (partner != ""){
+                 content = _.filter(content, function(inv){
+                     return inv.partner_id == partner[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(rowsTable){
+             var self = this;
+             var rowsPdf=[];
+             var rows=[];
+             var rows = self.rowsData;
+             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.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 Cabecera
+                 _.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 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: {
+                  name : {columnWidth: '8px'},
+                  description : {columnWidth: '8px'},
+                  partner : {columnWidth: '8px'},
+                  date : {columnWidth: '8px'},
+                  stage : {columnWidth: '8px'},
+                  user : {columnWidth: '8px'}
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de crm ', data.settings.margin.left, 10);
+                    var tipo = '';
+
+                    if ($('#lead').is(":checked")){
+                        tipo = tipo.concat(' Tipo de CRM : Iniciativas' );
+                    }
+                    if ($('#opportunity').is(":checked")){
+                        tipo = tipo.concat(' Tipo de CRM : Oportunidades' );
+                    }
+
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('normal');
+                    pdfDoc.setTextColor(40)
+                    pdfDoc.text(6,14,tipo);
+
+                    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('Histórico de crm.pdf')
+        },
+    });
+}

+ 93 - 29
static/src/js/reports/report_expenses.js

@@ -16,12 +16,22 @@ function report_expenses (reporting){
         // event
         events:{
             'click #toolbar > button' : 'clickOnAction',
+            'click  #volver_btn' : 'volver',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click #supplier' : 'factSearch',
+
             'change #current-journal' : 'factSearch',
             'change #current-currency' : 'factSearch',
             'change #from' : 'factSearch',
             'change #to' : 'factSearch',
-            'click  #volver_btn' : 'volver',
-            'click-row.bs.table #table ' : 'ckickAnalysisDetail',
+            'click-row.bs.table #table ' : 'clickAnalysisDetail',
         },
         // Initil
         init : function(parent){
@@ -52,15 +62,7 @@ function report_expenses (reporting){
             }
             e.stopImmediatePropagation();
         },
-        // volver
-        volver: function(){
-            this.$el.find('#volver').empty();
-            this.$el.find('.bootstrap-table').show({
-                effect: 'drop',
-                direction: 'down',
-                duration: 200,
-            });
-        },
+
         // Consultar
         submitForm: function () {
             var self = this;
@@ -224,11 +226,11 @@ function report_expenses (reporting){
                         value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
                 }
             });
-            self.$('#customer').autocomplete({
+            self.$('#supplier').autocomplete({
                 source: results,
                 minLength:0,
                 search: function(event, ui) {
-                    if (!(self.$('#customer').val())){
+                    if (!(self.$('#supplier').val())){
                         self.factSearch();
                     }
                 },
@@ -240,6 +242,17 @@ function report_expenses (reporting){
                 }
             });
         },
+
+        // volver
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+
         // unir los objetos
         fect_generar: function(invoices){
             var self = this;
@@ -269,30 +282,81 @@ function report_expenses (reporting){
             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 journal =this.$el.find('#current-journal').val();
             var currency =this.$el.find('#current-currency').val();
-            var prov= this.$el.find('#customer').val().split('-');
+            var prov= this.$el.find('#supplier').val().split('-');
             var newInvoice = self.newInvoice;
-            // Buscar por Sucursales
-            if (suc != 9999999){
-                newInvoice=_.filter(newInvoice, function (inv){
-                    return inv.journal_id == suc;
+            if ($('#A').is(":checked")){
+                content = _.filter(content, function (inv){
+                    return inv.date == hoy;
                 });
             }
-            // Buscar por fecha Desde
-            if (desde.length > 0){
-                var date= desde.split('/');
-                newInvoice = _.filter(newInvoice, function (inv){
-                    return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
+            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];
                 });
             }
-            // Buscar por Fechas Hasta
-            if (hasta.length > 0){
-                var date= hasta.split('/');
-                newInvoice = _.filter(newInvoice, function (inv){
-                    return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
+            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');
+            }
+            // Buscar por Sucursales
+            if (journal != 9999999){
+                newInvoice=_.filter(newInvoice, function (inv){
+                    return inv.journal_id == journal;
+                });
+            }
+
             // Busacar por moneda
             if(currency != 9999999){
                 newInvoice = _.filter(newInvoice,function(inv){

+ 655 - 0
static/src/js/reports/report_expenses_invoice_analysis.js

@@ -0,0 +1,655 @@
+function report_expenses_invoice_analysis (reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportExpenseInvoiceAnalysisWidget = reporting.Base.extend({
+        template: 'ReportExpenseInvoiceAnalysis',
+        invoices: [],
+        invoiceLines: [],
+        productProduct:[],
+        Currency:[],
+        rowsData :[],
+        rowOrigin:[],
+        accountJournal:[],
+        resCompany:[],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'fectSearch',
+            'click #A' : 'fectSearch',
+            'click #B' : 'fectSearch',
+            'click #C' : 'fectSearch',
+            'click #D' : 'fectSearch',
+            'click #Z' : 'fectSearch',
+            'change #current-journal': 'fectSearch',
+            'change #from' : 'fectSearch',
+            'change #to': 'fectSearch',
+            'click #volver_btn': 'volver',
+            'click-row.bs.table #table' : 'ckickAnalysisDetail',
+        },
+        init : function(parent){
+          this._super(parent);
+        },
+        start: function () {
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowOrigin});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        ckickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'name'){
+                this.do_action({
+                    name : "Variantes de Producto",
+                    type : 'ir.actions.act_window',
+                    res_model : "product.product",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['id','=', row.id_product]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.id_product,
+                });
+            }
+            if (field == 'number'){
+                this.do_action({
+                    name : "Factura de Cliente",
+                    type : 'ir.actions.act_window',
+                    res_model : "account.invoice",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['type', '=', 'out_invoice'],['id','=', row.id]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.id,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('#grafico').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Cansultar
+        submitForm: function () {
+            var self = this;
+            this.fetchCurency().then(function(Currency) {
+                self.Currency = Currency;
+                return Currency;
+            }).then(function (Currency) {
+                return self.fetchJournal();
+            }).then(function (journal) {
+                self.accountJournal =journal;
+                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
+                _.each(journal, function (item) {
+                  self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fetchInvoiceV2();
+            }).then(function (invoices){
+                self.invoices = invoices;
+                return self.fetchInvoiceLine(invoices);
+            }).then(function (invoiceLines) {
+                self.invoiceLines = invoiceLines;
+                return self.fecthProduct(invoiceLines);
+            }).then(function(productProduct){
+                self.productProduct = productProduct;
+                return self.fecthComanyCurrency();
+            }).then(function(resCompany){
+                self.resCompany = resCompany;
+            return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                self.searchProduct();
+                return self.invoice_Currency();
+            });
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new model.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // 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;
+            }
+          },
+        // Buscar Diario
+        fetchJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var Journal = new model.web.Model('account.journal');
+            Journal.query(['id', 'name']).filter([['type', '=', 'purchase'], ['active', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+              return defer;
+        },
+        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
+        fetchCurency: function () {
+            var defer = $.Deferred();
+            var currency_Rate = new model.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+          },
+        // Invoice (FACTURAS)
+        fetchInvoiceV2: function () {
+            var filter = [['state', 'in',['open','paid']],['type', '=', 'in_invoice'],['origin','=',false]];
+            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
+                return item.id;
+            }));
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice','partner_id'];
+            var defer = $.Deferred();
+            var Invoice = new model.web.Model('account.invoice');
+            Invoice.query(field).filter(filter).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Invoice line (Linea de Factura)
+        fetchInvoiceLine: function (invoices) {
+            var defer = $.Deferred();
+            var linesIds = _.flatten(_.map(invoices, function (item) {
+                return item.invoice_line;
+            }));
+            var InvoiceLine = new model.web.Model('account.invoice.line');
+            InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        fetchResPartner: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id','name','ruc']).filter([['active', '=', true],['supplier', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Product Product
+        fecthProduct: function(invoiceLines){
+            var defer = $.Deferred();
+            var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
+                return item.product_id[0];
+            }));
+            var ProductProdcut =  new model.web.Model('product.product');
+            var fields = ['id','name', 'default_code', 'name_template','ean13', 'standard_price','type'];
+            ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        // Obtener Monedas de la Factura
+        getCutrrency: function (id){
+            return _.find(this.Currency,function (curr) {
+                return _.contains(curr.currency_id,id);
+            });
+        },
+        // Actualizar cambio de las moneda de Factura
+        invoice_Currency: function(){
+            for (var i = 0; i < this.invoices.length; i++) {
+                var currency_new;
+                var item = this.invoices[i];
+                var id = item.currency_id[0];
+                currency_new = this.getCutrrency(id);
+                if (!currency_new){
+                    currency_new={};
+                    currency_new.rate=1;
+                }
+                this.invoices[i].rate=(currency_new.rate);
+            }
+            return this.fectUtility();
+        },
+        // Obtener la Detalles de la Factura
+        getInvoice: function (id_line){
+            return _.find(this.invoices, function (inv) {
+                return _.contains(inv.invoice_line, id_line);
+            });
+          },
+        // Obtener las lineas de las Facturas
+        getProduct: function(pro_id){
+            return _.find(this.productProduct, function(prod){
+                return _.contains(pro_id, prod.id);
+            });
+        },
+        // unir los objetos
+        fectUtility: function(){
+            var data=[];
+            var item;
+            var invoice;
+            var producto;
+
+            for (var i = 0; i < this.invoiceLines.length; i++) {
+                item = this.invoiceLines[i];
+                invoice = this.getInvoice(item.id);
+                producto =this.getProduct(item.product_id);
+                if (!producto){
+                    producto={};
+                    producto.standard_price=0;
+                }
+                data.push({
+                    id : invoice.id,
+                    number : (invoice.number),
+                    id_product : producto.id,
+                    name : (item.name),
+                    quantity : accounting.formatNumber((item.quantity),0, ".", ","),
+                    price_unity : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
+                    standar_tot : accounting.formatNumber((item.quantity * item.price_unit),2, ".", ","),
+                    journal_id :(invoice.journal_id[0]),
+                    journal_name :(invoice.journal_id[1]),
+                    date_invoice : (invoice.date_invoice),
+                    partner_id : invoice.partner_id[0],
+                    partner_name : invoice.partner_id[1]
+                });
+          }
+          this.rowsData=data;
+          this.rowOrigin=data;
+          this.loadTable(data)
+        },
+        // Buscar
+        fectSearch: function(){
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            var partner = this.$el.find('#partner').val().split('-');
+            var product = this.$el.find('#product').val().split('-');
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            self.rowsData=self.rowOrigin;
+
+            if ($('#A').is(":checked")){
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.date_invoice == hoy;
+                });
+            }
+            if ($('#B').is(":checked")){
+                var date = hoy.split('-');
+                var ayer = date[2] - 1;
+                date.splice(2,0);
+                date[2] = '0'+ayer;
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.date_invoice == date[0]+'-'+date[1]+'-'+date[2];
+                });
+            }
+            if ($('#C').is(":checked")){
+                var date = hoy.split('-');
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    var mes = inv.date_invoice.split('-');
+                    return mes[0]+'-'+mes[1] == date[0]+'-'+date[1];
+                });
+            }
+            if ($('#D').is(":checked")){
+                var date = hoy.split('-');
+                var mes = date[1] - 1;
+                date.splice(1,0);
+                if(date[1] < 10){
+                    date[1] = '0'+mes;
+                }else{
+                    date[1] = mes;
+                }
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    var mes = inv.date_invoice.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('/');
+                    self.rowsData = _.filter(self.rowsData, function (inv){
+                        return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    self.rowsData = _.filter(self.rowsData, function (inv){
+                        return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+            if (partner != ""){
+                self.rowsData = _.filter(self.rowsData, function(inv){
+                    return inv.partner_id == partner[0];
+                });
+            }
+            if (product != ""){
+                self.rowsData = _.filter(self.rowsData, function(inv){
+                    return inv.id_product == product[0];
+                });
+            }
+            self.loadTable(self.rowsData);
+        },
+        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.fectSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.fectSearch();
+                },
+                select: function(event, ui) {
+                    self.fectSearch();
+                }
+            });
+        },
+        searchProduct: function () {
+            var self = this;
+            var results = self.productProduct;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '-'+ item.name,
+                        value: item.id + '-'+ item.name
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.fectSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.fectSearch();
+                },
+                select: function(event, ui) {
+                    self.fectSearch();
+                }
+            });
+        },
+        // cargara la tabla
+        loadTable:function(rowsTable){
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load', rowsTable);
+        },
+        // imprimir PDF
+        clickOnAction: function (e) {
+            var action = this.$el.find(e.target).val();
+            var self = this;
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){ return val.field});
+                _.each(this.rowsData,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
+                                }]);
+                });
+                // Llamar al pdf
+                this.drawPDF(_.flatten(getColumns),rows)
+            }
+            if (action === 'chart'){
+                var suc =this.$el.find('#current-journal').val();
+                if (suc == 9999999){
+                    self.fectCharFilter();
+                }else{
+                    $("#dialog" ).dialog({
+                        autoOpen: true,
+                        resizable: false,
+                        modal: true,
+                        title: 'Atención',
+                        open: function() {
+                            $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
+                        },
+                        show: {
+                            effect: "shake",
+                            duration: 300
+                        },
+                        hide: {
+                            effect: "fade",
+                            duration: 300
+                        },
+                        buttons: {
+                            Aceptar: function() {
+                                $(this).dialog('close');
+                            }
+                        }
+                    });
+                }
+            }
+        },
+        // Generar pdfDoc
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var rowsPdf=[];
+            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();
+
+            // rows=this.rowsData;
+            var quantity=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.quantity){valor = parseFloat(((item.quantity.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var precio_unit=_.reduce(_.map(rows,function(item){
+                var valor =0;
+                if (item.price_unity){valor=parseFloat(((item.price_unity.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num; },0);
+            var precio_cost=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if(item.standar_price){valor=parseFloat(((item.standar_price.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num;},0);
+            var tot_unit=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.price_tot){valor=parseFloat(((item.price_tot.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var tol_cost=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.standar_tot){valor=parseFloat(((item.standar_tot.replace(".","")).replace(",",".")))} return valor }), function(memo, num){ return memo + num; },0);
+            var utility=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.utility){valor=parseFloat(((item.utility.replace(".","")).replace(",",".")))}return valor }), function(memo, num){ return memo + num; },0);
+
+            rowsPdf=rows;
+
+            var company = _.map(self.resCompany, function (map) {
+                return map.currency_id[1];
+            });
+            rowsPdf.push({
+                        number : "TOTAL "+company,
+                        name : " ",
+                        quantity: accounting.formatNumber(quantity,0, ".", ","),
+                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
+                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
+                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
+                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
+                        utility : accounting.formatNumber(utility,2, ".", ",")
+                    });
+
+            rowsPdf.unshift({
+                        number : "TOTAL "+company,
+                        name : " ",
+                        quantity: accounting.formatNumber(quantity,0, ".", ","),
+                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
+                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
+                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
+                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
+                        utility : accounting.formatNumber(utility,2, ".", ",")
+                    });
+
+            pdfDoc.autoTable(getColumns, rowsPdf, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                              number: {fontStyle: 'bold'},
+                              name :{columnWidth: '10px'},
+                              quantity :{halign:'right' },
+                              price_unity : {halign:'right' },
+                              standar_price : {halign:'right' },
+                              price_tot : {halign:'right' },
+                              standar_tot : {halign:'right' },
+                              utility : {halign:'right'},
+                          },
+                margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Análisis de facturas de compra ', 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('Análisis de facturas de compra.pdf')
+        },
+        // Chart Filter
+        fectCharFilter: function(){
+          var self = this;
+          var dataBody=[];
+          var dataHeader=[];
+
+          var canvas="<canvas id='graf_resume'></canvas>";
+          this.$el.find('#grafico').append(canvas);
+
+          _.each(self.accountJournal, function(journal){
+            dataHeader.push(journal.name);
+            var utility=_.reduce(_.map(_.filter(self.rowsData, function (inv){ return inv.journal_id == journal.id}),function(item){
+              return parseFloat(((item.utility.replace(".","")).replace(",",".")))}), function(memo, num){ return memo + num; },0);
+            dataBody.push(accounting.toFixed((utility),2));
+          });
+          var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
+
+          this.$el.find('#volver').append(selector);
+
+          this.$el.find('.bootstrap-table').hide({
+              effect: 'drop',
+              direction: 'up',
+              duration: 200,
+              complete: function () {
+                self.drawChart(dataHeader,dataBody);
+              }
+          });
+        },
+        // Chart
+        drawChart: function (dataHeader,dataBody) {
+            var barChart = new Chart(this.$el.find('#graf_resume'), {
+                type: 'doughnut',
+                data: {
+                    labels: dataHeader,
+                    datasets: [
+                        {
+                            labels: dataHeader,
+                            backgroundColor: [
+                                'rgba(255, 99, 132, 0.2)',
+                                'rgba(54, 162, 235, 0.2)',
+                                'rgba(255, 206, 86, 0.2)',
+                                'rgba(75, 192, 192, 0.2)',
+                                'rgba(153, 102, 255, 0.2)',
+                            ],
+                            borderColor: [
+                                'rgba(255,99,132,1)',
+                                'rgba(54, 162, 235, 1)',
+                                'rgba(255, 206, 86, 1)',
+                                'rgba(75, 192, 192, 1)',
+                                'rgba(153, 102, 255, 1)',
+                            ],
+                            borderWidth: 1,
+                            data: dataBody,
+                        }
+                    ]
+                },
+                options: {
+                    maintainAspectRatio: false,
+                    layout: {
+                        padding: 30
+                    }
+                },
+            });
+        },
+    });
+}

+ 512 - 0
static/src/js/reports/report_invoice_balance.js

@@ -0,0 +1,512 @@
+function report_invoice_balance (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportInvoiceBalanceWidget = reporting.Base.extend({
+        template: 'ReportInvoiceBalance',
+        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 #current-journal' : 'factSearch',
+            'change #current-currency' : '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.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;
+            }
+        },
+        fetchAccountInvoice: function () {
+            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();
+                }
+            });
+        },
+        BuildTable: function(){
+            var self = this;
+            var data = [];
+            var AccountInvoice = self.AccountInvoice;
+            var entry;
+            var egress;
+            var to_receive;
+            var to_pay;
+            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';
+                    }
+                }
+                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],
+                });
+            });
+            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 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];
+                });
+            }
+            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 = self.rowsData;
+            var amount_total =_.reduce(_.map(rows,function(item){
+                var valor = 0;
+                if (item.amount_total){
+                    valor = parseFloat(((item.amount_total.replace(".","")).replace(",",".")))
+                }return valor
+            }), function(memo, num){
+                return memo + num;
+            },0);
+            var entry =_.reduce(_.map(rows,function(item){
+                var valor = 0;
+                if (item.entry){
+                    valor = parseFloat(((item.entry.replace(".","")).replace(",",".")))
+                }return valor
+            }), function(memo, num){
+                return memo + num;
+            },0);
+            var egress =_.reduce(_.map(rows,function(item){
+                var valor = 0;
+                if (item.egress){
+                    valor = parseFloat(((item.egress.replace(".","")).replace(",",".")))
+                }return valor
+            }), function(memo, num){
+                return memo + num;
+            },0);
+            var to_receive =_.reduce(_.map(rows,function(item){
+                var valor = 0;
+                if (item.to_receive){
+                    valor = parseFloat(((item.to_receive.replace(".","")).replace(",",".")))
+                }return valor
+            }), function(memo, num){
+                return memo + num;
+            },0);
+            var to_pay =_.reduce(_.map(rows,function(item){
+                var valor = 0;
+                if (item.to_pay){
+                    valor = parseFloat(((item.to_pay.replace(".","")).replace(",",".")))
+                }return valor
+            }), function(memo, num){
+                return memo + num;
+            },0);
+            if (rows.length > 0){
+                rows.push({
+                    number: "Totales ",
+                    amount_total: accounting.formatNumber(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,".",","),
+                });
+            }
+            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();
+
+            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: 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 Facturas.pdf')
+        },
+    });
+}

+ 1 - 0
static/src/js/reports/report_invoice_utility.js

@@ -20,6 +20,7 @@ function report_invoice_utility (reporting){
             'change #from' : 'fectSearch',
             'change #to': 'fectSearch',
             'click #volver_btn': 'volver',
+            
             // 'click-row.bs.table #table ' : 'ckickAnalysisDetail',
             'click-row.bs.table #table' : 'ckickAnalysisDetail',
         },

+ 482 - 0
static/src/js/reports/report_mensajecrm.js

@@ -0,0 +1,482 @@
+function report_mensajecrm(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportMensajeCrmWidget = reporting.Base.extend({
+        template:'ReportMensajeCrm',
+        Crm: [],
+        MensajeCrm: [],
+        content:[],
+        rowsData :[],
+        modules:[],
+        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 #customer' : '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();
+        },
+
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'description'){
+                 this.do_action({
+                     name:"CRM Mensaje",
+                     type: 'ir.actions.act_window',
+                     res_model: "crm.mensaje",
+                     views: [[false,'form']],
+                     target: 'new',
+                     domain: [['id','=', row.id]],
+                     context: {},
+                     flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                     res_id: row.id,
+                 });
+            }
+            if (field === 'partner'){
+                this.do_action({
+                    name:"Registro Cliente",
+                    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.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fetchMensajeCrm();
+            }).then(function(MensajeCrm) {
+                self.MensajeCrm = MensajeCrm;
+                return self.fetchCrm();
+            }).then(function (Crm) {
+                self.Crm = Crm;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        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;
+            }
+        },
+
+        fetchMensajeCrm: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('crm_mensaje');
+            if (modules.length <= 0){
+                self.showMensaje('crm_mensaje');
+                return defer;
+            }
+            var MensajeCrm = new instance.web.Model('crm.mensaje');
+            MensajeCrm.query(['id', 'partner_id', 'name', 'date', 'opportunity_id', 'partner_mobile', 'user_id', 'state']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        fetchCrm: function () {
+            var self = this;
+            var defer = $.Deferred();
+
+            var Crm = new instance.web.Model('crm.lead');
+            Crm.query(['id', 'name', 'description', 'create_date', 'user_id', 'stage_id', 'type']).filter([['active', '=', true]]).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]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getCrm: function (id) {
+            var self = this;
+            return _.filter(self.Crm,function (item) {
+                return item.opportunity_id == id;
+            });
+        },
+
+        getMensajeCrm: function (id) {
+            var self = this;
+            return _.filter(self.MensajeCrm,function (item) {
+                return item.id == id;
+            });
+        },
+
+        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();
+                }
+            });
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var mensajecrm = self.MensajeCrm;
+            var invoice;
+            var Crm;
+            var data = [];
+
+            _.each(mensajecrm, function(item){
+
+                invoice = self.getMensajeCrm(item.id).shift();
+                Crm = self.getCrm(item.id);
+
+
+                data.push({
+                    id : item.id,
+                    opportunity_id : self.valorNull(item.opportunity_id[1]),
+                    partner: self.valorNull(item.partner_id[1]),
+                    description: self.valorNull(item.name),
+                    create_date: moment(item.date).format("DD/MM/YYYY"),
+                    date: moment(item.date).format("YYYY-MM-DD"),
+                    user: item.user_id[1],
+                    stage: item.state,
+                    partner_id : item.partner_id[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 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 (partner != ""){
+                 content = _.filter(content, function(inv){
+                     return inv.partner_id == partner[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(rowsTable){
+             var self = this;
+             var rowsPdf=[];
+             var rows=[];
+             var rows = self.rowsData;
+             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.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 Cabecera
+                 _.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 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: {
+                  opportunity_id : {columnWidth: '8px'},
+                  partner : {columnWidth: '8px'},
+                  description : {columnWidth: '8px'},
+                  date : {columnWidth: '8px'},
+                  stage : {columnWidth: '8px'},
+                  user : {columnWidth: '8px'}
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de mensajes de crm ', 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('Histórico de mensajes crm.pdf')
+        },
+    });
+}

+ 512 - 0
static/src/js/reports/report_phonecall.js

@@ -0,0 +1,512 @@
+function report_phonecall(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportPhoneCallWidget = reporting.Base.extend({
+        template:'ReportPhoneCall',
+        Crm: [],
+        CrmPhone: [],
+        content:[],
+        rowsData :[],
+        modules:[],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #volver_btn' : 'volver',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click #customer' : '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();
+        },
+
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'partner'){
+                 this.do_action({
+                     name:"CRM Llamadas",
+                     type: 'ir.actions.act_window',
+                     res_model: "crm.phonecall",
+                     views: [[false,'form']],
+                     target: 'new',
+                     domain: [['id','=', row.id]],
+                     context: {},
+                     flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                     res_id: row.id,
+                 });
+            }
+            if (field === 'opportunity_id'){
+                this.do_action({
+                    name:"Registro",
+                    type: 'ir.actions.act_window',
+                    res_model: "crm.lead",
+                    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.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fetchCrmPhone();
+            }).then(function(CrmPhone) {
+                self.CrmPhone = CrmPhone;
+                return self.fetchCrm();
+            }).then(function (Crm) {
+                self.Crm = Crm;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        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;
+            }
+        },
+
+        fetchCrmPhone: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('crm');
+            if (modules.length <= 0){
+                self.showMensaje('crm');
+                return defer;
+            }
+            var CrmPhone = new instance.web.Model('crm.phonecall');
+            CrmPhone.query(['id', 'partner_id', 'name', 'date', 'opportunity_id', 'partner_mobile', 'user_id', 'state']).filter([['active', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        fetchCrm: function () {
+            var self = this;
+            var defer = $.Deferred();
+
+            var Crm = new instance.web.Model('crm.lead');
+            Crm.query(['id', 'partner_id', 'name', 'description', 'create_date', 'user_id', 'stage_id', 'type']).filter([['active', '=', true]]).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]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getCrm: function (id) {
+            var self = this;
+            return _.filter(self.Crm,function (item) {
+                return item.opportunity_id == id;
+            });
+        },
+
+        getCrmPhone: function (id) {
+            var self = this;
+            return _.filter(self.CrmPhone,function (item) {
+                return item.id == id;
+            });
+        },
+
+        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();
+                }
+            });
+        },
+
+        // volver
+        volver: function(){
+            this.$el.find('#volver_btn').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var crmphone = self.CrmPhone;
+            var invoice;
+            var Crm;
+            var data = [];
+
+            _.each(crmphone, function(item){
+
+                invoice = self.getCrmPhone(item.id).shift();
+                Crm = self.getCrm(item.id);
+
+
+                data.push({
+                    id : item.id,
+                    opportunity_id : self.valorNull(item.opportunity_id),
+                    partner: self.valorNull(Crm.partner_id),
+                    description: self.valorNull(item.name),
+                    create_date: moment(item.date).format("DD/MM/YYYY"),
+                    date: moment(item.date).format("YYYY-MM-DD"),
+                    user: item.user_id[1],
+                    stage: item.state,
+                    partner_id : item.partner_id[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 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');
+             }
+
+             this.$el.find('#volver_btn').append(selector);
+             this.$el.find('.bootstrap-table').hide({
+                 effect: 'drop',
+                 direction: 'up',
+                 duration: 200,
+                 complete: function () {
+
+                 }
+             });
+             this.$el.find('#toolbar').hide({
+                 effect: 'drop',
+                 direction: 'up',
+                 duration: 200,
+                 complete: function () {
+
+                 }
+             });
+
+
+             if (partner != ""){
+                 content = _.filter(content, function(inv){
+                     return inv.partner_id == partner[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(rowsTable){
+             var self = this;
+             var rowsPdf=[];
+             var rows=[];
+             var rows = self.rowsData;
+             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.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 Cabecera
+                 _.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 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: {
+                  opportunity_id : {columnWidth: '8px'},
+                  partner : {columnWidth: '8px'},
+                  description : {columnWidth: '8px'},
+                  date : {columnWidth: '8px'},
+                  stage : {columnWidth: '8px'},
+                  user : {columnWidth: '8px'}
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Histórico de llamadas de crm ', 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('Histórico de llamadas crm.pdf')
+        },
+    });
+}

+ 486 - 0
static/src/js/reports/report_project.js

@@ -0,0 +1,486 @@
+function report_project(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportProjectWidget = reporting.Base.extend({
+        template:'ReportProject',
+        Project: [],
+        content:[],
+        rowsData :[],
+        modules:[],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #opportunity' : 'factSearch',
+            'click #lead' : 'factSearch',
+            'click #Z' : 'factSearch',
+
+            'click #Y' : 'factSearch',
+            'click #customer' : '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();
+        },
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'description'){
+                 this.do_action({
+                     name:"Project",
+                     type: 'ir.actions.act_window',
+                     res_model: "project.project",
+                     views: [[false,'form']],
+                     target: 'new',
+                     domain: [['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,
+                });
+            }
+            if (field === 'id'){
+                this.do_action({
+                    name:"Proyecto",
+                    type: 'ir.actions.act_window',
+                    res_model: "project.project",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.id,
+                });
+            }
+
+             e.stopImmediatePropagation();
+        },
+
+        submitForm: function () {
+            var self = this;
+            self.fecthIrModuleModule().then(function(modules){
+                self.modules = modules;
+                return modules;
+            }).then(function(modules){
+                return self.fetchProject();
+            }).then(function (Project) {
+                self.Project = Project;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                return self.BuildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        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;
+                    }
+                },
+
+                // fetchProjectTask: function () {
+                //     var self = this;
+                //     var defer = $.Deferred();
+                //
+                //     var ProjectTask = new instance.web.Model('project.task');
+                //     ProjectTask.query(['id',  'name', 'date', 'project_id', 'partner_mobile', 'user_id', 'state']).filter([['active', '=', true]]).all().then(function(results){
+                //         defer.resolve(results);
+                //     });
+                //
+                //     return defer;
+                // },
+
+                fetchProject: function () {
+                    var self = this;
+                    var defer = $.Deferred();
+                    var modules = self.checkModel('project');
+
+                    if (modules.length <= 0){
+                        self.showMensaje('project');
+                        return defer;
+                    }
+
+                    var Project = new instance.web.Model('project.project');
+                    Project.query(['id', 'name', 'partner_id', 'description', 'create_date', 'user_id', 'state', 'type']).filter([['active', '=', true]]).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]]).all().then(function(results){
+                        defer.resolve(results);
+                    });
+                    return defer;
+                },
+
+                getProject: function (id) {
+                    var self = this;
+                    return _.filter(self.Project,function (item) {
+                        return item.project_id == id;
+                    });
+                },
+
+                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();
+                        }
+                    });
+                },
+
+                BuildTable: function(){
+                    var self = this;
+                    var Project = self.Project;
+                    var invoice;
+                    var data = [];
+
+                    _.each(Project, function(item){
+
+                        // invoice = self.getProjectTask(item.id).shift();
+                        // projecttask = self.getProject(item.id);
+
+
+                        data.push({
+                            id : item.id,
+                            partner: self.valorNull(item.partner_id[1]),
+                            description: self.valorNull(item.name),
+                            create_date: moment(item.create_date).format("DD/MM/YYYY"),
+                            date: moment(item.create_date).format("YYYY-MM-DD"),
+                            user: item.user_id[1],
+                            state: item.state,
+                            partner_id : item.partner_id[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 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 (partner != ""){
+                         content = _.filter(content, function(inv){
+                             return inv.partner_id == partner[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(rowsTable){
+                     var self = this;
+                     var rowsPdf=[];
+                     var rows=[];
+                     var rows = self.rowsData;
+                     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.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 Cabecera
+                         _.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 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: {
+                          id : {columnWidth: '4px'},
+                          description : {columnWidth: '10px'},
+                          partner : {columnWidth: '8px'},
+                          date : {columnWidth: '8px'},
+                          state : {columnWidth: '8px'},
+                          user : {columnWidth: '8px'}
+                        },
+                        margin: { top: 16, horizontal: 7},
+
+                        addPageContent: function (data) {
+                            pdfDoc.setFontSize(12);
+                            pdfDoc.setFontStyle('bold');
+                            pdfDoc.setTextColor(40);
+                            pdfDoc.text('Histórico de proyectos', 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('Histórico de proyecto.pdf')
+                },
+            });
+        }

+ 1 - 1
static/src/js/reports/report_puchases.js

@@ -300,7 +300,7 @@ function report_puchases (reporting){
                     return inv.currency_id == currency;
                 });
             }
-            // Busacara por proveedor
+            // Buscar por proveedor
             if (prov != ""){
                 newInvoice = _.filter(newInvoice, function(inv){
                     return inv.partner_id == prov[0];

+ 614 - 0
static/src/js/reports/report_purchases_invoice_analysis.js

@@ -0,0 +1,614 @@
+function report_purchases_invoice_analysis (reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportPurchaseInvoiceAnalysisWidget = reporting.Base.extend({
+        template: 'ReportPurchaseInvoiceAnalysis',
+        invoices: [],
+        invoiceLines: [],
+        productProduct:[],
+        Currency:[],
+        rowsData :[],
+        rowOrigin:[],
+        accountJournal:[],
+        resCompany:[],
+        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 #purchase' : 'factSearch',
+            'click #expense' : 'factSearch',
+
+            'change #current-journal': 'factSearch',
+
+            'change #from' : 'factSearch',
+            'change #to': 'factSearch',
+            // 'click #volver_btn': 'volver',
+            'click-row.bs.table #table' : 'ckickAnalysisDetail',
+        },
+        init : function(parent){
+          this._super(parent);
+        },
+        start: function () {
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowOrigin});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        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;
+            }
+          },
+        ckickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'name'){
+                this.do_action({
+                    name : "Variantes de Producto",
+                    type : 'ir.actions.act_window',
+                    res_model : "product.product",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['id','=', row.id_product]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.id_product,
+                });
+            }
+            if (field == 'number'){
+                this.do_action({
+                    name : "Factura de Cliente",
+                    type : 'ir.actions.act_window',
+                    res_model : "account.invoice",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['type', '=', 'out_invoice'],['id','=', row.id]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.id,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        submitForm: function () {
+            var self = this;
+            this.fetchResCurrencyRate().then(function(ResCurrencyRate) {
+                self.ResCurrencyRate = ResCurrencyRate;
+                return ResCurrencyRate;
+            }).then(function (ResCurrencyRate) {
+                return self.fetchAccountJournal();
+            }).then(function (AccountJournal) {
+                self.AccountJournal = AccountJournal;
+                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
+                _.each(AccountJournal, function (item) {
+                  self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fetchAccountInvoice();
+            }).then(function (AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchAccountInvoiceLine();
+            }).then(function (AccountInvoiceLine) {
+                self.AccountInvoiceLine = AccountInvoiceLine;
+                return self.fecthProductProduct();
+            }).then(function(ProductProduct){
+                self.ProductProduct = ProductProduct;
+                return self.fecthResCompany();
+            }).then(function(ResCompany){
+                self.ResCompany = ResCompany;
+            return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                self.searchProduct();
+                return self.getInvoiceCurrency();
+            });
+        },
+        fetchResCurrencyRate: function () {
+            var defer = $.Deferred();
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+
+            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
+            var ResCurrencyRate = new model.web.Model('res.currency.rate');
+            ResCurrencyRate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchAccountJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var AccountJournal = new model.web.Model('account.journal');
+            AccountJournal.query(['id', 'name']).filter([['type', '=', 'purchase'], ['active', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+              return defer;
+        },
+        fetchAccountInvoice: function () {
+            var filter = [['state', 'in',['open','paid']],['type', '=', 'in_invoice']];
+            var journal_ids = _.flatten(_.map(this.AccountJournal, function (item) {
+                return item.id;
+            }));
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice','partner_id'];
+            var defer = $.Deferred();
+            var AccountInvoice = new model.web.Model('account.invoice');
+            AccountInvoice.query(field).filter(filter).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchAccountInvoiceLine: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var linesIds = _.flatten(_.map(self.AccountInvoice, function (item) {
+                return item.invoice_line;
+            }));
+            var InvoiceLine = new model.web.Model('account.invoice.line');
+            InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        fecthProductProduct: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var porductIDS = _.flatten(_.map(self.AccountInvoiceLine, function (item) {
+                return item.product_id[0];
+            }));
+            var ProductProduct =  new model.web.Model('product.product');
+            var fields = ['id','name', 'default_code', 'name_template','ean13', 'standard_price','type','attribute_str'];
+            ProductProduct.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        fecthResCompany: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new model.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchResPartner: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id','name','ruc']).filter([['active', '=', true],['supplier', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        getAccountInvoice: function (id){
+            var self = this;
+            return _.find(self.AccountInvoice, function (inv) {
+                return _.contains(inv.invoice_line, id);
+            });
+        },
+        getProductProduct: function(id){
+            var self = this;
+            return _.find(self.ProductProduct, function(item){
+                return _.contains(id, item.id);
+            });
+        },
+        getResCurrencyRate: function (id){
+            var self = this;
+            return _.find(self.ResCurrencyRate,function (item) {
+                return _.contains(item.currency_id,id);
+            });
+        },
+        getInvoiceCurrency: function(){
+            var self = this;
+            for (var i = 0; i < self.AccountInvoice.length; i++) {
+                var currency_new;
+                var item = self.AccountInvoice[i];
+                var id = item.currency_id[0];
+                currency_new = self.getResCurrencyRate(id);
+                if (!currency_new){
+                    currency_new={};
+                    currency_new.rate=1;
+                }
+                self.AccountInvoice[i].rate=(currency_new.rate);
+            }
+            return this.BuildTable();
+        },
+        BuildTable: function(){
+            var self = this;
+            var data=[];
+            var AccountInvoiceLine = self.AccountInvoiceLine
+            var invoice;
+            var producto;
+            var invoice_type;
+            _.each(AccountInvoiceLine, function(item){
+                invoice = self.getAccountInvoice(item.id);
+                producto =self.getProductProduct(item.product_id);
+                if (!producto){
+                    producto={};
+                    producto.standard_price=0;
+                }
+                if(invoice.origin == false){
+                    invoice_type = 'expense'
+                }else{
+                    invoice_type = 'purchase'
+                }
+                data.push({
+                    id : invoice.id,
+                    number : (invoice.number),
+                    id_product : producto.id,
+                    name : (item.name),
+                    quantity : accounting.formatNumber((item.quantity),0, ".", ","),
+                    price_unity : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
+                    standar_tot : accounting.formatNumber((item.quantity * item.price_unit),2, ".", ","),
+                    journal_id :(invoice.journal_id[0]),
+                    journal_name :(invoice.journal_id[1]),
+                    date_invoice : (invoice.date_invoice),
+                    partner_id : invoice.partner_id[0],
+                    partner_name : invoice.partner_id[1],
+                    invoice_type : invoice_type
+                });
+            });
+            self.rowsData=data;
+            self.rowOrigin=data;
+            self.loadTable(data)
+        },
+        factSearch: function(){
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            var partner = this.$el.find('#partner').val().split('-');
+            var product = this.$el.find('#product').val().split('-');
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            self.rowsData=self.rowOrigin;
+
+            if ($('#A').is(":checked")){
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.date_invoice == hoy;
+                });
+            }
+            if ($('#B').is(":checked")){
+                var date = hoy.split('-');
+                var ayer = date[2] - 1;
+                date.splice(2,0);
+                date[2] = '0'+ayer;
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.date_invoice == date[0]+'-'+date[1]+'-'+date[2];
+                });
+            }
+            if ($('#C').is(":checked")){
+                var date = hoy.split('-');
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    var mes = inv.date_invoice.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;
+                    }
+                }
+                self.rowsData = _.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('/');
+                    self.rowsData = _.filter(self.rowsData, function (inv){
+                        return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    self.rowsData = _.filter(self.rowsData, function (inv){
+                        return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+
+            if ($('#purchase').is(":checked")){
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.invoice_type == 'purchase';
+                });
+            }
+            if ($('#expense').is(":checked")){
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.invoice_type == 'expense';
+                });
+            }
+
+            if (partner != ""){
+                self.rowsData = _.filter(self.rowsData, function(inv){
+                    return inv.partner_id == partner[0];
+                });
+            }
+            if (product != ""){
+                self.rowsData = _.filter(self.rowsData, function(inv){
+                
+                    return inv.id_product == product[0];
+                });
+            }
+            self.loadTable(self.rowsData);
+        },
+        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();
+                }
+            });
+        },
+        searchProduct: function () {
+            var self = this;
+            var results = self.ProductProduct;
+            results = _.map(results, function (item) {
+                return {
+                    label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                    value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+        loadTable:function(rowsTable){
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load', rowsTable);
+        },
+        clickOnAction: function (e) {
+            var action = this.$el.find(e.target).val();
+            var self = this;
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){ return val.field});
+                _.each(this.rowsData,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)
+            }
+            // if (action === 'chart'){
+            //     var suc =this.$el.find('#current-journal').val();
+            //     if (suc == 9999999){
+            //         self.fectCharFilter();
+            //     }else{
+            //         $("#dialog" ).dialog({
+            //             autoOpen: true,
+            //             resizable: false,
+            //             modal: true,
+            //             title: 'Atención',
+            //             open: function() {
+            //                 $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
+            //             },
+            //             show: {
+            //                 effect: "shake",
+            //                 duration: 300
+            //             },
+            //             hide: {
+            //                 effect: "fade",
+            //                 duration: 300
+            //             },
+            //             buttons: {
+            //                 Aceptar: function() {
+            //                     $(this).dialog('close');
+            //                 }
+            //             }
+            //         });
+            //     }
+            // }
+        },
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var rowsPdf=[];
+            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 company = _.map(self.ResCompany, function (map) {
+                return map.currency_id[1];
+            });
+
+            var pdfDoc = new jsPDF();
+
+            var quantity=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.quantity){valor = parseFloat(((item.quantity.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var price_unity=_.reduce(_.map(rows,function(item){
+                var valor =0;
+                if (item.price_unity){valor=parseFloat(((item.price_unity.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num; },0);
+            var standar_tot=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.standar_tot){valor=parseFloat(((item.standar_tot.replace(".","")).replace(",",".")))} return valor }), function(memo, num){ return memo + num; },0);
+
+            rowsPdf=rows;
+
+            rowsPdf.push({
+                number : "TOTAL "+ company,
+                quantity: accounting.formatNumber(quantity,0, ".", ","),
+                standar_tot : accounting.formatNumber(standar_tot,2, ".", ","),
+            });
+
+            pdfDoc.autoTable(getColumns, rowsPdf, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    number: {fontStyle: 'bold'},
+                    partner_name :{columnWidth: '10px'},
+                    name :{columnWidth: '10px'},
+                    quantity :{halign:'right' },
+                    price_unity : {halign:'right' },
+                    standar_tot : {halign:'right' },
+                },
+                margin: { top: 20, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Análisis de facturas de compra ',80,10);
+
+                    var tipo = '';
+                    if ($('#Y').is(":checked")){
+                        tipo = tipo.concat(' Tipo de factura : Todas las facturas' );
+                    }
+                    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('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text(175,pdfDoc.internal.pageSize.height - 5,str);
+                }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            pdfDoc.save('Análisis de facturas de compra.pdf')
+        },
+    });
+}

+ 98 - 30
static/src/js/reports/report_resumen_egresos.js

@@ -1,4 +1,4 @@
-function report_resumen_engreso (reporting){
+function report_resumen_egresos (reporting){
 
     var instance = openerp;
 
@@ -13,7 +13,15 @@ function report_resumen_engreso (reporting){
         modules:[],
 
         events:{
-            'click  #toolbar > button' : 'clickOnAction',
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'fectSearch',
+            'click #A' : 'fectSearch',
+            'click #B' : 'fectSearch',
+            'click #C' : 'fectSearch',
+            'click #D' : 'fectSearch',
+            'click #Z' : 'fectSearch',
+
+            'click #Y' : 'fectSearch',
             'change #current-journal': 'fectSearch',
             'change #current-currency': 'fectSearch',
             'change #from' : 'fectSearch',
@@ -80,23 +88,25 @@ function report_resumen_engreso (reporting){
         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));
-                });
+            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;
@@ -105,9 +115,9 @@ function report_resumen_engreso (reporting){
                 } catch( error ) {
                     date = null;
                 }
-              return date;
+                return date;
             }
-         },
+        },
         //  Metodo inicial
         fecthInitial: function(){
             var self = this;
@@ -329,6 +339,7 @@ function report_resumen_engreso (reporting){
         // Buscar
         fectSearch: 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 journal =this.$el.find('#current-journal').val();
@@ -336,6 +347,72 @@ function report_resumen_engreso (reporting){
             var newJournal= self.accountJournal; //copia del Diario
             var newVoucher= self.accountVoucher; //copia del Vouacher
 
+            if ($('#A').is(":checked")){
+                newVoucher = _.filter(newVoucher, 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;
+                }
+                newVoucher = _.filter(newVoucher, function (inv){
+                    return inv.date == date[0]+'-'+date[1]+'-'+date[2];
+                });
+            }
+            if ($('#C').is(":checked")){
+                var date = hoy.split('-');
+                newVoucher = _.filter(newVoucher, 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;
+                 }
+                }
+                newVoucher = _.filter(newVoucher, 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('/');
+                    newVoucher = _.filter(newVoucher, function (inv){
+                        return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    newVoucher = _.filter(newVoucher, function (inv){
+                        return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+
             if (journal != 9999999){
                 var botonChart =this.$el.find('#chart').attr("disabled", true);
                  newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
@@ -347,15 +424,6 @@ function report_resumen_engreso (reporting){
                  newVoucher=_.filter(newVoucher, function (inv){ return inv.currency_id[0] == currency});
             }
 
-            if (desde){
-                 var date= desde.split('/')
-                 newVoucher=_.filter(newVoucher, function (inv){return inv.date >= (date[2]+"-"+date[1]+"-"+date[0])});
-            }
-
-            if (hasta){
-                var date= hasta.split('/')
-                newVoucher=_.filter(newVoucher, function (inv){return inv.date <= (date[2]+"-"+date[1]+"-"+date[0])});
-           }
             self.fecthDataVoucher(newVoucher,newJournal);
         },
         // volver

+ 126 - 51
static/src/js/reports/report_resumen_ingresos.js

@@ -14,12 +14,20 @@ function report_resumen_ingresos (reporting){
         modules:[],
 
         events:{
-          'click #toolbar > button' : 'clickOnAction',
-          'change #current-journal': 'fectSearch',
-          'change #current-currency': 'fectSearch',
-          'change #from' : 'fectSearch',
-          'change #to': 'fectSearch',
-          'click #volver_btn': 'volver',
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'fectSearch',
+            'click #A' : 'fectSearch',
+            'click #B' : 'fectSearch',
+            'click #C' : 'fectSearch',
+            'click #D' : 'fectSearch',
+            'click #Z' : 'fectSearch',
+
+            'click #Y' : 'fectSearch',
+            'change #current-journal': 'fectSearch',
+            'change #current-currency': 'fectSearch',
+            'change #from' : 'fectSearch',
+            'change #to': 'fectSearch',
+            'click #volver_btn': 'volver',
         },
 
         init:function(parent){
@@ -77,38 +85,7 @@ function report_resumen_ingresos (reporting){
             });
             return
         },
-        // 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;
-            }
-         },
+
         //  Metodo inicial
         fecthInitial: function(){
             var self = this;
@@ -136,7 +113,7 @@ function report_resumen_ingresos (reporting){
                 self.currencyRate =currencyRate;
                 return self.fecthVoucher();
             }).then(function(accountVoucher){
-                self.accountVoucher =accountVoucher;
+                self.accountVoucher=accountVoucher;
                 return self.fecthComanyCurrency();
             }).then(function(resCompany){
                 self.resCompany = resCompany;
@@ -157,6 +134,40 @@ function report_resumen_ingresos (reporting){
             });
             return defer;
         },
+        // 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;
+            }
+        },
         // company_curency
         fecthComanyCurrency: function(){
             var self = this;
@@ -291,7 +302,7 @@ function report_resumen_ingresos (reporting){
                                             journal_name: journal.name,
                                             graficar: true
                                     });
-                    // Generarl la Cabezera
+                    // Generar la Cabecera
                     voucherObjectItem.unshift({ journal : journal.name, method  :"", amount  :"", voucherLine_name :"", voucherLine_id :"",rate :"",amountBase :"",journal_id:journal.id, journal_name:journal.name, graficar:false});
                     // Generar Objeto Principal
                     voucherObject=voucherObject.concat(voucherObjectItem);
@@ -310,6 +321,7 @@ function report_resumen_ingresos (reporting){
                                         graficar: false
                                 });
             }
+            // self.content = voucherObject;
             self.loadTable(voucherObject);
         },
         // Obtener Voucher
@@ -330,6 +342,7 @@ function report_resumen_ingresos (reporting){
         // Buscar
         fectSearch: 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 journal =this.$el.find('#current-journal').val();
@@ -337,27 +350,89 @@ function report_resumen_ingresos (reporting){
             var newJournal= self.accountJournal; //copia del Diario
             var newVoucher= self.accountVoucher; //copia del Vouacher
 
+            if ($('#A').is(":checked")){
+                newVoucher = _.filter(newVoucher, 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;
+                }
+                newVoucher = _.filter(newVoucher, function (inv){
+                    return inv.date == date[0]+'-'+date[1]+'-'+date[2];
+                });
+            }
+            if ($('#C').is(":checked")){
+                var date = hoy.split('-');
+                newVoucher = _.filter(newVoucher, 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;
+                 }
+                }
+                newVoucher = _.filter(newVoucher, 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('/');
+                    newVoucher = _.filter(newVoucher, function (inv){
+                        return inv.date >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    newVoucher = _.filter(newVoucher, function (inv){
+                        return inv.date <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+
             if (journal != 9999999){
                 var botonChart =this.$el.find('#chart').attr("disabled", true);
-                 newJournal=_.filter(newJournal, function (inv){ return inv.id == journal});
+                newJournal=_.filter(newJournal, function (inv){
+                    return inv.id == journal
+                });
             }else {
                 var botonChart =this.$el.find('#chart').attr("disabled", false);
             }
 
             if(currency != 999){
-                 newVoucher=_.filter(newVoucher, function (inv){ return inv.currency_id[0] == currency});
-            }
-
-            if (desde){
-                 var date= desde.split('/')
-                 newVoucher=_.filter(newVoucher, function (inv){return inv.date >= (date[2]+"-"+date[1]+"-"+date[0])});
+                newVoucher=_.filter(newVoucher, function (inv){
+                    return inv.currency_id[0] == currency
+                });
             }
 
-            if (hasta){
-                var date= hasta.split('/')
-                newVoucher=_.filter(newVoucher, function (inv){return inv.date <= (date[2]+"-"+date[1]+"-"+date[0])});
-           }
             self.fecthDataVoucher(newVoucher,newJournal);
+            // self.loadTable(newVoucher,newJournal);
         },
         // volver
         volver: function(){

+ 356 - 0
static/src/js/reports/report_sales.js

@@ -0,0 +1,356 @@
+function report_sales(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportSaleWidget = reporting.Base.extend({
+        template: 'ReportSale',
+        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',
+            'change #from' : 'factSearch',
+            'change #to' : 'factSearch',
+            'click-row.bs.table #table ' : 'ckickAnalysisDetail',
+        },
+        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();
+        },
+        ckickAnalysisDetail: 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,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        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();
+            });
+        },
+        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 filter =[['state', 'in',['open','paid']],['type', '=', 'out_invoice']];
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'supplier_invoice_number','date_invoice','partner_id','amount_total','user_id','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']).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;
+        },
+        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();
+                }
+            });
+        },
+        BuildTable: function(invoices){
+            var self = this;
+            var AccountInvoice = self.AccountInvoice;
+            var data = [];
+            _.each(AccountInvoice, function(item){
+                data.push({
+                    id : item.id,
+                    number: item.number,
+                    origin: self.valorNull(item.origin),
+                    partner: item.partner_id[1],
+                    date_invoice: moment(item.date_invoice).format("DD/MM/YYYY"),
+                    amount_total: accounting.formatNumber(item.amount_total,2,".",","),
+                    residual: accounting.formatNumber(item.residual,2,".",","),
+                    date: item.date_invoice,
+                    partner_id : item.partner_id[0],
+                    amount : item.amount_total,
+                    total_residual : item.residual
+                });
+            });
+            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 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);
+                date[2] = '0'+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 (partner != ""){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == partner[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(rowsTable){
+            var self = this;
+            var rows=self.rowsData;
+            var amount = _.reduce(_.map(rows,function(map){
+                return(map.amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            var total_residual = _.reduce(_.map(rows,function(map){
+                return(map.total_residual);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            if (rows.length > 0){
+                rows.push({
+                    number: "Total",
+                    amount_total: accounting.formatNumber((amount),2,".",","),
+                    residual: accounting.formatNumber((total_residual),2,".",","),
+
+                });
+            }
+
+            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.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);
+            }
+        },
+        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();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    number : {columnWidth: '8px'},
+                    origin : {columnWidth: '8px'},
+                    partner : {columnWidth: '8px'},
+                    date_invoice : {columnWidth: '8px'},
+                    amount_total : {halign:'right',columnWidth: '8px'},
+                    residual : {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 Ventas ', 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('Histórico de ventas.pdf')
+        },
+    });
+}

+ 668 - 0
static/src/js/reports/report_sales_invoice_analysis.js

@@ -0,0 +1,668 @@
+function report_sales_invoice_analysis (reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportSaleInvoiceAnalysisWidget = reporting.Base.extend({
+        template: 'ReportSaleInvoiceAnalysis',
+        invoices: [],
+        invoiceLines: [],
+        productProduct:[],
+        Currency:[],
+        rowsData :[],
+        rowOrigin:[],
+        accountJournal:[],
+        resCompany:[],
+        events:{
+            'click #toolbar > button' : 'clickOnAction',
+            'click #X' : 'fectSearch',
+            'click #A' : 'fectSearch',
+            'click #B' : 'fectSearch',
+            'click #C' : 'fectSearch',
+            'click #D' : 'fectSearch',
+            'click #Z' : 'fectSearch',
+            'change #current-journal': 'fectSearch',
+            'change #from' : 'fectSearch',
+            'change #to': 'fectSearch',
+            'click #volver_btn': 'volver',
+            'click-row.bs.table #table' : 'ckickAnalysisDetail',
+        },
+        init : function(parent){
+          this._super(parent);
+        },
+        start: function () {
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowOrigin});
+            this.fecthFecha();
+            this.submitForm();
+        },
+        ckickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'name'){
+                this.do_action({
+                    name : "Variantes de Producto",
+                    type : 'ir.actions.act_window',
+                    res_model : "product.product",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['id','=', row.id_product]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.id_product,
+                });
+            }
+            if (field == 'number'){
+                this.do_action({
+                    name : "Factura de Cliente",
+                    type : 'ir.actions.act_window',
+                    res_model : "account.invoice",
+                    views : [[false,'form']],
+                    target : 'new',
+                    domain : [['type', '=', 'out_invoice'],['id','=', row.id]],
+                    context : {},
+                    flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id : row.id,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('#grafico').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+        // Cansultar
+        submitForm: function () {
+            var self = this;
+            this.fetchCurency().then(function(Currency) {
+                self.Currency = Currency;
+                return Currency;
+            }).then(function (Currency) {
+                return self.fetchJournal();
+            }).then(function (journal) {
+                self.accountJournal =journal;
+                self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
+                _.each(journal, function (item) {
+                  self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                return self.fetchInvoiceV2();
+            }).then(function (invoices){
+                self.invoices = invoices;
+                return self.fetchInvoiceLine(invoices);
+            }).then(function (invoiceLines) {
+                self.invoiceLines = invoiceLines;
+                return self.fecthProduct(invoiceLines);
+            }).then(function(productProduct){
+                self.productProduct = productProduct;
+                return self.fecthComanyCurrency();
+            }).then(function(resCompany){
+                self.resCompany = resCompany;
+            return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                self.searchProduct();
+                return self.invoice_Currency();
+            });
+        },
+        // company_curency
+        fecthComanyCurrency: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var currency = new model.web.Model('res.company');
+            var field=['id', 'currency_id'];
+            var domain=[['id','=',1]];
+            currency.query(field).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // 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;
+            }
+          },
+        // Buscar Diario
+        fetchJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var Journal = new model.web.Model('account.journal');
+            Journal.query(['id', 'name']).filter([['type', '=', 'sale'], ['active', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+              return defer;
+        },
+        // Buscar Cambio de Monedas USD,PYG,ARG,BRL
+        fetchCurency: function () {
+            var defer = $.Deferred();
+            var currency_Rate = new model.web.Model('res.currency.rate');
+            var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
+            var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
+            currency_Rate.query(fields).filter(domain).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+          },
+        // Invoice (FACTURAS)
+        fetchInvoiceV2: function () {
+            var filter ="[['state', 'in',['open','paid']],['type', '=', 'out_invoice']";
+            var journal_ids = _.flatten(_.map(this.accountJournal, function (item) {
+                return item.id;
+            }));
+            if (journal_ids){
+                filter=filter.concat(",['journal_id', 'in',["+journal_ids+"]]");
+            }
+            filter=filter.concat("]");
+            var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice','partner_id'];
+            var defer = $.Deferred();
+            var Invoice = new model.web.Model('account.invoice');
+            Invoice.query(field).filter(filter).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Invoice line (Linea de Factura)
+        fetchInvoiceLine: function (invoices) {
+            var defer = $.Deferred();
+            var linesIds = _.flatten(_.map(invoices, function (item) {
+                return item.invoice_line;
+            }));
+            var InvoiceLine = new model.web.Model('account.invoice.line');
+            InvoiceLine.query(['id', 'quantity', 'price_unit', 'discount', 'name', 'product_id', 'origin','invoice_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        fetchResPartner: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id','name','ruc']).filter([['active', '=', true],['customer', '=', true]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // Product Product
+        fecthProduct: function(invoiceLines){
+            var defer = $.Deferred();
+            var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
+                return item.product_id[0];
+            }));
+            var ProductProdcut =  new model.web.Model('product.product');
+            var fields = ['id','name', 'default_code', 'name_template','ean13', 'standard_price','type','attribute_str'];
+            ProductProdcut.query(fields).filter([['id', 'in', porductIDS]]).all().then(function (results) {
+                defer.resolve(results)
+            });
+            return defer;
+        },
+        // Obtener Monedas de la Factura
+        getCutrrency: function (id){
+            return _.find(this.Currency,function (curr) {
+                return _.contains(curr.currency_id,id);
+            });
+        },
+        // Actualizar cambio de las moneda de Factura
+        invoice_Currency: function(){
+            for (var i = 0; i < this.invoices.length; i++) {
+                var currency_new;
+                var item = this.invoices[i];
+                var id = item.currency_id[0];
+                currency_new = this.getCutrrency(id);
+                if (!currency_new){
+                    currency_new={};
+                    currency_new.rate=1;
+                }
+                this.invoices[i].rate=(currency_new.rate);
+            }
+            return this.fectUtility();
+        },
+        // Obtener la Detalles de la Factura
+        getInvoice: function (id_line){
+            return _.find(this.invoices, function (inv) {
+                return _.contains(inv.invoice_line, id_line);
+            });
+          },
+        // Obtener las lineas de las Facturas
+        getProduct: function(pro_id){
+            return _.find(this.productProduct, function(prod){
+                return _.contains(pro_id, prod.id);
+            });
+        },
+
+        fectUtility: function(){
+            var data=[];
+            var item;
+            var invoice;
+            var producto;
+
+            for (var i = 0; i < this.invoiceLines.length; i++) {
+                item = this.invoiceLines[i];
+                invoice = this.getInvoice(item.id);
+                producto =this.getProduct(item.product_id);
+                if (!producto){
+                    producto={};
+                    producto.standard_price=0;
+                }
+                data.push({
+                        id : invoice.id,
+                        number : (invoice.number),
+                        id_product : producto.id,
+                        name : (item.name),
+                        quantity : accounting.formatNumber((item.quantity),0, ".", ","),
+                        price_unity : accounting.formatNumber((item.price_unit / invoice.rate),2, ".", ","),
+                        standar_price : accounting.formatNumber((producto.standard_price),2, ".", ","),
+                        price_tot : accounting.formatNumber((item.quantity * (item.price_unit / invoice.rate)),2, ".", ","),
+                        standar_tot : accounting.formatNumber((item.quantity * producto.standard_price),2, ".", ","),
+                        utility : accounting.formatNumber(((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price)),2, ".", ","),
+                        journal_id :(invoice.journal_id[0]),
+                        journal_name :(invoice.journal_id[1]),
+                        date_invoice : (invoice.date_invoice),
+                        partner_id : invoice.partner_id[0],
+                        partner_name : invoice.partner_id[1]
+                });
+                // }
+          }
+          this.rowsData=data;
+          this.rowOrigin=data;
+          this.loadTable(data)
+        },
+
+
+        fectSearch: function(){
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            var partner = this.$el.find('#partner').val().split('-');
+            var product = this.$el.find('#product').val().split('-');
+            var desde =this.$el.find('#from').val();
+            var hasta =this.$el.find('#to').val();
+            self.rowsData=self.rowOrigin;
+
+            if ($('#A').is(":checked")){
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.date_invoice == hoy;
+                });
+            }
+            if ($('#B').is(":checked")){
+                var date = hoy.split('-');
+                var ayer = date[2] - 1;
+                date.splice(2,0);
+                date[2] = '0'+ayer;
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    return inv.date_invoice == date[0]+'-'+date[1]+'-'+date[2];
+                });
+            }
+            if ($('#C').is(":checked")){
+                var date = hoy.split('-');
+                self.rowsData = _.filter(self.rowsData, function (inv){
+                    var mes = inv.date_invoice.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;
+                    }
+                }
+                self.rowsData = _.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('/');
+                    self.rowsData = _.filter(self.rowsData, function (inv){
+                        return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+                if (hasta.length > 0){
+                    var date= hasta.split('/');
+                    self.rowsData = _.filter(self.rowsData, function (inv){
+                        return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
+                    });
+                }
+            }else{
+                $('#datepicker').css('display','none');
+            }
+            if (partner != ""){
+                self.rowsData = _.filter(self.rowsData, function(inv){
+                    return inv.partner_id == partner[0];
+                });
+            }
+            if (product != ""){
+                self.rowsData = _.filter(self.rowsData, function(inv){
+                    return inv.id_product == product[0];
+                });
+            }
+            self.loadTable(self.rowsData);
+        },
+        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.fectSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.fectSearch();
+                },
+                select: function(event, ui) {
+                    self.fectSearch();
+                }
+            });
+        },
+        searchProduct: function () {
+            var self = this;
+            var results = self.productProduct;
+            results = _.map(results, function (item) {
+                return {
+                    label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                    value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.fectSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.fectSearch();
+                },
+                select: function(event, ui) {
+                    self.fectSearch();
+                }
+            });
+        },
+        loadTable:function(rowsTable){
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load', rowsTable);
+        },
+        clickOnAction: function (e) {
+            var action = this.$el.find(e.target).val();
+            var self = this;
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var data2 = table.bootstrapTable('getVisibleColumns');
+            if (action === 'pdf') {
+                var dataNEW = _.map(data2, function (val){ return val.field});
+                _.each(this.rowsData,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
+                                }]);
+                });
+                // Llamar al pdf
+                this.drawPDF(_.flatten(getColumns),rows)
+            }
+            if (action === 'chart'){
+                var suc =this.$el.find('#current-journal').val();
+                if (suc == 9999999){
+                    self.fectCharFilter();
+                }else{
+                    $("#dialog" ).dialog({
+                        autoOpen: true,
+                        resizable: false,
+                        modal: true,
+                        title: 'Atención',
+                        open: function() {
+                            $(this).html('Para Generar el Gráfico debes Seleccionar todas las Sucursales');
+                        },
+                        show: {
+                            effect: "shake",
+                            duration: 300
+                        },
+                        hide: {
+                            effect: "fade",
+                            duration: 300
+                        },
+                        buttons: {
+                            Aceptar: function() {
+                                $(this).dialog('close');
+                            }
+                        }
+                    });
+                }
+            }
+        },
+        drawPDF: function (getColumns,rows) {
+            var self = this;
+            var rowsPdf=[];
+            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();
+
+            // rows=this.rowsData;
+            var quantity=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.quantity){valor = parseFloat(((item.quantity.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var precio_unit=_.reduce(_.map(rows,function(item){
+                var valor =0;
+                if (item.price_unity){valor=parseFloat(((item.price_unity.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num; },0);
+            var precio_cost=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if(item.standar_price){valor=parseFloat(((item.standar_price.replace(".","")).replace(",",".")))} return valor}), function(memo, num){ return memo + num;},0);
+            var tot_unit=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.price_tot){valor=parseFloat(((item.price_tot.replace(".","")).replace(",",".")))}return valor}), function(memo, num){ return memo + num; },0);
+            var tol_cost=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.standar_tot){valor=parseFloat(((item.standar_tot.replace(".","")).replace(",",".")))} return valor }), function(memo, num){ return memo + num; },0);
+            var utility=_.reduce(_.map(rows,function(item){
+                var valor=0;
+                if (item.utility){valor=parseFloat(((item.utility.replace(".","")).replace(",",".")))}return valor }), function(memo, num){ return memo + num; },0);
+
+            rowsPdf=rows;
+
+            var company = _.map(self.resCompany, function (map) {
+                return map.currency_id[1];
+            });
+            rowsPdf.push({
+                        number : "TOTAL "+company,
+                        name : " ",
+                        quantity: accounting.formatNumber(quantity,0, ".", ","),
+                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
+                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
+                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
+                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
+                        utility : accounting.formatNumber(utility,2, ".", ",")
+                    });
+
+            rowsPdf.unshift({
+                        number : "TOTAL "+company,
+                        name : " ",
+                        quantity: accounting.formatNumber(quantity,0, ".", ","),
+                        price_unity : accounting.formatNumber(precio_unit,2, ".", ","),
+                        standar_price : accounting.formatNumber(precio_cost,2, ".", ","),
+                        price_tot : accounting.formatNumber(tot_unit,2, ".", ","),
+                        standar_tot : accounting.formatNumber(tol_cost,2, ".", ","),
+                        utility : accounting.formatNumber(utility,2, ".", ",")
+                    });
+
+            pdfDoc.autoTable(getColumns, rowsPdf, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                              number: {fontStyle: 'bold'},
+                              name :{columnWidth: '10px'},
+                              quantity :{halign:'right' },
+                              price_unity : {halign:'right' },
+                              standar_price : {halign:'right' },
+                              price_tot : {halign:'right' },
+                              standar_tot : {halign:'right' },
+                              utility : {halign:'right'},
+                          },
+                margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Análisis de facturas de venta ', 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('Análisis de facturas de venta.pdf')
+        },
+
+        // fectCharFilter: function(){
+        //   var self = this;
+        //   var dataBody=[];
+        //   var dataHeader=[];
+
+        //   var canvas="<canvas id='graf_resume'></canvas>";
+        //   this.$el.find('#grafico').append(canvas);
+
+        //   _.each(self.accountJournal, function(journal){
+        //     dataHeader.push(journal.name);
+        //     var utility=_.reduce(_.map(_.filter(self.rowsData, function (inv){ return inv.journal_id == journal.id}),function(item){
+        //       return parseFloat(((item.utility.replace(".","")).replace(",",".")))}), function(memo, num){ return memo + num; },0);
+        //     dataBody.push(accounting.toFixed((utility),2));
+        //   });
+        //   var selector ="<button type='button' class='oe_button oe_form_button oe_highlight' id='volver_btn' name='volver_btn'><span>Atras</span></button>";
+
+        //   this.$el.find('#volver').append(selector);
+
+        //   this.$el.find('.bootstrap-table').hide({
+        //       effect: 'drop',
+        //       direction: 'up',
+        //       duration: 200,
+        //       complete: function () {
+        //         self.drawChart(dataHeader,dataBody);
+        //       }
+        //   });
+        // },
+        // drawChart: function (dataHeader,dataBody) {
+        //     var barChart = new Chart(this.$el.find('#graf_resume'), {
+        //         type: 'doughnut',
+        //         data: {
+        //             labels: dataHeader,
+        //             datasets: [
+        //                 {
+        //                     labels: dataHeader,
+        //                     backgroundColor: [
+        //                         'rgba(255, 99, 132, 0.2)',
+        //                         'rgba(54, 162, 235, 0.2)',
+        //                         'rgba(255, 206, 86, 0.2)',
+        //                         'rgba(75, 192, 192, 0.2)',
+        //                         'rgba(153, 102, 255, 0.2)',
+        //                     ],
+        //                     borderColor: [
+        //                         'rgba(255,99,132,1)',
+        //                         'rgba(54, 162, 235, 1)',
+        //                         'rgba(255, 206, 86, 1)',
+        //                         'rgba(75, 192, 192, 1)',
+        //                         'rgba(153, 102, 255, 1)',
+        //                     ],
+        //                     borderWidth: 1,
+        //                     data: dataBody,
+        //                 }
+        //             ]
+        //         },
+        //         options: {
+        //             maintainAspectRatio: false,
+        //             layout: {
+        //                 padding: 30
+        //             }
+        //         },
+        //     });
+        // },
+    });
+}

+ 319 - 0
static/src/js/reports/report_stock.js

@@ -0,0 +1,319 @@
+function report_stock (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportStockWidget = reporting.Base.extend({
+        template: 'ReportStock',
+        stockLocation: [],
+        stockQuant: [],
+        productProduct : [],
+        rowsData: [],
+        content: [],
+        newStock: [],
+
+        events : {
+            'change #current-location' : 'factSearch',
+            'change #current-category' : 'factSearch',
+            'click #toolbar > button' : 'clickOnAction',
+            'click-row.bs.table #table ' : 'clickAnalysisDetail',
+        },
+        init : function(parent){
+            this._super(parent);
+        },
+        start : function(){
+            var self = this;
+            var dato=[];
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            self.submitForm();
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        clickAnalysisDetail: function(e, row, $element,field){
+            if (field == 'product'){
+                this.do_action({
+                    name:"Variantes de Producto",
+                    type: 'ir.actions.act_window',
+                    res_model: "product.product",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id', '=',row.id ]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.id,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        submitForm: function(){
+            var self = this;
+            self.fecthStockLocation().then(function(StockLocation){
+                self.StockLocation=StockLocation;
+                return StockLocation;
+            }).then(function(StockLocation){
+                return self.fecthStockQuant();
+            }).then(function(StockQuant){
+                self.StockQuant = StockQuant;
+                return self.fecthProductProduct();
+            }).then(function(ProductProduct){
+                self.ProductProduct = ProductProduct;
+                return self.fecthProductCategory();
+            }).then(function(ProductCategory){
+                self.ProductCategory = ProductCategory;
+                self.$el.find('#current-category').append('<option value="9999999">Todos las categorias</option>');
+                _.each(ProductCategory, function (item) {
+                    self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                self.search();
+                return self.BuildTable(self.stockQuant, self.stockLocation);
+            });
+        },
+        fecthStockLocation : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var location = new instance.web.Model('stock.location');
+            var fields = ['id', 'name', 'company_id', 'location_id'];
+            var domain =[['active', '=', true],['usage', '=', 'internal']];
+            location.query(fields).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            })
+            return defer;
+        },
+        fecthStockQuant : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var location = _.flatten(_.map(self.StockLocation,function(item){
+                return item.id;
+            }));
+            var company_id =(_.map(self.StockLocation, function(item){
+                return item.company_id[0];
+            })).shift();
+            var quant = new instance.web.Model('stock.quant');
+            var fields = ['id', 'product_id', 'qty', 'cost','location_id'];
+            var domain =[['company_id', '=', company_id],['location_id', 'in',location]];
+            quant.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            })
+            return defer;
+        },
+        fecthProductProduct: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var ids = _.flatten(_.map(self.StockQuant, function (item) {
+                return item.product_id[0];
+            }));
+            var fields = ['id','name','name_template', 'standard_price','type','attribute_value_ids', 'lst_price','ean13','categ_id','attribute_str'];
+            var ProductProduct =  new instance.web.Model('product.product');
+            ProductProduct.query(fields).filter([['id', 'in', ids]]).all().then(function (results) {
+              defer.resolve(results)
+            });
+            return defer;
+        },
+        fecthProductCategory: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['id','name'];
+            var ProductCategory =  new instance.web.Model('product.category');
+            ProductCategory.query(fields).filter([['type', '=', 'normal']]).all().then(function (results) {
+              defer.resolve(results)
+            });
+            return defer;
+        },
+        getProductProduct: function(ProductProduct, StockQuant){
+            var self = this;
+            var product_ids= _.flatten(_.map(StockQuant,function(map){
+                return map.product_id[0];
+            }));
+
+            return _.filter(ProductProduct,function(prod){return _.contains(product_ids, prod.id)});
+        },
+        getStockQuant: function(product_id, quantObjs){
+            var self = this;
+            var quantProduct = quantObjs;
+            if (product_id){
+                quantProduct = _.filter(quantProduct, function(item){
+                    return item.product_id[0] == product_id;
+                });
+            }
+            return quantProduct;
+        },
+        BuildTable : function(stockQuant,stockLocation){
+            var self = this;
+            var data=[];
+            var itemLocation;
+            var itemProduct;
+            var itemQuant;
+            var ProductProduct;
+            var product;
+            var quantity = 0;
+            var total=0;
+            ProductProduct = self.getProductProduct(self.ProductProduct, self.StockQuant);
+            _.each(ProductProduct, function(item){    
+                itemProduct = item;
+                itemQuant = self.getStockQuant( itemProduct.id, self.StockQuant);
+                if (itemQuant.length > 0){
+                    quantity = _.reduce(_.map(itemQuant,function(item){
+                        return item.qty;
+                    }),function(mamo, num){
+                        return mamo + num;
+                    },0);
+                    product = itemQuant.shift();
+                    total = parseInt(quantity * itemProduct.standard_price);
+                    data.push({ 
+                        id : product.product_id[0],
+                        product : product.product_id[1],
+                        ean13 : self.valorNull(itemProduct.ean13),
+                        category_name : itemProduct.categ_id[1],
+                        qty : accounting.formatNumber(quantity,2, ".", ","),
+                        standard_price : accounting.formatNumber(itemProduct.standard_price,0, ".", ","),
+                        lst_price : accounting.formatNumber(itemProduct.lst_price,0, ".", ","),
+                        valuation: accounting.formatNumber(total,0,".",","),
+                        category_id : itemProduct.categ_id[0],
+                        location_id : product.location_id[0],
+                        total : total
+                    });
+                }
+            })
+            self.content = data;
+            self.loadTable(data);
+        },
+        search: function () {
+            var self = this;
+            var results = self.ProductProduct;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                        value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+        factSearch: function(){
+            var self = this;
+            var category = this.$el.find('#current-category').val();
+            var product= this.$el.find('#product').val().split('-');
+            var content = self.content;
+            if(category != 9999999){
+                content = _.filter(content,function(inv){
+                    return inv.category_id == category;
+                });
+            }
+            if (product != ""){
+                content = _.filter(content, function(inv){
+                    return inv.id == product[0];
+                });
+            }
+            self.loadTable(content)
+        },
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = self.$el.find('#table');
+            table.bootstrapTable('load' ,rowsTable);
+        },
+        getObjectPdf: function(){
+            var self = this;
+            var rows=[];
+            var rows = self.rowsData;
+            var total = _.reduce(_.map(rows,function(map){
+                return(map.total);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            if (rows.length > 0){
+                rows.push({
+                    product: "Totales ",
+                    valuation: accounting.formatNumber(total,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));
+                });
+                // 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);
+            }
+        },
+        drawPDF:function(getColumns,rows){
+            var self = this;
+            var fechaActu= new Date();
+            var location = this.sucDescrip = this.$el.find('#current-location option:selected').text();
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF();
+            pdfDoc.autoTable(getColumns, rows, {
+                    styles: { overflow: 'linebreak', fontSize:8 , columnWidth: 'wrap'},
+                    columnStyles:{
+                                    product :{columnWidth: '8px'},
+
+                                    qty : {halign:'center'},
+                                    standard_price : {halign:'right'},
+                                    lst_price : {halign:'right'},
+                                    valuation : {halign:'right'},
+                                },
+                    margin: { top: 16, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Listado de productos', data.settings.margin.left, 10);
+                    // FOOTER
+                    var str = "Pagina  " + data.pageCount;
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                        // +"\n  Día de Expedición  "+fechaActu.getDate()+"/"+fechaActu.getMonth()+"/"+fechaActu.getFullYear();
+                    }
+                    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('Listado de productos.pdf');
+        }
+    });
+}

+ 493 - 0
static/src/js/reports/report_stock_move.js

@@ -0,0 +1,493 @@
+function report_stock_move(reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportStockMoveWidget = reporting.Base.extend({
+        template: 'ReportStockMove',
+        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',
+            'change #from' : 'factSearch',
+            'change #to' : 'factSearch',
+            'change #current-location-origin' : 'factSearch',
+            'change #current-location-destiny' : '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();
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'picking_name'){
+                if(row.picking_id != undefined){
+                    this.do_action({
+                    name:"Transferencia",
+                    type: 'ir.actions.act_window',
+                    res_model: "stock.picking",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.picking_id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.picking_id,
+                    });
+                }
+
+            }
+            if (field == 'product_name'){
+                this.do_action({
+                name:"Producto",
+                type: 'ir.actions.act_window',
+                res_model: "product.product",
+                views: [[false,'form']],
+                target: 'new',
+                domain: [['id','=', row.product_id]],
+                context: {},
+                flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                res_id: row.product_id,
+                });
+            }
+            if (field == 'partner_name'){
+                if(row.partner_id != undefined){
+                    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();
+        },
+        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;
+            }
+        },
+        submitForm: function () {
+            var self = this;
+            self.fetchStockMove().then(function(StockMove) {
+                return StockMove;
+            }).then(function (StockMove){
+                self.StockMove = StockMove;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner=ResPartner;
+                return self.fetchProductProduct();
+            }).then(function(ProductProduct){
+                self.ProductProduct=ProductProduct;
+                return self.fetchStockLocation();
+            }).then(function(StockLocation){
+                self.StockLocation=StockLocation;
+                self.$el.find('#current-location-origin').append('<option value="9999999">Todas las ubicaciones</option>');
+                _.each(StockLocation, function (item) {
+                    self.$el.find('#current-location-origin').append('<option value="' + item.id + '">'+ item.location_id[1] + " / " + item.name + '</option>');
+                });
+                self.$el.find('#current-location-destiny').append('<option value="9999999">Todas las ubicaciones</option>');
+                _.each(StockLocation, function (item) {
+                    self.$el.find('#current-location-destiny').append('<option value="' + item.id + '">'+ item.location_id[1] + " / " + item.name + '</option>');
+                });
+                self.search();
+                self.searchProduct();
+                return self.BuildTable();
+            });
+        },
+        fetchStockMove: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var filter =[['state', '=', 'done']];
+            var field =['id', 'name', 'product_id', 'product_uom_qty', 'location_id', 'location_dest_id', 'date', 'picking_id','origin','partner_id'];
+            var StockMove = new instance.web.Model('stock.move');
+            StockMove.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']).filter([['active', '=', true], ['customer', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchProductProduct: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var ProductProduct = new instance.web.Model('product.product');
+            ProductProduct.query(['id', 'name','ean13','default_code','attribute_str']).filter([['active', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchStockLocation : function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['id', 'name', 'location_id'];
+            var domain =[['usage', 'not in', ['view','transit','production','procurement']],['scrap_location','=',false],['active','!=',false]];
+            var StockLocation = new instance.web.Model('stock.location');
+            StockLocation.query(fields).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            })
+            return defer;
+        },
+        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();
+                }
+            });
+        },
+        searchProduct: function () {
+            var self = this;
+            var results = self.ProductProduct;
+            results = _.map(results, function (item) {
+                return {
+                        label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) ' ,
+                        value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' +  self.valorNull(item.attribute_str) + ' ) '
+                }
+            });
+            self.$('#product').autocomplete({
+                source: results,
+                minLength:0,
+                search: function(event, ui) {
+                    if (!(self.$('#product').val())){
+                        self.factSearch();
+                    }
+                },
+                close: function( event, ui ) {
+                        self.factSearch();
+                },
+                select: function(event, ui) {
+                    self.factSearch();
+                }
+            });
+        },
+        BuildTable: function(){
+            var self = this;
+            var StockMove = self.StockMove;
+            var data = [];
+            var origin;
+            _.each(StockMove, function(item){
+                data.push({
+                    id : item.id,
+                    name : item.name,
+                    picking_name : self.valorNull(item.picking_id[1]),
+                    origin_name : self.valorNull(item.origin),
+                    product_name : item.product_id[1],
+                    product_uom_qty : item.product_uom_qty,
+                    date_move : moment(item.date).format("DD/MM/YYYY"),
+                    partner_name : self.valorNull(item.partner_id[1]),
+                    location : item.location_id[1],
+                    location_dest : item.location_dest_id[1],
+                    picking_id : item.picking_id[0],
+                    product_id : item.product_id[0],
+                    partner_id : item.partner_id[0],
+                    date : moment(item.date).format("YYYY-MM-DD"),
+                    location_id : item.location_id[0],
+                    location_dest_id : item.location_dest_id[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 location_id = this.$el.find('#current-location-origin').val();
+            var location_dest_id = this.$el.find('#current-location-destiny').val();
+            var partner = this.$el.find('#partner').val().split('-');
+            var product = this.$el.find('#product').val().split('-');
+            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 (partner != ''){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == partner[0];
+                });
+            }
+            if (product != ''){
+                content = _.filter(content, function(inv){
+                    return inv.product_id == product[0];
+                });
+            }
+            if (location_id != 9999999){
+                content = _.filter(content, function(inv){
+                    return inv.location_id == location_id;
+                });
+            }
+            if (location_dest_id != 9999999){
+                content = _.filter(content, function(inv){
+                    return inv.location_dest_id == location_dest_id;
+                });
+            }
+            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 rows=self.rowsData;
+            var product_uom_qty = _.reduce(_.map(rows,function(map){
+                return(map.product_uom_qty);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            if (rows.length > 0){
+                rows.push({
+                    product_uom_qty: accounting.formatNumber((product_uom_qty),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));
+                });
+                // 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);
+            }
+        },
+        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: {
+                    picking_name : {columnWidth: '8px'},
+                    origin_name : {columnWidth: '8px'},
+                    product_name : {columnWidth: '8px'},
+                    partner_name : {columnWidth: '8px'},
+                    product_uom_qty : {halign:'center',columnWidth: '8px'},
+                    date_move : {columnWidth: '8px'},
+                    location : {columnWidth: '8px'},
+                    location_dest : {columnWidth: '8px'},
+                },
+                margin: { top: 20, horizontal: 7},
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Análisis de Movimientos de Stock', 115, 10);
+
+                    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(240,18," 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(260,pdfDoc.internal.pageSize.height - 5,str);
+                    }
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            pdfDoc.save('Análisis de Movimientos de Stock.pdf')
+        },
+    });
+}

+ 448 - 0
static/src/js/reports/report_vouchers.js

@@ -0,0 +1,448 @@
+function report_vouchers (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportVoucherWidget = reporting.Base.extend({
+        template: 'ReportVoucher',
+        AccountVoucher: [],
+        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 #customer' : 'factSearch',
+            'click #supplier' : 'factSearch',
+
+            'change #current-journal' : '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();
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'reference'){
+                this.do_action({
+                    name:"Factura",
+                    type: 'ir.actions.act_window',
+                    res_model: "account.invoice",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.invoice_id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.invoice_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.fetchAccountVoucher().then(function(AccountVoucher) {
+                return AccountVoucher;
+            }).then(function (AccountVoucher) {
+                self.AccountVoucher = AccountVoucher;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                return self.fetchAccountInvoice();
+            }).then(function(AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchAccountJournal();
+            }).then(function (AccountJournal) {
+                self.AccountJournal =AccountJournal;
+                self.$el.find('#current-journal').append('<option value="9999999">Todos los pagos</option>');
+                _.each(AccountJournal, function (item) {
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+                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;
+            }
+        },
+        fetchAccountVoucher: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var AccountVoucher = new instance.web.Model('account.voucher');
+            AccountVoucher.query(['id', 'number','reference','partner_id','journal_id','amount','date','number','type']).filter([['state', '=', 'posted']]).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]]).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']).filter([['state', 'in', ['open','paid']]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchAccountJournal: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var AccountJournal = new instance.web.Model('account.journal');
+            AccountJournal.query(['id','name']).filter([['active','=',true],['type', 'in', ['bank','cash']]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        getAccountInvoice: function (number) {
+            var self = this;
+            return _.filter(self.AccountInvoice,function (item) {
+                return item.number == number;
+            });
+        },
+        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();
+                }
+            });
+        },
+        BuildTable: function(){
+            var self = this;
+            var AccountVoucher = self.AccountVoucher;
+            var invoice;
+            var amount_in;
+            var amount_out;
+            var data = [];
+            _.each(AccountVoucher, function(item){
+                invoice = self.getAccountInvoice(item.reference).shift();
+                if (item.type == 'payment') {
+                    amount_in = 0;
+                    amount_out = item.amount;
+                }else{
+                    amount_in = item.amount;
+                    amount_out = 0;
+                }
+                data.push({
+                    id : item.id,
+                    reference: item.reference,
+                    number: item.number,
+                    journal: item.journal_id[1],
+                    date_voucher: moment(item.date).format("DD/MM/YYYY"),
+                    partner: item.partner_id[1],
+                    amount_in: accounting.formatNumber(amount_in,2,".",","),
+                    amount_out: accounting.formatNumber(amount_out,2,".",","),
+                    type: item.type,
+                    date: item.date,
+                    journal_id: item.journal_id[0],
+                    partner_id: item.partner_id[0],
+                    invoice_id: invoice.id,
+                    in_amount:amount_in,
+                    out_amount:amount_out
+                });
+            });
+            self.content = data;
+            this.loadTable(data);
+        },
+        factSearch: function(){
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            var journal = this.$el.find('#current-journal').val();
+            var desde = this.$el.find('#from').val();
+            var hasta = this.$el.find('#to').val();
+            var partner= this.$el.find('#partner').val().split('-');
+            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 ($('#customer').is(":checked")){
+                content = _.filter(content, function (inv){
+                    return inv.type == 'receipt';
+                });
+            }
+            if ($('#supplier').is(":checked")){
+                content = _.filter(content, function (inv){
+                    return inv.type == 'payment';
+                });
+            }
+            if(journal != 9999999){
+                content = _.filter(content,function(inv){
+                    return inv.journal_id == journal;
+                });
+            }
+            if (partner != ""){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == partner[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(rowsTable){
+            var self = this;
+            var rowsPdf=[];
+            var rows=[];
+            var rows = self.rowsData;
+            var total_in = _.reduce(_.map(rows,function(map){
+                return(map.in_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            var total_out = _.reduce(_.map(rows,function(map){
+                return(map.out_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            if (rows.length > 0){
+                rows.push({
+                    reference: "Totales ",
+                    amount_in: accounting.formatNumber(total_in,2,".",","),
+                    amount_out: accounting.formatNumber(total_out,2,".",","),
+                });
+            }
+            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.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);
+            }
+        },
+        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();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    reference : {columnWidth: '8px'},
+                    number : {columnWidth: '8px'},
+                    journal_id : {columnWidth: '8px'},
+                    date_voucher : {columnWidth: '8px'},
+                    partner : {columnWidth: '8px'},
+                    amount_in : {halign:'right',columnWidth: '8px'},
+                    amount_out: {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 pagos ', 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('Histórico de pagos.pdf')
+        },
+    });
+}

+ 561 - 0
static/src/js/reports/report_works.js

@@ -0,0 +1,561 @@
+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',
+            'click #X' : 'factSearch',
+            'click #A' : 'factSearch',
+            'click #B' : 'factSearch',
+            'click #C' : 'factSearch',
+            'click #D' : 'factSearch',
+            'click #Z' : 'factSearch',
+            'click #customer' : 'factSearch',
+            '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();
+        },
+
+        // Redirecionar
+        renderReport: function () {
+            var self = this;
+
+            var container = this.$el.closest('.oe_form_sheet.oe_form_sheet_width');
+            this.$el.closest('.report_view').remove();
+            container.find('.report_view').show({
+                effect: 'fade',
+                duration: 200,
+            });
+        },
+
+        // Verificar el modelo
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.modules,function(item){return item.name === model});
+        },
+        // Lanzar el mensaje
+        showMensaje : function(modelos){
+            var self = this;
+            $("#dialog" ).dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true,
+                title: 'Atención',
+                width: 500,
+                open: function() {
+                    $(this).html('Reporte in-disponible, contacte con el administrador del sistema ref : '+modelos);
+                },
+                show: {
+                    effect: "fade",
+                    duration: 200
+                },
+                hide: {
+                    effect: "fade",
+                    duration: 200
+                },
+                buttons: {
+                    Aceptar: function() {
+                        $(this).dialog('close');
+                        self.renderReport()
+                    }
+                }
+            });
+            return
+        },
+
+        // Analisis Detallado
+        ckickAnalysisDetail: function(e, row, $element,field){
+            if (field == 'customer'){
+                this.do_action({
+                    name:"Registro del Cliente",
+                    type: 'ir.actions.act_window',
+                    res_model: "res.partner",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.customer_id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.customer_id,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+        // Consultar
+        submitForm: function () {
+            var self = this;
+            self.fetchProductService().then(function(ProductService) {
+                return ProductService;
+            }).then(function(ProductService){
+                self.ProductService = ProductService;
+                return self.fetchProjectService();
+            }).then(function(ProjectService){
+                self.ProjectService = ProjectService;
+                return self.fetchProjectServiceTask();
+            }).then(function (ProjectServiceTask){
+                self.ProjectServiceTask = ProjectServiceTask;
+                return self.fetchAccountInvoice();
+            }).then(function(AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                self.search();
+                return self.buildTable();
+            });
+        },
+
+        // Modelos instalados
+        fecthIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed']];
+            var irModule = new instance.web.Model('ir.module.module');
+
+            irModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        // 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;
+            }
+        },
+        fetchProductService: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var modules = self.checkModel('eiru_service');
+
+            if (modules.length <= 0){
+                self.showMensaje('eiru_service');
+                return defer;
+            }
+            var ProductService = new instance.web.Model('product.service');
+            ProductService.query(['id', 'name','policy','partner_id','agent_id','secure_id']).filter().all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchProjectServiceTask: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ProjectServiceTask = new instance.web.Model('project.service.task');
+            ProjectServiceTask.query(['id', 'name','project_id','activity_ids','state']).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','task_invoice_id','state']).filter().all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        fetchProjectService: function () {
+            var self = this;
+            var defer = $.Deferred();
+            var ProjectService = new instance.web.Model('project.service');
+            ProjectService.query(['id','name','project_service_task_ids','date_in']).filter([['project_service_task_ids','!=', false]]).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();
+                }
+            });
+        },
+        getProjectServiceTask : function(id){
+            var self = this;
+            return _.filter(self.ProjectServiceTask, function(item){
+                return item.project_id[0] == id;
+            });
+        },
+        getAccountInvoice : function(id){
+            var self = this;
+            return _.filter(self.AccountInvoice, function(item){
+                return item.task_invoice_id[0] == id;
+            });
+        },
+        getProjectService : function(id){
+            var self = this;
+            return _.filter(self.ProjectService, function(item){
+                return item.name[0] == id;
+            });
+        },
+        buildTable: function(){
+            var self = this;
+            var ProductService = self.ProductService;
+            var task;
+            var invoice;
+            var state;
+            var data = [];
+            var car1;
+            var agente;
+            _.each(ProductService, function(item){
+                task = self.getProjectServiceTask(item.id);
+                car1 = self.getProjectService(item.id);
+                var pay_amount = 0;
+                var collect_pay = 0;
+                var secure_amount = 0;
+                var particular_amount = 0;
+                invoice = self.getAccountInvoice(task[0].task_invoice_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') {
+                    state = 'No Facturado';
+                } else {
+                    state = 'Facturado';
+                }
+                if (item.agent_id.length == undefined) {
+                    agente = 'Particular';
+                }else{
+                    agente = item.agent_id[1];
+                }
+                data.push({
+                    id : item.id,
+                    customer_id : item.partner_id[0],
+                    customer : item.partner_id[1],
+                    car : item.name,
+                    agent : agente,
+                    date_in : moment(car1[0].date_in).format("DD/MM/YYYY"),
+                    date : car1[0].date_in,
+                    secure_amount : accounting.formatNumber(secure_amount,0,".",","),
+                    particular_amount : accounting.formatNumber(particular_amount,0,".",","),
+                    state : state,
+                    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 customer= this.$el.find('#customer').val().split('-');
+            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 (partner != ""){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == partner[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=[];
+            rows = self.rowsData;
+
+            // valor Aseguradora
+            var secure_total = _.reduce(_.map(rows,function(map){
+                return(map.intsecure_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            // valor Particular
+            var particular_total = _.reduce(_.map(rows,function(map){
+                return(map.intparticular_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            // Monto ya cobrado
+            var pay_total = _.reduce(_.map(rows,function(map){
+                return(map.intpay_amount);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+            // Monto a Cobrar
+            var collect_total = _.reduce(_.map(rows,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;
+            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: {
+                    customer : {columnWidth: '8px'},
+                    car : {columnWidth: '12px'},
+                    agent : {columnWidth: '8px'},
+                    date_in : {halign:'center',columnWidth: '5px'},
+                    secure_amount : {halign:'right',columnWidth: '5px'},
+                    particular_amount : {halign:'right',columnWidth: '5px'},
+                    state: {halign:'right',columnWidth: '6px'},
+                    pay_amount: {halign:'right',columnWidth: '6px'},
+                    collect: {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 trabajos ', 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('Informe de Trabajos.pdf')
+        },
+    });
+}

+ 445 - 0
static/src/js/reports/reporting_account.js

@@ -0,0 +1,445 @@
+function reporting_account (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportingAccountWidget = reporting.Base.extend({
+        template: 'ReportingAccount',
+        AccountVoucher: [],
+        content:[],
+        rowsData :[],
+        moveLine: [],
+        resCompany: [],
+        resCurrecy: [],
+        content: [],
+        modelId: [],
+        accountInvoice: [],
+
+        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',
+
+            'change #current-journal' : '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();
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'reference'){
+                this.do_action({
+                    name:"Factura",
+                    type: 'ir.actions.act_window',
+                    res_model: "account.invoice",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.invoice_id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.invoice_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.fetchMoveLine().then(function(moveLine) {
+                return moveLine;
+            }).then(function (moveLine) {
+                self.moveLine = _.filter(moveLine, function(item) {
+                    return item.amount_residual > 0;
+                });
+                return self.fetchInvoice(moveLine);
+            }).then(function(accountInvoice) {
+                self.accountInvoice = accountInvoice;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner=ResPartner;
+                return self.fetchGetModelId();
+            }).then(function(modelId) {
+                self.modelId= modelId;
+                return self.fetchReduceMoveLine();
+            });
+        },
+
+
+        // getModelId
+        fetchGetModelId: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var irModelData = new instance.web.Model('ir.model.data');
+            var getObtjectReference = irModelData.get_func('get_object_reference');
+
+            this.alive(getObtjectReference('account', 'invoice_form')).then(function(results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        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;
+            }
+        },
+        // Move line
+        fetchMoveLine: function () {
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            var defer = $.Deferred();
+            var field = ['id', 'partner_id', 'amount_residual', 'credit', 'debit', 'date_maturity', 'ref', 'invoice', 'amount_residual_currency','state'];
+            var domain = [['credit', '<=', 0], ['date_maturity', '<', hoy]];
+            var moveLine = new instance.web.Model('account.move.line');
+
+            moveLine.query(field).filter(domain).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]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // invoice
+        fetchInvoice: function(moveline) {
+            var self = this ;
+            var defer = $.Deferred()
+            var ref = _.map(moveline, function(map) {
+                return map.invoice[0];
+            });
+            var fields = ['id', 'currency_id', 'number'];
+            var domain = [['id', 'in', ref]];
+            var accountInvoice = new instance.web.Model('account.invoice');
+            accountInvoice.query(fields).filter(domain).all().then(function(results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        getAccountInvoice: function (id) {
+            var self = this;
+            return _.filter(self.AccountInvoice,function (item) {
+                return item.invoice[0] == id;
+            });
+        },
+
+        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();
+                }
+            });
+        },
+
+        fetchReduceMoveLine: function(){
+            var self = this;
+            var MoveLine = self.moveLine;
+            var invoice;
+            var data = [];
+            _.each(MoveLine, function(item){
+
+                invoice = self.getAccountInvoice(item.id);
+
+                data.push({
+                    id : item.id,
+                    reference: item.ref,
+                    number: item.number,
+                    date_maturity: moment(item.date_maturity).format("DD/MM/YYYY"),
+                    partner: item.partner_id[1],
+                    date: item.date_maturity,
+                    amount_residual: accounting.formatNumber(item.amount_residual,0,".",","),
+                    partner_id: item.partner_id[0],
+                    total_residual: item.amount_residual,
+                    invoice_id: item.invoice[0]
+                });
+            });
+            self.content = data;
+            this.loadTable(data);
+        },
+        factSearch: function(){
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            //var journal = this.$el.find('#current-journal').val();
+            var desde = this.$el.find('#from').val();
+            var hasta = this.$el.find('#to').val();
+            var partner= this.$el.find('#partner').val().split('-');
+
+            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 (partner != ""){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == partner[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(rowsTable){
+            var self = this;
+            var rowsPdf=[];
+            var rows=[];
+            var rows = self.rowsData;
+            var total_residual = _.reduce(_.map(rows,function(map){
+                return(map.total_residual);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+
+            if (rows.length > 0){
+                rows.push({
+                    reference: "Total a Cobrar",
+                    partner: "",
+                    date_maturity: "",
+                    amount_residual: accounting.formatNumber((total_residual),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.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);
+            }
+        },
+        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();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    id : {columnWidth: '6px'},
+                    reference : {columnWidth: '10px'},
+                    partner : {columnWidth: '10px'},
+                    date_maturity : {columnWidth: '6px'},
+                    amount_residual : {halign:'right', columnWidth: '8px'}
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Listado de cuentas a cobrar vencidas', 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('Listado de cuentas a cobrar vencidas.pdf')
+        },
+    });
+}

+ 443 - 0
static/src/js/reports/reporting_accountpending.js

@@ -0,0 +1,443 @@
+function reporting_accountpending (reporting){
+    "use strict";
+
+    var instance = openerp;
+
+    reporting.ReportingAccountPendingWidget = reporting.Base.extend({
+        template: 'ReportingAccountPending',
+        AccountVoucher: [],
+        content:[],
+        rowsData :[],
+        moveLine: [],
+        resCompany: [],
+        resCurrecy: [],
+        content: [],
+        modelId: [],
+        accountInvoice: [],
+
+        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',
+
+            'change #current-journal' : 'factSearch',
+
+            'change #from' : 'factSearch',
+            'change #to' : 'factSearch',
+            'click #volver_btn': 'volver',
+            '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();
+        },
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+        clickAnalysisDetail: function(e, row, $element, field){
+            if (field == 'reference'){
+                this.do_action({
+                    name:"Factura",
+                    type: 'ir.actions.act_window',
+                    res_model: "account.invoice",
+                    views: [[false,'form']],
+                    target: 'new',
+                    domain: [['id','=', row.invoice_id]],
+                    context: {},
+                    flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
+                    res_id: row.invoice_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.fetchMoveLine().then(function(moveLine) {
+                return moveLine;
+            }).then(function (moveLine) {
+                self.moveLine = _.filter(moveLine, function(item) {
+                    return item.amount_residual > 0;
+                });
+                return self.fetchInvoice(moveLine);
+            }).then(function(accountInvoice) {
+                self.accountInvoice = accountInvoice;
+                return self.fetchResPartner();
+            }).then(function(ResPartner){
+                self.ResPartner=ResPartner;
+                return self.fetchGetModelId();
+            }).then(function(modelId) {
+                self.modelId= modelId;
+                return self.fetchReduceMoveLine();
+            });
+        },
+
+        // getModelId
+        fetchGetModelId: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var irModelData = new instance.web.Model('ir.model.data');
+            var getObtjectReference = irModelData.get_func('get_object_reference');
+
+            this.alive(getObtjectReference('account', 'invoice_form')).then(function(results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        volver: function(){
+            this.$el.find('#volver').empty();
+            this.$el.find('.bootstrap-table').show({
+                effect: 'drop',
+                direction: 'down',
+                duration: 200,
+            });
+        },
+
+        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;
+            }
+        },
+        // Move line
+        fetchMoveLine: function () {
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            var defer = $.Deferred();
+            var field = ['id', 'partner_id', 'amount_residual', 'credit', 'debit', 'date_maturity', 'ref', 'invoice', 'amount_residual_currency','state'];
+            var domain = [['credit', '<=', 0], ['date_maturity', '>=', hoy]];
+            var moveLine = new instance.web.Model('account.move.line');
+
+            moveLine.query(field).filter(domain).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]]).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        // invoice
+        fetchInvoice: function(moveline) {
+            var self = this ;
+            var defer = $.Deferred()
+            var ref = _.map(moveline, function(map) {
+                return map.invoice[0];
+            });
+            var fields = ['id', 'currency_id', 'number'];
+            var domain = [['id', 'in', ref]];
+            var accountInvoice = new instance.web.Model('account.invoice');
+            accountInvoice.query(fields).filter(domain).all().then(function(results) {
+                defer.resolve(results);
+            });
+
+            return defer;
+        },
+
+        getAccountInvoice: function (id) {
+            var self = this;
+            return _.filter(self.AccountInvoice,function (item) {
+                return item.invoice[0] == id;
+            });
+        },
+
+        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();
+                }
+            });
+        },
+        fetchReduceMoveLine: function(){
+            var self = this;
+            var MoveLine = self.moveLine;
+            var invoice;
+            var data = [];
+            _.each(MoveLine, function(item){
+
+                invoice = self.getAccountInvoice(item.id);
+
+                data.push({
+                    id : item.id,
+                    reference: item.ref,
+                    number: item.number,
+                    date_maturity: moment(item.date_maturity).format("DD/MM/YYYY"),
+                    partner: item.partner_id[1],
+                    date: item.date_maturity,
+                    amount_residual: accounting.formatNumber(item.amount_residual,0,".",","),
+                    partner_id: item.partner_id[0],
+                    total_residual: item.amount_residual,
+                    invoice_id: item.invoice[0]
+                });
+            });
+            self.content = data;
+            this.loadTable(data);
+        },
+        factSearch: function(){
+            var self = this;
+            var hoy = moment().format('YYYY-MM-DD');
+            //var journal = this.$el.find('#current-journal').val();
+            var desde = this.$el.find('#from').val();
+            var hasta = this.$el.find('#to').val();
+            var partner= this.$el.find('#partner').val().split('-');
+            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 = moment(hoy).add(1,'months').format('YYYY-MM-DD');
+                var date1 = date.split('-');
+                var mes = date1[1];
+                var year;
+                date1.splice(1,0);
+
+                date1[1] = mes;
+
+                content = _.filter(content, function (inv){
+                    var mes = inv.date.split('-');
+                    return mes[0]+'-'+mes[1] == date1[0]+'-'+date1[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 (partner != ""){
+                content = _.filter(content, function(inv){
+                    return inv.partner_id == partner[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(rowsTable){
+            var self = this;
+            var rowsPdf=[];
+            var rows=[];
+            var rows = self.rowsData;
+
+            var total_residual = _.reduce(_.map(rows,function(map){
+                return(map.total_residual);
+            }),function(memo, num){
+                return memo + num;
+            },0);
+
+            if (rows.length > 0){
+                rows.push({
+                    reference: "Total a Cobrar",
+                    partner: "",
+                    date_maturity: "",
+                    amount_residual: accounting.formatNumber((total_residual),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.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);
+            }
+        },
+        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();
+
+            pdfDoc.autoTable(getColumns, rows, {
+                styles: { overflow: 'linebreak', fontSize: 8, columnWidth: 'wrap'},
+                columnStyles: {
+                    id : {columnWidth: '6px'},
+                    reference : {columnWidth: '10px'},
+                    partner : {columnWidth: '10px'},
+                    date_maturity : {columnWidth: '6px'},
+                    amount_residual : {halign:'right', columnWidth: '8px'}
+                },
+                margin: { top: 16, horizontal: 7},
+
+                addPageContent: function (data) {
+                    pdfDoc.setFontSize(12);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    pdfDoc.text('Listado de cuentas a cobrar no vencidas', 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('Listado de cuentas a cobrar no vencidas.pdf')
+        },
+    });
+}

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

@@ -0,0 +1,99 @@
+<?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>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <div class="card card-body">
+                    <br/>
+                    <div class="row">
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Fechas</div>
+                                <div class="panel-body">
+                                    <ul>
+                                        <li>
+                                            <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                            <label for="X">Sin Filtro</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="A" value="A"/> 
+                                            <label for="A">Hoy</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="B" value="B"/>
+                                            <label for="B">Ayer</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="C" value="C"/>
+                                            <label for="C">Mes Actual</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="D" value="D"/>
+                                            <label for="D">Mes Pasado</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="Z" value="Z"/>
+                                            <label for="Z">Busqueda Avanzada</label>
+                                        </li>
+                                    </ul>
+                                    <div id="datepicker" style="display:none;" class="container">
+                                        <label for="from">Desde: </label>
+                                        <input type="text"  id="from" name="from"/>
+                                        <label for="to" >Hasta: </label>
+                                        <input type="text"  id="to" name="to" />    
+                                    </div>
+                                    
+                                </div>
+                            </div> 
+                        </div>
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="panel-body">
+                                    <label for="customer"> Buscar cliente / proveedor:  </label>
+                                    <input id="customer" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/> 
+                                </div>
+                            </div> 
+                        </div>
+                    </div>
+                </div>
+            </div>
+
+
+            <div id="toolbar">
+                <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>

+ 111 - 0
static/src/reports/report_crm.xml

@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportCrm">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de CRM</h1>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <h3>Tipo</h3>
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="tipo" id="Y" value="Y" checked="checked"/>
+                                        <label for="Y">Sin Filtro</label>
+                                        <li>
+                                            <input type="radio" name="cateritica" id="lead" value="lead"/>
+                                            <label for="lead">Iniciativa</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="cateritica" id="opportunity" value="opportunity"/>
+                                            <label for="opportunity">Oportunidad</label>
+                                        </li>
+                                    </li>
+
+                                </ul>
+
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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="name" data-sortable="true">Asunto</th>
+                        <th data-field="description">Descripcion</th>
+                        <th data-field="partner">Cliente</th>
+                        <th data-field="create_date" data-sortable="true">Fecha</th>
+                        <th data-field="stage">Estado</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+    </template>

+ 67 - 16
static/src/reports/report_expenses.xml

@@ -6,23 +6,74 @@
                 <h1>Histórico de gastos</h1>
                 <div id="volver"></div>
             </div>
-            <div id="toolbar">
-                <label for="current-journal">Sucursal: </label>
-                <select id="current-journal" class="ui-autocomplete-input"  name="journal"></select>
-
-                <label for="current-currency">Moneda: </label>
-                <select id="current-currency" class="ui-autocomplete-input"  name="currency"></select>
-
-                <label for="from">Desde: </label>
-                <input type="text"  id="from" name="from"/>
-
-                <label for="to" >Hasta: </label>
-                <input type="text"  id="to" name="to" />
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
 
-                <label for="customer">Proveedor:</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>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="current-currency">Sucursal</label>
+                                    <input id="current-currency" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Sucursal"/>
+                                </div>
+                                <div class="form-group">
+                                    <label for="supplier">Proveedor</label>
+                                    <input id="supplier" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                                <div class="form-group">
+                                    <label for="current-currency">Moneda</label>
+                                    <input id="current-currency" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Moneda"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
             </div>
             <table id="table" class="table_paint_first_row"
                 data-pagination="true"

+ 104 - 0
static/src/reports/report_expenses_invoice_analysis.xml

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <template xml:space="preserve">
+      <t t-name="ReportExpenseInvoiceAnalysis">
+        <div class="report_view">
+          <div class="reporting_page_header">
+            <h1>Análisis de facturas de gasto</h1>
+            <div id="volver"></div>
+          </div>
+          <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <div class="card card-body">
+                    <br/>
+                    <div class="row">
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Fechas</div>
+                                <div class="panel-body">
+                                    <ul class="list-unstyled">
+                                        <li>
+                                            <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                            <label for="X">Sin Filtro</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="A" value="A"/> 
+                                            <label for="A">Hoy</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="B" value="B"/>
+                                            <label for="B">Ayer</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="C" value="C"/>
+                                            <label for="C">Mes Actual</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="D" value="D"/>
+                                            <label for="D">Mes Pasado</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="Z" value="Z"/>
+                                            <label for="Z">Busqueda Avanzada</label>
+                                        </li>
+                                    </ul>
+                                    <div id="datepicker" style="display:none;" class="container">
+                                        <label for="from">Desde: </label>
+                                        <input type="text"  id="from" name="from"/>
+                                        <label for="to" >Hasta: </label>
+                                        <input type="text"  id="to" name="to" />    
+                                    </div>
+                                    
+                                </div>
+                            </div> 
+                        </div>
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="panel-body">
+                                    <div class="form-group">
+                                        <label for="partner">Buscar Proveedor</label>
+                                        <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off"/>   
+                                    </div>
+                                    <div class="form-group">
+                                        <label for="product">Buscar Producto</label>
+                                        <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off"/> 
+                                    </div>    
+                                </div>
+                            </div> 
+                        </div>
+                    </div>
+                </div>
+            </div>
+          <div id="toolbar">
+            <button class="oe_button oe_form_button oe_highlight" value="pdf">PDF</button>
+            <!-- <button class="oe_button oe_form_button oe_highlight" value="chart">Graficar</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_name" >Proveedor</th>
+                <th data-field="name" >Producto</th>
+                <th data-field="quantity" data-sortable="true" data-align="right">Cantidad</th>
+                <th data-field="price_unity" data-sortable="true" data-align="right">Precio Unitario</th>
+                <th data-field="standar_tot" data-sortable="true" data-align="right">Total Costo</th>
+              </tr>
+            </thead>
+        </table>
+        <!-- <canvas></canvas> -->
+        <div class="widget-content" id="grafico"></div>
+        <div id="dialog"></div>
+      </div>
+      </t>
+  </template>

+ 139 - 0
static/src/reports/report_invoice_balance.xml

@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportInvoiceBalance">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de Facturas</h1>
+                <div id="volver"></div>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">  
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                        <label for="X">Sin Filtro</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/> 
+                                        <label for="A">Hoy</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />    
+                                </div>
+                                
+                            </div>
+                        </div> 
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="col-xs-6">
+                                    <h3>Tipo</h3>
+                                    <ul class="list-unstyled">
+                                        <li>
+                                            <input type="radio" name="cateritica" id="Y" value="Y" checked="checked"/> 
+                                            <label for="Y">Sin Filtro</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="cateritica" id="sale" value="sale"/> 
+                                            <label for="sale">Factura de venta</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="cateritica" id="purchase" value="purchase"/>
+                                            <label for="purchase">Factura de compra</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="cateritica" id="expense" value="expense"/>
+                                            <label for="expense">Factura de gasto</label>
+                                        </li>
+                                    </ul>
+                                </div>
+                                <div class="col-xs-6">
+                                    <h3>Estado</h3>
+                                    <ul class="list-unstyled">
+                                        <li>
+                                            <input type="radio" name="estado" id="W" value="W" checked="checked"/> 
+                                            <label for="W">Sin Filtro</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="estado" id="open" value="open"/> 
+                                            <label for="open">Abierto</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="estado" id="paid" value="paid"/>
+                                            <label for="paid">Pagado</label>
+                                        </li>
+                                    </ul>
+                                </div>
+                                <div class="col-xs-12"> 
+                                    <div class="form-group">
+                                        <label for="partner">Buscar Cliente / Proveedor:</label>
+                                        <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                    </div>
+                                </div>
+                            </div>
+                        </div> 
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <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">Cliente / Proveedor</th>
+                        <th data-field="date_invoice">Fecha</th>
+                        <th data-field="user">Responsable</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">Por Pagar</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 95 - 0
static/src/reports/report_mensajecrm.xml

@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportMensajeCrm">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de Mensaje CRM</h1>
+                <button onclick="window.history.back()">Atrás</button>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
+            </div>
+            <table id="table" 
+                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="opportunity_id" data-sortable="true">Oportunidad</th>
+                        <th data-field="partner">Cliente</th>
+                        <th data-field="description">Descripcion</th>
+                        <th data-field="create_date" data-sortable="true">Fecha</th>
+                        <th data-field="stage">Estado</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 96 - 0
static/src/reports/report_phonecall.xml

@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportPhoneCall">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de Llamadas CRM</h1>
+                <div id="volver"></div>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
+                <button type="button" class="oe_button oe_form_button oe_highlight" href="#volver_btn">Atras</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="opportunity_id" data-sortable="true">Oportunidad</th>
+                        <th data-field="partner">Cliente</th>
+                        <th data-field="description">Descripcion</th>
+                        <th data-field="create_date" data-sortable="true">Fecha</th>
+                        <th data-field="stage">Estado</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+    </template>

+ 95 - 0
static/src/reports/report_project.xml

@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportProject">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de Tareas de Proyecto</h1>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Por Cliente</div>
+                            <div class="panel-body">
+
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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="id" data-sortable="true">Orden</th>
+                        <th data-field="description">Descripcion</th>
+                        <th data-field="partner">Cliente</th>
+                        <th data-field="create_date" data-sortable="true">Fecha</th>
+                        <th data-field="state">Estado</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 111 - 0
static/src/reports/report_purchases_invoice_analysis.xml

@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <template xml:space="preserve">
+        <t t-name="ReportPurchaseInvoiceAnalysis">
+            <div class="report_view">
+              <div class="reporting_page_header">
+                <h1>Análisis de facturas de Compras y Gastos</h1>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                        <label for="X">Sin Filtro</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/> 
+                                        <label for="A">Hoy</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />    
+                                </div>
+
+                            </div>
+                        </div> 
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="tipo" id="Y" value="Y" checked="checked"/> 
+                                        <label for="Y">Sin Filtro</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="tipo" id="purchase" value="purchase"/> 
+                                        <label for="purchase">Facturas de compra</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="tipo" id="expense" value="expense"/>
+                                        <label for="expense">Facturas de gasto</label>
+                                    </li>
+                                </ul>
+                                <div class="form-group">
+                                    <label for="partner">Buscar Proveedor</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off"/>
+                                </div>
+                                <div class="form-group">
+                                    <label for="product">Buscar Producto</label>
+                                    <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>   
+                                </div>  
+                            </div>
+                        </div> 
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" 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_name" >Proveedor</th>
+                        <th data-field="name" >Producto</th>
+                        <th data-field="quantity" data-sortable="true" data-align="right">Cantidad</th>
+                        <th data-field="price_unity" data-sortable="true" data-align="right">Precio Unitario</th>
+                        <th data-field="standar_tot" data-sortable="true" data-align="right">Total Costo</th>
+                    </tr>
+                </thead>
+            </table>
+        </div>
+    </t>
+</template>

+ 62 - 13
static/src/reports/report_resumen_egresos.xml

@@ -6,18 +6,68 @@
                 <h1>Resumen de Egreso</h1>
                 <div id="volver"></div>
             </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                     <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="current-journal">Sucursal: </label>
+                                    <select id="current-journal" class="form-control ui-autocomplete-input"  name="journal"></select>
+                                    <br/>
+                                    <label for="current-currency">Moneda: </label>
+                                    <select id="current-currency" class="form-control ui-autocomplete-input"  name="currency"></select>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
             <div id="toolbar">
-                <!-- <div class="col-sm-12"> -->
-                    <label for="current-journal">Sucursal: </label>
-                    <select id="current-journal" class=" ui-autocomplete-input"  name="journal"></select>
-                    <label for="current-currency">Moneda: </label>
-                    <select id="current-currency" class=" ui-autocomplete-input"  name="currency"></select>
-                    <label for="from" >Desde:</label>
-                    <input type="text" id="from" name="from"/>
-                    <label for="to" >Hasta: </label>
-                    <input type="text" id="to" name="to" />
-                <!-- </div> -->
-                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">Exportar a PDF</button>
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
                 <button class="oe_button oe_form_button oe_highlight" value="chart" id="chart">Graficar</button>
             </div>
             <table id="table"
@@ -38,8 +88,7 @@
                     </tr>
                 </thead>
             </table>
-            <div class="widget-content" id="grafico">
-            </div>
+            <div class="widget-content" id="grafico"></div>
             <div id="dialog"></div>
         </div>
     </t>

+ 93 - 43
static/src/reports/report_resumen_ingresos.xml

@@ -1,46 +1,96 @@
 <?xml version="1.0" encoding="UTF-8"?>
-  <template xml:space="preserve">
-      <t t-name="ReportResumenIngreso">
+    <template xml:space="preserve">
+        <t t-name="ReportResumenIngreso">
         <div class="report_view">
-          <div class="reporting_page_header">
-            <h1>Resumen de Ingreso</h1>
-            <div id="volver"></div>
-          </div>
-          <div id="toolbar">
-                <!-- <div class="col-sm-12"> -->
-                    <label for="current-journal">Sucursal: </label>
-                    <select id="current-journal" class=" ui-autocomplete-input"  name="journal"></select>
-                    <label for="current-currency">Moneda: </label>
-                    <select id="current-currency" class=" ui-autocomplete-input"  name="currency"></select>
-                    <label for="from" >Desde:</label>
-                    <input type="text" id="from" name="from"/>
-                    <label for="to" >Hasta: </label>
-                    <input type="text" id="to" name="to" />
-                <!-- </div> -->
-            <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">Exportar a PDF</button>
-            <button class="oe_button oe_form_button oe_highlight" value="chart" id="chart">Graficar</button>
+            <div class="reporting_page_header">
+                <h1>Resumen de Ingreso</h1>
+                <div id="volver"></div>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                     <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="current-journal">Sucursal: </label>
+                                    <select id="current-journal" class="form-control ui-autocomplete-input"  name="journal"></select>
+                                    <br/>
+                                    <label for="current-currency">Moneda: </label>
+                                    <select id="current-currency" class="form-control ui-autocomplete-input"  name="currency"></select>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">PDF</button>
+                <button class="oe_button oe_form_button oe_highlight" value="chart" id="chart">Graficar</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="journal" class="sucursal" >Sucursal</th>
+                        <th data-field="method" >Método de Pago</th>
+                        <th data-field="amount" data-align="right" >Pagos de Cliente</th>
+                    </tr>
+                </thead>
+            </table>
+            <div class="widget-content" id="grafico"></div>
+            <div id="dialog"></div>
         </div>
-        <table id="table"
-              data-classes="table table-hover table-condensed"
-              data-buttons-class="oe_button oe_form_button oe_highlight"
-              data-reorderable-columns="true"
-              data-height="auto"
-              data-pagination="false"
-              data-show-columns="true"
-              data-toolbar="#toolbar"
-              data-id-field="number"
-              data-row-style="rowStyle">
-            <thead >
-              <tr>
-                <th data-field="journal" class="sucursal" >Sucursal</th>
-                <th data-field="method" >Método de Pago</th>
-                <th data-field="amount" data-align="right" >Pagos de Cliente</th>
-              </tr>
-            </thead>
-        </table>
-        <div class="widget-content" id="grafico">
-        </div>
-        <div id="dialog"></div>
-      </div>
-      </t>
-  </template>
+    </t>
+</template>

+ 96 - 0
static/src/reports/report_sales.xml

@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportSale">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de Ventas</h1>
+                <div id="volver"></div>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <div class="card card-body">
+                    <br/>
+                    <div class="row">
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Fechas</div>
+                                <div class="panel-body">
+                                    <ul>
+                                        <li>
+                                            <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                            <label for="X">Sin Filtro</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="A" value="A"/> 
+                                            <label for="A">Hoy</label>  
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="B" value="B"/>
+                                            <label for="B">Ayer</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="C" value="C"/>
+                                            <label for="C">Mes Actual</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="D" value="D"/>
+                                            <label for="D">Mes Pasado</label>
+                                        </li>
+                                        <li>
+                                            <input type="radio" name="valores" id="Z" value="Z"/>
+                                            <label for="Z">Busqueda Avanzada</label>
+                                        </li>
+                                    </ul>
+                                    <div id="datepicker" style="display:none;" class="container">
+                                        <label for="from">Desde: </label>
+                                        <input type="text"  id="from" name="from"/>
+                                        <label for="to" >Hasta: </label>
+                                        <input type="text"  id="to" name="to" />    
+                                    </div>
+                                    
+                                </div>
+                            </div> 
+                        </div>
+                        <div class="col-xs-6">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="panel-body">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div> 
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <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="origin">Referencia</th>
+                        <th data-field="partner">Cliente</th>
+                        <th data-field="date_invoice">Fecha</th>
+                        <th data-field="amount_total" data-sortable="true" data-align="right">Total</th>
+                        <th data-field="residual" data-sortable="true" data-align="right">A cobrar</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 104 - 0
static/src/reports/report_sales_invoice_analysis.xml

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <template xml:space="preserve">
+      <t t-name="ReportSaleInvoiceAnalysis">
+        <div class="report_view">
+          <div class="reporting_page_header">
+            <h1>Análisis de facturas de ventas</h1>
+            <div id="volver"></div>
+          </div>
+          <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                        <label for="X">Sin Filtro</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/> 
+                                        <label for="A">Hoy</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />    
+                                </div>
+                                
+                            </div>
+                        </div> 
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off"/>   
+                                </div>
+                                <div class="form-group">
+                                    <label for="product">Buscar Producto</label>
+                                    <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>
+                                </div>     
+                            </div>
+                        </div> 
+                    </div>
+                </div>
+            </div>
+          <div id="toolbar">
+            <button class="oe_button oe_form_button oe_highlight" 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_name" >Cliente</th>
+                <th data-field="name" >Producto</th>
+                <th data-field="quantity" data-sortable="true" data-align="right">Cantidad</th>
+                <th data-field="price_unity" data-sortable="true" data-align="right">Precio Unitario</th>
+                <th data-field="standar_price" data-sortable="true" data-align="right">Precio de Costo</th>
+                <th data-field="price_tot" data-sortable="true" data-align="right">Total Venta</th>
+                <th data-field="standar_tot" data-sortable="true" data-align="right">Total Costo</th>
+                <th data-field="utility" data-sortable="true"  data-align="right">Utilidad</th>
+              </tr>
+            </thead>
+        </table>
+        <!-- <canvas></canvas> -->
+        <div class="widget-content" id="grafico"></div>
+        <div id="dialog"></div>
+      </div>
+      </t>
+  </template>

+ 60 - 0
static/src/reports/report_stock.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <template xml:space="preserve">
+        <t t-name="ReportStock">
+            <div class="report_view">
+                <div class="reporting_page_header">
+                    <h1>Análisis de Stock</h1>
+                    <button onclick="window.history.back()">Atrás</button>
+                </div>
+                <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+                </button>
+                <div class="collapse" id="collapseExample">
+                    <br/>
+                    <div class="row">
+                        <div class="col-xs-12">
+                            <div class="panel panel-default">
+                                <div class="panel-heading">Características</div>
+                                <div class="panel-body">
+                                    <div class="col-xs-6">
+                                        <div class="form-group">
+                                            <label for="current-category">Todas la categorias: </label>
+                                            <select id="current-category" class="form-control ui-autocomplete-input"  name="current-category"></select>
+                                        </div>
+                                        <div class="form-group">
+                                            <label for="product">Buscar Producto:</label>
+                                            <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ Referencia/ Codigo de barras"/>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div id="toolbar">
+                    <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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 class="table_header">
+                        <tr>
+                            <th data-field="product" data-sortable="true" >Producto</th>
+                            <th data-field="ean13" data-sortable="true" >Codigo de barras</th>
+                            <th data-field="category_name" data-sortable="true" >Categoria</th>
+                            <th data-field="qty" data-sortable="true" data-align="center">Cantidad</th>
+                            <th data-field="standard_price" data-sortable="true" data-align="right">Precio</th>
+                            <th data-field="valuation" data-sortable="true" data-align="right">Valoración</th>
+                        </tr>
+                    </thead>
+                </table>
+            </div>
+        </t>
+    </template>

+ 111 - 0
static/src/reports/report_stock_move.xml

@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportStockMove">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Análisis de Movimientos de Stock</h1>
+                <div id="volver"></div>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-md-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/> 
+                                        <label for="X">Sin Filtro</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/> 
+                                        <label for="A">Hoy</label>  
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />    
+                                </div>
+                                
+                            </div>
+                        </div> 
+                    </div>
+                    <div class="col-md-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <div class="form-group">
+                                    <label for="current-location-origin">Ubicacion de origen: </label>
+                                    <select id="current-location-origin" class="form-control ui-autocomplete-input"  name="current-location-origin"></select>    
+                                </div>
+                                <div class="form-group">
+                                    <label for="current-location-destiny">Ubicacion de destino: </label>
+                                    <select id="current-location-destiny" class="form-control ui-autocomplete-input"  name="current-location-destiny"></select>    
+                                </div>
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente/Proveedor:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                                <div class="form-group">
+                                    <label for="product">Buscar Producto:</label>
+                                    <input id="product" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre / Referencia / Codigo de barras"/>
+                                </div>
+                            </div>
+                        </div> 
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <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="picking_name" data-sortable="true">Referencia</th>
+                        <th data-field="origin_name" data-sortable="true">Origen</th>
+                        <th data-field="product_name" data-sortable="true">Producto</th>
+                        <th data-field="partner_name" data-sortable="true">Cliente / Proveedor</th>
+                        <th data-field="product_uom_qty">Cantidad</th>
+                        <th data-field="date_move" data-sortable="true">Fecha</th>
+                        <th data-field="location">Ubicacion de Origen</th>
+                        <th data-field="location_dest">Ubicacion de Destino</th>
+                        
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 0 - 1
static/src/reports/report_stock_product.xml

@@ -4,7 +4,6 @@
             <div class="report_view">
                 <div class="reporting_page_header">
                     <h1>Listado de productos</h1>
-                    <div id="volver"></div>
                 </div>
                 <div id="toolbar">
                     <button class="oe_button oe_form_button oe_highlight" value="pdf" id="pdf">Exportar</button>

+ 116 - 0
static/src/reports/report_vouchers.xml

@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportVoucher">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Histórico de pagos</h1>
+
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <h3>Tipo</h3>
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="tipo" id="Y" value="Y" checked="checked"/>
+                                        <label for="Y">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="tipo" id="customer" value="customer"/>
+                                        <label for="customer">Pagos de cliente</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="tipo" id="supplier" value="supplier"/>
+                                        <label for="supplier">Pagos a proveedores</label>
+                                    </li>
+                                </ul>
+                                <div class="form-group">
+                                    <label for="current-journal">Metodo de pago: </label>
+                                    <select id="current-journal" class="form-control ui-autocomplete-input"  name="current-journal"></select>
+                                </div>
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente / Proveedor:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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="reference" data-sortable="true">Factura</th>
+                        <th data-field="number">Nro. de pago</th>
+                        <th data-field="journal">Metodo de pago</th>
+                        <th data-field="date_voucher">Fecha</th>
+                        <th data-field="partner">Cliente/Proveedor</th>
+                        <th data-field="amount_in" data-sortable="true" data-align="right">Pagos de clientes</th>
+                        <th data-field="amount_out" data-sortable="true" data-align="right">Pagos a proveedores</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+</template>

+ 101 - 0
static/src/reports/report_works.xml

@@ -0,0 +1,101 @@
+<?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>
+
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <h3>Características</h3>
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente / Proveedor:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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="customer" data-sortable="true">Cliente</th>
+                        <th data-field="car">Vehiculo</th>
+                        <th data-field="agent">Aseguradora / Agente</th>
+                        <!-- <th data-field="secure">Aseguradora</th> -->
+                        <th data-field="date_in">Fecha 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" 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>
+        </div>
+    </t>
+</template>

+ 101 - 0
static/src/reports/reporting_account.xml

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportingAccount">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Listado de cuentas a cobrar vencidas</h1>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Ayer</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Pasado</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <label for="Y">Cliente</label>
+                                    </li>
+
+                                </ul>
+
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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="id" data-sortable="true">Id</th>
+                        <th data-field="reference" data-sortable="true">Nro Factura</th>
+                        <th data-field="partner" data-sortable="true">Cliente</th>
+                        <th data-field="date_maturity" data-sortable="true">Vence</th>
+                        <th data-field="amount_residual" data-sortable="true" data-align="right">Monto</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+    </template>

+ 102 - 0
static/src/reports/reporting_accountpending.xml

@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportingAccountPending">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1>Listado de cuentas a cobrar no vencidas</h1>
+                <button onclick="window.history.back()">Atrás</button>
+            </div>
+            <button type="button" class="oe_button oe_form_button oe_highlight" aria-label="Left Align" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FILTRAR
+            </button>
+            <div class="collapse" id="collapseExample">
+                <br/>
+                <div class="row">
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Fechas</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <input type="radio" name="valores" id="X" value="X" checked="checked"/>
+                                        <label for="X">Sin Filtro</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="A" value="A"/>
+                                        <label for="A">Hoy</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="B" value="B"/>
+                                        <label for="B">Mañana</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="C" value="C"/>
+                                        <label for="C">Mes Actual</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="D" value="D"/>
+                                        <label for="D">Mes Próximo</label>
+                                    </li>
+                                    <li>
+                                        <input type="radio" name="valores" id="Z" value="Z"/>
+                                        <label for="Z">Busqueda Avanzada</label>
+                                    </li>
+                                </ul>
+                                <div id="datepicker" style="display:none;" class="container">
+                                    <label for="from">Desde: </label>
+                                    <input type="text"  id="from" name="from"/>
+                                    <label for="to" >Hasta: </label>
+                                    <input type="text"  id="to" name="to" />
+                                </div>
+
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-6">
+                        <div class="panel panel-default">
+                            <div class="panel-heading">Características</div>
+                            <div class="panel-body">
+                                <ul class="list-unstyled">
+                                    <li>
+                                        <label for="Y">Cliente</label>
+                                    </li>
+
+                                </ul>
+
+                                <div class="form-group">
+                                    <label for="partner">Buscar Cliente:</label>
+                                    <input id="partner" type="text" class="form-control ui-autocomplete-input" autocomplete="off" placeholder="Nombre/ CI/ Ruc"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div id="toolbar">
+                <button class="oe_button oe_form_button oe_highlight" value="pdf" id="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="id" data-sortable="true">Id</th>
+                        <th data-field="reference" data-sortable="true">Nro Factura</th>
+                        <th data-field="partner" data-sortable="true">Cliente</th>
+                        <th data-field="date_maturity" data-sortable="true">Vence</th>
+                        <th data-field="amount_residual" data-sortable="true" data-align="right">Monto</th>
+                    </tr>
+                </thead>
+            </table>
+            <canvas></canvas>
+            <div id="dialog"></div>
+        </div>
+    </t>
+    </template>

+ 41 - 6
templates.xml

@@ -12,14 +12,49 @@
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/configuration_reporting.js" />
 
                 <!-- Reportes -->
-                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_invoice_utility.js" />
-                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_resumen_egresos.js" />
+                <!-- Resumen de Ingresos -->
                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_resumen_ingresos.js" />
-                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_puchases.js" />
-                <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" />
+                <!-- Resumen de egresos -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_resumen_egresos.js" />
+                <!-- Historico de pagos -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_vouchers.js" />
+                <!-- Historico de facturas -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_invoice_balance.js" />
+                <!-- Historico de ventas -->
+                <!-- <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_sales.js" /> -->
+                <!-- Historico de compras -->
+                <!-- <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_puchases.js" /> -->
+                <!-- Historico de gastos -->
+                <!-- <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_expenses.js" /> -->
+                <!-- Analisis de ventas -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_sales_invoice_analysis.js" />
+                <!-- Analisis de compras -->
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_purchases_invoice_analysis.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock.js" />
+                <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_stock_move.js" />
+                <!-- crm -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_crm.js"/>
+                 <!-- crm_phonecall -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_phonecall.js"/>
+                 <!-- crm_mensaje -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_mensajecrm.js"/>
+                 <!-- project -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_project.js"/>
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_balance.js" />
+                 <!-- account -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/reporting_account.js"/>
+                 <!-- accountpending -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/reporting_accountpending.js"/>
+                 <!-- work -->
+                 <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_works.js" />
+                <!-- Analisis de gastos -->
+                <!-- <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_expenses_invoice _analysis.js" /> -->
+                <!-- Utilidad de facturas detalladas -->
+                <!-- <script type="text/javascript" src="/eiru_reporting/static/src/js/reports/report_invoice_utility.js" /> -->
+                <!-- Listado de productos -->
+                <!-- <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_stock_location.js" /> -->
             </xpath>
         </template>