Technician
This commit is contained in:
@@ -8,9 +8,35 @@
|
||||
*/
|
||||
import { addItem, getItems, resetItemCounter } from '../utils/item-editor.js';
|
||||
import { setDefaultDate, showSpinner, hideSpinner } from '../utils/helpers.js';
|
||||
import '../utils/api.js';
|
||||
|
||||
let currentInvoiceId = null;
|
||||
let qboLaborRate = null;
|
||||
let workerList = [];
|
||||
|
||||
export async function loadWorkers() {
|
||||
try {
|
||||
const result = await window.API.settings.get('invoice_workers');
|
||||
if (result && result.value) {
|
||||
workerList = result.value.split(',').map(w => w.trim()).filter(Boolean);
|
||||
} else {
|
||||
workerList = [];
|
||||
}
|
||||
populateWorkerDropdown();
|
||||
console.log(`👷 ${workerList.length} Bearbeiter geladen`);
|
||||
} catch (e) {
|
||||
console.log('Worker-Liste konnte nicht geladen werden.');
|
||||
}
|
||||
}
|
||||
|
||||
function populateWorkerDropdown() {
|
||||
const sel = document.getElementById('invoice-worker');
|
||||
if (!sel) return;
|
||||
const current = sel.value;
|
||||
sel.innerHTML = `<option value="">— None —</option>` +
|
||||
workerList.map(w => `<option value="${w}">${w}</option>`).join('');
|
||||
if (current) sel.value = current;
|
||||
}
|
||||
|
||||
export async function loadLaborRate() {
|
||||
try {
|
||||
@@ -179,6 +205,11 @@ async function loadInvoiceForEdit(invoiceId) {
|
||||
document.getElementById('invoice-authorization').value = data.invoice.auth_code || '';
|
||||
document.getElementById('invoice-tax-exempt').checked = data.invoice.tax_exempt;
|
||||
document.getElementById('invoice-bill-to-name').value = data.invoice.bill_to_name || '';
|
||||
|
||||
// Worker
|
||||
populateWorkerDropdown();
|
||||
const workerEl = document.getElementById('invoice-worker');
|
||||
if (workerEl) workerEl.value = data.invoice.worker || '';
|
||||
|
||||
const sendDateEl = document.getElementById('invoice-send-date');
|
||||
if (sendDateEl) {
|
||||
@@ -226,7 +257,12 @@ function prepareNewInvoice() {
|
||||
document.getElementById('invoice-terms').value = 'Net 14';
|
||||
document.getElementById('invoice-number').value = '';
|
||||
document.getElementById('invoice-send-date').value = '';
|
||||
|
||||
|
||||
// Worker zurücksetzen
|
||||
populateWorkerDropdown();
|
||||
const workerEl = document.getElementById('invoice-worker');
|
||||
if (workerEl) workerEl.value = '';
|
||||
|
||||
// Reset recurring
|
||||
const recurringCb = document.getElementById('invoice-recurring');
|
||||
const recurringGroup = document.getElementById('invoice-recurring-group');
|
||||
@@ -278,6 +314,7 @@ export async function handleInvoiceSubmit(e) {
|
||||
tax_exempt: document.getElementById('invoice-tax-exempt').checked,
|
||||
scheduled_send_date: document.getElementById('invoice-send-date')?.value || null,
|
||||
bill_to_name: document.getElementById('invoice-bill-to-name')?.value || null,
|
||||
worker: document.getElementById('invoice-worker')?.value || null,
|
||||
is_recurring: isRecurring,
|
||||
recurring_interval: recurringInterval,
|
||||
items: getItems('invoice-items')
|
||||
@@ -314,7 +351,9 @@ export async function handleInvoiceSubmit(e) {
|
||||
export function initInvoiceModal() {
|
||||
const form = document.getElementById('invoice-form');
|
||||
if (form) form.addEventListener('submit', handleInvoiceSubmit);
|
||||
|
||||
|
||||
loadWorkers(); // Bearbeiterliste laden
|
||||
|
||||
const taxExempt = document.getElementById('invoice-tax-exempt');
|
||||
if (taxExempt) taxExempt.addEventListener('change', updateInvoiceTotals);
|
||||
|
||||
@@ -342,4 +381,5 @@ export function initInvoiceModal() {
|
||||
|
||||
window.openInvoiceModal = openInvoiceModal;
|
||||
window.closeInvoiceModal = closeInvoiceModal;
|
||||
window.addInvoiceItem = addInvoiceItem;
|
||||
window.addInvoiceItem = addInvoiceItem;
|
||||
window.reloadInvoiceWorkers = loadWorkers;
|
||||
Reference in New Issue
Block a user