예제 #1
0
 public function edit($id)
 {
     $request = Request::with(['equipment', 'area', 'location', 'category', 'uploads', 'approvers', 'status', 'actions' => function ($query) {
         $query->orderBy('created_at', 'desc');
     }, 'actions.submitted', 'comments.author' => function ($query) {
         $query->orderBy('created_at', 'asc');
     }])->find($id);
     if (is_null($request)) {
         return view('security.not-found');
     }
     $data['request'] = $request;
     $data['areas'] = Area::all(['id', 'name']);
     $data['organizations'] = Organization::all();
     $data['categories'] = Category::all(['id', 'name']);
     $data['locations'] = Location::all(['id', 'name']);
     $data['approvers'] = Approval::getRecent($id);
     $data['hasApproved'] = Approval::hasApproved($id)->exists();
     if ($request->Status->name == 'Approved') {
         return view('request.view', $data);
     }
     if ($request->submitted_by != Auth::User()->id && !Auth::User()->hasRole(['administrator', 'approver'])) {
         return view('security.401');
     }
     return view('request.edit', $data);
 }
예제 #2
0
 public function reject($id, Request $request)
 {
     if (!Approval::hasApproved($id)->exists()) {
         $current = Approval::create(['request_id' => $id, 'user_id' => Auth::User()->id, 'organization_id' => Auth::User()->organization_id, 'approved_offline' => $request->input('approved-offline'), 'comment' => $request->input('comments'), 'choice' => 'Reject']);
         $submittal = \App\Request::find($id);
         $approvals = Approval::getRecent($id);
         $status = array('Approve' => 0, 'Reject' => 0);
         foreach ($approvals as $approval) {
             $status[$approval->choice]++;
         }
         $json = $this->updateStatus($submittal, $status);
         return json_encode($json);
     } else {
         $json = array('error' => true, 'message' => 'You have already approved this request.');
     }
 }