2020-07-16 09:40:49 +02:00
|
|
|
<?php
|
|
|
|
|
2020-07-16 11:32:56 +02:00
|
|
|
namespace Modules\Interventi\API\AppV1;
|
2020-07-16 09:40:49 +02:00
|
|
|
|
|
|
|
use API\AppResource;
|
2020-07-16 11:32:56 +02:00
|
|
|
use Auth;
|
2020-07-16 09:40:49 +02:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
2020-07-16 11:32:56 +02:00
|
|
|
class Interventi extends AppResource
|
2020-07-16 09:40:49 +02:00
|
|
|
{
|
|
|
|
protected function getCleanupData()
|
|
|
|
{
|
2020-07-16 11:32:56 +02:00
|
|
|
// Periodo per selezionare interventi
|
|
|
|
$today = new Carbon();
|
|
|
|
$start = $today->copy()->subMonths(2);
|
|
|
|
$end = $today->copy()->addMonth(1);
|
|
|
|
|
|
|
|
// Informazioni sull'utente
|
|
|
|
$user = Auth::user();
|
|
|
|
$id_tecnico = $user->id_anagrafica;
|
|
|
|
|
|
|
|
$query = 'SELECT in_interventi.id FROM in_interventi WHERE
|
|
|
|
deleted_at IS NOT NULL
|
|
|
|
OR EXISTS(
|
|
|
|
SELECT orario_fine FROM in_interventi_tecnici WHERE
|
|
|
|
in_interventi_tecnici.idintervento = in_interventi.id
|
|
|
|
AND orario_fine NOT BETWEEN :period_start AND :period_end
|
|
|
|
AND idtecnico = :id_tecnico
|
|
|
|
)';
|
|
|
|
$records = database()->fetchArray($query, [
|
|
|
|
':period_end' => $end,
|
|
|
|
':period_start' => $start,
|
|
|
|
':id_tecnico' => $id_tecnico,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return array_column($records, 'id');
|
2020-07-16 09:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getData($last_sync_at)
|
|
|
|
{
|
2020-07-16 11:32:56 +02:00
|
|
|
// Periodo per selezionare interventi
|
|
|
|
$today = new Carbon();
|
|
|
|
$start = $today->copy()->subMonths(2);
|
|
|
|
$end = $today->copy()->addMonth(1);
|
|
|
|
|
|
|
|
// Informazioni sull'utente
|
|
|
|
$user = Auth::user();
|
|
|
|
$id_tecnico = $user->id_anagrafica;
|
|
|
|
|
|
|
|
$query = 'SELECT in_interventi.id FROM in_interventi WHERE
|
|
|
|
in_interventi.id IN (
|
|
|
|
SELECT idintervento FROM in_interventi_tecnici
|
|
|
|
WHERE in_interventi_tecnici.idintervento = in_interventi.id
|
|
|
|
AND in_interventi_tecnici.orario_fine BETWEEN :period_start AND :period_end
|
|
|
|
AND in_interventi_tecnici.idtecnico = :id_tecnico
|
|
|
|
)
|
|
|
|
AND deleted_at IS NULL';
|
2020-07-16 09:40:49 +02:00
|
|
|
|
|
|
|
// Filtro per data
|
|
|
|
if ($last_sync_at) {
|
|
|
|
$last_sync = new Carbon($last_sync_at);
|
2020-07-16 11:32:56 +02:00
|
|
|
$query .= ' AND in_interventi.updated_at > '.prepare($last_sync);
|
2020-07-16 09:40:49 +02:00
|
|
|
}
|
2020-07-16 11:32:56 +02:00
|
|
|
$records = database()->fetchArray($query, [
|
|
|
|
':period_start' => $start,
|
|
|
|
':period_end' => $end,
|
|
|
|
':id_tecnico' => $id_tecnico,
|
|
|
|
]);
|
2020-07-16 09:40:49 +02:00
|
|
|
|
2020-07-16 11:32:56 +02:00
|
|
|
return array_column($records, 'id');
|
2020-07-16 09:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDetails($id)
|
|
|
|
{
|
|
|
|
// Gestione della visualizzazione dei dettagli del record
|
2020-07-16 11:32:56 +02:00
|
|
|
$query = "SELECT id,
|
|
|
|
codice,
|
|
|
|
richiesta,
|
|
|
|
data_richiesta,
|
|
|
|
descrizione,
|
|
|
|
idanagrafica AS id_anagrafica,
|
|
|
|
idtipointervento AS id_tipo_intervento,
|
|
|
|
idstatointervento AS id_stato_intervento,
|
|
|
|
informazioniaggiuntive AS informazioni_aggiuntive,
|
|
|
|
IF(idsede_destinazione = 0, NULL, idsede_destinazione) AS id_sede,
|
|
|
|
firma_file,
|
|
|
|
IF(firma_data = '0000-00-00 00:00:00', '', firma_data) AS firma_data,
|
|
|
|
firma_nome
|
|
|
|
FROM in_interventi
|
|
|
|
WHERE in_interventi.id = ".prepare($id);
|
2020-07-16 09:40:49 +02:00
|
|
|
|
|
|
|
$record = database()->fetchOne($query);
|
|
|
|
|
|
|
|
return $record;
|
|
|
|
}
|
|
|
|
}
|