A free open source IT asset/license management system
simplified checkout event handling per @uberbrady’s suggestion
Till Deeke007e8fbdf988
diff --git a/app/Events/AccessoryCheckedOut.php b/app/Events/AccessoryCheckedOut.phpdeleted file mode 100644index faf30adb36..0000000000--- a/app/Events/AccessoryCheckedOut.php+++ /dev/null@@ -1,32 +0,0 @@-<?php--namespace App\Events;--use App\Models\Accessory;-use App\Models\Actionlog;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class AccessoryCheckedOut-{- use Dispatchable, SerializesModels;-- public $accessory;- public $checkedOutTo;- public $logEntry;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOutBy, $note)- {- $this->accessory = $accessory;- $this->checkedOutTo = $checkedOutTo;- $this->checkedOutBy = $checkedOutBy;- $this->note = $note;- }-}diff --git a/app/Events/AssetCheckedIn.php b/app/Events/AssetCheckedIn.phpdeleted file mode 100644index 455b2b5d4e..0000000000--- a/app/Events/AssetCheckedIn.php+++ /dev/null@@ -1,33 +0,0 @@-<?php--namespace App\Events;--use App\Models\Actionlog;-use App\Models\Asset;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class AssetCheckedIn-{- use Dispatchable, SerializesModels;-- public $asset;- public $checkedOutTo;- public $checkedInBy;- public $note;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(Asset $asset, $checkedOutTo, User $checkedInBy, $note)- {- $this->asset = $asset;- $this->checkedOutTo = $checkedOutTo;- $this->checkedInBy = $checkedInBy;- $this->note = $note;- }-}diff --git a/app/Events/AssetCheckedOut.php b/app/Events/AssetCheckedOut.phpdeleted file mode 100644index 1cd0669ad8..0000000000--- a/app/Events/AssetCheckedOut.php+++ /dev/null@@ -1,32 +0,0 @@-<?php--namespace App\Events;--use App\Models\Actionlog;-use App\Models\Asset;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class AssetCheckedOut-{- use Dispatchable, SerializesModels;-- public $asset;- public $checkedOutTo;- public $logEntry;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $note)- {- $this->asset = $asset;- $this->checkedOutTo = $checkedOutTo;- $this->checkedOutBy = $checkedOutBy;- $this->note = $note;- }-}diff --git a/app/Events/AccessoryCheckedIn.php b/app/Events/CheckoutableCheckedIn.phpsimilarity index 62%rename from app/Events/AccessoryCheckedIn.phprename to app/Events/CheckoutableCheckedIn.phpindex 812e072b28..0f6a96491a 100644--- a/app/Events/AccessoryCheckedIn.php+++ b/app/Events/CheckoutableCheckedIn.php@@ -2,30 +2,27 @@namespace App\Events;-use App\Models\Accessory;-use App\Models\Actionlog;use App\Models\User;-use Illuminate\Broadcasting\Channel;use Illuminate\Foundation\Events\Dispatchable;use Illuminate\Queue\SerializesModels;-class AccessoryCheckedIn+class CheckoutableCheckedIn{use Dispatchable, SerializesModels;- public $accessory;+ public $checkoutable;public $checkedOutTo;public $checkedInBy;public $note;-+/*** Create a new event instance.** @return void*/- public function __construct(Accessory $accessory, $checkedOutTo, User $checkedInBy, $note)+ public function __construct($checkoutable, $checkedOutTo, User $checkedInBy, $note){- $this->accessory = $accessory;+ $this->checkoutable = $checkoutable;$this->checkedOutTo = $checkedOutTo;$this->checkedInBy = $checkedInBy;$this->note = $note;diff --git a/app/Events/ComponentCheckedOut.php b/app/Events/CheckoutableCheckedOut.phpsimilarity index 59%rename from app/Events/ComponentCheckedOut.phprename to app/Events/CheckoutableCheckedOut.phpindex f74e7d70f4..5e6ffd243a 100644--- a/app/Events/ComponentCheckedOut.php+++ b/app/Events/CheckoutableCheckedOut.php@@ -2,30 +2,29 @@namespace App\Events;-use App\Models\Component;use App\Models\User;-use Illuminate\Broadcasting\Channel;use Illuminate\Foundation\Events\Dispatchable;use Illuminate\Queue\SerializesModels;-class ComponentCheckedOut+class CheckoutableCheckedOut{use Dispatchable, SerializesModels;- public $component;+ public $checkoutable;public $checkedOutTo;public $checkedOutBy;+ public $note;/*** Create a new event instance.** @return void*/- public function __construct(Component $component, $checkedOutTo, $quantity, User $checkedOutBy)+ public function __construct($checkoutable, $checkedOutTo, User $checkedOutBy, $note){- $this->component = $component;+ $this->checkoutable = $checkoutable;$this->checkedOutTo = $checkedOutTo;- $this->quantity = $quantity;$this->checkedOutBy = $checkedOutBy;+ $this->note = $note;}}diff --git a/app/Events/ComponentCheckedIn.php b/app/Events/ComponentCheckedIn.phpdeleted file mode 100644index 283ea6e358..0000000000--- a/app/Events/ComponentCheckedIn.php+++ /dev/null@@ -1,35 +0,0 @@-<?php--namespace App\Events;--use App\Models\Actionlog;-use App\Models\Component;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class ComponentCheckedIn-{- use Dispatchable, SerializesModels;-- public $component;- public $checkedOutTo;- public $checkedInBy;- public $quantity;- public $note;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(Component $component, $checkedOutTo, User $checkedInBy, $quantity, $note)- {- $this->component = $component;- $this->checkedOutTo = $checkedOutTo;- $this->checkedInBy = $checkedInBy;- $this->quantity = $quantity;- $this->note = $note;- }-}diff --git a/app/Events/ConsumableCheckedOut.php b/app/Events/ConsumableCheckedOut.phpdeleted file mode 100644index ca002cc2f8..0000000000--- a/app/Events/ConsumableCheckedOut.php+++ /dev/null@@ -1,32 +0,0 @@-<?php--namespace App\Events;--use App\Models\Actionlog;-use App\Models\Consumable;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class ConsumableCheckedOut-{- use Dispatchable, SerializesModels;-- public $consumable;- public $checkedOutTo;- public $logEntry;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(Consumable $consumable, $checkedOutTo, User $checkedOutBy, $note)- {- $this->consumable = $consumable;- $this->checkedOutTo = $checkedOutTo;- $this->checkedOutBy = $checkedOutBy;- $this->note = $note;- }-}diff --git a/app/Events/LicenseSeatCheckedIn.php b/app/Events/LicenseSeatCheckedIn.phpdeleted file mode 100644index 80e7ecbaf4..0000000000--- a/app/Events/LicenseSeatCheckedIn.php+++ /dev/null@@ -1,34 +0,0 @@-<?php--namespace App\Events;--use App\Models\Actionlog;-use App\Models\License;-use App\Models\LicenseSeat;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class LicenseCheckedIn-{- use Dispatchable, SerializesModels;-- public $licenseSeat;- public $checkedOutTo;- public $checkedInBy;- public $note;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)- {- $this->licenseSeat = $licenseSeat;- $this->checkedOutTo = $checkedOutTo;- $this->checkedInBy = $checkedInBy;- $this->note = $note;- }-}diff --git a/app/Events/LicenseSeatCheckedOut.php b/app/Events/LicenseSeatCheckedOut.phpdeleted file mode 100644index 6b057be43e..0000000000--- a/app/Events/LicenseSeatCheckedOut.php+++ /dev/null@@ -1,33 +0,0 @@-<?php--namespace App\Events;--use App\Models\Actionlog;-use App\Models\License;-use App\Models\LicenseSeat;-use App\Models\User;-use Illuminate\Broadcasting\Channel;-use Illuminate\Foundation\Events\Dispatchable;-use Illuminate\Queue\SerializesModels;--class LicenseSeatCheckedOut-{- use Dispatchable, SerializesModels;-- public $licenseSeat;- public $checkedOutTo;- public $logEntry;-- /**- * Create a new event instance.- *- * @return void- */- public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedOutBy, $note)- {- $this->licenseSeat = $licenseSeat;- $this->checkedOutTo = $checkedOutTo;- $this->checkedOutBy = $checkedOutBy;- $this->note = $note;- }-}diff --git a/app/Http/Controllers/Accessories/AccessoryCheckinController.php b/app/Http/Controllers/Accessories/AccessoryCheckinController.phpindex e64d24f169..930e9b6619 100644--- a/app/Http/Controllers/Accessories/AccessoryCheckinController.php+++ b/app/Http/Controllers/Accessories/AccessoryCheckinController.php@@ -2,7 +2,7 @@namespace App\Http\Controllers\Accessories;-use App\Events\AccessoryCheckedIn;+use App\Events\CheckoutableCheckedIn;use App\Http\Controllers\Controller;use App\Models\Accessory;use App\Models\User;@@ -64,7 +64,7 @@ class AccessoryCheckinController extends Controllerif (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {$return_to = e($accessory_user->assigned_to);- event(new AccessoryCheckedIn($accessory, User::find($return_to), Auth::user(), $request->input('note')));+ event(new CheckoutableCheckedIn($accessory, User::find($return_to), Auth::user(), $request->input('note')));return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success'));}diff --git a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php b/app/Http/Controllers/Accessories/AccessoryCheckoutController.phpindex 13bc9e8fd2..5ec8a8704f 100644--- a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php+++ b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php@@ -2,7 +2,7 @@namespace App\Http\Controllers\Accessories;-use App\Events\AccessoryCheckedOut;+use App\Events\CheckoutableCheckedOut;use App\Http\Controllers\Controller;use App\Models\Accessory;use App\Models\User;@@ -80,7 +80,7 @@ class AccessoryCheckoutController extends ControllerDB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();- event(new AccessoryCheckedOut($accessory, $user, Auth::user(), $request->input('note')));+ event(new CheckoutableCheckedOut($accessory, $user, Auth::user(), $request->input('note')));// Redirect to the new accessory pagereturn redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.checkout.success'));diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.phpindex da141f8b3d..e87a1df23c 100644--- a/app/Http/Controllers/Assets/AssetCheckinController.php+++ b/app/Http/Controllers/Assets/AssetCheckinController.php@@ -2,7 +2,7 @@namespace App\Http\Controllers\Assets;-use App\Events\AssetCheckedIn;+use App\Events\CheckoutableCheckedIn;use App\Helpers\Helper;use App\Http\Controllers\Controller;use App\Http\Requests\AssetCheckinRequest;@@ -85,7 +85,7 @@ class AssetCheckinController extends Controller// Was the asset updated?if ($asset->save()) {- event(new AssetCheckedIn($asset, $target, Auth::user(), $request->input('note')));+ event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note')));if ($backto=='user') {return redirect()->route("users.show", $user->id)->with('success', trans('admin/hardware/message.checkin.success'));diff --git a/app/Http/Controllers/Components/ComponentCheckinController.php b/app/Http/Controllers/Components/ComponentCheckinController.phpindex fd91daa841..dfba1dcf84 100644--- a/app/Http/Controllers/Components/ComponentCheckinController.php+++ b/app/Http/Controllers/Components/ComponentCheckinController.php@@ -2,6 +2,7 @@namespace App\Http\Controllers\Components;+use App\Events\CheckoutableCheckedIn;use App\Events\ComponentCheckedIn;use App\Http\Controllers\Controller;use App\Models\Actionlog;@@ -94,7 +95,9 @@ class ComponentCheckinController extends ControllerDB::table('components_assets')->where('id', '=', $component_asset_id)->delete();}- event(new ComponentCheckedIn($component, $component_assets, Auth::user(), $request->input('checkin_qty'), $request->input('note')));+ $asset = Asset::find($component_assets->asset_id);++ event(new CheckoutableCheckedIn($component, $asset, Auth::user(), $request->input('note')));return redirect()->route('components.index')->with('success',trans('admin/components/message.checkout.success'));diff --git a/app/Http/Controllers/Components/ComponentCheckoutController.php b/app/Http/Controllers/Components/ComponentCheckoutController.phpindex c7e7fe3db5..bfa9e8967b 100644--- a/app/Http/Controllers/Components/ComponentCheckoutController.php+++ b/app/Http/Controllers/Components/ComponentCheckoutController.php@@ -2,6 +2,7 @@namespace App\Http\Controllers\Components;+use App\Events\CheckoutableCheckedOut;use App\Events\ComponentCheckedOut;use App\Http\Controllers\Controller;use App\Models\Asset;@@ -87,7 +88,7 @@ class ComponentCheckoutController extends Controller'asset_id' => $asset_id]);- event(new ComponentCheckedOut($component, $asset, $request->input('assigned_qty'), Auth::user()));+ event(new CheckoutableCheckedOut($component, $asset, Auth::user(), $request->input('note')));return redirect()->route('components.index')->with('success', trans('admin/components/message.checkout.success'));}diff --git a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php b/app/Http/Controllers/Consumables/ConsumableCheckoutController.phpindex 0b3d8c6c91..e3e3e11b03 100644--- a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php+++ b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php@@ -2,7 +2,7 @@namespace App\Http\Controllers\Consumables;-use App\Events\ConsumableCheckedOut;+use App\Events\CheckoutableCheckedOut;use App\Http\Controllers\Controller;use App\Models\Consumable;use App\Models\User;@@ -68,7 +68,7 @@ class ConsumableCheckoutController extends Controller'assigned_to' => e(Input::get('assigned_to'))]);- event(new ConsumableCheckedOut($consumable, $user, Auth::user(), $request->input('note')));+ event(new CheckoutableCheckedOut($consumable, $user, Auth::user(), $request->input('note')));// Redirect to the new consumable pagereturn redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.checkout.success'));diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.phpindex 9612028465..4bddbd5753 100644--- a/app/Http/Controllers/Licenses/LicenseCheckinController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php@@ -2,7 +2,7 @@namespace App\Http\Controllers\Licenses;-use App\Events\LicenseCheckedIn;+use App\Events\CheckoutableCheckedIn;use App\Models\Asset;use App\Models\License;use App\Models\LicenseSeat;@@ -91,7 +91,7 @@ class LicenseCheckinController extends Controller// Was the asset updated?if ($licenseSeat->save()) {- event(new LicenseCheckedIn($license, $return_to, Auth::user(), $request->input('note')));+ event(new CheckoutableCheckedIn($license, $return_to, Auth::user(), $request->input('note')));if ($backTo=='user') {return redirect()->route("users.show", $return_to->id)->with('success', trans('admin/licenses/message.checkin.success'));diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.phpindex a1a02c823b..5d878a1506 100644--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php@@ -2,17 +2,16 @@namespace App\Http\Controllers\Licenses;-use App\Events\LicenseCheckedOut;-use App\Events\LicenseSeatCheckedOut;+use App\Events\CheckoutableCheckedOut;use App\Http\Requests\LicenseCheckoutRequest;use App\Models\Asset;use App\Models\License;use App\Models\LicenseSeat;use App\Models\User;use Illuminate\Http\Request;-use App\Http\Controllers\Controller;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\Input;+use App\Http\Controllers\Controller;use Illuminate\Support\Facades\Validator;class LicenseCheckoutController extends Controller@@ -106,7 +105,7 @@ class LicenseCheckoutController extends Controller}if ($licenseSeat->save()) {- event(new LicenseSeatCheckedOut($licenseSeat, $target, Auth::user(), request('note')));+ event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('note')));return true;}@@ -123,7 +122,7 @@ class LicenseCheckoutController extends Controllerif ($licenseSeat->save()) {- event(new LicenseSeatCheckedOut($licenseSeat, $target, Auth::user(), request('note')));+ event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('note')));return true;}diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.phpnew file mode 100644index 0000000000..e06c6e1e40--- /dev/null+++ b/app/Listeners/CheckoutableListener.php@@ -0,0 +1,184 @@+<?php++namespace App\Listeners;++use App\Models\Accessory;+use App\Models\Asset;+use App\Models\CheckoutAcceptance;+use App\Models\Consumable;+use App\Models\LicenseSeat;+use App\Models\Recipients\AdminRecipient;+use App\Models\Setting;+use App\Models\User;+use App\Notifications\CheckinAccessoryNotification;+use App\Notifications\CheckinAssetNotification;+use App\Notifications\CheckinLicenseNotification;+use App\Notifications\CheckinLicenseSeatNotification;+use App\Notifications\CheckoutAccessoryNotification;+use App\Notifications\CheckoutAssetNotification;+use App\Notifications\CheckoutConsumableNotification;+use App\Notifications\CheckoutLicenseNotification;+use App\Notifications\CheckoutLicenseSeatNotification;+use Illuminate\Support\Facades\Notification;++class CheckoutableListener+{++ /**+ * Notify the user about the checked out checkoutable+ */+ public function onCheckedOut($event) {+ /**+ * When the item wasn't checked out to a user, we can't send notifications+ */+ if(! $event->checkedOutTo instanceof User) {+ return;+ }++ /**+ * Make a checkout acceptance and attach it in the notification+ */+ $acceptance = $this->getCheckoutAcceptance($event);++ Notification::send(+ $this->getNotifiables($event),+ $this->getCheckoutNotification($event, $acceptance)+ );+ }++ /**+ * Notify the user about the checked in checkoutable+ */+ public function onCheckedIn($event) {+ /**+ * When the item wasn't checked out to a user, we can't send notifications+ */+ if(!$event->checkedOutTo instanceof User) {+ return;+ }++ /**+ * Send the appropriate notification+ */+ Notification::send(+ $this->getNotifiables($event),+ $this->getCheckinNotification($event)+ );+ }++ /**+ * Generates a checkout acceptance+ * @param Event $event+ * @return mixed+ */+ private function getCheckoutAcceptance($event) {+ if (!$event->checkoutable->requireAcceptance()) {+ return null;+ }++ $acceptance = new CheckoutAcceptance;+ $acceptance->checkoutable()->associate($event->checkoutable);+ $acceptance->assignedTo()->associate($event->checkedOutTo);+ $acceptance->save();++ return $acceptance;+ }++ /**+ * Gets the entities to be notified of the passed event+ *+ * @param Event $event+ * @return Collection+ */+ private function getNotifiables($event) {+ $notifiables = collect();++ /**+ * Notify the user who checked out the item+ */+ $notifiables->push($event->checkedOutTo);++ /**+ * Notify Admin users if the settings is activated+ */+ if (Setting::getSettings()->admin_cc_email != '') {+ $notifiables->push(new AdminRecipient());+ }++ return $notifiables;+ }++ /**+ * Get the appropriate notification for the event+ *+ * @param CheckoutableCheckedIn $event+ * @return Notification+ */+ private function getCheckinNotification($event) {++ $model = get_class($event->checkoutable);++ $notificationClass = null;++ switch (get_class($event->checkoutable)) {+ case Accessory::class:+ $notificationClass = CheckinAccessoryNotification::class;+ break;+ case Asset::class:+ $notificationClass = CheckinAssetNotification::class;+ break;+ case LicenseSeat::class:+ $notificationClass = CheckinLicenseSeatNotification::class;+ break;+ }++ return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);+ }++ /**+ * Get the appropriate notification for the event+ *+ * @param CheckoutableCheckedIn $event+ * @param CheckoutAcceptance $acceptance+ * @return Notification+ */+ private function getCheckoutNotification($event, $acceptance) {+ $notificationClass = null;++ switch (get_class($event->checkoutable)) {+ case Accessory::class:+ $notificationClass = CheckoutAccessoryNotification::class;+ break;+ case Asset::class:+ $notificationClass = CheckoutAssetNotification::class;+ break;+ case Consumable::class:+ $notificationClass = CheckoutConsumableNotification::class;+ break;+ case LicenseSeat::class:+ $notificationClass = CheckoutLicenseSeatNotification::class;+ break;+ }++ return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note);+ }++ /**+ * Register the listeners for the subscriber.+ *+ * @param Illuminate\Events\Dispatcher $events+ */+ public function subscribe($events)+ {+ $events->listen(+ 'App\Events\CheckoutableCheckedIn',+ 'App\Listeners\CheckoutableListener@onCheckedIn'+ );++ $events->listen(+ 'App\Events\CheckoutableCheckedOut',+ 'App\Listeners\CheckoutableListener@onCheckedOut'+ );+ }++}\ No newline at end of filediff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.phpindex 9cd8ec2717..cdb4fda1fc 100644--- a/app/Listeners/LogListener.php+++ b/app/Listeners/LogListener.php@@ -8,6 +8,8 @@ use App\Events\AssetCheckedIn;use App\Events\AssetCheckedOut;use App\Events\CheckoutAccepted;use App\Events\CheckoutDeclined;+use App\Events\CheckoutableCheckedIn;+use App\Events\CheckoutableCheckedOut;use App\Events\ComponentCheckedIn;use App\Events\ComponentCheckedOut;use App\Events\ConsumableCheckedOut;@@ -23,50 +25,14 @@ use App\Models\LicenseSeat;class LogListener{- public function onAccessoryCheckedIn(AccessoryCheckedIn $event) {- $event->accessory->logCheckin($event->checkedOutTo, $event->note);- }-- public function onAccessoryCheckedOut(AccessoryCheckedOut $event) {- $event->accessory->logCheckout($event->note, $event->checkedOutTo);- }- public function onAssetCheckedIn(AssetCheckedIn $event) {- $event->asset->logCheckin($event->checkedOutTo, $event->note);- }-- public function onAssetCheckedOut(AssetCheckedOut $event) {- $event->asset->logCheckout($event->note, $event->checkedOutTo);- }-- public function onComponentCheckedIn(ComponentCheckedIn $event) {- $log = new Actionlog();- $log->user_id = $event->checkedInBy->id;- $log->action_type = 'checkin from';- $log->target_type = Asset::class;- $log->target_id = $event->checkedOutTo->asset_id;- $log->item_id = $event->checkedOutTo->component_id;- $log->item_type = Component::class;- $log->note = $event->note;- $log->save();+ public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event) {+ $event->checkoutable->logCheckin($event->checkedOutTo, $event->note);}- public function onComponentCheckedOut(ComponentCheckedOut $event) {- // Since components don't have a "note" field, submit empty note- $event->component->logCheckout(null, $event->checkedOutTo);- }-- public function onConsumableCheckedOut(ConsumableCheckedOut $event) {- $event->consumable->logCheckout($event->note, $event->checkedOutTo);- }-- public function onLicenseCheckedIn(LicenseCheckedIn $event) {- $event->license->logCheckin($event->checkedOutTo, $event->note);- }-- public function onLicenseCheckedOut(LicenseCheckedOut $event) {- $event->license->logCheckout($event->note, $event->checkedOutTo);- }+ public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event) {+ $event->checkoutable->logCheckout($event->note, $event->checkedOutTo);+ }public function onCheckoutAccepted(CheckoutAccepted $event) {$logaction = new Actionlog();@@ -107,15 +73,8 @@ class LogListenerpublic function subscribe($events){$list = [- 'AccessoryCheckedIn',- 'AccessoryCheckedOut',- 'AssetCheckedIn',- 'AssetCheckedOut',- 'ComponentCheckedIn',- 'ComponentCheckedOut',- 'ConsumableCheckedOut',- 'LicenseCheckedIn',- 'LicenseCheckedOut',+ 'CheckoutableCheckedIn',+ 'CheckoutableCheckedOut','CheckoutAccepted','CheckoutDeclined',];diff --git a/app/Listeners/SendingCheckInNotificationsListener.php b/app/Listeners/SendingCheckInNotificationsListener.phpdeleted file mode 100644index aa176e19fd..0000000000--- a/app/Listeners/SendingCheckInNotificationsListener.php+++ /dev/null@@ -1,117 +0,0 @@-<?php--namespace App\Listeners;--use App\Models\Recipients\AdminRecipient;-use App\Models\Setting;-use App\Models\User;-use App\Notifications\CheckinAccessoryNotification;-use App\Notifications\CheckinAssetNotification;-use App\Notifications\CheckinLicenseNotification;-use App\Notifications\CheckoutAccessoryNotification;-use App\Notifications\CheckoutAssetNotification;-use App\Notifications\CheckoutConsumableNotification;-use App\Notifications\CheckoutLicenseNotification;-use Illuminate\Support\Facades\Notification;--class SendingCheckInNotificationsListener-{- /**- * Notify the user about the checked in accessory- */- public function onAccessoryCheckedIn($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- Notification::send(- $this->getNotifiables($event),- new CheckinAccessoryNotification($event->accessory, $event->checkedOutTo, $event->checkedInBy, $event->note)- );- }-- /**- * Notify the user about the checked in asset- */- public function onAssetCheckedIn($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- Notification::send(- $this->getNotifiables($event),- new CheckinAssetNotification($event->asset, $event->checkedOutTo, $event->checkedInBy, $event->note)- );- }-- /**- * Notify the user about the checked in license- */- public function onLicenseSeatCheckedIn($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- Notification::send(- $this->getNotifiables($event),- new CheckinLicenseSeatNotification($event->licenseSeat, $event->checkedOutTo, $event->checkedInBy, $event->note)- );- }-- /**- * Gets the entities to be notified of the passed event- *- * @param Event $event- * @return Collection- */- private function getNotifiables($event) {- $notifiables = collect();-- /**- * Notify the user who checked out the item- */- $notifiables->push($event->checkedOutTo);-- /**- * Notify Admin users if the settings is activated- */- if (Setting::getSettings()->admin_cc_email != '') {- $notifiables->push(new AdminRecipient());- }-- return $notifiables;- }-- /**- * Register the listeners for the subscriber.- *- * @param Illuminate\Events\Dispatcher $events- */- public function subscribe($events)- {- $events->listen(- 'App\Events\AccessoryCheckedIn',- 'App\Listeners\SendingCheckInNotificationsListener@onAccessoryCheckedIn'- );-- $events->listen(- 'App\Events\AssetCheckedIn',- 'App\Listeners\SendingCheckInNotificationsListener@onAssetCheckedIn'- );-- $events->listen(- 'App\Events\LicenseSeatCheckedIn',- 'App\Listeners\SendingCheckInNotificationsListener@onLicenseSeatCheckedIn'- );- }--}\ No newline at end of filediff --git a/app/Listeners/SendingCheckOutNotificationsListener.php b/app/Listeners/SendingCheckOutNotificationsListener.phpdeleted file mode 100644index ed459c5a59..0000000000--- a/app/Listeners/SendingCheckOutNotificationsListener.php+++ /dev/null@@ -1,182 +0,0 @@-<?php--namespace App\Listeners;--use App\Models\CheckoutAcceptance;-use App\Models\Recipients\AdminRecipient;-use App\Models\Setting;-use App\Models\User;-use App\Notifications\CheckoutAccessoryNotification;-use App\Notifications\CheckoutAssetNotification;-use App\Notifications\CheckoutConsumableNotification;-use App\Notifications\CheckoutLicenseNotification;-use App\Notifications\CheckoutLicenseSeatNotification;-use Illuminate\Support\Facades\Notification;--class SendingCheckOutNotificationsListener-{- /**- * Notify the user about the checked out consumable- */- public function onConsumableCheckedOut($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- /**- * Make a checkout acceptance and attach it in the notification- */- $acceptance = null;- if ($event->consumable->requireAcceptance()) {- $acceptance = new CheckoutAcceptance;- $acceptance->checkoutable()->associate($event->consumable);- $acceptance->assignedTo()->associate($event->checkedOutTo);- $acceptance->save();- }-- Notification::send(- $this->getNotifiables($event),- new CheckoutConsumableNotification($event->consumable, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note)- );- }-- /**- * Notify the user about the checked out accessory- */- public function onAccessoryCheckedOut($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- /**- * Make a checkout acceptance and attach it in the notification- */- $acceptance = null;- if ($event->accessory->requireAcceptance()) {- $acceptance = new CheckoutAcceptance;- $acceptance->checkoutable()->associate($event->accessory);- $acceptance->assignedTo()->associate($event->checkedOutTo);- $acceptance->save();- }-- Notification::send(- $this->getNotifiables($event),- new CheckoutAccessoryNotification($event->accessory, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note)- );- }-- /**- * Notify the user about the checked out license- */- public function onLicenseSeatCheckedOut($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- /**- * Make a checkout acceptance and attach it in the notification- */- $acceptance = null;- if ($event->licenseSeat->license->requireAcceptance()) {- $acceptance = new CheckoutAcceptance;- $acceptance->checkoutable()->associate($event->licenseSeat);- $acceptance->assignedTo()->associate($event->checkedOutTo);- $acceptance->save();- }-- Notification::send(- $this->getNotifiables($event),- new CheckoutLicenseSeatNotification($event->licenseSeat, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note)- );- }-- /**- * Notify the user about the checked out asset- */- public function onAssetCheckedOut($event) {- /**- * When the item wasn't checked out to a user, we can't send notifications- */- if(! $event->checkedOutTo instanceof User) {- return;- }-- /**- * Make a checkout acceptance and attach it in the notification- */- $acceptance = null;- if ($event->asset->requireAcceptance()) {- $acceptance = new CheckoutAcceptance;- $acceptance->checkoutable()->associate($event->asset);- $acceptance->assignedTo()->associate($event->checkedOutTo);- $acceptance->save();- }-- Notification::send(- $this->getNotifiables($event),- new CheckoutAssetNotification($event->asset, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note)- );- }-- /**- * Gets the entities to be notified of the passed event- *- * @param Event $event- * @return Collection- */- private function getNotifiables($event) {- $notifiables = collect();-- /**- * Notify the user who checked out the item- */- $notifiables->push($event->checkedOutTo);-- /**- * Notify Admin users if the settings is activated- */- if (Setting::getSettings()->admin_cc_email != '') {- $notifiables->push(new AdminRecipient());- }-- return $notifiables;- }-- /**- * Register the listeners for the subscriber.- *- * @param Illuminate\Events\Dispatcher $events- */- public function subscribe($events)- {- $events->listen(- 'App\Events\ConsumableCheckedOut',- 'App\Listeners\SendingCheckOutNotificationsListener@onConsumableCheckedOut'- );-- $events->listen(- 'App\Events\AccessoryCheckedOut',- 'App\Listeners\SendingCheckOutNotificationsListener@onAccessoryCheckedOut'- );-- $events->listen(- 'App\Events\LicenseSeatCheckedOut',- 'App\Listeners\SendingCheckOutNotificationsListener@onLicenseSeatCheckedOut'- );-- $events->listen(- 'App\Events\AssetCheckedOut',- 'App\Listeners\SendingCheckOutNotificationsListener@onAssetCheckedOut'- );- }--}\ No newline at end of filediff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex 35206b41ea..ceb6ee6962 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -2,6 +2,7 @@namespace App\Models;use App\Events\AssetCheckedOut;+use App\Events\CheckoutableCheckedOut;use App\Exceptions\CheckoutNotAllowed;use App\Http\Traits\UniqueSerialTrait;use App\Http\Traits\UniqueUndeletedTrait;@@ -265,7 +266,7 @@ class Asset extends Depreciableif ($this->save()) {- event(new AssetCheckedOut($this, $target, Auth::user(), $note));+ event(new CheckoutableCheckedOut($this, $target, Auth::user(), $note));$this->increment('checkout_counter', 1);return true;diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex df3c643b24..28c3aecf06 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -3,9 +3,8 @@namespace App\Providers;use Illuminate\Support\Facades\Event;+use App\Listeners\CheckoutableListener;use App\Listeners\LogListener;-use App\Listeners\SendingCheckInNotificationsListener;-use App\Listeners\SendingCheckOutNotificationsListener;use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;class EventServiceProvider extends ServiceProvider@@ -32,9 +31,8 @@ class EventServiceProvider extends ServiceProvider* @var array*/protected $subscribe = [- SendingCheckOutNotificationsListener::class,- SendingCheckInNotificationsListener::class,- LogListener::class+ LogListener::class,+ CheckoutableListener::class];/**