Преглед изворни кода

Merge branch 'main' into develop

FabioFratini пре 11 месеци
родитељ
комит
04fd2bc6c6
2 измењених фајлова са 65 додато и 23 уклоњено
  1. 55 4
      app/Http/Livewire/Report.php
  2. 10 19
      resources/views/livewire/report.blade.php

+ 55 - 4
app/Http/Livewire/Report.php

@@ -1227,10 +1227,18 @@ class Report extends Component
 
             $targa = $this->vei_targa;
 
-            try {
+            try
+            {
+                Log::info("veicolo con targa: " . $targa);
+
                 $wd = "dettaglioAutoveicoloBase";
                 $wd = "datiCartaCircolazioneAutoveicoloProprietario";
+
+                Log::info("wd: " . $wd);
+
                 $url = env('MCTC_URL', 'https://e-servizicoll.dtt.ilportaledellautomobilista.it/Info-ws-sh/services');
+                Log::info("url: " . $url);
+
                 $client = new \SoapClient($url . '/' . $wd . '/' . $wd . '.wsdl', array(
                     'stream_context' => stream_context_create(array(
                         'ssl' => array(
@@ -1241,8 +1249,10 @@ class Report extends Component
                     )),
                     'trace' => 1
                 ));
+
                 $utente = env('MCTC_USER', '');
                 $password = env('MCTC_PASSWORD', '');
+
                 $xml = '<wsse:Security
                 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                 SOAP-ENV:mustUnderstand="1">
@@ -1273,16 +1283,28 @@ class Report extends Component
                             "pdf" => false
                         )
                     ));
+
+                    if (!$this->handleMCTCError($obj)) {
+                        $this->emit('hideLoading', 'btTarga');
+                        return;
+                    }
+
                     Log::debug(print_r($obj, true));
+
                     $this->vei_data_ultima_revisione = @$obj->DatiUltimaRevisione->dataUltimaRevisione;
                     $this->vei_carta_circolazione = @$obj->DatiAmministrativiVeicolo[0]->NumeroCartaCircolazione;
                     $this->vei_carta_circolazione_rilasciata_il = @$obj->DatiAmministrativiVeicolo[0]->DataEmissioneDocumento;
                     $this->vei_cilindrata = @$obj->DatiTecniciVeicolo->CilindrataInCentimetriCubi;
                     $this->vei_peso_complessivo = @$obj->DatiTecniciVeicolo->TaraInKG;
-                } catch (\SoapFault $fault) {
+                }
+                catch(\SoapFault $fault)
+                {
                     $this->loadTarga = $fault->getMessage();
                 }
-            } catch (\Exception $ex) {
+            }
+            catch(\Exception $ex)
+            {
+                Log::error($ex->getMessage());
             }
 
             $this->emit('hideLoading', 'btTarga');
@@ -1295,9 +1317,15 @@ class Report extends Component
         if ($this->anag_documento_numero != '') {
             $patente = $this->anag_documento_numero;
 
+            Log::info("patente numero: " . $patente);
+
+            Log::info("patente numero: " . $patente);
+
             try {
                 $wd = "dettaglioPatenteBase";
                 $url = env('MCTC_URL', 'https://e-servizicoll.dtt.ilportaledellautomobilista.it/Info-ws-sh/services');
+                Log::info("url: " . $url);
+
                 $client = new \SoapClient($url . '/' . $wd . '/' . $wd . '.wsdl', array(
                     'stream_context' => stream_context_create(array(
                         'ssl' => array(
@@ -1342,6 +1370,11 @@ class Report extends Component
                         )
                     ));
 
+                    if (!$this->handleMCTCError($obj)) {
+                        $this->emit('hideLoading', 'btTarga');
+                        return;
+                    }
+
                     Log::debug(print_r($obj, true));
                     $this->anag_firstname = @$obj->dettaglioPatenteBaseOutput->anagrafica->nome;
                     $this->anag_lastname = @$obj->dettaglioPatenteBaseOutput->anagrafica->cognome;
@@ -1355,11 +1388,29 @@ class Report extends Component
                     '</xmp><br/><br/> Error Message : <br/>',
                     $fault->getMessage();
                 }
-            } catch (\SoapFault $ex) {
+            }
+            catch(\SoapFault $ex)
+            {
+                Log::error($ex->getMessage());
             }
 
             $this->emit('hideLoading', 'btPatente');
+
+        }
+
+    }
+
+    protected function handleMCTCError($response)
+    {
+        if (isset($response->errore) && $response->errore->codiceErrore === '01') {
+            Log::error("MCTC API Error: {$response->errore->descrizioneErrore}");
+            if (str_contains($response->errore->descrizioneErrore, 'Errore di validazione - string length')) {
+                session()->flash('error', 'Errore di validazione numero di caratteri errato');
+            } else {
+                session()->flash('error', $response->errore->descrizioneErrore);
+            }            return false;
         }
+        return true;
     }
 
     public function print($id)

+ 10 - 19
resources/views/livewire/report.blade.php

@@ -17,12 +17,16 @@
             {{ session()->get('success') }}
         </div>
     @endif
-    @if (session()->has('error'))
-        <div class="alert alert-danger" role="alert">
-            {{ session()->get('error') }}
-        </div>
-    @endif
-
+    <div>
+        @if (session()->has('error'))
+        <div class="alert alert-danger alert-dismissible fade show position-fixed" role="alert" style="top: 20px; left: 50%; transform: translateX(-50%); z-index: 10000;">
+            {{ session('error') }}
+            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
+                <span aria-hidden="true">&times;</span>
+             </button>
+             </div>
+        @endif
+     </div>
     @if (count($errors) > 0)
         <div class="alert alert-danger">
             @foreach ($errors->all() as $e)
@@ -2843,7 +2847,6 @@
                                     <button wire:click="getByPatente()" type="button"
                                         class="btn btn-block btn-success float-right btPatente" style="max-width:150px">Dati
                                         MCTC</button>
-                                    <span class="btPatenteText" style="display:none">Caricamento...</span>
                                 </div>
                             </div>
                             <div class="row mt-3">
@@ -5982,18 +5985,6 @@
             $("." + cls + "Text").hide();
         });
 
-
-        $(document).ready(function () {
-            $(document).on('click', '.btPatente', function () {
-                $(".btPatente").hide();
-                $(".btPatenteText").show();
-            });
-            $(document).on('click', '.btTarga', function () {
-                $(".btTarga").hide();
-                $(".btTargaText").show();
-            });
-        });
-
         Livewire.on('load-polizza-modal', () => {
             $('.valida_dal').on('change', function (e) {
                 @this.set('valida_dal', $(this).val());