Miglioramenti strutturali di base

This commit is contained in:
Thomas Zilio 2020-07-28 09:42:05 +02:00
parent a7080ae4b1
commit cd505d35f6
19 changed files with 350 additions and 127 deletions

View File

@ -7,20 +7,33 @@ use API\Interfaces\DeleteInterface;
use API\Interfaces\RetrieveInterface;
use API\Interfaces\UpdateInterface;
use API\Resource;
use Carbon\Carbon;
use Exception;
/**
* Risorsa di base per la gestione delle operazioni standard di comunicazione con l'applicazione.
* Implementa le operazioni di *retrieve* in tre fasi, e rende disponibile l'espansione per operazioni di *create*, *update* e *delete*.
*/
abstract class AppResource extends Resource implements RetrieveInterface, CreateInterface, UpdateInterface, DeleteInterface
{
/**
* Gestisce le operazioni di *retrieve* in tre fasi:
* - Cleanup (elenco di record da rimuovere nell'applicazione);
* - Record modificati (elenco di record che sono stati aggiornati nel gestionale);
* - Dettagli del record.
*
* @param $request
*
* @return array[]
*/
public function retrieve($request)
{
$id = $request['id'];
$last_sync_at = $request['last_sync_at'] == 'undefined' ? null : $request['last_sync_at'];
$last_sync_at = $request['last_sync_at'] && $request['last_sync_at'] != 'undefined' ? new Carbon($request['last_sync_at']) : null;
// Gestione delle operazioni di cleanup
if (strpos($request['resource'], 'cleanup') !== false) {
$list = $this->getCleanupData();
$list = $this->getCleanupData($last_sync_at);
$list = $this->forceToString($list);
return [
@ -30,7 +43,7 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
// Gestione dell'enumerazione dei record modificati
if (!isset($id)) {
$list = $this->getData($last_sync_at);
$list = $this->getModifiedRecords($last_sync_at);
$list = $this->forceToString($list);
return [
@ -47,6 +60,13 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
];
}
/**
* Gestisce la richiesta di creazione di un record, delegando le operazioni relative a *createRecord* e forzando i risultati in formato stringa.
*
* @param $request
*
* @return array
*/
public function create($request)
{
$data = $request['data'];
@ -59,6 +79,13 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
];
}
/**
* Gestisce la richiesta di modifica di un record, delegando le operazioni relative a *updateRecord* e forzando i risultati in formato stringa.
*
* @param $request
*
* @return array
*/
public function update($request)
{
$data = $request['data'];
@ -70,12 +97,24 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
];
}
/**
* Gestisce la richiesta di eliminazione di un record, delegando le operazioni relative a *deleteRecord*.
*
* @param $request
*/
public function delete($request)
{
$id = $request['id'];
$this->deleteRecord($id);
}
/**
* Converte i valori numerici in stringhe.
*
* @param $list
*
* @return array
*/
protected function forceToString($list)
{
$result = [];
@ -94,28 +133,43 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
}
/**
* @param string $table_name Tabella da analizzare
* @param string $column Colonna di tipo AUTO_INCREMENT della tabella
* Restituisce gli ID dei potenziali record mancanti, sulla base della colonna indicata e a partire da *last_sync_at*.
*
* @throws \Exception
* @param string $table_name Tabella da analizzare
* @param string $column Colonna di tipo AUTO_INCREMENT della tabella
* @param null $last_sync_at
*
* @throws Exception
*
* @return array
*/
protected function getMissingIDs($table_name, $column)
protected function getMissingIDs($table_name, $column, $last_sync_at = null)
{
$database = database();
$db_name = $database->getDatabaseName();
// Ottiene il valore successivo della colonna di tipo AUTO_INCREMENT
$auto_inc = $database->fetchOne('SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '.prepare($table_name).' AND TABLE_SCHEMA = '.prepare($db_name))['AUTO_INCREMENT'];
$next_autoincrement = $database->fetchOne('SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '.prepare($table_name).' AND TABLE_SCHEMA = '.prepare($db_name))['AUTO_INCREMENT'];
// Ottiene l'ultimo record con data precedente a quella impostata
$last_id = null;
if ($last_sync_at) {
$last_record = $database->fetchOne('SELECT '.$column.' AS id FROM '.$table_name.' WHERE created_at <= '.prepare($last_sync_at).' ORDER BY '.$column.' DESC');
$last_id = $last_record['id'];
}
// Ottiene i vuoti all'interno della sequenza AUTO_INCREMENT
$steps = $database->fetchArray('SELECT (t1.'.$column.' + 1) as start, (SELECT MIN(t3.'.$column.') - 1 FROM '.$table_name.' t3 WHERE t3.'.$column.' > t1.'.$column.') as end FROM '.$table_name.' t1 WHERE NOT EXISTS (SELECT t2.'.$column.' FROM '.$table_name.' t2 WHERE t2.'.$column.' = t1.'.$column.' + 1) ORDER BY start');
$query = 'SELECT (t1.'.$column.' + 1) AS start, (SELECT MIN(t3.'.$column.') - 1 FROM '.$table_name.' t3 WHERE t3.'.$column.' > t1.'.$column.') AS end FROM '.$table_name.' t1 WHERE NOT EXISTS (SELECT t2.'.$column.' FROM '.$table_name.' t2 WHERE t2.'.$column.' = t1.'.$column.' + 1)';
if ($last_id) {
$query .= ' AND t1.'.$column.' >= '.prepare($last_id);
}
$query .= ' ORDER BY start';
$steps = $database->fetchArray($query);
$total = [];
foreach ($steps as $step) {
if ($step['end'] == null) {
$step['end'] = $auto_inc - 1;
$step['end'] = $next_autoincrement - 1;
}
if ($step['end'] >= $step['start']) {
@ -127,19 +181,26 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
}
/**
* @param string $table_name Tabella da analizzare
* @param string $column Colonna di tipo AUTO_INCREMENT della tabella
* Restituisce gli ID dei record con campo *deleted_at* maggiore di *last_sync_at*.
*
* @throws \Exception
* @param string $table_name Tabella da analizzare
* @param string $column Colonna di tipo AUTO_INCREMENT della tabella
* @param null $last_sync_at
*
* @throws Exception
*
* @return array
*/
protected function getDeleted($table_name, $column)
protected function getDeleted($table_name, $column, $last_sync_at = null)
{
$database = database();
$query = 'SELECT '.$column.' AS id FROM '.$table_name.' WHERE deleted_at';
if ($last_sync_at) {
$query .= ' > '.prepare($last_sync_at);
} else {
$query .= ' IS NOT NULL';
}
$query = 'SELECT '.$column.' AS id FROM '.$table_name.' WHERE deleted_at IS NOT NULL';
$results = $database->fetchArray($query);
$results = database()->fetchArray($query);
return array_column($results, 'id');
}
@ -147,9 +208,11 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
/**
* Restituisce un array contenente gli ID dei record eliminati.
*
* @param $last_sync
*
* @return array
*/
abstract protected function getCleanupData();
abstract protected function getCleanupData($last_sync);
/**
* Restituisce un array contenente gli ID dei record modificati e da sincronizzare.
@ -158,7 +221,7 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
*
* @return array
*/
abstract protected function getData($last_sync_at);
abstract protected function getModifiedRecords($last_sync_at);
/**
* Restituisce i dettagli relativi a un singolo record identificato tramite ID.

View File

@ -3,23 +3,21 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
class AliquoteIva extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getDeleted('co_iva', 'id');
return $this->getDeleted('co_iva', 'id', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT co_iva.id FROM co_iva WHERE deleted_at IS NULL';
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND co_iva.updated_at > '.prepare($last_sync);
$query .= ' AND co_iva.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -3,23 +3,21 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
class Articoli extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getDeleted('mg_articoli', 'id');
return $this->getDeleted('mg_articoli', 'id', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT mg_articoli.id FROM mg_articoli WHERE deleted_at IS NULL';
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND mg_articoli.updated_at > '.prepare($last_sync);
$query .= ' AND mg_articoli.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -3,18 +3,17 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Modules\Anagrafiche\Anagrafica;
class Clienti extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getDeleted('an_anagrafiche', 'idanagrafica');
return $this->getDeleted('an_anagrafiche', 'idanagrafica', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$statement = Anagrafica::select('idanagrafica')
->whereHas('tipi', function (Builder $query) {
@ -23,8 +22,7 @@ class Clienti extends AppResource
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$statement = $statement->where('updated_at', '>', $last_sync);
$statement = $statement->where('updated_at', '>', $last_sync_at);
}
$results = $statement->get()

View File

@ -4,11 +4,10 @@ namespace API\App\v1;
use API\App\AppResource;
use API\Interfaces\RetrieveInterface;
use Carbon\Carbon;
class Contratti extends AppResource implements RetrieveInterface
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
$query = 'SELECT DISTINCT(co_contratti.id) AS id FROM co_contratti
INNER JOIN co_staticontratti ON co_staticontratti.id = co_contratti.idstato
@ -16,14 +15,14 @@ class Contratti extends AppResource implements RetrieveInterface
$records = database()->fetchArray($query);
$da_stati = array_column($records, 'id');
$mancanti = $this->getMissingIDs('co_contratti', 'id');
$mancanti = $this->getMissingIDs('co_contratti', 'id', $last_sync_at);
$results = array_unique(array_merge($da_stati, $mancanti));
return $results;
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = "SELECT DISTINCT(co_contratti.id) AS id FROM co_contratti
INNER JOIN co_staticontratti ON co_staticontratti.id = co_contratti.idstato
@ -34,8 +33,7 @@ class Contratti extends AppResource implements RetrieveInterface
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND co_contratti.updated_at > '.prepare($last_sync);
$query .= ' AND co_contratti.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -3,18 +3,17 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Modules\Impianti\Impianto;
class Impianti extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getMissingIDs('my_impianti', 'id');
return $this->getMissingIDs('my_impianti', 'id', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$statement = Impianto::select('id')
->whereHas('anagrafica.tipi', function (Builder $query) {
@ -23,8 +22,7 @@ class Impianti extends AppResource
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$statement = $statement->where('updated_at', '>', $last_sync);
$statement = $statement->where('updated_at', '>', $last_sync_at);
}
$results = $statement->get()

View File

@ -3,23 +3,21 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
class Impostazioni extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return [];
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT zz_settings.id FROM zz_settings WHERE sezione = "Applicazione"';
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND zz_settings.updated_at > '.prepare($last_sync);
$query .= ' AND zz_settings.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -13,7 +13,7 @@ use Modules\TipiIntervento\Tipo as TipoSessione;
class Interventi extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
// Periodo per selezionare interventi
$today = new Carbon();
@ -46,7 +46,7 @@ class Interventi extends AppResource
return array_column($records, 'id');
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
// Periodo per selezionare interventi
$today = new Carbon();
@ -72,8 +72,7 @@ class Interventi extends AppResource
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND in_interventi.updated_at > '.prepare($last_sync);
$query .= ' AND in_interventi.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query, [
':period_start' => $start,

View File

@ -4,26 +4,28 @@ namespace API\App\v1;
use API\App\AppResource;
use API\Interfaces\RetrieveInterface;
use Carbon\Carbon;
class Preventivi extends AppResource implements RetrieveInterface
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
$query = 'SELECT DISTINCT(co_preventivi.id) AS id FROM co_preventivi
INNER JOIN co_statipreventivi ON co_statipreventivi.id = co_preventivi.idstato
WHERE co_statipreventivi.is_pianificabile = 0';
if ($last_sync_at) {
$query .= ' AND (co_preventivi.updated_at > '.prepare($last_sync_at).' OR co_statipreventivi.updated_at > '.prepare($last_sync_at).')';
}
$records = database()->fetchArray($query);
$da_stati = array_column($records, 'id');
$mancanti = $this->getMissingIDs('co_preventivi', 'id');
$mancanti = $this->getMissingIDs('co_preventivi', 'id', $last_sync_at);
$results = array_unique(array_merge($da_stati, $mancanti));
return $results;
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = "SELECT DISTINCT(co_preventivi.id) AS id FROM co_preventivi
INNER JOIN co_statipreventivi ON co_statipreventivi.id = co_preventivi.idstato
@ -34,8 +36,7 @@ class Preventivi extends AppResource implements RetrieveInterface
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND co_preventivi.updated_at > '.prepare($last_sync);
$query .= ' AND co_preventivi.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -4,16 +4,15 @@ namespace API\App\v1;
use API\App\AppResource;
use API\Interfaces\RetrieveInterface;
use Carbon\Carbon;
class Referenti extends AppResource implements RetrieveInterface
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getMissingIDs('an_referenti', 'id');
return $this->getMissingIDs('an_referenti', 'id', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = "SELECT DISTINCT(an_referenti.id) AS id FROM an_referenti
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = an_referenti.idanagrafica
@ -23,8 +22,7 @@ class Referenti extends AppResource implements RetrieveInterface
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND an_referenti.updated_at > '.prepare($last_sync);
$query .= ' AND an_referenti.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -13,9 +13,9 @@ use Modules\Interventi\Components\Sconto;
use Modules\Interventi\Intervento;
use UnexpectedValueException;
class Righe extends AppResource
class RigheInterventi extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
// Periodo per selezionare interventi
$today = new Carbon();
@ -43,14 +43,14 @@ class Righe extends AppResource
]);
$da_interventi = array_column($records, 'id');
$mancanti = $this->getMissingIDs('in_righe_interventi', 'id');
$mancanti = $this->getMissingIDs('in_righe_interventi', 'id', $last_sync_at);
$results = array_unique(array_merge($da_interventi, $mancanti));
return $results;
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
// Periodo per selezionare interventi
$today = new Carbon();
@ -74,8 +74,7 @@ class Righe extends AppResource
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND in_righe_interventi.updated_at > '.prepare($last_sync);
$query .= ' AND in_righe_interventi.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query, [
':period_start' => $start,

View File

@ -3,16 +3,15 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
class Sedi extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getMissingIDs('an_sedi', 'id');
return $this->getMissingIDs('an_sedi', 'id', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = "SELECT DISTINCT(an_sedi.id) AS id FROM an_sedi
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = an_sedi.idanagrafica
@ -22,8 +21,7 @@ class Sedi extends AppResource
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND an_sedi.updated_at > '.prepare($last_sync);
$query .= ' AND an_sedi.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -9,9 +9,9 @@ use Modules\Anagrafiche\Anagrafica;
use Modules\Interventi\Components\Sessione;
use Modules\Interventi\Intervento;
class Sessioni extends AppResource
class SessioniInterventi extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
// Periodo per selezionare interventi
$today = new Carbon();
@ -33,14 +33,14 @@ class Sessioni extends AppResource
':id_tecnico' => $id_tecnico,
]);
$da_interventi = array_column($records, 'id');
$mancanti = $this->getMissingIDs('in_interventi_tecnici', 'id');
$mancanti = $this->getMissingIDs('in_interventi_tecnici', 'id', $last_sync_at);
$results = array_unique(array_merge($da_interventi, $mancanti));
return $results;
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
// Periodo per selezionare interventi
$today = new Carbon();
@ -59,8 +59,7 @@ class Sessioni extends AppResource
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' AND in_interventi_tecnici.updated_at > '.prepare($last_sync);
$query .= ' AND in_interventi_tecnici.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query, [
':period_start' => $start,

View File

@ -3,23 +3,21 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
class StatiIntervento extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getDeleted('in_statiintervento', 'idstatointervento');
return $this->getDeleted('in_statiintervento', 'idstatointervento', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT in_statiintervento.idstatointervento AS id FROM in_statiintervento';
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' WHERE in_statiintervento.updated_at > '.prepare($last_sync);
$query .= ' WHERE in_statiintervento.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);

View File

@ -0,0 +1,51 @@
<?php
namespace API\App\v1;
use API\App\AppResource;
class TariffeContratti extends AppResource
{
protected function getCleanupData($last_sync_at)
{
// Le associazioni Contratti - Tariffe per tipi non sono cancellabili a database
// Per le ultime versioni, sono anzi sempre presenti!
return [];
}
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT CONCAT(idtipointervento, "-", idcontratto) AS id FROM co_contratti_tipiintervento';
// Filtro per data
if ($last_sync_at) {
$query .= ' WHERE updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);
return array_column($records, 'id');
}
protected function retrieveRecord($id)
{
$pieces = explode('-', $id);
$id_tipo_intervento = $pieces[0];
$id_contratto = $pieces[1];
// Gestione della visualizzazione dei dettagli del record
$query = 'SELECT CONCAT(idtipointervento, "-", idcontratto) AS id,
NULL AS id_tecnico,
idtipointervento AS id_tipo_intervento,
idcontratto AS id_contratto,
costo_ore AS prezzo_orario,
costo_km AS prezzo_chilometrico,
costo_dirittochiamata AS prezzo_diritto_chiamata
FROM co_contratti_tipiintervento
WHERE co_contratti_tipiintervento.idtipointervento = '.prepare($id_tipo_intervento).' AND co_contratti_tipiintervento.idcontratto = '.prepare($id_contratto);
$record = database()->fetchOne($query);
return $record;
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace API\App\v1;
use API\App\AppResource;
use Illuminate\Database\Eloquent\Builder;
use Modules\Anagrafiche\Anagrafica;
class TariffeTecnici extends AppResource
{
protected function getCleanupData($last_sync_at)
{
return $this->getMissingIDs('in_tariffe', 'id', $last_sync_at);
}
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT id FROM in_tariffe';
// Filtro per data
if ($last_sync_at) {
$query .= ' WHERE updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);
return array_column($records, 'id');
}
protected function retrieveRecord($id)
{
// Gestione della visualizzazione dei dettagli del record
$query = 'SELECT id,
idtecnico AS id_tecnico,
idtipointervento AS id_tipo_intervento,
NULL AS id_contratto,
costo_ore AS prezzo_orario,
costo_km AS prezzo_chilometrico,
costo_dirittochiamata AS prezzo_diritto_chiamata
FROM in_tariffe
WHERE id = '.prepare($id);
$record = database()->fetchOne($query);
return $record;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace API\App\v1;
use API\App\AppResource;
use Illuminate\Database\Eloquent\Builder;
use Modules\Anagrafiche\Anagrafica;
class Tecnici extends AppResource
{
protected function getCleanupData($last_sync_at)
{
return $this->getDeleted('an_anagrafiche', 'idanagrafica', $last_sync_at);
}
protected function getModifiedRecords($last_sync_at)
{
$statement = Anagrafica::select('idanagrafica')
->whereHas('tipi', function (Builder $query) {
$query->where('descrizione', '=', 'Tecnico');
});
// Filtro per data
if ($last_sync_at) {
$statement = $statement->where('updated_at', '>', $last_sync_at);
}
$results = $statement->get()
->pluck('idanagrafica');
return $results;
}
protected function retrieveRecord($id)
{
// Gestione della visualizzazione dei dettagli del record
$query = 'SELECT an_anagrafiche.idanagrafica AS id,
an_anagrafiche.ragione_sociale
FROM an_anagrafiche
WHERE an_anagrafiche.idanagrafica = '.prepare($id);
$record = database()->fetchOne($query);
return $record;
}
}

View File

@ -3,23 +3,21 @@
namespace API\App\v1;
use API\App\AppResource;
use Carbon\Carbon;
class TipiIntervento extends AppResource
{
protected function getCleanupData()
protected function getCleanupData($last_sync_at)
{
return $this->getMissingIDs('in_tipiintervento', 'idtipointervento');
return $this->getMissingIDs('in_tipiintervento', 'idtipointervento', $last_sync_at);
}
protected function getData($last_sync_at)
protected function getModifiedRecords($last_sync_at)
{
$query = 'SELECT in_tipiintervento.idtipointervento AS id FROM in_tipiintervento';
// Filtro per data
if ($last_sync_at) {
$last_sync = new Carbon($last_sync_at);
$query .= ' WHERE in_tipiintervento.updated_at > '.prepare($last_sync);
$query .= ' WHERE in_tipiintervento.updated_at > '.prepare($last_sync_at);
}
$records = database()->fetchArray($query);
@ -31,7 +29,10 @@ class TipiIntervento extends AppResource
{
// Gestione della visualizzazione dei dettagli del record
$query = 'SELECT in_tipiintervento.idtipointervento AS id,
in_tipiintervento.descrizione
in_tipiintervento.descrizione,
costo_orario AS prezzo_orario,
costo_km AS prezzo_chilometrico,
costo_diritto_chiamata AS prezzo_diritto_chiamata
FROM in_tipiintervento
WHERE in_tipiintervento.idtipointervento = '.prepare($id);

View File

@ -166,62 +166,97 @@ UPDATE `co_righe_promemoria` INNER JOIN `co_iva` ON `co_iva`.`id` = `co_righe_pr
UPDATE `zz_api_resources` SET `class` = 'API\\Common\\Stampa' WHERE `class` = 'Api\\Common\\Stampa';
UPDATE `zz_api_resources` SET `class` = 'API\\Common\\Allegato' WHERE `class` = 'Api\\Common\\Allegato';
-- Aggiunta risorse dedicate all'applicazione
-- Aggiunta risorse API dedicate all'applicazione
DELETE FROM `zz_api_resources` WHERE `version` = 'app-v1';
INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `enabled`) VALUES
-- Login
(NULL, 'app-v1', 'create', 'login', 'API\\App\\v1\\Login', '1'),
-- Clienti
(NULL, 'app-v1', 'retrieve', 'clienti', 'API\\App\\v1\\Clienti', '1'),
(NULL, 'app-v1', 'retrieve', 'clienti-cleanup', 'API\\App\\v1\\Clienti', '1'),
(NULL, 'app-v1', 'retrieve', 'cliente', 'API\\App\\v1\\Clienti', '1'),
-- Tecnici
(NULL, 'app-v1', 'retrieve', 'tecnici', 'API\\App\\v1\\Tecnici', '1'),
(NULL, 'app-v1', 'retrieve', 'tecnici-cleanup', 'API\\App\\v1\\Tecnici', '1'),
(NULL, 'app-v1', 'retrieve', 'tecnico', 'API\\App\\v1\\Tecnici', '1'),
-- Sedi
(NULL, 'app-v1', 'retrieve', 'sedi', 'API\\App\\v1\\Sedi', '1'),
(NULL, 'app-v1', 'retrieve', 'sedi-cleanup', 'API\\App\\v1\\Sedi', '1'),
(NULL, 'app-v1', 'retrieve', 'sede', 'API\\App\\v1\\Sedi', '1'),
-- Referenti
(NULL, 'app-v1', 'retrieve', 'referenti', 'API\\App\\v1\\Referenti', '1'),
(NULL, 'app-v1', 'retrieve', 'referenti-cleanup', 'API\\App\\v1\\Referenti', '1'),
(NULL, 'app-v1', 'retrieve', 'referente', 'API\\App\\v1\\Referenti', '1'),
-- Impianti
(NULL, 'app-v1', 'retrieve', 'impianti', 'API\\App\\v1\\Impianti', '1'),
(NULL, 'app-v1', 'retrieve', 'impianti-cleanup', 'API\\App\\v1\\Impianti', '1'),
(NULL, 'app-v1', 'retrieve', 'impianto', 'API\\App\\v1\\Impianti', '1'),
-- Stati degli interventi
(NULL, 'app-v1', 'retrieve', 'stati-intervento', 'API\\App\\v1\\StatiIntervento', '1'),
(NULL, 'app-v1', 'retrieve', 'stati-intervento-cleanup', 'API\\App\\v1\\StatiIntervento', '1'),
(NULL, 'app-v1', 'retrieve', 'stato-intervento', 'API\\App\\v1\\StatiIntervento', '1'),
-- Tipi degli interventi
(NULL, 'app-v1', 'retrieve', 'tipi-intervento', 'API\\App\\v1\\TipiIntervento', '1'),
(NULL, 'app-v1', 'retrieve', 'tipi-intervento-cleanup', 'API\\App\\v1\\TipiIntervento', '1'),
(NULL, 'app-v1', 'retrieve', 'tipo-intervento', 'API\\App\\v1\\TipiIntervento', '1'),
-- Articoli
(NULL, 'app-v1', 'retrieve', 'articoli', 'API\\App\\v1\\Articoli', '1'),
(NULL, 'app-v1', 'retrieve', 'articoli-cleanup', 'API\\App\\v1\\Articoli', '1'),
(NULL, 'app-v1', 'retrieve', 'articolo', 'API\\App\\v1\\Articoli', '1'),
-- Interventi
(NULL, 'app-v1', 'retrieve', 'interventi', 'API\\App\\v1\\Interventi', '1'),
(NULL, 'app-v1', 'retrieve', 'interventi-cleanup', 'API\\App\\v1\\Interventi', '1'),
(NULL, 'app-v1', 'retrieve', 'intervento', 'API\\App\\v1\\Interventi', '1'),
(NULL, 'app-v1', 'retrieve', 'sessioni', 'API\\App\\v1\\Sessioni', '1'),
(NULL, 'app-v1', 'retrieve', 'sessioni-cleanup', 'API\\App\\v1\\Sessioni', '1'),
(NULL, 'app-v1', 'retrieve', 'sessione', 'API\\App\\v1\\Sessioni', '1'),
(NULL, 'app-v1', 'retrieve', 'righe-intervento', 'API\\App\\v1\\Righe', '1'),
(NULL, 'app-v1', 'retrieve', 'righe-intervento-cleanup', 'API\\App\\v1\\Righe', '1'),
(NULL, 'app-v1', 'retrieve', 'riga-intervento', 'API\\App\\v1\\Righe', '1'),
(NULL, 'app-v1', 'retrieve', 'aliquote-iva', 'API\\App\\v1\\AliquoteIva', '1'),
(NULL, 'app-v1', 'retrieve', 'aliquote-iva-cleanup', 'API\\App\\v1\\AliquoteIva', '1'),
(NULL, 'app-v1', 'retrieve', 'aliquota-iva', 'API\\App\\v1\\AliquoteIva', '1'),
(NULL, 'app-v1', 'retrieve', 'impostazioni', 'API\\App\\v1\\Impostazioni', '1'),
(NULL, 'app-v1', 'retrieve', 'impostazioni-cleanup', 'API\\App\\v1\\Impostazioni', '1'),
(NULL, 'app-v1', 'retrieve', 'impostazione', 'API\\App\\v1\\Impostazioni', '1'),
(NULL, 'app-v1', 'retrieve', 'contratti', 'API\\App\\v1\\Contratti', '1'),
(NULL, 'app-v1', 'retrieve', 'contratti-cleanup', 'API\\App\\v1\\Contratti', '1'),
(NULL, 'app-v1', 'retrieve', 'contratto', 'API\\App\\v1\\Contratti', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivi', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivi-cleanup', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivo', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'create', 'intervento', 'API\\App\\v1\\Interventi', '1'),
(NULL, 'app-v1', 'update', 'intervento', 'API\\App\\v1\\Interventi', '1'),
(NULL, 'app-v1', 'delete', 'intervento', 'API\\App\\v1\\Interventi', '1'),
(NULL, 'app-v1', 'delete', 'sessione', 'API\\App\\v1\\Sessioni', '1'),
(NULL, 'app-v1', 'create', 'sessione', 'API\\App\\v1\\Sessioni', '1'),
(NULL, 'app-v1', 'update', 'sessione', 'API\\App\\v1\\Sessioni', '1'),
(NULL, 'app-v1', 'create', 'riga-intervento', 'API\\App\\v1\\Righe', '1'),
(NULL, 'app-v1', 'update', 'riga-intervento', 'API\\App\\v1\\Righe', '1'),
(NULL, 'app-v1', 'delete', 'riga-intervento', 'API\\App\\v1\\Righe', '1'),
-- Sessioni degli interventi
(NULL, 'app-v1', 'retrieve', 'sessioni', 'API\\App\\v1\\SessioniInterventi', '1'),
(NULL, 'app-v1', 'retrieve', 'sessioni-cleanup', 'API\\App\\v1\\SessioniInterventi', '1'),
(NULL, 'app-v1', 'retrieve', 'sessione', 'API\\App\\v1\\SessioniInterventi', '1'),
(NULL, 'app-v1', 'delete', 'sessione', 'API\\App\\v1\\SessioniInterventi', '1'),
(NULL, 'app-v1', 'create', 'sessione', 'API\\App\\v1\\SessioniInterventi', '1'),
(NULL, 'app-v1', 'update', 'sessione', 'API\\App\\v1\\SessioniInterventi', '1'),
-- Righe degli interventi
(NULL, 'app-v1', 'retrieve', 'righe-interventi', 'API\\App\\v1\\RigheInterventi', '1'),
(NULL, 'app-v1', 'retrieve', 'righe-interventi-cleanup', 'API\\App\\v1\\RigheInterventi', '1'),
(NULL, 'app-v1', 'retrieve', 'riga-intervento', 'API\\App\\v1\\RigheInterventi', '1'),
(NULL, 'app-v1', 'create', 'riga-intervento', 'API\\App\\v1\\RigheInterventi', '1'),
(NULL, 'app-v1', 'update', 'riga-intervento', 'API\\App\\v1\\RigheInterventi', '1'),
(NULL, 'app-v1', 'delete', 'riga-intervento', 'API\\App\\v1\\RigheInterventi', '1'),
-- Aliquote IVA
(NULL, 'app-v1', 'retrieve', 'aliquote-iva', 'API\\App\\v1\\AliquoteIva', '1'),
(NULL, 'app-v1', 'retrieve', 'aliquote-iva-cleanup', 'API\\App\\v1\\AliquoteIva', '1'),
(NULL, 'app-v1', 'retrieve', 'aliquota-iva', 'API\\App\\v1\\AliquoteIva', '1'),
-- Impostazioni (non modificabili)
(NULL, 'app-v1', 'retrieve', 'impostazioni', 'API\\App\\v1\\Impostazioni', '1'),
(NULL, 'app-v1', 'retrieve', 'impostazioni-cleanup', 'API\\App\\v1\\Impostazioni', '1'),
(NULL, 'app-v1', 'retrieve', 'impostazione', 'API\\App\\v1\\Impostazioni', '1'),
-- Contratti
(NULL, 'app-v1', 'retrieve', 'contratti', 'API\\App\\v1\\Contratti', '1'),
(NULL, 'app-v1', 'retrieve', 'contratti-cleanup', 'API\\App\\v1\\Contratti', '1'),
(NULL, 'app-v1', 'retrieve', 'contratto', 'API\\App\\v1\\Contratti', '1'),
-- Preventivi
(NULL, 'app-v1', 'retrieve', 'preventivi', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivi-cleanup', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivo', 'API\\App\\v1\\Preventivi', '1'),
-- Sedi
(NULL, 'app-v1', 'retrieve', 'preventivi', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivi-cleanup', 'API\\App\\v1\\Preventivi', '1'),
(NULL, 'app-v1', 'retrieve', 'preventivo', 'API\\App\\v1\\Preventivi', '1'),
-- Tariffe dei tecnici
(NULL, 'app-v1', 'retrieve', 'tariffe-tecnici', 'API\\App\\v1\\TariffeTecnici', '1'),
(NULL, 'app-v1', 'retrieve', 'tariffe-tecnici-cleanup', 'API\\App\\v1\\TariffeTecnici', '1'),
(NULL, 'app-v1', 'retrieve', 'tariffa-tecnico', 'API\\App\\v1\\TariffeTecnici', '1'),
-- Tariffe relative ai contratti
(NULL, 'app-v1', 'retrieve', 'tariffe-contratti', 'API\\App\\v1\\TariffeContratti', '1'),
(NULL, 'app-v1', 'retrieve', 'tariffe-contratti-cleanup', 'API\\App\\v1\\TariffeContratti', '1'),
(NULL, 'app-v1', 'retrieve', 'tariffa-contratto', 'API\\App\\v1\\TariffeContratti', '1'),
-- Allegati
(NULL, 'app-v1', 'retrieve', 'allegati', 'API\\App\\v1\\Allegati', '1'),
(NULL, 'app-v1', 'retrieve', 'allegati-cleanup', 'API\\App\\v1\\Allegati', '1'),
(NULL, 'app-v1', 'retrieve', 'allegato', 'API\\App\\v1\\Allegati', '1'),
-- Email di rapportino intervento
(NULL, 'app-v1', 'retrieve', 'email-rapportino', 'API\\App\\v1\\RapportinoIntervento', '1'),
(NULL, 'app-v1', 'create', 'email-rapportino', 'API\\App\\v1\\RapportinoIntervento', '1');