Make invoice due date optional with 14-day default
Datum vystaveni defaults to today and Datum splatnosti defaults to 14 days after the issue date. Both fields are now optional date inputs and only override the default when a user enters a custom value. Applies to the invoice editor and generated PDF. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+17
-11
@@ -40,8 +40,8 @@ const passwordForm = document.getElementById("passwordForm");
|
||||
const savePasswordButton = document.getElementById("savePasswordButton");
|
||||
const cancelPasswordButton = document.getElementById("cancelPasswordButton");
|
||||
const passwordStatus = document.getElementById("passwordStatus");
|
||||
const dueDateOption = document.getElementById("dueDateOption");
|
||||
const dueDateDisplay = document.getElementById("dueDateDisplay");
|
||||
const issueDateInput = document.getElementById("issueDate");
|
||||
const dueDateInput = document.getElementById("dueDate");
|
||||
const paymentPresetSelect = document.getElementById("paymentPresetSelect");
|
||||
const paymentPresetName = document.getElementById("paymentPresetName");
|
||||
const savePaymentPresetButton = document.getElementById("savePaymentPresetButton");
|
||||
@@ -108,17 +108,17 @@ const getClientLabel = (client) => [
|
||||
|
||||
const formatCzechDate = (dateValue) => new Date(`${dateValue}T00:00:00`).toLocaleDateString("cs-CZ");
|
||||
|
||||
const getDueDays = () => Number.parseInt(dueDateOption.value, 10) || 14;
|
||||
const toDateInputValue = (date) => date.toISOString().slice(0, 10);
|
||||
|
||||
const getIssueDate = () => issueDateInput.value || toDateInputValue(new Date());
|
||||
|
||||
const getDueDate = () => {
|
||||
const dueDate = new Date();
|
||||
dueDate.setHours(0, 0, 0, 0);
|
||||
dueDate.setDate(dueDate.getDate() + getDueDays());
|
||||
return dueDate.toISOString().slice(0, 10);
|
||||
};
|
||||
|
||||
const updateDueDate = () => {
|
||||
dueDateDisplay.textContent = `Splatnost: ${formatCzechDate(getDueDate())}`;
|
||||
if (dueDateInput.value) {
|
||||
return dueDateInput.value;
|
||||
}
|
||||
const dueDate = new Date(`${getIssueDate()}T00:00:00`);
|
||||
dueDate.setDate(dueDate.getDate() + 14);
|
||||
return toDateInputValue(dueDate);
|
||||
};
|
||||
|
||||
const updateClientTypeFields = () => {
|
||||
@@ -234,6 +234,8 @@ deletePaymentPresetButton.addEventListener("click", async () => {
|
||||
});
|
||||
|
||||
const readInvoiceData = () => ({
|
||||
issueDate: getIssueDate(),
|
||||
dueDate: getDueDate(),
|
||||
supplier: {
|
||||
...readProfileFields("dodavatel"),
|
||||
typSubjektu: supplierTypeSelect.value
|
||||
@@ -263,6 +265,8 @@ const clearInvoiceEditor = () => {
|
||||
currentInvoiceId = null;
|
||||
invoiceNumberDisplay.textContent = "Nová faktura";
|
||||
invoiceSaveStatus.textContent = "";
|
||||
issueDateInput.value = "";
|
||||
dueDateInput.value = "";
|
||||
writeProfileFields("odberatel", {});
|
||||
clientSelect.value = "";
|
||||
clientTypeSelect.value = "osoba";
|
||||
@@ -282,6 +286,8 @@ const loadInvoiceIntoEditor = (invoice) => {
|
||||
currentInvoiceId = invoice.id;
|
||||
invoiceNumberDisplay.textContent = invoice.invoiceNumber;
|
||||
invoiceSaveStatus.textContent = "";
|
||||
issueDateInput.value = invoice.data.issueDate || "";
|
||||
dueDateInput.value = invoice.data.dueDate || "";
|
||||
writeProfileFields("dodavatel", invoice.data.supplier || {});
|
||||
supplierTypeSelect.value = invoice.data.supplier?.typSubjektu || "osoba";
|
||||
updateSupplierTypeFields();
|
||||
|
||||
Reference in New Issue
Block a user