/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //
     $deliverables = Deliverable::where('project_id', $id)->get();
     $i = 1;
     $input = Request::all();
     /* Check if $input["submit$i"] checkbox is checked or not */
     foreach ($deliverables as $deliverable) {
         if (isset($input["submit{$i}"])) {
             $deliverable->update(['submitted' => 1]);
         } else {
             $deliverable->update(['submitted' => 0]);
         }
         $deliverable->update(['required' => $input["required{$i}"], 'incharge' => $input["incharge{$i}"], 'condition' => $input["condition{$i}"]]);
         $i = $i + 1;
     }
     return redirect()->action('DeliverablesController@show', [$id]);
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $project = Project::findOrFail($id);
     $validator = Validator::make(Input::all(), array('cac' => 'required|cac|unique:projects,cac,' . $id, 'title' => 'required', 'target_start' => 'required', 'target_end' => 'required', 'target_mandays' => 'required', 'budget' => 'required', 'confidentiality' => 'required'));
     if ($validator->fails()) {
         return redirect()->action('ProjectsController@edit', $project->id)->withErrors($validator);
     } else {
         $users = User::all();
         //$input = Request::all();
         $input = Input::all();
         foreach ($users as $user) {
             if ($user->id == $input['pm']) {
                 $pmid = $user->id;
                 $pmname = User::find($pmid);
             }
         }
         if ($input['target_mandays'] >= 60 or $input['budget'] >= 2000000) {
             $importance = "MAJOR";
         } else {
             $importance = "MINOR";
         }
         $project->update(['cac' => $input['cac'], 'title' => $input['title'], 'user_id' => $pmid, 'pm' => $pmname->name, 'percent' => $input['percent'], 'target_start' => $input['target_start'], 'target_end' => $input['target_end'], 'status' => $input['status'], 'color' => $input['color'], 'rationale' => $input['rationale'], 'actual_start' => $input['actual_start'], 'actual_end' => $input['actual_end'], 'budget' => $input['budget'], 'utilization' => $input['utilization'], 'target_mandays' => $input['target_mandays'], 'actual_mandays' => $input['actual_mandays'], 'hardware' => $input['hardware'], 'software' => $input['software'], 'importance' => $importance, 'applicability' => $input['applicability'], 'confidentiality' => $input['confidentiality']]);
         if ($input['status'] != 'Not Started') {
             $project->update(['actual_start' => $input['actual_start']]);
         }
         if ($input['status'] == 'Completed' or $input['status'] == 'Cancelled') {
             $project->update(['actual_end' => $input['actual_end']]);
         }
         //$input = Request::all();
         //$request = new CreateProjectRequest;
         if (isset($input['users']) == true) {
             $project->users()->sync($input['users']);
         } else {
             DB::delete('delete from project_user where project_id = ?', array($project->id));
         }
         $deliverables = Deliverable::where('project_id', $id)->get();
         $i = 0;
         $required = [];
         if ($input['applicability'] == 'New or Replacement of IT Solution') {
             $required = ['M', 'O', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'O', 'M', 'M', 'O', 'M', 'M', 'M', 'M', 'O', 'O', 'O', 'N/A', 'M', 'M', 'M', 'M', 'O', 'M', 'O', 'O', 'M', 'M', 'M', 'O', 'O', 'O', 'M', 'M', 'O', 'O', 'O', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'O', 'O', 'M', 'M', 'M', 'M', 'O', 'O'];
         } elseif ($input['applicability'] == 'Enhancement or Application System Upgrade') {
             $required = ['M', 'O', '-', '-', '-', 'M', 'M', 'M', 'M', 'M', 'M', 'M', '-', 'O', 'M', 'M', 'O', '-', '-', 'M', 'M', 'O', 'O', 'O', 'N/A', 'M', 'M', 'M', 'M', 'O', 'M', 'O', 'O', 'M', 'M', 'M', 'O', 'O', 'O', 'M', 'M', 'O', 'O', 'O', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'O', 'O', 'O', 'O', 'O', 'M', 'O', 'O'];
         } elseif ($input['applicability'] == 'IT Infrastructure') {
             $required = ['M', '-', '-', '-', '-', 'M', 'M', 'M', 'M', 'M', 'M', 'M', '-', '-', '-', '-', '-', '-', 'M', 'M', 'M', 'O', 'O', 'O', 'N/A', 'M', 'M', 'M', 'M', 'O', 'M', 'O', 'O', 'M', 'M', 'M', 'O', '-', '-', 'M', 'M', 'O', 'O', 'O', 'M', '-', '-', 'M', '-', 'M', 'M', 'M', '-', 'O', 'O', 'O', 'O', 'M', 'O', 'O'];
         }
         foreach ($deliverables as $deliverable) {
             $deliverable->update(['required' => $required[$i]]);
             $i = $i + 1;
         }
         flash()->success('Your project has been successfully updated!');
         return redirect()->action('ProjectsController@show', [$id]);
     }
 }