FIX_4TH XL-download api Month Param Removed
This commit is contained in:
parent
3e0f9de8b5
commit
bb1d18d393
@ -454,20 +454,20 @@ class ExcelExportController extends ResourceController
|
|||||||
try{
|
try{
|
||||||
$managerId = $this->request->getGet('manager_id');
|
$managerId = $this->request->getGet('manager_id');
|
||||||
$agentId = $this->request->getGet('agent_id');
|
$agentId = $this->request->getGet('agent_id');
|
||||||
$month = $this->request->getGet('month');
|
// $month = $this->request->getGet('month');
|
||||||
|
|
||||||
if (empty($managerId) || empty($agentId) || empty($month)) {
|
if (empty($managerId) || empty($agentId)) {
|
||||||
|
|
||||||
$msg = "Missing: ";
|
$msg = "Missing: ";
|
||||||
$msg .= empty($managerId) ? "manager_id " : "";
|
$msg .= empty($managerId) ? "manager_id " : "";
|
||||||
$msg .= empty($agentId) ? "agent_id " : "";
|
$msg .= empty($agentId) ? "agent_id " : "";
|
||||||
$msg .= empty($month) ? "month " : "";
|
// $msg .= empty($month) ? "month " : "";
|
||||||
$ref = ['debug_msg' => $msg];
|
$ref = ['debug_msg' => $msg];
|
||||||
return $this->response->setJSON(['status' => 'error','code' => 400,'data' => [],'message' => 'Missing required parameters','ref' => $ref])->setStatusCode(200);
|
return $this->response->setJSON(['status' => 'error','code' => 400,'data' => [],'message' => 'Missing required parameters','ref' => $ref])->setStatusCode(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renamed helper function for consistency: getAgentMonthlyPoliciesData
|
// Renamed helper function for consistency: getAgentMonthlyPoliciesData
|
||||||
$data = $this->getAgentMonthlyPoliciesData($managerId, $agentId, $month);
|
$data = $this->getAgentMonthlyPoliciesData($managerId, $agentId); // , $month);
|
||||||
$header = ['Partner Name','Partner Code' , 'Policy Number','Issue Date', 'Premium Amount'];
|
$header = ['Partner Name','Partner Code' , 'Policy Number','Issue Date', 'Premium Amount'];
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
@ -477,7 +477,8 @@ class ExcelExportController extends ResourceController
|
|||||||
$grandTotal = array_sum(array_column($data, 4));
|
$grandTotal = array_sum(array_column($data, 4));
|
||||||
$data[] = ['','','','Total:',$grandTotal]; // Column D is 'Total:', Column E is the value
|
$data[] = ['','','','Total:',$grandTotal]; // Column D is 'Total:', Column E is the value
|
||||||
|
|
||||||
$monthName = ($month === 'current') ? date('M_Y') : date('M_Y', strtotime('-1 month'));
|
// $monthName = ($month === 'current') ? date('M_Y') : date('M_Y', strtotime('-1 month'));
|
||||||
|
$monthName = date('M_Y') ;
|
||||||
$PartnerName = $data[0][0] ?? 'Partner';
|
$PartnerName = $data[0][0] ?? 'Partner';
|
||||||
$cleanPartnerName = str_replace(' ', '_', strtolower($PartnerName));
|
$cleanPartnerName = str_replace(' ', '_', strtolower($PartnerName));
|
||||||
$fileName = $cleanPartnerName . '_Policies_Details_' . $monthName . '.xlsx';
|
$fileName = $cleanPartnerName . '_Policies_Details_' . $monthName . '.xlsx';
|
||||||
@ -933,7 +934,7 @@ class ExcelExportController extends ResourceController
|
|||||||
* @param string $month ('current' or 'previous')
|
* @param string $month ('current' or 'previous')
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getAgentMonthlyPoliciesData($managerId, $AgentId, $month): array
|
private function getAgentMonthlyPoliciesData($managerId, $AgentId): array
|
||||||
{
|
{
|
||||||
// --- Correction 1: Initialize Database Connection ---
|
// --- Correction 1: Initialize Database Connection ---
|
||||||
|
|
||||||
@ -952,16 +953,16 @@ class ExcelExportController extends ResourceController
|
|||||||
$builder->where('pp.policy_number IS NOT NULL');
|
$builder->where('pp.policy_number IS NOT NULL');
|
||||||
|
|
||||||
// --- Correction 2: Use Robust Date Range Filtering ---
|
// --- Correction 2: Use Robust Date Range Filtering ---
|
||||||
if ($month === "current") {
|
// if ($month === "current") {
|
||||||
// WHERE issued_date >= start_of_current_month AND issued_date < start_of_next_month
|
// // WHERE issued_date >= start_of_current_month AND issued_date < start_of_next_month
|
||||||
$builder->where("pp.issued_date >= DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01')", NULL, FALSE);
|
$builder->where("pp.issued_date >= DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01')", NULL, FALSE);
|
||||||
$builder->where("pp.issued_date < DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')", NULL, FALSE);
|
$builder->where("pp.issued_date < DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')", NULL, FALSE);
|
||||||
}
|
// }
|
||||||
else if ($month === "previous") {
|
// else if ($month === "previous") {
|
||||||
// WHERE issued_date >= start_of_previous_month AND issued_date < start_of_current_month
|
// // WHERE issued_date >= start_of_previous_month AND issued_date < start_of_current_month
|
||||||
$builder->where("pp.issued_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')", NULL, FALSE);
|
// $builder->where("pp.issued_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')", NULL, FALSE);
|
||||||
$builder->where("pp.issued_date < DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01')", NULL, FALSE);
|
// $builder->where("pp.issued_date < DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01')", NULL, FALSE);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$builder->orderBy('pp.issued_date', 'DESC');
|
$builder->orderBy('pp.issued_date', 'DESC');
|
||||||
|
|
||||||
@ -985,8 +986,6 @@ class ExcelExportController extends ResourceController
|
|||||||
/**
|
/**
|
||||||
* Executes the detailed policy query and extracts the data for the spreadsheet.
|
* Executes the detailed policy query and extracts the data for the spreadsheet.
|
||||||
* @param string $managerId
|
* @param string $managerId
|
||||||
* @param int $brokerId
|
|
||||||
* @param string $month ('current' or 'previous')
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getAgentsWithoutPoliciesData($managerId): array
|
private function getAgentsWithoutPoliciesData($managerId): array
|
||||||
@ -1026,8 +1025,6 @@ class ExcelExportController extends ResourceController
|
|||||||
/**
|
/**
|
||||||
* Executes the detailed policy query and extracts the data for the spreadsheet.
|
* Executes the detailed policy query and extracts the data for the spreadsheet.
|
||||||
* @param string $managerId
|
* @param string $managerId
|
||||||
* @param int $brokerId
|
|
||||||
* @param string $month ('current' or 'previous')
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getLowPremiumAgentData($managerId): array
|
private function getLowPremiumAgentData($managerId): array
|
||||||
@ -1043,8 +1040,8 @@ class ExcelExportController extends ResourceController
|
|||||||
pa.name AS agent_name,
|
pa.name AS agent_name,
|
||||||
pa.agent_code,
|
pa.agent_code,
|
||||||
CASE
|
CASE
|
||||||
WHEN pa.is_active = 1 THEN 'Active Agent'
|
WHEN pa.is_active = 1 THEN 'Active Partner'
|
||||||
ELSE 'Inactive Agent'
|
ELSE 'Inactive Partner'
|
||||||
END AS agent_status,
|
END AS agent_status,
|
||||||
pp.policy_number,
|
pp.policy_number,
|
||||||
DATE_FORMAT(pp.issued_date, '%d-%m-%Y') AS issued_date,
|
DATE_FORMAT(pp.issued_date, '%d-%m-%Y') AS issued_date,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user