2018-03-21 16:57:31 +01:00
|
|
|
<?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-03-21 16:57:31 +01:00
|
|
|
|
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
|
|
|
|
2018-08-21 10:11:30 +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-08-21 10:11:30 +02:00
|
|
|
}
|
2018-09-03 16:49:43 +02:00
|
|
|
|
2018-08-21 10:11:30 +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-08-21 10:11:30 +02:00
|
|
|
}
|
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'),
|
2018-08-21 10:11:30 +02:00
|
|
|
'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-03-21 16:57:31 +01:00
|
|
|
|
2018-05-11 15:56:08 +02:00
|
|
|
break;
|
2018-03-21 16:57:31 +01:00
|
|
|
|
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-03-21 16:57:31 +01:00
|
|
|
|
2018-05-30 10:06:08 +02:00
|
|
|
if (empty(Modules::getSegments($module))) {
|
2018-05-11 15:56:08 +02:00
|
|
|
$predefined = 1;
|
|
|
|
}
|
2018-03-21 16:57:31 +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-03-21 16:57:31 +01: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
|
|
|
|
2018-05-12 10:50:51 +02: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-03-21 16:57:31 +01:00
|
|
|
|
2018-05-11 15:56:08 +02:00
|
|
|
case 'delete':
|
|
|
|
$dbo->query('DELETE FROM zz_segments WHERE id='.prepare($id_record));
|
2018-03-21 16:57:31 +01:00
|
|
|
|
2018-05-11 15:56:08 +02:00
|
|
|
// TODO
|
|
|
|
// eliminare riferimento sulle fatture eventuali collegate a questo segmento?
|
2018-03-21 16:57:31 +01:00
|
|
|
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->info(tr('Segmento eliminato'));
|
2018-03-21 16:57:31 +01:00
|
|
|
|
2018-05-11 15:56:08 +02:00
|
|
|
break;
|
|
|
|
}
|