feat(FE-344,345): Integrate HPP Ekspedisi into Closing detail

This commit is contained in:
rstubryan
2025-12-11 15:04:37 +07:00
parent 38b91a57f0
commit bd8d121113
4 changed files with 79 additions and 53 deletions
+11 -1
View File
@@ -24,6 +24,11 @@ const ClosingDetailPage = () => {
() => ClosingApi.getPenjualan(Number(closingId)) () => ClosingApi.getPenjualan(Number(closingId))
); );
const { data: hppEkspedisiData, isLoading: isLoadingHppEkspedisi } = useSWR(
closingId ? `hpp-ekspedisi-${closingId}` : null,
() => ClosingApi.getHppEkspedisi(Number(closingId))
);
if (!closingId) { if (!closingId) {
router.back(); router.back();
@@ -39,7 +44,7 @@ const ClosingDetailPage = () => {
return; return;
} }
const isLoading = isLoadingClosing || isLoadingSales; const isLoading = isLoadingClosing || isLoadingSales || isLoadingHppEkspedisi;
return ( return (
<div className='w-full p-4 flex flex-row justify-center'> <div className='w-full p-4 flex flex-row justify-center'>
@@ -50,6 +55,11 @@ const ClosingDetailPage = () => {
id={Number(closingId)} id={Number(closingId)}
initialValue={closing.data} initialValue={closing.data}
salesData={isResponseSuccess(salesData) ? salesData.data : undefined} salesData={isResponseSuccess(salesData) ? salesData.data : undefined}
costOfRevenueExpeditionData={
isResponseSuccess(hppEkspedisiData)
? hppEkspedisiData.data
: undefined
}
/> />
)} )}
</div> </div>
@@ -21,25 +21,16 @@ const CostOfRevenueExpeditionReportTable = ({
}: CostOfRevenueExpeditionReportTableProps) => { }: CostOfRevenueExpeditionReportTableProps) => {
const costOfRevenueExpeditionData: BaseCostOfRevenueExpedition[] = const costOfRevenueExpeditionData: BaseCostOfRevenueExpedition[] =
useMemo(() => { useMemo(() => {
return initialValues?.cos_expeditions || []; return initialValues?.expedition_costs || [];
}, [initialValues]); }, [initialValues]);
const totals = useMemo(() => { const totals = useMemo(() => {
if (costOfRevenueExpeditionData.length === 0) { const totalHpp = initialValues?.total_hpp_amount || 0;
return {
totalHpp: 0,
};
}
const totalHpp = costOfRevenueExpeditionData.reduce(
(sum, item) => sum + (item.hpp || 0),
0
);
return { return {
totalHpp, totalHpp,
}; };
}, [costOfRevenueExpeditionData]); }, [initialValues]);
const costOfRevenueExpeditionColumns: ColumnDef<BaseCostOfRevenueExpedition>[] = const costOfRevenueExpeditionColumns: ColumnDef<BaseCostOfRevenueExpedition>[] =
useMemo( useMemo(
@@ -58,14 +49,14 @@ const CostOfRevenueExpeditionReportTable = ({
), ),
}, },
{ {
id: 'expedition_name', id: 'expedition_vendor_name',
accessorKey: 'expedition_name', accessorKey: 'expedition_vendor_name',
header: 'Nama Ekspedisi', header: 'Nama Ekspedisi',
cell: (props) => props.getValue() || '-', cell: (props) => props.getValue() || '-',
}, },
{ {
id: 'hpp', id: 'hpp_amount',
accessorKey: 'hpp', accessorKey: 'hpp_amount',
header: 'HPP Ekspedisi', header: 'HPP Ekspedisi',
cell: (props) => { cell: (props) => {
const value = props.getValue() as number; const value = props.getValue() as number;
+23
View File
@@ -6,6 +6,7 @@ import {
ClosingGeneralInformation, ClosingGeneralInformation,
ClosingIncomingSapronak, ClosingIncomingSapronak,
ClosingOutgoingSapronak, ClosingOutgoingSapronak,
ClosingCostOfRevenueExpedition,
} from '@/types/api/closing'; } from '@/types/api/closing';
import { httpClient, httpClientFetcher } from '@/services/http/client'; import { httpClient, httpClientFetcher } from '@/services/http/client';
import { BaseApiResponse } from '@/types/api/api-general'; import { BaseApiResponse } from '@/types/api/api-general';
@@ -33,6 +34,28 @@ export class ClosingApiService extends BaseApiService<Closing, null, null> {
} }
} }
async getHppEkspedisi(
id: number
): Promise<BaseApiResponse<ClosingCostOfRevenueExpedition> | undefined> {
try {
const getHppEkspedisiPath = `${this.basePath}/${id}/hpp-ekspedisi`;
const getHppEkspedisiRes =
await httpClient<BaseApiResponse<ClosingCostOfRevenueExpedition>>(
getHppEkspedisiPath
);
return getHppEkspedisiRes;
} catch (error) {
if (
axios.isAxiosError<BaseApiResponse<ClosingCostOfRevenueExpedition>>(
error
)
) {
return error.response?.data;
}
return undefined;
}
}
async getAllIncomingSapronakFetcher( async getAllIncomingSapronakFetcher(
endpoint: string endpoint: string
): Promise<BaseApiResponse<ClosingIncomingSapronak[]>> { ): Promise<BaseApiResponse<ClosingIncomingSapronak[]>> {
+38 -36
View File
@@ -7,26 +7,6 @@ import { Product } from '@type/api/master-data/product';
import { Customer } from '@type/api/master-data/customer'; import { Customer } from '@type/api/master-data/customer';
import { BaseMetadata } from '@/types/api/api-general'; import { BaseMetadata } from '@/types/api/api-general';
export type BaseSales = {
id: number;
realization_date: string;
age: number;
do_number: string;
product: Product;
customer: Customer;
qty: number;
weight: number;
avg_weight: number;
price: number;
total_price: number;
kandang: Kandang;
payment_status: string;
};
export type BaseClosingSales = {
sales: BaseSales[];
};
export type BaseClosing = { export type BaseClosing = {
id: number; id: number;
location_id: number; location_id: number;
@@ -44,22 +24,6 @@ export type BaseClosing = {
export type Closing = BaseMetadata & BaseClosing; export type Closing = BaseMetadata & BaseClosing;
export type BaseCostOfRevenueExpedition = {
id: number;
expedition_name: string;
hpp: number;
};
export type BaseClosingCostOfRevenueExpedition = {
project_type: string;
flock_id: number;
period: number;
cos_expeditions: BaseCostOfRevenueExpedition[];
};
export type ClosingCostOfRevenueExpedition = BaseMetadata &
BaseClosingCostOfRevenueExpedition;
export type BaseClosingGeneralInformation = BaseClosing & { export type BaseClosingGeneralInformation = BaseClosing & {
flock_id: number; flock_id: number;
period: number; period: number;
@@ -91,4 +55,42 @@ export type ClosingIncomingSapronak = {
}; };
export type ClosingOutgoingSapronak = ClosingIncomingSapronak; export type ClosingOutgoingSapronak = ClosingIncomingSapronak;
export type BaseSales = {
id: number;
realization_date: string;
age: number;
do_number: string;
product: Product;
customer: Customer;
qty: number;
weight: number;
avg_weight: number;
price: number;
total_price: number;
kandang: Kandang;
payment_status: string;
};
export type BaseClosingSales = {
sales: BaseSales[];
};
export type ClosingSales = BaseMetadata & BaseClosingSales; export type ClosingSales = BaseMetadata & BaseClosingSales;
export type BaseCostOfRevenueExpedition = {
id: number;
expedition_vendor_id: number;
expedition_vendor_name: string;
qty: number;
unit_price: number;
hpp_amount: number;
};
export type BaseClosingCostOfRevenueExpedition = {
expedition_costs: BaseCostOfRevenueExpedition[];
total_hpp_amount: number;
};
export type ClosingCostOfRevenueExpedition = BaseMetadata &
BaseClosingCostOfRevenueExpedition;