Skip to content

A free open source IT asset/license management system

Adds checkout events

Till Deekeea64abc60721
diff --git a/app/Events/AccessoryCheckedOut.php b/app/Events/AccessoryCheckedOut.php
new file mode 100644
index 0000000000..397500238d
--- /dev/null
+++ b/app/Events/AccessoryCheckedOut.php
@@ -0,0 +1,31 @@
+<?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, Actionlog $logEntry)
+ {
+ $this->accessory = $accessory;
+ $this->checkedOutTo = $checkedOutTo;
+ $this->logEntry = $logEntry;
+ }
+}
diff --git a/app/Events/AssetCheckedOut.php b/app/Events/AssetCheckedOut.php
new file mode 100644
index 0000000000..6d2fdea3a0
--- /dev/null
+++ b/app/Events/AssetCheckedOut.php
@@ -0,0 +1,31 @@
+<?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, Actionlog $logEntry)
+ {
+ $this->asset = $asset;
+ $this->checkedOutTo = $checkedOutTo;
+ $this->logEntry = $logEntry;
+ }
+}
diff --git a/app/Events/ComponentCheckedOut.php b/app/Events/ComponentCheckedOut.php
new file mode 100644
index 0000000000..81826a4d2f
--- /dev/null
+++ b/app/Events/ComponentCheckedOut.php
@@ -0,0 +1,31 @@
+<?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 ComponentCheckedOut
+{
+ use Dispatchable, SerializesModels;
+
+ public $component;
+ public $checkedOutTo;
+ public $logEntry;
+
+ /**
+ * Create a new event instance.
+ *
+ * @return void
+ */
+ public function __construct(Component $component, $checkedOutTo, Actionlog $logEntry)
+ {
+ $this->component = $component;
+ $this->checkedOutTo = $checkedOutTo;
+ $this->logEntry = $logEntry;
+ }
+}
diff --git a/app/Events/ConsumableCheckedOut.php b/app/Events/ConsumableCheckedOut.php
new file mode 100644
index 0000000000..df97561c38
--- /dev/null
+++ b/app/Events/ConsumableCheckedOut.php
@@ -0,0 +1,31 @@
+<?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, Actionlog $logEntry)
+ {
+ $this->consumable = $consumable;
+ $this->checkedOutTo = $checkedOutTo;
+ $this->logEntry = $logEntry;
+ }
+}
diff --git a/app/Events/LicenseCheckedOut.php b/app/Events/LicenseCheckedOut.php
new file mode 100644
index 0000000000..5d1b8335ec
--- /dev/null
+++ b/app/Events/LicenseCheckedOut.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Events;
+
+use App\Models\Actionlog;
+use App\Models\License;
+use App\Models\User;
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class LicenseCheckedOut
+{
+ use Dispatchable, SerializesModels;
+
+ public $license;
+ public $checkedOutTo;
+ public $logEntry;
+
+ /**
+ * Create a new event instance.
+ *
+ * @return void
+ */
+ public function __construct(License $license, $checkedOutTo, Actionlog $logEntry)
+ {
+ $this->license = $license;
+ $this->checkedOutTo = $checkedOutTo;
+ $this->logEntry = $logEntry;
+ }
+}
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 4805602f34..288cb04068 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -1,6 +1,7 @@
<?php
namespace App\Models;
+use App\Events\AssetCheckedOut;
use App\Exceptions\CheckoutNotAllowed;
use App\Http\Traits\UniqueSerialTrait;
use App\Http\Traits\UniqueUndeletedTrait;
@@ -266,7 +267,10 @@ class Asset extends Depreciable
}
if ($this->save()) {
- $this->logCheckout($note, $target);
+ $loggedAction = $this->logCheckout($note, $target);
+
+ event(new AssetCheckedOut($this, $target, $loggedAction));
+
$this->increment('checkout_counter', 1);
return true;
}