/** * Request a specific Inventory from View Page * * @param Request $request (Ajax) * @param Inventory $item * * @return array */ public function request(Request $request, Inventory $item) { /** * If stock don't exist for this item, create it in location 1 (Nonlocated) * with zero quantity. * If stock exist, fetch the stock from record. */ if (count($item->stocks) == 0) { $stock = $item->newStockOnLocation(Location::find(1)); $stock->quantity = 0; $stock->save(); } else { $stock = InventoryStock::where('inventory_id', $item->id)->first(); } // Create new Request Transaction (order-requested) $transaction = $stock->newTransaction(); $transaction->requested($request->quantity); return $transaction; }