Buchungen funktioniern mitsamt modal und laufendem saldo
This commit is contained in:
+54
-8
@@ -1,5 +1,10 @@
|
||||
read_buch_tabelle <- function(conn){
|
||||
postings <- tbl(conn, "postings")
|
||||
read_buch_tabelle <- function(conn, trans_id = NULL){
|
||||
if(!is.null(trans_id)){
|
||||
postings <- tbl(conn, "postings") %>%
|
||||
filter(entry_id == trans_id)
|
||||
} else {
|
||||
postings <- tbl(conn, "postings")
|
||||
}
|
||||
entries <- tbl(conn, "entries")
|
||||
accounts <- tbl(conn, "accounts")
|
||||
projects <- tbl(conn, "projects")
|
||||
@@ -9,14 +14,55 @@ read_buch_tabelle <- function(conn){
|
||||
left_join(contacts, by = c("contact_id" = "id")) |> # contact_id jetzt verfügbar
|
||||
left_join(accounts, by = c("account_id" = "id")) |>
|
||||
left_join(projects, by = c("project_id" = "id")) |>
|
||||
select(id, valuta, kontoname, projektname, display_name, amount, entry_id) |>
|
||||
collect()
|
||||
select(id, valuta, account_name, projektname, display_name, amount, entry_id) |>
|
||||
collect() %>%
|
||||
mutate(saldo = 0)
|
||||
}
|
||||
|
||||
read_posting <- function(conn, id){
|
||||
dbxSelect(conn, paste0("SELECT * FROM postings WHERE id =", id))
|
||||
}
|
||||
read_postings_by_entry <- function(conn, id){
|
||||
dbxSelect(conn, paste0("SELECT * FROM postings WHERE entry_id =", id))
|
||||
}
|
||||
tbl(conn, "accounts") %>% collect %>% str
|
||||
|
||||
|
||||
coldef_entries_tabelle <-
|
||||
list(
|
||||
id = colDef(name = "ID", width = 80),
|
||||
valuta = colDef(name = "Wertstellung", width = 120),
|
||||
account_name = colDef(name = "Kontoname", width = 200),
|
||||
projektname = colDef(name = "Projektname", width = 150),
|
||||
display_name = colDef(name = "Kontakt", width = 250),
|
||||
amount = colDef(name = "Betrag", width = 120,
|
||||
format = colFormat(prefix = "", separators = TRUE, digits = 2),
|
||||
style = function(value) {
|
||||
color <- if (value < 0) "#e06666" else "#2b2b2b" # Rot bei negativ, sonst dunkelgrau
|
||||
list(color = color, fontWeight = "bold") # Gibt CSS-Styles zurück
|
||||
}
|
||||
),
|
||||
entry_id = colDef(name ="trans_id", width = 120),
|
||||
saldo = colDef(
|
||||
name = "Saldo",
|
||||
width = 140,
|
||||
html = TRUE,
|
||||
cell = JS("
|
||||
function(cellInfo, state) {
|
||||
const page = state.page || 0
|
||||
const pageSize = state.pageSize || state.sortedData.length
|
||||
const globalIndex = page * pageSize + cellInfo.viewIndex
|
||||
|
||||
let total = 0
|
||||
for (let i = 0; i <= globalIndex && i < state.sortedData.length; i++) {
|
||||
total += Number(state.sortedData[i].amount || 0)
|
||||
}
|
||||
|
||||
const color = total < 0 ? '#e06666' : '#2b2b2b'
|
||||
|
||||
return `<span style='color:${color}; font-weight:bold'>
|
||||
${total.toLocaleString('de-DE', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2
|
||||
})}
|
||||
</span>`
|
||||
}
|
||||
")
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user