|
@@ -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);
|
|
|
+
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -204,6 +204,7 @@ function report_purchases (reporting){
|
|
|
return item.id === attachment_ids;
|
|
|
}).shift();
|
|
|
},
|
|
|
+
|
|
|
|
|
|
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);
|
|
|
},
|
|
|
+
|
|
|
|
|
|
fect_cabecera: function(resCompanys, invoices){
|
|
|
var self = this;
|
|
|
+
|
|
|
|
|
|
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');
|
|
|
|
|
|
- datos.push(moment(periodo).format("YYYYMM"));
|
|
|
+ datos.push(201708);
|
|
|
+
|
|
|
datos.push('\t');
|
|
|
|
|
|
datos.push(1);
|
|
@@ -368,105 +377,74 @@ function report_purchases (reporting){
|
|
|
datos.push(version);
|
|
|
datos.push('\r\n');
|
|
|
});
|
|
|
+
|
|
|
|
|
|
- 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){
|
|
|
+
|
|
|
+ datos.push(newInvoice.tipo_registro);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.ruc_proveedor);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.dv);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.partner);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.supplier_invoice_number);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.tipo_documento);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.number);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.date);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.tasa_10);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.iva_10);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.tasa_5);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.iva_5);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.amount_untaxed);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.tipo_operacion);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.condicion_compra);
|
|
|
+ datos.push('\t');
|
|
|
+
|
|
|
+ datos.push(newInvoice.cantidad_cuotas);
|
|
|
+ datos.push('\r\n');
|
|
|
+
|
|
|
+ cantidad += 1;
|
|
|
+ valor = parseInt(newInvoice.amount_untaxed) + parseInt(newInvoice.tasa_5) + parseInt(newInvoice.tasa_10);
|
|
|
+ total += valor;
|
|
|
+ periodo = newInvoice.period_name.split("/");
|
|
|
}
|
|
|
-
|
|
|
- datos.push(2);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(ruc[0]);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(ruc[1]);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(invoice.partner_id[1]);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(self.valorNull(invoice.supplier_invoice_number));
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(tipo);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(invoice.number);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(moment(invoice.date_invoice).format("DD/MM/YYYY"));
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(tasa_10);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(iva_10);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(tasa_5);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(iva_5);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(accounting.formatNumber(invoice.amount_untaxed,"",""));
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(8);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(condicion);
|
|
|
- datos.push('\t');
|
|
|
-
|
|
|
- datos.push(cuotaII);
|
|
|
- datos.push('\r\n');
|
|
|
-
|
|
|
-
|
|
|
- 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'});
|
|
|
},
|
|
|
+
|
|
|
|
|
|
factSearch: function(){
|
|
|
var self = this;
|
|
@@ -490,9 +468,23 @@ function report_purchases (reporting){
|
|
|
|
|
|
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');
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
downloadAttachment: function (e) {
|