public function destroy($id) { $funcionarios = Funcionario::find($id); $funcionarios->delete(); Session::flash('message', 'El funcionaro ' . $funcionarios->nombres . ' de rut ' . $funcionarios->rut . ' fue eliminado'); return redirect()->route('Administrador.funcionarios.index'); }
public function store(Request $request) { //dd('jajaja'); $file = $request->file('file'); if (is_null($request->file('file'))) { Session::flash('message', 'Seleccion el archivo'); return redirect()->back(); } //obtenemos el campo file obtenido por el formulario $nombre = $file->getClientOriginalName(); //indicamos que queremos guardar un nuevo archivo en el disco local \Storage::disk('local')->put($nombre, \File::get($file)); $falla = false; $departamentos = $request->get('departamentos'); // dd($departamentos); \Excel::load('/storage/public/files/' . $nombre, function ($archivo) use(&$falla) { $result = $archivo->get(); //leer todas las filas del archivo foreach ($result as $key => $value) { $departamentos = Departamento::whereNombre($value->departamento_id)->pluck('id'); if (is_null($departamentos)) { // El campus no existe, deberia hacer algo para mitigar esto, o retornarlo al usuario ... } $var = new Funcionario(); $datos = ['rut' => $value->rut, 'nombres' => $value->nombres, 'apellidos' => $value->apellidos, 'email' => $value->email, 'departamento_id' => $departamentos]; $validator = Validator::make($datos, Funcionario::storeRules()); if ($validator->fails()) { Session::flash('message', 'Los Funcionarios ya existen o el archivo ingresado no es valido'); $falla = true; } else { $var->fill($datos); $var->save(); } } })->get(); if ($falla) { // Fallo la validacion de algun campus, retornar al index con mensaje return redirect()->route('Administrador.funcionarios.index'); } \Storage::delete($nombre); Session::flash('message', 'Los Docentes fueron agregados exitosamente!'); return redirect()->route('Administrador.funcionarios.index'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Funcionario::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'dependenciaid' => $this->dependenciaid, 'cargoid' => $this->cargoid, 'estado' => $this->estado, 'usuariocrea' => $this->usuariocrea, 'fechacrea' => $this->fechacrea, 'usuariomodifica' => $this->usuariomodifica, 'fechamodifica' => $this->fechamodifica]); $query->andFilterWhere(['like', 'primernombre', $this->primernombre])->andFilterWhere(['like', 'segundonombre', $this->segundonombre])->andFilterWhere(['like', 'primerapellido', $this->primerapellido])->andFilterWhere(['like', 'segundoapellido', $this->segundoapellido])->andFilterWhere(['like', 'celular', $this->celular])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
public function show($id) { $funcionarios = Funcionario::find($id); //dd($Campus); if ($funcionarios) { $data = array(array('rut', 'nombres', 'apellidos', 'email', 'departamento_id'), array($funcionarios->rut, $funcionarios->nombres, $funcionarios->apellidos, $funcionarios->email, $funcionarios->departamentos->nombre)); Excel::create('Funcionarios' . $funcionarios->nombres, function ($excel) use($data) { $excel->sheet('Sheetname', function ($sheet) use($data) { $sheet->fromArray($data); }); })->download('csv'); } else { abort('404'); } }
/** * @return \yii\db\ActiveQuery */ public function getFuncionario() { return $this->hasOne(Funcionario::className(), ['id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getFuncionarios() { return $this->hasMany(Funcionario::className(), ['dependenciaid' => 'id']); }
/** * Finds the Funcionario model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Funcionario the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Funcionario::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }