|
@@ -0,0 +1,802 @@
|
|
|
|
+function report_sale_utility_vendor(reporting){
|
|
|
|
+ "use strict";
|
|
|
|
+
|
|
|
|
+ var model = openerp;
|
|
|
|
+
|
|
|
|
+ reporting.ReportSaleUtilityVendorWidget = reporting.Base.extend({
|
|
|
|
+ template: 'ReportSaleUtilityVendor',
|
|
|
|
+ rowsData :[],
|
|
|
|
+ content :[],
|
|
|
|
+
|
|
|
|
+ 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',
|
|
|
|
+ 'change #current-period': 'updatePeriodSelections',
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ init : function(parent){
|
|
|
|
+ this._super(parent);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ start: function () {
|
|
|
|
+ var table = this.$el.find('#table');
|
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
|
+ var date = new model.eiru_reports.ReportDatePickerWidget(self);
|
|
|
|
+ date.fecthFecha();
|
|
|
|
+ this.fetchInitial();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ valorNull:function(dato){
|
|
|
|
+ var valor = "";
|
|
|
|
+ if (dato){
|
|
|
|
+ valor = dato;
|
|
|
|
+ }
|
|
|
|
+ return valor;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ ShowDateRange : function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
|
+ if(date == 'range'){
|
|
|
|
+ self.$el.find('.datepicker').css('display','block');
|
|
|
|
+ }
|
|
|
|
+ if(date != 'range'){
|
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ clickAnalysisDetail: function(e, row, $element,field){
|
|
|
|
+ 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 == '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) {
|
|
|
|
+ return ResCompany;
|
|
|
|
+ }).then(function(ResCompany){
|
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
|
+ if(ResCompany.length > 1){
|
|
|
|
+ self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
|
|
|
|
+ _.each(ResCompany,function(item){
|
|
|
|
+ self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.company').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ return self.fetchResStore();
|
|
|
|
+ }).then(function(ResStore){
|
|
|
|
+ self.ResStore = ResStore;
|
|
|
|
+ if(ResStore.length > 1){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
|
+ _.each(ResStore,function(item){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.store').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ return self.fetchAccountJournal();
|
|
|
|
+ }).then(function(AccountJournal){
|
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
|
+ if(AccountJournal.length > 0){
|
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todos los vendedores</option>');
|
|
|
|
+ _.each(AccountJournal,function(item){
|
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.journal').css('display','none');
|
|
|
|
+ }
|
|
|
|
+ return self.fetchAccountPeriod();
|
|
|
|
+ }).then(function(AccountPeriod){
|
|
|
|
+ self.AccountPeriod = AccountPeriod;
|
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
|
+ _.each(AccountPeriod,function(item){
|
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ 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;
|
|
|
|
+ });
|
|
|
|
+ self.$el.find('#generate').css('display','inline');
|
|
|
|
+ return;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchGenerate: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.$el.find('.search-form').block({
|
|
|
|
+ message: null,
|
|
|
|
+ overlayCSS: {
|
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ self.$el.find('.report-form').block({
|
|
|
|
+ message: null,
|
|
|
|
+ overlayCSS: {
|
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ this.fetchAccountInvoice().then(function(AccountInvoice) {
|
|
|
|
+ return AccountInvoice;
|
|
|
|
+ }).then(function (AccountInvoice){
|
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
|
+ return self.fetchAccountInvoiceLine();
|
|
|
|
+ }).then(function (AccountInvoiceLine){
|
|
|
|
+ self.AccountInvoiceLine = AccountInvoiceLine;
|
|
|
|
+ return self.BuildTable();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ RES COMPANY
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ fetchResCompany: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var currency = new model.web.Model('res.company');
|
|
|
|
+ var field=['id','name','currency_id','logo'];
|
|
|
|
+ currency.query(field).filter().all().then(function(results){
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ RES STORE
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ fetchResStore: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var field = ['id','name','company_id'];
|
|
|
|
+ var ResStore = new model.web.Model('res.store');
|
|
|
|
+ ResStore.query(field).all().then(function(results){
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ ACCOUNT JOURNAL
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ fetchAccountJournal: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var domain = [['active','=',true],['type','=','sale']];
|
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
|
+ return AccountJournal.call('getAccountJournal',[domain], {
|
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*=====================================================================
|
|
|
|
+ ACCOUNT PERIOD
|
|
|
|
+ =====================================================================*/
|
|
|
|
+ fetchAccountPeriod: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var domain = [['special','=',false]];
|
|
|
|
+ var field =['id', 'name', 'date_start','date_stop','company_id'];
|
|
|
|
+ var AccountPeriod = new model.web.Model('account.period');
|
|
|
|
+ AccountPeriod.query(field).filter(domain).all().then(function (results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ 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
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ fetchResCurrency : function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ ACCOUNT INVOICE
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ fetchAccountInvoice: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ 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 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();
|
|
|
|
+
|
|
|
|
+ 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'],
|
|
|
|
+ ['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)]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(period && period != 9999999){
|
|
|
|
+ domain.push(['period_id','=',parseInt(period)]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date && date != 9999999){
|
|
|
|
+
|
|
|
|
+ if(desde){
|
|
|
|
+ var date = desde.split('/')
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ domain.push(['date_invoice','>=',date]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(hasta){
|
|
|
|
+ var date = hasta.split('/')
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ domain.push(['date_invoice','<=',date]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date == 'today'){
|
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
|
+ domain.push(['date_invoice','=',today]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date == 'yesterday'){
|
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
|
+ domain.push(['date_invoice','=',yesterday]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date == 'currentMonth'){
|
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
|
+ domain.push(['date_invoice','like',currentMonth]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date == 'lastMonth'){
|
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
|
+ domain.push(['date_invoice','like',lastMonth]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
|
+ return AccountInvoice.call('getAccountInvoiceDental',[domain], {
|
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ 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;
|
|
|
|
+ }));
|
|
|
|
+ var domain = [
|
|
|
|
+ ['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()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ UPDATE SELECTIONS
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ updateSelections: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
|
+ if(company != 9999999){
|
|
|
|
+ /*===================
|
|
|
|
+ STORE SELECTION
|
|
|
|
+ ===================*/
|
|
|
|
+ var store = self.$el.find('#current-store').empty();
|
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursellers</option>');
|
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ /*====================
|
|
|
|
+ PERIOD SELECTION
|
|
|
|
+ ====================*/
|
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
|
+ _.each(self.AccountPeriod,function(item){
|
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ /*===================
|
|
|
|
+ STORE SELECTION
|
|
|
|
+ ===================*/
|
|
|
|
+ var store = self.$el.find('#current-store').empty();
|
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursellers</option>');
|
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ /*====================
|
|
|
|
+ PERIOD SELECTION
|
|
|
|
+ ====================*/
|
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todas los periodos</option>');
|
|
|
|
+ _.each(self.AccountPeriod,function(item){
|
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ updateJournalSelections: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
|
+ if(store != 9999999){
|
|
|
|
+ /*=============================
|
|
|
|
+ ACCOUNT JOURNAL SELECTION
|
|
|
|
+ =============================*/
|
|
|
|
+ var journal = self.$el.find('#current-journal').empty();
|
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
|
+ _.each(self.AccountJournal,function(item){
|
|
|
|
+ if(parseFloat(store) == item.store_ids){
|
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ /*=============================
|
|
|
|
+ ACCOUNT JOURNAL SELECTION
|
|
|
|
+ =============================*/
|
|
|
|
+ var journal = self.$el.find('#current-journal').empty();
|
|
|
|
+ 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>');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ updatePeriodSelections: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
|
+ if(period != 9999999){
|
|
|
|
+ self.$el.find('#current-date').val(9999999);
|
|
|
|
+ self.$el.find('#current-date').prop('disabled','disabled');
|
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('#current-date').prop('disabled',false);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ GET RES COMPANY
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ getResCompany: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.ResCompany,function (item) {
|
|
|
|
+ return item.id == id;
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ GET RES CURRENCY BASE
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ getResCurrency: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
|
+ return item.id === id;
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ GET ACCOUNT INVOICE
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ getAccountInvoice: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.AccountInvoice,function (item) {
|
|
|
|
+ return item.journal_id[0] === id;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ GET ACCOUNT INVOICE LINE
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ getAccountInvoiceLine: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.AccountInvoiceLine, function(item){
|
|
|
|
+ return item.invoice_id === id;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ BUILD
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ BuildTable: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = [];
|
|
|
|
+ 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 AccountJournal = self.AccountJournal;
|
|
|
|
+ _.each(AccountJournal,function(item) {
|
|
|
|
+
|
|
|
|
+ var total_price = 0;
|
|
|
|
+ var total_cost = 0;
|
|
|
|
+
|
|
|
|
+ var utility = 0;
|
|
|
|
+ var porc_utility = 0;
|
|
|
|
+ var payment_type = '';
|
|
|
|
+
|
|
|
|
+ var AccountInvoice = self.getAccountInvoice(item.id);
|
|
|
|
+ _.each(AccountInvoice,function(item2) {
|
|
|
|
+ var total_sale = 0;
|
|
|
|
+
|
|
|
|
+ var AccountInvoiceLine = self.getAccountInvoiceLine(item2.id);
|
|
|
|
+ _.each(AccountInvoiceLine, function(line_item){
|
|
|
|
+
|
|
|
|
+ if(line_item.product_id.standard_price != 0){
|
|
|
|
+ total_sale = (line_item.price_unit/(1.1));
|
|
|
|
+ total_cost = line_item.product_id.standard_price * line_item.quantity;
|
|
|
|
+ total_price = total_sale * line_item.quantity;
|
|
|
|
+ utility = total_price - total_cost;
|
|
|
|
+ porc_utility = (utility/total_cost)*100;
|
|
|
|
+ }else{
|
|
|
|
+ total_sale = (line_item.price_unit/(1.1));
|
|
|
|
+ total_cost = line_item.product_id.standard_price * line_item.quantity;
|
|
|
|
+ total_price = total_sale * line_item.quantity;
|
|
|
|
+ utility = total_price - total_cost;
|
|
|
|
+ porc_utility = (0/total_cost)*100;
|
|
|
|
+ }
|
|
|
|
+ data.push({
|
|
|
|
+ //IDS
|
|
|
|
+ id: line_item.id,
|
|
|
|
+ product_id : line_item.product_id.id,
|
|
|
|
+ invoice_id : item2.id,
|
|
|
|
+
|
|
|
|
+ //DATAS
|
|
|
|
+ categ_id : line_item.product_id.categ_id,
|
|
|
|
+ date_invoice: moment(item2.date_invoice).format('YYYY-MM-DD'),
|
|
|
|
+ invoice_name : item2.number,
|
|
|
|
+ product_code : self.valorNull(line_item.product_id.default_code),
|
|
|
|
+ barcode : self.valorNull(line_item.product_id.ean13),
|
|
|
|
+ product_name : line_item.product_id.name,
|
|
|
|
+ item_cost : accounting.formatMoney(line_item.product_id.standard_price,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ item_price : accounting.formatMoney(total_sale,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ qty : line_item.quantity,
|
|
|
|
+ total_price : accounting.formatMoney(total_price,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ total_cost : accounting.formatMoney(total_cost,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ utility_porcent : accounting.formatNumber((porc_utility),2, ".", ","),
|
|
|
|
+ utility : accounting.formatMoney(utility,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ user_id : self.valorNull(item2.user_id[0]),
|
|
|
|
+ user_name : item2.user_id[1],
|
|
|
|
+
|
|
|
|
+ //VALORES SIN FORMATEAR
|
|
|
|
+ item_cost_no_format : line_item.product_id.standard_price,
|
|
|
|
+ item_price_no_format : total_sale,
|
|
|
|
+ total_price_no_format : total_price,
|
|
|
|
+ total_cost_no_format : total_cost,
|
|
|
|
+ utility_no_format : utility,
|
|
|
|
+ utility_porcent_no_format : porc_utility,
|
|
|
|
+
|
|
|
|
+ //TOTAL FOOTER CONFIGURATION
|
|
|
|
+ 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();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ LOAD BOOTSTRAP TABLE
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ loadTable:function(rowsTable){
|
|
|
|
+ var self = this;
|
|
|
|
+ self.rowsData = rowsTable;
|
|
|
|
+ var table = this.$el.find('#table');
|
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ PRINT PDF
|
|
|
|
+ ====================================================================*/
|
|
|
|
+ clickOnAction: function (e) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var ResCompany;
|
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
|
+ var company = $('#current-company').val();
|
|
|
|
+ if(company && company != 9999999){
|
|
|
|
+ ResCompany = self.getResCompany(company).shift();
|
|
|
|
+ var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
|
+ }else{
|
|
|
|
+ ResCompany = self.ResCompany[0];
|
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
|
+ }
|
|
|
|
+ var getColumns=[];
|
|
|
|
+ var rows=[];
|
|
|
|
+ var table = this.$el.find("#table");
|
|
|
|
+ var column = table.bootstrapTable('getVisibleColumns');
|
|
|
|
+ var row = table.bootstrapTable('getData');
|
|
|
|
+
|
|
|
|
+ var total_price = totalPriceFormatter(row);
|
|
|
|
+ var total_cost = totalCostFormatter(row);
|
|
|
|
+ var utility = totalUtilityFormatter(row);
|
|
|
|
+ var utility_porcent_no_format = totalUtilityPorcFormatter(row);
|
|
|
|
+
|
|
|
|
+ row.push({
|
|
|
|
+ date_invoice: 'Totales',
|
|
|
|
+ total_price: total_price,
|
|
|
|
+ total_cost: total_cost,
|
|
|
|
+ utility:utility,
|
|
|
|
+ utility_porcent:utility_porcent_no_format,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ }]);
|
|
|
|
+ });
|
|
|
|
+ /*
|
|
|
|
+ ============================================================
|
|
|
|
+ CONFIGURACION DEL PDF
|
|
|
|
+ ============================================================
|
|
|
|
+ */
|
|
|
|
+ var pdf_title = 'Utilidad por línea de ventas por Vendedores';
|
|
|
|
+ var pdf_type = 'l';
|
|
|
|
+ var pdf_name = 'utilidad_venta_vendedor';
|
|
|
|
+ var pdf_columnStyles = {
|
|
|
|
+
|
|
|
|
+ date_invoice: {columnWidth: 21, halign:'center'},
|
|
|
|
+ invoice_name : {columnWidth: 24, halign:'center'},
|
|
|
|
+ product_code : {columnWidth: 21, halign:'center'},
|
|
|
|
+ barcode : {columnWidth: 15, halign:'center'},
|
|
|
|
+ product_name : {columnWidth: 38, halign:'center'},
|
|
|
|
+ item_cost : {columnWidth: 21, halign:'right'},
|
|
|
|
+ item_price : {columnWidth: 21, halign:'right'},
|
|
|
|
+ qty : {columnWidth: 16, halign:'center'},
|
|
|
|
+ total_price : {columnWidth: 21, halign:'right'},
|
|
|
|
+ total_cost : {columnWidth: 21, halign:'right'},
|
|
|
|
+ utility : {columnWidth: 21, halign:'right'},
|
|
|
|
+ utility_porcent : {columnWidth: 16, halign:'center'},
|
|
|
|
+ user_name : {columnWidth: 23, halign:'center'},
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+ /*
|
|
|
|
+ ============================================================
|
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
|
+ ============================================================
|
|
|
|
+ */
|
|
|
|
+ var filter = self.getFilter();
|
|
|
|
+ var pdf = new reporting.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 journal = self.$el.find('#current-journal').val();
|
|
|
|
+ var category = self.$el.find('#current-category').val();
|
|
|
|
+ var period = self.$el.find('#current-period').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 = [];
|
|
|
|
+
|
|
|
|
+ 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(journal && journal != 9999999){
|
|
|
|
+ var AccountJournal = _.filter(self.AccountJournal,function (item) {
|
|
|
|
+ return item.id == journal;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Vendedor',
|
|
|
|
+ value: AccountJournal[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(category && category != 9999999){
|
|
|
|
+ var ProductCategory = _.filter(self.ProductCategory, function(item){
|
|
|
|
+ return item.id == category;
|
|
|
|
+ })
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Categoría',
|
|
|
|
+ value: ProductCategory[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(period && period != 9999999){
|
|
|
|
+
|
|
|
|
+ var AccountPeriod = _.filter(self.AccountPeriod,function (item) {
|
|
|
|
+ return item.id == period;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Periodo',
|
|
|
|
+ value: AccountPeriod[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'){
|
|
|
|
+ var fecha = moment().format('DD/MM/YYYY');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(date == 'yesterday'){
|
|
|
|
+ var fecha = moment().add(-1,'days').format('DD/MM/YYYY');
|
|
|
|
+ }
|
|
|
|
+ if(date == 'currentMonth'){
|
|
|
|
+ var fecha = moment().format('MMMM/YYYY');
|
|
|
|
+ }
|
|
|
|
+ if(date == 'lastMonth'){
|
|
|
|
+ var fecha = moment().add(-1,'months').format('MMMM/YYYY');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Fecha',
|
|
|
|
+ value: fecha,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return filter;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+}
|