openstamanager/modules/segmenti/actions.php

101 lines
3.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) {
2018-09-27 12:54:57 +02: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) {
2018-09-27 12:54:57 +02: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) {
2018-09-27 12:54:57 +02: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,
2018-05-11 15:56:08 +02:00
'name' => post('name'),
2019-08-26 10:11:04 +02:00
'clause' => $_POST['clause'],
2018-05-11 15:56:08 +02:00
'pattern' => $pattern,
'note' => post('note'),
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,
2018-05-11 15:56:08 +02:00
], ['id' => $id_record]);
2018-03-22 15:40:20 +01:00
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) {
2018-09-27 12:54:57 +02: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
'name' => post('name'),
'clause' => '1=1',
'pattern' => $pattern,
'note' => post('note'),
'predefined' => $predefined,
]);
2018-03-22 15:40:20 +01:00
$id_record = $dbo->lastInsertedID();
2018-03-22 15:40:20 +01:00
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;
}