add contracts
This commit is contained in:
@ -103,3 +103,134 @@ expense[expense$overhead_relevant]
|
||||
expense %>% filter(overhead_relevant == TRUE)
|
||||
source("~/Workspace/hv2-all-in-one/r-scripts/hv2-analysis/income.R")
|
||||
View(expense)
|
||||
knitr::opts_chunk$set(echo = TRUE)
|
||||
total_fee <- sum(income$Miete)
|
||||
knitr::opts_chunk$set(echo = TRUE)
|
||||
library(tidyverse, warn.conflicts = FALSE)
|
||||
library(DBI, warn.conflicts = FALSE)
|
||||
library(tidyr, warn.conflicts = FALSE)
|
||||
library(dplyr, warn.conflicts = FALSE)
|
||||
YEAR <- 2021
|
||||
HOME <- Sys.getenv("HOME")
|
||||
Sys.setenv(PGHOST = "db.mainscnt.eu",
|
||||
PGDATABASE = "hv2",
|
||||
PGPORT = 5432,
|
||||
PGUSER = "wn",
|
||||
PGSSLMODE = "verify-ca",
|
||||
PGSSLKEY = paste(HOME, "/keys/psql/wn-postgresql-client-2.key", sep=""),
|
||||
PGSSLCERT = paste(HOME, "/keys/psql/wn-postgresql-client-2.crt", sep=""),
|
||||
PGSSLROOTCERT = paste(HOME, "/keys/psql/postgres-ca.crt", sep=""))
|
||||
con <- dbConnect(RPostgres::Postgres())
|
||||
res <- dbSendQuery(con, "
|
||||
select f.description as flat,
|
||||
p.description as premise,
|
||||
aec.description as category,
|
||||
sum(ae.amount) as amount
|
||||
from flat_t f,
|
||||
premise_t p,
|
||||
tenancy_t ty,
|
||||
tenant_t t,
|
||||
account_t a,
|
||||
account_entry_t ae,
|
||||
account_entry_category_t aec
|
||||
where p.id = f.premise and
|
||||
ty.flat = f.id and
|
||||
ty.tenant = t.id and
|
||||
a.id = t.account and
|
||||
ae.account = a.id and
|
||||
aec.id = ae.account_entry_category and
|
||||
ae.fiscal_year = $1 and
|
||||
aec.description in ('Mietzahlung', 'Mietforderung', 'Betriebskostenforderung', 'Betriebskostenausgleich')
|
||||
group by p.description,
|
||||
f.description,
|
||||
aec.description;
|
||||
")
|
||||
dbBind(res, list(YEAR))
|
||||
income <- dbFetch(res)
|
||||
dbClearResult(res)
|
||||
income <- income %>%
|
||||
pivot_wider(names_from = category, values_from = amount) %>%
|
||||
mutate(Miete := -1 * Mietforderung) %>%
|
||||
mutate(Betriebskosten := Mietzahlung - Miete + Betriebskostenausgleich) %>%
|
||||
select(flat, premise, Miete, Betriebskosten) %>%
|
||||
arrange(premise, flat) %>%
|
||||
mutate(across(where(is.numeric), ~num(., digits=2))) %>%
|
||||
mutate(across(where(is.numeric), ~replace(., is.na(.), 0)))
|
||||
knitr::kable(income)
|
||||
total_fee <- sum(income$Miete)
|
||||
total_overhead <- sum(income$Betriebskosten)
|
||||
total_income <- total_fee + total_overhead
|
||||
View(income)
|
||||
knitr::opts_chunk$set(echo = TRUE)
|
||||
library(tidyverse, warn.conflicts = FALSE)
|
||||
library(DBI, warn.conflicts = FALSE)
|
||||
library(tidyr, warn.conflicts = FALSE)
|
||||
library(dplyr, warn.conflicts = FALSE)
|
||||
YEAR <- 2021
|
||||
HOME <- Sys.getenv("HOME")
|
||||
Sys.setenv(PGHOST = "db.mainscnt.eu",
|
||||
PGDATABASE = "hv2",
|
||||
PGPORT = 5432,
|
||||
PGUSER = "wn",
|
||||
PGSSLMODE = "verify-ca",
|
||||
PGSSLKEY = paste(HOME, "/keys/psql/wn-postgresql-client-2.key", sep=""),
|
||||
PGSSLCERT = paste(HOME, "/keys/psql/wn-postgresql-client-2.crt", sep=""),
|
||||
PGSSLROOTCERT = paste(HOME, "/keys/psql/postgres-ca.crt", sep=""))
|
||||
con <- dbConnect(RPostgres::Postgres())
|
||||
res <- dbSendQuery(con, "
|
||||
select f.description as flat,
|
||||
p.description as premise,
|
||||
aec.description as category,
|
||||
sum(ae.amount) as amount
|
||||
from flat_t f,
|
||||
premise_t p,
|
||||
tenancy_t ty,
|
||||
tenant_t t,
|
||||
account_t a,
|
||||
account_entry_t ae,
|
||||
account_entry_category_t aec
|
||||
where p.id = f.premise and
|
||||
ty.flat = f.id and
|
||||
ty.tenant = t.id and
|
||||
a.id = t.account and
|
||||
ae.account = a.id and
|
||||
aec.id = ae.account_entry_category and
|
||||
ae.fiscal_year = $1 and
|
||||
aec.description in ('Mietzahlung', 'Mietforderung', 'Betriebskostenforderung', 'Betriebskostenausgleich')
|
||||
group by p.description,
|
||||
f.description,
|
||||
aec.description;
|
||||
")
|
||||
dbBind(res, list(YEAR))
|
||||
income <- dbFetch(res)
|
||||
dbClearResult(res)
|
||||
income <- income %>%
|
||||
pivot_wider(names_from = category, values_from = amount) %>%
|
||||
mutate(Miete := -1 * Mietforderung) %>%
|
||||
mutate(Betriebskosten := Mietzahlung - Miete + Betriebskostenausgleich) %>%
|
||||
select(flat, premise, Miete, Betriebskosten) %>%
|
||||
arrange(premise, flat) %>%
|
||||
mutate(across(where(is.numeric), ~num(., digits=2))) %>%
|
||||
mutate(across(where(is.numeric), ~replace(., is.na(.), 0)))
|
||||
knitr::kable(income)
|
||||
total_fee <- sum(income$Miete)
|
||||
total_overhead <- sum(income$Betriebskosten)
|
||||
total_income <- total_fee + total_overhead
|
||||
toString(total_fee)
|
||||
total_fee$value
|
||||
total_fee[1]
|
||||
total_fee[2]
|
||||
total_fee[1]
|
||||
t=total_fee
|
||||
t
|
||||
unnest(t)
|
||||
a <- 6.4234
|
||||
a
|
||||
num(a, digits=2)
|
||||
a
|
||||
format(a, digits=2)
|
||||
format(a, digits=3)
|
||||
a<-100.4234234
|
||||
a
|
||||
format(a, digits=3)
|
||||
format(a, nsmall=2)
|
||||
|
Reference in New Issue
Block a user