mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Merge branch 'fix/marketing' into 'development'
[FIX/FE] Fixing Module Marketing Change UI Layout See merge request mbugroup/lti-web-client!178
This commit is contained in:
@@ -11,6 +11,13 @@ import {
|
|||||||
type MarketingSchemaType = {
|
type MarketingSchemaType = {
|
||||||
customer_id: number | undefined;
|
customer_id: number | undefined;
|
||||||
sales_person_id: number | undefined;
|
sales_person_id: number | undefined;
|
||||||
|
sales_person:
|
||||||
|
| {
|
||||||
|
value: number;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
| undefined
|
||||||
|
| null;
|
||||||
customer:
|
customer:
|
||||||
| {
|
| {
|
||||||
value: number;
|
value: number;
|
||||||
@@ -33,7 +40,11 @@ type DeliveryOrderSchemaType = {
|
|||||||
export const SalesOrderSchema: Yup.ObjectSchema<SalesOrderSchemaType> =
|
export const SalesOrderSchema: Yup.ObjectSchema<SalesOrderSchemaType> =
|
||||||
Yup.object({
|
Yup.object({
|
||||||
customer_id: Yup.number().required('Customer wajib diisi!'),
|
customer_id: Yup.number().required('Customer wajib diisi!'),
|
||||||
sales_person_id: Yup.number().required('Sales Person wajib diisi!'),
|
sales_person_id: Yup.number().required('Sales wajib diisi!'),
|
||||||
|
sales_person: Yup.object({
|
||||||
|
value: Yup.number().required(),
|
||||||
|
label: Yup.string().required(),
|
||||||
|
}).nullable(),
|
||||||
customer: Yup.object({
|
customer: Yup.object({
|
||||||
value: Yup.number().required(),
|
value: Yup.number().required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ import { DeliveryOrderProductFormValues } from '@/components/pages/marketing/for
|
|||||||
import RequirePermission from '@/components/helper/RequirePermission';
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import { CreatedUser } from '@/types/api/api-general';
|
||||||
|
import { UserApi } from '@/services/api/user';
|
||||||
|
|
||||||
const MemoizedSalesOrderProductTable = memo(SalesOrderProductTable);
|
const MemoizedSalesOrderProductTable = memo(SalesOrderProductTable);
|
||||||
const MemoizedSalesOrderProductForm = memo(SalesOrderProductForm);
|
const MemoizedSalesOrderProductForm = memo(SalesOrderProductForm);
|
||||||
@@ -244,7 +246,15 @@ const MarketingForm = ({
|
|||||||
const {
|
const {
|
||||||
options: customerOptions,
|
options: customerOptions,
|
||||||
isLoadingOptions: isLoadingCustomerOptions,
|
isLoadingOptions: isLoadingCustomerOptions,
|
||||||
|
setInputValue: setInputCustomerValue,
|
||||||
|
loadMore: loadMoreCustomer,
|
||||||
} = useSelect<Customer>(CustomerApi.basePath, 'id', 'name');
|
} = useSelect<Customer>(CustomerApi.basePath, 'id', 'name');
|
||||||
|
const {
|
||||||
|
options: salesOptions,
|
||||||
|
isLoadingOptions: isLoadingSalesOptions,
|
||||||
|
setInputValue: setInputSalesValue,
|
||||||
|
loadMore: loadMoreSales,
|
||||||
|
} = useSelect<CreatedUser>(UserApi.basePath, 'id', 'name');
|
||||||
|
|
||||||
// ================== SETUP FORMIK ==================
|
// ================== SETUP FORMIK ==================
|
||||||
const formikInitialValues = useMemo<
|
const formikInitialValues = useMemo<
|
||||||
@@ -255,6 +265,12 @@ const MarketingForm = ({
|
|||||||
notes: initialValues?.notes || undefined,
|
notes: initialValues?.notes || undefined,
|
||||||
customer_id: initialValues?.customer?.id || undefined,
|
customer_id: initialValues?.customer?.id || undefined,
|
||||||
sales_person_id: initialValues?.sales_person?.id || 1,
|
sales_person_id: initialValues?.sales_person?.id || 1,
|
||||||
|
sales_person: initialValues?.sales_person
|
||||||
|
? {
|
||||||
|
value: initialValues.sales_person.id,
|
||||||
|
label: initialValues.sales_person.name,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
customer: initialValues?.customer
|
customer: initialValues?.customer
|
||||||
? {
|
? {
|
||||||
value: initialValues.customer.id,
|
value: initialValues.customer.id,
|
||||||
@@ -443,6 +459,13 @@ const MarketingForm = ({
|
|||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
const handleChangeSalesPerson = useCallback(
|
||||||
|
(val: OptionType | OptionType[] | null) => {
|
||||||
|
formik.setFieldValue('sales_person_id', (val as OptionType)?.value);
|
||||||
|
formik.setFieldValue('sales_person', val as OptionType);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
const handleDelete = useCallback(() => {
|
const handleDelete = useCallback(() => {
|
||||||
deleteModal.openModal();
|
deleteModal.openModal();
|
||||||
}, [deleteModal]);
|
}, [deleteModal]);
|
||||||
@@ -580,6 +603,7 @@ const MarketingForm = ({
|
|||||||
className={{
|
className={{
|
||||||
wrapper: 'bg-white w-full',
|
wrapper: 'bg-white w-full',
|
||||||
}}
|
}}
|
||||||
|
variant='bordered'
|
||||||
>
|
>
|
||||||
<div className='grid sm:grid-cols-2 gap-3 mt-3'>
|
<div className='grid sm:grid-cols-2 gap-3 mt-3'>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
@@ -588,6 +612,8 @@ const MarketingForm = ({
|
|||||||
isLoading={isLoadingCustomerOptions}
|
isLoading={isLoadingCustomerOptions}
|
||||||
value={formik.values.customer}
|
value={formik.values.customer}
|
||||||
onChange={handleChangeCustomer}
|
onChange={handleChangeCustomer}
|
||||||
|
onInputChange={setInputCustomerValue}
|
||||||
|
onMenuScrollToBottom={loadMoreCustomer}
|
||||||
isError={
|
isError={
|
||||||
formik.touched.customer_id && Boolean(formik.errors.customer_id)
|
formik.touched.customer_id && Boolean(formik.errors.customer_id)
|
||||||
}
|
}
|
||||||
@@ -617,6 +643,7 @@ const MarketingForm = ({
|
|||||||
className={{
|
className={{
|
||||||
wrapper: 'bg-white w-full',
|
wrapper: 'bg-white w-full',
|
||||||
}}
|
}}
|
||||||
|
variant='bordered'
|
||||||
>
|
>
|
||||||
<MemoizedSalesOrderProductTable
|
<MemoizedSalesOrderProductTable
|
||||||
formType={formType}
|
formType={formType}
|
||||||
@@ -651,6 +678,26 @@ const MarketingForm = ({
|
|||||||
|
|
||||||
{/* Input Notes */}
|
{/* Input Notes */}
|
||||||
<div className='grid sm:grid-cols-2 gap-3'>
|
<div className='grid sm:grid-cols-2 gap-3'>
|
||||||
|
<div className='flex flex-col h-full items-end gap-3'>
|
||||||
|
<SelectInput
|
||||||
|
label='Sales'
|
||||||
|
options={salesOptions}
|
||||||
|
isLoading={isLoadingSalesOptions}
|
||||||
|
value={formik.values.sales_person}
|
||||||
|
onChange={handleChangeSalesPerson}
|
||||||
|
onInputChange={setInputSalesValue}
|
||||||
|
onMenuScrollToBottom={loadMoreSales}
|
||||||
|
isError={
|
||||||
|
formik.touched.sales_person_id &&
|
||||||
|
Boolean(formik.errors.sales_person_id)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.sales_person_id}
|
||||||
|
isClearable
|
||||||
|
placeholder='Pilih Sales'
|
||||||
|
isDisabled={
|
||||||
|
formType === 'add_deliver' || formType === 'edit_deliver'
|
||||||
|
}
|
||||||
|
/>
|
||||||
<DebouncedTextArea
|
<DebouncedTextArea
|
||||||
required
|
required
|
||||||
name='notes'
|
name='notes'
|
||||||
@@ -661,9 +708,12 @@ const MarketingForm = ({
|
|||||||
onChange={formik.handleChange}
|
onChange={formik.handleChange}
|
||||||
isError={formik.touched.notes && Boolean(formik.errors.notes)}
|
isError={formik.touched.notes && Boolean(formik.errors.notes)}
|
||||||
errorMessage={formik.errors.notes}
|
errorMessage={formik.errors.notes}
|
||||||
disabled={formType === 'add_deliver' || formType === 'edit_deliver'}
|
disabled={
|
||||||
|
formType === 'add_deliver' || formType === 'edit_deliver'
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<div className='flex flex-col h-full justify-between items-end py-6'>
|
</div>
|
||||||
|
<div className='flex flex-col h-full justify-end items-end'>
|
||||||
<span>Total Penjualan</span>
|
<span>Total Penjualan</span>
|
||||||
<span className='text-lg font-semibold'>
|
<span className='text-lg font-semibold'>
|
||||||
{formatCurrency(grandTotal)}{' '}
|
{formatCurrency(grandTotal)}{' '}
|
||||||
|
|||||||
+99
-35
@@ -18,6 +18,11 @@ import * as Yup from 'yup';
|
|||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import { ProductApi } from '@/services/api/master-data';
|
||||||
|
|
||||||
|
const roundWeight = (value: number) => Number(value.toFixed(2));
|
||||||
|
const roundPrice = (value: number) => Math.round(value);
|
||||||
|
|
||||||
const DeliveryOrderProductForm = ({
|
const DeliveryOrderProductForm = ({
|
||||||
formState,
|
formState,
|
||||||
@@ -43,6 +48,17 @@ const DeliveryOrderProductForm = ({
|
|||||||
);
|
);
|
||||||
const [currentInput, setCurrentInput] = useState<string>('');
|
const [currentInput, setCurrentInput] = useState<string>('');
|
||||||
|
|
||||||
|
// ============ Fetch Data ============
|
||||||
|
const { data: productData } = useSWR(
|
||||||
|
selectedProduct?.value
|
||||||
|
? ProductApi.basePath + '/' + selectedProduct?.value
|
||||||
|
: null,
|
||||||
|
() =>
|
||||||
|
selectedProduct?.value
|
||||||
|
? ProductApi.getSingle(Number(selectedProduct?.value))
|
||||||
|
: undefined
|
||||||
|
);
|
||||||
|
|
||||||
const salesOrder = salesOrders.find(
|
const salesOrder = salesOrders.find(
|
||||||
(item) => item.id === initialValues?.marketing_product_id
|
(item) => item.id === initialValues?.marketing_product_id
|
||||||
);
|
);
|
||||||
@@ -113,22 +129,60 @@ const DeliveryOrderProductForm = ({
|
|||||||
|
|
||||||
const handleBlurField = (field: string) => {
|
const handleBlurField = (field: string) => {
|
||||||
setCurrentInput(field);
|
setCurrentInput(field);
|
||||||
const { qty, unit_price, total_price, avg_weight, total_weight } =
|
|
||||||
formik.values;
|
|
||||||
|
|
||||||
if (field === 'unit_price' || field === 'total_price' || field === 'qty') {
|
const qty = Number(formik.values.qty || 0);
|
||||||
if (qty && unit_price && (field === 'unit_price' || field === 'qty')) {
|
const avgWeight = Number(formik.values.avg_weight || 0);
|
||||||
formik.setFieldValue('total_price', Number(qty) * Number(unit_price));
|
const totalWeight = Number(formik.values.total_weight || 0);
|
||||||
} else if (qty && total_price && field === 'total_price') {
|
const unitPrice = Number(formik.values.unit_price || 0);
|
||||||
formik.setFieldValue('unit_price', Number(total_price) / Number(qty));
|
const totalPrice = Number(formik.values.total_price || 0);
|
||||||
}
|
|
||||||
|
if (qty <= 0) return;
|
||||||
|
|
||||||
|
switch (field) {
|
||||||
|
// ===== SOURCE FIELDS =====
|
||||||
|
case 'qty': {
|
||||||
|
if (avgWeight > 0) {
|
||||||
|
formik.setFieldValue('total_weight', roundWeight(qty * avgWeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field === 'avg_weight' || field === 'total_weight' || field === 'qty') {
|
if (unitPrice > 0) {
|
||||||
if (qty && avg_weight && (field === 'avg_weight' || field === 'qty')) {
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
formik.setFieldValue('total_weight', Number(qty) * Number(avg_weight));
|
}
|
||||||
} else if (qty && total_weight && field === 'total_weight') {
|
break;
|
||||||
formik.setFieldValue('avg_weight', Number(total_weight) / Number(qty));
|
}
|
||||||
|
|
||||||
|
case 'avg_weight': {
|
||||||
|
if (avgWeight > 0) {
|
||||||
|
const tw = roundWeight(qty * avgWeight);
|
||||||
|
formik.setFieldValue('total_weight', tw);
|
||||||
|
|
||||||
|
if (unitPrice > 0) {
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'unit_price': {
|
||||||
|
if (unitPrice > 0) {
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== TOTAL EDITABLE =====
|
||||||
|
case 'total_weight': {
|
||||||
|
if (totalWeight > 0) {
|
||||||
|
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'total_price': {
|
||||||
|
if (totalPrice > 0) {
|
||||||
|
formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -183,7 +237,7 @@ const DeliveryOrderProductForm = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className='grid sm:grid-cols-2 gap-4'>
|
<div className='grid sm:grid-cols-3 gap-4'>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
options={options}
|
options={options}
|
||||||
label='Produk'
|
label='Produk'
|
||||||
@@ -287,7 +341,9 @@ const DeliveryOrderProductForm = ({
|
|||||||
isError={Boolean(formik.errors.vehicle_number)}
|
isError={Boolean(formik.errors.vehicle_number)}
|
||||||
errorMessage={formik.errors.vehicle_number}
|
errorMessage={formik.errors.vehicle_number}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='divider my-6'></div>
|
||||||
|
<div className='grid sm:grid-cols-3 gap-4'>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Kuantitas'
|
label='Kuantitas'
|
||||||
@@ -301,33 +357,28 @@ const DeliveryOrderProductForm = ({
|
|||||||
isError={Boolean(formik.errors.qty)}
|
isError={Boolean(formik.errors.qty)}
|
||||||
errorMessage={formik.errors.qty}
|
errorMessage={formik.errors.qty}
|
||||||
placeholder='Masukan Kuantitas'
|
placeholder='Masukan Kuantitas'
|
||||||
|
endAdornment={
|
||||||
|
<div className='flex items-center gap-2'>
|
||||||
|
<span className='text-sm text-gray-500'>
|
||||||
|
{isResponseSuccess(productData)
|
||||||
|
? productData?.data?.uom.name
|
||||||
|
: ''}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
bottomLabel={
|
bottomLabel={
|
||||||
formik.values.marketing_product_id
|
formik.values.marketing_product_id
|
||||||
? 'Stok dijual: ' +
|
? 'Stok dijual: ' +
|
||||||
salesOrders?.find(
|
salesOrders?.find(
|
||||||
(item) => item.id === formik.values.marketing_product_id
|
(item) => item.id === formik.values.marketing_product_id
|
||||||
)?.qty
|
)?.qty +
|
||||||
|
' ' +
|
||||||
|
(isResponseSuccess(productData)
|
||||||
|
? productData?.data?.uom.name
|
||||||
|
: '')
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<div className='divider my-6'></div>
|
|
||||||
<div className='grid sm:grid-cols-2 gap-4'>
|
|
||||||
<NumberInput
|
|
||||||
required
|
|
||||||
label='Avg. Bobot (Kg)'
|
|
||||||
name='avg_weight'
|
|
||||||
value={formik.values.avg_weight}
|
|
||||||
onChange={(e) => {
|
|
||||||
formik.handleChange(e);
|
|
||||||
setCurrentInput(e.target.name);
|
|
||||||
}}
|
|
||||||
onBlur={() => handleBlurField('avg_weight')}
|
|
||||||
isError={Boolean(formik.errors.avg_weight)}
|
|
||||||
errorMessage={formik.errors.avg_weight}
|
|
||||||
placeholder='Masukan Bobot Rata-rata'
|
|
||||||
/>
|
|
||||||
|
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Harga Satuan (Rp)'
|
label='Harga Satuan (Rp)'
|
||||||
@@ -342,7 +393,20 @@ const DeliveryOrderProductForm = ({
|
|||||||
errorMessage={formik.errors.unit_price}
|
errorMessage={formik.errors.unit_price}
|
||||||
placeholder='Masukan Harga Satuan'
|
placeholder='Masukan Harga Satuan'
|
||||||
/>
|
/>
|
||||||
|
<NumberInput
|
||||||
|
required
|
||||||
|
label='Avg. Bobot (Kg)'
|
||||||
|
name='avg_weight'
|
||||||
|
value={formik.values.avg_weight}
|
||||||
|
onChange={(e) => {
|
||||||
|
formik.handleChange(e);
|
||||||
|
setCurrentInput(e.target.name);
|
||||||
|
}}
|
||||||
|
onBlur={() => handleBlurField('avg_weight')}
|
||||||
|
isError={Boolean(formik.errors.avg_weight)}
|
||||||
|
errorMessage={formik.errors.avg_weight}
|
||||||
|
placeholder='Masukan Bobot Rata-rata'
|
||||||
|
/>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Total Bobot (Kg)'
|
label='Total Bobot (Kg)'
|
||||||
|
|||||||
+111
-50
@@ -11,7 +11,7 @@ import SelectInput, {
|
|||||||
useSelect,
|
useSelect,
|
||||||
} from '@/components/input/SelectInput';
|
} from '@/components/input/SelectInput';
|
||||||
import { Kandang } from '@/types/api/master-data/kandang';
|
import { Kandang } from '@/types/api/master-data/kandang';
|
||||||
import { WarehouseApi } from '@/services/api/master-data';
|
import { ProductApi, UomApi, WarehouseApi } from '@/services/api/master-data';
|
||||||
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
||||||
import { ProductWarehouseApi } from '@/services/api/inventory';
|
import { ProductWarehouseApi } from '@/services/api/inventory';
|
||||||
import NumberInput from '@/components/input/NumberInput';
|
import NumberInput from '@/components/input/NumberInput';
|
||||||
@@ -26,6 +26,10 @@ import PatternInput from '@/components/input/PatternInput';
|
|||||||
import Alert from '@/components/Alert';
|
import Alert from '@/components/Alert';
|
||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
const roundWeight = (value: number) => Number(value.toFixed(2));
|
||||||
|
const roundPrice = (value: number) => Math.round(value);
|
||||||
|
|
||||||
const SalesOrderProductForm = ({
|
const SalesOrderProductForm = ({
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -39,6 +43,19 @@ const SalesOrderProductForm = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [formErrorMessage, setFormErrorMessage] = useState('');
|
const [formErrorMessage, setFormErrorMessage] = useState('');
|
||||||
const [currentInput, setCurrentInput] = useState<string>('');
|
const [currentInput, setCurrentInput] = useState<string>('');
|
||||||
|
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 ============
|
// ============ Formik ============
|
||||||
const formik = useFormik<SalesOrderProductFormValues>({
|
const formik = useFormik<SalesOrderProductFormValues>({
|
||||||
@@ -69,17 +86,21 @@ const SalesOrderProductForm = ({
|
|||||||
const {
|
const {
|
||||||
options: kandangSourceOptions,
|
options: kandangSourceOptions,
|
||||||
isLoadingOptions: isLoadingKandangSourceOptions,
|
isLoadingOptions: isLoadingKandangSourceOptions,
|
||||||
|
setInputValue: setKandangInputValue,
|
||||||
|
loadMore: loadMoreKandang,
|
||||||
} = useSelect<Kandang>(WarehouseApi.basePath, 'id', 'name');
|
} = useSelect<Kandang>(WarehouseApi.basePath, 'id', 'name');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
options: warehouseSourceOptions,
|
options: warehouseSourceOptions,
|
||||||
rawData: warehouseSourceRawData,
|
rawData: warehouseSourceRawData,
|
||||||
isLoadingOptions: isLoadingWarehouseSourceOptions,
|
isLoadingOptions: isLoadingWarehouseSourceOptions,
|
||||||
|
setInputValue: setWarehouseInputValue,
|
||||||
|
loadMore: loadMoreWarehouse,
|
||||||
} = useSelect<ProductWarehouse>(
|
} = useSelect<ProductWarehouse>(
|
||||||
ProductWarehouseApi.basePath,
|
ProductWarehouseApi.basePath,
|
||||||
'id',
|
'id',
|
||||||
'product.name',
|
'product.name',
|
||||||
'search',
|
'',
|
||||||
{
|
{
|
||||||
warehouse_id: formik.values.kandang_id?.toString() ?? '',
|
warehouse_id: formik.values.kandang_id?.toString() ?? '',
|
||||||
}
|
}
|
||||||
@@ -112,6 +133,7 @@ const SalesOrderProductForm = ({
|
|||||||
const productWarehouse = warehouseSourceRawData?.data.find(
|
const productWarehouse = warehouseSourceRawData?.data.find(
|
||||||
(item: ProductWarehouse) => item.id === newId
|
(item: ProductWarehouse) => item.id === newId
|
||||||
);
|
);
|
||||||
|
setSelectedProductWarehouse(productWarehouse || null);
|
||||||
formik.setFieldValue('qty', productWarehouse?.quantity);
|
formik.setFieldValue('qty', productWarehouse?.quantity);
|
||||||
handleBlurField('qty');
|
handleBlurField('qty');
|
||||||
} else {
|
} else {
|
||||||
@@ -139,34 +161,60 @@ const SalesOrderProductForm = ({
|
|||||||
|
|
||||||
const handleBlurField = (field: string) => {
|
const handleBlurField = (field: string) => {
|
||||||
setCurrentInput(field);
|
setCurrentInput(field);
|
||||||
const { qty, unit_price, total_price, avg_weight, total_weight } =
|
|
||||||
formik.values;
|
|
||||||
|
|
||||||
if (field === 'unit_price' || field === 'total_price' || field === 'qty') {
|
const qty = Number(formik.values.qty || 0);
|
||||||
if (qty && unit_price && (field === 'unit_price' || field === 'qty')) {
|
const avgWeight = Number(formik.values.avg_weight || 0);
|
||||||
formik.setFieldValue(
|
const totalWeight = Number(formik.values.total_weight || 0);
|
||||||
'total_price',
|
const unitPrice = Number(formik.values.unit_price || 0);
|
||||||
(qty as number) * (unit_price as number)
|
const totalPrice = Number(formik.values.total_price || 0);
|
||||||
);
|
|
||||||
} else if (qty && total_price && field === 'total_price') {
|
if (qty <= 0) return;
|
||||||
formik.setFieldValue(
|
|
||||||
'unit_price',
|
switch (field) {
|
||||||
(total_price as number) / (qty as number)
|
// ===== SOURCE FIELDS =====
|
||||||
);
|
case 'qty': {
|
||||||
}
|
if (avgWeight > 0) {
|
||||||
|
formik.setFieldValue('total_weight', roundWeight(qty * avgWeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field === 'avg_weight' || field === 'total_weight' || field === 'qty') {
|
if (unitPrice > 0) {
|
||||||
if (qty && avg_weight && (field === 'avg_weight' || field === 'qty')) {
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
formik.setFieldValue(
|
}
|
||||||
'total_weight',
|
break;
|
||||||
(qty as number) * (avg_weight as number)
|
}
|
||||||
);
|
|
||||||
} else if (qty && total_weight && field === 'total_weight') {
|
case 'avg_weight': {
|
||||||
formik.setFieldValue(
|
if (avgWeight > 0) {
|
||||||
'avg_weight',
|
const tw = roundWeight(qty * avgWeight);
|
||||||
(total_weight as number) / (qty as number)
|
formik.setFieldValue('total_weight', tw);
|
||||||
);
|
|
||||||
|
if (unitPrice > 0) {
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'unit_price': {
|
||||||
|
if (unitPrice > 0) {
|
||||||
|
formik.setFieldValue('total_price', roundPrice(qty * unitPrice));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== TOTAL EDITABLE =====
|
||||||
|
case 'total_weight': {
|
||||||
|
if (totalWeight > 0) {
|
||||||
|
formik.setFieldValue('avg_weight', roundWeight(totalWeight / qty));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'total_price': {
|
||||||
|
if (totalPrice > 0) {
|
||||||
|
formik.setFieldValue('unit_price', roundPrice(totalPrice / qty));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -188,7 +236,7 @@ const SalesOrderProductForm = ({
|
|||||||
</Alert>
|
</Alert>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className='grid sm:grid-cols-2 gap-4 z-200'>
|
<div className='grid sm:grid-cols-3 gap-4 z-200'>
|
||||||
<PatternInput
|
<PatternInput
|
||||||
name='vehicle_number'
|
name='vehicle_number'
|
||||||
label='No. Polisi'
|
label='No. Polisi'
|
||||||
@@ -215,6 +263,8 @@ const SalesOrderProductForm = ({
|
|||||||
value={formik.values.kandang}
|
value={formik.values.kandang}
|
||||||
onChange={kandangChangeHandler}
|
onChange={kandangChangeHandler}
|
||||||
isClearable
|
isClearable
|
||||||
|
onInputChange={setKandangInputValue}
|
||||||
|
onMenuScrollToBottom={loadMoreKandang}
|
||||||
isError={
|
isError={
|
||||||
formik.touched.kandang_id && Boolean(formik.errors.kandang_id)
|
formik.touched.kandang_id && Boolean(formik.errors.kandang_id)
|
||||||
}
|
}
|
||||||
@@ -228,6 +278,8 @@ const SalesOrderProductForm = ({
|
|||||||
isLoading={isLoadingWarehouseSourceOptions}
|
isLoading={isLoadingWarehouseSourceOptions}
|
||||||
value={formik.values.product_warehouse}
|
value={formik.values.product_warehouse}
|
||||||
onChange={warehouseChangeHandler}
|
onChange={warehouseChangeHandler}
|
||||||
|
onInputChange={setWarehouseInputValue}
|
||||||
|
onMenuScrollToBottom={loadMoreWarehouse}
|
||||||
isClearable
|
isClearable
|
||||||
placeholder={
|
placeholder={
|
||||||
formik.values.kandang_id
|
formik.values.kandang_id
|
||||||
@@ -243,6 +295,9 @@ const SalesOrderProductForm = ({
|
|||||||
}
|
}
|
||||||
errorMessage={formik.errors.product_warehouse_id}
|
errorMessage={formik.errors.product_warehouse_id}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div className='divider my-6'></div>
|
||||||
|
<div className='grid sm:grid-cols-3 gap-4 z-200'>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Kuantitas'
|
label='Kuantitas'
|
||||||
@@ -256,6 +311,15 @@ const SalesOrderProductForm = ({
|
|||||||
isError={formik.touched.qty && Boolean(formik.errors.qty)}
|
isError={formik.touched.qty && Boolean(formik.errors.qty)}
|
||||||
errorMessage={formik.errors.qty}
|
errorMessage={formik.errors.qty}
|
||||||
placeholder='Masukan Kuantitas'
|
placeholder='Masukan Kuantitas'
|
||||||
|
endAdornment={
|
||||||
|
<div className='flex items-center gap-2'>
|
||||||
|
<span className='text-sm text-gray-500'>
|
||||||
|
{isResponseSuccess(productData)
|
||||||
|
? productData?.data?.uom.name
|
||||||
|
: ''}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
bottomLabel={
|
bottomLabel={
|
||||||
isResponseSuccess(warehouseSourceRawData) &&
|
isResponseSuccess(warehouseSourceRawData) &&
|
||||||
formik.values.product_warehouse_id
|
formik.values.product_warehouse_id
|
||||||
@@ -264,32 +328,13 @@ const SalesOrderProductForm = ({
|
|||||||
(item) => item.id === formik.values.product_warehouse_id
|
(item) => item.id === formik.values.product_warehouse_id
|
||||||
)?.quantity ?? 0
|
)?.quantity ?? 0
|
||||||
)} ${
|
)} ${
|
||||||
warehouseSourceRawData?.data?.find(
|
isResponseSuccess(productData)
|
||||||
(item) => item.id === formik.values.product_warehouse_id
|
? productData?.data?.uom.name
|
||||||
)?.product?.uom?.name ?? ''
|
: ''
|
||||||
}`
|
}`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<div className='divider my-6'></div>
|
|
||||||
<div className='grid sm:grid-cols-2 gap-4 z-200'>
|
|
||||||
<NumberInput
|
|
||||||
required
|
|
||||||
label='Avg. Bobot (Kg)'
|
|
||||||
name='avg_weight'
|
|
||||||
value={formik.values.avg_weight}
|
|
||||||
onChange={(e) => {
|
|
||||||
formik.handleChange(e);
|
|
||||||
setCurrentInput(e.target.name);
|
|
||||||
}}
|
|
||||||
onBlur={() => handleBlurField('avg_weight')}
|
|
||||||
isError={
|
|
||||||
formik.touched.avg_weight && Boolean(formik.errors.avg_weight)
|
|
||||||
}
|
|
||||||
errorMessage={formik.errors.avg_weight}
|
|
||||||
placeholder='Masukan Bobot Rata-rata'
|
|
||||||
/>
|
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Harga Satuan (Rp)'
|
label='Harga Satuan (Rp)'
|
||||||
@@ -306,6 +351,22 @@ const SalesOrderProductForm = ({
|
|||||||
errorMessage={formik.errors.unit_price}
|
errorMessage={formik.errors.unit_price}
|
||||||
placeholder='Masukan Harga Satuan'
|
placeholder='Masukan Harga Satuan'
|
||||||
/>
|
/>
|
||||||
|
<NumberInput
|
||||||
|
required
|
||||||
|
label='Avg. Bobot (Kg)'
|
||||||
|
name='avg_weight'
|
||||||
|
value={formik.values.avg_weight}
|
||||||
|
onChange={(e) => {
|
||||||
|
formik.handleChange(e);
|
||||||
|
setCurrentInput(e.target.name);
|
||||||
|
}}
|
||||||
|
onBlur={() => handleBlurField('avg_weight')}
|
||||||
|
isError={
|
||||||
|
formik.touched.avg_weight && Boolean(formik.errors.avg_weight)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.avg_weight}
|
||||||
|
placeholder='Masukan Bobot Rata-rata'
|
||||||
|
/>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required
|
||||||
label='Total Bobot (Kg)'
|
label='Total Bobot (Kg)'
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
todayRecordings.forEach((recording) => {
|
todayRecordings.forEach((recording) => {
|
||||||
const recordingDate = recording.record_datetime?.split('T')[0];
|
const recordingDate = recording.record_datetime?.split('T')[0];
|
||||||
if (recordingDate === today) {
|
if (recordingDate === today) {
|
||||||
recordedIds.add(recording.project_flock.project_flock_kandang_id);
|
recordedIds.add(recording.project_flock?.project_flock_kandang_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user