Skip to content

Commit

Permalink
Seleccionar ficha activa para encuestas
Browse files Browse the repository at this point in the history
  • Loading branch information
elyambay committed Nov 7, 2018
1 parent fd869c3 commit 8c7ca54
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 28 deletions.
6 changes: 5 additions & 1 deletion app/Ficha_dato.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ class Ficha_dato extends Model
{
protected $table = 'ficha_datos';

protected $fillable = ['rubro_id', 'periodo', 'tipo_cambio', 'cargos_emergentes'];
protected $fillable = ['rubro_id', 'periodo', 'tipo_cambio', 'cargos_emergentes', 'activo'];

public function rubro(){
return $this->belongsTo('App\Rubro');
}

public function scopeActiva($query){
return $query->where('activo', 1);
}
}
19 changes: 15 additions & 4 deletions app/Http/Controllers/FichasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function create(){

public function store(Request $request){
$dbData = new Ficha_dato($request->all());

$dbData->activo = 0;
$dbData->save();
return redirect()->route('admin_ficha.index');
}
Expand All @@ -44,15 +44,26 @@ public function edit($id){
$rubro = Rubro::get()->first()->id;
$periodos = $this->getPeriodos($rubro);
$rubros = $this->getRubros();
return view('fichas.create')->with('dbData', $dbData)
return view('fichas.edit')->with('dbData', $dbData)
->with('periodos', $periodos)
->with('rubros', $rubros);
}

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

$dbData = new Ficha_dato($request->all());

if($request->activo){
$activo = 1;
$fichas = Ficha_dato::where('rubro_id', $request->rubro_id)->get();
foreach($fichas as $ficha){
$ficha->activo = 0;
$ficha->save();
}
}else{
$activo = 0;
}
$dbData = Ficha_dato::find($id);
$dbData->fill($request->all());
$dbData->activo = $activo;
$dbData->save();
return redirect()->route('admin_ficha.index');
}
Expand Down
38 changes: 29 additions & 9 deletions app/Http/Controllers/ReporteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,18 @@ public function ficha($id){
$per = Session::get('periodo');
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $id)->whereRaw("periodo = '". $per."'")->first();
}else{
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $id)->whereRaw('id = (select max(id) from cabecera_encuestas where empresa_id = '. $id.')')->first();
$dbFicha = Ficha_dato::activa()->where('rubro_id', $rubro)->first();
if($dbFicha){
$periodo = $dbFicha->periodo;
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $id)->where('periodo', $periodo)->first();
}else{
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $id)->whereRaw('id = (select max(id) from cabecera_encuestas where empresa_id = '. $id.')')->first();
}

}
$cargos = Encuestas_cargo::where('cabecera_encuesta_id', $dbEncuesta->id)->get()->count();
$periodo = $dbEncuesta->periodo;
$dbFicha = Ficha_dato::where('rubro_id', $rubro)->where('periodo', $periodo)->first();

if($dbFicha){
$cargos = $dbFicha->cargos_emergentes;
$tipoCambio = $dbFicha = $dbFicha->tipo_cambio;
Expand Down Expand Up @@ -2522,16 +2529,29 @@ private function cargoReportAll(Request $request, $tipo){
->first();
//dd($dbEncuesta, $request->periodo);
}else{
if($dbEmpresa->rubro_id == '1'){
$per = '06/2018';
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id)
->whereRaw("periodo = '". $per."'")
->first();
$ficha = Ficha_dato::activa()->where('rubro_id', $dbEmpresa->rubro_id)->first();
if($ficha){
$per = $ficha->periodo;
}else{
$per = null;
}
if($per){
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id)
->whereRaw('id = (select max(id) from cabecera_encuestas where empresa_id = '. $dbEmpresa->id.')')
->first();
->where("periodo",$per)
->first();
}else{
if($dbEmpresa->rubro_id == '1'){
$per = '06/2018';
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id)
->whereRaw("periodo = '". $per."'")
->first();
}else{
$dbEncuesta = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id)
->whereRaw('id = (select max(id) from cabecera_encuestas where empresa_id = '. $dbEmpresa->id.')')
->first();
}
}



}
Expand Down
30 changes: 22 additions & 8 deletions resources/views/fichas/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h4>Editar Cargo</h4>
</div>
<div class="content">
<form class="col s12" action="{{route('cargos.update', $dbData->id)}}" method="POST">
<form class="col s12" action="{{route('admin_ficha.update', $dbData->id)}}" method="POST">
<div class="row">
<div class="input-field col s6">
<select id="rubro_id" name="rubro_id">
Expand Down Expand Up @@ -37,19 +37,32 @@
<div class="row">
<div class="input-field col s6">
<label for="cargos_emergentes" id="cargos_emergentes">Cargos Emergentes</label>
<input type="number" name="cargos_emergentes" id="cargos_emergentes" class="validate"/>
<input type="number" name="cargos_emergentes" id="cargos_emergentes" class="validate" value="{{$dbData->cargos_emergentes}}"/>
</div>

