GWM : getAgentUnusedCommissionList
This commit is contained in:
parent
a86dc72dd3
commit
c7eb344dcb
@ -38,8 +38,36 @@ class InvoiceController extends ResourceController
|
|||||||
public function invoiceList()
|
public function invoiceList()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$fromDateRaw = $this->request->getGet('from_date');
|
||||||
|
$toDateRaw = $this->request->getGet('to_date');
|
||||||
|
|
||||||
$data = $this->InvoiceModel
|
$fromParsed = $this->parseOptionalDmYDate($fromDateRaw);
|
||||||
|
$toParsed = $this->parseOptionalDmYDate($toDateRaw);
|
||||||
|
|
||||||
|
if ($fromParsed['error'] !== null) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'failed',
|
||||||
|
'code' => 400,
|
||||||
|
'data' => $fromParsed['error'],
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
if ($toParsed['error'] !== null) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'failed',
|
||||||
|
'code' => 400,
|
||||||
|
'data' => $toParsed['error'],
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fromParsed['ymd'] !== null && $toParsed['ymd'] !== null && $fromParsed['ymd'] > $toParsed['ymd']) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'failed',
|
||||||
|
'code' => 400,
|
||||||
|
'data' => 'from_date must be on or before to_date',
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->InvoiceModel
|
||||||
->select('partner_invoice.*,
|
->select('partner_invoice.*,
|
||||||
PB.name as broker_name,
|
PB.name as broker_name,
|
||||||
pos.name as pos_name,
|
pos.name as pos_name,
|
||||||
@ -78,9 +106,16 @@ class InvoiceController extends ResourceController
|
|||||||
false)
|
false)
|
||||||
->join('partner_brokers PB', 'PB.id = partner_invoice.broker_id', 'left')
|
->join('partner_brokers PB', 'PB.id = partner_invoice.broker_id', 'left')
|
||||||
->join('partner_pos pos', 'pos.id = partner_invoice.pos_id', 'left')
|
->join('partner_pos pos', 'pos.id = partner_invoice.pos_id', 'left')
|
||||||
->where('partner_invoice.is_active', 1)
|
->where('partner_invoice.is_active', 1);
|
||||||
->orderBy('partner_invoice.id', 'DESC')
|
|
||||||
->findAll();
|
if ($fromParsed['ymd'] !== null) {
|
||||||
|
$query->where('DATE(partner_invoice.invoice_date) >=', $fromParsed['ymd']);
|
||||||
|
}
|
||||||
|
if ($toParsed['ymd'] !== null) {
|
||||||
|
$query->where('DATE(partner_invoice.invoice_date) <=', $toParsed['ymd']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $query->orderBy('partner_invoice.id', 'DESC')->findAll();
|
||||||
|
|
||||||
return $this->respond(['status' => 'success', 'code' => 200,'data' => $data ], 200);
|
return $this->respond(['status' => 'success', 'code' => 200,'data' => $data ], 200);
|
||||||
|
|
||||||
@ -89,6 +124,32 @@ class InvoiceController extends ResourceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional invoice list date filter: format d-m-Y (e.g. 10-03-2026). Empty / null = no filter.
|
||||||
|
*
|
||||||
|
* @return array{ymd: ?string, error: ?string}
|
||||||
|
*/
|
||||||
|
private function parseOptionalDmYDate($value): array
|
||||||
|
{
|
||||||
|
if ($value === null) {
|
||||||
|
return ['ymd' => null, 'error' => null];
|
||||||
|
}
|
||||||
|
$v = trim((string) $value);
|
||||||
|
if ($v === '') {
|
||||||
|
return ['ymd' => null, 'error' => null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$dt = \DateTime::createFromFormat('d-m-Y', $v);
|
||||||
|
if ($dt === false || $dt->format('d-m-Y') !== $v) {
|
||||||
|
return [
|
||||||
|
'ymd' => null,
|
||||||
|
'error' => 'Invalid date format; use d-m-Y (e.g. 10-03-2026)',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['ymd' => $dt->format('Y-m-d'), 'error' => null];
|
||||||
|
}
|
||||||
|
|
||||||
public function findInvoiceWithItems()
|
public function findInvoiceWithItems()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user