|
@@ -17,6 +17,8 @@ function report_sales (reporting){
|
|
events:{
|
|
events:{
|
|
'change #current-period' : 'factSearch',
|
|
'change #current-period' : 'factSearch',
|
|
'click #txt' : 'generarTxt',
|
|
'click #txt' : 'generarTxt',
|
|
|
|
+ 'click .download' : 'downloadAttachment',
|
|
|
|
+ 'click .preview' : 'previewAttachment'
|
|
},
|
|
},
|
|
// Initil
|
|
// Initil
|
|
init : function(parent){
|
|
init : function(parent){
|
|
@@ -132,7 +134,7 @@ function report_sales (reporting){
|
|
return id;
|
|
return id;
|
|
}));
|
|
}));
|
|
var attachment = new instance.web.Model('ir.attachment');
|
|
var attachment = new instance.web.Model('ir.attachment');
|
|
- attachment.query(['id','res_id', 'datas', 'res_model']).filter([['res_model', '=','account.invoice']]).all().then(function (results) {
|
|
|
|
|
|
+ attachment.query(['id','res_id', 'datas', 'res_model','file_type','name']).filter([['res_model', '=','account.invoice']]).all().then(function (results) {
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
return defer;
|
|
return defer;
|
|
@@ -203,12 +205,18 @@ function report_sales (reporting){
|
|
|
|
|
|
getAttachment : function(attachment_ids){
|
|
getAttachment : function(attachment_ids){
|
|
var self = this;
|
|
var self = this;
|
|
- return _.map(_.filter(self.attachment,function(item){
|
|
|
|
|
|
+ return _.filter(self.attachment,function(item){
|
|
return item.id === attachment_ids;
|
|
return item.id === attachment_ids;
|
|
- }),function(map){
|
|
|
|
- return map.datas;
|
|
|
|
- });
|
|
|
|
|
|
+ }).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
|
|
// unir los objetos
|
|
fect_generar: function(invoices){
|
|
fect_generar: function(invoices){
|
|
@@ -227,7 +235,11 @@ function report_sales (reporting){
|
|
var condicion;
|
|
var condicion;
|
|
var IVA;
|
|
var IVA;
|
|
var TAX;
|
|
var TAX;
|
|
|
|
+ var adjunto;
|
|
var untaxed;
|
|
var untaxed;
|
|
|
|
+ var contador = 0;
|
|
|
|
+ var icons = 0;
|
|
|
|
+
|
|
_.each(invoices, function(invoice){
|
|
_.each(invoices, function(invoice){
|
|
// obtener el ruc y el DV del cliente
|
|
// obtener el ruc y el DV del cliente
|
|
customer_ruc = self.getCustomer(invoice.partner_id[0]);
|
|
customer_ruc = self.getCustomer(invoice.partner_id[0]);
|
|
@@ -273,7 +285,16 @@ function report_sales (reporting){
|
|
total = 0;
|
|
total = 0;
|
|
total = parseInt(tasa_10) + parseInt(iva_10) + parseInt(tasa_5) + parseInt(iva_5) + parseInt(untaxed);
|
|
total = parseInt(tasa_10) + parseInt(iva_10) + parseInt(tasa_5) + parseInt(iva_5) + parseInt(untaxed);
|
|
|
|
|
|
|
|
+ adjunto = self.getAttachment(invoice.attachment_ids[0]);
|
|
|
|
+ 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{
|
|
|
|
+ icons = '<a class="download" href="javascript:void(0)" title="Descargar"><i class="fa fa-download fa-lg" aria-hidden="true"></i></a> <a class="preview" href="javascript:void(0)" title="Vista previa"><i class="fa fa-eye fa-lg" aria-hidden="true"></i></a>';
|
|
|
|
+ }
|
|
|
|
+ contador += 1;
|
|
|
|
+
|
|
data.push({
|
|
data.push({
|
|
|
|
+ linea: contador,
|
|
tipo_registro: 2,
|
|
tipo_registro: 2,
|
|
ruc_cliente: ruc[0],
|
|
ruc_cliente: ruc[0],
|
|
dv: ruc[1],
|
|
dv: ruc[1],
|
|
@@ -293,6 +314,8 @@ function report_sales (reporting){
|
|
// informacion del periodo
|
|
// informacion del periodo
|
|
period_id : invoice.period_id[0],
|
|
period_id : invoice.period_id[0],
|
|
period_name : invoice.period_id[1],
|
|
period_name : invoice.period_id[1],
|
|
|
|
+ attachment_ids : adjunto,
|
|
|
|
+ download_icon : icons,
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
});
|
|
@@ -503,31 +526,62 @@ function report_sales (reporting){
|
|
},
|
|
},
|
|
|
|
|
|
// Descarga el archivo en formato txt
|
|
// 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);
|
|
|
|
- },
|
|
|
|
|
|
+ // 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
|
|
// Genera el archivo txt, con el nombre correspondiente
|
|
generarTxt: function () {
|
|
generarTxt: function () {
|
|
var self = this;
|
|
var self = this;
|
|
var periodo = self.newInvoice[0].period_name.split("/");
|
|
var periodo = self.newInvoice[0].period_name.split("/");
|
|
var fileName = "Ventas " + periodo[1] + periodo[0];
|
|
var fileName = "Ventas " + periodo[1] + periodo[0];
|
|
- self.descargarArchivo(self.newCabecera, fileName);
|
|
|
|
|
|
+ // self.descargarArchivo(self.newCabecera, fileName);
|
|
|
|
+ download(self.newCabecera, fileName, "text/plain");
|
|
|
|
+ },
|
|
|
|
+ // Descargar el archivo adjunto
|
|
|
|
+ downloadAttachment: function (e) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var newInvoice = self.newInvoice;
|
|
|
|
+ var fila = $(e.target).closest('tr');
|
|
|
|
+ var columnas = fila.children();
|
|
|
|
+ var orden = parseInt(columnas[0].textContent);
|
|
|
|
+ var dato = newInvoice[orden - 1].attachment_ids;
|
|
|
|
+
|
|
|
|
+ if(dato.file_type == 'image/png'){
|
|
|
|
+ download("data:image/png;base64,"+ dato.datas +" ",dato.name,"image/png");
|
|
|
|
+ }
|
|
|
|
+ if(dato.file_type == 'application/pdf'){
|
|
|
|
+ download("data:application/pdf;base64,"+ dato.datas +" ",dato.name,"application/pdf");
|
|
|
|
+ }
|
|
|
|
+ if(dato.file_type == 'application/vnd.ms-excel'){
|
|
|
|
+ download("data:application/vnd.ms-excel;base64,"+ dato.datas +" ",dato.name,"application/vnd.ms-excel");
|
|
|
|
+ }
|
|
|
|
+ if(dato.file_type == 'application/msword'){
|
|
|
|
+ download("data:application/msword;base64,"+ dato.datas +" ",dato.name,"application/msword");
|
|
|
|
+ }
|
|
|
|
+ if(dato.file_type == 'image/jpeg'){
|
|
|
|
+ download("data:image/jpeg;base64,"+ dato.datas +" ",dato.name,"image/jpeg");
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // Vista previa del archivo adjunto
|
|
|
|
+ previewAttachment: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ console.log('Previsualizar Adjunto');
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}
|
|
}
|