فهرست منبع

GCHR / GCHRStruct-Export

gc-server3 11 ساعت پیش
والد
کامیت
c450b4b6f9
9فایلهای تغییر یافته به همراه168 افزوده شده و 21 حذف شده
  1. 7 0
      config/gchr2.json
  2. BIN
      dist/gchr2.exe
  3. BIN
      dist/gchrstruct_export.exe
  4. 5 1
      gchr/gchr.py
  5. 45 1
      gchr/gchr_translate.py
  6. 4 0
      gchrstruct_export.bat
  7. 18 0
      gchrstruct_export.py
  8. 38 0
      gchrstruct_export.spec
  9. 51 19
      gcstruct/gcstruct.py

+ 7 - 0
config/gchr2.json

@@ -0,0 +1,7 @@
+{
+  "first_month_of_financial_year": "01",
+  "data_dir": "C:\\Projekte\\Python\\data",
+  "gcstruct_dir": "C:\\Projekte\\Python\\..\\GCStruct_Aufbereitung",
+  "export_dir": "C:\\Projekte\\Python\\Export",
+  "export_format": "SKR51"
+}

BIN
dist/gchr2.exe


BIN
dist/gchrstruct_export.exe


+ 5 - 1
gchr/gchr.py

@@ -89,7 +89,11 @@ class GCHR:
         all_periods = set(df_bookings["Bookkeep Period"].to_list())
         bookkeep_period_date = datetime(int(year), int(month), 28)
 
-        if df_bookings.shape[0] == 0 or len(all_periods) <= 1 or self.bookings.booking_date < bookkeep_period_date:
+        if (
+            df_bookings.shape[0] == 0
+            or (len(all_periods) <= 1 and all_periods[0][-2:] == "00")
+            or self.bookings.booking_date < bookkeep_period_date
+        ):
             logging.error("ABBRUCH!!! Keine Daten vorhanden!")
             return False
 

+ 45 - 1
gchr/gchr_translate.py

