2019-03-28 19:00:00 +01:00
< ? 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 />.
*/
2019-03-28 19:00:00 +01:00
include_once __DIR__ . '/../../core.php' ;
switch ( post ( 'op' )) {
case 'update' :
$dbo -> update ( 'co_staticontratti' , [
'descrizione' => ( count ( $dbo -> fetchArray ( 'SELECT descrizione FROM co_staticontratti WHERE descrizione = ' . prepare ( post ( 'descrizione' )))) > 0 ) ? $dbo -> fetchOne ( 'SELECT descrizione FROM co_staticontratti WHERE id =' . $id_record )[ 'descrizione' ] : post ( 'descrizione' ),
'icona' => post ( 'icona' ),
2023-09-27 17:04:00 +02:00
'colore' => post ( 'colore' ),
2019-03-28 19:00:00 +01:00
'is_completato' => post ( 'is_completato' ) ? : null ,
'is_fatturabile' => post ( 'is_fatturabile' ) ? : null ,
'is_pianificabile' => post ( 'is_pianificabile' ) ? : null ,
], [ 'id' => $id_record ]);
flash () -> info ( tr ( 'Informazioni salvate correttamente.' ));
break ;
case 'add' :
$descrizione = post ( 'descrizione' );
$icona = post ( 'icona' );
2023-09-27 17:04:00 +02:00
$colore = post ( 'colore' );
2019-04-04 17:30:58 +02:00
$is_completato = post ( 'is_completato' ) ? : null ;
$is_fatturabile = post ( 'is_fatturabile' ) ? : null ;
$is_pianificabile = post ( 'is_pianificabile' ) ? : null ;
2019-03-28 19:00:00 +01:00
2024-01-15 15:30:45 +01:00
// controlla descrizione che non sia duplicata
2019-03-28 19:00:00 +01:00
if ( count ( $dbo -> fetchArray ( 'SELECT descrizione FROM co_staticontratti WHERE descrizione=' . prepare ( $descrizione ))) > 0 ) {
flash () -> error ( tr ( 'Stato di contratto già esistente.' ));
} else {
2023-09-27 17:04:00 +02:00
$query = 'INSERT INTO co_staticontratti(descrizione, icona, colore, is_completato, is_fatturabile, is_pianificabile) VALUES (' . prepare ( $descrizione ) . ', ' . prepare ( $icona ) . ', ' . prepare ( $colore ) . ', ' . prepare ( $is_completato ) . ', ' . prepare ( $is_fatturabile ) . ', ' . prepare ( $is_pianificabile ) . ' )' ;
2019-03-28 19:00:00 +01:00
$dbo -> query ( $query );
$id_record = $dbo -> lastInsertedID ();
flash () -> info ( tr ( 'Nuovo stato contratto aggiunto.' ));
}
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 nei contratti
2019-03-28 19:00:00 +01:00
if ( count ( $dbo -> fetchArray ( 'SELECT id FROM co_contratti WHERE idstato=' . prepare ( $id_record ))) > 0 ) {
2019-11-14 10:22:47 +01:00
$query = 'UPDATE co_staticontratti SET deleted_at = NOW() WHERE can_delete = 1 AND id=' . prepare ( $id_record );
2019-03-28 19:00:00 +01:00
} else {
2019-11-14 10:22:47 +01:00
$query = 'DELETE FROM co_staticontratti WHERE can_delete = 1 AND id=' . prepare ( $id_record );
2019-03-28 19:00:00 +01:00
}
$dbo -> query ( $query );
flash () -> info ( tr ( 'Stato contratto eliminato.' ));
break ;
}