1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-11 16:06:20 +01:00
openstamanager/modules/scadenzario/actions.php

96 lines
3.4 KiB
PHP
Raw 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
* Copyright (C) DevCode s.n.c.
*
* 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';
switch (post('op')) {
case 'add':
2019-05-04 00:32:28 +02:00
$data = post('data');
$tipo = post('tipo');
$da_pagare = post('da_pagare');
$descrizione = post('descrizione');
2019-07-31 18:22:35 +02:00
$dbo->query('INSERT INTO co_scadenziario(descrizione, tipo, data_emissione, scadenza, da_pagare, pagato) VALUES('.prepare($descrizione).', '.prepare($tipo).', CURDATE(), '.prepare($data).', '.prepare(-$da_pagare).", '0')");
$id_record = $dbo->lastInsertedID();
2019-05-04 00:32:28 +02:00
flash()->info(tr('Scadenza inserita!'));
break;
case 'update':
2019-07-25 18:05:47 +02:00
$tipo = post('tipo');
$descrizione = post('descrizione');
$iddocumento = post('iddocumento') ?: 0;
2019-09-28 11:25:20 +02:00
$totale_pagato = 0;
$id_scadenza_non_completa = null;
foreach (post('da_pagare') as $id => $da_pagare) {
$pagato = post('pagato')[$id];
$scadenza = post('scadenza')[$id];
$data_concordata = post('data_concordata')[$id];
$pagato = floatval($pagato);
$da_pagare = floatval($da_pagare);
$totale_pagato = sum($totale_pagato, $pagato);
$id_scadenza = post('id_scadenza')[$id];
if (!empty($id_scadenza)) {
$database->update('co_scadenziario', [
'descrizione' => $descrizione,
'da_pagare' => $da_pagare,
'pagato' => $pagato,
'scadenza' => $scadenza,
'data_concordata' => $data_concordata,
2020-01-28 14:20:14 +01:00
'note' => post('note'),
], ['id' => $id_scadenza]);
if ($da_pagare == 0) {
$database->delete('co_scadenziario', ['id' => $id]);
2019-09-28 11:25:20 +02:00
}
} else {
$database->insert('co_scadenziario', [
'descrizione' => $descrizione,
'tipo' => $tipo,
'iddocumento' => $iddocumento,
'da_pagare' => $da_pagare,
'pagato' => $pagato,
'scadenza' => $scadenza,
'data_concordata' => $data_concordata,
'data_emissione' => date('Y-m-d'),
2020-01-28 14:20:14 +01:00
'note' => post('note'),
]);
$id_scadenza = $database->lastInsertedID();
}
2019-09-28 11:25:20 +02:00
if ($pagato != $da_pagare) {
$id_scadenza_non_completa = $id_scadenza;
}
}
flash()->info(tr('Scadenze aggiornate!'));
2019-09-28 11:25:20 +02:00
break;
2019-05-04 00:32:28 +02:00
case 'delete':
$dbo->query("DELETE FROM co_scadenziario WHERE id='".$id_record."'");
flash()->info(tr('Scadenza eliminata!'));
break;
}