105 lines
4.2 KiB
R
105 lines
4.2 KiB
R
|
|
# --- MODUL UI ---
|
|
postingModuleUI <- function(id) {
|
|
ns <- NS(id)
|
|
tagList(
|
|
|
|
)
|
|
}
|
|
|
|
# --- MODUL SERVER ---
|
|
postingModuleServer <- function(id, conn, trans_id, post_id = NULL) {
|
|
moduleServer(id, function(input, output, session) {
|
|
ns <- session$ns # Wichtig für das Namespacing innerhalb des Modals
|
|
if(is.null(post_id)){
|
|
record <- read_posting(conn, trans_id)
|
|
}else {
|
|
wertstellung <- dbxSelect(conn, paste0("SELECT max(valuta) from Postings WHERE entry_id=", trans_id)) %>%
|
|
pull
|
|
record <- leer_df_from_table(conn, "postings")
|
|
record[1, "id"] <- post_id
|
|
record$entry_id <- trans_id
|
|
record$account_id <- 0
|
|
record$valuta <- wertstellung
|
|
record$booking_date <- wertstellung
|
|
}
|
|
trans <- dbxSelect(conn, paste0("SELECT * FROM entries WHERE id=", record$entry_id))
|
|
# Modal öffnen
|
|
|
|
showModal(modalDialog(
|
|
title = "Buchung-Eingabe",
|
|
|
|
|
|
f_airdatepicker_UI(ns("valuta"), "Wertstellung", record$valuta),
|
|
f_airdatepicker_UI(ns("buchungsdatum"), "Buchungsdatum", record$booking_date),
|
|
selectizeInput(ns("kontakt"), "Kontakt:",selected = trans$contact_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ünzen:", 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"),
|
|
actionBttn(ns("confirm"), "Bestätigen", style = "minimal", color = "success"),
|
|
actionBttn(ns("delete"), "Löschen", style = "minimal", color = "danger"),
|
|
splitLayout(cellWidths = c("50%", "50%"),
|
|
numericInput(ns("bid"), "ID:", value = record$id),
|
|
numericInput(ns("trans_id"), "Trans_id:", value = record$entry_id)
|
|
),
|
|
),
|
|
easyClose = TRUE
|
|
))
|
|
|
|
# Aktion beim Bestätigen
|
|
observeEvent(input$confirm, ignoreInit = T, {
|
|
trans$contact_id <- input$kontakt
|
|
trans$note <- input$trans_notiz
|
|
record$amount <- input$amount
|
|
record$account_id <- input$konto
|
|
record$project_id <- input$projekt
|
|
record$valuta <- as.character(input$valuta)
|
|
record$booking_date <- as.character(input$buchungsdatum)
|
|
record$coin_share_amount <- input$coin_share_amount
|
|
record$receipt_id <- input$receipt_id
|
|
|
|
# Check - Postings constraint
|
|
## Entweder 1 oder 0 (neu)
|
|
anz <- dbxSelect(conn, paste0("SELECT count(id) FROM postings WHERE id=", record$id)) %>% pull
|
|
ok <- anz <=1
|
|
ok <- !(is.na(record$entry_id) | record$entry_id == "") & ok
|
|
ok <- !(is.na(record$valuta) | record$valuta == "") & ok
|
|
ok <- !is.na(record$amount)
|
|
ok <- record$account_id > 0 & ok
|
|
|
|
|
|
if(ok) {
|
|
dbxUpsert(conn, "postings", records = record, where_cols = "id")
|
|
dbxUpsert(conn, "entries", records = trans, where_cols = "id")
|
|
removeModal()
|
|
return(reactive(input$confirm))
|
|
} else showNotification("Die Buchung enthält Fehler", type = "error")
|
|
|
|
})
|
|
|
|
# Aktion Detail löschen
|
|
observeEvent(input$delete, ignoreInit = T, {
|
|
anz <- dbxSelect(conn, paste0("SELECT count(entry_id) FROM postings WHERE entry_id=", record$entry_id) ) %>% pull
|
|
if(anz>1){
|
|
dbxDelete(conn, "postings", where = data.frame(id=record$id))
|
|
removeModal()
|
|
return(reactive(input$delete))
|
|
} else {
|
|
showNotification("Das ist der letzte Buchungsteil, er kann nicht gelöscht werden -> Transaktion löschen", type = "error")
|
|
}
|
|
})
|
|
|
|
#
|
|
})
|
|
} |