@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / b1069b8
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 18:15 UTC

Persist cash and credit settlement on invoices

davoodmehraban89 committed Sep 28, 2026 at 12:52 UTC b1069b8ac1d21a701203492775c40b5b4b7e11f7
1 file changed +6 -2
js/invoices.js
+6 -2
@@ -329,6 +329,8 @@ function commitSaveInvoice(){
329 const date=document.getElementById('invoice-date-input')?.value.trim()||getJalaliNumeric();
330 const kind=document.getElementById('invoice-kind')?.value||'non_formal';
331 const description=document.getElementById('invoice-desc-input')?.value.trim()||'';
332 + const paymentMethod=document.getElementById('invoice-payment-method')?.value||'cash';
333 + const paymentMethodLabel=paymentMethod==='credit'?'نسیه':'نقدی';
334 const editId=document.getElementById('edit-invoice-id')?.value;
335 if(kind==='non_formal'){document.getElementById('invoice-vat-mode').value='none';}
336
@@ -379,12 +381,12 @@ function commitSaveInvoice(){
381 if(existingIndex!==-1){
382 const prev=datastore.invoices[existingIndex];
383 const finalEdoc=edoc?edoc:(prev.electronicDoc||null);
382 - datastore.invoices[existingIndex]={...prev,ownerUserId:currentUser.id,number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod:'cash',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};
384 + 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};
385 alert('فاکتور با موفقیت ویرایش شد.');
386 }
387 cancelInvoiceEdit();
388 }else{
387 - const record={id:'INV_'+Date.now(),ownerUserId:currentUser.id,number,date,companyId,companyName,kind,kindLabel:kindLabels[kind],contactId,contactName,projectId,projectName,contractNumber,paymentMethod:'cash',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};
389 + 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};
390 datastore.invoices.push(record);
391 alert('فاکتور با موفقیت ثبت شد.');
392 cancelInvoiceEdit();
@@ -410,6 +412,7 @@ function editInvoice(invId){
412 document.getElementById('invoice-number').value=inv.number;
413 document.getElementById('invoice-contact-id').value=inv.contactId;
414 document.getElementById('invoice-date-input').value=inv.date;
415 + if(document.getElementById('invoice-payment-method'))document.getElementById('invoice-payment-method').value=inv.paymentMethod||'cash';
416 document.getElementById('invoice-discount-type').value=inv.discountType||'fixed';
417 document.getElementById('label-invoice-discount-value').innerText=(inv.discountType==='percent')?'درصد تخفیف (٪)':`مبلغ تخفیف (${getCurrencyLabel()})`;
418 document.getElementById('invoice-discount-fixed').value=(inv.discountType==='percent')?(inv.discountInput||0):(inv.discount||0);
@@ -456,6 +459,7 @@ function cancelInvoiceEdit(){
459 document.getElementById('invoice-discount-fixed').value=0;
460 document.getElementById('invoice-vat-type').value='percent';
461 document.getElementById('invoice-desc-input').value='';
462 + if(document.getElementById('invoice-payment-method'))document.getElementById('invoice-payment-method').value='cash';
463 const contractInput=document.getElementById('invoice-contract-number');
464 if(contractInput)contractInput.value='';
465 const contractBox=document.getElementById('box-invoice-contract-number');