PHP Трейт Stevebauman\Inventory\Traits\InventoryTransactionTrait

Наследование: use trait CommonMethodsTrait
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$beforeQuantity string Stores the quantity before an update.
$beforeState string Stores the state before an update.

Открытые методы

Метод Описание
backOrder ( integer | float | string $quantity ) Back-orders the specified amount of quantity on the stock, if stock is sufficient enough for the quantity specified, this will throw an exception. This prevents back-orders being created when unnecessary.
bootInventoryTransactionTrait ( ) : void Overrides the models boot function to generate a new transaction history record when it is created and updated.
cancel ( string $reason = '', integer | float | string $cost ) Cancels any transaction and returns or removes stock depending on the last state.
checkout ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Checks out the specified amount of quantity from the stock, waiting to be sold.
fillBackOrder ( string $reason = '', integer | float | string $cost ) Fills a back order by trying to remove the transaction quantity from the stock. This will return false if there was not enough stock to fill the back order, or an exception occurred.
getByState ( string $state ) : Illuminate\Database\Eloquent\Collection Returns all transactions by the specified state.
getHistory ( ) : mixed Returns the current transaction history.
getLastHistoryRecord ( ) : boolean | mixed Returns the last transaction history record.
getStockRecord ( ) : mixed Returns the current stock record attached to the current transaction.
hasStock ( ) : boolean Returns true/false depending if the current transaction is attached to a stock.
histories ( ) : Illuminate\Database\Eloquent\Relations\HasMany The hasMany histories relationship.
hold ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Holds the specified amount of quantity until it is either used or released.
isBackOrder ( ) : boolean Returns true or false depending if the current state of the transaction is a back order.
isCancelled ( ) : boolean Returns true or false depending if the current state of the transaction is cancelled.
isCheckout ( ) : boolean Returns true or false depending if the current state of the transaction is a checkout.
isOnHold ( ) : boolean Returns true or false depending if the current state of the transaction is on-hold.
isOrder ( ) : boolean Returns true or false depending if the current state of the transaction is an order.
isOrderReceived ( ) : boolean Returns true or false depending if the current state of the transaction is a received order.
isReleased ( ) : boolean Returns true or false depending if the current state of the transaction is released inventory.
isRemoved ( ) : boolean Returns true or false depending if the current state of the transaction is removed inventory.
isReservation ( ) : boolean Returns true or false depending if the current state of the transaction is reserved.
isReturn ( ) : boolean Returns true or false depending if the current state of the transaction is a return.
isSold ( ) : boolean Returns true or false depending if the current state of the transaction is sold.
ordered ( integer | float | string $quantity ) Creates a transaction that specifies the amount of quantity that has been ordered.
postCreate ( ) Generates a transaction history record after a transaction has been created.
postUpdate ( ) Generates a transaction history record when a transaction has been updated.
received ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Marks a transaction as received. If the previous state was ordered then the amount ordered is inserted into the stock. If a quantity is specified then the status of the transaction is set to received-partial, and then returned to ordered with the amount of quantity left to receive.
receivedAll ( string $reason = '', integer | float | string $cost ) Marks an order transaction as received, placing all the quantity from the transaction into the stock.
receivedPartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Marks an order transaction as received-partial, placing the specified quantity into the stock and returning the transaction to the previous ordered state with the remaining stock to receive.
release ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Releases held inventory and inserts it back into the stock. If a quantity is specified and it is lower than the held quantity, than the transaction state will change to released-partial and then returned to the state on-hold with the remainder of the held stock.
releaseAll ( string $reason = '', integer | float | string $cost ) Releases an on-hold inventory transaction, placing all the quantity in the transaction back into the stock.
releasePartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Releases a partial amount of the specified quantity from the transaction and returns it to the previous state.
remove ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Removes the specified quantity from the stock for the current transaction.
removeAll ( ) Permanently removes all of the transaction quantity from the stock. Since the stock was already removed with the on-hold method, the removed state is an 'end of the line' state, and cannot be recovered or reversed.
removePartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) 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.
reserved ( integer | float | string $quantity, boolean $backOrder = false, string $reason = '', integer | float | string $cost ) Reserves the specified amount of quantity for a reservation for commerce.
returned ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Returns the specified amount of quantity back into the stock. A previous state is required to successfully insert the quantity back into the stock, for example, if the stock was sold, or was in checkout, the returned method could be called and the quantity that was sold or was in checkout would be inserted back into the stock. If a quantity is specified and it is less than the amount that was sold/checked-out, then the specified amount is inserted back into the stock and the transaction is reverted to its previous state with the leftover amount.
returnedAll ( string $reason = '', integer | float | string $cost ) Marks a transaction as returned and places the stock that was taken back into the inventory.
returnedPartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) 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.
setQuantityAttribute ( integer | float | string $quantity ) Validates the quantity attribute when it has been set.
setStateAttribute ( string $state ) Verifies if the state being set is valid.
sold ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Marks and removes the specified amount of quantity sold from the stock.
soldAmount ( integer | float | string $quantity, string $reason = '', integer | float | string $cost ) Marks a new or open transaction as sold and removes the amount of the specified quantity from from the inventory stock.
stock ( ) : BelongsTo The belongsTo stock relationship.

