瀏覽代碼

Queries für Datenimport und -aufbereitung (alter Stand)

Reisacher C7 11 月之前
父節點
當前提交
518c16420a

+ 139 - 0
sql/import/fm_aha_import.sql

@@ -0,0 +1,139 @@
+select distinct
+CLE."VIN" as chassis_number,
+CLE."Make Code" as make_code,
+CLE."Posting Date" as posting_date,
+CLE."Due Date" as due_date,
+C."No_" as account_number,
+CLE."Document No_" as document_number,
+CLE."Entry No_" as entry_number,
+
+CLE."Amount" as transact_sum,
+CLE."Remaining Amount" as transact_outstanding,
+
+C."No_" as customer_number,
+C."Name" as customer_name,
+C."Phone No_" as customer_phone,
+C."Address" as customer_address,
+C."Post Code" as customer_zipcode,
+C."City" as customer_city,
+CLE."Salesperson Code" as salesman_number,
+SP."Name" as salesman_name,
+
+'' as salesman_user,
+
+case
+  when E."Name" <> '' then ASH."Service Advisor No_" + ' - ' + E."Name"
+  else CLE."Salesperson Code" + ' - ' + SP."Name"
+end as verkaeufer,
+RCE."Reminder Level" as reminder_level,
+
+case 
+  when RCE."Reminder Level" = '0' then 'Mahnst. 0: Kontoauszug vor Mahnung' 
+  when RCE."Reminder Level" = '1' then 'Mahnst. 1: Zahlungserinnerung' 
+  when RCE."Reminder Level" = '2' then 'Mahnst. 2: RA-Androhung' 
+  when RCE."Reminder Level" = '3' then 'Mahnst. M: Rechtsanwalt' 
+  else NULL end as mahnstufe,
+  
+case 
+  when RCE."Reminder Level" = '0' then 'Mahnst. 1: Zahlungserinnerung'  
+  when RCE."Reminder Level" = '1' then 'Mahnst. 2: RA-Androhung'  
+  when RCE."Reminder Level" = '2' then 'Mahnst. M: Rechtsanwalt' 
+  when RCE."Reminder Level" = '3' then '-' 
+  else NULL end as mahnstufe2,
+
+CASE 
+  WHEN CLE."Branch Code" <> '' THEN CLE."Branch Code"  
+  ELSE 'n.v.' END as branch_code,
+
+CASE 
+  WHEN CLE."Branch Code" = 'GÖG'  THEN ('60') 
+  WHEN CLE."Branch Code" = 'LEH' THEN ('70') 
+  WHEN CLE."Branch Code" = 'WTB' THEN ('80') 
+  ELSE 'n.v.' END as filiale_nummer,
+
+case
+  when (not CLE."Main Area" IN (1,2,3)
+		and not left(CLE."Document No_",2) IN ('AL','BF','E4','HV','KA','LB','LO','LP','LQ','LR','RB','SP','UM')
+		and not CLE."Document No_" LIKE '166%'
+		and not CLE."Document No_" LIKE '169%'
+		and not CLE."Document No_" LIKE 'UB0%') then (		
+    CASE
+	  WHEN C."No_" IN ('690101','690102','690103','690104','690105') THEN ('RA') 
+      WHEN left(CLE."Document No_",3) IN ('D12','D13','D14','D15','D16','D23','D24','D25','D32','D34','D35','D43','D44','D45','D51','D52','D54','D55') THEN ('SC') 
+      WHEN left(CLE."Document No_",3) IN ('D17','D18','D26','D27','D36','D46','D47','D56','D57') THEN ('TZ') 
+      WHEN right(CLE."Document No_",2) = 'NA' THEN ('NA') 
+      WHEN right(CLE."Document No_",2) = 'GA' THEN ('GA') 
+      ELSE ('n.v.') END )
+  when ((CLE."Document No_" LIKE 'VRGGFZ%' 
+			or CLE."Document No_" LIKE 'VGUGFZ%' 
+			or CLE."Document No_" LIKE 'VRGF%' 
+			or CLE."Document No_" LIKE 'VRF%' 
+			or CLE."Document No_" LIKE 'VGGF%')
+		and VLE."Entry Type" = 1) then (
+    CASE
+	  WHEN substring(VLE."Department Code",3,1) = '1' THEN ('NA') 
+      WHEN substring(VLE."Department Code",3,1) = '2' THEN ('GA') 
+      WHEN substring(CLE."Department Code",3,1) = '4' THEN ('SC') 
+      WHEN substring(CLE."Department Code",3,1) = '5' THEN ('TZ') 
+      ELSE ('NA/GA') END )
+  else
+    CASE
+      WHEN (CLE."Main Area" = 3) THEN ('SC') 
+      WHEN (CLE."Main Area" = 1) THEN ('TZ')  
+      WHEN (CLE."Main Area" = 2) THEN ('NA/GA')
+      ELSE 'SC/TZ' END    
+  end as kostenstelle_text,
+  CASE WHEN V."Date of Sales Shipment" > '2000-01-01' THEN V."Date of Sales Shipment" ELSE NULL END as shipment_date,
+  CASE WHEN C."No_" <> C2."No_" THEN C2."No_" ELSE '' END as customer_number_leasing,
+  CASE WHEN C."No_" <> C2."No_" THEN C2."Name" ELSE '' END as customer_name_leasing,
+  PSDT1."Text" as text1,
+  PSDT2."Text" as text2
+
+from "DMS1"."dbo"."AH Augsburg$Customer Ledger Entry" as CLE 
+left join "DMS1"."dbo"."AH Augsburg$Customer" as C on C."No_" = CLE."Customer No_"
+left join "DMS1"."dbo"."AH Augsburg$Department" as D on CLE."Department Code" = D."Code"
+left join "DMS1"."dbo"."AH Augsburg$Salesperson_Purchaser" as SP on CLE."Salesperson Code" = SP."Code"
+left join "DMS1"."dbo"."AH Augsburg$Reminder_Fin_ Charge Entry" as RCE on CLE."Entry No_" = RCE."Customer Entry No_"
+left join "DMS1"."dbo"."AH Augsburg$Vehicle Ledger Entry" as VLE on CLE."Document No_" = VLE."Document No_"
+
+left join "DMS1"."dbo"."AH Augsburg$Vehicle" as V on CLE."VIN" = V."VIN"
+left join "DMS1"."dbo"."AH Augsburg$Customer" as C2 on V."Customer No_" = C2."No_" 
+left join "DMS1"."dbo"."AH Augsburg$Posted Sales Document Text" as PSDT1 on CLE."Document No_" = PSDT1."Document No_" and PSDT1."Line No_" = 10000 and PSDT1."Header_Footer" = 1
+left join "DMS1"."dbo"."AH Augsburg$Posted Sales Document Text" as PSDT2 on CLE."Document No_" = PSDT2."Document No_" and PSDT2."Line No_" = 20000 and PSDT2."Header_Footer" = 1
+
+left join "DMS1"."dbo"."AH Augsburg$Service Ledger Entry" SLE on CLE."Document No_" = SLE."Document No_"
+left join "DMS1"."dbo"."AH Augsburg$Archived Service Header" ASH on SLE."Order No_" = ASH."No_"
+left join "DMS1"."dbo"."AH Augsburg$Employee" E on ASH."Service Advisor No_" = E."No_"
+
+where CLE."Remaining Amount" <> 0 
+  and CLE."Journal Batch Name" <> 'ERSTIMPORT' 
+  and not C."No_" LIKE '600%' 
+  
+  and (
+  
+  ((CLE."Document No_" LIKE 'VRGGFZ%' 
+    or CLE."Document No_" LIKE 'VGUGFZ%' 
+ or CLE."Document No_" LIKE 'VRGF%' 
+ or CLE."Document No_" LIKE 'VRF%' 
+ or CLE."Document No_" LIKE 'VGGF%')
+  and VLE."Entry Type" = 1)
+  
+  or 
+
+  (not CLE."Main Area" IN (1,2,3)
+  and not left(CLE."Document No_",2) IN ('AL','BF','E4','HV','KA','LB','LO','LP','LQ','LR','RB','SP','UM')
+  and not CLE."Document No_" LIKE '166%'
+  and not CLE."Document No_" LIKE '169%'
+  and not CLE."Document No_" LIKE 'UB0%')
+  
+  or
+  
+  (CLE."Document No_" LIKE 'WRG%' 
+    or CLE."Document No_" LIKE 'WGG%' 
+ or CLE."Document No_" LIKE 'WGGS%' 
+ or CLE."Document No_" LIKE 'VRGGET%' 
+ or CLE."Document No_" LIKE 'VRT%' 
+ or CLE."Document No_" LIKE 'VRGT%' 
+ or CLE."Document No_" LIKE 'VGUGET%')
+  
+  )

