Skip to content

Commit

Permalink
Excel cargos oficiales
Browse files Browse the repository at this point in the history
  • Loading branch information
elyambay committed Dec 10, 2019
1 parent f33c463 commit 0e6839b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app/Http/Controllers/CargosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}


}
8 changes: 8 additions & 0 deletions resources/views/cargos/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<div class="col l4">
<a href="{{ route('cargos.create') }}" class="btn waves-effect waves-light lighten-1 white-text"><i class="material-icons left">add</i>Cargo</a>
</div>
<form id="excel_form" action="{{ route('cargos.excel') }}" method="POST">
{{ csrf_field() }}
<button class="btn waves-effect waves-light lighten-1 white-text" type="submit" name="submit_excel" id="btn_excel">
<i class="material-icons left">cloud_download</i>Excel
</button>
</form>
</div>
<div class="row">
<div class="browser-window">
Expand Down Expand Up @@ -89,5 +95,7 @@ function delete_row(row){
return false;
}
}
</script>
@endpush
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 0e6839b

Please sign in to comment.