Эх сурвалжийг харах

gcstruct.py auf Cognos11 angepasst
gchr.py etwas verfeinert, noch nicht fertig
mazda-upload.py immer noch falsch

Robert Bedner 3 жил өмнө
parent
commit
f6d4a043f1

+ 8 - 10
gcstruct/gchr.py

@@ -77,19 +77,15 @@ def export_month():
     df = df_translate.drop(columns=['Konto_Nr_Händler', 'Kostenträger_Ebene']).drop_duplicates()
     df = df.merge(df_pivot, how='inner', on='Konto_Nr_SKR51')
 
+    # Bereinigung GW-Kostenträger
     df['GW_Verkauf'] = (df['Konto_Nr'].str.match('^[78]')) & (df['Kostenstelle'].str.match('^2'))
     df['Kostenträger'] = np.where(df['GW_Verkauf'] == True, '52', df['Kostenträger'])
     df['Kostenträger'] = np.where((df['GW_Verkauf'] == True) & (df['Marke'] == '01'), '50', df['Kostenträger'])
+    
 
     from_label = ['Marke', 'Standort', 'Konto_Nr', 'Kostenstelle', 'Absatzkanal', 'Kostenträger']
     to_label = ['Make', 'Site', 'Account', 'Origin', 'SalesChannel', 'CostCarrier']
     df = df.rename(columns=dict(zip(from_label, to_label)))
-    # df['Make'] = df['Konto_Nr_SKR51'].str.slice(start=0, stop=2)
-    # df['Site'] = df['Konto_Nr_SKR51'].str.slice(start=3, stop=5)
-    # df['Account'] = df['Konto_Nr_SKR51'].str.slice(start=6, stop=10)
-    # df['Origin'] = df['Konto_Nr_SKR51'].str.slice(start=11, stop=13)
-    # df['SalesChannel'] = df['Konto_Nr_SKR51'].str.slice(start=14, stop=16)
-    # df['CostCarrier'] = df['Konto_Nr_SKR51'].str.slice(start=17, stop=19)
 
     df['CostAccountingString'] = df['Make'] + df['Site'] + df['Origin'] + \
         df['SalesChannel'] + df['CostCarrier']
@@ -98,9 +94,7 @@ def export_month():
     df_invalid = df[df['IsNumeric'] == False]
     df_invalid.to_csv(account_invalid, decimal=',', sep=';', encoding='latin-1', index=False)
 
-    df = df[df['IsNumeric']]
-    makes = df[['Make', 'Marke_HBV']].drop_duplicates().sort_values(by=['Make']).to_dict(orient='records')
-    sites = df[['Make', 'Site', 'Marke_HBV']].drop_duplicates().sort_values(by=['Make', 'Site']).to_dict(orient='records')
+    export_xml(df, bk_filter, period_no)
 
     # Join auf Übersetzung - nicht zugeordnet
     df_ignored = df_bookings.merge(df_translate, how='left', on='Konto_Nr_Händler')
@@ -110,7 +104,11 @@ def export_month():
                                             aggfunc=np.sum, margins=True, margins_name='CumulatedYear')
         df_ignored.to_csv(account_ignored, decimal=',', sep=';', encoding='latin-1')
 
-    # als xml exportieren
+
+def export_xml(df: pd.DataFrame, bk_filter, period_no):
+    df = df[df['IsNumeric']]
+    makes = df[['Make', 'Marke_HBV']].drop_duplicates().sort_values(by=['Make']).to_dict(orient='records')
+    sites = df[['Make', 'Site', 'Marke_HBV']].drop_duplicates().sort_values(by=['Make', 'Site']).to_dict(orient='records')
     res = df.to_dict(orient='records')
     record_elements = ['Account', 'Make', 'Site', 'Origin', 'SalesChannel', 'CostCarrier', 'CostAccountingString',
                        'Decimals', 'OpeningBalance'] + list(bk_filter.values())[:period_no] + ['CumulatedYear']

+ 30 - 5
gcstruct/gcstruct.py

