diff --git a/app/Http/Controllers/Admin/ReportController.php b/app/Http/Controllers/Admin/ReportController.php index 4fcdc4f..626d1b3 100644 --- a/app/Http/Controllers/Admin/ReportController.php +++ b/app/Http/Controllers/Admin/ReportController.php @@ -105,12 +105,12 @@ public function destroy($id) // } - /*public function getPeriodos(Request $request){ + public function getPeriodosEmpresa(Request $request){ $id = $request->empresa_id; $periodos = Cabecera_encuesta::distinct('periodo') ->where('empresa_id', $id) ->pluck('periodo', 'periodo'); return $periodos; - }*/ + } } diff --git a/app/Http/Controllers/FichasController.php b/app/Http/Controllers/FichasController.php index f056790..2f58737 100644 --- a/app/Http/Controllers/FichasController.php +++ b/app/Http/Controllers/FichasController.php @@ -8,7 +8,9 @@ use App\Cabecera_encuesta; use App\Rubro; use App\Traits\PeriodosTrait; +use Carbon\Carbon; use flash; +use DB; class FichasController extends Controller { @@ -41,9 +43,10 @@ public function show($id) public function edit($id){ $dbData = Ficha_dato::find($id); - $rubro = Rubro::get()->first()->id; - $periodos = $this->getPeriodos($rubro); + $rubro = Rubro::find($dbData->rubro_id); + $periodos = $this->getPeriodos($rubro->id); $rubros = $this->getRubros(); + //dd($periodos, $dbData); return view('fichas.edit')->with('dbData', $dbData) ->with('periodos', $periodos) ->with('rubros', $rubros); @@ -80,5 +83,24 @@ public function getDetalle(Request $request){ return $cargo->detalle; } + public function countEmergentes(Request $request){ + $rubro = $request->rubro_id; + $periodo = $request->periodo; + $results = DB::select( DB::raw( + "SELECT count(distinct cargo_id) cargos + FROM encuestas_cargos e + WHERE cabecera_encuesta_id in ( select id + from cabecera_encuestas + where rubro_id = :rubro + and periodo = :periodo)"), + array('rubro' => $rubro, 'periodo' => $periodo)); + //return $results; + if($results){ + $count = $results[0]->cargos; + }else{ + $count = 0; + } + return $count; + } } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index e277aac..2bc2b0c 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -6,6 +6,7 @@ use Auth; use App\Cabecera_encuesta; use App\beneficios_cabecera_encuesta; +use App\Ficha_dato; use App\Traits\ClubsTrait; class HomeController extends Controller @@ -45,9 +46,22 @@ public function index() }else{ $dbEmpresa = Auth::user()->empresa; - $dbEncuestas = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id)->orderBy('id', 'DESC')->get(); - $dbEncuesta = $dbEncuestas->first(); + $ficha = Ficha_dato::where('rubro_id', $dbEmpresa->rubro_id)->activa()->first(); + if($ficha){ + $dbEncuesta = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id) + ->where('periodo', $ficha->periodo) + ->first(); + $dbEncuestas = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id) + ->orderBy('id', 'DESC') + ->get(); + }else{ + $dbEncuestas = Cabecera_encuesta::where('empresa_id', $dbEmpresa->id)->orderBy('id', 'DESC')->get(); + $dbEncuesta = $dbEncuestas->first(); + } + + $dbEncuestaAnt = $dbEncuestas->get(1); + //dd($dbEncuesta, $dbEncuestaAnt); $club = $this->club($dbEmpresa->rubro_id); return view('clientes.home')->with('dbEmpresa', $dbEmpresa) ->with('club', $club) diff --git a/app/Http/Controllers/ReporteController.php b/app/Http/Controllers/ReporteController.php index 4eca33d..6e80f99 100644 --- a/app/Http/Controllers/ReporteController.php +++ b/app/Http/Controllers/ReporteController.php @@ -166,9 +166,13 @@ public function ficha($id){ $empresa = Empresa::find($id); $rubro = $empresa->rubro_id; $locale = $this->getIdioma(); + if(Session::has('periodo')){ $per = Session::get('periodo'); $dbEncuesta = Cabecera_encuesta::where('empresa_id', $id)->whereRaw("periodo = '". $per."'")->first(); + $dbFicha = Ficha_dato::where('rubro_id', $rubro) + ->where('periodo', $per) + ->first(); }else{ $dbFicha = Ficha_dato::activa()->where('rubro_id', $rubro)->first(); if($dbFicha){ @@ -678,46 +682,76 @@ public function cargoReportClubExcel(Request $request){ $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - // Salario Efectivo Total Anual + }); + + // Comision + $sheet->cell('AI5', function($cell){ - $cell->setValue('EFECTIVO TOTAL ANUAL'); + $cell->setValue('COMISION'); }); $sheet->mergeCells('AI5:AN5'); $sheet->cells('AI5:AN5', function($cells){ - $cells->setBackground('#f57c00'); + $cells->setBackground('#6a1b9a'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); - // $cells->setValignment('center'); + // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - // Salario Base Comparativo Header + }); + + // Salario Efectivo Total Anual $sheet->cell('AO5', function($cell){ - $cell->setValue('SALARIO BASE COMP.'); + $cell->setValue('EFECTIVO TOTAL ANUAL'); }); $sheet->mergeCells('AO5:AT5'); $sheet->cells('AO5:AT5', function($cells){ - $cells->setBackground('#0288d1'); + $cells->setBackground('#f57c00'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - // Salario Variable Anual comp. + }); + + // Salario Base Comparativo Header $sheet->cell('AU5', function($cell){ - $cell->setValue('VARIABLE ANUAL COMP.'); + $cell->setValue('SALARIO BASE COMPARATIVO ORGANIZACION VS MERCADO'); }); $sheet->mergeCells('AU5:AZ5'); $sheet->cells('AU5:AZ5', function($cells){ + $cells->setBackground('#0288d1'); + $cells->setFontColor("#FFFFFF"); + $cells->setFontWeight("bold"); + // $cells->setValignment('center'); + $cells->setAlignment('center'); + }); + // Salario Variable Anual comp. + $sheet->cell('BA5', function($cell){ + $cell->setValue('VARIABLE ANUAL COMPARATIVO ORGANIZACION VS MERCADO'); + }); + + $sheet->mergeCells('BA5:BF5'); + $sheet->cells('BA5:BF5', function($cells){ $cells->setBackground('#afb42b'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); + }); + + // Salario Variable Anual comp. + $sheet->cell('BG5', function($cell){ + $cell->setValue('RATIO SALARIO BASE ANUAL / TOTAL EFECTIVO ANUAL'); + }); + $sheet->mergeCells('BG5:BL5'); + $sheet->cells('BG5:BL5', function($cells){ + $cells->setBackground('#afb42b'); + $cells->setFontColor("#FFFFFF"); + $cells->setFontWeight("bold"); + $cells->setAlignment('center'); + }); + $itemsHeader = array("Mínimo", "25 Perc.", "Promedio", "Mediana", "75 Perc.", "Máximo"); $cargoHeader = array("Cargo Company", "Oficial", "Ocupantes", "Casos"); - for ($i= 0; $i < 8; $i++) { + for ($i= 0; $i < 10; $i++) { foreach ($itemsHeader as $key => $value) { array_push($cargoHeader, $value); } @@ -725,7 +759,7 @@ public function cargoReportClubExcel(Request $request){ } $sheet->row(6, $cargoHeader); - $sheet->cells('A6:AZ6', function($cells){ + $sheet->cells('A6:BL6', function($cells){ $cells->setBackground('#a7ffeb'); }); @@ -810,13 +844,26 @@ public function cargoReportClubExcel(Request $request){ $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - // Salario Efectivo Total Anual + }); + + // Comision $sheet->cell('AI5', function($cell){ - $cell->setValue('EFECTIVO TOTAL ANUAL'); + $cell->setValue('COMISION'); }); $sheet->mergeCells('AI5:AN5'); $sheet->cells('AI5:AN5', function($cells){ + $cells->setBackground('#6a1b9a'); + $cells->setFontColor('#FFFFFF'); + $cells->setFontWeight("bold"); + $cells->setAlignment('center'); + }); + + // Salario Efectivo Total Anual + $sheet->cell('AO5', function($cell){ + $cell->setValue('EFECTIVO TOTAL ANUAL'); + }); + $sheet->mergeCells('AO5:AT5'); + $sheet->cells('AO5:AT5', function($cells){ $cells->setBackground('#f57c00'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); @@ -824,11 +871,11 @@ public function cargoReportClubExcel(Request $request){ $cells->setAlignment('center'); }); // Salario Base Comparativo Header - $sheet->cell('AO5', function($cell){ - $cell->setValue('SALARIO BASE COMP.'); + $sheet->cell('AU5', function($cell){ + $cell->setValue('SALARIO BASE COMPARATIVO ORGANIZACION VS MERCADO'); }); - $sheet->mergeCells('AO5:AT5'); - $sheet->cells('AO5:AT5', function($cells){ + $sheet->mergeCells('AU5:AZ5'); + $sheet->cells('AU5:AZ5', function($cells){ $cells->setBackground('#0288d1'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); @@ -836,20 +883,34 @@ public function cargoReportClubExcel(Request $request){ $cells->setAlignment('center'); }); // Salario Variable Anual comp. - $sheet->cell('AU5', function($cell){ - $cell->setValue('VARIABLE ANUAL COMP.'); + $sheet->cell('BA5', function($cell){ + $cell->setValue('VARIABLE ANUAL COMPARATIVO ORGANIZACION VS MERCADO'); }); - $sheet->mergeCells('AU5:AZ5'); - $sheet->cells('AU5:AZ5', function($cells){ + $sheet->mergeCells('BA5:BF5'); + $sheet->cells('BA5:BF5', function($cells){ + $cells->setBackground('#afb42b'); + $cells->setFontColor("#FFFFFF"); + $cells->setFontWeight("bold"); + // $cells->setValignment('center'); + $cells->setAlignment('center'); + }); + + // Salario Variable Anual comp. + $sheet->cell('BG5', function($cell){ + $cell->setValue('RATIO SALARIO BASE ANUAL / TOTAL EFECTIVO ANUAL'); + }); + $sheet->mergeCells('BG5:BL5'); + $sheet->cells('BG5:BL5', function($cells){ $cells->setBackground('#afb42b'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); + }); + $itemsHeader = array("Mínimo", "25 Perc.", "Promedio", "Mediana", "75 Perc.", "Máximo"); $cargoHeader = array("Cargo Company", "Oficial", "Ocupantes", "Casos"); - for ($i= 0; $i < 8; $i++) { + for ($i= 0; $i < 10; $i++) { foreach ($itemsHeader as $key => $value) { array_push($cargoHeader, $value); } @@ -860,7 +921,7 @@ public function cargoReportClubExcel(Request $request){ $sheet->rows($detalleInternacional); - $sheet->cells('A6:AZ6', function($cells){ + $sheet->cells('A6:BL6', function($cells){ $cells->setBackground('#a7ffeb'); }); $sheet->setFreeze('A7'); @@ -885,7 +946,9 @@ public function nivelReportClubExcel(Request $request){ ->whereNotNull('cargo_oficial_id') ->pluck('nivel_oficial_id'); // variables de detalle para cada segmento + $detalleUniverso = collect(); $detalleNacional = collect(); + $detalleInternacional = collect(); $detalleInternacional = collect(); // Procesamiento por cargo @@ -899,7 +962,7 @@ public function nivelReportClubExcel(Request $request){ $nivel->descripcion, ); $itemArrayNac = $itemArray; - //$itemArrayInt = $itemArray; + $itemArrayInt = $itemArray; // por cada item del detalle foreach ($respuesta as $key => $item) { @@ -918,26 +981,25 @@ public function nivelReportClubExcel(Request $request){ } - //$detalleUniverso->push($itemArray); + $detalleUniverso->push($itemArray); $detalleNacional->push($itemArrayNac); - //$detalleInternacional->push($itemArrayInt); + $detalleInternacional->push($itemArrayInt); } $filename = 'Resultados_Niveles'.$periodo; - //Excel::create($filename, function($excel) use($detalleUniverso, $detalleNacional, $detalleInternacional) { - Excel::create($filename, function($excel) use($detalleNacional) { - /* $excel->sheet("universo", function($sheet) use($detalleUniverso){ - + Excel::create($filename, function($excel) use($detalleUniverso, $detalleNacional, $detalleInternacional) { + //Excel::create($filename, function($excel) use($detalleNacional) { + $excel->sheet("universo", function($sheet) use($detalleUniverso){ $objDrawing = new PHPExcel_Worksheet_Drawing; $objDrawing->setPath(public_path('images/logo.jpg')); //your image path $objDrawing->setCoordinates('A1'); $objDrawing->setWidthAndHeight(304,60); - $objDrawing->setWorksheet($sheet); + $objDrawing->setWorksheet($sheet); $sheet->cell('A5', function($cell){ - $cell->setValue('CARGO'); + $cell->setValue('NIVEL'); }); $sheet->mergeCells('A5:D5'); $sheet->cells('A5:D5', function($cells){ @@ -959,139 +1021,50 @@ public function nivelReportClubExcel(Request $request){ // $cells->setValignment('center'); $cells->setAlignment('center'); }); - // Salario Efectivo Anual Garantizado + + // Bono Anual $sheet->cell('K5', function($cell){ - $cell->setValue('EFECTIVO ANUAL GARANTIZADO'); + $cell->setValue('BONO ANUAL'); }); $sheet->mergeCells('K5:P5'); $sheet->cells('K5:P5', function($cells){ - $cells->setBackground('#388e3c'); + $cells->setBackground('#ffa000'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - // Salario Variable Anual + }); + + // Total efectivo anual $sheet->cell('Q5', function($cell){ - $cell->setValue('VARIABLE ANUAL'); + $cell->setValue('TOTAL EFECTIVO ANUAL'); }); $sheet->mergeCells('Q5:V5'); $sheet->cells('Q5:V5', function($cells){ - $cells->setBackground('#afb42b'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Total Adicional Anual - $sheet->cell('W5', function($cell){ - $cell->setValue('TOTAL ADICIONAL ANUAL'); - }); - $sheet->mergeCells('W5:AB5'); - $sheet->cells('W5:AB5', function($cells){ - $cells->setBackground('#fbc02d'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Bono Anual - $sheet->cell('AC5', function($cell){ - $cell->setValue('BONO ANUAL'); - }); - $sheet->mergeCells('AC5:AH5'); - $sheet->cells('AC5:AH5', function($cells){ - $cells->setBackground('#ffa000'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - - // Comision - - $sheet->cell('AI5', function($cell){ - $cell->setValue('COMISION'); - }); - $sheet->mergeCells('AI5:AN5'); - $sheet->cells('AI5:AN5', function($cells){ - $cells->setBackground('#6a1b9a'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - - // Salario Efectivo Total Anual - $sheet->cell('AO5', function($cell){ - $cell->setValue('EFECTIVO TOTAL ANUAL'); - }); - $sheet->mergeCells('AO5:AT5'); - $sheet->cells('AO5:AT5', function($cells){ - $cells->setBackground('#f57c00'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Base Comparativo Header - $sheet->cell('AU5', function($cell){ - $cell->setValue('SALARIO BASE COMPARATIVO ORGANIZACION VS MERCADO'); - }); - $sheet->mergeCells('AU5:AZ5'); - $sheet->cells('AU5:AZ5', function($cells){ - $cells->setBackground('#0288d1'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Variable Anual comp. - $sheet->cell('BA5', function($cell){ - $cell->setValue('VARIABLE ANUAL COMPARATIVO ORGANIZACION VS MERCADO'); - }); - $sheet->mergeCells('BA5:BF5'); - $sheet->cells('BA5:BF5', function($cells){ - $cells->setBackground('#afb42b'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - - // Salario Variable Anual comp. - $sheet->cell('BG5', function($cell){ - $cell->setValue('RATIO SALARIO BASE ANUAL / TOTAL EFECTIVO ANUAL'); - }); - $sheet->mergeCells('BG5:BL5'); - $sheet->cells('BG5:BL5', function($cells){ - $cells->setBackground('#afb42b'); + $cells->setBackground('#4a148c'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); - // $cells->setValignment('center'); + // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - + }); $itemsHeader = array("Mínimo", "25 Perc.", "Promedio", "Mediana", "75 Perc.", "Máximo"); $cargoHeader = array("Cargo Company", "Oficial", "Ocupantes", "Casos"); - for ($i= 0; $i < 10; $i++) { + for ($i= 0; $i < 3; $i++) { foreach ($itemsHeader as $key => $value) { array_push($cargoHeader, $value); } } - - $sheet->row(6, $cargoHeader); - //dd($detalleUniverso); - $sheet->rows($detalleUniverso); - $sheet->cells('A6:BL6', function($cells){ + $sheet->row(6, $cargoHeader); + $sheet->cells('A6:V6', function($cells){ $cells->setBackground('#a7ffeb'); - }); + }); - - $sheet->setFreeze('A7'); - }); */ + $sheet->rows($detalleUniverso); + $sheet->setFreeze('A7'); + + }); // hoja nacional $excel->sheet("nacional", function($sheet) use($detalleNacional){ $objDrawing = new PHPExcel_Worksheet_Drawing; @@ -1167,7 +1140,7 @@ public function nivelReportClubExcel(Request $request){ $sheet->setFreeze('A7'); }); // hoja internacional - /* $excel->sheet("internacional", function($sheet) use($detalleInternacional){ + $excel->sheet("internacional", function($sheet) use($detalleInternacional){ $objDrawing = new PHPExcel_Worksheet_Drawing; $objDrawing->setPath(public_path('images/logo.jpg')); //your image path $objDrawing->setCoordinates('A1'); @@ -1175,7 +1148,7 @@ public function nivelReportClubExcel(Request $request){ $objDrawing->setWorksheet($sheet); $sheet->cell('A5', function($cell){ - $cell->setValue('CARGO'); + $cell->setValue('NIVEL'); }); $sheet->mergeCells('A5:D5'); $sheet->cells('A5:D5', function($cells){ @@ -1197,93 +1170,35 @@ public function nivelReportClubExcel(Request $request){ // $cells->setValignment('center'); $cells->setAlignment('center'); }); - // Salario Efectivo Anual Garantizado + + // Bono Anual $sheet->cell('K5', function($cell){ - $cell->setValue('EFECTIVO ANUAL GARANTIZADO'); + $cell->setValue('BONO ANUAL'); }); $sheet->mergeCells('K5:P5'); $sheet->cells('K5:P5', function($cells){ - $cells->setBackground('#388e3c'); + $cells->setBackground('#ffa000'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); // $cells->setValignment('center'); $cells->setAlignment('center'); - }); - // Salario Variable Anual + }); + + // Total efectivo anual $sheet->cell('Q5', function($cell){ - $cell->setValue('VARIABLE ANUAL'); + $cell->setValue('TOTAL EFECTIVO ANUAL'); }); $sheet->mergeCells('Q5:V5'); $sheet->cells('Q5:V5', function($cells){ - $cells->setBackground('#afb42b'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Total Adicional Anual - $sheet->cell('W5', function($cell){ - $cell->setValue('TOTAL ADICIONAL ANUAL'); - }); - $sheet->mergeCells('W5:AB5'); - $sheet->cells('W5:AB5', function($cells){ - $cells->setBackground('#fbc02d'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Bono Anual - $sheet->cell('AC5', function($cell){ - $cell->setValue('BONO ANUAL'); - }); - $sheet->mergeCells('AC5:AH5'); - $sheet->cells('AC5:AH5', function($cells){ - $cells->setBackground('#ffa000'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Efectivo Total Anual - $sheet->cell('AI5', function($cell){ - $cell->setValue('EFECTIVO TOTAL ANUAL'); - }); - $sheet->mergeCells('AI5:AN5'); - $sheet->cells('AI5:AN5', function($cells){ - $cells->setBackground('#f57c00'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Base Comparativo Header - $sheet->cell('AO5', function($cell){ - $cell->setValue('SALARIO BASE COMP.'); - }); - $sheet->mergeCells('AO5:AT5'); - $sheet->cells('AO5:AT5', function($cells){ - $cells->setBackground('#0288d1'); - $cells->setFontColor("#FFFFFF"); - $cells->setFontWeight("bold"); - // $cells->setValignment('center'); - $cells->setAlignment('center'); - }); - // Salario Variable Anual comp. - $sheet->cell('AU5', function($cell){ - $cell->setValue('VARIABLE ANUAL COMP.'); - }); - $sheet->mergeCells('AU5:AZ5'); - $sheet->cells('AU5:AZ5', function($cells){ - $cells->setBackground('#afb42b'); + $cells->setBackground('#4a148c'); $cells->setFontColor("#FFFFFF"); $cells->setFontWeight("bold"); - // $cells->setValignment('center'); + // $cells->setValignment('center'); $cells->setAlignment('center'); - }); + }); $itemsHeader = array("Mínimo", "25 Perc.", "Promedio", "Mediana", "75 Perc.", "Máximo"); $cargoHeader = array("Cargo Company", "Oficial", "Ocupantes", "Casos"); - for ($i= 0; $i < 8; $i++) { + for ($i= 0; $i < 3; $i++) { foreach ($itemsHeader as $key => $value) { array_push($cargoHeader, $value); } @@ -1291,14 +1206,13 @@ public function nivelReportClubExcel(Request $request){ } $sheet->row(6, $cargoHeader); - - $sheet->rows($detalleInternacional); - - $sheet->cells('A6:AZ6', function($cells){ + $sheet->cells('A6:V6', function($cells){ $cells->setBackground('#a7ffeb'); }); + + $sheet->rows($detalleInternacional); $sheet->setFreeze('A7'); - }); */ + }); $excel->setActiveSheetIndex(0); })->export('xlsx'); } @@ -3180,6 +3094,7 @@ private function cargoReportAll(Request $request, $tipo, $muestraComision = fals } } + //dd($dbEmpresa, $ficha, $per); $periodo = $dbEncuesta->periodo; // periodo de la encuesta actual $rubro = $dbEmpresa->rubro_id; // rubro de la empresa del cliente @@ -3523,21 +3438,148 @@ private function nivelReport(Request $request, $encuestasIDs, $muestraComision = } // Recuperamos los datos de los cargos proveídos por las empresas encuestadas + $dbEncuestasNivel = Detalle_encuestas_nivel::whereIn('cabecera_encuesta_id', $encuestasIDs) + ->where('nivel_oficial_id', $nivel) + ->where('incluir', 1) + ->get(); $dbEncuestasNivelNac = Detalle_encuestas_nivel::whereIn('cabecera_encuesta_id', $encuestadasNacIds) ->where('nivel_oficial_id', $nivel) ->where('incluir', 1) ->get(); + $dbEncuestasNivelInter = Detalle_encuestas_nivel::whereIn('cabecera_encuesta_id', $encuestadasInterIds) + ->where('nivel_oficial_id', $nivel) + ->where('incluir', 1) + ->get(); - + // conteo de casos encontrados universo + $countCasos = $dbEncuestasNivel->where('cantidad_ocupantes', '>', '0') + ->unique('cabecera_encuesta_id') + ->count(); // conteo de casos encontrados nacionales $countCasosNac = $dbEncuestasNivelNac->where('cantidad_ocupantes', '>', '0') ->unique('cabecera_encuesta_id') ->count(); - //$countCasosNac = $encuestadasNacIds->count(); + // conteo de casos encontrados internacionales + $countCasosInter = $dbEncuestasNivelInter->where('cantidad_ocupantes', '>', '0') + ->unique('cabecera_encuesta_id') + ->count(); + // conteo de casos encontrados - $countOcupantesNac = $dbEncuestasNivelNac->sum('cantidad_ocupantes'); + $countOcupantes = $dbEncuestasNivel->sum('cantidad_ocupantes'); + $universo = collect(); + $segmento = "universo"; + // Salario Base + $salariosBase = $dbEncuestasNivel->where('salario_base', '>', '0') + ->pluck('salario_base'); + $salarioMin = $salariosBase->min(); + $salarioMax = $salariosBase->max(); + $salarioProm = $salariosBase->avg(); + $salarioMed = $this->median($salariosBase); + $salario25Per = $this->percentile(25,$salariosBase); + $salario75Per = $this->percentile(75, $salariosBase); + + //dd($dbClienteEnc); + $this->pusherNivel( $universo, + $countCasos, + Lang::get('reportReport.concept_salary'), + $salarioMin, + $salarioMax, + $salarioProm, + $salarioMed, + $salario25Per, + $salario75Per, + $segmento, + $dbNivel); + + //Bono + $bonos = $dbEncuestasNivel->where('bono_anual', '>', '0') + ->pluck('bono_anual'); + $bonoMin = $bonos->min(); + $bonoMax = $bonos->max(); + $bonoProm = $bonos->avg(); + $bonoMed = $this->median($bonos); + $bono25Per = $this->percentile(25, $bonos); + $bono75Per = $this->percentile(75, $bonos); + + $countCasosBonos = $dbEncuestasNivel->where('bono_anual', '>', '0') + ->unique('cabecera_encuesta_id') + ->count(); + $this->pusherNivel( $universo, + $countCasosBonos, + Lang::get('reportReport.concept_bonus'), + $bonoMin, + $bonoMax, + $bonoProm, + $bonoMed, + $bono25Per, + $bono75Per, + $segmento, + $dbNivel); + + // Efectivo Total Anual + $efectivoAnual = $dbEncuestasNivel->where('salario_base', '>', '0') + ->pluck('total_efectivo_anual'); + + $efectivoTotalMin = $efectivoAnual->min(); + $efectivoTotalMax = $efectivoAnual->max(); + $efectivoTotalProm = $efectivoAnual->avg(); + $efectivoTotalMed = $this->median($efectivoAnual); + $efectivoTotal25Per = $this->percentile(25, $efectivoAnual); + $efectivoTotal75Per = $this->percentile(75, $efectivoAnual); + + $this->pusherNivel( $universo, + $countCasos, + Lang::get('reportReport.concept_bonus'), + $efectivoTotalMin, + $efectivoTotalMax, + $efectivoTotalProm, + $efectivoTotalMed, + $efectivoTotal25Per, + $efectivoTotal75Per, + $segmento, + $dbNivel); + + //$detalleUniverso = $this->nivelSegmentArrayFactory($universo); + $detalleUniverso = array(); + foreach ($universo as $value) { + $detalleUniverso[] = array( "Concepto"=>$value["concepto"], + "ocupantes"=> $countOcupantes, + "Casos"=>$value["casos"], + "Min"=>$value["min"], + "25 Percentil"=>$value["per25"], + "Promedio"=>$value["prom"], + "Mediana"=>$value["med"], + "75 Percentil"=>$value["per75"], + "Max"=>$value["max"], + "nivel"=>$value["nivel"] + ); + } + $nacional = collect(); + $salarioBase = 0; + $salarioMin = 0; + $salarioMax = 0; + $salarioProm = 0; + $salarioMed = 0; + $salario25Per = 0; + $salario75Per = 0; + $bonos = 0; + $bonoMin = 0; + $bonoMax = 0; + $bonoProm = 0; + $bonoMed = 0; + $bono25Per = 0; + $bono75Per = 0; + $efectivoAnual = 0; + $efectivoTotalMin = 0; + $efectivoTotalMax = 0; + $efectivoTotalProm = 0; + $efectivoTotalMed = 0; + $efectivoTotal25Per = 0; + $efectivoTotal75Per = 0; + $segmento = "nacional"; + $countOcupantesNac = $dbEncuestasNivelNac->sum('cantidad_ocupantes'); // Salario Base $salariosBase = $dbEncuestasNivelNac->where('salario_base', '>', '0')->pluck('salario_base'); $salarioMin = $salariosBase->min(); @@ -3549,16 +3591,16 @@ private function nivelReport(Request $request, $encuestasIDs, $muestraComision = //dd($dbClienteEnc); $this->pusherNivel( $nacional, - $countCasosNac, - Lang::get('reportReport.concept_salary'), - $salarioMin, - $salarioMax, - $salarioProm, - $salarioMed, - $salario25Per, - $salario75Per, - $segmento, - $dbNivel); + $countCasosNac, + Lang::get('reportReport.concept_salary'), + $salarioMin, + $salarioMax, + $salarioProm, + $salarioMed, + $salario25Per, + $salario75Per, + $segmento, + $dbNivel); //Bono $bonos = $dbEncuestasNivelNac->where('bono_anual', '>', '0')->pluck('bono_anual'); @@ -3570,22 +3612,23 @@ private function nivelReport(Request $request, $encuestasIDs, $muestraComision = $bono75Per = $this->percentile(75, $bonos); $countCasosBonosNac = $dbEncuestasNivelNac->where('bono_anual', '>', '0') - ->unique('cabecera_encuesta_id') - ->count(); - $this->pusherNivel( $nacional, - $countCasosBonosNac, - Lang::get('reportReport.concept_bonus'), - $bonoMin, - $bonoMax, - $bonoProm, - $bonoMed, - $bono25Per, - $bono75Per, - $segmento, - $dbNivel); + ->unique('cabecera_encuesta_id') + ->count(); + $this->pusherNivel( $nacional, + $countCasosBonosNac, + Lang::get('reportReport.concept_bonus'), + $bonoMin, + $bonoMax, + $bonoProm, + $bonoMed, + $bono25Per, + $bono75Per, + $segmento, + $dbNivel); // Efectivo Total Anual - $efectivoAnual = $dbEncuestasNivelNac->where('salario_base', '>', '0')->pluck('total_efectivo_anual'); + $efectivoAnual = $dbEncuestasNivelNac->where('salario_base', '>', '0') + ->pluck('total_efectivo_anual'); $efectivoTotalMin = $efectivoAnual->min(); $efectivoTotalMax = $efectivoAnual->max(); @@ -3594,21 +3637,21 @@ private function nivelReport(Request $request, $encuestasIDs, $muestraComision = $efectivoTotal25Per = $this->percentile(25, $efectivoAnual); $efectivoTotal75Per = $this->percentile(75, $efectivoAnual); - $this->pusherNivel( $nacional, - $countCasosBonosNac, - Lang::get('reportReport.concept_bonus'), - $efectivoTotalMin, - $efectivoTotalMax, - $efectivoTotalProm, - $efectivoTotalMed, - $efectivoTotal25Per, - $efectivoTotal75Per, - $segmento, - $dbNivel); + $this->pusherNivel( $nacional, + $countCasosBonosNac, + Lang::get('reportReport.concept_bonus'), + $efectivoTotalMin, + $efectivoTotalMax, + $efectivoTotalProm, + $efectivoTotalMed, + $efectivoTotal25Per, + $efectivoTotal75Per, + $segmento, + $dbNivel); - $detalleNacional = $this->nivelSegmentArrayFactory($nacional); + //$detalleNacional = $this->nivelSegmentArrayFactory($nacional); $detalleNacional = array(); - foreach ($nacional as $value) { + foreach ($nacional as $value) { $detalleNacional[] = array( "Concepto"=>$value["concepto"], "ocupantes"=> $countOcupantesNac, "Casos"=>$value["casos"], @@ -3620,12 +3663,123 @@ private function nivelReport(Request $request, $encuestasIDs, $muestraComision = "Max"=>$value["max"], "nivel"=>$value["nivel"] ); - } + } + + $internacional = collect(); + $salarioBase = 0; + $salarioMin = 0; + $salarioMax = 0; + $salarioProm = 0; + $salarioMed = 0; + $salario25Per = 0; + $salario75Per = 0; + $bonos = 0; + $bonoMin = 0; + $bonoMax = 0; + $bonoProm = 0; + $bonoMed = 0; + $bono25Per = 0; + $bono75Per = 0; + $efectivoAnual = 0; + $efectivoTotalMin = 0; + $efectivoTotalMax = 0; + $efectivoTotalProm = 0; + $efectivoTotalMed = 0; + $efectivoTotal25Per = 0; + $efectivoTotal75Per = 0; + $countOcupantesInter = $dbEncuestasNivelInter->sum('cantidad_ocupantes'); + $segmento = "internacional"; + // Salario Base + $salariosBase = $dbEncuestasNivelInter->where('salario_base', '>', '0') + ->pluck('salario_base'); + $salarioMin = $salariosBase->min(); + $salarioMax = $salariosBase->max(); + $salarioProm = $salariosBase->avg(); + $salarioMed = $this->median($salariosBase); + $salario25Per = $this->percentile(25,$salariosBase); + $salario75Per = $this->percentile(75, $salariosBase); + + //dd($dbClienteEnc); + $this->pusherNivel( $internacional, + $countCasosInter, + Lang::get('reportReport.concept_salary'), + $salarioMin, + $salarioMax, + $salarioProm, + $salarioMed, + $salario25Per, + $salario75Per, + $segmento, + $dbNivel); + + //Bono + $bonos = $dbEncuestasNivelInter->where('bono_anual', '>', '0') + ->pluck('bono_anual'); + $bonoMin = $bonos->min(); + $bonoMax = $bonos->max(); + $bonoProm = $bonos->avg(); + $bonoMed = $this->median($bonos); + $bono25Per = $this->percentile(25, $bonos); + $bono75Per = $this->percentile(75, $bonos); + + $countCasosBonosInter = $dbEncuestasNivelInter->where('bono_anual', '>', '0') + ->unique('cabecera_encuesta_id') + ->count(); + $this->pusherNivel( $internacional, + $countCasosBonosInter, + Lang::get('reportReport.concept_bonus'), + $bonoMin, + $bonoMax, + $bonoProm, + $bonoMed, + $bono25Per, + $bono75Per, + $segmento, + $dbNivel); + + // Efectivo Total Anual + $efectivoAnual = $dbEncuestasNivelInter->where('salario_base', '>', '0') + ->pluck('total_efectivo_anual'); + + $efectivoTotalMin = $efectivoAnual->min(); + $efectivoTotalMax = $efectivoAnual->max(); + $efectivoTotalProm = $efectivoAnual->avg(); + $efectivoTotalMed = $this->median($efectivoAnual); + $efectivoTotal25Per = $this->percentile(25, $efectivoAnual); + $efectivoTotal75Per = $this->percentile(75, $efectivoAnual); + + $this->pusherNivel( $internacional, + $countCasosInter, + Lang::get('reportReport.concept_bonus'), + $efectivoTotalMin, + $efectivoTotalMax, + $efectivoTotalProm, + $efectivoTotalMed, + $efectivoTotal25Per, + $efectivoTotal75Per, + $segmento, + $dbNivel); + + //$detalleInternacional = $this->nivelSegmentArrayFactory($internacional); + $detalleInternacional = array(); + foreach ($internacional as $value) { + $detalleInternacional[] = array("Concepto"=>$value["concepto"], + "ocupantes"=> $countOcupantesInter, + "Casos"=>$value["casos"], + "Min"=>$value["min"], + "25 Percentil"=>$value["per25"], + "Promedio"=>$value["prom"], + "Mediana"=>$value["med"], + "75 Percentil"=>$value["per75"], + "Max"=>$value["max"], + "nivel"=>$value["nivel"] + ); + } $resultado = collect([ - // "detalle_universo"=> $detalleUniverso, - "detalle_nacional"=> $detalleNacional, - // "detalleInternacional"=>$detalleInternacional + "detalle_universo"=> $detalleUniverso, + "detalle_nacional"=> $detalleNacional, + "detalleInternacional"=>$detalleInternacional ]); return $resultado; diff --git a/resources/views/clientes/home.blade.php b/resources/views/clientes/home.blade.php index edffb8e..c44a617 100644 --- a/resources/views/clientes/home.blade.php +++ b/resources/views/clientes/home.blade.php @@ -40,7 +40,7 @@ edit@lang('homepage.button_edit') -
+
@if($dbEmpresa->rubro_id == 4) dashboard@lang('homepage.button_report') @@ -70,12 +70,16 @@
- - + +
-
- - +
+ +
+
+ +
+ +
@@ -85,6 +92,17 @@ function(json){ ); }); + $("#emergentes").click(function(e){ + e.preventDefault(); + var rubroId = $("#rubro_id").val(); + var periodo = $("#periodo").val(); + $.post("{{route('admin.ficha.contar')}}", {"rubro_id": rubroId, "periodo": periodo, "_token": "{{csrf_token()}}"}, + function(json){ + $("#cargos_emergentes").val(json); + $("#emergentes_label").addClass("active"); + }); + }); + @endpush \ No newline at end of file diff --git a/resources/views/fichas/edit.blade.php b/resources/views/fichas/edit.blade.php index 1e73cb8..74fca7a 100644 --- a/resources/views/fichas/edit.blade.php +++ b/resources/views/fichas/edit.blade.php @@ -35,13 +35,17 @@
-
- +
+
- +
+ +
- +
@@ -73,7 +77,7 @@ $(function(){ //$("select").select2(); $("select").select2(); - updatePeriodo(); + //updatePeriodo(); }); $("#rubro_id").change(function(){ @@ -100,6 +104,17 @@ function(json){ ); } + $("#emergentes").click(function(e){ + e.preventDefault(); + var rubroId = $("#rubro_id").val(); + var periodo = $("#periodo").val(); + $.post("{{route('admin.ficha.contar')}}", {"rubro_id": rubroId, "periodo": periodo, "_token": "{{csrf_token()}}"}, + function(json){ + $("#cargos_emergentes").val(json); + $("#emergentes_label").addClass("active"); + }); + }); + @endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index f73e97d..6fd731a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -123,8 +123,10 @@ Route::get('admin_reportes_filter', 'Admin\ReportController@index')->name('admin.reporte.filter'); Route::get('admin_reportes_filter/niveles', 'Admin\ReportController@filterNiveles')->name('admin.reporte.filter.niveles'); - Route::post('admin_reportes_filter/periodos', 'Admin\ReportController@getPeriodos')->name('admin.reporte.filter.periodos'); + Route::post('admin_reportes_filter/periodos', 'Admin\ReportController@getPeriodosEmpresa')->name('admin.reporte.filter.periodos'); Route::post('admin_reportes_excel/niveles', 'ReporteController@nivelReportClubExcel')->name('reportes.nivelesClubExcel'); + + Route::post('admin_ficha/contar_emergentes', 'FichasController@countEmergentes')->name('admin.ficha.contar'); Route::resource('admin_ficha', 'FichasController'); Route::resource('areas', 'AreasController');