tuckerhallie / bangazon-hip-hop-pizza-and-wangs-docs

0 stars 0 forks source link

Revenue Addition #22

Open MsSanli opened 5 months ago

MsSanli commented 5 months ago

Given: An authenticated cashier When: They submit booking Then: The # of days stayed and also amount paid (by # of days) should populate on the bookings page

MsSanli commented 5 months ago

can refer to pizza wings "parse"

import renderToDOM from '../utils/renderToDom'; import clearDom from '../utils/clearDom';

const revenuePage = (orders) => { // calculate total revenue let totalRevenue = 0; let totalTips = 0; let totalWalkIns = 0; let totalCallIns = 0; const paymentTypes = []; orders.forEach((order) => { // loop over items order.items.forEach((item) => { const parsedItemPrice = parseFloat(item.item_price); if (!Number.isNaN(parsedItemPrice)) { totalRevenue += parsedItemPrice; } }); if (order.order_type === 'Walk-in') totalWalkIns += 1; if (order.order_type === 'Call-in') totalCallIns += 1;

const parsedTipAmount = parseFloat(order.tip_amount);
if (!Number.isNaN(parsedTipAmount)) {
  totalTips += parsedTipAmount;
  totalRevenue += parsedTipAmount;
}
paymentTypes.push(order.payment_type);

}); clearDom(); const domString = `

REVENUE

TOTAL REVENUE: ${new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(totalRevenue)}

DATE RANGE:
TOTAL TIPS: $${totalTips}
TOTAL CALL IN ORDERS: ${totalCallIns}
TOTAL WALK IN ORDERS: ${totalWalkIns}
PAYMENT TYPES: ${Array.from(new Set(paymentTypes)).join(', ')}

`;

renderToDOM('#homeContainer', domString); };

export default revenuePage;