Skip to content
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

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

Godmartinz
Copy link
Collaborator

@Godmartinz Godmartinz commented Jan 13, 2025

This adds the ability to check in unreassignable licenses.
When a seat is checked in, the seat is disabled and a default note of Seat has been used. will be added in addition to any other note entered.
On check in of a unreassignable license the seat is marked dead and also will not be allowed to be checked out via the API.

image The available seat count is also updated accordingly on the seats tab, the index page, and the licenses reports. image image API attempt to checkout an unreassignable: image

[sc-14999]

Copy link

what-the-diff bot commented Jan 13, 2025

PR Summary

  • Introduction of New Model References
    Imported Actionlog and LicenseSeat models into the Helper.php file to allow for advanced functionality.

  • Addition of New Method
    Created a new method unReassignableCount($license) in Helper.php that tallies up the number of licenses that can't be reassigned.

  • Revised LicenseCheckinController:

    • Altered the license check-in control, removing the need to check if a license is reassignable before checking-in.
    • Enhanced the note-keeping for licenses that can't be reassigned, allowing for more accurate record-keeping during the check-in process.
    • Changed how events are initiated to consider the revised notes.
  • Upgraded LicensesController:

    • Refactored computation of checkedout_seats_count to consider licenses that can't be reassigned.
    • Following this, unreassignable_seats_count is sent for viewing.
  • Transformation of LicenseSeatsTransformer:

    • Incorporated a new method unReassignable($seat) to verify if a seat is non-reassignable.
    • Altered the transformation output to feature a 'disabled' field.
  • Modification of LicensesTransformer:

    • Tweaked the computation of free_seats_count to deduct the count of unReassignable licenses.
  • Revision of License Model:

    • Altered remaincount() to subtract unreassignable licenses, providing a more accurate count of available licenses.
  • Upgraded Blade Templates:

    • Optimized the licenses' view to display available license count subject to unreassignable seats.
    • Updated the interaction with the check-in button when a seat is disabled as depicted in bootstrap-table.
  • Language Files Update:

    • Enhanced clarity by updating the message for non-reassignable licenses to 'Seat has been used' instead.

@Godmartinz
Copy link
Collaborator Author

disabled button color has been fixed 👍

@Godmartinz
Copy link
Collaborator Author

looking into failing tests

@Godmartinz Godmartinz marked this pull request as draft January 14, 2025 20:24
@Godmartinz Godmartinz marked this pull request as ready for review January 16, 2025 19:53
@snipe
Copy link
Owner

snipe commented Jan 16, 2025

Not sure I love the field dead for this.

@snipe
Copy link
Owner

snipe commented Jan 16, 2025

(Also, tests are failing)

@marcusmoore
Copy link
Collaborator

Not sure I love the field dead for this.

😆 @Godmartinz and I were going back and forth on how best to communicate what the column represents.

@snipe
Copy link
Owner

snipe commented Jan 16, 2025

@marcusmoore - unassignable would probably work fine, but I'd probably return a true or false if it's meant to be boolean. Or reverse the logic and use reassignable.

@marcusmoore
Copy link
Collaborator

@snipe we (me really) were trying to avoid confusion around a license seat having assigned_to and unassignable (or a similar word) both be populated at the same time. That really threw me off and I wanted to find another word to signify "this seat might be checked out now but it cannot be checked out again in the future".

Maybe other devs won't find that as confusing as I did.

@snipe
Copy link
Owner

snipe commented Jan 16, 2025

@marcusmoore reassignable_seat perhaps?

@marcusmoore
Copy link
Collaborator

marcusmoore commented Jan 16, 2025

@snipe that would be a lot clearer for me. Though I would go with reassignable so we don't have a redundant word in there $licenseSeat-> reassignable_seat // @Godmartinz

@Godmartinz Godmartinz requested a review from snipe January 16, 2025 20:29
Copy link
Collaborator

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bones are solid but I think there is some improvements that can be made.

@@ -2,13 +2,15 @@

namespace App\Helpers;
use App\Models\Accessory;
use App\Models\Actionlog;
Copy link
Collaborator

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.

Comment on lines +1534 to +1543
public static function unReassignableCount($license)
{

if (!$license->reassignable) {
$count = LicenseSeat::where('unreassignable_seat', '=', true)
->where('license_id', '=', $license->id)
->count();
return $count;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

@@ -0,0 +1,29 @@
<?php
namespace App\Models\LicenseSeat;
use App\Models\LicenseSeat;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unused import can be removed.

use App\Models\LicenseSeat;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unused import can be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to use proper casts more. Can we add $casts and set unreassignable_seat to be a boolean?

@@ -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') . '.';
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Comment on lines +253 to +259
$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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Comment on lines +71 to +83
// 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;
// }
// }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

@@ -2,6 +2,7 @@

namespace App\Http\Transformers;

use App\Models\Actionlog;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unused import can be removed.

@@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;

class LicensesTransformer
class LicensesTransformer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra space can be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants