Roberto Santini пре 1 час
родитељ
комит
95912a1819

+ 12
- 4
app/DataTables/AziendaDataTable.php Прегледај датотеку

@@ -28,7 +28,14 @@ class AziendaDataTable extends DataTable
28 28
                 return view('azienda.menu', ['entity' => $entity]);
29 29
             })
30 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 40
             ->addColumn('utenti_conta', function ($entity) {
34 41
                 return $entity->utenti()->soloUtenti()->count();
@@ -77,9 +84,10 @@ class AziendaDataTable extends DataTable
77 84
     public function getColumns(): array
78 85
     {
79 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 91
             Column::make('telefono')->title('Telefono'),
84 92
             Column::computed('fic_label')->title('FiC')->searchable(false)->orderable(false),
85 93
             Column::make('utenti_conta')->title('Utenti')->attributes(['class' => 'text-center'])->searchable(false)->orderable(false),

+ 1
- 1
app/DataTables/FatturaDataTable.php Прегледај датотеку

@@ -21,7 +21,7 @@ class FatturaDataTable extends DataTable
21 21
   {
22 22
     return (new EloquentDataTable($query))
23 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 25
       ->addColumn('stato_label', function ($e) {
26 26
         $map = [
27 27
           Fattura::STATO_BOZZA => 'secondary',

+ 17
- 0
app/Models/Fattura.php Прегледај датотеку

@@ -141,6 +141,23 @@ class Fattura extends \App\Models\AbstractModels\AbstractFattura
141 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 161
     public function snapshotDaUser(User $user): void
145 162
     {
146 163
         $this->ragione_sociale = $user->is_azienda

+ 15
- 1
app/Models/User.php Прегледај датотеку

@@ -38,11 +38,25 @@ class User extends \App\Models\AbstractModels\AbstractUser
38 38
       return $this->label_gruppo;
39 39
     }
40 40
     if($this->is_azienda){
41
-      return $this->ragione_sociale ?: $this->nome;
41
+      return self::etichettaAzienda($this->ragione_sociale, $this->nome);
42 42
     }
43 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 60
   public function azienda()
47 61
   {
48 62
     return $this->belongsTo(self::class, 'azienda_id', 'id');

+ 1
- 1
resources/views/config/index.blade.php Прегледај датотеку

@@ -146,7 +146,7 @@ if (is_string($activeGroup)) {
146 146
                 <option value="">— Seleziona —</option>
147 147
                 @foreach($aziende as $azienda)
148 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 150
                 </option>
151 151
                 @endforeach
152 152
               </select>

+ 1
- 1
resources/views/fatturazione/report-ticket.blade.php Прегледај датотеку

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

+ 2
- 2
resources/views/fatturazione/show.blade.php Прегледај датотеку

@@ -5,7 +5,7 @@
5 5
 @section('pageTitle')
6 6
 <div>
7 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 9
 </div>
10 10
 @endsection
11 11
 
@@ -370,7 +370,7 @@
370 370
           {{ $fattura->stato_label }}
371 371
         </span>
372 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 374
         @if($fattura->piva)<p class="mb-1">P.IVA {{ $fattura->piva }}</p>@endif
375 375
         @if($fattura->cod_fiscale)<p class="mb-1">CF {{ $fattura->cod_fiscale }}</p>@endif
376 376
         @if($fattura->indirizzo)<p class="mb-1">{{ $fattura->indirizzo }}</p>@endif

+ 1
- 1
resources/views/segnalazione/admin/show.blade.php Прегледај датотеку

@@ -222,7 +222,7 @@ use App\Models\Config;
222 222
 
223 223
     // Eventi: Audit cambiamenti di stato / azienda
224 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 226
     foreach($audits as $audit) {
227 227
       // Gestisce sia array che stringhe JSON
228 228
       $oldValues = [];

+ 1
- 1
resources/views/segnalazione/cliente/show.blade.php Прегледај датотеку

@@ -218,7 +218,7 @@ use App\Models\Config;
218 218
 
219 219
     // Eventi: Audit cambiamenti di stato / azienda
220 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 222
     foreach($audits as $audit) {
223 223
       // Gestisce sia array che stringhe JSON
224 224
       $oldValues = [];

Loading…
Откажи
Сачувај