From 33b1ab3658d2e6fcaa2083fede60f7041fce8b06 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 10 May 2022 16:19:06 -0700 Subject: [PATCH 1/2] prevents values for assets being negative through validation --- app/Models/Asset.php | 2 +- resources/lang/en/validation.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index ac373b2ad4..3466cbffe7 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -111,7 +111,7 @@ class Asset extends Depreciable 'asset_tag' => 'required|min:1|max:255|unique_undeleted', 'status' => 'integer', 'serial' => 'unique_serial|nullable', - 'purchase_cost' => 'numeric|nullable', + 'purchase_cost' => 'numeric|nullable|gte:0', 'next_audit_date' => 'date|nullable', 'last_audit_date' => 'date|nullable', 'supplier_id' => 'exists:suppliers,id|nullable', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 72b465f211..5f097b717c 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -91,6 +91,10 @@ return [ 'url' => 'The :attribute format is invalid.', 'unique_undeleted' => 'The :attribute must be unique.', 'non_circular' => 'The :attribute must not create a circular reference.', + 'gte' => [ + 'numeric' => 'Value cannot be negative' + ], + /* |-------------------------------------------------------------------------- From 2c1f3688286bd3b6692800ffe6411ff3c21107ba Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 10 May 2022 16:26:06 -0700 Subject: [PATCH 2/2] adds validation for all purchase costs variables --- app/Models/Accessory.php | 2 +- app/Models/Component.php | 2 +- app/Models/Consumable.php | 2 +- app/Models/License.php | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index bc7c533832..50abf84b21 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -61,7 +61,7 @@ class Accessory extends SnipeModel 'category_id' => 'required|integer|exists:categories,id', 'company_id' => 'integer|nullable', 'min_amt' => 'integer|min:0|nullable', - 'purchase_cost' => 'numeric|nullable', + 'purchase_cost' => 'numeric|nullable|gte:0', ]; diff --git a/app/Models/Component.php b/app/Models/Component.php index a94371ec6f..fb841d3074 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -36,7 +36,7 @@ class Component extends SnipeModel 'company_id' => 'integer|nullable', 'min_amt' => 'integer|min:0|nullable', 'purchase_date' => 'date|nullable', - 'purchase_cost' => 'numeric|nullable', + 'purchase_cost' => 'numeric|nullable|gte:0', ]; /** diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 0c3dc247e7..bb0ebb60de 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -39,7 +39,7 @@ class Consumable extends SnipeModel 'category_id' => 'required|integer', 'company_id' => 'integer|nullable', 'min_amt' => 'integer|min:0|nullable', - 'purchase_cost' => 'numeric|nullable', + 'purchase_cost' => 'numeric|nullable|gte:0', ]; /** diff --git a/app/Models/License.php b/app/Models/License.php index 2c7efacf23..58b4854a33 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -48,6 +48,7 @@ class License extends Depreciable 'notes' => 'string|nullable', 'category_id' => 'required|exists:categories,id', 'company_id' => 'integer|nullable', + 'purchase_cost'=> 'numeric|nullable|gte:0', ]; /**