mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 17:45:42 +00:00
Added financial report
This commit is contained in:
65
apps/edr-passenger-web/backoffice/src/lib/api/finance.ts
Normal file
65
apps/edr-passenger-web/backoffice/src/lib/api/finance.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { apiClient } from '@/lib/api-client';
|
||||
|
||||
export type FinanceGranularity = 'daily' | 'weekly' | 'monthly';
|
||||
|
||||
export interface FinanceSummaryFilters {
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
granularity?: FinanceGranularity;
|
||||
originStationId?: string;
|
||||
destinationStationId?: string;
|
||||
method?: string;
|
||||
}
|
||||
|
||||
export interface FinanceBucketRow {
|
||||
period: string;
|
||||
originStationId: string;
|
||||
destinationStationId: string;
|
||||
segmentLabel: string;
|
||||
method: string;
|
||||
bookingCount: number;
|
||||
revenueEtbMinor: number;
|
||||
}
|
||||
|
||||
export interface FinanceRollupRow {
|
||||
key: string;
|
||||
label: string;
|
||||
revenueEtbMinor: number;
|
||||
bookingCount: number;
|
||||
}
|
||||
|
||||
export interface FinanceTotals {
|
||||
bookingCount: number;
|
||||
revenueEtbMinor: number;
|
||||
}
|
||||
|
||||
export interface FinanceSummaryReport {
|
||||
granularity: FinanceGranularity;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
currency: string;
|
||||
totals: FinanceTotals;
|
||||
byPeriod: FinanceRollupRow[];
|
||||
bySegment: FinanceRollupRow[];
|
||||
byMethod: FinanceRollupRow[];
|
||||
rows: FinanceBucketRow[];
|
||||
}
|
||||
|
||||
/** Drops blanks so the API applies its own defaults (granularity=daily, no station/method filter). */
|
||||
function toParams(filters: FinanceSummaryFilters): Record<string, string> {
|
||||
const params: Record<string, string> = { dateFrom: filters.dateFrom, dateTo: filters.dateTo };
|
||||
if (filters.granularity) params.granularity = filters.granularity;
|
||||
if (filters.originStationId) params.originStationId = filters.originStationId;
|
||||
if (filters.destinationStationId) params.destinationStationId = filters.destinationStationId;
|
||||
if (filters.method) params.method = filters.method;
|
||||
return params;
|
||||
}
|
||||
|
||||
export const financeApi = {
|
||||
getSummary: (filters: FinanceSummaryFilters) =>
|
||||
apiClient.get<FinanceSummaryReport>('/reports/finance', { params: toParams(filters) }),
|
||||
|
||||
/** CSV export. `getRaw` because the endpoint streams a bare CSV body, not the `{success,data}` envelope. */
|
||||
exportCsv: (filters: FinanceSummaryFilters) =>
|
||||
apiClient.getRaw<string>('/reports/finance/export', { params: toParams(filters) }),
|
||||
};
|
||||
Reference in New Issue
Block a user