|
@@ -0,0 +1,767 @@
|
|
|
+function report_crm_partners(reporting) {
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportCrmPartnersWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportCrmPartners',
|
|
|
+ rowsData: [],
|
|
|
+ content: [],
|
|
|
+
|
|
|
+ events: {
|
|
|
+ 'click #toolbar > button': 'clickOnAction',
|
|
|
+ 'click #generate': 'fetchGenerate',
|
|
|
+ 'click-row.bs.table #table': 'clickAnalysisDetail',
|
|
|
+ },
|
|
|
+
|
|
|
+ init: function(parent) {
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function() {
|
|
|
+ var date = new model.eiru_reports.ReportDatePickerWidget(self);
|
|
|
+ date.fecthFecha();
|
|
|
+ this.fetchInitial();
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull: function(dato) {
|
|
|
+ var valor = "";
|
|
|
+ if (dato) {
|
|
|
+ valor = dato;
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ clickAnalysisDetail: function(e, row, $element, field) {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ if (field == 'partner_name') {
|
|
|
+ this.do_action({
|
|
|
+ name: "Cliente",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "res.partner",
|
|
|
+ views: [
|
|
|
+ [false, 'form']
|
|
|
+ ],
|
|
|
+ target: 'new',
|
|
|
+ domain: [
|
|
|
+ ['id', '=', row.id]
|
|
|
+ ],
|
|
|
+ context: {},
|
|
|
+ flags: {
|
|
|
+ 'form': {
|
|
|
+ 'action_buttons': false,
|
|
|
+ 'options': {
|
|
|
+ 'mode': 'view'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ res_id: row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (field == 'name') {
|
|
|
+ var model_obj = new model.web.Model('ir.model.data');
|
|
|
+ model_obj.call('get_object_reference', ["crm", "crm_case_form_view_oppor"]).then(function(result) {
|
|
|
+
|
|
|
+ self.do_action({
|
|
|
+ name: "Oportunidad",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "crm.lead",
|
|
|
+ view_mode: 'form',
|
|
|
+ view_type: 'form',
|
|
|
+ views: [
|
|
|
+ [result[1], 'form']
|
|
|
+ ],
|
|
|
+ target: 'new',
|
|
|
+ domain: [
|
|
|
+ ['id', '=', row.crm_id]
|
|
|
+ ],
|
|
|
+ context: {},
|
|
|
+ flags: {
|
|
|
+ 'form': {
|
|
|
+ 'action_buttons': false,
|
|
|
+ 'options': {
|
|
|
+ 'mode': 'view'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ res_id: row.crm_id,
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function() {
|
|
|
+ var self = this;
|
|
|
+ this.fetchResUser().then(function(ResUser) {
|
|
|
+ return ResUser;
|
|
|
+ }).then(function(ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function(ResCompany) {
|
|
|
+ self.ResCompany = ResCompany;
|
|
|
+ if (ResCompany.length > 1) {
|
|
|
+ self.$el.find('#current-company').append('<option value="9999999">Todas las empresas</option>');
|
|
|
+ _.each(ResCompany, function(item) {
|
|
|
+ self.$el.find('#current-company').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.company').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchResStore();
|
|
|
+ }).then(function(ResStore) {
|
|
|
+ self.ResStore = ResStore;
|
|
|
+ if (ResStore.length > 1) {
|
|
|
+ self.$el.find('#current-store').append('<option value="9999999">Todas las sucursales</option>');
|
|
|
+ _.each(ResStore, function(item) {
|
|
|
+ self.$el.find('#current-store').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.store').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchCrmCaseStage();
|
|
|
+ }).then(function(CrmCaseStage) {
|
|
|
+ self.CrmCaseStage = CrmCaseStage
|
|
|
+ if (CrmCaseStage.length > 1) {
|
|
|
+ self.$el.find('#current-crm-stage').append('<option value="9999999">Todas las etapas</option>');
|
|
|
+ _.each(CrmCaseStage, function(item) {
|
|
|
+ self.$el.find('#current-crm-stage').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.crm-stage').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchFirstContact();
|
|
|
+ }).then(function(FirstContact) {
|
|
|
+ self.FirstContact = FirstContact;
|
|
|
+ if (FirstContact.length > 1) {
|
|
|
+ self.$el.find('#current-contact').append('<option value="9999999">Todos los medios</option>');
|
|
|
+ _.each(FirstContact, function(item) {
|
|
|
+ self.$el.find('#current-contact').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ CrmTrackingSource
|
|
|
+ self.$el.find('.contact').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchCrmTrackingSource();
|
|
|
+ }).then(function(CrmTrackingSource) {
|
|
|
+ self.CrmTrackingSource = CrmTrackingSource;
|
|
|
+ if (CrmTrackingSource.length > 1) {
|
|
|
+ self.$el.find('#current-source').append('<option value="9999999">Todos los origenes</option>');
|
|
|
+ _.each(CrmTrackingSource, function(item) {
|
|
|
+ self.$el.find('#current-source').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.contact').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchCrmTrackingCampaign();
|
|
|
+ }).then(function(CrmTrackingCampaign) {
|
|
|
+ self.CrmTrackingCampaign = CrmTrackingCampaign;
|
|
|
+ if (CrmTrackingCampaign.length > 1) {
|
|
|
+ self.$el.find('#current-campaign').append('<option value="9999999">Todas las campañas</option>');
|
|
|
+ _.each(CrmTrackingCampaign, function(item) {
|
|
|
+ self.$el.find('#current-campaign').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.campaign').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchResCountryState();
|
|
|
+ }).then(function(ResCountryState) {
|
|
|
+ self.ResCountryState = ResCountryState;
|
|
|
+ if (ResCountryState.length > 1) {
|
|
|
+ self.$el.find('#current-city').append('<option value="9999999">Todas las ciudades</option>');
|
|
|
+ _.each(ResCountryState, function(item) {
|
|
|
+ self.$el.find('#current-city').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.$el.find('.city').css('display', 'none');
|
|
|
+ }
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency) {
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+
|
|
|
+ });
|
|
|
+ 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.fetchCrmLead().then(function(CrmLead) {
|
|
|
+ return CrmLead;
|
|
|
+ }).then(function(CrmLead) {
|
|
|
+ self.CrmLead = CrmLead;
|
|
|
+ return self.fetchAccountInvoice();
|
|
|
+ }).then(function(AccountInvoice) {
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner) {
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResStore: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var field = ['id', 'name', 'company_id'];
|
|
|
+ var ResStore = new model.web.Model('res.store');
|
|
|
+ ResStore.query(field).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResUser: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', 'store_id'];
|
|
|
+ var domain = [
|
|
|
+ ['id', '=', self.session.uid]
|
|
|
+ ];
|
|
|
+ var ResUser = new model.web.Model('res.users');
|
|
|
+ ResUser.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchFirstContact: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', ];
|
|
|
+ var contact = new model.web.Model('res.partner.primer.contacto');
|
|
|
+ contact.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchCrmCaseStage: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', ];
|
|
|
+ var stage = new model.web.Model('crm.case.stage');
|
|
|
+ stage.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchCrmTrackingSource: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', ];
|
|
|
+ var source = new model.web.Model('crm.tracking.source');
|
|
|
+ source.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchCrmTrackingCampaign: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', ];
|
|
|
+ var campaign = new model.web.Model('crm.tracking.campaign');
|
|
|
+ campaign.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCountryState: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', ];
|
|
|
+ var city = new model.web.Model('res.country.state');
|
|
|
+ city.query(fields).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchCrmLead: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
+ var stage = self.$el.find('#current-crm-stage').val();
|
|
|
+ var source = self.$el.find('#current-source').val();
|
|
|
+ var campaign = self.$el.find('#current-campaign').val();
|
|
|
+ var fields = ['id', 'name', 'partner_id', 'stage_id', 'source_id', 'create_date'];
|
|
|
+ var domain = [
|
|
|
+ ['type', '=', 'opportunity']
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ domain.push(['company_id', '=', parseInt(company)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (store && store != 9999999) {
|
|
|
+ var user_ids = _.map(_.filter(self.ResUser, function(item) {
|
|
|
+ return item.store_id[0] == store;
|
|
|
+ }), function(map) {
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ domain.push(['user_id', 'in', user_ids]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type && type != 9999999) {
|
|
|
+ if (type == 'leads') {
|
|
|
+ domain.push(['stage_id.code', '=', 'LEAD_NO_DELETE'])
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type == 'prospect' || type == 'customer') {
|
|
|
+ domain.push('|', ['stage_id.code', '!=', 'LEAD_NO_DELETE'], ['stage_id.code', '=', null])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stage && stage != 9999999) {
|
|
|
+ domain.push(['stage_id', '=', parseInt(stage)])
|
|
|
+ }
|
|
|
+
|
|
|
+ if (source && source != 9999999) {
|
|
|
+ domain.push(['source_id', '=', parseInt(source)])
|
|
|
+ }
|
|
|
+ if (campaign && campaign != 9999999) {
|
|
|
+ domain.push(['campaign_id', '=', parseInt(campaign)])
|
|
|
+ }
|
|
|
+
|
|
|
+ var contact = new model.web.Model('crm.lead');
|
|
|
+ contact.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getCrmLead: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.CrmLead, function(item) {
|
|
|
+ return item.partner_id[0] == id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountInvoice: function(id) {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', 'partner_id'];
|
|
|
+
|
|
|
+ var partner_ids = _.map(self.CrmLead, function(item) {
|
|
|
+ return item.partner_id[0];
|
|
|
+ });
|
|
|
+
|
|
|
+ var domain = [
|
|
|
+ ['partner_id', 'in', partner_ids],
|
|
|
+ ];
|
|
|
+ var contact = new model.web.Model('account.invoice');
|
|
|
+ contact.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResPartner: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+
|
|
|
+ var fields = ['id', 'ruc', 'name', 'street', 'state_id', 'phone', 'mobile', 'email'];
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
+ var contact = self.$el.find('#current-contact').val();
|
|
|
+ var city = self.$el.find('#current-city').val();
|
|
|
+
|
|
|
+
|
|
|
+ var partner_ids = _.map(self.CrmLead, function(item) {
|
|
|
+ return item.partner_id[0];
|
|
|
+ });
|
|
|
+
|
|
|
+ var domain = [
|
|
|
+ ['active', '=', true],
|
|
|
+ ['id', 'in', partner_ids],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (type && type != 9999999) {
|
|
|
+ if (type == 'leads' || type == 'prospect') {
|
|
|
+ domain.push(['customer', '=', false])
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type == 'customer') {
|
|
|
+ domain.push(['customer', '=', true])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (contact && contact != 9999999) {
|
|
|
+ domain.push(['primer_contacto', '=', parseInt(contact)])
|
|
|
+ }
|
|
|
+
|
|
|
+ if (city && city != 9999999) {
|
|
|
+ domain.push(['state_id', '=', parseInt(city)])
|
|
|
+ }
|
|
|
+
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ ResPartner.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ getResPartner: function() {
|
|
|
+ var self = this;
|
|
|
+ var ResPartner = self.ResPartner;
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
+
|
|
|
+ var ids = _.map(self.AccountInvoice, function(item) {
|
|
|
+ return item.partner_id[0];
|
|
|
+ });
|
|
|
+
|
|
|
+ if (type == 'leads' || type == 'prospect') {
|
|
|
+ ResPartner = _.filter(ResPartner, function(a) {
|
|
|
+ return !_.find(ids, function(b) {
|
|
|
+ return b === a.id;
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (type == 'customer') {
|
|
|
+ ResPartner = _.filter(ResPartner, function(a) {
|
|
|
+ return _.find(ids, function(b) {
|
|
|
+ return b === a.id;
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return ResPartner;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchResCompany: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new model.web.Model('res.company');
|
|
|
+ var field = ['id', 'name', 'currency_id', 'logo'];
|
|
|
+ currency.query(field).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ fetchResCurrency: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id', 'name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
+ var domain = [
|
|
|
+ ['active', '=', true]
|
|
|
+ ];
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getResCompany: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCompany, function(item) {
|
|
|
+ return item.id == id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getResCurrency: function(id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency, function(item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ BuildTable: function() {
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var info = [];
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ var ResCompany = self.getResCompany(company).shift();
|
|
|
+ var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ } else {
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ var ResPartner = self.getResPartner();
|
|
|
+ _.each(ResPartner, function(item) {
|
|
|
+ info = [];
|
|
|
+ var CrmLead = self.getCrmLead(item.id);
|
|
|
+ _.each(CrmLead, function(index) {
|
|
|
+ info.push({
|
|
|
+ crm_id: index.id,
|
|
|
+ create_date: moment(index.create_date).format("DD/MM/YYYY"),
|
|
|
+ name: index.name,
|
|
|
+ stage_name: index.stage_id[1],
|
|
|
+ source_name: index.source_id[1],
|
|
|
+ })
|
|
|
+
|
|
|
+ });
|
|
|
+ data.push({
|
|
|
+ id: item.id,
|
|
|
+ ruc: self.valorNull(item.ruc),
|
|
|
+ partner_name: item.name,
|
|
|
+ street: self.valorNull(item.street),
|
|
|
+ state_id: self.valorNull(item.state_id[1]),
|
|
|
+ phone: self.valorNull(item.phone),
|
|
|
+ mobile: self.valorNull(item.mobile),
|
|
|
+ email: self.valorNull(item.email),
|
|
|
+
|
|
|
+ decimal_places: CurrencyBase.decimal_places,
|
|
|
+ thousands_separator: CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator: CurrencyBase.decimal_separator,
|
|
|
+
|
|
|
+ info: info,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ 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();
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ LOAD BOOTSTRAP TABLE
|
|
|
+ ====================================================================*/
|
|
|
+ loadTable: function(rowsTable) {
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+
|
|
|
+ table.bootstrapTable({
|
|
|
+ data: rowsTable,
|
|
|
+ detailView: true,
|
|
|
+ onExpandRow: function(index, row, $detail) {
|
|
|
+ $detail.html('<div class="panel panel-first-style"><div class="panel-heading panel-header-first-style">Oportunidades del contacto</div><table id="table2"></table></div>').find('table').bootstrapTable({
|
|
|
+ columns: [{
|
|
|
+ field: 'create_date',
|
|
|
+ title: 'Creado el',
|
|
|
+ align: 'left',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'name',
|
|
|
+ title: 'Oportunidad',
|
|
|
+ align: 'left',
|
|
|
+ class: 'hover',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'stage_name',
|
|
|
+ title: 'Estado',
|
|
|
+ align: 'left',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'source_name',
|
|
|
+ title: 'Origen de la Oportunidad',
|
|
|
+ align: 'left',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+
|
|
|
+ data: row.info,
|
|
|
+ })
|
|
|
+ $('#table2').removeClass('table-hover').addClass('table-no-bordered');
|
|
|
+ $('thead').css('background', 'none');
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ table.bootstrapTable('load', rowsTable);
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ PRINT PDF
|
|
|
+ ====================================================================*/
|
|
|
+ clickOnAction: function(e) {
|
|
|
+ var self = this;
|
|
|
+ var ResCompany;
|
|
|
+ var action = this.$el.find(e.target).val();
|
|
|
+ var company = $('#current-company').val();
|
|
|
+ if (company && company != 9999999) {
|
|
|
+ ResCompany = self.getResCompany(company).shift();
|
|
|
+ var CurrencyBase = self.getResCurrency(ResCompany.currency_id[0]).shift();
|
|
|
+ } else {
|
|
|
+ ResCompany = self.ResCompany[0];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ }
|
|
|
+ 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 = 'Contactos del CRM.';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'contactos_del_crm_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ ruc: {
|
|
|
+ columnWidth: 18,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ partner_name: {
|
|
|
+ columnWidth: 25,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ street: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ state_id: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ phone: {
|
|
|
+ columnWidth: 25,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ mobile: {
|
|
|
+ columnWidth: 25,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ email: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var filter = self.getFilter();
|
|
|
+ var pdf = new model.eiru_reports.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 stage = self.$el.find('#current-crm-stage').val();
|
|
|
+ var type = self.$el.find('#current-type').val();
|
|
|
+ var contact = self.$el.find('#current-contact').val();
|
|
|
+ var source = self.$el.find('#current-source').val();
|
|
|
+ var campaign = self.$el.find('#current-campaign').val();
|
|
|
+ var city = self.$el.find('#current-city').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 (stage && stage != 9999999) {
|
|
|
+ var CrmCaseStage = _.filter(self.CrmCaseStage, function(item) {
|
|
|
+ return item.id == stage;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Etapa',
|
|
|
+ value: CrmCaseStage[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type && type != 9999999) {
|
|
|
+ filter.push({
|
|
|
+ title: 'Tipo de contacto',
|
|
|
+ value: $('#current-type option:selected').text(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (contact && contact != 9999999) {
|
|
|
+ var FirstContact = _.filter(self.FirstContact, function(item) {
|
|
|
+ return item.id == contact;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Primer contacto',
|
|
|
+ value: FirstContact[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (source && source != 9999999) {
|
|
|
+ var CrmTrackingSource = _.filter(self.CrmTrackingSource, function(item) {
|
|
|
+ return item.id == source;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Origen',
|
|
|
+ value: CrmTrackingSource[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (campaign && campaign != 9999999) {
|
|
|
+ var CrmTrackingCampaign = _.filter(self.CrmTrackingCampaign, function(item) {
|
|
|
+ return item.id == campaign;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Campaña',
|
|
|
+ value: CrmTrackingCampaign[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (city && city != 9999999) {
|
|
|
+ var ResCountryState = _.filter(self.ResCountryState, function(item) {
|
|
|
+ return item.id == city;
|
|
|
+ });
|
|
|
+ filter.push({
|
|
|
+ title: 'Ciudad',
|
|
|
+ value: ResCountryState[0].name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return filter;
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|