2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
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;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
switch (post('op')) {
|
|
|
|
case 'add':
|
2018-07-19 15:33:32 +02:00
|
|
|
$data = post('data');
|
2017-08-04 16:28:16 +02:00
|
|
|
$descrizione = post('descrizione');
|
2019-07-31 18:22:35 +02:00
|
|
|
$is_insoluto = post('is_insoluto');
|
|
|
|
|
2019-08-01 10:08:34 +02:00
|
|
|
$mastrino = Mastrino::build($descrizione, $data, $is_insoluto, true);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-07-25 12:54:28 +02:00
|
|
|
$conti = post('idconto');
|
|
|
|
foreach ($conti as $i => $id_conto) {
|
|
|
|
$id_scadenza = post('id_scadenza')[$i];
|
2018-07-19 15:33:32 +02:00
|
|
|
$dare = post('dare')[$i];
|
|
|
|
$avere = post('avere')[$i];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-07-31 18:22:35 +02:00
|
|
|
$scadenza = Scadenza::find($id_scadenza);
|
2019-07-25 12:54:28 +02:00
|
|
|
|
2019-08-01 10:08:34 +02:00
|
|
|
$movimento = Movimento::build($mastrino, $id_conto, $scadenza);
|
2019-07-31 18:22:35 +02:00
|
|
|
$movimento->setTotale($avere, $dare);
|
|
|
|
$movimento->save();
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-08-01 10:08:34 +02:00
|
|
|
$mastrino->aggiornaScadenzario();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
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'))) {
|
2019-01-06 14:18:48 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($i = 0; $i < sizeof(post('idconto')); ++$i) {
|
|
|
|
$idconto = post('idconto')[$i];
|
2019-04-11 16:04:08 +02:00
|
|
|
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($descrizione).', '.prepare($descrizione).', '.prepare($idconto).')';
|
2019-01-06 14:18:48 +01:00
|
|
|
$dbo->query($query);
|
|
|
|
}
|
2018-05-04 17:57:46 +02:00
|
|
|
}
|
2018-06-26 09:41:43 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
break;
|
|
|
|
|
2019-07-31 18:22:35 +02:00
|
|
|
case 'update':
|
2018-07-19 15:33:32 +02:00
|
|
|
$data = post('data');
|
2017-08-04 16:28:16 +02:00
|
|
|
$descrizione = post('descrizione');
|
|
|
|
|
2019-08-01 10:08:34 +02:00
|
|
|
$mastrino->descrizione = $descrizione;
|
|
|
|
$mastrino->data = $data;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
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];
|
2018-07-19 15:33:32 +02:00
|
|
|
$dare = post('dare')[$i];
|
|
|
|
$avere = post('avere')[$i];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-07-31 18:22:35 +02:00
|
|
|
$scadenza = Scadenza::find($id_scadenza);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-08-01 10:08:34 +02:00
|
|
|
$movimento = Movimento::build($mastrino, $id_conto, $scadenza);
|
2019-07-31 18:22:35 +02:00
|
|
|
$movimento->setTotale($avere, $dare);
|
|
|
|
$movimento->save();
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2019-08-01 10:08:34 +02:00
|
|
|
$mastrino->aggiornaScadenzario();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-07-31 18:22:35 +02:00
|
|
|
flash()->info(tr('Movimento modificato in prima nota!'));
|
2017-08-04 16:28:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
// eliminazione movimento prima nota
|
|
|
|
case 'delete':
|
2019-08-01 10:08:34 +02:00
|
|
|
$mastrino->delete();
|
2017-08-04 16:28:16 +02:00
|
|
|
break;
|
|
|
|
}
|