+ 45 - 0
sql/import/fm_aha_report.sql

@@ -0,0 +1,45 @@
+select
+
+chassis_number as FAGNR, 
+make_code as FTYPE, 
+posting_date as REDAT,
+posting_date as OPDAT, 
+due_date as FLDAT, 
+account_number as O500_KTONR, 
+document_number as O500_BELEGNR1, 
+entry_number as Reserve_1, 
+transact_sum as REBEB, 
+transact_outstanding as O500_HW2BETR_OFFEN, 
+transact_outstanding as O500_HW2BUCHGBETR, 
+customer_number as KNDNR,  
+concat(customer_number,' - ', replace(replace(customer_name, "  ", " "), "'", "´")) as KNAME, 
+customer_phone as KTELF, 
+customer_address as KSTRA, 
+customer_zipcode as KDPLZ,  
+customer_city as KDORT,
+salesman_user as KDBNR, 
+salesman_number as KDBERA, 
+salesman_name as KDBNAME, 
+verkaeufer as Stufe5, 
+reminder_level as Reserve_2,
+mahnstufe as O500_MAHNSTUFE, 
+mahnstufe2 as Next_MAHNSTUFE, 
+branch_code as Stufe3, 
+filiale_nummer as FFIRM, 
+'Forderungen DMS' as Stufe1,
+kostenstelle_text as Stufe2,
+'n.v.' as Stufe4,
+
+branch_code as Betrieb,
+shipment_date,
+customer_number_leasing,
+customer_name_leasing,
+text1,
+text2
+  
+from fm_aha_import as t1
+
+INNER JOIN ( SELECT document_number, chassis_number, due_date, entry_number, MAX(reminder_level) as reminder_level
+             FROM fm_aha_import 
+			 GROUP BY 1, 2, 3, 4 ) AS t2 
+  USING(document_number, chassis_number, due_date, entry_number, reminder_level)

