Aggiunta informazioni sui conflitti API da applicazione
This commit is contained in:
parent
528c93fc9e
commit
a56166da22
|
@ -26,6 +26,7 @@ use API\Interfaces\UpdateInterface;
|
|||
use API\Resource;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Risorsa di base per la gestione delle operazioni standard di comunicazione con l'applicazione.
|
||||
|
@ -142,7 +143,7 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
|
|||
*
|
||||
* @param string $last_sync_at
|
||||
*
|
||||
* @return array
|
||||
* @return array<number, array>
|
||||
*/
|
||||
abstract public function getModifiedRecords($last_sync_at);
|
||||
|
||||
|
@ -190,6 +191,28 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Genera la mappatura id => updated_at necessaria per la gestione dei record modificati.
|
||||
*
|
||||
* @param $records
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected function mapModifiedRecords($records)
|
||||
{
|
||||
if ($records instanceof Collection){
|
||||
return $records->mapToGroups(function ($item, $key) {
|
||||
return [$item['id'] => $item];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
return array_reduce($records, function ($accumulator, $item) {
|
||||
$accumulator[$item['id']] = $item;
|
||||
|
||||
return $accumulator;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converte i valori numerici in stringhe.
|
||||
*
|
||||
|
|
|
@ -30,7 +30,7 @@ class AliquoteIva extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT co_iva.id FROM co_iva WHERE deleted_at IS NULL';
|
||||
$query = 'SELECT co_iva.id, co_iva.updated_at FROM co_iva WHERE deleted_at IS NULL';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
|
@ -39,7 +39,7 @@ class AliquoteIva extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -56,7 +56,8 @@ class AllegatiInterventi extends AppResource
|
|||
return [];
|
||||
}
|
||||
|
||||
$query = 'SELECT zz_files.id FROM zz_files WHERE id_module = (SELECT `id` FROM `zz_modules` WHERE `name` = "Interventi") AND id_record IN ('.implode(',', $interventi).')';
|
||||
$id_interventi = array_keys($interventi);
|
||||
$query = 'SELECT zz_files.id, zz_files.updated_at FROM zz_files WHERE id_module = (SELECT `id` FROM `zz_modules` WHERE `name` = "Interventi") AND id_record IN ('.implode(',', $id_interventi).')';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
|
@ -65,7 +66,7 @@ class AllegatiInterventi extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -30,7 +30,7 @@ class Articoli extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT mg_articoli.id FROM mg_articoli WHERE deleted_at IS NULL';
|
||||
$query = 'SELECT mg_articoli.id, mg_articoli.updated_at FROM mg_articoli WHERE deleted_at IS NULL';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
|
@ -39,7 +39,7 @@ class Articoli extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -33,7 +33,10 @@ class Clienti extends AppResource
|
|||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$parameters = [];
|
||||
$query = "SELECT an_anagrafiche.idanagrafica AS id FROM an_anagrafiche
|
||||
$query = "SELECT
|
||||
an_anagrafiche.idanagrafica AS id,
|
||||
an_anagrafiche.updated_at
|
||||
FROM an_anagrafiche
|
||||
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
|
||||
WHERE an_tipianagrafiche.descrizione = 'Cliente' AND an_anagrafiche.deleted_at IS NULL";
|
||||
|
@ -71,7 +74,7 @@ class Clienti extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query, $parameters);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -44,7 +44,10 @@ class Contratti extends AppResource implements RetrieveInterface
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = "SELECT DISTINCT(co_contratti.id) AS id FROM co_contratti
|
||||
$query = "SELECT
|
||||
DISTINCT(co_contratti.id) AS id,
|
||||
co_contratti.updated_at
|
||||
FROM co_contratti
|
||||
INNER JOIN co_staticontratti ON co_staticontratti.id = co_contratti.idstato
|
||||
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_contratti.idanagrafica
|
||||
INNER JOIN an_tipianagrafiche_anagrafiche ON an_tipianagrafiche_anagrafiche.idanagrafica = an_anagrafiche.idanagrafica
|
||||
|
@ -58,7 +61,7 @@ class Contratti extends AppResource implements RetrieveInterface
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -32,7 +32,7 @@ class Impianti extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Impianto::select('id')
|
||||
$statement = Impianto::select('id', 'updated_at')
|
||||
->whereHas('anagrafica.tipi', function (Builder $query) {
|
||||
$query->where('descrizione', '=', 'Cliente');
|
||||
});
|
||||
|
@ -42,10 +42,9 @@ class Impianti extends AppResource
|
|||
$statement = $statement->where('updated_at', '>', $last_sync_at);
|
||||
}
|
||||
|
||||
$results = $statement->get()
|
||||
->pluck('id');
|
||||
$records = $statement->get();
|
||||
|
||||
return $results;
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -30,7 +30,7 @@ class Impostazioni extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = "SELECT zz_settings.id FROM zz_settings WHERE (sezione = 'Applicazione'";
|
||||
$query = "SELECT zz_settings.id, zz_settings.updated_at FROM zz_settings WHERE (sezione = 'Applicazione'";
|
||||
|
||||
// Aggiunta delle impostazioni esterne alla sezione Applicazione
|
||||
$impostazioni_esterne = $this->getImpostazioniEsterne();
|
||||
|
@ -51,7 +51,7 @@ class Impostazioni extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -99,7 +99,10 @@ class Interventi extends AppResource
|
|||
// Informazioni sull'utente
|
||||
$id_tecnico = Auth::user()->id_anagrafica;
|
||||
|
||||
$query = 'SELECT in_interventi.id FROM in_interventi WHERE
|
||||
$query = 'SELECT
|
||||
in_interventi.id,
|
||||
in_interventi.updated_at
|
||||
FROM in_interventi WHERE
|
||||
deleted_at IS NULL AND (
|
||||
in_interventi.id IN (
|
||||
SELECT idintervento FROM in_interventi_tecnici
|
||||
|
@ -126,7 +129,7 @@ class Interventi extends AppResource
|
|||
':id_tecnico' => $id_tecnico,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -44,7 +44,7 @@ class Preventivi extends AppResource implements RetrieveInterface
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = "SELECT DISTINCT(co_preventivi.id) AS id FROM co_preventivi
|
||||
$query = "SELECT DISTINCT(co_preventivi.id) AS id, co_preventivi.updated_at FROM co_preventivi
|
||||
INNER JOIN co_statipreventivi ON co_statipreventivi.id = co_preventivi.idstato
|
||||
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_preventivi.idanagrafica
|
||||
INNER JOIN an_tipianagrafiche_anagrafiche ON an_tipianagrafiche_anagrafiche.idanagrafica = an_anagrafiche.idanagrafica
|
||||
|
@ -58,7 +58,7 @@ class Preventivi extends AppResource implements RetrieveInterface
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -31,7 +31,7 @@ class Referenti extends AppResource implements RetrieveInterface
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = "SELECT DISTINCT(an_referenti.id) AS id FROM an_referenti
|
||||
$query = "SELECT DISTINCT(an_referenti.id) AS id, an_referenti.updated_at FROM an_referenti
|
||||
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = an_referenti.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
|
||||
|
@ -44,7 +44,7 @@ class Referenti extends AppResource implements RetrieveInterface
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -78,7 +78,7 @@ class RigheInterventi extends AppResource
|
|||
$user = Auth::user();
|
||||
$id_tecnico = $user->id_anagrafica;
|
||||
|
||||
$query = 'SELECT in_righe_interventi.id FROM in_righe_interventi WHERE in_righe_interventi.idintervento IN (
|
||||
$query = 'SELECT in_righe_interventi.id, in_righe_interventi.updated_at FROM in_righe_interventi WHERE in_righe_interventi.idintervento IN (
|
||||
SELECT in_interventi.id FROM in_interventi WHERE
|
||||
in_interventi.id IN (
|
||||
SELECT idintervento FROM in_interventi_tecnici
|
||||
|
@ -99,7 +99,7 @@ class RigheInterventi extends AppResource
|
|||
':id_tecnico' => $id_tecnico,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -30,7 +30,7 @@ class Sedi extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = "SELECT DISTINCT(an_sedi.id) AS id FROM an_sedi
|
||||
$query = "SELECT DISTINCT(an_sedi.id) AS id, an_sedi.updated_at FROM an_sedi
|
||||
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
|
||||
|
@ -43,7 +43,7 @@ class Sedi extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -86,11 +86,12 @@ class SessioniInterventi extends AppResource
|
|||
return [];
|
||||
}
|
||||
|
||||
$id_interventi = array_keys($interventi);
|
||||
$query = 'SELECT in_interventi_tecnici.id
|
||||
FROM in_interventi_tecnici
|
||||
INNER JOIN in_interventi ON in_interventi_tecnici.idintervento = in_interventi.id
|
||||
WHERE
|
||||
in_interventi.id IN ('.implode(',', $interventi).')
|
||||
in_interventi.id IN ('.implode(',', $id_interventi).')
|
||||
AND (orario_fine BETWEEN :period_start AND :period_end)';
|
||||
|
||||
// Filtro per data
|
||||
|
@ -102,7 +103,7 @@ class SessioniInterventi extends AppResource
|
|||
':period_end' => $end,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -30,7 +30,7 @@ class StatiIntervento extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT in_statiintervento.idstatointervento AS id FROM in_statiintervento';
|
||||
$query = 'SELECT in_statiintervento.idstatointervento AS id, in_statiintervento.updated_at FROM in_statiintervento';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
|
@ -39,7 +39,7 @@ class StatiIntervento extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -44,8 +44,10 @@ class TariffeContratti extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT CONCAT(idtipointervento, "-", idcontratto) AS id
|
||||
FROM co_contratti_tipiintervento
|
||||
$query = 'SELECT
|
||||
CONCAT(idtipointervento, "-", idcontratto) AS id,
|
||||
co_contratti_tipiintervento.updated_at
|
||||
FROM co_contratti_tipiintervento
|
||||
INNER JOIN co_contratti ON co_contratti.id = co_contratti_tipiintervento.idcontratto
|
||||
INNER JOIN co_staticontratti ON co_staticontratti.id = co_contratti.idstato
|
||||
WHERE co_staticontratti.is_pianificabile = 1';
|
||||
|
@ -57,7 +59,7 @@ class TariffeContratti extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -30,7 +30,7 @@ class TariffeTecnici extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT id FROM in_tariffe';
|
||||
$query = 'SELECT id, updated_at FROM in_tariffe';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
|
@ -39,7 +39,7 @@ class TariffeTecnici extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -32,7 +32,7 @@ class Tecnici extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Anagrafica::select('idanagrafica')
|
||||
$statement = Anagrafica::select('idanagrafica as id', 'updated_at')
|
||||
->whereHas('tipi', function (Builder $query) {
|
||||
$query->where('descrizione', '=', 'Tecnico');
|
||||
});
|
||||
|
@ -42,10 +42,9 @@ class Tecnici extends AppResource
|
|||
$statement = $statement->where('updated_at', '>', $last_sync_at);
|
||||
}
|
||||
|
||||
$results = $statement->get()
|
||||
->pluck('idanagrafica');
|
||||
$records = $statement->get();
|
||||
|
||||
return $results;
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
|
@ -30,7 +30,7 @@ class TipiIntervento extends AppResource
|
|||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT in_tipiintervento.idtipointervento AS id FROM in_tipiintervento';
|
||||
$query = 'SELECT in_tipiintervento.idtipointervento AS id, in_tipiintervento.updated_at FROM in_tipiintervento';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
|
@ -39,7 +39,7 @@ class TipiIntervento extends AppResource
|
|||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
return $this->mapModifiedRecords($records);
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
|
|
Loading…
Reference in New Issue