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

receivedPartial() public method

If the quantity specified is greater or equal to the amount ordered, this will mark the transaction as received all and place the quantity of the transaction into the stock.
public receivedPartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string
    public function receivedPartial($quantity, $reason = '', $cost = 0)
    {
        $current = $this->getAttribute('quantity');
        if ((double) $quantity === (double) $current || $quantity > $current) {
            return $this->receivedAll($reason, $cost);
        }
        // Only allow the previous state of ordered
        $this->validatePreviousState([$this::STATE_ORDERED_PENDING], $this::STATE_ORDERED_RECEIVED_PARTIAL);
        // Get the left over amount of quantity still to be received
        $left = (double) $current - (double) $quantity;
        $this->setAttribute('quantity', $left);
        $previousState = $this->getAttribute('state');
        $this->setAttribute('state', $this::STATE_ORDERED_RECEIVED_PARTIAL);
        if (empty($reason)) {
            $reason = $this->getTransactionReason('received-partial');
        }
        if ($this->processStockPutAndSave($left, 'inventory.transaction.received.partial', $reason, $cost)) {
            return $this->returnToPreviousState($previousState);
        }
        return false;
    }