سامانه صدور فاکتور و حسابداری
feat(stage3): preserve new sale VAT mode and explicit currency/version metadata
davoodmehraban89 committed
Oct 23, 2026 at 02:33 UTC
ab3f1a7664419e5c60303cc327f39153b621128b
1 file changed
+9
-6
js/invoices.js
+9
-6
@@ -578,12 +578,15 @@ function commitSaveInvoice(){
578
const totals=recomputeTotals();
579
const kindLabels={formal:'رسمی',non_formal:'غیررسمی',pre_invoice:'پیشفاکتور',contract_statement:'صورت وضعیت پیمان'};
580
const cur=getCurrencyLabel();
581
+ // SQL-v1 uses IRR; never infer a conversion rate from toman/custom display.
582
+ const currencyCode=(mySettings.currency_mode||'rial')==='rial'?'IRR':'UNSUPPORTED_NON_RIAL';
583
+ const vatMode=kind==='non_formal'?'none':(document.getElementById('invoice-vat-mode')?.value||'none');
584
if(editId&&finoraSaleAmendmentId===editId){
585
const changes={number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,
586
projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,warehouseId,
587
subtotal:totals.subtotal,discount:totals.fixedDiscount,discountType:totals.discountType,
585
- discountInput:totals.discountInput,vat:totals.vatAmount,vatType:totals.vatType,
586
- vatRate:totals.vatRate,grandTotal:totals.grandTotal,description,items,currencyLabel:cur,
588
+ discountInput:totals.discountInput,vat:totals.vatAmount,vatMode,vatType:totals.vatType,
589
+ vatRate:totals.vatRate,grandTotal:totals.grandTotal,description,items,currencyLabel:cur,currencyCode,
590
electronicDoc:edoc};
591
const btn=document.getElementById('btn-save-invoice');if(btn)btn.disabled=true;
592
void commitInvoiceSeamlessAmendment(editId,changes).then(()=>{
@@ -604,12 +607,12 @@ function commitSaveInvoice(){
607
if(existingIndex!==-1){
608
const prev=datastore.invoices[existingIndex];
609
const finalEdoc=edoc?edoc:(prev.electronicDoc||null);
607
- datastore.invoices[existingIndex]={...prev,ownerUserId:currentUser.id,number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,warehouseId,subtotal:totals.subtotal,discount:totals.fixedDiscount,discountType:totals.discountType,discountInput:totals.discountInput,vat:totals.vatAmount,vatType:totals.vatType,vatRate:totals.vatRate,grandTotal:totals.grandTotal,description,items,currencyLabel:cur,electronicDoc:finalEdoc,documentStatus:'draft',accountingStatus:'draft',documentVersion:Number(prev.documentVersion||1)+1,updatedAt:new Date().toISOString()};
610
+ datastore.invoices[existingIndex]={...prev,ownerUserId:currentUser.id,number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,warehouseId,subtotal:totals.subtotal,discount:totals.fixedDiscount,discountType:totals.discountType,discountInput:totals.discountInput,vat:totals.vatAmount,vatMode,vatType:totals.vatType,vatRate:totals.vatRate,grandTotal:totals.grandTotal,description,items,currencyLabel:cur,currencyCode,electronicDoc:finalEdoc,documentStatus:'draft',accountingStatus:'draft',documentVersion:Number(prev.documentVersion||1)+1,updatedAt:new Date().toISOString()};
611
alert('فاکتور با موفقیت ویرایش شد.');
612
}
613
cancelInvoiceEdit();
614
}else{
612
- const record={id:'INV_'+Date.now(),ownerUserId:currentUser.id,documentStatus:'draft',accountingStatus:'draft',documentVersion:1,createdAt:new Date().toISOString(),number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,warehouseId,subtotal:totals.subtotal,discount:totals.fixedDiscount,discountType:totals.discountType,discountInput:totals.discountInput,vat:totals.vatAmount,vatType:totals.vatType,vatRate:totals.vatRate,grandTotal:totals.grandTotal,description,items,currencyLabel:cur,electronicDoc:edoc};
615
+ const record={id:'INV_'+Date.now(),ownerUserId:currentUser.id,documentStatus:'draft',accountingStatus:'draft',documentVersion:1,accountingVersion:1,createdAt:new Date().toISOString(),number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,warehouseId,subtotal:totals.subtotal,discount:totals.fixedDiscount,discountType:totals.discountType,discountInput:totals.discountInput,vat:totals.vatAmount,vatMode,vatType:totals.vatType,vatRate:totals.vatRate,grandTotal:totals.grandTotal,description,items,currencyLabel:cur,currencyCode,electronicDoc:edoc};
616
datastore.invoices.push(record);
617
alert(invoiceCreatesAccountingEntry(kind)?'فاکتور بهصورت پیشنویس ذخیره شد. از حسابداری ← مدیریت اسناد میتوانید آن را بازبینی و قطعی کنید.':'سند عملیاتی ذخیره شد؛ ثبت حسابداری قطعی ایجاد نمیشود.');
618
cancelInvoiceEdit();
@@ -634,9 +637,9 @@ function editInvoice(invId,allowPostedCorrection=false){
637
document.getElementById('btn-save-invoice').innerText='💾 ذخیره تغییرات';
638
document.getElementById('invoice-company-id').value=inv.companyId;
639
document.getElementById('invoice-kind').value=inv.kind;
637
- document.getElementById('invoice-vat-mode').value=inv.vat>0?'with_vat':'none';
640
+ document.getElementById('invoice-vat-mode').value=inv.vatMode||((inv.vat||0)>0?'with_vat':'none');
641
document.getElementById('invoice-vat-type').value=inv.vatType||'percent';
639
- document.getElementById('invoice-vat-rate-input').value=inv.vatRate||10;
642
+ document.getElementById('invoice-vat-rate-input').value=inv.vatRate??10;
643
document.getElementById('invoice-number').value=invoiceVisibleNumber(inv);
644
document.getElementById('invoice-contact-id').value=inv.contactId;
645
document.getElementById('invoice-date-input').value=inv.date;