FabioFratini 1 год назад
Родитель
Сommit
14437f8779

+ 44 - 687
app/Http/Livewire/Report.php

@@ -1,8 +1,10 @@
 <?php
 namespace App\Http\Livewire;
 use App\Http\Livewire\Traits\HasAccertatore;
+use App\Http\Livewire\Traits\HasAnagrafica;
 use App\Http\Livewire\Traits\HasNote;
 use App\Http\Livewire\Traits\HasParteCoinvolta;
+use App\Http\Livewire\Traits\HasPasseggero;
 use App\Http\Livewire\Traits\HasPedoni;
 use App\Http\Livewire\Traits\HasPolizza;
 use App\Http\Livewire\Traits\HasAllegato;
@@ -32,6 +34,8 @@ class Report extends Component{
     use HasPedoni;
     use HasProprietari;
     use HasVeicoli;
+    use HasAnagrafica;
+    use HasPasseggero;
     protected $paginationTheme = 'bootstrap';
     public $title = 'Verbali';
     public $loadPatente;
@@ -213,47 +217,6 @@ class Report extends Component{
     public $modelli = array();
     public $polizze = array();
     public $allegatiType = array();
-    public $currentAnagrafica;
-    public $anag_firstname;
-    public $anag_lastname;
-    public $anag_gender;
-    public $anag_birth_date;
-    public $anag_birth_town_id;
-    public $anag_birth_prov_id;
-    public $anag_residenza_town_id;
-    public $anag_residenza_prov_id;
-    public $anag_residenza_address;
-    public $anag_residenza_cap;
-    public $anag_mobile;
-    public $anag_sedicente;
-    public $anag_documento_tipo;
-    public $anag_documento_patente_cat;
-    public $anag_documento_tipo_altro;
-    public $anag_documento_numero;
-    public $anag_documento_rilasciato_da;
-    public $anag_documento_rilasciato_da_altro;
-    public $anag_foreign_country;
-    public $anag_documento_rilasciato_da_di_foreign_localita;
-    public $anag_documento_rilasciato_da_di_foreign_country;
-    public $anag_documento_rilasciato_da_prov_id;
-    public $anag_documento_rilasciato_da_town_id;
-    public $anag_documento_rilasciato_il;
-    public $anag_documento_scadenza_il;
-    public $anag_state;
-    public $anag_nazionalita;
-    public $anag_nazione_straniera;
-    public $anag_localita_straniera;
-    public $anag_rag_soc;
-    public $anag_vat;
-    public $anag_sede_legale_town_id;
-    public $anag_sede_legale_prov_id;
-    public $anag_sede_legale_address;
-    public $anag_sede_legale_cap;
-    public $anag_phone;
-    public $anag_foreign_birth_country;
-    public $anag_foreign_birth_city;
-    public $anag_foreign_residence_country;
-    public $anag_foreign_residence_city;
     public $currentConducente;
     public $currentPasseggero;
     public $currentTeste;
@@ -275,6 +238,46 @@ class Report extends Component{
     public $loadAnagrafica;
     public $currentInfortunato;
     public $cds_2;
+
+
+    public $data_passeggero_0;
+    public $data_infortunato_0;
+    public $data_infortunato_ospedale_0;
+    public $data_passeggero_1;
+    public $data_infortunato_1;
+    public $data_infortunato_ospedale_1;
+    public $data_passeggero_2;
+    public $data_infortunato_2;
+    public $data_infortunato_ospedale_2;
+    public $data_passeggero_3;
+    public $data_infortunato_3;
+    public $data_infortunato_ospedale_3;
+    public $data_infortunato_extra_0;
+    public $data_infortunato_extra_1;
+    public $data_infortunato_extra_2;
+    public $data_infortunato_extra_3;
+    public $data_testi_oculari_0;
+    public $data_testi_oculari_stato_0;
+    public $data_testi_oculari_1;
+    public $data_testi_oculari_stato_1;
+    public $data_testi_oculari_2;
+    public $data_testi_oculari_stato_2;
+    public $data_testi_oculari_3;
+    public $data_testi_oculari_stato_3;
+    public $data_cinture_passeggeri_0;
+    public $data_cinture_passeggeri_1;
+    public $data_cinture_passeggeri_2;
+    public $data_cinture_passeggeri_3;
+    public $data_casco_conducente;
+    public $data_casco_passeggero;
+    public $data_casco_omologazione_conducente;
+    public $data_casco_omologazione_passeggero;
+    public $generalizzato;
+    public $generalizzato_altrove;
+    public $infortunato;
+    public $infortunato_ospedale;
+    public $cds;
+
     protected $rules = [
         //'name' => 'required'
     ];
@@ -503,56 +506,6 @@ class Report extends Component{
             }
         }
     }
-
-    public function resetAnagrafica(){
-        $this->loadAnagrafica = '';
-        $this->currentAnagrafica = 0;
-        $this->currentPasseggero = 0;
-        $this->currentInfortunato = 0;
-        $this->currentProprietario = 0;
-        $this->currentCoproprietario = 0;
-        $this->currentConducente = 0;
-        $this->currentTeste = 0;
-        $this->anag_type = 0;
-        $this->anag_firstname = '';
-        $this->anag_lastname = '';
-        $this->anag_gender = '';
-        $this->anag_birth_date = null;
-        $this->anag_birth_town_id = null;
-        $this->anag_birth_prov_id = null;
-        $this->anag_residenza_town_id = null;
-        $this->anag_residenza_prov_id = null;
-        $this->anag_residenza_address = '';
-        $this->anag_residenza_cap = '';
-        $this->anag_mobile = '';
-        $this->anag_sedicente;
-        $this->anag_documento_tipo = '';
-        $this->anag_documento_patente_cat = '';
-        $this->anag_documento_tipo_altro = '';
-        $this->anag_documento_numero = '';
-        $this->anag_documento_rilasciato_da = '';
-        $this->anag_documento_rilasciato_da_altro = '';
-        $this->anag_foreign_country = null;
-        $this->anag_documento_rilasciato_da_di_foreign_localita = null;
-        $this->anag_documento_rilasciato_da_di_foreign_country = null;
-        $this->anag_documento_rilasciato_da_prov_id = null;
-        $this->anag_documento_rilasciato_da_town_id = null;
-        $this->anag_documento_rilasciato_il = '';
-        $this->anag_documento_scadenza_il = '';
-        $this->anag_state = '';
-        $this->anag_nazionalita = '';
-        $this->anag_nazione_straniera = '';
-        $this->anag_localita_straniera = '';
-        $this->anag_rag_soc = '';
-        $this->anag_vat = '';
-        $this->anag_sede_legale_town_id = null;
-        $this->anag_sede_legale_prov_id = null;
-        $this->anag_sede_legale_address = '';
-        $this->anag_sede_legale_cap = '';
-        $this->anag_phone = '';
-    }
-
-
     public function hydrate(){
         $this->emit('load-select');
         $this->emit('load-check');
@@ -1164,21 +1117,6 @@ class Report extends Component{
         $this->emit('close-modal-parte-comune');
 
     }
-    public function editAnagraficaParte($progressive) {
-        $parte_comune = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->first();
-        if ($parte_comune != null)
-        {
-            $this->editAnagrafica($parte_comune->anagrafica);
-            $this->emit('load-anagrafica-modal');
-        }
-    }
-
-    public function addAnagrafica($progressive) {
-        $this->resetAnagrafica();
-        $this->currentProgressive = $progressive;
-        $this->emit('load-anagrafica-modal');
-    }
-
     public function addTesteOculare($x){
         $this->resetAnagrafica();
         $this->currentTeste = $x;
@@ -1192,12 +1130,6 @@ class Report extends Component{
 
     }
 
-    public function addPasseggero($x){
-        $this->resetAnagrafica();
-        $this->currentPasseggero = $x;
-        $this->emit('load-anagrafica-modal');
-    }
-
     public function removeConducente() {
         $this->data_conducenti = 0;
         $this->emit('add-default-value', $this->data_conducenti, '', 'data_conducenti');
@@ -1209,567 +1141,12 @@ class Report extends Component{
         $this->emit('load-anagrafica-modal');
     }
 
-    public function editPasseggero($x)
-    {
-        $this->currentPasseggero = $x;
-        if ($x == 1){
-            $this->editAnagrafica($this->data_passeggero_0);
-            $this->emit('load-anagrafica-modal');
-        }
-        if ($x == 2){
-            $this->editAnagrafica($this->data_passeggero_1);
-            $this->emit('load-anagrafica-modal');
-        }
-        if ($x == 3){
-            $this->editAnagrafica($this->data_passeggero_2);
-            $this->emit('load-anagrafica-modal');
-        }
-        if ($x == 4){
-            $this->editAnagrafica($this->data_passeggero_3s);
-            $this->emit('load-anagrafica-modal');
-        }
-    }
-
-    public function removePasseggero($x){
-        if ($x == 1){
-            $this->data_passeggero_0 = 0;
-            $this->emit('add-default-value', $this->data_passeggero_0, '', 'data_passeggero_0');
-        }
-        if ($x == 2){
-            $this->data_passeggero_1 = 0;
-            $this->emit('add-default-value', $this->data_passeggero_1, '', 'data_passeggero_1');
-        }
-        if ($x == 3){
-            $this->data_passeggero_2 = 0;
-            $this->emit('add-default-value', $this->data_passeggero_2, '', 'data_passeggero_2');
-        }
-        if ($x == 4){
-            $this->data_passeggero_3 = 0;
-            $this->emit('add-default-value', $this->data_passeggero_3, '', 'data_passeggero_3');
-        }
-    }
-
     public function addInfortunato($x){
         $this->resetAnagrafica();
         $this->currentInfortunato = $x;
         $this->emit('load-anagrafica-modal');
     }
 
-    public function editAnagrafica($anagrafica)
-    {
-        $this->resetAnagrafica();
-        $anag = \App\Models\Anagrafica::where('id', $anagrafica)->first();
-
-        if ($anag != null){
-            $this->currentAnagrafica = $anagrafica;
-            $this->anag_type = $anag->type;
-            $this->anag_firstname = $anag->firstname;
-            $this->anag_lastname = $anag->lastname;
-            $this->anag_gender = $anag->gender;
-            $this->anag_birth_date = $anag->birth_date;
-            $this->anag_birth_town_id = $anag->birth_town_id;
-            $this->anag_birth_prov_id = $anag->birth_prov_id;
-            $this->anag_residenza_town_id = $anag->residenza_town_id;
-            $this->anag_residenza_prov_id = $anag->residenza_prov_id;
-            $this->anag_residenza_address = $anag->residenza_address;
-            $this->anag_residenza_cap = $anag->residenza_cap;
-            $this->anag_mobile = $anag->mobile;
-            $this->anag_sedicente = $anag->sedicente;
-            $this->anag_documento_tipo = $anag->documento_tipo;
-            $this->anag_documento_patente_cat = $anag->documento_patente_cat;
-            $this->anag_documento_tipo_altro = $anag->documento_tipo_altro;
-            $this->anag_documento_numero = $anag->documento_numero;
-            $this->anag_documento_rilasciato_da = $anag->documento_rilasciato_da;
-            $this->anag_documento_rilasciato_da_altro = $anag->documento_rilasciato_da_altro;
-            $this->anag_foreign_country = $anag->foreign_country;
-            $this->anag_documento_rilasciato_da_di_foreign_localita = $anag->documento_rilasciato_da_di_foreign_localita;
-            $this->anag_documento_rilasciato_da_di_foreign_country = $anag->documento_rilasciato_da_di_foreign_country;
-            $this->anag_documento_rilasciato_da_prov_id = $anag->documento_rilasciato_da_prov_id;
-            $this->anag_documento_rilasciato_da_town_id = $anag->documento_rilasciato_da_town_id;
-            $this->anag_documento_rilasciato_il = $anag->documento_rilasciato_il;
-            $this->anag_documento_scadenza_il = $anag->documento_scadenza_il;
-            $this->anag_state = $anag->state;
-            $this->anag_nazionalita = $anag->nazionalita;
-            $this->anag_nazione_straniera = $anag->nazione_straniera;
-            $this->anag_localita_straniera = $anag->localita_straniera;
-            $this->anag_rag_soc = $anag->rag_soc;
-            $this->anag_vat = $anag->vat;
-            $this->anag_sede_legale_town_id = $anag->sede_legale_town_id;
-            $this->anag_sede_legale_prov_id = $anag->sede_legale_prov_id;
-            $this->anag_sede_legale_address = $anag->sede_legale_address;
-            $this->anag_sede_legale_cap = $anag->sede_legale_cap;
-            $this->anag_phone = $anag->phone;
-            $this->anag_foreign_birth_country = $anag->anag_foreign_birth_country;
-            $this->anag_foreign_birth_city = $anag->anag_foreign_birth_city;
-            $this->anag_foreign_residence_country = $anag->anag_foreign_residence_country;
-            $this->anag_foreign_residence_city = $anag->anag_foreign_residence_city;
-        }
-        $this->emit('load-anagrafica-modal');
-        $this->emit('change-visualization', $this->anag_type);
-
-        if ($this->anag_birth_town_id > 0)
-            $this->emit('add-default-value', $this->anag_birth_town_id, $this->getLocalita($this->anag_birth_town_id), 'anag_birth_town_id');
-        if ($this->anag_residenza_town_id > 0)
-            $this->emit('add-default-value', $this->anag_residenza_town_id, $this->getLocalita($this->anag_residenza_town_id), 'anag_residenza_town_id');
-        if ($this->anag_documento_rilasciato_da_di_foreign_localita > 0)
-            $this->emit('add-default-value', $this->anag_documento_rilasciato_da_di_foreign_localita, $this->getLocalita($this->anag_documento_rilasciato_da_di_foreign_localita), 'anag_documento_rilasciato_da_di_foreign_localita');
-        if ($this->vei_carta_circolazione_rilasciata_da_di_foreign_localita > 0)
-            $this->emit('add-default-value', $this->vei_carta_circolazione_rilasciata_da_di_foreign_localita, $this->getLocalita($this->vei_carta_circolazione_rilasciata_da_di_foreign_localita), 'vei_carta_circolazione_rilasciata_da_di_foreign_localita');
-        if ($this->anag_sede_legale_town_id > 0)
-            $this->emit('add-default-value', $this->anag_sede_legale_town_id, $this->getLocalita($this->anag_sede_legale_town_id), 'anag_sede_legale_town_id');
-    }
-
-    public function anagraficaSave()
-    {
-
-        if ($this->currentAnagrafica > 0){
-            \App\Models\Anagrafica::whereId($this->currentAnagrafica)->update([
-                'type' => $this->anag_type,
-                'firstname' => $this->anag_firstname,
-                'lastname' => $this->anag_lastname,
-                'gender' => $this->anag_gender,
-                'birth_date' => $this->anag_birth_date,
-                'birth_town_id' => $this->anag_birth_town_id,
-                'birth_prov_id' => $this->anag_birth_prov_id,
-                'residenza_town_id' => $this->anag_residenza_town_id,
-                'residenza_prov_id' => $this->anag_residenza_prov_id,
-                'residenza_address' => $this->anag_residenza_address,
-                'residenza_cap' => $this->anag_residenza_cap,
-                'mobile' => $this->anag_mobile,
-                'sedicente' => $this->anag_sedicente,
-                'documento_tipo' => $this->anag_documento_tipo,
-                'documento_patente_cat' => $this->anag_documento_patente_cat,
-                'documento_tipo_altro' => $this->anag_documento_tipo_altro,
-                'documento_numero' => $this->anag_documento_numero,
-                'documento_rilasciato_da' => $this->anag_documento_rilasciato_da,
-                'documento_rilasciato_da_altro' => $this->anag_documento_rilasciato_da_altro,
-                'foreign_country' => $this->anag_foreign_country,
-                'documento_rilasciato_da_di_foreign_localita' => $this->anag_documento_rilasciato_da_di_foreign_localita,
-                'documento_rilasciato_da_di_foreign_country' => $this->anag_documento_rilasciato_da_di_foreign_country,
-                'documento_rilasciato_da_prov_id' => $this->anag_documento_rilasciato_da_prov_id,
-                'documento_rilasciato_da_town_id' => $this->anag_documento_rilasciato_da_town_id,
-                'documento_rilasciato_il' => $this->anag_documento_rilasciato_il,
-                'documento_scadenza_il' => $this->anag_documento_scadenza_il,
-                'state' => $this->anag_state,
-                'nazionalita' => $this->anag_nazionalita,
-                'nazione_straniera' => $this->anag_nazione_straniera,
-                'localita_straniera' => $this->anag_localita_straniera,
-                'rag_soc' => $this->anag_rag_soc,
-                'vat' => $this->anag_vat,
-                'sede_legale_town_id' => $this->anag_sede_legale_town_id,
-                'sede_legale_prov_id' => $this->anag_sede_legale_prov_id,
-                'sede_legale_address' => $this->anag_sede_legale_address,
-                'sede_legale_cap' => $this->anag_sede_legale_cap,
-                'phone' => $this->anag_phone,
-                'anag_foreign_birth_country' => $this->anag_foreign_birth_country,
-                'anag_foreign_birth_city' => $this->anag_foreign_birth_city,
-                'anag_foreign_residence_country' => $this->anag_foreign_residence_country,
-                'anag_foreign_residence_city' => $this->anag_foreign_residence_city
-            ]);
-        } else {
-            $anagrafica = \App\Models\Anagrafica::create([
-                'type' => $this->anag_type,
-                'firstname' => $this->anag_firstname,
-                'lastname' => $this->anag_lastname,
-                'gender' => $this->anag_gender,
-                'birth_date' => $this->anag_birth_date,
-                'birth_town_id' => $this->anag_birth_town_id,
-                'birth_prov_id' => $this->anag_birth_prov_id,
-                'residenza_town_id' => $this->anag_residenza_town_id,
-                'residenza_prov_id' => $this->anag_residenza_prov_id,
-                'residenza_address' => $this->anag_residenza_address,
-                'residenza_cap' => $this->anag_residenza_cap,
-                'mobile' => $this->anag_mobile,
-                'sedicente' => $this->anag_sedicente,
-                'documento_tipo' => $this->anag_documento_tipo,
-                'documento_patente_cat' => $this->anag_documento_patente_cat,
-                'documento_tipo_altro' => $this->anag_documento_tipo_altro,
-                'documento_numero' => $this->anag_documento_numero,
-                'documento_rilasciato_da' => $this->anag_documento_rilasciato_da,
-                'documento_rilasciato_da_altro' => $this->anag_documento_rilasciato_da_altro,
-                'foreign_country' => $this->anag_foreign_country,
-                'documento_rilasciato_da_di_foreign_localita' => $this->anag_documento_rilasciato_da_di_foreign_localita,
-                'documento_rilasciato_da_di_foreign_country' => $this->anag_documento_rilasciato_da_di_foreign_country,
-                'documento_rilasciato_da_prov_id' => $this->anag_documento_rilasciato_da_prov_id,
-                'documento_rilasciato_da_town_id' => $this->anag_documento_rilasciato_da_town_id,
-                'documento_rilasciato_il' => $this->anag_documento_rilasciato_il,
-                'documento_scadenza_il' => $this->anag_documento_scadenza_il,
-                'state' => $this->anag_state,
-                'nazionalita' => $this->anag_nazionalita,
-                'nazione_straniera' => $this->anag_nazione_straniera,
-                'localita_straniera' => $this->anag_localita_straniera,
-                'rag_soc' => $this->anag_rag_soc,
-                'vat' => $this->anag_vat,
-                'sede_legale_town_id' => $this->anag_sede_legale_town_id,
-                'sede_legale_prov_id' => $this->anag_sede_legale_prov_id,
-                'sede_legale_address' => $this->anag_sede_legale_address,
-                'sede_legale_cap' => $this->anag_sede_legale_cap,
-                'phone' => $this->anag_phone
-            ]);
-            $set = false;
-
-            if ($this->currentTeste > 0){
-                $set = true;
-                if ($this->currentTeste == 1)
-                    $this->data_testi_oculari_0 = $anagrafica->id;
-                if ($this->currentTeste == 2)
-                    $this->data_testi_oculari_1 = $anagrafica->id;
-                if ($this->currentTeste == 3)
-                    $this->data_testi_oculari_2 = $anagrafica->id;
-                if ($this->currentTeste == 4)
-                    $this->data_testi_oculari_3 = $anagrafica->id;
-            }
-
-            if ($this->currentProprietario > 0){
-                $set = true;
-                $this->data_proprietari = $anagrafica->id;
-                $this->emit('add-default-value', $this->data_proprietari, $this->getAnagrafica($this->data_proprietari), 'data_proprietari');
-            }
-
-            if ($this->currentCoproprietario > 0){
-                $set = true;
-                $this->data_coproprietari = $anagrafica->id;
-                $this->emit('add-default-value', $this->data_coproprietari, $this->getAnagrafica($this->data_coproprietari), 'data_coproprietari');
-            }
-
-            if ($this->currentPasseggero > 0){
-                $set = true;
-                if ($this->currentPasseggero == 1){
-                    $this->data_passeggero_0 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_passeggero_0, $this->getAnagrafica($this->data_passeggero_0), 'data_passeggero_0');
-                }
-
-                if ($this->currentPasseggero == 2){
-                    $this->data_passeggero_1 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_passeggero_1, $this->getAnagrafica($this->data_passeggero_1), 'data_passeggero_1');
-                }
-
-                if ($this->currentPasseggero == 3){
-                    $this->data_passeggero_2 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_passeggero_2, $this->getAnagrafica($this->data_passeggero_2), 'data_passeggero_2');
-                }
-
-                if ($this->currentPasseggero == 4){
-                    $this->data_passeggero_3 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_passeggero_3, $this->getAnagrafica($this->data_passeggero_3), 'data_passeggero_3');
-                }
-            }
-
-            if ($this->currentInfortunato > 0){
-                $set = true;
-                if ($this->currentInfortunato == 1){
-                    $this->data_infortunato_extra_0 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_infortunato_extra_0, $this->getAnagrafica($this->data_infortunato_extra_0), 'data_infortunato_extra_0');
-                }
-
-                if ($this->currentInfortunato == 2){
-                    $this->data_infortunato_extra_1 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_infortunato_extra_1, $this->getAnagrafica($this->data_infortunato_extra_1), 'data_infortunato_extra_1');
-                }
-
-                if ($this->currentInfortunato == 3){
-                    $this->data_infortunato_extra_2 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_infortunato_extra_2, $this->getAnagrafica($this->data_infortunato_extra_2), 'data_infortunato_extra_2');
-                }
-
-                if ($this->currentInfortunato == 4){
-                    $this->data_infortunato_extra_3 = $anagrafica->id;
-                    $this->emit('add-default-value', $this->data_infortunato_extra_3, $this->getAnagrafica($this->data_infortunato_extra_3), 'data_infortunato_extra_3');
-                }
-            }
-
-
-            if ($this->currentConducente > 0){
-                $set = true;
-                $this->data_conducenti = $anagrafica->id;
-                $this->emit('add-default-value', $this->data_conducenti, $this->getAnagrafica($this->data_conducenti), 'data_conducenti');
-            }
-
-            if ($this->currentProgressive > -1 && !$set){
-                $this->updateAnagraficaParteCoinvolta($anagrafica->id, $this->currentProgressive);
-            }
-
-        }
-        $this->resetAnagrafica();
-        $this->emit('close-modal');
-    }
-
-    public function veicoloSave()
-    {
-        $this->validate([
-            'vei_tipo_id' => 'required',
-            'vei_marca_id' => 'required',
-            'vei_modello_id' => 'required',
-            'vei_carta_circolazione_rilasciata_da' => 'required',
-            'vei_foreign_country' => 'required',
-            'vei_carta_circolazione_rilasciata_da_di' => 'required',
-            'vei_destinazione_uso' => 'required',
-        ], [
-            'vei_tipo_id.required' => 'Il campo "Tipo di veicolo" è obbligatorio.',
-            'vei_marca_id.required' => 'Il campo "Marca" è obbligatorio.',
-            'vei_modello_id.required' => 'Il campo "Modello" è obbligatorio.',
-            'vei_carta_circolazione_rilasciata_da.required' => 'Il campo "Rilasciata da" è obbligatorio.',
-            'vei_foreign_country.required' => 'Il campo "Paese di rilascio" è obbligatorio.',
-            'vei_carta_circolazione_rilasciata_da_di.required' => 'Il campo "Località di rilascio" è obbligatorio.',
-            'vei_destinazione_uso.required' => 'Il campo "Destinazione d\'uso" è obbligatorio.',
-        ]);
-
-        if ($this->currentVeicolo > 0){
-            Vehicle::whereId($this->currentVeicolo)->update([
-                'tipo_id' => $this->vei_tipo_id,
-                'marca_id' => $this->vei_marca_id,
-                'marca_altro' => $this->vei_marca_altro,
-                'modello_id' => $this->vei_modello_id,
-                'modello_altro' => $this->vei_modello_altro,
-                'colore' => $this->vei_colore,
-                'targa' => $this->vei_targa,
-                'carta_circolazione' => $this->vei_carta_circolazione,
-                'carta_circolazione_rilasciata_da' => $this->vei_carta_circolazione_rilasciata_da,
-                'carta_circolazione_rilasciata_da_altro' => $this->vei_carta_circolazione_rilasciata_da_altro,
-                'foreign_country' => $this->vei_foreign_country,
-                'carta_circolazione_rilasciata_da_di_foreign_country' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_country,
-                'carta_circolazione_rilasciata_da_di_foreign_localita' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_localita,
-                'carta_circolazione_rilasciata_da_di' => $this->vei_carta_circolazione_rilasciata_da_di,
-                'carta_circolazione_rilasciata_il' => $this->vei_carta_circolazione_rilasciata_il,
-                'data_ultima_revisione' => $this->vei_data_ultima_revisione,
-                'cilindrata' => $this->vei_cilindrata,
-                'peso_complessivo' => $this->vei_peso_complessivo,
-                'destinazione_uso' => $this->vei_destinazione_uso
-            ]);
-        }else{
-            $veicolo = \App\Models\Vehicle::create([
-                'tipo_id' => $this->vei_tipo_id,
-                'marca_id' => $this->vei_marca_id,
-                'marca_altro' => $this->vei_marca_altro,
-                'modello_id' => $this->vei_modello_id,
-                'modello_altro' => $this->vei_modello_altro,
-                'colore' => $this->vei_colore,
-                'targa' => $this->vei_targa,
-                'carta_circolazione' => $this->vei_carta_circolazione,
-                'carta_circolazione_rilasciata_da' => $this->vei_carta_circolazione_rilasciata_da,
-                'carta_circolazione_rilasciata_da_altro' => $this->vei_carta_circolazione_rilasciata_da_altro,
-                'foreign_country' => $this->vei_foreign_country,
-                'carta_circolazione_rilasciata_da_di_foreign_country' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_country,
-                'carta_circolazione_rilasciata_da_di_foreign_localita' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_localita,
-                'carta_circolazione_rilasciata_da_di' => $this->vei_carta_circolazione_rilasciata_da_di,
-                'carta_circolazione_rilasciata_il' => $this->vei_carta_circolazione_rilasciata_il,
-                'data_ultima_revisione' => $this->vei_data_ultima_revisione,
-                'cilindrata' => $this->vei_cilindrata,
-                'peso_complessivo' => $this->vei_peso_complessivo,
-                'destinazione_uso' => $this->vei_destinazione_uso
-            ]);
-            $this->updateVeicoloParteCoinvolta($veicolo->id, $this->currentProgressive);
-        }
-        $this->resetVeicolo();
-        $this->emit('close-modal');
-    }
-
-    public function anagraficaDataParteComuneSave(){
-
-        ReportDataVeicoli::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
-        \App\Models\ReportDataInfortunati::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
-        \App\Models\ReportDataPasseggeri::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
-        \App\Models\ReportDataUsoDelCascoOmologazione::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
-        \App\Models\ReportDataUsoDelCasco::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
-        \App\Models\ReportDataCintureSicurezza::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
-
-        try {
-            ReportDataVeicoli::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'veicolo' => $this->currentVeicolo,
-                'chilometri_percorsi' => $this->data_chilometri_percorsi,
-                'stato_veicolo' => $this->data_stato_veicolo,
-                'polizze' => $this->data_polizze,
-                'proprietari' => $this->data_proprietari,
-                'coproprietari' => $this->data_coproprietari,
-                'conducente_uguale_proprietario' => $this->data_conducente_uguale_proprietario,
-                'conducenti' => $this->data_conducenti,
-                'infortunato' => $this->data_infortunato,
-                'infortunato_ospedale' => $this->data_infortunato_ospedale,
-                'patente_al_seguito' => $this->data_patente_al_seguito,
-                'generalizzato' => $this->data_generalizzato,
-                'generalizzato_altrove' => $this->data_generalizzato_altrove,
-                'posizione_statica_finale' => $this->data_posizione_statica_finale,
-                'danni_visibili_riportati' => $this->data_danni_visibili_riportati,
-                'danni_visibili_pre_esistenti' => $this->data_danni_visibili_pre_esistenti,
-                'destinazione_veicolo' => $this->data_destinazione_veicolo,
-                'destinazione_veicolo_affidato_a' => $this->data_destinazione_veicolo_affidato_a,
-                'destinazione_veicolo_sequestro_num_art' => $this->data_destinazione_veicolo_sequestro_num_art,
-                'destinazione_veicolo_amministrativo_num' => $this->data_destinazione_veicolo_amministrativo_num,
-                'destinazione_veicolo_amministrativo_num_art_violato' => $this->data_destinazione_veicolo_amministrativo_num_art_violato,
-                'destinazione_veicolo_amministrativo_cds' => $this->data_destinazione_veicolo_amministrativo_cds,
-                'circostanze_presunte_incidente' => $this->data_circostanze_presunte_incidente,
-                'stato_pneumatici' => $this->data_stato_pneumatici,
-                'marca_pneumatici' => $this->data_marca_pneumatici,
-                'misura_pneumatici' => $this->data_misura_pneumatici,
-                'dispositivi_ottici' => $this->data_dispositivi_ottici,
-                'tergicristalli' => $this->data_tergicristalli,
-                'segnale_pericolo' => $this->data_segnale_pericolo,
-                'abs' => $this->data_abs,
-                'gps' => $this->data_gps,
-                'marcia_inserita' => $this->data_marcia_inserita,
-                'cristallo' => $this->data_cristallo,
-                'cristallo_posizione' => $this->data_cristallo_posizione,
-                'specchio_retrovisore' => $this->data_specchio_retrovisore,
-                'specchio_lat_dx' => $this->data_specchio_lat_dx,
-                'specchio_lat_sx' => $this->data_specchio_lat_sx,
-                'attivazione_airbag' => $this->data_attivazione_airbag,
-                'airbag_posizione' => $this->data_airbag_posizione,
-                'alcool_test' => $this->data_alcool_test,
-                'alcool_test_esito' => $this->data_alcool_test_esito,
-                'drug_test' => $this->data_drug_test,
-                'drug_test_esito' => $this->data_drug_test_esito,
-                'sistema_ritenuta_minori' => $this->data_sistema_ritenuta_minori,
-                'sistema_ritenuta_minori_omologazione' => $this->data_sistema_ritenuta_minori_omologazione,
-                'verbale_violazione_numero_1' => $this->data_verbale_violazione_numero_1,
-                'articolo_violato_1' => $this->data_articolo_violato_1,
-                'cds_1' => $this->data_cds_1,
-                'verbale_violazione_numero_2' => $this->data_verbale_violazione_numero_2,
-                'articolo_violato_2' => $this->data_articolo_violato_2,
-                'cds_2' => $this->data_cds_2,
-                'verbale_violazione_numero_3' => $this->data_verbale_violazione_numero_3,
-                'articolo_violato_3' => $this->data_articolo_violato_3,
-                'cds_3' => $this->data_cds_3,
-                'conducente_patente_numero' => $this->data_conducente_patente_numero,
-                'conducente_patente_categoria' => $this->data_conducente_patente_categoria,
-                'conducente_patente_rilasciata_da' => $this->data_conducente_patente_rilasciata_da,
-                'conducente_patente_rilasciata_da_altro' => $this->data_conducente_patente_rilasciata_da_altro,
-                'conducente_patente_rilasciata_il' => $this->data_conducente_patente_rilasciata_il,
-                'conducente_patente_scadenza' => $this->data_conducente_patente_scadenza,
-                'conducente_patente_prescrizioni' => $this->data_conducente_patente_prescrizioni,
-                'conducente_patente_limitazioni_art_117_1' => $this->data_conducente_patente_limitazioni_art_117_1,
-                'conducente_patente_limitazioni_art_117_2' => $this->data_conducente_patente_limitazioni_art_117_2,
-                'conducente_patente_abilitazione' => $this->data_conducente_patente_abilitazione,
-                'conducente_patente_abilitazione_numero' => $this->data_conducente_patente_abilitazione_numero,
-                'conducente_patente_abilitazione_rilasciata_da' => $this->data_conducente_patente_abilitazione_rilasciata_da,
-                'conducente_patente_abilitazione_rilasciata_il' => $this->data_conducente_patente_abilitazione_rilasciata_il,
-                'conducente_documento' => $this->data_conducente_documento,
-                'conducente_documento_numero' => $this->data_conducente_documento_numero,
-                'conducente_sedicente' => $this->data_conducente_sedicente,
-                'tipo_danno' => $this->data_tipo_danno > 0 ? $this->data_tipo_danno : null,
-                'entita_danno' => $this->data_entita_danno > 0 ? $this->data_entita_danno : null,
-                'effetto_danno' => $this->data_effetto_danno > 0 ? $this->data_effetto_danno : null,
-                'parte_macchina' => $this->data_parte_macchina > 0 ? $this->data_parte_macchina : null,
-                'tipo_danno_2' => $this->data_tipo_danno_2 > 0 ? $this->data_tipo_danno_2 : null,
-                'entita_danno_2' => $this->data_entita_danno_2 > 0 ? $this->data_entita_danno_2 : null,
-                'effetto_danno_2' => $this->data_effetto_danno_2 > 0 ? $this->data_effetto_danno_2 : null,
-                'parte_macchina_2' => $this->data_parte_macchina_2 > 0 ? $this->data_parte_macchina_2 : null,
-                'tipo_danno_3' => $this->data_tipo_danno_3 > 0 ? $this->data_tipo_danno_3 : null,
-                'entita_danno_3' => $this->data_entita_danno_3 > 0 ? $this->data_entita_danno_3 : null,
-                'effetto_danno_3' => $this->data_effetto_danno_3 > 0 ? $this->data_effetto_danno_3 : null,
-                'parte_macchina_3' => $this->data_parte_macchina_3 > 0 ? $this->data_parte_macchina_3 : null,
-                'tipo_danno_4' => $this->data_tipo_danno_4 > 0 ? $this->data_tipo_danno_4 : null,
-                'entita_danno_4' => $this->data_entita_danno_4 > 0 ? $this->data_entita_danno_4 : null,
-                'effetto_danno_4' => $this->data_effetto_danno_4 > 0 ? $this->data_effetto_danno_4 : null,
-                'parte_macchina_4' => $this->data_parte_macchina_4 > 0 ? $this->data_parte_macchina_4 : null
-            ]);
-            session()->flash('success','Record creato');
-
-        } catch (\Exception $ex) {
-            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
-        }
-
-        try {
-            \App\Models\ReportDataCintureSicurezza::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'conducente' => $this->data_cinture_conducente,
-                'passeggeri_0' => $this->data_cinture_passeggeri_0,
-                'passeggeri_1' => $this->data_cinture_passeggeri_1,
-                'passeggeri_2' => $this->data_cinture_passeggeri_2,
-                'passeggeri_3' => $this->data_cinture_passeggeri_3
-            ]);
-        } catch (\Exception $ex) {
-            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
-        }
-
-        try {
-            \App\Models\ReportDataUsoDelCasco::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'conducente' => $this->data_casco_conducente,
-                'passeggeri' => $this->data_casco_passeggero
-            ]);
-        } catch (\Exception $ex) {
-            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
-        }
-
-        try {
-            \App\Models\ReportDataUsoDelCascoOmologazione::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'conducente' => $this->data_casco_omologazione_conducente,
-                'passeggeri' => $this->data_casco_omologazione_passeggero
-            ]);
-        } catch (\Exception $ex) {
-            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
-        }
-
-        try {
-            \App\Models\ReportDataPasseggeri::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'passeggero' => $this->data_passeggero_0,
-                'infortunato' => $this->data_infortunato_0,
-                'infortunato_ospedale' => $this->data_infortunato_ospedale_0
-            ]);
-            \App\Models\ReportDataPasseggeri::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'passeggero' => $this->data_passeggero_1,
-                'infortunato' => $this->data_infortunato_1,
-                'infortunato_ospedale' => $this->data_infortunato_ospedale_1
-            ]);
-            \App\Models\ReportDataPasseggeri::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'passeggero' => $this->data_passeggero_2,
-                'infortunato' => $this->data_infortunato_2,
-                'infortunato_ospedale' => $this->data_infortunato_ospedale_2
-            ]);
-            \App\Models\ReportDataPasseggeri::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'passeggero' => $this->data_passeggero_3,
-                'infortunato' => $this->data_infortunato_3,
-                'infortunato_ospedale' => $this->data_infortunato_ospedale_3
-            ]);
-        } catch (\Exception $ex) {
-            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
-        }
-
-
-        try {
-            \App\Models\ReportDataInfortunati::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'infortunato' => $this->data_infortunato_extra_0
-            ]);
-            \App\Models\ReportDataInfortunati::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'infortunato' => $this->data_infortunato_extra_1
-            ]);
-            \App\Models\ReportDataInfortunati::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'infortunato' => $this->data_infortunato_extra_2
-            ]);
-            \App\Models\ReportDataInfortunati::create([
-                'progressive' => $this->currentProgressive,
-                'report_id' => $this->dataId,
-                'infortunato' => $this->data_infortunato_extra_3
-            ]);
-        } catch (\Exception $ex) {
-            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
-        }
-
-        $this->resetVeicoloData();
-        $this->emit('close-modal-parte-comune');
-
-    }
-
     public function dateToNull()
     {
         return "0000-00-00";
@@ -1797,26 +1174,6 @@ class Report extends Component{
         return "";
     }
 
-    public function getAnagrafica($anagrafica){
-        if ($anagrafica > 0)
-        {
-            $ret = \App\Models\Anagrafica::findOrFail($anagrafica);
-            if($ret->type == 0)
-            return $ret->lastname . " " . $ret->firstname;
-            else
-            return $ret->rag_soc;
-        }
-        return "";
-    }
-    public function getVeicolo($veicolo){
-        if ($veicolo > 0)
-        {
-            $ret = Vehicle::findOrFail($veicolo);
-            return ($ret->marca ? $ret->marca->name : '') . " " . ($ret->modello ? $ret->modello->name : '') . " " . $ret->targa;
-        }
-        return "";
-    }
-
     public function getByTarga(){
 
         if ($this->vei_targa != '')

+ 571 - 0
app/Http/Livewire/Traits/HasAnagrafica.php

@@ -0,0 +1,571 @@
+<?php
+
+namespace App\Http\Livewire\Traits;
+
+use App\Models\ReportDataPartiCoinvolte;
+use App\Models\ReportDataVeicoli;
+
+trait HasAnagrafica{
+    public $currentAnagrafica;
+    public $anag_firstname;
+    public $anag_lastname;
+    public $anag_gender;
+    public $anag_birth_date;
+    public $anag_birth_town_id;
+    public $anag_birth_prov_id;
+    public $anag_residenza_town_id;
+    public $anag_residenza_prov_id;
+    public $anag_residenza_address;
+    public $anag_residenza_cap;
+    public $anag_mobile;
+    public $anag_sedicente;
+    public $anag_documento_tipo;
+    public $anag_documento_patente_cat;
+    public $anag_documento_tipo_altro;
+    public $anag_documento_numero;
+    public $anag_documento_rilasciato_da;
+    public $anag_documento_rilasciato_da_altro;
+    public $anag_foreign_country;
+    public $anag_documento_rilasciato_da_di_foreign_localita;
+    public $anag_documento_rilasciato_da_di_foreign_country;
+    public $anag_documento_rilasciato_da_prov_id;
+    public $anag_documento_rilasciato_da_town_id;
+    public $anag_documento_rilasciato_il;
+    public $anag_documento_scadenza_il;
+    public $anag_state;
+    public $anag_nazionalita;
+    public $anag_nazione_straniera;
+    public $anag_localita_straniera;
+    public $anag_rag_soc;
+    public $anag_vat;
+    public $anag_sede_legale_town_id;
+    public $anag_sede_legale_prov_id;
+    public $anag_sede_legale_address;
+    public $anag_sede_legale_cap;
+    public $anag_phone;
+    public $anag_foreign_birth_country;
+    public $anag_foreign_birth_city;
+    public $anag_foreign_residence_country;
+    public $anag_foreign_residence_city;
+
+    public function editAnagrafica($anagrafica)
+    {
+        $this->resetAnagrafica();
+        $anag = \App\Models\Anagrafica::where('id', $anagrafica)->first();
+
+        if ($anag != null){
+            $this->currentAnagrafica = $anagrafica;
+            $this->anag_type = $anag->type;
+            $this->anag_firstname = $anag->firstname;
+            $this->anag_lastname = $anag->lastname;
+            $this->anag_gender = $anag->gender;
+            $this->anag_birth_date = $anag->birth_date;
+            $this->anag_birth_town_id = $anag->birth_town_id;
+            $this->anag_birth_prov_id = $anag->birth_prov_id;
+            $this->anag_residenza_town_id = $anag->residenza_town_id;
+            $this->anag_residenza_prov_id = $anag->residenza_prov_id;
+            $this->anag_residenza_address = $anag->residenza_address;
+            $this->anag_residenza_cap = $anag->residenza_cap;
+            $this->anag_mobile = $anag->mobile;
+            $this->anag_sedicente = $anag->sedicente;
+            $this->anag_documento_tipo = $anag->documento_tipo;
+            $this->anag_documento_patente_cat = $anag->documento_patente_cat;
+            $this->anag_documento_tipo_altro = $anag->documento_tipo_altro;
+            $this->anag_documento_numero = $anag->documento_numero;
+            $this->anag_documento_rilasciato_da = $anag->documento_rilasciato_da;
+            $this->anag_documento_rilasciato_da_altro = $anag->documento_rilasciato_da_altro;
+            $this->anag_foreign_country = $anag->foreign_country;
+            $this->anag_documento_rilasciato_da_di_foreign_localita = $anag->documento_rilasciato_da_di_foreign_localita;
+            $this->anag_documento_rilasciato_da_di_foreign_country = $anag->documento_rilasciato_da_di_foreign_country;
+            $this->anag_documento_rilasciato_da_prov_id = $anag->documento_rilasciato_da_prov_id;
+            $this->anag_documento_rilasciato_da_town_id = $anag->documento_rilasciato_da_town_id;
+            $this->anag_documento_rilasciato_il = $anag->documento_rilasciato_il;
+            $this->anag_documento_scadenza_il = $anag->documento_scadenza_il;
+            $this->anag_state = $anag->state;
+            $this->anag_nazionalita = $anag->nazionalita;
+            $this->anag_nazione_straniera = $anag->nazione_straniera;
+            $this->anag_localita_straniera = $anag->localita_straniera;
+            $this->anag_rag_soc = $anag->rag_soc;
+            $this->anag_vat = $anag->vat;
+            $this->anag_sede_legale_town_id = $anag->sede_legale_town_id;
+            $this->anag_sede_legale_prov_id = $anag->sede_legale_prov_id;
+            $this->anag_sede_legale_address = $anag->sede_legale_address;
+            $this->anag_sede_legale_cap = $anag->sede_legale_cap;
+            $this->anag_phone = $anag->phone;
+            $this->anag_foreign_birth_country = $anag->anag_foreign_birth_country;
+            $this->anag_foreign_birth_city = $anag->anag_foreign_birth_city;
+            $this->anag_foreign_residence_country = $anag->anag_foreign_residence_country;
+            $this->anag_foreign_residence_city = $anag->anag_foreign_residence_city;
+        }
+        $this->emit('load-anagrafica-modal');
+        $this->emit('change-visualization', $this->anag_type);
+
+        if ($this->anag_birth_town_id > 0)
+            $this->emit('add-default-value', $this->anag_birth_town_id, $this->getLocalita($this->anag_birth_town_id), 'anag_birth_town_id');
+        if ($this->anag_residenza_town_id > 0)
+            $this->emit('add-default-value', $this->anag_residenza_town_id, $this->getLocalita($this->anag_residenza_town_id), 'anag_residenza_town_id');
+        if ($this->anag_documento_rilasciato_da_di_foreign_localita > 0)
+            $this->emit('add-default-value', $this->anag_documento_rilasciato_da_di_foreign_localita, $this->getLocalita($this->anag_documento_rilasciato_da_di_foreign_localita), 'anag_documento_rilasciato_da_di_foreign_localita');
+        if ($this->vei_carta_circolazione_rilasciata_da_di_foreign_localita > 0)
+            $this->emit('add-default-value', $this->vei_carta_circolazione_rilasciata_da_di_foreign_localita, $this->getLocalita($this->vei_carta_circolazione_rilasciata_da_di_foreign_localita), 'vei_carta_circolazione_rilasciata_da_di_foreign_localita');
+        if ($this->anag_sede_legale_town_id > 0)
+            $this->emit('add-default-value', $this->anag_sede_legale_town_id, $this->getLocalita($this->anag_sede_legale_town_id), 'anag_sede_legale_town_id');
+    }
+
+    public function anagraficaSave()
+    {
+
+        if ($this->currentAnagrafica > 0){
+            \App\Models\Anagrafica::whereId($this->currentAnagrafica)->update([
+                'type' => $this->anag_type,
+                'firstname' => $this->anag_firstname,
+                'lastname' => $this->anag_lastname,
+                'gender' => $this->anag_gender,
+                'birth_date' => $this->anag_birth_date,
+                'birth_town_id' => $this->anag_birth_town_id,
+                'birth_prov_id' => $this->anag_birth_prov_id,
+                'residenza_town_id' => $this->anag_residenza_town_id,
+                'residenza_prov_id' => $this->anag_residenza_prov_id,
+                'residenza_address' => $this->anag_residenza_address,
+                'residenza_cap' => $this->anag_residenza_cap,
+                'mobile' => $this->anag_mobile,
+                'sedicente' => $this->anag_sedicente,
+                'documento_tipo' => $this->anag_documento_tipo,
+                'documento_patente_cat' => $this->anag_documento_patente_cat,
+                'documento_tipo_altro' => $this->anag_documento_tipo_altro,
+                'documento_numero' => $this->anag_documento_numero,
+                'documento_rilasciato_da' => $this->anag_documento_rilasciato_da,
+                'documento_rilasciato_da_altro' => $this->anag_documento_rilasciato_da_altro,
+                'foreign_country' => $this->anag_foreign_country,
+                'documento_rilasciato_da_di_foreign_localita' => $this->anag_documento_rilasciato_da_di_foreign_localita,
+                'documento_rilasciato_da_di_foreign_country' => $this->anag_documento_rilasciato_da_di_foreign_country,
+                'documento_rilasciato_da_prov_id' => $this->anag_documento_rilasciato_da_prov_id,
+                'documento_rilasciato_da_town_id' => $this->anag_documento_rilasciato_da_town_id,
+                'documento_rilasciato_il' => $this->anag_documento_rilasciato_il,
+                'documento_scadenza_il' => $this->anag_documento_scadenza_il,
+                'state' => $this->anag_state,
+                'nazionalita' => $this->anag_nazionalita,
+                'nazione_straniera' => $this->anag_nazione_straniera,
+                'localita_straniera' => $this->anag_localita_straniera,
+                'rag_soc' => $this->anag_rag_soc,
+                'vat' => $this->anag_vat,
+                'sede_legale_town_id' => $this->anag_sede_legale_town_id,
+                'sede_legale_prov_id' => $this->anag_sede_legale_prov_id,
+                'sede_legale_address' => $this->anag_sede_legale_address,
+                'sede_legale_cap' => $this->anag_sede_legale_cap,
+                'phone' => $this->anag_phone,
+                'anag_foreign_birth_country' => $this->anag_foreign_birth_country,
+                'anag_foreign_birth_city' => $this->anag_foreign_birth_city,
+                'anag_foreign_residence_country' => $this->anag_foreign_residence_country,
+                'anag_foreign_residence_city' => $this->anag_foreign_residence_city
+            ]);
+        } else {
+            $anagrafica = \App\Models\Anagrafica::create([
+                'type' => $this->anag_type,
+                'firstname' => $this->anag_firstname,
+                'lastname' => $this->anag_lastname,
+                'gender' => $this->anag_gender,
+                'birth_date' => $this->anag_birth_date,
+                'birth_town_id' => $this->anag_birth_town_id,
+                'birth_prov_id' => $this->anag_birth_prov_id,
+                'residenza_town_id' => $this->anag_residenza_town_id,
+                'residenza_prov_id' => $this->anag_residenza_prov_id,
+                'residenza_address' => $this->anag_residenza_address,
+                'residenza_cap' => $this->anag_residenza_cap,
+                'mobile' => $this->anag_mobile,
+                'sedicente' => $this->anag_sedicente,
+                'documento_tipo' => $this->anag_documento_tipo,
+                'documento_patente_cat' => $this->anag_documento_patente_cat,
+                'documento_tipo_altro' => $this->anag_documento_tipo_altro,
+                'documento_numero' => $this->anag_documento_numero,
+                'documento_rilasciato_da' => $this->anag_documento_rilasciato_da,
+                'documento_rilasciato_da_altro' => $this->anag_documento_rilasciato_da_altro,
+                'foreign_country' => $this->anag_foreign_country,
+                'documento_rilasciato_da_di_foreign_localita' => $this->anag_documento_rilasciato_da_di_foreign_localita,
+                'documento_rilasciato_da_di_foreign_country' => $this->anag_documento_rilasciato_da_di_foreign_country,
+                'documento_rilasciato_da_prov_id' => $this->anag_documento_rilasciato_da_prov_id,
+                'documento_rilasciato_da_town_id' => $this->anag_documento_rilasciato_da_town_id,
+                'documento_rilasciato_il' => $this->anag_documento_rilasciato_il,
+                'documento_scadenza_il' => $this->anag_documento_scadenza_il,
+                'state' => $this->anag_state,
+                'nazionalita' => $this->anag_nazionalita,
+                'nazione_straniera' => $this->anag_nazione_straniera,
+                'localita_straniera' => $this->anag_localita_straniera,
+                'rag_soc' => $this->anag_rag_soc,
+                'vat' => $this->anag_vat,
+                'sede_legale_town_id' => $this->anag_sede_legale_town_id,
+                'sede_legale_prov_id' => $this->anag_sede_legale_prov_id,
+                'sede_legale_address' => $this->anag_sede_legale_address,
+                'sede_legale_cap' => $this->anag_sede_legale_cap,
+                'phone' => $this->anag_phone
+            ]);
+            $set = false;
+
+            if ($this->currentTeste > 0){
+                $set = true;
+                if ($this->currentTeste == 1)
+                    $this->data_testi_oculari_0 = $anagrafica->id;
+                if ($this->currentTeste == 2)
+                    $this->data_testi_oculari_1 = $anagrafica->id;
+                if ($this->currentTeste == 3)
+                    $this->data_testi_oculari_2 = $anagrafica->id;
+                if ($this->currentTeste == 4)
+                    $this->data_testi_oculari_3 = $anagrafica->id;
+            }
+
+            if ($this->currentProprietario > 0){
+                $set = true;
+                $this->data_proprietari = $anagrafica->id;
+                $this->emit('add-default-value', $this->data_proprietari, $this->getAnagrafica($this->data_proprietari), 'data_proprietari');
+            }
+
+            if ($this->currentCoproprietario > 0){
+                $set = true;
+                $this->data_coproprietari = $anagrafica->id;
+                $this->emit('add-default-value', $this->data_coproprietari, $this->getAnagrafica($this->data_coproprietari), 'data_coproprietari');
+            }
+
+            if ($this->currentPasseggero > 0){
+                $set = true;
+                if ($this->currentPasseggero == 1){
+                    $this->data_passeggero_0 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_passeggero_0, $this->getAnagrafica($this->data_passeggero_0), 'data_passeggero_0');
+                }
+
+                if ($this->currentPasseggero == 2){
+                    $this->data_passeggero_1 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_passeggero_1, $this->getAnagrafica($this->data_passeggero_1), 'data_passeggero_1');
+                }
+
+                if ($this->currentPasseggero == 3){
+                    $this->data_passeggero_2 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_passeggero_2, $this->getAnagrafica($this->data_passeggero_2), 'data_passeggero_2');
+                }
+
+                if ($this->currentPasseggero == 4){
+                    $this->data_passeggero_3 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_passeggero_3, $this->getAnagrafica($this->data_passeggero_3), 'data_passeggero_3');
+                }
+            }
+
+            if ($this->currentInfortunato > 0){
+                $set = true;
+                if ($this->currentInfortunato == 1){
+                    $this->data_infortunato_extra_0 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_infortunato_extra_0, $this->getAnagrafica($this->data_infortunato_extra_0), 'data_infortunato_extra_0');
+                }
+
+                if ($this->currentInfortunato == 2){
+                    $this->data_infortunato_extra_1 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_infortunato_extra_1, $this->getAnagrafica($this->data_infortunato_extra_1), 'data_infortunato_extra_1');
+                }
+
+                if ($this->currentInfortunato == 3){
+                    $this->data_infortunato_extra_2 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_infortunato_extra_2, $this->getAnagrafica($this->data_infortunato_extra_2), 'data_infortunato_extra_2');
+                }
+
+                if ($this->currentInfortunato == 4){
+                    $this->data_infortunato_extra_3 = $anagrafica->id;
+                    $this->emit('add-default-value', $this->data_infortunato_extra_3, $this->getAnagrafica($this->data_infortunato_extra_3), 'data_infortunato_extra_3');
+                }
+            }
+
+
+            if ($this->currentConducente > 0){
+                $set = true;
+                $this->data_conducenti = $anagrafica->id;
+                $this->emit('add-default-value', $this->data_conducenti, $this->getAnagrafica($this->data_conducenti), 'data_conducenti');
+            }
+
+            if ($this->currentProgressive > -1 && !$set){
+                $this->updateAnagraficaParteCoinvolta($anagrafica->id, $this->currentProgressive);
+            }
+
+        }
+        $this->resetAnagrafica();
+        $this->emit('close-modal');
+    }
+
+    public function anagraficaDataParteComuneSave(){
+
+        ReportDataVeicoli::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
+        \App\Models\ReportDataInfortunati::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
+        \App\Models\ReportDataPasseggeri::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
+        \App\Models\ReportDataUsoDelCascoOmologazione::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
+        \App\Models\ReportDataUsoDelCasco::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
+        \App\Models\ReportDataCintureSicurezza::where('progressive', $this->currentProgressive)->where('report_id', $this->dataId)->delete();
+
+        try {
+            ReportDataVeicoli::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'veicolo' => $this->currentVeicolo,
+                'chilometri_percorsi' => $this->data_chilometri_percorsi,
+                'stato_veicolo' => $this->data_stato_veicolo,
+                'polizze' => $this->data_polizze,
+                'proprietari' => $this->data_proprietari,
+                'coproprietari' => $this->data_coproprietari,
+                'conducente_uguale_proprietario' => $this->data_conducente_uguale_proprietario,
+                'conducenti' => $this->data_conducenti,
+                'infortunato' => $this->data_infortunato,
+                'infortunato_ospedale' => $this->data_infortunato_ospedale,
+                'patente_al_seguito' => $this->data_patente_al_seguito,
+                'generalizzato' => $this->data_generalizzato,
+                'generalizzato_altrove' => $this->data_generalizzato_altrove,
+                'posizione_statica_finale' => $this->data_posizione_statica_finale,
+                'danni_visibili_riportati' => $this->data_danni_visibili_riportati,
+                'danni_visibili_pre_esistenti' => $this->data_danni_visibili_pre_esistenti,
+                'destinazione_veicolo' => $this->data_destinazione_veicolo,
+                'destinazione_veicolo_affidato_a' => $this->data_destinazione_veicolo_affidato_a,
+                'destinazione_veicolo_sequestro_num_art' => $this->data_destinazione_veicolo_sequestro_num_art,
+                'destinazione_veicolo_amministrativo_num' => $this->data_destinazione_veicolo_amministrativo_num,
+                'destinazione_veicolo_amministrativo_num_art_violato' => $this->data_destinazione_veicolo_amministrativo_num_art_violato,
+                'destinazione_veicolo_amministrativo_cds' => $this->data_destinazione_veicolo_amministrativo_cds,
+                'circostanze_presunte_incidente' => $this->data_circostanze_presunte_incidente,
+                'stato_pneumatici' => $this->data_stato_pneumatici,
+                'marca_pneumatici' => $this->data_marca_pneumatici,
+                'misura_pneumatici' => $this->data_misura_pneumatici,
+                'dispositivi_ottici' => $this->data_dispositivi_ottici,
+                'tergicristalli' => $this->data_tergicristalli,
+                'segnale_pericolo' => $this->data_segnale_pericolo,
+                'abs' => $this->data_abs,
+                'gps' => $this->data_gps,
+                'marcia_inserita' => $this->data_marcia_inserita,
+                'cristallo' => $this->data_cristallo,
+                'cristallo_posizione' => $this->data_cristallo_posizione,
+                'specchio_retrovisore' => $this->data_specchio_retrovisore,
+                'specchio_lat_dx' => $this->data_specchio_lat_dx,
+                'specchio_lat_sx' => $this->data_specchio_lat_sx,
+                'attivazione_airbag' => $this->data_attivazione_airbag,
+                'airbag_posizione' => $this->data_airbag_posizione,
+                'alcool_test' => $this->data_alcool_test,
+                'alcool_test_esito' => $this->data_alcool_test_esito,
+                'drug_test' => $this->data_drug_test,
+                'drug_test_esito' => $this->data_drug_test_esito,
+                'sistema_ritenuta_minori' => $this->data_sistema_ritenuta_minori,
+                'sistema_ritenuta_minori_omologazione' => $this->data_sistema_ritenuta_minori_omologazione,
+                'verbale_violazione_numero_1' => $this->data_verbale_violazione_numero_1,
+                'articolo_violato_1' => $this->data_articolo_violato_1,
+                'cds_1' => $this->data_cds_1,
+                'verbale_violazione_numero_2' => $this->data_verbale_violazione_numero_2,
+                'articolo_violato_2' => $this->data_articolo_violato_2,
+                'cds_2' => $this->data_cds_2,
+                'verbale_violazione_numero_3' => $this->data_verbale_violazione_numero_3,
+                'articolo_violato_3' => $this->data_articolo_violato_3,
+                'cds_3' => $this->data_cds_3,
+                'conducente_patente_numero' => $this->data_conducente_patente_numero,
+                'conducente_patente_categoria' => $this->data_conducente_patente_categoria,
+                'conducente_patente_rilasciata_da' => $this->data_conducente_patente_rilasciata_da,
+                'conducente_patente_rilasciata_da_altro' => $this->data_conducente_patente_rilasciata_da_altro,
+                'conducente_patente_rilasciata_il' => $this->data_conducente_patente_rilasciata_il,
+                'conducente_patente_scadenza' => $this->data_conducente_patente_scadenza,
+                'conducente_patente_prescrizioni' => $this->data_conducente_patente_prescrizioni,
+                'conducente_patente_limitazioni_art_117_1' => $this->data_conducente_patente_limitazioni_art_117_1,
+                'conducente_patente_limitazioni_art_117_2' => $this->data_conducente_patente_limitazioni_art_117_2,
+                'conducente_patente_abilitazione' => $this->data_conducente_patente_abilitazione,
+                'conducente_patente_abilitazione_numero' => $this->data_conducente_patente_abilitazione_numero,
+                'conducente_patente_abilitazione_rilasciata_da' => $this->data_conducente_patente_abilitazione_rilasciata_da,
+                'conducente_patente_abilitazione_rilasciata_il' => $this->data_conducente_patente_abilitazione_rilasciata_il,
+                'conducente_documento' => $this->data_conducente_documento,
+                'conducente_documento_numero' => $this->data_conducente_documento_numero,
+                'conducente_sedicente' => $this->data_conducente_sedicente,
+                'tipo_danno' => $this->data_tipo_danno > 0 ? $this->data_tipo_danno : null,
+                'entita_danno' => $this->data_entita_danno > 0 ? $this->data_entita_danno : null,
+                'effetto_danno' => $this->data_effetto_danno > 0 ? $this->data_effetto_danno : null,
+                'parte_macchina' => $this->data_parte_macchina > 0 ? $this->data_parte_macchina : null,
+                'tipo_danno_2' => $this->data_tipo_danno_2 > 0 ? $this->data_tipo_danno_2 : null,
+                'entita_danno_2' => $this->data_entita_danno_2 > 0 ? $this->data_entita_danno_2 : null,
+                'effetto_danno_2' => $this->data_effetto_danno_2 > 0 ? $this->data_effetto_danno_2 : null,
+                'parte_macchina_2' => $this->data_parte_macchina_2 > 0 ? $this->data_parte_macchina_2 : null,
+                'tipo_danno_3' => $this->data_tipo_danno_3 > 0 ? $this->data_tipo_danno_3 : null,
+                'entita_danno_3' => $this->data_entita_danno_3 > 0 ? $this->data_entita_danno_3 : null,
+                'effetto_danno_3' => $this->data_effetto_danno_3 > 0 ? $this->data_effetto_danno_3 : null,
+                'parte_macchina_3' => $this->data_parte_macchina_3 > 0 ? $this->data_parte_macchina_3 : null,
+                'tipo_danno_4' => $this->data_tipo_danno_4 > 0 ? $this->data_tipo_danno_4 : null,
+                'entita_danno_4' => $this->data_entita_danno_4 > 0 ? $this->data_entita_danno_4 : null,
+                'effetto_danno_4' => $this->data_effetto_danno_4 > 0 ? $this->data_effetto_danno_4 : null,
+                'parte_macchina_4' => $this->data_parte_macchina_4 > 0 ? $this->data_parte_macchina_4 : null
+            ]);
+            session()->flash('success','Record creato');
+
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
+        }
+
+        try {
+            \App\Models\ReportDataCintureSicurezza::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'conducente' => $this->data_cinture_conducente,
+                'passeggeri_0' => $this->data_cinture_passeggeri_0,
+                'passeggeri_1' => $this->data_cinture_passeggeri_1,
+                'passeggeri_2' => $this->data_cinture_passeggeri_2,
+                'passeggeri_3' => $this->data_cinture_passeggeri_3
+            ]);
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
+        }
+
+        try {
+            \App\Models\ReportDataUsoDelCasco::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'conducente' => $this->data_casco_conducente,
+                'passeggeri' => $this->data_casco_passeggero
+            ]);
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
+        }
+
+        try {
+            \App\Models\ReportDataUsoDelCascoOmologazione::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'conducente' => $this->data_casco_omologazione_conducente,
+                'passeggeri' => $this->data_casco_omologazione_passeggero
+            ]);
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
+        }
+
+        try {
+            \App\Models\ReportDataPasseggeri::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'passeggero' => $this->data_passeggero_0,
+                'infortunato' => $this->data_infortunato_0,
+                'infortunato_ospedale' => $this->data_infortunato_ospedale_0
+            ]);
+            \App\Models\ReportDataPasseggeri::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'passeggero' => $this->data_passeggero_1,
+                'infortunato' => $this->data_infortunato_1,
+                'infortunato_ospedale' => $this->data_infortunato_ospedale_1
+            ]);
+            \App\Models\ReportDataPasseggeri::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'passeggero' => $this->data_passeggero_2,
+                'infortunato' => $this->data_infortunato_2,
+                'infortunato_ospedale' => $this->data_infortunato_ospedale_2
+            ]);
+            \App\Models\ReportDataPasseggeri::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'passeggero' => $this->data_passeggero_3,
+                'infortunato' => $this->data_infortunato_3,
+                'infortunato_ospedale' => $this->data_infortunato_ospedale_3
+            ]);
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
+        }
+
+
+        try {
+            \App\Models\ReportDataInfortunati::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'infortunato' => $this->data_infortunato_extra_0
+            ]);
+            \App\Models\ReportDataInfortunati::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'infortunato' => $this->data_infortunato_extra_1
+            ]);
+            \App\Models\ReportDataInfortunati::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'infortunato' => $this->data_infortunato_extra_2
+            ]);
+            \App\Models\ReportDataInfortunati::create([
+                'progressive' => $this->currentProgressive,
+                'report_id' => $this->dataId,
+                'infortunato' => $this->data_infortunato_extra_3
+            ]);
+        } catch (\Exception $ex) {
+            session()->flash('error','Errore in fase di salvataggio (' . $ex->getMessage() . ')');
+        }
+
+        $this->resetVeicoloData();
+        $this->emit('close-modal-parte-comune');
+
+    }
+
+    public function editAnagraficaParte($progressive) {
+        $parte_comune = ReportDataPartiCoinvolte::where('report_id', $this->dataId)->where('progressive', $progressive)->first();
+        if ($parte_comune != null)
+        {
+            $this->editAnagrafica($parte_comune->anagrafica);
+            $this->emit('load-anagrafica-modal');
+        }
+    }
+
+    public function addAnagrafica($progressive) {
+        $this->resetAnagrafica();
+        $this->currentProgressive = $progressive;
+        $this->emit('load-anagrafica-modal');
+    }
+
+    public function getAnagrafica($anagrafica){
+        if ($anagrafica > 0)
+        {
+            $ret = \App\Models\Anagrafica::findOrFail($anagrafica);
+            if($ret->type == 0)
+            return $ret->lastname . " " . $ret->firstname;
+            else
+            return $ret->rag_soc;
+        }
+        return "";
+    }
+
+
+    public function resetAnagrafica(){
+        $this->loadAnagrafica = '';
+        $this->currentAnagrafica = 0;
+        $this->currentPasseggero = 0;
+        $this->currentInfortunato = 0;
+        $this->currentProprietario = 0;
+        $this->currentCoproprietario = 0;
+        $this->currentConducente = 0;
+        $this->currentTeste = 0;
+        $this->anag_type = 0;
+        $this->anag_firstname = '';
+        $this->anag_lastname = '';
+        $this->anag_gender = '';
+        $this->anag_birth_date = null;
+        $this->anag_birth_town_id = null;
+        $this->anag_birth_prov_id = null;
+        $this->anag_residenza_town_id = null;
+        $this->anag_residenza_prov_id = null;
+        $this->anag_residenza_address = '';
+        $this->anag_residenza_cap = '';
+        $this->anag_mobile = '';
+        $this->anag_sedicente;
+        $this->anag_documento_tipo = '';
+        $this->anag_documento_patente_cat = '';
+        $this->anag_documento_tipo_altro = '';
+        $this->anag_documento_numero = '';
+        $this->anag_documento_rilasciato_da = '';
+        $this->anag_documento_rilasciato_da_altro = '';
+        $this->anag_foreign_country = null;
+        $this->anag_documento_rilasciato_da_di_foreign_localita = null;
+        $this->anag_documento_rilasciato_da_di_foreign_country = null;
+        $this->anag_documento_rilasciato_da_prov_id = null;
+        $this->anag_documento_rilasciato_da_town_id = null;
+        $this->anag_documento_rilasciato_il = '';
+        $this->anag_documento_scadenza_il = '';
+        $this->anag_state = '';
+        $this->anag_nazionalita = '';
+        $this->anag_nazione_straniera = '';
+        $this->anag_localita_straniera = '';
+        $this->anag_rag_soc = '';
+        $this->anag_vat = '';
+        $this->anag_sede_legale_town_id = null;
+        $this->anag_sede_legale_prov_id = null;
+        $this->anag_sede_legale_address = '';
+        $this->anag_sede_legale_cap = '';
+        $this->anag_phone = '';
+    }
+}

+ 39 - 0
app/Http/Livewire/Traits/HasPasseggero.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Http\Livewire\Traits;
+
+trait HasPasseggero{
+
+    public function editPasseggero($x) {
+        if (!in_array($x, [1, 2, 3, 4])) {
+            return;
+        }
+
+        $this->currentPasseggero = $x;
+        $propertyName = 'data_passeggero_' . ($x - 1);
+
+        if (property_exists($this, $propertyName)) {
+            $this->editAnagrafica($this->{$propertyName});
+            $this->emit('load-anagrafica-modal');
+        }
+    }
+
+    public function removePasseggero($x){
+        if (!in_array($x, [1, 2, 3, 4])) {
+            return;
+        }
+
+        $propertyName = 'data_passeggero_' . ($x - 1);
+
+        if (property_exists($this, $propertyName)) {
+            $this->{$propertyName} = 0;
+            $this->emit('add-default-value', 0, '', $propertyName);
+        }
+    }
+
+    public function addPasseggero($x){
+        $this->resetAnagrafica();
+        $this->currentPasseggero = $x;
+        $this->emit('load-anagrafica-modal');
+    }
+}

+ 80 - 38
app/Http/Livewire/Traits/HasVeicoli.php

@@ -114,46 +114,8 @@ trait HasVeicoli{
     public $data_effetto_danno_4;
     public $data_parte_macchina_4;
     public $data_cinture_conducente;
-    public $data_cinture_passeggeri_0;
-    public $data_cinture_passeggeri_1;
-    public $data_cinture_passeggeri_2;
-    public $data_cinture_passeggeri_3;
-    public $data_casco_conducente;
-    public $data_casco_passeggero;
-    public $data_casco_omologazione_conducente;
-    public $data_casco_omologazione_passeggero;
-    public $data_passeggero_0;
-    public $data_infortunato_0;
-    public $data_infortunato_ospedale_0;
-    public $data_passeggero_1;
-    public $data_infortunato_1;
-    public $data_infortunato_ospedale_1;
-    public $data_passeggero_2;
-    public $data_infortunato_2;
-    public $data_infortunato_ospedale_2;
-    public $data_passeggero_3;
-    public $data_infortunato_3;
-    public $data_infortunato_ospedale_3;
-    public $data_infortunato_extra_0;
-    public $data_infortunato_extra_1;
-    public $data_infortunato_extra_2;
-    public $data_infortunato_extra_3;
-    public $data_testi_oculari_0;
-    public $data_testi_oculari_stato_0;
-    public $data_testi_oculari_1;
-    public $data_testi_oculari_stato_1;
-    public $data_testi_oculari_2;
-    public $data_testi_oculari_stato_2;
-    public $data_testi_oculari_3;
-    public $data_testi_oculari_stato_3;
-    public $generalizzato;
-    public $generalizzato_altrove;
-    public $infortunato;
-    public $infortunato_ospedale;
     public $verbale_violazione_numero;
     public $articolo_violato;
-    public $cds;
-
 
     public function resetVeicolo(){
         $this->loadTarga = '';
@@ -525,4 +487,84 @@ trait HasVeicoli{
         $this->emit('add-default-value', $this->data_conducenti, $this->getAnagrafica($this->data_conducenti), 'data_conducenti');
 
     }
+
+    public function getVeicolo($veicolo){
+        if ($veicolo > 0)
+        {
+            $ret = Vehicle::findOrFail($veicolo);
+            return ($ret->marca ? $ret->marca->name : '') . " " . ($ret->modello ? $ret->modello->name : '') . " " . $ret->targa;
+        }
+        return "";
+    }
+
+    public function veicoloSave()
+    {
+        $this->validate([
+            'vei_tipo_id' => 'required',
+            'vei_marca_id' => 'required',
+            'vei_modello_id' => 'required',
+            'vei_carta_circolazione_rilasciata_da' => 'required',
+            'vei_foreign_country' => 'required',
+            'vei_carta_circolazione_rilasciata_da_di' => 'required',
+            'vei_destinazione_uso' => 'required',
+        ], [
+            'vei_tipo_id.required' => 'Il campo "Tipo di veicolo" è obbligatorio.',
+            'vei_marca_id.required' => 'Il campo "Marca" è obbligatorio.',
+            'vei_modello_id.required' => 'Il campo "Modello" è obbligatorio.',
+            'vei_carta_circolazione_rilasciata_da.required' => 'Il campo "Rilasciata da" è obbligatorio.',
+            'vei_foreign_country.required' => 'Il campo "Paese di rilascio" è obbligatorio.',
+            'vei_carta_circolazione_rilasciata_da_di.required' => 'Il campo "Località di rilascio" è obbligatorio.',
+            'vei_destinazione_uso.required' => 'Il campo "Destinazione d\'uso" è obbligatorio.',
+        ]);
+
+        if ($this->currentVeicolo > 0){
+            Vehicle::whereId($this->currentVeicolo)->update([
+                'tipo_id' => $this->vei_tipo_id,
+                'marca_id' => $this->vei_marca_id,
+                'marca_altro' => $this->vei_marca_altro,
+                'modello_id' => $this->vei_modello_id,
+                'modello_altro' => $this->vei_modello_altro,
+                'colore' => $this->vei_colore,
+                'targa' => $this->vei_targa,
+                'carta_circolazione' => $this->vei_carta_circolazione,
+                'carta_circolazione_rilasciata_da' => $this->vei_carta_circolazione_rilasciata_da,
+                'carta_circolazione_rilasciata_da_altro' => $this->vei_carta_circolazione_rilasciata_da_altro,
+                'foreign_country' => $this->vei_foreign_country,
+                'carta_circolazione_rilasciata_da_di_foreign_country' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_country,
+                'carta_circolazione_rilasciata_da_di_foreign_localita' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_localita,
+                'carta_circolazione_rilasciata_da_di' => $this->vei_carta_circolazione_rilasciata_da_di,
+                'carta_circolazione_rilasciata_il' => $this->vei_carta_circolazione_rilasciata_il,
+                'data_ultima_revisione' => $this->vei_data_ultima_revisione,
+                'cilindrata' => $this->vei_cilindrata,
+                'peso_complessivo' => $this->vei_peso_complessivo,
+                'destinazione_uso' => $this->vei_destinazione_uso
+            ]);
+        }else{
+            $veicolo = Vehicle::create([
+                'tipo_id' => $this->vei_tipo_id,
+                'marca_id' => $this->vei_marca_id,
+                'marca_altro' => $this->vei_marca_altro,
+                'modello_id' => $this->vei_modello_id,
+                'modello_altro' => $this->vei_modello_altro,
+                'colore' => $this->vei_colore,
+                'targa' => $this->vei_targa,
+                'carta_circolazione' => $this->vei_carta_circolazione,
+                'carta_circolazione_rilasciata_da' => $this->vei_carta_circolazione_rilasciata_da,
+                'carta_circolazione_rilasciata_da_altro' => $this->vei_carta_circolazione_rilasciata_da_altro,
+                'foreign_country' => $this->vei_foreign_country,
+                'carta_circolazione_rilasciata_da_di_foreign_country' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_country,
+                'carta_circolazione_rilasciata_da_di_foreign_localita' => $this->vei_carta_circolazione_rilasciata_da_di_foreign_localita,
+                'carta_circolazione_rilasciata_da_di' => $this->vei_carta_circolazione_rilasciata_da_di,
+                'carta_circolazione_rilasciata_il' => $this->vei_carta_circolazione_rilasciata_il,
+                'data_ultima_revisione' => $this->vei_data_ultima_revisione,
+                'cilindrata' => $this->vei_cilindrata,
+                'peso_complessivo' => $this->vei_peso_complessivo,
+                'destinazione_uso' => $this->vei_destinazione_uso
+            ]);
+            $this->updateVeicoloParteCoinvolta($veicolo->id, $this->currentProgressive);
+        }
+        $this->resetVeicolo();
+        $this->emit('close-modal');
+    }
+
 }