fix: adjust DeliveryProductToFieldValues and mergeSOwithDO return values

This commit is contained in:
ValdiANS
2026-04-09 11:09:04 +07:00
parent 095b1c5850
commit 1dafb0d365
@@ -144,15 +144,15 @@ export const DeliveryProductToFieldValues = (
delivery: BaseDeliveryOrder
): DeliveryOrderProductFormValues[] => {
const data = delivery.deliveries.map((item) => {
const soId = salesOrders.find(
const salesOrder = salesOrders.find(
(so) => so.product_warehouse.id === item.product_warehouse.id
)?.id;
);
const warehouseOption = {
value: item.product_warehouse.warehouse.id,
label: item.product_warehouse.warehouse.name,
};
return {
id: soId,
id: salesOrder?.id,
unit_price: item.unit_price,
total_weight: item.total_weight,
qty: item.qty,
@@ -161,9 +161,21 @@ export const DeliveryProductToFieldValues = (
vehicle_number: item.vehicle_number,
delivery_date: formatDate(delivery.delivery_date, 'yyyy-MM-DD'),
do_number: delivery.do_number,
marketing_product_id: soId,
marketing_product_id: salesOrder?.id,
marketing_type: salesOrder?.marketing_type
? {
value: salesOrder?.marketing_type,
label: formatTitleCase(salesOrder?.marketing_type),
}
: null,
convertion_unit: salesOrder?.convertion_unit
? {
value: salesOrder?.convertion_unit.toLowerCase(),
label: formatTitleCase(salesOrder?.convertion_unit),
}
: null,
marketing_product: {
id: soId,
id: salesOrder?.id,
vehicle_number: item.vehicle_number,
warehouse_id: item.product_warehouse.warehouse.id,
warehouse: warehouseOption,
@@ -183,6 +195,7 @@ export const DeliveryProductToFieldValues = (
},
} as DeliveryOrderProductFormValues;
});
return data;
};
export const mergeSOwithDO = (
@@ -214,30 +227,30 @@ export const mergeSOwithDO = (
delivery_date: delivery?.delivery_date || undefined,
do_number: delivery?.do_number || undefined,
vehicle_number: delivery?.vehicle_number || so.vehicle_number,
unit_price: autofill ? salesOrderUnitPrice : delivery?.unit_price,
total_weight: autofill ? so.total_weight : delivery?.total_weight,
qty: autofill ? so.qty : delivery?.qty,
avg_weight: autofill ? so.avg_weight : delivery?.avg_weight,
total_price: autofill ? so.total_price : delivery?.total_price,
unit_price: autofill ? delivery?.unit_price : salesOrderUnitPrice,
total_weight: autofill ? delivery?.total_weight : so.total_weight,
qty: autofill ? delivery?.qty : so.qty,
avg_weight: autofill ? delivery?.avg_weight : so.avg_weight,
total_price: autofill ? delivery?.total_price : so.total_price,
marketing_product: so, // jika ada, override
uom: autofill ? so.uom : delivery?.uom,
uom: autofill ? delivery?.uom : so.uom,
weight_per_convertion: autofill
? so.weight_per_convertion
: delivery?.weight_per_convertion,
? delivery?.weight_per_convertion
: so.weight_per_convertion,
price_per_convertion: autofill
? so.price_per_convertion
: delivery?.price_per_convertion,
? delivery?.price_per_convertion
: so.price_per_convertion,
convertion_unit: autofill
? so.convertion_unit
: delivery?.convertion_unit,
marketing_type: autofill ? so.marketing_type : delivery?.marketing_type,
total_peti: autofill ? so.total_peti : delivery?.total_peti,
price_per_qty: autofill ? salesOrderPricePerQty : delivery?.price_per_qty,
sisa_berat: autofill ? so.sisa_berat : delivery?.sisa_berat,
? delivery?.convertion_unit
: so.convertion_unit,
marketing_type: autofill ? delivery?.marketing_type : so.marketing_type,
total_peti: autofill ? delivery?.total_peti : so.total_peti,
price_per_qty: autofill ? delivery?.price_per_qty : salesOrderPricePerQty,
sisa_berat: autofill ? delivery?.sisa_berat : so.sisa_berat,
price_sisa_berat: autofill
? so.price_sisa_berat
: delivery?.price_sisa_berat,
week: autofill ? so.week : delivery?.week,
? delivery?.price_sisa_berat
: so.price_sisa_berat,
week: autofill ? delivery?.week : so.week,
} as DeliveryOrderProductFormValues;
});
};