public function save($request, $id = false)
 {
     $rules = ['affiliate_id' => 'numeric', 'retirement_fund_modality_id' => 'numeric'];
     $messages = ['affiliate_id.numeric' => 'Solo se aceptan números para id afiliado', 'retirement_fund_modality_id.numeric' => 'Solo se aceptan números para id modalidad'];
     $validator = Validator::make($request->all(), $rules, $messages);
     if ($validator->fails()) {
         return redirect('tramite_fondo_retiro/' . $id)->withErrors($validator)->withInput();
     } else {
         $retirement_fund = RetirementFund::afiIs($id)->first();
         $affiliate = Affiliate::idIs($id)->first();
         switch ($request->type) {
             case 'form_modality':
                 if ($request->modality == 4 && $affiliate->date_decommissioned == null) {
                     $message = "Ingrese Fecha de deceso de Afiliado";
                 } else {
                     if ($request->modality) {
                         $retirement_fund->retirement_fund_modality_id = trim($request->modality);
                     }
                     $retirement_fund->city_id = trim($request->city);
                     $retirement_fund->save();
                     switch ($request->modality) {
                         case '1':
                             $affiliate->affiliate_state_id = 8;
                             $affiliate->save();
                             break;
                         case '2':
                             $affiliate->affiliate_state_id = 7;
                             $affiliate->save();
                             break;
                         case '3':
                             $affiliate->affiliate_state_id = 5;
                             $affiliate->save();
                             break;
                         case '4':
                             $affiliate->affiliate_state_id = 4;
                             $affiliate->save();
                             break;
                     }
                     $message = "Información General de Fondo de Retiro actualizado con éxito";
                 }
                 break;
             case 'form_document':
                 if ($retirement_fund->retirement_fund_modality_id) {
                     foreach (json_decode($request->data) as $item) {
                         $Document = Document::where('retirement_fund_id', '=', $retirement_fund->id)->where('requirement_id', '=', $item->requirement_id)->first();
                         if (!$Document) {
                             $Document = new Document();
                             $Document->retirement_fund_id = $retirement_fund->id;
                             $Document->requirement_id = $item->requirement_id;
                         }
                         $Document->status = $item->booleanValue;
                         $Document->reception_date = date('Y-m-d');
                         $Document->save();
                         $retirement_fund->reception_date = date('Y-m-d');
                         $retirement_fund->save();
                     }
                     $message = "Información de requisitos de Fondo de Retiro actualizado con éxito";
                 } else {
                     $message = "Seleccione la modalidad y la ciudad";
                 }
                 break;
             case 'antec':
                 foreach (json_decode($request->data) as $item) {
                     $antecedent = Antecedent::where('retirement_fund_id', '=', $retirement_fund->id)->where('antecedent_file_id', '=', $item->prestacion_id)->first();
                     if (!$antecedent) {
                         $antecedent = new Antecedent();
                         $antecedent->retirement_fund_id = $retirement_fund->id;
                         $antecedent->antecedent_file_id = $item->prestacion_id;
                     }
                     $antecedent->status = $item->booleanValue;
                     $antecedent->save();
                 }
                 $retirement_fund->check_file_date = date('Y-m-d');
                 $retirement_fund->save();
                 $message = "Información de requisitos de Fondo de Retiro actualizado con éxito";
                 break;
             case 'periods':
                 $affiliate->service_start_date = Util::datePickPeriod($request->fech_ini_serv);
                 $affiliate->service_end_date = Util::datePickPeriod($request->fech_fin_serv);
                 $affiliate->save();
                 $retirement_fund->anticipation_start_date = Util::datePickPeriod($request->fech_ini_anti);
                 $retirement_fund->anticipation_end_date = Util::datePickPeriod($request->fech_fin_anti);
                 $retirement_fund->recognized_start_date = Util::datePickPeriod($request->fech_ini_reco);
                 $retirement_fund->recognized_end_date = Util::datePickPeriod($request->fech_fin_reco);
                 $retirement_fund->save();
                 $retirement_fund->qualification_date = date('Y-m-d');
                 $retirement_fund->save();
                 $message = "Información de Periodos de Aporte actualizado con éxito";
                 break;
         }
         Session::flash('message', $message);
     }
     return redirect('retirement_fund/' . $id);
 }
Exemplo n.º 2
0
{
    protected $table = 'documents';
    protected $fillable = ['requirement_id', 'retirement_fund_id', 'reception_date', 'status', 'comment'];
    protected $guarded = ['id'];
    public function retirement_fund()
    {
        return $this->belongsTo('Muserpol\\RetirementFund');
    }
    public function requirement()
    {
        return $this->belongsTo('Muserpol\\Requirement');
    }
    public function scopeRetirementFundIs($query, $id)
    {
        return $query->where('retirement_fund_id', $id);
    }
    public function getData_fech_requi()
    {
        return Util::getDateAbrePeriod($this->reception_date);
    }
    public function getDataEdit()
    {
        return Util::getdateforEdit($this->fech_pres);
    }
}
Document::created(function ($document) {
    Activity::createdDocument($document);
});
Document::updating(function ($document) {
    Activity::updateDocument($document);
});