sdfsdf
This commit is contained in:
@@ -709,6 +709,16 @@ async function convertQuoteToInvoice(quoteId) {
|
||||
}
|
||||
|
||||
// Invoice Management - Same accordion pattern
|
||||
async function fetchNextInvoiceNumber() {
|
||||
try {
|
||||
const response = await fetch('/api/invoices/next-number');
|
||||
const data = await response.json();
|
||||
document.getElementById('invoice-number').value = data.next_number;
|
||||
} catch (error) {
|
||||
console.error('Error fetching next invoice number:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadInvoices() {
|
||||
try {
|
||||
const response = await fetch('/api/invoices');
|
||||
@@ -765,6 +775,7 @@ async function openInvoiceModal(invoiceId = null) {
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('invoice-number').value = data.invoice.invoice_number;
|
||||
document.getElementById('invoice-customer').value = data.invoice.customer_id;
|
||||
const dateOnly = data.invoice.invoice_date.split('T')[0];
|
||||
document.getElementById('invoice-date').value = dateOnly;
|
||||
@@ -788,6 +799,9 @@ async function openInvoiceModal(invoiceId = null) {
|
||||
itemCounter = 0;
|
||||
setDefaultDate();
|
||||
|
||||
// Fetch next invoice number
|
||||
fetchNextInvoiceNumber();
|
||||
|
||||
// Add one default item
|
||||
addInvoiceItem();
|
||||
}
|
||||
@@ -1037,7 +1051,15 @@ async function handleInvoiceSubmit(e) {
|
||||
return;
|
||||
}
|
||||
|
||||
const invoiceNumber = document.getElementById('invoice-number').value;
|
||||
|
||||
if (!invoiceNumber || !/^\d+$/.test(invoiceNumber)) {
|
||||
alert('Invalid invoice number. Must be a numeric value.');
|
||||
return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
invoice_number: invoiceNumber,
|
||||
customer_id: parseInt(document.getElementById('invoice-customer').value),
|
||||
invoice_date: document.getElementById('invoice-date').value,
|
||||
terms: document.getElementById('invoice-terms').value,
|
||||
@@ -1060,7 +1082,8 @@ async function handleInvoiceSubmit(e) {
|
||||
closeInvoiceModal();
|
||||
loadInvoices();
|
||||
} else {
|
||||
alert('Error saving invoice');
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Error saving invoice');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
@@ -1090,4 +1113,4 @@ async function deleteInvoice(id) {
|
||||
|
||||
function viewInvoicePDF(id) {
|
||||
window.open(`/api/invoices/${id}/pdf`, '_blank');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user