All checks were successful
Build Frontend / build (push) Successful in 1m11s
Enhanced the AnalyticsDashboard layout with a premium glassmorphism UI, improved toolbar, and reorganized tabs for better clarity. MetricsCard now features dynamic color coding and trend badges. PredictionsChart received scenario simulation UI upgrades, disabled future ranges based on available history, and improved chart tooltips and visuals. ProfitAnalyticsChart added error handling for product images and minor UI refinements. Updated globals.css with new premium utility classes and improved dark mode color variables.
88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import { apiRequest } from '../api';
|
|
|
|
export interface ProfitOverview {
|
|
period: string;
|
|
startDate?: string;
|
|
endDate?: 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;
|
|
image?: 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 interface DateRange {
|
|
from: Date;
|
|
to: Date;
|
|
}
|
|
|
|
export const getProfitOverview = async (
|
|
periodOrRange?: string | DateRange
|
|
): Promise<ProfitOverview> => {
|
|
let url = '/analytics/profit-overview';
|
|
|
|
if (periodOrRange && typeof periodOrRange !== 'string') {
|
|
// Date range provided
|
|
const startDate = periodOrRange.from.toISOString().split('T')[0];
|
|
const endDate = periodOrRange.to.toISOString().split('T')[0];
|
|
url += `?startDate=${startDate}&endDate=${endDate}`;
|
|
} else {
|
|
// Period provided (backward compatibility)
|
|
const period = periodOrRange || '30';
|
|
url += `?period=${period}`;
|
|
}
|
|
|
|
return apiRequest(url);
|
|
};
|
|
|
|
export const getProfitTrends = async (
|
|
periodOrRange?: string | DateRange
|
|
): Promise<ProfitTrend[]> => {
|
|
let url = '/analytics/profit-trends';
|
|
|
|
if (periodOrRange && typeof periodOrRange !== 'string') {
|
|
// Date range provided
|
|
const startDate = periodOrRange.from.toISOString().split('T')[0];
|
|
const endDate = periodOrRange.to.toISOString().split('T')[0];
|
|
url += `?startDate=${startDate}&endDate=${endDate}`;
|
|
} else {
|
|
// Period provided (backward compatibility)
|
|
const period = periodOrRange || '30';
|
|
url += `?period=${period}`;
|
|
}
|
|
|
|
return apiRequest(url);
|
|
};
|