mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Aggiunto supporto agli Allegati degli Interventi
This commit is contained in:
parent
cd505d35f6
commit
992ceb656c
@ -33,7 +33,10 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
|
||||
|
||||
// Gestione delle operazioni di cleanup
|
||||
if (strpos($request['resource'], 'cleanup') !== false) {
|
||||
$list = $this->getCleanupData($last_sync_at);
|
||||
$list = [];
|
||||
if (!empty($last_sync_at)) {
|
||||
$list = $this->getCleanupData($last_sync_at);
|
||||
}
|
||||
$list = $this->forceToString($list);
|
||||
|
||||
return [
|
||||
@ -108,6 +111,68 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
|
||||
$this->deleteRecord($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce un array contenente gli ID dei record eliminati.
|
||||
*
|
||||
* @param $last_sync
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getCleanupData($last_sync);
|
||||
|
||||
/**
|
||||
* Restituisce un array contenente gli ID dei record modificati e da sincronizzare.
|
||||
*
|
||||
* @param string $last_sync_at
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getModifiedRecords($last_sync_at);
|
||||
|
||||
/**
|
||||
* Restituisce i dettagli relativi a un singolo record identificato tramite ID.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function retrieveRecord($id);
|
||||
|
||||
/**
|
||||
* Crea un nuovo record relativo alla risorsa, restituendo l'ID relativo ed eventuali campi da aggiornare in remoto.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function createRecord($data)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna un record relativo alla risorsa, restituendo eventuali campi da aggiornare in remoto.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function updateRecord($data)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina un record relativo alla risorsa.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteRecord($id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Converte i valori numerici in stringhe.
|
||||
*
|
||||
@ -204,66 +269,4 @@ abstract class AppResource extends Resource implements RetrieveInterface, Create
|
||||
|
||||
return array_column($results, 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce un array contenente gli ID dei record eliminati.
|
||||
*
|
||||
* @param $last_sync
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getCleanupData($last_sync);
|
||||
|
||||
/**
|
||||
* Restituisce un array contenente gli ID dei record modificati e da sincronizzare.
|
||||
*
|
||||
* @param string $last_sync_at
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getModifiedRecords($last_sync_at);
|
||||
|
||||
/**
|
||||
* Restituisce i dettagli relativi a un singolo record identificato tramite ID.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function retrieveRecord($id);
|
||||
|
||||
/**
|
||||
* Crea un nuovo record relativo alla risorsa, restituendo l'ID relativo ed eventuali campi da aggiornare in remoto.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function createRecord($data)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna un record relativo alla risorsa, restituendo eventuali campi da aggiornare in remoto.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function updateRecord($data)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina un record relativo alla risorsa.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteRecord($id)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ use API\App\AppResource;
|
||||
|
||||
class AliquoteIva extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('co_iva', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT co_iva.id FROM co_iva WHERE deleted_at IS NULL';
|
||||
|
||||
@ -25,7 +25,7 @@ class AliquoteIva extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT co_iva.id,
|
||||
|
98
src/API/App/v1/AllegatiInterventi.php
Normal file
98
src/API/App/v1/AllegatiInterventi.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use Models\Upload;
|
||||
use Modules;
|
||||
|
||||
class AllegatiInterventi extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// Elenco di interventi di interesse
|
||||
$risorsa_interventi = $this->getRisorsaInterventi();
|
||||
$interventi = $risorsa_interventi->getCleanupData($last_sync_at);
|
||||
|
||||
// Elenco allegati degli interventi da rimuovere
|
||||
$da_interventi = [];
|
||||
if (!empty($interventi)) {
|
||||
$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).')';
|
||||
$allegati_interventi = database()->fetchArray($query);
|
||||
$da_interventi = array_column($allegati_interventi, 'id');
|
||||
}
|
||||
|
||||
// Allegati rimossi manualmente
|
||||
$mancanti = $this->getMissingIDs('zz_files', 'id', $last_sync_at);
|
||||
$results = array_unique(array_merge($da_interventi, $mancanti));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// Elenco di interventi di interesse
|
||||
$risorsa_interventi = $this->getRisorsaInterventi();
|
||||
$interventi = $risorsa_interventi->getModifiedRecords($last_sync_at);
|
||||
if (empty($interventi)) {
|
||||
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).')';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND zz_files.updated_at > '.prepare($last_sync_at);
|
||||
}
|
||||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$upload = Upload::find($id);
|
||||
|
||||
$record = [
|
||||
'id' => $upload->id,
|
||||
'tipo' => $upload->extension,
|
||||
'nome' => $upload->name,
|
||||
'categoria' => $upload->category,
|
||||
'size' => $upload->size,
|
||||
'id_intervento' => $upload->id_record,
|
||||
];
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function createRecord($data)
|
||||
{
|
||||
$module = Modules::get('Interventi');
|
||||
|
||||
// Creazione del file temporaneo
|
||||
$file = tmpfile();
|
||||
$path = stream_get_meta_data($file)['uri'];
|
||||
fwrite($file, $data['contenuto']);
|
||||
|
||||
// Salvataggio del file come allegato
|
||||
$upload = Upload::build($path, [
|
||||
'id_module' => $module['id'],
|
||||
'id_record' => $data['id_intervento'],
|
||||
], $data['nome'], $data['categoria']);
|
||||
|
||||
// Chiusura e rimozione del file temporaneo
|
||||
fclose($file);
|
||||
|
||||
return[
|
||||
'id' => $upload->id,
|
||||
'filename' => $upload->filename,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRisorsaInterventi()
|
||||
{
|
||||
return new Interventi();
|
||||
}
|
||||
}
|
@ -6,12 +6,12 @@ use API\App\AppResource;
|
||||
|
||||
class Articoli extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('mg_articoli', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT mg_articoli.id FROM mg_articoli WHERE deleted_at IS NULL';
|
||||
|
||||
@ -25,7 +25,7 @@ class Articoli extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT mg_articoli.id AS id,
|
||||
|
@ -8,12 +8,12 @@ use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
class Clienti extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('an_anagrafiche', 'idanagrafica', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Anagrafica::select('idanagrafica')
|
||||
->whereHas('tipi', function (Builder $query) {
|
||||
@ -31,7 +31,7 @@ class Clienti extends AppResource
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT an_anagrafiche.idanagrafica AS id,
|
||||
|
@ -7,11 +7,14 @@ use API\Interfaces\RetrieveInterface;
|
||||
|
||||
class Contratti extends AppResource implements RetrieveInterface
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public 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
|
||||
WHERE co_staticontratti.is_pianificabile = 0';
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND (co_contratti.updated_at > '.prepare($last_sync_at).' OR co_staticontratti.updated_at > '.prepare($last_sync_at).')';
|
||||
}
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
$da_stati = array_column($records, 'id');
|
||||
@ -22,7 +25,7 @@ class Contratti extends AppResource implements RetrieveInterface
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public 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
|
||||
@ -41,7 +44,7 @@ class Contratti extends AppResource implements RetrieveInterface
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT co_contratti.id,
|
||||
|
@ -8,12 +8,12 @@ use Modules\Impianti\Impianto;
|
||||
|
||||
class Impianti extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('my_impianti', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Impianto::select('id')
|
||||
->whereHas('anagrafica.tipi', function (Builder $query) {
|
||||
@ -31,7 +31,7 @@ class Impianti extends AppResource
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT my_impianti.id,
|
||||
|
@ -6,12 +6,12 @@ use API\App\AppResource;
|
||||
|
||||
class Impostazioni extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT zz_settings.id FROM zz_settings WHERE sezione = "Applicazione"';
|
||||
|
||||
@ -25,7 +25,7 @@ class Impostazioni extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT id AS id,
|
||||
|
@ -13,7 +13,7 @@ use Modules\TipiIntervento\Tipo as TipoSessione;
|
||||
|
||||
class Interventi extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
@ -33,7 +33,7 @@ class Interventi extends AppResource
|
||||
AND in_interventi_tecnici.orario_fine BETWEEN :period_start AND :period_end
|
||||
AND in_interventi_tecnici.idtecnico = :id_tecnico
|
||||
)
|
||||
AND in_interventi.id NOT IN (
|
||||
AND in_interventi.id IN (
|
||||
SELECT idintervento FROM in_interventi_tecnici
|
||||
)
|
||||
)';
|
||||
@ -46,7 +46,7 @@ class Interventi extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
@ -83,7 +83,7 @@ class Interventi extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
@ -106,14 +106,14 @@ class Interventi extends AppResource
|
||||
|
||||
$record = $database->fetchOne($query);
|
||||
|
||||
// Individuazione impianti collegati
|
||||
// Individuazione degli impianti collegati
|
||||
$impianti = $database->fetchArray('SELECT idimpianto AS id FROM my_impianti_interventi WHERE idintervento = '.prepare($id));
|
||||
$record['impianti'] = array_column($impianti, 'id');
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
protected function createRecord($data)
|
||||
public function createRecord($data)
|
||||
{
|
||||
$anagrafica = Anagrafica::find($data['id_anagrafica']);
|
||||
$tipo = TipoSessione::find($data['id_tipo_intervento']);
|
||||
@ -131,7 +131,7 @@ class Interventi extends AppResource
|
||||
];
|
||||
}
|
||||
|
||||
protected function updateRecord($data)
|
||||
public function updateRecord($data)
|
||||
{
|
||||
$intervento = Intervento::find($data['id']);
|
||||
|
||||
|
@ -7,7 +7,7 @@ use API\Interfaces\RetrieveInterface;
|
||||
|
||||
class Preventivi extends AppResource implements RetrieveInterface
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public 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
|
||||
@ -25,7 +25,7 @@ class Preventivi extends AppResource implements RetrieveInterface
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public 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
|
||||
@ -44,7 +44,7 @@ class Preventivi extends AppResource implements RetrieveInterface
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT co_preventivi.id,
|
||||
|
@ -7,12 +7,12 @@ use API\Interfaces\RetrieveInterface;
|
||||
|
||||
class Referenti extends AppResource implements RetrieveInterface
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('an_referenti', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public 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
|
||||
@ -30,7 +30,7 @@ class Referenti extends AppResource implements RetrieveInterface
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT id,
|
||||
|
@ -15,7 +15,7 @@ use UnexpectedValueException;
|
||||
|
||||
class RigheInterventi extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
@ -50,7 +50,7 @@ class RigheInterventi extends AppResource
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
@ -85,7 +85,7 @@ class RigheInterventi extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Individuazione riga tramite classi
|
||||
$riga = $this->getRecord($id);
|
||||
@ -129,6 +129,42 @@ class RigheInterventi extends AppResource
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function createRecord($data)
|
||||
{
|
||||
$intervento = Intervento::find($data['id_intervento']);
|
||||
if ($data['is_articolo']) {
|
||||
$originale = ArticoloOriginale::find($data['id_articolo']);
|
||||
$riga = Articolo::build($intervento, $originale);
|
||||
} elseif ($data['is_sconto']) {
|
||||
// TODO: sconti
|
||||
} else {
|
||||
$riga = Riga::build($intervento);
|
||||
}
|
||||
|
||||
$this->aggiornaRecord($riga, $data);
|
||||
$riga->save();
|
||||
|
||||
return [
|
||||
'id' => $riga->id,
|
||||
];
|
||||
}
|
||||
|
||||
public function updateRecord($data)
|
||||
{
|
||||
$riga = $this->getRecord($data['id']);
|
||||
|
||||
$this->aggiornaRecord($riga, $data);
|
||||
$riga->save();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function deleteRecord($id)
|
||||
{
|
||||
$riga = $this->getRecord($id);
|
||||
$riga->delete();
|
||||
}
|
||||
|
||||
protected function getRecord($id)
|
||||
{
|
||||
// Individuazione delle caratteristiche del record
|
||||
@ -158,42 +194,6 @@ class RigheInterventi extends AppResource
|
||||
return $type;
|
||||
}
|
||||
|
||||
protected function createRecord($data)
|
||||
{
|
||||
$intervento = Intervento::find($data['id_intervento']);
|
||||
if ($data['is_articolo']) {
|
||||
$originale = ArticoloOriginale::find($data['id_articolo']);
|
||||
$riga = Articolo::build($intervento, $originale);
|
||||
} elseif ($data['is_sconto']) {
|
||||
// TODO: sconti
|
||||
} else {
|
||||
$riga = Riga::build($intervento);
|
||||
}
|
||||
|
||||
$this->aggiornaRecord($riga, $data);
|
||||
$riga->save();
|
||||
|
||||
return [
|
||||
'id' => $riga->id,
|
||||
];
|
||||
}
|
||||
|
||||
protected function updateRecord($data)
|
||||
{
|
||||
$riga = $this->getRecord($data['id']);
|
||||
|
||||
$this->aggiornaRecord($riga, $data);
|
||||
$riga->save();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function deleteRecord($id)
|
||||
{
|
||||
$riga = $this->getRecord($id);
|
||||
$riga->delete();
|
||||
}
|
||||
|
||||
protected function aggiornaRecord($record, $data)
|
||||
{
|
||||
$record->descrizione = $data['descrizione'];
|
||||
|
@ -6,12 +6,12 @@ use API\App\AppResource;
|
||||
|
||||
class Sedi extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('an_sedi', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public 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
|
||||
@ -29,7 +29,7 @@ class Sedi extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT an_sedi.id,
|
||||
|
@ -11,7 +11,7 @@ use Modules\Interventi\Intervento;
|
||||
|
||||
class SessioniInterventi extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
@ -40,7 +40,7 @@ class SessioniInterventi extends AppResource
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
@ -70,7 +70,7 @@ class SessioniInterventi extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT id,
|
||||
@ -99,7 +99,7 @@ class SessioniInterventi extends AppResource
|
||||
return $record;
|
||||
}
|
||||
|
||||
protected function createRecord($data)
|
||||
public function createRecord($data)
|
||||
{
|
||||
// Informazioni sull'utente
|
||||
$user = Auth::user();
|
||||
@ -120,7 +120,7 @@ class SessioniInterventi extends AppResource
|
||||
];
|
||||
}
|
||||
|
||||
protected function updateRecord($data)
|
||||
public function updateRecord($data)
|
||||
{
|
||||
$sessione = Sessione::find($data['id']);
|
||||
|
||||
@ -130,6 +130,12 @@ class SessioniInterventi extends AppResource
|
||||
return [];
|
||||
}
|
||||
|
||||
public function deleteRecord($id)
|
||||
{
|
||||
$sessione = Sessione::find($id);
|
||||
$sessione->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna i dati della sessione sulla base dei dati caricati dall'applicazione.
|
||||
*
|
||||
@ -163,10 +169,4 @@ class SessioniInterventi extends AppResource
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function deleteRecord($id)
|
||||
{
|
||||
$sessione = Sessione::find($id);
|
||||
$sessione->delete();
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ use API\App\AppResource;
|
||||
|
||||
class StatiIntervento extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('in_statiintervento', 'idstatointervento', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT in_statiintervento.idstatointervento AS id FROM in_statiintervento';
|
||||
|
||||
@ -25,7 +25,7 @@ class StatiIntervento extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT in_statiintervento.idstatointervento AS id,
|
||||
|
@ -6,20 +6,36 @@ use API\App\AppResource;
|
||||
|
||||
class TariffeContratti extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT CONCAT(idtipointervento, "-", idcontratto) AS id
|
||||
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 = 0';
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND (co_contratti.updated_at > '.prepare($last_sync_at).' OR co_staticontratti.updated_at > '.prepare($last_sync_at).')';
|
||||
}
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
$da_stati = array_column($records, 'id');
|
||||
|
||||
// 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)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT CONCAT(idtipointervento, "-", idcontratto) AS id FROM co_contratti_tipiintervento';
|
||||
$query = 'SELECT CONCAT(idtipointervento, "-", idcontratto) AS id
|
||||
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';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' WHERE updated_at > '.prepare($last_sync_at);
|
||||
$query .= ' AND co_contratti_tipiintervento.updated_at > '.prepare($last_sync_at);
|
||||
}
|
||||
|
||||
$records = database()->fetchArray($query);
|
||||
@ -27,7 +43,7 @@ class TariffeContratti extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
$pieces = explode('-', $id);
|
||||
$id_tipo_intervento = $pieces[0];
|
||||
|
@ -3,17 +3,15 @@
|
||||
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)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('in_tariffe', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT id FROM in_tariffe';
|
||||
|
||||
@ -27,7 +25,7 @@ class TariffeTecnici extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT id,
|
||||
|
@ -8,12 +8,12 @@ use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
class Tecnici extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('an_anagrafiche', 'idanagrafica', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Anagrafica::select('idanagrafica')
|
||||
->whereHas('tipi', function (Builder $query) {
|
||||
@ -31,7 +31,7 @@ class Tecnici extends AppResource
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT an_anagrafiche.idanagrafica AS id,
|
||||
|
@ -6,12 +6,12 @@ use API\App\AppResource;
|
||||
|
||||
class TipiIntervento extends AppResource
|
||||
{
|
||||
protected function getCleanupData($last_sync_at)
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('in_tipiintervento', 'idtipointervento', $last_sync_at);
|
||||
}
|
||||
|
||||
protected function getModifiedRecords($last_sync_at)
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT in_tipiintervento.idtipointervento AS id FROM in_tipiintervento';
|
||||
|
||||
@ -25,7 +25,7 @@ class TipiIntervento extends AppResource
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
protected function retrieveRecord($id)
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT in_tipiintervento.idtipointervento AS id,
|
||||
|
@ -253,9 +253,10 @@ INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `e
|
||||
(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'),
|
||||
(NULL, 'app-v1', 'retrieve', 'allegati-interventi', 'API\\App\\v1\\AllegatiInterventi', '1'),
|
||||
(NULL, 'app-v1', 'retrieve', 'allegati-interventi-cleanup', 'API\\App\\v1\\AllegatiInterventi', '1'),
|
||||
(NULL, 'app-v1', 'retrieve', 'allegato-intervento', 'API\\App\\v1\\AllegatiInterventi', '1'),
|
||||
(NULL, 'app-v1', 'create', 'allegato-intervento', 'API\\App\\v1\\AllegatiInterventi', '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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user