/**
  * Validates that the inserted stock is smaller than the available stock.
  *
  * @param $attribute
  * @param $quantity
  * @param $parameters
  *
  * @return bool
  */
 public function validateEnoughQuantity($attribute, $quantity, $parameters)
 {
     if (is_numeric($quantity)) {
         $stockId = Route::getCurrentRoute()->getParameter('stocks');
         $stock = $this->inventoryStock->find($stockId);
         if ($quantity > $stock->quantity) {
             return false;
         }
         return true;
     }
     return false;
 }
 /**
  * Validates that a stock does not exist on the specified location.
  *
  * @param string     $attribute
  * @param int|string $locationId
  * @param array      $parameters
  *
  * @return bool
  */
 public function validateStockLocation($attribute, $locationId, $parameters)
 {
     $itemId = Route::getCurrentRoute()->getParameter('inventory');
     $stockId = Route::getCurrentRoute()->getParameter('stocks');
     if (!empty($stockId)) {
         $stocks = $this->inventoryStock->where('inventory_id', $itemId)->where('id', '!=', $stockId)->where('location_id', $locationId)->get();
     } else {
         $stocks = $this->inventoryStock->where('inventory_id', $itemId)->where('location_id', $locationId)->get();
     }
     if ($stocks->count() > 0) {
         return false;
     }
     return true;
 }
 /**
  * Rolls back an inventory stock movement.
  *
  * @param $inventory_id
  * @param $stock_id
  * @param $movement_id
  *
  * @return \Illuminate\Http\JsonResponse|mixed
  */
 public function rollback($inventory_id, $stock_id, $movement_id)
 {
     $item = $this->inventory->find($inventory_id);
     $stock = $this->inventoryStock->find($stock_id);
     $movement = $this->inventoryStockMovement->find($movement_id);
     if ($stock->rollback($movement)) {
         $this->message = 'Successfully rolled back movement';
         $this->messageType = 'success';
         $this->redirect = routeBack('maintenance.inventory.stock.movements.index', [$item->id, $stock->id]);
     } else {
         $this->message = 'There was an error trying to roll back this movement. Please try again.';
         $this->messageType = 'success';
         $this->redirect = routeBack('maintenance.inventory.stock.movements.index', [$item->id, $stock->id]);
     }
     return $this->response();
 }