From 4f5595379afdfc01bb9c7c16a75da371b0718867 Mon Sep 17 00:00:00 2001 From: elyambay Date: Tue, 16 Oct 2018 10:20:24 -0300 Subject: [PATCH] Agregar ABM de Areas y Niveles --- app/Area.php | 4 + app/Http/Controllers/AreasController.php | 90 ++++++++++++++++++ .../Controllers/FileAttachmentController.php | 2 +- app/Http/Controllers/NivelesController.php | 87 +++++++++++++++++ app/Nivel.php | 4 + resources/views/areas/create.blade.php | 30 ++++++ resources/views/areas/edit.blade.php | 31 ++++++ resources/views/areas/list.blade.php | 95 +++++++++++++++++++ resources/views/cargos/list.blade.php | 30 ++---- resources/views/layout.blade.php | 19 ++-- resources/views/niveles/create.blade.php | 30 ++++++ resources/views/niveles/edit.blade.php | 31 ++++++ resources/views/niveles/list.blade.php | 93 ++++++++++++++++++ resources/views/report/panel.blade.php | 9 +- routes/web.php | 4 + 15 files changed, 529 insertions(+), 30 deletions(-) create mode 100644 app/Http/Controllers/AreasController.php create mode 100644 app/Http/Controllers/NivelesController.php create mode 100644 resources/views/areas/create.blade.php create mode 100644 resources/views/areas/edit.blade.php create mode 100644 resources/views/areas/list.blade.php create mode 100644 resources/views/niveles/create.blade.php create mode 100644 resources/views/niveles/edit.blade.php create mode 100644 resources/views/niveles/list.blade.php diff --git a/app/Area.php b/app/Area.php index 7d4e550..2218af0 100644 --- a/app/Area.php +++ b/app/Area.php @@ -13,4 +13,8 @@ class Area extends Model public function detalleEncuestas(){ return $this->hasMany("App\Detalle_encuesta"); } + + public function areaEn(){ + return $this->hasOne('App\Area_en', 'id' , 'id'); + } } diff --git a/app/Http/Controllers/AreasController.php b/app/Http/Controllers/AreasController.php new file mode 100644 index 0000000..f515ba2 --- /dev/null +++ b/app/Http/Controllers/AreasController.php @@ -0,0 +1,90 @@ +forget('delete_failed'); + } + return view('areas.list')->with('dbData', $dbData)->with('toast', $toast); + } + + public function create(){ + return view('areas.create'); + } + + public function store(Request $request){ + DB::transaction(function() use($request){ + //Cargamos el área en español + $dbData = new Area($request->all()); + //Cargamos el área en inglés + $dbDataEn = new Area_en(); + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registros + $dbData->save(); + $dbDataEn->save(); + }); + + return redirect()->route('areas.index'); + } + + public function show($id) + { + // + } + + public function edit($id){ + $dbData = Area::find($id); + return view('areas.edit')->with('dbData', $dbData); + } + + public function update(Request $request, $id){ + + //Area en español + $dbData = Area::find($id); + //Area en inglés + $dbDataEn = Area_en::find($id); + DB::transaction(function() use($request, $id, $dbData, $dbDataEn){ + //Cargamos el área en español + $dbData->fill($request->all()); + //Cargamos el área en inglés + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registos + $dbData->save(); + $dbDataEn->save(); + }); + + + + return redirect()->route('areas.index'); + } + + public function destroy($id){ + DB::beginTransaction(); + try{ + $dbData = Area::find($id); + $dbDataEn = Area_en::find($id); + $dbData->delete(); + $dbDataEn->delete(); + }catch(\Exception $e){ + DB::rollback(); + session(['delete_failed'=>"true"]); + return redirect()->back()->withErrors($e->getMessage()); + } + DB::commit(); + + return redirect()->route('areas.index'); + } +} diff --git a/app/Http/Controllers/FileAttachmentController.php b/app/Http/Controllers/FileAttachmentController.php index ceb5805..d7b7fd4 100644 --- a/app/Http/Controllers/FileAttachmentController.php +++ b/app/Http/Controllers/FileAttachmentController.php @@ -121,7 +121,7 @@ public function upload(Request $request){ public function getPeriodosAjax(Request $request){ $periodos = $this->getPeriodos($request->rubro_id); - + session(['delete_failed'=>"true"]); return $periodos; } diff --git a/app/Http/Controllers/NivelesController.php b/app/Http/Controllers/NivelesController.php new file mode 100644 index 0000000..72de1dd --- /dev/null +++ b/app/Http/Controllers/NivelesController.php @@ -0,0 +1,87 @@ +forget('delete_failed'); + } + return view('niveles.list')->with('dbData', $dbData)->with('toast', $toast); + } + + public function create(){ + return view('niveles.create'); + } + + public function store(Request $request){ + DB::transaction(function() use($request){ + //Cargamos el área en español + $dbData = new Nivel($request->all()); + //Cargamos el área en inglés + $dbDataEn = new Nivel_en(); + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registros + $dbData->save(); + $dbDataEn->save(); + }); + + return redirect()->route('niveles.index'); + } + + public function show($id) + { + // + } + + public function edit($id){ + $dbData = nivel::find($id); + return view('niveles.edit')->with('dbData', $dbData); + } + + public function update(Request $request, $id){ + + //nivel en español + $dbData = Nivel::find($id); + //nivel en inglés + $dbDataEn = Nivel_en::find($id); + DB::transaction(function() use($request, $id, $dbData, $dbDataEn){ + //Cargamos el área en español + $dbData->fill($request->all()); + //Cargamos el área en inglés + $dbDataEn->descripcion = $request->descripcion_en; + //Guardamos los registos + $dbData->save(); + $dbDataEn->save(); + }); + return redirect()->route('niveles.index'); + } + + public function destroy($id){ + DB::beginTransaction(); + try{ + $dbData = Nivel::find($id); + $dbDataEn = Nivel_en::find($id); + $dbData->delete(); + $dbDataEn->delete(); + + }catch(\Exception $e){ + DB::rollback(); + session(['delete_failed'=>"true"]); + return redirect()->back()->withErrors($e->getMessage()); + } + DB::commit(); + return redirect()->route('niveles.index'); + } +} diff --git a/app/Nivel.php b/app/Nivel.php index 4b72baa..071a70e 100644 --- a/app/Nivel.php +++ b/app/Nivel.php @@ -13,4 +13,8 @@ class Nivel extends Model public function detalleEncuestas(){ return $this->hasMany("App\Detalle_encuesta"); } + + public function nivelEn(){ + return $this->hasOne('App\Nivel_en', 'id' , 'id'); + } } diff --git a/resources/views/areas/create.blade.php b/resources/views/areas/create.blade.php new file mode 100644 index 0000000..3d949e8 --- /dev/null +++ b/resources/views/areas/create.blade.php @@ -0,0 +1,30 @@ +@extends('layout') +@section('content') +
+
+
+

Crear Nueva Area

+
+
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
+
+@stop diff --git a/resources/views/areas/edit.blade.php b/resources/views/areas/edit.blade.php new file mode 100644 index 0000000..8db9563 --- /dev/null +++ b/resources/views/areas/edit.blade.php @@ -0,0 +1,31 @@ +@extends('layout') +@section('content') +
+
+
+

Editar Area

+
+
+
+
+
+ + +
+
+ + +
+
+
+ + {{ method_field('PUT') }} + +
+
+
+
+
+@stop \ No newline at end of file diff --git a/resources/views/areas/list.blade.php b/resources/views/areas/list.blade.php new file mode 100644 index 0000000..56add78 --- /dev/null +++ b/resources/views/areas/list.blade.php @@ -0,0 +1,95 @@ +@extends('layout') + +@section('content') +
+
+ addArea +
+
+
+
+
+

Listado de Areas

+
+
+ + + + + + + + + + + @foreach($dbData as $est) + + + + + + + @endforeach + +
IdDescripciónDescripción (Inglés)Opciones
{{ $est->id }}{{ $est->descripcion }}{{ $est->areaEn->descripcion }} + editEditar + + + + deleteBorrar + + +
+
+
+
+ @if($toast) +
+ @endif + +@endsection +@push('scripts') + +@endpush \ No newline at end of file diff --git a/resources/views/cargos/list.blade.php b/resources/views/cargos/list.blade.php index 3d11ab4..b339810 100644 --- a/resources/views/cargos/list.blade.php +++ b/resources/views/cargos/list.blade.php @@ -6,7 +6,6 @@ addCargo - @if($dbData)
@@ -15,16 +14,19 @@
- - - - + + + + + + @foreach($dbData as $est) - + +
IdDescripciónOpciones
IdDescripciónDescripción (en inglés)Opciones
{{ $est->id }}{{ $est->descripcion }}{{ $est->descripcion }}{{ $est->cargoEn->descripcion }} editEditar @@ -50,22 +52,6 @@ - @else -
-
-

Listado de Cargos

-
-
-
- Saludos -

Esta es la primera vez que participa de la Encuesta, por favor ingrese un cargo nuevo

-
-
- -
-
-
- @endif @endsection @push('scripts') +@endpush \ No newline at end of file diff --git a/resources/views/report/panel.blade.php b/resources/views/report/panel.blade.php index b586814..a84a971 100644 --- a/resources/views/report/panel.blade.php +++ b/resources/views/report/panel.blade.php @@ -69,8 +69,15 @@ "info": "Page _PAGE_ of _PAGES_", "infoEmpty": "No records found", "infoFiltered": "(Filtered out of _MAX_ rows)", - "search": "Search" + "search": "Search", + "paginate":{ + "first": "First", + "last": "Last", + "next": "Next", + "previous": "Previous", + }, } + }); } diff --git a/routes/web.php b/routes/web.php index 0cebe68..0f574d6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -124,6 +124,10 @@ Route::resource('admin_ficha', 'FichasController'); + Route::resource('areas', 'AreasController'); + + Route::resource('niveles', 'NivelesController'); + });