Buchungen funktioniern mitsamt modal und laufendem saldo
This commit is contained in:
+25
-69
@@ -1,92 +1,48 @@
|
||||
buchungenUI <- function(id) {
|
||||
ns <- NS(id)
|
||||
tagList(
|
||||
reactableOutput(ns("buchungen_table"))
|
||||
reactableOutput(ns("buchungen_table")),
|
||||
reactableOutput(ns("details_table")),
|
||||
postingModuleUI(ns("posting_modal"))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
buchungenServer <- function(id) {
|
||||
moduleServer( id, function(input, output, session) {
|
||||
moduleServer(id, function(input, output, session) {
|
||||
ns <- session$ns
|
||||
|
||||
postings <- reactiveVal(read_buch_tabelle(conn))
|
||||
|
||||
|
||||
# NEU: Eine reactive variable für die ID, die wir editieren wollen
|
||||
# current_entry_id <- reactiveVal(NULL)
|
||||
|
||||
# NEU: Den Modul-Server EINMALIG hier oben starten (nicht im Observer!)
|
||||
# entryEditServer("entry_edit", entry_id = current_entry_id, conn = conn)
|
||||
|
||||
output$buchungen_table <- renderReactable({
|
||||
reactable(
|
||||
postings(),
|
||||
onClick = "expand",
|
||||
selection = "single",
|
||||
details = function(index) {
|
||||
entry_id <- postings()$entry_id[index]
|
||||
detail_rows <- postings()[postings()$entry_id == entry_id, ]
|
||||
|
||||
div(
|
||||
style = "padding: 10px; background: #f4f4f4; border-left: 4px solid #3c8dbc; max-width: 800px; margin-left: auto",
|
||||
|
||||
reactable(
|
||||
dplyr::select(detail_rows, konto, projektname, amount),
|
||||
fullWidth = TRUE,
|
||||
columns = list(
|
||||
konto = colDef(name = "Konto", minWidth = 150),
|
||||
projektname = colDef(name = "Projekt", minWidth = 150),
|
||||
amount = colDef(name = "Betrag", minWidth = 80)
|
||||
)
|
||||
)
|
||||
)
|
||||
},
|
||||
columns = list(
|
||||
id = colDef(name = "ID", minWidth = 80),
|
||||
valuta = colDef(name = "Wertstellung", minWidth = 80),
|
||||
konto = colDef(name = "Kontoname", minWidth = 200),
|
||||
entry_id = colDef(show = FALSE)
|
||||
)
|
||||
)
|
||||
# req(postings())
|
||||
f_reactable(postings(), coldefs = coldef_entries_tabelle)
|
||||
})
|
||||
|
||||
# Modal zum editieren
|
||||
selected <- reactive(getReactableState("buchungen_table", "selected"))
|
||||
observeEvent(selected(),{
|
||||
idwert <- postings()[selected(), "id"]
|
||||
selected_row <- read_posting(conn, idwert) %>%
|
||||
mutate(verzicht = ifelse(is.na(verzicht), F, verzicht))
|
||||
showModal(modalDialog(
|
||||
title = "Buchung bearbeiten",
|
||||
size = "l",
|
||||
tags$style(HTML(".modal-dialog { max-width: 90% !important; width: 90% !important; }")),
|
||||
|
||||
entryEditUI(ns("entry_edit")),
|
||||
footer = tagList(
|
||||
modalButton("Abbrechen"),
|
||||
actionButton(ns("speichern"), "Speichern")
|
||||
)
|
||||
))
|
||||
|
||||
entryEditServer("entry_edit", entry_id = selected_row$entry_id, conn = conn)
|
||||
|
||||
}, ignoreInit = TRUE)
|
||||
|
||||
observeEvent(input$speichern, {
|
||||
browser()
|
||||
dbExecute(conn, "UPDATE postings SET
|
||||
account_id = ?, project_id = ?, amount = ?, valuta = ?,
|
||||
notiz = ?, rechnungsnummer = ?, betrag_muenzen = ?, verzicht = ?
|
||||
WHERE id = ?",
|
||||
params = list(
|
||||
input$account_id, input$project_id, input$amount, input$valuta,
|
||||
input$notiz, input$rechnungsnummer, input$betrag_muenzen, input$verzicht,
|
||||
selected_row$id
|
||||
)
|
||||
observeEvent(selected(), {
|
||||
idwert <- postings()[selected(),"entry_id"] %>% pull
|
||||
details <- read_buch_tabelle(conn, trans_id = idwert)
|
||||
output$details_table <- renderReactable(
|
||||
f_reactable(details, coldefs = coldef_entries_tabelle)
|
||||
)
|
||||
|
||||
removeModal()
|
||||
buchungen(read_buch_tabelle(conn)) # Tabelle neu laden
|
||||
})
|
||||
|
||||
selected_det <- reactive(getReactableState("details_table", "selected"))
|
||||
observeEvent(selected_det(),{
|
||||
idwert <- postings()[selected(),"id"] %>% pull
|
||||
postingModuleServer("posting_modal",conn, idwert)
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user