createorder
This commit is contained in:
@@ -27,10 +27,12 @@
|
|||||||
|
|
||||||
<!-- this is to resolve issue in old safari browser in tablet -->
|
<!-- this is to resolve issue in old safari browser in tablet -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/resize-observer-polyfill@1.5.1/dist/ResizeObserver.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/resize-observer-polyfill@1.5.1/dist/ResizeObserver.min.js"></script>
|
||||||
|
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDQ2c_pOSOFYSjxGMwkFvCVWKjYOM9siow&libraries=places"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.datedialog > div > div > .MuiPaper-root{
|
.datedialog > div > div > .MuiPaper-root {
|
||||||
box-shadow: none !important;
|
box-shadow: none !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -483,7 +483,8 @@ const Createorder1 = () => {
|
|||||||
console.log('startPoint', startPoint);
|
console.log('startPoint', startPoint);
|
||||||
console.log('endPoint', endPoint);
|
console.log('endPoint', endPoint);
|
||||||
if (startPoint.latitude != 0 && startPoint.longitude != 0 && endPoint.latitude != 0 && endPoint.longitude != 0) {
|
if (startPoint.latitude != 0 && startPoint.longitude != 0 && endPoint.latitude != 0 && endPoint.longitude != 0) {
|
||||||
getDistance();
|
// getDistance();
|
||||||
|
calculateDistance(startPoint, endPoint);
|
||||||
}
|
}
|
||||||
}, [startPoint, endPoint]);
|
}, [startPoint, endPoint]);
|
||||||
|
|
||||||
@@ -507,6 +508,72 @@ const Createorder1 = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const calculateDistance = async (pickup, drop) => {
|
||||||
|
const service = new google.maps.DistanceMatrixService();
|
||||||
|
|
||||||
|
const getDistanceMatrix = (origins, destinations, travelMode, unitSystem) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
service.getDistanceMatrix(
|
||||||
|
{
|
||||||
|
origins: [new google.maps.LatLng(origins.latitude, origins.longitude)],
|
||||||
|
destinations: [new google.maps.LatLng(destinations.latitude, destinations.longitude)],
|
||||||
|
travelMode: travelMode,
|
||||||
|
unitSystem: unitSystem
|
||||||
|
},
|
||||||
|
(response, status) => {
|
||||||
|
if (status === 'OK') {
|
||||||
|
resolve(response);
|
||||||
|
} else {
|
||||||
|
reject(new Error(`Error calculating distance: ${status}`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Use await to wait for the promise to resolve
|
||||||
|
const response = await getDistanceMatrix(pickup, drop, 'DRIVING', google.maps.UnitSystem.METRIC);
|
||||||
|
|
||||||
|
// Handle the response
|
||||||
|
const results = response.rows[0].elements;
|
||||||
|
for (let i = 0; i < results.length; i++) {
|
||||||
|
const element = results[i];
|
||||||
|
const distance = element.distance.value;
|
||||||
|
console.log('distance in m ', distance);
|
||||||
|
const distanceInKm = (distance / 1000).toFixed(2);
|
||||||
|
console.log('distance in km ', distanceInKm);
|
||||||
|
const roundedDistance = Math.round(distanceInKm);
|
||||||
|
console.log('roundedDistance', roundedDistance);
|
||||||
|
setDistance(roundedDistance);
|
||||||
|
if (roundedDistance < minKm) {
|
||||||
|
setTotalCharge(basePrice);
|
||||||
|
} else {
|
||||||
|
console.log('minKm', minKm);
|
||||||
|
console.log('pricePerKm', pricePerKm);
|
||||||
|
console.log('basePrice', basePrice);
|
||||||
|
const total = (roundedDistance - minKm) * pricePerKm + basePrice;
|
||||||
|
console.log('total', total);
|
||||||
|
setTotalCharge(total);
|
||||||
|
}
|
||||||
|
setShowDistance(true);
|
||||||
|
if (roundedDistance > appLocaRadius) {
|
||||||
|
setShowDistance(true);
|
||||||
|
setOpen4(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the numerical value of the duration
|
||||||
|
const durationMatch = element.duration.text.match(/([\d.]+)/);
|
||||||
|
const duration = durationMatch ? parseInt(durationMatch[0]) : null;
|
||||||
|
|
||||||
|
// Display only the numerical values
|
||||||
|
console.log(`Distance: ${roundedDistance}, Duration: ${duration}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error calculating distance:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (timeslotarr[0]) {
|
if (timeslotarr[0]) {
|
||||||
let arr = [];
|
let arr = [];
|
||||||
@@ -759,7 +826,7 @@ const Createorder1 = () => {
|
|||||||
applocationid: parseInt(localStorage.getItem('applocationid')),
|
applocationid: parseInt(localStorage.getItem('applocationid')),
|
||||||
deliveryid: clientinfo.customerid,
|
deliveryid: clientinfo.customerid,
|
||||||
pickuplocationid: tenantinfo.deliverylocationid,
|
pickuplocationid: tenantinfo.deliverylocationid,
|
||||||
kms: distance
|
kms: distance.toString()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -828,7 +895,7 @@ const Createorder1 = () => {
|
|||||||
deliverytype: pickCust.customerid !== 0 || dropCust.customerid !== 0 ? 'B' : 'C',
|
deliverytype: pickCust.customerid !== 0 || dropCust.customerid !== 0 ? 'B' : 'C',
|
||||||
delivered: '',
|
delivered: '',
|
||||||
itemcount: 1,
|
itemcount: 1,
|
||||||
kms: distance || 0,
|
kms: distance.toString() || 0,
|
||||||
locationid: +tenanatLocoId, //main or branch
|
locationid: +tenanatLocoId, //main or branch
|
||||||
moduleid: +tenant.moduleid,
|
moduleid: +tenant.moduleid,
|
||||||
orderamount: +totalCharge.toFixed(2) || 0,
|
orderamount: +totalCharge.toFixed(2) || 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user