/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // $list = _MODEL::all();
     $list = _MODEL::leftJoin('initiatives', 'initiatives.id', '=', 'measures.initiative_id')->leftJoin('objectives', 'objectives.id', '=', 'initiatives.objective_id')->leftJoin('dimensions', 'dimensions.id', '=', 'objectives.dimension_id')->leftJoin('plans', 'plans.id', '=', 'dimensions.plan_id')->where('plans.user_id', '=', $this->viewData['user_id'])->where('plans.id', '=', $this->viewData['currentPlan']->id)->select('measures.*')->get();
     foreach ($list as $row) {
         //Calculate actual
         $row->actual = ActualMeasure::where('actual_measures.measure_id', '=', (int) $row->id)->sum('actual_measures.actual_measure');
         if ($row->target != 0) {
             $row->percent = $row->actual / $row->target * 100;
         }
     }
     return view($this->controller . '.index', compact('list'), $this->viewData);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 private function populateInitiativeTabularAndGraph($initiative_id)
 {
     $list = _MODEL::leftJoin('objectives', 'objectives.id', '=', 'initiatives.objective_id')->leftJoin('dimensions', 'dimensions.id', '=', 'objectives.dimension_id')->leftJoin('plans', 'plans.id', '=', 'dimensions.plan_id')->where('initiatives.id', '=', (int) $initiative_id)->select('initiatives.*')->get();
     $initiative_AVERAGE = 0;
     $initiative_count = 0;
     foreach ($list as $initiative) {
         // get measures related to initiative
         $measures = $initiative->measures;
         $measure_count = 0;
         $percent = 0;
         foreach ($measures as $measure) {
             $measure->percent = 0;
             $measure->actual = ActualMeasure::where('actual_measures.measure_id', '=', (int) $measure->id)->sum('actual_measures.actual_measure');
             if ($measure->target != 0) {
                 $percent += $measure->actual / $measure->target * 100;
                 $measure->AVERAGE = $measure->actual / $measure->target * 100;
             }
             $measure_count++;
         }
         $initiative->measures = $measures;
         //end measures
         if ($measure_count != 0) {
             $initiative_AVERAGE += $percent / $measure_count;
             $initiative->AVERAGE = $percent / $measure_count;
         }
         $initiative_count++;
     }
     $this->viewData['initiatives'] = $list;
     self::populateInitiativeGraph();
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 private function populateDimensionTabularAndGraph($dimension_id)
 {
     $list = _MODEL::leftJoin('plans', 'plans.id', '=', 'dimensions.plan_id')->where('dimensions.id', '=', (int) $dimension_id)->select('dimensions.*')->get();
     $this->viewData['graphData'] = [];
     $this->viewData['graphData']['title'] = "BSC Report - Dimension: " . $list[0]->name;
     $this->viewData['graphData']['subtitle'] = "Report for " . $list[0]->name . "'s objectives";
     $this->viewData['graphData']['data'] = [];
     foreach ($list as $row) {
         $row->AVERAGE = 0;
         // get objectives list related to dimension
         $objectives = $row->objectives;
         $objective_AVERAGE = 0;
         $objective_count = 0;
         $total_bojectives = 0;
         foreach ($objectives as $objective) {
             $objective->AVERAGE = 0;
             //get initiatives related to objective
             $initiatives = $objective->initiatives;
             $initiative_AVERAGE = 0;
             $initiative_count = 0;
             foreach ($initiatives as $initiative) {
                 // get measures related to initiative
                 $measures = $initiative->measures;
                 $measure_count = 0;
                 $percent = 0;
                 foreach ($measures as $measure) {
                     $measure->percent = 0;
                     $measure->actual = ActualMeasure::where('actual_measures.measure_id', '=', (int) $measure->id)->sum('actual_measures.actual_measure');
                     if ($measure->target != 0) {
                         $percent += $measure->actual / $measure->target * 100;
                         $measure->AVERAGE = $measure->actual / $measure->target * 100;
                     }
                     $measure_count++;
                 }
                 $initiative->measures = $measures;
                 //end measures
                 if ($measure_count != 0) {
                     $initiative_AVERAGE += $percent / $measure_count;
                     $initiative->AVERAGE = $percent / $measure_count;
                 }
                 $initiative_count++;
             }
             // $objective->initiatives = $initiatives;
             //end initiative
             if ($initiative_count != 0) {
                 $objective_AVERAGE += $initiative_AVERAGE / $initiative_count;
                 $objective->AVERAGE = $initiative_AVERAGE / $initiative_count;
             }
             $objective_count++;
         }
         // $row->objectives = $objectives;
         if ($objective_count != 0) {
             $row->AVERAGE = $objective_AVERAGE / $objective_count;
         }
     }
     $this->viewData['plan_dimensions'] = $list;
     self::populateDimensionGraph();
     // echo '<pre>';print_r($this->viewData['graphData']);die;print_r($this->viewData['plan_dimensions'][0]->objectives);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 private function populateDimensionsTabularAndGraph($plan_id)
 {
     $list = Dimension::leftJoin('plans', 'plans.id', '=', 'dimensions.plan_id')->where('plans.id', '=', (int) $plan_id)->select('dimensions.*')->get();
     foreach ($list as $row) {
         $row->AVERAGE = 0;
         // get objectives list related to dimension
         $objectives = $row->objectives;
         $objective_AVERAGE = 0;
         $objective_count = 0;
         foreach ($objectives as $objective) {
             $objective->AVERAGE = 0;
             //get initiatives related to objective
             $initiatives = $objective->initiatives;
             $initiative_AVERAGE = 0;
             $initiative_count = 0;
             foreach ($initiatives as $initiative) {
                 // get measures related to initiative
                 $measures = $initiative->measures;
                 $measure_count = 0;
                 $percent = 0;
                 foreach ($measures as $measure) {
                     $measure->percent = 0;
                     $measure->actual = ActualMeasure::where('actual_measures.measure_id', '=', (int) $measure->id)->sum('actual_measures.actual_measure');
                     if ($measure->target != 0) {
                         $percent += $measure->actual / $measure->target * 100;
                         $measure->AVERAGE = $measure->actual / $measure->target * 100;
                     }
                     $measure_count++;
                 }
                 $initiative->measures = $measures;
                 //end measures
                 if ($measure_count != 0) {
                     $initiative_AVERAGE += $percent / $measure_count;
                     $initiative->AVERAGE = $percent / $measure_count;
                 }
                 $initiative_count++;
             }
             // $objective->initiatives = $initiatives;
             //end initiative
             if ($initiative_count != 0) {
                 $objective_AVERAGE += $initiative_AVERAGE / $initiative_count;
                 $objective->AVERAGE = $initiative_AVERAGE / $initiative_count;
             }
             $objective_count++;
         }
         // $row->objectives = $objectives;
         if ($objective_count != 0) {
             $row->AVERAGE = $objective_AVERAGE / $objective_count;
         }
     }
     $this->viewData['plan_dimensions'] = $list;
     self::populatePlanGraph();
 }
 public function getAverageDimension($dimension)
 {
     $dimension->AVERAGE = 0;
     // get objectives list related to dimension
     $objectives = Objective::where('objectives.dimension_id', '=', (int) $dimension->id)->select('*')->get();
     $objective_AVERAGE = 0;
     $objective_count = 0;
     foreach ($objectives as $objective) {
         //get initiatives related to objective
         $initiatives = Initiative::where('initiatives.objective_id', '=', (int) $objective->id)->select('*')->get();
         $initiative_AVERAGE = 0;
         $initiative_count = 0;
         foreach ($initiatives as $initiative) {
             //get measures related to initiative
             $measures = Measure::where('measures.initiative_id', '=', (int) $initiative->id)->select('*')->get();
             $measure_count = 0;
             $percent = 0;
             foreach ($measures as $measure) {
                 $measure->actual = ActualMeasure::where('actual_measures.measure_id', '=', (int) $measure->id)->sum('actual_measures.actual_measure');
                 if ($measure->target != 0) {
                     $percent += $measure->actual / $measure->target * 100;
                 }
                 $measure_count++;
             }
             //end measures
             if ($measure_count != 0) {
                 $initiative_AVERAGE += $percent / $measure_count;
             }
             $initiative_count++;
         }
         //end initiative
         if ($initiative_count != 0) {
             $objective_AVERAGE += $initiative_AVERAGE / $initiative_count;
         }
         $objective_count++;
     }
     if ($objective_count != 0) {
         $dimension->AVERAGE = (double) $objective_AVERAGE / $objective_count;
     }
     return $dimension;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($measureId, $actualMeaserId)
 {
     $this->viewData['measure_id'] = $measureId;
     _MODEL::find($actualMeaserId)->delete();
     Session::flash('message', $this->viewData['whatisit'] . ' deleted!');
     Session::flash('alert-class', 'alert-danger');
     return redirect('measures' . '/' . $measureId . '/' . $this->controller);
 }