update the prodect itesm

This commit is contained in:
2026-09-30 19:09:48 +05:30
parent 76839eede2
commit 418081a545
99 changed files with 3501 additions and 203 deletions

View File

@@ -1,15 +1,30 @@
import type {ApiDashboardSummary} from '@/services/api/types';
import type {ApiPlatformDashboardSummary, ApiPlatformSale} from '@/services/api/types';
import type {TodaySummary} from '@/features/floor/types/summary';
import {rupeesToPaise} from '@/services/api/saleMapper';
/** Paise to rupees here, once, so no component ever divides by 100 itself. */
export function toTodaySummary(s: ApiDashboardSummary): TodaySummary {
/**
* 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: (s.total_revenue_paise ?? 0) / 100,
currency: s.currency || 'INR',
salesCount: s.sales_count,
enquiriesCount: s.enquiries_count,
onFloorNow: s.active_customer_count,
visitors: s.visitors_count,
revenue: paise / 100,
currency: sales[0]?.currency || 'INR',
salesCount: sales.length,
enquiriesCount: null,
onFloorNow: null,
visitors: s.visitors ?? 0,
};
}