Files
ember-market-frontend/lib/services/profit-analytics-service.ts
NotII f3fb067da7 Add profit analytics chart and service
Introduces a new ProfitAnalyticsChart component to display profit-related metrics, including total revenue, cost, profit, and top profitable products. Updates the AnalyticsDashboard to include a Profit tab and adds a profit-analytics-service for fetching profit data from the backend.
2025-08-26 21:03:05 +01:00

49 lines
1.1 KiB
TypeScript

import { apiRequest } from '../api';
export interface ProfitOverview {
period: string;
summary: {
totalRevenue: number;
totalCost: number;
totalProfit: number;
overallProfitMargin: number;
averageProfitPerUnit: number;
costDataCoverage: number;
totalProductsSold: number;
productsWithCostData: number;
};
topProfitableProducts: Array<{
productId: string;
productName: string;
totalQuantitySold: number;
totalRevenue: number;
totalCost: number;
totalProfit: number;
averageProfit: number;
profitMargin: number;
}>;
hasCostData: boolean;
}
export interface ProfitTrend {
_id: {
year: number;
month: number;
day: number;
};
revenue: number;
cost: number;
profit: number;
orders: number;
itemsWithCostData: number;
profitMargin: number;
}
export const getProfitOverview = async (period: string = '30'): Promise<ProfitOverview> => {
return apiRequest(`/analytics/profit-overview?period=${period}`);
};
export const getProfitTrends = async (period: string = '30'): Promise<ProfitTrend[]> => {
return apiRequest(`/analytics/profit-trends?period=${period}`);
};