Adress-Modul erstellt
This commit is contained in:
@@ -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"
|
||||
# })
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user