Files
loyaly_cutomerweb/src/features/floor/services/mapSummary.ts
2026-09-30 19:09:48 +05:30

31 lines
1.1 KiB
TypeScript

import type {ApiPlatformDashboardSummary, ApiPlatformSale} from '@/services/api/types';
import type {TodaySummary} from '@/features/floor/types/summary';
import {rupeesToPaise} from '@/services/api/saleMapper';
/**
* The platform's summary (footfall) plus today's sales (money) → the card.
*
* `/api/dashboard/summary` carries no revenue or sales, so those are counted
* from the same day's `/api/sales` rows. Summed in integer paise so a day of
* ₹0.10s cannot drift, then turned into rupees here, once, so no component
* ever divides by 100 itself.
*
* Enquiries and "on the floor now" have no source on the platform yet and are
* `null` — the card shows "—" rather than a 0 that reads as a real answer.
*/
export function toTodaySummary(
s: ApiPlatformDashboardSummary,
sales: ApiPlatformSale[],
): TodaySummary {
const paise = sales.reduce((sum, sale) => sum + rupeesToPaise(sale.amount), 0);
return {
date: s.date,
revenue: paise / 100,
currency: sales[0]?.currency || 'INR',
salesCount: sales.length,
enquiriesCount: null,
onFloorNow: null,
visitors: s.visitors ?? 0,
};
}