|
@@ -2,10 +2,14 @@ openerp.eiru_quota_analysis = function (instance, local) {
|
|
local.widgetInstance = null;
|
|
local.widgetInstance = null;
|
|
local.parentInstance = null;
|
|
local.parentInstance = null;
|
|
var model = openerp;
|
|
var model = openerp;
|
|
|
|
+ var instanceWeb = openerp.web;
|
|
|
|
|
|
local.EiruQuotaAnalysisWidget = instance.Widget.extend({
|
|
local.EiruQuotaAnalysisWidget = instance.Widget.extend({
|
|
template : "eiru_quota_analysis.EiruQuotaAnalysis",
|
|
template : "eiru_quota_analysis.EiruQuotaAnalysis",
|
|
id: undefined,
|
|
id: undefined,
|
|
|
|
+ AccountInvoice: [],
|
|
|
|
+ ResCurrency: [],
|
|
|
|
+ invoiceState : [],
|
|
|
|
|
|
init: function(parent) {
|
|
init: function(parent) {
|
|
this._super(parent);
|
|
this._super(parent);
|
|
@@ -20,18 +24,10 @@ openerp.eiru_quota_analysis = function (instance, local) {
|
|
/* Click Imprimir */
|
|
/* Click Imprimir */
|
|
bottomPrint = this.$el.find('.button-quota-print');
|
|
bottomPrint = this.$el.find('.button-quota-print');
|
|
bottomPrint.click(function(){
|
|
bottomPrint.click(function(){
|
|
- console.log("Porrrra");
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- /*
|
|
|
|
- start: function() {
|
|
|
|
- var self = this;
|
|
|
|
-
|
|
|
|
- this.$el.click(function(){
|
|
|
|
- self.fectchInitial()
|
|
|
|
|
|
+ self.initialPrint();
|
|
});
|
|
});
|
|
self.buttons.click(function(e) {
|
|
self.buttons.click(function(e) {
|
|
- E (Editar)
|
|
|
|
|
|
+ // E (Editar)
|
|
if (e.target.accessKey === 'E')
|
|
if (e.target.accessKey === 'E')
|
|
self.$el.css('display','none');
|
|
self.$el.css('display','none');
|
|
// S (Guarrdar)
|
|
// S (Guarrdar)
|
|
@@ -45,14 +41,7 @@ openerp.eiru_quota_analysis = function (instance, local) {
|
|
self.$el.css('display','none');
|
|
self.$el.css('display','none');
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- */
|
|
|
|
|
|
|
|
- /*
|
|
|
|
- checkQuota: function(id) {
|
|
|
|
- var self = this;
|
|
|
|
- self.Initial();
|
|
|
|
- },
|
|
|
|
- */
|
|
|
|
/* */
|
|
/* */
|
|
updateId : function(id){
|
|
updateId : function(id){
|
|
var self = this;
|
|
var self = this;
|
|
@@ -73,16 +62,17 @@ openerp.eiru_quota_analysis = function (instance, local) {
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ /* GET Quota invoice */
|
|
fetchAccountInvoice: function (){
|
|
fetchAccountInvoice: function (){
|
|
var self = this;
|
|
var self = this;
|
|
- var domain = [
|
|
|
|
- ['id','=',self.id],
|
|
|
|
- ];
|
|
|
|
var AccountInvoice = new model.web.Model('account.invoice');
|
|
var AccountInvoice = new model.web.Model('account.invoice');
|
|
- return AccountInvoice.call('getAccountInvoiceQuoteAnalysis',[domain], {
|
|
|
|
|
|
+ return AccountInvoice.call('getAccountInvoiceQuoteAnalysis',[self.id], {
|
|
context: new model.web.CompoundContext()
|
|
context: new model.web.CompoundContext()
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ /* CURRENCY */
|
|
fetchResCurrency: function (){
|
|
fetchResCurrency: function (){
|
|
var self = this;
|
|
var self = this;
|
|
var domain = [
|
|
var domain = [
|
|
@@ -93,6 +83,8 @@ openerp.eiru_quota_analysis = function (instance, local) {
|
|
context: new model.web.CompoundContext()
|
|
context: new model.web.CompoundContext()
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ /* Generar Table */
|
|
build: function(){
|
|
build: function(){
|
|
var self = this;
|
|
var self = this;
|
|
var data = [];
|
|
var data = [];
|
|
@@ -100,33 +92,249 @@ openerp.eiru_quota_analysis = function (instance, local) {
|
|
var date = '';
|
|
var date = '';
|
|
var CurrencyBase = self.ResCurrency[0];
|
|
var CurrencyBase = self.ResCurrency[0];
|
|
_.each(self.AccountInvoice, function(item){
|
|
_.each(self.AccountInvoice, function(item){
|
|
|
|
+
|
|
if(item.state == 'Amortizado'){
|
|
if(item.state == 'Amortizado'){
|
|
state = item.state + ' ( ' + accounting.formatMoney(item.value, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator) + ' )';
|
|
state = item.state + ' ( ' + accounting.formatMoney(item.value, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator) + ' )';
|
|
}else{
|
|
}else{
|
|
state = item.state;
|
|
state = item.state;
|
|
}
|
|
}
|
|
- date = moment(item.date).format('DD/MM/YYYY');
|
|
|
|
|
|
+
|
|
|
|
+ date = moment(item.dateMaturity).format('DD/MM/YYYY');
|
|
if(item.state != 'Pagado'){
|
|
if(item.state != 'Pagado'){
|
|
- if(item.date < moment().format('YYYY-MM-DD')){
|
|
|
|
- date = moment(item.date,'YYYY-MM-DD').format('DD/MM/YYYY') + ' (vencido) ';
|
|
|
|
|
|
+ if(item.dateMaturity < moment().format('YYYY-MM-DD')){
|
|
|
|
+ date = moment(item.dateMaturity,'YYYY-MM-DD').format('DD/MM/YYYY') + ' (vencido) ';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
data.push({
|
|
data.push({
|
|
- 'date': date,
|
|
|
|
- 'name': item.name,
|
|
|
|
- 'state': state,
|
|
|
|
- 'amount': accounting.formatMoney(item.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
- 'residual': accounting.formatMoney(item.residual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
|
|
+ 'dateMaturity': date,
|
|
|
|
+ 'quotaNumber': item.quotaNumber,
|
|
|
|
+ 'amountQuota': accounting.formatMoney(item.amountQuota, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ 'amountResidual': accounting.formatMoney(item.amountResidual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ 'expiredDays': item.expiredDays,
|
|
|
|
+ 'amountInterest': accounting.formatMoney(item.amountInterest, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ 'amountTotal': accounting.formatMoney(item.amountTotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+ 'state': state
|
|
});
|
|
});
|
|
});
|
|
});
|
|
self.loadTable(data);
|
|
self.loadTable(data);
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ /* Load Table */
|
|
loadTable:function(rowsTable){
|
|
loadTable:function(rowsTable){
|
|
var self = this;
|
|
var self = this;
|
|
self.rowsData = rowsTable;
|
|
self.rowsData = rowsTable;
|
|
var table = $('#quota_table');
|
|
var table = $('#quota_table');
|
|
table.bootstrapTable('load', rowsTable);
|
|
table.bootstrapTable('load', rowsTable);
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*---------------------------
|
|
|
|
+ | IMPRIMIR |
|
|
|
|
+ --------------------------*/
|
|
|
|
+ /*INIT PRINT*/
|
|
|
|
+ initialPrint: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+
|
|
|
|
+ self.fetchInvoiceState().then(function(invoiceState){
|
|
|
|
+ return invoiceState
|
|
|
|
+ }).then(function(invoiceState){
|
|
|
|
+ self.invoiceState = invoiceState
|
|
|
|
+ return self.printCustomerAccountStatement();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /* GET Quota invoice */
|
|
|
|
+ fetchInvoiceState: function (){
|
|
|
|
+ var self = this;
|
|
|
|
+ var invoice = new model.web.Model('account.invoice');
|
|
|
|
+ return invoice.call('getInvoiceAccountStatemnete',[self.id], {
|
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /* Get interets total */
|
|
|
|
+ getInterestLines: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var total = 0;
|
|
|
|
+ _.each(self.AccountInvoice, function(item){
|
|
|
|
+ total += item.amountInterest;
|
|
|
|
+ });
|
|
|
|
+ return total;
|
|
|
|
+ },
|
|
|
|
+ filterLineQuota: function(currency) {
|
|
|
|
+ self = this;
|
|
|
|
+ var data = [];
|
|
|
|
+
|
|
|
|
+ _.each(self.AccountInvoice, function(item){
|
|
|
|
+ //
|
|
|
|
+ var state = item.state;
|
|
|
|
+ if(item.state == 'Amortizado'){
|
|
|
|
+ state = item.state + ' ('+instanceWeb.formatCurrency(item.value, currency)+' )';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ date = moment(item.dateMaturity).format('DD/MM/YYYY');
|
|
|
|
+
|
|
|
|
+ if(item.state != 'Pagado') {
|
|
|
|
+ if(item.dateMaturity < moment().format('YYYY-MM-DD')) {
|
|
|
|
+ date = moment(item.dateMaturity,'YYYY-MM-DD').format('DD/MM/YYYY') +' (vencido)';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ data.push({
|
|
|
|
+ 'dateMaturity': date,
|
|
|
|
+ 'quotaNumber': item.quotaNumber,
|
|
|
|
+ 'amountQuota': instanceWeb.formatCurrency(item.amountQuota, currency),
|
|
|
|
+ 'amountResidual': instanceWeb.formatCurrency(item.amountResidual, currency),
|
|
|
|
+ 'expiredDays': item.expiredDays,
|
|
|
|
+ 'amountInterest': instanceWeb.formatCurrency(item.amountInterest, currency),
|
|
|
|
+ 'amountTotal': instanceWeb.formatCurrency(item.amountTotal, currency),
|
|
|
|
+ 'state': state
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ return data
|
|
|
|
+ },
|
|
|
|
+ /*PRINT*/
|
|
|
|
+ printCustomerAccountStatement: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var pdfDoc = new jsPDF();
|
|
|
|
+ var y = 15;
|
|
|
|
+ var space = 7;
|
|
|
|
+ var invoice = self.invoiceState.shift();
|
|
|
|
+ var currency = invoice.currency;
|
|
|
|
+ console.log(currency.name);
|
|
|
|
+ var company = invoice.company;
|
|
|
|
+ var interest = self.getInterestLines();
|
|
|
|
+ var lineQuota =self.filterLineQuota(currency);
|
|
|
|
+ var base64Img = 'data:image/png;base64,' + company.logo;
|
|
|
|
+
|
|
|
|
+ /********************
|
|
|
|
+ | LOGO |
|
|
|
|
+ ********************/
|
|
|
|
+ pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
|
|
|
|
+ /********************
|
|
|
|
+ | FECHA |
|
|
|
|
+ ********************/
|
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.setTextColor(40)
|
|
|
|
+ pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, 8, moment().format('DD/MM/YYYY'));
|
|
|
|
+ /********************
|
|
|
|
+ | TITLE |
|
|
|
|
+ ********************/
|
|
|
|
+ pdfDoc.setFontSize('18');
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(105,y, pdfDoc.splitTextToSize('Estado de cuenta' , 180) , null, null, 'center');
|
|
|
|
+ pdfDoc.setFontSize('12');
|
|
|
|
+ /************************
|
|
|
|
+ | Clientes |
|
|
|
|
+ ************************/
|
|
|
|
+ y += 10;
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(10,y,'Cliente :');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.text(28,y, invoice.partner.name);
|
|
|
|
+ /********************************
|
|
|
|
+ | RUC |
|
|
|
|
+ ********************************/
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(110,y, 'RUC:');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.text(125, y,invoice.partner.ruc);
|
|
|
|
+ /************************
|
|
|
|
+ | Factura |
|
|
|
|
+ ************************/
|
|
|
|
+ y += space;
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(10,y, 'Factura :');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.text(30,y, invoice.number);
|
|
|
|
+ /********************
|
|
|
|
+ | MONEDA |
|
|
|
|
+ ********************/
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(110,y, 'Moneda:');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.text(130,y, currency.name);
|
|
|
|
+ /*****************************
|
|
|
|
+ | Amount TOTAL |
|
|
|
|
+ ****************************/
|
|
|
|
+ y += space;
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(10,y, 'Total Factura:');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.text(40, y, instanceWeb.formatCurrency(invoice.amountTotal, currency));
|
|
|
|
+ /********************************
|
|
|
|
+ | Amount Residual |
|
|
|
|
+ ********************************/
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(110,y, 'Residual:');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.setTextColor(231, 76, 60);
|
|
|
|
+ pdfDoc.text(132, y, instanceWeb.formatCurrency(invoice.amountResidual, currency));
|
|
|
|
+
|
|
|
|
+ /******************************
|
|
|
|
+ | Amount Interes |
|
|
|
|
+ ******************************/
|
|
|
|
+ y += space;
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.setTextColor(0, 0, 0);
|
|
|
|
+ pdfDoc.text(10,y, 'Interés Calculado:');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.text(50, y, instanceWeb.formatCurrency(interest, currency));
|
|
|
|
+ /*****************************************
|
|
|
|
+ | Amount Residual +Interes |
|
|
|
|
+ *****************************************/
|
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
|
+ pdfDoc.text(110,y, 'Residual + Interés:');
|
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
|
+ pdfDoc.setTextColor(231, 76, 60);
|
|
|
|
+ pdfDoc.text(150, y, instanceWeb.formatCurrency((invoice.amountResidual+interest), currency));
|
|
|
|
+
|
|
|
|
+ /*********************
|
|
|
|
+ | Table |
|
|
|
|
+ **********************/
|
|
|
|
+ var getColumns = [
|
|
|
|
+ {'title' : 'Vencimiento', 'dataKey' : 'dateMaturity'},
|
|
|
|
+ {'title' : 'Nº Cuota', 'dataKey' : 'quotaNumber'},
|
|
|
|
+ {'title' : 'Cuota', 'dataKey' : 'amountQuota'},
|
|
|
|
+ {'title' : 'Pendiente', 'dataKey' : 'amountResidual'},
|
|
|
|
+ {'title' : 'Días atrasado', 'dataKey' : 'expiredDays'},
|
|
|
|
+ {'title' : 'Interés', 'dataKey' : 'amountInterest'},
|
|
|
|
+ {'title' : 'Total', 'dataKey' : 'amountTotal'},
|
|
|
|
+ {'title' : 'Estado', 'dataKey' : 'state'},
|
|
|
|
+ ]
|
|
|
|
+ rowsPdf = lineQuota;
|
|
|
|
+
|
|
|
|
+ pdfDoc.autoTable(getColumns,rowsPdf, {
|
|
|
|
+ body: rowsPdf,
|
|
|
|
+ theme: 'grid',
|
|
|
|
+ startY: 50,
|
|
|
|
+ styles: {
|
|
|
|
+ overflow: 'linebreak',
|
|
|
|
+ columnWidth: 'auto',
|
|
|
|
+ fontSize: 8,
|
|
|
|
+ },
|
|
|
|
+ columnStyles: {
|
|
|
|
+ dateMaturity : {columnWidth: 25, halign:'center'},
|
|
|
|
+ quotaNumber: {columnWidth: 20, halign:'center'},
|
|
|
|
+ amountQuota: {halign:'right'},
|
|
|
|
+ amountResidual : {halign:'right'},
|
|
|
|
+ expiredDays : {columnWidth: 25, halign:'center'},
|
|
|
|
+ amountInterest : {halign:'right'},
|
|
|
|
+ amountTotal : {halign:'right'},
|
|
|
|
+ state : {columnWidth: 20, halign:'center'},
|
|
|
|
+ },
|
|
|
|
+ headerStyles: {
|
|
|
|
+ fillColor: [76, 133, 248],
|
|
|
|
+ fontSize: 9
|
|
|
|
+ },
|
|
|
|
+ margin: {
|
|
|
|
+ top: 20,
|
|
|
|
+ horizontal: 7,
|
|
|
|
+ bottom: 40
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ pdfDoc.save('Estado_financiero.pdf');
|
|
|
|
+ },
|
|
});
|
|
});
|
|
|
|
|
|
if (instance.web && instance.web.FormView) {
|
|
if (instance.web && instance.web.FormView) {
|