feat(FE): report sapronak calculation per kandang

This commit is contained in:
randy-ar
2026-01-12 13:44:03 +07:00
parent d879acc001
commit d6c6211937
5 changed files with 34 additions and 31 deletions
@@ -56,6 +56,7 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
<ClosingSapronakCalculationTabContent <ClosingSapronakCalculationTabContent
closingGeneralInformation={initialValue} closingGeneralInformation={initialValue}
projectFlockId={id} projectFlockId={id}
projectKandangId={kandangData?.id}
/> />
), ),
}, },
@@ -94,7 +95,9 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
<section className='w-full max-w-7xl pb-16'> <section className='w-full max-w-7xl pb-16'>
<header className='flex flex-col gap-4'> <header className='flex flex-col gap-4'>
<Button <Button
href='/closing' href={
!kandangData ? '/closing' : `/closing/detail/?closingId=${id}`
}
variant='link' variant='link'
className='w-fit p-0 text-primary' className='w-fit p-0 text-primary'
> >
@@ -5,11 +5,13 @@ import { ClosingGeneralInformation } from '@/types/api/closing';
interface ClosingSapronakCalculationTabContentProps { interface ClosingSapronakCalculationTabContentProps {
projectFlockId?: number; projectFlockId?: number;
projectKandangId?: number;
closingGeneralInformation?: ClosingGeneralInformation; closingGeneralInformation?: ClosingGeneralInformation;
} }
const ClosingSapronakCalculationTabContent = ({ const ClosingSapronakCalculationTabContent = ({
projectFlockId, projectFlockId,
projectKandangId,
closingGeneralInformation, closingGeneralInformation,
}: ClosingSapronakCalculationTabContentProps) => { }: ClosingSapronakCalculationTabContentProps) => {
return ( return (
@@ -19,6 +21,7 @@ const ClosingSapronakCalculationTabContent = ({
<ClosingSapronakCalculationTable <ClosingSapronakCalculationTable
closingGeneralInformation={closingGeneralInformation} closingGeneralInformation={closingGeneralInformation}
projectFlockId={projectFlockId} projectFlockId={projectFlockId}
projectKandangId={projectKandangId}
/> />
</> </>
)} )}
@@ -17,16 +17,18 @@ import { ClosingGeneralInformation } from '@/types/api/closing';
interface ClosingSapronakCalculationTableProps { interface ClosingSapronakCalculationTableProps {
projectFlockId: number; projectFlockId: number;
projectKandangId?: number;
closingGeneralInformation?: ClosingGeneralInformation; closingGeneralInformation?: ClosingGeneralInformation;
} }
const ClosingSapronakCalculationTable = ({ const ClosingSapronakCalculationTable = ({
projectFlockId, projectFlockId,
closingGeneralInformation, closingGeneralInformation,
projectKandangId,
}: ClosingSapronakCalculationTableProps) => { }: ClosingSapronakCalculationTableProps) => {
const { data: sapronakCalculation, isLoading } = useSWR( const { data: sapronakCalculation, isLoading } = useSWR(
`/closing/sapronak-calculation/${projectFlockId}`, `/closing/sapronak-calculation/${projectFlockId}${projectKandangId ? `/${projectKandangId}` : ''}`,
() => ClosingApi.getPerhitunganSapronak(projectFlockId), () => ClosingApi.getPerhitunganSapronak(projectFlockId, projectKandangId),
{ {
keepPreviousData: true, keepPreviousData: true,
} }
@@ -57,11 +59,11 @@ const ClosingSapronakCalculationTable = ({
cell: (props) => cell: (props) =>
props.row.original.qty_in props.row.original.qty_in
? formatNumber(props.row.original.qty_in as number) ? formatNumber(props.row.original.qty_in as number)
: '-', : '0',
footer: total footer: total
? () => ( ? () => (
<div className='font-semibold text-gray-900'> <div className='font-semibold text-gray-900'>
{total?.qty_in ? formatNumber(total?.qty_in) : '-'} {total?.qty_in ? formatNumber(total?.qty_in) : '0'}
</div> </div>
) )
: '', : '',
@@ -72,11 +74,11 @@ const ClosingSapronakCalculationTable = ({
cell: (props) => cell: (props) =>
props.row.original.qty_out props.row.original.qty_out
? formatNumber(props.row.original.qty_out as number) ? formatNumber(props.row.original.qty_out as number)
: '-', : '0',
footer: total footer: total
? () => ( ? () => (
<div className='font-semibold text-gray-900'> <div className='font-semibold text-gray-900'>
{total?.qty_out ? formatNumber(total?.qty_out) : '-'} {total?.qty_out ? formatNumber(total?.qty_out) : '0'}
</div> </div>
) )
: '', : '',
@@ -87,11 +89,11 @@ const ClosingSapronakCalculationTable = ({
cell: (props) => cell: (props) =>
props.row.original.qty_used props.row.original.qty_used
? formatNumber(props.row.original.qty_used as number) ? formatNumber(props.row.original.qty_used as number)
: '-', : '0',
footer: total footer: total
? () => ( ? () => (
<div className='font-semibold text-gray-900'> <div className='font-semibold text-gray-900'>
{total?.qty_used ? formatNumber(total?.qty_used) : '-'} {total?.qty_used ? formatNumber(total?.qty_used) : '0'}
</div> </div>
) )
: '', : '',
@@ -173,14 +175,6 @@ const ClosingSapronakCalculationTable = ({
[sapronakCalculation] [sapronakCalculation]
); );
const pulletColumns = useMemo(
() =>
isResponseSuccess(sapronakCalculation)
? createColumns(sapronakCalculation.data?.pullet?.total)
: createColumns(),
[sapronakCalculation]
);
return ( return (
<div className='flex flex-col gap-4'> <div className='flex flex-col gap-4'>
{/* Table DOC jika kategori Project Flock Growing */} {/* Table DOC jika kategori Project Flock Growing */}
@@ -200,20 +194,17 @@ const ClosingSapronakCalculationTable = ({
<Table<RowSapronakCalculation> <Table<RowSapronakCalculation>
data={ data={
isResponseSuccess(sapronakCalculation) isResponseSuccess(sapronakCalculation)
? ((closingGeneralInformation?.project_category === 'GROWING' ? (sapronakCalculation.data?.doc?.rows ?? [])
? sapronakCalculation.data?.doc?.rows
: sapronakCalculation.data?.pullet?.rows) ?? [])
: [] : []
} }
columns={ columns={docColumns}
closingGeneralInformation?.project_category === 'GROWING'
? docColumns
: pulletColumns
}
className={{ className={{
containerClassName: 'my-4', containerClassName: 'my-4',
}} }}
renderFooter={isResponseSuccess(sapronakCalculation)} renderFooter={
isResponseSuccess(sapronakCalculation) &&
sapronakCalculation.data?.doc?.rows.length > 0
}
/> />
</Card> </Card>
@@ -236,7 +227,10 @@ const ClosingSapronakCalculationTable = ({
className={{ className={{
containerClassName: 'my-4', containerClassName: 'my-4',
}} }}
renderFooter={isResponseSuccess(sapronakCalculation)} renderFooter={
isResponseSuccess(sapronakCalculation) &&
sapronakCalculation.data?.ovk?.rows.length > 0
}
/> />
</Card> </Card>
@@ -259,7 +253,10 @@ const ClosingSapronakCalculationTable = ({
className={{ className={{
containerClassName: 'my-4', containerClassName: 'my-4',
}} }}
renderFooter={isResponseSuccess(sapronakCalculation)} renderFooter={
isResponseSuccess(sapronakCalculation) &&
sapronakCalculation.data?.pakan?.rows.length > 0
}
/> />
</Card> </Card>
</div> </div>
+3 -2
View File
@@ -92,10 +92,11 @@ export class ClosingApiService extends BaseApiService<Closing, null, null> {
} }
async getPerhitunganSapronak( async getPerhitunganSapronak(
id: number id: number,
projectKandangId?: number
): Promise<BaseApiResponse<ClosingSapronakCalculation> | undefined> { ): Promise<BaseApiResponse<ClosingSapronakCalculation> | undefined> {
try { try {
const path = `${this.basePath}/${id}/perhitungan_sapronak`; const path = `${this.basePath}/${id}${projectKandangId ? `/${projectKandangId}` : ''}/perhitungan_sapronak`;
return await httpClient<BaseApiResponse<ClosingSapronakCalculation>>( return await httpClient<BaseApiResponse<ClosingSapronakCalculation>>(
path, path,
{ {
-1
View File
@@ -185,7 +185,6 @@ export type ClosingSapronakCalculation = {
doc: ClosingSapronakCalculationItem; doc: ClosingSapronakCalculationItem;
ovk: ClosingSapronakCalculationItem; ovk: ClosingSapronakCalculationItem;
pakan: ClosingSapronakCalculationItem; pakan: ClosingSapronakCalculationItem;
pullet: ClosingSapronakCalculationItem;
}; };
// ====== OVERHEAD ====== // ====== OVERHEAD ======