Stevebauman\Inventory\Traits\InventoryTransactionTrait::releasePartial PHP Method

releasePartial() public method

Releases a partial amount of the specified quantity from the transaction and returns it to the previous state.
public releasePartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string
    public function releasePartial($quantity, $reason = '', $cost = 0)
    {
        $current = $this->getAttribute('quantity');
        if ((double) $quantity === (double) $current || $quantity > $current) {
            return $this->releaseAll($reason, $cost);
        }
        $this->validatePreviousState([$this::STATE_INVENTORY_ON_HOLD], $this::STATE_INVENTORY_RELEASED);
        $left = (double) $current - (double) $quantity;
        $this->setAttribute('quantity', $left);
        $previousState = $this->getAttribute('state');
        $this->setAttribute('state', $this::STATE_INVENTORY_RELEASED_PARTIAL);
        if (empty($reason)) {
            $reason = $this->getTransactionReason('released-partial');
        }
        if ($this->processStockPutAndSave($quantity, 'inventory.transaction.released.partial', $reason, $cost)) {
            return $this->returnToPreviousState($previousState);
        }
        return false;
    }