diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index a11ea8e270..1551348046 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -50,7 +50,7 @@ class SendAcceptanceReminder extends Command $query->where('accepted_at', null) ->where('declined_at', null); }) - ->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.admin']) + ->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser']) ->get(); $count = 0; diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.php index 4fd5a4c547..8c66c9a3b2 100755 --- a/app/Http/Controllers/Accessories/AccessoriesController.php +++ b/app/Http/Controllers/Accessories/AccessoriesController.php @@ -73,7 +73,7 @@ class AccessoriesController extends Controller $accessory->purchase_date = request('purchase_date'); $accessory->purchase_cost = request('purchase_cost'); $accessory->qty = request('qty'); - $accessory->user_id = auth()->id(); + $accessory->created_by = auth()->id(); $accessory->supplier_id = request('supplier_id'); $accessory->notes = request('notes'); diff --git a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php index 03fb6ac250..2417f16567 100644 --- a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php +++ b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php @@ -78,7 +78,7 @@ class AccessoryCheckoutController extends Controller AccessoryCheckout::create([ 'accessory_id' => $accessory->id, 'created_at' => Carbon::now(), - 'user_id' => Auth::id(), + 'created_by' => auth()->id(), 'assigned_to' => $target->id, 'assigned_type' => $target::class, 'note' => $request->input('note'), diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 6d84861fb0..c6cdf9bbf8 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -237,7 +237,11 @@ class AcceptanceController extends Controller } $acceptance->accept($sig_filename, $item->getEula(), $pdf_filename, $request->input('note')); - $acceptance->notify(new AcceptanceAssetAcceptedNotification($data)); + try { + $acceptance->notify(new AcceptanceAssetAcceptedNotification($data)); + } catch (\Exception $e) { + Log::error($e); + } event(new CheckoutAccepted($acceptance)); $return_msg = trans('admin/users/message.accepted'); diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index d88b5c6849..d1ef72bcca 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -56,8 +56,9 @@ class AccessoriesController extends Controller ]; - $accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'checkouts', 'location', 'supplier') - ->withCount('checkouts as checkouts_count'); + $accessories = Accessory::select('accessories.*') + ->with('category', 'company', 'manufacturer', 'checkouts', 'location', 'supplier', 'adminuser') + ->withCount('checkouts as checkouts_count'); if ($request->filled('search')) { $accessories = $accessories->TextSearch($request->input('search')); @@ -110,7 +111,10 @@ class AccessoriesController extends Controller break; case 'supplier': $accessories = $accessories->OrderSupplier($order); - break; + break; + case 'created_by': + $accessories = $accessories->OrderByCreatedByName($order); + break; default: $accessories = $accessories->orderBy($column_sort, $order); break; @@ -283,7 +287,7 @@ class AccessoriesController extends Controller AccessoryCheckout::create([ 'accessory_id' => $accessory->id, 'created_at' => Carbon::now(), - 'user_id' => Auth::id(), + 'created_by' => auth()->id(), 'assigned_to' => $target->id, 'assigned_type' => $target::class, 'note' => $request->input('note'), diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index e12dc826a9..3e02a56195 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -34,7 +34,7 @@ class AssetMaintenancesController extends Controller $this->authorize('view', Asset::class); $maintenances = AssetMaintenance::select('asset_maintenances.*') - ->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'asset.assetstatus', 'admin'); + ->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'asset.assetstatus', 'adminuser'); if ($request->filled('search')) { $maintenances = $maintenances->TextSearch($request->input('search')); @@ -48,6 +48,10 @@ class AssetMaintenancesController extends Controller $maintenances->where('asset_maintenances.supplier_id', '=', $request->input('supplier_id')); } + if ($request->filled('created_by')) { + $maintenances->where('asset_maintenances.created_by', '=', $request->input('created_by')); + } + if ($request->filled('asset_maintenance_type')) { $maintenances->where('asset_maintenance_type', '=', $request->input('asset_maintenance_type')); } @@ -69,7 +73,7 @@ class AssetMaintenancesController extends Controller 'asset_tag', 'asset_name', 'serial', - 'user_id', + 'created_by', 'supplier', 'is_warranty', 'status_label', @@ -79,8 +83,8 @@ class AssetMaintenancesController extends Controller $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; switch ($sort) { - case 'user_id': - $maintenances = $maintenances->OrderAdmin($order); + case 'created_by': + $maintenances = $maintenances->OrderByCreatedBy($order); break; case 'supplier': $maintenances = $maintenances->OrderBySupplier($order); @@ -124,7 +128,7 @@ class AssetMaintenancesController extends Controller // create a new model instance $maintenance = new AssetMaintenance(); $maintenance->fill($request->all()); - $maintenance->user_id = Auth::id(); + $maintenance->created_by = auth()->id(); // Was the asset maintenance created? if ($maintenance->save()) { @@ -186,6 +190,7 @@ class AssetMaintenancesController extends Controller { $this->authorize('update', Asset::class); // Check if the asset maintenance exists + $assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId); $assetMaintenance->delete(); diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 9f78193420..e1ae0c12d3 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -48,6 +48,8 @@ class AssetModelsController extends Controller 'assets_count', 'category', 'fieldset', + 'deleted_at', + 'updated_at', ]; $assetmodels = AssetModel::select([ @@ -67,7 +69,7 @@ class AssetModelsController extends Controller 'models.deleted_at', 'models.updated_at', ]) - ->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues') + ->with('category', 'depreciation', 'manufacturer', 'fieldset.fields.defaultValues','adminuser') ->withCount('assets as assets_count'); if ($request->input('status')=='deleted') { diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 0c80d50e5c..514f4484c8 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -56,6 +56,11 @@ class AssetsController extends Controller public function index(Request $request, $action = null, $upcoming_status = null) : JsonResponse | array { + + // This handles the legacy audit endpoints :( + if ($action == 'audit') { + $action = 'audits'; + } $filter_non_deprecable_assets = false; /** @@ -121,7 +126,7 @@ class AssetsController extends Controller } $assets = Asset::select('assets.*') - ->with('location', 'assetstatus', 'company', 'defaultLoc','assignedTo', + ->with('location', 'assetstatus', 'company', 'defaultLoc','assignedTo', 'adminuser','model.depreciation', 'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users. @@ -154,8 +159,8 @@ class AssetsController extends Controller * Handle due and overdue audits and checkin dates */ switch ($action) { - case 'audits': - + // Audit (singular) is left over from earlier legacy APIs + case 'audits' : switch ($upcoming_status) { case 'due': $assets->DueForAudit($settings); @@ -371,6 +376,9 @@ class AssetsController extends Controller case 'assigned_to': $assets->OrderAssigned($order); break; + case 'created_by': + $assets->OrderByCreatedByName($order); + break; default: $numeric_sort = false; @@ -590,7 +598,7 @@ class AssetsController extends Controller $asset->model()->associate(AssetModel::find((int) $request->get('model_id'))); $asset->fill($request->validated()); - $asset->user_id = Auth::id(); + $asset->created_by = auth()->id(); /** * this is here just legacy reasons. Api\AssetController diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php index 6e9866f90b..e772bec4df 100644 --- a/app/Http/Controllers/Api/CategoriesController.php +++ b/app/Http/Controllers/Api/CategoriesController.php @@ -43,6 +43,7 @@ class CategoriesController extends Controller $categories = Category::select([ 'id', + 'created_by', 'created_at', 'updated_at', 'name', 'category_type', @@ -50,8 +51,10 @@ class CategoriesController extends Controller 'eula_text', 'require_acceptance', 'checkin_email', - 'image' - ])->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count'); + 'image', + ]) + ->with('adminuser') + ->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count'); /* @@ -91,13 +94,33 @@ class CategoriesController extends Controller $categories->where('checkin_email', '=', $request->input('checkin_email')); } + if ($request->filled('created_by')) { + $categories->where('created_by', '=', $request->input('created_by')); + } + + if ($request->filled('created_at')) { + $categories->where('created_at', '=', $request->input('created_at')); + } + + if ($request->filled('updated_at')) { + $categories->where('updated_at', '=', $request->input('updated_at')); + } + // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $categories->count()) ? $categories->count() : app('api_offset_value'); $limit = app('api_limit_value'); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count'; - $categories->orderBy($sort, $order); + $sort_override = $request->input('sort'); + $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets_count'; + + switch ($sort_override) { + case 'created_by': + $categories = $categories->OrderByCreatedBy($order); + break; + default: + $categories = $categories->orderBy($column_sort, $order); + break; + } $total = $categories->count(); $categories = $categories->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index 0d78df9acc..5ba342db33 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -42,7 +42,7 @@ class CompaniesController extends Controller $companies = Company::withCount(['assets as assets_count' => function ($query) { $query->AssetsForShow(); - }])->withCount('licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count'); + }])->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count'); if ($request->filled('search')) { $companies->TextSearch($request->input('search')); @@ -56,17 +56,29 @@ class CompaniesController extends Controller $companies->where('email', '=', $request->input('email')); } + if ($request->filled('created_by')) { + $companies->where('created_by', '=', $request->input('created_by')); + } + // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $companies->count()) ? $companies->count() : app('api_offset_value'); $limit = app('api_limit_value'); - - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; - $companies->orderBy($sort, $order); + $sort_override = $request->input('sort'); + $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at'; + + switch ($sort_override) { + case 'created_by': + $companies = $companies->OrderByCreatedBy($order); + break; + default: + $companies = $companies->orderBy($column_sort, $order); + break; + } $total = $companies->count(); + $companies = $companies->skip($offset)->take($limit)->get(); return (new CompaniesTransformer)->transformCompanies($companies, $total); diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index 69bd828487..561e13c9cd 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -47,7 +47,7 @@ class ComponentsController extends Controller ]; $components = Component::select('components.*') - ->with('company', 'location', 'category', 'assets', 'supplier'); + ->with('company', 'location', 'category', 'assets', 'supplier', 'adminuser'); if ($request->filled('search')) { $components = $components->TextSearch($request->input('search')); @@ -98,6 +98,9 @@ class ComponentsController extends Controller case 'supplier': $components = $components->OrderSupplier($order); break; + case 'created_by': + $components = $components->OrderByCreatedBy($order); + break; default: $components = $components->orderBy($column_sort, $order); break; @@ -270,7 +273,7 @@ class ComponentsController extends Controller 'component_id' => $component->id, 'created_at' => Carbon::now(), 'assigned_qty' => $request->get('assigned_qty', 1), - 'user_id' => auth()->id(), + 'created_by' => auth()->id(), 'asset_id' => $request->get('assigned_to'), 'note' => $request->get('note'), ]); diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index 7be4c3d2dd..8e7f321720 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -92,6 +92,9 @@ class ConsumablesController extends Controller case 'supplier': $consumables = $consumables->OrderSupplier($order); break; + case 'created_by': + $consumables = $consumables->OrderByCreatedBy($order); + break; default: // This array is what determines which fields should be allowed to be sorted on ON the table itself. // These must match a column on the consumables table directly. @@ -210,7 +213,7 @@ class ConsumablesController extends Controller $consumable = Consumable::with(['consumableAssignments'=> function ($query) { $query->orderBy($query->getModel()->getTable().'.created_at', 'DESC'); }, - 'consumableAssignments.admin'=> function ($query) { + 'consumableAssignments.adminuser'=> function ($query) { }, 'consumableAssignments.user'=> function ($query) { }, @@ -228,7 +231,8 @@ class ConsumablesController extends Controller 'name' => ($consumable_assignment->user) ? $consumable_assignment->user->present()->nameUrl() : 'Deleted User', 'created_at' => Helper::getFormattedDateObject($consumable_assignment->created_at, 'datetime'), 'note' => ($consumable_assignment->note) ? e($consumable_assignment->note) : null, - 'admin' => ($consumable_assignment->admin) ? $consumable_assignment->admin->present()->nameUrl() : null, + 'admin' => ($consumable_assignment->adminuser) ? $consumable_assignment->adminuser->present()->nameUrl() : null, // legacy, so we don't change the shape of the response + 'created_by' => ($consumable_assignment->adminuser) ? $consumable_assignment->adminuser->present()->nameUrl() : null, ]; } @@ -277,7 +281,7 @@ class ConsumablesController extends Controller $consumable->users()->attach($consumable->id, [ 'consumable_id' => $consumable->id, - 'user_id' => $user->id, + 'created_by' => $user->id, 'assigned_to' => $request->input('assigned_to'), 'note' => $request->input('note'), ] diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index eabc79ec2b..e337360cd7 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -97,7 +97,7 @@ class DepartmentsController extends Controller $department->fill($request->all()); $department = $request->handleImages($department); - $department->user_id = auth()->id(); + $department->created_by = auth()->id(); $department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null); if ($department->save()) { diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 72e0f3a14a..254a72c98e 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -32,7 +32,8 @@ class DepreciationsController extends Controller 'licenses_count', ]; - $depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','user_id','created_at','updated_at') + $depreciations = Depreciation::select('id','name','months','depreciation_min','depreciation_type','created_at','updated_at', 'created_by') + ->with('adminuser') ->withCount('assets as assets_count') ->withCount('models as models_count') ->withCount('licenses as licenses_count'); @@ -44,10 +45,18 @@ class DepreciationsController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $depreciations->count()) ? $depreciations->count() : app('api_offset_value'); $limit = app('api_limit_value'); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; - $depreciations->orderBy($sort, $order); + $sort_override = $request->input('sort'); + $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at'; + + switch ($sort_override) { + case 'created_by': + $depreciations = $depreciations->OrderByCreatedBy($order); + break; + default: + $depreciations = $depreciations->orderBy($column_sort, $order); + break; + } $total = $depreciations->count(); $depreciations = $depreciations->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/GroupsController.php b/app/Http/Controllers/Api/GroupsController.php index 878650c718..81217ce8db 100644 --- a/app/Http/Controllers/Api/GroupsController.php +++ b/app/Http/Controllers/Api/GroupsController.php @@ -23,9 +23,8 @@ class GroupsController extends Controller $this->authorize('superadmin'); $this->authorize('view', Group::class); - $allowed_columns = ['id', 'name', 'created_at', 'users_count']; - $groups = Group::select('id', 'name', 'permissions', 'created_at', 'updated_at', 'created_by')->with('admin')->withCount('users as users_count'); + $groups = Group::select('id', 'name', 'permissions', 'created_at', 'updated_at', 'created_by')->with('adminuser')->withCount('users as users_count'); if ($request->filled('search')) { $groups = $groups->TextSearch($request->input('search')); @@ -35,13 +34,29 @@ class GroupsController extends Controller $groups->where('name', '=', $request->input('name')); } - // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $groups->count()) ? $groups->count() : app('api_offset_value'); $limit = app('api_limit_value'); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; - $groups->orderBy($sort, $order); + + switch ($request->input('sort')) { + case 'created_by': + $groups = $groups->OrderByCreatedBy($order); + break; + default: + // This array is what determines which fields should be allowed to be sorted on ON the table itself. + // These must match a column on the consumables table directly. + $allowed_columns = [ + 'id', + 'name', + 'created_at', + 'users_count', + ]; + + $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; + $groups = $groups->orderBy($sort, $order); + break; + } $total = $groups->count(); $groups = $groups->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.php index a9630aa296..2ed7097322 100644 --- a/app/Http/Controllers/Api/LicenseSeatsController.php +++ b/app/Http/Controllers/Api/LicenseSeatsController.php @@ -107,7 +107,7 @@ class LicenseSeatsController extends Controller // attempt to update the license seat $licenseSeat->fill($request->all()); - $licenseSeat->user_id = auth()->id(); + $licenseSeat->created_by = auth()->id(); // check if this update is a checkin operation // 1. are relevant fields touched at all? diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 61f04bbd0b..db39f987aa 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -70,8 +70,8 @@ class LicensesController extends Controller $licenses->where('depreciation_id', '=', $request->input('depreciation_id')); } - if ($request->filled('user_id')) { - $licenses->where('user_id', '=', $request->input('user_id')); + if ($request->filled('created_by')) { + $licenses->where('created_by', '=', $request->input('created_by')); } if (($request->filled('maintained')) && ($request->input('maintained')=='true')) { @@ -117,7 +117,7 @@ class LicensesController extends Controller $licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order); break; case 'created_by': - $licenses = $licenses->OrderCreatedBy($order); + $licenses = $licenses->OrderByCreatedBy($order); break; default: $allowed_columns = @@ -182,7 +182,7 @@ class LicensesController extends Controller public function show($id) : JsonResponse | array { $this->authorize('view', License::class); - $license = License::withCount('freeSeats')->findOrFail($id); + $license = License::withCount('freeSeats as free_seats_count')->findOrFail($id); $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset'); return (new LicensesTransformer)->transformLicense($license); diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php index eb89693e5c..f111ef6c83 100644 --- a/app/Http/Controllers/Api/ManufacturersController.php +++ b/app/Http/Controllers/Api/ManufacturersController.php @@ -25,11 +25,42 @@ class ManufacturersController extends Controller public function index(Request $request) : JsonResponse | array { $this->authorize('view', Manufacturer::class); - $allowed_columns = ['id', 'name', 'url', 'support_url', 'support_email', 'warranty_lookup_url', 'support_phone', 'created_at', 'updated_at', 'image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count']; + $allowed_columns = [ + 'id', + 'name', + 'url', + 'support_url', + 'support_email', + 'warranty_lookup_url', + 'support_phone', + 'created_at', + 'updated_at', + 'image', + 'assets_count', + 'consumables_count', + 'components_count', + 'licenses_count' + ]; - $manufacturers = Manufacturer::select( - ['id', 'name', 'url', 'support_url', 'warranty_lookup_url', 'support_email', 'support_phone', 'created_at', 'updated_at', 'image', 'deleted_at'] - )->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count'); + $manufacturers = Manufacturer::select([ + 'id', + 'name', + 'url', + 'support_url', + 'warranty_lookup_url', + 'support_email', + 'support_phone', + 'created_by', + 'created_at', + 'updated_at', + 'image', + 'deleted_at', + ]) + ->with('adminuser') + ->withCount('assets as assets_count') + ->withCount('licenses as licenses_count') + ->withCount('consumables as consumables_count') + ->withCount('accessories as accessories_count'); if ($request->input('deleted') == 'true') { $manufacturers->onlyTrashed(); @@ -66,10 +97,18 @@ class ManufacturersController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $manufacturers->count()) ? $manufacturers->count() : app('api_offset_value'); $limit = app('api_limit_value'); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; - $manufacturers->orderBy($sort, $order); + $sort_override = $request->input('sort'); + $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at'; + + switch ($sort_override) { + case 'created_by': + $manufacturers = $manufacturers->OrderByCreatedBy($order); + break; + default: + $manufacturers = $manufacturers->orderBy($column_sort, $order); + break; + } $total = $manufacturers->count(); $manufacturers = $manufacturers->skip($offset)->take($limit)->get(); @@ -181,7 +220,7 @@ class ManufacturersController extends Controller $logaction->item_type = Manufacturer::class; $logaction->item_id = $manufacturer->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('restore'); return response()->json(Helper::formatStandardApiResponse('success', trans('admin/manufacturers/message.restore.success')), 200); diff --git a/app/Http/Controllers/Api/PredefinedKitsController.php b/app/Http/Controllers/Api/PredefinedKitsController.php index 26ccb50354..24f1320185 100644 --- a/app/Http/Controllers/Api/PredefinedKitsController.php +++ b/app/Http/Controllers/Api/PredefinedKitsController.php @@ -23,9 +23,8 @@ class PredefinedKitsController extends Controller public function index(Request $request) : JsonResponse | array { $this->authorize('view', PredefinedKit::class); - $allowed_columns = ['id', 'name']; - $kits = PredefinedKit::query(); + $kits = PredefinedKit::query()->with('adminuser'); if ($request->filled('search')) { $kits = $kits->TextSearch($request->input('search')); @@ -36,8 +35,25 @@ class PredefinedKitsController extends Controller $limit = app('api_limit_value'); $order = $request->input('order') === 'desc' ? 'desc' : 'asc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'name'; - $kits->orderBy($sort, $order); + + switch ($request->input('sort')) { + case 'created_by': + $kits = $kits->OrderByCreatedBy($order); + break; + default: + // This array is what determines which fields should be allowed to be sorted on ON the table itself. + // These must match a column on the consumables table directly. + $allowed_columns = [ + 'id', + 'name', + 'created_at', + 'updated_at', + ]; + + $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; + $kits = $kits->orderBy($sort, $order); + break; + } $total = $kits->count(); $kits = $kits->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index 931886fb29..566911dd27 100644 --- a/app/Http/Controllers/Api/ReportsController.php +++ b/app/Http/Controllers/Api/ReportsController.php @@ -20,7 +20,7 @@ class ReportsController extends Controller { $this->authorize('reports.view'); - $actionlogs = Actionlog::with('item', 'user', 'admin', 'target', 'location'); + $actionlogs = Actionlog::with('item', 'user', 'adminuser', 'target', 'location'); if ($request->filled('search')) { $actionlogs = $actionlogs->TextSearch(e($request->input('search'))); @@ -48,8 +48,8 @@ class ReportsController extends Controller $actionlogs = $actionlogs->where('action_type', '=', $request->input('action_type'))->orderBy('created_at', 'desc'); } - if ($request->filled('user_id')) { - $actionlogs = $actionlogs->where('user_id', '=', $request->input('user_id')); + if ($request->filled('created_by')) { + $actionlogs = $actionlogs->where('created_by', '=', $request->input('created_by')); } if ($request->filled('action_source')) { @@ -68,13 +68,14 @@ class ReportsController extends Controller 'id', 'created_at', 'target_id', - 'user_id', + 'created_by', 'accept_signature', 'action_type', 'note', 'remote_ip', 'user_agent', 'action_source', + 'action_date', ]; @@ -86,8 +87,8 @@ class ReportsController extends Controller $order = ($request->input('order') == 'asc') ? 'asc' : 'desc'; switch ($request->input('sort')) { - case 'admin': - $actionlogs->OrderAdmin($order); + case 'created_by': + $actionlogs->OrderByCreatedBy($order); break; default: $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index ce61d653f5..754ebf7323 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -25,9 +25,17 @@ class StatuslabelsController extends Controller public function index(Request $request) : array { $this->authorize('view', Statuslabel::class); - $allowed_columns = ['id', 'name', 'created_at', 'assets_count', 'color', 'notes', 'default_label']; + $allowed_columns = [ + 'id', + 'name', + 'created_at', + 'assets_count', + 'color', + 'notes', + 'default_label' + ]; - $statuslabels = Statuslabel::withCount('assets as assets_count'); + $statuslabels = Statuslabel::with('adminuser')->withCount('assets as assets_count'); if ($request->filled('search')) { $statuslabels = $statuslabels->TextSearch($request->input('search')); @@ -54,10 +62,18 @@ class StatuslabelsController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $statuslabels->count()) ? $statuslabels->count() : app('api_offset_value'); $limit = app('api_limit_value'); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; - $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; - $statuslabels->orderBy($sort, $order); + $sort_override = $request->input('sort'); + $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at'; + + switch ($sort_override) { + case 'created_by': + $statuslabels = $statuslabels->OrderByCreatedBy($order); + break; + default: + $statuslabels = $statuslabels->orderBy($column_sort, $order); + break; + } $total = $statuslabels->count(); $statuslabels = $statuslabels->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 7a126ba97a..bfe8f44ef1 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -691,7 +691,7 @@ class UsersController extends Controller $logaction->item_type = User::class; $logaction->item_id = $user->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('2FA reset'); return response()->json(['message' => trans('admin/settings/general.two_factor_reset_success')], 200); @@ -741,7 +741,7 @@ class UsersController extends Controller $logaction->item_type = User::class; $logaction->item_id = $user->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('restore'); return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.restored')), 200); diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index 02be1e6061..360db45262 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -109,7 +109,7 @@ class AssetMaintenancesController extends Controller $assetMaintenance->title = $request->input('title'); $assetMaintenance->start_date = $request->input('start_date'); $assetMaintenance->completion_date = $request->input('completion_date'); - $assetMaintenance->user_id = Auth::id(); + $assetMaintenance->created_by = auth()->id(); if (($assetMaintenance->completion_date !== null) && ($assetMaintenance->start_date !== '') diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 94c630c094..9d4c13afd9 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -78,7 +78,7 @@ class AssetModelsController extends Controller $model->manufacturer_id = $request->input('manufacturer_id'); $model->category_id = $request->input('category_id'); $model->notes = $request->input('notes'); - $model->user_id = Auth::id(); + $model->created_by = auth()->id(); $model->requestable = $request->has('requestable'); if ($request->input('fieldset_id') != '') { @@ -237,7 +237,7 @@ class AssetModelsController extends Controller $logaction->item_type = AssetModel::class; $logaction->item_id = $model->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('restore'); diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 5f944c386e..dceaa9b08a 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -133,7 +133,7 @@ class AssetsController extends Controller $asset->model_id = $request->input('model_id'); $asset->order_number = $request->input('order_number'); $asset->notes = $request->input('notes'); - $asset->user_id = Auth::id(); + $asset->created_by = auth()->id(); $asset->status_id = request('status_id'); $asset->warranty_months = request('warranty_months', null); $asset->purchase_cost = request('purchase_cost'); @@ -329,9 +329,7 @@ class AssetsController extends Controller } $asset->supplier_id = $request->input('supplier_id', null); $asset->expected_checkin = $request->input('expected_checkin', null); - - // If the box isn't checked, it's not in the request at all. - $asset->requestable = $request->filled('requestable', 0); + $asset->requestable = $request->input('requestable', 0); $asset->rtd_location_id = $request->input('rtd_location_id', null); $asset->byod = $request->input('byod', 0); @@ -747,7 +745,7 @@ class AssetsController extends Controller Actionlog::firstOrCreate([ 'item_id' => $asset->id, 'item_type' => Asset::class, - 'user_id' => auth()->id(), + 'created_by' => auth()->id(), 'note' => 'Checkout imported by '.auth()->user()->present()->fullName().' from history importer', 'target_id' => $item[$asset_tag][$batch_counter]['user_id'], 'target_type' => User::class, @@ -775,7 +773,7 @@ class AssetsController extends Controller Actionlog::firstOrCreate([ 'item_id' => $item[$asset_tag][$batch_counter]['asset_id'], 'item_type' => Asset::class, - 'user_id' => auth()->id(), + 'created_by' => auth()->id(), 'note' => 'Checkin imported by '.auth()->user()->present()->fullName().' from history importer', 'target_id' => null, 'created_at' => $checkin_date, diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index d58edbacab..1ce08e65e9 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -10,6 +10,7 @@ use App\Models\AssetModel; use App\Models\Statuslabel; use App\Models\Setting; use App\View\Label; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB; @@ -271,6 +272,23 @@ class BulkAssetsController extends Controller $this->conditionallyAddItem($custom_field_column); } + if (!($asset->eol_explicit)) { + if ($request->filled('model_id')) { + $model = AssetModel::find($request->input('model_id')); + if ($model->eol > 0) { + if ($request->filled('purchase_date')) { + $this->update_array['asset_eol_date'] = Carbon::parse($request->input('purchase_date'))->addMonths($model->eol)->format('Y-m-d'); + } else { + $this->update_array['asset_eol_date'] = Carbon::parse($asset->purchase_date)->addMonths($model->eol)->format('Y-m-d'); + } + } else { + $this->update_array['asset_eol_date'] = null; + } + } elseif (($request->filled('purchase_date')) && ($asset->model->eol > 0)) { + $this->update_array['asset_eol_date'] = Carbon::parse($request->input('purchase_date'))->addMonths($asset->model->eol)->format('Y-m-d'); + } + } + /** * Blank out fields that were requested to be blanked out via checkbox */ @@ -281,6 +299,9 @@ class BulkAssetsController extends Controller if ($request->input('null_purchase_date')=='1') { $this->update_array['purchase_date'] = null; + if (!($asset->eol_explicit)) { + $this->update_array['asset_eol_date'] = null; + } } if ($request->input('null_expected_checkin_date')=='1') { diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index ac57ad6a6d..93b3d4a0d0 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -69,7 +69,7 @@ class CategoriesController extends Controller $category->use_default_eula = $request->input('use_default_eula', '0'); $category->require_acceptance = $request->input('require_acceptance', '0'); $category->checkin_email = $request->input('checkin_email', '0'); - $category->user_id = Auth::id(); + $category->created_by = auth()->id(); $category = $request->handleImages($category); if ($category->save()) { diff --git a/app/Http/Controllers/CompaniesController.php b/app/Http/Controllers/CompaniesController.php index 589832af72..238ffc85f5 100644 --- a/app/Http/Controllers/CompaniesController.php +++ b/app/Http/Controllers/CompaniesController.php @@ -60,6 +60,7 @@ final class CompaniesController extends Controller $company->phone = $request->input('phone'); $company->fax = $request->input('fax'); $company->email = $request->input('email'); + $company->created_by = auth()->id(); $company = $request->handleImages($company); diff --git a/app/Http/Controllers/Components/ComponentCheckoutController.php b/app/Http/Controllers/Components/ComponentCheckoutController.php index e9db70811c..b40d592369 100644 --- a/app/Http/Controllers/Components/ComponentCheckoutController.php +++ b/app/Http/Controllers/Components/ComponentCheckoutController.php @@ -106,7 +106,7 @@ class ComponentCheckoutController extends Controller $component->asset_id = $request->input('asset_id'); $component->assets()->attach($component->id, [ 'component_id' => $component->id, - 'user_id' => auth()->user()->id, + 'created_by' => auth()->user()->id, 'created_at' => date('Y-m-d H:i:s'), 'assigned_qty' => $request->input('assigned_qty'), 'asset_id' => $request->input('asset_id'), diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.php index 57cd0a2b45..430984767e 100644 --- a/app/Http/Controllers/Components/ComponentsController.php +++ b/app/Http/Controllers/Components/ComponentsController.php @@ -81,7 +81,7 @@ class ComponentsController extends Controller $component->purchase_date = $request->input('purchase_date', null); $component->purchase_cost = $request->input('purchase_cost', null); $component->qty = $request->input('qty'); - $component->user_id = Auth::id(); + $component->created_by = auth()->id(); $component->notes = $request->input('notes'); $component = $request->handleImages($component); diff --git a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php index 1bdb16af92..3bf202733a 100644 --- a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php +++ b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php @@ -95,7 +95,7 @@ class ConsumableCheckoutController extends Controller for($i = 0; $i < $quantity; $i++){ $consumable->users()->attach($consumable->id, [ 'consumable_id' => $consumable->id, - 'user_id' => $admin_user->id, + 'created_by' => $admin_user->id, 'assigned_to' => e($request->input('assigned_to')), 'note' => $request->input('note'), ]); diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.php index 42c0766fe0..98141f2783 100644 --- a/app/Http/Controllers/Consumables/ConsumablesController.php +++ b/app/Http/Controllers/Consumables/ConsumablesController.php @@ -81,7 +81,7 @@ class ConsumablesController extends Controller $consumable->purchase_date = $request->input('purchase_date'); $consumable->purchase_cost = $request->input('purchase_cost'); $consumable->qty = $request->input('qty'); - $consumable->user_id = Auth::id(); + $consumable->created_by = auth()->id(); $consumable->notes = $request->input('notes'); @@ -221,7 +221,7 @@ class ConsumablesController extends Controller $consumable = clone $consumable_to_close; $consumable->id = null; $consumable->image = null; - $consumable->user_id = null; + $consumable->created_by = null; return view('consumables/edit')->with('item', $consumable); } diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 42f6c212db..5a0dc6aec2 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -104,7 +104,7 @@ class CustomFieldsController extends Controller "auto_add_to_fieldsets" => $request->get("auto_add_to_fieldsets", 0), "show_in_listview" => $request->get("show_in_listview", 0), "show_in_requestable_list" => $request->get("show_in_requestable_list", 0), - "user_id" => Auth::id() + "user_id" => auth()->id() ]); @@ -248,7 +248,7 @@ class CustomFieldsController extends Controller $field->name = trim(e($request->get("name"))); $field->element = e($request->get("element")); $field->field_values = $request->get("field_values"); - $field->user_id = Auth::id(); + $field->created_by = auth()->id(); $field->help_text = $request->get("help_text"); $field->show_in_email = $show_in_email; $field->is_unique = $request->get("is_unique", 0); diff --git a/app/Http/Controllers/CustomFieldsetsController.php b/app/Http/Controllers/CustomFieldsetsController.php index 8b9844d152..1d887db29a 100644 --- a/app/Http/Controllers/CustomFieldsetsController.php +++ b/app/Http/Controllers/CustomFieldsetsController.php @@ -90,7 +90,7 @@ class CustomFieldsetsController extends Controller $fieldset = new CustomFieldset([ 'name' => $request->get('name'), - 'user_id' => auth()->id(), + 'created_by' => auth()->id(), ]); $validator = Validator::make($request->all(), $fieldset->rules); diff --git a/app/Http/Controllers/DepartmentsController.php b/app/Http/Controllers/DepartmentsController.php index 5818435deb..287315ef2c 100644 --- a/app/Http/Controllers/DepartmentsController.php +++ b/app/Http/Controllers/DepartmentsController.php @@ -51,7 +51,7 @@ class DepartmentsController extends Controller $this->authorize('create', Department::class); $department = new Department; $department->fill($request->all()); - $department->user_id = auth()->id(); + $department->created_by = auth()->id(); $department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null); $department->location_id = ($request->filled('location_id') ? $request->input('location_id') : null); $department->company_id = ($request->filled('company_id') ? $request->input('company_id') : null); diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index 888f7a7e77..5f4a5ca10d 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -61,7 +61,7 @@ class DepreciationsController extends Controller // Depreciation data $depreciation->name = $request->input('name'); $depreciation->months = $request->input('months'); - $depreciation->user_id = Auth::id(); + $depreciation->created_by = auth()->id(); $request->validate([ 'depreciation_min' => [ diff --git a/app/Http/Controllers/Kits/PredefinedKitsController.php b/app/Http/Controllers/Kits/PredefinedKitsController.php index 187f5aad14..54f7514510 100644 --- a/app/Http/Controllers/Kits/PredefinedKitsController.php +++ b/app/Http/Controllers/Kits/PredefinedKitsController.php @@ -55,6 +55,7 @@ class PredefinedKitsController extends Controller // Create a new Predefined Kit $kit = new PredefinedKit; $kit->name = $request->input('name'); + $kit->created_by = auth()->id(); if (! $kit->save()) { return redirect()->back()->withInput()->withErrors($kit->getErrors()); diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php index c08980fc06..0f31db1449 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php @@ -77,7 +77,7 @@ class LicenseCheckoutController extends Controller $this->authorize('checkout', $license); $licenseSeat = $this->findLicenseSeatToCheckout($license, $seatId); - $licenseSeat->user_id = Auth::id(); + $licenseSeat->created_by = auth()->id(); $licenseSeat->notes = $request->input('notes'); diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.php index 7a51344dd0..6098423ba3 100755 --- a/app/Http/Controllers/Licenses/LicensesController.php +++ b/app/Http/Controllers/Licenses/LicensesController.php @@ -99,7 +99,7 @@ class LicensesController extends Controller $license->supplier_id = $request->input('supplier_id'); $license->category_id = $request->input('category_id'); $license->termination_date = $request->input('termination_date'); - $license->user_id = Auth::id(); + $license->created_by = auth()->id(); $license->min_amt = $request->input('min_amt'); session()->put(['redirect_option' => $request->get('redirect_option')]); diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index f32e6b8489..75abce97ed 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -75,7 +75,7 @@ class LocationsController extends Controller $location->zip = $request->input('zip'); $location->ldap_ou = $request->input('ldap_ou'); $location->manager_id = $request->input('manager_id'); - $location->user_id = auth()->id(); + $location->created_by = auth()->id(); $location->phone = request('phone'); $location->fax = request('fax'); @@ -278,7 +278,7 @@ class LocationsController extends Controller $logaction->item_type = Location::class; $logaction->item_id = $location->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('restore'); return redirect()->route('locations.index')->with('success', trans('admin/locations/message.restore.success')); diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 8e979e3896..68124f644c 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -61,7 +61,7 @@ class ManufacturersController extends Controller $this->authorize('create', Manufacturer::class); $manufacturer = new Manufacturer; $manufacturer->name = $request->input('name'); - $manufacturer->user_id = Auth::id(); + $manufacturer->created_by = auth()->id(); $manufacturer->url = $request->input('url'); $manufacturer->support_url = $request->input('support_url'); $manufacturer->warranty_lookup_url = $request->input('warranty_lookup_url'); @@ -219,7 +219,7 @@ class ManufacturersController extends Controller $logaction->item_type = Manufacturer::class; $logaction->item_id = $manufacturer->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('restore'); // Redirect them to the deleted page if there are more, otherwise the section index diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index c4b7ee0609..105dac6350 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -703,6 +703,10 @@ class ReportsController extends Controller $assets->whereBetween('assets.expected_checkin', [$request->input('expected_checkin_start'), $request->input('expected_checkin_end')]); } + if (($request->filled('asset_eol_date_start')) && ($request->filled('asset_eol_date_end'))) { + $assets->whereBetween('assets.asset_eol_date', [$request->input('asset_eol_date_start'), $request->input('asset_eol_date_end')]); + } + if (($request->filled('last_audit_start')) && ($request->filled('last_audit_end'))) { $last_audit_start = Carbon::parse($request->input('last_audit_start'))->startOfDay(); $last_audit_end = Carbon::parse($request->input('last_audit_end'))->endOfDay(); @@ -778,7 +782,7 @@ class ReportsController extends Controller } if ($request->filled('eol')) { - $row[] = ($asset->asset_eol_date) ? $asset->asset_eol_date : ''; + $row[] = ($asset->purchase_date != '') ? $asset->asset_eol_date : ''; } if ($request->filled('order')) { diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 31b4179b4a..b9026aaece 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -181,7 +181,7 @@ class SettingsController extends Controller $settings->brand = 1; $settings->locale = $request->input('locale', 'en-US'); $settings->default_currency = $request->input('default_currency', 'USD'); - $settings->user_id = 1; + $settings->created_by = 1; $settings->email_domain = $request->input('email_domain'); $settings->email_format = $request->input('email_format'); $settings->next_auto_tag_base = 1; diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index 535117e97f..21a7c798b9 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -69,7 +69,7 @@ class StatuslabelsController extends Controller // Save the Statuslabel data $statusLabel->name = $request->input('name'); - $statusLabel->user_id = Auth::id(); + $statusLabel->created_by = auth()->id(); $statusLabel->notes = $request->input('notes'); $statusLabel->deployable = $statusType['deployable']; $statusLabel->pending = $statusType['pending']; diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.php index e96e32b84f..605bb66f6d 100755 --- a/app/Http/Controllers/SuppliersController.php +++ b/app/Http/Controllers/SuppliersController.php @@ -62,7 +62,7 @@ class SuppliersController extends Controller $supplier->email = request('email'); $supplier->notes = request('notes'); $supplier->url = $supplier->addhttp(request('url')); - $supplier->user_id = Auth::id(); + $supplier->created_by = auth()->id(); $supplier = $request->handleImages($supplier); if ($supplier->save()) { diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index a848f3808b..fbf08c9820 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -13,6 +13,7 @@ use App\Models\Group; use App\Models\LicenseSeat; use App\Models\ConsumableAssignment; use App\Models\Consumable; +use App\Models\Setting; use App\Models\User; use Carbon\Carbon; use Illuminate\Http\Request; @@ -35,7 +36,7 @@ class BulkUsersController extends Controller */ public function edit(Request $request) { - $this->authorize('update', User::class); + $this->authorize('view', User::class); // Make sure there were users selected if (($request->filled('ids')) && (count($request->input('ids')) > 0)) { @@ -47,16 +48,18 @@ class BulkUsersController extends Controller // bulk edit, display the bulk edit form if ($request->input('bulk_actions') == 'edit') { + $this->authorize('update', User::class); return view('users/bulk-edit', compact('users')) ->with('groups', Group::pluck('name', 'id')); // bulk delete, display the bulk delete confirmation form } elseif ($request->input('bulk_actions') == 'delete') { + $this->authorize('delete', User::class); return view('users/confirm-bulk-delete')->with('users', $users)->with('statuslabel_list', Helper::statusLabelList()); // merge, confirm they have at least 2 users selected and display the merge screen } elseif ($request->input('bulk_actions') == 'merge') { - + $this->authorize('delete', User::class); if (($request->filled('ids')) && (count($request->input('ids')) > 1)) { return view('users/confirm-merge')->with('users', $users); // Not enough users selected, send them back @@ -76,6 +79,33 @@ class BulkUsersController extends Controller } return redirect()->back()->with('success', trans('admin/users/message.password_resets_sent')); + } elseif ($request->input('bulk_actions') == 'print') { + $users = User::query() + ->with([ + 'assets.assetlog', + 'assets.assignedAssets.assetlog', + 'assets.assignedAssets.defaultLoc', + 'assets.assignedAssets.location', + 'assets.assignedAssets.model.category', + 'assets.defaultLoc', + 'assets.location', + 'assets.model.category', + 'accessories.assetlog', + 'accessories.category', + 'accessories.manufacturer', + 'consumables.assetlog', + 'consumables.category', + 'consumables.manufacturer', + 'licenses.category', + ]) + ->withTrashed() + ->findMany($request->input('ids')); + + $users->each(fn($user) => $this->authorize('view', $user)); + + return view('users.print') + ->with('users', $users) + ->with('settings', Setting::getSettings()); } } @@ -101,7 +131,7 @@ class BulkUsersController extends Controller $user_raw_array = $request->input('ids'); // Remove the user from any updates. - $user_raw_array = array_diff($user_raw_array, [Auth::id()]); + $user_raw_array = array_diff($user_raw_array, [auth()->id()]); $manager_conflict = false; $users = User::whereIn('id', $user_raw_array)->where('id', '!=', auth()->id())->get(); @@ -166,7 +196,7 @@ class BulkUsersController extends Controller } // Save the updated info User::whereIn('id', $user_raw_array) - ->where('id', '!=', Auth::id())->update($this->update_array); + ->where('id', '!=', auth()->id())->update($this->update_array); if (array_key_exists('location_id', $this->update_array)){ Asset::where('assigned_type', User::class) @@ -228,7 +258,7 @@ class BulkUsersController extends Controller $user_raw_array = request('ids'); - if (($key = array_search(Auth::id(), $user_raw_array)) !== false) { + if (($key = array_search(auth()->id(), $user_raw_array)) !== false) { unset($user_raw_array[$key]); } @@ -293,7 +323,7 @@ class BulkUsersController extends Controller $logAction->item_type = $itemType; $logAction->target_id = $item->assigned_to; $logAction->target_type = User::class; - $logAction->user_id = Auth::id(); + $logAction->created_at = auth()->id(); $logAction->note = 'Bulk checkin items'; $logAction->logaction('checkin from'); } @@ -307,7 +337,7 @@ class BulkUsersController extends Controller $logAction->item_type = Accessory::class; $logAction->target_id = $accessoryUserRow->assigned_to; $logAction->target_type = User::class; - $logAction->user_id = Auth::id(); + $logAction->created_at = auth()->id(); $logAction->note = 'Bulk checkin items'; $logAction->logaction('checkin from'); } @@ -321,7 +351,7 @@ class BulkUsersController extends Controller $logAction->item_type = Consumable::class; $logAction->target_id = $consumableUserRow->assigned_to; $logAction->target_type = User::class; - $logAction->user_id = Auth::id(); + $logAction->created_at = auth()->id(); $logAction->note = 'Bulk checkin items'; $logAction->logaction('checkin from'); } diff --git a/app/Http/Controllers/Users/UserFilesController.php b/app/Http/Controllers/Users/UserFilesController.php index ded44f35f6..9e5f322c03 100644 --- a/app/Http/Controllers/Users/UserFilesController.php +++ b/app/Http/Controllers/Users/UserFilesController.php @@ -46,7 +46,7 @@ class UserFilesController extends Controller $logAction = new Actionlog(); $logAction->item_id = $user->id; $logAction->item_type = User::class; - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->note = $request->input('notes'); $logAction->target_id = null; $logAction->created_at = date("Y-m-d H:i:s"); diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 1d7fc91ebd..051db1f4ef 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -372,7 +372,7 @@ class UsersController extends Controller $logaction->item_type = User::class; $logaction->item_id = $user->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = auth()->id(); + $logaction->created_by = auth()->id(); $logaction->logaction('restore'); // Redirect them to the deleted page if there are more, otherwise the section index @@ -597,23 +597,37 @@ class UsersController extends Controller public function printInventory($id) { $this->authorize('view', User::class); - if ($user = User::where('id', $id)->withTrashed()->first()) { + $user = User::where('id', $id) + ->with([ + 'assets.assetlog', + 'assets.assignedAssets.assetlog', + 'assets.assignedAssets.defaultLoc', + 'assets.assignedAssets.location', + 'assets.assignedAssets.model.category', + 'assets.defaultLoc', + 'assets.location', + 'assets.model.category', + 'accessories.assetlog', + 'accessories.category', + 'accessories.manufacturer', + 'consumables.assetlog', + 'consumables.category', + 'consumables.manufacturer', + 'licenses.category', + ]) + ->withTrashed() + ->first(); + + if ($user) { $this->authorize('view', $user); - $assets = Asset::where('assigned_to', $id)->where('assigned_type', User::class)->with('model', 'model.category')->get(); - $accessories = $user->accessories()->get(); - $consumables = $user->consumables()->get(); - return view('users/print')->with('assets', $assets) - ->with('licenses', $user->licenses()->get()) - ->with('accessories', $accessories) - ->with('consumables', $consumables) - ->with('show_user', $user) + return view('users.print') + ->with('users', [$user]) ->with('settings', Setting::getSettings()); } return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id'))); - } /** diff --git a/app/Http/Requests/ItemImportRequest.php b/app/Http/Requests/ItemImportRequest.php index 2ea0839c93..a6dc0ad7e5 100644 --- a/app/Http/Requests/ItemImportRequest.php +++ b/app/Http/Requests/ItemImportRequest.php @@ -60,7 +60,7 @@ class ItemImportRequest extends FormRequest $fieldMappings = array_change_key_case(array_flip($import->field_map), CASE_LOWER); } $importer->setCallbacks([$this, 'log'], [$this, 'progress'], [$this, 'errorCallback']) - ->setUserId(Auth::id()) + ->setUserId(auth()->id()) ->setUpdating($this->get('import-update')) ->setShouldNotify($this->get('send-welcome')) ->setUsernameFormat('firstname.lastname') diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index b2feb72f79..e1665e2136 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -9,6 +9,7 @@ use App\Models\Setting; use Carbon\Carbon; use Carbon\Exceptions\InvalidFormatException; use Illuminate\Support\Facades\Gate; +use App\Rules\AssetCannotBeCheckedOutToNondeployableStatus; class StoreAssetRequest extends ImageUploadRequest { @@ -61,6 +62,7 @@ class StoreAssetRequest extends ImageUploadRequest return array_merge( $modelRules, + ['status_id' => [new AssetCannotBeCheckedOutToNondeployableStatus()]], parent::rules(), ); } diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php index c85c4e86f4..839576c729 100644 --- a/app/Http/Transformers/AccessoriesTransformer.php +++ b/app/Http/Transformers/AccessoriesTransformer.php @@ -38,9 +38,12 @@ 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' => (int) $accessory->numRemaining(), + 'remaining_qty' => (int) ($accessory->qty - $accessory->checkouts_count), 'checkouts_count' => $accessory->checkouts_count, - + 'created_by' => ($accessory->adminuser) ? [ + 'id' => (int) $accessory->adminuser->id, + 'name'=> e($accessory->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($accessory->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($accessory->updated_at, 'datetime'), @@ -57,7 +60,7 @@ class AccessoriesTransformer $permissions_array['user_can_checkout'] = false; - if ($accessory->numRemaining() > 0) { + if (($accessory->qty - $accessory->checkouts_count) > 0) { $permissions_array['user_can_checkout'] = true; } diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 96d74827d2..d0605c747b 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -176,11 +176,17 @@ class ActionlogsTransformer 'next_audit_date' => ($actionlog->itemType()=='asset') ? Helper::getFormattedDateObject($actionlog->calcNextAuditDate(null, $actionlog->item), 'date'): null, 'days_to_next_audit' => $actionlog->daysUntilNextAudit($settings->audit_interval, $actionlog->item), 'action_type' => $actionlog->present()->actionType(), - 'admin' => ($actionlog->admin) ? [ - 'id' => (int) $actionlog->admin->id, - 'name' => e($actionlog->admin->getFullNameAttribute()), - 'first_name'=> e($actionlog->admin->first_name), - 'last_name'=> e($actionlog->admin->last_name) + 'admin' => ($actionlog->adminuser) ? [ + 'id' => (int) $actionlog->adminuser->id, + 'name' => e($actionlog->adminuser->getFullNameAttribute()), + 'first_name'=> e($actionlog->adminuser->first_name), + 'last_name'=> e($actionlog->adminuser->last_name) + ] : null, + 'created_by' => ($actionlog->adminuser) ? [ + 'id' => (int) $actionlog->adminuser->id, + 'name' => e($actionlog->adminuser->getFullNameAttribute()), + 'first_name'=> e($actionlog->adminuser->first_name), + 'last_name'=> e($actionlog->adminuser->last_name) ] : null, 'target' => ($actionlog->target) ? [ 'id' => (int) $actionlog->target->id, diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php index 88ac447c25..c5f0abbaab 100644 --- a/app/Http/Transformers/AssetMaintenancesTransformer.php +++ b/app/Http/Transformers/AssetMaintenancesTransformer.php @@ -64,7 +64,14 @@ class AssetMaintenancesTransformer 'start_date' => Helper::getFormattedDateObject($assetmaintenance->start_date, 'date'), 'asset_maintenance_time' => $assetmaintenance->asset_maintenance_time, 'completion_date' => Helper::getFormattedDateObject($assetmaintenance->completion_date, 'date'), - 'user_id' => ($assetmaintenance->admin) ? ['id' => $assetmaintenance->admin->id, 'name'=> e($assetmaintenance->admin->getFullNameAttribute())] : null, + 'user_id' => ($assetmaintenance->adminuser) ? [ + 'id' => $assetmaintenance->adminuser->id, + 'name'=> e($assetmaintenance->admin->getFullNameAttribute()) + ] : null, // legacy to not change the shape of the API + 'created_by' => ($assetmaintenance->adminuser) ? [ + 'id' => (int) $assetmaintenance->adminuser->id, + 'name'=> e($assetmaintenance->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($assetmaintenance->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($assetmaintenance->updated_at, 'datetime'), 'is_warranty'=> $assetmaintenance->is_warranty, diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 17693fccf4..d7ee423249 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -80,6 +80,10 @@ class AssetsTransformer 'assigned_to' => $this->transformAssignedTo($asset), 'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null, 'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null, + 'created_by' => ($asset->adminuser) ? [ + 'id' => (int) $asset->adminuser->id, + 'name'=> e($asset->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'), 'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime'), diff --git a/app/Http/Transformers/CategoriesTransformer.php b/app/Http/Transformers/CategoriesTransformer.php index d5e1ceb51b..2dd82b3b70 100644 --- a/app/Http/Transformers/CategoriesTransformer.php +++ b/app/Http/Transformers/CategoriesTransformer.php @@ -62,6 +62,10 @@ class CategoriesTransformer 'consumables_count' => (int) $category->consumables_count, 'components_count' => (int) $category->components_count, 'licenses_count' => (int) $category->licenses_count, + 'created_by' => ($category->adminuser) ? [ + 'id' => (int) $category->adminuser->id, + 'name'=> e($category->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($category->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($category->updated_at, 'datetime'), ]; diff --git a/app/Http/Transformers/CompaniesTransformer.php b/app/Http/Transformers/CompaniesTransformer.php index fe8befc27a..530df32044 100644 --- a/app/Http/Transformers/CompaniesTransformer.php +++ b/app/Http/Transformers/CompaniesTransformer.php @@ -30,14 +30,18 @@ class CompaniesTransformer 'fax' => ($company->fax!='') ? e($company->fax): null, 'email' => ($company->email!='') ? e($company->email): null, 'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null, - 'created_at' => Helper::getFormattedDateObject($company->created_at, 'datetime'), - 'updated_at' => Helper::getFormattedDateObject($company->updated_at, 'datetime'), 'assets_count' => (int) $company->assets_count, 'licenses_count' => (int) $company->licenses_count, 'accessories_count' => (int) $company->accessories_count, 'consumables_count' => (int) $company->consumables_count, 'components_count' => (int) $company->components_count, 'users_count' => (int) $company->users_count, + 'created_by' => ($company->adminuser) ? [ + 'id' => (int) $company->adminuser->id, + 'name'=> e($company->adminuser->present()->fullName()), + ] : null, + 'created_at' => Helper::getFormattedDateObject($company->created_at, 'datetime'), + 'updated_at' => Helper::getFormattedDateObject($company->updated_at, 'datetime'), ]; $permissions_array['available_actions'] = [ diff --git a/app/Http/Transformers/ComponentsTransformer.php b/app/Http/Transformers/ComponentsTransformer.php index d18870bdc3..70572c9494 100644 --- a/app/Http/Transformers/ComponentsTransformer.php +++ b/app/Http/Transformers/ComponentsTransformer.php @@ -47,6 +47,10 @@ class ComponentsTransformer 'name' => e($component->company->name), ] : null, 'notes' => ($component->notes) ? Helper::parseEscapedMarkedownInline($component->notes) : null, + 'created_by' => ($component->adminuser) ? [ + 'id' => (int) $component->adminuser->id, + 'name'=> e($component->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($component->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($component->updated_at, 'datetime'), 'user_can_checkout' => ($component->numRemaining() > 0) ? 1 : 0, diff --git a/app/Http/Transformers/ConsumablesTransformer.php b/app/Http/Transformers/ConsumablesTransformer.php index d0ae57eef0..b31e31ac96 100644 --- a/app/Http/Transformers/ConsumablesTransformer.php +++ b/app/Http/Transformers/ConsumablesTransformer.php @@ -40,6 +40,10 @@ class ConsumablesTransformer 'purchase_date' => Helper::getFormattedDateObject($consumable->purchase_date, 'date'), 'qty' => (int) $consumable->qty, 'notes' => ($consumable->notes) ? Helper::parseEscapedMarkedownInline($consumable->notes) : null, + 'created_by' => ($consumable->adminuser) ? [ + 'id' => (int) $consumable->adminuser->id, + 'name'=> e($consumable->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($consumable->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($consumable->updated_at, 'datetime'), ]; diff --git a/app/Http/Transformers/DepreciationsTransformer.php b/app/Http/Transformers/DepreciationsTransformer.php index b3dc8c5aae..64d4c88f7e 100644 --- a/app/Http/Transformers/DepreciationsTransformer.php +++ b/app/Http/Transformers/DepreciationsTransformer.php @@ -31,6 +31,10 @@ class DepreciationsTransformer 'assets_count' => $depreciation->assets_count, 'models_count' => $depreciation->models_count, 'licenses_count' => $depreciation->licenses_count, + 'created_by' => ($depreciation->adminuser) ? [ + 'id' => (int) $depreciation->adminuser->id, + 'name'=> e($depreciation->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime') ]; diff --git a/app/Http/Transformers/GroupsTransformer.php b/app/Http/Transformers/GroupsTransformer.php index bf7e2bfd70..03e96d5622 100644 --- a/app/Http/Transformers/GroupsTransformer.php +++ b/app/Http/Transformers/GroupsTransformer.php @@ -26,7 +26,10 @@ class GroupsTransformer 'name' => e($group->name), 'permissions' => json_decode($group->permissions), 'users_count' => (int) $group->users_count, - 'created_by' => ($group->admin) ? e($group->admin->present()->fullName) : null, + 'created_by' => ($group->adminuser) ? [ + 'id' => (int) $group->adminuser->id, + 'name'=> e($group->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($group->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($group->updated_at, 'datetime'), ]; diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php index 4fad9b9a68..673ac06b3d 100644 --- a/app/Http/Transformers/LicensesTransformer.php +++ b/app/Http/Transformers/LicensesTransformer.php @@ -61,7 +61,7 @@ class LicensesTransformer 'checkin' => Gate::allows('checkin', License::class), 'clone' => Gate::allows('create', License::class), 'update' => Gate::allows('update', License::class), - 'delete' => (Gate::allows('delete', License::class) && ($license->seats == $license->availCount()->count())) ? true : false, + 'delete' => (Gate::allows('delete', License::class) && ($license->free_seats_count > 0)) ? true : false, ]; $array += $permissions_array; diff --git a/app/Http/Transformers/ManufacturersTransformer.php b/app/Http/Transformers/ManufacturersTransformer.php index 9c84fd50fe..e08aaa7436 100644 --- a/app/Http/Transformers/ManufacturersTransformer.php +++ b/app/Http/Transformers/ManufacturersTransformer.php @@ -36,6 +36,10 @@ class ManufacturersTransformer 'licenses_count' => (int) $manufacturer->licenses_count, 'consumables_count' => (int) $manufacturer->consumables_count, 'accessories_count' => (int) $manufacturer->accessories_count, + 'created_by' => ($manufacturer->adminuser) ? [ + 'id' => (int) $manufacturer->adminuser->id, + 'name'=> e($manufacturer->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'), 'deleted_at' => Helper::getFormattedDateObject($manufacturer->deleted_at, 'datetime'), diff --git a/app/Http/Transformers/PredefinedKitsTransformer.php b/app/Http/Transformers/PredefinedKitsTransformer.php index a5d37e5c72..b5de12fc08 100644 --- a/app/Http/Transformers/PredefinedKitsTransformer.php +++ b/app/Http/Transformers/PredefinedKitsTransformer.php @@ -2,6 +2,7 @@ namespace App\Http\Transformers; +use App\Helpers\Helper; use App\Models\PredefinedKit; use App\Models\SnipeModel; use Illuminate\Support\Facades\Gate; @@ -30,6 +31,12 @@ class PredefinedKitsTransformer $array = [ 'id' => (int) $kit->id, 'name' => e($kit->name), + 'created_by' => ($kit->adminuser) ? [ + 'id' => (int) $kit->adminuser->id, + 'name'=> e($kit->adminuser->present()->fullName()), + ] : null, + 'created_at' => Helper::getFormattedDateObject($kit->created_at, 'datetime'), + 'updated_at' => Helper::getFormattedDateObject($kit->updated_at, 'datetime'), ]; $permissions_array['available_actions'] = [ diff --git a/app/Http/Transformers/StatuslabelsTransformer.php b/app/Http/Transformers/StatuslabelsTransformer.php index 41dd336068..751edb7016 100644 --- a/app/Http/Transformers/StatuslabelsTransformer.php +++ b/app/Http/Transformers/StatuslabelsTransformer.php @@ -30,6 +30,10 @@ class StatuslabelsTransformer 'default_label' => ($statuslabel->default_label == '1') ? true : false, 'assets_count' => (int) $statuslabel->assets_count, 'notes' => e($statuslabel->notes), + 'created_by' => ($statuslabel->adminuser) ? [ + 'id' => (int) $statuslabel->adminuser->id, + 'name'=> e($statuslabel->adminuser->present()->fullName()), + ] : null, 'created_at' => Helper::getFormattedDateObject($statuslabel->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($statuslabel->updated_at, 'datetime'), ]; diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 781a6311fe..1112a04e35 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -177,7 +177,7 @@ class AssetImporter extends ItemImporter $this->log('Asset '.$this->item['name'].' with serial number '.$this->item['serial'].' was created'); // If we have a target to checkout to, lets do so. - //-- user_id is a property of the abstract class Importer, which this class inherits from and it's set by + //-- created_by is a property of the abstract class Importer, which this class inherits from and it's set by //-- the class that needs to use it (command importer or GUI importer inside the project). if (isset($target) && ($target !== false)) { if (!is_null($asset->assigned_to)){ @@ -186,7 +186,7 @@ class AssetImporter extends ItemImporter } } - $asset->fresh()->checkOut($target, $this->user_id, $checkout_date, null, 'Checkout from CSV Importer', $asset->name); + $asset->fresh()->checkOut($target, $this->created_by, $checkout_date, null, 'Checkout from CSV Importer', $asset->name); } return; diff --git a/app/Importer/ComponentImporter.php b/app/Importer/ComponentImporter.php index f72d4cbfd7..9687ec4f17 100644 --- a/app/Importer/ComponentImporter.php +++ b/app/Importer/ComponentImporter.php @@ -58,7 +58,7 @@ class ComponentImporter extends ItemImporter if (isset($this->item['asset_tag']) && ($asset = Asset::where('asset_tag', $this->item['asset_tag'])->first())) { $component->assets()->attach($component->id, [ 'component_id' => $component->id, - 'user_id' => $this->user_id, + 'created_by' => $this->created_by, 'created_at' => date('Y-m-d H:i:s'), 'assigned_qty' => 1, // Only assign the first one to the asset 'asset_id' => $asset->id, diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index c2214ef37d..678fb9ecb2 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -22,7 +22,7 @@ abstract class Importer * @var */ - protected $user_id; + protected $created_by; /** * Are we updating items in the import * @var bool @@ -395,7 +395,7 @@ abstract class Importer } /** - * Matches a user by user_id if user_name provided is a number + * Matches a user by created_by if user_name provided is a number * @param string $user_name users full name from csv * @return User User Matching ID */ @@ -412,13 +412,13 @@ abstract class Importer /** * Sets the Id of User performing import. * - * @param mixed $user_id the user id + * @param mixed $created_by the user id * * @return self */ - public function setUserId($user_id) + public function setUserId($created_by) { - $this->user_id = $user_id; + $this->created_by = $created_by; return $this; } diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 29197ca5dc..360618f4f0 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -94,7 +94,7 @@ class ItemImporter extends Importer $this->item['qty'] = $this->findCsvMatch($row, 'quantity'); $this->item['requestable'] = $this->findCsvMatch($row, 'requestable'); - $this->item['user_id'] = $this->user_id; + $this->item['created_by'] = $this->created_by; $this->item['serial'] = $this->findCsvMatch($row, 'serial'); // NO need to call this method if we're running the user import. // TODO: Merge these methods. @@ -301,7 +301,7 @@ class ItemImporter extends Importer $category = new Category(); $category->name = $asset_category; $category->category_type = $item_type; - $category->user_id = $this->user_id; + $category->created_by = $this->created_by; if ($category->save()) { $this->log('Category '.$asset_category.' was created'); @@ -425,7 +425,7 @@ class ItemImporter extends Importer //Otherwise create a manufacturer. $manufacturer = new Manufacturer(); $manufacturer->name = trim($item_manufacturer); - $manufacturer->user_id = $this->user_id; + $manufacturer->created_by = $this->created_by; if ($manufacturer->save()) { $this->log('Manufacturer '.$manufacturer->name.' was created'); @@ -466,7 +466,7 @@ class ItemImporter extends Importer $location->city = ''; $location->state = ''; $location->country = ''; - $location->user_id = $this->user_id; + $location->created_by = $this->created_by; if ($location->save()) { $this->log('Location '.$asset_location.' was created'); @@ -502,7 +502,7 @@ class ItemImporter extends Importer $supplier = new Supplier(); $supplier->name = $item_supplier; - $supplier->user_id = $this->user_id; + $supplier->created_by = $this->created_by; if ($supplier->save()) { $this->log('Supplier '.$item_supplier.' was created'); diff --git a/app/Importer/LicenseImporter.php b/app/Importer/LicenseImporter.php index b7c55cdba6..3f7bb9f85c 100644 --- a/app/Importer/LicenseImporter.php +++ b/app/Importer/LicenseImporter.php @@ -103,13 +103,13 @@ class LicenseImporter extends ItemImporter if ($checkout_target) { $targetLicense->assigned_to = $checkout_target->id; - $targetLicense->user_id = Auth::id(); + $targetLicense->created_by = auth()->id(); if ($asset) { $targetLicense->asset_id = $asset->id; } $targetLicense->save(); } elseif ($asset) { - $targetLicense->user_id = Auth::id(); + $targetLicense->created_by = auth()->id(); $targetLicense->asset_id = $asset->id; $targetLicense->save(); } diff --git a/app/Importer/LocationImporter.php b/app/Importer/LocationImporter.php index e344b6beaf..b3ef59d248 100644 --- a/app/Importer/LocationImporter.php +++ b/app/Importer/LocationImporter.php @@ -65,7 +65,7 @@ class LocationImporter extends ItemImporter $this->item['ldap_ou'] = trim($this->findCsvMatch($row, 'ldap_ou')); $this->item['manager'] = trim($this->findCsvMatch($row, 'manager')); $this->item['manager_username'] = trim($this->findCsvMatch($row, 'manager_username')); - $this->item['user_id'] = auth()->id(); + $this->item['created_by'] = auth()->id(); if ($this->findCsvMatch($row, 'parent_location')) { $this->item['parent_id'] = $this->createOrFetchLocation(trim($this->findCsvMatch($row, 'parent_location'))); diff --git a/app/Importer/UserImporter.php b/app/Importer/UserImporter.php index 4a8d76b68e..036bf15c9a 100644 --- a/app/Importer/UserImporter.php +++ b/app/Importer/UserImporter.php @@ -165,7 +165,7 @@ class UserImporter extends ItemImporter $department = new department(); $department->name = $department_name; - $department->user_id = $this->user_id; + $department->created_by = $this->created_by; if ($department->save()) { $this->log('department ' . $department_name . ' was created'); diff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.php index b44fcdfcb4..6dbeb7312c 100644 --- a/app/Listeners/LogListener.php +++ b/app/Listeners/LogListener.php @@ -111,7 +111,7 @@ class LogListener $logaction->target_type = User::class; $logaction->action_type = 'merged'; $logaction->note = trans('general.merged_log_this_user_from', $to_from_array); - $logaction->user_id = $event->admin->id ?? null; + $logaction->created_by = $event->admin->id ?? null; $logaction->save(); // Add a record to the users being merged TO @@ -122,7 +122,7 @@ class LogListener $logaction->item_type = User::class; $logaction->action_type = 'merged'; $logaction->note = trans('general.merged_log_this_user_into', $to_from_array); - $logaction->user_id = $event->admin->id ?? null; + $logaction->created_by = $event->admin->id ?? null; $logaction->save(); diff --git a/app/Livewire/OauthClients.php b/app/Livewire/OauthClients.php index fda91260c8..017e789060 100644 --- a/app/Livewire/OauthClients.php +++ b/app/Livewire/OauthClients.php @@ -47,10 +47,10 @@ class OauthClients extends Component { // test for safety // ->delete must be of type Client - thus the model binding - if ($clientId->user_id == auth()->id()) { + if ($clientId->created_by == auth()->id()) { app(ClientRepository::class)->delete($clientId); } else { - Log::warning('User ' . auth()->id() . ' attempted to delete client ' . $clientId->id . ' which belongs to user ' . $clientId->user_id); + Log::warning('User ' . auth()->id() . ' attempted to delete client ' . $clientId->id . ' which belongs to user ' . $clientId->created_by); $this->authorizationError = 'You are not authorized to delete this client.'; } } @@ -58,10 +58,10 @@ class OauthClients extends Component public function deleteToken($tokenId): void { $token = app(TokenRepository::class)->find($tokenId); - if ($token->user_id == auth()->id()) { + if ($token->created_by == auth()->id()) { app(TokenRepository::class)->revokeAccessToken($tokenId); } else { - Log::warning('User ' . auth()->id() . ' attempted to delete token ' . $tokenId . ' which belongs to user ' . $token->user_id); + Log::warning('User ' . auth()->id() . ' attempted to delete token ' . $tokenId . ' which belongs to user ' . $token->created_by); $this->authorizationError = 'You are not authorized to delete this token.'; } } @@ -84,12 +84,12 @@ class OauthClients extends Component ]); $client = app(ClientRepository::class)->find($editClientId->id); - if ($client->user_id == auth()->id()) { + if ($client->created_by == auth()->id()) { $client->name = $this->editName; $client->redirect = $this->editRedirect; $client->save(); } else { - Log::warning('User ' . auth()->id() . ' attempted to edit client ' . $editClientId->id . ' which belongs to user ' . $client->user_id); + Log::warning('User ' . auth()->id() . ' attempted to edit client ' . $editClientId->id . ' which belongs to user ' . $client->created_by); $this->authorizationError = 'You are not authorized to edit this client.'; } diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index c1366f67e6..3fc4c5c9c6 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -259,6 +259,18 @@ class Accessory extends SnipeModel ->with('assignedTo'); } + /** + * Establishes the accessory -> admin user relationship + * + * @author A. Gianotto + * @since [v7.0.13] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + /** * Checks whether or not the accessory has users * @@ -410,6 +422,16 @@ class Accessory extends SnipeModel * ----------------------------------------------- **/ + + /** + * Query builder scope to order on created_by name + * + */ + public function scopeOrderByCreatedByName($query, $order) + { + return $query->leftJoin('users as admin_sort', 'accessories.created_by', '=', 'admin_sort.id')->select('accessories.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } + /** * Query builder scope to order on company * diff --git a/app/Models/AccessoryCheckout.php b/app/Models/AccessoryCheckout.php index 7f42b354e1..bdfbf11d9d 100755 --- a/app/Models/AccessoryCheckout.php +++ b/app/Models/AccessoryCheckout.php @@ -22,7 +22,7 @@ class AccessoryCheckout extends Model { use Searchable; - protected $fillable = ['user_id', 'accessory_id', 'assigned_to', 'assigned_type', 'note']; + protected $fillable = ['created_by', 'accessory_id', 'assigned_to', 'assigned_type', 'note']; protected $table = 'accessories_checkout'; /** diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 7f3b46e46c..0831352b87 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -21,7 +21,7 @@ class Actionlog extends SnipeModel // This is to manually set the source (via setActionSource()) for determineActionSource() protected ?string $source = null; - protected $with = ['admin']; + protected $with = ['adminuser']; protected $presenter = \App\Presenters\ActionlogPresenter::class; use SoftDeletes; @@ -32,7 +32,7 @@ class Actionlog extends SnipeModel protected $fillable = [ 'created_at', 'item_type', - 'user_id', + 'created_by', 'item_id', 'action_type', 'note', @@ -52,7 +52,7 @@ class Actionlog extends SnipeModel 'action_type', 'note', 'log_meta', - 'user_id', + 'created_by', 'remote_ip', 'user_agent', 'action_source' @@ -65,7 +65,7 @@ class Actionlog extends SnipeModel */ protected $searchableRelations = [ 'company' => ['name'], - 'admin' => ['first_name','last_name','username', 'email'], + 'adminuser' => ['first_name','last_name','username', 'email'], 'user' => ['first_name','last_name','username', 'email'], 'assets' => ['asset_tag','name'], ]; @@ -198,9 +198,9 @@ class Actionlog extends SnipeModel * @since [v3.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - public function admin() + public function adminuser() { - return $this->belongsTo(User::class, 'user_id') + return $this->belongsTo(User::class, 'created_by') ->withTrashed(); } @@ -374,8 +374,8 @@ class Actionlog extends SnipeModel $this->source = $source; } - public function scopeOrderAdmin($query, $order) + public function scopeOrderByCreatedBy($query, $order) { - return $query->leftJoin('users as admin_sort', 'action_logs.user_id', '=', 'admin_sort.id')->select('action_logs.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + return $query->leftJoin('users as admin_sort', 'action_logs.created_by', '=', 'admin_sort.id')->select('action_logs.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); } } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index aff06b6689..bd0578fc2e 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -30,7 +30,7 @@ class Asset extends Depreciable { protected $presenter = AssetPresenter::class; - protected $with = ['model', 'admin']; + protected $with = ['model', 'adminuser']; use CompanyableTrait; use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait; @@ -108,7 +108,6 @@ class Asset extends Depreciable 'expected_checkin' => ['nullable', 'date'], 'last_audit_date' => ['nullable', 'date_format:Y-m-d H:i:s'], 'next_audit_date' => ['nullable', 'date'], - //'after:last_audit_date'], 'location_id' => ['nullable', 'exists:locations,id'], 'rtd_location_id' => ['nullable', 'exists:locations,id'], 'purchase_date' => ['nullable', 'date', 'date_format:Y-m-d'], @@ -710,15 +709,15 @@ class Asset extends Depreciable } /** - * Get action logs history for this asset + * Get user who created the item * * @author [A. Gianotto] [] * @since [v1.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - public function admin() + public function adminuser() { - return $this->belongsTo(\App\Models\User::class, 'user_id'); + return $this->belongsTo(\App\Models\User::class, 'created_by'); } @@ -931,9 +930,20 @@ class Asset extends Depreciable * */ public function checkInvalidNextAuditDate() { - if (($this->last_audit_date) && ($this->next_audit_date) && ($this->last_audit_date > $this->next_audit_date)) { + + // Deliberately parse the dates as Y-m-d (without H:i:s) to compare them + if ($this->last_audit_date) { + $last = Carbon::parse($this->last_audit_date)->format('Y-m-d'); + } + + if ($this->next_audit_date) { + $next = Carbon::parse($this->next_audit_date)->format('Y-m-d'); + } + + if ((isset($last) && (isset($next))) && ($last > $next)) { return true; } + return false; } @@ -1761,6 +1771,20 @@ class Asset extends Depreciable } + /** + * Query builder scope to order on created_by name + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderByCreatedByName($query, $order) + { + return $query->leftJoin('users as admin_sort', 'assets.created_by', '=', 'admin_sort.id')->select('assets.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } + + /** * Query builder scope to order on assigned user * diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php index 5f66783cbb..f629b03dfb 100644 --- a/app/Models/AssetMaintenance.php +++ b/app/Models/AssetMaintenance.php @@ -174,7 +174,7 @@ class AssetMaintenance extends Model implements ICompanyableChild * @author A. Gianotto * @version v3.0 */ - public function admin() + public function adminuser() { return $this->belongsTo(\App\Models\User::class, 'user_id') ->withTrashed(); @@ -207,20 +207,6 @@ class AssetMaintenance extends Model implements ICompanyableChild } - /** - * Query builder scope to order on admin user - * - * @param \Illuminate\Database\Query\Builder $query Query builder instance - * @param string $order Order - * - * @return \Illuminate\Database\Query\Builder Modified query builder - */ - public function scopeOrderAdmin($query, $order) - { - return $query->leftJoin('users', 'asset_maintenances.user_id', '=', 'users.id') - ->orderBy('users.first_name', $order) - ->orderBy('users.last_name', $order); - } /** * Query builder scope to order on asset tag @@ -278,4 +264,12 @@ class AssetMaintenance extends Model implements ICompanyableChild ->leftjoin('status_labels as maintained_asset_status', 'maintained_asset_status.id', '=', 'maintained_asset.status_id') ->orderBy('maintained_asset_status.name', $order); } + + /** + * Query builder scope to order on the user that created it + */ + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'asset_maintenances.created_by', '=', 'admin_sort.id')->select('asset_maintenances.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index e9b859e128..0c8f8e7b3c 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -36,7 +36,6 @@ class AssetModel extends SnipeModel protected $injectUniqueIdentifier = true; use ValidatingTrait; protected $table = 'models'; - protected $hidden = ['user_id', 'deleted_at']; protected $presenter = AssetModelPresenter::class; // Declare the rules for the model validation @@ -69,7 +68,6 @@ class AssetModel extends SnipeModel 'model_number', 'name', 'notes', - 'user_id', ]; use Searchable; @@ -226,6 +224,18 @@ class AssetModel extends SnipeModel ->orderBy('created_at', 'desc'); } + /** + * Get user who created the item + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + /** * ----------------------------------------------- diff --git a/app/Models/Category.php b/app/Models/Category.php index f21038bab0..5965404f59 100755 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -29,17 +29,17 @@ class Category extends SnipeModel use SoftDeletes; protected $table = 'categories'; - protected $hidden = ['user_id', 'deleted_at']; + protected $hidden = ['created_by', 'deleted_at']; protected $casts = [ - 'user_id' => 'integer', + 'created_by' => 'integer', ]; /** * Category validation rules */ public $rules = [ - 'user_id' => 'numeric|nullable', + 'created_by' => 'numeric|nullable', 'name' => 'required|min:1|max:255|two_column_unique_undeleted:category_type', 'require_acceptance' => 'boolean', 'use_default_eula' => 'boolean', @@ -70,7 +70,7 @@ class Category extends SnipeModel 'name', 'require_acceptance', 'use_default_eula', - 'user_id', + 'created_by', ]; use Searchable; @@ -228,6 +228,11 @@ class Category extends SnipeModel return $this->hasMany(\App\Models\AssetModel::class, 'category_id'); } + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + /** * Checks for a category-specific EULA, and if that doesn't exist, * checks for a settings level EULA @@ -286,4 +291,9 @@ class Category extends SnipeModel { return $query->where('require_acceptance', '=', true); } + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'categories.created_by', '=', 'admin_sort.id')->select('categories.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/CheckoutRequest.php b/app/Models/CheckoutRequest.php index b717a332aa..d6a85f2972 100644 --- a/app/Models/CheckoutRequest.php +++ b/app/Models/CheckoutRequest.php @@ -13,7 +13,7 @@ class CheckoutRequest extends Model public function user() { - return $this->belongsTo(User::class); + return $this->belongsTo(User::class, 'user_id', 'id'); } public function requestingUser() diff --git a/app/Models/Company.php b/app/Models/Company.php index 657b34390b..171d559542 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -67,6 +67,7 @@ final class Company extends SnipeModel 'phone', 'fax', 'email', + 'created_by' ]; private static function isFullMultipleCompanySupportEnabled() @@ -186,12 +187,15 @@ final class Company extends SnipeModel */ public function isDeletable() { + return Gate::allows('delete', $this) - && ($this->assets()->count() === 0) - && ($this->accessories()->count() === 0) - && ($this->consumables()->count() === 0) - && ($this->components()->count() === 0) - && ($this->users()->count() === 0); + && (($this->assets_count ?? $this->assets()->count()) === 0) + && (($this->accessories_count ?? $this->accessories()->count()) === 0) + && (($this->licenses_count ?? $this->licenses()->count()) === 0) + && (($this->components_count ?? $this->components()->count()) === 0) + && (($this->consumables_count ?? $this->consumables()->count()) === 0) + && (($this->accessories_count ?? $this->accessories()->count()) === 0) + && (($this->users_count ?? $this->users()->count()) === 0); } /** @@ -294,6 +298,12 @@ final class Company extends SnipeModel } + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + + /** * I legit do not know what this method does, but we can't remove it (yet). * @@ -329,4 +339,13 @@ final class Company extends SnipeModel } } + + /** + * Query builder scope to order on the user that created it + */ + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'companies.created_by', '=', 'admin_sort.id')->select('companies.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } + } diff --git a/app/Models/Component.php b/app/Models/Component.php index 536e06d0af..7bba37ac12 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -130,7 +130,7 @@ class Component extends SnipeModel */ public function assets() { - return $this->belongsToMany(\App\Models\Asset::class, 'components_assets')->withPivot('id', 'assigned_qty', 'created_at', 'user_id', 'note'); + return $this->belongsToMany(\App\Models\Asset::class, 'components_assets')->withPivot('id', 'assigned_qty', 'created_at', 'created_by', 'note'); } /** @@ -142,9 +142,9 @@ class Component extends SnipeModel * @since [v3.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - public function admin() + public function adminuser() { - return $this->belongsTo(\App\Models\User::class, 'user_id'); + return $this->belongsTo(\App\Models\User::class, 'created_by'); } /** @@ -310,4 +310,9 @@ class Component extends SnipeModel { return $query->leftJoin('suppliers', 'components.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order); } + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'components.created_by', '=', 'admin_sort.id')->select('components.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 3b33035b1e..eb0acc8016 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -154,9 +154,9 @@ class Consumable extends SnipeModel * @since [v3.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - public function admin() + public function adminuser() { - return $this->belongsTo(User::class, 'user_id'); + return $this->belongsTo(User::class, 'created_by'); } /** @@ -256,7 +256,7 @@ class Consumable extends SnipeModel */ public function users() : Relation { - return $this->belongsToMany(User::class, 'consumables_users', 'consumable_id', 'assigned_to')->withPivot('user_id')->withTrashed()->withTimestamps(); + return $this->belongsToMany(User::class, 'consumables_users', 'consumable_id', 'assigned_to')->withPivot('created_by')->withTrashed()->withTimestamps(); } /** @@ -451,4 +451,9 @@ class Consumable extends SnipeModel { return $query->leftJoin('suppliers', 'consumables.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order); } + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as users_sort', 'consumables.created_by', '=', 'users_sort.id')->select('consumables.*')->orderBy('users_sort.first_name', $order)->orderBy('users_sort.last_name', $order); + } } diff --git a/app/Models/ConsumableAssignment.php b/app/Models/ConsumableAssignment.php index db0cfa4bd6..4c9a19703e 100644 --- a/app/Models/ConsumableAssignment.php +++ b/app/Models/ConsumableAssignment.php @@ -26,8 +26,8 @@ class ConsumableAssignment extends Model return $this->belongsTo(\App\Models\User::class, 'assigned_to'); } - public function admin() + public function adminuser() { - return $this->belongsTo(\App\Models\User::class, 'user_id'); + return $this->belongsTo(\App\Models\User::class, 'created_by'); } } diff --git a/app/Models/Department.php b/app/Models/Department.php index 62755d2aa0..855cb25f64 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -42,7 +42,7 @@ class Department extends SnipeModel * @var array */ protected $fillable = [ - 'user_id', + 'created_by', 'name', 'phone', 'fax', diff --git a/app/Models/Depreciation.php b/app/Models/Depreciation.php index 7aceddf7c4..11ee82c16a 100755 --- a/app/Models/Depreciation.php +++ b/app/Models/Depreciation.php @@ -88,4 +88,27 @@ class Depreciation extends SnipeModel return $this->hasManyThrough(\App\Models\Asset::class, \App\Models\AssetModel::class, 'depreciation_id', 'model_id'); } + /** + * Get the user that created the depreciation + * + * @author A. Gianotto + * @since [v7.0.13] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + + + /** + * ----------------------------------------------- + * BEGIN QUERY SCOPES + * ----------------------------------------------- + **/ + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'depreciations.created_by', '=', 'admin_sort.id')->select('depreciations.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/Group.php b/app/Models/Group.php index c6e6e56039..7278152df9 100755 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -65,7 +65,7 @@ class Group extends SnipeModel * @since [v6.3.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - public function admin() + public function adminuser() { return $this->belongsTo(\App\Models\User::class, 'created_by'); } @@ -81,4 +81,16 @@ class Group extends SnipeModel { return json_decode($this->permissions, true); } + + /** + * ----------------------------------------------- + * BEGIN QUERY SCOPES + * ----------------------------------------------- + **/ + + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'permission_groups.created_by', '=', 'admin_sort.id')->select('permission_groups.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/License.php b/app/Models/License.php index 554929c0ac..4923072f07 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -81,8 +81,7 @@ class License extends Depreciable 'serial', 'supplier_id', 'termination_date', - 'free_seat_count', - 'user_id', + 'created_by', 'min_amt', ]; @@ -184,7 +183,7 @@ class License extends Depreciable $logAction = new Actionlog; $logAction->item_type = self::class; $logAction->item_id = $license->id; - $logAction->user_id = Auth::id() ?: 1; // We don't have an id while running the importer from CLI. + $logAction->created_by = auth()->id() ?: 1; // We don't have an id while running the importer from CLI. $logAction->note = "deleted ${change} seats"; $logAction->target_id = null; $logAction->logaction('delete seats'); @@ -196,7 +195,7 @@ class License extends Depreciable $licenseInsert = []; for ($i = $oldSeats; $i < $newSeats; $i++) { $licenseInsert[] = [ - 'user_id' => Auth::id(), + 'created_by' => auth()->id(), 'license_id' => $license->id, 'created_at' => now(), 'updated_at' => now() @@ -216,7 +215,7 @@ class License extends Depreciable $logAction = new Actionlog(); $logAction->item_type = self::class; $logAction->item_id = $license->id; - $logAction->user_id = Auth::id() ?: 1; // Importer. + $logAction->created_by = auth()->id() ?: 1; // Importer. $logAction->note = "added ${change} seats"; $logAction->target_id = null; $logAction->logaction('add seats'); @@ -434,7 +433,7 @@ class License extends Depreciable */ public function adminuser() { - return $this->belongsTo(\App\Models\User::class, 'user_id'); + return $this->belongsTo(\App\Models\User::class, 'created_by'); } /** @@ -739,14 +738,9 @@ class License extends Depreciable /** * Query builder scope to order on the user that created it - * - * @param \Illuminate\Database\Query\Builder $query Query builder instance - * @param text $order Order - * - * @return \Illuminate\Database\Query\Builder Modified query builder */ - public function scopeOrderCreatedBy($query, $order) + public function scopeOrderByCreatedBy($query, $order) { - return $query->leftJoin('users as users_sort', 'licenses.user_id', '=', 'users_sort.id')->select('licenses.*')->orderBy('users_sort.first_name', $order)->orderBy('users_sort.last_name', $order); + return $query->leftJoin('users as admin_sort', 'licenses.created_by', '=', 'admin_sort.id')->select('licenses.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); } } \ No newline at end of file diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index a246503165..72a7a7f262 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -37,7 +37,7 @@ trait Loggable $log = new Actionlog; $log = $this->determineLogItemType($log); if (auth()->user()) { - $log->user_id = auth()->id(); + $log->created_by = auth()->id(); } if (! isset($target)) { @@ -148,7 +148,7 @@ trait Loggable } if (auth()->user()) { - $log->user_id = auth()->id(); + $log->created_by = auth()->id(); } $changed = []; @@ -191,14 +191,14 @@ trait Loggable } $log->location_id = ($location_id) ? $location_id : null; $log->note = $note; - $log->user_id = auth()->id(); + $log->created_by = auth()->id(); $log->filename = $filename; $log->logaction('audit'); $params = [ 'item' => $log->item, 'filename' => $log->filename, - 'admin' => $log->admin, + 'admin' => $log->adminuser, 'location' => ($location) ? $location->name : '', 'note' => $note, ]; @@ -214,9 +214,9 @@ trait Loggable */ public function logCreate($note = null) { - $user_id = -1; + $created_by = -1; if (auth()->user()) { - $user_id = auth()->id(); + $created_by = auth()->id(); } $log = new Actionlog; if (static::class == LicenseSeat::class) { @@ -228,7 +228,7 @@ trait Loggable } $log->location_id = null; $log->note = $note; - $log->user_id = $user_id; + $log->created_by = $created_by; $log->logaction('create'); $log->save(); @@ -250,7 +250,7 @@ trait Loggable $log->item_type = static::class; $log->item_id = $this->id; } - $log->user_id = auth()->id(); + $log->created_by = auth()->id(); $log->note = $note; $log->target_id = null; $log->created_at = date('Y-m-d H:i:s'); diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index 85907f7ddb..6e72b3a2bb 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -74,10 +74,10 @@ class Manufacturer extends SnipeModel public function isDeletable() { return Gate::allows('delete', $this) - && ($this->assets()->count() === 0) - && ($this->licenses()->count() === 0) - && ($this->consumables()->count() === 0) - && ($this->accessories()->count() === 0) + && (($this->assets_count ?? $this->assets()->count()) === 0) + && (($this->licenses_count ?? $this->licenses()->count()) === 0) + && (($this->consumables_count ?? $this->consumables()->count()) === 0) + && (($this->accessories_count ?? $this->accessories()->count()) === 0) && ($this->deleted_at == ''); } @@ -105,4 +105,19 @@ class Manufacturer extends SnipeModel { return $this->hasMany(\App\Models\Consumable::class, 'manufacturer_id'); } + + + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + + + /** + * Query builder scope to order on the user that created it + */ + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'manufacturers.created_by', '=', 'admin_sort.id')->select('manufacturers.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/PredefinedKit.php b/app/Models/PredefinedKit.php index f9464e12c7..36790a1fc7 100644 --- a/app/Models/PredefinedKit.php +++ b/app/Models/PredefinedKit.php @@ -135,6 +135,13 @@ class PredefinedKit extends SnipeModel */ protected $searchableRelations = []; + + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + + /** * Establishes the kits -> models relationship * @return \Illuminate\Database\Eloquent\Relations\Relation @@ -181,4 +188,9 @@ class PredefinedKit extends SnipeModel * BEGIN QUERY SCOPES * ----------------------------------------------- **/ + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'kits.created_by', '=', 'admin_sort.id')->select('kits.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Models/Requestable.php b/app/Models/Requestable.php index bf5c9c427b..4dead82bb3 100644 --- a/app/Models/Requestable.php +++ b/app/Models/Requestable.php @@ -29,19 +29,19 @@ trait Requestable public function request($qty = 1) { $this->requests()->save( - new CheckoutRequest(['user_id' => Auth::id(), 'qty' => $qty]) + new CheckoutRequest(['user_id' => auth()->id(), 'qty' => $qty]) ); } public function deleteRequest() { - $this->requests()->where('user_id', Auth::id())->delete(); + $this->requests()->where('user_id', auth()->id())->delete(); } public function cancelRequest($user_id = null) { if (!$user_id){ - $user_id = Auth::id(); + $user_id = auth()->id(); } $this->requests()->where('user_id', $user_id)->update(['canceled_at' => \Carbon\Carbon::now()]); diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php index 0f8a0b6075..c1bcc3042d 100755 --- a/app/Models/Statuslabel.php +++ b/app/Models/Statuslabel.php @@ -64,6 +64,11 @@ class Statuslabel extends SnipeModel return $this->hasMany(\App\Models\Asset::class, 'status_id'); } + public function adminuser() + { + return $this->belongsTo(\App\Models\User::class, 'created_by'); + } + /** * Gets the status label type * @@ -161,4 +166,9 @@ class Statuslabel extends SnipeModel return $statustype; } + + public function scopeOrderByCreatedBy($query, $order) + { + return $query->leftJoin('users as admin_sort', 'status_labels.created_by', '=', 'admin_sort.id')->select('status_labels.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } } diff --git a/app/Observers/AccessoryObserver.php b/app/Observers/AccessoryObserver.php index 661d00b4c2..0f8b2492cd 100644 --- a/app/Observers/AccessoryObserver.php +++ b/app/Observers/AccessoryObserver.php @@ -20,7 +20,7 @@ class AccessoryObserver $logAction->item_type = Accessory::class; $logAction->item_id = $accessory->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('update'); } @@ -37,7 +37,7 @@ class AccessoryObserver $logAction->item_type = Accessory::class; $logAction->item_id = $accessory->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); if($accessory->imported) { $logAction->setActionSource('importer'); } @@ -56,7 +56,7 @@ class AccessoryObserver $logAction->item_type = Accessory::class; $logAction->item_id = $accessory->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('delete'); } } diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index f77c4cc00f..0d01428ea8 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -62,7 +62,7 @@ class AssetObserver $logAction->item_type = Asset::class; $logAction->item_id = $asset->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->log_meta = json_encode($changed); $logAction->logaction('update'); } @@ -108,7 +108,7 @@ class AssetObserver $logAction->item_type = Asset::class; // can we instead say $logAction->item = $asset ? $logAction->item_id = $asset->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); if($asset->imported) { $logAction->setActionSource('importer'); } @@ -127,7 +127,7 @@ class AssetObserver $logAction->item_type = Asset::class; $logAction->item_id = $asset->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('delete'); } @@ -143,7 +143,7 @@ class AssetObserver $logAction->item_type = Asset::class; $logAction->item_id = $asset->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('restore'); } diff --git a/app/Observers/ComponentObserver.php b/app/Observers/ComponentObserver.php index 44bf819353..cd2c58c367 100644 --- a/app/Observers/ComponentObserver.php +++ b/app/Observers/ComponentObserver.php @@ -20,7 +20,7 @@ class ComponentObserver $logAction->item_type = Component::class; $logAction->item_id = $component->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('update'); } @@ -37,7 +37,7 @@ class ComponentObserver $logAction->item_type = Component::class; $logAction->item_id = $component->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); if($component->imported) { $logAction->setActionSource('importer'); } @@ -56,7 +56,7 @@ class ComponentObserver $logAction->item_type = Component::class; $logAction->item_id = $component->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('delete'); } } diff --git a/app/Observers/ConsumableObserver.php b/app/Observers/ConsumableObserver.php index 377995ebb9..57471cee9c 100644 --- a/app/Observers/ConsumableObserver.php +++ b/app/Observers/ConsumableObserver.php @@ -34,7 +34,7 @@ class ConsumableObserver $logAction->item_type = Consumable::class; $logAction->item_id = $consumable->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->log_meta = json_encode($changed); $logAction->logaction('update'); } @@ -53,7 +53,7 @@ class ConsumableObserver $logAction->item_type = Consumable::class; $logAction->item_id = $consumable->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); if($consumable->imported) { $logAction->setActionSource('importer'); } @@ -98,7 +98,7 @@ class ConsumableObserver $logAction->item_type = Consumable::class; $logAction->item_id = $consumable->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('delete'); } } diff --git a/app/Observers/LicenseObserver.php b/app/Observers/LicenseObserver.php index de4863fafa..4e355bf639 100644 --- a/app/Observers/LicenseObserver.php +++ b/app/Observers/LicenseObserver.php @@ -20,7 +20,7 @@ class LicenseObserver $logAction->item_type = License::class; $logAction->item_id = $license->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('update'); } @@ -37,7 +37,7 @@ class LicenseObserver $logAction->item_type = License::class; $logAction->item_id = $license->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); if($license->imported) { $logAction->setActionSource('importer'); } @@ -56,7 +56,7 @@ class LicenseObserver $logAction->item_type = License::class; $logAction->item_id = $license->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('delete'); } } diff --git a/app/Observers/UserObserver.php b/app/Observers/UserObserver.php index c7c2a460cb..acde9ceaed 100644 --- a/app/Observers/UserObserver.php +++ b/app/Observers/UserObserver.php @@ -83,7 +83,7 @@ class UserObserver $logAction->target_type = User::class; // can we instead say $logAction->item = $asset ? $logAction->target_id = $user->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->log_meta = json_encode($changed); $logAction->logaction('update'); } @@ -105,7 +105,7 @@ class UserObserver $logAction->item_type = User::class; // can we instead say $logAction->item = $asset ? $logAction->item_id = $user->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('create'); } @@ -123,7 +123,7 @@ class UserObserver $logAction->target_type = User::class; // can we instead say $logAction->item = $asset ? $logAction->target_id = $user->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('delete'); } @@ -141,7 +141,7 @@ class UserObserver $logAction->target_type = User::class; // can we instead say $logAction->item = $asset ? $logAction->target_id = $user->id; $logAction->created_at = date('Y-m-d H:i:s'); - $logAction->user_id = Auth::id(); + $logAction->created_by = auth()->id(); $logAction->logaction('restore'); } diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php index 4ff3c699c7..04f55cf364 100644 --- a/app/Presenters/AccessoryPresenter.php +++ b/app/Presenters/AccessoryPresenter.php @@ -127,6 +127,29 @@ class AccessoryPresenter extends Presenter 'visible' => false, 'title' => trans('general.notes'), 'formatter' => 'notesFormatter' + ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ + 'field' => 'created_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.created_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'change', 'searchable' => false, diff --git a/app/Presenters/ActionlogPresenter.php b/app/Presenters/ActionlogPresenter.php index ebbe3d7823..37a1adbc28 100644 --- a/app/Presenters/ActionlogPresenter.php +++ b/app/Presenters/ActionlogPresenter.php @@ -7,7 +7,7 @@ namespace App\Presenters; */ class ActionlogPresenter extends Presenter { - public function admin() + public function adminuser() { if ($user = $this->model->user) { if (empty($user->deleted_at)) { diff --git a/app/Presenters/AssetMaintenancesPresenter.php b/app/Presenters/AssetMaintenancesPresenter.php index 3908720dc3..6a315ad8e0 100644 --- a/app/Presenters/AssetMaintenancesPresenter.php +++ b/app/Presenters/AssetMaintenancesPresenter.php @@ -123,6 +123,29 @@ class AssetMaintenancesPresenter extends Presenter 'title' => trans('general.admin'), 'formatter' => 'usersLinkObjFormatter', ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ + 'field' => 'created_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.created_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ],[ 'field' => 'actions', 'searchable' => false, 'sortable' => false, diff --git a/app/Presenters/AssetModelPresenter.php b/app/Presenters/AssetModelPresenter.php index da93092b91..324cc7d096 100644 --- a/app/Presenters/AssetModelPresenter.php +++ b/app/Presenters/AssetModelPresenter.php @@ -135,19 +135,27 @@ class AssetModelPresenter extends Presenter 'formatter' => 'notesFormatter', ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ 'field' => 'created_at', 'searchable' => true, 'sortable' => true, - 'visible' => false, + 'switchable' => true, 'title' => trans('general.created_at'), + 'visible' => false, 'formatter' => 'dateDisplayFormatter', - ], - [ + ], [ 'field' => 'updated_at', 'searchable' => true, 'sortable' => true, - 'visible' => false, + 'switchable' => true, 'title' => trans('general.updated_at'), + 'visible' => false, 'formatter' => 'dateDisplayFormatter', ], diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index e55cb00c2e..19bd2985e7 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -233,18 +233,28 @@ class AssetPresenter extends Presenter 'title' => trans('general.user_requests_count'), ], [ - 'field' => 'created_at', + 'field' => 'created_by', 'searchable' => false, 'sortable' => true, + 'title' => trans('general.created_by'), 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], + [ + 'field' => 'created_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, 'title' => trans('general.created_at'), + 'visible' => false, 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'updated_at', - 'searchable' => false, + 'searchable' => true, 'sortable' => true, - 'visible' => false, + 'switchable' => true, 'title' => trans('general.updated_at'), + 'visible' => false, 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'last_checkout', diff --git a/app/Presenters/CategoryPresenter.php b/app/Presenters/CategoryPresenter.php index fbf431637c..f551c0ba1b 100644 --- a/app/Presenters/CategoryPresenter.php +++ b/app/Presenters/CategoryPresenter.php @@ -77,19 +77,28 @@ class CategoryPresenter extends Presenter "title" => trans('admin/categories/general.use_default_eula_column'), 'visible' => true, "formatter" => 'trueFalseFormatter', + ],[ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', ], [ 'field' => 'created_at', 'searchable' => true, 'sortable' => true, - 'visible' => false, + 'switchable' => true, 'title' => trans('general.created_at'), + 'visible' => false, 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'updated_at', 'searchable' => true, 'sortable' => true, - 'visible' => false, + 'switchable' => true, 'title' => trans('general.updated_at'), + 'visible' => false, 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'actions', diff --git a/app/Presenters/CompanyPresenter.php b/app/Presenters/CompanyPresenter.php index bcb77c7eba..6f9ece2141 100644 --- a/app/Presenters/CompanyPresenter.php +++ b/app/Presenters/CompanyPresenter.php @@ -105,20 +105,29 @@ class CompanyPresenter extends Presenter 'title' => trans('general.components'), 'visible' => true, 'class' => 'css-component', - ], [ - 'field' => 'updated_at', + ],[ + 'field' => 'created_by', 'searchable' => false, 'sortable' => true, + 'title' => trans('general.created_by'), 'visible' => false, - 'title' => trans('general.updated_at'), - 'formatter' => 'createdAtFormatter', + 'formatter' => 'usersLinkObjFormatter', ], [ 'field' => 'created_at', - 'searchable' => false, + 'searchable' => true, 'sortable' => true, - 'visible' => false, + 'switchable' => true, 'title' => trans('general.created_at'), - 'formatter' => 'createdAtFormatter', + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'actions', 'searchable' => false, diff --git a/app/Presenters/ComponentPresenter.php b/app/Presenters/ComponentPresenter.php index d142d7abc2..f32bb56d57 100644 --- a/app/Presenters/ComponentPresenter.php +++ b/app/Presenters/ComponentPresenter.php @@ -119,6 +119,27 @@ class ComponentPresenter extends Presenter 'visible' => false, 'title' => trans('general.notes'), 'formatter' => 'notesFormatter', + ],[ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ],[ + 'field' => 'created_at', + 'searchable' => false, + 'sortable' => true, + 'visible' => false, + 'title' => trans('general.created_at'), + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => false, + 'sortable' => true, + 'visible' => false, + 'title' => trans('general.updated_at'), + 'formatter' => 'dateDisplayFormatter', ], ]; diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.php index dc22c69e24..cab8bed8bb 100644 --- a/app/Presenters/ConsumablePresenter.php +++ b/app/Presenters/ConsumablePresenter.php @@ -131,6 +131,27 @@ class ConsumablePresenter extends Presenter 'visible' => false, 'title' => trans('general.notes'), 'formatter' => 'notesFormatter', + ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ],[ + 'field' => 'created_at', + 'searchable' => false, + 'sortable' => true, + 'visible' => false, + 'title' => trans('general.created_at'), + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => false, + 'sortable' => true, + 'visible' => false, + 'title' => trans('general.updated_at'), + 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'change', 'searchable' => false, diff --git a/app/Presenters/DepreciationPresenter.php b/app/Presenters/DepreciationPresenter.php index cfba531623..3f240fcc53 100644 --- a/app/Presenters/DepreciationPresenter.php +++ b/app/Presenters/DepreciationPresenter.php @@ -65,8 +65,30 @@ class DepreciationPresenter extends Presenter 'sortable' => true, 'title' => trans('general.licenses'), 'visible' => true, - ], - [ + ],[ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ + 'field' => 'created_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.created_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ 'field' => 'actions', 'searchable' => false, 'sortable' => false, diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php index 1545cabd30..4256c2c686 100644 --- a/app/Presenters/LicensePresenter.php +++ b/app/Presenters/LicensePresenter.php @@ -162,7 +162,7 @@ class LicensePresenter extends Presenter 'field' => 'created_by', 'searchable' => false, 'sortable' => true, - 'title' => trans('general.admin'), + 'title' => trans('general.created_by'), 'visible' => false, 'formatter' => 'usersLinkObjFormatter', ], [ diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.php index 07a22c9ea4..ea29974f34 100644 --- a/app/Presenters/ManufacturerPresenter.php +++ b/app/Presenters/ManufacturerPresenter.php @@ -126,6 +126,13 @@ class ManufacturerPresenter extends Presenter 'class' => 'css-accessory', ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ 'field' => 'created_at', 'searchable' => true, 'sortable' => true, @@ -133,9 +140,15 @@ class ManufacturerPresenter extends Presenter 'title' => trans('general.created_at'), 'visible' => false, 'formatter' => 'dateDisplayFormatter', - ], - - [ + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ 'field' => 'actions', 'searchable' => false, 'sortable' => false, diff --git a/app/Presenters/PredefinedKitPresenter.php b/app/Presenters/PredefinedKitPresenter.php index b234653adf..7ce7d8c23d 100644 --- a/app/Presenters/PredefinedKitPresenter.php +++ b/app/Presenters/PredefinedKitPresenter.php @@ -27,6 +27,29 @@ class PredefinedKitPresenter extends Presenter 'sortable' => true, 'title' => trans('general.name'), 'formatter' => 'kitsLinkFormatter', + ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ + 'field' => 'created_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.created_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', ], ]; diff --git a/app/Presenters/StatusLabelPresenter.php b/app/Presenters/StatusLabelPresenter.php new file mode 100644 index 0000000000..2e43400041 --- /dev/null +++ b/app/Presenters/StatusLabelPresenter.php @@ -0,0 +1,115 @@ + 'id', + 'searchable' => false, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.id'), + 'visible' => false, + ], [ + 'field' => 'name', + 'searchable' => true, + 'sortable' => true, + 'switchable' => false, + 'title' => trans('general.name'), + 'visible' => true, + 'formatter' => 'statuslabelsAssetLinkFormatter', + ],[ + 'field' => 'type', + 'searchable' => false, + 'sortable' => false, + 'switchable' => false, + 'title' => trans('admin/statuslabels/table.status_type'), + 'visible' => true, + 'formatter' => 'statusLabelTypeFormatter', + ], [ + 'field' => 'assets_count', + 'searchable' => false, + 'sortable' => true, + 'switchable' => false, + 'title' => trans('general.assets'), + 'visible' => true, + ], [ + 'field' => 'color', + 'searchable' => false, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('admin/statuslabels/table.color'), + 'visible' => true, + 'formatter' => 'colorSqFormatter', + ], [ + 'field' => 'show_in_nav', + 'searchable' => false, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('admin/statuslabels/table.show_in_nav'), + 'visible' => true, + 'formatter' => 'trueFalseFormatter', + ], [ + 'field' => 'default_label', + 'searchable' => false, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('admin/statuslabels/table.default_label'), + 'visible' => true, + 'formatter' => 'trueFalseFormatter', + ],[ + 'field' => 'notes', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.notes'), + 'visible' => false, + ], [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.created_by'), + 'visible' => false, + 'formatter' => 'usersLinkObjFormatter', + ], [ + 'field' => 'created_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.created_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'actions', + 'searchable' => false, + 'sortable' => false, + 'switchable' => false, + 'title' => trans('table.actions'), + 'formatter' => 'statuslabelsActionsFormatter', + ], + ]; + + return json_encode($layout); + } + + +} diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 12d833e60b..7ee05da0cb 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -361,6 +361,14 @@ class UserPresenter extends Presenter 'title' => trans('general.created_at'), 'visible' => false, 'formatter' => 'dateDisplayFormatter', + ], [ + 'field' => 'updated_at', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('general.updated_at'), + 'visible' => false, + 'formatter' => 'dateDisplayFormatter', ], [ 'field' => 'start_date', diff --git a/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php b/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php new file mode 100644 index 0000000000..c2c451b82b --- /dev/null +++ b/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php @@ -0,0 +1,51 @@ + + */ + protected $data = []; + + + /** + * Set the data under validation. + * + * @param array $data + */ + public function setData(array $data): static + { + $this->data = $data; + return $this; + } + + /** + * Run the validation rule. + * + * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail + */ + public function validate(string $attribute, mixed $value, Closure $fail): void + { + // Check to see if any of the assign-ish fields are set + if ((isset($this->data['assigned_to'])) || (isset($this->data['assigned_user'])) || (isset($this->data['assigned_location'])) || (isset($this->data['assigned_asset'])) || (isset($this->data['assigned_type']))) { + + if (($value) && ($label = Statuslabel::find($value)) && ($label->getStatuslabelType()!='deployable')) { + $fail(trans('admin/hardware/form.asset_not_deployable')); + } + + } + + + } +} diff --git a/app/Services/PredefinedKitCheckoutService.php b/app/Services/PredefinedKitCheckoutService.php index d683875395..2cf4593687 100644 --- a/app/Services/PredefinedKitCheckoutService.php +++ b/app/Services/PredefinedKitCheckoutService.php @@ -157,7 +157,7 @@ class PredefinedKitCheckoutService } // licenses foreach ($license_seats_to_add as $licenseSeat) { - $licenseSeat->user_id = $admin->id; + $licenseSeat->created_by = $admin->id; $licenseSeat->assigned_to = $user->id; if ($licenseSeat->save()) { event(new CheckoutableCheckedOut($licenseSeat, $user, $admin, $note)); diff --git a/config/version.php b/config/version.php index d303fcc808..a4396196c5 100644 --- a/config/version.php +++ b/config/version.php @@ -1,10 +1,10 @@ 'v7.0.12', - 'full_app_version' => 'v7.0.12 - build 15249-g713bb104e', - 'build_version' => '15249', + 'app_version' => 'v7.0.13-pre', + 'full_app_version' => 'v7.0.13-pre - build 15360-g4ab478bb9', + 'build_version' => '15360', 'prerelease_version' => '', - 'hash_version' => 'g713bb104e', - 'full_hash' => 'v7.0.12-338-g713bb104e', - 'branch' => 'develop', + 'hash_version' => 'g4ab478bb9', + 'full_hash' => 'v7.0.13-pre-111-g4ab478bb9', + 'branch' => 'master', ); \ No newline at end of file diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 178f8fa9ad..6442472d5f 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -33,7 +33,7 @@ class AccessoryFactory extends Factory $this->faker->randomElement(['Bluetooth', 'Wired']), $this->faker->randomElement(['Keyboard', 'Wired']) ), - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'category_id' => Category::factory()->forAccessories(), 'model_number' => $this->faker->numberBetween(1000000, 50000000), 'location_id' => Location::factory(), @@ -128,7 +128,7 @@ class AccessoryFactory extends Factory $accessory->checkouts()->create([ 'accessory_id' => $accessory->id, 'created_at' => Carbon::now(), - 'user_id' => $user->id, + 'created_by' => $user->id, 'assigned_to' => $user->id, 'assigned_type' => User::class, 'note' => '', @@ -149,7 +149,7 @@ class AccessoryFactory extends Factory $accessory->checkouts()->create([ 'accessory_id' => $accessory->id, 'created_at' => Carbon::now(), - 'user_id' => 1, + 'created_by' => 1, 'assigned_to' => $user->id ?? User::factory()->create()->id, 'assigned_type' => User::class, ]); diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index a88166d14b..ad07f7082b 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -29,7 +29,7 @@ class ActionlogFactory extends Factory return [ 'item_id' => Asset::factory(), 'item_type' => Asset::class, - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'action_type' => 'uploaded', ]; } @@ -92,7 +92,7 @@ class ActionlogFactory extends Factory $licenseSeat->update([ 'assigned_to' => $target->id, - 'user_id' => 1, // not ideal but works + 'created_by' => 1, // not ideal but works ]); return [ diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index b1255baeee..4d6d20651c 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -36,7 +36,7 @@ class AssetFactory extends Factory 'status_id' => function () { return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']); }, - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'asset_tag' => $this->faker->unixTime('now'), 'notes' => 'Created by DB seeder', 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 6790897567..8acecd55d7 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -28,7 +28,7 @@ class AssetModelFactory extends Factory public function definition() { return [ - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'name' => $this->faker->catchPhrase(), 'category_id' => Category::factory(), 'model_number' => $this->faker->creditCardNumber(), diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index 2a89c12892..540dcb3085 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -29,7 +29,7 @@ class CategoryFactory extends Factory 'eula_text' => $this->faker->paragraph(), 'require_acceptance' => false, 'use_default_eula' => $this->faker->boolean(), - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), ]; } diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php index 607822fef1..5f1ac0c98a 100644 --- a/database/factories/CompanyFactory.php +++ b/database/factories/CompanyFactory.php @@ -23,6 +23,7 @@ class CompanyFactory extends Factory { return [ 'name' => $this->faker->unique()->company(), + 'created_by' => 1, ]; } } diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 2557f29c77..51942fc694 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -108,7 +108,7 @@ class ComponentFactory extends Factory $component->assets()->attach($component->id, [ 'component_id' => $component->id, 'created_at' => Carbon::now(), - 'user_id' => 1, + 'created_by' => 1, 'asset_id' => $asset->id ?? Asset::factory()->create()->id, ]); }); diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index ca3a2faf95..4a4b3ef872 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -30,7 +30,7 @@ class ConsumableFactory extends Factory return [ 'name' => $this->faker->words(3, true), 'category_id' => Category::factory(), - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'item_no' => $this->faker->numberBetween(1000000, 50000000), 'order_number' => $this->faker->numberBetween(1000000, 50000000), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), @@ -104,7 +104,7 @@ class ConsumableFactory extends Factory $consumable->users()->attach($consumable->id, [ 'consumable_id' => $consumable->id, - 'user_id' => $user->id, + 'created_by' => $user->id, 'assigned_to' => $user->id, 'note' => '', ]); @@ -124,7 +124,7 @@ class ConsumableFactory extends Factory $consumable->users()->attach($consumable->id, [ 'consumable_id' => $consumable->id, 'created_at' => Carbon::now(), - 'user_id' => User::factory()->create()->id, + 'created_by' => User::factory()->create()->id, 'assigned_to' => $user->id ?? User::factory()->create()->id, ]); }); diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index afcc9cbd33..011a632669 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -25,7 +25,7 @@ class DepartmentFactory extends Factory { return [ 'name' => $this->faker->unique()->word() . ' Department', - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'location_id' => Location::factory(), ]; } diff --git a/database/factories/DepreciationFactory.php b/database/factories/DepreciationFactory.php index 6359e2326b..52258e784b 100644 --- a/database/factories/DepreciationFactory.php +++ b/database/factories/DepreciationFactory.php @@ -24,7 +24,7 @@ class DepreciationFactory extends Factory { return [ 'name' => $this->faker->unique()->catchPhrase(), - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'months' => 36, ]; } diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 6360735c5f..1f5b105f42 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -25,7 +25,7 @@ class LicenseFactory extends Factory public function definition() { return [ - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'name' => $this->faker->name(), 'license_email' => $this->faker->safeEmail(), 'serial' => $this->faker->uuid(), diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.php index 7d6892426d..47d4f672f3 100644 --- a/database/factories/ManufacturerFactory.php +++ b/database/factories/ManufacturerFactory.php @@ -24,7 +24,7 @@ class ManufacturerFactory extends Factory { return [ 'name' => $this->faker->unique()->company(), - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'support_phone' => $this->faker->phoneNumber(), 'url' => $this->faker->url(), 'support_email' => $this->faker->safeEmail(), diff --git a/database/factories/StatuslabelFactory.php b/database/factories/StatuslabelFactory.php index fa2e5d5e1a..1f04f4564e 100644 --- a/database/factories/StatuslabelFactory.php +++ b/database/factories/StatuslabelFactory.php @@ -26,7 +26,7 @@ class StatuslabelFactory extends Factory 'name' => $this->faker->sentence(), 'created_at' => $this->faker->dateTime(), 'updated_at' => $this->faker->dateTime(), - 'user_id' => User::factory()->superuser(), + 'created_by' => User::factory()->superuser(), 'deleted_at' => null, 'deployable' => 0, 'pending' => 0, diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index b375142196..1b469941b4 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -35,6 +35,7 @@ class UserFactory extends Factory 'state' => $this->faker->stateAbbr(), 'username' => $this->faker->unique()->username(), 'zip' => $this->faker->postcode(), + 'created_by' => 1, ]; } diff --git a/database/migrations/2024_09_17_204302_change_user_id_to_created_by.php b/database/migrations/2024_09_17_204302_change_user_id_to_created_by.php new file mode 100644 index 0000000000..a57406ce10 --- /dev/null +++ b/database/migrations/2024_09_17_204302_change_user_id_to_created_by.php @@ -0,0 +1,93 @@ +add_to_table_list() as $add_table) { + if (!Schema::hasColumn($add_table, 'created_by')) { + Schema::table($add_table, function (Blueprint $add_table) { + $add_table->unsignedBigInteger('created_by')->nullable()->before('created_at'); + }); + } + } + + foreach ($this->existing_table_list() as $table) { + if (Schema::hasColumn($table, 'user_id')) { + Schema::table($table, function (Blueprint $table) { + $table->renameColumn('user_id', 'created_by'); + }); + } + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + foreach ($this->add_to_table_list() as $add_table) { + if (Schema::hasColumn($add_table, 'created_by')) { + Schema::table($add_table, function (Blueprint $add_table) { + $add_table->dropColumn('created_by'); + }); + } + } + + foreach ($this->existing_table_list() as $table) { + if (Schema::hasColumn($table, 'user_id')) { + Schema::table($table, function (Blueprint $table) { + $table->renameColumn('created_by', 'user_id'); + }); + } + } + } + + public function existing_table_list() { + return [ + 'accessories', + 'accessories_checkout', + 'action_logs', + 'asset_maintenances', + 'assets', + 'categories', + 'components', + 'components_assets', + 'consumables', + 'consumables_users', + 'custom_fields', + 'custom_fieldsets', + 'departments', + 'depreciations', + 'license_seats', + 'licenses', + 'locations', + 'manufacturers', + 'models', + 'settings', + 'status_labels', + 'suppliers', + 'users', + ]; + } + + public function add_to_table_list() { + return [ + 'companies', + 'imports', + 'kits', + 'kits_accessories', + 'kits_consumables', + 'kits_licenses', + 'kits_models', + 'users_groups', + ]; + } +}; diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.php index 2330a99733..5f4cca8cf6 100644 --- a/database/seeders/AccessorySeeder.php +++ b/database/seeders/AccessorySeeder.php @@ -35,25 +35,25 @@ class AccessorySeeder extends Seeder Accessory::factory()->appleUsbKeyboard()->create([ 'location_id' => $locationIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Accessory::factory()->appleBtKeyboard()->create([ 'location_id' => $locationIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Accessory::factory()->appleMouse()->create([ 'location_id' => $locationIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Accessory::factory()->microsoftMouse()->create([ 'location_id' => $locationIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); diff --git a/database/seeders/ActionlogSeeder.php b/database/seeders/ActionlogSeeder.php index 28191d53b0..3903980007 100644 --- a/database/seeders/ActionlogSeeder.php +++ b/database/seeders/ActionlogSeeder.php @@ -27,16 +27,16 @@ class ActionlogSeeder extends Seeder Actionlog::factory() ->count(300) ->assetCheckoutToUser() - ->create(['user_id' => $admin->id]); + ->create(['created_by' => $admin->id]); Actionlog::factory() ->count(100) ->assetCheckoutToLocation() - ->create(['user_id' => $admin->id]); + ->create(['created_by' => $admin->id]); Actionlog::factory() ->count(20) ->licenseCheckoutToUser() - ->create(['user_id' => $admin->id]); + ->create(['created_by' => $admin->id]); } } diff --git a/database/seeders/AssetModelSeeder.php b/database/seeders/AssetModelSeeder.php index 1fc0b28cd3..f2902ffe7c 100755 --- a/database/seeders/AssetModelSeeder.php +++ b/database/seeders/AssetModelSeeder.php @@ -17,34 +17,34 @@ class AssetModelSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); // Laptops - AssetModel::factory()->count(1)->mbp13Model()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->mbpAirModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->surfaceModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->xps13Model()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->spectreModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->zenbookModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->yogaModel()->create(['user_id' => $admin->id]); + AssetModel::factory()->count(1)->mbp13Model()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->mbpAirModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->surfaceModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->xps13Model()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->spectreModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->zenbookModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->yogaModel()->create(['created_by' => $admin->id]); // Desktops - AssetModel::factory()->count(1)->macproModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->lenovoI5Model()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->optiplexModel()->create(['user_id' => $admin->id]); + AssetModel::factory()->count(1)->macproModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->lenovoI5Model()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->optiplexModel()->create(['created_by' => $admin->id]); // Conference Phones - AssetModel::factory()->count(1)->polycomModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->polycomcxModel()->create(['user_id' => $admin->id]); + AssetModel::factory()->count(1)->polycomModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->polycomcxModel()->create(['created_by' => $admin->id]); // Tablets - AssetModel::factory()->count(1)->ipadModel()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->tab3Model()->create(['user_id' => $admin->id]); + AssetModel::factory()->count(1)->ipadModel()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->tab3Model()->create(['created_by' => $admin->id]); // Phones - AssetModel::factory()->count(1)->iphone11Model()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->iphone12Model()->create(['user_id' => $admin->id]); + AssetModel::factory()->count(1)->iphone11Model()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->iphone12Model()->create(['created_by' => $admin->id]); // Displays - AssetModel::factory()->count(1)->ultrafine()->create(['user_id' => $admin->id]); - AssetModel::factory()->count(1)->ultrasharp()->create(['user_id' => $admin->id]); + AssetModel::factory()->count(1)->ultrafine()->create(['created_by' => $admin->id]); + AssetModel::factory()->count(1)->ultrasharp()->create(['created_by' => $admin->id]); $src = public_path('/img/demo/models/'); $dst = 'models'.'/'; diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index 5fdc09bdb3..9d21e7f9fa 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -25,7 +25,7 @@ class AssetSeeder extends Seeder $this->ensureLocationsSeeded(); $this->ensureSuppliersSeeded(); - $this->admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + $this->adminuser = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); $this->locationIds = Location::all()->pluck('id'); $this->supplierIds = Supplier::all()->pluck('id'); @@ -82,7 +82,7 @@ class AssetSeeder extends Seeder return fn($sequence) => [ 'rtd_location_id' => $this->locationIds->random(), 'supplier_id' => $this->supplierIds->random(), - 'user_id' => $this->admin->id, + 'created_by' => $this->adminuser->id, ]; } } diff --git a/database/seeders/CategorySeeder.php b/database/seeders/CategorySeeder.php index da542cff9e..137dea2aba 100755 --- a/database/seeders/CategorySeeder.php +++ b/database/seeders/CategorySeeder.php @@ -14,20 +14,20 @@ class CategorySeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Category::factory()->count(1)->assetLaptopCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->assetDesktopCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->assetTabletCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->assetMobileCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->assetDisplayCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->assetVoipCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->assetConferenceCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->accessoryKeyboardCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->accessoryMouseCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->consumablePaperCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->consumableInkCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->componentHddCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->componentRamCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->licenseGraphicsCategory()->create(['user_id' => $admin->id]); - Category::factory()->count(1)->licenseOfficeCategory()->create(['user_id' => $admin->id]); + Category::factory()->count(1)->assetLaptopCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->assetDesktopCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->assetTabletCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->assetMobileCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->assetDisplayCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->assetVoipCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->assetConferenceCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->accessoryKeyboardCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->accessoryMouseCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->consumablePaperCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->consumableInkCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->componentHddCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->componentRamCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->licenseGraphicsCategory()->create(['created_by' => $admin->id]); + Category::factory()->count(1)->licenseOfficeCategory()->create(['created_by' => $admin->id]); } } diff --git a/database/seeders/ConsumableSeeder.php b/database/seeders/ConsumableSeeder.php index 42527e1df8..de20141c7a 100644 --- a/database/seeders/ConsumableSeeder.php +++ b/database/seeders/ConsumableSeeder.php @@ -16,8 +16,8 @@ class ConsumableSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Consumable::factory()->count(1)->cardstock()->create(['user_id' => $admin->id]); - Consumable::factory()->count(1)->paper()->create(['user_id' => $admin->id]); - Consumable::factory()->count(1)->ink()->create(['user_id' => $admin->id]); + Consumable::factory()->count(1)->cardstock()->create(['created_by' => $admin->id]); + Consumable::factory()->count(1)->paper()->create(['created_by' => $admin->id]); + Consumable::factory()->count(1)->ink()->create(['created_by' => $admin->id]); } } diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php index 7406b97afb..7f20ee8cb9 100644 --- a/database/seeders/DepartmentSeeder.php +++ b/database/seeders/DepartmentSeeder.php @@ -23,32 +23,32 @@ class DepartmentSeeder extends Seeder Department::factory()->count(1)->hr()->create([ 'location_id' => $locationIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Department::factory()->count(1)->engineering()->create([ 'location_id' => $locationIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Department::factory()->count(1)->marketing()->create([ 'location_id' => $locationIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Department::factory()->count(1)->client()->create([ 'location_id' => $locationIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Department::factory()->count(1)->product()->create([ 'location_id' => $locationIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Department::factory()->count(1)->silly()->create([ 'location_id' => $locationIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); } } diff --git a/database/seeders/DepreciationSeeder.php b/database/seeders/DepreciationSeeder.php index 349d8aff53..ed78c0b115 100644 --- a/database/seeders/DepreciationSeeder.php +++ b/database/seeders/DepreciationSeeder.php @@ -14,8 +14,8 @@ class DepreciationSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Depreciation::factory()->count(1)->computer()->create(['user_id' => $admin->id]); - Depreciation::factory()->count(1)->display()->create(['user_id' => $admin->id]); - Depreciation::factory()->count(1)->mobilePhones()->create(['user_id' => $admin->id]); + Depreciation::factory()->count(1)->computer()->create(['created_by' => $admin->id]); + Depreciation::factory()->count(1)->display()->create(['created_by' => $admin->id]); + Depreciation::factory()->count(1)->mobilePhones()->create(['created_by' => $admin->id]); } } diff --git a/database/seeders/LicenseSeeder.php b/database/seeders/LicenseSeeder.php index 4868dd41e1..bc19727f7e 100644 --- a/database/seeders/LicenseSeeder.php +++ b/database/seeders/LicenseSeeder.php @@ -33,25 +33,25 @@ class LicenseSeeder extends Seeder License::factory()->count(1)->photoshop()->create([ 'category_id' => $categoryIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); License::factory()->count(1)->acrobat()->create([ 'category_id' => $categoryIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); License::factory()->count(1)->indesign()->create([ 'category_id' => $categoryIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); License::factory()->count(1)->office()->create([ 'category_id' => $categoryIds->random(), 'supplier_id' => $supplierIds->random(), - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); } } diff --git a/database/seeders/ManufacturerSeeder.php b/database/seeders/ManufacturerSeeder.php index cbd70f4c3d..adc13dc73e 100644 --- a/database/seeders/ManufacturerSeeder.php +++ b/database/seeders/ManufacturerSeeder.php @@ -16,17 +16,17 @@ class ManufacturerSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Manufacturer::factory()->count(1)->apple()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->microsoft()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->dell()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->asus()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->hp()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->lenovo()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->lg()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->polycom()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->adobe()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->avery()->create(['user_id' => $admin->id]); - Manufacturer::factory()->count(1)->crucial()->create(['user_id' => $admin->id]); + Manufacturer::factory()->count(1)->apple()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->microsoft()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->dell()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->asus()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->hp()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->lenovo()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->lg()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->polycom()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->adobe()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->avery()->create(['created_by' => $admin->id]); + Manufacturer::factory()->count(1)->crucial()->create(['created_by' => $admin->id]); $src = public_path('/img/demo/manufacturers/'); $dst = 'manufacturers'.'/'; diff --git a/database/seeders/StatuslabelSeeder.php b/database/seeders/StatuslabelSeeder.php index fbc6a9fb66..be36e7790d 100755 --- a/database/seeders/StatuslabelSeeder.php +++ b/database/seeders/StatuslabelSeeder.php @@ -16,22 +16,22 @@ class StatuslabelSeeder extends Seeder Statuslabel::factory()->rtd()->create([ 'name' => 'Ready to Deploy', - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Statuslabel::factory()->pending()->create([ 'name' => 'Pending', - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); Statuslabel::factory()->archived()->create([ 'name' => 'Archived', - 'user_id' => $admin->id, + 'created_by' => $admin->id, ]); - Statuslabel::factory()->outForDiagnostics()->create(['user_id' => $admin->id]); - Statuslabel::factory()->outForRepair()->create(['user_id' => $admin->id]); - Statuslabel::factory()->broken()->create(['user_id' => $admin->id]); - Statuslabel::factory()->lost()->create(['user_id' => $admin->id]); + Statuslabel::factory()->outForDiagnostics()->create(['created_by' => $admin->id]); + Statuslabel::factory()->outForRepair()->create(['created_by' => $admin->id]); + Statuslabel::factory()->broken()->create(['created_by' => $admin->id]); + Statuslabel::factory()->lost()->create(['created_by' => $admin->id]); } } diff --git a/package-lock.json b/package-lock.json index a5296ae5f3..5a98e56c6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "jquery-ui": "^1.14.0", "jquery-validation": "^1.21.0", "jquery.iframe-transport": "^1.0.0", - "jspdf-autotable": "^3.8.2", + "jspdf-autotable": "^3.8.3", "less": "^4.2.0", "less-loader": "^6.0", "list.js": "^1.5.0", @@ -7167,8 +7167,9 @@ } }, "node_modules/jspdf-autotable": { - "version": "3.8.2", - "license": "MIT", + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/jspdf-autotable/-/jspdf-autotable-3.8.3.tgz", + "integrity": "sha512-PQFdljBt+ijm6ZWXYxhZ54A/awV63UKcipYoA2+YGsz0BXXiXTIL/FIg+V30j7wPdSdzClfbB3qKX9UeuFylPQ==", "peerDependencies": { "jspdf": "^2.5.1" } diff --git a/package.json b/package.json index 3d8e3eda2d..2b3ec19b63 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "jquery-ui": "^1.14.0", "jquery-validation": "^1.21.0", "jquery.iframe-transport": "^1.0.0", - "jspdf-autotable": "^3.8.2", + "jspdf-autotable": "^3.8.3", "less": "^4.2.0", "less-loader": "^6.0", "list.js": "^1.5.0", diff --git a/public/css/build/app.css b/public/css/build/app.css index a2e11fc496..3cea5e2d0f 100644 Binary files a/public/css/build/app.css and b/public/css/build/app.css differ diff --git a/public/css/build/overrides.css b/public/css/build/overrides.css index 807ea0b0a4..52c81f55f6 100644 Binary files a/public/css/build/overrides.css and b/public/css/build/overrides.css differ diff --git a/public/css/dist/all.css b/public/css/dist/all.css index cafb9a2c4a..eda068945a 100644 Binary files a/public/css/dist/all.css and b/public/css/dist/all.css differ diff --git a/public/js/build/app.js.LICENSE.txt b/public/js/build/app.js.LICENSE.txt index cb3342c839..931b6a9882 100644 Binary files a/public/js/build/app.js.LICENSE.txt and b/public/js/build/app.js.LICENSE.txt differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 822ca188e5..0290e23dfa 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -2,8 +2,8 @@ "/js/build/app.js": "/js/build/app.js?id=5e9ac5c1a7e089f056fb1dba566193a6", "/css/dist/skins/skin-black-dark.css": "/css/dist/skins/skin-black-dark.css?id=f0b08873a06bb54daeee176a9459f4a9", "/css/dist/skins/_all-skins.css": "/css/dist/skins/_all-skins.css?id=f4397c717b99fce41a633ca6edd5d1f4", - "/css/build/overrides.css": "/css/build/overrides.css?id=7fa231e10a862be5469f803bb9b02e16", - "/css/build/app.css": "/css/build/app.css?id=6f058a6824a8b236f9e5ac4c993d4520", + "/css/build/overrides.css": "/css/build/overrides.css?id=efd9f439cb0586512d03172bcd9a5752", + "/css/build/app.css": "/css/build/app.css?id=2f45befb40b9d7f038eeae9569c33a5f", "/css/build/AdminLTE.css": "/css/build/AdminLTE.css?id=4ea0068716c1bb2434d87a16d51b98c9", "/css/dist/skins/skin-yellow.css": "/css/dist/skins/skin-yellow.css?id=7b315b9612b8fde8f9c5b0ddb6bba690", "/css/dist/skins/skin-yellow-dark.css": "/css/dist/skins/skin-yellow-dark.css?id=393aaa7b368b0670fc42434c8cca7dc7", @@ -19,7 +19,7 @@ "/css/dist/skins/skin-blue.css": "/css/dist/skins/skin-blue.css?id=f677207c6cf9678eb539abecb408c374", "/css/dist/skins/skin-blue-dark.css": "/css/dist/skins/skin-blue-dark.css?id=0640e45bad692dcf62873c6e85904899", "/css/dist/skins/skin-black.css": "/css/dist/skins/skin-black.css?id=76482123f6c70e866d6b971ba91de7bb", - "/css/dist/all.css": "/css/dist/all.css?id=0665a8b7a6fcf6d93218ffdf67e98193", + "/css/dist/all.css": "/css/dist/all.css?id=e9509d7591637153f667461642e47e30", "/css/dist/signature-pad.css": "/css/dist/signature-pad.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/dist/signature-pad.min.css": "/css/dist/signature-pad.min.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/js/select2/i18n/af.js": "/js/select2/i18n/af.js?id=4f6fcd73488ce79fae1b7a90aceaecde", diff --git a/resources/assets/less/app.less b/resources/assets/less/app.less index 94f5f4098b..37514e5cfd 100644 --- a/resources/assets/less/app.less +++ b/resources/assets/less/app.less @@ -384,7 +384,7 @@ a.logo.no-hover a:hover { background-color: transparent; } -.required { +input:required, select:required { border-right: 6px solid orange; } diff --git a/resources/assets/less/overrides.less b/resources/assets/less/overrides.less index f3261a19b7..0721c401df 100644 --- a/resources/assets/less/overrides.less +++ b/resources/assets/less/overrides.less @@ -156,10 +156,10 @@ a.accordion-header { height: 150px; } - .select2-container { width: 100%; } + .error input { color: #a94442; border: 2px solid #a94442 !important; @@ -341,8 +341,11 @@ a.logo.no-hover a:hover { } -.required { - border-right: 6px solid orange; +input:required, select:required { + border-right: 5px solid orange; +} +select:required + .select2-container .select2-selection, select:required + .select2-container .select2-selection .select2-selection--multiple { + border-right: 5px solid orange !important; } body { diff --git a/resources/lang/en-US/admin/hardware/table.php b/resources/lang/en-US/admin/hardware/table.php index 92b228dccd..2d88c6c131 100644 --- a/resources/lang/en-US/admin/hardware/table.php +++ b/resources/lang/en-US/admin/hardware/table.php @@ -25,7 +25,6 @@ return [ 'image' => 'Device Image', 'days_without_acceptance' => 'Days Without Acceptance', 'monthly_depreciation' => 'Monthly Depreciation', - 'assigned_to' => 'Assigned To', 'requesting_user' => 'Requesting User', 'requested_date' => 'Requested Date', 'changed' => 'Changed', diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 3092228674..b566b1f19d 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -282,6 +282,7 @@ return [ 'status_label' => 'Status Label', 'status' => 'Status', 'accept_eula' => 'Acceptance Agreement', + 'show_or_hide_eulas' => 'Show/Hide EULAs', 'supplier' => 'Supplier', 'suppliers' => 'Suppliers', 'sure_to_delete' => 'Are you sure you wish to delete', diff --git a/resources/views/asset_maintenances/edit.blade.php b/resources/views/asset_maintenances/edit.blade.php index c3aa8e1483..4dd390ddfa 100644 --- a/resources/views/asset_maintenances/edit.blade.php +++ b/resources/views/asset_maintenances/edit.blade.php @@ -41,28 +41,32 @@
- @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/table.asset_tag'), 'fieldname' => 'asset_id', 'required' => 'true']) - @include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id', 'required' => 'true']) - @include ('partials.forms.edit.maintenance_type')
-
- +
+ {!! $errors->first('title', '') !!}
+ + @include ('partials.forms.edit.asset-select', ['translated_name' => trans('general.asset'), 'fieldname' => 'asset_id', 'required' => 'true']) + @include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id', 'required' => 'true']) + @include ('partials.forms.edit.maintenance_type') + + +
-
+
- +
{!! $errors->first('start_date', '') !!} @@ -75,10 +79,12 @@
-
+
- - + + + +
{!! $errors->first('completion_date', '') !!}
diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.php index a281beebc2..61779f1939 100755 --- a/resources/views/depreciations/edit.blade.php +++ b/resources/views/depreciations/edit.blade.php @@ -15,7 +15,7 @@ -
+
{!! $errors->first('months', '') !!} diff --git a/resources/views/groups/index.blade.php b/resources/views/groups/index.blade.php index 5f96551d31..11c16a8b09 100755 --- a/resources/views/groups/index.blade.php +++ b/resources/views/groups/index.blade.php @@ -45,7 +45,7 @@ {{ trans('admin/groups/table.name') }} {{ trans('admin/groups/table.users') }} {{ trans('general.created_at') }} - {{ trans('general.created_by') }} + {{ trans('general.created_by') }} {{ trans('table.actions') }} diff --git a/resources/views/hardware/bulk-checkout.blade.php b/resources/views/hardware/bulk-checkout.blade.php index 465336563d..f309cadbd9 100644 --- a/resources/views/hardware/bulk-checkout.blade.php +++ b/resources/views/hardware/bulk-checkout.blade.php @@ -27,7 +27,18 @@
{{ csrf_field() }} - + @include ('partials.forms.edit.asset-select', [ + 'translated_name' => trans('general.assets'), + 'fieldname' => 'selected_assets[]', + 'multiple' => true, + 'required' => true, + 'asset_status_type' => 'RTD', + 'select_id' => 'assigned_assets_select', + ]) + + + + @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true']) @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_user', 'required'=>'true']) @@ -74,13 +85,6 @@
- @include ('partials.forms.edit.asset-select', [ - 'translated_name' => trans('general.assets'), - 'fieldname' => 'selected_assets[]', - 'multiple' => true, - 'asset_status_type' => 'RTD', - 'select_id' => 'assigned_assets_select', - ])
diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index a067a5a11d..943b4ba798 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -89,12 +89,12 @@ @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true']) - @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_user', 'required'=>'true']) + @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_user']) - @include ('partials.forms.edit.asset-select', ['translated_name' => trans('general.asset'), 'fieldname' => 'assigned_asset', 'unselect' => 'true', 'style' => 'display:none;', 'required'=>'true']) + @include ('partials.forms.edit.asset-select', ['translated_name' => trans('general.asset'), 'fieldname' => 'assigned_asset', 'unselect' => 'true', 'style' => 'display:none;']) - @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required'=>'true']) + @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'assigned_location', 'style' => 'display:none;']) diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index abba2cdb9b..efd5d24b9c 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -28,8 +28,7 @@ @if ($item->id) -
- +
{!! $errors->first('asset_tags', ' :message') !!} @@ -37,7 +36,7 @@
@else -
+
{!! $errors->first('asset_tags', ' :message') !!} {!! $errors->first('asset_tag', ' :message') !!} diff --git a/resources/views/hardware/requested.blade.php b/resources/views/hardware/requested.blade.php index 83ea30090f..969bf991a6 100644 --- a/resources/views/hardware/requested.blade.php +++ b/resources/views/hardware/requested.blade.php @@ -40,8 +40,8 @@ }'> - Image - Item Name + {{ trans('general.image') }} + {{ trans('general.name') }} {{ trans('admin/hardware/table.location') }} {{ trans('admin/hardware/form.expected_checkin') }} {{ trans('admin/hardware/table.requesting_user') }} @@ -102,7 +102,13 @@ {{ Form::open([ 'method' => 'POST', - 'route' => ['account/request-item', $request->itemType(), $request->requestable->id, true, $request->requestingUser()->id], + 'route' => [ + 'account/request-item', + $request->itemType(), + $request->requestable->id, + true, + $request->requestingUser()->id + ], ]) }} {{ Form::close() }} diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 42144fc20c..0dd2d75c46 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -27,7 +27,7 @@ [ 'warning' => trans('admin/hardware/message.warning_audit_date_mismatch', [ - 'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'date', false), + 'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime', false), 'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date', false) ] ) @@ -156,10 +156,11 @@
- {{ trans('admin/users/message.user_deleted_warning') }} + {{ trans('general.asset_deleted_warning') }}
@endif +
@@ -492,7 +493,7 @@
{!! $asset->checkInvalidNextAuditDate() ? '' : '' !!} - {{ Helper::getFormattedDateObject($audit_log->created_at, 'date', false) }} + {{ Helper::getFormattedDateObject($audit_log->created_at, 'datetime', false) }} @if ($audit_log->user) (by {{ link_to_route('users.show', $audit_log->user->present()->fullname(), [$audit_log->user->id]) }}) @endif @@ -657,6 +658,16 @@
+ +
+
+ {{ trans('admin/hardware/general.requestable') }} +
+
+ {!! ($asset->requestable=='1') ? ' '.trans('general.yes') : ' '.trans('general.no') !!} +
+
+ @if (($asset->model) && ($asset->model->fieldset)) @foreach($asset->model->fieldset->fields as $field)
diff --git a/resources/views/licenses/checkout.blade.php b/resources/views/licenses/checkout.blade.php index bfd4773099..ef6b87fc0d 100755 --- a/resources/views/licenses/checkout.blade.php +++ b/resources/views/licenses/checkout.blade.php @@ -55,9 +55,9 @@
- @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'false']) + @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true']) - @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_to', 'required'=>'true']) + @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_to']) @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/licenses/form.asset'), 'fieldname' => 'asset_id', 'style' => 'display:none;']) diff --git a/resources/views/licenses/edit.blade.php b/resources/views/licenses/edit.blade.php index c092324a63..1bd40c6c54 100755 --- a/resources/views/licenses/edit.blade.php +++ b/resources/views/licenses/edit.blade.php @@ -33,8 +33,8 @@ @can('viewKeys', $item)
-
- +
+ {!! $errors->first('serial', '') !!}
diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php index 95ba245359..55d638a9f5 100755 --- a/resources/views/locations/edit.blade.php +++ b/resources/views/locations/edit.blade.php @@ -25,8 +25,8 @@ -
- {{ Form::text('currency', old('currency', $item->currency), array('class' => 'form-control','placeholder' => 'USD', 'maxlength'=>'3', 'style'=>'width: 60px;', 'aria-label'=>'currency')) }} +
+ {{ Form::text('currency', old('currency', $item->currency), array('class' => 'form-control','placeholder' => 'USD', 'maxlength'=>'3', 'style'=>'width: 60px;', 'aria-label'=>'currency', 'required' => (Helper::checkIfRequired($item, 'currency')) ? true : '')) }} {!! $errors->first('currency', '') !!}
@@ -39,8 +39,8 @@ -
- {{ Form::text('ldap_ou', old('ldap_ou', $item->ldap_ou), array('class' => 'form-control')) }} +
+ {{ Form::text('ldap_ou', old('ldap_ou', $item->ldap_ou), array('class' => 'form-control', 'required' => (Helper::checkIfRequired($item, 'ldap_ou')) ? true : '')) }} {!! $errors->first('ldap_ou', '') !!}
diff --git a/resources/views/manufacturers/index.blade.php b/resources/views/manufacturers/index.blade.php index e7afd91ddf..c8fd3184d0 100755 --- a/resources/views/manufacturers/index.blade.php +++ b/resources/views/manufacturers/index.blade.php @@ -37,7 +37,6 @@ data-pagination="true" data-id-table="manufacturersTable" data-search="true" - data-show-footer="true" data-side-pagination="server" data-show-columns="true" data-show-fullscreen="true" diff --git a/resources/views/modals/category.blade.php b/resources/views/modals/category.blade.php index c07b092ace..4dfe26d026 100644 --- a/resources/views/modals/category.blade.php +++ b/resources/views/modals/category.blade.php @@ -11,19 +11,10 @@ {{ csrf_field() }} -
-
-
- -
-
+ @include('modals.partials.name')
- + @include('modals.partials.footer')
diff --git a/resources/views/modals/location.blade.php b/resources/views/modals/location.blade.php index d705f5500e..9580f4bbf9 100644 --- a/resources/views/modals/location.blade.php +++ b/resources/views/modals/location.blade.php @@ -9,11 +9,7 @@
-
-
-
-
+ @include('modals.partials.name', ['item' => new \App\Models\Location(), 'required' => 'true'])
@@ -26,10 +22,6 @@
- - + @include('modals.partials.footer')
diff --git a/resources/views/modals/manufacturer.blade.php b/resources/views/modals/manufacturer.blade.php index 60cf8363e4..38c6e32af8 100644 --- a/resources/views/modals/manufacturer.blade.php +++ b/resources/views/modals/manufacturer.blade.php @@ -8,20 +8,13 @@
-
diff --git a/resources/views/modals/model.blade.php b/resources/views/modals/model.blade.php index abbd50ee97..fb1650eee7 100644 --- a/resources/views/modals/model.blade.php +++ b/resources/views/modals/model.blade.php @@ -9,40 +9,13 @@
-
-
-
-
- -
-
-
- -
-
- -
-
-
- -
-
- -
-
-
-
- -
-
-
{{ Form::select('fieldset_id', Helper::customFieldsetList(),old('fieldset_id'), array('class'=>'select2', 'id'=>'modal-fieldset_id', 'style'=>'width:350px')) }}
-
-
- + @include('modals.partials.footer')
diff --git a/resources/views/modals/partials/categories-select.blade.php b/resources/views/modals/partials/categories-select.blade.php new file mode 100644 index 0000000000..116a0808e9 --- /dev/null +++ b/resources/views/modals/partials/categories-select.blade.php @@ -0,0 +1,11 @@ + +@php + $required = $required ?? ''; +@endphp +
+
+
+ +
+
+ \ No newline at end of file diff --git a/resources/views/modals/partials/fieldset-select.blade.php b/resources/views/modals/partials/fieldset-select.blade.php new file mode 100644 index 0000000000..3f4efc24b6 --- /dev/null +++ b/resources/views/modals/partials/fieldset-select.blade.php @@ -0,0 +1,6 @@ + +
+
+
{{ Form::select('fieldset_id', Helper::customFieldsetList(),old('fieldset_id'), array('class'=>'select2', 'id'=>'modal-fieldset_id', 'style'=>'width:100%;')) }}
+
+ \ No newline at end of file diff --git a/resources/views/modals/partials/footer.blade.php b/resources/views/modals/partials/footer.blade.php new file mode 100644 index 0000000000..354d189b9e --- /dev/null +++ b/resources/views/modals/partials/footer.blade.php @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/resources/views/modals/partials/manufacturer-select.blade.php b/resources/views/modals/partials/manufacturer-select.blade.php new file mode 100644 index 0000000000..810292067e --- /dev/null +++ b/resources/views/modals/partials/manufacturer-select.blade.php @@ -0,0 +1,8 @@ + +
+
+
+ +
+
+ \ No newline at end of file diff --git a/resources/views/modals/partials/model-number.blade.php b/resources/views/modals/partials/model-number.blade.php new file mode 100644 index 0000000000..2691f30d48 --- /dev/null +++ b/resources/views/modals/partials/model-number.blade.php @@ -0,0 +1,6 @@ + +
+
+
+
+ \ No newline at end of file diff --git a/resources/views/modals/partials/name.blade.php b/resources/views/modals/partials/name.blade.php new file mode 100644 index 0000000000..6a64ed525f --- /dev/null +++ b/resources/views/modals/partials/name.blade.php @@ -0,0 +1,10 @@ + +@php + $required = $required ?? ''; +@endphp +
+
+
+
+ \ No newline at end of file diff --git a/resources/views/modals/statuslabel.blade.php b/resources/views/modals/statuslabel.blade.php index 7e07854197..e7076f1bbb 100644 --- a/resources/views/modals/statuslabel.blade.php +++ b/resources/views/modals/statuslabel.blade.php @@ -10,21 +10,18 @@
-
-
+ @include('partials.forms.edit.name', ['required' => 'true', 'item' => new \App\Models\Statuslabel(),'translated_name' => trans('admin/statuslabels/table.name') ])
-
- diff --git a/resources/views/modals/supplier.blade.php b/resources/views/modals/supplier.blade.php index 0dd10595bf..806b57c1de 100644 --- a/resources/views/modals/supplier.blade.php +++ b/resources/views/modals/supplier.blade.php @@ -10,15 +10,12 @@
-
-
+ @include('partials.forms.edit.name', [ 'item' => new \App\Models\Supplier(), 'translated_name' => trans('admin/suppliers/table.name')])
- diff --git a/resources/views/modals/user.blade.php b/resources/views/modals/user.blade.php index e65fcca5b0..5672119fa1 100644 --- a/resources/views/modals/user.blade.php +++ b/resources/views/modals/user.blade.php @@ -25,11 +25,10 @@ - - diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php index d38b63264e..65f9bdd4fe 100755 --- a/resources/views/models/view.blade.php +++ b/resources/views/models/view.blade.php @@ -166,7 +166,7 @@ {{ $file->note }} @endif - + @if (($file->filename) && (Storage::exists('private_uploads/assetmodels/'.$file->filename))) diff --git a/resources/views/notifications/markdown/asset-reminder.blade.php b/resources/views/notifications/markdown/asset-reminder.blade.php index 408c3847f4..691f454a36 100644 --- a/resources/views/notifications/markdown/asset-reminder.blade.php +++ b/resources/views/notifications/markdown/asset-reminder.blade.php @@ -1,11 +1,11 @@ @component('mail::message') - # {{ trans('mail.hello') }} {{ $assigned_to}}, +# {{ trans('mail.hello') }} {{ $assigned_to}}, - {{trans('mail.item_checked_reminder', ['count' => $count])}} - [{{ trans('general.click_here')}}]({{$accept_url}}) +{{trans('mail.item_checked_reminder', ['count' => $count])}} +[{{ trans('general.click_here')}}]({{$accept_url}}) - {{ trans('mail.best_regards') }} +{{ trans('mail.best_regards') }} - {{ $snipeSettings->site_name }} +{{ $snipeSettings->site_name }} @endcomponent diff --git a/resources/views/partials/forms/edit/accessory-select.blade.php b/resources/views/partials/forms/edit/accessory-select.blade.php index 12be9bf7b7..d34b6b2fe0 100644 --- a/resources/views/partials/forms/edit/accessory-select.blade.php +++ b/resources/views/partials/forms/edit/accessory-select.blade.php @@ -1,8 +1,8 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
- @if ((!isset($unselect)) && ($accessory_id = old($fieldname, (isset($accessory) ? $accessory->id : (isset($item) ? $item->{$fieldname} : '')))))
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
- @if ((!isset($unselect)) && ($asset_id = old($fieldname, (isset($asset) ? $asset->id : (isset($item) ? $item->{$fieldname} : '')))))
+
@if ($company_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
-
- +
+ {!! $errors->first('item_no', '') !!}
diff --git a/resources/views/partials/forms/edit/kit-select.blade.php b/resources/views/partials/forms/edit/kit-select.blade.php index a9b6525202..d8c6ba1013 100644 --- a/resources/views/partials/forms/edit/kit-select.blade.php +++ b/resources/views/partials/forms/edit/kit-select.blade.php @@ -2,8 +2,8 @@ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
- @if ($kit_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
- @if ((!isset($unselect)) && ($license_id = old($fieldname, (isset($license) ? $license->id : (isset($item) ? $item->{$fieldname} : '')))))
{{ Form::label('location_id', $translated_name, array('class' => 'col-md-3 control-label')) }} -
+
+
+ @if ($manufacturer_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
+
-
- {{ Form::select('manufacturer_id', $manufacturer_list , old('manufacturer_id', $item->manufacturer_id), array('class'=>'select2', 'style'=>'width:100%')) }} +
+ {{ Form::select('manufacturer_id', $manufacturer_list , old('manufacturer_id', $item->manufacturer_id), array('class'=>'select2', 'style'=>'width:100%', 'required' => Helper::checkIfRequired($item, 'manufacturer_id') ? true : '')) }} {!! $errors->first('manufacturer_id', '') !!}
diff --git a/resources/views/partials/forms/edit/minimum_quantity.blade.php b/resources/views/partials/forms/edit/minimum_quantity.blade.php index 798c6fe72d..5c9f5e8588 100644 --- a/resources/views/partials/forms/edit/minimum_quantity.blade.php +++ b/resources/views/partials/forms/edit/minimum_quantity.blade.php @@ -1,13 +1,14 @@
-
+
- +
diff --git a/resources/views/partials/forms/edit/model-select.blade.php b/resources/views/partials/forms/edit/model-select.blade.php index c18d85af3b..db62a34fd4 100644 --- a/resources/views/partials/forms/edit/model-select.blade.php +++ b/resources/views/partials/forms/edit/model-select.blade.php @@ -3,8 +3,8 @@ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} -
- @if ($model_id = old($fieldname, ($item->{$fieldname} ?? request($fieldname) ?? '')))