mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
feat(FE): Closing Finance and adjust reports expense filter request
This commit is contained in:
+35
-17
@@ -60,6 +60,12 @@ export interface TableProps<TData extends object> {
|
||||
renderFooter?: boolean;
|
||||
withCheckbox?: boolean;
|
||||
rowOptions?: number[];
|
||||
/**
|
||||
* Custom row renderer. Should return a complete <tr> element or null.
|
||||
* This gives full control over the row structure including colspan.
|
||||
* Return null to render the default row.
|
||||
*/
|
||||
renderCustomRow?: (row: Row<TData>) => ReactNode | null;
|
||||
}
|
||||
|
||||
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
|
||||
@@ -112,6 +118,7 @@ const Table = <TData extends object>({
|
||||
renderFooter = false,
|
||||
withCheckbox = false,
|
||||
rowOptions = [10, 20, 50, 100],
|
||||
renderCustomRow,
|
||||
}: TableProps<TData>) => {
|
||||
const isServerSideTable =
|
||||
totalItems !== undefined &&
|
||||
@@ -305,24 +312,35 @@ const Table = <TData extends object>({
|
||||
</thead>
|
||||
|
||||
<tbody className={tableClassNames.tableBodyClassName}>
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<tr key={row.id} className={tableClassNames.bodyRowClassName}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<td
|
||||
key={cell.id}
|
||||
className={cn(
|
||||
{ 'first:w-9 first:pr-0': withCheckbox },
|
||||
tableClassNames.bodyColumnClassName
|
||||
)}
|
||||
>
|
||||
{!isLoading &&
|
||||
flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
{table.getRowModel().rows.map((row) => {
|
||||
const customRowContent = renderCustomRow?.(row);
|
||||
|
||||
{isLoading && <div className='skeleton w-full h-4' />}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
if (customRowContent) {
|
||||
return renderCustomRow?.(row);
|
||||
}
|
||||
|
||||
return (
|
||||
<tr key={row.id} className={tableClassNames.bodyRowClassName}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<td
|
||||
key={cell.id}
|
||||
className={cn(
|
||||
{ 'first:w-9 first:pr-0': withCheckbox },
|
||||
tableClassNames.bodyColumnClassName
|
||||
)}
|
||||
>
|
||||
{!isLoading &&
|
||||
flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext()
|
||||
)}
|
||||
|
||||
{isLoading && <div className='skeleton w-full h-4' />}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
<tfoot className={cn(tableClassNames.tableFooterClassName)}>
|
||||
{renderFooter && (
|
||||
|
||||
@@ -1,87 +1,197 @@
|
||||
'use client';
|
||||
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import useSWRImmutable from 'swr/immutable';
|
||||
|
||||
import { useAuth } from '@/services/hooks/useAuth';
|
||||
import { httpClientFetcher, SWRHttpKey } from '@/services/http/client';
|
||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
import { BaseApiResponse, GetMeResponse } from '@/types/api/api-general';
|
||||
import { AxiosError } from 'axios';
|
||||
import { redirectToSSO } from '@/lib/auth-helper';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { GetMeResponse } from '@/types/api/api-general';
|
||||
|
||||
// TODO: delete this later, DONT HARDCODE USER DATA
|
||||
const DUMMY_USER = {
|
||||
id: 1,
|
||||
email: 'admin@mbugroup.id',
|
||||
npk: '0001',
|
||||
name: 'Super Admin',
|
||||
image: null,
|
||||
created_at: '2025-09-30T03:24:20.899229Z',
|
||||
updated_at: '2025-09-30T03:24:20.899229Z',
|
||||
roles: [
|
||||
{
|
||||
id: 1,
|
||||
key: 'mbu.super_admin',
|
||||
name: 'MBU Administrator',
|
||||
client: {
|
||||
id: 1,
|
||||
name: 'PT Mitra Berlian Unggas',
|
||||
alias: 'MBU',
|
||||
},
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'mbu:purchase:read',
|
||||
action: 'read',
|
||||
client: {
|
||||
id: 1,
|
||||
name: 'PT Mitra Berlian Unggas',
|
||||
alias: 'MBU',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'mbu:purchase:create',
|
||||
action: 'create',
|
||||
client: {
|
||||
id: 1,
|
||||
name: 'PT Mitra Berlian Unggas',
|
||||
alias: 'MBU',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'mbu:purchase:approve',
|
||||
action: 'approve',
|
||||
client: {
|
||||
id: 1,
|
||||
name: 'PT Mitra Berlian Unggas',
|
||||
alias: 'MBU',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
key: 'lti.super_admin',
|
||||
name: 'LTI Administrator',
|
||||
client: {
|
||||
id: 2,
|
||||
name: 'PT Lumbung Telur Indonesia',
|
||||
alias: 'LTI',
|
||||
},
|
||||
permissions: [
|
||||
{
|
||||
id: 4,
|
||||
name: 'lti:purchase:read',
|
||||
action: 'read',
|
||||
client: {
|
||||
id: 2,
|
||||
name: 'PT Lumbung Telur Indonesia',
|
||||
alias: 'LTI',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'lti:purchase:create',
|
||||
action: 'create',
|
||||
client: {
|
||||
id: 2,
|
||||
name: 'PT Lumbung Telur Indonesia',
|
||||
alias: 'LTI',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'lti:purchase:approve',
|
||||
action: 'approve',
|
||||
client: {
|
||||
id: 2,
|
||||
name: 'PT Lumbung Telur Indonesia',
|
||||
alias: 'LTI',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
key: 'manbu.super_admin',
|
||||
name: 'MANBU Administrator',
|
||||
client: {
|
||||
id: 3,
|
||||
name: 'PT Mandiri Berlian Unggas',
|
||||
alias: 'MANBU',
|
||||
},
|
||||
permissions: [
|
||||
{
|
||||
id: 7,
|
||||
name: 'manbu:purchase:read',
|
||||
action: 'read',
|
||||
client: {
|
||||
id: 3,
|
||||
name: 'PT Mandiri Berlian Unggas',
|
||||
alias: 'MANBU',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'manbu:purchase:create',
|
||||
action: 'create',
|
||||
client: {
|
||||
id: 3,
|
||||
name: 'PT Mandiri Berlian Unggas',
|
||||
alias: 'MANBU',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: 'manbu:purchase:approve',
|
||||
action: 'approve',
|
||||
client: {
|
||||
id: 3,
|
||||
name: 'PT Mandiri Berlian Unggas',
|
||||
alias: 'MANBU',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
interface RequireAuthProps {
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
const RequireAuth = ({ children }: RequireAuthProps) => {
|
||||
const { user, setUser, setIsLoadingUser } = useAuth();
|
||||
const router = useRouter();
|
||||
const { setUser, setIsLoadingUser } = useAuth();
|
||||
|
||||
const {
|
||||
data: userResponse,
|
||||
isLoading: isLoadingUserResponse,
|
||||
error: userErrorResponse,
|
||||
} = useSWR<
|
||||
GetMeResponse & { ok?: boolean },
|
||||
AxiosError<BaseApiResponse>,
|
||||
SWRHttpKey
|
||||
>('/sso/userinfo', httpClientFetcher, {
|
||||
shouldRetryOnError: false,
|
||||
});
|
||||
const { data: userResponse, isLoading: isLoadingUserResponse } =
|
||||
useSWRImmutable<GetMeResponse & { ok?: boolean }, unknown, SWRHttpKey>(
|
||||
'/auth/sso/userinfo',
|
||||
httpClientFetcher,
|
||||
{
|
||||
shouldRetryOnError: false,
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
refreshInterval: 0,
|
||||
}
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoadingUser(isLoadingUserResponse);
|
||||
}, [isLoadingUserResponse, setIsLoadingUser]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isResponseSuccess(userResponse)) {
|
||||
setUser(userResponse.data);
|
||||
} else {
|
||||
// router.replace(process.env.NEXT_PUBLIC_SSO_LOGIN_URL as string);
|
||||
// TODO: remove this later, DONT HARDCODE USER DATA
|
||||
setUser(DUMMY_USER);
|
||||
}
|
||||
}, [userResponse, setUser]);
|
||||
}, [userResponse, setIsLoadingUser, setUser]);
|
||||
|
||||
// Explicitly handle 401 redirect from the component level
|
||||
useEffect(() => {
|
||||
if (
|
||||
isResponseError(userResponse) &&
|
||||
userErrorResponse?.response?.status === 401
|
||||
) {
|
||||
// Clear cache to prevent stale data from rendering children
|
||||
// mutate('/sso/userinfo', undefined, { revalidate: false }); // Optional: if using global mutate
|
||||
setUser(undefined);
|
||||
redirectToSSO();
|
||||
}
|
||||
}, [userErrorResponse, setUser, userResponse]);
|
||||
// TODO: uncomment this later
|
||||
// if (isLoadingUserResponse && !userResponse) {
|
||||
// return (
|
||||
// <div className='w-full flex flex-row justify-center items-center p-4'>
|
||||
// <span className='loading loading-spinner loading-xl' />
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoadingUser(isLoadingUserResponse);
|
||||
}, [isLoadingUserResponse]);
|
||||
|
||||
if (
|
||||
(isLoadingUserResponse && !userResponse && !userErrorResponse) ||
|
||||
(!userResponse && !userErrorResponse)
|
||||
) {
|
||||
return (
|
||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||
<span className='loading loading-spinner loading-xl' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (userErrorResponse) {
|
||||
return (
|
||||
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
||||
<h2 className='text-2xl font-bold text-error'>Authentication Failed</h2>
|
||||
<p className='text-gray-600'>
|
||||
Please try refreshing the page or contact support if the problem
|
||||
persists.
|
||||
</p>
|
||||
<button
|
||||
className='btn btn-primary'
|
||||
onClick={() => window.location.reload()}
|
||||
>
|
||||
Retry
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <>{isResponseSuccess(userResponse) && user && children}</>;
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default RequireAuth;
|
||||
|
||||
@@ -15,6 +15,7 @@ import ClosingSapronakTabContent from './ClosingSapronakTabContent';
|
||||
import ClosingSapronakCalculationTabContent from '@/components/pages/closing/ClosingSapronakCalculationTabContent';
|
||||
import ClosingOverheadTabContent from '@/components/pages/closing/ClosingOverheadTabContent';
|
||||
import SalesReportTable from './sale/SalesReportTable';
|
||||
import ClosingFinanceTabContent from '@/components/pages/closing/ClosingFinanceTabContent';
|
||||
|
||||
interface ClosingDetailProps {
|
||||
id: number;
|
||||
@@ -64,7 +65,7 @@ const ClosingDetail: React.FC<ClosingDetailProps> = ({
|
||||
{
|
||||
id: 'keuangan',
|
||||
label: 'Keuangan',
|
||||
content: 'Keuangan',
|
||||
content: <ClosingFinanceTabContent projectFlockId={id} />,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import ClosingFinanceTable from '@/components/pages/closing/ClosingFinanceTable';
|
||||
|
||||
const ClosingFinanceTabContent = ({
|
||||
projectFlockId,
|
||||
}: {
|
||||
projectFlockId: number;
|
||||
}) => {
|
||||
return (
|
||||
<div className='flex flex-col gap-4'>
|
||||
{projectFlockId && (
|
||||
<ClosingFinanceTable projectFlockId={projectFlockId} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ClosingFinanceTabContent;
|
||||
@@ -0,0 +1,518 @@
|
||||
import Card from '@/components/Card';
|
||||
import Table, { TABLE_DEFAULT_STYLING } from '@/components/Table';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { formatCurrency, formatTitleCase } from '@/lib/helper';
|
||||
import { ClosingApi } from '@/services/api/closing';
|
||||
import {
|
||||
DataSummarySubTotal,
|
||||
HppPurchaseData,
|
||||
ProfitLossDataAmount,
|
||||
} from '@/types/api/closing';
|
||||
import useSWR from 'swr';
|
||||
|
||||
type HppTableRow =
|
||||
| (HppPurchaseData & {
|
||||
group_name: string;
|
||||
group_index: number;
|
||||
isGroupHeader?: boolean;
|
||||
})
|
||||
| {
|
||||
group_name: string;
|
||||
group_index: number;
|
||||
isGroupHeader: true;
|
||||
type?: never;
|
||||
budgeting?: never;
|
||||
realization?: never;
|
||||
};
|
||||
|
||||
type ProfitLossTableRow =
|
||||
| (DataSummarySubTotal & {
|
||||
type: string;
|
||||
group_name: string;
|
||||
group_index: number;
|
||||
isGroupHeader?: boolean;
|
||||
})
|
||||
| {
|
||||
group_name: string;
|
||||
group_index: number;
|
||||
isGroupHeader: true;
|
||||
type?: never;
|
||||
rp_per_bird?: never;
|
||||
rp_per_kg?: never;
|
||||
amount?: never;
|
||||
};
|
||||
|
||||
const ClosingFinanceTable = ({
|
||||
projectFlockId,
|
||||
}: {
|
||||
projectFlockId: number;
|
||||
}) => {
|
||||
const { data: finance, isLoading } = useSWR(
|
||||
`/closing/finance/${projectFlockId}`,
|
||||
() => ClosingApi.getFinance(projectFlockId)
|
||||
);
|
||||
|
||||
const hppTableData: HppTableRow[] = isResponseSuccess(finance)
|
||||
? finance.data.hpp_purchases.hpp.flatMap((hpp, groupIndex) => [
|
||||
// Group header row
|
||||
{
|
||||
group_name: hpp.group_name,
|
||||
group_index: groupIndex,
|
||||
isGroupHeader: true as const,
|
||||
},
|
||||
// Data rows
|
||||
...hpp.data.map((item) => ({
|
||||
group_name: hpp.group_name,
|
||||
group_index: groupIndex,
|
||||
type: item.type,
|
||||
budgeting: item.budgeting,
|
||||
realization: item.realization,
|
||||
isGroupHeader: false as const,
|
||||
})),
|
||||
])
|
||||
: [];
|
||||
|
||||
const profitLossTableData: ProfitLossTableRow[] = isResponseSuccess(finance)
|
||||
? [
|
||||
// Penjualan group
|
||||
{
|
||||
label: 'Penjualan',
|
||||
group_name: 'Penjualan',
|
||||
group_index: 0,
|
||||
isGroupHeader: true as const,
|
||||
},
|
||||
...finance.data.profit_loss.data.penjualan.map((item) => ({
|
||||
label: 'Penjualan',
|
||||
group_name: 'Penjualan',
|
||||
group_index: 0,
|
||||
type: item.type,
|
||||
rp_per_bird: item.rp_per_bird,
|
||||
rp_per_kg: item.rp_per_kg,
|
||||
amount: item.amount,
|
||||
isGroupHeader: false as const,
|
||||
})),
|
||||
{
|
||||
label: finance.data.profit_loss.data.summary.gross_profit.label,
|
||||
group_name: 'Penjualan',
|
||||
group_index: 0,
|
||||
isGroupHeader: true as const,
|
||||
type: finance.data.profit_loss.data.summary.gross_profit.label,
|
||||
rp_per_bird:
|
||||
finance.data.profit_loss.data.summary.gross_profit.rp_per_bird,
|
||||
rp_per_kg:
|
||||
finance.data.profit_loss.data.summary.gross_profit.rp_per_kg,
|
||||
amount: finance.data.profit_loss.data.summary.gross_profit.amount,
|
||||
},
|
||||
// Pembelian group
|
||||
{
|
||||
label: 'Pembelian',
|
||||
group_name: 'Pembelian',
|
||||
group_index: 1,
|
||||
isGroupHeader: true as const,
|
||||
},
|
||||
...finance.data.profit_loss.data.pembelian.map((item) => ({
|
||||
label: 'Pembelian',
|
||||
group_name: 'Pembelian',
|
||||
group_index: 1,
|
||||
type: item.type,
|
||||
rp_per_bird: item.rp_per_bird,
|
||||
rp_per_kg: item.rp_per_kg,
|
||||
amount: item.amount,
|
||||
isGroupHeader: false as const,
|
||||
})),
|
||||
{
|
||||
label: finance.data.profit_loss.data.summary.sub_total.label,
|
||||
group_name: 'Pembelian',
|
||||
group_index: 1,
|
||||
isGroupHeader: true as const,
|
||||
type: finance.data.profit_loss.data.summary.sub_total.label,
|
||||
rp_per_bird:
|
||||
finance.data.profit_loss.data.summary.sub_total.rp_per_bird,
|
||||
rp_per_kg: finance.data.profit_loss.data.summary.sub_total.rp_per_kg,
|
||||
amount: finance.data.profit_loss.data.summary.sub_total.amount,
|
||||
},
|
||||
]
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-4'>
|
||||
{isResponseSuccess(finance) && (
|
||||
<>
|
||||
<Card
|
||||
variant='bordered'
|
||||
className={{
|
||||
wrapper: 'w-full',
|
||||
}}
|
||||
>
|
||||
<div className='grid grid-cols-2 gap-6'>
|
||||
<div className='flex flex-col gap-1'>
|
||||
<div>
|
||||
{formatTitleCase(
|
||||
finance.data.profit_loss.data.summary.gross_profit.label ||
|
||||
'-'
|
||||
)}
|
||||
</div>
|
||||
<div className='text-lg font-bold'>
|
||||
{formatCurrency(
|
||||
finance.data.profit_loss.data.summary.gross_profit.amount
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex flex-col gap-1'>
|
||||
<div>
|
||||
{formatTitleCase(
|
||||
finance.data.profit_loss.data.summary.net_profit.label ||
|
||||
'-'
|
||||
)}
|
||||
</div>
|
||||
<div className='text-lg font-bold'>
|
||||
{formatCurrency(
|
||||
finance.data.profit_loss.data.summary.net_profit.amount
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
<Card
|
||||
title={finance.data.hpp_purchases.title}
|
||||
variant='bordered'
|
||||
collapsible
|
||||
className={{
|
||||
wrapper: 'w-full',
|
||||
}}
|
||||
>
|
||||
<div className='mt-6 p-0 mb-0'>
|
||||
<Table<HppTableRow>
|
||||
data={hppTableData}
|
||||
columns={[
|
||||
{
|
||||
header: 'No.',
|
||||
enableSorting: false,
|
||||
accessorFn: (item, index) => {
|
||||
if (item.isGroupHeader) return '-';
|
||||
// Calculate row number excluding group headers
|
||||
const dataRowsBefore = hppTableData
|
||||
.slice(0, index)
|
||||
.filter((row) => !row.isGroupHeader).length;
|
||||
return dataRowsBefore + 1;
|
||||
},
|
||||
footer: (props) => {
|
||||
return 'HPP';
|
||||
},
|
||||
},
|
||||
{
|
||||
header: 'Type',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) => formatTitleCase(item.type || '-'),
|
||||
},
|
||||
{
|
||||
header: 'Budgeting',
|
||||
enableSorting: false,
|
||||
columns: [
|
||||
{
|
||||
header: 'Rp/Ekor',
|
||||
id: 'budgeting_rp_per_bird',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) =>
|
||||
formatCurrency(item.budgeting?.rp_per_bird || 0),
|
||||
footer: (props) => {
|
||||
return props.column.id === 'budgeting_rp_per_bird'
|
||||
? formatCurrency(
|
||||
finance.data.hpp_purchases.hpp.reduce(
|
||||
(total, hpp) =>
|
||||
total +
|
||||
(finance.data.hpp_purchases.summary_hpp
|
||||
.budgeting.rp_per_bird || 0),
|
||||
0
|
||||
)
|
||||
)
|
||||
: '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
header: 'Rp/Kg',
|
||||
id: 'budgeting_rp_per_kg',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) =>
|
||||
formatCurrency(item.budgeting?.rp_per_kg || 0),
|
||||
footer: (props) => {
|
||||
return props.column.id === 'budgeting_rp_per_kg'
|
||||
? formatCurrency(
|
||||
finance.data.hpp_purchases.hpp.reduce(
|
||||
(total, hpp) =>
|
||||
total +
|
||||
(finance.data.hpp_purchases.summary_hpp
|
||||
.budgeting.rp_per_kg || 0),
|
||||
0
|
||||
)
|
||||
)
|
||||
: '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
header: 'Jumlah (Rp)',
|
||||
id: 'budgeting_amount',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) =>
|
||||
formatCurrency(item.budgeting?.amount || 0),
|
||||
footer: (props) => {
|
||||
return props.column.id === 'budgeting_amount'
|
||||
? formatCurrency(
|
||||
finance.data.hpp_purchases.hpp.reduce(
|
||||
(total, hpp) =>
|
||||
total +
|
||||
(finance.data.hpp_purchases.summary_hpp
|
||||
.budgeting.amount || 0),
|
||||
0
|
||||
)
|
||||
)
|
||||
: '-';
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
header: 'Realization',
|
||||
enableSorting: false,
|
||||
columns: [
|
||||
{
|
||||
header: 'Rp/Ekor',
|
||||
id: 'realization_rp_per_bird',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) =>
|
||||
formatCurrency(item.realization?.rp_per_bird || 0),
|
||||
footer: (props) => {
|
||||
return props.column.id === 'realization_rp_per_bird'
|
||||
? formatCurrency(
|
||||
finance.data.hpp_purchases.hpp.reduce(
|
||||
(total, hpp) =>
|
||||
total +
|
||||
(finance.data.hpp_purchases.summary_hpp
|
||||
.realization.rp_per_bird || 0),
|
||||
0
|
||||
)
|
||||
)
|
||||
: '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
header: 'Rp/Kg',
|
||||
id: 'realization_rp_per_kg',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) =>
|
||||
formatCurrency(item.realization?.rp_per_kg || 0),
|
||||
footer: (props) => {
|
||||
return props.column.id === 'realization_rp_per_kg'
|
||||
? formatCurrency(
|
||||
finance.data.hpp_purchases.hpp.reduce(
|
||||
(total, hpp) =>
|
||||
total +
|
||||
(finance.data.hpp_purchases.summary_hpp
|
||||
.realization.rp_per_kg || 0),
|
||||
0
|
||||
)
|
||||
)
|
||||
: '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
header: 'Jumlah (Rp)',
|
||||
id: 'realization_amount',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) =>
|
||||
formatCurrency(item.realization?.amount || 0),
|
||||
footer: (props) => {
|
||||
return props.column.id === 'realization_amount'
|
||||
? formatCurrency(
|
||||
finance.data.hpp_purchases.hpp.reduce(
|
||||
(total, hpp) =>
|
||||
total +
|
||||
(finance.data.hpp_purchases.summary_hpp
|
||||
.realization.amount || 0),
|
||||
0
|
||||
)
|
||||
)
|
||||
: '-';
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
renderCustomRow={(row) => {
|
||||
const rowData = row.original;
|
||||
if (rowData.isGroupHeader) {
|
||||
return (
|
||||
<tr
|
||||
key={row.id}
|
||||
className={TABLE_DEFAULT_STYLING.bodyRowClassName}
|
||||
>
|
||||
<td
|
||||
className={TABLE_DEFAULT_STYLING.bodyColumnClassName}
|
||||
></td>
|
||||
<td
|
||||
colSpan={7}
|
||||
className={TABLE_DEFAULT_STYLING.bodyColumnClassName}
|
||||
>
|
||||
<div className='font-bold'>
|
||||
{formatTitleCase(rowData.group_name ?? '-')}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}}
|
||||
renderFooter
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
<Card
|
||||
title={finance.data.profit_loss.title}
|
||||
variant='bordered'
|
||||
collapsible
|
||||
className={{
|
||||
wrapper: 'w-full',
|
||||
}}
|
||||
>
|
||||
<div className='mt-6 p-0 mb-0'>
|
||||
<Table<ProfitLossTableRow>
|
||||
data={profitLossTableData}
|
||||
columns={[
|
||||
{
|
||||
header: 'Type',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) => item.type,
|
||||
cell: (item) => (
|
||||
<div className='ps-6'>
|
||||
{formatTitleCase(item.row.original.type || '-')}
|
||||
</div>
|
||||
),
|
||||
footer: (item) => (
|
||||
<div className='font-bold'>
|
||||
{formatTitleCase(
|
||||
finance.data.profit_loss.data.summary.net_profit
|
||||
.label || '-'
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
header: 'Rp/Ekor',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) => formatCurrency(item.rp_per_bird || 0),
|
||||
footer: (item) => (
|
||||
<div className='font-bold'>
|
||||
{formatCurrency(
|
||||
finance.data.profit_loss.data.summary.net_profit
|
||||
.rp_per_bird || 0
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
header: 'Rp/Kg',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) => formatCurrency(item.rp_per_kg || 0),
|
||||
footer: (item) => (
|
||||
<div className='font-bold'>
|
||||
{formatCurrency(
|
||||
finance.data.profit_loss.data.summary.net_profit
|
||||
.rp_per_kg || 0
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
header: 'Jumlah (Rp)',
|
||||
enableSorting: false,
|
||||
accessorFn: (item) => formatCurrency(item.amount || 0),
|
||||
footer: (item) => (
|
||||
<div className='font-bold'>
|
||||
{formatCurrency(
|
||||
finance.data.profit_loss.data.summary.net_profit
|
||||
.amount || 0
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
renderCustomRow={(row) => {
|
||||
const rowData = row.original;
|
||||
if (rowData.isGroupHeader) {
|
||||
if (rowData.amount) {
|
||||
return (
|
||||
<tr
|
||||
key={row.id}
|
||||
className={TABLE_DEFAULT_STYLING.footerRowClassName}
|
||||
>
|
||||
<td
|
||||
className={
|
||||
TABLE_DEFAULT_STYLING.bodyColumnClassName
|
||||
}
|
||||
>
|
||||
<div className='font-bold'>
|
||||
{formatTitleCase(rowData.label ?? '-')}
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className={
|
||||
TABLE_DEFAULT_STYLING.bodyColumnClassName
|
||||
}
|
||||
>
|
||||
<div className='font-bold'>
|
||||
{formatCurrency(rowData.rp_per_bird ?? 0)}
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className={
|
||||
TABLE_DEFAULT_STYLING.bodyColumnClassName
|
||||
}
|
||||
>
|
||||
<div className='font-bold'>
|
||||
{formatCurrency(rowData.rp_per_kg ?? 0)}
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
className={
|
||||
TABLE_DEFAULT_STYLING.bodyColumnClassName
|
||||
}
|
||||
>
|
||||
<div className='font-bold'>
|
||||
{formatCurrency(rowData.amount ?? 0)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<tr
|
||||
key={row.id}
|
||||
className={TABLE_DEFAULT_STYLING.bodyRowClassName}
|
||||
>
|
||||
<td
|
||||
colSpan={4}
|
||||
className={TABLE_DEFAULT_STYLING.bodyColumnClassName}
|
||||
>
|
||||
<div className='font-bold'>
|
||||
{formatTitleCase(rowData.group_name ?? '-')}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}}
|
||||
className={{
|
||||
paginationClassName: 'hidden',
|
||||
}}
|
||||
renderFooter
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ClosingFinanceTable;
|
||||
@@ -12,7 +12,10 @@ import ExpenseStatusBadge from '@/components/pages/expense/ExpenseStatusBadge';
|
||||
import RealizationStatusBadge from '@/components/pages/expense/RealizationStatusBadge';
|
||||
import Table, { TABLE_DEFAULT_STYLING } from '@/components/Table';
|
||||
import { cn, formatCurrency, formatDate } from '@/lib/helper';
|
||||
import { ReportExpense } from '@/types/api/report/report-expense';
|
||||
import {
|
||||
ReportExpense,
|
||||
ReportExpenseSearchParams,
|
||||
} from '@/types/api/report/report-expense';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { useMemo, useState } from 'react';
|
||||
@@ -23,16 +26,7 @@ const ReportExpenseTable = ({
|
||||
onSearch,
|
||||
}: {
|
||||
reportExpenses: ReportExpense[];
|
||||
onSearch: (params: {
|
||||
locationId: string | null;
|
||||
supplierId: string | null;
|
||||
kandangId: string | null;
|
||||
startDate: string | null;
|
||||
endDate: string | null;
|
||||
category: string | null;
|
||||
period: string | number;
|
||||
search: string;
|
||||
}) => void;
|
||||
onSearch: (params: ReportExpenseSearchParams) => void;
|
||||
}) => {
|
||||
const [selectedLocation, setSelectedLocation] = useState<OptionType | null>(
|
||||
null
|
||||
@@ -46,10 +40,11 @@ const ReportExpenseTable = ({
|
||||
const [selectedKandang, setSelectedKandang] = useState<OptionType | null>(
|
||||
null
|
||||
);
|
||||
const [selectedNonstock, setSelectedNonstock] = useState<OptionType | null>(
|
||||
null
|
||||
);
|
||||
const [search, setSearch] = useState('');
|
||||
const [startDate, setStartDate] = useState<string | null>(null);
|
||||
const [endDate, setEndDate] = useState<string | null>(null);
|
||||
const [period, setPeriod] = useState<number | string>('');
|
||||
const [realizationDate, setRealizationDate] = useState<string | null>(null);
|
||||
|
||||
const { options: optionsLocation, isLoadingOptions: isLoadingLocation } =
|
||||
useSelect(`/master-data/locations`, 'id', 'name');
|
||||
@@ -59,6 +54,8 @@ const ReportExpenseTable = ({
|
||||
useSelect(`/master-data/kandangs`, 'id', 'name', '', {
|
||||
location_id: selectedLocation?.value.toString() || '',
|
||||
});
|
||||
const { options: optionsNonstock, isLoadingOptions: isLoadingNonstock } =
|
||||
useSelect(`/master-data/nonstocks`, 'id', 'name');
|
||||
|
||||
const columns = useMemo((): ColumnDef<ReportExpense>[] => {
|
||||
return [
|
||||
@@ -92,13 +89,17 @@ const ReportExpenseTable = ({
|
||||
header: 'Kategori',
|
||||
accessorKey: 'category',
|
||||
},
|
||||
{
|
||||
header: 'Produk',
|
||||
accessorFn: (row) => row.pengajuan.nonstock.name,
|
||||
},
|
||||
{
|
||||
header: 'Supplier',
|
||||
accessorFn: (row) => row.supplier.name,
|
||||
},
|
||||
{
|
||||
header: 'Lokasi',
|
||||
accessorFn: (row) => row.location.name,
|
||||
accessorFn: (row) => row.kandang.location.name,
|
||||
},
|
||||
{
|
||||
header: 'Kandang',
|
||||
@@ -181,44 +182,31 @@ const ReportExpenseTable = ({
|
||||
const handleSearch = () => {
|
||||
onSearch({
|
||||
search,
|
||||
period,
|
||||
startDate,
|
||||
endDate,
|
||||
realizationDate,
|
||||
locationId: selectedLocation?.value.toString() ?? '',
|
||||
kandangId: selectedKandang?.value.toString() ?? '',
|
||||
nonstockId: selectedNonstock?.value.toString() ?? '',
|
||||
supplierId: selectedSupplier?.value.toString() ?? '',
|
||||
category: selectedCategory?.value.toString() ?? '',
|
||||
});
|
||||
};
|
||||
const handleSearchInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setSearch(e.target.value);
|
||||
onSearch({
|
||||
search: e.target.value,
|
||||
period,
|
||||
startDate,
|
||||
endDate,
|
||||
locationId: selectedLocation?.value.toString() ?? '',
|
||||
kandangId: selectedKandang?.value.toString() ?? '',
|
||||
supplierId: selectedSupplier?.value.toString() ?? '',
|
||||
category: selectedCategory?.value.toString() ?? '',
|
||||
});
|
||||
};
|
||||
const handleReset = () => {
|
||||
setSearch('');
|
||||
setPeriod('');
|
||||
setStartDate('');
|
||||
setEndDate('');
|
||||
setRealizationDate('');
|
||||
setSelectedLocation(null);
|
||||
setSelectedKandang(null);
|
||||
setSelectedNonstock(null);
|
||||
setSelectedSupplier(null);
|
||||
setSelectedCategory(null);
|
||||
onSearch({
|
||||
search: '',
|
||||
period: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
realizationDate: '',
|
||||
locationId: '',
|
||||
kandangId: '',
|
||||
nonstockId: '',
|
||||
supplierId: '',
|
||||
category: '',
|
||||
});
|
||||
@@ -283,6 +271,15 @@ const ReportExpenseTable = ({
|
||||
value={selectedSupplier}
|
||||
onChange={(option) => setSelectedSupplier(option as OptionType)}
|
||||
/>
|
||||
<SelectInput
|
||||
isClearable
|
||||
label='Produk'
|
||||
options={optionsNonstock}
|
||||
isLoading={isLoadingNonstock}
|
||||
placeholder='Produk'
|
||||
value={selectedNonstock}
|
||||
onChange={(option) => setSelectedNonstock(option as OptionType)}
|
||||
/>
|
||||
<SelectInput
|
||||
isClearable
|
||||
label='Kategori'
|
||||
@@ -292,7 +289,7 @@ const ReportExpenseTable = ({
|
||||
label: 'BOP',
|
||||
},
|
||||
{
|
||||
value: 'NON BOP',
|
||||
value: 'NON-BOP',
|
||||
label: 'Non BOP',
|
||||
},
|
||||
]}
|
||||
@@ -300,26 +297,12 @@ const ReportExpenseTable = ({
|
||||
value={selectedCategory}
|
||||
onChange={(option) => setSelectedCategory(option as OptionType)}
|
||||
/>
|
||||
<NumberInput
|
||||
label='Periode'
|
||||
value={period}
|
||||
onChange={(e) => setPeriod(e.target.value)}
|
||||
name='periode'
|
||||
placeholder='Periode'
|
||||
/>
|
||||
<DateInput
|
||||
label='Tanggal Mulai'
|
||||
value={startDate as string}
|
||||
onChange={(e) => setStartDate(e.target.value)}
|
||||
name='start_date'
|
||||
placeholder='Tanggal Mulai'
|
||||
/>
|
||||
<DateInput
|
||||
label='Tanggal Selesai'
|
||||
value={endDate as string}
|
||||
onChange={(e) => setEndDate(e.target.value)}
|
||||
name='end_date'
|
||||
placeholder='Tanggal Selesai'
|
||||
label='Tanggal Realisasi'
|
||||
value={realizationDate as string}
|
||||
onChange={(e) => setRealizationDate(e.target.value)}
|
||||
name='realization_date'
|
||||
placeholder='Tanggal Realisasi'
|
||||
/>
|
||||
<DebouncedTextInput
|
||||
label='Cari'
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useMemo, useState } from 'react';
|
||||
import { formatCurrency, formatDate } from '@/lib/helper';
|
||||
import pdfStyles from '@/components/pages/report/expense/pdf/styles/ReportExpenseStyles';
|
||||
import toast from 'react-hot-toast';
|
||||
import ExpenseStatusBadge from '@/components/pages/expense/ExpenseStatusBadge';
|
||||
|
||||
interface ReportExpenseExportProps {
|
||||
data: ReportExpense[];
|
||||
@@ -134,58 +135,208 @@ const PDFDocument = ({ data }: { data: ReportExpense[] }) => {
|
||||
|
||||
{/* Table */}
|
||||
<View style={pdfStyles.table}>
|
||||
{/* Table Header */}
|
||||
{/* Header Row 1: Group Headers */}
|
||||
<View style={[pdfStyles.tableRow, pdfStyles.tableHeader]}>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellNarrowHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>No</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellWrapHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>No. PO</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellWrapHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>No. Referensi</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Tgl Realisasi</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Tgl Transaksi</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellXSmallHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Kategori</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Produk</Text>
|
||||
</View>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellSmallHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Lokasi</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellSmallHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Kandang</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Qty Pengajuan</Text>
|
||||
|
||||
{/* Pengajuan Group - spans 3 columns: XSmall + Medium + Medium */}
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellXSmallHeader,
|
||||
{ borderBottomWidth: 0, borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Harga Pengajuan</Text>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{
|
||||
borderBottomWidth: 0,
|
||||
borderRightWidth: 0,
|
||||
textAlign: 'center',
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Text>Pengajuan</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Total Pengajuan</Text>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Qty Realisasi</Text>
|
||||
|
||||
{/* Realisasi Group - spans 3 columns: XSmall + Medium + Medium */}
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellXSmallHeader,
|
||||
{ borderBottomWidth: 0, borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Harga Realisasi</Text>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{
|
||||
borderBottomWidth: 0,
|
||||
borderRightWidth: 0,
|
||||
textAlign: 'center',
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Text>Realisasi</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Total Realisasi</Text>
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text>Status Pencairan</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeaderLast}>
|
||||
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellMediumHeader,
|
||||
{ borderBottomWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text>Status BOP</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Header Row 2: Sub Headers */}
|
||||
<View style={[pdfStyles.tableRow, pdfStyles.tableHeader]}>
|
||||
<View style={pdfStyles.tableCellNarrowHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellWrapHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellWrapHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellXSmallHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellSmallHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellSmallHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
|
||||
{/* Pengajuan sub-headers */}
|
||||
<View style={pdfStyles.tableCellXSmallHeader}>
|
||||
<Text>Qty</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text>Harga</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text>Total</Text>
|
||||
</View>
|
||||
|
||||
{/* Realisasi sub-headers */}
|
||||
<View style={pdfStyles.tableCellXSmallHeader}>
|
||||
<Text>Qty</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text>Harga</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text>Total</Text>
|
||||
</View>
|
||||
|
||||
<View style={pdfStyles.tableCellMediumHeader}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Table Body */}
|
||||
{items.map((item, index) => {
|
||||
const pengajuanTotal =
|
||||
@@ -195,74 +346,60 @@ const PDFDocument = ({ data }: { data: ReportExpense[] }) => {
|
||||
|
||||
return (
|
||||
<View key={index} style={pdfStyles.tableRow}>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<View style={pdfStyles.tableCellNarrow}>
|
||||
<Text>{index + 1}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<View style={pdfStyles.tableCellWrap}>
|
||||
<Text>{item.po_number}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<View style={pdfStyles.tableCellWrap}>
|
||||
<Text>{item.reference_number}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<View style={pdfStyles.tableCellMedium}>
|
||||
<Text>
|
||||
{formatDate(item.realization_date, 'DD MMM YY')}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<View style={pdfStyles.tableCellMedium}>
|
||||
<Text>
|
||||
{formatDate(item.transaction_date, 'DD MMM YY')}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<Text>{item.category}</Text>
|
||||
<View style={pdfStyles.tableCellXSmall}>
|
||||
<Text>{item.category.split('-').join(' ')}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<Text>{item.location.name}</Text>
|
||||
<Text>{item.pengajuan.nonstock.name}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<View style={pdfStyles.tableCellSmall}>
|
||||
<Text>{item.kandang.location.name}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellSmall}>
|
||||
<Text>{item.kandang.name}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightXSmall}>
|
||||
<Text>
|
||||
{item.pengajuan.qty.toLocaleString('id-ID')}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text>{formatCurrency(item.pengajuan.price)}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text>{formatCurrency(pengajuanTotal)}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightXSmall}>
|
||||
<Text>
|
||||
{item.realisasi.qty.toLocaleString('id-ID')}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text>{formatCurrency(item.realisasi.price)}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text>{formatCurrency(realisasiTotal)}</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCell}>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 7,
|
||||
backgroundColor:
|
||||
item.latest_approval.step_number === 3
|
||||
? '#dcfce7'
|
||||
: '#fef3c7',
|
||||
padding: 2,
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
{item.latest_approval.step_number === 3
|
||||
? 'Lunas'
|
||||
: 'Belum Lunas'}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellLast}>
|
||||
<View style={pdfStyles.tableCellMedium}>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 7,
|
||||
@@ -276,7 +413,7 @@ const PDFDocument = ({ data }: { data: ReportExpense[] }) => {
|
||||
borderRadius: 2,
|
||||
}}
|
||||
>
|
||||
{item.latest_approval.action}
|
||||
{item.latest_approval.step_name}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
@@ -285,78 +422,112 @@ const PDFDocument = ({ data }: { data: ReportExpense[] }) => {
|
||||
|
||||
{/* Supplier Subtotal Row */}
|
||||
<View style={pdfStyles.grandTotalRow}>
|
||||
{/* Empty cells for columns before subtotal */}
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellNarrow,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[pdfStyles.tableCellWrap, { borderRightWidth: 0 }]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[pdfStyles.tableCellWrap, { borderRightWidth: 0 }]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellMedium,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellMedium,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellXSmall,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellXSmall,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellSmall,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellSmall,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
|
||||
{/* Pengajuan Subtotal */}
|
||||
<View
|
||||
style={[
|
||||
pdfStyles.tableCellRightXSmall,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text style={{ fontWeight: 'bold' }}>Subtotal</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text style={{ fontWeight: 'bold' }}>
|
||||
{formatCurrency(supplierTotals.pengajuan)}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{/* Realisasi Subtotal */}
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
style={[
|
||||
pdfStyles.tableCellRightXSmall,
|
||||
{ borderRightWidth: 0 },
|
||||
]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text style={{ fontWeight: 'bold' }}>Subtotal</Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellRight}>
|
||||
<View style={pdfStyles.tableCellRightMedium}>
|
||||
<Text style={{ fontWeight: 'bold' }}>
|
||||
{formatCurrency(supplierTotals.realisasi)}
|
||||
</Text>
|
||||
</View>
|
||||
<View
|
||||
style={[pdfStyles.tableCell, { borderRightWidth: 0 }]}
|
||||
>
|
||||
<Text></Text>
|
||||
</View>
|
||||
<View style={pdfStyles.tableCellLast}>
|
||||
|
||||
{/* Empty cell for Status BOP */}
|
||||
<View style={pdfStyles.tableCellMedium}>
|
||||
<Text></Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -112,6 +112,159 @@ const pdfStyles = StyleSheet.create({
|
||||
fontSize: 7,
|
||||
textAlign: 'right',
|
||||
},
|
||||
tableCellNarrow: {
|
||||
width: '1%',
|
||||
minWidth: 20,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
textAlign: 'center',
|
||||
},
|
||||
tableCellNarrowHeader: {
|
||||
width: '1%',
|
||||
minWidth: 20,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
fontWeight: 'bold',
|
||||
backgroundColor: '#F5F5F5',
|
||||
textAlign: 'center',
|
||||
},
|
||||
tableCellWrap: {
|
||||
flex: 1,
|
||||
maxWidth: 80,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
flexWrap: 'wrap',
|
||||
},
|
||||
tableCellWrapHeader: {
|
||||
flex: 1,
|
||||
maxWidth: 80,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
fontWeight: 'bold',
|
||||
backgroundColor: '#F5F5F5',
|
||||
},
|
||||
// Nested header styles
|
||||
tableHeaderGroup: {
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: '#000000',
|
||||
borderBottomStyle: 'solid',
|
||||
backgroundColor: '#F5F5F5',
|
||||
},
|
||||
tableHeaderGroupLast: {
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: '#000000',
|
||||
borderBottomStyle: 'solid',
|
||||
backgroundColor: '#F5F5F5',
|
||||
},
|
||||
tableHeaderGroupTitle: {
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
fontWeight: 'bold',
|
||||
textAlign: 'center',
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: '#000000',
|
||||
borderBottomStyle: 'solid',
|
||||
},
|
||||
tableSubHeaderRow: {
|
||||
flexDirection: 'row',
|
||||
},
|
||||
// Specific width columns
|
||||
tableCellXSmall: {
|
||||
width: 30,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
},
|
||||
tableCellXSmallHeader: {
|
||||
width: 30,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
fontWeight: 'bold',
|
||||
backgroundColor: '#F5F5F5',
|
||||
},
|
||||
tableCellSmall: {
|
||||
width: 40,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
},
|
||||
tableCellSmallHeader: {
|
||||
width: 40,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
fontWeight: 'bold',
|
||||
backgroundColor: '#F5F5F5',
|
||||
},
|
||||
tableCellMedium: {
|
||||
width: 60,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
},
|
||||
tableCellMediumHeader: {
|
||||
width: 60,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
fontWeight: 'bold',
|
||||
backgroundColor: '#F5F5F5',
|
||||
},
|
||||
tableCellRightXSmall: {
|
||||
width: 30,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
textAlign: 'right',
|
||||
},
|
||||
tableCellRightSmall: {
|
||||
width: 40,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
textAlign: 'right',
|
||||
},
|
||||
tableCellRightMedium: {
|
||||
width: 60,
|
||||
borderRightWidth: 1,
|
||||
borderRightColor: '#000000',
|
||||
borderRightStyle: 'solid',
|
||||
padding: 3,
|
||||
fontSize: 7,
|
||||
textAlign: 'right',
|
||||
},
|
||||
tableBorderBottom: {
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: '#000000',
|
||||
@@ -142,7 +295,7 @@ const pdfStyles = StyleSheet.create({
|
||||
borderRightWidth: 0,
|
||||
},
|
||||
allocationSection: {
|
||||
marginBottom: 15,
|
||||
marginBottom: 8,
|
||||
},
|
||||
allocationTable: {
|
||||
borderWidth: 1,
|
||||
|
||||
Reference in New Issue
Block a user