2 Commit

Autore SHA1 Messaggio Data
  marcofalabretti fa032c8a2f Variante piatto 1 mese fa
  marcofalabretti d0dd517546 fix stampanteController e Datatable, fix migration attivita, 1 mese fa

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

@@ -0,0 +1,129 @@
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 Vedi File

@@ -65,9 +65,9 @@ class PagamentoDataTable extends DataTable
65 65
     public function query(Pagamento $model): QueryBuilder
66 66
     {
67 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 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 Vedi File

@@ -54,7 +54,12 @@ class StampanteDataTable extends DataTable
54 54
      */
55 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 Vedi File

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

+ 32
- 0
app/Http/Controllers/VariatePiattoController.php Vedi File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use Illuminate\Http\Request;
6
+use App\Models\VariantePiatto;
7
+
8
+class VariantePiattoController extends Controller
9
+{
10
+    public static $permission_group = "Varianti Piatto";
11
+    public static $permissions = [
12
+        'view-variante-piatto' => 'Vedi',
13
+        'create-variante-piatto' => 'Crea',
14
+        'edit-variante-piatto' => 'Modifica',
15
+        'delete-variante-piatto' => 'Elimina',
16
+    ];
17
+
18
+    public static function middleware(): array
19
+    {
20
+        return [
21
+            new Middleware('permission:view-variante-piatto', only: ['index']),
22
+            new Middleware('permission:create-variante-piatto|edit-variante-piatto|delete-variante-piatto', only: ['store', 'update', 'destroy']),
23
+        ];
24
+    }
25
+
26
+    public function index(VariantePiattoDataTable $dataTable)
27
+    {
28
+        $dataTable->attivita_id = Session::get('attivita_attuale');
29
+        return $dataTable->render('variante_piatto.index');
30
+    }
31
+
32
+}

+ 74
- 0
app/Models/AbstractModels/AbstractVariantePiatto.php Vedi File

@@ -0,0 +1,74 @@
1
+<?php
2
+/**
3
+ * Model object generated by: Skipper (http://www.skipper18.com)
4
+ * Do not modify this file manually.
5
+ */
6
+
7
+namespace App\Models\AbstractModels;
8
+
9
+abstract class AbstractVariantePiatto extends \Illuminate\Foundation\Auth\User
10
+{
11
+    /**  
12
+     * The table associated with the model.
13
+     * 
14
+     * @var string
15
+     */
16
+    protected $table = 'variante_piatto';
17
+    
18
+    /**  
19
+     * Primary key type.
20
+     * 
21
+     * @var string
22
+     */
23
+    protected $keyType = 'bigInteger';
24
+    
25
+    /**  
26
+     * The model's default values for attributes.
27
+     * 
28
+     * @var array
29
+     */
30
+    // protected $attributes = ['is_gruppo' => 0];
31
+    
32
+    /**  
33
+     * The attributes that should be cast to native types.
34
+     * 
35
+     * @var array
36
+     */
37
+    protected $casts = [
38
+        'id' => 'integer',
39
+        'attivita_id' => 'integer',
40
+        'piatto_id' => 'integer',
41
+        'label' => 'string',
42
+        'prezzo' => 'decimal:2',
43
+        'is_attivo' => 'boolean',
44
+        'created_at' => 'datetime',
45
+        'updated_at' => 'datetime'
46
+    ];
47
+    
48
+    /**  
49
+     * The attributes that are mass assignable.
50
+     * 
51
+     * @var array
52
+     */
53
+    protected $fillable = [
54
+        'id',
55
+        'attivita_id',
56
+        'piatto_id',
57
+        'label',
58
+        'prezzo',
59
+        'is_attivo',
60
+        'created_at',
61
+        'updated_at'
62
+    ];
63
+    
64
+    public function attivita()
65
+    {
66
+        return $this->belongsTo('\App\Models\Attivita', 'attivita_id', 'id');
67
+    }
68
+
69
+    public function piatto()
70
+    {
71
+        return $this->belongsTo('\App\Models\Piatto', 'piatto_id', 'id');
72
+    }
73
+    
74
+}

+ 14
- 0
app/Models/VariantePiatto.php Vedi File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class VariantePiatto extends \App\Models\AbstractModels\AbstractVariantePiatto
8
+{
9
+
10
+    public function isGlobal()
11
+    {
12
+        return is_null($this->piatto_id);
13
+    }
14
+}

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

@@ -40,7 +40,10 @@ return new class extends Migration
40 40
 
41 41
     foreach ($gruppoTabelle as $nomeTabella) {
42 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 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 Vedi File

@@ -12,7 +12,7 @@ return new class extends Migration
12 12
     public function up(): void
13 13
     {
14 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
 

+ 32
- 0
database/migrations/2026_06_20_143147_create_variantes_table.php Vedi File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     */
12
+    public function up(): void
13
+    {
14
+        Schema::create('variante_piatto', function (Blueprint $table) {
15
+            $table->id();
16
+            $table->bigInteger('attivita_id')->unsigned();
17
+            $table->bigInteger('piatto_id')->unsigned()->nullable();
18
+            $table->string('label')->nullable();
19
+            $table->decimal('prezzo', 10, 2)->nullable();
20
+            $table->boolean('is_attivo')->default(true);
21
+            $table->timestamps();
22
+        });
23
+    }
24
+
25
+    /**
26
+     * Reverse the migrations.
27
+     */
28
+    public function down(): void
29
+    {
30
+        Schema::dropIfExists('variante_piatto');
31
+    }
32
+};

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

@@ -0,0 +1,39 @@
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…
Annulla
Salva