Files
ember-market-frontend/lib/services/profit-analytics-service.ts
NotII 50d0100056 Improve profit analytics chart and modal data handling
Enhanced ProfitAnalyticsChart to display more robust skeleton loaders and improved summary card logic with fallbacks for missing data. Updated the chart to distinguish between tracked and total revenue, and improved cost data coverage display. In the profit analysis modal, profit margin tiers are now sorted by minimum quantity. Updated the ProfitOverview interface to include revenueFromTrackedProducts.
2025-08-26 21:36:08 +01:00

50 lines
1.2 KiB
TypeScript

import { apiRequest } from '../api';
export interface ProfitOverview {
period: string;
summary: {
totalRevenue: number;
revenueFromTrackedProducts: 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}`);
};