mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-18 04:00:12 +01:00
Merge branch 'app-api'
This commit is contained in:
commit
8dd8007147
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use API\Response;
|
||||
|
||||
function serverError()
|
||||
{
|
||||
$error = error_get_last();
|
||||
@ -15,15 +17,13 @@ register_shutdown_function('serverError');
|
||||
|
||||
include_once __DIR__.'/../core.php';
|
||||
|
||||
// Disabilta la sessione per l'API
|
||||
// Disabilita la sessione per l'API
|
||||
session_write_close();
|
||||
|
||||
// Permesso di accesso all'API da ogni dispositivo
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
|
||||
|
||||
use API\Response;
|
||||
|
||||
try {
|
||||
$response = Response::manage();
|
||||
} catch (Exception $e) {
|
||||
|
@ -912,6 +912,15 @@ input.small-width {
|
||||
margin-top: 1.4rem;
|
||||
}
|
||||
|
||||
/** Fix tooltip per elementi disabilitati. */
|
||||
div.tip {
|
||||
display: inline-block !important;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
pointer-events: none
|
||||
}
|
||||
|
||||
/* Fancy checkbox: https://bootsnipp.com/snippets/M2bda */
|
||||
.form-group input[type="checkbox"] {
|
||||
display: none;
|
||||
|
@ -32,6 +32,7 @@ return [
|
||||
'modules/categorie_documenti' => 'Modules\CategorieDocumentali',
|
||||
'modules/listini' => 'Modules\Listini',
|
||||
'modules/my_impianti' => 'Modules\Impianti',
|
||||
'modules/impostazioni' => 'Modules\Impostazioni',
|
||||
'plugins/exportFE' => 'Plugins\ExportFE',
|
||||
'plugins/importFE' => 'Plugins\ImportFE',
|
||||
'plugins/receiptFE' => 'Plugins\ReceiptFE',
|
||||
|
@ -4,24 +4,32 @@ include_once __DIR__.'/../../core.php';
|
||||
|
||||
$rs_documento = $dbo->fetchArray('SELECT * FROM co_righe_contratti WHERE idcontratto='.prepare($id_record));
|
||||
|
||||
$disabled = $record['is_fatturabile'] && !empty($rs_documento);
|
||||
$is_fatturabile = $record['is_fatturabile'] && !empty($rs_documento);
|
||||
|
||||
$stati_fatturabili = $dbo->fetchOne('SELECT GROUP_CONCAT(`descrizione` SEPARATOR ", ") AS stati_abilitati FROM `co_staticontratti` WHERE `is_fatturabile` = 1')['stati_abilitati'];
|
||||
|
||||
/* permetto di fatturare il contratto solo se contiene righe e si trova in uno stato fatturabile */
|
||||
echo '
|
||||
<button type="button" '.($disabled ? '' : 'disabled').' class="btn btn-info '.($disabled ? '' : 'disabled tip').' " data-href="'.$structure->fileurl('crea_documento.php').'?id_module='.$id_module.'&id_record='.$id_record.'&documento=fattura" data-toggle="modal" data-title="'.tr('Crea fattura').'" title="'.($disabled ? '' : tr('Per creare un documento deve essere inserita almeno una riga e lo stato del contratto deve essere tra: ').$stati_fatturabili).'">
|
||||
<i class="fa fa-magic"></i> '.tr('Crea fattura').'
|
||||
</button>';
|
||||
<div class="tip" data-toggle="tooltip" title="'.tr('Per creare un documento deve essere inserita almeno una riga e lo stato del contratto deve essere tra: _STATE_LIST_', [
|
||||
'_STATE_LIST_' => $stati_fatturabili,
|
||||
]).'">
|
||||
<button type="button" class="btn btn-info '.($is_fatturabile ? '' : 'disabled').' " data-href="'.$structure->fileurl('crea_documento.php').'?id_module='.$id_module.'&id_record='.$id_record.'&documento=fattura" data-toggle="modal" data-title="'.tr('Crea fattura').'">
|
||||
<i class="fa fa-magic"></i> '.tr('Crea fattura').'
|
||||
</button>
|
||||
</div>';
|
||||
|
||||
$rinnova = !empty($record['data_accettazione']) && !empty($record['data_conclusione']) && $record['data_accettazione'] != '0000-00-00' && $record['data_conclusione'] != '0000-00-00' && $record['is_pianificabile'] && $record['rinnovabile'];
|
||||
|
||||
$stati_pianificabili = $dbo->fetchOne('SELECT GROUP_CONCAT(`descrizione` SEPARATOR ", ") AS stati_pianificabili FROM `co_staticontratti` WHERE `is_pianificabile` = 1')['stati_pianificabili'];
|
||||
|
||||
echo '
|
||||
<button type="button" class="btn btn-warning ask '.($rinnova ? '' : 'disabled tip').'" data-backto="record-edit" data-op="renew" data-msg="'.tr('Rinnovare questo contratto?').'" data-button="'.tr('Rinnova').'" data-class="btn btn-lg btn-warning" '.($rinnova ? '' : 'disabled').' title="'.(($rinnova) ? '' : tr('Il contratto è rinnovabile se sono definite le date di accettazione e conclusione e si trova in uno stato di questi stati: '.$stati_pianificabili)).'">
|
||||
<i class="fa fa-refresh"></i> '.tr('Rinnova').'...
|
||||
</button>';
|
||||
<div class="tip" data-toggle="tooltip" title="'.tr('Il contratto è rinnovabile se sono definite le date di accettazione e conclusione e si trova in uno stato di questi stati: _STATE_LIST_', [
|
||||
'_STATE_LIST_' => $stati_pianificabili,
|
||||
]).'">
|
||||
<button type="button" class="btn btn-warning ask '.($rinnova ? '' : 'disabled').'" data-backto="record-edit" data-op="renew" data-msg="'.tr('Rinnovare questo contratto?').'" data-button="'.tr('Rinnova').'" data-class="btn btn-lg btn-warning">
|
||||
<i class="fa fa-refresh"></i> '.tr('Rinnova').'...
|
||||
</button>
|
||||
</div>';
|
||||
|
||||
// Duplica contratto
|
||||
echo'
|
||||
|
@ -3,9 +3,10 @@
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
echo '
|
||||
<i class="fa fa-question-circle-o tip" title="'.tr("Il ddt è fatturabile solo se non si trova negli stati _STATE_LIST_ e la relativa causale è abilitata all'importazione in altri documenti", [
|
||||
<div class="tip" data-toggle="tooltip" title="'.tr("Il ddt è fatturabile solo se non si trova negli stati _STATE_LIST_ e la relativa causale è abilitata all'importazione in altri documenti", [
|
||||
'_STATE_LIST_' => 'Evaso, Parzialmente evaso, Parzialmente fatturato',
|
||||
]).'"></i>
|
||||
<button class="btn btn-info '.($ddt->isImportabile() ? '' : 'disabled').'" data-href="'.$structure->fileurl('crea_documento.php').'?id_module='.$id_module.'&id_record='.$id_record.'&documento=fattura" data-toggle="modal" data-title="'.tr('Crea fattura').(($dir == 'entrata') ? ' di vendita' : ' di acquisto').'">
|
||||
<i class="fa fa-magic"></i> '.tr('Crea fattura').(($dir == 'entrata') ? ' di vendita' : ' di acquisto').'
|
||||
</button>';
|
||||
]).'">
|
||||
<button class="btn btn-info '.($ddt->isImportabile() ? '' : 'disabled').'" data-href="'.$structure->fileurl('crea_documento.php').'?id_module='.$id_module.'&id_record='.$id_record.'&documento=fattura" data-toggle="modal" data-title="'.tr('Crea fattura').(($dir == 'entrata') ? ' di vendita' : ' di acquisto').'">
|
||||
<i class="fa fa-magic"></i> '.tr('Crea fattura').(($dir == 'entrata') ? ' di vendita' : ' di acquisto').'
|
||||
</button>
|
||||
</div>';
|
||||
|
@ -590,7 +590,7 @@ if (!$block_edit) {
|
||||
}
|
||||
|
||||
echo '
|
||||
<div class="tip" data-toggle="tooltip" title="'.tr('Attività completate non collegate a preventivi o contratti e che non siano già state fatturate.').'" style="display:inline;">
|
||||
<div class="tip" data-toggle="tooltip" title="'.tr('Attività completate non collegate a preventivi o contratti e che non siano già state fatturate.').'">
|
||||
<a class="btn btn-sm btn-primary '.(!empty($interventi) ? '' : ' disabled').'" data-href="'.$rootdir.'/modules/fatture/add_intervento.php?id_module='.$id_module.'&id_record='.$id_record.'" data-title="Aggiungi attività">
|
||||
<i class="fa fa-plus"></i> Attività
|
||||
</a>
|
||||
@ -600,7 +600,7 @@ if (!$block_edit) {
|
||||
$prev_query = 'SELECT COUNT(*) AS tot FROM co_preventivi WHERE idanagrafica='.prepare($record['idanagrafica']).' AND idstato IN(SELECT id FROM co_statipreventivi WHERE is_fatturabile = 1) AND default_revision=1 AND co_preventivi.id IN (SELECT idpreventivo FROM co_righe_preventivi WHERE co_righe_preventivi.idpreventivo = co_preventivi.id AND (qta - qta_evasa) > 0)';
|
||||
$preventivi = $dbo->fetchArray($prev_query)[0]['tot'];
|
||||
echo '
|
||||
<div class="tip" style="display:inline;">
|
||||
<div class="tip">
|
||||
<a class="btn btn-sm btn-primary '.(!empty($preventivi) ? '' : ' disabled').'" data-href="'.$rootdir.'/modules/fatture/add_preventivo.php?id_module='.$id_module.'&id_record='.$id_record.'" data-title="Aggiungi preventivo" data-toggle="tooltip">
|
||||
<i class="fa fa-plus"></i> Preventivo
|
||||
</a>
|
||||
@ -610,7 +610,7 @@ if (!$block_edit) {
|
||||
$contr_query = 'SELECT COUNT(*) AS tot FROM co_contratti WHERE idanagrafica='.prepare($record['idanagrafica']).' AND idstato IN( SELECT id FROM co_staticontratti WHERE is_fatturabile = 1) AND co_contratti.id IN (SELECT idcontratto FROM co_righe_contratti WHERE co_righe_contratti.idcontratto = co_contratti.id AND (qta - qta_evasa) > 0)';
|
||||
$contratti = $dbo->fetchArray($contr_query)[0]['tot'];
|
||||
echo '
|
||||
<div class="tip" style="display:inline;">
|
||||
<div class="tip">
|
||||
<a class="btn btn-sm btn-primary '.(!empty($contratti) ? '' : ' disabled').'" data-href="'.$rootdir.'/modules/fatture/add_contratto.php?id_module='.$id_module.'&id_record='.$id_record.'" data-title="Aggiungi contratto" data-toggle="tooltip">
|
||||
<i class="fa fa-plus"></i> Contratto
|
||||
</a>
|
||||
|
@ -3,8 +3,15 @@
|
||||
namespace Modules\Impianti;
|
||||
|
||||
use Common\Model;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
class Impianto extends Model
|
||||
{
|
||||
protected $table = 'my_impianti';
|
||||
|
||||
// Relazioni Eloquent
|
||||
public function anagrafica()
|
||||
{
|
||||
return $this->belongsTo(Anagrafica::class, 'idanagrafica');
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,13 @@ $stati_abilitati = $dbo->fetchOne('SELECT GROUP_CONCAT(`descrizione` SEPARATOR "
|
||||
|
||||
// Crea revisione
|
||||
echo '
|
||||
<button type="button" class="btn btn-warning '.($record['is_revisionabile'] ? '' : 'disabled tip').'" onclick="if(confirm(\'Vuoi creare un nuova revisione?\')){$(\'#crea-revisione\').submit();}" '.($record['is_revisionabile'] ? '' : 'disabled').' title="'.($record['is_revisionabile'] ? '' : tr('Per creare una nuova revisione lo stato del preventivo deve essere tra: ').$stati_abilitati).'">
|
||||
<i class="fa fa-edit"></i> '.tr('Crea nuova revisione...').'
|
||||
</button>';
|
||||
<div class="tip" data-toggle="tooltip" title="'.tr('Per creare una nuova revisione lo stato del preventivo deve essere tra: _STATE_LIST_', [
|
||||
'_STATE_LIST_' => $stati_abilitati,
|
||||
]).'">
|
||||
<button type="button" class="btn btn-warning '.($record['is_revisionabile'] ? '' : 'disabled').'" onclick="if(confirm(\'Vuoi creare un nuova revisione?\')){$(\'#crea-revisione\').submit();}">
|
||||
<i class="fa fa-edit"></i> '.tr('Crea nuova revisione...').'
|
||||
</button>
|
||||
</div>';
|
||||
|
||||
$rs_documento = $dbo->fetchArray('SELECT * FROM co_righe_preventivi WHERE idpreventivo='.prepare($id_record));
|
||||
|
||||
@ -23,11 +27,11 @@ $stati_abilitati = $dbo->fetchOne('SELECT GROUP_CONCAT(`descrizione` SEPARATOR "
|
||||
|
||||
// Creazione altri documenti
|
||||
echo '
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-info dropdown-toggle '.($disabled ? '' : 'disabled tip').'" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" '.($disabled ? '' : 'disabled').' title="'.($disabled ? '' : tr('Per creare un documento deve essere inserita almeno una riga e lo stato del preventivo deve essere tra: _STATE_LIST_', [
|
||||
'_STATE_LIST_' => $stati_abilitati,
|
||||
])).'" >
|
||||
<i class="fa fa-magic"></i> '.tr('Crea').'
|
||||
<div style="margin-left: 4px" class="dropdown pull-right tip" data-toggle="tooltip" title="'.tr('Per creare un documento deve essere inserita almeno una riga e lo stato del preventivo deve essere tra: _STATE_LIST_', [
|
||||
'_STATE_LIST_' => $stati_abilitati,
|
||||
]).'">
|
||||
<button class="btn btn-info dropdown-toggle '.($disabled ? '' : 'disabled').'" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
<i class="fa fa-magic"></i> '.tr('Crea').'...
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-right">
|
||||
|
272
src/API/App/AppResource.php
Normal file
272
src/API/App/AppResource.php
Normal file
@ -0,0 +1,272 @@
|
||||
<?php
|
||||
|
||||
namespace API\App;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
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'] && $request['last_sync_at'] != 'undefined' ? new Carbon($request['last_sync_at']) : null;
|
||||
|
||||
// Gestione delle operazioni di cleanup
|
||||
if (strpos($request['resource'], 'cleanup') !== false) {
|
||||
$list = [];
|
||||
if (!empty($last_sync_at)) {
|
||||
$list = $this->getCleanupData($last_sync_at);
|
||||
}
|
||||
$list = $this->forceToString($list);
|
||||
|
||||
return [
|
||||
'records' => $list,
|
||||
];
|
||||
}
|
||||
|
||||
// Gestione dell'enumerazione dei record modificati
|
||||
if (!isset($id)) {
|
||||
$list = $this->getModifiedRecords($last_sync_at);
|
||||
$list = $this->forceToString($list);
|
||||
|
||||
return [
|
||||
'records' => $list,
|
||||
];
|
||||
}
|
||||
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$details = $this->retrieveRecord($id);
|
||||
$details = $this->forceToString($details);
|
||||
|
||||
return [
|
||||
'record' => $details,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
$response_data = $this->createRecord($data);
|
||||
$response_data = $this->forceToString($response_data);
|
||||
|
||||
return [
|
||||
'id' => $response_data['id'],
|
||||
'data' => $response_data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
$response_data = $this->updateRecord($data);
|
||||
$response_data = $this->forceToString($response_data);
|
||||
|
||||
return [
|
||||
'data' => $response_data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param $list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function forceToString($list)
|
||||
{
|
||||
$result = [];
|
||||
// Fix per la gestione dei contenuti numerici
|
||||
foreach ($list as $key => $value) {
|
||||
if (is_numeric($value)) {
|
||||
$result[$key] = (string) $value;
|
||||
} elseif (is_array($value)) {
|
||||
$result[$key] = $this->forceToString($value);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce gli ID dei potenziali record mancanti, sulla base della colonna indicata e a partire da *last_sync_at*.
|
||||
*
|
||||
* @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, $last_sync_at = null)
|
||||
{
|
||||
$database = database();
|
||||
$db_name = $database->getDatabaseName();
|
||||
|
||||
// Ottiene il valore successivo della colonna di tipo 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
|
||||
$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'] = $next_autoincrement - 1;
|
||||
}
|
||||
|
||||
if ($step['end'] >= $step['start']) {
|
||||
$total = array_merge($total, range($step['start'], $step['end']));
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce gli ID dei record con campo *deleted_at* maggiore di *last_sync_at*.
|
||||
*
|
||||
* @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, $last_sync_at = null)
|
||||
{
|
||||
$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';
|
||||
}
|
||||
|
||||
$results = database()->fetchArray($query);
|
||||
|
||||
return array_column($results, 'id');
|
||||
}
|
||||
}
|
41
src/API/App/v1/AliquoteIva.php
Normal file
41
src/API/App/v1/AliquoteIva.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class AliquoteIva extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('co_iva', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
public 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) {
|
||||
$query .= ' AND co_iva.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
|
||||
$query = 'SELECT co_iva.id,
|
||||
co_iva.descrizione,
|
||||
co_iva.percentuale
|
||||
FROM co_iva
|
||||
WHERE co_iva.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
108
src/API/App/v1/AllegatiInterventi.php
Normal file
108
src/API/App/v1/AllegatiInterventi.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use API\Exceptions\InternalError;
|
||||
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,
|
||||
'data_creazione' => $upload->created_at,
|
||||
];
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function createRecord($data)
|
||||
{
|
||||
$module = Modules::get('Interventi');
|
||||
|
||||
// Creazione del file temporaneo
|
||||
$content = explode(',', $data['contenuto']);
|
||||
if (count($content) < 1) {
|
||||
throw new InternalError();
|
||||
}
|
||||
|
||||
$file = tmpfile();
|
||||
$path = stream_get_meta_data($file)['uri'];
|
||||
fwrite($file, base64_decode($content[1]));
|
||||
|
||||
// Salvataggio del file come allegato
|
||||
$upload = Upload::build($path, [
|
||||
'id_module' => $module['id'],
|
||||
'id_record' => $data['id_intervento'],
|
||||
'original_name' => $data['nome'],
|
||||
], $data['nome'], $data['categoria']);
|
||||
|
||||
// Chiusura e rimozione del file temporaneo
|
||||
fclose($file);
|
||||
|
||||
return [
|
||||
'id' => $upload->id,
|
||||
'tipo' => $upload->extension,
|
||||
'size' => $upload->size,
|
||||
'contenuto' => '',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRisorsaInterventi()
|
||||
{
|
||||
return new Interventi();
|
||||
}
|
||||
}
|
47
src/API/App/v1/Articoli.php
Normal file
47
src/API/App/v1/Articoli.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class Articoli extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('mg_articoli', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
public 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) {
|
||||
$query .= ' AND mg_articoli.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
|
||||
$query = 'SELECT mg_articoli.id AS id,
|
||||
mg_articoli.codice,
|
||||
mg_articoli.descrizione,
|
||||
mg_articoli.prezzo_vendita,
|
||||
mg_articoli.prezzo_acquisto,
|
||||
mg_articoli.qta,
|
||||
mg_articoli.um,
|
||||
(SELECT nome FROM mg_categorie WHERE id = mg_articoli.id_categoria) AS categoria,
|
||||
(SELECT nome FROM mg_categorie WHERE id = mg_articoli.id_sottocategoria) AS sottocategoria
|
||||
FROM mg_articoli
|
||||
WHERE mg_articoli.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
65
src/API/App/v1/Clienti.php
Normal file
65
src/API/App/v1/Clienti.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
class Clienti extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('an_anagrafiche', 'idanagrafica', $last_sync_at);
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Anagrafica::select('idanagrafica')
|
||||
->whereHas('tipi', function (Builder $query) {
|
||||
$query->where('descrizione', '=', 'Cliente');
|
||||
});
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$statement = $statement->where('updated_at', '>', $last_sync_at);
|
||||
}
|
||||
|
||||
$results = $statement->get()
|
||||
->pluck('idanagrafica');
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT an_anagrafiche.idanagrafica AS id,
|
||||
an_anagrafiche.ragione_sociale,
|
||||
an_anagrafiche.piva AS partita_iva,
|
||||
an_anagrafiche.codice_fiscale,
|
||||
an_anagrafiche.indirizzo,
|
||||
an_anagrafiche.indirizzo2,
|
||||
an_anagrafiche.citta,
|
||||
an_anagrafiche.cap,
|
||||
an_anagrafiche.provincia,
|
||||
an_anagrafiche.km,
|
||||
IFNULL(an_anagrafiche.lat, 0.00) AS latitudine,
|
||||
IFNULL(an_anagrafiche.lng, 0.00) AS longitudine,
|
||||
an_nazioni.nome AS nazione,
|
||||
an_anagrafiche.fax,
|
||||
an_anagrafiche.telefono,
|
||||
an_anagrafiche.cellulare,
|
||||
an_anagrafiche.email,
|
||||
an_anagrafiche.sitoweb AS sito_web,
|
||||
an_anagrafiche.note,
|
||||
an_anagrafiche.deleted_at
|
||||
FROM an_anagrafiche
|
||||
LEFT OUTER JOIN an_nazioni ON an_anagrafiche.id_nazione = an_nazioni.id
|
||||
WHERE an_anagrafiche.idanagrafica = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
64
src/API/App/v1/Contratti.php
Normal file
64
src/API/App/v1/Contratti.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use API\Interfaces\RetrieveInterface;
|
||||
|
||||
class Contratti extends AppResource implements RetrieveInterface
|
||||
{
|
||||
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');
|
||||
$mancanti = $this->getMissingIDs('co_contratti', 'id', $last_sync_at);
|
||||
|
||||
$results = array_unique(array_merge($da_stati, $mancanti));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
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
|
||||
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_contratti.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
|
||||
WHERE an_tipianagrafiche.descrizione = 'Cliente' AND co_staticontratti.is_pianificabile = 1 AND an_anagrafiche.deleted_at IS NULL";
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND co_contratti.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
|
||||
$query = 'SELECT co_contratti.id,
|
||||
co_contratti.idanagrafica AS id_cliente,
|
||||
IF(co_contratti.idsede = 0, NULL, co_contratti.idsede) AS id_sede,
|
||||
co_contratti.nome,
|
||||
co_contratti.numero,
|
||||
co_contratti.data_bozza
|
||||
FROM co_contratti
|
||||
INNER JOIN co_staticontratti ON co_staticontratti.id = co_contratti.idstato
|
||||
WHERE co_contratti.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
60
src/API/App/v1/Impianti.php
Normal file
60
src/API/App/v1/Impianti.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Modules\Impianti\Impianto;
|
||||
|
||||
class Impianti extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('my_impianti', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$statement = Impianto::select('id')
|
||||
->whereHas('anagrafica.tipi', function (Builder $query) {
|
||||
$query->where('descrizione', '=', 'Cliente');
|
||||
});
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$statement = $statement->where('updated_at', '>', $last_sync_at);
|
||||
}
|
||||
|
||||
$results = $statement->get()
|
||||
->pluck('id');
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT my_impianti.id,
|
||||
my_impianti.idanagrafica AS id_cliente,
|
||||
my_impianti.idsede AS id_sede,
|
||||
my_impianti.matricola,
|
||||
my_impianti.nome,
|
||||
my_impianti.descrizione,
|
||||
my_impianti.data AS data_installazione,
|
||||
my_impianti.proprietario,
|
||||
my_impianti.ubicazione,
|
||||
my_impianti.palazzo,
|
||||
my_impianti.scala,
|
||||
my_impianti.piano,
|
||||
my_impianti.interno,
|
||||
my_impianti.occupante,
|
||||
my_impianti_categorie.nome AS categoria
|
||||
FROM my_impianti
|
||||
LEFT JOIN my_impianti_categorie ON my_impianti_categorie.id = my_impianti.id_categoria
|
||||
WHERE my_impianti.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
42
src/API/App/v1/Impostazioni.php
Normal file
42
src/API/App/v1/Impostazioni.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class Impostazioni extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT zz_settings.id FROM zz_settings WHERE sezione = "Applicazione"';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND zz_settings.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
|
||||
$query = 'SELECT id AS id,
|
||||
nome,
|
||||
valore AS contenuto,
|
||||
tipo
|
||||
FROM zz_settings
|
||||
WHERE zz_settings.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
206
src/API/App/v1/Interventi.php
Normal file
206
src/API/App/v1/Interventi.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Intervention\Image\ImageManagerStatic;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Interventi\Intervento;
|
||||
use Modules\Interventi\Stato;
|
||||
use Modules\TipiIntervento\Tipo as TipoSessione;
|
||||
|
||||
class Interventi extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// Periodo per selezionare interventi
|
||||
$today = new Carbon();
|
||||
$start = $today->copy()->subMonths(2);
|
||||
$end = $today->copy()->addMonth(1);
|
||||
|
||||
$remove_end = $start->copy();
|
||||
$remove_start = $remove_end->copy()->subMonths(2);
|
||||
|
||||
// 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 (
|
||||
in_interventi.id NOT 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_q1
|
||||
)
|
||||
AND 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 :remove_period_start AND :remove_period_end
|
||||
AND in_interventi_tecnici.idtecnico = :id_tecnico_q2
|
||||
)
|
||||
)';
|
||||
$records = database()->fetchArray($query, [
|
||||
':period_end' => $end,
|
||||
':period_start' => $start,
|
||||
':remove_period_end' => $remove_end,
|
||||
':remove_period_start' => $remove_start,
|
||||
':id_tecnico_q1' => $id_tecnico,
|
||||
':id_tecnico_q2' => $id_tecnico,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// 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 NULL AND (
|
||||
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
|
||||
)
|
||||
OR (
|
||||
in_interventi.id NOT IN (
|
||||
SELECT idintervento FROM in_interventi_tecnici
|
||||
)
|
||||
AND in_interventi.idstatointervento IN (SELECT idstatointervento FROM in_statiintervento WHERE is_completato = 0)
|
||||
)
|
||||
)';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND in_interventi.updated_at > '.prepare($last_sync_at);
|
||||
}
|
||||
$records = database()->fetchArray($query, [
|
||||
':period_start' => $start,
|
||||
':period_end' => $end,
|
||||
':id_tecnico' => $id_tecnico,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = "SELECT id,
|
||||
codice,
|
||||
richiesta,
|
||||
data_richiesta,
|
||||
descrizione,
|
||||
idanagrafica AS id_cliente,
|
||||
id_contratto,
|
||||
id_preventivo,
|
||||
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);
|
||||
|
||||
$record = $database->fetchOne($query);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
public function createRecord($data)
|
||||
{
|
||||
$anagrafica = Anagrafica::find($data['id_cliente']);
|
||||
$tipo = TipoSessione::find($data['id_tipo_intervento']);
|
||||
$stato = Stato::find($data['id_stato_intervento']);
|
||||
|
||||
$data_richiesta = new Carbon($data['data_richiesta']);
|
||||
$intervento = Intervento::build($anagrafica, $tipo, $stato, $data_richiesta);
|
||||
|
||||
$this->aggiornaRecord($intervento, $data);
|
||||
$intervento->save();
|
||||
|
||||
return [
|
||||
'id' => $intervento->id,
|
||||
'codice' => $intervento->codice,
|
||||
];
|
||||
}
|
||||
|
||||
public function updateRecord($data)
|
||||
{
|
||||
$intervento = Intervento::find($data['id']);
|
||||
|
||||
$this->aggiornaRecord($intervento, $data);
|
||||
$intervento->save();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function aggiornaRecord($record, $data)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
// Aggiornamento intervento
|
||||
$record->idstatointervento = $data['id_stato_intervento'];
|
||||
$record->id_contratto = $data['id_contratto'] ?: null;
|
||||
$record->id_preventivo = $data['id_preventivo'] ?: null;
|
||||
$record->richiesta = $data['richiesta'];
|
||||
$record->descrizione = $data['descrizione'];
|
||||
$record->informazioniaggiuntive = $data['informazioni_aggiuntive'];
|
||||
|
||||
// Salvataggio firma eventuale
|
||||
if (empty($record->firma_nome) && !empty($data['firma_nome'])) {
|
||||
$record->firma_nome = $data['firma_nome'];
|
||||
$record->firma_data = $data['firma_data'];
|
||||
|
||||
// Salvataggio fisico
|
||||
$firma_file = $this->salvaFirma($data['firma_contenuto']);
|
||||
$record->firma_file = $firma_file;
|
||||
}
|
||||
|
||||
// Aggiornamento impianti collegati
|
||||
$database->query('DELETE FROM my_impianti_interventi WHERE idintervento = '.prepare($record->id));
|
||||
foreach ($data['impianti'] as $id_impianto) {
|
||||
$database->insert('my_impianti_interventi', [
|
||||
'idimpianto' => $id_impianto,
|
||||
'idintervento' => $record->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function salvaFirma($firma_base64)
|
||||
{
|
||||
// Salvataggio firma
|
||||
$firma_file = 'firma_'.time().'.png';
|
||||
|
||||
$data = explode(',', $firma_base64);
|
||||
|
||||
$img = ImageManagerStatic::make(base64_decode($data[1]));
|
||||
$img->resize(680, 202, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
|
||||
$img->save(DOCROOT.'/files/interventi/'.$firma_file);
|
||||
|
||||
return $firma_file;
|
||||
}
|
||||
}
|
60
src/API/App/v1/Login.php
Normal file
60
src/API/App/v1/Login.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
use API\Resource;
|
||||
use API\Response;
|
||||
use Auth;
|
||||
use Update;
|
||||
|
||||
class Login extends Resource implements CreateInterface
|
||||
{
|
||||
public function create($request)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
// Controllo sulle credenziali
|
||||
if (auth()->attempt($request['username'], $request['password'])) {
|
||||
$user = $this->getUser();
|
||||
$token = auth()->getToken();
|
||||
|
||||
// Informazioni sull'utente, strettamente collegato ad una anagrafica di tipo Tecnico
|
||||
$utente = $database->fetchOne("SELECT
|
||||
`an_anagrafiche`.`idanagrafica` AS id_anagrafica,
|
||||
`an_anagrafiche`.`ragione_sociale`
|
||||
FROM `zz_users`
|
||||
INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `zz_users`.`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
|
||||
WHERE an_tipianagrafiche.descrizione = 'Tecnico' AND `an_anagrafiche`.`deleted_at` IS NULL AND `id` = :id", [
|
||||
':id' => $user['id'],
|
||||
]);
|
||||
|
||||
if (!empty($utente)) {
|
||||
// Informazioni da restituire tramite l'API
|
||||
$response = [
|
||||
'id_anagrafica' => (string) $utente['id_anagrafica'],
|
||||
'ragione_sociale' => $utente['ragione_sociale'],
|
||||
'token' => $token,
|
||||
'version' => Update::getVersion(),
|
||||
];
|
||||
} else {
|
||||
$response = [
|
||||
'status' => Response::getStatus()['unauthorized']['code'],
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$response = [
|
||||
'status' => Response::getStatus()['unauthorized']['code'],
|
||||
];
|
||||
|
||||
// Se è in corso un brute-force, aggiunge il timeout
|
||||
if (Auth::isBrute()) {
|
||||
$response['timeout'] = Auth::getBruteTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
64
src/API/App/v1/Preventivi.php
Normal file
64
src/API/App/v1/Preventivi.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use API\Interfaces\RetrieveInterface;
|
||||
|
||||
class Preventivi extends AppResource implements RetrieveInterface
|
||||
{
|
||||
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
|
||||
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', $last_sync_at);
|
||||
|
||||
$results = array_unique(array_merge($da_stati, $mancanti));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
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
|
||||
INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_preventivi.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
|
||||
WHERE an_tipianagrafiche.descrizione = 'Cliente' AND co_statipreventivi.is_pianificabile = 1 AND an_anagrafiche.deleted_at IS NULL";
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND co_preventivi.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
|
||||
$query = 'SELECT co_preventivi.id,
|
||||
co_preventivi.idanagrafica AS id_cliente,
|
||||
IF(co_preventivi.idsede = 0, NULL, co_preventivi.idsede) AS id_sede,
|
||||
co_preventivi.nome,
|
||||
co_preventivi.numero,
|
||||
co_preventivi.data_bozza
|
||||
FROM co_preventivi
|
||||
INNER JOIN co_statipreventivi ON co_statipreventivi.id = co_preventivi.idstato
|
||||
WHERE co_preventivi.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
78
src/API/App/v1/RapportinoIntervento.php
Normal file
78
src/API/App/v1/RapportinoIntervento.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
use API\Interfaces\RetrieveInterface;
|
||||
use API\Resource;
|
||||
use Modules\Emails\Mail;
|
||||
use Modules\Emails\Template;
|
||||
use Notifications\EmailNotification;
|
||||
|
||||
class RapportinoIntervento extends Resource implements RetrieveInterface, CreateInterface
|
||||
{
|
||||
public function retrieve($request)
|
||||
{
|
||||
$database = database();
|
||||
$id_record = $request['id'];
|
||||
|
||||
$template = Template::where('name', 'Rapportino intervento')->first();
|
||||
$module = $template->module;
|
||||
|
||||
$body = $module->replacePlaceholders($id_record, $template['body']);
|
||||
$subject = $module->replacePlaceholders($id_record, $template['subject']);
|
||||
$email = $module->replacePlaceholders($id_record, '{email}');
|
||||
|
||||
$prints = $database->fetchArray('SELECT id, title, EXISTS(SELECT id_print FROM em_print_template WHERE id_template = '.prepare($template['id']).' AND em_print_template.id_print = zz_prints.id) AS selected FROM zz_prints WHERE id_module = '.prepare($module->id).' AND enabled = 1');
|
||||
|
||||
return [
|
||||
'email' => $email,
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
'prints' => $prints,
|
||||
'read_notify' => $template->read_notify,
|
||||
];
|
||||
}
|
||||
|
||||
public function create($request)
|
||||
{
|
||||
$data = $request['data'];
|
||||
$id_record = $data['id'];
|
||||
|
||||
$template = Template::where('name', 'Rapportino intervento')->first();
|
||||
$mail = Mail::build($this->getUser(), $template, $id_record);
|
||||
|
||||
// Rimozione allegati predefiniti
|
||||
$mail->resetPrints();
|
||||
|
||||
// Destinatari
|
||||
$receivers = $data['receivers'];
|
||||
foreach ($receivers as $receiver) {
|
||||
$mail->addReceiver($receiver['email'], $receiver['tipo']);
|
||||
}
|
||||
|
||||
// Contenuti
|
||||
$mail->subject = $data['subject'];
|
||||
$mail->content = $data['body'];
|
||||
$mail->read_notify = $data['read_notify'];
|
||||
|
||||
// Stampe da allegare
|
||||
$prints = $data['prints'];
|
||||
foreach ($prints as $print_id) {
|
||||
$mail->addPrint($print_id);
|
||||
}
|
||||
|
||||
$mail->save();
|
||||
|
||||
$email = EmailNotification::build($mail);
|
||||
try {
|
||||
$email_success = $email->send();
|
||||
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
||||
$email_success = false;
|
||||
}
|
||||
|
||||
return [
|
||||
'sent' => $email_success,
|
||||
];
|
||||
}
|
||||
}
|
50
src/API/App/v1/Referenti.php
Normal file
50
src/API/App/v1/Referenti.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use API\Interfaces\RetrieveInterface;
|
||||
|
||||
class Referenti extends AppResource implements RetrieveInterface
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('an_referenti', 'id', $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
|
||||
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";
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND an_referenti.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
|
||||
$query = 'SELECT id,
|
||||
idanagrafica AS id_cliente,
|
||||
IF(idsede = 0, NULL, idsede) AS id_sede,
|
||||
nome,
|
||||
mansione,
|
||||
telefono,
|
||||
email
|
||||
FROM an_referenti
|
||||
WHERE an_referenti.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
212
src/API/App/v1/RigheInterventi.php
Normal file
212
src/API/App/v1/RigheInterventi.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use API\Exceptions\InternalError;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\Interventi\Components\Articolo;
|
||||
use Modules\Interventi\Components\Riga;
|
||||
use Modules\Interventi\Components\Sconto;
|
||||
use Modules\Interventi\Intervento;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class RigheInterventi extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// 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_righe_interventi.id FROM in_righe_interventi WHERE in_righe_interventi.idintervento IN (
|
||||
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,
|
||||
]);
|
||||
|
||||
$da_interventi = array_column($records, 'id');
|
||||
$mancanti = $this->getMissingIDs('in_righe_interventi', 'id', $last_sync_at);
|
||||
|
||||
$results = array_unique(array_merge($da_interventi, $mancanti));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// 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_righe_interventi.id 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
|
||||
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
|
||||
)';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND in_righe_interventi.updated_at > '.prepare($last_sync_at);
|
||||
}
|
||||
$records = database()->fetchArray($query, [
|
||||
':period_start' => $start,
|
||||
':period_end' => $end,
|
||||
':id_tecnico' => $id_tecnico,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Individuazione riga tramite classi
|
||||
$riga = $this->getRecord($id);
|
||||
|
||||
// Generazione del record ristretto ai campi di interesse
|
||||
$record = [
|
||||
'id' => $riga->id,
|
||||
'id_intervento' => $riga->idintervento,
|
||||
'descrizione' => $riga->descrizione,
|
||||
'qta' => $riga->qta,
|
||||
'um' => $riga->um,
|
||||
'ordine' => $riga->order,
|
||||
|
||||
// Caratteristiche della riga
|
||||
'id_articolo' => $riga->idarticolo,
|
||||
'is_articolo' => intval($riga->isArticolo()),
|
||||
'is_riga' => intval($riga->isRiga()),
|
||||
'is_descrizione' => intval($riga->isDescrizione()),
|
||||
'is_sconto' => intval($riga->isSconto()),
|
||||
|
||||
// Campi contabili
|
||||
'costo_unitario' => $riga->costo_unitario,
|
||||
'prezzo_unitario' => $riga->prezzo_unitario,
|
||||
'tipo_sconto' => $riga->tipo_sconto,
|
||||
'sconto_percentuale' => $riga->sconto_percentuale,
|
||||
'sconto_unitario' => $riga->sconto_unitario,
|
||||
'id_iva' => $riga->idiva,
|
||||
'iva_unitaria' => $riga->iva_unitaria,
|
||||
'prezzo_unitario_ivato' => $riga->prezzo_unitario_ivato,
|
||||
'sconto_iva_unitario' => $riga->sconto_iva_unitario,
|
||||
'sconto_unitario_ivato' => $riga->sconto_unitario_ivato,
|
||||
|
||||
// Campi contabili di riepilogo
|
||||
'imponibile' => $riga->imponibile,
|
||||
'sconto' => $riga->sconto,
|
||||
'totale_imponibile' => $riga->totale_imponibile,
|
||||
'iva' => $riga->iva,
|
||||
'totale' => $riga->totale,
|
||||
];
|
||||
|
||||
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
|
||||
$data = database()->fetchOne('SELECT idintervento AS id_intervento,
|
||||
IF(idarticolo IS NULL OR idarticolo = 0, 0, 1) AS is_articolo,
|
||||
is_descrizione,
|
||||
is_sconto
|
||||
FROM in_righe_interventi WHERE in_righe_interventi.id = '.prepare($id));
|
||||
|
||||
// Individuazione riga tramite classi
|
||||
$type = $this->getType($data);
|
||||
$intervento = Intervento::find($data['id_intervento']);
|
||||
|
||||
return $intervento->getRiga($type, $id);
|
||||
}
|
||||
|
||||
protected function getType($data)
|
||||
{
|
||||
if (!empty($data['is_sconto'])) {
|
||||
$type = Sconto::class;
|
||||
} elseif (!empty($data['is_articolo'])) {
|
||||
$type = Articolo::class;
|
||||
} else {
|
||||
$type = Riga::class;
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
protected function aggiornaRecord($record, $data)
|
||||
{
|
||||
$record->descrizione = $data['descrizione'];
|
||||
$record->um = $data['um'] ?: null;
|
||||
|
||||
//$record->costo_unitario = $data['costo_unitario'] ?: 0;
|
||||
$record->setPrezzoUnitario($data['prezzo_unitario'], $data['id_iva']);
|
||||
$record->setSconto($data['sconto_percentuale'] ?: $data['sconto_unitario'], $data['tipo_sconto']);
|
||||
|
||||
try {
|
||||
$record->qta = $data['qta'];
|
||||
} catch (UnexpectedValueException $e) {
|
||||
throw new InternalError();
|
||||
}
|
||||
}
|
||||
}
|
61
src/API/App/v1/Sedi.php
Normal file
61
src/API/App/v1/Sedi.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class Sedi extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('an_sedi', 'id', $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
|
||||
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";
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND an_sedi.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
|
||||
$query = 'SELECT an_sedi.id,
|
||||
an_sedi.idanagrafica AS id_cliente,
|
||||
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;
|
||||
}
|
||||
}
|
172
src/API/App/v1/SessioniInterventi.php
Normal file
172
src/API/App/v1/SessioniInterventi.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Interventi\Components\Sessione;
|
||||
use Modules\Interventi\Intervento;
|
||||
|
||||
class SessioniInterventi extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
// 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_tecnici.id FROM in_interventi_tecnici
|
||||
INNER JOIN in_interventi ON in_interventi_tecnici.idintervento = in_interventi.id
|
||||
WHERE
|
||||
in_interventi.deleted_at IS NOT NULL
|
||||
OR (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,
|
||||
]);
|
||||
$da_interventi = array_column($records, 'id');
|
||||
$mancanti = $this->getMissingIDs('in_interventi_tecnici', 'id', $last_sync_at);
|
||||
|
||||
$results = array_unique(array_merge($da_interventi, $mancanti));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
// 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_tecnici.id FROM in_interventi_tecnici
|
||||
INNER JOIN in_interventi ON in_interventi_tecnici.idintervento = in_interventi.id
|
||||
WHERE
|
||||
in_interventi.deleted_at IS NULL
|
||||
AND (orario_fine BETWEEN :period_start AND :period_end AND idtecnico = :id_tecnico)';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND in_interventi_tecnici.updated_at > '.prepare($last_sync_at);
|
||||
}
|
||||
$records = database()->fetchArray($query, [
|
||||
':period_start' => $start,
|
||||
':period_end' => $end,
|
||||
':id_tecnico' => $id_tecnico,
|
||||
]);
|
||||
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
public function retrieveRecord($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT id,
|
||||
idintervento AS id_intervento,
|
||||
idtipointervento AS id_tipo_intervento,
|
||||
orario_inizio,
|
||||
orario_fine,
|
||||
km,
|
||||
|
||||
prezzo_ore_unitario AS prezzo_orario,
|
||||
IF(tipo_sconto = "UNT", sconto_unitario, sconto_unitario * prezzo_ore_unitario / 100) AS sconto_orario,
|
||||
IF(tipo_sconto = "PRC", sconto_unitario, 0) AS sconto_orario_percentuale,
|
||||
tipo_sconto AS tipo_sconto_orario,
|
||||
|
||||
prezzo_km_unitario AS prezzo_chilometrico,
|
||||
IF(tipo_scontokm = "UNT", scontokm_unitario, scontokm_unitario * prezzo_km_unitario / 100) AS sconto_chilometrico,
|
||||
IF(tipo_scontokm = "PRC", scontokm_unitario, 0) AS sconto_chilometrico_percentuale,
|
||||
tipo_sconto AS tipo_sconto_chilometrico,
|
||||
|
||||
prezzo_dirittochiamata AS prezzo_diritto_chiamata
|
||||
FROM in_interventi_tecnici
|
||||
WHERE in_interventi_tecnici.id = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function createRecord($data)
|
||||
{
|
||||
// Informazioni sull'utente
|
||||
$user = Auth::user();
|
||||
$id_tecnico = $user->id_anagrafica;
|
||||
|
||||
// Informazioni di base
|
||||
$intervento = Intervento::find($data['id_intervento']);
|
||||
$anagrafica = Anagrafica::find($id_tecnico);
|
||||
|
||||
// Creazione della sessione
|
||||
$sessione = Sessione::build($intervento, $anagrafica, $data['orario_inizio'], $data['orario_fine']);
|
||||
|
||||
$this->aggiornaSessione($sessione, $data);
|
||||
$sessione->save();
|
||||
|
||||
return [
|
||||
'id' => $sessione->id,
|
||||
];
|
||||
}
|
||||
|
||||
public function updateRecord($data)
|
||||
{
|
||||
$sessione = Sessione::find($data['id']);
|
||||
|
||||
$this->aggiornaSessione($sessione, $data);
|
||||
$sessione->save();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function deleteRecord($id)
|
||||
{
|
||||
$sessione = Sessione::find($id);
|
||||
$sessione->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna i dati della sessione sulla base dei dati caricati dall'applicazione.
|
||||
*
|
||||
* @param $sessione
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function aggiornaSessione($sessione, $data)
|
||||
{
|
||||
$id_tipo = $data['id_tipo_intervento'];
|
||||
$sessione->setTipo($id_tipo);
|
||||
|
||||
// Campi di base
|
||||
$sessione->orario_inizio = $data['orario_inizio'];
|
||||
$sessione->orario_fine = $data['orario_fine'];
|
||||
$sessione->km = $data['km'];
|
||||
|
||||
// Prezzi
|
||||
$sessione->prezzo_ore_unitario = $data['prezzo_orario'];
|
||||
$sessione->prezzo_km_unitario = $data['prezzo_chilometrico'];
|
||||
$sessione->prezzo_dirittochiamata = $data['prezzo_diritto_chiamata'];
|
||||
|
||||
// Sconto orario
|
||||
$sessione->sconto_unitario = $data['sconto_orario_percentuale'] ?: $data['sconto_orario'];
|
||||
$sessione->tipo_sconto = $data['tipo_sconto_orario'];
|
||||
|
||||
// Sconto chilometrico
|
||||
$sessione->scontokm_unitario = $data['sconto_chilometrico_percentuale'] ?: $data['sconto_chilometrico'];
|
||||
$sessione->tipo_scontokm = $data['tipo_sconto_chilometrico'];
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
43
src/API/App/v1/StatiIntervento.php
Normal file
43
src/API/App/v1/StatiIntervento.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class StatiIntervento extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('in_statiintervento', 'idstatointervento', $last_sync_at);
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT in_statiintervento.idstatointervento AS id FROM in_statiintervento';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' WHERE in_statiintervento.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
|
||||
$query = 'SELECT in_statiintervento.idstatointervento AS id,
|
||||
in_statiintervento.codice,
|
||||
in_statiintervento.descrizione,
|
||||
in_statiintervento.colore,
|
||||
in_statiintervento.is_completato
|
||||
FROM in_statiintervento
|
||||
WHERE in_statiintervento.idstatointervento = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
67
src/API/App/v1/TariffeContratti.php
Normal file
67
src/API/App/v1/TariffeContratti.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class TariffeContratti extends AppResource
|
||||
{
|
||||
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_contratti = array_column($records, 'id');
|
||||
|
||||
// Le associazioni Contratti - Tariffe per tipi non sono cancellabili a database
|
||||
// Per le ultime versioni, sono anzi sempre presenti!
|
||||
return $da_contratti;
|
||||
}
|
||||
|
||||
public function getModifiedRecords($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 = 1';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' AND co_contratti_tipiintervento.updated_at > '.prepare($last_sync_at);
|
||||
}
|
||||
|
||||
$records = database()->fetchArray($query);
|
||||
|
||||
return array_column($records, 'id');
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
45
src/API/App/v1/TariffeTecnici.php
Normal file
45
src/API/App/v1/TariffeTecnici.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class TariffeTecnici extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('in_tariffe', 'id', $last_sync_at);
|
||||
}
|
||||
|
||||
public 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');
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
46
src/API/App/v1/Tecnici.php
Normal file
46
src/API/App/v1/Tecnici.php
Normal 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
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getDeleted('an_anagrafiche', 'idanagrafica', $last_sync_at);
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
43
src/API/App/v1/TipiIntervento.php
Normal file
43
src/API/App/v1/TipiIntervento.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace API\App\v1;
|
||||
|
||||
use API\App\AppResource;
|
||||
|
||||
class TipiIntervento extends AppResource
|
||||
{
|
||||
public function getCleanupData($last_sync_at)
|
||||
{
|
||||
return $this->getMissingIDs('in_tipiintervento', 'idtipointervento', $last_sync_at);
|
||||
}
|
||||
|
||||
public function getModifiedRecords($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT in_tipiintervento.idtipointervento AS id FROM in_tipiintervento';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$query .= ' WHERE in_tipiintervento.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
|
||||
$query = 'SELECT in_tipiintervento.idtipointervento AS id,
|
||||
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);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
@ -3,11 +3,12 @@
|
||||
namespace API\Common;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
use API\Interfaces\RetrieveInterface;
|
||||
use API\Resource;
|
||||
use Models\Upload;
|
||||
use Modules;
|
||||
|
||||
class Allegato extends Resource implements CreateInterface
|
||||
class Allegato extends Resource implements RetrieveInterface, CreateInterface
|
||||
{
|
||||
public function create($request)
|
||||
{
|
||||
@ -21,9 +22,24 @@ class Allegato extends Resource implements CreateInterface
|
||||
'id_record' => $request['id'],
|
||||
], $name, $category);
|
||||
|
||||
return[
|
||||
return [
|
||||
'id' => $upload->id,
|
||||
'filename' => $upload->filename,
|
||||
];
|
||||
}
|
||||
|
||||
public function retrieve($request)
|
||||
{
|
||||
$upload = Upload::where('name', $request['name'])
|
||||
->where('id', $request['id'])
|
||||
->where('id_record', $request['id_record'])
|
||||
->first();
|
||||
if (!empty($upload)) {
|
||||
download(DOCROOT.'/'.$upload->filepath);
|
||||
}
|
||||
|
||||
return [
|
||||
'custom' => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ class Stampa extends Resource implements RetrieveInterface
|
||||
{
|
||||
public function retrieve($request)
|
||||
{
|
||||
$content = '';
|
||||
|
||||
$print = PrintTemplate::where('name', $request['name'])->first();
|
||||
if (!empty($print)) {
|
||||
$directory = DOCROOT.'/files/api';
|
||||
|
@ -40,6 +40,7 @@ class Upload extends Model
|
||||
foreach ($data as $key => $value) {
|
||||
$model->{$key} = $value;
|
||||
}
|
||||
$original_name = $model->original_name; // Fix per "original_name" variato in modo dinamico
|
||||
|
||||
// Nome fisico del file
|
||||
$directory = DOCROOT.'/'.$model->directory;
|
||||
|
@ -165,3 +165,106 @@ UPDATE `co_righe_promemoria` INNER JOIN `co_iva` ON `co_iva`.`id` = `co_righe_pr
|
||||
-- Fix namespace classi Stampa e Allegato per API
|
||||
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 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', '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'),
|
||||
-- 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-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');
|
||||
|
||||
-- Impostazioni relative all'applicazione
|
||||
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES
|
||||
(NULL, 'Google Maps API key', '', 'string', '1', 'Applicazione', 1),
|
||||
(NULL, 'Mostra prezzi', '1', 'boolean', '1', 'Applicazione', 1);
|
||||
|
||||
-- Aggiunta risorsa per il download degli allegati
|
||||
INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `enabled`) VALUES (NULL, 'v1', 'retrieve', 'allegato', 'API\\Common\\Allegato', '1');
|
||||
|
Loading…
x
Reference in New Issue
Block a user