Browse Source

[FIX] agregado impresion del pdf

Rodney Elpidio Enciso Arias 6 years ago
parent
commit
1ebff179a5

+ 1 - 0
controllers/helpers/__init__.py

@@ -3,6 +3,7 @@ from account_invoice import get_account_invoice
 from account_invoice_line import get_account_invoice_line
 from account_journal import get_account_journal
 from res_company import get_res_company
+from res_company import get_res_company_logo
 from res_store import get_res_store
 from account_move_line import get_account_move_line
 from account_voucher import get_account_voucher

+ 11 - 0
controllers/helpers/res_company.py

@@ -42,3 +42,14 @@ def get_res_company():
             'ruc': j[9],
         } for j in r.cr.fetchall()
     ]
+
+def get_res_company_logo():
+    values = []
+    for company in r.env['res.company'].search([]):
+        values.append({
+            'id': company.id,
+            'name': company.name,
+            'logo': company.logo,
+        })
+
+    return values

+ 1 - 0
controllers/main.py

@@ -35,6 +35,7 @@ class ReportCrifinController(http.Controller):
             'invoice_lines': hp.get_account_invoice_line(),
             'journals': hp.get_account_journal(),
             'companies': hp.get_res_company(),
+            'company_logo': hp.get_res_company_logo(),
             'stores': hp.get_res_store(),
             'move_lines': hp.get_account_move_line(),
             'vouchers': hp.get_account_voucher(),

+ 152 - 116
static/src/js/reports/report_amortization_and_interest.js

