This commit is contained in:
2026-05-01 17:05:41 -05:00
parent 950d50b354
commit e00b748927
2 changed files with 32 additions and 29 deletions

View File

@@ -43,16 +43,20 @@ function parseLocalDate(dateValue) {
return Number.isNaN(d.getTime()) ? null : d;
}
function getLastSentDate(invoice) {
function getFirstSentDate(invoice) {
const sentDates = Array.isArray(invoice.sent_dates)
? invoice.sent_dates.filter(Boolean)
: [];
if (sentDates.length > 0) {
return sentDates[sentDates.length - 1];
if (sentDates.length === 0) {
return null;
}
return null;
const sortedDates = sentDates
.map(d => String(d).split('T')[0])
.sort();
return sortedDates[0];
}
function getTermDays(invoice) {
@@ -79,18 +83,13 @@ function addDays(dateValue, days) {
}
function getEffectiveDueDate(invoice) {
const lastSentDate = getLastSentDate(invoice);
const firstSentDate = getFirstSentDate(invoice);
// Nie versendet = kein Reminder/Overdue Text
if (!lastSentDate) {
if (!firstSentDate) {
return null;
}
if (invoice.due_date) {
return parseLocalDate(invoice.due_date);
}
return addDays(lastSentDate, getTermDays(invoice));
return addDays(firstSentDate, getTermDays(invoice));
}
function getOverdueDays(invoice) {