Esempio n. 1
0
 /**
  * Check authorization and display admin dashboard, otherwise display
  * the user's checked-out assets.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.0]
  * @return View
  */
 public function getIndex()
 {
     // Show the page
     if (Auth::user()->hasAccess('admin')) {
         $recent_activity = Actionlog::orderBy('created_at', 'DESC')->with('accessorylog', 'consumablelog', 'licenselog', 'assetlog', 'adminlog', 'userlog', 'componentlog')->take(30)->get();
         $asset_stats['total'] = Asset::Hardware()->count();
         $asset_stats['rtd']['total'] = Asset::Hardware()->RTD()->count();
         if ($asset_stats['rtd']['total'] > 0) {
             $asset_stats['rtd']['percent'] = round($asset_stats['rtd']['total'] / $asset_stats['total'] * 100);
         } else {
             $asset_stats['rtd']['percent'] = 0;
         }
         $asset_stats['pending']['total'] = Asset::Hardware()->Pending()->count();
         if ($asset_stats['pending']['total'] > 0) {
             $asset_stats['pending']['percent'] = round($asset_stats['pending']['total'] / $asset_stats['total'] * 100);
         } else {
             $asset_stats['pending']['percent'] = 0;
         }
         $asset_stats['deployed']['total'] = Asset::Hardware()->Deployed()->count();
         if ($asset_stats['deployed']['total'] > 0) {
             $asset_stats['deployed']['percent'] = round($asset_stats['deployed']['total'] / $asset_stats['total'] * 100);
         } else {
             $asset_stats['deployed']['percent'] = 0;
         }
         $asset_stats['undeployable']['total'] = Asset::Hardware()->Undeployable()->count();
         if ($asset_stats['undeployable']['total'] > 0) {
             $asset_stats['undeployable']['percent'] = round($asset_stats['undeployable']['total'] / $asset_stats['total'] * 100);
         } else {
             $asset_stats['undeployable']['percent'] = 0;
         }
         $asset_stats['archived']['total'] = Asset::Hardware()->Archived()->count();
         if ($asset_stats['archived']['total'] > 0) {
             $asset_stats['archived']['percent'] = round($asset_stats['archived']['total'] / $asset_stats['total'] * 100);
         } else {
             $asset_stats['archived']['percent'] = 0;
         }
         return View::make('dashboard')->with('asset_stats', $asset_stats)->with('recent_activity', $recent_activity);
     } else {
         // Redirect to the profile page
         return redirect()->route('view-assets');
     }
 }
Esempio n. 2
0
 public function createLogRecord($action, $asset, $admin, $user, $expected_checkin = null, $note = null, $checkout_at = null)
 {
     $logaction = new Actionlog();
     $logaction->asset_id = $this->id;
     $logaction->checkedout_to = $this->assigned_to;
     $logaction->asset_type = 'hardware';
     $logaction->note = $note;
     if ($checkout_at != '') {
         $logaction->created_at = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s', strtotime($checkout_at)));
     } else {
         $logaction->created_at = \Carbon\Carbon::now();
     }
     if ($action == "checkout") {
         if ($user) {
             $logaction->location_id = $user->location_id;
         }
     } else {
         // Update the asset data to null, since it's being checked in
         $logaction->checkedout_to = $asset->assigned_to;
         $logaction->checkedout_to = '';
         $logaction->asset_id = $asset->id;
         $logaction->location_id = null;
         $logaction->asset_type = 'hardware';
         $logaction->note = $note;
         $logaction->user_id = $admin->id;
     }
     $logaction->adminlog()->associate($admin);
     $log = $logaction->logaction($action);
     return $logaction;
 }