Защищенные методы

Метод Описание
checkoutFromReserved ( ) Changes the state of the current transaction to checkout. This will not take any stock from the inventory since a reservation already does this.
generateTransactionHistory ( string $stateBefore, string $stateAfter, integer | float | string $quantityBefore, integer | float | string $quantityAfter ) : boolean | Model Processes generating a transaction history entry.
getAvailableStates ( ) : array Returns an array of available states.
getTransactionReason ( string $key ) : string Returns a default transaction reason from the specified key in the reasons lang file.
processSave ( string $event = '' ) Processes saving the transaction by covering it with a database transaction.
processStockPutAndSave ( integer | float | string $quantity, string $event = '', string $reason = '', integer | float | string $cost ) Processes putting the specified quantity into the current transaction stock and saving the current transaction.
processStockTakeAndSave ( integer | float | string $quantity, string $event = '', string $reason = '', integer | float | string $cost ) Processes removing the specified quantity from transaction stock and saving the current transaction.
reservedFromCheckout ( ) Changes the state of the current transaction to reserved. This will not take any stock from the inventory since a checkout already does this.
returnToPreviousState ( string $previousState ) Returns a transaction to its previous specified state when a returned partial is called. This is to allow a transaction to continue functioning normally since only a partial amount of the transaction was returned, therefore it is still open.
validatePreviousState ( array $allowedStates = [], string $toState ) : boolean Returns true if the current state equals at least one of the allowed states in the array. Throws an exception otherwise.
validateStateIsAvailable ( string $state ) : boolean Returns true if the specified state is valid, throws an exception otherwise.

Описание методов

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

Back-orders the specified amount of quantity on the stock, if stock is sufficient enough for the quantity specified, this will throw an exception. This prevents back-orders being created when unnecessary.
public backOrder ( integer | float | string $quantity )
$quantity integer | float | string

bootInventoryTransactionTrait() публичный статический Метод

Overrides the models boot function to generate a new transaction history record when it is created and updated.
public static bootInventoryTransactionTrait ( ) : void
Результат void

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

Transactions with states of opened, checkout, reserved, back ordered, ordered-pending, and inventory on hold CAN be cancelled Transactions with states such as sold, returned, order-received, and inventory released CAN NOT be cancelled.
public cancel ( string $reason = '', integer | float | string $cost )
$reason string
$cost integer | float | string

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

Checks out the specified amount of quantity from the stock, waiting to be sold.
public checkout ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

checkoutFromReserved() защищенный Метод

Changes the state of the current transaction to checkout. This will not take any stock from the inventory since a reservation already does this.
protected checkoutFromReserved ( )

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

Fills a back order by trying to remove the transaction quantity from the stock. This will return false if there was not enough stock to fill the back order, or an exception occurred.
public fillBackOrder ( string $reason = '', integer | float | string $cost )
$reason string
$cost integer | float | string

generateTransactionHistory() защищенный Метод

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
Результат boolean | Illuminate\Database\Eloquent\Model

getAvailableStates() защищенный Метод

Returns an array of available states.
protected getAvailableStates ( ) : array
Результат array

getByState() публичный статический Метод

Returns all transactions by the specified state.
public static getByState ( string $state ) : Illuminate\Database\Eloquent\Collection
$state string
Результат Illuminate\Database\Eloquent\Collection

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

Returns the current transaction history.
public getHistory ( ) : mixed
Результат mixed

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

Returns the last transaction history record.
public getLastHistoryRecord ( ) : boolean | mixed
Результат boolean | mixed

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

Returns the current stock record attached to the current transaction.
public getStockRecord ( ) : mixed
Результат mixed

getTransactionReason() защищенный Метод

Returns a default transaction reason from the specified key in the reasons lang file.
protected getTransactionReason ( string $key ) : string
$key string
Результат string

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

Returns true/false depending if the current transaction is attached to a stock.
public hasStock ( ) : boolean
Результат boolean

histories() абстрактный публичный Метод

The hasMany histories relationship.
abstract public histories ( ) : Illuminate\Database\Eloquent\Relations\HasMany
Результат Illuminate\Database\Eloquent\Relations\HasMany

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

Holds the specified amount of quantity until it is either used or released.
public hold ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

Returns true or false depending if the current state of the transaction is a back order.
public isBackOrder ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is cancelled.
public isCancelled ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is a checkout.
public isCheckout ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is on-hold.
public isOnHold ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is an order.
public isOrder ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is a received order.
public isOrderReceived ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is released inventory.
public isReleased ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is removed inventory.
public isRemoved ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is reserved.
public isReservation ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is a return.
public isReturn ( ) : boolean
Результат boolean

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

Returns true or false depending if the current state of the transaction is sold.
public isSold ( ) : boolean
Результат boolean

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

The received or cancel method must be used after this is performed.
public ordered ( integer | float | string $quantity )
$quantity integer | float | string

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

