Esempio n. 1
0
 public static function etapa($project_id, $stage_id)
 {
     return Activity_Stage::join('stages', 'stages.id', '=', 'activity_stage.stage_id')->join('desing_stage', 'desing_stage.stage_id', '=', 'stages.id')->join('designs', 'designs.id', '=', 'desing_stage.desing_id')->join('projects', 'projects.desing_id', '=', 'projects.id')->where('projects.id', '=', $project_id)->where('stages.id', '=', $stage_id)->get([DB::raw('count(activity_stage.id) as c')]);
 }
 public function update($id, Request $request)
 {
     $design = Desing::find($id);
     $design->name = $request->get('name');
     $design->save();
     $tree = $request->get('data');
     $stages_ids = array();
     $activities_ids = array();
     foreach ($tree as $node) {
         foreach ($node as $key => $attribute) {
             if ($key == 'stage_id') {
                 array_push($stages_ids, $attribute);
             }
         }
     }
     foreach ($design->etapas as $etapa) {
         foreach ($etapa->actividades as $actividad) {
             $actividad->etapas()->detach($etapa->id);
         }
         $design->etapas()->detach($etapa->id);
     }
     foreach ($stages_ids as $ids) {
         $design->etapas()->attach($ids);
     }
     foreach ($tree as $leaf) {
         $act = Activity_Stage::create($leaf);
         $act->design_id = $design->id;
         $act->save();
     }
     return response()->json($request->all());
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function crear(Request $request)
 {
     $data = $request->all();
     $actividad = new Activity_Stage();
     $actividad->stage_project_id = $data['project_stage_id'];
     $actividad->activity_id = $data['activity_id'];
     $actividad->unity = $data['unity'];
     $actividad->other_unity = $data['other_unity'];
     $actividad->quantity = $data['quantity'];
     $actividad->material = $data['material'];
     $actividad->hand = $data['hand'];
     $actividad->transport = $data['transport'];
     $actividad->save();
     $project = Project::find($data['project_id']);
     $homes = Home::where('project_id', '=', $project->id)->get();
     foreach ($homes as $home) {
         $avance = new Advanced();
         $avance->porcent = 0.0;
         $avance->state = 4;
         $avance->home_id = $home->id;
         $avance->project_stage_id = $actividad->stage_project_id;
         $avance->save();
     }
     $all = Activity_Stage::join('project_stage', 'project_stage.id', '=', 'activity_stage.stage_project_id')->join('projects', 'projects.id', '=', 'project_stage.project_id')->where('projects.id', '=', $project->id)->get(['activity_stage.*']);
     $valor_total = 0;
     foreach ($all as $a) {
         $valor = 0;
         $valor += $a->hand + $a->transport + $a->material;
         $valor_total += $valor * $a->quantity;
     }
     $project->budget = 0;
     $project->budget = $valor_total;
     $project->save();
     return response()->json([$all]);
 }