Add template option to sort entries chronologically

This commit is contained in:
Joscha 2024-11-04 15:57:07 +01:00
parent 55b21c28e6
commit d30cd79229
2 changed files with 8 additions and 0 deletions

View file

@ -121,6 +121,9 @@ Named arguments:
Whether the template should try to validate the data you entered (check if Whether the template should try to validate the data you entered (check if
values look wrong, if you worked on a holiday, ...). If you turn this off, you values look wrong, if you worked on a holiday, ...). If you turn this off, you
can do funky things like work a negative amount of time or on Sundays. can do funky things like work a negative amount of time or on Sundays.
- `sort` (default: `true`):
Whether the template should sort sort all entries in chronological order. If
you turn this off, entries are kept in their original order.
- `year`: - `year`:
The year this time sheet is being generated for. The year this time sheet is being generated for.
- `month`: - `month`:

View file

@ -507,6 +507,7 @@
monthly_hours: 40, monthly_hours: 40,
hourly_wage: [14.09], hourly_wage: [14.09],
validate: true, validate: true,
sort: true,
carry_prev_month: "00:00", carry_prev_month: "00:00",
year: 2024, year: 2024,
month: 1, month: 1,
@ -521,6 +522,10 @@
entries = entries.pos() entries = entries.pos()
assert(entries.len() <= _kit_rows, message: "at most " + str(_kit_rows) + " entries allowed") assert(entries.len() <= _kit_rows, message: "at most " + str(_kit_rows) + " entries allowed")
if sort {
entries = entries.sorted(key: entry => (entry.day, entry.end, entry.start))
}
let monthly = monthly_hours * 60 let monthly = monthly_hours * 60
let holiday = entries.filter(e => e.note == notes.Urlaub).map(e => e.duration).sum(default: 0) let holiday = entries.filter(e => e.note == notes.Urlaub).map(e => e.duration).sum(default: 0)
let total = entries.map(e => e.duration).sum(default: 0) let total = entries.map(e => e.duration).sum(default: 0)