Skip to content

Commit

Permalink
tweeks
Browse files Browse the repository at this point in the history
  • Loading branch information
drseveriano committed Nov 11, 2024
1 parent 16f0744 commit 9e34428
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/model/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Inventory extends AuditEntity implements Serializable {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Item item;

private String batch;

@ManyToOne(fetch = FetchType.LAZY)
private Supplier supplier;

Expand All @@ -46,6 +48,8 @@ public class Inventory extends AuditEntity implements Serializable {
@Column(nullable = false)
private BigDecimal costPrice = BigDecimal.ZERO;

private BigDecimal salePrice = BigDecimal.ZERO;

private String notes;

}
2 changes: 1 addition & 1 deletion src/main/java/records/InventoryManualRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
public record InventoryManualRequest(Integer itemId, Supplier supplier, Warehouse warehouse,
InventoryType inventoryType, int quantity,
int minQuantity, boolean alertLowStock, Integer unitId,
BigDecimal costPrice, String notes) {
BigDecimal costPrice, String notes, String batch, BigDecimal salePrice) {
}
35 changes: 33 additions & 2 deletions src/main/java/service/AggregatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class AggregatorService {
public List<StatisticCard> getStatistics() {
return List.of(
createStatisticCard("Inventory Items", getTotalNumberOfItems(), "ri-box-1-fill", "primary", false),
createStatisticCard("(Stock) Finished Products", getTotalNumberOfFinishedProducts(), "ri-beer-line", "success", false),
createStatisticCard("Stock (Beer) Items", getTotalNumberOfFinishedProducts(), "ri-beer-line", "success", false),
createStatisticCard("Purchase Orders (Pendind Delivery)", getTotalNumberOfPurchaseOrdersPendingDelivery(), "ri-ship-2-line", "info", false),
createStatisticCard("Inventory Alerts", getTotalNumberOfInventoryAlerts(), "ri-alert-line", "error", false),
createStatisticCard("Inventory Price", getInventoryTotalPrice(), "ri-money-euro-circle-line", "info", true)
createStatisticCard("Inventory Price", getInventoryTotalPrice(), "ri-money-euro-circle-line", "info", true),
createStatisticCard("Stock Price", getStockPrice(), "ri-money-euro-circle-line", "info", true),
createStatisticCard("Potential Profit", getPotentialProfit(), "ri-money-euro-circle-line", "warning", true)
);
}

Expand Down Expand Up @@ -84,4 +86,33 @@ private String getInventoryTotalPrice() {

return "0";
}

private String getStockPrice() {
if (warehouseService.getDefaultWarehouse().isPresent()) {
return "" + inventoryService.findAll().stream()
.filter(inventory -> inventory.getInventoryType().equals(InventoryType.FINISHED_PRODUCT))
.map(inventory -> inventory.getCostPrice()
.multiply(BigDecimal.valueOf(inventory.getQuantity()))
.setScale(2, RoundingMode.HALF_UP))
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

return "0";
}

private String getPotentialProfit() {
if (warehouseService.getDefaultWarehouse().isPresent()) {
return "" + inventoryService.findAll().stream()
.filter(inventory -> inventory.getInventoryType().equals(InventoryType.FINISHED_PRODUCT) &&
inventory.getSalePrice() != null)
.map(inventory -> inventory.getSalePrice()
.multiply(BigDecimal.valueOf(inventory.getQuantity()))
.setScale(2, RoundingMode.HALF_UP))
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

return "0";
}
}
2 changes: 2 additions & 0 deletions src/main/java/service/InventoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class InventoryService {
@Transactional
public boolean createManualEntryOnInventory(InventoryManualRequest request) {
Inventory.builder()
.salePrice(request.salePrice())
.supplier(request.supplier())
.batch(request.batch())
.warehouse(request.warehouse())
.item(itemService.findById(request.itemId()))
.inventoryType(request.inventoryType())
Expand Down

0 comments on commit 9e34428

Please sign in to comment.