From 78e3211bdd3dbeb5ad17ed1545875b91a3467142 Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Sun, 10 Sep 2023 07:11:10 +0700 Subject: [PATCH 1/5] update data --- .../Http/Controllers/Api/LivechatController.php | 12 +++++++----- Modules/Internal/Transformers/LivechatResource.php | 11 +++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Modules/Internal/Http/Controllers/Api/LivechatController.php b/Modules/Internal/Http/Controllers/Api/LivechatController.php index 2fb42f3f..e8ef1620 100644 --- a/Modules/Internal/Http/Controllers/Api/LivechatController.php +++ b/Modules/Internal/Http/Controllers/Api/LivechatController.php @@ -26,9 +26,9 @@ class LivechatController extends Controller $startDate = $request->startDate; $endDate = $request->endDate; - $livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare') - ->where('nIDAppointment', '!=', null) - ->where('nIDAppointment', '!=', ''); + $livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare'); + // ->where('nIDAppointment', '!=', null) + // ->where('nIDAppointment', '!=', ''); if ($startDate) { @@ -74,6 +74,7 @@ class LivechatController extends Controller $query->where('dCreateOn', '<=', $endDate); } }) + ->orderBy('nID', 'desc') ->get(['nID', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia', 'dCreateOn']); $headers = [ @@ -116,7 +117,8 @@ class LivechatController extends Controller $phone = $liveChat->user->sPhone ?? '-'; $status = $liveChat->sStatus; $nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent - $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'Belum ada Pembayaran'; + $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A'; + $fullNameDoctor = $liveChat->doctor->user->full_name ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; $recordType = 'P'; if ($nIDUser){ $recordType = 'D'; @@ -147,7 +149,7 @@ class LivechatController extends Controller $sheet->setCellValue('D' . $startFrom, Carbon::parse($liveChat->dCreateOn)->format('H:m:i')); // $sheet->setCellValue('D' . $startFrom, Carbon::parse($liveChat->dRequestTime)->format('H:i:s')); $sheet->setCellValue('E' . $startFrom, $liveChat->healthCare->sHealthCare ?? '-'); - $sheet->setCellValue('F' . $startFrom, $liveChat->doctor->user->full_name ?? '-'); + $sheet->setCellValue('F' . $startFrom, $fullNameDoctor); $sheet->setCellValue('G' . $startFrom, $liveChat->doctor->speciality->sSpesialis ?? '-'); $sheet->setCellValue('H' . $startFrom, $liveChat->sMedia ?? '-'); $sheet->setCellValue('I' . $startFrom, $liveChat->sMediaDokter ?? '-'); diff --git a/Modules/Internal/Transformers/LivechatResource.php b/Modules/Internal/Transformers/LivechatResource.php index f8977412..013e5729 100644 --- a/Modules/Internal/Transformers/LivechatResource.php +++ b/Modules/Internal/Transformers/LivechatResource.php @@ -18,14 +18,16 @@ class LivechatResource extends JsonResource { $livechat = [ 'id' => $this->nID, - 'doctor_name' => isset($this->doctor->user->sFirstName) ? $this->doctor->user->sFirstName . ' ' . $this->doctor->user->sLastName : null, + 'doctor_name' => isset($this->doctor->user->sFirstName) ? $this->doctor->user->detail->sTitlePrefix . ' ' . $this->doctor->user->sFirstName . ' ' . $this->doctor->user->sLastName . ' ' . $this->doctor->user->detail->sTitleSuffix : null, 'pasien_name' => isset($this->user->sFirstName) ? $this->user->sFirstName . ' ' . $this->user->sLastName : null, 'pasien_phone' => isset($this->user->sPhone) ? $this->user->sPhone : '-', 'pasien_email' => isset($this->user->sEmail) ? $this->user->sEmail : '-', 'speciality' => $this->doctor->speciality->sKeterangan ?? null, 'health_care' => $this->healthCare->sHealthCare ?? null, - 'date_appointment' => Carbon::parse($this->appointment->appointmentDetail->dTanggalAppointment)->format('d-m-Y') - . ' ' . $this->appointment->appointmentDetail->tTimeAppointment ?? null, + 'date_appointment' => $this->appointment !== null ? + Carbon::parse($this->appointment->appointmentDetail->dTanggalAppointment)->format('d-m-Y') + . ' ' . $this->appointment->appointmentDetail->tTimeAppointment : + null, 'status_appointment' => $this->appointment->paymentStatus ?? null, 'date_created' => Carbon::parse($this->dRequestTime)->format('d-m-Y') ?? null, 'time_request' => Carbon::parse($this->dRequestTime)->format('H:i:s') ?? null, @@ -51,7 +53,8 @@ class LivechatResource extends JsonResource $livechat['duration'] = $data_duration; $payment_detail = null; - if ($this->appointment->appointmentDetail->sPaymentDetails != null) { + + if ($this->appointment !== null && $this->appointment->appointmentDetail->sPaymentDetails !== null) { $payment_detail = [ 'payment_type' => $this->appointment->appointmentDetail->sPaymentDetails['payment_type'], 'transaction_time' => $this->appointment->appointmentDetail->sPaymentDetails['transaction_time'], From 115dfbda4deac2e29ad5c407cf76347a3383a327 Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Sun, 10 Sep 2023 07:14:02 +0700 Subject: [PATCH 2/5] update --- Modules/Internal/Http/Controllers/Api/LivechatController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Internal/Http/Controllers/Api/LivechatController.php b/Modules/Internal/Http/Controllers/Api/LivechatController.php index e8ef1620..c8074d8e 100644 --- a/Modules/Internal/Http/Controllers/Api/LivechatController.php +++ b/Modules/Internal/Http/Controllers/Api/LivechatController.php @@ -118,7 +118,7 @@ class LivechatController extends Controller $status = $liveChat->sStatus; $nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A'; - $fullNameDoctor = $liveChat->doctor->user->full_name ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; + $fullNameDoctor = $liveChat->doctor->user != null ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; $recordType = 'P'; if ($nIDUser){ $recordType = 'D'; From 03e33fb37570a3cbb114839798966f921ea7d9e1 Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Sun, 10 Sep 2023 07:15:11 +0700 Subject: [PATCH 3/5] update --- Modules/Internal/Http/Controllers/Api/LivechatController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Internal/Http/Controllers/Api/LivechatController.php b/Modules/Internal/Http/Controllers/Api/LivechatController.php index c8074d8e..55bd46aa 100644 --- a/Modules/Internal/Http/Controllers/Api/LivechatController.php +++ b/Modules/Internal/Http/Controllers/Api/LivechatController.php @@ -118,7 +118,7 @@ class LivechatController extends Controller $status = $liveChat->sStatus; $nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A'; - $fullNameDoctor = $liveChat->doctor->user != null ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; + $fullNameDoctor = $liveChat->doctor != null ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; $recordType = 'P'; if ($nIDUser){ $recordType = 'D'; From afda88cea79f2a9d8bb603d50c0c7fe605b69f09 Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Sun, 10 Sep 2023 07:16:12 +0700 Subject: [PATCH 4/5] update --- Modules/Internal/Http/Controllers/Api/LivechatController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Internal/Http/Controllers/Api/LivechatController.php b/Modules/Internal/Http/Controllers/Api/LivechatController.php index 55bd46aa..c8074d8e 100644 --- a/Modules/Internal/Http/Controllers/Api/LivechatController.php +++ b/Modules/Internal/Http/Controllers/Api/LivechatController.php @@ -118,7 +118,7 @@ class LivechatController extends Controller $status = $liveChat->sStatus; $nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A'; - $fullNameDoctor = $liveChat->doctor != null ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; + $fullNameDoctor = $liveChat->doctor->user != null ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; $recordType = 'P'; if ($nIDUser){ $recordType = 'D'; From 45d52ed655f398daf2a1e76f23341e25410b7610 Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Sun, 10 Sep 2023 07:19:50 +0700 Subject: [PATCH 5/5] update fix --- .../Controllers/Api/LivechatController.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Modules/Internal/Http/Controllers/Api/LivechatController.php b/Modules/Internal/Http/Controllers/Api/LivechatController.php index c8074d8e..6c78e9fb 100644 --- a/Modules/Internal/Http/Controllers/Api/LivechatController.php +++ b/Modules/Internal/Http/Controllers/Api/LivechatController.php @@ -118,7 +118,25 @@ class LivechatController extends Controller $status = $liveChat->sStatus; $nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent $paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A'; - $fullNameDoctor = $liveChat->doctor->user != null ? $liveChat->doctor->user->detail->sTitlePrefix . ' ' . $liveChat->doctor->user->full_name . ' ' . $liveChat->doctor->user->detail->sTitleSuffix : '-' ; + $fullNameDoctor = '-'; + if ($liveChat->doctor->user !== null) { + $fullNameDoctor = ''; + + if ($liveChat->doctor->user->detail !== null) { + if ($liveChat->doctor->user->detail->sTitlePrefix !== null) { + $fullNameDoctor .= $liveChat->doctor->user->detail->sTitlePrefix . ' '; + } + + if ($liveChat->doctor->user->full_name !== null) { + $fullNameDoctor .= $liveChat->doctor->user->full_name . ' '; + } + + if ($liveChat->doctor->user->detail->sTitleSuffix !== null) { + $fullNameDoctor .= $liveChat->doctor->user->detail->sTitleSuffix; + } + } + } + $recordType = 'P'; if ($nIDUser){ $recordType = 'D';