|
@@ -43,7 +43,8 @@ def actuals(period):
|
|
|
df["FCQ"] = df["YTDQ"] * 12 / month_no
|
|
|
df.drop(columns=["Menge", "Betrag"], inplace=True)
|
|
|
|
|
|
- # df2 = pd.pivot_table(df, values='Betrag', index=['Konto Nr', 'Betrieb Nr'], columns=['Jahr'], aggfunc=np.sum, fill_value=0.0)
|
|
|
+ # df2 = pd.pivot_table(df, values='Betrag', index=['Konto Nr', 'Betrieb Nr'],
|
|
|
+ # columns=['Jahr'], aggfunc=np.sum, fill_value=0.0)
|
|
|
df = df.groupby(["Konto_Nr", "Betrieb_Nr"]).sum()
|
|
|
print(df.head())
|
|
|
|
|
@@ -68,8 +69,9 @@ def planning_prev(year):
|
|
|
encoding="latin-1",
|
|
|
dtype={"Betrieb Nr": str, "Bereich": str, "Zeile": str},
|
|
|
)
|
|
|
- df1["Wert"] = df1["Gesamt"]
|
|
|
- df1 = df1[["Jahr", "Betrieb Nr", "Vstufe 1", "Bereich", "Zeile", "Konto", "Version", "Wert"]]
|
|
|
+ df1["Wert"] = np.where(df1["Vstufe 1"] == "Umsatzerlöse", df1["Gesamt"], df1["Gesamt"] * -1)
|
|
|
+ df1["Menge"] = 0
|
|
|
+ df1 = df1[["Jahr", "Betrieb Nr", "Vstufe 1", "Bereich", "Zeile", "Konto", "Version", "Wert", "Menge"]]
|
|
|
|
|
|
df2 = pd.read_csv(
|
|
|
base_dir / f"data/Planner_{year}_V1_Stk.csv",
|
|
@@ -78,26 +80,28 @@ def planning_prev(year):
|
|
|
encoding="latin-1",
|
|
|
dtype={"Betrieb Nr": str, "Bereich": str, "Zeile": str},
|
|
|
)
|
|
|
- df2["Menge"] = df2["Gesamt"]
|
|
|
+ df2.rename(columns={"Gesamt": "Menge"}, inplace=True)
|
|
|
+ df2["Wert"] = 0
|
|
|
df2["Vstufe 1"] = "Umsatzerlöse"
|
|
|
- df2 = df2[["Jahr", "Betrieb Nr", "Vstufe 1", "Bereich", "Zeile", "Konto", "Version", "Menge"]]
|
|
|
- df = pd.merge(df1, df2, how="left", on=["Jahr", "Betrieb Nr", "Vstufe 1", "Bereich", "Zeile", "Konto", "Version"])
|
|
|
- df["Menge"] = df["Menge"].fillna(0)
|
|
|
- df["Wert"] = df["Wert"].fillna(0)
|
|
|
- df["Wert"] = np.where(df["Vstufe 1"] == "Umsatzerlöse", df["Wert"], df["Wert"] * -1)
|
|
|
+ df2 = df2[["Jahr", "Betrieb Nr", "Vstufe 1", "Bereich", "Zeile", "Konto", "Version", "Wert", "Menge"]]
|
|
|
+
|
|
|
+ df = pd.concat([df1, df2])
|
|
|
|
|
|
df["Bereich"] = df["Bereich"].fillna("NA").replace("VW (inkl. GF)", "?")
|
|
|
df["regex"] = df["Vstufe 1"] + ";" + df["Bereich"] + ";.*" + df["Zeile"] + " - [^;]*;;"
|
|
|
- df = df[df["Wert"] != 0]
|
|
|
|
|
|
gcstruct = json.load(open(base_dir / "export/gcstruct.json", "r"))
|
|
|
structure_ids = [s["id"] for s in gcstruct["flat"]["Struktur_FB"]]
|
|
|
|
|
|
df["id"] = df["regex"].apply(lambda x: (list(filter(lambda y: match(x, y), structure_ids)) + [""])[0])
|
|
|
+ df["order_by"] = df.index
|
|
|
df = df[df["id"] != ""]
|
|
|
|
|
|
+ df_grouped = df.groupby(by=["id", "Betrieb Nr"], sort=False).aggregate("sum").reset_index()
|
|
|
+ df_grouped = df_grouped[df_grouped["Wert"] != 0] # .sort_values(by="order_by")
|
|
|
+
|
|
|
res = {}
|
|
|
- for item in df.to_dict(orient="records"):
|
|
|
+ for item in df_grouped.to_dict(orient="records"):
|
|
|
if item["id"] not in res:
|
|
|
res[item["id"]] = {}
|
|
|
res[item["id"]][item["Betrieb Nr"]] = [item["Wert"], item["Menge"]]
|