extract frontend analytics helpers
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m12s

This commit is contained in:
Cauê Faleiros
2026-05-27 15:58:12 -03:00
parent 8c2590c56a
commit 72ded82ec7
9 changed files with 362 additions and 258 deletions

23
src/analytics/orders.ts Normal file
View File

@@ -0,0 +1,23 @@
import type { DateRange, OrderData } from '../types';
import { parseOrderDate } from '../dataService';
export const getBaseProductName = (description: string): string => {
return description.split(' TAMANHO')[0];
};
export const getClientDisplayName = (order: OrderData): string => {
return order.Nome_Cliente || `Cliente Desconhecido (Pedido ${order.Valor_Pedido})`;
};
export const isOrderInDateRange = (order: OrderData, dateRange: DateRange): boolean => {
const orderDate = parseOrderDate(order.Data_Pedido);
return orderDate >= dateRange.start && orderDate <= dateRange.end;
};
export const filterOrdersByDateRange = (orders: OrderData[], dateRange: DateRange): OrderData[] => {
return orders.filter(order => isOrderInDateRange(order, dateRange));
};
export const getOrderItemRevenue = (order: OrderData): number => {
return order.Quantidade * order.Valor_Unitario;
};