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');
|
||||
}
|
||||
}
|
||||
@@ -335,7 +335,13 @@
|
||||
</div>
|
||||
|
||||
<form id="invoice-form" class="space-y-6">
|
||||
<div class="grid grid-cols-4 gap-4">
|
||||
<div class="grid grid-cols-5 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Invoice #</label>
|
||||
<input type="text" id="invoice-number" required pattern="[0-9]+"
|
||||
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
||||
title="Must be a numeric value">
|
||||
</div>
|
||||
<div x-data="customerSearch('invoice')" class="relative">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Customer</label>
|
||||
<div class="relative">
|
||||
|
||||
Reference in New Issue
Block a user