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); }
public function show($slug) { $data['requests'] = \App\Request::with('status', 'equipment')->requestStatusSlug($slug)->get(); return view('approval.index', $data); }
public function averageToApprove($start, $end) { $columns = ['id', 'status_id', 'requested_on']; //$lccb = \App\Request::with('Approvers')->where('status_id', 5)->whereBetween('created_at', [$start, $end])->get($columns); $lccb = \App\Request::with('Approvers')->where('status_id', 5)->whereBetween('requested_on', [$start, $end])->get($columns); // $test = DB::table('requests')->select(DB::raw( // 'AVG(TIMESTAMPDIFF(SECOND, // requested_on, // contactdatetimecomplete) // ) AS average')); $statistics = DB::table('requests')->select(DB::raw("COUNT(status_id) AS total"), DB::raw("SUM(CASE WHEN status_id = 1 THEN 1 ELSE 0 END) AS new"), DB::raw("SUM(CASE WHEN status_id = 2 THEN 1 ELSE 0 END) AS open"), DB::raw("SUM(CASE WHEN status_id = 3 THEN 1 ELSE 0 END) AS waiting"), DB::raw("SUM(CASE WHEN status_id = 4 THEN 1 ELSE 0 END) AS rejected"), DB::raw("SUM(CASE WHEN status_id = 5 THEN 1 ELSE 0 END) AS approved"))->whereNull('deleted_at')->whereRaw("requested_on BETWEEN DATE_SUB('" . $start . "', INTERVAL 1 DAY) AND DATE_ADD('" . $end . "', INTERVAL 1 DAY)")->get(); $json['stats'] = $statistics; if ($lccb->isEmpty()) { $json['average'] = ['status' => 'error', 'title' => 'Error', 'message' => 'Nothing was approved in this date range!']; return $json; } $total = 0; $count = 0; foreach ($lccb as $calculate) { //echo $calculate->requested_on."<br>"; $lccbDate = new Carbon($calculate->requested_on); foreach ($calculate->approvers as $approval) { $date[] = new Carbon($approval->created_at); } $max = $date[0]->max($date[1]); //$max = Carbon::parse('2015-08-10'); $diff = $max->diffInSeconds($lccbDate); $total += $diff; $count++; unset($date); } //echo "total time: ".$total; //echo "total count: ".$count; $time = $total / $count; $days = floor($time / (60 * 60 * 24)); $time -= $days * (60 * 60 * 24); $hours = floor($time / (60 * 60)); $time -= $hours * (60 * 60); $minutes = floor($time / 60); $time -= $minutes * 60; $seconds = floor($time); $time -= $seconds; $json['average'] = array('status' => 'success', 'message' => "<p class='lead'>{$days}d {$hours}h {$minutes}m {$seconds}s</p>"); return $json; }
public function build($start, $end) { return Request::with('comments')->select(['requests.description', 'requests.id', 'o.name AS organization', 'e.name AS equipment', 'cat.name AS category', 'requests.requester_name AS requester', 'status.name AS status', 'requests.layout_updated', 'requests.design_updated', 'requests.mw_updated'])->join('organizations AS o', 'o.id', '=', 'requests.organization_id')->join('equipment AS e', 'e.id', '=', 'requests.equipment_id')->join('categories AS cat', 'cat.id', '=', 'requests.category_id')->join('status AS status', 'status.id', '=', 'requests.status_id')->whereBetween('requests.requested_on', [$start, $end])->whereNull('requests.deleted_at')->get(); }
public function myRequests() { $data['requests'] = Request::with('Requester', 'Location', 'Equipment', 'Category', 'Area', 'Uploads', 'Status')->user()->get()->toArray(); return view('user.myRequests', $data); }