mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixed #6013 - add accessory checkout notes to detail page
This commit is contained in:
parent
400913631c
commit
b1b5eeecba
|
@ -136,14 +136,16 @@ class AccessoriesController extends Controller
|
|||
{
|
||||
$this->authorize('view', Accessory::class);
|
||||
|
||||
$accessory = Accessory::findOrFail($id);
|
||||
$accessory = Accessory::with('lastCheckout')->findOrFail($id);
|
||||
if (!Company::isCurrentUserHasAccess($accessory)) {
|
||||
return ['total' => 0, 'rows' => []];
|
||||
}
|
||||
|
||||
$accessory->lastCheckoutArray = $accessory->lastCheckout->toArray();
|
||||
$accessory_users = $accessory->users;
|
||||
$total = $accessory_users->count();
|
||||
|
||||
return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory_users, $total);
|
||||
return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $accessory_users, $total);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class AccessoriesTransformer
|
|||
}
|
||||
|
||||
|
||||
public function transformCheckedoutAccessory ($accessory_users, $total)
|
||||
public function transformCheckedoutAccessory ($accessory, $accessory_users, $total)
|
||||
{
|
||||
|
||||
|
||||
|
@ -75,6 +75,7 @@ class AccessoriesTransformer
|
|||
'first_name'=> e($user->first_name),
|
||||
'last_name'=> e($user->last_name),
|
||||
'employee_number' => e($user->employee_num),
|
||||
'checkout_notes' => $accessory->lastCheckoutArray[0]['note'],
|
||||
'type' => 'user',
|
||||
'available_actions' => ['checkin' => true]
|
||||
];
|
||||
|
|
|
@ -140,6 +140,39 @@ class Accessory extends SnipeModel
|
|||
return $this->hasMany('\App\Models\Actionlog', 'item_id')->where('item_type', Accessory::class)->orderBy('created_at', 'desc')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the LAST checkout for this accessory.
|
||||
*
|
||||
* This is kinda gross, but is necessary for how the accessory
|
||||
* pivot stuff works for now.
|
||||
*
|
||||
* It looks like we should be able to use ->first() here and
|
||||
* return an object instead of a collection, but we actually
|
||||
* cannot.
|
||||
*
|
||||
* In short, you cannot execute the query defined when you're eager loading.
|
||||
* and in order to avoid 1001 query problems when displaying the most
|
||||
* recent checkout note, we have to eager load this.
|
||||
*
|
||||
* This means we technically return a collection of one here, and then
|
||||
* in the controller, we convert that collection to an array, so we can
|
||||
* use it in the transformer to display only the notes of the LAST
|
||||
* checkout.
|
||||
*
|
||||
* It's super-mega-assy, but it's the best I could do for now.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v5.0.0
|
||||
*
|
||||
* @see \App\Http\Controllers\Api\AccessoriesController\checkedout()
|
||||
*
|
||||
*/
|
||||
public function lastCheckout()
|
||||
{
|
||||
return $this->assetlog()->where('action_type','=','checkout')->take(1);
|
||||
}
|
||||
|
||||
|
||||
public function getImageUrl() {
|
||||
if ($this->image) {
|
||||
return url('/').'/uploads/accessories/'.$this->image;
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th data-searchable="false" data-formatter="usersLinkFormatter" data-sortable="false" data-field="name">{{ trans('general.user') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="checkout_notes">{{ trans('general.notes') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="actions" data-formatter="accessoriesInOutFormatter">{{ trans('table.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
Loading…
Reference in a new issue