Esempio n. 1
0
 /**
  * It gets all active occurrences that are not paid
  * for this year up to the current month.
  *
  * @return [type]
  */
 public function getPreviousUnpaidOccurrences()
 {
     $date = Carbon::now();
     $date->day = 1;
     $date->hour = 0;
     $date->minute = 0;
     $date->second = 0;
     return $this->occurrences->orderBy('occurs_at')->where(function ($query) use($date) {
         $query->where('occurs_at', '<', $date);
     })->where('payment_received', 0)->whereHas('service', function ($query) {
         $query->where('active', 1);
     })->with(['service.client'])->get();
 }
Esempio n. 2
0
 /**
  * Query scope for adding searching based on $filterArgs
  *
  * @param [type] $query Query builder object
  *
  * @return [type] [description]
  */
 public static function scopeSearch($query, $input = null)
 {
     if ($input == null) {
         $input = Input::all();
     }
     // sort
     $sortField = isset($_GET['sort']) ? $_GET['sort'] : false;
     $sortField = static::isSortable($sortField);
     if ($sortField) {
         $direction = $input['direction'];
         $direction = $direction == 'asc' ? 'asc' : 'desc';
         $query->orderBy($sortField, $direction);
     }
     $data = [];
     foreach (array_keys(static::$filterArgs) as $key) {
         if (isset($input[$key])) {
             $data[$key] = $input[$key];
         }
     }
     foreach ($data as $key => $value) {
         $filter = static::$filterArgs[$key];
         if (is_null($value) || strlen($value) == 0) {
             continue;
         }
         $fieldName = isset($filter['field']) ? $filter['field'] : $key;
         switch ($filter['type']) {
             case 'value':
                 $query->where($fieldName, '=', $value);
                 break;
             case 'like':
                 $query->where($fieldName, 'LIKE', '%' . $value . '%');
                 break;
             case 'custom':
                 $query->where($fieldName, $filter['custom'], $value);
                 break;
             case 'gt':
                 $query->where($fieldName, '>', $value);
                 break;
             case 'lt':
                 $query->where($fieldName, '<', $value);
                 break;
             case 'scope':
                 // $query = static::{'scope' . $filter['method']}($query);
                 break;
             default:
                 break;
         }
     }
     return $query;
 }
Esempio n. 3
0
 /**
  * Popularity by view count.
  * 
  * @param  [type]  $query      [description]
  * @param  boolean $descending [description]
  * 
  * @return [type]              [description]
  */
 public function scopePopular($query, $descending = true)
 {
     $query->orderBy('view_count', $descending ? 'desc' : 'asc');
 }
Esempio n. 4
0
 /**
  * [scopeOrder description]
  * @param  [type] $query [description]
  * @return [type]        [description]
  */
 public function scopeOrder($query)
 {
     return $query->orderBy('level', 'desc')->orderBy('id', 'asc');
 }