Browse Source

eiru_reports_anillos pagos sin primeras cuota

sebas 2 years ago
commit
202c358b69
52 changed files with 5396 additions and 0 deletions
  1. 2 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 22 0
      __openerp__.py
  4. 2 0
      controller/__init__.py
  5. BIN
      controller/__init__.pyc
  6. 48 0
      controller/helpers/__init__.py
  7. BIN
      controller/helpers/__init__.pyc
  8. 76 0
      controller/helpers/account_bank_statement_line.py
  9. BIN
      controller/helpers/account_bank_statement_line.pyc
  10. 516 0
      controller/helpers/account_invoice.py
  11. BIN
      controller/helpers/account_invoice.pyc
  12. 999 0
      controller/helpers/account_invoice_line.py
  13. BIN
      controller/helpers/account_invoice_line.pyc
  14. 15 0
      controller/helpers/account_journal.py
  15. BIN
      controller/helpers/account_journal.pyc
  16. 42 0
      controller/helpers/account_move_line.py
  17. BIN
      controller/helpers/account_move_line.pyc
  18. 26 0
      controller/helpers/account_period.py
  19. BIN
      controller/helpers/account_period.pyc
  20. 297 0
      controller/helpers/account_voucher.py
  21. BIN
      controller/helpers/account_voucher.pyc
  22. 15 0
      controller/helpers/company_logo.py
  23. 79 0
      controller/helpers/pos_order.py
  24. BIN
      controller/helpers/pos_order.pyc
  25. 242 0
      controller/helpers/pos_order_line.py
  26. BIN
      controller/helpers/pos_order_line.pyc
  27. 106 0
      controller/helpers/product_product.py
  28. BIN
      controller/helpers/product_product.pyc
  29. 28 0
      controller/helpers/report_report.py
  30. BIN
      controller/helpers/report_report.pyc
  31. 62 0
      controller/helpers/res_company.py
  32. BIN
      controller/helpers/res_company.pyc
  33. 21 0
      controller/helpers/res_partner.py
  34. BIN
      controller/helpers/res_partner.pyc
  35. 13 0
      controller/helpers/res_store.py
  36. BIN
      controller/helpers/res_store.pyc
  37. 27 0
      controller/helpers/res_users.py
  38. BIN
      controller/helpers/res_users.pyc
  39. 41 0
      controller/main.py
  40. BIN
      controller/main.pyc
  41. BIN
      static/description/icon.png
  42. 148 0
      static/src/css/custom.css
  43. 20 0
      static/src/js/main.js
  44. 1575 0
      static/src/js/pdf_anillos.js
  45. 22 0
      static/src/js/reporting_base.js
  46. 715 0
      static/src/js/reports/report_customer_paymentanillos.js
  47. 178 0
      static/src/reports/report_customer_paymentanillos.xml
  48. 5 0
      static/src/xml/eiru_reporting.xml
  49. 5 0
      static/src/xml/eiru_reporting_base.xml
  50. 23 0
      templates.xml
  51. 13 0
      views/actions.xml
  52. 13 0
      views/menus.xml

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import controller

BIN
__init__.pyc


+ 22 - 0
__openerp__.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Eiru Reports Señor de los Anillos",
+    'author': "Sebastian Penayo",
+    'category': 'Reports',
+    'version': '0.1',
+    'depends': [
+        'base',
+        'account',
+        'eiru_assets',
+        'eiru_reports',
+    ],
+    'qweb': [
+        'static/src/xml/*.xml',
+        'static/src/reports/*.xml'
+    ],
+    'data': [
+        'templates.xml',
+        'views/actions.xml',
+        'views/menus.xml',
+    ],
+}

+ 2 - 0
controller/__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import main

BIN
controller/__init__.pyc


+ 48 - 0
controller/helpers/__init__.py

@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+# REPORT CONFIG
+from report_report import get_report_report
+# from report_category import get_report_category
+# RES USERS
+from res_users import get_res_users
+from res_partner import get_res_partner
+
+# ACCOUNT VOUCHER
+from account_voucher import get_account_voucher_all
+from account_voucher import get_account_voucher_customer
+from account_voucher import get_account_voucher_supplier
+from account_voucher import get_account_voucher_payment
+from account_move_line import get_account_move_line
+
+# ACCOUNT BANK STATEMENT lINE
+from account_bank_statement_line import get_account_bank_statement_line
+
+from res_company import get_res_company
+from res_company import get_company_logo
+from res_store import get_res_store
+from account_journal import get_account_journal
+
+from pos_order import get_pos_order
+from pos_order_line import get_pos_order_line
+from account_period import get_account_period
+
+# PRODUCT
+# from product_category import get_product_category_all
+# from product_category import get_product_category_expense
+# from product_brand import get_product_brand
+# from product_attribute import get_product_attribute
+# from product_attribute_value import get_product_attribute_value
+# from product_product import get_product_product
+
+# ACCOUNT INVOICE
+from account_invoice import get_account_invoice_all_type
+from account_invoice import get_account_invoice_sale_type
+from account_invoice import get_account_invoice_sale_and_refund_type
+from account_invoice import get_account_invoice_purchase_type
+from account_invoice import get_account_invoice_expense_type
+
+# ACCOUNT INVOICE LINE
+from account_invoice_line import get_account_invoice_line_all_type
+from account_invoice_line import get_account_invoice_line_out_invoice
+from account_invoice_line import get_account_invoice_line_out_invoice_and_out_refund
+from account_invoice_line import get_account_invoice_line_in_invoice_purchase
+from account_invoice_line import get_account_invoice_line_in_invoice_expense

BIN
controller/helpers/__init__.pyc


+ 76 - 0
controller/helpers/account_bank_statement_line.py

