Files
aso/Modules/Internal/Http/Controllers/Api/LivechatController.php

989 lines
51 KiB
PHP
Executable File

<?php
namespace Modules\Internal\Http\Controllers\Api;
use App\Helpers\Helper;
use App\Models\OLDLMS\Livechat;
use App\Models\OLDLMS\Appointment;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Modules\Internal\Transformers\LivechatResource;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class LivechatController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index(Request $request)
{
$startDate = $request->startDate;
$endDate = $request->endDate;
$livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare');
// ->where('nIDAppointment', '!=', null)
// ->where('nIDAppointment', '!=', '');
if ($startDate) {
$livechat = $livechat->where('dCreateOn', '>=', $startDate);
}
if ($endDate) {
$endDate = date('Y-m-d', strtotime($endDate . ' +1 day'));
$livechat = $livechat->where('dCreateOn', '<', $endDate);
}
$livechat = $livechat->latest()->paginate(15);
return response()->json(Helper::paginateResources(LivechatResource::collection($livechat)));
}
/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
$livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare')
->where('nIDAppointment', '!=', null)->where('nIDAppointment', '!=', '')
->where('nID', $id)
->first();
return response()->json(new LivechatResource($livechat));
}
public function export(Request $request)
{
$startDate = $request->has('startDate') ? $request->input('startDate') : '';
$endDate = $request->has('endDate') ? $request->input('endDate') : '';
$liveChats = Livechat::with('userInsurance',
'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',
'prescription',
'rujukan'
)
->whereHas('userInsurance', function (Builder $query) {
// Kondisi pada relasi userInsurance
$query->where('nIDInsurance', 107); // khusus inhealth
})
->where(function (Builder $query) use ($startDate, $endDate) {
// $query->where('nIDAppointment', '!=', null);
// $query->where('nIDAppointment', '!=', '');
if ($startDate) {
$query->where('dCreateOn', '>=', $startDate);
}
if ($endDate) {
$endDate = date('Y-m-d', strtotime($endDate . ' +1 day'));
$query->where('dCreateOn', '<', $endDate);
}
})
->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'],
['value' => 'Tanggal', 'cell' => 'C1', 'mergeCell' => true, 'mergeToCell' => 'C2'],
['value' => 'Waktu', 'cell' => 'D1', 'mergeCell' => true, 'mergeToCell' => 'D2'],
['value' => 'Faskes', 'cell' => 'E1', 'mergeCell' => true, 'mergeToCell' => 'E2'],
['value' => 'Nama Dokter', 'cell' => 'F1', 'mergeCell' => true, 'mergeToCell' => 'F2'],
['value' => 'Spesialis', 'cell' => 'G1', 'mergeCell' => true, 'mergeToCell' => 'G2'],
['value' => 'Chat Via App/Website', 'cell' => 'H1', 'mergeCell' => true, 'mergeToCell' => 'I1'],
['value' => 'Pasien', 'cell' => 'H2', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Dokter', 'cell' => 'I2', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'nIDUser', 'cell' => 'J1', 'mergeCell' => true, 'mergeToCell' => 'J2'],
['value' => 'Nama Pasien', 'cell' => 'K1', 'mergeCell' => true, 'mergeToCell' => 'K2'],
['value' => 'No Telepon Pasien', 'cell' => 'L1', 'mergeCell' => true, 'mergeToCell' => 'L2'],
['value' => 'Email Pasien', 'cell' => 'M1', 'mergeCell' => true, 'mergeToCell' => 'M2'],
['value' => 'No Kartu Insurance', 'cell' => 'N1', 'mergeCell' => true, 'mergeToCell' => 'N2'],
['value' => 'Corporate ID', 'cell' => 'O1', 'mergeCell' => true, 'mergeToCell' => 'O2'],
['value' => 'Corporate Name', 'cell' => 'P1', 'mergeCell' => true, 'mergeToCell' => 'P2'],
['value' => 'Hubungan Pasien', 'cell' => 'Q1', 'mergeCell' => true, 'mergeToCell' => 'Q2'],
['value' => 'Chanel', 'cell' => 'R1', 'mergeCell' => true, 'mergeToCell' => 'R2'],
['value' => 'Status', 'cell' => 'S1', 'mergeCell' => true, 'mergeToCell' => 'S2'],
['value' => 'Request Time', 'cell' => 'T1', 'mergeCell' => true, 'mergeToCell' => 'T2'],
['value' => 'Accept Time', 'cell' => 'U1', 'mergeCell' => true, 'mergeToCell' => 'U2'],
['value' => 'Start Time', 'cell' => 'V1', 'mergeCell' => true, 'mergeToCell' => 'V2'],
['value' => 'End Time', 'cell' => 'W1', 'mergeCell' => true, 'mergeToCell' => 'W2'],
['value' => 'Kode Diagnosa', 'cell' => 'X1', 'mergeCell' => true, 'mergeToCell' => 'X2'],
['value' => 'Diagnosa', 'cell' => 'Y1', 'mergeCell' => true, 'mergeToCell' => 'Y2'],
['value' => 'Kode Resep', 'cell' => 'Z1', 'mergeCell' => true, 'mergeToCell' => 'Z2'],
['value' => 'Tanggal Resep', 'cell' => 'AA1', 'mergeCell' => true, 'mergeToCell' => 'AA2'],
['value' => 'Obat', 'cell' => 'AB1', 'mergeCell' => true, 'mergeToCell' => 'AB2'],
['value' => 'Tebus Resep', 'cell' => 'AC1', 'mergeCell' => true, 'mergeToCell' => 'AC2'],
['value' => 'Tanggal Bayar', 'cell' => 'AD1', 'mergeCell' => true, 'mergeToCell' => 'AD2'],
['value' => 'Provider Rujukan', 'cell' => 'AE1', 'mergeCell' => true, 'mergeToCell' => 'AE2'],
['value' => 'Poli', 'cell' => 'AF1', 'mergeCell' => true, 'mergeToCell' => 'AF2'],
['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);
}
$startFrom = 3;
foreach ($liveChats as $indexLiveChat => $liveChat) {
$phone = $liveChat->user->sPhone ?? '-';
$status = $liveChat->sStatus;
$nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent
$paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A';
$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";
break;
case 1:
$statusLivechat = "Accepted by Doctor but User not Payment";
break;
case 2:
$statusLivechat = "Payment Success";
break;
case 3:
$statusLivechat = "Decline by Doctor";
break;
case 4:
$statusLivechat = "Payment Expired";
break;
default:
$statusLivechat = "Cancel 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);
$responseTimeDiff = sprintf('%02d:%02d:%02d', $diff->h, $diff->i, $diff->s);
} else {
$responseTimeDiff = '00:00:00'; // Default jika data kosong
}
// Hitung selisih waktu chat
if ($startTime && $endTime) {
$diffChatTime = $startTime->diff($endTime);
$chatTimeDiff = sprintf('%02d:%02d:%02d', $diffChatTime->h, $diffChatTime->i, $diffChatTime->s);
} 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 = [];
foreach($diagnosis as $data){
$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
}
}
$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';
}
if($liveChat->prescription->payment){
$tebusResep = 'Online';
if ($liveChat->prescription->payment->sPaymentStatus == 'paid'){
$paymentTebus = Carbon::parse($liveChat->prescription->payment->dCreateOn)->format('d-m-Y H:i:s');
}
};
} else {
$tebusResep = '-';
}
switch ($liveChat->user->nIDHubunganKeluarga) {
case 9:
$nIDHubunganKeluarga = "Peserta"; // Parent
break;
case 4:
$nIDHubunganKeluarga = 'Istri'; // Spouse
break;
case 5:
$nIDHubunganKeluarga = 'Anak'; // Child
break;
case 3:
$nIDHubunganKeluarga = 'Suami'; // Husband
break;
default:
$nIDHubunganKeluarga = '-'; // No need to set $nIDHubunganKeluarga as it's already set to default value
break;
}
if ($liveChat->user->relation && $nIDHubunganKeluarga == '-'){
$nIDHubunganKeluarga = $liveChat->user->relation->sHubunganKeluarga;
}
$obat = '-';
if($liveChat->prescription){
if ($liveChat->prescription->items){
$obatArray = [];
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'));
$sheet->setCellValue('D' . $startFrom, Carbon::parse($liveChat->dCreateOn)->format('H:i:s'));
// $sheet->setCellValue('D' . $startFrom, Carbon::parse($liveChat->dRequestTime)->format('H:i:s'));
$sheet->setCellValue('E' . $startFrom, $liveChat->healthCare->sHealthCare ?? '-');
$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 ?? '-');
$sheet->setCellValue('J' . $startFrom, $liveChat->user->nID ?? '-');
$sheet->setCellValue('K' . $startFrom, $liveChat->user->full_name ?? '-');
$sheet->setCellValue('L' . $startFrom, preg_replace('/(\d{3})(\d{4})(\d{3})/', '$1$2$3', $phone));
$sheet->setCellValue('M' . $startFrom, $liveChat->user->sEmail ?? '-');
$sheet->setCellValue('N' . $startFrom, (string)($liveChat->userInsurance->sNoPolis ?? '-'));
$sheet->setCellValue('O' . $startFrom, (string)($liveChat->userInsurance->sCorporateCode ?? '-'));
$sheet->setCellValue('P' . $startFrom, (string)($liveChat->userInsurance->sCorporateName ?? '-'));
$sheet->setCellValue('Q' . $startFrom, (string)($nIDHubunganKeluarga ?? '-'));
$sheet->setCellValue('R' . $startFrom, (string)($liveChat->userInsurance->sChannel ?? '-'));
$sheet->setCellValue('S' . $startFrom, $statusLivechat);
// $sheet->setCellValue('O' . $startFrom, $recordType);
// $sheet->setCellValue('P' . $startFrom, $nIDUser ?? '-');
// $sheet->setCellValue('Q' . $startFrom, $paymentMethod ?? '-');
$sheet->setCellValue('T' . $startFrom, $requestTime);
$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 ?? '-');
$sheet->setCellValue('AG' . $startFrom, $liveChat->summary->sSubjective ?? '-');
$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');
} elseif ($header === 'H' || $header === 'I') {
$spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(100, 'px');
} else {
$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(Request $request)
{
$startDate = $request->has('startDate') ? $request->input('startDate') : '';
$endDate = $request->has('endDate') ? $request->input('endDate') : '';
$liveChats = Livechat::with('userInsurance',
'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',
'prescription',
'rujukan'
)
->whereHas('userInsurance', function (Builder $query) {
// Kondisi pada relasi userInsurance
$query->where('nIDInsurance', 107); // khusus inhealth
})
->where(function (Builder $query) use ($startDate, $endDate) {
// $query->where('nIDAppointment', '!=', null);
// $query->where('nIDAppointment', '!=', '');
if ($startDate) {
$query->where('dCreateOn', '>=', $startDate);
}
if ($endDate) {
$endDate = date('Y-m-d', strtotime($endDate . ' +1 day'));
$query->where('dCreateOn', '<', $endDate);
}
})
->orderBy('nID', 'desc')
->get(['nID', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia', 'dCreateOn', 'sNoSpj', 'dRequestTime', 'dAcceptTime', 'dStartTime', 'dEndTime']);
$headers = [
['value' => 'ConsultationId', 'cell' => 'A1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'No SJP', 'cell' => 'B1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'PKSKD', 'cell' => 'C1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'PKSNM', 'cell' => 'D1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Card Number', 'cell' => 'E1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'NamaPasien', 'cell' => 'F1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'JenisKelamin', 'cell' => 'G1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'TanggalLahir', 'cell' => 'H1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Usia', 'cell' => 'I1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Produk', 'cell' => 'J1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Plan', 'cell' => 'K1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'DependencyStatus', 'cell' => 'L1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'TanggalKonsultasi', 'cell' => 'M1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Keluhan', 'cell' => 'N1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Kode Diagnosa', 'cell' => 'O1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Diagnosa', 'cell' => 'P1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'StartTime', 'cell' => 'Q1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'EndTime', 'cell' => 'R1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'DurasiKonsultasi', 'cell' => 'S1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'StatusKonsultasi', 'cell' => 'T1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'PrescriptionNumber', 'cell' => 'U1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'NamaDokter', 'cell' => 'V1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Jenis Dokter', 'cell' => 'W1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Rujuk (Ya/Tidak)', 'cell' => 'X1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Poli', 'cell' => 'Y1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Total', 'cell' => 'Z1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Obat', 'cell' => 'AA1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'By', 'cell' => 'AB1', 'mergeCell' => false, 'mergeToCell' => ''],
];
$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);
}
$startFrom = 2;
foreach ($liveChats as $indexLiveChat => $liveChat) {
$phone = $liveChat->user->sPhone ?? '-';
$status = $liveChat->sStatus;
$nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent
$paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A';
$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";
break;
case 1:
$statusLivechat = "Accepted by Doctor but User not Payment";
break;
case 2:
$statusLivechat = "Payment Success";
break;
case 3:
$statusLivechat = "Decline by Doctor";
break;
case 4:
$statusLivechat = "Payment Expired";
break;
default:
$statusLivechat = "Cancel 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);
$responseTimeDiff = sprintf('%02d:%02d:%02d', $diff->h, $diff->i, $diff->s);
} else {
$responseTimeDiff = '00:00:00'; // Default jika data kosong
}
// Hitung selisih waktu chat
if ($startTime && $endTime) {
$diffChatTime = $startTime->diff($endTime);
$chatTimeDiff = sprintf('%02d:%02d:%02d', $diffChatTime->h, $diffChatTime->i, $diffChatTime->s);
} 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 = [];
foreach($diagnosis as $data){
$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
}
}
$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';
}
if($liveChat->prescription->payment){
$tebusResep = 'Online';
if ($liveChat->prescription->payment->sPaymentStatus == 'paid'){
$paymentTebus = Carbon::parse($liveChat->prescription->payment->dCreateOn)->format('d-m-Y H:i:s');
}
};
} else {
$tebusResep = '-';
}
switch ($liveChat->user->nIDHubunganKeluarga) {
case 9:
$nIDHubunganKeluarga = "Peserta"; // Parent
break;
case 4:
$nIDHubunganKeluarga = 'Istri'; // Spouse
break;
case 5:
$nIDHubunganKeluarga = 'Anak'; // Child
break;
case 3:
$nIDHubunganKeluarga = 'Suami'; // Husband
break;
default:
$nIDHubunganKeluarga = '-'; // No need to set $nIDHubunganKeluarga as it's already set to default value
break;
}
if ($liveChat->user->relation && $nIDHubunganKeluarga == '-'){
$nIDHubunganKeluarga = $liveChat->user->relation->sHubunganKeluarga;
}
$obat = '-';
if($liveChat->prescription){
if ($liveChat->prescription->items){
$obatArray = [];
foreach($liveChat->prescription->items as $data){
$obatArray[] = $data->sItemName .' - '. $data->nQty;
}
$obat = implode('; ',$obatArray);
}
};
$sheet->setCellValue('A' . $startFrom, $liveChat->nID ?? '-');
$sheet->setCellValue('B' . $startFrom, $liveChat->sNoSpj ?? '-');
$sheet->setCellValue('C' . $startFrom, (string)($liveChat->userInsurance->sCorporateCode ?? '-'));
$sheet->setCellValue('D' . $startFrom, (string)($liveChat->userInsurance->sCorporateName ?? '-'));
$sheet->setCellValue('E' . $startFrom, (string)($liveChat->userInsurance->sNoPolis ?? '-'));
$sheet->setCellValue('F' . $startFrom, $liveChat->user->full_name ?? '-');
$sheet->setCellValue('G' . $startFrom, $liveChat->user->detail->dTanggalLahir ?? '-');
$sheet->setCellValue('H' . $startFrom, $liveChat->user->detail->nIDJenisKelamin == 1 ? 'Laki-laki' : 'Wanita');
$sheet->setCellValue('I' . $startFrom, Helper::calculateAge($liveChat->user->detail->dTanggalLahir) ?? '-');
$sheet->setCellValue('J' . $startFrom, (string)($liveChat->userInsurance->sProductCode ?? '-'));
$sheet->setCellValue('K' . $startFrom, (string)($liveChat->userInsurance->sPlanCode ?? '-'));
$sheet->setCellValue('L' . $startFrom, $nIDHubunganKeluarga ?? '-');
$sheet->setCellValue('M' . $startFrom, $requestTime->format('Y-m-d'));
$sheet->setCellValue('N' . $startFrom, $liveChat->summary->sSubjective ?? '-');
$sheet->setCellValue('O' . $startFrom, $diagnosaCode ?? '-');
$sheet->setCellValue('P' . $startFrom, $diagnosa ?? '-');
$sheet->setCellValue('Q' . $startFrom, $startTime->format('H:i:s'));
$sheet->setCellValue('R' . $startFrom, $endTime->format('H:i:s'));
$sheet->setCellValue('S' . $startFrom, $chatTime);
// $sheet->setCellValue('O' . $startFrom, $recordType);
// $sheet->setCellValue('P' . $startFrom, $nIDUser ?? '-');
// $sheet->setCellValue('Q' . $startFrom, $paymentMethod ?? '-');
$sheet->setCellValue('T' . $startFrom, $statusLivechat);
$sheet->setCellValue('U' . $startFrom, $liveChat->prescription->sKodeResep ?? '-');
$sheet->setCellValue('V' . $startFrom, $fullNameDoctor);
$sheet->setCellValue('W' . $startFrom, $liveChat->doctor->speciality->sSpesialis ?? '-');
$sheet->setCellValue('X' . $startFrom, $liveChat->rujukan ? 'Ya' : 'Tidak');
$sheet->setCellValue('Y' . $startFrom, $liveChat->rujukan->sDepartement ?? '-' );
$sheet->setCellValue('Z' . $startFrom, '-');
$sheet->setCellValue('AA' . $startFrom, $tebusResep);
$sheet->setCellValue('AB' . $startFrom, 'LMS');
// $sheet->setCellValue('AC' . $startFrom, $liveChat->prescription->dCreateOn ?? '-');
// $sheet->setCellValue('AD' . $startFrom, $obat);
// $sheet->setCellValue('AE' . $startFrom, $tebusResep);
// $sheet->setCellValue('AF' . $startFrom, $paymentTebus);
// $sheet->setCellValue('AG' . $startFrom, $liveChat->rujukan->nIDHealthcare ?? '-');
// $sheet->setCellValue('AH' . $startFrom, $liveChat->rujukan->sDepartement ?? '-');
// $sheet->setCellValue('AI' . $startFrom, $liveChat->summary->sSubjective ?? '-');
// $sheet->setCellValue('AJ' . $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'] as $header) {
// if ($header === 'A') {
// $spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(35, 'px');
// } elseif ($header === 'H' || $header === 'I') {
// $spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(100, 'px');
// } else {
$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(Request $request)
{
$startDate = $request->has('startDate') ? $request->input('startDate') : '';
$endDate = $request->has('endDate') ? $request->input('endDate') : '';
$liveChats = Livechat::with('userInsurance',
'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',
'prescription',
'rujukan'
)
->whereHas('userInsurance', function (Builder $query) {
// Kondisi pada relasi userInsurance
$query->where('nIDInsurance', 107); // khusus inhealth
})
->where(function (Builder $query) use ($startDate, $endDate) {
// $query->where('nIDAppointment', '!=', null);
// $query->where('nIDAppointment', '!=', '');
if ($startDate) {
$query->where('dCreateOn', '>=', $startDate);
}
if ($endDate) {
$endDate = date('Y-m-d', strtotime($endDate . ' +1 day'));
$query->where('dCreateOn', '<', $endDate);
}
})
->orderBy('nID', 'desc')
->get(['nID', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia', 'dCreateOn', 'sNoSpj', 'dRequestTime', 'dAcceptTime', 'dStartTime', 'dEndTime']);
$headers = [
['value' => 'ConsultationId', 'cell' => 'A1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'No SJP', 'cell' => 'B1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'PKSKD', 'cell' => 'C1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'PKSNM', 'cell' => 'D1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Card Number', 'cell' => 'E1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'NamaPasien', 'cell' => 'F1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'JenisKelamin', 'cell' => 'G1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'TanggalLahir', 'cell' => 'H1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Usia', 'cell' => 'I1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Produk', 'cell' => 'J1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Plan', 'cell' => 'K1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'DependencyStatus', 'cell' => 'L1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'TanggalKonsultasi', 'cell' => 'M1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Keluhan', 'cell' => 'N1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Kode Diagnosa', 'cell' => 'O1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Diagnosa', 'cell' => 'P1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'StartTime', 'cell' => 'Q1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'EndTime', 'cell' => 'R1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'DurasiKonsultasi', 'cell' => 'S1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'StatusKonsultasi', 'cell' => 'T1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'PrescriptionNumber', 'cell' => 'U1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'NamaDokter', 'cell' => 'V1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Jenis Dokter', 'cell' => 'W1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Rujuk (Ya/Tidak)', 'cell' => 'X1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Poli', 'cell' => 'Y1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Total', 'cell' => 'Z1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'Obat', 'cell' => 'AA1', 'mergeCell' => false, 'mergeToCell' => ''],
['value' => 'By', 'cell' => 'AB1', 'mergeCell' => false, 'mergeToCell' => ''],
];
$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);
}
$startFrom = 2;
foreach ($liveChats as $indexLiveChat => $liveChat) {
$phone = $liveChat->user->sPhone ?? '-';
$status = $liveChat->sStatus;
$nIDUser = $liveChat->user->nIDUser ?? 0; // Principal or Dependent
$paymentMethod = $liveChat->appointment ? Helper::sPaymentMethod($liveChat->appointment->sPaymentMethod) : 'N/A';
$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";
break;
case 1:
$statusLivechat = "Accepted by Doctor but User not Payment";
break;
case 2:
$statusLivechat = "Payment Success";
break;
case 3:
$statusLivechat = "Decline by Doctor";
break;
case 4:
$statusLivechat = "Payment Expired";
break;
default:
$statusLivechat = "Cancel 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);
$responseTimeDiff = sprintf('%02d:%02d:%02d', $diff->h, $diff->i, $diff->s);
} else {
$responseTimeDiff = '00:00:00'; // Default jika data kosong
}
// Hitung selisih waktu chat
if ($startTime && $endTime) {
$diffChatTime = $startTime->diff($endTime);
$chatTimeDiff = sprintf('%02d:%02d:%02d', $diffChatTime->h, $diffChatTime->i, $diffChatTime->s);
} 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 = [];
foreach($diagnosis as $data){
$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
}
}
$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';
}
if($liveChat->prescription->payment){
$tebusResep = 'Online';
if ($liveChat->prescription->payment->sPaymentStatus == 'paid'){
$paymentTebus = Carbon::parse($liveChat->prescription->payment->dCreateOn)->format('d-m-Y H:i:s');
}
};
} else {
$tebusResep = '-';
}
switch ($liveChat->user->nIDHubunganKeluarga) {
case 9:
$nIDHubunganKeluarga = "Peserta"; // Parent
break;
case 4:
$nIDHubunganKeluarga = 'Istri'; // Spouse
break;
case 5:
$nIDHubunganKeluarga = 'Anak'; // Child
break;
case 3:
$nIDHubunganKeluarga = 'Suami'; // Husband
break;
default:
$nIDHubunganKeluarga = '-'; // No need to set $nIDHubunganKeluarga as it's already set to default value
break;
}
if ($liveChat->user->relation && $nIDHubunganKeluarga == '-'){
$nIDHubunganKeluarga = $liveChat->user->relation->sHubunganKeluarga;
}
$obat = '-';
if($liveChat->prescription){
if ($liveChat->prescription->items){
$obatArray = [];
foreach($liveChat->prescription->items as $data){
$obatArray[] = $data->sItemName .' - '. $data->nQty;
}
$obat = implode('; ',$obatArray);
}
};
$sheet->setCellValue('A' . $startFrom, $liveChat->nID ?? '-');
$sheet->setCellValue('B' . $startFrom, $liveChat->sNoSpj ?? '-');
$sheet->setCellValue('C' . $startFrom, (string)($liveChat->userInsurance->sCorporateCode ?? '-'));
$sheet->setCellValue('D' . $startFrom, (string)($liveChat->userInsurance->sCorporateName ?? '-'));
$sheet->setCellValue('E' . $startFrom, (string)($liveChat->userInsurance->sNoPolis ?? '-'));
$sheet->setCellValue('F' . $startFrom, $liveChat->user->full_name ?? '-');
$sheet->setCellValue('G' . $startFrom, $liveChat->user->detail->dTanggalLahir ?? '-');
$sheet->setCellValue('H' . $startFrom, $liveChat->user->detail->nIDJenisKelamin == 1 ? 'Laki-laki' : 'Wanita');
$sheet->setCellValue('I' . $startFrom, Helper::calculateAge($liveChat->user->detail->dTanggalLahir) ?? '-');
$sheet->setCellValue('J' . $startFrom, (string)($liveChat->userInsurance->sProductCode ?? '-'));
$sheet->setCellValue('K' . $startFrom, (string)($liveChat->userInsurance->sPlanCode ?? '-'));
$sheet->setCellValue('L' . $startFrom, $nIDHubunganKeluarga ?? '-');
$sheet->setCellValue('M' . $startFrom, $requestTime->format('Y-m-d'));
$sheet->setCellValue('N' . $startFrom, $liveChat->summary->sSubjective ?? '-');
$sheet->setCellValue('O' . $startFrom, $diagnosaCode ?? '-');
$sheet->setCellValue('P' . $startFrom, $diagnosa ?? '-');
$sheet->setCellValue('Q' . $startFrom, $startTime->format('H:i:s'));
$sheet->setCellValue('R' . $startFrom, $endTime->format('H:i:s'));
$sheet->setCellValue('S' . $startFrom, $chatTime);
// $sheet->setCellValue('O' . $startFrom, $recordType);
// $sheet->setCellValue('P' . $startFrom, $nIDUser ?? '-');
// $sheet->setCellValue('Q' . $startFrom, $paymentMethod ?? '-');
$sheet->setCellValue('T' . $startFrom, $statusLivechat);
$sheet->setCellValue('U' . $startFrom, $liveChat->prescription->sKodeResep ?? '-');
$sheet->setCellValue('V' . $startFrom, $fullNameDoctor);
$sheet->setCellValue('W' . $startFrom, $liveChat->doctor->speciality->sSpesialis ?? '-');
$sheet->setCellValue('X' . $startFrom, $liveChat->rujukan ? 'Ya' : 'Tidak');
$sheet->setCellValue('Y' . $startFrom, $liveChat->rujukan->sDepartement ?? '-' );
$sheet->setCellValue('Z' . $startFrom, '-');
$sheet->setCellValue('AA' . $startFrom, $tebusResep);
$sheet->setCellValue('AB' . $startFrom, 'LMS');
// $sheet->setCellValue('AC' . $startFrom, $liveChat->prescription->dCreateOn ?? '-');
// $sheet->setCellValue('AD' . $startFrom, $obat);
// $sheet->setCellValue('AE' . $startFrom, $tebusResep);
// $sheet->setCellValue('AF' . $startFrom, $paymentTebus);
// $sheet->setCellValue('AG' . $startFrom, $liveChat->rujukan->nIDHealthcare ?? '-');
// $sheet->setCellValue('AH' . $startFrom, $liveChat->rujukan->sDepartement ?? '-');
// $sheet->setCellValue('AI' . $startFrom, $liveChat->summary->sSubjective ?? '-');
// $sheet->setCellValue('AJ' . $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'] as $header) {
// if ($header === 'A') {
// $spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(35, 'px');
// } elseif ($header === 'H' || $header === 'I') {
// $spreadsheet->getActiveSheet()->getColumnDimension($header)->setWidth(100, 'px');
// } else {
$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
]);
}
}