Rechtliches: Anzeige-Texte der Vertragsliste als Lib mit Test
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
625efc7f18
commit
313ead77f4
2 files changed
+96
No files matched your search
@@ -0,0 +1,53 @@
|
||||
// Anzeige-Texte der Vertragsliste im Bereich Rechtliches (reine Funktionen, ohne React).
|
||||
// Die Rechenlogik der Fristen steht in legal.js; hier nur Beschriftung, Badge und Daempfung.
|
||||
import { deadlineTone, formatDate } from './legal'
|
||||
|
||||
const euro = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' })
|
||||
|
||||
export function costLabel(c) {
|
||||
if (c.cost === null || c.cost === undefined) return '–'
|
||||
return `${euro.format(c.cost)}/${c.costInterval === 'year' ? 'Jahr' : 'Monat'}`
|
||||
}
|
||||
|
||||
export function termLabel(c) {
|
||||
if (c.termMonths === null || c.termMonths === undefined) return '–'
|
||||
if (c.termMonths === 0) return 'jederzeit kündbar'
|
||||
const renew = c.renewalMonths ? `, dann je ${c.renewalMonths} Monate` : ', endet danach'
|
||||
return `${c.termMonths} Monate${renew}`
|
||||
}
|
||||
|
||||
export function noticeLabel(c) {
|
||||
if (c.noticeValue === null || c.noticeValue === undefined) return '–'
|
||||
return `${c.noticeValue} ${c.noticeUnit === 'days' ? 'Tage' : 'Monate'}`
|
||||
}
|
||||
|
||||
export function deadlineLabel(r) {
|
||||
switch (r.state) {
|
||||
case 'active': return `kündbar bis ${formatDate(r.noticeBy)} (Periode endet ${formatDate(r.periodEnd)})`
|
||||
case 'anytime': return 'jederzeit kündbar'
|
||||
case 'ends': return `endet am ${formatDate(r.periodEnd)}`
|
||||
case 'ended': return `beendet seit ${formatDate(r.periodEnd)}`
|
||||
case 'cancelled': return r.periodEnd ? `gekündigt zum ${formatDate(r.periodEnd)}` : 'gekündigt'
|
||||
default: return 'Fristen fehlen'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Darstellung der Frist-Spalte: text (voller Satz), lead und rest (Aufteilung, wenn ein
|
||||
* Badge gesetzt ist, sonst lead = text und rest leer), badge ('danger' bei rot, 'warn' bei
|
||||
* orange, sonst null) und muted (Vertrag beendet, gekuendigt oder unvollstaendig).
|
||||
*/
|
||||
export function deadlineView(result, today) {
|
||||
const tone = deadlineTone(result, today)
|
||||
const text = deadlineLabel(result)
|
||||
const badge = tone === 'red' ? 'danger' : tone === 'orange' ? 'warn' : null
|
||||
const muted = tone === 'grey' || tone === 'missing'
|
||||
if (!badge) return { text, lead: text, rest: '', badge, muted }
|
||||
return {
|
||||
text,
|
||||
lead: `kündbar bis ${formatDate(result.noticeBy)}`,
|
||||
rest: `(Periode endet ${formatDate(result.periodEnd)})`,
|
||||
badge,
|
||||
muted,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user