@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_bank_statement_line():
+    user_store = r.env.user.store_id.id
+
+    validate = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='pos_order')
+    '''
+
+    query = '''
+        SELECT
+        	line.id,
+        	line.name,
+        	statement.journal_id,
+        	line.amount,
+        	CASE
+        		WHEN journal.currency IS NULL
+        		THEN line.amount
+        		ELSE line.amount * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
+        		END AS amount_currency,
+        	journal_rel.store_id,
+        	line.company_id,
+        	journal.name,
+        	partner.name,
+            line.date,
+            line.ref
+            FROM account_bank_statement_line as line
+            LEFT JOIN account_bank_statement as statement
+            ON statement.id = line.statement_id
+            LEFT JOIN res_store_journal_rel AS journal_rel
+            ON statement.journal_id = journal_rel.journal_id
+            LEFT JOIN account_journal AS journal
+            ON journal.id = statement.journal_id
+            LEFT JOIN res_partner AS partner
+            ON partner.id = line.partner_id
+            LEFT JOIN res_currency_rate AS rate
+            ON rate.currency_id = journal.currency
+            WHERE line.pos_statement_id IS NOT NULL
+            GROUP BY
+        		line.id,
+        		statement.journal_id,
+        		journal.currency,
+        		journal_rel.store_id,
+        		journal.name,
+        		partner.name
+    '''
+
+    r.cr.execute(validate)
+    for j in r.cr.fetchall():
+        band = j[0]
+
+    if band == True:
+        company_currency_rate = r.env.user.company_id.currency_id.rate
+        r.cr.execute(query,[company_currency_rate])
+        return [
+            {
+                'id': j[0],
+                'name': j[1],
+                'journal_id': j[2],
+                'amount': j[3],
+                'amount_currency': j[4],
+                'store_id': j[5],
+                'company_id': j[6],
+                'journal_name': j[7],
+                'partner_name': j[8],
+                'date': j[9],
+                'origin': j[10],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        return []

BIN
controller/helpers/account_bank_statement_line.pyc


+ 516 - 0
controller/helpers/account_invoice.py

@@ -0,0 +1,516 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_invoice_all_type():
+    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,
+            partner.name,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            customer.ruc,
+            invoice.supplier_invoice_number
+        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_users AS users
+        ON users.id = invoice.user_id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        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,
+            partner.name,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            customer.ruc,
+            invoice.supplier_invoice_number
+    '''
+
+    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],
+            'user_name':j[9],
+            'customer_name':j[10],
+            'amount_tax':j[11],
+            'state':j[12],
+            'store_id':j[13],
+            'journal_id':j[14],
+            'state':j[15],
+            'customer_ruc':j[16],
+            'supplier_invoice_number':j[17],
+        } for j in r.cr.fetchall()
+    ]
+
+def get_account_invoice_sale_type(): #historico de venta
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    validate_columns = '''
+        SELECT EXISTS (SELECT 1 FROM information_schema.columns
+        WHERE table_name='account_invoice' AND column_name in ('contado','credito'))'''
+
+    query1 = '''
+        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]),
+            invoice.number,
+            partner.name,
+            customer.name,
+            invoice.amount_tax * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            customer.ruc,
+            invoice.supplier_invoice_number
+        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_users AS users
+        ON users.id = invoice.user_id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        AND invoice.type IN ('out_invoice')
+        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,
+            partner.name,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            customer.ruc,
+            invoice.supplier_invoice_number
+    '''
+
+    query2 = '''
+        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]),
+            invoice.number,
+            partner.name,
+            customer.name,
+            invoice.amount_tax * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]),
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            customer.ruc,
+            invoice.supplier_invoice_number,
+            invoice.contado,
+            invoice.credito
+        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_users AS users
+        ON users.id = invoice.user_id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        AND invoice.type IN ('out_invoice')
+        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,
+            partner.name,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            customer.ruc,
+            invoice.supplier_invoice_number
+    '''
+
+    r.cr.execute(validate_columns)
+
+    for j in r.cr.fetchall():
+        column = j[0]
+
+    if column == True:
+        r.cr.execute(query2,(tuple([company_currency_rate,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],
+            'user_name':j[9],
+            'customer_name':j[10],
+            'amount_tax':j[11],
+            'state':j[12],
+            'store_id':j[13],
+            'journal_id':j[14],
+            'state':j[15],
+            'company_id':j[16],
+            'customer_ruc':j[17],
+            'supplier_invoice_number':j[18],
+            'contado':j[19],
+            'credito':j[20],
+        } for j in r.cr.fetchall()]
+    else:
+        r.cr.execute(query1,(tuple([company_currency_rate,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],
+            'user_name':j[9],
+            'customer_name':j[10],
+            'amount_tax':j[11],
+            'state':j[12],
+            'store_id':j[13],
+            'journal_id':j[14],
+            'state':j[15],
+            'company_id':j[16],
+            'customer_ruc':j[17],
+            'supplier_invoice_number':j[18],
+        } for j in r.cr.fetchall()]
+
+def get_account_invoice_sale_and_refund_type():
+    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,
+            partner.name,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id
+        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_users AS users
+        ON users.id = invoice.user_id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        AND invoice.type IN ('out_invoice','out_refund')
+        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,
+            partner.name,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id
+    '''
+
+    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],
+            'user_name':j[9],
+            'customer_name':j[10],
+            'amount_tax':j[11],
+            'state':j[12],
+            'store_id':j[13],
+            'journal_id':j[14],
+            'state':j[15],
+            'company_id':j[16]
+        } for j in r.cr.fetchall()
+    ]
+
+def get_account_invoice_expense_type():
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    origin = '%PO%'
+    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,
+            partner.name,
+            customer.ruc,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            invoice.supplier_invoice_number
+        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_users AS users
+        ON users.id = invoice.user_id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        AND invoice.type IN ('in_invoice')
+        AND (invoice.origin NOT LIKE %s OR invoice.origin IS NULL)
+        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,
+            partner.name,
+            customer.ruc,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            invoice.supplier_invoice_number
+    '''
+    r.cr.execute(query,([company_currency_rate,origin]))
+
+    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],
+            'user_name':j[9],
+            'supplier_ruc':j[10],
+            'supplier_name':j[11],
+            'amount_tax':j[12],
+            'state':j[13],
+            'store_id':j[14],
+            'journal_id':j[15],
+            'state':j[16],
+            'company_id':j[17],
+            'supplier_invoice_number':j[18],
+        } for j in r.cr.fetchall()
+    ]
+
+def get_account_invoice_purchase_type():
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    origin = '%PO%'
+    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,
+            partner.name,
+            customer.ruc,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            invoice.supplier_invoice_number
+        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_users AS users
+        ON users.id = invoice.user_id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = invoice.partner_id
+        WHERE invoice.state NOT IN ('draft', 'cancel')
+        AND invoice.type IN ('in_invoice')
+        AND (invoice.origin LIKE %s OR invoice.origin <> NULL)
+        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,
+            partner.name,
+            customer.ruc,
+            customer.name,
+            invoice.amount_tax,
+            invoice.state,
+            journal.store_id,
+            invoice.journal_id,
+            invoice.state,
+            invoice.company_id,
+            invoice.supplier_invoice_number
+    '''
+    r.cr.execute(query,([company_currency_rate,origin]))
+
+    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],
+            'user_name':j[9],
+            'supplier_ruc':j[10],
+            'supplier_name':j[11],
+            'amount_tax':j[12],
+            'state':j[13],
+            'store_id':j[14],
+            'journal_id':j[15],
+            'state':j[16],
+            'company_id':j[17],
+            'supplier_invoice_number':j[18],
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/account_invoice.pyc


+ 999 - 0
controller/helpers/account_invoice_line.py

@@ -0,0 +1,999 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_invoice_line_all_type():
+    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,
+        	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] AS cost,
+            --line.name,
+            journal.store_id,
+            template.categ_id
+            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')
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id
+    '''
+
+    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],
+            'store_id': j[12],
+            'categ_id': j[13],
+        } for j in r.cr.fetchall()
+    ]
+
+def get_account_invoice_line_out_invoice(): #analisis de venta
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+
+    validate_brand = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='product_brand')
+    '''
+
+    query_with_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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.quantity * (line.price_unit * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) * line.discount)/100))) - (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] AS cost,
+            journal.store_id,
+            template.categ_id,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            template.product_brand_id,
+            brand.name,
+            line.discount,
+            line.name
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_id
+            LEFT JOIN product_brand AS brand
+            ON brand.id = template.product_brand_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,
+            --line.name,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            template.product_brand_id,
+            brand.name,
+            line.name
+    '''
+
+    query_without_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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.quantity * (line.price_unit * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) * line.discount)/100))) - (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] AS cost,
+            journal.store_id,
+            template.categ_id,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            line.discount,
+            line.name
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_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.name,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            line.name
+    '''
+
+    r.cr.execute(validate_brand)
+    for j in r.cr.fetchall():
+        brand = j[0]
+
+    if brand == True:
+        r.cr.execute(query_with_brand,[company_currency_rate,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],
+                'store_id': j[12],
+                'categ_id': j[13],
+                'partner_name': j[14],
+                'partner_ruc': j[15],
+                'product_id': j[16],
+                'company_id': j[17],
+                'journal_id': j[18],
+                'attribute_value_ids': j[19],
+                'attribute_values': j[20],
+                'attribute_ids': j[21],
+                'product_brand_id': j[22],
+                'brand_name': j[23],
+                'discount': j[24],
+                'name': j[25],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        r.cr.execute(query_without_brand,[company_currency_rate,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],
+                'store_id': j[12],
+                'categ_id': j[13],
+                'partner_ruc': j[14],
+                'partner_name': j[15],
+                'product_id': j[16],
+                'company_id': j[17],
+                'journal_id': j[18],
+                'attribute_value_ids': j[19],
+                'attribute_values': j[20],
+                'attribute_ids': j[21],
+                'discount': j[22],
+                'name': j[23],
+            } for j in r.cr.fetchall()
+        ]
+
+def get_account_invoice_line_out_invoice_and_out_refund():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+
+    validate_brand = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='product_brand')
+    '''
+
+    query_with_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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] AS cost,
+            journal.store_id,
+            template.categ_id,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            template.product_brand_id,
+            brand.name,
+            partner.id
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_id
+            LEFT JOIN product_brand AS brand
+            ON brand.id = template.product_brand_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type in ('out_invoice','out_refund')
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            template.product_brand_id,
+            brand.name,
+            partner.id
+    '''
+
+    query_without_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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] AS cost,
+            --line.name
+            journal.store_id,
+            template.categ_id,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            partner.id
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_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,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            partner.id
+    '''
+
+    r.cr.execute(validate_brand)
+    for j in r.cr.fetchall():
+        brand = j[0]
+
+    if brand == True:
+        r.cr.execute(query_with_brand,(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],
+                'store_id': j[12],
+                'categ_id': j[13],
+                'partner_name': j[14],
+                'product_id': j[15],
+                'company_id': j[16],
+                'journal_id': j[17],
+                'attribute_value_ids': j[18],
+                'attribute_values': j[19],
+                'attribute_ids': j[20],
+                'product_brand_id': j[21],
+                'brand_name': j[22],
+                'partner_id': j[23],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        r.cr.execute(query_without_brand,(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],
+                'store_id': j[12],
+                'categ_id': j[13],
+                'partner_name': j[14],
+                'product_id': j[15],
+                'company_id': j[16],
+                'journal_id': j[17],
+                'attribute_value_ids': j[18],
+                'attribute_values': j[19],
+                'attribute_ids': j[20],
+                'partner_id': j[21],
+            } for j in r.cr.fetchall()
+        ]
+
+def get_account_invoice_line_in_invoice_purchase():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    origin = '%PO%'
+
+    validate_brand = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='product_brand')
+    '''
+
+    query_with_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+            invoice.supplier_invoice_number,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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] AS cost,
+            --line.name
+            journal.store_id,
+            template.categ_id,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            template.product_brand_id,
+            brand.name
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_id
+            LEFT JOIN product_brand AS brand
+            ON brand.id = template.product_brand_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type = 'in_invoice'
+            AND invoice.origin LIKE %s
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+            invoice.supplier_invoice_number,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            template.product_brand_id,
+            brand.name
+    '''
+
+    query_without_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+            invoice.supplier_invoice_number,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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] AS cost,
+            --line.name
+            journal.store_id,
+            template.categ_id,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type = 'in_invoice'
+            AND invoice.origin LIKE %s
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+            invoice.supplier_invoice_number,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id
+    '''
+
+    r.cr.execute(validate_brand)
+    for j in r.cr.fetchall():
+        brand = j[0]
+
+    if brand == True:
+        r.cr.execute(query_with_brand,([company_currency_rate,company_currency_rate,company_currency_rate,company_currency_rate,origin]))
+        return [
+            {
+                'invoice_id': j[0],
+                'invoice_line_id': j[1],
+                'number': j[2],
+                'origin': j[3],
+                'supplier_invoice_number': j[4],
+                'date': j[5],
+                'type': j[6],
+                'product_name':j[7],
+                'price_unit':j[8],
+                'quantity':j[9],
+                'subtotal':j[10],
+                'tax': j[11],
+                'cost': j[12],
+                'store_id': j[13],
+                'categ_id': j[14],
+                'partner_ruc': j[15],
+                'partner_name': j[16],
+                'product_id': j[17],
+                'company_id': j[18],
+                'journal_id': j[19],
+                'attribute_value_ids': j[20],
+                'attribute_values': j[21],
+                'attribute_ids': j[22],
+                'product_brand_id': j[23],
+                'brand_name': j[24],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        r.cr.execute(query_without_brand,([company_currency_rate,company_currency_rate,company_currency_rate,company_currency_rate,origin]))
+        return [
+            {
+                'invoice_id': j[0],
+                'invoice_line_id': j[1],
+                'number': j[2],
+                'origin': j[3],
+                'supplier_invoice_number': j[4],
+                'date': j[5],
+                'type': j[6],
+                'product_name':j[7],
+                'price_unit':j[8],
+                'quantity':j[9],
+                'subtotal':j[10],
+                'tax': j[11],
+                'cost': j[12],
+                'store_id': j[13],
+                'categ_id': j[14],
+                'partner_ruc': j[15],
+                'partner_name': j[16],
+                'product_id': j[17],
+                'company_id': j[18],
+                'journal_id': j[19],
+                'attribute_value_ids': j[20],
+                'attribute_values': j[21],
+                'attribute_ids': j[22],
+            } for j in r.cr.fetchall()
+        ]
+
+def get_account_invoice_line_in_invoice_expense():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    origin = '%PO%'
+
+    validate_brand = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='product_brand')
+    '''
+
+    query_with_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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] AS cost,
+            --line.name
+            journal.store_id,
+            template.categ_id,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            template.product_brand_id,
+            brand.name
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_id
+            LEFT JOIN product_brand AS brand
+            ON brand.id = template.product_brand_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type = 'in_invoice'
+            AND (invoice.origin NOT LIKE %s OR invoice.origin IS NULL)
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            template.product_brand_id,
+            brand.name
+    '''
+
+    query_without_brand = '''
+        SELECT
+        	invoice.id AS invoice_id,
+        	line.id AS invoice_line_id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	invoice.type,
+            CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	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] AS cost,
+            --line.name
+            journal.store_id,
+            template.categ_id,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr
+            FROM account_invoice AS invoice
+            LEFT JOIN account_invoice_line AS line
+            ON line.invoice_id = invoice.id
+            --Product
+            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 product_attribute_value_product_product_rel AS attr_rel
+        	ON attr_rel.prod_id = product.id
+        	LEFT JOIN product_attribute_value AS attr_value
+        	ON attr_value.id = attr_rel.att_id
+        	LEFT JOIN product_attribute AS attr
+        	ON attr.id = attr_value.attribute_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
+            LEFT JOIN res_partner AS partner
+            ON partner.id = invoice.partner_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type = 'in_invoice'
+            AND (invoice.origin NOT LIKE %s OR invoice.origin IS NULL)
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            journal.store_id,
+            template.categ_id,
+            product.default_code,
+            partner.ruc,
+            partner.name,
+            product.id,
+            invoice.company_id,
+            invoice.journal_id
+    '''
+
+    r.cr.execute(validate_brand)
+    for j in r.cr.fetchall():
+        brand = j[0]
+
+    if brand == True:
+        r.cr.execute(query_with_brand,([company_currency_rate,company_currency_rate,company_currency_rate,company_currency_rate,origin]))
+        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],
+                'store_id': j[12],
+                'categ_id': j[13],
+                'partner_ruc': j[14],
+                'partner_name': j[15],
+                'product_id': j[16],
+                'company_id': j[17],
+                'journal_id': j[18],
+                'attribute_value_ids': j[19],
+                'attribute_values': j[20],
+                'attribute_ids': j[21],
+                'product_brand_id': j[22],
+                'brand_name': j[23],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        r.cr.execute(query_without_brand,([company_currency_rate,company_currency_rate,company_currency_rate,company_currency_rate,origin]))
+        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],
+                'store_id': j[12],
+                'categ_id': j[13],
+                'partner_ruc': j[14],
+                'partner_name': j[15],
+                'product_id': j[16],
+                'company_id': j[17],
+                'journal_id': j[18],
+                'attribute_value_ids': j[19],
+                'attribute_values': j[20],
+                'attribute_ids': j[21],
+            } for j in r.cr.fetchall()
+        ]

BIN
controller/helpers/account_invoice_line.pyc


+ 15 - 0
controller/helpers/account_journal.py

@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+_MODEL = 'account.journal'
+
+def get_account_journal():
+    return [
+        {
+            'id': journal.id,
+            'name': journal.name,
+            'code': journal.code,
+            'type': journal.type,
+            'store_id': journal.store_ids.id
+        } for journal in r.env[_MODEL].search([])
+    ]

BIN
controller/helpers/account_journal.pyc


+ 42 - 0
controller/helpers/account_move_line.py

@@ -0,0 +1,42 @@
+# -*- 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
+        	move.id,
+        	move_line.id,
+        	account.id,
+            move.name,
+        	move_line.debit,
+        	move_line.credit,
+        	move_line.date_maturity,
+        	move_line.reconcile_ref,
+            account.type,
+            move_line.reconcile_partial_id
+        FROM account_move AS move
+        LEFT JOIN account_move_line AS move_line
+        ON move_line.move_id = move.id
+        LEFT JOIN account_account AS account
+        ON account.id = move_line.account_id
+        ORDER BY move_line.date_maturity
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'move_id': j[0],
+            'move_line_id': j[1],
+            'account_id': j[2],
+            'name': j[3],
+            'debit': j[4],
+            'credit': j[5],
+            'date_maturity': j[6],
+            'reconcile_ref':j[7],
+            'type':j[8],
+            'reconcile_partial_id':j[9],
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/account_move_line.pyc


+ 26 - 0
controller/helpers/account_period.py

@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_period():
+    query = '''
+        SELECT
+            id,
+            name,
+            company_id,
+            date_start,
+            date_stop
+        FROM account_period
+        WHERE special = False
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'company_id': j[2],
+            'date_start': j[3],
+            'date_stop': j[4],
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/account_period.pyc


+ 297 - 0
controller/helpers/account_voucher.py

