|
@@ -8,7 +8,8 @@ function report_sales_invoice_analysis (reporting){
|
|
invoices: [],
|
|
invoices: [],
|
|
invoiceLines: [],
|
|
invoiceLines: [],
|
|
productProduct:[],
|
|
productProduct:[],
|
|
- Currency:[],
|
|
|
|
|
|
+ ResCurrency:[],
|
|
|
|
+ AccountVoucher:[],
|
|
rowsData :[],
|
|
rowsData :[],
|
|
content :[],
|
|
content :[],
|
|
rowOrigin:[],
|
|
rowOrigin:[],
|
|
@@ -117,10 +118,10 @@ function report_sales_invoice_analysis (reporting){
|
|
// Cansultar
|
|
// Cansultar
|
|
submitForm: function () {
|
|
submitForm: function () {
|
|
var self = this;
|
|
var self = this;
|
|
- this.fetchCurency().then(function(Currency) {
|
|
|
|
- self.Currency = Currency;
|
|
|
|
- return Currency;
|
|
|
|
- }).then(function (Currency) {
|
|
|
|
|
|
+ this.fetchResCurrency().then(function(ResCurrency) {
|
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
|
+ return ResCurrency;
|
|
|
|
+ }).then(function (ResCurrency) {
|
|
return self.fecthResStore();
|
|
return self.fecthResStore();
|
|
}).then(function(ResStore){
|
|
}).then(function(ResStore){
|
|
self.ResStore = ResStore;
|
|
self.ResStore = ResStore;
|
|
@@ -154,6 +155,9 @@ function report_sales_invoice_analysis (reporting){
|
|
return self.fecthCompanyCurrency();
|
|
return self.fecthCompanyCurrency();
|
|
}).then(function(resCompany){
|
|
}).then(function(resCompany){
|
|
self.resCompany = resCompany;
|
|
self.resCompany = resCompany;
|
|
|
|
+ return self.fetchAccountVoucher();
|
|
|
|
+ }).then(function (AccountVoucher) {
|
|
|
|
+ self.AccountVoucher = AccountVoucher;
|
|
return self.fetchResPartner();
|
|
return self.fetchResPartner();
|
|
}).then(function(ResPartner){
|
|
}).then(function(ResPartner){
|
|
self.ResPartner = ResPartner;
|
|
self.ResPartner = ResPartner;
|
|
@@ -163,7 +167,7 @@ function report_sales_invoice_analysis (reporting){
|
|
self.search();
|
|
self.search();
|
|
self.searchProduct();
|
|
self.searchProduct();
|
|
self.searchUser();
|
|
self.searchUser();
|
|
- return self.invoice_Currency();
|
|
|
|
|
|
+ return self.fectUtility();
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
|
|
@@ -242,7 +246,7 @@ function report_sales_invoice_analysis (reporting){
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
var field = ['id', 'name','store_ids'];
|
|
var field = ['id', 'name','store_ids'];
|
|
- var domain = [['active','=',true],['type','in',['sale','purchase']]];
|
|
|
|
|
|
+ var domain = [['active','=',true]];
|
|
var AccountJournal = new model.web.Model('account.journal');
|
|
var AccountJournal = new model.web.Model('account.journal');
|
|
AccountJournal.query(field).filter(domain).all().then(function(results){
|
|
AccountJournal.query(field).filter(domain).all().then(function(results){
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
@@ -253,22 +257,34 @@ function report_sales_invoice_analysis (reporting){
|
|
fecthCompanyCurrency: function(){
|
|
fecthCompanyCurrency: function(){
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
- var currency = new model.web.Model('res.company');
|
|
|
|
- var field=['id', 'currency_id'];
|
|
|
|
- var domain=[['id','=',1]];
|
|
|
|
- currency.query(field).filter(domain).all().then(function(results){
|
|
|
|
|
|
+ var field=['id','name', 'currency_id'];
|
|
|
|
+ var domain = [['id', '=', self.session.company_id]];
|
|
|
|
+ var ResCompany = new model.web.Model('res.company');
|
|
|
|
+ ResCompany.query(field).filter(domain).all().then(function(results){
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
|
|
|
|
- // Buscar Cambio de Monedas USD,PYG,ARG,BRL
|
|
|
|
- fetchCurency: function () {
|
|
|
|
|
|
+ fetchResCurrency : function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fecthCompanyCurrency: function(){
|
|
|
|
+ var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
- var currency_Rate = new model.web.Model('res.currency.rate');
|
|
|
|
- var fields = ['id', 'name', 'currency_id', 'rate', 'create_date'];
|
|
|
|
- var domain = [['currency_id', 'in', [166 , 20, 7, 3]]];
|
|
|
|
- currency_Rate.query(fields).filter(domain).all().then(function (results) {
|
|
|
|
|
|
+ var field=['id','name', 'currency_id'];
|
|
|
|
+ var domain = [['id', '=', self.session.company_id]];
|
|
|
|
+ var ResCompany = new model.web.Model('res.company');
|
|
|
|
+ ResCompany.query(field).filter(domain).all().then(function(results){
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
return defer;
|
|
return defer;
|
|
@@ -285,7 +301,7 @@ function report_sales_invoice_analysis (reporting){
|
|
filter=filter.concat(",['journal_id', 'in',["+journal_ids+"]]");
|
|
filter=filter.concat(",['journal_id', 'in',["+journal_ids+"]]");
|
|
}
|
|
}
|
|
filter=filter.concat("]");
|
|
filter=filter.concat("]");
|
|
- var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice','partner_id' ,'user_id'];
|
|
|
|
|
|
+ var field =['id', 'type', 'number', 'origin', 'state', 'journal_id', 'currency_id', 'invoice_line','date_invoice','partner_id' ,'user_id', 'reference' ,'payment_ids'];
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
var Invoice = new model.web.Model('account.invoice');
|
|
var Invoice = new model.web.Model('account.invoice');
|
|
Invoice.query(field).filter(filter).all().then(function (results) {
|
|
Invoice.query(field).filter(filter).all().then(function (results) {
|
|
@@ -307,6 +323,16 @@ function report_sales_invoice_analysis (reporting){
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ fetchAccountVoucher: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var AccountVoucher = new model.web.Model('account.voucher');
|
|
|
|
+ AccountVoucher.query(['id', 'number','reference','journal_id','type']).filter([['state', '=', 'posted']]).all().then(function(results){
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
fetchResPartner: function () {
|
|
fetchResPartner: function () {
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
@@ -385,35 +411,28 @@ function report_sales_invoice_analysis (reporting){
|
|
},
|
|
},
|
|
|
|
|
|
// Obtener Monedas de la Factura
|
|
// Obtener Monedas de la Factura
|
|
- getCurrency: function (id){
|
|
|
|
- return _.find(this.Currency,function (curr) {
|
|
|
|
- return _.contains(curr.currency_id,id);
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // Actualizar cambio de las moneda de Factura
|
|
|
|
- invoice_Currency: function(){
|
|
|
|
- for (var i = 0; i < this.invoices.length; i++) {
|
|
|
|
- var currency_new;
|
|
|
|
- var item = this.invoices[i];
|
|
|
|
- var id = item.currency_id[0];
|
|
|
|
- currency_new = this.getCurrency(id);
|
|
|
|
- if (!currency_new){
|
|
|
|
- currency_new={};
|
|
|
|
- currency_new.rate=1;
|
|
|
|
- }
|
|
|
|
- this.invoices[i].rate=(currency_new.rate);
|
|
|
|
- }
|
|
|
|
- return this.fectUtility();
|
|
|
|
|
|
+ getResCurrency: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
|
+ return item.id === id;
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
// Obtener la Detalles de la Factura
|
|
// Obtener la Detalles de la Factura
|
|
getInvoice: function (id_line){
|
|
getInvoice: function (id_line){
|
|
|
|
+ var self = this;
|
|
return _.find(this.invoices, function (inv) {
|
|
return _.find(this.invoices, function (inv) {
|
|
return _.contains(inv.invoice_line, id_line);
|
|
return _.contains(inv.invoice_line, id_line);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ getAccountVoucher: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.AccountVoucher,function (item) {
|
|
|
|
+ return item.reference === id;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
// Obtener las lineas de las Facturas
|
|
// Obtener las lineas de las Facturas
|
|
getProduct: function(pro_id){
|
|
getProduct: function(pro_id){
|
|
var self = this;
|
|
var self = this;
|
|
@@ -432,14 +451,29 @@ function report_sales_invoice_analysis (reporting){
|
|
fectUtility: function(){
|
|
fectUtility: function(){
|
|
var self = this;
|
|
var self = this;
|
|
var data=[];
|
|
var data=[];
|
|
|
|
+ var CurrencyBase = self.getResCurrency(self.resCompany[0].currency_id[0]).shift();
|
|
var item;
|
|
var item;
|
|
- var invoice;
|
|
|
|
|
|
+ var invoice=[];
|
|
|
|
+ var voucher;
|
|
var producto;
|
|
var producto;
|
|
var attribute;
|
|
var attribute;
|
|
|
|
|
|
for (var i = 0; i < this.invoiceLines.length; i++) {
|
|
for (var i = 0; i < this.invoiceLines.length; i++) {
|
|
item = this.invoiceLines[i];
|
|
item = this.invoiceLines[i];
|
|
invoice = this.getInvoice(item.id);
|
|
invoice = this.getInvoice(item.id);
|
|
|
|
+ var currency = self.getResCurrency(invoice.currency_id[0]).shift();
|
|
|
|
+ voucher = self.getAccountVoucher(invoice.number).shift();
|
|
|
|
+ var pago = '';
|
|
|
|
+ var pago_name = '';
|
|
|
|
+
|
|
|
|
+ if (voucher != undefined){
|
|
|
|
+ pago = voucher.journal_id[0];
|
|
|
|
+ pago_name=voucher.journal_id[1];
|
|
|
|
+ }else{
|
|
|
|
+ pago = '';
|
|
|
|
+ pago_name= '';
|
|
|
|
+ }
|
|
|
|
+
|
|
producto =this.getProduct(item.product_id);
|
|
producto =this.getProduct(item.product_id);
|
|
|
|
|
|
if (producto != undefined){
|
|
if (producto != undefined){
|
|
@@ -457,17 +491,17 @@ function report_sales_invoice_analysis (reporting){
|
|
ean_product : self.valorNull(producto.ean13),
|
|
ean_product : self.valorNull(producto.ean13),
|
|
name : (item.name + attribute),
|
|
name : (item.name + attribute),
|
|
quantity : accounting.formatNumber((item.quantity),0, ".", ","),
|
|
quantity : accounting.formatNumber((item.quantity),0, ".", ","),
|
|
- price_unity : accounting.formatNumber((item.price_unit / invoice.rate),0, ".", ","),
|
|
|
|
|
|
+ price_unity : accounting.formatNumber((item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent)),0, ".", ","),
|
|
standar_price : accounting.formatNumber((producto.standard_price),0, ".", ","),
|
|
standar_price : accounting.formatNumber((producto.standard_price),0, ".", ","),
|
|
- price_tot : accounting.formatNumber((item.quantity * (item.price_unit / invoice.rate)),0, ".", ","),
|
|
|
|
|
|
+ price_tot : accounting.formatNumber((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))),0, ".", ","),
|
|
standar_tot : accounting.formatNumber((item.quantity * producto.standard_price),0, ".", ","),
|
|
standar_tot : accounting.formatNumber((item.quantity * producto.standard_price),0, ".", ","),
|
|
- utility : accounting.formatNumber(((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price)),0, ".", ","),
|
|
|
|
- journal_id :(invoice.journal_id[0]),
|
|
|
|
- journal_name :(invoice.journal_id[1]),
|
|
|
|
|
|
+ utility : accounting.formatNumber(((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))) - (item.quantity * producto.standard_price)),0, ".", ","),
|
|
|
|
+ journal_id : pago,
|
|
|
|
+ journal_name : pago_name,
|
|
quantity_tot : (item.quantity),
|
|
quantity_tot : (item.quantity),
|
|
- price_tot_tot : ((item.quantity * (item.price_unit / invoice.rate))),
|
|
|
|
|
|
+ price_tot_tot : ((item.quantity * (item.price_unit *(CurrencyBase.rate_silent/currency.rate_silent)))),
|
|
standar_tot_tot : ((item.quantity * producto.standard_price)),
|
|
standar_tot_tot : ((item.quantity * producto.standard_price)),
|
|
- utility_tot : (((item.quantity * (item.price_unit / invoice.rate)) - (item.quantity * producto.standard_price))),
|
|
|
|
|
|
+ utility_tot : (((item.quantity * (item.price_unit * (CurrencyBase.rate_silent/currency.rate_silent))) - (item.quantity * producto.standard_price))),
|
|
date_create :moment(invoice.date_invoice).format("DD/MM/YYYY"),
|
|
date_create :moment(invoice.date_invoice).format("DD/MM/YYYY"),
|
|
date_invoice : (invoice.date_invoice),
|
|
date_invoice : (invoice.date_invoice),
|
|
partner_id : invoice.partner_id[0],
|
|
partner_id : invoice.partner_id[0],
|