maade it so sales display points earned

This commit is contained in:
Alex
2026-04-14 22:33:10 -06:00
parent b7d6adc1cc
commit 2b4fcfe24c
4 changed files with 65 additions and 4 deletions

View File

@@ -111,6 +111,7 @@ public class SaleDetailFragment extends Fragment {
binding.llLoyaltyPoints.setVisibility(View.GONE);
binding.cbUseLoyaltyPoints.setChecked(false);
}
updateTotal();
});
}
@@ -420,6 +421,15 @@ public class SaleDetailFragment extends Fragment {
}
binding.tvSaleDetailTotal.setText("Total: $" + String.format(Locale.getDefault(), "%.2f", total));
CustomerDTO customer = viewModel.getSelectedCustomerData().getValue();
if (customer != null && !viewModel.isViewOnly()) {
int pointsToEarn = total.max(BigDecimal.ZERO).intValue();
binding.tvPointsToEarn.setText("+" + pointsToEarn + " pts");
binding.llPointsToEarn.setVisibility(View.VISIBLE);
} else {
binding.llPointsToEarn.setVisibility(View.GONE);
}
}
private void saveSale() {

View File

@@ -444,6 +444,30 @@
android:textColor="@color/accent_coral"
android:layout_gravity="end"
android:layout_marginTop="12dp"/>
<LinearLayout
android:id="@+id/llPointsToEarn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Points to earn: "
android:textColor="#4ECDC4"
android:textSize="13sp"/>
<TextView
android:id="@+id/tvPointsToEarn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+0 pts"
android:textColor="#4ECDC4"
android:textSize="13sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -199,6 +199,12 @@ public class SaleController {
@FXML
private Label lblLoyaltyDiscount;
@FXML
private HBox hbPointsToEarn;
@FXML
private Label lblPointsToEarn;
private final ObservableList<SaleCartItem> cartItems = FXCollections.observableArrayList();
private final ObservableList<SaleLineItem> saleItems = FXCollections.observableArrayList();
private FilteredList<SaleLineItem> filteredSales;
@@ -389,12 +395,15 @@ public class SaleController {
task.setOnSucceeded(event -> {
selectedCustomerData = task.getValue();
if (selectedCustomerData != null && selectedCustomerData.getLoyaltyPoints() != null && selectedCustomerData.getLoyaltyPoints() >= 20) {
lblLoyaltyPoints.setText(selectedCustomerData.getLoyaltyPoints() + " pts available");
if (selectedCustomerData != null) {
int pts = selectedCustomerData.getLoyaltyPoints() != null ? selectedCustomerData.getLoyaltyPoints() : 0;
lblLoyaltyPoints.setText(pts + " pts available");
lblLoyaltyPoints.setVisible(true);
lblLoyaltyPoints.setManaged(true);
chkUseLoyaltyPoints.setVisible(true);
chkUseLoyaltyPoints.setManaged(true);
boolean canRedeem = pts >= 20;
chkUseLoyaltyPoints.setVisible(canRedeem);
chkUseLoyaltyPoints.setManaged(canRedeem);
if (!canRedeem) chkUseLoyaltyPoints.setSelected(false);
} else {
lblLoyaltyPoints.setVisible(false);
lblLoyaltyPoints.setManaged(false);
@@ -701,6 +710,8 @@ public class SaleController {
hbCouponDiscount.setManaged(false);
hbLoyaltyDiscount.setVisible(false);
hbLoyaltyDiscount.setManaged(false);
hbPointsToEarn.setVisible(false);
hbPointsToEarn.setManaged(false);
cbCustomer.setValue(null);
selectedCustomerData = null;
lblLoyaltyPoints.setVisible(false);
@@ -875,6 +886,16 @@ public class SaleController {
}
lblCartTotal.setText(currency.format(Math.max(0, total.doubleValue())));
if (selectedCustomerData != null) {
int pointsToEarn = (int) Math.max(0, total.doubleValue());
lblPointsToEarn.setText("+" + pointsToEarn + " pts");
hbPointsToEarn.setVisible(true);
hbPointsToEarn.setManaged(true);
} else {
hbPointsToEarn.setVisible(false);
hbPointsToEarn.setManaged(false);
}
}
private BigDecimal calculateCouponDiscount(BigDecimal subtotal) {

View File

@@ -173,6 +173,12 @@
<Label fx:id="lblCartTotal" text="" textFill="#2c3e50"><font><Font name="System Bold" size="16.0" /></font></Label>
</children>
</HBox>
<HBox fx:id="hbPointsToEarn" spacing="8.0" alignment="CENTER_LEFT" visible="false" managed="false">
<children>
<Label text="Points to earn:" textFill="#4ECDC4"><font><Font size="12.0" /></font></Label>
<Label fx:id="lblPointsToEarn" text="+0 pts" textFill="#4ECDC4"><font><Font size="12.0" /></font></Label>
</children>
</HBox>
</children>
</VBox>
<FlowPane hgap="8.0" prefWrapLength="220.0" vgap="8.0">