Browse Source

commit inicial

Rodney Elpidio Enciso Arias 6 years ago
commit
c17b9d3bfc

+ 1 - 0
.gitignore

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

+ 3 - 0
__init__.py

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

+ 24 - 0
__openerp__.py

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

+ 1 - 0
controllers/__init__.py

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

+ 6 - 0
controllers/helpers/__init__.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+from res_company import get_res_company
+from res_store import get_res_store
+from account_invoice_line import get_account_invoice_line
+from product_category import get_product_category
+from account_journal import get_account_journal

+ 74 - 0
controllers/helpers/account_invoice_line.py

@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_account_invoice_line():
+    user_store = r.env.user.store_id.id
+    company_currency_rate = r.env.user.company_id.currency_id.rate
+    query = '''
+        SELECT
+            	invoice.id AS invoice_id,
+            	line.id AS invoice_line_id,
+            	invoice.number,
+            	invoice.origin,
+            	invoice.date_invoice,
+            	invoice.type,
+            	product.name_template,
+            	line.price_unit * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) as price_unit,
+            	line.quantity AS cant,
+            	line.price_subtotal * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]) AS subtotal,
+            	(line.quantity * (line.price_unit * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1]))) - (line.price_subtotal * (%s / (array_agg(rate.rate ORDER BY rate.id DESC))[1])) AS impuestos,
+            	(array_agg(history.cost ORDER BY history.id DESC))[1] * line.quantity as cost,
+                template.categ_id,
+                journal.store_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 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 product_template AS template
+            ON template.id = product.product_tmpl_id
+            WHERE invoice.state NOT IN ('draft', 'cancel')
+            AND invoice.type = 'in_invoice'
+            AND invoice.origin IS NULL
+            --AND TO_CHAR(invoice.date_invoice,'YYYY-MM') = TO_CHAR(current_date,'YYYY-MM')
+            --AND journal.store_id = ''' + str(user_store) + '''
+        GROUP BY
+        	invoice.id,
+        	line.id,
+        	invoice.number,
+        	invoice.origin,
+        	invoice.date_invoice,
+        	product.name_template,
+        	line.price_unit,
+        	line.quantity,
+        	line.price_subtotal,
+            template.categ_id,
+            journal.store_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],
+            'categ_id': j[12],
+            'store_id': j[13],
+        } for j in r.cr.fetchall()
+    ]

+ 26 - 0
controllers/helpers/account_journal.py

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

+ 12 - 0
controllers/helpers/product_category.py

@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_product_category(purchase=True):
+    domain = [('expense', '=', True)]
+
+    return [
+        {
+            'id': p.id,
+            'name': p.complete_name,
+        } for p in r.env['product.category'].search(domain)
+    ]

+ 49 - 0
controllers/helpers/res_company.py

@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+from openerp.http import request as r
+
+def get_res_company():
+    user_company = r.env.user.company_id.id
+    user_store = r.env.user.store_id.id
+    query = '''
+        SELECT
+            company.id,
+            company.name,
+            currency.id,
+            currency.name,
+            currency.symbol,
+            currency.decimal_places,
+            currency.decimal_separator,
+            currency.thousands_separator,
+            currency.symbol_position,
+            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
+        AND company.id = ''' + str(user_company) + '''
+    '''
+
+    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()
+    ]

+ 18 - 0
controllers/helpers/res_store.py

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

+ 41 - 0
controllers/main.py

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

+ 111 - 0
models.py

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

BIN
static/description/icon.png


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

@@ -0,0 +1,17 @@
+openerp.eiru_reports_agroyguazu = function (instance) {
+    "use strict";
+
+    var reporting = instance.eiru_reports_agroyguazu;
+
+    reporting_base(instance,reporting);
+
+    try {
+        report_expense_comparative(reporting);
+        // report_sale_by_city(reporting);
+    } catch (e) {
+        // ignorar error
+    }
+
+    instance.web.client_actions.add('eiru_reports_agroyguazu.expense_comparative_action', 'instance.eiru_reports_agroyguazu.ReportExpenseComparativeWidget');
+    // instance.web.client_actions.add('agroyguazu.sale_by_city_action', 'instance.agroyguazu.ReportSaleByCityWidget');
+};

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

+ 480 - 0
static/src/js/reports/report_expense_comparative.js

@@ -0,0 +1,480 @@
+function report_expense_comparative(reporting){
+    "use strict";
+
+    var model = openerp;
+
+    reporting.ReportExpenseComparativeWidget = reporting.Base.extend({
+        template: 'ReportExpenseComparative',
+        rowsData :[],
+        content :[],
+
+        events:{
+            'click #generate' : 'fetchGenerate',
+            'change #current-date' : 'ShowDateRange',
+        },
+
+        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();
+        },
+
+        valorNull:function(dato){
+            var valor = "";
+            if (dato){
+                valor = dato;
+            }
+            return valor;
+        },
+
+        ShowDateRange : function(){
+            var self = this;
+            var date = self.$el.find('#current-date').val();
+            if(date == 'range'){
+                self.$el.find('.datepicker').css('display','block');
+            }
+            if(date != 'range'){
+                self.$el.find('.datepicker').css('display','none');
+            }
+        },
+
+        fetchInitial: function () {
+            var self = this;
+            self.fetchDataSQL().then(function (DataSQL) {
+                return DataSQL;
+            }).then(function(DataSQL) {
+                self.AccountInvoiceLine = DataSQL.invoice_lines;
+                self.ProductCategory = DataSQL.categories;
+                self.ResCompany = DataSQL.companies;
+                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');
+                }
+
+                self.ResStore = DataSQL.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');
+                }
+            });
+            self.$el.find('#generate').css('display','inline');
+            return;
+        },
+
+        fetchDataSQL: function() {
+            var self = this;
+            var data = $.get('/reports-agroyguazu-expense');
+            return data;
+        },
+
+        fetchGenerate: function () {
+            var self = this;
+            self.$el.find('.search-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            self.$el.find('.report-form').block({
+                message: null,
+                overlayCSS: {
+                    backgroundColor: '#FAFAFA'
+                }
+            });
+            return self.BuildTable();
+        },
+
+        /*====================================================================
+            UPDATE SELECTIONS
+        ====================================================================*/
+        updateSelections: function () {
+            var self = this;
+            var store = '';
+            var company = self.$el.find('#current-company').val();
+            if(company != 9999999){
+                /*===================
+                    STORE SELECTION
+                ===================*/
+                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 SELECTION
+                ===================*/
+                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>');
+                });
+            }
+        },
+
+        getAccountInvoiceLine: function (categ_id) {
+            var self = this;
+            var content = self.AccountInvoiceLine;
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var store = self.$el.find('#current-store').val();
+            var data = [];
+            var start = '';
+            var finish = '';
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (inv){
+                    return inv.store_id == store;
+                }));
+            }
+            if(date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        start = moment(date).format('YYYY-MM');
+                        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]);
+                        finish = moment(date).format('YYYY-MM');
+                        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');
+                    start = today;
+                    finish = today;
+                    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');
+                    start = yesterday;
+                    finish = yesterday;
+                    content = _.flatten(_.filter(content,function (inv){
+                        return moment(inv.date).format('YYYY-MM-DD') == yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    start = currentMonth;
+                    finish = currentMonth;
+                    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');
+                    start = lastMonth;
+                    finish = lastMonth;
+                    content = _.flatten(_.filter(content,function (inv){
+                        return moment(inv.date).format('YYYY-MM') == lastMonth;
+                    }));
+                }
+            }
+
+            content.sort(function (a, b) {
+                if (a.date > b.date) {
+                    return 1;
+                }
+                if (a.date < b.date) {
+                    return -1;
+                }
+                return 0;
+            });
+
+            // console.log(content);
+
+            if(content.length > 0){
+                if(date == 9999999){
+                    start = moment(content[0].date).format('YYYY-MM');
+                    finish = moment(content[content.length-1].date).format('YYYY-MM');
+                }
+
+                if(!desde){
+                    start = moment(content[0].date).format('YYYY-MM');
+                }
+
+                if(!hasta){
+                    finish = moment(content[content.length -1].date).format('YYYY-MM');
+                }
+
+                var total = 0;
+                for (var i = 0; i < 12; i++) {
+                    total = _.reduce(_.map(content,function(item) {
+                        if(item.categ_id == categ_id && moment(item.date).format('YYYY-MM') == start){
+                            return item.quantity * item.price_unit;
+                        }else{
+                            return 0;
+                        }
+                    }),function(memo, num) {
+                        return memo + num;
+                    },0);
+                    data.push({
+                        'date': start,
+                        'amount': total
+                    });
+                    start = moment(start).add(1,'months').format('YYYY-MM');
+                    if(start > finish){
+                        break;
+                    }
+                }
+            }
+
+            return data;
+        },
+
+
+        getColumns: function(){
+            var self = this;
+            var columns = [];
+            columns.push({
+                field: 'name',
+                title: 'Descripcion',
+                footerFormatter: 'Totales',
+            });
+
+            moment.locale('es', {
+                months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
+            });
+
+            var content = self.AccountInvoiceLine;
+            var date = self.$el.find('#current-date').val();
+            var desde = self.$el.find('#from').val();
+            var hasta = self.$el.find('#to').val();
+            var store = self.$el.find('#current-store').val();
+            var data = [];
+            var start = '';
+            var finish = '';
+            if(store && store != 9999999){
+                content = _.flatten(_.filter(content,function (inv){
+                    return inv.store_id == store;
+                }));
+            }
+            if(date != 9999999){
+                if(date == 'range'){
+                    if(desde){
+                        date = desde.split('/');
+                        date = (date[2]+"-"+date[1]+"-"+date[0]);
+                        start = date;
+                        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]);
+                        finish = date;
+                        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');
+                    start = today;
+                    finish = today;
+                    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');
+                    start = yesterday;
+                    finish = yesterday;
+                    content = _.flatten(_.filter(content,function (inv){
+                        return moment(inv.date).format('YYYY-MM-DD') == yesterday;
+                    }));
+                }
+                if(date == 'currentMonth'){
+                    var currentMonth = moment().format('YYYY-MM');
+                    start = currentMonth;
+                    finish = currentMonth;
+                    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');
+                    start = lastMonth;
+                    finish = lastMonth;
+                    content = _.flatten(_.filter(content,function (inv){
+                        return moment(inv.date).format('YYYY-MM') == lastMonth;
+                    }));
+                }
+            }
+
+            content.sort(function (a, b) {
+                if (a.date > b.date) {
+                    return 1;
+                }
+                if (a.date < b.date) {
+                    return -1;
+                }
+                return 0;
+            });
+
+
+            if(content.length > 0){
+                if(date == 9999999){
+                    start = moment(content[0].date).format('YYYY-MM');
+                    finish = moment(content[content.length-1].date).format('YYYY-MM');
+                }
+
+                if(!desde){
+                    start = moment(content[0].date).format('YYYY-MM');
+                }
+
+                if(!hasta){
+                    finish = moment(content[content.length -1].date).format('YYYY-MM');
+                }
+
+                for (var i = 0; i < 12; i++) {
+                    var column_name = start;
+                    columns.push({
+                        field: moment(start).format('MMMM'),
+                        title: moment(start).format('MMMM/YY'),
+                        align: 'right',
+                        footerFormatter: totalFormatter,
+                    });
+                    start = moment(start).add(1,'months').format('YYYY-MM');
+                    if(start > finish){
+                        break;
+                    }
+                }
+
+                columns.push({
+                    field: 'Total',
+                    title: 'Totales',
+                    align: 'right',
+                    cellStyle: columnStyle,
+                    footerFormatter: totalFormatter,
+                });
+
+            }
+            return columns;
+        },
+
+        BuildTable: function(){
+            var self = this;
+            console.log(self);
+            var data = [];
+            var columns = self.getColumns();
+            var AccountInvoiceLine = 0;
+            var CurrencyBase = self.ResCompany[0].currency_id;
+            _.each(self.ProductCategory,function(item) {
+                AccountInvoiceLine = self.getAccountInvoiceLine(item.id);
+                data.push({
+                    'name': item.name,
+                    'symbol': CurrencyBase.symbol,
+                    'decimal_places': CurrencyBase.decimal_places,
+                    'thousands_separator': CurrencyBase.thousands_separator,
+                    'decimal_separator': CurrencyBase.decimal_separator,
+                });
+                _.each(AccountInvoiceLine,function(index) {
+                    if(moment(index.date).format('MM') == '01'){
+                        data[data.length -1].Enero = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].enero = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '02'){
+                        data[data.length -1].Febrero = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].febrero = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '03'){
+                        data[data.length -1].Marzo = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].marzo = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '04'){
+                        data[data.length -1].Abril = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].abril = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '05'){
+                        data[data.length -1].Mayo = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].mayo = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '06'){
+                        data[data.length -1].Junio = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].junio = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '07'){
+                        data[data.length -1].Julio = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].julio = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '08'){
+                        data[data.length -1].Agosto = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].agosto = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '09'){
+                        data[data.length -1].Septiembre = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].septiembre = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '10'){
+                        data[data.length -1].Octubre = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].octubre = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '11'){
+                        data[data.length -1].Noviembre = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].noviembre = (index.amount);
+                    }
+                    if(moment(index.date).format('MM') == '12'){
+                        data[data.length -1].Diciembre = (accounting.formatMoney(index.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                        data[data.length -1].diciembre = (index.amount);
+                    }
+                });
+                var total = _.reduce(_.map(AccountInvoiceLine,function(inv) {
+                    return inv.amount;
+                }),function(memo, num) {
+                    return memo + num;
+                },0);
+                data[data.length -1].Total = (accounting.formatMoney(total, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+                data[data.length -1].total = total;
+            });
+            // data.push({
+            //     'symbol': CurrencyBase.symbol,
+            //     'decimal_places': CurrencyBase.decimal_places,
+            //     'thousands_separator': CurrencyBase.thousands_separator,
+            //     'decimal_separator': CurrencyBase.decimal_separator,
+            // });
+            self.content = data;
+            self.loadTable(data,columns);
+            self.$el.find('.report-form').css('display','block');
+            self.$el.find('.search-form').unblock();
+            self.$el.find('.report-form').unblock();
+        },
+
+        loadTable:function(data,columns){
+            var self = this;
+            var table = this.$el.find('#table');
+            table.bootstrapTable('destroy');
+            table.bootstrapTable({
+                data: data,
+                columns: columns,
+            });
+            table.bootstrapTable('load', data);
+        },
+
+    });
+}

+ 203 - 0
static/src/reports/report_expense_comparative.xml

@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="ReportExpenseComparative">
+        <div class="report_view">
+            <div class="reporting_page_header">
+                <h1 class="report_title">Cuadro Comparativo de Gastos por Categoria.</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 filter-style">
+                        <label>Fechas</label>
+                        <select id="current-date" class="form-control form-control-sm">
+                            <option value="9999999">Sin fechas</option>
+                            <option value="today">Hoy</option>
+                            <option value="yesterday">Ayer</option>
+                            <option value="currentMonth">Mes Actual</option>
+                            <option value="lastMonth">Mes Pasado</option>
+                            <option value="range">Busqueda Avanzada</option>
+                        </select>
+                    </div>
+                </div>
+                <div class="row" >
+                    <div class="datepicker" style="display:none;">
+                        <div class="col-lg-3 filter-style col-md-offset-3">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Desde</span>
+                                <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                        <div class="col-lg-3 filter-style">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                                <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="text-center" style="padding-top:20px;">
+                        <button id="generate" class="myButton" aria-label="Left Align">
+                            Generar
+                        </button>
+                    </div>
+                    <br/>
+                </div>
+            </div>
+
+            <div class="report-form" style="display:none;">
+                <div class="container" style="width:95%;">
+                    <table id="table"
+                        data-show-export="true"
+                        data-show-columns="true"
+                        data-show-footer="true"
+                        data-classes="table table-no-bordered table-condensed"
+                        data-search="true"
+                        data-buttons-class="oe_button myButton"
+                        data-search-on-enter-key="true"
+                        data-undefined-text=" "
+                        data-footer-style="footerStyle"
+                        data-show-toggle="true"
+                        >
+                        <thead style="background:none;"></thead>
+                    </table>
+                </div>
+            </div>
+            <script>
+
+                <!--
+                    TOTAL
+                -->
+                function totalFormatter(rowsTable) {
+                    var self = this;
+                    if(rowsTable.length > 0){
+                        var decimal_places = rowsTable[0].decimal_places;
+                        var thousands_separator = rowsTable[0].thousands_separator;
+                        var decimal_separator = rowsTable[0].decimal_separator;
+                    }
+                    if(self.field == 'Enero'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.enero);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Febrero'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.febrero);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Marzo'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.marzo);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Abril'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.abril);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Mayo'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.mayo);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Junio'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.junio);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Julio'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.julio);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Agosto'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.agosto);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Septiembre'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.septiembre);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Octubre'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.octubre);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Noviembre'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.noviembre);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Diciembre'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.diciembre);
+                        }), function(memo, num){
+                            return memo + num;
+                        },0);
+                    }
+                    if(self.field == 'Total'){
+                        var amount =  _.reduce(_.map(rowsTable,function(item){
+                            return (item.total);
+                        }), 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"
+                        }
+                    };
+                };
+                <!--
+                    COLUMN STYLE
+                -->
+                function columnStyle(value, row, index, field) {
+                    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>

+ 21 - 0
templates.xml

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

+ 11 - 0
views/actions.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+
+		<record id="expense_comparative_action" model="ir.actions.client">
+            <field name="name">Gastos</field>
+            <field name="tag">eiru_reports_agroyguazu.expense_comparative_action</field>
+        </record>
+
+    </data>
+</openerp>

+ 17 - 0
views/menus.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+
+        <menuitem id="welcome_odontoimagen_parent_menu"
+            name="Gastos"
+            parent="eiru_reports.eiru_reports_main_menu"
+            sequence="30"/>
+
+        <menuitem id="doctor_ranking_menu"
+            parent="welcome_odontoimagen_parent_menu"
+            name="Cuadro Comparativo de Gastos"
+            action="expense_comparative_action"
+            sequence="3"/>
+
+    </data>
+</openerp>