-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows check-ins of unreassignable licenses #16063
base: develop
Are you sure you want to change the base?
Changes from all commits
8a0ed49
5e1562a
50e0e4a
9da15a8
7a23372
344b4e7
f47a2b1
db11fc3
f050864
3f3f2bf
52bf0fa
d217c2e
6bab6e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,15 @@ | |
|
||
namespace App\Helpers; | ||
use App\Models\Accessory; | ||
use App\Models\Actionlog; | ||
use App\Models\Asset; | ||
use App\Models\AssetModel; | ||
use App\Models\Component; | ||
use App\Models\Consumable; | ||
use App\Models\CustomField; | ||
use App\Models\CustomFieldset; | ||
use App\Models\Depreciation; | ||
use App\Models\LicenseSeat; | ||
use App\Models\Setting; | ||
use App\Models\Statuslabel; | ||
use App\Models\License; | ||
|
@@ -1529,4 +1531,14 @@ static public function getRedirectOption($request, $id, $table, $item_id = null) | |
} | ||
return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error')); | ||
} | ||
public static function unReassignableCount($license) | ||
{ | ||
|
||
if (!$license->reassignable) { | ||
$count = LicenseSeat::where('unreassignable_seat', '=', true) | ||
->where('license_id', '=', $license->id) | ||
->count(); | ||
return $count; | ||
} | ||
} | ||
Comment on lines
+1534
to
+1543
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method feels like it would be more at home on the actual License model. Is there any reason it needs to be a helper? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,12 +69,7 @@ public function store(Request $request, $seatId = null, $backTo = null) | |
|
||
$this->authorize('checkout', $license); | ||
|
||
if (! $license->reassignable) { | ||
// Not allowed to checkin | ||
Session::flash('error', trans('admin/licenses/message.checkin.not_reassignable') . '.'); | ||
|
||
return redirect()->back()->withInput(); | ||
} | ||
|
||
// Declare the rules for the form validation | ||
$rules = [ | ||
|
@@ -100,13 +95,18 @@ public function store(Request $request, $seatId = null, $backTo = null) | |
$licenseSeat->assigned_to = null; | ||
$licenseSeat->asset_id = null; | ||
$licenseSeat->notes = $request->input('notes'); | ||
if (! $licenseSeat->license->reassignable) { | ||
$licenseSeat->unreassignable_seat = true; | ||
$licenseSeat->notes .= "\n" . trans('admin/licenses/message.checkin.not_reassignable') . '.'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need to append this message. I think we can remove it? If we're going to keep it then it should be in the API controller too. |
||
|
||
} | ||
|
||
session()->put(['redirect_option' => $request->get('redirect_option')]); | ||
|
||
|
||
// Was the asset updated? | ||
if ($licenseSeat->save()) { | ||
event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $request->input('notes'))); | ||
event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $licenseSeat->notes)); | ||
|
||
|
||
return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.checkin.success')); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,16 +248,23 @@ public function show($licenseId = null) | |
} | ||
|
||
$users_count = User::where('autoassign_licenses', '1')->count(); | ||
$total_seats_count = $license->totalSeatsByLicenseID(); | ||
$total_seats_count = (int) $license->totalSeatsByLicenseID(); | ||
$available_seats_count = $license->availCount()->count(); | ||
$checkedout_seats_count = ($total_seats_count - $available_seats_count); | ||
$unreassignable_seats_count = Helper::unReassignableCount($license); | ||
if(!$license->reassignable){ | ||
$checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count ); | ||
} | ||
else { | ||
$checkedout_seats_count = ($total_seats_count - $available_seats_count); | ||
} | ||
Comment on lines
+253
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic feels like it should live on the model since there's a good chance we'll want to use it elsewhere in the future. We can avoid copy/pasting by moving it there. |
||
|
||
$this->authorize('view', $license); | ||
return view('licenses.view', compact('license')) | ||
->with('users_count', $users_count) | ||
->with('total_seats_count', $total_seats_count) | ||
->with('available_seats_count', $available_seats_count) | ||
->with('checkedout_seats_count', $checkedout_seats_count); | ||
->with('checkedout_seats_count', $checkedout_seats_count) | ||
->with('unreassignable_seats_count', $unreassignable_seats_count); | ||
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace App\Http\Transformers; | ||
|
||
use App\Models\Actionlog; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unused import can be removed. |
||
use App\Models\License; | ||
use App\Models\LicenseSeat; | ||
use Illuminate\Support\Facades\Gate; | ||
|
@@ -48,6 +49,7 @@ public function transformLicenseSeat(LicenseSeat $seat, $seat_count = 0) | |
'reassignable' => (bool) $seat->license->reassignable, | ||
'notes' => e($seat->notes), | ||
'user_can_checkout' => (($seat->assigned_to == '') && ($seat->asset_id == '')), | ||
'disabled' => $seat->unreassignable_seat, | ||
]; | ||
|
||
if ($seat_count != 0) { | ||
|
@@ -66,4 +68,17 @@ public function transformLicenseSeat(LicenseSeat $seat, $seat_count = 0) | |
|
||
return $array; | ||
} | ||
// private function unReassignable($seat) | ||
// { | ||
// if (!$seat->license->reassignable) { | ||
// $exists = Actionlog::where('action_type', '=', 'checkin from') | ||
// ->where('item_id', '=', $seat->license->id) | ||
// ->where('updated_at', '=', $seat->updated_at) | ||
// ->exists(); | ||
// if($exists) { | ||
// return true; | ||
// } | ||
// return false; | ||
// } | ||
// } | ||
Comment on lines
+71
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class LicensesTransformer | ||
class LicensesTransformer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extra space can be removed. |
||
{ | ||
public function transformLicenses(Collection $licenses, $total) | ||
{ | ||
|
@@ -37,7 +37,7 @@ public function transformLicense(License $license) | |
'notes' => Helper::parseEscapedMarkedownInline($license->notes), | ||
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), | ||
'seats' => (int) $license->seats, | ||
'free_seats_count' => (int) $license->free_seats_count, | ||
'free_seats_count' => (int) $license->free_seats_count - Helper::unReassignableCount($license), | ||
'min_amt' => ($license->min_amt) ? (int) ($license->min_amt) : null, | ||
'license_name' => ($license->license_name) ? e($license->license_name) : null, | ||
'license_email' => ($license->license_email) ? e($license->license_email) : null, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to use proper casts more. Can we add |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
namespace App\Models\LicenseSeat; | ||
use App\Models\LicenseSeat; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unused import can be removed. |
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unused import can be removed. |
||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('license_seats', function (Blueprint $table) { | ||
$table->addColumn('boolean', 'unreassignable_seat')->default(false)->after('assigned_to'); | ||
}); | ||
} | ||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('license_seats', function (Blueprint $table) { | ||
$table->dropColumn('unreassignable_seat'); | ||
}); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused and can be removed.