mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE): Filter transaction subtypes based on selected product
flags
This commit is contained in:
@@ -206,10 +206,19 @@ const InventoryAdjustmentForm = ({
|
|||||||
value: pw.product.id,
|
value: pw.product.id,
|
||||||
label: pw.product.name,
|
label: pw.product.name,
|
||||||
quantity: pw.quantity,
|
quantity: pw.quantity,
|
||||||
|
flags: pw.product.flags,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
}, [productWarehouses]);
|
}, [productWarehouses]);
|
||||||
|
|
||||||
|
const selectedProductFlags = useMemo(() => {
|
||||||
|
if (!selectedProduct) return [];
|
||||||
|
const product = productOptions.find(
|
||||||
|
(opt) => opt.value === selectedProduct.value
|
||||||
|
);
|
||||||
|
return (product?.flags as string[]) || [];
|
||||||
|
}, [selectedProduct, productOptions]);
|
||||||
|
|
||||||
const ProductOption = useMemo(() => {
|
const ProductOption = useMemo(() => {
|
||||||
const OptionComponent = (
|
const OptionComponent = (
|
||||||
props: OptionProps<OptionType & { quantity?: number }, boolean>
|
props: OptionProps<OptionType & { quantity?: number }, boolean>
|
||||||
@@ -305,11 +314,43 @@ const InventoryAdjustmentForm = ({
|
|||||||
const transactionType = selectedTransactionType?.value;
|
const transactionType = selectedTransactionType?.value;
|
||||||
|
|
||||||
if (transactionType === 'RECORDING') {
|
if (transactionType === 'RECORDING') {
|
||||||
return [...TRANSACTION_SUBTYPE_OPTIONS.RECORDING];
|
const allRecordingOptions = [...TRANSACTION_SUBTYPE_OPTIONS.RECORDING];
|
||||||
|
|
||||||
|
if (selectedProductFlags.length > 0) {
|
||||||
|
const isEggProduct = selectedProductFlags.some((flag) =>
|
||||||
|
flag.startsWith('TELUR')
|
||||||
|
);
|
||||||
|
const isChickenProduct = selectedProductFlags.some(
|
||||||
|
(flag) =>
|
||||||
|
flag.startsWith('AYAM') ||
|
||||||
|
flag === 'DOC' ||
|
||||||
|
flag === 'PULLET' ||
|
||||||
|
flag === 'LAYER'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isEggProduct) {
|
||||||
|
// Produk telur: hanya RECORDING_EGG_IN
|
||||||
|
return allRecordingOptions.filter(
|
||||||
|
(opt) => opt.value === 'RECORDING_EGG_IN'
|
||||||
|
);
|
||||||
|
} else if (isChickenProduct) {
|
||||||
|
// Produk ayam: hanya RECORDING_DEPLETION_OUT
|
||||||
|
return allRecordingOptions.filter(
|
||||||
|
(opt) => opt.value === 'RECORDING_DEPLETION_OUT'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Produk non-telur dan non-ayam (PAKAN, OVK, dll): hanya RECORDING_STOCK_OUT
|
||||||
|
return allRecordingOptions.filter(
|
||||||
|
(opt) => opt.value === 'RECORDING_STOCK_OUT'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allRecordingOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}, [selectedTransactionType]);
|
}, [selectedTransactionType, selectedProductFlags]);
|
||||||
|
|
||||||
const isTransactionSubtypeReadonly = useMemo(() => {
|
const isTransactionSubtypeReadonly = useMemo(() => {
|
||||||
const transactionType = selectedTransactionType?.value;
|
const transactionType = selectedTransactionType?.value;
|
||||||
|
|||||||
Reference in New Issue
Block a user