Roberto Santini пре 2 недеља
родитељ
комит
7abe400559
2 измењених фајлова са 34 додато и 2 уклоњено
  1. 12
    2
      app/Services/FattureInCloudClient.php
  2. 22
    0
      resources/views/azienda/fic-scripts.blade.php

+ 12
- 2
app/Services/FattureInCloudClient.php Прегледај датотеку

@@ -50,9 +50,12 @@ class FattureInCloudClient
50 50
             'page' => max(1, $page),
51 51
             'per_page' => 20,
52 52
         ];
53
-        $term = trim(str_replace("'", '', $term));
53
+        $term = $this->searchTerm($term);
54 54
         if ($term !== '') {
55
-            $params['q'] = "(name like '%{$term}%' or vat_number like '%{$term}%' or tax_code like '%{$term}%')";
55
+            // contains, senza % e senza parentesi: like '%…%' viene bloccato
56
+            // dal gateway di Fatture in Cloud con un 403 senza corpo JSON.
57
+            $quoted = "'{$term}'";
58
+            $params['q'] = "name contains {$quoted} or vat_number contains {$quoted} or tax_code contains {$quoted}";
56 59
         }
57 60
 
58 61
         $json = $this->decode($this->http()->get($this->url('/entities/clients'), $params));
@@ -76,6 +79,13 @@ class FattureInCloudClient
76 79
         ];
77 80
     }
78 81
 
82
+    private function searchTerm(string $term): string
83
+    {
84
+        $term = trim(str_replace(["'", '\\', '%', '(', ')', "\0", "\n", "\r"], '', $term));
85
+
86
+        return mb_substr($term, 0, 80);
87
+    }
88
+
79 89
     public function getClient(int $id): array
80 90
     {
81 91
         $json = $this->decode($this->http()->get($this->url('/entities/clients/'.$id), [

+ 22
- 0
resources/views/azienda/fic-scripts.blade.php Прегледај датотеку

@@ -137,6 +137,28 @@ $(function () {
137 137
             results: data.results || [],
138 138
             pagination: { more: !!(data.pagination && data.pagination.more) }
139 139
           };
140
+        },
141
+        transport: function (params, success, failure) {
142
+          const request = $.ajax(params);
143
+          request.done(function (data) {
144
+            const el = document.getElementById('ficErrorAlert');
145
+            if (el.dataset.searchError === '1') {
146
+              el.removeAttribute('data-search-error');
147
+              showAlert('ficErrorAlert', '');
148
+            }
149
+            success(data);
150
+          });
151
+          request.fail(function (xhr) {
152
+            if (xhr.status === 0) {
153
+              failure();
154
+              return;
155
+            }
156
+            const message = (xhr.responseJSON && xhr.responseJSON.message) || 'Impossibile cercare su Fatture in Cloud.';
157
+            showAlert('ficErrorAlert', message);
158
+            document.getElementById('ficErrorAlert').dataset.searchError = '1';
159
+            failure();
160
+          });
161
+          return request;
140 162
         }
141 163
       }
142 164
     });

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