Browse Source

[FIX] ajustes varios

Rodney Elpidio Enciso Arias 6 years ago
parent
commit
90c9880590

+ 14 - 2
controllers/helpers/account_invoice.py

@@ -16,7 +16,11 @@ def get_account_invoice():
         	invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as invoice_rate,
             invoice.number,
             invoice.is_interest,
-            customer.name
+            customer.name,
+            invoice.state,
+            invoice.journal_id,
+            invoice.company_id,
+            journal.store_id
         FROM account_invoice AS invoice
         LEFT JOIN res_store_journal_rel AS journal
         ON journal.journal_id = invoice.journal_id
@@ -39,7 +43,11 @@ def get_account_invoice():
         	invoice.user_id,
             invoice.amount_total,
             invoice.is_interest,
-            customer.name
+            customer.name,
+            invoice.state,
+            invoice.journal_id,
+            invoice.company_id,
+            journal.store_id
     '''
 
     r.cr.execute(query,(tuple([company_currency_rate])))
@@ -57,5 +65,9 @@ def get_account_invoice():
             'number':j[8],
             'is_interest':j[9],
             'customer_name':j[10],
+            'state':j[11],
+            'journal_id':j[12],
+            'company_id':j[13],
+            'store_id':j[14],
         } for j in r.cr.fetchall()
     ]

+ 122 - 5
static/src/js/reports/report_amortization_and_interest.js

@@ -61,11 +61,35 @@ function report_amortization_and_interest(reporting){
             self.fetchDataSQL().then(function (DataSQL) {
                 return DataSQL;
             }).then(function(DataSQL) {
-                self.AccountInvoice = DataSQL.invoices;
-                self.AccountInvoiceLine = DataSQL.invoice_lines;
-                self.AccountJournal = DataSQL.journals;
                 self.ResCompany = DataSQL.companies;
+                if(self.ResCompany.length > 1){
+                    self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
+                    _.each(self.ResCompany,function(item){
+                        self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.company').css('display','none');
+                }
                 self.ResStore = DataSQL.stores;
+                if(self.ResStore.length > 1){
+                    self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                    _.each(self.ResStore,function(item){
+                        self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.store').css('display','none');
+                }
+                self.AccountJournal = DataSQL.journals;
+                if(self.AccountJournal.length > 1){
+                    self.$el.find('#current-journal').append('<option value="9999999">Todas las Facturas</option>');
+                    _.each(self.AccountJournal,function(item){
+                        self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.journal').css('display','none');
+                }
+                self.AccountInvoice = DataSQL.invoices;
+                self.AccountInvoiceLine = DataSQL.invoice_lines;
                 self.AccountMoveLine = DataSQL.move_lines;
                 self.AccountVoucher = DataSQL.vouchers;
             });
@@ -87,6 +111,7 @@ function report_amortization_and_interest(reporting){
                     backgroundColor: '#FAFAFA'
                 }
             });
+
             return self.BuildTable();
         },
 
@@ -132,13 +157,95 @@ function report_amortization_and_interest(reporting){
             }));
         },
 
+        getContent: function (id) {
+            var self = this;
+            var content = self.AccountInvoice;
+
+            var company = $('#current-company').val();
+            var store = $('#current-store').val();
+            var journal = $('#current-journal').val();
+            var state = $('#current-state').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            if(company && company != 9999999){
+                content = _.filter(content,function (item) {
+                    return item.company_id == company;
+                });
+            }
+
+            if(store && store != 9999999){
+                content = _.filter(content,function (item) {
+                    return item.store_id == store;
+                });
+            }
+
+            if(journal && journal != 9999999){
+                content = _.filter(content,function (item) {
+                    return item.journal_id == journal;
+                });
+            }
+
+            if(state && state != 9999999){
+                content = _.filter(content,function (item) {
+                    return item.state == state;
+                });
+            }
+
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.filter(content,function (item) {
+                            return item.date >= date;
+                        });
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.filter(content,function (item) {
+                            return item.date <= date;
+                        });
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.filter(content,function (item) {
+                        return item.date == today;
+                    });
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.filter(content,function (item) {
+                        return item.date == yesterday;
+                    });
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.filter(content,function (item) {
+                        return moment(item.date).format('YYYY-MM') == currentMonth;
+                    });
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.filter(content,function (item) {
+                        return moment(item.date).format('YYYY-MM') == lastMonth;
+                    });
+                }
+            }
+
+            return content;
+        },
+
         BuildTable: function(){
             var self = this;
-            console.log(self);
             var columns = [];
             var data = [];
+            var AccountInvoice = self.getContent();
             var CurrencyBase = self.ResCompany[0].currency_id;
-            _.each(self.AccountInvoice,function(item) {
+            _.each(AccountInvoice,function(item) {
                 if(item.is_interest == null){
                     var pagado = self.getAccountVoucher(item.number);
                     var AccountInvoiceLine = self.getAccountInvoiceLine(item.invoice_id);
@@ -187,6 +294,7 @@ function report_amortization_and_interest(reporting){
                             DATOS SIN FORMATO
                         ########################
                         */
+                        date:item.date,
                         capital_amount_value: capital,
                         interest_amount_value:interes,
                         amount_value:item.amount,
@@ -194,6 +302,15 @@ function report_amortization_and_interest(reporting){
                     });
                 }
             });
+            data.sort(function (a, b) {
+                if (a.date > b.date) {
+                    return -1;
+                }
+                if (a.date < b.date) {
+                    return 1;
+                }
+                return 0;
+            });
             self.loadTable(data);
             self.$el.find('.report-form').css('display','block');
             self.$el.find('.search-form').unblock();

+ 9 - 14
static/src/reports/report_amortization_and_interest.xml

@@ -16,24 +16,19 @@
                         <select id="current-store" class="form-control form-control-sm">
                         </select>
                     </div>
-                    <!-- <div class="col-lg-3 journal filter-style">
+                    <div class="col-lg-3 journal filter-style">
                         <label>Factura</label>
                         <select id="current-journal" class="form-control form-control-sm">
                         </select>
-                    </div> -->
-                    <!-- <div class="col-lg-3 type filter-style">
-                        <label>Tipo de Venta</label>
-                        <select id="current-type" class="form-control form-control-sm">
-                            <option value="9999999">Todos los Tipos</option>
-                            <option value="tpv">Terminal</option>
-                            <option value="sale">Normal</option>
-                        </select>
-                    </div> -->
-                    <!-- <div class="col-lg-3 filter-style">
-                        <label>Periodo</label>
-                        <select id="current-period" class="form-control form-control-sm">
+                    </div>
+                    <div class="col-lg-3 filter-style">
+                        <label>Estado de cuentas</label>
+                        <select id="current-state" class="form-control form-control-sm">
+                            <option value="9999999">Todos los estados</option>
+                            <option value="open">Abiertos</option>
+                            <option value="paid">Pagados</option>
                         </select>
-                    </div> -->
+                    </div>
                     <div class="col-lg-3 filter-style">
                         <label>Fechas</label>
                         <select id="current-date" class="form-control form-control-sm">