openstamanager/modules/stati_intervento/actions.php

74 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'update':
$dbo->update('in_statiintervento', [
2020-01-14 17:20:19 +01:00
'codice' => post('codice'),
'descrizione' => post('descrizione'),
'colore' => post('colore'),
'is_completato' => post('is_completato'),
'is_fatturabile' => post('is_fatturabile'),
'notifica' => post('notifica'),
'notifica_cliente' => post('notifica_cliente'),
'notifica_tecnici' => post('notifica_tecnici'),
2018-10-26 19:33:45 +02:00
'id_email' => post('email') ?: null,
'destinatari' => post('destinatari'),
], ['idstatointervento' => $id_record]);
2018-07-19 17:29:21 +02:00
flash()->info(tr('Informazioni salvate correttamente.'));
break;
case 'add':
2020-01-14 17:20:19 +01:00
$codice = post('codice');
$descrizione = post('descrizione');
$colore = post('colore');
2018-02-18 19:53:23 +01:00
2020-01-14 17:20:19 +01:00
//controllo che il codice non sia duplicato
if (count($dbo->fetchArray('SELECT idstatointervento FROM in_statiintervento WHERE codice='.prepare($codice))) > 0) {
flash()->warning(tr('Attenzione: lo stato attività _COD_ risulta già esistente.', [
'_COD_' => $codice,
]));
2018-02-18 19:53:23 +01:00
} else {
2020-01-14 17:20:19 +01:00
$query = 'INSERT INTO in_statiintervento(codice, descrizione, colore) VALUES ('.prepare($codice).', '.prepare($descrizione).', '.prepare($colore).')';
2018-02-18 19:53:23 +01:00
$dbo->query($query);
2019-07-08 16:45:00 +02:00
$id_record = $database->lastInsertedID();
2020-01-14 17:20:19 +01:00
flash()->info(tr('Nuovo stato attività aggiunto.'));
2018-02-18 19:53:23 +01:00
}
break;
case 'delete':
2018-02-18 19:53:23 +01:00
//scelgo se settare come eliminato o cancellare direttamente la riga se non è stato utilizzato negli interventi
if (count($dbo->fetchArray('SELECT id FROM in_interventi WHERE idstatointervento='.prepare($id_record))) > 0) {
$query = 'UPDATE in_statiintervento SET deleted_at = NOW() WHERE idstatointervento='.prepare($id_record).' AND `can_delete`=1';
2018-02-18 19:53:23 +01:00
} else {
$query = 'DELETE FROM in_statiintervento WHERE idstatointervento='.prepare($id_record).' AND `can_delete`=1';
}
$dbo->query($query);
flash()->info(tr('Stato attività eliminato.'));
break;
}