Product inventory management updated
This commit is contained in:
parent
ab07518779
commit
f1371fd6a0
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue