diff --git a/src/components/pages/production/recording/RecordingTable.tsx b/src/components/pages/production/recording/RecordingTable.tsx
index 3cd64344..e9d260ce 100644
--- a/src/components/pages/production/recording/RecordingTable.tsx
+++ b/src/components/pages/production/recording/RecordingTable.tsx
@@ -107,12 +107,9 @@ const RowOptionsMenu = ({
};
const isRecordingEditable = (recording: Recording) => {
- const category = recording.project_flock?.project_flock_category;
- const isTransition = recording.is_transition;
-
const restriction = getRecordingRestriction(
- category || 'GROWING',
- isTransition
+ recording.is_laying,
+ recording.is_transition
);
if (restriction.isLocked) {
@@ -122,10 +119,7 @@ const RowOptionsMenu = ({
};
const getRecordingRestrictionInfo = (recording: Recording) => {
- const category = recording.project_flock?.project_flock_category;
- const isTransition = recording.is_transition;
-
- return getRecordingRestriction(category || 'GROWING', isTransition);
+ return getRecordingRestriction(recording.is_laying, recording.is_transition);
};
const isApproved = isRecordingApproved(props.row.original);
@@ -790,11 +784,10 @@ const RecordingTable = () => {
{
header: 'Kategori',
cell: (props) => {
- const category =
- props.row.original.project_flock?.project_flock_category;
+ const isLaying = props.row.original.is_laying;
const isTransition = props.row.original.is_transition;
- if (!category) return '-';
- const color = category === 'LAYING' ? 'info' : 'warning';
+ const category = isLaying ? 'LAYING' : 'GROWING';
+ const color = isLaying ? 'info' : 'warning';
return (
diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx
index c744d768..274080e3 100644
--- a/src/components/pages/production/recording/form/RecordingForm.tsx
+++ b/src/components/pages/production/recording/form/RecordingForm.tsx
@@ -473,21 +473,21 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}, [initialValues]);
const recordingRestriction = useMemo(() => {
- const category =
- initialValues?.project_flock?.project_flock_category ||
- projectFlockKandangLookup?.project_flock?.category ||
- projectFlockKandangDetail?.project_flock?.category ||
- 'GROWING';
+ const isLaying =
+ initialValues?.is_laying ??
+ (projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
+ projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
+ false);
const isTransition = initialValues?.is_transition ?? false;
- const currentFlockCategory = projectFlockKandangDetail?.project_flock
- ?.category as 'GROWING' | 'LAYING' | undefined;
+ const currentIsLaying =
+ projectFlockKandangDetail?.project_flock?.category === 'LAYING';
return getRecordingRestriction(
- category as 'GROWING' | 'LAYING',
+ isLaying,
isTransition,
- type === 'edit' ? currentFlockCategory : undefined
+ type === 'edit' ? currentIsLaying : undefined
);
}, [
initialValues,
@@ -500,16 +500,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
(recording?: Recording) => {
if (!recording) return true;
- const category = recording.project_flock?.project_flock_category;
- const isTransition = recording.is_transition;
-
- const currentFlockCategory = projectFlockKandangDetail?.project_flock
- ?.category as 'GROWING' | 'LAYING' | undefined;
+ const currentIsLaying =
+ projectFlockKandangDetail?.project_flock?.category === 'LAYING';
const restriction = getRecordingRestriction(
- category || 'GROWING',
- isTransition,
- currentFlockCategory
+ recording.is_laying,
+ recording.is_transition,
+ currentIsLaying
);
if (restriction.isLocked) {
@@ -627,14 +624,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}, [approvedProjectFlockKandangsData]);
const isLayingCategory =
- initialValues?.project_flock?.project_flock_category === 'LAYING' ||
- projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
- projectFlockKandangDetail?.project_flock?.category === 'LAYING';
+ initialValues?.is_laying ??
+ (projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
+ projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
+ false);
- const isGrowingCategory =
- initialValues?.project_flock?.project_flock_category === 'GROWING' ||
- projectFlockKandangLookup?.project_flock?.category === 'GROWING' ||
- projectFlockKandangDetail?.project_flock?.category === 'GROWING';
+ const isGrowingCategory = !isLayingCategory;
const recordingApprovalLines = useMemo(() => {
if (isLayingCategory) {
@@ -2003,15 +1998,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
- {initialValues.project_flock?.project_flock_category}
+ {initialValues.is_laying ? 'LAYING' : 'GROWING'}
@@ -2148,9 +2138,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{type === 'detail' && initialValues && (
{/* FCR Section */}
@@ -2241,8 +2229,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{/* Egg Production Section - Only for LAYING category */}
{type === 'detail' &&
initialValues &&
- initialValues.project_flock?.project_flock_category ===
- 'LAYING' && (
+ initialValues.is_laying && (
diff --git a/src/components/pages/production/recording/recording-utils.ts b/src/components/pages/production/recording/recording-utils.ts
index 3b7530c9..53bd94ad 100644
--- a/src/components/pages/production/recording/recording-utils.ts
+++ b/src/components/pages/production/recording/recording-utils.ts
@@ -7,11 +7,11 @@ export type RecordingRestriction = {
};
export const getRecordingRestriction = (
- category: 'GROWING' | 'LAYING',
+ isLaying: boolean,
isTransition: boolean,
- currentCategory?: 'GROWING' | 'LAYING'
+ currentIsLaying?: boolean
): RecordingRestriction => {
- if (currentCategory === 'LAYING' && category === 'GROWING') {
+ if (currentIsLaying && !isLaying) {
return {
canEditStock: false,
canEditDepletion: false,
@@ -22,7 +22,7 @@ export const getRecordingRestriction = (
};
}
- if (category === 'GROWING') {
+ if (!isLaying) {
if (isTransition) {
return {
canEditStock: true,
diff --git a/src/types/api/production/recording.d.ts b/src/types/api/production/recording.d.ts
index 23093169..8ce0ef15 100644
--- a/src/types/api/production/recording.d.ts
+++ b/src/types/api/production/recording.d.ts
@@ -50,6 +50,7 @@ export type BaseRecording = {
record_datetime: string;
day: number;
is_transition: boolean;
+ is_laying: boolean;
} & ProductionMetrics;
export type RecordingDepletion = {