1. Go to this page and download the library: Download aldeebhasan/inventorix library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aldeebhasan / inventorix example snippets
use Aldeebhasan\Inventorix\Traits\HasInventory;
class Product extends Model
{
use HasInventory;
}
use Aldeebhasan\Inventorix\DTOs\StockOperationDto;
// Add stock
$product->addStock(quantity: 100, location: $location);
// Deduct stock
$product->deductStock(quantity: 10, location: $location);
// Set stock to an absolute quantity (reconciliation)
$product->adjustStock(newQuantity: 50, location: $location);
// Transfer between locations
$product->transfer(quantity: 20, from: $warehouseA, to: $warehouseB);
$options = new StockOperationDto(
transaction: $existingTransaction, // attach to an open bulk transaction
causable: $order, // the model that caused this operation
cost: 9.99, // explicit cost per unit (null = no cost, false = use model's cost_price)
note: 'Purchase order #123',
createdBy: auth()->id(),
allowNegative: true, // allow stock to go below zero for this call
expiresAt: now()->addHours(2), // reservation TTL
serials: ['SN-001', 'SN-002'], // explicit serial numbers
lotReference: 'LOT-2024-01',
externalReference: 'PO-9876',
reasonCode: 'purchase',
);
$product->addStock(100, $location, $options);
use Aldeebhasan\Inventorix\Facades\Inventorix;
$transaction = Inventorix::bulk(function ($transaction) use ($product, $location) {
$options = new StockOperationDto(transaction: $transaction);
$product->addStock(50, $location, $options);
$anotherProduct->deductStock(5, $location, $options);
});
// Reserve stock
$reservation = $product->reserve(quantity: 5, location: $location);
// Release the reservation (stock returns to available)
$product->releaseReservation($reservation);
// Fulfill the reservation (converts reserved stock to a real deduction)
$product->fulfillReservation($reservation);
// Stock record at a specific location
$stock = $product->stockAt($location);
// Totals (optionally scoped to a location, with or without child locations)
$product->totalStock();
$product->totalStock($location, uct->stockSummary($location);
// Returns: total_quantity, reserved_quantity, available_quantity, locations[], is_low_stock, last_movement_at
// Value of on-hand stock for this product (uses configured costing strategy)
$product->stockValuation($location);
// Total valuation across all stockables or scoped to a location
Inventorix::totalValuation($location);
// Valuation of movements caused by a specific model
Inventorix::valuationByCausable($order);
// Average units deducted per day over the last N days
$product->stockVelocity($location, days: 30);
// How many days until stock runs out at current velocity
$product->daysOfStock($location, velocityDays: 30);
// The calendar day with the highest deductions in the last N days
$product->peakDemandDay($location, days: 90);
// Set a low-stock threshold for a product at a location
$product->setStockThreshold(location: $location, minQuantity: 10, maxQuantity: 500);
// Manually trigger threshold evaluation
$product->checkThresholds($location);
Inventorix::lowStockItems($location); // scoped to a location
Inventorix::lowStockItems(stockableType: Product::class); // all products
$product->addStock(2, $location, new StockOperationDto(serials: ['SN-A1', 'SN-A2']));
$product->deductStock(1, $location, new StockOperationDto(serials: ['SN-A1']));
$reservation = $product->reserve(1, $location, new StockOperationDto(serials: ['SN-A2']));
use Aldeebhasan\Inventorix\Facades\Inventorix;
Inventorix::beforeAdd(function ($stockable, $quantity, $location, $dto) {
// called before every addStock
});
Inventorix::afterAdd(function ($stock, $movement) {
// called after every addStock
});
Inventorix::beforeDeduct(function ($stockable, $quantity, $location, $dto) { });
Inventorix::afterDeduct(function ($stock, $movement) { });
use Aldeebhasan\Inventorix\Enums\CostingStrategy;
class Product extends Model
{
use HasInventory;
public function inventorixCostingStrategy(): CostingStrategy
{
return CostingStrategy::Average;
}
}