Browse Source

cerca fic

Roberto Santini 2 weeks ago
parent
commit
7abe400559

+ 12
- 2
app/Services/FattureInCloudClient.php View File

50
             'page' => max(1, $page),
50
             'page' => max(1, $page),
51
             'per_page' => 20,
51
             'per_page' => 20,
52
         ];
52
         ];
53
-        $term = trim(str_replace("'", '', $term));
53
+        $term = $this->searchTerm($term);
54
         if ($term !== '') {
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
         $json = $this->decode($this->http()->get($this->url('/entities/clients'), $params));
61
         $json = $this->decode($this->http()->get($this->url('/entities/clients'), $params));
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
     public function getClient(int $id): array
89
     public function getClient(int $id): array
80
     {
90
     {
81
         $json = $this->decode($this->http()->get($this->url('/entities/clients/'.$id), [
91
         $json = $this->decode($this->http()->get($this->url('/entities/clients/'.$id), [

+ 22
- 0
resources/views/azienda/fic-scripts.blade.php View File

137
             results: data.results || [],
137
             results: data.results || [],
138
             pagination: { more: !!(data.pagination && data.pagination.more) }
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…
Cancel
Save