|
302 | 302 | <?php } |
303 | 303 | echo ' |
304 | 304 | <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').'" ]} |
306 | 306 | </div> |
307 | 307 | </div> |
308 | 308 |
|
@@ -1270,19 +1270,67 @@ function caricaRighe(id_riga) { |
1270 | 1270 | }); |
1271 | 1271 |
|
1272 | 1272 | $("#barcode").focus(); |
1273 | | -}); |
1274 | 1273 |
|
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 | +});'; |
1277 | 1333 |
|
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 | | -}'; |
1286 | 1334 | if ($dir == 'entrata') { |
1287 | 1335 | echo ' |
1288 | 1336 | function bolloAutomatico() { |
|
0 commit comments