verschiedene änderungen

This commit is contained in:
2026-04-28 15:40:44 +02:00
parent db63fecded
commit a0e2fb986d
4 changed files with 97 additions and 38 deletions
+3 -2
View File
@@ -1,5 +1,5 @@
f_reactable <- function(daten, coldefs = NULL, selection = "single", f_reactable <- function(daten, coldefs = NULL, selection = "single",
defaultSelected = NULL, hoehe = NULL, highlight_valuta = NULL) { defaultSelected = NULL, hoehe = NULL, highlight_valuta = NULL, filterable = T) {
reactable( reactable(
daten, daten,
selection = selection, selection = selection,
@@ -7,7 +7,8 @@ f_reactable <- function(daten, coldefs = NULL, selection = "single",
pagination = F, pagination = F,
defaultPageSize = 17, defaultPageSize = 17,
showPageSizeOptions = TRUE, showPageSizeOptions = TRUE,
filterable = TRUE, defaultSorted = list(valuta = "desc"),
filterable = filterable,
highlight = TRUE, highlight = TRUE,
height = hoehe, # <--- FIXIERT DEN HEADER und macht den Body scrollbar height = hoehe, # <--- FIXIERT DEN HEADER und macht den Body scrollbar
bordered = TRUE, bordered = TRUE,
+1
View File
@@ -119,6 +119,7 @@ contactsServer <- function(id, conn, r_global) {
valuta = colDef(name = "Wertstellung", minWidth = 80), valuta = colDef(name = "Wertstellung", minWidth = 80),
account_name = colDef( name = "Konto", minWidth = 150 ), account_name = colDef( name = "Konto", minWidth = 150 ),
projektname = colDef(name = "Projekt", minWidth = 150), projektname = colDef(name = "Projekt", minWidth = 150),
amount = colDef(name = "Betrag", minWidth = 150) amount = colDef(name = "Betrag", minWidth = 150)
) )
) )
+3 -1
View File
@@ -97,6 +97,7 @@ buchungenServer <- function(id, conn, r_global) {
selection = "single", selection = "single",
hoehe = "60vh", hoehe = "60vh",
defaultSelected = current_main_idx(), defaultSelected = current_main_idx(),
filterable = TRUE,
highlight_valuta = highlighted_valuta() highlight_valuta = highlighted_valuta()
) )
}) })
@@ -119,7 +120,8 @@ buchungenServer <- function(id, conn, r_global) {
details_data(), details_data(),
coldefs = coldef_entries_tabelle, coldefs = coldef_entries_tabelle,
selection = "single", selection = "single",
hoehe = NULL hoehe = NULL,
filterable = FALSE
) )
}) })
+87 -32
View File
@@ -4,11 +4,15 @@ umsatzUI <- function(id) {
useShinyjs(), useShinyjs(),
# Sync-Button oben # Sync-Button oben
div( div(
style = "display: flex; justify-content: flex-end; margin-bottom: 8px;", style = "display: flex; justify-content: flex-end; margin-bottom: 8px; gap: 8px;",
actionBttn(ns("deselect_all"), "Auswahl aufheben",
size = "xs", style = "minimal",
icon = icon("xmark"), color = "default"),
actionBttn(ns("sync"), "Sync Hibiscus", actionBttn(ns("sync"), "Sync Hibiscus",
size = "xs", style = "minimal", size = "xs", style = "minimal",
icon = icon("rotate"), color = "primary") icon = icon("rotate"), color = "primary")
), ),
# Buchungspanel immer sichtbar unten # Buchungspanel immer sichtbar unten
uiOutput(ns("buchungs_panel")), uiOutput(ns("buchungs_panel")),
# Tabelle mit begrenzter Höhe und Scroll # Tabelle mit begrenzter Höhe und Scroll
@@ -78,7 +82,7 @@ umsatzServer <- function(id, conn, r_global) {
}"), }"),
filterable = F, filterable = F,
pagination = F, pagination = F,
selection = "single", selection = "multiple",
onClick = "select", onClick = "select",
defaultSorted = list(valuta = "desc"), defaultSorted = list(valuta = "desc"),
columns = list( columns = list(
@@ -128,18 +132,46 @@ umsatzServer <- function(id, conn, r_global) {
# ── Buchungs-Panel ---- # ── Buchungs-Panel ----
output$buchungs_panel <- renderUI({ output$buchungs_panel <- renderUI({
req(selected_umsatz()) req(selected_umsatz())
u <- selected_umsatz() rows <- selected_umsatz()
if (u$gebucht) { alle_gebucht <- all(rows$gebucht)
manche_gebucht <- any(rows$gebucht) && !alle_gebucht
keine_gebucht <- !any(rows$gebucht)
if (alle_gebucht && nrow(rows) == 1) {
# Einzelauswahl, bereits gebucht → Sprung-Button
tagList( tagList(
h4("Bereits gebucht"), h4("Bereits gebucht"),
actionBttn(ns("goto_buchung"), actionBttn(ns("goto_buchung"),
paste0("→ Zur Buchung (Entry #", u$entry_id, ")"), paste0("→ Zur Buchung (Entry #", rows$entry_id, ")"),
size = "sm", style = "minimal", color = "primary") size = "sm", style = "minimal", color = "primary")
) )
} else if (manche_gebucht) {
div(style = "color: orange;",
icon("triangle-exclamation"),
strong(paste0(sum(rows$gebucht), " von ", nrow(rows),
" Umsätzen bereits gebucht bitte nur ungebuchte auswählen."))
)
} else { } else {
# Alle ungebucht → Buchungsformular
info_text <- if (nrow(rows) > 1) {
tags$p(style = "color: steelblue; font-size: 0.9em;",
icon("info-circle"),
paste0(nrow(rows), " Umsätze ausgewählt ",
"Konto/Projekt/Kontakt werden für alle verwendet.")
)
}
# Kontakt: bei Mehrfachauswahl keinen Auto-Resolve
kontakt_selected <- if (nrow(rows) == 1) {
resolve_contact(conn, rows$empfaenger_name, rows$empfaenger_konto)
} else {
NULL
}
tagList( tagList(
h4("Buchen"), h4(if (nrow(rows) == 1) "Buchen" else paste0(nrow(rows), " Umsätze buchen")),
info_text,
fluidRow( fluidRow(
column(4, column(4,
selectizeInput(ns("konto"), "Konto:", selectizeInput(ns("konto"), "Konto:",
@@ -155,11 +187,11 @@ umsatzServer <- function(id, conn, r_global) {
column(3, column(3,
selectizeInput(ns("kontakt"), "Kontakt:", selectizeInput(ns("kontakt"), "Kontakt:",
choices = get_contact_choices(conn), choices = get_contact_choices(conn),
selected = resolve_contact(conn, u$empfaenger_name, u$empfaenger_konto), selected = kontakt_selected,
width = "100%") width = "100%")
), ),
column(1, column(1,
div(style = "margin-top: 25px;", # Label-Höhe ausgleichen div(style = "margin-top: 25px;",
actionBttn(ns("new_contact"), "Neuer Kontakt", actionBttn(ns("new_contact"), "Neuer Kontakt",
size = "xs", style = "minimal", icon = icon("plus"), color = "warning") size = "xs", style = "minimal", icon = icon("plus"), color = "warning")
) )
@@ -186,36 +218,55 @@ umsatzServer <- function(id, conn, r_global) {
# ── Buchen ---- # ── Buchen ----
observeEvent(input$buchen, { observeEvent(input$buchen, {
req(selected_umsatz(), input$konto) req(selected_umsatz(), input$konto, input$konto != 0)
u <- selected_umsatz() rows <- selected_umsatz()
rows <- rows %>% filter(!gebucht)
req(nrow(rows) > 0)
gegenkonto_id <- dbReadTable(conn, "accounts") %>% bank_connections <- dbReadTable(conn, "bank_connections")
filter(hibiscus_account_id == u$konto_id) %>%
pull(id)
req(length(gegenkonto_id) > 0, input$konto != 0) for (i in seq_len(nrow(rows))) {
u <- rows[i, ]
gegenkonto_id <- dbReadTable(conn, "accounts") %>%
filter(hibiscus_account_id == u$konto_id) %>%
pull(id)
if (length(gegenkonto_id) == 0) next
new_t_id <- max_id(conn, "entries") + 1L # contact_id: manuell gewählt oder aus bank_connections
dbxInsert(conn, "entries", data.frame( contact_id <- if (!is.null(input$kontakt) && as.integer(input$kontakt) != 0) {
id = new_t_id, as.integer(input$kontakt)
contact_id = as.integer(input$kontakt), } else {
note = u$zweck match <- bank_connections %>%
)) filter(contact_text == u$empfaenger_name) %>%
pull(contact_id)
if (length(match) > 0) as.integer(match[[1]]) else NA_integer_
}
p_id1 <- max_id(conn, "postings") + 1L new_t_id <- max_id(conn, "entries") + 1L
dbxInsert(conn, "postings", data.frame( dbxInsert(conn, "entries", data.frame(
id = c(p_id1, p_id1 + 1L), id = new_t_id,
entry_id = c(new_t_id, new_t_id), contact_id = contact_id,
account_id = c(as.integer(input$konto), gegenkonto_id), note = u$zweck
project_id = c(as.integer(input$projekt), NA_integer_), ))
amount = c(u$betrag, -u$betrag),
valuta = c(as.character(u$valuta), as.character(u$valuta)), p_id1 <- max_id(conn, "postings") + 1L
booking_date = c(as.character(u$datum), as.character(u$datum)), dbxInsert(conn, "postings", data.frame(
bank_transaction_id = c(u$id, NA_integer_) id = c(p_id1, p_id1 + 1L),
)) entry_id = c(new_t_id, new_t_id),
account_id = c(as.integer(input$konto), gegenkonto_id),
project_id = c(as.integer(input$projekt), NA_integer_),
amount = c(u$betrag, -u$betrag),
valuta = c(as.character(u$valuta), as.character(u$valuta)),
booking_date = c(as.character(u$datum), as.character(u$datum)),
bank_transaction_id = c(u$id, NA_integer_)
))
}
refresh(refresh() + 1) refresh(refresh() + 1)
showNotification("✓ Gebucht", type = "message") showNotification(
paste0("✓ ", nrow(rows), " Umsatz/Umsätze gebucht"),
type = "message"
)
}) })
# ── Neuer Kontakt / Bankverbindung ---- # ── Neuer Kontakt / Bankverbindung ----
@@ -277,6 +328,10 @@ umsatzServer <- function(id, conn, r_global) {
showNotification(msg, type = "message") showNotification(msg, type = "message")
}) })
## ** Auswahl aufheben ----
observeEvent(input$deselect_all, {
updateReactable("umsatz_table", selected = NA, session = session)
})
}) })
} }