Skip to content

Commit 7bd5d9d

Browse files
committed
refactor: avviso in cambio stato fattura
1 parent 902b77a commit 7bd5d9d

1 file changed

Lines changed: 60 additions & 12 deletions

File tree

modules/fatture/edit.php

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
<?php }
303303
echo '
304304
<div class="col-md-4 col-lg-2'.($dir == 'uscita' ? ' offset-md-8 offset-lg-10' : '').'">
305-
{[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "'.$fattura->stato->id.'", "class": "'.(($fattura->stato->id != $id_stato_bozza && ! $abilita_genera) ? '' : 'unblockable').'", "extra": "onchange=\"return cambiaStato()\"" ]}
305+
{[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "'.$fattura->stato->id.'", "class": "'.(($fattura->stato->id != $id_stato_bozza && ! $abilita_genera) ? '' : 'unblockable').'" ]}
306306
</div>
307307
</div>
308308
@@ -1270,19 +1270,67 @@ function caricaRighe(id_riga) {
12701270
});
12711271
12721272
$("#barcode").focus();
1273-
});
12741273
1275-
function cambiaStato() {
1276-
let testo = $("#idstatodocumento option:selected").text();
1274+
const form = document.getElementById("edit-form");
1275+
const statoDocumento = $("#idstatodocumento");
1276+
const statoCorrente = Number('.$fattura->stato->id.');
1277+
const idStatoBozza = Number('.$id_stato_bozza.');
1278+
const statiChiusi = [
1279+
Number('.$id_stato_emessa.'),
1280+
Number('.$id_stato_pagato.'),
1281+
Number('.$id_stato_parz_pagato.'),
1282+
];
1283+
const statiPrimaNota = [
1284+
Number('.$id_stato_pagato.'),
1285+
Number('.$id_stato_parz_pagato.'),
1286+
];
1287+
1288+
function getConfigConfermaStato(nuovoStato) {
1289+
if (statiChiusi.includes(statoCorrente) && nuovoStato === idStatoBozza) {
1290+
return {
1291+
title: "'.tr('Riaprire il documento?').'",
1292+
text: "'.tr('Se riapri questo documento verrà azzerato lo scadenzario e la relativa prima nota. Continuare?').'",
1293+
type: "warning",
1294+
showCancelButton: true,
1295+
confirmButtonText: "'.tr('Procedi').'",
1296+
confirmButtonClass: "btn btn-lg btn-warning",
1297+
};
1298+
}
1299+
1300+
if (statiPrimaNota.includes(nuovoStato)) {
1301+
return {
1302+
title: "'.tr('Attenzione').'",
1303+
text: "'.tr('Sicuro di voler impostare manualmente la fattura come pagata senza aggiungere il movimento in prima nota?').'",
1304+
type: "warning",
1305+
showCancelButton: true,
1306+
confirmButtonText: "'.tr('Procedi').'",
1307+
};
1308+
}
1309+
1310+
return null;
1311+
}
1312+
1313+
$(form).on("submit", function(e) {
1314+
const config = getConfigConfermaStato(Number(statoDocumento.val()));
1315+
1316+
if (!config) {
1317+
return true;
1318+
}
1319+
1320+
e.preventDefault();
1321+
swal(config)
1322+
.then(function() {
1323+
content_was_modified = false;
1324+
prepareForm(form);
1325+
HTMLFormElement.prototype.submit.call(form);
1326+
})
1327+
.catch(function() {
1328+
statoDocumento.selectSet(statoCorrente);
1329+
});
1330+
return false;
1331+
});
1332+
});';
12771333

1278-
if (testo === "Pagato" || testo === "Parzialmente pagato") {
1279-
if(confirm("'.tr('Sicuro di voler impostare manualmente la fattura come pagata senza aggiungere il movimento in prima nota?').'")) {
1280-
return true;
1281-
} else {
1282-
$("#idstatodocumento").selectSet('.$record['idstatodocumento'].');
1283-
}
1284-
}
1285-
}';
12861334
if ($dir == 'entrata') {
12871335
echo '
12881336
function bolloAutomatico() {

0 commit comments

Comments
 (0)