update the prodect itesm
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user