|
@@ -0,0 +1,989 @@
|
|
|
+function report_doctor_ranking(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportDoctorRankingWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportDoctorRanking',
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+ modules: ['product_brand','point_of_sale'],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ 'click-row.bs.table #table' : 'clickAnalysisDetail',
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-attribute' : 'updateAttributeSelections',
|
|
|
+ 'change #current-store' : 'updateJournalSelections',
|
|
|
+ '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;
|
|
|
+ },
|
|
|
+
|
|
|
+ checkModel : function(model){
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.IrModuleModule,function(item){
|
|
|
+ return item.name === model
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ 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');
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ clickAnalysisDetail: function(e, row, $element,field){
|
|
|
+ if (field == 'product'){
|
|
|
+ this.do_action({
|
|
|
+ name:"Producto",
|
|
|
+ type: 'ir.actions.act_window',
|
|
|
+ res_model: "product.product",
|
|
|
+ views: [[false,'form']],
|
|
|
+ target: 'new',
|
|
|
+ domain: [['id','=', row.id]],
|
|
|
+ context: {},
|
|
|
+ flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ res_id: row.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ e.stopImmediatePropagation();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fecthIrModuleModule().then(function (IrModuleModule) {
|
|
|
+ return IrModuleModule;
|
|
|
+ }).then(function(IrModuleModule) {
|
|
|
+ self.IrModuleModule = IrModuleModule;
|
|
|
+ return self.fetchResUser();
|
|
|
+ }).then(function (ResUser) {
|
|
|
+ self.ResUser = ResUser;
|
|
|
+ self.fecthCheckType();
|
|
|
+ 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.fetchAccountJournal();
|
|
|
+ }).then(function(AccountJournal){
|
|
|
+ self.AccountJournal = AccountJournal;
|
|
|
+ if(AccountJournal.length > 1){
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
+ _.each(AccountJournal,function(item){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ self.$el.find('.journal').css('display','none');
|
|
|
+ }
|
|
|
+ return self.fetchAccountPeriod();
|
|
|
+ }).then(function(AccountPeriod){
|
|
|
+ self.AccountPeriod = AccountPeriod;
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todas los periodos</option>');
|
|
|
+ _.each(AccountPeriod,function(item){
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ 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.fetchAccountInvoice().then(function(AccountInvoice) {
|
|
|
+ return AccountInvoice;
|
|
|
+ }).then(function (AccountInvoice) {
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fetchPosOrder();
|
|
|
+ }).then(function (PosOrder){
|
|
|
+ self.PosOrder = PosOrder;
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function (ResPartner){
|
|
|
+ self.ResPartner = ResPartner;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ IR MODULE
|
|
|
+ =====================================================================*/
|
|
|
+ fecthIrModuleModule: 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
|
|
|
+ =====================================================================*/
|
|
|
+ fecthCheckType: function(){
|
|
|
+ var self = this;
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+ if(modules.length == 0){
|
|
|
+ self.$el.find('.type').css('display','none');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ USER
|
|
|
+ =====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES COMPANY
|
|
|
+ ====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES STORE
|
|
|
+ ====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ ACCOUNT JOURNAL
|
|
|
+ ====================================================================*/
|
|
|
+ fetchAccountJournal: function(){
|
|
|
+ var self = this;
|
|
|
+ var domain = [['active','=',true],['type','=','sale']];
|
|
|
+ var AccountJournal = new model.web.Model('account.journal');
|
|
|
+ return AccountJournal.call('getAccountJournal',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*=====================================================================
|
|
|
+ ACCOUNT PERIOD
|
|
|
+ =====================================================================*/
|
|
|
+ fetchAccountPeriod: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var domain = [['special','=',false]];
|
|
|
+ var field =['id', 'name', 'date_start','date_stop','company_id'];
|
|
|
+ var AccountPeriod = new model.web.Model('account.period');
|
|
|
+ AccountPeriod.query(field).filter(domain).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES CURRENCY
|
|
|
+ ====================================================================*/
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ ACCOUNT INVOICE
|
|
|
+ ====================================================================*/
|
|
|
+ fetchAccountInvoice: function () {
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+
|
|
|
+ if(store && store != 9999999){
|
|
|
+ var journal_ids = _.map(_.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.store_ids == store;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ var domain = [
|
|
|
+ ['state', 'in',['open','paid']],
|
|
|
+ ['type', '=', 'out_invoice'],
|
|
|
+ ['journal_id','in',journal_ids],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ domain.push(['company_id','=',parseInt(company)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ domain.push(['journal_id','=',parseInt(journal)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(period && period != 9999999){
|
|
|
+ domain.push(['period_id','=',parseInt(period)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date && date != 9999999){
|
|
|
+
|
|
|
+ if(desde){
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ domain.push(['date_invoice','>=',date]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(hasta){
|
|
|
+ var date = hasta.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ domain.push(['date_invoice','<=',date]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ domain.push(['date_invoice','=',today]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ domain.push(['date_invoice','=',yesterday]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ domain.push(['date_invoice','like',currentMonth]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ domain.push(['date_invoice','like',lastMonth]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var AccountInvoice = new model.web.Model('account.invoice');
|
|
|
+ return AccountInvoice.call('getAccountInvoice',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ POS ORDER
|
|
|
+ ====================================================================*/
|
|
|
+ /*
|
|
|
+ TO DO
|
|
|
+ **************************************************
|
|
|
+ Mejorar los filtros de fechas en el modelo POS ORDER - Actualmente
|
|
|
+ es necesario filtrar al momento de hacer la consulta para reducir
|
|
|
+ la carga de la consulta y la segunda vez que se filtra es para
|
|
|
+ analizar los datos con la zona horaria.
|
|
|
+ */
|
|
|
+ fetchPosOrder: function () {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var type = $('#current-type').val();
|
|
|
+ var modules = self.checkModel('point_of_sale');
|
|
|
+ if (type && modules.length > 0){
|
|
|
+ if(type != 'sale'){
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ var journal = self.$el.find('#current-journal').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+
|
|
|
+ if(store && store != 9999999){
|
|
|
+ var journal_ids = _.map(_.filter(self.AccountJournal,function (item) {
|
|
|
+ return item.store_ids == store;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ var domain = [
|
|
|
+ ['state', 'not in',['draft','cancel']],
|
|
|
+ ['sale_journal','in',journal_ids],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(company && company != 9999999){
|
|
|
+ domain.push(['company_id','=',parseInt(company)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(journal && journal != 9999999){
|
|
|
+ domain.push(['sale_journal','=',parseInt(journal)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date && date != 9999999){
|
|
|
+
|
|
|
+ if(desde){
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ domain.push(['date_order','>=',date]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(hasta){
|
|
|
+ var date = hasta.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ domain.push(['date_order','<=',date]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD 00:00:00');
|
|
|
+ domain.push(['date_order','>=',today]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD 00:00:00');
|
|
|
+ domain.push(['date_order','>=',yesterday]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ domain.push(['date_order','like',currentMonth]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ domain.push(['date_order','like',lastMonth]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var PosOrder = new model.web.Model('account.invoice');
|
|
|
+ return PosOrder.call('getPosOrder',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ var PosOrder = [];
|
|
|
+ return PosOrder;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ RES PARTNER
|
|
|
+ ====================================================================*/
|
|
|
+ fetchResPartner: function(){
|
|
|
+ var self = this;
|
|
|
+ var domain = [['active','=',true]];
|
|
|
+ var ResPartner = new model.web.Model('res.partner');
|
|
|
+ return ResPartner.call('getResPartnerMedic',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ UPDATE SELECTIONS
|
|
|
+ ====================================================================*/
|
|
|
+ updateSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var company = self.$el.find('#current-company').val();
|
|
|
+ if(company != 9999999){
|
|
|
+ /*===================
|
|
|
+ STORE SELECTION
|
|
|
+ ===================*/
|
|
|
+ var 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>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*====================
|
|
|
+ PERIOD SELECTION
|
|
|
+ ====================*/
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todos los periodos</option>');
|
|
|
+ _.each(self.AccountPeriod,function(item){
|
|
|
+ if(parseFloat(company) == item.company_id[0]){
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*===================
|
|
|
+ STORE SELECTION
|
|
|
+ ===================*/
|
|
|
+ var 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>');
|
|
|
+ });
|
|
|
+ /*====================
|
|
|
+ PERIOD SELECTION
|
|
|
+ ====================*/
|
|
|
+ var period = self.$el.find('#current-period').empty();
|
|
|
+ self.$el.find('#current-period').append('<option value="9999999">Todas los periodos</option>');
|
|
|
+ _.each(self.AccountPeriod,function(item){
|
|
|
+ self.$el.find('#current-period').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateAttributeSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var attribute = self.$el.find('#current-attribute').val();
|
|
|
+ if(attribute != 9999999){
|
|
|
+ /*=============================
|
|
|
+ ATTRIBUTE VALUE SELECTION
|
|
|
+ =============================*/
|
|
|
+ var attribute_value = self.$el.find('#current-attribute-value').empty();
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(self.ProductAttributeValue,function(item){
|
|
|
+ if(parseFloat(attribute) == item.attribute_id[0]){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*=============================
|
|
|
+ ATTRIBUTE VALUE SELECTION
|
|
|
+ =============================*/
|
|
|
+ var attribute_value = self.$el.find('#current-attribute-value').empty();
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="9999999">Todos los valores de atributos</option>');
|
|
|
+ _.each(self.ProductAttributeValue,function(item){
|
|
|
+ self.$el.find('#current-attribute-value').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateJournalSelections: function () {
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').val();
|
|
|
+ if(store != 9999999){
|
|
|
+ /*=============================
|
|
|
+ ACCOUNT JOURNAL SELECTION
|
|
|
+ =============================*/
|
|
|
+ var journal = self.$el.find('#current-journal').empty();
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
+ _.each(self.AccountJournal,function(item){
|
|
|
+ if(parseFloat(store) == item.store_ids){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ /*=============================
|
|
|
+ ACCOUNT JOURNAL SELECTION
|
|
|
+ =============================*/
|
|
|
+ var journal = self.$el.find('#current-journal').empty();
|
|
|
+ self.$el.find('#current-journal').append('<option value="9999999">Todas las facturas</option>');
|
|
|
+ _.each(self.AccountJournal,function(item){
|
|
|
+ self.$el.find('#current-journal').append('<option value="' + item.id + '">' + item.name + '</option>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES COMPANY
|
|
|
+ ====================================================================*/
|
|
|
+ getResCompany: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCompany,function (item) {
|
|
|
+ return item.id == id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES CURRENCY BASE
|
|
|
+ ====================================================================*/
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET POS ORDER LINE
|
|
|
+ ====================================================================*/
|
|
|
+ getPosOrder: function (id) {
|
|
|
+ var self = this;
|
|
|
+ var content = []
|
|
|
+ var period = self.$el.find('#current-period').val();
|
|
|
+ var date = self.$el.find('#current-date').val();
|
|
|
+ var desde = self.$el.find('#from').val();
|
|
|
+ var hasta = self.$el.find('#to').val();
|
|
|
+ var partner_ids = _.map(_.filter(self.ResPartner,function (item) {
|
|
|
+ return item.medic[0] === id;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ content = _.flatten(_.filter(self.PosOrder,function (item) {
|
|
|
+ return _.contains(partner_ids, item.partner_id[0]);
|
|
|
+ }));
|
|
|
+
|
|
|
+ /*
|
|
|
+ =================================================
|
|
|
+ FILTRAR PERIODO
|
|
|
+ =================================================
|
|
|
+ */
|
|
|
+ if(period && period != 9999999){
|
|
|
+ var periodo = _.flatten(_.filter(self.AccountPeriod,function (item) {
|
|
|
+ return item.id == period;
|
|
|
+ }));
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM') === moment(periodo[0].date_start).format('YYYY-MM');
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ =================================================
|
|
|
+ FILTRAR POR FECHAS
|
|
|
+ =================================================
|
|
|
+ */
|
|
|
+ if(date && date != 9999999){
|
|
|
+
|
|
|
+ if(desde){
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM-DD') >= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(hasta){
|
|
|
+ var date = hasta.split('/')
|
|
|
+ date = (date[2]+"-"+date[1]+"-"+date[0]);
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM-DD') <= date;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM-DD') == today;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM-DD') == yesterday;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM') == currentMonth;
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM');
|
|
|
+ content = _.flatten(_.filter(content,function (item) {
|
|
|
+ var utc = moment.utc(item.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ return moment(utc._d).format('YYYY-MM') == lastMonth;
|
|
|
+ }));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET ACCOUNT INVOICE
|
|
|
+ ====================================================================*/
|
|
|
+ getAccountInvoice: function (id) {
|
|
|
+ var self = this;
|
|
|
+ var partner_ids = _.map(_.filter(self.ResPartner,function (item) {
|
|
|
+ return item.medic[0] === id;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ return _.flatten(_.filter(self.AccountInvoice,function (item) {
|
|
|
+ return _.contains(partner_ids, item.partner_id[0]);
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ GET RES DOCTOR
|
|
|
+ ====================================================================*/
|
|
|
+ getResDoctor: function () {
|
|
|
+ var self = this;
|
|
|
+ var content = self.ResPartner;
|
|
|
+ content = _.filter(content,function (item) {
|
|
|
+ return item.is_medic
|
|
|
+ });
|
|
|
+ return content;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ BUILD
|
|
|
+ ====================================================================*/
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var ResDoctor = self.getResDoctor();
|
|
|
+ console.log(self);
|
|
|
+ var type = $('#current-type').val();
|
|
|
+ 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();
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ==========================================
|
|
|
+ RECORRER DOCTORES
|
|
|
+ ==========================================
|
|
|
+ */
|
|
|
+ _.each(ResDoctor,function(item) {
|
|
|
+ var AccountInvoice = self.getAccountInvoice(item.id);
|
|
|
+ var PosOrder = self.getPosOrder(item.id);
|
|
|
+ var info = [];
|
|
|
+ /*
|
|
|
+ ==========================================
|
|
|
+ ACCOUNT INVOICE
|
|
|
+ ==========================================
|
|
|
+ */
|
|
|
+ var invoice_amount = 0;
|
|
|
+ if(type == 'sale' || type == 9999999){
|
|
|
+ if(AccountInvoice.length > 0){
|
|
|
+ /*
|
|
|
+ ==========================================
|
|
|
+ AMOUNT TOTAL
|
|
|
+ ==========================================
|
|
|
+ */
|
|
|
+ invoice_amount = _.reduce(_.map(AccountInvoice, function (map) {
|
|
|
+ return map.amount_total_currency
|
|
|
+ }), function (meno,num) {
|
|
|
+ return meno + num
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ _.each(AccountInvoice,function(index) {
|
|
|
+ info.push({
|
|
|
+ number: index.number,
|
|
|
+ date: moment(index.date_invoice).format('DD/MM/YYYY'),
|
|
|
+ customer: index.partner_id[1],
|
|
|
+ amount: accounting.formatMoney(index.amount_total_currency,'',CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ ==========================================
|
|
|
+ POS ORDER
|
|
|
+ ==========================================
|
|
|
+ */
|
|
|
+ var pos_amount = 0;
|
|
|
+ if(PosOrder.length > 0){
|
|
|
+ /*
|
|
|
+ ==========================================
|
|
|
+ AMOUNT TOTAL
|
|
|
+ ==========================================
|
|
|
+ */
|
|
|
+ pos_amount = _.reduce(_.map(PosOrder, function (map) {
|
|
|
+ return map.amount_total_currency
|
|
|
+ }), function (meno,num) {
|
|
|
+ return meno + num
|
|
|
+ }, 0);
|
|
|
+ _.each(PosOrder,function(index) {
|
|
|
+ var utc = moment.utc(index.date_order,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ info.push({
|
|
|
+ number: index.name,
|
|
|
+ date: moment(utc._d).format('DD/MM/YYYY'),
|
|
|
+ customer: index.partner_id[1],
|
|
|
+ amount: accounting.formatMoney(index.amount_total_currency,'',CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ var amount = invoice_amount + pos_amount;
|
|
|
+
|
|
|
+ if(amount > 0){
|
|
|
+ data.push({
|
|
|
+ id: item.id,
|
|
|
+ medic: item.name,
|
|
|
+ qty_total: accounting.formatNumber((PosOrder.length + AccountInvoice.length),0,'.',','),
|
|
|
+ total_amount: accounting.formatMoney(pos_amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ /*
|
|
|
+ ================================
|
|
|
+ VALORES SIN FORMATEAR
|
|
|
+ ================================
|
|
|
+ */
|
|
|
+ qty: (PosOrder.length + AccountInvoice.length),
|
|
|
+ amount: pos_amount,
|
|
|
+ /*
|
|
|
+ ================================
|
|
|
+ TOTAL FOOTER CONFIGURATION
|
|
|
+ ================================
|
|
|
+ */
|
|
|
+ decimal_places : CurrencyBase.decimal_places,
|
|
|
+ thousands_separator: CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator: CurrencyBase.decimal_separator,
|
|
|
+ /*
|
|
|
+ ================================
|
|
|
+ DATA
|
|
|
+ ================================
|
|
|
+ */
|
|
|
+ info: info,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data.sort(function(a, b) {
|
|
|
+ return b.amount - a.amount
|
|
|
+ });
|
|
|
+ self.content = data;
|
|
|
+ self.loadTable(data);
|
|
|
+ self.CallCharts(data,CurrencyBase);
|
|
|
+ },
|
|
|
+ /*
|
|
|
+ ======================================================================
|
|
|
+ LLAMAR LOS GRAFICOS
|
|
|
+ ======================================================================
|
|
|
+ */
|
|
|
+ CallCharts: function(data,CurrencyBase){
|
|
|
+ var self = this;
|
|
|
+ /*
|
|
|
+ ================================================
|
|
|
+ GRAFICO DE BARRAS
|
|
|
+ ================================================
|
|
|
+ */
|
|
|
+ var BarChart = new model.eiru_reports.ReportChartWidget(self);
|
|
|
+ var rank = 10;
|
|
|
+ var item;
|
|
|
+ var label = [];
|
|
|
+ var body = [];
|
|
|
+ for (var i = 0; i < rank; i++) {
|
|
|
+ if (data[i]){
|
|
|
+ item = data[i];
|
|
|
+ }else{
|
|
|
+ item = {};
|
|
|
+ item.medic = "N/A";
|
|
|
+ item.amount = 0;
|
|
|
+ }
|
|
|
+ label.push(item.medic.trim());
|
|
|
+ body.push(item.amount);
|
|
|
+ }
|
|
|
+ BarChart.fetchBarChart(data,CurrencyBase,label,body);
|
|
|
+
|
|
|
+ /*
|
|
|
+ ================================================
|
|
|
+ GRAFICO CIRCULAR
|
|
|
+ ================================================
|
|
|
+ */
|
|
|
+ var PieChart = new model.eiru_reports.ReportChartWidget(self);
|
|
|
+ var rank = 9;
|
|
|
+ var item;
|
|
|
+ var label = [];
|
|
|
+ var body = [];
|
|
|
+ var amount_total = _.reduce(_.map(data, function (map) {
|
|
|
+ return map.amount
|
|
|
+ }), function (meno,num) {
|
|
|
+ return meno + num
|
|
|
+ }, 0);
|
|
|
+ for (var i = 0; i < rank; i++) {
|
|
|
+ if (data[i]){
|
|
|
+ item = data[i];
|
|
|
+ }else{
|
|
|
+ item = {};
|
|
|
+ item.medic = "N/A";
|
|
|
+ item.amount = 0;
|
|
|
+ }
|
|
|
+ label.push(item.medic.trim());
|
|
|
+ body.push((item.amount/amount_total)*100);
|
|
|
+ }
|
|
|
+ var num = 0;
|
|
|
+ for (var i = 9; i < data.length; i++) {
|
|
|
+ num += data[i].amount;
|
|
|
+ }
|
|
|
+ if(num > 0){
|
|
|
+ label.push('Otros Doctores');
|
|
|
+ body.push((num/amount_total)*100);
|
|
|
+ }
|
|
|
+ PieChart.fetchPieChart(data,CurrencyBase,label,body);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ self.rowsData = rowsTable;
|
|
|
+ var table = this.$el.find('#table');
|
|
|
+ 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');
|
|
|
+
|
|
|
+ var qty = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.qty;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ var amount = _.reduce(_.map(row, function (map) {
|
|
|
+ return map.amount;
|
|
|
+ }), function (memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ });
|
|
|
+
|
|
|
+ row.push({
|
|
|
+ medic: 'Totales',
|
|
|
+ qty_total: qty,
|
|
|
+ total_amount: accounting.formatMoney(amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ })
|
|
|
+
|
|
|
+ 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 = 'Ranking de Doctores';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'ranking_de_doctores';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ product :{halign:'left'},
|
|
|
+ qty_total :{columnWidth: 30, halign:'right'},
|
|
|
+ total_amount:{columnWidth: 30, halign:'right'},
|
|
|
+ };
|
|
|
+ /*
|
|
|
+ ============================================================
|
|
|
+ LLAMAR FUNCION DE IMPRESION
|
|
|
+ ============================================================
|
|
|
+ */
|
|
|
+ var pdf = new model.eiru_reports.ReportPdfWidget(self);
|
|
|
+ pdf.drawPDF(
|
|
|
+ _.flatten(getColumns),
|
|
|
+ row,
|
|
|
+ ResCompany,
|
|
|
+ pdf_title,
|
|
|
+ pdf_type,
|
|
|
+ pdf_name,
|
|
|
+ pdf_columnStyles,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|