FEATURE_ exportCashDepositData New api : GWM

This commit is contained in:
bitbucket 2024-04-24 17:06:43 +05:30
parent 4aa74e7d44
commit b34ebf686c
2 changed files with 70 additions and 1 deletions

View File

@ -267,6 +267,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
$routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData");
});
$routes->post("sendEmail", "EmployeeRestController::send_email");

View File

@ -398,7 +398,7 @@ class EmployeeRestController extends AdminController
if(count($empData))
{
// Define headers and map database fields to Excel fields
// Define headers and map database fields to Excel fields
$headers = [
'Employee Code' => 'emp_code',
'Name' => 'name',
@ -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);
}
}
}