diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index e30f485..de7f509 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -6,6 +6,7 @@ use App\Models\ClaimModel; use App\Models\PolicyModel; use App\Models\EnquiryModel; use App\Models\QuotationModel; +use App\Models\ClaimStatusModel; use CodeIgniter\RESTful\ResourceController; class ClaimController extends ResourceController @@ -15,6 +16,7 @@ class ClaimController extends ResourceController protected $PolicyModel; protected $QuotationModel; protected $EnquiryModel; + protected $ClaimStatusModel; public function __construct() { @@ -23,6 +25,7 @@ class ClaimController extends ResourceController $this->PolicyModel = new PolicyModel(); $this->QuotationModel = new QuotationModel(); $this->EnquiryModel = new EnquiryModel(); + $this->ClaimStatusModel = new ClaimStatusModel(); } // Get all tickets @@ -115,10 +118,12 @@ class ClaimController extends ResourceController ], 200); } + $status = $this->ClaimStatusModel->where('ticket_type', 8)->first(); + // Prepare claim data for ticket_master $claimData = [ 'ticket_type_id' => 8, - 'claim_status_id' => 1, + 'claim_status_id' => $status['id'], 'policy_no' => $policy['policy_number'], 'client_policy_id' => $policy['client_policy_id'], 'insurer_id' => $policy['insurer_id'], diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 56afa1d..fadcc5b 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -77,6 +77,13 @@ class DashboardController extends ResourceController ->getResultArray(); + // --- Un assigned enquiry --- + $unassignedEnquiry = $this->db->table('partner_enquiry pe') + ->where('pe.assigned_to', null) + ->where('pe.manager_id', $manager_id) + ->get() + ->getResultArray(); + // --- Staff level Quotations Pending --- @@ -88,6 +95,15 @@ class DashboardController extends ResourceController ->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 --- @@ -117,9 +133,11 @@ class DashboardController extends ResourceController 'month' => $earningsMonth, 'year' => $earningsYear, ], - 'agents_performance' => $performanceAgents, - 'quotations_pending' => $quotationsPending, - 'policies_pending' => $policiesPending, + 'agents_performance' => $performanceAgents, + 'unassigned_enquiry' => $unassignedEnquiry, + 'quotations_pending' => $quotationsPending, + 'quotations_approval_pending' => $quotationsApprovalPending, + 'policies_pending' => $policiesPending, ]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); @@ -136,7 +154,18 @@ class DashboardController extends ResourceController ->select('pe.* , I.name as insurer_name, I.short_name as insurer_short_name') ->join('insurers I', 'I.id = pe.insurer_id', 'left') ->where('pe.assigned_to',$staff_id) - ->where('pe.status','Awaiting Quotation') + ->whereIn('pe.status',["Awaiting Quotation","Quotation Rejected"]) + ->orderBy('pe.created_on', 'DESC') + ->get() + ->getResultArray(); + + + // --- Quotation Approval pending for staff (last 30 days) --- + $quotationsApprovalPending = $this->db->table('partner_enquiry pe') + ->select('pe.* , I.name as insurer_name, I.short_name as insurer_short_name') + ->join('insurers I', 'I.id = pe.insurer_id', 'left') + ->where('pe.assigned_to',$staff_id) + ->whereIn('pe.status',["Quotation Created"]) ->orderBy('pe.created_on', 'DESC') ->get() ->getResultArray(); @@ -146,13 +175,15 @@ class DashboardController extends ResourceController ->select('pe.* , I.name as insurer_name, I.short_name as insurer_short_name') ->join('insurers I', 'I.id = pe.insurer_id', 'left') ->where('pe.assigned_to',$staff_id) - ->where('pe.status','Quotation Accepted') + ->whereIn('pe.status',["Quotation Accepted"]) ->orderBy('pe.created_on', 'DESC') ->get() ->getResultArray(); $result = [ 'quotations_pending' => $quotationsPending, + 'quotations_approval_pending' => $quotationsApprovalPending, + 'quotations_rejected' => $quotationsApprovalPending, 'policies_pending' => $policiesPending, ]; @@ -220,7 +251,18 @@ class DashboardController extends ResourceController ->join('insurers I', 'I.id = pe.insurer_id', 'left') ->where('pe.created_on >=', $last30) ->where('pe.agent_id',$agent_id) - ->where('pe.status','Awaiting Quotation') + ->whereIn('pe.status',["Awaiting Quotation","Quotation Rejected"]) + ->orderBy('pe.created_on', 'DESC') + ->get() + ->getResultArray(); + + // --- Quotation approval pending for agent (last 30 days) --- + $quotationsApprovalPending = $this->db->table('partner_enquiry pe') + ->select('pe.* , I.name as insurer_name , I.short_name as insurer_short_name') + ->join('insurers I', 'I.id = pe.insurer_id', 'left') + ->where('pe.created_on >=', $last30) + ->where('pe.agent_id',$agent_id) + ->whereIn('pe.status',["Awaiting Created"]) ->orderBy('pe.created_on', 'DESC') ->get() ->getResultArray(); @@ -253,6 +295,7 @@ class DashboardController extends ResourceController 'year' => $earningsYear, ], 'quotations_pending' => $quotationsPending, + 'quotations_approval_pending' => $quotationsApprovalPending, 'policies_pending' => $policiesPending, ]; diff --git a/app/Models/ClaimStatusModel.php b/app/Models/ClaimStatusModel.php new file mode 100644 index 0000000..5b214b8 --- /dev/null +++ b/app/Models/ClaimStatusModel.php @@ -0,0 +1,41 @@ + 'required|max_length[40]', + 'allowed_status' => 'max_length[250]', + 'is_active' => 'in_list[0,1]' + ]; + + protected $validationMessages = []; + protected $skipValidation = false; +}