openstamanager/modules/modelli_primanota/actions.php

88 lines
3.0 KiB
PHP
Raw Normal View History

2018-05-04 17:57:46 +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/>.
*/
2018-05-04 17:57:46 +02:00
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'add':
$idmastrino = get_new_idmastrino('co_movimenti_modelli');
$descrizione = post('descrizione');
$nome = post('nome');
2018-05-04 17:57:46 +02:00
2018-07-19 15:33:32 +02:00
for ($i = 0; $i < sizeof(post('idconto')); ++$i) {
2018-05-04 17:57:46 +02:00
$idconto = post('idconto')[$i];
$dare = post('dare')[$i];
$avere = post('avere')[$i];
2019-04-12 01:11:32 +02:00
if (!empty($idconto)) {
2021-02-18 18:48:44 +01:00
if (!empty($dare)) {
$totale = $dare;
} else {
$totale = -$avere;
}
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto, totale) VALUES('.prepare($idmastrino).', '.prepare($nome).', '.prepare($descrizione).', '.prepare($idconto).', '.prepare($totale).')';
if ($dbo->query($query)) {
$id_record = $idmastrino;
}
2018-05-04 17:57:46 +02:00
}
}
break;
case 'editriga':
$idmastrino = post('idmastrino');
$descrizione = post('descrizione');
$nome = post('nome');
2018-05-04 17:57:46 +02:00
// Eliminazione prima nota
$dbo->query('DELETE FROM co_movimenti_modelli WHERE idmastrino='.prepare($idmastrino));
2018-07-19 15:33:32 +02:00
for ($i = 0; $i < sizeof(post('idconto')); ++$i) {
2018-05-04 17:57:46 +02:00
$idconto = post('idconto')[$i];
$dare = post('dare')[$i];
$avere = post('avere')[$i];
2019-04-12 01:11:32 +02:00
if (!empty($idconto)) {
2021-02-18 18:48:44 +01:00
if (!empty($dare)) {
$totale = $dare;
} else {
$totale = -$avere;
}
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto, totale) VALUES('.prepare($idmastrino).', '.prepare($nome).', '.prepare($descrizione).', '.prepare($idconto).', '.prepare($totale).')';
if ($dbo->query($query)) {
$id_record = $idmastrino;
}
2018-05-04 17:57:46 +02:00
}
}
break;
case 'delete':
$idmastrino = post('idmastrino');
2018-05-11 15:56:08 +02:00
if (!empty($idmastrino)) {
2018-05-04 17:57:46 +02:00
// Eliminazione prima nota
$dbo->query('DELETE FROM co_movimenti_modelli WHERE idmastrino='.prepare($idmastrino));
2018-07-19 17:29:21 +02:00
flash()->info(tr('Movimento eliminato!'));
2018-05-04 17:57:46 +02:00
}
2018-05-11 15:56:08 +02:00
2018-05-04 17:57:46 +02:00
break;
}