summaryrefslogtreecommitdiff
path: root/clients/screens_settings.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-21 21:43:44 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-21 21:43:44 +0200
commit62a92f0af0442c78277c3c97c9efe6fef8145625 (patch)
tree3802a62904880da22bf84a44e9ece3cdff9cd8aa /clients/screens_settings.c
parentf1eeb15781a044a9451ee08b91c63feb395b4767 (diff)
downloadbokf-0.1.60.tar.gz
bokf-0.1.60.zip
settings: per-feature voucher series and console invoice number; tui: F9 hintsv0.1.60
Diffstat (limited to 'clients/screens_settings.c')
-rw-r--r--clients/screens_settings.c89
1 files changed, 71 insertions, 18 deletions
diff --git a/clients/screens_settings.c b/clients/screens_settings.c
index 8a31620..7730ff4 100644
--- a/clients/screens_settings.c
+++ b/clients/screens_settings.c
@@ -199,6 +199,7 @@ struct setting_field {
const char *const *choices;
int nchoices;
int mask;
+ int invoice_number;
};
static void setting_save(struct app *a, const struct setting_field *f,
@@ -218,9 +219,11 @@ static void setting_save(struct app *a, const struct setting_field *f,
char *rr = client_rpc(&a->conn, "settings.set", a->session, a->org, args);
free(args);
if (rr && client_ok(rr)) {
- if (strcmp(f->key, "default_series") == 0)
+ if (strcmp(f->key, "series_voucher") == 0)
snprintf(a->default_series, sizeof a->default_series, "%s",
value);
+ else if (strcmp(f->key, "series_ib") == 0)
+ snprintf(a->ib_series, sizeof a->ib_series, "%s", value);
else if (strcmp(f->key, "attachment_dir") == 0)
snprintf(a->attachment_dir, sizeof a->attachment_dir, "%s",
value);
@@ -283,12 +286,42 @@ static void settings_form(struct app *a, const char *title,
acts[0].enabled = -1;
}
free(resp);
+ for (int i = 0; i < n; i++) {
+ if (!fields[i].invoice_number)
+ continue;
+ char *seq = client_rpc(&a->conn, "invoice.sequence_get",
+ a->session, a->org, "{}");
+ if (seq && client_ok(seq))
+ snprintf(vals[i], 512, "%lld",
+ (long long)jint_val(seq, "result.next_number", 1));
+ free(seq);
+ }
tui_form_hint("upp/ned/Home/End Enter = ändra F5 = uppdatera"
" Esc/q = tillbaka ^C = avsluta");
int r = tui_form_run_actions(title, ff, n, can_edit, acts,
show_password_status ? 1 : 0, NULL,
focus);
- if (r >= 0 && r < n) {
+ if (r >= 0 && r < n && fields[r].invoice_number) {
+ if (!(a->role[0] && strcmp(a->role, "owner") == 0)) {
+ tui_message(title, "Kräver ägarbehörighet.");
+ } else {
+ char *end = NULL;
+ long v = strtol(vals[r], &end, 10);
+ if (!end || *end || v < 1) {
+ tui_message(title,
+ "Nästa fakturanummer måste vara ett positivt"
+ " heltal.");
+ } else {
+ char args[64];
+ snprintf(args, sizeof args, "{\"next_number\":%ld}", v);
+ char *rr = client_rpc(&a->conn, "invoice.sequence_set",
+ a->session, a->org, args);
+ if (!rr || !client_ok(rr))
+ show_error(title, rr);
+ free(rr);
+ }
+ }
+ } else if (r >= 0 && r < n) {
const char *val = vals[r];
if (fields[r].choices)
val = fields[r].choices[choice[r]];
@@ -304,21 +337,29 @@ static void settings_form(struct app *a, const char *title,
static const char *const SECURITY_CHOICES[] = { "starttls", "tls", "plain" };
static const struct setting_field INVOICE_SETTINGS[] = {
- { "default_series", "Standardserie", NULL, 0, 0 },
- { "invoice_receivable_account", "Fordringskonto", NULL, 0, 0 },
- { "invoice_revenue_account", "Intäktskonto", NULL, 0, 0 },
- { "invoice_bankgiro", "Bankgiro", NULL, 0, 0 },
- { "invoice_our_ref", "Vår referens (faktura)", NULL, 0, 0 },
+ { "invoice_next_number", "Nästa fakturanummer", NULL, 0, 0, 1 },
+ { "invoice_receivable_account", "Fordringskonto", NULL, 0, 0, 0 },
+ { "invoice_revenue_account", "Intäktskonto", NULL, 0, 0, 0 },
+ { "invoice_bankgiro", "Bankgiro", NULL, 0, 0, 0 },
+ { "invoice_our_ref", "Vår referens (faktura)", NULL, 0, 0, 0 },
+};
+
+static const struct setting_field SERIES_SETTINGS[] = {
+ { "series_voucher", "Manuella verifikat", NULL, 0, 0, 0 },
+ { "series_invoice", "Fakturor", NULL, 0, 0, 0 },
+ { "series_payroll", "Lön", NULL, 0, 0, 0 },
+ { "series_bokslut", "Bokslut", NULL, 0, 0, 0 },
+ { "series_ib", "Ingående balans", NULL, 0, 0, 0 },
};
static const struct setting_field SMTP_SETTINGS[] = {
- { "smtp_host", "SMTP-server", NULL, 0, 0 },
- { "smtp_port", "SMTP-port", NULL, 0, 0 },
- { "smtp_user", "SMTP-användare", NULL, 0, 0 },
- { "smtp_from", "SMTP-avsändare", NULL, 0, 0 },
- { "smtp_reply_to", "SMTP-svarsadress", NULL, 0, 0 },
- { "smtp_security", "SMTP-säkerhet", SECURITY_CHOICES, 3, 0 },
- { "smtp_password", "SMTP-lösenord", NULL, 0, 1 },
+ { "smtp_host", "SMTP-server", NULL, 0, 0, 0 },
+ { "smtp_port", "SMTP-port", NULL, 0, 0, 0 },
+ { "smtp_user", "SMTP-användare", NULL, 0, 0, 0 },
+ { "smtp_from", "SMTP-avsändare", NULL, 0, 0, 0 },
+ { "smtp_reply_to", "SMTP-svarsadress", NULL, 0, 0, 0 },
+ { "smtp_security", "SMTP-säkerhet", SECURITY_CHOICES, 3, 0, 0 },
+ { "smtp_password", "SMTP-lösenord", NULL, 0, 1, 0 },
};
static int settings_can_write(struct app *a)
@@ -343,6 +384,14 @@ static void smtp_settings_screen(struct app *a)
settings_can_write(a), 1, &sel);
}
+static void series_settings_screen(struct app *a)
+{
+ static int sel = 0;
+ settings_form(a, "Verifikationsserier", SERIES_SETTINGS,
+ (int)(sizeof SERIES_SETTINGS / sizeof SERIES_SETTINGS[0]),
+ settings_can_write(a), 0, &sel);
+}
+
static const char *const SYSTEM_ITEMS[] = {
"Skattetabeller",
"Revision",
@@ -435,6 +484,7 @@ static void company_data_screen(struct app *a)
static const char *const COMPANY_ITEMS[] = {
"Företagsuppgifter",
"Fakturauppgifter",
+ "Verifikationsserier",
"E-post (SMTP)",
"Styrelseledamöter",
MK_SECTION "Register",
@@ -462,18 +512,21 @@ void company_screen(struct app *a)
invoice_settings_screen(a);
break;
case 2:
- smtp_settings_screen(a);
+ series_settings_screen(a);
break;
case 3:
+ smtp_settings_screen(a);
+ break;
+ case 4:
board_screen(a);
break;
- case 5:
+ case 6:
employees_screen(a);
break;
- case 6:
+ case 7:
customers_screen(a);
break;
- case 7:
+ case 8:
rules_screen(a);
break;
default: