fix bug upload file claim request

This commit is contained in:
korospace
2023-11-03 08:38:22 +07:00
parent 186312bb6a
commit 16449bd18b
3 changed files with 130 additions and 76 deletions

View File

@@ -51,86 +51,133 @@ class ClaimRequestController extends Controller
$code = $this->getNextCode(); $code = $this->getNextCode();
$member = Member::find($member_id); $member = Member::find($member_id);
$newClaimRequest = ClaimRequestService::storeClaimRequest(
row: [],
code: $code,
member: $member,
paymentType: 'reimbursement',
serviceCode: $request->service_code[$key],
);
ClaimRequested::dispatch($newClaimRequest); DB::beginTransaction();
// Log History
$newClaimRequest->histories()->create([
'title' => 'New Claim Requested',
'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})",
'type' => 'info',
'system_origin' => 'client-portal'
]);
// Claim Log try {
DB::table('claim_logs') $newClaimRequest = ClaimRequestService::storeClaimRequest(
->insert([ row: [],
'claim_request_id' => $newClaimRequest->id, code: $code,
'status' => 'requested', member: $member,
'date' => date('Y-m-d H:i:s'), paymentType: 'reimbursement',
'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})", serviceCode: $request->service_code[$key],
'system_origin' => 'hospital-portal', );
'created_by' => auth()->user()->id,
'created_at' => date('Y-m-d H:i:s'),
'updated_at'=> date('Y-m-d H:i:s'),
]);
if ($request->hasFile('laboratorium')) { ClaimRequested::dispatch($newClaimRequest);
foreach ($request->laboratorium[$key] as $file) {
$pathFile = File::storeFile('claim-result', $newClaimRequest->id, $file); // Log History
$newClaimRequest->files()->updateOrCreate([ $newClaimRequest->histories()->create([
'type' => 'claim-result', 'title' => 'New Claim Requested',
'name' => File::getFileName('claim-result', $newClaimRequest->id, $file), 'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})",
'original_name' => $file->getClientOriginalName(), 'type' => 'info',
'extension' => $file->getClientOriginalExtension(), 'system_origin' => 'client-portal'
'path' => $pathFile, ]);
'created_by' => auth()->user()->id,
'updated_by' => auth()->user()->id, // Claim Log
]); DB::table('claim_logs')
->insert([
'claim_request_id' => $newClaimRequest->id,
'status' => 'requested',
'date' => date('Y-m-d H:i:s'),
'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})",
'system_origin' => 'hospital-portal',
'created_by' => auth()->user()->id,
'created_at' => date('Y-m-d H:i:s'),
'updated_at'=> date('Y-m-d H:i:s'),
]);
$storage_path = storage_path() . "/app/public";
$folder = "claim/";
if (is_dir($storage_path . "/" . $folder) == false) {
mkdir($storage_path . "/" . $folder, 0770, true);
} }
if (isset($_FILES['laboratorium'])) {
foreach ($_FILES['laboratorium']['error']["member_" .$member_id] as $key => $value) {
if ($value == 0) {
$new_file_name = "claim-result-" . time() . "-" . uniqid();
$ekstension = "." . explode("/", $_FILES['laboratorium']['type']["member_" .$member_id][$key])[1];
$pathFile = $folder . $new_file_name . $ekstension;
$tmp_name = $_FILES['laboratorium']['tmp_name']["member_" .$member_id][$key];
$full_path = $_FILES['laboratorium']['full_path']["member_" .$member_id][$key];
if (move_uploaded_file($tmp_name, $storage_path . "/" . $pathFile)) {
$newClaimRequest->files()->updateOrCreate([
'type' => 'claim-result',
'name' => $new_file_name,
'original_name' => $full_path,
'extension' => $ekstension,
'path' => $pathFile,
'created_by' => auth()->user()->id,
'updated_by' => auth()->user()->id,
]);
}
}
}
}
if (isset($_FILES['prescription'])) {
foreach ($_FILES['prescription']['error']["member_" .$member_id] as $key => $value) {
if ($value == 0) {
$new_file_name = "claim-diagnosis-" . time() . "-" . uniqid();
$ekstension = "." . explode("/", $_FILES['prescription']['type']["member_" .$member_id][$key])[1];
$pathFile = $folder . $new_file_name . $ekstension;
$tmp_name = $_FILES['prescription']['tmp_name']["member_" .$member_id][$key];
$full_path = $_FILES['prescription']['full_path']["member_" .$member_id][$key];
if (move_uploaded_file($tmp_name, $storage_path . "/" . $pathFile)) {
$newClaimRequest->files()->updateOrCreate([
'type' => 'claim-diagnosis',
'name' => $new_file_name,
'original_name' => $full_path,
'extension' => $ekstension,
'path' => $pathFile,
'created_by' => auth()->user()->id,
'updated_by' => auth()->user()->id,
]);
}
}
}
}
if (isset($_FILES['invoice'])) {
foreach ($_FILES['invoice']['error']["member_" .$member_id] as $key => $value) {
if ($value == 0) {
$new_file_name = "claim-kondisi-" . time() . "-" . uniqid();
$ekstension = "." . explode("/", $_FILES['invoice']['type']["member_" .$member_id][$key])[1];
$pathFile = $folder . $new_file_name . $ekstension;
$tmp_name = $_FILES['invoice']['tmp_name']["member_" .$member_id][$key];
$full_path = $_FILES['invoice']['full_path']["member_" .$member_id][$key];
if (move_uploaded_file($tmp_name, $storage_path . "/" . $pathFile)) {
$newClaimRequest->files()->updateOrCreate([
'type' => 'claim-kondisi',
'name' => $new_file_name,
'original_name' => $full_path,
'extension' => $ekstension,
'path' => $pathFile,
'created_by' => auth()->user()->id,
'updated_by' => auth()->user()->id,
]);
}
}
}
}
DB::commit();
} }
catch (\Throwable $th) {
DB::rollBack();
if ($request->hasFile('prescription')) { return Helper::responseJson(status: 'failed', statusCode: 500, message: $th->getMessage());
foreach ($request->prescription[$key] as $file) {
$pathFile = File::storeFile('claim-diagnosis', $newClaimRequest->id, $file);
$newClaimRequest->files()->updateOrCreate([
'type' => 'claim-diagnosis',
'name' => File::getFileName('claim-diagnosis', $newClaimRequest->id, $file),
'original_name' => $file->getClientOriginalName(),
'extension' => $file->getClientOriginalExtension(),
'path' => $pathFile,
'created_by' => auth()->user()->id,
'updated_by' => auth()->user()->id,
]);
}
}
if ($request->hasFile('invoice')) {
foreach ($request->invoice[$key] as $file) {
$pathFile = File::storeFile('claim-kondisi', $newClaimRequest->id, $file);
$newClaimRequest->files()->updateOrCreate([
'type' => 'claim-kondisi',
'name' => File::getFileName('claim-kondisi', $newClaimRequest->id, $file),
'original_name' => $file->getClientOriginalName(),
'extension' => $file->getClientOriginalExtension(),
'path' => $pathFile,
'created_by' => auth()->user()->id,
'updated_by' => auth()->user()->id,
]);
}
} }
} }
} }
return Helper::responseJson(data: $request->toArray(), message: 'Claim Request berhasil ajukan!'); return Helper::responseJson(data: $request->toArray(), message: 'Claim Request berhasil ajukan!');
} }

