Aggiunti modelli prima nota

This commit is contained in:
Bacca97 2018-05-04 17:57:46 +02:00
parent 00864a0bd3
commit 8214c1d6aa
9 changed files with 337 additions and 9 deletions

View File

@ -450,11 +450,11 @@ function aggiungi_movimento($iddocumento, $dir, $primanota = 0)
/**
* Funzione per generare un nuovo codice per il mastrino.
*/
function get_new_idmastrino()
function get_new_idmastrino( $table = 'co_movimenti' )
{
global $dbo;
$query = 'SELECT MAX(idmastrino) AS maxidmastrino FROM co_movimenti';
$query = 'SELECT MAX(idmastrino) AS maxidmastrino FROM '.$table;
$rs = $dbo->fetchArray($query);
return intval($rs[0]['maxidmastrino']) + 1;

View File

@ -0,0 +1,51 @@
<?php
include_once __DIR__.'/../../core.php';
include_once $docroot.'/modules/fatture/modutil.php';
switch (post('op')) {
case 'add':
$idmastrino = get_new_idmastrino('co_movimenti_modelli');
$descrizione = post('descrizione');
for ($i = 0; $i < sizeof($post['idconto']); ++$i) {
$idconto = post('idconto')[$i];
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($descrizione).', '.prepare($idconto).')';
if ($dbo->query($query)) {
$id_record = $dbo->lastInsertedID();
}
}
break;
case 'editriga':
$idmastrino = post('idmastrino');
$descrizione = post('descrizione');
// Eliminazione prima nota
$dbo->query('DELETE FROM co_movimenti_modelli WHERE idmastrino='.prepare($idmastrino));
for ($i = 0; $i < sizeof($post['idconto']); ++$i) {
$idconto = post('idconto')[$i];
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($descrizione).', '.prepare($idconto).')';
if ($dbo->query($query)) {
$id_record = $dbo->lastInsertedID();
}
}
break;
case 'delete':
$idmastrino = post('idmastrino');
if ($idmastrino != '') {
// Eliminazione prima nota
$dbo->query('DELETE FROM co_movimenti_modelli WHERE idmastrino='.prepare($idmastrino));
$_SESSION['infos'][] = tr('Movimento eliminato!');
}
break;
}

View File

@ -0,0 +1,76 @@
<?php
include_once __DIR__.'/../../core.php';
?><form action="<?php echo ROOTDIR ?>/editor.php?id_module=<?php echo Modules::get('Modelli prima nota')['id']; ?>" 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-8">
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "required": 1, "value": "<?php echo $descrizione; ?>" ]}
</div>
</div>
<?php
// Salvo l'elenco conti in un array (per non fare il ciclo ad ogni riga)
/*
Form di aggiunta riga movimento
*/
echo '
<table class="table table-striped table-condensed table-hover table-bordered"
<tr>
<th>'.tr('Conto').'</th>
</tr>';
for ($i = 0; $i < 10; ++$i) {
($i<=1) ? $required = 1 : $required = 0;
// Conto
echo '
<tr>
<td>
{[ "type": "select", "name": "idconto['.$i.']", "value": "';
if ($i == 0) {
echo $idconto_controparte;
} elseif ($i == 1) {
echo $idconto_aziendale;
}
echo '", "ajax-source": "conti", "required": "'.$required.'" ]}
</td>';
echo '
</tr>';
}
echo '
</table>';
?>
<!-- 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>
<script type="text/javascript">
$(document).ready( function(){
$('select').on('change', function(){
if($(this).parent().parent().find('input[disabled]').length != 1){
if($(this).val()) {
$(this).parent().parent().find('input').prop("disabled", false);
}
else{
$(this).parent().parent().find('input').prop("disabled", true);
$(this).parent().parent().find('input').val("");
}
}
});
});
</script>
</form>

View File

@ -0,0 +1,94 @@
<?php
include_once __DIR__.'/../../core.php';
?><form action="" method="post" id="edit-form">
<input type="hidden" name="op" value="editriga">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="id_record" value="<?php echo $id_record; ?>">
<input type="hidden" name="idmastrino" value="<?php echo $records[0]['idmastrino']; ?>">
<input type="hidden" name="iddocumento" value="<?php echo $records[0]['iddocumento']; ?>">
<div class="row">
<div class="col-md-12">
{[ "type": "text", "label": "<?php echo tr('Causale predefinita'); ?>", "name": "descrizione", "required": 1, "value": "$descrizione$" ]}
</div>
</div>
<?php
$conti3 = []; // contenitore conti di terzo livello
$idmastrino = $records[0]['idmastrino'];
// Salvo l'elenco conti in un array (per non fare il ciclo ad ogni riga)
$query2 = 'SELECT * FROM co_pianodeiconti2';
$conti2 = $dbo->fetchArray($query2);
for ($x = 0; $x < sizeof($conti2); ++$x) {
$query3 = 'SELECT * FROM co_pianodeiconti3 WHERE idpianodeiconti2='.prepare($conti2[$x]['id']);
$rs3 = $dbo->fetchArray($query3);
for ($y = 0; $y < sizeof($rs3); ++$y) {
// Creo un array con le descrizioni dei conti di livello 3 che ha come indice l'id del livello2 e del livello3
$conti3[$rs3[$y]['idpianodeiconti2']][$y]['id'] = $rs3[$y]['id'];
$conti3[$rs3[$y]['idpianodeiconti2']][$y]['descrizione'] = $conti2[$x]['numero'].'.'.$rs3[$y]['numero'].' '.$rs3[$y]['descrizione'];
}
}
/*
Form di modifica riga movimento
*/
// Lettura movimenti del mastrino selezionato
$query = 'SELECT * FROM co_movimenti_modelli WHERE idmastrino='.prepare($records[0]['idmastrino']);
$rs = $dbo->fetchArray($query);
$n = sizeof($rs);
echo '
<table class="table table-striped table-condensed table-hover table-bordered"
<tr>
<th>'.tr('Conto').'</th>
</tr>';
for ($i = 0; $i < 10; ++$i) {
($i<=1) ? $required = 1 : $required = 0;
// Conto
echo '
<tr>
<td>
{[ "type": "select", "name": "idconto['.$i.']", "value": "'.$rs[$i]['idconto'].'", "ajax-source": "conti", "required": "'.$required.'" ]}
</td>';
echo '
</tr>';
}
// Totale per controllare sbilancio
// Verifica sbilancio
echo '
</table>';
?>
<script type="text/javascript">
$(document).ready( function(){
$('select').on('change', function(){
if($(this).parent().parent().find('input[disabled]').length != 1){
if($(this).val()) {
$(this).parent().parent().find('input').prop("disabled", false);
}
else{
$(this).parent().parent().find('input').prop("disabled", true);
$(this).parent().parent().find('input').val("");
}
}
});
});
</script>
</form>
<a class="btn btn-danger ask" data-backto="record-list" data-idmastrino="<?php echo $records[0]['idmastrino']; ?>">
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
</a>

View File

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

View File

@ -90,6 +90,19 @@ switch (post('op')) {
$dbo->query("UPDATE in_interventi SET idstatointervento=(SELECT idstatointervento FROM in_statiintervento WHERE descrizione='Fatturato') WHERE id IN (SELECT idintervento FROM co_preventivi_interventi WHERE idpreventivo=".prepare($rs2[$j]['idpreventivo']).')');
}
}
//Creo il modello di prima nota
if(post('crea_modello')=='1'){
$idmastrino = get_new_idmastrino('co_movimenti_modelli');
for ($i = 0; $i < sizeof($post['idconto']); ++$i) {
$idconto = post('idconto')[$i];
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($descrizione).', '.prepare($idconto).')';
$dbo->query($query);
}
}
break;
case 'editriga':

View File

@ -6,6 +6,7 @@ include_once __DIR__.'/../../core.php';
<input type="hidden" name="op" value="add">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="iddocumento" value="<?php echo get('iddocumento'); ?>">
<input type="hidden" name="crea_modello" id="crea_modello" value="0">
<?php
$idconto = get('idconto');
@ -108,6 +109,12 @@ include_once __DIR__.'/../../core.php';
}
}
?>
<div class="row">
<div class="col-md-12">
{[ "type": "select", "label": "<?php echo tr('Modello primanota'); ?>", "id": "modello_primanota", "required": 0, "values": "query=SELECT idmastrino AS id, descrizione FROM co_movimenti_modelli GROUP BY idmastrino", "value": "" ]}
</div>
</div>
<div class="row">
<div class="col-md-4">
@ -115,7 +122,7 @@ include_once __DIR__.'/../../core.php';
</div>
<div class="col-md-8">
{[ "type": "text", "label": "<?php echo tr('Causale'); ?>", "name": "descrizione", "required": 1, "value": "<?php echo $descrizione; ?>" ]}
{[ "type": "text", "label": "<?php echo tr('Causale'); ?>", "name": "descrizione", "id": "desc", "required": 1, "value": "<?php echo $descrizione; ?>" ]}
</div>
</div>
@ -145,7 +152,7 @@ include_once __DIR__.'/../../core.php';
echo '
<tr>
<td>
{[ "type": "select", "name": "idconto['.$i.']", "value": "';
{[ "type": "select", "name": "idconto['.$i.']", "id": "conto'.$i.'", "value": "';
if ($i == 0) {
echo $idconto_controparte;
} elseif ($i == 1) {
@ -222,7 +229,8 @@ include_once __DIR__.'/../../core.php';
<!-- 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>
<button type='button' class="btn btn-primary" id='btn_crea_modello'><i class="fa fa-plus"></i> <?php echo tr('Aggiungi e crea modello'); ?></button>
<button type="submit" class="btn btn-primary" id='btn_submit'><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
</div>
</div>
@ -239,7 +247,7 @@ include_once __DIR__.'/../../core.php';
}
else{
$(this).parent().parent().find('input').prop("disabled", true);
$(this).parent().parent().find('input').val("");
$(this).parent().parent().find('input').val("0.00");
}
}
});
@ -296,11 +304,11 @@ include_once __DIR__.'/../../core.php';
if(bilancio == 0){
$("#testo_aggiuntivo").removeClass('text-danger').html("");
$("button[type=submit]").removeClass('hide');
$("#btn_submit").removeClass('hide');
}
else{
$("#testo_aggiuntivo").addClass('text-danger').html("sbilancio di " + bilancio.toLocale() + " &euro;" );
$("button[type=submit]").addClass('hide');
$("#btn_submit").addClass('hide');
}
}
@ -310,6 +318,36 @@ include_once __DIR__.'/../../core.php';
$("select[id*=idconto]").click( function(){
$("input[id*=dare][value!=''], input[id*=avere][value!='']").keyup();
});
$('#modello_primanota').change(function(){
var idmastrino = $(this).val();
if(idmastrino!=''){
$('#btn_crea_modello').hide();
var causale = $(this).find('option:selected').text();
$('#desc').val(causale);
$.get('<?=$rootdir?>/ajax_complete.php?op=get_conti&idmastrino='+idmastrino, function(data){
var conti = data.split(',');
for(i=0;i<conti.length;i++){
var conto = conti[i].split(';');
var option = $("<option selected></option>").val(conto[0]).text(conto[1]);
$('#conto'+i).selectReset();
$('#conto'+i).append(option).trigger('change');
}
});
}else{
$('#btn_crea_modello').show();
}
});
$('#btn_crea_modello').click(function(){
$("#crea_modello").val("1");
$("#add-form").submit();
});
});
</script>
</form>

View File

@ -0,0 +1,20 @@
<?php
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'get_conti':
$idmastrino = get('idmastrino');
$conti = array();
$rs_conti = $dbo->fetchArray("SELECT *, (SELECT descrizione FROM co_pianodeiconti3 WHERE id=co_movimenti_modelli.idconto) AS descrizione_conto FROM co_movimenti_modelli WHERE idmastrino=".prepare($idmastrino)." GROUP BY id");
for($i=0;$i<sizeof($rs_conti);$i++){
$conti[$i] = $rs_conti[$i]['idconto'].";".$rs_conti[$i]['descrizione_conto'];
}
echo implode(',', $conti);
break;
}

View File

@ -31,4 +31,33 @@ UPDATE `zz_widgets` SET `enabled` = '1' WHERE `zz_widgets`.`name` = 'Rate contra
ALTER TABLE `zz_plugins` ADD `help` VARCHAR(255) NOT NULL AFTER `directory`;
-- Help text per plugin Ddt del cliente
UPDATE `zz_plugins` SET `help` = 'Righe ddt del cliente. I ddt senza righe non saranno visualizzati.' WHERE `zz_plugins`.`name` = 'Ddt del cliente';
UPDATE `zz_plugins` SET `help` = 'Righe ddt del cliente. I ddt senza righe non saranno visualizzati.' WHERE `zz_plugins`.`name` = 'Ddt del cliente';
-- Creazione tablla per modelli primanota
CREATE TABLE IF NOT EXISTS `co_movimenti_modelli` (
`id` int(11) NOT NULL,
`idmastrino` int(11) NOT NULL,
`descrizione` text NOT NULL,
`idconto` int(11) NOT NULL
);
ALTER TABLE `co_movimenti_modelli` ADD PRIMARY KEY (`id`);
ALTER TABLE `co_movimenti_modelli` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
-- Modulo modelli primanota
INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Modelli prima nota', 'Modelli prima nota', 'modelli_primanota', 'SELECT |select| FROM `co_movimenti_modelli` WHERE 1=1 GROUP BY `idmastrino` HAVING 2=2', '', 'fa fa-angle-right', '2.4.1', '2.4.1', '1', '40', '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='Modelli prima nota'), 'id', 'co_movimenti_modelli.id', '0', '1', '0', '0', NULL, NULL, '0', '0', '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='Modelli prima nota'), 'Causale predefinita', 'co_movimenti_modelli.descrizione', '1', '1', '0', '0', NULL, NULL, '1', '0', '1');
INSERT INTO `zz_group_view` (`id_gruppo`, `id_vista`) VALUES
(1, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='id' )),
(1, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='Causale predefinita' )),
(2, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='id' )),
(2, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='Causale predefinita' )),
(3, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='id' )),
(3, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='Causale predefinita' )),
(4, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='id' )),
(4, (SELECT id FROM `zz_views` WHERE id_module=(SELECT id FROM zz_modules WHERE name='Modelli prima nota') AND name='Causale predefinita' ));