|
@@ -0,0 +1,493 @@
|
|
|
+function report_amortization_and_interest(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportAmortizationAndInterestWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportAmortizationAndInterest',
|
|
|
+ rowsData : [],
|
|
|
+ content : [],
|
|
|
+ Order: '',
|
|
|
+ modules: ['point_of_sale'],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ // 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ // 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-date' : 'ShowDateRange',
|
|
|
+ // 'change #current-period' : 'updatePeriodSelections',
|
|
|
+ },
|
|
|
+
|
|
|
+ init : function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ var table = this.$el.find('#xtable');
|
|
|
+ table.bootstrapTable({
|
|
|
+ data : self.rowsData,
|
|
|
+ onExpandRow: function (index, row, $detail) {
|
|
|
+ self.expandTable($detail,row.number);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var date = new model.eiru_reports.ReportDatePickerWidget(self);
|
|
|
+ date.fecthFecha();
|
|
|
+ this.fetchInitial();
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor = "";
|
|
|
+ if (dato){
|
|
|
+ valor = dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ ShowDateRange : function(){
|
|
|
+ var self = this;
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ if(date == 'range'){
|
|
|
+ self.$el.find('.datepicker').css('display','block');
|
|
|
+ }
|
|
|
+ if(date != 'range'){
|
|
|
+ self.$el.find('.datepicker').css('display','none');
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fetchDataSQL().then(function (DataSQL) {
|
|
|
+ return DataSQL;
|
|
|
+ }).then(function(DataSQL) {
|
|
|
+ self.AccountInvoice = DataSQL.invoices;
|
|
|
+ self.AccountInvoiceLine = DataSQL.invoice_lines;
|
|
|
+ self.AccountJournal = DataSQL.journals;
|
|
|
+ self.ResCompany = DataSQL.companies;
|
|
|
+ self.ResStore = DataSQL.stores;
|
|
|
+ self.AccountMoveLine = DataSQL.move_lines;
|
|
|
+ self.AccountVoucher = DataSQL.vouchers;
|
|
|
+ });
|
|
|
+ self.$el.find('#generate').css('display','inline');
|
|
|
+ return;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchGenerate: function () {
|
|
|
+ var self = this;
|
|
|
+ self.$el.find('.search-form').block({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.$el.find('.report-form').block({
|
|
|
+ message: null,
|
|
|
+ overlayCSS: {
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return self.BuildTable();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchDataSQL: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = $.get('/report-crifin-credit-utility');
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountMoveLine: function (number) {
|
|
|
+ var self = this;
|
|
|
+ var lines = _.filter(self.AccountMoveLine,function (item) {
|
|
|
+ return item.number == number;
|
|
|
+ });
|
|
|
+ var x = lines.length;
|
|
|
+ var i = 1;
|
|
|
+ var content =_.map(lines, function(item){
|
|
|
+ item.description = 'Cuota ' + i +' / ' + x;
|
|
|
+ i++;
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountVoucher: function (number) {
|
|
|
+ var self = this;
|
|
|
+ var valor = _.reduce(_.map(self.AccountVoucher, function (map) {
|
|
|
+ if(map.reference == number){
|
|
|
+ return map.amount_currency;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ getAccountInvoiceLine: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.flatten(_.filter(self.AccountInvoiceLine,function (item){
|
|
|
+ return item.invoice_id == id;
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ console.log(self);
|
|
|
+ var columns = [];
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
+ _.each(self.AccountInvoice,function(item) {
|
|
|
+ if(item.is_interest == null){
|
|
|
+ var pagado = self.getAccountVoucher(item.number);
|
|
|
+ var AccountInvoiceLine = self.getAccountInvoiceLine(item.invoice_id);
|
|
|
+
|
|
|
+ var capital = _.reduce(_.map(AccountInvoiceLine, function (map) {
|
|
|
+ if(!map.is_interest){
|
|
|
+ return map.quantity * map.price_unit;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var interes = _.reduce(_.map(AccountInvoiceLine, function (map) {
|
|
|
+ if(map.is_interest){
|
|
|
+ return map.quantity * map.price_unit;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ /*
|
|
|
+ ########################
|
|
|
+ ID
|
|
|
+ ########################
|
|
|
+ */
|
|
|
+ id:item.invoice_id,
|
|
|
+ /*
|
|
|
+ ########################
|
|
|
+ DATOS FORMATADOS
|
|
|
+ ########################
|
|
|
+ */
|
|
|
+ number:item.number,
|
|
|
+ origin:item.origin,
|
|
|
+ customer_name:item.customer_name,
|
|
|
+ date_invoice:moment(item.date).format('DD/MM/YYYY'),
|
|
|
+ capital_amount:accounting.formatMoney(capital,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ interest_amount:accounting.formatMoney(interes,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ amount:accounting.formatMoney(item.amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ residual:accounting.formatMoney(item.amount - pagado,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ /*
|
|
|
+ ########################
|
|
|
+ DATOS SIN FORMATO
|
|
|
+ ########################
|
|
|
+ */
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self.loadTable(data);
|
|
|
+ self.$el.find('.report-form').css('display','block');
|
|
|
+ self.$el.find('.search-form').unblock();
|
|
|
+ self.$el.find('.report-form').unblock();
|
|
|
+ },
|
|
|
+
|
|
|
+ expandTable: function($detail,number) {
|
|
|
+ var self = this;
|
|
|
+ self.BuildSubTable($detail.html('<table data-classes="table table-condensed" data-buttons-class="oe_button myButton" data-show-export="true" data-show-footer="true" data-footer-style="footerStyle"></table><br/>').find('table'),number);
|
|
|
+ },
|
|
|
+
|
|
|
+ BuildSubTable: function($el,number) {
|
|
|
+ var self = this;
|
|
|
+ var columns = [];
|
|
|
+ var data = [];
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
+ columns.push({
|
|
|
+ field:'description',
|
|
|
+ title:'Descripcion',
|
|
|
+ footerFormatter:'Totales'
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'date_maturity',
|
|
|
+ title:'Vencimiento',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'capital',
|
|
|
+ title:'Saldo del Capital',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'interest_amount',
|
|
|
+ title:'Interes',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'capital_amount',
|
|
|
+ title:'Amortizacion',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'amount',
|
|
|
+ title:'Monto de la cuota',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ footerFormatter:'TotalFormatter'
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'residual',
|
|
|
+ title:'Saldo de la cuota',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ footerFormatter:'ResidualFormatter'
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'capital_receive',
|
|
|
+ title:'Capital Recuperado',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ // footerFormatter:'TotalFormatter'
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ field:'interest_receive',
|
|
|
+ title:'Interes Cobrado',
|
|
|
+ align:'right',
|
|
|
+ with:'12%',
|
|
|
+ // footerFormatter:'TotalFormatter'
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var AccountMoveLine = self.getAccountMoveLine(number);
|
|
|
+ var AccountInvoice = _.flatten(_.filter(self.AccountInvoice,function (item){
|
|
|
+ return item.number == number;
|
|
|
+ }));
|
|
|
+ var AccountInvoiceLine = self.getAccountInvoiceLine(AccountInvoice[0].invoice_id);
|
|
|
+ var capital = AccountInvoice[0].amount;
|
|
|
+ var cant_cuota = AccountMoveLine.length;
|
|
|
+
|
|
|
+ var amortizacion = _.reduce(_.map(AccountInvoiceLine, function (map) {
|
|
|
+ if(!map.is_interest){
|
|
|
+ return map.quantity * map.price_unit;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var interes = _.reduce(_.map(AccountInvoiceLine, function (map) {
|
|
|
+ if(map.is_interest){
|
|
|
+ return map.quantity * map.price_unit;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var interest_amount = interes / cant_cuota;
|
|
|
+ var capital_amount = amortizacion / cant_cuota;
|
|
|
+ var capital_receive = 0;
|
|
|
+ var interest_receive = 0;
|
|
|
+ _.each(AccountMoveLine,function(item) {
|
|
|
+ if(item.number == number){
|
|
|
+ capital_receive = 0
|
|
|
+ interest_receive = 0
|
|
|
+ if(item.debit > 0 && item.date_maturity != false){
|
|
|
+ if(item.reconcile_partial_id == null){
|
|
|
+ var residual = item.debit;
|
|
|
+ }else{
|
|
|
+ var pagado = self.getAccountVoucher(item.number);
|
|
|
+ var x = 0;
|
|
|
+ var band = true;
|
|
|
+ _.each(AccountMoveLine,function(i) {
|
|
|
+ x += i.debit;
|
|
|
+ var saldo = Math.abs(pagado - x);
|
|
|
+ if(AccountMoveLine.length == 1){
|
|
|
+ residual = saldo;
|
|
|
+ band = false;
|
|
|
+ }
|
|
|
+ if(saldo < i.debit && band == true){
|
|
|
+ residual = i.debit - saldo;
|
|
|
+ band = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(item.reconcile_id != null){
|
|
|
+ residual = 0;
|
|
|
+ capital_receive = capital_amount;
|
|
|
+ interest_receive = interest_amount;
|
|
|
+ }
|
|
|
+ capital = capital - item.debit;
|
|
|
+ data.push({
|
|
|
+ /*
|
|
|
+ ########################
|
|
|
+ DATOS FORMATADOS
|
|
|
+ ########################
|
|
|
+ */
|
|
|
+ description:item.description,
|
|
|
+ date:item.date_maturity,
|
|
|
+ date_maturity: moment(item.date_maturity).format('DD/MM/YYYY'),
|
|
|
+ capital: accounting.formatMoney(capital,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ capital_amount: accounting.formatMoney(capital_amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ interest_amount: accounting.formatMoney(interest_amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ residual: accounting.formatMoney(residual,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ amount: accounting.formatMoney(item.debit,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ capital_receive:accounting.formatMoney(capital_receive,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+ interest_receive:accounting.formatMoney(interest_receive,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
|
|
|
+
|
|
|
+ /*
|
|
|
+ ########################
|
|
|
+ DATOS FORMATADOS
|
|
|
+ ########################
|
|
|
+ */
|
|
|
+ 'residual_value': residual,
|
|
|
+ 'amount_value': item.debit,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $el.bootstrapTable({
|
|
|
+ columns: columns,
|
|
|
+ data: data,
|
|
|
+ // onExpandRow: function (index, row, $detail) {
|
|
|
+ // self.expandSubTable($detail,row.id);
|
|
|
+ // }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // expandSubTable: function($detail,id) {
|
|
|
+ // var self = this;
|
|
|
+ // self.BuildSubSubTable($detail.html('<table data-detail-view="true" data-classes="table table-condensed"></table>').find('table'),id);
|
|
|
+ // },
|
|
|
+ //
|
|
|
+ // BuildSubSubTable: function($el,id) {
|
|
|
+ // var self = this;
|
|
|
+ // var columns = [];
|
|
|
+ // var data = [];
|
|
|
+ // columns.push({
|
|
|
+ // field: 'id',
|
|
|
+ // title: 'ID',
|
|
|
+ // visible: false,
|
|
|
+ // });
|
|
|
+ // columns.push({
|
|
|
+ // field: 'ruc',
|
|
|
+ // title: 'RUC',
|
|
|
+ // with:'15%',
|
|
|
+ // });
|
|
|
+ // columns.push({
|
|
|
+ // field: 'name',
|
|
|
+ // title: 'Nombre',
|
|
|
+ // });
|
|
|
+ // columns.push({
|
|
|
+ // field: 'amount',
|
|
|
+ // title: 'Valor',
|
|
|
+ // align:'right',
|
|
|
+ // with:'15%',
|
|
|
+ // });
|
|
|
+ // var company = $('#current-company').val();
|
|
|
+ // if(company && company != 9999999){
|
|
|
+ // var ResCompany = self.getResCompany(company).shift();
|
|
|
+ // var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ // }else{
|
|
|
+ // var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ // };
|
|
|
+ // _.each(self.ResPartner,function(item) {
|
|
|
+ // if(item.state_id.id == id){
|
|
|
+ // var amount = self.getAmount([item.id]);
|
|
|
+ // data.push({
|
|
|
+ // 'id': item.id,
|
|
|
+ // 'ruc': self.valorNull(item.ruc),
|
|
|
+ // 'name': item.name,
|
|
|
+ // 'amount': accounting.formatMoney(amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ // });
|
|
|
+ // };
|
|
|
+ // });
|
|
|
+ // $el.bootstrapTable({
|
|
|
+ // columns: columns,
|
|
|
+ // data: data,
|
|
|
+ // onExpandRow: function (index, row, $detail) {
|
|
|
+ // self.expandSubSubTable($detail,row.id);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ //
|
|
|
+ // expandSubSubTable: function($detail,id) {
|
|
|
+ // var self = this;
|
|
|
+ // self.BuildSubSubSubTable($detail.html('<table data-classes="table table-condensed"></table>').find('table'),id);
|
|
|
+ // },
|
|
|
+ //
|
|
|
+ // BuildSubSubSubTable: function($el,id) {
|
|
|
+ // var self = this;
|
|
|
+ // var columns = [];
|
|
|
+ // var data = [];
|
|
|
+ // columns.push({
|
|
|
+ // field: 'date',
|
|
|
+ // title: 'Fecha',
|
|
|
+ // with:'15%',
|
|
|
+ // });
|
|
|
+ // columns.push({
|
|
|
+ // field: 'number',
|
|
|
+ // title: 'Factura',
|
|
|
+ // });
|
|
|
+ // columns.push({
|
|
|
+ // field: 'amount',
|
|
|
+ // title: 'Valor',
|
|
|
+ // align:'right',
|
|
|
+ // with:'15%',
|
|
|
+ // });
|
|
|
+ // var company = $('#current-company').val();
|
|
|
+ // if(company && company != 9999999){
|
|
|
+ // var ResCompany = self.getResCompany(company).shift();
|
|
|
+ // var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ // }else{
|
|
|
+ // var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ // }
|
|
|
+ // var invoice = self.getInvoiceDetails([id]);
|
|
|
+ // _.each(invoice,function(index) {
|
|
|
+ // data.push({
|
|
|
+ // 'date': moment(index.date_invoice).format('DD/MM/YYYY'),
|
|
|
+ // 'number': index.number,
|
|
|
+ // 'amount': accounting.formatMoney(index.amount_currency, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // var pos = self.getPosDetails([id]);
|
|
|
+ // _.each(pos,function(index) {
|
|
|
+ // var utc = moment.utc(index.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ // data.push({
|
|
|
+ // 'date': moment(utc._d).format('DD/MM/YYYY'),
|
|
|
+ // 'number': index.number,
|
|
|
+ // 'amount': accounting.formatMoney(index.amount_currency, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // $el.bootstrapTable({
|
|
|
+ // columns: columns,
|
|
|
+ // data: data,
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+
|
|
|
+ loadTable:function(rowsTable){
|
|
|
+ var self = this;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#xtable');
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ });
|
|
|
+}
|