Esempio n. 3
0
 /**
  * Save bulk deleted.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param  array  $assets
  * @since [v2.0]
  * @return View
  */
 public function postBulkDelete($assets = null)
 {
     if (!Company::isCurrentUserAuthorized()) {
         return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
     } elseif (Input::has('bulk_edit')) {
         //$assets = Input::get('bulk_edit');
         $assets = Asset::find(Input::get('bulk_edit'));
         //print_r($assets);
         foreach ($assets as $asset) {
             //echo '<li>'.$asset;
             $update_array['deleted_at'] = date('Y-m-d h:i:s');
             $update_array['assigned_to'] = null;
             if (DB::table('assets')->where('id', $asset->id)->update($update_array)) {
                 $logaction = new Actionlog();
                 $logaction->asset_id = $asset->id;
                 $logaction->asset_type = 'hardware';
                 $logaction->created_at = date("Y-m-d H:i:s");
                 $logaction->user_id = Auth::user()->id;
                 $log = $logaction->logaction('deleted');
             }
         }
         // endforeach
         return redirect()->to("hardware")->with('success', trans('admin/hardware/message.delete.success'));
         // no values given, nothing to update
     } else {
         return redirect()->to("hardware")->with('info', trans('admin/hardware/message.delete.nothing_updated'));
     }
     // Something weird happened here - default to hardware
     return redirect()->to("hardware");
 }
 /**
  * Saves the checkout information
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ConsumablesController::getCheckout() method that returns the form.
  * @since [v1.0]
  * @param int $consumableId
  * @return Redirect
  */
 public function postCheckout($consumableId)
 {
     // Check if the consumable exists
     if (is_null($consumable = Consumable::find($consumableId))) {
         // Redirect to the consumable management page with error
         return redirect()->to('consumables')->with('error', trans('admin/consumables/message.not_found'));
     } elseif (!Company::isCurrentUserHasAccess($consumable)) {
         return redirect()->to('admin/consumables')->with('error', trans('general.insufficient_permissions'));
     }
     $admin_user = Auth::user();
     $assigned_to = e(Input::get('assigned_to'));
     // Check if the user exists
     if (is_null($user = User::find($assigned_to))) {
         // Redirect to the consumable management page with error
         return redirect()->to('admin/consumables')->with('error', trans('admin/consumables/message.user_does_not_exist'));
     }
     // Update the consumable data
     $consumable->assigned_to = e(Input::get('assigned_to'));
     $consumable->users()->attach($consumable->id, array('consumable_id' => $consumable->id, 'user_id' => $admin_user->id, 'assigned_to' => e(Input::get('assigned_to'))));
     $logaction = new Actionlog();
     $logaction->consumable_id = $consumable->id;
     $logaction->checkedout_to = $consumable->assigned_to;
     $logaction->asset_type = 'consumable';
     $logaction->asset_id = 0;
     $logaction->location_id = $user->location_id;
     $logaction->user_id = Auth::user()->id;
     $logaction->note = e(Input::get('note'));
     $settings = Setting::getSettings();
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/consumables/' . $consumable->id . '/view' . '|' . $consumable->name . '> checked out to <' . config('app.url') . '/admin/users/' . $user->id . '/view|' . $user->fullName() . '> by <' . config('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Consumable Checked Out');
         } catch (Exception $e) {
         }
     }
     $log = $logaction->logaction('checkout');
     $consumable_user = DB::table('consumables_users')->where('assigned_to', '=', $consumable->assigned_to)->where('consumable_id', '=', $consumable->id)->first();
     $data['log_id'] = $logaction->id;
     $data['eula'] = $consumable->getEula();
     $data['first_name'] = $user->first_name;
     $data['item_name'] = $consumable->name;
     $data['checkout_date'] = $logaction->created_at;
     $data['note'] = $logaction->note;
     $data['require_acceptance'] = $consumable->requireAcceptance();
     if ($consumable->requireAcceptance() == '1' || $consumable->getEula()) {
         Mail::send('emails.accept-asset', $data, function ($m) use($user) {
             $m->to($user->email, $user->first_name . ' ' . $user->last_name);
             $m->subject('Confirm consumable delivery');
         });
     }
     // Redirect to the new consumable page
     return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.checkout.success'));
 }
Esempio n. 5
0
 /**
  * exportAssetAcceptanceReport
  *
  * @return \Illuminate\Http\Response
  * @author  Vincent Sposato <*****@*****.**>
  * @version v1.0
  */
 public function exportAssetAcceptanceReport()
 {
     // Grab all the improvements
     $assetsForReport = Actionlog::whereIn('id', $this->getAssetsNotAcceptedYet())->get();
     $rows = [];
     $header = [trans('general.category'), trans('admin/hardware/form.model'), trans('admin/hardware/form.name'), trans('admin/hardware/table.asset_tag'), trans('admin/hardware/table.checkoutto')];
     $header = array_map('trim', $header);
     $rows[] = implode($header, ',');
     foreach ($assetsForReport as $assetItem) {
         $row = [];
         $row[] = str_replace(',', '', e($assetItem->assetlog->model->category->name));
         $row[] = str_replace(',', '', e($assetItem->assetlog->model->name));
         $row[] = str_replace(',', '', e($assetItem->assetlog->showAssetName()));
         $row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag));
         $row[] = str_replace(',', '', e($assetItem->assetlog->assigneduser->fullName()));
         $rows[] = implode($row, ',');
     }
     // spit out a csv
     $csv = implode($rows, "\n");
     $response = Response::make($csv, 200);
     $response->header('Content-Type', 'text/csv');
     $response->header('Content-disposition', 'attachment;filename=report.csv');
     return $response;
 }
