changes
This commit is contained in:
@@ -327,14 +327,15 @@
|
||||
|
||||
{{-- Edit Invoice Header --}}
|
||||
<div class="glass-card">
|
||||
<div class="card-header-compact">
|
||||
<div class="card-header-compact d-flex justify-content-between align-items-center">
|
||||
<h4>
|
||||
<i class="fas fa-edit me-2"></i>
|
||||
Edit Invoice Details
|
||||
</h4>
|
||||
<small id="headerUpdateMsg" class="text-light"></small>
|
||||
</div>
|
||||
<div class="card-body-compact">
|
||||
<form action="{{ route('admin.invoices.update', $invoice->id) }}" method="POST">
|
||||
<form id="invoiceHeaderForm" action="{{ route('admin.invoices.update', $invoice->id) }}" method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="form-grid-compact">
|
||||
@@ -379,13 +380,12 @@
|
||||
<label class="form-label-compact">
|
||||
<i class="fas fa-tasks"></i> Status
|
||||
</label>
|
||||
<select name="status" class="form-select-compact" required>
|
||||
<select name="status" id="statusSelect" class="form-select-compact" required>
|
||||
<option value="pending" {{ old('status', $invoice->status) === 'pending' ? 'selected' : '' }}>Pending</option>
|
||||
<option value="paying" {{ old('status', $invoice->status) === 'paying' ? 'selected' : '' }}>Paying</option>
|
||||
<option value="paid" {{ old('status', $invoice->status) === 'paid' ? 'selected' : '' }}>Paid</option>
|
||||
<option value="overdue" {{ old('status', $invoice->status) === 'overdue' ? 'selected' : '' }}>Overdue</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- Notes --}}
|
||||
@@ -401,7 +401,7 @@
|
||||
</div>
|
||||
|
||||
<div class="text-end mt-3">
|
||||
<button type="submit" class="btn-success-compact btn-compact">
|
||||
<button type="submit" id="btnHeaderSave" class="btn-success-compact btn-compact">
|
||||
<i class="fas fa-save me-2"></i>Update Invoice
|
||||
</button>
|
||||
</div>
|
||||
@@ -857,6 +857,72 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ✅ Invoice header AJAX save (no page refresh)
|
||||
const headerForm = document.getElementById('invoiceHeaderForm');
|
||||
const headerBtn = document.getElementById('btnHeaderSave');
|
||||
const headerMsg = document.getElementById('headerUpdateMsg');
|
||||
|
||||
if (headerForm && headerBtn) {
|
||||
headerForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
headerMsg.textContent = '';
|
||||
headerBtn.disabled = true;
|
||||
headerBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Saving...';
|
||||
|
||||
const formData = new FormData(headerForm);
|
||||
|
||||
|
||||
fetch(headerForm.action, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}',
|
||||
'Accept': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
},
|
||||
body: formData
|
||||
})
|
||||
.then(async res => {
|
||||
let data = null;
|
||||
try { data = await res.json(); } catch(e) {}
|
||||
|
||||
if (!res.ok) {
|
||||
if (data && data.errors) {
|
||||
const firstError = Object.values(data.errors)[0][0] ?? 'Validation error.';
|
||||
throw new Error(firstError);
|
||||
}
|
||||
throw new Error(data && data.message ? data.message : 'Failed to update invoice.');
|
||||
}
|
||||
|
||||
headerMsg.textContent = 'Invoice header updated.';
|
||||
headerMsg.classList.remove('text-danger');
|
||||
headerMsg.classList.add('text-light');
|
||||
|
||||
// popup_invoice वरचा status badge update करायचा असल्यास:
|
||||
const status = document.getElementById('statusSelect')?.value;
|
||||
const badge = document.querySelector('.status-badge');
|
||||
if (badge && status) {
|
||||
badge.classList.remove('status-paid','status-pending','status-overdue','status-default');
|
||||
if (status === 'paid') badge.classList.add('status-paid');
|
||||
else if (status === 'pending') badge.classList.add('status-pending');
|
||||
else if (status === 'overdue') badge.classList.add('status-overdue');
|
||||
else badge.classList.add('status-default');
|
||||
|
||||
badge.innerHTML = status.charAt(0).toUpperCase() + status.slice(1);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
headerMsg.textContent = err.message || 'Error updating invoice.';
|
||||
headerMsg.classList.remove('text-light');
|
||||
headerMsg.classList.add('text-warning');
|
||||
})
|
||||
.finally(() => {
|
||||
headerBtn.disabled = false;
|
||||
headerBtn.innerHTML = '<i class="fas fa-save me-2"></i>Update Invoice';
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user