Quellcode durchsuchen

Modificar informes de cuentas

root vor 2 Jahren
Ursprung
Commit
85d5d02771
4 geänderte Dateien mit 563 neuen und 177 gelöschten Zeilen
  1. 2 0
      models.py
  2. BIN
      models.pyc
  3. 122 33
      static/src/js/reports/report_cuenta_resumen_dna.js
  4. 439 144
      static/src/js/reports/report_seller.js

+ 2 - 0
models.py

@@ -126,6 +126,8 @@ class AccountVoucher(models.Model):
 				'amount': voucher.amount,
 				'reference' : voucher.reference,
 				'date': voucher.date,
+				'state': voucher.state,
+				'type': voucher.type,
 			})
 
 		return values

BIN
models.pyc


+ 122 - 33
static/src/js/reports/report_cuenta_resumen_dna.js

@@ -408,7 +408,7 @@ function report_cuenta_resumen_dna(reporting){
               var self = this;
               var defer = $.Deferred();
               var AccountVoucher = new model.web.Model('account.voucher');
-              AccountVoucher.query(['id', 'number','reference','partner_id','date','number','type']).filter([['state', '=', 'posted']]).all().then(function(results){
+              AccountVoucher.query(['id', 'number','reference','partner_id','date','amount','type']).filter([['state', '=', 'posted']]).all().then(function(results){
                   defer.resolve(results);
               });
               return defer;
@@ -527,11 +527,98 @@ function report_cuenta_resumen_dna(reporting){
             })
         },
 
-        getAccountVoucher: function (id) {
+        // getAccountVoucher: function (id) {
+        //     var self = this;
+        //     return _.filter(self.AccountVoucher,function (item) {
+        //         return item.reference === id;
+        //     });
+        // },
+
+
+        getAccountVoucher:function(id) {
             var self = this;
-            return _.filter(self.AccountVoucher,function (item) {
-                return item.reference === id;
-            });
+            var content = self.AccountVoucher;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var journal = self.$el.find('#current-journal').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            content = _.filter(content,function (item) {
+                return item.reference == id;
+            })
+
+            if((store && store == 9999999)||(company && company == 9999999)){
+                var store_ids = _.flatten(_.map(self.ResStore, function (item) {
+                    return item.id;
+                }));
+                var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
+                    return item.id;
+                }));
+                content = _.flatten(_.filter(content,function (item) {
+                    return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
+                }));
+            }
+
+            if(company && company != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.company_id == company;
+                }));
+            }
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.store_id == store;
+                }));
+            }
+            if(journal && journal != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.journal_id == journal;
+                }));
+            }
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') <= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === lastMonth;
+                    }));
+                }
+            }
+            return content;
         },
 
 
@@ -699,38 +786,40 @@ function report_cuenta_resumen_dna(reporting){
             var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
           };
 
-          // var AccountJournal = self.AccountJournal;
-          // _.each(AccountJournal,function(item) {
 
