diff --git a/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php b/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php index a3d8ea35..1484056f 100644 --- a/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php +++ b/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php @@ -10,6 +10,8 @@ use Illuminate\Support\Facades\DB; use Modules\Internal\Http\Controllers\Api\RequestLogController as primeCenterRequestLog; use App\Helpers\Helper; use App\Models\File; +use Dompdf\Dompdf; +use Dompdf\Options; class RequestLogController extends Controller { @@ -281,4 +283,27 @@ class RequestLogController extends Controller } } } + + public function downlodLog($request_log_id) + { + $data = ['key' => $request_log_id]; + $pdf = new Dompdf(); + + $options = new Options(); + $options->set('isHtml5ParserEnabled', true); + $options->set('isPhpEnabled', true); + $pdf->setOptions($options); + + $html = view('pdf.view', $data); + $pdf->loadHtml($html); + + $pdf->render(); + + $headers = [ + 'Content-Type' => 'application/pdf', + 'Content-Disposition' => 'inline; filename="file.pdf"', + ]; + + return response($pdf->output(), 200, $headers); + } } diff --git a/Modules/HospitalPortal/Routes/api.php b/Modules/HospitalPortal/Routes/api.php index fabf81c9..f0717cc0 100644 --- a/Modules/HospitalPortal/Routes/api.php +++ b/Modules/HospitalPortal/Routes/api.php @@ -54,6 +54,7 @@ Route::prefix('v1')->group(function() { Route::get('get-request-log', 'getRequestLog'); Route::get('get-final-log', 'getFinalLog'); Route::post('request-final-log', 'requestFinalLog'); + Route::get('download-log/{request_log_id}', 'downlodLog'); }); //Notification Route::controller(NotificationController::class)->group(function() { diff --git a/frontend/hospital-portal/src/sections/dashboard/TableList.tsx b/frontend/hospital-portal/src/sections/dashboard/TableList.tsx index 44cdedc9..b3f95ca0 100644 --- a/frontend/hospital-portal/src/sections/dashboard/TableList.tsx +++ b/frontend/hospital-portal/src/sections/dashboard/TableList.tsx @@ -51,23 +51,16 @@ function handleChangeTab(event: React.SyntheticEvent, newValue: string) { const [data, setData] = useState([]); // Download LOG - async function handleDownloadLog(claimRequest:any) { + async function handleDownloadLog(request_log_id:any) { return axios - .get(`claim-requests/${claimRequest}/log`, { + .get(`download-log/${request_log_id}`, { responseType: 'blob', }) .then((response) => { - window.open(URL.createObjectURL(response.data)); - // setLoadingLog(false); + window.open(URL.createObjectURL(response.data), '_blank'); }) - // .then((blobFile) => { - // new File([blobFile], 'asdads.pdf', { type: blobFile.type }) - // setLoadingLog(false); - // }) .catch((response) => { - console.log(response); enqueueSnackbar(response.message, { variant: 'error' }); - // setLoadingLog(false); }); } @@ -358,7 +351,7 @@ function handleChangeTab(event: React.SyntheticEvent, newValue: string) { View {/* {obj.status === 'approved' ? ( */} - handleDownloadLog(38)}> + handleDownloadLog(obj.id)}> Download LOG diff --git a/resources/views/pdf/view.blade.php b/resources/views/pdf/view.blade.php new file mode 100644 index 00000000..dd2e4a16 --- /dev/null +++ b/resources/views/pdf/view.blade.php @@ -0,0 +1,37 @@ + + + + + + + + Ivan Julian + + + + + + + +

Hello, {{ $key }}

+

This is a simple example for generating PDF in Laravel using Dompdf.

+ +