diff --git a/app/Classes/General/Eloquent/Filters/DateRangeNoData.php b/app/Classes/General/Eloquent/Filters/DateRangeNoData.php index 3bfb27e6..278fe9dd 100644 --- a/app/Classes/General/Eloquent/Filters/DateRangeNoData.php +++ b/app/Classes/General/Eloquent/Filters/DateRangeNoData.php @@ -65,6 +65,9 @@ class DateRangeNoData implements Filter ->whereDoesntHave('attributesKVP', function ($invoiceQuery) { $invoiceQuery->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE); }); + }) + ->whereDoesntHave('attributesKVP', function ($invoiceQuery) { + $invoiceQuery->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE); }); } } diff --git a/app/Classes/General/Eloquent/Filters/DateRangeWithData.php b/app/Classes/General/Eloquent/Filters/DateRangeWithData.php new file mode 100644 index 00000000..12fd2d67 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/DateRangeWithData.php @@ -0,0 +1,73 @@ +startOfDay() + : Carbon::now()->subMonth()->startOfDay(); + + $endDate = isset($dt2) && $dt2 + ? Carbon::createFromFormat('Y-m-d', $dt2)->endOfDay() + : Carbon::now()->endOfDay(); + + $minAllowedDate = Carbon::createFromFormat('Y-m-d', '2025-07-01')->startOfDay(); + if ($startDate->lt($minAllowedDate) || $endDate->lt($minAllowedDate)) { + $startDate = Carbon::createFromFormat('Y-m-d', '1970-01-01')->startOfDay(); + $endDate = Carbon::createFromFormat('Y-m-d', '1970-01-01')->startOfDay(); + } + + return $builder->with([ + 'company', + 'transactions.transactionDetails', + 'transactions.voucherRedemption', + ]) + + // ->whereHas('company', function ($query) { + // $query->where('debtor', '!=', 'N/A NO NEED TO IMPORT'); + // }) + ->whereHas('transactions', function ($query) use ($startDate, $endDate){ + $query->payments() + ->complete() + ->whereBetween('created_at', [$startDate, $endDate]) + ->latest('created_at'); + }) + ->whereDoesntHave('transactions', function ($query) use ($startDate, $endDate) { + $query->payments() + ->complete() + ->where(function ($q) use ($startDate, $endDate) { + $q->where('created_at', '<', $startDate) + ->orWhere('created_at', '>', $endDate); + }); + }) + ->whereHas('transactions', function ($query) use ($startDate, $endDate){ + $query->where('type', TransactionType::INVOICE) + ->latest('created_at') + ->whereHas('attributesKVP', function ($invoiceQuery) { + $invoiceQuery->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE); + }); + }); + // ->WhereHas('attributesKVP', function ($invoiceQuery) { + // $invoiceQuery->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE); + // }); + } +} diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsSalesInvoiceLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsSalesInvoiceLogic.php index 493be93f..b0a330b7 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsSalesInvoiceLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/ListBookingsSalesInvoiceLogic.php @@ -57,7 +57,7 @@ class ListBookingsSalesInvoiceLogic extends AbstractControllerLogic } // Only these filters are allowed - $allowedKeys = ['per_page', 'status', 'order_by', 'date_range', 'date_range_no_data']; + $allowedKeys = ['per_page', 'status', 'order_by', 'date_range', 'date_range_no_data', 'date_range_with_data']; $extra = array_diff(array_keys($filters), $allowedKeys); if (!empty($extra)) { @@ -86,9 +86,9 @@ class ListBookingsSalesInvoiceLogic extends AbstractControllerLogic } // Required at least one of: date_range or date_range_no_data - if (!isset($filters['date_range']) && !isset($filters['date_range_no_data'])) { + if (!isset($filters['date_range']) && !isset($filters['date_range_no_data']) && !isset($filters['date_range_with_data'])) { return response()->json([ - 'message' => 'Either "date_range" or "date_range_no_data" filter is required.', + 'message' => 'Either "date_range" or "date_range_no_data" or "date_range_with_data" filter is required.', 'payload' => new \stdClass(), ], 400); }