Add field for carry

This commit is contained in:
Joscha 2024-05-05 00:46:36 +02:00
parent 24649725bb
commit 0795dbf903
3 changed files with 29 additions and 3 deletions

View file

@ -42,12 +42,18 @@ label {
#i-monthlyhours { #i-monthlyhours {
width: 6ch; width: 6ch;
} }
#l-hourlyrate { #l-hourlywage {
padding-left: 4ch; padding-left: 4ch;
} }
#i-hourlyrate { #i-hourlywage {
width: 8ch; width: 8ch;
} }
#carry {
grid-column: 2 / 4;
display: flex;
justify-content: end;
align-items: baseline;
}
#table { #table {
display: grid; display: grid;
grid: auto-flow / 3fr 1fr 1fr 1fr 1fr 1fr; grid: auto-flow / 3fr 1fr 1fr 1fr 1fr 1fr;

View file

@ -55,12 +55,19 @@ pub async fn get() -> Markup {
input #i-monthlyhours name="monthly_hours" type="number" value="40" {} input #i-monthlyhours name="monthly_hours" type="number" value="40" {}
" Std." " Std."
} }
label #l-hourlywage for="i-hourlywage" { "Stundensatz:" }
span { span {
label #l-hourlywage for="i-hourlywage" { "Stundensatz: " }
input #i-hourlywage name="hourly_wage" type="number" step="0.01" placeholder="14.09" {} 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 { div #table {
@ -109,6 +116,7 @@ pub struct PostForm {
department: String, department: String,
monthly_hours: u32, monthly_hours: u32,
hourly_wage: String, hourly_wage: String,
carry_prev_month: String,
task: Vec<String>, task: Vec<String>,
day: Vec<u32>, day: Vec<u32>,
start: Vec<String>, start: Vec<String>,
@ -170,6 +178,13 @@ pub async fn post(form: Form<PostForm>) -> Response {
notes.push(note) 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()) let entries = (form.task.into_iter())
.zip(form.day.into_iter()) .zip(form.day.into_iter())
.zip(form.start.into_iter()) .zip(form.start.into_iter())
@ -199,6 +214,7 @@ pub async fn post(form: Form<PostForm>) -> Response {
monthly_hours: form.monthly_hours, monthly_hours: form.monthly_hours,
hourly_wage: form.hourly_wage, hourly_wage: form.hourly_wage,
validate: true, validate: true,
carry_prev_month,
year, year,
month, month,
entries, entries,

View file

@ -52,6 +52,7 @@ pub struct Timesheet {
pub monthly_hours: u32, pub monthly_hours: u32,
pub hourly_wage: String, pub hourly_wage: String,
pub validate: bool, pub validate: bool,
pub carry_prev_month: Option<String>,
pub year: u32, pub year: u32,
pub month: u32, pub month: u32,
pub entries: Vec<Entry>, pub entries: Vec<Entry>,
@ -137,6 +138,9 @@ fn fmt_timesheet(ts: Timesheet) -> String {
lines.push(format!(" monthly_hours: {},", fmt_int(ts.monthly_hours))); lines.push(format!(" monthly_hours: {},", fmt_int(ts.monthly_hours)));
lines.push(format!(" hourly_wage: {},", fmt_str(&ts.hourly_wage))); lines.push(format!(" hourly_wage: {},", fmt_str(&ts.hourly_wage)));
lines.push(format!(" validate: {},", fmt_bool(ts.validate))); 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!(" year: {},", fmt_int(ts.year)));
lines.push(format!(" month: {},", fmt_int(ts.month))); lines.push(format!(" month: {},", fmt_int(ts.month)));
for entry in ts.entries { for entry in ts.entries {