|
|
@@ -69,6 +69,35 @@ $configData = Helper::appClasses();
|
|
69
|
69
|
$puoDissociareDispositivo = Auth::user()->hasRole('superadmin')
|
|
70
|
70
|
|| Auth::user()->hasRole('amministratore')
|
|
71
|
71
|
|| Auth::user()->hasRole('administrator');
|
|
|
72
|
+
|
|
|
73
|
+ $campiOrdineCatalogo = [
|
|
|
74
|
+ 'cliente' => ['label' => 'Cliente', 'icon' => 'bx-user', 'type' => 'text', 'mostra' => true, 'required' => true, 'stampa' => true, 'placeholder' => 'Cliente'],
|
|
|
75
|
+ 'tavolo' => ['label' => 'Tavolo', 'icon' => 'bx-chair', 'type' => 'text', 'mostra' => true, 'required' => true, 'stampa' => true, 'placeholder' => 'Tavolo'],
|
|
|
76
|
+ 'telefono' => ['label' => 'Telefono', 'icon' => 'bx-phone', 'type' => 'tel', 'mostra' => false, 'required' => false, 'stampa' => false, 'placeholder' => 'Telefono'],
|
|
|
77
|
+ 'note_ordine' => ['label' => 'Note ordine', 'icon' => 'bx-note', 'type' => 'text', 'mostra' => false, 'required' => false, 'stampa' => true, 'placeholder' => 'Note per la cucina'],
|
|
|
78
|
+ 'coperti' => ['label' => 'N. coperti', 'icon' => 'bx-group', 'type' => 'number', 'mostra' => false, 'required' => false, 'stampa' => false, 'placeholder' => 'Coperti'],
|
|
|
79
|
+ ];
|
|
|
80
|
+ $campiOrdineSalvati = $puntoVendita->info['campi_ordine'] ?? [];
|
|
|
81
|
+ $campiOrdine = [];
|
|
|
82
|
+ foreach ($campiOrdineCatalogo as $chiave => $defaults) {
|
|
|
83
|
+ $campiOrdine[$chiave] = array_merge($defaults, $campiOrdineSalvati[$chiave] ?? []);
|
|
|
84
|
+ $campiOrdine[$chiave]['custom'] = false;
|
|
|
85
|
+ }
|
|
|
86
|
+ foreach ($campiOrdineSalvati as $chiave => $campo) {
|
|
|
87
|
+ if (! array_key_exists($chiave, $campiOrdineCatalogo)) {
|
|
|
88
|
+ $campiOrdine[$chiave] = array_merge([
|
|
|
89
|
+ 'label' => $campo['label'] ?? ucfirst(str_replace('_', ' ', $chiave)),
|
|
|
90
|
+ 'icon' => 'bx-edit',
|
|
|
91
|
+ 'type' => $campo['type'] ?? 'text',
|
|
|
92
|
+ 'mostra' => false,
|
|
|
93
|
+ 'required' => false,
|
|
|
94
|
+ 'stampa' => false,
|
|
|
95
|
+ 'placeholder' => $campo['placeholder'] ?? ($campo['label'] ?? $chiave),
|
|
|
96
|
+ 'custom' => true,
|
|
|
97
|
+ ], $campo);
|
|
|
98
|
+ $campiOrdine[$chiave]['custom'] = true;
|
|
|
99
|
+ }
|
|
|
100
|
+ }
|
|
72
|
101
|
@endphp
|
|
73
|
102
|
|
|
74
|
103
|
<div class="nav-align-top">
|
|
|
@@ -83,6 +112,11 @@ $configData = Helper::appClasses();
|
|
83
|
112
|
<i class="bx bx-cog me-1"></i>Generali
|
|
84
|
113
|
</button>
|
|
85
|
114
|
</li>
|
|
|
115
|
+ <li class="nav-item" role="presentation">
|
|
|
116
|
+ <button type="button" class="nav-link" role="tab" data-bs-toggle="tab" data-bs-target="#pv-tab-dati-ordine" aria-controls="pv-tab-dati-ordine" aria-selected="false">
|
|
|
117
|
+ <i class="bx bx-notepad me-1"></i>Dati ordine
|
|
|
118
|
+ </button>
|
|
|
119
|
+ </li>
|
|
86
|
120
|
<li class="nav-item" role="presentation">
|
|
87
|
121
|
<button type="button" class="nav-link" role="tab" data-bs-toggle="tab" data-bs-target="#pv-tab-cucine" aria-controls="pv-tab-cucine" aria-selected="false">
|
|
88
|
122
|
<i class="bx bx-restaurant me-1"></i>Cucine
|
|
|
@@ -171,6 +205,9 @@ $configData = Helper::appClasses();
|
|
171
|
205
|
<button type="button" class="btn btn-sm btn-outline-primary" data-pv-go-tab="#pv-tab-generali">
|
|
172
|
206
|
<i class="bx bx-cog me-1"></i> Modifica generali
|
|
173
|
207
|
</button>
|
|
|
208
|
+ <button type="button" class="btn btn-sm btn-outline-primary" data-pv-go-tab="#pv-tab-dati-ordine">
|
|
|
209
|
+ <i class="bx bx-notepad me-1"></i> Dati ordine
|
|
|
210
|
+ </button>
|
|
174
|
211
|
<button type="button" class="btn btn-sm btn-outline-primary" data-pv-go-tab="#pv-tab-cucine">
|
|
175
|
212
|
<i class="bx bx-restaurant me-1"></i> Gestisci cucine
|
|
176
|
213
|
</button>
|
|
|
@@ -405,6 +442,177 @@ $configData = Helper::appClasses();
|
|
405
|
442
|
</form>
|
|
406
|
443
|
</div>
|
|
407
|
444
|
|
|
|
445
|
+ <div class="tab-pane fade" id="pv-tab-dati-ordine" role="tabpanel">
|
|
|
446
|
+ <div class="mt-1">
|
|
|
447
|
+ <div class="alert alert-secondary d-flex align-items-start gap-2 mb-4" role="alert">
|
|
|
448
|
+ <i class="bx bx-info-circle fs-5 mt-1"></i>
|
|
|
449
|
+ <div>
|
|
|
450
|
+ <strong>Campi mostrati in cassa</strong>
|
|
|
451
|
+ <p class="mb-0 small">Configura i campi predefiniti o aggiungine di personalizzati. Per i campi nuovi inserisci solo etichetta e tipo: la chiave tecnica viene generata automaticamente e identifica il valore in <code>Ordine->info</code>.</p>
|
|
|
452
|
+ </div>
|
|
|
453
|
+ </div>
|
|
|
454
|
+
|
|
|
455
|
+ <form id="puntoVenditaEditCampiOrdineForm">
|
|
|
456
|
+ <div class="card mb-4 border-primary border-opacity-25">
|
|
|
457
|
+ <div class="card-header d-flex flex-wrap align-items-center justify-content-between gap-2">
|
|
|
458
|
+ <h6 class="card-title mb-0"><i class="bx bx-plus-circle me-1"></i> Aggiungi campo personalizzato</h6>
|
|
|
459
|
+ </div>
|
|
|
460
|
+ <div class="card-body">
|
|
|
461
|
+ <div class="row g-3 align-items-end">
|
|
|
462
|
+ <div class="col-md-4">
|
|
|
463
|
+ <label for="pv_nuovo_campo_label" class="form-label">Etichetta</label>
|
|
|
464
|
+ <input type="text" class="form-control form-control-sm" id="pv_nuovo_campo_label" placeholder="es. Referente evento" autocomplete="off">
|
|
|
465
|
+ <div class="form-text">Mostrata all'operatore in cassa</div>
|
|
|
466
|
+ </div>
|
|
|
467
|
+ <div class="col-md-3">
|
|
|
468
|
+ <label for="pv_nuovo_campo_type" class="form-label">Tipo</label>
|
|
|
469
|
+ <select class="form-select form-select-sm" id="pv_nuovo_campo_type">
|
|
|
470
|
+ <option value="text">Testo</option>
|
|
|
471
|
+ <option value="tel">Telefono</option>
|
|
|
472
|
+ <option value="email">Email</option>
|
|
|
473
|
+ <option value="number">Numero</option>
|
|
|
474
|
+ <option value="checkbox">Checkbox</option>
|
|
|
475
|
+ </select>
|
|
|
476
|
+ <div class="form-text">Tipo di input mostrato all'operatore</div>
|
|
|
477
|
+ </div>
|
|
|
478
|
+ <div class="col-md-3">
|
|
|
479
|
+ <label class="form-label">Chiave generata</label>
|
|
|
480
|
+ <div class="form-control form-control-sm bg-light text-muted" id="pv_nuovo_campo_chiave_preview" aria-live="polite">—</div>
|
|
|
481
|
+ <div class="form-text">Calcolata dall'etichetta</div>
|
|
|
482
|
+ </div>
|
|
|
483
|
+ <div class="col-md-2">
|
|
|
484
|
+ <button type="button" class="btn btn-sm btn-primary w-100" id="pvAggiungiCampoOrdine">
|
|
|
485
|
+ <i class="bx bx-plus me-1"></i> Aggiungi
|
|
|
486
|
+ </button>
|
|
|
487
|
+ <div class="form-text">poi salva la configurazione</div>
|
|
|
488
|
+ </div>
|
|
|
489
|
+ </div>
|
|
|
490
|
+ </div>
|
|
|
491
|
+ </div>
|
|
|
492
|
+
|
|
|
493
|
+ <div class="table-responsive">
|
|
|
494
|
+ <table class="table table-hover align-middle mb-0">
|
|
|
495
|
+ <thead class="table-light">
|
|
|
496
|
+ <tr>
|
|
|
497
|
+ <th scope="col">Campo</th>
|
|
|
498
|
+ <th scope="col">Didascalia</th>
|
|
|
499
|
+ <th scope="col" class="text-center" style="width: 8rem;">Mostra</th>
|
|
|
500
|
+ <th scope="col" class="text-center" style="width: 8rem;">Obbligatorio</th>
|
|
|
501
|
+ <th scope="col" class="text-center" style="width: 8rem;">Stampa</th>
|
|
|
502
|
+ <th scope="col" class="text-center" style="width: 5rem;"></th>
|
|
|
503
|
+ </tr>
|
|
|
504
|
+ </thead>
|
|
|
505
|
+ <tbody id="pvCampiOrdineBody">
|
|
|
506
|
+ @foreach($campiOrdine as $chiave => $campo)
|
|
|
507
|
+ <tr
|
|
|
508
|
+ data-pv-campo-ordine="{{ $chiave }}"
|
|
|
509
|
+ data-pv-campo-type="{{ $campo['type'] ?? 'text' }}"
|
|
|
510
|
+ data-pv-campo-label="{{ $campo['label'] ?? $chiave }}"
|
|
|
511
|
+ data-pv-campo-custom="{{ !empty($campo['custom']) ? '1' : '0' }}"
|
|
|
512
|
+ >
|
|
|
513
|
+ <td>
|
|
|
514
|
+ <div class="d-flex align-items-center gap-2">
|
|
|
515
|
+ <span class="avatar avatar-sm">
|
|
|
516
|
+ <span class="avatar-initial rounded bg-label-primary">
|
|
|
517
|
+ <i class="bx {{ $campo['icon'] ?? 'bx-edit' }}"></i>
|
|
|
518
|
+ </span>
|
|
|
519
|
+ </span>
|
|
|
520
|
+ <div>
|
|
|
521
|
+ <span class="fw-medium">{{ $campo['label'] ?? $chiave }}</span>
|
|
|
522
|
+ <div class="text-muted small">
|
|
|
523
|
+ Chiave: <code>{{ $chiave }}</code>
|
|
|
524
|
+ @if(!empty($campo['custom']))
|
|
|
525
|
+ <span class="badge bg-label-warning ms-1">Personalizzato</span>
|
|
|
526
|
+ @endif
|
|
|
527
|
+ </div>
|
|
|
528
|
+ </div>
|
|
|
529
|
+ </div>
|
|
|
530
|
+ </td>
|
|
|
531
|
+ <td>
|
|
|
532
|
+ <input type="text" class="form-control form-control-sm" id="pv_campo_{{ $chiave }}_placeholder" data-pv-campo-placeholder value="{{ $campo['placeholder'] ?? ($campo['label'] ?? $chiave) }}" placeholder="{{ $campo['placeholder'] ?? ($campo['label'] ?? $chiave) }}">
|
|
|
533
|
+ </td>
|
|
|
534
|
+ <td class="text-center">
|
|
|
535
|
+ <div class="form-check form-switch d-inline-block mb-0">
|
|
|
536
|
+ <input class="form-check-input" type="checkbox" id="pv_campo_{{ $chiave }}_mostra" data-pv-campo-mostra {{ !empty($campo['mostra']) ? 'checked' : '' }}>
|
|
|
537
|
+ </div>
|
|
|
538
|
+ </td>
|
|
|
539
|
+ <td class="text-center">
|
|
|
540
|
+ <div class="form-check form-switch d-inline-block mb-0">
|
|
|
541
|
+ <input class="form-check-input" type="checkbox" id="pv_campo_{{ $chiave }}_required" data-pv-campo-required {{ !empty($campo['required']) ? 'checked' : '' }}>
|
|
|
542
|
+ </div>
|
|
|
543
|
+ </td>
|
|
|
544
|
+ <td class="text-center">
|
|
|
545
|
+ <div class="form-check form-switch d-inline-block mb-0">
|
|
|
546
|
+ <input class="form-check-input" type="checkbox" id="pv_campo_{{ $chiave }}_stampa" data-pv-campo-stampa {{ !empty($campo['stampa']) ? 'checked' : '' }}>
|
|
|
547
|
+ </div>
|
|
|
548
|
+ </td>
|
|
|
549
|
+ <td class="text-center">
|
|
|
550
|
+ @if(!empty($campo['custom']))
|
|
|
551
|
+ <button type="button" class="btn btn-sm btn-icon btn-label-danger" data-pv-campo-rimuovi title="Rimuovi campo">
|
|
|
552
|
+ <i class="bx bx-trash"></i>
|
|
|
553
|
+ </button>
|
|
|
554
|
+ @endif
|
|
|
555
|
+ </td>
|
|
|
556
|
+ </tr>
|
|
|
557
|
+ @endforeach
|
|
|
558
|
+ </tbody>
|
|
|
559
|
+ </table>
|
|
|
560
|
+ </div>
|
|
|
561
|
+
|
|
|
562
|
+ <div class="row g-4 mt-2">
|
|
|
563
|
+ <div class="col-lg-6">
|
|
|
564
|
+ <div class="card h-100">
|
|
|
565
|
+ <div class="card-header">
|
|
|
566
|
+ <h6 class="card-title mb-0">
|
|
|
567
|
+ <i class="bx bx-show me-1"></i> Anteprima cassa
|
|
|
568
|
+ </h6>
|
|
|
569
|
+ </div>
|
|
|
570
|
+ <div class="card-body">
|
|
|
571
|
+ <div id="pvCampiOrdineAnteprima" class="row g-3">
|
|
|
572
|
+ @foreach($campiOrdine as $chiave => $campo)
|
|
|
573
|
+ <div class="col-md-6 pv-campo-anteprima" data-pv-anteprima="{{ $chiave }}" data-pv-anteprima-type="{{ $campo['type'] ?? 'text' }}" style="{{ !empty($campo['mostra']) ? '' : 'display:none;' }}">
|
|
|
574
|
+ @if(($campo['type'] ?? 'text') === 'checkbox')
|
|
|
575
|
+ <div class="form-check form-switch mt-1">
|
|
|
576
|
+ <input class="form-check-input" type="checkbox" id="pv_anteprima_{{ $chiave }}" disabled>
|
|
|
577
|
+ <label class="form-check-label small text-primary" for="pv_anteprima_{{ $chiave }}" data-pv-anteprima-label="{{ $chiave }}">{{ $campo['label'] ?? $chiave }}</label>
|
|
|
578
|
+ </div>
|
|
|
579
|
+ @else
|
|
|
580
|
+ <label class="form-label small text-primary mb-1" data-pv-anteprima-label="{{ $chiave }}">{{ ($campo['label'] ?? $chiave) }}</label>
|
|
|
581
|
+ <input type="{{ $campo['type'] ?? 'text' }}" class="form-control form-control-sm border-primary border-top-0 border-start-0 border-end-0 rounded-0 bg-transparent" disabled placeholder="{{ $campo['placeholder'] ?? $chiave }}">
|
|
|
582
|
+ @endif
|
|
|
583
|
+ </div>
|
|
|
584
|
+ @endforeach
|
|
|
585
|
+ <div class="col-md-6" data-pv-anteprima-totale>
|
|
|
586
|
+ <label class="form-label small text-primary mb-1">Totale</label>
|
|
|
587
|
+ <div class="fw-bold text-primary border-bottom border-primary pb-1">€ 0,00</div>
|
|
|
588
|
+ </div>
|
|
|
589
|
+ </div>
|
|
|
590
|
+ <p class="text-muted small mb-0 mt-3">Il totale resta sempre visibile in cassa.</p>
|
|
|
591
|
+ </div>
|
|
|
592
|
+ </div>
|
|
|
593
|
+ </div>
|
|
|
594
|
+ <div class="col-lg-6">
|
|
|
595
|
+ <div class="card h-100 border-primary border-opacity-25">
|
|
|
596
|
+ <div class="card-body d-flex flex-column">
|
|
|
597
|
+ <h6 class="mb-2">Suggerimento</h6>
|
|
|
598
|
+ <p class="text-muted small mb-3">I campi predefiniti restano sempre disponibili. I campi personalizzati si aggiungono con la chiave che verrà usata in <code>Ordine->info</code>.</p>
|
|
|
599
|
+ <ul class="small text-muted mb-4 ps-3">
|
|
|
600
|
+ <li><strong>Mostra</strong> — compare nel riepilogo ordine in cassa</li>
|
|
|
601
|
+ <li><strong>Obbligatorio</strong> — richiesto prima del pagamento</li>
|
|
|
602
|
+ <li><strong>Stampa</strong> — compare sullo scontrino</li>
|
|
|
603
|
+ <li><strong>Didascalia</strong> — placeholder mostrato all'operatore</li>
|
|
|
604
|
+ </ul>
|
|
|
605
|
+ <button type="button" class="btn btn-primary mt-auto align-self-start" id="saveCampiOrdine">
|
|
|
606
|
+ <i class="bx bx-save me-1"></i> Salva configurazione
|
|
|
607
|
+ </button>
|
|
|
608
|
+ </div>
|
|
|
609
|
+ </div>
|
|
|
610
|
+ </div>
|
|
|
611
|
+ </div>
|
|
|
612
|
+ </form>
|
|
|
613
|
+ </div>
|
|
|
614
|
+ </div>
|
|
|
615
|
+
|
|
408
|
616
|
<div class="tab-pane fade" id="pv-tab-cucine" role="tabpanel">
|
|
409
|
617
|
<form id="puntoVenditaEditCucineForm" class="mt-1" action="{{ route('punto-vendita.associa-cucina') }}" method="POST">
|
|
410
|
618
|
@csrf
|
|
|
@@ -589,6 +797,285 @@ $configData = Helper::appClasses();
|
|
589
|
797
|
}
|
|
590
|
798
|
});
|
|
591
|
799
|
|
|
|
800
|
+ var pvInfoEsistente = @json($puntoVendita->info ?? []);
|
|
|
801
|
+
|
|
|
802
|
+ function pvNormalizzaChiaveCampo(valore) {
|
|
|
803
|
+ var chiave = String(valore || '')
|
|
|
804
|
+ .trim()
|
|
|
805
|
+ .toLowerCase()
|
|
|
806
|
+ .normalize('NFD')
|
|
|
807
|
+ .replace(/[\u0300-\u036f]/g, '')
|
|
|
808
|
+ .replace(/\s+/g, '_')
|
|
|
809
|
+ .replace(/[^a-z0-9_]/g, '')
|
|
|
810
|
+ .replace(/_+/g, '_')
|
|
|
811
|
+ .replace(/^_|_$/g, '');
|
|
|
812
|
+
|
|
|
813
|
+ if (chiave && /^[0-9]/.test(chiave)) {
|
|
|
814
|
+ chiave = 'campo_' + chiave;
|
|
|
815
|
+ }
|
|
|
816
|
+
|
|
|
817
|
+ return chiave;
|
|
|
818
|
+ }
|
|
|
819
|
+
|
|
|
820
|
+ function pvGeneraChiaveCampoUnica(etichetta) {
|
|
|
821
|
+ var base = pvNormalizzaChiaveCampo(etichetta);
|
|
|
822
|
+ if (!base) {
|
|
|
823
|
+ return '';
|
|
|
824
|
+ }
|
|
|
825
|
+ if (!/^[a-z]/.test(base)) {
|
|
|
826
|
+ base = 'campo_' + base;
|
|
|
827
|
+ }
|
|
|
828
|
+
|
|
|
829
|
+ var chiave = base;
|
|
|
830
|
+ var i = 2;
|
|
|
831
|
+ while (pvCampoOrdineEsiste(chiave)) {
|
|
|
832
|
+ chiave = base + '_' + i;
|
|
|
833
|
+ i += 1;
|
|
|
834
|
+ }
|
|
|
835
|
+ return chiave;
|
|
|
836
|
+ }
|
|
|
837
|
+
|
|
|
838
|
+ function pvAggiornaAnteprimaChiaveCampo() {
|
|
|
839
|
+ var etichetta = ($('#pv_nuovo_campo_label').val() || '').trim();
|
|
|
840
|
+ var $preview = $('#pv_nuovo_campo_chiave_preview');
|
|
|
841
|
+ if (!etichetta) {
|
|
|
842
|
+ $preview.text('—').removeClass('text-danger text-success').addClass('text-muted');
|
|
|
843
|
+ return;
|
|
|
844
|
+ }
|
|
|
845
|
+ var chiave = pvGeneraChiaveCampoUnica(etichetta);
|
|
|
846
|
+ if (!chiave) {
|
|
|
847
|
+ $preview.text('Etichetta non valida').removeClass('text-muted text-success').addClass('text-danger');
|
|
|
848
|
+ return;
|
|
|
849
|
+ }
|
|
|
850
|
+ $preview.text(chiave).removeClass('text-muted text-danger').addClass('text-success');
|
|
|
851
|
+ }
|
|
|
852
|
+
|
|
|
853
|
+ function pvCampoOrdineEsiste(chiave) {
|
|
|
854
|
+ return $('#pvCampiOrdineBody [data-pv-campo-ordine="' + chiave + '"]').length > 0;
|
|
|
855
|
+ }
|
|
|
856
|
+
|
|
|
857
|
+ function pvRaccogliCampiOrdine() {
|
|
|
858
|
+ var campi = {};
|
|
|
859
|
+ $('#pvCampiOrdineBody [data-pv-campo-ordine]').each(function() {
|
|
|
860
|
+ var $row = $(this);
|
|
|
861
|
+ var chiave = $row.data('pv-campo-ordine');
|
|
|
862
|
+ campi[chiave] = {
|
|
|
863
|
+ label: $row.data('pv-campo-label') || chiave,
|
|
|
864
|
+ placeholder: $('#pv_campo_' + chiave + '_placeholder').val() || chiave,
|
|
|
865
|
+ mostra: $('#pv_campo_' + chiave + '_mostra').is(':checked'),
|
|
|
866
|
+ required: $('#pv_campo_' + chiave + '_required').is(':checked'),
|
|
|
867
|
+ stampa: $('#pv_campo_' + chiave + '_stampa').is(':checked'),
|
|
|
868
|
+ type: $row.data('pv-campo-type') || 'text',
|
|
|
869
|
+ icon: String($row.data('pv-campo-custom')) === '1' ? 'bx-edit' : undefined
|
|
|
870
|
+ };
|
|
|
871
|
+ if (String($row.data('pv-campo-custom')) === '1') {
|
|
|
872
|
+ campi[chiave].custom = true;
|
|
|
873
|
+ }
|
|
|
874
|
+ });
|
|
|
875
|
+ return campi;
|
|
|
876
|
+ }
|
|
|
877
|
+
|
|
|
878
|
+ function pvAggiornaAnteprimaCampiOrdine() {
|
|
|
879
|
+ $('#pvCampiOrdineBody [data-pv-campo-ordine]').each(function() {
|
|
|
880
|
+ var $row = $(this);
|
|
|
881
|
+ var chiave = $row.data('pv-campo-ordine');
|
|
|
882
|
+ var mostra = $('#pv_campo_' + chiave + '_mostra').is(':checked');
|
|
|
883
|
+ var label = $row.data('pv-campo-label') || chiave;
|
|
|
884
|
+ var placeholder = $('#pv_campo_' + chiave + '_placeholder').val() || label;
|
|
|
885
|
+ var $anteprima = $('[data-pv-anteprima="' + chiave + '"]');
|
|
|
886
|
+ if (!$anteprima.length) {
|
|
|
887
|
+ return;
|
|
|
888
|
+ }
|
|
|
889
|
+ $anteprima.toggle(mostra);
|
|
|
890
|
+ $('[data-pv-anteprima-label="' + chiave + '"]').text(label);
|
|
|
891
|
+ if ($anteprima.data('pv-anteprima-type') !== 'checkbox') {
|
|
|
892
|
+ $anteprima.find('input:not([type=checkbox])').attr('placeholder', placeholder);
|
|
|
893
|
+ }
|
|
|
894
|
+ });
|
|
|
895
|
+ }
|
|
|
896
|
+
|
|
|
897
|
+ function pvAggiungiAnteprimaCampo(chiave, label, type, mostra) {
|
|
|
898
|
+ if ($('[data-pv-anteprima="' + chiave + '"]').length) {
|
|
|
899
|
+ return;
|
|
|
900
|
+ }
|
|
|
901
|
+ type = type || 'text';
|
|
|
902
|
+ var $wrap = $('<div>', {
|
|
|
903
|
+ class: 'col-md-6 pv-campo-anteprima',
|
|
|
904
|
+ 'data-pv-anteprima': chiave,
|
|
|
905
|
+ 'data-pv-anteprima-type': type
|
|
|
906
|
+ }).toggle(!!mostra);
|
|
|
907
|
+
|
|
|
908
|
+ if (type === 'checkbox') {
|
|
|
909
|
+ var inputId = 'pv_anteprima_' + chiave;
|
|
|
910
|
+ $wrap.append(
|
|
|
911
|
+ $('<div>', { class: 'form-check form-switch mt-1' }).append(
|
|
|
912
|
+ $('<input>', {
|
|
|
913
|
+ class: 'form-check-input',
|
|
|
914
|
+ type: 'checkbox',
|
|
|
915
|
+ id: inputId,
|
|
|
916
|
+ disabled: true
|
|
|
917
|
+ }),
|
|
|
918
|
+ $('<label>', {
|
|
|
919
|
+ class: 'form-check-label small text-primary',
|
|
|
920
|
+ for: inputId,
|
|
|
921
|
+ 'data-pv-anteprima-label': chiave,
|
|
|
922
|
+ text: label
|
|
|
923
|
+ })
|
|
|
924
|
+ )
|
|
|
925
|
+ );
|
|
|
926
|
+ } else {
|
|
|
927
|
+ $wrap.append(
|
|
|
928
|
+ $('<label>', {
|
|
|
929
|
+ class: 'form-label small text-primary mb-1',
|
|
|
930
|
+ 'data-pv-anteprima-label': chiave,
|
|
|
931
|
+ text: label
|
|
|
932
|
+ })
|
|
|
933
|
+ );
|
|
|
934
|
+ $wrap.append(
|
|
|
935
|
+ $('<input>', {
|
|
|
936
|
+ type: type,
|
|
|
937
|
+ class: 'form-control form-control-sm border-primary border-top-0 border-start-0 border-end-0 rounded-0 bg-transparent',
|
|
|
938
|
+ disabled: true,
|
|
|
939
|
+ placeholder: label
|
|
|
940
|
+ })
|
|
|
941
|
+ );
|
|
|
942
|
+ }
|
|
|
943
|
+
|
|
|
944
|
+ $('#pvCampiOrdineAnteprima [data-pv-anteprima-totale]').before($wrap);
|
|
|
945
|
+ }
|
|
|
946
|
+
|
|
|
947
|
+ function pvAggiungiRigaCampoOrdine(chiave, label, type, options) {
|
|
|
948
|
+ options = options || {};
|
|
|
949
|
+ var mostra = options.mostra !== undefined ? options.mostra : true;
|
|
|
950
|
+ var required = !!options.required;
|
|
|
951
|
+ var stampa = !!options.stampa;
|
|
|
952
|
+ var custom = options.custom !== false;
|
|
|
953
|
+
|
|
|
954
|
+ var $row = $('<tr>', {
|
|
|
955
|
+ 'data-pv-campo-ordine': chiave,
|
|
|
956
|
+ 'data-pv-campo-type': type || 'text',
|
|
|
957
|
+ 'data-pv-campo-label': label,
|
|
|
958
|
+ 'data-pv-campo-custom': custom ? '1' : '0'
|
|
|
959
|
+ });
|
|
|
960
|
+
|
|
|
961
|
+ $row.append(
|
|
|
962
|
+ '<td><div class="d-flex align-items-center gap-2">' +
|
|
|
963
|
+ '<span class="avatar avatar-sm"><span class="avatar-initial rounded bg-label-primary"><i class="bx bx-edit"></i></span></span>' +
|
|
|
964
|
+ '<div><span class="fw-medium">' + $('<div>').text(label).html() + '</span>' +
|
|
|
965
|
+ '<div class="text-muted small">Chiave: <code>' + chiave + '</code>' +
|
|
|
966
|
+ (custom ? ' <span class="badge bg-label-warning ms-1">Personalizzato</span>' : '') +
|
|
|
967
|
+ '</div></div></div></td>'
|
|
|
968
|
+ );
|
|
|
969
|
+ $row.append(
|
|
|
970
|
+ '<td><input type="text" class="form-control form-control-sm" id="pv_campo_' + chiave + '_placeholder" data-pv-campo-placeholder value="' + $('<div>').text(label).html() + '"></td>'
|
|
|
971
|
+ );
|
|
|
972
|
+ $row.append(
|
|
|
973
|
+ '<td class="text-center"><div class="form-check form-switch d-inline-block mb-0">' +
|
|
|
974
|
+ '<input class="form-check-input" type="checkbox" id="pv_campo_' + chiave + '_mostra" data-pv-campo-mostra' + (mostra ? ' checked' : '') + '></div></td>'
|
|
|
975
|
+ );
|
|
|
976
|
+ $row.append(
|
|
|
977
|
+ '<td class="text-center"><div class="form-check form-switch d-inline-block mb-0">' +
|
|
|
978
|
+ '<input class="form-check-input" type="checkbox" id="pv_campo_' + chiave + '_required" data-pv-campo-required' + (required ? ' checked' : '') + '></div></td>'
|
|
|
979
|
+ );
|
|
|
980
|
+ $row.append(
|
|
|
981
|
+ '<td class="text-center"><div class="form-check form-switch d-inline-block mb-0">' +
|
|
|
982
|
+ '<input class="form-check-input" type="checkbox" id="pv_campo_' + chiave + '_stampa" data-pv-campo-stampa' + (stampa ? ' checked' : '') + '></div></td>'
|
|
|
983
|
+ );
|
|
|
984
|
+ $row.append(
|
|
|
985
|
+ '<td class="text-center">' +
|
|
|
986
|
+ (custom ? '<button type="button" class="btn btn-sm btn-icon btn-label-danger" data-pv-campo-rimuovi title="Rimuovi campo"><i class="bx bx-trash"></i></button>' : '') +
|
|
|
987
|
+ '</td>'
|
|
|
988
|
+ );
|
|
|
989
|
+
|
|
|
990
|
+ $('#pvCampiOrdineBody').append($row);
|
|
|
991
|
+ pvAggiungiAnteprimaCampo(chiave, label, type, mostra);
|
|
|
992
|
+ }
|
|
|
993
|
+
|
|
|
994
|
+ function pvSalvaCampiOrdineServer() {
|
|
|
995
|
+ var info = $.extend(true, {}, pvInfoEsistente || {});
|
|
|
996
|
+ info.campi_ordine = pvRaccogliCampiOrdine();
|
|
|
997
|
+
|
|
|
998
|
+ $.ajax({
|
|
|
999
|
+ url: '{{ route('punto-vendita.update') }}',
|
|
|
1000
|
+ method: 'POST',
|
|
|
1001
|
+ data: {
|
|
|
1002
|
+ punto_vendita_id: pvId,
|
|
|
1003
|
+ info: JSON.stringify(info),
|
|
|
1004
|
+ _token: '{{ csrf_token() }}'
|
|
|
1005
|
+ },
|
|
|
1006
|
+ headers: { 'Accept': 'application/json' }
|
|
|
1007
|
+ })
|
|
|
1008
|
+ .done(function(response) {
|
|
|
1009
|
+ if (response.success) {
|
|
|
1010
|
+ pvInfoEsistente = info;
|
|
|
1011
|
+ pvNotyf('success', response.message || 'Configurazione salvata');
|
|
|
1012
|
+ } else {
|
|
|
1013
|
+ pvNotyf('error', response.message || 'Errore nel salvataggio');
|
|
|
1014
|
+ }
|
|
|
1015
|
+ })
|
|
|
1016
|
+ .fail(function(xhr) {
|
|
|
1017
|
+ pvAjaxError(xhr, 'Errore nel salvataggio');
|
|
|
1018
|
+ });
|
|
|
1019
|
+ }
|
|
|
1020
|
+
|
|
|
1021
|
+ pvAggiornaAnteprimaCampiOrdine();
|
|
|
1022
|
+
|
|
|
1023
|
+ $(document).on('change.pvCampiOrdine', '[data-pv-campo-mostra], [data-pv-campo-required]', function() {
|
|
|
1024
|
+ var $row = $(this).closest('[data-pv-campo-ordine]');
|
|
|
1025
|
+ var chiave = $row.data('pv-campo-ordine');
|
|
|
1026
|
+ if ($(this).is('[data-pv-campo-mostra]') && !$(this).is(':checked')) {
|
|
|
1027
|
+ $('#pv_campo_' + chiave + '_required').prop('checked', false);
|
|
|
1028
|
+ }
|
|
|
1029
|
+ pvAggiornaAnteprimaCampiOrdine();
|
|
|
1030
|
+ });
|
|
|
1031
|
+
|
|
|
1032
|
+ $(document).on('input.pvCampiOrdine', '[data-pv-campo-placeholder]', function() {
|
|
|
1033
|
+ pvAggiornaAnteprimaCampiOrdine();
|
|
|
1034
|
+ });
|
|
|
1035
|
+
|
|
|
1036
|
+ $(document).on('input.pvNuovoCampoLabel', '#pv_nuovo_campo_label', function() {
|
|
|
1037
|
+ pvAggiornaAnteprimaChiaveCampo();
|
|
|
1038
|
+ });
|
|
|
1039
|
+
|
|
|
1040
|
+ pvAggiornaAnteprimaChiaveCampo();
|
|
|
1041
|
+
|
|
|
1042
|
+ $(document).on('click.pvAggiungiCampoOrdine', '#pvAggiungiCampoOrdine', function() {
|
|
|
1043
|
+ var label = ($('#pv_nuovo_campo_label').val() || '').trim();
|
|
|
1044
|
+ var type = $('#pv_nuovo_campo_type').val() || 'text';
|
|
|
1045
|
+ var chiave = pvGeneraChiaveCampoUnica(label);
|
|
|
1046
|
+
|
|
|
1047
|
+ if (!label) {
|
|
|
1048
|
+ pvNotyf('error', 'Inserisci un\'etichetta');
|
|
|
1049
|
+ return;
|
|
|
1050
|
+ }
|
|
|
1051
|
+ if (!chiave) {
|
|
|
1052
|
+ pvNotyf('error', 'Impossibile generare una chiave valida da questa etichetta');
|
|
|
1053
|
+ return;
|
|
|
1054
|
+ }
|
|
|
1055
|
+
|
|
|
1056
|
+ pvAggiungiRigaCampoOrdine(chiave, label, type, { mostra: true, required: false, stampa: false, custom: true });
|
|
|
1057
|
+ pvAggiornaAnteprimaCampiOrdine();
|
|
|
1058
|
+
|
|
|
1059
|
+ $('#pv_nuovo_campo_label').val('');
|
|
|
1060
|
+ $('#pv_nuovo_campo_type').val('text');
|
|
|
1061
|
+ pvAggiornaAnteprimaChiaveCampo();
|
|
|
1062
|
+ pvNotyf('success', 'Campo "' + label + '" aggiunto (chiave: ' + chiave + '). Salva la configurazione.');
|
|
|
1063
|
+ });
|
|
|
1064
|
+
|
|
|
1065
|
+ $(document).on('click.pvRimuoviCampoOrdine', '[data-pv-campo-rimuovi]', function() {
|
|
|
1066
|
+ var $row = $(this).closest('[data-pv-campo-ordine]');
|
|
|
1067
|
+ var chiave = $row.data('pv-campo-ordine');
|
|
|
1068
|
+ if (!confirm('Rimuovere il campo "' + chiave + '"?')) {
|
|
|
1069
|
+ return;
|
|
|
1070
|
+ }
|
|
|
1071
|
+ $row.remove();
|
|
|
1072
|
+ $('[data-pv-anteprima="' + chiave + '"]').remove();
|
|
|
1073
|
+ });
|
|
|
1074
|
+
|
|
|
1075
|
+ $(document).on('click.pvSaveCampiOrdine', '#saveCampiOrdine', function() {
|
|
|
1076
|
+ pvSalvaCampiOrdineServer();
|
|
|
1077
|
+ });
|
|
|
1078
|
+
|
|
592
|
1079
|
$(document).on('click.pvSaveCucine', '#saveCucine', function() {
|
|
593
|
1080
|
var $form = $('#puntoVenditaEditCucineForm');
|
|
594
|
1081
|
var cucineIds = [];
|