Skip to content

commison on sale #158

Merged
merged 1 commit into from
May 26, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,27 @@ private void updatePreviews() {
Stock current = getViewElement().getCurrentStock();
if (current == null) {
getViewElement().updateCostPreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f, 0f);
return;
}
String text = getViewElement().getQuantityInputField().getText();
if (!Validator.NOT_EMPTY.isValid(text)) {
getViewElement().updateCostPreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f, 0f);
return;
}
try {
BigDecimal quantity = new BigDecimal(text);
if (quantity.compareTo(BigDecimal.ZERO) <= 0) {
getViewElement().updateCostPreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f, 0f);
return;
}
updateCostPreview(current, quantity);
updateSalePreview(current, quantity);
} catch (IllegalArgumentException e) {
getViewElement().updateCostPreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f, 0f);
}
}

Expand Down Expand Up @@ -162,13 +162,13 @@ private void updateSalePreview(final Stock stock,
final BigDecimal quantity) {
List<Share> owned = player.getPortfolio().getShares(stock.getSymbol());
if (owned.isEmpty()) {
getViewElement().updateSalePreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f, 0f);
return;
}
Share ownedPosition = owned.getFirst();
BigDecimal sellQuantity = quantity.min(ownedPosition.getQuantity());
if (sellQuantity.compareTo(BigDecimal.ZERO) <= 0) {
getViewElement().updateSalePreview(0f, 0f);
getViewElement().updateSalePreview(0f, 0f, 0f);
return;
}
Share previewShare = new Share(
Expand All @@ -177,6 +177,7 @@ private void updateSalePreview(final Stock stock,
SaleCalculator calc = new SaleCalculator(previewShare);
getViewElement().updateSalePreview(
calc.calculateTotal().floatValue(),
calc.calculateCommission().floatValue(),
calc.calculateTax().floatValue()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,20 +581,23 @@ public void updateCostPreview(final float cost,
* Updates the sale preview labels, showing how much the
* player would receive on their account if they sold the
* chosen amount of currently owned shares right now
* (gross minus commission and tax), as well as the tax
* part of that calculation on its own.
* (gross minus commission and tax), as well as the
* commission and tax part of that calculation on their own.
*
* @param saleNet the estimated net amount received from
* the sale in NOK (gross - commission - tax).
* @param commission the estimated commission in NOK.
* @param tax the estimated tax in NOK.
* */
public void updateSalePreview(final float saleNet,
final float commission,
final float tax) {
saleTotalPreviewLabel.setText(
"Sale total: " + Math.round(saleNet * 100f) / 100f + " NOK"
);
saleTaxPreviewLabel.setText(
"Tax: " + Math.round(tax * 100f) / 100f + " NOK"
"Commission: " + Math.round(commission * 100f) / 100f + " NOK"
+ " Tax: " + Math.round(tax * 100f) / 100f + " NOK"
);
}

Expand Down