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 totalDiscount = 0; // to be subtracted from totalRawPrice let totalTax = 0; for (let i = 0; i < items.length; i++) { const itemTotalPrice = items[i].TotalPrice; const itemDiscount = (items[i].Discount / 100) * itemTotalPrice; totalRawPrice += itemTotalPrice; totalDiscount += itemDiscount; totalTax += (items[i].GST / 100) * (itemTotalPrice - itemDiscount); } const totalPriceAfterTax = (totalRawPrice - totalDiscount) + totalTax; const totalRoundedOff = Math.abs(totalPriceAfterTax - Math.round(totalPriceAfterTax)); return ( { "TotalRawPrice": totalRawPrice.toFixed(2), "TotalDiscountPrice": totalDiscount.toFixed(2), "TotalPriceAfterDiscount": (totalRawPrice - totalDiscount).toFixed(2), "TotalTaxAmount": totalTax.toFixed(2), "TotalPriceAfterTax": totalPriceAfterTax.toFixed(2), "RoundedOff": totalRoundedOff.toFixed(2), "TotalPrice": Math.round(totalPriceAfterTax) } ); } export const SummaryDisplayTR = (props) => { const summary = getBasicSummary(props.items); return ( Total {summary.TotalQuantity} {summary.TotalRawPrice} ); } const SummaryDisplay = (props) => { const summary = getFullSummary(props.items); return (

Summary

{true &&// summary.TotalDiscountPrice !== 0 && } {true && //summary.RoundedOff !== 0 && }
Base Total {summary.TotalRawPrice}
After Discount {summary.TotalPriceAfterDiscount} (-{summary.TotalDiscountPrice})
After Tax {summary.TotalPriceAfterTax} (+{summary.TotalTaxAmount})
Rounded Off {summary.RoundedOff}
Grand Total {summary.TotalPrice}
); } export default SummaryDisplay;