diff --git a/src/components/pages/finance/FinanceDetail.tsx b/src/components/pages/finance/FinanceDetail.tsx
index 03291420..76d2d1a0 100644
--- a/src/components/pages/finance/FinanceDetail.tsx
+++ b/src/components/pages/finance/FinanceDetail.tsx
@@ -34,7 +34,7 @@ const FinanceDetail = ({ finance }: { finance: Finance }) => {
},
{
label: 'Pihak',
- value: finance.party.id ? finance.party.name : '-',
+ value: finance.party?.id ? finance.party?.name : '-',
},
{
label: 'Tanggal',
@@ -56,25 +56,21 @@ const FinanceDetail = ({ finance }: { finance: Finance }) => {
},
{
label: 'Nomor Rekening',
- value: `${finance.bank.alias} - ${finance.bank.account_number} - ${finance.bank.owner}`,
+ value: `${finance.bank?.alias} - ${finance.bank?.account_number} - ${finance.bank?.owner}`,
},
{
- label: `Rekening ${formatTitleCase(finance.party.type)}`,
- value: finance.party.account_number,
+ label: `Rekening ${formatTitleCase(finance.party?.type)}`,
+ value: finance.party?.account_number,
},
{
label: 'Nominal',
- value: formatCurrency(finance.expense_amount),
- },
- {
- label: 'Sisa',
- value: formatCurrency(finance.income_amount),
+ value: formatCurrency(finance.nominal),
},
].filter((item) => {
// Hide party account number row if transaction type is INJECTION
if (
FINANCE_INJECTION_STATUS.includes(finance.transaction_type) &&
- item.label === `Rekening ${formatTitleCase(finance.party.type)}`
+ item.label === `Rekening ${formatTitleCase(finance.party?.type)}`
) {
return false;
}
@@ -148,18 +144,19 @@ const FinanceDetail = ({ finance }: { finance: Finance }) => {
- {FINANCE_TRANSACTION_STATUS.includes(finance.transaction_type) && (
-
-
-
- )}
+ {FINANCE_TRANSACTION_STATUS.includes(finance.transaction_type) &&
+ finance.party?.type !== 'SUPPLIER' && (
+
+
+
+ )}
{FINANCE_INITIAL_BALANCE_STATUS.includes(finance.transaction_type) && (
- )}
+ ) &&
+ props.row.original.party?.type !== 'SUPPLIER' && (
+
+
+
+ Edit
+
+
+ )}
{FINANCE_INITIAL_BALANCE_STATUS.includes(
props.row.original.transaction_type
@@ -194,20 +199,25 @@ const FinanceTable = () => {
// ===== Options =====
const transactionTypeOptions = useMemo(() => {
- return [
- { label: 'Transfer', value: 'TRANSFER' },
- { label: 'Cash', value: 'CASH' },
- { label: 'Card', value: 'CARD' },
- { label: 'Cheque', value: 'CHEQUE' },
- { label: 'Saldo', value: 'SALDO' },
- ];
- }, []);
- const partyTypeOptions = useMemo(() => {
return [
{ label: 'Customer', value: 'CUSTOMER' },
{ label: 'Supplier', value: 'SUPPLIER' },
];
}, []);
+ const {
+ options: partyTypeOptions,
+ isLoadingOptions: partyTypeIsLoadingOptions,
+ setInputValue: partyTypeInputValue,
+ loadMore: partyTypeLoadMore,
+ } = useSelect(
+ selectedTransactionType
+ ? selectedTransactionType.value === 'CUSTOMER'
+ ? CustomerApi.basePath
+ : SupplierApi.basePath
+ : '',
+ 'id',
+ 'name'
+ );
const sortByOptions = useMemo(() => {
return [
{ label: 'Tanggal Pembayaran', value: 'payment_date' },
@@ -336,10 +346,10 @@ const FinanceTable = () => {
},
{
header: 'Pihak',
- accessorFn: (finance: Finance) => finance.party.name,
+ accessorFn: (finance: Finance) => finance.party?.name,
cell: (props: CellContext
) => {
- if (props.row.original.party.id) {
- return {props.row.original.party.name};
+ if (props.row.original.party?.id) {
+ return {props.row.original.party?.name};
}
return {'-'};
},
@@ -360,12 +370,12 @@ const FinanceTable = () => {
{
header: 'Bank',
accessorFn: (finance: Finance) =>
- `${finance.bank.alias} - ${finance.bank.account_number} - ${finance.bank.owner}`,
+ `${finance.bank?.alias} - ${finance.bank?.account_number} - ${finance.bank?.owner}`,
},
{
header: 'Pengeluaran (Rp)',
accessorFn: (finance: Finance) =>
- formatCurrency(finance.expense_amount),
+ formatCurrency(Math.abs(finance.expense_amount)),
},
{
header: 'Pemasukan (Rp)',
@@ -468,25 +478,41 @@ const FinanceTable = () => {
+
({
label:
- bankRawData.data.find((data) => data.id === bank.value)
+ bankRawData.data.find((data) => data.id === bank?.value)
?.alias +
' - ' +
- bankRawData.data.find((data) => data.id === bank.value)
+ bankRawData.data.find((data) => data.id === bank?.value)
?.account_number +
' - ' +
- bankRawData.data.find((data) => data.id === bank.value)
+ bankRawData.data.find((data) => data.id === bank?.value)
?.owner,
- value: bank.value,
+ value: bank?.value,
}))
: []
}
@@ -497,13 +523,6 @@ const FinanceTable = () => {
onMenuScrollToBottom={bankLoadMore}
isClearable
/>
-
{
const router = useRouter();
+ const [serverErrorMessage, setServerErrorMessage] = useState('');
+ const [isSupplier, setIsSupplier] = useState(
+ initialValues?.party?.type === 'SUPPLIER'
+ );
// ===== Formik =====
const formikInitialValues = useMemo((): FinanceFormValues => {
return {
party_type_option:
FINANCE_PARTY_TYPE_OPTIONS.find(
- (option) => option.value === initialValues?.party.type
+ (option) => option.value === initialValues?.party?.type
) || null,
party_id_option: initialValues?.party
? {
- label: initialValues?.party.name || '',
- value: initialValues?.party.id || 0,
+ label: initialValues?.party?.name || '',
+ value: initialValues?.party?.id || 0,
}
: null,
payment_date: initialValues?.payment_date || '',
@@ -72,11 +78,11 @@ const FormFinanceAdd = ({
) || null,
bank_id_option: initialValues?.bank
? {
- label: initialValues.bank.name,
- value: initialValues.bank.id,
+ label: initialValues?.bank?.name,
+ value: initialValues?.bank?.id,
}
: null,
- party_account_number: initialValues?.party.account_number || '',
+ party_account_number: initialValues?.party?.account_number || '',
reference_number: initialValues?.reference_number || '',
nominal: initialValues?.nominal.toString() || '',
notes: initialValues?.notes || '',
@@ -153,6 +159,7 @@ const FormFinanceAdd = ({
if (isResponseError(response)) {
toast.error(response.message);
+ setServerErrorMessage(response.message);
return;
}
@@ -168,6 +175,7 @@ const FormFinanceAdd = ({
if (isResponseError(response)) {
toast.error(response.message);
+ setServerErrorMessage(response.message);
return;
}
@@ -207,6 +215,7 @@ const FormFinanceAdd = ({
? formik.errors.party_type_option
: ''
}
+ isDisabled={type === 'edit' || isSupplier}
required
isClearable
/>
@@ -245,7 +254,7 @@ const FormFinanceAdd = ({
}
required
isClearable
- isDisabled={!formik.values.party_type_option?.value}
+ isDisabled={!formik.values.party_type_option?.value || isSupplier}
/>
+ {serverErrorMessage && (
+
+
+ {serverErrorMessage}
+ setServerErrorMessage('')}>
+
+
+
+ )}
value !== null && value !== undefined
),
- bank_id_option: Yup.mixed()
- .nullable()
- .test(
- 'is-valid-option',
- 'Bank wajib diisi',
- (value) => value !== null && value !== undefined
- ),
+ bank_id_option: Yup.mixed().nullable(),
reference_number: Yup.string().required('Nomor referensi wajib diisi'),
initial_balance_type_option: Yup.mixed()
.nullable()
diff --git a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
index 7bcdbccf..e1a31415 100644
--- a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
+++ b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
@@ -29,8 +29,9 @@ import { Bank } from '@/types/api/master-data/bank';
import { Icon } from '@iconify/react';
import { useFormik } from 'formik';
import { useRouter } from 'next/navigation';
-import { useCallback, useMemo } from 'react';
+import { useCallback, useMemo, useState } from 'react';
import toast from 'react-hot-toast';
+import Alert from '@/components/Alert';
interface FormFinanceAddInitialBalanceProps {
type?: 'add' | 'edit';
@@ -42,6 +43,7 @@ const FormFinanceAddInitialBalance = ({
initialValues,
}: FormFinanceAddInitialBalanceProps) => {
const router = useRouter();
+ const [serverErrorMessage, setServerErrorMessage] = useState('');
// ===== Formik =====
const formikInitialValues = useMemo((): InitialBalanceFormValues => {
@@ -53,18 +55,18 @@ const FormFinanceAddInitialBalance = ({
return {
party_type_option:
FINANCE_PARTY_TYPE_OPTIONS.find(
- (option) => option.value === initialValues?.party.type
+ (option) => option.value === initialValues?.party?.type
) || null,
party_id_option: initialValues?.party
? {
- label: initialValues.party.name,
- value: initialValues.party.id,
+ label: initialValues.party?.name,
+ value: initialValues.party?.id,
}
: null,
bank_id_option: initialValues?.bank
? {
- label: initialValues.bank.name,
- value: initialValues.bank.id,
+ label: initialValues.bank?.name,
+ value: initialValues.bank?.id,
}
: null,
reference_number: initialValues?.reference_number || '',
@@ -147,6 +149,7 @@ const FormFinanceAddInitialBalance = ({
if (isResponseError(response)) {
toast.error(response.message);
+ setServerErrorMessage(response.message);
return;
}
@@ -166,6 +169,7 @@ const FormFinanceAddInitialBalance = ({
if (isResponseError(response)) {
toast.error(response.message);
+ setServerErrorMessage(response.message);
return;
}
@@ -211,6 +215,7 @@ const FormFinanceAddInitialBalance = ({
: ''
}
required
+ isDisabled={type === 'edit'}
isClearable
/>
+
+ {serverErrorMessage && (
+
+
+ {serverErrorMessage}
+ setServerErrorMessage('')}>
+
+
+
+ )}
+
{
const router = useRouter();
+ const [serverErrorMessage, setServerErrorMessage] = useState('');
// ===== Formik =====
const formikInitialValues = useMemo((): InjectionFormValues => {
return {
bank_id_option: initialValues?.bank
? {
- label: initialValues.bank.name,
- value: initialValues.bank.id,
+ label: initialValues.bank?.name,
+ value: initialValues.bank?.id,
}
: null,
adjustment_date: initialValues?.payment_date || '',
@@ -103,6 +106,7 @@ const FormFinanceInjection = ({
if (isResponseError(response)) {
toast.error(response.message);
+ setServerErrorMessage(response.message);
return;
}
@@ -119,6 +123,7 @@ const FormFinanceInjection = ({
if (isResponseError(response)) {
toast.error(response.message);
+ setServerErrorMessage(response.message);
return;
}
@@ -230,6 +235,15 @@ const FormFinanceInjection = ({
required
/>
+ {serverErrorMessage && (
+
+
+ {serverErrorMessage}
+ setServerErrorMessage('')}>
+
+
+
+ )}