@@ -383,14 +383,39 @@ class GCStruct():
         df_amount['Konto_Nr_Händler'] = df_amount['Konto_Nr_Händler'] + '_STK'
         df_source = pd.concat([df_source, df_amount])
 
+        df_source['GuV'] = (df_source['Ebene71'] == 'GuV')
+        df_source['Ebene81'] = np.where(df_source['GuV'], df_source['Ebene72'], 'Bilanz')
+        df_source['Ebene82'] = np.where(df_source['GuV'], df_source['Ebene73'], '')
+        df_source['Ebene83'] = np.where(df_source['GuV'], df_source['Ebene74'], '')
+        df_source['Ebene84'] = np.where(df_source['GuV'], df_source['Ebene75'], '')
+        df_source['Ebene85'] = np.where(df_source['GuV'], df_source['Ebene76'], '')
+        df_source['Ebene86'] = np.where(df_source['GuV'], df_source['Ebene77'], '')
+        df_source['Ebene87'] = np.where(df_source['GuV'], df_source['Ebene78'], '')
+        df_source['Ebene88'] = np.where(df_source['GuV'], df_source['Ebene79'], '')
+        df_source['Ebene89'] = np.where(df_source['GuV'], df_source['Ebene80'], '')
+        df_source['Ebene90'] = ''
+        df_source['Ebene71'] = np.where(df_source['GuV'], 'GuV', df_source['Ebene72'])
+        df_source['Ebene72'] = np.where(df_source['GuV'], '', df_source['Ebene73'])
+        df_source['Ebene73'] = np.where(df_source['GuV'], '', df_source['Ebene74'])
+        df_source['Ebene74'] = np.where(df_source['GuV'], '', df_source['Ebene75'])
+        df_source['Ebene75'] = np.where(df_source['GuV'], '', df_source['Ebene76'])
+        df_source['Ebene76'] = np.where(df_source['GuV'], '', df_source['Ebene77'])
+        df_source['Ebene77'] = np.where(df_source['GuV'], '', df_source['Ebene78'])
+        df_source['Ebene78'] = np.where(df_source['GuV'], '', df_source['Ebene79'])
+        df_source['Ebene79'] = np.where(df_source['GuV'], '', df_source['Ebene80'])
+        df_source['Ebene80'] = ''
+
         df_source = df_source[['Konto_neu', 'Konto_Nr_Händler', 'Konto_Bezeichnung', 'Konto_Art', 'Konto_KST', 'Konto_STK',
-                               'Konto_1', 'Konto_2', 'Konto_3', 'Konto_4', 'Konto_5',
-                               'Ebene1', 'Ebene2', 'Ebene3', 'Ebene4', 'Ebene5', 'Ebene6', 'Ebene7', 'Ebene8', 'Ebene9',
-                               'Ebene10', 'Konto_Gruppe']]
-        from_label = cols
-        to_label = get_default_cols(9)
+                               'Konto_1', 'Konto_2', 'Konto_3', 'Konto_4', 'Konto_5'] +
+                              get_default_cols(0) + get_default_cols(7) + get_default_cols(8) +
+                              ['Konto_Gruppe']]
+        # from_label = cols
+        # to_label = get_default_cols(9)
+        from_label = ['Konto_neu', 'Konto_Nr_Händler', 'Konto_Art']
+        to_label = ['Konto', 'Acct_Nr', 'GuV_Bilanz']
 
         df_source = df_source.rename(columns=dict(zip(from_label, to_label)))
+        df_source['Susa'] = df_source['Konto_Gruppe'].str.slice(stop=1)
         # 'Marke', 'Standort', 'Konto_Nr', 'Kostenstelle', 'Absatzkanal', 'Kostenträger',
         df_source.to_csv(f"{self.config['path2']}/SKR51_Uebersetzung.csv", sep=';', encoding='latin-1', index=False)
 

+ 38 - 33
gcstruct/gcstruct.spec

