From 439daf4e2e779c7ce037f721ee72fdb6cac67bc3 Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Tue, 16 Jan 2024 10:33:07 +0700 Subject: [PATCH] Update import request log --- .../Internal/Services/RequestLogService.php | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/Modules/Internal/Services/RequestLogService.php b/Modules/Internal/Services/RequestLogService.php index 2455e2ad..fd1272d6 100644 --- a/Modules/Internal/Services/RequestLogService.php +++ b/Modules/Internal/Services/RequestLogService.php @@ -187,39 +187,66 @@ class RequestLogService $final_log = 1; } + if ($row['catatan']){ + $data = [ + 'code' => $code, + 'member_id' => $member->id, + 'submission_date' => $row['submission_date'], + 'discharge_date' => $row['submission_date'], + 'payment_type' => 'cashless', + 'status' => $status, + 'status_final_log' => $statusFinalLog, + 'final_log' =>$final_log, + 'import_system' =>TRUE, + // 'catatan' => $row['catatan'], + 'keterangan' => $row['keterangan'], + 'policy_id' => $member->currentPolicy->id ?? null, + 'organization_id' => $organization_id, + 'diagnosis' => $row['catatan'], + 'service_code' => $serviceCode, + 'approved_final_log_at' => $row['approved_final_log_at'], + ]; + } else { + $data = [ + 'code' => $code, + 'member_id' => $member->id, + 'submission_date' => $row['submission_date'], + 'discharge_date' => $row['submission_date'], + 'payment_type' => 'cashless', + 'status' => $status, + 'status_final_log' => $statusFinalLog, + 'final_log' =>$final_log, + 'import_system' =>TRUE, + // 'catatan' => $row['catatan'], + 'keterangan' => $row['keterangan'], + 'policy_id' => $member->currentPolicy->id ?? null, + 'organization_id' => $organization_id, + 'service_code' => $serviceCode, + 'approved_final_log_at' => $row['approved_final_log_at'], + ]; + } + $requestLog = RequestLog::updateOrCreate( - [ - 'code' => $code - ], [ 'code' => $code, - 'member_id' => $member->id, - 'submission_date' => $row['submission_date'], - 'discharge_date' => $row['submission_date'], - 'payment_type' => 'cashless', - 'status' => $status, - 'status_final_log' => $statusFinalLog, - 'final_log' =>$final_log, - 'import_system' =>TRUE, - 'catatan' => $row['catatan'], - 'policy_id' => $member->currentPolicy->id ?? null, - 'organization_id' => $organization_id, - 'service_code' => $serviceCode, - 'approved_final_log_at' => $row['approved_final_log_at'], - ]); + ], + $data); if ($benefit) { // jika tidak ada benefit nya maka belum ngisi benefit nya - RequestLogBenefit::updateOrCreate( - [ - 'request_log_id' => $requestLog->id, - ], + // Delete item + if ($row['total_billing']){ + RequestLogBenefit::where('request_log_id', '=', $requestLog->id)->delete(); + } + + // Insert Item + RequestLogBenefit::create( [ 'request_log_id' => $requestLog->id, 'benefit_id' => $benefit->id, - 'amount_incurred' => $row['total_billing'], + 'amount_incurred' => ($row['amount_not_approval'] ? $row['amount_not_approval'] : 0) + $row['amount_approval'] , 'amount_approved' => $row['amount_approval'], - 'amount_not_approved' => $row['amount_not_approval'], + 'amount_not_approved' => $row['amount_not_approval'] ?? 0, 'excess_paid' => $row['amount_not_approval'], 'created_by' => auth()->user()->id,