瀏覽代碼

commit inicial

Rodney Elpidio Enciso Arias 6 年之前
當前提交
89cbfdfbdc

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import models
+import controllers

+ 20 - 0
__openerp__.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Eiru Reports - Crifin",
+    'author': "Eiru",
+    'category': 'report',
+    'version': '0.1',
+    'depends': [
+        'eiru_assets',
+        'eiru_reports',
+    ],
+    'qweb': [
+        'static/src/xml/*.xml',
+        'static/src/reports/*.xml'
+    ],
+    'data': [
+        'templates.xml',
+        'views/actions.xml',
+        'views/menus.xml',
+    ],
+}

+ 1 - 0
controllers/__init__.py

@@ -0,0 +1 @@
+import main

+ 8 - 0
controllers/helpers/__init__.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+from account_invoice import get_account_invoice
+from account_invoice_line import get_account_invoice_line
+from account_journal import get_account_journal
+from res_company import get_res_company
+from res_store import get_res_store
+from account_move_line import get_account_move_line
+from account_voucher import get_account_voucher

+ 62 - 0
controllers/helpers/account_invoice.py

@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_invoice():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT
+        	invoice.id,
+        	rate.currency_id,
+        	invoice.date_invoice,
+        	invoice.type,
+        	invoice.origin,
+        	invoice.partner_id,
+        	invoice.user_id,
+        	invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as invoice_rate,
+            invoice.number,
+            invoice.is_interest,
+            customer.name
+        FROM account_invoice AS invoice
+        LEFT JOIN res_store_journal_rel AS journal
+        ON journal.journal_id = invoice.journal_id
+        LEFT JOIN res_currency_rate AS rate
+        ON rate.currency_id = invoice.currency_id
+        LEFT JOIN res_company AS company
+        ON company.id = invoice.company_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        AND invoice.type = 'out_invoice'
+        AND invoice.id = 8
+        GROUP BY
+        	invoice.id,
+        	rate.currency_id,
+        	invoice.date_invoice,
+        	invoice.type,
+        	invoice.origin,
+        	invoice.amount_total,
+        	invoice.partner_id,
+        	invoice.user_id,
+            invoice.amount_total,
+            invoice.is_interest,
+            customer.name
+    '''
+
+    r.cr.execute(query,(tuple([company_currency_rate])))
+
+    return [
+        {
+            'invoice_id': j[0],
+            'currency_id': j[1],
+            'date': j[2],
+            'type': j[3],
+            'origin': j[4],
+            'customer_id':j[5],
+            'user_id':j[6],
+            'amount':j[7],
+            'number':j[8],
+            'is_interest':j[9],
+            'customer_name':j[10],
+        } for j in r.cr.fetchall()
+    ]

+ 68 - 0
controllers/helpers/account_invoice_line.py

@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_invoice_line():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+        	product.name_template,
+        	line.price_unit * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as price_unit,
+        	line.quantity AS cant,
+        	line.price_subtotal * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) AS subtotal,
+        	(line.quantity * (line.price_unit * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]))) - (line.price_subtotal * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1])) AS impuestos,
+        	(array_agg(history.cost ORDER BY history.id DESC))[1] * line.quantity as cost,
+            template.is_interest
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            LEFT JOIN product_product AS product
+            ON line.product_id = product.id
+            LEFT JOIN product_template AS template
+            ON template.id = product.product_tmpl_id
+            LEFT JOIN res_store_journal_rel AS journal
+            ON journal.journal_id = invoice.journal_id
+            LEFT JOIN product_price_history AS history
+            ON history.product_template_id = product.product_tmpl_id
+            LEFT JOIN res_currency_rate AS rate
+            ON rate.currency_id = invoice.currency_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type = 'out_invoice'
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            template.is_interest
+    '''
+
+    r.cr.execute(query,(tuple([company_currency_rate,company_currency_rate,company_currency_rate,company_currency_rate])))
+
+    return [
+        {
+            'invoice_id': j[0],
+            'invoice_line_id': j[1],
+            'number': j[2],
+            'origin': j[3],
+            'date': j[4],
+            'type': j[5],
+            'product_name':j[6],
+            'price_unit':j[7],
+            'quantity':j[8],
+            'subtotal':j[9],
+            'tax': j[10],
+            'cost': j[11],
+            'is_interest': j[12],
+        } for j in r.cr.fetchall()
+    ]

