Compare commits

...

6 Commits

Author SHA1 Message Date
snipe
172942878b Added checkin as option in dropdown actions
Signed-off-by: snipe <snipe@snipe.net>
2022-03-02 14:20:13 -08:00
snipe
46279c5f3d Small layout fix
Signed-off-by: snipe <snipe@snipe.net>
2022-03-02 14:19:56 -08:00
snipe
731dc29bf5 New checkin blade
Signed-off-by: snipe <snipe@snipe.net>
2022-03-02 14:19:48 -08:00
snipe
530a76881e Added language strings
Signed-off-by: snipe <snipe@snipe.net>
2022-03-02 14:19:42 -08:00
snipe
257a501d70 Added routing logic for what form should be displayed
Signed-off-by: snipe <snipe@snipe.net>
2022-03-02 14:19:34 -08:00
snipe
e047d5516c Added new bulk checkin routes
Signed-off-by: snipe <snipe@snipe.net>
2022-03-02 14:19:16 -08:00
6 changed files with 149 additions and 6 deletions

View File

@@ -2,15 +2,21 @@
namespace App\Http\Controllers\Assets;
use App\Events\CheckoutableCheckedIn;
use App\Models\Actionlog;
use App\Helpers\Helper;
use App\Http\Controllers\CheckInOutRequest;
use App\Models\CheckoutAcceptance;
use App\Http\Controllers\Controller;
use App\Models\Asset;
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Http\Requests\AssetCheckinRequest;
use Illuminate\Database\Eloquent\Builder;
class BulkAssetsController extends Controller
{
@@ -49,8 +55,14 @@ class BulkAssetsController extends Controller
$assets->each(function ($asset) {
$this->authorize('delete', $asset);
});
return view('hardware/bulk-delete')->with('assets', $assets);
case 'checkin':
$assets = Asset::with('assignedTo', 'location')->find($asset_ids);
$assets->each(function ($asset) {
$this->authorize('checkin', $asset);
});
return view('hardware/bulk-checkin')->with('assets', $assets);
case 'edit':
return view('hardware/bulk')
->with('assets', $asset_ids)
@@ -206,6 +218,8 @@ class BulkAssetsController extends Controller
return redirect()->to('hardware')->with('info', trans('admin/hardware/message.delete.nothing_updated'));
}
/**
* Show Bulk Checkout Page
* @return View View to checkout multiple assets
@@ -213,8 +227,6 @@ class BulkAssetsController extends Controller
public function showCheckout()
{
$this->authorize('checkout', Asset::class);
// Filter out assets that are not deployable.
return view('hardware/bulk-checkout');
}
@@ -282,4 +294,55 @@ class BulkAssetsController extends Controller
return redirect()->to('hardware/bulk-checkout')->with('error', $e->getErrors());
}
}
/**
* Show Bulk Checkout Page
* @return View View to checkout multiple assets
*/
public function showCheckin(Request $request)
{
$this->authorize('checkin', Asset::class);
$assets = Asset::find($request->input('ids'));
return view('hardware/bulk-checkin')->with($assets);
}
/**
* Process Multiple Checkout Request
* @return View
*/
public function storeCheckin(AssetCheckinRequest $request)
{
$this->authorize('checkin', Asset::class);
if (! is_array($request->get('ids'))) {
return redirect()->route('hardware')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
}
$asset_ids = array_filter($request->get('ids'));
DB::transaction(function () use ($asset_ids, $request) {
foreach ($asset_ids as $asset_id) {
$asset = Asset::findOrFail($asset_id);
$this->authorize('checkin', $asset);
event(new CheckoutableCheckedIn($asset, '', Auth::user(), $request->input('note')));
}
});
// Get all pending Acceptances for this asset and delete them
$assets = Asset::find($request->input('ids'));
$acceptances = CheckoutAcceptance::pending()->whereHasMorph('checkoutable',
[Asset::class],
function (Builder $query) use ($asset) {
$query->where('id', $asset->id);
})->get();
$acceptances->map(function($acceptance) {
$acceptance->delete();
});
return redirect()->to('hardware');
}
}

View File

