This commit is contained in:
@@ -311,6 +311,22 @@ function getGeneralDonationCutoffSelectionValue(cutoffs: DashboardPeriodCutoff[]
|
|||||||
return createCutoffSelectionValue(cutoffs[cutoffs.length - 1].id, "POST");
|
return createCutoffSelectionValue(cutoffs[cutoffs.length - 1].id, "POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExpenseFinanceDate(expense: { createdAt: string; documents: { invoiceDate: string }[] }) {
|
||||||
|
const invoiceDate = expense.documents
|
||||||
|
.map((document) => document.invoiceDate)
|
||||||
|
.sort((left, right) => new Date(left).getTime() - new Date(right).getTime())[0];
|
||||||
|
|
||||||
|
return new Date(invoiceDate ?? expense.createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFinanceMonthKey(date: Date) {
|
||||||
|
return `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFinanceMonthLabel(date: Date) {
|
||||||
|
return new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(date);
|
||||||
|
}
|
||||||
|
|
||||||
function formatPeriodRange(startsAt: string, endsAt: string) {
|
function formatPeriodRange(startsAt: string, endsAt: string) {
|
||||||
const formatter = new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" });
|
const formatter = new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" });
|
||||||
return `${formatter.format(new Date(startsAt))} bis ${formatter.format(new Date(endsAt))}`;
|
return `${formatter.format(new Date(startsAt))} bis ${formatter.format(new Date(endsAt))}`;
|
||||||
@@ -3681,10 +3697,10 @@ export function DashboardShell({
|
|||||||
if (financeViewMode === "monthly") {
|
if (financeViewMode === "monthly") {
|
||||||
const rows = new Map<string, { label: string; planned: number; approved: number; paid: number; donations: number }>();
|
const rows = new Map<string, { label: string; planned: number; approved: number; paid: number; donations: number }>();
|
||||||
for (const expense of allExpenses) {
|
for (const expense of allExpenses) {
|
||||||
const date = new Date(expense.createdAt);
|
const date = getExpenseFinanceDate(expense);
|
||||||
const key = `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
const key = getFinanceMonthKey(date);
|
||||||
const row = rows.get(key) ?? {
|
const row = rows.get(key) ?? {
|
||||||
label: new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(date),
|
label: getFinanceMonthLabel(date),
|
||||||
planned: 0,
|
planned: 0,
|
||||||
approved: 0,
|
approved: 0,
|
||||||
paid: 0,
|
paid: 0,
|
||||||
@@ -3697,9 +3713,9 @@ export function DashboardShell({
|
|||||||
}
|
}
|
||||||
for (const donation of donations) {
|
for (const donation of donations) {
|
||||||
const date = new Date(donation.donatedAt);
|
const date = new Date(donation.donatedAt);
|
||||||
const key = `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
const key = getFinanceMonthKey(date);
|
||||||
const row = rows.get(key) ?? {
|
const row = rows.get(key) ?? {
|
||||||
label: new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(date),
|
label: getFinanceMonthLabel(date),
|
||||||
planned: 0,
|
planned: 0,
|
||||||
approved: 0,
|
approved: 0,
|
||||||
paid: 0,
|
paid: 0,
|
||||||
@@ -3788,14 +3804,14 @@ export function DashboardShell({
|
|||||||
const financeMonthOptions = (() => {
|
const financeMonthOptions = (() => {
|
||||||
const rows = new Map<string, string>();
|
const rows = new Map<string, string>();
|
||||||
for (const expense of allExpenses) {
|
for (const expense of allExpenses) {
|
||||||
const date = new Date(expense.createdAt);
|
const date = getExpenseFinanceDate(expense);
|
||||||
const key = `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
const key = getFinanceMonthKey(date);
|
||||||
rows.set(key, new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(date));
|
rows.set(key, getFinanceMonthLabel(date));
|
||||||
}
|
}
|
||||||
for (const donation of donations) {
|
for (const donation of donations) {
|
||||||
const date = new Date(donation.donatedAt);
|
const date = new Date(donation.donatedAt);
|
||||||
const key = `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
const key = getFinanceMonthKey(date);
|
||||||
rows.set(key, new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(date));
|
rows.set(key, getFinanceMonthLabel(date));
|
||||||
}
|
}
|
||||||
return [...rows.entries()].sort(([left], [right]) => left.localeCompare(right));
|
return [...rows.entries()].sort(([left], [right]) => left.localeCompare(right));
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user