|
@@ -0,0 +1,661 @@
|
|
|
|
+function report_ventas_inmobiliaria(reporting){
|
|
|
|
+ "use strict";
|
|
|
|
+
|
|
|
|
+ var model = openerp;
|
|
|
|
+
|
|
|
|
+ reporting.ReportVentasWidget = reporting.Base.extend({
|
|
|
|
+ template: 'ReportVentasInmobiliaria',
|
|
|
|
+ rowsData :[],
|
|
|
|
+ content :[],
|
|
|
|
+ modules: ['point_of_sale'],
|
|
|
|
+
|
|
|
|
+ events:{
|
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
|
+ '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.fetchInitialSQL().then(function (InitialSQL) {
|
|
|
|
+ return InitialSQL;
|
|
|
|
+ }).then(function(InitialSQL) {
|
|
|
|
+ /*
|
|
|
|
+ =================================
|
|
|
|
+ RES COMPANY
|
|
|
|
+ =================================
|
|
|
|
+ */
|
|
|
|
+ self.ResCompany = InitialSQL.companies;
|
|
|
|
+ self.CompanyLogo = InitialSQL.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 = InitialSQL.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');
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ =================================
|
|
|
|
+ RES PARTNER
|
|
|
|
+ =================================
|
|
|
|
+ */
|
|
|
|
+ self.ResPartner = InitialSQL.partner;
|
|
|
|
+ if(self.ResPartner.length > 0){
|
|
|
|
+ self.$el.find('#current-customer').append('<option value="9999999">Todas los compradores</option>');
|
|
|
|
+ _.each(self.ResPartner,function(item){
|
|
|
|
+ self.$el.find('#current-customer').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ self.$el.find('.customer').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.ResPartner = DataSQL.partners;
|
|
|
|
+ self.AccountInvoice = DataSQL.invoices;
|
|
|
|
+ self.AccountInvoiceLine = DataSQL.invoice_line;
|
|
|
|
+ self.Contrato = DataSQL.contracts;
|
|
|
|
+ self.ContractLine = DataSQL.contract_line;
|
|
|
|
+
|
|
|
|
+ return self.fetchAccountMoveLine();
|
|
|
|
+ }).then(function(MoveLine){
|
|
|
|
+ self.MoveLine = MoveLine;
|
|
|
|
+ return self.BuildTable();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchInitialSQL: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = $.get('/report-filter-data-inmobiliaria');
|
|
|
|
+ return data;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ fetchDataSQL: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = $.get('/report-sale-inmobiliaria');
|
|
|
|
+ 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');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ fetchAccountMoveLine: function (){
|
|
|
|
+ var self = this;
|
|
|
|
+ var domain = [];
|
|
|
|
+
|
|
|
|
+ var AccountMoveLine = new model.web.Model('account.move.line');
|
|
|
|
+ return AccountMoveLine.call('getAccountMoveLine',[domain], {
|
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*====================================================================
|
|
|
|
+ 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>');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getAccountInvoice:function(origin) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var content = self.AccountInvoice;
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.origin == origin;
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ return content;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getStoreName:function(store_id){
|
|
|
|
+ var self = this;
|
|
|
|
+ var ResStore = _.filter(self.ResStore,function (item) {
|
|
|
|
+ return item.id == store_id;
|
|
|
|
+ });
|
|
|
|
+ return ResStore[0].name;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getAccountInvoiceLine:function(invoice_id){
|
|
|
|
+ var self = this;
|
|
|
|
+ var AccountInvoiceLine = _.filter(self.AccountInvoiceLine,function (item) {
|
|
|
|
+ return item.invoice_id == invoice_id;
|
|
|
|
+ });
|
|
|
|
+ return AccountInvoiceLine;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getOwnerName:function(partner_id){
|
|
|
|
+ var self = this;
|
|
|
|
+ var ResPartners = _.filter(self.ResPartner,function (item) {
|
|
|
|
+ return item.id == partner_id;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (ResPartners.length > 0){
|
|
|
|
+ return ResPartners[0].name;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getContracts:function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var content = self.Contrato;
|
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
|
+ var customer = self.$el.find('#current-customer').val();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(state && state != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.state == state;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(customer && customer != 9999999){
|
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
|
+ return item.partner_id == customer;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return content;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getContractLine:function(contract_id){
|
|
|
|
+ var self = this;
|
|
|
|
+ var ContractLine = _.filter(self.ContractLine,function (item) {
|
|
|
|
+ return item.analytic_account_id == contract_id;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return ContractLine;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getUltimoPago:function(move_ids){
|
|
|
|
+ var self = this;
|
|
|
|
+ var ref = [];
|
|
|
|
+ var fechas = [];
|
|
|
|
+
|
|
|
|
+ _.each(move_ids,function(item){
|
|
|
|
+ _.each(self.MoveLine, function(x){
|
|
|
|
+ if(x.move_id[0] == item && x.reconcile_ref != false){
|
|
|
|
+ ref.push(x.reconcile_ref)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ _.each(ref,function(item){
|
|
|
|
+ _.each(self.MoveLine, function(x){
|
|
|
|
+ if(x.reconcile_ref == item && x.credit > 0){
|
|
|
|
+ fechas.push(x.date)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ fechas.sort(function (a, b) {
|
|
|
|
+ if (a> b) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if (a < b) {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return fechas[0]
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ BuildTable: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var data = [];
|
|
|
|
+ var CurrencyBase = self.ResCompany[0].currency_id;
|
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
|
+
|
|
|
|
+ var Contrato = self.getContracts();
|
|
|
|
+
|
|
|
|
+ _.each(Contrato, function(item){
|
|
|
|
+ if(item.state == "open"){ var estado = "En curso"};
|
|
|
|
+ if(item.state == "pending"){ var estado = "A renovar"};
|
|
|
|
+ if(item.state == "close"){ var estado = "Cerrado"};
|
|
|
|
+ if(item.state == "cancelled"){ var estado = "Cancelado"};
|
|
|
|
+
|
|
|
|
+ var AccountInvoice = self.getAccountInvoice(item.code)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ var cuotas_pagadas = 0;
|
|
|
|
+ var cuotas_atrasadas = 0;
|
|
|
|
+
|
|
|
|
+ var move_ids = _.flatten(_.map(_.filter(AccountInvoice,function(item){
|
|
|
|
+ return item.move_id != null;
|
|
|
|
+ }), function(map){
|
|
|
|
+ return map.move_id;
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ var ultimo_pago = self.getUltimoPago(move_ids);
|
|
|
|
+
|
|
|
|
+ _.each(_.filter(AccountInvoice,function(x){
|
|
|
|
+ return x.state == 'paid'
|
|
|
|
+ }),function(each){
|
|
|
|
+ cuotas_pagadas = cuotas_pagadas + 1;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ _.each(_.filter(AccountInvoice,function(x){
|
|
|
|
+ return x.state == 'open' || x.state == 'draft'
|
|
|
|
+ }),function(each){
|
|
|
|
+ cuotas_atrasadas = cuotas_atrasadas + 1;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ var contract_line = self.getContractLine(item.id)
|
|
|
|
+ if(item.cuota_total > 1){var plazo = item.cuota_total}
|
|
|
|
+ else{ var plazo = "Contado"}
|
|
|
|
+
|
|
|
|
+ _.each(contract_line, function(line){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ data.push({
|
|
|
|
+ id:item.id,
|
|
|
|
+ t_nro: line.t_nro,
|
|
|
|
+ t_manzana: line.t_manzana,
|
|
|
|
+ t_lote:line.t_lote,
|
|
|
|
+ partner_name: item.partner_name,
|
|
|
|
+ date_start: moment(item.date_start).format('DD/MM/YYYY'),
|
|
|
|
+ precio_cuota:accounting.formatMoney(line.price_unit, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
|
+
|
|
|
|
+ cuota_total:plazo,
|
|
|
|
+ ultimo_pago:ultimo_pago != null ? moment(ultimo_pago).format('DD/MM/YYYY') : "",
|
|
|
|
+ cuotas_pagadas: cuotas_pagadas,
|
|
|
|
+ cuotas_atrasadas: cuotas_atrasadas,
|
|
|
|
+ state: estado,
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ ===========================
|
|
|
|
+ NO FORMAT
|
|
|
|
+ ===========================
|
|
|
|
+ */
|
|
|
|
+ date_no_format: moment(ultimo_pago).format('YYYY-MM-DD'),
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ ===========================
|
|
|
|
+ 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;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if(date && date != 9999999){
|
|
|
|
+ if(date == 'range'){
|
|
|
|
+ if(desde){
|
|
|
|
+ date = desde.split('/');
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ data = _.flatten(_.filter(data,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date_no_format,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') >= date;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(hasta){
|
|
|
|
+ date = hasta.split('/');
|
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
|
+ data = _.flatten(_.filter(data,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date_no_format,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') <= date;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(date == 'today'){
|
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
|
+ data = _.flatten(_.filter(data,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date_no_format,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') === today;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'yesterday'){
|
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
|
+ data = _.flatten(_.filter(data,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date_no_format,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM-DD') === yesterday;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'currentMonth'){
|
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
|
+ data = _.flatten(_.filter(data,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date_no_format,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM') === currentMonth;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ if(date == 'lastMonth'){
|
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
|
+ data = _.flatten(_.filter(data,function (inv) {
|
|
|
|
+ var utc = moment.utc(inv.date_no_format,'YYYY-MM-DD h:mm:ss A');
|
|
|
|
+ utc = moment(utc).format('YYYY-MM-DD');
|
|
|
|
+ return moment(utc).format('YYYY-MM') === lastMonth;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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');
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ row.push({
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ 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 = 'Situación General de ventas.';
|
|
|
|
+ var pdf_type = 'l';
|
|
|
|
+ var pdf_name = 'situacion_general_ventas_';
|
|
|
|
+
|
|
|
|
+ var pdf_columnStyles = {
|
|
|
|
+ t_nro:{columnWidth: 15, halign:'center'},
|
|
|
|
+ t_manzana:{columnWidth:18, halign:'center'},
|
|
|
|
+ t_lote:{columnWidth: 15, halign:'center'},
|
|
|
|
+ partner_name:{ halign:'left'},
|
|
|
|
+ date_start:{columnWidth: 18,halign:'center'},
|
|
|
|
+ ultimo_pago:{columnWidth: 18,halign:'center'},
|
|
|
|
+ cuota_total:{columnWidth:18,align:'center'},
|
|
|
|
+ cuotas_pagadas:{columnWidth: 20, halign:'center'},
|
|
|
|
+ cuotas_atrasadas:{columnWidth: 20, halign:'center'},
|
|
|
|
+ precio_cuota:{columnWidth: 20, halign:'right'},
|
|
|
|
+ state:{columnWidth: 18, halign:'center'},
|
|
|
|
+ };
|
|
|
|
+ /*
|
|
|
|
+ ============================================================
|
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
|
+ ============================================================
|
|
|
|
+ */
|
|
|
|
+ var filter = self.getFilter();
|
|
|
|
+ var pdf = new reporting.ReportPdfWidgetInmobiliaria(self);
|
|
|
|
+ pdf.drawPDFInmobiliaria(
|
|
|
|
+ _.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 user = self.$el.find('#current-user').val();
|
|
|
|
+ var customer = self.$el.find('#current-customer').val();
|
|
|
|
+ var state = self.$el.find('#current-state').val();
|
|
|
|
+ var type = self.$el.find('#current-type').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(user && user != 9999999){
|
|
|
|
+ var ResUser = _.filter(self.ResUsers, function(item){
|
|
|
|
+ return item.id == user;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title:'Vendedor',
|
|
|
|
+ value: ResUser[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(customer && customer != 9999999){
|
|
|
|
+ var ResPartner = _.filter(self.ResPartner, function(item){
|
|
|
|
+ return item.id == customer;
|
|
|
|
+ });
|
|
|
|
+ filter.push({
|
|
|
|
+ title:'Cliente',
|
|
|
|
+ value: ResPartner[0].name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if(state && state != 9999999){
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Estado',
|
|
|
|
+ value: $('#current-state option:selected').text(),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(type && type != 9999999){
|
|
|
|
+ filter.push({
|
|
|
|
+ title: 'Tipo de Factura',
|
|
|
|
+ value: $('#current-type option:selected').text(),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+}
|