fix sale and adoption bugs

This commit is contained in:
2026-04-15 15:46:46 -06:00
parent 9c1cbb0ed8
commit 1ab4df0b81
4 changed files with 4 additions and 2 deletions

View File

@@ -40,7 +40,7 @@ public class SaleController {
}
@PostMapping
@PreAuthorize("hasRole('STAFF')")
@PreAuthorize("hasAnyRole('STAFF', 'ADMIN')")
public ResponseEntity<SaleResponse> createSale(@Valid @RequestBody SaleRequest request) {
return ResponseEntity.status(HttpStatus.CREATED).body(saleService.createSale(request));
}

View File

@@ -20,6 +20,7 @@ public class AdoptionRequest {
private Long employeeId;
@NotNull(message = "Source store ID is required")
private Long sourceStoreId;
private String paymentMethod;

View File

@@ -9,6 +9,7 @@ public class SaleItemRequest {
private Long prodId;
@NotNull(message = "Quantity is required")
@Positive(message = "Quantity must be positive")
private Integer quantity;
public Long getProdId() {

View File

@@ -172,7 +172,7 @@ public class SaleService {
BigDecimal refundTotal;
if (originalSubtotal != null && originalSubtotal.compareTo(BigDecimal.ZERO) > 0) {
BigDecimal ratio = subtotalAmount.divide(originalSubtotal, 10, RoundingMode.HALF_UP);
BigDecimal ratio = subtotalAmount.abs().divide(originalSubtotal, 10, RoundingMode.HALF_UP);
refundTotal = originalSale.getTotalAmount().abs().multiply(ratio).negate().setScale(2, RoundingMode.HALF_UP);
if (originalSale.getLoyaltyDiscountAmount() != null) {
loyaltyDiscountRefunded = originalSale.getLoyaltyDiscountAmount().multiply(ratio).setScale(2, RoundingMode.HALF_UP);