Skip to content

Commit

Permalink
Clonador de Clubes
Browse files Browse the repository at this point in the history
  • Loading branch information
elsoftpy committed May 4, 2021
1 parent 957cc41 commit 161ce5b
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/Http/Controllers/Actions/EmpresaEncuestaAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers\Actions;

use App\Cabecera_encuesta;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class EmpresaEncuestaAction extends Controller
{
public function getEncuesta($empresa)
{
return Cabecera_encuesta::where('empresa_id', $empresa)
->pluck('periodo', 'id');
}
}
19 changes: 19 additions & 0 deletions app/Http/Controllers/Actions/EmpresaRubroAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers\Actions;

use App\Empresa;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Rubro;

class EmpresaRubroAction extends Controller
{
public function getEmpresas(Rubro $rubro)
{
$rubroId = $rubro->id;

return Empresa::where('rubro_id', $rubroId)
->pluck('descripcion', 'id');
}
}
67 changes: 67 additions & 0 deletions app/Http/Controllers/CloneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Controllers;

use App\Cabecera_encuesta;
use App\Empresa;
use App\Rubro;
use Illuminate\Http\Request;

class CloneController extends Controller
Expand Down Expand Up @@ -281,7 +283,72 @@ public function cloneAMX(Request $request){
return redirect()->route('clonar.amx.form')->with('toast', $toast);
}

public function index(){

$rubros = Rubro::pluck('descripcion', 'id');
$empresas = Empresa::pluck('descripcion', 'id');

return view('encuestas.clone.index')->with('rubros', $rubros)
->with('empresas', $empresas);


}

public function cloneClub(Request $request)
{
ini_set('max_execution_time', 0);
ini_set('memory_limit', '1000M');
if(!$request->empresas){
return redirect()->route('clone.error.missing', 'Empresas origen y destino');
}

if(!$request->rubro_id){
return redirect()->route('clone.error.missing', 'CLUB DESTINO');
}

if(!$request->periodo){
return redirect()->route('clone.error.missing', 'PERIODO');
}

$empresas = json_decode($request->empresas);
foreach ($empresas as $empresa) {
//dd($empresa);
$encuesta = Cabecera_encuesta::find($empresa->encuesta);
if($encuesta){
$cabecera = $encuesta->replicate();
$cabecera->rubro_id = $request->rubro_id;
$cabecera->periodo = $request->periodo;
$cabecera->empresa_id = $empresa->id;
$cabecera->save();
$encuestaCargo = $encuesta->encuestasCargo;
foreach($encuestaCargo as $cargo){
$newCargo = $cargo->replicate();
$newCargo->cabecera_encuesta_id = $cabecera->id;
$newCargo->save();
$detalle = $cargo->detalleEncuestas;
if($detalle){
$newDetalle = $detalle->replicate();
$newDetalle->cabecera_encuesta_id = $cabecera->id;
$newDetalle->encuestas_cargo_id = $newCargo->id;
$newDetalle->save();
}
}
}
}


return redirect()->route('clone.success');
}

public function success()
{
return view('encuestas.clone.success');
}

public function errorMissing($field)
{
return view('encuestas.clone.errors.error_missing')->with('field', $field);
}


}
Binary file added public/images/caratula-amx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions resources/views/encuestas/clone/errors/error_missing.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@extends('layout')
@section('content')
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="hoverable bordered">
<div class="card red lighten-2">
<div class="card-content white-text" style="margin-bottom:2.5em;">
<span class="card-title"><strong>Los sentimos</strong></span>
<p>No encontramos datos para el campo: {{ $field }}</p>
</div>
<div class="card-action white">
<a href="{{route('clonar.club')}}">Volver al formulario de clonación</a>
</div>
</div>
</div>
</div>
</div>
@stop
231 changes: 231 additions & 0 deletions resources/views/encuestas/clone/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
@extends('layout')
@section('content')
<div class="row">
<div class="browser-window">
<div class="top-bar">
<h4>Clonar Club</h4>
</div>
<div class="content">
<form class="col s12" id="realForm" action="{{route('clonar.club')}}" method="POST">

<div class="row" >
<div class="input-field col s6">
<select class="validate" id="rubro_id" name="rubro_id">
<option value="">Elija una Opción</option>
@foreach ($rubros as $id => $descripcion)
<option value="{{$id}}">{{ $descripcion }}</option>
@endforeach
</select>
<label class="active" for="rubro_id">Club Destino</label>
</div>
<div class="input-field col s6">
<input type="text" class="validate" id="periodo" name="periodo"/>
<label for="periodo">Periodo</label>
</div>
</div>
<div class="row">
<div class="input-field col s4">
<select class="validate" id="empresa_id" name="empresa_id">
<option value="">Elija una Opción</option>
@foreach ($empresas as $id => $descripcion)
<option value="{{$id}}">{{ $descripcion }}</option>
@endforeach
</select>
<label class="active" for="empresa_id">Empresa Origen</label>
</div>
<div class="input-field col s4">
<select class="validate" id="encuesta_id" name="encuesta_id">
<option value="">Elija una Opción</option>

</select>
<label class="active" for="encuesta_id">Periodo origen</label>
</div>
<div class="input-field col s4">
<select class="validate" id="empresa_destino" name="empresa_destino">
<option value="">Elija una Opción</option>

