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.
This commit is contained in:
NotII
2025-08-26 21:03:05 +01:00
parent be746664c5
commit f3fb067da7
3 changed files with 336 additions and 3 deletions

View File

@@ -0,0 +1,48 @@
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}`);
};