Exemplo n.º 1
0
 /**
  * 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'));
 }
Exemplo n.º 2
0
 public function getAcceptAsset($logID = null)
 {
     if (!($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) {
         echo 'no record';
         //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     }
     $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'));
     }
     // Asset
     if ($findlog->asset_id != '' && $findlog->asset_type == 'hardware') {
         $item = Asset::find($findlog->asset_id);
         // software
     } elseif ($findlog->asset_id != '' && $findlog->asset_type == 'software') {
         $item = License::find($findlog->asset_id);
         // accessories
     } elseif ($findlog->accessory_id != '') {
         $item = Accessory::find($findlog->accessory_id);
         // consumable
     } elseif ($findlog->consumable_id != '') {
         $item = Consumable::find($findlog->consumable_id);
         // components
     } elseif ($findlog->component_id != '') {
         $item = Component::find($findlog->component_id);
     }
     // Check if the asset exists
     if (is_null($item)) {
         // Redirect to the asset management page
         return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
     } elseif (!Company::isCurrentUserHasAccess($item)) {
         return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions'));
     } else {
         return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog);
     }
 }