diff --git a/Modules/Internal/Http/Controllers/Api/CorporateController.php b/Modules/Internal/Http/Controllers/Api/CorporateController.php index 835e948f..ccee8cc7 100755 --- a/Modules/Internal/Http/Controllers/Api/CorporateController.php +++ b/Modules/Internal/Http/Controllers/Api/CorporateController.php @@ -38,6 +38,8 @@ class CorporateController extends Controller ->withCount([ 'employees', 'corporateBenefits', + 'corporatePlans', + // 'claims' ]) ->where('type', 'corporate') @@ -141,7 +143,7 @@ class CorporateController extends Controller 'description' => 'Optical', ], ]; - + foreach ($services as $service) { $corporateService = $newCorporate->corporateServices()->create([ @@ -236,11 +238,11 @@ class CorporateController extends Controller public function show($id) { $corporate = Corporate::query() - ->with(['currentPolicy']) - ->withCount('corporatePlans') - ->withCount('employees') - // ->withCount('employees.claims') - ->findOrFail($id); + ->with(['currentPolicy']) + ->withCount('corporatePlans') + ->withCount('employees') + // ->withCount('employees.claims') + ->findOrFail($id); return response()->json($corporate); } diff --git a/Modules/Internal/Http/Controllers/Api/CorporatePlanController.php b/Modules/Internal/Http/Controllers/Api/CorporatePlanController.php index 1fb51643..23e016a7 100755 --- a/Modules/Internal/Http/Controllers/Api/CorporatePlanController.php +++ b/Modules/Internal/Http/Controllers/Api/CorporatePlanController.php @@ -17,14 +17,33 @@ class CorporatePlanController extends Controller public function index(Request $request, $corporate_id) { $benefits = CorporatePlan::query() - ->filter($request->all()) - ->where('corporate_id', $corporate_id) - ->paginate(0) - ->appends($request->all()); - + ->filter($request->all()) + ->where('corporate_id', $corporate_id) + ->paginate(0) + ->appends($request->all()); + return $benefits; } + public function activation(Request $request, $plan_id) + { + $request->validate([ + 'active' => 'required' + ]); + + // abort(404); + + $plan = CorporatePlan::findOrFail($plan_id); + $plan->active = $request->active == '1'; + + if ($plan->save()) { + return response()->json([ + 'plan' => $plan, + 'message' => 'Status Updated Successfully' + ]); + } + } + /** * Show the form for creating a new resource. * @return Renderable diff --git a/Modules/Internal/Routes/api.php b/Modules/Internal/Routes/api.php index a4aef83d..741d4f5d 100755 --- a/Modules/Internal/Routes/api.php +++ b/Modules/Internal/Routes/api.php @@ -56,6 +56,7 @@ Route::prefix('internal')->group(function () { Route::post('corporates/{corporate_id}/corporate-plans', [CorporatePlanController::class, 'store']); Route::get('corporates/{corporate_id}/corporate-plans/{id}/edit', [CorporatePlanController::class, 'edit']); Route::put('corporates/{corporate_id}/corporate-plans/{id}', [CorporatePlanController::class, 'update']); + Route::put('plans/{plan_id}/activation', [CorporatePlanController::class, 'activation']); Route::get('corporates/{corporate_id}/plans', [PlanController::class, 'index']); Route::post('corporates/{corporate_id}/plans/import', [PlanController::class, 'planImport']); diff --git a/app/Models/CorporatePlan.php b/app/Models/CorporatePlan.php index aa5ae22e..7ecd18de 100755 --- a/app/Models/CorporatePlan.php +++ b/app/Models/CorporatePlan.php @@ -11,6 +11,8 @@ class CorporatePlan extends Model { use HasFactory, SoftDeletes, Blameable; + protected $table = 'plans'; + protected $fillable = [ 'corporate_id', 'code', @@ -28,8 +30,8 @@ class CorporatePlan extends Model { $query->when($filters['search'] ?? false, function ($query, $search) { return $query - ->where('code', 'like', "%" . $search . "%") - ->orWhere('name', 'like', "%" . $search . "%"); + ->where('code', 'like', "%" . $search . "%") + ->orWhere('name', 'like', "%" . $search . "%"); }); } } diff --git a/database/migrations/2022_12_19_171824_add_active_to_plans_table.php b/database/migrations/2022_12_19_171824_add_active_to_plans_table.php new file mode 100644 index 00000000..c80f2d0c --- /dev/null +++ b/database/migrations/2022_12_19_171824_add_active_to_plans_table.php @@ -0,0 +1,32 @@ +boolean('active')->after('max_surgery_periode_days'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('plans', function (Blueprint $table) { + $table->dropColumn('active'); + }); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 2385d392..22acb740 100755 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -15,7 +15,7 @@ class DatabaseSeeder extends Seeder public function run() { // \App\Models\User::factory(10)->create(); - + $this->call([ DummyMemberSeeder::class, DrugSeeder::class, @@ -25,7 +25,9 @@ class DatabaseSeeder extends Seeder ProvinceSeeder::class, CitySeeder::class, DistrictSeeder::class, - VillageSeeder::class + VillageSeeder::class, + OrganizationSeeder::class, + PractitionerSeeder::class, ]); } } diff --git a/frontend/dashboard/src/pages/Corporates/Index.tsx b/frontend/dashboard/src/pages/Corporates/Index.tsx index 6f99353a..3d22df70 100755 --- a/frontend/dashboard/src/pages/Corporates/Index.tsx +++ b/frontend/dashboard/src/pages/Corporates/Index.tsx @@ -403,10 +403,7 @@ export default function Corporates() { Corporate Limit - :{' '} - {row.current_policy - ? fCurrency(row.current_policy?.limit_balance) - : '-'} + : {row.current_policy ? fCurrency(row.current_policy?.limit_balance) : '-'} @@ -437,7 +434,7 @@ export default function Corporates() { - Sub Corporate + {/* Sub Corporate @@ -449,7 +446,7 @@ export default function Corporates() { - + */} diff --git a/frontend/dashboard/src/pages/Corporates/Plan/List.tsx b/frontend/dashboard/src/pages/Corporates/Plan/List.tsx index 81783e6a..83d4e89c 100755 --- a/frontend/dashboard/src/pages/Corporates/Plan/List.tsx +++ b/frontend/dashboard/src/pages/Corporates/Plan/List.tsx @@ -1,5 +1,33 @@ // @mui -import { Box, Button, Card, Collapse, IconButton, InputLabel, MenuItem, OutlinedInput, Paper, Select, SelectChangeEvent, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography, Badge, Tab, Tabs, CardHeader, Stack, Menu, ButtonGroup } from '@mui/material'; +import { + Box, + Button, + Card, + Collapse, + IconButton, + InputLabel, + MenuItem, + OutlinedInput, + Paper, + Select, + SelectChangeEvent, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + TextField, + Typography, + Badge, + Tab, + Tabs, + CardHeader, + Stack, + Menu, + ButtonGroup, + Grid, +} from '@mui/material'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight'; import AddIcon from '@mui/icons-material/Add'; @@ -21,30 +49,38 @@ export default function CorporatePlanList() { const { corporate_id } = useParams(); const [searchParams, setSearchParams] = useSearchParams(); const [importResult, setImportResult] = useState(null); - + function SearchInput(props: any) { - // SEARCH + // SEARCH const searchInput = useRef(null); - const [searchText, setSearchText] = useState(""); + const [searchText, setSearchText] = useState(''); const handleSearchChange = (event: any) => { - const newSearchText = event.target.value ?? '' + const newSearchText = event.target.value ?? ''; setSearchText(newSearchText); - } + }; const handleSubmit = (event: any) => { event.preventDefault(); props.onSearch(searchText); // Trigger to Parent - } + }; - useEffect(() => { + useEffect(() => { // console.log('Search Input: useEffect') setSearchText(searchParams.get('search') ?? ''); - }, [searchParams]) + }, [searchParams]); return (
- + ); } @@ -54,8 +90,8 @@ export default function CorporatePlanList() { // Create Button Menu const [anchorEl, setAnchorEl] = React.useState(null); const createMenu = Boolean(anchorEl); - const importPlan = useRef(null) - const [currentImportFileName, setCurrentImportFileName] = useState(null) + const importPlan = useRef(null); + const [currentImportFileName, setCurrentImportFileName] = useState(null); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); @@ -70,52 +106,66 @@ export default function CorporatePlanList() { handleClose(); importPlan.current ? importPlan.current.click() : console.log('No File selected'); } else { - alert('No file selected') + alert('No file selected'); } - } + }; const handleCancelImportButton = () => { - importPlan.current.value = ""; - importPlan.current.dispatchEvent(new Event("change", { bubbles: true })); - } + importPlan.current.value = ''; + importPlan.current.dispatchEvent(new Event('change', { bubbles: true })); + }; const handleImportChange = (event: any) => { if (event.target.files[0]) { - setCurrentImportFileName(event.target.files[0].name) + setCurrentImportFileName(event.target.files[0].name); } else { setCurrentImportFileName(null); } - } + }; const handleUpload = () => { if (importPlan.current?.files.length) { const formData = new FormData(); - formData.append("file", importPlan.current?.files[0]) - axios.post(`corporates/${corporate_id}/import-plan-benefit`, formData ) - .then(response => { + formData.append('file', importPlan.current?.files[0]); + axios + .post(`corporates/${corporate_id}/import-plan-benefit`, formData) + .then((response) => { handleCancelImportButton(); loadDataTableData(); - setImportResult(response.data) + setImportResult(response.data); // alert('Succesfully read '+ response.data.total_successed_row + ' with ' + response.data.total_failed_row + ' failed rows'); }) - .catch(response => { - enqueueSnackbar('Looks like something went wrong. Please check your data and try again. ' + response.message, { variant: 'error' }) - }) + .catch((response) => { + enqueueSnackbar( + 'Looks like something went wrong. Please check your data and try again. ' + + response.message, + { variant: 'error' } + ); + }); } else { - enqueueSnackbar('No File Selected', { variant: 'warning' }) + enqueueSnackbar('No File Selected', { variant: 'warning' }); } - } - + }; + return (
- - {( !currentImportFileName && - - {/*

kjasndkjandskjasndkjansdkjansd

*/} - - - + {currentImportFileName && ( + + + + + - - + +
)} - {( importResult && - - Last Import Result Report : {importResult.result_file?.name ?? "-"} - + {importResult && ( + + + Last Import Result Report :{' '} + + {importResult.result_file?.name ?? '-'} + + + )}
); } // Called on every row to map the data to the columns - function createData( plan: Plan ): Plan { + function createData(plan: Plan): Plan { return { ...plan, - } + }; } // Generate the every row of the table @@ -175,15 +241,38 @@ export default function CorporatePlanList() { const { row } = props; const [open, setOpen] = React.useState(false); + const handleActivate = (model: any, status: string) => { + axios + .put(`/plans/${row.id}/activation`, { + // service_code: service.service_code, + active: status == 'active', + }) + .then((res) => { + setDataTableData({ + ...dataTableData, + data: dataTableData.data.map((model) => { + let updatedModel = model; + if (row.id == model.id) { + updatedModel.active = res.data.plan.active; + } + return updatedModel; + }), + }); + }) + .catch((error) => { + // console.log('asdasd', error.response.data.message) + enqueueSnackbar( + error.response.data.message ?? error.message ?? 'Failed Processing Request', + { variant: 'error' } + ); + }); + }; + return ( *': { borderBottom: 'unset' } }}> - setOpen(!open)} - > + setOpen(!open)}> {open ? : } @@ -191,93 +280,321 @@ export default function CorporatePlanList() { {row.corporate_plan_id} {row.code} {row.type} - {row.start} - {row.end} - {row.require_referral} - {row.referral_source} - {row.referral_duration} - {row.family_plan} - {row.family_plan_share_rules} + {row.limit_rules} - {row.layer} - {row.layer_conditions} - {row.budget_type} - {row.budget_code} - {row.budget_conditions} - {row.surgery_limit} - {row.non_surgery_limit} - {row.max_claim_limit} - {row.max_claim_count} - {row.area_limit} - {row.limit_shared_plans} - {row.limit_shared_plan_type} - {row.cashless_percentage} - {row.reimbursement_percentage} - {row.digital_percentage} - {row.co_share_m_percentage} - {row.co_share_s_percentage} - {row.co_share_c_percentage} - {row.cashless_deductible} - {row.reimbursement_deductible} - {row.digital_deductible} - {row.co_share_m_deductible} - {row.co_share_s_deductible} - {row.co_share_c_deductible} - {row.co_share_deductible_condition} - {row.msc} - {row.genders} - {row.min_age} - {row.max_age} - {row.rule_of_excess} - {row.max_excess_covered} - {row.prorate_type} - {row.prorate_lookup} - {row.currency} - {row.max_surgery_reinstatement_days} - {row.max_surgery_periode_days} - - + + + {row.active == 1 && ( + + )} + {row.active != 1 && ( + + )} + + + + {/* COLLAPSIBLE ROW */} - + - - - No Extra Data - + + + + + + Start + + + : {row.start ? row.start : '-'} + + + End + + + : {row.end ? row.end : '-'} + + + Referal + + + : {row.require_referral ? row.require_referral : '-'} + + + Referral Source + + + : {row.referral_source ? row.referral_source : '-'} + + + Referral Duration + + + : {row.referral_duration ? row.referral_duration : '-'} + + + Family Plan + + + : {row.family_plan ? row.family_plan : '-'} + + + Family Sharing Overflow + + + : {row.family_plan_share_rules ? row.family_plan_share_rules : '-'} + + + Max/Claim + + + : {row.max_claim_limit ? row.max_claim_limit : '-'} + + + Max Count of Claim + + + : {row.max_claim_count ? row.max_claim_count : '-'} + + + Area + + + : {row.area_limit ? row.area_limit : '-'} + + + Shared Plan + + + : {row.limit_shared_plans ? row.limit_shared_plans : '-'} + + + Limit Shared Type + + + : {row.limit_shared_plan_type ? row.limit_shared_plan_type : '-'} + + + Cashless(%) + + + : {row.cashless_percentage ? row.cashless_percentage : '-'} + + + Reimbursement(%) + + + : {row.reimbursement_percentage ? row.reimbursement_percentage : '-'} + + + Digital(%) + + + : {row.digital_deductible ? row.digital_deductible : '-'} + + + CoShare M(%) + + + : {row.co_share_m_percentage ? row.co_share_m_percentage : '-'} + + + CoShare S(%) + + + : {row.co_share_s_percentage ? row.co_share_s_percentage : '-'} + + + CoShare C(%) + + + : {row.co_share_c_percentage ? row.co_share_c_percentage : '-'} + + + Cashless Deductible + + + : {row.cashless_deductible ? row.cashless_deductible : '-'} + + + Reimbursement Deductible + + + : {row.reimbursement_deductible ? row.reimbursement_deductible : '-'} + + + Digital Deductible + + + : {row.digital_deductible ? row.digital_deductible : '-'} + + + + + + + Layer ID + + + : {row.layer ? row.layer : '-'} + + + Layer Condition + + + : {row.layer_conditions ? row.layer_conditions : '-'} + + + Budget Type + + + : {row.budget_type ? row.budget_type : '-'} + + + Budget Code + + + : {row.budget_code ? row.budget_code : '-'} + + + Budget Condition + + + : {row.budget_conditions ? row.budget_conditions : '-'} + + + Surgery + + + : {row.surgery_limit ? row.surgery_limit : '-'} + + + Non Surgery + + + : {row.non_surgery_limit ? row.non_surgery_limit : '-'} + + + DeductibleM + + + : {row.co_share_m_deductible ? row.co_share_m_deductible : '-'} + + + DeductibleS + + + : {row.co_share_s_deductible ? row.co_share_s_deductible : '-'} + + + DeductibleC + + + : {row.co_share_c_deductible ? row.co_share_c_deductible : '-'} + + + CoShare & Deductible Condition + + + : + {row.co_share_deductible_condition + ? row.co_share_deductible_condition + : '-'} + + + MSC + + + : {row.msc ? row.msc : '-'} + + + Gender + + + : {row.genders ? row.genders : '-'} + + + Min Age + + + : {row.min_age ? row.min_age : '-'} + + + Max Age + + + : {row.max_age ? row.max_age : '-'} + + + Rule of Excess + + + : {row.rule_of_excess ? row.rule_of_excess : '-'} + + + Max Excess Covered + + + : {row.max_excess_covered ? row.max_excess_covered : '-'} + + + Prorate Type + + + : {row.prorate_type ? row.prorate_type : '-'} + + + Prorate Lookup + + + : {row.prorate_lookup ? row.prorate_lookup : '-'} + + + Currency + + + : {row.currency ? row.currency : '-'} + + + Reinstatement Surgery + + + : + {row.max_surgery_reinstatement_days + ? row.max_surgery_reinstatement_days + : '-'} + + + Period of Surgery + + + : {row.max_surgery_periode_days ? row.max_surgery_periode_days : '-'} + + + + - {false && - - Rules - - - - - Date - Customer - Amount - Total price ($) - - - - {/* {row.history ? row.history.map((historyRow) => ( */} - - {row.start} - {row.end} - {row.start} - {row.start} - {row.start} - - {/* )) - : ( - - No Data - - ) - } */} - -
-
}
@@ -290,138 +607,109 @@ export default function CorporatePlanList() { const [dataTableData, setDataTableData] = React.useState({ current_page: 1, data: [], - path: "", - first_page_url: "", + path: '', + first_page_url: '', last_page: 1, - last_page_url: "", - next_page_url: "", - prev_page_url: "", + last_page_url: '', + next_page_url: '', + prev_page_url: '', per_page: 10, from: 0, to: 0, - total: 0 + total: 0, }); const loadDataTableData = async (appliedFilter = null) => { setDataTableLoading(true); const filter = appliedFilter ? appliedFilter : Object.fromEntries([...searchParams.entries()]); - const response = await axios.get('/corporates/'+corporate_id+'/plans', { params: filter }); + const response = await axios.get('/corporates/' + corporate_id + '/plans', { params: filter }); // console.log(response.data); setDataTableLoading(false); setDataTableData(response.data); - } + }; const headStyle = { fontWeight: 'bold', }; const applyFilter = async (searchFilter: string) => { - await loadDataTableData({ "search" : searchFilter }); - setSearchParams({ "search" : searchFilter }); - } + await loadDataTableData({ search: searchFilter }); + setSearchParams({ search: searchFilter }); + }; - const handlePageChange = (event : ChangeEvent, value: number) => { - const filter = Object.fromEntries([...searchParams.entries(), ["page", value]]); + const handlePageChange = (event: ChangeEvent, value: number) => { + const filter = Object.fromEntries([...searchParams.entries(), ['page', value]]); loadDataTableData(filter); setSearchParams(filter); - } + }; useEffect(() => { loadDataTableData(); - }, []) - + }, []); + return ( - + {/* The Main Table */} - Service - Plan - Code - Type - Start - End - Referral - Referral Source - Referral Duration - Family Plan - Family Sharing Overflow - Plan Limit - Layer ID - Layer Condition - Budget Type - Budget Code - Budget Condition - Surgery - Non Surgery - Max/Claim - Max Count of Claim - Area - Shared Plan - Limit Shared Type - Cashless(%) - Reimbursement(%) - Digital(%) - CoShare M(%) - CoShare S(%) - CoShare C(%) - Cashless Deductible - Reimbursement Deductible - Digital Deductible - DeductibleM - DeductibleS - DeductibleC - CoShare & Deductible Condition - MSC - Gender - Min Age - Max Age - Rule of Excess - Max Excess Covered - Prorate Type - Prorate Lookup - Currency - Reinstatement Surgery - Period of Surgery - Status - Action + + Service + + + Plan + + + Code + + + Type + + + Plan Limit + + + Status + + + Action + - {dataTableIsLoading ? - ( - - - Loading - - - ) : ( - dataTableData.data.length == 0 ? - ( - - - No Data - - - ) : ( - - {dataTableData.data.map(row => ( - - ))} - - ) + {dataTableIsLoading ? ( + + + + Loading + + + + ) : dataTableData.data.length == 0 ? ( + + + + No Data + + + + ) : ( + + {dataTableData.data.map((row) => ( + + ))} + )}
- - -
+ + +
); }