Buchungen als tr mit inputs

This commit is contained in:
2026-04-28 17:06:08 +02:00
parent a0e2fb986d
commit 23e3c3d4fb
6 changed files with 136 additions and 150 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ contactsUI <- function(id) {
), ),
fluidRow( fluidRow(
column(4, actionBttn(ns("add"), "Neu", size = "sm", style = "material-flat", color = "warning", icon = icon("plus"), block = T)), column(4, actionBttn(ns("add"), "Neu", size = "sm", style = "material-flat", color = "warning", icon = icon("plus"), block = T)),
column(4, actionBttn(ns("del"), "Löschen", size = "sm", style = "material-flat", color = "danger", icon = icon("thrash"), block = T)), column(4, actionBttn(ns("del"), "Löschen", size = "sm", style = "material-flat", color = "danger", icon = icon("trash"), block = T)),
column(4, actionBttn(ns("save"), "Speichern", size = "sm", style = "material-flat", color = "success", icon = icon("floppy-disk"), block = T)), column(4, actionBttn(ns("save"), "Speichern", size = "sm", style = "material-flat", color = "success", icon = icon("floppy-disk"), block = T)),
), ),
br(), br(),
+5
View File
@@ -35,6 +35,11 @@ read_posting <- function(conn, id){
dbxSelect(conn, paste0("SELECT * FROM postings WHERE id =", id)) dbxSelect(conn, paste0("SELECT * FROM postings WHERE id =", id))
} }
read_buch_entries <- function(conn, idwert){
dbxSelect(conn, paste0("SELECT id, entry_id, valuta, account_id, project_id, amount FROM postings WHERE entry_id=", idwert))
}
coldef_entries_tabelle <- coldef_entries_tabelle <-
list( list(
+97 -150
View File
@@ -8,7 +8,7 @@ buchungenUI <- function(id) {
reactableOutput(ns("buchungen_table")), reactableOutput(ns("buchungen_table")),
hr(), hr(),
h3("Details / Gegenbuchungen"), h3("Details / Gegenbuchungen"),
reactableOutput(ns("details_table")), uiOutput(ns("details_table")) ,
h3("Anhänge"), h3("Anhänge"),
uiOutput(ns("attachments_ui")), uiOutput(ns("attachments_ui")),
fileInput(ns("anhang"), NULL, multiple = TRUE, fileInput(ns("anhang"), NULL, multiple = TRUE,
@@ -19,8 +19,8 @@ buchungenUI <- function(id) {
actionBttn(ns("del_trans"), "Transaktion Löschen", size = "sm", style = "material-flat", color = "danger"), actionBttn(ns("del_trans"), "Transaktion Löschen", size = "sm", style = "material-flat", color = "danger"),
actionBttn(ns("add_detail"), "Detail hinzu", size = "sm", style = "material-flat", color = "success"), actionBttn(ns("add_detail"), "Detail hinzu", size = "sm", style = "material-flat", color = "success"),
# Das UI-Element des Moduls (auch wenn es leer ist)
postingModuleUI(ns("posting_modal"))
) )
} }
@@ -30,16 +30,13 @@ buchungenServer <- function(id, conn, r_global) {
# ── Reactive Variablen ---- # ── Reactive Variablen ----
postings_data <- reactiveVal(read_buch_tabelle(conn)) postings_data <- reactiveVal(read_buch_tabelle(conn))
details_data <- reactiveVal(NULL) sel_details <- reactiveVal(NULL)
selected_trans_id <- reactiveVal(NULL) selected_trans_id <- reactiveVal(NULL)
current_main_idx <- reactiveVal(NULL) reset_trigger <- reactiveVal(NULL)
reset_trigger <- reactiveVal(0) current_main_idx <- reactiveVal(NULL)
modal_trigger <- reactiveVal(list(post_id = NULL, counter = 0))
highlighted_valuta <- reactiveVal(NULL)
update_db_trigger <- postingModuleServer(
"posting_modal", conn, selected_trans_id, modal_trigger
)
# ── Filter ---- # ── Filter ----
aktiver_filter <- reactive(r_global$buchungen_filter) aktiver_filter <- reactive(r_global$buchungen_filter)
@@ -58,35 +55,6 @@ buchungenServer <- function(id, conn, r_global) {
else d else d
}) })
observeEvent(aktiver_filter(), {
current_main_idx(NULL)
selected_trans_id(NULL)
details_data(NULL)
})
# ── Sprung von anderem Modul ----
observeEvent(r_global$jump_to_entry_id, ignoreInit = TRUE, {
req(r_global$jump_to_entry_id)
t_id <- r_global$jump_to_entry_id
# Daten neu laden
postings_data(read_buch_tabelle(conn))
# Zeile suchen
idx <- which(gefilterte_daten()$entry_id == t_id)[1]
req(!is.na(idx))
current_main_idx(idx)
selected_trans_id(t_id)
details_data(read_buch_tabelle(conn, trans_id = t_id))
highlighted_valuta(gefilterte_daten()[idx, "valuta"])
reset_trigger(isolate(reset_trigger()) + 1)
scroll_to_row(ns("buchungen_table"), idx)
# Sprungziel zurücksetzen
r_global$jump_to_entry_id <- NULL
})
# ── Haupttabelle rendern ---- # ── Haupttabelle rendern ----
output$buchungen_table <- renderReactable({ output$buchungen_table <- renderReactable({
@@ -96,125 +64,104 @@ buchungenServer <- function(id, conn, r_global) {
coldefs = coldef_entries_tabelle, coldefs = coldef_entries_tabelle,
selection = "single", selection = "single",
hoehe = "60vh", hoehe = "60vh",
defaultSelected = current_main_idx(),
filterable = TRUE, filterable = TRUE,
highlight_valuta = highlighted_valuta()
) )
}) })
# ── Details laden ────────────────────────────────────────────────────────── sel <- reactive(getReactableState("buchungen_table", "selected"))
sel_details <- reactive(getReactableState("buchungen_table", "selected")) observeEvent(sel(), ignoreInit = T, {
observeEvent(sel_details(), ignoreInit = TRUE, {
output$details_table <- renderUI({
sel_details(read_buch_entries(conn, gefilterte_daten()$entry_id[sel()]))
rows <- lapply(1:nrow(sel_details()), function(ind) {
fluidRow(class = "details-row",
column(1, numericInput(ns("id"), label = NULL, width = "100%", value = sel_details()$id[ind])),
column(2, dateInput( ns("valuta"), label = NULL, width = "100%",value = sel_details()$valuta[ind])),
column(3,
selectizeInput(ns("account"), label = NULL,
choices = get_account_choices(conn),
selected = sel_details()$account_id[ind],
width = "100%")
),
column(3,
selectizeInput(ns("projekt"), label = NULL,
choices = get_project_choices(conn),
selected = sel_details()$projekt_id[ind],
width = "100%")
),
column(2, numericInput(ns("betrag"), label = NULL, width = "100%",value = sel_details()$amount[ind]))
)
})
tagList(
rows)
})
})
observe({
req(sel_details()) req(sel_details())
highlighted_valuta(gefilterte_daten()[sel_details(), "valuta"])
current_main_idx(sel_details()) lapply(1:nrow(sel_details()), function(ind) {
t_id <- gefilterte_daten()[sel_details(), "entry_id"] |> pull()
selected_trans_id(t_id) # Alle Input-IDs dieser Zeile
details_data(read_buch_tabelle(conn, trans_id = t_id)) ids <- c(paste0("id_", ind),
paste0("valuta_", ind),
paste0("betrag_", ind),
paste0("account_", ind),
paste0("projekt_", ind))
# Observer nur für diese Zeile
observeEvent(
lapply(ids, function(nm) input[[nm]]), # Trigger: irgendein Input dieser Zeile
ignoreInit = TRUE, {
record <- list(
id = input[[paste0("id_", ind)]],
valuta = input[[paste0("valuta_", ind)]],
betrag = input[[paste0("betrag_", ind)]],
account = input[[paste0("account_", ind)]],
projekt = input[[paste0("projekt_", ind)]]
)
print( record)
}
)
})
}) })
output$details_table <- renderReactable({
req(details_data())
f_reactable(
details_data(),
coldefs = coldef_entries_tabelle,
selection = "single",
hoehe = NULL,
filterable = FALSE
)
})
# ── Detail hinzufügen ----
observeEvent(input$add_detail, {
req(selected_trans_id())
modal_trigger(list(post_id = NULL, counter = modal_trigger()$counter + 1))
})
# ── Detail editieren ----
sel_detail <- reactive(getReactableState("details_table", "selected"))
observeEvent(sel_detail(), ignoreInit = TRUE, {
p_id <- details_data()$id[sel_detail()]
modal_trigger(list(post_id = p_id, counter = modal_trigger()$counter + 1))
})
# ── DB-Update durch Modal ----
observeEvent(update_db_trigger(), ignoreInit = TRUE, {
req(selected_trans_id())
details_data(read_buch_tabelle(conn, trans_id = selected_trans_id()))
postings_data(read_buch_tabelle(conn))
updateReactable("buchungen_table", data = gefilterte_daten())
})
# ── Neue Transaktion ----
observeEvent(input$add_trans, {
new_t_id <- max_id(conn, "entries") + 1
dbxInsert(conn, "entries", data.frame(id = new_t_id))
p_id1 <- max_id(conn, "postings") + 1
p_id2 <- p_id1 + 1
dbxInsert(conn, "postings", data.frame(
id = c(p_id1, p_id2),
entry_id = c(new_t_id, new_t_id),
amount = c(0, 0),
account_id = c(0, 0),
valuta = c(Sys.Date(), Sys.Date())
))
# Filter zurücksetzen damit neue Transaktion sichtbar ist
r_global$buchungen_filter <- "alle"
postings_data(read_buch_tabelle(conn))
selected_trans_id(new_t_id)
details_data(read_buch_tabelle(conn, trans_id = new_t_id))
neue_zeile <- which(postings_data()$id == p_id1)
current_main_idx(neue_zeile)
reset_trigger(isolate(reset_trigger()) + 1)
scroll_to_row(ns("buchungen_table"), neue_zeile)
})
# ── Transaktion löschen ----
observeEvent(input$del_trans, ignoreInit = TRUE, {
req(selected_trans_id())
dbxDelete(conn, "postings", where = data.frame(entry_id = selected_trans_id()))
dbxDelete(conn, "entries", where = data.frame(id = selected_trans_id()))
postings_data(read_buch_tabelle(conn))
current_main_idx(NULL)
selected_trans_id(NULL)
details_data(NULL)
updateReactable("buchungen_table", data = gefilterte_daten())
})
# ── Anhänge ---- # ── Anhänge ----
output$attachments_ui <- renderUI({ # output$attachments_ui <- renderUI({
req(selected_trans_id()) # req(selected_trans_id())
att <- dbxSelect(conn, paste0( # att <- dbxSelect(conn, paste0(
"SELECT * FROM attachments WHERE entry_id = ", selected_trans_id() # "SELECT * FROM attachments WHERE entry_id = ", selected_trans_id()
)) # ))
if (nrow(att) == 0) return(p("Keine Anhänge vorhanden.")) # if (nrow(att) == 0) return(p("Keine Anhänge vorhanden."))
#
tagList(lapply(seq_len(nrow(att)), function(i) { # tagList(lapply(seq_len(nrow(att)), function(i) {
ext <- tools::file_ext(att$original_name[i]) # ext <- tools::file_ext(att$original_name[i])
filename <- paste0("attachments/", att$id[i], ".", ext) # filename <- paste0("attachments/", att$id[i], ".", ext)
#
observeEvent(input[[paste0("open_att_", att$id[i])]], { # observeEvent(input[[paste0("open_att_", att$id[i])]], {
showModal(modalDialog( # showModal(modalDialog(
tags$iframe(src = filename, width = "100%", height = "600px", # tags$iframe(src = filename, width = "100%", height = "600px",
style = "border:none;"), # style = "border:none;"),
title = att$original_name[i], # title = att$original_name[i],
size = "l", # size = "l",
easyClose = TRUE, # easyClose = TRUE,
footer = modalButton("Schließen") # footer = modalButton("Schließen")
)) # ))
}, ignoreInit = TRUE, once = FALSE) # }, ignoreInit = TRUE, once = FALSE)
#
div( # div(
actionLink(ns(paste0("open_att_", att$id[i])), att$original_name[i]), # actionLink(ns(paste0("open_att_", att$id[i])), att$original_name[i]),
actionLink(ns(paste0("del_att_", att$id[i])), "✕", # actionLink(ns(paste0("del_att_", att$id[i])), "✕",
style = "color:red; margin-left:8px;") # style = "color:red; margin-left:8px;")
) # )
})) # }))
}) # })
}) })
} }
Binary file not shown.
+3
View File
@@ -55,6 +55,9 @@ dashboardPage(
), ),
dashboardBody( dashboardBody(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "main.css")
),
tabItems( tabItems(
tabItem(tabName = "buchungen", tabItem(tabName = "buchungen",
buchungenUI("buchungen_tab") buchungenUI("buchungen_tab")
+31
View File
@@ -9,3 +9,34 @@
height: 28px !important; height: 28px !important;
font-size: 14px !important; font-size: 14px !important;
} }
/* 1. Den Abstand des Containers verringern */
.details-row .form-group {
margin-bottom: 2px !important;
}
/* 2. Die Geister-Labels (shiny-label-null) komplett ausblenden */
.details-row .shiny-label-null {
display: none !important;
}
/* 3. Den Abstand der Zeile selbst minimieren */
.details-row {
margin-top: 0px !important;
margin-bottom: 0px !important;
}
/* 4. Speziell für die Selectize-Felder (die sind oft höher) */
.details-row .selectize-control {
margin-bottom: 0px !important;
}
/* Positioniert das Dropdown-Menü über dem Eingabefeld statt darunter */
.details-row .selectize-dropdown {
top: auto !important;
bottom: 100% !important;
margin-bottom: 2px !important;
}