2018-04-04 17:33:02 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2018-04-04 17:33:02 -07:00
|
|
|
use App\Http\Controllers\Controller;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Models\CheckoutRequest;
|
2018-04-04 17:33:02 -07:00
|
|
|
use Auth;
|
|
|
|
|
|
|
|
class ProfileController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of requested assets.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.3.0]
|
|
|
|
*
|
2021-06-10 13:15:52 -07:00
|
|
|
* @return array
|
2018-04-04 17:33:02 -07:00
|
|
|
*/
|
|
|
|
public function requestedAssets()
|
|
|
|
{
|
|
|
|
$checkoutRequests = CheckoutRequest::where('user_id', '=', Auth::user()->id)->get();
|
|
|
|
|
|
|
|
$results = [];
|
|
|
|
$results['total'] = $checkoutRequests->count();
|
|
|
|
|
|
|
|
foreach ($checkoutRequests as $checkoutRequest) {
|
2019-03-05 23:46:40 -08:00
|
|
|
|
|
|
|
// Make sure the asset and request still exist
|
|
|
|
if ($checkoutRequest && $checkoutRequest->itemRequested()) {
|
|
|
|
$results['rows'][] = [
|
2022-04-15 04:22:20 -07:00
|
|
|
'image' => e($checkoutRequest->itemRequested()->present()->getImageUrl()),
|
|
|
|
'name' => e($checkoutRequest->itemRequested()->present()->name()),
|
|
|
|
'type' => e($checkoutRequest->itemType()),
|
|
|
|
'qty' => (int) $checkoutRequest->quantity,
|
|
|
|
'location' => ($checkoutRequest->location()) ? e($checkoutRequest->location()->name) : null,
|
2019-03-05 23:46:40 -08:00
|
|
|
'expected_checkin' => Helper::getFormattedDateObject($checkoutRequest->itemRequested()->expected_checkin, 'datetime'),
|
|
|
|
'request_date' => Helper::getFormattedDateObject($checkoutRequest->created_at, 'datetime'),
|
|
|
|
];
|
|
|
|
}
|
2018-04-04 17:33:02 -07:00
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-04-04 17:33:02 -07:00
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
}
|