From 9e344283e76fd5e5422f97928cfa37cc5fb7540a Mon Sep 17 00:00:00 2001 From: Diogo Severiano Date: Mon, 11 Nov 2024 15:09:05 +0000 Subject: [PATCH] tweeks --- src/main/java/model/Inventory.java | 4 +++ .../java/records/InventoryManualRequest.java | 2 +- src/main/java/service/AggregatorService.java | 35 +++++++++++++++++-- src/main/java/service/InventoryService.java | 2 ++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/main/java/model/Inventory.java b/src/main/java/model/Inventory.java index 6bdb6c5..efa60d5 100644 --- a/src/main/java/model/Inventory.java +++ b/src/main/java/model/Inventory.java @@ -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; @@ -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; } diff --git a/src/main/java/records/InventoryManualRequest.java b/src/main/java/records/InventoryManualRequest.java index c9e0285..1a49d98 100644 --- a/src/main/java/records/InventoryManualRequest.java +++ b/src/main/java/records/InventoryManualRequest.java @@ -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) { } diff --git a/src/main/java/service/AggregatorService.java b/src/main/java/service/AggregatorService.java index 63f266d..c0f59bf 100644 --- a/src/main/java/service/AggregatorService.java +++ b/src/main/java/service/AggregatorService.java @@ -22,10 +22,12 @@ public class AggregatorService { public List 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) ); } @@ -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"; + } } diff --git a/src/main/java/service/InventoryService.java b/src/main/java/service/InventoryService.java index 5585173..3296340 100644 --- a/src/main/java/service/InventoryService.java +++ b/src/main/java/service/InventoryService.java @@ -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())