+ 187 - 0
sql/import/fm_ahr_import.sql

@@ -0,0 +1,187 @@
+select distinct
+CLE."VIN" as chassis_number,
+CLE."Make Code" as make_code,
+CLE."Posting Date" as posting_date,
+CLE."Due Date" as due_date,
+C."No_" as account_number,
+CLE."Document No_" as document_number,
+CLE."Entry No_" as entry_number,
+
+CLE."Amount" as transact_sum,
+CLE."Remaining Amount" as transact_outstanding,
+
+C."No_" as customer_number,
+C."Name" as customer_name,
+C."Phone No_" as customer_phone,
+C."Address" as customer_address,
+C."Post Code" as customer_zipcode,
+C."City" as customer_city,
+CLE."Salesperson Code" as salesman_number,
+SP."Name" as salesman_name,
+
+case
+  when CLE."Salesperson Code" = '104' then 'cab' 
+  when CLE."Salesperson Code" = '106' then 'bv'
+  when CLE."Salesperson Code" = '109' then 'fd'
+  when CLE."Salesperson Code" = '111' then 'aho'
+  when CLE."Salesperson Code" = '133' then 'mk'
+  when CLE."Salesperson Code" = '141' then 'ka'
+  when CLE."Salesperson Code" = '142' then 'fl'
+  when CLE."Salesperson Code" = '143' then 'tb'
+  when CLE."Salesperson Code" = '144' then 'gr'
+  when CLE."Salesperson Code" = '145' then 'kgu'
+  when CLE."Salesperson Code" = '148' then 'hbo'
+  when CLE."Salesperson Code" = '149' then 'sbe'
+  when CLE."Salesperson Code" = '152' then 'hp'
+  when CLE."Salesperson Code" = '153' then 'rhe'
+  when CLE."Salesperson Code" = '154' then 'fja'
+  when CLE."Salesperson Code" = '302' then 'jja'
+  when CLE."Salesperson Code" = '303' then 'twa'
+  when CLE."Salesperson Code" = '304' then 'sdo'
+  when CLE."Salesperson Code" = '308' then 'tbe'
+  when CLE."Salesperson Code" = '309' then 'ba'
+  when CLE."Salesperson Code" = '332' then 'kkl'
+  when CLE."Salesperson Code" = '341' then 'af'
+  when CLE."Salesperson Code" = '342' then 'vpo'
+  when CLE."Salesperson Code" = '343' then 'mku'
+  when CLE."Salesperson Code" = '344' then 'rwo'
+  when CLE."Salesperson Code" = '345' then 'osa'
+  when CLE."Salesperson Code" = '351' then 'ipl'
+  when CLE."Salesperson Code" = '353' then 'sse'
+  when CLE."Salesperson Code" = '354' then 'rze'
+  when CLE."Salesperson Code" = '550' then 'aan'
+  when CLE."Salesperson Code" = '811' then 'tal'
+  when CLE."Salesperson Code" = '820' then 'wr'
+  when CLE."Salesperson Code" = '821' then 'mma'
+  when CLE."Salesperson Code" = '822' then 'mme'
+else '' end as salesman_user,
+
+case
+  when E."Name" <> '' then ASH."Service Advisor No_" + ' - ' + E."Name"
+  else CLE."Salesperson Code" + ' - ' + SP."Name"
+end as verkaeufer,
+
+RCE."Reminder Level" as reminder_level,
+
+case 
+  when RCE."Reminder Level" = '0' then 'Mahnst. 0: Kontoauszug vor Mahnung' 
+  when RCE."Reminder Level" = '1' then 'Mahnst. 1: Zahlungserinnerung' 
+  when RCE."Reminder Level" = '2' then 'Mahnst. 2: RA-Androhung' 
+  when RCE."Reminder Level" = '3' then 'Mahnst. M: Rechtsanwalt' 
+  else NULL end as mahnstufe,
+  
+case 
+  when RCE."Reminder Level" = '0' then 'Mahnst. 1: Zahlungserinnerung'  
+  when RCE."Reminder Level" = '1' then 'Mahnst. 2: RA-Androhung'  
+  when RCE."Reminder Level" = '2' then 'Mahnst. M: Rechtsanwalt' 
+  when RCE."Reminder Level" = '3' then '-' 
+  else NULL end as mahnstufe2,
+
+CASE 
+  WHEN CLE."Branch Code" <> '' THEN CLE."Branch Code"  
+  WHEN substring(CLE."Document No_" ,8,1) = '1' THEN ('MM') 
+  WHEN substring(CLE."Document No_" ,8,1) = '2' THEN ('VÖH') 
+  WHEN substring(CLE."Document No_" ,8,1) = '3' THEN ('KRU') 
+  WHEN substring(CLE."Document No_" ,8,1) = '4' THEN ('ULM') 
+  WHEN substring(CLE."Document No_" ,8,1) = '5' THEN ('LL') 
+  ELSE null END as branch_code,
+
+CASE 
+  WHEN CLE."Branch Code" = 'MM'  THEN ('10') 
+  WHEN CLE."Branch Code" = 'VÖH' THEN ('20') 
+  WHEN CLE."Branch Code" = 'KRU' THEN ('30') 
+  WHEN CLE."Branch Code" = 'ULM' THEN ('40') 
+  WHEN CLE."Branch Code" = 'LL'  THEN ('50')
+  WHEN substring(CLE."Document No_" ,8,1) = '1' THEN ('10') 
+  WHEN substring(CLE."Document No_" ,8,1) = '2' THEN ('20') 
+  WHEN substring(CLE."Document No_" ,8,1) = '3' THEN ('30') 
+  WHEN substring(CLE."Document No_" ,8,1) = '4' THEN ('40') 
+  WHEN substring(CLE."Document No_" ,8,1) = '5' THEN ('50')   
+  ELSE 'n.v.' END as filiale_nummer,
+
+case
+  when (not CLE."Main Area" IN (1,2,3)
+		and not left(CLE."Document No_",2) IN ('AL','BF','E4','HV','KA','LB','LO','LP','LQ','LR','RB','SP','UM')
+		and not CLE."Document No_" LIKE '166%'
+		and not CLE."Document No_" LIKE '169%'
+		and not CLE."Document No_" LIKE 'UB0%') then (		
+    CASE
+	  WHEN C."No_" IN ('690101','690102','690103','690104','690105') THEN ('RA') 
+      WHEN left(CLE."Document No_",3) IN ('D12','D13','D14','D15','D16','D23','D24','D25','D32','D34','D35','D43','D44','D45','D51','D52','D54','D55') THEN ('SC') 
+      WHEN left(CLE."Document No_",3) IN ('D17','D18','D26','D27','D36','D46','D47','D56','D57') THEN ('TZ') 
+      WHEN right(CLE."Document No_",2) = 'NA' THEN ('NA') 
+      WHEN right(CLE."Document No_",2) = 'GA' THEN ('GA') 
+      ELSE ('n.v.') END )
+  when ((CLE."Document No_" LIKE 'VRGGFZ%' 
+			or CLE."Document No_" LIKE 'VGUGFZ%' 
+			or CLE."Document No_" LIKE 'VRGF%' 
+			or CLE."Document No_" LIKE 'VRF%' 
+			or CLE."Document No_" LIKE 'VGGF%')
+		and VLE."Entry Type" = 1) then (
+    CASE
+	  WHEN substring(VLE."Department Code",3,1) = '1' THEN ('NA') 
+      WHEN substring(VLE."Department Code",3,1) = '2' THEN ('GA') 
+      WHEN substring(CLE."Department Code",3,1) = '4' THEN ('SC') 
+      WHEN substring(CLE."Department Code",3,1) = '5' THEN ('TZ') 
+      ELSE ('NA/GA') END )
+  else
+    CASE
+      WHEN (CLE."Main Area" = 3) THEN ('SC') 
+      WHEN (CLE."Main Area" = 1) THEN ('TZ')  
+      WHEN (CLE."Main Area" = 2) THEN ('NA/GA')
+      ELSE 'SC/TZ' END    
+  end as kostenstelle_text,
+  CASE WHEN V."Date of Sales Shipment" > '2000-01-01' THEN V."Date of Sales Shipment" ELSE NULL END as shipment_date,
+  CASE WHEN C."No_" <> C2."No_" THEN C2."No_" ELSE '' END as customer_number_leasing,
+  CASE WHEN C."No_" <> C2."No_" THEN C2."Name" ELSE '' END as customer_name_leasing,
+  PSDT1."Text" as text1,
+  PSDT2."Text" as text2
+
+from "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry" as CLE 
+left join "DMS1"."dbo"."AH Reisacher$Customer" as C on C."No_" = CLE."Customer No_"
+left join "DMS1"."dbo"."AH Reisacher$Department" as D on CLE."Department Code" = D."Code"
+left join "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser" as SP on CLE."Salesperson Code" = SP."Code"
+left join "DMS1"."dbo"."AH Reisacher$Reminder_Fin_ Charge Entry" as RCE on CLE."Entry No_" = RCE."Customer Entry No_"
+left join "DMS1"."dbo"."AH Reisacher$Vehicle Ledger Entry" as VLE on CLE."Document No_" = VLE."Document No_"
+
+left join "DMS1"."dbo"."AH Reisacher$Vehicle" as V on CLE."VIN" = V."VIN"
+left join "DMS1"."dbo"."AH Reisacher$Customer" as C2 on V."Customer No_" = C2."No_" 
+left join "DMS1"."dbo"."AH Reisacher$Posted Sales Document Text" as PSDT1 on CLE."Document No_" = PSDT1."Document No_" and PSDT1."Line No_" = 10000 and PSDT1."Header_Footer" = 1
+left join "DMS1"."dbo"."AH Reisacher$Posted Sales Document Text" as PSDT2 on CLE."Document No_" = PSDT2."Document No_" and PSDT2."Line No_" = 20000 and PSDT2."Header_Footer" = 1
+
+left join "DMS1"."dbo"."AH Reisacher$Service Ledger Entry" SLE on CLE."Document No_" = SLE."Document No_"
+left join "DMS1"."dbo"."AH Reisacher$Archived Service Header" ASH on SLE."Order No_" = ASH."No_"
+left join "DMS1"."dbo"."AH Reisacher$Employee" E on ASH."Service Advisor No_" = E."No_"
+
+where CLE."Remaining Amount" <> 0 
+  and CLE."Journal Batch Name" <> 'ERSTIMPORT' 
+  and not C."No_" LIKE '600%' 
+  
+  and (
+  
+  ((CLE."Document No_" LIKE 'VRGGFZ%' 
+    or CLE."Document No_" LIKE 'VGUGFZ%' 
+ or CLE."Document No_" LIKE 'VRGF%' 
+ or CLE."Document No_" LIKE 'VRF%' 
+ or CLE."Document No_" LIKE 'VGGF%')
+  and VLE."Entry Type" = 1)
+  
+  or 
+
+  (not CLE."Main Area" IN (1,2,3)
+  and not left(CLE."Document No_",2) IN ('AL','BF','E4','HV','KA','LB','LO','LP','LQ','LR','RB','SP','UM')
+  and not CLE."Document No_" LIKE '166%'
+  and not CLE."Document No_" LIKE '169%'
+  and not CLE."Document No_" LIKE 'UB0%')
+  
+  or
+  
+  (CLE."Document No_" LIKE 'WRG%' 
+    or CLE."Document No_" LIKE 'WGG%' 
+ or CLE."Document No_" LIKE 'WGGS%' 
+ or CLE."Document No_" LIKE 'VRGGET%' 
+ or CLE."Document No_" LIKE 'VRT%' 
+ or CLE."Document No_" LIKE 'VRGT%' 
+ or CLE."Document No_" LIKE 'VGUGET%')
+  
+  )

