import * as React from 'react'; // import AlertCustomerDelete from 'sections/apps/customer/AlertCustomerDelete'; // import { useNavigate } from 'react-router'; import Loader from 'components/Loader' // import AddCustomer from 'sections/apps/customer/AddCustomer'; import { useState, Fragment } from 'react'; // import PlaceOutlinedIcon from '@mui/icons-material/PlaceOutlined'; // import EmailOutlinedIcon from '@mui/icons-material/EmailOutlined'; // import LocalPhoneOutlinedIcon from '@mui/icons-material/LocalPhoneOutlined'; // import AccessTimeOutlinedIcon from '@mui/icons-material/AccessTimeOutlined'; // import CustomerCard from 'sections/apps/customer/CustomerCard'; // import CustomerCardPage from 'pages/apps/customer/card'; import { DeleteFilled, NotificationOutlined } from '@ant-design/icons'; import { Empty } from 'antd'; import { Avatar, // AvatarGroup, Button, Box, // Button, Grid, Skeleton, Stack, // TextField, Chip, // TableSortLabel, Typography, // Divider, Table, TableCell, TableBody, TableHead, IconButton, Collapse, // Tabs, // Tab, Dialog, // DialogActions, DialogTitle, DialogContent, CircularProgress, // TableSortLabel, TableRow, Tooltip, // List, // ListItem, // ListItemIcon, FormControl, OutlinedInput, InputAdornment, Popper, ClickAwayListener, // Tooltip, // Badge, // Avatar } from '@mui/material'; // import { PopupTransition } from 'components/@extended/Transitions'; import { SearchOutlined } from '@ant-design/icons'; import { enqueueSnackbar } from 'notistack'; var utc = require('dayjs/plugin/utc') // import { useEffect, useState } from 'react'; import axios from 'axios'; import { useTheme } from '@mui/material/styles'; // import ListIcon from '@mui/icons-material/List'; // import CheckIcon from '@mui/icons-material/Check'; // import CloseIcon from '@mui/icons-material/Close'; // import TwoWheelerIcon from '@mui/icons-material/TwoWheeler'; import { // CloseOutlined, // // PlusOutlined, // ContactsOutlined, // EyeTwoTone, // MailOutlined, // PhoneOutlined, // // EditTwoTone, DeleteTwoTone, CheckCircleOutlined, MoreOutlined } from '@ant-design/icons'; import dayjs from 'dayjs'; dayjs.extend(utc) import { KeyboardArrowUp, KeyboardArrowDown } from '@mui/icons-material' import PropTypes from 'prop-types'; import TableContainer from '@mui/material/TableContainer'; import TablePagination from '@mui/material/TablePagination'; import TableSortLabel from '@mui/material/TableSortLabel'; import { visuallyHidden } from '@mui/utils'; import { useEffect } from 'react'; import MainCard from 'components/MainCard'; const Client = () => { let theme = useTheme(); const [rows, setRows] = useState([]); const [loading, setLoading] = useState(false); const [searchword, setSearchword] = useState(''); const [stafflist, setStafflist] = useState([]); useEffect(() => { if (localStorage.getItem('tenantid')) { fetchtable(localStorage.getItem('tenantid')) } }, []) useEffect(() => { if (searchword) { let arr = stafflist.filter((val) => { return (val.firstname.toLowerCase().includes(searchword.toLowerCase()) // || val.locationaddress.toLowerCase().includes(searchword.toLowerCase()) || val.contactno.toLowerCase().includes(searchword.toLowerCase()) // || val.productname.toString().toLowerCase().includes(searchword.toLowerCase()) || val.address.toString().toLowerCase().includes(searchword.toLowerCase()) // || val.staffname.toString().toLowerCase().includes(searchword.toLowerCase()) ) }) console.log(arr) setRows([...arr]) } else { setRows([...stafflist]) } }, [searchword]) const fetchtable = async (tid) => { setLoading(true) try { // await axios.get(`${process.env.REACT_APP_URL2}/orders/getordershiftsbystatus`) await axios.get(`${process.env.REACT_APP_URL}/customers/getbytid/?tenantid=${tid}`) .then((res) => { if (res.data.message === "Success") { let arr = [] res.data.details.map((val, i) => { arr = [...arr, { ...val, sno: i + 1 }]; }) // setArr(arr) setRows([...arr]) setStafflist([...arr]) console.log(res.data.Details) console.log(arr) setLoading(false) } }).catch((err) => { console.log(err) setLoading(false) enqueueSnackbar(err.message, { variant: 'error', anchorOrigin: { vertical: 'top', horizontal: 'right' }, autoHideDuration: 2000 }) }) } catch (err) { console.log(err); setLoading(false) } } function descendingComparator(a, b, orderBy) { if (b[orderBy] < a[orderBy]) { return -1; } if (b[orderBy] > a[orderBy]) { return 1; } return 0; } function getComparator(order, orderBy) { return order === 'desc' ? (a, b) => descendingComparator(a, b, orderBy) : (a, b) => -descendingComparator(a, b, orderBy); } // Since 2020 all major browsers ensure sort stability with Array.prototype.sort(). // stableSort() brings sort stability to non-modern browsers (notably IE11). If you // only support modern browsers you can replace stableSort(exampleArray, exampleComparator) // with exampleArray.slice().sort(exampleComparator) function stableSort(array, comparator) { const stabilizedThis = array.map((el, index) => [el, index]); stabilizedThis.sort((a, b) => { const order = comparator(a[0], b[0]); if (order !== 0) { return order; } return a[1] - b[1]; }); return stabilizedThis.map((el) => el[0]); } const headCells = [ { id: 'sno', disablePadding: true, label: '#', }, { id: 'tenantname', numeric: false, disablePadding: false, label: 'CLIENT', }, // { // id: 'orderid', // numeric: false, // disablePadding: false, // label: 'CONTACT', // }, { id: 'eventname', disablePadding: false, label: 'ADDRESS', }, { id: 'starttime1', disablePadding: false, label: 'LANDMARK', }, { id: 'starttime', disablePadding: false, label: 'CITY', }, // { // id: 'endtime', // disablePadding: false, // label: 'END TIME', // }, // { // id: 'staff', // numeric: false, // disablePadding: false, // label: 'STAFF', // }, // { // id: 'orderstatus', // disablePadding: false, // label: 'STATUS', // }, // { // id: 'orderstatus', // disablePadding: false, // label: 'Details', // } { id: 'orderstatus1', disablePadding: false, label: 'ACTION', } ]; function EnhancedTableHead(props) { const { // onSelectAllClick, order, orderBy, // numSelected, rowCount, onRequestSort } = props; const createSortHandler = (property) => (event) => { onRequestSort(event, property); }; return ( {/* 0 && numSelected < rowCount} checked={rowCount > 0 && numSelected === rowCount} onChange={onSelectAllClick} inputProps={{ 'aria-label': 'select all desserts', }} /> */} {headCells.map((headCell) => ( {headCell.label} {orderBy === headCell.id ? ( {order === 'desc' ? 'sorted descending' : 'sorted ascending'} ) : null} ))} ); } EnhancedTableHead.propTypes = { numSelected: PropTypes.number.isRequired, onRequestSort: PropTypes.func.isRequired, onSelectAllClick: PropTypes.func.isRequired, order: PropTypes.oneOf(['asc', 'desc']).isRequired, orderBy: PropTypes.string.isRequired, rowCount: PropTypes.number.isRequired, }; function EnhancedTable() { const [order, setOrder] = React.useState('asc'); const [orderBy, setOrderBy] = React.useState('calories'); const [selected, setSelected] = React.useState([]); const [page, setPage] = React.useState(0); // const [dense, setDense] = React.useState(false); const [rowsPerPage, setRowsPerPage] = React.useState(10); const [expandopen, setExpandopen] = useState(''); const [open, setOpen] = useState(''); // const [stafflog, setStafflog] = useState([]); // const [loading1, setLoading1] = useState(false); // const [currentshiftobj, setCurrentshiftobj] = useState({}); const [loading1, setLoading1] = useState(false); const [staffdetaillist, setStaffdetaillist] = useState([]); const [anchorEl, setAnchorEl] = React.useState(null); const [currentcustomerid, setCurrentcustomerid] = useState('') const handleClickAway = () => { setOpen(''); }; // const fetchstafflog = async (uid, sid) => { // setLoading1(true) // try { // await axios.get(`${process.env.REACT_APP_URL2}/staffs/get/stafflogbytid/?userid=${uid}&shiftid=${sid}`) // .then((res) => { // if (res.data.message === "Success") { // console.log(res.data.details) // setStafflog(res.data.details); // setLoading1(false) // } // }).catch((err) => { // console.log(err) // setLoading1(false) // }) // } catch (err) { // console.log(err); // setLoading1(false) // } // } const removeclient = async () => { setLoading(true) try { await axios.delete(`${process.env.REACT_APP_URL}/customers/delete/?customerid=${currentcustomerid}`) .then((res) => { if (res.data.status) { enqueueSnackbar("Deleted Successfully", { variant: 'success', anchorOrigin: { vertical: 'top', horizontal: 'right' }, autoHideDuration: 2000 }) setCurrentcustomerid('') fetchtable(localStorage.getItem('tenantid')) } setLoading(false) }).catch((err) => { console.log(err) setLoading(false) }) } catch (err) { console.log(err); setLoading(false) } } const fetchstafflist = async (oid) => { setLoading1(true) try { // await axios.get(`${process.env.REACT_APP_URL2}/orders/getorderprocessbyid?orderheaderid=${oid}`) await axios.get(`${process.env.REACT_APP_URL2}/client/orders/getorderprocessbyid?orderheaderid=${oid}`) .then((res) => { console.log(res) if (res.data.message === "Successful") { let arr = [] res.data.details.map((val, i) => { arr = [...arr, { ...val, sno: i + 1 }]; }) // setRows([...arr]) setStaffdetaillist([...arr]) // console.log(res.data.Details) // console.log(arr) // setLoading(false) } setLoading1(false) }).catch((err) => { console.log(err) setLoading1(false) }) } catch (err) { console.log(err); setLoading1(false) } } const staffearningsverify = async (sid) => { setLoading(true) try { // await axios.get(`${process.env.REACT_APP_URL2}/orders/getorderprocessbystatus`) await axios.put(`${process.env.REACT_APP_URL2}/staffs/earnings/update`, { "staffearningsid": sid, "verified": 1 }) // await axios.get(`${process.env.REACT_APP_URL2}/staffs/earnings/?fromdate=2023-09-07&todate=2023-09-09`) .then((res) => { console.log(res) if (res.data.status) { // let arr = [] // res.data.Details.map((val, i) => { // arr = [...arr, { ...val, sno: i + 1 }]; // }) // // setArr(arr) // setRows(arr) // console.log(res.data.Details) // console.log(arr) // setLoading(false) enqueueSnackbar("Updated Successfully", { variant: 'success', anchorOrigin: { vertical: 'top', horizontal: 'right' }, autoHideDuration: 2000 }) // setTimeout(() => { if (localStorage.getItem('appuserid')) { fetchtable(localStorage.getItem('appuserid')) } // }, 2000) } }).catch((err) => { console.log(err) setLoading(false) }) } catch (err) { console.log(err); setLoading(false) } } const handleRequestSort = (event, property) => { const isAsc = orderBy === property && order === 'asc'; setOrder(isAsc ? 'desc' : 'asc'); setOrderBy(property); }; const handleSelectAllClick = (event) => { if (event.target.checked) { const newSelected = rows.map((n) => n.name); setSelected(newSelected); return; } setSelected([]); }; const handleClick = (event, name) => { const selectedIndex = selected.indexOf(name); let newSelected = []; if (selectedIndex === -1) { newSelected = newSelected.concat(selected, name); } else if (selectedIndex === 0) { newSelected = newSelected.concat(selected.slice(1)); } else if (selectedIndex === selected.length - 1) { newSelected = newSelected.concat(selected.slice(0, -1)); } else if (selectedIndex > 0) { newSelected = newSelected.concat( selected.slice(0, selectedIndex), selected.slice(selectedIndex + 1), ); } setSelected(newSelected); }; const handleChangePage = (event, newPage) => { setPage(newPage); }; const handleChangeRowsPerPage = (event) => { setRowsPerPage(parseInt(event.target.value, 10)); setPage(0); }; // const handleChangeDense = (event) => { // setDense(event.target.checked); // }; const isSelected = (name) => selected.indexOf(name) !== -1; // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; const visibleRows = React.useMemo( () => stableSort(rows, getComparator(order, orderBy)).slice( page * rowsPerPage, page * rowsPerPage + rowsPerPage, ), [order, orderBy, page, rowsPerPage], ); const handleClose = () => { setOpen(false); }; function AlertCustomerDelete({ // title, open, handleClose }) { // const [deletepassword, setDeletepassword] = useState(''); return ( handleClose(false)} maxWidth="xs" > {/* */} Are you sure you want to Remove this Client? {/* Please type in the order number to confirm. */} {/* { console.log(e.target.value) setDeletepassword(e.target.value) }} error={deletepassword !== orderid.slice(4)} value={deletepassword} /> */} ); } return ( <> {loading && } {/* setOpen(false)} scroll={'paper'} TransitionComponent={PopupTransition}> Staff Details {(loading1) ? <> : <> {`${currentshiftobj.staffname}`} {currentshiftobj.productname} {(stafflog[0]) && <> +1 {stafflog[0].contactno} Hours Worked: {' '} {stafflog[0].hoursworked} Hrs } {(stafflog[0]) && <> Clock In: Clock Out: } {currentshiftobj.locationaddress} Start Time {dayjs(currentshiftobj.Starttime) .utc() .format('MM/DD/YYYY')} {dayjs(currentshiftobj.Starttime) .utc() .format('hh:mm A')} End Time {dayjs(currentshiftobj.Endtime) .utc() .format('MM/DD/YYYY')} {dayjs(currentshiftobj.Endtime) .utc() .format('hh:mm A')} } */} {(loading) && <> {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((item) => ( ))} } {((visibleRows.length == 0) && !loading) && <> {/*
empty
*/} } {visibleRows.map((row, index) => { const isItemSelected = isSelected(row.sno); const labelId = `enhanced-table-checkbox-${index}`; return ( <> handleClick(event, row.sno)} role="checkbox" aria-checked={isItemSelected} tabIndex={-1} key={row.sno} sx={{ cursor: 'pointer' }} > {/* */} {row.sno} {/* { if(!expandopen){ fetchstafflist(row.orderheaderid) } setExpandopen((expandopen === row.sno) ? '' : row.sno) }}> {(expandopen === row.sno) ? : } */} {/* */} {`${row.firstname} ${row.lastname}`} {/* {row.identification}*/} {row.contactno} {/* {row.contactno} */} {row.address} {/* {`${row.locationaddress.slice(0, 25)}${(row.locationaddress.length > 25)?'...':''}`} */} {row.landmark} {/* {dayjs(row.Endtime) // .utc() .format('MM/DD/YYYY')} {dayjs(row.Endtime) // .utc() .format('hh:mm A')} */} {/* {row.staffname} */} {row.city} {/* { fetchstafflist(row.orderheaderid) setExpandopen((expandopen === row.sno) ? '' : row.sno) }}> {(expandopen === row.sno) ? : } */} {/* */} {/* {(row.orderstatus === 'pending' ) && { }}> } { setCurrentshiftobj({ ...row }) console.log(row) setStafflog([]) fetchstafflog(row.Userid, row.shiftid) setOpen(true) }}> */} { setOpen(true) setCurrentcustomerid(row.customerid) }}> {/*
Contact Name Contact No {(row.ordercontacts.map((val) => { return <> {val.contactname} {val.contactno} })) }
*/} {(loading1) ? <> : # Staff Start Time End Time {/* Pay Rate */} {/* Category */} Clockin Clockout Actual Hrs Hrs Worked OT Deficit {/* Experience */} {/* Level */} {/* City */} Status Action {/* {row.ordeprocessInfo.map((val, i) => { */} {staffdetaillist.map((val, i) => { return res.userid == val.userid)) ? '#f5f5f5' : '', ':hover': { // backgroundColor: (staffarr.find((res) => res.userid == val.userid)) ? '#f5f5f5 !important' : '' // } }}> {i + 1} {val.staffname} {dayjs(val.starttime) // .utc() .format('MM/DD/YYYY')} {dayjs(val.starttime) // .utc() .format('hh:mm A')} {dayjs(val.endtime) // .utc() .format('MM/DD/YYYY')} {dayjs(val.endtime) // .utc() .format('hh:mm A')} {/* {val.rolecost} */} {val.workhours} {val.hoursworked} {val.overtime} {val.shorttime} {(val.orderstatus === 'pending') && } {(val.orderstatus === 'cancelled') && } {(val.orderstatus === 'completed') && } {(val.orderstatus === 'processing') && } {(val.orderstatus === 'assigned') && } {(val.orderstatus === 'confirmed') && } {(val.orderstatus === 'active') && } {(val.orderstatus === 'closed') && } {((val.verified == 0) && (val.orderstatus === 'completed')) && <> handleClick1(e, row.sno)} onClick={(e) => { setOpen(i + 1) setAnchorEl(e.currentTarget); }} aria-describedby={`aria-${row.sno}`} > { // setApproveid(true) // setDisableid(false) // setExpandopen('') // setRolestab(0) staffearningsverify(val.staffearningsid) // fetchclientbyid(row.tenantid, row.sno); // fetchclientpricing(row.tenantid) // setEditexpandopen(row.sno) handleClickAway() }} > Verify } {(val.verified == 1) && <> } }) }
} ); })} {emptyRows > 0 && ( )}
); } return <> Clients } aria-describedby="header-search-text" inputProps={{ 'aria-label': 'weight' }} placeholder="Search" value={searchword} onChange={(e) => { setSearchword(e.target.value) }} autoComplete='off' /> } export default Client;