Skip to content

Commit 1566a1b

Browse files
Implemented clients CSV export
1 parent d81e637 commit 1566a1b

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Cliente;
6+
use Illuminate\Http\Request;
7+
use App\Http\Requests;
8+
use Illuminate\Support\Facades\Auth;
9+
10+
class StrumentiController extends Controller
11+
{
12+
public function __construct()
13+
{
14+
$this->middleware('auth');
15+
$this->middleware('conferma-promemoria');
16+
}
17+
18+
public function index(Request $request)
19+
{
20+
if ($request->user()->cannot('generare-export')) {
21+
// L'utente non ha il permesso di generare documenti di pratiche di altre filiali
22+
abort(403);
23+
}
24+
25+
return view('strumenti.index');
26+
}
27+
28+
public function exportClients(Request $request)
29+
{
30+
if ($request->user()->cannot('generare-export')) {
31+
// L'utente non ha il permesso di generare documenti di pratiche di altre filiali
32+
abort(403);
33+
}
34+
35+
$columns = ['Nome', 'Cognome', 'Email', 'Cellulare', 'Telefono'];
36+
$rows = Cliente::all()->map(function ($cliente) {
37+
return [
38+
$cliente->nome,
39+
$cliente->cognome,
40+
$cliente->email,
41+
$cliente->cellulare,
42+
$cliente->telefono,
43+
];
44+
});
45+
46+
$headers = [
47+
"Content-type" => "text/csv",
48+
"Content-Disposition" => "attachment; filename=exportClienti.csv",
49+
"Pragma" => "no-cache",
50+
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
51+
"Expires" => "0"
52+
];
53+
$callback = function () use ($columns, $rows) {
54+
$file = fopen('php://output', 'w');
55+
fputcsv($file, $columns);
56+
foreach ($rows as $row) {
57+
fputcsv($file, $row);
58+
}
59+
fclose($file);
60+
};
61+
return response()->stream($callback, 200, $headers);
62+
}
63+
}

app/Http/routes.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@
105105
Route::get( '/clienti/{cliente}/pratiche/{pratica}/fatture/{fattura}/edit', 'FattureController@edit');
106106
Route::put( '/clienti/{cliente}/pratiche/{pratica}/fatture/{fattura}', 'FattureController@update');
107107
Route::post('/clienti/{cliente}/pratiche/{pratica}/fatture/', 'FattureController@store');
108-
Route::delete( '/clienti/{cliente}/pratiche/{pratica}/fatture/{fattura}', 'FattureController@destroy');
108+
Route::delete( '/clienti/{cliente}/pratiche/{pratica}/fatture/{fattura}', 'FattureController@destroy');
109+
110+
111+
112+
Route::get( '/strumenti', 'StrumentiController@index');
113+
Route::get( '/strumenti/export/clienti', 'StrumentiController@exportClients');

app/Providers/AuthServiceProvider.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,16 @@ public function boot(GateContract $gate)
106106

107107

108108
$gate->define('generare-fatture', function ($user) {
109-
return false;
109+
return false;
110110
});
111111

112112
$gate->define('cancellare-fatture', function ($user) {
113-
return false;
113+
return false;
114+
});
115+
116+
117+
$gate->define('generare-export', function ($user) {
118+
return false;
114119
});
115120
}
116121
}

resources/views/layouts/app.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<li role="separator" class="divider"></li>
9494
<li><a href="{{ action('FilialiController@index') }}"><i class="fa fa-btn fa-gear"></i>Gestione filiali</a></li>
9595
<li><a href="{{ action('PromemoriaController@indexAll', ['filiale' => Auth::user()->filiale]) }}"><i class="fa fa-btn fa-gear"></i>Elenco promemoria</a></li>
96+
<li><a href="{{ action('StrumentiController@index') }}"><i class="fa fa-btn fa-gear"></i>Strumenti</a></li>
9697
@endif
9798
<li role="separator" class="divider"></li>
9899
<li><a href="{{ url('/logout') }}"><i class="fa fa-btn fa-sign-out"></i>Logout</a></li>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
<h1 class="page-header text-center">Strumenti</h1>
6+
<div>
7+
<div class="list-group">
8+
<a class="list-group-item" href="{{ action('StrumentiController@exportClients') }}" target="_blank">
9+
<h4 class="list-group-item-heading">Export lista utenti</h4>
10+
<p class="list-group-item-text">
11+
Seleziona per generare un file CSV contenente i dati Nome, Cognome, Email, Cellulare, Telefono appartanenti a ciascun cliente registrato
12+
</p>
13+
</a>
14+
</div>
15+
</div>
16+
</div>
17+
@endsection

0 commit comments

Comments
 (0)