Update Status Livechat

This commit is contained in:
ivan-sim
2025-09-25 14:16:07 +07:00
parent 04752ffcd7
commit d547b6d374
3 changed files with 137 additions and 111 deletions

View File

@@ -74,11 +74,11 @@ class LivechatController extends Controller
return $this->exportMonthly($startDate, $endDate);
} else {
$liveChats = Livechat::with('userInsurance',
'user:nID,sFirstName,sLastName,sEmail,sPhone,nIDUser,nIDHubunganKeluarga', 'user.detail:dTanggalLahir,nIDJenisKelamin',
'user:nID,sFirstName,sLastName,sEmail,sPhone,nIDUser,nIDHubunganKeluarga', 'user.detail:dTanggalLahir,nIDJenisKelamin',
'doctor:nID,nIDSpesialis,nIDUser', 'doctor.user:nID,sFirstName,sLastName',
'appointment:nID,sPaymentStatus,sPaymentMethod',
'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment',
'healthCare:nID,sHealthCare',
'appointment:nID,sPaymentStatus,sPaymentMethod',
'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment',
'healthCare:nID,sHealthCare',
'prescription',
'rujukan'
)
@@ -99,7 +99,7 @@ class LivechatController extends Controller
})
->orderBy('nID', 'desc')
->get(['nID', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia', 'dCreateOn', 'sNoSpj', 'dRequestTime', 'dAcceptTime', 'dStartTime', 'dEndTime']);
$headers = [
['value' => 'No', 'cell' => 'A1', 'mergeCell' => true, 'mergeToCell' => 'A2'],
['value' => 'Kode TC', 'cell' => 'B1', 'mergeCell' => true, 'mergeToCell' => 'B2'],
@@ -137,31 +137,31 @@ class LivechatController extends Controller
['value' => 'Subjek', 'cell' => 'AG1', 'mergeCell' => true, 'mergeToCell' => 'AG2'],
['value' => 'No SJP', 'cell' => 'AH1', 'mergeCell' => true, 'mergeToCell' => 'AH2'],
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
foreach ($headers as $header) {
$sheet->setCellValue($header['cell'], $header['value']);
if ($header['mergeCell'] === true) {
$sheet->mergeCells($header['cell'] . ':' . $header['mergeToCell']);
}
$sheet->getStyle($header['cell'])->getFont()->setBold(true);
$sheet->getStyle($header['cell'])->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet->setCellValue($header['cell'], $header['value']);
if ($header['mergeCell'] === true) {
$sheet->mergeCells($header['cell'] . ':' . $header['mergeToCell']);
}
$sheet->getStyle($header['cell'])->getFont()->setBold(true);
$sheet->getStyle($header['cell'])->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
}
$startFrom = 3;
foreach ($liveChats as $indexLiveChat => $liveChat) {
if ( $liveChat->user->nID == 109370 || $liveChat->nIDDokter == 100120) {
@@ -176,51 +176,56 @@ class LivechatController extends Controller
$fullNameDoctor = '-';
if (!empty($liveChat->doctor->user)) {
$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';
}
switch ($status) {
case 0:
$statusLivechat = "Request TC";
$statusLivechat = "Canceled by Doctor";
break;
case 1:
$statusLivechat = "Accepted by Doctor but User not Payment";
$statusLivechat = "Ended chat by patient";
break;
case 2:
$statusLivechat = "Payment Success";
$statusLivechat = "Resolved";
break;
case 3:
$statusLivechat = "Decline by Doctor";
$statusLivechat = "Canceled by Doctor";
break;
case 4:
$statusLivechat = "Payment Expired";
$statusLivechat = "Resolved";
case 5:
$statusLivechat = "Ended chat by patient";
break;
case 6:
$statusLivechat = "Canceled by system";
break;
default:
$statusLivechat = "Cancel by Patient";
$statusLivechat = "Ended chat by patient";
}
$requestTime = Carbon::parse($liveChat->dRequestTime);
$acceptTime = Carbon::parse($liveChat->dAcceptTime);
$startTime = Carbon::parse($liveChat->dStartTime);
$endTime = Carbon::parse($liveChat->dEndTime);
// Hitung selisih waktu response
if ($requestTime && $acceptTime) {
$diff = $requestTime->diff($acceptTime);
@@ -228,7 +233,7 @@ class LivechatController extends Controller
} else {
$responseTimeDiff = '00:00:00'; // Default jika data kosong
}
// Hitung selisih waktu chat
if ($startTime && $endTime) {
$diffChatTime = $startTime->diff($endTime);
@@ -236,17 +241,17 @@ class LivechatController extends Controller
} else {
$chatTimeDiff = '00:00:00'; // Default jika data kosong
}
// Set nilai responseTime dan chatTime
$responseTime = $responseTimeDiff;
$chatTime = $chatTimeDiff;
// $diagnosa = '-';
// $diagnosaCode = '-';
// if($liveChat->summary){
// $diagnosis = explode(', ', $liveChat->summary->sAssessment);
// if ($diagnosis) {
// $diagnosaArray = [];
// $diagnosaCodeArray = [];
@@ -254,7 +259,7 @@ class LivechatController extends Controller
// $diagnosaArray[] = Helper::diagnosisName($data); // Tambahkan diagnosis ke array
// $diagnosaCodeArray[] = $data; // Tambahkan diagnosis ke array
// }
// $diagnosa = implode('; ', $diagnosaArray); // Gabungkan array dengan tanda koma
// $diagnosaCode = implode('; ', $diagnosaCodeArray); // Gabungkan array dengan tanda koma
// }
@@ -268,22 +273,22 @@ class LivechatController extends Controller
$diagnosa = implode('; ', $diagnosaArray);
$diagnosaCode = implode('; ', $diagnosisCodes);
}
$tebusResep = 'Belum Ditebus';
$paymentTebus = '-';
if ($liveChat->prescription){
// Tanggal target (misalnya, dari database atau input)
$tanggalResep = Carbon::parse($liveChat->prescription->dTanggalResep);
// Tanggal hari ini
$tanggalNow = Carbon::now();
// Menghitung selisih hari
$selisihHari = $tanggalNow->diffInDays($tanggalResep);
if ($selisihHari > 1){
$tebusResep = 'Resep Kadaluarsa';
}
if ($liveChat->prescription->sIsDownload == 1){
$tebusResep = 'Offline';
}
@@ -296,9 +301,9 @@ class LivechatController extends Controller
} else {
$tebusResep = '-';
}
// switc
$nIDHubunganKeluarga = match($user->nIDHubunganKeluarga) {
9 => "Peserta",
4 => "Istri",
@@ -306,11 +311,11 @@ class LivechatController extends Controller
3 => "Suami",
default => $user->relation->sHubunganKeluarga ?? '-'
};
if ($liveChat->user->relation && $nIDHubunganKeluarga == '-'){
$nIDHubunganKeluarga = $liveChat->user->relation->sHubunganKeluarga;
}
$obat = '-';
if($liveChat->prescription){
if ($liveChat->prescription->items){
@@ -318,12 +323,12 @@ class LivechatController extends Controller
foreach($liveChat->prescription->items as $data){
$obatArray[] = $data->sItemName .' - '. $data->nQty;
}
$obat = implode('; ',$obatArray);
}
};
$sheet->setCellValue('A' . $startFrom, $indexLiveChat + 1);
$sheet->setCellValue('B' . $startFrom, $liveChat->nID ?? '-');
$sheet->setCellValue('C' . $startFrom, Carbon::parse($liveChat->dCreateOn)->format('d-m-Y'));
@@ -351,15 +356,15 @@ class LivechatController extends Controller
$sheet->setCellValue('U' . $startFrom, $acceptTime);
$sheet->setCellValue('V' . $startFrom, $startTime);
$sheet->setCellValue('W' . $startFrom, $endTime);
$sheet->setCellValue('X' . $startFrom, $diagnosaCode ?? '-');
$sheet->setCellValue('Y' . $startFrom, $diagnosa ?? '-');
$sheet->setCellValue('Z' . $startFrom, $liveChat->prescription->sKodeResep ?? '-');
$sheet->setCellValue('AA' . $startFrom, $liveChat->prescription->dCreateOn ?? '-');
$sheet->setCellValue('AB' . $startFrom, $obat);
$sheet->setCellValue('AC' . $startFrom, $tebusResep);
$sheet->setCellValue('AD' . $startFrom, $paymentTebus);
$sheet->setCellValue('AE' . $startFrom, $liveChat->rujukan->nIDHealthcare ?? '-');
$sheet->setCellValue('AF' . $startFrom, $liveChat->rujukan->sDepartement ?? '-');
@@ -367,7 +372,7 @@ class LivechatController extends Controller
$sheet->setCellValue('AH' . $startFrom, $liveChat->sNoSpj ?? '-');
$startFrom++;
}
foreach (['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K', 'L', 'M', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AF', 'AH'] as $header) {
if ($header === 'A') {
$spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(35, 'px');
@@ -377,38 +382,38 @@ class LivechatController extends Controller
$spreadsheet->getActiveSheet()->getColumnDimension($header)->setAutoSize(true);
}
}
$spreadsheet->getActiveSheet()->getStyle('A2:A' . $startFrom)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet->getDefaultRowDimension()->setRowHeight(-1);
$sheet->setTitle('Live Chat Report');
$writer = new Xlsx($spreadsheet);
ob_start();
$writer->save('php://output');
$content = ob_get_contents();
ob_end_clean();
$fileName = 'result-' . now()->getPreciseTimestamp(3) . '-livechat-report.xlsx';
Storage::disk('public')->put('temp/' . $fileName, $content);
$fileUrl = url('storage/temp/' . $fileName);
return Helper::responseJson([
"file_url" => $fileUrl
]);
}
}
public function exportMonthly($startDate, $endDate)
{
$liveChats = Livechat::with('userInsurance',
'user:nID,sFirstName,sLastName,sEmail,sPhone,nIDUser,nIDHubunganKeluarga',
'user:nID,sFirstName,sLastName,sEmail,sPhone,nIDUser,nIDHubunganKeluarga',
'doctor:nID,nIDSpesialis,nIDUser', 'doctor.user:nID,sFirstName,sLastName',
'appointment:nID,sPaymentStatus,sPaymentMethod',
'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment',
'healthCare:nID,sHealthCare',
'appointment:nID,sPaymentStatus,sPaymentMethod',
'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment',
'healthCare:nID,sHealthCare',
'prescription',
'rujukan'
)
@@ -480,7 +485,7 @@ class LivechatController extends Controller
$sheet->getStyle($header['cell'])->getFont()->setBold(true);
$sheet->getStyle($header['cell'])->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet2->setCellValue($header['cell'], $header['value']);
$sheet2->getStyle($header['cell'])->getFont()->setBold(true);
@@ -527,22 +532,27 @@ class LivechatController extends Controller
}
switch ($status) {
case 0:
$statusLivechat = "Request TC";
$statusLivechat = "Canceled by Doctor";
break;
case 1:
$statusLivechat = "Accepted by Doctor but User not Payment";
$statusLivechat = "Ended chat by patient";
break;
case 2:
$statusLivechat = "Payment Success";
$statusLivechat = "Resolved";
break;
case 3:
$statusLivechat = "Decline by Doctor";
$statusLivechat = "Canceled by Doctor";
break;
case 4:
$statusLivechat = "Payment Expired";
$statusLivechat = "Resolved";
case 5:
$statusLivechat = "Ended chat by patient";
break;
case 6:
$statusLivechat = "Canceled by system";
break;
default:
$statusLivechat = "Cancel by Patient";
$statusLivechat = "Ended chat by patient";
}
$requestTime = Carbon::parse($liveChat->dRequestTime);
@@ -575,7 +585,7 @@ class LivechatController extends Controller
// $diagnosaCode = '-';
// if($liveChat->summary){
// $diagnosis = explode(', ', $liveChat->summary->sAssessment);
// if ($diagnosis) {
// $diagnosaArray = [];
// $diagnosaCodeArray = [];
@@ -583,7 +593,7 @@ class LivechatController extends Controller
// $diagnosaArray[] = Helper::diagnosisName($data); // Tambahkan diagnosis ke array
// $diagnosaCodeArray[] = $data; // Tambahkan diagnosis ke array
// }
// $diagnosa = implode('; ', $diagnosaArray); // Gabungkan array dengan tanda koma
// $diagnosaCode = implode('; ', $diagnosaCodeArray); // Gabungkan array dengan tanda koma
// }
@@ -637,7 +647,7 @@ class LivechatController extends Controller
}
};
if ($liveChat->prescription->items){
$obatArray = [];
$obatQtyArray = [];
@@ -665,8 +675,8 @@ class LivechatController extends Controller
if ($liveChat->user->relation && $nIDHubunganKeluarga == '-'){
$nIDHubunganKeluarga = $liveChat->user->relation->sHubunganKeluarga;
}
$sheet->setCellValue('A' . $startFromSheet1, $liveChat->nID ?? '-');
$sheet->setCellValue('B' . $startFromSheet1, $liveChat->sNoSpj ?? '-');
@@ -730,52 +740,57 @@ class LivechatController extends Controller
$fullNameDoctor = '-';
if (!empty($liveChat->doctor->user)) {
$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';
}
switch ($status) {
case 0:
$statusLivechat = "Request TC";
$statusLivechat = "Canceled by Doctor";
break;
case 1:
$statusLivechat = "Accepted by Doctor but User not Payment";
$statusLivechat = "Ended chat by patient";
break;
case 2:
$statusLivechat = "Payment Success";
$statusLivechat = "Resolved";
break;
case 3:
$statusLivechat = "Decline by Doctor";
$statusLivechat = "Canceled by Doctor";
break;
case 4:
$statusLivechat = "Payment Expired";
$statusLivechat = "Resolved";
case 5:
$statusLivechat = "Ended chat by patient";
break;
case 6:
$statusLivechat = "Canceled by system";
break;
default:
$statusLivechat = "Cancel by Patient";
$statusLivechat = "Ended chat by patient";
}
$requestTime = Carbon::parse($liveChat->dRequestTime);
$acceptTime = Carbon::parse($liveChat->dAcceptTime);
$startTime = Carbon::parse($liveChat->dStartTime);
$endTime = Carbon::parse($liveChat->dEndTime);
// Hitung selisih waktu response
if ($requestTime && $acceptTime) {
$diff = $requestTime->diff($acceptTime);
@@ -783,7 +798,7 @@ class LivechatController extends Controller
} else {
$responseTimeDiff = '00:00:00'; // Default jika data kosong
}
// Hitung selisih waktu chat
if ($startTime && $endTime) {
$diffChatTime = $startTime->diff($endTime);
@@ -791,18 +806,18 @@ class LivechatController extends Controller
} else {
$chatTimeDiff = '00:00:00'; // Default jika data kosong
}
// Set nilai responseTime dan chatTime
$responseTime = $responseTimeDiff;
$chatTime = $chatTimeDiff;
// $diagnosa = '-';
// $diagnosaCode = '-';
// if($liveChat->summary){
// $diagnosis = explode(', ', $liveChat->summary->sAssessment);
// if ($diagnosis) {
// $diagnosaArray = [];
// $diagnosaCodeArray = [];
@@ -810,7 +825,7 @@ class LivechatController extends Controller
// $diagnosaArray[] = Helper::diagnosisName($dataDiagnosa); // Tambahkan diagnosis ke array
// $diagnosaCodeArray[] = $dataDiagnosa; // Tambahkan diagnosis ke array
// }
// $diagnosa = implode('; ', $diagnosaArray); // Gabungkan array dengan tanda koma
// $diagnosaCode = implode('; ', $diagnosaCodeArray); // Gabungkan array dengan tanda koma
// }
@@ -824,14 +839,14 @@ class LivechatController extends Controller
$diagnosa = implode('; ', $diagnosaArray);
$diagnosaCode = implode('; ', $diagnosisCodes);
}
$tebusResep = 'Belum Ditebus';
$paymentTebus = '-';
if ($liveChat->prescription){
// Tanggal target (misalnya, dari database atau input)
$tanggalResep = Carbon::parse($liveChat->prescription->dTanggalResep);
// Tanggal hari ini
$tanggalNow = Carbon::now();
@@ -840,7 +855,7 @@ class LivechatController extends Controller
if ($selisihHari > 1){
$tebusResep = 'Resep Kadaluarsa';
}
if ($liveChat->prescription->sIsDownload == 1){
$tebusResep = 'Offline';
}
@@ -853,7 +868,7 @@ class LivechatController extends Controller
// $apotek = '-';
// }
$apotek = $apotekList[$liveChat->prescription->payment->nIDApotek] ?? '-';
if ($liveChat->prescription->payment->sPaymentStatus == 'paid'){
$paymentTebus = Carbon::parse($liveChat->prescription->payment->dCreateOn)->format('d-m-Y H:i:s');
}
@@ -861,7 +876,7 @@ class LivechatController extends Controller
} else {
$tebusResep = '-';
}
// switch ($liveChat->user->nIDHubunganKeluarga) {
// case 9:
// $nIDHubunganKeluarga = "Peserta"; // Parent
@@ -887,7 +902,7 @@ class LivechatController extends Controller
3 => "Suami",
default => $user->relation->sHubunganKeluarga ?? '-'
};
if ($liveChat->user->relation && $nIDHubunganKeluarga == '-'){
$nIDHubunganKeluarga = $liveChat->user->relation->sHubunganKeluarga;
}
@@ -925,10 +940,10 @@ class LivechatController extends Controller
$sheet2->setCellValue('X' . $startFromSheet2, $liveChat->rujukan ? 'Ya' : 'Tidak');
$sheet2->setCellValue('Y' . $startFromSheet2, $liveChat->rujukan->nIDHealthcare ?? '-' );
$sheet2->setCellValue('Z' . $startFromSheet2, $liveChat->rujukan->sDepartement ?? '-' );
$sheet2->setCellValue('AA' . $startFromSheet2, '-');
$sheet2->setCellValue('AB' . $startFromSheet2, $tebusResep);
$sheet2->setCellValue('AC' . $startFromSheet2, $apotek );
$sheet2->setCellValue('AD' . $startFromSheet2, $obat);
$sheet2->setCellValue('AE' . $startFromSheet2, $obatQty);
@@ -936,7 +951,7 @@ class LivechatController extends Controller
// $sheet->setCellValue('AC' . $startFromSheet2, $liveChat->prescription->dCreateOn ?? '-');
// $sheet->setCellValue('AD' . $startFromSheet2, $obat);
// $sheet->setCellValue('AE' . $startFromSheet2, $tebusResep);
// $sheet->setCellValue('AF' . $startFromSheet2, $paymentTebus);
// $sheet->setCellValue('AG' . $startFromSheet2, $liveChat->rujukan->nIDHealthcare ?? '-');
// $sheet->setCellValue('AH' . $startFromSheet2, $liveChat->rujukan->sDepartement ?? '-');

