Merge branch 'main' of bitbucket.org:jubilian/nhance_partner_be
This commit is contained in:
commit
8481f19feb
@ -179,6 +179,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
$routes->post('invoice/create-or-update', 'InvoiceController::createOrUpdateInvoice');
|
||||
$routes->get('invoice/delete', 'InvoiceController::deleteInvoice');
|
||||
$routes->post('invoice/commission-rate-list', 'InvoiceController::getCommissionRateList');
|
||||
$routes->get('invoice/getAgentUnusedCommissionList', 'InvoiceController::getAgentUnusedCommissionList');
|
||||
|
||||
|
||||
// SALES EXECUTIVE
|
||||
|
||||
@ -319,6 +319,72 @@ class InvoiceController extends ResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function getAgentUnusedCommissionList()
|
||||
{
|
||||
try {
|
||||
|
||||
$manager_id = $this->request->getGet('manager_id');
|
||||
$broker_id = $this->request->getGet('broker_id');
|
||||
|
||||
if (empty($broker_id)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'message'=> 'broker_id is required'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$query = $this->PolicyModel
|
||||
->select([
|
||||
'pe.agent_id',
|
||||
'pa.name as agent_name',
|
||||
'SUM(partner_policy.commission_amount) as unused_commission_amount',
|
||||
'COUNT(partner_policy.id) as total_policies'
|
||||
])
|
||||
->join(
|
||||
'partner_enquiry pe',
|
||||
'pe.id = partner_policy.enquiry_id AND pe.broker_id = ' . (int)$broker_id,
|
||||
'left'
|
||||
)
|
||||
->join('partner_agent pa', 'pa.id = pe.agent_id', 'left')
|
||||
->join('partner_invoice_items pii', 'pii.policy_id = partner_policy.id', 'left')
|
||||
->join('partner_invoice pi', 'pi.id = pii.invoice_id AND pi.is_active = 1', 'left')
|
||||
->where('partner_policy.is_active', 1)
|
||||
->where('partner_policy.commission_amount >', 0)
|
||||
->where('partner_policy.is_data_accuracy_checked', 1)
|
||||
->where('partner_policy.manager_id', $manager_id)
|
||||
->where('pii.policy_id IS NULL') // ❗ unused commission
|
||||
->groupBy('pe.agent_id');
|
||||
|
||||
|
||||
|
||||
$data = $query->findAll();
|
||||
|
||||
// Grand total (optional but useful for FE)
|
||||
$grand_total = 0;
|
||||
foreach ($data as $row) {
|
||||
$grand_total += (float)$row['unused_commission_amount'];
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => $data,
|
||||
'grand_total_unused_commission' => $grand_total,
|
||||
'total_agents' => count($data)
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'message'=> $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public function getCommissionRateList()
|
||||
// {
|
||||
// try {
|
||||
|
||||
@ -285,7 +285,6 @@ class QuotationController extends ResourceController
|
||||
// update enquiry
|
||||
$enquiryArray = [
|
||||
'broker_id' => $data['broker_id'] ?? 0 ,
|
||||
'vehicle_type_id' => $data['vehicle_type_id'] ?? 0 ,
|
||||
'status'=> 'Proposal Accepted'
|
||||
];
|
||||
$this->EnquiryModel->update($data['enquiry_id'], $enquiryArray );
|
||||
@ -413,7 +412,6 @@ class QuotationController extends ResourceController
|
||||
* -------------------------------------------- */
|
||||
$this->EnquiryModel->update($data['enquiry_id'], [
|
||||
'broker_id' => $data['broker_id'] ?? 0,
|
||||
'vehicle_type_id' => $data['vehicle_type_id'] ?? 0,
|
||||
]);
|
||||
|
||||
}
|
||||
@ -434,7 +432,6 @@ class QuotationController extends ResourceController
|
||||
* -------------------------------------------- */
|
||||
$this->EnquiryModel->update($data['enquiry_id'], [
|
||||
'broker_id' => $data['broker_id'] ?? 0,
|
||||
'vehicle_type_id' => $data['vehicle_type_id'] ?? 0,
|
||||
'status' => 'Proposal Accepted'
|
||||
]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user