From 0795dbf9038c333076c5794e48ce9c4a9d3c924d Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 5 May 2024 00:46:36 +0200 Subject: [PATCH] Add field for carry --- src/endpoints/index.css | 10 ++++++++-- src/endpoints/index.rs | 18 +++++++++++++++++- src/render.rs | 4 ++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/endpoints/index.css b/src/endpoints/index.css index 6df522d..e9aed52 100644 --- a/src/endpoints/index.css +++ b/src/endpoints/index.css @@ -42,12 +42,18 @@ label { #i-monthlyhours { width: 6ch; } -#l-hourlyrate { +#l-hourlywage { padding-left: 4ch; } -#i-hourlyrate { +#i-hourlywage { width: 8ch; } +#carry { + grid-column: 2 / 4; + display: flex; + justify-content: end; + align-items: baseline; +} #table { display: grid; grid: auto-flow / 3fr 1fr 1fr 1fr 1fr 1fr; diff --git a/src/endpoints/index.rs b/src/endpoints/index.rs index f8c7724..4e2338f 100644 --- a/src/endpoints/index.rs +++ b/src/endpoints/index.rs @@ -55,12 +55,19 @@ pub async fn get() -> Markup { input #i-monthlyhours name="monthly_hours" type="number" value="40" {} " Std." } - label #l-hourlywage for="i-hourlywage" { "Stundensatz:" } span { + label #l-hourlywage for="i-hourlywage" { "Stundensatz: " } input #i-hourlywage name="hourly_wage" type="number" step="0.01" placeholder="14.09" {} " €" } } + + div #carry { + span { + label #l-carry for="i-carry" { "Übertrag vom Vormonat: " } + input #i-carry .i-dur name="carry_prev_month" type="text" placeholder="00:00" {} + } + } } div #table { @@ -109,6 +116,7 @@ pub struct PostForm { department: String, monthly_hours: u32, hourly_wage: String, + carry_prev_month: String, task: Vec, day: Vec, start: Vec, @@ -170,6 +178,13 @@ pub async fn post(form: Form) -> Response { notes.push(note) } + // Parse carry + let carry_prev_month = if form.carry_prev_month.is_empty() { + None + } else { + Some(form.carry_prev_month) + }; + let entries = (form.task.into_iter()) .zip(form.day.into_iter()) .zip(form.start.into_iter()) @@ -199,6 +214,7 @@ pub async fn post(form: Form) -> Response { monthly_hours: form.monthly_hours, hourly_wage: form.hourly_wage, validate: true, + carry_prev_month, year, month, entries, diff --git a/src/render.rs b/src/render.rs index d1c1870..f833369 100644 --- a/src/render.rs +++ b/src/render.rs @@ -52,6 +52,7 @@ pub struct Timesheet { pub monthly_hours: u32, pub hourly_wage: String, pub validate: bool, + pub carry_prev_month: Option, pub year: u32, pub month: u32, pub entries: Vec, @@ -137,6 +138,9 @@ fn fmt_timesheet(ts: Timesheet) -> String { lines.push(format!(" monthly_hours: {},", fmt_int(ts.monthly_hours))); lines.push(format!(" hourly_wage: {},", fmt_str(&ts.hourly_wage))); lines.push(format!(" validate: {},", fmt_bool(ts.validate))); + if let Some(carry) = ts.carry_prev_month { + lines.push(format!(" carry_prev_month: {},", fmt_str(&carry))); + } lines.push(format!(" year: {},", fmt_int(ts.year))); lines.push(format!(" month: {},", fmt_int(ts.month))); for entry in ts.entries {