BF stock calculation
This commit is contained in:
parent
0bb3b63a32
commit
ab8ea6afec
|
|
@ -3,8 +3,8 @@
|
|||
# Laravel Shop
|
||||
|
||||
[](https://github.com/blax-software/laravel-shop/actions/workflows/tests.yml)
|
||||
[](#testing)
|
||||
[](#testing)
|
||||
[](#testing)
|
||||
[](#testing)
|
||||
[](https://packagist.org/packages/blax-software/laravel-shop)
|
||||
[](https://packagist.org/packages/blax-software/laravel-shop)
|
||||
[](https://packagist.org/packages/blax-software/laravel-shop)
|
||||
|
|
@ -192,7 +192,7 @@ booking, Stripe sync and the event surface — so host applications can lean
|
|||
on the behaviour with confidence.
|
||||
|
||||
```
|
||||
Tests: 1228, Assertions: 3291
|
||||
Tests: 1349, Assertions: 3641
|
||||
```
|
||||
|
||||
CI runs the full suite on every push (see the badge above). To run it
|
||||
|
|
|
|||
|
|
@ -663,7 +663,7 @@ class Product extends Model implements Purchasable, Cartable
|
|||
// Use base stock at the START of the booking period and subtract all overlapping reservations
|
||||
// We check availability at $from because claims that expire before then should not affect availability
|
||||
// Note: overlappingBookings is already negative (DECREASE entries), so we add it
|
||||
$availableStock = $this->getAvailableStock($from) - abs($overlappingClaims) + $overlappingBookings;
|
||||
$availableStock = $this->getAvailableStock($from) - abs((int) $overlappingClaims) + (int) $overlappingBookings;
|
||||
|
||||
return $availableStock >= $quantity;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -503,7 +503,9 @@ trait HasStocks
|
|||
*/
|
||||
public function getCurrentlyClaimedStock(): int
|
||||
{
|
||||
return abs($this->stocks()
|
||||
// SQL SUM comes back as a numeric string under PDO mysql; cast
|
||||
// before abs() so strict types accept it.
|
||||
return abs((int) $this->stocks()
|
||||
->whereIn('type', StockType::claimTypeValues())
|
||||
->where('status', StockStatus::PENDING->value)
|
||||
->willExpire()
|
||||
|
|
@ -523,7 +525,7 @@ trait HasStocks
|
|||
*/
|
||||
public function getActiveAndPlannedClaimedStock(): int
|
||||
{
|
||||
return abs($this->stocks()
|
||||
return abs((int) $this->stocks()
|
||||
->whereIn('type', StockType::claimTypeValues())
|
||||
->where('status', StockStatus::PENDING->value)
|
||||
->willExpire()
|
||||
|
|
@ -552,7 +554,7 @@ trait HasStocks
|
|||
});
|
||||
}
|
||||
|
||||
return abs($query->sum('quantity'));
|
||||
return abs((int) $query->sum('quantity'));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ trait MayBePoolProduct
|
|||
|
||||
// Get available stock at the START of the booking period
|
||||
// This ensures claims that will expire before the booking starts don't reduce availability
|
||||
$available = max(0, $item->getAvailableStock($from) - abs($overlappingClaims));
|
||||
$available = max(0, $item->getAvailableStock($from) - abs((int) $overlappingClaims));
|
||||
}
|
||||
} elseif (!$item->isBooking()) {
|
||||
$available = $item->getAvailableStock();
|
||||
|
|
|
|||
Loading…
Reference in New Issue