/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($controlTestId)
 {
     $control = Control::find($controlTestId);
     $controlTest = ControlTest::find($controlTestId);
     $controlTest->entered_by = Auth::user()->id;
     $controlTest->control_id = $controlTest->control->id;
     $controlTest->save();
     foreach ($controlTest->control->controlMeasures as $controlMeasure) {
         $controlResult = ControlMeasureResult::where('control_measure_id', $controlMeasure->id)->where('control_test_id', $controlTest->id)->first();
         $controlResult->results = Input::get('m_' . $controlMeasure->id);
         $controlResult->control_measure_id = $controlMeasure->id;
         $controlResult->control_test_id = $controlTestId;
         $controlResult->save();
     }
     return Redirect::route('control.resultsIndex')->with('message', trans('messages.success-updating-control-result'));
 }
 /**
  * Returns qc results for a specific control page
  *
  * @param Input - controlId, date range
  * @return view
  */
 public function qualityControlResults()
 {
     $rules = array('start_date' => 'date|required', 'end_date' => 'date|required', 'control' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         $controlId = Input::get('control');
         $endDatePlusOne = date_add(new DateTime(Input::get('end_date')), date_interval_create_from_date_string('1 day'));
         $dates = array(Input::get('start_date'), $endDatePlusOne);
         $control = Control::find($controlId);
         $controlTests = ControlTest::where('control_id', '=', $controlId)->whereBetween('created_at', $dates)->get();
         $leveyJennings = $this->leveyJennings($control, $dates);
         return View::make('reports.qualitycontrol.results')->with('control', $control)->with('controlTests', $controlTests)->with('leveyJennings', $leveyJennings)->withInput(Input::all());
     }
 }
 /**
  * Testing Control destroy funciton
  */
 public function testDestroy()
 {
     $this->action('DELETE', 'ControlController@destroy', array(1));
     $control = Control::find(1);
     $this->assertNull($control);
 }