Merge branch 'main' of https://git.oswaldonline.de/cosw/gemfin-shiny
This commit is contained in:
+53
-33
@@ -1,9 +1,17 @@
|
||||
# module_buchungen.R
|
||||
##
|
||||
## Datum : 2026-04-29_08-17
|
||||
## Name : Christian Oswald
|
||||
## Datei : buchungen_mod.R
|
||||
## Projekt : gemfin-shiny
|
||||
## Kommentar: Modul für die Anzeige der Buchungen - praktisch Hauptformular
|
||||
##
|
||||
|
||||
## * UI ----
|
||||
buchungenUI <- function(id) {
|
||||
ns <- NS(id)
|
||||
tagList(
|
||||
useShinyjs(),
|
||||
## ** Tabelle ----
|
||||
h3("Hauptbuchungen"),
|
||||
fluidRow(
|
||||
column(8, reactableOutput(ns("buchungen_table")),
|
||||
@@ -13,21 +21,23 @@ buchungenUI <- function(id) {
|
||||
|
||||
),
|
||||
hr(),
|
||||
## ** Gegenbuchungen ----
|
||||
h3("Details / Gegenbuchungen"),
|
||||
uiOutput(ns("details_table")) ,
|
||||
|
||||
|
||||
),
|
||||
|
||||
),
|
||||
## ** Eingabefelder ----
|
||||
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%"),
|
||||
|
||||
## ** Anhänge ----
|
||||
h3("Dateien"),
|
||||
uiOutput(ns("attachments_ui")),
|
||||
fileInput(ns("anhang"), NULL, multiple = TRUE,
|
||||
accept = c(".pdf", ".jpg", ".png", ".xlsx", ".docx"),
|
||||
width = "100%"),
|
||||
## ** Buttons ----
|
||||
div(
|
||||
style = "display: flex; flex-direction: column; gap: 10px; align-items: flex-start;",
|
||||
|
||||
@@ -44,12 +54,7 @@ buchungenUI <- function(id) {
|
||||
size = "sm", style = "material-flat", color = "success", block = TRUE, icon = icon("floppy-disk")),
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,19 +62,18 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
moduleServer(id, function(input, output, session) {
|
||||
ns <- session$ns
|
||||
|
||||
# ── Reactive Variablen ----
|
||||
## ** Reactive Variablen ----
|
||||
postings_data <- reactiveVal(read_buch_tabelle(conn))
|
||||
sel_details <- reactiveVal(NULL)
|
||||
selected_trans_id <- reactiveVal(NULL)
|
||||
selected_entry_id <- reactiveVal(NULL)
|
||||
reset_trigger <- reactiveVal(NULL)
|
||||
current_main_idx <- reactiveVal(NULL)
|
||||
|
||||
|
||||
|
||||
|
||||
# ── Filter ----
|
||||
## ** Filter ----
|
||||
aktiver_filter <- reactive(r_global$buchungen_filter)
|
||||
|
||||
gefilterte_daten <- reactive({
|
||||
d <- postings_data()
|
||||
f <- aktiver_filter()
|
||||
@@ -84,8 +88,7 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
else d
|
||||
})
|
||||
|
||||
|
||||
# ── Haupttabelle rendern ----
|
||||
## ** Haupttabelle rendern ----
|
||||
output$buchungen_table <- renderReactable({
|
||||
reset_trigger()
|
||||
f_reactable(
|
||||
@@ -96,15 +99,24 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
filterable = TRUE,
|
||||
)
|
||||
})
|
||||
|
||||
## ** Auswahl anzeigen ----
|
||||
sel <- reactive(getReactableState("buchungen_table", "selected"))
|
||||
observeEvent(sel(), ignoreInit = T, {
|
||||
idwert <- gefilterte_daten()$id[sel()]
|
||||
record <- read_posting(conn, idwert)
|
||||
record_entry <- read_entry(conn, record$entry_id)
|
||||
updateSelectizeInput(session, "contact", selected = record_entry$contact_id)
|
||||
updateTextAreaInput(session, "note", value = record_entry$purpose)
|
||||
|
||||
|
||||
|
||||
|
||||
output$details_table <- renderUI({
|
||||
req(sel())
|
||||
# Daten laden
|
||||
## *** Daten-Gegenbuchungen laden ----
|
||||
df <- read_buch_entries(conn, gefilterte_daten()$entry_id[sel()])
|
||||
sel_details(df)
|
||||
|
||||
## *** Gegenbuchungen rendern ----
|
||||
rows <- lapply(1:nrow(df), function(ind) {
|
||||
fluidRow(class = "details-row",
|
||||
# HIER: Index an die ID hängen!
|
||||
@@ -121,14 +133,11 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
})
|
||||
tagList(rows)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
observeEvent(input$save_trans, {
|
||||
req(sel_details())
|
||||
n_rows <- nrow(sel_details())
|
||||
|
||||
# Alle Zeilen in einer Liste sammeln
|
||||
all_records <- lapply(1:n_rows, function(ind) {
|
||||
data.frame(
|
||||
@@ -140,10 +149,19 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
stringsAsFactors = FALSE
|
||||
)
|
||||
})
|
||||
|
||||
# Zu einem großen Dataframe zusammenfügen
|
||||
final_df <- do.call(rbind, all_records)
|
||||
browser()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Datenbank-Update-Logik
|
||||
tryCatch({
|
||||
@@ -166,19 +184,20 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
## ** Anhänge ----
|
||||
output$attachments_ui <- renderUI({
|
||||
req(sel_details())
|
||||
entry_id <-
|
||||
dbxSelect(conn, paste0("SELECT entry_id FROM postings WHERE id=",
|
||||
sel_details()$id[1])) %>% pull
|
||||
att <- dbxSelect(conn, paste0(
|
||||
"SELECT * FROM attachments WHERE entry_id = ", entry_id
|
||||
))
|
||||
selected_entry_id(dbxSelect(conn, paste0("SELECT entry_id FROM postings WHERE id=",
|
||||
sel_details()$id[1])) %>%
|
||||
pull )
|
||||
print(selected_entry_id())
|
||||
att <- dbxSelect(conn, paste0("SELECT * FROM attachments WHERE entry_id = ", selected_entry_id() ))
|
||||
if (nrow(att) == 0) return(p("Keine Anhänge vorhanden."))
|
||||
|
||||
## *** Anhänge anzeigen ----
|
||||
tagList(lapply(seq_len(nrow(att)), function(i) {
|
||||
ext <- tools::file_ext(att$original_name[i])
|
||||
filename <- paste0("attachments/", att$id[i], ".", ext)
|
||||
filename <- paste0("www/documents/", att$id[i], ".", ext)
|
||||
|
||||
## *** Anhang öffnen ----
|
||||
observeEvent(input[[paste0("open_att_", att$id[i])]], {
|
||||
browser()
|
||||
showModal(modalDialog(
|
||||
tags$iframe(src = filename, width = "100%", height = "600px",
|
||||
style = "border:none;"),
|
||||
@@ -189,6 +208,7 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
))
|
||||
}, ignoreInit = TRUE, once = FALSE)
|
||||
|
||||
## *** Buttons Anhänge ----
|
||||
div(
|
||||
actionLink(ns(paste0("open_att_", att$id[i])), att$original_name[i]),
|
||||
actionLink(ns(paste0("del_att_", att$id[i])), "✕",
|
||||
|
||||
+25
-1
@@ -450,7 +450,7 @@ if(ok){
|
||||
anz <- length(eintraege)
|
||||
for(ind in 1:length(eintraege)){
|
||||
if( exists(paste0(zielpfad, eintraege[ind])) ){
|
||||
cat(ind, " von ", anz, "\n")
|
||||
cat(ind, " von ", anz, "\n")
|
||||
file.copy(
|
||||
from = paste0(pfad, vorhanden[ind]),
|
||||
to = "~/Documents/workspace/gemfin-shiny/www/documents/")
|
||||
@@ -498,3 +498,27 @@ dbDisconnect(con_f)
|
||||
|
||||
print("Migration finished.")
|
||||
|
||||
|
||||
## * Dateien umbenennen ----
|
||||
library("tools")
|
||||
atts <- dbReadTable(conn, "attachments")
|
||||
sum(duplicated(atts$id)) == 0
|
||||
pfad <- "www/attachments/"
|
||||
for( ind in 1:nrow(atts)){
|
||||
datei <- atts$original_name[ind]
|
||||
if( file.exists(paste0(pfad, datei)) ){
|
||||
# print(ind)
|
||||
ext <- file_ext(datei)
|
||||
idwert <- atts$id[ind]
|
||||
if(is.na(idwert)) break
|
||||
name_neu <- paste0(idwert,".",ext)
|
||||
print(name_neu)
|
||||
file.copy(from = paste0(pfad, datei), to=paste0("www/documents/", name_neu), overwrite = T)
|
||||
}
|
||||
}
|
||||
atts %>%
|
||||
filter(id == 1379)
|
||||
|
||||
which( "1379.pdf" %in% atts$original_name)
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ library("conflicted")
|
||||
library("R.utils")
|
||||
library("shinyjs")
|
||||
|
||||
conflicts_prefer(dplyr::select)
|
||||
conflicts_prefer(dplyr::filter)
|
||||
conflicts_prefer()
|
||||
conflicts_prefer()
|
||||
|
||||
|
||||
conn <- dbConnect(RSQLite::SQLite(), "db/development.sqlite")
|
||||
@@ -21,3 +21,25 @@ sourceDirectory("R/")
|
||||
source("~/R/rfunc/fehler_add.R")
|
||||
|
||||
|
||||
conflicts_prefer(
|
||||
ggplot2::`%+%`,
|
||||
shinyjs::alert,
|
||||
shinydashboard::box,
|
||||
rJava::clone,
|
||||
dplyr::select,
|
||||
dplyr::filter,
|
||||
tidyr::extract,
|
||||
shinyjs::hidden,
|
||||
dplyr::ident,
|
||||
dplyr::lag,
|
||||
shiny::printStackTrace,
|
||||
shinyjs::removeClass,
|
||||
shinyjs::reset,
|
||||
shiny::runExample,
|
||||
shiny::setProgress,
|
||||
shinyjs::show,
|
||||
dplyr::sql,
|
||||
shiny::validate,
|
||||
.quiet = TRUE
|
||||
)
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user