From 2353c8199cde14768c7f494736082417815217d5 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 22 Nov 2023 15:25:22 +0000 Subject: [PATCH] Set qty mutators Signed-off-by: snipe --- app/Models/Accessory.php | 29 +++++++++++++++++++++++++++++ app/Models/Component.php | 31 +++++++++++++++++++++++++++++++ app/Models/Consumable.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 86502dc7e7..9a93c386fc 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -365,6 +365,35 @@ class Accessory extends SnipeModel $accessory_user->limit(1)->delete(); } + /** + * ----------------------------------------------- + * BEGIN MUTATORS + * ----------------------------------------------- + **/ + + /** + * This sets a value for qty if no value is given. The database does not allow this + * field to be null, and in the other areas of the code, we set a default, but the importer + * does not. + * + * This simply checks that there is a value for quantity, and if there isn't, set it to 0. + * + * @author A. Gianotto + * @since v6.3.4 + * @param $value + * @return void + */ + public function setQtyAttribute($value) + { + $this->attributes['qty'] = (!$value) ? 0 : intval($value); + } + + /** + * ----------------------------------------------- + * BEGIN QUERY SCOPES + * ----------------------------------------------- + **/ + /** * Query builder scope to order on company * diff --git a/app/Models/Component.php b/app/Models/Component.php index 052ec1219d..671b0101c4 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -224,6 +224,37 @@ class Component extends SnipeModel return $this->qty - $this->numCheckedOut(); } + + /** + * ----------------------------------------------- + * BEGIN MUTATORS + * ----------------------------------------------- + **/ + + /** + * This sets a value for qty if no value is given. The database does not allow this + * field to be null, and in the other areas of the code, we set a default, but the importer + * does not. + * + * This simply checks that there is a value for quantity, and if there isn't, set it to 0. + * + * @author A. Gianotto + * @since v6.3.4 + * @param $value + * @return void + */ + public function setQtyAttribute($value) + { + $this->attributes['qty'] = (!$value) ? 0 : intval($value); + } + + /** + * ----------------------------------------------- + * BEGIN QUERY SCOPES + * ----------------------------------------------- + **/ + + /** * Query builder scope to order on company * diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index a3a0d59178..008dffa4ca 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -339,6 +339,35 @@ class Consumable extends SnipeModel return $remaining; } + /** + * ----------------------------------------------- + * BEGIN MUTATORS + * ----------------------------------------------- + **/ + + /** + * This sets a value for qty if no value is given. The database does not allow this + * field to be null, and in the other areas of the code, we set a default, but the importer + * does not. + * + * This simply checks that there is a value for quantity, and if there isn't, set it to 0. + * + * @author A. Gianotto + * @since v6.3.4 + * @param $value + * @return void + */ + public function setQtyAttribute($value) + { + $this->attributes['qty'] = (!$value) ? 0 : intval($value); + } + + /** + * ----------------------------------------------- + * BEGIN QUERY SCOPES + * ----------------------------------------------- + **/ + /** * Query builder scope to order on company *