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

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

Marks a transaction as partially returned and returns the specified quantity back into the stock. If the transaction quantity is greater or equal to the specified quantity then a full return is processed.
public returnedPartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string
    public function returnedPartial($quantity, $reason = '', $cost = 0)
    {
        $current = $this->getAttribute('quantity');
        if ((double) $quantity === (double) $current || $quantity > $current) {
            return $this->returnedAll($reason, $cost);
        }
        /*
         * Only allow partial returns when the transaction state is
         * sold, reserved, checkout, or returned partial
         */
        $this->validatePreviousState([$this::STATE_COMMERCE_SOLD, $this::STATE_COMMERCE_RESERVED, $this::STATE_COMMERCE_CHECKOUT, $this::STATE_COMMERCE_RETURNED_PARTIAL], $this::STATE_COMMERCE_RETURNED_PARTIAL);
        // Retrieve the previous state for returning the transaction to it's original state
        $previousState = $this->getAttribute('state');
        // Set a new state so a history record is created
        $this->setAttribute('state', $this::STATE_COMMERCE_RETURNED_PARTIAL);
        // Set the new left-over quantity from removing the amount returned
        $left = (double) $current - (double) $quantity;
        $this->setAttribute('quantity', $left);
        if (empty($reason)) {
            $reason = $this->getTransactionReason('returned-partial');
        }
        if ($this->processStockPutAndSave($quantity, 'inventory.transaction.returned.partial', $reason, $cost)) {
            return $this->returnToPreviousState($previousState);
        }
        return false;
    }