diff --git a/app/Actions/Categories/DestroyCategoryAction.php b/app/Actions/Categories/DestroyCategoryAction.php new file mode 100644 index 000000000000..305f88fc15ed --- /dev/null +++ b/app/Actions/Categories/DestroyCategoryAction.php @@ -0,0 +1,59 @@ +loadCount([ + 'assets as assets_count', + 'accessories as accessories_count', + 'consumables as consumables_count', + 'components as components_count', + 'licenses as licenses_count', + 'models as models_count' + ]); + + if ($category->assets_count > 0) { + throw new ItemStillHasAssets($category); + } + if ($category->accessories_count > 0) { + throw new ItemStillHasAccessories($category); + } + if ($category->consumables_count > 0) { + throw new ItemStillHasConsumables($category); + } + if ($category->components_count > 0) { + throw new ItemStillHasComponents($category); + } + if ($category->licenses_count > 0) { + throw new ItemStillHasLicenses($category); + } + if ($category->models_count > 0) { + throw new ItemStillHasAssetModels($category); + } + + Storage::disk('public')->delete('categories'.'/'.$category->image); + $category->delete(); + + return true; + } +} \ No newline at end of file diff --git a/app/Actions/Manufacturers/DeleteManufacturerAction.php b/app/Actions/Manufacturers/DeleteManufacturerAction.php new file mode 100644 index 000000000000..bb17a2736711 --- /dev/null +++ b/app/Actions/Manufacturers/DeleteManufacturerAction.php @@ -0,0 +1,63 @@ +loadCount([ + 'assets as assets_count', + 'accessories as accessories_count', + 'consumables as consumables_count', + 'components as components_count', + 'licenses as licenses_count', + ]); + + if ($manufacturer->assets_count > 0) { + throw new ItemStillHasAssets($manufacturer); + } + if ($manufacturer->accessories_count > 0) { + throw new ItemStillHasAccessories($manufacturer); + } + if ($manufacturer->consumables_count > 0) { + throw new ItemStillHasConsumables($manufacturer); + } + if ($manufacturer->components_count > 0) { + throw new ItemStillHasComponents($manufacturer); + } + if ($manufacturer->licenses_count > 0) { + throw new ItemStillHasLicenses($manufacturer); + } + + if ($manufacturer->image) { + try { + Storage::disk('public')->delete('manufacturers/'.$manufacturer->image); + } catch (\Exception $e) { + Log::info($e); + } + } + + $manufacturer->delete(); + //dd($manufacturer); + + return true; + } + +} \ No newline at end of file diff --git a/app/Actions/Suppliers/DestroySupplierAction.php b/app/Actions/Suppliers/DestroySupplierAction.php new file mode 100644 index 000000000000..6c6e211ac622 --- /dev/null +++ b/app/Actions/Suppliers/DestroySupplierAction.php @@ -0,0 +1,72 @@ +loadCount([ + 'maintenances as maintenances_count', + 'assets as assets_count', + 'licenses as licenses_count', + 'accessories as accessories_count', + 'consumables as consumables_count', + 'components as components_count', + ]); + if ($supplier->assets_count > 0) { + throw new ItemStillHasAssets($supplier); + } + + if ($supplier->maintenances_count > 0) { + throw new ItemStillHasMaintenances($supplier); + } + + if ($supplier->licenses_count > 0) { + throw new ItemStillHasLicenses($supplier); + } + + if ($supplier->accessories_count > 0) { + throw new ItemStillHasAccessories($supplier); + } + + if ($supplier->consumables_count > 0) { + throw new ItemStillHasConsumables($supplier); + } + + if ($supplier->components_count > 0) { + throw new ItemStillHasComponents($supplier); + } + + if ($supplier->image) { + try { + Storage::disk('public')->delete('suppliers/'.$supplier->image); + } catch (\Exception $e) { + Log::info($e->getMessage()); + } + } + + $supplier->delete(); + + return true; + } +} diff --git a/app/Exceptions/ItemStillHasAccessories.php b/app/Exceptions/ItemStillHasAccessories.php new file mode 100644 index 000000000000..b40551b08b23 --- /dev/null +++ b/app/Exceptions/ItemStillHasAccessories.php @@ -0,0 +1,10 @@ +authorize('delete', Category::class); - $category = Category::withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count', 'models as models_count')->findOrFail($id); - - if (! $category->isDeletable()) { + try { + DestroyCategoryAction::run(category: $category); + } catch (ItemStillHasChildren $e) { + return response()->json( + Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.general_assoc_warning', ['asset_type' => $category->category_type])) + ); + } catch (\Exception $e) { + report($e); return response()->json( - Helper::formatStandardApiResponse('error', null, trans('admin/categories/message.assoc_items', ['asset_type'=>$category->category_type])) + Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')) ); } - $category->delete(); return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/categories/message.delete.success'))); } diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php index 652fad1cfc6b..b714675b751e 100644 --- a/app/Http/Controllers/Api/ManufacturersController.php +++ b/app/Http/Controllers/Api/ManufacturersController.php @@ -2,6 +2,13 @@ namespace App\Http\Controllers\Api; +use App\Actions\Manufacturers\DeleteManufacturerAction; +use App\Exceptions\ItemStillHasAccessories; +use App\Exceptions\ItemStillHasAssets; +use App\Exceptions\ItemStillHasChildren; +use App\Exceptions\ItemStillHasComponents; +use App\Exceptions\ItemStillHasConsumables; +use App\Exceptions\ItemStillHasLicenses; use App\Helpers\Helper; use App\Http\Controllers\Controller; use App\Http\Transformers\ManufacturersTransformer; @@ -184,19 +191,19 @@ public function update(ImageUploadRequest $request, $id) : JsonResponse * @since [v4.0] * @param int $id */ - public function destroy($id) : JsonResponse + public function destroy(Manufacturer $manufacturer): JsonResponse { - $this->authorize('delete', Manufacturer::class); - $manufacturer = Manufacturer::findOrFail($id); $this->authorize('delete', $manufacturer); - - if ($manufacturer->isDeletable()) { - $manufacturer->delete(); - return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/manufacturers/message.delete.success'))); + try { + DeleteManufacturerAction::run($manufacturer); + } catch (ItemStillHasChildren $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.general_assoc_warning', ['item' => trans('general.manufacturer')]))); + } catch (\Exception $e) { + report($e); + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong'))); } - return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/manufacturers/message.assoc_users'))); - + return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/manufacturers/message.delete.success'))); } /** diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php index 6784ee82c16e..b985be6587e4 100644 --- a/app/Http/Controllers/Api/SuppliersController.php +++ b/app/Http/Controllers/Api/SuppliersController.php @@ -2,6 +2,13 @@ namespace App\Http\Controllers\Api; +use App\Actions\Suppliers\DestroySupplierAction; +use App\Exceptions\ItemStillHasAccessories; +use App\Exceptions\ItemStillHasComponents; +use App\Exceptions\ItemStillHasConsumables; +use App\Exceptions\ItemStillHasMaintenances; +use App\Exceptions\ItemStillHasAssets; +use App\Exceptions\ItemStillHasLicenses; use App\Helpers\Helper; use App\Http\Controllers\Controller; use App\Http\Transformers\SelectlistTransformer; @@ -191,27 +198,40 @@ public function update(ImageUploadRequest $request, $id) : JsonResponse * @since [v4.0] * @param int $id */ - public function destroy($id) : JsonResponse + public function destroy(Supplier $supplier): JsonResponse { - $this->authorize('delete', Supplier::class); - $supplier = Supplier::with('maintenances', 'assets', 'licenses')->withCount('maintenances as maintenances_count', 'assets as assets_count', 'licenses as licenses_count')->findOrFail($id); $this->authorize('delete', $supplier); - - - if ($supplier->assets_count > 0) { - return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count]))); - } - - if ($supplier->maintenances_count > 0) { - return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_maintenances', ['maintenances_count' => $supplier->maintenances_count]))); + try { + DestroySupplierAction::run(supplier: $supplier); + } catch (ItemStillHasAssets $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_assets', [ + 'asset_count' => (int) $supplier->assets_count, 'item' => trans('general.supplier') + ]))); + } catch (ItemStillHasMaintenances $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_maintenances', [ + 'asset_maintenances_count' => $supplier->asset_maintenances_count, 'item' => trans('general.supplier') + ]))); + } catch (ItemStillHasLicenses $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_licenses', [ + 'licenses_count' => (int) $supplier->licenses_count, 'item' => trans('general.supplier') + ]))); + } catch (ItemStillHasAccessories $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_accessories', [ + 'accessories_count' => (int) $supplier->accessories_count, 'item' => trans('general.supplier') + ]))); + } catch (ItemStillHasConsumables $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_consumables', [ + 'consumables_count' => (int) $supplier->consumables_count, 'item' => trans('general.supplier') + ]))); + } catch (ItemStillHasComponents $e) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.bulk_delete_associations.assoc_components', [ + 'components_count' => (int) $supplier->components_count, 'item' => trans('general.supplier') + ]))); + } catch (\Exception $e) { + report($e); + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong'))); } - if ($supplier->licenses_count > 0) { - return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_licenses', ['licenses_count' => (int) $supplier->licenses_count]))); - } - - $supplier->delete(); - return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/suppliers/message.delete.success'))); } diff --git a/app/Http/Controllers/BulkCategoriesController.php b/app/Http/Controllers/BulkCategoriesController.php new file mode 100644 index 000000000000..3beb3279f66f --- /dev/null +++ b/app/Http/Controllers/BulkCategoriesController.php @@ -0,0 +1,53 @@ +authorize('delete', Category::class); + + $errors = []; + foreach ($request->ids as $id) { + $category = Category::find($id); + if (is_null($category)) { + $errors[] = trans('admin/categories/message.does_not_exist'); + continue; + } + try { + DestroyCategoryAction::run(category: $category); + } catch (ItemStillHasAccessories $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_assets_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]); + } catch (ItemStillHasAssetModels) { + $errors[] = trans('general.bulk_delete_associations.assoc_asset_models_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]); + } catch (ItemStillHasAssets) { + $errors[] = trans('general.bulk_delete_associations.assoc_assets_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]); + } catch (ItemStillHasComponents) { + $errors[] = trans('general.bulk_delete_associations.assoc_components_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]); + } catch (ItemStillHasConsumables) { + $errors[] = trans('general.bulk_delete_associations.assoc_consumables_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]); + } catch (ItemStillHasLicenses) { + $errors[] = trans('general.bulk_delete_associations.assoc_licenses_no_count', ['item_name' => $category->name, 'item' => trans('general.category')]);; + } catch (\Exception $e) { + report($e); + $errors[] = trans('general.something_went_wrong'); + } + } + if (count($errors) > 0) { + return redirect()->route('categories.index')->with('multi_error_messages', $errors); + } else { + return redirect()->route('categories.index')->with('success', trans('admin/categories/message.delete.bulk_success')); + } + } +} diff --git a/app/Http/Controllers/BulkManufacturersController.php b/app/Http/Controllers/BulkManufacturersController.php new file mode 100644 index 000000000000..68df82e9bcba --- /dev/null +++ b/app/Http/Controllers/BulkManufacturersController.php @@ -0,0 +1,52 @@ +authorize('delete', Manufacturer::class); + + $errors = []; + foreach ($request->ids as $id) { + $manufacturer = Manufacturer::find($id); + if (is_null($manufacturer)) { + $errors[] = trans('admin/manufacturers/message.does_not_exist'); + continue; + } + try { + DeleteManufacturerAction::run(manufacturer: $manufacturer); + } catch (ItemStillHasAssets $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_assets_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]); + } catch (ItemStillHasAccessories $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_accessories_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]); + } catch (ItemStillHasConsumables $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_consumables_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]); + } catch (ItemStillHasComponents $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_components_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]); + } catch (ItemStillHasLicenses $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_licenses_no_count', ['item_name' => $manufacturer->name, 'item' => trans('general.manufacturer')]);; + } catch (\Exception $e) { + report($e); + $errors[] = trans('general.something_went_wrong'); + } + } + if (count($errors) > 0) { + return redirect()->route('manufacturers.index')->with('multi_error_messages', $errors); + } else { + return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.delete.bulk_success')); + } + } +} diff --git a/app/Http/Controllers/BulkSuppliersController.php b/app/Http/Controllers/BulkSuppliersController.php new file mode 100644 index 000000000000..01fda3e7144a --- /dev/null +++ b/app/Http/Controllers/BulkSuppliersController.php @@ -0,0 +1,53 @@ +authorize('delete', Supplier::class); + + $errors = []; + foreach ($request->ids as $id) { + $supplier = Supplier::find($id); + if (is_null($supplier)) { + $errors[] = trans('admin/suppliers/message.delete.not_found'); + continue; + } + try { + DestroySupplierAction::run(supplier: $supplier); + } catch (ItemStillHasAssets $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_assets', ['asset_count' => (int) $supplier->assets_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]); + } catch (ItemStillHasMaintenances $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_maintenances', ['asset_maintenances_count' => $supplier->asset_maintenances_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]); + } catch (ItemStillHasLicenses $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_licenses', ['licenses_count' => (int) $supplier->licenses_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]); + } catch (ItemStillHasAccessories $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_accessories', ['accessories_count' => (int) $supplier->accessories_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]); + } catch (ItemStillHasConsumables $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_consumables', ['consumables_count' => (int) $supplier->consumables_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]); + } catch (ItemStillHasComponents $e) { + $errors[] = trans('general.bulk_delete_associations.assoc_components', ['components_count' => (int) $supplier->components_count, 'item' => trans('general.supplier'), 'item_name' => $supplier->name]); + } catch (\Exception $e) { + report($e); + $errors[] = trans('general.something_went_wrong'); + } + } + if (count($errors) > 0) { + return redirect()->route('suppliers.index')->with('multi_error_messages', $errors); + } else { + return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.delete.bulk_success')); + } + } +} diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index 3e902541b330..600d99d6b6e4 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -2,6 +2,14 @@ namespace App\Http\Controllers; +use App\Actions\Categories\DestroyCategoryAction; +use App\Exceptions\ItemStillHasAccessories; +use App\Exceptions\ItemStillHasAssetModels; +use App\Exceptions\ItemStillHasAssets; +use App\Exceptions\ItemStillHasChildren; +use App\Exceptions\ItemStillHasComponents; +use App\Exceptions\ItemStillHasConsumables; +use App\Exceptions\ItemStillHasLicenses; use App\Helpers\Helper; use App\Http\Requests\ImageUploadRequest; use App\Models\Category; @@ -143,20 +151,18 @@ public function update(ImageUploadRequest $request, Category $category) : Redire * @since [v1.0] * @param int $categoryId */ - public function destroy($categoryId) : RedirectResponse + public function destroy(Category $category): RedirectResponse { $this->authorize('delete', Category::class); - // Check if the category exists - if (is_null($category = Category::withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count', 'models as models_count')->findOrFail($categoryId))) { - return redirect()->route('categories.index')->with('error', trans('admin/categories/message.not_found')); + try { + DestroyCategoryAction::run($category); + } catch (ItemStillHasChildren $e) { + return redirect()->route('categories.index')->with('error', trans('general.bulk_delete_associations.general_assoc_warning', ['item' => trans('general.category')])); + } catch (\Exception $e) { + report($e); + return redirect()->route('categories.index')->with('error', trans('admin/categories/message.delete.error')); } - if (! $category->isDeletable()) { - return redirect()->route('categories.index')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=> $category->category_type])); - } - - Storage::disk('public')->delete('categories'.'/'.$category->image); - $category->delete(); return redirect()->route('categories.index')->with('success', trans('admin/categories/message.delete.success')); } diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index ac0b2818f44c..d996855a5ee0 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -2,6 +2,14 @@ namespace App\Http\Controllers; +use App\Actions\Manufacturers\DeleteManufacturerAction; +use App\Exceptions\ItemStillHasAccessories; +use App\Exceptions\ItemStillHasAssets; +use App\Exceptions\ItemStillHasChildren; +use App\Exceptions\ItemStillHasComponents; +use App\Exceptions\ItemStillHasConsumables; +use App\Exceptions\ItemStillHasLicenses; +use App\Helpers\Helper; use App\Http\Requests\ImageUploadRequest; use App\Models\Actionlog; use App\Models\Manufacturer; @@ -157,32 +165,18 @@ public function update(ImageUploadRequest $request, Manufacturer $manufacturer) * @param int $manufacturerId * @since [v1.0] */ - public function destroy($manufacturerId) : RedirectResponse + public function destroy(Manufacturer $manufacturer): RedirectResponse { - $this->authorize('delete', Manufacturer::class); - if (is_null($manufacturer = Manufacturer::withTrashed()->withCount('models as models_count')->find($manufacturerId))) { - return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.not_found')); - } - - if (! $manufacturer->isDeletable()) { - return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users')); + $this->authorize('delete', $manufacturer); + try { + DeleteManufacturerAction::run($manufacturer); + } catch (ItemStillHasChildren $e) { + return redirect()->route('manufacturers.index')->with('error', trans('general.bulk_delete_associations.general_assoc_warning', ['item' => trans('general.manufacturer')])); + } catch (\Exception $e) { + report($e); + return redirect()->route('manufacturers.index')->with('error', trans('general.something_went_wrong')); } - if ($manufacturer->image) { - try { - Storage::disk('public')->delete('manufacturers/'.$manufacturer->image); - } catch (\Exception $e) { - Log::info($e); - } - } - - // Soft delete the manufacturer if active, permanent delete if is already deleted - if ($manufacturer->deleted_at === null) { - $manufacturer->delete(); - } else { - $manufacturer->forceDelete(); - } - // Redirect to the manufacturers management page return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.delete.success')); } diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.php index 2a3c73bebe8a..e699c5ced86a 100755 --- a/app/Http/Controllers/SuppliersController.php +++ b/app/Http/Controllers/SuppliersController.php @@ -2,10 +2,18 @@ namespace App\Http\Controllers; +use App\Actions\Suppliers\DestroySupplierAction; +use App\Exceptions\ItemStillHasAccessories; +use App\Exceptions\ItemStillHasComponents; +use App\Exceptions\ItemStillHasConsumables; +use App\Exceptions\ItemStillHasMaintenances; +use App\Exceptions\ItemStillHasAssets; +use App\Exceptions\ItemStillHasLicenses; use App\Http\Requests\ImageUploadRequest; use App\Models\Supplier; use Illuminate\Http\RedirectResponse; use \Illuminate\Contracts\View\View; +use Illuminate\Support\MessageBag; /** * This controller handles all actions related to Suppliers for @@ -118,30 +126,41 @@ public function update(ImageUploadRequest $request, Supplier $supplier) : Redire * * @param int $supplierId */ - public function destroy($supplierId) : RedirectResponse + public function destroy(Supplier $supplier): RedirectResponse { $this->authorize('delete', Supplier::class); - if (is_null($supplier = Supplier::with('maintenances', 'assets', 'licenses')->withCount('maintenances as maintenances_count', 'assets as assets_count', 'licenses as licenses_count')->find($supplierId))) { - return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.not_found')); + try { + DestroySupplierAction::run(supplier: $supplier); + } catch (ItemStillHasAssets $e) { + return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_assets', [ + 'asset_count' => (int) $supplier->assets_count, 'item' => trans('general.supplier') + ])); + } catch (ItemStillHasMaintenances $e) { + return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_maintenances', [ + 'asset_maintenances_count' => $supplier->asset_maintenances_count, 'item' => trans('general.supplier') + ])); + } catch (ItemStillHasLicenses $e) { + return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_licenses', [ + 'licenses_count' => (int) $supplier->licenses_count, 'item' => trans('general.supplier') + ])); + } catch (ItemStillHasAccessories $e) { + return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_accessories', [ + 'accessories_count' => (int) $supplier->accessories_count, 'item' => trans('general.supplier') + ])); + } catch (ItemStillHasConsumables $e) { + return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_consumables', [ + 'consumables_count' => (int) $supplier->consumables_count, 'item' => trans('general.supplier') + ])); + } catch (ItemStillHasComponents $e) { + return redirect()->route('suppliers.index')->with('error', trans('general.bulk_delete_associations.assoc_components', [ + 'components_count' => (int) $supplier->components_count, 'item' => trans('general.supplier') + ])); + } catch (\Exception $e) { + report($e); + return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.error')); } - if ($supplier->assets_count > 0) { - return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count])); - } - - if ($supplier->maintenances_count > 0) { - return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.assoc_maintenances', ['maintenances_count' => $supplier->maintenances_count])); - } - - if ($supplier->licenses_count > 0) { - return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.delete.assoc_licenses', ['licenses_count' => (int) $supplier->licenses_count])); - } - - $supplier->delete(); - - return redirect()->route('suppliers.index')->with('success', - trans('admin/suppliers/message.delete.success') - ); + return redirect()->route('suppliers.index')->with('success', trans('admin/suppliers/message.delete.success')); } /** @@ -154,6 +173,5 @@ public function show(Supplier $supplier) : View | RedirectResponse { $this->authorize('view', Supplier::class); return view('suppliers/view', compact('supplier')); - } } diff --git a/app/Presenters/CategoryPresenter.php b/app/Presenters/CategoryPresenter.php index e09b1e4a610f..9299d15c334e 100644 --- a/app/Presenters/CategoryPresenter.php +++ b/app/Presenters/CategoryPresenter.php @@ -14,6 +14,11 @@ class CategoryPresenter extends Presenter public static function dataTableLayout() { $layout = [ + [ + 'field' => 'checkbox', + 'checkbox' => true, + 'titleTooltip' => trans('general.select_all_none'), + ], [ 'field' => 'id', 'searchable' => false, diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.php index 5d539641cf3b..56c101295fe9 100644 --- a/app/Presenters/ManufacturerPresenter.php +++ b/app/Presenters/ManufacturerPresenter.php @@ -14,7 +14,11 @@ class ManufacturerPresenter extends Presenter public static function dataTableLayout() { $layout = [ - + [ + 'field' => 'checkbox', + 'checkbox' => true, + 'titleTooltip' => trans('general.select_all_none'), + ], [ 'field' => 'id', 'searchable' => false, diff --git a/app/Presenters/SupplierPresenter.php b/app/Presenters/SupplierPresenter.php index 13f18876216d..6dd594dc6b7b 100644 --- a/app/Presenters/SupplierPresenter.php +++ b/app/Presenters/SupplierPresenter.php @@ -13,6 +13,11 @@ class SupplierPresenter extends Presenter public static function dataTableLayout() { $layout = [ + [ + 'field' => 'checkbox', + 'checkbox' => true, + 'titleTooltip' => trans('general.select_all_none'), + ], [ 'field' => 'id', 'searchable' => false, diff --git a/resources/lang/en-US/admin/categories/message.php b/resources/lang/en-US/admin/categories/message.php index 4e493f68b6f8..052fa644235a 100644 --- a/resources/lang/en-US/admin/categories/message.php +++ b/resources/lang/en-US/admin/categories/message.php @@ -18,9 +18,10 @@ ), 'delete' => array( - 'confirm' => 'Are you sure you wish to delete this category?', - 'error' => 'There was an issue deleting the category. Please try again.', - 'success' => 'The category was deleted successfully.' + 'confirm' => 'Are you sure you wish to delete this category?', + 'error' => 'There was an issue deleting the category. Please try again.', + 'success' => 'The category was deleted successfully.', + 'bulk_success' => 'The Categories were deleted successfully.', ) ); diff --git a/resources/lang/en-US/admin/manufacturers/message.php b/resources/lang/en-US/admin/manufacturers/message.php index 61416e023026..70e414057799 100644 --- a/resources/lang/en-US/admin/manufacturers/message.php +++ b/resources/lang/en-US/admin/manufacturers/message.php @@ -22,9 +22,10 @@ ), 'delete' => array( - 'confirm' => 'Are you sure you wish to delete this manufacturer?', + 'confirm' => 'Are you sure you wish to delete this manufacturer?', 'error' => 'There was an issue deleting the manufacturer. Please try again.', - 'success' => 'The Manufacturer was deleted successfully.' + 'success' => 'The Manufacturer was deleted successfully.', + 'bulk_success' => 'The Manufacturers were deleted successfully.', ) ); diff --git a/resources/lang/en-US/admin/suppliers/message.php b/resources/lang/en-US/admin/suppliers/message.php index 01256abd235a..a5f9ef02aa7f 100644 --- a/resources/lang/en-US/admin/suppliers/message.php +++ b/resources/lang/en-US/admin/suppliers/message.php @@ -20,9 +20,8 @@ 'confirm' => 'Are you sure you wish to delete this supplier?', 'error' => 'There was an issue deleting the supplier. Please try again.', 'success' => 'Supplier was deleted successfully.', - 'assoc_assets' => 'This supplier is currently associated with :asset_count asset(s) and cannot be deleted. Please update your assets to no longer reference this supplier and try again. ', - 'assoc_licenses' => 'This supplier is currently associated with :licenses_count licences(s) and cannot be deleted. Please update your licenses to no longer reference this supplier and try again. ', - 'assoc_maintenances' => 'This supplier is currently associated with :maintenances_count asset maintenances(s) and cannot be deleted. Please update your asset maintenances to no longer reference this supplier and try again. ', + 'not_found' => 'Supplier not found.', + 'bulk_success' => 'Suppliers were deleted successfully.', ) ); diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 3c6738bbdc02..e18eca65ce3d 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -1,6 +1,7 @@ 'Show All', '2FA_reset' => '2FA reset', 'accessories' => 'Accessories', 'activated' => 'Activated', @@ -629,6 +630,24 @@ 'notes' => 'Add a note', ], + 'bulk_delete_associations' => [ + 'general_assoc_warning' => ':item_name still has associated items. Please remove them before deleting this :item.', + 'assoc_assets' => ':item_name is currently associated with :asset_count asset(s) and cannot be deleted. Please update your assets to no longer reference this :item and try again.', + 'asset_models' => ':item_name is currently associated with :asset_count asset(s) and cannot be deleted. Please update your asset models to no longer reference this :item and try again.', + 'assoc_maintenances' => ':item_name is currently associated with :maintenance_count maintenance(s) and cannot be deleted. Please update your maintenances to no longer reference this :item and try again.', + 'assoc_accessories' => ':item_name is currently associated with :accessory_count accessory(ies) and cannot be deleted. Please update your accessories to no longer reference this :item and try again.', + 'assoc_consumables' => ':item_name is currently associated with :consumable_count consumable(s) and cannot be deleted. Please update your consumables to no longer reference this :item and try again.', + 'assoc_components' => ':item_name is currently associated with :component_count component(s) and cannot be deleted. Please update your components to no longer reference this :item and try again.', + 'assoc_licenses' => ':item_name is currently associated with :license_count license(s) and cannot be deleted. Please update your licenses to no longer reference this :item and try again.', + 'assoc_assets_no_count' => ':item_name is currently associated with other assets and cannot be deleted. Please update your assets to no longer reference this :item and try again.', + 'asset_models_no_count' => ':item_name is currently associated with other asset models and cannot be deleted. Please update your assets to no longer reference this :item and try again.', + 'assoc_maintenances_no_count' => ':item_name is currently associated with other maintenances and cannot be deleted. Please update your maintenances to no longer reference this :item and try again.', + 'assoc_accessories_no_count' => ':item_name is currently associated with other accessories and cannot be deleted. Please update your accessories to no longer reference this :item and try again.', + 'assoc_consumables_no_count' => ':item_name is currently associated with other consumables and cannot be deleted. Please update your consumables to no longer reference this :item and try again.', + 'assoc_components_no_count' => ':item_name is currently associated with other components and cannot be deleted. Please update your components to no longer reference this :item and try again.', + 'assoc_licenses_no_count' => ':item_name is currently associated with other licenses and cannot be deleted. Please update your licenses to no longer reference this :item and try again.', + ], + 'breadcrumb_button_actions' => [ 'edit_item' => 'Edit :name', 'checkout_item' => 'Checkout :name', diff --git a/resources/views/categories/index.blade.php b/resources/views/categories/index.blade.php index 6eec402ddd46..6c95800c7cf9 100755 --- a/resources/views/categories/index.blade.php +++ b/resources/views/categories/index.blade.php @@ -13,13 +13,31 @@