mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
E-Invoice - API, Sales Invoice Report Get request new filter
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DateRangeWithData implements Filter
|
||||
{
|
||||
/**
|
||||
* Apply the filter to the query.
|
||||
*
|
||||
* @param Builder $builder
|
||||
* @param mixed $value
|
||||
* @return Builder
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$dt1 = $value[0];
|
||||
$dt2 = $value[1];
|
||||
|
||||
$startDate = isset($dt1) && $dt1
|
||||
? Carbon::createFromFormat('Y-m-d', $dt1)->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);
|
||||
// });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user