View File

@@ -19,13 +19,23 @@ class Livechat extends Model
// 4 => 'Expired',
// ];
// public $sStatusNames = [
// 0 => 'Request TC',
// 1 => 'Accepted by Doctor but User not Payment',
// 3 => 'Decline by Doctor',
// 2 => 'Payment Success',
// 4 => 'Payment Expired',
// 5 => 'Cancel by Patient'
// ];
public $sStatusNames = [
0 => 'Request TC',
1 => 'Accepted by Doctor but User not Payment',
3 => 'Decline by Doctor',
2 => 'Payment Success',
4 => 'Payment Expired',
5 => 'Cancel by Patient'
0 => 'Canceled by Doctor',
1 => 'Ended chat by patient',
2 => 'Resolved',
3 => 'Canceled by Doctor',
4 => 'Resolved',
5 => 'Ended chat by patient',
6 => 'Canceled by system'
];
const CREATED_AT = 'dCreateOn';

View File

@@ -20,12 +20,13 @@ class LivechatSummary extends Model
// ];
public $sStatusNames = [
0 => 'Request TC',
1 => 'Accepted by Doctor but User not Payment',
3 => 'Decline by Doctor',
2 => 'Payment Success',
4 => 'Payment Expired',
5 => 'Cancel by Patient'
0 => 'Canceled by Doctor',
1 => 'Ended chat by patient',
2 => 'Resolved',
3 => 'Canceled by Doctor',
4 => 'Resolved',
5 => 'Ended chat by patient',
6 => 'Canceled by system'
];
const CREATED_AT = 'dCreateOn';