-            // var AccountInvoice = self.getAccountInvoice(item.id);
             var AccountInvoice = self.AccountInvoice;
             _.each(AccountInvoice,function(item2) {
+                var amount_saldo = 0;
+                var amount_venta = 0;
+                var amount_pagado = 0;
               if (item2.residual>0){
                     var description_product = '';
                     var date_pay = '';
                     var date = '';
                     if(item2.is_anticipo == false){
-                    var total_sale = 0;
-                    var forma = 'Contado';
-                     if (item2.contado == true){
-                        forma = 'Contado'
-                     };
-                     if (item2.credito == true){
-                        forma = 'Credito'
-                     };
-                     if (!item2.date_pay){
-                        date_pay = ''
-                     };
-                     if (item2.date_pay){
-                        date_pay = item2.date_pay
-                     };
-                     var voucher = self.getAccountVoucher(item2.number).shift();
-
-                     if (voucher != null){
-                          date = voucher.date
-                      }else{
-                            date = ''
-                      }
+                        var total_sale = 0;
+                        var forma = 'Contado';
+                         if (item2.contado == true){
+                            forma = 'Contado'
+                         };
+                         if (item2.credito == true){
+                            forma = 'Credito'
+                         };
+                         if (!item2.date_pay){
+                            date_pay = ''
+                         };
+                         if (item2.date_pay){
+                            date_pay = item2.date_pay
+                         };
+
+                         var AccountVoucher = self.getAccountVoucher(item2.number);
+
+                         var date = '';
+                         _.each(AccountVoucher, function(each){
+                                   date = each.date
+                                   amount_pagado = amount_pagado+each.amount
+                         });
+
 
 
                      var AccountInvoiceLine = self.getAccountInvoiceLine(item2.id);
@@ -759,12 +848,12 @@ function report_cuenta_resumen_dna(reporting){
                               date_pago:  moment(date).format('DD/MM/YYYY'),
                               product_name: description_product,
                               amount_total: accounting.formatMoney(item2.amount_total_currency, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
-                              amount_pagado:accounting.formatMoney(item2.amount_total - item2.residual,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
-                              amount_residual: accounting.formatMoney((item2.residual * (CurrencyBase.rate_silent/currency.rate_silent)), '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                              amount_pagado:accounting.formatMoney(amount_pagado,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                              amount_residual: accounting.formatMoney(((item2.amount_total_currency-amount_pagado) * (CurrencyBase.rate_silent/currency.rate_silent)), '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
                               date: item2.date_invoice,
                               amount : (item2.amount_total),
-                              residual: (item2.residual),
-                              pagado: item2.amount_total - item2.residual,
+                              residual: (item2.amount_total - amount_pagado),
+                              pagado: amount_pagado,
                               user_id : self.valorNull(item2.user_id[0]),
                               user_name : item2.user_id[1],
 

+ 439 - 144
static/src/js/reports/report_seller.js

@@ -1,16 +1,18 @@
-function report_seller(reporting){
+function report_cuenta_resumen_dna(reporting){
     "use strict";
 
     var model = openerp;
 
-    reporting.ReportSellerWidget = reporting.Base.extend({
-        template: 'ReportSeller',
+    reporting.ReportCuentaResumenDnaWidget = reporting.Base.extend({
+        template: 'ReportCuentaResumenDna',
         rowsData :[],
         content :[],
+        modules: ['product_brand'],
 
         events:{
             'click #toolbar > button' : 'clickOnAction',
             'click #generate' : 'fetchGenerate',
+            'click-row.bs.table #table' : 'clickAnalysisDetail',
             'change #current-company' : 'updateSelections',
             'change #current-store' : 'updateJournalSelections',
             'change #current-date' : 'ShowDateRange',
@@ -49,6 +51,37 @@ function report_seller(reporting){
 
         },
 
+        clickAnalysisDetail: function(e, row, $element,field){
+            if (field == 'partner_name'){
+                this.do_action({
+                    name:"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,
+                });
+            }
+
+            if (field == 'invoice_name'){
+                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,
+                });
+            }
+            e.stopImmediatePropagation();
+        },
+
         fetchInitial: function () {
             var self = this;
             self.fetchResCompany().then(function (ResCompany) {
@@ -63,17 +96,6 @@ function report_seller(reporting){
                 }else{
                     self.$el.find('.company').css('display','none');
                 }
-                return self.fetchResUser();
-           }).then(function(ResUser){
-                  self.ResUser = ResUser;
-                  if(ResUser.length > 1){
-                      self.$el.find('#current-user').append('<option value="9999999">Todas los vendedores</option>');
-                      _.each(ResUser,function(item){
-                          self.$el.find('#current-user').append('<option value="' + item.id + '">' + item.name + '</option>');
-                      });
-                  }else{
-                      self.$el.find('.user').css('display','none');
-                  }
                 return self.fetchResStore();
             }).then(function(ResStore){
                 self.ResStore = ResStore;
@@ -103,6 +125,20 @@ function report_seller(reporting){
                 _.each(AccountPeriod,function(item){
                     self.$el.find('#current-period').append('<option value="' +  item.id + '">' + item.name + '</option>');
                 });
+                return self.fetchResPartner();
+          }).then(function(ResPartner){
+                self.ResPartner = ResPartner;
+                return self.fetchProductCategory();
+          }).then(function(ProductCategory){
+              self.ProductCategory = ProductCategory;
+              if(ProductCategory.length > 1){
+                  self.$el.find('#current-category').append('<option value="9999999">Todas las categorias</option>');
+                  _.each(ProductCategory,function(item){
+                      self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
+                  });
+              }else{
+                  self.$el.find('.category').css('display','none');
+              }
                 return self.fetchResCurrency();
             }).then(function(ResCurrency){
                 self.ResCurrency = ResCurrency;
@@ -126,16 +162,16 @@ function report_seller(reporting){
                 }
             });
 
-            this.fetchAccountJournal().then(function(AccountJournal) {
-                return AccountJournal;
-            }).then(function (AccountJournal) {
-                self.AccountJournal = AccountJournal;
-                return self.fetchAccountInvoice();
+            this.fetchAccountInvoice().then(function(AccountInvoice) {
+                return AccountInvoice;
             }).then(function (AccountInvoice){
                 self.AccountInvoice = AccountInvoice;
                 return self.fetchAccountInvoiceLine();
             }).then(function (AccountInvoiceLine){
                 self.AccountInvoiceLine = AccountInvoiceLine;
+                return self.fetchAccountVoucher();
+            }).then(function (AccountVoucher){
+                self.AccountVoucher = AccountVoucher;
                 return self.BuildTable();
             });
         },
@@ -170,16 +206,23 @@ function report_seller(reporting){
             return defer;
         },
 
+
+        fetchResPartner: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var ResPartner = new model.web.Model('res.partner');
+            ResPartner.query(['id', 'name', 'ruc', 'mobile', 'email']).filter([['active', '=', true], ['customer', '=', true]]).all().then(function (results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
         /*====================================================================
             ACCOUNT JOURNAL
         ====================================================================*/
         fetchAccountJournal: function(){
             var self = this;
-            var journal = self.$el.find('#current-journal').val();
-            var domain = [['active','=',true],['type','=','sale']];
-            if(journal && journal != 9999999){
-                domain.push(['id','=',parseInt(journal)]);
-            }
+            var domain = [['active','=',true],['type','in',['sale','sale_refund']]];
             var AccountJournal = new model.web.Model('account.journal');
             return AccountJournal.call('getAccountJournal',[domain], {
                 context: new model.web.CompoundContext()
@@ -201,6 +244,19 @@ function report_seller(reporting){
             return defer;
         },
 
+        /*====================================================================
+        PRODUCT CATEGORY
+    ====================================================================*/
+    fetchProductCategory: function () {
+        var self = this;
+        var domain = [];
+        var ProductCategory = new model.web.Model('product.category');
+        return ProductCategory.call('getProductCategory',[domain], {
+            context: new model.web.CompoundContext()
+        });
+    },
+
+
         /*====================================================================
             RES CURRENCY
         ====================================================================*/
@@ -217,56 +273,44 @@ function report_seller(reporting){
         },
 
 
-        fetchResUser: function() {
-            var self = this;
-            var defer = $.Deferred();
-            var fields = ['id','name','store_id'];
-            var domain = [];
-            var ResUser = new model.web.Model('res.users');
-            ResUser.query(fields).filter(domain).all().then(function (results) {
-                defer.resolve(results);
-            });
-            return defer;
-        },
-
-
-        getAccountInvoice:function(id) {
-            var self = this;
-            return _.flatten(_.filter(self.AccountInvoice,function (inv) {
-                return inv.user_id === id && inv.type == 'out_invoice';
-            }));
-        },
-
         /*====================================================================
             ACCOUNT INVOICE
         ====================================================================*/
         fetchAccountInvoice: function () {
             var self = this;
+            var content = self.AccountInvoice;
             var store = self.$el.find('#current-store').val();
             var period = self.$el.find('#current-period').val();
             var company = self.$el.find('#current-company').val();
-
+            var state = self.$el.find('#current-state').val();
+            var journal = self.$el.find('#current-journal').val();
+            var invoice_type = self.$el.find('#current-invoice-type').val();
             var date = self.$el.find('#current-date').val();
             var desde = self.$el.find('#from').val();
             var hasta = self.$el.find('#to').val();
 
-            // if(store && store != 9999999){
-            //     var journal_ids = _.map(_.filter(self.AccountJournal,function (item) {
-            //         return item.store_ids == store;
-            //     }), function(map){
-            //         return map.id;
-            //     });
-            // }else{
-            //     var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
-            //         return item.id;
-            //     }));
-            // }
+            if(store && store != 9999999){
+                var journal_ids = _.map(_.filter(self.AccountJournal,function (item) {
+                    return item.store_ids == store;
+                }), function(map){
+                    return map.id;
+                });
+            }else{
+                var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
+                    return item.id;
+                }));
+            }
 
             var domain = [
                 ['state', 'in',['open','paid']],
-                ['type', '=', 'out_invoice'],
+                ['type', 'in', ['out_invoice']],
+                ['journal_id','in',journal_ids],
             ];
 
+            if(journal && journal != 9999999){
+                domain.push(['journal_id','=',parseInt(journal)]);
+            }
+
             if(company && company != 9999999){
                 domain.push(['company_id','=',parseInt(company)]);
             }
@@ -274,17 +318,22 @@ function report_seller(reporting){
             if(period && period != 9999999){
                 domain.push(['period_id','=',parseInt(period)]);
             }
+            if(state && state != 9999999){
+                if(state == 'open'){
+                    content = [];
+                }
+            }
 
             if(date && date != 9999999){
 
                 if(desde){
-                    var date = desde.split('/')
+                    date = desde.split('/')
                     date = (date[2]+"-"+date[1]+"-"+date[0]);
                     domain.push(['date_invoice','>=',date]);
                 }
 
                 if(hasta){
-                    var date = hasta.split('/')
+                    date = hasta.split('/')
                     date = (date[2]+"-"+date[1]+"-"+date[0]);
                     domain.push(['date_invoice','<=',date]);
                 }
@@ -316,23 +365,54 @@ function report_seller(reporting){
             });
         },
 
-
         /*====================================================================
-                  ACCOUNT INVOICE LINE
+            ACCOUNT INVOICE LINE
         ====================================================================*/
         fetchAccountInvoiceLine: function () {
             var self = this;
+            var categ_ids = [];
+            var category = self.$el.find('#current-category').val();
             var invoice_ids = _.flatten(_.map(self.AccountInvoice, function (item) {
-                  return item.id;
+                return item.id;
             }));
             var domain = [
-                  ['invoice_id','in',invoice_ids],
+                ['invoice_id','in',invoice_ids],
             ];
+
+            if(category){
+                var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
+                    return item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+
+                categ_ids =  _.map(_.filter(self.ProductCategory,function (item) {
+                    return _.contains(category_ids, item.parent_id[0]) || item.id == category;
+                }), function(map){
+                    return map.id;
+                });
+            };
+
+            if(category && category != 9999999){
+                domain.push(['product_id.categ_id','in',categ_ids]);
+            }
+
             var AccountInvoiceLine = new model.web.Model('account.invoice.line');
                 return AccountInvoiceLine.call('getAccountInvoiceLineDental',[domain], {
                     context: new model.web.CompoundContext()
-                });
-            },
+            });
+        },
+
+
+        fetchAccountVoucher: function () {
+              var self = this;
+              var defer = $.Deferred();
+              var AccountVoucher = new model.web.Model('account.voucher');
+              AccountVoucher.query(['id', 'number','reference','partner_id','date','number','type']).filter([['state', '=', 'posted']]).all().then(function(results){
+                  defer.resolve(results);
+              });
+              return defer;
+          },
 
 
         /*====================================================================
@@ -407,6 +487,7 @@ function report_seller(reporting){
                 });
             }
         },
+
         updatePeriodSelections: function () {
             var self = this;
             var period = self.$el.find('#current-period').val();
@@ -429,6 +510,13 @@ function report_seller(reporting){
             })
         },
 
+        getResPartner: function (id) {
+            var self = this;
+            return _.filter(self.ResPartner,function (item) {
+                return item.id === id;
+            });
+        },
+
         /*====================================================================
             GET RES CURRENCY BASE
         ====================================================================*/
@@ -439,15 +527,150 @@ function report_seller(reporting){
             })
         },
 
+        getAccountVoucher: function (id) {
+            var self = this;
+            return _.filter(self.AccountVoucher,function (item) {
+                return item.reference === id;
+            });
+        },
 
-        /*====================================================================
-            GET ACCOUNT INVOICE
-        ====================================================================*/
-        getAccountInvoice: function (id) {
-          var self = this;
-          return _.filter(self.AccountInvoice,function (item) {
-            return item.user_id[0] === id;
-          });
+
+        getAccountInvoice:function(id) {
+            var self = this;
+            var content = self.AccountInvoice;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var state = self.$el.find('#current-state').val();
+            var type = self.$el.find('#current-type').val();
+            var invoice_type = self.$el.find('#current-invoice-type').val();
+            var journal = self.$el.find('#current-journal').val();
+            var user = self.$el.find('#current-user').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            content = _.flatten(_.filter(content,function (inv) {
+                return inv.id == id;
+            }));
+
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (inv) {
+                    return inv.store_id == store;
+                }));
+            }
+
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return inv.date >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return inv.date<= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return inv.date === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return inv.date === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') == currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') == lastMonth;
+                    }));
+                }
+            }
+            return content;
+        },
+
+        getPosOrderLine: function (id) {
+            var self = this;
+            var content = self.PosOrderLine;
+            var state = self.$el.find('#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();
+
+            content = _.flatten(_.filter(content,function (inv) {
+                return inv.store_id == id;
+            }));
+
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                            utc = moment(utc._d).format('YYYY-MM-DD');
+                            return moment(utc).format('YYYY-MM-DD') >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                            utc = moment(utc._d).format('YYYY-MM-DD');
+                            return moment(utc).format('YYYY-MM-DD') <= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM-DD') === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM-DD') === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM') == currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        var utc = moment.utc(inv.date,'YYYY-MM-DD h:mm:ss A');
+                        utc = moment(utc._d).format('YYYY-MM-DD');
+                        return moment(utc).format('YYYY-MM') == lastMonth;
+                    }));
+                }
+            }
+            return content;
         },
 
       /*====================================================================
@@ -460,11 +683,13 @@ function report_seller(reporting){
          });
        },
 
-
-      BuildTable: function() {
+        /*====================================================================
+            BUILD
+        ====================================================================*/
+        BuildTable: function(){
           var self = this;
-          var ranking = [];
           var data = [];
+
           var company = $('#current-company').val();
 
           if(company && company != 9999999){
@@ -474,50 +699,89 @@ function report_seller(reporting){
             var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
           };
 
-          var ResUser = self.ResUser;
-          _.each(ResUser, function (item) {
-
-              var AccountInvoice = self.getAccountInvoice(item.id);
-
-              // var AccountInvoice = self.getAccountInvoice(item.id);
-              // _.each(AccountInvoice,function(item2) {
-
-            //   var AccountInvoiceLine = self.getAccountInvoiceLine(item2.id);
-            //   _.each(AccountInvoiceLine, function(line_item){
-            //     total_cost = total_cost + (line_item.product_id.standard_price * line_item.quantity);
-            //   });
-            // });
-
-              var account_invoice_amount = 0;
-              if(AccountInvoice.length > 0){
-                  account_invoice_amount = _.reduce(_.map(AccountInvoice,function(item) {
-                          return item.amount_total;
-                      }),function(memo, num) {
-                          return memo + num
-                  },0);
-              }
-
-              if(account_invoice_amount > 0){
-                    data.push({
-                         name: item.name,
-                         total_amount : accounting.formatMoney(account_invoice_amount,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
 
-                         total_amount_no_format : account_invoice_amount,
+            var AccountInvoice = self.AccountInvoice;
+            _.each(AccountInvoice,function(item2) {
+              if (item2.residual>0){
+                    var description_product = '';
+                    var date_pay = '';
+                    var date = '';
+                    if(item2.is_anticipo == false){
+                    var total_sale = 0;
+                    var forma = 'Contado';
+                     if (item2.contado == true){
+                        forma = 'Contado'
+                     };
+                     if (item2.credito == true){
+                        forma = 'Credito'
+                     };
+                     if (!item2.date_pay){
+                        date_pay = ''
+                     };
+                     if (item2.date_pay){
+                        date_pay = item2.date_pay
+                     };
+                     var voucher = self.getAccountVoucher(item2.number).shift();
+
+                     if (voucher != null){
+                          date = voucher.date
+                      }else{
+                            date = ''
+                      }
+
+
+                     var AccountInvoiceLine = self.getAccountInvoiceLine(item2.id);
+                     _.each(AccountInvoiceLine, function(line_item){
+                        description_product = description_product + " " + line_item.product_id.name
+                     });
+
+                          var partner= self.getResPartner(item2.partner_id[0]);
+                          var currency = self.getResCurrency(item2.company_currency[0]).shift();
+
+                            data.push({
+                              //IDS
+                              invoice_id : item2.id,
+
+                              //DATAS
+                              date_invoice: moment(item2.date_invoice).format('DD/MM/YYYY'),
+                              partner_id : item2.partner_id[0],
+                              partner_name : item2.partner_id[1],
+                              ruc: self.valorNull(item2.partner_id[2]),
+                              partner_email: self.valorNull(item2.partner_id[3]),
+                              partner_mobile: self.valorNull(item2.partner_id[4]),
+                              invoice_name : self.valorNull(item2.number),
+                              supplier_invoice_number: self.valorNull(item2.supplier_invoice_number),
+                              forma: forma,
+                              date_pay:  moment(date_pay).format('DD/MM/YYYY'),
+                              date_pago:  moment(date).format('DD/MM/YYYY'),
+                              product_name: description_product,
+                              amount_total: accounting.formatMoney(item2.amount_total_currency, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                              amount_pagado:accounting.formatMoney(item2.amount_total - item2.residual,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                              amount_residual: accounting.formatMoney((item2.residual * (CurrencyBase.rate_silent/currency.rate_silent)), '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                              date: item2.date_invoice,
+                              amount : (item2.amount_total),
+                              residual: (item2.residual),
+                              pagado: item2.amount_total - item2.residual,
+                              user_id : self.valorNull(item2.user_id[0]),
+                              user_name : item2.user_id[1],
+
+                              //TOTAL FOOTER CONFIGURATION
+                              decimal_places : CurrencyBase.decimal_places,
+                              thousands_separator: CurrencyBase.thousands_separator,
+                              decimal_separator: CurrencyBase.decimal_separator,
+
+                            });
+                         };
+                    }
 
-                         decimal_places : CurrencyBase.decimal_places,
-                         thousands_separator: CurrencyBase.thousands_separator,
-                         decimal_separator: CurrencyBase.decimal_separator,
-                    });
-               }
           });
-                self.content = data;
-                self.loadTable(data);
-                self.$el.find('.report-form').css('display','block');
-                self.$el.find('.search-form').unblock();
-                self.$el.find('.report-form').unblock();
-      },
-
 
+          self.content = data;
+          self.loadTable(data);
+          self.$el.find('.report-form').css('display','block');
+          self.$el.find('.search-form').unblock();
+          self.$el.find('.report-form').unblock();
+        },
 
         /*====================================================================
             LOAD BOOTSTRAP TABLE
@@ -550,20 +814,15 @@ function report_seller(reporting){
             var column = table.bootstrapTable('getVisibleColumns');
             var row = table.bootstrapTable('getData');
 
-            var total_amount = totalAmountFormatter(row);
-            // var total_cost = totalCostFormatter(row);
-            // var total_utility = totalUtilityFormatter(row);
-            // var total_cost_percent = totalCostPercentFormatter(row);
-            // var total_sale_percent = totalSalePercentFormatter(row);
+            var amount = totalTotalFormatter(row);
+            var pagado = totalPagadoFormatter(row);
+            var residual = totalResidualFormatter(row);
 
             row.push({
-                name: 'Totales',
-                total_amount: total_amount,
-                // total_cost: total_cost,
-                // utility: total_utility,
-                // cost_percent: total_cost_percent,
-                // sale_percent: total_sale_percent,
-
+                date_invoice: 'Totales',
+                amount_total: amount,
+                amount_pagado: pagado,
+                amount_residual:residual,
             })
 
             if (action === 'pdf') {
@@ -580,16 +839,25 @@ function report_seller(reporting){
                     CONFIGURACION DEL PDF
                 ============================================================
                 */
-                var pdf_title = 'Venta/Costo/Utilidad por vendedores';
-                var pdf_type = '';
-                var pdf_name = 'venta_costo_utilidad_por_vendedores_';
+                var pdf_title = 'Resumen Estado de Cuenta';
+                var pdf_type = 'l';
+                var pdf_name = 'resumen_estado_cuenta';
                 var pdf_columnStyles =  {
-                  name : {columnWidth: 30, halign:'left'},
-                  total_amount : {columnWidth: 25, halign:'right'},
-                  // total_cost : {columnWidth: 25, halign:'right'},
-                  // utility : {columnWidth: 25, halign:'right'},
-                  // cost_percent : {columnWidth: 20, halign:'right'},
-                  // sale_percent : {columnWidth: 20, halign:'right'},
+
+                  date_invoice: {columnWidth: 18, halign:'center'},
+                  partner_name : {columnWidth: 36, halign:'left'},
+                  partner_mobile : {columnWidth: 22, halign:'left'},
+                  partner_email: {columnWidth: 34, halign:'left'},
+                  invoice_name : {columnWidth: 25, halign:'center'},
+                  supplier_invoice_number : {columnWidth: 24, halign:'center'},
+                  forma: {columnWidth: 19, halign:'left'},
+                  date_pay: {columnWidth: 23, halign:'center'},
+                  product_name: {columnWidth: 22, halign:'left'},
+                  amount_total: {columnWidth: 20, halign:'right'},
+                  amount_pagado : {columnWidth: 20, halign:'right'},
+                  amount_residual : {columnWidth: 18, halign:'right'},
+                  date_pago: {columnWidth: 22, halign:'center'},
+                  user_name : {columnWidth: 19, halign:'center'},
 
                 };
                 /*
@@ -598,7 +866,7 @@ function report_seller(reporting){
                 ============================================================
                 */
                 var filter = self.getFilter();
-                var pdf = new model.eiru_reports.ReportPdfWidget(self);
+                var pdf = new reporting.ReportPdfWidget(self);
                 pdf.drawPDF(
                     _.flatten(getColumns),
                     row,
@@ -617,6 +885,8 @@ function report_seller(reporting){
           var store = self.$el.find('#current-store').val();
           var journal = self.$el.find('#current-journal').val();
           var period = self.$el.find('#current-period').val();
+          var state = self.$el.find('#current-state').val();
+          var invoice_type = self.$el.find('#current-invoice-type').val();
           var date = self.$el.find('#current-date').val();
           var desde = self.$el.find('#from').val();
           var hasta = self.$el.find('#to').val();
@@ -632,6 +902,12 @@ function report_seller(reporting){
               value: ResCompany[0].name,
             });
           }
+          if(state && state != 9999999){
+              filter.push({
+                  title: 'Estado',
+                  value: $('#current-state option:selected').text(),
+              });
+          }
 
           if(store && store != 9999999){
             var ResStore =  _.filter(self.ResStore,function (item) {
@@ -644,14 +920,32 @@ function report_seller(reporting){
             });
 
           }
+
           if(journal && journal != 9999999){
-            var AccountJournal = _.filter(self.AccountJournal, function(item){
-              return item.id == journal;
-            })
-            filter.push({
-                title: 'Vendedor',
-                value:  AccountJournal[0].name,
+            var AccountJournal =  _.filter(self.AccountJournal,function (item) {
+                return item.id == journal;
             });
+            filter.push({
+                 title: 'Vendedor',
+                 value: AccountJournal[0].name,
+               });
+          }
+
+          // if(partner && partner != 9999999){
+          //   var ResPartner = _.filter(self.ProductCategory, function(item){
+          //     return item.id == category;
+          //   })
+          //   filter.push({
+          //       title: 'Categoría',
+          //       value:  ProductCategory[0].name,
+          //   });
+          // }
+
+          if(invoice_type && invoice_type != 9999999){
+              filter.push({
+                  title: 'Tipo de Factura',
+                  value: $('#current-invoice-type option:selected').text(),
+              });
           }
 
           if(period && period != 9999999){
@@ -700,5 +994,6 @@ function report_seller(reporting){
           }
           return filter;
         },
+
     });
 }