소스 검색

[ADD] filtro de fechas

deisy 6 년 전
부모
커밋
1940c6d6c8
2개의 변경된 파일126개의 추가작업 그리고 0개의 파일을 삭제
  1. 98 0
      static/src/js/reports/report_salesman_commission.js
  2. 28 0
      static/src/reports/report_salesman_commission.xml

+ 98 - 0
static/src/js/reports/report_salesman_commission.js

@@ -13,6 +13,8 @@ function report_salesman_commission(reporting) {
       'click #generate': 'fetchGenerate',
       'change #current-company': 'updateSelections',
       'change #current-store': 'updateUsers',
+      'change #current-period' : 'updatePeriodSelections',
+      'change #current-date' : 'ShowDateRange',
     },
 
     init: function(parent) {
@@ -37,6 +39,17 @@ function report_salesman_commission(reporting) {
       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');
+      }
+    },
+
     checkModel: function(model) {
       var self = this;
       return _.filter(self.IrModuleModule, function(item) {
@@ -239,6 +252,9 @@ function report_salesman_commission(reporting) {
       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 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) {
@@ -266,6 +282,38 @@ function report_salesman_commission(reporting) {
         domain.push(['period_id', '=', parseInt(period)]);
       }
 
+      if(date && date != 9999999){
+          if(date == 'range'){
+              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 field = ['id', 'number', 'state', 'type', 'amount_total', 'user_id', 'company_id', 'period_id', 'date_invoice', 'journal_id', 'credito', 'contado'];
       var AccountInvoice = new model.web.Model('account.invoice');
       AccountInvoice.query(field).filter(domain).all().then(function(results) {
@@ -354,6 +402,19 @@ function report_salesman_commission(reporting) {
       }
     },
 
+    updatePeriodSelections: function () {
+      var self = this;
+      var period = self.$el.find('#current-period').val();
+      if(period != 9999999){
+        self.$el.find('#current-date').val(9999999);
+        self.$el.find('#current-date').prop('disabled','disabled');
+        self.$el.find('.datepicker').css('display','none');
+      }else{
+        self.$el.find('#current-date').prop('disabled',false);
+      }
+    },
+
+
     /*====================================================================
         GET RES COMPANY
     ====================================================================*/
@@ -572,6 +633,9 @@ function report_salesman_commission(reporting) {
       var store = self.$el.find('#current-store').val();
       var user = self.$el.find('#current-user').val();
       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 filter = [];
       if (company && company != 9999999) {
@@ -613,6 +677,40 @@ function report_salesman_commission(reporting) {
         });
       };
 
+      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 {
+          if(date == 'today'){
+              var fecha = moment().format('DD/MM/YYYY');
+          }
+
+          if(date == 'yesterday'){
+              var fecha = moment().add(-1,'days').format('DD/MM/YYYY');
+          }
+          if(date == 'currentMonth'){
+              var fecha = moment().format('MMMM/YYYY');
+          }
+          if(date == 'lastMonth'){
+              var fecha = moment().add(-1,'months').format('MMMM/YYYY');
+          }
+
+          filter.push({
+              title: 'Fecha',
+              value:  fecha,
+          });
+        }
+      }
+
       return filter;
     },
   });

+ 28 - 0
static/src/reports/report_salesman_commission.xml

@@ -26,6 +26,34 @@
                         <select id="current-period" class="form-control form-control-sm">
                         </select>
                     </div>
+                    <div class="col-lg-3 filter-style">
+                       <label>Fechas</label>
+                       <select id="current-date" class="form-control form-control-sm">
+                           <option value="9999999">Sin fechas</option>
+                           <option value="today">Hoy</option>
+                           <option value="yesterday">Ayer</option>
+                           <option value="currentMonth">Mes Actual</option>
+                           <option value="lastMonth">Mes Pasado</option>
+                           <option value="range">Busqueda Avanzada</option>
+                       </select>
+                   </div>
+                </div>
+
+                <div class="row" >
+                    <div class="datepicker" style="display:none;">
+                        <div class="col-lg-3 filter-style col-md-offset-3">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Desde</span>
+                                <input type="text" id="from" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                        <div class="col-lg-3 filter-style">
+                            <div class="input-group">
+                                <span class="input-group-addon" id="basic-addon1">Hasta</span>
+                                <input type="text" id="to" class="form-control" aria-describedby="basic-addon1"/>
+                            </div>
+                        </div>
+                    </div>
                 </div>
 
                 <div class="row">