2020-07-15 16:58:01 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-15 16:58:01 +02:00
|
|
|
|
2020-07-24 10:20:42 +02:00
|
|
|
namespace API\App\v1;
|
2020-07-15 16:58:01 +02:00
|
|
|
|
2020-07-24 10:20:42 +02:00
|
|
|
use API\App\AppResource;
|
2020-07-15 16:58:01 +02:00
|
|
|
|
|
|
|
class Sedi extends AppResource
|
|
|
|
{
|
2020-07-28 12:12:27 +02:00
|
|
|
public function getCleanupData($last_sync_at)
|
2020-07-15 16:58:01 +02:00
|
|
|
{
|
2020-07-28 09:42:05 +02:00
|
|
|
return $this->getMissingIDs('an_sedi', 'id', $last_sync_at);
|
2020-07-15 16:58:01 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 12:12:27 +02:00
|
|
|
public function getModifiedRecords($last_sync_at)
|
2020-07-15 16:58:01 +02:00
|
|
|
{
|
2021-02-24 11:48:38 +01:00
|
|
|
$query = "SELECT DISTINCT(an_sedi.id) AS id, an_sedi.updated_at FROM an_sedi
|
2020-07-15 16:58:01 +02:00
|
|
|
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = an_sedi.idanagrafica
|
|
|
|
INNER JOIN an_tipianagrafiche_anagrafiche ON an_tipianagrafiche_anagrafiche.idanagrafica = an_anagrafiche.idanagrafica
|
|
|
|
INNER JOIN an_tipianagrafiche ON an_tipianagrafiche_anagrafiche.idtipoanagrafica = an_tipianagrafiche.idtipoanagrafica
|
2020-07-16 11:32:56 +02:00
|
|
|
WHERE an_tipianagrafiche.descrizione = 'Cliente' AND an_anagrafiche.deleted_at IS NULL";
|
2020-07-15 16:58:01 +02:00
|
|
|
|
|
|
|
// Filtro per data
|
|
|
|
if ($last_sync_at) {
|
2020-07-28 09:42:05 +02:00
|
|
|
$query .= ' AND an_sedi.updated_at > '.prepare($last_sync_at);
|
2020-07-15 16:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$records = database()->fetchArray($query);
|
|
|
|
|
2021-02-24 11:48:38 +01:00
|
|
|
return $this->mapModifiedRecords($records);
|
2020-07-15 16:58:01 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 12:12:27 +02:00
|
|
|
public function retrieveRecord($id)
|
2020-07-15 16:58:01 +02:00
|
|
|
{
|
|
|
|
// Gestione della visualizzazione dei dettagli del record
|
|
|
|
$query = 'SELECT an_sedi.id,
|
2020-07-27 16:28:46 +02:00
|
|
|
an_sedi.idanagrafica AS id_cliente,
|
2020-07-15 16:58:01 +02:00
|
|
|
an_sedi.nomesede AS nome,
|
|
|
|
an_sedi.piva AS partita_iva,
|
|
|
|
an_sedi.codice_fiscale,
|
|
|
|
an_sedi.indirizzo,
|
|
|
|
an_sedi.indirizzo2,
|
|
|
|
an_sedi.citta,
|
|
|
|
an_sedi.cap,
|
|
|
|
an_sedi.provincia,
|
|
|
|
an_sedi.km,
|
|
|
|
IFNULL(an_sedi.lat, 0.00) AS latitudine,
|
|
|
|
IFNULL(an_sedi.lng, 0.00) AS longitudine,
|
|
|
|
an_nazioni.nome AS nazione,
|
|
|
|
an_sedi.telefono,
|
|
|
|
an_sedi.cellulare,
|
|
|
|
an_sedi.fax,
|
|
|
|
an_sedi.email
|
|
|
|
FROM an_sedi
|
|
|
|
LEFT OUTER JOIN an_nazioni ON an_sedi.id_nazione = an_nazioni.id
|
|
|
|
WHERE an_sedi.id = '.prepare($id);
|
|
|
|
|
|
|
|
$record = database()->fetchOne($query);
|
|
|
|
|
|
|
|
return $record;
|
|
|
|
}
|
|
|
|
}
|