export excel livechat
This commit is contained in:
@@ -5,9 +5,14 @@ namespace Modules\Internal\Http\Controllers\Api;
|
|||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Models\OLDLMS\Livechat;
|
use App\Models\OLDLMS\Livechat;
|
||||||
use Illuminate\Contracts\Support\Renderable;
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Modules\Internal\Transformers\LivechatResource;
|
use Modules\Internal\Transformers\LivechatResource;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
class LivechatController extends Controller
|
class LivechatController extends Controller
|
||||||
{
|
{
|
||||||
@@ -17,19 +22,19 @@ class LivechatController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$startDate = $request->startDate;
|
$startDate = $request->startDate;
|
||||||
$endDate = $request->endDate;
|
$endDate = $request->endDate;
|
||||||
|
|
||||||
$livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare')
|
$livechat = Livechat::with('doctor.user', 'doctor.speciality', 'appointment.appointmentDetail', 'healthCare')
|
||||||
->where('nIDAppointment', '!=', null)
|
->where('nIDAppointment', '!=', null)
|
||||||
->where('nIDAppointment', '!=', '');
|
->where('nIDAppointment', '!=', '');
|
||||||
|
|
||||||
|
|
||||||
if ($startDate){
|
if ($startDate) {
|
||||||
$livechat = $livechat->where('dCreateOn', '>=', $startDate);
|
$livechat = $livechat->where('dCreateOn', '>=', $startDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($endDate){
|
if ($endDate) {
|
||||||
$livechat = $livechat->where('dCreateOn', '<=', $endDate);
|
$livechat = $livechat->where('dCreateOn', '<=', $endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,24 +43,6 @@ class LivechatController extends Controller
|
|||||||
return response()->json(Helper::paginateResources(LivechatResource::collection($livechat)));
|
return response()->json(Helper::paginateResources(LivechatResource::collection($livechat)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for creating a new resource.
|
|
||||||
* @return Renderable
|
|
||||||
*/
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
return view('internal::create');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
* @param Request $request
|
|
||||||
* @return Renderable
|
|
||||||
*/
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the specified resource.
|
* Show the specified resource.
|
||||||
* @param int $id
|
* @param int $id
|
||||||
@@ -70,34 +57,95 @@ class LivechatController extends Controller
|
|||||||
return response()->json(new LivechatResource($livechat));
|
return response()->json(new LivechatResource($livechat));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function export(Request $request)
|
||||||
* Show the form for editing the specified resource.
|
|
||||||
* @param int $id
|
|
||||||
* @return Renderable
|
|
||||||
*/
|
|
||||||
public function edit($id)
|
|
||||||
{
|
{
|
||||||
return view('internal::edit');
|
$startDate = $request->has('startDate') ? $request->input('startDate') : '';
|
||||||
}
|
$endDate = $request->has('endDate') ? $request->input('endDate') : '';
|
||||||
|
|
||||||
/**
|
$liveChats = Livechat::with('user:nID,sFirstName,sLastName,sEmail,sPhone', 'doctor:nID,nIDSpesialis,nIDUser', 'doctor.user:nID,sFirstName,sLastName', 'appointment:nID,sPaymentStatus', 'appointment.appointmentDetail:nID,nIDAppointment,dTanggalAppointment,tTimeAppointment', 'healthCare:nID,sHealthCare')
|
||||||
* Update the specified resource in storage.
|
->where(function (Builder $query) use ($startDate, $endDate) {
|
||||||
* @param Request $request
|
$query->where('nIDAppointment', '!=', null);
|
||||||
* @param int $id
|
$query->where('nIDAppointment', '!=', '');
|
||||||
* @return Renderable
|
if ($startDate) {
|
||||||
*/
|
$query->where('dCreateOn', '>=', $startDate);
|
||||||
public function update(Request $request, $id)
|
}
|
||||||
{
|
if ($endDate) {
|
||||||
//
|
$query->where('dCreateOn', '<=', $endDate);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
->get(['nId', 'nIDUser', 'nIDDokter', 'nIDHealthCare', 'nIDAppointment', 'sStatus', 'sMediaDokter', 'sMedia']);
|
||||||
|
|
||||||
/**
|
$headers = [
|
||||||
* Remove the specified resource from storage.
|
['value' => 'No', 'cell' => 'A1', 'mergeCell' => true, 'mergeToCell' => 'A2'],
|
||||||
* @param int $id
|
['value' => 'Nama Dokter', 'cell' => 'B1', 'mergeCell' => true, 'mergeToCell' => 'B2'],
|
||||||
* @return Renderable
|
['value' => 'Nama Pasien', 'cell' => 'C1', 'mergeCell' => true, 'mergeToCell' => 'C2'],
|
||||||
*/
|
['value' => 'No Telepon Pasien', 'cell' => 'D1', 'mergeCell' => true, 'mergeToCell' => 'D2'],
|
||||||
public function destroy($id)
|
['value' => 'Email Pasien', 'cell' => 'E1', 'mergeCell' => true, 'mergeToCell' => 'E2'],
|
||||||
{
|
['value' => 'Faskes', 'cell' => 'F1', 'mergeCell' => true, 'mergeToCell' => 'F2'],
|
||||||
//
|
['value' => 'Tanggal Appointment', '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' => 'Status Appointment', 'cell' => 'J1', 'mergeCell' => true, 'mergeToCell' => 'J2'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$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) {
|
||||||
|
$sheet->setCellValue('A' . $startFrom, $indexLiveChat + 1);
|
||||||
|
$sheet->setCellValue('B' . $startFrom, $liveChat->doctor->user->full_name ?? '-');
|
||||||
|
$sheet->setCellValue('C' . $startFrom, $liveChat->user->full_name ?? '-');
|
||||||
|
$sheet->setCellValue('D' . $startFrom, preg_replace('/(\d{3})(\d{4})(\d{3})/', '$1 $2 $3', $liveChat->user->sPhone) ?? '-');
|
||||||
|
$sheet->setCellValue('E' . $startFrom, $liveChat->user->sEmail ?? '-');
|
||||||
|
$sheet->setCellValue('F' . $startFrom, $liveChat->healthCare->sHealthCare ?? '-');
|
||||||
|
$sheet->setCellValue('G' . $startFrom, Carbon::parse($liveChat->appointment->appointmentDetail->dTanggalAppointment)->format('d-m-Y') . ' ' . $liveChat->appointment->appointmentDetail->tTimeAppointment ?? '-');
|
||||||
|
$sheet->setCellValue('H' . $startFrom, $liveChat->sMedia ?? '-');
|
||||||
|
$sheet->setCellValue('I' . $startFrom, $liveChat->sMediaDokter ?? '-');
|
||||||
|
$sheet->setCellValue('J' . $startFrom, $liveChat->appointment->paymentStatus ?? '-');
|
||||||
|
$startFrom++;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] 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('A3: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
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ Route::prefix('internal')->group(function () {
|
|||||||
Route::get('search-specialities', [SpecialityController::class, 'searchSpeciality']);
|
Route::get('search-specialities', [SpecialityController::class, 'searchSpeciality']);
|
||||||
Route::resource('organizations', OrganizationController::class);
|
Route::resource('organizations', OrganizationController::class);
|
||||||
Route::resource('appointments', AppointmentController::class);
|
Route::resource('appointments', AppointmentController::class);
|
||||||
|
Route::get('live-chat/export', [LivechatController::class, 'export']);
|
||||||
Route::resource('live-chat', LivechatController::class);
|
Route::resource('live-chat', LivechatController::class);
|
||||||
Route::get('prescription', [PrescriptionController::class, 'index']);
|
Route::get('prescription', [PrescriptionController::class, 'index']);
|
||||||
Route::get('prescription/{id}', [PrescriptionController::class, 'index']);
|
Route::get('prescription/{id}', [PrescriptionController::class, 'index']);
|
||||||
@@ -161,8 +162,8 @@ Route::prefix('internal')->group(function () {
|
|||||||
Route::resource('doctors', DoctorController::class);
|
Route::resource('doctors', DoctorController::class);
|
||||||
|
|
||||||
Route::post('generate-log/{member_id}', [CorporateMemberController::class, 'generateLog']);
|
Route::post('generate-log/{member_id}', [CorporateMemberController::class, 'generateLog']);
|
||||||
Route::controller(ClaimRequestController::class)->group(function(){
|
Route::controller(ClaimRequestController::class)->group(function () {
|
||||||
Route::post('files-mcu','filesMcu');
|
Route::post('files-mcu', 'filesMcu');
|
||||||
});
|
});
|
||||||
Route::get('claim-requests', [ClaimRequestController::class, 'index'])->name('claim-requests.index');
|
Route::get('claim-requests', [ClaimRequestController::class, 'index'])->name('claim-requests.index');
|
||||||
Route::post('claim-requests/{id}/approve', [ClaimRequestController::class, 'approve'])->name('claim-requests.approve');
|
Route::post('claim-requests/{id}/approve', [ClaimRequestController::class, 'approve'])->name('claim-requests.approve');
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class Appointment extends Model
|
|||||||
'dUpdateOn',
|
'dUpdateOn',
|
||||||
'dDeleteOn',
|
'dDeleteOn',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
'status_name',
|
'status_name',
|
||||||
'payment_method',
|
'payment_method',
|
||||||
@@ -86,7 +86,7 @@ class Appointment extends Model
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function paymentStatus(): Attribute
|
protected function paymentStatus(): Attribute
|
||||||
{
|
{
|
||||||
@@ -109,7 +109,7 @@ class Appointment extends Model
|
|||||||
protected function type(): Attribute
|
protected function type(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: function($value) {
|
get: function ($value) {
|
||||||
return $this->nIDJenisBookingNames[$this->nIDJenisBooking] ?? '-';
|
return $this->nIDJenisBookingNames[$this->nIDJenisBooking] ?? '-';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -118,16 +118,14 @@ class Appointment extends Model
|
|||||||
protected function shareKonsultasi(): Attribute
|
protected function shareKonsultasi(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: function() {
|
get: function () {
|
||||||
$consulPrice = ((float) $this->detail->sPaymentDetails['gross_amount'] ?? 0) - $this->nAdminFee;
|
$consulPrice = ((float) $this->detail->sPaymentDetails['gross_amount'] ?? 0) - $this->nAdminFee;
|
||||||
if ( $this->nIDJenisBooking == 3 ) { // Telekonsultasi Sekarang
|
if ($this->nIDJenisBooking == 3) { // Telekonsultasi Sekarang
|
||||||
return $consulPrice * (100-$this->healthCare->commission->nCommissionATC) / 100;
|
return $consulPrice * (100 - $this->healthCare->commission->nCommissionATC) / 100;
|
||||||
}
|
} else if ($this->nIDJenisBooking == 2) { // Telekonsultasi
|
||||||
else if ( $this->nIDJenisBooking == 2 ) { // Telekonsultasi
|
return $consulPrice * (100 - $this->healthCare->commission->nCommissionTC) / 100;
|
||||||
return $consulPrice * (100-$this->healthCare->commission->nCommissionTC) / 100;
|
} else { // Walk In
|
||||||
}
|
return $consulPrice * (100 - $this->healthCare->commission->nCommission) / 100;
|
||||||
else { // Walk In
|
|
||||||
return $consulPrice * (100-$this->healthCare->commission->nCommission) / 100;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -136,16 +134,14 @@ class Appointment extends Model
|
|||||||
protected function shareKomisi(): Attribute
|
protected function shareKomisi(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: function() {
|
get: function () {
|
||||||
$consulPrice = ((float) $this->detail->sPaymentDetails['gross_amount'] ?? 0) - $this->nAdminFee;
|
$consulPrice = ((float) $this->detail->sPaymentDetails['gross_amount'] ?? 0) - $this->nAdminFee;
|
||||||
if ( $this->nIDJenisBooking == 3 ) { // Telekonsultasi Sekarang
|
if ($this->nIDJenisBooking == 3) { // Telekonsultasi Sekarang
|
||||||
return $consulPrice * ($this->healthCare->commission->nCommissionATC) / 100;
|
return $consulPrice * ($this->healthCare->commission->nCommissionATC) / 100;
|
||||||
}
|
} else if ($this->nIDJenisBooking == 2) { // Telekonsultasi
|
||||||
else if ( $this->nIDJenisBooking == 2 ) { // Telekonsultasi
|
|
||||||
return $consulPrice * ($this->healthCare->commission->nCommissionTC) / 100;
|
return $consulPrice * ($this->healthCare->commission->nCommissionTC) / 100;
|
||||||
}
|
} else { // Walk In
|
||||||
else { // Walk In
|
return $consulPrice * ($this->healthCare->commission->nCommission) / 100;
|
||||||
return $consulPrice * ($this->healthCare->commission->nCommission) / 100;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -188,7 +188,13 @@ export default function List() {
|
|||||||
</LocalizationProvider>
|
</LocalizationProvider>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} md={2}>
|
<Grid item xs={12} md={2}>
|
||||||
<Button variant="outlined" fullWidth startIcon={<Add />} sx={{ p: 1.8 }}>
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
fullWidth
|
||||||
|
startIcon={<Add />}
|
||||||
|
sx={{ p: 1.8 }}
|
||||||
|
onClick={exportExcel}
|
||||||
|
>
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -397,6 +403,27 @@ export default function List() {
|
|||||||
setDataTableData(response.data);
|
setDataTableData(response.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const exportExcel = async () => {
|
||||||
|
var filter = Object.fromEntries([...searchParams.entries()]);
|
||||||
|
|
||||||
|
await axios
|
||||||
|
.get('live-chat/export', { params: filter })
|
||||||
|
.then((res) => {
|
||||||
|
enqueueSnackbar('Data berhasil di Export', {
|
||||||
|
variant: 'success',
|
||||||
|
anchorOrigin: { horizontal: 'right', vertical: 'top' },
|
||||||
|
});
|
||||||
|
|
||||||
|
document.location.href = res.data.data.file_url;
|
||||||
|
})
|
||||||
|
.catch((err) =>
|
||||||
|
enqueueSnackbar('Data Gagal di Export', {
|
||||||
|
variant: 'error',
|
||||||
|
anchorOrigin: { horizontal: 'right', vertical: 'top' },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// const applyFilter = async (searchFilter: string) => {
|
// const applyFilter = async (searchFilter: string) => {
|
||||||
// await loadDataTableData({ search: searchFilter });
|
// await loadDataTableData({ search: searchFilter });
|
||||||
// setSearchParams({ search: searchFilter });
|
// setSearchParams({ search: searchFilter });
|
||||||
@@ -485,20 +512,20 @@ export default function List() {
|
|||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell style={headStyle} align="left" />
|
<TableCell style={headStyle} align="left" />
|
||||||
{/* <TableCell style={headStyle} align="left">
|
{/* <TableCell style={headStyle} align="left">
|
||||||
Tanggal Booking
|
Tanggal Booking
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell style={headStyle} align="left">
|
<TableCell style={headStyle} align="left">
|
||||||
Tanggal Appointment
|
Tanggal Appointment
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell style={headStyle} align="left">
|
<TableCell style={headStyle} align="left">
|
||||||
Faskes
|
Faskes
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell style={headStyle} align="left">
|
<TableCell style={headStyle} align="left">
|
||||||
Nama Dokter
|
Nama Dokter
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell style={headStyle} align="left">
|
<TableCell style={headStyle} align="left">
|
||||||
Spesialisasi
|
Spesialisasi
|
||||||
</TableCell> */}
|
</TableCell> */}
|
||||||
<TableCell style={headStyle} align="left">
|
<TableCell style={headStyle} align="left">
|
||||||
Pasien
|
Pasien
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
Reference in New Issue
Block a user