From d27a892ce815fa146267c7b6d86a6edd5220240b Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 09:34:35 +0530 Subject: [PATCH 1/8] FEAT_PAYOUT --- app/Controllers/PayoutController.php | 113 ++++++++++++++++++++++++++ app/Models/InvoiceItemModel.php | 41 ++++++++++ app/Models/InvoiceModel.php | 117 +++++++++++++++++++++++++++ app/Models/InvoiceUtrModel.php | 39 +++++++++ 4 files changed, 310 insertions(+) create mode 100644 app/Controllers/PayoutController.php create mode 100644 app/Models/InvoiceItemModel.php create mode 100644 app/Models/InvoiceModel.php create mode 100644 app/Models/InvoiceUtrModel.php diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php new file mode 100644 index 00000000..7b798537 --- /dev/null +++ b/app/Controllers/PayoutController.php @@ -0,0 +1,113 @@ +myLogger = \Config\Services::mylogger(); + + $this->payout_status = [ + 1 => "Draft", + 2 => "Pending", + 3 => "Complete", + ]; + + $this->invoiceItemModel = new InvoiceItemModel(); + $this->invoiceModel = new InvoiceModel(); + $this->invoiceUtrModel = new InvoiceUtrModel(); + $this->policyTransactionModel = new PolicyTransactionModel(); + } + + public function payoutList() + { + // for filtering list + if($this->request->is('post')){ + try{ + $data = $this->request->getPost(); + // print_r($data); die; + + $agent_id = $data['agent_id'] ?? null; + $status_id = $data['status_id'] ?? null; + $start_date = $data['start_date'] ?? null; + $end_date = $data['end_date'] ?? null; + + $payout_data = $this->invoiceModel->invoiceList($this->payout_status, $agent_id, $status_id, $start_date, $end_date); + + $payout_data['payout_list_data'] = $payout_data; + $payout_data = view('payout_list', $payout_data); + + if(!empty($payout_data)){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); + } + }catch (\Throwable $th) { + + $this->myLogger->logme("error", "PayoutController - payoutList: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString()); + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + $payout_data = view('payout_list'); + return $this->respond(['status' => false, 'code' => 500, 'data' => $payout_data, "message" => "No data found", 'error_data' => $errorData], 500); + } + } + + // for list + $data['payout_status'] = $this->payout_status; + $data['agent_list'] = $this->invoiceModel->agentList(); + $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList($this->payout_status); + $data['payout_list'] = view('payout_list', $payout_data); + + // dd($data); + return $this->loadLayout('payout_list_handler', $data); + } + + public function fetchUtrDetails() + { + $invoice_id = $this->request->getPost('invoice_id') ?? null; + + $payout_data = $this->invoiceModel->invoiceList(); + + $data['utr_data'] = $payout_data; + $payout_data = view('partner_utr_details', $data); + + if(!empty($payout_data)){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); + } + } + + public function saveUtrDetails() + { + $data = $this->request->getPost(); + } + + +} diff --git a/app/Models/InvoiceItemModel.php b/app/Models/InvoiceItemModel.php new file mode 100644 index 00000000..328be1d9 --- /dev/null +++ b/app/Models/InvoiceItemModel.php @@ -0,0 +1,41 @@ + 'required|integer', + 'policy_id' => 'required|integer', + 'policy_no' => 'required|max_length[100]', + 'commission_amount' => 'decimal' + ]; + + protected $validationMessages = []; + protected $skipValidation = false; +} diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php new file mode 100644 index 00000000..2a3b71e0 --- /dev/null +++ b/app/Models/InvoiceModel.php @@ -0,0 +1,117 @@ + 'required|max_length[100]', + 'invoice_amount' => 'decimal', + 'agent_id' => 'required|integer', + 'invoice_date' => 'required|valid_date', + ]; + + protected $validationMessages = []; + protected $skipValidation = false; + + + public function invoiceList($status = [], $agent_id = null, $status_id = null, $start_date = null, $end_date = null) + { + $data = $this->select(" + partner_invoice.*, + + -- Total UTR Amount + (SELECT SUM(piu.amount) + FROM partner_invoice_utr piu + WHERE piu.invoice_id = partner_invoice.id + AND piu.is_active = 1 + ) AS total_utr_amount, + + -- Balance Amount + (partner_invoice.invoice_amount - + IFNULL( + (SELECT SUM(piu2.amount) + FROM partner_invoice_utr piu2 + WHERE piu2.invoice_id = partner_invoice.id + AND piu2.is_active = 1 + ), + 0) + ) AS balance_amount, + + -- Payout status + CASE + WHEN payout_status = 1 THEN 'Draft' + WHEN payout_status = 2 THEN 'Pending' + WHEN payout_status = 3 THEN 'Complete' + END AS status_text, + + partner_agent.name as agent_name + ") + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->where('partner_invoice.is_active', 1); + + if(!empty($agent_id)){ + $data->where('partner_invoice.agent_id', $agent_id); + } + + if(!empty($status_id)){ + $data->where('partner_invoice.payout_status', $status_id); + } + + if (!empty($start_date) && !empty($end_date)) { + + $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); + $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); + + $data->where('partner_invoice.invoice_date >=', $startDate) + ->where('partner_invoice.invoice_date <=', $endDate); + } + + if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + + $fromDate = date('Y-m-d', strtotime('-60 days')); + $toDate = date('Y-m-d 23:59:59'); + + $data->where('partner_invoice.created_at >=', $fromDate) + ->where('partner_invoice.created_at <=', $toDate); + + } + + $return_data = $data->orderBy('partner_invoice.id','desc')->findAll(); + + // print_r($this->db->getLastQuery()); die; + + return $return_data; + } + + public function agentList(){ + return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray(); + } +} diff --git a/app/Models/InvoiceUtrModel.php b/app/Models/InvoiceUtrModel.php new file mode 100644 index 00000000..9f0c44c4 --- /dev/null +++ b/app/Models/InvoiceUtrModel.php @@ -0,0 +1,39 @@ + 'required|integer', + 'utr_no' => 'required|max_length[100]', + 'amount' => 'decimal' + ]; + + protected $validationMessages = []; + protected $skipValidation = false; +} From 2bf53a61da1c72b84ea4abb4214ae2d22f12b988 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 09:35:17 +0530 Subject: [PATCH 2/8] CHANGE_ROUTE --- app/Config/Routes.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7c7ba864..c089cd4e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -737,7 +737,6 @@ $routes->get('testTracelog','TestBusinessController::a'); $routes->get("claimView", "EmployeeRestController::claimView"); // General Tickets - $routes->post("ticketSave", "ThzController::ticketSave"); $routes->get("ticketList", "ThzController::ticketList"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); @@ -767,3 +766,10 @@ $routes->group('test', function($routes) { }); $routes->cli('cli/testcli', 'TestingController::testcli'); +//PARTNER PAYOUT +$routes->group('payout', function($routes) { + $routes->match (['get','post'],'list',"PayoutController::payoutList"); + $routes->post('fetchUtrDetails',"PayoutController::fetchUtrDetails"); + $routes->post('saveUtrDetails',"PayoutController::saveUtrDetails"); +}); + From 16135992fa8d8d628aa6fc6673de43edefe03274 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 10:49:27 +0530 Subject: [PATCH 3/8] FEAT_PAYOUT_VIEWS --- app/Views/payout_list.php | 318 ++++++++++++++++++++++++++++++ app/Views/payout_list_handler.php | 308 +++++++++++++++++++++++++++++ 2 files changed, 626 insertions(+) create mode 100644 app/Views/payout_list.php create mode 100644 app/Views/payout_list_handler.php diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php new file mode 100644 index 00000000..4b4eb477 --- /dev/null +++ b/app/Views/payout_list.php @@ -0,0 +1,318 @@ + + +
+
+
+
+
+

Payout List

+
+
+
+ + + + + + + + + + + + + + + + + $row){ ?> + + + + + + + + + + + + + + +
S.No.Inovice NoInvoice DateInvoice AmountUTR Total AmountBalanceStatusAgentAction
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/app/Views/payout_list_handler.php b/app/Views/payout_list_handler.php new file mode 100644 index 00000000..1857baea --- /dev/null +++ b/app/Views/payout_list_handler.php @@ -0,0 +1,308 @@ +
+
+
+
+
+

+ Filter + + + +

+
+
+
+
+
+ + +
+ +
+ + +
+ +
+ +
+ + +
+ + +
+ +
+ Clear + Submit +
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+ + \ No newline at end of file From ab1f3d6a9fee375ae1dc5cc8f40f1070bfc67931 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 15 Nov 2025 18:48:20 +0530 Subject: [PATCH 4/8] FEAT_PAYOUT_CHANGES --- app/Config/Routes.php | 1 + app/Controllers/ClientController.php | 4 + app/Controllers/PayoutController.php | 100 ++++++++-- app/Models/InvoiceModel.php | 83 +++++++- app/Models/InvoiceUtrModel.php | 34 ++++ app/Views/payout_list.php | 247 +++++++++++++---------- app/Views/payout_list_handler.php | 126 +----------- app/Views/payout_utr_details.php | 280 +++++++++++++++++++++++++++ 8 files changed, 630 insertions(+), 245 deletions(-) create mode 100644 app/Views/payout_utr_details.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3efa4981..9b083b0f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -772,5 +772,6 @@ $routes->group('payout', function($routes) { $routes->match (['get','post'],'list',"PayoutController::payoutList"); $routes->post('fetchUtrDetails',"PayoutController::fetchUtrDetails"); $routes->post('saveUtrDetails',"PayoutController::saveUtrDetails"); + $routes->post('removeUtrDetails',"PayoutController::removeUtrDetails"); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 0bed75f5..87ec5222 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -5673,6 +5673,10 @@ class ClientController extends AdminController // $response = $ticketServiceController->extractExcelData("claims_dump_form_client.xlsx"); // dd($response); + // $TicketController = new TicketController(); + // $response = $TicketController->getMoreInfo($requestFrom = 'rest', $ticket_id = 70); + // dd($response); + // ---------- EMP SERVICE CONTROLLER -------------------------------------------------------------------------------- $empServiceController = new EmployeeServiceController(); diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 7b798537..06762fd8 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -50,7 +50,7 @@ class PayoutController extends BaseController $start_date = $data['start_date'] ?? null; $end_date = $data['end_date'] ?? null; - $payout_data = $this->invoiceModel->invoiceList($this->payout_status, $agent_id, $status_id, $start_date, $end_date); + $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); $payout_data['payout_list_data'] = $payout_data; $payout_data = view('payout_list', $payout_data); @@ -81,7 +81,7 @@ class PayoutController extends BaseController // for list $data['payout_status'] = $this->payout_status; $data['agent_list'] = $this->invoiceModel->agentList(); - $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList($this->payout_status); + $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList(); $data['payout_list'] = view('payout_list', $payout_data); // dd($data); @@ -90,23 +90,101 @@ class PayoutController extends BaseController public function fetchUtrDetails() { - $invoice_id = $this->request->getPost('invoice_id') ?? null; + $invoice_id = $this->request->getPost('invoice_id') ?? null; + $payout_data = $this->constructUtrDetails($invoice_id); - $payout_data = $this->invoiceModel->invoiceList(); + if(!empty($payout_data)){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); + } + } - $data['utr_data'] = $payout_data; - $payout_data = view('partner_utr_details', $data); + public function constructUtrDetails($invoice_id) + { + $utr_data = $this->invoiceUtrModel->where('is_active', 1)->where('invoice_id', $invoice_id)->findAll(); + $summary_data = $this->invoiceModel->utrSummary($invoice_id); - if(!empty($payout_data)){ - return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200); - }else{ - return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200); - } + if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']) { + $data['invoice_completed'] = true; + } + + $data['utr_list_data'] = $utr_data; + $data['summary'] = $summary_data; + $data = view('payout_utr_details', $data); + + return $data; } public function saveUtrDetails() { $data = $this->request->getPost(); + $invoice_id = $this->request->getPost('invoice_id') ?? null; + $utr_id = $this->request->getPost('utr_pk') ?? null; + + if(isset($data['utr_date'])){ + $data['utr_date'] = change_date_format($data['utr_date']); + } + + + if(!empty($utr_id)){ + + $update = $this->invoiceUtrModel->where('id', $utr_id)->set($data)->update(); + $payout_edit_data = $this->constructUtrDetails($invoice_id); + + if($update){ + + $summary_data = $this->invoiceModel->utrSummary($invoice_id); + if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){ + $sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?"; + db_connect()->query($sql, [$invoice_id]); + } + + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_edit_data, "message" => "UTR successfully updated"], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_edit_data, "message" => "Failed to update UTR"], 200); + } + + }else{ + + unset($data['utr_pk']); + $insert_id = $this->invoiceUtrModel->insert($data); + $payout_data = $this->constructUtrDetails($invoice_id); + + if($insert_id){ + + $summary_data = $this->invoiceModel->utrSummary($invoice_id); + if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){ + $sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?"; + db_connect()->query($sql, [$invoice_id]); + } + + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR added successfully"], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to add UTR"], 200); + } + } + } + + public function removeUtrDetails() + { + $data = $this->request->getPost(); + + if(isset($data['utr_id'])){ + + $sql = "UPDATE partner_invoice_utr SET is_active = 0 WHERE id = ?"; + $update = db_connect()->query($sql, [$data['utr_id']]); + + $payout_data = $this->constructUtrDetails($data['invoice_id'] ?? ""); + + if($update){ + return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR removed successfully"], 200); + }else{ + return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to remove UTR"], 200); + } + }else { + return $this->respond(['status' => false, 'code' => 500, 'data' => "", "message" => "Failed to remove UTR"], 200); + } } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 2a3b71e0..49d91ced 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -41,8 +41,41 @@ class InvoiceModel extends Model protected $validationMessages = []; protected $skipValidation = false; + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; - public function invoiceList($status = [], $agent_id = null, $status_id = null, $start_date = null, $end_date = null) + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + + + public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null) { $data = $this->select(" partner_invoice.*, @@ -67,9 +100,8 @@ class InvoiceModel extends Model -- Payout status CASE - WHEN payout_status = 1 THEN 'Draft' - WHEN payout_status = 2 THEN 'Pending' - WHEN payout_status = 3 THEN 'Complete' + WHEN payout_status = 1 THEN 'Pending' + WHEN payout_status = 2 THEN 'Complete' END AS status_text, partner_agent.name as agent_name @@ -111,7 +143,48 @@ class InvoiceModel extends Model return $return_data; } - public function agentList(){ + public function agentList() + { return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray(); } + + public function utrSummary($invoice_id) + { + $data = $this->select(" + + partner_invoice.*, + + -- Total UTR Amount + (SELECT SUM(piu.amount) + FROM partner_invoice_utr piu + WHERE piu.invoice_id = partner_invoice.id + AND piu.is_active = 1 + ) AS total_utr_amount, + + -- Balance Amount + (partner_invoice.invoice_amount - + IFNULL( + (SELECT SUM(piu2.amount) + FROM partner_invoice_utr piu2 + WHERE piu2.invoice_id = partner_invoice.id + AND piu2.is_active = 1 + ), + 0) + ) AS balance_amount, + + -- Payout status + CASE + WHEN payout_status = 1 THEN 'Pending' + WHEN payout_status = 2 THEN 'Complete' + END AS status_text, + + partner_agent.name as agent_name + ") + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->where('partner_invoice.is_active', 1) + ->where('partner_invoice.id', $invoice_id) + ->first(); + + return $data; + } } diff --git a/app/Models/InvoiceUtrModel.php b/app/Models/InvoiceUtrModel.php index 9f0c44c4..a9da5960 100644 --- a/app/Models/InvoiceUtrModel.php +++ b/app/Models/InvoiceUtrModel.php @@ -17,6 +17,7 @@ class InvoiceUtrModel extends Model 'invoice_id', 'utr_no', 'amount', + 'utr_date', 'is_active', 'created_at', 'created_by', @@ -36,4 +37,37 @@ class InvoiceUtrModel extends Model protected $validationMessages = []; protected $skipValidation = false; + + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; + + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } } diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php index 4b4eb477..d911715d 100644 --- a/app/Views/payout_list.php +++ b/app/Views/payout_list.php @@ -38,21 +38,145 @@ border-left: 4px solid #2196F3; } + + + + +
@@ -94,7 +218,7 @@
-