FIX_SIR told to merge agent policy count array and premium amount array into single array

This commit is contained in:
sanjeev.p 2025-12-10 11:11:52 +05:30
parent 228f44b544
commit d5dcb0aa01

View File

@ -443,6 +443,9 @@ class DashboardController extends ResourceController
$details['brokerWise'] = $this->brokerWise($manager_id,$raw);
$details['productWise'] = $this->productWise($manager_id,$raw);
$details['insurerWise'] = $this->insurerWise($manager_id,$raw);
$counts['brokerWise_total_records'] = is_array($details['brokerWise']) ? count($details['brokerWise']) : 0;
$counts['productWise_total_records'] = is_array($details['productWise']) ? count($details['productWise']) : 0 ;
$counts['insurerWise_total_records'] = is_array($details['insurerWise']) ? count($details['insurerWise']) : 0;
// 2. Check for overall emptiness (optional, but good practice)
$is_empty = array_reduce($details, function ($carry, $item) {
@ -460,7 +463,8 @@ class DashboardController extends ResourceController
'data' => $details, // Contains the nested arrays: brokerWise, productWise, insurerWise
'code' => 200,
'message' => $message,
'ref' => 'NIL'
'ref' => 'NIL',
'counts' => counts
])->setStatusCode(200);
} catch (\Throwable $e) {
@ -503,7 +507,7 @@ class DashboardController extends ResourceController
// Initialize the details array to ensure the final output is always structured.
$code = 200;
$message = "Partner Dashboard Data Retrieved Successfully";
$details = [ 'monthlyPolicyCount' => [],'monthlyPremiumAmount' => [],'noPolicyTimeRange' => [],'below50tPremiumTimeRange' => []];
$details = [ 'monthlyPolicyCount' => [],'noPolicyTimeRange' => [],'below50tPremiumTimeRange' => []];
// 'agentNoPolicyLast10Days' => [],// 'agentBelow50tPremiumLast10Days' => [],
try {
@ -511,14 +515,14 @@ class DashboardController extends ResourceController
$date = $this->request->getGet('date');
$date = $date ?? date('Y-m-d');
$details['monthlyPolicyCount'] = $this->agentMonthlyPolicyCount($date,$manager_id,$raw);
$details['monthlyPremiumAmount'] = $this->agentMonthlyPremiumAmount($date,$manager_id,$raw);
$details['monthlyPolicyCount'] = $this->agentMonthlyPolicyCountandPremiumAmount($date,$manager_id,$raw);
// $details['monthlyPremiumAmount'] = $this->agentMonthlyPremiumAmount($date,$manager_id,$raw);
$details['noPolicyTimeRange'] = $this->agentNoPolicyTimeRange($manager_id,$raw);
$details['below50tPremiumTimeRange'] = $this->agentBelow50tPremiumTimeRange($manager_id,$raw);
$details['monthlyPolicyCount_total_records'] = count($details['monthlyPolicyCount']);
$details['monthlyPremiumAmount_total_records'] = count($details['monthlyPremiumAmount']);
$details['noPolicyTimeRange_total_records'] = count($details['noPolicyTimeRange']);
$details['below50tPremiumTimeRange_total_records'] = count($details['below50tPremiumTimeRange']);
$counts['monthlyPolicyCountAndPremiumAmount_total_records'] = is_array($details['monthlyPolicyCount']) ? count($details['monthlyPolicyCount']) : 0;
$counts['noPolicyTimeRange_total_records'] = is_array($details['noPolicyTimeRange']) ? count($details['noPolicyTimeRange']) : 0;
$counts['below50tPremiumTimeRange_total_records'] = is_array($details['below50tPremiumTimeRange']) ? count($details['below50tPremiumTimeRange']) : 0;
// 2. Check for overall emptiness (optional, but good practice)
@ -536,7 +540,8 @@ class DashboardController extends ResourceController
'data' => $details, // Contains the nested arrays: brokerWise, productWise, insurerWise
'code' => 200,
'message' => $message,
'ref' => 'NIL'
'ref' => 'NIL',
'counts' => $counts
])->setStatusCode(200);
} catch (\Throwable $e) {
@ -583,6 +588,10 @@ class DashboardController extends ResourceController
try {
// 1. Fetch all data concurrently (or sequentially, as shown)
$details['StaffWise'] = $this->staffWiseProductList($manager_id,$raw);
$counts['StaffWise_total_records'] = is_array($details['StaffWise'])
? count($details['StaffWise'])
: 0;
// 2. Check for overall emptiness (optional, but good practice)
$is_empty = array_reduce($details, function ($carry, $item) {
@ -600,7 +609,8 @@ class DashboardController extends ResourceController
'data' => $details,
'code' => 200,
'message' => $message,
'ref' => 'NIL'
'ref' => 'NIL',
'counts' => $counts
])->setStatusCode(200);
} catch (\Throwable $e) {
@ -827,8 +837,8 @@ class DashboardController extends ResourceController
}
//Step 2.1
public function agentMonthlyPolicyCount($customDate,$manager_id, $raw){
//Step 2
public function agentMonthlyPolicyCountandPremiumAmount($customDate,$manager_id, $raw){
$builder = $this->db->table('partner_policy pp');
@ -837,7 +847,8 @@ class DashboardController extends ResourceController
pa.id AS agent_id,
pa.name AS agent_name,
pa.agent_code,
COUNT(pp.id) AS policy_count
COUNT(pp.id) AS policy_count,
SUM(pp.premium_amount) AS total_premium_amount
");
$builder->join('partner_agent pa', 'pp.agent_id = pa.id', 'inner');
@ -861,34 +872,34 @@ class DashboardController extends ResourceController
}
//Step 2.2
public function agentMonthlyPremiumAmount($customDate,$manager_id, $raw){
// public function agentMonthlyPremiumAmount($customDate,$manager_id, $raw){
$builder = $this->db->table('partner_policy pp');
// $builder = $this->db->table('partner_policy pp');
$builder->select("
pa.id AS agent_id,
pa.name AS agent_name,
pa.agent_code,
SUM(pp.premium_amount) AS total_premium_amount
");
// $builder->select("
// pa.id AS agent_id,
// pa.name AS agent_name,
// pa.agent_code,
// SUM(pp.premium_amount) AS total_premium_amount
// ");
$builder->join('partner_agent pa', 'pp.agent_id = pa.id', 'inner');
// $builder->join('partner_agent pa', 'pp.agent_id = pa.id', 'inner');
$builder->where("MONTH(pp.issued_date) = MONTH('$customDate')", null, false);
$builder->where("YEAR(pp.issued_date) = YEAR('$customDate')", null, false);
$builder->where('pp.manager_id',$manager_id);
// $builder->where("MONTH(pp.issued_date) = MONTH('$customDate')", null, false);
// $builder->where("YEAR(pp.issued_date) = YEAR('$customDate')", null, false);
// $builder->where('pp.manager_id',$manager_id);
$builder->groupBy(['pa.id','pa.name','pa.agent_code']);
$builder->orderBy('total_premium_amount', 'DESC');
$builder->limit(50);
if ($raw === true) {
return $builder->getCompiledSelect();
}
$result = $builder->get()->getResultArray();
return $result;
// $builder->groupBy(['pa.id','pa.name','pa.agent_code']);
// $builder->orderBy('total_premium_amount', 'DESC');
// $builder->limit(50);
// if ($raw === true) {
// return $builder->getCompiledSelect();
// }
// $result = $builder->get()->getResultArray();
// return $result;
}
// }
//Step 3 no buiness
public function agentNoPolicyTimeRange($manager_id, $raw){