openstamanager/modules/segmenti/actions.php

83 lines
2.5 KiB
PHP
Raw Normal View History

<?php
include_once __DIR__.'/../../core.php';
switch (post('op')) {
2018-05-11 15:56:08 +02:00
case 'update':
$pattern = str_contains(post('pattern'), '#') ? post('pattern') : '####';
$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'),
'clause' => post('clause'),
'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,
'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 = str_contains(post('pattern'), '#') ? post('pattern') : '####';
$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;
}