Esempio n. 6
0
 /**
  * Validate and store checkout data.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see ComponentsController::getCheckout() method that returns the form.
  * @since [v3.0]
  * @param int $componentId
  * @return Redirect
  */
 public function postCheckout(Request $request, $componentId)
 {
     // Check if the component exists
     if (is_null($component = Component::find($componentId))) {
         // Redirect to the component management page with error
         return redirect()->to('components')->with('error', trans('admin/components/message.not_found'));
     } elseif (!Company::isCurrentUserHasAccess($component)) {
         return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions'));
     }
     $max_to_checkout = $component->numRemaining();
     $validator = Validator::make($request->all(), ["asset_id" => "required", "assigned_qty" => "required|numeric|between:1,{$max_to_checkout}"]);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $admin_user = Auth::user();
     $asset_id = e(Input::get('asset_id'));
     // Check if the user exists
     if (is_null($asset = Asset::find($asset_id))) {
         // Redirect to the component management page with error
         return redirect()->to('admin/components')->with('error', trans('admin/components/message.asset_does_not_exist'));
     }
     // Update the component data
     $component->asset_id = $asset_id;
     $component->assets()->attach($component->id, array('component_id' => $component->id, 'user_id' => $admin_user->id, 'created_at' => date('Y-m-d h:i:s'), 'assigned_qty' => e(Input::get('assigned_qty')), 'asset_id' => $asset_id));
     $logaction = new Actionlog();
     $logaction->component_id = $component->id;
     $logaction->asset_id = $asset_id;
     $logaction->asset_type = 'component';
     $logaction->location_id = $asset->location_id;
     $logaction->user_id = Auth::user()->id;
     $logaction->note = e(Input::get('note'));
     $settings = Setting::getSettings();
     if ($settings->slack_endpoint) {
         $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true];
         $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
         try {
             $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/components/' . $component->id . '/view' . '|' . $component->name . '> checked out to <' . config('app.url') . '/hardware/' . $asset->id . '/view|' . $asset->showAssetName() . '> by <' . config('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Component Checked Out');
         } catch (Exception $e) {
         }
     }
     $log = $logaction->logaction('checkout');
     // Redirect to the new component page
     return redirect()->to("admin/components")->with('success', trans('admin/components/message.checkout.success'));
 }
Esempio n. 7
0
 /**
  * Allows the selected file to be viewed.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.4]
  * @param int $licenseId
  * @param int $fileId
  * @return Redirect
  */
 public function displayFile($licenseId = null, $fileId = null)
 {
     $license = License::find($licenseId);
     // the license is valid
     if (isset($license->id)) {
         if (!Company::isCurrentUserHasAccess($license)) {
             return redirect()->to('admin/licenses')->with('error', trans('general.insufficient_permissions'));
         }
         $log = Actionlog::find($fileId);
         $file = $log->get_src('licenses');
         return Response::download($file);
     } else {
         // Prepare the error message
         $error = trans('admin/licenses/message.does_not_exist', compact('id'));
         // Redirect to the licence management page
         return redirect()->route('licenses')->with('error', $error);
     }
 }
 /**
  * Check in the item so that it can be checked out again to someone else
  *
  * @uses Accessory::checkin_email() to determine if an email can and should be sent
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param  int  $accessoryId
  * @return Redirect
  **/
 public function postCheckin(Request $request, $accessoryUserId = null, $backto = null)
 {
     // Check if the accessory exists
     if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
         // Redirect to the accessory management page with error
         return redirect()->to('admin/accessories')->with('error', trans('admin/accessories/message.not_found'));
     }
     $accessory = Accessory::find($accessory_user->accessory_id);
     if (!Company::isCurrentUserHasAccess($accessory)) {
         return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
     }
     $logaction = new Actionlog();
     $logaction->checkedout_to = e($accessory_user->assigned_to);
     $return_to = e($accessory_user->assigned_to);
     $admin_user = Auth::user();
     // Was the accessory updated?
     if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
         $logaction->accessory_id = e($accessory->id);
         $logaction->location_id = null;
         $logaction->asset_type = 'accessory';
         $logaction->user_id = e($admin_user->id);
         $logaction->note = e(Input::get('note'));
         $settings = Setting::getSettings();
         if ($settings->slack_endpoint) {
             $slack_settings = ['username' => e($settings->botname), 'channel' => e($settings->slack_channel), 'link_names' => true];
             $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
             try {
                 $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked In:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/accessories/' . e($accessory->id) . '/view' . '|' . e($accessory->name) . '> checked in by <' . config('app.url') . '/admin/users/' . e($admin_user->id) . '/view' . '|' . e($admin_user->fullName()) . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Accessory Checked In');
             } catch (Exception $e) {
             }
         }
         $log = $logaction->logaction('checkin from');
         if (!is_null($accessory_user->assigned_to)) {
             $user = User::find($accessory_user->assigned_to);
         }
         $data['log_id'] = $logaction->id;
         $data['first_name'] = e($user->first_name);
         $data['item_name'] = e($accessory->name);
         $data['checkin_date'] = e($logaction->created_at);
         $data['item_tag'] = '';
         $data['note'] = e($logaction->note);
         if ($accessory->checkin_email() == '1') {
             Mail::send('emails.checkin-asset', $data, function ($m) use($user) {
                 $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                 $m->subject('Confirm Accessory Checkin');
             });
         }
         if ($backto == 'user') {
             return redirect()->to("admin/users/" . $return_to . '/view')->with('success', trans('admin/accessories/message.checkin.success'));
         } else {
             return redirect()->to("admin/accessories/" . $accessory->id . "/view")->with('success', trans('admin/accessories/message.checkin.success'));
         }
     }
     // Redirect to the accessory management page with error
     return redirect()->to("admin/accessories")->with('error', trans('admin/accessories/message.checkin.error'));
 }
