3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-04 15:05:42 +00:00

reworked checkedInBy, added option logic to accessories

This commit is contained in:
Godfrey M
2025-04-08 11:43:02 -07:00
parent 85b67dbb71
commit b7492928ad
3 changed files with 18 additions and 8 deletions

View File

@ -1475,11 +1475,19 @@ class Helper
}
static public function getRedirectOption($request, $id, $table, $checkedInBy=null, $item_id = null)
static public function getRedirectOption($request, $id, $table,$item_id = null)
{
$redirect_option = Session::get('redirect_option');
$checkout_to_type = Session::get('checkout_to_type');
$checkedInBy = Session::get('checkedInBy');
// dd([
// 'called from' => __FILE__,
// 'line' => __LINE__,
// 'redirect_option' => Session::get('redirect_option'),
// 'checkout_to_type' => Session::get('checkout_to_type'),
// 'target_id_param' => $checkedInBy,
// ]);
// return to index
if ($redirect_option == 'index') {

View File

@ -7,6 +7,7 @@ use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Asset;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -50,9 +51,14 @@ class AccessoryCheckinController extends Controller
}
$accessory = Accessory::find($accessory_checkout->accessory_id);
$checkedInBy = 0;
if($accessory_checkout->assigned_type === 'App\Models\User') {
$checkedInBy = $accessory_checkout->assigned_to;
session()->put('checkout_to_type', 'user');
session()->put('checkedInBy', $checkedInBy);
}
$this->authorize('checkin', $accessory);
$checkin_hours = date('H:i:s');
$checkin_at = date('Y-m-d H:i:s');
if ($request->filled('checkin_at')) {

View File

@ -77,6 +77,7 @@ class AssetCheckinController extends Controller
if ($asset->assignedType() == Asset::USER) {
$user = $asset->assignedTo;
session()->put('checkedInBy', $user->id);
}
$asset->expected_checkin = null;
@ -133,13 +134,8 @@ class AssetCheckinController extends Controller
$asset->customFieldsForCheckinCheckout('display_checkin');
if ($asset->save()) {
Log::debug([
'redirect_option' => $request->get('redirect_option'),
'checkout_to_type' => session()->get('checkout_to_type'),
'assigned_user' => session()->get('assigned_user'),
]);
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), $request->input('note'), $checkin_at, $originalValues));
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets', $user->id))->with('success', trans('admin/hardware/message.checkin.success'));
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))->with('success', trans('admin/hardware/message.checkin.success'));
}
// Redirect to the asset management page with error
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());