@@ -0,0 +1,297 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_voucher_all():
+    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
+        WHERE voucher.state = 'posted'
+        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()
+    ]
+
+def get_account_voucher_customer():
+    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,
+            journal_rel.store_id,
+            journal.name,
+            invoice.origin,
+            partner.name,
+            voucher.name,
+            voucher.company_id,
+            move.id
+            --,
+        	--move_line.reconcile_ref
+        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
+        LEFT JOIN res_partner AS partner
+        ON partner.id = voucher.partner_id
+        LEFT JOIN account_move AS move
+        ON move.name = voucher.number
+        --LEFT JOIN account_move_line AS move_line
+        --on move_line.move_id = move.id
+        WHERE voucher.state = 'posted'
+        AND voucher.type = 'receipt'
+        --AND move_line.reconcile_ref IS NOT NULL
+        GROUP BY
+        	voucher.id,
+        	voucher.number,
+        	voucher.type,
+        	voucher.date,
+        	voucher.amount,
+        	journal.name,
+        	journal.currency,
+            journal_rel.store_id,
+            invoice.origin,
+            partner.name,
+            move.id
+            --,
+            --move_line.reconcile_ref
+    '''
+
+    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],
+            'store_id': j[9],
+            'journal_name': j[10],
+            'origin': j[11],
+            'partner_name': j[12],
+            'name': j[13],
+            'company_id': j[14],
+            'move_id': j[15],
+            # 'reconcile_ref': j[16],
+        } for j in r.cr.fetchall()
+    ]
+
+def get_account_voucher_supplier():
+    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,
+            journal_rel.store_id,
+            journal.name,
+            invoice.origin,
+            partner.name,
+            voucher.name,
+            voucher.company_id
+        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
+        LEFT JOIN res_partner AS partner
+        ON partner.id = voucher.partner_id
+        WHERE voucher.state = 'posted'
+        AND voucher.type = 'payment'
+        GROUP BY
+        	voucher.id,
+        	voucher.number,
+        	voucher.type,
+        	voucher.date,
+        	voucher.amount,
+        	journal.name,
+        	journal.currency,
+            journal_rel.store_id,
+            invoice.origin,
+            partner.name
+    '''
+
+    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],
+            'store_id': j[9],
+            'journal_name': j[10],
+            'origin': j[11],
+            'partner_name': j[12],
+            'name': j[13],
+            'company_id': j[14],
+        } for j in r.cr.fetchall()
+    ]
+
+
+def get_account_voucher_payment():
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+    SELECT
+        voucher.id,
+        voucher.number,
+        voucher.type,
+        voucher.date,
+        journal.currency,
+        voucher_line.amount_original,
+        voucher_line.amount,
+        CASE
+            WHEN journal.currency IS NULL
+        	THEN voucher_line.amount
+        	ELSE voucher_line.amount * (%s / (array_agg(rate.rate ORDER BY rate.name DESC))[1])
+        	END AS amount_currency,
+        voucher.journal_id,
+        voucher.reference,
+        journal_rel.store_id,
+        journal.name,
+        partner.name,
+        invoice.number,
+        invoice.residual,
+        voucher.company_id,
+	    move_line.date_maturity,
+        voucher.name,
+        move_line.reconcile_ref
+    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
+    LEFT JOIN res_partner AS partner
+    ON partner.id = voucher.partner_id
+	LEFT JOIN account_voucher_line AS voucher_line
+	ON voucher_line.voucher_id = voucher.id
+    LEFT JOIN account_move_line AS move_line
+    ON move_line.id = voucher_line.move_line_id
+    WHERE voucher.state = 'posted'
+    AND voucher.type = 'receipt'
+    AND move_line.reconcile_ref IS NOT NULL
+    GROUP BY
+        voucher.id,
+        voucher.number,
+        voucher.type,
+        voucher.date,
+        voucher_line.amount_original,
+        voucher_line.amount,
+        journal.name,
+        journal.currency,
+		journal_rel.store_id,
+		invoice.origin,
+		invoice.number,
+        invoice.residual,
+        partner.name,
+	    move_line.date_maturity,
+        voucher.name,
+        move_line.reconcile_ref
+
+    '''
+    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_original': j[5],
+            'amount': j[6],
+            'amount_currency': j[7],
+            'journal_id': j[8],
+            'reference': j[9],
+            'store_id': j[10],
+            'journal_name': j[11],
+            'partner_name': j[12],
+            'invoice_number': j[13],
+            'residual': j[14],
+            'company_id': j[15],
+            'date_maturity': j[16],
+            'name': j[17],
+            'reconcile_ref': j[18],
+
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/account_voucher.pyc


+ 15 - 0
controller/helpers/company_logo.py

@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+_MODEL = 'res.company'
+
+def get_company_logo():
+    # domain = [
+    #     ('expense','=', True)
+    # ]
+    return [
+        {
+            'id': company.id,
+            'logo': company.image_medium,
+        } for company in r.env[_MODEL].search()
+    ]

+ 79 - 0
controller/helpers/pos_order.py

@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_pos_order():
+    user_store = r.env.user.store_id.id
+
+    validate = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='pos_order')
+    '''
+
+    query = '''
+        SELECT
+            pos.create_date,
+            pos.name,
+            pos.partner_id,
+            pos.user_id,
+            SUM(line.price_subtotal_incl) as amount,
+            partner.name,
+            pos.id,
+            salesperson.name,
+            SUM(line.price_subtotal) as untaxed,
+            pos.sale_journal,
+            journal.store_id,
+            pos.company_id,
+            partner.ruc
+        FROM pos_order as pos
+        LEFT JOIN res_store_journal_rel as journal
+        ON journal.journal_id = pos.sale_journal
+        LEFT JOIN pos_order_line AS line
+        ON line.order_id = pos.id
+        LEFT JOIN res_partner AS partner
+        ON partner.id = pos.partner_id
+        LEFT JOIN res_users AS users
+        ON users.id = pos.user_id
+        LEFT JOIN res_partner AS salesperson
+        ON salesperson.id = users.partner_id
+        GROUP BY
+            pos.create_date,
+            pos.partner_id,
+            pos.user_id,
+            pos.name,
+            partner.name,
+            pos.id,
+            salesperson.name,
+            pos.sale_journal,
+            journal.store_id,
+            pos.company_id,
+            partner.ruc
+    '''
+
+    r.cr.execute(validate)
+    for j in r.cr.fetchall():
+        band = j[0]
+
+    if band == True:
+        r.cr.execute(query)
+        return [
+            {
+                'date': j[0],
+                'name': j[1],
+                'customer_id': j[2],
+                'user_id': j[3],
+                'amount': j[4],
+                'customer_name': j[5],
+                'order_id': j[6],
+                'user_name': j[7],
+                'amount_untaxed': j[8],
+                'journal_id': j[9],
+                'store_id': j[10],
+                'company_id': j[11],
+                'customer_ruc': j[12],
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        return []

BIN
controller/helpers/pos_order.pyc


+ 242 - 0
controller/helpers/pos_order_line.py

@@ -0,0 +1,242 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_pos_order_line():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+
+    validate = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='pos_order')
+    '''
+
+    validate_brand = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='product_brand')
+    '''
+
+    query_with_brand = '''
+        SELECT
+        	pos.id,
+        	line.id,
+        	pos.name,
+        	CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	line.price_unit,
+        	line.qty,
+        	line.price_subtotal,
+        	line.price_subtotal_incl - line.price_subtotal AS impuestos,
+        	(array_agg(history.cost ORDER BY history.id DESC))[1] AS cost,
+            history.product_template_id,
+            journal.store_id,
+            pos.date_order,
+            pos.company_id,
+            pos.sale_journal,
+            template.categ_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            template.product_brand_id,
+            brand.name,
+            product.id,
+            customer.ruc,
+            customer.name,
+            customer.id,
+            line.discount
+        FROM pos_order AS pos
+        LEFT JOIN pos_order_line AS line
+        ON pos.id = line.order_id
+        LEFT JOIN res_store_journal_rel as journal
+        ON journal.journal_id = pos.sale_journal
+        LEFT JOIN product_product as product
+        ON product.id = line.product_id
+        LEFT JOIN product_template as template
+        ON template.id = product.product_tmpl_id
+        LEFT JOIN product_attribute_value_product_product_rel AS attr_rel
+        ON attr_rel.prod_id = product.id
+        LEFT JOIN product_attribute_value AS attr_value
+        ON attr_value.id = attr_rel.att_id
+        LEFT JOIN product_attribute AS attr
+        ON attr.id = attr_value.attribute_id
+        LEFT JOIN product_price_history AS history
+        ON history.product_template_id = product.product_tmpl_id
+        LEFT JOIN product_brand AS brand
+        ON brand.id = template.product_brand_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = pos.partner_id
+        WHERE pos.state NOT IN ('draft')
+        GROUP BY
+        	pos.id,
+        	line.id,
+        	pos.name,
+        	product.name_template,
+        	line.price_unit,
+        	line.qty,
+        	line.price_subtotal,
+            history.product_template_id,
+            journal.store_id,
+            pos.date_order,
+            pos.company_id,
+            pos.sale_journal,
+            template.categ_id,
+            product.default_code,
+            template.product_brand_id,
+            brand.name,
+            product.id,
+            customer.ruc,
+            customer.name,
+            customer.id
+    '''
+
+    query_without_brand = '''
+        SELECT
+        	pos.id,
+        	line.id,
+        	pos.name,
+        	CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	line.price_unit,
+        	line.qty,
+        	line.price_subtotal,
+        	line.price_subtotal_incl - line.price_subtotal AS impuestos,
+        	(array_agg(history.cost ORDER BY history.id DESC))[1] AS cost,
+            history.product_template_id,
+            journal.store_id,
+            pos.date_order,
+            pos.company_id,
+            pos.sale_journal,
+            template.categ_id,
+            (array_agg(attr_rel.att_id)) AS attr_rel,
+            (array_agg(attr_value.name)) AS attr_value,
+            (array_agg(attr.id)) AS attr,
+            product.id,
+            customer.ruc,
+            customer.name,
+            customer.id,
+            line.discount
+        FROM pos_order AS pos
+        LEFT JOIN pos_order_line AS line
+        ON pos.id = line.order_id
+        LEFT JOIN res_store_journal_rel as journal
+        ON journal.journal_id = pos.sale_journal
+        LEFT JOIN product_product as product
+        ON product.id = line.product_id
+        LEFT JOIN product_template as template
+        ON template.id = product.product_tmpl_id
+        LEFT JOIN product_attribute_value_product_product_rel AS attr_rel
+        ON attr_rel.prod_id = product.id
+        LEFT JOIN product_attribute_value AS attr_value
+        ON attr_value.id = attr_rel.att_id
+        LEFT JOIN product_attribute AS attr
+        ON attr.id = attr_value.attribute_id
+        LEFT JOIN product_price_history AS history
+        ON history.product_template_id = product.product_tmpl_id
+        LEFT JOIN res_partner AS customer
+        ON customer.id = pos.partner_id
+        WHERE pos.state NOT IN ('draft')
+        GROUP BY
+        	pos.id,
+        	line.id,
+        	pos.name,
+        	product.name_template,
+        	line.price_unit,
+        	line.qty,
+        	line.price_subtotal,
+            history.product_template_id,
+            journal.store_id,
+            pos.date_order,
+            pos.company_id,
+            pos.sale_journal,
+            template.categ_id,
+            product.default_code,
+            product.id,
+            customer.ruc,
+            customer.name,
+            customer.id
+    '''
+
+    r.cr.execute(validate)
+
+    for j in r.cr.fetchall():
+        band = j[0]
+
+    if band == True:
+        r.cr.execute(validate_brand)
+
+        for j in r.cr.fetchall():
+            brand = j[0]
+
+        if brand == True:
+            r.cr.execute(query_with_brand,(tuple([company_currency_rate,company_currency_rate])))
+            return [
+                {
+                    'order_id': j[0],
+                    'order_line_id': j[1],
+                    'name': j[2],
+                    'product_name':j[3],
+                    'price_unit':j[4],
+                    'quantity':j[5],
+                    'subtotal':j[6],
+                    'tax': j[7],
+                    'cost': j[8],
+                    'template_id': j[9],
+                    'store_id': j[10],
+                    'date': j[11],
+                    'company_id': j[12],
+                    'journal_id': j[13],
+                    'categ_id': j[14],
+                    'attribute_value_ids': j[15],
+                    'attribute_values': j[16],
+                    'attribute_ids': j[17],
+                    'product_brand_id': j[18],
+                    'brand_name': j[19],
+                    'product_id': j[20],
+                    'customer_ruc': j[21],
+                    'customer_name': j[22],
+                    'customer_id': j[23],
+                    'discount': j[24],
+                } for j in r.cr.fetchall()
+            ]
+        else:
+            r.cr.execute(query_without_brand,(tuple([company_currency_rate,company_currency_rate])))
+            return [
+                {
+                    'order_id': j[0],
+                    'order_line_id': j[1],
+                    'name': j[2],
+                    'product_name':j[3],
+                    'price_unit':j[4],
+                    'quantity':j[5],
+                    'subtotal':j[6],
+                    'tax': j[7],
+                    'cost': j[8],
+                    'template_id': j[9],
+                    'store_id': j[10],
+                    'date': j[11],
+                    'company_id': j[12],
+                    'journal_id': j[13],
+                    'categ_id': j[14],
+                    'attribute_value_ids': j[15],
+                    'attribute_values': j[16],
+                    'attribute_ids': j[17],
+                    'product_id': j[18],
+                    'customer_ruc': j[19],
+                    'customer_name': j[20],
+                    'customer_id': j[21],
+                    'discount': j[22],
+                } for j in r.cr.fetchall()
+            ]
+    else:
+        return []

BIN
controller/helpers/pos_order_line.pyc


+ 106 - 0
controller/helpers/product_product.py

@@ -0,0 +1,106 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_product_product():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+
+    validate_brand = '''
+        SELECT EXISTS(
+            SELECT table_name
+            FROM information_schema.columns
+            WHERE table_schema='public'
+                AND table_name='product_brand')
+    '''
+
+    query_with_brand = '''
+        SELECT
+        	product.id,
+        	template.categ_id,
+        	CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	(array_agg(attr_rel.att_id)) AS attr_rel,
+        	(array_agg(attr_value.name)) AS attr_value,
+        	(array_agg(attr.id)) AS attr,
+        	template.product_brand_id,
+        	brand.name
+        FROM product_product AS product
+        LEFT JOIN product_template AS template
+        ON template.id = product.product_tmpl_id
+        LEFT JOIN product_attribute_value_product_product_rel AS attr_rel
+        ON attr_rel.prod_id = product.id
+        LEFT JOIN product_attribute_value AS attr_value
+        ON attr_value.id = attr_rel.att_id
+        LEFT JOIN product_attribute AS attr
+        ON attr.id = attr_value.attribute_id
+        LEFT JOIN product_brand AS brand
+        ON brand.id = template.product_brand_id
+        GROUP BY
+        	product.id,
+        	template.categ_id,
+        	product.default_code,
+        	template.product_brand_id,
+        	brand.name
+    '''
+
+    query_without_brand = '''
+        SELECT
+        	product.id,
+        	template.categ_id,
+        	CASE
+        		WHEN product.default_code IS NOT NULL
+        		THEN ('[' || product.default_code || '] ' || product.name_template)
+        		ELSE product.name_template
+        		END AS display_name,
+        	(array_agg(attr_rel.att_id)) AS attr_rel,
+        	(array_agg(attr_value.name)) AS attr_value,
+        	(array_agg(attr.id)) AS attr
+        FROM product_product AS product
+        LEFT JOIN product_template AS template
+        ON template.id = product.product_tmpl_id
+        LEFT JOIN product_attribute_value_product_product_rel AS attr_rel
+        ON attr_rel.prod_id = product.id
+        LEFT JOIN product_attribute_value AS attr_value
+        ON attr_value.id = attr_rel.att_id
+        LEFT JOIN product_attribute AS attr
+        ON attr.id = attr_value.attribute_id
+        GROUP BY
+        	product.id,
+        	template.categ_id,
+        	product.default_code
+    '''
+
+    r.cr.execute(validate_brand)
+
+    for j in r.cr.fetchall():
+        brand = j[0]
+
+    if brand == True:
+        r.cr.execute(query_with_brand,([company_currency_rate]))
+        return [
+            {
+                'product_id': j[0],
+                'categ_id': j[1],
+                'product_name': j[2],
+                'attribute_value_ids':j[3],
+                'attribute_values':j[4],
+                'attribute':j[5],
+                'product_brand_id':j[6],
+                'brand_name': j[7]
+            } for j in r.cr.fetchall()
+        ]
+    else:
+        r.cr.execute(query_without_brand,([company_currency_rate]))
+        return [
+            {
+                'product_id': j[0],
+                'categ_id': j[1],
+                'product_name': j[2],
+                'attribute_value_ids':j[3],
+                'attribute_values':j[4],
+                'attribute':j[5],
+            } for j in r.cr.fetchall()
+        ]

BIN
controller/helpers/product_product.pyc


+ 28 - 0
controller/helpers/report_report.py

@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_report_report():
+    query = '''
+        SELECT
+            report.id,
+            report.name,
+            report.name_template,
+            report.description,
+            report.icon_code,
+            report.category_id
+        FROM report_report AS report
+        ORDER BY report.sequence
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'name': j[1],
+            'name_template': j[2],
+            'description': j[3],
+            'icon_code': j[4],
+            'category_id': j[5],
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/report_report.pyc


+ 62 - 0
controller/helpers/res_company.py

@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+_MODEL = 'res.company'
+
+def get_company_logo():
+    domain = [
+        # ('expense','=', True)
+    ]
+    return [
+        {
+            'id': company.id,
+            'logo': company.logo,
+        } for company in r.env[_MODEL].search(domain)
+    ]
+
+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,
+            store.name AS store,
+            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_store AS store
+        ON store.id = ''' + str(user_store) + '''
+        LEFT JOIN res_partner AS partner
+        ON partner.id = company.partner_id
+        WHERE currency.active = true
+        ORDER BY company.id ASC
+    '''
+
+    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],
+            },
+            'store': j[9],
+            'ruc': j[10],
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/res_company.pyc


+ 21 - 0
controller/helpers/res_partner.py

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

BIN
controller/helpers/res_partner.pyc


