|
@@ -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> <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);
|
|
|
-
|
|
|
},
|
|
|
});
|
|
|
-}
|
|
|
+}
|