public function create(Request $request)
 {
     $newBusinessPlan = new BusinessPlan();
     $newBusinessPlan->start = date($request['sYear'] . '-01-01 00:00:00');
     $newBusinessPlan->end = date($request['eYear'] . '-12-31 00:00:00');
     $newBusinessPlan->save();
     foreach (array_keys($request['data']) as $idx) {
         $key = array_keys($request['data'][$idx])[0];
         $newGoal = new Goat();
         $newGoal->type = 'G';
         $newGoal->parent_id = null;
         $newGoal->description = $key;
         $newGoal->priority = 0;
         $newGoal->complete = false;
         $newGoal->goal_type = 'B';
         $newGoal->due_date = null;
         $newGoal->budget = 0;
         $newGoal->bid = $newBusinessPlan->id;
         $newGoal->save();
         foreach ($request['data'][$idx][$key] as $obj) {
             $newObj = new Goat();
             $newObj->type = 'O';
             $newObj->parent_id = $newGoal->id;
             $newObj->description = $obj;
             $newObj->priority = 0;
             $newObj->complete = false;
             $newObj->goal_type = 'B';
             $newObj->due_date = null;
             $newObj->budget = 0;
             $newObj->bid = $newBusinessPlan->id;
             $newObj->save();
         }
     }
     foreach (Department::lists('name') as $dept_name) {
         $newGoal = new Goat();
         $newGoal->type = 'G';
         $newGoal->parent_id = null;
         $newGoal->description = $dept_name . " Goals";
         $newGoal->priority = 0;
         $newGoal->complete = false;
         $newGoal->goal_type = 'D';
         $newGoal->due_date = null;
         $newGoal->budget = 0;
         $newGoal->bid = $newBusinessPlan->id;
         $newGoal->save();
     }
     return response()->json([], 200);
 }
 public function dashboard()
 {
     $user = Auth::user();
     $recent = Change::where('user_id', $user->id)->get();
     $tasks = $user->goats()->orderBy('due_date')->get();
     $dept = $user->departments()->get();
     $recentEmpty = true;
     $tasksEmpty = true;
     foreach ($tasks as $task) {
         if (!$task->complete) {
             $tasksEmpty = false;
         }
         //     if (Carbon\Carbon::parse($task->due_date)->diff(Carbon\Carbon::now())){
         //         $task->soon = 'red';
         //     }
         //     else{
         //         $task->soon = '';
         //     }
     }
     //redo controller
     $inProgress = $user->goats()->where('complete', '0')->count();
     $complete = $user->goats()->where('complete', '1')->count();
     $overdue = 0;
     foreach ($tasks as $task) {
         if (Carbon\Carbon::parse($task->due_date)->lt(Carbon\Carbon::now())) {
             $overdue++;
         }
     }
     $inProgress -= $overdue;
     foreach ($recent as $task) {
         $recentEmpty = false;
         $task->task = Goat::where('id', $task->goat_id)->value('description');
     }
     return view('dashboard', compact('user', 'tasks', 'dept', 'recent', 'recentEmpty', 'tasksEmpty', 'complete', 'inProgress', 'overdue'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     Department::create($request->input());
     foreach (BusinessPlan::lists('id') as $bid) {
         $newGoal = new Goat();
         $newGoal->type = 'G';
         $newGoal->parent_id = null;
         $newGoal->description = $request['name'] . " Goals";
         $newGoal->priority = 0;
         $newGoal->complete = false;
         $newGoal->goal_type = 'D';
         $newGoal->due_date = null;
         $newGoal->budget = 0;
         $newGoal->bid = $bid;
         $newGoal->save();
     }
     return redirect('admin/depts');
 }
예제 #4
0
 public function create(Request $req)
 {
     $user = Auth::user();
     $change = new Change();
     if ($req->option === 'Status') {
         $changeType = 'S';
     } else {
         $changeType = 'N';
     }
     if ($req->complete) {
         Goat::where('id', $req->id)->update(['complete' => '1']);
     } else {
         Goat::where('id', $req->id)->update(['complete' => false]);
     }
     if ($req->statusUpdate === '' && $req->complete) {
         $req->statusUpdate = 'Complete';
     }
     $change = Change::create(['change_type' => $changeType, 'description' => $req->statusUpdate, 'goat_id' => $req->id, 'user_id' => $user->id]);
     return back();
 }
예제 #5
0
    Route::patch('/manage', 'ManagePlanController@update');
    Route::delete('/manage', 'ManagePlanController@destroy');
    Route::get('ajax-action', function () {
        $obj_Id = Input::get('obj_Id');
        $user = Auth::user();
        if ($user->is_bplead) {
            $actions = Goat::where('parent_id', '=', $obj_Id)->where('type', '=', 'A')->get();
            return Response::json($actions);
        } else {
            $actions = $user->leadOn()->where('parent_id', '=', $obj_Id)->where('type', '=', 'A')->get();
            $action = $actions->map(function ($elem) {
                return $elem;
            });
            return Response::json($action);
        }
    });
    Route::get('ajax-task', function () {
        $action_Id = Input::get('action_Id');
        $user = Auth::user();
        if ($user->is_bplead) {
            $tasks = Goat::where('parent_id', '=', $action_Id)->where('type', '=', 'T')->get();
            return Response::json($tasks);
        } else {
            $tasks = $user->leadOf()->first()->leadOn()->where('parent_id', '=', $action_Id)->where('type', '=', 'T')->get();
            $task = $tasks->map(function ($elem) {
                return $elem;
            });
            return Response::json($task);
        }
    });
});
 public function updateGoat(Request $request, $id)
 {
     $goat = Goat::find($id);
     $userCollabs = array();
     $deptCollabs = array();
     if ($request->collabs) {
         foreach ($request->collabs as $col) {
             if (strpos($col, 'user') !== false) {
                 array_push($userCollabs, substr($col, 5));
             } else {
                 array_push($deptCollabs, substr($col, 5));
             }
         }
     }
     $this->createChanges($goat, $request->department, $request->description, $request->success_measure, $request->leads, $userCollabs, $deptCollabs, $request->due_date, $request->priority);
     $goat->description = $request->description;
     $goat->success_measure = $request->success_measure;
     $goat->due_date = $request->due_date;
     $goat->priority = $request->priority;
     $goat->department_id = $request->department;
     $goat->save();
     $leads = array_fill_keys($request->leads ? $request->leads : array(), ['user_role' => 'L']);
     $collabs = array_fill_keys($userCollabs, ['user_role' => 'C']);
     $goat->userLeads()->sync($leads + $collabs);
     $goat->departmentCollaborators()->sync($deptCollabs);
     return redirect('/view');
 }
