mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b9bd3c5bd | |||
| 9dc30c1f58 | |||
| 671fd72141 | |||
| d236138aa7 | |||
| 3042b54577 | |||
| e5a686e5ee | |||
| 37d5a6b675 | |||
| 2ff32094ce | |||
| 7207f1ba75 | |||
| 41d2e8737b | |||
| b2016314f5 | |||
| 7366d6490c | |||
| e5e9b517fd | |||
| b6629b0bbb | |||
| bac6766fa2 |
@@ -185,7 +185,9 @@ const InventoryAdjustmentForm = ({
|
|||||||
isLoadingOptions: isLoadingProductOptions,
|
isLoadingOptions: isLoadingProductOptions,
|
||||||
loadMore: loadMoreProducts,
|
loadMore: loadMoreProducts,
|
||||||
rawData: products,
|
rawData: products,
|
||||||
} = useSelect<Product>(ProductApi.basePath, 'id', 'name', 'search');
|
} = useSelect<Product>(ProductApi.basePath, 'id', 'name', 'search', {
|
||||||
|
include_all: 'true',
|
||||||
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setInputValue: setDepletionProductInputValue,
|
setInputValue: setDepletionProductInputValue,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const ChickinLogsView = ({
|
|||||||
rawDataApprovals: BaseApproval[];
|
rawDataApprovals: BaseApproval[];
|
||||||
}) => {
|
}) => {
|
||||||
const [chickinErrorMessage, setChickinErrorMessage] = useState('');
|
const [chickinErrorMessage, setChickinErrorMessage] = useState('');
|
||||||
const { openChickinApproveModal } = useChickinStore();
|
const { openChickinApproveModal, openChickinDeleteModal } = useChickinStore();
|
||||||
|
|
||||||
const handleClickApprove = () => {
|
const handleClickApprove = () => {
|
||||||
openChickinApproveModal(initialValues, async (notes?: string) => {
|
openChickinApproveModal(initialValues, async (notes?: string) => {
|
||||||
@@ -44,6 +44,21 @@ const ChickinLogsView = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteChickin = (chickinId: number) => {
|
||||||
|
openChickinDeleteModal(chickinId, async () => {
|
||||||
|
const deleteRes = await ChickinApi.delete(chickinId);
|
||||||
|
|
||||||
|
if (isResponseSuccess(deleteRes)) {
|
||||||
|
toast.success(deleteRes?.message || 'Chickin berhasil dihapus');
|
||||||
|
afterSubmit && afterSubmit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isResponseError(deleteRes)) {
|
||||||
|
toast.error(deleteRes?.message || 'Gagal menghapus chickin');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='px-4 pb-4 flex flex-col gap-4'>
|
<div className='px-4 pb-4 flex flex-col gap-4'>
|
||||||
@@ -86,6 +101,7 @@ const ChickinLogsView = ({
|
|||||||
<div className='text-lg font-semibold'>
|
<div className='text-lg font-semibold'>
|
||||||
Chick In #{index + 1} - {latestApproval?.step_number}
|
Chick In #{index + 1} - {latestApproval?.step_number}
|
||||||
</div>
|
</div>
|
||||||
|
<div className='flex flex-row gap-2 items-center'>
|
||||||
<PillBadge
|
<PillBadge
|
||||||
content={
|
content={
|
||||||
isApproved ? 'Disetujui' : isPending ? 'Pending' : '-'
|
isApproved ? 'Disetujui' : isPending ? 'Pending' : '-'
|
||||||
@@ -94,6 +110,21 @@ const ChickinLogsView = ({
|
|||||||
isApproved ? 'green' : isPending ? 'yellow' : 'gray'
|
isApproved ? 'green' : isPending ? 'yellow' : 'gray'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{isApproved && (
|
||||||
|
<Button
|
||||||
|
color='error'
|
||||||
|
className='w-fit text-sm text-base-100 rounded-lg shadow-sm btn-xs!'
|
||||||
|
onClick={() => handleDeleteChickin(chickin.id)}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='heroicons:trash-solid'
|
||||||
|
width={10}
|
||||||
|
height={10}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Tanggal Chick In */}
|
{/* Tanggal Chick In */}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
|||||||
const confirmModal = useModal();
|
const confirmModal = useModal();
|
||||||
const successModal = useModal();
|
const successModal = useModal();
|
||||||
const chickinApproveModal = useModal();
|
const chickinApproveModal = useModal();
|
||||||
|
const chickinDeleteModal = useModal();
|
||||||
const closingModal = useModal();
|
const closingModal = useModal();
|
||||||
const [approvalAction, setApprovalAction] = useState<'APPROVED' | 'REJECTED'>(
|
const [approvalAction, setApprovalAction] = useState<'APPROVED' | 'REJECTED'>(
|
||||||
'APPROVED'
|
'APPROVED'
|
||||||
@@ -214,6 +215,11 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
|||||||
chickinApproveCallback,
|
chickinApproveCallback,
|
||||||
closeChickinApproveModal,
|
closeChickinApproveModal,
|
||||||
setChickinApproveLoading,
|
setChickinApproveLoading,
|
||||||
|
isChickinDeleteModalOpen,
|
||||||
|
isChickinDeleteLoading,
|
||||||
|
chickinDeleteCallback,
|
||||||
|
closeChickinDeleteModal,
|
||||||
|
setChickinDeleteLoading,
|
||||||
} = useChickinStore();
|
} = useChickinStore();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -478,6 +484,14 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
|||||||
}
|
}
|
||||||
}, [isChickinApproveModalOpen, chickinApproveModal]);
|
}, [isChickinApproveModalOpen, chickinApproveModal]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isChickinDeleteModalOpen) {
|
||||||
|
chickinDeleteModal.openModal();
|
||||||
|
} else {
|
||||||
|
chickinDeleteModal.closeModal();
|
||||||
|
}
|
||||||
|
}, [isChickinDeleteModalOpen, chickinDeleteModal]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isClosingModalOpen) {
|
if (isClosingModalOpen) {
|
||||||
closingModal.openModal();
|
closingModal.openModal();
|
||||||
@@ -1208,6 +1222,38 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Chickin Delete Modal */}
|
||||||
|
<ConfirmationModal
|
||||||
|
ref={chickinDeleteModal.ref}
|
||||||
|
type='error'
|
||||||
|
text='Apakah anda yakin ingin menghapus data chick in ini?'
|
||||||
|
secondaryButton={{
|
||||||
|
text: 'Tidak',
|
||||||
|
onClick: () => {
|
||||||
|
closeChickinDeleteModal();
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
className={{
|
||||||
|
modal: 'z-9999',
|
||||||
|
}}
|
||||||
|
primaryButton={{
|
||||||
|
text: 'Ya',
|
||||||
|
color: 'error',
|
||||||
|
isLoading: isChickinDeleteLoading,
|
||||||
|
onClick: async () => {
|
||||||
|
if (chickinDeleteCallback) {
|
||||||
|
setChickinDeleteLoading(true);
|
||||||
|
try {
|
||||||
|
await chickinDeleteCallback();
|
||||||
|
} finally {
|
||||||
|
setChickinDeleteLoading(false);
|
||||||
|
closeChickinDeleteModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Filter Modal */}
|
{/* Filter Modal */}
|
||||||
<Modal
|
<Modal
|
||||||
ref={filterModal.ref}
|
ref={filterModal.ref}
|
||||||
|
|||||||
@@ -104,8 +104,19 @@ const RowOptionsMenu = ({
|
|||||||
return recording.approval?.action === 'REJECTED';
|
return recording.approval?.action === 'REJECTED';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isRecordingEditable = (recording: Recording) => {
|
||||||
|
if (recording.project_flock?.project_flock_category === 'GROWING') {
|
||||||
|
if (recording.transfer_executed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return recording.population_can_change === true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const isApproved = isRecordingApproved(props.row.original);
|
const isApproved = isRecordingApproved(props.row.original);
|
||||||
const isRejected = isRecordingRejected(props.row.original);
|
const isRejected = isRecordingRejected(props.row.original);
|
||||||
|
const isEditable = isRecordingEditable(props.row.original);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative'>
|
<div className='relative'>
|
||||||
@@ -138,6 +149,7 @@ const RowOptionsMenu = ({
|
|||||||
View Details
|
View Details
|
||||||
</Button>
|
</Button>
|
||||||
</RequirePermission>
|
</RequirePermission>
|
||||||
|
{isEditable && (
|
||||||
<RequirePermission permissions='lti.production.recording.update'>
|
<RequirePermission permissions='lti.production.recording.update'>
|
||||||
<Button
|
<Button
|
||||||
href={`/production/recording/detail/edit/?recordingId=${props.row.original.id}`}
|
href={`/production/recording/detail/edit/?recordingId=${props.row.original.id}`}
|
||||||
@@ -150,6 +162,7 @@ const RowOptionsMenu = ({
|
|||||||
Edit
|
Edit
|
||||||
</Button>
|
</Button>
|
||||||
</RequirePermission>
|
</RequirePermission>
|
||||||
|
)}
|
||||||
{!isApproved && !isRejected && (
|
{!isApproved && !isRejected && (
|
||||||
<RequirePermission permissions='lti.production.recording.approve'>
|
<RequirePermission permissions='lti.production.recording.approve'>
|
||||||
<Button
|
<Button
|
||||||
@@ -182,6 +195,7 @@ const RowOptionsMenu = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</RequirePermission>
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
{isEditable && (
|
||||||
<RequirePermission permissions='lti.production.recording.delete'>
|
<RequirePermission permissions='lti.production.recording.delete'>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -196,6 +210,7 @@ const RowOptionsMenu = ({
|
|||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</RequirePermission>
|
</RequirePermission>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ type RecordingGrowingFormSchemaType = {
|
|||||||
} | null;
|
} | null;
|
||||||
project_flock_kandang_id: number;
|
project_flock_kandang_id: number;
|
||||||
stocks: {
|
stocks: {
|
||||||
product_warehouse_id: number;
|
product_warehouse_id?: number;
|
||||||
qty: number | string;
|
qty?: number | string;
|
||||||
}[];
|
}[];
|
||||||
depletions: {
|
depletions: {
|
||||||
product_warehouse_id?: number;
|
product_warehouse_id?: number;
|
||||||
@@ -73,6 +73,18 @@ const StockObjectSchema: Yup.ObjectSchema<StockSchema> = Yup.object({
|
|||||||
.typeError('Jumlah penggunaan harus berupa angka!'),
|
.typeError('Jumlah penggunaan harus berupa angka!'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const OptionalStockObjectSchema: Yup.ObjectSchema<{
|
||||||
|
product_warehouse_id?: number;
|
||||||
|
qty?: number | string;
|
||||||
|
}> = Yup.object({
|
||||||
|
product_warehouse_id: Yup.number()
|
||||||
|
.optional()
|
||||||
|
.typeError('Produk harus berupa angka!'),
|
||||||
|
qty: Yup.number()
|
||||||
|
.optional()
|
||||||
|
.typeError('Jumlah penggunaan harus berupa angka!'),
|
||||||
|
});
|
||||||
|
|
||||||
const DepletionObjectSchema: Yup.ObjectSchema<DepletionSchema> = Yup.object({
|
const DepletionObjectSchema: Yup.ObjectSchema<DepletionSchema> = Yup.object({
|
||||||
product_warehouse_id: Yup.number()
|
product_warehouse_id: Yup.number()
|
||||||
.optional()
|
.optional()
|
||||||
@@ -90,7 +102,9 @@ const EggObjectSchema: Yup.ObjectSchema<EggSchema> = Yup.object({
|
|||||||
weight: Yup.number().optional().typeError('Berat telur harus berupa angka!'),
|
weight: Yup.number().optional().typeError('Berat telur harus berupa angka!'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const RecordingGrowingFormSchema: Yup.ObjectSchema<RecordingGrowingFormSchemaType> =
|
export const RecordingGrowingFormSchema = (
|
||||||
|
isTransitioningToLaying = false
|
||||||
|
): Yup.ObjectSchema<RecordingGrowingFormSchemaType> =>
|
||||||
Yup.object({
|
Yup.object({
|
||||||
record_date: Yup.string()
|
record_date: Yup.string()
|
||||||
.required('Tanggal recording wajib diisi!')
|
.required('Tanggal recording wajib diisi!')
|
||||||
@@ -150,7 +164,9 @@ export const RecordingGrowingFormSchema: Yup.ObjectSchema<RecordingGrowingFormSc
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
stocks: Yup.array()
|
stocks: isTransitioningToLaying
|
||||||
|
? Yup.array().of(OptionalStockObjectSchema).default([])
|
||||||
|
: Yup.array()
|
||||||
.of(StockObjectSchema)
|
.of(StockObjectSchema)
|
||||||
.min(1, 'Minimal harus ada 1 data stok!')
|
.min(1, 'Minimal harus ada 1 data stok!')
|
||||||
.required('Data stok wajib diisi!'),
|
.required('Data stok wajib diisi!'),
|
||||||
@@ -158,12 +174,14 @@ export const RecordingGrowingFormSchema: Yup.ObjectSchema<RecordingGrowingFormSc
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const RecordingLayingFormSchema: Yup.ObjectSchema<RecordingLayingFormSchemaType> =
|
export const RecordingLayingFormSchema: Yup.ObjectSchema<RecordingLayingFormSchemaType> =
|
||||||
RecordingGrowingFormSchema.shape({
|
RecordingGrowingFormSchema().shape({
|
||||||
eggs: Yup.array().of(EggObjectSchema).default([]),
|
eggs: Yup.array().of(EggObjectSchema).default([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UpdateRecordingGrowingFormSchema =
|
export const UpdateRecordingGrowingFormSchema = (
|
||||||
RecordingGrowingFormSchema.shape({
|
isTransitioningToLaying = false
|
||||||
|
) =>
|
||||||
|
RecordingGrowingFormSchema(isTransitioningToLaying).shape({
|
||||||
location_id: Yup.number().nullable().optional(),
|
location_id: Yup.number().nullable().optional(),
|
||||||
project_flock_id: Yup.number().nullable().optional(),
|
project_flock_id: Yup.number().nullable().optional(),
|
||||||
kandang_id: Yup.number().nullable().optional(),
|
kandang_id: Yup.number().nullable().optional(),
|
||||||
@@ -193,10 +211,13 @@ export const UpdateRecordingLayingFormSchema = RecordingLayingFormSchema.shape({
|
|||||||
.required('Project Flock Kandang wajib diisi!'),
|
.required('Project Flock Kandang wajib diisi!'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type RecordingGrowingFormValues = Yup.InferType<
|
type RecordingGrowingFormSchemaFn = ReturnType<
|
||||||
typeof RecordingGrowingFormSchema
|
typeof RecordingGrowingFormSchema
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export type RecordingGrowingFormValues =
|
||||||
|
Yup.InferType<RecordingGrowingFormSchemaFn>;
|
||||||
|
|
||||||
export type RecordingLayingFormValues = Yup.InferType<
|
export type RecordingLayingFormValues = Yup.InferType<
|
||||||
typeof RecordingLayingFormSchema
|
typeof RecordingLayingFormSchema
|
||||||
>;
|
>;
|
||||||
|
|||||||
@@ -272,6 +272,16 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
return recording?.approval?.action === 'REJECTED';
|
return recording?.approval?.action === 'REJECTED';
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const isRecordingEditable = useCallback((recording?: Recording) => {
|
||||||
|
if (recording?.project_flock?.project_flock_category === 'GROWING') {
|
||||||
|
if (recording?.transfer_executed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return recording?.population_can_change === true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}, []);
|
||||||
|
|
||||||
// ===== PAYLOAD CREATION HELPERS =====
|
// ===== PAYLOAD CREATION HELPERS =====
|
||||||
const createGrowingPayload = useCallback(
|
const createGrowingPayload = useCallback(
|
||||||
(values: RecordingGrowingFormValues) => {
|
(values: RecordingGrowingFormValues) => {
|
||||||
@@ -581,6 +591,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
projectFlockKandangLookup?.project_flock?.category === 'GROWING' ||
|
projectFlockKandangLookup?.project_flock?.category === 'GROWING' ||
|
||||||
projectFlockKandangDetail?.project_flock?.category === 'GROWING';
|
projectFlockKandangDetail?.project_flock?.category === 'GROWING';
|
||||||
|
|
||||||
|
const isTransitioningToLaying = useMemo(() => {
|
||||||
|
if (!isGrowingCategory) return false;
|
||||||
|
return (
|
||||||
|
initialValues?.population_can_change === true ||
|
||||||
|
initialValues?.transfer_executed === true
|
||||||
|
);
|
||||||
|
}, [initialValues, isGrowingCategory]);
|
||||||
|
|
||||||
const recordingApprovalLines = useMemo(() => {
|
const recordingApprovalLines = useMemo(() => {
|
||||||
if (isLayingCategory) {
|
if (isLayingCategory) {
|
||||||
return LAYING_RECORDING_APPROVAL_LINE;
|
return LAYING_RECORDING_APPROVAL_LINE;
|
||||||
@@ -941,8 +959,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
} else {
|
} else {
|
||||||
schema =
|
schema =
|
||||||
type === 'edit'
|
type === 'edit'
|
||||||
? UpdateRecordingGrowingFormSchema
|
? UpdateRecordingGrowingFormSchema(isTransitioningToLaying)
|
||||||
: RecordingGrowingFormSchema;
|
: RecordingGrowingFormSchema(isTransitioningToLaying);
|
||||||
}
|
}
|
||||||
return schema.clone().concat(
|
return schema.clone().concat(
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
@@ -2323,21 +2341,25 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
)}
|
)}
|
||||||
<th>
|
<th>
|
||||||
Persediaan
|
Persediaan
|
||||||
|
{!isTransitioningToLaying && (
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom '
|
className='tooltip tooltip-error tooltip-bottom '
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
</span>
|
</span>
|
||||||
|
)}
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Jumlah Pakai
|
Jumlah Pakai
|
||||||
|
{!isTransitioningToLaying && (
|
||||||
<span
|
<span
|
||||||
className='tooltip tooltip-error tooltip-bottom '
|
className='tooltip tooltip-error tooltip-bottom '
|
||||||
data-tip='required'
|
data-tip='required'
|
||||||
>
|
>
|
||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
</span>
|
</span>
|
||||||
|
)}
|
||||||
</th>
|
</th>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
@@ -2372,7 +2394,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
)}
|
)}
|
||||||
<td>
|
<td>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
required
|
required={!isTransitioningToLaying}
|
||||||
key={`stock-product-${idx}-${stock.product_warehouse_id}`}
|
key={`stock-product-${idx}-${stock.product_warehouse_id}`}
|
||||||
value={
|
value={
|
||||||
unifiedStockProducts.find(
|
unifiedStockProducts.find(
|
||||||
@@ -2430,7 +2452,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<td>
|
<td>
|
||||||
<div className='flex flex-col gap-1'>
|
<div className='flex flex-col gap-1'>
|
||||||
<NumberInput
|
<NumberInput
|
||||||
required
|
required={!isTransitioningToLaying}
|
||||||
name={`stocks.${idx}.qty`}
|
name={`stocks.${idx}.qty`}
|
||||||
value={stock.qty ?? ''}
|
value={stock.qty ?? ''}
|
||||||
onChange={handleStockUsageQtyChangeWrapper(idx)}
|
onChange={handleStockUsageQtyChangeWrapper(idx)}
|
||||||
@@ -2990,7 +3012,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<div className='flex flex-col sm:flex-row sm:justify-between gap-2'>
|
<div className='flex flex-col sm:flex-row sm:justify-between gap-2'>
|
||||||
{/* Left side - Detail & Edit actions */}
|
{/* Left side - Detail & Edit actions */}
|
||||||
<div className='flex flex-col sm:flex-row justify-start gap-2 w-full sm:w-auto'>
|
<div className='flex flex-col sm:flex-row justify-start gap-2 w-full sm:w-auto'>
|
||||||
{type === 'detail' && deleteRecordingClickHandler && (
|
{type === 'detail' &&
|
||||||
|
deleteRecordingClickHandler &&
|
||||||
|
isRecordingEditable(initialValues) && (
|
||||||
<RequirePermission permissions='lti.production.recording.delete'>
|
<RequirePermission permissions='lti.production.recording.delete'>
|
||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
@@ -3008,7 +3032,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</RequirePermission>
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
{type === 'detail' && initialValues && (
|
{type === 'detail' &&
|
||||||
|
initialValues &&
|
||||||
|
isRecordingEditable(initialValues) && (
|
||||||
<RequirePermission permissions='lti.production.recording.update'>
|
<RequirePermission permissions='lti.production.recording.update'>
|
||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
|
|||||||
+13
-3
@@ -50,12 +50,18 @@ const TransferToLayingConfirmationModalTable = ({
|
|||||||
transferToLayingForm?: TransferToLayingFormValues;
|
transferToLayingForm?: TransferToLayingFormValues;
|
||||||
transferToLayingId?: number;
|
transferToLayingId?: number;
|
||||||
}) => {
|
}) => {
|
||||||
|
const isValidId =
|
||||||
|
transferToLayingId !== undefined &&
|
||||||
|
transferToLayingId !== null &&
|
||||||
|
!isNaN(transferToLayingId) &&
|
||||||
|
transferToLayingId > 0;
|
||||||
|
|
||||||
const { data: transferToLaying, isLoading: isLoadingTransferToLaying } =
|
const { data: transferToLaying, isLoading: isLoadingTransferToLaying } =
|
||||||
useSWR(
|
useSWR(
|
||||||
transferToLayingId
|
isValidId
|
||||||
? ['detail-transfer-to-laying', String(transferToLayingId)]
|
? ['detail-transfer-to-laying', String(transferToLayingId)]
|
||||||
: undefined,
|
: undefined,
|
||||||
([id]) => TransferToLayingApi.getSingle(Number(id))
|
([, id]) => TransferToLayingApi.getSingle(Number(id))
|
||||||
);
|
);
|
||||||
|
|
||||||
const confirmationTableColumns: ColumnDef<TransferToLayingConfirmationTableDataType>[] =
|
const confirmationTableColumns: ColumnDef<TransferToLayingConfirmationTableDataType>[] =
|
||||||
@@ -273,7 +279,11 @@ const TransferToLayingConfirmationModal = ({
|
|||||||
|
|
||||||
{transferToLayingIds &&
|
{transferToLayingIds &&
|
||||||
!transferToLayingForm &&
|
!transferToLayingForm &&
|
||||||
transferToLayingIds.map((transferToLayingId, idx) => (
|
transferToLayingIds
|
||||||
|
.filter(
|
||||||
|
(id) => id !== undefined && id !== null && !isNaN(id) && id > 0
|
||||||
|
)
|
||||||
|
.map((transferToLayingId, idx) => (
|
||||||
<TransferToLayingConfirmationModalTable
|
<TransferToLayingConfirmationModalTable
|
||||||
key={idx}
|
key={idx}
|
||||||
transferToLayingId={transferToLayingId}
|
transferToLayingId={transferToLayingId}
|
||||||
|
|||||||
@@ -229,6 +229,8 @@ const TransferToLayingFormModal = () => {
|
|||||||
ProjectFlock | undefined
|
ProjectFlock | undefined
|
||||||
>(undefined);
|
>(undefined);
|
||||||
|
|
||||||
|
const [maxSourceQuantity, setMaxSourceQuantity] = useState<number>(0);
|
||||||
|
|
||||||
const selectedFlockDestinationRawData = isResponseSuccess(
|
const selectedFlockDestinationRawData = isResponseSuccess(
|
||||||
flockDestinationRawData
|
flockDestinationRawData
|
||||||
)
|
)
|
||||||
@@ -353,19 +355,14 @@ const TransferToLayingFormModal = () => {
|
|||||||
return { available: countAvailable, unavailable: countUnavailable };
|
return { available: countAvailable, unavailable: countUnavailable };
|
||||||
}, [mappedFlockDestinationKandangsMaxTargetQty]);
|
}, [mappedFlockDestinationKandangsMaxTargetQty]);
|
||||||
|
|
||||||
const totalEnteredChickenForTransfer =
|
|
||||||
formik.values.flockSourceKandangs.reduce(
|
|
||||||
(acc, item) => acc + Number(item.quantity),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
const totalTransferedChicken = formik.values.flockDestinationKandangs.reduce(
|
const totalTransferedChicken = formik.values.flockDestinationKandangs.reduce(
|
||||||
(acc, item) => acc + Number(item.quantity),
|
(acc, item) => acc + Number(item.quantity),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Sisa transfer = Max available dari kandang asal - Total yang sudah diisi di kandang tujuan
|
||||||
const totalAvailableChickenForTransfer =
|
const totalAvailableChickenForTransfer =
|
||||||
totalEnteredChickenForTransfer - totalTransferedChicken;
|
maxSourceQuantity - totalTransferedChicken;
|
||||||
|
|
||||||
const isNextButtonDisabled = useMemo(() => {
|
const isNextButtonDisabled = useMemo(() => {
|
||||||
if (step === 1) {
|
if (step === 1) {
|
||||||
@@ -397,6 +394,7 @@ const TransferToLayingFormModal = () => {
|
|||||||
formik.setFieldValue('maxTotalQuantity', '');
|
formik.setFieldValue('maxTotalQuantity', '');
|
||||||
formik.setFieldValue('reason', '');
|
formik.setFieldValue('reason', '');
|
||||||
formik.setFieldTouched('reason', false);
|
formik.setFieldTouched('reason', false);
|
||||||
|
setMaxSourceQuantity(0);
|
||||||
|
|
||||||
setStep(2);
|
setStep(2);
|
||||||
};
|
};
|
||||||
@@ -404,6 +402,7 @@ const TransferToLayingFormModal = () => {
|
|||||||
const flockSourceChangeHandler = (val: OptionType | OptionType[] | null) => {
|
const flockSourceChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
formik.setFieldValue('flockSource', val);
|
formik.setFieldValue('flockSource', val);
|
||||||
formik.setFieldValue('flockSourceKandangs', []);
|
formik.setFieldValue('flockSourceKandangs', []);
|
||||||
|
setMaxSourceQuantity(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const flockDestinationChangeHandler = (
|
const flockDestinationChangeHandler = (
|
||||||
@@ -469,6 +468,26 @@ const TransferToLayingFormModal = () => {
|
|||||||
formik.setFieldValue('maxTotalQuantity', totalTransferedChicken);
|
formik.setFieldValue('maxTotalQuantity', totalTransferedChicken);
|
||||||
}, [totalTransferedChicken, formik.values.flockDestinationKandangs]);
|
}, [totalTransferedChicken, formik.values.flockDestinationKandangs]);
|
||||||
|
|
||||||
|
// Auto-fill source kandang quantity from total destination quantity
|
||||||
|
useEffect(() => {
|
||||||
|
if (formik.values.flockSourceKandangs.length > 0) {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'flockSourceKandangs.0.quantity',
|
||||||
|
totalTransferedChicken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [totalTransferedChicken]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
formik.values.flockSourceKandangs.length > 0 &&
|
||||||
|
formik.values.flockSourceKandangs[0].maxQuantity &&
|
||||||
|
maxSourceQuantity === 0
|
||||||
|
) {
|
||||||
|
setMaxSourceQuantity(formik.values.flockSourceKandangs[0].maxQuantity);
|
||||||
|
}
|
||||||
|
}, [formik.values.flockSourceKandangs, maxSourceQuantity]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal
|
||||||
@@ -583,14 +602,9 @@ const TransferToLayingFormModal = () => {
|
|||||||
k.kandang.value === item.project_flock_kandang_id
|
k.kandang.value === item.project_flock_kandang_id
|
||||||
);
|
);
|
||||||
|
|
||||||
const flockSourceKandangCheckboxChangeHandler: FormEventHandler<
|
const flockSourceKandangRadioChangeHandler = () => {
|
||||||
HTMLInputElement
|
if (isAvailable) {
|
||||||
> = (e) => {
|
|
||||||
const checked = (e.target as HTMLInputElement)
|
|
||||||
.checked;
|
|
||||||
if (checked) {
|
|
||||||
formik.setFieldValue('flockSourceKandangs', [
|
formik.setFieldValue('flockSourceKandangs', [
|
||||||
...formik.values.flockSourceKandangs,
|
|
||||||
{
|
{
|
||||||
kandang: {
|
kandang: {
|
||||||
value: item.project_flock_kandang_id,
|
value: item.project_flock_kandang_id,
|
||||||
@@ -600,15 +614,7 @@ const TransferToLayingFormModal = () => {
|
|||||||
maxQuantity: item.available_qty,
|
maxQuantity: item.available_qty,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
} else {
|
setMaxSourceQuantity(item.available_qty);
|
||||||
formik.setFieldValue(
|
|
||||||
'flockSourceKandangs',
|
|
||||||
formik.values.flockSourceKandangs.filter(
|
|
||||||
(k) =>
|
|
||||||
k.kandang.value !==
|
|
||||||
item.project_flock_kandang_id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -618,28 +624,22 @@ const TransferToLayingFormModal = () => {
|
|||||||
className='w-full p-3 flex flex-row items-center justify-between'
|
className='w-full p-3 flex flex-row items-center justify-between'
|
||||||
>
|
>
|
||||||
<div className='flex flex-row items-center gap-3'>
|
<div className='flex flex-row items-center gap-3'>
|
||||||
<CheckboxInput
|
<input
|
||||||
name={`flockSourceKandang.${itemIdx}.value`}
|
type='radio'
|
||||||
|
name='flockSourceKandang'
|
||||||
value={item.project_flock_kandang_id}
|
value={item.project_flock_kandang_id}
|
||||||
checked={isChecked}
|
checked={isChecked}
|
||||||
onChange={
|
onChange={flockSourceKandangRadioChangeHandler}
|
||||||
flockSourceKandangCheckboxChangeHandler
|
|
||||||
}
|
|
||||||
size='md'
|
|
||||||
disabled={!isAvailable}
|
disabled={!isAvailable}
|
||||||
classNames={{
|
className={cn('radio radio-md radio-primary', {
|
||||||
checkbox: cn({
|
'opacity-50 cursor-not-allowed': !isAvailable,
|
||||||
'bg-base-200 border border-base-content/10 opacity-100':
|
})}
|
||||||
!isAvailable,
|
|
||||||
}),
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
htmlFor={`flockSourceKandang.${itemIdx}.value`}
|
|
||||||
className={cn('text-sm text-base-content/50', {
|
className={cn('text-sm text-base-content/50', {
|
||||||
'cursor-pointer': isAvailable,
|
'cursor-pointer': isAvailable,
|
||||||
'cursor-not-allowed': !isAvailable,
|
'cursor-not-allowed opacity-50': !isAvailable,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{item.kandang_name}{' '}
|
{item.kandang_name}{' '}
|
||||||
@@ -858,7 +858,7 @@ const TransferToLayingFormModal = () => {
|
|||||||
<NumberInput
|
<NumberInput
|
||||||
key={`flockSourceKandangs-${item.kandang.value}-${index}`}
|
key={`flockSourceKandangs-${item.kandang.value}-${index}`}
|
||||||
name={`flockSourceKandangs.${index}.quantity`}
|
name={`flockSourceKandangs.${index}.quantity`}
|
||||||
placeholder='Masukkan Kuantitas'
|
placeholder='Masukkan Kuantitas pada Kandang Tujuan'
|
||||||
value={item.quantity}
|
value={item.quantity}
|
||||||
onChange={formik.handleChange}
|
onChange={formik.handleChange}
|
||||||
isError={isInvalid}
|
isError={isInvalid}
|
||||||
@@ -875,6 +875,8 @@ const TransferToLayingFormModal = () => {
|
|||||||
<div className='w-px bg-base-content/10' />
|
<div className='w-px bg-base-content/10' />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
readOnly
|
||||||
|
disabled
|
||||||
className={{
|
className={{
|
||||||
inputPrefix:
|
inputPrefix:
|
||||||
'py-0 px-0 pl-3 text-base-content/50 bg-transparent border-r-0',
|
'py-0 px-0 pl-3 text-base-content/50 bg-transparent border-r-0',
|
||||||
@@ -1000,7 +1002,7 @@ const TransferToLayingFormModal = () => {
|
|||||||
isError={totalAvailableChickenForTransfer < 0}
|
isError={totalAvailableChickenForTransfer < 0}
|
||||||
errorMessage={
|
errorMessage={
|
||||||
totalAvailableChickenForTransfer < 0
|
totalAvailableChickenForTransfer < 0
|
||||||
? `Jumlah transfer melebihi ketersediaan (${formatNumber(totalEnteredChickenForTransfer, 'en-US')} ayam)`
|
? `Jumlah transfer melebihi ketersediaan (${formatNumber(maxSourceQuantity, 'en-US')} ayam)`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
disabled
|
disabled
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ const RowOptionsMenu = ({
|
|||||||
popoverPosition: 'bottom' | 'top';
|
popoverPosition: 'bottom' | 'top';
|
||||||
deleteClickHandler: () => void;
|
deleteClickHandler: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const showEditButton =
|
const showEditButton = props.row.original.approval.action !== 'APPROVED';
|
||||||
props.row.original.approval.action !== 'APPROVED' &&
|
|
||||||
props.row.original.approval.action !== 'REJECTED';
|
|
||||||
|
|
||||||
const showDeleteButton = showEditButton;
|
const showDeleteButton =
|
||||||
|
props.row.original.approval.action === 'APPROVED' ||
|
||||||
|
props.row.original.approval.step_name.toLowerCase() === 'pengajuan';
|
||||||
|
|
||||||
const popoverId = `transferToLaying#${props.row.original.id}`;
|
const popoverId = `transferToLaying#${props.row.original.id}`;
|
||||||
const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`;
|
const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`;
|
||||||
|
|||||||
@@ -4,13 +4,16 @@ import { create } from 'zustand';
|
|||||||
import { devtools } from 'zustand/middleware';
|
import { devtools } from 'zustand/middleware';
|
||||||
import { createChickinApprovalSlice } from '@/stores/production/chickin/slices/chickin-approval.slice';
|
import { createChickinApprovalSlice } from '@/stores/production/chickin/slices/chickin-approval.slice';
|
||||||
import { ChickinApprovalSlice } from '@/stores/production/chickin/slices/chickin-approval.slice';
|
import { ChickinApprovalSlice } from '@/stores/production/chickin/slices/chickin-approval.slice';
|
||||||
|
import { createChickinDeleteSlice } from '@/stores/production/chickin/slices/chickin-delete.slice';
|
||||||
|
import { ChickinDeleteSlice } from '@/stores/production/chickin/slices/chickin-delete.slice';
|
||||||
|
|
||||||
export type ChickinStore = ChickinApprovalSlice;
|
export type ChickinStore = ChickinApprovalSlice & ChickinDeleteSlice;
|
||||||
|
|
||||||
export const useChickinStore = create<ChickinStore>()(
|
export const useChickinStore = create<ChickinStore>()(
|
||||||
devtools(
|
devtools(
|
||||||
(...args) => ({
|
(...args) => ({
|
||||||
...createChickinApprovalSlice(...args),
|
...createChickinApprovalSlice(...args),
|
||||||
|
...createChickinDeleteSlice(...args),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: 'ChickinStore',
|
name: 'ChickinStore',
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { StateCreator } from 'zustand';
|
||||||
|
|
||||||
|
export type ChickinDeleteSlice = {
|
||||||
|
// State
|
||||||
|
isChickinDeleteModalOpen: boolean;
|
||||||
|
selectedChickinIdForDelete: number | null;
|
||||||
|
isChickinDeleteLoading: boolean;
|
||||||
|
chickinDeleteCallback: (() => Promise<void>) | null;
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
openChickinDeleteModal: (
|
||||||
|
chickinId: number,
|
||||||
|
callback: () => Promise<void>
|
||||||
|
) => void;
|
||||||
|
closeChickinDeleteModal: () => void;
|
||||||
|
setChickinDeleteLoading: (loading: boolean) => void;
|
||||||
|
resetChickinDelete: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createChickinDeleteSlice: StateCreator<
|
||||||
|
ChickinDeleteSlice,
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
ChickinDeleteSlice
|
||||||
|
> = (set) => ({
|
||||||
|
// Initial state
|
||||||
|
isChickinDeleteModalOpen: false,
|
||||||
|
selectedChickinIdForDelete: null,
|
||||||
|
isChickinDeleteLoading: false,
|
||||||
|
chickinDeleteCallback: null,
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
openChickinDeleteModal: (chickinId, callback) =>
|
||||||
|
set({
|
||||||
|
isChickinDeleteModalOpen: true,
|
||||||
|
selectedChickinIdForDelete: chickinId,
|
||||||
|
chickinDeleteCallback: callback,
|
||||||
|
}),
|
||||||
|
|
||||||
|
closeChickinDeleteModal: () =>
|
||||||
|
set({
|
||||||
|
isChickinDeleteModalOpen: false,
|
||||||
|
selectedChickinIdForDelete: null,
|
||||||
|
chickinDeleteCallback: null,
|
||||||
|
}),
|
||||||
|
|
||||||
|
setChickinDeleteLoading: (loading) =>
|
||||||
|
set({ isChickinDeleteLoading: loading }),
|
||||||
|
|
||||||
|
resetChickinDelete: () =>
|
||||||
|
set({
|
||||||
|
isChickinDeleteModalOpen: false,
|
||||||
|
selectedChickinIdForDelete: null,
|
||||||
|
isChickinDeleteLoading: false,
|
||||||
|
chickinDeleteCallback: null,
|
||||||
|
}),
|
||||||
|
});
|
||||||
+2
@@ -49,6 +49,8 @@ export type BaseRecording = {
|
|||||||
project_flock: ProjectFlock;
|
project_flock: ProjectFlock;
|
||||||
record_datetime: string;
|
record_datetime: string;
|
||||||
day: number;
|
day: number;
|
||||||
|
population_can_change: boolean;
|
||||||
|
transfer_executed: boolean;
|
||||||
} & ProductionMetrics;
|
} & ProductionMetrics;
|
||||||
|
|
||||||
export type RecordingDepletion = {
|
export type RecordingDepletion = {
|
||||||
|
|||||||
Reference in New Issue
Block a user