Browse Source

fix stampanteController e Datatable, fix migration attivita,

marcofalabretti 11 hours ago
parent
commit
d0dd517546

+ 129
- 0
app/DataTables/ImpostazioniDataTable.php View File

1
+<?php
2
+
3
+namespace App\DataTables;
4
+
5
+use App\Models\Impostazioni;
6
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
7
+use Yajra\DataTables\EloquentDataTable;
8
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
9
+use Yajra\DataTables\Html\Button;
10
+use Yajra\DataTables\Html\Column;
11
+use Yajra\DataTables\Html\Editor\Editor;
12
+use Yajra\DataTables\Html\Editor\Fields;
13
+use Yajra\DataTables\Services\DataTable;
14
+use Illuminate\Support\Facades\Auth;
15
+
16
+class ImpostazioniDataTable extends DataTable
17
+{
18
+    public function __construct(){
19
+        $this->dataTableVariable = 'dataTable_impostazioni';
20
+    }
21
+    /**
22
+     * Build the DataTable class.
23
+     *
24
+     * @param QueryBuilder<Impostazioni> $query Results from query() method.
25
+     */
26
+    public function dataTable(QueryBuilder $query): EloquentDataTable
27
+    {
28
+        return (new EloquentDataTable($query))
29
+            ->addColumn('action', function($entity){
30
+                return view('impostazioni.menu', ['entity' => $entity]);
31
+            })
32
+            ->setRowId('id');
33
+    }
34
+
35
+    /**
36
+     * Get the query source of dataTable.
37
+     *
38
+     * @return QueryBuilder<Impostazioni>
39
+     */
40
+    public function query(Impostazioni $model): QueryBuilder
41
+    {
42
+        if($this->attivita_id){
43
+            return $model->newQuery()->where('attivita_id', $this->attivita_id);
44
+        }else{
45
+            return $model->newQuery()->whereRaw('1 = 0');
46
+        }
47
+    }
48
+
49
+    /**
50
+     * Optional method if you want to use the html builder.
51
+     */
52
+    public function html(): HtmlBuilder
53
+    {
54
+        $buttons = [];
55
+        if(Auth::user()->hasRole('superadmin')){
56
+            array_push($buttons, Button::make('create')
57
+                ->editor('editor')
58
+                ->className('btn btn-sm btn-primary mb-4')
59
+                ->formTitle('Crea nuova impostazione')
60
+                ->text('<i class="fas fa-plus"></i> Nuova impostazione'));
61
+        }
62
+
63
+        $editorFields = [
64
+            Fields\Hidden::make('attivita_id')->default($this->attivita_id),
65
+            Fields\Text::make('label')->label('Label'),
66
+            Fields\Text::make('valore')->label('Valore'),
67
+            Fields\Text::make('descrizione')->label('Descrizione'),
68
+            Fields\Text::make('opzioni')->label('Opzioni'),
69
+        ];
70
+        
71
+        if(Auth::user()->hasRole('superadmin')){
72
+            $editorFields[] = Fields\Text::make('chiave')->label('Chiave');
73
+            $editorFields[] = Fields\Select::make('tipo')->label('Tipo')->options(Impostazioni::getTipi());
74
+        }
75
+
76
+        return $this->builder()
77
+                    ->setTableId($this->dataTableVariable)
78
+                    ->columns($this->getColumns())
79
+                    ->minifiedAjax()
80
+                    ->orderBy(1)
81
+                    ->selectStyleSingle()
82
+                    ->buttons($buttons)
83
+                    ->language(asset('assets/Italian.json'))
84
+                    ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
85
+                    ->editor(
86
+                        Editor::make()->fields($editorFields)
87
+                    )
88
+                    ->initComplete("function(settings, json){
89
+                        initComplete_impostazioni();
90
+                    }") ;
91
+    }
92
+
93
+    /**
94
+     * Get the dataTable columns definition.
95
+     */
96
+    public function getColumns(): array
97
+    {
98
+        $columns = [
99
+            Column::make('id')->visible(false),
100
+        ];
101
+
102
+        if(Auth::user()->hasRole('superadmin')){
103
+            $columns[] = Column::make('chiave');
104
+            $columns[] = Column::make('tipo')->title('Tipo');
105
+        }
106
+
107
+        $columns[] = Column::make('label');
108
+        $columns[] = Column::make('valore')->title('Valore')->visible(false);
109
+        $columns[] = Column::make('descrizione')->title('Descrizione');
110
+        $columns[] = Column::make('opzioni')->title('Opzioni')->visible(false);
111
+        $columns[] = Column::computed('action')
112
+                  ->title('')
113
+                  ->exportable(false)
114
+                  ->printable(false)
115
+                  ->width(60)
116
+                  ->addClass('text-center')
117
+                  ->responsivePriority(1);
118
+
119
+        return $columns;
120
+    }
121
+
122
+    /**
123
+     * Get the filename for export.
124
+     */
125
+    protected function filename(): string
126
+    {
127
+        return 'Impostazioni_' . date('YmdHis');
128
+    }
129
+}

+ 2
- 2
app/DataTables/PagamentoDataTable.php View File

65
     public function query(Pagamento $model): QueryBuilder
