Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
elyambay committed Oct 15, 2018
2 parents 6c17168 + ae5b014 commit bd3cfb5
Show file tree
Hide file tree
Showing 75 changed files with 1,855 additions and 745 deletions.
16 changes: 16 additions & 0 deletions app/Area_en.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Area_en extends Model
{
protected $table = "areas_en";

protected $fillable = ["descripcion"];

public function detalleEncuestas(){
return $this->hasMany("App\Detalle_encuesta");
}
}
4 changes: 4 additions & 0 deletions app/Cargo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public function nivel(){
return $this->belongsTo("App\Nivel");
}

public function cargoEn(){
return $this->hasOne('App\Cargo_en', 'id', 'id');
}

}
29 changes: 29 additions & 0 deletions app/Cargo_en.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Cargo_en extends Model
{
protected $table = "cargos_en";

protected $fillable = ["descripcion", "area_id", "nivel_id", "is_temporal", "detalle"];

public function encuestasCargo(){
return $this->hasMany("App\Encuestas_cargo");
}

public function cargosRubro(){
return $this->hasMany("App\Cargos_rubro");
}

public function area(){
return $this->belongsTo("App\Area");
}

public function nivel(){
return $this->belongsTo("App\Nivel_en");
}

}
10 changes: 10 additions & 0 deletions app/Cargos_rubro.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class cargos_rubro extends Model

protected $fillable = ["cargo_id", "rubro_id"];

public $timestamps = false;

public function rubro(){
return $this->belongsTo("App\Rubro");
}
Expand All @@ -18,6 +20,14 @@ public function cargo(){
return $this->belongsTo("App\Cargo");
}

public function cargoEn(){
return $this->belongsTo("App\Cargo_en", "cargo_id", "id");
}

public function getDescripcionRubroAttribute(){
return $this->rubro->descripcion;
}



}
102 changes: 84 additions & 18 deletions app/Http/Controllers/CargosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Cargo;
use App\Cargo_en;
use App\Cargos_rubro;
use App\Area;
use App\Nivel;
use App\Rubro;
use flash;
use DB;

class CargosController extends Controller
{
Expand All @@ -18,20 +22,46 @@ public function index(){

public function create(){
$dbNivel = Nivel::all()->pluck('descripcion', 'id');
$dbArea = Area::all()->pluck('descripcion', 'id');
return view('cargos.create')->with('dbNivel', $dbNivel)
$dbArea = Area::all()->pluck('descripcion', 'id');
$dbRubros = Rubro::get()->pluck('descripcion', 'id');
return view('cargos.create')->with('dbNivel', $dbNivel)
->with('dbRubros', $dbRubros)
->with('dbArea', $dbArea);
}

public function store(Request $request){
$dbData = new Cargo($request->all());
if(!is_null($request->is_temporal)){
$dbData->is_temporal = 1;
}else{
$dbData->is_temporal = 0;
}

$dbData->save();
DB::transaction(function() use($request){
$dbData = new Cargo($request->all());
if(!is_null($request->is_temporal)){
$dbData->is_temporal = 1;
}else{
$dbData->is_temporal = 0;
}

$dbDataEn = new Cargo_en($request->all());
if(!is_null($request->is_temporal)){
$dbDataEn->is_temporal = 1;
}else{
$dbDataEn->is_temporal = 0;
}
$dbDataEn->descripcion = $request->descripcion_en;
$dbDataEn->detalle = $request->detalle_en;

$dbData->save();
$dbDataEn->save();

if($request->rubros){
foreach ($request->rubros as $key => $value) {
$dbRubro = new Cargos_rubro();
$dbRubro->cargo_id = $dbData->id;
$dbRubro->rubro_id = $value;
$dbRubro->save();
}
}


});

return redirect()->route('cargos.index');
}

Expand All @@ -44,21 +74,57 @@ public function edit($id){
$dbData = Cargo::find($id);
$dbNivel = Nivel::all()->pluck('descripcion', 'id');
$dbArea = Area::all()->pluck('descripcion', 'id');
$dbRubros = Rubro::get()->pluck('descripcion', 'id');
return view('cargos.edit')->with('dbData', $dbData)
->with('dbNivel', $dbNivel)
->with('dbRubros', $dbRubros)
->with('dbArea', $dbArea);
}

public function update(Request $request, $id){

//Cargo en español
$dbData = Cargo::find($id);
//Cargo en inglés
$dbDataEn = Cargo_en::find($id);
DB::transaction(function() use($request, $id, $dbData, $dbDataEn){
$dbRubros = Cargos_rubro::where('cargo_id', $id);

if($request->rubros){
if($dbRubros->count() > 0){
$dbRubros->delete();

}
foreach ($request->rubros as $key => $value) {
$dbRubro = new Cargos_rubro();
$dbRubro->cargo_id = $id;
$dbRubro->rubro_id = $value;
$dbRubro->save();
}
}else{
if($dbRubros->count() > 0){
$dbRubros->delete();
}
}

$dbData->fill($request->all());
$dbDataEn->fill($request->all());
if(!is_null($request->is_temporal)){
$dbData->is_temporal = 1;
$dbDataEn->is_temporal = 1;
}else{
$dbData->is_temporal = 0;
$dbDataEn->is_temporal = 0;
}
$dbDataEn->descripcion = $request->descripcion_en;
$dbDataEn->detalle = $request->detalle_en;

$dbData->save();
$dbDataEn->save();
});



$dbData = Cargo::find($id);
$dbData->fill($request->all());
if(!is_null($request->is_temporal)){
$dbData->is_temporal = 1;
}else{
$dbData->is_temporal = 0;
}
$dbData->save();
return redirect()->route('cargos.index');
}

Expand Down
26 changes: 26 additions & 0 deletions app/Http/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;
use Session;


class LanguageController extends Controller
{
public function switchLang($lang){

if (array_key_exists($lang, config('languages'))) {
session()->put('applocale', $lang);
}
return redirect()->back();
}

public function switchLangReport($lang){
if (array_key_exists($lang, config('languages'))) {
session()->put('applocale', $lang);
}
return "true";
}
}
Loading

0 comments on commit bd3cfb5

Please sign in to comment.