From 72d6c9f0207bae9619c347b8ad2415f94706f7bc Mon Sep 17 00:00:00 2001 From: joshikannan Date: Wed, 24 Jan 2024 09:49:20 +0530 Subject: [PATCH] createOrders up --- src/pages/nearle/orders/createorder.js | 2446 +++++++++++------------ src/pages/nearle/orders/createorder1.js | 21 +- 2 files changed, 1180 insertions(+), 1287 deletions(-) diff --git a/src/pages/nearle/orders/createorder.js b/src/pages/nearle/orders/createorder.js index 21abed4..de058cf 100644 --- a/src/pages/nearle/orders/createorder.js +++ b/src/pages/nearle/orders/createorder.js @@ -1,51 +1,51 @@ 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 + 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'; @@ -56,27 +56,27 @@ import { PopupTransition } from 'components/@extended/Transitions'; import axios from 'axios'; import { useTheme } from '@mui/material/styles'; // import { usePlacesWidget } from "react-google-autocomplete"; -import Geocode from "react-geocode"; +import Geocode from 'react-geocode'; // import {setApi} from "react-geocode"; -import Autocomplete1 from "react-google-autocomplete"; +import Autocomplete1 from 'react-google-autocomplete'; // import logo from 'assets/images/location.png' -import Loader from 'components/Loader' +import Loader from 'components/Loader'; import { - // EditOutlined, - PlusOutlined, - SearchOutlined + // EditOutlined, + PlusOutlined, + SearchOutlined } from '@ant-design/icons'; import { DeleteOutlined } from '@ant-design/icons'; import MainCard from 'components/MainCard'; import { - EnvironmentOutlined, - // LinkOutlined, - // MailOutlined, - // MoreOutlined, - // PhoneOutlined + EnvironmentOutlined + // LinkOutlined, + // MailOutlined, + // MoreOutlined, + // PhoneOutlined } from '@ant-design/icons'; import CheckCircleRoundedIcon from '@mui/icons-material/CheckCircleRounded'; // import VisibilityIcon from '@mui/icons-material/Visibility'; @@ -93,8 +93,10 @@ 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 + useEffect, + useState, + Fragment + // useReducer } from 'react'; // import { Label } from '@mui/icons-material'; import dayjs from 'dayjs'; @@ -104,612 +106,578 @@ import dayjs from 'dayjs'; import { enqueueSnackbar } from 'notistack'; // import { CheckBox } from '@mui/icons-material'; // dayjs.extend(utc) -var utc = require('dayjs/plugin/utc') -dayjs.extend(utc) - - +var utc = require('dayjs/plugin/utc'); +dayjs.extend(utc); const Createorder = () => { + Geocode.setApiKey(process.env.REACT_APP_GOOGLE_MAPS_API_KEY); - 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 navigate = useNavigate(); - const [open, setOpen] = useState({}); - const [open1, setOpen1] = useState('') - const [open2, setOpen2] = useState(false) - const [open3, setOpen3] = useState(false) + const [timeslotarr, setTimeslotarr] = useState([]); + const [currentsno, setCurrentsno] = useState(''); - const [shift, setShift] = useState(1); - const [clientlist, setClientlist] = useState([]) - const [clientdetail, setClientdetail] = useState([]); - const [eventname, setEventname] = useState(''); + const [roleoptions, setRoleoptions] = 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 theme = useTheme(); - const [timeslotarr, setTimeslotarr] = useState([]); - const [currentsno, setCurrentsno] = useState(''); + 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({}); - const [roleoptions, setRoleoptions] = 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')); + } + }, []); - 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: '' + } + ]); + } - 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); } - }, [timeslotarr]) + setLoading(false); + }) + .catch((err) => { + console.log(err); + setLoading(false); + }); + }; - 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; - } + 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({ - "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') + ...val, + label: ` ${val.locationname}` + }); + }); + setTenantlocationlist(arr); } + setLoading(false); + }) + .catch((err) => { + console.log(err); + setLoading(false); + }); + }; - console.log(arr) - } - - - - - useEffect(() => { - if (localStorage.getItem('tenantid')) { - // clientdetails(localStorage.getItem('tenantid')); - fetchtenantinfo(localStorage.getItem('tenantid')) + 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); + }); + }; - // 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, + const opentoast = (message) => { + enqueueSnackbar(message, { + variant: 'error', + anchorOrigin: { vertical: 'top', horizontal: 'right' }, + autoHideDuration: 2000 + }); + console.log(alertmessage); + }; - // "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": [] + function closeAddressModal() { + setOpen2(false); + } + function closetimemodal() { + setOpen3(false); + setCurrentsno(''); + } - // }) - // setShiftarr1(arr) - // setShiftarr([]) - }, [clientdetail.tenantname]) + const createsubmitobj1 = async () => { + let arr = []; + let timecheck = false; + let addresscheck = false; + orderarr.map((val) => { + if (!val.address) { + addresscheck = true; + } + if (!val.deliverytime) { + timecheck = true; + } - - - - - - - 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" - } + 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); }) - .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) - - }) + .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": [] - return <> - {(loading) && + // }) + // 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); + }); + }; - + {loading && } + + + + - - - Create Order - - - + Create Order + + + - - - - - - - - - - - - - - - - - - {/* + + + + + + + + + + + {/* Event @@ -744,144 +712,120 @@ const Createorder = () => { {`${eventname.length}/50`} */} - - Pickup Location - {/* + + Pickup Location + {/* {' '}{tenantinfo.address || ''} */} - } - onChange={(e, val) => { - if (val) { + } + onChange={(e, val) => { + if (val) { + setTenantinfo(val); + } else { + setTenantinfo({}); + } + // if (reason === 'reset'){ + // setTenantinfo({}) + // } + console.log(val); + }} + // value={tenantinfo} + disabled={tenant.tenantid ? false : true} + /> + - 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')} + /> + + - - Date - + {/* */} + + + {tenantinfo.locationaddress || ''} + + + {/* */} + + + + - // label='Date' - format="DD-MM-YYYY" - onChange={(e) => { - 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) => { + {/* {shiftarr1.map((result) => { return <> */} + + + + {/* Shift {result.sno} */} - - - - - - - - - {/* Shift {result.sno} */} - - - - {/* */} - - + + - - - {/* + + {/* { /> */} - - - - {/* + + + {/* @@ -976,399 +922,376 @@ const Createorder = () => { */} - {/* */} - + {/* */} + - // if (localStorage.getItem('tenantid')) { - // clientdetails(localStorage.getItem('tenantid')); - // } - 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]) { - if (tenantinfo.tenantid) { - // clientdetails(tenant.tenantid); - setOpen2(true) - - } else { - opentoast('Choose Location') - } - } else { - opentoast('We are unable to process the order at this time. Kindly schedule it for an other day') - } - - }} color="success" startIcon={}>ADD Customers - {/* */} - - - - - - - - - - Select Address - {/* */} - - - - - {(loading2) ? + + + + + {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); + } + }); - - - - - - ) - }} - 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} */} - - - - ))} - - - - - + 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: '' } - - - - - - -
- - - - - - - - - - - - - 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')}