@@ -1,33 +1,38 @@
-# -*- mode: python ; coding: utf-8 -*-
-
-block_cipher = None
-
-
-a = Analysis(['gcstruct.py'],
-             pathex=['C:\\Projekte\\Python'],
-             binaries=[],
-             datas=[],
-             hiddenimports=[],
-             hookspath=[],
-             runtime_hooks=[],
-             excludes=[],
-             win_no_prefer_redirects=False,
-             win_private_assemblies=False,
-             cipher=block_cipher,
-             noarchive=False)
-pyz = PYZ(a.pure, a.zipped_data,
-             cipher=block_cipher)
-exe = EXE(pyz,
-          a.scripts,
-          a.binaries,
-          a.zipfiles,
-          a.datas,
-          [],
-          name='gcstruct',
-          debug=False,
-          bootloader_ignore_signals=False,
-          strip=False,
-          upx=True,
-          upx_exclude=[],
-          runtime_tmpdir=None,
-          console=True )
+# -*- mode: python ; coding: utf-8 -*-
+
+
+block_cipher = None
+
+
+a = Analysis(['gcstruct.py'],
+             pathex=['/home/robert/projekte/python/gcstruct'],
+             binaries=[],
+             datas=[],
+             hiddenimports=[],
+             hookspath=[],
+             runtime_hooks=[],
+             excludes=[],
+             win_no_prefer_redirects=False,
+             win_private_assemblies=False,
+             cipher=block_cipher,
+             noarchive=False)
+pyz = PYZ(a.pure, a.zipped_data,
+             cipher=block_cipher)
+exe = EXE(pyz,
+          a.scripts,
+          [],
+          exclude_binaries=True,
+          name='gcstruct',
+          debug=False,
+          bootloader_ignore_signals=False,
+          strip=False,
+          upx=True,
+          console=True )
+coll = COLLECT(exe,
+               a.binaries,
+               a.zipfiles,
+               a.datas,
+               strip=False,
+               upx=True,
+               upx_exclude=[],
+               name='gcstruct')

+ 9 - 8
mazda/mazda-upload.py

@@ -1,6 +1,6 @@
 import pandas as pd
 import json
-import requests
+# import requests
 from requests_oauthlib import OAuth2Session
 from oauthlib.oauth2 import BackendApplicationClient
 from datetime import datetime
@@ -12,19 +12,20 @@ webservice = domain + '/dogma-restapi-dms/api'
 module = '/vehicles/workshop/order-report'
 auth_url = domain + '/oauth/authorize'
 token_url = domain + '/oauth/token'
+redirect_uri = 'https://localhost/'
 
 client_id = 'E7FC943B-B73F-F48E-B71A-419EA4CD4AC7'
-api_key = '^bH=rk@c58zrr^Apc#9fzy$c'
+client_secret = '^bH=rk@c58zrr^Apc#9fzy$c'
 username = 'mmd88888.cdk'
-password = 'Der neue MX-30'
+password = 'MazdaCX30'   # 'Der neue MX-30'
 dealer_number = '11197/MMD'   # Example '10030/MMD'
 # token = 'MDDq3CUd9ix0iSqR'
 
-base_dir = 'C:/Projekte/Python/mazda/'
+base_dir = '/home/robert/projekte/python/mazda/'
 
 
 def date_format(d):
-    return d.isoformat() + "Z"
+    return d.isoformat() + 'Z'
 
 
 def convert_csv(csv_file, json_file):
@@ -117,12 +118,12 @@ def upload(data):
     }
 
     # client = BackendApplicationClient(client_id=client_id)
-    oauth = OAuth2Session(client=client_id)
+    oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)
     authorization_url, state = oauth.authorization_url(auth_url)
     print('Please go here and authorize: ' + authorization_url)
     redirect_response = input('Paste the full redirect URL here:')
-
-    token = oauth.fetch_token(token_url=auth_url, client_id=client_id, client_secret=api_key, authorization_response=redirect_response)
+    # redirect_response = redirect_response.replace('code=', 'token=')
+    token = oauth.fetch_token(auth_url, client_secret=client_secret, authorization_response=redirect_response)
 
     # s = requests.Session()
     # s.auth = (username, password)

+ 439 - 0
mazda/test.sql

