From 74f87e150ac8c02757802aa90263c5063af216ca Mon Sep 17 00:00:00 2001 From: Tb Fajri Date: Fri, 26 Jan 2024 11:07:13 +0700 Subject: [PATCH] [Improvement] add fitur delete request log --- .../Controllers/Api/RequestLogController.php | 1 + .../Controllers/Api/RequestLogController.php | 37 +++-- Modules/Internal/Routes/api.php | 2 + .../InpatientMonitoring/List.tsx | 60 +++----- .../Components/DialogDeleteFinalLOG.tsx | 132 ++++++++++++++++++ .../pages/CustomerService/FinalLog/List.tsx | 36 ++--- .../Components/DialogDeleteRequestLOG.tsx | 132 ++++++++++++++++++ .../pages/CustomerService/Request/List.tsx | 60 +++----- 8 files changed, 351 insertions(+), 109 deletions(-) create mode 100644 frontend/dashboard/src/pages/CustomerService/FinalLog/Components/DialogDeleteFinalLOG.tsx create mode 100644 frontend/dashboard/src/pages/CustomerService/Request/Components/DialogDeleteRequestLOG.tsx diff --git a/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php b/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php index 7360e4ef..3f6328c9 100644 --- a/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php +++ b/Modules/HospitalPortal/Http/Controllers/Api/RequestLogController.php @@ -163,6 +163,7 @@ class RequestLogController extends Controller $results = DB::table('request_logs') ->leftJoin('members', 'request_logs.member_id', '=', 'members.id') + ->where('request_logs.deleted_at', null) ->when($request->input('search'), function ($query, $search) { $query->where(function ($query) use ($search) { $query->orWhere('request_logs.code', 'like', "%" . $search . "%") diff --git a/Modules/Internal/Http/Controllers/Api/RequestLogController.php b/Modules/Internal/Http/Controllers/Api/RequestLogController.php index e8e2ec81..690d1564 100644 --- a/Modules/Internal/Http/Controllers/Api/RequestLogController.php +++ b/Modules/Internal/Http/Controllers/Api/RequestLogController.php @@ -52,6 +52,10 @@ class RequestLogController extends Controller public function index(Request $request) { $requestLog = RequestLog::query() + ->where('deleted_at', null) + ->when($request->final_log, function($q, $final_log) { + $q->where('final_log', $final_log); + }) ->when($request->search, function ($q, $search) { $q->where('code', 'LIKE', "%".$search."%"); $q->orWhereHas('member', function ($subQuery) use ($search) { @@ -66,9 +70,6 @@ class RequestLogController extends Controller ->when(empty($request->orderBy), function ($q) { $q->orderBy('created_at', 'desc'); }) - ->when($request->final_log, function($q, $final_log) { - $q->where('final_log', $final_log); - }) ->when($request->service_code, function($q, $service_code) { if ($service_code == 'IP'){ // Penjagaan sementara agar ini hanya muncul di inpatient monitoring $q->where('service_code', $service_code); @@ -252,16 +253,12 @@ class RequestLogController extends Controller $requestLog->reason = $request->reason; } - // Simpan perubahan pada entitas - $requestLog->save(); - - if ($request->status){ $requestLog->status = $request->status; + $requestLog->approved_by = auth()->user()->id; + $requestLog->approved_at = Carbon::now(); } - $requestLog->approved_by = auth()->user()->id; - $requestLog->approved_at = Carbon::now(); $requestLog->save(); // update nirc member @@ -284,9 +281,27 @@ class RequestLogController extends Controller * @param int $id * @return Renderable */ - public function destroy($id) + public function destroy(Request $request, $id) { - // + $requestLog = RequestLog::findOrFail($id); + $requestLog->reason = 'Reason Delete ' .$request->reason; + $requestLog->deleted_at = Carbon::now(); + $requestLog->deleted_by = auth()->user()->id; + // Delete the record + $requestLog->save(); + } + + public function deleteFinalLog(Request $request, $id){ + $requestLog = RequestLog::findOrFail($id); + $requestLog->status_final_log = null; + $requestLog->final_log = 0; + $requestLog->reason_final = 'Reason Delete ' .$request->reason; + $requestLog->save(); + return response()->json([ + 'error' => false, + 'message' => 'Delete Final LOG', + 'data' => $requestLog], + 200); } /** diff --git a/Modules/Internal/Routes/api.php b/Modules/Internal/Routes/api.php index 30556c0e..0b9b9cd3 100644 --- a/Modules/Internal/Routes/api.php +++ b/Modules/Internal/Routes/api.php @@ -258,6 +258,8 @@ Route::prefix('internal')->group(function () { Route::post('customer-service/request', [RequestLogController::class, 'createNew']); Route::put('customer-service/request/{id}', [RequestLogController::class, 'update']); Route::get('customer-service/request/{id}', [RequestLogController::class, 'show']); + Route::put('customer-service/request/{id}', [RequestLogController::class, 'destroy']); + Route::put('customer-service/request/final_log/{id}', [RequestLogController::class, 'deleteFinalLog']); Route::get('customer-service/request/{id}/download', [RequestLogController::class, 'generateRequestLog']); Route::post('customer-service/request/import', [RequestLogController::class, 'importRequestLog']); Route::get('customer-service/request/data', [RequestLogController::class, 'generateDataRequestLogExcel']); diff --git a/frontend/dashboard/src/pages/CaseManagement/InpatientMonitoring/List.tsx b/frontend/dashboard/src/pages/CaseManagement/InpatientMonitoring/List.tsx index c8a20a05..32ea17c9 100644 --- a/frontend/dashboard/src/pages/CaseManagement/InpatientMonitoring/List.tsx +++ b/frontend/dashboard/src/pages/CaseManagement/InpatientMonitoring/List.tsx @@ -50,6 +50,8 @@ import TableMoreMenu from '@/components/table/TableMoreMenu'; import { Import } from '@/@types/claims'; import { FinalLogType } from '../../CustomerService/FinalLog/Model/Types'; +import DialogDeleteFinalLOG from '@/pages/CustomerService/FinalLog/Components/DialogDeleteFinalLOG'; +import { Delete } from '@mui/icons-material'; // import LoadingButton from '@/theme/overrides/LoadingButton'; export default function List() { @@ -301,17 +303,9 @@ export default function List() { setSearchParams(filter); }; - const handleApprove = (claimRequest) => { - axios - .post(`claim-requests/${claimRequest.id}/approve`) - .then((response) => { - enqueueSnackbar('Success Approve', { variant: 'success' }); - loadDataTableData(); - }) - .catch(({ response }) => { - enqueueSnackbar(response.data.message ?? 'Something went wrong!', { variant: 'error' }); - }); - }; + // Handel Delete Final LOG + const [idFinalLog, setidFinalLog] = useState(); + const [openDialogDeleteFinalLog, setDialogDeleteFinalLog] = useState(false) useEffect(() => { loadDataTableData(); @@ -379,6 +373,14 @@ export default function List() { Detail + { + setidFinalLog(row.id) + setDialogDeleteFinalLog(true) + }} + > + + Delete + } /> @@ -534,30 +536,6 @@ export default function List() { ); } - - // --------------------------------------------------------- - // Dialog Detail Claim Request - const [openDialogDetailClaim, setOpenDialogDetailClaim] = useState(false); - const [loadingClaimDetail, setLoadingClaimDetail] = useState(true); - const [currentClaim, setCurrentClaim] = useState(null); - - function handleShowClaim(claimRequest) { - setLoadingClaimDetail(true); - setOpenDialogDetailClaim(true); - - axios - .get(`/claim-requests/${claimRequest.id}`) - .then(({ data }) => { - setCurrentClaim(data.data); - setLoadingClaimDetail(false); - }) - .catch((err) => { - enqueueSnackbar(err.message, { variant: 'error' }); - }); - } - - function handleDownloadLog() {} - return ( @@ -574,12 +552,12 @@ export default function List() { /> - + {/* Dialog Delete */} + ); diff --git a/frontend/dashboard/src/pages/CustomerService/FinalLog/Components/DialogDeleteFinalLOG.tsx b/frontend/dashboard/src/pages/CustomerService/FinalLog/Components/DialogDeleteFinalLOG.tsx new file mode 100644 index 00000000..c5520968 --- /dev/null +++ b/frontend/dashboard/src/pages/CustomerService/FinalLog/Components/DialogDeleteFinalLOG.tsx @@ -0,0 +1,132 @@ +import MuiDialog from "@/components/MuiDialog"; +import { Autocomplete, Button, Card, Checkbox, DialogActions, Grid, Typography } from "@mui/material"; +import { Paper } from "@mui/material"; +import { Stack } from '@mui/material'; +import React, { useState } from 'react'; +import { fDateTimesecond, toTitleCase } from "@/utils/formatTime"; +import axios from "@/utils/axios"; +import { enqueueSnackbar } from "notistack"; +import { useNavigate } from "react-router"; +import { TextField } from "@mui/material"; + + +type DialogDeleteType = { + openDialog: boolean; + setOpenDialog: any; + onSubmit?: void; + id: number|undefined; +} + +export default function DialogDeleteFinalLOG({id, setOpenDialog, openDialog,onSubmit} : DialogDeleteType ) { + const style1 = { + color: '#919EAB', + width: '30%' + } + const style2 = { + width: '70%' + } + const marginBottom2 = { + marginBottom: 2, + } + + const handleCloseDialog = () => { + setOpenDialog(false); + resetForm(); + } + + const [isReasonSelected, setIsReasonSelected] = useState(false); + + const reasons = [ + { value: 'agreement', label: 'Agreement changed' }, + { value: 'endorsement', label: 'Endorsement' }, + { value: 'renewal', label: 'Renewal' }, + { value: 'wrong_setting', label: 'Wrong Setting' }, + // Add more options as needed + ]; + const [formData, setFormData] = useState({ + reason: null + }); + + const resetForm = () => { + setFormData({ + reason: null + }); + }; + + const handleChange = (field, value) => { + setFormData((prevData) => ({ + ...prevData, + [field]: value, + })); + if (field === 'reason') { + setIsReasonSelected(!!value); + } + + }; + + const handleSubmit = () => { + if (isReasonSelected && formData.reason !== '') { + axios + .put(`customer-service/request/final_log/${id}`, formData) + .then((response) => { + enqueueSnackbar('Request LOG has Deleted', { variant: 'success' }); + setOpenDialog(false); + window.location.reload() + }) + .catch(({ response }) => { + enqueueSnackbar(response.data.message ?? 'Something went wrong!', { variant: 'error' }); + }); + } else { + setIsReasonSelected(false); + alert('Silakan pilih alasan sebelum menghapus data.'); + } + + } + + + const getContent = () => ( + + Are you sure to delete this detail LOG ? + + + + Reason* + option.label} + fullWidth + value={reasons.find((r) => r.value === formData.reason) || null} // Use find to match the default value + onChange={(e, newValue) => handleChange('reason', newValue?.value)} + renderInput={(params) => ( + + )} + /> + + + + + + + + + ); + + + return ( + + ); +} diff --git a/frontend/dashboard/src/pages/CustomerService/FinalLog/List.tsx b/frontend/dashboard/src/pages/CustomerService/FinalLog/List.tsx index 349e9106..5ac5e5af 100644 --- a/frontend/dashboard/src/pages/CustomerService/FinalLog/List.tsx +++ b/frontend/dashboard/src/pages/CustomerService/FinalLog/List.tsx @@ -50,6 +50,8 @@ import TableMoreMenu from '@/components/table/TableMoreMenu'; import { Import } from '@/@types/claims'; import { FinalLogType } from '../FinalLog/Model/Types'; +import DialogDeleteFinalLOG from './Components/DialogDeleteFinalLOG'; +import { Delete } from '@mui/icons-material'; // import LoadingButton from '@/theme/overrides/LoadingButton'; export default function List() { @@ -301,17 +303,9 @@ export default function List() { setSearchParams(filter); }; - const handleApprove = (claimRequest) => { - axios - .post(`claim-requests/${claimRequest.id}/approve`) - .then((response) => { - enqueueSnackbar('Success Approve', { variant: 'success' }); - loadDataTableData(); - }) - .catch(({ response }) => { - enqueueSnackbar(response.data.message ?? 'Something went wrong!', { variant: 'error' }); - }); - }; + // Handel Delete Final LOG + const [idFinalLog, setidFinalLog] = useState(); + const [openDialogDeleteFinalLog, setDialogDeleteFinalLog] = useState(false) useEffect(() => { loadDataTableData(); @@ -379,6 +373,14 @@ export default function List() { Detail + { + setidFinalLog(row.id) + setDialogDeleteFinalLog(true) + }} + > + + Delete + } /> @@ -574,12 +576,12 @@ export default function List() { /> - + {/* Dialog Delete */} + ); diff --git a/frontend/dashboard/src/pages/CustomerService/Request/Components/DialogDeleteRequestLOG.tsx b/frontend/dashboard/src/pages/CustomerService/Request/Components/DialogDeleteRequestLOG.tsx new file mode 100644 index 00000000..bbe05d3a --- /dev/null +++ b/frontend/dashboard/src/pages/CustomerService/Request/Components/DialogDeleteRequestLOG.tsx @@ -0,0 +1,132 @@ +import MuiDialog from "@/components/MuiDialog"; +import { Button, Card, Checkbox, DialogActions, Grid, TextField, Typography } from "@mui/material"; +import { Paper } from "@mui/material"; +import { Stack } from '@mui/material'; +import React, { useState } from 'react'; +import { fDateTimesecond, toTitleCase } from "@/utils/formatTime"; +import axios from "@/utils/axios"; +import { enqueueSnackbar } from "notistack"; +import { useNavigate } from "react-router"; +import { Autocomplete } from "@mui/material"; + + +type DialogDeleteType = { + openDialog: boolean; + setOpenDialog: any; + onSubmit?: void; + id: number|undefined; +} + +export default function DialogDeleteRequestLOG({id, setOpenDialog, openDialog,onSubmit} : DialogDeleteType ) { + const style1 = { + color: '#919EAB', + width: '30%' + } + const style2 = { + width: '70%' + } + const marginBottom2 = { + marginBottom: 2, + } + + const handleCloseDialog = () => { + setOpenDialog(false); + resetForm(); + } + const [isReasonSelected, setIsReasonSelected] = useState(false); + + const reasons = [ + { value: 'agreement', label: 'Agreement changed' }, + { value: 'endorsement', label: 'Endorsement' }, + { value: 'renewal', label: 'Renewal' }, + { value: 'wrong_setting', label: 'Wrong Setting' }, + // Add more options as needed + ]; + const [formData, setFormData] = useState({ + reason: null + }); + + const resetForm = () => { + setFormData({ + reason: null + }); + }; + + const handleChange = (field, value) => { + setFormData((prevData) => ({ + ...prevData, + [field]: value, + })); + if (field === 'reason') { + setIsReasonSelected(!!value); + } + + }; + + const handleSubmit = () => { + if (isReasonSelected && formData.reason !== '') { + axios + .put(`customer-service/request/${id}`, formData) + .then((response) => { + enqueueSnackbar('Request LOG has Deleted', { variant: 'success' }); + setOpenDialog(false); + window.location.reload() + }) + .catch(({ response }) => { + enqueueSnackbar(response.data.message ?? 'Something went wrong!', { variant: 'error' }); + }); + } else { + setIsReasonSelected(false); + alert('Silakan pilih alasan sebelum menghapus data.'); + } + + } + + + const getContent = () => ( + + Are you sure to delete this detail LOG ? + + + + Reason* + option.label} + fullWidth + value={reasons.find((r) => r.value === formData.reason) || null} // Use find to match the default value + onChange={(e, newValue) => handleChange('reason', newValue?.value)} + renderInput={(params) => ( + + )} + /> + + + + + + + + + + ); + + + return ( + + ); +} diff --git a/frontend/dashboard/src/pages/CustomerService/Request/List.tsx b/frontend/dashboard/src/pages/CustomerService/Request/List.tsx index 01b83b9c..44cef222 100644 --- a/frontend/dashboard/src/pages/CustomerService/Request/List.tsx +++ b/frontend/dashboard/src/pages/CustomerService/Request/List.tsx @@ -55,6 +55,8 @@ import { Import } from '@/@types/claims'; import { RequestLogType } from '../Request/Model/Types'; // import SvgIconStyle from '@/components/SvgIconStyle'; import SvgIconStyle from '../../../components/SvgIconStyle'; +import { Delete } from '@mui/icons-material'; +import DialogDeleteRequestLOG from '../Request/Components/DialogDeleteRequestLOG'; // import LoadingButton from '@/theme/overrides/LoadingButton'; export default function List() { @@ -313,17 +315,9 @@ export default function List() { setSearchParams(filter); }; - const handleApprove = (claimRequest) => { - axios - .post(`claim-requests/${claimRequest.id}/approve`) - .then((response) => { - enqueueSnackbar('Success Approve', { variant: 'success' }); - loadDataTableData(); - }) - .catch(({ response }) => { - enqueueSnackbar(response.data.message ?? 'Something went wrong!', { variant: 'error' }); - }); - }; + // Handel Delete Request LOG + const [idRequestLog, setidRequestLog] = useState(); + const [openDialogDeleteRequestLog, setDialogDeleteRequestLog] = useState(false) useEffect(() => { loadDataTableData(); @@ -347,7 +341,7 @@ export default function List() { const { row } = props; const [open, setOpen] = React.useState(false); const [loadingApprove, setLoadingApprove] = React.useState(false); - + return ( *': { borderBottom: 'unset' } }}> @@ -390,6 +384,14 @@ export default function List() { Detail + { + setidRequestLog(row.id) + setDialogDeleteRequestLog(true) + }} + > + + Delete + } /> @@ -548,28 +550,6 @@ export default function List() { } // --------------------------------------------------------- - // Dialog Detail Claim Request - const [openDialogDetailClaim, setOpenDialogDetailClaim] = useState(false); - const [loadingClaimDetail, setLoadingClaimDetail] = useState(true); - const [currentClaim, setCurrentClaim] = useState(null); - - function handleShowClaim(claimRequest) { - setLoadingClaimDetail(true); - setOpenDialogDetailClaim(true); - - axios - .get(`/claim-requests/${claimRequest.id}`) - .then(({ data }) => { - setCurrentClaim(data.data); - setLoadingClaimDetail(false); - }) - .catch((err) => { - enqueueSnackbar(err.message, { variant: 'error' }); - }); - } - - function handleDownloadLog() {} - return ( @@ -586,12 +566,12 @@ export default function List() { /> - + {/* Dialog Delete */} + );