Skip to content

Commit 79cf4de

Browse files
committed
refactor: importazione anagrafiche a blocchi e ottimizzazione per evitare duplicati
1 parent 9adffd5 commit 79cf4de

6 files changed

Lines changed: 523 additions & 224 deletions

File tree

modules/anagrafiche/src/Anagrafica.php

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
use Common\SimpleModelTrait;
2424
use Illuminate\Database\Eloquent\Model;
2525
use Illuminate\Database\Eloquent\SoftDeletes;
26+
use Models\Locale;
2627
use Modules\Anagrafiche\Tipo as TipoAnagrafica;
2728
use Modules\Contratti\Contratto;
2829
use Modules\DDT\DDT;
2930
use Modules\Fatture\Fattura;
3031
use Modules\Interventi\Intervento;
3132
use Modules\Ordini\Ordine;
33+
use Modules\PianiSconto\PianoSconto;
3234
use Modules\Preventivi\Preventivo;
3335
use Modules\TipiIntervento\Tipo as TipoSessione;
3436
use Plugins\DichiarazioniIntento\Dichiarazione;
@@ -37,12 +39,14 @@
3739

3840
class Anagrafica extends Model
3941
{
40-
use SimpleModelTrait;
4142
use RecordTrait;
43+
use SimpleModelTrait;
4244
use SoftDeletes;
4345

4446
protected $table = 'an_anagrafiche';
47+
4548
protected $primaryKey = 'idanagrafica';
49+
4650
protected $module = 'Anagrafiche';
4751

4852
protected $guarded = [];
@@ -285,6 +289,81 @@ public function setCodiceDestinatarioAttribute($value)
285289
$this->attributes['codice_destinatario'] = trim(strtoupper((string) $value));
286290
}
287291

292+
public function setCodiceAttribute($value)
293+
{
294+
$this->attributes['codice'] = trim((string) $value);
295+
}
296+
297+
public function setRagioneSocialeAttribute($value)
298+
{
299+
$this->attributes['ragione_sociale'] = trim((string) $value);
300+
}
301+
302+
public function setTelefonoAttribute($value)
303+
{
304+
$this->attributes['telefono'] = trim((string) $value);
305+
}
306+
307+
public function setIndirizzoAttribute($value)
308+
{
309+
$this->attributes['indirizzo'] = trim((string) $value);
310+
}
311+
312+
public function setCapAttribute($value)
313+
{
314+
$this->attributes['cap'] = trim((string) $value);
315+
}
316+
317+
public function setCellulareAttribute($value)
318+
{
319+
$this->attributes['cellulare'] = trim((string) $value);
320+
}
321+
322+
public function setFaxAttribute($value)
323+
{
324+
$this->attributes['fax'] = trim((string) $value);
325+
}
326+
327+
public function setEmailAttribute($value)
328+
{
329+
$this->attributes['email'] = trim((string) $value);
330+
}
331+
332+
public function setPecAttribute($value)
333+
{
334+
$this->attributes['pec'] = trim((string) $value);
335+
}
336+
337+
public function setSitewebAttribute($value)
338+
{
339+
$this->attributes['sitoweb'] = trim((string) $value);
340+
}
341+
342+
public function setLuogoNascitaAttribute($value)
343+
{
344+
$this->attributes['luogo_nascita'] = trim((string) $value);
345+
}
346+
347+
public function setSessoAttribute($value)
348+
{
349+
$this->attributes['sesso'] = trim((string) $value);
350+
}
351+
352+
public function setNoteAttribute($value)
353+
{
354+
$this->attributes['note'] = trim((string) $value);
355+
}
356+
357+
public function setProvinciaAttribute($value)
358+
{
359+
$this->attributes['provincia'] = trim((string) $value);
360+
}
361+
362+
public function setCittaAttribute($value)
363+
{
364+
$this->attributes['citta'] = trim((string) $value);
365+
}
366+
288367
/**
289368
* Restituisce la sede legale collegata.
290369
*
@@ -359,20 +438,20 @@ public function interventi()
359438

360439
public function pianoScontoVendite()
361440
{
362-
return $this->belongsTo(\Modules\PianiSconto\PianoSconto::class, 'id_piano_sconto_vendite');
441+
return $this->belongsTo(PianoSconto::class, 'id_piano_sconto_vendite');
363442
}
364443

365444
public function pianoScontoAcquisti()
366445
{
367-
return $this->belongsTo(\Modules\PianiSconto\PianoSconto::class, 'id_piano_sconto_acquisti');
446+
return $this->belongsTo(PianoSconto::class, 'id_piano_sconto_acquisti');
368447
}
369448

370449
/**
371450
* Restituisce il piano di sconto in base alla direzione.
372451
*
373452
* @param string $dir
374453
*
375-
* @return \Modules\PianiSconto\PianoSconto|null
454+
* @return PianoSconto|null
376455
*/
377456
public function pianoSconto($dir)
378457
{
@@ -491,13 +570,15 @@ protected function geolocalizzazione()
491570
}
492571
$ch = curl_init();
493572

494-
$lang = \Models\Locale::find(setting('Lingua'))->language_code;
573+
$lang = Locale::find(setting('Lingua'))->language_code;
495574
$url = 'https://nominatim.openstreetmap.org/search.php?q='.$indirizzo.'&format=jsonv2&accept-language='.$lang;
496575
$user_agent = 'traccar';
497576
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
498577
curl_setopt($ch, CURLOPT_URL, $url);
499578
curl_setopt($ch, CURLOPT_HEADER, 0);
500579
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
580+
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
581+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
501582
$data = json_decode(curl_exec($ch));
502583
curl_close($ch);
503584

@@ -515,7 +596,17 @@ protected function geolocalizzazione()
515596
return false;
516597
}
517598

518-
$response = file_get_contents($url);
599+
$context = stream_context_create([
600+
'http' => [
601+
'timeout' => 10,
602+
],
603+
]);
604+
605+
$response = @file_get_contents($url, false, $context);
606+
if ($response === false) {
607+
return false;
608+
}
609+
519610
$data = json_decode($response, true);
520611

521612
if ($data['status'] == 'OK') {

0 commit comments

Comments
 (0)