@@ -1,11 +1,13 @@
<?php
return [
'bulk_checkin' => 'Confirm Bulk Checkin Assets',
'bulk_delete' => 'Confirm Bulk Delete Assets',
'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.',
'bulk_delete_warn' => 'You are about to delete :asset_count assets.',
'bulk_update' => 'Bulk Update Assets',
'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ',
'bulk_checkin_warn' => 'You are about to checkin :asset_count assets.',
'bulk_update_warn' => 'You are about to edit the properties of :asset_count assets.',
'checkedout_to' => 'Checked Out To',
'checkout_date' => 'Checkout Date',

View File

@@ -0,0 +1,67 @@
@extends('layouts/default')
{{-- Page title --}}
@section('title')
{{ trans('admin/hardware/form.bulk_checkin') }}
@parent
@stop
@section('header_right')
<a href="{{ URL::previous() }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}</a>
@stop
{{-- Page content --}}
@section('content')
<div class="row">
<!-- left column -->
<div class="col-md-8 col-md-offset-2">
<form class="form-horizontal" method="post" action="{{ route('hardware/bulkcheckin') }}" autocomplete="off" role="form">
{{csrf_field()}}
<div class="box box-default">
<div class="box-header with-border">
</div>
<div class="box-body">
<table class="table table-striped table-condensed">
<thead>
<tr>
<td></td>
<td>{{ trans('admin/hardware/table.id') }}</td>
<td>{{ trans('admin/hardware/table.name') }}</td>
<td>{{ trans('admin/hardware/table.location')}}</td>
<td>{{ trans('admin/hardware/table.assigned_to') }}</td>
</tr>
</thead>
<tbody>
@foreach ($assets as $asset)
<tr>
<td><input type="checkbox" name="ids[]" value="{{ $asset->id }}" checked="checked"></td>
<td>{{ $asset->id }}</td>
<td>{{ $asset->present()->name() }}</td>
<td>
@if ($asset->location)
{{ $asset->location->name }}
@endif
</td>
<td>
@if ($asset->assignedTo)
{{ $asset->assignedTo->present()->name()}}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div><!-- /.box-body -->
<div class="box-footer text-right">
<a class="btn btn-link" href="{{ URL::previous() }}" method="post" enctype="multipart/form-data">{{ trans('button.cancel') }}</a>
<button type="submit" class="btn btn-success" id="submit-button"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.checkin') }}</button>
</div><!-- /.box-footer -->
</div><!-- /.box -->
</form>
</div> <!-- .col-md-12-->
</div><!--.row-->
@stop

View File

@@ -15,7 +15,7 @@
@section('content')
<div class="row">
<!-- left column -->
<div class="col-md-12">
<div class="col-md-8 col-md-offset-2">
<p>{{ trans('admin/hardware/form.bulk_delete_help') }}</p>
<form class="form-horizontal" method="post" action="{{ route('hardware/bulkdelete') }}" autocomplete="off" role="form">
{{csrf_field()}}

View File

@@ -76,6 +76,7 @@
<label for="bulk_actions"><span class="sr-only">{{ trans('button.bulk_actions') }}</span></label>
<select name="bulk_actions" class="form-control select2" aria-label="bulk_actions">
<option value="edit">{{ trans('button.edit') }}</option>
<option value="checkin">{{ trans('general.checkin') }}</option>
<option value="delete">{{ trans('button.delete') }}</option>
<option value="labels">{{ trans_choice('button.generate_labels', 2) }}</option>
</select>

View File

@@ -165,7 +165,7 @@ Route::group(
[BulkAssetsController::class, 'update']
)->name('hardware/bulksave');
// Bulk checkout / checkin
// Bulk checkout
Route::get('bulkcheckout',
[BulkAssetsController::class, 'showCheckout']
)->name('hardware/bulkcheckout');
@@ -173,7 +173,17 @@ Route::group(
Route::post('bulkcheckout',
[BulkAssetsController::class, 'storeCheckout']
)->name('hardware/bulkcheckout');
});
// Bulk checkin
Route::get('bulkcheckin',
[BulkAssetsController::class, 'showCheckin']
)->name('hardware/bulkcheckin');
Route::post('bulkcheckin',
[BulkAssetsController::class, 'storeCheckin']
)->name('hardware/bulkcheckin');
});
Route::resource('hardware',
AssetsController::class,