From c7f48951a9a6206455f3df1e305ccfac1e861789 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Date: Wed, 13 Mar 2019 22:36:32 -0600 Subject: [PATCH] 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' --- app/Events/CheckoutableCheckedIn.php | 4 +- .../Assets/AssetCheckinController.php | 7 +++- .../Transformers/ActionlogsTransformer.php | 2 +- app/Listeners/LogListener.php | 4 +- app/Models/Loggable.php | 7 ++-- ..._12_182750_add_actiondate_to_actionlog.php | 38 +++++++++++++++++++ resources/views/hardware/checkin.blade.php | 2 +- resources/views/hardware/view.blade.php | 5 ++- 8 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 database/migrations/2019_02_12_182750_add_actiondate_to_actionlog.php diff --git a/app/Events/CheckoutableCheckedIn.php b/app/Events/CheckoutableCheckedIn.php index 0f6a96491a..2edb6888c3 100644 --- a/app/Events/CheckoutableCheckedIn.php +++ b/app/Events/CheckoutableCheckedIn.php @@ -14,17 +14,19 @@ class CheckoutableCheckedIn public $checkedOutTo; public $checkedInBy; 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. * * @return void */ - public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note) + public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note, $action_date) { $this->checkoutable = $checkoutable; $this->checkedOutTo = $checkedOutTo; $this->checkedInBy = $checkedInBy; $this->note = $note; + $this->action_date = $action_date; } } diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index e87a1df23c..c573389c9b 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -82,10 +82,15 @@ class AssetCheckinController extends Controller $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? 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') { return redirect()->route("users.show", $user->id)->with('success', trans('admin/hardware/message.checkin.success')); diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index eb1a1340b7..d119f3bb60 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -64,7 +64,7 @@ class ActionlogsTransformer 'note' => ($actionlog->note) ? e($actionlog->note): 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, - + 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'date'): null, ]; diff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.php index 9d0da17470..5e9445183f 100644 --- a/app/Listeners/LogListener.php +++ b/app/Listeners/LogListener.php @@ -24,11 +24,11 @@ class LogListener { 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) { - $event->checkoutable->logCheckout($event->note, $event->checkedOutTo); + $event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout); } public function onCheckoutAccepted(CheckoutAccepted $event) { diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index c2977ca030..ba2be7ba38 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -24,7 +24,7 @@ trait Loggable * @since [v3.4] * @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 = $this->determineLogItemType($log); @@ -49,6 +49,7 @@ trait Loggable } $log->note = $note; + $log->action_date = $action_date; $log->logaction('checkout'); return $log; @@ -75,7 +76,7 @@ trait Loggable * @since [v3.4] * @return \App\Models\Actionlog */ - public function logCheckin($target, $note) + public function logCheckin($target, $note, $action_date) { $log = new Actionlog; $log->target_type = get_class($target); @@ -91,7 +92,6 @@ trait Loggable if (static::class == Asset::class) { if ($asset = Asset::find($log->item_id)) { - \Log::debug('Increment the checkin count for asset: '.$log->item_id); $asset->increment('checkin_counter', 1); } } @@ -101,6 +101,7 @@ trait Loggable $log->location_id = null; $log->note = $note; + $log->action_date = $action_date; $log->user_id = Auth::user()->id; $log->logaction('checkin from'); diff --git a/database/migrations/2019_02_12_182750_add_actiondate_to_actionlog.php b/database/migrations/2019_02_12_182750_add_actiondate_to_actionlog.php new file mode 100644 index 0000000000..7537261de8 --- /dev/null +++ b/database/migrations/2019_02_12_182750_add_actiondate_to_actionlog.php @@ -0,0 +1,38 @@ +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'); + }); + } +} \ No newline at end of file diff --git a/resources/views/hardware/checkin.blade.php b/resources/views/hardware/checkin.blade.php index f7ba4cc173..624318e685 100755 --- a/resources/views/hardware/checkin.blade.php +++ b/resources/views/hardware/checkin.blade.php @@ -82,7 +82,7 @@ {{ Form::label('checkin_at', trans('admin/hardware/form.checkin_date'), array('class' => 'col-md-3 control-label')) }}
-
+
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index f6b5ffc69e..297da6fc9d 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -750,11 +750,12 @@ - {{ trans('general.date') }} + {{ trans('general.date') }} {{ trans('general.admin') }} - {{ trans('general.action') }} {{ trans('general.item') }} + {{ trans('general.action') }} {{ trans('general.target') }} + {{ trans('general.date') }} {{ trans('general.notes') }} @if ($snipeSettings->require_accept_signature=='1') {{ trans('general.signature') }}