diff --git a/app/Http/Controllers/CargosController.php b/app/Http/Controllers/CargosController.php index b02ce6d..07a19af 100644 --- a/app/Http/Controllers/CargosController.php +++ b/app/Http/Controllers/CargosController.php @@ -10,7 +10,10 @@ use App\Area; use App\Nivel; use App\Rubro; +use Carbon\Carbon; +use PHPExcel_Worksheet_Drawing; use flash; +use Excel; use DB; class CargosController extends Controller @@ -145,5 +148,50 @@ public function getDetalle(Request $request){ return $cargo->detalle; } + public function excel(Request $request){ + + $now = Carbon::now(); + $filename = "cargos_".$now->format('diYHms'); + $cargos = DB::table('cargos') + ->leftJoin('areas', 'cargos.area_id', '=', 'areas.id') + ->leftJoin('niveles', 'cargos.id', '=', 'niveles.id') + ->leftJoin('cargos_en', 'cargos.id', '=', 'cargos_en.id') + ->select(DB::raw( + 'cargos.id, + cargos.descripcion nombre_cargo, + cargos.detalle descripcion, + cargos.area_id, + areas.descripcion area, + cargos.nivel_id, + niveles.descripcion nivel, + cargos_en.descripcion cargo_ingles, + cargos_en.detalle detalle_ingles' + )) + ->get(); + $data = array(); + foreach ($cargos as $cargo) { + $data[] = (array)$cargo; + }; + + Excel::create($filename, function($excel) use($data) { + $excel->sheet("Cargos", function($sheet) use($data){ + $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); + + $sheet->cells('A5:I5', function($cells){ + $cells->setBackground('#00897b'); + $cells->setFontColor("#FFFFFF"); + $cells->setFontWeight("bold"); + // $cells->setValignment('center'); + $cells->setAlignment('center'); + }); + $sheet->fromArray($data, null, 'A5'); + }); + })->export('xlsx'); + } + } diff --git a/resources/views/cargos/list.blade.php b/resources/views/cargos/list.blade.php index b339810..3dc1d77 100644 --- a/resources/views/cargos/list.blade.php +++ b/resources/views/cargos/list.blade.php @@ -5,6 +5,12 @@
addCargo
+
+ {{ csrf_field() }} + +
@@ -89,5 +95,7 @@ function delete_row(row){ return false; } } + + @endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index a611f7c..dfd3a72 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,6 +25,7 @@ Route::resource('empresas', 'EmpresasController'); Route::post('cargos_detalle', "CargosController@getDetalle")->name('cargos.detalle'); + Route::post('cargos_excel', 'CargosController@excel')->name('cargos.excel'); Route::resource('cargos', 'CargosController'); Route::resource('cargos_clientes', 'CargosClientesController');