+ 46 - 0
sql/import/fm_ahr_report.sql

@@ -0,0 +1,46 @@
+select
+
+chassis_number as FAGNR, 
+make_code as FTYPE, 
+posting_date as REDAT,
+posting_date as OPDAT, 
+due_date as FLDAT, 
+account_number as O500_KTONR, 
+document_number as O500_BELEGNR1, 
+entry_number as Reserve_1, 
+transact_sum as REBEB, 
+transact_outstanding as O500_HW2BETR_OFFEN, 
+transact_outstanding as O500_HW2BUCHGBETR, 
+customer_number as KNDNR,  
+concat(customer_number,' - ', replace(replace(customer_name, "  ", " "), "'", "´")) as KNAME, 
+customer_phone as KTELF, 
+customer_address as KSTRA, 
+customer_zipcode as KDPLZ,  
+customer_city as KDORT,
+salesman_user as KDBNR, 
+salesman_number as KDBERA, 
+salesman_name as KDBNAME, 
+verkaeufer as Stufe5, 
+reminder_level as Reserve_2,
+mahnstufe as O500_MAHNSTUFE, 
+mahnstufe2 as Next_MAHNSTUFE, 
+branch_code as Stufe3, 
+filiale_nummer as FFIRM, 
+'Forderungen DMS' as Stufe1,
+kostenstelle_text as Stufe2,
+'n.v.' as Stufe4,
+
+branch_code as Betrieb,
+shipment_date,
+customer_number_leasing,
+customer_name_leasing,
+text1,
+text2
+  
+  
+from fm_ahr_import as t1
+
+INNER JOIN ( SELECT document_number, chassis_number, due_date, entry_number, MAX(reminder_level) as reminder_level
+             FROM fm_ahr_import 
+			 GROUP BY 1, 2, 3, 4 ) AS t2 
+  USING(document_number, chassis_number, due_date, entry_number, reminder_level)

