From 09b016abd8af6ae9293238b5cdfc7242a0fd69c8 Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Mon, 21 Feb 2022 16:39:25 +0100 Subject: [PATCH] Aggiunta gestione righe dinamiche per i modelli prima nota --- modules/modelli_primanota/add.php | 153 ++++++++++++++++++++--------- modules/modelli_primanota/edit.php | 148 ++++++++++++++++++---------- 2 files changed, 198 insertions(+), 103 deletions(-) diff --git a/modules/modelli_primanota/add.php b/modules/modelli_primanota/add.php index fafa65c4f..719f724a2 100755 --- a/modules/modelli_primanota/add.php +++ b/modules/modelli_primanota/add.php @@ -19,6 +19,40 @@ include_once __DIR__.'/../../core.php'; +function renderRiga($id, $riga) +{ + // Conto + echo ' + + + {[ "type": "select", "name": "idconto['.$id.']", "id": "conto'.$id.'", "value": "'.($riga['idconto'] ?: '').'", "ajax-source": "conti-modelliprimanota" ]} + '; + + // Dare + echo ' + + {[ "type": "number", "name": "dare['.$id.']", "id": "dare'.$id.'", "value": "'.($riga['totale'] > 0 ? abs($riga['totale']) : 0).'" ]} + '; + + // Avere + echo ' + + {[ "type": "number", "name": "avere['.$id.']", "id": "avere'.$id.'", "value": "'.($riga['totale'] < 0 ? abs($riga['totale']) : 0).'" ]} + + '; +} + +// Nuova riga +echo ' + + '; + +renderRiga('-id-', null); + +echo ' + +
'; + ?>
@@ -41,6 +75,10 @@ include_once __DIR__.'/../../core.php'; Form di aggiunta riga movimento */ echo ' + +

@@ -48,25 +86,11 @@ include_once __DIR__.'/../../core.php'; '; - for ($i = 0; $i < 10; ++$i) { - $required = ($i <= 1) ? 1 : 0; + $counter = 0; - // Conto - echo ' - - - - - - - '; - } + foreach ($rs as $r) { + renderRiga($counter++, $r); + } echo '
'.tr('Conto').''.tr('Avere').'
- {[ "type": "select", "name": "idconto['.$i.']", "ajax-source": "conti", "required": "'.$required.'" ]} - - {[ "type": "number", "name": "dare['.$i.']", "id": "dare'.$id.'", "value": "'.($rs[$i]['totale'] > 0 ? $rs[$i]['totale'] : '').'"]} - - {[ "type": "number", "name": "avere['.$i.']", "id": "avere'.$id.'", "value": "'.($rs[$i]['totale'] < 0 ? abs($rs[$i]['totale']) : '').'"]} -
'; @@ -110,41 +134,72 @@ include_once __DIR__.'/../../core.php';
\ No newline at end of file diff --git a/modules/modelli_primanota/edit.php b/modules/modelli_primanota/edit.php index 364b02f01..aa03a86d7 100755 --- a/modules/modelli_primanota/edit.php +++ b/modules/modelli_primanota/edit.php @@ -19,6 +19,40 @@ include_once __DIR__.'/../../core.php'; +function renderRiga($id, $riga) +{ + // Conto + echo ' + + + {[ "type": "select", "name": "idconto['.$id.']", "id": "conto'.$id.'", "value": "'.($riga['idconto'] ?: '').'", "ajax-source": "conti-modelliprimanota" ]} + '; + + // Dare + echo ' + + {[ "type": "number", "name": "dare['.$id.']", "id": "dare'.$id.'", "value": "'.($riga['totale'] > 0 ? abs($riga['totale']) : 0).'" ]} + '; + + // Avere + echo ' + + {[ "type": "number", "name": "avere['.$id.']", "id": "avere'.$id.'", "value": "'.($riga['totale'] < 0 ? abs($riga['totale']) : 0).'" ]} + + '; +} + +// Nuova riga +echo ' + + '; + +renderRiga('-id-', null); + +echo ' + +
'; + ?>
@@ -58,6 +92,10 @@ for ($x = 0; $x < sizeof($conti2); ++$x) { Form di modifica riga movimento */ echo ' + +

@@ -67,24 +105,10 @@ echo ' // Lettura movimenti del mastrino selezionato $rs = $dbo->fetchArray('SELECT * FROM co_movimenti_modelli WHERE idmastrino='.prepare($record['idmastrino'])); -for ($i = 0; $i < 10; ++$i) { - $required = ($i <= 1) ? 1 : 0; +$counter = 0; - // Conto - echo ' - - - - - - - '; +foreach ($rs as $r) { + renderRiga($counter++, $r); } echo ' @@ -92,49 +116,65 @@ echo ' ?> - + }); + + $(document).on("change", "select", function() { + let row = $(this).parent().parent(); + + if (row.find("input[disabled]").length > 1) { + row.find("input").prop("disabled", !$(this).val()); + } + }); + + $(document).on("keyup change", "input[id*=dare]", function() { + let row = $(this).parent().parent(); + + if (!$(this).prop("disabled")) { + row.find("input[id*=avere]").prop("disabled", $(this).val().toEnglish()); + } + }); + + $(document).on("keyup change", "input[id*=avere]", function() { + let row = $(this).parent().parent(); + + if (!$(this).prop("disabled")) { + row.find("input[id*=dare]").prop("disabled", $(this).val().toEnglish()); + } + }); + + var n = ; + function addRiga(btn) { + var raggruppamento = $(btn).parent(); + cleanup_inputs(); + + var tabella = raggruppamento.find("tbody"); + var content = $("#template").html(); + var text = replaceAll(content, "-id-", "" + n); + tabella.append(text); + + restart_inputs(); + n++; + } + + $(document).ready(init); +
'.tr('Conto').'
- {[ "type": "select", "name": "idconto['.$i.']", "value": "'.$rs[$i]['idconto'].'", "ajax-source": "conti-modelliprimanota", "required": "'.$required.'" ]} - - {[ "type": "number", "name": "dare['.$i.']", "id": "dare'.$id.'", "value": "'.($rs[$i]['totale'] > 0 ? $rs[$i]['totale'] : '').'"]} - - {[ "type": "number", "name": "avere['.$i.']", "id": "avere'.$id.'", "value": "'.($rs[$i]['totale'] < 0 ? abs($rs[$i]['totale']) : '').'"]} -