Modulo per gestire le banche

This commit is contained in:
Luca 2018-03-28 17:04:10 +02:00
parent 854f6709a9
commit 9262a910d5
6 changed files with 313 additions and 2 deletions

View File

@ -0,0 +1,58 @@
<?php
include_once __DIR__.'/../../core.php';
switch (filter('op')) {
case 'update':
$nome = filter('nome');
if (isset($nome)) {
$array = [
'nome' => $nome,
'filiale' => $post['filiale'],
'IBAN' => $post['IBAN'],
'BIC' => $post['BIC'],
'idconto_vendite' => $post['idconto_vendite'],
'idconto_acquisti' => $post['idconto_acquisti'],
'note' => $post['note'],
];
if (!empty($id_record)) {
$dbo->update('co_banche', $array, ['id_record' => $id_record]);
}
$_SESSION['infos'][] = tr('Salvataggio completato!');
} else {
$_SESSION['errors'][] = tr('Ci sono stati alcuni errori durante il salvataggio!');
}
break;
case 'add':
$nome = filter('nome');
if (isset($nome)) {
$dbo->query('INSERT INTO `co_banche` (`nome`) VALUES ('.prepare($nome).')');
$id_record = $dbo->lastInsertedID();
$_SESSION['infos'][] = tr('Aggiunta nuova _TYPE_', [
'_TYPE_' => 'banca',
]);
} else {
$_SESSION['errors'][] = tr('Ci sono stati alcuni errori durante il salvataggio!');
}
break;
case 'delete':
if (!empty($id_record)) {
$dbo->query('DELETE FROM `co_banche` WHERE `id`='.prepare($id_record));
$_SESSION['infos'][] = tr('_TYPE_ eliminata con successo!', [
'_TYPE_' => 'Banca',
]);
}
break;
}

21
modules/banche/add.php Normal file
View File

@ -0,0 +1,21 @@
<?php
include_once __DIR__.'/../../core.php';
?><form action="" method="post" id="add-form">
<input type="hidden" name="op" value="add">
<input type="hidden" name="backto" value="record-edit">
<div class="row">
<div class="col-md-12">
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "value": "" ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
</div>
</div>
</form>

199
modules/banche/edit.php Normal file
View File

@ -0,0 +1,199 @@
<?php
include_once __DIR__.'/../../core.php';
?><form action="" method="post" id="edit-form">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="update">
<!-- DATI -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><?php echo tr('Dati'); ?></h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-4">
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "value": "$descrizione$" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Conto predefinito per le vendite'); ?>", "name": "idconto_vendite", "value": "$idconto_vendite$", "ajax-source": "conti" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Conto predefinito per gli acquisti'); ?>", "name": "idconto_acquisti", "value": "$idconto_acquisti$", "ajax-source": "conti" ]}
</div>
</div>
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"><?php echo tr('Rate'); ?></h3>
</div>
<div class="panel-body">
<div class="data">
<?php
$values = '';
for ($i = 1; $i <= 31; ++$i) {
$values .= '\"'.$i.'\": \"'.$i.'\"';
if ($i != 31) {
$values .= ',';
}
}
$results = $dbo->fetchArray('SELECT * FROM `co_pagamenti` WHERE descrizione='.prepare($records[0]['descrizione']).' ORDER BY `num_giorni` ASC');
$cont = 1;
foreach ($results as $result) {
echo '
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">'.tr('Rata _NUMBER_', [
'_NUMBER_' => $cont,
]).'</h3>
<a class="btn btn-danger pull-right" onclick="';
echo "if(confirm('".tr('Eliminare questo elemento?')."')){ location.href='".$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.'&op=delete_rata&id='.$result['id']."'; }";
echo '"><i class="fa fa-trash"></i> '.tr('Elimina').'</a>
</div>
<div class="box-body">
<input type="hidden" value="'.$result['id'].'" name="id[]">
<div class="row">
<div class="col-md-6">
{[ "type": "number", "label": "'.tr('Percentuale').'", "name": "percentuale[]", "value": "'.$result['prc'].'", "icon-after": "<i class=\"fa fa-percent\"></i>" ]}
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Scadenza').'", "name": "scadenza[]", "values": "list=\"1\":\"'.tr('Data fatturazione').'\",\"2\":\"'.tr('Data fatturazione fine mese').'\",\"3\":\"'.tr('Data fatturazione giorno fisso').'\",\"4\":\"'.tr('Data fatturazione fine mese (giorno fisso)').'\"", "value": "';
if ($result['giorno'] == 0) {
$select = 1;
} elseif ($result['giorno'] == -1) {
$select = 2;
} elseif ($result['giorno'] < -1) {
$select = 4;
} elseif ($result['giorno'] > 0) {
$select = 3;
}
echo $select;
echo '" ]}
</div>
</div>
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Giorno').'", "name": "giorno[]", "values": "list='.$values.'", "value": "';
if ($result['giorno'] != 0 && $result['giorno'] != -1) {
echo ($result['giorno'] < -1) ? -$result['giorno'] - 1 : $result['giorno'];
}
echo '", "extra": "';
if ($result['giorno'] == 0 || $result['giorno'] == -1) {
echo ' disabled';
}
echo '" ]}
</div>
<div class="col-md-6">
{[ "type": "number", "label": "'.tr('Distanza in giorni').'", "name": "distanza[]", "decimals": "0", "value": "'.$result['num_giorni'].'" ]}
</div>
</div>
</div>
</div>';
++$cont;
}
?>
</div>
<div class="pull-right">
<button type="button" class="btn btn-info" id="add"><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
<button type="submit" class="btn btn-success"><i class="fa fa-check"></i> <?php echo tr('Salva'); ?></button>
</div>
</div>
</div>
</form>
<div class="box box-warning box-solid text-center hide" id="wait">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-warning"></i> <?php echo tr('Attenzione!'); ?></h3>
</div>
<div class="box-body">
<p><?php echo tr('Prima di poter continuare con il salvataggio è necessario che i valori percentuali raggiungano in totale il 100%'); ?>.</p>
</div>
</div>
<a class="btn btn-danger ask" data-backto="record-list">
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
</a>
<?php
echo '
<form class="hide" id="template">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">'.tr('Nuova rata').'</h3>
</div>
<div class="box-body">
<input type="hidden" value="" name="id[]">
<div class="row">
<div class="col-md-6">
{[ "type": "number", "label": "'.tr('Percentuale').'", "name": "percentuale[]", "icon-after": "<i class=\"fa fa-percent\"></i>" ]}
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Scadenza').'", "name": "scadenza[]", "values": "list=\"1\":\"'.tr('Data fatturazione').'\",\"2\":\"'.tr('Data fatturazione fine mese').'\",\"3\":\"'.tr('Data fatturazione giorno fisso').'\",\"4\":\"'.tr('Data fatturazione fine mese (giorno fisso)').'\"", "value": 1 ]}
</div>
</div>
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Giorno').'", "name": "giorno[]", "values": "list='.$values.'" ]}
</div>
<div class="col-md-6">
{[ "type": "number", "label": "'.tr('Distanza in giorni').'", "name": "distanza[]", "decimals": "0" ]}
</div>
</div>
</div>
</div>
</form>';
?>
<script>
$(document).ready(function(){
$(document).on('click', '#add', function(){
$("#template .superselect, #template_filter .superselectajax").select2().select2("destroy");
$(this).parent().parent().find('.data').append($('#template').html());
start_superselect();
});
$(document).on('change', '[id*=scadenza]', function(){
if($(this).val() == 1 || $(this).val() == 2){
$(this).parentsUntil('.box').find('[id*=giorno]').prop('disabled', true);
}else{
$(this).parentsUntil('.box').find('[id*=giorno]').prop('disabled', false);
}
});
$('#edit-form').submit(function(event) {
var tot = 0;
$(this).find('[id*=percentuale]').each(function(){
prc = $(this).val().toEnglish();
prc = !isNaN(prc) ? prc : 0;
tot += prc;
});
if(tot != 100) {
$('#wait').removeClass("hide");
event.preventDefault();
}
});
});
</script>

