from ((("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry" left outer join "DMS1"."dbo"."AH Reisacher$Customer" on "DMS1"."dbo"."AH Reisacher$Customer"."No_" = "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Customer No_") left outer join "DMS1"."dbo"."AH Reisacher$Department" on "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Department Code" = "DMS1"."dbo". "AH Reisacher$Department"."Code") left outer join "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser" on 
"DMS1"."dbo". "AH Reisacher$Customer Ledger Entry"."Salesperson Code" = "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser"."Code") where(((((("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Remaining Amount")) <> 0) and ("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Journal Batch Name" <> 'ERSTIMPORT')) and (not "DMS1"."dbo". "AH Reisacher$Customer"."No_"LIKE '600%')) and (("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Document No_"LIKE 'VRGGFZ%') or ("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Document No_" LIKE 'VGUGFZ%')))





from (((("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"  left outer join "DMS1"."dbo"."AH Reisacher$Customer"  on "DMS1"."dbo"."AH Reisacher$Customer"."No_" = "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Customer No_") left outer join "DMS1"."dbo"."AH Reisacher$Department"  on "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Department Code" = "DMS1"."dbo"."AH Reisacher$Department"."Code") left outer join "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser"  on "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Salesperson Code" = "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser"."Code") left outer join "DMS1"."dbo"."AH Reisacher$Reminder_Fin_ Charge Entry"  on "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Entry No_" = "DMS1"."dbo"."AH Reisacher$Reminder_Fin_ Charge Entry"."Customer Entry No_")
where ((((((cast_float("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Remaining Amount"))) <> 0) and ("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Journal Batch Name" <> 'ERSTIMPORT')) and (not "DMS1"."dbo"."AH Reisacher$Customer"."No_" LIKE '600%')) and (("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Document No_" LIKE 'VRGGFZ%') or ("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"."Document No_" LIKE 'VGUGFZ%')))



T2  "DMS1"."dbo"."AH Reisacher$Customer Ledger Entry"
T1  "DMS1"."dbo"."AH Reisacher$Customer"
T3  "DMS1"."dbo"."AH Reisacher$Department"
T4  "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser"
T5  "DMS1"."dbo"."AH Reisacher$Reminder_Fin_ Charge Entry"

	   CASE WHEN (T1."No_" IN ('690101','690102','690103','690104','690105')) THEN ('Ford. bei Rechtsanwalt') WHEN ((od_left(T2."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 ((od_left(T2."Document No_",3)) IN ('D17','D18','D26','D27','D36','D46','D47','D56','D57')) THEN ('T&Z') WHEN ((od_right(T2."Document No_",2)) = 'NA') THEN ('NA') WHEN ((od_right(T2."Document No_",2)) = 'GA') THEN ('GA') ELSE ('nicht zuzuordnen') END as c65,
	   (cast_float(T2."Remaining Amount")) as c66,
	   CASE WHEN (((CASE WHEN (T1."No_" IN ('690101','690102','690103','690104','690105')) THEN ('Ford. bei Rechtsanwalt') WHEN ((od_left(T2."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 ((od_left(T2."Document No_",3)) IN ('D17','D18','D26','D27','D36','D46','D47','D56','D57')) THEN ('T&Z') WHEN ((od_right(T2."Document No_",2)) = 'NA') THEN ('NA') WHEN ((od_right(T2."Document No_",2)) = 'GA') THEN ('GA') ELSE ('nicht zuzuordnen') END) = 'SC') and (T1."No_" IN ('001490','001491'))) THEN ('GWL-Forderungen') WHEN (((CASE WHEN (T1."No_" IN ('690101','690102','690103','690104','690105')) THEN ('Ford. bei Rechtsanwalt') WHEN ((od_left(T2."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 ((od_left(T2."Document No_",3)) IN ('D17','D18','D26','D27','D36','D46','D47','D56','D57')) THEN ('T&Z') WHEN ((od_right(T2."Document No_",2)) = 'NA') THEN ('NA') WHEN ((od_right(T2."Document No_",2)) = 'GA') THEN ('GA') ELSE ('nicht zuzuordnen') END) = 'SC') and (not T1."No_" IN ('001490','001491'))) THEN ('KD-Forderungen') ELSE null END as c67,
	   CASE WHEN (T2."Branch Code" = 'MM') THEN ('10') WHEN (T2."Branch Code" = 'VÖH') THEN ('20') WHEN (T2."Branch Code" = 'KRU') THEN ('30') WHEN (T2."Branch Code" = 'ULM') THEN ('40') WHEN (T2."Branch Code" = 'LL') THEN ('50') ELSE null END as c68,
	   T2."Due Date" as c69,
	   (now()) as c70,
	   (CASE WHEN (T2."Branch Code" = 'MM') THEN ('10') WHEN (T2."Branch Code" = 'VÖH') THEN ('20') WHEN (T2."Branch Code" = 'KRU') THEN ('30') WHEN (T2."Branch Code" = 'ULM') THEN ('40') WHEN (T2."Branch Code" = 'LL') THEN ('50') ELSE null END) as c71,
	   (extract(DAY FROM ((now())) - T2."Due Date")) as c72,
	   CASE WHEN (((extract(DAY FROM ((now())) - T2."Due Date"))) > 28) THEN ('älter 4 Wochen') WHEN (((extract(DAY FROM ((now())) - T2."Due Date"))) BETWEEN 22 AND 28) THEN ('3 - 4 Wochen') WHEN (((extract(DAY FROM ((now())) - T2."Due Date"))) BETWEEN 15 AND 21) THEN ('2 - 3 Wochen') WHEN (((extract(DAY FROM ((now())) - T2."Due Date"))) BETWEEN 0 AND 14) THEN ('0 - 2 Wochen') ELSE ('noch nicht fällig') END as c73,
	   T2."Salesperson Code" || ' - ' || T4."Name" as c74,
	   T2."Document No_" || ' - ' || T1."Name" || ' - ' || (asciiz(extract(YEAR FROM T2."Due Date"),4) || '-' || asciiz(extract(MONTH FROM T2."Due Date"),2) || '-' || asciiz(extract(DAY FROM T2."Due Date"),2)) as c75,
	   T5."No_" as c76,
	   T5."Reminder Level" as c77
from (((("DMS1"."dbo"."AH Reisacher$Customer Ledger Entry" T2 left outer join "DMS1"."dbo"."AH Reisacher$Customer" T1 on T1."No_" = T2."Customer No_") left outer join "DMS1"."dbo"."AH Reisacher$Department" T3 on T2."Department Code" = T3."Code") left outer join "DMS1"."dbo"."AH Reisacher$Salesperson_Purchaser" T4 on T2."Salesperson Code" = T4."Code") left outer join "DMS1"."dbo"."AH Reisacher$Reminder_Fin_ Charge Entry" T5 on T2."Entry No_" = T5."Customer Entry No_")
where ((((((cast_float(T2."Remaining Amount"))) <> 0) and (T2."Journal Batch Name" = 'ERSTIMPORT')) and (not T1."No_" LIKE '600%')) and ((CASE WHEN (T1."No_" IN ('690101','690102','690103','690104','690105')) THEN ('Ford. bei Rechtsanwalt') WHEN ((od_left(T2."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 ((od_left(T2."Document No_",3)) IN ('D17','D18','D26','D27','D36','D46','D47','D56','D57')) THEN ('T&Z') WHEN ((od_right(T2."Document No_",2)) = 'NA') THEN ('NA') WHEN ((od_right(T2."Document No_",2)) = 'GA') THEN ('GA') ELSE ('nicht zuzuordnen') END) = 'GA'))
order by c14 asc,c1 asc
