Stock Management

Tracking inventory balances and creating stock.

Stock Control

The Stock Service (Obelaw\Wms\Services\StockService) manages the quantity of items stored in specific locations. It supports any polymorphic stockable model (like Product or Asset).

Checking Balances

Use getBalance to see the aggregated stock state for a specific item in a specific location.

use Obelaw\Wms\Facades\WMS;

$balance = WMS::stocks()->getBalance($product, $locationId);

The result is an array containing the counts for different statuses:

[
    'available' => 120, // Ready to be picked
    'reserved' => 5,    // Held for orders
    'sold' => 10        // Processed but not yet shipped/archived
]

Creating Stock (Inbound)

When new stock arrives, create a record linking the stockable item to a location. This creates a Stock parent record and generates individual ProductSerial records for each unit.

$stock = WMS::stocks()->create(
    stockable: $product,
    locationId: $warehouseId,
    quantity: 50,
    serials: [] // Optional: provide specific serial numbers
);

If serials are omitted, the system generates unique identifiers automatically based on the stockable ID.

Finding Stock

$stock = WMS::stocks()->find($id);