예제 #7
0
 public function createChanges(Goat $goat, $department_id, $description, $success_measure, $leads, $userCollabs, $deptCollabs, $due_date, $priority)
 {
     if ($department_id != $goat->department_id) {
         $change = new \App\Change();
         $change->change_type = 'L';
         $change->description = 'Assigned to ' . Department::find($department_id)->name;
         $change->goat_id = $goat->id;
         $change->user_id = Auth::user()->id;
         $change->save();
     }
     if ($description != $goat->description) {
         $change = new \App\Change();
         $change->change_type = 'D';
         $change->description = $description;
         $change->goat_id = $goat->id;
         $change->user_id = Auth::user()->id;
         $change->save();
     }
     if ($success_measure != $goat->success_measure) {
         $change = new \App\Change();
         $change->change_type = 'M';
         $change->description = "Success Measure: " . $success_measure;
         $change->goat_id = $goat->id;
         $change->user_id = Auth::user()->id;
         $change->save();
     }
     $newLeads = $leads ? $leads : array();
     $curLeads = $goat->userLeads()->get()->map(function ($user) {
         return $user->id;
     })->toArray();
     sort($newLeads);
     sort($curLeads);
     if ($newLeads != $curLeads) {
         if ($diff = array_diff($newLeads, $curLeads)) {
             $users = array_map(function ($id) {
                 return User::findOrFail($id)->name();
             }, $diff);
             $change = new \App\Change();
             $change->change_type = 'L';
             $change->description = "Added " . join(', ', $users);
             $change->goat_id = $goat->id;
             $change->user_id = Auth::user()->id;
             $change->save();
         }
         if ($diff = array_diff($curLeads, $newLeads)) {
             $users = array_map(function ($id) {
                 return User::findOrFail($id)->name();
             }, $diff);
             $change = new \App\Change();
             $change->change_type = 'L';
             $change->description = "Removed " . join(', ', $users);
             $change->goat_id = $goat->id;
             $change->user_id = Auth::user()->id;
             $change->save();
         }
     }
     $newCollaborators = $userCollabs ? $userCollabs : array();
     $curCollaborators = $goat->userCollaborators()->get()->map(function ($user) {
         return $user->id;
     })->toArray();
     sort($newCollaborators);
     sort($curCollaborators);
     if ($newCollaborators != $curCollaborators) {
         if ($diff = array_diff($newCollaborators, $curCollaborators)) {
             $users = array_map(function ($id) {
                 return User::findOrFail($id)->name();
             }, $diff);
             $change = new \App\Change();
             $change->change_type = 'C';
             $change->description = "Added " . join(', ', $users);
             $change->goat_id = $goat->id;
             $change->user_id = Auth::user()->id;
             $change->save();
         }
         if ($diff = array_diff($curCollaborators, $newCollaborators)) {
             $users = array_map(function ($id) {
                 return User::findOrFail($id)->name();
             }, $diff);
             $change = new \App\Change();
             $change->change_type = 'C';
             $change->description = "Removed " . join(', ', $users);
             $change->goat_id = $goat->id;
             $change->user_id = Auth::user()->id;
             $change->save();
         }
     }
     $newCollaborators = $deptCollabs ? $deptCollabs : array();
     $curCollaborators = $goat->departmentCollaborators()->get()->map(function ($dept) {
         return $dept->id;
     })->toArray();
     sort($newCollaborators);
     sort($curCollaborators);
     if ($newCollaborators != $curCollaborators) {
         if ($diff = array_diff($newCollaborators, $curCollaborators)) {
             $depts = array_map(function ($id) {
                 return Department::findOrFail($id)->name;
             }, $diff);
             $change = new \App\Change();
             $change->change_type = 'C';
             $change->description = "Added " . join(', ', $depts);
             $change->goat_id = $goat->id;
             $change->user_id = Auth::user()->id;
             $change->save();
         }
         if ($diff = array_diff($curCollaborators, $newCollaborators)) {
             $depts = array_map(function ($id) {
                 return Department::findOrFail($id)->name;
             }, $diff);
             $change = new \App\Change();
             $change->change_type = 'C';
             $change->description = "Removed " . join(', ', $depts);
             $change->goat_id = $goat->id;
             $change->user_id = Auth::user()->id;
             $change->save();
         }
     }
     if ($goat->due_date != $due_date) {
         $change = new \App\Change();
         $change->change_type = 'T';
         $change->description = "Changed from " . \Carbon\Carbon::parse($goat->due_date)->toDateString() . " to " . \Carbon\Carbon::parse($due_date)->toDateString();
         $change->goat_id = $goat->id;
         $change->user_id = Auth::user()->id;
         $change->save();
     }
     if ($goat->priority != $priority) {
         $change = new \App\Change();
         $change->change_type = 'P';
         $change->description = "Changed from " . $this->priority_string($goat->priority) . " to " . $this->priority_string($priority);
         $change->goat_id = $goat->id;
         $change->user_id = Auth::user()->id;
         $change->save();
     }
 }
 public function destroy(Request $request)
 {
     $type = $request->type;
     if ($type == 'G') {
         $this->validate($request, ['businessId' => 'required', 'goalId' => 'required']);
         $elem = Goat::find($request->goalId);
     } elseif ($type == 'O') {
         $this->validate($request, ['businessId' => 'required', 'goalId' => 'required', 'objId' => 'required']);
         $elem = Goat::find($request->objId);
     } elseif ($type == 'A') {
         $this->validate($request, ['businessId' => 'required', 'goalId' => 'required', 'objId' => 'required', 'actionId' => 'required']);
         $elem = Goat::find($request->actionId);
     } else {
         $this->validate($request, ['businessId' => 'required', 'goalId' => 'required', 'objId' => 'required', 'actionId' => 'required', 'taskId' => 'required']);
         $elem = Goat::find($request->taskId);
     }
     $elem->delete();
     return back();
 }