Prefill refund dialog

This commit is contained in:
2026-03-10 21:59:48 -06:00
parent d58801e51f
commit bbc28bef47
3 changed files with 24 additions and 0 deletions

View File

@@ -51,4 +51,11 @@ public class SaleItemResponse {
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getLineTotal() {
if (unitPrice == null || quantity == null) {
return BigDecimal.ZERO;
}
return unitPrice.multiply(BigDecimal.valueOf(quantity));
}
}

View File

@@ -371,6 +371,7 @@ public class SaleController {
private void openRefundDialog() {
try {
SaleLineItem selectedSale = tvSales.getSelectionModel().getSelectedItem();
FXMLLoader loader = new FXMLLoader(getClass().getResource(
"/org/example/petshopdesktop/dialogviews/refund-dialog-view.fxml"));
Stage dialog = new Stage();
@@ -378,6 +379,10 @@ public class SaleController {
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.setTitle("Process Refund");
dialog.setScene(new Scene(loader.load()));
if (selectedSale != null) {
loader.<org.example.petshopdesktop.controllers.dialogcontrollers.RefundDialogController>getController()
.prefillSale((long) selectedSale.getSaleId());
}
dialog.setResizable(false);
dialog.showAndWait();

View File

@@ -114,6 +114,18 @@ public class RefundDialogController {
@FXML
void btnLoadSaleClicked(ActionEvent event) {
loadSale();
}
public void prefillSale(Long saleId) {
if (saleId == null) {
return;
}
txtSaleId.setText(String.valueOf(saleId));
loadSale();
}
private void loadSale() {
String saleIdText = txtSaleId.getText().trim();
if (saleIdText.isEmpty()) {
showError("Load Sale", "Enter a transaction ID.");