import React from "react"; import "./Display.css"; const getBasicSummary = (items) => { let totalRawPrice = 0; let totalQuantity = 0; for (let i = 0; i < items.length; i++) { totalRawPrice += items[i].TotalPrice; totalQuantity += items[i].Quantity } return ( { "TotalRawPrice": totalRawPrice, "TotalQuantity": totalQuantity } ); } const getFullSummary = (items) => { let totalRawPrice = 0; let totalDiscountPrice = 0; // to be subtracted from totalRawPrice for (let i = 0; i < items.length; i++) { const itemTotalPrice = items[i].TotalPrice; const itemDiscount = items[i].Discount; totalRawPrice += itemTotalPrice; totalDiscountPrice += (itemDiscount / 100) * itemTotalPrice; } // TODO: add support for calculating gst from TotalPriceAfterDiscount return ( { "TotalRawPrice": totalRawPrice, "TotalPriceAfterDiscount": totalRawPrice - totalDiscountPrice } ); } export const SummaryDisplayTR = (props) => { const summary = getBasicSummary(props.items); return ( Total {summary.TotalQuantity} {summary.TotalRawPrice} ); } const SummaryDisplay = (props) => { const summary = getFullSummary(props.items); return ( <>

Total: {summary.TotalRawPrice}

Total after discount: {summary.TotalPriceAfterDiscount}

); } export default SummaryDisplay;