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:
48
lib/services/profit-analytics-service.ts
Normal file
48
lib/services/profit-analytics-service.ts
Normal 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}`);
|
||||
};
|
||||
Reference in New Issue
Block a user