|
@@ -16,7 +16,9 @@ function report_purchases (reporting){
|
|
|
rowsData :[],
|
|
|
events:{
|
|
|
'change #current-period' : 'factSearch',
|
|
|
- 'click #txt' : 'generarTxt',
|
|
|
+ 'click #txt' : 'generarTxt',
|
|
|
+ 'click .download' : 'downloadAttachment',
|
|
|
+ 'click .preview' : 'previewAttachment'
|
|
|
},
|
|
|
|
|
|
init : function(parent){
|
|
@@ -26,7 +28,9 @@ function report_purchases (reporting){
|
|
|
start: function () {
|
|
|
var self = this;
|
|
|
var table = this.$el.find('#table');
|
|
|
- table.bootstrapTable({data : self.rowsData});
|
|
|
+ table.bootstrapTable(
|
|
|
+ {data : self.rowsData}
|
|
|
+ );
|
|
|
this.submitForm();
|
|
|
},
|
|
|
|
|
@@ -133,7 +137,7 @@ function report_purchases (reporting){
|
|
|
return id;
|
|
|
}));
|
|
|
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);
|
|
|
});
|
|
|
return defer;
|
|
@@ -205,14 +209,20 @@ function report_purchases (reporting){
|
|
|
|
|
|
getAttachment : function(attachment_ids){
|
|
|
var self = this;
|
|
|
- return _.map(_.filter(self.attachment,function(item){
|
|
|
+ return _.filter(self.attachment,function(item){
|
|
|
return item.id === attachment_ids;
|
|
|
- }),function(map){
|
|
|
- return map.datas;
|
|
|
- });
|
|
|
+ }).shift();
|
|
|
},
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
fect_generar: function(invoices){
|
|
|
var self = this;
|
|
|
var data = [];
|
|
@@ -229,6 +239,8 @@ function report_purchases (reporting){
|
|
|
var adjunto;
|
|
|
var untaxed;
|
|
|
var condicion;
|
|
|
+ var contador = 0;
|
|
|
+ var icons = 0;
|
|
|
|
|
|
_.each(invoices, function(invoice){
|
|
|
|
|
@@ -282,8 +294,15 @@ function report_purchases (reporting){
|
|
|
|
|
|
|
|
|
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({
|
|
|
+ linea: contador,
|
|
|
tipo_registro: 2,
|
|
|
ruc_proveedor: ruc[0],
|
|
|
dv: ruc[1],
|
|
@@ -302,7 +321,8 @@ function report_purchases (reporting){
|
|
|
cantidad_cuotas : cuota,
|
|
|
period_id : invoice.period_id[0],
|
|
|
period_name : invoice.period_id[1],
|
|
|
-
|
|
|
+ attachment_ids : adjunto,
|
|
|
+ download_icon : icons,
|
|
|
});
|
|
|
});
|
|
|
self.newInvoice = data;
|
|
@@ -492,30 +512,61 @@ function report_purchases (reporting){
|
|
|
table.bootstrapTable('load',rowsTable);
|
|
|
},
|
|
|
|
|
|
- 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);
|
|
|
- },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
generarTxt: function () {
|
|
|
var self = this;
|
|
|
var periodo = self.newInvoice[0].period_name.split("/");
|
|
|
var fileName = "Compras " + periodo[1] + periodo[0];
|
|
|
- self.descargarArchivo(self.newCabecera, fileName);
|
|
|
+
|
|
|
+ download(self.newCabecera, fileName, "text/plain");
|
|
|
+ },
|
|
|
+
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ previewAttachment: function () {
|
|
|
+ var self = this;
|
|
|
+ console.log('Previsualizar Adjunto');
|
|
|
},
|
|
|
});
|
|
|
}
|