GWM : commissionPayoutReportExport API

This commit is contained in:
Gowtham M 2026-04-18 18:33:29 +05:30
parent 5e17a4c2e4
commit 9dad32794b

View File

@ -1812,6 +1812,14 @@ class PolicyController extends ResourceController
. 'WHERE pii_utr.policy_id = pp.id AND pii_utr.is_active = 1), "") AS utr_no', . 'WHERE pii_utr.policy_id = pp.id AND pii_utr.is_active = 1), "") AS utr_no',
false false
); );
$builder->select(
'COALESCE((SELECT GROUP_CONCAT(DATE_FORMAT(piu.utr_date, \'%d-%m-%Y\') ORDER BY piu.id SEPARATOR ", ") '
. 'FROM partner_invoice_items pii_utr2 '
. 'INNER JOIN partner_invoice pi_u2 ON pi_u2.id = pii_utr2.invoice_id AND pi_u2.is_active = 1 '
. 'INNER JOIN partner_invoice_utr piu ON piu.invoice_id = pii_utr2.invoice_id AND piu.is_active = 1 '
. 'WHERE pii_utr2.policy_id = pp.id AND pii_utr2.is_active = 1), "") AS utr_date',
false
);
$builder->select( $builder->select(
"(CASE WHEN EXISTS (SELECT 1 FROM partner_invoice_items pii " "(CASE WHEN EXISTS (SELECT 1 FROM partner_invoice_items pii "
. "INNER JOIN partner_invoice pi ON pi.id = pii.invoice_id AND pi.is_active = 1 " . "INNER JOIN partner_invoice pi ON pi.id = pii.invoice_id AND pi.is_active = 1 "
@ -1888,33 +1896,52 @@ class PolicyController extends ResourceController
'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['argb' => 'FFFFFF00']], 'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['argb' => 'FFFFFF00']],
'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10], 'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10],
]; ];
$colHeaderStyle = [ $colHeaderStyleText = [
'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10], 'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10],
'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['argb' => 'FFB8CCE4']], 'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['argb' => 'FFB8CCE4']],
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, 'wrapText' => true], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, 'wrapText' => true],
'borders' => ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]], 'borders' => ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]],
]; ];
$cellStyle = [ $colHeaderStyleNumber = [
'font' => ['name' => 'Arial', 'size' => 9], 'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10],
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER], 'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['argb' => 'FFB8CCE4']],
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, 'wrapText' => true],
'borders' => ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]], 'borders' => ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]],
]; ];
// Data rows: text left-aligned (LTR), numbers right-aligned
$cellBorder = ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]];
$cellStyleText = [
'font' => ['name' => 'Arial', 'size' => 9],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
],
'borders' => $cellBorder,
];
$cellStyleNumber = [
'font' => ['name' => 'Arial', 'size' => 9],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
],
'borders' => $cellBorder,
];
$summaryLabelStyle = [ $summaryLabelStyle = [
'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10], 'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10],
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT],
]; ];
$summaryValueStyle = [ $summaryValueStyle = [
'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10, 'color' => ['argb' => 'FF0070C0']], 'font' => ['bold' => true, 'name' => 'Arial', 'size' => 10, 'color' => ['argb' => 'FF0070C0']],
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT],
]; ];
// Total columns used: AT (20 columns) // Total columns used: AV (UTR NO + UTR DATE after PAYMENT PO MODE)
$lastCol = 'T'; $lastCol = 'V';
$lastColNo = 20; $lastColNo = 22;
// ── Row 1: Title ────────────────────────────────────────────────────── // ── Row 1: Title ──────────────────────────────────────────────────────
$sheet->mergeCells("A1:{$lastCol}1"); $sheet->mergeCells("A1:{$lastCol}1");
$sheet->setCellValue('A1', 'WE NEED THIS TYPE FORMENT IN PATNER LOGIN (PAYOUT REPORT)'); $sheet->setCellValue('A1', 'Payout Report');
$sheet->getStyle('A1')->applyFromArray($redBoldCenter); $sheet->getStyle('A1')->applyFromArray($redBoldCenter);
$sheet->getRowDimension(1)->setRowHeight(20); $sheet->getRowDimension(1)->setRowHeight(20);
@ -1961,12 +1988,18 @@ class PolicyController extends ResourceController
'Q3' => 'A+B (NET)', 'Q3' => 'A+B (NET)',
'R3' => 'S.TAX', 'R3' => 'S.TAX',
'S3' => 'TOTAL', 'S3' => 'TOTAL',
'T3' => "PAYMENT\nPO MODE", // UTR / UTR DATE placed here for simplicity 'T3' => "PAYMENT\nPO MODE",
'U3' => 'UTR NO',
'V3' => 'UTR DATE',
]; ];
$headerNumberCols = ['A', 'O', 'P', 'Q', 'R', 'S', 'I'];
foreach ($headers as $cell => $label) { foreach ($headers as $cell => $label) {
$sheet->setCellValue($cell, $label); $sheet->setCellValue($cell, $label);
$sheet->getStyle($cell)->applyFromArray($colHeaderStyle); $col = preg_replace('/\d+/', '', $cell);
$sheet->getStyle($cell)->applyFromArray(
in_array($col, $headerNumberCols, true) ? $colHeaderStyleNumber : $colHeaderStyleText
);
} }
$sheet->getRowDimension(3)->setRowHeight(30); $sheet->getRowDimension(3)->setRowHeight(30);
@ -1976,7 +2009,7 @@ class PolicyController extends ResourceController
foreach ($rows as $index => $row) { foreach ($rows as $index => $row) {
$refNo = $index + 1; $refNo = $index + 1;
$policyNo = $row['policy_no'] ?? ''; $policyNo = '`'.$row['policy_no'] ?? '';
$regNo = $row['reg_no'] ?? ''; $regNo = $row['reg_no'] ?? '';
$fuelType = $row['fuel_type'] ?? ''; $fuelType = $row['fuel_type'] ?? '';
$vehicleType = $row['vehicle_type'] ?? ''; $vehicleType = $row['vehicle_type'] ?? '';
@ -1984,6 +2017,7 @@ class PolicyController extends ResourceController
$commissionAmt = (float) ($row['commission_amount'] ?? 0); $commissionAmt = (float) ($row['commission_amount'] ?? 0);
$premium = (float) ($row['premium'] ?? 0); $premium = (float) ($row['premium'] ?? 0);
$utrNo = $row['utr_no'] ?? ''; $utrNo = $row['utr_no'] ?? '';
$utrDate = $row['utr_date'] ?? '';
$payoutStatus = ($row['received_or_not'] ?? '') === 'yes' ? 'LINK' : 'PENDING'; $payoutStatus = ($row['received_or_not'] ?? '') === 'yes' ? 'LINK' : 'PENDING';
$rowData = [ $rowData = [
@ -2006,12 +2040,17 @@ class PolicyController extends ResourceController
'Q' => $premium, // A+B Net 'Q' => $premium, // A+B Net
'R' => 0, // S.TAX add if available 'R' => 0, // S.TAX add if available
'S' => $commissionAmt, // Commission as TOTAL 'S' => $commissionAmt, // Commission as TOTAL
'T' => $payoutStatus . ($utrNo ? ' | ' . $utrNo : ''), 'T' => $payoutStatus,
'U' => $utrNo,
'V' => $utrDate,
]; ];
$dataNumberCols = ['A', 'I', 'O', 'P', 'Q', 'R', 'S'];
foreach ($rowData as $col => $value) { foreach ($rowData as $col => $value) {
$sheet->setCellValue("{$col}{$rowNum}", $value); $sheet->setCellValue("{$col}{$rowNum}", $value);
$sheet->getStyle("{$col}{$rowNum}")->applyFromArray($cellStyle); $sheet->getStyle("{$col}{$rowNum}")->applyFromArray(
in_array($col, $dataNumberCols, true) ? $cellStyleNumber : $cellStyleText
);
} }
$sheet->getRowDimension($rowNum)->setRowHeight(18); $sheet->getRowDimension($rowNum)->setRowHeight(18);
@ -2020,7 +2059,7 @@ class PolicyController extends ResourceController
// ── Summary row ─────────────────────────────────────────────────────── // ── Summary row ───────────────────────────────────────────────────────
$summaryRow = $rowNum + 1; $summaryRow = $rowNum + 1;
$sheet->mergeCells("A{$summaryRow}:R{$summaryRow}"); $sheet->mergeCells("A{$summaryRow}:{$lastCol}{$summaryRow}");
$sheet->setCellValue("A{$summaryRow}", 'TOTAL COMMISSION SUMMARY'); $sheet->setCellValue("A{$summaryRow}", 'TOTAL COMMISSION SUMMARY');
$sheet->getStyle("A{$summaryRow}")->applyFromArray($summaryLabelStyle); $sheet->getStyle("A{$summaryRow}")->applyFromArray($summaryLabelStyle);
@ -2047,7 +2086,8 @@ class PolicyController extends ResourceController
'A' => 8, 'B' => 16, 'C' => 13, 'D' => 14, 'E' => 16, 'A' => 8, 'B' => 16, 'C' => 13, 'D' => 14, 'E' => 16,
'F' => 13, 'G' => 13, 'H' => 10, 'I' => 8, 'J' => 8, 'F' => 13, 'G' => 13, 'H' => 10, 'I' => 8, 'J' => 8,
'K' => 10, 'L' => 13, 'M' => 16, 'N' => 16, 'O' => 8, 'K' => 10, 'L' => 13, 'M' => 16, 'N' => 16, 'O' => 8,
'P' => 8, 'Q' => 10, 'R' => 8, 'S' => 10, 'T' => 18, 'P' => 8, 'Q' => 10, 'R' => 8, 'S' => 10, 'T' => 12,
'U' => 18, 'V' => 14,
]; ];
foreach ($colWidths as $col => $width) { foreach ($colWidths as $col => $width) {
$sheet->getColumnDimension($col)->setWidth($width); $sheet->getColumnDimension($col)->setWidth($width);