+ 84 - 0
sql/view/fm_aha_naga.sql

@@ -0,0 +1,84 @@
+select
+Betrieb,
+Stufe2, 
+FAGNR, 
+FTYPE,
+KNDNR,
+KNAME, 
+Stufe5, 
+REDAT, 
+O500_HW2BUCHGBETR, 
+FLDAT as FLDAT_von, 
+FLDAT as FLDAT_bis, 
+FLDAT, 
+O500_MAHNSTUFE, 
+Next_MAHNSTUFE,  
+ZA_1,
+ZA_2,
+ZA_3,
+O500_HW2BETR_OFFEN, 
+OPDAT,
+O500_BELEGNR1,
+Ktelf, 
+Kstra, 
+Kdplz, 
+Kdort,  
+Bemerkung, 
+Wiedervorlage, 
+Bemerkung_2, 
+Bearbeitet, 
+Mahnen, 
+`User`, 
+Aenderungsdatum,  
+User_2, 
+Reklamation, 
+Aenderungsdatum_u2,
+geplAuslief_NA, 
+Auslief_NA, 
+geplAuslief_GA, 
+Auslief_GA, 
+LKNAME, 
+LKTELF, 
+LKSTRA, 
+LKDPLZ, 
+LKDORT,
+Reserve_1,
+Reserve_3,
+shipment_date,
+customer_number_leasing,
+customer_name_leasing,
+text1,
+text2,
+round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) as "Faell_Tage",
+case 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 14 ) then '0-2 Wochen'  
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 28 )then '2-4 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 42 )then '4-6 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) >= 42 ) then '> 6 Wochen'   
+  else 'n.v.' 
+end as "Wochen"
+
+from fm_aha_report
+
+where stufe2 NOT IN ('SC','TZ')
+
+and 
+
+case
+  when [userid] IN ('girardini','mba') then stufe2 IN ('NA')
+  when [userid] IN ('rosenkranz') then stufe2 IN ('GA')
+  when [userid] IN ('dk') then kndnr NOT IN ('580000','690121','690122','690123','GARANTIE')
+  else 1 end
+  
+and 
+
+case
+  when [userid] IN ('carville') then betrieb IN ('GÖG')
+  when [userid] IN ('ortner') then betrieb IN ('WTB')
+  when [userid] IN ('karas') then betrieb IN ('LEH')
+  when [userid] IN ('wecker') then betrieb IN ('GÖG','LEH')
+  when [userid] IN ('pho') then betrieb IN ('GÖG','WTB','LEH')
+  when [userid] IN ('preis') then betrieb IN ('GÖG','LEH','WTB')
+  else 1 end
+
+order by FLDAT asc

