|
@@ -9,7 +9,6 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
|
|
|
|
start: function () {
|
|
start: function () {
|
|
this.fetchJournal();
|
|
this.fetchJournal();
|
|
- // this.fetchCurency();
|
|
|
|
this.$el.find('#report_form').submit(_.bind(this.submitForm, this));
|
|
this.$el.find('#report_form').submit(_.bind(this.submitForm, this));
|
|
},
|
|
},
|
|
// Buscar Diario
|
|
// Buscar Diario
|
|
@@ -19,7 +18,7 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
Journal.query(['id', 'type', 'code', 'currency', 'name', 'company_id', 'active']).filter([['type', '=', 'sale'], ['active', '=', true]]).all().then(function (results) {
|
|
Journal.query(['id', 'type', 'code', 'currency', 'name', 'company_id', 'active']).filter([['type', '=', 'sale'], ['active', '=', true]]).all().then(function (results) {
|
|
self.journal = results;
|
|
self.journal = results;
|
|
_.each(results, function (item) {
|
|
_.each(results, function (item) {
|
|
- self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
});
|
|
});
|
|
self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
|
|
self.$el.find('#current-journal').append('<option value="9999999">TODAS LAS SUC.</option>');
|
|
});
|
|
});
|
|
@@ -74,8 +73,6 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
|
|
var porductIDS = _.flatten(_.map(invoiceLines, function (item) {
|
|
return item.product_id[0];
|
|
return item.product_id[0];
|
|
}));
|
|
}));
|
|
- // console.log(porductIDS.length);
|
|
|
|
- // console.log((_.uniq(porductIDS)).length);
|
|
|
|
|
|
|
|
var ProductProdcut = new instance.web.Model('product.product');
|
|
var ProductProdcut = new instance.web.Model('product.product');
|
|
var fields = ['id', 'default_code', 'name_template', 'factory_code', 'factory_reference', 'factory_barcode', 'standard_price'];
|
|
var fields = ['id', 'default_code', 'name_template', 'factory_code', 'factory_reference', 'factory_barcode', 'standard_price'];
|
|
@@ -90,7 +87,6 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
submitForm: function (e) {
|
|
submitForm: function (e) {
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
var formData = this.$(e.currentTarget).serializeJSON();
|
|
var formData = this.$(e.currentTarget).serializeJSON();
|
|
- // alert(formData.journal);
|
|
|
|
if (formData.journal == 0) {
|
|
if (formData.journal == 0) {
|
|
$("#dialog" ).dialog({
|
|
$("#dialog" ).dialog({
|
|
autoOpen: true,
|
|
autoOpen: true,
|
|
@@ -122,21 +118,15 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
var self = this;
|
|
var self = this;
|
|
this.fetchInvoiceV2(formData.journal).then(function (invoices) {
|
|
this.fetchInvoiceV2(formData.journal).then(function (invoices) {
|
|
self.invoices = invoices;
|
|
self.invoices = invoices;
|
|
- // console.log(this.invoices);
|
|
|
|
- // console.log(invoices.length);
|
|
|
|
return invoices;
|
|
return invoices;
|
|
}).then(function (invoices) {
|
|
}).then(function (invoices) {
|
|
return self.fetchInvoiceLine(invoices);
|
|
return self.fetchInvoiceLine(invoices);
|
|
}).then(function (invoiceLines) {
|
|
}).then(function (invoiceLines) {
|
|
self.invoiceLines = invoiceLines;
|
|
self.invoiceLines = invoiceLines;
|
|
- // console.log(invoiceLines.length);
|
|
|
|
return self.fecthProduct(invoiceLines);
|
|
return self.fecthProduct(invoiceLines);
|
|
}).then(function(productProduct){
|
|
}).then(function(productProduct){
|
|
self.productProduct = productProduct;
|
|
self.productProduct = productProduct;
|
|
- // console.log(productProduct);
|
|
|
|
- // console.log(productProduct.length);
|
|
|
|
return self.invoice_Currency();
|
|
return self.invoice_Currency();
|
|
- // return self.fectUtility();
|
|
|
|
});
|
|
});
|
|
|
|
|
|
return false;
|
|
return false;
|
|
@@ -153,7 +143,6 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
currency_new={};
|
|
currency_new={};
|
|
currency_new.rate=1;
|
|
currency_new.rate=1;
|
|
}
|
|
}
|
|
-
|
|
|
|
this.invoices[i].rate=(currency_new.rate);
|
|
this.invoices[i].rate=(currency_new.rate);
|
|
}
|
|
}
|
|
return this.fectUtility();
|
|
return this.fectUtility();
|
|
@@ -178,8 +167,7 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
producto={};
|
|
producto={};
|
|
producto.standard_price=0;
|
|
producto.standard_price=0;
|
|
}
|
|
}
|
|
- // console.log(producto);
|
|
|
|
- // console.log(data);
|
|
|
|
|
|
+
|
|
data.push({number : (invoice.number),
|
|
data.push({number : (invoice.number),
|
|
name : (item.name),
|
|
name : (item.name),
|
|
quantity : (item.quantity),
|
|
quantity : (item.quantity),
|
|
@@ -189,36 +177,21 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
standar_tot : (item.quantity * producto.standard_price.toFixed(2)),
|
|
standar_tot : (item.quantity * producto.standard_price.toFixed(2)),
|
|
utility : ((item.quantity * (item.price_unit.toFixed(2) / invoice.rate.toFixed(2))) - (item.quantity * producto.standard_price)).toFixed(2)});
|
|
utility : ((item.quantity * (item.price_unit.toFixed(2) / invoice.rate.toFixed(2))) - (item.quantity * producto.standard_price)).toFixed(2)});
|
|
|
|
|
|
- // : dato[1],
|
|
|
|
- // : dato[2],
|
|
|
|
- // : dato[3],
|
|
|
|
- // : dato[4],
|
|
|
|
- // : dato[5],
|
|
|
|
- // : dato[6],
|
|
|
|
- // : dato[7]});
|
|
|
|
- // data.push([(invoice.number),
|
|
|
|
- // (item.name),
|
|
|
|
- // (item.quantity),
|
|
|
|
- // (item.price_unit.toFixed(2) / invoice.rate.toFixed(2)),
|
|
|
|
- // (producto.standard_price.toFixed(2)),
|
|
|
|
- // (item.quantity * (item.price_unit.toFixed(2) / invoice.rate.toFixed(2))),
|
|
|
|
- // (item.quantity * producto.standard_price.toFixed(2)),
|
|
|
|
- // ((item.quantity * (item.price_unit.toFixed(2) / invoice.rate.toFixed(2))) - (item.quantity * producto.standard_price)).toFixed(2)]);
|
|
|
|
}
|
|
}
|
|
- // console.log(data);
|
|
|
|
- // console.log(data.length);
|
|
|
|
this.drawPDF(data);
|
|
this.drawPDF(data);
|
|
},
|
|
},
|
|
|
|
|
|
drawPDF: function (rows) {
|
|
drawPDF: function (rows) {
|
|
-
|
|
|
|
|
|
+ rows2=[];
|
|
|
|
+ var sucusal = this.sucDescrip = this.$el.find('#current-journal option:selected').text();
|
|
|
|
+ var totalPagesExp = "{total_pages_count_string}";
|
|
getColumns = [
|
|
getColumns = [
|
|
{title: "Factura", dataKey: "number"},
|
|
{title: "Factura", dataKey: "number"},
|
|
{title: "Producto", dataKey: "name"},
|
|
{title: "Producto", dataKey: "name"},
|
|
{title: "Cantidad", dataKey: "quantity"},
|
|
{title: "Cantidad", dataKey: "quantity"},
|
|
{title: "Precio Unitario", dataKey: "price_unity"},
|
|
{title: "Precio Unitario", dataKey: "price_unity"},
|
|
{title: "Precio Costo", dataKey: "standar_price"},
|
|
{title: "Precio Costo", dataKey: "standar_price"},
|
|
- {title: "Totla Venta", dataKey: "price_tot"},
|
|
|
|
|
|
+ {title: "Total Venta", dataKey: "price_tot"},
|
|
{title: "Total Costo", dataKey: "standar_tot"},
|
|
{title: "Total Costo", dataKey: "standar_tot"},
|
|
{title: "Utilidad", dataKey: "utility"}
|
|
{title: "Utilidad", dataKey: "utility"}
|
|
];
|
|
];
|
|
@@ -235,7 +208,7 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
});
|
|
});
|
|
|
|
|
|
rows.push({ number : " ",
|
|
rows.push({ number : " ",
|
|
- name : "TOTAL ",
|
|
|
|
|
|
+ name : "TOTAL USD ",
|
|
quantity: quantity,
|
|
quantity: quantity,
|
|
price_unity : precio_unit.toFixed(2),
|
|
price_unity : precio_unit.toFixed(2),
|
|
standar_price : precio_cost.toFixed(2),
|
|
standar_price : precio_cost.toFixed(2),
|
|
@@ -244,7 +217,7 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
utility : utility.toFixed(2)});
|
|
utility : utility.toFixed(2)});
|
|
|
|
|
|
rows.unshift({ number : " ",
|
|
rows.unshift({ number : " ",
|
|
- name : "TOTAL ",
|
|
|
|
|
|
+ name : "TOTAL USD ",
|
|
quantity: quantity,
|
|
quantity: quantity,
|
|
price_unity : precio_unit.toFixed(2),
|
|
price_unity : precio_unit.toFixed(2),
|
|
standar_price : precio_cost.toFixed(2),
|
|
standar_price : precio_cost.toFixed(2),
|
|
@@ -252,11 +225,20 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
standar_tot : tol_cost.toFixed(2),
|
|
standar_tot : tol_cost.toFixed(2),
|
|
utility : utility.toFixed(2)});
|
|
utility : utility.toFixed(2)});
|
|
|
|
|
|
- // console.log(this.formatear(123456789.5));
|
|
|
|
- pdfDoc.autoTable(getColumns, rows, {
|
|
|
|
|
|
+ _.each(rows, function (rows1) {
|
|
|
|
+ rows2.push({ number : rows1.number,
|
|
|
|
+ name : rows1.name,
|
|
|
|
+ quantity: accounting.formatNumber(rows1.quantity,0, ".", ","),
|
|
|
|
+ price_unity : accounting.formatNumber(rows1.price_unity, 2, ".", ","),
|
|
|
|
+ standar_price : accounting.formatNumber(rows1.standar_price, 2, ".", ","),
|
|
|
|
+ price_tot : accounting.formatNumber(rows1.price_tot, 2, ".", ","),
|
|
|
|
+ standar_tot : accounting.formatNumber(rows1.standar_tot, 2, ".", ","),
|
|
|
|
+ utility :accounting.formatNumber(rows1.utility, 2, ".", ",")});
|
|
|
|
+ });
|
|
|
|
|
|
- theme: 'striped', // 'striped', 'grid' or 'plain',
|
|
|
|
|
|
+ pdfDoc.autoTable(getColumns, rows2, {
|
|
|
|
|
|
|
|
+ theme: 'striped', // 'striped', 'grid' or 'plain',
|
|
// startY: pdfDoc.autoTable.previous.finalY + 15,
|
|
// startY: pdfDoc.autoTable.previous.finalY + 15,
|
|
// margin: {},
|
|
// margin: {},
|
|
// tableLineWidth: 0.75,
|
|
// tableLineWidth: 0.75,
|
|
@@ -272,26 +254,30 @@ openerp.report_invoice_utility = function (instance, local) {
|
|
standar_price : {halign:'right' },
|
|
standar_price : {halign:'right' },
|
|
price_tot : {halign:'right' },
|
|
price_tot : {halign:'right' },
|
|
standar_tot : {halign:'right' },
|
|
standar_tot : {halign:'right' },
|
|
- utility : {halign:'right' },
|
|
|
|
|
|
+ utility : {halign:'right'},
|
|
|
|
+
|
|
},
|
|
},
|
|
- // styles: {
|
|
|
|
- //
|
|
|
|
- // overflow: 'linebreak' // visible, hidden, ellipsize or linebreak
|
|
|
|
- // },
|
|
|
|
- // showHeader: 'firstPage', // 'everyPage', 'firstPage', 'never',
|
|
|
|
- // headerStyles: {
|
|
|
|
- // // // fontStyle: 'bold',
|
|
|
|
- // // // fillColor: '#000000'
|
|
|
|
- // // // columnWidth: 'relative',
|
|
|
|
- // },
|
|
|
|
|
|
+
|
|
margin: { top: 15, horizontal: 7},
|
|
margin: { top: 15, horizontal: 7},
|
|
|
|
|
|
addPageContent: function (data) {
|
|
addPageContent: function (data) {
|
|
- pdfDoc.text('Facturas de SUC.', 10, 10);
|
|
|
|
|
|
+ pdfDoc.text('Análisis de Utilidad '+ sucusal, 10, 10);
|
|
|
|
+ // FOOTER
|
|
|
|
+ var str = "Pagina " + data.pageCount;
|
|
|
|
+ // Total page number plugin only available in jspdf v1.0+
|
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
|
+ str = str + " de " + totalPagesExp;
|
|
|
|
+ }
|
|
|
|
+ pdfDoc.setFontSize(7);
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
|
+ pdfDoc.text(str, data.settings.margin.left, pdfDoc.internal.pageSize.height - 10);
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+ if (typeof pdfDoc.putTotalPages === 'function') {
|
|
|
|
+ pdfDoc.putTotalPages(totalPagesExp);
|
|
|
|
+ }
|
|
pdfDoc.save('Analisis de utilidad.pdf')
|
|
pdfDoc.save('Analisis de utilidad.pdf')
|
|
// pdfDoc.output('dataurlnewwindow');
|
|
// pdfDoc.output('dataurlnewwindow');
|
|
},
|
|
},
|