openstamanager/modules/segmenti/actions.php

128 lines
4.3 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')) {
2018-05-11 15:56:08 +02:00
case 'update':
$pattern = string_contains(post('pattern'), '#') ? post('pattern') : '####';
2018-05-11 15:56:08 +02:00
$predefined = post('predefined');
2018-09-27 12:54:57 +02:00
$module = post('module');
2018-09-27 12:54:57 +02:00
if (empty(Modules::getSegments($module))) {
2018-05-11 15:56:08 +02:00
$predefined = 1;
}
2018-03-22 15:40:20 +01:00
2018-05-11 15:56:08 +02:00
if ($predefined) {
2024-03-11 10:40:42 +01:00
$dbo->query('UPDATE `zz_segments` SET `predefined` = 0 WHERE `id_module` = '.prepare($module));
2018-05-11 15:56:08 +02:00
}
2018-09-03 16:49:43 +02:00
$predefined_accredito = post('predefined_accredito');
if ($predefined_accredito) {
2024-03-11 10:40:42 +01:00
$dbo->query('UPDATE `zz_segments` SET `predefined_accredito` = 0 WHERE `id_module` = '.prepare($module));
}
2018-09-03 16:49:43 +02:00
$predefined_addebito = post('predefined_addebito');
if ($predefined_addebito) {
2024-03-11 10:40:42 +01:00
$dbo->query('UPDATE `zz_segments` SET `predefined_addebito` = 0 WHERE `id_module` = '.prepare($module));
}
2018-03-22 15:40:20 +01:00
2018-05-30 10:06:08 +02:00
$dbo->update('zz_segments', [
2018-09-27 12:54:57 +02:00
'id_module' => $module,
2019-08-26 10:11:04 +02:00
'clause' => $_POST['clause'],
2018-05-11 15:56:08 +02:00
'pattern' => $pattern,
'note' => post('note'),
'dicitura_fissa' => post('dicitura_fissa'),
2018-05-30 10:06:08 +02:00
'position' => post('position'),
2018-05-11 15:56:08 +02:00
'predefined' => $predefined,
2018-09-27 15:50:03 +02:00
'is_fiscale' => post('is_fiscale'),
'predefined_accredito' => $predefined_accredito,
'predefined_addebito' => $predefined_addebito,
'autofatture' => post('autofatture'),
'for_fe' => post('for_fe'),
2018-05-11 15:56:08 +02:00
], ['id' => $id_record]);
2018-03-22 15:40:20 +01:00
2024-03-11 10:40:42 +01:00
$dbo->update('zz_segments_lang', [
'name' => post('name'),
], ['id_record' => $id_record, 'id_lang' => setting('Lingua')]);
// Aggiornamento dei permessi relativi
$dbo->sync('zz_group_segment', ['id_segment' => $id_record], ['id_gruppo' => (array) post('gruppi')]);
2018-07-19 17:29:21 +02:00
flash()->info(tr('Modifiche salvate correttamente'));
2018-05-11 15:56:08 +02:00
break;
2018-05-11 15:56:08 +02:00
case 'add':
$pattern = string_contains(post('pattern'), '#') ? post('pattern') : '####';
2018-05-11 15:56:08 +02:00
$predefined = post('predefined');
2018-05-30 10:06:08 +02:00
$module = post('module');
2018-05-30 10:06:08 +02:00
if (empty(Modules::getSegments($module))) {
2018-05-11 15:56:08 +02:00
$predefined = 1;
}
2018-05-11 15:56:08 +02:00
if ($predefined) {
2024-03-11 10:40:42 +01:00
$dbo->query('UPDATE `zz_segments` SET `predefined` = 0 WHERE `id_module` = '.prepare($module));
2018-05-11 15:56:08 +02:00
}
2018-05-11 15:56:08 +02:00
$dbo->insert('zz_segments', [
2018-09-27 12:54:57 +02:00
'id_module' => $module,
2018-05-11 15:56:08 +02:00
'clause' => '1=1',
'pattern' => $pattern,
'note' => post('note'),
2024-03-08 16:29:53 +01:00
'predefined' => $predefined ?: 0,
2023-08-04 14:54:28 +02:00
'is_sezionale' => post('is_sezionale'),
2018-05-11 15:56:08 +02:00
]);
2018-03-22 15:40:20 +01:00
$id_record = $dbo->lastInsertedID();
2018-03-22 15:40:20 +01:00
2024-03-11 10:40:42 +01:00
$dbo->insert('zz_segments_lang', [
'name' => post('name'),
'id_record' => $id_record,
'id_lang' => setting('Lingua'),
]);
// Aggiunta permessi segmento
$gruppi = $dbo->fetchArray('SELECT `id` FROM `zz_groups`');
$array = [];
foreach ($gruppi as $gruppo) {
$array[] = [
'id_gruppo' => $gruppo['id'],
'id_segment' => $id_record,
];
}
$dbo->insert('zz_group_segment', $array);
2018-07-19 17:29:21 +02:00
flash()->info(tr('Nuovo segmento aggiunto'));
2018-03-22 15:40:20 +01:00
2018-05-11 15:56:08 +02:00
break;
2018-05-11 15:56:08 +02:00
case 'delete':
$dbo->query('DELETE FROM zz_segments WHERE id='.prepare($id_record));
2018-05-11 15:56:08 +02:00
// TODO
// eliminare riferimento sulle fatture eventuali collegate a questo segmento?
2018-07-19 17:29:21 +02:00
flash()->info(tr('Segmento eliminato'));
2018-05-11 15:56:08 +02:00
break;
}