+ 74 - 0
sql/view/fm_aha_sc.sql

@@ -0,0 +1,74 @@
+select 
+Betrieb,  
+Stufe2, 
+FAGNR, 
+FTYPE,
+KNDNR,
+KNAME, 
+Stufe5, 
+REDAT, 
+O500_HW2BUCHGBETR,  
+FLDAT as FLDAT_von, 
+FLDAT as FLDAT_bis, 
+FLDAT, 
+O500_MAHNSTUFE, 
+Next_MAHNSTUFE, 
+O500_HW2BETR_OFFEN, 
+OPDAT,
+O500_BELEGNR1,
+Ktelf, 
+Kstra, 
+Kdplz, 
+Kdort,  
+Bemerkung, 
+Wiedervorlage, 
+Bemerkung_2, 
+Bearbeitet, 
+Mahnen, 
+`User`, 
+Aenderungsdatum,  
+User_2, 
+Aenderungsdatum_u2,
+KZALA, 
+Versicherung,
+Rechtsanwalt,
+Reklamation, 
+Selbstbeteiligung, 
+SelbstbeteiligungBetrag, 
+Mwst, 
+MwstBetrag,
+Reserve_1,
+ReservE_3,
+round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) as "Faell_Tage",
+case 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 14 ) then '0-2 Wochen'  
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 28 )then '2-4 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 42 )then '4-6 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) >= 42 ) then '> 6 Wochen'   
+  else 'n.v.' 
+end as "Wochen"
+
+from fm_aha_report
+
+where stufe2 IN ('SC','TZ')
+
+and
+
+case
+  when [userid] IN ('') then stufe2 IN ('SC')
+  when [userid] IN ('') then stufe2 IN ('TZ')
+  else 1 end
+  
+and 
+
+case
+  when [userid] IN ('carville') then betrieb IN ('GÖG')
+  when [userid] IN ('acimovic') then betrieb IN ('WTB')
+  when [userid] IN ('samueller') then betrieb IN ('LEH')
+  when [userid] IN ('preis') then betrieb IN ('LEH','GÖG')
+  when [userid] IN ('cfj') then betrieb IN ('LEH','GÖG','WTB')
+  when [userid] IN ('rolle') then betrieb IN ('GÖG','WTB')
+  else 1 end
+
+
+order by FLDAT asc

+ 93 - 0
sql/view/fm_ahr_naga.sql

