コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\BeneficiatyCreateRequest $request)
 {
     $proyecto = Project::find($request->get('project_id'));
     if ($proyecto == null) {
         return redirect()->back()->with('errors', 'El proyecto no existe');
     }
     $homes = Beneficiary::where('project_id', '=', $proyecto->id)->get();
     if (count($homes) >= $proyecto->quantity) {
         Session::flash('message', 'Este proyecto tiene el maximo numero de beneficiarios');
         return redirect()->to('admin/proyectos');
     } else {
         $beneficiario = Beneficiary::create($request->all());
         $beneficiario->birthdate = Carbon::parse($request->get('birthdate'));
         $beneficiario->save();
         $etapas_project = Project::where('projects.id', '=', $proyecto->id)->join('designs', 'designs.id', '=', 'projects.desing_id')->join('desing_stage', 'desing_stage.desing_id', '=', 'designs.id')->join('stages', 'stages.id', '=', 'desing_stage.stage_id')->join('activity_stage', 'activity_stage.stage_id', '=', 'stages.id')->join('activities', 'activities.id', '=', 'activity_stage.activity_id')->groupBy('activities.id')->get(['activities.id as id']);
         foreach ($etapas_project as $e) {
             $avance = new Advanced();
             $avance->porcent = 0.0;
             $avance->state = 4;
             $avance->beneficiary_id = $beneficiario->id;
             $avance->save();
             $avance->actividades()->attach($e->id);
         }
         Session::flash('message', 'Beneficiario creado de forma correcta');
         return redirect()->to('admin/beneficiarios');
     }
 }
コード例 #2
0
 public static function avances($id)
 {
     return Advanced::leftJoin('beneficiaries', 'beneficiaries.id', '=', 'advanceds.beneficiary_id')->join('projects', 'projects.id', '=', 'beneficiaries.project_id')->where('projects.id', '=', $id)->orderBy('advanceds.created_at', 'ASC')->get(['advanceds.created_at']);
 }
コード例 #3
0
 public function all()
 {
     $avances = Advanced::where('advanceds.resident_id', '=', Auth::user()->id)->join('beneficiaries', 'beneficiaries.id', '=', 'advanceds.beneficiary_id')->leftJoin('projects', 'projects.id', '=', 'beneficiaries.project_id')->leftJoin('activity_advanced', 'activity_advanced.advanced_id', '=', 'advanceds.id')->leftJoin('activities', 'activities.id', '=', 'activity_advanced.activity_id')->orderBy('advanceds.fecha_visita', 'DESC')->select(['activities.name as act_name', 'advanceds.*', 'beneficiaries.name as user_name', 'beneficiaries.last_name as user_last', 'projects.name as p_name'])->paginate(5);
     return view('residente.all', compact('avances'));
 }
コード例 #4
0
 /**
  * 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]);
 }