سامانه صدور فاکتور و حسابداری

feat(ux): keep saved corrected sales invoice in same form with print control

davoodmehraban89 committed Oct 14, 2026 at 10:15 UTC 7a2ed502c6b53c8a23b981f5dca569c23fd757f7
1 file changed +26 -2
js/invoices.js
+26 -2
@@ -326,12 +326,31 @@ function invoicePrintView(record){
326 return {...current,number:invoiceVisibleNumber(current)};
327 }
328 let finoraSaleAmendmentId='';
329 +function invoiceSavedCorrectionPrintButton(show,id){
330 + const save=document.getElementById('btn-save-invoice');
331 + if(!save)return;
332 + let btn=document.getElementById('finora-print-saved-amendment');
333 + if(!btn){btn=document.createElement('button');btn.type='button';btn.className='btn btn-secondary';
334 + btn.id='finora-print-saved-amendment';btn.textContent='چاپ همین فاکتور';save.after(btn);}
335 + btn.style.display=show?'inline-flex':'none';
336 + if(show){btn.onclick=()=>renderAndPrintDirect(id);}
337 +}
338 +document.addEventListener('input',e=>{
339 + if(e.target instanceof Element&&e.target.closest('#view-invoices'))
340 + invoiceSavedCorrectionPrintButton(false);
341 +});
342 +document.addEventListener('change',e=>{
343 + if(e.target instanceof Element&&e.target.closest('#view-invoices'))
344 + invoiceSavedCorrectionPrintButton(false);
345 +});
346 +
347 function beginInvoiceAmendment(id){
348 const source=invoiceCurrentVisible(id);
349 if(!source)return alert('فاکتور پیدا نشد.');
350 try{
351 invoicePilotCorrectionEligible(source);
352 finoraSaleAmendmentId=source.id;
353 + invoiceSavedCorrectionPrintButton(false);
354 editInvoice(source.id,true);
355 }catch(e){finoraSaleAmendmentId='';alert(e.message)}
356 }
@@ -354,8 +373,12 @@ async function commitInvoiceSeamlessAmendment(id,changes){
373 saveDatastore();
374 await invoicePilotAwaitSync(['invoices|'+idNew]);
375 await finalizeInvoiceDocument(idNew);
357 - finoraSaleAmendmentId='';
358 - cancelInvoiceEdit();refreshAllSurfaces();
376 + // Stay in the same business invoice form after Save, ready for Print or further edits.
377 + // Only the hidden technical source ID advances; employee number/form remain identical.
378 + finoraSaleAmendmentId=idNew;
379 + editInvoice(idNew,true);
380 + invoiceSavedCorrectionPrintButton(true,idNew);
381 + refreshAllSurfaces();
382 return idNew;
383 }
384
@@ -664,6 +687,7 @@ function editInvoice(invId,allowPostedCorrection=false){
687 recomputeTotals();
688 }
689 function cancelInvoiceEdit(){
690 + invoiceSavedCorrectionPrintButton(false);
691 finoraSaleAmendmentId='';
692 document.getElementById('edit-invoice-id').value='';
693 document.getElementById('invoice-form-title').innerText='صدور فاکتور جدید';