FEAT_INVOICE SEARCH
This commit is contained in:
parent
471a2ce86b
commit
5e230303fc
@ -40,6 +40,14 @@ class InvoiceController extends ResourceController
|
|||||||
try {
|
try {
|
||||||
$fromDateRaw = $this->request->getGet('from_date');
|
$fromDateRaw = $this->request->getGet('from_date');
|
||||||
$toDateRaw = $this->request->getGet('to_date');
|
$toDateRaw = $this->request->getGet('to_date');
|
||||||
|
$agentNameRaw = $this->request->getGet('agent_name');
|
||||||
|
$agentCodeRaw = $this->request->getGet('agent_code');
|
||||||
|
$policyNumberRaw = $this->request->getGet('policy_no');
|
||||||
|
|
||||||
|
$agentName = trim((string) ($agentNameRaw ?? ''));
|
||||||
|
$agentCode = trim((string) ($agentCodeRaw ?? ''));
|
||||||
|
$policyNumber = trim((string) ($policyNumberRaw ?? ''));
|
||||||
|
|
||||||
|
|
||||||
$fromParsed = $this->parseOptionalDmYDate($fromDateRaw);
|
$fromParsed = $this->parseOptionalDmYDate($fromDateRaw);
|
||||||
$toParsed = $this->parseOptionalDmYDate($toDateRaw);
|
$toParsed = $this->parseOptionalDmYDate($toDateRaw);
|
||||||
@ -122,6 +130,47 @@ class InvoiceController extends ResourceController
|
|||||||
$query->where('DATE(partner_invoice.invoice_date) <=', $toParsed['ymd']);
|
$query->where('DATE(partner_invoice.invoice_date) <=', $toParsed['ymd']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($agentName !== '' || $agentCode !== '') {
|
||||||
|
$agentQuery = $this->db->table('partner_agent')->select('id');
|
||||||
|
|
||||||
|
if ($agentName !== '') {
|
||||||
|
$agentQuery->like('name', $agentName);
|
||||||
|
}
|
||||||
|
if ($agentCode !== '') {
|
||||||
|
$agentQuery->like('agent_code', $agentCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
$agentIds = array_column($agentQuery->get()->getResultArray(), 'id');
|
||||||
|
|
||||||
|
if (empty($agentIds)) {
|
||||||
|
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->groupStart();
|
||||||
|
foreach ($agentIds as $agentId) {
|
||||||
|
$query->orWhere(
|
||||||
|
'JSON_SEARCH(partner_invoice.agent_id, "one", CAST(' . (int) $agentId . ' AS CHAR)) IS NOT NULL',
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$query->groupEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($policyNumber !== '') {
|
||||||
|
$policyLike = '%' . $this->db->escapeLikeString($policyNumber) . '%';
|
||||||
|
$query->where(
|
||||||
|
'EXISTS (
|
||||||
|
SELECT 1 FROM partner_invoice_items pii
|
||||||
|
WHERE pii.invoice_id = partner_invoice.id
|
||||||
|
AND pii.is_active = 1
|
||||||
|
AND pii.policy_no LIKE ' . $this->db->escape($policyLike) . '
|
||||||
|
)',
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$data = $query->orderBy('partner_invoice.id', 'DESC')->findAll();
|
$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);
|
||||||
|
|||||||
@ -116,7 +116,7 @@ class MasterController extends ResourceController
|
|||||||
|
|
||||||
public function saveInsurer()
|
public function saveInsurer()
|
||||||
{
|
{
|
||||||
$input = $this->request->getPost();
|
$input = $this->request->getJSON(true);
|
||||||
|
|
||||||
if (empty($input['name'])) {
|
if (empty($input['name'])) {
|
||||||
return $this->respond(['status' => 404, 'message' => 'Insurer name is required', 'data' => []]);
|
return $this->respond(['status' => 404, 'message' => 'Insurer name is required', 'data' => []]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user