diff --git a/src/app/closing/detail/page.tsx b/src/app/closing/detail/page.tsx index 1b4ebc45..62f3fa20 100644 --- a/src/app/closing/detail/page.tsx +++ b/src/app/closing/detail/page.tsx @@ -24,6 +24,11 @@ const ClosingDetailPage = () => { () => ClosingApi.getPenjualan(Number(closingId)) ); + const { data: hppEkspedisiData, isLoading: isLoadingHppEkspedisi } = useSWR( + closingId ? `hpp-ekspedisi-${closingId}` : null, + () => ClosingApi.getHppEkspedisi(Number(closingId)) + ); + if (!closingId) { router.back(); @@ -39,7 +44,7 @@ const ClosingDetailPage = () => { return; } - const isLoading = isLoadingClosing || isLoadingSales; + const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi; return (
@@ -50,6 +55,11 @@ const ClosingDetailPage = () => { id={Number(closingId)} initialValue={closing.data} salesData={isResponseSuccess(salesData) ? salesData.data : undefined} + hppExpeditionData={ + isResponseSuccess(hppEkspedisiData) + ? hppEkspedisiData.data + : undefined + } /> )}
diff --git a/src/components/pages/closing/ClosingDetail.tsx b/src/components/pages/closing/ClosingDetail.tsx index 8a6331f0..94647f87 100644 --- a/src/components/pages/closing/ClosingDetail.tsx +++ b/src/components/pages/closing/ClosingDetail.tsx @@ -12,22 +12,26 @@ import ClosingProductionDataTabContent from '@/components/pages/closing/ClosingP import { ClosingGeneralInformation, BaseClosingSales, + ClosingHppExpedition, } from '@/types/api/closing'; import ClosingSapronakCalculationTabContent from '@/components/pages/closing/ClosingSapronakCalculationTabContent'; import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverheadTabContent'; import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent'; import SalesReportTable from '@/components/pages/closing/sale/SalesReportTable'; +import HppExpeditionReportTable from './hpp-ekspedisi/HppExpeditionReportTable'; interface ClosingDetailProps { id: number; initialValue?: ClosingGeneralInformation; salesData?: BaseClosingSales; + hppExpeditionData?: ClosingHppExpedition; } const ClosingDetail: React.FC = ({ id, initialValue, salesData, + hppExpeditionData, }) => { const [activeTab, setActiveTab] = useState('sapronak'); @@ -56,7 +60,7 @@ const ClosingDetail: React.FC = ({ { id: 'hppEkspedisi', label: 'HPP Ekspedisi', - content: 'HPP Ekspedisi', + content: , }, { id: 'dataProduksi', diff --git a/src/components/pages/closing/hpp-ekspedisi/HppExpeditionReportTable.tsx b/src/components/pages/closing/hpp-ekspedisi/HppExpeditionReportTable.tsx new file mode 100644 index 00000000..f683ec58 --- /dev/null +++ b/src/components/pages/closing/hpp-ekspedisi/HppExpeditionReportTable.tsx @@ -0,0 +1,110 @@ +'use client'; + +import React, { useMemo } from 'react'; +import { ColumnDef } from '@tanstack/react-table'; +import Table from '@/components/Table'; +import Card from '@/components/Card'; +import { formatCurrency } from '@/lib/helper'; +import { BaseHppExpedition, BaseExpeditionCost } from '@/types/api/closing'; + +interface HppExpeditionReportTableProps { + type?: 'detail'; + initialValues?: BaseHppExpedition; +} + +const HppExpeditionReportTable = ({ + type = 'detail', + initialValues, +}: HppExpeditionReportTableProps) => { + const costOfRevenueExpeditionData: BaseExpeditionCost[] = useMemo(() => { + return initialValues?.expedition_costs || []; + }, [initialValues]); + + const totals = useMemo(() => { + const totalHpp = initialValues?.total_hpp_amount || 0; + + return { + totalHpp, + }; + }, [initialValues]); + + const costOfRevenueExpeditionColumns: ColumnDef[] = + useMemo( + () => [ + { + id: 'id', + accessorKey: 'id', + header: 'No', + cell: (props) => { + return
{props.row.index + 1}
; + }, + footer: () => ( +
+ Total HPP Ekspedisi +
+ ), + }, + { + id: 'expedition_vendor_name', + accessorKey: 'expedition_vendor_name', + header: 'Nama Ekspedisi', + cell: (props) => props.getValue() || '-', + }, + { + id: 'hpp_amount', + accessorKey: 'hpp_amount', + header: 'HPP Ekspedisi', + cell: (props) => { + const value = props.getValue() as number; + return
{formatCurrency(value)}
; + }, + footer: () => ( +
+ {formatCurrency(totals.totalHpp)} +
+ ), + }, + ], + [totals] + ); + + return ( + <> +
+
+

HPP Ekspedisi

+ + 0} + className={{ + tableWrapperClassName: 'overflow-x-auto', + tableClassName: 'w-full table-auto text-sm', + headerRowClassName: 'border-b border-b-gray-200', + headerColumnClassName: + 'px-4 py-3 text-xs font-semibold text-gray-500 last:flex last:flex-row last:justify-end whitespace-nowrap', + bodyRowClassName: + 'hover:bg-gray-50 transition-colors border-b border-l border-r border-b-gray-200 border-l-gray-200 border-r-gray-200', + bodyColumnClassName: + 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', + tableFooterClassName: + 'bg-gray-100 font-semibold border border-gray-200', + footerRowClassName: 'border-t-2 border-gray-300', + footerColumnClassName: + 'px-4 py-3 text-xs text-gray-900 whitespace-nowrap', + }} + /> + + + + + ); +}; + +export default HppExpeditionReportTable; diff --git a/src/services/api/closing.ts b/src/services/api/closing.ts index 6e38a5e4..9513760c 100644 --- a/src/services/api/closing.ts +++ b/src/services/api/closing.ts @@ -10,6 +10,7 @@ import { ClosingOverhead, ClosingSapronakCalculation, ClosingProductionData, + ClosingHppExpedition, } from '@/types/api/closing'; import { BaseApiResponse } from '@/types/api/api-general'; import { httpClient, httpClientFetcher } from '@/services/http/client'; @@ -156,6 +157,24 @@ export class ClosingApiService extends BaseApiService { return undefined; } } + + async getHppEkspedisi( + id: number + ): Promise | undefined> { + try { + const getHppEkspedisiPath = `${this.basePath}/${id}/expedition-hpp`; + const getHppEkspedisiRes = + await httpClient>( + getHppEkspedisiPath + ); + return getHppEkspedisiRes; + } catch (error) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + return undefined; + } + } } export const ClosingApi = new ClosingApiService('/closings'); diff --git a/src/types/api/closing.d.ts b/src/types/api/closing.d.ts index 38d135ab..c23354f8 100644 --- a/src/types/api/closing.d.ts +++ b/src/types/api/closing.d.ts @@ -283,3 +283,16 @@ export interface DataSummarySubTotal { rp_per_kg: number; amount: number; } + +export type BaseExpeditionCost = { + id: number; + expedition_vendor_name: string; + hpp_amount: number; +}; + +export type BaseHppExpedition = { + expedition_costs: BaseExpeditionCost[]; + total_hpp_amount: number; +}; + +export type ClosingHppExpedition = BaseMetadata & BaseHppExpedition;