From fd73bee8505b766d102cb2003ae6bb6e0437dc92 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:38:05 -0800 Subject: [PATCH 01/40] Fixed hardcoded string and added new checkout count to accessory view Signed-off-by: snipe --- resources/views/accessories/view.blade.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php index 82d7c8201a..59ff1b9c80 100644 --- a/resources/views/accessories/view.blade.php +++ b/resources/views/accessories/view.blade.php @@ -327,13 +327,22 @@
- Number remaining + {{ trans('admin/accessories/general.remaining') }}
{{ $accessory->numRemaining() }}
+
+
+ {{ trans('general.checked_out') }} +
+
+ {{ $accessory->users_count }} +
+
+ @can('checkout', \App\Models\Accessory::class) From 56090bc64534f73d9e2cab10ff4f70e4d97d65ef Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:38:35 -0800 Subject: [PATCH 02/40] Re-ordered notes to be more consistent, fixed missing iCheck class Signed-off-by: snipe --- resources/views/accessories/edit.blade.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/views/accessories/edit.blade.php b/resources/views/accessories/edit.blade.php index d6233d4e5a..c16e57cb22 100755 --- a/resources/views/accessories/edit.blade.php +++ b/resources/views/accessories/edit.blade.php @@ -21,22 +21,24 @@ @include ('partials.forms.edit.purchase_cost') @include ('partials.forms.edit.quantity') @include ('partials.forms.edit.minimum_quantity') - +@include ('partials.forms.edit.notes') @if ($item->image)
- {{ Form::checkbox('image_delete') }} - - {!! $errors->first('image_delete', '') !!} + +
+ +
@endif -@include ('partials.forms.edit.notes') - @include ('partials.forms.edit.image-upload') @stop From 46e3e8a3dd9b80e1c33b0a3af951ec547f8b638c Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:39:53 -0800 Subject: [PATCH 03/40] Added new users_count field to API Signed-off-by: snipe --- app/Presenters/AccessoryPresenter.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php index 7d77acc8d7..cc4f9badfc 100644 --- a/app/Presenters/AccessoryPresenter.php +++ b/app/Presenters/AccessoryPresenter.php @@ -80,19 +80,25 @@ class AccessoryPresenter extends Presenter ], [ 'field' => 'qty', 'searchable' => false, - 'sortable' => false, - 'title' => trans('admin/accessories/general.total'), - ], [ - 'field' => 'min_qty', - 'searchable' => false, 'sortable' => true, - 'title' => trans('general.min_amt'), + 'title' => trans('admin/accessories/general.total'), ], [ 'field' => 'remaining_qty', 'searchable' => false, 'sortable' => false, 'visible' => false, 'title' => trans('admin/accessories/general.remaining'), + ],[ + 'field' => 'users_count', + 'searchable' => false, + 'sortable' => true, + 'visible' => true, + 'title' => trans('general.checked_out'), + ], [ + 'field' => 'min_qty', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.min_amt'), ], [ 'field' => 'purchase_date', 'searchable' => true, From dceb77d4d4a70df6a1ab0b4a70b1bf0ad500e64a Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:40:20 -0800 Subject: [PATCH 04/40] Refactored numRemaining, removed unnecessary numCheckout Signed-off-by: snipe --- app/Models/Accessory.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 3f2004b047..d39d653382 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -327,20 +327,6 @@ class Accessory extends SnipeModel return null; } - /** - * Check how many items within an accessory are checked out - * - * @author [A. Gianotto] [] - * @since [v5.0] - * @return int - */ - public function numCheckedOut() - { - $checkedout = 0; - $checkedout = $this->users->count(); - - return $checkedout; - } /** * Check how many items of an accessory remain @@ -351,11 +337,11 @@ class Accessory extends SnipeModel */ public function numRemaining() { - $checkedout = $this->users->count(); + $checkedout = $this->users_count; $total = $this->qty; $remaining = $total - $checkedout; - return $remaining; + return (int) $remaining; } /** From 90c16318201b45fa233e07ca19f0e4f8a38c7c54 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:40:35 -0800 Subject: [PATCH 05/40] Added users_count to transformer for API Signed-off-by: snipe --- app/Http/Transformers/AccessoriesTransformer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php index 6f254b3b87..00c30f9ea2 100644 --- a/app/Http/Transformers/AccessoriesTransformer.php +++ b/app/Http/Transformers/AccessoriesTransformer.php @@ -38,7 +38,8 @@ class AccessoriesTransformer 'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost), 'order_number' => ($accessory->order_number) ? e($accessory->order_number) : null, 'min_qty' => ($accessory->min_amt) ? (int) $accessory->min_amt : null, - 'remaining_qty' => $accessory->numRemaining(), + 'remaining_qty' => (int) $accessory->numRemaining(), + 'users_count' => $accessory->users_count, 'created_at' => Helper::getFormattedDateObject($accessory->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($accessory->updated_at, 'datetime'), From 60eab08735187044240c3f180867411c9b772813 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:41:07 -0800 Subject: [PATCH 06/40] =?UTF-8?q?Added=20`->with(=E2=80=98users=20as=20use?= =?UTF-8?q?rs=5Fcount=E2=80=99)`=20in=20Accessory=20query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- .../Accessories/AccessoriesController.php | 74 +++++++++---------- .../Controllers/Api/AccessoriesController.php | 5 +- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.php index d1af79adf1..96f83d7665 100755 --- a/app/Http/Controllers/Accessories/AccessoriesController.php +++ b/app/Http/Controllers/Accessories/AccessoriesController.php @@ -127,45 +127,45 @@ class AccessoriesController extends Controller */ public function update(ImageUploadRequest $request, $accessoryId = null) { - if (is_null($accessory = Accessory::find($accessoryId))) { + if ($accessory = Accessory::withCount('users as users_count')->find($accessoryId)) { + + $validator = Validator::make($request->all(), [ + "qty" => "required|numeric|min:$accessory->users_count" + ]); + + if ($validator->fails()) { + return redirect()->back() + ->withErrors($validator) + ->withInput(); + } + + $this->authorize($accessory); + + // Update the accessory data + $accessory->name = request('name'); + $accessory->location_id = request('location_id'); + $accessory->min_amt = request('min_amt'); + $accessory->category_id = request('category_id'); + $accessory->company_id = Company::getIdForCurrentUser(request('company_id')); + $accessory->manufacturer_id = request('manufacturer_id'); + $accessory->order_number = request('order_number'); + $accessory->model_number = request('model_number'); + $accessory->purchase_date = request('purchase_date'); + $accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost')); + $accessory->qty = request('qty'); + $accessory->supplier_id = request('supplier_id'); + $accessory->notes = request('notes'); + + $accessory = $request->handleImages($accessory); + + // Was the accessory updated? + if ($accessory->save()) { + return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success')); + } + } else { return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); } - $min = $accessory->numCheckedOut(); - $validator = Validator::make($request->all(), [ - "qty" => "required|numeric|min:$min" - ]); - - if ($validator->fails()) { - return redirect()->back() - ->withErrors($validator) - ->withInput(); - } - - $this->authorize($accessory); - - // Update the accessory data - $accessory->name = request('name'); - $accessory->location_id = request('location_id'); - $accessory->min_amt = request('min_amt'); - $accessory->category_id = request('category_id'); - $accessory->company_id = Company::getIdForCurrentUser(request('company_id')); - $accessory->manufacturer_id = request('manufacturer_id'); - $accessory->order_number = request('order_number'); - $accessory->model_number = request('model_number'); - $accessory->purchase_date = request('purchase_date'); - $accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost')); - $accessory->qty = request('qty'); - $accessory->supplier_id = request('supplier_id'); - $accessory->notes = request('notes'); - - $accessory = $request->handleImages($accessory); - - // Was the accessory updated? - if ($accessory->save()) { - return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success')); - } - return redirect()->back()->withInput()->withErrors($accessory->getErrors()); } @@ -217,7 +217,7 @@ class AccessoriesController extends Controller */ public function show($accessoryID = null) { - $accessory = Accessory::find($accessoryID); + $accessory = Accessory::withCount('users as users_count')->find($accessoryID); $this->authorize('view', $accessory); if (isset($accessory->id)) { return view('accessories/view', compact('accessory')); diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index a894dc3760..fd21ebaf3a 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -41,10 +41,13 @@ class AccessoriesController extends Controller 'min_amt', 'company_id', 'notes', + 'users_count', + 'qty', ]; - $accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'users', 'location', 'supplier'); + $accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'users', 'location', 'supplier') + ->withCount('users as users_count'); if ($request->filled('search')) { $accessories = $accessories->TextSearch($request->input('search')); From 2bdf3d3f44cc460c26f68949891ea16c5f0025c8 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:44:10 -0800 Subject: [PATCH 07/40] Missed a few strong HTML tags Signed-off-by: snipe --- resources/views/accessories/view.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php index 59ff1b9c80..fd31722204 100644 --- a/resources/views/accessories/view.blade.php +++ b/resources/views/accessories/view.blade.php @@ -290,7 +290,7 @@ @if ($accessory->company)
- {{ trans('general.company')}} + {{ trans('general.company')}}
{{ $accessory->company->name }} @@ -302,7 +302,7 @@ @if ($accessory->category)
- {{ trans('general.category')}} + {{ trans('general.category')}}
{{ $accessory->category->name }} From 563a252d180b0d2ad20101e05a30b5f5ef47f35b Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 14:57:52 -0800 Subject: [PATCH 08/40] Updated checkboxed with missing `minimal` class for iCheck Signed-off-by: snipe --- resources/views/accessories/edit.blade.php | 6 ++---- resources/views/categories/edit.blade.php | 2 +- resources/views/companies/edit.blade.php | 2 +- resources/views/components/edit.blade.php | 2 +- resources/views/consumables/edit.blade.php | 5 +++-- resources/views/departments/edit.blade.php | 2 +- resources/views/locations/edit.blade.php | 2 +- resources/views/manufacturers/edit.blade.php | 2 +- resources/views/models/edit.blade.php | 2 +- resources/views/suppliers/edit.blade.php | 2 +- resources/views/users/edit.blade.php | 3 ++- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/resources/views/accessories/edit.blade.php b/resources/views/accessories/edit.blade.php index d6233d4e5a..6bef8201b6 100755 --- a/resources/views/accessories/edit.blade.php +++ b/resources/views/accessories/edit.blade.php @@ -21,22 +21,20 @@ @include ('partials.forms.edit.purchase_cost') @include ('partials.forms.edit.quantity') @include ('partials.forms.edit.minimum_quantity') - +@include ('partials.forms.edit.notes') @if ($item->image)
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', '') !!}
@endif -@include ('partials.forms.edit.notes') - @include ('partials.forms.edit.image-upload') @stop diff --git a/resources/views/categories/edit.blade.php b/resources/views/categories/edit.blade.php index 9d4d25c814..e09182743d 100755 --- a/resources/views/categories/edit.blade.php +++ b/resources/views/categories/edit.blade.php @@ -91,7 +91,7 @@
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', ':message') !!}
diff --git a/resources/views/companies/edit.blade.php b/resources/views/companies/edit.blade.php index bc74c7357d..a2bf8e5d84 100644 --- a/resources/views/companies/edit.blade.php +++ b/resources/views/companies/edit.blade.php @@ -15,7 +15,7 @@
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', ':message') !!}
diff --git a/resources/views/components/edit.blade.php b/resources/views/components/edit.blade.php index 77cdb17c3c..8c7c74d6e8 100644 --- a/resources/views/components/edit.blade.php +++ b/resources/views/components/edit.blade.php @@ -26,7 +26,7 @@
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', ':message') !!}
diff --git a/resources/views/consumables/edit.blade.php b/resources/views/consumables/edit.blade.php index a270cc33db..4ae61fa0a5 100644 --- a/resources/views/consumables/edit.blade.php +++ b/resources/views/consumables/edit.blade.php @@ -20,20 +20,21 @@ @include ('partials.forms.edit.purchase_cost') @include ('partials.forms.edit.quantity') @include ('partials.forms.edit.minimum_quantity') +@include ('partials.forms.edit.notes') @if ($item->image)
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', ':message') !!}
@endif -@include ('partials.forms.edit.notes') + @include ('partials.forms.edit.image-upload') @stop diff --git a/resources/views/departments/edit.blade.php b/resources/views/departments/edit.blade.php index 0a2c1a7d46..b120b2924a 100644 --- a/resources/views/departments/edit.blade.php +++ b/resources/views/departments/edit.blade.php @@ -28,7 +28,7 @@
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', ':message') !!}
diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php index c7fe202fa8..86cf7894bd 100755 --- a/resources/views/locations/edit.blade.php +++ b/resources/views/locations/edit.blade.php @@ -49,7 +49,7 @@

Image for {{ $item->name }} diff --git a/resources/views/manufacturers/edit.blade.php b/resources/views/manufacturers/edit.blade.php index 355dd478df..bc3012f8a6 100755 --- a/resources/views/manufacturers/edit.blade.php +++ b/resources/views/manufacturers/edit.blade.php @@ -56,7 +56,7 @@

Image for {{ $item->name }} diff --git a/resources/views/models/edit.blade.php b/resources/views/models/edit.blade.php index 436e425179..1f2deff371 100755 --- a/resources/views/models/edit.blade.php +++ b/resources/views/models/edit.blade.php @@ -45,7 +45,7 @@

Image for {{ $item->name }} diff --git a/resources/views/suppliers/edit.blade.php b/resources/views/suppliers/edit.blade.php index 8a9014f708..285d6627c1 100755 --- a/resources/views/suppliers/edit.blade.php +++ b/resources/views/suppliers/edit.blade.php @@ -49,7 +49,7 @@

Image for {{ $item->name }} diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 93b8fb7a21..7428fafe7f 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -272,12 +272,13 @@
@endif + @if ($user->avatar)
- {{ Form::checkbox('image_delete') }} + {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} {!! $errors->first('image_delete', '
:message
') !!}
From cfa342c81aaa8e894500f17d8e9f7f1db3de0b20 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 21 Jan 2023 16:23:04 -0800 Subject: [PATCH 09/40] =?UTF-8?q?Updated=20HTML=20for=20=E2=80=9Cstandard?= =?UTF-8?q?=E2=80=9D=20image=20edit/delete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- resources/views/accessories/edit.blade.php | 21 ++++++++++------ resources/views/categories/edit.blade.php | 23 ++++++++++------- resources/views/companies/edit.blade.php | 20 +++++++++------ resources/views/components/edit.blade.php | 19 +++++++++----- resources/views/consumables/edit.blade.php | 19 +++++++++----- resources/views/departments/edit.blade.php | 19 +++++++++----- resources/views/hardware/edit.blade.php | 25 ++++++++++--------- resources/views/locations/edit.blade.php | 18 ++++++++------ resources/views/manufacturers/edit.blade.php | 13 ++++------ resources/views/models/edit.blade.php | 26 +++++++++++--------- resources/views/suppliers/edit.blade.php | 20 ++++++++------- resources/views/users/edit.blade.php | 21 ++++++++++------ 12 files changed, 149 insertions(+), 95 deletions(-) diff --git a/resources/views/accessories/edit.blade.php b/resources/views/accessories/edit.blade.php index 6bef8201b6..532336182b 100755 --- a/resources/views/accessories/edit.blade.php +++ b/resources/views/accessories/edit.blade.php @@ -24,13 +24,20 @@ @include ('partials.forms.edit.notes') -@if ($item->image) -
- -
- {{ Form::checkbox('image_delete', '1', old('image_delete'), array('class' => 'minimal', 'aria-label'=>'image_delete')) }} - - {!! $errors->first('image_delete', '') !!} +@if (($item->image) && ($item->image!='')) +
+
+ +
+
+
+
+ + {!! $errors->first('image_delete', ':message') !!}
@endif diff --git a/resources/views/categories/edit.blade.php b/resources/views/categories/edit.blade.php index e09182743d..3d24650a73 100755 --- a/resources/views/categories/edit.blade.php +++ b/resources/views/categories/edit.blade.php @@ -74,9 +74,7 @@
-
-
-
+