diff --git a/src/config/constant.ts b/src/config/constant.ts
index 47352d8b..047ed279 100644
--- a/src/config/constant.ts
+++ b/src/config/constant.ts
@@ -300,6 +300,17 @@ export const FINANCE_PAYMENT_METHOD_OPTIONS = [
{ label: 'Saldo', value: 'SALDO' },
];
+export const FINANCE_INITIAL_BALANCE_TYPE_OPTIONS = [
+ { label: 'Saldo Awal Positif', value: 'POSITIVE' },
+ { label: 'Saldo Awal Negatif', value: 'NEGATIVE' },
+];
+
+export const FINANCE_TRANSACTION_STATUS = ['PENJUALAN', 'BIAYA'];
+
+export const FINANCE_INITIAL_BALANCE_STATUS = ['SALDO_AWAL'];
+
+export const FINANCE_INJECTION_STATUS = ['INJECTION'];
+
export const APPROVAL_WORKFLOWS = [
{
key: 'PROJECT_FLOCKS',
diff --git a/src/config/route-permission.ts b/src/config/route-permission.ts
index 87faf10d..1b9df69d 100644
--- a/src/config/route-permission.ts
+++ b/src/config/route-permission.ts
@@ -68,6 +68,28 @@ export const ROUTE_PERMISSIONS: Record = {
'/expense/realization/': ['lti.expense.create.realization'],
'/expense/realization/edit/': ['lti.expense.update.realization'],
+ // Finance
+ // // ===== FINANCE =====
+ // "lti.finance.transaction.list",
+ // "lti.finance.transaction.detail",
+ // "lti.finance.transaction.delete",
+ // "lti.finance.payments.create",
+ // "lti.finance.payments.update",
+ // "lti.finance.initial_balances.create",
+ // "lti.finance.initial_balances.update",
+ // "lti.finance.injections.create",
+ // "lti.finance.injections.update",
+ '/finance/': ['lti.finance.transaction.list'],
+ '/finance/detail/': ['lti.finance.transaction.detail'],
+ '/finance/add/': ['lti.finance.payments.create'],
+ '/finance/detail/edit/': ['lti.finance.payments.update'],
+ '/finance/add/initial-balance/': ['lti.finance.initial_balances.create'],
+ '/finance/detail/edit/initial-balance/': [
+ 'lti.finance.initial_balances.update',
+ ],
+ '/finance/add/injection/': ['lti.finance.injections.create'],
+ '/finance/detail/edit/injection/': ['lti.finance.injections.update'],
+
// Closing
'/closing/': ['lti.closing.list'],
'/closing/detail/': ['lti.closing.detail'],
diff --git a/src/services/api/finance.ts b/src/services/api/finance.ts
index c277cfde..f9ba367f 100644
--- a/src/services/api/finance.ts
+++ b/src/services/api/finance.ts
@@ -1,11 +1,16 @@
import axios from 'axios';
import { BaseApiService } from '@/services/api/base';
import { BaseApiResponse } from '@/types/api/api-general';
-import { httpClient } from '@/services/http/client';
-import { Finance } from '@/types/api/finance/finance';
-// DUMMY_START
-import { getAllFetcher, getFetcher } from '@/dummy/finance/finance.dummy';
-// DUMMY_END
+import { httpClient, httpClientFetcher } from '@/services/http/client';
+import {
+ CreateFinancePayment,
+ CreateInitialBalance,
+ CreateInjection,
+ Finance,
+ UpdateFinancePayment,
+ UpdateInitialBalance,
+ UpdateInjection,
+} from '@/types/api/finance/finance';
export class FinanceApiService extends BaseApiService<
Finance,
@@ -16,41 +21,173 @@ export class FinanceApiService extends BaseApiService<
super(basePath);
}
- async getAllFetcher(): Promise> {
- // DUMMY_START
- return await getAllFetcher();
- // DUMMY_END
-
- // LIVE_START
- // try {
- // const path = `${this.basePath}/`;
- // return await httpClient>(path);
- // } catch (error) {
- // if (axios.isAxiosError>(error)) {
- // return error.response?.data;
- // }
- // return undefined;
- // }
- // LIVE_END
+ async getSingle(id: number): Promise> {
+ return await httpClientFetcher>(
+ `${this.basePath}/transactions/${id}`
+ );
}
- async getSingle(id: number): Promise> {
- // DUMMY_START
- return await getFetcher(id);
- // DUMMY_END
+ async create(payload: CreateFinancePayment) {
+ const isFormData =
+ typeof FormData !== 'undefined' && payload instanceof FormData;
+ try {
+ const headers = isFormData
+ ? { ...(this.header ?? {}) }
+ : { 'Content-Type': 'application/json', ...(this.header ?? {}) };
- // LIVE_START
- // try {
- // const path = `${this.basePath}/`;
- // return await httpClient>(path);
- // } catch (error) {
- // if (axios.isAxiosError>(error)) {
- // return error.response?.data;
- // }
- // return undefined;
- // }
- // LIVE_END
+ const createRes = await httpClient>(
+ `${this.basePath}/payments`,
+ {
+ method: 'POST',
+ body: payload,
+ headers,
+ }
+ );
+ return createRes;
+ } catch (error: unknown) {
+ if (axios.isAxiosError>(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
+ }
+
+ async createInitialBalances(payload: CreateInitialBalance) {
+ const isFormData =
+ typeof FormData !== 'undefined' && payload instanceof FormData;
+ try {
+ const headers = isFormData
+ ? { ...(this.header ?? {}) }
+ : { 'Content-Type': 'application/json', ...(this.header ?? {}) };
+
+ const createRes = await httpClient>(
+ `${this.basePath}/initial-balances`,
+ {
+ method: 'POST',
+ body: payload,
+ headers,
+ }
+ );
+ return createRes;
+ } catch (error: unknown) {
+ if (axios.isAxiosError>(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
+ }
+
+ async createInjections(payload: CreateInjection) {
+ const isFormData =
+ typeof FormData !== 'undefined' && payload instanceof FormData;
+ try {
+ const headers = isFormData
+ ? { ...(this.header ?? {}) }
+ : { 'Content-Type': 'application/json', ...(this.header ?? {}) };
+
+ const createRes = await httpClient>(
+ `${this.basePath}/injections`,
+ {
+ method: 'POST',
+ body: payload,
+ headers,
+ }
+ );
+ return createRes;
+ } catch (error: unknown) {
+ if (axios.isAxiosError>(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
+ }
+
+ async update(id: number, payload: UpdateFinancePayment) {
+ const isFormData =
+ typeof FormData !== 'undefined' && payload instanceof FormData;
+ try {
+ const updatePath = `${this.basePath}/payments/${id}`;
+
+ const headers = isFormData
+ ? { ...(this.header ?? {}) }
+ : { 'Content-Type': 'application/json', ...(this.header ?? {}) };
+
+ const updateRes = await httpClient>(updatePath, {
+ method: 'PATCH',
+ body: payload,
+ headers,
+ });
+ return updateRes;
+ } catch (error: unknown) {
+ if (axios.isAxiosError>(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
+ }
+
+ async updateInitialBalances(id: number, payload: UpdateInitialBalance) {
+ const isFormData =
+ typeof FormData !== 'undefined' && payload instanceof FormData;
+ try {
+ const updatePath = `${this.basePath}/initial-balances/${id}`;
+
+ const headers = isFormData
+ ? { ...(this.header ?? {}) }
+ : { 'Content-Type': 'application/json', ...(this.header ?? {}) };
+
+ const updateRes = await httpClient>(updatePath, {
+ method: 'PATCH',
+ body: payload,
+ headers,
+ });
+ return updateRes;
+ } catch (error: unknown) {
+ if (axios.isAxiosError>(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
+ }
+
+ async updateInjections(id: number, payload: UpdateInjection) {
+ const isFormData =
+ typeof FormData !== 'undefined' && payload instanceof FormData;
+ try {
+ const updatePath = `${this.basePath}/injections/${id}`;
+
+ const headers = isFormData
+ ? { ...(this.header ?? {}) }
+ : { 'Content-Type': 'application/json', ...(this.header ?? {}) };
+
+ const updateRes = await httpClient>(updatePath, {
+ method: 'PATCH',
+ body: payload,
+ headers,
+ });
+ return updateRes;
+ } catch (error: unknown) {
+ if (axios.isAxiosError>(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
+ }
+
+ async delete(id: number) {
+ try {
+ const deletePath = `${this.basePath}/transactions/${id}`;
+ const deleteRes = await httpClient(deletePath, {
+ method: 'DELETE',
+ });
+ return deleteRes;
+ } catch (error) {
+ if (axios.isAxiosError(error)) {
+ return error.response?.data;
+ }
+ return undefined;
+ }
}
}
-export const FinanceApi = new FinanceApiService('/finances');
+export const FinanceApi = new FinanceApiService('/finance');
diff --git a/src/types/api/finance/finance.d.ts b/src/types/api/finance/finance.d.ts
index 574ee4d6..02f8bbbb 100644
--- a/src/types/api/finance/finance.d.ts
+++ b/src/types/api/finance/finance.d.ts
@@ -1,4 +1,4 @@
-export interface Finance {
+export type Finance = {
id: number;
payment_code: string;
reference_number: string;
@@ -12,18 +12,49 @@ export interface Finance {
income_amount: number;
nominal: number;
notes: string;
-}
+};
-export interface FinanceParty {
+export type FinanceParty = {
id: number;
name: string;
type: string;
account_number: string;
-}
-export interface FinanceBank {
+};
+export type FinanceBank = {
id: number;
name: string;
alias: string;
owner: string;
account_number: string;
-}
+};
+export type CreateFinancePayment = {
+ party_id: number;
+ party_type: string;
+ payment_date: string;
+ payment_method: string;
+ bank_id: number;
+ reference_number: string;
+ nominal: number;
+ notes: string;
+};
+
+export type UpdateFinancePayment = CreateFinancePayment;
+export type CreateInitialBalance = {
+ party_type: string;
+ party_id: number;
+ bank_id: number;
+ reference_number: string;
+ initial_balance_type: string;
+ nominal: number;
+ note: string;
+};
+
+export type UpdateInitialBalance = CreateInitialBalance;
+export type CreateInjection = {
+ bank_id: number;
+ adjustment_date: string;
+ nominal: number;
+ notes: string;
+};
+
+export type UpdateInjection = CreateInjection;