Neue Transaktion hinzu, es fehlt noch das springen zum neuen ds in der reactable
This commit is contained in:
+38
-8
@@ -9,7 +9,10 @@ buchungenUI <- function(id) {
|
|||||||
h3("Details / Gegenbuchungen"),
|
h3("Details / Gegenbuchungen"),
|
||||||
reactableOutput(ns("details_table")),
|
reactableOutput(ns("details_table")),
|
||||||
br(),
|
br(),
|
||||||
actionBttn(ns("add_detail"), "Detail hinzufügen", size = "sm", style = "material-flat", color = "success"),
|
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"),
|
||||||
|
|
||||||
# Das UI-Element des Moduls (auch wenn es leer ist)
|
# Das UI-Element des Moduls (auch wenn es leer ist)
|
||||||
postingModuleUI(ns("posting_modal"))
|
postingModuleUI(ns("posting_modal"))
|
||||||
)
|
)
|
||||||
@@ -19,7 +22,7 @@ buchungenServer <- function(id, conn) {
|
|||||||
moduleServer(id, function(input, output, session) {
|
moduleServer(id, function(input, output, session) {
|
||||||
ns <- session$ns
|
ns <- session$ns
|
||||||
|
|
||||||
# Reactive States
|
# Reactive States ----
|
||||||
postings_data <- reactiveVal(read_buch_tabelle(conn))
|
postings_data <- reactiveVal(read_buch_tabelle(conn))
|
||||||
details_data <- reactiveVal(NULL)
|
details_data <- reactiveVal(NULL)
|
||||||
selected_trans_id <- reactiveVal(NULL)
|
selected_trans_id <- reactiveVal(NULL)
|
||||||
@@ -29,10 +32,10 @@ buchungenServer <- function(id, conn) {
|
|||||||
# Der Counter erzwingt eine Reaktion, auch wenn die gleiche ID zweimal geklickt wird
|
# Der Counter erzwingt eine Reaktion, auch wenn die gleiche ID zweimal geklickt wird
|
||||||
modal_trigger <- reactiveVal(list(post_id = NULL, counter = 0))
|
modal_trigger <- reactiveVal(list(post_id = NULL, counter = 0))
|
||||||
|
|
||||||
# --- MODUL-SERVER STARTEN (EINMALIG) ---
|
# --- MODUL-SERVER STARTEN (EINMALIG) ----
|
||||||
update_db_trigger <- postingModuleServer("posting_modal", conn, selected_trans_id, modal_trigger)
|
update_db_trigger <- postingModuleServer("posting_modal", conn, selected_trans_id, modal_trigger)
|
||||||
|
|
||||||
# Haupttabelle rendern
|
# Haupttabelle rendern ----
|
||||||
output$buchungen_table <- renderReactable({
|
output$buchungen_table <- renderReactable({
|
||||||
req(postings_data())
|
req(postings_data())
|
||||||
f_reactable(daten = postings_data(), coldefs = coldef_entries_tabelle,
|
f_reactable(daten = postings_data(), coldefs = coldef_entries_tabelle,
|
||||||
@@ -40,7 +43,7 @@ buchungenServer <- function(id, conn) {
|
|||||||
defaultSelected = current_main_idx())
|
defaultSelected = current_main_idx())
|
||||||
})
|
})
|
||||||
|
|
||||||
# Details laden wenn Zeile gewählt wird
|
# Details laden wenn Zeile gewählt wird ----
|
||||||
sel_details <- reactive(getReactableState("buchungen_table", "selected"))
|
sel_details <- reactive(getReactableState("buchungen_table", "selected"))
|
||||||
observeEvent(sel_details(), ignoreInit = T, {
|
observeEvent(sel_details(), ignoreInit = T, {
|
||||||
current_main_idx(getReactableState("buchungen_table", "selected"))
|
current_main_idx(getReactableState("buchungen_table", "selected"))
|
||||||
@@ -54,20 +57,20 @@ buchungenServer <- function(id, conn) {
|
|||||||
f_reactable(details_data(), coldefs = coldef_entries_tabelle, selection = "single")
|
f_reactable(details_data(), coldefs = coldef_entries_tabelle, selection = "single")
|
||||||
})
|
})
|
||||||
|
|
||||||
# Event: Detail hinzufügen (Neu)
|
# Event: Detail hinzufügen (Neu) ----
|
||||||
observeEvent(input$add_detail, {
|
observeEvent(input$add_detail, {
|
||||||
req(selected_trans_id())
|
req(selected_trans_id())
|
||||||
modal_trigger(list(post_id = NULL, counter = modal_trigger()$counter + 1))
|
modal_trigger(list(post_id = NULL, counter = modal_trigger()$counter + 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
# Event: Detail editieren (Klick auf Detail-Tabelle)
|
# Event: Detail editieren (Klick auf Detail-Tabelle) ----
|
||||||
sel_detail <- reactive(getReactableState("details_table", "selected"))
|
sel_detail <- reactive(getReactableState("details_table", "selected"))
|
||||||
observeEvent(sel_detail(), ignoreInit = T, {
|
observeEvent(sel_detail(), ignoreInit = T, {
|
||||||
p_id <- details_data()$id[sel_detail()]
|
p_id <- details_data()$id[sel_detail()]
|
||||||
modal_trigger(list(post_id = p_id, counter = modal_trigger()$counter + 1))
|
modal_trigger(list(post_id = p_id, counter = modal_trigger()$counter + 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
# --- DAS REAKTIVE UPDATE ---
|
# --- DAS REAKTIVE UPDATE ----
|
||||||
# Wenn das Modal sagt "Fertig", laden wir die Details neu
|
# Wenn das Modal sagt "Fertig", laden wir die Details neu
|
||||||
observeEvent(update_db_trigger(), ignoreInit = TRUE, {
|
observeEvent(update_db_trigger(), ignoreInit = TRUE, {
|
||||||
req(selected_trans_id())
|
req(selected_trans_id())
|
||||||
@@ -77,5 +80,32 @@ buchungenServer <- function(id, conn) {
|
|||||||
postings_data(read_buch_tabelle(conn))
|
postings_data(read_buch_tabelle(conn))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# 'Neue Transaktion' Observer ----
|
||||||
|
observeEvent(input$add_trans, {
|
||||||
|
new_t_id <- max_id(conn, "entries") + 1
|
||||||
|
|
||||||
|
# 1. Entry anlegen
|
||||||
|
dbxInsert(conn, "entries", data.frame(id = new_t_id))
|
||||||
|
|
||||||
|
# 2. Zwei Postings direkt vor-anlegen (z.B. mit Betrag 0)
|
||||||
|
p_id1 <- max_id(conn, "postings") + 1
|
||||||
|
p_id2 <- p_id1 + 1
|
||||||
|
|
||||||
|
new_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())
|
||||||
|
|
||||||
|
)
|
||||||
|
dbxInsert(conn, "postings", new_postings)
|
||||||
|
|
||||||
|
# 3. UI refreshen
|
||||||
|
selected_trans_id(new_t_id)
|
||||||
|
postings_data(read_buch_tabelle(conn))
|
||||||
|
details_data(read_buch_tabelle(conn, trans_id = new_t_id))
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user