diff --git a/Modules/Internal/Http/Controllers/Api/CorporateController.php b/Modules/Internal/Http/Controllers/Api/CorporateController.php index 6eb07399..394d5d2b 100644 --- a/Modules/Internal/Http/Controllers/Api/CorporateController.php +++ b/Modules/Internal/Http/Controllers/Api/CorporateController.php @@ -23,10 +23,19 @@ class CorporateController extends Controller * Display a listing of the resource. * @return Renderable */ - public function index() + public function index(Request $request) { $corporates = Corporate::query() - ->paginate(0); + ->when($request->search, function ($query, $search) { + return $query->where('name', 'LIKE', '%'.$search.'%'); + }) + ->with('currentPolicy') + ->withCount([ + 'employees', + 'corporatePlans', + 'corporateBenefits' + ]) + ->paginate(2); return $corporates; } diff --git a/frontend/client-portal/src/pages/Members/List.tsx b/frontend/client-portal/src/pages/Members/List.tsx index 07bd9c79..38b825c6 100644 --- a/frontend/client-portal/src/pages/Members/List.tsx +++ b/frontend/client-portal/src/pages/Members/List.tsx @@ -1,5 +1,5 @@ // @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, Pagination } 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, Pagination, 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'; @@ -174,7 +174,7 @@ export default function List() { // Generate the every row of the table function Row(props: { row: ReturnType }) { const { row } = props; - const [open, setOpen] = React.useState(false); + const [open, setOpen] = React.useState(true); return ( @@ -203,7 +203,7 @@ export default function List() { - Description : {row.description} + diff --git a/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx b/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx index bae56f71..a7191de0 100644 --- a/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx +++ b/frontend/dashboard/src/layouts/dashboard/navbar/NavConfig.tsx @@ -53,7 +53,7 @@ const navConfig = [ openWhen: ['/corporates', '/formularium', '/diagnosis', '/hospitals'], children: [ { title: 'Corporate', path: '/corporates' }, - { title: 'Corporate Create', path: '/corporates/create' }, + // { title: 'Corporate Create', path: '/corporates/create' }, { title: 'Formularium', path: '/master/formularium' }, { title: 'Obat', path: '/master/drugs' }, { title: 'Diagnosis Library (ICD-X)', path: '/master/diagnosis' }, diff --git a/frontend/dashboard/src/pages/Corporates/Index.tsx b/frontend/dashboard/src/pages/Corporates/Index.tsx index c73bcffa..c9be9bae 100644 --- a/frontend/dashboard/src/pages/Corporates/Index.tsx +++ b/frontend/dashboard/src/pages/Corporates/Index.tsx @@ -10,15 +10,18 @@ import useSettings from '../../hooks/useSettings'; import Page from '../../components/Page'; import axios from '../../utils/axios'; import useAuth from '../../hooks/useAuth'; -import { Link , NavLink as RouterLink } from 'react-router-dom'; -import React, { useEffect, useRef } from 'react'; +import { Link , NavLink as RouterLink, useSearchParams } from 'react-router-dom'; +import React, { ChangeEvent, useEffect, useRef, useState } from 'react'; import { Theme, useTheme } from '@mui/material/styles'; import { Corporate } from '../../@types/corporates'; import { LaravelPaginatedData } from '../../@types/paginated-data'; import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs'; +import BasePagination from '../../components/BasePagination'; +import { fCurrency } from '../../utils/formatNumber'; export default function Corporates() { const { themeStretch } = useSettings(); + const [searchParams, setSearchParams] = useSearchParams(); // Called on every row to map the data to the columns function createData( corporate: Corporate ): Corporate { @@ -27,79 +30,6 @@ export default function Corporates() { } } - // Generate the every row of the table - function Row(props: { row: ReturnType }) { - const { row } = props; - const [open, setOpen] = React.useState(false); - - return ( - - *': { borderBottom: 'unset' } }}> - - setOpen(!open)} - > - {open ? : } - - - {row.code} - {row.name} - - - - - - - - - {/* COLLAPSIBLE ROW */} - - - - - - History - - - - - Date - Customer - Amount - Total price ($) - - - - {row.history ? row.history.map((historyRow) => ( - - - {historyRow?.date} - - {historyRow?.customerId} - {historyRow?.amount} - - {Math.round(historyRow?.amount * 1000 * 100) / 100} - - - )) - : ( - - No Data - - ) - } - -
-
-
-
-
-
- ); - } - // Dummy Default Data const [dataTableIsLoading, setDataTableLoading] = React.useState(true); const [dataTableData, setDataTableData] = React.useState({ @@ -117,19 +47,34 @@ export default function Corporates() { total: 0 }); - const loadDataTableData = async () => { + const loadDataTableData = async (appliedFilter : any | null = null) => { setDataTableLoading(true); - const response = await axios.get('/corporates'); + const filter = appliedFilter ? appliedFilter : Object.fromEntries([...searchParams.entries()]); + const response = await axios.get('/corporates', { params: filter }); // console.log(response.data); setDataTableLoading(false); setDataTableData(response.data); } + + const applyFilter = async (searchFilter: any) => { + await loadDataTableData({ "search" : searchFilter }); + setSearchParams({ "search" : searchFilter }); + } + + const handlePageChange = (event : ChangeEvent, value: number) => { + const filter = Object.fromEntries([...searchParams.entries(), ["page", value]]); + loadDataTableData(filter); + setSearchParams(filter); + } + + useEffect(() => { loadDataTableData(); }, []) + const headStyle = { fontWeight: 'bold', }; @@ -187,31 +132,33 @@ export default function Corporates() { }; // END FILTER SELECT - // IMPORT - const importMember = React.useRef(null); - const handleImportButton = (event: any) => { - if (importMember?.current) - importMember.current ? importMember.current.click() : console.log('fuck'); - else - alert('No file selected') - } + // Component Search Input + function SearchInput(props: any) { + // SEARCH + const searchInput = useRef(null); + const [searchText, setSearchText] = useState(""); - return ( - - - + const handleSearchChange = (event: any) => { + const newSearchText = event.target.value ?? '' + setSearchText(newSearchText); + } - - + const handleSubmit = (event: any) => { + event.preventDefault(); + props.onSearch(searchText); // Trigger to Parent + } + + useEffect(() => { + // console.log('Search Input: useEffect') + setSearchText(searchParams.get('search') ?? ''); + }, [searchParams]) + + return ( +
+ + + + {/* @@ -263,9 +210,9 @@ export default function Corporates() { ))} - + */} - + {/* */} {/* + + ); + } + + // Component Row + // Generate the every row of the table + function Row(props: { row: ReturnType }) { + const { row } = props; + const [open, setOpen] = React.useState(false); + + return ( + + *': { borderBottom: 'unset' } }}> + + setOpen(!open)} + > + {open ? : } + + + {row.code} + {row.name} + + + + + + + + + {/* COLLAPSIBLE ROW */} + + + + + Current Policy Detail + + + + + Policy Code + + + : {row.current_policy?.code} + + + + Number of Plan + + + : {row.corporate_plans_count} + + + + Number of Benefit + + + : {row.corporate_benefits_count} + + + + + + + + Period + + + : {row.current_policy?.start} - {row.current_policy?.end} + + + + Total Premi + + + : {row.current_policy ? fCurrency(row.current_policy?.total_premi) : '-'} + + + + Minimal Deposit + + + : {row.current_policy ? fCurrency(row.current_policy?.minimal_deposit_net) : '-'} + + + + + + Member Detail + + + + + Total Member + + + : {row.employees_count} + + + + + + + + Total Claim This Month + + + : 0 + + + + + + + + + + ); + } + + return ( + + + + + + {/* The Main Table */} @@ -285,8 +371,8 @@ export default function Corporates() { # Code Name - Status - Action + Status + Action {dataTableIsLoading ? @@ -314,6 +400,7 @@ export default function Corporates() { )} +