Rodney Enciso Arias 7 years ago
parent
commit
531c0d955f

+ 2 - 2
static/src/js/configuration_reporting.js

@@ -12,12 +12,12 @@ function configuration_reporting (instance, widget) {
         reports: [
             {
                 title: 'Ventas',
-                description: 'Analisis Tributario de ventas',
+                description: 'Análisis Tributario de Ventas',
                 action: 'ReportSales'
             },
             {
                 title: 'Compras',
-                description: 'Analisis Tributario de compras',
+                description: 'Análisis Tributario de Compras',
                 action: 'ReportPurchases'
             }
         ],

+ 9 - 36
static/src/js/reports/report_purchases.js

@@ -69,7 +69,6 @@ function report_purchases (reporting){
                 return self.fect_cabecera(self.resCompany, self.invoice);
             });
         },
-
         // Buscar Diario
         fetchJournal: function () {
             var self = this;
@@ -80,7 +79,6 @@ function report_purchases (reporting){
             });
             return defer;
         },
-
         // Periodo
         fetchPeriod: function () {
             var defer = $.Deferred();
@@ -128,8 +126,7 @@ function report_purchases (reporting){
             });
             return defer;
         },
-
-        // archivos Adjuntos
+        // Archivos Adjuntos
         fetchAttachment: function() {
             var self = this;
             var defer = $.Deferred();
@@ -142,7 +139,6 @@ function report_purchases (reporting){
             });
             return defer;
         },
-
         // Plazos de pagos
         fetchPaymentTerm: function () {
             var self = this;
@@ -156,7 +152,6 @@ function report_purchases (reporting){
             });
             return defer;
         },
-
         // Verificar si los Valores no son nulos
         valorNull:function(dato){
             var valor ="";
@@ -165,7 +160,6 @@ function report_purchases (reporting){
             }
             return valor;
         },
-
         // Buscador
         inicializarBuscadorsup: function () {
             var self = this;
@@ -192,28 +186,24 @@ function report_purchases (reporting){
                 }
             });
         },
-
         getSupplier : function(partner_id){
             var self = this;
             return _.filter(self.supplier,function(item){
                 return item.id === partner_id;
             }).shift();
         },
-
         getPaymentTerm : function(id){
             var self = this;
             return _.filter(self.paymentTerm,function(item){
                 return item.id === id;
             }).shift();
         },
-
         getAttachment : function(attachment_ids){
             var self = this;
             return _.filter(self.attachment,function(item){
                 return item.id === attachment_ids;
             }).shift();
         },
