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{
|
||||
$managerId = $this->request->getGet('manager_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 .= empty($managerId) ? "manager_id " : "";
|
||||
$msg .= empty($agentId) ? "agent_id " : "";
|
||||
$msg .= empty($month) ? "month " : "";
|
||||
// $msg .= empty($month) ? "month " : "";
|
||||
$ref = ['debug_msg' => $msg];
|
||||
return $this->response->setJSON(['status' => 'error','code' => 400,'data' => [],'message' => 'Missing required parameters','ref' => $ref])->setStatusCode(200);
|
||||
}
|
||||
|
||||
// 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'];
|
||||
|
||||
if (empty($data)) {
|
||||
@ -477,7 +477,8 @@ class ExcelExportController extends ResourceController
|
||||
$grandTotal = array_sum(array_column($data, 4));
|
||||
$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';
|
||||
$cleanPartnerName = str_replace(' ', '_', strtolower($PartnerName));
|
||||
$fileName = $cleanPartnerName . '_Policies_Details_' . $monthName . '.xlsx';
|
||||
@ -933,7 +934,7 @@ class ExcelExportController extends ResourceController
|
||||
* @param string $month ('current' or 'previous')
|
||||
* @return array
|
||||
*/
|
||||
private function getAgentMonthlyPoliciesData($managerId, $AgentId, $month): array
|
||||
private function getAgentMonthlyPoliciesData($managerId, $AgentId): array
|
||||
{
|
||||
// --- Correction 1: Initialize Database Connection ---
|
||||
|
||||
@ -952,16 +953,16 @@ class ExcelExportController extends ResourceController
|
||||
$builder->where('pp.policy_number IS NOT NULL');
|
||||
|
||||
// --- Correction 2: Use Robust Date Range Filtering ---
|
||||
if ($month === "current") {
|
||||
// WHERE issued_date >= start_of_current_month AND issued_date < start_of_next_month
|
||||
// if ($month === "current") {
|
||||
// // 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(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH), '%Y-%m-01')", NULL, FALSE);
|
||||
}
|
||||
else if ($month === "previous") {
|
||||
// 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(CURRENT_DATE(), '%Y-%m-01')", NULL, FALSE);
|
||||
}
|
||||
// }
|
||||
// else if ($month === "previous") {
|
||||
// // 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(CURRENT_DATE(), '%Y-%m-01')", NULL, FALSE);
|
||||
// }
|
||||
|
||||
$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.
|
||||
* @param string $managerId
|
||||
* @param int $brokerId
|
||||
* @param string $month ('current' or 'previous')
|
||||
* @return 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.
|
||||
* @param string $managerId
|
||||
* @param int $brokerId
|
||||
* @param string $month ('current' or 'previous')
|
||||
* @return array
|
||||
*/
|
||||
private function getLowPremiumAgentData($managerId): array
|
||||
@ -1043,8 +1040,8 @@ class ExcelExportController extends ResourceController
|
||||
pa.name AS agent_name,
|
||||
pa.agent_code,
|
||||
CASE
|
||||
WHEN pa.is_active = 1 THEN 'Active Agent'
|
||||
ELSE 'Inactive Agent'
|
||||
WHEN pa.is_active = 1 THEN 'Active Partner'
|
||||
ELSE 'Inactive Partner'
|
||||
END AS agent_status,
|
||||
pp.policy_number,
|
||||
DATE_FORMAT(pp.issued_date, '%d-%m-%Y') AS issued_date,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user