Skip to content

Commit 0ff25b8

Browse files
committed
fix: aggiunta prima nota da edit prima nota
1 parent 0faa667 commit 0ff25b8

3 files changed

Lines changed: 58 additions & 24 deletions

File tree

modules/primanota/actions.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@
2727

2828
switch (post('op')) {
2929
case 'add':
30-
$data = post('data');
31-
$descrizione = post('descrizione');
30+
$data = post('data_add');
31+
$descrizione = post('descrizione_add');
3232
$is_insoluto = post('is_insoluto');
3333
$id_anagrafica = post('id_anagrafica');
3434
$chiudi_scadenza = post('chiudi_scadenza_add');
3535
$mastrino = Mastrino::build($descrizione, $data, $is_insoluto, true, $id_anagrafica);
3636

37-
$conti = post('idconto');
37+
$conti = post('idconto_add');
3838
$scadenze = [];
3939
foreach ($conti as $i => $id_conto) {
40-
$id_scadenza = post('id_scadenza')[$i];
41-
$id_documento = post('id_documento')[$i];
42-
$dare = post('dare')[$i];
43-
$avere = post('avere')[$i];
40+
$id_scadenza = post('id_scadenza_add')[$i];
41+
$id_documento = post('id_documento_add')[$i];
42+
$dare = post('dare_add')[$i];
43+
$avere = post('avere_add')[$i];
4444

4545
if (empty($dare) && empty($avere)) {
4646
continue;
@@ -84,7 +84,7 @@
8484
}
8585

8686
foreach ($conti as $i => $id_conto) {
87-
$idconto = post('idconto')[$i];
87+
$idconto = post('idconto_add')[$i];
8888
$query = 'INSERT INTO co_movimenti_modelli(idmastrino, nome, descrizione, idconto) VALUES('.prepare($idmastrino).', '.prepare($descrizione).', '.prepare($descrizione).', '.prepare($id_conto).')';
8989
$dbo->query($query);
9090
}

modules/primanota/add.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@
291291
echo '
292292
<div class="row">
293293
<div class="col-md-4">
294-
{[ "type": "date", "label": "'.tr('Data movimento').'", "name": "data", "required": 1, "value": "-now-" ]}
294+
{[ "type": "date", "label": "'.tr('Data movimento').'", "name": "data_add", "required": 1, "value": "-now-" ]}
295295
</div>
296296
297297
<div class="col-md-8">
298-
{[ "type": "text", "label": "'.tr('Causale').'", "name": "descrizione", "id": "desc", "required": 1, "value": '.json_encode($descrizione).' ]}
298+
{[ "type": "text", "label": "'.tr('Causale').'", "name": "descrizione_add", "id": "desc_add", "required": 1, "value": '.json_encode($descrizione).' ]}
299299
</div>
300300
</div>';
301301

@@ -404,11 +404,11 @@
404404
causale = causale.replace(key, value);
405405
}
406406
407-
$("#modals > div #desc").val(causale);
407+
$("#modals > div #desc_add").val(causale);
408408
}
409409
410-
if ($("#modals > div #desc").val() == "") {
411-
$("#modals > div #desc").val(causale);
410+
if ($("#modals > div #desc_add").val() == "") {
411+
$("#modals > div #desc_add").val(causale);
412412
}
413413
414414
$.get(globals.rootdir + "/ajax_complete.php?op=get_conti&idmastrino=" + id_mastrino, function(data) {

modules/primanota/movimenti.php

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@
2424

2525
function renderRiga($id, $riga, $totale_dare = null, $totale_avere = null)
2626
{
27+
global $id_record;
28+
29+
// Determina se siamo nell'add (non c'è $id_record) o nell'edit
30+
$suffix = empty($id_record) ? '_add' : '';
31+
2732
// Conto
2833
echo '
2934
<tr>
30-
<input type="hidden" name="id_documento['.$id.']" value="'.$riga['iddocumento'].'">
31-
<input type="hidden" name="id_scadenza['.$id.']" value="'.$riga['id_scadenza'].'">
35+
<input type="hidden" name="id_documento'.$suffix.'['.$id.']" value="'.$riga['iddocumento'].'">
36+
<input type="hidden" name="id_scadenza'.$suffix.'['.$id.']" value="'.$riga['id_scadenza'].'">
3237
3338
<td class="text-center" style="width:40px;">
3439
<button type="button" class="btn btn-danger btn-xs" onclick="deleteRiga(this)">
@@ -37,19 +42,19 @@ function renderRiga($id, $riga, $totale_dare = null, $totale_avere = null)
3742
</td>
3843
3944
<td>
40-
{[ "type": "select", "name": "idconto['.$id.']", "id": "conto'.$id.'", "value": "'.($riga['id_conto'] ?: '').'", "ajax-source": "conti", "icon-after": '.json_encode('<button type="button" onclick="visualizzaMovimenti(this)" class="btn btn-info '.($riga['id_conto'] ? '' : 'disabled').'"><i class="fa fa-eye"></i></button>').' ]}
45+
{[ "type": "select", "name": "idconto'.$suffix.'['.$id.']", "id": "conto'.$suffix.'_'.$id.'", "value": "'.($riga['id_conto'] ?: '').'", "ajax-source": "conti", "icon-after": '.json_encode('<button type="button" onclick="visualizzaMovimenti(this)" class="btn btn-info '.($riga['id_conto'] ? '' : 'disabled').'"><i class="fa fa-eye"></i></button>').' ]}
4146
</td>';
4247

4348
// Dare
4449
echo '
4550
<td>
46-
{[ "type": "number", "name": "dare['.$id.']", "id": "dare'.$id.'", "value": "'.($riga['dare'] ?: 0).'" ]}
51+
{[ "type": "number", "name": "dare'.$suffix.'['.$id.']", "id": "dare'.$suffix.'_'.$id.'", "value": "'.($riga['dare'] ?: 0).'" ]}
4752
</td>';
4853

4954
// Avere
5055
echo '
5156
<td>
52-
{[ "type": "number", "name": "avere['.$id.']", "id": "avere'.$id.'", "value": "'.($riga['avere'] ?: 0).'" ]}
57+
{[ "type": "number", "name": "avere'.$suffix.'['.$id.']", "id": "avere'.$suffix.'_'.$id.'", "value": "'.($riga['avere'] ?: 0).'" ]}
5358
</td>
5459
</tr>';
5560

@@ -197,12 +202,13 @@ function renderTabella($nome, $righe, $totale_dare = null, $totale_avere = null)
197202
</table>';
198203

199204
// Nuova riga
205+
$suffix = empty($id_record) ? '_add' : '';
200206
echo '
201207
<table class="table table-bordered">
202208
<tr>
203209
<th class="text-right">'.tr('Totale').'</th>
204-
<th id="totale_dare" class="text-right" width="20%">'.moneyFormat($totale_dare).'</th>
205-
<th id="totale_avere" class="text-right" width="20%">'.moneyFormat($totale_avere).'</th>
210+
<th id="totale_dare'.$suffix.'" class="text-right" width="20%">'.moneyFormat($totale_dare).'</th>
211+
<th id="totale_avere'.$suffix.'" class="text-right" width="20%">'.moneyFormat($totale_avere).'</th>
206212
</tr>
207213
</table>';
208214

@@ -334,7 +340,7 @@ function calcolaBilancio(gruppo) {
334340
// Trigger dell\'evento keyup() per la prima volta, per eseguire i dovuti controlli nel caso siano predisposte delle righe in prima nota
335341
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
336342
337-
$("select[id*=idconto]").click(function() {
343+
$("select[id*=conto]").click(function() {
338344
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
339345
});
340346
});
@@ -379,20 +385,48 @@ function calcolaBilancio(gruppo) {
379385
}
380386
});
381387
382-
$(document).on("change", "[id*=dare], [id*=avere]", function() {
388+
// Funzione per aggiornare i totali dell\'edit
389+
function aggiornaTotaliEdit() {
383390
var totalDare = 0;
384391
var totalAvere = 0;
385392
386-
$("[id*=dare]").each(function() {
393+
$("[id*=dare]:not([id*=_add_])").each(function() {
387394
totalDare += parseFloat($(this).val().toEnglish()) || 0;
388395
});
389396
390-
$("[id*=avere]").each(function() {
397+
$("[id*=avere]:not([id*=_add_])").each(function() {
391398
totalAvere += parseFloat($(this).val().toEnglish()) || 0;
392399
});
393400
394401
$("#totale_dare").text(totalDare.toLocale());
395402
$("#totale_avere").text(totalAvere.toLocale());
403+
}
404+
405+
// Funzione per aggiornare i totali dell\'add
406+
function aggiornaTotaliAdd() {
407+
var totalDare = 0;
408+
var totalAvere = 0;
409+
410+
$("[id*=dare_add_]").each(function() {
411+
totalDare += parseFloat($(this).val().toEnglish()) || 0;
412+
});
413+
414+
$("[id*=avere_add_]").each(function() {
415+
totalAvere += parseFloat($(this).val().toEnglish()) || 0;
416+
});
417+
418+
$("#totale_dare_add").text(totalDare.toLocale());
419+
$("#totale_avere_add").text(totalAvere.toLocale());
420+
}
421+
422+
// Event handler per i campi dell\'edit
423+
$(document).on("change", "[id*=dare]:not([id*=_add_]), [id*=avere]:not([id*=_add_])", function() {
424+
aggiornaTotaliEdit();
425+
});
426+
427+
// Event handler per i campi dell\'add
428+
$(document).on("change", "[id*=dare_add_], [id*=avere_add_]", function() {
429+
aggiornaTotaliAdd();
396430
});
397431
398432
function visualizzaMovimenti(button) {

0 commit comments

Comments
 (0)