diff options
Diffstat (limited to 'clients/screens_vouchers.c')
| -rw-r--r-- | clients/screens_vouchers.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clients/screens_vouchers.c b/clients/screens_vouchers.c index d87cfd2..fedffe9 100644 --- a/clients/screens_vouchers.c +++ b/clients/screens_vouchers.c @@ -769,6 +769,11 @@ static int vform_key(void *ud, int ch) int64_t vouchers_new(struct app *a) { + return vouchers_new_prefill(a, NULL); +} + +int64_t vouchers_new_prefill(struct app *a, const struct voucher_prefill *p) +{ struct vform vf; memset(&vf, 0, sizeof vf); vf.a = a; @@ -778,6 +783,28 @@ int64_t vouchers_new(struct app *a) char *ref = util_random_id("tui-", 8); snprintf(vf.client_ref, sizeof vf.client_ref, "%s", ref); free(ref); + if (p) { + if (p->date && *p->date && util_parse_iso_date(p->date)) + snprintf(vf.date, sizeof vf.date, "%s", p->date); + if (p->description && *p->description) + snprintf(vf.desc, sizeof vf.desc, "%s", p->description); + if (p->bank_account && *p->bank_account) { + snprintf(vf.rows[0].account, sizeof vf.rows[0].account, "%s", + p->bank_account); + int64_t amt = p->amount_ore < 0 ? -p->amount_ore : p->amount_ore; + char tmp[32]; + tui_kr_format(amt, tmp, sizeof tmp); + if (p->amount_ore > 0) + snprintf(vf.rows[0].debit, sizeof vf.rows[0].debit, "%s", + tmp); + else if (p->amount_ore < 0) + snprintf(vf.rows[0].credit, sizeof vf.rows[0].credit, "%s", + tmp); + } + if (p->description && *p->description) + snprintf(vf.rows[0].text, sizeof vf.rows[0].text, "%s", + p->description); + } int text_w = COLS - 60; if (text_w < 8) text_w = 8; @@ -806,6 +833,7 @@ int64_t vouchers_new(struct app *a) ff[2].cap = sizeof vf.desc; ff[2].kind = TUI_F_TEXT; tui_rt_set_fields(&vf.rt, ff, 3); + tui_rt_normalize(&vf.rt); const char *hint = "Enter = ändra fält Tab = byta fält F4 = mall" " ^F = bifoga fil F5 = validera ^X = rensa rad" " ^Enter = bokför Esc = avbryt"; |
