Handle side effects of accepting/declining
When declining an asset, it gets checked in.
This commit is contained in:
+9
-43
@@ -5,7 +5,7 @@ use App\Events\AssetCheckedOut;
|
||||
use App\Exceptions\CheckoutNotAllowed;
|
||||
use App\Http\Traits\UniqueSerialTrait;
|
||||
use App\Http\Traits\UniqueUndeletedTrait;
|
||||
use App\Models\Contracts\Acceptable as AcceptableContract;
|
||||
use App\Models\Traits\Acceptable;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Models\User;
|
||||
use App\Presenters\Presentable;
|
||||
@@ -20,13 +20,12 @@ use Watson\Validating\ValidatingTrait;
|
||||
use DB;
|
||||
use App\Notifications\CheckinAssetNotification;
|
||||
use App\Notifications\CheckoutAssetNotification;
|
||||
|
||||
/**
|
||||
* Model for Assets.
|
||||
*
|
||||
* @version v1.0
|
||||
*/
|
||||
class Asset extends Depreciable implements AcceptableContract
|
||||
class Asset extends Depreciable
|
||||
{
|
||||
protected $presenter = 'App\Presenters\AssetPresenter';
|
||||
use Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait, UniqueSerialTrait;
|
||||
@@ -36,52 +35,19 @@ class Asset extends Depreciable implements AcceptableContract
|
||||
const USER = 'user';
|
||||
|
||||
const ACCEPTANCE_PENDING = 'pending';
|
||||
use Acceptable;
|
||||
|
||||
/**
|
||||
* Accept the asset
|
||||
* Run after the checkout acceptance was declined by the user
|
||||
*
|
||||
* @param User $acceptedBy The user who accepts the asset
|
||||
* @param string $signature The filename of the signature, if provided
|
||||
*/
|
||||
public function accept(User $acceptedBy, $signature = null) {
|
||||
$this->accepted = 'accepted';
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decline the asset
|
||||
*
|
||||
* @param User $declinedBy The user who declines the asset
|
||||
* @param string $signature The filename of the signature, if provided
|
||||
*/
|
||||
public function decline(User $declinedBy, $signature = null) {
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
*/
|
||||
public function declinedCheckout(User $declinedBy, $signature) {
|
||||
$this->assigned_to = null;
|
||||
$this->assigned_type = null;
|
||||
$this->accepted = null;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the asset already accepted?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAccepted() : bool {
|
||||
return $this->accepted != 'pending';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the asset checked out to this user?
|
||||
*
|
||||
* @param User $user
|
||||
* @return boolean
|
||||
*/
|
||||
public function isCheckedOutTo(User $user) {
|
||||
if (is_null($this->assignedTo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->assignedTo->is($user);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user