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 = { ACTIVE: "green", FULLY_DEPRECIATED: "blue", DISPOSED: "gray", WRITTEN_OFF: "red", }; export const fetchAssets = async (status?: string): Promise => { const { data } = await financeApi.get("/assets", { params: status ? { status } : undefined, }); return data; }; export const fetchAssetCategories = async (): Promise => { 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 => { 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 => { 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 => { const { data } = await financeApi.get("/reports/trial-balance", { params: { dateFrom, dateTo }, }); return data; }; export const fetchProfitAndLoss = async ( dateFrom: string, dateTo: string, ): Promise => { const { data } = await financeApi.get( "/reports/profit-and-loss", { params: { dateFrom, dateTo } }, ); return data; }; export const fetchBalanceSheet = async (asOf: string): Promise => { const { data } = await financeApi.get("/reports/balance-sheet", { params: { asOf }, }); return data; }; export const fetchCashMovement = async ( dateFrom: string, dateTo: string, ): Promise => { const { data } = await financeApi.get("/reports/cash-movement", { params: { dateFrom, dateTo }, }); return data; }; export const fetchGeneralLedger = async ( accountId: string, dateFrom: string, dateTo: string, ): Promise => { const { data } = await financeApi.get( "/reports/general-ledger", { params: { accountId, dateFrom, dateTo } }, ); return data; };