Update Import Billing & Invoice
This commit is contained in:
@@ -575,6 +575,12 @@ class CorporateController extends Controller
|
||||
"file_url" => url('files/Template Import Request LOG.xlsx')
|
||||
]);
|
||||
break;
|
||||
case 'final-log-invoice':
|
||||
return Helper::responseJson([
|
||||
'file_name' => "Template Import Invoice.xlsx",
|
||||
"file_url" => url('files/Template Import Invoice.xlsx')
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
return Helper::responseJson([], 'error', 404);
|
||||
break;
|
||||
|
||||
@@ -22,6 +22,8 @@ use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||
use Box\Spout\Common\Entity\Style\CellAlignment;
|
||||
|
||||
|
||||
use Exception;
|
||||
@@ -212,7 +214,7 @@ class RequestLogController extends Controller
|
||||
});
|
||||
return Helper::responseJson(data: $manipulatedIcds);
|
||||
}
|
||||
|
||||
|
||||
public function hospitals(){
|
||||
$organizations = Organization::query()
|
||||
->where([
|
||||
@@ -330,7 +332,7 @@ class RequestLogController extends Controller
|
||||
|
||||
// Hapus semua manfaat log permintaan terkait
|
||||
RequestLogBenefit::where('request_log_id', $id)->delete();
|
||||
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Delete Final LOG',
|
||||
@@ -461,7 +463,7 @@ class RequestLogController extends Controller
|
||||
// if($requestLog->service_code != 'IP'){
|
||||
// $requestLog->discharge_date = Carbon::now();
|
||||
// }
|
||||
|
||||
|
||||
$requestLog->save();
|
||||
|
||||
|
||||
@@ -670,6 +672,181 @@ class RequestLogController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
public function importInvoice(Request $request)
|
||||
{
|
||||
if ($request->hasFile('file')) {
|
||||
$file = $request->file('file');
|
||||
$data = Excel::toArray([], $file);
|
||||
|
||||
$processedData = $this->processCategoryNames($data);
|
||||
|
||||
$importedRows = 0;
|
||||
$result_rows = [];
|
||||
$failedRows = [];
|
||||
|
||||
foreach ($processedData as $row) {
|
||||
if($row['code'])
|
||||
{
|
||||
try {
|
||||
$affectedRows = DB::table('request_logs')
|
||||
->where('code','=', $row['code'])
|
||||
->update([
|
||||
'invoice_no' => $row['invoice_no'],
|
||||
'billing_no' => $row['billing_no'],
|
||||
]);
|
||||
|
||||
if ($affectedRows === 0) {
|
||||
$row['code_error'] = '500';
|
||||
$row['error'] = 'Gagal update karena data sudah ada ';
|
||||
$result_rows[] = $row;
|
||||
$failedRows[] = $row;
|
||||
} else {
|
||||
$importedRows += $affectedRows;
|
||||
$row['code_error'] = '200';
|
||||
$row['error'] = 'Sukses';
|
||||
$result_rows[] = $row;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$row['code_error'] = '500';
|
||||
$row['error'] = $e->getMessage();
|
||||
if(!$row['code'])
|
||||
{
|
||||
$row['error'] = 'Kolom Code wajib isi';
|
||||
}
|
||||
if(!$row['invoice_no'])
|
||||
{
|
||||
$row['error'] = 'No Invoice wajib isi';
|
||||
}
|
||||
if(!$row['billing_no'])
|
||||
{
|
||||
$row['error'] = 'No Billing wajib isi';
|
||||
}
|
||||
$result_rows[] = $row;
|
||||
$failedRows[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$response = [
|
||||
'message' => 'File uploaded and data saved to database',
|
||||
'metaData' => 'invoice',
|
||||
'data' => [
|
||||
'total_success_row' => $importedRows,
|
||||
'total_failed_row' => count($failedRows),
|
||||
'result_rows' => $result_rows,
|
||||
],
|
||||
];
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
return response()->json(['error' => 'No file uploaded.']);
|
||||
}
|
||||
|
||||
private function processCategoryNames($data)
|
||||
{
|
||||
$header = [];
|
||||
$row = [];
|
||||
for ($i = 1; $i < count($data[0]); $i++) {
|
||||
$row[] = $data[0][$i];
|
||||
$header[] = $data[0][0];
|
||||
}
|
||||
|
||||
$filed = [];
|
||||
foreach ($header[0] as $value)
|
||||
{
|
||||
$modelColumn = strtolower(preg_replace('/\s+/', '_', trim($value)));
|
||||
$modelColumn = str_replace(['*', ' '], '', $modelColumn);
|
||||
if($modelColumn)
|
||||
{
|
||||
$filed[] = $modelColumn;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($row as $subarray) {
|
||||
$trimmedSubarray = [];
|
||||
for ($i = 0; $i < count($filed); $i++) {
|
||||
$trimmedSubarray[$filed[$i]] = $subarray[$i] ? $subarray[$i] : null;
|
||||
}
|
||||
|
||||
$result[] = $trimmedSubarray;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function exportFiledInvoice(Request $request)
|
||||
{
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
$writer->openToFile(public_path('files/Report-Data-Result-Import.xlsx'));
|
||||
$header = [
|
||||
'Code*',
|
||||
'Inovice No*',
|
||||
'Billing NO*',
|
||||
'Ingest Code',
|
||||
'Ingest Note'
|
||||
];
|
||||
$style = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
// ->setFontSize(15)
|
||||
// ->setFontColor(Color::BLUE)
|
||||
// ->setShouldWrapText()
|
||||
->setCellAlignment(CellAlignment::LEFT)
|
||||
// ->setBackgroundColor(Color::YELLOW)
|
||||
->build();
|
||||
|
||||
$headerRow = WriterEntityFactory::createRowFromArray($header, $style);
|
||||
$writer->addRow($headerRow);
|
||||
// ============================
|
||||
|
||||
foreach($request->params as $item)
|
||||
{
|
||||
|
||||
$rowData = [
|
||||
$item['code'],
|
||||
$item['invoice_no'],
|
||||
$item['billing_no'],
|
||||
$item['code_error'],
|
||||
$item['error']
|
||||
];
|
||||
$style = (new StyleBuilder())
|
||||
//->setFontBold()
|
||||
// ->setFontSize(15)
|
||||
// ->setFontColor(Color::BLUE)
|
||||
// ->setShouldWrapText()
|
||||
->setCellAlignment(CellAlignment::LEFT)
|
||||
// ->setBackgroundColor(Color::YELLOW)
|
||||
->build();
|
||||
$row = WriterEntityFactory::createRowFromArray($rowData, $style);
|
||||
$writer->addRow($row);
|
||||
}
|
||||
$footer = [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
''
|
||||
];
|
||||
$style = (new StyleBuilder())
|
||||
->setFontBold()
|
||||
// ->setFontSize(15)
|
||||
// ->setFontColor(Color::BLUE)
|
||||
// ->setShouldWrapText()
|
||||
->setCellAlignment(CellAlignment::LEFT)
|
||||
// ->setBackgroundColor(Color::YELLOW)
|
||||
->build();
|
||||
|
||||
$footerRow = WriterEntityFactory::createRowFromArray($footer, $style);
|
||||
$writer->addRow($footerRow);
|
||||
|
||||
$writer->close();
|
||||
|
||||
return Helper::responseJson([
|
||||
'file_name' => 'Report-Data-Result-Import',
|
||||
"file_url" => url('files/Report-Data-Result-Import.xlsx')
|
||||
]);
|
||||
}
|
||||
|
||||
public function claimRequestDetail($claimRequestId)
|
||||
{
|
||||
$status = DB::table('claim_requests')
|
||||
@@ -962,7 +1139,7 @@ class RequestLogController extends Controller
|
||||
// Menghapus file dari penyimpanan
|
||||
if (Storage::exists($path)) {
|
||||
Storage::delete($path);
|
||||
|
||||
|
||||
// Update entri file dari basis data
|
||||
File::where('path', $request->path)->update([
|
||||
'deleted_at' => Carbon::now(), // Gunakan Carbon untuk mendapatkan tanggal dan waktu saat ini
|
||||
|
||||
@@ -278,6 +278,8 @@ Route::prefix('internal')->group(function () {
|
||||
Route::put('customer-service/request/final_log/{id}', [RequestLogController::class, 'deleteFinalLog']);
|
||||
Route::get('customer-service/request/{id}/download', [RequestLogController::class, 'generateRequestLog']);
|
||||
Route::post('customer-service/request/import', [RequestLogController::class, 'importRequestLog']);
|
||||
Route::post('customer-service/request/import-invoice', [RequestLogController::class, 'importInvoice']);
|
||||
Route::post('customer-service/request/exportFiledInvoice', [RequestLogController::class, 'exportFiledInvoice']);
|
||||
Route::get('customer-service/request/data', [RequestLogController::class, 'generateDataRequestLogExcel']);
|
||||
Route::post('customer-service/request/{id}/add_file', [RequestLogController::class, 'requestFiles']);
|
||||
Route::post('customer-service/request/{id}/delete_file', [RequestLogController::class, 'deleteFiles']);
|
||||
@@ -306,13 +308,13 @@ Route::prefix('internal')->group(function () {
|
||||
Route::resource('appointments', AppointmentController::class);
|
||||
Route::get('live-chat/export', [LivechatController::class, 'export']);
|
||||
Route::resource('live-chat', LivechatController::class);
|
||||
|
||||
|
||||
Route::get('prescription', [PrescriptionController::class, 'index']);
|
||||
|
||||
Route::post('prescription', [PrescriptionController::class, 'store']);
|
||||
Route::get('prescription-download/{id}', [PrescriptionController::class, 'downloadPrescription']);
|
||||
|
||||
|
||||
|
||||
Route::get('prescription/{id}', [PrescriptionController::class, 'index']);
|
||||
Route::get('doctorrating', [DoctorRatingController::class, 'index']);
|
||||
Route::get('doctorrating/{id}', [PrescriptionController::class, 'index']);
|
||||
|
||||
@@ -115,13 +115,12 @@ export default function List() {
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const handleImportButton = () => {
|
||||
const [paramImport, setParamImport] = useState('');
|
||||
const handleImportButton = (param:any) => {
|
||||
setParamImport(param);
|
||||
if (importForm?.current) {
|
||||
handleClose();
|
||||
importForm.current ? importForm.current.click() : console.log('No File selected');
|
||||
} else {
|
||||
alert('No file selected');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -144,12 +143,18 @@ export default function List() {
|
||||
formData.append('file', importForm.current?.files[0]);
|
||||
|
||||
setImportLoading(true);
|
||||
let url = 'claim-requests/import';
|
||||
if(paramImport == 'invoice')
|
||||
{
|
||||
url = 'customer-service/request/import-invoice'
|
||||
}
|
||||
axios
|
||||
.post(`claim-requests/import`, formData)
|
||||
.post(`${url}`, formData)
|
||||
.then((response) => {
|
||||
handleCancelImportButton();
|
||||
loadDataTableData();
|
||||
// loadDataTableData();
|
||||
setImportResult(response.data);
|
||||
setParamImport(response.data.metaData);
|
||||
// alert('Succesfully read '+ response.data.total_successed_row + ' with ' + response.data.total_failed_row + ' failed rows');
|
||||
setImportLoading(false);
|
||||
})
|
||||
@@ -166,6 +171,28 @@ export default function List() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportReportFiled = async () => {
|
||||
|
||||
await axios
|
||||
.post('customer-service/request/exportFiledInvoice', { params: importResult?.data.result_rows })
|
||||
.then((res) => {
|
||||
enqueueSnackbar('Data berhasil di Export', {
|
||||
variant: 'success',
|
||||
anchorOrigin: { horizontal: 'right', vertical: 'top' },
|
||||
});
|
||||
setImportLoading(false);
|
||||
|
||||
document.location.href = res.data.data.file_url;
|
||||
})
|
||||
.catch((err) =>
|
||||
enqueueSnackbar('Data Gagal di Export', {
|
||||
variant: 'error',
|
||||
anchorOrigin: { horizontal: 'right', vertical: 'top' },
|
||||
})
|
||||
|
||||
);
|
||||
};
|
||||
|
||||
const handleGetTemplate = (type :string) => {
|
||||
axios.get('corporates/import-document-example/' + type)
|
||||
.then((response) => {
|
||||
@@ -220,9 +247,11 @@ export default function List() {
|
||||
'aria-labelledby': 'basic-button',
|
||||
}}
|
||||
>
|
||||
<MenuItem onClick={handleImportButton}>Import</MenuItem>
|
||||
<MenuItem onClick={() => {handleImportButton('claim')}}>Import</MenuItem>
|
||||
<MenuItem onClick={() => {handleGetTemplate('claim-request')}}>Download Template</MenuItem>
|
||||
<MenuItem onClick={() => {handleGetData('data-plan-benefit')}}>Download Claim Request</MenuItem>
|
||||
<MenuItem onClick={() => {handleImportButton('invoice')}}>Import Invoice</MenuItem>
|
||||
<MenuItem onClick={() => {handleGetTemplate('final-log-invoice')}}>Download Template Invoice</MenuItem>
|
||||
</Menu>
|
||||
{/* <Button
|
||||
variant="contained"
|
||||
@@ -265,16 +294,35 @@ export default function List() {
|
||||
</LoadingButton>
|
||||
</Stack>
|
||||
)}
|
||||
{importResult && (
|
||||
{importResult && importResult?.metaData == 'invoice' ? (
|
||||
<Stack direction={'row'} sx={{ px: 2, pb: 2 }}>
|
||||
<Box sx={{ color: 'text.secondary' }}>
|
||||
Last Import Result :{' '}
|
||||
<Box sx={{ color: 'success.main', display: 'inline' }}>
|
||||
{importResult.data.total_success_row ?? 0}
|
||||
</Box>{' '}
|
||||
Row Processed,{' '}
|
||||
<Box sx={{ color: 'error.main', display: 'inline' }}>
|
||||
{importResult.data.total_failed_row}
|
||||
</Box>{' '}
|
||||
Failed,
|
||||
{/* {importResult.data.failed_rows.map((row, index) => (
|
||||
<Typography variant='body' key={index} color="error"> [Code={row.code ? row.code : 'Required'}]</Typography>
|
||||
))} */}
|
||||
Report:
|
||||
<u onClick={handleExportReportFiled} style={{cursor:'pointer'}}>Download Data Result Import</u>
|
||||
</Box>
|
||||
</Stack>
|
||||
) : importResult ? (
|
||||
<Stack direction={'row'} sx={{ px: 2, pb: 2 }}>
|
||||
<Box sx={{ color: 'text.secondary' }}>
|
||||
Last Import Result Report :{' '}
|
||||
<a href={importResult.result_file?.url ?? '#'}>
|
||||
{importResult.result_file?.name ?? '-'}
|
||||
Last Import Result Report {paramImport} :{' '}
|
||||
<a href={importResult?.result_file?.url ?? '#'}>
|
||||
{importResult?.result_file?.name ?? '-'}
|
||||
</a>
|
||||
</Box>
|
||||
</Stack>
|
||||
)}
|
||||
):''}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
BIN
public/files/Template Import Invoice.xlsx
Normal file
BIN
public/files/Template Import Invoice.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user