|
@@ -0,0 +1,584 @@
|
|
|
+function report_session(reporting){
|
|
|
+ "use strict";
|
|
|
+
|
|
|
+ var model = openerp;
|
|
|
+
|
|
|
+ reporting.ReportSessionWidget = reporting.Base.extend({
|
|
|
+ template: 'ReportSession',
|
|
|
+ rowsData :[],
|
|
|
+ content :[],
|
|
|
+ modules: ['point_of_sale'],
|
|
|
+
|
|
|
+ events:{
|
|
|
+ 'click #toolbar > button' : 'clickOnAction',
|
|
|
+ 'click #generate' : 'fetchGenerate',
|
|
|
+ 'change #current-company' : 'updateSelections',
|
|
|
+ 'change #current-attribute' : 'updateAttributeSelections',
|
|
|
+ 'change #current-period' : 'updatePeriodSelections',
|
|
|
+ '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');
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function () {
|
|
|
+ var self = this;
|
|
|
+ self.fetchResCompany().then(function (ResCompany) {
|
|
|
+ return ResCompany;
|
|
|
+ }).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;
|
|
|
+ return self.fetchPosConfig();
|
|
|
+ }).then(function(PosConfig){
|
|
|
+ self.PosConfig = PosConfig;
|
|
|
+ self.$el.find('#current-config').append('<option value="9999999">Todas las Terminales</option>');
|
|
|
+ _.each(PosConfig,function(item){
|
|
|
+ self.$el.find('#current-config').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.fetchPosSession().then(function(PosSession) {
|
|
|
+ return PosSession;
|
|
|
+ }).then(function (PosSession) {
|
|
|
+ self.PosSession = PosSession;
|
|
|
+ return self.fetchPosOrder();
|
|
|
+ }).then(function (PosOrder){
|
|
|
+ self.PosOrder = PosOrder;
|
|
|
+ return self.BuildTable();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ POS CONFIG
|
|
|
+ ====================================================================*/
|
|
|
+ fetchPosConfig: function () {
|
|
|
+ var self = this;
|
|
|
+ var domain = [
|
|
|
+ ['state','in',['active']],
|
|
|
+ ];
|
|
|
+ var PosConfig = new model.web.Model('pos.config');
|
|
|
+ return PosConfig.call('getPosConfig',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ POS SESSION
|
|
|
+ ====================================================================*/
|
|
|
+ fetchPosSession: function () {
|
|
|
+ var self = this;
|
|
|
+ var store = self.$el.find('#current-store').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[0] == store;
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ var config_ids = _.map(_.filter(self.PosConfig,function (item) {
|
|
|
+ return _.contains(journal_ids, item.journal_id[0])
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+
|
|
|
+ }else{
|
|
|
+ var journal_ids = _.flatten(_.map(self.AccountJournal, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var config_ids = _.map(_.filter(self.PosConfig,function (item) {
|
|
|
+ return _.contains(journal_ids, item.journal_id[0])
|
|
|
+ }), function(map){
|
|
|
+ return map.id;
|
|
|
+ });
|
|
|
+ };
|
|
|
+ var domain = [
|
|
|
+ ['state','in',['opened','closed']],
|
|
|
+ ['config_id','in',config_ids],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if(date && date != 9999999){
|
|
|
+
|
|
|
+ if(date == 'range'){
|
|
|
+ if(desde){
|
|
|
+ var date = desde.split('/')
|
|
|
+ date = date[2]+"-"+date[1]+"-"+date[0]+" 00:00:00";
|
|
|
+ var utc = moment.utc(date,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var first = moment('00:00:00','HH:mm:ss');
|
|
|
+ var second = moment(moment(utc._d,'HH:mm:ss'));
|
|
|
+ var data = moment.duration(first - second);
|
|
|
+ date = moment(date).add(data._data.hours,'hours').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ domain.push(['start_at','>=',date]);
|
|
|
+ }
|
|
|
+ if(hasta){
|
|
|
+ var date = hasta.split('/')
|
|
|
+ date = date[2]+"-"+date[1]+"-"+date[0]+" 00:00:00";
|
|
|
+ var utc = moment.utc(date,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var first = moment('00:00:00','HH:mm:ss');
|
|
|
+ var second = moment(moment(utc._d,'HH:mm:ss'));
|
|
|
+ var data = moment.duration(first - second);
|
|
|
+ date = moment(date).add(data._data.hours,'hours').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ date = moment(date).add(1,'days').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ domain.push(['start_at','<=',date]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'today'){
|
|
|
+ var today = moment().format('YYYY-MM-DD 00:00:00');
|
|
|
+ var utc = moment.utc(today,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var first = moment('00:00:00','HH:mm:ss');
|
|
|
+ var second = moment(moment(utc._d,'HH:mm:ss'));
|
|
|
+ var data = moment.duration(first - second);
|
|
|
+ today = moment(today).add(data._data.hours,'hours').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ domain.push(['start_at','>=',today]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'yesterday'){
|
|
|
+ var today = moment().format('YYYY-MM-DD 00:00:00');
|
|
|
+ var yesterday = moment().add(-2,'days').format('YYYY-MM-DD 00:00:00');
|
|
|
+ var utc = moment.utc(yesterday,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var first = moment('00:00:00','HH:mm:ss');
|
|
|
+ var second = moment(moment(utc._d,'HH:mm:ss'));
|
|
|
+ var data = moment.duration(first - second);
|
|
|
+ yesterday = moment(yesterday).add(data._data.hours,'hours').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ today = moment(today).add(data._data.hours,'hours').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ domain.push(['start_at','>=',yesterday]);
|
|
|
+ domain.push(['start_at','<=',today]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'currentMonth'){
|
|
|
+ var currentMonth = moment().format('YYYY-MM-01 00:00:00');
|
|
|
+ var utc = moment.utc(currentMonth,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var first = moment('00:00:00','HH:mm:ss');
|
|
|
+ var second = moment(moment(utc._d,'HH:mm:ss'));
|
|
|
+ var data = moment.duration(first - second);
|
|
|
+ currentMonth = moment(currentMonth).add(data._data.hours,'hours').format('YYYY-MM');
|
|
|
+ domain.push(['start_at','like',currentMonth]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date == 'lastMonth'){
|
|
|
+ var lastMonth = moment().add(-1,'months').format('YYYY-MM-01 00:00:00');
|
|
|
+ var utc = moment.utc(lastMonth,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ var first = moment('00:00:00','HH:mm:ss');
|
|
|
+ var second = moment(moment(utc._d,'HH:mm:ss'));
|
|
|
+ var data = moment.duration(first - second);
|
|
|
+ lastMonth = moment(lastMonth).add(data._data.hours,'hours').format('YYYY-MM');
|
|
|
+ domain.push(['start_at','like',lastMonth]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var PosSession = new model.web.Model('pos.session');
|
|
|
+ return PosSession.call('getPosSession',[domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ POS ORDER
|
|
|
+ ====================================================================*/
|
|
|
+ fetchPosOrder: function () {
|
|
|
+ var self = this;
|
|
|
+ var session_ids = _.flatten(_.map(self.PosSession, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var domain = [
|
|
|
+ ['session_id','in',session_ids],
|
|
|
+ ];
|
|
|
+ var PosOrder = new model.web.Model('account.invoice');
|
|
|
+ return PosOrder.call('getPosOrder',[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>');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ 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
|
|
|
+ ====================================================================*/
|
|
|
+ getPosOrder: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.PosOrder,function (item) {
|
|
|
+ return item.session_id[0] === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /*====================================================================
|
|
|
+ BUILD
|
|
|
+ ====================================================================*/
|
|
|
+ BuildTable: function(){
|
|
|
+ var self = this;
|
|
|
+ console.log(self);
|
|
|
+ var data = [];
|
|
|
+ var PosSession = self.PosSession;
|
|
|
+ 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 info = [];
|
|
|
+ _.each(PosSession,function(item) {
|
|
|
+ info = [];
|
|
|
+ var PosOrder = self.getPosOrder(item.id);
|
|
|
+ if(PosOrder.length > 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 HH:mm:ss'),
|
|
|
+ customer: self.valorNull(index.partner_id[1]),
|
|
|
+ amount: accounting.formatMoney(index.amount_total_currency,'',CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+ var utc_start;
|
|
|
+ var utc_stop = ' ';
|
|
|
+ utc_start = moment.utc(item.start_at,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ utc_start = moment(utc_start._d).format('DD/MM/YYYY HH:mm:ss');
|
|
|
+
|
|
|
+ if(item.stop_at){
|
|
|
+ utc_stop = moment.utc(item.stop_at,'YYYY-MM-DD h:mm:ss A');
|
|
|
+ utc_stop = moment(utc_stop._d).format('DD/MM/YYYY HH:mm:ss');
|
|
|
+ };
|
|
|
+ data.push({
|
|
|
+ id: item.id,
|
|
|
+ config_id: item.config_id[1],
|
|
|
+ name: item.name,
|
|
|
+ user_id: item.user_id[1],
|
|
|
+ start_at: utc_start,
|
|
|
+ stop_at: utc_stop,
|
|
|
+ /*
|
|
|
+ ================================
|
|
|
+ TOTAL FOOTER CONFIGURATION
|
|
|
+ ================================
|
|
|
+ */
|
|
|
+ decimal_places : CurrencyBase.decimal_places,
|
|
|
+ thousands_separator: CurrencyBase.thousands_separator,
|
|
|
+ decimal_separator: CurrencyBase.decimal_separator,
|
|
|
+ /*
|
|
|
+ ================================
|
|
|
+ DATA
|
|
|
+ ================================
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ 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,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|