سامانه صدور فاکتور و حسابداری
Phase 5: persist sales warehouse [skip ci]
davoodmehraban89 committed
Sep 29, 2026 at 20:56 UTC
20fa8be23846a33ac6ffdf8c07ff5630c11a35dd
1 file changed
+4
-3
js/invoices.js
+4
-3
@@ -335,6 +335,7 @@ function commitSaveInvoice(){
335
const description=document.getElementById('invoice-desc-input')?.value.trim()||'';
336
const paymentMethod=document.getElementById('invoice-payment-method')?.value||'cash';
337
const paymentMethodLabel=paymentMethod==='credit'?'نسیه':'نقدی';
338
+ const warehouseId=document.getElementById('invoice-warehouse-id')?.value||'';
339
const editId=document.getElementById('edit-invoice-id')?.value;
340
if(getMyInvoices().some(i=>i.id!==editId&&i.companyId===companyId&&String(i.number||'').trim()===number)){alert('شماره فاکتور برای این شرکت قبلاً ثبت شده است.');return;}
341
if(kind==='non_formal'){document.getElementById('invoice-vat-mode').value='none';}
@@ -387,12 +388,12 @@ function commitSaveInvoice(){
388
if(existingIndex!==-1){
389
const prev=datastore.invoices[existingIndex];
390
const finalEdoc=edoc?edoc:(prev.electronicDoc||null);
390
- datastore.invoices[existingIndex]={...prev,ownerUserId:currentUser.id,number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,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};
391
+ 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};
392
alert('فاکتور با موفقیت ویرایش شد.');
393
}
394
cancelInvoiceEdit();
395
}else{
395
- const record={id:'INV_'+Date.now(),ownerUserId:currentUser.id,number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod,paymentMethodLabel,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};
396
+ const record={id:'INV_'+Date.now(),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:edoc};
397
datastore.invoices.push(record);
398
if(invoiceCreatesAccountingEntry(kind)&&typeof jePostSourceRecord==='function'){try{jePostSourceRecord('sale',record);}catch(e){datastore.invoices=datastore.invoices.filter(x=>x.id!==record.id);alert('فاکتور ثبت نشد: '+e.message);return;}}
399
alert(invoiceCreatesAccountingEntry(kind)?'فاکتور و سند حسابداری با موفقیت ثبت شد.':'سند عملیاتی ثبت شد؛ تا تبدیل به فاکتور فروش قطعی، ثبت حسابداری ایجاد نمیشود.');
@@ -419,7 +420,7 @@ function editInvoice(invId){
420
document.getElementById('invoice-number').value=inv.number;
421
document.getElementById('invoice-contact-id').value=inv.contactId;
422
document.getElementById('invoice-date-input').value=inv.date;
422
- if(document.getElementById('invoice-payment-method'))document.getElementById('invoice-payment-method').value=inv.paymentMethod||'cash';
423
+ if(document.getElementById('invoice-payment-method'))document.getElementById('invoice-payment-method').value=inv.paymentMethod||'cash';if(document.getElementById('invoice-warehouse-id'))document.getElementById('invoice-warehouse-id').value=inv.warehouseId||p5DefaultWarehouse()?.id||'';
424
document.getElementById('invoice-discount-type').value=inv.discountType||'fixed';
425
document.getElementById('label-invoice-discount-value').innerText=(inv.discountType==='percent')?'درصد تخفیف (٪)':`مبلغ تخفیف (${getCurrencyLabel()})`;
426
document.getElementById('invoice-discount-fixed').value=(inv.discountType==='percent')?(inv.discountInput||0):(inv.discount||0);