diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-26 10:47:58 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-02-26 10:47:58 +0700 |
| commit | 58601bc17b6f0516eee9c36aa36e39f1dea3ad77 (patch) | |
| tree | 1223647d2e4c80603685fb97532b85649a8edc37 /src/lib/checkout/components | |
| parent | fdb488651e864cf30f09fe2337187241ef649177 (diff) | |
bitehsip
Diffstat (limited to 'src/lib/checkout/components')
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 14 | ||||
| -rw-r--r-- | src/lib/checkout/components/SectionExpedition.jsx | 23 |
2 files changed, 17 insertions, 20 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 3ad833ec..1a7fdc03 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -165,6 +165,7 @@ const Checkout = () => { etd, unit, selectedCourier, + selectedCourierId, selectedService, listExpedisi, setExpedisi, @@ -447,6 +448,10 @@ const Checkout = () => { quantity: product.quantity, available_quantity: product?.availableQuantity, })); + let estimated_courier = etd.split('-').map(Number); + let eta_courier = Math.max(...estimated_courier); + let eta_courier_start = Math.min(...estimated_courier); + let data = { // partner_shipping_id: auth.partnerId,, // partner_invoice_id: auth.partnerId, @@ -455,8 +460,9 @@ const Checkout = () => { user_id: auth.id, order_line: JSON.stringify(productOrder), delivery_amount: biayaKirim, - carrier_id: selectedCourier, - estimated_arrival_days: getToDate(etd, unit), + carrier_id: selectedCourierId, + estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla), + estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla), delivery_service_type: selectedService?.service_type, flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false voucher: activeVoucher, @@ -469,6 +475,8 @@ const Checkout = () => { if (poNumber.current.value) data.po_number = poNumber.current.value; if (typeof file !== 'undefined') data.po_file = await getFileBase64(file); + console.log('ini data', data); + const isCheckouted = await checkoutApi({ data }); if (!isCheckouted?.id) { @@ -1297,7 +1305,6 @@ const Checkout = () => { className='flex-1 btn-yellow' onClick={checkout} disabled={ - isLoading || !products || products?.length == 0 || priceCheck || @@ -1603,7 +1610,6 @@ const Checkout = () => { className='w-full btn-yellow mt-4' onClick={checkout} disabled={ - isLoading || !products || products?.length == 0 || priceCheck || diff --git a/src/lib/checkout/components/SectionExpedition.jsx b/src/lib/checkout/components/SectionExpedition.jsx index a00858e5..b261cae0 100644 --- a/src/lib/checkout/components/SectionExpedition.jsx +++ b/src/lib/checkout/components/SectionExpedition.jsx @@ -49,7 +49,7 @@ function reverseMappingCourier(couriersOdoo, couriers, includeInstant = false) { shipment_range: item.shipment_duration_range, shipment_unit: item.shipment_duration_unit, price: item.price, - service_type: item.service_type, + service_type: courier_service_code, description: item.description, }; @@ -81,13 +81,6 @@ function reverseMappingCourier(couriersOdoo, couriers, includeInstant = false) { } -function isHiloday(){ - const today = new Date(); - const day = today.getDay(); - - return day === 6 || day === 7 -} - function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) { const validCourierMap = couriersOdoo.reduce((acc, courier) => { acc[courier.label.toLowerCase()] = courier.carrierId; @@ -144,9 +137,6 @@ function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) { }, {}); } -function hasCanInstantFalse(items) { - return items.some((item) => item.canInstant === false); -} // interface CourierService { // courier_name: string; @@ -181,6 +171,7 @@ export default function SectionExpedition({ products }) { const [onFocusSelectedCourier, setOnFocuseSelectedCourier] = useState(false); const [couriers, setCouriers] = useState(null); const [slaProducts, setSlaProducts] = useState(null); + const [addHolidays, setAddHolidays] = useState(0); const { checkWeigth, @@ -194,7 +185,8 @@ export default function SectionExpedition({ products }) { setSelectedService, listExpedisi, productSla, - setProductSla + setProductSla, + setSelectedCourierId } = useCheckout(); let destination = {}; @@ -217,7 +209,6 @@ export default function SectionExpedition({ products }) { try { const ids = products.map((p) => p.id).join(',') const res = await odooApi('GET', `/api/v1/product/variants/sla?ids=${ids}`) - setSlaProducts(res); } catch (error) { console.error('Failed to fetch expedition rates:', error); @@ -230,7 +221,7 @@ export default function SectionExpedition({ products }) { useEffect(() => { if (slaProducts) { - let productSla = slaProducts?.slaDuration + let productSla = slaProducts?.slaTotal if(slaProducts.slaUnit === 'jam') { productSla = 1 } @@ -282,11 +273,13 @@ export default function SectionExpedition({ products }) { setIsOpen(false); setOnFocuseSelectedCourier(false); const courier = code; + console.log('ini courier', courier, couriers); setSelectedService(null); setBiayaKirim(0); if (courier !== 0 && courier !== 32) { if (courier.courier) { setSelectedCourier(courier.courier.courier_code); + setSelectedCourierId(courier.carrierId) setServiceOptions(Object.values(courier.courier.service_type)); } else { if ( @@ -328,8 +321,6 @@ export default function SectionExpedition({ products }) { setIsOpen(false); }; - console.log('ini selectedCourier', couriers); - return ( <form onSubmit={handleSubmit(onSubmit)}> <div className='px-4 py-2'> |