65
     public function query(Pagamento $model): QueryBuilder
66
     {
66
     {
67
         if($this->attivita_id){
67
         if($this->attivita_id){
68
-            return $model->newQuery()->where('attivita_id', $this->attivita_id);
68
+            return $model->newQuery()->where('attivita_id', $this->attivita_id)->orderBy('created_at', 'desc');
69
         }else{
69
         }else{
70
-            return $model->newQuery()->whereRaw('1 = 0');
70
+            return $model->newQuery()->whereRaw('1 = 0')->orderBy('created_at', 'desc');
71
         }
71
         }
72
     }
72
     }
73
 
73
 

+ 6
- 1
app/DataTables/StampanteDataTable.php View File

54
      */
54
      */
55
     public function query(Dispositivo $model): QueryBuilder
55
     public function query(Dispositivo $model): QueryBuilder
56
     {
56
     {
57
-        return $model->newQuery()->where('tipo', Dispositivo::STAMPANTE);
57
+        if($this->attivita_id){
58
+            return $model->newQuery()->where('tipo', Dispositivo::STAMPANTE)->where('attivita_id', $this->attivita_id);
59
+        }else{
60
+            return $model->newQuery()->where(' 1 = 0');
61
+        }
62
+
58
     }
63
     }
59
 
64
 
60
     /**
65
     /**

+ 3
- 0
app/Http/Controllers/StampanteController.php View File

7
 use App\DataTables\StampanteDataTable;
7
 use App\DataTables\StampanteDataTable;
8
 use App\DataTables\StampanteDataTableEditor;
8
 use App\DataTables\StampanteDataTableEditor;
9
 use Illuminate\Support\Facades\Auth;
9
 use Illuminate\Support\Facades\Auth;
10
+use Illuminate\Support\Facades\Session;
11
+
10
 
12
 
11
 class StampanteController extends Controller
13
 class StampanteController extends Controller
12
 {
14
 {
28
     
30
     
29
     public function index(StampanteDataTable $dataTable)
31
     public function index(StampanteDataTable $dataTable)
30
     {
32
     {
33
+        $dataTable->attivita_id = Session::get('attivita_attuale');
31
         return $dataTable->render('stampante.index');
34
         return $dataTable->render('stampante.index');
32
     }
35
     }
33
     public function store(StampanteDataTableEditor $editor)
36
     public function store(StampanteDataTableEditor $editor)

+ 4
- 1
database/migrations/2026_03_25_004544_attivita.php View File

40
 
40
 
41
     foreach ($gruppoTabelle as $nomeTabella) {
41
     foreach ($gruppoTabelle as $nomeTabella) {
42
         Schema::table($nomeTabella, function (Blueprint $table) {
42
         Schema::table($nomeTabella, function (Blueprint $table) {
43
-            $table->unsignedBigInteger('attivita_id')->nullable()->after('id');
43
+            if (!Schema::hasColumn($table->getTable(), 'attivita_id')) {
44
+                $table->bigInteger('attivita_id')->unsigned()->nullable()->after('id');
45
+            }
46
+       
44
             $table->foreign('attivita_id')->references('id')->on('attivita')->onDelete('set null');
47
             $table->foreign('attivita_id')->references('id')->on('attivita')->onDelete('set null');
45
         });
48
         });
46
     }
49
     }

+ 1
- 1
database/migrations/2026_06_18_164218_contabilizzare_metodo_di_pagamento.php View File

12
     public function up(): void
12
     public function up(): void
13
     {
13
     {
14
         Schema::table('metodo_pagamento', function (Blueprint $table) {
14
         Schema::table('metodo_pagamento', function (Blueprint $table) {
15
-            $table->boolean('escludi_contabilita')->default(false);
15
+            $table->boolean('escludi_contabilita')->default(false)->nullable();
16
         });
16
         });
17
     }
17
     }
18
 
18
 

+ 39
- 0
database/seeders/ImpostazioniSeeder.php View File

1
+<?php
2
+
3
+namespace Database\Seeders;
4
+
5
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
6
+use Illuminate\Database\Seeder;
7
+use App\Models\Impostazioni;
8
+
9
+class ImpostazioniSeeder extends Seeder
10
+{
11
+    /**
12
+     * Run the database seeds.
13
+     */
14
+
15
+    public function run(): void
16
+    {
17
+        $impostazioni = [
18
+            [
19
+                'label' => 'Stampa QR code scontrino',
20
+                'chiave' => 'stampa_qr_code_chiamata',
21
+                'valore' => 'true',
22
+                'tipo' => 'boolean',
23
+                'opzioni' => null,
24
+            ],
25
+            [
26
+                'label' => 'Larghezza della stampante in caratteri',
27
+                'chiave' => 'stampante_width_default',
28
+                'valore' => '42',
29
+                'tipo' => 'integer',
30
+                'opzioni' => null,
31
+            ]
32
+        ];
33
+
34
+        foreach ($impostazioni as $impostazione) {
35
+            Impostazioni::firstOrCreate($impostazione);
36
+            echo "Impostazione '{$impostazione['label']}' creata\n";
37
+        } 
38
+    }
39
+}

Loading…
Cancel
Save