Product inventory management updated

This commit is contained in:
jitendra 2019-01-11 14:51:20 +05:30
parent ab07518779
commit f1371fd6a0
10 changed files with 65 additions and 20 deletions

View File

@ -159,6 +159,7 @@ class ShipmentController extends Controller
$inventory = $product->inventories()
->where('inventory_source_id', $data['shipment']['source'])
->where('vendor_id', 0)
->first();
if ($orderItem->qty_to_ship < $qty || $inventory->qty < $qty) {

View File

@ -7,7 +7,7 @@
$qty = 0;
foreach ($product->inventories as $inventory) {
if($inventory->inventory_source_id == $inventorySource->id) {
if($inventory->inventory_source_id == $inventorySource->id && !$inventory->vendor_id) {
$qty = $inventory->qty;
break;
}

View File

@ -325,7 +325,7 @@
sourceInventoryQty (inventorySourceId) {
var inventories = this.variant.inventories.filter(function(inventory) {
return inventorySourceId === inventory.inventory_source_id;
return inventorySourceId === inventory.inventory_source_id && !inventory.vendor_id;
})
if(inventories.length)

View File

@ -306,6 +306,19 @@
}
?>
<?php
$sourceQty = 0;
$product = $item->type == 'configurable' ? $item->child->product : $item->product;
foreach ($product->inventories as $inventory) {
if($inventory->inventory_source_id == $inventorySource->id && !$inventory->vendor_id) {
$sourceQty = $inventory->qty;
break;
}
}
?>
{{ $sourceQty }}
</td>

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddVendorIdColumnInProductInventoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('product_inventories', function (Blueprint $table) {
$table->integer('vendor_id')->default(0);
$table->unique(['product_id', 'inventory_source_id', 'vendor_id'], 'product_source_vendor_index_unique');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('product_inventories', function (Blueprint $table) {
//
});
}
}

View File

@ -163,10 +163,10 @@ class Product extends Model
*
* @return bool
*/
public function inventory_source_qty($inventorySource)
public function inventory_source_qty($inventorySourceId)
{
return $this->inventories()
->where('inventory_source_id', $inventorySource->id)
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
}

View File

@ -9,7 +9,7 @@ class ProductInventory extends Model
{
public $timestamps = false;
protected $fillable = ['qty', 'product_id', 'inventory_source_id'];
protected $fillable = ['qty', 'product_id', 'inventory_source_id', 'vendor_id'];
/**
* Get the product attribute family that owns the product.

View File

@ -33,36 +33,32 @@ class ProductInventoryRepository extends Repository
if ($product->type == 'configurable')
return;
$inventorySourceIds = $product->inventory_sources->pluck('id');
if(isset($data['inventories'])) {
foreach($data['inventories'] as $inventorySourceId => $qty) {
if(is_null($qty))
continue;
if(is_null($qty)) {
$qty = 0;
}
$productInventory = $this->findOneWhere([
'product_id' => $product->id,
'inventory_source_id' => $inventorySourceId,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
if($productInventory) {
if(is_numeric($index = $inventorySourceIds->search($inventorySourceId))) {
$inventorySourceIds->forget($index);
}
$productInventory->qty = $qty;
$this->update(['qty' => $qty], $productInventory->id);
$productInventory->save();
} else {
$this->create([
'qty' => $qty,
'product_id' => $product->id,
'inventory_source_id' => $inventorySourceId,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
}
}
}
if($inventorySourceIds->count()) {
$product->inventory_sources()->detach($inventorySourceIds);
}
}
}

View File

@ -50,6 +50,7 @@ class ShipmentItemRepository extends Repository
}
$inventory = $data['product']->inventories()
->where('vendor_id', $data['vendor_id'])
->where('inventory_source_id', $data['shipment']->inventory_source_id)
->first();

View File

@ -134,7 +134,8 @@ class ShipmentRepository extends Repository
'shipment' => $shipment,
'shipmentItem' => $shipmentItem,
'product' => $product,
'qty' => $qty
'qty' => $qty,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
$this->orderItem->update(['qty_shipped' => $orderItem->qty_shipped + $qty], $orderItem->id);