From 4d2ebeb41c02d45b9582a9eaf0b4ddf74e858bd1 Mon Sep 17 00:00:00 2001 From: joshikannan Date: Wed, 13 Mar 2024 19:58:02 +0530 Subject: [PATCH] createorder --- src/pages/nearle/orders/createorder.js | 1502 ----------------------- src/pages/nearle/orders/createorder1.js | 268 ++-- src/pages/nearle/orders/orders.js | 2 +- src/routes/MainRoutes.js | 10 +- 4 files changed, 193 insertions(+), 1589 deletions(-) delete mode 100644 src/pages/nearle/orders/createorder.js diff --git a/src/pages/nearle/orders/createorder.js b/src/pages/nearle/orders/createorder.js deleted file mode 100644 index de058cf..0000000 --- a/src/pages/nearle/orders/createorder.js +++ /dev/null @@ -1,1502 +0,0 @@ -import { - FormControl, - InputAdornment, - Grid, - Typography, - Stack, - Box, - // Autocomplete, - Button, - // Stepper, - // Step, - // StepLabel, - TextField, - Autocomplete, - CardActions, - // CardActions, - Chip, - // AvatarGroup, - // RadioGroup, - // Radio - Avatar, - // List, - // ListItem, - // IconButton, - // ListItemAvatar, - // ListItemText, - // Menu, - // MenuItem, - // ListItemIcon, - // Link, - Divider, - Table, - TableContainer, - TableRow, - TableCell, - TableHead, - TableBody, - // FormLabel, - Tooltip, - DialogTitle, - DialogContent, - Checkbox, - DialogActions, - CircularProgress, - ButtonGroup, - FormLabel, - IconButton - // LinkOutlined -} from '@mui/material'; -import { useNavigate } from 'react-router'; -import CheckCircleIcon from '@mui/icons-material/CheckCircle'; -import AccessTimeOutlinedIcon from '@mui/icons-material/AccessTimeOutlined'; -import { PopupTransition } from 'components/@extended/Transitions'; -// var utc = require('dayjs/plugin/utc') - -import axios from 'axios'; -import { useTheme } from '@mui/material/styles'; -// import { usePlacesWidget } from "react-google-autocomplete"; -import Geocode from 'react-geocode'; -// import {setApi} from "react-geocode"; -import Autocomplete1 from 'react-google-autocomplete'; -// import logo from 'assets/images/location.png' -import Loader from 'components/Loader'; - -import { - // EditOutlined, - PlusOutlined, - SearchOutlined -} from '@ant-design/icons'; - -import { DeleteOutlined } from '@ant-design/icons'; - -import MainCard from 'components/MainCard'; -import { - EnvironmentOutlined - // LinkOutlined, - // MailOutlined, - // MoreOutlined, - // PhoneOutlined -} from '@ant-design/icons'; -import CheckCircleRoundedIcon from '@mui/icons-material/CheckCircleRounded'; -// import VisibilityIcon from '@mui/icons-material/Visibility'; -// import AccessTimeFilledIcon from '@mui/icons-material/AccessTimeFilled'; -// import EditCalendarIcon from '@mui/icons-material/EditCalendar'; -import AccessibilityNewIcon from '@mui/icons-material/AccessibilityNew'; - -// import { PatternFormat } from 'react-number-format'; -import { DatePicker } from '@mui/x-date-pickers/DatePicker'; -import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; -import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; -import { TimePicker } from '@mui/x-date-pickers/TimePicker'; - -// import DialogTitle from '@mui/material/DialogTitle'; -import Dialog from '@mui/material/Dialog'; -import { - useEffect, - useState, - Fragment - // useReducer -} from 'react'; -// import { Label } from '@mui/icons-material'; -import dayjs from 'dayjs'; -// import { useDispatch } from 'react-redux'; -// import { openSnackbar, closeSnackbar } from 'store/reducers/snackbar'; -// import {Autocompletemap} from 'pages/autocompletemap' -import { enqueueSnackbar } from 'notistack'; -// import { CheckBox } from '@mui/icons-material'; -// dayjs.extend(utc) -var utc = require('dayjs/plugin/utc'); -dayjs.extend(utc); - -const Createorder = () => { - Geocode.setApiKey(process.env.REACT_APP_GOOGLE_MAPS_API_KEY); - - const navigate = useNavigate(); - const [open, setOpen] = useState({}); - const [open1, setOpen1] = useState(''); - const [open2, setOpen2] = useState(false); - const [open3, setOpen3] = useState(false); - - const [shift, setShift] = useState(1); - const [clientlist, setClientlist] = useState([]); - const [clientdetail, setClientdetail] = useState([]); - const [eventname, setEventname] = useState(''); - - const [startdate, setStartdate] = useState(dayjs().format('MM-DD-YYYY')); - const [enddate, setEnddate] = useState(dayjs().add(1, 'day').format('MM-DD-YYYY')); - const [starttime, setStatrttime] = useState(`${dayjs().format('MM-DD-YYYY')} 08:00:00`); - const [endtime, setEndtime] = useState(`${dayjs().format('MM-DD-YYYY')} 20:00:00`); - - const [timeslotarr, setTimeslotarr] = useState([]); - const [currentsno, setCurrentsno] = useState(''); - - const [roleoptions, setRoleoptions] = useState([]); - - const theme = useTheme(); - - const [otherinstructions, setOtherinstructions] = useState(''); - - const [attireslist, setAttireslist] = useState([]); - const [serviceaddonslist, setServiceaddonslist] = useState([]); - const [orderaddonobj, setOrderaddonobj] = useState([]); - - const [stafflist, setStafflist] = useState([]); - const [loading2, setLoading2] = useState(false); - const [loading, setLoading] = useState(false); - - const [shiftarr, setShiftarr] = useState([]); - const [shiftarr1, setShiftarr1] = useState([]); - - const [orderarr, setOrderarr] = useState([]); - - const [alertmessage, setAlertmessage] = useState(''); - const [tabstatus, setTabstatus] = useState(''); - const [tenantinfo, setTenantinfo] = useState({}); - const [searchword, setSearchword] = useState(''); - const [clientdetailarr, setClientdetailarr] = useState([]); - const [admintoken, setAdmintoken] = useState(''); - const [tenantlocationlist, setTenantlocationlist] = useState([]); - const [tenant, setTenant] = useState({}); - - useEffect(() => { - if (localStorage.getItem('tenantid')) { - // setOrderarr([{ - // sno: 1, - // address: '', - // "customerid": '', - // "deliverytime": dayjs(), - // "deliverylocationid": '', - // "clientname": '', - // "contactno": '', - // "latitude": '', - // "longitude": '' - // }]) - // console.log(dayjs()) - fetchtenantlocation(localStorage.getItem('tenantid')); - clientdetails(localStorage.getItem('tenantid')); - } - }, []); - - useEffect(() => { - if (timeslotarr[0]) { - let arr = []; - timeslotarr.map((val) => { - if (dayjs().diff(dayjs(`${dayjs(startdate).format('MM-DD-YYYY')} ${dayjs(val).format('HH:mm:ss')}`), 'm') <= 0) { - arr.push(val); - } - }); - // if(!arr[0]){ - // setStartdate(dayjs().add(1,'day').format('MM/DD/YYYY')) - // }else{ - if (arr[0]) { - setOrderarr([ - { - sno: 1, - address: '', - customerid: '', - deliverytime: dayjs(arr[0]) || '', - deliverylocationid: '', - clientname: '', - contactno: '', - latitude: '', - longitude: '' - } - ]); - } - - // } - } - }, [timeslotarr]); - - useEffect(() => { - if (searchword) { - // setClientdetailarr() - let arr = clientdetail.filter((val) => { - return ( - val.address.toLowerCase().includes(searchword.toLowerCase()) || - val.firstname.toLowerCase().includes(searchword.toLowerCase()) || - val.contactno.toLowerCase().includes(searchword.toLowerCase()) - // || val.pickupaddress.toString().toLowerCase().includes(searchword.toLowerCase()) - // || val.ordernotes.toString().toLowerCase().includes(searchword.toLowerCase()) - ); - }); - console.log(arr); - setClientdetailarr([...arr]); - } else { - setClientdetailarr([...clientdetail]); - } - }, [searchword]); - - const fetchtenantinfo = async (tid) => { - setLoading(true); - await axios - .get(`${process.env.REACT_APP_URL}/tenants/gettenantinfo/?tenantid=${tid}`) - .then((res) => { - console.log(res); - if (res.data.status) { - // setTenantinfo(res.data.details); - setTenant(res.data.details); - - fetchadmintoken(res.data.details.tenantid, res.data.details.partnerid); - } - setLoading(false); - }) - .catch((err) => { - console.log(err); - setLoading(false); - }); - }; - - const fetchtenantlocation = async (tid) => { - setLoading(true); - await axios - .get(`${process.env.REACT_APP_URL}/tenants/gettenantlocations/?tenantid=${tid}`) - - .then((res) => { - console.log(res); - if (res.data.status) { - // setTenantinfo(res.data.details); - let arr = []; - res.data.details.map((val) => { - arr.push({ - ...val, - label: ` ${val.locationname}` - }); - }); - setTenantlocationlist(arr); - } - setLoading(false); - }) - .catch((err) => { - console.log(err); - setLoading(false); - }); - }; - - const fetchadmintoken = async (tid, pid) => { - setLoading(true); - await axios - .get(`${process.env.REACT_APP_URL}/partners/getadmintoken/?tenantid=${tid}&partnerid=${pid}`) - .then((res) => { - console.log(res); - if (res.data.status) { - // setTenantinfo(res.data.details); - setAdmintoken(res.data.details.userfcmtokem); - // setEndtime(res.data.details.closetime) - let arr = []; - for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) { - console.log(dayjs(endtime).diff(i, 'm')); - console.log(dayjs(i).format('hh:mm A')); - arr.push(i); - } - console.log(arr); - setTimeslotarr(arr); - // console.log(dayjs(starttime)) - } - setLoading(false); - }) - .catch((err) => { - console.log(err); - setLoading(false); - }); - }; - - const opentoast = (message) => { - enqueueSnackbar(message, { - variant: 'error', - anchorOrigin: { vertical: 'top', horizontal: 'right' }, - autoHideDuration: 2000 - }); - console.log(alertmessage); - }; - - function closeAddressModal() { - setOpen2(false); - } - function closetimemodal() { - setOpen3(false); - setCurrentsno(''); - } - - const createsubmitobj1 = async () => { - let arr = []; - let timecheck = false; - let addresscheck = false; - orderarr.map((val) => { - if (!val.address) { - addresscheck = true; - } - - if (!val.deliverytime) { - timecheck = true; - } - - arr.push({ - orderheaderid: 0, - tenantid: parseInt(localStorage.getItem('tenantid')), - locationid: tenantinfo.locationid, - moduleid: tenantinfo.moduleid, - configid: 7, - orderid: '', - customerid: val.customerid, - orderdate: dayjs().format('YYYY-MM-DD HH:mm:ss'), - orderstatus: 'created', - pending: '', - processing: '', - ready: '', - delivered: '', - cancellled: '', - promoid: 0, - promoname: '', - promoterms: '', - promovalue: 0, - promoamount: 0, - orderamount: 0, - taxamount: 0, - ordercharges: 0, - ordervalue: 0, - itemcount: 1, - paymenttype: 64, - paymentstatus: 0, - deliverycharge: 0, - deliverytime: `${dayjs(startdate).format('YYYY-MM-DD')} ${dayjs(val.deliverytime.$d).format('HH:mm:ss')}`, - deliverylocationid: val.deliverylocationid, - deliveryaddress: val.address, - pickupaddress: tenantinfo.locationaddress, - pickuplat: tenantinfo.locationlatitude, - pickuplong: tenantinfo.locationlong, - ordernotes: otherinstructions, - remarks: '', - tenantuserid: parseInt(localStorage.getItem('tenantid')), - categoryid: tenant.categoryid, - subcategoryid: tenant.subcategoryid, - partnerid: tenant.partnerid, - deliverylat: val.latitude, - deliverylong: val.longitude, - applocationid: parseInt(localStorage.getItem('applocationid')) - }); - }); - if (!orderarr[0]) { - opentoast('Choose Customer'); - } else if (!tenantinfo.tenantid) { - opentoast('Choose Location'); - } else if (addresscheck) { - opentoast('Choose Customer'); - } else if (timecheck) { - opentoast('Choose Schedule Time'); - } else { - setLoading(true); - await axios - .post(`${process.env.REACT_APP_URL}/orders/createorders`, arr) - .then((res) => { - if (res.data.status) { - enqueueSnackbar('Order Created Successfully', { - variant: 'success', - anchorOrigin: { vertical: 'top', horizontal: 'right' }, - autoHideDuration: 2000 - }); - if (admintoken) { - notifyadmin(admintoken); - } - - navigate('/orders'); - } else { - opentoast(res.data.message); - } - setLoading(false); - console.log(res); - }) - .catch((err) => { - console.log(err); - opentoast(err.data.message); - setLoading(false); - }); - // opentoast('success') - } - - console.log(arr); - }; - - useEffect(() => { - if (localStorage.getItem('tenantid')) { - // clientdetails(localStorage.getItem('tenantid')); - fetchtenantinfo(localStorage.getItem('tenantid')); - } - - // fetchattires(); - // fetchserviceaddons(); - // let arr = []; - // arr.push({ - // sno: arr.length + 1, - // address: "", - // starttime: "", - // endtime: "", - // latitude: '', - // longitude: '', - // state: "", - // city: "", - // orderattires: [], - // details: [{ - // sno: 1, - // role: '', - // position: '', - // uniform: '', - // cost: 0, - - // "orderdetailid": 0, - // "orderheaderid": 0, - // "tenantid": '', - // "locationid": 0, - // "productid": 1, - // "productname": "", - // "productdescription": "description1", - // "starttime": '', - // "endtime": '', - // "unpaidbreak": 0, - // "orderqty": 0, - // "price": 0, - // "unitid": 1, - // "unitname": "", - // "landingamount": 0, - // "taxamount": 0, - // "productsumprice": 0, - // "workhours": '' - // }], - // "clientstaff": [] - - // }) - // setShiftarr1(arr) - // setShiftarr([]) - }, [clientdetail.tenantname]); - - useEffect(() => { - console.log('shiftarr'); - console.log(shiftarr); - }, [shiftarr]); - - const clicked1 = (e) => { - setShift(e); - }; - - const dialogopen = (i, result) => { - console.log(i, result); - setOpen({ shiftsno: result.sno, sno: i.sno }); - }; - const dialogclose = () => { - setOpen(''); - }; - - const clientdetails = async (tid) => { - // setClientdetail([{ - // "address": 'ttt uuu vvvv', - // "customerid":10, - // "deliverylocationid": 20, - // "contactno":4444, - // "firstname":'test1', - // }, - // { - // "address": '2ttt uuu vvvv', - // "customerid":11, - // "deliverylocationid": 21, - // "contactno":5555, - // "firstname":'test2', - // }, - // { - // "address": '3ttt uuu vvvv', - // "customerid":12, - // "deliverylocationid": 22, - // "contactno":6666, - // "firstname":'test3', - // } - // ]) - setLoading2(true); - try { - await axios - .get(`${process.env.REACT_APP_URL}/customers/getbytid/?tenantid=${tid}`) - - .then((res) => { - if (res.data.status) { - setClientdetail(res.data.details); - if (!searchword) { - let arr = []; - res.data.details.map((val) => { - arr.push({ - ...val, - label: `${val.firstname} | ${val.contactno}` - }); - }); - setClientdetailarr(arr); - } - } - setLoading2(false); - }) - .catch((err) => { - console.log(err); - setLoading2(false); - opentoast('server error'); - }); - } catch (err) { - console.log(err); - setLoading2(false); - // opentoast('Something went wrong') - } - }; - - const notifyadmin = async (id1) => { - setLoading(true); - await axios - .post(`${process.env.REACT_APP_URL}/utils/notifyuser`, { - sender: localStorage.getItem('firstname'), - accessid: process.env.REACT_APP_RIDER_ACCESS_ID, - notification: { - priority: 'high', - to: id1, - notification: { - title: 'Nearle Admin', - body: 'Orders has been placed for delivery.Kindly accept and process deliveries', - sound: 'ring' - } - } - }) - .then((res) => { - console.log(res); - if (res.data.message == 'Success') { - enqueueSnackbar('Notification sent Successfully', { - variant: 'success', - anchorOrigin: { vertical: 'top', horizontal: 'right' }, - autoHideDuration: 2000 - }); - } - setLoading(false); - }) - .catch((err) => { - console.log(err); - enqueueSnackbar(err.message, { - variant: 'error', - anchorOrigin: { vertical: 'top', horizontal: 'right' }, - autoHideDuration: 2000 - }); - setLoading(false); - }); - }; - - return ( - <> - {loading && } - - - - - Create Order - - - - - - - - - - - - - - - {/* - Event - - - - - - - { - if (clientdetail.tenantname) { - - - if (e.target.value.length <= 50) { - setEventname(e.target.value); - } - } else { - setAlertmessage('choose client'); - opentoast('choose client'); - } - }} - sx={{ m: 0 }} - /> - - {`${eventname.length}/50`} - - */} - - Pickup Location - {/* - - - {' '}{tenantinfo.address || ''} - - - */} - } - onChange={(e, val) => { - if (val) { - setTenantinfo(val); - } else { - setTenantinfo({}); - } - // if (reason === 'reset'){ - // setTenantinfo({}) - // } - console.log(val); - }} - // value={tenantinfo} - disabled={tenant.tenantid ? false : true} - /> - - - - - Date - { - let dateres11 = dayjs().diff(dayjs(`${dayjs(e).format('YYYY-MM-DD')}`), 'd'); - console.log('dateres11'); - console.log(dateres11); - if (dateres11 <= 0) { - setStartdate(e); - setEnddate(e); - - let arr = []; - timeslotarr.map((val) => { - if (dayjs().diff(dayjs(`${dayjs(e).format('MM-DD-YYYY')} ${dayjs(val).format('HH:mm:ss')}`), 'm') <= 0) { - arr.push(val); - } - }); - if (arr[0]) { - setOrderarr([ - { - sno: 1, - address: '', - customerid: '', - deliverytime: dayjs(arr[0]) || '', - deliverylocationid: '', - clientname: '', - contactno: '', - latitude: '', - longitude: '' - } - ]); - } else { - setOrderarr([]); - } - } else { - setAlertmessage('choose Upcoming Date'); - opentoast('choose Upcoming Date'); - setStartdate(NaN); - } - }} - value={dayjs(startdate)} - sx={{ width: '100%', mt: 2 }} - disablePast - // minDate={dayjs().add(1, 'day')} - /> - - - - - {/* */} - - - {tenantinfo.locationaddress || ''} - - - {/* */} - - - - - - {/* {shiftarr1.map((result) => { - - return <> */} - - - - - {/* Shift {result.sno} */} - - - {/* */} - - - - - {/* - - { - let city1, state, zipcode1, suburb1; - for (let i = 0; i < place.address_components.length; i++) { - for (let j = 0; j < place.address_components[i].types.length; j++) { - switch (place.address_components[i].types[j]) { - case "locality": - city1 = place.address_components[i].long_name; - break; - case "administrative_area_level_1": - state = place.address_components[i].long_name; - break; - case "postal_code": - zipcode1 = place.address_components[i].long_name; - break; - case "sublocality": - suburb1 = place.address_components[i].long_name; - break; - } - } - } - console.log(city1, state, zipcode1, suburb1) - let arr = shiftarr1; - try { - Geocode.fromAddress(place.formatted_address).then( - (response) => { - const { lat, lng } = response.results[0].geometry.location; - arr[result.sno - 1].latitude = lat; - arr[result.sno - 1].longitude = lng; - - console.log(lat, lng); - }, - (error) => { - console.error(error); - } - ); - } catch (err) { - console.log(err) - } - arr[result.sno - 1].city = city1 || ''; - arr[result.sno - 1].state = state || ''; - - arr[result.sno - 1].address = place.formatted_address; - setShiftarr1([...arr]); - - }} - options={{ - - types: ['address' || 'geocode'] - - }} - placeholder='Shift Location' - - onChange={() => { - if (!eventname) { - setAlertmessage('Fill Event name'); - opentoast('Fill Event name'); - } - }} - - /> - - */} - - - {/* - - - - {result.clientstaff.map((val11) => { - - return <> - - {val11.firstname.charAt(0).toUpperCase()} - - - }) - - } - - - */} - {/* */} - - {/* */} - - - - - - Select Address - {/* */} - - - - - {loading2 ? ( - <> - - - - - ) : ( - <> - - - - - ) - }} - placeholder="Search" - fullWidth - onChange={(e) => { - setSearchword(e.target.value); - }} - /> - - - {/*
*/} - - {clientdetailarr.map((address) => ( - handlerAddress(address)} - onClick={() => { - if (tabstatus == 1) { - let arr5 = []; - timeslotarr.map((val) => { - if ( - dayjs().diff( - dayjs(`${dayjs(startdate).format('MM-DD-YYYY')} ${dayjs(val).format('HH:mm:ss')}`), - 'm' - ) <= 0 - ) { - arr5.push(val); - } - }); - - if (orderarr[0].address == '') { - setOrderarr([ - { - sno: 1, - address: address.address, - customerid: address.customerid, - deliverytime: dayjs(arr5[0]) || '', - deliverylocationid: address.deliverylocationid, - clientname: address.firstname, - contactno: address.contactno, - latitude: address.latitude, - longitude: address.longitude - } - ]); - } else { - if (orderarr.find((val2) => val2.customerid == address.customerid)) { - if (orderarr.length > 1) { - let arr = orderarr; - let res = orderarr.find((val2) => val2.address == address.address); - arr.splice(res.sno - 1, 1); - console.log(arr); - let arr1 = []; - arr.map((val2, k) => { - arr1.push({ - sno: k + 1, - address: val2.address, - customerid: val2.customerid, - deliverytime: val2.deliverytime, - deliverylocationid: val2.deliverylocationid, - clientname: val2.clientname, - contactno: val2.contactno, - latitude: val2.latitude, - longitude: val2.longitude - }); - }); - setOrderarr([...arr1]); - } else { - setOrderarr([ - { - sno: 1, - address: '', - customerid: '', - deliverytime: dayjs(arr5[0]) || '', - deliverylocationid: '', - clientname: '', - contactno: '', - latitude: '', - longitude: '' - } - ]); - } - } else { - console.log(clientdetail); - let arr = orderarr; - arr.push({ - sno: arr.length + 1, - address: address.address, - customerid: address.customerid, - deliverytime: dayjs(arr5[0]) || '', - deliverylocationid: address.deliverylocationid, - clientname: address.firstname, - contactno: address.contactno, - latitude: address.latitude, - longitude: address.longitude - }); - setOrderarr([...arr]); - } - } - console.log(orderarr); - } - - if (tabstatus == 0) { - let arr = []; - timeslotarr.map((val) => { - if ( - dayjs().diff( - dayjs(`${dayjs(startdate).format('MM-DD-YYYY')} ${dayjs(val).format('HH:mm:ss')}`), - 'm' - ) <= 0 - ) { - arr.push(val); - } - }); - - setOrderarr([ - { - sno: 1, - address: address.address, - customerid: address.customerid, - deliverytime: dayjs(arr[0]) || '', - deliverylocationid: address.deliverylocationid, - clientname: address.firstname, - contactno: address.contactno, - latitude: address.latitude, - longitude: address.longitude - } - ]); - - // console.log({ - // sno: 1, - // address: address.address, - // "customerid": address.customerid, - // "deliverytime": "", - // "deliverylocationid": address.deliverylocationid, - // }) - } - }} - key={address.contactno} - sx={{ - width: '100%', - border: '1px solid', - borderColor: 'grey.200', - borderRadius: 1, - cursor: 'pointer', - p: 1.25, - '&:hover': { - // bgcolor: theme.palette.primary.lighter, - // borderColor: theme.palette.primary.lighter - bgcolor: orderarr.find((val2) => val2.address == address.address) ? '#e1bee7' : '' - }, - bgcolor: orderarr.find((val2) => val2.address == address.address) ? '#e1bee7' : '' - }} - > - - - {address.firstname} - - {orderarr.find((val2) => val2.address == address.address) && } - - - - {address.address} - - - {address.contactno} - - - {/* {address.email} */} - - - - ))} - - - )} - - - - - - -
- - - - - Select Time - - - - - - {timeslotarr.map((val) => { - if ( - dayjs().diff(dayjs(`${dayjs(startdate).format('MM-DD-YYYY')} ${dayjs(val).format('HH:mm:ss')}`), 'm') <= - 0 && - currentsno - ) { - return ( - <> - - { - let arr = orderarr; - arr[currentsno - 1].deliverytime = val; - setOrderarr([...arr]); - console.log(arr); - }} - /> - - {/*

{dayjs().diff(dayjs(val),'m')}

*/} - - ); - } - })} -
-
- - - - - -
-
-
- - - - - - # - {/* Role */} - Client - Schedule Time - {/* End Time */} - {/* Pickup Location */} - {/* Break */} - Drop Location - {/* Value */} - Action - - - - {orderarr.map((val) => { - return ( - <> - - {val.sno} - - - - - {val.clientname} - - {val.contactno} - - - - - - - {/* - { - console.log(e) - if (e.$d) { - - - let arr = orderarr; - arr[val.sno - 1].deliverytime = e - setOrderarr([...arr]) - console.log(arr) - } - - - } - } - - sx={{ width: '150px' }} - value={val.deliverytime || null} - disabled - - /> - */} - - {dayjs(val.deliverytime).format('hh:mm A')} - { - if (tenantinfo.tenantid && orderarr[0].address) { - setCurrentsno(val.sno); - setOpen3(true); - } else { - opentoast('Choose Location & Client'); - } - }} - > - - - - - {val.address} - - {/* - {(val.cost) && - <> - {`${val.cost}/hr`} - - } - - */} - - {/* {(val.role && val.position) && - <> - {val.landingamount} - - } - {(!val.position || !val.role) && - 0 - } - */} - - - - - - - - - ); - })} - -
-
- {/* - - */} -
-
- - {/* - }) */} - - {/* } */} - {/* - - */} - - - - - setOtherinstructions(e.target.value)} - /> - - - - -
- - - - -
-
- -
- - ); -}; - -export default Createorder; diff --git a/src/pages/nearle/orders/createorder1.js b/src/pages/nearle/orders/createorder1.js index 38b6085..b10ba17 100644 --- a/src/pages/nearle/orders/createorder1.js +++ b/src/pages/nearle/orders/createorder1.js @@ -5,29 +5,12 @@ import { Typography, Stack, Box, - // Autocomplete, Button, - // Stepper, - // Step, - // StepLabel, TextField, Autocomplete, CardActions, - // CardActions, Chip, - // AvatarGroup, - // RadioGroup, - // Radio Avatar, - // List, - // ListItem, - // IconButton, - // ListItemAvatar, - // ListItemText, - // Menu, - // MenuItem, - // ListItemIcon, - // Link, Divider, Table, TableContainer, @@ -35,7 +18,6 @@ import { TableCell, TableHead, TableBody, - // FormLabel, Tooltip, DialogTitle, DialogContent, @@ -50,8 +32,8 @@ import { Select, MenuItem, Switch - // LinkOutlined } from '@mui/material'; + import { useNavigate } from 'react-router'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import AccessTimeOutlinedIcon from '@mui/icons-material/AccessTimeOutlined'; @@ -138,6 +120,8 @@ function loadScript(src, position, id) { const autocompleteService = { current: null }; const Createorder1 = () => { + const appId = localStorage.getItem('applocationid'); + Geocode.setApiKey(process.env.REACT_APP_GOOGLE_MAPS_API_KEY); function GoogleMaps() { @@ -680,8 +664,10 @@ const Createorder1 = () => { const [startdate, setStartdate] = useState(dayjs().format('MM-DD-YYYY')); const [enddate, setEnddate] = useState(dayjs().add(1, 'day').format('MM-DD-YYYY')); - const [starttime, setStatrttime] = useState(`${dayjs().format('MM-DD-YYYY')} 08:00:00`); - const [endtime, setEndtime] = useState(`${dayjs().format('MM-DD-YYYY')} 20:00:00`); + // const [starttime, setStatrttime] = useState(`${dayjs().format('MM-DD-YYYY')} 08:00:00`); + const [starttime, setStatrttime] = useState(); + // const [endtime, setEndtime] = useState(`${dayjs().format('MM-DD-YYYY')} 20:00:00`); + const [endtime, setEndtime] = useState(); const [timeslotarr, setTimeslotarr] = useState([]); const [currentsno, setCurrentsno] = useState(''); @@ -712,7 +698,8 @@ const Createorder1 = () => { const [clientdetailarr, setClientdetailarr] = useState([]); const [clientdetailbusinessarr, setClientdetailbusinessarr] = useState([]); - const [admintoken, setAdmintoken] = useState(''); + // const [admintoken, setAdmintoken] = useState(''); + const [admintoken, setAdmintoken] = useState(); const [tenantlocationlist, setTenantlocationlist] = useState([]); const [tenant, setTenant] = useState({}); const [clientinfo, setClientinfo] = useState({}); @@ -750,6 +737,20 @@ const Createorder1 = () => { useEffect(() => { fetchTenantPricing(); }, []); + // const fetchAppPricing = async () => { + // try { + // const pricingResponse = await axios.get(`${process.env.REACT_APP_URL}/utils/getapppricing/?applocationid=${appId}`); + // console.log('pricingResponse', pricingResponse.data.details); + // setBasePrice(pricingResponse.data.details.baseprice); + // setPricePerKm(pricingResponse.data.details.priceperkm); + // setMinKm(pricingResponse.data.details.minkm); + // } catch (error) { + // console.log('fetchAppPricing error', error); + // } + // }; + // useEffect(() => { + // fetchAppPricing(); + // }, []); useEffect(() => { console.log('startPoint', startPoint); @@ -872,6 +873,8 @@ const Createorder1 = () => { } }); + // ==================================================== || fetchtenantinfo || ==================================================== + const fetchtenantinfo = async () => { setLoading(true); console.log('tid', tid); @@ -881,8 +884,8 @@ const Createorder1 = () => { console.log('fetchtenantinfo', res); if (res.data.status) { setTenant(res.data.details); - - fetchadmintoken(res.data.details.tenantid, res.data.details.partnerid); + // fetchadmintoken(res.data.details.tenantid, res.data.details.partnerid); + fetchAppAdminTokens(); } setLoading(false); }) @@ -896,33 +899,69 @@ const Createorder1 = () => { fetchtenantlocation(); }, []); - // const fetchtenantinfolist = async () => { - // setLoading(true); - // console.log('tid', tid); - // // await axios.get(`${process.env.REACT_APP_URL}/tenants/gettenantinfo/?tenantid=${tid}`) - // await axios - // .get(`${process.env.REACT_APP_URL}/tenants/gettenants/?partnerid=${tid}&status=active`) + // ==================================================== || fetchTiming || ==================================================== + const fetchTiming = async () => { + setLoading(true); + console.log('tid', tid); + await axios + .get(`${process.env.REACT_APP_URL}/utils/getapplocations/?applocationid=${appId}`) + .then((res) => { + console.log('fetchTiming', res); + const { opentime, closetime } = res.data.details[0]; + if (res.data.status) { + setStatrttime(`${dayjs().format('MM-DD-YYYY')} ${opentime}`); + setEndtime(`${dayjs().format('MM-DD-YYYY')} ${closetime}`); + console.log('starttime', `${dayjs().format('MM-DD-YYYY')} ${opentime}`); + console.log('endtime', `${dayjs().format('MM-DD-YYYY')} ${closetime} `); + let arr = []; + for ( + let i = `${dayjs().format('MM-DD-YYYY')} ${opentime}`, j = 0; + dayjs(`${dayjs().format('MM-DD-YYYY')} ${closetime} `).diff(i, 'm') >= 0; + j++, i = dayjs(i).add(30, 'm') + ) { + arr.push(i); + } + console.log('setTimeslotarr', arr); + setTimeslotarr(arr); + } + setLoading(false); + }) + .catch((err) => { + console.log(err); + setLoading(false); + }); + }; + useEffect(() => { + fetchTiming(); + }, [starttime, endtime]); - // .then((res) => { - // console.log(res); - // if (res.data.status) { - // // setTenantinfo(res.data.details); - // let arr = []; - // res.data.details.map((val) => { - // arr.push({ - // ...val, - // label: `${val.tenantname}` - // }); + // const fetchtenantinfolist = async () => { + // setLoading(true); + // console.log('tid', tid); + // // await axios.get(`${process.env.REACT_APP_URL}/tenants/gettenantinfo/?tenantid=${tid}`) + // await axios + // .get(`${process.env.REACT_APP_URL}/tenants/gettenants/?partnerid=${tid}&status=active`) + + // .then((res) => { + // console.log(res); + // if (res.data.status) { + // // setTenantinfo(res.data.details); + // let arr = []; + // res.data.details.map((val) => { + // arr.push({ + // ...val, + // label: `${val.tenantname}` // }); - // setTenantlist(arr); - // } - // setLoading(false); - // }) - // .catch((err) => { - // console.log(err); - // setLoading(false); - // }); - // }; + // }); + // setTenantlist(arr); + // } + // setLoading(false); + // }) + // .catch((err) => { + // console.log(err); + // setLoading(false); + // }); + // }; const fetchtenantlocation = async () => { setLoading(true); @@ -948,21 +987,47 @@ const Createorder1 = () => { }); }; - const fetchadmintoken = async (tid, pid) => { + // // =============================================== || fetchadmintoken (via tid , pid) || =============================================== + // const fetchadmintoken = async (tid, pid) => { + // setLoading(true); + // await axios + // .get(`${process.env.REACT_APP_URL}/partners/getadmintoken/?tenantid=${tid}&partnerid=${pid}`) + // .then((res) => { + // console.log(res); + // if (res.data.status) { + // setAdmintoken(res.data.details.userfcmtokem); + + // let arr = []; + // for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) { + // arr.push(i); + // } + // console.log(arr); + // setTimeslotarr(arr); + // } + // setLoading(false); + // }) + // .catch((err) => { + // console.log(err); + // setLoading(false); + // }); + // }; + // =============================================== || fetchAppAdminTokens (via appId) || =============================================== + const fetchAppAdminTokens = async () => { setLoading(true); await axios - .get(`${process.env.REACT_APP_URL}/partners/getadmintoken/?tenantid=${tid}&partnerid=${pid}`) + .get(`${process.env.REACT_APP_URL}/utils/getapplocationconfig/?applocationid=${appId}`) .then((res) => { - console.log(res); + const userfcmtokemArray = res.data.details.applocationadmins.map((admin) => admin.userfcmtokem); + console.log('fetchAppAdminTokens', res); + console.log('userfcmtokemArray', userfcmtokemArray); if (res.data.status) { - setAdmintoken(res.data.details.userfcmtokem); - - let arr = []; - for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) { - arr.push(i); - } - console.log(arr); - setTimeslotarr(arr); + setAdmintoken(userfcmtokemArray); + // let arr = []; + // for (let i = starttime, j = 0; dayjs(endtime).diff(i, 'm') >= 0; j++, i = dayjs(i).add(30, 'm')) { + // arr.push(i); + // } + // console.log('setTimeslotarr', arr); + // setTimeslotarr(arr); } setLoading(false); }) @@ -972,6 +1037,14 @@ const Createorder1 = () => { }); }; + useEffect(() => { + if (starttime && endtime) { + fetchAppAdminTokens(); + } + }, [starttime, endtime]); + + // =============================================== || opentoast || =============================================== + const opentoast = (message) => { enqueueSnackbar(message, { variant: 'error', @@ -989,6 +1062,7 @@ const Createorder1 = () => { setCurrentsno(''); } + // =============================================== || createsubmitobj1 (create orders) || =============================================== const createsubmitobj1 = async () => { let arr = []; let timecheck = false; @@ -1058,7 +1132,8 @@ const Createorder1 = () => { autoHideDuration: 1000 }); if (admintoken) { - notifyadmin(admintoken); + // notifyadmin(admintoken); + sendnotifications(); } navigate('/orders'); @@ -1078,13 +1153,6 @@ const Createorder1 = () => { console.log(arr); }; - // useEffect(() => { - // if (localStorage.getItem('tenantid')) { - - // fetchtenantinfo(localStorage.getItem('tenantid')) - // } - // }, [clientdetail.tenantname]) - useEffect(() => { console.log('shiftarr'); console.log(shiftarr); @@ -1170,20 +1238,58 @@ const Createorder1 = () => { } }; - const notifyadmin = async (id1) => { + // ================================================== || notifyadmin || ================================================== + // const notifyadmin = async (id1) => { + // setLoading(true); + // await axios + // .post(`${process.env.REACT_APP_URL}/utils/notifyuser`, { + // sender: localStorage.getItem('firstname'), + // accessid: process.env.REACT_APP_RIDER_ACCESS_ID, + // notification: { + // priority: 'high', + // to: id1, + // notification: { + // title: 'Nearle Admin', + // body: 'Orders has been placed for delivery.Kindly accept and process deliveries', + // sound: 'ring' + // } + // } + // }) + // .then((res) => { + // console.log(res); + // if (res.data.message == 'Success') { + // enqueueSnackbar('Notification sent Successfully', { + // variant: 'success', + // anchorOrigin: { vertical: 'top', horizontal: 'right' }, + // autoHideDuration: 1000 + // }); + // } + // setLoading(false); + // }) + // .catch((err) => { + // console.log(err); + // enqueueSnackbar(err.message, { + // variant: 'error', + // anchorOrigin: { vertical: 'top', horizontal: 'right' }, + // autoHideDuration: 1000 + // }); + // setLoading(false); + // }); + // }; + // ================================================== || sendnotifications || ================================================== + const sendnotifications = async () => { setLoading(true); await axios - .post(`${process.env.REACT_APP_URL}/utils/notifyuser`, { - sender: localStorage.getItem('firstname'), - accessid: process.env.REACT_APP_RIDER_ACCESS_ID, + .post(`${process.env.REACT_APP_URL}/utils/sendnotifications`, { + priority: 'high', + registration_ids: admintoken, + data: { + accessid: process.env.REACT_APP_RIDER_ACCESS_ID + }, notification: { - priority: 'high', - to: id1, - notification: { - title: 'Nearle Admin', - body: 'Orders has been placed for delivery.Kindly accept and process deliveries', - sound: 'ring' - } + title: 'Nearle Merchant', + body: 'An Order has been placed successfully,kindly process the same', + sound: 'ring' } }) .then((res) => { @@ -1423,8 +1529,8 @@ const Createorder1 = () => { {showDistance && ( - - + + {/* */} {/* */} diff --git a/src/pages/nearle/orders/orders.js b/src/pages/nearle/orders/orders.js index 4e029d1..750593c 100644 --- a/src/pages/nearle/orders/orders.js +++ b/src/pages/nearle/orders/orders.js @@ -1648,7 +1648,7 @@ const Orders = () => { try { // await axios.get(`${process.env.REACT_APP_URL}/orders/getordersummary/?tenantid=${tid}&fromdate=${startdate}&todate=${enddate}`) await axios - .get(`${process.env.REACT_APP_URL}/orders/getordersummary/?tenantid=${tid}`) + .get(`${process.env.REACT_APP_URL}/orders/getordersummary/?applocationid=${tid}`) .then((res) => { console.log(res); diff --git a/src/routes/MainRoutes.js b/src/routes/MainRoutes.js index a00ad63..700a331 100644 --- a/src/routes/MainRoutes.js +++ b/src/routes/MainRoutes.js @@ -24,7 +24,7 @@ const Details = Loadable(lazy(() => import('pages/nearle/orders/details'))); const Accountsettings = Loadable(lazy(() => import('pages/nearle/accountsettings'))); -const Createorder = Loadable(lazy(() => import('pages/nearle/orders/createorder'))); +// const Createorder = Loadable(lazy(() => import('pages/nearle/orders/createorder'))); const Createclient = Loadable(lazy(() => import('pages/nearle/clients/createclient'))); const Createorder1 = Loadable(lazy(() => import('pages/nearle/orders/createorder1'))); @@ -71,10 +71,10 @@ const MainRoutes = { path: 'accountsettings', element: }, - { - path: 'orders/create1', - element: - }, + // { + // path: 'orders/create1', + // element: + // }, { path: 'orders/create', element: