Example #1
0
 public function getTotalInventoryValue()
 {
     $stocks = InventoryStock::where('quantity', '>', 0)->get();
     $value = 0;
     foreach ($stocks as $stock) {
         $pivot = $stock->item->getCurrentSupplierPivot();
         if ($pivot->supplier_id == $this->id) {
             $value += $stock->quantity * $pivot->cost;
         }
     }
     return $value;
 }
 /**
  * Create Request of inventory item
  *
  * @param Request      $request
  *
  * @return array
  */
 public function request(Request $request)
 {
     $item = Inventory::where('serialnr', $request->serialnr)->first();
     // If no item was found in database, create it.
     if (count($item) < 1) {
         $item = Inventory::createNewItem($request);
     }
     $stock = InventoryStock::where('inventory_id', $item->id)->where('location_id', 1)->first();
     // If no stock was found in database, create one.
     if (count($stock) < 1) {
         $stock = InventoryStock::createEmptyStock($item);
     }
     // create a request transaction
     $transaction = $stock->newTransaction();
     $transaction->requested($request->quantity);
     return redirect()->back()->with('message', $request->quantity . ' stk has been requested!');
 }
 /**
  * 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;
 }