View File

@@ -66,6 +66,11 @@ class ClaimRequestController extends Controller
return view('internal::create'); return view('internal::create');
} }
/**
* Create New Calim Request
*
* Bagaskoro, BSD 03 November 2023
*/
public function createNew(Request $request) public function createNew(Request $request)
{ {
$request->validate([ $request->validate([
@@ -114,11 +119,15 @@ class ClaimRequestController extends Controller
]); ]);
$storage_path = storage_path() . "/app/public"; $storage_path = storage_path() . "/app/public";
$folder = "claim/";
if (is_dir($storage_path . "/" . $folder) == false) {
mkdir($storage_path . "/" . $folder, 0770, true);
}
if (isset($_FILES['file_penunjang'])) { if (isset($_FILES['file_penunjang'])) {
foreach ($_FILES['file_penunjang']['error']["member_" .$member_id] as $key => $value) { foreach ($_FILES['file_penunjang']['error']["member_" .$member_id] as $key => $value) {
if ($value == 0) { if ($value == 0) {
$folder = "claim/";
$new_file_name = "claim-result-" . time() . "-" . uniqid(); $new_file_name = "claim-result-" . time() . "-" . uniqid();
$ekstension = "." . explode("/", $_FILES['file_penunjang']['type']["member_" .$member_id][$key])[1]; $ekstension = "." . explode("/", $_FILES['file_penunjang']['type']["member_" .$member_id][$key])[1];
$pathFile = $folder . $new_file_name . $ekstension; $pathFile = $folder . $new_file_name . $ekstension;
@@ -144,7 +153,6 @@ class ClaimRequestController extends Controller
if (isset($_FILES['file_diagnosa'])) { if (isset($_FILES['file_diagnosa'])) {
foreach ($_FILES['file_diagnosa']['error']["member_" .$member_id] as $key => $value) { foreach ($_FILES['file_diagnosa']['error']["member_" .$member_id] as $key => $value) {
if ($value == 0) { if ($value == 0) {
$folder = "claim/";
$new_file_name = "claim-diagnosis-" . time() . "-" . uniqid(); $new_file_name = "claim-diagnosis-" . time() . "-" . uniqid();
$ekstension = "." . explode("/", $_FILES['file_diagnosa']['type']["member_" .$member_id][$key])[1]; $ekstension = "." . explode("/", $_FILES['file_diagnosa']['type']["member_" .$member_id][$key])[1];
$pathFile = $folder . $new_file_name . $ekstension; $pathFile = $folder . $new_file_name . $ekstension;
@@ -170,7 +178,6 @@ class ClaimRequestController extends Controller
if (isset($_FILES['file_kondisi'])) { if (isset($_FILES['file_kondisi'])) {
foreach ($_FILES['file_kondisi']['error']["member_" .$member_id] as $key => $value) { foreach ($_FILES['file_kondisi']['error']["member_" .$member_id] as $key => $value) {
if ($value == 0) { if ($value == 0) {
$folder = "claim/";
$new_file_name = "claim-kondisi-" . time() . "-" . uniqid(); $new_file_name = "claim-kondisi-" . time() . "-" . uniqid();
$ekstension = "." . explode("/", $_FILES['file_kondisi']['type']["member_" .$member_id][$key])[1]; $ekstension = "." . explode("/", $_FILES['file_kondisi']['type']["member_" .$member_id][$key])[1];
$pathFile = $folder . $new_file_name . $ekstension; $pathFile = $folder . $new_file_name . $ekstension;

View File

@@ -218,15 +218,15 @@ const DialogDetailClaim = ({ title, openDialog, setOpenDialog, data }: MuiDialog
formData.append(`service_code[${index}]`, claim.typePatient); formData.append(`service_code[${index}]`, claim.typePatient);
claim.laboratoryResult.forEach((file, fileIndex) => { claim.laboratoryResult.forEach((file, fileIndex) => {
formData.append(`laboratorium[${index}][${fileIndex}]`, file); formData.append(`laboratorium[member_${claim.id}][${fileIndex}]`, file);
}); });
claim.anotherDocument.forEach((file, fileIndex) => { claim.anotherDocument.forEach((file, fileIndex) => {
formData.append(`prescription[${index}][${fileIndex}]`, file); formData.append(`prescription[member_${claim.id}][${fileIndex}]`, file);
}); });
claim.fileRealInvoice.forEach((file, fileIndex) => { claim.fileRealInvoice.forEach((file, fileIndex) => {
formData.append(`invoice[${index}][${fileIndex}]`, file); formData.append(`invoice[member_${claim.id}][${fileIndex}]`, file);
}); });
}); });