modify sale return

This commit is contained in:
Flatlogic Bot 2026-02-17 16:35:20 +00:00
parent ea63a5146b
commit bad7441af2

View File

@ -4935,8 +4935,8 @@ document.addEventListener('DOMContentLoaded', function() {
}
};
returnInvoiceSelect.addEventListener('change', async function() {
const invoiceId = this.value;
const handleInvoiceChange = async function() {
const invoiceId = returnInvoiceSelect.value;
const container = document.getElementById('return_items_container');
const tbody = document.getElementById('return_items_tbody');
const submitBtn = document.getElementById('submit_return_btn');
@ -4986,15 +4986,27 @@ document.addEventListener('DOMContentLoaded', function() {
if (submitBtn) submitBtn.disabled = true;
// Add event listeners for qty changes
tbody.querySelectorAll('.return-qty-input').forEach(input => {
const qtyInputs = tbody.querySelectorAll('.return-qty-input');
qtyInputs.forEach(input => {
input.addEventListener('input', calculateReturnTotal);
input.addEventListener('change', calculateReturnTotal);
input.addEventListener('keyup', calculateReturnTotal);
});
calculateReturnTotal();
} catch (e) {
console.error(e);
Swal.fire('Error', 'Failed to fetch invoice items', 'error');
if (window.Swal) Swal.fire('Error', 'Failed to fetch invoice items', 'error');
}
});
};
returnInvoiceSelect.addEventListener('change', handleInvoiceChange);
// Also support Select2
if (window.jQuery && jQuery.fn.select2) {
$(returnInvoiceSelect).on('select2:select', handleInvoiceChange);
$(returnInvoiceSelect).on('change', handleInvoiceChange);
}
}
// View Return Logic
@ -5025,7 +5037,7 @@ document.addEventListener('DOMContentLoaded', function() {
<option value="">Choose Invoice...</option>
<?php if (!empty($data['sales_invoices'])): ?>
<?php foreach ($data['sales_invoices'] as $inv): ?>
<option value="<?= $inv['id'] ?>">INV-<?= str_pad((string)$inv['id'], 5, '0', STR_PAD_LEFT) ?> (<?= $inv['invoice_date'] ?>) - OMR <?= number_format($inv['total_with_vat'], 3) ?></option>
<option value="<?= $inv['id'] ?>">INV-<?= str_pad((string)$inv['id'], 5, '0', STR_PAD_LEFT) ?> (<?= $inv['invoice_date'] ?>) - OMR <?= number_format((float)$inv['total_with_vat'], 3) ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>