diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 5c7235a2ae..3e37871aa4 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -85,11 +85,7 @@ class AcceptanceController extends Controller { if ($request->input('asset_acceptance') == 'accepted') { - $acceptance->accepted_at = now(); - $acceptance->signature_filename = $sig_filename; - $acceptance->save(); - - // TODO: Update state for the checkoutable + $acceptance->accept($sig_filename); event(new CheckoutAccepted($acceptance)); @@ -97,11 +93,7 @@ class AcceptanceController extends Controller { } else { - $acceptance->declined_at = now(); - $acceptance->signature_filename = $sig_filename; - $acceptance->save(); - - // TODO: Update state for the checkoutable + $acceptance->decline($sig_filename); event(new CheckoutDeclined($acceptance)); diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index cdba5f3206..76b50704c6 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -1,6 +1,7 @@ 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(); } diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index f3d2355e53..28442a0aeb 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -40,6 +40,28 @@ class CheckoutAcceptance extends Model return $this->assignedTo->is($user); } + public function accept($signature_filename) { + $this->accepted_at = now(); + $this->signature_filename = $signature_filename; + $this->save(); + + /** + * Update state for the checked out item + */ + $this->checkoutable->acceptedCheckout($this->assignedTo, $signature_filename); + } + + public function decline($signature_filename) { + $this->declined_at = now(); + $this->signature_filename = $signature_filename; + $this->save(); + + /** + * Update state for the checked out item + */ + $this->checkoutable->declinedCheckout($this->assignedTo, $signature_filename); + } + public function scopeForUser(Builder $query, User $user) { return $query->where('assigned_to_id', $user->id); } diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 1b3a0da156..596106c262 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -1,6 +1,7 @@