diff --git a/server/src/services/etlSync.ts b/server/src/services/etlSync.ts index 95d9404..4be56d2 100644 --- a/server/src/services/etlSync.ts +++ b/server/src/services/etlSync.ts @@ -40,7 +40,11 @@ export function aggregateTransactions(sales: ERPSaleRecord[]): AggregatedRecord[ for (const sale of sales) { const date = sale.TransactionDate.split(' ')[0]; - const channel = getChannelLabel(sale.OperatingAreaName); + const rawChannel = sale.OperatingAreaName; + const channel = getChannelLabel(rawChannel); + // B2C: each ticket = one visitor (1 PDF per person) + // Other channels: PeopleCount = actual visitors (group tickets) + const isB2C = rawChannel === 'B2C'; for (const product of sale.Products) { const { museums, split } = getMuseumsFromProduct(product.ProductDescription); @@ -72,7 +76,8 @@ export function aggregateTransactions(sales: ERPSaleRecord[]): AggregatedRecord[ map.set(key, entry); } - entry.Visits += product.PeopleCount * split; + const visitors = isB2C ? product.UnitQuantity : product.PeopleCount; + entry.Visits += visitors * split; entry.Tickets += product.UnitQuantity * split; entry.GrossRevenue += product.TotalPrice * split; entry.NetRevenue += (product.TotalPrice - product.TaxAmount) * split;