FIX_SIR told to merge agent policy count array and premium amount array into single array
This commit is contained in:
parent
228f44b544
commit
d5dcb0aa01
@ -443,6 +443,9 @@ class DashboardController extends ResourceController
|
|||||||
$details['brokerWise'] = $this->brokerWise($manager_id,$raw);
|
$details['brokerWise'] = $this->brokerWise($manager_id,$raw);
|
||||||
$details['productWise'] = $this->productWise($manager_id,$raw);
|
$details['productWise'] = $this->productWise($manager_id,$raw);
|
||||||
$details['insurerWise'] = $this->insurerWise($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)
|
// 2. Check for overall emptiness (optional, but good practice)
|
||||||
$is_empty = array_reduce($details, function ($carry, $item) {
|
$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
|
'data' => $details, // Contains the nested arrays: brokerWise, productWise, insurerWise
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'ref' => 'NIL'
|
'ref' => 'NIL',
|
||||||
|
'counts' => counts
|
||||||
])->setStatusCode(200);
|
])->setStatusCode(200);
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@ -503,7 +507,7 @@ class DashboardController extends ResourceController
|
|||||||
// Initialize the details array to ensure the final output is always structured.
|
// Initialize the details array to ensure the final output is always structured.
|
||||||
$code = 200;
|
$code = 200;
|
||||||
$message = "Partner Dashboard Data Retrieved Successfully";
|
$message = "Partner Dashboard Data Retrieved Successfully";
|
||||||
$details = [ 'monthlyPolicyCount' => [],'monthlyPremiumAmount' => [],'noPolicyTimeRange' => [],'below50tPremiumTimeRange' => []];
|
$details = [ 'monthlyPolicyCount' => [],'noPolicyTimeRange' => [],'below50tPremiumTimeRange' => []];
|
||||||
// 'agentNoPolicyLast10Days' => [],// 'agentBelow50tPremiumLast10Days' => [],
|
// 'agentNoPolicyLast10Days' => [],// 'agentBelow50tPremiumLast10Days' => [],
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -511,14 +515,14 @@ class DashboardController extends ResourceController
|
|||||||
$date = $this->request->getGet('date');
|
$date = $this->request->getGet('date');
|
||||||
$date = $date ?? date('Y-m-d');
|
$date = $date ?? date('Y-m-d');
|
||||||
|
|
||||||
$details['monthlyPolicyCount'] = $this->agentMonthlyPolicyCount($date,$manager_id,$raw);
|
$details['monthlyPolicyCount'] = $this->agentMonthlyPolicyCountandPremiumAmount($date,$manager_id,$raw);
|
||||||
$details['monthlyPremiumAmount'] = $this->agentMonthlyPremiumAmount($date,$manager_id,$raw);
|
// $details['monthlyPremiumAmount'] = $this->agentMonthlyPremiumAmount($date,$manager_id,$raw);
|
||||||
$details['noPolicyTimeRange'] = $this->agentNoPolicyTimeRange($manager_id,$raw);
|
$details['noPolicyTimeRange'] = $this->agentNoPolicyTimeRange($manager_id,$raw);
|
||||||
$details['below50tPremiumTimeRange'] = $this->agentBelow50tPremiumTimeRange($manager_id,$raw);
|
$details['below50tPremiumTimeRange'] = $this->agentBelow50tPremiumTimeRange($manager_id,$raw);
|
||||||
$details['monthlyPolicyCount_total_records'] = count($details['monthlyPolicyCount']);
|
|
||||||
$details['monthlyPremiumAmount_total_records'] = count($details['monthlyPremiumAmount']);
|
$counts['monthlyPolicyCountAndPremiumAmount_total_records'] = is_array($details['monthlyPolicyCount']) ? count($details['monthlyPolicyCount']) : 0;
|
||||||
$details['noPolicyTimeRange_total_records'] = count($details['noPolicyTimeRange']);
|
$counts['noPolicyTimeRange_total_records'] = is_array($details['noPolicyTimeRange']) ? count($details['noPolicyTimeRange']) : 0;
|
||||||
$details['below50tPremiumTimeRange_total_records'] = count($details['below50tPremiumTimeRange']);
|
$counts['below50tPremiumTimeRange_total_records'] = is_array($details['below50tPremiumTimeRange']) ? count($details['below50tPremiumTimeRange']) : 0;
|
||||||
|
|
||||||
|
|
||||||
// 2. Check for overall emptiness (optional, but good practice)
|
// 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
|
'data' => $details, // Contains the nested arrays: brokerWise, productWise, insurerWise
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'ref' => 'NIL'
|
'ref' => 'NIL',
|
||||||
|
'counts' => $counts
|
||||||
])->setStatusCode(200);
|
])->setStatusCode(200);
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@ -583,6 +588,10 @@ class DashboardController extends ResourceController
|
|||||||
try {
|
try {
|
||||||
// 1. Fetch all data concurrently (or sequentially, as shown)
|
// 1. Fetch all data concurrently (or sequentially, as shown)
|
||||||
$details['StaffWise'] = $this->staffWiseProductList($manager_id,$raw);
|
$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)
|
// 2. Check for overall emptiness (optional, but good practice)
|
||||||
$is_empty = array_reduce($details, function ($carry, $item) {
|
$is_empty = array_reduce($details, function ($carry, $item) {
|
||||||
@ -600,7 +609,8 @@ class DashboardController extends ResourceController
|
|||||||
'data' => $details,
|
'data' => $details,
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'ref' => 'NIL'
|
'ref' => 'NIL',
|
||||||
|
'counts' => $counts
|
||||||
])->setStatusCode(200);
|
])->setStatusCode(200);
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@ -827,8 +837,8 @@ class DashboardController extends ResourceController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Step 2.1
|
//Step 2
|
||||||
public function agentMonthlyPolicyCount($customDate,$manager_id, $raw){
|
public function agentMonthlyPolicyCountandPremiumAmount($customDate,$manager_id, $raw){
|
||||||
|
|
||||||
|
|
||||||
$builder = $this->db->table('partner_policy pp');
|
$builder = $this->db->table('partner_policy pp');
|
||||||
@ -837,7 +847,8 @@ class DashboardController extends ResourceController
|
|||||||
pa.id AS agent_id,
|
pa.id AS agent_id,
|
||||||
pa.name AS agent_name,
|
pa.name AS agent_name,
|
||||||
pa.agent_code,
|
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');
|
$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){
|
|
||||||
|
|
||||||
$builder = $this->db->table('partner_policy pp');
|
// public function agentMonthlyPremiumAmount($customDate,$manager_id, $raw){
|
||||||
|
|
||||||
$builder->select("
|
// $builder = $this->db->table('partner_policy pp');
|
||||||
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->select("
|
||||||
|
// pa.id AS agent_id,
|
||||||
|
// pa.name AS agent_name,
|
||||||
|
// pa.agent_code,
|
||||||
|
// SUM(pp.premium_amount) AS total_premium_amount
|
||||||
|
// ");
|
||||||
|
|
||||||
$builder->where("MONTH(pp.issued_date) = MONTH('$customDate')", null, false);
|
// $builder->join('partner_agent pa', 'pp.agent_id = pa.id', 'inner');
|
||||||
$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->where("MONTH(pp.issued_date) = MONTH('$customDate')", null, false);
|
||||||
$builder->orderBy('total_premium_amount', 'DESC');
|
// $builder->where("YEAR(pp.issued_date) = YEAR('$customDate')", null, false);
|
||||||
$builder->limit(50);
|
// $builder->where('pp.manager_id',$manager_id);
|
||||||
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
|
//Step 3 no buiness
|
||||||
public function agentNoPolicyTimeRange($manager_id, $raw){
|
public function agentNoPolicyTimeRange($manager_id, $raw){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user