Valo/checkin date in history of asset (#6733)

* To see checkin/checkout Date in History of Asset

* Added some logic to get today's date if the checkin_at input is blank

* Updating the action_date taking the value from the action_log table

* Hide created_at field and rename 'Action Date' as only 'Date'
This commit is contained in:
Ivan Nieto 2019-03-13 22:36:32 -06:00 committed by snipe
parent 8d63533205
commit c7f48951a9
8 changed files with 58 additions and 11 deletions

View file

@ -14,17 +14,19 @@ class CheckoutableCheckedIn
public $checkedOutTo; public $checkedOutTo;
public $checkedInBy; public $checkedInBy;
public $note; public $note;
public $action_date; // Date setted in the hardware.checkin view at the checkin_at input, for the action log
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @return void * @return void
*/ */
public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note) public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note, $action_date)
{ {
$this->checkoutable = $checkoutable; $this->checkoutable = $checkoutable;
$this->checkedOutTo = $checkedOutTo; $this->checkedOutTo = $checkedOutTo;
$this->checkedInBy = $checkedInBy; $this->checkedInBy = $checkedInBy;
$this->note = $note; $this->note = $note;
$this->action_date = $action_date;
} }
} }

View file

@ -82,10 +82,15 @@ class AssetCheckinController extends Controller
$asset->location_id = e($request->get('location_id')); $asset->location_id = e($request->get('location_id'));
} }
$checkin_at = date('Y-m-d');
if($request->filled('checkin_at')){
$checkin_at = $request->input('checkin_at');
}
// Was the asset updated? // Was the asset updated?
if ($asset->save()) { if ($asset->save()) {
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'))); event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at));
if ($backto=='user') { if ($backto=='user') {
return redirect()->route("users.show", $user->id)->with('success', trans('admin/hardware/message.checkin.success')); return redirect()->route("users.show", $user->id)->with('success', trans('admin/hardware/message.checkin.success'));

View file

@ -64,7 +64,7 @@ class ActionlogsTransformer
'note' => ($actionlog->note) ? e($actionlog->note): null, 'note' => ($actionlog->note) ? e($actionlog->note): null,
'signature_file' => ($actionlog->signature_filename) ? route('log.signature.view', ['filename' => $actionlog->signature_filename ]) : null, 'signature_file' => ($actionlog->signature_filename) ? route('log.signature.view', ['filename' => $actionlog->signature_filename ]) : null,
'log_meta' => ($actionlog->log_meta) ? json_decode($actionlog->log_meta): null, 'log_meta' => ($actionlog->log_meta) ? json_decode($actionlog->log_meta): null,
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'date'): null,
]; ];

View file

@ -24,11 +24,11 @@ class LogListener
{ {
public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event) { public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event) {
$event->checkoutable->logCheckin($event->checkedOutTo, $event->note); $event->checkoutable->logCheckin($event->checkedOutTo, $event->note, $event->action_date);
} }
public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event) { public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event) {
$event->checkoutable->logCheckout($event->note, $event->checkedOutTo); $event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout);
} }
public function onCheckoutAccepted(CheckoutAccepted $event) { public function onCheckoutAccepted(CheckoutAccepted $event) {

View file

@ -24,7 +24,7 @@ trait Loggable
* @since [v3.4] * @since [v3.4]
* @return \App\Models\Actionlog * @return \App\Models\Actionlog
*/ */
public function logCheckout($note, $target /* What are we checking out to? */) public function logCheckout($note, $target, $action_date)
{ {
$log = new Actionlog; $log = new Actionlog;
$log = $this->determineLogItemType($log); $log = $this->determineLogItemType($log);
@ -49,6 +49,7 @@ trait Loggable
} }
$log->note = $note; $log->note = $note;
$log->action_date = $action_date;
$log->logaction('checkout'); $log->logaction('checkout');
return $log; return $log;
@ -75,7 +76,7 @@ trait Loggable
* @since [v3.4] * @since [v3.4]
* @return \App\Models\Actionlog * @return \App\Models\Actionlog
*/ */
public function logCheckin($target, $note) public function logCheckin($target, $note, $action_date)
{ {
$log = new Actionlog; $log = new Actionlog;
$log->target_type = get_class($target); $log->target_type = get_class($target);
@ -91,7 +92,6 @@ trait Loggable
if (static::class == Asset::class) { if (static::class == Asset::class) {
if ($asset = Asset::find($log->item_id)) { if ($asset = Asset::find($log->item_id)) {
\Log::debug('Increment the checkin count for asset: '.$log->item_id);
$asset->increment('checkin_counter', 1); $asset->increment('checkin_counter', 1);
} }
} }
@ -101,6 +101,7 @@ trait Loggable
$log->location_id = null; $log->location_id = null;
$log->note = $note; $log->note = $note;
$log->action_date = $action_date;
$log->user_id = Auth::user()->id; $log->user_id = Auth::user()->id;
$log->logaction('checkin from'); $log->logaction('checkin from');

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddActionDateToActionlog extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('action_logs', function (Blueprint $table) {
$table->date('action_date')->nullable()->default(null);
});
$results = DB::table('action_logs')->select('created_at', 'id')->where('action_type', 'checkout')->orWhere('action_type', 'checkin from')->get();
foreach($results as $result){
$update = DB::update('update '.DB::getTablePrefix().'action_logs set action_date=? where id=?', [$result->created_at, $result->id]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('action_logs', function (Blueprint $table) {
$table->dropColumn('action_date');
});
}
}

View file

@ -82,7 +82,7 @@
{{ Form::label('checkin_at', trans('admin/hardware/form.checkin_date'), array('class' => 'col-md-3 control-label')) }} {{ Form::label('checkin_at', trans('admin/hardware/form.checkin_date'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8"> <div class="col-md-8">
<div class="input-group col-md-5 required"> <div class="input-group col-md-5 required">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true"> <div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-end-date="0d" data-autoclose="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="checkin_at" id="checkin_at" value="{{ Input::old('checkin_at', date('Y-m-d')) }}"> <input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="checkin_at" id="checkin_at" value="{{ Input::old('checkin_at', date('Y-m-d')) }}">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div> </div>

View file

@ -750,11 +750,12 @@
<thead> <thead>
<tr> <tr>
<th data-field="icon" data-visible="true" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter"></th> <th data-field="icon" data-visible="true" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter"></th>
<th class="col-sm-2" data-visible="true" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th> <th class="col-sm-2" data-visible="false" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
<th class="col-sm-1" data-visible="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th> <th class="col-sm-1" data-visible="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
<th class="col-sm-1" data-visible="true" data-field="action_type">{{ trans('general.action') }}</th>
<th class="col-sm-2" data-visible="true" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th> <th class="col-sm-2" data-visible="true" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
<th class="col-sm-1" data-visible="true" data-field="action_type">{{ trans('general.action') }}</th>
<th class="col-sm-2" data-visible="true" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th> <th class="col-sm-2" data-visible="true" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
<th class="col-sm-2" data-visible="true" data-field="action_date" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
<th class="col-sm-2" data-field="note">{{ trans('general.notes') }}</th> <th class="col-sm-2" data-field="note">{{ trans('general.notes') }}</th>
@if ($snipeSettings->require_accept_signature=='1') @if ($snipeSettings->require_accept_signature=='1')
<th class="col-md-3" data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th> <th class="col-md-3" data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>