Neues Dashboard: Kostenobjekte
This commit is contained in:
3
app/data/datasets.py
Normal file
3
app/data/datasets.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from scriptloader import get_sql
|
||||
from db import get_conn
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import streamlit as st
|
||||
from sqlalchemy import create_engine, Text
|
||||
from data.scriptloader import get_sql
|
||||
import oracledb
|
||||
import pandas as pd
|
||||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
@@ -26,6 +29,25 @@ def get_conn(db):
|
||||
logging.info(f"Datenbank {db} konnte nicht gefunden werden")
|
||||
return engine
|
||||
|
||||
def load_data(sql_file, db):
|
||||
sql = get_sql(sql_file)
|
||||
engine = get_conn(db)
|
||||
with engine.connect():
|
||||
df = pd.read_sql(sql, engine)
|
||||
return df
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# def get_data(db):
|
||||
# engine = get_conn(db)
|
||||
# with engine.connect() as conn:
|
||||
|
||||
@@ -7,4 +7,4 @@ def get_sql(filename):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_sql("sales_umsatz"))
|
||||
print(get_sql("ergebnis_kpi"))
|
||||
|
||||
92
app/data/sql/ergebnis_kpi.sql
Normal file
92
app/data/sql/ergebnis_kpi.sql
Normal file
@@ -0,0 +1,92 @@
|
||||
/*******************************************************************************************
|
||||
* Basis-Daten aus der Kostenrechnung
|
||||
*******************************************************************************************/
|
||||
with basis as(
|
||||
Select
|
||||
p.geschaeftsjahr as jahr,
|
||||
p.geschaeftsperiode as monat,
|
||||
p.periode_key,
|
||||
b.zgrp1,
|
||||
b.zgrp2,
|
||||
b.zgrp3,
|
||||
b.bezeichnung as Bereich,
|
||||
ko.kostenobjekt,
|
||||
ko.bezeichnung as obj_bezeichnung,
|
||||
ko.obj_text,
|
||||
ko.objektgruppe,
|
||||
ko.objekttyp,
|
||||
ko.verantwortlicher,
|
||||
ks.co_koa_grp,
|
||||
ks.co_grp_bez,
|
||||
ks.co_grp_text,
|
||||
ks.kostenart,
|
||||
ks.koa_text,
|
||||
coalesce(ws.uml_kz,'') as uml_kz,
|
||||
coalesce(ws.zgrp_1_entlastung, '') as zgrp1_entlastung,
|
||||
coalesce(ws.wert * -1, 0) as wert,
|
||||
coalesce(ws.wert_plan * -1, 0) as wert_plan,
|
||||
0 as wert_forecast
|
||||
from
|
||||
co_dw.bi.fact_wertsummen ws
|
||||
left join co_dw.bi.dim_periode p
|
||||
on ws.periode_key = p.periode_key
|
||||
left join co_dw.bi.dim_kostenobjekt ko
|
||||
on ws.objekt_key = ko.objekt_key
|
||||
left join co_dw.bi.dim_koastruktur ks
|
||||
on ws.kostenart = ks.kostenart
|
||||
left join co_dw.bi.dim_bereich b
|
||||
on ko.bereich_key = b.bereich_key
|
||||
where
|
||||
ks.co_koa_grp_01 = 'GMN001'
|
||||
and ko.objektgruppe in ('HKST', 'VKST', 'KTRG', 'KtrBereich', 'KtrMNr')
|
||||
and p.geschaeftsperiode < 14
|
||||
and (p.geschaeftsjahr = :jahr or p.geschaeftsjahr = :jahr -1)
|
||||
),
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************************
|
||||
* Gesamtergebnis
|
||||
*******************************************************************************************/
|
||||
ergebnis_gesamt as (
|
||||
select
|
||||
zgrp1,
|
||||
zgrp2,
|
||||
zgrp3,
|
||||
kostenobjekt,
|
||||
obj_bezeichnung,
|
||||
obj_text,
|
||||
co_koa_grp,
|
||||
co_grp_bez,
|
||||
co_grp_text,
|
||||
'Ergebnis' as main_kpi,
|
||||
'Gesamtergebnis' as kpi,
|
||||
round(sum(case when jahr = :jahr-1 then wert else 0 end),0) as vor_jahr,
|
||||
round(sum(case when jahr = :jahr-1 and monat <= :monat then wert else 0 end),0) as vor_jahr_bis_monat,
|
||||
round(sum(case when jahr = :jahr-1 and monat = :monat then wert else 0 end),0) as vor_jahr_monat,
|
||||
round(sum(case when jahr = :jahr then wert else 0 end),0) as akt_jahr,
|
||||
round(sum(case when jahr = :jahr and monat <= :monat then wert else 0 end),0) as akt_jahr_bis_monat,
|
||||
round(sum(case when jahr = :jahr and monat = :monat then wert else 0 end),0) as akt_jahr_monat,
|
||||
round(sum(case when jahr = :jahr then wert_plan else 0 end),0) as plan_akt_jahr,
|
||||
round(sum(case when jahr = :jahr and monat <= :monat then wert_plan else 0 end),0) as plan_akt_jahr_bis_monat,
|
||||
round(sum(case when jahr = :jahr and monat = :monat then wert_plan else 0 end),0) as plan_akt_jahr_monat,
|
||||
round(sum(case when jahr = :jahr then wert_forecast else 0 end),0) as forecast_akt_jahr,
|
||||
round(sum(case when jahr = :jahr and monat <= :monat then wert_forecast else 0 end),0) as forecast_akt_jahr_bis_monat,
|
||||
round(sum(case when jahr = :jahr and monat = :monat then wert_forecast else 0 end),0) as forecast_akt_jahr_monat
|
||||
from
|
||||
basis
|
||||
group by
|
||||
zgrp1,
|
||||
zgrp2,
|
||||
zgrp3,
|
||||
kostenobjekt,
|
||||
obj_bezeichnung,
|
||||
obj_text,
|
||||
co_koa_grp,
|
||||
co_grp_bez,
|
||||
co_grp_text
|
||||
)
|
||||
|
||||
|
||||
select * from ergebnis_gesamt
|
||||
select * from co_dw.bi.Fact_Wertsummen
|
||||
19
app/data/sql/ora_kostenobjekte.sql
Normal file
19
app/data/sql/ora_kostenobjekte.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
/* Orlacle (PENTA) Kostenobjekte */
|
||||
|
||||
select
|
||||
GESCHAEFTSJAHR as jahr,
|
||||
OBJEKTTYP as typ,
|
||||
KOSTENOBJEKT as obj,
|
||||
BEZEICHNUNG,
|
||||
VERANTWORTLICHER,
|
||||
FELD_2_X30 as VORGESETZER,
|
||||
ZUORDNUNGSGRUPPE_1 as zgrp1,
|
||||
ZUORDNUNGSGRUPPE_2 as zgrp2,
|
||||
ZUORDNUNGSGRUPPE_3 as zgrp3,
|
||||
ZUORDNUNGSGRUPPE_4 as zgrp4,
|
||||
ZUORDNUNGSGRUPPE_5 as zgrp5,
|
||||
ZUORDNUNGSGRUPPE_6 as zgrp6,
|
||||
FELD_1_X30 as fertigung,
|
||||
OBJEKTGRUPPE as objgrp
|
||||
from
|
||||
pkos
|
||||
Reference in New Issue
Block a user