GWM : payout view
This commit is contained in:
parent
c460b933cd
commit
be72099cae
@ -211,6 +211,7 @@ $routes->group('api', ['filter' => ["jwtAuth:1,2,3,4,agent","appSignature"] ], f
|
||||
//invoice
|
||||
$routes->get('invoice/list', 'InvoiceController::invoiceList');
|
||||
$routes->get('invoice/details', 'InvoiceController::findInvoiceWithItems');
|
||||
$routes->get('invoice/view', 'InvoiceController::invoiceView');
|
||||
$routes->post('invoice/create-or-update', 'InvoiceController::createOrUpdateInvoice');
|
||||
$routes->get('invoice/utrDetails', 'InvoiceController::utrDetails');
|
||||
$routes->post('invoice/add-payment', 'InvoiceController::addInvoicePayment'); // tempo
|
||||
|
||||
@ -211,6 +211,79 @@ class InvoiceController extends ResourceController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET invoice_id, manager_id — invoice header + active line items (policies under this manager only).
|
||||
*/
|
||||
public function invoiceView()
|
||||
{
|
||||
try {
|
||||
$invoiceId = (int) $this->request->getGet('invoice_id');
|
||||
$managerId = (int) $this->request->getGet('manager_id');
|
||||
|
||||
if ($invoiceId <= 0 || $managerId <= 0) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'data' => 'invoice_id and manager_id are required',
|
||||
], 400);
|
||||
}
|
||||
|
||||
$invoice = $this->InvoiceModel
|
||||
->where('id', $invoiceId)
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
|
||||
if (! $invoice) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 404,
|
||||
'data' => 'Invoice not found',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$forbidden = $this->db->query(
|
||||
'SELECT 1 AS x FROM partner_invoice_items pii '
|
||||
. 'INNER JOIN partner_policy pp ON pp.id = pii.policy_id '
|
||||
. 'WHERE pii.invoice_id = ? AND pii.is_active = 1 '
|
||||
. 'AND (pp.manager_id IS NULL OR pp.manager_id != ?) '
|
||||
. 'LIMIT 1',
|
||||
[$invoiceId, $managerId]
|
||||
)->getRow();
|
||||
|
||||
if ($forbidden !== null) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 403,
|
||||
'data' => 'You do not have access to this invoice',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$items = $this->InvoiceItemModel
|
||||
->select('partner_invoice_items.* , pp.issued_date , pe.name as customer_name , pq.premium_amount')
|
||||
->join('partner_policy pp', 'pp.id = partner_invoice_items.policy_id', 'left')
|
||||
->join('partner_enquiry pe', 'pe.id = pp.enquiry_id', 'left')
|
||||
->join('partner_quotation pq', 'pq.id = pp.quotation_id', 'left')
|
||||
->where('partner_invoice_items.invoice_id', $invoiceId)
|
||||
->where('partner_invoice_items.is_active', 1)
|
||||
->findAll();
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'invoice' => $invoice,
|
||||
'items' => $items,
|
||||
],
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'data' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function createOrUpdateInvoice()
|
||||
{
|
||||
$this->db->transBegin();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user