Skip to content

Commit

Permalink
chore: Update TransacitionComponent based on math changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsa committed May 16, 2026
1 parent b26bdbb commit 6074d58
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.ntnu.idi.idatt.model.transaction.Purchase;
import edu.ntnu.idi.idatt.model.transaction.Sale;
import edu.ntnu.idi.idatt.model.transaction.Transaction;
import edu.ntnu.idi.idatt.service.transaction.PurchaseCalculator;
import edu.ntnu.idi.idatt.service.transaction.SaleCalculator;
import edu.ntnu.idi.idatt.service.transaction.TransactionCalculator;
import edu.ntnu.idi.idatt.view.components.ui.UICompositor;
Expand All @@ -20,7 +21,6 @@ public class TransactionComponent extends VBox {
public TransactionComponent(Transaction transaction) {

Stock stock = transaction.getShare().getStock();
TransactionCalculator calculator = transaction.getCalculator();

Label title;
Label name = new Label(stock.toString());
Expand All @@ -30,18 +30,20 @@ public TransactionComponent(Transaction transaction) {
Label amountOfShares;
Label saleProfit;

totalValue = new Label(String.format("Total: %.2f USD", calculator.calculateTotal()));

taxComissionValue = new Label(String.format(
"Tax & Comission: %.2f USD", calculator.calculateTax().add(calculator.calculateCommision())));

grossValue = new Label(String.format("Gross: %.2f USD", calculator.calculateGross()));

amountOfShares = new Label(
String.format("Shares: %.2f [%s]", transaction.getShare().getQuantity(), stock.getSymbol()));

if (transaction instanceof Purchase) {
title = new Label("PURCHASE");
PurchaseCalculator pCalc = (PurchaseCalculator) transaction.getCalculator();

totalValue = new Label(String.format("Total: %.2f USD", pCalc.calculateTotal()));

taxComissionValue = new Label(String.format(
"Tax & Comission: %.2f USD", pCalc.calculateTax().add(pCalc.calculateCommision())));

grossValue = new Label(String.format("Gross: %.2f USD", pCalc.calculateGross()));

saleProfit = new Label();
CssUtils.apply(title, CssUtils.GREEN);

Expand All @@ -50,9 +52,17 @@ public TransactionComponent(Transaction transaction) {
CssUtils.apply(title, CssUtils.RED);

SaleCalculator sCalc = (SaleCalculator) transaction.getCalculator();

totalValue = new Label(String.format("Total: %.2f USD", sCalc.calculateTotal()));

taxComissionValue = new Label(String.format(
"Tax & Comission: %.2f USD", sCalc.calculateTax().add(sCalc.calculateCommision())));

grossValue = new Label(String.format("Gross: %.2f USD", sCalc.calculateGross()));

saleProfit = new Label(String.format("Profit: %.2f USD", sCalc.calculateProfit()));

CssUtils.apply(saleProfit, CssUtils.generateValueColors(sCalc.calculateProfit().doubleValue()));
CssUtils.apply(saleProfit, CssUtils.generateValueColors(sCalc.calculateProfit()));
}

else {
Expand Down

0 comments on commit 6074d58

Please sign in to comment.