@@ -0,0 +1,93 @@
+select
+Betrieb,
+Stufe2, 
+FAGNR, 
+FTYPE,
+KNDNR,
+KNAME, 
+Stufe5, 
+REDAT, 
+O500_HW2BUCHGBETR, 
+FLDAT as FLDAT_von, 
+FLDAT as FLDAT_bis, 
+FLDAT, 
+O500_MAHNSTUFE, 
+Next_MAHNSTUFE,  
+ZA_1,
+ZA_2,
+ZA_3,
+O500_HW2BETR_OFFEN, 
+OPDAT,
+O500_BELEGNR1,
+Ktelf, 
+Kstra, 
+Kdplz, 
+Kdort,  
+Bemerkung, 
+Wiedervorlage, 
+Bemerkung_2, 
+Bearbeitet, 
+Mahnen, 
+`User`, 
+Aenderungsdatum,  
+User_2, 
+Reklamation, 
+Aenderungsdatum_u2,
+geplAuslief_NA, 
+Auslief_NA, 
+geplAuslief_GA, 
+Auslief_GA, 
+LKNAME, 
+LKTELF, 
+LKSTRA, 
+LKDPLZ, 
+LKDORT,
+Reserve_1,
+Reserve_3,
+shipment_date,
+customer_number_leasing,
+customer_name_leasing,
+text1,
+text2,
+round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) as "Faell_Tage",
+case 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 14 ) then '0-2 Wochen'  
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 28 )then '2-4 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 42 )then '4-6 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) >= 42 ) then '> 6 Wochen'   
+  else 'n.v.' 
+end as "Wochen"
+
+from fm_ahr_report
+
+where stufe2 NOT IN ('SC','TZ','RA')
+
+and 
+
+case
+  when [userid] IN ('aba','bwo','mba','sop') then stufe2 IN ('NA')
+  when [userid] IN ('hko','sc','sv','fpo','fda') then stufe2 IN ('GA')
+  else 1 end
+  
+and 
+
+case
+  when [userid] IN ('mh') then betrieb IN ('MM','VÖH','KRU','ULM')
+  when [userid] IN ('mc') then betrieb IN ('MM','VÖH','KRU','LL')
+  when [userid] IN ('mj') then betrieb IN ('MM','KRU','ULM','LL')
+  when [userid] IN ('hg') then betrieb IN ('VÖH','KRU','ULM','LL')
+  when [userid] IN ('??') then betrieb IN ('MM','LL')
+  when [userid] IN ('be') then betrieb IN ('VÖH','KRU')
+  when [userid] IN ('mba') then betrieb IN ('MM','KRU')
+  when [userid] IN ('??') then betrieb IN ('GZ','KRU')
+  when [userid] IN ('mvo') then betrieb IN ('GZ')
+  when [userid] IN ('aho','azh','bv','dvr','fpo','hko','jlt','jsh','jti','mga','sc','sko','sop') then betrieb IN ('MM')
+  when [userid] IN ('mba','kkl','vwi') then betrieb IN ('KRU')
+  when [userid] IN ('asl','bta','bwo','fda','lho','mn','mne','mvo','nba','rl','rp','son','ssu','tbo','um','vb','vs') then betrieb IN ('ULM')
+  when [userid] IN ('ak','ala','ash','bb','dp','jdr','muy','mzo','nst','rhe','skr','sv','ype') then betrieb IN ('LL')
+  when [userid] IN ('cab','fd','aho','mk','ka','fl','tb','gr','kgu','hbo','sbe','hp',
+					'fja','jja','twa','sdo','tbe','ba','af','vpo','mku','rwo','osa','ipl',
+					'sse','rze','aan','tal','wr','mma') then kdbnr = [userid]
+  else 1 end
+
+order by FLDAT asc

+ 91 - 0
sql/view/fm_ahr_sc.sql