7
modules/banche/init.php Normal file
View File

@ -0,0 +1,7 @@
<?php
include_once __DIR__.'/../../core.php';
if (isset($id_record)) {
$records = $dbo->fetchArray('SELECT * FROM `co_banche` WHERE id='.prepare($id_record));
}

View File

@ -65,8 +65,8 @@ switch (filter('op')) {
break;
case 'delete':
if (isset($id_record)) {
$dbo->query('DELETE FROM `co_pagamenti` WHERE `descrizione`='.prepare($records[0]['descrizione']));
if (!empty($id_record)) {
$dbo->query('DELETE FROM `co_pagamenti` WHERE `id`='.prepare($id_record));
$_SESSION['infos'][] = tr('Tipologia di _TYPE_ eliminata con successo!', [
'_TYPE_' => 'pagamento',
]);

View File

@ -307,3 +307,29 @@ UPDATE `zz_group_module` SET `enabled` = '0' WHERE `zz_group_module`.`id` = 2;
-- Disattivazione funzionalità in attesa di approfondire alcuni problemi di rallentamento e ottimizzazione performance
UPDATE `zz_settings` SET `valore` = '0' WHERE `nome` = 'Attiva notifica di presenza utenti sul record';
-- Tabella co_banche
CREATE TABLE IF NOT EXISTS `co_banche` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(255) NOT NULL,
`filiale` varchar(255) NOT NULL,
`iban` varchar(50) NOT NULL,
`id_pianodeiconti3` int(11) DEFAULT NULL,
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1 ;
-- Innesto modulo per gestione banche
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Banche', 'Banche', 'banche', 'SELECT |select| FROM `co_banche` WHERE 1=1 AND deleted = 0 GROUP BY `nome` HAVING 2=2', '', 'fa fa-university', '2.4', '2.4', '1', (SELECT `id` FROM `zz_modules` m WHERE `name` = 'Tabelle'), '1', '1');
INSERT INTO `zz_views` (`id`, `id_module`, `name`, `query`, `order`, `search`, `slow`, `format`, `search_inside`, `order_by`, `enabled`, `summable`, `default`) VALUES
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche'), 'id', 'co_banche.id', 0, 0, 0, 0, '', '', 1, 0, 0),
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche'), 'Nome', 'co_banche.nome', 0, 0, 0, 0, '', '', 1, 0, 0),
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche'), 'Filiale', 'co_banche.filiale', 0, 0, 0, 0, '', '', 1, 0, 0),
(NULL, (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche'), 'IBAN', 'co_banche.iban', 0, 0, 0, 0, '', '', 1, 0, 0);
INSERT INTO `zz_group_view` (`id_gruppo`, `id_vista`) VALUES
((SELECT `id` FROM `zz_groups` WHERE `nome` = 'Amministratori'), (SELECT `id` FROM `zz_views` WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche') AND `name` = 'id')),
((SELECT `id` FROM `zz_groups` WHERE `nome` = 'Amministratori'), (SELECT `id` FROM `zz_views` WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche') AND `name` = 'Nome')),
((SELECT `id` FROM `zz_groups` WHERE `nome` = 'Amministratori'), (SELECT `id` FROM `zz_views` WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche') AND `name` = 'Filiale')),
((SELECT `id` FROM `zz_groups` WHERE `nome` = 'Amministratori'), (SELECT `id` FROM `zz_views` WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Banche') AND `name` = 'IBAN'));