-
         // Detalle del registro
         fect_generar: function(invoices){
             var self = this;
@@ -235,43 +225,35 @@ function report_purchases (reporting){
             var icons = 0;
             var imagen;
             var img;
-
             _.each(invoices, function(invoice){
                 // Obtener el ruc y el DV del proveedor
                 supplier_ruc = self.getSupplier(invoice.partner_id[0]);
                 ruc = supplier_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;
-
                 // Validar. Si la factura es al contado, la cuota debe ser cero.
                 if (condicion == 1 || cuota < 1){
                     cuota = 0;
                 }
-                
                 // Determinar el tipo de factura.
                 if(invoice.type == 'in_invoice'){
                     tipo = 1;
                 }else{
                     tipo = 2;
                 }
-
                 // 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,"","");        
@@ -285,11 +267,10 @@ function report_purchases (reporting){
                         tasa_5 = accounting.formatNumber(invoice.amount_untaxed,"","");
                     }
                 }
-
                 // Obtener binario del archivo adjunto
                 adjunto = self.getAttachment(invoice.attachment_ids[0]);
                 imagen = _.flatten(adjunto);
-
+                // Obtener el tipo de adjunto
                 if(adjunto == undefined){
                     icons = '<a class="" href="javascript:void(0)" title="Descarga no disponible"><i class="fa fa-file fa-lg" aria-hidden="true"></i></a>&nbsp;&nbsp;&nbsp;<a class="" href="javascript:void(0)" title="Vista previa no disponible"><i class="fa fa-eye-slash fa-lg" aria-hidden="true"></i></a>';
                 }else{
@@ -297,11 +278,11 @@ function report_purchases (reporting){
                         icons = '<a class="download" href="javascript:void(0)" title="Descargar"><i class="fa fa-download fa-lg" aria-hidden="true"></i></a>&nbsp;&nbsp;&nbsp;<a class="preview" title="Vista previa"><i class="fa fa-eye fa-lg" aria-hidden="true"></i></a>';    
                     }else{
                         icons = '<a class="download" href="javascript:void(0)" title="Descargar"><i class="fa fa-download fa-lg" aria-hidden="true"></i></a>&nbsp;&nbsp;&nbsp;<a class="" href="javascript:void(0)" title="Vista previa no disponible"><i class="fa fa-eye-slash fa-lg" aria-hidden="true"></i></a>';
-                    }
-                    
+                    }  
                 }
+                // Indice de la tabla
                 contador += 1;
-                
+                // Crear el objeto que se muestra en la tabla
                 data.push({
                     linea: contador,
                     tipo_registro: 2,
@@ -329,13 +310,10 @@ function report_purchases (reporting){
             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;
@@ -390,7 +368,6 @@ function report_purchases (reporting){
                 datos.push(version);
                 datos.push('\r\n');                
             });
-
             // detalles
             var supplier_ruc;
             var ruc;
@@ -430,7 +407,6 @@ function report_purchases (reporting){
                 }else{
                     iva_5 = IVA;
                 }
-
                 // tipo de registro
                 datos.push(2);
                 datos.push('\t');
@@ -480,6 +456,7 @@ function report_purchases (reporting){
                 datos.push(cuotaII);
                 datos.push('\r\n');
 
+                // Catidad de registros
                 cantidad += 1;
                 valor = invoice.amount_untaxed + tasa_5 + tasa_10;
                 total += valor;
@@ -490,7 +467,6 @@ function report_purchases (reporting){
             datos[24] = accounting.formatNumber(total,"","");
             self.newCabecera = new Blob(datos, {type: 'text/plain'});
         },
-
         // Buscar
         factSearch: function(){
             var self = this;
@@ -504,7 +480,6 @@ function report_purchases (reporting){
             }
             self.loadTable(newInvoice)
         },
-
         // cargara la tabla
         loadTable:function(rowsTable){
             var self = this;
@@ -512,14 +487,14 @@ function report_purchases (reporting){
             var table = this.$el.find('#table');
             table.bootstrapTable('load',rowsTable);
         },
-
+        // 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");
         },
-
+        // Descargar el archivo adjunto
         downloadAttachment: function (e) {
             var self = this;
             var newInvoice = self.newInvoice;
@@ -529,7 +504,7 @@ function report_purchases (reporting){
             var dato = newInvoice[orden - 1].attachment_ids;
             download("data:"+dato.file_type+";base64,"+dato.datas+"",dato.name,dato.file_type);
         },
-
+        // Vista previa del archivo 
         previewAttachment: function (e) {
             var self = this;
             var newInvoice = self.newInvoice;
@@ -538,11 +513,9 @@ function report_purchases (reporting){
             var orden = parseInt(columnas[0].textContent);
             var dato = newInvoice[orden -1].attachment_ids;
             var img = 'data:'+dato.file_type+';base64,'+dato.datas;
-
             lightbox.option({
                 'showImageNumberLabel': false
             });
-
             $(".preview").attr("data-lightbox",dato.name);
             $(".preview").attr("href",img);
         },

+ 10 - 67
static/src/js/reports/report_sales.js

@@ -20,7 +20,7 @@ function report_sales (reporting){
             'click .download' : 'downloadAttachment',
             'click .preview' : 'previewAttachment'
         },
-        // Initil
+        // Init
         init : function(parent){
             this._super(parent);
         },
@@ -124,8 +124,6 @@ function report_sales (reporting){
             });
             return defer;
         },
-
-
         // archivos Adjuntos
         fetchAttachment: function() {
             var self = this;
@@ -139,7 +137,6 @@ function report_sales (reporting){
             });
             return defer;
         },
-
         // plazos de pago
         fetchPaymentTerm: function () {
             var self = this;
@@ -153,7 +150,6 @@ function report_sales (reporting){
             });
             return defer;
         },
-
         // Verificar si los Valores no son nulos
         valorNull:function(dato){
             var valor ="";
@@ -188,36 +184,27 @@ function report_sales (reporting){
                 }
             });
         },
-
+        // Obtener el cliente
         getCustomer : function(partner_id){
             var self = this;
             return _.filter(self.customer,function(item){
                 return item.id === partner_id;
             }).shift();
         },
-
+        // Obtener el metodo de pago 
         getPaymentTerm : function(id){
             var self = this;
             return _.filter(self.paymentTerm,function(item){
                 return item.id === id;
             }).shift();
         },
-
+        // Obtener el archivo Adjunto
         getAttachment : function(attachment_ids){
             var self = this;
             return _.filter(self.attachment,function(item){
                 return item.id === attachment_ids;
             }).shift();
         },
-        // getAttachment : function(attachment_ids){
-        //     var self = this;
-        //     return _.map(_.filter(self.attachment,function(item){
-        //         return item.id === attachment_ids;
-        //     }),function(map){
-        //         return map.datas;
-        //     });
-        // },
-
         // unir los objetos
         fect_generar: function(invoices){
             var self = this;
@@ -240,35 +227,29 @@ function report_sales (reporting){
             var contador = 0;
             var icons = 0;
             var imagen;
-
             _.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;
                 // cuotaII = (cuota.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,"","");        
@@ -282,13 +263,13 @@ function report_sales (reporting){
                         tasa_5 = accounting.formatNumber(invoice.amount_untaxed,"","");
                     }
                 }
-
                 total = 0;
+                // Calcular total del ingreso
                 total = parseInt(tasa_10) + parseInt(iva_10) + parseInt(tasa_5) + parseInt(iva_5) + parseInt(untaxed);
-                
+                // Manipular el archivo adjunto
                 adjunto = self.getAttachment(invoice.attachment_ids[0]);
                 imagen = _.flatten(adjunto);
-                // img = 'data:'+imagen[1]+'+;base64,'+imagen[5]+'';
+                // Determinar el tipo de adjunto
                 if(adjunto == undefined){
                     icons = '<a class="" href="javascript:void(0)" title="Descarga no disponible"><i class="fa fa-file fa-lg" aria-hidden="true"></i></a>&nbsp;&nbsp;&nbsp;<a class="" href="javascript:void(0)" title="Vista previa no disponible"><i class="fa fa-eye-slash fa-lg" aria-hidden="true"></i></a>';
                 }else{
@@ -299,8 +280,9 @@ function report_sales (reporting){
                     }
                     
                 }
+                // Indice de columnas
                 contador += 1;
-
+                // Crear el objeto que se muestra en la tabla
                 data.push({
                     linea: contador,
                     tipo_registro: 2,
@@ -330,14 +312,10 @@ function report_sales (reporting){
             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;
@@ -389,7 +367,6 @@ function report_sales (reporting){
                 datos.push(version);
                 datos.push('\r\n');                
             });
-
             // detalles
             var customer_ruc;
             var ruc;
@@ -408,34 +385,28 @@ function report_sales (reporting){
             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,"","");        
@@ -449,10 +420,8 @@ function report_sales (reporting){
                         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');
@@ -501,7 +470,6 @@ function report_sales (reporting){
                 // Numero de timbrado
                 datos.push(invoice.number);
                 datos.push('\r\n');
-
                 cantidad += 1;
                 ingreso += total;    
             });
@@ -532,33 +500,11 @@ function report_sales (reporting){
             var table = this.$el.find('#table');
             table.bootstrapTable('load',rowsTable);
         },
-        
-        // Descarga el archivo en formato txt
-        // descargarArchivo: function(contenidoEnBlob, nombreArchivo) {
-        //     var self = this;
-        //     var reader = new FileReader();
-        //     reader.onload = function (event) {
-        //         var save = document.createElement('a');
-        //         save.href = event.target.result;
-        //         save.target = '_blank';
-        //         save.download = nombreArchivo || 'archivo.dat';
-        //         var clicEvent = new MouseEvent('click', {
-        //             'view': window,
-        //             'bubbles': true,
-        //             'cancelable': true
-        //         });
-        //         save.dispatchEvent(clicEvent);
-        //         (window.URL || window.webkitURL).revokeObjectURL(save.href);
-        //     };
-        //     reader.readAsDataURL(contenidoEnBlob);
-        // },
-
         // 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];
-            // self.descargarArchivo(self.newCabecera, fileName);
             download(self.newCabecera, fileName, "text/plain");
         },
         // Descargar el archivo adjunto
@@ -580,14 +526,11 @@ function report_sales (reporting){
             var orden = parseInt(columnas[0].textContent);
             var dato = newInvoice[orden -1].attachment_ids;
             var img = 'data:'+dato.file_type+';base64,'+dato.datas;
-
             lightbox.option({
                 'showImageNumberLabel': false
             });
-
             $(".preview").attr("data-lightbox",dato.name);
             $(".preview").attr("href",img);
-            
         },
     });
-}
+}