|
@@ -0,0 +1,710 @@
|
|
|
+function report_expense_analytic(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportExpenseAnalyticWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportExpenseAnalytic',
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+ modules: ['product_brand'],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click .print-report' : 'clickOnAction',
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-attribute' : 'updateAttributeSelections',
|
|
|
+ 'change #current-store' : 'updateJournalSelections',
|
|
|
+ 'change #current-date' : 'ShowDateRange',
|
|
|
+ },
|
|
|
+
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ var date = new reporting.ReportDatePickerWidget(self);
|
|
|
+ date.fecthFecha();
|
|
|
+ this.fetchInitial();
|
|
|
+ },
|
|
|
+
|
|
|
+ checkModule : function(model){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.IrModuleModule,function(item){
|
|
|
+ return item.name === model;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fetchIntialSQL().then(function (IntialSQL) {
|
|
|
+ return IntialSQL;
|
|
|
+ }).then(function(IntialSQL) {
|
|
|
+ /*
|
|
|
+ =================================
|
|
|
+ RES COMPANY
|
|
|
+ =================================
|
|
|
+ */
|
|
|
+ self.ResCompany = IntialSQL.companies;
|
|
|
+ self.CompanyLogo = IntialSQL.logo;
|
|
|
+ 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');
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ =================================
|
|
|
+ RES STORE
|
|
|
+ =================================
|
|
|
+ */
|
|
|
+ self.ResStore = IntialSQL.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');
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ =================================
|
|
|
+ ACCOUNT JOURNAL
|
|
|
+ =================================
|
|
|
+ */
|
|
|
+ self.AccountJournal = IntialSQL.journals;
|
|
|
+ var journal = _.flatten(_.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.type == 'sale';
|
|
|
+ }));
|
|
|
+ if(journal.length > 1){
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
+ _.each(self.AccountJournal,function(item){
|
|
|
+ if(item.type == 'sale'){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.journal').css('display','none');
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ =================================
|
|
|
+ PRODUCT CATEGORY
|
|
|
+ =================================
|
|
|
+ */
|
|
|
+ self.ProductCategory = IntialSQL.categories;
|
|
|
+ if(self.ProductCategory.length > 1){
|
|
|
+ self.$el.find('#current-category').append('<option value="9999999">Todas las Categorias</option>');
|
|
|
+ _.each(self.ProductCategory,function(item){
|
|
|
+ self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ =================================
|
|
|
+ PRODUCT BRAND
|
|
|
+ =================================
|
|
|
+ */
|
|
|
+ self.ProductBrand = IntialSQL.brands;
|
|
|
+ if(self.ProductBrand.length > 1){
|
|
|
+ self.$el.find('#current-brand').append('<option value="9999999">Todas las Marcas</option>');
|
|
|
+ _.each(self.ProductBrand,function(item){
|
|
|
+ self.$el.find('#current-brand').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.brand').css('display','none');
|
|
|
+ }
|
|
|
+ self.ProductAttribute = IntialSQL.attributes;
|
|
|
+ if(self.ProductAttribute.length > 1){
|
|
|
+ self.$el.find('#current-attribute').append('<option value="9999999">Todos los atributos</option>');
|
|
|
+ _.each(self.ProductAttribute,function(item){
|
|
|
+ self.$el.find('#current-attribute').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.attribute').css('display','none');
|
|
|
+ }
|
|
|
+ self.ProductAttributeValue = IntialSQL.attribute_values;
|
|
|
+ if(self.ProductAttributeValue.length > 1){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(self.ProductAttributeValue,function(item){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.attribute-value').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchIrModuleModule();
|
|
|
+ }).then(function(IrModuleModule) {
|
|
|
+ self.IrModuleModule = IrModuleModule;
|
|
|
+ return self.fetchCheckType();
|
|
|
+ });
|
|
|
+ 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.fetchDataSQL().then(function(DataSQL) {
|
|
|
+ return DataSQL;
|
|
|
+ }).then(function (DataSQL) {
|
|
|
+ self.AccountInvoiceLine = DataSQL.invoice_lines;
|
|
|
+ self.PosOrderLine = DataSQL.order_lines;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchIntialSQL: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = $.get('/report-filter-data');
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchDataSQL: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = $.get('/report-expense-analytic');
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchIrModuleModule: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['name','id'];
|
|
|
+ var domain=[['state','=','installed'],['name','in',self.modules]];
|
|
|
+ var IrModuleModule = new model.web.Model('ir.module.module');
|
|
|
+ IrModuleModule.query(fields).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchCheckType: function(){
|
|
|
+ var self = this;
|
|
|
+ var modules = self.checkModule('point_of_sale');
|
|
|
+ if(modules.length == 0){
|
|
|
+ self.$el.find('.type').css('display','none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ UPDATE SELECTIONS
|
|
|
+ ====================================================================*/
|
|
|
+ updateSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var store;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ if(company != 9999999){
|
|
|
+ store = self.$el.find('#current-store').empty();
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(self.ResStore,function(item){
|
|
|
+ if(parseFloat(company) == item.company_id){
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ store = self.$el.find('#current-store').empty();
|
|
|
+ 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>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateAttributeSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var attribute_value;
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ if(attribute != 9999999){
|
|
|
+ attribute_value = self.$el.find('#current-attribute-value').empty();
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(self.ProductAttributeValue,function(item){
|
|
|
+ if(parseFloat(attribute) == item.attribute_id){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ attribute_value = self.$el.find('#current-attribute-value').empty();
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(self.ProductAttributeValue,function(item){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateJournalSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var journal;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ if(store != 9999999){
|
|
|
+ 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_id){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ 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>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getProductCategory: function (id) {
|
|
|
+ var self = this;
|
|
|
+ var category;
|
|
|
+ category = _.filter(self.ProductCategory,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ });
|
|
|
+ if(category.length > 0)
|
|
|
+ return category[0].name;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountInvoiceLine:function() {
|
|
|
+ var self = this;
|
|
|
+ var content = self.AccountInvoiceLine;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var category = self.$el.find('#current-category').val();
|
|
|
+ var brand = self.$el.find('#current-brand').val();
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ var attribute_value = self.$el.find('#current-attribute-value').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)||(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(type && type != 9999999){
|
|
|
+ if(type == 'tpv'){
|
|
|
+ content = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(category && category != 9999999){
|
|
|
+ var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return item.id == category || item.parent_id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ var category_children_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_ids, item.parent_id) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ var category_grandchildren_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_children_ids, item.parent_id) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ var categ_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_grandchildren_ids, item.parent_id) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ content = _.flatten(_.filter(content,function (inv) {
|
|
|
+ return _.contains(categ_ids, inv.categ_id);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if(brand && brand != 9999999){
|
|
|
+ content = _.filter(content,function (item) {
|
|
|
+ return item.product_brand_id == parseInt(brand);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(attribute && attribute != 9999999){
|
|
|
+ content = _.filter(content,function (item) {
|
|
|
+ return _.contains(item.attribute_ids, parseInt(attribute));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(attribute_value && attribute_value != 9999999){
|
|
|
+ content = _.filter(content,function (item) {
|
|
|
+ return _.contains(item.attribute_value_ids, parseInt(attribute_value));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
+ var display_name;
|
|
|
+ var discount_amount;
|
|
|
+ var modules = self.checkModule('product_brand');
|
|
|
+ var AccountInvoiceLine = self.getAccountInvoiceLine();
|
|
|
+ _.each(AccountInvoiceLine,function(item) {
|
|
|
+ var category = self.getProductCategory(item.categ_id);
|
|
|
+ if(item.attribute_values[0] == null){
|
|
|
+ display_name = item.product_name;
|
|
|
+ }else{
|
|
|
+ display_name = item.product_name + ' (' + _.uniq(item.attribute_values) + ')';
|
|
|
+ }
|
|
|
+ if(modules.length > 0){
|
|
|
+ if(item.product_brand_id != null){
|
|
|
+ display_name = display_name + ' ( ' + item.brand_name + ')';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ discount_amount = 0;
|
|
|
+ if(item.discount > 0){
|
|
|
+ discount_amount = ((item.quantity * item.price_unit) * item.discount)/100;
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ id : item.invoice_line_id,
|
|
|
+ number:item.number,
|
|
|
+ date:moment(item.date).format('DD/MM/YYYY'),
|
|
|
+ customer_name:self.valorNull(item.partner_name),
|
|
|
+ product_name:display_name,
|
|
|
+ product_category:category,
|
|
|
+ discount:accounting.formatNumber(item.discount,2,'.',',') + '%',
|
|
|
+ discount_amount:accounting.formatMoney(discount_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ price_unit:accounting.formatMoney(item.price_unit, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ quantity:accounting.formatNumber(item.quantity,2,'.',','),
|
|
|
+ untaxed:accounting.formatMoney(item.subtotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ tax:accounting.formatMoney(item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ total:accounting.formatMoney(item.subtotal + item.tax, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ /*
|
|
|
+ =============================
|
|
|
+ NO FORMAT
|
|
|
+ =============================
|
|
|
+ */
|
|
|
+ date_no_format:item.date,
|
|
|
+ price_unit_no_format:item.price_unit,
|
|
|
+ quantity_no_format:item.quantity,
|
|
|
+ discount_amount_no_format: discount_amount,
|
|
|
+ untaxed_no_format:item.subtotal,
|
|
|
+ tax_no_format:item.tax,
|
|
|
+ total_no_format:item.subtotal + item.tax,
|
|
|
+ /*
|
|
|
+ ==============================
|
|
|
+ FOOTER
|
|
|
+ ==============================
|
|
|
+ */
|
|
|
+ decimal_places:CurrencyBase.decimal_places,
|
|
|
+ thousands_separator:CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator:CurrencyBase.decimal_separator,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ data.sort(function (a, b) {
|
|
|
+ if (a.date_no_format > b.date_no_format) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (a.date_no_format < b.date_no_format) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+ 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();
|
|
|
+ },
|
|
|
+
|
|
|
+ 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 CurrencyBase;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ if(company && company != 9999999){
|
|
|
+ ResCompany = _.flatten(_.filter(self.CompanyLogo,function (inv) {
|
|
|
+ return inv.id == company;
|
|
|
+ }));
|
|
|
+ ResCompany = ResCompany[0];
|
|
|
+ CurrencyBase = ResCompany[0].currency_id;
|
|
|
+ }else{
|
|
|
+ ResCompany = self.ResCompany[0];
|
|
|
+ CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
+ }
|
|
|
+ var getColumns = [];
|
|
|
+ var rows = [];
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var column = table.bootstrapTable('getVisibleColumns');
|
|
|
+ var row = table.bootstrapTable('getData');
|
|
|
+
|
|
|
+ var price_unit = PriceUnitFooter(row);
|
|
|
+ var quantity = QuantityFooter(row);
|
|
|
+ var tax = TaxFooter(row);
|
|
|
+ var untaxed = UntaxedFooter(row);
|
|
|
+ var total = TotalFooter(row);
|
|
|
+
|
|
|
+ row.push({
|
|
|
+ number : 'Totales',
|
|
|
+ price_unit : price_unit,
|
|
|
+ quantity : quantity,
|
|
|
+ tax : tax,
|
|
|
+ untaxed : untaxed,
|
|
|
+ total : total,
|
|
|
+ });
|
|
|
+
|
|
|
+ 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 = 'Analisis de Compra.';
|
|
|
+ var pdf_type = 'l';
|
|
|
+ var pdf_name = 'analisis_de_compra_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ number:{columnWidth: 30, halign:'center'},
|
|
|
+ date:{columnWidth: 20, halign:'center'},
|
|
|
+ customer_name:{halign:'center'},
|
|
|
+ product_name:{columnWidth: 'auto', halign:'left'},
|
|
|
+ product_category:{columnWidth: 40, halign:'left'},
|
|
|
+ price_unit:{columnWidth: 20, halign:'right'},
|
|
|
+ quantity:{columnWidth: 20, halign:'right'},
|
|
|
+ untaxed:{columnWidth: 20, halign:'right'},
|
|
|
+ tax:{columnWidth: 20, halign:'right'},
|
|
|
+ total:{columnWidth: 20, halign:'right'},
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var filter = self.getFilter();
|
|
|
+ var pdf = new reporting.ReportSalePdfWidget(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 brand = self.$el.find('#current-brand').val();
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ var attribute_value = self.$el.find('#current-attribute-value').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 != 9999999){
|
|
|
+ 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: 'Factura',
|
|
|
+ value: AccountJournal[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(category && category != 9999999){
|
|
|
+ var categ = _.filter(self.ProductCategory,function (item) {
|
|
|
+ return item.id == category;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Categoría',
|
|
|
+ value: categ[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(brand && brand != 9999999){
|
|
|
+ var ProductBrand = _.filter(self.ProductBrand,function (item) {
|
|
|
+ return item.id == brand;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Marca',
|
|
|
+ value: ProductBrand[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(attribute && attribute != 9999999){
|
|
|
+ var attr = _.filter(self.ProductAttribute,function (item) {
|
|
|
+ return item.id == attribute;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Atributo',
|
|
|
+ value: attr[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(attribute_value && attribute_value != 9999999){
|
|
|
+ var attr_value = _.filter(self.ProductAttributeValue,function (item) {
|
|
|
+ return item.id == attribute_value;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Valor de Atributo',
|
|
|
+ value: attr_value[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 {
|
|
|
+ var fecha;
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|