PHP Trait Stevebauman\Inventory\Traits\InventoryStockTrait

Inheritance: use trait CommonMethodsTrait
Datei anzeigen Open project: stevebauman/inventory

Public Properties

Property Type Description
$cost integer | float | string Stores the cost for updating a stock.
$reason string Stores the reason for updating / creating a stock.

Protected Properties

Property Type Description
$beforeQuantity integer | float | string Stores the quantity before an update.

Public Methods

Method Description
add ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Alias for put function.
bootInventoryStockTrait ( ) Overrides the models boot function to set the user ID automatically to every new record.
getLastMovement ( ) : boolean | Model Returns the last movement on the current stock record.
getMovement ( integer | string | Model $movement ) : mixed Returns a movement depending on the specified argument. If an object is supplied, it is checked if it is an instance of an eloquent model. If a numeric value is entered, it is retrieved by it's ID.
hasEnoughStock ( integer | float | string $quantity ) : boolean Returns true if there is enough stock for the specified quantity being taken.
item ( ) : BelongsTo The belongsTo item relationship.
location ( ) : Illuminate\Database\Eloquent\Relations\HasOne The hasOne location relationship.
moveTo ( Model $location ) : boolean Moves a stock to the specified location.
movements ( ) : Illuminate\Database\Eloquent\Relations\HasMany The hasMany movements relationship.
newTransaction ( string $name = '' ) : Model Creates and returns a new un-saved stock transaction instance with the current stock ID attached.
postCreate ( ) : void Generates a stock movement after a stock is created.
postUpdate ( ) : void Generates a stock movement after a stock is updated.
put ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Processes a 'put' operation on the current stock.
remove ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Removes the specified quantity from the current stock.
rollback ( mixed $movement = null, boolean $recursive = false ) Rolls back the last movement, or the movement specified. If recursive is set to true, it will rollback all movements leading up to the movement specified.
rollbackMovement ( mixed $movement, boolean $recursive = false ) Rolls back a specific movement.
take ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Processes a 'take' operation on the current stock.
transactions ( ) : Illuminate\Database\Eloquent\Relations\HasMany The hasMany transactions relationship.
updateQuantity ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Performs a quantity update. Automatically determining depending on the quantity entered if stock is being taken or added.

Protected Methods

Method Description
allowDuplicateMovementsEnabled ( ) : boolean Returns true/false from the configuration file determining whether or not stock movements can have the same before and after quantities.
generateStockMovement ( integer | float | string $before, integer | float | string $after, string $reason = '', integer | float | string $cost ) : boolean | Model Creates a new stock movement record.
getMovementById ( integer | string $id ) : null | Model Retrieves a movement by the specified ID.
processMoveOperation ( Model $location ) : boolean Processes the stock moving from it's current location, to the specified location.
processPutOperation ( integer | float | string $putting, string $reason = '', integer | float | string $cost ) Processes adding quantity to current stock.
processRecursiveRollbackOperation ( Model $movement ) : array Processes a recursive rollback operation.
processRollbackOperation ( Model $movement, boolean $recursive = false ) Processes a single rollback operation.
processTakeOperation ( integer | float | string $taking, string $reason = '', integer | float | string $cost ) Processes removing quantity from the current stock.
processUpdateQuantityOperation ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Processes a quantity update operation.
reverseCost ( ) Reverses the cost of a movement.
rollbackCostEnabled ( ) : boolean Returns true/false from the configuration file determining whether or not to rollback costs when a rollback occurs on a stock.
setCost ( integer | float | string $cost ) Sets the cost attribute.
setReason ( string $reason = '' ) Sets the reason attribute.

Method Details

add() public method

Alias for put function.
public add ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

allowDuplicateMovementsEnabled() protected method

Returns true/false from the configuration file determining whether or not stock movements can have the same before and after quantities.

bootInventoryStockTrait() public static method

Overrides the models boot function to set the user ID automatically to every new record.
public static bootInventoryStockTrait ( )

generateStockMovement() protected method

Creates a new stock movement record.
protected generateStockMovement ( integer | float | string $before, integer | float | string $after, string $reason = '', integer | float | string $cost ) : boolean | Model
$before integer | float | string
$after integer | float | string
$reason string
$cost integer | float | string
return boolean | Illuminate\Database\Eloquent\Model

getLastMovement() public method

Returns the last movement on the current stock record.
public getLastMovement ( ) : boolean | Model
return boolean | Illuminate\Database\Eloquent\Model

getMovement() public method