@@ -0,0 +1,439 @@
+SELECT T3."Auftragsnr_",
+CASE
+WHEN T3."Art" = 1 THEN T3."Menge"
+ELSE 0
+END,
+CASE
+WHEN T3."Nr_" NOT like 'HU-K%'
+AND T3."Produktbuchungsgruppe" NOT IN ('W_DP')
+AND T3."Nr_" NOT IN ('E002540') THEN T3."Menge (Stunde)"
+ELSE 0
+END,
+CASE
+WHEN T3."Produktbuchungsgruppe" NOT IN (
+'W_KARO',
+'W_MECH',
+'W_LACK',
+'W_KARO_AZK',
+'W_LACK_AZE',
+'W_ELEK',
+'W_ELEK_NL',
+'W_KARO_NL',
+'W_LACK_NL',
+'W_MECH_NL',
+'W_SATT'
+)
+AND T3."Produktbuchungsgruppe" NOT like 'T\_%' escape '\' or T3."Nr_" = ' E002540 ' THEN CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                                                                                                                                                                                                WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                                                                                                                                                                                                ELSE ' Extern '
+                                                                                                                                                                                                                                                                                                            END = ' Intern ' THEN T3."Verrechnungsbetrag"
+                                                                                                                                                                                                                                                                                                                            ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                                                                                                                                                                                            ELSE T3."Verkaufsbetrag"
+                                                                                                                                                                                                                                                                                                                                    END
+                                                                                                                                                                                                                                                                                                    END
+                                                                                                                                                                                                                                                                                                                                                            ELSE 0
+                                    END , CASE WHEN case WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+                                                                                                                        ELSE 0
+                                                    END = 0 AND CASE WHEN(T3."Produktbuchungsgruppe"IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ')
+                                                                                AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                ELSE ' Extern '
+                                                                                                                            END = ' Intern ') THEN T3."Verrechnungsbetrag"
+                                                                                                                                            ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                            ELSE T3."Verkaufsbetrag"
+                                                                                                                                                END
+                                                                                                                END
+                                                                                                                                                                            ELSE 0
+                                                                END = 0 AND CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
+                                                                                            AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                            WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                            ELSE ' Extern '
+                                                                                                                                        END = ' Intern ') THEN T3."Verrechnungsbetrag"
+                                                                                                                                                        ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                        ELSE T3."Verkaufsbetrag"
+                                                                                                                                                            END
+                                                                                                                            END
+                                                                                                                                                                                        ELSE 0
+                                                                            END <> 0 THEN T3."Menge" * T8."Einstandspreis"
+                                                                                    ELSE CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+                                                                                                                                                            ELSE 0
+                                                                                            END
+                                            END , CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' AND T3."Nr_" <> ' E002540 ' THEN CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                                                    WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                                                    ELSE ' Extern '
+                                                                                                                                                                END = ' Intern ' THEN T3."Verrechnungsbetrag"
+                                                                                                                                                                                ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                                            ELSE T3."Verkaufsbetrag"
+                                                                                                                                                                                    END
+                                                                                                                                                    END
+                                                                                                                                                                                                            ELSE 0
+                                                END , CASE WHEN T3."Produktbuchungsgruppe" IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ') AND T3."Nr_" <> ' E002540 ' THEN CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                                                                                                                                                                            WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                                                                                                                                                                            ELSE ' Extern '
+                                                                                                                                                                                                                                                                                        END = ' Intern ' THEN T3."Verrechnungsbetrag"
+                                                                                                                                                                                                                                                                                                        ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                                                                                                                                                                        ELSE T3."Verkaufsbetrag"
+                                                                                                                                                                                                                                                                                                                END
+                                                                                                                                                                                                                                                                                END
+                                                                                                                                                                                                                                                                                                                                        ELSE 0
+                                                        END , CASE WHEN case WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
+                                                                                    AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                    WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                    ELSE ' Extern '
+                                                                                                                                END = ' Intern ') THEN T3."Verrechnungsbetrag"
+                                                                                                                                                    ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                ELSE T3."Verkaufsbetrag"
+                                                                                                                                                        END
+                                                                                                                        END
+                                                                                                                                                                                ELSE 0
+                                                                        END - CASE WHEN(case WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+                                                                                                                                                        ELSE 0
+                                                                                        END = 0
+                                                                                            AND CASE WHEN(T3."Produktbuchungsgruppe"IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ')
+                                                                                                            AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                                            WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                                            ELSE ' Extern '
+                                                                                                                                                        END = ' Intern ') THEN T3."Verrechnungsbetrag"
+                                                                                                                                                                            ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                                        ELSE T3."Verkaufsbetrag"
+                                                                                                                                                                                END
+                                                                                                                                                END
+                                                                                                                                                                                                        ELSE 0
+                                                                                                END = 0
+                                                                                            AND CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
+                                                                                                            AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+                                                                                                                                                            WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                                                                                                                                                                                            ELSE ' Extern '
+                                                                                                                                                        END = ' Intern ') THEN T3."Verrechnungsbetrag"
+                                                                                                                                                                            ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                                                                                                                                                                                        ELSE T3."Verkaufsbetrag"
+                                                                                                                                                                                END
+                                                                                                                                                END
+                                                                                                                                                                                                        ELSE 0
+                                                                                                END <> 0) THEN T3."Menge" * T8."Einstandspreis"
+                                                                                                        ELSE CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+                                                                                                                                                                                ELSE 0
+                                                                                                            END
+                                                                            END < 0 THEN ' VK < EK '
+                                                                                    ELSE ' VK > EK '
+                                                            END , CASE WHEN T3."Produktbuchungsgruppe" like ' % LOHN % ' THEN T3."Produktbuchungsgruppe"
+                                                                                                                        ELSE NULL
+                                                                    END ,
+T8."Nr_"
+,
+T8."GMPD Code" + T8."GMPD Subcode"
+,
+T8."GMPD Subcode"
+,
+T8."GMPD Code"
+,
+T7."Erstzulassung"
+, CASE WHEN T1."Buchungsdatum" is null THEN T2."Buchungsdatum"
+ELSE T1."Buchungsdatum"
+END ,
+T6."PLZ Code"
+,
+substring(T6."PLZ Code",1,4) ,
+substring(T6."PLZ Code",1,3) ,
+substring(T6."PLZ Code",1,2) ,
+substring(T6."PLZ Code",1,1) , CASE WHEN T10."Ländercode" is null or T10."Ländercode" = ' ' or T10."Ländercode" IN (' D ',' DE ') THEN ' Deutschland '
+                                        ELSE ' Ausland '
+END ,
+T6."Ländercode"
+,
+T6."Nr_" + ' - ' + T6."Name"
+,
+T3."Geschäftsbuchungsgruppe"
+,
+substring(upper(T7."Modell") ,1,3) ,
+T3."Markencode"
+, CASE WHEN T3."Markencode" IN (' OPEL ',' VW ') THEN T3."Markencode"
+ELSE ' Fremdfabrikat '
+END ,
+T3."Kostenstellencode" + ' - ' + T9."Name"
+,
+getdate() , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
+ELSE T1."Nr_"
+END + ' - ' + CASE WHEN NOT T5."Nachname" is null or T5."Nachname" <> '' THEN T3."Serviceberaternr_" + ' - ' + T5."Vorname" + ' ' + T5."Nachname"
+ELSE ' SB fehlt '
+END + ' - ' + T6."Nr_" + ' - ' + T6."Name" , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
+        ELSE T1."Nr_"
+END + ' - ' + T6."Name" , CASE WHEN T3."Geschäftsbuchungsgruppe" IN (' C_INTERN ',' INTERN ',' P_INTERN ') THEN ' Intern '
+            WHEN T3."Geschäftsbuchungsgruppe" IN (' GAR_NST ',' GAR_STB ') THEN ' GWL '
+                                                                            ELSE ' Extern '
+        END , CASE WHEN NOT T5."Nachname" is null or T5."Nachname" <> '' THEN T3."Serviceberaternr_" + ' - ' + T5."Vorname" + ' ' + T5."Nachname"
+                                                                        ELSE ' SB fehlt '
+            END , CASE WHEN T1."Filialcode" is null THEN T2."Filialcode"
+                                                    ELSE T1."Filialcode"
+                    END , CASE WHEN T5."Funktion" IN (' Service Berater ',' Serviceberater ',' Serviceverater ') THEN ' Serviceberater '
+                                                                                                                ELSE ' sonstige MA '
+                        END ,
+T5."Funktion"
+,
+T3."Herkunftsnr_(Zahlung)"
+,
+T1."Rech_ an Name"
+,
+T1."Rech_ an Deb_-Nr_"
+, CASE WHEN T1."Auftragsdatum" is null THEN T2."Auftragsdatum"
+ELSE T1."Auftragsdatum"
+END , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
+ELSE T1."Nr_"
+END + ' - ' + T6."Name" + ' - ' + CASE WHEN NOT T5."Nachname" is null or T5."Nachname" <> '' THEN T3."Serviceberaternr_" + ' - ' + T5."Vorname" + ' ' + T5."Nachname"
+            ELSE ' SB fehlt '
+END + ' - ' ,
+datepart(weekday,getdate()) ,
+T8."Einstandspreis (durchschn_)"
+,
+T8."EK-Preis (neuester)"
+,
+T8."Einstandspreis"
+,
+T8."VK-Preis"
+,
+T8."Basiseinheitencode"
+,
+T8."Beschreibung"
+,
+T3."Verrechnungsbetrag"
+, CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
+AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                    ELSE ' Extern '
+END = ' Intern ') THEN T3."Verrechnungsbetrag"
+ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                    ELSE T3."Verkaufsbetrag"
+END
+END
+                    ELSE 0
+END - CASE WHEN(case WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+ELSE 0
+END = 0
+AND CASE WHEN(T3."Produktbuchungsgruppe"IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ')
+AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                            ELSE ' Extern '
+END = ' Intern ') THEN T3."Verrechnungsbetrag"
+            ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                            ELSE T3."Verkaufsbetrag"
+                END
+END
+                                            ELSE 0
+END = 0
+AND CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
+AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+                                                            ELSE ' Extern '
+END = ' Intern ') THEN T3."Verrechnungsbetrag"
+            ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
+                                            ELSE T3."Verkaufsbetrag"
+                END
+END
+                                            ELSE 0
+END <> 0) THEN T3."Menge" * T8."Einstandspreis"
+ELSE CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+                ELSE 0
+END
+END ,
+T3."Kundengruppencode"
+,
+T1."Archivierungsdatum"
+, CASE WHEN T3."Menge pro Stunde" <> 0 THEN convert(float(53) ,(T3."AW Mont_ 1" + T3."AW Mont_ 2")) / T3."Menge pro Stunde"
+ELSE T3."AW Mont_ 1" + T3."AW Mont_ 2"
+END , CASE WHEN T3."Menge pro Stunde" <> 0 AND CASE WHEN(T3."Nr_" NOT like ' HU - K % '
+AND T3."Produktbuchungsgruppe" NOT IN (' W_DP ')
+AND T3."Nr_" NOT IN (' E002540 ')) THEN T3."Menge (Stunde)"
+        ELSE 0
+END >= 0 AND T3."Nr_" NOT like ' HU - K % ' THEN convert(float(53) ,T3."Vorgabezeit") / T3."Menge pro Stunde"
+WHEN T3."Menge pro Stunde" <> 0 AND CASE WHEN(T3."Nr_" NOT like ' HU - K % '
+AND T3."Produktbuchungsgruppe" NOT IN (' W_DP ')
+AND T3."Nr_" NOT IN (' E002540 ')) THEN T3."Menge (Stunde)"
+        ELSE 0
+END < 0 AND T3."Nr_" NOT like ' HU - K % ' THEN(convert(float(53) ,T3."Vorgabezeit") / T3."Menge pro Stunde") * -1
+ELSE T3."Vorgabezeit"
+END ,
+T3."AW Mont_ 2"
+,
+T3."AW Mont_ 1"
+,
+T3."Vorgabezeitart"
+,
+T3."Vorgabezeit"
+,
+T3."Menge (Stunde)"
+,
+T3."Menge pro Stunde"
+, CASE WHEN T3."Produktbuchungsgruppe" NOT IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ') AND T3."Produktbuchungsgruppe" NOT like ' T \ _ % ' escape ' \ ' or T3."Nr_" = ' E002540 ' THEN T3."Einstandsbetrag"
+                                                                                                                ELSE 0
+END , CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
+ELSE 0
+END , CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+ELSE ' Extern '
+END = ' Intern ' THEN T3."Verrechnungsbetrag"
+ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
+ELSE T3."Verkaufsbetrag"
+END
+END , CASE WHEN T3."Kostenstellencode" like ' 1 % ' THEN ' 1 '
+WHEN T3."Kostenstellencode" like ' 2 % ' THEN ' 2 '
+WHEN T3."Kostenstellencode" IN (' 30 ',' 31 ',' 60 ') THEN ' 6 '
+WHEN T3."Kostenstellencode" IN (' 40 ',' 62 ') THEN ' 3 '
+WHEN T3."Kostenstellencode" = ' 41 ' THEN ' 4 '
+WHEN T3."Kostenstellencode" = ' 42 ' THEN ' 5 '
+WHEN T3."Kostenstellencode" like ' 7 % ' THEN ' 7 '
+WHEN T3."Kostenstellencode" like ' 9 % ' THEN ' 0 '
+ELSE NULL
+END ,
+T3."Fahrgestellnummer" + ' - ' + T7."Modell"
+,
+T7."Modell"
+,
+T6."Name"
+,
+T6."Nr_"
+, CASE WHEN T3."Herkunftsnr_" like ' % INT % ' or CASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
+ELSE T1."Verk_ an Deb_-Nr_"
+END like ' % INT % ' or CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
+                        ELSE T1."Rech_ an Deb_-Nr_"
+END like ' % INT % ' THEN ' Intern '
+WHEN T3."Belegtyp" = 2 AND(T3."Herkunftsnr_" NOT like ' % INT % ' orCASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
+                        ELSE T1."Verk_ an Deb_-Nr_"
+END NOT like ' % INT % ' or CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
+                                                    ELSE T1."Rech_ an Deb_-Nr_"
+            END NOT like ' % INT % ') THEN ' Extern '
+WHEN T3."Belegtyp" = 3 AND(T3."Herkunftsnr_" NOT like ' % INT % ' orCASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
+                        ELSE T1."Verk_ an Deb_-Nr_"
+END NOT like ' % INT % ' or CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
+                                                    ELSE T1."Rech_ an Deb_-Nr_"
+            END NOT like ' % INT % ') THEN ' GWL '
+                                        ELSE NULL
+END , CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
+ELSE T1."Rech_ an Deb_-Nr_"
+END , CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
+ELSE T3."Verkaufsbetrag"
+END ,
+T3."Einstandsbetrag"
+,
+T3."Menge"
+,
+T5."Nachname"
+,
+T5."Vorname"
+, CASE WHEN ' 1 ' = ' 2 ' THEN ' 20 '
+ELSE CASE WHEN T1."Filialcode" is null THEN T2."Filialcode"
+ELSE T1."Filialcode"
+END
+END ,
+T4."Bezeichnung"
+,
+T4."Code"
+,
+T3."Monteur Nr_ 2"
+,
+T3."Monteur Nr_ 1"
+,
+T3."Serviceberaternr_"
+,
+T3."Auftragszeilennr_"
+,
+T3."Herkunftsnr_"
+,
+T3."Fahrzeugartencode"
+,
+T3."Artikelgruppencode"
+,
+T3."Fahrgestellnummer"
+,
+T3."Nummernserie"
+,
+T3."Belegdatum"
+,
+T3."Produktbuchungsgruppe"
+,
+T3."Herkunftscode"
+,
+T3."Benutzer ID"
+,
+T3."Kostenstellencode"
+,
+T3."Werkstattbuchungsgruppe"
+,
+T3."Verkaufsbetrag"
+,
+T3."VK-Preis"
+,
+T3."Einstandspreis"
+,
+T3."EK-Preis"
+,
+T3."Beschreibung"
+,
+T3."Nr_"
+,
+T3."Art"
+,
+T3."Belegnr_"
+, CASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
+ELSE T1."Verk_ an Deb_-Nr_"
+END , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
+ELSE T1."Nr_"
+END , CASE WHEN T1."Belegart" is null THEN T2."Belegart"
+ELSE T1."Belegart"
+END ,
+T1."Interne Belegnr_"
+,
+T1."Interner Auftrag"
+,
+T1."Filialcode"
+,
+T1."Buchungsdatum"
+,
+T1."Auftragsdatum"
+,
+T1."Verk_ an Deb_-Nr_"
+,
+T1."Nr_"
+,
+T1."Belegart"
+FROM((((((((("CARLO"."import"."Werkstattposten" T3 FULL OUTER JOIN
+"CARLO"."import"."Archiv_Werkstattkopf" T1 ON T3."Auftragsnr_" = T1."Nr_"
+AND T3."Client_DB" = T1."Client_DB") FULL OUTER JOIN
+"CARLO"."import"."Werkstattkopf" T2 ON T2."Nr_" = T3."Auftragsnr_"
+AND T2."Client_DB" = T3."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Filialbezeichnung" T4 ON T3."Filialcode" = T4."Code"
+AND T3."Client_DB" = T4."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Employee" T5 ON T3."Serviceberaternr_" = T5."Nr_"
+AND T3."Client_DB" = T5."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Debitor" T6 ON T3."Herkunftsnr_" = T6."Nr_"
+AND T3."Client_DB" = T6."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Fahrzeug" T7 ON T3."Fahrgestellnummer" = T7."Fahrgestellnummer"
+AND T3."Client_DB" = T7."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Artikel" T8 ON T3."Nr_" = T8."Nr_"
+AND T3."Client_DB" = T8."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Kostenstelle" T9 ON T3."Kostenstellencode" = T9."Code"
+AND T3."Client_DB" = T9."Client_DB") FULL OUTER JOIN
+"CARLO"."import"."Verkaufsrechnungskopf" T11 ON T11."Nr_" = T3."Belegnr_"
+AND T11."Client_DB" = T3."Client_DB") LEFT OUTER JOIN
+"CARLO"."import"."Debitor" T10 ON T11."Verk_ an Deb_-Nr_" = T10."Nr_" AND T11."Client_DB" = T10."Client_DB"
+WHERE CASE WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
+else ' Extern '
+end = ' Intern ' AND(T3."Art" <> 2
+AND T3."Belegnr_" NOT like ' G % '
+AND T3."Abgeschlossen" = 1
+AND T3."Nummernserie" <> ''
+AND T3."Offen" = 0
+AND(T3."Belegnr_" like ' WVRG % ' or T3."Belegnr_" like ' WSGG % ')
+AND T3."Nummernserie" <> ' WSLIEFG ' or T3."Art" <> 2
+AND T3."Belegnr_" NOT like ' G % '
+AND T3."Abgeschlossen" = 1
+AND T3."Nummernserie" <> ''
+AND T3."Offen" = 1
+AND(T3."Belegnr_" like ' WVLG % ' or T3."Belegnr_" like ' WVGL % ') or T3."Art" <> 2
+AND T3."Belegnr_" NOT like ' G % '
+AND T3."Abgeschlossen" = 1
+AND T3."Offen" = 1
+AND T3."Belegnr_" like ' WVAN % ') AND CASE WHEN T1."Buchungsdatum" is null THEN T2."Buchungsdatum"
+else T1."Buchungsdatum"
+end >= {ts ' 2018 -01 -01 00 :00 :00.000 '}
+ORDER BY 1 asc

+ 0 - 0
datev_skr51_modelle.py → sandbox/datev_skr51_modelle.py