Adds checkout events

This commit is contained in:
Till Deeke 2018-07-21 14:01:30 +02:00
parent f0acf47101
commit ea64abc607
6 changed files with 160 additions and 1 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}