|
@@ -0,0 +1,755 @@
|
|
|
+function report_orden_servicio_analytic(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportOrdenServicioWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportOrdenServicio',
|
|
|
+ servicios: [],
|
|
|
+ servicioLines: [],
|
|
|
+ productProduct:[],
|
|
|
+ ResCurrency:[],
|
|
|
+ insumoLines:[],
|
|
|
+ logisticaLines:[],
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+ rowOrigin:[],
|
|
|
+ fabricaLines:[],
|
|
|
+ resCompany:[],
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #X' : 'fectSearch',
|
|
|
+ 'click #A' : 'fectSearch',
|
|
|
+ 'click #B' : 'fectSearch',
|
|
|
+ 'click #C' : 'fectSearch',
|
|
|
+ 'click #D' : 'fectSearch',
|
|
|
+ 'click #Z' : 'fectSearch',
|
|
|
+ 'click #W' : 'fectSearch',
|
|
|
+ 'click #draft' : 'fectSearch',
|
|
|
+ 'click #in_progress' : 'fectSearch',
|
|
|
+ 'click #done' : 'fectSearch',
|
|
|
+ 'click #canceled' : 'fectSearch',
|
|
|
+ 'change #current-store': 'fectSearch',
|
|
|
+ 'change #current-category' : 'fectSearch',
|
|
|
+ 'change #current-attribute': 'fectSearch',
|
|
|
+ 'change #current-attribute-value': 'fectSearch',
|
|
|
+ 'change #user': 'fectSearch',
|
|
|
+ 'change #from' : 'fectSearch',
|
|
|
+ 'change #to': 'fectSearch',
|
|
|
+ 'click #volver_btn': 'volver',
|
|
|
+ 'click-row.bs.table #table' : 'ckickAnalysisDetail',
|
|
|
+ },
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable({data : self.rowsData});
|
|
|
+ this.fecthFecha();
|
|
|
+ this.submitForm();
|
|
|
+ },
|
|
|
+ ckickAnalysisDetail: function(e, row, $element, field){
|
|
|
+
|
|
|
+ // if (field == 'number'){
|
|
|
+ // this.do_action({
|
|
|
+ // name : "Factura de Cliente",
|
|
|
+ // type : 'ir.actions.act_window',
|
|
|
+ // res_model : "account.invoice",
|
|
|
+ // views : [[false,'form']],
|
|
|
+ // target : 'new',
|
|
|
+ // domain : [['type', '=', 'out_invoice'],['id','=', row.id]],
|
|
|
+ // context : {},
|
|
|
+ // flags : {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ // res_id : row.id,
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+ volver: function(){
|
|
|
+ this.$el.find('#volver').empty();
|
|
|
+ this.$el.find('#grafico').empty();
|
|
|
+ this.$el.find('.bootstrap-table').show({
|
|
|
+ effect: 'drop',
|
|
|
+ direction: 'down',
|
|
|
+ duration: 200,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // Fecha
|
|
|
+ fecthFecha: function() {
|
|
|
+ var to;
|
|
|
+ var dateFormat1 = "mm/dd/yy",
|
|
|
+ from = $( "#from" )
|
|
|
+ .datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ to.datepicker( "option", "minDate", getDate(this), "dd/mm/yyyy");
|
|
|
+ });
|
|
|
+ to = $( "#to" ).datepicker({
|
|
|
+ dateFormat: "dd/mm/yy",
|
|
|
+ defaultDate: "+7d",
|
|
|
+ changeMonth: true,
|
|
|
+ numberOfMonths: 1,
|
|
|
+ })
|
|
|
+ .on( "change", function() {
|
|
|
+ from.datepicker( "option", "maxDate", getDate(this));
|
|
|
+ });
|
|
|
+
|
|
|
+ function getDate( element ) {
|
|
|
+ var fechaSel =element.value.split('/');
|
|
|
+ var date;
|
|
|
+ try {
|
|
|
+ date = $.datepicker.parseDate( dateFormat1, (fechaSel[1]+"/"+fechaSel[0]+"/"+fechaSel[2]));
|
|
|
+ } catch( error ) {
|
|
|
+ date = null;
|
|
|
+ }
|
|
|
+ return date;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // Cansultar
|
|
|
+ submitForm: function () {
|
|
|
+ var self = this;
|
|
|
+ this.fetchResCurrency().then(function(ResCurrency) {
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return ResCurrency;
|
|
|
+ }).then(function (ResCurrency) {
|
|
|
+ return self.fetchOrdenServicio();
|
|
|
+ }).then(function (servicios){
|
|
|
+ self.servicios = servicios;
|
|
|
+ return self.fetchServicioProducto(servicios);
|
|
|
+ }).then(function (servicioLines) {
|
|
|
+ self.servicioLines = servicioLines;
|
|
|
+ return self.fetchServicioInsumo();
|
|
|
+ }).then(function (insumoLines) {
|
|
|
+ self.insumoLines = insumoLines;
|
|
|
+ return self.fetchServicioLogistica();
|
|
|
+ }).then(function (logisticaLines) {
|
|
|
+ self.logisticaLines = logisticaLines;
|
|
|
+ return self.fetchDevolucionInsumo();
|
|
|
+ }).then(function (devolucionLines) {
|
|
|
+ self.devolucionLines = devolucionLines;
|
|
|
+ return self.fetchRecepcionFabrica();
|
|
|
+ }).then(function (fabricaLines) {
|
|
|
+ self.fabricaLines = fabricaLines;
|
|
|
+ return self.fetchProductProduct();
|
|
|
+ }).then(function(ProductProduct){
|
|
|
+ self.ProductProduct = ProductProduct;
|
|
|
+ return self.fetchProductCategory();
|
|
|
+ }).then(function(ProductCategory){
|
|
|
+ self.ProductCategory= ProductCategory;
|
|
|
+ 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.complete_name + '</option>');
|
|
|
+ });
|
|
|
+ return self.fecthCompanyCurrency();
|
|
|
+ }).then(function(resCompany){
|
|
|
+ self.resCompany = resCompany;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ return self.fecthResUser();
|
|
|
+ }).then(function (ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ self.search();
|
|
|
+ self.searchProduct();
|
|
|
+ self.searchUser();
|
|
|
+ return self.fectUtility();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ search: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ResPartner;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc),
|
|
|
+ value: item.id + '-'+ item.name + ' ' + self.valorNull(item.ruc)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#partner').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#partner').val())){
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ searchProduct: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ProductProduct;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) ' ,
|
|
|
+ value: item.id + '- '+ ' [ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' ( ' + self.valorNull(item.attribute_str) + ' ) '
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#product').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ search: function(event, ui) {
|
|
|
+ if (!(self.$('#product').val())){
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fecthCompanyCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field=['id','name', 'currency_id'];
|
|
|
+ var domain = [['id', '=', self.session.company_id]];
|
|
|
+ var ResCompany = new model.web.Model('res.company');
|
|
|
+ ResCompany.query(field).filter(domain).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchOrdenServicio: function () {
|
|
|
+ var self = this;
|
|
|
+ var filter ="[]";
|
|
|
+ filter=filter.concat("]");
|
|
|
+ var field =['id', 'name', 'user_id', 'order_date', 'partner_id', 'state', 'celular_partner', 'planned_start_date', 'company_id', 'currency_id', 'product_ids', 'telefono_partner','insumos_ids','logistica_ids','devolucion_ids','recepcion_ids','invoice_ids'];
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var OrdenServicio = new model.web.Model('orden.servicio');
|
|
|
+ OrdenServicio.query(field).filter().all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchServicioProducto: function (servicios) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var linesIds = _.flatten(_.map(servicios, function (item) {
|
|
|
+ return item.product_ids;
|
|
|
+ }));
|
|
|
+
|
|
|
+ var ServicioProducto = new model.web.Model('servicio.producto');
|
|
|
+ ServicioProducto.query(['id', 'quantity', 'price_unit', 'price_subtotal', 'product_id', 'product_category_id','servicio_id']).filter([['id', 'in', linesIds]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchServicioInsumo: function (servicios) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var insumoIds = _.flatten(_.map(servicios, function (item) {
|
|
|
+ return item.insumos_ids;
|
|
|
+ }));
|
|
|
+ var ServicioInsumo = new model.web.Model('servicio.insumo');
|
|
|
+ ServicioInsumo.query(['id', 'descripcion', 'quantity', 'price_unit', 'price_subtotal', 'product_id', 'servicio_id']).filter([['id', 'in', insumoIds]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchServicioLogistica: function (servicios) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var logisticaIds = _.flatten(_.map(servicios, function (item) {
|
|
|
+ return item.logistica_ids;
|
|
|
+ }));
|
|
|
+ var ServicioLogistica = new model.web.Model('servicio.logistica');
|
|
|
+ ServicioLogistica.query(['id', 'fecha', 'descripcion', 'quantity', 'price_unit', 'price_subtotal', 'product_id', 'servicio_id']).filter([['id', 'in', logisticaIds]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchDevolucionInsumo: function (servicios) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var devolucion_ids = _.flatten(_.map(servicios, function (item) {
|
|
|
+ return item.devolucion_ids;
|
|
|
+ }));
|
|
|
+ var DevolucionInsumo = new model.web.Model('devolucion.insumo');
|
|
|
+ DevolucionInsumo.query(['id', 'descripcion', 'quantity', 'price_unit', 'price_subtotal', 'product_id', 'servicio_id']).filter([['id', 'in', devolucion_ids]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchRecepcionFabrica: function (servicios) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var recepcion_ids = _.flatten(_.map(servicios, function (item) {
|
|
|
+ return item.recepcion_ids;
|
|
|
+ }));
|
|
|
+ var fabricaLines = new model.web.Model('recepcion.fabrica');
|
|
|
+ fabricaLines.query(['id', 'fecha', 'descripcion', 'quantity', 'price_unit', 'price_subtotal', 'product_id', 'servicio_id']).filter([['id', 'in', recepcion_ids]]).all().then(function (results) {
|
|
|
+ defer.resolve(results)
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResPartner: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ ResPartner.query(['id','name','ruc']).filter([['active', '=', true],['customer', '=', true]]).all().then(function(results){
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthResUser: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var user_ids = _.map(self.servicios,function(map){
|
|
|
+ return map.user_id[0];
|
|
|
+ });
|
|
|
+ var fields = ['id', 'name'];
|
|
|
+ var domain = [['id', 'in', user_ids]];
|
|
|
+ var ResUsers = new model.web.Model('res.users');
|
|
|
+ ResUsers.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ searchUser: function () {
|
|
|
+ var self = this;
|
|
|
+ var results = self.ResUser;
|
|
|
+ results = _.map(results, function (item) {
|
|
|
+ return {
|
|
|
+ label: item.id + '-'+ item.name,
|
|
|
+ value: item.id + '-'+ item.name
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$('#user').autocomplete({
|
|
|
+ source: results,
|
|
|
+ minLength:0,
|
|
|
+ searchUser: function(event, ui) {
|
|
|
+ if (!(self.$('#user').val())){
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ close: function( event, ui ) {
|
|
|
+ self.fectSearch();
|
|
|
+ },
|
|
|
+ select: function(event, ui) {
|
|
|
+ self.fectSearch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Product Product
|
|
|
+ fetchProductProduct: function(){
|
|
|
+ var self = this;
|
|
|
+ var product_ids = _.flatten(_.map(self.servicioLines, function (item) {
|
|
|
+ return item.product_id[0];
|
|
|
+ }));
|
|
|
+ var domain = [['id','in',product_ids]];
|
|
|
+ var ProductProduct = new model.web.Model('product.product');
|
|
|
+ return ProductProduct.call('getProductProduct',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Buscar Category
|
|
|
+ fetchProductCategory : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name','parent_id','complete_name'];
|
|
|
+ var ProductCategory = new model.web.Model('product.category');
|
|
|
+ ProductCategory.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // Obtener Monedas de la Factura
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener la Detalles de la Factura
|
|
|
+ getServicio: function (id_line){
|
|
|
+ var self = this;
|
|
|
+ return _.find(this.servicios, function (inv) {
|
|
|
+ return _.contains(inv.product_ids, id_line);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // Obtener las lineas de las Facturas
|
|
|
+ getProductProduct: function(pro_id){
|
|
|
+ var self = this;
|
|
|
+ return _.find(self.ProductProduct, function(item){
|
|
|
+ return _.contains(pro_id, item.id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fectUtility: function(){
|
|
|
+ var self = this;
|
|
|
+ var data=[];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.resCompany[0].currency_id[0]).shift();
|
|
|
+ var item;
|
|
|
+ var state;
|
|
|
+ var servicio=[];
|
|
|
+ var product;
|
|
|
+
|
|
|
+ for (var i = 0; i < this.servicioLines.length; i++) {
|
|
|
+ item = this.servicioLines[i];
|
|
|
+ servicio = this.getServicio(item.id);
|
|
|
+ if(servicio.state=='draft'){
|
|
|
+ state = 'Borrador'
|
|
|
+ }
|
|
|
+ if(servicio.state=='in_progress'){
|
|
|
+ state = 'En progreso'
|
|
|
+ }
|
|
|
+ if(servicio.state=='done'){
|
|
|
+ state = 'Realizado'
|
|
|
+ }
|
|
|
+ if(servicio.state=='canceled'){
|
|
|
+ state = 'Cancelado'
|
|
|
+ }
|
|
|
+
|
|
|
+ // var currency = self.getResCurrency(servicio.currency_id[0]).shift();
|
|
|
+ // console.log(currency);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ product =this.getProductProduct(item.product_id);
|
|
|
+
|
|
|
+ if (product != undefined){
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ id : servicio.id,
|
|
|
+ name : (servicio.name),
|
|
|
+ planned_start_date : (servicio.planned_start_date),
|
|
|
+ celular_obra: (servicio.celular_obra),
|
|
|
+ product_id : item.product_id[0],
|
|
|
+ product_name : item.product_id[1],
|
|
|
+ quantity : accounting.formatNumber((item.quantity),0, ".", ","),
|
|
|
+ // price_unity : accounting.formatNumber((item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent)),0, ".", ","),
|
|
|
+ price_unity : accounting.formatNumber((item.price_unit),0, ".", ","),
|
|
|
+ // price_tot : accounting.formatNumber((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))),0, ".", ","),
|
|
|
+ price_tot : accounting.formatNumber((item.quantity * (item.price_unit)),0, ".", ","),
|
|
|
+ quantity_tot : (item.quantity),
|
|
|
+ // price_tot_tot : ((item.quantity * (item.price_unit *(CurrencyBase.rate_silent/currency.rate_silent)))),
|
|
|
+ price_tot_tot : ((item.quantity * (item.price_unit))),
|
|
|
+ order_date : moment(servicio.order_date).format("DD/MM/YYYY"),
|
|
|
+ date_invoice : (servicio.order_date),
|
|
|
+ partner_id : servicio.partner_id[0],
|
|
|
+ partner_name : servicio.partner_id[1],
|
|
|
+ category_name : product.categ_id.complete_name,
|
|
|
+ category_id : product.categ_id.id,
|
|
|
+ user_id : self.valorNull(servicio.user_id[0]),
|
|
|
+ user_name : servicio.user_id[1],
|
|
|
+ state: state,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.sort(function (a, b) {
|
|
|
+ if (a.date_invoice > b.date_invoice) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (a.date_invoice < b.date_invoice) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+ this.rowsData=data;
|
|
|
+ self.content = data;
|
|
|
+ this.loadTable(data)
|
|
|
+ },
|
|
|
+
|
|
|
+ fectSearch: function(){
|
|
|
+ var self = this;
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ var yesterday = moment().add(-1, 'days').format('YYYY-MM-DD');
|
|
|
+ var month = moment().format('YYYY-MM');
|
|
|
+ var last_month = moment().add(-1, 'months').format('YYYY-MM');
|
|
|
+ var partner = this.$el.find('#partner').val().split('-');
|
|
|
+ var user = this.$el.find('#user').val().split('-');
|
|
|
+ var product = this.$el.find('#product').val().split('-');
|
|
|
+ var categ_ids = [];
|
|
|
+ var category = self.$el.find('#current-category').val();
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
+ var desde =this.$el.find('#from').val();
|
|
|
+ var hasta =this.$el.find('#to').val();
|
|
|
+ var content = self.content;
|
|
|
+
|
|
|
+ if ($('#A').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') == today;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#B').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM-DD') == yesterday;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#C').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM') == month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#D').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return moment(inv.date_invoice).format('YYYY-MM') == last_month;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($('#Z').is(":checked")){
|
|
|
+ $('#datepicker').css('display','block');
|
|
|
+ if (desde.length > 0){
|
|
|
+ var date= desde.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date_invoice >= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (hasta.length > 0){
|
|
|
+ var date= hasta.split('/');
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.date_invoice <= (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $('#datepicker').css('display','none');
|
|
|
+ }
|
|
|
+ if ($('#draft').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.state == 'Pendiente';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#in_progress').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.state == 'En progreso';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#done').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.state == 'Realizado';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if ($('#canceled').is(":checked")){
|
|
|
+ content = _.filter(content, function (inv){
|
|
|
+ return inv.state == 'Cancelado';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (partner != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.partner_id == partner[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (product != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.product_id == product[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(category){
|
|
|
+ // Nivel 0, nivel 1
|
|
|
+ var category_ids = _.map(_.filter(self.ProductCategory,function (item) {
|
|
|
+ return item.id == category || item.parent_id[0] == category;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+
|
|
|
+ // Nivel 0, nivel 1, nivel 2
|
|
|
+ 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(category && category != 9999999){
|
|
|
+ content = _.filter(content,function (inv) {
|
|
|
+ return _.contains(categ_ids, inv.category_id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user != ""){
|
|
|
+ content = _.filter(content, function(inv){
|
|
|
+ return inv.user_id == user[0];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if(state && state != 9999999){
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ return item.state == state;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ var price_total_total = _.reduce(_.map(content,function(map){
|
|
|
+ return(map.price_tot_tot);
|
|
|
+ }),function(memo, num){
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+
|
|
|
+ content.push({
|
|
|
+ name: "Totales:",
|
|
|
+ quantity: accounting.formatNumber((quantity_tot_total),0,".",","),
|
|
|
+ price_tot: accounting.formatNumber((price_total_total),0,".",","),
|
|
|
+ });
|
|
|
+
|
|
|
+ self.loadTable(content)
|
|
|
+ },
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ getObjetPdf: function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ var rows=self.rowsData;
|
|
|
+
|
|
|
+ return rows;
|
|
|
+ },
|
|
|
+
|
|
|
+ clickOnAction: function (e) {
|
|
|
+ var self = this;
|
|
|
+ var rowsNew;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var getColumns=[];
|
|
|
+ var rows=[];
|
|
|
+ rowsNew = self.getObjetPdf();
|
|
|
+ var table = this.$el.find("#table");
|
|
|
+ var data2 = table.bootstrapTable('getVisibleColumns');
|
|
|
+ if (action === 'pdf') {
|
|
|
+ var dataNEW = _.map(data2, function (val){ return val.field});
|
|
|
+ _.each(rowsNew,function (item){
|
|
|
+ rows.push(_.pick(item, dataNEW));
|
|
|
+ });
|
|
|
+ // Obtener los nombre de la Cabezera
|
|
|
+ _.each(_.map(data2,function(val){
|
|
|
+ return val}), function(item){
|
|
|
+ getColumns.push([{
|
|
|
+ title: item.title,
|
|
|
+ dataKey: item.field
|
|
|
+ }]);
|
|
|
+ });
|
|
|
+ // Llamar al pdf
|
|
|
+ this.drawPDF(_.flatten(getColumns),rows)
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ drawPDF: function (getColumns,rows) {
|
|
|
+ var self = this;
|
|
|
+ var rowsPdf=[];
|
|
|
+ var desde =(this.$el.find('#from').val());
|
|
|
+ var hasta =(this.$el.find('#to').val());
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
|
+ var pdfDoc = new jsPDF('l');
|
|
|
+
|
|
|
+ var company = _.map(self.resCompany, function (map) {
|
|
|
+ return map.currency_id[1];
|
|
|
+ });
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, rows, {
|
|
|
+ styles: { overflow: 'linebreak', fontSize: 7, columnWidth: 'wrap'},
|
|
|
+ columnStyles: {
|
|
|
+ name : {columnWidth: 20},
|
|
|
+ order_date : {columnWidth: 20},
|
|
|
+ partner_name : {columnWidth: 25},
|
|
|
+ product_name : {columnWidth: 40},
|
|
|
+ category_name : {columnWidth: 30},
|
|
|
+ quantity : {halign:'right', columnWidth: 6},
|
|
|
+ price_unity : {halign:'right', columnWidth: 18},
|
|
|
+ price_tot : {halign:'right', columnWidth: 18},
|
|
|
+ user_name : {columnWidth: 15},
|
|
|
+ state: {columnWidth: 10},
|
|
|
+ },
|
|
|
+ margin: { top: 16, horizontal: 7},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text('Análisis de orden de servicio ', data.settings.margin.left, 10);
|
|
|
+
|
|
|
+ if(desde.length > 0 || hasta.length > 0){
|
|
|
+ var fecha='';
|
|
|
+ if(desde){
|
|
|
+ fecha=fecha.concat(' Desde '+desde);
|
|
|
+ }
|
|
|
+ if (hasta){
|
|
|
+ fecha=fecha.concat(' Hasta '+hasta);
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(fecha, data.settings.margin.left,14);
|
|
|
+ }
|
|
|
+ // FOOTER
|
|
|
+ var str = "Pagina " + data.pageCount;
|
|
|
+ // Total page number plugin only available in jspdf v1.0+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ str = str + " de " + totalPagesExp;
|
|
|
+ }
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 5);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
+ pdfDoc.putTotalPages(totalPagesExp);
|
|
|
+ }
|
|
|
+ pdfDoc.save('Análisis de orden de servicio.pdf')
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|