This commit is contained in:
Gowtham M 2025-10-11 12:29:05 +05:30
parent b4dd5aab1d
commit b0d2031e33
6 changed files with 167 additions and 79 deletions

View File

@ -99,6 +99,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
//dashboard //dashboard
$routes->get('dashboard/managerDashboard', 'DashboardController::managerDashboard'); $routes->get('dashboard/managerDashboard', 'DashboardController::managerDashboard');
$routes->get('dashboard/handlerDashboard', 'DashboardController::handlerDashboard');
$routes->get('dashboard/staffDashboard', 'DashboardController::staffDashboard'); $routes->get('dashboard/staffDashboard', 'DashboardController::staffDashboard');
$routes->get('dashboard/agentDashboard', 'DashboardController::agentDashboard'); $routes->get('dashboard/agentDashboard', 'DashboardController::agentDashboard');

View File

@ -118,6 +118,19 @@ class ClaimController extends ResourceController
], 200); ], 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(); $status = $this->ClaimStatusModel->where('ticket_type', 8)->first();
// Prepare claim data for ticket_master // Prepare claim data for ticket_master
@ -139,6 +152,7 @@ class ClaimController extends ResourceController
'claim_type' => $reqData['claim_type'], 'claim_type' => $reqData['claim_type'],
'claim_description'=> $reqData['claim_description'], 'claim_description'=> $reqData['claim_description'],
'created_by' => $reqData['created_by'] ?? null, 'created_by' => $reqData['created_by'] ?? null,
'claim_file_name' => $uploadedFileName,
]; ];
// Insert claim // Insert claim

View File

@ -89,35 +89,54 @@ class DashboardController extends ResourceController
// --- Staff level Quotations Pending --- // // --- Staff level Quotations Pending ---
$quotationsPending = $this->db->table('partner_staff ps') // $quotationsPending = $this->db->table('partner_staff ps')
->select('ps.name as staff_name, COUNT(pe.id) as total_quotation_pending') // ->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') // ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Awaiting Quotation'", 'left')
->where('ps.role_id', 2) // ->where('ps.role_id', 2)
->where('ps.manager_id',$manager_id) // ->where('ps.manager_id',$manager_id)
->groupBy('ps.id, ps.name') // ->groupBy('ps.id, ps.name')
->get()->getResultArray(); // ->get()->getResultArray();
// --- Staff level Quotations Approva Pending --- // // --- Staff level Quotations Approva Pending ---
$quotationsApprovalPending = $this->db->table('partner_staff ps') // $quotationsApprovalPending = $this->db->table('partner_staff ps')
->select('ps.name as staff_name, COUNT(pe.id) as total_approval_pending') // ->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') // ->join('partner_enquiry pe', "pe.assigned_to = ps.id AND pe.status = 'Quotation Created'", 'left')
->where('ps.role_id', 2) // ->where('ps.role_id', 2)
->where('ps.manager_id',$manager_id) // ->where('ps.manager_id',$manager_id)
->groupBy('ps.id, ps.name') // ->groupBy('ps.id, ps.name')
->get()->getResultArray(); // ->get()->getResultArray();
// --- Staff level Policies Pending --- // // --- Staff level Policies Pending ---
$policiesPending = $this->db->table('partner_staff ps') // $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') // ->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_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') // ->join('partner_quotation pq', "pq.enquiry_id = pe.id AND pq.status = 'Accepted'", 'left')
->where('ps.role_id', 2) // ->where('ps.role_id', 2)
->where('ps.manager_id',$manager_id) // ->where('ps.manager_id',$manager_id)
->groupBy('ps.id, ps.name') // ->groupBy('ps.id, ps.name')
->get()->getResultArray(); // ->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 = [ $result = [
@ -138,14 +157,52 @@ class DashboardController extends ResourceController
], ],
'agents_performance' => $performanceAgents, 'agents_performance' => $performanceAgents,
'unassigned_enquiry' => $unassignedEnquiry, 'unassigned_enquiry' => $unassignedEnquiry,
'quotations_pending' => $quotationsPending, // 'quotations_pending' => $quotationsPending,
'quotations_approval_pending' => $quotationsApprovalPending, // 'quotations_approval_pending' => $quotationsApprovalPending,
'policies_pending' => $policiesPending, // 'policies_pending' => $policiesPending,
'staff_level_pending_summary' => $staffLevelPendingSummary
]; ];
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); 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() public function staffDashboard()
{ {

View File

@ -87,66 +87,80 @@ class EndorsementController extends ResourceController
public function createEndorsement() public function createEndorsement()
{ {
try { try {
$reqData = $this->request->getJSON(true); $reqData = $this->request->getJSON(true);
// Validate required fields // Validate required fields
if (empty($reqData['policy_number']) || empty($reqData['endorsement_type']) || empty($reqData['endorsement_description'])) { 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); return $this->respond(['status' => 'failed','code' => 400,'data' => 'policy_number, endorsement_type and endorsement_description are required' ], 200);
} }
// Fetch policy details // 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') $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_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left')
->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left') ->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left')
->where('partner_policy.policy_number', $reqData['policy_number']) ->where('partner_policy.policy_number', $reqData['policy_number'])
->first(); ->first();
if (empty($policy)) { if (empty($policy)) {
return $this->respond(['status' => 'failed','code' => 404,'data' => 'Policy not found'], 200); 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 $uploadFile = $this->request->getFile('endorsement_file_name');
if (!$this->EndorsementModel->insert($endorsementData)) { $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([ return $this->respond([
'status' => 'failed', 'status' => 'failed',
'code' => 422, 'code' => 500,
'data' => $this->EndorsementModel->errors() 'data' => $e->getMessage()
], 422); ], 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);
} }
}

View File

@ -33,6 +33,7 @@ class ClaimModel extends Model
'vehicle_id', 'vehicle_id',
'claim_description', 'claim_description',
'is_active', 'is_active',
'claim_file_name'
]; ];
// Auto timestamps // Auto timestamps

View File

@ -23,6 +23,7 @@ class EndorsementModel extends Model
'endorsement_type', 'endorsement_type',
'endorsement_description', 'endorsement_description',
'status', 'status',
'endorsement_file_name',
'created_at', 'created_at',
'updated_by', 'updated_by',
'updated_at', 'updated_at',