FEATURE_ exportCashDepositData New api : GWM
This commit is contained in:
parent
4aa74e7d44
commit
b34ebf686c
@ -267,6 +267,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
|
|||||||
|
|
||||||
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
|
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
|
||||||
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
|
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
|
||||||
|
$routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData");
|
||||||
});
|
});
|
||||||
|
|
||||||
$routes->post("sendEmail", "EmployeeRestController::send_email");
|
$routes->post("sendEmail", "EmployeeRestController::send_email");
|
||||||
|
|||||||
@ -1578,4 +1578,72 @@ public function getCashDepositData()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function exportCashDepositData()
|
||||||
|
{
|
||||||
|
|
||||||
|
$CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id'));
|
||||||
|
|
||||||
|
// echo '<pre>';print_r($CashDepositData); echo '</pre>';die;
|
||||||
|
|
||||||
|
if(count($CashDepositData))
|
||||||
|
{
|
||||||
|
// Define headers and map database fields to Excel fields
|
||||||
|
$headers = [
|
||||||
|
'Date' => 'created_at',
|
||||||
|
'Type' => 'transaction_type',
|
||||||
|
'Amount' => 'amount',
|
||||||
|
'Balance' => 'balance',
|
||||||
|
'Description' => 'description',
|
||||||
|
'Insurer Name' => 'insurer_name',
|
||||||
|
'Client Name' => 'clientname'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Create a new Spreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
|
// Get the active sheet
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add headers
|
||||||
|
$column = 'A';
|
||||||
|
foreach ($headers as $header => $dbField) {
|
||||||
|
$sheet->setCellValue($column . '1', $header);
|
||||||
|
$column++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add data
|
||||||
|
$row = 2;
|
||||||
|
foreach ($CashDepositData as $Cashvalue) {
|
||||||
|
$column = 'A';
|
||||||
|
foreach ($headers as $dbField) {
|
||||||
|
$sheet->setCellValue($column . $row, $Cashvalue->$dbField);
|
||||||
|
$column++;
|
||||||
|
}
|
||||||
|
$row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Set the header for download
|
||||||
|
$filename = $CashDepositData[0]->insurer_name.'-CashDeposit.xlsx';
|
||||||
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||||
|
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
||||||
|
header('Cache-Control: max-age=0');
|
||||||
|
|
||||||
|
// Save the Excel file to output
|
||||||
|
$writer = new Xlsx($spreadsheet);
|
||||||
|
$writer->save('php://output');
|
||||||
|
exit;
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user