@@ -61,7 +61,7 @@ def get_sites_from_translation(df_translate_import: pd.DataFrame) -> dict[str, s
     return sites
 
 
-def prepare_translation(df_translate_import: pd.DataFrame, dest_account: str = "01-01-0861-00-00-00") -> pd.DataFrame:
+def prepare_translation(df_translate_import: pd.DataFrame, dest_account: str = "01-01-0860-10-00-00") -> pd.DataFrame:
     df = df_translate_import[
         [
             "Konto_Nr_Händler",
@@ -189,6 +189,50 @@ def special_translation(
     )
     df["Kostenträger"] = np.where(df["MW_KTR_70_VZ"] == True, "00", df["Kostenträger"])
 
+    # Volkswagen Specials
+    kto_1250 = (df["Konto_Nr"].str.match(r"^1250")) & ~(df["Kostenstelle"].str.match(r"^1"))
+    df["Kostenstelle"] = np.where(kto_1250, "11", df["Kostenstelle"])
+
+    kto_1729 = (df["Konto_Nr"].str.match(r"^1729")) & (df["Kostenstelle"].str.match(r"^9"))
+    df["Kostenstelle"] = np.where(kto_1729, "11", df["Kostenstelle"])
+
+    kto_1795 = (df["Konto_Nr"].str.match(r"^1795")) & ~(df["Kostenstelle"].str.match(r"^3"))
+    df["Kostenstelle"] = np.where(kto_1795, "31", df["Kostenstelle"])
+
+    kto_2 = (df["Konto_Nr"].str.match(r"^2")) & (df["Kostenträger"].str.match(r"^70"))
+    df["Kostenträger"] = np.where(kto_2, "00", df["Kostenträger"])
+
+    kto_4560 = (df["Konto_Nr"].isin(["4560", "4570", "5004"])) & (df["Kostenträger"].str.match(r"^70"))
+    df["Kostenträger"] = np.where(kto_4560, "00", df["Kostenträger"])
+
+    kto_8520 = (df["Konto_Nr"].isin(["8520", "8900"])) & (df["Kostenstelle"].str.match(r"^51"))
+    df["Kostenträger"] = np.where(kto_8520, "00", df["Kostenträger"])
+
+    kto_8999 = (df["Konto_Nr"].isin(["8999"])) & (df["Kostenstelle"].str.match(r"^30"))
+    df["Kostenträger"] = np.where(kto_8999, "00", df["Kostenträger"])
+
+    kto_8860 = df["Konto_Nr"].isin(["8860"])
+    df["Kostenträger"] = np.where(kto_8860, "00", df["Kostenträger"])
+
+    kto_3000 = (df["Konto_Nr"].isin(["3000", "3001"])) & ~(df["Kostenstelle"].isin(["10", "11", "13"]))
+    df["Kostenstelle"] = np.where(kto_3000, "11", df["Kostenstelle"])
+
+    kto_3010 = df["Konto_Nr"].isin(["3010", "3011"])
+    df["Kostenstelle"] = np.where(kto_3010, "14", df["Kostenstelle"])
+
+    kto_3110 = (df["Konto_Nr"].isin(["3110"])) & (df["Kostenstelle"].str.match(r"^1"))
+    df["Kostenstelle"] = np.where(kto_3110, "20", df["Kostenstelle"])
+
+    kto_3300 = (df["Konto_Nr"].isin(["3300"])) & ~(df["Kostenstelle"].str.match(r"^3"))
+    df["Kostenstelle"] = np.where(kto_3300, "31", df["Kostenstelle"])
+
+    kto_0200 = (df["Konto_Nr"].isin(["0200"])) & (df["Kostenstelle"].isin(["90"]))
+    df["Kostenstelle"] = np.where(kto_0200, "40", df["Kostenstelle"])
+
+    kto_3510 = (df["Konto_Nr"].isin(["3510"])) & (df["Kostenstelle"].isin(["00"]))
+    df["Kostenstelle"] = np.where(kto_3510, "51", df["Kostenstelle"])
+    df["Kostenträger"] = np.where(kto_3510, "01", df["Kostenträger"])
+
     df["KRM"] = df["Marke"] + df["Standort"] + df["Kostenstelle"] + df["Absatzkanal"] + df["Kostenträger"]
     df["Konto_Nr_SKR51"] = (
         (df["Marke"] + "-" + df["Standort"] + "-" + df["Konto_Nr"])

+ 4 - 0
gchrstruct_export.bat

@@ -0,0 +1,4 @@
+cd /d %~dp0
+call .venv\Scripts\activate.bat
+pyinstaller -F --path %~dp0 gchrstruct_export.py
+pause

+ 18 - 0
gchrstruct_export.py

@@ -0,0 +1,18 @@
+import os
+from pathlib import Path
+
+from gcstruct.gcstruct import GCStruct
+
+
+def gcstruct_export():
+    base_dir = "C:/Projekte/GCHRStruct_Hyundai_Export"
+    if not Path(base_dir).exists():
+        base_dir = os.getcwd()
+    struct = GCStruct(base_dir)
+    struct.get_structure_and_tree()
+    struct.export_structure_and_tree()
+    struct.export()
+
+
+if __name__ == "__main__":
+    gcstruct_export()

+ 38 - 0
gchrstruct_export.spec

@@ -0,0 +1,38 @@
+# -*- mode: python ; coding: utf-8 -*-
+
+
+a = Analysis(
+    ['gchrstruct_export.py'],
+    pathex=['C:\\Projekte\\Python\\'],
+    binaries=[],
+    datas=[],
+    hiddenimports=[],
+    hookspath=[],
+    hooksconfig={},
+    runtime_hooks=[],
+    excludes=[],
+    noarchive=False,
+    optimize=0,
+)
+pyz = PYZ(a.pure)
+
+exe = EXE(
+    pyz,
+    a.scripts,
+    a.binaries,
+    a.datas,
+    [],
+    name='gchrstruct_export',
+    debug=False,
+    bootloader_ignore_signals=False,
+    strip=False,
+    upx=True,
+    upx_exclude=[],
+    runtime_tmpdir=None,
+    console=True,
+    disable_windowed_traceback=False,
+    argv_emulation=False,
+    target_arch=None,
+    codesign_identity=None,
+    entitlements_file=None,
+)

+ 51 - 19
gcstruct/gcstruct.py

@@ -18,6 +18,7 @@ def get_flat(node):
         {
             "id": node["id"],
             "text": node["text"],
+            "amount_text": node["amount_text"],
             "children": [x["id"] for x in node["children"]],
             "children2": [],
             "parents": node["parents"],
@@ -209,7 +210,7 @@ class GCStruct:
                 "Case",
                 "Info",
             ],
-        }[filetype]
+        }.get(filetype, [])
 
     def accounts_from_csv(self, struct):
         max_rows = (len(self.config["default"]) + 1) * 10
@@ -292,19 +293,55 @@ class GCStruct:
 
     def export(self):
         for s in self.config["export"].keys():
+            if len(self.config["export"][s]["files"]) == 0:
+                continue
+            struct_info = {e["id"]: e for e in self.json_result["flat"][s]}
             for filetype, filename in self.config["export"][s]["files"].items():
-                with open(self.config["path2"] + "/" + filename, "w") as fwh:
-                    fwh.write("Konto_Nr_Hersteller;Konto_Nr_Split;Konto_Nr_Haendler;Info\n")
-                    # 'Hersteller'Konto_Nr;Konto_Bezeichnung;Case;Info'
+                with open(self.config["path2"] + "/" + filename, "w", encoding="latin-1", errors="ignore") as fwh:
+                    fwh.write(";".join(self.export_header(filetype)) + "\n")
+                    unique_accounts = []
                     for a in self.json_result["accounts"]:
-                        if a["Herstellerkonto_Nr"] != "":
-                            account = chevron.render(
-                                self.config["export"]["SKR51"]["format"]["HerstellerkontoFormat"],
-                                a,
-                            )
-                            fwh.write(
-                                account + ";" + account + ";" + a["Konto_Nr"] + ";" + "\n"
-                            )  # a['Herstellerkonto_Bez']
+                        if a["Herstellerkonto_Nr"] == "":
+                            continue
+
+                        account = chevron.render(
+                            self.config["export"]["SKR51"]["format"]["HerstellerkontoFormat"],
+                            a,
+                        )
+
+                        amount_text = struct_info.get(a[s], {}).get("amount_text", "")
+                        if amount_text == "" or " - " not in amount_text:
+                            amount_text += " - "
+                        account_amount_nr, account_amount_text = amount_text.split(" - ")
+                        a2 = a.copy()
+                        a2["Herstellerkonto_Nr"] = account_amount_nr
+                        a2["Herstellerkonto_Bez"] = account_amount_text
+                        account2 = chevron.render(
+                            self.config["export"]["SKR51"]["format"]["HerstellerkontoFormat"],
+                            a2,
+                        )
+                        if filetype == "ExportUebersetzungStk" and a["Konto_STK"] != "1":
+                            continue
+
+                        if filetype == "ExportHerstellerKontenrahmen":
+                            if account not in unique_accounts:
+                                unique_accounts.append(account)
+                                account_text = chevron.render(
+                                    self.config["export"]["SKR51"]["format"]["HerstellerBezeichnungFormat"],
+                                    a,
+                                )
+                                fwh.write(account + ";" + account_text + ";2;" + a["Herstellerkonto_Bez"] + "\n")
+                            if account_amount_nr != "" and account2 not in unique_accounts:
+                                unique_accounts.append(account2)
+                                account_text = chevron.render(
+                                    self.config["export"]["SKR51"]["format"]["HerstellerBezeichnungFormat"],
+                                    a2,
+                                )
+                                fwh.write(account2 + ";" + account_text + ";2;" + a["Herstellerkonto_Bez"] + "\n")
+                        elif filetype == "ExportUebersetzungStk":
+                            fwh.write(account2 + ";" + account2 + ";" + a["Konto_Nr"] + ";" + "\n")
+                        else:
+                            fwh.write(account + ";" + account + ";" + a["Konto_Nr"] + ";" + "\n")
 
     def get_tree(self, node, parents, structure):
         result = []
@@ -321,6 +358,7 @@ class GCStruct:
                     "accounts": self.get_accounts(structure, id),
                     "level": len(parents),
                     "form": child.attrib.get("Split", ""),
+                    "amount_text": child.attrib.get("NameStk", ""),
                 }
             )
             parents.pop()
@@ -336,6 +374,7 @@ class GCStruct:
             "accounts": [],
             "level": 0,
             "form": "",
+            "amount_text": "",
         }
 
     def post_structure_and_tree(self):
@@ -805,13 +844,6 @@ class GCStruct:
         )
 
 
-def dresen():
-    struct = GCStruct("c:/projekte/GCHRStruct_Hyundai_Export")
-    struct.get_structure_and_tree()
-    struct.export_structure_and_tree()
-    struct.export()
-
-
 def reisacher():
     base_dir = "X:/Robert/Planung Reisacher/GCStruct_neue_Struktur_Planung"
     if not Path(base_dir).exists():