fix sale and adoption bugs
This commit is contained in:
@@ -40,7 +40,7 @@ public class SaleController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@PreAuthorize("hasRole('STAFF')")
|
@PreAuthorize("hasAnyRole('STAFF', 'ADMIN')")
|
||||||
public ResponseEntity<SaleResponse> createSale(@Valid @RequestBody SaleRequest request) {
|
public ResponseEntity<SaleResponse> createSale(@Valid @RequestBody SaleRequest request) {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(saleService.createSale(request));
|
return ResponseEntity.status(HttpStatus.CREATED).body(saleService.createSale(request));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public class AdoptionRequest {
|
|||||||
|
|
||||||
private Long employeeId;
|
private Long employeeId;
|
||||||
|
|
||||||
|
@NotNull(message = "Source store ID is required")
|
||||||
private Long sourceStoreId;
|
private Long sourceStoreId;
|
||||||
|
|
||||||
private String paymentMethod;
|
private String paymentMethod;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ public class SaleItemRequest {
|
|||||||
private Long prodId;
|
private Long prodId;
|
||||||
|
|
||||||
@NotNull(message = "Quantity is required")
|
@NotNull(message = "Quantity is required")
|
||||||
|
@Positive(message = "Quantity must be positive")
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
|
|
||||||
public Long getProdId() {
|
public Long getProdId() {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ public class SaleService {
|
|||||||
BigDecimal refundTotal;
|
BigDecimal refundTotal;
|
||||||
|
|
||||||
if (originalSubtotal != null && originalSubtotal.compareTo(BigDecimal.ZERO) > 0) {
|
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);
|
refundTotal = originalSale.getTotalAmount().abs().multiply(ratio).negate().setScale(2, RoundingMode.HALF_UP);
|
||||||
if (originalSale.getLoyaltyDiscountAmount() != null) {
|
if (originalSale.getLoyaltyDiscountAmount() != null) {
|
||||||
loyaltyDiscountRefunded = originalSale.getLoyaltyDiscountAmount().multiply(ratio).setScale(2, RoundingMode.HALF_UP);
|
loyaltyDiscountRefunded = originalSale.getLoyaltyDiscountAmount().multiply(ratio).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|||||||
Reference in New Issue
Block a user