</select>
<label class="active" for="empresa_destino">Empresa Destino</label>
</div>
</div>

<input id="empresas" type="text" name="empresas">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
<div class="button-group">
<a class="btn waves-effect waves-light amber" href="#" id="add">Opción
<i class="material-icons left">add</i>
</a>
<button class="btn waves-effect waves-light" type="submit" name="submit">Guardar
<i class="material-icons left">save</i>
</button>

</div>
<div class="row">
<div class="browser-window">
<div class="top-bar">
<div class="row">
<p>
<h6>Empresas a clonar</h6>
</p>
</div>
</div>
<div class="content">
<table id="detlist" class="highlight">
<thead>
<tr>
<th>Empresa Origen</th>
<th>Periodo</th>
<th>Empresa Destino</th>
<th>Opción</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
</div>
</div>
</div>

</form>
</div>
</div>
</div>

@stop
@push('scripts')
<script>
var opciones = [];
$('#realForm').submit(function(e){
if( $("#empresas").val() === '' ){
e.preventDefault();
}
});
$('#realForm').keypress(function(event){
if (event.keyCode === 10 || event.keyCode === 13){
event.preventDefault();
}
});
$(document).ready(function() {
$('select').select2();
});
$("#empresa_id").change(function(){
var selectEncuesta = $("#encuesta_id");
var empresaId = $(this).val();
var url = "{{route('empresa.encuesta.list', ':empresa')}}";
console.log(url);
url = url.replace(':empresa', empresaId);
console.log(url);
selectEncuesta.empty();
$.get(url,
function(json){
var data = $.map(json, function(text, id){
return {text:text, id:id};
});
for(i = 0; i < data.length; i++){
selectEncuesta.append(
$("<option></option>").attr("value", data[i].id)
.text(data[i].text));
}
$("select").select2();
}
);
});
$("#rubro_id").change(function(){
var selectEmpresa = $("#empresa_destino");
var rubroId = $(this).val();
var url = "{{route('rubro.empresas.list', ':rubro')}}";
url = url.replace(':rubro', rubroId);
selectEmpresa.empty();
$.get(url,
function(json){
var data = $.map(json, function(text, id){
return {text:text, id:id};
});
for(i = 0; i < data.length; i++){
selectEmpresa.append(
$("<option></option>").attr("value", data[i].id)
.text(data[i].text));
}
$("select").select2();
}
);
});
$('#add').click(function(e){
e.preventDefault();
if(!$("#encuesta_id").val() == ''){
var item = {};
var rowCount = $('#detlist .ingData').length;
rowCount++;
item.id = $("#empresa_id").val();
item.encuesta = $("#encuesta_id").val();
item.destino = $("#empresa_destino").val();
item.row = rowCount;
opciones.push(item);
var empresaOrigen = $("#empresa_id option:selected").text();
var periodo = $("#encuesta_id option:selected").text();
var empresaDestino = $("#empresa_destino option:selected").text();
$('#empresas').val(JSON.stringify(opciones));
var outHTML =
'<tr class="ingData" id="ingRow' + rowCount + '">'
+ '<td>'
+'<div id="empresa' + rowCount + '">' + empresaOrigen + '</div>'
+'</td>'
+ '<td>'
+'<div id="periodo' + rowCount + '">' + periodo + '</div>'
+'</td>'
+ '<td>'
+'<div id="empresa_dest' + rowCount + '">' + empresaDestino + '</div>'
+'</td>'
+ '<td>'
+ '<button class="btn waves-effect waves-light red" onClick="removeItem('+rowCount+')" type="button">Borrar</button>'
+ '</td>'
+ '</tr>';
$('#detlist tr:last').after(outHTML);
$('#ingRow'+rowCount).children('td,div').hide().slideDown(300);
$('#ingRow'+rowCount).children('td, div').animate({'backgroundColor' : '#00A65A'}, 300);
$('#ingRow'+rowCount).children('td, div').animate({'backgroundColor' : '#FFFFFF'}, 300);
// clear detail form
$('#opcion').val('');
item.length = 0;
}
});
function removeItem(row){
var actualRow = arrayObjectIndexOf(opciones, row, "row");
$('#ingRow'+row).children('td, div').animate({'backgroundColor':'#fb6c6c'},300);
opciones.splice(actualRow, 1);
$('#fields').val(JSON.stringify(opciones));
$('#ingRow'+row).children('td, div').slideUp(300, function(){
this.remove();
});
$('#empresas').val(JSON.stringify(opciones));
}
function arrayObjectIndexOf(myArray, searchTerm, property) {
for(var i = 0, len = myArray.length; i < len; i++) {
if (myArray[i][property] === searchTerm){
return i;
}
}
return -1;
}
</script>
@endpush
18 changes: 18 additions & 0 deletions resources/views/encuestas/clone/success.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@extends('layout')
@section('content')
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="hoverable bordered">
<div class="card teal lighten-2">
<div class="card-content white-text" style="margin-bottom:2.5em;">
<span class="card-title"><strong>La clonación fue exitosa</strong></span>
<p>Las encuestas están disponibles para el nuevo club</p>
</div>
<div class="card-action white">
<a href="{{route('home')}}">@lang('attachmentNotFound.button_return_home')</a>
</div>
</div>
</div>
</div>
</div>
@stop
Loading

0 comments on commit 161ce5b

Please sign in to comment.