fix: prioritize DO data if delivery orders exist

This commit is contained in:
ValdiANS
2026-04-09 16:36:59 +07:00
parent a725ae4891
commit bf5591d61d
@@ -203,6 +203,8 @@ export const mergeSOwithDO = (
deliveryOrders: DeliveryOrderProductFormValues[], deliveryOrders: DeliveryOrderProductFormValues[],
autofill?: boolean autofill?: boolean
): DeliveryOrderProductFormValues[] => { ): DeliveryOrderProductFormValues[] => {
const hasDeliveryOrders = deliveryOrders.length > 0;
return salesOrders.map((so) => { return salesOrders.map((so) => {
const delivery = deliveryOrders.find( const delivery = deliveryOrders.find(
(d) => d?.marketing_product_id === so.id (d) => d?.marketing_product_id === so.id
@@ -227,30 +229,50 @@ export const mergeSOwithDO = (
delivery_date: delivery?.delivery_date || undefined, delivery_date: delivery?.delivery_date || undefined,
do_number: delivery?.do_number || undefined, do_number: delivery?.do_number || undefined,
vehicle_number: delivery?.vehicle_number || so.vehicle_number, vehicle_number: delivery?.vehicle_number || so.vehicle_number,
unit_price: autofill ? delivery?.unit_price : salesOrderUnitPrice, unit_price:
total_weight: autofill ? delivery?.total_weight : so.total_weight, autofill && hasDeliveryOrders
qty: autofill ? delivery?.qty : so.qty, ? delivery?.unit_price
avg_weight: autofill ? delivery?.avg_weight : so.avg_weight, : salesOrderUnitPrice,
total_price: autofill ? delivery?.total_price : so.total_price, total_weight:
autofill && hasDeliveryOrders
? delivery?.total_weight
: so.total_weight,
qty: autofill && hasDeliveryOrders ? delivery?.qty : so.qty,
avg_weight:
autofill && hasDeliveryOrders ? delivery?.avg_weight : so.avg_weight,
total_price:
autofill && hasDeliveryOrders ? delivery?.total_price : so.total_price,
marketing_product: so, // jika ada, override marketing_product: so, // jika ada, override
uom: autofill ? delivery?.uom : so.uom, uom: autofill && hasDeliveryOrders ? delivery?.uom : so.uom,
weight_per_convertion: autofill weight_per_convertion:
autofill && hasDeliveryOrders
? delivery?.weight_per_convertion ? delivery?.weight_per_convertion
: so.weight_per_convertion, : so.weight_per_convertion,
price_per_convertion: autofill price_per_convertion:
autofill && hasDeliveryOrders
? delivery?.price_per_convertion ? delivery?.price_per_convertion
: so.price_per_convertion, : so.price_per_convertion,
convertion_unit: autofill convertion_unit:
autofill && hasDeliveryOrders
? delivery?.convertion_unit ? delivery?.convertion_unit
: so.convertion_unit, : so.convertion_unit,
marketing_type: autofill ? delivery?.marketing_type : so.marketing_type, marketing_type:
total_peti: autofill ? delivery?.total_peti : so.total_peti, autofill && hasDeliveryOrders
price_per_qty: autofill ? delivery?.price_per_qty : salesOrderPricePerQty, ? delivery?.marketing_type
sisa_berat: autofill ? delivery?.sisa_berat : so.sisa_berat, : so.marketing_type,
price_sisa_berat: autofill total_peti:
autofill && hasDeliveryOrders ? delivery?.total_peti : so.total_peti,
price_per_qty:
autofill && hasDeliveryOrders
? delivery?.price_per_qty
: salesOrderPricePerQty,
sisa_berat:
autofill && hasDeliveryOrders ? delivery?.sisa_berat : so.sisa_berat,
price_sisa_berat:
autofill && hasDeliveryOrders
? delivery?.price_sisa_berat ? delivery?.price_sisa_berat
: so.price_sisa_berat, : so.price_sisa_berat,
week: autofill ? delivery?.week : so.week, week: autofill && hasDeliveryOrders ? delivery?.week : so.week,
} as DeliveryOrderProductFormValues; } as DeliveryOrderProductFormValues;
}); });
}; };