*/} - - } - - }) - - } -
-
- - - - - -
- - + ]); + } + } 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} + + + + - - -
- - - # - {/* Role */} - Client - Schedule Time - {/* End Time */} - {/* Pickup Location */} - {/* Break */} - Drop Location - {/* Value */} - Action - - - - - - {orderarr.map((val) => { - return <> - - - - {val.sno} - - - - - - - {val.clientname} - - - - {val.contactno} - - - - - - - {/* + + {/* { /> */} - - {dayjs(val.deliverytime).format('hh:mm A')} - + {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} - onClick={() => { - if (tenantinfo.tenantid && orderarr[0].address) { - setCurrentsno(val.sno) - setOpen3(true) - - } else { - opentoast('Choose Location & Client') - } - - }} - > - - - - - {val.address} - - - {/* + {/* {(val.cost) && <> {`${val.cost}/hr`} @@ -1425,8 +1344,7 @@ const Createorder = () => { */} - - {/* {(val.role && val.position) && + {/* {(val.role && val.position) && <> {val.landingamount} @@ -1436,74 +1354,74 @@ const Createorder = () => { } */} - + + + - - - - - - - - - - - }) + 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.length > 1) { + arr.splice(val.sno - 1, 1); + 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: arr5[0], + deliverylocationid: '', + clientname: '', + contactno: '', + latitude: '', + longitude: '' } + ]); + } - -
-
- {/* + // arr[val.sno-1] + }} + > + + + + + + + ); + })} + + + + {/* */} -
+ +
- - - - - - - - {/* + {/* }) */} - {/* } */} - {/* + {/* } */} + {/* */} - - - - - - - - setOtherinstructions(e.target.value)} /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + setOtherinstructions(e.target.value)} + /> + + + + - + + + + + + + -} + ); +}; -export default Createorder; \ No newline at end of file +export default Createorder; diff --git a/src/pages/nearle/orders/createorder1.js b/src/pages/nearle/orders/createorder1.js index d364dbd..535b1de 100644 --- a/src/pages/nearle/orders/createorder1.js +++ b/src/pages/nearle/orders/createorder1.js @@ -997,8 +997,7 @@ const Createorder1 = () => { arr = [ { orderheaderid: 0, - tenantid: tenantid, - // "locationid": tenant.locationid, + tenantid: parseFloat(tid), locationid: clientinfo.tenantlocationid ? clientinfo.tenantlocationid : tenantinfo.tenantlocationid, moduleid: tenant.moduleid, configid: 7, @@ -1011,11 +1010,6 @@ const Createorder1 = () => { ready: '', delivered: '', cancellled: '', - // "promoid": 0, - // "promoname": "", - // "promoterms": "", - // "promovalue": 0, - // "promoamount": 0, orderamount: totalCharge, taxamount: 0, ordercharges: 0, @@ -1027,12 +1021,9 @@ const Createorder1 = () => { deliverytime: `${dayjs(startdate).format('YYYY-MM-DD')} ${dayjs(selectedtime.$d).format('HH:mm:ss')}`, deliverylocationid: clientinfo.deliverylocationid, deliveryaddress: clientinfo.address, - // "pickupaddress": tenantinfo.locationaddress,// - // "pickuplat": tenantinfo.locationlatitude,// - // "pickuplong": tenantinfo.locationlong,// - pickupaddress: tenantinfo.address, // - pickuplat: startPoint.latitude, // - pickuplong: startPoint.longitude, // + pickupaddress: tenantinfo.address, + pickuplat: startPoint.latitude, + pickuplong: startPoint.longitude, ordernotes: otherinstructions, remarks: '', tenantuserid: parseInt(localStorage.getItem('userid')), @@ -1047,8 +1038,8 @@ const Createorder1 = () => { kms: distance } ]; - if (!tenantid) { - opentoast('Choose Client'); + if (!tid) { + opentoast('Choose Client '); } else if (!tenantinfo.address) { opentoast('Choose Pickup Location'); } else if (!clientinfo.address) {