Adress-Modul erstellt
This commit is contained in:
@@ -33,3 +33,29 @@ f_reactable <- function(daten, coldefs = NULL, selection = "single",
|
||||
columns = coldefs
|
||||
)
|
||||
}
|
||||
|
||||
f_reactable_sub <- function(daten, coldefs = NULL) {
|
||||
reactable(
|
||||
daten,
|
||||
selection = "single",
|
||||
pagination = T,
|
||||
defaultPageSize = 17,
|
||||
showPageSizeOptions = TRUE,
|
||||
filterable = TRUE,
|
||||
highlight = TRUE,
|
||||
bordered = TRUE,
|
||||
striped = FALSE,
|
||||
compact = TRUE,
|
||||
# Styling
|
||||
theme = reactableTheme(
|
||||
highlightColor = "#e6f7ff", # Etwas dezenter als knallgrün, optional
|
||||
# borderColor = "#dfe2e5",
|
||||
rowSelectedStyle = list(backgroundColor = "#98F5FF")#
|
||||
),
|
||||
rowStyle = function(index) {
|
||||
style <- list(cursor = "pointer") # immer aktiv
|
||||
},
|
||||
onClick = "select",
|
||||
columns = coldefs
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
##
|
||||
## Datum: 2024-10-17_14-31
|
||||
## Name: Christian Oswald
|
||||
## Projekt: etatverwaltung
|
||||
## Datei: f_zeitstempel.R
|
||||
## Kommentar: Erstellt einen Zeitstempel für die DB-Felder updatea und created
|
||||
##
|
||||
|
||||
# Funkton die prüft ob das Format stimmt
|
||||
is.ymd_hms <- function(x) !is.na(lubridate::ymd_hms(x, quiet = TRUE))
|
||||
# Zeitstempel
|
||||
f_zeitstempel <- function(ts){
|
||||
# Erstellt einen wenn leer
|
||||
if(is.na(ts)) ts <- format(Sys.time(), tz="")
|
||||
# Erstellt einen wenn das Format nicht stimmt
|
||||
if(!is.ymd_hms(ts)) ts <- format(Sys.time(), tz="")
|
||||
return(ts)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
##
|
||||
## Datum : 2026-04-28_13-43
|
||||
## Name : Christian Oswald
|
||||
## Datei : contact_io.R
|
||||
## Projekt : gemfin-shiny
|
||||
## Kommentar: Befüllt die Felder und liest sie aus
|
||||
##
|
||||
|
||||
contact_io <- function(session, input, output, record, flag){
|
||||
if(flag == "lesen"){
|
||||
record[1,"id"] <- input$cid
|
||||
record$first_name <- input$first_name
|
||||
record$last_name <- input$last_name
|
||||
record$postal_code <- input$postal_code
|
||||
record$city <- input$city
|
||||
record$street <- input$street
|
||||
record$phone <- input$phone
|
||||
record$mobile <- input$mobile
|
||||
record$email <- input$email
|
||||
record$member <- input$member
|
||||
record$display_name <- input$display_name
|
||||
record$is_company <- input$is_company
|
||||
record$notes <- input$note
|
||||
record$created_at <- f_zeitstempel( record$created_at)
|
||||
record$updated_at <- format(Sys.time(), tz="")
|
||||
return(record)
|
||||
}
|
||||
if(flag == "schreiben"){
|
||||
updateNumericInput(session,"cid", value = record$id)
|
||||
updateTextInput(session,"display_name", value = record$display_name)
|
||||
updateTextInput(session,"first_name", value = record$first_name)
|
||||
updateTextInput(session,"last_name", value = record$last_name)
|
||||
updateTextInput(session,"postal_code", value = record$postal_code)
|
||||
updateTextInput(session,"city", value = record$city)
|
||||
updateTextInput(session,"email", value = record$email)
|
||||
updateTextInput(session,"street", value = record$street)
|
||||
updateTextInput(session,"mobile", value = record$mobile)
|
||||
updateTextInput(session,"phone", value = record$phone)
|
||||
updateTextAreaInput(session,"note", value = record$notes)
|
||||
updateCheckboxInput(session, "is_company", value = record$is_company)
|
||||
updateCheckboxInput(session, "member", value = record$member)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,22 @@
|
||||
##
|
||||
## Datum : 2026-04-28_13-11
|
||||
## Name : Christian Oswald
|
||||
## Datei : contacts.R
|
||||
## Projekt : gemfin-shiny
|
||||
## Kommentar: model für contacts
|
||||
##
|
||||
|
||||
|
||||
f_contacts_tabelle <- function(conn){
|
||||
tbl(conn, "contacts") %>%
|
||||
select(id, display_name, street, city, member) %>%
|
||||
arrange(display_name) %>%
|
||||
collect
|
||||
}
|
||||
|
||||
f_contact <- function(conn, idwert){
|
||||
dbxSelect(conn, paste0("SELECT * FROM contacts WHERE id=", idwert))
|
||||
}
|
||||
|
||||
get_contact_choices <- function(conn) {
|
||||
contacts <- tbl(conn, "contacts") |>
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
contactsUI <- function(id) {
|
||||
ns <- NS(id)
|
||||
tagList(
|
||||
useShinyjs(),
|
||||
# Sync-Button oben
|
||||
div(
|
||||
style = "display: flex; justify-content: flex-end; margin-bottom: 8px;",
|
||||
actionBttn(ns("sync"), "Sync Hibiscus",
|
||||
size = "xs", style = "minimal",
|
||||
icon = icon("rotate"), color = "primary")
|
||||
),
|
||||
sidebarLayout(
|
||||
sidebarPanel(width = 6,
|
||||
reactableOutput(ns("contacts_table"), height = 800)
|
||||
|
||||
),
|
||||
mainPanel(width = 6,
|
||||
fluidRow(
|
||||
column(8, textInput(ns("display_name"), label = "Bezeichnung", value = NA, width = "100%")),
|
||||
column(4, numericInput(ns("cid"), label = "ID", value = NA, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(6, textInput(ns("first_name"), label = "Vorname", value = NA, width = "100%")),
|
||||
column(6, textInput(ns("last_name"), label = "Nachname", value = NA, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(12, textInput(ns("street"), label = "Strasse", value = NA, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(4, textInput(ns("postal_code"), label = "PLZ", value = NA, width = "100%")),
|
||||
column(8, textInput(ns("city"), label = "Ort", value = NA, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(4, textInput(ns("phone"), label = "Telefon", value = NA, width = "100%")),
|
||||
column(4, textInput(ns("mobile"), label = "Mobil", value = NA, width = "100%")),
|
||||
column(4, textInput(ns("email"), label = "E-Mail", value = NA, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(4, checkboxInput(ns("is_company"), label = "Firma", value = F, width = "100%")),
|
||||
column(4, checkboxInput(ns("member"), label = "Mitglied", value = F, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(12, textAreaInput(ns("note"), label = "Notiz", value = NA, width = "100%"))
|
||||
),
|
||||
fluidRow(
|
||||
column(4, actionBttn(ns("add"), "Neu", size = "sm", style = "material-flat", color = "warning", icon = icon("plus"), block = T)),
|
||||
column(4, actionBttn(ns("del"), "Löschen", size = "sm", style = "material-flat", color = "danger", icon = icon("thrash"), block = T)),
|
||||
column(4, actionBttn(ns("save"), "Speichern", size = "sm", style = "material-flat", color = "success", icon = icon("floppy-disk"), block = T)),
|
||||
),
|
||||
br(),
|
||||
reactableOutput(ns("entries"))
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
contactsServer <- function(id, conn, r_global) {
|
||||
moduleServer(id, function(input, output, session) {
|
||||
ns <- session$ns
|
||||
|
||||
# ── Daten ----
|
||||
refresh <- reactiveVal(0)
|
||||
zeige_alle <- reactiveVal(FALSE)
|
||||
|
||||
contact_data <- reactive({
|
||||
f_contacts_tabelle(conn)
|
||||
})
|
||||
|
||||
|
||||
# ── Filter-Buttons ----
|
||||
observeEvent(input$mitglieder, { zeige_alle(FALSE) })
|
||||
observeEvent(input$filter_alle, { zeige_alle(TRUE) })
|
||||
|
||||
# ── Tabelle ----
|
||||
output$contacts_table <- renderReactable({
|
||||
reactable(
|
||||
contact_data(),
|
||||
striped = TRUE,
|
||||
highlight = TRUE,
|
||||
filterable = T,
|
||||
pagination = F,
|
||||
selection = "single",
|
||||
onClick = "select",
|
||||
defaultSorted = list(display_name = "asc"),
|
||||
columns = list(
|
||||
id = colDef(show = FALSE),
|
||||
display_name = colDef( name = "Bezeichnung", minWidth = 150 ),
|
||||
street = colDef(name = "Strasse", minWidth = 150),
|
||||
city = colDef(name = "Ort", minWidth = 150),
|
||||
member = colDef(name = "Mitglied", maxWidth = 80,
|
||||
align = "center")
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
## * Selektierter Umsatz ----
|
||||
sel <- reactive(getReactableState("contacts_table", "selected"))
|
||||
observeEvent(sel(), ignoreInit = T, {
|
||||
idwert <- contact_data()$id[sel()]
|
||||
record <- f_contact(conn, idwert)
|
||||
contact_io(session, input, output, record, "schreiben")
|
||||
# ── Buchungs-Panel ----
|
||||
entries <- read_buch_tabelle(conn) %>%
|
||||
filter(contact_id == idwert) %>%
|
||||
select(id, valuta, account_name, projektname, amount)
|
||||
output$entries <- renderReactable(
|
||||
reactable(entries,
|
||||
striped = TRUE,
|
||||
highlight = TRUE,
|
||||
searchable = T,
|
||||
filterable = F,
|
||||
pagination = T,
|
||||
defaultPageSize = 6,
|
||||
selection = "single",
|
||||
onClick = "select",
|
||||
columns = list(
|
||||
id = colDef(show = FALSE),
|
||||
valuta = colDef(name = "Wertstellung", minWidth = 80),
|
||||
account_name = colDef( name = "Konto", minWidth = 150 ),
|
||||
projektname = colDef(name = "Projekt", minWidth = 150),
|
||||
amount = colDef(name = "Betrag", minWidth = 150)
|
||||
)
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
## * Speichern ----
|
||||
observeEvent(input$save, ignoreInit = T, {
|
||||
record <- leer_df_from_table(conn, "contacts")
|
||||
record <- contact_io(session, input, output, record, "lesen")
|
||||
print(record)
|
||||
dbxUpsert(conn, "contacts", records = record, where_cols = c("id"))
|
||||
})
|
||||
|
||||
## * Hinzufügen ----
|
||||
observeEvent(input$add, ignoreInit = T, {
|
||||
record <- leer_df_from_table(conn, "contacts")
|
||||
record$id <- max_id(conn, "contacts")
|
||||
record <- contact_io(session, input, output, record, "schreiben")
|
||||
})
|
||||
## * Löschen ----
|
||||
observeEvent(input$del, ignoreInit = T, {
|
||||
dbxDelete(conn, "contacts", where = data.frame(id = input$cid))
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ── Zur Buchung springen ----
|
||||
# observeEvent(input$goto_buchung, {
|
||||
# req(selected_umsatz())
|
||||
# r_global$nav_history <- c(r_global$nav_history, list(list(tab = "umsatz")))
|
||||
# r_global$jump_to_entry_id <- selected_umsatz()$entry_id
|
||||
# r_global$active_tab <- "buchungen"
|
||||
# })
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
@@ -22,7 +22,7 @@ read_buch_tabelle <- function(conn, trans_id = NULL){
|
||||
left_join(accounts, by = c("account_id" = "id")) |>
|
||||
left_join(projects, by = c("project_id" = "id")) |>
|
||||
left_join(attachment_counts, by = "entry_id") |>
|
||||
select(id, valuta, account_name, projektname, display_name, amount, entry_id, n_attachments, account_id) |>
|
||||
select(id, valuta, account_name, projektname, display_name, amount, entry_id, n_attachments, account_id, contact_id) |>
|
||||
collect() %>%
|
||||
mutate(
|
||||
saldo = 0,
|
||||
|
||||
@@ -123,13 +123,13 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
)
|
||||
})
|
||||
|
||||
# ── Detail hinzufügen ──────────────────────────────────────────────────────
|
||||
# ── Detail hinzufügen ----
|
||||
observeEvent(input$add_detail, {
|
||||
req(selected_trans_id())
|
||||
modal_trigger(list(post_id = NULL, counter = modal_trigger()$counter + 1))
|
||||
})
|
||||
|
||||
# ── Detail editieren ───────────────────────────────────────────────────────
|
||||
# ── Detail editieren ----
|
||||
sel_detail <- reactive(getReactableState("details_table", "selected"))
|
||||
|
||||
observeEvent(sel_detail(), ignoreInit = TRUE, {
|
||||
@@ -137,7 +137,7 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
modal_trigger(list(post_id = p_id, counter = modal_trigger()$counter + 1))
|
||||
})
|
||||
|
||||
# ── DB-Update durch Modal ──────────────────────────────────────────────────
|
||||
# ── DB-Update durch Modal ----
|
||||
observeEvent(update_db_trigger(), ignoreInit = TRUE, {
|
||||
req(selected_trans_id())
|
||||
details_data(read_buch_tabelle(conn, trans_id = selected_trans_id()))
|
||||
@@ -145,7 +145,7 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
updateReactable("buchungen_table", data = gefilterte_daten())
|
||||
})
|
||||
|
||||
# ── Neue Transaktion ───────────────────────────────────────────────────────
|
||||
# ── Neue Transaktion ----
|
||||
observeEvent(input$add_trans, {
|
||||
new_t_id <- max_id(conn, "entries") + 1
|
||||
dbxInsert(conn, "entries", data.frame(id = new_t_id))
|
||||
@@ -172,7 +172,7 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
scroll_to_row(ns("buchungen_table"), neue_zeile)
|
||||
})
|
||||
|
||||
# ── Transaktion löschen ────────────────────────────────────────────────────
|
||||
# ── Transaktion löschen ----
|
||||
observeEvent(input$del_trans, ignoreInit = TRUE, {
|
||||
req(selected_trans_id())
|
||||
dbxDelete(conn, "postings", where = data.frame(entry_id = selected_trans_id()))
|
||||
@@ -184,7 +184,7 @@ buchungenServer <- function(id, conn, r_global) {
|
||||
updateReactable("buchungen_table", data = gefilterte_daten())
|
||||
})
|
||||
|
||||
# ── Anhänge ────────────────────────────────────────────────────────────────
|
||||
# ── Anhänge ----
|
||||
output$attachments_ui <- renderUI({
|
||||
req(selected_trans_id())
|
||||
att <- dbxSelect(conn, paste0(
|
||||
|
||||
Binary file not shown.
@@ -54,4 +54,5 @@ server <- function(input, output, session) {
|
||||
accountsServer("accounts_tab", conn, r_global)
|
||||
buchungenServer("buchungen_tab", conn, r_global)
|
||||
umsatzServer("umsatz_tab", conn, r_global)
|
||||
contactsServer("contacts_tab", conn, r_global)
|
||||
}
|
||||
@@ -49,7 +49,8 @@ dashboardPage(
|
||||
sidebarMenu(id = "tabs",
|
||||
menuItem("Buchungen", tabName = "buchungen", icon = icon("list")),
|
||||
menuItem("Umsätze", tabName = "umsatz", icon = icon("bank")),
|
||||
menuItem("Konten", tabName = "konten", icon = icon("building-columns"))
|
||||
menuItem("Konten", tabName = "konten", icon = icon("building-columns")),
|
||||
menuItem("Adressen", tabName = "contacts", icon = icon("people-group"))
|
||||
)
|
||||
),
|
||||
|
||||
@@ -63,6 +64,9 @@ dashboardPage(
|
||||
),
|
||||
tabItem(tabName = "konten",
|
||||
accountsUI("accounts_tab")
|
||||
),
|
||||
tabItem(tabName = "contacts",
|
||||
contactsUI("contacts_tab")
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user