39 $user = User::with(
'assets',
'assets.model',
'consumables',
'accessories',
'licenses',
'userloc')->withTrashed()->find(Auth::user()->
id);
41 $userlog = $user->userlog->load(
'assetlog',
'consumablelog',
'assetlog.model',
'licenselog',
'accessorylog',
'userlog',
'adminlog');
45 if (isset($user->id)) {
46 return View::make(
'account/view-assets', compact(
'user',
'userlog'));
49 $error = trans(
'admin/users/message.user_not_found', compact(
'id'));
52 return Redirect::route(
'users')->with(
'error', $error);
61 $assets = Asset::with(
'model',
'defaultLoc')->Hardware()->RequestableAssets()->get();
63 return View::make(
'account/requestable-assets', compact(
'user',
'assets'));
73 if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
75 return Redirect::route(
'requestable-assets')->with(
'error', trans(
'admin/hardware/message.does_not_exist_or_not_requestable'));
77 return Redirect::route(
'requestable-assets')->with(
'error', trans(
'general.insufficient_permissions'));
81 $logaction->asset_id = $data[
'asset_id'] = $asset->id;
82 $logaction->asset_type = $data[
'asset_type'] =
'hardware';
83 $logaction->created_at = $data[
'requested_date'] = date(
"Y-m-d h:i:s");
85 if ($user->location_id) {
86 $logaction->location_id = $user->location_id;
88 $logaction->user_id = $data[
'user_id'] = Auth::user()->id;
89 $log = $logaction->logaction(
'requested');
91 $data[
'requested_by'] = $user->fullName();
92 $data[
'asset_name'] = $asset->showAssetName();
96 if (($settings->alert_email!=
'') && ($settings->alerts_enabled==
'1') && (!config(
'app.lock_passwords'))) {
97 Mail::send(
'emails.asset-requested', $data,
function ($m) use ($user, $settings) {
98 $m->to(explode(
',', $settings->alert_email), $settings->site_name);
99 $m->subject(
'Asset Requested');
104 if ($settings->slack_endpoint) {
108 'username' => $settings->botname,
109 'channel' => $settings->slack_channel,
113 $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
120 'title' =>
'REQUESTED:',
121 'value' => strtoupper($logaction->asset_type).
' asset <'.config(
'app.url').
'/hardware/'.$asset->id.
'/view'.
'|'.$asset->showAssetName().
'> requested by <'.config(
'app.url').
'/hardware/'.$asset->id.
'/view'.
'|'.Auth::user()->fullName().
'>.' 125 ])->send(
'Asset Requested');
133 return Redirect::route(
'requestable-assets')->with(
'success')->with(
'success', trans(
'admin/hardware/message.requests.success'));
145 if (is_null($findlog = Actionlog::find($logID))) {
147 return Redirect::to(
'account')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
150 $user = Auth::user();
152 if ($user->id != $findlog->checkedout_to) {
153 return Redirect::to(
'account/view-assets')->with(
'error', trans(
'admin/users/message.error.incorrect_user_accepted'));
157 if (($findlog->asset_id!=
'') && ($findlog->asset_type==
'hardware')) {
158 $item = Asset::find($findlog->asset_id);
161 } elseif (($findlog->asset_id!=
'') && ($findlog->asset_type==
'software')) {
162 $item = License::find($findlog->asset_id);
164 } elseif ($findlog->accessory_id!=
'') {
165 $item = Accessory::find($findlog->accessory_id);
169 if (is_null($item)) {
171 return Redirect::to(
'account')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
173 return Redirect::route(
'requestable-assets')->with(
'error', trans(
'general.insufficient_permissions'));
175 return View::make(
'account/accept-asset', compact(
'item'))->with(
'findlog', $findlog);
184 if (is_null($findlog = Actionlog::find($logID))) {
186 return Redirect::to(
'account/view-assets')->with(
'error', trans(
'admin/hardware/message.does_not_exist'));
190 $is_unauthorized = is_null(Actionlog::where(
'id',
'=', $logID)->first());
191 if ($is_unauthorized) {
192 return Redirect::route(
'requestable-assets')->with(
'error', trans(
'general.insufficient_permissions'));
195 if ($findlog->accepted_id!=
'') {
197 return Redirect::to(
'account/view-assets')->with(
'error', trans(
'admin/users/message.error.asset_already_accepted'));
200 if (!Input::has(
'asset_acceptance')) {
201 return Redirect::to(
'account/view-assets')->with(
'error', trans(
'admin/users/message.error.accept_or_decline'));
204 $user = Auth::user();
206 if ($user->id != $findlog->checkedout_to) {
207 return Redirect::to(
'account/view-assets')->with(
'error', trans(
'admin/users/message.error.incorrect_user_accepted'));
212 if (Input::get(
'asset_acceptance')==
'accepted') {
213 $logaction_msg =
'accepted';
214 $accepted=
"accepted";
215 $return_msg = trans(
'admin/users/message.accepted');
217 $logaction_msg =
'declined';
218 $accepted=
"rejected";
219 $return_msg = trans(
'admin/users/message.declined');
223 if (($findlog->asset_id!=
'') && ($findlog->asset_type==
'hardware')) {
224 $logaction->asset_id = $findlog->asset_id;
225 $logaction->accessory_id = null;
226 $logaction->asset_type =
'hardware';
228 if (Input::get(
'asset_acceptance')!=
'accepted') {
230 ->where(
'id', $findlog->asset_id)
231 ->update(array(
'assigned_to' => null));
236 } elseif (($findlog->asset_id!=
'') && ($findlog->asset_type==
'software')) {
237 $logaction->asset_id = $findlog->asset_id;
238 $logaction->accessory_id = null;
239 $logaction->asset_type =
'software';
242 } elseif ($findlog->accessory_id!=
'') {
243 $logaction->asset_id = null;
244 $logaction->accessory_id = $findlog->accessory_id;
245 $logaction->asset_type =
'accessory';
248 $logaction->checkedout_to = $findlog->checkedout_to;
250 $logaction->note = e(Input::get(
'note'));
251 $logaction->user_id = $user->id;
252 $logaction->accepted_at = date(
"Y-m-d h:i:s");
253 $log = $logaction->logaction($logaction_msg);
255 $update_checkout = DB::table(
'asset_logs')
256 ->where(
'id', $findlog->id)
257 ->update(array(
'accepted_id' => $logaction->id));
259 $affected_asset=$logaction->assetlog;
260 $affected_asset->accepted=$accepted;
261 $affected_asset->save();
263 if ($update_checkout) {
264 return Redirect::to(
'account/view-assets')->with(
'success', $return_msg);
267 return Redirect::to(
'account/view-assets')->with(
'error',
'Something went wrong ');
This controller handles all actions related to the ability for users to view their own assets in the ...
Model for the Actionlog (the table that keeps a historical log of checkouts, checkins, and updates).
static isCurrentUserHasAccess($companyable)
getRequestAsset($assetId=null)
getIndex()
Redirect to the profile page.
getAcceptAsset($logID=null)
postAcceptAsset($logID=null)