diff --git a/invoices/templates/invoices/final_invoice_step.html b/invoices/templates/invoices/final_invoice_step.html index 1d99072..17e6730 100644 --- a/invoices/templates/invoices/final_invoice_step.html +++ b/invoices/templates/invoices/final_invoice_step.html @@ -224,7 +224,7 @@
- +
@@ -246,8 +246,17 @@ else { el.classList.add('show'); el.style.display = 'block'; } } function submitSpecialCharge(){ - const fd = new FormData(document.getElementById('specialChargeForm')); + const form = document.getElementById('specialChargeForm'); + const fd = new FormData(form); fd.append('csrfmiddlewaretoken', document.querySelector('input[name=csrfmiddlewaretoken]').value); + // Ensure raw numeric amount is sent + (function ensureRawAmount(){ + const amountInput = document.getElementById('id_charge_amount'); + if (amountInput){ + const raw = (amountInput.getAttribute('data-raw-value') || amountInput.value.replace(/\D/g, '')); + if (raw) fd.set('amount', raw); + } + })(); fetch('{% url "invoices:add_special_charge" instance.id step.id %}', { method: 'POST', body: fd }) .then(r=>r.json()).then(resp=>{ if (resp.success){ @@ -285,6 +294,8 @@ } }).catch(()=> showToast('خطا در ارتباط با سرور', 'danger')); }); + + // Number formatting is handled by number-formatter.js {% endblock %} diff --git a/invoices/templates/invoices/final_settlement_step.html b/invoices/templates/invoices/final_settlement_step.html index a4767d4..e03a7e2 100644 --- a/invoices/templates/invoices/final_settlement_step.html +++ b/invoices/templates/invoices/final_settlement_step.html @@ -76,7 +76,7 @@
- +
@@ -405,6 +405,14 @@ function buildForm(){ const fd = new FormData(document.getElementById('formFinalPayment')); + // Ensure raw numeric amount is sent + (function ensureRawAmount(){ + const amountInput = document.getElementById('id_amount'); + if (amountInput){ + const raw = (amountInput.getAttribute('data-raw-value') || amountInput.value.replace(/\D/g, '')); + if (raw) fd.set('amount', raw); + } + })(); // تبدیل تاریخ شمسی به میلادی برای ارسال const persianDateValue = $('#id_payment_date').val(); @@ -465,6 +473,24 @@ } // Legacy approve button removed; using modal forms below + + // Handle AJAX form submission with number formatting + $(document).ready(function() { + // Override buildForm function for AJAX submission + const originalBuildForm = window.buildForm; + window.buildForm = function() { + // Set raw values before creating FormData + if (window.setRawValuesForSubmission) { + window.setRawValuesForSubmission(); + } + const result = originalBuildForm ? originalBuildForm() : new FormData(document.querySelector('form')); + // Restore formatted values for display + if (window.restoreFormattedValues) { + window.restoreFormattedValues(); + } + return result; + }; + }); {% endblock %} diff --git a/invoices/templates/invoices/quote_payment_step.html b/invoices/templates/invoices/quote_payment_step.html index e9bc07f..4a071f8 100644 --- a/invoices/templates/invoices/quote_payment_step.html +++ b/invoices/templates/invoices/quote_payment_step.html @@ -72,7 +72,7 @@
- +
@@ -366,6 +366,12 @@ } const form = document.getElementById('formAddPayment'); const fd = buildFormData(form); + // Ensure raw numeric amount is sent + (function ensureRawAmount(){ + const amountInput = document.getElementById('id_amount'); + const raw = (amountInput.getAttribute('data-raw-value') || amountInput.value.replace(/\D/g, '')); + if (raw) fd.set('amount', raw); + })(); // تبدیل تاریخ شمسی به میلادی برای ارسال const persianDateValue = $('#id_payment_date').val(); @@ -383,7 +389,7 @@ setTimeout(() => { window.location.href = resp.redirect; }, 700); } } else { - showToast(resp.message + ':' + resp.error || 'خطا در ثبت فیش', 'danger'); + showToast((resp.message || resp.error || 'خطا در ثبت فیش'), 'danger'); } }).catch(() => showToast('خطا در ارتباط با سرور', 'danger')); }); @@ -460,6 +466,7 @@ } catch (e) { console.error('Error initializing Persian Date Picker:', e); } } })(); + {% endblock %}