+ 25 - 0
controllers/helpers/account_journal.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_journal():
+    user_store = r.env.user.store_id.id
+    query = '''
+        SELECT aj.id, aj.name, aj.code, aj.type, rs.store_id
+        FROM account_journal AS aj
+        LEFT JOIN res_store_journal_rel AS rs
+        ON aj.id = rs.journal_id
+        WHERE aj.active = true
+        AND aj.type in ('sale')
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'code': j[2],
+            'type': j[3],
+            'store_id': j[4]
+        } for j in r.cr.fetchall()
+    ]

+ 79 - 0
controllers/helpers/account_move_line.py

@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_move_line():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT
+            invoice.number,
+            line.date_maturity,
+            partner.name,
+            partner.ruc,
+            line.credit,
+            line.debit,
+            invoice.id,
+            line.reconcile_ref,
+            line.reconcile_id,
+            line.reconcile_partial_id,
+            invoice.amount_total AS invoice_amount,
+            CASE
+        		WHEN invoice.currency_id IS NULL
+        		THEN invoice.amount_total
+        		ELSE invoice.amount_total * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
+        		END AS invoice_amount_currency
+        -- INVOICE
+        FROM account_invoice AS invoice
+        -- JOURNAL/STORE
+        LEFT JOIN res_store_journal_rel AS journal_rel
+        ON journal_rel.journal_id = invoice.journal_id
+        -- JOURNAL
+        LEFT JOIN account_journal AS journal
+        ON journal.id = invoice.journal_id
+	-- MOVE
+        LEFT JOIN account_move AS move
+        ON move.name = invoice.number
+	-- MOVE LINE
+        LEFT JOIN account_move_line AS line
+        ON line.move_id = move.id AND line.date_maturity IS NOT NULL
+        -- PARTNER
+        LEFT JOIN res_partner AS partner
+        ON line.partner_id = partner.id
+        -- RATE
+        LEFT JOIN res_currency_rate AS rate
+        ON rate.currency_id = invoice.currency_id
+        
+        --AND invoice.id = 20940
+        GROUP BY    invoice.number,
+                    line.date_maturity,
+                    partner.name,
+                    partner.ruc,
+                    line.credit,
+                    line.debit,
+                    invoice.id,
+                    line.reconcile_ref,
+                    line.reconcile_id,
+                    line.reconcile_partial_id,
+                    invoice.amount_total,
+                    journal.currency,
+                    journal.name
+
+    '''
+
+    r.cr.execute(query,(tuple([company_currency_rate])))
+    return [
+        {
+            'number': j[0],
+            'date_maturity': j[1],
+            'partner': j[2],
+            'ruc': j[3],
+            'credit': j[4],
+            'debit': j[5],
+            'invoice_id': j[6],
+            'reconcile_ref': j[7],
+            'reconcile_id': j[8],
+            'reconcile_partial_id': j[9],
+            'amount_total': j[10],
+            'amount_total_currency': j[11],
+        } for j in r.cr.fetchall()
+    ]

+ 55 - 0
controllers/helpers/account_voucher.py

