|
@@ -0,0 +1,760 @@
|
|
|
+function report_stock_athletic(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportStockAthleticWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportStockAthletic',
|
|
|
+ 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-attribute' : 'updateAttributeSelections',
|
|
|
+ 'click #btnPrint' : 'callprint',
|
|
|
+ },
|
|
|
+
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fetchInitial();
|
|
|
+ },
|
|
|
+
|
|
|
+ checkModel : 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ clickAnalysisDetail: function(e, row, $element,field){
|
|
|
+ if (field == 'name'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Producto",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "product.product",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id','=', row.id]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function (IrModuleModule) {
|
|
|
+ return IrModuleModule;
|
|
|
+ }).then(function(IrModuleModule) {
|
|
|
+ self.IrModuleModule = IrModuleModule;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).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.fetchStockLocation();
|
|
|
+ }).then(function(StockLocation){
|
|
|
+ self.StockLocation = StockLocation;
|
|
|
+ if(StockLocation.length > 1){
|
|
|
+ self.$el.find('#current-location').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
+ _.each(StockLocation,function(item){
|
|
|
+ self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.display_name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.location').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchProductBrand();
|
|
|
+ }).then(function(ProductBrand){
|
|
|
+ self.ProductBrand = ProductBrand;
|
|
|
+ if(ProductBrand.length > 1){
|
|
|
+ self.$el.find('#current-brand').append('<option value="9999999">Todas las marcas</option>');
|
|
|
+ _.each(ProductBrand,function(item){
|
|
|
+ self.$el.find('#current-brand').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.brand').css('display','none');
|
|
|
+ }
|
|
|
+ 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.display_name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.category').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchProductAttribute();
|
|
|
+ }).then(function(ProductAttribute){
|
|
|
+ self.ProductAttribute = ProductAttribute;
|
|
|
+ if(ProductAttribute.length > 1){
|
|
|
+ self.$el.find('#current-attribute').append('<option value="9999999">Todos los atributos</option>');
|
|
|
+ _.each(ProductAttribute,function(item){
|
|
|
+ self.$el.find('#current-attribute').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.attribute').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchProductAttributeValue();
|
|
|
+ }).then(function(ProductAttributeValue){
|
|
|
+ self.ProductAttributeValue = ProductAttributeValue;
|
|
|
+ if(ProductAttributeValue.length > 1){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(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.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'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.fetchStockQuant().then(function(StockQuant) {
|
|
|
+ return StockQuant;
|
|
|
+ }).then(function (StockQuant) {
|
|
|
+ self.StockQuant = StockQuant;
|
|
|
+ return self.fetchProductProduct();
|
|
|
+ }).then(function (ProductProduct){
|
|
|
+ self.ProductProduct = ProductProduct;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ IR MODULE
|
|
|
+ =====================================================================*/
|
|
|
+ fecthIrModuleModule: 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ STOCK LOCATION
|
|
|
+ ====================================================================*/
|
|
|
+ fetchStockLocation: function () {
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var domain = [
|
|
|
+ ['active', '=',true],
|
|
|
+ ['usage', '=','internal'],
|
|
|
+ ];
|
|
|
+ if(company && company != 9999999){
|
|
|
+ domain.push(['company_id','=',parseInt(company)]);
|
|
|
+ }
|
|
|
+ var StockLocation = new model.web.Model('stock.location');
|
|
|
+ return StockLocation.call('getStockLocation',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRODUCT BRAND
|
|
|
+ ====================================================================*/
|
|
|
+ fetchProductBrand: function () {
|
|
|
+ var self = this;
|
|
|
+ var domain = [];
|
|
|
+ var modules = self.checkModel('product_brand');
|
|
|
+ if (modules.length > 0){
|
|
|
+ var ProductBrand = new model.web.Model('product.product');
|
|
|
+ return ProductBrand.call('getProductBrand',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ var ProductBrand = [];
|
|
|
+ return ProductBrand;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRODUCT ATTRIBUTE
|
|
|
+ ====================================================================*/
|
|
|
+ fetchProductAttribute: function () {
|
|
|
+ var self = this;
|
|
|
+ var domain = [];
|
|
|
+ var ProductAttribute = new model.web.Model('product.attribute');
|
|
|
+ return ProductAttribute.call('getProductAttribute',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRODUCT ATTRIBUTE VALUE
|
|
|
+ ====================================================================*/
|
|
|
+ fetchProductAttributeValue: function () {
|
|
|
+ var self = this;
|
|
|
+ var domain = [];
|
|
|
+ var ProductAttributeValue = new model.web.Model('product.attribute.value');
|
|
|
+ return ProductAttributeValue.call('getProductAttributeValue',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES CURRENCY
|
|
|
+ ====================================================================*/
|
|
|
+ fetchResCurrency : function(){
|
|
|
+ var self = this;
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
+ return ResCurrency.call('getResCurrency',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ STOCK QUANT
|
|
|
+ ====================================================================*/
|
|
|
+ fetchStockQuant: function () {
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var location = self.$el.find('#current-location').val();
|
|
|
+ var location_ids = _.flatten(_.map(self.StockLocation, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var domain = [
|
|
|
+ ['location_id', 'in',location_ids],
|
|
|
+ ];
|
|
|
+ if(company && company != 9999999){
|
|
|
+ domain.push(['company_id','=',parseInt(company)]);
|
|
|
+ }
|
|
|
+ if(location && location != 9999999){
|
|
|
+ domain.push(['location_id','=',parseInt(location)]);
|
|
|
+ }
|
|
|
+ var StockQuant = new model.web.Model('stock.quant');
|
|
|
+ return StockQuant.call('getStockQuant',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRODUCT PRODUCT
|
|
|
+ ====================================================================*/
|
|
|
+ fetchProductProduct: function () {
|
|
|
+ var self = this;
|
|
|
+ var categ_ids = [];
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var brand = self.$el.find('#current-brand').val();
|
|
|
+ var category = self.$el.find('#current-category').val();
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
+ var domain = [
|
|
|
+ ['active','=',true],
|
|
|
+ ['type','=','product'],
|
|
|
+ ];
|
|
|
+ if(state == 'available'){
|
|
|
+ var product_ids = _.flatten(_.map(self.StockQuant, function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ domain.push(['id','in',product_ids]);
|
|
|
+ };
|
|
|
+ if(company && company != 9999999){
|
|
|
+ domain.push(['company_id','=',parseInt(company)]);
|
|
|
+ };
|
|
|
+ if(category){
|
|
|
+ var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return item.id == category || item.parent_id[0] == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ var category_children_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_ids, item.parent_id[0]) || 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[0]) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ }) ;
|
|
|
+ categ_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return _.contains(category_grandchildren_ids, item.parent_id[0]) || item.id == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ };
|
|
|
+ if(brand && brand != 9999999){
|
|
|
+ domain.push(['product_brand_id','=',parseInt(brand)]);
|
|
|
+ }
|
|
|
+ if(category && category != 9999999){
|
|
|
+ domain.push(['categ_id','in',categ_ids]);
|
|
|
+ }
|
|
|
+ var ProductProduct = new model.web.Model('product.product');
|
|
|
+ return ProductProduct.call('getProductProductStockAthletic',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ UPDATE SELECTIONS
|
|
|
+ ====================================================================*/
|
|
|
+ updateSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ if(company != 9999999){
|
|
|
+ /*======================
|
|
|
+ LOCATION SELECTION
|
|
|
+ ======================*/
|
|
|
+ var location = self.$el.find('#current-location').empty();
|
|
|
+ self.$el.find('#current-location').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
+ _.each(self.StockLocation,function(item){
|
|
|
+ if(parseInt(company) == item.company_id[0]){
|
|
|
+ self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.display_name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*=====================
|
|
|
+ LOCATION SELECTION
|
|
|
+ =====================*/
|
|
|
+ var location = self.$el.find('#current-location').empty();
|
|
|
+ self.$el.find('#current-location').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
+ _.each(self.StockLocation,function(item){
|
|
|
+ self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.display_name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateAttributeSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ if(attribute != 9999999){
|
|
|
+ /*=============================
|
|
|
+ ATTRIBUTE VALUE SELECTION
|
|
|
+ =============================*/
|
|
|
+ var 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[0]){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*=============================
|
|
|
+ ATTRIBUTE VALUE SELECTION
|
|
|
+ =============================*/
|
|
|
+ var 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>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES COMPANY
|
|
|
+ ====================================================================*/
|
|
|
+ getResCompany: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCompany,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET CURRENT LOCATION
|
|
|
+ ====================================================================*/
|
|
|
+ getCurrentLocation: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.StockLocation,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 PRODUCT PRODUCT
|
|
|
+ ====================================================================*/
|
|
|
+ getProductProduct: function () {
|
|
|
+ var self = this;
|
|
|
+ var content = self.ProductProduct;
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ var attribute_value = self.$el.find('#current-attribute-value').val();
|
|
|
+ if(attribute && attribute != 9999999 && attribute_value == 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.atribute_value_ids, parseFloat(attribute_value));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET STOCK QUANT
|
|
|
+ ====================================================================*/
|
|
|
+ getStockQuant: function(id){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.StockQuant, function(item){
|
|
|
+ return item.product_id[0] === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ BUILD
|
|
|
+ ====================================================================*/
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ console.log(self);
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ var state = $('#current-state').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 ProductProduct = self.getProductProduct();
|
|
|
+ _.each(ProductProduct, function(item){
|
|
|
+ var quantity = 0;
|
|
|
+ var StockQuant = self.getStockQuant(item.id);
|
|
|
+ if(StockQuant.length > 0){
|
|
|
+ quantity = _.reduce(_.map(StockQuant,function(item){
|
|
|
+ return item.qty;
|
|
|
+ }),function(mamo, num){
|
|
|
+ return mamo + num;
|
|
|
+ },0);
|
|
|
+ };
|
|
|
+ data.push({
|
|
|
+ /*=======================
|
|
|
+ IDS
|
|
|
+ =======================*/
|
|
|
+ id : item.id,
|
|
|
+ /*=======================
|
|
|
+ INFO
|
|
|
+ =======================*/
|
|
|
+ default_code: item.default_code,
|
|
|
+ factory_reference: item.factory_reference,
|
|
|
+ name : item.display_name,
|
|
|
+ ean13 : self.valorNull(item.ean13),
|
|
|
+ category : item.categ_id.complete_name,
|
|
|
+ standard_price_total : accounting.formatMoney(item.standard_price, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ lst_price_total : accounting.formatMoney(item.lst_price, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ quantity : accounting.formatNumber(quantity,2,'.',','),
|
|
|
+ valuation_cost_total : accounting.formatMoney((item.standard_price * quantity), '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ valuation_sale_total : accounting.formatMoney((item.lst_price * quantity), '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ utility_total : accounting.formatMoney(((item.lst_price * quantity)-(item.standard_price * quantity)), '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ /*=======================
|
|
|
+ VALORES SIN FORMATEAR
|
|
|
+ =======================*/
|
|
|
+ qty : quantity,
|
|
|
+ standard_price : item.standard_price,
|
|
|
+ lst_price : item.lst_price,
|
|
|
+ valuation_cost : item.standard_price * quantity,
|
|
|
+ valuation_sale : item.lst_price * quantity,
|
|
|
+ utility : (item.lst_price * quantity)-(item.standard_price * quantity),
|
|
|
+ /*==============================
|
|
|
+ TOTAL FOOTER CONFIGURATION
|
|
|
+ ==============================*/
|
|
|
+ decimal_places : CurrencyBase.decimal_places,
|
|
|
+ thousands_separator: CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator: CurrencyBase.decimal_separator,
|
|
|
+ });
|
|
|
+
|
|
|
+ if(state && state == 'available' && quantity <= 0){
|
|
|
+ data.pop();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(state && state == 'unavailable' && quantity > 0){
|
|
|
+ data.pop();
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ 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);
|
|
|
+ },
|
|
|
+
|
|
|
+ callprint: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var pdf = new reporting.ReportPdfWidget(self);
|
|
|
+ pdf.getPDFFileButton();
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRINT PDF
|
|
|
+ ====================================================================*/
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var ResCompany;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ var location = $('#current-location').val();
|
|
|
+ var pdf_type = $('#current-pdf-type').val();
|
|
|
+ var current_location = [];
|
|
|
+ if(location && location != 9999999){
|
|
|
+ current_location = self.getCurrentLocation(location);
|
|
|
+ }
|
|
|
+ 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 qty = qtyFormatter(row);
|
|
|
+ var valuation_cost_total = CostValuationFormatter(row);
|
|
|
+ var valuation_sale_total = SaleValuationFormatter(row);
|
|
|
+ var utility_total = UtilityFormatter(row);
|
|
|
+
|
|
|
+ row.push({
|
|
|
+ default_code : 'Totales',
|
|
|
+ quantity : qty,
|
|
|
+ valuation_cost_total : valuation_cost_total,
|
|
|
+ valuation_sale_total : valuation_sale_total,
|
|
|
+ utility_total : utility_total,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var data = _.map(column, function (val){ return val.field});
|
|
|
+ _.each(_.map(column,function(val){
|
|
|
+ return val}), function(item){
|
|
|
+ if(item.field != 'image'){
|
|
|
+ getColumns.push([{
|
|
|
+ title: item.title,
|
|
|
+ dataKey: item.field
|
|
|
+ }]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ CONFIGURACION DEL PDF
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var pdf_title = 'Valoracion de Inventario';
|
|
|
+ var pdf_name = 'valoracion_de_inventario_';
|
|
|
+ if(pdf_type == 1){
|
|
|
+ pdf_type = 'l';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ name :{halign:'left'},
|
|
|
+ ean13 :{columnWidth: 21, halign:'center'},
|
|
|
+ category :{halign:'left'},
|
|
|
+ standard_price_total :{columnWidth: 20, halign:'right'},
|
|
|
+ lst_price_total :{columnWidth: 20, halign:'right'},
|
|
|
+ quantity : {columnWidth: 20, halign:'right'},
|
|
|
+ valuation_cost_total : {columnWidth: 20, halign:'right'},
|
|
|
+ valuation_sale_total : {columnWidth: 20, halign:'right'},
|
|
|
+ utility_total : {columnWidth: 20, halign:'right'},
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ pdf_type = '';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ name :{halign:'left'},
|
|
|
+ ean13 :{columnWidth: 21, halign:'center'},
|
|
|
+ category :{halign:'left'},
|
|
|
+ standard_price_total :{columnWidth: 20, halign:'right'},
|
|
|
+ lst_price_total :{columnWidth: 20, halign:'right'},
|
|
|
+ quantity : {columnWidth: 20, halign:'right'},
|
|
|
+ valuation_cost_total : {columnWidth: 20, halign:'right'},
|
|
|
+ valuation_sale_total : {columnWidth: 20, halign:'right'},
|
|
|
+ utility_total : {columnWidth: 20, halign:'right'},
|
|
|
+ };
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var filter = self.getFilter();
|
|
|
+ var pdf = new model.eiru_reports.ReportPdfWidget(self);
|
|
|
+ pdf.drawPDF(
|
|
|
+ _.flatten(getColumns),
|
|
|
+ row,
|
|
|
+ ResCompany,
|
|
|
+ pdf_title,
|
|
|
+ pdf_type,
|
|
|
+ pdf_name,
|
|
|
+ pdf_columnStyles,
|
|
|
+ filter,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getFilter: function(){
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var location = self.$el.find('#current-location').val();
|
|
|
+ var brand = self.$el.find('#current-brand').val();
|
|
|
+ var category = self.$el.find('#current-category').val();
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ var attribute_value = self.$el.find('#current-attribute-value').val();
|
|
|
+ var state = self.$el.find('#current-state').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(location && location != 9999999){
|
|
|
+ var StockLocation = _.filter(self.StockLocation,function (item) {
|
|
|
+ return item.id == location;
|
|
|
+ });
|
|
|
+
|
|
|
+ filter.push({
|
|
|
+ title: 'Ubicación',
|
|
|
+ value: StockLocation[0].display_name,
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(brand && brand != 9999999){
|
|
|
+ var brand = _.filter(self.ProductBrand,function (item) {
|
|
|
+ return item.id == brand;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Marca',
|
|
|
+ value: brand[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(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(state && state != 9999999){
|
|
|
+ filter.push({
|
|
|
+ title: 'Estado',
|
|
|
+ value: $("#current-state option:selected").text(),
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|