mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Add validation to Accessories and Consumables to not let the user update the number of items to less than they already have checked out
This commit is contained in:
parent
84aa26dd50
commit
570dd09dcd
|
@ -9,6 +9,7 @@ use App\Models\Accessory;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
|
|
||||||
/** This controller handles all actions related to Accessories for
|
/** This controller handles all actions related to Accessories for
|
||||||
|
@ -130,6 +131,17 @@ class AccessoriesController extends Controller
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$min = $accessory->numCHeckedOut();
|
||||||
|
$validator = Validator::make($request->all(), [
|
||||||
|
"qty" => "required|numeric|min:$min"
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return redirect()->back()
|
||||||
|
->withErrors($validator)
|
||||||
|
->withInput();
|
||||||
|
}
|
||||||
|
|
||||||
$this->authorize($accessory);
|
$this->authorize($accessory);
|
||||||
|
|
||||||
// Update the accessory data
|
// Update the accessory data
|
||||||
|
|
|
@ -9,6 +9,7 @@ use App\Models\Company;
|
||||||
use App\Models\Consumable;
|
use App\Models\Consumable;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Input;
|
use Illuminate\Support\Facades\Input;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller handles all actions related to Consumables for
|
* This controller handles all actions related to Consumables for
|
||||||
|
@ -128,6 +129,17 @@ class ConsumablesController extends Controller
|
||||||
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist'));
|
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$min = $consumable->numCHeckedOut();
|
||||||
|
$validator = Validator::make($request->all(), [
|
||||||
|
"qty" => "required|numeric|min:$min"
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return redirect()->back()
|
||||||
|
->withErrors($validator)
|
||||||
|
->withInput();
|
||||||
|
}
|
||||||
|
|
||||||
$this->authorize($consumable);
|
$this->authorize($consumable);
|
||||||
|
|
||||||
$consumable->name = $request->input('name');
|
$consumable->name = $request->input('name');
|
||||||
|
|
|
@ -310,6 +310,21 @@ class Accessory extends SnipeModel
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check how many items within an accessory are checked out
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v5.0]
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function numCheckedOut()
|
||||||
|
{
|
||||||
|
$checkedout = 0;
|
||||||
|
$checkedout = $this->users->count();
|
||||||
|
|
||||||
|
return $checkedout;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check how many items of an accessory remain
|
* Check how many items of an accessory remain
|
||||||
*
|
*
|
||||||
|
|
|
@ -276,6 +276,21 @@ class Consumable extends SnipeModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check how many items within a consumable are checked out
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v5.0]
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function numCheckedOut()
|
||||||
|
{
|
||||||
|
$checkedout = 0;
|
||||||
|
$checkedout = $this->users->count();
|
||||||
|
|
||||||
|
return $checkedout;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the number of available consumables
|
* Checks the number of available consumables
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue