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

generateTransactionHistory() protected method

Processes generating a transaction history entry.
protected generateTransactionHistory ( string $stateBefore, string $stateAfter, integer | float | string $quantityBefore, integer | float | string $quantityAfter ) : boolean | Model
$stateBefore string
$stateAfter string
$quantityBefore integer | float | string
$quantityAfter integer | float | string
return boolean | Illuminate\Database\Eloquent\Model
    protected function generateTransactionHistory($stateBefore, $stateAfter, $quantityBefore = 0, $quantityAfter = 0)
    {
        $history = $this->histories()->getRelated()->newInstance();
        $history->setAttribute('transaction_id', $this->getKey());
        $history->setAttribute('state_before', $stateBefore);
        $history->setAttribute('state_after', $stateAfter);
        $history->setAttribute('quantity_before', $quantityBefore);
        $history->setAttribute('quantity_after', $quantityAfter);
        if ($history->save()) {
            return $history;
        }
        return false;
    }