diff --git a/README.md b/README.md
index 728f1dc4..0ac6c3fa 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,5 @@
# Inventory
-[](https://travis-ci.org/stevebauman/inventory)
-[](https://scrutinizer-ci.com/g/stevebauman/inventory/?branch=master)
-[](https://insight.sensiolabs.com/projects/69e0abf0-cd74-4d4d-b40c-e943c4a7eea9)
-[](https://packagist.org/packages/stevebauman/inventory)
-[](https://packagist.org/packages/stevebauman/inventory)
-[](https://packagist.org/packages/stevebauman/inventory)
-
-## Index
-
-[](https://gitter.im/stevebauman/inventory?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-
-
Description
diff --git a/composer.json b/composer.json
index 0320274e..196c890a 100644
--- a/composer.json
+++ b/composer.json
@@ -1,19 +1,18 @@
{
- "name": "stevebauman/inventory",
+ "name": "trexology/laravel-inventory",
"description": "Inventory management using Laravel 4 / 5",
"keywords": ["laravel", "inventory", "inventory-management"],
"authors": [
{
- "name": "Steve Bauman",
- "email": "steven_bauman@outlook.com"
+ "name": "Trex Lim",
+ "email": "trexlim@gmail.com"
}
],
"license": "MIT",
"require": {
- "php": ">=5.4.0",
- "illuminate/database": "5.*",
- "illuminate/support": "5.*",
- "baum/baum": "1.1.*"
+ "php": "^7.1.3 || ^8.0",
+ "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0",
+ "baum/baum": "^2.0@alpha"
},
"require-dev": {
"orchestra/testbench": "3.1.*"
@@ -23,14 +22,23 @@
},
"autoload": {
"psr-4": {
- "Stevebauman\\Inventory\\": "src/"
+ "Trexology\\Inventory\\": "src/"
}
},
"autoload-dev":
{
"psr-4": {
- "Stevebauman\\Inventory\\Tests\\": "tests/"
+ "Trexology\\Inventory\\Tests\\": "tests/"
}
},
- "minimum-stability": "stable"
+ "minimum-stability": "stable",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Trexology\\Inventory\\InventoryServiceProvider"
+ ],
+ "aliases": {
+ }
+ }
+ }
}
diff --git a/docs/ASSEMBLIES.md b/docs/ASSEMBLIES.md
index 690d126c..4ef2d53e 100644
--- a/docs/ASSEMBLIES.md
+++ b/docs/ASSEMBLIES.md
@@ -153,7 +153,7 @@ When adding parts to your items assembly, you have to make sure you're aware of
#### InvalidPartException
-The exception `Stevebauman\Inventory\Exceptions\InvalidPartException` is thrown when you try to add a part to an assembly
+The exception `Trexology\Inventory\Exceptions\InvalidPartException` is thrown when you try to add a part to an assembly
that contains itself. This exception prevents infinite recursive queries. For example:
$tables = Inventory::create([
@@ -222,7 +222,7 @@ resource intensive on larger assemblies. However this validation is completely n
#### InvalidQuantityException
-As such when managing stock quantities, you will receive an `Stevebauman\Inventory\Exceptions\InvalidQuantityException` if
+As such when managing stock quantities, you will receive an `Trexology\Inventory\Exceptions\InvalidQuantityException` if
and invalid quantity is entered inside any assembly methods that accept a quantity, for example:
// All below methods throw InvalidQuantityException
diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md
index 724a5f29..a7bafee5 100644
--- a/docs/INSTALLATION.md
+++ b/docs/INSTALLATION.md
@@ -5,52 +5,52 @@ multiple cascade delete paths are present on foreign keys, and you'll need to mo
### Installation (Laravel 4)
-Add inventory to your `composer.json` file:
+Run the following command:
- "stevebauman/inventory" : "1.7.*"
+ composer require trexology/laravel-inventory
Now perform a `composer update` on your project's source.
Then insert the service provider in your `app/config/app.php` config file:
- 'Stevebauman\Inventory\InventoryServiceProvider'
+ 'Trexology\Inventory\InventoryServiceProvider'
If you want to customize the database tables, you can publish the migration and run it yourself:
- php artisan migrate:publish stevebauman/inventory
+ php artisan migrate:publish trexology/laravel-inventory
And then run the migration:
php artisan migrate
-
+
Otherwise you can run the install command:
php artisan inventory:install
-
+
Be sure to publish the configuration if you'd like to customize inventory:
-
- php artisan config:publish stevebauman/inventory
-
+
+ php artisan config:publish trexology/laravel-inventory
+
### Installation (Laravel 5)
-Add inventory to your `composer.json` file:
+Run the following command:
- "stevebauman/inventory" : "1.7.*"
+ composer require trexology/laravel-inventory
Now perform a `composer update` on your project's source.
-Then insert the service provider in your `config/app.php` config file:
+Then insert the service provider in your `config/app.php` config file: (Skip this step if you are on 5.5 and above)
+
+ 'Trexology\Inventory\InventoryServiceProvider'
- 'Stevebauman\Inventory\InventoryServiceProvider'
-
Either publish the assets to customize the database tables using:
php artisan vendor:publish
-
+
And then run the migrations:
php artisan migrate
-
+
Or use the inventory install command:
php artisan inventory:install
@@ -63,8 +63,8 @@ If you don't need to create & customize your models, I've included pre-built mod
If you'd like to use them you'll have include them in your use statements:
- use Stevebauman\Inventory\Models\Inventory;
-
+ use Trexology\Inventory\Models\Inventory;
+
class InventoryController extends BaseController
{
/*
@@ -73,16 +73,16 @@ If you'd like to use them you'll have include them in your use statements:
* @var Inventory
*/
protected $inventory;
-
+
public function __construct(Inventory $inventory)
{
$this->inventory = $inventory;
}
-
+
public function create()
{
$item = new $this->inventory;
-
+
// etc...
}
}
@@ -97,51 +97,51 @@ Create the models, but keep in mind the models need:
You are free to modify anything else (such as table names, model names, namespace etc!).
-Metric:
+InventoryMetric:
- class Metric extends Model
+ class InventoryMetric extends Model
{
protected $table = 'metrics';
}
-
+
Location:
-
+
use Baum\Node;
-
- class Location extends Node
+
+ class Location extends Node
{
protected $table = 'locations';
}
-Category:
+InventoryCategory:
- use Stevebauman\Inventory\Traits\CategoryTrait;
+ use Trexology\Inventory\Traits\CategoryTrait;
use Baum\Node;
-
- class Category extends Node
+
+ class InventoryCategory extends Node
{
use CategoryTrait;
-
+
protected $table = 'categories';
-
+
protected $scoped = ['belongs_to'];
-
+
public function inventories()
{
return $this->hasMany('Inventory', 'category_id');
}
}
-Supplier:
+InventorySupplier:
- use Stevebauman\Inventory\Traits\SupplierTrait;
-
- class Supplier extends BaseModel
+ use Trexology\Inventory\Traits\SupplierTrait;
+
+ class InventorySupplier extends BaseModel
{
use SupplierTrait;
-
+
protected $table = 'suppliers';
-
+
public function items()
{
return $this->belongsToMany('Inventory', 'inventory_suppliers', 'supplier_id')->withTimestamps();
@@ -150,81 +150,81 @@ Supplier:
Inventory:
- use Stevebauman\Inventory\Traits\AssemblyTrait;
- use Stevebauman\Inventory\Traits\InventoryTrait;
- use Stevebauman\Inventory\Traits\InventoryVariantTrait;
-
+ use Trexology\Inventory\Traits\AssemblyTrait;
+ use Trexology\Inventory\Traits\InventoryTrait;
+ use Trexology\Inventory\Traits\InventoryVariantTrait;
+
class Inventory extends Model
{
use InventoryTrait;
use InventoryVariantTrait;
use AssemblyTrait;
-
+
protected $table = 'inventories';
-
+
public function category()
{
return $this->hasOne('Category', 'id', 'category_id');
}
-
+
public function metric()
{
return $this->hasOne('Metric', 'id', 'metric_id');
}
-
+
public function sku()
{
return $this->hasOne('InventorySku', 'inventory_id', 'id');
}
-
+
public function stocks()
{
return $this->hasMany('InventoryStock', 'inventory_id');
}
-
+
public function suppliers()
{
return $this->belongsToMany('Supplier', 'inventory_suppliers', 'inventory_id')->withTimestamps();
}
-
+
public function assemblies()
{
return $this->belongsToMany($this, 'inventory_assemblies', 'inventory_id', 'part_id')
->withPivot(['quantity'])->withTimestamps();
}
}
-
+
InventorySku:
- use Stevebauman\Inventory\Traits\InventorySkuTrait;
-
+ use Trexology\Inventory\Traits\InventorySkuTrait;
+
class InventorySku extends Model
{
use InventorySkuTrait;
-
+
protected $table = 'inventory_skus';
-
+
protected $fillable = array(
'inventory_id',
'code',
);
-
+
public function item()
{
return $this->belongsTo('Inventory', 'inventory_id', 'id');
}
}
-
+
InventoryStock:
- use Stevebauman\Inventory\Traits\InventoryStockTrait;
-
+ use Trexology\Inventory\Traits\InventoryStockTrait;
+
class InventoryStock extends Model
{
use InventoryStockTrait;
-
+
protected $table = 'inventory_stocks';
-
+
protected $fillable = array(
'inventory_id',
'location_id',
@@ -233,7 +233,7 @@ InventoryStock:
'row',
'bin',
);
-
+
public function item()
{
return $this->belongsTo('Inventory', 'inventory_id', 'id');
@@ -243,12 +243,12 @@ InventoryStock:
{
return $this->hasMany('InventoryStockMovement', 'stock_id');
}
-
+
public function transactions()
{
return $this->hasMany('InventoryTransaction', 'stock_id', 'id');
}
-
+
public function location()
{
return $this->hasOne('Location', 'id', 'location_id');
@@ -257,14 +257,14 @@ InventoryStock:
InventoryStockMovement:
- use Stevebauman\Inventory\Traits\InventoryStockMovementTrait;
-
+ use Trexology\Inventory\Traits\InventoryStockMovementTrait;
+
class InventoryStockMovement extends Model
{
use InventoryStockMovementTrait;
-
+
protected $table = 'inventory_stock_movements';
-
+
protected $fillable = array(
'stock_id',
'user_id',
@@ -273,24 +273,24 @@ InventoryStockMovement:
'cost',
'reason',
);
-
+
public function stock()
{
return $this->belongsTo('InventoryStock', 'stock_id', 'id');
}
}
-
+
InventoryTransaction:
-
- use Stevebauman\Inventory\Traits\InventoryTransactionTrait;
- use Stevebauman\Inventory\Interfaces\StateableInterface;
-
+
+ use Trexology\Inventory\Traits\InventoryTransactionTrait;
+ use Trexology\Inventory\Interfaces\StateableInterface;
+
class InventoryTransaction extends BaseModel implements StateableInterface
{
use InventoryTransactionTrait;
-
+
protected $table = 'inventory_transactions';
-
+
protected $fillable = array(
'user_id',
'stock_id',
@@ -298,7 +298,7 @@ InventoryTransaction:
'state',
'quantity',
);
-
+
public function stock()
{
return $this->belongsTo('InventoryStock', 'stock_id', 'id');
@@ -309,17 +309,17 @@ InventoryTransaction:
return $this->hasMany('InventoryTransactionHistory', 'transaction_id', 'id');
}
}
-
+
InventoryTransactionHistory:
- use Stevebauman\Inventory\Traits\InventoryTransactionHistoryTrait;
-
+ use Trexology\Inventory\Traits\InventoryTransactionHistoryTrait;
+
class InventoryTransactionHistory extends BaseModel
{
use InventoryTransactionHistoryTrait;
-
+
protected $table = 'inventory_transaction_histories';
-
+
protected $fillable = array(
'user_id',
'transaction_id',
@@ -328,7 +328,7 @@ InventoryTransactionHistory:
'quantity_before',
'quantity_after',
);
-
+
public function transaction()
{
return $this->belongsTo('InventoryTransaction', 'transaction_id', 'id');
diff --git a/docs/TRANSACTIONS.md b/docs/TRANSACTIONS.md
index 8ae35e5a..226fea66 100644
--- a/docs/TRANSACTIONS.md
+++ b/docs/TRANSACTIONS.md
@@ -253,7 +253,7 @@ You also can not mix inventory orders with inventory holds/releasing/remo
Transactions must be kept within their 'scope of use', and a new transaction must be created if a new operation
needs to take place.
-With any method that requires a quantity, a `Stevebauman\Inventory\Exceptions\InvalidQuantityException` will be thrown
+With any method that requires a quantity, a `Trexology\Inventory\Exceptions\InvalidQuantityException` will be thrown
if the quantity supplied is invalid. For example, these would all throw the above exception:
$transaction->reserved('120 pieces');
@@ -261,7 +261,7 @@ if the quantity supplied is invalid. For example, these would all throw the abov
$transaction->reserved('a120');
$transaction->reserved('12..0');
-With any method that requires a removal of stock from the inventory, a `Stevebauman\Inventory\Exceptions\NotEnoughStockException` will
+With any method that requires a removal of stock from the inventory, a `Trexology\Inventory\Exceptions\NotEnoughStockException` will
be thrown if the quantity supplied is over the amount inside the current stock. For example, these would all throw the above exception:
$stock->put(100);
@@ -281,16 +281,16 @@ These are easy to guard against however, you can just place the transaction meth
try
{
$transaction->reserve($quantity);
- } catch(Stevebauman\Inventory\Exceptions\InvalidQuantityException $e)
+ } catch(Trexology\Inventory\Exceptions\InvalidQuantityException $e)
{
return 'Invalid quantity was supplied. Please enter a valid quantity.';
- } catch(Stevebauman\Inventory\Exceptions\NotEnoughStockException $e)
+ } catch(Trexology\Inventory\Exceptions\NotEnoughStockException $e)
{
return "There wasn't enough stock to reserve: $quantity";
}
States can be set manually, however it's definitely not recommended. Setting a state manually may throw an
-`Stevebauman\Inventory\Exceptions\InvalidTransactionStateException`, if the state is not one of the constants
+`Trexology\Inventory\Exceptions\InvalidTransactionStateException`, if the state is not one of the constants
shown above. For example:
// This will fail
diff --git a/docs/UPDATES.md b/docs/UPDATES.md
index 31ec6494..fbd885f2 100644
--- a/docs/UPDATES.md
+++ b/docs/UPDATES.md
@@ -32,7 +32,7 @@ If you have modified the migrations and ran them yourself, you will have
##### Laravel 4:
- php artisan migrate:publish --package="stevebauman/inventory"
+ php artisan migrate:publish --package="trexology/laravel-inventory"
##### Laravel 5:
@@ -86,7 +86,7 @@ If you're using custom migrations you will need to re-publish the inventory migr
##### Laravel 4:
- php artisan migrate:publish --package="stevebauman/inventory"
+ php artisan migrate:publish --package="trexology/laravel-inventory"
##### Laravel 5:
@@ -116,7 +116,7 @@ If you have customized the included migrations, you'll have to publish the new o
##### Laravel 4:
- php artisan migrate:publish --package="stevebauman/inventory"
+ php artisan migrate:publish --package="trexology/laravel-inventory"
##### Laravel 5:
@@ -139,7 +139,7 @@ Now you're good to go to use the new update!
No migrations were added to this release, you can jump to `1.5.*` with no issues.
-However, the exception `Stevebauman\Inventory\Exceptions\StockIsSufficientException` has been removed.
+However, the exception `Trexology\Inventory\Exceptions\StockIsSufficientException` has been removed.
It is no longer thrown when there is enough stock for a back-order. Simply remove it from your
try/catch statement.
@@ -154,7 +154,7 @@ Follow standard update migration procedure:
##### Laravel 4:
- php artisan migrate:publish --package="stevebauman/inventory"
+ php artisan migrate:publish --package="trexology/laravel-inventory"
##### Laravel 5:
@@ -166,7 +166,7 @@ Then run the migration using:
If you're using your own models, be sure to insert the new trait on your `Inventory` model:
- use Stevebauman\Inventory\Traits\InventoryVariantTrait;
+ use Trexology\Inventory\Traits\InventoryVariantTrait;
class Inventory extends Eloquent {
use InventoryVariantTrait;
@@ -178,7 +178,7 @@ If you're using the built in models, it's already included.
In update `1.7`, assembly functionality has been added. This update comes with 2 new migrations, and a new trait.
-The new trait added is named `Stevebauman\Inventory\Traits\AssemblyTrait`. This trait will need to be inserted into
+The new trait added is named `Trexology\Inventory\Traits\AssemblyTrait`. This trait will need to be inserted into
your `Inventory` model if you wish to use the assembly functionality.
The first migration adds the column `is_assembly (bool)` to your `inventories` table. It is defaulted to `false`.
@@ -190,7 +190,7 @@ These migrations are non-destructive, so follow the standard update procedure:
##### Laravel 4:
- php artisan migrate:publish --package="stevebauman/inventory"
+ php artisan migrate:publish --package="trexology/laravel-inventory"
##### Laravel 5:
@@ -202,9 +202,9 @@ Then run the migration using:
Once you've ran the migrations, insert the new Assembly trait into your inventory model:
- use Stevebauman\Inventory\Traits\AssemblyTrait;
- use Stevebauman\Inventory\Traits\InventoryVariantTrait;
- use Stevebauman\Inventory\Traits\InventoryTrait;
+ use Trexology\Inventory\Traits\AssemblyTrait;
+ use Trexology\Inventory\Traits\InventoryVariantTrait;
+ use Trexology\Inventory\Traits\InventoryTrait;
class Inventory extends Eloquent
{
diff --git a/docs/USAGE.md b/docs/USAGE.md
index e4622c34..3a96d0fd 100644
--- a/docs/USAGE.md
+++ b/docs/USAGE.md
@@ -3,62 +3,62 @@
First you'll have to create a metric that your Inventory is measured by:
$metric = new Metric;
-
+
$metric->name = 'Litres';
$metric->symbol = 'L';
$metric->save();
-
+
Now, create a category to store the inventory record under:
$category = new Category;
-
+
$category->name = 'Drinks';
$category->save();
-
+
Then, you'll create an inventory record, and assign the metric and category we just created:
-
+
$item = new Inventory;
-
+
$item->metric_id = $metric->id;
$item->category_id = $category->id;
$item->name = 'Milk';
$item->description = 'Delicious milk';
$item->save();
-
+
Now we have our inventory item created. We have to add stock, but to add stock we need to create a Location to bind the stock to:
$location = new Location;
-
+
$location->name = 'Warehouse';
$location->save();
#### Creating and Adding Stock
Now we can add stock to our inventory by supplying a number (int or string), and the location (Location object):
-
+
/*
* Creating a stock will automatically create a stock movement, no matter which method is used below.
*/
-
+
$item->createStockOnLocation(20, $location);
-
+
/*
- * Or instantiate a new stock. This will automatically
+ * Or instantiate a new stock. This will automatically
* assign the location ID and inventory ID to the new stock
* record so we don't have to.
*/
-
+
$stock = $item->newStockOnLocation($location);
$stock->quantity = 20;
$stock->cost = '5.20';
$stock->reason = 'I bought some';
$stock->save();
-
+
/*
* Or we can create a stock manually.
* If you want to set the cost and reason for the creation of the stock, be sure to do so
*/
-
+
$stock = new InventoryStock;
$stock->inventory_id = $item->id;
$stock->location_id = $location->id;
@@ -72,22 +72,22 @@ Now we can add stock to our inventory by supplying a number (int or string), and
So, we've successfully added stock to our inventory item, now let's add some more quantity to it:
$location = Location::find(1);
-
+
$item = Inventory::find(1);
-
+
$stock = $item->getStockFromLocation($location);
-
+
/*
* Reason and cost are always optional
*/
$reason = 'I bought some';
$cost = '5.20';
-
+
/*
* Remember, you're adding the amount of your metric, in this case Litres
*/
$stock->put(3, $reason, $cost);
-
+
/*
* Or you can use the add, they both perform the same function
*/
@@ -98,9 +98,9 @@ So, we've successfully added stock to our inventory item, now let's add some mor
We've added quantity to our stock, now lets take some away:
$reason = 'I drank it';
-
+
$stock->take(15, $reason);
-
+
/*
* Or you can use remove, they both perform the same function
*/
@@ -111,22 +111,22 @@ We've added quantity to our stock, now lets take some away:
Actually hang on, we definitely didn't drink that much, let's roll it back:
$stock->rollback();
-
+
/*
- * We can also rollback specific movements, this is recommended
+ * We can also rollback specific movements, this is recommended
* so you know which movement you're rolling back. You may want to
* rollback the last movement, but if a movement is created during a rollback,
* it won't take this into account.
*/
$movement = InventoryStockMovement::find(2);
-
+
$stock->rollback($movement);
-
+
// Or we can even trigger a rollback on the specific movement:
-
+
$movement->rollback();
-
-Now that we've added stock to our inventory, and made some changes, all changes are automatically tracked.
+
+Now that we've added stock to our inventory, and made some changes, all changes are automatically tracked.
If an exception occurs during a stock change, it is automatically reversed using Laravel's built in database transactions.
If you look at your database, inside your `inventory_stock_movements` table, you should see 4 records:
@@ -141,15 +141,15 @@ Another situation you might run into, is rolling back a specific movement and re
occurred AFTER the inserted movement. This is called a recursive rollback. This is how it's performed:
$movement = InventoryStockMovement::find(3);
-
+
$stock = InventoryStock::find(1);
-
+
/*
* Passing in true to the second argument will rollback all movements that happened after the inserted rollback,
* including itself.
*/
$stock->rollback($movement, true);
-
+
/*
* Or on the movement itself:
*/
@@ -168,17 +168,17 @@ There are some built in 'questions' you can ask your retrieved records. Many mor
####Inventory
$item = Inventory::find(1);
-
+
/*
* Returns true/false it the total stock of the item is greater than 0
*/
$item->isInStock();
-
+
/*
* Returns true/false if the item has a metric assigned to it
*/
$item->hasMetric();
-
+
/*
* Returns true/false if the item has an SKU
*/
@@ -187,18 +187,18 @@ There are some built in 'questions' you can ask your retrieved records. Many mor
####Stock
$stock = InventoryStock::find(1);
-
+
/*
* Returns true if the quantity entered is less than or equal to the amount of available stock.
*
- * This will throw a Stevebauman\Inventory\Exceptions\NotEnoughStockException if there is not enough
+ * This will throw a Trexology\Inventory\Exceptions\NotEnoughStockException if there is not enough
*/
$stock->hasEnoughStock($quantity = 0);
-
+
/*
* Returns true if the quantity entered is a valid quantity for updating the stock with.
*
- * This will throw a Stevebauman\Inventory\Exceptions\InvalidQuantityException if it is not valid
+ * This will throw a Trexology\Inventory\Exceptions\InvalidQuantityException if it is not valid
*/
$stock->isValidQuantity($quantity);
@@ -211,7 +211,7 @@ by disabling it inside the configuration.
From Google:
-'Stock Keeping Unit - SKU' A store's or catalog's product and service identification code, often portrayed
+'Stock Keeping Unit - SKU' A store's or catalog's product and service identification code, often portrayed
as a machine-readable bar code that helps the item to be tracked for inventory.
### How does inventory create the SKU?
@@ -228,7 +228,7 @@ always unique.
### What happens when an inventory item doesn't have a category?
-If an inventory item does not have a category, no SKU is generated. Once you assign a category to the inventory,
+If an inventory item does not have a category, no SKU is generated. Once you assign a category to the inventory,
it will be automatically generated.
### What happens if the category name is short?
@@ -237,7 +237,7 @@ If the categories name is below the number of characters set in the configuratio
For example, an item with a category named 'D', and an item ID of 1 (one), this will be generated:
D00001
-
+
A category name needs to be at least 1 (one) character in length to generate a valid SKU.
### How do I get the SKU from an item?
@@ -245,9 +245,9 @@ A category name needs to be at least 1 (one) character in length to generate a v
Easy, just ask the item using the laravel accessor:
$item = Inventory::find(1);
-
+
$item->sku_code;
-
+
Or use the method:
$item->getSku();
@@ -258,9 +258,9 @@ Regenerating an SKU will delete the previous items SKU and create another. This
You can perform this like so:
$item = Inventory::find(1);
-
+
$item->regenerateSku();
-
+
If regenerating an SKU fails, the items previous SKU will be restored. An example of this might be, an item's category
has changed to a category with no name. Then you call `regenerateSku()`, however this fails due to the category's name
not meeting at least 1 (one) character in length, so the previous items SKU is restored.
@@ -272,7 +272,7 @@ If the item does not have an SKU and `regenerateSku()` is called, then an SKU wi
You can generate an sku yourself like so:
$item = Inventory::find(1);
-
+
$item->generateSku();
If an item already has an SKU, or SKU generation was successful, it will return the current SKU record.
@@ -289,26 +289,26 @@ If you'd like to create your own SKU's, disable sku generation in the configurat
the method `createSku($code, $overwrite = false)` on your Inventory record like so:
$item = Inventory::find(1);
-
+
$item->createSku('my own sku');
This function contains no validation besides checking if an item already has an SKU, so you can create your own
ways of generating unique SKU's.
-If an item already has an SKU, and `createSku($code)` is called, then an `Stevebauman\Inventory\Exceptions\SkuAlreadyExistsException`
+If an item already has an SKU, and `createSku($code)` is called, then an `Trexology\Inventory\Exceptions\SkuAlreadyExistsException`
will be thrown.
If you'd like to overwrite the SKU if it exists, pass in `true` into the second argument in the function like so:
$item = Inventory::find(1);
-
+
// The current sku record will be updated if one exists with the new code
- $sku = $item->createSku('my own sku', true);
+ $sku = $item->createSku('my own sku', true);
If you'd like to update your custom SKU, you can just call the `updateSku($code)` method like so:
$item = Inventory::find(1);
-
+
$sku = $item->updateSku('my new sku code');
Calling `updateSku($code)` will also create an SKU if one doesn't exist.
@@ -326,10 +326,10 @@ In update 1.3 you can now add Suppliers easily to an inventory item.
First we'll create a supplier:
$supplier = new Supplier;
-
+
//Mandatory fields
$supplier->name = 'Drink Supplier';
-
+
//Optional fields
$supplier->address = '123 Fake Street';
$supplier->postal_code = 'N8J 2K7';
@@ -342,31 +342,31 @@ First we'll create a supplier:
$supplier->contact_phone = '555 555-5555';
$supplier->contact_fax = '555 555-5555';
$supplier->contact_email = 'john.doe@email.com';
-
+
$supplier->save();
-
+
Now we can add the supplier to an item using the `Inventory` model helper function `addSupplier($supplier)`:
$item = Inventory::find(1);
-
+
$item->addSupplier($supplier);
-
+
//Or we can use the suppliers ID
$item->addSupplier(1);
-
+
//Adding multiple suppliers at once
$item->addSuppliers(array($supplier));
-
+
We can also remove suppliers using:
$item->removeSupplier($supplier);
-
+
//Or we can use the suppliers ID
$item->removeSupplier(1);
-
+
//Removing multiple suppliers at once
$item->removeSuppliers(array($supplier));
-
+
//Removing all suppliers from an item
$item->removeAllSuppliers();
@@ -374,16 +374,16 @@ The inverse can also be done on the supplier model:
$supplier->addItem($item);
$supplier->addItem(1);
-
+
$supplier->addItems(array($item));
$supplier->addItems(array(1, 2, 3));
-
+
$supplier->removeItem($item);
$supplier->removeItem(1);
-
+
$supplier->removeItems(array($item));
$supplier->removeItems(array(1, 2, 3));
-
+
$supplier->removeAllItems();
## Exceptions
@@ -396,20 +396,20 @@ Here is a list of method's along with their exceptions that they can throw.
### NoUserLoggedInException
-Occurs when a user ID cannot be retrieved from Sentry, Sentinel, or built in Auth driver
+Occurs when a user ID cannot be retrieved from Sentry, Sentinel, or built in Auth driver
(doesn't apply when `allow_no_user` is enabled)
### NotEnoughStockException
Occurs when you're trying to take more stock than available. Use a try/catch block when processing take/remove actions:
-
- try
+
+ try
{
$stock->take($quantity);
-
+
return "Successfully removed $quantity";
-
- } catch(Stevebauman\Inventory\Exceptions\NotEnoughStockException)
+
+ } catch(Trexology\Inventory\Exceptions\NotEnoughStockException $e)
{
return "There wasn't enough stock to perform this action. Please try again.";
}
@@ -421,29 +421,29 @@ Occurs when a stock of the item already exists at the specified location. Use a
try
{
$stock->moveTo($location);
-
+
return "Successfully moved stock to $location->name";
-
- } catch(Stevebauman\Inventory\Exceptions\StockAlreadyExistsException)
+
+ } catch(Trexology\Inventory\Exceptions\StockAlreadyExistsException)
{
return "Stock already exists at this location. Please try again.";
}
### InvalidQuantityException
-Occurs when a non-numerical value is entered as the quantity, such as `'30L'`, `'a20.0'`. Strings (as long as they're numeric),
+Occurs when a non-numerical value is entered as the quantity, such as `'30L'`, `'a20.0'`. Strings (as long as they're numeric),
integers and doubles/decimals/floats are always valid. You can use laravel's built in validation to prevent this exception from
occurring, or you can use a try/catch block when processing actions involving quantity:
- try
+ try
{
$quantity = '20 Litres'; //This will cause an exception
-
+
$stock->add($quantity);
-
+
return "Successfully added $quantity";
-
- } catch(Stevebauman\Inventory\Exceptions\InvalidQuantityException)
+
+ } catch(Trexology\Inventory\Exceptions\InvalidQuantityException)
{
return "The quantity you entered is invalid. Please try again.";
}
@@ -463,18 +463,18 @@ Occurs when a movement cannot be found, or the specified movement is not a subcl
All methods used on the inventory can throw a `NoUserLoggedInException` if `allow_no_user` is disabled inside the configuration.
/**
- * @throws NoUserLoggedInException
+ * @throws NoUserLoggedInException
*/
#### Inventory Model Methods
-
+
/**
* @throws InvalidQuantityException
* @throws InvalidLocationException
* @throws StockAlreadyExistsException
*/
$item->createStockOnLocation($quantity, $location, $reason = '', $cost = 0, $aisle = NULL, $row = NULL, $bin = NULL);
-
+
/**
* @throws InvalidQuantityException
* @throws InvalidLocationException
@@ -482,7 +482,7 @@ All methods used on the inventory can throw a `NoUserLoggedInException` if `allo
*/
$item->takeFromLocation($quantity, $location, $reason = '');
$item->removeFromLocation($quantity, $locations = array(), $reason = '');
-
+
/**
* @throws InvalidQuantityException
* @throws InvalidLocationException
@@ -490,27 +490,27 @@ All methods used on the inventory can throw a `NoUserLoggedInException` if `allo
*/
$item->takeFromManyLocations($quantity, $locations = array(), $reason = '');
$item->removeFromManyLocations($quantity, $locations = array(), $reason = '');
-
+
/**
* @throws InvalidQuantityException
* @throws InvalidLocationException
*/
$item->putToLocation($quantity, $location, $reason = '', $cost = 0);
$item->addToLocation($quantity, $location, $reason = '', $cost = 0);
-
+
/**
* @throws InvalidQuantityException
* @throws InvalidLocationException
*/
$item->putToManyLocations($quantity, $locations = array(), $reason = '', $cost = 0);
$item->addToManyLocations($quantity, $locations = array(), $reason = '', $cost = 0);
-
+
/**
* @throws InvalidLocationException
* @throws StockAlreadyExistsException
*/
$item->moveStock($fromLocation, $toLocation);
-
+
/**
* @throws InvalidLocationException
* @throws StockNotFoundException
@@ -523,26 +523,26 @@ All methods used on the inventory can throw a `NoUserLoggedInException` if `allo
* @throws InvalidQuantityException
*/
$stock->updateQuantity($quantity, $reason= '', $cost = 0);
-
+
/**
* @throws InvalidQuantityException
* @throws NotEnoughStockException
*/
$stock->take($quantity, $reason = '');
$stock->remove($quantity, $reason= '');
-
+
/**
* @throws InvalidQuantityException
*/
$stock->add($quantity, $reason = '', $cost = 0);
$stock->put($quantity, $reason = '', $cost = 0);
-
+
/**
* @throws InvalidLocationException
* @throws StockAlreadyExistsException
*/
$stock->moveTo($location);
-
+
/**
* @throws NotEnoughStockException
*/
@@ -562,7 +562,7 @@ Integration with Sentry, Sentinel and Laravel's auth driver is built in, so inve
tagged to the current logged in user. However, you turn this off if you'd like in the config file under:
'allow_no_user' => false //Set to true
-
+
If you're using another form of authentication, you can always override the `protected static function getCurrentUserId()`
that is included on each trait by your own `UserIdentificationTrait`. For example:
@@ -575,21 +575,21 @@ The trait:
// Return the current users ID using your own method
}
}
-
+
On your models:
-
- use Stevebauman\Inventory\Traits\InventoryTrait;
-
+
+ use Trexology\Inventory\Traits\InventoryTrait;
+
class Inventory extends Eloquent
{
//Place the trait on your model
use MyUserIdentificationTrait;
-
+
use InventoryTrait;
-
+
protected $table = 'inventories';
}
-
+
## Misc Functions and Uses
#### Helpful Scopes
@@ -606,30 +606,30 @@ Place this inside your `Inventory` model. You can also use this implementation f
public function scopeCategory($query, $category_id = NULL)
{
if ($category_id) {
-
+
/*
* Get descendants and self inventory category nodes
*/
$categories = $this->category()->find($category_id)->getDescendantsAndSelf();
-
+
/*
* Perform a subquery on main query
*/
$query->where(function ($query) use ($categories) {
-
+
/*
* For each category, apply a orWhere query to the subquery
*/
foreach ($categories as $category) {
$query->orWhere('category_id', $category->id);
}
-
+
return $query;
-
+
});
}
}
-
+
Using this will effectively allow you to see all of the inventory from a parent category.
#### Helpful Accessors
@@ -668,7 +668,7 @@ You can simply create 2 Accessors. Place this accessor on the `InventoryStock` m
return NULL;
}
-
+
Place this accessor on the `InventoryStockMovement` model:
/**
@@ -690,19 +690,19 @@ Place this accessor on the `InventoryStockMovement` model:
return 'None';
}
}
-
+
Now, inside your view to display stock records you can use:
@if($stocks->count() > 0)
-
+
@foreach($stocks as $stock)
-
+
{{ $stock->last_movement }} // Will display in format '+ 20 (Stock was Added) - Reason: Stock check'
-
+
@endforeach
-
+
@else
-
+
There are no stocks to display for this item.
-
+
@endif
diff --git a/phpunit.xml b/phpunit.xml
index 50d47596..3834a800 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -12,9 +12,9 @@
>
- src/Stevebauman/Inventory
+ src/trexology/laravel-inventory
- src/Stevebauman/Inventory/InventoryServiceProvider.php
+ src/trexology/laravel-inventory/InventoryServiceProvider.php
diff --git a/src/Exceptions/Commands/DatabaseTableReservedException.php b/src/Exceptions/Commands/DatabaseTableReservedException.php
index 6f9a6f81..97d2fce5 100644
--- a/src/Exceptions/Commands/DatabaseTableReservedException.php
+++ b/src/Exceptions/Commands/DatabaseTableReservedException.php
@@ -1,6 +1,6 @@
loadTranslationsFrom(__DIR__.'/Lang', 'inventory');
+ }
+
/**
* {@inheritdoc}
*/
public function register()
{
- // Load the inventory translations from the inventory lang folder
- $this->loadTranslationsFrom(__DIR__.'/Lang', 'inventory');
-
// Assign the configuration as publishable, and tag it as 'config'
$this->publishes([
__DIR__.'/Config/config.php' => config_path('inventory.php'),
diff --git a/src/Migrations/2014_07_31_123201_create_metrics_table.php b/src/Migrations/2014_07_31_123201_create_inventory_metrics_table.php
similarity index 78%
rename from src/Migrations/2014_07_31_123201_create_metrics_table.php
rename to src/Migrations/2014_07_31_123201_create_inventory_metrics_table.php
index e2b438b9..7a0353ff 100644
--- a/src/Migrations/2014_07_31_123201_create_metrics_table.php
+++ b/src/Migrations/2014_07_31_123201_create_inventory_metrics_table.php
@@ -3,14 +3,14 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
-class CreateMetricsTable extends Migration
+class CreateInventoryMetricsTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
- Schema::create('metrics', function (Blueprint $table) {
+ Schema::create('inventory_metrics', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
@@ -29,6 +29,6 @@ public function up()
*/
public function down()
{
- Schema::dropIfExists('metrics');
+ Schema::dropIfExists('inventory_metrics');
}
}
diff --git a/src/Migrations/2014_07_31_123204_create_categories_table.php b/src/Migrations/2014_07_31_123204_create_inventory_categories_table.php
similarity index 81%
rename from src/Migrations/2014_07_31_123204_create_categories_table.php
rename to src/Migrations/2014_07_31_123204_create_inventory_categories_table.php
index efd386e5..3ef688c1 100644
--- a/src/Migrations/2014_07_31_123204_create_categories_table.php
+++ b/src/Migrations/2014_07_31_123204_create_inventory_categories_table.php
@@ -3,14 +3,14 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
-class CreateCategoriesTable extends Migration
+class CreateInventoryCategoriesTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
- Schema::create('categories', function (Blueprint $table) {
+ Schema::create('inventory_categories', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('parent_id')->nullable()->index();
@@ -32,6 +32,6 @@ public function up()
*/
public function down()
{
- Schema::dropIfExists('categories');
+ Schema::dropIfExists('inventory_categories');
}
}
diff --git a/src/Migrations/2014_07_31_123213_create_inventory_tables.php b/src/Migrations/2014_07_31_123213_create_inventory_tables.php
index 8126e279..9e9e1b1d 100644
--- a/src/Migrations/2014_07_31_123213_create_inventory_tables.php
+++ b/src/Migrations/2014_07_31_123213_create_inventory_tables.php
@@ -21,7 +21,7 @@ public function up()
$table->string('name');
$table->text('description')->nullable();
- $table->foreign('category_id')->references('id')->on('categories')
+ $table->foreign('category_id')->references('id')->on('inventory_categories')
->onUpdate('restrict')
->onDelete('set null');
@@ -29,7 +29,7 @@ public function up()
->onUpdate('restrict')
->onDelete('set null');
- $table->foreign('metric_id')->references('id')->on('metrics')
+ $table->foreign('metric_id')->references('id')->on('inventory_metrics')
->onUpdate('restrict')
->onDelete('cascade');
});
@@ -76,7 +76,9 @@ public function up()
$table->decimal('before', 8, 2)->default(0);
$table->decimal('after', 8, 2)->default(0);
$table->decimal('cost', 8, 2)->default(0)->nullable();
+ $table->nullableMorphs('receiver');
$table->string('reason')->nullable();
+ $table->boolean('returned')->default(0);
$table->foreign('stock_id')->references('id')->on('inventory_stocks')
->onUpdate('restrict')
diff --git a/src/Migrations/2017_02_08_115523_add_serial_number.php b/src/Migrations/2017_02_08_115523_add_serial_number.php
new file mode 100644
index 00000000..aa8e0fb1
--- /dev/null
+++ b/src/Migrations/2017_02_08_115523_add_serial_number.php
@@ -0,0 +1,35 @@
+text('serial')->nullable()->after('bin');
+ });
+
+ Schema::table('inventory_stock_movements', function (Blueprint $table) {
+ $table->text('serial')->nullable()->after('returned');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down()
+ {
+ Schema::table('inventory_stocks', function (Blueprint $table) {
+ $table->dropColumn('serial');
+ });
+
+ Schema::table('inventory_stock_movements', function (Blueprint $table) {
+ $table->dropColumn('serial');
+ });
+ }
+}
diff --git a/src/Models/BaseModel.php b/src/Models/BaseModel.php
index 43fe346c..13864308 100644
--- a/src/Models/BaseModel.php
+++ b/src/Models/BaseModel.php
@@ -1,10 +1,10 @@
hasMany('Stevebauman\Inventory\Models\Inventory', 'category_id', 'id');
- }
-}
diff --git a/src/Models/Inventory.php b/src/Models/Inventory.php
index c2dd6750..3932710e 100644
--- a/src/Models/Inventory.php
+++ b/src/Models/Inventory.php
@@ -1,12 +1,12 @@
hasOne(Category::class);
+ return $this->hasOne(InventoryCategory::class,'id','category_id');
}
/**
@@ -36,7 +43,7 @@ public function category()
*/
public function metric()
{
- return $this->hasOne(Metric::class);
+ return $this->hasOne(InventoryMetric::class,'id','metric_id');
}
/**
diff --git a/src/Models/InventoryCategory.php b/src/Models/InventoryCategory.php
new file mode 100644
index 00000000..0f4abe92
--- /dev/null
+++ b/src/Models/InventoryCategory.php
@@ -0,0 +1,52 @@
+hasMany('Trexology\Inventory\Models\Inventory', 'category_id', 'id');
+ }
+
+ /**
+ * Override the "default" left column name.
+ *
+ * @return string
+ */
+ public function getDefaultLeftColumnName()
+ {
+ return 'lft';
+ }
+
+ /**
+ * Override the "default" right column name.
+ *
+ * @return string
+ */
+ public function getDefaultRightColumnName()
+ {
+ return 'rgt';
+ }
+}
diff --git a/src/Models/Metric.php b/src/Models/InventoryMetric.php
similarity index 60%
rename from src/Models/Metric.php
rename to src/Models/InventoryMetric.php
index 21e96d45..9c86efe5 100644
--- a/src/Models/Metric.php
+++ b/src/Models/InventoryMetric.php
@@ -1,9 +1,13 @@
'array',
+ ];
+
/**
* The belongsTo inventory item relationship.
*
@@ -45,6 +49,6 @@ public function transactions()
*/
public function location()
{
- return $this->hasOne(Location::class);
+ return $this->belongsTo(Location::class);
}
}
diff --git a/src/Models/InventoryStockMovement.php b/src/Models/InventoryStockMovement.php
index 7520f1f7..c7509cd1 100644
--- a/src/Models/InventoryStockMovement.php
+++ b/src/Models/InventoryStockMovement.php
@@ -1,13 +1,17 @@
'array',
+ ];
+
/**
* The belongsTo stock relationship.
*
diff --git a/src/Models/Supplier.php b/src/Models/InventorySupplier.php
similarity index 72%
rename from src/Models/Supplier.php
rename to src/Models/InventorySupplier.php
index 3331f589..aee3199b 100644
--- a/src/Models/Supplier.php
+++ b/src/Models/InventorySupplier.php
@@ -1,10 +1,10 @@
hasMany(InventoryStock::class, 'location_id', 'id');
}
+
+
}
diff --git a/src/Traits/AssemblyTrait.php b/src/Traits/AssemblyTrait.php
index cb34d6f6..eb720a12 100644
--- a/src/Traits/AssemblyTrait.php
+++ b/src/Traits/AssemblyTrait.php
@@ -1,8 +1,8 @@
stock->rollback($this, $recursive);
}
+
+ /**
+ * Rolls back the current movement.
+ *
+ * @param bool $recursive
+ *
+ * @return mixed
+ */
+ public function returnStock($collect_amt, $collect_reason, $collect_serial, $dispose_amt, $dispose_reason, $dispose_serial)
+ {
+ return $this->stock->returnStock($this, $collect_amt, $collect_reason, $collect_serial, $dispose_amt, $dispose_reason, $dispose_serial);
+ }
}
diff --git a/src/Traits/InventoryStockTrait.php b/src/Traits/InventoryStockTrait.php
index 423e78bc..2333be8d 100644
--- a/src/Traits/InventoryStockTrait.php
+++ b/src/Traits/InventoryStockTrait.php
@@ -1,11 +1,11 @@
beforeQuantity = $model->getOriginal('quantity');
+ // Check if a serial number has been changed,
+ $original = json_decode($model->getOriginal('serial'));
+ if ($model->serial != $original && $model->quantity == $model->getOriginal('quantity')) {
+ $model->reason = "Serial number adjustment";
+ }
+
// Check if a reason has been set, if not let's
// retrieve the default change reason.
if (!$model->reason) {
@@ -107,7 +128,7 @@ public static function bootInventoryStockTrait()
*/
public function postCreate()
{
- $this->generateStockMovement(0, $this->getAttribute('quantity'), $this->reason, $this->cost);
+ $this->generateStockMovement(0, $this->getAttribute('quantity'), $this->reason, $this->cost, $this->receiver_id, $this->receiver_type, $this->movementSerial);
}
/**
@@ -117,7 +138,7 @@ public function postCreate()
*/
public function postUpdate()
{
- $this->generateStockMovement($this->beforeQuantity, $this->getAttribute('quantity'), $this->reason, $this->cost);
+ $this->generateStockMovement($this->beforeQuantity, $this->getAttribute('quantity'), $this->reason, $this->cost, $this->receiver_id, $this->receiver_type, $this->movementSerial);
}
/**
@@ -149,9 +170,9 @@ public function updateQuantity($quantity, $reason = '', $cost = 0)
*
* @return $this|bool
*/
- public function remove($quantity, $reason = '', $cost = 0)
+ public function remove($quantity, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
- return $this->take($quantity, $reason, $cost);
+ return $this->take($quantity, $reason, $cost, $receiver_id, $receiver_type, $serial);
}
/**
@@ -166,9 +187,9 @@ public function remove($quantity, $reason = '', $cost = 0)
*
* @return $this|bool
*/
- public function take($quantity, $reason = '', $cost = 0)
+ public function take($quantity, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
- return $this->processTakeOperation($quantity, $reason, $cost);
+ return $this->processTakeOperation($quantity, $reason, $cost, $receiver_id, $receiver_type, $serial);
}
/**
@@ -180,9 +201,9 @@ public function take($quantity, $reason = '', $cost = 0)
*
* @return $this
*/
- public function add($quantity, $reason = '', $cost = 0)
+ public function add($quantity, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
- return $this->put($quantity, $reason, $cost);
+ return $this->put($quantity, $reason, $cost, $receiver_id, $receiver_type, $serial);
}
/**
@@ -196,9 +217,9 @@ public function add($quantity, $reason = '', $cost = 0)
*
* @return $this
*/
- public function put($quantity, $reason = '', $cost = 0)
+ public function put($quantity, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
- return $this->processPutOperation($quantity, $reason, $cost);
+ return $this->processPutOperation($quantity, $reason, $cost, $receiver_id, $receiver_type,$serial);
}
/**
@@ -237,6 +258,50 @@ public function rollback($movement = null, $recursive = false)
return false;
}
+ /**
+ * Return stock assigned to an entity. Stock may be disposed of during the process of returning
+ *
+ * @param mixed $movement
+ * @param bool $recursive
+ *
+ * @return $this|bool
+ */
+ public function returnStock($movement, $collect_amt, $collect_reason, $collect_serial, $dispose_amt, $dispose_reason,$dispose_serial)
+ {
+ $collect_serial = is_null($collect_serial) ? [] : $collect_serial;
+ $dispose_serial = is_null($dispose_serial) ? [] : $dispose_serial;
+ $movement_serial = is_null($movement->serial) ? [] : $movement->serial;
+
+ if (!$movement) {
+ $movement = $this->getLastMovement();
+ }
+
+ $amt = $movement->getAttribute('before') - $movement->getAttribute('after');
+ $balance = $amt - $dispose_amt - $collect_amt;
+ if ($amt > 0 && $balance >= 0) {
+ // $bal_reason = Lang::get('inventory::reasons.rollback', [
+ // 'id' => $movement->getOriginal('id'),
+ // 'date' => $movement->getOriginal('created_at'),
+ // ]);
+ $bal_reason = "Balance leftover from stock redistribution. (id: $movement->id)";
+
+ $bal_serial = null;
+ if (is_array($collect_serial) && is_array($dispose_serial)) {
+ $bal_serial = array_diff($movement_serial, $collect_serial,$dispose_serial);
+ }
+ $this->put($amt,$collect_reason,0,$movement->receiver_id,$movement->receiver_type,$collect_serial);
+ $this->take($dispose_amt,$dispose_reason,0,null,null,$dispose_serial);
+ if ($balance > 0) {
+ $this->take($balance,$bal_reason,0,$movement->receiver_id,$movement->receiver_type,$bal_serial);
+ }
+
+ $movement->returned = true; // Prevent duplicate return for this movements
+ $movement->save();
+ }
+
+ return false;
+ }
+
/**
* Rolls back a specific movement.
*
@@ -385,7 +450,7 @@ protected function processUpdateQuantityOperation($quantity, $reason = '', $cost
*
* @return $this|bool
*/
- protected function processTakeOperation($taking, $reason = '', $cost = 0)
+ protected function processTakeOperation($taking, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
if($this->isValidQuantity($taking) && $this->hasEnoughStock($taking)) {
$available = $this->getAttribute('quantity');
@@ -400,15 +465,23 @@ protected function processTakeOperation($taking, $reason = '', $cost = 0)
if ((float) $left === (float) $available && !$this->allowDuplicateMovementsEnabled()) {
return $this;
}
-
$this->setAttribute('quantity', $left);
- $this->setReason($reason);
+ if (is_string($serial)) {
+ $serial = preg_split("/\s*,\s*/", trim($serial), -1, PREG_SPLIT_NO_EMPTY);
+ }
+ if ($this->serial && is_array($serial)) {
+ $this->serial = array_diff($this->serial,$serial);
+ }
+
+ $this->movementSerial = $serial;
+ $this->setReason($reason);
$this->setCost($cost);
+ $this->receiver_id = $receiver_id;
+ $this->receiver_type = $receiver_type;
$this->dbStartTransaction();
-
try {
if ($this->save()) {
$this->dbCommitTransaction();
@@ -436,7 +509,7 @@ protected function processTakeOperation($taking, $reason = '', $cost = 0)
*
* @return $this|bool
*/
- protected function processPutOperation($putting, $reason = '', $cost = 0)
+ protected function processPutOperation($putting, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
if($this->isValidQuantity($putting)) {
$current = $this->getAttribute('quantity');
@@ -449,11 +522,22 @@ protected function processPutOperation($putting, $reason = '', $cost = 0)
return $this;
}
+ if (is_string($serial)) {
+ $serial = preg_split("/\s*,\s*/", trim($serial), -1, PREG_SPLIT_NO_EMPTY);
+ }
+ if ($this->serial && is_array($serial)) {
+ $this->serial = array_merge($this->serial,$serial);
+ }
+ elseif (!$this->serial) {
+ $this->serial = $serial;
+ }
$this->quantity = $total;
+ $this->movementSerial = $serial;
$this->setReason($reason);
-
$this->setCost($cost);
+ $this->receiver_id = $receiver_id;
+ $this->receiver_type = $receiver_type;
$this->dbStartTransaction();
@@ -520,7 +604,8 @@ protected function processRollbackOperation(Model $movement, $recursive = false)
return $this->processRecursiveRollbackOperation($movement);
}
- $this->setAttribute('quantity', $movement->getAttribute('before'));
+ $amt = $movement->getAttribute('after')- $movement->getAttribute('before');
+ $this->setAttribute('quantity', $this->quantity - $amt);
$reason = Lang::get('inventory::reasons.rollback', [
'id' => $movement->getOriginal('id'),
@@ -529,6 +614,9 @@ protected function processRollbackOperation(Model $movement, $recursive = false)
$this->setReason($reason);
+ $this->receiver_id = $movement->receiver_id;
+ $this->receiver_type = $movement->receiver_type;
+
if ($this->rollbackCostEnabled()) {
$this->setCost($movement->getAttribute('cost'));
@@ -594,15 +682,20 @@ protected function processRecursiveRollbackOperation(Model $movement)
*
* @return bool|Model
*/
- protected function generateStockMovement($before, $after, $reason = '', $cost = 0)
+ protected function generateStockMovement($before, $after, $reason = '', $cost = 0, $receiver_id = null, $receiver_type = null, $serial = null)
{
$movement = $this->movements()->getRelated()->newInstance();
$movement->setAttribute('stock_id', $this->getKey());
$movement->setAttribute('before', $before);
$movement->setAttribute('after', $after);
+ if ($receiver_id && $receiver_type) {
+ $movement->setAttribute('receiver_id', $receiver_id);
+ $movement->setAttribute('receiver_type', $receiver_type);
+ }
$movement->setAttribute('reason', $reason);
$movement->setAttribute('cost', $cost);
+ $movement->setAttribute('serial', $serial);
if($movement->save()) {
return $movement;
diff --git a/src/Traits/InventoryTrait.php b/src/Traits/InventoryTrait.php
index ba6190b3..6161593c 100644
--- a/src/Traits/InventoryTrait.php
+++ b/src/Traits/InventoryTrait.php
@@ -1,11 +1,11 @@
category) {
+ if ($this->inventoryCategory) {
return true;
}
@@ -208,11 +208,11 @@ public function isInStock()
*
* @throws StockAlreadyExistsException
* @throws StockNotFoundException
- * @throws \Stevebauman\Inventory\Exceptions\NoUserLoggedInException
+ * @throws \Trexology\Inventory\Exceptions\NoUserLoggedInException
*
* @return Model
*/
- public function createStockOnLocation($quantity, Model $location, $reason = '', $cost = 0, $aisle = null, $row = null, $bin = null)
+ public function createStockOnLocation($quantity, Model $location, $reason = '', $cost = 0, $serial = null, $aisle = null, $row = null, $bin = null)
{
try {
// We want to make sure stock doesn't exist on the specified location already
@@ -234,8 +234,8 @@ public function createStockOnLocation($quantity, Model $location, $reason = '',
$stock->setAttribute('row', $row);
$stock->setAttribute('bin', $bin);
- if($stock->save()) {
- return $stock->put($quantity, $reason, $cost);
+ if($stock->save() && $quantity > 0) {
+ return $stock->put($quantity, $reason, $cost, null, null, $serial);
}
}
diff --git a/src/Traits/InventoryTransactionHistoryTrait.php b/src/Traits/InventoryTransactionHistoryTrait.php
index 45dc5c91..a94e10d1 100644
--- a/src/Traits/InventoryTransactionHistoryTrait.php
+++ b/src/Traits/InventoryTransactionHistoryTrait.php
@@ -1,8 +1,8 @@
'Stevebauman\Inventory\InventoryServiceProvider',
+ 'Inventory' => 'Trexology\Inventory\InventoryServiceProvider',
];
}
}