Merge branch 'development' of gitlab.com:mbugroup/lti-web-client into dev/hotfix/restu

This commit is contained in:
rstubryan
2026-01-22 14:48:38 +07:00
5 changed files with 150 additions and 58 deletions
@@ -444,7 +444,13 @@ const DashboardProduction = () => {
)?.value === 'FARM' ? (
<SelectInputCheckbox
label='Farm'
value={formik.values.location}
value={
formik.values.location as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined
}
onInputChange={setInputValueLocation}
onMenuScrollToBottom={loadMoreLocation}
onChange={(selected) => {
@@ -466,7 +472,13 @@ const DashboardProduction = () => {
) : (
<SelectInputRadio
label='Farm'
value={formik.values.location as OptionType}
value={
formik.values.location as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined
}
onInputChange={setInputValueLocation}
onMenuScrollToBottom={loadMoreLocation}
onChange={(selected) => {
@@ -502,7 +514,13 @@ const DashboardProduction = () => {
)?.value === 'FLOCK' ? (
<SelectInputCheckbox
label='Flock'
value={formik.values.flock as OptionType[]}
value={
formik.values.flock as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined
}
onChange={(selected) =>
formik.setFieldValue('flock', selected)
}
@@ -519,7 +537,13 @@ const DashboardProduction = () => {
) : (
<SelectInputRadio
label='Flock'
value={formik.values.flock as OptionType}
value={
formik.values.flock as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined
}
onChange={(selected) =>
formik.setFieldValue('flock', selected)
}
@@ -548,7 +572,13 @@ const DashboardProduction = () => {
)?.value === 'KANDANG' ? (
<SelectInputCheckbox
label='Kandang'
value={formik.values.kandang as OptionType[]}
value={
formik.values.kandang as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined
}
onChange={(selected) =>
formik.setFieldValue('kandang', selected)
}
@@ -565,7 +595,13 @@ const DashboardProduction = () => {
) : (
<SelectInputRadio
label='Kandang'
value={formik.values.kandang as OptionType}
value={
formik.values.kandang as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined
}
onChange={(selected) =>
formik.setFieldValue('kandang', selected)
}
@@ -54,9 +54,6 @@ const FormFinanceAdd = ({
}: FormFinanceAddProps) => {
const router = useRouter();
const [serverErrorMessage, setServerErrorMessage] = useState('');
const [isSupplier, setIsSupplier] = useState(
initialValues?.party?.type === 'SUPPLIER'
);
// ===== Formik =====
const formikInitialValues = useMemo((): FinanceFormValues => {
@@ -215,7 +212,7 @@ const FormFinanceAdd = ({
? formik.errors.party_type_option
: ''
}
isDisabled={type === 'edit' || isSupplier}
isDisabled={type === 'edit'}
required
isClearable
/>
@@ -254,7 +251,7 @@ const FormFinanceAdd = ({
}
required
isClearable
isDisabled={!formik.values.party_type_option?.value || isSupplier}
isDisabled={!formik.values.party_type_option?.value}
/>
<DateInput
label='Tanggal'
@@ -272,7 +269,6 @@ const FormFinanceAdd = ({
: ''
}
required
disabled={isSupplier}
/>
<SelectInput
label='Metode Pembayaran'
@@ -294,7 +290,6 @@ const FormFinanceAdd = ({
}
required
isClearable
isDisabled={isSupplier}
/>
<SelectInput
label='Bank'
@@ -335,7 +330,6 @@ const FormFinanceAdd = ({
}
required
isClearable
isDisabled={isSupplier}
/>
<TextInput
label={`Nomor Rekening ${formik.values.party_type_option?.value ? formatTitleCase(formik.values.party_type_option.value as string) : 'Pihak'}`}
@@ -356,7 +350,6 @@ const FormFinanceAdd = ({
}
required
readOnly
disabled={isSupplier}
/>
<TextInput
label='Nomor Referensi'
@@ -376,7 +369,6 @@ const FormFinanceAdd = ({
: ''
}
required
disabled={isSupplier}
/>
<NumberInput
label='Nominal'
@@ -392,7 +384,6 @@ const FormFinanceAdd = ({
: ''
}
required
disabled={isSupplier}
/>
<TextArea
label='Catatan'
@@ -408,7 +399,6 @@ const FormFinanceAdd = ({
: ''
}
required
disabled={isSupplier}
/>
<AlertErrorList formErrorList={formErrorList} onClose={close} />
{serverErrorMessage && (
@@ -143,11 +143,13 @@ const DeliveryOrderProductForm = ({
// ===== SOURCE FIELDS =====
case 'qty': {
if (avgWeight > 0) {
formik.setFieldValue('total_weight', roundWeight(qty * avgWeight));
}
const tw = roundWeight(qty * avgWeight);
formik.setFieldValue('total_weight', tw);
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
// Hitung total_price berdasarkan unit_price × total_weight
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
}
}
break;
}
@@ -157,16 +159,21 @@ const DeliveryOrderProductForm = ({
const tw = roundWeight(qty * avgWeight);
formik.setFieldValue('total_weight', tw);
// Hitung total_price berdasarkan unit_price × total_weight
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
}
}
break;
}
case 'unit_price': {
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
if (unitPrice > 0 && totalWeight > 0) {
// Hitung total_price berdasarkan unit_price × total_weight
formik.setFieldValue(
'total_price',
roundPrice(unitPrice * totalWeight)
);
}
break;
}
@@ -175,13 +182,25 @@ const DeliveryOrderProductForm = ({
case 'total_weight': {
if (totalWeight > 0) {
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
// Hitung ulang total_price berdasarkan unit_price × total_weight
if (unitPrice > 0) {
formik.setFieldValue(
'total_price',
roundPrice(unitPrice * totalWeight)
);
}
}
break;
}
case 'total_price': {
if (totalPrice > 0) {
formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
if (totalPrice > 0 && totalWeight > 0) {
// Hitung unit_price berdasarkan total_price / total_weight
formik.setFieldValue(
'unit_price',
roundPrice(totalPrice / totalWeight)
);
}
break;
}
@@ -382,7 +401,7 @@ const DeliveryOrderProductForm = ({
/>
<NumberInput
required
label='Harga Satuan (Rp)'
label={`Harga / ${isResponseSuccess(productData) ? productData?.data?.uom?.name : 'Produk'} (Rp)`}
name='unit_price'
value={formik.values.unit_price}
onChange={(e) => {
@@ -49,17 +49,6 @@ const SalesOrderProductForm = ({
const [selectedProductWarehouse, setSelectedProductWarehouse] =
useState<ProductWarehouse | null>(null);
// ============ Fetch Data ============
const { data: productData } = useSWR(
selectedProductWarehouse?.product_id
? ProductApi.basePath + '/' + selectedProductWarehouse?.product_id
: null,
() =>
selectedProductWarehouse?.product_id
? ProductApi.getSingle(selectedProductWarehouse?.product_id)
: undefined
);
// ============ Formik ============
const formik = useFormik<SalesOrderProductFormValues>({
enableReinitialize: true,
@@ -174,15 +163,28 @@ const SalesOrderProductForm = ({
if (qty <= 0) return;
// Cek apakah produk memiliki flag OVK atau PAKAN
const productFlags = selectedProductWarehouse?.product?.flags || [];
const isOvkOrPakan =
productFlags.includes('OVK') || productFlags.includes('PAKAN');
switch (field) {
// ===== SOURCE FIELDS =====
case 'qty': {
if (avgWeight > 0) {
formik.setFieldValue('total_weight', roundWeight(qty * avgWeight));
}
const tw = roundWeight(qty * avgWeight);
formik.setFieldValue('total_weight', tw);
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
// Hitung total_price berdasarkan flag produk
if (unitPrice > 0) {
if (isOvkOrPakan) {
// Untuk OVK/PAKAN: total_price = qty × unit_price
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
} else {
// Untuk produk lain: total_price = unit_price × total_weight
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
}
}
}
break;
}
@@ -192,8 +194,15 @@ const SalesOrderProductForm = ({
const tw = roundWeight(qty * avgWeight);
formik.setFieldValue('total_weight', tw);
// Hitung total_price berdasarkan flag produk
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
if (isOvkOrPakan) {
// Untuk OVK/PAKAN: total_price = qty × unit_price
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
} else {
// Untuk produk lain: total_price = unit_price × total_weight
formik.setFieldValue('total_price', roundPrice(unitPrice * tw));
}
}
}
break;
@@ -201,7 +210,16 @@ const SalesOrderProductForm = ({
case 'unit_price': {
if (unitPrice > 0) {
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
if (isOvkOrPakan) {
// Untuk OVK/PAKAN: total_price = qty × unit_price
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
} else if (totalWeight > 0) {
// Untuk produk lain: total_price = unit_price × total_weight
formik.setFieldValue(
'total_price',
roundPrice(unitPrice * totalWeight)
);
}
}
break;
}
@@ -210,13 +228,36 @@ const SalesOrderProductForm = ({
case 'total_weight': {
if (totalWeight > 0) {
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
// Hitung ulang total_price berdasarkan flag produk
if (unitPrice > 0) {
if (isOvkOrPakan) {
// Untuk OVK/PAKAN: total_price = qty × unit_price
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
} else {
// Untuk produk lain: total_price = unit_price × total_weight
formik.setFieldValue(
'total_price',
roundPrice(unitPrice * totalWeight)
);
}
}
}
break;
}
case 'total_price': {
if (totalPrice > 0) {
formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
if (isOvkOrPakan && qty > 0) {
// Untuk OVK/PAKAN: unit_price = total_price / qty
formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
} else if (totalWeight > 0) {
// Untuk produk lain: unit_price = total_price / total_weight
formik.setFieldValue(
'unit_price',
roundPrice(totalPrice / totalWeight)
);
}
}
break;
}
@@ -232,7 +273,7 @@ const SalesOrderProductForm = ({
handleBlurField(currentInput);
formik.setFieldValue(
'uom',
isResponseSuccess(productData) ? productData?.data?.uom.name : ''
selectedProductWarehouse?.product?.uom?.name
);
},
}
@@ -330,9 +371,7 @@ const SalesOrderProductForm = ({
endAdornment={
<div className='flex items-center gap-2'>
<span className='text-sm text-gray-500'>
{isResponseSuccess(productData)
? productData?.data?.uom.name
: ''}
{selectedProductWarehouse?.product?.uom?.name}
</span>
</div>
}
@@ -343,17 +382,13 @@ const SalesOrderProductForm = ({
warehouseSourceRawData?.data?.find(
(item) => item.id === formik.values.product_warehouse_id
)?.quantity ?? 0
)} ${
isResponseSuccess(productData)
? productData?.data?.uom.name
: ''
}`
)} ${selectedProductWarehouse?.product?.uom?.name}`
: ''
}
/>
<NumberInput
required
label='Harga Satuan (Rp)'
label={`Harga / ${selectedProductWarehouse?.product?.uom?.name ?? 'Produk'} (Rp)`}
name='unit_price'
value={formik.values.unit_price}
onChange={(e) => {
@@ -678,7 +678,13 @@ const DebtSupplierTab = () => {
placeholder='Pilih Supplier'
isMulti
options={supplierOptions}
value={formik.values.supplierIds || []}
value={
(formik.values.supplierIds as
| { value: number; label: string }
| { value: number; label: string }[]
| null
| undefined) || []
}
onChange={(val) => {
formik.setFieldValue(
'supplierIds',
@@ -702,7 +708,13 @@ const DebtSupplierTab = () => {
label='Filter Berdasarkan'
placeholder='Pilih Filter Berdasarkan'
options={dataTypeOptions}
value={formik.values.filterBy || null}
value={
(formik.values.filterBy as
| { value: string; label: string }
| { value: string; label: string }[]
| null
| undefined) || null
}
onChange={(val) => {
formik.setFieldValue(
'filterBy',