This commit is contained in:
Андрей Дувакин 2024-10-08 11:18:39 +05:00
parent 7dbf147cef
commit 09d0b03834

View File

@ -43,7 +43,6 @@ const DeliveryOrderDetails = () => {
useEffect(() => {
fetchDeliveryOrder();
fetchDeliveryAccessories();
}, [deliveryOrderId]);
const formatDuration = (minutes) => {
@ -74,6 +73,9 @@ const DeliveryOrderDetails = () => {
try {
const order = await getTotalOrder(orderId);
setTotalOrder(order);
if (order) {
fetchDeliveryAccessories(order);
}
} catch (error) {
if (error.response && error.response.status === 401) {
navigate("/login");
@ -82,7 +84,7 @@ const DeliveryOrderDetails = () => {
}
};
const fetchDeliveryAccessories = async () => {
const fetchDeliveryAccessories = async (totalOrder) => {
try {
const deliveryOrderDetails = await getDeliveryOrderDetails(
deliveryOrderId
@ -95,12 +97,17 @@ const DeliveryOrderDetails = () => {
const accessories = await getDeliveryAccessories(deliveryOrderId);
setDeliveryAccessories(accessories);
if (totalOrder) {
const totalWeightCalculated = accessories.reduce((acc, accessory) => {
return (
acc + Math.round((accessory.accessory_weight * accessory.count) / 100)
acc +
Math.round(
(accessory.accessory_weight / 100) * totalOrder.count_robots
)
);
}, 0);
setTotalWeight(totalWeightCalculated);
}
const coords = await Promise.all(
accessories.map(async (accessory) => {
@ -256,12 +263,8 @@ const DeliveryOrderDetails = () => {
</td>
<td>
{Math.round(
(Math.round(
(accessory.accessory_volume / 100) *
(accessory.accessory_weight / 100) *
totalOrder.count_robots
) /
100) *
accessory.accessory_weight
)}
</td>
</tr>