@@ -0,0 +1,91 @@
+select 
+Betrieb,  
+Stufe2, 
+FAGNR, 
+FTYPE,
+KNDNR,
+KNAME, 
+Stufe5, 
+REDAT, 
+O500_HW2BUCHGBETR,  
+FLDAT as FLDAT_von, 
+FLDAT as FLDAT_bis, 
+FLDAT, 
+O500_MAHNSTUFE, 
+Next_MAHNSTUFE, 
+O500_HW2BETR_OFFEN, 
+OPDAT,
+O500_BELEGNR1,
+Ktelf, 
+Kstra, 
+Kdplz, 
+Kdort,  
+Bemerkung, 
+Wiedervorlage, 
+Bemerkung_2, 
+Bearbeitet, 
+Mahnen, 
+`User`, 
+Aenderungsdatum,  
+User_2, 
+Aenderungsdatum_u2,
+KZALA, 
+Versicherung,
+Rechtsanwalt,
+Reklamation, 
+Selbstbeteiligung, 
+SelbstbeteiligungBetrag, 
+Mwst, 
+MwstBetrag,
+Reserve_1,
+Reserve_3,
+round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) as "Faell_Tage",
+case 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 14 ) then '0-2 Wochen'  
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 28 )then '2-4 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) < 42 )then '4-6 Wochen' 
+  when (round((unix_timestamp(current_date())-unix_timestamp(FLDAT))/86400) >= 42 ) then '> 6 Wochen'   
+  else 'n.v.' 
+end as "Wochen"
+
+from fm_ahr_report
+
+where stufe2 IN ('SC','TZ')
+
+and
+
+case 
+  when [userid] IN ('aet','afr','afo','asd','asf','asi','azn','bc','bsc','bz','ch','cbo','cgr','cho','cke','cki','cpe','cwd','de','dek','dfa','dfi','dki','dsu','eeb','ef','egi','eh','ekd','el','em','es','fau','fdo','fe','fgh','fhs','fhu','fsc','gcu',
+  'ge','gj','gk','hh','hce','hfr','hk','ho','ite','jal','jb','jhe','jhl','jkn','jmr','jg','jre',
+  'kh','kgr','kni','kta','kwe','kwi','lgi','lkr','lm','lre','lt','lwr','mb','mdi','mdk','me','mei','mf','mfr','mge','mgi','mmi','mop','msi','msu','mtr','mwe','nba','nf','nfi','ngu','nke','nna','nsa','nsc','nsm','nwa','obo','oke','ost','pkr','pma','psc','pwi',
+  'rhi','rm','ro','rr','sbr','sft','ssr','tre','skr','smr','spa','spe','ssh','sso','thg','tgn','tke','tkh','tno','ts','tsp','tze','var','vfe','vko','wb','we','wh','wk','wm','ws','wsc','yko','yun') then stufe2 IN ('SC')
+  when [userid] IN ('ach','asa','atz','bs','bsr','cfo','cla','cle','cw','dbi','dwe','ead','esr','fs','gmo','js','kk','ksc','mae','lmo','man','mmz','msd','mrr','mvk','mvs','ng',
+  'or','pjr','psh','rcl','rti','sb','sd','se','sf','shu','sl','spr','ssg','st','sz','ta','thc','tl','tpa','tsa','tzg','tzw','usc','ut') then stufe2 IN ('TZ')
+  else 1 end
+
+and 
+
+case 
+  when [userid] IN ('sz') then betrieb IN ('VÖH','KRU','LL')
+  when [userid] IN ('me') then betrieb IN ('VÖH','KRU','ULM')
+  when [userid] IN ('ch','lre','ws') then betrieb IN ('MM','VÖH')
+  when [userid] IN ('el','wsc') then betrieb IN ('MM','KRU')
+  when [userid] IN ('nsa') then betrieb IN ('MM','KRU','GZ','LL','ULM')
+  when [userid] IN ('ef') then betrieb IN ('MM','LL')
+  when [userid] IN ('sd') then betrieb IN ('VÖH','KRU')
+    when [userid] IN ('??') then betrieb IN ('GZ','KRU')
+   when [userid] IN ('mvo', 'lmo') then betrieb IN ('GZ')
+  when [userid] IN ('jb') then betrieb IN ('VÖH','ULM')
+  when [userid] IN ('kh','wh') then betrieb IN ('KRU','ULM')
+  when [userid] IN ('fe') then betrieb IN ('KRU','LL')
+  when [userid] IN ('lgl') then betrieb IN ('ULM','KRU')
+  when [userid] IN ('aet','afr','ag','asf','atz','bv','bsc','bsr','bz','cbo','cki','cpe','dek','dfa','egi','eh','es','fau','fhu','gcu','gk','hh','hk','jal','jg','js','jre','khe','kk','kni','kwi','ma','mmz','mrr','mrs','msu','mwe','nfi','ng','oke','pkr','pjr','pwi','rhi','rm','ro','sf','sl','smr','tke','tma','ut','we','yun') then betrieb IN ('MM')
+  when [userid] IN ('gj','cw','st') then betrieb IN ('VÖH')
+  when [userid] IN ('asd','dbi','shu','ssr','rr','rcl','jj','kkl','spe','vwi') then betrieb IN ('KRU')
+  when [userid] IN ('afo','mmi','csi','dsu','mdi','ngu','ite','jhl','spr','vko') then betrieb IN ('GZ')
+  when [userid] IN ('ach','asi','asl','awr','azn','bs','cgr','cla','cle','de','dfi','dki','dsm','dwe','ead','eeb','ekd','esr','fce','fgh','fs','fsc','gml','gmo','hce','hja','ho','jkn','jmr','kta','ksc','lgi','lbr','lkr','lt','lwr','mb','mdk','mei','mge','mgi','mtr','nba','nke','nf','nsm','nwa',
+  'obo','or','psc','psh','pz','rl','rti','sb','se','tre','sbr','ssg','sis','ta','tgn','thg','tkh','tno','tsa','tsp','tze','tzg','tzw','um','usc','vdu','vfe','vko','wb','wm') then betrieb IN ('ULM')
+  when [userid] IN ('agr','ak','ala','asa','ash','bc','cfo','cho','cwd','dp','fdo','feb','fkn','hfr','jdr','jhe','kgr','kwe','lra','mae','man','mfr','mop','msd','msi','mvk','mvs','mzo','nna','nst','pma','sft','spa','ssh','thc','tl','tpa','ts','var','yko') then betrieb IN ('LL')
+  else 1 end
+
+order by FLDAT asc