diff --git a/app/Domains/Virtual/Repositories/Concerns/OrderCardConcern.php b/app/Domains/Virtual/Repositories/Concerns/OrderCardConcern.php index d4e227ba..3a608f7a 100644 --- a/app/Domains/Virtual/Repositories/Concerns/OrderCardConcern.php +++ b/app/Domains/Virtual/Repositories/Concerns/OrderCardConcern.php @@ -124,16 +124,18 @@ trait OrderCardConcern $relation->where('transaction_no', 'like', "%{$conditions['transaction_no']}%"); }); } + }); + if (isset($conditions['card_status'])) { switch ($conditions['card_status']) { case 0: - $query->whereNull('service_start_at')->whereHas('card', function ($relation) { + $this->model = $this->model->whereNull('service_start_at')->whereHas('card', function ($relation) { $relation->whereNull('cancelled_at'); })->where('created_at', '<', Carbon::now()->subMonths(6)); break; case 1: - $query->whereNull('service_start_at')->whereHas('card', function ($relation) { + $this->model = $this->model->whereNull('service_start_at')->whereHas('card', function ($relation) { $relation->whereNull('cancelled_at'); })->where('created_at', '>=', Carbon::now()->subMonths(6)); break; @@ -141,7 +143,7 @@ trait OrderCardConcern case 2: $havingRaw = sprintf("MAX(service_end_at) >= '%s'", date('Y-m-d H:i:s')); - $query->whereNotNull('service_start_at') + $this->model = $this->model->whereNotNull('service_start_at') ->groupBy('sim')->havingRaw($havingRaw) ->whereHas('card', function ($relation) { $relation->whereNull('cancelled_at'); @@ -151,7 +153,7 @@ trait OrderCardConcern case 3: $havingRaw = sprintf("MAX(service_end_at) < '%s'", date('Y-m-d H:i:s')); - $query->whereNotNull('service_start_at') + $this->model = $this->model->whereNotNull('service_start_at') ->groupBy('sim')->havingRaw($havingRaw) ->whereHas('card', function ($relation) { $relation->whereNull('cancelled_at'); @@ -159,7 +161,7 @@ trait OrderCardConcern break; case 4: - $query->whereHas('card', function ($relation) { + $this->model = $this->model->whereHas('card', function ($relation) { $relation->whereNotNull('cancelled_at'); }); break; @@ -168,7 +170,7 @@ trait OrderCardConcern # code... break; } - }); + } return $this; }