diff --git a/src/app/closing/detail/page.tsx b/src/app/closing/detail/page.tsx
index e630a279..f271700b 100644
--- a/src/app/closing/detail/page.tsx
+++ b/src/app/closing/detail/page.tsx
@@ -7,18 +7,33 @@ import ClosingDetail from '@/components/pages/closing/ClosingDetail';
import { ClosingApi } from '@/services/api/closing';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
+import { FlockApi } from '@/services/api/master-data';
+import { ProjectFlockApi } from '@/services/api/production/project-flock';
+import { ProjectFlockKandangApi } from '@/services/api/production';
const ClosingDetailPage = () => {
const router = useRouter();
const searchParams = useSearchParams();
const closingId = searchParams.get('closingId');
+ const kandangId = searchParams.get('kandangId'); // project flock kandang ID
const { data: closing, isLoading: isLoadingClosing } = useSWR(
closingId,
(id: number) => ClosingApi.getGeneralInfo(id)
);
+ // WORKAROUND - get flock data from closing ID
+ const { data: projectData, isLoading: isLoadingProject } = useSWR(
+ `flock-${closingId}`,
+ () => ProjectFlockApi.getSingle(Number(closingId))
+ );
+ // WORKAROUND - get kandang data from closing ID
+ const { data: kandangData, isLoading: isLoadingKandang } = useSWR(
+ kandangId ? `kandang-${closingId}-${kandangId}` : null,
+ () => ProjectFlockKandangApi.getSingle(Number(kandangId))
+ );
+
const { data: salesData, isLoading: isLoadingSales } = useSWR(
closingId ? `sales-${closingId}` : null,
() => ClosingApi.getPenjualan(Number(closingId))
@@ -44,8 +59,12 @@ const ClosingDetailPage = () => {
return;
}
- const isLoading = isLoadingClosing || isLoadingHppEkspedisi;
- // const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi;
+ const isLoading =
+ isLoadingClosing ||
+ isLoadingSales ||
+ isLoadingHppEkspedisi ||
+ isLoadingProject ||
+ isLoadingKandang;
return (
@@ -61,6 +80,12 @@ const ClosingDetailPage = () => {
? hppEkspedisiData.data
: undefined
}
+ projectData={
+ isResponseSuccess(projectData) ? projectData.data : undefined
+ }
+ kandangData={
+ isResponseSuccess(kandangData) ? kandangData.data : undefined
+ }
/>
)}
diff --git a/src/components/pages/closing/ClosingDetail.tsx b/src/components/pages/closing/ClosingDetail.tsx
index 3de2ffe9..441c84dd 100644
--- a/src/components/pages/closing/ClosingDetail.tsx
+++ b/src/components/pages/closing/ClosingDetail.tsx
@@ -19,12 +19,17 @@ import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverhea
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable';
import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable';
+import ClosingKandangList from '@/components/pages/closing/ClosingKandangList';
+import { ProjectFlock } from '@/types/api/production/project-flock';
+import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
interface ClosingDetailProps {
id: number;
initialValue?: ClosingGeneralInformation;
salesData?: BaseClosingSales;
hppExpeditionData?: ClosingHppExpedition;
+ projectData?: ProjectFlock;
+ kandangData?: ProjectFlockKandang;
}
const ClosingDetail: React.FC = ({
@@ -32,6 +37,8 @@ const ClosingDetail: React.FC = ({
initialValue,
salesData,
hppExpeditionData,
+ projectData,
+ kandangData,
}) => {
const [activeTab, setActiveTab] = useState('sapronak');
@@ -49,6 +56,7 @@ const ClosingDetail: React.FC = ({
),
},
@@ -87,7 +95,9 @@ const ClosingDetail: React.FC = ({
-
+
+
+ {!kandangData && (
+
+ )}
{
+ const chickinPopulation = useMemo(() => {
+ if (kandangData) {
+ return kandangData?.chickins?.reduce(
+ (acc, chickin) => acc + chickin.usage_qty,
+ 0
+ );
+ }
+ return 0;
+ }, [kandangData]);
+
return (
@@ -17,7 +34,9 @@ const ClosingGeneralInformationTable = ({
| Lokasi |
: |
- {initialValue?.location_name} |
+
+ {initialValue?.location_name ?? projectData?.location?.name}
+ |
| Periode |
@@ -27,12 +46,20 @@ const ClosingGeneralInformationTable = ({
| Project Flock |
: |
- {initialValue?.project_flock?.name} |
+
+ {initialValue?.project_flock?.name ??
+ projectData?.flock_name}
+ |
| Populasi |
: |
- {initialValue?.population} Ekor |
+
+ {!kandangData
+ ? (initialValue?.population ?? 0)
+ : (chickinPopulation ?? 0)}{' '}
+ Ekor
+ |
| Jenis Project |
@@ -40,9 +67,13 @@ const ClosingGeneralInformationTable = ({
{initialValue?.project_type} |
- | Kandang Aktif |
+ Kandang {!kandangData && 'Aktif'} |
: |
- {initialValue?.active_house_count} Kandang |
+
+ {!kandangData
+ ? `${initialValue?.active_house_count} Kandang`
+ : kandangData?.kandang?.name}
+ |
| Status Pembayaran Penjualan |
@@ -69,9 +100,13 @@ const ClosingGeneralInformationTable = ({
- | Kandang Aktif |
+ Kandang {!kandangData && 'Aktif'} |
: |
- {initialValue?.active_house_count} Kandang |
+
+ {!kandangData
+ ? `${initialValue?.active_house_count} Kandang`
+ : kandangData?.kandang?.name}
+ |
| Status Pembayaran Penjualan |
diff --git a/src/components/pages/closing/ClosingKandangList.tsx b/src/components/pages/closing/ClosingKandangList.tsx
new file mode 100644
index 00000000..dd3083a7
--- /dev/null
+++ b/src/components/pages/closing/ClosingKandangList.tsx
@@ -0,0 +1,37 @@
+import Button from '@/components/Button';
+import { ClosingGeneralInformation } from '@/types/api/closing';
+import { ProjectFlock } from '@/types/api/production/project-flock';
+
+const ClosingKandangList = ({
+ initialValue,
+ projectData,
+}: {
+ initialValue?: ClosingGeneralInformation;
+ projectData?: ProjectFlock;
+}) => {
+ return (
+
+
+
+
+
Kandang
+
+ {projectData?.kandangs?.map((kandang) => (
+
+ ))}
+
+
+
+
+
+ );
+};
+
+export default ClosingKandangList;
diff --git a/src/components/pages/closing/ClosingSapronakCalculationTabContent.tsx b/src/components/pages/closing/ClosingSapronakCalculationTabContent.tsx
index b8add15b..cae2d406 100644
--- a/src/components/pages/closing/ClosingSapronakCalculationTabContent.tsx
+++ b/src/components/pages/closing/ClosingSapronakCalculationTabContent.tsx
@@ -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 = ({
>
)}
diff --git a/src/components/pages/closing/ClosingSapronakCalculationTable.tsx b/src/components/pages/closing/ClosingSapronakCalculationTable.tsx
index 6e3b1a95..17527959 100644
--- a/src/components/pages/closing/ClosingSapronakCalculationTable.tsx
+++ b/src/components/pages/closing/ClosingSapronakCalculationTable.tsx
@@ -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
? () => (
- {total?.qty_in ? formatNumber(total?.qty_in) : '-'}
+ {total?.qty_in ? formatNumber(total?.qty_in) : '0'}
)
: '',
@@ -72,11 +74,11 @@ const ClosingSapronakCalculationTable = ({
cell: (props) =>
props.row.original.qty_out
? formatNumber(props.row.original.qty_out as number)
- : '-',
+ : '0',
footer: total
? () => (
- {total?.qty_out ? formatNumber(total?.qty_out) : '-'}
+ {total?.qty_out ? formatNumber(total?.qty_out) : '0'}
)
: '',
@@ -87,11 +89,11 @@ const ClosingSapronakCalculationTable = ({
cell: (props) =>
props.row.original.qty_used
? formatNumber(props.row.original.qty_used as number)
- : '-',
+ : '0',
footer: total
? () => (
- {total?.qty_used ? formatNumber(total?.qty_used) : '-'}
+ {total?.qty_used ? formatNumber(total?.qty_used) : '0'}
)
: '',
@@ -173,14 +175,6 @@ const ClosingSapronakCalculationTable = ({
[sapronakCalculation]
);
- const pulletColumns = useMemo(
- () =>
- isResponseSuccess(sapronakCalculation)
- ? createColumns(sapronakCalculation.data?.pullet?.total)
- : createColumns(),
- [sapronakCalculation]
- );
-
return (
{/* Table DOC jika kategori Project Flock Growing */}
@@ -200,20 +194,17 @@ const ClosingSapronakCalculationTable = ({
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
+ }
/>
@@ -236,7 +227,10 @@ const ClosingSapronakCalculationTable = ({
className={{
containerClassName: 'my-4',
}}
- renderFooter={isResponseSuccess(sapronakCalculation)}
+ renderFooter={
+ isResponseSuccess(sapronakCalculation) &&
+ sapronakCalculation.data?.ovk?.rows.length > 0
+ }
/>
@@ -259,7 +253,10 @@ const ClosingSapronakCalculationTable = ({
className={{
containerClassName: 'my-4',
}}
- renderFooter={isResponseSuccess(sapronakCalculation)}
+ renderFooter={
+ isResponseSuccess(sapronakCalculation) &&
+ sapronakCalculation.data?.pakan?.rows.length > 0
+ }
/>
diff --git a/src/components/pages/report/finance/tab/DebtSupplierTab.tsx b/src/components/pages/report/finance/tab/DebtSupplierTab.tsx
index 8ac75821..c8df2120 100644
--- a/src/components/pages/report/finance/tab/DebtSupplierTab.tsx
+++ b/src/components/pages/report/finance/tab/DebtSupplierTab.tsx
@@ -96,7 +96,7 @@ const DebtSupplierTab = () => {
filterSupplier.length > 0
? filterSupplier.map((v) => String(v.value)).join(',')
: undefined,
- filter_by: 'do_date' as const,
+ filter_by: filterDataType?.value || 'do_date',
start_date: filterStartDate || undefined,
end_date: filterEndDate || undefined,
page: currentPage,
@@ -109,7 +109,7 @@ const DebtSupplierTab = () => {
([, params]) =>
FinanceApi.getDebtSupplierReport(
params.supplier_ids,
- params.filter_by,
+ params.filter_by?.toString(),
params.start_date,
params.end_date,
params.page,
@@ -448,7 +448,7 @@ const DebtSupplierTab = () => {
0}
className={{
containerClassName: 'w-full',
@@ -534,6 +534,7 @@ const DebtSupplierTab = () => {
{
diff --git a/src/services/api/closing.ts b/src/services/api/closing.ts
index c1f0db62..8ea2faa5 100644
--- a/src/services/api/closing.ts
+++ b/src/services/api/closing.ts
@@ -92,10 +92,11 @@ export class ClosingApiService extends BaseApiService {
}
async getPerhitunganSapronak(
- id: number
+ id: number,
+ projectKandangId?: number
): Promise | undefined> {
try {
- const path = `${this.basePath}/${id}/perhitungan_sapronak`;
+ const path = `${this.basePath}/${id}${projectKandangId ? `/${projectKandangId}` : ''}/perhitungan_sapronak`;
return await httpClient>(
path,
{
diff --git a/src/services/api/report/finance-report.ts b/src/services/api/report/finance-report.ts
index 85f8a356..014b9fec 100644
--- a/src/services/api/report/finance-report.ts
+++ b/src/services/api/report/finance-report.ts
@@ -40,7 +40,7 @@ export class FinanceApiService extends BaseApiService<
async getDebtSupplierReport(
supplier_ids?: string,
- filter_by?: 'do_date',
+ filter_by?: string,
start_date?: string,
end_date?: string,
page?: number,
diff --git a/src/types/api/closing.d.ts b/src/types/api/closing.d.ts
index 95d1526d..b5fd2f67 100644
--- a/src/types/api/closing.d.ts
+++ b/src/types/api/closing.d.ts
@@ -185,7 +185,6 @@ export type ClosingSapronakCalculation = {
doc: ClosingSapronakCalculationItem;
ovk: ClosingSapronakCalculationItem;
pakan: ClosingSapronakCalculationItem;
- pullet: ClosingSapronakCalculationItem;
};
// ====== OVERHEAD ======