diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-23 09:34:16 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-23 09:34:16 +0200 |
| commit | 79b27457125dc2e259783359085021eea1d26e3a (patch) | |
| tree | e5b733b642437d34d46ee34514b093daee52fcef /clients | |
| parent | 6159042d0cb3870e6a7c6f8d9a97e175d59e6f80 (diff) | |
| download | bokf-79b27457125dc2e259783359085021eea1d26e3a.tar.gz bokf-79b27457125dc2e259783359085021eea1d26e3a.zip | |
tui: "Byt bolag" in the main menu
Reopens the org picker (cursor on the current org) and switches the
running session: the org's name, role, current fiscal year and series
are reloaded and the remembered list selections cleared. The context
reload now clears the previous org's values first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'clients')
| -rw-r--r-- | clients/bokftui.c | 19 | ||||
| -rw-r--r-- | clients/screens_dashboard.c | 21 | ||||
| -rw-r--r-- | clients/ui.c | 6 | ||||
| -rw-r--r-- | clients/ui.h | 1 |
4 files changed, 40 insertions, 7 deletions
diff --git a/clients/bokftui.c b/clients/bokftui.c index 867e63e..19a63cf 100644 --- a/clients/bokftui.c +++ b/clients/bokftui.c @@ -286,7 +286,9 @@ static int login_screen(struct app *a) } } -static int select_org(struct app *a) +/* Org picker; the cursor starts on the current org. 0 when one was + chosen (a->org set), -1 on Esc or error. */ +int select_org(struct app *a) { char *resp = client_rpc(&a->conn, "session.list_orgs", a->session, 0, "{}"); if (!resp || !client_ok(resp)) { @@ -319,17 +321,20 @@ static int select_org(struct app *a) free(name); free(role); } - int sel = tui_select_list("Välj organisation att representera", items, (int)n, - 0, 0, NULL, 0, NULL, 0); + int start = 0; + for (size_t i = 0; i < n; i++) + if (ids[i] == a->org) + start = (int)i; + int sel = tui_select_list("Välj organisation att representera", items, + (int)n, start, 0, NULL, 0, NULL, 0); for (size_t i = 0; i < n; i++) free(items[i]); free(items); free(resp); - if (sel < 0) - return -1; - a->org = ids[sel]; + if (sel >= 0) + a->org = ids[sel]; free(ids); - return 0; + return sel >= 0 ? 0 : -1; } static void usage(FILE *f) diff --git a/clients/screens_dashboard.c b/clients/screens_dashboard.c index 83b4f6a..127d4df 100644 --- a/clients/screens_dashboard.c +++ b/clients/screens_dashboard.c @@ -274,9 +274,27 @@ static const char *const MAIN_ITEMS[] = { "Rapporter", "Bokslut", "Bolaget", "System", "Ingående balans", "Räkenskapsår", + "Byt bolag", "Logga ut / avsluta", }; +/* Picks another org and reloads everything that belongs to the org: its + context (name, role, current fiscal year, series) and the remembered + list selections. */ +static void switch_org(struct app *a) +{ + int64_t old = a->org; + if (select_org(a) != 0 || a->org == old) + return; + a->voucher_sel = 0; + a->invoice_sel = 0; + a->customer_sel = 0; + a->employee_sel = 0; + a->payroll_sel = 0; + app_refresh_context(a); + update_status(a); +} + void dashboard(struct app *a) { static int last_sel = 0; @@ -335,6 +353,9 @@ void dashboard(struct app *a) select_fiscal_year(a); break; case 12: + switch_org(a); + break; + case 13: return; default: break; diff --git a/clients/ui.c b/clients/ui.c index cda0883..2eb2dfe 100644 --- a/clients/ui.c +++ b/clients/ui.c @@ -183,6 +183,12 @@ void replace_x_into(const char *src, double x, char *dst, size_t cap) void app_refresh_context(struct app *a) { + a->org_name[0] = '\0'; + a->role[0] = '\0'; + a->fy = 0; + a->fy_label[0] = '\0'; + a->fy_start[0] = '\0'; + a->fy_end[0] = '\0'; char args[64]; snprintf(args, sizeof args, "{\"org\":%lld}", (long long)a->org); char *resp = client_rpc(&a->conn, "session.use_org", a->session, 0, args); diff --git a/clients/ui.h b/clients/ui.h index 8574121..884adbf 100644 --- a/clients/ui.h +++ b/clients/ui.h @@ -76,6 +76,7 @@ void kr_whole(int64_t ore, char *buf, size_t n); int parse_x_double(const char *s, double *out); void replace_x_into(const char *src, double x, char *dst, size_t cap); void app_refresh_context(struct app *a); +int select_org(struct app *a); char *rpc_dry(struct app *a, const char *cmd, const char *args); char *read_file_b64(const char *path); char *file_browser(struct app *a, const char *start_dir); |
