Buchungen funktioniern mitsamt modal und laufendem saldo

This commit is contained in:
2026-03-09 15:41:08 +01:00
parent da524d4af5
commit 5cb4eb96e8
9 changed files with 182 additions and 163 deletions
+39 -81
View File
@@ -1,93 +1,51 @@
# entry_edit_mod.R
entryEditUI <- function(id) {
# --- MODUL UI ---
postingModuleUI <- function(id) {
ns <- NS(id)
tagList(
uiOutput(ns("entry_ui")),
uiOutput(ns("postings_ui"))
)
}
entryEditServer <- function(id, entry_id, conn) {
# --- MODUL SERVER ---
postingModuleServer <- function(id, conn, idwert) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
ns <- session$ns # Wichtig für das Namespacing innerhalb des Modals
record <- read_posting(conn, idwert)
trans <- dbxSelect(conn, paste0("SELECT * FROM entries WHERE id=", record$entry_id))
# Modal öffnen
entry_postings <- reactiveVal(read_postings_by_entry(conn, entry_id))
entry_data <- reactiveVal(read_entry(conn, entry_id))
output$entry_ui <- renderUI({
e <- entry_data()
tagList(
fluidRow(
column(6, selectizeInput(ns("contact_id"), "Kontakt",
choices = get_contact_choices(conn),
selected = e$contact_id)),
column(6, textInput(ns("purpose"), "Verwendungszweck", value = e$purpose))
),
hr()
)
})
# Choices für contact nach dem Flush setzen
output$postings_ui <- renderUI({
alle <- entry_postings()
lapply(seq_len(nrow(alle)), function(i) {
print(paste("project selected:", alle$project_id[i]))
print(head(get_project_choices(conn)))
print(class(get_project_choices(conn)))
div(
style = "border-left: 3px solid #3c8dbc; padding: 5px; margin-bottom: 5px",
fluidRow(
column(3,
selectInput(ns(paste0("account_id_", i)), "Konto",
choices = get_account_choices(conn),
selected = as.character(alle$account_id[i]))
),
column(3, selectizeInput(ns(paste0("project_id_", i)), "Projekt",
choices = get_project_choices(conn),
selected = ifelse(is.na(alle$project_id[i]), "", as.character(alle$project_id[i])))
),
column(2, numericInput(ns(paste0("amount_", i)), "Betrag", value = alle$amount[i])),
column(3, textInput(ns(paste0("notiz_", i)), "Notiz", value = alle$notiz[i])),
column(1, actionButton(ns(paste0("delete_", i)), "", icon = icon("trash"), class = "btn-danger btn-sm"))
)
)
})
})
# Choices befüllen nachdem renderUI fertig ist
observe({
alle <- entry_postings()
e <- entry_data()
req(nrow(alle) > 0, nrow(e) > 0)
showModal(modalDialog(
title = "Buchung-Eingabe",
session$onFlushed(function() {
# Contact
updateSelectizeInput(session, "contact_id",
choices = get_contact_choices(conn),
selected = e$contact_id)
# Postings
lapply(seq_len(nrow(alle)), function(i) {
updateSelectizeInput(session, paste0("account_id_", i),
choices = get_account_choices(conn),
selected = alle$account_id[i])
updateSelectizeInput(session, paste0("project_id_", i),
choices = get_project_choices(conn),
selected = alle$project_id[i])
})
}, once = TRUE)
})
f_airdatepicker_UI(ns("valuta"), "Wertstellung", record$valuta),
f_airdatepicker_UI(ns("buchungsdatum"), "Buchungsdatum", record$booking_date),
selectizeInput(ns("kontakt"), "Kontakt:",selected = trans$adress_id, choices = get_contact_choices(conn), width = "100%"),
selectizeInput(ns("konto"), "Kontoname:",selected = record$account_id, choices = get_account_choices(conn), width = "100%"),
selectizeInput(ns("projekt"), "Projektname", selected = NULL, choices = get_project_choices(conn), width = "100%"),
splitLayout(cellWidths = c("70%", "30%"),
numericInput(ns("amount"), "Betrag:", value = record$amount, width = "100%"),
numericInput(ns("coin_share_amount"), "Münzne:", value = record$coin_share_amount, width = "100%")
),
textAreaInput(ns("trans_notiz"), label= "Notiz (Transaktion)", value = trans$note, width = "100%"),
splitLayout(cellWidths = c("50%", "50%"),
numericInput(ns("receipt_id"), "Umsatz_id:", value = record$receipt_id, width = "100%"),
numericInput(ns("wiso_id"), "Wiso_id:", value = record$wiso_id, width = "100%")
),
#
footer = tagList(
modalButton("Abbrechen"),
actionButton(ns("confirm"), "Bestätigen", class = "btn-success")
),
easyClose = TRUE
))
# Speichern-Logik
observeEvent(input$speichern, {
alle <- entry_postings()
lapply(seq_len(nrow(alle)), function(i) {
# update posting i in DB
})
# Aktion beim Bestätigen
observeEvent(input$confirm, ignoreInit = T, {
message("Eingabe im Modul ", id, ": ", input$user_name)
removeModal()
})
#
})
}