fix loyalty points display

This commit is contained in:
2026-04-15 15:49:47 -06:00
parent 4f564acd2b
commit 8b473c19f8
8 changed files with 44 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ public class SaleResponse {
private BigDecimal employeeDiscountAmount;
private BigDecimal loyaltyDiscountAmount;
private Integer pointsEarned;
private Integer pointsUsed;
private String channel;
private Long couponId;
private Long cartId;
@@ -145,6 +146,14 @@ public class SaleResponse {
this.pointsEarned = pointsEarned;
}
public Integer getPointsUsed() {
return pointsUsed;
}
public void setPointsUsed(Integer pointsUsed) {
this.pointsUsed = pointsUsed;
}
public String getChannel() {
return channel;
}

View File

@@ -73,6 +73,9 @@ public class Sale {
@Column(nullable = false)
private Integer pointsEarned = 0;
@Column(nullable = false)
private Integer pointsUsed = 0;
@OneToMany(mappedBy = "sale", cascade = CascadeType.ALL)
private List<SaleItem> items = new ArrayList<>();
@@ -224,6 +227,14 @@ public class Sale {
this.pointsEarned = pointsEarned;
}
public Integer getPointsUsed() {
return pointsUsed;
}
public void setPointsUsed(Integer pointsUsed) {
this.pointsUsed = pointsUsed;
}
public List<SaleItem> getItems() {
return items;
}

View File

@@ -200,6 +200,7 @@ public class SaleService {
sale.setEmployeeDiscountAmount(BigDecimal.ZERO);
sale.setLoyaltyDiscountAmount(loyaltyDiscountRefunded);
sale.setPointsEarned(0);
sale.setPointsUsed(0);
} else {
if (request.getItems() == null || request.getItems().isEmpty()) {
throw new BusinessException("At least one item is required");
@@ -254,6 +255,7 @@ public class SaleService {
pointsDeducted = toPointsUsed(loyaltyDiscount);
}
sale.setLoyaltyDiscountAmount(loyaltyDiscount);
sale.setPointsUsed(pointsDeducted);
BigDecimal finalTotal = subtotalAmount.subtract(couponDiscount).subtract(employeeDiscount).subtract(loyaltyDiscount);
sale.setTotalAmount(finalTotal.max(BigDecimal.ZERO));
@@ -376,6 +378,7 @@ public class SaleService {
response.setEmployeeDiscountAmount(sale.getEmployeeDiscountAmount());
response.setLoyaltyDiscountAmount(sale.getLoyaltyDiscountAmount());
response.setPointsEarned(sale.getPointsEarned());
response.setPointsUsed(sale.getPointsUsed());
response.setChannel(sale.getChannel());
if (sale.getCoupon() != null) {
response.setCouponId(sale.getCoupon().getCouponId());