Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel requested assets without checkin/out [ch-17606] #13219

Merged
merged 8 commits into from
Jun 29, 2023
10 changes: 5 additions & 5 deletions app/Http/Controllers/ViewAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getRequestableIndex()
return view('account/requestable-assets', compact('assets', 'models'));
}

public function getRequestItem(Request $request, $itemType, $itemId = null)
public function getRequestItem(Request $request, $itemType, $itemId = null, $cancel_by_admin = false, $requestingUser = null)
{
$item = null;
$fullItemType = 'App\\Models\\'.studly_case($itemType);
Expand Down Expand Up @@ -119,16 +119,16 @@ public function getRequestItem(Request $request, $itemType, $itemId = null)

$settings = Setting::getSettings();

if ($item_request = $item->isRequestedBy($user)) {
$item->cancelRequest();
$data['item_quantity'] = $item_request->qty;
if (($item_request = $item->isRequestedBy($user)) || $cancel_by_admin) {
$item->cancelRequest($requestingUser);
$data['item_quantity'] = ($item_request) ? $item_request->qty : 1;
$logaction->logaction('request_canceled');

if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {
$settings->notify(new RequestAssetCancelation($data));
}

return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
return redirect()->back()->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
} else {
$item->request();
if (($settings->alert_email != '') && ($settings->alerts_enabled == '1') && (! config('app.lock_passwords'))) {
Expand Down
8 changes: 6 additions & 2 deletions app/Models/Requestable.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public function deleteRequest()
$this->requests()->where('user_id', Auth::id())->delete();
}

public function cancelRequest()
public function cancelRequest($user_id = null)
{
$this->requests()->where('user_id', Auth::id())->update(['canceled_at' => \Carbon\Carbon::now()]);
if (!$user_id){
$user_id = Auth::id();
}

$this->requests()->where('user_id', $user_id)->update(['canceled_at' => \Carbon\Carbon::now()]);
}
}
1 change: 1 addition & 0 deletions resources/lang/en/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@
'errors_importing' => 'Some Errors occurred while importing: ',
'warning' => 'WARNING: :warning',
'success_redirecting' => '"Success... Redirecting.',
'cancel_request' => 'Cancel this item request',
'setup_successful_migrations' => 'Your database tables have been created',
'setup_migration_output' => 'Migration output:',
'setup_migration_create_user' => 'Next: Create User',
Expand Down
15 changes: 9 additions & 6 deletions resources/views/hardware/requested.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
<div class="col-md-12">
<div class="box">
<div class="box-body">
{{ Form::open([
'method' => 'POST',
'route' => ['hardware/bulkedit'],
'class' => 'form-inline',
'id' => 'bulkForm']) }}
<div class="row">
<div class="col-md-12">

Expand Down Expand Up @@ -51,7 +46,7 @@ class="table table-striped snipe-table"
<th class="col-md-2" data-sortable="true">{{ trans('admin/hardware/form.expected_checkin') }}</th>
<th class="col-md-3" data-sortable="true">{{ trans('admin/hardware/table.requesting_user') }}</th>
<th class="col-md-2">{{ trans('admin/hardware/table.requested_date') }}</th>
<th class="col-md-1">{{ trans('general.checkin').'/'.trans('general.checkout') }}</th>
<th class="col-md-1">{{ trans('button.actions') }}</th> <th></th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -103,6 +98,14 @@ class="table table-striped snipe-table"
@endif
</td>
<td>{{ App\Helpers\Helper::getFormattedDateObject($request->created_at, 'datetime', false) }}</td>
<td>
{{ Form::open([
'method' => 'POST',
'route' => ['account/request-item', $request->itemType(), $request->requestable->id, true, $request->requestingUser()->id],
]) }}
<button class="btn btn-warning btn-sm" data-tooltip="true" title="{{ trans('general.cancel_request') }}">{{ trans('button.cancel') }}</button>
{{ Form::close() }}
</td>
<td>
@if ($request->itemType() == "asset")
@if ($request->requestable->assigned_to=='')
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
)->name('account/request-asset');

Route::post(
'request/{itemType}/{itemId}',
'request/{itemType}/{itemId}/{cancel_by_admin?}/{requestingUser?}',
[ViewAssetsController::class, 'getRequestItem']
)->name('account/request-item');

Expand Down