Stevebauman\Inventory\Traits\InventoryTransactionTrait::removePartial PHP Метод

removePartial() публичный Метод

Removes a partial amount of quantity from the inventory. If the transactions previous state was on-hold, no inventory will be removed since the stock was already taken. If the previous state is null or opened, then it will remove the specified quantity from the stock.
public removePartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string
    public function removePartial($quantity, $reason = '', $cost = 0)
    {
        /*
         * If a partial remove is called and quantity is given, then we are removing
         * a partial amount from the on hold transaction. Otherwise we are just processing
         * a transaction for removing a quantity from the current stock
         */
        if ($this->isOnHold()) {
            $current = $this->getAttribute('quantity');
            if ((double) $quantity === (double) $current || $quantity > $current) {
                return $this->removeAll();
            }
            $this->validatePreviousState([$this::STATE_INVENTORY_ON_HOLD], $this::STATE_INVENTORY_REMOVED_PARTIAL);
            $left = (double) $current - (double) $quantity;
            $this->setAttribute('quantity', $left);
            $previousState = $this->getAttribute('state');
            $this->setAttribute('state', $this::STATE_INVENTORY_REMOVED_PARTIAL);
            if ($this->processSave('inventory.transaction.removed.partial')) {
                return $this->returnToPreviousState($previousState);
            }
        } else {
            /*
             * We must be processing a pure removal transaction, make sure
             * previous state was null or opened
             */
            $this->validatePreviousState([null, $this::STATE_OPENED], $this::STATE_INVENTORY_REMOVED);
            $this->setAttribute('state', $this::STATE_INVENTORY_REMOVED);
            $this->setAttribute('quantity', (double) $quantity);
            if (empty($reason)) {
                $reason = $this->getTransactionReason('removed');
            }
            return $this->processStockTakeAndSave($quantity, 'inventory.transaction.removed', $reason, $cost);
        }
        return false;
    }