mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 00:50:56 +00:00
280 lines
6.6 KiB
TypeScript
280 lines
6.6 KiB
TypeScript
import { financeApi } from "@/auth/http";
|
|
import type { LocalizedName } from "@/shared/types";
|
|
|
|
export type AssetStatus =
|
|
| "ACTIVE"
|
|
| "FULLY_DEPRECIATED"
|
|
| "DISPOSED"
|
|
| "WRITTEN_OFF";
|
|
|
|
export type AssetRow = {
|
|
id: string;
|
|
assetCode: string;
|
|
name: string;
|
|
serialNumber: string | null;
|
|
acquisitionDate: string;
|
|
inServiceDate: string;
|
|
acquisitionCost: number | string;
|
|
salvageValue: number | string;
|
|
usefulLifeMonths: number;
|
|
accumulatedDepreciation: number | string;
|
|
netBookValue: number | string;
|
|
status: AssetStatus;
|
|
categoryCode: string;
|
|
categoryName: LocalizedName;
|
|
costCenterCode: string | null;
|
|
};
|
|
|
|
export type AssetCategory = {
|
|
id: string;
|
|
code: string;
|
|
name: LocalizedName;
|
|
defaultLifeMonths: number;
|
|
defaultSalvageRate: string;
|
|
isActive: boolean;
|
|
};
|
|
|
|
export type ScheduleRow = {
|
|
month: number;
|
|
amount: number;
|
|
accumulated: number;
|
|
netBookValue: number;
|
|
};
|
|
|
|
export type DepreciationRun = {
|
|
id: string;
|
|
runDate: string;
|
|
assetCount: number;
|
|
totalAmount: number | string;
|
|
entryNumber: string | null;
|
|
periodName: LocalizedName;
|
|
periodNumber: number;
|
|
};
|
|
|
|
export type Disposal = {
|
|
id: string;
|
|
disposalDate: string;
|
|
disposalType: string;
|
|
proceeds: number | string;
|
|
netBookValue: number | string;
|
|
gainLoss: number | string;
|
|
reference: string | null;
|
|
assetCode: string;
|
|
assetName: string;
|
|
};
|
|
|
|
export const ASSET_STATUS_COLOR: Record<AssetStatus, string> = {
|
|
ACTIVE: "green",
|
|
FULLY_DEPRECIATED: "blue",
|
|
DISPOSED: "gray",
|
|
WRITTEN_OFF: "red",
|
|
};
|
|
|
|
export const fetchAssets = async (status?: string): Promise<AssetRow[]> => {
|
|
const { data } = await financeApi.get("/assets", {
|
|
params: status ? { status } : undefined,
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const fetchAssetCategories = async (): Promise<AssetCategory[]> => {
|
|
const { data } = await financeApi.get("/assets/categories");
|
|
return data;
|
|
};
|
|
|
|
export const createAssetCategory = async (payload: {
|
|
code: string;
|
|
name: { en: string; am: string };
|
|
assetAccountId: string;
|
|
accumulatedAccountId: string;
|
|
expenseAccountId: string;
|
|
defaultLifeMonths: number;
|
|
defaultSalvageRate?: number;
|
|
}) => {
|
|
const { data } = await financeApi.post("/assets/categories", payload);
|
|
return data;
|
|
};
|
|
|
|
export const createAsset = async (payload: {
|
|
assetCategoryId: string;
|
|
assetCode: string;
|
|
name: string;
|
|
acquisitionDate: string;
|
|
inServiceDate?: string;
|
|
acquisitionCost: number;
|
|
salvageValue?: number;
|
|
usefulLifeMonths?: number;
|
|
costCenterId?: string;
|
|
fundingAccountId?: string;
|
|
}) => {
|
|
const { data } = await financeApi.post("/assets", payload);
|
|
return data;
|
|
};
|
|
|
|
export const fetchSchedule = async (
|
|
id: string,
|
|
): Promise<{
|
|
assetCode: string;
|
|
acquisitionCost: number;
|
|
salvageValue: number;
|
|
netBookValue: number;
|
|
periodsCharged: number;
|
|
schedule: ScheduleRow[];
|
|
}> => {
|
|
const { data } = await financeApi.get(`/assets/${id}/schedule`);
|
|
return data;
|
|
};
|
|
|
|
export const fetchDepreciationRuns = async (): Promise<DepreciationRun[]> => {
|
|
const { data } = await financeApi.get("/assets/depreciation/runs");
|
|
return data;
|
|
};
|
|
|
|
export const runDepreciation = async (fiscalPeriodId: string) => {
|
|
const { data } = await financeApi.post("/assets/depreciation/run", {
|
|
fiscalPeriodId,
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const fetchDisposals = async (): Promise<Disposal[]> => {
|
|
const { data } = await financeApi.get("/assets/disposals");
|
|
return data;
|
|
};
|
|
|
|
export const disposeAsset = async (
|
|
id: string,
|
|
payload: {
|
|
disposalType: string;
|
|
disposalDate: string;
|
|
proceeds?: number;
|
|
proceedsAccountId?: string;
|
|
reference?: string;
|
|
},
|
|
) => {
|
|
const { data } = await financeApi.post(`/assets/${id}/dispose`, payload);
|
|
return data;
|
|
};
|
|
|
|
// ── reports (4.6) ──────────────────────────────────────────────────────────
|
|
|
|
export type AccountLine = {
|
|
accountCode: string;
|
|
accountName: LocalizedName;
|
|
accountType: string;
|
|
isContra?: boolean;
|
|
};
|
|
|
|
export type TrialBalance = {
|
|
rows: (AccountLine & { normalBalance: string; debit: number; credit: number })[];
|
|
totalDebit: number;
|
|
totalCredit: number;
|
|
balanced: boolean;
|
|
difference: number;
|
|
};
|
|
|
|
export type ProfitAndLoss = {
|
|
dateFrom: string;
|
|
dateTo: string;
|
|
revenue: (AccountLine & { amount: number })[];
|
|
expenses: (AccountLine & { amount: number })[];
|
|
totalRevenue: number;
|
|
totalExpenses: number;
|
|
netResult: number;
|
|
};
|
|
|
|
export type BalanceSheet = {
|
|
asOf: string;
|
|
assets: (AccountLine & { balance: number })[];
|
|
liabilities: (AccountLine & { balance: number })[];
|
|
equity: (AccountLine & { balance: number })[];
|
|
totalAssets: number;
|
|
totalLiabilities: number;
|
|
totalEquity: number;
|
|
retainedResult: number;
|
|
equityWithResult: number;
|
|
balanced: boolean;
|
|
difference: number;
|
|
};
|
|
|
|
export type CashMovement = {
|
|
accounts: {
|
|
accountCode: string;
|
|
accountName: LocalizedName;
|
|
opening: number;
|
|
cashIn: number;
|
|
cashOut: number;
|
|
closing: number;
|
|
}[];
|
|
totalOpening: number;
|
|
totalIn: number;
|
|
totalOut: number;
|
|
totalClosing: number;
|
|
};
|
|
|
|
export type GeneralLedger = {
|
|
openingBalance: number;
|
|
closingBalance: number;
|
|
lines: {
|
|
entryDate: string;
|
|
entryNumber: string;
|
|
memo: string;
|
|
journalType: string;
|
|
description: string | null;
|
|
costCenterCode: string | null;
|
|
debit: number;
|
|
credit: number;
|
|
balance: number;
|
|
}[];
|
|
};
|
|
|
|
export const fetchTrialBalance = async (
|
|
dateFrom: string,
|
|
dateTo: string,
|
|
): Promise<TrialBalance> => {
|
|
const { data } = await financeApi.get<TrialBalance>("/reports/trial-balance", {
|
|
params: { dateFrom, dateTo },
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const fetchProfitAndLoss = async (
|
|
dateFrom: string,
|
|
dateTo: string,
|
|
): Promise<ProfitAndLoss> => {
|
|
const { data } = await financeApi.get<ProfitAndLoss>(
|
|
"/reports/profit-and-loss",
|
|
{ params: { dateFrom, dateTo } },
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const fetchBalanceSheet = async (asOf: string): Promise<BalanceSheet> => {
|
|
const { data } = await financeApi.get<BalanceSheet>("/reports/balance-sheet", {
|
|
params: { asOf },
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const fetchCashMovement = async (
|
|
dateFrom: string,
|
|
dateTo: string,
|
|
): Promise<CashMovement> => {
|
|
const { data } = await financeApi.get<CashMovement>("/reports/cash-movement", {
|
|
params: { dateFrom, dateTo },
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const fetchGeneralLedger = async (
|
|
accountId: string,
|
|
dateFrom: string,
|
|
dateTo: string,
|
|
): Promise<GeneralLedger> => {
|
|
const { data } = await financeApi.get<GeneralLedger>(
|
|
"/reports/general-ledger",
|
|
{ params: { accountId, dateFrom, dateTo } },
|
|
);
|
|
return data;
|
|
};
|