194 lines
4.6 KiB
TypeScript
194 lines
4.6 KiB
TypeScript
import request from "@/api/request";
|
|
|
|
export type Status = "ACTIVE" | "INACTIVE";
|
|
export type MasterResource =
|
|
| "legal-entities"
|
|
| "cost-centers"
|
|
| "currencies"
|
|
| "payment-methods"
|
|
| "payment-accounts";
|
|
|
|
export interface LegalEntity {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
creditCode: string;
|
|
status: Status;
|
|
}
|
|
export interface CostCenter {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
legalEntityId: number;
|
|
legalEntityName: string;
|
|
managerName: string;
|
|
status: Status;
|
|
}
|
|
export interface Currency {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
symbol: string;
|
|
decimalPlaces: number;
|
|
status: Status;
|
|
}
|
|
export interface PaymentMethod {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
description: string;
|
|
status: Status;
|
|
}
|
|
export interface PaymentMethodOption {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
}
|
|
export interface PaymentAccount {
|
|
id: number;
|
|
code: string;
|
|
legalEntityId: number;
|
|
legalEntityName: string;
|
|
branchName?: string | null;
|
|
bankName: string;
|
|
accountNoMask: string;
|
|
currencyCode: string;
|
|
paymentMethodIds: number[];
|
|
paymentMethods: PaymentMethodOption[];
|
|
status: Status;
|
|
}
|
|
export interface BudgetSubject {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
level: 1 | 2;
|
|
parentId?: number;
|
|
parentCode?: string;
|
|
parentName?: string;
|
|
description: string;
|
|
status: Status;
|
|
}
|
|
export interface BudgetLedger {
|
|
id: number;
|
|
fiscalYear: number;
|
|
legalEntityId: number;
|
|
legalEntityName: string;
|
|
costCenterId: number;
|
|
costCenterCode: string;
|
|
costCenterName: string;
|
|
subjectId: number;
|
|
subjectCode: string;
|
|
subjectName: string;
|
|
categoryCode: string;
|
|
categoryName: string;
|
|
currencyCode: string;
|
|
limitAmount: number;
|
|
occupiedAmount: number;
|
|
executedAmount: number;
|
|
availableAmount: number;
|
|
usagePercent: number;
|
|
status: Status;
|
|
}
|
|
export interface BudgetAdjustment {
|
|
id: number;
|
|
requestNo: string;
|
|
createdAt: string;
|
|
fiscalYear: number;
|
|
legalEntityName: string;
|
|
costCenterCode: string;
|
|
costCenterName: string;
|
|
subjectCode: string;
|
|
subjectName: string;
|
|
categoryName: string;
|
|
currencyCode: string;
|
|
direction: "INCREASE" | "DECREASE";
|
|
amount: number;
|
|
beforeLimit: number;
|
|
afterLimit: number;
|
|
reason: string;
|
|
approvalStatus: string;
|
|
applicantName: string;
|
|
}
|
|
export interface BudgetSummary {
|
|
currencyCode: string;
|
|
limitAmount: number;
|
|
occupiedAmount: number;
|
|
executedAmount: number;
|
|
availableAmount: number;
|
|
}
|
|
export interface BudgetOverview {
|
|
fiscalYear: number;
|
|
subjects: BudgetSubject[];
|
|
ledgers: BudgetLedger[];
|
|
adjustments: BudgetAdjustment[];
|
|
summary: BudgetSummary[];
|
|
}
|
|
export interface BusinessConfigReferences {
|
|
employees?: { openId: string; name: string }[];
|
|
legalEntities?: LegalEntity[];
|
|
costCenters?: CostCenter[];
|
|
currencies?: Currency[];
|
|
paymentMethods?: PaymentMethod[];
|
|
}
|
|
|
|
const list = <T>(resource: MasterResource) =>
|
|
request.get<T[]>(`/business-config/${resource}`, {
|
|
suppressErrorNotification: true,
|
|
});
|
|
|
|
export const businessConfigApi = {
|
|
references: () =>
|
|
request.get<BusinessConfigReferences>("/business-config/references", {
|
|
suppressErrorNotification: true,
|
|
}),
|
|
legalEntities: () => list<LegalEntity>("legal-entities"),
|
|
costCenters: () => list<CostCenter>("cost-centers"),
|
|
currencies: () => list<Currency>("currencies"),
|
|
paymentMethods: () => list<PaymentMethod>("payment-methods"),
|
|
paymentAccounts: () => list<PaymentAccount>("payment-accounts"),
|
|
create<T>(
|
|
resource: Exclude<MasterResource, "currencies">,
|
|
payload: Record<string, unknown>,
|
|
) {
|
|
return request.post<T>(`/business-config/${resource}`, payload);
|
|
},
|
|
changeStatus<T>(
|
|
resource: Exclude<MasterResource, "currencies">,
|
|
id: number,
|
|
status: Status,
|
|
) {
|
|
return request.patch<T>(`/business-config/${resource}/${id}/status`, {
|
|
status,
|
|
});
|
|
},
|
|
budgetOverview: () =>
|
|
request.get<BudgetOverview>("/business-config/budgets/overview", {
|
|
suppressErrorNotification: true,
|
|
}),
|
|
createBudgetSubject: (payload: {
|
|
parentId: number;
|
|
name: string;
|
|
description: string;
|
|
}) =>
|
|
request.post<BudgetSubject>("/business-config/budget-subjects", payload),
|
|
changeBudgetSubjectStatus: (id: number, status: Status) =>
|
|
request.patch<BudgetSubject>(
|
|
`/business-config/budget-subjects/${id}/status`,
|
|
{ status },
|
|
),
|
|
requestBudgetAdjustment: (payload: {
|
|
fiscalYear: number;
|
|
legalEntityId: number;
|
|
costCenterId: number;
|
|
subjectId: number;
|
|
currencyCode: string;
|
|
direction: "INCREASE" | "DECREASE";
|
|
amount: number;
|
|
reason: string;
|
|
}) =>
|
|
request.post<BudgetAdjustment>(
|
|
"/business-config/budget-adjustments",
|
|
payload,
|
|
),
|
|
};
|