Example #1
0
 public function objetivosPlan($plan_id)
 {
     if (strpos($_SERVER['REQUEST_URI'], "verbloqueados")) {
         $objetivos = \Ermtool\Objective::where('strategic_plan_id', $plan_id)->where('status', 1)->get();
     } else {
         $objetivos = \Ermtool\Objective::where('strategic_plan_id', $plan_id)->where('status', 0)->get();
     }
     //seleccionamos todos los datos del plan para mostrarlo
     $datos_plan = \Ermtool\Strategic_plan::find($plan_id);
     $nombre_organizacion = \Ermtool\Organization::name($datos_plan->organization_id);
     $i = 0;
     //para saber si hay objetivos
     $objectives = array();
     //almacenará los objetivos con el formato correcto de sus atributos
     foreach ($objetivos as $objetivo) {
         //damos formato a fecha expiración
         if ($objetivo['expiration_date'] == NULL or $objetivo['expiration_date'] == "0000-00-00") {
             $fecha_exp = NULL;
         } else {
             $expiration_date = new DateTime($objetivo['expiration_date']);
             $fecha_exp = date_format($expiration_date, 'd-m-Y');
         }
         //damos formato a fecha creación
         if ($objetivo['created_at'] != NULL) {
             $fecha_creacion = date_format($objetivo['created_at'], "d-m-Y");
         } else {
             $fecha_creacion = NULL;
         }
         //damos formato a fecha de actualización
         if ($objetivo['updated_at'] != NULL) {
             $fecha_act = date_format($objetivo['updated_at'], "d-m-Y");
         } else {
             $fecha_act = NULL;
         }
         //damos formato a categoría de objetivo
         if ($objetivo['objective_category_id'] == NULL) {
             $categoria = NULL;
         } else {
             $categoria = \Ermtool\Objective_category::where('id', $objetivo['objective_category_id'])->value('name');
         }
         if ($objetivo['perspective'] == NULL) {
             $perspective = NULL;
         } else {
             $perspective = $objetivo['perspective'];
         }
         $objectives[$i] = array('id' => $objetivo['id'], 'nombre' => $objetivo['name'], 'descripcion' => $objetivo['description'], 'fecha_creacion' => $fecha_creacion, 'fecha_act' => $fecha_act, 'fecha_exp' => $fecha_exp, 'categoria' => $categoria, 'estado' => $objetivo['status'], 'perspective' => $perspective);
         $i += 1;
     }
     if (Session::get('languaje') == 'en') {
         return view('en.datos_maestros.objetivos.index', ['objetivos' => $objectives, 'nombre_organizacion' => $nombre_organizacion, 'datos_plan' => $datos_plan, 'probador' => $i, 'strategic_plan_id' => $plan_id]);
     } else {
         return view('datos_maestros.objetivos.index', ['objetivos' => $objectives, 'nombre_organizacion' => $nombre_organizacion, 'datos_plan' => $datos_plan, 'probador' => $i, 'strategic_plan_id' => $plan_id]);
     }
 }
 public function updatePlanEstrategico(Request $request, $id)
 {
     if (Auth::guest()) {
         return view('login');
     } else {
         global $id1;
         $id1 = $id;
         DB::transaction(function () {
             $strategic_plan = \Ermtool\Strategic_plan::find($GLOBALS['id1']);
             if ($_POST['comments'] != "") {
                 $comments = $_POST['comments'];
             } else {
                 $comments = NULL;
             }
             //seteamos fecha de expiracion
             $initial_date = explode('-', $_POST['initial_date']);
             $final_date = $initial_date[0] + $_POST['duration'] . '-' . $initial_date[1] . '-' . $initial_date[2];
             $strategic_plan->name = $_POST['name'];
             $strategic_plan->comments = $comments;
             $strategic_plan->initial_date = $_POST['initial_date'];
             $strategic_plan->final_date = $final_date;
             $strategic_plan->save();
             if (Session::get('languaje') == 'en') {
                 Session::flash('message', 'Objective was successfully updated');
             } else {
                 Session::flash('message', 'Plan estratégico actualizado correctamente');
             }
         });
         return Redirect::to('plan_estrategico?organizacion=' . $_POST['org_id']);
     }
 }