2017-08-04 16:28:16 +02: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 />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
switch ( filter ( 'op' )) {
case 'update' :
2018-09-21 18:08:47 +02:00
$descrizione = post ( 'descrizione' );
$codice = post ( 'codice' );
$esente = post ( 'esente' );
$percentuale = empty ( $esente ) ? post ( 'percentuale' ) : 0 ;
2024-02-06 17:36:05 +01:00
if ( $dbo -> fetchNum ( 'SELECT * FROM `co_iva` LEFT JOIN `co_iva_lang` ON (`co_iva`.`id` = `co_iva_lang`.`id_record` AND `co_iva_lang`.`id_lang` = ' . prepare ( setting ( 'Lingua' )) . ') WHERE (`name` = ' . prepare ( $descrizione ) . ' AND `codice` = ' . prepare ( $codice ) . ') AND `co_iva`.`id` != ' . prepare ( $id_record )) == 0 ) {
2018-11-30 16:10:15 +01:00
$codice_natura = post ( 'codice_natura_fe' ) ? : null ;
2018-11-09 10:49:21 +01:00
$esigibilita = post ( 'esigibilita' );
2018-09-21 18:08:47 +02:00
$dbo -> update ( 'co_iva' , [
'esente' => $esente ,
'percentuale' => $percentuale ,
'indetraibile' => post ( 'indetraibile' ),
'dicitura' => post ( 'dicitura' ),
'codice' => $codice ,
2018-11-09 10:49:21 +01:00
'codice_natura_fe' => $codice_natura ,
'esigibilita' => $esigibilita ,
2018-09-21 18:08:47 +02:00
], [ 'id' => $id_record ]);
2024-02-06 17:36:05 +01:00
$dbo -> update ( 'co_iva_lang' , [
'name' => $descrizione ,
], [ 'id_record' => $id_record , 'id_lang' => setting ( 'Lingua' )]);
2018-11-09 10:49:21 +01:00
// Messaggio di avvertenza
2021-07-07 07:57:10 +02:00
if (( stripos ( 'N6' , ( string ) $codice_natura ) === 0 ) && $esigibilita == 'S' ) {
2020-11-11 11:01:50 +01:00
flash () -> warning ( tr ( 'Combinazione di natura IVA _TYPE_ ed esigibilità non compatibile' , [
'_TYPE_' => $codice_natura ,
]));
2018-11-09 10:49:21 +01:00
}
2018-09-21 18:08:47 +02:00
flash () -> info ( tr ( 'Salvataggio completato!' ));
2017-08-04 16:28:16 +02:00
} else {
2018-11-14 00:39:51 +01:00
flash () -> error ( tr ( " E' già presente una tipologia di _TYPE_ con lo stesso codice e descrizione " , [
2018-09-21 18:08:47 +02:00
'_TYPE_' => 'IVA' ,
]));
2017-08-04 16:28:16 +02:00
}
break ;
case 'add' :
2018-09-21 18:08:47 +02:00
$descrizione = post ( 'descrizione' );
2018-11-14 00:39:51 +01:00
$codice = post ( 'codice' );
2018-09-21 18:08:47 +02:00
$esente = post ( 'esente' );
$percentuale = empty ( $esente ) ? post ( 'percentuale' ) : 0 ;
2018-11-30 16:10:15 +01:00
$codice_natura = post ( 'codice_natura_fe' ) ? : null ;
2022-02-21 10:30:19 +01:00
$esigibilita = post ( 'esigibilita' );
$indetraibile = post ( 'indetraibile' );
2024-02-06 17:36:05 +01:00
if ( $dbo -> fetchNum ( 'SELECT * FROM `co_iva` LEFT JOIN `co_iva_lang` ON (`co_iva`.`id` = `co_iva_lang`.`id_record` AND `co_iva_lang`.`id_lang` = ' . prepare ( setting ( 'Lingua' )) . ') WHERE `name` = ' . prepare ( $descrizione ) . ' AND `codice` = ' . prepare ( $codice )) == 0 ) {
2018-09-21 18:08:47 +02:00
$dbo -> insert ( 'co_iva' , [
'esente' => $esente ,
2018-11-14 00:39:51 +01:00
'codice' => $codice ,
'codice_natura_fe' => $codice_natura ,
2018-09-21 18:08:47 +02:00
'percentuale' => $percentuale ,
2022-02-21 10:30:19 +01:00
'indetraibile' => $indetraibile ,
'esigibilita' => $esigibilita ,
2018-09-21 18:08:47 +02:00
]);
$id_record = $dbo -> lastInsertedID ();
2024-02-06 17:36:05 +01:00
$dbo -> insert ( 'co_iva_lang' , [
'id_record' => $id_record ,
'name' => $descrizione ,
'id_lang' => setting ( 'Lingua' ),
]);
2018-09-21 18:08:47 +02:00
flash () -> info ( tr ( 'Aggiunta nuova tipologia di _TYPE_' , [
'_TYPE_' => 'IVA' ,
]));
2017-08-04 16:28:16 +02:00
} else {
2018-11-14 00:39:51 +01:00
flash () -> error ( tr ( " E' già presente una tipologia di _TYPE_ con lo stesso codice e descrizione " , [
2018-09-21 18:08:47 +02:00
'_TYPE_' => 'IVA' ,
]));
2017-08-04 16:28:16 +02:00
}
break ;
case 'delete' :
if ( isset ( $id_record )) {
2019-01-23 15:40:37 +01:00
$dbo -> query ( 'UPDATE `co_iva` SET deleted_at = NOW() WHERE `id`=' . prepare ( $id_record ));
2017-08-04 16:28:16 +02:00
2018-11-14 00:39:51 +01:00
flash () -> info ( tr ( 'Tipologia di _TYPE_ eliminata con successo' , [
2017-09-10 14:35:41 +02:00
'_TYPE_' => 'IVA' ,
2018-07-07 13:56:22 +02:00
]));
2017-08-04 16:28:16 +02:00
}
break ;
}