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';
|
2024-03-06 17:26:58 +01:00
|
|
|
use Modules\Iva\Aliquota;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
switch (filter('op')) {
|
|
|
|
case 'update':
|
2024-03-08 16:29:53 +01:00
|
|
|
$esente = post('esente') ?: 0;
|
2018-09-21 18:08:47 +02:00
|
|
|
$percentuale = empty($esente) ? post('percentuale') : 0;
|
2024-03-06 17:26:58 +01:00
|
|
|
$indetraibile = post('indetraibile');
|
|
|
|
$dicitura = post('dicitura');
|
|
|
|
$codice = post('codice');
|
2024-03-08 16:29:53 +01:00
|
|
|
$codice_natura_fe = post('codice_natura_fe') ?: null;
|
2024-03-06 17:26:58 +01:00
|
|
|
$esigibilita = post('esigibilita');
|
|
|
|
$descrizione = post('descrizione');
|
2018-09-21 18:08:47 +02:00
|
|
|
|
2024-04-18 17:44:05 +02:00
|
|
|
$aliquota = Aliquota::where('id', '=', (new Aliquota())->getByField('title', $descrizione))->where('codice', '=', $codice)->where('id', '!=', $iva->id)->first();
|
2024-03-06 17:26:58 +01:00
|
|
|
if (!$aliquota) {
|
|
|
|
$iva->esente = $esente;
|
|
|
|
$iva->percentuale = $percentuale;
|
|
|
|
$iva->indetraibile = $indetraibile;
|
2024-03-22 15:52:24 +01:00
|
|
|
$iva->dicitura = $dicitura ?: 0;
|
2024-03-06 17:26:58 +01:00
|
|
|
$iva->codice = $codice;
|
|
|
|
$iva->codice_natura_fe = $codice_natura_fe;
|
|
|
|
$iva->esigibilita = $esigibilita;
|
2024-04-18 17:44:05 +02:00
|
|
|
$iva->setTranslation('title', $descrizione);
|
2024-04-19 16:44:08 +02:00
|
|
|
if (Models\Locale::getDefault()->id == Models\Locale::getPredefined()->id) {
|
|
|
|
$iva->name = $descrizione;
|
2024-04-23 09:56:36 +02:00
|
|
|
}
|
2024-03-06 17:26:58 +01:00
|
|
|
$iva->save();
|
2024-02-06 17:36:05 +01:00
|
|
|
|
2018-11-09 10:49:21 +01:00
|
|
|
// Messaggio di avvertenza
|
2024-03-08 16:29:53 +01:00
|
|
|
if ((stripos('N6', (string) $codice_natura_fe) === 0) && $esigibilita == 'S') {
|
2020-11-11 11:01:50 +01:00
|
|
|
flash()->warning(tr('Combinazione di natura IVA _TYPE_ ed esigibilità non compatibile', [
|
2024-03-08 16:29:53 +01:00
|
|
|
'_TYPE_' => $codice_natura_fe,
|
2020-11-11 11:01:50 +01:00
|
|
|
]));
|
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');
|
2024-05-30 10:53:28 +02:00
|
|
|
$esente = post('esente_add');
|
2018-09-21 18:08:47 +02:00
|
|
|
$percentuale = empty($esente) ? post('percentuale') : 0;
|
2024-03-08 16:29:53 +01:00
|
|
|
$codice_natura = post('codice_natura_fe') ?: '';
|
2022-02-21 10:30:19 +01:00
|
|
|
$esigibilita = post('esigibilita');
|
|
|
|
$indetraibile = post('indetraibile');
|
|
|
|
|
2024-04-18 17:44:05 +02:00
|
|
|
$aliquota = Aliquota::where('id', '=', (new Aliquota())->getByField('title', $descrizione))->where('codice', '=', $codice)->first();
|
2024-03-06 17:26:58 +01:00
|
|
|
if (!$aliquota) {
|
|
|
|
$iva = Aliquota::build($esente, $percentuale, $indetraibile, $dicitura, $codice, $codice_natura_fe, $esigibilita);
|
2024-03-22 15:52:24 +01:00
|
|
|
$id_record = $dbo->lastInsertedID();
|
2024-04-18 17:44:05 +02:00
|
|
|
$iva->setTranslation('title', $descrizione);
|
2024-04-19 16:44:08 +02:00
|
|
|
if (Models\Locale::getDefault()->id == Models\Locale::getPredefined()->id) {
|
|
|
|
$iva->name = $descrizione;
|
2024-04-23 09:56:36 +02:00
|
|
|
}
|
2024-03-06 17:26:58 +01:00
|
|
|
$iva->save();
|
2024-03-22 15:52:24 +01:00
|
|
|
|
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':
|
2024-04-12 16:59:19 +02:00
|
|
|
if (!empty($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;
|
|
|
|
}
|