From b0d2031e338c40688dab8e2ff67a9f3910a3b263 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Sat, 11 Oct 2025 12:29:05 +0530 Subject: [PATCH] GWM --- app/Config/Routes.php | 1 + app/Controllers/ClaimController.php | 14 +++ app/Controllers/DashboardController.php | 113 +++++++++++++++------ app/Controllers/EndorsementController.php | 116 ++++++++++++---------- app/Models/ClaimModel.php | 1 + app/Models/EndorsementModel.php | 1 + 6 files changed, 167 insertions(+), 79 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a0a04eb..2a30a2e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -99,6 +99,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { //dashboard $routes->get('dashboard/managerDashboard', 'DashboardController::managerDashboard'); + $routes->get('dashboard/handlerDashboard', 'DashboardController::handlerDashboard'); $routes->get('dashboard/staffDashboard', 'DashboardController::staffDashboard'); $routes->get('dashboard/agentDashboard', 'DashboardController::agentDashboard'); diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 9bc3f26..2f92020 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -118,6 +118,19 @@ class ClaimController extends ResourceController ], 200); } + $uploadFile = $this->request->getFile('claim_file_name'); + $uploadedFileName = null; + + if ($uploadFile && $uploadFile->isValid()) { + $uploadPath = WRITEPATH . 'uploads/claims/'; + if (!is_dir($uploadPath)) { + mkdir($uploadPath, 0777, true); + } + $uploadedFileName = time() . '_' . $uploadFile->getRandomName(); + $uploadFile->move($uploadPath, $uploadedFileName); + } + + $status = $this->ClaimStatusModel->where('ticket_type', 8)->first(); // Prepare claim data for ticket_master @@ -139,6 +152,7 @@ class ClaimController extends ResourceController 'claim_type' => $reqData['claim_type'], 'claim_description'=> $reqData['claim_description'], 'created_by' => $reqData['created_by'] ?? null, + 'claim_file_name' => $uploadedFileName, ]; // Insert claim diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 12027ec..fd97493 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -89,35 +89,54 @@ class DashboardController extends ResourceController - // --- Staff level Quotations Pending --- - $quotationsPending = $this->db->table('partner_staff ps') - ->select('ps.name as staff_name, COUNT(pe.id) as total_quotation_pending') - ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Awaiting Quotation'", 'left') - ->where('ps.role_id', 2) - ->where('ps.manager_id',$manager_id) - ->groupBy('ps.id, ps.name') - ->get()->getResultArray(); + // // --- Staff level Quotations Pending --- + // $quotationsPending = $this->db->table('partner_staff ps') + // ->select('ps.name as staff_name, COUNT(pe.id) as total_quotation_pending') + // ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Awaiting Quotation'", 'left') + // ->where('ps.role_id', 2) + // ->where('ps.manager_id',$manager_id) + // ->groupBy('ps.id, ps.name') + // ->get()->getResultArray(); - // --- Staff level Quotations Approva Pending --- - $quotationsApprovalPending = $this->db->table('partner_staff ps') - ->select('ps.name as staff_name, COUNT(pe.id) as total_approval_pending') - ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Quotation Created'", 'left') - ->where('ps.role_id', 2) - ->where('ps.manager_id',$manager_id) - ->groupBy('ps.id, ps.name') - ->get()->getResultArray(); + // // --- Staff level Quotations Approva Pending --- + // $quotationsApprovalPending = $this->db->table('partner_staff ps') + // ->select('ps.name as staff_name, COUNT(pe.id) as total_approval_pending') + // ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Quotation Created'", 'left') + // ->where('ps.role_id', 2) + // ->where('ps.manager_id',$manager_id) + // ->groupBy('ps.id, ps.name') + // ->get()->getResultArray(); - // --- Staff level Policies Pending --- - $policiesPending = $this->db->table('partner_staff ps') - ->select('ps.name as staff_name, COUNT(pe.id) as total_policis_pending, SUM(pq.premium_amount) as total_premium_value') - ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Quotation Accepted'", 'left') - ->join('partner_quotation pq', "pq.enquiry_id = pe.id AND pq.status = 'Accepted'", 'left') - ->where('ps.role_id', 2) - ->where('ps.manager_id',$manager_id) - ->groupBy('ps.id, ps.name') - ->get()->getResultArray(); + // // --- Staff level Policies Pending --- + // $policiesPending = $this->db->table('partner_staff ps') + // ->select('ps.name as staff_name, COUNT(pe.id) as total_policis_pending, SUM(pq.premium_amount) as total_premium_value') + // ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Quotation Accepted'", 'left') + // ->join('partner_quotation pq', "pq.enquiry_id = pe.id AND pq.status = 'Accepted'", 'left') + // ->where('ps.role_id', 2) + // ->where('ps.manager_id',$manager_id) + // ->groupBy('ps.id, ps.name') + // ->get()->getResultArray(); + + + $staffLevelPendingSummary = $this->db->table('partner_enquiry pe') + ->select(" + ps.name AS staff_name, + ps.id AS staff_id, + COUNT(pe.id) AS total_assigned, + SUM(CASE WHEN pe.status = 'Awaiting Quotation' THEN 1 ELSE 0 END) AS awaiting_quotation, + SUM(CASE WHEN pe.status = 'Quotation Created' THEN 1 ELSE 0 END) AS pending_quotation_approval, + SUM(CASE WHEN pe.status = 'Quotation Accepted' THEN 1 ELSE 0 END) AS awaiting_policy, + SUM(CASE WHEN pe.status = 'Policy Created' THEN 1 ELSE 0 END) AS policy_created + ") + ->join('partner_staff ps', 'ps.id = pe.assigned_to', 'left') + ->where('pe.manager_id', $manager_id) + ->where('pe.is_active', 1) + ->groupBy('pe.assigned_to') + ->orderBy('ps.name', 'ASC') + ->get() + ->getResultArray(); $result = [ @@ -138,14 +157,52 @@ class DashboardController extends ResourceController ], 'agents_performance' => $performanceAgents, 'unassigned_enquiry' => $unassignedEnquiry, - 'quotations_pending' => $quotationsPending, - 'quotations_approval_pending' => $quotationsApprovalPending, - 'policies_pending' => $policiesPending, + // 'quotations_pending' => $quotationsPending, + // 'quotations_approval_pending' => $quotationsApprovalPending, + // 'policies_pending' => $policiesPending, + 'staff_level_pending_summary' => $staffLevelPendingSummary ]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); } + public function handlerDashboard() + { + $handler_id = $this->request->getGet('handler_id'); + + if (empty($handler_id)) { + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Handler ID is required.' + ]); + } + + $staffLevelPendingSummary = $this->db->table('partner_enquiry pe') + ->select(" + ps.name AS staff_name, + ps.id AS staff_id, + COUNT(pe.id) AS total_assigned, + SUM(CASE WHEN pe.status = 'Awaiting Quotation' THEN 1 ELSE 0 END) AS awaiting_quotation, + SUM(CASE WHEN pe.status = 'Quotation Created' THEN 1 ELSE 0 END) AS pending_quotation_approval, + SUM(CASE WHEN pe.status = 'Quotation Accepted' THEN 1 ELSE 0 END) AS awaiting_policy, + SUM(CASE WHEN pe.status = 'Policy Created' THEN 1 ELSE 0 END) AS policy_created + ") + ->join('partner_staff ps', 'ps.id = pe.assigned_to', 'left') + ->where('ps.handler_id', $handler_id) + ->where('pe.is_active', 1) + ->groupBy('pe.assigned_to') + ->orderBy('ps.name', 'ASC') + ->get() + ->getResultArray(); + + $result = [ + 'staff_level_pending_summary' => $staffLevelPendingSummary + ]; + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } + + public function staffDashboard() { diff --git a/app/Controllers/EndorsementController.php b/app/Controllers/EndorsementController.php index 412c492..ff298f0 100644 --- a/app/Controllers/EndorsementController.php +++ b/app/Controllers/EndorsementController.php @@ -87,66 +87,80 @@ class EndorsementController extends ResourceController public function createEndorsement() -{ - try { - $reqData = $this->request->getJSON(true); + { + try { + $reqData = $this->request->getJSON(true); - // Validate required fields - if (empty($reqData['policy_number']) || empty($reqData['endorsement_type']) || empty($reqData['endorsement_description'])) { - return $this->respond(['status' => 'failed','code' => 400,'data' => 'policy_number, endorsement_type and endorsement_description are required' ], 200); - } + // Validate required fields + if (empty($reqData['policy_number']) || empty($reqData['endorsement_type']) || empty($reqData['endorsement_description'])) { + return $this->respond(['status' => 'failed','code' => 400,'data' => 'policy_number, endorsement_type and endorsement_description are required' ], 200); + } - // Fetch policy details - $policy = $this->PolicyModel->select('partner_policy.*, Q.insurer_id, Q.insurer_branch_id, E.name as client_name, E.mobile as client_mobile, E.email as client_email, E.reg_no') - ->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left') - ->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left') - ->where('partner_policy.policy_number', $reqData['policy_number']) - ->first(); + // Fetch policy details + $policy = $this->PolicyModel->select('partner_policy.*, Q.insurer_id, Q.insurer_branch_id, E.name as client_name, E.mobile as client_mobile, E.email as client_email, E.reg_no') + ->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left') + ->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left') + ->where('partner_policy.policy_number', $reqData['policy_number']) + ->first(); - if (empty($policy)) { - return $this->respond(['status' => 'failed','code' => 404,'data' => 'Policy not found'], 200); - } + if (empty($policy)) { + return $this->respond(['status' => 'failed','code' => 404,'data' => 'Policy not found'], 200); + } - // Prepare endorsement data - $endorsementData = [ - 'policy_number' => $policy['policy_number'], - 'client_policy_id' => $policy['client_policy_id'] ?? null, - 'insurer_id' => $policy['insurer_id'] ?? null, - 'insurer_branch_id' => $policy['insurer_branch_id'] ?? null, - 'client_id' => $policy['client_id'] ?? null, - 'agent_id' => $policy['agent_id'] ?? null, - 'manager_id' => $policy['manager_id'] ?? null, - 'endorsement_type' => $reqData['endorsement_type'], - 'endorsement_description'=> $reqData['endorsement_description'], - 'endorsement_no' => $reqData['endorsement_no'] ?? null, - 'created_by' => $reqData['created_by'] ?? null, - 'status' => 'Open', - 'is_active' => 1 - ]; - // ✅ Insert endorsement - if (!$this->EndorsementModel->insert($endorsementData)) { + $uploadFile = $this->request->getFile('endorsement_file_name'); + $uploadedFileName = null; + + if ($uploadFile && $uploadFile->isValid()) { + $uploadPath = WRITEPATH . 'uploads/endorsement/'; + if (!is_dir($uploadPath)) { + mkdir($uploadPath, 0777, true); + } + $uploadedFileName = time() . '_' . $uploadFile->getRandomName(); + $uploadFile->move($uploadPath, $uploadedFileName); + } + + // Prepare endorsement data + $endorsementData = [ + 'policy_number' => $policy['policy_number'], + 'client_policy_id' => $policy['client_policy_id'] ?? null, + 'insurer_id' => $policy['insurer_id'] ?? null, + 'insurer_branch_id' => $policy['insurer_branch_id'] ?? null, + 'client_id' => $policy['client_id'] ?? null, + 'agent_id' => $policy['agent_id'] ?? null, + 'manager_id' => $policy['manager_id'] ?? null, + 'endorsement_type' => $reqData['endorsement_type'], + 'endorsement_description'=> $reqData['endorsement_description'], + 'endorsement_no' => $reqData['endorsement_no'] ?? null, + 'created_by' => $reqData['created_by'] ?? null, + 'status' => 'Open', + 'endorsement_file_name' => $uploadedFileName, + 'is_active' => 1 + ]; + + // ✅ Insert endorsement + if (!$this->EndorsementModel->insert($endorsementData)) { + return $this->respond([ + 'status' => 'failed', + 'code' => 422, + 'data' => $this->EndorsementModel->errors() + ], 422); + } + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'data' => ['endorsement_id' => $this->EndorsementModel->getInsertID()] + ], 200); + + } catch (\Exception $e) { return $this->respond([ 'status' => 'failed', - 'code' => 422, - 'data' => $this->EndorsementModel->errors() - ], 422); + 'code' => 500, + 'data' => $e->getMessage() + ], 500); } - - return $this->respond([ - 'status' => 'success', - 'code' => 200, - 'data' => ['endorsement_id' => $this->EndorsementModel->getInsertID()] - ], 200); - - } catch (\Exception $e) { - return $this->respond([ - 'status' => 'failed', - 'code' => 500, - 'data' => $e->getMessage() - ], 500); } -} diff --git a/app/Models/ClaimModel.php b/app/Models/ClaimModel.php index c00e6ff..644b3a1 100644 --- a/app/Models/ClaimModel.php +++ b/app/Models/ClaimModel.php @@ -33,6 +33,7 @@ class ClaimModel extends Model 'vehicle_id', 'claim_description', 'is_active', + 'claim_file_name' ]; // Auto timestamps diff --git a/app/Models/EndorsementModel.php b/app/Models/EndorsementModel.php index 4843815..e9c57a7 100644 --- a/app/Models/EndorsementModel.php +++ b/app/Models/EndorsementModel.php @@ -23,6 +23,7 @@ class EndorsementModel extends Model 'endorsement_type', 'endorsement_description', 'status', + 'endorsement_file_name', 'created_at', 'updated_by', 'updated_at',