public function change_password() { $validator = Validator::make($input = Input::all(), Personal::rules('password')); if ($validator->fails()) { $output['status'] = 'error'; $output['msg'] = $validator->getMessageBag()->toArray(); } else { $employee = Personal::find(Auth::personales()->get()->id); $employee->password = Hash::make($input['password']); $employee->save(); $output['status'] = 'success'; $output['msg'] = '<strong>Success ! </strong>Password changed successfully'; } return Response::json($output, 200); }
/** * Update the specified in storage. */ public function update($id) { //----Bank Details Update------- if (Input::get('updateType') == 'zonificacion') { $validator = Validator::make($input = Input::all(), Beneficiario::rules('zonificacion')); if ($validator->fails()) { $output['status'] = 'error'; $output['msg'] = $validator->getMessageBag()->toArray(); } else { $details = Zonificacion::firstOrNew(['beneficiarioID' => $id]); $details->departamento = Input::get('departamento'); $details->provincia = Input::get('provincia'); $details->otros = Input::get('otros'); $details->localidad = Input::get('localidad'); $details->canton = Input::get('canton'); $details->zona = Input::get('zona'); $details->save(); $output['status'] = 'success'; $output['msg'] = 'Zonificacion actualizado exitosamente'; } } else { if (Input::get('updateType') == 'donacion') { $ddetails = Beneficiario::where('beneficiarioID', '=', $id)->first(); $validator = Validator::make($input = Input::all(), Beneficiario::rules('update', $ddetails->id)); if ($validator->fails()) { $output['status'] = 'error'; $output['msg'] = $validator->getMessageBag()->toArray(); } else { $ddetails->beneficiarioID = $id; $ddetails->objetivo = Input::get('objetivo'); $ddetails->fechaing = date('Y-m-d', strtotime(Input::get('fechaing'))); $ddetails->fecha_desvinculacion = trim(Input::get('fecha_desvinculacion')) != '' ? date('Y-m-d', strtotime(Input::get('fecha_desvinculacion'))) : null; $ddetails->status = Input::get('status') != 'activo' ? 'inactivo' : 'activo'; $ddetails->save(); if (isset($input['monto'])) { foreach ($input['monto'] as $index => $value) { $salary_details = Soldonacion::find($index); $salary_details->tipo = $input['tipo'][$index]; $salary_details->monto = $value; $salary_details->save(); } } $output['status'] = 'success'; $output['msg'] = 'Donacion Actualizado Existosamente'; } } else { if (Input::get('updateType') == 'personalInfo') { $ben = Beneficiario::where('beneficiarioID', '=', $id)->get()->first(); $validator = Validator::make($data = Input::all(), Beneficiario::rules('personalInfo', $ben->id)); if ($validator->fails()) { return Redirect::back()->with(['errorPersonal' => $validator->messages()->all()])->withInput(); } $input = Input::all(); $fullname = $input['nombres'] . " " . $input['apellidos']; // $password = ($data['password']!='')?Hash::make(Input::get('password')):$data['oldpassword']; // Profile Image Upload if (Input::hasFile('foto')) { $path = public_path() . "/profileImages/"; File::makeDirectory($path, $mode = 0777, true, true); $image = Input::file('foto'); $extension = $image->getClientOriginalExtension(); $filename = "{$fullname}_{$id}." . strtolower($extension); //Image::make($image->getRealPath())->resize(872,724)->save("$path$filename"); Image::make($image->getRealPath())->fit(872, 724, function ($constraint) { $constraint->upsize(); })->save($path . $filename); } else { $filename = Input::get('hiddenImage'); } $ben->update(['nombres' => ucwords(strtolower($input['nombres'])), 'apellidos' => ucwords(strtolower($input['apellidos'])), 'genero' => $input['genero'], 'fechanac' => trim(Input::get('fechanac')) != '' ? date('Y-m-d', strtotime(Input::get('fechanac'))) : null, 'telefono' => $input['telefono'], 'direccion' => $input['direccion'], 'foto' => isset($filename) ? $filename : 'default.jpg', 'direccionperm' => $input['direccionperm'], 'iddiagnostico' => $input['iddiag'], 'diagnostico' => $input['diagnostico'], 'fechadiagnostico' => $input['fechadiag'], 'tratamiento' => $input['tratamiento'], 'razon' => $input['razon'], 'duracion' => $input['duracion'], 'referencia' => $input['referencia'], 'lugar' => $input['lugar']]); Activity::log(['contentId' => $id, 'contentType' => 'Beneficiario', 'user_id' => Auth::admin()->get()->id, 'action' => 'Update', 'description' => 'Actualizacion ' . Input::get('updateType'), 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); return Redirect::route('admin.beneficiarios.edit', $id)->with('successPersonal', "<strong>Actualizacion</strong> Existosa"); } else { if (Input::get('updateType') == 'responsable') { // dd(Input::all()); $per = Personal::where('personalID', '=', $id)->get()->first(); $validator = Validator::make($input = Input::all(), Personal::rules('personalInfo', $per->id)); if ($validator->fails()) { $output['status'] = 'error'; $output['msg'] = $validator->getMessageBag()->toArray(); } else { $responsable = Personal::firstOrNew(['personalID' => $id]); $responsable->personalID = $input['ciResponsable']; $responsable->emision = $input['ciResponsableEmision']; $responsable->nombres = ucwords(strtolower($input['nombresReponsable'])); $responsable->apellidos = ucwords(strtolower($input['apellidosResponsable'])); $responsable->ocupacion = $input['ocupacionResponsable']; $responsable->tipoPersonal = "Responsable"; $responsable->parentesco = Input::get('parentesco'); $responsable->save(); $output['status'] = 'success'; $output['msg'] = 'Persona actualizad correctamente....'; } return $responsable; return $responsable; } else { if (Input::get('updateType') == 'documents') { $input = Input::all(); $ben = Beneficiario::where('beneficiarioID', '=', $id)->get()->first(); // -------------- UPLOAD THE DOCUMENTS ----------------- $documents = ['certnac', 'CIprueba', 'solicitud', 'croquis', 'perfil']; $fullname = $ben->nombres . " " . $ben->apellidos; foreach ($documents as $document) { if (Input::hasFile($document)) { $path = public_path() . "/beneficiarios_documents/{$document}/"; File::makeDirectory($path, $mode = 0777, true, true); $file = Input::file($document); $extension = $file->getClientOriginalExtension(); $filename = "{$document}_{$id}_{$fullname}.{$extension}"; Input::file($document)->move($path, $filename); $edoc = Bendocumentos::where('beneficiarioID', '=', $id)->get()->first(); if ($edoc) { $edoc->fileName = $filename; $edoc->type = $document; $edoc->save(); } else { $edoc = new Bendocumentos(); $edoc->beneficiarioID = $id; $edoc->fileName = $filename; $edoc->type = $document; $edoc->save(); } } } Activity::log(['contentId' => $id, 'contentType' => 'Beneficiario', 'user_id' => Auth::admin()->get()->id, 'action' => 'Update', 'description' => 'Actualizacion ' . Input::get('updateType'), 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); return Redirect::route('admin.beneficiarios.edit', $id)->with('successDocuments', "<strong>Actualizacion</strong> Existosa"); // ********** END UPLOAD THE DOCUMENTS********** } } } } } Activity::log(['contentId' => $id, 'contentType' => 'Beneficiario', 'user_id' => Auth::admin()->get()->id, 'action' => 'Update', 'description' => 'Actualizacion ' . Input::get('updateType'), 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); //-------Documents info Details Update END-------- return Response::json($output, 200); }
/** * Update the specified employee in storage. */ public function update($id) { if (Input::get('updateType') == 'responsable') { $per = Personal::where('personalID', '=', $id)->get()->first(); $validator = Validator::make($input = Input::all(), Personal::rules('personalInfo', $per->id)); if ($validator->fails()) { $output['status'] = 'error'; $output['msg'] = $validator->getMessageBag()->toArray(); } else { // Profile Image Upload if (Input::hasFile('fotoPersonal')) { $path = public_path() . "/personalImages/"; File::makeDirectory($path, $mode = 0777, true, true); $image = Input::file('fotoPersonal'); $fullname = Input::get('nombres') . " " . Input::get('apellidos'); $extension = $image->getClientOriginalExtension(); $filename = "{$fullname}_{$id}." . strtolower($extension); Image::make($image->getRealPath())->fit(872, 724, function ($constraint) { $constraint->upsize(); })->save($path . $filename); } else { $filename = Input::get('hiddenImage'); } $responsable = Personal::firstOrNew(['personalID' => $id]); $responsable->nombres = ucwords(strtolower($input['nombres'])); $responsable->apellidos = ucwords(strtolower($input['apellidos'])); $responsable->email = Input::get('email'); $responsable->password = Hash::make($input['password']); $responsable->genero = Input::get('genero'); $responsable->tipoPersonal = Input::get('tipoPersonal'); $responsable->telefono = Input::get('telefono'); $responsable->fechanac = date('Y-m-d', strtotime(Input::get('fechanac'))); $responsable->fotoPersonal = isset($filename) ? $filename : 'default.jpg'; $responsable->save(); // return $responsable; Activity::log(['contentId' => $id, 'contentType' => 'Personal', 'user_id' => Auth::admin()->get()->id, 'action' => 'Update', 'description' => 'Actualizacion ' . Input::get('tipoPersonal'), 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); $output['status'] = 'success'; $output['msg'] = 'Persona actualizad correctamente....'; } } //-------Documents info Details Update END-------- return Redirect::route('admin.personal.edit', $id)->with('successPersonal', "<strong>Actualizacion</strong> Existosa"); }