Esempio n. 9
0
 public function run()
 {
     Actionlog::truncate();
     factory(Actionlog::class, 'asset-checkout', 5)->create();
 }
Esempio n. 10
0
 public function postAcceptAsset($logID = null)
 {
     // Check if the asset exists
     if (is_null($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) {
         // Redirect to the asset management page
         return redirect()->to('account/view-assets')->with('error', trans('admin/hardware/message.does_not_exist'));
     }
     if ($findlog->accepted_id != '') {
         // Redirect to the asset management page
         return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.asset_already_accepted'));
     }
     if (!Input::has('asset_acceptance')) {
         return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.accept_or_decline'));
     }
     $user = Auth::user();
     if ($user->id != $findlog->checkedout_to) {
         return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
     }
     $logaction = new Actionlog();
     if (Input::get('asset_acceptance') == 'accepted') {
         $logaction_msg = 'accepted';
         $accepted = "accepted";
         $return_msg = trans('admin/users/message.accepted');
     } else {
         $logaction_msg = 'declined';
         $accepted = "rejected";
         $return_msg = trans('admin/users/message.declined');
     }
     // Asset
     if ($findlog->asset_id != '' && $findlog->asset_type == 'hardware') {
         $logaction->asset_id = $findlog->asset_id;
         $logaction->accessory_id = null;
         $logaction->asset_type = 'hardware';
         if (Input::get('asset_acceptance') != 'accepted') {
             DB::table('assets')->where('id', $findlog->asset_id)->update(array('assigned_to' => null));
         }
         // software
     } elseif ($findlog->asset_id != '' && $findlog->asset_type == 'software') {
         $logaction->asset_id = $findlog->asset_id;
         $logaction->accessory_id = null;
         $logaction->component_id = null;
         $logaction->asset_type = 'software';
         // accessories
     } elseif ($findlog->accessory_id != '') {
         $logaction->asset_id = null;
         $logaction->component_id = null;
         $logaction->accessory_id = $findlog->accessory_id;
         $logaction->asset_type = 'accessory';
         // accessories
     } elseif ($findlog->consumable_id != '') {
         $logaction->asset_id = null;
         $logaction->accessory_id = null;
         $logaction->component_id = null;
         $logaction->consumable_id = $findlog->consumable_id;
         $logaction->asset_type = 'consumable';
     } elseif ($findlog->component_id != '') {
         $logaction->asset_id = null;
         $logaction->accessory_id = null;
         $logaction->consumable_id = null;
         $logaction->component_id = $findlog->component_id;
         $logaction->asset_type = 'component';
     }
     $logaction->checkedout_to = $findlog->checkedout_to;
     $logaction->note = e(Input::get('note'));
     $logaction->user_id = $user->id;
     $logaction->accepted_at = date("Y-m-d h:i:s");
     $log = $logaction->logaction($logaction_msg);
     $update_checkout = DB::table('asset_logs')->where('id', $findlog->id)->update(array('accepted_id' => $logaction->id));
     $affected_asset = $logaction->assetlog;
     $affected_asset->accepted = $accepted;
     $affected_asset->save();
     if ($update_checkout) {
         return redirect()->to('account/view-assets')->with('success', $return_msg);
     } else {
         return redirect()->to('account/view-assets')->with('error', 'Something went wrong ');
     }
 }
 /**
  * updateAssetLogWithThreadInformation
  *
  * @param $assetLog
  *
  * @author  Vincent Sposato <*****@*****.**>
  * @version v1.0
  */
 protected function updateAssetLogWithThreadInformation($assetLog)
 {
     $loadedAssetLog = Actionlog::find($assetLog->id);
     $loadedAssetLog->thread_id = $this->currentAssetLogId;
     $loadedAssetLog->update();
     unset($loadedAssetLog);
 }