openstamanager/modules/stati_intervento/actions.php

89 lines
3.5 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';
2024-03-07 15:08:26 +01:00
use Modules\Interventi\Stato;
switch (post('op')) {
case 'update':
2024-03-07 15:08:26 +01:00
$descrizione = post('descrizione');
2024-04-18 17:44:05 +02:00
$stato_new = (new Stato())->getByField('title', $descrizione);
2024-03-07 15:08:26 +01:00
2024-03-22 15:52:24 +01:00
if (!empty($stato_new) && $stato_new != $id_record) {
2024-03-07 15:08:26 +01:00
flash()->error(tr('Questo nome è già stato utilizzato per un altro stato attività.'));
} else {
2024-04-19 16:44:08 +02:00
if (Models\Locale::getDefault()->id == Models\Locale::getPredefined()->id) {
$stato->name = $descrizione;
}
2024-03-07 15:08:26 +01:00
$stato->codice = post('codice');
$stato->colore = post('colore');
$stato->is_completato = post('is_completato');
$stato->is_fatturabile = post('is_fatturabile');
$stato->notifica = post('notifica');
$stato->notifica_cliente = post('notifica_cliente');
$stato->notifica_tecnico_sessione = post('notifica_tecnico_sessione');
$stato->notifica_tecnico_assegnato = post('notifica_tecnico_assegnato');
$stato->id_email = post('email') ?: null;
$stato->destinatari = post('destinatari');
2024-04-18 17:44:05 +02:00
$stato->setTranslation('title', $descrizione);
2024-03-07 15:08:26 +01:00
$stato->save();
2024-03-07 15:08:26 +01: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
2024-04-18 17:44:05 +02:00
$stato_new = Stato::find((new Stato())->getByField('title', $descrizione));
2024-03-07 15:08:26 +01:00
if ($stato_new) {
flash()->error(tr('Questo nome è già stato utilizzato per un altro stato attività.'));
2018-02-18 19:53:23 +01:00
} else {
2024-03-07 15:08:26 +01:00
$stato = Stato::build($codice, $colore);
2024-04-19 16:44:08 +02:00
if (Models\Locale::getDefault()->id == Models\Locale::getPredefined()->id) {
$stato->name = $descrizione;
}
2024-03-22 15:52:24 +01:00
$id_record = $dbo->lastInsertedID();
2024-04-18 17:44:05 +02:00
$stato->setTranslation('title', $descrizione);
2024-03-07 15:08:26 +01:00
$stato->save();
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':
2024-01-15 15:30:45 +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 `id`='.prepare($id_record).' AND `can_delete`=1';
2018-02-18 19:53:23 +01:00
} else {
$query = 'DELETE FROM `in_statiintervento` WHERE `id`='.prepare($id_record).' AND `can_delete`=1';
2018-02-18 19:53:23 +01:00
}
$dbo->query($query);
flash()->info(tr('Stato attività eliminato.'));
break;
}