@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_voucher():
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT  voucher.id,
+        	voucher.number,
+        	voucher.type,
+        	voucher.date,
+        	journal.currency,
+            voucher.amount,
+        	CASE
+        		WHEN journal.currency IS NULL
+        		THEN voucher.amount
+        		ELSE voucher.amount * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
+        		END AS amount_currency,
+            voucher.journal_id,
+            voucher.reference
+        FROM account_voucher AS voucher
+        LEFT JOIN res_store_journal_rel AS journal_rel
+        ON voucher.journal_id = journal_rel.journal_id
+        LEFT JOIN account_journal AS journal
+        ON journal.id = voucher.journal_id
+        LEFT JOIN res_currency_rate AS rate
+        ON rate.currency_id = journal.currency
+        LEFT JOIN account_invoice AS invoice
+        ON invoice.number = voucher.reference
+        WHERE voucher.state = 'posted'
+        AND invoice.state = 'open'
+        GROUP BY
+        	voucher.id,
+        	voucher.number,
+        	voucher.type,
+        	voucher.date,
+        	voucher.amount,
+        	journal.name,
+        	journal.currency
+    '''
+
+    r.cr.execute(query,(tuple([company_currency_rate])))
+
+    return [
+        {
+            'id': j[0],
+            'number': j[1],
+            'type': j[2],
+            'date': j[3],
+            'currency_id': j[4],
+            'amount': j[5],
+            'amount_currency': j[6],
+            'journal_id': j[7],
+            'reference': j[8],
+        } for j in r.cr.fetchall()
+    ]

+ 44 - 0
controllers/helpers/res_company.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_res_company():
+    user_company = r.env.user.company_id.id
+    user_store = r.env.user.store_id.id
+    query = '''
+    SELECT
+        company.id,
+        company.name,
+        currency.id,
+        currency.name,
+        currency.symbol,
+        currency.decimal_places,
+        currency.decimal_separator,
+        currency.thousands_separator,
+        currency.symbol_position,
+        partner.ruc AS company_ruc
+    FROM res_company AS company
+    LEFT JOIN res_currency AS currency
+    ON company.currency_id = currency.id
+    LEFT JOIN res_partner AS partner
+    ON partner.id = company.partner_id
+    WHERE currency.active = true
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'currency_id':{
+                'id':  j[2],
+                'name':  j[3],
+                'symbol':  j[4],
+                'decimal_places':  j[5],
+                'decimal_separator':  j[6],
+                'thousands_separator':  j[7],
+                'symbol_position':  j[8],
+            },
+            'ruc': j[9],
+        } for j in r.cr.fetchall()
+    ]

