Skip to content

Commit

Permalink
prevents required serial from being selected if serials are blank
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Jul 2, 2024
1 parent fb01682 commit 5d1266b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ public function getSettings()
/**
* Return a form to allow a super admin to update settings.
*
* @author [A. Gianotto] [<[email protected]>]
* @return \Illuminate\Http\RedirectResponse
*@since [v1.0]
*
* @since [v1.0]
* @author [A. Gianotto] [<[email protected]>]
*
* @return View
*/
public function postSettings(Request $request)
{
Expand All @@ -335,7 +335,13 @@ public function postSettings(Request $request)

$setting->full_multiple_companies_support = $request->input('full_multiple_companies_support', '0');
$setting->unique_serial = $request->input('unique_serial', '0');
$setting->required_serial = $request->input('required_serial', '0');
// dd(Asset::where('serial', '=', null)->count());
if((Asset::where('serial', '=', null)->count() > 0) && ($request->input('required_serial') == 0)) {
$setting->required_serial = $request->input('required_serial', '0');
}
else{
return redirect()->route('settings.general.index')->with('error', trans('admin/settings/general.required_serial_error', ['count' => Asset::where('serial', '=', null)->count(),'link' => route('hardware.index')]));
}
$setting->show_images_in_email = $request->input('show_images_in_email', '0');
$setting->show_archived_in_list = $request->input('show_archived_in_list', '0');
$setting->dashboard_message = $request->input('dashboard_message');
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function declinedCheckout(User $declinedBy, $signature)
'deleted_at' => 'datetime',
];


protected $rules = [
'model_id' => 'required|integer|exists:models,id,deleted_at,NULL|not_array',
'status_id' => 'required|integer|exists:status_labels,id',
Expand All @@ -113,7 +112,7 @@ public function declinedCheckout(User $declinedBy, $signature)
'location_id' => 'nullable|exists:locations,id',
'rtd_location_id' => 'nullable|exists:locations,id',
'purchase_date' => 'nullable|date|date_format:Y-m-d',
'serial' => 'unique_undeleted:assets,serial|potentially_required:required_serial',
'serial' => 'nullable|unique_undeleted:assets,serial',
'purchase_cost' => 'nullable|numeric|gte:0',
'supplier_id' => 'nullable|exists:suppliers,id',
'asset_eol_date' => 'nullable|date',
Expand All @@ -125,6 +124,7 @@ public function declinedCheckout(User $declinedBy, $signature)
'requestable' => 'nullable|boolean',
];


/**
* The attributes that are mass assignable.
*
Expand Down
7 changes: 7 additions & 0 deletions resources/lang/en-US/admin/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,12 @@
'timezone' => 'Timezone',
'profile_edit' => 'Edit Profile',
'profile_edit_help' => 'Allow users to edit their own profiles.',
'required_serial_error' => 'All current assets must have a serial before you can select this option. There are currently :count Assets without serials',







];

0 comments on commit 5d1266b

Please sign in to comment.