Roberto Santini před 4 hodinami
rodič
revize
95912a1819

+ 12
- 4
app/DataTables/AziendaDataTable.php Zobrazit soubor

28
                 return view('azienda.menu', ['entity' => $entity]);
28
                 return view('azienda.menu', ['entity' => $entity]);
29
             })
29
             })
30
             ->addColumn('ragione_display', function ($entity) {
30
             ->addColumn('ragione_display', function ($entity) {
31
-                return $entity->full_name ?: '—';
31
+                $ragione = trim((string) $entity->ragione_sociale);
32
+
33
+                return $ragione !== '' ? $ragione : '—';
34
+            })
35
+            ->addColumn('nome_display', function ($entity) {
36
+                $nome = trim((string) $entity->nome);
37
+
38
+                return $nome !== '' ? $nome : '—';
32
             })
39
             })
33
             ->addColumn('utenti_conta', function ($entity) {
40
             ->addColumn('utenti_conta', function ($entity) {
34
                 return $entity->utenti()->soloUtenti()->count();
41
                 return $entity->utenti()->soloUtenti()->count();
77
     public function getColumns(): array
84
     public function getColumns(): array
78
     {
85
     {
79
         return [
86
         return [
80
-            Column::make('ragione_sociale')->title('Azienda')->data('ragione_display')->name('ragione_sociale')->responsivePriority(1),
81
-            Column::make('piva')->title('P. IVA')->responsivePriority(3),
82
-            Column::make('email')->title('Email')->responsivePriority(2),
87
+            Column::make('ragione_sociale')->title('Ragione sociale')->data('ragione_display')->name('ragione_sociale')->responsivePriority(1),
88
+            Column::make('nome')->title('Nome commerciale')->data('nome_display')->name('nome')->responsivePriority(2),
89
+            Column::make('piva')->title('P. IVA')->responsivePriority(4),
90
+            Column::make('email')->title('Email')->responsivePriority(3),
83
             Column::make('telefono')->title('Telefono'),
91
             Column::make('telefono')->title('Telefono'),
84
             Column::computed('fic_label')->title('FiC')->searchable(false)->orderable(false),
92
             Column::computed('fic_label')->title('FiC')->searchable(false)->orderable(false),
85
             Column::make('utenti_conta')->title('Utenti')->attributes(['class' => 'text-center'])->searchable(false)->orderable(false),
93
             Column::make('utenti_conta')->title('Utenti')->attributes(['class' => 'text-center'])->searchable(false)->orderable(false),

+ 1
- 1
app/DataTables/FatturaDataTable.php Zobrazit soubor

21
   {
21
   {
22
     return (new EloquentDataTable($query))
22
     return (new EloquentDataTable($query))
23
       ->addColumn('action', fn ($e) => view('fatturazione.menu', ['entity' => $e]))
23
       ->addColumn('action', fn ($e) => view('fatturazione.menu', ['entity' => $e]))
24
-      ->addColumn('cliente_label', fn ($e) => $e->ragione_sociale ?: ($e->user?->full_name ?: '—'))
24
+      ->addColumn('cliente_label', fn ($e) => $e->clienteLabel())
25
       ->addColumn('stato_label', function ($e) {
25
       ->addColumn('stato_label', function ($e) {
26
         $map = [
26
         $map = [
27
           Fattura::STATO_BOZZA => 'secondary',
27
           Fattura::STATO_BOZZA => 'secondary',

+ 17
- 0
app/Models/Fattura.php Zobrazit soubor

141
         $this->save();
141
         $this->save();
142
     }
142
     }
143
 
143
 
144
+    public function clienteLabel(): string
145
+    {
146
+        $this->loadMissing('user');
147
+        if ($this->user?->is_azienda) {
148
+            $label = User::etichettaAzienda(
149
+                $this->ragione_sociale ?: $this->user->ragione_sociale,
150
+                $this->user->nome
151
+            );
152
+
153
+            return $label !== '' ? $label : '—';
154
+        }
155
+
156
+        $label = trim((string) ($this->ragione_sociale ?: $this->user?->full_name));
157
+
158
+        return $label !== '' ? $label : '—';
159
+    }
160
+
144
     public function snapshotDaUser(User $user): void
161
     public function snapshotDaUser(User $user): void
145
     {
162
     {
146
         $this->ragione_sociale = $user->is_azienda
163
         $this->ragione_sociale = $user->is_azienda

+ 15
- 1
app/Models/User.php Zobrazit soubor

38
       return $this->label_gruppo;
38
       return $this->label_gruppo;
39
     }
39
     }
40
     if($this->is_azienda){
40
     if($this->is_azienda){
41
-      return $this->ragione_sociale ?: $this->nome;
41
+      return self::etichettaAzienda($this->ragione_sociale, $this->nome);
42
     }
42
     }
43
     return trim(($this->cognome ?? '').' '.($this->nome ?? ''));
43
     return trim(($this->cognome ?? '').' '.($this->nome ?? ''));
44
   }
44
   }
45
 
45
 
46
+  /**
47
+   * Ragione sociale e, se diverso, il nome commerciale.
48
+   */
49
+  public static function etichettaAzienda(?string $ragioneSociale, ?string $nomeCommerciale): string
50
+  {
51
+    $ragione = trim((string) $ragioneSociale);
52
+    $commerciale = trim((string) $nomeCommerciale);
53
+    if ($ragione !== '' && $commerciale !== '' && strcasecmp($ragione, $commerciale) !== 0) {
54
+      return $ragione.' — '.$commerciale;
55
+    }
56
+
57
+    return $ragione !== '' ? $ragione : $commerciale;
58
+  }
59
+
46
   public function azienda()
60
   public function azienda()
47
   {
61
   {
48
     return $this->belongsTo(self::class, 'azienda_id', 'id');
62
     return $this->belongsTo(self::class, 'azienda_id', 'id');

+ 1
- 1
resources/views/config/index.blade.php Zobrazit soubor

146
                 <option value="">— Seleziona —</option>
146
                 <option value="">— Seleziona —</option>
147
                 @foreach($aziende as $azienda)
147
                 @foreach($aziende as $azienda)
148
                 <option value="{{ $azienda->id }}" @selected((string) $config->value === (string) $azienda->id)>
148
                 <option value="{{ $azienda->id }}" @selected((string) $config->value === (string) $azienda->id)>
149
-                  {{ $azienda->ragione_sociale ?: $azienda->full_name }} (#{{ $azienda->id }})
149
+                  {{ $azienda->full_name }} (#{{ $azienda->id }})
150
                 </option>
150
                 </option>
151
                 @endforeach
151
                 @endforeach
152
               </select>
152
               </select>

+ 1
- 1
resources/views/fatturazione/report-ticket.blade.php Zobrazit soubor

13
     <tr>
13
     <tr>
14
       <td style="width:50%">
14
       <td style="width:50%">
15
         <div class="label">Cliente</div>
15
         <div class="label">Cliente</div>
16
-        <strong>{{ $fattura->ragione_sociale ?: '—' }}</strong>
16
+        <strong>{{ $fattura->clienteLabel() }}</strong>
17
       </td>
17
       </td>
18
       <td style="width:50%">
18
       <td style="width:50%">
19
         <div class="label">Periodo</div>
19
         <div class="label">Periodo</div>

+ 2
- 2
resources/views/fatturazione/show.blade.php Zobrazit soubor

5
 @section('pageTitle')
5
 @section('pageTitle')
6
 <div>
6
 <div>
7
   <h4 class="mb-1">{{ $fattura->label }}</h4>
7
   <h4 class="mb-1">{{ $fattura->label }}</h4>
8
-  <span class="text-muted">{{ $fattura->ragione_sociale ?: ($fattura->user?->full_name ?: 'Cliente') }}</span>
8
+  <span class="text-muted">{{ $fattura->clienteLabel() }}</span>
9
 </div>
9
 </div>
10
 @endsection
10
 @endsection
11
 
11
 
370
           {{ $fattura->stato_label }}
370
           {{ $fattura->stato_label }}
371
         </span>
371
         </span>
372
         <h5 class="card-title">Cliente</h5>
372
         <h5 class="card-title">Cliente</h5>
373
-        <p class="mb-1"><strong>{{ $fattura->ragione_sociale ?: '—' }}</strong></p>
373
+        <p class="mb-1"><strong>{{ $fattura->clienteLabel() }}</strong></p>
374
         @if($fattura->piva)<p class="mb-1">P.IVA {{ $fattura->piva }}</p>@endif
374
         @if($fattura->piva)<p class="mb-1">P.IVA {{ $fattura->piva }}</p>@endif
375
         @if($fattura->cod_fiscale)<p class="mb-1">CF {{ $fattura->cod_fiscale }}</p>@endif
375
         @if($fattura->cod_fiscale)<p class="mb-1">CF {{ $fattura->cod_fiscale }}</p>@endif
376
         @if($fattura->indirizzo)<p class="mb-1">{{ $fattura->indirizzo }}</p>@endif
376
         @if($fattura->indirizzo)<p class="mb-1">{{ $fattura->indirizzo }}</p>@endif

+ 1
- 1
resources/views/segnalazione/admin/show.blade.php Zobrazit soubor

222
 
222
 
223
     // Eventi: Audit cambiamenti di stato / azienda
223
     // Eventi: Audit cambiamenti di stato / azienda
224
     $audits = $segnalazione->audits()->where('event', 'updated')->orderBy('created_at', 'desc')->get();
224
     $audits = $segnalazione->audits()->where('event', 'updated')->orderBy('created_at', 'desc')->get();
225
-    $aziendeById = \App\Models\Azienda::pluck('nome', 'id');
225
+    $aziendeById = \App\Models\Azienda::query()->get()->mapWithKeys(fn ($azienda) => [$azienda->id => $azienda->full_name]);
226
     foreach($audits as $audit) {
226
     foreach($audits as $audit) {
227
       // Gestisce sia array che stringhe JSON
227
       // Gestisce sia array che stringhe JSON
228
       $oldValues = [];
228
       $oldValues = [];

+ 1
- 1
resources/views/segnalazione/cliente/show.blade.php Zobrazit soubor

218
 
218
 
219
     // Eventi: Audit cambiamenti di stato / azienda
219
     // Eventi: Audit cambiamenti di stato / azienda
220
     $audits = $segnalazione->audits()->where('event', 'updated')->orderBy('created_at', 'desc')->get();
220
     $audits = $segnalazione->audits()->where('event', 'updated')->orderBy('created_at', 'desc')->get();
221
-    $aziendeById = \App\Models\Azienda::pluck('nome', 'id');
221
+    $aziendeById = \App\Models\Azienda::query()->get()->mapWithKeys(fn ($azienda) => [$azienda->id => $azienda->full_name]);
222
     foreach($audits as $audit) {
222
     foreach($audits as $audit) {
223
       // Gestisce sia array che stringhe JSON
223
       // Gestisce sia array che stringhe JSON
224
       $oldValues = [];
224
       $oldValues = [];

Loading…
Zrušit
Uložit