+ 20 - 0
controllers/helpers/res_store.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_res_store():
+    query = '''
+        SELECT  id,
+                name,
+                company_id
+        FROM res_store
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'company_id': j[2],
+        } for j in r.cr.fetchall()
+    ]

+ 41 - 0
controllers/main.py

@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+from openerp import http
+from werkzeug.wrappers import Response
+from werkzeug.datastructures import Headers
+from gzip import GzipFile
+from StringIO import StringIO as IO
+import simplejson as json
+import helpers as hp
+import logging
+
+LOGGER = logging.getLogger(__name__)
+GZIP_COMPRESSION_LEVEL = 9
+
+def make_gzip_response(data=None, status=200):
+    gzip_buffer = IO()
+
+    with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
+        gzip_file.write(json.dumps(data))
+
+    value = gzip_buffer.getvalue()
+    gzip_buffer.close()
+
+    headers = Headers()
+    headers.add('Content-Encoding', 'gzip')
+    headers.add('Vary', 'Accept-Encoding')
+    headers.add('Content-Length', len(value))
+
+    return Response(value, status=status, headers=headers, content_type='application/json')
+
+class ReportCrifinController(http.Controller):
+    @http.route('/report-crifin-credit-utility', auth='user', methods=['GET', 'POST'])
+    def getWidgetList(self, **kw):
+        return make_gzip_response({
+            'invoices': hp.get_account_invoice(),
+            'invoice_lines': hp.get_account_invoice_line(),
+            'journals': hp.get_account_journal(),
+            'companies': hp.get_res_company(),
+            'stores': hp.get_res_store(),
+            'move_lines': hp.get_account_move_line(),
+            'vouchers': hp.get_account_voucher(),
+        })

+ 111 - 0
models.py

@@ -0,0 +1,111 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api
+
+class ResPartner(models.Model):
+	_inherit = 'res.partner'
+
+	@api.model
+	def getResPartnerMedic(self,domain):
+		ResPartner = self.env['res.partner'].search(domain)
+		values = []
+		for partner in ResPartner:
+			values.append({
+				'id': partner.id,
+				'name': partner.name,
+				'ruc': partner.ruc,
+				'street': partner.street,
+				'city': partner.city,
+				'state_id': {
+					'id':partner.state_id.id,
+					'name':partner.state_id.name,
+					'complete_name':partner.state_id.complete_name,
+				},
+				'phone': partner.phone,
+				'mobile': partner.mobile,
+				'email': partner.email,
+				'property_product_pricelist': partner.property_product_pricelist.name,
+				'property_product_pricelist_purchase': partner.property_product_pricelist_purchase.name,
+				'credit': partner.credit,
+				'debit': partner.debit,
+				'supplier': partner.supplier,
+				'is_medic': partner.is_medic,
+				'medic': [
+					partner.medic.id,
+					partner.medic.name,
+				],
+			})
+
+		return values
+
+
+class AccountInvoice(models.Model):
+	_inherit = 'account.invoice'
+
+	@api.model
+	def getAccountInvoiceOdontoimagen(self,domain):
+		AccountInvoice = self.env['account.invoice'].search(domain)
+		decimal_precision = self.env['decimal.precision'].precision_get('Account')
+		values = []
+		for invoice in AccountInvoice:
+			values.append({
+				'id': invoice.id,
+				'number': invoice.number,
+				'date_invoice': invoice.date_invoice,
+				'journal_id':{
+					'id': invoice.journal_id.id,
+					'name': invoice.journal_id.name,
+				},
+				'partner_id':{
+					'id':invoice.partner_id.id,
+					'name':invoice.partner_id.name,
+					'ruc':invoice.partner_id.ruc,
+				},
+				'amount_currency': round(invoice.amount_total * (invoice.company_id.currency_id.rate / invoice.currency_id.rate),decimal_precision),
+			})
+
+		return values
+
+	@api.model
+	def getPosOrderOdontoimagen(self,domain):
+		PosOrder = self.env['pos.order'].search(domain)
+		decimal_precision = self.env['decimal.precision'].precision_get('Account')
+		values = []
+		for order in PosOrder:
+			values.append({
+				'id': order.id,
+				'number': order.name,
+				'date_order': order.date_order,
+				'sale_journal':{
+					'id': order.sale_journal.id,
+					'name': order.sale_journal.name,
+				},
+				'partner_id':{
+					'id': order.partner_id.id,
+					'name': order.partner_id.name,
+					'ruc': order.partner_id.ruc,
+				},
+				'amount_currency': round(order.amount_total * (order.company_id.currency_id.rate / order.pricelist_id.currency_id.rate),decimal_precision),
+			})
+
+		return values
+
+class ResCountryState(models.Model):
+	_inherit = 'res.country.state'
+
+	@api.model
+	def getResCountryState(self,domain):
+		ResCountryState = self.env['res.country.state'].search(domain)
+		values = []
+		for state in ResCountryState:
+			values.append({
+				'id': state.id,
+				'name': state.name,
+				'complete_name':state.complete_name,
+				'parent_id':{
+					'id': state.parent_id.id,
+					'name': state.parent_id.name,
+				},
+			})
+
+		return values

二進制
static/description/icon.png


+ 15 - 0
static/src/js/main.js

@@ -0,0 +1,15 @@
+openerp.eiru_reports_crifin = function (instance) {
+    "use strict";
+
+    var reporting = instance.eiru_reports_crifin;
+
+    reporting_base(instance,reporting);
+
+    try {
+        report_amortization_and_interest(reporting);
+    } catch (e) {
+
+    }
+
+    instance.web.client_actions.add('eiru_reports_crifin.amortization_and_interest_report', 'instance.eiru_reports_crifin.ReportAmortizationAndInterestWidget');
+};

+ 22 - 0
static/src/js/reporting_base.js

@@ -0,0 +1,22 @@
+function reporting_base (instance, widget) {
+    "use strict";
+
+    widget.Base = instance.Widget.extend({
+
+        position: 0,
+
+        init: function (parent, position) {
+            this._super(parent);
+            this.position = position || this.position;
+        },
+        start: function () {
+            
+        },
+        getPosition: function () {
+            return this.position;
+        },
+        setPosition: function (position) {
+            this.position = position;
+        }
+    });
+}

+ 493 - 0
static/src/js/reports/report_amortization_and_interest.js

@@ -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);
+        },
+
+    });
+}

+ 150 - 0
static/src/reports/report_amortization_and_interest.xml

@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportAmortizationAndInterest">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title">Amortizaciones e Intereses</h1>
+            </div>
+            <div class="container search-form" style="border-bottom:1px solid #eee; width:95%;">
+                <div class="row">
+                    <div class="col-lg-3 company filter-style">
+                        <label>Empresa</label>
+                        <select id="current-company" class="form-control form-control-sm"></select>
+                    </div>
+                    <div class="col-lg-3 store filter-style">
+                        <label>Sucursal</label>
+                        <select id="current-store" class="form-control form-control-sm">
+                        </select>
+                    </div>
+                    <!-- <div class="col-lg-3 journal filter-style">
+                        <label>Factura</label>
+                        <select id="current-journal" class="form-control form-control-sm">
+                        </select>
+                    </div> -->
+                    <!-- <div class="col-lg-3 type filter-style">
+                        <label>Tipo de Venta</label>
+                        <select id="current-type" class="form-control form-control-sm">
+                            <option value="9999999">Todos los Tipos</option>
+                            <option value="tpv">Terminal</option>
+                            <option value="sale">Normal</option>
+                        </select>
+                    </div> -->
+                    <!-- <div class="col-lg-3 filter-style">
+                        <label>Periodo</label>
+                        <select id="current-period" class="form-control form-control-sm">
+                        </select>
+                    </div> -->
+                    <div class="col-lg-3 filter-style">
+                        <label>Fechas</label>
+                        <select id="current-date" class="form-control form-control-sm">
+                            <option value="9999999">Sin fechas</option>
+                            <option value="today">Hoy</option>
+                            <option value="yesterday">Ayer</option>
+                            <option value="currentMonth">Mes Actual</option>
+                            <option value="lastMonth">Mes Pasado</option>
+                            <option value="range">Busqueda Avanzada</option>
+                        </select>
+                    </div>
+                </div>
+                <div class="row" >
+                    <div class="datepicker" style="display:none;">
+                        <div class="col-lg-3 filter-style col-md-offset-3">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Desde</span>
+                                <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                        <div class="col-lg-3 filter-style">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                                <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="text-center" style="padding-top:20px;">
+                        <button id="generate" class="myButton" aria-label="Left Align">
+                            Generar
+                        </button>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+
+            <div class="report-form" style="display:none;">
+                <!-- <div id="toolbar">
+                    <button class="oe_button myButton" value="pdf">Imprimir Informe</button>
+                </div> -->
+                <div class="container" style="width:95%;">
+                     <!-- table-no-bordered -->
+                    <table
+                        id = "xtable"
+                        data-show-columns="true"
+                        data-show-footer="true"
+                        data-show-export="true"
+                        data-show-toggle="true"
+                        data-show-pagination-switch="true"
+                        data-detail-view = "true"
+                        data-classes="table table-condensed table-no-bordered"
+                        data-search="true"
+                        data-search-on-enter-key="true"
+                        data-toolbar="#toolbar"
+                        data-buttons-class="oe_button myButton"
+                        data-footer-style="footerStyle"
+                        data-pagination="true"
+                        data-page-size="10"
+                        >
+                        <thead style="background:none;">
+                            <tr>
+                                <th data-field="id" data-visible="false">ID</th>
+                                <th data-field="number">Factura</th>
+                                <th data-field="origin">Documento Origen</th>
+                                <th data-field="customer_name">Cliente</th>
+                                <th data-field="date_invoice">Fecha</th>
+                                <th data-field="capital_amount" data-align="right" data-width="12%">Capital</th>
+                                <th data-field="interest_amount" data-align="right" data-width="12%">Interes</th>
+                                <th data-field="amount" data-align="right" data-width="12%">Monto de la Cuenta</th>
+                                <th data-field="residual" data-align="right" data-width="12%">Saldo de la Cuenta</th>
+                            </tr>
+                        </thead>
+                    </table>
+                </div>
+            </div>
+            <script>
+                function AmountFooter(rowsTable) {
+                    var quantity =  _.reduce(_.map(rowsTable,function(item){
+                        return (item.amount_float);
+                    }), function(memo, num){
+                    return memo + num; },0)
+                    return accounting.formatNumber(quantity,0,'.',',');
+                }
+
+                function TotalFormatter(rowsTable) {
+                    var amount =  _.reduce(_.map(rowsTable,function(item){
+                        return (item.amount_value);
+                    }), function(memo, num){
+                    return memo + num; },0)
+                    return accounting.formatNumber(amount,0,'.',',');
+                }
+
+                function ResidualFormatter(rowsTable) {
+                    var amount =  _.reduce(_.map(rowsTable,function(item){
+                        return (item.residual_value);
+                    }), function(memo, num){
+                    return memo + num; },0)
+                    return accounting.formatNumber(amount,0,'.',',');
+                }
+
+                function footerStyle(row, index) {
+                    return {
+                        css: {
+                            "font-weight": "bold",
+                            <!-- "border": "1px solid", -->
+                        }
+                    };
+                };
+            </script>
+        </div>
+    </t>
+</template>

+ 5 - 0
static/src/xml/eiru_reporting.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+    
+</template>

+ 5 - 0
static/src/xml/eiru_reporting_base.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<template xml:space="preserve">
+    
+</template>

+ 22 - 0
templates.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <template id="eiru_reports_crifin_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+
+                <!-- configuration < main > -->
+                <script type="text/javascript" src="/eiru_reports_crifin/static/src/js/main.js" />
+                <script type="text/javascript" src="/eiru_reports_crifin/static/src/js/reporting_base.js" />
+                <!-- Ranking de Doctores -->
+                <!-- <script type="text/javascript" src="/eiru_reports_crifin/static/src/js/reports/report_doctor_ranking.js"/> -->
+                <script type="text/javascript" src="/eiru_reports_crifin/static/src/js/reports/report_amortization_and_interest.js"/>
+
+            </xpath>
+        </template>
+
+        <record id="eiru_reports_action" model="ir.actions.client">
+            <field name="name">Eiru Reports</field>
+            <field name="tag">eiru_reports_crifin.action_report</field>
+        </record>
+    </data>
+</openerp>

+ 9 - 0
views/actions.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+		<record id="amortization_and_interest_report" model="ir.actions.client">
+            <field name="name">Amortazaciones e Intereses</field>
+            <field name="tag">eiru_reports_crifin.amortization_and_interest_report</field>
+        </record>
+    </data>
+</openerp>

+ 10 - 0
views/menus.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <menuitem id="amortization_and_interest_report"
+            parent="eiru_reports.account_parent_menu"
+            name="Amortizaciones e Intereses"
+            action="amortization_and_interest_report"
+            sequence="10"/>
+    </data>
+</openerp>