FIX_Excel
This commit is contained in:
parent
964eec071a
commit
3fda0c6839
@ -1518,6 +1518,14 @@ class ExcelExportController extends ResourceController
|
|||||||
try{
|
try{
|
||||||
$managerId = $this->request->getGet('manager_id');
|
$managerId = $this->request->getGet('manager_id');
|
||||||
$search = $this->request->getGet('search');
|
$search = $this->request->getGet('search');
|
||||||
|
$agent_id = $this->request->getGet('agent_id');
|
||||||
|
$policy_number = $this->request->getGet('policy_number');
|
||||||
|
$from_date = $this->request->getGet('from_date');
|
||||||
|
$to_date = $this->request->getGet('to_date');
|
||||||
|
$endorsement_type = $this->request->getGet('endorsement_type');
|
||||||
|
$insurer_id = $this->request->getGet('insurer_id');
|
||||||
|
$status = $this->request->getGet('status');
|
||||||
|
$verification = $this->request->getGet('verification');
|
||||||
|
|
||||||
|
|
||||||
// --- ADDED VALIDATION (Simplified logic for clarity) ---
|
// --- ADDED VALIDATION (Simplified logic for clarity) ---
|
||||||
@ -1527,22 +1535,21 @@ class ExcelExportController extends ResourceController
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->getDataEndorsement($managerId,$search);
|
// $data = $this->getDataEndorsement($managerId,$search);
|
||||||
|
$data = $this->getDataEndorsement($managerId,$search,$agent_id,$policy_number,$from_date,$to_date,$endorsement_type,$insurer_id,$status,$verification);
|
||||||
|
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
throw new \RuntimeException('No Endorsement Details found.', 404);
|
throw new \RuntimeException('No Endorsement Details found.', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define column headers
|
|
||||||
|
|
||||||
|
|
||||||
$header = [
|
$header = [
|
||||||
'S.No',
|
'S.No',
|
||||||
'Created Date',
|
'Created Date',
|
||||||
'Internal/External',
|
'Internal/External',
|
||||||
'Created By',
|
'Created By',
|
||||||
'Policy Number',
|
'Policy Number',
|
||||||
|
'Start Date', 'End Date',
|
||||||
'Vehicle No',
|
'Vehicle No',
|
||||||
'Type Of Endorsement',
|
'Type Of Endorsement',
|
||||||
'Endorsement Number',
|
'Endorsement Number',
|
||||||
@ -1553,6 +1560,7 @@ class ExcelExportController extends ResourceController
|
|||||||
'Contact Person',
|
'Contact Person',
|
||||||
'Remarks',
|
'Remarks',
|
||||||
'Is Financial',
|
'Is Financial',
|
||||||
|
'Status','Verification','Pending Days',
|
||||||
'Endorsement Premium Amount',
|
'Endorsement Premium Amount',
|
||||||
'Commission Amount',
|
'Commission Amount',
|
||||||
];
|
];
|
||||||
@ -2468,67 +2476,174 @@ class ExcelExportController extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function getDataEndorsement($managerId, $search = ''): array
|
private function getDataEndorsement($managerId, $search = '',
|
||||||
|
$agent_id = null,
|
||||||
|
$policy_number = null,
|
||||||
|
$from_date = null,
|
||||||
|
$to_date = null,
|
||||||
|
$endorsement_type = null,
|
||||||
|
$insurer_id = null,
|
||||||
|
$status = null,
|
||||||
|
$verification = null
|
||||||
|
): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$builder = $this->db->table('partner_endorsement_request per');
|
||||||
|
$builder->select("
|
||||||
|
DATE_FORMAT(per.created_at, '%d-%m-%Y %h:%i %p') AS received_date,
|
||||||
|
per.policy_from,
|
||||||
|
ps.name AS staff_name,
|
||||||
|
per.policy_number,
|
||||||
|
CASE
|
||||||
|
WHEN per.policy_start_date = '0000-00-00'
|
||||||
|
OR YEAR(per.policy_start_date) < 2000
|
||||||
|
THEN NULL
|
||||||
|
ELSE DATE_FORMAT(per.policy_start_date, '%Y-%m-%d')
|
||||||
|
END AS policy_start_date,
|
||||||
|
CASE
|
||||||
|
WHEN per.policy_end_date = '0000-00-00'
|
||||||
|
OR YEAR(per.policy_end_date) < 2000
|
||||||
|
THEN NULL
|
||||||
|
ELSE DATE_FORMAT(per.policy_end_date, '%Y-%m-%d')
|
||||||
|
END AS policy_end_date,
|
||||||
|
per.reg_no,
|
||||||
|
petm.endorsement_type,
|
||||||
|
per.endorsement_no,
|
||||||
|
per.insured_name,
|
||||||
|
CONCAT(I.name, ' - ', I.short_name) AS insurer_name,
|
||||||
|
pb.name AS broker_name,
|
||||||
|
CONCAT(pa.agent_code, ' - ', pa.name) AS agent_details,
|
||||||
|
per.contact_person,
|
||||||
|
per.endorsement_description,
|
||||||
|
per.financia_or_non_financial,
|
||||||
|
per.status,
|
||||||
|
CASE
|
||||||
|
WHEN per.is_data_accuracy_checked = 0 THEN 'To Verify'
|
||||||
|
ELSE 'Verified'
|
||||||
|
END AS verification_status,
|
||||||
|
CASE
|
||||||
|
WHEN per.created_at IS NULL
|
||||||
|
THEN 0
|
||||||
|
ELSE DATEDIFF(CURDATE(), DATE(per.created_at))
|
||||||
|
END AS pending_days,
|
||||||
|
per.endorsement_premium,
|
||||||
|
per.commission_amount,
|
||||||
|
");
|
||||||
|
|
||||||
$sql = "SELECT
|
// ✅ Correct joins (NO duplicates)
|
||||||
DATE_FORMAT(per.created_at, '%d-%m-%Y %h:%i %p') AS received_date,
|
$builder->join('partner_policy pp', 'pp.policy_number = per.policy_number', 'left');
|
||||||
per.policy_from,
|
$builder->join('partner_enquiry pe', 'pe.id = pp.enquiry_id', 'left');
|
||||||
ps.name AS staff_name,
|
$builder->join('partner_agent pa', 'pa.id = per.agent_id', 'left');
|
||||||
per.policy_number AS policy_number,
|
$builder->join('partner_staff ps', 'ps.id = per.created_by', 'left');
|
||||||
per.reg_no,
|
$builder->join('insurers I', 'I.id = per.insurer_id', 'left');
|
||||||
petm.endorsement_type AS endorsement_type,
|
$builder->join('partner_endorsement_type_master petm', 'petm.id = per.endorsement_type', 'left');
|
||||||
per.endorsement_no,
|
$builder->join('partner_brokers pb', 'pb.id = per.broker_id', 'left');
|
||||||
per.insured_name,
|
$builder->join('clients c', 'c.id = per.client_id', 'left');
|
||||||
I.name AS insurer_name,
|
$builder->join('partner_payment_mode_master pm', 'pm.id = per.payment_mode_id', 'left');
|
||||||
pb.name AS broker_name,
|
$builder->where('per.manager_id', $managerId);
|
||||||
CONCAT(pa.agent_code, ' - ', pa.name) AS agent_details,
|
$builder->where('per.is_active', 1);
|
||||||
per.contact_person,
|
|
||||||
per.endorsement_description,
|
|
||||||
per.financia_or_non_financial,
|
|
||||||
per.endorsement_premium,
|
|
||||||
per.commission_amount
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM partner_endorsement_request per
|
// Filters
|
||||||
LEFT JOIN partner_policy pp ON pp.agent_id = per.agent_id
|
if (!empty($agent_id)) {
|
||||||
LEFT JOIN partner_enquiry pe ON pe.agent_id = per.agent_id
|
$builder->where('per.agent_id', $agent_id);
|
||||||
LEFT JOIN partner_agent pa ON pa.id = per.agent_id
|
}
|
||||||
LEFT JOIN partner_staff ps ON ps.id = per.created_by
|
|
||||||
LEFT JOIN insurers I ON I.id = pe.insurer_id
|
|
||||||
LEFT JOIN partner_endorsement_type_master petm ON petm.id = per.endorsement_type
|
|
||||||
LEFT JOIN partner_brokers pb ON pb.id = per.broker_id
|
|
||||||
WHERE per.manager_id = ?
|
|
||||||
AND per.is_active = 1";
|
|
||||||
|
|
||||||
$bindings = [$managerId];
|
if (!empty($policy_number)) {
|
||||||
|
$builder->where('per.policy_number', $policy_number);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($search)) {
|
if (!empty($from_date) && !empty($to_date)) {
|
||||||
|
$builder->where('per.created_at >=', $from_date . ' 00:00:00');
|
||||||
|
$builder->where('per.created_at <=', $to_date . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
$searchTerm = '%' . strtolower(trim($search)) . '%';
|
if (!empty($endorsement_type) && $endorsement_type != 'All') {
|
||||||
|
$builder->where('per.endorsement_type', $endorsement_type);
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= " AND (
|
if (!empty($insurer_id)) {
|
||||||
LOWER(per.policy_from) LIKE ? OR
|
$builder->where('per.insurer_id', $insurer_id);
|
||||||
LOWER(per.status) LIKE ? OR
|
}
|
||||||
LOWER(pe.reg_no) LIKE ? OR
|
|
||||||
LOWER(I.name) LIKE ? OR
|
|
||||||
LOWER(pp.policy_number) LIKE ? OR
|
|
||||||
LOWER(petm.endorsement_type) LIKE ? OR
|
|
||||||
LOWER(per.endorsement_no) LIKE ?
|
|
||||||
)";
|
|
||||||
|
|
||||||
for ($i = 0; $i < 7; $i++) {
|
if (!empty($status) && $status != 'All') {
|
||||||
$bindings[] = $searchTerm;
|
$builder->where('per.status', $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($verification) && $verification != 'All') {
|
||||||
|
if ($verification == 'Verified') {
|
||||||
|
$builder->where('per.is_data_accuracy_checked', 1);
|
||||||
|
} elseif ($verification == 'To Verify') {
|
||||||
|
$builder->where('per.is_data_accuracy_checked', 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GROUP BY must be LAST
|
// Search filter
|
||||||
$sql .= " GROUP BY per.id";
|
// if (!empty($search)) {
|
||||||
|
// $search = strtolower(trim($search));
|
||||||
|
|
||||||
$query = $this->db->query($sql, $bindings);
|
// $builder->groupStart()
|
||||||
$results = $query->getResultArray();
|
// ->like('LOWER(per.policy_from)', $search)
|
||||||
|
// ->orLike('LOWER(per.status)', $search)
|
||||||
|
// ->orLike('LOWER(per.reg_no)', $search)
|
||||||
|
// ->orLike('LOWER(per.policy_start_date)', $search)
|
||||||
|
// ->orLike('LOWER(per.policy_end_date)', $search)
|
||||||
|
// ->orLike('LOWER(I.name)', $search)
|
||||||
|
// ->orLike('LOWER(I.insurer_short_name)', $search)
|
||||||
|
// ->orLike('LOWER(per.policy_number)', $search)
|
||||||
|
// ->orLike('LOWER(petm.endorsement_type)', $search)
|
||||||
|
// ->orLike('LOWER(per.endorsement_no)', $search)
|
||||||
|
// ->groupEnd();
|
||||||
|
// }
|
||||||
|
if (!empty($search)) {
|
||||||
|
$search = strtolower(trim($search));
|
||||||
|
|
||||||
|
$builder->groupStart()
|
||||||
|
|
||||||
|
// Normal columns
|
||||||
|
->like('LOWER(per.policy_from)', $search)
|
||||||
|
->orLike('LOWER(per.status)', $search)
|
||||||
|
->orLike('LOWER(per.reg_no)', $search)
|
||||||
|
->orLike('LOWER(per.policy_number)', $search)
|
||||||
|
->orLike('LOWER(per.endorsement_no)', $search)
|
||||||
|
|
||||||
|
// Insurer
|
||||||
|
->orLike('LOWER(I.name)', $search)
|
||||||
|
->orLike('LOWER(I.short_name)', $search)
|
||||||
|
|
||||||
|
// Endorsement type
|
||||||
|
->orLike('LOWER(petm.endorsement_type)', $search)
|
||||||
|
|
||||||
|
// ✅ Broker name
|
||||||
|
->orLike('LOWER(pb.name)', $search)
|
||||||
|
|
||||||
|
// ✅ Agent code + name (CONCAT)
|
||||||
|
->orLike("LOWER(CONCAT(pa.agent_code, ' - ', pa.name))", $search)
|
||||||
|
->orLike("LOWER(pa.agent_code)", $search)
|
||||||
|
->orLike("LOWER(pa.name)", $search)
|
||||||
|
|
||||||
|
// ✅ Verification (CASE condition)
|
||||||
|
->orLike("
|
||||||
|
LOWER(
|
||||||
|
CASE
|
||||||
|
WHEN per.is_data_accuracy_checked = 0 THEN 'to verify'
|
||||||
|
ELSE 'verified'
|
||||||
|
END
|
||||||
|
)", $search)
|
||||||
|
|
||||||
|
// ✅ Received date (formatted)
|
||||||
|
->orLike("DATE_FORMAT(per.created_at, '%d-%m-%Y %h:%i %p')", $search)
|
||||||
|
|
||||||
|
// ✅ Policy dates (formatted)
|
||||||
|
->orLike("DATE_FORMAT(per.policy_start_date, '%Y-%m-%d')", $search)
|
||||||
|
->orLike("DATE_FORMAT(per.policy_end_date, '%Y-%m-%d')", $search)
|
||||||
|
|
||||||
|
->groupEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$builder->groupBy('per.id');
|
||||||
|
|
||||||
|
$results = $builder->get()->getResultArray();
|
||||||
|
|
||||||
// Convert associative rows to indexed rows (Excel-friendly)
|
// Convert associative rows to indexed rows (Excel-friendly)
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user