Returns a movement depending on the specified argument. If an object is supplied, it is checked if it is an instance of an eloquent model. If a numeric value is entered, it is retrieved by it's ID.
public getMovement ( integer | string | Model $movement ) : mixed
$movement integer | string | Illuminate\Database\Eloquent\Model
return mixed

getMovementById() protected method

Retrieves a movement by the specified ID.
protected getMovementById ( integer | string $id ) : null | Model
$id integer | string
return null | Illuminate\Database\Eloquent\Model

hasEnoughStock() public method

Throws NotEnoughStockException otherwise.
public hasEnoughStock ( integer | float | string $quantity ) : boolean
$quantity integer | float | string
return boolean

item() abstract public method

The belongsTo item relationship.
abstract public item ( ) : BelongsTo
return Illuminate\Database\Eloquent\Relations\BelongsTo

location() abstract public method

The hasOne location relationship.
abstract public location ( ) : Illuminate\Database\Eloquent\Relations\HasOne
return Illuminate\Database\Eloquent\Relations\HasOne

moveTo() public method

Moves a stock to the specified location.
public moveTo ( Model $location ) : boolean
$location Illuminate\Database\Eloquent\Model
return boolean

movements() abstract public method

The hasMany movements relationship.
abstract public movements ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany

newTransaction() public method

Creates and returns a new un-saved stock transaction instance with the current stock ID attached.
public newTransaction ( string $name = '' ) : Model
$name string
return Illuminate\Database\Eloquent\Model

postCreate() public method

Generates a stock movement after a stock is created.
public postCreate ( ) : void
return void

postUpdate() public method

Generates a stock movement after a stock is updated.
public postUpdate ( ) : void
return void

processMoveOperation() protected method

Processes the stock moving from it's current location, to the specified location.
protected processMoveOperation ( Model $location ) : boolean
$location Illuminate\Database\Eloquent\Model
return boolean

processPutOperation() protected method

Processes adding quantity to current stock.
protected processPutOperation ( integer | float | string $putting, string $reason = '', integer | float | string $cost )
$putting integer | float | string
$reason string
$cost integer | float | string

processRecursiveRollbackOperation() protected method

Processes a recursive rollback operation.
protected processRecursiveRollbackOperation ( Model $movement ) : array
$movement Illuminate\Database\Eloquent\Model
return array

processRollbackOperation() protected method

Processes a single rollback operation.
protected processRollbackOperation ( Model $movement, boolean $recursive = false )
$movement Illuminate\Database\Eloquent\Model
$recursive boolean

processTakeOperation() protected method

Processes removing quantity from the current stock.
protected processTakeOperation ( integer | float | string $taking, string $reason = '', integer | float | string $cost )
$taking integer | float | string
$reason string
$cost integer | float | string

processUpdateQuantityOperation() protected method

Processes a quantity update operation.
protected processUpdateQuantityOperation ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

put() public method

Processes a 'put' operation on the current stock.
public put ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

remove() public method

Removes the specified quantity from the current stock.
public remove ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

reverseCost() protected method

Reverses the cost of a movement.
protected reverseCost ( )

rollback() public method

Rolls back the last movement, or the movement specified. If recursive is set to true, it will rollback all movements leading up to the movement specified.
public rollback ( mixed $movement = null, boolean $recursive = false )
$movement mixed
$recursive boolean

rollbackCostEnabled() protected method

Returns true/false from the configuration file determining whether or not to rollback costs when a rollback occurs on a stock.
protected rollbackCostEnabled ( ) : boolean
return boolean

rollbackMovement() public method

Rolls back a specific movement.
public rollbackMovement ( mixed $movement, boolean $recursive = false )
$movement mixed
$recursive boolean

setCost() protected method

Sets the cost attribute.
protected setCost ( integer | float | string $cost )
$cost integer | float | string

setReason() protected method

Sets the reason attribute.
protected setReason ( string $reason = '' )
$reason string

take() public method

Processes a 'take' operation on the current stock.
public take ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

transactions() abstract public method

The hasMany transactions relationship.
abstract public transactions ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany

updateQuantity() public method

Performs a quantity update. Automatically determining depending on the quantity entered if stock is being taken or added.
public updateQuantity ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

Property Details

$beforeQuantity protected_oe property

Stores the quantity before an update.
protected int|float|string $beforeQuantity
return integer | float | string

$cost public_oe property

Stores the cost for updating a stock.
public int|float|string $cost
return integer | float | string

$reason public_oe property

Stores the reason for updating / creating a stock.
public string $reason
return string