Skip to content

Commit

Permalink
Refactor setCalculatedFieldsOfMotorcycleStockObjectFromClient private…
Browse files Browse the repository at this point in the history
… helper method [CI]

Refactor code to make it more readable and verbose.
  • Loading branch information
ibardos committed Jul 28, 2024
1 parent 5f3c98c commit 76b0752
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -80,7 +81,13 @@ public void delete(int id) {
private void setCalculatedFieldsOfMotorcycleStockObjectFromClient(MotorcycleStock motorcycleStock) {
BigDecimal purchasingPrice = motorcycleStock.getPurchasingPrice();
Float profitMargin = motorcycleStock.getProfitMargin();
BigDecimal profitOnUnit = BigDecimal.valueOf(Math.ceil(Double.parseDouble(String.valueOf(purchasingPrice.multiply(BigDecimal.valueOf(profitMargin))))/100)*100);

BigDecimal profit = purchasingPrice.multiply(BigDecimal.valueOf(profitMargin));

// Round up to the nearest hundred
BigDecimal profitOnUnit = profit.setScale(0, RoundingMode.CEILING);
profitOnUnit = profitOnUnit.divide(BigDecimal.valueOf(100), 0, RoundingMode.CEILING).multiply(BigDecimal.valueOf(100));

BigDecimal sellingPrice = purchasingPrice.add(profitOnUnit);

motorcycleStock.setProfitOnUnit(profitOnUnit);
Expand Down

0 comments on commit 76b0752

Please sign in to comment.