extract frontend analytics helpers
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m12s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m12s
This commit is contained in:
23
src/analytics/orders.ts
Normal file
23
src/analytics/orders.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user