<div class="input-field col s6">
<div class="input-field col s4">
<label for="tipo_cambio" id="tipo_cambio">Tipo de Cambio</label>
<input type="text" name="tipo_cambio" id="tipo_cambio" class="validate"/>
<input type="text" name="tipo_cambio" id="tipo_cambio" class="validate" value="{{$dbData->tipo_cambio}}"/>
</div>
<div class="input-field col s2">
<label for="activo">
@if ($dbData->activo)
<input type="checkbox" name="activo" id="activo" checked="checked">
@else
<input type="checkbox" name="activo" id="activo">
@endif
<span>Activo</span>
</label>
</div>
</div>
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
{{ method_field('PUT') }}
<button class="btn waves-effect waves-light" type="submit" name="submit">Guardar
<i class="material-icons left">save</i>
</button>
<div class="row">
<button class="btn waves-effect waves-light" type="submit" name="submit">Guardar
<i class="material-icons left">save</i>
</button>
</div>

</form>
</div>
</div>
Expand All @@ -58,7 +71,8 @@
@push('scripts')
<script type="text/javascript">
$(function(){
$("select").select2();
//$("select").select2();
$("select").formSelect();
});
Expand Down
2 changes: 1 addition & 1 deletion resources/views/includes/translation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@endif
</div>
<!-- Language selector button -->
<div class="fixed-action-btn">
<div class="fixed-action-btn" style="bottom:50px !important;">
@if (app()->getLocale() == 'es')
<a class="btn-floating btn-large tooltipped amber" data-position="left" data-tooltip="Cambiar idioma">
@else
Expand Down
5 changes: 3 additions & 2 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{!! MaterializeCSS::include_css() !!}
<link rel="stylesheet" href="{{ asset('css/flash.css')}}">
<style type="text/css"></style>
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<!-- Datatables css -->
<link href="{{ asset('/plugins/datatables/dataTables-materialize.css') }}" rel="stylesheet"/>
Expand Down Expand Up @@ -193,7 +193,8 @@
<script src="{{ asset('/plugins/intro.js-2.7.0/intro.js') }}" type="text/javascript"></script>
<!-- InputMask -->
<script src="{{ asset('plugins/input-mask/jquery.inputmask.bundle.js') }}"></script>

<!-- mcafee -->
<script type="text/javascript" src="https://cdn.ywxi.net/js/1.js" async></script>
<script type="text/javascript">
var tour = introJs().setOptions({ "skipLabel": "Lo tengo",
"nextLabel": "Continue",
Expand Down
2 changes: 1 addition & 1 deletion resources/views/niveles/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div class="input-field col s6">
<input id="descripcion_en" type="text" class="validate" name="descripcion_en" >
<label for="descripcion_en">Descipción (en inglés)</label>
<label for="descripcion_en">Descripción (en inglés)</label>
</div>
</div>
<div class="row">
Expand Down
5 changes: 3 additions & 2 deletions resources/views/report/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{!! MaterializeCSS::include_css() !!}
<link rel="stylesheet" href="{{ asset('css/flash.css')}}">
<style type="text/css"></style>
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Datatables css -->
<link href="{{ asset('/plugins/datatables/dataTables-materialize.css') }}" rel="stylesheet"/>
<!-- Select 2 Materialize -->
Expand Down Expand Up @@ -106,7 +106,8 @@
<script src="{{ asset('/plugins/chartjs/Chart.bundle.js') }}" type="text/javascript"></script>
<!-- Intro JS -->
<script src="{{ asset('/plugins/intro.js-2.7.0/intro.js') }}" type="text/javascript"></script>

<!-- mcafee -->
<script type="text/javascript" src="https://cdn.ywxi.net/js/1.js" async></script>
<script type="text/javascript">
var tour = introJs().setOptions({ "skipLabel": "Lo tengo",
"nextLabel": "Continue",
Expand Down

0 comments on commit 8c7ca54

Please sign in to comment.