Generates a transaction history record after a transaction has been created.
public postCreate ( )

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

Generates a transaction history record when a transaction has been updated.
public postUpdate ( )

processSave() защищенный Метод

Processes saving the transaction by covering it with a database transaction.
protected processSave ( string $event = '' )
$event string

processStockPutAndSave() защищенный Метод

Processes putting the specified quantity into the current transaction stock and saving the current transaction.
protected processStockPutAndSave ( integer | float | string $quantity, string $event = '', string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$event string
$reason string
$cost integer | float | string

processStockTakeAndSave() защищенный Метод

Processes removing the specified quantity from transaction stock and saving the current transaction.
protected processStockTakeAndSave ( integer | float | string $quantity, string $event = '', string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$event string
$reason string
$cost integer | float | string

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

Marks a transaction as received. If the previous state was ordered then the amount ordered is inserted into the stock. If a quantity is specified then the status of the transaction is set to received-partial, and then returned to ordered with the amount of quantity left to receive.
public received ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

Marks an order transaction as received, placing all the quantity from the transaction into the stock.
public receivedAll ( string $reason = '', integer | float | string $cost )
$reason string
$cost integer | float | string

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

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

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

Releases held inventory and inserts it back into the stock. If a quantity is specified and it is lower than the held quantity, than the transaction state will change to released-partial and then returned to the state on-hold with the remainder of the held stock.
public release ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

Releases an on-hold inventory transaction, placing all the quantity in the transaction back into the stock.
public releaseAll ( string $reason = '', integer | float | string $cost )
$reason string
$cost integer | float | string

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

Releases a partial amount of the specified quantity from the transaction and returns it to the previous state.
public releasePartial ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

If the transaction state is current on-hold, and a quantity is given then a partial-remove will be triggered and the remaining quantity will be on-hold. If no quantity is given, then this will set the transaction state to removed and the stock will be permanently removed from the current stock. If the transaction state was open or null, and a quantity is given, then the specified quantity is permanently removed from the stock.
public remove ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

Permanently removes all of the transaction quantity from the stock. Since the stock was already removed with the on-hold method, the removed state is an 'end of the line' state, and cannot be recovered or reversed.
public removeAll ( )

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

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

If backOrder is true then the state will be set to back-order if the specified quantity is unavailable to be reserved. Otherwise it will throw an exception. If reserved is called from being checked out we'll make sure we don't take any inventory.
public reserved ( integer | float | string $quantity, boolean $backOrder = false, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$backOrder boolean
$reason string
$cost integer | float | string

reservedFromCheckout() защищенный Метод

Changes the state of the current transaction to reserved. This will not take any stock from the inventory since a checkout already does this.
protected reservedFromCheckout ( )

returnToPreviousState() защищенный Метод

Returns a transaction to its previous specified state when a returned partial is called. This is to allow a transaction to continue functioning normally since only a partial amount of the transaction was returned, therefore it is still open.
protected returnToPreviousState ( string $previousState )
$previousState string

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

Returns the specified amount of quantity back into the stock. A previous state is required to successfully insert the quantity back into the stock, for example, if the stock was sold, or was in checkout, the returned method could be called and the quantity that was sold or was in checkout would be inserted back into the stock. If a quantity is specified and it is less than the amount that was sold/checked-out, then the specified amount is inserted back into the stock and the transaction is reverted to its previous state with the leftover amount.
public returned ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

Marks a transaction as returned and places the stock that was taken back into the inventory.
public returnedAll ( string $reason = '', integer | float | string $cost )
$reason string
$cost integer | float | string

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

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

Validates the quantity attribute when it has been set.
public setQuantityAttribute ( integer | float | string $quantity )
$quantity integer | float | string

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

Verifies if the state being set is valid.
public setStateAttribute ( string $state )
$state string

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

If no quantity is specified and the previous state was not in checkout, reserved, back ordered, returned or returned partial, this will throw an exception.
public sold ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

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

Marks a new or open transaction as sold and removes the amount of the specified quantity from from the inventory stock.
public soldAmount ( integer | float | string $quantity, string $reason = '', integer | float | string $cost )
$quantity integer | float | string
$reason string
$cost integer | float | string

stock() абстрактный публичный Метод

The belongsTo stock relationship.
abstract public stock ( ) : BelongsTo
Результат Illuminate\Database\Eloquent\Relations\BelongsTo

validatePreviousState() защищенный Метод

Returns true if the current state equals at least one of the allowed states in the array. Throws an exception otherwise.
protected validatePreviousState ( array $allowedStates = [], string $toState ) : boolean
$allowedStates array
$toState string
Результат boolean

validateStateIsAvailable() защищенный Метод

Returns true if the specified state is valid, throws an exception otherwise.
protected validateStateIsAvailable ( string $state ) : boolean
$state string
Результат boolean

Описание свойств

$beforeQuantity защищенное свойство

Stores the quantity before an update.
protected string $beforeQuantity
Результат string

$beforeState защищенное свойство

Stores the state before an update.
protected string $beforeState
Результат string