Skip to content

A free open source IT asset/license management system

Fixed #2855 - checkin for components

snipeb567ffdcfebd
diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php
index 01574ea794..0d4d6f0768 100644
--- a/app/Http/Controllers/ComponentsController.php
+++ b/app/Http/Controllers/ComponentsController.php
@@ -3,6 +3,7 @@ namespace App\Http\Controllers;
use App\Helpers\Helper;
use App\Http\Requests\ImageUploadRequest;
+use App\Models\Actionlog;
use App\Models\Company;
use App\Models\Component;
use App\Models\CustomField;
@@ -313,5 +314,97 @@ class ComponentsController extends Controller
return redirect()->route('components.index')->with('success', trans('admin/components/message.checkout.success'));
}
+ /**
+ * Returns a view that allows the checkin of a component from an asset.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @see ComponentsController::postCheckout() method that stores the data.
+ * @since [v4.1.4]
+ * @param int $componentId
+ * @return \Illuminate\Contracts\View\View
+ */
+ public function getCheckin($component_asset_id)
+ {
+
+ // This could probably be done more cleanly but I am very tired. - @snipe
+ if ($component_assets = DB::table('components_assets')->find($component_asset_id)) {
+ if (is_null($component = Component::find($component_assets->component_id))) {
+ return redirect()->route('components.index')->with('error', trans('admin/components/messages.not_found'));
+ }
+ if (is_null($asset = Asset::find($component_assets->asset_id))) {
+ return redirect()->route('components.index')->with('error',
+ trans('admin/components/message.not_found'));
+ }
+ $this->authorize('checkin', $component_assets);
+ return view('components/checkin', compact('component_assets','component','asset'));
+ }
+
+ return redirect()->route('components.index')->with('error', trans('admin/components/messages.not_found'));
+
+ }
+
+ /**
+ * Validate and store checkin data.
+ *
+ * @author [A. Gianotto] [<[email protected]>]
+ * @see ComponentsController::getCheckout() method that returns the form.
+ * @since [v4.1.4]
+ * @param Request $request
+ * @param int $componentId
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function postCheckin(Request $request, $component_asset_id)
+ {
+ if ($component_assets = DB::table('components_assets')->find($component_asset_id)) {
+ if (is_null($component = Component::find($component_assets->component_id))) {
+ return redirect()->route('components.index')->with('error',
+ trans('admin/components/message.not_found'));
+ }
+
+
+ $this->authorize('checkin', $component);
+
+ $max_to_checkin = $component_assets->assigned_qty;
+ $validator = Validator::make($request->all(), [
+ "checkin_qty" => "required|numeric|between:1,$max_to_checkin"
+ ]);
+
+ if ($validator->fails()) {
+ return redirect()->back()
+ ->withErrors($validator)
+ ->withInput();
+ }
+
+ // Validation passed, so let's figure out what we have to do here.
+ $qty_remaining_in_checkout = ($component_assets->assigned_qty - (int)$request->input('checkin_qty'));
+
+ // We have to modify the record to reflect the new qty that's
+ // actually checked out.
+ $component_assets->assigned_qty = $qty_remaining_in_checkout;
+ DB::table('components_assets')->where('id',
+ $component_asset_id)->update(['assigned_qty' => $qty_remaining_in_checkout]);
+
+ $log = new Actionlog();
+ $log->user_id = Auth::user()->id;
+ $log->action_type = 'checkin from';
+ $log->target_type = Asset::class;
+ $log->target_id = $component_assets->asset_id;
+ $log->item_id = $component_assets->component_id;
+ $log->item_type = Component::class;
+ $log->note = $request->input('note');
+ $log->save();
+
+ // If the checked-in qty is exactly the same as the assigned_qty,
+ // we can simply delete the associated components_assets record
+ if ($qty_remaining_in_checkout == 0) {
+ DB::table('components_assets')->where('id', '=', $component_asset_id)->delete();
+ }
+
+ return redirect()->route('components.index')->with('success',
+ trans('admin/components/message.checkout.success'));
+ }
+ return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
+ }
+
}
diff --git a/resources/views/components/checkin.blade.php b/resources/views/components/checkin.blade.php
new file mode 100644
index 0000000000..96c2181172
--- /dev/null
+++ b/resources/views/components/checkin.blade.php
@@ -0,0 +1,69 @@
+@extends('layouts/default')
+
+{{-- Page title --}}
+@section('title')
+ {{ trans('admin/licenses/general.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-7">
+ <form class="form-horizontal" method="post" action="{{ route('component.checkin.save', $component_assets->id) }}" autocomplete="off">
+ {{csrf_field()}}
+
+ <div class="box box-default">
+ <div class="box-header with-border">
+ <h3 class="box-title"> {{ $component->name }}</h3>
+ </div>
+ <div class="box-body">
+
+ <!-- Checked out to -->
+ <div class="form-group">
+ <label class="col-sm-2 control-label">{{ trans('general.checkin_from') }}</label>
+ <div class="col-md-6">
+ <p class="form-control-static">{{ $asset->present()->fullName }}</p>
+ </div>
+ </div>
+
+
+ <!-- Qty -->
+ <div class="form-group {{ $errors->has('checkin_qty') ? 'error' : '' }}">
+ <label for="note" class="col-md-2 control-label">{{ trans('general.qty') }}</label>
+ <div class="col-md-3">
+ <input type="text" class="form-control" name="checkin_qty" value="{{ Input::old('assigned_qty', $component_assets->assigned_qty) }}">
+ </div>
+ <div class="col-md-9 col-md-offset-2">
+ <p class="help-block">Must be {{ $component_assets->assigned_qty }} or less.</p>
+ {!! $errors->first('checkin_qty', '<span class="alert-msg"><i class="fa fa-times"></i>
+ :message</span>') !!}
+ </div>
+ </div>
+
+ <!-- Note -->
+ <div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
+ <label for="note" class="col-md-2 control-label">{{ trans('admin/hardware/form.notes') }}</label>
+ <div class="col-md-7">
+ <textarea class="col-md-6 form-control" id="note" name="note">{{ Input::old('note', $component->note) }}</textarea>
+ {!! $errors->first('note', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
+ </div>
+ </div>
+ <div class="box-footer">
+ <a class="btn btn-link" href="{{ route('components.index') }}">{{ trans('button.cancel') }}</a>
+ <button type="submit" class="btn btn-success pull-right"><i class="fa fa-check icon-white"></i> {{ trans('general.checkin') }}</button>
+ </div>
+ </div> <!-- /.box-->
+ </form>
+ </div> <!-- /.col-md-7-->
+ </div>
+
+
+@stop
diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php
index 57f2eb7141..b7b08232c9 100644
--- a/resources/views/components/view.blade.php
+++ b/resources/views/components/view.blade.php
@@ -58,6 +58,7 @@
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="name" data-formatter="hardwareLinkFormatter">{{ trans('general.asset') }}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="qty">{{ trans('general.qty') }}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
+ <th data-switchable="false" data-searchable="false" data-sortable="false" data-field="checkincheckout" data-formatter="componentsInOutFormatter">Checkin/Checkout</th>
</tr>
</thead>
</table>
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index 2c2da6cefc..a57980aaf2 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -299,7 +299,7 @@
if (row.assigned_to) {
return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans('general.checkin') }}</a>';
} else if (row.assigned_pivot_id) {
- return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin" class="btn btn-sm bg-purpley" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans('general.checkin') }}</a>';
+ return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans('general.checkin') }}</a>';
}
}
diff --git a/routes/web/components.php b/routes/web/components.php
index 7be4b1e9d5..4edeae9f56 100644
--- a/routes/web/components.php
+++ b/routes/web/components.php
@@ -11,6 +11,14 @@ Route::group([ 'prefix' => 'components','middleware' => ['auth'] ], function ()
'{componentID}/checkout',
[ 'as' => 'checkout/component', 'uses' => 'ComponentsController@postCheckout' ]
);
+ Route::get(
+ '{componentID}/checkin',
+ [ 'as' => 'checkin/component', 'uses' => 'ComponentsController@getCheckin' ]
+ );
+ Route::post(
+ '{componentID}/checkin',
+ [ 'as' => 'component.checkin.save', 'uses' => 'ComponentsController@postCheckin' ]
+ );
Route::post('bulk', [ 'as' => 'component/bulk-form', 'uses' => 'ComponentsController@postBulk' ]);
Route::post('bulksave', [ 'as' => 'component/bulk-save', 'uses' => 'ComponentsController@postBulkSave' ]);