Merge branch 'loyalty-points'
This commit is contained in:
@@ -206,15 +206,12 @@ public class SaleDetailFragment extends Fragment {
|
|||||||
binding.llEmployeeDiscount.setVisibility(View.GONE);
|
binding.llEmployeeDiscount.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sale.getPointsDiscountAmount() != null && sale.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (sale.getLoyaltyDiscountAmount() != null && sale.getLoyaltyDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
binding.llLoyaltyDiscount.setVisibility(View.VISIBLE);
|
|
||||||
binding.tvSaleLoyaltyDiscount.setText("-$" + String.format(Locale.getDefault(), "%.2f", sale.getPointsDiscountAmount()));
|
|
||||||
if (sale.getPointsUsed() != null) {
|
|
||||||
binding.tvLoyaltyDiscountLabel.setText("Loyalty Discount (" + sale.getPointsUsed() + " pts):");
|
|
||||||
}
|
|
||||||
} else if (sale.getLoyaltyDiscountAmount() != null && sale.getLoyaltyDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
||||||
binding.llLoyaltyDiscount.setVisibility(View.VISIBLE);
|
binding.llLoyaltyDiscount.setVisibility(View.VISIBLE);
|
||||||
binding.tvSaleLoyaltyDiscount.setText("-$" + String.format(Locale.getDefault(), "%.2f", sale.getLoyaltyDiscountAmount()));
|
binding.tvSaleLoyaltyDiscount.setText("-$" + String.format(Locale.getDefault(), "%.2f", sale.getLoyaltyDiscountAmount()));
|
||||||
|
if (sale.getPointsUsed() != null && sale.getPointsUsed() > 0) {
|
||||||
|
binding.tvLoyaltyDiscountLabel.setText("Loyalty Discount (" + sale.getPointsUsed() + " pts):");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.llLoyaltyDiscount.setVisibility(View.GONE);
|
binding.llLoyaltyDiscount.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class SaleResponse {
|
|||||||
private BigDecimal employeeDiscountAmount;
|
private BigDecimal employeeDiscountAmount;
|
||||||
private BigDecimal loyaltyDiscountAmount;
|
private BigDecimal loyaltyDiscountAmount;
|
||||||
private Integer pointsEarned;
|
private Integer pointsEarned;
|
||||||
|
private Integer pointsUsed;
|
||||||
private String channel;
|
private String channel;
|
||||||
private Long couponId;
|
private Long couponId;
|
||||||
private Long cartId;
|
private Long cartId;
|
||||||
@@ -145,6 +146,14 @@ public class SaleResponse {
|
|||||||
this.pointsEarned = pointsEarned;
|
this.pointsEarned = pointsEarned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getPointsUsed() {
|
||||||
|
return pointsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPointsUsed(Integer pointsUsed) {
|
||||||
|
this.pointsUsed = pointsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
public String getChannel() {
|
public String getChannel() {
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ public class Sale {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer pointsEarned = 0;
|
private Integer pointsEarned = 0;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Integer pointsUsed = 0;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "sale", cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "sale", cascade = CascadeType.ALL)
|
||||||
private List<SaleItem> items = new ArrayList<>();
|
private List<SaleItem> items = new ArrayList<>();
|
||||||
|
|
||||||
@@ -224,6 +227,14 @@ public class Sale {
|
|||||||
this.pointsEarned = pointsEarned;
|
this.pointsEarned = pointsEarned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getPointsUsed() {
|
||||||
|
return pointsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPointsUsed(Integer pointsUsed) {
|
||||||
|
this.pointsUsed = pointsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
public List<SaleItem> getItems() {
|
public List<SaleItem> getItems() {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ public class SaleService {
|
|||||||
sale.setEmployeeDiscountAmount(BigDecimal.ZERO);
|
sale.setEmployeeDiscountAmount(BigDecimal.ZERO);
|
||||||
sale.setLoyaltyDiscountAmount(loyaltyDiscountRefunded);
|
sale.setLoyaltyDiscountAmount(loyaltyDiscountRefunded);
|
||||||
sale.setPointsEarned(0);
|
sale.setPointsEarned(0);
|
||||||
|
sale.setPointsUsed(0);
|
||||||
} else {
|
} else {
|
||||||
if (request.getItems() == null || request.getItems().isEmpty()) {
|
if (request.getItems() == null || request.getItems().isEmpty()) {
|
||||||
throw new BusinessException("At least one item is required");
|
throw new BusinessException("At least one item is required");
|
||||||
@@ -254,6 +255,7 @@ public class SaleService {
|
|||||||
pointsDeducted = toPointsUsed(loyaltyDiscount);
|
pointsDeducted = toPointsUsed(loyaltyDiscount);
|
||||||
}
|
}
|
||||||
sale.setLoyaltyDiscountAmount(loyaltyDiscount);
|
sale.setLoyaltyDiscountAmount(loyaltyDiscount);
|
||||||
|
sale.setPointsUsed(pointsDeducted);
|
||||||
|
|
||||||
BigDecimal finalTotal = subtotalAmount.subtract(couponDiscount).subtract(employeeDiscount).subtract(loyaltyDiscount);
|
BigDecimal finalTotal = subtotalAmount.subtract(couponDiscount).subtract(employeeDiscount).subtract(loyaltyDiscount);
|
||||||
sale.setTotalAmount(finalTotal.max(BigDecimal.ZERO));
|
sale.setTotalAmount(finalTotal.max(BigDecimal.ZERO));
|
||||||
@@ -376,6 +378,7 @@ public class SaleService {
|
|||||||
response.setEmployeeDiscountAmount(sale.getEmployeeDiscountAmount());
|
response.setEmployeeDiscountAmount(sale.getEmployeeDiscountAmount());
|
||||||
response.setLoyaltyDiscountAmount(sale.getLoyaltyDiscountAmount());
|
response.setLoyaltyDiscountAmount(sale.getLoyaltyDiscountAmount());
|
||||||
response.setPointsEarned(sale.getPointsEarned());
|
response.setPointsEarned(sale.getPointsEarned());
|
||||||
|
response.setPointsUsed(sale.getPointsUsed());
|
||||||
response.setChannel(sale.getChannel());
|
response.setChannel(sale.getChannel());
|
||||||
if (sale.getCoupon() != null) {
|
if (sale.getCoupon() != null) {
|
||||||
response.setCouponId(sale.getCoupon().getCouponId());
|
response.setCouponId(sale.getCoupon().getCouponId());
|
||||||
|
|||||||
@@ -841,6 +841,7 @@ public class SaleController {
|
|||||||
double subtotal = sale.getSubtotalAmount() != null ? sale.getSubtotalAmount().doubleValue() : 0.0;
|
double subtotal = sale.getSubtotalAmount() != null ? sale.getSubtotalAmount().doubleValue() : 0.0;
|
||||||
double couponDiscount = sale.getCouponDiscountAmount() != null ? sale.getCouponDiscountAmount().doubleValue() : 0.0;
|
double couponDiscount = sale.getCouponDiscountAmount() != null ? sale.getCouponDiscountAmount().doubleValue() : 0.0;
|
||||||
double loyaltyDiscount = sale.getLoyaltyDiscountAmount() != null ? sale.getLoyaltyDiscountAmount().doubleValue() : 0.0;
|
double loyaltyDiscount = sale.getLoyaltyDiscountAmount() != null ? sale.getLoyaltyDiscountAmount().doubleValue() : 0.0;
|
||||||
|
int pointsUsed = sale.getPointsUsed() != null ? sale.getPointsUsed() : 0;
|
||||||
return new SaleDetail(
|
return new SaleDetail(
|
||||||
sale.getSaleId().intValue(),
|
sale.getSaleId().intValue(),
|
||||||
sale.getSaleDate(),
|
sale.getSaleDate(),
|
||||||
@@ -852,7 +853,8 @@ public class SaleController {
|
|||||||
sale.getCustomerName(),
|
sale.getCustomerName(),
|
||||||
subtotal,
|
subtotal,
|
||||||
couponDiscount,
|
couponDiscount,
|
||||||
loyaltyDiscount
|
loyaltyDiscount,
|
||||||
|
pointsUsed
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class SaleDetailDialogController {
|
|||||||
@FXML private javafx.scene.layout.HBox hbDetailCouponDiscount;
|
@FXML private javafx.scene.layout.HBox hbDetailCouponDiscount;
|
||||||
@FXML private Label lblDetailCouponDiscount;
|
@FXML private Label lblDetailCouponDiscount;
|
||||||
@FXML private javafx.scene.layout.HBox hbDetailLoyaltyDiscount;
|
@FXML private javafx.scene.layout.HBox hbDetailLoyaltyDiscount;
|
||||||
|
@FXML private Label lblDetailLoyaltyDiscountTitle;
|
||||||
@FXML private Label lblDetailLoyaltyDiscount;
|
@FXML private Label lblDetailLoyaltyDiscount;
|
||||||
@FXML private Label lblTotal;
|
@FXML private Label lblTotal;
|
||||||
@FXML private Button btnRefund;
|
@FXML private Button btnRefund;
|
||||||
@@ -86,6 +87,11 @@ public class SaleDetailDialogController {
|
|||||||
|
|
||||||
if (sale.getLoyaltyDiscountAmount() > 0.001) {
|
if (sale.getLoyaltyDiscountAmount() > 0.001) {
|
||||||
lblDetailLoyaltyDiscount.setText("-" + currency.format(sale.getLoyaltyDiscountAmount()));
|
lblDetailLoyaltyDiscount.setText("-" + currency.format(sale.getLoyaltyDiscountAmount()));
|
||||||
|
if (sale.getPointsUsed() > 0) {
|
||||||
|
lblDetailLoyaltyDiscountTitle.setText("Loyalty Discount (" + sale.getPointsUsed() + " pts):");
|
||||||
|
} else {
|
||||||
|
lblDetailLoyaltyDiscountTitle.setText("Loyalty Discount:");
|
||||||
|
}
|
||||||
hbDetailLoyaltyDiscount.setVisible(true);
|
hbDetailLoyaltyDiscount.setVisible(true);
|
||||||
hbDetailLoyaltyDiscount.setManaged(true);
|
hbDetailLoyaltyDiscount.setManaged(true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ public class SaleDetail {
|
|||||||
private final double subtotalAmount;
|
private final double subtotalAmount;
|
||||||
private final double couponDiscountAmount;
|
private final double couponDiscountAmount;
|
||||||
private final double loyaltyDiscountAmount;
|
private final double loyaltyDiscountAmount;
|
||||||
|
private final int pointsUsed;
|
||||||
|
|
||||||
public SaleDetail(int saleId, LocalDateTime saleDate, double totalAmount, String paymentMethod, String employeeName, boolean refund, ObservableList<SaleDetailItem> items, String customerName, double subtotalAmount, double couponDiscountAmount, double loyaltyDiscountAmount) {
|
public SaleDetail(int saleId, LocalDateTime saleDate, double totalAmount, String paymentMethod, String employeeName, boolean refund, ObservableList<SaleDetailItem> items, String customerName, double subtotalAmount, double couponDiscountAmount, double loyaltyDiscountAmount, int pointsUsed) {
|
||||||
this.saleId = saleId;
|
this.saleId = saleId;
|
||||||
this.saleDate = saleDate;
|
this.saleDate = saleDate;
|
||||||
this.totalAmount = totalAmount;
|
this.totalAmount = totalAmount;
|
||||||
@@ -28,6 +29,7 @@ public class SaleDetail {
|
|||||||
this.subtotalAmount = subtotalAmount;
|
this.subtotalAmount = subtotalAmount;
|
||||||
this.couponDiscountAmount = couponDiscountAmount;
|
this.couponDiscountAmount = couponDiscountAmount;
|
||||||
this.loyaltyDiscountAmount = loyaltyDiscountAmount;
|
this.loyaltyDiscountAmount = loyaltyDiscountAmount;
|
||||||
|
this.pointsUsed = pointsUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSaleId() {
|
public int getSaleId() {
|
||||||
@@ -74,6 +76,10 @@ public class SaleDetail {
|
|||||||
return loyaltyDiscountAmount;
|
return loyaltyDiscountAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPointsUsed() {
|
||||||
|
return pointsUsed;
|
||||||
|
}
|
||||||
|
|
||||||
public static class SaleDetailItem {
|
public static class SaleDetailItem {
|
||||||
private final int prodId;
|
private final int prodId;
|
||||||
private final String productName;
|
private final String productName;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<HBox fx:id="hbDetailLoyaltyDiscount" spacing="8.0" alignment="CENTER_RIGHT" visible="false" managed="false">
|
<HBox fx:id="hbDetailLoyaltyDiscount" spacing="8.0" alignment="CENTER_RIGHT" visible="false" managed="false">
|
||||||
<children>
|
<children>
|
||||||
<Label text="Loyalty Discount:" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
|
<Label fx:id="lblDetailLoyaltyDiscountTitle" text="Loyalty Discount:" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
|
||||||
<Label fx:id="lblDetailLoyaltyDiscount" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
|
<Label fx:id="lblDetailLoyaltyDiscount" textFill="#27ae60"><font><Font size="12.0" /></font></Label>
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
|||||||
Reference in New Issue
Block a user