Rodney Enciso Arias 7 years ago
parent
commit
0e6e9144fc
2 changed files with 173 additions and 192 deletions
  1. 90 98
      static/src/js/reports/report_purchases.js
  2. 83 94
      static/src/js/reports/report_sales.js

+ 90 - 98
static/src/js/reports/report_purchases.js

@@ -66,7 +66,7 @@ function report_purchases (reporting){
                 return self.fect_generar(self.invoice);
             }).then(function(currency){
                 self.currency = currency;
-                return self.fect_cabecera(self.resCompany, self.invoice);
+                // return self.fect_cabecera(self.resCompany, self.newInvoice);
             });
         },
         // Buscar Diario
@@ -204,6 +204,7 @@ function report_purchases (reporting){
                 return item.id === attachment_ids;
             }).shift();
         },
+        
         // Detalle del registro
         fect_generar: function(invoices){
             var self = this;
@@ -307,18 +308,25 @@ function report_purchases (reporting){
                     download_icon : icons,
                 });
             });
-            self.newInvoice = data;
-            this.loadTable(data);  
+        self.newInvoice = data;
+        this.loadTable(data);  
         },
+
         // Informacion para el txt.
         fect_cabecera: function(resCompanys, invoices){
             var self = this;
+            
             // Cabecera
             var datos = [];
-            var periodo =(this.$el.find('#from').val());
             var company_ruc;
             var agent_ruc;
             var version = 2;
+            var total = 0;
+            var cantidad = 0;
+            var valor = 0;
+            var periodo;
+            var period =this.$el.find('#current-period').val();
+
             _.each(resCompanys, function(resCompany){
                 company_ruc = resCompany.company_ruc.split("-");
                 agent_ruc = resCompany.agent_ruc.split("-");
@@ -326,7 +334,8 @@ function report_purchases (reporting){
                 datos.push(1);
                 datos.push('\t');
                 // Periodo
-                datos.push(moment(periodo).format("YYYYMM"));
+                datos.push(201708);
+                // moment(periodo).format("YYYYMM")
                 datos.push('\t');
                 // Tipo de reporte
                 datos.push(1);
@@ -368,105 +377,74 @@ function report_purchases (reporting){
                 datos.push(version);
                 datos.push('\r\n');                
             });
+            
             // detalles
-            var supplier_ruc;
-            var ruc;
-            var cuota;
-            var cuotaII;
-            var tipo;
-            var cantidad = 0;
-            var tasa_10 = 0;
-            var tasa_5 = 0;
-            var iva_5 = 0;
-            var iva_10 = 0;
-            var IVA = 0;
-            var tax = 0;
-            var total = 0;
-            var valor = 0;
-            _.each(invoices, function(invoice){
-                supplier_ruc = self.getSupplier(invoice.partner_id[0]);
-                ruc = supplier_ruc.ruc.split("-");
-                var condicion = 1;
-                if (invoice.credito == true){
-                    condicion = 2;
-                }
-                cuota = _.flatten(self.getPaymentTerm(invoice.payment_term[0]));
-                cuotaII = (cuota.length - 2);
-                if (condicion == 1 || cuotaII < 1){
-                    cuotaII = 0;
-                }
-                if(invoice.type == 'in_invoice'){
-                    tipo = 1;
-                }else{
-                    tipo = 2;
-                }
-                IVA = accounting.formatNumber(((invoice.amount_untaxed * 10)/100),"","");
-                tax = accounting.formatNumber(invoice.amount_tax,"","");
-                if(IVA == tax){
-                    iva_10 = IVA;
-                }else{
-                    iva_5 = IVA;
+            _.each(invoices, function(newInvoice){
+                if(newInvoice.period_id == period){
+                    // tipo de registro
+                    datos.push(newInvoice.tipo_registro);
+                    datos.push('\t');
+                    // ruc del proveedor
+                    datos.push(newInvoice.ruc_proveedor);
+                    datos.push('\t'); 
+                    // dv del proveedor
+                    datos.push(newInvoice.dv);
+                    datos.push('\t');
+                    // Nombre o denominacion del proveedor
+                    datos.push(newInvoice.partner);
+                    datos.push('\t');
+                    // Numero de timbrado
+                    datos.push(newInvoice.supplier_invoice_number);
+                    datos.push('\t'); 
+                    // Tipo de documento
+                    datos.push(newInvoice.tipo_documento);
+                    datos.push('\t');
+                    // Numero de documento
+                    datos.push(newInvoice.number);
+                    datos.push('\t');
+                    // Fecha de documento
+                    datos.push(newInvoice.date);
+                    datos.push('\t');
+                    // Monto de la compra a la tasa 10%
+                    datos.push(newInvoice.tasa_10);
+                    datos.push('\t');
+                    // IVA credito 10%
+                    datos.push(newInvoice.iva_10);
+                    datos.push('\t');
+                    // Monto de la compra a la tasa 5%
+                    datos.push(newInvoice.tasa_5);
+                    datos.push('\t');
+                    // IVA credito 5%
+                    datos.push(newInvoice.iva_5);
+                    datos.push('\t');
+                    // Monto de la compra no gravada o exenta
+                    datos.push(newInvoice.amount_untaxed);
+                    datos.push('\t');
+                    // Tipo de operacion
+                    datos.push(newInvoice.tipo_operacion);
+                    datos.push('\t');
+                    // Condicion de compra
+                    datos.push(newInvoice.condicion_compra);
+                    datos.push('\t');
+                    // Cantidad de cuotas
+                    datos.push(newInvoice.cantidad_cuotas);
+                    datos.push('\r\n');
+                    // Catidad de registros
+                    cantidad += 1;
+                    valor = parseInt(newInvoice.amount_untaxed) + parseInt(newInvoice.tasa_5) + parseInt(newInvoice.tasa_10);
+                    total += valor;
+                    periodo = newInvoice.period_name.split("/");
                 }
-                // tipo de registro
-                datos.push(2);
-                datos.push('\t');
-                // ruc del proveedor
-                datos.push(ruc[0]);
-                datos.push('\t'); 
-                // dv del proveedor
-                datos.push(ruc[1]);
-                datos.push('\t');
-                // Nombre o denominacion del proveedor
-                datos.push(invoice.partner_id[1]);
-                datos.push('\t');
-                // Numero de timbrado
-                datos.push(self.valorNull(invoice.supplier_invoice_number));
-                datos.push('\t'); 
-                // Tipo de documento
-                datos.push(tipo);
-                datos.push('\t');
-                // Numero de documento
-                datos.push(invoice.number);
-                datos.push('\t');
-                // Fecha de documento
-                datos.push(moment(invoice.date_invoice).format("DD/MM/YYYY"));
-                datos.push('\t');
-                // Monto de la compra a la tasa 10%
-                datos.push(tasa_10);
-                datos.push('\t');
-                // IVA credito 10%
-                datos.push(iva_10);
-                datos.push('\t');
-                // Monto de la compra a la tasa 5%
-                datos.push(tasa_5);
-                datos.push('\t');
-                // IVA credito 5%
-                datos.push(iva_5);
-                datos.push('\t');
-                // Monto de la compra no gravada o exenta
-                datos.push(accounting.formatNumber(invoice.amount_untaxed,"",""));
-                datos.push('\t');
-                // Tipo de operacion
-                datos.push(8);
-                datos.push('\t');
-                // Condicion de compra
-                datos.push(condicion);
-                datos.push('\t');
-                // Cantidad de cuotas
-                datos.push(cuotaII);
-                datos.push('\r\n');
-
-                // Catidad de registros
-                cantidad += 1;
-                valor = invoice.amount_untaxed + tasa_5 + tasa_10;
-                total += valor;
             });
+            datos.splice(2,0);
+            datos[2] = periodo[1] + periodo[0];
             datos.splice(22,0);
             datos[22] = cantidad;
             datos.splice(24,0);
             datos[24] = accounting.formatNumber(total,"","");
             self.newCabecera = new Blob(datos, {type: 'text/plain'});
         },
+
         // Buscar
         factSearch: function(){
             var self = this;
@@ -490,9 +468,23 @@ function report_purchases (reporting){
         // Generar el txt con el nombre correspondiente
         generarTxt: function () {
             var self = this;
-            var periodo = self.newInvoice[0].period_name.split("/");
-            var fileName = "Compras " + periodo[1] + periodo[0];
-            download(self.newCabecera, fileName, "text/plain");
+            var newInvoice = self.newInvoice;
+            var period =this.$el.find('#current-period').val();
+            if (period != 9999999){
+                newInvoice=_.filter(newInvoice, function (inv){
+                    return inv.period_id == period;
+                });
+                if(newInvoice.length != 0){
+                    var periodo = newInvoice[0].period_name.split("/");
+                    var fileName = "Compras " + periodo[1] + periodo[0];
+                    self.fect_cabecera(self.resCompany, self.newInvoice);
+                    download(self.newCabecera, fileName, "text/plain");   
+                }else{
+                    alert('No hay registros para importar');
+                }
+            }else{
+                alert('Debe elegir un periodo');
+            }
         },
         // Descargar el archivo adjunto
         downloadAttachment: function (e) {

+ 83 - 94
static/src/js/reports/report_sales.js

@@ -64,7 +64,7 @@ function report_sales (reporting){
                 return self.fect_generar(self.invoice);
             }).then(function(currency){
                 self.currency = currency;
-                return self.fect_cabecera(self.resCompany, self.invoice);
+                // return self.fect_cabecera(self.resCompany, self.invoice);
             });
         },
         // Buscar Diario
@@ -317,10 +317,15 @@ function report_sales (reporting){
             var self = this;
             // Cabecera
             var datos = [];
-            var periodo =(this.$el.find('#from').val());
+            var periodo;
             var company_ruc;
             var agent_ruc;
             var version = 2;
+            var total = 0;
+            var cantidad = 0;
+            var valor = 0;
+            var periodo;
+            var period =this.$el.find('#current-period').val();
             _.each(resCompanys, function(resCompany){
                 company_ruc = resCompany.company_ruc.split("-");
                 agent_ruc = resCompany.agent_ruc.split("-");
@@ -328,7 +333,7 @@ function report_sales (reporting){
                 datos.push(1);
                 datos.push('\t');
                 // Periodo
-                datos.push(moment(periodo).format("YYYYMM"));
+                datos.push(201708);
                 datos.push('\t');
                 // Tipo de reporte
                 datos.push(1);
@@ -380,99 +385,67 @@ function report_sales (reporting){
             var iva_10 = 0;
             var IVA = 0;
             var TAX = 0;
-            var total = 0;
             var valor = 0;
             var condicion;
             var untaxed;
             var ingreso = 0;
-            _.each(invoices, function(invoice){
-                // obtener el ruc y el DV del cliente
-                customer_ruc = self.getCustomer(invoice.partner_id[0]);
-                ruc = customer_ruc.ruc.split("-");
-                // Determinar si la factura es a credito o al contado
-                condicion = 1;
-                if (invoice.credito == true){
-                    condicion = 2;
-                }
-                // Determinar la cantidad de cuotas
-                cuota = _.flatten(self.getPaymentTerm(invoice.payment_term[0])).length - 2;
-                if (condicion == 1 || cuota < 1){
-                    cuota = 0;
-                }
-                // Manejo de impuestos
-                IVA = accounting.formatNumber(((invoice.amount_untaxed * 10)/100),"","");
-                TAX = accounting.formatNumber(invoice.amount_tax,"","");
-                untaxed = 0;
-                iva_5 = 0;
-                iva_10 = 0;
-                tasa_10 = 0;
-                tasa_5 = 0;
-                // Determinar si fue aplicado algun impuesto a la factura.
-                if(invoice.amount_total == invoice.amount_untaxed){
-                    untaxed = accounting.formatNumber(invoice.amount_untaxed,"","");        
-                }else{
-                    // Si fue aplicado impuesto, determina si fue de 10% o 5%.
-                    if(IVA == TAX){
-                        iva_10 = accounting.formatNumber(invoice.amount_tax,"","");;
-                        tasa_10 = accounting.formatNumber(invoice.amount_untaxed,"","");   
-                    }else{
-                        iva_5 = accounting.formatNumber(invoice.amount_tax,"","");;
-                        tasa_5 = accounting.formatNumber(invoice.amount_untaxed,"","");
-                    }
-                }
-                total = 0;
-                total = parseInt(tasa_10) + parseInt(iva_10) + parseInt(tasa_5) + parseInt(iva_5) + parseInt(untaxed);
-                // tipo de registro
-                datos.push(2);
-                datos.push('\t');
-                // ruc del cliente
-                datos.push(ruc[0]);
-                datos.push('\t'); 
-                // dv del cliente
-                datos.push(ruc[1]);
-                datos.push('\t');
-                // Nombre o denominacion del cliente
-                datos.push(invoice.partner_id[1]);
-                datos.push('\t');
-                // tipo de documento
-                datos.push(1);
-                datos.push('\t'); 
-                // Numero de documento
-                datos.push(invoice.number);
-                datos.push('\t');
-                // Fecha de documento
-                datos.push(moment(invoice.date_invoice).format("DD/MM/YYYY"));
-                datos.push('\t');
-                // Monto de la venta a la tasa 10%
-                datos.push(tasa_10);
-                datos.push('\t');
-                // IVA debito 10%
-                datos.push(iva_10);
-                datos.push('\t');
-                // Monto de la venta a la tasa 5%
-                datos.push(tasa_5);
-                datos.push('\t');
-                // IVA debito 5%
-                datos.push(iva_5);
-                datos.push('\t');
-                // Monto de la venta no gravada o exenta
-                datos.push(untaxed);
-                datos.push('\t');
-                // Monto del ingreso
-                datos.push(total);
-                datos.push('\t');
-                // Condicion de venta
-                datos.push(condicion);
-                datos.push('\t');
-                // Cantidad de cuotas
-                datos.push(cuota);
-                datos.push('\t');
-                // Numero de timbrado
-                datos.push(invoice.number);
-                datos.push('\r\n');
-                cantidad += 1;
-                ingreso += total;    
+            _.each(invoices, function(newInvoice){
+                if(newInvoice.period_id == period){
+                    // tipo de registro
+                    datos.push(newInvoice.tipo_registro);
+                    datos.push('\t');
+                    // ruc del cliente
+                    datos.push(newInvoice.ruc_cliente);
+                    datos.push('\t'); 
+                    // dv del cliente
+                    datos.push(newInvoice.dv);
+                    datos.push('\t');
+                    // Nombre o denominacion del cliente
+                    datos.push(newInvoice.partner);
+                    datos.push('\t');
+                    // tipo de documento
+                    datos.push(newInvoice.tipo_documento);
+                    datos.push('\t'); 
+                    // Numero de documento
+                    datos.push(newInvoice.numero_documento);
+                    datos.push('\t');
+                    // Fecha de documento
+                    datos.push(newInvoice.date);
+                    datos.push('\t');
+                    // Monto de la venta a la tasa 10%
+                    datos.push(newInvoice.tasa_10);
+                    datos.push('\t');
+                    // IVA debito 10%
+                    datos.push(newInvoice.iva_10);
+                    datos.push('\t');
+                    // Monto de la venta a la tasa 5%
+                    datos.push(newInvoice.tasa_5);
+                    datos.push('\t');
+                    // IVA debito 5%
+                    datos.push(newInvoice.iva_5);
+                    datos.push('\t');
+                    // Monto de la venta no gravada o exenta
+                    datos.push(newInvoice.amount);
+                    datos.push('\t');
+                    // Monto del ingreso
+                    datos.push(newInvoice.total);
+                    datos.push('\t');
+                    // Condicion de venta
+                    datos.push(newInvoice.condicion_venta);
+                    datos.push('\t');
+                    // Cantidad de cuotas
+                    datos.push(newInvoice.cantidad_cuotas);
+                    datos.push('\t');
+                    // Numero de timbrado
+                    datos.push(newInvoice.number);
+                    datos.push('\r\n');
+                    cantidad += 1;
+                    ingreso += parseInt(newInvoice.total);
+                    periodo = newInvoice.period_name.split("/");    
+                }         
             });
+            datos.splice(2,0);
+            datos[2] = periodo[1] + periodo[0];
             datos.splice(22,0);
             datos[22] = cantidad;
             datos.splice(24,0);
@@ -500,13 +473,29 @@ function report_sales (reporting){
             var table = this.$el.find('#table');
             table.bootstrapTable('load',rowsTable);
         },
+        
         // Genera el archivo txt, con el nombre correspondiente
         generarTxt: function () {
             var self = this;
-            var periodo = self.newInvoice[0].period_name.split("/");
-            var fileName = "Ventas " + periodo[1] + periodo[0];
-            download(self.newCabecera, fileName, "text/plain");
+            var newInvoice = self.newInvoice;
+            var period =this.$el.find('#current-period').val();
+            if (period != 9999999){
+                newInvoice=_.filter(newInvoice, function (inv){
+                    return inv.period_id == period;
+                });
+                if(newInvoice.length != 0){
+                    var periodo = newInvoice[0].period_name.split("/");
+                    var fileName = "Ventas " + periodo[1] + periodo[0];
+                    self.fect_cabecera(self.resCompany, self.newInvoice);
+                    download(self.newCabecera, fileName, "text/plain");
+                }else{
+                    alert('No hay registros para importar');
+                }     
+            }else{
+                alert('Debe elegir un periodo');
+            }
         },
+
         // Descargar el archivo adjunto
         downloadAttachment: function (e) {
             var self = this;