Buchungs-Seite aufgeräumt
This commit is contained in:
+110
-86
@@ -5,19 +5,39 @@ buchungenUI <- function(id) {
|
|||||||
tagList(
|
tagList(
|
||||||
useShinyjs(),
|
useShinyjs(),
|
||||||
h3("Hauptbuchungen"),
|
h3("Hauptbuchungen"),
|
||||||
reactableOutput(ns("buchungen_table")),
|
fluidRow(
|
||||||
|
column(8, reactableOutput(ns("buchungen_table"))),
|
||||||
|
|
||||||
|
column(4,
|
||||||
|
selectizeInput(ns("contact"), label = "Kontakt", choices = get_contact_choices(conn),
|
||||||
|
selected = NA, width = "100%"),
|
||||||
|
textAreaInput(ns("note"), label = "Verwendungszweck", value = NA, width = "100%"),
|
||||||
|
h3("Dateien"),
|
||||||
|
uiOutput(ns("attachments_ui")),
|
||||||
|
fileInput(ns("anhang"), NULL, multiple = TRUE,
|
||||||
|
accept = c(".pdf", ".jpg", ".png", ".xlsx", ".docx"),
|
||||||
|
width = "100%"),
|
||||||
|
div(
|
||||||
|
style = "display: flex; flex-direction: column; gap: 10px; align-items: flex-start;",
|
||||||
|
|
||||||
|
actionBttn(ns("add_detail"), "Detail hinzu",
|
||||||
|
size = "sm", style = "material-flat", color = "default", block = TRUE),
|
||||||
|
actionBttn(ns("del_detail"), "Detail Löschen",
|
||||||
|
size = "sm", style = "material-flat", color = "danger", block = TRUE),
|
||||||
|
actionBttn(ns("add_trans"), "Transaktion hinzu",
|
||||||
|
size = "sm", style = "material-flat", color = "default", block = TRUE),
|
||||||
|
|
||||||
|
actionBttn(ns("del_trans"), "Transaktion Löschen",
|
||||||
|
size = "sm", style = "material-flat", color = "danger", block = TRUE),
|
||||||
|
actionBttn(ns("save_trans"), "Transaktion speichern",
|
||||||
|
size = "sm", style = "material-flat", color = "success", block = TRUE, icon = icon("floppy-disk")),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
hr(),
|
hr(),
|
||||||
h3("Details / Gegenbuchungen"),
|
h3("Details / Gegenbuchungen"),
|
||||||
uiOutput(ns("details_table")) ,
|
uiOutput(ns("details_table")) ,
|
||||||
h3("Anhänge"),
|
|
||||||
uiOutput(ns("attachments_ui")),
|
|
||||||
fileInput(ns("anhang"), NULL, multiple = TRUE,
|
|
||||||
accept = c(".pdf", ".jpg", ".png", ".xlsx", ".docx"),
|
|
||||||
width = "100%"),
|
|
||||||
br(),
|
|
||||||
actionBttn(ns("add_trans"), "Transaktion hinzu", size = "sm", style = "material-flat", color = "warning"),
|
|
||||||
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"),
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -70,98 +90,102 @@ buchungenServer <- function(id, conn, r_global) {
|
|||||||
|
|
||||||
sel <- reactive(getReactableState("buchungen_table", "selected"))
|
sel <- reactive(getReactableState("buchungen_table", "selected"))
|
||||||
observeEvent(sel(), ignoreInit = T, {
|
observeEvent(sel(), ignoreInit = T, {
|
||||||
|
|
||||||
|
|
||||||
output$details_table <- renderUI({
|
output$details_table <- renderUI({
|
||||||
sel_details(read_buch_entries(conn, gefilterte_daten()$entry_id[sel()]))
|
req(sel())
|
||||||
rows <- lapply(1:nrow(sel_details()), function(ind) {
|
# Daten laden
|
||||||
|
df <- read_buch_entries(conn, gefilterte_daten()$entry_id[sel()])
|
||||||
|
sel_details(df)
|
||||||
|
|
||||||
|
rows <- lapply(1:nrow(df), function(ind) {
|
||||||
fluidRow(class = "details-row",
|
fluidRow(class = "details-row",
|
||||||
column(1, numericInput(ns("id"), label = NULL, width = "100%", value = sel_details()$id[ind])),
|
# HIER: Index an die ID hängen!
|
||||||
column(2, dateInput( ns("valuta"), label = NULL, width = "100%",value = sel_details()$valuta[ind])),
|
column(1, numericInput(ns(paste0("id_", ind)), label = NULL, width = "100%", value = df$id[ind])),
|
||||||
column(3,
|
column(2, dateInput(ns(paste0("valuta_", ind)), label = NULL, width = "100%", value = df$valuta[ind])),
|
||||||
selectizeInput(ns("account"), label = NULL,
|
column(3, selectizeInput(ns(paste0("account_", ind)), label = NULL,
|
||||||
choices = get_account_choices(conn),
|
choices = get_account_choices(conn),
|
||||||
selected = sel_details()$account_id[ind],
|
selected = df$account_id[ind], width = "100%")),
|
||||||
width = "100%")
|
column(3, selectizeInput(ns(paste0("projekt_", ind)), label = NULL,
|
||||||
),
|
choices = get_project_choices(conn),
|
||||||
column(3,
|
selected = df$projekt_id[ind], width = "100%")),
|
||||||
selectizeInput(ns("projekt"), label = NULL,
|
column(2, numericInput(ns(paste0("betrag_", ind)), label = NULL, width = "100%", value = df$amount[ind]))
|
||||||
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)
|
||||||
tagList(
|
|
||||||
rows)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
observe({
|
observeEvent(input$save_trans, {
|
||||||
req(sel_details())
|
req(sel_details())
|
||||||
|
n_rows <- nrow(sel_details())
|
||||||
|
|
||||||
lapply(1:nrow(sel_details()), function(ind) {
|
# Alle Zeilen in einer Liste sammeln
|
||||||
|
all_records <- lapply(1:n_rows, function(ind) {
|
||||||
# Alle Input-IDs dieser Zeile
|
data.frame(
|
||||||
ids <- c(paste0("id_", ind),
|
id = as.integer(input[[paste0("id_", ind)]]),
|
||||||
paste0("valuta_", ind),
|
valuta = as.Date(input[[paste0("valuta_", ind)]]),
|
||||||
paste0("betrag_", ind),
|
amount = as.numeric(input[[paste0("betrag_", ind)]]),
|
||||||
paste0("account_", ind),
|
account_id = input[[paste0("account_", ind)]],
|
||||||
paste0("projekt_", ind))
|
projekt_id = input[[paste0("projekt_", ind)]],
|
||||||
|
stringsAsFactors = FALSE
|
||||||
# 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)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Zu einem großen Dataframe zusammenfügen
|
||||||
|
final_df <- do.call(rbind, all_records)
|
||||||
|
browser()
|
||||||
|
|
||||||
|
# Datenbank-Update-Logik
|
||||||
|
tryCatch({
|
||||||
|
# Beispiel: Für jede Zeile ein Update ausführen
|
||||||
|
for(i in 1:nrow(final_df)) {
|
||||||
|
update_buchung_detail(conn, final_df[i, ]) # Deine DB-Funktion
|
||||||
|
}
|
||||||
|
|
||||||
|
showNotification("Daten erfolgreich gespeichert", type = "message")
|
||||||
|
|
||||||
|
# Optional: Haupttabelle aktualisieren, falls sich Summen geändert haben
|
||||||
|
# trigger_refresh(trigger_refresh() + 1)
|
||||||
|
|
||||||
|
}, error = function(e) {
|
||||||
|
showNotification(paste("Fehler beim Speichern:", e$message), type = "error")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
# ── Anhänge ----
|
# ── Anhänge ----
|
||||||
# output$attachments_ui <- renderUI({
|
output$attachments_ui <- renderUI({
|
||||||
# req(selected_trans_id())
|
req(sel_details())
|
||||||
# att <- dbxSelect(conn, paste0(
|
entry_id <-
|
||||||
# "SELECT * FROM attachments WHERE entry_id = ", selected_trans_id()
|
dbxSelect(conn, paste0("SELECT entry_id FROM postings WHERE id=",
|
||||||
# ))
|
sel_details()$id[1])) %>% pull
|
||||||
# if (nrow(att) == 0) return(p("Keine Anhänge vorhanden."))
|
att <- dbxSelect(conn, paste0(
|
||||||
#
|
"SELECT * FROM attachments WHERE entry_id = ", entry_id
|
||||||
# tagList(lapply(seq_len(nrow(att)), function(i) {
|
))
|
||||||
# ext <- tools::file_ext(att$original_name[i])
|
if (nrow(att) == 0) return(p("Keine Anhänge vorhanden."))
|
||||||
# filename <- paste0("attachments/", att$id[i], ".", ext)
|
|
||||||
#
|
tagList(lapply(seq_len(nrow(att)), function(i) {
|
||||||
# observeEvent(input[[paste0("open_att_", att$id[i])]], {
|
ext <- tools::file_ext(att$original_name[i])
|
||||||
# showModal(modalDialog(
|
filename <- paste0("attachments/", att$id[i], ".", ext)
|
||||||
# tags$iframe(src = filename, width = "100%", height = "600px",
|
|
||||||
# style = "border:none;"),
|
observeEvent(input[[paste0("open_att_", att$id[i])]], {
|
||||||
# title = att$original_name[i],
|
showModal(modalDialog(
|
||||||
# size = "l",
|
tags$iframe(src = filename, width = "100%", height = "600px",
|
||||||
# easyClose = TRUE,
|
style = "border:none;"),
|
||||||
# footer = modalButton("Schließen")
|
title = att$original_name[i],
|
||||||
# ))
|
size = "l",
|
||||||
# }, ignoreInit = TRUE, once = FALSE)
|
easyClose = TRUE,
|
||||||
#
|
footer = modalButton("Schließen")
|
||||||
# div(
|
))
|
||||||
# actionLink(ns(paste0("open_att_", att$id[i])), att$original_name[i]),
|
}, ignoreInit = TRUE, once = FALSE)
|
||||||
# actionLink(ns(paste0("del_att_", att$id[i])), "✕",
|
|
||||||
# style = "color:red; margin-left:8px;")
|
div(
|
||||||
# )
|
actionLink(ns(paste0("open_att_", att$id[i])), att$original_name[i]),
|
||||||
# }))
|
actionLink(ns(paste0("del_att_", att$id[i])), "✕",
|
||||||
# })
|
style = "color:red; margin-left:8px;")
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user