openstamanager/modules/primanota/actions.php

109 lines
3.7 KiB
PHP
Raw Permalink 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';
2020-08-10 10:20:22 +02:00
use Modules\Fatture\Fattura;
2019-08-01 10:08:34 +02:00
use Modules\PrimaNota\Mastrino;
2019-08-01 15:43:19 +02:00
use Modules\PrimaNota\Movimento;
2019-07-31 18:22:35 +02:00
use Modules\Scadenzario\Scadenza;
switch (post('op')) {
case 'add':
2018-07-19 15:33:32 +02:00
$data = post('data');
$descrizione = post('descrizione');
2019-07-31 18:22:35 +02:00
$is_insoluto = post('is_insoluto');
$id_anagrafica = post('id_anagrafica');
$mastrino = Mastrino::build($descrizione, $data, $is_insoluto, true, $id_anagrafica);
2019-07-25 12:54:28 +02:00
$conti = post('idconto');
foreach ($conti as $i => $id_conto) {
$id_scadenza = post('id_scadenza')[$i];
2020-08-10 10:20:22 +02:00
$id_documento = post('id_documento')[$i];
2018-07-19 15:33:32 +02:00
$dare = post('dare')[$i];
$avere = post('avere')[$i];
2019-07-31 18:22:35 +02:00
$scadenza = Scadenza::find($id_scadenza);
2020-08-10 10:20:22 +02:00
$fattura = Fattura::find($id_documento);
2019-07-25 12:54:28 +02:00
2020-08-10 10:20:22 +02:00
$movimento = Movimento::build($mastrino, $id_conto, $fattura, $scadenza);
2019-07-31 18:22:35 +02:00
$movimento->setTotale($avere, $dare);
$movimento->save();
}
2019-08-01 10:08:34 +02:00
$mastrino->aggiornaScadenzario();
2019-08-01 10:08:34 +02:00
$id_record = $mastrino->id;
2018-06-26 09:41:43 +02:00
2019-07-25 12:54:28 +02:00
flash()->info(tr('Movimento aggiunto in prima nota!'));
2018-06-26 09:41:43 +02:00
2019-07-25 12:54:28 +02:00
// Creo il modello di prima nota
2019-01-04 13:27:58 +01:00
if (!empty(post('crea_modello'))) {
if (empty(post('idmastrino'))) {
$idmastrino = get_new_idmastrino('co_movimenti_modelli');
} else {
$dbo->query('DELETE FROM co_movimenti_modelli WHERE idmastrino='.prepare(post('idmastrino')));
$idmastrino = post('idmastrino');
}
2020-02-16 12:54:34 +01:00
foreach ($conti as $i => $id_conto) {
$idconto = post('idconto')[$i];
2020-02-16 12:54:34 +01:00
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($descrizione).', '.prepare($descrizione).', '.prepare($id_conto).')';
$dbo->query($query);
}
2018-05-04 17:57:46 +02:00
}
2018-06-26 09:41:43 +02:00
break;
2019-07-31 18:22:35 +02:00
case 'update':
2018-07-19 15:33:32 +02:00
$data = post('data');
$descrizione = post('descrizione');
2020-10-06 12:29:14 +02:00
$note = post('note');
2019-08-01 10:08:34 +02:00
$mastrino->descrizione = $descrizione;
$mastrino->data = $data;
2020-10-06 12:29:14 +02:00
$mastrino->note = $note;
2019-08-01 10:08:34 +02:00
$mastrino->cleanup();
2019-04-12 09:20:23 +02:00
2019-07-31 18:22:35 +02:00
$conti = post('idconto');
foreach ($conti as $i => $id_conto) {
$id_scadenza = post('id_scadenza')[$i];
2020-08-10 10:20:22 +02:00
$id_documento = post('id_documento')[$i];
2018-07-19 15:33:32 +02:00
$dare = post('dare')[$i];
$avere = post('avere')[$i];
2019-07-31 18:22:35 +02:00
$scadenza = Scadenza::find($id_scadenza);
2020-08-10 10:20:22 +02:00
$fattura = Fattura::find($id_documento);
2020-08-10 10:20:22 +02:00
$movimento = Movimento::build($mastrino, $id_conto, $fattura, $scadenza);
2019-07-31 18:22:35 +02:00
$movimento->setTotale($avere, $dare);
$movimento->save();
}
2019-08-01 10:08:34 +02:00
$mastrino->aggiornaScadenzario();
2019-07-31 18:22:35 +02:00
flash()->info(tr('Movimento modificato in prima nota!'));
break;
// eliminazione movimento prima nota
case 'delete':
2019-08-01 10:08:34 +02:00
$mastrino->delete();
break;
}