+ 13 - 0
controller/helpers/res_store.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+_MODEL = 'res.store'
+
+def get_res_store():
+    return [
+        {
+            'id': store.id,
+            'name': store.name,
+            'company_id': store.company_id.id,
+        } for store in r.env[_MODEL].search([])
+    ]

BIN
controller/helpers/res_store.pyc


+ 27 - 0
controller/helpers/res_users.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_res_users():
+    query = '''
+        SELECT
+            users.id,
+            users.company_id,
+            users.store_id,
+            partner.name
+        FROM res_users AS users
+        LEFT JOIN res_partner AS partner
+        ON partner.id = users.partner_id
+        WHERE users.active = true
+    '''
+
+    r.cr.execute(query)
+
+    return [
+        {
+            'id': j[0],
+            'company_id': j[1],
+            'store_id': j[2],
+            'name': j[3],
+
+        } for j in r.cr.fetchall()
+    ]

BIN
controller/helpers/res_users.pyc


+ 41 - 0
controller/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 ReportController(http.Controller):
+
+
+   # PAGOS DE CLIENTES
+    @http.route('/report-account-voucherrefund-customer-payment', auth='user', methods=['GET', 'POST'])
+    def getCustomerAccountRefundVoucher(self, **kw):
+        return make_gzip_response({
+            'vouchers': hp.get_account_voucher_payment(),
+            'statement_lines': hp.get_account_bank_statement_line(),
+            'move_lines': hp.get_account_move_line(),
+            'invoices': hp.get_account_invoice_sale_and_refund_type(),
+        })

BIN
controller/main.pyc


BIN
static/description/icon.png


+ 148 - 0
static/src/css/custom.css

@@ -0,0 +1,148 @@
+.reporting_page_header {
+    padding-bottom: 9px;
+    margin: 25px 0 35px;
+    border-bottom: 1px solid #eee;
+}
+.range-style {
+    padding-bottom: 9px;
+    border-bottom: 1px solid #eee;
+}
+
+.hover:hover{
+  cursor: grab;
+  cursor: -webkit-grab;
+}
+
+/*
+=============================================
+    FIRST STYLE
+=============================================
+*/
+.panel-first-style {
+    border: 1px solid #bbdefb !important;
+}
+
+.panel-header-first-style {
+    background: #bbdefb !important;
+    text-align: center;
+    font-weight: normal;
+}
+
+/*
+=============================================
+    SECOND STYLE
+=============================================
+*/
+
+.panel-second-style {
+    border: 1px solid #c8e6c9 !important;
+}
+
+.panel-header-second-style {
+    background-color: #c8e6c9 !important;
+    text-align: center;
+    font-weight: bold;
+}
+
+/*
+=============================================
+    THIRD STYLE
+=============================================
+*/
+
+.panel-third-style {
+    border: 1px solid #ffccbc !important;
+}
+
+.panel-header-third-style {
+    background-color: #ffccbc !important;
+    text-align: center;
+    font-weight: bold;
+}
+
+/*
+=============================================
+    BUTTON STYLE
+=============================================
+*/
+
+.myButton{
+    background: #d9534f !important;
+    /* background: #d9534f !important; */
+    /* color: #37474f !important; */
+    color: #fff !important;
+    height: 34px !important;
+    /* border: 1px solid #bdbdbd !important; */
+    /* border: 1px solid #428bca !important; */
+    border: none !important;
+}
+
+.dropdown-menu > li > a {
+    color: #37474f !important;
+}
+
+.dropdown-menu > .active > a {
+    color:#fff !important;
+    background-color: #d9534f !important;
+}
+
+.detail-icon {
+    color: #e57373 !important;
+}
+
+.pagination > .active > a{
+    color:#fff !important;
+    background-color: #d9534f !important;
+    border-color: #d9534f !important;
+}
+
+.filter-style {
+    padding-top: 10px;
+}
+
+.sale-button {
+    color: #fff !important;
+    background: #81c784;
+    border-color: #81c784;
+}
+.sale-button:hover{
+    color: #fff !important;
+    background: #81c784;
+    border-color: #81c784;
+}
+
+.purchase-button {
+    color: #fff !important;
+    background: #ffb74d;
+    border-color: #ffb74d;
+}
+.purchase-button:hover{
+    color: #fff !important;
+    background: #ffb74d;
+    border-color: #ffb74d;
+}
+
+.expense-button {
+    color: #fff !important;
+    background: #e57373;
+    border-color: #e57373;
+}
+.expense-button:hover{
+    color: #fff !important;
+    background: #e57373;
+    border-color: #e57373;
+}
+
+.balance-button {
+    color: #fff !important;
+    background: #0288d1;
+    border-color: #0288d1;
+}
+.balance-button:hover{
+    color: #fff !important;
+    background: #0288d1;
+    border-color: #0288d1;
+}
+.chart-container{
+    width: 100%;
+}

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

@@ -0,0 +1,20 @@
+openerp.eiru_reports_anillos = function(instance) {
+  "use strict";
+
+  var reporting = instance.eiru_reports_anillos;
+
+  reporting_base(instance, reporting);
+
+  try {
+    pdf_anillos(reporting);
+    report_customer_paymentanillos(reporting);
+
+  } catch (e) {
+    // ignorar error
+  }
+
+  //  PAGOS DE CLIENTES Y NOTA DE CREDITO
+  instance.web.client_actions.add('eiru_reports_anillos.customer_paymentanillos_action', 'instance.eiru_reports_anillos.ReportCustomerPaymentAnillosWidget');
+
+
+}

+ 1575 - 0
static/src/js/pdf_anillos.js

