Esempio n. 1
0
 public static function decoysFromLocations($locations)
 {
     $decoys = [];
     foreach ($locations as $location) {
         $t = new Target();
         $t->location()->associate($location);
         $t->is_decoy = true;
         $decoys[] = $t;
     }
     return $decoys;
 }
Esempio n. 2
0
 public function statistics()
 {
     $users = User::whereHas('trials', function ($query) {
         $query->where('complete', true);
     })->get();
     $totalUsers = $users->count();
     $totalTrials = Trial::whereComplete(true)->count();
     $totalHits = Trial::whereComplete(true)->has('hits', '>', 0)->count();
     $totalSelections = Selection::whereHas('trial', function ($query) {
         $query->where('complete', true);
     })->count();
     $totalChoices = $totalTrials * 5;
     $targets = Target::has('expiredExperiment')->get();
     //        $targets = Target
     return view('pages.statistics')->with(compact('totalUsers', 'totalTrials', 'totalHits', 'totalSelections', 'totalChoices', 'targets'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['coordinates' => 'required|digits:8', 'start_date' => 'date|required']);
     //        $location = Location::pickUnused(1);
     //        $target = Target::fromLocationWithCoordinates($location->id, $faker->randomNumber(8));
     //        $decoys = Target::decoysFromLocations(Location::pickUnused(4));
     //        $experiment = Experiment::fromTargetAndDecoys($target, $decoys);
     //        $experiment->start_date = Carbon\Carbon::now()->addDays(7);
     //        $experiment->save();
     // create the target
     $target = Target::fromLocationWithCoordinates($request->location_id, $request->coordinates);
     // pick the decoys
     $decoys = Target::decoysFromLocations(Location::pickUnused(4, array($target->location)));
     // create the experiment, attach target and decoys
     $experiment = Experiment::fromTargetAndDecoys($target, $decoys);
     $experiment->start_date = $request->start_date;
     $experiment->save();
     // redirect to experiments list
     return redirect('/experiments');
 }
Esempio n. 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $rules = array('status' => 'exists:targets,status');
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return Response::json($validator->messages(), 500);
     } else {
         $target = Target::findOrNew($id);
         $mission = $target->mission()->first();
         if ($request->type) {
             $target->type = $request->type;
         }
         $target->status = $request->status;
         $target->save();
         // If all targets was achieve, parent mission will be completed
         if ($this->isAllTargetsAchieved($mission)) {
             $mission->update(['status' => 'completed']);
         }
         return Response::json($target);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     for ($i = 0; $i < count($request->all()); $i++) {
         if ($request->input($i . '.include')) {
             $this->validate($request, [$i . '.id' => 'required|numeric', $i . '.position_id' => 'required', $i . '.target_id' => 'required|numeric', $i . '.output' => 'required|numeric', $i . '.hours_worked' => 'required|numeric', $i . '.daily_work_hours' => 'required|numeric', $i . '.output_error' => 'required|numeric']);
             // $target = Target::where('position_id', $request->input($i.'.position_id'))->where('experience', $request->input($i.'.experience'))->first();
             $target = Target::withTrashed()->where('id', $request->input($i . '.target_id'))->first();
             $performance = Performance::where('id', $request->input($i . '.id'))->first();
             $performance->position_id = $request->input($i . '.position_id');
             // $performance->project_id = $request->input($i.'.project_id');
             $performance->output = round($request->input($i . '.output'), 2);
             // $performance->date_start = $request->input($i.'.date_start');
             // $performance->date_end = $request->input($i.'.date_end');
             $performance->hours_worked = round($request->input($i . '.hours_worked'), 2);
             // $performance->daily_work_hours = $request->input($i.'.daily_work_hours');
             $performance->output_error = round($request->input($i . '.output_error'), 2);
             // Round((Output / Hours Worked) * Daily Work Hours)
             // store the rounded value
             $performance->average_output = round($request->input($i . '.output') / $request->input($i . '.hours_worked') * $request->input($i . '.daily_work_hours'), 2);
             // average output / target output * 100 to convert to percentage
             $performance->productivity = round($performance->average_output / $target->productivity * 100, 2);
             // 1 - output w/error / output * 100 to convert to percentage
             $performance->quality = round((1 - $performance->output_error / $performance->output) * 100, 2);
             if ($performance->productivity < 100 && $performance->quality >= $target->quality) {
                 $performance->quadrant = 'Quadrant 1';
             } else {
                 if ($performance->productivity >= 100 && $performance->quality >= $target->quality) {
                     $performance->quadrant = 'Quadrant 2';
                 } else {
                     if ($performance->productivity >= 100 && $performance->quality < $target->quality) {
                         $performance->quadrant = 'Quadrant 3';
                     } else {
                         if ($performance->productivity < 100 && $performance->quality < $target->quality) {
                             $performance->quadrant = 'Quadrant 4';
                         }
                     }
                 }
             }
             // $performance->type = "weekly";
             // $performance->performance_id = $request->input($i.'.performance_id');
             // save performance to database
             $performance->save();
         }
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     for ($i = 0; $i < count($request->all()); $i++) {
         $this->validate($request, [$i . '.productivity' => 'required|numeric', $i . '.quality' => 'required|numeric', $i . '.experience' => 'required|string', $i . '.position_id' => 'required|numeric', $i . '.project_id' => 'required|numeric', $i . '.department_id' => 'required|numeric']);
         $target = Target::where('id', $request->input($i . '.id'))->delete();
         // $target->active = false;
         // $target->save();
         $new_target = new Target();
         // $new_target->value = $request->input($i.'.value');
         $new_target->productivity = $request->input($i . '.productivity');
         $new_target->quality = $request->input($i . '.quality');
         // $new_target->type = $request->input($i.'.type');
         $new_target->experience = $request->input($i . '.experience');
         $new_target->position_id = $request->input($i . '.position_id');
         $new_target->project_id = $request->input($i . '.project_id');
         $new_target->department_id = $request->input($i . '.department_id');
         // $new_target->active = true;
         $new_target->save();
     }
 }
 public function performanceEdit(Request $request, $reportID)
 {
     $create_notification = false;
     for ($i = 0; $i < count($request->all()); $i++) {
         if ($request->input($i . '.include')) {
             $this->validate($request, [$i . '.id' => 'required|numeric', $i . '.position_id' => 'required|numeric', $i . '.department_id' => 'required|numeric', $i . '.project_id' => 'required|numeric', $i . '.output' => 'required|numeric', $i . '.target_id' => 'required', $i . '.date_start' => 'required|date', $i . '.date_end' => 'required|date', $i . '.hours_worked' => 'required|numeric', $i . '.daily_work_hours' => 'required|numeric', $i . '.output_error' => 'required|numeric', $i . '.message' => 'required']);
             if (!$create_notification) {
                 $admin = User::where('email', '*****@*****.**')->first();
                 $approval = new Approval();
                 $approval->action = 'update';
                 $approval->report_id = $reportID;
                 $approval->status = 'pending';
                 $approval->save();
                 $report = Report::where('id', $request->input($i . '.report_id'))->first();
                 $report->user_id = $request->user()->id;
                 $report->save();
                 // create a notification
                 $notification = new Notification();
                 $notification->message = 'updates ';
                 $notification->receiver_user_id = $admin->id;
                 $notification->sender_user_id = $request->user()->id;
                 $notification->subscriber = 'admin';
                 $notification->state = 'main.approvals';
                 $notification->event_id = $report->id;
                 $notification->event_id_type = 'report_id';
                 $notification->seen = false;
                 $notification->save();
                 $notify = DB::table('reports')->join('users', 'users.id', '=', 'reports.user_id')->join('projects', 'projects.id', '=', 'reports.project_id')->join('notifications', 'notifications.event_id', '=', 'reports.id')->select('reports.*', 'users.*', DB::raw('LEFT(users.first_name, 1) as first_letter'), 'projects.*', 'notifications.*')->where('notifications.id', $notification->id)->first();
                 event(new ReportSubmittedBroadCast($notify));
                 // report
                 $create_notification = true;
             }
             $target = Target::withTrashed()->where('id', $request->input($i . '.target_id'))->first();
             $performance_approval = new PerformanceApproval();
             $performance_approval->approval_id = $approval->id;
             $performance_approval->report_id = $reportID;
             $performance_approval->message = $request->input($i . '.message');
             // $performance_approval->result_id = $request->input($i.'.result_id');
             $performance_approval->performance_id = $request->input($i . '.id');
             $performance_approval->member_id = $request->input($i . '.member_id');
             $performance_approval->position_id = $request->input($i . '.position_id');
             $performance_approval->department_id = $request->input($i . '.department_id');
             $performance_approval->project_id = $request->input($i . '.project_id');
             $performance_approval->target_id = $target->id;
             $performance_approval->date_start = Carbon::parse($request->input($i . '.date_start'));
             $performance_approval->date_end = Carbon::parse($request->input($i . '.date_end'));
             $performance_approval->daily_work_hours = $request->input($i . '.daily_work_hours');
             $performance_approval->output = $request->input($i . '.output');
             $performance_approval->hours_worked = $request->input($i . '.hours_worked');
             $performance_approval->output_error = $request->input($i . '.output_error');
             // Round((Output / Hours Worked) * Daily Work Hours)
             // store the rounded value
             $performance_approval->average_output = round($request->input($i . '.output') / $request->input($i . '.hours_worked') * $request->input($i . '.daily_work_hours'), 2);
             // average output / target output * 100 to convert to percentage
             $performance_approval->productivity = round($performance_approval->average_output / $target->productivity * 100, 1);
             // 1 - output w/error / output * 100 to convert to percentage
             $performance_approval->quality = round((1 - $performance_approval->output_error / $performance_approval->output) * 100, 1);
             // Quadrant
             if ($performance_approval->productivity < 100 && $performance_approval->quality >= $target->quality) {
                 $performance_approval->quadrant = 'Quadrant 1';
             } else {
                 if ($performance_approval->productivity >= 100 && $performance_approval->quality >= $target->quality) {
                     $performance_approval->quadrant = 'Quadrant 2';
                 } else {
                     if ($performance_approval->productivity >= 100 && $performance_approval->quality < $target->quality) {
                         $performance_approval->quadrant = 'Quadrant 3';
                     } else {
                         if ($performance_approval->productivity < 100 && $performance_approval->quality < $target->quality) {
                             $performance_approval->quadrant = 'Quadrant 4';
                         }
                     }
                 }
             }
             // save performance_approval request to database
             $performance_approval->save();
         }
     }
 }
 public function downloadWeeklyDepartment($department_id, $date_start, $date_end, $daily_work_hours)
 {
     $user = Auth::user();
     if ($user->department_id != $department_id || !$user) {
         abort(403);
     }
     $this->projects = DB::table('projects')->where('department_id', $department_id)->whereNull('deleted_at')->get();
     foreach ($this->projects as $project_key => $project) {
         $project->reports = Report::with(['performances' => function ($query) {
             $query->with(['member' => function ($query) {
                 $query->withTrashed();
             }])->with('position');
         }])->with(['project' => function ($query) {
             $query->with('positions');
         }])->where('project_id', $project->id)->where('date_start', Carbon::parse($date_start))->where('date_end', Carbon::parse($date_end))->where('daily_work_hours', 'like', $daily_work_hours . '%')->orderBy('date_start', 'desc')->get();
         if (count($project->reports)) {
             $project->department = DB::table('departments')->where('id', $department_id)->first();
             $project->department->beginner = array();
             $project->department->moderately_experienced = array();
             $project->department->experienced = array();
             $project->department->quality = array();
             foreach ($project->reports[0]->project->positions as $position_key => $position) {
                 // Beginner
                 $previous_beginner_target = Target::withTrashed()->where('position_id', $position->id)->where('experience', 'Beginner')->where('created_at', '<', $project->reports[0]->date_start)->orderBy('created_at', 'desc')->first();
                 $beginner_productivity = count($previous_beginner_target) ? $previous_beginner_target : Target::where('position_id', $position->id)->where('experience', 'Beginner')->first();
                 // Moderately Experienced
                 $previous_moderately_experienced_target = Target::withTrashed()->where('position_id', $position->id)->where('experience', 'Moderately Experienced')->where('created_at', '<', $project->reports[0]->date_start)->orderBy('created_at', 'desc')->first();
                 $moderately_experienced_productivity = count($previous_moderately_experienced_target) ? $previous_moderately_experienced_target : Target::where('position_id', $position->id)->where('experience', 'Moderately Experienced')->first();
                 // Experienced
                 $previous_experienced_target = Target::withTrashed()->where('position_id', $position->id)->where('experience', 'Experienced')->where('created_at', '<', $project->reports[0]->date_start)->orderBy('created_at', 'desc')->first();
                 $experienced_productivity = count($previous_experienced_target) ? $previous_experienced_target : Target::where('position_id', $position->id)->where('experience', 'Experienced')->first();
                 // Quality
                 $previous_experienced_target = Target::withTrashed()->where('position_id', $position->id)->where('experience', 'Experienced')->where('created_at', '<', $project->reports[0]->date_start)->orderBy('created_at', 'desc')->first();
                 $quality = count($previous_experienced_target) ? $previous_experienced_target : Target::where('position_id', $position->id)->where('experience', 'Experienced')->first();
                 array_push($project->department->beginner, $beginner_productivity);
                 array_push($project->department->moderately_experienced, $moderately_experienced_productivity);
                 array_push($project->department->experienced, $experienced_productivity);
                 array_push($project->department->quality, $quality);
             }
             foreach ($project->reports as $report_key => $report) {
                 foreach ($report->performances as $performance_key => $performance) {
                     $performance->experience = Experience::where('member_id', $performance->member_id)->where('project_id', $performance->project_id)->first()->experience;
                 }
             }
         }
     }
     // return response()->json('$this->projects');
     Excel::create('PQR ' . $this->projects[0]->department->name . ' Weekly Summary ' . Carbon::parse($date_start)->toFormattedDateString() . ' to ' . Carbon::parse($date_end)->toFormattedDateString(), function ($excel) {
         foreach ($this->projects as $project_key => $project) {
             $this->project = $project;
             if (count($this->project->reports)) {
                 $excel->sheet($this->project->name, function ($sheet) {
                     $sheet->loadView('excel.weekly')->with('project', $this->project);
                 });
             }
         }
     })->download('xls');
 }