From 6874be2c3016b872016ba32181823a8e1232a1a7 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Fri, 25 Jun 2021 18:06:56 +0530 Subject: Ported SummaryDisplay to tsx --- src/components/Display/SummaryDisplay.txt | 132 ------------------------------ 1 file changed, 132 deletions(-) delete mode 100644 src/components/Display/SummaryDisplay.txt (limited to 'src/components/Display/SummaryDisplay.txt') diff --git a/src/components/Display/SummaryDisplay.txt b/src/components/Display/SummaryDisplay.txt deleted file mode 100644 index e06eac5..0000000 --- a/src/components/Display/SummaryDisplay.txt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * OpenBills - Self hosted browser app to generate and keep track of simple invoices - * Version - 0 - * Licensed under the MIT license - https://opensource.org/licenses/MIT - * - * Copyright (c) 2021 Vidhu Kant Sharma -*/ - -import React from "react"; -import "./Display.scss"; - -interface props { -} - -const getBasicSummary = (items) => { - let totalRawPrice = 0; - let totalQuantity = 0; - - items.some((i) => { - totalRawPrice += i.TotalPrice; - totalQuantity += i.Quantity; - return null; - } - ) - - return ( - { - "TotalRawPrice": totalRawPrice, - "TotalQuantity": totalQuantity - } - ); -} - -// TODO: remove mutability from this function -const getFullSummary = (items) => { - let totalRawPrice = 0; - let totalDiscount = 0; // to be subtracted from totalRawPrice - let totalTax = 0; - - items.some((i) => { - const itemTotalPrice = i.TotalPrice; - const itemDiscount = (i.Discount / 100) * itemTotalPrice; - - totalRawPrice += itemTotalPrice; - totalDiscount += itemDiscount; - totalTax += i.igst === "" - ? ((i.sgst + i.cgst) / 100) * (itemTotalPrice - itemDiscount) - : (i.igst / 100) * (itemTotalPrice - itemDiscount); - return null; - }) - - - - const totalPriceAfterTax = (totalRawPrice - totalDiscount) + totalTax; - const totalRoundedOff = Math.abs(totalPriceAfterTax - Math.round(totalPriceAfterTax)); - return ( - { - "TotalRawPrice": parseFloat(totalRawPrice.toFixed(2)), - "TotalDiscountPrice": parseFloat(totalDiscount.toFixed(2)), - "TotalPriceAfterDiscount": parseFloat((totalRawPrice - totalDiscount).toFixed(2)), - "TotalTaxAmount": parseFloat(totalTax.toFixed(2)), - "TotalPriceAfterTax": parseFloat(totalPriceAfterTax.toFixed(2)), - "RoundedOff": parseFloat(totalRoundedOff.toFixed(2)), - "TotalPrice": Math.round(totalPriceAfterTax) - } - ); -} - -export const SummaryDisplayTR: React.FC = (props) => { - const summary = getBasicSummary(props.items); - - return ( - - Total - - - {summary.TotalQuantity} - - - - - - {summary.TotalRawPrice} - - ); -} - -const SummaryDisplay = (props) => { - const summary = getFullSummary(props.items); - - return ( -
-

Summary

- - - - - - - - {summary.TotalDiscountPrice !== 0.00 && - - - - - - } - - - - - - - - {summary.RoundedOff !== 0.00 && - - - - - } - - - - - - -
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; -- cgit v1.2.3