A free open source IT asset/license management system
added new counts and throw new exceptions and catch them
spencerrlongg36f509993282
diff --git a/app/Actions/Suppliers/DestroySupplierAction.php b/app/Actions/Suppliers/DestroySupplierAction.phpindex bea1757854..6c6e211ac6 100644--- a/app/Actions/Suppliers/DestroySupplierAction.php+++ b/app/Actions/Suppliers/DestroySupplierAction.php@@ -2,6 +2,9 @@namespace App\Actions\Suppliers;+use App\Exceptions\ItemStillHasAccessories;+use App\Exceptions\ItemStillHasComponents;+use App\Exceptions\ItemStillHasConsumables;use App\Models\Supplier;use App\Exceptions\ItemStillHasAssets;use App\Exceptions\ItemStillHasMaintenances;@@ -12,16 +15,23 @@ use Illuminate\Support\Facades\Storage;class DestroySupplierAction{/**+ ** @throws ItemStillHasLicenses* @throws ItemStillHasAssets* @throws ItemStillHasMaintenances+ * @throws ItemStillHasAccessories+ * @throws ItemStillHasConsumables+ * @throws ItemStillHasComponents*/static function run(Supplier $supplier): bool{$supplier->loadCount(['maintenances as maintenances_count','assets as assets_count',- 'licenses as licenses_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);@@ -35,6 +45,18 @@ class DestroySupplierActionthrow 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);diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.phpindex 304a70094a..b985be6587 100644--- a/app/Http/Controllers/Api/SuppliersController.php+++ b/app/Http/Controllers/Api/SuppliersController.php@@ -3,6 +3,9 @@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;@@ -212,6 +215,18 @@ class SuppliersController extends Controllerreturn 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')));diff --git a/app/Http/Controllers/BulkSuppliersController.php b/app/Http/Controllers/BulkSuppliersController.phpindex 3933f615ce..01fda3e714 100644--- a/app/Http/Controllers/BulkSuppliersController.php+++ b/app/Http/Controllers/BulkSuppliersController.php@@ -3,6 +3,9 @@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;@@ -30,6 +33,12 @@ class BulkSuppliersController extends Controller$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');diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.phpindex 681eb835d7..e699c5ced8 100755--- a/app/Http/Controllers/SuppliersController.php+++ b/app/Http/Controllers/SuppliersController.php@@ -3,6 +3,9 @@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;@@ -140,6 +143,18 @@ class SuppliersController extends Controllerreturn 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'));