mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE): Show pending stock usage and depletions in detail
This commit is contained in:
@@ -48,6 +48,7 @@ import {
|
|||||||
UpdateLayingRecordingPayload,
|
UpdateLayingRecordingPayload,
|
||||||
Recording,
|
Recording,
|
||||||
NextDayRecording,
|
NextDayRecording,
|
||||||
|
RecordingStock,
|
||||||
} from '@/types/api/production/recording';
|
} from '@/types/api/production/recording';
|
||||||
import { type BaseApiResponse } from '@/types/api/api-general';
|
import { type BaseApiResponse } from '@/types/api/api-general';
|
||||||
import {
|
import {
|
||||||
@@ -1103,14 +1104,51 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
[formik.values.stocks, type]
|
[formik.values.stocks, type]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getStockPendingInfo = useCallback(
|
||||||
|
(productWarehouseId: number) => {
|
||||||
|
if ((type === 'edit' || type === 'detail') && initialValues?.stocks) {
|
||||||
|
const existingStock = initialValues.stocks.find(
|
||||||
|
(s) => s.product_warehouse_id === productWarehouseId
|
||||||
|
) as RecordingStock | undefined;
|
||||||
|
if (existingStock) {
|
||||||
|
return {
|
||||||
|
usageAmount: existingStock.usage_amount ?? 0,
|
||||||
|
pendingQty: existingStock.pending_qty ?? 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
usageAmount: 0,
|
||||||
|
pendingQty: 0,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[initialValues, type]
|
||||||
|
);
|
||||||
|
|
||||||
const getStockUsageAdornment = useCallback(
|
const getStockUsageAdornment = useCallback(
|
||||||
(stockIdx: number) => {
|
(stockIdx: number) => {
|
||||||
if ((type as 'add' | 'edit' | 'detail') === 'detail') return null;
|
|
||||||
const stock = formik.values.stocks?.[stockIdx];
|
const stock = formik.values.stocks?.[stockIdx];
|
||||||
if (!stock || !stock.product_warehouse_id) return null;
|
if (!stock || !stock.product_warehouse_id) return null;
|
||||||
|
|
||||||
|
const isDetail = (type as 'add' | 'edit' | 'detail') === 'detail';
|
||||||
const availableStock = getAvailableStock(stock.product_warehouse_id);
|
const availableStock = getAvailableStock(stock.product_warehouse_id);
|
||||||
const requestedUsage = Number(stock.qty) || 0;
|
const requestedUsage = Number(stock.qty) || 0;
|
||||||
const remainingStock = availableStock - requestedUsage;
|
const remainingStock = availableStock - requestedUsage;
|
||||||
|
const { pendingQty } = getStockPendingInfo(stock.product_warehouse_id);
|
||||||
|
|
||||||
|
if (isDetail) {
|
||||||
|
if (pendingQty > 0) {
|
||||||
|
return (
|
||||||
|
<span className='text-sm text-gray-600 whitespace-nowrap'>
|
||||||
|
(tersedia: {formatNumber(requestedUsage)} | pending:{' '}
|
||||||
|
<span className='text-error'>{formatNumber(pendingQty)}</span> |
|
||||||
|
pakai: {formatNumber(requestedUsage + pendingQty)})
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (requestedUsage > 0) {
|
if (requestedUsage > 0) {
|
||||||
return (
|
return (
|
||||||
<span className='text-sm text-gray-600 whitespace-nowrap'>
|
<span className='text-sm text-gray-600 whitespace-nowrap'>
|
||||||
@@ -1127,7 +1165,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[formik.values.stocks, getAvailableStock, type]
|
[formik.values.stocks, getAvailableStock, getStockPendingInfo, type]
|
||||||
);
|
);
|
||||||
|
|
||||||
const getProjectFlockBadgeAdornment = useCallback(() => {
|
const getProjectFlockBadgeAdornment = useCallback(() => {
|
||||||
@@ -2550,8 +2588,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' &&
|
{getStockUsageAdornment(idx)}
|
||||||
getStockUsageAdornment(idx)}
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
||||||
@@ -2604,6 +2641,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Depletions Table */}
|
{/* Depletions Table */}
|
||||||
|
{((type as 'add' | 'edit' | 'detail') !== 'detail' ||
|
||||||
|
(formik.values.depletions?.length ?? 0) > 0) && (
|
||||||
<Card
|
<Card
|
||||||
title='Deplesi'
|
title='Deplesi'
|
||||||
className={{
|
className={{
|
||||||
@@ -2685,11 +2724,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
value={
|
value={
|
||||||
depletionProducts.find(
|
depletionProducts.find(
|
||||||
(product) =>
|
(product) =>
|
||||||
product.value === depletion.product_warehouse_id
|
product.value ===
|
||||||
|
depletion.product_warehouse_id
|
||||||
) || null
|
) || null
|
||||||
}
|
}
|
||||||
onChange={(selectedOption) => {
|
onChange={(selectedOption) => {
|
||||||
const option = selectedOption as OptionType | null;
|
const option =
|
||||||
|
selectedOption as OptionType | null;
|
||||||
formik.setFieldValue(
|
formik.setFieldValue(
|
||||||
`depletions.${idx}.product_warehouse_id`,
|
`depletions.${idx}.product_warehouse_id`,
|
||||||
option?.value || 0
|
option?.value || 0
|
||||||
@@ -2802,9 +2843,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Eggs Table - Only for LAYING Category */}
|
{/* Eggs Table - Only for LAYING Category */}
|
||||||
{isLayingCategory && (
|
{isLayingCategory &&
|
||||||
|
((type as 'add' | 'edit' | 'detail') !== 'detail' ||
|
||||||
|
((formik.values as RecordingLayingFormValues).eggs?.length ?? 0) >
|
||||||
|
0) && (
|
||||||
<Card
|
<Card
|
||||||
title='Telur'
|
title='Telur'
|
||||||
className={{
|
className={{
|
||||||
@@ -2821,10 +2866,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<CheckboxInput
|
<CheckboxInput
|
||||||
name='select-all-eggs'
|
name='select-all-eggs'
|
||||||
checked={
|
checked={
|
||||||
((formik.values as RecordingLayingFormValues).eggs
|
((formik.values as RecordingLayingFormValues)
|
||||||
?.length ?? 0) === selectedEggs.length &&
|
.eggs?.length ?? 0) === selectedEggs.length &&
|
||||||
((formik.values as RecordingLayingFormValues).eggs
|
((formik.values as RecordingLayingFormValues)
|
||||||
?.length ?? 0) > 0
|
.eggs?.length ?? 0) > 0
|
||||||
}
|
}
|
||||||
onChange={(
|
onChange={(
|
||||||
e: React.ChangeEvent<HTMLInputElement>
|
e: React.ChangeEvent<HTMLInputElement>
|
||||||
@@ -2874,7 +2919,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
{(formik.values as RecordingLayingFormValues).eggs?.map(
|
{(formik.values as RecordingLayingFormValues).eggs?.map(
|
||||||
(egg, idx) => (
|
(egg, idx) => (
|
||||||
<tr key={`egg-${idx}`}>
|
<tr key={`egg-${idx}`}>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !==
|
||||||
|
'detail' && (
|
||||||
<td className='align-middle!'>
|
<td className='align-middle!'>
|
||||||
<CheckboxInput
|
<CheckboxInput
|
||||||
name={`egg-${idx}`}
|
name={`egg-${idx}`}
|
||||||
@@ -2950,7 +2996,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
thousandSeparator=','
|
thousandSeparator=','
|
||||||
decimalSeparator='.'
|
decimalSeparator='.'
|
||||||
isError={
|
isError={
|
||||||
isRepeaterInputError('eggs', 'qty', idx).isError
|
isRepeaterInputError('eggs', 'qty', idx)
|
||||||
|
.isError
|
||||||
}
|
}
|
||||||
errorMessage={
|
errorMessage={
|
||||||
isRepeaterInputError('eggs', 'qty', idx)
|
isRepeaterInputError('eggs', 'qty', idx)
|
||||||
@@ -2990,7 +3037,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
inputSuffix='Kilogram'
|
inputSuffix='Kilogram'
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !==
|
||||||
|
'detail' && (
|
||||||
<td>
|
<td>
|
||||||
<div className='flex items-center'>
|
<div className='flex items-center'>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user