Die Umsatztabelle zeigt jetzt unbekannte bvbs an und man kann auch eine bvb den contacts zuordnern oder einen neuen contacct erstellen

This commit is contained in:
2026-04-28 11:36:11 +02:00
parent 85ad80add7
commit f16386810f
+49 -22
View File
@@ -51,8 +51,11 @@ umsatzServer <- function(id, conn, r_global) {
}) })
}) })
# ── Tabelle ──────────────────────────────────────────────────────────────── # ── Tabelle ----
output$umsatz_table <- renderReactable({ output$umsatz_table <- renderReactable({
# remote_names einmal laden
known_names <- dbGetQuery(conn, "SELECT contact_text FROM bank_connections")$contact_text
reactable( reactable(
umsatz_data() %>% umsatz_data() %>%
select(id, valuta, empfaenger_name, empfaenger_konto, select(id, valuta, empfaenger_name, empfaenger_konto,
@@ -73,7 +76,7 @@ umsatzServer <- function(id, conn, r_global) {
}); });
}); });
}"), }"),
filterable = F, # ← das reicht filterable = F,
pagination = F, pagination = F,
selection = "single", selection = "single",
onClick = "select", onClick = "select",
@@ -83,7 +86,15 @@ umsatzServer <- function(id, conn, r_global) {
posting_id = colDef(show = FALSE), posting_id = colDef(show = FALSE),
entry_id = colDef(show = FALSE), entry_id = colDef(show = FALSE),
valuta = colDef(name = "Datum", maxWidth = 120), valuta = colDef(name = "Datum", maxWidth = 120),
empfaenger_name = colDef(name = "Empfänger", minWidth = 150), empfaenger_name = colDef(
name = "Empfänger",
minWidth = 150,
style = function(value) {
if (!is.na(value) && !(value %in% known_names)) {
list(color = "red", fontWeight = "bold")
}
}
),
empfaenger_konto = colDef(name = "IBAN", minWidth = 150), empfaenger_konto = colDef(name = "IBAN", minWidth = 150),
betrag = colDef( betrag = colDef(
name = "Betrag", name = "Betrag",
@@ -106,7 +117,7 @@ umsatzServer <- function(id, conn, r_global) {
) )
}) })
# ── Selektierter Umsatz ──────────────────────────────────────────────────── # ── Selektierter Umsatz ----
sel <- reactive(getReactableState("umsatz_table", "selected")) sel <- reactive(getReactableState("umsatz_table", "selected"))
selected_umsatz <- reactive({ selected_umsatz <- reactive({
@@ -114,7 +125,7 @@ umsatzServer <- function(id, conn, r_global) {
umsatz_data()[sel(), ] umsatz_data()[sel(), ]
}) })
# ── Buchungs-Panel ───────────────────────────────────────────────────────── # ── Buchungs-Panel ----
output$buchungs_panel <- renderUI({ output$buchungs_panel <- renderUI({
req(selected_umsatz()) req(selected_umsatz())
u <- selected_umsatz() u <- selected_umsatz()
@@ -165,7 +176,7 @@ umsatzServer <- function(id, conn, r_global) {
} }
}) })
# ── Zur Buchung springen ─────────────────────────────────────────────────── # ── Zur Buchung springen ----
observeEvent(input$goto_buchung, { observeEvent(input$goto_buchung, {
req(selected_umsatz()) req(selected_umsatz())
r_global$nav_history <- c(r_global$nav_history, list(list(tab = "umsatz"))) r_global$nav_history <- c(r_global$nav_history, list(list(tab = "umsatz")))
@@ -173,7 +184,7 @@ umsatzServer <- function(id, conn, r_global) {
r_global$active_tab <- "buchungen" r_global$active_tab <- "buchungen"
}) })
# ── Buchen ──────────────────────────────────────────────────────────────── # ── Buchen ----
observeEvent(input$buchen, { observeEvent(input$buchen, {
req(selected_umsatz(), input$konto) req(selected_umsatz(), input$konto)
u <- selected_umsatz() u <- selected_umsatz()
@@ -207,14 +218,24 @@ umsatzServer <- function(id, conn, r_global) {
showNotification("✓ Gebucht", type = "message") showNotification("✓ Gebucht", type = "message")
}) })
# ── Neuer Kontakt ────────────────────────────────────────────────────────── # ── Neuer Kontakt / Bankverbindung ----
observeEvent(input$new_contact, { observeEvent(input$new_contact, {
req(selected_umsatz()) req(selected_umsatz())
u <- selected_umsatz() u <- selected_umsatz()
contact_choices <- get_contact_choices(conn)
showModal(modalDialog( showModal(modalDialog(
title = "Neuer Kontakt", title = "Neuer Kontakt",
textInput(ns("new_contact_name"), "Name", value = u$empfaenger_name), selectizeInput(ns("existing_contact_id"),
"Vorhandenen Kontakt verknüpfen (optional)",
choices = contact_choices,
selected = 0,
options = list(placeholder = "Kontakt suchen...")
),
hr(),
conditionalPanel(
condition = paste0("input['", ns("existing_contact_id"), "'] == '0'"),
textInput(ns("new_contact_name"), "Name", value = u$empfaenger_name)
),
textInput(ns("new_contact_iban"), "IBAN", value = u$empfaenger_konto), textInput(ns("new_contact_iban"), "IBAN", value = u$empfaenger_konto),
footer = tagList( footer = tagList(
modalButton("Abbrechen"), modalButton("Abbrechen"),
@@ -223,33 +244,39 @@ umsatzServer <- function(id, conn, r_global) {
) )
)) ))
}) })
# ** Neuen Kontakt/Bvb speichern
observeEvent(input$save_contact, { observeEvent(input$save_contact, {
req(input$new_contact_name)
u <- selected_umsatz() u <- selected_umsatz()
existing_id <- as.integer(input$existing_contact_id)
if (!is.na(existing_id) && existing_id != 0L) {
# ── Nur bank_connection anlegen ----
target_contact_id <- existing_id
new_c_id <- max_id(conn, "contacts") + 1L } else {
# ── Neuen Kontakt + bank_connection anlegen ----
req(input$new_contact_name)
target_contact_id <- max_id(conn, "contacts") + 1L
dbxInsert(conn, "contacts", data.frame( dbxInsert(conn, "contacts", data.frame(
id = new_c_id, id = target_contact_id,
display_name = input$new_contact_name display_name = input$new_contact_name
)) ))
}
new_bc_id <- max_id(conn, "bank_connections") + 1L new_bc_id <- max_id(conn, "bank_connections") + 1L
dbxInsert(conn, "bank_connections", data.frame( dbxInsert(conn, "bank_connections", data.frame(
id = new_bc_id, id = new_bc_id,
contact_id = new_c_id, contact_id = target_contact_id,
iban = input$new_contact_iban, iban = input$new_contact_iban,
remote_name = u$empfaenger_name contact_text = u$empfaenger_name
)) ))
removeModal() removeModal()
updateSelectizeInput(session, "kontakt", updateSelectizeInput(session, "kontakt",
choices = get_contact_choices(conn), choices = get_contact_choices(conn),
selected = new_c_id selected = target_contact_id
) )
msg <- if (existing_id != 0L) "✓ Bankverbindung verknüpft" else "✓ Kontakt angelegt"
showNotification("✓ Kontakt angelegt", type = "message") showNotification(msg, type = "message")
}) })
}) })
} }