aboutsummaryrefslogtreecommitdiff
path: root/clients/bokftui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-20 16:17:52 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-20 16:17:52 +0200
commita15e9a3b6e3528a6665533929f67e725960f4fa1 (patch)
tree0dc8ce16264656a22b948bdf238b75156bb8cbdb /clients/bokftui.c
parent375ac6067555ab2b20f2802f1c5f5587e1b7b391 (diff)
downloadbokf-0.1.52.tar.gz
bokf-0.1.52.zip
tui: set the next invoice number from the listv0.1.52
Diffstat (limited to 'clients/bokftui.c')
-rw-r--r--clients/bokftui.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/clients/bokftui.c b/clients/bokftui.c
index 06ccfe8..ec7e75a 100644
--- a/clients/bokftui.c
+++ b/clients/bokftui.c
@@ -5905,6 +5905,33 @@ static int64_t invoices_new(struct app *a)
return out;
}
+static int invoices_key(void *ud, int ch)
+{
+ struct app *a = ud;
+ if (ch != 'n')
+ return TUI_HOOK_NONE;
+ char *resp = client_rpc(&a->conn, "invoice.sequence_get", a->session,
+ a->org, "{}");
+ char def[16] = "1";
+ if (resp && client_ok(resp))
+ snprintf(def, sizeof def, "%lld",
+ (long long)jint_val(resp, "result.next_number", 1));
+ free(resp);
+ char buf[16] = "";
+ if (!tui_prompt_into(buf, sizeof buf, "Nästa fakturanummer", def, 0))
+ return TUI_HOOK_STAY;
+ char args[64];
+ snprintf(args, sizeof args, "{\"next_number\":%s}", buf);
+ resp = client_rpc(&a->conn, "invoice.sequence_set", a->session, a->org,
+ args);
+ if (resp && client_ok(resp))
+ tui_message("Fakturor", "Nästa fakturanummer: %s.", buf);
+ else
+ show_error("Fakturor", resp);
+ free(resp);
+ return TUI_HOOK_REFRESH;
+}
+
static void invoices_screen(struct app *a)
{
char **items = NULL;
@@ -5978,8 +6005,8 @@ static void invoices_screen(struct app *a)
}
}
int cur = start;
- int sel = tui_select_list("Fakturor", items, (int)n + 1, start, 1,
- &cur, 1, NULL, 0);
+ int sel = tui_select_list_hook("Fakturor", items, (int)n + 1, start, 1,
+ &cur, 1, NULL, 0, invoices_key, a);
if (cur >= 0 && (size_t)cur < n)
a->invoice_sel = ids[cur];
if (sel == -1) {