/** * 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; }
/** * 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(); }