@@ -0,0 +1,1575 @@
+function pdf_anillos(reporting) {
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportPdfWidget = reporting.Base.extend({
+      drawPDF: function (getColumns,row,ResCompany,pdf_title,pdf_type,pdf_name,pdf_columnStyles,filter) {
+        var self = this;
+        var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+        var hoy = moment().format('DD/MM/YYYY');
+        var totalPagesExp = "{total_pages_count_string}";
+        var pdfDoc = new jsPDF(pdf_type);
+        var y_position = 15;
+        var y_position2 = 15;
+
+        //LOGO
+        pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
+
+        //FECHA
+        pdfDoc.setFontSize(13);
+        pdfDoc.setFontStyle('normal');
+        pdfDoc.setTextColor(40)
+        pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, 12,hoy);
+
+        //TITULO
+        pdfDoc.setFontSize(15);
+        pdfDoc.setFontStyle('bold');
+        pdfDoc.setTextColor('#0288d1');
+        pdfDoc.autoTableText(pdf_title, pdfDoc.internal.pageSize.getWidth() - 12, 18, {
+          halign: 'right',
+          valign: 'middle'
+        });
+        pdfDoc.setLineWidth(0.5);
+        pdfDoc.setDrawColor('#424242');
+        pdfDoc.line(10, 22, pdfDoc.internal.pageSize.getWidth() - 10 , 22);
+
+        var i=0;
+        if(pdf_type == 'l'){
+          var col1_title = 15;
+          var col1_value = 55;
+          var col2_title = 150;
+          var col2_value = 190;
+        }
+        else{
+          var col1_title = 10;
+          var col1_value = 50;
+          var col2_title = 110;
+          var col2_value = 150;
+        }
+        if(filter.length >0){
+          _.each(filter,function(item){
+            if(i<4){
+              self.addFilter(pdfDoc,item.title,item.value,col1_title,col1_value,y_position);
+              y_position = y_position + 5;
+            }else{
+              self.addFilter(pdfDoc,item.title,item.value,col2_title,col2_value,y_position2);
+              y_position2 = y_position2 + 5;
+            }
+              i++;
+          });
+          pdfDoc.setLineWidth(0.5);
+          pdfDoc.setDrawColor('#424242');
+
+          if(y_position >= y_position2){
+            y_position = y_position;
+            pdfDoc.line(10, y_position, pdfDoc.internal.pageSize.getWidth() - 10 , y_position);
+          }else{
+            y_position = y_position2;
+            pdfDoc.line(10, y_position2, pdfDoc.internal.pageSize.getWidth() - 10 , y_position2);
+          }
+        }
+
+
+        pdfDoc.autoTable(getColumns, row, {
+            // showHeader: 'firstPage',
+            startY: y_position + 5,
+            theme: 'grid',
+            styles: {
+                overflow: 'linebreak',
+                columnWidth: 'auto',
+                fontSize: 7,
+            },
+            headerStyles: {
+                fillColor: [76, 133, 248],
+                fontSize: 9
+            },
+            columnStyles: pdf_columnStyles,
+            margin: { horizontal: 3},
+
+            drawCell: function(cell, opts) {
+                var rows = opts.table.rows;
+                if (opts.row.index == rows.length - 1) {
+                  pdfDoc.setFontStyle('bold');
+                }
+            },
+
+            addPageContent: function (data) {
+
+            //FOOTER
+                var str = "Página " + data.pageCount;
+                if (typeof pdfDoc.putTotalPages === 'function') {
+                    str = str + " de " + totalPagesExp;
+                }
+                pdfDoc.setFontSize(9);
+                pdfDoc.setFontStyle('bold');
+                pdfDoc.setTextColor(40);
+                var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                pdfDoc.autoTableText(str, pdfDoc.internal.pageSize.getWidth() - 35, pageHeight - 5, {
+                  halign: 'rigth',
+                  valign: 'middle'
+                });
+            }
+        });
+        if (typeof pdfDoc.putTotalPages === 'function') {
+            pdfDoc.putTotalPages(totalPagesExp);
+        }
+        row.pop();
+        if(model.printer_bridge){
+            var data = pdfDoc.output('datauristring');
+            model.printer_bridge.print(data);
+            return;
+        }
+        pdfDoc.save(pdf_name + hoy + '.pdf');
+      },
+
+      addFilter: function(pdfDoc,title,value,x_position_title,x_position_value,y_position){
+        pdfDoc.setFontSize(10);
+        pdfDoc.setTextColor('#424242');
+        pdfDoc.setFontStyle('bold');
+        pdfDoc.autoTableText(title+':', x_position_title, y_position, {
+          halign: 'left',
+          valign: 'middle'
+        });
+        pdfDoc.setFontSize(10);
+        pdfDoc.setTextColor('#424242');
+        pdfDoc.setFontStyle('normal');
+        pdfDoc.autoTableText(value, x_position_value, y_position, {
+          halign: 'left',
+          valign: 'middle'
+        });
+      },
+
+        drawStockPDF: function (
+            index,
+            getColumns,
+            row,
+            ResCompany,
+            pdf_title,
+            pdf_type,
+            pdf_name,
+            pdf_columnStyles,
+            current_location) {
+            var self = this;
+            var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF(pdf_type);
+            getColumns.shift();
+            pdfDoc.autoTable(getColumns, row, {
+                theme: 'grid',
+                styles: {
+                    overflow: 'linebreak',
+                    columnWidth: 'auto',
+                    fontSize: 7,
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 8
+                },
+                columnStyles: pdf_columnStyles,
+                margin: { top: 20, horizontal: 7, bottom: 40,},
+
+                drawCell: function(cell, data) {
+                    var rows = data.table.rows;
+                    if (data.row.index == rows.length - 1) {
+                        pdfDoc.setFontStyle('bold');
+                    };
+                },
+
+                addPageContent: function (data) {
+                    pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
+                    if(pdf_type == 'l'){
+                        pdfDoc.setFontSize(12);
+                        pdfDoc.setFontStyle('bold');
+                        pdfDoc.setTextColor(40);
+                        pdfDoc.text(pdf_title,130,10);
+                    }else{
+                        pdfDoc.setFontSize(12);
+                        pdfDoc.setFontStyle('bold');
+                        pdfDoc.setTextColor(40);
+                        pdfDoc.text(pdf_title,80,10);
+                    }
+                    if(current_location.length > 0){
+                        pdfDoc.setFontSize(9);
+                        pdfDoc.setFontStyle('normal');
+                        pdfDoc.setTextColor(40)
+                        pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 54, 18,"Ubicación: " + current_location[0].parent_name);
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('normal');
+                    pdfDoc.setTextColor(40)
+                    pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 55, 14," Fecha de Expedición: " + hoy);
+
+                    /*===========
+                        FOOTER
+                    ===========*/
+                    var str = "Página " + data.pageCount;
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                    pdfDoc.text(str, pdfDoc.internal.pageSize.getWidth() - 55, pageHeight - 5);
+                }
+            });
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            row.pop();
+            if(model.printer_bridge){
+                var data = pdfDoc.output('datauristring');
+                model.printer_bridge.print(data);
+                return;
+            }
+            pdfDoc.save(pdf_name + hoy + '.pdf');
+        },
+
+        drawSaleJournalPDF: function (getColumns,row,ResCompany,pdf_title,pdf_type,pdf_name,pdf_columnStyles,desde,hasta) {
+            var self = this;
+            var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF(pdf_type);
+
+            /*
+            ==============================================
+                PRIMERA COLUMNA
+            ==============================================
+            */
+
+            // Title
+            pdfDoc.setFontSize(15);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(pdf_title,7,10);
+
+            // DEL
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('DEL: ' + desde,7,20);
+
+            // AL
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('AL: ' + hasta ,7,24);
+
+            /*
+            ==============================================
+                SEGUNDA COLUMNA
+            ==============================================
+            */
+
+            // CODIGO DESDE
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Código Desde: ' + 1 ,50,20);
+
+            // CODIGO HASTA
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Código Hasta: ' + (row.length - 1),50,24);
+
+            /*
+            ==============================================
+                QUINTA COLUMNA
+            ==============================================
+            */
+
+            // Empresa
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Empresa: ' + ResCompany.name ,100,20);
+
+            // RUC
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('R.U.C: ' + ResCompany.ruc ,100,24);
+
+            /*
+            ==============================================
+                    CREACION DEL PDF
+            ==============================================
+            */
+
+            pdfDoc.autoTable(getColumns, row, {
+                showHeader: 'false',
+                theme: 'grid',
+
+                drawRow: function (row, data) {
+                    if(pdf_type == "l"){
+                        if (row.index === 0) {
+                             pdfDoc.setTextColor(40);
+                             pdfDoc.setFontSize(8);
+                             pdfDoc.setFontStyle('bold');
+                             // Documento
+                             pdfDoc.rect(data.settings.margin.left, row.y, 75, 8, 'S');
+                             // Clientes
+                             pdfDoc.rect(82, row.y, 70, 8, 'S');
+                             // Total de Ventas
+                             pdfDoc.rect(152, row.y, 140, 8, 'S');
+
+                             pdfDoc.autoTableText("DOCUMENTO", 33, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("CLIENTES", 115, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("TOTAL DE VENTAS", 210, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // NUM
+                             pdfDoc.rect(data.settings.margin.left, row.y + 8, 27, 8, 'S');
+                             pdfDoc.autoTableText("NUM", 22, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // Factura
+                             pdfDoc.rect(34, row.y + 8, 21, 8, 'S');
+                             pdfDoc.autoTableText("N° Factura", 44, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // FECHA
+                             pdfDoc.rect(55, row.y + 8, 27, 8, 'S');
+                             pdfDoc.autoTableText("FECHA", 65, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // RAZON SOCIAL
+                             pdfDoc.rect(82, row.y + 8, 50, 8, 'S');
+                             pdfDoc.autoTableText("RAZON SOCIAL", 105, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // RUC
+                             pdfDoc.rect(132, row.y + 8, 19.87, 8, 'S');
+                             pdfDoc.autoTableText("RUC", 143, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // TASA 5%
+                             pdfDoc.rect(151.9, row.y + 8, 24.32, 8, 'S');
+                             pdfDoc.autoTableText("TASA 5%", 163, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 5%
+                             pdfDoc.rect(151.9, row.y + 8, 24.32, 8, 'S');
+                             pdfDoc.autoTableText("5%", 163, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // TASA 10%
+                             pdfDoc.rect(151.9, row.y + 8, 24.32, 8, 'S');
+                             pdfDoc.autoTableText("TASA 10%", 163, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                              // GRAVADAS 10%
+                             pdfDoc.rect(151.9, row.y + 8, 24.32, 8, 'S');
+                             pdfDoc.autoTableText("10%", 163, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // %
+                             pdfDoc.rect(176.45, row.y + 8, 8.6, 8, 'S');
+                             pdfDoc.autoTableText("%", 179.5, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             //IMPUESTOS
+                             pdfDoc.rect(184.85, row.y + 8, 24, 8, 'S');
+                             pdfDoc.autoTableText("IMPUESTOS", 197, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // EXENTAS
+                             pdfDoc.rect(209, row.y + 8, 21, 8, 'S');
+                             pdfDoc.autoTableText("EXENTAS", 220, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // Ret IVA
+                             pdfDoc.rect(230, row.y + 8, 18, 8, 'S');
+                             pdfDoc.autoTableText("Ret IVA", 238, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // Ret Renta
+                             pdfDoc.rect(248, row.y + 8, 20, 8, 'S');
+                             pdfDoc.autoTableText("Ret RENTA", 258, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // TOTAL
+                             pdfDoc.rect(268, row.y + 8, 24, 8, 'S');
+                             pdfDoc.autoTableText("TOTAL", 279, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             data.cursor.y += 16;
+                         };
+                     }else{
+                         if (row.index === 0) {
+                             pdfDoc.setTextColor(40);
+                             pdfDoc.setFontSize(8);
+                             pdfDoc.setFontStyle('bold');
+                             // Documento
+                             pdfDoc.rect(data.settings.margin.left, row.y, 65, 8, 'S');
+                             // Clientes
+                             pdfDoc.rect(71.9, row.y, 49.1, 8, 'S');
+                             // Total de Ventas
+                             pdfDoc.rect(121.1, row.y, 86.6, 8, 'S');
+                             pdfDoc.autoTableText("DOCUMENTO", 29, row.y + row.height / 2, {
+                                 halign: 'center',
+                             });
+                             pdfDoc.autoTableText(" CLIENTES", 85, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("TOTAL DE VENTAS",167, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // NUM
+                             pdfDoc.setFontSize(6);
+                             pdfDoc.rect(data.settings.margin.left, row.y + 8, 25, 8, 'S');
+                             pdfDoc.autoTableText("NUM", 21, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // factura
+                             pdfDoc.rect(32.15, row.y + 8, 23.7, 8, 'S');
+                             pdfDoc.autoTableText("N° Fact.", 42, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // FECHA
+                             pdfDoc.rect(55.7, row.y + 8, 16.2, 8, 'S');
+                             pdfDoc.autoTableText("FECHA", 65, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                            });
+                             // RAZON SOCIAL
+                             pdfDoc.rect(72, row.y + 8, 32, 8, 'S');
+                             pdfDoc.autoTableText("RAZON SOCIAL", 85, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // RUC
+                             pdfDoc.rect(104.2, row.y + 8, 16.8, 8, 'S');
+                             pdfDoc.autoTableText("RUC", 111, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // TASA 5%
+                             pdfDoc.rect(121.1, row.y + 8, 15.1, 8, 'S');
+                             pdfDoc.autoTableText("TASA 5%", 128, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 5%
+                             pdfDoc.rect(136.1, row.y + 8, 13.05, 8, 'S');
+                             pdfDoc.autoTableText("IVA 5%", 142, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // TASA 10%
+                             pdfDoc.rect(148.7, row.y + 8, 14.55, 8, 'S');
+                             pdfDoc.autoTableText("TASA 10%", 156, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 10%
+                             pdfDoc.rect(163.52, row.y + 8, 12.7, 8, 'S');
+                             pdfDoc.autoTableText("IVA 10%", 170, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // EXENTAS
+                             pdfDoc.rect(176.5, row.y + 8, 14.7, 8, 'S');
+                             pdfDoc.autoTableText("EXENTAS", 183.5, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // %
+/*                             pdfDoc.rect(165.5, row.y + 8, 4.6, 8, 'S');
+                             pdfDoc.autoTableText("%", 171, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+                             // IMPUESTOS
+                         /*    pdfDoc.rect(177, row.y + 8, 15, 7.9, 'S');
+                             pdfDoc.autoTableText("IMPUESTOS", 185, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+
+                             // Ret IVA
+/*                             pdfDoc.rect(177.1, row.y + 8, 6.7, 8, 'S');
+                             pdfDoc.autoTableText("Ret", 179.3, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+                           /*  pdfDoc.autoTableText("IVA", 179.3, row.y + row.height / 2 + 10, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+                             // Ret Renta
+ /*                            pdfDoc.rect(184, row.y + 8, 7.9, 8, 'S');
+                             pdfDoc.autoTableText("Ret", 187.5, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("Renta", 187.5, row.y + row.height / 2 + 10, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             }); */
+                             // TOTAL
+                             pdfDoc.rect(190.9, row.y + 8, 17, 8, 'S');
+                             pdfDoc.autoTableText("TOTAL", 199, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             data.cursor.y += 16;
+                        };
+                    }
+                },
+
+                drawCell: function(cell, data) {
+                    var rows = data.table.rows;
+                    if (data.row.index == rows.length - 1) {
+                        pdfDoc.setFillColor(200, 200, 255);
+                    }
+                },
+
+                styles: {
+                    overflow: 'linebreak',
+                    columnWidth: 'auto',
+                    fontSize: 7,
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 9
+                },
+
+                columnStyles: pdf_columnStyles,
+                margin: { top: 28, horizontal: 7},
+
+                addPageContent: function (data) {
+                    /*===========
+                        FOOTER
+                    ===========*/
+                    var str = "Página " + data.pageCount;
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                    pdfDoc.text(str, pdfDoc.internal.pageSize.getWidth() - 55, pageHeight - 5);
+                }
+            });
+
+            pdfDoc.setFontSize(9);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Listado concluido', 7, pdfDoc.autoTable.previous.finalY + 5);
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            row.pop();
+            if(model.printer_bridge){
+                var data = pdfDoc.output('datauristring');
+                model.printer_bridge.print(data);
+                return;
+            }
+            pdfDoc.save(pdf_name + hoy + '.pdf');
+        },
+
+
+        // ----------------------- purchase libro
+
+        drawPurchaseJournalPDF: function (getColumns,row,ResCompany,pdf_title,pdf_type,pdf_name,pdf_columnStyles,desde,hasta) {
+            var self = this;
+            var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF(pdf_type);
+
+            /*
+            ==============================================
+                PRIMERA COLUMNA
+            ==============================================
+            */
+
+            // Title
+            pdfDoc.setFontSize(15);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(pdf_title,7,10);
+
+            // DEL
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('DEL: ' + desde,7,20);
+
+            // AL
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('AL: ' + hasta ,7,24);
+
+            /*
+            ==============================================
+                SEGUNDA COLUMNA
+            ==============================================
+            */
+
+            // CODIGO DESDE
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Código Desde: ' + 1 ,50,20);
+
+            // CODIGO HASTA
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Código Hasta: ' + (row.length - 1),50,24);
+
+            /*
+            ==============================================
+                QUINTA COLUMNA
+            ==============================================
+            */
+
+            // Empresa
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Empresa: ' + ResCompany.name ,100,20);
+
+            // RUC
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('R.U.C: ' + ResCompany.ruc ,100,24);
+
+            /*
+            ==============================================
+                    CREACION DEL PDF
+            ==============================================
+            */
+
+            pdfDoc.autoTable(getColumns, row, {
+                showHeader: 'false',
+                theme: 'grid',
+
+                drawRow: function (row, data) {
+                    if(pdf_type == "l"){
+                        if (row.index === 0) {
+                             pdfDoc.setTextColor(40);
+                             pdfDoc.setFontSize(8);
+                             pdfDoc.setFontStyle('bold');
+                             // Documento
+                             pdfDoc.rect(data.settings.margin.left, row.y, 75, 8, 'S');
+                             // Clientes
+                             pdfDoc.rect(82, row.y, 70, 8, 'S');
+                             // Total de Ventas
+                             pdfDoc.rect(152, row.y, 140, 8, 'S');
+
+                             pdfDoc.autoTableText("DOCUMENTO", 33, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("PROVEEDORES", 115, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("TOTAL DE COMPRAS", 210, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // NUM
+                             pdfDoc.rect(data.settings.margin.left, row.y + 8, 27, 8, 'S');
+                             pdfDoc.autoTableText("NUM", 22, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // Factura
+                             pdfDoc.rect(34, row.y + 8, 21, 8, 'S');
+                             pdfDoc.autoTableText("N° Factura", 44, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // FECHA
+                             pdfDoc.rect(55, row.y + 8, 27, 8, 'S');
+                             pdfDoc.autoTableText("FECHA", 65, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // RAZON SOCIAL
+                             pdfDoc.rect(82, row.y + 8, 50, 8, 'S');
+                             pdfDoc.autoTableText("RAZON SOCIAL", 105, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // RUC
+                             pdfDoc.rect(132, row.y + 8, 19.87, 8, 'S');
+                             pdfDoc.autoTableText("RUC", 143, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // TASA 5%
+                             pdfDoc.rect(151.1, row.y + 8, 15.1, 8, 'S');
+                             pdfDoc.autoTableText("TASA 5%", 158, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 5%
+                             pdfDoc.rect(166.1, row.y + 8, 13.05, 8, 'S');
+                             pdfDoc.autoTableText("IVA 5%", 172, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // TASA 10%
+                             pdfDoc.rect(178.7, row.y + 8, 14.55, 8, 'S');
+                             pdfDoc.autoTableText("TASA 10%", 186, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 10%
+                             pdfDoc.rect(193.52, row.y + 8, 12.7, 8, 'S');
+                             pdfDoc.autoTableText("IVA 10%", 200, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // EXENTAS
+                             pdfDoc.rect(206.5, row.y + 8, 14.7, 8, 'S');
+                             pdfDoc.autoTableText("EXENTAS", 213.5, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // Ret IVA
+                             pdfDoc.rect(230, row.y + 8, 18, 8, 'S');
+                             pdfDoc.autoTableText("Ret IVA", 238, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // Ret Renta
+                             pdfDoc.rect(248, row.y + 8, 20, 8, 'S');
+                             pdfDoc.autoTableText("Ret RENTA", 258, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // TOTAL
+                             pdfDoc.rect(268, row.y + 8, 24, 8, 'S');
+                             pdfDoc.autoTableText("TOTAL", 279, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             data.cursor.y += 16;
+                         };
+                     }else{
+                         if (row.index === 0) {
+                             pdfDoc.setTextColor(40);
+                             pdfDoc.setFontSize(8);
+                             pdfDoc.setFontStyle('bold');
+                             // Documento
+                             pdfDoc.rect(data.settings.margin.left, row.y, 65, 8, 'S');
+                             // Clientes
+                             pdfDoc.rect(71.9, row.y, 49.1, 8, 'S');
+                             // Total de Ventas
+                             pdfDoc.rect(121.1, row.y, 86.6, 8, 'S');
+                             pdfDoc.autoTableText("DOCUMENTO", 29, row.y + row.height / 2, {
+                                 halign: 'center',
+                             });
+                             pdfDoc.autoTableText("PROVEEDORES", 85, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("TOTAL DE COMPRAS",167, row.y + row.height / 2, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // NUM
+                             pdfDoc.setFontSize(6);
+                             pdfDoc.rect(data.settings.margin.left, row.y + 8, 25, 8, 'S');
+                             pdfDoc.autoTableText("NUM", 21, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // factura
+                             pdfDoc.rect(32.15, row.y + 8, 23.7, 8, 'S');
+                             pdfDoc.autoTableText("N° Fact.", 42, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // FECHA
+                             pdfDoc.rect(55.7, row.y + 8, 16.2, 8, 'S');
+                             pdfDoc.autoTableText("FECHA", 65, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                            });
+                             // RAZON SOCIAL
+                             pdfDoc.rect(72, row.y + 8, 32, 8, 'S');
+                             pdfDoc.autoTableText("RAZON SOCIAL", 85, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // RUC
+                             pdfDoc.rect(104.2, row.y + 8, 16.8, 8, 'S');
+                             pdfDoc.autoTableText("RUC", 111, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // TASA 5%
+                             pdfDoc.rect(121.1, row.y + 8, 15.1, 8, 'S');
+                             pdfDoc.autoTableText("TASA 5%", 128, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 5%
+                             pdfDoc.rect(136.1, row.y + 8, 13.05, 8, 'S');
+                             pdfDoc.autoTableText("IVA 5%", 142, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // TASA 10%
+                             pdfDoc.rect(148.7, row.y + 8, 14.55, 8, 'S');
+                             pdfDoc.autoTableText("TASA 10%", 156, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // GRAVADAS 10%
+                             pdfDoc.rect(163.52, row.y + 8, 12.7, 8, 'S');
+                             pdfDoc.autoTableText("IVA 10%", 170, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                            // EXENTAS
+                             pdfDoc.rect(176.5, row.y + 8, 14.7, 8, 'S');
+                             pdfDoc.autoTableText("EXENTAS", 183.5, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             // %
+/*                             pdfDoc.rect(165.5, row.y + 8, 4.6, 8, 'S');
+                             pdfDoc.autoTableText("%", 171, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+                             // IMPUESTOS
+                         /*    pdfDoc.rect(177, row.y + 8, 15, 7.9, 'S');
+                             pdfDoc.autoTableText("IMPUESTOS", 185, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+
+                             // Ret IVA
+/*                             pdfDoc.rect(177.1, row.y + 8, 6.7, 8, 'S');
+                             pdfDoc.autoTableText("Ret", 179.3, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+                           /*  pdfDoc.autoTableText("IVA", 179.3, row.y + row.height / 2 + 10, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });*/
+                             // Ret Renta
+ /*                            pdfDoc.rect(184, row.y + 8, 7.9, 8, 'S');
+                             pdfDoc.autoTableText("Ret", 187.5, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             pdfDoc.autoTableText("Renta", 187.5, row.y + row.height / 2 + 10, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             }); */
+                             // TOTAL
+                            pdfDoc.rect(190.9, row.y + 8, 17, 8, 'S');
+                             pdfDoc.autoTableText("TOTAL", 199, row.y + row.height / 2 + 8, {
+                                 halign: 'center',
+                                 valign: 'middle'
+                             });
+                             data.cursor.y += 16;
+                        };
+                    }
+                },
+
+                drawCell: function(cell, data) {
+                    var rows = data.table.rows;
+                    if (data.row.index == rows.length - 1) {
+                        pdfDoc.setFillColor(200, 200, 255);
+                    }
+                },
+
+                styles: {
+                    overflow: 'linebreak',
+                    columnWidth: 'auto',
+                    fontSize: 7,
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 9
+                },
+
+                columnStyles: pdf_columnStyles,
+                margin: { top: 28, horizontal: 7},
+
+                addPageContent: function (data) {
+                    /*===========
+                        FOOTER
+                    ===========*/
+                    var str = "Página " + data.pageCount;
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                    pdfDoc.text(str, pdfDoc.internal.pageSize.getWidth() - 55, pageHeight - 5);
+                }
+            });
+
+            pdfDoc.setFontSize(9);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text('Listado concluido', 7, pdfDoc.autoTable.previous.finalY + 5);
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            row.pop();
+            if(model.printer_bridge){
+                var data = pdfDoc.output('datauristring');
+                model.printer_bridge.print(data);
+                return;
+            }
+            pdfDoc.save(pdf_name + hoy + '.pdf');
+        },
+
+
+        // ---------------------- fin purchase libro
+
+        drawWithDetails: function (getColumns,row,ResCompany,pdf_title,pdf_type,pdf_name,pdf_columnStyles,amount) {
+            var self = this;
+            var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF(pdf_type);
+            var title = [];
+            title.push({
+                title : 'Metodo de Pago',
+                dataKey: 'name',
+                align: 'left',
+            });
+            title.push({
+                title : 'Monto',
+                dataKey: 'amount',
+                align: 'right',
+            });
+            var i = 0;
+            var position = 25;
+            _.each(row, function(item){
+                var docItem = [];
+                if(item.info != 'undefined'){
+                    _.each(item.info, function(index){
+                        docItem.push({
+                            name: index.journal,
+                            amount: index.amount_total
+                        });
+                    });
+                };
+                docItem.push({
+                    name: 'Total',
+                    amount: item.amount_total
+                });
+
+                if(row.length <= 2 & row.length == i+1){
+                    return false;
+                };
+
+                if(i > 0){
+                    let first = pdfDoc.autoTable.previous;
+                    position = first.finalY + 7;
+                    pdfDoc.rect(7, position - 7, 196, 10, 'S');
+                };
+                pdfDoc.setFontSize(10);
+                pdfDoc.autoTableText(item.store, 102, position - 3, {
+                    halign: 'center',
+                    valign: 'middle'
+                });
+                pdfDoc.autoTable(title, docItem, {
+                    showHeader: false,
+                    startY: position,
+                    theme: 'grid',
+                    styles: {
+                        overflow: 'linebreak',
+                        columnWidth: 'auto',
+                        fontSize: 7,
+                    },
+                    headerStyles: {
+                        fillColor: [76, 133, 248],
+                        fontSize: 9
+                    },
+                    columnStyles: {
+                        name:{halign:'left'},
+                        amount:{columnWidth: 50, halign:'right'},
+                    },
+                    margin: { horizontal: 7},
+                    drawCell: function(cell, data) {
+                        var rows = data.table.rows;
+                        if (data.row.index == rows.length - 1) {
+                            pdfDoc.setFontStyle('bold');
+                        }
+                    },
+                    addPageContent: function (data) {
+                        if(i == 0){
+                            pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
+                            if(pdf_type == 'l'){
+                                pdfDoc.setFontSize(12);
+                                pdfDoc.setFontStyle('bold');
+                                pdfDoc.setTextColor(40);
+                                pdfDoc.text(pdf_title,130,10);
+                            }else{
+                                pdfDoc.setFontSize(12);
+                                pdfDoc.setFontStyle('bold');
+                                pdfDoc.setTextColor(40);
+                                pdfDoc.text(pdf_title,80,10);
+                            }
+                            pdfDoc.setFontSize(9);
+                            pdfDoc.setFontStyle('normal');
+                            pdfDoc.setTextColor(40)
+                            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 55, 14," Fecha de Expedición: " + hoy);
+
+                            /*===========
+                                FOOTER
+                            ===========*/
+                            var str = "Página " + data.pageCount;
+                            if (typeof pdfDoc.putTotalPages === 'function') {
+                                str = str + " de " + totalPagesExp;
+                            }
+                            pdfDoc.setFontSize(9);
+                            pdfDoc.setFontStyle('bold');
+                            pdfDoc.setTextColor(40);
+                            var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                            pdfDoc.text(str, pdfDoc.internal.pageSize.getWidth() - 55, pageHeight - 5);
+                        }
+                    }
+                });
+                i++;
+            });
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+            // row.pop();
+            if(model.printer_bridge){
+                var data = pdfDoc.output('datauristring');
+                model.printer_bridge.print(data);
+                return;
+            }
+            pdfDoc.save(pdf_name + hoy + '.pdf');
+        },
+
+        drawProfitAndLossPDF: function (
+            getColumns,
+            row,
+            ResCompany,
+            pdf_title,
+            pdf_type,
+            pdf_name,
+            amount
+            ) {
+            var self = this;
+            var sale = [];
+            var expense = [];
+            var column = [];
+            var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+            var hoy = moment().format('DD/MM/YYYY');
+            var totalPagesExp = "{total_pages_count_string}";
+            var pdfDoc = new jsPDF(pdf_type);
+
+            /*
+            ============================
+                VENTAS
+            ============================
+            */
+            var coste = 0;
+            var profit = 0;
+            _.each(row, function(item){
+                if(item.type == 'sale'){
+                    sale.push({
+                        name : item.store,
+                        total : item.amount_total,
+                    });
+                };
+                if(item.expense == true){
+                    coste = item.amount_total;
+                };
+                if(item.profit == true){
+                    profit = item.amount_total;
+                };
+                if(item.expense_detail == true){
+                    expense.push({
+                        name : item.store,
+                        total : item.amount_total,
+                    });
+                };
+            });
+            column.push({
+                title : 'Name',
+                dataKey: 'name',
+                align: 'left',
+            });
+            column.push({
+                title : 'total',
+                dataKey: 'total',
+                align: 'right',
+            });
+
+            /*
+            ==============================
+                LOGO
+            ==============================
+            */
+            pdfDoc.addImage(base64Img, 'png', 10, 10, 0, 20);
+            /*
+            ==============================
+                FECHA
+            ==============================
+            */
+            pdfDoc.setFontSize(13);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40)
+            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 32, 12,hoy);
+            /*
+            ==============================
+                TITULO
+            ==============================
+            */
+            pdfDoc.setFontSize(15);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#0288d1');
+            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 75, 18, pdf_title);
+            /*
+            ==============================
+                DESCRIPCION
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#424242');
+            pdfDoc.text(10, 38, 'Descripción');
+            /*
+            ==============================
+                LINEA
+            ==============================
+            */
+            pdfDoc.setLineWidth(0.5);
+            pdfDoc.setDrawColor('#424242');
+            pdfDoc.line(10, 40, pdfDoc.internal.pageSize.getWidth() - 10 , 40);
+            /*
+            ==============================
+                VENTAS
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#424242');
+            pdfDoc.text(10, 45, 'VENTAS');
+
+            /*
+            ==============================
+                PRIMERA TABLA
+            ==============================
+            */
+            pdfDoc.autoTable(column, sale, {
+                showHeader: false,
+                theme: 'plain',
+                styles: {
+                    overflow: 'linebreak',
+                    columnWidth: 'auto',
+                    fontSize: 9,
+                },
+                columnStyles: {
+                    amount:{halign:'left'},
+                    total:{columnWidth: 50, halign:'right'},
+                },
+                margin: { top: 48, horizontal: 20},
+                drawCell: function(cell, data) {
+                    var rows = data.table.rows;
+                    if (data.row.index == rows.length - 1) {
+                        pdfDoc.setTextColor('#0288d1');
+                        pdfDoc.setFontStyle('bold');
+                    };
+                },
+            });
+            /*
+            ==============================
+                LINEA
+            ==============================
+            */
+            pdfDoc.setLineWidth(0.5);
+            pdfDoc.setDrawColor('#424242');
+            pdfDoc.line(10, pdfDoc.autoTable.previous.finalY + 1, pdfDoc.internal.pageSize.getWidth() - 10 , pdfDoc.autoTable.previous.finalY + 1);
+            /*
+            ==============================
+                COSTE DE VENTAS
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#424242');
+            pdfDoc.text(10, pdfDoc.autoTable.previous.finalY + 7, 'Coste de ventas');
+            /*
+            ==============================
+                COSTE DE VENTAS - valor
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#424242');
+            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, pdfDoc.autoTable.previous.finalY + 7, coste);
+            /*
+            ==============================
+                LINEA
+            ==============================
+            */
+            pdfDoc.setLineWidth(0.5);
+            pdfDoc.setDrawColor('#424242');
+            pdfDoc.line(10, pdfDoc.autoTable.previous.finalY + 10, pdfDoc.internal.pageSize.getWidth() - 10 , pdfDoc.autoTable.previous.finalY + 10);
+            /*
+            ==============================
+                BENEFICIO
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(10, pdfDoc.autoTable.previous.finalY + 15, 'BENEFICIO BRUTO');
+            /*
+            ==============================
+                BENEFICIO - valor
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#0288d1');
+            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, pdfDoc.autoTable.previous.finalY + 15, profit);
+            /*
+            ==============================
+                SEGUNDA TABLA
+            ==============================
+            */
+            var dynamic_top = pdfDoc.autoTable.previous.finalY + 25;
+            pdfDoc.autoTable(column, expense, {
+                showHeader: false,
+                theme: 'plain',
+                styles: {
+                    overflow: 'linebreak',
+                    columnWidth: 'auto',
+                    fontSize: 9,
+                },
+                columnStyles: {
+                    amount:{halign:'left'},
+                    total:{columnWidth: 50, halign:'right'},
+                },
+                startY: pdfDoc.autoTable.previous.finalY + 25,
+                margin: {
+                    horizontal: 20
+                },
+                drawCell: function(cell, data) {
+                    var rows = data.table.rows;
+                    if (data.row.index == rows.length - 1) {
+                        pdfDoc.setTextColor('#0288d1');
+                        pdfDoc.setFontStyle('bold');
+                    };
+                },
+                addPageContent: function (data) {
+                    /*===========
+                        FOOTER
+                    ===========*/
+                    var str = "Página " + data.pageCount;
+                    if (typeof pdfDoc.putTotalPages === 'function') {
+                        str = str + " de " + totalPagesExp;
+                    }
+                    pdfDoc.setFontSize(9);
+                    pdfDoc.setFontStyle('bold');
+                    pdfDoc.setTextColor(40);
+                    var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                    pdfDoc.text(str, pdfDoc.internal.pageSize.getWidth() - 55, pageHeight - 5);
+                },
+            });
+
+            /*
+            ==============================
+                LINEA
+            ==============================
+            */
+            pdfDoc.setLineWidth(0.5);
+            pdfDoc.setDrawColor('#424242');
+            pdfDoc.line(10, pdfDoc.autoTable.previous.finalY + 10, pdfDoc.internal.pageSize.getWidth() - 10 , pdfDoc.autoTable.previous.finalY + 10);
+            /*
+            ==============================
+                RESULTADO
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(10, pdfDoc.autoTable.previous.finalY + 15, 'RESULTADO');
+            /*
+            ==============================
+                VALOR FINAL
+            ==============================
+            */
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor('#0288d1');
+            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, pdfDoc.autoTable.previous.finalY + 15, amount);
+
+            if (typeof pdfDoc.putTotalPages === 'function') {
+                pdfDoc.putTotalPages(totalPagesExp);
+            }
+
+            if(model.printer_bridge){
+                var data = pdfDoc.output('datauristring');
+                model.printer_bridge.print(data);
+                return;
+            };
+            pdfDoc.save(pdf_name + hoy + '.pdf');
+        },
+
+        getPDFFileButton: function  () {
+            var canvas = $(".reporting-chart").get(0);
+            var dataURL = canvas.toDataURL();
+            var pdf = new jsPDF();
+            pdf.addImage(dataURL, 'JPEG', 10, 10, 190, 70);
+            pdf.save("chart.pdf");
+        },
+
+        // pdf resumen de ventas diarias cod:3
+        drawPdf3: function (row,ResCompany,pdf_title,pdf_type,pdf_name,pdf_columnStyles,filter) {
+          var self = this;
+          var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+          var hoy = moment().format('DD/MM/YYYY');
+          var totalPagesExp = "{total_pages_count_string}";
+          var pdfDoc = new jsPDF(pdf_type);
+          var title = [];
+          var currentpage = 0;
+          var i = 0;
+          var position = 27;
+          var y_position2 = 27;
+
+          title.push({
+            title : 'Fecha',
+            dataKey: 'date',
+            align: 'center',
+          });
+          title.push({
+            title : 'Sucursal',
+            dataKey: 'store',
+            align: 'center',
+          });
+          title.push({
+            title : 'Cantidad',
+            dataKey: 'qty',
+            align: 'center',
+          });
+          title.push({
+            title : 'Monto de Venta',
+            dataKey: 'price',
+            align: 'right',
+          });
+          title.push({
+            title : 'Promedio de Venta Total',
+            dataKey: 'average',
+            align: 'right',
+          });
+
+          //LOGO
+          pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
+
+          //FECHA
+          pdfDoc.setFontSize(13);
+          pdfDoc.setFontStyle('normal');
+          pdfDoc.setTextColor(40)
+          pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, 12,hoy);
+
+          //TITULO
+          pdfDoc.setFontSize(15);
+          pdfDoc.setFontStyle('bold');
+          pdfDoc.setTextColor('#0288d1');
+          pdfDoc.autoTableText(pdf_title, pdfDoc.internal.pageSize.getWidth() - 12, 18, {
+            halign: 'right',
+            valign: 'middle'
+          });
+          pdfDoc.setLineWidth(0.5);
+          pdfDoc.setDrawColor('#424242');
+          pdfDoc.line(10, 22, pdfDoc.internal.pageSize.getWidth() - 10 , 22);
+
+          var ii=0;
+          if(pdf_type == 'l'){
+            var col1_title = 15;
+            var col1_value = 55;
+            var col2_title = 150;
+            var col2_value = 190;
+          }
+          else{
+            var col1_title = 10;
+            var col1_value = 50;
+            var col2_title = 110;
+            var col2_value = 150;
+          }
+          if(filter.length >0){
+            _.each(filter,function(item){
+              if(ii<4){
+                self.addFilter(pdfDoc,item.title,item.value,col1_title,col1_value,position);
+                position = position + 5;
+              }else{
+                self.addFilter(pdfDoc,item.title,item.value,col2_title,col2_value,y_position2);
+                y_position2 = y_position2 + 5;
+              }
+                ii++;
+            });
+            pdfDoc.setLineWidth(0.5);
+            pdfDoc.setDrawColor('#424242');
+
+            if(position >= y_position2){
+              position = position;
+              pdfDoc.line(10, position, pdfDoc.internal.pageSize.getWidth() - 10 , position);
+            }else{
+              position = y_position2;
+              pdfDoc.line(10, y_position2, pdfDoc.internal.pageSize.getWidth() - 10 , y_position2);
+            }
+          }
+
+          _.each(row, function(item){
+            if(i > 0){
+              let first = pdfDoc.autoTable.previous;
+              position = first.finalY + 5;
+            };
+
+            var docItem = [];
+            if(item.info != 'undefined'){
+              _.each(item.info, function(index){
+                docItem.push({
+                  date: index.date,
+                  store: index.store,
+                  qty: index.qty,
+                  price: index.price,
+                  average: index.average,
+                })
+              });
+            }
+
+            pdfDoc.setDrawColor(0);
+            pdfDoc.setFillColor(76, 133, 248);
+            pdfDoc.rect(7, position+5, 196, 8, 'F');
+
+            pdfDoc.setFontSize(9);
+            pdfDoc.setTextColor(255,255,255)
+            pdfDoc.setFontStyle('bold');
+
+            pdfDoc.autoTableText('Vendedor: ', 15, position+9, {
+              halign: 'left',
+              valign: 'middle'
+            });
+
+            pdfDoc.autoTableText(item.user, 33, position+9, {
+              halign: 'left',
+              valign: 'middle'
+            });
+
+            pdfDoc.autoTableText('Cantidad: ', 110, position+9, {
+              halign: 'left',
+              valign: 'middle'
+            });
+
+            pdfDoc.autoTableText(item.qty, 126, position+9, {
+              halign: 'left',
+              valign: 'middle'
+            });
+
+            pdfDoc.autoTableText('Monto Total: ', 145, position+9, {
+              halign: 'left',
+              valign: 'middle'
+            });
+
+            pdfDoc.autoTableText(item.price, 165, position+9, {
+              halign: 'left',
+              valign: 'middle'
+            });
+
+            pdfDoc.autoTable(title, docItem, {
+              //  showHeader: false,
+              startY: position+15,
+              theme: 'grid',
+              styles: {
+                overflow: 'linebreak',
+                fontSize: 8,
+                margin: 50,
+                lineWidth: 0.3,
+                lineColor: [132,132,132]
+              },
+              headerStyles: {
+                fillColor: [255,255,255],
+                fontSize: 9,
+                textColor: [0,0,0],
+                lineWidth: 0.3,
+                lineColor: [132,132,132]
+              },
+              columnStyles: pdf_columnStyles,
+              margin: 'auto',
+              tableWidth: 'auto',
+
+              addPageContent: function (data) {
+                // FOOTER
+                if (currentpage < pdfDoc.internal.getNumberOfPages()) {
+                  var str = "Página " + pdfDoc.internal.getNumberOfPages();
+                  str = str + " de " + totalPagesExp;
+                  pdfDoc.setFontSize(9);
+                  pdfDoc.setFontStyle('bold');
+                  pdfDoc.setTextColor(40);
+                  var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+                  pdfDoc.text(str, pdfDoc.internal.pageSize.getWidth() - 55, pageHeight - 5);
+                  currentpage = pdfDoc.internal.getNumberOfPages();
+                }
+              }
+            });
+            i++;
+          });
+          if (typeof pdfDoc.putTotalPages === 'function') {
+            pdfDoc.putTotalPages(totalPagesExp);
+          }
+          row.pop();
+          if(model.printer_bridge){
+            var data = pdfDoc.output('datauristring');
+            model.printer_bridge.print(data);
+            return;
+          }
+          pdfDoc.save(pdf_name + hoy + '.pdf');
+        },
+        //end cod:3
+
+    });
+}

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

+ 715 - 0
static/src/js/reports/report_customer_paymentanillos.js

@@ -0,0 +1,715 @@
+function report_customer_paymentanillos(reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportCustomerPaymentAnillosWidget = reporting.Base.extend({
+        template: 'ReportCustomerPaymentAnillos',
+        rowsData :[],
+        content :[],
+        modules: ['point_of_sale'],
+
+        events:{
+            'click #generate' : 'fetchGenerate',
+            'change #current-company' : 'updateSelections',
+            'change #current-store' : 'updateJournalSelections',
+            'change #current-date' : 'ShowDateRange',
+            'click .print-report':'clickOnAction',
+        },
+
+        init : function(parent){
+            this._super(parent);
+        },
+
+        start: function () {
+            var table = this.$el.find('#table');
+            table.bootstrapTable({data : self.rowsData});
+            var date = new model.eiru_reports.ReportDatePickerWidget(self);
+            date.fecthFecha();
+            this.fetchInitial();
+        },
+
+        checkModel : function(model){
+            var self = this;
+            return _.filter(self.IrModuleModule,function(item){
+                return item.name === model;
+            });
+        },
+
+        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.fetchIntialSQL().then(function (IntialSQL) {
+                return IntialSQL;
+            }).then(function(IntialSQL) {
+                /*
+                =================================
+                    RES COMPANY
+                =================================
+                */
+                self.ResCompany = IntialSQL.companies;
+                self.CompanyLogo = IntialSQL.logo;
+                if(self.ResCompany.length > 1){
+                    self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
+                    _.each(self.ResCompany,function(item){
+                        self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.company').css('display','none');
+                }
+                /*
+                =================================
+                    RES STORE
+                =================================
+                */
+                self.ResStore = IntialSQL.stores;
+                if(self.ResStore.length > 1){
+                    self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                    _.each(self.ResStore,function(item){
+                        self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.store').css('display','none');
+                }
+                /*
+                =================================
+                    ACCOUNT JOURNAL
+                =================================
+                */
+                self.AccountJournal = IntialSQL.journals;
+                var journal = _.flatten(_.filter(self.AccountJournal,function (item) {
+                    return item.type == 'cash' || item.type == 'bank';
+                }));
+                if(journal.length > 1){
+                    self.$el.find('#current-journal').append('<option value="9999999">Todos los métodos de pago</option>');
+                    _.each(journal,function(item){
+                        self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    });
+                }else{
+                    self.$el.find('.journal').css('display','none');
+                }
+                return self.fethIrModuleModule();
+            }).then(function(IrModuleModule) {
+                self.IrModuleModule = IrModuleModule;
+                return self.fethCheckType();
+            });
+            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'
+                }
+            });
+            this.fetchDataSQL().then(function(DataSQL) {
+                return DataSQL;
+            }).then(function (DataSQL) {
+                self.AccountVoucher = DataSQL.vouchers;
+                self.AccountBankStatementLine = DataSQL.statement_lines;
+                self.AccountMoveLine = DataSQL.move_lines;
+                self.AccountInvoice = DataSQL.invoices;
+                return self.BuildTable();
+            });
+        },
+
+        fetchIntialSQL: function() {
+            var self = this;
+            var data = $.get('/report-filter-data');
+            return data;
+        },
+
+        fetchDataSQL: function() {
+            var self = this;
+            var data = $.get('/report-account-voucherrefund-customer-payment');
+            return data;
+        },
+
+        fethIrModuleModule: function(){
+            var self = this;
+            var defer = $.Deferred();
+            var fields = ['name','id'];
+            var domain=[['state','=','installed'],['name','in',self.modules]];
+            var IrModuleModule = new model.web.Model('ir.module.module');
+            IrModuleModule.query(fields).filter(domain).all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        /*=====================================================================
+            Check type
+        =====================================================================*/
+        fethCheckType: function(){
+            var self = this;
+            var modules = self.checkModel('point_of_sale');
+            if(modules.length == 0){
+                self.$el.find('.type').css('display','none');
+            }
+        },
+
+        /*====================================================================
+            UPDATE SELECTIONS
+        ====================================================================*/
+        updateSelections: function () {
+            var self = this;
+            var store;
+            var company = self.$el.find('#current-company').val();
+            if(company != 9999999){
+                store = self.$el.find('#current-store').empty();
+                self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                _.each(self.ResStore,function(item){
+                    if(parseFloat(company) == item.company_id[0]){
+                        self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    }
+                });
+            }else{
+                store = self.$el.find('#current-store').empty();
+                self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
+                _.each(self.ResStore,function(item){
+                    self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+            }
+        },
+
+        updateJournalSelections: function () {
+            var self = this;
+            var journal;
+            var AccountJournal = _.flatten(_.filter(self.AccountJournal,function (item) {
+                return item.type == 'cash' || item.type == 'bank';
+            }));
+            var store = self.$el.find('#current-store').val();
+            if(store != 9999999){
+                self.$el.find('#current-journal').empty();
+                self.$el.find('#current-journal').append('<option value="9999999">Todos los métodos de pago</option>');
+                _.each(AccountJournal,function(item){
+                    if(item.store_id == store){
+                        self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                    }
+                });
+            }else{
+                journal = self.$el.find('#current-journal').empty();
+                self.$el.find('#current-journal').append('<option value="9999999">Todos los métodos de pago</option>');
+                _.each(AccountJournal,function(item){
+                    self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
+                });
+            }
+        },
+
+        getAccountBankStatementLine:function() {
+            var self = this;
+            var content = self.AccountBankStatementLine;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var journal = self.$el.find('#current-journal').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            if((store && store == 9999999)||(company && company == 9999999)){
+                var store_ids = _.flatten(_.map(self.ResStore, function (item) {
+                    return item.id;
+                }));
+                var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
+                    return item.id;
+                }));
+                content = _.flatten(_.filter(content,function (item) {
+                    return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
+                }));
+            }
+
+            if(company && company != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.company_id == company;
+                }));
+            }
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.store_id == store;
+                }));
+            }
+            if(journal && journal != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.journal_id == journal;
+                }));
+            }
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') <= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === lastMonth;
+                    }));
+                }
+            }
+            return content;
+        },
+
+        getAccountVoucher:function(number) {
+            var self = this;
+            var content = self.AccountVoucher;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var journal = self.$el.find('#current-journal').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+
+            content = _.filter(content,function (item) {
+                return item.reference == number;
+            })
+
+            if((store && store == 9999999)||(company && company == 9999999)){
+                var store_ids = _.flatten(_.map(self.ResStore, function (item) {
+                    return item.id;
+                }));
+                var company_ids = _.flatten(_.map(self.ResCompany, function (item) {
+                    return item.id;
+                }));
+                content = _.flatten(_.filter(content,function (item) {
+                    return _.contains(store_ids, item.store_id) && _.contains(company_ids, item.company_id);
+                }));
+            }
+
+            if(company && company != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.company_id == company;
+                }));
+            }
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.store_id == store;
+                }));
+            }
+            if(journal && journal != 9999999){
+                content = _.flatten(_.filter(content,function (item) {
+                    return item.journal_id == journal;
+                }));
+            }
+            if(date && date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') >= date;
+                        }));
+                    }
+                    if(hasta){
+                        date = hasta.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        content = _.flatten(_.filter(content,function (inv) {
+                            return moment(inv.date).format('YYYY-MM-DD') <= date;
+                        }));
+                    }
+                }
+                if(date == 'today'){
+                    var today = moment().format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === today;
+                    }));
+                }
+                if(date == 'yesterday'){
+                    var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM-DD') === yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === currentMonth;
+                    }));
+                }
+                if(date == 'lastMonth'){
+                    var lastMonth = moment().add(-1,'months').format('YYYY-MM');
+                    content = _.flatten(_.filter(content,function (inv) {
+                        return moment(inv.date).format('YYYY-MM') === lastMonth;
+                    }));
+                }
+            }
+            return content;
+        },
+
+        getQuota:function(reference, reconcile_ref) {
+
+            var self = this;
+            var content = [];
+            var AccountMoveLine = self.AccountMoveLine;
+            content = _.flatten(_.filter(AccountMoveLine,function (item) {
+                return item.name == reference && item.type == 'receivable';
+            }));
+            var c = 1;
+            var x = content.length;
+
+            _.each(content, function(item){
+                item.quota = 'Cuota ' + c + ' / ' + x;
+                item.ban = c;
+                c++;
+            });
+            content = _.flatten(_.filter(content,function (item) {
+                return item.reconcile_ref == reconcile_ref;
+            }));
+
+
+          if (content.length > 0){
+            if(content[0].reconcile_partial_id != null){
+                AccountMoveLine = _.flatten(_.filter(AccountMoveLine,function (item) {
+                    return item.reconcile_partial_id == content[0].reconcile_partial_id && item.credit > 0;
+                }));
+                var total =  _.reduce(_.map(AccountMoveLine,function(item){
+                    return item.credit;
+                }), function(memo, num){
+                    return memo + num;
+                },0);
+                content[0].residual = content[0].debit - total;
+
+            }
+          }
+
+            return content;
+        },
+
+        BuildTable: function(){
+            var self = this;
+            var data = [];
+            var residual = 0;
+            var CurrencyBase = self.ResCompany[0].currency_id;
+
+            var AccountInvoice = self.AccountInvoice;
+
+            _.each(AccountInvoice, function(each){
+              var AccountVoucher = self.getAccountVoucher(each.number);
+              _.each(AccountVoucher, function(item){
+                var pagado = 0;
+                var totalpagado = 0;
+                var tresidual = 0;
+              if(each.type == 'out_refund'){
+                    pagado = -(item.amount_original);
+                    totalpagado = -(item.amount);
+                    tresidual = -(item.residual);
+                }else{
+                  pagado = (item.amount_original);
+                  totalpagado = (item.amount);
+                  tresidual = (item.residual);
+                }
+
+                var quota = self.getQuota(self.valorNull(item.reference), item.reconcile_ref);
+                if(quota[0].ban > 1){
+                // _.each(quota, function(itemquo){
+                    data.push({
+                        id:item.id,
+                        number:item.number,
+                        partner_name:item.partner_name,
+                        invoice_number: self.valorNull(item.invoice_number),
+                        origin: self.valorNull(each.origin),
+                        user_name: self.valorNull(each.user_name),
+                        // description: quota.length > 0,
+                        description: quota.length > 0 ? quota[0].quota : 'Cuota 1 / 1',
+                        date:moment(item.date).format('DD/MM/YYYY'),
+                        date_maturity:moment(item.date_maturity).format('DD/MM/YYYY'),
+                        journal_name:item.journal_name,
+                        user_name: self.valorNull(each.user_name),
+                        amount_original:accounting.formatMoney(pagado,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                        total:accounting.formatMoney(totalpagado,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                        residual:accounting.formatMoney(tresidual,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+
+                        /*
+                        =======================
+                            NO FORMAT
+                        =======================
+                        */
+                        amount_original_no_format: pagado,
+                        total_no_format:totalpagado,
+                        residual_no_format:tresidual,
+                        /*
+                        =======================
+                            FOOTER
+                        =======================
+                        */
+                        decimal_places:CurrencyBase.decimal_places,
+                        thousands_separator:CurrencyBase.thousands_separator,
+                        decimal_separator:CurrencyBase.decimal_separator,
+                    // });
+                  });
+                }
+              })
+            });
+            /*
+            ==========================================
+                ACCOUNT BANK STATEMENT LINE
+            ==========================================
+            */
+            var AccountBankStatementLine = self.getAccountBankStatementLine();
+            _.each(AccountBankStatementLine, function(item){
+                var amount = item.amount_currency;
+                if(item.currency_id != null){
+                    amount = amount + '('  + item.amount + ')';
+                }
+                data.push({
+                    id:item.id,
+                    date:moment(item.date).format('DD/MM/YYYY'),
+                    invoice_number:item.origin,
+                    // name:item.name,
+                    number:item.name,
+                    partner_name:self.valorNull(item.partner_name),
+                    journal_name:item.journal_name,
+                    reference:item.name,
+                    description: 'Cuota 1 / 1',
+                    residual: accounting.formatMoney(0,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                    amount_original:accounting.formatMoney(amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                    total:accounting.formatMoney(amount,'',CurrencyBase.decimal_places,CurrencyBase.thousands_separator,CurrencyBase.decimal_separator),
+                    /*
+                    =======================
+                        NO FORMAT
+                    =======================
+                    */
+                    date_no_format: moment(item.date).format('YYYY-MM-DD'),
+                    amount_original_no_format: item.amount_currency,
+                    total_no_format:item.amount_currency,
+                    /*
+                    =======================
+                        FOOTER
+                    =======================
+                    */
+                    decimal_places:CurrencyBase.decimal_places,
+                    thousands_separator:CurrencyBase.thousands_separator,
+                    decimal_separator:CurrencyBase.decimal_separator,
+                });
+            });
+            data.sort(function (a, b) {
+                if (a.date_no_format > b.date_no_format) {
+                    return -1;
+                }
+                if (a.date_no_format < b.date_no_format) {
+                    return 1;
+                }
+                return 0;
+            });
+            self.content = data;
+            self.loadTable(data);
+            self.$el.find('.report-form').css('display','block');
+            self.$el.find('.search-form').unblock();
+            self.$el.find('.report-form').unblock();
+        },
+
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('load', rowsTable);
+        },
+
+        clickOnAction: function (e) {
+            var self = this;
+            var ResCompany;
+            var CurrencyBase;
+            var action = this.$el.find(e.target).val();
+            var company = $('#current-company').val();
+            if(company && company != 9999999){
+                ResCompany = _.flatten(_.filter(self.ResCompany,function (inv) {
+                    return inv.id == company;
+                }));
+                ResCompany = CompanyLogo[0];
+                CurrencyBase = ResCompany[0].currency_id;
+            }else{
+                ResCompany = self.CompanyLogo[0];
+                CurrencyBase = self.ResCompany[0].currency_id;
+            }
+            var getColumns=[];
+            var rows=[];
+            var table = this.$el.find("#table");
+            var column = table.bootstrapTable('getVisibleColumns');
+            var row = table.bootstrapTable('getData');
+            var amount_original = amountOriginalFormatter(row);
+            var total = totalFormatter(row);
+            row.push({
+                number:'Totales',
+                amount_original: amount_original,
+                total:total,
+            });
+
+            if (action === 'pdf') {
+                var data = _.map(column, function (val){
+                    return val.field;
+                });
+                _.each(_.map(column,function(val){
+                    return val;
+                }), function(item){
+                    getColumns.push([{
+                        title: item.title,
+                        dataKey: item.field
+                    }]);
+                });
+                /*
+                ============================================================
+                    CONFIGURACION DEL PDF
+                ============================================================
+                */
+                var pdf_title = 'Pagos y devoluciones de clientes.';
+                var pdf_type = '';
+                var pdf_name = 'pagos_devoluciones_clientes';
+                var pdf_columnStyles = {
+                    number:{columnWidth: 22, halign:'left'},
+                    partner_name:{columnWidth: 22, halign:'left'},
+                    invoice_number:{columnWidth: 25, halign:'left'},
+                    origin:{columnWidth: 15, halign:'left'},
+                    description:{columnWidth: 18, halign:'left'},
+                    date:{columnWidth: 18,  halign:'center'},
+                    date_maturity:{columnWidth: 14,  halign:'center'},
+                    journal_name:{columnWidth: 18, halign:'left'},
+                    user_name:{columnWidth: 18, halign:'left'},
+                    amount_original:{columnWidth: 18, halign:'right'},
+                    total:{columnWidth: 18, halign:'right'},
+
+                };
+                /*
+                ============================================================
+                    LLAMAR FUNCION DE IMPRESION
+                ============================================================
+                */
+                var filter = self.getFilter();
+                var pdf = new reporting.ReportPdfWidget(self);
+                pdf.drawPDF(
+                    _.flatten(getColumns),
+                    row,
+                    ResCompany,
+                    pdf_title,
+                    pdf_type,
+                    pdf_name,
+                    pdf_columnStyles,
+                    filter
+                );
+            }
+        },
+        getFilter: function(){
+            var self = this;
+            var company = self.$el.find('#current-company').val();
+            var store = self.$el.find('#current-store').val();
+            var state = self.$el.find('#current-state').val();
+            var journal = self.$el.find('#current-journal').val();
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var filter = [];
+            if(company && company != 9999999){
+                var ResCompany = _.filter(self.ResCompany, function(item){
+                    return item.id == company;
+                });
+                filter.push({
+                    title:'Empresa',
+                    value: ResCompany[0].name,
+                });
+            }
+            if(store && store != 9999999){
+                var ResStore =  _.filter(self.ResStore,function (item) {
+                        return item.id == store;
+                });
+                filter.push({
+                    title: 'Sucursal',
+                    value:  ResStore[0].name,
+                });
+            }
+            if(journal && journal != 9999999){
+                var AccountJournal =  _.filter(self.AccountJournal,function (item) {
+                    return item.id == journal;
+                });
+                filter.push({
+                   title: 'Método de pago',
+                   value: AccountJournal[0].name,
+                });
+            }
+            if(date && date != 9999999){
+                moment.locale('es', {
+                    months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
+                });
+
+                if(date == 'range'){
+                    filter.push({
+                        title: 'Fecha',
+                        value:  desde +' al '+hasta,
+                    });
+                }else {
+                    var fecha;
+                    if(date == 'today'){
+                        fecha = moment().format('DD/MM/YYYY');
+                    }
+                    if(date == 'yesterday'){
+                        fecha = moment().add(-1,'days').format('DD/MM/YYYY');
+                    }
+                    if(date == 'currentMonth'){
+                        fecha = moment().format('MMMM/YYYY');
+                    }
+                    if(date == 'lastMonth'){
+                        fecha = moment().add(-1,'months').format('MMMM/YYYY');
+                    }
+                    filter.push({
+                        title: 'Fecha',
+                        value:  fecha,
+                    });
+                }
+            }
+            return filter;
+        },
+    });
+}

+ 178 - 0
static/src/reports/report_customer_paymentanillos.xml

@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportCustomerPaymentAnillos">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title">Pagos de Clientes sin 1º cuota</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>Método de pago</label>
+                        <select id="current-journal" 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" style="color:#fff;display:none;">
+                            Generar
+                        </button>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+            <div class="report-form" style="display:none;">
+                <div id="toolbar">
+                    <button class="print-report oe_button myButton" value="pdf">Imprimir Informe</button>
+                </div>
+                <div class="container" style="width:95%;">
+                    <table id="table"
+                        data-pagination="true"
+                        data-toggle="table"
+                        data-toolbar="#toolbar"
+                        data-show-columns="true"
+                        data-classes="table table-condensed"
+                        data-search="true"
+                        data-show-export="true"
+                        data-show-toggle="true"
+                        data-show-footer="true"
+                        data-footer-style="footerStyle"
+                        data-buttons-class="oe_button myButton"
+                        data-show-pagination-switch="true"
+                        data-search-on-enter-key="true"
+                        data-undefined-text=" "
+                        data-pagination-v-align="top"
+                        >
+                        <thead style="background:none;">
+                            <tr>
+                              <th data-field="number"
+                                    data-align="left"
+                                    data-footer-formatter="Totales"
+                                    >Número de Pago</th>
+                              <th data-field="partner_name"
+                                    data-align="left"
+                                    >Cliente</th>
+                              <th data-field="invoice_number"
+                                    data-align="left"
+                                    >Número Fact.</th>
+                              <th data-field="origin"
+                                    data-align="left"
+                                    >Origen</th>
+                              <th data-field="description"
+                                  data-align="left"
+                                  >Cuotas</th>
+                                <th data-field="date"
+                                    data-align="left"
+                                    >Fecha pago</th>
+                                <th data-field="date_maturity"
+                                    data-align="left"
+                                    >Vence</th>
+                                <th data-field="journal_name"
+                                    data-align="left"
+                                    >Método de Pago</th>
+                                <th data-field="user_name"
+                                    data-align="left"
+                                    >Vendedor</th>
+                                <th data-field="amount_original"
+                                    data-align="right"
+                                    data-footer-formatter="amountOriginalFormatter"
+                                    >Monto cuota</th>
+                                <th data-field="total"
+                                    data-align="right"
+                                    data-footer-formatter="totalFormatter"
+                                    >Monto Pagado</th>
+                            </tr>
+                        </thead>
+                    </table>
+                </div>
+            </div>
+
+            <script>
+                <!--
+                    TOTAL
+                -->
+                function amountOriginalFormatter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var amount =  _.reduce(_.map(rowsTable,function(item){
+                        return item.amount_original_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0)
+                    return accounting.formatNumber(amount,decimal_places,thousands_separator,decimal_separator);
+                }
+                function totalFormatter(rowsTable) {
+                    var decimal_places = 0;
+                    var thousands_separator = '.';
+                    var decimal_separator = ',';
+                    if(rowsTable.length > 0){
+                        decimal_places = rowsTable[0].decimal_places;
+                        thousands_separator = rowsTable[0].thousands_separator;
+                        decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    var amount =  _.reduce(_.map(rowsTable,function(item){
+                        return item.total_no_format;
+                    }), function(memo, num){
+                        return memo + num;
+                    },0)
+                    return accounting.formatNumber(amount,decimal_places,thousands_separator,decimal_separator);
+                }
+
+
+                <!--
+                    FOOTER STYLE
+                -->
+                function footerStyle(row, index) {
+                    return {
+                        css: {
+                          "font-weight": "bold"
+                        }
+                    };
+                };
+            </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>

+ 23 - 0
templates.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <template id="eiru_reports_anillos_assets" inherit_id="eiru_assets.assets">
+      <xpath expr="." position="inside">
+        <link rel="stylesheet" href="/eiru_reports_anillos/static/src/css/custom.css"/>
+
+        <!-- configuration < main > -->
+        <script type="text/javascript" src="/eiru_reports_anillos/static/src/js/main.js"/>
+        <script type="text/javascript" src="/eiru_reports_anillos/static/src/js/reporting_base.js"/>
+        <script type="text/javascript" src="/eiru_reports_anillos/static/src/js/pdf_anillos.js" />
+
+        <!-- ================================= anillos ========================================= -->
+
+        <!--=============================
+            Pagos de clientes y devoluciones
+        ==============================-->
+        <script type="text/javascript" src="/eiru_reports_anillos/static/src/js/reports/report_customer_paymentanillos.js"/>
+
+      </xpath>
+    </template>
+  </data>
+</openerp>

+ 13 - 0
views/actions.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+
+		<!--======================================
+				PAGOS DE CLIENTES Y NOTA DE CREDITO
+		=======================================-->
+		<record id="customer_paymentanillos_action" model="ir.actions.client">
+					<field name="name">Pagos sin primera cuota</field>
+					<field name="tag">eiru_reports_anillos.customer_paymentanillos_action</field>
+		</record>
+	</data>
+</openerp>

+ 13 - 0
views/menus.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <!-- main menu name -->
+    <!-- <menuitem id="anillos_parent_menu" name="Anillos" parent="eiru_reports.account_parent_menu" sequence="70"/> -->
+
+    <!-- sub menu -->
+
+
+    <menuitem id="payment_anillo" parent="eiru_reports.account_parent_menu" name="Pagos de Clientes sin 1º cuota" action="customer_paymentanillos_action" sequence="12"/>
+
+  </data>
+</openerp>