@@ -11,11 +11,9 @@ function report_amortization_and_interest(reporting){
         modules: ['point_of_sale'],
 
         events:{
-            // 'click #toolbar > button' : 'clickOnAction',
+            'click #toolbar > button' : 'clickOnAction',
             'click #generate' : 'fetchGenerate',
-            // 'change #current-company' : 'updateSelections',
             'change #current-date' : 'ShowDateRange',
-            // 'change #current-period' : 'updatePeriodSelections',
         },
 
         init : function(parent){
@@ -88,6 +86,7 @@ function report_amortization_and_interest(reporting){
                 }else{
                     self.$el.find('.journal').css('display','none');
                 }
+                self.ResCompanyLogo = DataSQL.company_logo;
                 self.AccountInvoice = DataSQL.invoices;
                 self.AccountInvoiceLine = DataSQL.invoice_lines;
                 self.AccountMoveLine = DataSQL.move_lines;
@@ -241,6 +240,7 @@ function report_amortization_and_interest(reporting){
 
         BuildTable: function(){
             var self = this;
+            console.log(self);
             var columns = [];
             var data = [];
             var AccountInvoice = self.getContent();
@@ -494,122 +494,9 @@ function report_amortization_and_interest(reporting){
             $el.bootstrapTable({
                 columns: columns,
                 data: data,
-                // onExpandRow: function (index, row, $detail) {
-                //     self.expandSubTable($detail,row.id);
-                // }
             });
         },
 
-        // expandSubTable: function($detail,id) {
-        //     var self = this;
-        //     self.BuildSubSubTable($detail.html('<table data-detail-view="true" data-classes="table table-condensed"></table>').find('table'),id);
-        // },
-        //
-        // BuildSubSubTable: function($el,id) {
-        //     var self = this;
-        //     var columns = [];
-        //     var data = [];
-        //     columns.push({
-        //         field: 'id',
-        //         title: 'ID',
-        //         visible: false,
-        //     });
-        //     columns.push({
-        //         field: 'ruc',
-        //         title: 'RUC',
-        //         with:'15%',
-        //     });
-        //     columns.push({
-        //         field: 'name',
-        //         title: 'Nombre',
-        //     });
-        //     columns.push({
-        //         field: 'amount',
-        //         title: 'Valor',
-        //         align:'right',
-        //         with:'15%',
-        //     });
-        //     var company = $('#current-company').val();
-        //     if(company && company != 9999999){
-        //         var ResCompany = self.getResCompany(company).shift();
-        //         var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
-        //     }else{
-        //         var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
-        //     };
-        //     _.each(self.ResPartner,function(item) {
-        //         if(item.state_id.id == id){
-        //             var amount = self.getAmount([item.id]);
-        //             data.push({
-        //                 'id': item.id,
-        //                 'ruc': self.valorNull(item.ruc),
-        //                 'name': item.name,
-        //                 'amount': accounting.formatMoney(amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
-        //             });
-        //         };
-        //     });
-        //     $el.bootstrapTable({
-        //         columns: columns,
-        //         data: data,
-        //         onExpandRow: function (index, row, $detail) {
-        //             self.expandSubSubTable($detail,row.id);
-        //         }
-        //     });
-        // },
-        //
-        // expandSubSubTable: function($detail,id) {
-        //     var self = this;
-        //     self.BuildSubSubSubTable($detail.html('<table data-classes="table table-condensed"></table>').find('table'),id);
-        // },
-        //
-        // BuildSubSubSubTable: function($el,id) {
-        //     var self = this;
-        //     var columns = [];
-        //     var data = [];
-        //     columns.push({
-        //         field: 'date',
-        //         title: 'Fecha',
-        //         with:'15%',
-        //     });
-        //     columns.push({
-        //         field: 'number',
-        //         title: 'Factura',
-        //     });
-        //     columns.push({
-        //         field: 'amount',
-        //         title: 'Valor',
-        //         align:'right',
-        //         with:'15%',
-        //     });
-        //     var company = $('#current-company').val();
-        //     if(company && company != 9999999){
-        //         var ResCompany = self.getResCompany(company).shift();
-        //         var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
-        //     }else{
-        //         var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
-        //     }
-        //     var invoice = self.getInvoiceDetails([id]);
-        //     _.each(invoice,function(index) {
-        //         data.push({
-        //             'date': moment(index.date_invoice).format('DD/MM/YYYY'),
-        //             'number': index.number,
-        //             'amount': accounting.formatMoney(index.amount_currency, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
-        //         });
-        //     });
-        //     var pos = self.getPosDetails([id]);
-        //     _.each(pos,function(index) {
-        //         var utc = moment.utc(index.date_order,'YYYY-MM-DD h:mm:ss A');
-        //         data.push({
-        //             'date': moment(utc._d).format('DD/MM/YYYY'),
-        //             'number': index.number,
-        //             'amount': accounting.formatMoney(index.amount_currency, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
-        //         });
-        //     });
-        //     $el.bootstrapTable({
-        //         columns: columns,
-        //         data: data,
-        //     });
-        // },
-
         loadTable:function(rowsTable){
             var self = this;
             self.rowsData = rowsTable;
@@ -617,5 +504,154 @@ function report_amortization_and_interest(reporting){
             table.bootstrapTable('load', rowsTable);
         },
 
+        /*====================================================================
+            GET RES COMPANY
+        ====================================================================*/
+        getResCompany: function (id) {
+            var self = this;
+            return _.filter(self.ResCompanyLogo,function (item) {
+                return item.id == id;
+            });
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var ResCompany;
+            var action = this.$el.find(e.target).val();
+            var company = $('#current-company').val();
+            var CurrencyBase;
+            if(company && company != 9999999){
+                ResCompany = self.getResCompany(company).shift();
+                CurrencyBase = self.ResCompany[0].currency_id;
+            }else{
+                ResCompany = self.ResCompanyLogo[0];
+                CurrencyBase = self.ResCompany[0].currency_id;
+            }
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#xtable");
+            var column = table.bootstrapTable('getVisibleColumns');
+            var row = table.bootstrapTable('getData');
+
+            var capital_amount = CapitalAmountFormatter(row);
+            var interest_amount = InterestAmountFormatter(row);
+            var amount = AmountFormatter(row);
+            var residual = ResidualAmountFormatter(row);
+
+            row.push({
+                number:'Totales',
+                capital_amount:capital_amount,
+                interest_amount:interest_amount,
+                amount:amount,
+                residual:residual,
+            });
+
+            if (action === 'pdf') {
+                var data = _.map(column, function (val){
+                    return val.field;
+                });
+                _.each(_.map(column,function(val){
+                    return val;
+                }), function(item){
+                    getColumns.push([{
+                        title: item.title,
+                        dataKey: item.field
+                    }]);
+                });
+
+                var pdf_title = 'Amortizaciones e Intereses';
+                var pdf_type = '';
+                var pdf_name = 'amortizaciones_e_intereses';
+                var pdf_columnStyles =  {
+                    number:{columnWidth: 20, halign:'left'},
+                    origin:{columnWidth: 20, halign:'left'},
+                    customer_name:{halign:'left'},
+                    date_invoice:{columnWidth: 20, halign:'left'},
+                    capital_amount :{columnWidth: 25, halign:'right'},
+                    interest_amount :{columnWidth: 25, halign:'right'},
+                    amount :{columnWidth: 25, halign:'right'},
+                    residual:{columnWidth: 25, halign:'right'},
+                };
+
+                var filter = self.getFilter();
+                var pdf = new model.eiru_reports.ReportPdfWidget(self);
+                pdf.drawPDF(
+                    _.flatten(getColumns),
+                    row,
+                    ResCompany,
+                    pdf_title,
+                    pdf_type,
+                    pdf_name,
+                    pdf_columnStyles,
+                    filter
+                );
+            }
+        },
+
+        getFilter: function(){
+            var self = this;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var filter = [];
+            var fecha;
+            if(company && company){
+                var ResCompany = _.filter(self.ResCompany, function(item){
+                    return item.id == company;
+                });
+                filter.push({
+                    title:'Empresa',
+                    value: ResCompany[0].name,
+                });
+            }
+            if(store && store != 9999999){
+                var ResStore =  _.filter(self.ResStore,function (item) {
+                   return item.id == store;
+                });
+                filter.push({
+                   title: 'Sucursal',
+                   value:  ResStore[0].name,
+                });
+            }
+
+            if(date && date != 9999999){
+                moment.locale('es', {
+                    months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
+                });
+                if(date == 'range'){
+                    filter.push({
+                        title: 'Fecha',
+                        value:  desde +' al '+hasta,
+                    });
+                    } else {
+                        if(date == 'today'){
+                            fecha = moment().format('DD/MM/YYYY');
+                        }
+                        if(date == 'yesterday'){
+                            fecha = moment().add(-1,'days').format('DD/MM/YYYY');
+                        }
+                        if(date == 'currentMonth'){
+                            fecha = moment().format('MMMM/YYYY');
+                        }
+                        if(date == 'lastMonth'){
+                            fecha = moment().add(-1,'months').format('MMMM/YYYY');
+                        }
+                        filter.push({
+                            title: 'Fecha',
+                            value:  fecha,
+                        });
+                    }
+                }
+           return filter;
+        },
+
+
+
+
+
+
+
     });
 }

+ 3 - 4
static/src/reports/report_amortization_and_interest.xml

@@ -68,11 +68,10 @@
             </div>
 
             <div class="report-form" style="display:none;">
-                <!-- <div id="toolbar">
+                <div id="toolbar">
                     <button class="oe_button myButton" value="pdf">Imprimir Informe</button>
-                </div> -->
+                </div>
                 <div class="container" style="width:95%;">
-                     <!-- table-no-bordered -->
                     <table
                         id = "xtable"
                         data-show-columns="true"
@@ -94,7 +93,7 @@
                             <tr>
                                 <th data-field="id" data-visible="false">ID</th>
                                 <th data-field="number" data-footer-formatter="Totales">Factura</th>
-                                <th data-field="origin">Documento Origen</th>
+                                <th data-field="origin">Origen</th>
                                 <th data-field="customer_name">Cliente</th>
                                 <th data-field="date_invoice">Fecha</th>
                                 <th data-field="capital_amount" data-footer-formatter="CapitalAmountFormatter" data-align="right" data-width="12%">Capital</th>