mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE): report sapronak calculation per kandang
This commit is contained in:
@@ -56,6 +56,7 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
||||
<ClosingSapronakCalculationTabContent
|
||||
closingGeneralInformation={initialValue}
|
||||
projectFlockId={id}
|
||||
projectKandangId={kandangData?.id}
|
||||
/>
|
||||
),
|
||||
},
|
||||
@@ -94,7 +95,9 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
||||
<section className='w-full max-w-7xl pb-16'>
|
||||
<header className='flex flex-col gap-4'>
|
||||
<Button
|
||||
href='/closing'
|
||||
href={
|
||||
!kandangData ? '/closing' : `/closing/detail/?closingId=${id}`
|
||||
}
|
||||
variant='link'
|
||||
className='w-fit p-0 text-primary'
|
||||
>
|
||||
|
||||
@@ -5,11 +5,13 @@ import { ClosingGeneralInformation } from '@/types/api/closing';
|
||||
|
||||
interface ClosingSapronakCalculationTabContentProps {
|
||||
projectFlockId?: number;
|
||||
projectKandangId?: number;
|
||||
closingGeneralInformation?: ClosingGeneralInformation;
|
||||
}
|
||||
|
||||
const ClosingSapronakCalculationTabContent = ({
|
||||
projectFlockId,
|
||||
projectKandangId,
|
||||
closingGeneralInformation,
|
||||
}: ClosingSapronakCalculationTabContentProps) => {
|
||||
return (
|
||||
@@ -19,6 +21,7 @@ const ClosingSapronakCalculationTabContent = ({
|
||||
<ClosingSapronakCalculationTable
|
||||
closingGeneralInformation={closingGeneralInformation}
|
||||
projectFlockId={projectFlockId}
|
||||
projectKandangId={projectKandangId}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -17,16 +17,18 @@ import { ClosingGeneralInformation } from '@/types/api/closing';
|
||||
|
||||
interface ClosingSapronakCalculationTableProps {
|
||||
projectFlockId: number;
|
||||
projectKandangId?: number;
|
||||
closingGeneralInformation?: ClosingGeneralInformation;
|
||||
}
|
||||
|
||||
const ClosingSapronakCalculationTable = ({
|
||||
projectFlockId,
|
||||
closingGeneralInformation,
|
||||
projectKandangId,
|
||||
}: ClosingSapronakCalculationTableProps) => {
|
||||
const { data: sapronakCalculation, isLoading } = useSWR(
|
||||
`/closing/sapronak-calculation/${projectFlockId}`,
|
||||
() => ClosingApi.getPerhitunganSapronak(projectFlockId),
|
||||
`/closing/sapronak-calculation/${projectFlockId}${projectKandangId ? `/${projectKandangId}` : ''}`,
|
||||
() => ClosingApi.getPerhitunganSapronak(projectFlockId, projectKandangId),
|
||||
{
|
||||
keepPreviousData: true,
|
||||
}
|
||||
@@ -57,11 +59,11 @@ const ClosingSapronakCalculationTable = ({
|
||||
cell: (props) =>
|
||||
props.row.original.qty_in
|
||||
? formatNumber(props.row.original.qty_in as number)
|
||||
: '-',
|
||||
: '0',
|
||||
footer: total
|
||||
? () => (
|
||||
<div className='font-semibold text-gray-900'>
|
||||
{total?.qty_in ? formatNumber(total?.qty_in) : '-'}
|
||||
{total?.qty_in ? formatNumber(total?.qty_in) : '0'}
|
||||
</div>
|
||||
)
|
||||
: '',
|
||||
@@ -72,11 +74,11 @@ const ClosingSapronakCalculationTable = ({
|
||||
cell: (props) =>
|
||||
props.row.original.qty_out
|
||||
? formatNumber(props.row.original.qty_out as number)
|
||||
: '-',
|
||||
: '0',
|
||||
footer: total
|
||||
? () => (
|
||||
<div className='font-semibold text-gray-900'>
|
||||
{total?.qty_out ? formatNumber(total?.qty_out) : '-'}
|
||||
{total?.qty_out ? formatNumber(total?.qty_out) : '0'}
|
||||
</div>
|
||||
)
|
||||
: '',
|
||||
@@ -87,11 +89,11 @@ const ClosingSapronakCalculationTable = ({
|
||||
cell: (props) =>
|
||||
props.row.original.qty_used
|
||||
? formatNumber(props.row.original.qty_used as number)
|
||||
: '-',
|
||||
: '0',
|
||||
footer: total
|
||||
? () => (
|
||||
<div className='font-semibold text-gray-900'>
|
||||
{total?.qty_used ? formatNumber(total?.qty_used) : '-'}
|
||||
{total?.qty_used ? formatNumber(total?.qty_used) : '0'}
|
||||
</div>
|
||||
)
|
||||
: '',
|
||||
@@ -173,14 +175,6 @@ const ClosingSapronakCalculationTable = ({
|
||||
[sapronakCalculation]
|
||||
);
|
||||
|
||||
const pulletColumns = useMemo(
|
||||
() =>
|
||||
isResponseSuccess(sapronakCalculation)
|
||||
? createColumns(sapronakCalculation.data?.pullet?.total)
|
||||
: createColumns(),
|
||||
[sapronakCalculation]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-4'>
|
||||
{/* Table DOC jika kategori Project Flock Growing */}
|
||||
@@ -200,20 +194,17 @@ const ClosingSapronakCalculationTable = ({
|
||||
<Table<RowSapronakCalculation>
|
||||
data={
|
||||
isResponseSuccess(sapronakCalculation)
|
||||
? ((closingGeneralInformation?.project_category === 'GROWING'
|
||||
? sapronakCalculation.data?.doc?.rows
|
||||
: sapronakCalculation.data?.pullet?.rows) ?? [])
|
||||
? (sapronakCalculation.data?.doc?.rows ?? [])
|
||||
: []
|
||||
}
|
||||
columns={
|
||||
closingGeneralInformation?.project_category === 'GROWING'
|
||||
? docColumns
|
||||
: pulletColumns
|
||||
}
|
||||
columns={docColumns}
|
||||
className={{
|
||||
containerClassName: 'my-4',
|
||||
}}
|
||||
renderFooter={isResponseSuccess(sapronakCalculation)}
|
||||
renderFooter={
|
||||
isResponseSuccess(sapronakCalculation) &&
|
||||
sapronakCalculation.data?.doc?.rows.length > 0
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -236,7 +227,10 @@ const ClosingSapronakCalculationTable = ({
|
||||
className={{
|
||||
containerClassName: 'my-4',
|
||||
}}
|
||||
renderFooter={isResponseSuccess(sapronakCalculation)}
|
||||
renderFooter={
|
||||
isResponseSuccess(sapronakCalculation) &&
|
||||
sapronakCalculation.data?.ovk?.rows.length > 0
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -259,7 +253,10 @@ const ClosingSapronakCalculationTable = ({
|
||||
className={{
|
||||
containerClassName: 'my-4',
|
||||
}}
|
||||
renderFooter={isResponseSuccess(sapronakCalculation)}
|
||||
renderFooter={
|
||||
isResponseSuccess(sapronakCalculation) &&
|
||||
sapronakCalculation.data?.pakan?.rows.length > 0
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -92,10 +92,11 @@ export class ClosingApiService extends BaseApiService<Closing, null, null> {
|
||||
}
|
||||
|
||||
async getPerhitunganSapronak(
|
||||
id: number
|
||||
id: number,
|
||||
projectKandangId?: number
|
||||
): Promise<BaseApiResponse<ClosingSapronakCalculation> | undefined> {
|
||||
try {
|
||||
const path = `${this.basePath}/${id}/perhitungan_sapronak`;
|
||||
const path = `${this.basePath}/${id}${projectKandangId ? `/${projectKandangId}` : ''}/perhitungan_sapronak`;
|
||||
return await httpClient<BaseApiResponse<ClosingSapronakCalculation>>(
|
||||
path,
|
||||
{
|
||||
|
||||
Vendored
-1
@@ -185,7 +185,6 @@ export type ClosingSapronakCalculation = {
|
||||
doc: ClosingSapronakCalculationItem;
|
||||
ovk: ClosingSapronakCalculationItem;
|
||||
pakan: ClosingSapronakCalculationItem;
|
||||
pullet: ClosingSapronakCalculationItem;
|
||||
};
|
||||
|
||||
// ====== OVERHEAD ======
|
||||
|
||||
Reference in New Issue
Block a user