Pārlūkot izejas kodu

Views von gc-server6

Zumbuelt 1 gadu atpakaļ
vecāks
revīzija
84ed3add42
100 mainītis faili ar 6693 papildinājumiem un 4066 dzēšanām
  1. 21 11
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/Tabellengroesse.sql
  2. 43 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/data.Arbeitstage.sql
  3. 4 3
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/data.GC_Config_Pivot.sql
  4. 13 10
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Imvoice_No_Order_No.sql
  5. 111 111
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Kontenrahmen.sql
  6. 19 16
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.OP_aus_LOC_Belege_8520.sql
  7. 21 14
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Serviceberater_Rechnung.sql
  8. 9 9
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.ben_AW_Order_Number.sql
  9. 77 21
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql
  10. 7 6
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/invoices.sql
  11. 73 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.aftersales_rechnungen_ben_aw_final.sql
  12. 74 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.aftersales_rechnungen_neu.sql
  13. 73 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.aftersales_rechnungen_verk_aw_final.sql
  14. 33 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.current_date_prognose.sql
  15. 39 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.current_date_prognose_operativ.sql
  16. 29 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.current_date_prognose_operativ_vj.sql
  17. 65 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege.sql
  18. 65 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege_bilanz.sql
  19. 67 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege_nw_gw_vk.sql
  20. 65 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege_nw_gw_vk_stk_fibu.sql
  21. 48 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.nw_gw_be_auf_nw_gw_bestand_cat.sql
  22. 69 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.nw_gw_vk_journal_accountings.sql
  23. 35 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.offene_auftraege_dg_anz_tage.sql
  24. 35 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.offene_auftraege_teile.sql
  25. 36 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.offene_auftraege_ums_ben_aw.sql
  26. 33 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.op_aus_loc_belege_deb_saldo.sql
  27. 33 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.op_aus_loc_belege_ohne_8520.sql
  28. 66 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.umsatz_belege_skr.sql
  29. 41 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_abwesenheit_neu.sql
  30. 42 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_ben_std_lg.sql
  31. 43 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_stempelungen_neu.sql
  32. 40 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_stempelungen_pausen.sql
  33. 39 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_stempelungen_pausen_produktiv.sql
  34. 43 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_verk_std.sql
  35. 0 255
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/locosoft.LOC_Belege.sql
  36. 25 25
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/order_positions.sql
  37. 0 82
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_ben_AW_final.sql
  38. 0 268
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_neu.sql
  39. 0 45
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_verk_AW_final.sql
  40. 0 20
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Imvoice_No_Order_No.sql
  41. 0 125
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kontenrahmen.sql
  42. 0 117
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kreditorenbewegungen.sql
  43. 0 419
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.LOC_Belege_NW_GW_VK.sql
  44. 0 558
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.LOC_Belege_NW_GW_VK_Stk_FIBU.sql
  45. 0 265
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.NW_GW_BE_auf_NW_GW_Bestand_Cat.sql
  46. 0 26
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_8520.sql
  47. 0 196
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_Deb_Saldo.sql
  48. 0 173
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_nur_8520.sql
  49. 0 196
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_ohne_8520.sql
  50. 0 24
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Serviceberater_Rechnung.sql
  51. 0 130
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Abwesenheit_neu.sql
  52. 0 181
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_Pausen.sql
  53. 0 184
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_Pausen_produktiv.sql
  54. 0 48
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_neu.sql
  55. 0 88
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_ben_Std_LG.sql
  56. 0 49
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_verk_Std.sql
  57. 73 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_0.sql
  58. 102 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_11.sql
  59. 48 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_80.sql
  60. 157 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_90.sql
  61. 102 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_fm.sql
  62. 202 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_imr.sql
  63. 74 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_0.sql
  64. 141 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_11.sql
  65. 151 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_80.sql
  66. 293 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_90.sql
  67. 141 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_fm.sql
  68. 432 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_imr.sql
  69. 73 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_0.sql
  70. 102 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_11.sql
  71. 44 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_80.sql
  72. 165 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_90.sql
  73. 102 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_fm.sql
  74. 165 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_imr.sql
  75. 0 19
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.ben_AW_Order_Number.sql
  76. 0 43
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_Prognose.sql
  77. 0 43
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_Prognose_operativ_VJ-2.sql
  78. 45 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_prognose_0.sql
  79. 57 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_prognose_imr.sql
  80. 121 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_80.sql
  81. 121 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_90.sql
  82. 0 121
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_gc_struct_skr.sql
  83. 121 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_gc_struct_skr_80.sql
  84. 121 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_gc_struct_skr_imr.sql
  85. 121 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_imr.sql
  86. 95 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kreditorenbewegungen_80.sql
  87. 277 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kreditorenbewegungen_90.sql
  88. 359 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kreditorenbewegungen_imr.sql
  89. 0 82
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege.sql
  90. 65 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_0.sql
  91. 115 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_11.sql
  92. 79 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_80.sql
  93. 159 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_90.sql
  94. 0 83
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz.sql
  95. 65 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_0.sql
  96. 115 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_11.sql
  97. 80 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_80.sql
  98. 179 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_90.sql
  99. 115 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_fm.sql
  100. 180 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_imr.sql

+ 21 - 11
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/Tabellengroesse.sql

@@ -4,17 +4,27 @@ SET ANSI_NULLS ON
 GO
 GO
 CREATE VIEW [dbo].[Tabellengroesse]
 CREATE VIEW [dbo].[Tabellengroesse]
 AS
 AS
-
-SELECT        TOP (100) PERCENT t.name AS TableName, s.name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, CAST(ROUND(SUM(a.total_pages) * 8 / 1024.00, 2) AS NUMERIC(36, 2)) 
-                         AS TotalSpaceMB, SUM(a.used_pages) * 8 AS UsedSpaceKB, CAST(ROUND(SUM(a.used_pages) * 8 / 1024.00, 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, (SUM(a.total_pages) - SUM(a.used_pages)) 
-                         * 8 AS UnusedSpaceKB, CAST(ROUND((SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
-FROM            sys.tables AS t INNER JOIN
-                         sys.indexes AS i ON t.object_id = i.object_id INNER JOIN
-                         sys.partitions AS p ON i.object_id = p.object_id AND i.index_id = p.index_id INNER JOIN
-                         sys.allocation_units AS a ON p.partition_id = a.container_id LEFT OUTER JOIN
-                         sys.schemas AS s ON t.schema_id = s.schema_id
-WHERE        (t.name NOT LIKE 'dt%') AND (t.is_ms_shipped = 0) AND (i.object_id > 255)
-GROUP BY t.name, s.name, p.rows
+SELECT TOP (100) PERCENT t.name AS TableName,
+	s.name AS SchemaName,
+	p.rows AS RowCounts,
+	SUM(a.total_pages) * 8 AS TotalSpaceKB,
+	CAST(ROUND(SUM(a.total_pages) * 8 / 1024.00, 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
+	SUM(a.used_pages) * 8 AS UsedSpaceKB,
+	CAST(ROUND(SUM(a.used_pages) * 8 / 1024.00, 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,
+	(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
+	CAST(ROUND((SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
+FROM sys.tables AS t
+INNER JOIN sys.indexes AS i ON t.object_id = i.object_id
+INNER JOIN sys.partitions AS p ON i.object_id = p.object_id
+	AND i.index_id = p.index_id
+INNER JOIN sys.allocation_units AS a ON p.partition_id = a.container_id
+LEFT OUTER JOIN sys.schemas AS s ON t.schema_id = s.schema_id
+WHERE (t.name NOT LIKE 'dt%')
+	AND (t.is_ms_shipped = 0)
+	AND (i.object_id > 255)
+GROUP BY t.name,
+	s.name,
+	p.rows
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO

+ 43 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/data.Arbeitstage.sql

@@ -0,0 +1,43 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [data].[Arbeitstage]
+AS
+SELECT [bundeslaender_id],
+	[datum],
+	[wochentage_id],
+	[arbeitstag_mofr],
+	[zaehler_mofr],
+	[summe_mofr],
+	RANK() OVER (
+		PARTITION BY bundeslaender_id,
+		year(datum),
+		arbeitstag_mofr ORDER BY datum
+		) AS [zaehler_jahr_mofr],
+	SUM([arbeitstag_mofr]) OVER (
+		PARTITION BY bundeslaender_id,
+		year(datum)
+		) AS [summe_jahr_mofr],
+	[arbeitstag_mosa],
+	[zaehler_mosa],
+	[summe_mosa],
+	RANK() OVER (
+		PARTITION BY bundeslaender_id,
+		year(datum),
+		arbeitstag_mosa ORDER BY datum
+		) AS [zaehler_jahr_mosa],
+	SUM([arbeitstag_mosa]) OVER (
+		PARTITION BY bundeslaender_id,
+		year(datum)
+		) AS [summe_jahr_mosa],
+	[feiertage_id]
+FROM [GC].[data].[Arbeitstage]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 4 - 3
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/data.GC_Config_Pivot.sql

@@ -2,9 +2,10 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW data.GC_Config_Pivot AS
-
-select * from GC.data.GC_Config_Pivot
+CREATE VIEW [data].[GC_Config_Pivot]
+AS
+SELECT *
+FROM GC.data.GC_Config_Pivot
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO

+ 13 - 10
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Imvoice_No_Order_No.sql

@@ -2,19 +2,22 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW ims.Imvoice_No_Order_No AS
-
-select distinct T1."order_number" as "Order Number",
-	   T1."invoice_number" as "Invoice Number_ohne_type",
-	   T2."invoice_type" as "Invoice Type",
-	   (left(((convert(varchar(50), T2."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) as "Invoice Number"
-from ("dbo"."invoices" T2 left outer join "dbo"."labours" T1 on (T1."invoice_number" = T2."invoice_number") and (T1."invoice_type" = T2."invoice_type"))
-where ((((left(((convert(varchar(50), T2."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number")))))) <> '') and (T2."invoice_date" >= convert(date, '2019-01-01')))
--- order by "Order Number" asc
+CREATE VIEW [ims].[Imvoice_No_Order_No]
+AS
+SELECT DISTINCT T1."order_number" AS "Order Number",
+	T1."invoice_number" AS "Invoice Number_ohne_type",
+	T2."invoice_type" AS "Invoice Type",
+	(substring((convert(VARCHAR(50), T2."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 6)) AS "Invoice Number"
+FROM (
+	"dbo"."invoices" T2 LEFT OUTER JOIN "dbo"."labours" T1 ON (T1."invoice_number" = T2."invoice_number")
+		AND (T1."invoice_type" = T2."invoice_type")
+	)
+WHERE (((substring((convert(VARCHAR(50), T2."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 6))) <> '')
+	-- order by "Order Number" asc
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO
 SET ANSI_NULLS OFF 
 SET ANSI_NULLS OFF 
 GO
 GO
 
 
-GO
+GO

+ 111 - 111
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Kontenrahmen.sql

@@ -2,120 +2,120 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW ims.Kontenrahmen AS
-
-select T1."KONTO_NR" as "Konto Nr",
-	   T1."KONTO_BEZEICHNUNG" as "Konto Bezeichnung",
-	   T1."KONTO_ART" as "Konto Art_ori",
-	   T1."KOSTENSTELLE" as "Kostenstelle",
-	   T1."STK" as "Stk",
-	   T1."KONTO_1" as "Konto 1",
-	   T1."KONTO_2" as "Konto 2",
-	   T1."KONTO_3" as "Konto 3",
-	   T1."KONTO_4" as "Konto 4",
-	   T1."KONTO_5" as "Konto 5",
-	   T1."EBENE1" as "Ebene1",
-	   T1."EBENE2" as "Ebene2",
-	   T1."EBENE3" as "Ebene3",
-	   T1."EBENE4" as "Ebene4",
-	   T1."EBENE5" as "Ebene5",
-	   T1."EBENE6" as "Ebene6",
-	   T1."EBENE7" as "Ebene7",
-	   T1."EBENE8" as "Ebene8",
-	   T1."EBENE9" as "Ebene9",
-	   T1."EBENE10" as "Ebene10",
-	   T1."EBENE11" as "Ebene11",
-	   T1."EBENE12" as "Ebene12",
-	   T1."EBENE13" as "Ebene13",
-	   T1."EBENE14" as "Ebene14",
-	   T1."EBENE15" as "Ebene15",
-	   T1."EBENE16" as "Ebene16",
-	   T1."EBENE17" as "Ebene17",
-	   T1."EBENE18" as "Ebene18",
-	   T1."EBENE19" as "Ebene19",
-	   T1."EBENE20" as "Ebene20",
-	   T1."EBENE21" as "Ebene21",
-	   T1."EBENE22" as "Ebene22",
-	   T1."EBENE23" as "Ebene23",
-	   T1."EBENE24" as "Ebene24",
-	   T1."EBENE25" as "Ebene25",
-	   T1."EBENE26" as "Ebene26",
-	   T1."EBENE27" as "Ebene27",
-	   T1."EBENE28" as "Ebene28",
-	   T1."EBENE29" as "Ebene29",
-	   T1."EBENE30" as "Ebene30",
-	   T1."EBENE31" as "Ebene31",
-	   T1."EBENE32" as "Ebene32",
-	   T1."EBENE33" as "Ebene33",
-	   T1."EBENE34" as "Ebene34",
-	   T1."EBENE35" as "Ebene35",
-	   T1."EBENE36" as "Ebene36",
-	   T1."EBENE37" as "Ebene37",
-	   T1."EBENE38" as "Ebene38",
-	   T1."EBENE39" as "Ebene39",
-	   T1."EBENE40" as "Ebene40",
-	   T1."EBENE41" as "Ebene41",
-	   T1."EBENE42" as "Ebene42",
-	   T1."EBENE43" as "Ebene43",
-	   T1."EBENE44" as "Ebene44",
-	   T1."EBENE45" as "Ebene45",
-	   T1."EBENE46" as "Ebene46",
-	   T1."EBENE47" as "Ebene47",
-	   T1."EBENE48" as "Ebene48",
-	   T1."EBENE49" as "Ebene49",
-	   T1."EBENE50" as "Ebene50",
-	   T1."EBENE51" as "Ebene51",
-	   T1."EBENE52" as "Ebene52",
-	   T1."EBENE53" as "Ebene53",
-	   T1."EBENE54" as "Ebene54",
-	   T1."EBENE55" as "Ebene55",
-	   T1."EBENE56" as "Ebene56",
-	   T1."EBENE57" as "Ebene57",
-	   T1."EBENE58" as "Ebene58",
-	   T1."EBENE59" as "Ebene59",
-	   T1."EBENE60" as "Ebene60",
-	   T1."EBENE61" as "Ebene61",
-	   T1."EBENE62" as "Ebene62",
-	   T1."EBENE63" as "Ebene63",
-	   T1."EBENE64" as "Ebene64",
-	   T1."EBENE65" as "Ebene65",
-	   T1."EBENE66" as "Ebene66",
-	   T1."EBENE67" as "Ebene67",
-	   T1."EBENE68" as "Ebene68",
-	   T1."EBENE69" as "Ebene69",
-	   T1."EBENE70" as "Ebene70",
-	   T1."EBENE71" as "Ebene71",
-	   T1."EBENE72" as "Ebene72",
-	   T1."EBENE73" as "Ebene73",
-	   T1."EBENE74" as "Ebene74",
-	   T1."EBENE75" as "Ebene75",
-	   T1."EBENE76" as "Ebene76",
-	   T1."EBENE77" as "Ebene77",
-	   T1."EBENE78" as "Ebene78",
-	   T1."EBENE79" as "Ebene79",
-	   T1."EBENE80" as "Ebene80",
-	   T1."EBENE81" as "Ebene81",
-	   T1."EBENE82" as "Ebene82",
-	   T1."EBENE83" as "Ebene83",
-	   T1."EBENE84" as "Ebene84",
-	   T1."EBENE85" as "Ebene85",
-	   T1."EBENE86" as "Ebene86",
-	   T1."EBENE87" as "Ebene87",
-	   T1."EBENE88" as "Ebene88",
-	   T1."EBENE89" as "Ebene89",
-	   T1."EBENE90" as "Ebene90",
-	   (len(T1."KONTO_NR" + 'Z') - 1) as "Anzahl Stellen_Konto_Nr",
-	   T1."KONTO_ART" as "Konto Art",
-	   T1."KONTO_ART" as "GuV_Bilanz",
-	   T1."KONTO_NR" as "Acct Nr",
-	   T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" as "Konto",
-	   (left(T1."KONTO_NR",1)) as "Susa"
-from "Kontenrahmen.csv" T1
-where (((left(T1."KONTO_NR",1))) <> '9')
+CREATE VIEW [ims].[Kontenrahmen]
+AS
+SELECT T1."KONTO_NR" AS "Konto Nr",
+	T1."KONTO_BEZEICHNUNG" AS "Konto Bezeichnung",
+	T1."KONTO_ART" AS "Konto Art_ori",
+	T1."KOSTENSTELLE" AS "Kostenstelle",
+	T1."STK" AS "Stk",
+	T1."KONTO_1" AS "Konto 1",
+	T1."KONTO_2" AS "Konto 2",
+	T1."KONTO_3" AS "Konto 3",
+	T1."KONTO_4" AS "Konto 4",
+	T1."KONTO_5" AS "Konto 5",
+	T1."EBENE1" AS "Ebene1",
+	T1."EBENE2" AS "Ebene2",
+	T1."EBENE3" AS "Ebene3",
+	T1."EBENE4" AS "Ebene4",
+	T1."EBENE5" AS "Ebene5",
+	T1."EBENE6" AS "Ebene6",
+	T1."EBENE7" AS "Ebene7",
+	T1."EBENE8" AS "Ebene8",
+	T1."EBENE9" AS "Ebene9",
+	T1."EBENE10" AS "Ebene10",
+	T1."EBENE11" AS "Ebene11",
+	T1."EBENE12" AS "Ebene12",
+	T1."EBENE13" AS "Ebene13",
+	T1."EBENE14" AS "Ebene14",
+	T1."EBENE15" AS "Ebene15",
+	T1."EBENE16" AS "Ebene16",
+	T1."EBENE17" AS "Ebene17",
+	T1."EBENE18" AS "Ebene18",
+	T1."EBENE19" AS "Ebene19",
+	T1."EBENE20" AS "Ebene20",
+	T1."EBENE21" AS "Ebene21",
+	T1."EBENE22" AS "Ebene22",
+	T1."EBENE23" AS "Ebene23",
+	T1."EBENE24" AS "Ebene24",
+	T1."EBENE25" AS "Ebene25",
+	T1."EBENE26" AS "Ebene26",
+	T1."EBENE27" AS "Ebene27",
+	T1."EBENE28" AS "Ebene28",
+	T1."EBENE29" AS "Ebene29",
+	T1."EBENE30" AS "Ebene30",
+	T1."EBENE31" AS "Ebene31",
+	T1."EBENE32" AS "Ebene32",
+	T1."EBENE33" AS "Ebene33",
+	T1."EBENE34" AS "Ebene34",
+	T1."EBENE35" AS "Ebene35",
+	T1."EBENE36" AS "Ebene36",
+	T1."EBENE37" AS "Ebene37",
+	T1."EBENE38" AS "Ebene38",
+	T1."EBENE39" AS "Ebene39",
+	T1."EBENE40" AS "Ebene40",
+	T1."EBENE41" AS "Ebene41",
+	T1."EBENE42" AS "Ebene42",
+	T1."EBENE43" AS "Ebene43",
+	T1."EBENE44" AS "Ebene44",
+	T1."EBENE45" AS "Ebene45",
+	T1."EBENE46" AS "Ebene46",
+	T1."EBENE47" AS "Ebene47",
+	T1."EBENE48" AS "Ebene48",
+	T1."EBENE49" AS "Ebene49",
+	T1."EBENE50" AS "Ebene50",
+	T1."EBENE51" AS "Ebene51",
+	T1."EBENE52" AS "Ebene52",
+	T1."EBENE53" AS "Ebene53",
+	T1."EBENE54" AS "Ebene54",
+	T1."EBENE55" AS "Ebene55",
+	T1."EBENE56" AS "Ebene56",
+	T1."EBENE57" AS "Ebene57",
+	T1."EBENE58" AS "Ebene58",
+	T1."EBENE59" AS "Ebene59",
+	T1."EBENE60" AS "Ebene60",
+	T1."EBENE61" AS "Ebene61",
+	T1."EBENE62" AS "Ebene62",
+	T1."EBENE63" AS "Ebene63",
+	T1."EBENE64" AS "Ebene64",
+	T1."EBENE65" AS "Ebene65",
+	T1."EBENE66" AS "Ebene66",
+	T1."EBENE67" AS "Ebene67",
+	T1."EBENE68" AS "Ebene68",
+	T1."EBENE69" AS "Ebene69",
+	T1."EBENE70" AS "Ebene70",
+	T1."EBENE71" AS "Ebene71",
+	T1."EBENE72" AS "Ebene72",
+	T1."EBENE73" AS "Ebene73",
+	T1."EBENE74" AS "Ebene74",
+	T1."EBENE75" AS "Ebene75",
+	T1."EBENE76" AS "Ebene76",
+	T1."EBENE77" AS "Ebene77",
+	T1."EBENE78" AS "Ebene78",
+	T1."EBENE79" AS "Ebene79",
+	T1."EBENE80" AS "Ebene80",
+	T1."EBENE81" AS "Ebene81",
+	T1."EBENE82" AS "Ebene82",
+	T1."EBENE83" AS "Ebene83",
+	T1."EBENE84" AS "Ebene84",
+	T1."EBENE85" AS "Ebene85",
+	T1."EBENE86" AS "Ebene86",
+	T1."EBENE87" AS "Ebene87",
+	T1."EBENE88" AS "Ebene88",
+	T1."EBENE89" AS "Ebene89",
+	T1."EBENE90" AS "Ebene90",
+	(len(T1."KONTO_NR" + 'Z') - 1) AS "Anzahl Stellen_Konto_Nr",
+	T1."KONTO_ART" AS "Konto Art",
+	T1."KONTO_ART" AS "GuV_Bilanz",
+	T1."KONTO_NR" AS "Acct Nr",
+	T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" AS "Konto",
+	(left(T1."KONTO_NR", 1)) AS "Susa"
+FROM OPENROWSET(BULK 'C:\GlobalCube\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv', FORMATFILE = 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv.xml', FIRSTROW = 2) T1
+WHERE (((left(T1."KONTO_NR", 1))) <> '9')
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO
 SET ANSI_NULLS OFF 
 SET ANSI_NULLS OFF 
 GO
 GO
 
 
-GO
+GO

+ 19 - 16
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.OP_aus_LOC_Belege_8520.sql

@@ -2,25 +2,28 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW ims.OP_aus_LOC_Belege_8520 AS
-
-select distinct T1."document_type" as "Document Type",
-	   T1."nominal_account_number" as "Nominal Account Number",
-	   T1."customer_contra_account" as "Customer Contra Account",
-	   T1."invoice_number" as "Invoice Number",
-	   T1."skr51_branch" as "Skr51 Branch",
-	   '1' as "Rechtseinheit",
-	   '0' + ((convert(varchar(50), T1."skr51_branch"))) as "Betrieb",
-	   '1' as "Mandant",
-	   '1' as "Hauptbetrieb",
-	   ('0' + ((convert(varchar(50), T1."skr51_branch")))) as "Standort"
-from "journal_accountings" T1
-where (((T1."nominal_account_number" IN (8520)) and (T1."document_type" = 'R')) and (T1."invoice_date" >= convert(date, '2016-01-01')))
--- order by "Invoice Number" asc,"Nominal Account Number" asc
+CREATE VIEW [ims].[OP_aus_LOC_Belege_8520]
+AS
+SELECT DISTINCT T1."document_type" AS "Document Type",
+	T1."nominal_account_number" AS "Nominal Account Number",
+	T1."customer_contra_account" AS "Customer Contra Account",
+	T1."invoice_number" AS "Invoice Number",
+	T1."skr51_branch" AS "Skr51 Branch",
+	'1' AS "Rechtseinheit",
+	'0' + (convert(VARCHAR(50), T1."skr51_branch")) AS "Betrieb",
+	'1' AS "Mandant",
+	'1' AS "Hauptbetrieb",
+	('0' + (convert(VARCHAR(50), T1."skr51_branch"))) AS "Standort"
+FROM "journal_accountings" T1
+WHERE (
+		(T1."nominal_account_number" IN (8520))
+		AND (T1."document_type" = 'R')
+		)
+	-- order by "Invoice Number" asc,"Nominal Account Number" asc
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO
 SET ANSI_NULLS OFF 
 SET ANSI_NULLS OFF 
 GO
 GO
 
 
-GO
+GO

+ 21 - 14
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Serviceberater_Rechnung.sql

@@ -2,23 +2,30 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW ims.Serviceberater_Rechnung AS
-
-select distinct T1."invoice_type" as "Invoice Type",
-	   T1."invoice_number" as "Invoice Number",
-	   T2."order_taking_employee_no" as "Order Taking Employee No",
-	   T2."order_delivery_employee_no" as "Order Delivery Employee No",
-	   T1."invtype_invnr" as "Invoice_Type_Invoice_Number",
-	   T3."employee_number" as "Employee Number_Employees",
-	   T3."name" as "Name_Employees",
-	   (left(((convert(varchar(50), T3."employee_number"))))) + ' - ' + T3."name" as "Serviceberater"
-from (("LOCOSOFT"."dbo"."order_positions" T2 left outer join "dbo"."invoices" T1 on T2."order_number" = T1."order_number") left outer join "LOCOSOFT"."dbo"."employees" T3 on T2."order_taking_employee_no" = T3."employee_number")
-where ((T1."invoice_type" BETWEEN 2 AND 6) and (T2."order_date" >= convert(datetime, '2019-01-01 00:00:00.000')))
--- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
+CREATE VIEW [ims].[Serviceberater_Rechnung]
+AS
+SELECT DISTINCT T1."invoice_type" AS "Invoice Type",
+	T1."invoice_number" AS "Invoice Number",
+	T2."order_taking_employee_no" AS "Order Taking Employee No",
+	T2."order_delivery_employee_no" AS "Order Delivery Employee No",
+	T1."invtype_invnr",
+	T3."employee_number" AS "Employee Number_Employees",
+	T3."name" AS "Name_Employees",
+	(substring((convert(VARCHAR(50), T3."employee_number")), 1, 4)) + ' - ' + T3."name" AS "Serviceberater"
+FROM (
+	(
+		"LOCOSOFT"."dbo"."order_positions" T2 LEFT OUTER JOIN "dbo"."invoices" T1 ON T2."order_number" = T1."order_number"
+		) LEFT OUTER JOIN "LOCOSOFT"."dbo"."employees" T3 ON T2."order_taking_employee_no" = T3."employee_number"
+	)
+WHERE (
+		(T1."invoice_type" BETWEEN 2 AND 6)
+		AND (T2."order_date" >= convert(DATETIME, '2019-01-01 00:00:00.000'))
+		)
+	-- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO
 SET ANSI_NULLS OFF 
 SET ANSI_NULLS OFF 
 GO
 GO
 
 
-GO
+GO

+ 9 - 9
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.ben_AW_Order_Number.sql

@@ -2,18 +2,18 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW ims.ben_AW_Order_Number AS
-
-select T1."order_number" as "Order Number",
-	   SUM(T1."duration_minutes") as "Summe_Duration_Minutes"
-from "dbo"."times" T1
-where (T1."order_number" <> 0)
-group by (T1."order_number")
--- order by "Order Number" asc
+CREATE VIEW [ims].[ben_AW_Order_Number]
+AS
+SELECT T1."order_number" AS "Order_Number",
+	SUM(T1."duration_minutes") AS "Summe_Duration_Minutes"
+FROM "dbo"."times" T1
+WHERE (T1."order_number" <> 0)
+GROUP BY (T1."order_number")
+	-- order by "Order Number" asc
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO
 SET ANSI_NULLS OFF 
 SET ANSI_NULLS OFF 
 GO
 GO
 
 
-GO
+GO

+ 77 - 21
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql

@@ -2,30 +2,86 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE VIEW ims.offene_Auftraege_Ums_ben_AW_fuer_Monteure AS
-
-select distinct c6 as "Order Number_ori",
-	   c7 as "Order Number",
-	   c5 as "verk. Std. aus o.A."
-from 
-(select T1."order_number" as c4,
-	   SUM((convert(float, T5."time_units")) / 10) as c5
-from (((("dbo"."order_positions" T1 left outer join "dbo"."vehicles" T2 on T1."vehicle_number" = T2."internal_number") left outer join "dbo"."employees" T3 on T1."order_taking_employee_no" = T3."employee_number") left outer join "dbo"."customers_suppliers" T4 on T1."order_customer" = T4."customer_number") left outer join "dbo"."labours" T5 on T1."order_number" = T5."order_number")
-where ((((T5."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2017-01-01 00:00:00.000'))) and (T5."net_price_in_order" IS NOT NULL)) and (T5."labour_type" <> 'F'))
-group by T1."order_number"
-) D2,
-	
-(select distinct T1."order_number" as c6,
-	   CASE WHEN (T2."license_plate" IS NOT NULL) THEN ((left(((convert(varchar(50), T1."order_number"))))) + ' - ' + CASE WHEN (T1."order_taking_employee_no" = 0) THEN ('SB fehlt') ELSE ((left(((convert(varchar(50), T1."order_taking_employee_no"))))) + ' - ' + T3."name") END + ' - ' + T4."family_name" + ' - ' + (convert(varchar(50), year(T1."order_date")) + '-' + convert(varchar(50), month(T1."order_date")) + '-' + convert(varchar(50), day(T1."order_date"))) + ' - ' + T2."license_plate") ELSE ((left(((convert(varchar(50), T1."order_number"))))) + ' - ' + CASE WHEN (T1."order_taking_employee_no" = 0) THEN ('SB fehlt') ELSE ((left(((convert(varchar(50), T1."order_taking_employee_no"))))) + ' - ' + T3."name") END + ' - ' + T4."family_name" + ' - ' + (convert(varchar(50), year(T1."order_date")) + '-' + convert(varchar(50), month(T1."order_date")) + '-' + convert(varchar(50), day(T1."order_date")))) END as c7
-from (((("dbo"."order_positions" T1 left outer join "dbo"."vehicles" T2 on T1."vehicle_number" = T2."internal_number") left outer join "dbo"."employees" T3 on T1."order_taking_employee_no" = T3."employee_number") left outer join "dbo"."customers_suppliers" T4 on T1."order_customer" = T4."customer_number") left outer join "dbo"."labours" T5 on T1."order_number" = T5."order_number")
-where ((((T5."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2017-01-01 00:00:00.000'))) and (T5."net_price_in_order" IS NOT NULL)) and (T5."labour_type" <> 'F'))
-) D1
-where ((c6 = c4) or ((c6 IS NULL) and (c4 IS NULL)))
--- order by "Order Number_ori" asc
+CREATE VIEW [ims].[offene_Auftraege_Ums_ben_AW_fuer_Monteure]
+AS
+SELECT DISTINCT c6 AS "Order Number_ori",
+	c7 AS "Order Number",
+	c5 AS "verk. Std. aus o.A."
+FROM (
+	SELECT T1."order_number" AS c4,
+		SUM((convert(FLOAT, T5."time_units")) / 10) AS c5
+	FROM (
+		(
+			(
+				(
+					"dbo"."order_positions" T1 LEFT OUTER JOIN "dbo"."vehicles" T2 ON T1."vehicle_number" = T2."internal_number"
+					) LEFT OUTER JOIN "dbo"."employees" T3 ON T1."order_taking_employee_no" = T3."employee_number"
+				) LEFT OUTER JOIN "dbo"."customers_suppliers" T4 ON T1."order_customer" = T4."customer_number"
+			) LEFT OUTER JOIN "dbo"."labours" T5 ON T1."order_number" = T5."order_number"
+		)
+	WHERE (
+			(
+				(
+					(T5."invoice_number" IS NULL)
+					AND (T1."order_date" >= convert(DATETIME, '2017-01-01 00:00:00.000'))
+					)
+				AND (T5."net_price_in_order" IS NOT NULL)
+				)
+			AND (T5."labour_type" <> 'F')
+			)
+	GROUP BY T1."order_number"
+	) D2,
+	(
+		SELECT DISTINCT T1."order_number" AS c6,
+			CASE 
+				WHEN (T2."license_plate" IS NOT NULL)
+					THEN (
+							(substring((convert(VARCHAR(50), T1."order_number")), 1, 6)) + ' - ' + CASE 
+								WHEN (T1."order_taking_employee_no" = 0)
+									THEN ('SB fehlt')
+								ELSE ((substring((convert(VARCHAR(50), T1."order_taking_employee_no")), 1, 4)) + ' - ' + T3."name")
+								END + ' - ' + T4."family_name" + ' - ' + (convert(VARCHAR(50), year(T1."order_date")) + '-' + convert(VARCHAR(50), month(T1."order_date")) + '-' + convert(VARCHAR(50), day(T1."order_date"))) + ' - ' + T2."license_plate"
+							)
+				ELSE (
+						(substring((convert(VARCHAR(50), T1."order_number")), 1, 6)) + ' - ' + CASE 
+							WHEN (T1."order_taking_employee_no" = 0)
+								THEN ('SB fehlt')
+							ELSE ((substring((convert(VARCHAR(50), T1."order_taking_employee_no")), 1, 4)) + ' - ' + T3."name")
+							END + ' - ' + T4."family_name" + ' - ' + (convert(VARCHAR(50), year(T1."order_date")) + '-' + convert(VARCHAR(50), month(T1."order_date")) + '-' + convert(VARCHAR(50), day(T1."order_date")))
+						)
+				END AS c7
+		FROM (
+			(
+				(
+					(
+						"dbo"."order_positions" T1 LEFT OUTER JOIN "dbo"."vehicles" T2 ON T1."vehicle_number" = T2."internal_number"
+						) LEFT OUTER JOIN "dbo"."employees" T3 ON T1."order_taking_employee_no" = T3."employee_number"
+					) LEFT OUTER JOIN "dbo"."customers_suppliers" T4 ON T1."order_customer" = T4."customer_number"
+				) LEFT OUTER JOIN "dbo"."labours" T5 ON T1."order_number" = T5."order_number"
+			)
+		WHERE (
+				(
+					(
+						(T5."invoice_number" IS NULL)
+						AND (T1."order_date" >= convert(DATETIME, '2017-01-01 00:00:00.000'))
+						)
+					AND (T5."net_price_in_order" IS NOT NULL)
+					)
+				AND (T5."labour_type" <> 'F')
+				)
+		) D1
+WHERE (
+		(c6 = c4)
+		OR (
+			(c6 IS NULL)
+			AND (c4 IS NULL)
+			)
+		)
+	-- order by "Order Number_ori" asc
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO
 SET ANSI_NULLS OFF 
 SET ANSI_NULLS OFF 
 GO
 GO
 
 
-GO
+GO

+ 7 - 6
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/invoices.sql

@@ -2,12 +2,13 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-CREATE View [dbo].[invoices] AS
-
-SELECT *, 0 as order_customer,
-cast(T1.invoice_type as varchar(1)) +  right(REPLICATE('0', 12) + cast(T1.invoice_number as varchar(12)), cast(T2.len_invoice_number as int)) as invtype_invnr 
-
-FROM dbo.invoices_import T1, data.GC_Config_Pivot T2
+CREATE VIEW [dbo].[invoices]
+AS
+SELECT *,
+	0 AS order_customer,
+	cast(T1.invoice_type AS VARCHAR(1)) + right(REPLICATE('0', 12) + cast(T1.invoice_number AS VARCHAR(12)), cast(T2.len_invoice_number AS INT)) AS invtype_invnr
+FROM dbo.invoices_import T1,
+	data.GC_Config_Pivot T2
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO

+ 73 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.aftersales_rechnungen_ben_aw_final.sql

@@ -0,0 +1,73 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[aftersales_rechnungen_ben_aw_final]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Employee_Function],
+	[Serviceberater],
+	[Order_Number],
+	[Invoice_Desc_100],
+	[Fabrikat],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Umsatzart],
+	[Auftragsart],
+	[Auftragsposition],
+	[Kundenart],
+	[Kunde],
+	[Order_Desc_30],
+	[Invoice_Desc_30],
+	[c21],
+	[Produktbuchungsgruppe],
+	[FZG_Altersstaffel],
+	[Repair_Group_Desc],
+	[DB1____EK],
+	[Rechnung_Gutschrift],
+	[Parts_Focus_Group],
+	[Parts_Make_Desc],
+	[Parts_Group_Desc],
+	[PLZ_1_Stelle],
+	[PLZ_2_Stelle],
+	[PLZ_3_Stelle],
+	[PLZ_4_Stelle],
+	[PLZ],
+	[Zuordnung_Funktion],
+	[Order_Desc_100],
+	[Lohn],
+	[Teile],
+	[EW_Teile],
+	[Sonst_],
+	[TÜV],
+	[Fremdl_],
+	[Mietw_],
+	[Rädereinl_],
+	[verk__Std_],
+	[ben__Std_],
+	[NL_Lohn],
+	[NL_Teile],
+	[NL_Sonst_],
+	[DG],
+	[NL_Sonst__],
+	[Anz__AT],
+	[Anwesenheit_Mech_Karo_Lack],
+	[Anwesenheit_Meister],
+	[Invoice_Date],
+	[Rechnungsausgang],
+	[Fabrikat_Order_By],
+	[Serviceberater_Rg_Steller]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_ben_aw_final_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 74 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.aftersales_rechnungen_neu.sql

@@ -0,0 +1,74 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[aftersales_rechnungen_neu]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Employee_Function],
+	[Serviceberater],
+	[Order_Number],
+	[Invoice_Desc_100],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Umsatzart],
+	[Auftragsart],
+	[Auftragsposition],
+	[Kundenart],
+	[Kunde],
+	[Order_Desc_30],
+	[Invoice_Desc_30],
+	[c22],
+	[Produktbuchungsgruppe],
+	[FZG_Altersstaffel],
+	[Repair_Group_Desc],
+	[DB1____EK],
+	[Rechnung_Gutschrift],
+	[Parts_Focus_Group],
+	[Parts_Make_Desc],
+	[Parts_Group_Desc],
+	[PLZ_1_Stelle],
+	[PLZ_2_Stelle],
+	[PLZ_3_Stelle],
+	[PLZ_4_Stelle],
+	[PLZ],
+	[Zuordnung_Funktion],
+	[Order_Desc_100],
+	[Lohn],
+	[Teile],
+	[EW_Teile],
+	[Sonst_],
+	[TÜV],
+	[Fremdl_],
+	[Mietw_],
+	[Rädereinl_],
+	[verk__Std_],
+	[ben__Std_],
+	[NL_Lohn],
+	[NL_Teile],
+	[NL_Sonst_],
+	[DG],
+	[NL_Sonst__],
+	[Anz__AT],
+	[Anwesenheit_Mech_Karo_Lack],
+	[Anwesenheit_Meister],
+	[Invoice_Date],
+	[Rechnungsausgang],
+	[EW_Fremdl_],
+	[Serviceberater_Rg_Steller]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_neu_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 73 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.aftersales_rechnungen_verk_aw_final.sql

@@ -0,0 +1,73 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[aftersales_rechnungen_verk_aw_final]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Employee_Function],
+	[Serviceberater],
+	[Order_Number],
+	[Invoice_Desc_100],
+	[Fabrikat],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Umsatzart],
+	[Auftragsart],
+	[Auftragsposition],
+	[Kundenart],
+	[Kunde],
+	[Order_Desc_30],
+	[Invoice_Desc_30],
+	[c21],
+	[Produktbuchungsgruppe],
+	[FZG_Altersstaffel],
+	[Repair_Group_Desc],
+	[DB1____EK],
+	[Rechnung_Gutschrift],
+	[Parts_Focus_Group],
+	[Parts_Make_Desc],
+	[Parts_Group_Desc],
+	[PLZ_1_Stelle],
+	[PLZ_2_Stelle],
+	[PLZ_3_Stelle],
+	[PLZ_4_Stelle],
+	[PLZ],
+	[Zuordnung_Funktion],
+	[Order_Desc_100],
+	[Lohn],
+	[Teile],
+	[EW_Teile],
+	[Sonst_],
+	[TÜV],
+	[Fremdl_],
+	[Mietw_],
+	[Rädereinl_],
+	[verk__Std_],
+	[ben__Std_],
+	[NL_Lohn],
+	[NL_Teile],
+	[NL_Sonst_],
+	[DG],
+	[NL_Sonst__],
+	[Anz__AT],
+	[Anwesenheit_Mech_Karo_Lack],
+	[Anwesenheit_Meister],
+	[Invoice_Date],
+	[Rechnungsausgang],
+	[Fabrikat_Order_By],
+	[Serviceberater_Rg_Steller]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_verk_aw_final_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 33 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.current_date_prognose.sql

@@ -0,0 +1,33 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [load].[current_date_prognose]
+AS
+SELECT "current_date_Prognose"."Bundeslaender Id" AS "Bundeslaender_Id",
+	"current_date_Prognose"."Invoice Date" AS "Invoice_Date",
+	"current_date_Prognose"."Wochentage Id" AS "Wochentage_Id",
+	"current_date_Prognose"."Arbeitstag Mofr" AS "Arbeitstag_Mofr",
+	"current_date_Prognose"."Zaehler Mofr" AS "Zaehler_Mofr",
+	"current_date_Prognose"."Summe Mofr" AS "Summe_Mofr",
+	"current_date_Prognose"."Arbeitstag Mosa" AS "Arbeitstag_Mosa",
+	"current_date_Prognose"."Zaehler Mosa" AS "Zaehler_Mosa",
+	"current_date_Prognose"."Summe Mosa" AS "Summe_Mosa",
+	"current_date_Prognose"."Feiertage Id" AS "Feiertage_Id",
+	"current_date_Prognose"."Jahr" AS "Jahr",
+	"current_date_Prognose"."Arbeitstag Nr Jahr" AS "Arbeitstag_Nr_Jahr",
+	"current_date_Prognose"."Gesamt Arbeitstage" AS "Gesamt_Arbeitstage"
+FROM "GC"."data"."current_date_Prognose" "current_date_Prognose"
+WHERE "current_date_Prognose"."Invoice Date" < getdate()
+	AND "current_date_Prognose"."Bundeslaender Id" = 10
+	AND (
+		"current_date_Prognose"."Arbeitstag Mosa" = 1
+		OR "current_date_Prognose"."Feiertage Id" = 23
+		)
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 39 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.current_date_prognose_operativ.sql

@@ -0,0 +1,39 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [load].[current_date_prognose_operativ]
+AS
+SELECT "current_date_Prognose_operativ"."Bundeslaender Id" AS "Bundeslaender_Id",
+	"current_date_Prognose_operativ"."Invoice Date" AS "Invoice_Date",
+	"current_date_Prognose_operativ"."Wochentage Id" AS "Wochentage_Id",
+	"current_date_Prognose_operativ"."Arbeitstag Mofr" AS "Arbeitstag_Mofr",
+	"current_date_Prognose_operativ"."Zaehler Mofr" AS "Zaehler_Mofr",
+	"current_date_Prognose_operativ"."Summe Mofr" AS "Summe_Mofr",
+	"current_date_Prognose_operativ"."Arbeitstag Mosa" AS "Arbeitstag_Mosa",
+	"current_date_Prognose_operativ"."Zaehler Mosa" AS "Zaehler_Mosa",
+	"current_date_Prognose_operativ"."Summe Mosa" AS "Summe_Mosa",
+	"current_date_Prognose_operativ"."Feiertage Id" AS "Feiertage_Id",
+	"current_date_Prognose_operativ"."Jahr" AS "Jahr",
+	"current_date_Prognose_operativ"."Arbeitstag Nr Jahr" AS "Arbeitstag_Nr_Jahr",
+	"current_date_Prognose_operativ"."Gesamt Arbeitstage" AS "Gesamt_Arbeitstage"
+FROM "GC"."data"."current_date_Prognose_operativ" "current_date_Prognose_operativ"
+WHERE "current_date_Prognose_operativ"."Invoice Date" < convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)
+	AND "current_date_Prognose_operativ"."Bundeslaender Id" = 10
+	AND (
+		"current_date_Prognose_operativ"."Arbeitstag Mosa" = 1
+		OR CASE 
+			WHEN DATEDIFF(DY, DATEADD(DY, 3, DATEADD(YY, 1, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)))), convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) + ((DATEPART(DW, DATEADD(DY, 3, DATEADD(YY, 1, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112))))) + 5 - @@DATEFIRST) % 7 + 7) % 7 >= 0
+				THEN 1
+			WHEN DATEDIFF(DY, DATEADD(DY, 3, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112))), convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) + ((DATEPART(DW, DATEADD(DY, 3, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)))) + 5 - @@DATEFIRST) % 7 + 7) % 7 >= 0
+				THEN (DATEDIFF(DY, DATEADD(DY, 3, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112))), convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) + ((DATEPART(DW, DATEADD(DY, 3, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)))) + 5 - @@DATEFIRST) % 7 + 7) % 7) / 7 + 1
+			ELSE (DATEDIFF(DY, DATEADD(DY, 3, DATEADD(YY, - 1, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)))), convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) + ((DATEPART(DW, DATEADD(DY, 3, DATEADD(YY, - 1, DATENAME(YY, convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112))))) + 5 - @@DATEFIRST) % 7 + 7) % 7) / 7 + 1
+			END = 1
+		)
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 29 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.current_date_prognose_operativ_vj.sql

@@ -0,0 +1,29 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [load].[current_date_prognose_operativ_vj]
+AS
+SELECT "T1"."Bundeslaender Id" AS "Bundeslaender_Id",
+	"T1"."Invoice Date" AS "Invoice_Date",
+	"T1"."Wochentage Id" AS "Wochentage_Id",
+	"T1"."Arbeitstag Mofr" AS "Arbeitstag_Mofr",
+	"T1"."Zaehler Mofr" AS "Zaehler_Mofr",
+	"T1"."Summe Mofr" AS "Summe_Mofr",
+	"T1"."Arbeitstag Mosa" AS "Arbeitstag_Mosa",
+	"T1"."Zaehler Mosa" AS "Zaehler_Mosa",
+	"T1"."Summe Mosa" AS "Summe_Mosa",
+	"T1"."Feiertage Id" AS "Feiertage_Id",
+	"T1"."Jahr" AS "Jahr",
+	"T1"."Arbeitstag Nr Jahr" AS "Arbeitstag_Nr_Jahr",
+	"T1"."Gesamt Arbeitstage" AS "Gesamt_Arbeitstage"
+FROM "GC"."data"."current_date_Prognose_operativ_VJ" "T1"
+WHERE "T1"."Bundeslaender Id" = 10
+	AND "T1"."Arbeitstag Mosa" = 1
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 65 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege.sql

@@ -0,0 +1,65 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[loc_belege]
+AS
+SELECT [Rechtseinheit_ID],
+	[Rechtseinheit_Name],
+	[Betrieb_ID],
+	[Betrieb_Name],
+	[Ebene1],
+	[Ebene2],
+	[Ebene3],
+	[Ebene4],
+	[Ebene5],
+	[Ebene6],
+	[Konto],
+	[Acct_Nr],
+	[Text],
+	[Kostenstelle],
+	[KST_mit_Bez],
+	[KST],
+	[Markencode],
+	[Fahrgestellnummer],
+	[Konto_Buchung],
+	[Marke_mit_Bez],
+	[Marke],
+	[Ebene21],
+	[Absatzkanal_mit_Bez],
+	[Absatzkanal],
+	[Ebene31],
+	[Kostenträger_mit_Bez],
+	[Kostenträger_FIBU],
+	[Ebene71],
+	[Ebene72],
+	[Ebene73],
+	[Ebene74],
+	[Ebene75],
+	[Ebene76],
+	[Ebene77],
+	[Ebene81],
+	[Ebene82],
+	[Ebene83],
+	[Ebene84],
+	[Ebene85],
+	[Ebene86],
+	[GuV_Bilanz],
+	[Susa],
+	[Mandant],
+	[Ist],
+	[Menge],
+	[Gruppe_ID],
+	[Gruppe_Name],
+	[Invoice_Date],
+	[Fabrikat],
+	[Fabrikat_Order_By]
+FROM [LOCOSOFT].[staging].[loc_belege_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 65 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege_bilanz.sql

@@ -0,0 +1,65 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[loc_belege_bilanz]
+AS
+SELECT [Rechtseinheit_ID],
+	[Rechtseinheit_Name],
+	[Betrieb_ID],
+	[Betrieb_Name],
+	[Ebene1],
+	[Ebene2],
+	[Ebene3],
+	[Ebene4],
+	[Ebene5],
+	[Ebene6],
+	[Konto],
+	[Acct_Nr],
+	[Text],
+	[Kostenstelle],
+	[KST_mit_Bez],
+	[KST],
+	[Markencode],
+	[Fahrgestellnummer],
+	[Konto_Buchung],
+	[Marke_mit_Bez],
+	[Marke],
+	[Ebene21],
+	[Absatzkanal_mit_Bez],
+	[Absatzkanal],
+	[Ebene31],
+	[Kostenträger_mit_Bez],
+	[Kostenträger_FIBU],
+	[Ebene71],
+	[Ebene72],
+	[Ebene73],
+	[Ebene74],
+	[Ebene75],
+	[Ebene76],
+	[Ebene77],
+	[Ebene81],
+	[Ebene82],
+	[Ebene83],
+	[Ebene84],
+	[Ebene85],
+	[Ebene86],
+	[GuV_Bilanz],
+	[Susa],
+	[Mandant],
+	[Ist],
+	[Menge],
+	[Gruppe_ID],
+	[Gruppe_Name],
+	[Invoice_Date],
+	[Fabrikat],
+	[Fabrikat_Order_By]
+FROM [LOCOSOFT].[staging].[loc_belege_bilanz_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 67 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege_nw_gw_vk.sql

@@ -0,0 +1,67 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[loc_belege_nw_gw_vk]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Verkäufer],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Model],
+	[FZG],
+	[Konto],
+	[Modell_Beschreibung],
+	[Kunde],
+	[Kundenart],
+	[Fahrzeugart],
+	[Fahrzeugtyp],
+	[Fahrzeugtyp_1],
+	[FZG_Detail],
+	[Buch_Text],
+	[PLZ_1],
+	[PLZ_2],
+	[PLZ_3],
+	[PLZ_4],
+	[PLZ_Code_Deb],
+	[Name_Lieferant],
+	[DB1___0],
+	[Name_Einkäufer],
+	[Menge],
+	[Erlös_FZG],
+	[Einsatz_FZG],
+	[Boni],
+	[Nachlass],
+	[Erlös_Prov_],
+	[Erlös_Überf_],
+	[VAK_Überf_],
+	[Erlös_Gar_],
+	[VAK_Gar_],
+	[Erlös_Zul_],
+	[VAK_Zul_],
+	[Erlös_Nachr_],
+	[VAK_Nachr_],
+	[Erlös_Sonst_],
+	[VAK_Sonst_],
+	[VAK_Inst_setz_],
+	[Standtage],
+	[Instands__Werkstatt],
+	[Instands__Teile],
+	[Instandsetzung_ges_],
+	[Gesamterlöse],
+	[Einsatz_Gesamt],
+	[Invoice_Date],
+	[VAK_intern],
+	[PKW_NFZ]
+FROM [LOCOSOFT].[staging].[loc_belege_nw_gw_vk_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 65 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.loc_belege_nw_gw_vk_stk_fibu.sql

@@ -0,0 +1,65 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[loc_belege_nw_gw_vk_stk_fibu]
+AS
+SELECT [Rechtseinheit_ID],
+	[Rechtseinheit_Name],
+	[Betrieb_ID],
+	[Betrieb_Name],
+	[Ebene1],
+	[Ebene2],
+	[Ebene3],
+	[Ebene4],
+	[Ebene5],
+	[Ebene6],
+	[Konto],
+	[Acct_Nr],
+	[Text],
+	[Kostenstelle],
+	[KST_mit_Bez],
+	[KST],
+	[Markencode],
+	[Fahrgestellnummer],
+	[Konto_Buchung],
+	[Marke_mit_Bez],
+	[Marke],
+	[Ebene21],
+	[Absatzkanal_mit_Bez],
+	[Absatzkanal],
+	[Ebene31],
+	[Kostenträger_mit_Bez],
+	[Kostenträger_FIBU],
+	[Ebene71],
+	[Ebene72],
+	[Ebene73],
+	[Ebene74],
+	[Ebene75],
+	[Ebene76],
+	[Ebene77],
+	[Ebene81],
+	[Ebene82],
+	[Ebene83],
+	[Ebene84],
+	[Ebene85],
+	[Ebene86],
+	[GuV_Bilanz],
+	[Susa],
+	[Mandant],
+	[Ist],
+	[Menge],
+	[Gruppe_ID],
+	[Gruppe_Name],
+	[Invoice_Date],
+	[Fabrikat],
+	[Fabrikat_Order_By]
+FROM [LOCOSOFT].[staging].[loc_belege_nw_gw_vk_stk_fibu_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 48 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.nw_gw_be_auf_nw_gw_bestand_cat.sql

@@ -0,0 +1,48 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[nw_gw_be_auf_nw_gw_bestand_cat]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Fabrikat],
+	[Modell_Beschreibung],
+	[Model],
+	[FZG],
+	[Fahrzeugart],
+	[Fahrzeugtyp],
+	[Fahrzeugtyp_1],
+	[Standtagestaffel],
+	[Farbe],
+	[Standort_1],
+	[Lieferant_Einkäufer],
+	[Name_Lieferant],
+	[Name_Einkäufer],
+	[FZG_Einkäufer],
+	[EZ],
+	[Km_stand],
+	[Menge],
+	[Einsatz],
+	[int__Aufw_],
+	[Standtage],
+	[Plan_VK_Netz_brutto],
+	[Plan_VK_Netz_netto],
+	[Plan_Vk_Platz_brutto],
+	[Plan_VK_Platz_netto],
+	[Einsatz_ori__Betrag_FIBU_],
+	[Einsatz_ber],
+	[Invoice_Date],
+	[Fabrikat_Order_By],
+	[Standtage_ER]
+FROM [LOCOSOFT].[staging].[nw_gw_be_auf_nw_gw_bestand_cat_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 69 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.nw_gw_vk_journal_accountings.sql

@@ -0,0 +1,69 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[nw_gw_vk_journal_accountings]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Verkäufer],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Model],
+	[FZG],
+	[Konto],
+	[Modell_Beschreibung],
+	[Kunde],
+	[Kundenart],
+	[Fahrzeugart],
+	[Fahrzeugtyp],
+	[Fahrzeugtyp_1],
+	[FZG_Detail],
+	[Buch_Text],
+	[PLZ_1],
+	[PLZ_2],
+	[PLZ_3],
+	[PLZ_4],
+	[PLZ_Code_Deb],
+	[Name_Lieferant],
+	[DB1___0],
+	[Name_Einkäufer],
+	[Menge],
+	[Erlös_FZG],
+	[Einsatz_FZG],
+	[Boni],
+	[Nachlass],
+	[Erlös_Prov_],
+	[Erlös_Überf_],
+	[VAK_Überf_],
+	[Erlös_Gar_],
+	[VAK_Gar_],
+	[Erlös_Zul_],
+	[VAK_Zul_],
+	[Erlös_Nachr_],
+	[VAK_Nachr_],
+	[Erlös_Sonst_],
+	[VAK_Sonst_],
+	[VAK_Inst_setz_],
+	[Standtage],
+	[Instands__Werkstatt],
+	[Instands__Teile],
+	[Instandsetzung_ges_],
+	[Gesamterlöse_aus_imr],
+	[Einsatz_Gesamt_aus_imr],
+	[Invoice_Date],
+	[Erlös_ges_],
+	[VAK_intern],
+	[VAK_ges_],
+	[PKW_NFZ]
+FROM [LOCOSOFT].[staging].[nw_gw_vk_journal_accountings_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 35 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.offene_auftraege_dg_anz_tage.sql

@@ -0,0 +1,35 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[offene_auftraege_dg_anz_tage]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Serviceberater],
+	[Order_Number],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Kunde],
+	[Turnover_Type_Desc],
+	[Tage_offen],
+	[DG],
+	[Lohn],
+	[Teile],
+	[Sonst_],
+	[Invoice_Date]
+FROM [LOCOSOFT].[staging].[offene_auftraege_dg_anz_tage_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 35 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.offene_auftraege_teile.sql

@@ -0,0 +1,35 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[offene_auftraege_teile]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Serviceberater],
+	[Order_Number],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Kunde],
+	[Turnover_Type_Desc],
+	[Tage_offen],
+	[DG],
+	[Lohn],
+	[Teile],
+	[Sonst_],
+	[Invoice_Date]
+FROM [LOCOSOFT].[staging].[offene_auftraege_teile_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 36 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.offene_auftraege_ums_ben_aw.sql

@@ -0,0 +1,36 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[offene_auftraege_ums_ben_aw]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Serviceberater],
+	[Order_Number],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Kunde],
+	[Turnover_Type_Desc],
+	[Tage_offen],
+	[DG],
+	[Lohn],
+	[Teile],
+	[Sonst_],
+	[ben_Std],
+	[Invoice_Date]
+FROM [LOCOSOFT].[staging].[offene_auftraege_ums_ben_aw_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 33 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.op_aus_loc_belege_deb_saldo.sql

@@ -0,0 +1,33 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[op_aus_loc_belege_deb_saldo]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Sel_Name],
+	[Kunde],
+	[Beleg],
+	[Kostenstelle],
+	[Bereich],
+	[Staffel],
+	[Forderungsart],
+	[Abwarten],
+	[Leasing],
+	[offen],
+	[Rechnungsbetrag],
+	[Gesamt_offen_KD__Info_],
+	[Invoice_Date],
+	[Bonus_Startguthaben]
+FROM [LOCOSOFT].[staging].[op_aus_loc_belege_deb_saldo_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 33 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.op_aus_loc_belege_ohne_8520.sql

@@ -0,0 +1,33 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[op_aus_loc_belege_ohne_8520]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Sel_Name],
+	[Kunde],
+	[Beleg],
+	[Kostenstelle],
+	[Bereich],
+	[Staffel],
+	[Forderungsart],
+	[Abwarten],
+	[Leasing],
+	[offen],
+	[Rechnungsbetrag],
+	[Gesamt_offen_KD__Info_],
+	[Invoice_Date],
+	[Bonus_Startguthaben]
+FROM [LOCOSOFT].[staging].[op_aus_loc_belege_ohne_8520_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 66 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.umsatz_belege_skr.sql

@@ -0,0 +1,66 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[umsatz_belege_skr]
+AS
+SELECT [Rechtseinheit_ID],
+	[Rechtseinheit_Name],
+	[Betrieb_ID],
+	[Betrieb_Name],
+	[Ebene1_],
+	[Ebene2_],
+	[Ebene3_],
+	[Ebene4_],
+	[Ebene5_],
+	[Ebene6_],
+	[Konto_],
+	[Acct_Nr_],
+	[Text],
+	[Kostenstelle],
+	[KST_mit_Bez],
+	[KST],
+	[Markencode],
+	[Fahrgestellnummer],
+	[Konto_Buchung],
+	[Marke_mit_Bez],
+	[Marke],
+	[Ebene21],
+	[Absatzkanal_mit_Bez],
+	[Absatzkanal],
+	[Ebene31],
+	[Kostenträger_mit_Bez],
+	[Kostenträger_FIBU],
+	[Ebene71],
+	[Ebene72],
+	[Ebene73],
+	[Ebene74],
+	[Ebene75],
+	[Ebene76],
+	[Ebene77],
+	[Ebene81],
+	[Ebene82],
+	[Ebene83],
+	[Ebene84],
+	[Ebene85],
+	[Ebene86],
+	[GuV_Bilanz],
+	[Susa],
+	[Mandant],
+	[Ist_],
+	[Menge_],
+	[Gruppe_ID],
+	[Gruppe_Name],
+	[Invoice_Date],
+	[Fabrikat],
+	[Fabrikat_Order_By],
+	[Umsatz_FIBU_gesamt]
+FROM [LOCOSOFT].[staging].[umsatz_belege_skr_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 41 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_abwesenheit_neu.sql

@@ -0,0 +1,41 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[zeit_abwesenheit_neu]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Monteur_Gruppe],
+	[Monteur_Gruppe_2],
+	[Monteur],
+	[Order_Number],
+	[Activity_Codes_Group1],
+	[Activity_Codes_Group2],
+	[Activity_Desc],
+	[Kostenstelle],
+	[Invoice_Date],
+	[prod_],
+	[unprod_],
+	[Abw_],
+	[Extern],
+	[GWL],
+	[Intern],
+	[Sollzeit],
+	[TOY_produktiv_Zeit],
+	[verr__Zeit_ohne_TOY],
+	[ben__Zeit_ohne_TOY],
+	[Anz__AT],
+	[Order_Positions_Times],
+	[Status]
+FROM [LOCOSOFT].[staging].[zeit_abwesenheit_neu_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 42 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_ben_std_lg.sql

@@ -0,0 +1,42 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[zeit_ben_std_lg]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Monteur_Gruppe],
+	[Monteur_Gruppe_2],
+	[Monteur],
+	[Order_Number],
+	[Activity_Codes_Group1],
+	[Activity_Codes_Group2],
+	[Activity_Desc],
+	[Kostenstelle],
+	[Invoice_Date],
+	[prod__],
+	[unprod__falsch],
+	[Abw_],
+	[Extern],
+	[GWL],
+	[Intern],
+	[Sollzeit],
+	[TOY_produktiv_Zeit],
+	[verr__Zeit_ohne_TOY],
+	[ben__Zeit_ohne_TOY],
+	[Anz__AT],
+	[ben__Zeit],
+	[Order_Positions_Times],
+	[Status]
+FROM [LOCOSOFT].[staging].[zeit_ben_std_lg_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 43 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_stempelungen_neu.sql

@@ -0,0 +1,43 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[zeit_stempelungen_neu]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Monteur_Gruppe],
+	[Monteur_Gruppe_2],
+	[Monteur],
+	[Order_Number],
+	[Activity_Codes_Group1],
+	[Activity_Codes_Group2],
+	[Activity_Desc],
+	[Kostenstelle],
+	[Invoice_Date],
+	[prod_],
+	[unprod__falsch],
+	[Abw_],
+	[Extern],
+	[GWL],
+	[Intern],
+	[Sollzeit],
+	[TOY_produktiv_Zeit],
+	[verr__Zeit_ohne_TOY],
+	[ben__Zeit_ohne_TOY],
+	[Anz__AT],
+	[Anw_],
+	[Order_Positions_Times],
+	[Status],
+	[prod__aus_o_A_]
+FROM [LOCOSOFT].[staging].[zeit_stempelungen_neu_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 40 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_stempelungen_pausen.sql

@@ -0,0 +1,40 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[zeit_stempelungen_pausen]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Monteur_Gruppe],
+	[Monteur_Gruppe_2],
+	[Monteur],
+	[Order_Number],
+	[Activity_Codes_Group1],
+	[Activity_Codes_Group2],
+	[Activity_Desc],
+	[Kostenstelle],
+	[Invoice_Date],
+	[prod_],
+	[unprod__falsch],
+	[Abw_],
+	[Extern],
+	[GWL],
+	[Intern],
+	[Sollzeit],
+	[TOY_produktiv_Zeit],
+	[verr__Zeit_ohne_TOY],
+	[ben__Zeit_ohne_TOY],
+	[Anz__AT],
+	[Anw_]
+FROM [LOCOSOFT].[staging].[zeit_stempelungen_pausen_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 39 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_stempelungen_pausen_produktiv.sql

@@ -0,0 +1,39 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[zeit_stempelungen_pausen_produktiv]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Monteur_Gruppe],
+	[Monteur_Gruppe_2],
+	[Monteur],
+	[Order_Number],
+	[Activity_Codes_Group1],
+	[Activity_Codes_Group2],
+	[Activity_Desc],
+	[Kostenstelle],
+	[Invoice_Date],
+	[prod_],
+	[unprod__falsch],
+	[Abw_],
+	[Extern],
+	[GWL],
+	[Intern],
+	[Sollzeit],
+	[TOY_produktiv_Zeit],
+	[verr__Zeit_ohne_TOY],
+	[ben__Zeit_ohne_TOY],
+	[Anz__AT]
+FROM [LOCOSOFT].[staging].[zeit_stempelungen_pausen_produktiv_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 43 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/load.zeit_verk_std.sql

@@ -0,0 +1,43 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [load].[zeit_verk_std]
+AS
+SELECT [Hauptbetrieb_ID],
+	[Hauptbetrieb_Name],
+	[Standort_ID],
+	[Standort_Name],
+	[Monteur_Gruppe],
+	[Monteur_Gruppe_2],
+	[Monteur],
+	[Order_Number],
+	[Activity_Codes_Group1],
+	[Activity_Codes_Group2],
+	[Activity_Desc],
+	[Kostenstelle],
+	[Invoice_Date],
+	[prod__],
+	[unprod__],
+	[Abw_],
+	[Extern],
+	[GWL],
+	[Intern],
+	[Sollzeit],
+	[TOY_produktiv_Zeit],
+	[verr__Zeit_ohne_TOY],
+	[ben__Zeit_ohne_TOY],
+	[Anz__AT],
+	[verr__Zeit],
+	[Order_Positions_Times],
+	[Status],
+	[Umsatz_Lohn]
+FROM [LOCOSOFT].[staging].[zeit_verk_std_0]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 0 - 255
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/locosoft.LOC_Belege.sql

@@ -1,255 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW locosoft.LOC_Belege AS
-
-select 
-    T1."accounting_date" as "Accounting Date",
-    T1."document_type" as "Document Type",
-    T1."document_number" as "Document Number",
-    T1."position_in_document" as "Position In Document",
-    T1."customer_number" as "Customer Number",
-    T1."nominal_account_number" as "Nominal Account Number",
-    T1."is_balanced" as "Is Balanced",
-    T1."clearing_number" as "Clearing Number",
-    T1."document_date" as "Document Date",
-    T1."posted_value" as "Posted Value",
-    T1."debit_or_credit" as "Debit Or Credit",
-    T1."posted_count" as "Posted Count",
-    T1."branch_number" as "Branch Number",
-    T1."customer_contra_account" as "Customer Contra Account",
-    T1."nominal_contra_account" as "Nominal Contra Account", 
-    T1."contra_account_text" as "Contra Account Text",
-    T1."account_form_page_number" as "Account Form Page Number",
-    T1."account_form_page_line" as "Account Form Page Line",
-    T1."serial_number_each_month" as "Serial Number Each Month",
-    T1."employee_number" as "Employee Number",
-    T1."invoice_date" as "Invoice Date",
-    T1."invoice_number" as "Invoice Number",
-    T1."dunning_level" as "Dunning Level",   
-    T1."last_dunning_date" as "Last Dunning Date",
-    T1."journal_page" as "Journal Page",
-    T1."journal_line" as "Journal Line",
-    T1."cash_discount" as "Cash Discount",
-    T1."term_of_payment" as "Term Of Payment",
-    T1."posting_text" as "Posting Text",
-    T1."vehicle_reference" as "Vehicle Reference",
-    T1."vat_id_number" as "Vat Id Number",
-    T1."account_statement_number" as "Account Statement Number",
-    T1."account_statement_page" as "Account Statement Page",
-    T1."vat_key" as "Vat Key",
-    T1."days_for_cash_discount" as "Days For Cash Discount",
-    T1."day_of_actual_accounting" as "Day Of Actual Accounting",
-    T1."skr51_branch" as "Skr51 Branch",
-    T1."skr51_make" as "Skr51 Make",
-    T1."skr51_cost_center" as "Skr51 Cost Center",
-    T1."skr51_sales_channel" as "Skr51 Sales Channel",
-    T1."skr51_cost_unit" as "Skr51 Cost Unit",
-    T1."previously_used_account_no" as "Previously Used Account No",
-    T1."free_form_accounting_text" as "Free Form Accounting Text",
-
-    case
-        when T1."skr51_cost_unit" between 1 and 49 then 'Neuwagen'
-        when T1."skr51_cost_unit" between 50 and 59 then 'Gebrauchtwagen'
-        when T1."skr51_cost_unit" between 60 and 69 then 'Teile & Zubehör'
-        when T1."skr51_cost_unit" between 70 and 79 then 'Service'
-        when T1."skr51_cost_unit" = 0 then 'Ohne Kostenträger'
-        else NULL
-    end as "Free Form Document Text",
-    T2."is_profit_loss_account" as "Nom_Account_Is Profit Loss Account",
-    '1' as "Rechtseinheit",
-    { fn CONCAT(
-        '0',
-        CAST(
-            CAST(T1."subsidiary_to_company_ref" AS INTEGER) AS CHAR(254)
-        )
-    ) } as "Betrieb",
-    case
-        when T1."posting_text" = 'Saldenübernahme CDK'
-        or T1."accounting_date" = '2019-01-01' then convert(datetime, '2019-12-01')
-        else T1."accounting_date"
-    end as "Bookkeep Date",
-    { fn CONCAT(
-        { fn CONCAT(
-            { fn RTRIM(
-                CAST(CAST(T1."skr51_make" AS INTEGER) AS CHAR(254))
-            ) },
-            ' - '
-        ) },
-        T3."skr51_make_description"
-    ) } as "Marke",
-    
-    
-    isnull(CAST(T1."invoice_number" as VARCHAR(100)), '') + ' - ' + T1."posting_text" + '/' + isnull(T1."vehicle_reference",'') + ' - ' + isnull(CAST(T1."employee_number" as VARCHAR(50)), '') as "Text",
-
-
-    '1' as "Mandant",
-    case
-        when T1."debit_or_credit" = 'H' then (CAST(T1."posted_value" AS FLOAT) / 100) * -1
-        else CAST(T1."posted_value" AS FLOAT) / 100
-    end as "Betrag",
-    { fn CONCAT(
-        { fn CONCAT(
-            { fn LEFT(
-                CAST(
-                    CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
-                ),
-                4
-            ) },
-            ' - '
-        ) },
-        T2."account_description"
-    ) } as "Konto_mit_Bezeichnung",
-    case
-        when T1."debit_or_credit" = 'H' then (CAST(T1."posted_count" AS FLOAT) / 100) * -1
-        else CAST(T1."posted_count" AS FLOAT) / 100
-    end as "Menge",
-    { fn LENGTH(
-        { fn CONCAT(
-            CAST(
-                CAST(T1."skr51_cost_center" AS INTEGER) AS CHAR(254)
-            ),
-            'Z'
-        ) }
-    ) } - 1 as "Stellen Cost Center",
-    { fn CONCAT(
-        { fn CONCAT(
-            { fn RTRIM(
-                CAST(
-                    CAST(T1."skr51_cost_center" AS INTEGER) AS CHAR(254)
-                )
-            ) },
-            ' - '
-        ) },
-        T3."skr51_cost_center_name"
-    ) } as "KST",
-    { fn LENGTH(
-        { fn CONCAT(
-            CAST(
-                CAST(T1."skr51_sales_channel" AS INTEGER) AS CHAR(254)
-            ),
-            'Z'
-        ) }
-    ) } - 1 as "Stellen Sales Channel",
-
-    { fn CONCAT(
-        { fn CONCAT(
-            { fn RTRIM(
-                CAST(
-                    CAST(T1."skr51_sales_channel" AS INTEGER) AS CHAR(254)
-                )
-            ) },
-            ' - '
-        ) },
-        T3."skr51_sales_channel_name"
-    ) } as "Absatzkanal",
-    { fn LENGTH(
-        { fn CONCAT(
-            CAST(
-                CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
-            ),
-            'Z'
-        ) }
-    ) } - 1 as "Stellen Cost Unit",
-    { fn CONCAT(
-        { fn CONCAT(
-            { fn CONCAT(
-                { fn CONCAT(
-                    { fn RTRIM(
-                        CAST(CAST(T1."skr51_make" AS INTEGER) AS CHAR(254))
-                    ) },
-                    ' - '
-                ) },
-                { fn RTRIM(
-                    CAST(
-                        CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
-                    )
-                ) }
-            ) },
-            ' - '
-        ) },
-        T3."skr51_cost_unit_name"
-    ) } as "Kostenträger_mit_Null",
-    case
-        when T1."skr51_cost_unit" between 1 and 49 then { fn CONCAT(
-            { fn CONCAT(
-                { fn CONCAT(
-                    { fn CONCAT(
-                        { fn RTRIM(
-                            CAST(CAST(T1."skr51_make" AS INTEGER) AS CHAR(254))
-                        ) },
-                        ' - '
-                    ) },
-                    { fn RTRIM(
-                        CAST(
-                            CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
-                        )
-                    ) }
-                ) },
-                ' - '
-            ) },
-            T3."skr51_cost_unit_name"
-        ) }
-        else { fn CONCAT(
-            { fn CONCAT(
-                { fn RTRIM(
-                    CAST(
-                        CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
-                    )
-                ) },
-                ' - '
-            ) },
-            T3."skr51_cost_unit_name"
-        ) }
-    end as "Kostenträger",
-    case
-        when T2."is_profit_loss_account" = 'J' then '2'
-        else '1'
-    end as "GuV_Bilanz",
-    { fn LEFT(
-        CAST(
-            CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
-        ),
-        1
-    ) } as "Susa",
-    case
-        when T1."skr51_cost_center" <> 0 then { fn CONCAT(
-            { fn CONCAT(
-                { fn RTRIM(
-                    CAST(
-                        CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
-                    )
-                ) },
-                '_'
-            ) },
-            { fn RTRIM(
-                CAST(
-                    CAST(T1."skr51_cost_center" AS INTEGER) AS CHAR(254)
-                )
-            ) }
-        ) }
-        else CAST(
-            CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
-        )
-    end as "Acct Nr"
-
-
-from "dbo"."journal_accountings" T1
-    INNER JOIN "dbo"."nominal_accounts" T2 ON T2."nominal_account_number" = T1."nominal_account_number"
-    and T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref"
-    LEFT OUTER JOIN "dbo"."accounts_characteristics" T3 on T1."subsidiary_to_company_ref" = T3."subsidiary_to_company_ref"
-    and T1."skr51_branch" = T3."skr51_branch"
-    and T1."skr51_make" = T3."skr51_make"
-    and T1."skr51_cost_center" = T3."skr51_cost_center"
-    and T1."skr51_sales_channel" = T3."skr51_sales_channel"
-    and T1."skr51_cost_unit" = T3."skr51_cost_unit"
-where 
-    T2."is_profit_loss_account" = 'J'
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 25 - 25
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/order_positions.sql

@@ -2,31 +2,31 @@ SET QUOTED_IDENTIFIER ON
 GO
 GO
 SET ANSI_NULLS ON 
 SET ANSI_NULLS ON 
 GO
 GO
-Create view dbo.order_positions as
-SELECT 
-	   number as [order_number]
-      ,0 as [order_position]
-      ,'0' as [labour_type]
-      ,[subsidiary]
-      ,0 as [is_invoiced]
-      ,0 as [invoice_type]
-      ,0 as [invoice_number]
-      ,[order_date]
-      ,[estimated_inbound_time]
-      ,[estimated_outbound_time]
-      ,[order_print_date]
-      ,[order_taking_employee_no]
-      ,[order_delivery_employee_no]
-      ,[vehicle_number]
-      ,[dealer_vehicle_type]
-      ,[dealer_vehicle_number]
-      ,[order_mileage]
-      ,[order_customer]
-      ,[paying_customer]
-      ,0 as [holder_number]
-      ,[parts_rebate_group_sell]
-      ,[clearing_delay_type]
-  FROM [LOCOSOFT].[dbo].[orders]
+CREATE VIEW [dbo].[order_positions]
+AS
+SELECT number AS [order_number],
+	0 AS [order_position],
+	'0' AS [labour_type],
+	[subsidiary],
+	0 AS [is_invoiced],
+	0 AS [invoice_type],
+	0 AS [invoice_number],
+	[order_date],
+	[estimated_inbound_time],
+	[estimated_outbound_time],
+	[order_print_date],
+	[order_taking_employee_no],
+	[order_delivery_employee_no],
+	[vehicle_number],
+	[dealer_vehicle_type],
+	[dealer_vehicle_number],
+	[order_mileage],
+	[order_customer],
+	[paying_customer],
+	0 AS [holder_number],
+	[parts_rebate_group_sell],
+	[clearing_delay_type]
+FROM [LOCOSOFT].[dbo].[orders]
 GO
 GO
 SET QUOTED_IDENTIFIER OFF 
 SET QUOTED_IDENTIFIER OFF 
 GO
 GO

+ 0 - 82
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_ben_AW_final.sql

@@ -1,82 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Aftersales_Rechnungen_ben_AW_final AS
-
-select c64 as "Invoice Type",
-	   c63 as "Invoice Number",
-	   c62 as "Subsidiary",
-	   c61 as "Invoice Date",
-	   c60 as "Service Date",
-	   c59 as "Is Canceled",
-	   c58 as "Vehicle Number",
-	   c57 as "Invoice_Type_Invoice_Number",
-	   '1' as "Hauptbetrieb",
-	   c56 as "Standort",
-	   c55 as "Serviceberater",
-	   c54 as "Umsatzart",
-	   c53 as "Fabrikat",
-	   c53 as "Description_Makes",
-	   c52 as "Description_Models",
-	   c51 as "Model",
-	   c50 as "Fahrzeug",
-	   c49 as "Kostenstelle",
-	   c48 as "Marke",
-	   'Service' as "Auftragsart",
-	   c47 as "Geschäftsart",
-	   c46 as "Kunde",
-	   c45 as "Time Units",
-	   c44 as "Time Units_Zahl",
-	   10 as "AW/Std.",
-	   c43 as "verk. Std._",
-	   c37 as "Order Number",
-	   c42 as "Order Number_Rg_Ausg",
-	   c41 as "Kundenart",
-	   c40 as "Summe Duration Minutes",
-	   c39 as "Order Number_ben_AW",
-	   1 as "Anzahl_Datensätze_1",
-	   COUNT(c39) OVER (partition by c37) as "Anzahl_Datensätze_2",
-	   (c38) / (COUNT(c39) OVER (partition by c37)) as "ben. Std."
-from 
-(select (CASE WHEN (T2."Serviceberater" IS NOT NULL) THEN ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + T2."Serviceberater" + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) ELSE ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) END) as c37,
-	   T9."Summe_Duration_Minutes" / 60 as c38,
-	   T9."order_number" as c39,
-	   T9."Summe_Duration_Minutes" as c40,
-	   (left(((convert(varchar(50), T8."employee_number"))))) + ' - ' + T8."name" as c41,
-	   CASE WHEN ((day((getdate()) - (convert(datetime, T1."invoice_date")))) <= 4) THEN ((CASE WHEN (T2."Serviceberater" IS NOT NULL) THEN ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + T2."Serviceberater" + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) ELSE ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) END)) ELSE null END as c42,
-	   ((convert(float, T7."time_units"))) / 10 as c43,
-	   (convert(float, T7."time_units")) as c44,
-	   T7."time_units" as c45,
-	   CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END as c46,
-	   T3."zip_code" as c47,
-	   CASE WHEN (T4."description" = 'Ford') THEN ('1') WHEN (T4."description" = 'Nissan') THEN ('3') WHEN (T4."description" = 'Suzuki') THEN ('2') ELSE ('9') END as c48,
-	   CASE WHEN ((left(((convert(varchar(50), T6."type"))))) IN ('1','6')) THEN ('41 - After Sales Kundendienst eigene Werkstatt') WHEN (T6."type" IN (40,41,44,45,46,47,48,49,88,89,50,90)) THEN ('41 - After Sales Kundendienst eigene Werkstatt') WHEN ((left(((convert(varchar(50), T6."type"))))) IN ('2')) THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung') WHEN (T6."type" IN (42,92)) THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung') WHEN ((left(((convert(varchar(50), T6."type"))))) IN ('3')) THEN ('45 - After Sales Kundendienst eigene Lackiererei') WHEN (T6."type" IN (43,93)) THEN ('45 - After Sales Kundendienst eigene Lackiererei') ELSE null END as c49,
-	   (left((left(((convert(varchar(50), T1."vehicle_number"))))) + ' - ' + T5."description",100)) as c50,
-	   (left((ucase(T5."description")),3)) as c51,
-	   T5."description" as c52,
-	   T4."description" as c53,
-	   CASE WHEN (T1."invoice_type" = 6) THEN ('GWL') WHEN ((T1."invoice_type" = 4) or (T3."customer_number" = 100001)) THEN ('intern') ELSE ('extern') END as c54,
-	   T2."Serviceberater" as c55,
-	   '0' + ((convert(varchar(50), T1."subsidiary"))) as c56,
-	   (left(((convert(varchar(50), T1."invoice_type"))))) + '_' + (left(((convert(varchar(50), T1."invoice_number"))))) as c57,
-	   T1."vehicle_number" as c58,
-	   T1."is_canceled" as c59,
-	   T1."service_date" as c60,
-	   T1."invoice_date" as c61,
-	   T1."subsidiary" as c62,
-	   T1."invoice_number" as c63,
-	   T1."invoice_type" as c64
-from "ims"."ben_AW_Order_Number" T9,
-	(((((((("dbo"."invoices" T1 left outer join "dbo"."customers_suppliers" T3 on T3."customer_number" = T1."paying_customer") left outer join "dbo"."vehicles" T10 on T1."vehicle_number" = T10."internal_number") left outer join "dbo"."makes" T4 on T10."make_number" = T4."make_number") left outer join "dbo"."models" T5 on (T10."make_number" = T5."make_number") and (T10."model_code" = T5."model_code")) left outer join "dbo"."labours" T7 on (T7."invoice_number" = T1."invoice_number") and (T7."invoice_type" = T1."invoice_type")) left outer join "dbo"."charge_type_descriptions" T6 on T6."type" = T7."charge_type") left outer join "dbo"."employees" T8 on T1."creating_employee" = T8."employee_number") left outer join "ims"."Serviceberater_Rechnung" T2 on T1."invtype_invnr" = T2."invtype_invnr")
-where (T7."order_number" = T9."order_number")
-and ((((T1."invoice_type" BETWEEN 2 AND 6) and (T1."is_canceled" <> 1)) and (T1."invoice_date" >= convert(date, '2017-01-01'))) and ((((convert(float, T7."time_units"))) <> 0) and (((convert(float, T7."time_units"))) IS NOT NULL)))
-) D1
--- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 268
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_neu.sql

@@ -1,268 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Aftersales_Rechnungen_neu AS
-
-select c253 as "Invoice Type",
-	   c252 as "Type_Invoice_Types",
-	   c251 as "Description_Invoice_Types",
-	   c250 as "Invoice Number",
-	   c249 as "Subsidiary",
-	   c248 as "Paying Customer",
-	   c247 as "Order Customer",
-	   c246 as "Invoice Date",
-	   c245 as "Service Date",
-	   c244 as "Is Canceled",
-	   c243 as "Cancelation Number",
-	   c242 as "Cancelation Date",
-	   c241 as "Cancelation Employee",
-	   c240 as "Is Own Vehicle",
-	   c239 as "Is Credit",
-	   c238 as "Credit Invoice Type",
-	   c237 as "Credit Invoice Number",
-	   c236 as "Odometer Reading",
-	   c235 as "Creating Employee",
-	   c234 as "Internal Cost Account",
-	   c233 as "Vehicle Number",
-	   c232 as "Full Vat Basevalue",
-	   c231 as "Full Vat Percentage",
-	   c230 as "Full Vat Value",
-	   c229 as "Reduced Vat Basevalue",
-	   c228 as "Reduced Vat Percentage",
-	   c227 as "Reduced Vat Value",
-	   c226 as "Used Part Vat Value",
-	   c225 as "Job Amount Net",
-	   c224 as "Job Amount Gross",
-	   c223 as "Job Rebate",
-	   c222 as "Part Amount Net",
-	   c221 as "Part Amount Gross",
-	   c220 as "Part Rebate",
-	   c219 as "Part Disposal",
-	   c218 as "Total Gross",
-	   c217 as "Total Net",
-	   c216 as "Inv_Type_Invoice_Number",
-	   c172 as "Accounting Date",
-	   c215 as "Document Type",
-	   c214 as "Document Number",
-	   c213 as "Position In Document",
-	   c212 as "Customer Number",
-	   c211 as "Nominal Account Number",
-	   c210 as "Is Balanced",
-	   c209 as "Clearing Number",
-	   c208 as "Document Date",
-	   c207 as "Posted Value",
-	   c206 as "Debit Or Credit",
-	   c205 as "Posted Count",
-	   c204 as "Branch Number",
-	   c203 as "Customer Contra Account",
-	   c202 as "Nominal Contra Account",
-	   c201 as "Contra Account Text",
-	   c200 as "Account Form Page Number",
-	   c199 as "Account Form Page Line",
-	   c198 as "Serial Number Each Month",
-	   c197 as "Employee Number",
-	   c196 as "Invoice Date_falsch",
-	   c195 as "Invoice Number",
-	   c194 as "Dunning Level",
-	   c193 as "Last Dunning Date",
-	   c192 as "Journal Page",
-	   c191 as "Journal Line",
-	   c190 as "Cash Discount",
-	   c189 as "Term Of Payment",
-	   c188 as "Posting Text",
-	   c187 as "Vehicle Reference",
-	   c186 as "Vat Id Number",
-	   c185 as "Account Statement Number",
-	   c184 as "Account Statement Page",
-	   c183 as "Vat Key",
-	   c182 as "Days For Cash Discount",
-	   c181 as "Day Of Actual Accounting",
-	   c180 as "Skr51 Branch",
-	   c158 as "Skr51 Make",
-	   c179 as "Skr51 Cost Center",
-	   c178 as "Skr51 Sales Channel",
-	   c177 as "Skr51 Cost Unit",
-	   c176 as "Previously Used Account No",
-	   c175 as "Free Form Accounting Text",
-	   c174 as "Free Form Document Text",
-	   '1' as "Hauptbetrieb",
-	   c173 as "Standort",
-	   c172 as "Invoice Date_accounting",
-	   c171 as "Employee Number_Employees",
-	   c170 as "Name_Employees",
-	   c169 as "Mechanic Number_Employees",
-	   c168 as "Salesman Number_Employees",
-	   c167 as "Is Business Executive_Employees",
-	   c166 as "Is Master Craftsman_Employees",
-	   c165 as "Serviceberater_Rg_Steller",
-	   c164 as "Customer Number_Customers_Suppliers",
-	   c163 as "First Name_Customers_Suppliers",
-	   c162 as "Family Name_Customers_Suppliers",
-	   c161 as "Kunde",
-	   c160 as "Betrag",
-	   c159 as "Kostenstelle",
-	   c158 as "Marke",
-	   c157 as "Kundenart",
-	   c156 as "KST_1_Stelle",
-	   c155 as "Umsatzart",
-	   c154 as "Auftragsart",
-	   '' as "Geschäftsart",
-	   c153 as "Make Number",
-	   c152 as "Free Form Make Text",
-	   c151 as "Model Code",
-	   c150 as "Free Form Model Text",
-	   c149 as "Description_Makes",
-	   c148 as "Description_Models",
-	   c149 as "Fabrikat",
-	   c148 as "Model_Detail",
-	   c147 as "Model",
-	   (0) as "Umsatz Lohn",
-	   (0) as "Umsatz FL",
-	   (0) as "Einsatz FL",
-	   (0) as "Umsatz Teile",
-	   (0) as "Einsatz Teile",
-	   (0) as "Umsatz MW",
-	   (0) as "Einsatz MW",
-	   (0) as "Umsatz Sonst.",
-	   (0) as "Einsatz Sonst.",
-	   1 as "DG_1",
-	   COUNT(c253) OVER (partition by c141) as "DG_2",
-	   1 / (COUNT(c253) OVER (partition by c141)) as "DG",
-	   c146 as "Fahrzeug",
-	   c141 as "Order Number",
-	   c145 as "Invoice_Date_Uhrzeit",
-	   c144 as "Order Number_Rg_Ausg",
-	   '' as "Konto Nr",
-	   '' as "Konto Bezeichnung",
-	   '' as "Ebene1",
-	   '' as "Ebene2",
-	   '' as "Ebene3",
-	   '' as "Ebene4",
-	   c143 as "Serviceberater_order_pos",
-	   c142 as "Serviceberater"
-from 
-(select (CASE WHEN ((CASE WHEN (T1."invoice_type" = 5) THEN (((left(((convert(varchar(50), T5."employee_number"))))) + ' - ' + T5."name")) ELSE (T10."Serviceberater") END) IS NOT NULL) THEN (((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number")))))) + ' - ' + (CASE WHEN (T1."invoice_type" = 5) THEN (((left(((convert(varchar(50), T5."employee_number"))))) + ' - ' + T5."name")) ELSE (T10."Serviceberater") END) + ' - ' + (CASE WHEN (T4."first_name" IS NULL) THEN ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."family_name") ELSE ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."first_name" + ' ' + T4."family_name") END)) ELSE (((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number")))))) + ' - ' + (CASE WHEN (T4."first_name" IS NULL) THEN ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."family_name") ELSE ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."first_name" + ' ' + T4."family_name") END)) END) as c141,
-	   CASE WHEN (T1."invoice_type" = 5) THEN (((left(((convert(varchar(50), T5."employee_number"))))) + ' - ' + T5."name")) ELSE (T10."Serviceberater") END as c142,
-	   T10."Serviceberater" as c143,
-	   CASE WHEN ((day((getdate()) - ((convert(datetime, T1."invoice_date"))))) <= 4) THEN ((CASE WHEN ((CASE WHEN (T1."invoice_type" = 5) THEN (((left(((convert(varchar(50), T5."employee_number"))))) + ' - ' + T5."name")) ELSE (T10."Serviceberater") END) IS NOT NULL) THEN (((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number")))))) + ' - ' + (CASE WHEN (T1."invoice_type" = 5) THEN (((left(((convert(varchar(50), T5."employee_number"))))) + ' - ' + T5."name")) ELSE (T10."Serviceberater") END) + ' - ' + (CASE WHEN (T4."first_name" IS NULL) THEN ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."family_name") ELSE ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."first_name" + ' ' + T4."family_name") END)) ELSE (((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number")))))) + ' - ' + (CASE WHEN (T4."first_name" IS NULL) THEN ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."family_name") ELSE ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."first_name" + ' ' + T4."family_name") END)) END)) ELSE null END as c144,
-	   (convert(datetime, T1."invoice_date")) as c145,
-	   (left((left(((convert(varchar(50), T1."vehicle_number"))))) + ' - ' + T9."description",100)) as c146,
-	   (left((ucase(T9."description")),3)) as c147,
-	   T9."description" as c148,
-	   T8."description" as c149,
-	   T7."free_form_model_text" as c150,
-	   T7."model_code" as c151,
-	   T7."free_form_make_text" as c152,
-	   T7."make_number" as c153,
-	   CASE WHEN (T1."invoice_type" = 5) THEN ('Teile') ELSE ('Service') END as c154,
-	   CASE WHEN (T1."invoice_type" = 6) THEN ('GWL') WHEN ((T1."invoice_type" = 4) or (T4."customer_number" IN (1000000,1000001,1000002,1000003,1000010))) THEN ('intern') ELSE ('extern') END as c155,
-	   (left(((rtrim(((convert(varchar(50), T3."skr51_cost_center"))))) + ' - ' + T6."skr51_cost_center_name"))) as c156,
-	   (rtrim(((convert(varchar(50), T3."skr51_sales_channel"))))) + ' - ' + T6."skr51_sales_channel_name" as c157,
-	   T3."skr51_make" as c158,
-	   (rtrim(((convert(varchar(50), T3."skr51_cost_center"))))) + ' - ' + T6."skr51_cost_center_name" as c159,
-	   CASE WHEN (T3."debit_or_credit" = 'H') THEN (((convert(float, T3."posted_value"))) / 100 * -1) ELSE (((convert(float, T3."posted_value"))) / 100) END as c160,
-	   CASE WHEN (T4."first_name" IS NULL) THEN ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."family_name") ELSE ((left(((convert(varchar(50), T4."customer_number"))))) + ' - ' + T4."first_name" + ' ' + T4."family_name") END as c161,
-	   T4."family_name" as c162,
-	   T4."first_name" as c163,
-	   T4."customer_number" as c164,
-	   (left(((convert(varchar(50), T5."employee_number"))))) + ' - ' + T5."name" as c165,
-	   T5."is_master_craftsman" as c166,
-	   T5."is_business_executive" as c167,
-	   T5."salesman_number" as c168,
-	   T5."mechanic_number" as c169,
-	   T5."name" as c170,
-	   T5."employee_number" as c171,
-	   T3."accounting_date" as c172,
-	   '0' + ((convert(varchar(50), T3."branch_number"))) as c173,
-	   CASE WHEN (T3."skr51_cost_unit" BETWEEN 1 AND 49) THEN ('Neuwagen') WHEN (T3."skr51_cost_unit" BETWEEN 50 AND 59) THEN ('Gebrauchtwagen') WHEN (T3."skr51_cost_unit" BETWEEN 60 AND 69) THEN ('Teile & Zubehör') WHEN (T3."skr51_cost_unit" BETWEEN 70 AND 79) THEN ('Service') WHEN (T3."skr51_cost_unit" = 0) THEN ('Ohne Kostenträger') ELSE null END as c174,
-	   T4."zip_code" as c175,
-	   T3."previously_used_account_no" as c176,
-	   T3."skr51_cost_unit" as c177,
-	   T3."skr51_sales_channel" as c178,
-	   T3."skr51_cost_center" as c179,
-	   T3."skr51_branch" as c180,
-	   T3."day_of_actual_accounting" as c181,
-	   T3."days_for_cash_discount" as c182,
-	   T3."vat_key" as c183,
-	   T3."account_statement_page" as c184,
-	   T3."account_statement_number" as c185,
-	   T3."vat_id_number" as c186,
-	   T3."vehicle_reference" as c187,
-	   T3."posting_text" as c188,
-	   T3."term_of_payment" as c189,
-	   T3."cash_discount" as c190,
-	   T3."journal_line" as c191,
-	   T3."journal_page" as c192,
-	   T3."last_dunning_date" as c193,
-	   T3."dunning_level" as c194,
-	   T3."invoice_number" as c195,
-	   T3."invoice_date" as c196,
-	   T3."employee_number" as c197,
-	   T3."serial_number_each_month" as c198,
-	   T3."account_form_page_line" as c199,
-	   T3."account_form_page_number" as c200,
-	   CASE WHEN (T3."nominal_account_number" = 5701) THEN ((rtrim(((convert(varchar(50), T3."nominal_account_number"))))) + '_' + (rtrim(((convert(varchar(50), T3."skr51_cost_center")))))) ELSE ((rtrim(((convert(varchar(50), T3."nominal_account_number")))))) END as c201,
-	   T3."nominal_contra_account" as c202,
-	   T3."customer_contra_account" as c203,
-	   T3."branch_number" as c204,
-	   T3."posted_count" as c205,
-	   T3."debit_or_credit" as c206,
-	   (convert(float, T3."posted_value")) as c207,
-	   T3."document_date" as c208,
-	   T3."clearing_number" as c209,
-	   T3."is_balanced" as c210,
-	   T3."nominal_account_number" as c211,
-	   T3."customer_number" as c212,
-	   T3."position_in_document" as c213,
-	   T3."document_number" as c214,
-	   T3."document_type" as c215,
-	   (left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) as c216,
-	   T1."total_net" as c217,
-	   T1."total_gross" as c218,
-	   T1."part_disposal" as c219,
-	   T1."part_rebate" as c220,
-	   T1."part_amount_gross" as c221,
-	   T1."part_amount_net" as c222,
-	   T1."job_rebate" as c223,
-	   T1."job_amount_gross" as c224,
-	   T1."job_amount_net" as c225,
-	   T1."used_part_vat_value" as c226,
-	   T1."reduced_vat_value" as c227,
-	   T1."reduced_vat_percentage" as c228,
-	   T1."reduced_vat_basevalue" as c229,
-	   T1."full_vat_value" as c230,
-	   T1."full_vat_percentage" as c231,
-	   T1."full_vat_basevalue" as c232,
-	   T1."vehicle_number" as c233,
-	   T1."internal_cost_account" as c234,
-	   T1."creating_employee" as c235,
-	   T1."odometer_reading" as c236,
-	   T1."credit_invoice_number" as c237,
-	   T1."credit_invoice_type" as c238,
-	   T1."is_credit" as c239,
-	   T1."is_own_vehicle" as c240,
-	   T1."cancelation_employee" as c241,
-	   T1."cancelation_date" as c242,
-	   T1."cancelation_number" as c243,
-	   T1."is_canceled" as c244,
-	   T1."service_date" as c245,
-	   T1."invoice_date" as c246,
-	   T1."order_customer" as c247,
-	   T1."paying_customer" as c248,
-	   T1."subsidiary" as c249,
-	   T1."invoice_number" as c250,
-	   T2."description" as c251,
-	   T2."type" as c252,
-	   T1."invoice_type" as c253
-from ((((((((("dbo"."invoices" T1 left outer join "dbo"."invoice_types" T2 on T2."type" = T1."invoice_type") left outer join "dbo"."journal_accountings" T3 on T3."invoice_number" = T1."invtype_invnr") left outer join "dbo"."customers_suppliers" T4 on T4."customer_number" = T1."paying_customer") left outer join "dbo"."employees" T5 on T1."creating_employee" = T5."employee_number") left outer join "dbo"."accounts_characteristics" T6 on (((((T6."skr51_branch" = T3."skr51_branch") and (T6."skr51_make" = T3."skr51_make")) and (T6."skr51_cost_center" = T3."skr51_cost_center")) and (T6."skr51_sales_channel" = T3."skr51_sales_channel")) and (T6."skr51_cost_unit" = T3."skr51_cost_unit")) and (T6."subsidiary_to_company_ref" = T3."subsidiary_to_company_ref")) left outer join "dbo"."vehicles" T7 on T1."vehicle_number" = T7."internal_number") left outer join "dbo"."makes" T8 on T7."make_number" = T8."make_number") left outer join "dbo"."models" T9 on (T7."make_number" = T9."make_number") and (T7."model_code" = T9."model_code")) left outer join "ims"."Serviceberater_Rechnung" T10 on T1."invtype_invnr" = T10."invtype_invnr")
-where (((((T1."invoice_type" BETWEEN 2 AND 6) and ((left(((convert(varchar(50), T3."nominal_account_number"))))) IN ('4','5','7','8'))) and (T1."invoice_date" >= convert(date, '2019-01-01'))) and (T1."is_canceled" <> 1)) and (((len((rtrim(((convert(varchar(50), T3."nominal_account_number"))))) + 'Z') - 1)) = 4))
--- order by c141 asc,c214 asc,c213 asc,c216 asc
-) D1
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 45
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_verk_AW_final.sql

@@ -1,45 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Aftersales_Rechnungen_verk_AW_final AS
-
-select T1."invoice_type" as "Invoice Type",
-	   T1."invoice_number" as "Invoice Number",
-	   T1."subsidiary" as "Subsidiary",
-	   T1."invoice_date" as "Invoice Date",
-	   T1."service_date" as "Service Date",
-	   T1."is_canceled" as "Is Canceled",
-	   T1."vehicle_number" as "Vehicle Number",
-	   (left(((convert(varchar(50), T1."invoice_type"))))) + '_' + (left(((convert(varchar(50), T1."invoice_number"))))) as "Invoice_Type_Invoice_Number",
-	   '1' as "Hauptbetrieb",
-	   '0' + ((convert(varchar(50), T1."subsidiary"))) as "Standort",
-	   T2."Serviceberater" as "Serviceberater",
-	   CASE WHEN (T1."invoice_type" = 6) THEN ('GWL') WHEN ((T1."invoice_type" = 4) or (T3."customer_number" = 100001)) THEN ('intern') ELSE ('extern') END as "Umsatzart",
-	   T4."description" as "Fabrikat",
-	   T4."description" as "Description_Makes",
-	   T5."description" as "Description_Models",
-	   (left((ucase(T5."description")),3)) as "Model",
-	   (left((left(((convert(varchar(50), T1."vehicle_number"))))) + ' - ' + T5."description",100)) as "Fahrzeug",
-	   CASE WHEN ((left(((convert(varchar(50), T6."type"))))) IN ('1','6')) THEN ('41 - After Sales Kundendienst eigene Werkstatt') WHEN (T6."type" IN (40,41,44,45,46,47,48,49,88,89,50,90)) THEN ('41 - After Sales Kundendienst eigene Werkstatt') WHEN ((left(((convert(varchar(50), T6."type"))))) IN ('2')) THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung') WHEN (T6."type" IN (42,92)) THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung') WHEN ((left(((convert(varchar(50), T6."type"))))) IN ('3')) THEN ('45 - After Sales Kundendienst eigene Lackiererei') WHEN (T6."type" IN (43,93)) THEN ('45 - After Sales Kundendienst eigene Lackiererei') ELSE null END as "Kostenstelle",
-	   CASE WHEN (T4."description" = 'Ford') THEN ('1') WHEN (T4."description" = 'Nissan') THEN ('3') WHEN (T4."description" = 'Suzuki') THEN ('2') ELSE ('9') END as "Marke",
-	   'Service' as "Auftragsart",
-	   T3."zip_code" as "Geschäftsart",
-	   CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END as "Kunde",
-	   T7."time_units" as "Time Units",
-	   (convert(float, T7."time_units")) as "Time Units_Zahl",
-	   10 as "AW/Std.",
-	   ((convert(float, T7."time_units"))) / 10 as "verk. Std.",
-	   CASE WHEN (T2."Serviceberater" IS NOT NULL) THEN ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + T2."Serviceberater" + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) ELSE ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) END as "Order Number",
-	   CASE WHEN ((day((getdate()) - (convert(datetime, T1."invoice_date")))) <= 4) THEN ((CASE WHEN (T2."Serviceberater" IS NOT NULL) THEN ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + T2."Serviceberater" + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) ELSE ((left(((convert(varchar(50), T1."invoice_type"))))) + (left(((convert(varchar(50), T1."invoice_number"))))) + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") END)) END)) ELSE null END as "Order Number_Rg_Ausg",
-	   (left(((convert(varchar(50), T8."employee_number"))))) + ' - ' + T8."name" as "Kundenart"
-from (((((((("dbo"."invoices" T1 left outer join "dbo"."customers_suppliers" T3 on T3."customer_number" = T1."paying_customer") left outer join "dbo"."vehicles" T9 on T1."vehicle_number" = T9."internal_number") left outer join "dbo"."makes" T4 on T9."make_number" = T4."make_number") left outer join "dbo"."models" T5 on (T9."make_number" = T5."make_number") and (T9."model_code" = T5."model_code")) left outer join "dbo"."labours" T7 on (T7."invoice_number" = T1."invoice_number") and (T7."invoice_type" = T1."invoice_type")) left outer join "dbo"."charge_type_descriptions" T6 on T6."type" = T7."charge_type") left outer join "dbo"."employees" T8 on T1."creating_employee" = T8."employee_number") left outer join "ims"."Serviceberater_Rechnung" T2 on T1."invtype_invnr" = T2."invtype_invnr")
-where (((((T1."invoice_type" BETWEEN 2 AND 6) and (T1."is_canceled" <> 1)) and (T1."invoice_date" >= convert(date, '2017-01-01'))) and ((((convert(float, T7."time_units"))) <> 0) and (((convert(float, T7."time_units"))) IS NOT NULL))) and (T7."mechanic_no" IS NOT NULL))
--- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 20
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Imvoice_No_Order_No.sql

@@ -1,20 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Imvoice_No_Order_No AS
-
-select distinct T1."order_number" as "Order Number",
-	   T1."invoice_number" as "Invoice Number_ohne_type",
-	   T2."invoice_type" as "Invoice Type",
-	   (substring((convert(varchar(50), T2."invoice_type")), 1, 1)) + (substring((convert(varchar(50), T1."invoice_number")), 1, 6)) as "Invoice Number"
-from ("dbo"."invoices" T2 left outer join "dbo"."labours" T1 on (T1."invoice_number" = T2."invoice_number") and (T1."invoice_type" = T2."invoice_type"))
-where (((substring((convert(varchar(50), T2."invoice_type")), 1, 1)) + (substring((convert(varchar(50), T1."invoice_number")), 1, 6))) <> '')
-order by "Order Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 125
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kontenrahmen.sql

@@ -1,125 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Kontenrahmen AS
-
-select T1."KONTO_NR" as "Konto Nr",
-	   T1."KONTO_BEZEICHNUNG" as "Konto Bezeichnung",
-	   T1."KONTO_ART" as "Konto Art_ori",
-	   T1."KOSTENSTELLE" as "Kostenstelle",
-	   T1."STK" as "Stk",
-	   T1."KONTO_1" as "Konto 1",
-	   T1."KONTO_2" as "Konto 2",
-	   T1."KONTO_3" as "Konto 3",
-	   T1."KONTO_4" as "Konto 4",
-	   T1."KONTO_5" as "Konto 5",
-	   T1."EBENE1" as "Ebene1",
-	   T1."EBENE2" as "Ebene2",
-	   T1."EBENE3" as "Ebene3",
-	   T1."EBENE4" as "Ebene4",
-	   T1."EBENE5" as "Ebene5",
-	   T1."EBENE6" as "Ebene6",
-	   T1."EBENE7" as "Ebene7",
-	   T1."EBENE8" as "Ebene8",
-	   T1."EBENE9" as "Ebene9",
-	   T1."EBENE10" as "Ebene10",
-	   T1."EBENE11" as "Ebene11",
-	   T1."EBENE12" as "Ebene12",
-	   T1."EBENE13" as "Ebene13",
-	   T1."EBENE14" as "Ebene14",
-	   T1."EBENE15" as "Ebene15",
-	   T1."EBENE16" as "Ebene16",
-	   T1."EBENE17" as "Ebene17",
-	   T1."EBENE18" as "Ebene18",
-	   T1."EBENE19" as "Ebene19",
-	   T1."EBENE20" as "Ebene20",
-	   T1."EBENE21" as "Ebene21",
-	   T1."EBENE22" as "Ebene22",
-	   T1."EBENE23" as "Ebene23",
-	   T1."EBENE24" as "Ebene24",
-	   T1."EBENE25" as "Ebene25",
-	   T1."EBENE26" as "Ebene26",
-	   T1."EBENE27" as "Ebene27",
-	   T1."EBENE28" as "Ebene28",
-	   T1."EBENE29" as "Ebene29",
-	   T1."EBENE30" as "Ebene30",
-	   T1."EBENE31" as "Ebene31",
-	   T1."EBENE32" as "Ebene32",
-	   T1."EBENE33" as "Ebene33",
-	   T1."EBENE34" as "Ebene34",
-	   T1."EBENE35" as "Ebene35",
-	   T1."EBENE36" as "Ebene36",
-	   T1."EBENE37" as "Ebene37",
-	   T1."EBENE38" as "Ebene38",
-	   T1."EBENE39" as "Ebene39",
-	   T1."EBENE40" as "Ebene40",
-	   T1."EBENE41" as "Ebene41",
-	   T1."EBENE42" as "Ebene42",
-	   T1."EBENE43" as "Ebene43",
-	   T1."EBENE44" as "Ebene44",
-	   T1."EBENE45" as "Ebene45",
-	   T1."EBENE46" as "Ebene46",
-	   T1."EBENE47" as "Ebene47",
-	   T1."EBENE48" as "Ebene48",
-	   T1."EBENE49" as "Ebene49",
-	   T1."EBENE50" as "Ebene50",
-	   T1."EBENE51" as "Ebene51",
-	   T1."EBENE52" as "Ebene52",
-	   T1."EBENE53" as "Ebene53",
-	   T1."EBENE54" as "Ebene54",
-	   T1."EBENE55" as "Ebene55",
-	   T1."EBENE56" as "Ebene56",
-	   T1."EBENE57" as "Ebene57",
-	   T1."EBENE58" as "Ebene58",
-	   T1."EBENE59" as "Ebene59",
-	   T1."EBENE60" as "Ebene60",
-	   T1."EBENE61" as "Ebene61",
-	   T1."EBENE62" as "Ebene62",
-	   T1."EBENE63" as "Ebene63",
-	   T1."EBENE64" as "Ebene64",
-	   T1."EBENE65" as "Ebene65",
-	   T1."EBENE66" as "Ebene66",
-	   T1."EBENE67" as "Ebene67",
-	   T1."EBENE68" as "Ebene68",
-	   T1."EBENE69" as "Ebene69",
-	   T1."EBENE70" as "Ebene70",
-	   T1."EBENE71" as "Ebene71",
-	   T1."EBENE72" as "Ebene72",
-	   T1."EBENE73" as "Ebene73",
-	   T1."EBENE74" as "Ebene74",
-	   T1."EBENE75" as "Ebene75",
-	   T1."EBENE76" as "Ebene76",
-	   T1."EBENE77" as "Ebene77",
-	   T1."EBENE78" as "Ebene78",
-	   T1."EBENE79" as "Ebene79",
-	   T1."EBENE80" as "Ebene80",
-	   T1."EBENE81" as "Ebene81",
-	   T1."EBENE82" as "Ebene82",
-	   T1."EBENE83" as "Ebene83",
-	   T1."EBENE84" as "Ebene84",
-	   T1."EBENE85" as "Ebene85",
-	   T1."EBENE86" as "Ebene86",
-	   T1."EBENE87" as "Ebene87",
-	   T1."EBENE88" as "Ebene88",
-	   T1."EBENE89" as "Ebene89",
-	   T1."EBENE90" as "Ebene90",
-	   (len(T1."KONTO_NR" + 'Z') - 1) as "Anzahl Stellen_Konto_Nr",
-	   T1."KONTO_ART" as "Konto Art",
-	   T1."KONTO_ART" as "GuV_Bilanz",
-	   T1."KONTO_NR" as "Acct Nr",
-	   T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" as "Konto",
-	   (left(T1."KONTO_NR",1)) as "Susa"
-from OPENROWSET(
-    BULK 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv',
-	FORMATFILE = 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv.xml',
-	FIRSTROW = 2
-) T1
-where (((left(T1."KONTO_NR",1))) <> '9')
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 117
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kreditorenbewegungen.sql


+ 0 - 419
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.LOC_Belege_NW_GW_VK.sql

@@ -1,419 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.LOC_Belege_NW_GW_VK AS
-
-select "Accounting Date" as "Accounting Date",
-	   "Document Type" as "Document Type",
-	   "Document Number" as "Document Number",
-	   "Position In Document" as "Position In Document",
-	   (day((convert(datetime, (CASE WHEN ((MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet")) IS NULL) THEN ("Invoice Date_journal_accountings") ELSE ((MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet"))) END))) - c142)) as "Customer Number",
-	   "Nominal Account Number" as "Nominal Account Number",
-	   "Is Balanced" as "Is Balanced",
-	   "Clearing Number" as "Clearing Number",
-	   "Document Date" as "Document Date",
-	   "Posted Value" as "Posted Value",
-	   "Debit Or Credit" as "Debit Or Credit",
-	   "Posted Count" as "Posted Count",
-	   "Branch Number" as "Branch Number",
-	   "Customer Contra Account" as "Customer Contra Account",
-	   "Nominal Contra Account" as "Nominal Contra Account",
-	   "Contra Account Text" as "Contra Account Text",
-	   "Account Form Page Number" as "Account Form Page Number",
-	   "Account Form Page Line" as "Account Form Page Line",
-	   "Serial Number Each Month" as "Serial Number Each Month",
-	   "Employee Number" as "Employee Number",
-	   "Invoice Date_journal_accountings" as "Invoice Date_journal_accountings",
-	   "Invoice Number" as "Invoice Number",
-	   "Dunning Level" as "Dunning Level",
-	   "Last Dunning Date" as "Last Dunning Date",
-	   "Journal Page" as "Journal Page",
-	   "Journal Line" as "Journal Line",
-	   "Cash Discount" as "Cash Discount",
-	   "Term Of Payment" as "Term Of Payment",
-	   "Posting Text" as "Posting Text",
-	   "Vehicle Reference" as "Vehicle Reference",
-	   "Vat Id Number" as "Vat Id Number",
-	   "Account Statement Number" as "Account Statement Number",
-	   "Account Statement Page" as "Account Statement Page",
-	   "Vat Key" as "Vat Key",
-	   "Days For Cash Discount" as "Days For Cash Discount",
-	   "Day Of Actual Accounting" as "Day Of Actual Accounting",
-	   "Skr51 Branch" as "Skr51 Branch",
-	   "Skr51 Make" as "Skr51 Make",
-	   "Skr51 Cost Center" as "Skr51 Cost Center",
-	   "Skr51 Sales Channel" as "Skr51 Sales Channel",
-	   "Skr51 Cost Unit" as "Skr51 Cost Unit",
-	   "Previously Used Account No" as "Previously Used Account No",
-	   "Free Form Accounting Text" as "Free Form Accounting Text",
-	   "Free Form Document Text" as "Free Form Document Text",
-	   "Nom_Account_Is Profit Loss Account" as "Nom_Account_Is Profit Loss Account",
-	   "Rechtseinheit" as "Rechtseinheit",
-	   "Betrieb" as "Betrieb",
-	   "Bookkeep Date" as "Bookkeep Date",
-	   "Marke" as "Marke",
-	   "Text" as "Text",
-	   "Mandant" as "Mandant",
-	   "Betrag" as "Betrag",
-	   "Konto_mit_Bezeichnung" as "Konto_mit_Bezeichnung",
-	   "Menge" as "Menge",
-	   "Stellen Cost Center" as "Stellen Cost Center",
-	   "KST" as "KST",
-	   "Stellen Sales Channel" as "Stellen Sales Channel",
-	   "Absatzkanal" as "Absatzkanal",
-	   "Stellen Cost Unit" as "Stellen Cost Unit",
-	   "Kostenträger_mit_Null" as "Kostenträger_mit_Null",
-	   "Kostenträger" as "Kostenträger",
-	   "GuV_Bilanz" as "GuV_Bilanz",
-	   "Susa" as "Susa",
-	   "Acct Nr" as "Acct Nr",
-	   "Document Type In Journal" as "Document Type In Journal",
-	   "Document Type Description" as "Document Type Description",
-	   "FZG_ja_nein" as "FZG_ja_nein",
-	   SUM("FZG_ja_nein") OVER (partition by "Vehicle Reference_berechnet") as "Summe_FZG_ja_nein",
-	   CASE WHEN (SUM("FZG_ja_nein") OVER (partition by "Vehicle Reference_berechnet") > 0) THEN ('FZG-Geschäft') ELSE ('Buchungen ohne FZG-Geschäft') END as "FZG_Geschäft ja/nein",
-	   "Invoice Type_Invoices" as "Invoice Type_Invoices",
-	   "Invoice Number_Invoices" as "Invoice Number_Invoices",
-	   "Invoice Date_Invoices" as "Invoice Date_Invoices",
-	   "Is Canceled_Invoices" as "Is Canceled_Invoices",
-	   "Vehicle Number_Invoices" as "Vehicle Number_Invoices",
-	   MAX("Vehicle Number_Invoices") OVER (partition by "Vehicle Reference_berechnet") as "Vehicle_Number_Max",
-	   "Invoice_Date_1" as "Invoice_Date_1",
-	   MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet") as "Invoice Date_FZG",
-	   CASE WHEN (MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet") IS NULL) THEN ("Invoice Date_journal_accountings") ELSE MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet") END as "Invoice Date",
-	   SUM("Betrag") OVER (partition by "Vehicle Reference_berechnet") as "Summe Betrag",
-	   "Internal Number_Vehicles" as "Internal Number_Vehicles",
-	   "Vin_Vehicles" as "Vin_Vehicles",
-	   "Dealer Vehicle Type" as "Dealer Vehicle Type",
-	   "Fahrzeugtyp" as "Fahrzeugtyp",
-	   "Fahrzeugart" as "Fahrzeugart",
-	   "Make Number_Vehicles" as "Make Number_Vehicles",
-	   "Description_Make" as "Description_Make",
-	   "Fabrikat" as "Fabrikat",
-	   "Model Code_Models" as "Model Code_Models",
-	   "Model_Detail" as "Model_Detail",
-	   "Model" as "Model",
-	   "Owner Number_Vehicles" as "Owner Number_Vehicles",
-	   "Holder Number_Vehicles" as "Holder Number_Vehicles",
-	   "First Name_Owner_Customer" as "First Name_Owner_Customer",
-	   "Family Name_Owner_Customer" as "Family Name_Owner_Customer",
-	   "First Name_Holder_Customer" as "First Name_Holder_Customer",
-	   "Family Name_Holder_Customer" as "Family Name_Holder_Customer",
-	   "Kunde" as "Kunde",
-	   "Sales_Channel_FZG" as "Sales_Channel_FZG",
-	   MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") as "Kundenart_Zahl",
-	   CASE WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 10 AND 19) THEN ('Privater Endkunde') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 20 AND 29) THEN ('Gewerbekunde') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 30 AND 39) THEN ('Großkunde') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 40 AND 49) THEN ('Sonderabnehmer') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 50 AND 59) THEN ('Wiederverkäufer') ELSE null END as "Kundenart",
-	   "Hauptbetrieb" as "Hauptbetrieb",
-	   "Standort_alt" as "Standort_alt",
-	   "Salesman Number_Vehicles" as "Salesman Number_Vehicles",
-	   "Employee Number_Employees_Salesman" as "Employee Number_Employees_Salesman",
-	   "Name_Employees_Salesman" as "Name_Employees_Salesman",
-	   "Verkäufer" as "Verkäufer",
-	   "Standort_FZG_Verkauf" as "Standort_FZG_Verkauf",
-	   MAX("Standort_FZG_Verkauf") OVER (partition by "Vehicle Reference_berechnet") as "Standort_Zahl",
-	   "Standort" as "Standort",
-	   "FZG" as "FZG",
-	   "Konto" as "Konto",
-	   "Body Paint Code" as "Body Paint Code",
-	   "Body Paint Description" as "Body Paint Description",
-	   "Farbe" as "Farbe",
-	   "Erlös FZG" as "Erlös FZG",
-	   "Nachlass" as "Nachlass",
-	   "VAK FZG" as "VAK FZG",
-	   "Erlös Zulass." as "Erlös Zulass.",
-	   "VAK Zulass." as "VAK Zulass.",
-	   "Erlös Gar." as "Erlös Gar.",
-	   "VAK Gar." as "VAK Gar.",
-	   "Erlös Nachr./Aufb." as "Erlös Nachr./Aufb.",
-	   "VAK Nachr./Aufb." as "VAK Nachr./Aufb.",
-	   "VAK Fertigm." as "VAK Fertigm.",
-	   "Erlös Überf." as "Erlös Überf.",
-	   "VAK Überf." as "VAK Überf.",
-	   "Erlös Sonst._8900" as "Erlös Sonst._8900",
-	   "Erlös Sonst." as "Erlös Sonst.",
-	   "VAK Sonst." as "VAK Sonst.",
-	   "VAK intern" as "VAK intern",
-	   "Erlös Prov." as "Erlös Prov.",
-	   "Boni/VK-Hilfen" as "Boni/VK-Hilfen",
-	   "Erlös ges." as "Erlös ges.",
-	   "VAK ges." as "VAK ges.",
-	   "Menge_1" as "Menge_1",
-	   COUNT("Accounting Date") OVER (partition by "Vehicle Reference_berechnet") as "Menge_2",
-	   ("Menge_1" / COUNT("Accounting Date") OVER (partition by "Vehicle Reference_berechnet")) as "Menge",
-	   "Vehicle Reference_berechnet" as "Vehicle Reference_berechnet",
-	   "var. Kosten" as "var. Kosten",
-	   "Dealer Vehicle Type_Vehicles" as "Dealer Vehicle Type_Vehicles",
-	   "Dealer Vehicle Number_Vehicles" as "Dealer Vehicle Number_Vehicles"
-from 
-(select c230 as "Accounting Date",
-	   c271 as "Document Type",
-	   c270 as "Document Number",
-	   c269 as "Position In Document",
-	   c216 as "Nominal Account Number",
-	   c268 as "Is Balanced",
-	   c267 as "Clearing Number",
-	   c266 as "Document Date",
-	   c265 as "Posted Value",
-	   c264 as "Debit Or Credit",
-	   c263 as "Posted Count",
-	   c262 as "Branch Number",
-	   c261 as "Customer Contra Account",
-	   c260 as "Nominal Contra Account",
-	   c259 as "Contra Account Text",
-	   c258 as "Account Form Page Number",
-	   c257 as "Account Form Page Line",
-	   c256 as "Serial Number Each Month",
-	   c255 as "Employee Number",
-	   c151 as "Invoice Date_journal_accountings",
-	   c254 as "Invoice Number",
-	   c253 as "Dunning Level",
-	   c252 as "Last Dunning Date",
-	   c251 as "Journal Page",
-	   c250 as "Journal Line",
-	   c249 as "Cash Discount",
-	   c248 as "Term Of Payment",
-	   c247 as "Posting Text",
-	   c246 as "Vehicle Reference",
-	   c245 as "Vat Id Number",
-	   c244 as "Account Statement Number",
-	   c243 as "Account Statement Page",
-	   c242 as "Vat Key",
-	   c241 as "Days For Cash Discount",
-	   c240 as "Day Of Actual Accounting",
-	   c239 as "Skr51 Branch",
-	   c238 as "Skr51 Make",
-	   c237 as "Skr51 Cost Center",
-	   c236 as "Skr51 Sales Channel",
-	   c235 as "Skr51 Cost Unit",
-	   c234 as "Previously Used Account No",
-	   c233 as "Free Form Accounting Text",
-	   c232 as "Free Form Document Text",
-	   c231 as "Nom_Account_Is Profit Loss Account",
-	   c187 as "Rechtseinheit",
-	   c186 as "Betrieb",
-	   c230 as "Bookkeep Date",
-	   c229 as "Marke",
-	   c228 as "Text",
-	   '1' as "Mandant",
-	   c227 as "Betrag",
-	   c178 as "Konto_mit_Bezeichnung",
-	   c226 as "Menge",
-	   c225 as "Stellen Cost Center",
-	   c224 as "KST",
-	   c223 as "Stellen Sales Channel",
-	   c222 as "Absatzkanal",
-	   c221 as "Stellen Cost Unit",
-	   c220 as "Kostenträger_mit_Null",
-	   c219 as "Kostenträger",
-	   c218 as "GuV_Bilanz",
-	   c217 as "Susa",
-	   c216 as "Acct Nr",
-	   c215 as "Document Type In Journal",
-	   c214 as "Document Type Description",
-	   c213 as "FZG_ja_nein",
-	   c212 as "Invoice Type_Invoices",
-	   c211 as "Invoice Number_Invoices",
-	   c210 as "Invoice Date_Invoices",
-	   c209 as "Is Canceled_Invoices",
-	   c208 as "Vehicle Number_Invoices",
-	   c207 as "Invoice_Date_1",
-	   c206 as "Internal Number_Vehicles",
-	   c205 as "Vin_Vehicles",
-	   c204 as "Dealer Vehicle Type",
-	   c203 as "Fahrzeugtyp",
-	   c202 as "Fahrzeugart",
-	   c201 as "Make Number_Vehicles",
-	   c200 as "Description_Make",
-	   c199 as "Fabrikat",
-	   c198 as "Model Code_Models",
-	   c197 as "Model_Detail",
-	   c196 as "Model",
-	   c195 as "Owner Number_Vehicles",
-	   c194 as "Holder Number_Vehicles",
-	   c193 as "First Name_Owner_Customer",
-	   c192 as "Family Name_Owner_Customer",
-	   c191 as "First Name_Holder_Customer",
-	   c190 as "Family Name_Holder_Customer",
-	   c189 as "Kunde",
-	   c188 as "Sales_Channel_FZG",
-	   c187 as "Hauptbetrieb",
-	   c186 as "Standort_alt",
-	   c185 as "Salesman Number_Vehicles",
-	   c184 as "Employee Number_Employees_Salesman",
-	   c183 as "Name_Employees_Salesman",
-	   c182 as "Verkäufer",
-	   c181 as "Standort_FZG_Verkauf",
-	   c180 as "Standort",
-	   c179 as "FZG",
-	   c178 as "Konto",
-	   c177 as "Body Paint Code",
-	   c176 as "Body Paint Description",
-	   c176 as "Farbe",
-	   c175 as "Erlös FZG",
-	   c174 as "Nachlass",
-	   c173 as "VAK FZG",
-	   c172 as "Erlös Zulass.",
-	   c171 as "VAK Zulass.",
-	   c170 as "Erlös Gar.",
-	   c169 as "VAK Gar.",
-	   c168 as "Erlös Nachr./Aufb.",
-	   c167 as "VAK Nachr./Aufb.",
-	   c166 as "VAK Fertigm.",
-	   c165 as "Erlös Überf.",
-	   c164 as "VAK Überf.",
-	   c163 as "Erlös Sonst._8900",
-	   c162 as "Erlös Sonst.",
-	   c161 as "VAK Sonst.",
-	   c160 as "VAK intern",
-	   c159 as "Erlös Prov.",
-	   c158 as "Boni/VK-Hilfen",
-	   c157 as "Erlös ges.",
-	   c156 as "VAK ges.",
-	   1 as "Menge_1",
-	   c150 as "Vehicle Reference_berechnet",
-	   c155 as "var. Kosten",
-	   c154 as "Dealer Vehicle Type_Vehicles",
-	   c153 as "Dealer Vehicle Number_Vehicles",
-	   c152 as c142,
-	   MAX(c208) OVER (partition by c150) as c143,
-	   (CASE WHEN ((MAX(c207) OVER (partition by c150)) IS NULL) THEN ((c151)) ELSE ((MAX(c207) OVER (partition by c150))) END) as c144,
-	   (CASE WHEN ((SUM(c213) OVER (partition by c150)) > 0) THEN ('FZG-Geschäft') ELSE ('Buchungen ohne FZG-Geschäft') END) as c145
-from 
-(select (left(T1."vehicle_reference",7)) + '_' + (od_right(T1."vehicle_reference",17)) as c150,
-	   (cdate((nconvert((left(T1."invoice_date",4)) + (substring(T1."invoice_date", 6, 2)) + (substring(T1."invoice_date", 9, 2)))))) as c151,
-	   T2."in_buy_invoice_no_date" as c152,
-	   T8."dealer_vehicle_number" as c153,
-	   T8."dealer_vehicle_type" as c154,
-	   CASE WHEN (T1."nominal_account_number" IN (4300,4560,4580,4530,4540,4590,4591,4690,4621,4622,4623,4500,4501,4502,4503,4504,5501)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c155,
-	   (CASE WHEN (T1."nominal_account_number" IN (7000,7010,7100,7101,7110,7111,7120,7510)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + ((CASE WHEN (T1."nominal_account_number" IN (7200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7240)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END)) + (CASE WHEN (T1."nominal_account_number" IN (5001,5005,5006,5007,5008,5003,5004)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7800,7850)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) as c156,
-	   (CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8111,8112,8510,8928,8934)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + ((CASE WHEN (T1."nominal_account_number" IN (8200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8900)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END)) + (CASE WHEN (T1."nominal_account_number" IN (8800,8801,8870,8820,8830)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8001,8011,5002)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) as c157,
-	   CASE WHEN (T1."nominal_account_number" IN (7800,7850)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c158,
-	   CASE WHEN (T1."nominal_account_number" IN (8800,8801,8870,8820,8830)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c159,
-	   CASE WHEN (T1."nominal_account_number" IN (5001,5005,5006,5007,5008,5003,5004)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c160,
-	   (CASE WHEN (T1."nominal_account_number" IN (7200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7240)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) as c161,
-	   (CASE WHEN (T1."nominal_account_number" IN (8200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8900)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) as c162,
-	   CASE WHEN (T1."nominal_account_number" IN (8900)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c163,
-	   CASE WHEN (T1."nominal_account_number" IN (7030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c164,
-	   CASE WHEN (T1."nominal_account_number" IN (8030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c165,
-	   CASE WHEN (T1."nominal_account_number" IN (7240)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c166,
-	   CASE WHEN (T1."nominal_account_number" IN (7220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c167,
-	   CASE WHEN (T1."nominal_account_number" IN (8220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c168,
-	   CASE WHEN (T1."nominal_account_number" IN (7210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c169,
-	   CASE WHEN (T1."nominal_account_number" IN (8210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c170,
-	   CASE WHEN (T1."nominal_account_number" IN (7200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c171,
-	   CASE WHEN (T1."nominal_account_number" IN (8200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c172,
-	   CASE WHEN (T1."nominal_account_number" IN (7000,7010,7100,7101,7110,7111,7120,7510)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c173,
-	   CASE WHEN (T1."nominal_account_number" IN (8001,8011,5002)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c174,
-	   CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8111,8112,8510,8928,8934)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c175,
-	   T8."body_paint_description" as c176,
-	   T8."body_paint_code" as c177,
-	   ((left(((convert(varchar(50), T1."nominal_account_number"))))) + ' - ' + T4."account_description") as c178,
-	   (left(((left(T1."vehicle_reference",7)) + '_' + (od_right(T1."vehicle_reference",17))),7)) + ' / ' + ((left(((convert(varchar(50), T8."internal_number")))))) + ' - ' + T10."description" + ' - ' + (((left(((convert(varchar(50), T8."holder_number"))))) + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ('') ELSE (T3."first_name") END) + ' ' + T3."family_name")) as c179,
-	   CASE WHEN (T2."out_subsidiary" IS NULL) THEN ((('0' + ((convert(varchar(50), T1."skr51_branch")))))) ELSE ('0' + ((convert(varchar(50), T2."out_subsidiary")))) END as c180,
-	   T2."out_subsidiary" as c181,
-	   (left(((convert(varchar(50), T8."salesman_number"))))) + ' - ' + T12."name" as c182,
-	   T12."name" as c183,
-	   T12."employee_number" as c184,
-	   T8."salesman_number" as c185,
-	   ('0' + ((convert(varchar(50), T1."skr51_branch")))) as c186,
-	   T1."subsidiary_to_company_ref" as c187,
-	   CASE WHEN (((CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END) = 1) and (T7."is_canceled" <> '1')) THEN (T1."skr51_sales_channel") ELSE null END as c188,
-	   ((left(((convert(varchar(50), T8."holder_number"))))) + ' - ' + (CASE WHEN (T3."first_name" IS NULL) THEN ('') ELSE (T3."first_name") END) + ' ' + T3."family_name") as c189,
-	   T3."family_name" as c190,
-	   CASE WHEN (T3."first_name" IS NULL) THEN ('') ELSE (T3."first_name") END as c191,
-	   T11."family_name" as c192,
-	   T11."first_name" as c193,
-	   T8."holder_number" as c194,
-	   T8."owner_number" as c195,
-	   (left((ucase(T10."description")),3)) as c196,
-	   T10."description" as c197,
-	   T10."model_code" as c198,
-	   CASE WHEN (((rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + T5."skr51_make_description") = '3 - Husqvarna') THEN ('Husqvarna') ELSE (T9."description") END as c199,
-	   T9."description" as c200,
-	   T8."make_number" as c201,
-	   CASE WHEN ((CASE WHEN (((left(T1."vehicle_reference",1))) IN ('N')) THEN ('NW') WHEN (((left(T1."vehicle_reference",1))) IN ('V')) THEN ('VFW') WHEN (((left(T1."vehicle_reference",1))) IN ('G','D')) THEN ('GW') WHEN (((left(T1."vehicle_reference",1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c202,
-	   CASE WHEN (((left(T1."vehicle_reference",1))) IN ('N')) THEN ('NW') WHEN (((left(T1."vehicle_reference",1))) IN ('V')) THEN ('VFW') WHEN (((left(T1."vehicle_reference",1))) IN ('G','D')) THEN ('GW') WHEN (((left(T1."vehicle_reference",1))) IN ('T')) THEN ('TZ') ELSE null END as c203,
-	   (left(T1."vehicle_reference",1)) as c204,
-	   T8."vin" as c205,
-	   T8."internal_number" as c206,
-	   CASE WHEN ((CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END) = 1) THEN (((cdate((nconvert((left(T1."invoice_date",4)) + (substring(T1."invoice_date", 6, 2)) + (substring(T1."invoice_date", 9, 2)))))))) ELSE null END as c207,
-	   T7."vehicle_number" as c208,
-	   T7."is_canceled" as c209,
-	   T7."invoice_date" as c210,
-	   T7."invoice_number" as c211,
-	   T7."invoice_type" as c212,
-	   CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END as c213,
-	   T6."document_type_description" as c214,
-	   T6."document_type_in_journal" as c215,
-	   T1."nominal_account_number" as c216,
-	   (left(((convert(varchar(50), T1."nominal_account_number"))))) as c217,
-	   CASE WHEN (T4."is_profit_loss_account" = 'J') THEN ('2') ELSE ('1') END as c218,
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN (((rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T5."skr51_cost_unit_name"))) ELSE ((rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T5."skr51_cost_unit_name")) END as c219,
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T5."skr51_cost_unit_name") as c220,
-	   (len(((convert(varchar(50), T1."skr51_cost_unit"))) + 'Z') - 1) as c221,
-	   (rtrim(((convert(varchar(50), T1."skr51_sales_channel"))))) + ' - ' + T5."skr51_sales_channel_name" as c222,
-	   (len(((convert(varchar(50), T1."skr51_sales_channel"))) + 'Z') - 1) as c223,
-	   (rtrim(((convert(varchar(50), T1."skr51_cost_center"))))) + ' - ' + T5."skr51_cost_center_name" as c224,
-	   (len(((convert(varchar(50), T1."skr51_cost_center"))) + 'Z') - 1) as c225,
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_count" / 100 * -1) ELSE (T1."posted_count" / 100) END as c226,
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END as c227,
-	   CASE WHEN ((day((getdate()) - (convert(datetime, T1."accounting_date")))) <= 360) THEN (T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + (rtrim(((convert(varchar(50), T1."employee_number")))))) ELSE ('Buchungen älter 360 Tage') END as c228,
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + T5."skr51_make_description" as c229,
-	   T1."accounting_date" as c230,
-	   T4."is_profit_loss_account" as c231,
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN ('Neuwagen') WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59) THEN ('Gebrauchtwagen') WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69) THEN ('Teile & Zubehör') WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79) THEN ('Service') WHEN (T1."skr51_cost_unit" = 0) THEN ('Ohne Kostenträger') ELSE null END as c232,
-	   T3."zip_code" as c233,
-	   T1."previously_used_account_no" as c234,
-	   T1."skr51_cost_unit" as c235,
-	   T1."skr51_sales_channel" as c236,
-	   T1."skr51_cost_center" as c237,
-	   T1."skr51_make" as c238,
-	   T1."skr51_branch" as c239,
-	   T1."day_of_actual_accounting" as c240,
-	   T1."days_for_cash_discount" as c241,
-	   T1."vat_key" as c242,
-	   T1."account_statement_page" as c243,
-	   T1."account_statement_number" as c244,
-	   T1."vat_id_number" as c245,
-	   T1."vehicle_reference" as c246,
-	   T1."posting_text" as c247,
-	   T1."term_of_payment" as c248,
-	   T1."cash_discount" as c249,
-	   T1."journal_line" as c250,
-	   T1."journal_page" as c251,
-	   T1."last_dunning_date" as c252,
-	   T1."dunning_level" as c253,
-	   T1."invoice_number" as c254,
-	   T1."employee_number" as c255,
-	   T1."serial_number_each_month" as c256,
-	   T1."account_form_page_line" as c257,
-	   T1."account_form_page_number" as c258,
-	   T1."contra_account_text" as c259,
-	   T1."nominal_contra_account" as c260,
-	   T1."customer_contra_account" as c261,
-	   T1."branch_number" as c262,
-	   T1."posted_count" as c263,
-	   T1."debit_or_credit" as c264,
-	   T1."posted_value" as c265,
-	   T1."document_date" as c266,
-	   T1."clearing_number" as c267,
-	   T1."is_balanced" as c268,
-	   T1."position_in_document" as c269,
-	   T1."document_number" as c270,
-	   T1."document_type" as c271
-from "nominal_accounts" T4,
-	(((((((((("journal_accountings" T1 left outer join "vehicles" T8 on (od_right(T1."vehicle_reference",17)) = T8."vin") left outer join "LOCOSOFT"."dbo"."dealer_vehicles" T2 on (T8."dealer_vehicle_type" = T2."dealer_vehicle_type") and (T8."dealer_vehicle_number" = T2."dealer_vehicle_number")) left outer join "customers_suppliers" T3 on T3."customer_number" = T8."holder_number") left outer join "accounts_characteristics" T5 on (((((T5."skr51_make" = T1."skr51_make") and (T5."skr51_cost_center" = T1."skr51_cost_center")) and (T5."skr51_sales_channel" = T1."skr51_sales_channel")) and (T5."skr51_cost_unit" = T1."skr51_cost_unit")) and (T5."skr51_branch" = T1."skr51_branch")) and (T5."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")) left outer join "document_types" T6 on T6."document_type_in_journal" = T1."document_type") left outer join "invoices" T7 on T7."invtype_invnr" = T1."invoice_number") left outer join "makes" T9 on T8."make_number" = T9."make_number") left outer join "models" T10 on (T8."make_number" = T10."make_number") and (T8."model_code" = T10."model_code")) left outer join "customers_suppliers" T11 on T11."customer_number" = T8."owner_number") left outer join "employees" T12 on (T8."salesman_number" <> 0) and (T8."salesman_number" = T12."salesman_number"))
-where ((T4."nominal_account_number" = T1."nominal_account_number") and (T4."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref"))
-and (((T4."is_profit_loss_account" = 'J') and (T1."vehicle_reference" <> ' ')) and (T1."nominal_account_number" IN (8000,8001,8010,8011,5002,8100,8110,8111,8200,8210,8510,8800,8820,8830,8870,8928,8934,7000,7010,7100,7101,7110,7111,7120,7200,7210,7240,7510,5001,5005,5006,5007,5008,5003,5004,4300,4560,4580,4530,4540,4590,4591,4690,4621,4622,4623,4500,4501,4502,4503,4504,5501,7220,7800,7850,7801,7802,7803,7804,7805,7806,7807,7820,7825,7827,7808,8030,7030,8870,8871,8872,8220,7220)))
-) D2
-) D1
-where (((((c143 = "Internal Number_Vehicles") or ("Internal Number_Vehicles" IS NULL)) or (c143 IS NULL)) and (c144 >= convert(date, '2017-01-01'))) and (c145 = 'FZG-Geschäft'))
--- order by "Vehicle Reference_berechnet" asc,"Vehicle Reference" asc,"Nominal Account Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 558
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.LOC_Belege_NW_GW_VK_Stk_FIBU.sql

@@ -1,558 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.LOC_Belege_NW_GW_VK_Stk_FIBU AS
-
-select "Accounting Date" as "Accounting Date",
-	   "Document Type" as "Document Type",
-	   "Document Number" as "Document Number",
-	   "Position In Document" as "Position In Document",
-	   "Customer Number" as "Customer Number",
-	   "Nominal Account Number" as "Nominal Account Number",
-	   "Is Balanced" as "Is Balanced",
-	   "Clearing Number" as "Clearing Number",
-	   "Document Date" as "Document Date",
-	   "Posted Value" as "Posted Value",
-	   "Debit Or Credit" as "Debit Or Credit",
-	   "Posted Count" as "Posted Count",
-	   "Branch Number" as "Branch Number",
-	   "Customer Contra Account" as "Customer Contra Account",
-	   "Nominal Contra Account" as "Nominal Contra Account",
-	   "Contra Account Text" as "Contra Account Text",
-	   "Account Form Page Number" as "Account Form Page Number",
-	   "Account Form Page Line" as "Account Form Page Line",
-	   "Serial Number Each Month" as "Serial Number Each Month",
-	   "Employee Number" as "Employee Number",
-	   "Invoice Date_journal_accountings" as "Invoice Date_journal_accountings",
-	   "Invoice Number" as "Invoice Number",
-	   "Dunning Level" as "Dunning Level",
-	   "Last Dunning Date" as "Last Dunning Date",
-	   "Journal Page" as "Journal Page",
-	   "Journal Line" as "Journal Line",
-	   "Cash Discount" as "Cash Discount",
-	   "Term Of Payment" as "Term Of Payment",
-	   "Posting Text" as "Posting Text",
-	   "Vehicle Reference" as "Vehicle Reference",
-	   "Vat Id Number" as "Vat Id Number",
-	   "Account Statement Number" as "Account Statement Number",
-	   "Account Statement Page" as "Account Statement Page",
-	   "Vat Key" as "Vat Key",
-	   "Days For Cash Discount" as "Days For Cash Discount",
-	   "Day Of Actual Accounting" as "Day Of Actual Accounting",
-	   "Skr51 Branch" as "Skr51 Branch",
-	   "Skr51 Make" as "Skr51 Make",
-	   "Skr51 Cost Center" as "Skr51 Cost Center",
-	   "Skr51 Sales Channel" as "Skr51 Sales Channel",
-	   "Skr51 Cost Unit" as "Skr51 Cost Unit",
-	   "Previously Used Account No" as "Previously Used Account No",
-	   "Free Form Accounting Text" as "Free Form Accounting Text",
-	   "Free Form Document Text" as "Free Form Document Text",
-	   "Nom_Account_Is Profit Loss Account" as "Nom_Account_Is Profit Loss Account",
-	   "Rechtseinheit" as "Rechtseinheit",
-	   "Betrieb" as "Betrieb",
-	   "Bookkeep Date" as "Bookkeep Date",
-	   "Marke" as "Marke",
-	   "Text" as "Text",
-	   "Mandant" as "Mandant",
-	   "Betrag_ori" as "Betrag_ori",
-	   "Konto_mit_Bezeichnung" as "Konto_mit_Bezeichnung",
-	   "Menge" as "Menge",
-	   "Stellen Cost Center" as "Stellen Cost Center",
-	   "KST" as "KST",
-	   "Stellen Sales Channel" as "Stellen Sales Channel",
-	   "Absatzkanal" as "Absatzkanal",
-	   "Stellen Cost Unit" as "Stellen Cost Unit",
-	   "Kostenträger_mit_Null" as "Kostenträger_mit_Null",
-	   "Kostenträger" as "Kostenträger",
-	   "GuV_Bilanz" as "GuV_Bilanz",
-	   "Susa" as "Susa",
-	   "Acct Nr_ori" as "Acct Nr_ori",
-	   "Document Type In Journal" as "Document Type In Journal",
-	   "Document Type Description" as "Document Type Description",
-	   "FZG_ja_nein" as "FZG_ja_nein",
-	   "Summe_FZG_ja_nein" as "Summe_FZG_ja_nein",
-	   "FZG_Geschäft ja/nein" as "FZG_Geschäft ja/nein",
-	   "Invoice Type_Invoices" as "Invoice Type_Invoices",
-	   "Invoice Number_Invoices" as "Invoice Number_Invoices",
-	   "Invoice Date_Invoices" as "Invoice Date_Invoices",
-	   "Is Canceled_Invoices" as "Is Canceled_Invoices",
-	   "Vehicle Number_Invoices" as "Vehicle Number_Invoices",
-	   "Vehicle_Number_Max" as "Vehicle_Number_Max",
-	   "Invoice_Date_1" as "Invoice_Date_1",
-	   "Invoice Date_FZG" as "Invoice Date_FZG",
-	   "Invoice Date" as "Invoice Date",
-	   SUM("Betrag_ori") OVER (partition by "Vehicle Reference") as "Summe Betrag",
-	   "Internal Number_Vehicles" as "Internal Number_Vehicles",
-	   "Vin_Vehicles" as "Vin_Vehicles",
-	   "Dealer Vehicle Type" as "Dealer Vehicle Type",
-	   "Fahrzeugtyp" as "Fahrzeugtyp",
-	   "Fahrzeugart" as "Fahrzeugart",
-	   "Make Number_Vehicles" as "Make Number_Vehicles",
-	   "Description_Make" as "Description_Make",
-	   "Fabrikat" as "Fabrikat",
-	   "Model Code_Models" as "Model Code_Models",
-	   "Model_Detail" as "Model_Detail",
-	   "Model" as "Model",
-	   "Owner Number_Vehicles" as "Owner Number_Vehicles",
-	   "Holder Number_Vehicles" as "Holder Number_Vehicles",
-	   "First Name_Owner_Customer" as "First Name_Owner_Customer",
-	   "Family Name_Owner_Customer" as "Family Name_Owner_Customer",
-	   "First Name_Holder_Customer" as "First Name_Holder_Customer",
-	   "Family Name_Holder_Customer" as "Family Name_Holder_Customer",
-	   "Kunde" as "Kunde",
-	   "Sales_Channel_FZG" as "Sales_Channel_FZG",
-	   "Kundenart_Zahl" as "Kundenart_Zahl",
-	   "Kundenart" as "Kundenart",
-	   "Hauptbetrieb" as "Hauptbetrieb",
-	   "Standort_alt" as "Standort_alt",
-	   "Salesman Number_Vehicles" as "Salesman Number_Vehicles",
-	   "Employee Number_Employees_Salesman" as "Employee Number_Employees_Salesman",
-	   "Name_Employees_Salesman" as "Name_Employees_Salesman",
-	   "Verkäufer" as "Verkäufer",
-	   "Standort_FZG_Verkauf" as "Standort_FZG_Verkauf",
-	   "Standort_Zahl" as "Standort_Zahl",
-	   "Standort" as "Standort",
-	   "FZG" as "FZG",
-	   "Konto" as "Konto",
-	   "Body Paint Code" as "Body Paint Code",
-	   "Body Paint Description" as "Body Paint Description",
-	   "Farbe" as "Farbe",
-	   "Erlös FZG" as "Erlös FZG",
-	   "Nachlass" as "Nachlass",
-	   "VAK FZG" as "VAK FZG",
-	   "Erlös Zulass." as "Erlös Zulass.",
-	   "VAK Zulass." as "VAK Zulass.",
-	   "Erlös Gar." as "Erlös Gar.",
-	   "VAK Gar." as "VAK Gar.",
-	   "Erlös Nachr./Aufb." as "Erlös Nachr./Aufb.",
-	   "VAK Nachr./Aufb." as "VAK Nachr./Aufb.",
-	   "VAK Fertigm." as "VAK Fertigm.",
-	   "Erlös Überf." as "Erlös Überf.",
-	   "VAK Überf." as "VAK Überf.",
-	   "Erlös Sonst._8900" as "Erlös Sonst._8900",
-	   "Erlös Sonst." as "Erlös Sonst.",
-	   "VAK Sonst." as "VAK Sonst.",
-	   "VAK intern" as "VAK intern",
-	   "Erlös Prov." as "Erlös Prov.",
-	   "Boni/VK-Hilfen" as "Boni/VK-Hilfen",
-	   "Erlös ges." as "Erlös ges.",
-	   "VAK ges." as "VAK ges.",
-	   "Menge_1" as "Menge_1",
-	   "Menge_2" as "Menge_2",
-	   "Betrag" as "Betrag",
-	   "Vehicle Reference_berechnet" as "Vehicle Reference_berechnet",
-	   "Acct Nr" as "Acct Nr",
-	   "Dealer Vehicle Type_Vehicles" as "Dealer Vehicle Type_Vehicles",
-	   "Dealer Vehicle Number_Vehicles" as "Dealer Vehicle Number_Vehicles"
-from 
-(select "Accounting Date" as "Accounting Date",
-	   "Document Type" as "Document Type",
-	   "Document Number" as "Document Number",
-	   "Position In Document" as "Position In Document",
-	   "Customer Number" as "Customer Number",
-	   "Nominal Account Number" as "Nominal Account Number",
-	   "Is Balanced" as "Is Balanced",
-	   "Clearing Number" as "Clearing Number",
-	   "Document Date" as "Document Date",
-	   "Posted Value" as "Posted Value",
-	   "Debit Or Credit" as "Debit Or Credit",
-	   "Posted Count" as "Posted Count",
-	   "Branch Number" as "Branch Number",
-	   "Customer Contra Account" as "Customer Contra Account",
-	   "Nominal Contra Account" as "Nominal Contra Account",
-	   "Contra Account Text" as "Contra Account Text",
-	   "Account Form Page Number" as "Account Form Page Number",
-	   "Account Form Page Line" as "Account Form Page Line",
-	   "Serial Number Each Month" as "Serial Number Each Month",
-	   "Employee Number" as "Employee Number",
-	   "Invoice Date_journal_accountings" as "Invoice Date_journal_accountings",
-	   "Invoice Number" as "Invoice Number",
-	   "Dunning Level" as "Dunning Level",
-	   "Last Dunning Date" as "Last Dunning Date",
-	   "Journal Page" as "Journal Page",
-	   "Journal Line" as "Journal Line",
-	   "Cash Discount" as "Cash Discount",
-	   "Term Of Payment" as "Term Of Payment",
-	   "Posting Text" as "Posting Text",
-	   "Vehicle Reference" as "Vehicle Reference",
-	   "Vat Id Number" as "Vat Id Number",
-	   "Account Statement Number" as "Account Statement Number",
-	   "Account Statement Page" as "Account Statement Page",
-	   "Vat Key" as "Vat Key",
-	   "Days For Cash Discount" as "Days For Cash Discount",
-	   "Day Of Actual Accounting" as "Day Of Actual Accounting",
-	   "Skr51 Branch" as "Skr51 Branch",
-	   "Skr51 Make" as "Skr51 Make",
-	   "Skr51 Cost Center" as "Skr51 Cost Center",
-	   "Skr51 Sales Channel" as "Skr51 Sales Channel",
-	   "Skr51 Cost Unit" as "Skr51 Cost Unit",
-	   "Previously Used Account No" as "Previously Used Account No",
-	   "Free Form Accounting Text" as "Free Form Accounting Text",
-	   "Free Form Document Text" as "Free Form Document Text",
-	   "Nom_Account_Is Profit Loss Account" as "Nom_Account_Is Profit Loss Account",
-	   "Rechtseinheit" as "Rechtseinheit",
-	   "Betrieb" as "Betrieb",
-	   "Bookkeep Date" as "Bookkeep Date",
-	   "Marke" as "Marke",
-	   "Text" as "Text",
-	   "Mandant" as "Mandant",
-	   "Betrag_ori" as "Betrag_ori",
-	   "Konto_mit_Bezeichnung" as "Konto_mit_Bezeichnung",
-	   "Menge" as "Menge",
-	   "Stellen Cost Center" as "Stellen Cost Center",
-	   "KST" as "KST",
-	   "Stellen Sales Channel" as "Stellen Sales Channel",
-	   "Absatzkanal" as "Absatzkanal",
-	   "Stellen Cost Unit" as "Stellen Cost Unit",
-	   "Kostenträger_mit_Null" as "Kostenträger_mit_Null",
-	   "Kostenträger" as "Kostenträger",
-	   "GuV_Bilanz" as "GuV_Bilanz",
-	   "Susa" as "Susa",
-	   "Acct Nr_ori" as "Acct Nr_ori",
-	   "Document Type In Journal" as "Document Type In Journal",
-	   "Document Type Description" as "Document Type Description",
-	   "FZG_ja_nein" as "FZG_ja_nein",
-	   SUM("FZG_ja_nein") OVER (partition by "Vehicle Reference_berechnet") as "Summe_FZG_ja_nein",
-	   CASE WHEN (SUM("FZG_ja_nein") OVER (partition by "Vehicle Reference_berechnet") > 0) THEN ('FZG-Geschäft') ELSE ('Buchungen ohne FZG-Geschäft') END as "FZG_Geschäft ja/nein",
-	   "Invoice Type_Invoices" as "Invoice Type_Invoices",
-	   "Invoice Number_Invoices" as "Invoice Number_Invoices",
-	   "Invoice Date_Invoices" as "Invoice Date_Invoices",
-	   "Is Canceled_Invoices" as "Is Canceled_Invoices",
-	   "Vehicle Number_Invoices" as "Vehicle Number_Invoices",
-	   MAX("Vehicle Number_Invoices") OVER (partition by "Vehicle Reference_berechnet") as "Vehicle_Number_Max",
-	   "Invoice_Date_1" as "Invoice_Date_1",
-	   MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet") as "Invoice Date_FZG",
-	   CASE WHEN (MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet") IS NULL) THEN ("Invoice Date_journal_accountings") ELSE MAX("Invoice_Date_1") OVER (partition by "Vehicle Reference_berechnet") END as "Invoice Date",
-	   "Internal Number_Vehicles" as "Internal Number_Vehicles",
-	   "Vin_Vehicles" as "Vin_Vehicles",
-	   "Dealer Vehicle Type" as "Dealer Vehicle Type",
-	   "Fahrzeugtyp" as "Fahrzeugtyp",
-	   "Fahrzeugart" as "Fahrzeugart",
-	   "Make Number_Vehicles" as "Make Number_Vehicles",
-	   "Description_Make" as "Description_Make",
-	   "Fabrikat" as "Fabrikat",
-	   "Model Code_Models" as "Model Code_Models",
-	   "Model_Detail" as "Model_Detail",
-	   "Model" as "Model",
-	   "Owner Number_Vehicles" as "Owner Number_Vehicles",
-	   "Holder Number_Vehicles" as "Holder Number_Vehicles",
-	   "First Name_Owner_Customer" as "First Name_Owner_Customer",
-	   "Family Name_Owner_Customer" as "Family Name_Owner_Customer",
-	   "First Name_Holder_Customer" as "First Name_Holder_Customer",
-	   "Family Name_Holder_Customer" as "Family Name_Holder_Customer",
-	   "Kunde" as "Kunde",
-	   "Sales_Channel_FZG" as "Sales_Channel_FZG",
-	   MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") as "Kundenart_Zahl",
-	   CASE WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 10 AND 19) THEN ('Privater Endkunde') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 20 AND 29) THEN ('Gewerbekunde') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 30 AND 39) THEN ('Großkunde') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 40 AND 49) THEN ('Sonderabnehmer') WHEN (MAX("Sales_Channel_FZG") OVER (partition by "Vehicle Reference_berechnet") BETWEEN 50 AND 59) THEN ('Wiederverkäufer') ELSE null END as "Kundenart",
-	   "Hauptbetrieb" as "Hauptbetrieb",
-	   "Standort_alt" as "Standort_alt",
-	   "Salesman Number_Vehicles" as "Salesman Number_Vehicles",
-	   "Employee Number_Employees_Salesman" as "Employee Number_Employees_Salesman",
-	   "Name_Employees_Salesman" as "Name_Employees_Salesman",
-	   "Verkäufer" as "Verkäufer",
-	   "Standort_FZG_Verkauf" as "Standort_FZG_Verkauf",
-	   MAX("Standort_FZG_Verkauf") OVER (partition by "Vehicle Reference_berechnet") as "Standort_Zahl",
-	   '0' + (convert(varchar(50), MAX("Standort_FZG_Verkauf") OVER (partition by "Vehicle Reference_berechnet"))) as "Standort",
-	   "FZG" as "FZG",
-	   "Konto" as "Konto",
-	   "Body Paint Code" as "Body Paint Code",
-	   "Body Paint Description" as "Body Paint Description",
-	   "Farbe" as "Farbe",
-	   "Erlös FZG" as "Erlös FZG",
-	   "Nachlass" as "Nachlass",
-	   "VAK FZG" as "VAK FZG",
-	   "Erlös Zulass." as "Erlös Zulass.",
-	   "VAK Zulass." as "VAK Zulass.",
-	   "Erlös Gar." as "Erlös Gar.",
-	   "VAK Gar." as "VAK Gar.",
-	   "Erlös Nachr./Aufb." as "Erlös Nachr./Aufb.",
-	   "VAK Nachr./Aufb." as "VAK Nachr./Aufb.",
-	   "VAK Fertigm." as "VAK Fertigm.",
-	   "Erlös Überf." as "Erlös Überf.",
-	   "VAK Überf." as "VAK Überf.",
-	   "Erlös Sonst._8900" as "Erlös Sonst._8900",
-	   "Erlös Sonst." as "Erlös Sonst.",
-	   "VAK Sonst." as "VAK Sonst.",
-	   "VAK intern" as "VAK intern",
-	   "Erlös Prov." as "Erlös Prov.",
-	   "Boni/VK-Hilfen" as "Boni/VK-Hilfen",
-	   "Erlös ges." as "Erlös ges.",
-	   "VAK ges." as "VAK ges.",
-	   "Menge_1" as "Menge_1",
-	   COUNT("Accounting Date") OVER (partition by "Vehicle Reference_berechnet") as "Menge_2",
-	   ("Menge_1" / COUNT("Accounting Date") OVER (partition by "Vehicle Reference_berechnet")) as "Betrag",
-	   "Vehicle Reference_berechnet" as "Vehicle Reference_berechnet",
-	   "Acct Nr" as "Acct Nr",
-	   "Dealer Vehicle Type_Vehicles" as "Dealer Vehicle Type_Vehicles",
-	   "Dealer Vehicle Number_Vehicles" as "Dealer Vehicle Number_Vehicles"
-from 
-(select c225 as "Accounting Date",
-	   c268 as "Document Type",
-	   c267 as "Document Number",
-	   c266 as "Position In Document",
-	   c265 as "Customer Number",
-	   c264 as "Nominal Account Number",
-	   c263 as "Is Balanced",
-	   c262 as "Clearing Number",
-	   c261 as "Document Date",
-	   c260 as "Posted Value",
-	   c259 as "Debit Or Credit",
-	   c258 as "Posted Count",
-	   c257 as "Branch Number",
-	   c256 as "Customer Contra Account",
-	   c255 as "Nominal Contra Account",
-	   c254 as "Contra Account Text",
-	   c253 as "Account Form Page Number",
-	   c252 as "Account Form Page Line",
-	   c251 as "Serial Number Each Month",
-	   c250 as "Employee Number",
-	   c150 as "Invoice Date_journal_accountings",
-	   c249 as "Invoice Number",
-	   c248 as "Dunning Level",
-	   c247 as "Last Dunning Date",
-	   c246 as "Journal Page",
-	   c245 as "Journal Line",
-	   c244 as "Cash Discount",
-	   c243 as "Term Of Payment",
-	   c242 as "Posting Text",
-	   c241 as "Vehicle Reference",
-	   c240 as "Vat Id Number",
-	   c239 as "Account Statement Number",
-	   c238 as "Account Statement Page",
-	   c237 as "Vat Key",
-	   c236 as "Days For Cash Discount",
-	   c235 as "Day Of Actual Accounting",
-	   c234 as "Skr51 Branch",
-	   c233 as "Skr51 Make",
-	   c232 as "Skr51 Cost Center",
-	   c231 as "Skr51 Sales Channel",
-	   c230 as "Skr51 Cost Unit",
-	   c229 as "Previously Used Account No",
-	   c228 as "Free Form Accounting Text",
-	   c227 as "Free Form Document Text",
-	   c226 as "Nom_Account_Is Profit Loss Account",
-	   c184 as "Rechtseinheit",
-	   c183 as "Betrieb",
-	   c225 as "Bookkeep Date",
-	   c224 as "Marke",
-	   c223 as "Text",
-	   '1' as "Mandant",
-	   c222 as "Betrag_ori",
-	   c176 as "Konto_mit_Bezeichnung",
-	   c221 as "Menge",
-	   c220 as "Stellen Cost Center",
-	   c219 as "KST",
-	   c218 as "Stellen Sales Channel",
-	   c217 as "Absatzkanal",
-	   c216 as "Stellen Cost Unit",
-	   c215 as "Kostenträger_mit_Null",
-	   c214 as "Kostenträger",
-	   c213 as "GuV_Bilanz",
-	   '3' as "Susa",
-	   c212 as "Acct Nr_ori",
-	   c211 as "Document Type In Journal",
-	   c210 as "Document Type Description",
-	   c209 as "FZG_ja_nein",
-	   c208 as "Invoice Type_Invoices",
-	   c207 as "Invoice Number_Invoices",
-	   c206 as "Invoice Date_Invoices",
-	   c205 as "Is Canceled_Invoices",
-	   c204 as "Vehicle Number_Invoices",
-	   c203 as "Invoice_Date_1",
-	   c202 as "Internal Number_Vehicles",
-	   c201 as "Vin_Vehicles",
-	   c200 as "Dealer Vehicle Type",
-	   c199 as "Fahrzeugtyp",
-	   c198 as "Fahrzeugart",
-	   c197 as "Make Number_Vehicles",
-	   c196 as "Description_Make",
-	   c196 as "Fabrikat",
-	   c195 as "Model Code_Models",
-	   c194 as "Model_Detail",
-	   c193 as "Model",
-	   c192 as "Owner Number_Vehicles",
-	   c191 as "Holder Number_Vehicles",
-	   c190 as "First Name_Owner_Customer",
-	   c189 as "Family Name_Owner_Customer",
-	   c188 as "First Name_Holder_Customer",
-	   c187 as "Family Name_Holder_Customer",
-	   c186 as "Kunde",
-	   c185 as "Sales_Channel_FZG",
-	   c184 as "Hauptbetrieb",
-	   c183 as "Standort_alt",
-	   c182 as "Salesman Number_Vehicles",
-	   c181 as "Employee Number_Employees_Salesman",
-	   c180 as "Name_Employees_Salesman",
-	   c179 as "Verkäufer",
-	   c178 as "Standort_FZG_Verkauf",
-	   c177 as "FZG",
-	   c176 as "Konto",
-	   c175 as "Body Paint Code",
-	   c174 as "Body Paint Description",
-	   c174 as "Farbe",
-	   c173 as "Erlös FZG",
-	   c172 as "Nachlass",
-	   c171 as "VAK FZG",
-	   c170 as "Erlös Zulass.",
-	   c169 as "VAK Zulass.",
-	   c168 as "Erlös Gar.",
-	   c167 as "VAK Gar.",
-	   c166 as "Erlös Nachr./Aufb.",
-	   c165 as "VAK Nachr./Aufb.",
-	   c164 as "VAK Fertigm.",
-	   c163 as "Erlös Überf.",
-	   c162 as "VAK Überf.",
-	   c161 as "Erlös Sonst._8900",
-	   c160 as "Erlös Sonst.",
-	   c159 as "VAK Sonst.",
-	   c158 as "VAK intern",
-	   c157 as "Erlös Prov.",
-	   c156 as "Boni/VK-Hilfen",
-	   c155 as "Erlös ges.",
-	   c154 as "VAK ges.",
-	   1 as "Menge_1",
-	   c149 as "Vehicle Reference_berechnet",
-	   c153 as "Acct Nr",
-	   c152 as "Dealer Vehicle Type_Vehicles",
-	   c151 as "Dealer Vehicle Number_Vehicles",
-	   MAX(c204) OVER (partition by c149) as c142,
-	   (CASE WHEN ((MAX(c203) OVER (partition by c149)) IS NULL) THEN ((c150)) ELSE ((MAX(c203) OVER (partition by c149))) END) as c143,
-	   (CASE WHEN ((SUM(c209) OVER (partition by c149)) > 0) THEN ('FZG-Geschäft') ELSE ('Buchungen ohne FZG-Geschäft') END) as c144
-from 
-(select (left(T1."vehicle_reference",8)) + '_' + (od_right(T1."vehicle_reference",17)) as c149,
-	   (cdate((nconvert((left(T1."invoice_date",4)) + (substring(T1."invoice_date", 6, 2)) + (substring(T1."invoice_date", 9, 2)))))) as c150,
-	   T6."dealer_vehicle_number" as c151,
-	   T6."dealer_vehicle_type" as c152,
-	   (ltrim(((left(((convert(varchar(50), T1."nominal_account_number"))))) + '_STK'))) as c153,
-	   (CASE WHEN (T1."nominal_account_number" IN (7000,7010,7100,7101,7110,7111,7120,7510)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + ((CASE WHEN (T1."nominal_account_number" IN (7200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7240)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END)) + (CASE WHEN (T1."nominal_account_number" IN (5001,5005,5006,5007,5008,5003,5004)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7800,7850)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) as c154,
-	   (CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8111,8112,8510,8928,8934)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + ((CASE WHEN (T1."nominal_account_number" IN (8200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8900)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END)) + (CASE WHEN (T1."nominal_account_number" IN (8800,8801,8870,8820,8830)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8001,8011,5002)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) as c155,
-	   CASE WHEN (T1."nominal_account_number" IN (7800,7850)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c156,
-	   CASE WHEN (T1."nominal_account_number" IN (8800,8801,8870,8820,8830)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c157,
-	   CASE WHEN (T1."nominal_account_number" IN (5001,5005,5006,5007,5008,5003,5004)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c158,
-	   (CASE WHEN (T1."nominal_account_number" IN (7200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7240)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (7030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END) as c159,
-	   (CASE WHEN (T1."nominal_account_number" IN (8200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) + (CASE WHEN (T1."nominal_account_number" IN (8900)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END) as c160,
-	   CASE WHEN (T1."nominal_account_number" IN (8900)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c161,
-	   CASE WHEN (T1."nominal_account_number" IN (7030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c162,
-	   CASE WHEN (T1."nominal_account_number" IN (8030)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c163,
-	   CASE WHEN (T1."nominal_account_number" IN (7240)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c164,
-	   CASE WHEN (T1."nominal_account_number" IN (7220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c165,
-	   CASE WHEN (T1."nominal_account_number" IN (8220)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c166,
-	   CASE WHEN (T1."nominal_account_number" IN (7210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c167,
-	   CASE WHEN (T1."nominal_account_number" IN (8210)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c168,
-	   CASE WHEN (T1."nominal_account_number" IN (7200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c169,
-	   CASE WHEN (T1."nominal_account_number" IN (8200)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c170,
-	   CASE WHEN (T1."nominal_account_number" IN (7000,7010,7100,7101,7110,7111,7120,7510)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END)) ELSE (0) END as c171,
-	   CASE WHEN (T1."nominal_account_number" IN (8001,8011,5002)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c172,
-	   CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8111,8112,8510,8928,8934)) THEN ((CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) * -1) ELSE (0) END as c173,
-	   T6."body_paint_description" as c174,
-	   T6."body_paint_code" as c175,
-	   ((left(((convert(varchar(50), T1."nominal_account_number"))))) + ' - ' + T2."account_description") as c176,
-	   (od_right(T6."vin",5)) + ' / ' + ((left(((convert(varchar(50), T6."internal_number")))))) + ' - ' + T8."description" + ' - ' + (CASE WHEN (T10."first_name" <> ' ') THEN ((left(((convert(varchar(50), T6."holder_number"))))) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((left(((convert(varchar(50), T6."holder_number"))))) + ' - ' + T10."family_name") END) as c177,
-	   CASE WHEN (((CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END) = 1) and (T5."is_canceled" <> '1')) THEN (T1."skr51_branch") ELSE null END as c178,
-	   (left(((convert(varchar(50), T6."salesman_number"))))) + ' - ' + T11."name" as c179,
-	   T11."name" as c180,
-	   T11."employee_number" as c181,
-	   T6."salesman_number" as c182,
-	   ('0' + ((convert(varchar(50), T1."skr51_branch")))) as c183,
-	   T1."subsidiary_to_company_ref" as c184,
-	   CASE WHEN (((CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END) = 1) and (T5."is_canceled" <> '1')) THEN (T1."skr51_sales_channel") ELSE null END as c185,
-	   CASE WHEN (T10."first_name" <> ' ') THEN ((left(((convert(varchar(50), T6."holder_number"))))) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((left(((convert(varchar(50), T6."holder_number"))))) + ' - ' + T10."family_name") END as c186,
-	   T10."family_name" as c187,
-	   T10."first_name" as c188,
-	   T9."family_name" as c189,
-	   T9."first_name" as c190,
-	   T6."holder_number" as c191,
-	   T6."owner_number" as c192,
-	   (left((ucase(T8."description")),3)) as c193,
-	   T8."description" as c194,
-	   T8."model_code" as c195,
-	   T7."description" as c196,
-	   T6."make_number" as c197,
-	   CASE WHEN ((CASE WHEN (((left(T1."vehicle_reference",1))) IN ('N')) THEN ('NW') WHEN (((left(T1."vehicle_reference",1))) IN ('V')) THEN ('VFW') WHEN (((left(T1."vehicle_reference",1))) IN ('G','D')) THEN ('GW') WHEN (((left(T1."vehicle_reference",1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c198,
-	   CASE WHEN (((left(T1."vehicle_reference",1))) IN ('N')) THEN ('NW') WHEN (((left(T1."vehicle_reference",1))) IN ('V')) THEN ('VFW') WHEN (((left(T1."vehicle_reference",1))) IN ('G','D')) THEN ('GW') WHEN (((left(T1."vehicle_reference",1))) IN ('T')) THEN ('TZ') ELSE null END as c199,
-	   (left(T1."vehicle_reference",1)) as c200,
-	   T6."vin" as c201,
-	   T6."internal_number" as c202,
-	   CASE WHEN ((CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END) = 1) THEN (((cdate((nconvert((left(T1."invoice_date",4)) + (substring(T1."invoice_date", 6, 2)) + (substring(T1."invoice_date", 9, 2)))))))) ELSE null END as c203,
-	   T5."vehicle_number" as c204,
-	   T5."is_canceled" as c205,
-	   T5."invoice_date" as c206,
-	   T5."invoice_number" as c207,
-	   T5."invoice_type" as c208,
-	   CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END as c209,
-	   T4."document_type_description" as c210,
-	   T4."document_type_in_journal" as c211,
-	   (left(((convert(varchar(50), T1."nominal_account_number"))))) + '_STK' as c212,
-	   CASE WHEN (T2."is_profit_loss_account" = 'J') THEN ('2') ELSE ('1') END as c213,
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN (((rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name"))) ELSE ((rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name")) END as c214,
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name") as c215,
-	   (len(((convert(varchar(50), T1."skr51_cost_unit"))) + 'Z') - 1) as c216,
-	   (rtrim(((convert(varchar(50), T1."skr51_sales_channel"))))) + ' - ' + T3."skr51_sales_channel_name" as c217,
-	   (len(((convert(varchar(50), T1."skr51_sales_channel"))) + 'Z') - 1) as c218,
-	   (rtrim(((convert(varchar(50), T1."skr51_cost_center"))))) + ' - ' + T3."skr51_cost_center_name" as c219,
-	   (len(((convert(varchar(50), T1."skr51_cost_center"))) + 'Z') - 1) as c220,
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_count" / 100 * -1) ELSE (T1."posted_count" / 100) END as c221,
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END as c222,
-	   CASE WHEN ((day((getdate()) - (convert(datetime, T1."accounting_date")))) <= 360) THEN (T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((convert(varchar(50), T1."employee_number")))) ELSE ('Buchungen älter 360 Tage') END as c223,
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + T3."skr51_make_description" as c224,
-	   T1."accounting_date" as c225,
-	   T2."is_profit_loss_account" as c226,
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN ('Neuwagen') WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59) THEN ('Gebrauchtwagen') WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69) THEN ('Teile & Zubehör') WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79) THEN ('Service') WHEN (T1."skr51_cost_unit" = 0) THEN ('Ohne Kostenträger') ELSE null END as c227,
-	   T1."free_form_accounting_text" as c228,
-	   T1."previously_used_account_no" as c229,
-	   T1."skr51_cost_unit" as c230,
-	   T1."skr51_sales_channel" as c231,
-	   T1."skr51_cost_center" as c232,
-	   T1."skr51_make" as c233,
-	   T1."skr51_branch" as c234,
-	   T1."day_of_actual_accounting" as c235,
-	   T1."days_for_cash_discount" as c236,
-	   T1."vat_key" as c237,
-	   T1."account_statement_page" as c238,
-	   T1."account_statement_number" as c239,
-	   T1."vat_id_number" as c240,
-	   T1."vehicle_reference" as c241,
-	   T1."posting_text" as c242,
-	   T1."term_of_payment" as c243,
-	   T1."cash_discount" as c244,
-	   T1."journal_line" as c245,
-	   T1."journal_page" as c246,
-	   T1."last_dunning_date" as c247,
-	   T1."dunning_level" as c248,
-	   T1."invoice_number" as c249,
-	   T1."employee_number" as c250,
-	   T1."serial_number_each_month" as c251,
-	   T1."account_form_page_line" as c252,
-	   T1."account_form_page_number" as c253,
-	   T1."contra_account_text" as c254,
-	   T1."nominal_contra_account" as c255,
-	   T1."customer_contra_account" as c256,
-	   T1."branch_number" as c257,
-	   T1."posted_count" as c258,
-	   T1."debit_or_credit" as c259,
-	   T1."posted_value" as c260,
-	   T1."document_date" as c261,
-	   T1."clearing_number" as c262,
-	   T1."is_balanced" as c263,
-	   T1."nominal_account_number" as c264,
-	   T1."customer_number" as c265,
-	   T1."position_in_document" as c266,
-	   T1."document_number" as c267,
-	   T1."document_type" as c268
-from "nominal_accounts" T2,
-	((((((((("journal_accountings" T1 left outer join "accounts_characteristics" T3 on (((((T3."skr51_make" = T1."skr51_make") and (T3."skr51_cost_center" = T1."skr51_cost_center")) and (T3."skr51_sales_channel" = T1."skr51_sales_channel")) and (T3."skr51_cost_unit" = T1."skr51_cost_unit")) and (T3."skr51_branch" = T1."skr51_branch")) and (T3."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")) left outer join "document_types" T4 on T4."document_type_in_journal" = T1."document_type") left outer join "invoices" T5 on T5."invtype_invnr" = T1."invoice_number") left outer join "vehicles" T6 on (od_right(T1."vehicle_reference",17)) = T6."vin") left outer join "makes" T7 on T6."make_number" = T7."make_number") left outer join "models" T8 on (T6."make_number" = T8."make_number") and (T6."model_code" = T8."model_code")) left outer join "customers_suppliers" T9 on T9."customer_number" = T6."owner_number") left outer join "customers_suppliers" T10 on T10."customer_number" = T6."holder_number") left outer join "employees" T11 on (T6."salesman_number" <> 0) and (T6."salesman_number" = T11."salesman_number"))
-where ((T2."nominal_account_number" = T1."nominal_account_number") and (T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref"))
-and ((((T2."is_profit_loss_account" = 'J') and (T1."vehicle_reference" <> ' ')) and (T1."nominal_account_number" IN (8000,8001,8010,8011,5002,8100,8110,8111,8200,8210,8510,8800,8820,8830,8870,8928,8934,7000,7010,7100,7101,7110,7111,7120,7200,7210,7240,7510,7800,7850,5001,5005,5006,5007,5008,5003,5004))) and ((CASE WHEN (T1."nominal_account_number" IN (8000,8010,8100,8110,8510)) THEN (1) ELSE (0) END) = 1))
-) D2
-) D1
-where ((((((c142 = "Internal Number_Vehicles") or ("Internal Number_Vehicles" IS NULL)) or (c142 IS NULL)) and (c143 >= convert(date, '2017-01-01'))) and (c144 = 'FZG-Geschäft')) and (c143 = "Invoice_Date_1"))
-) D4
--- order by "Vehicle Reference_berechnet" asc,"Vehicle Reference" asc,"Nominal Account Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 265
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.NW_GW_BE_auf_NW_GW_Bestand_Cat.sql

@@ -1,265 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.NW_GW_BE_auf_NW_GW_Bestand_Cat AS
-
-select convert(date, '1900-01-01') as "Accounting Date",
-	   '' as "Document Type",
-	   0 as "Document Number",
-	   0 as "Position In Document",
-	   0 as "Customer Number",
-	   0 as "Nominal Account Number",
-	   '' as "Is Balanced",
-	   0 as "Clearing Number",
-	   convert(date, '1900-01-01') as "Document Date",
-	   0 as "Posted Value",
-	   '' as "Debit Or Credit",
-	   0 as "Posted Count",
-	   0 as "Branch Number",
-	   0 as "Customer Contra Account",
-	   0 as "Nominal Contra Account",
-	   '' as "Contra Account Text",
-	   0 as "Account Form Page Number",
-	   0 as "Account Form Page Line",
-	   0 as "Serial Number Each Month",
-	   0 as "Employee Number",
-	   convert(date, '1900-01-01') as "Invoice Date",
-	   '' as "Invoice Number",
-	   '' as "Dunning Level",
-	   convert(date, '1900-01-01') as "Last Dunning Date",
-	   0 as "Journal Page",
-	   0 as "Journal Line",
-	   0 as "Cash Discount",
-	   0 as "Term Of Payment",
-	   '' as "Posting Text",
-	   '' as "Vehicle Reference",
-	   '' as "Vat Id Number",
-	   0 as "Account Statement Number",
-	   0 as "Account Statement Page",
-	   '' as "Vat Key",
-	   0 as "Days For Cash Discount",
-	   convert(date, '1900-01-01') as "Day Of Actual Accounting",
-	   0 as "Skr51 Branch",
-	   0 as "Skr51 Make",
-	   0 as "Skr51 Cost Center",
-	   0 as "Skr51 Sales Channel",
-	   0 as "Skr51 Cost Unit",
-	   '' as "Previously Used Account No",
-	   c252 as "Free Form Accounting Text",
-	   c251 as "Free Form Document Text",
-	   '' as "Nom_Account_Is Profit Loss Account",
-	   '1' as "Rechtseinheit",
-	   '' as "Betrieb",
-	   convert(date, '1900-01-01') as "Bookkeep Date",
-	   '' as "Marke",
-	   '' as "Text",
-	   '1' as "Mandant",
-	   0 as "Betrag",
-	   '' as "Konto_mit_Bezeichnung",
-	   0 as "Menge_FIBU",
-	   0 as "Stellen Cost Center",
-	   '' as "KST",
-	   0 as "Stellen Sales Channel",
-	   '' as "Absatzkanal",
-	   0 as "Stellen Cost Unit",
-	   '' as "Kostenträger_mit_Null",
-	   '' as "Kostenträger",
-	   '' as "GuV_Bilanz",
-	   '' as "Susa",
-	   '' as "Acct Nr",
-	   0 as "Stellen_Konto_Nr",
-	   SUM(0) OVER (partition by c166) as "Summe_Betrag",
-	   c167 as "Internal Number_ori",
-	   c250 as "Vin",
-	   c249 as "License Plate",
-	   c248 as "License Plate Country",
-	   c247 as "License Plate Season",
-	   c246 as "Make Number",
-	   c245 as "Free Form Make Text",
-	   c244 as "Model Code",
-	   c243 as "Free Form Model Text",
-	   c242 as "Is Roadworthy",
-	   c241 as "Is Customer Vehicle",
-	   c240 as "Dealer Vehicle Type",
-	   c239 as "Dealer Vehicle Number",
-	   c173 as "First Registration Date",
-	   c238 as "Readmission Date",
-	   c237 as "Next Service Date",
-	   c236 as "Next Service Km",
-	   c235 as "Next Service Miles",
-	   c234 as "Production Year",
-	   c233 as "Owner Number",
-	   c232 as "Holder Number",
-	   c231 as "Previous Owner Number",
-	   c230 as "Previous Owner Counter",
-	   c229 as "Last Holder Change Date",
-	   c228 as "German Kba Hsn",
-	   c227 as "German Kba Tsn",
-	   c226 as "Austria Nat Code",
-	   c225 as "Is Prefer Km",
-	   c224 as "Mileage Km",
-	   c223 as "Mileage Miles",
-	   c222 as "Odometer Reading Date",
-	   c221 as "Engine Number",
-	   c220 as "Gear Number",
-	   c219 as "Unloaded Weight",
-	   c218 as "Gross Vehicle Weight",
-	   c217 as "Power Kw",
-	   c216 as "Cubic Capacity",
-	   c215 as "Is All Accidents Repaired",
-	   c214 as "Accidents Counter",
-	   c213 as "Has Tyre Pressure Sensor",
-	   c212 as "Carkey Number",
-	   c211 as "Internal Source Flag",
-	   c210 as "Emission Code",
-	   c209 as "First Sold Country",
-	   c208 as "First Sold Dealer Code",
-	   c207 as "Body Paint Code",
-	   c178 as "Body Paint Description",
-	   c206 as "Is Body Paint Metallic",
-	   c205 as "Interior Paint Code",
-	   c204 as "Interior Paint Description",
-	   c203 as "Trim Code",
-	   c202 as "Trim Description",
-	   c201 as "Fine Dust Label",
-	   c200 as "Internal Assignment",
-	   c199 as "Ricambi Free Input",
-	   c198 as "Document Number",
-	   c197 as "Salesman Number",
-	   c196 as "Sale Date",
-	   c195 as "Next Emission Test Date",
-	   c194 as "Next General Inspection Date",
-	   c193 as "Next Rust Inspection Date",
-	   c192 as "Next Exceptional Inspection Da",
-	   c191 as "Last Change Date",
-	   c190 as "Last Change Employee No",
-	   c189 as "Created Date",
-	   c188 as "Created Employee No",
-	   c187 as "Last Change Subsidiary",
-	   MIN(convert(date, '1900-01-01')) OVER (partition by c166) as "Minimum_Accounting_Date",
-	   c186 as "Hauptbetrieb",
-	   c185 as "Standort",
-	   c184 as "Description_Makes",
-	   c184 as "Fabrikat",
-	   c183 as "Description_Models",
-	   c182 as "Model_Detail",
-	   c181 as "Model",
-	   c180 as "Fahrzeugtyp",
-	   c179 as "Fahrzeugart",
-	   c178 as "Farbe",
-	   c177 as "Customer Number_Vorbesitzer",
-	   c176 as "First Name_Vorbesitzer",
-	   c175 as "Family Name_Vorbesitzer",
-	   c174 as "Vorbesitzer",
-	   c173 as "Zulassungsdatum",
-	   1 as "Menge_1",
-	   COUNT(c239) OVER (partition by c166) as "Menge_2",
-	   1 / (COUNT(c239) OVER (partition by c166)) as "Menge",
-	   c172 as "Einsatz",
-	   CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END as "Standtage_Berechnung",
-	   (c171) / (COUNT(c239) OVER (partition by c166)) as "Standtage",
-	   CASE WHEN ((CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END) BETWEEN 0 AND 30) THEN ('0 - 30 Tage') WHEN ((CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END) BETWEEN 31 AND 60) THEN ('31 - 60 Tage') WHEN ((CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END) BETWEEN 61 AND 90) THEN ('61 - 90 Tage') WHEN ((CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END) BETWEEN 91 AND 180) THEN ('91 - 180 Tage') WHEN ((CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END) BETWEEN 181 AND 360) THEN ('181 - 360 Tage') WHEN ((CASE WHEN (c170 IS NULL) THEN ((((c171) / (COUNT(c239) OVER (partition by c166))))) ELSE ((c169) / (COUNT(c239) OVER (partition by c166))) END) > 360) THEN ('> 360 Tage') ELSE null END as "Standtagestaffel",
-	   (@CURRENT_DATE) as "Heute",
-	   c168 as "FZG",
-	   c166 as "Vehicle_Reference_berechnet",
-	   c167 as "Internal Number"
-from 
-(select ((T1."dealer_vehicle_type" + (rtrim(((convert(varchar(50), T1."dealer_vehicle_number"))))))) as c166,
-	   T2."internal_number" as c167,
-	   ((T1."dealer_vehicle_type" + (rtrim(((convert(varchar(50), T1."dealer_vehicle_number"))))))) + ' - ' + (substring((CASE WHEN ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END) IS NULL) THEN ('keine Angabe') WHEN ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END) LIKE '???%') THEN ('???') ELSE ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END)) END), 1, 170)) as c168,
-	   day((getdate()) - T1."in_buy_invoice_no_date") as c169,
-	   T1."in_buy_invoice_no_date" as c170,
-	   day((getdate()) - T1."in_arrival_date") as c171,
-	   T1."calc_basic_charge" + T1."calc_accessory" + T1."calc_extra_expenses" + T1."calc_usage_value_encr_external" + T1."calc_usage_value_encr_internal" + T1."calc_usage_value_encr_other" + T1."calc_total_writedown" + T1."calc_commission_for_arranging" + T1."calc_cost_internal_invoices" + T1."calc_cost_other" + T1."calc_returns_workshop" + (T1."calc_sales_aid" + T1."calc_sales_aid_finish" + T1."calc_sales_aid_bonus") * -1 as c172,
-	   T2."first_registration_date" as c173,
-	   (left(((convert(varchar(50), T5."customer_number"))))) + ' - ' + T5."first_name" + ' ' + T5."family_name" as c174,
-	   T5."family_name" as c175,
-	   T5."first_name" as c176,
-	   T5."customer_number" as c177,
-	   T2."body_paint_description" as c178,
-	   CASE WHEN ((CASE WHEN ((left(T2."dealer_vehicle_type",1)) IN ('N')) THEN ('NW') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('V')) THEN ('VFW') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('D')) THEN ('GW diff.') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('G')) THEN ('GW regel.') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c179,
-	   CASE WHEN ((left(T2."dealer_vehicle_type",1)) IN ('N')) THEN ('NW') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('V')) THEN ('VFW') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('D')) THEN ('GW diff.') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('G')) THEN ('GW regel.') WHEN ((left(T2."dealer_vehicle_type",1)) IN ('T')) THEN ('TZ') ELSE null END as c180,
-	   (substring((upper((CASE WHEN ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END) IS NULL) THEN ('keine Angabe') WHEN ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END) LIKE '???%') THEN ('???') ELSE ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END)) END))), 1, 3)) as c181,
-	   CASE WHEN ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END) IS NULL) THEN ('keine Angabe') WHEN ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END) LIKE '???%') THEN ('???') ELSE ((CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END)) END as c182,
-	   CASE WHEN (T4."description" = 'DIVERSE') THEN (T2."free_form_model_text") ELSE (T4."description") END as c183,
-	   T3."description" as c184,
-	   '0' + ((convert(varchar(50), T1."in_subsidiary"))) as c185,
-	   CASE WHEN (('0' + ((convert(varchar(50), T1."in_subsidiary")))) = '015                                                                                                                                                                                                                                                            ') THEN ('15') ELSE (T1."client_db") END as c186,
-	   T2."last_change_subsidiary" as c187,
-	   T2."created_employee_no" as c188,
-	   T2."created_date" as c189,
-	   T2."last_change_employee_no" as c190,
-	   T2."last_change_date" as c191,
-	   T2."next_exceptional_inspection_da" as c192,
-	   T2."next_rust_inspection_date" as c193,
-	   T2."next_general_inspection_date" as c194,
-	   T2."next_emission_test_date" as c195,
-	   T2."sale_date" as c196,
-	   T2."salesman_number" as c197,
-	   T2."document_number" as c198,
-	   T2."ricambi_free_input" as c199,
-	   T2."internal_assignment" as c200,
-	   T2."fine_dust_label" as c201,
-	   T2."trim_description" as c202,
-	   T2."trim_code" as c203,
-	   T2."interior_paint_description" as c204,
-	   T2."interior_paint_code" as c205,
-	   T2."is_body_paint_metallic" as c206,
-	   T2."body_paint_code" as c207,
-	   T2."first_sold_dealer_code" as c208,
-	   T2."first_sold_country" as c209,
-	   T2."emission_code" as c210,
-	   T2."internal_source_flag" as c211,
-	   T2."carkey_number" as c212,
-	   T2."has_tyre_pressure_sensor" as c213,
-	   T2."accidents_counter" as c214,
-	   T2."is_all_accidents_repaired" as c215,
-	   T2."cubic_capacity" as c216,
-	   T2."power_kw" as c217,
-	   T2."gross_vehicle_weight" as c218,
-	   T2."unloaded_weight" as c219,
-	   T2."gear_number" as c220,
-	   T2."engine_number" as c221,
-	   T2."odometer_reading_date" as c222,
-	   T2."mileage_miles" as c223,
-	   T2."mileage_km" as c224,
-	   T2."is_prefer_km" as c225,
-	   T2."austria_nat_code" as c226,
-	   T2."german_kba_tsn" as c227,
-	   T2."german_kba_hsn" as c228,
-	   T2."last_holder_change_date" as c229,
-	   T2."previous_owner_counter" as c230,
-	   T2."previous_owner_number" as c231,
-	   T2."holder_number" as c232,
-	   T2."owner_number" as c233,
-	   T2."production_year" as c234,
-	   T2."next_service_miles" as c235,
-	   T2."next_service_km" as c236,
-	   T2."next_service_date" as c237,
-	   T2."readmission_date" as c238,
-	   T2."dealer_vehicle_number" as c239,
-	   T2."dealer_vehicle_type" as c240,
-	   T2."is_customer_vehicle" as c241,
-	   T2."is_roadworthy" as c242,
-	   T2."free_form_model_text" as c243,
-	   T2."model_code" as c244,
-	   T2."free_form_make_text" as c245,
-	   T2."make_number" as c246,
-	   T2."license_plate_season" as c247,
-	   T2."license_plate_country" as c248,
-	   T2."license_plate" as c249,
-	   T2."vin" as c250,
-	   (rtrim(((convert(varchar(50), T1."dealer_vehicle_number"))))) as c251,
-	   T1."dealer_vehicle_type" + (rtrim(((convert(varchar(50), T1."dealer_vehicle_number"))))) as c252
-from (((("dbo"."vehicles" T2 left outer join "dbo"."makes" T3 on T2."make_number" = T3."make_number") left outer join "dbo"."models" T4 on (T2."make_number" = T4."make_number") and (T2."model_code" = T4."model_code")) left outer join "dbo"."customers_suppliers" T5 on T2."previous_owner_number" = T5."customer_number") left outer join "LOCOSOFT"."dbo"."dealer_vehicles" T1 on (T1."dealer_vehicle_type" = T2."dealer_vehicle_type") and (T1."dealer_vehicle_number" = T2."dealer_vehicle_number"))
-where ((T1."in_arrival_date" IS NOT NULL) and (T1."out_invoice_number" IS NULL))
--- order by c166 asc
-) D1
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 26
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_8520.sql

@@ -1,26 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.OP_aus_LOC_Belege_8520 AS
-
-select distinct T1."document_type" as "Document Type",
-	   T1."nominal_account_number" as "Nominal Account Number",
-	   T1."customer_contra_account" as "Customer Contra Account",
-	   T1."invoice_number" as "Invoice Number",
-	   T1."skr51_branch" as "Skr51 Branch",
-	   '1' as "Rechtseinheit",
-	   '0' + ((convert(varchar(50), T1."skr51_branch"))) as "Betrieb",
-	   '1' as "Mandant",
-	   '1' as "Hauptbetrieb",
-	   ('0' + ((convert(varchar(50), T1."skr51_branch")))) as "Standort"
-from "journal_accountings" T1
-where (((T1."nominal_account_number" IN (8520)) and (T1."document_type" = 'R')) and (T1."invoice_date" >= convert(date, '2016-01-01')))
--- order by "Invoice Number" asc,"Nominal Account Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 196
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_Deb_Saldo.sql


+ 0 - 173
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_nur_8520.sql

@@ -1,173 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.OP_aus_LOC_Belege_nur_8520 AS
-
-select c113 as "Accounting Date",
-	   c155 as "Document Type",
-	   c154 as "Document Number",
-	   c153 as "Position In Document",
-	   c110 as "Nominal Account Number",
-	   c152 as "Customer Number",
-	   c151 as "Is Balanced",
-	   c150 as "Clearing Number",
-	   c149 as "Document Date",
-	   c148 as "Posted Value",
-	   c147 as "Debit Or Credit",
-	   c146 as "Posted Count",
-	   c145 as "Branch Number",
-	   c144 as "Customer Contra Account",
-	   c143 as "Nominal Contra Account",
-	   c142 as "Contra Account Text",
-	   c141 as "Account Form Page Number",
-	   c140 as "Account Form Page Line",
-	   c139 as "Serial Number Each Month",
-	   c138 as "Employee Number",
-	   c137 as "Invoice Date",
-	   c136 as "Invoice Number",
-	   c135 as "Dunning Level",
-	   c134 as "Last Dunning Date",
-	   c133 as "Journal Page",
-	   c132 as "Journal Line",
-	   c131 as "Cash Discount",
-	   c130 as "Term Of Payment",
-	   c129 as "Posting Text",
-	   c128 as "Vehicle Reference",
-	   c127 as "Vat Id Number",
-	   c126 as "Account Statement Number",
-	   c125 as "Account Statement Page",
-	   c124 as "Vat Key",
-	   c123 as "Days For Cash Discount",
-	   c122 as "Day Of Actual Accounting",
-	   c121 as "Skr51 Branch",
-	   c120 as "Skr51 Make",
-	   c119 as "Skr51 Cost Center",
-	   c118 as "Skr51 Sales Channel",
-	   c117 as "Skr51 Cost Unit",
-	   c116 as "Previously Used Account No",
-	   c115 as "Free Form Accounting Text",
-	   c114 as "Free Form Document Text",
-	   '1' as "Rechtseinheit",
-	   c85 as "Betrieb",
-	   c113 as "Bookkeep Date",
-	   c112 as "Text",
-	   '1' as "Mandant",
-	   c97 as "Betrag",
-	   c111 as "Menge",
-	   c110 as "Acct Nr",
-	   c83 as "Customer Number_suctomer_supplier",
-	   c109 as "Is Supplier",
-	   c108 as "First Name",
-	   c107 as "Family Name",
-	   c106 as "Document Type In Journal",
-	   c105 as "Document Type Description",
-	   SUM(c97) OVER (partition by c83) as "Debitorsaldo_",
-	   c104 as "Invoice Type_Invoices",
-	   c103 as "Invoice Number_Invoices",
-	   c102 as "Subsidiary_Invoices",
-	   c101 as "Invoice Date_Invoices",
-	   c100 as "Hauptbetrieb",
-	   c99 as "Standort_ori",
-	   c98 as "Sel Name",
-	   c97 as "OP-Saldo",
-	   c96 as "Kostenstelle",
-	   c95 as "Tage",
-	   c94 as "Staffel",
-	   c93 as "Kunde",
-	   c92 as "Beleg",
-	   c91 as "Employee Number_Employees_journal_accountings",
-	   c90 as "Name_Employees_journal_accountings",
-	   c89 as "Anzahl_Stellen_Invoice_Number",
-	   c88 as "Forderungsart_aus_erste_Stelle_Inv_Number",
-	   c87 as "Forderungsart",
-	   c86 as "Standort_aus_2_Stelle_Invoice_Number",
-	   c85 as "Standort",
-	   c84 as "Standort_ims_8520"
-from 
-(select T3."customer_number" as c83,
-	   T6."Standort" as c84,
-	   ('0' + ((convert(varchar(50), T1."subsidiary_to_company_ref")))) as c85,
-	   CASE WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((substring(T1."invoice_number", 2, 1)) BETWEEN '1' AND '4')) THEN ('0' + (substring(T1."invoice_number", 2, 1))) ELSE null END as c86,
-	   CASE WHEN (T1."dunning_level" = 'Gesperrt') THEN ('Versicherung') ELSE ((CASE WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('2','3','4'))) THEN ('Service') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('5'))) THEN ('Teile') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('6'))) THEN ('Garantie') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('7'))) THEN ('Neuwagen') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('8'))) THEN ('Gebrauchtwagen') WHEN (T1."document_type" = 'R') THEN ('Rent') ELSE ('nicht zuzuordnen') END)) END as c87,
-	   CASE WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('2','3','4'))) THEN ('Service') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('5'))) THEN ('Teile') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('6'))) THEN ('Garantie') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('7'))) THEN ('Neuwagen') WHEN ((((len(T1."invoice_number" + 'Z') - 1)) = 7) and ((left(T1."invoice_number",1)) IN ('8'))) THEN ('Gebrauchtwagen') WHEN (T1."document_type" = 'R') THEN ('Rent') ELSE ('nicht zuzuordnen') END as c88,
-	   (len(T1."invoice_number" + 'Z') - 1) as c89,
-	   T2."name" as c90,
-	   T2."employee_number" as c91,
-	   CASE WHEN (T1."posting_text" IS NOT NULL) THEN ((substring((convert(varchar(50), ((T1."document_number")))), 1, 7)) + ' - ' + T1."posting_text" + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END as c92,
-	   CASE WHEN (T3."first_name" <> ' ') THEN ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."first_name" + ' ' + T3."family_name") ELSE ((left(((convert(varchar(50), T3."customer_number"))))) + ' - ' + T3."family_name") END as c93,
-	   CASE WHEN (((day((getdate()) - (convert(datetime, T1."accounting_date"))))) BETWEEN 0 AND 14) THEN ('< 2 Wochen') WHEN (((day((getdate()) - (convert(datetime, T1."accounting_date"))))) BETWEEN 15 AND 28) THEN ('2 - 4 Wochen') WHEN (((day((getdate()) - (convert(datetime, T1."accounting_date"))))) BETWEEN 29 AND 42) THEN ('4 - 6 Wochen') WHEN (((day((getdate()) - (convert(datetime, T1."accounting_date"))))) BETWEEN 43 AND 84) THEN ('6 - 12 Wochen') WHEN (((day((getdate()) - (convert(datetime, T1."accounting_date"))))) > 84) THEN ('> 12 Wochen') ELSE null END as c94,
-	   (day((getdate()) - (convert(datetime, T1."accounting_date")))) as c95,
-	   CASE WHEN (T5."invoice_type" IN (2,4,6,3)) THEN ('3') WHEN (T5."invoice_type" IN (5)) THEN ('6') WHEN (T5."invoice_type" IN (7)) THEN ('1') WHEN (T5."invoice_type" IN (8)) THEN ('2') WHEN (T4."document_type_in_journal" = 'R') THEN ('7') ELSE null END as c96,
-	   (CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) as c97,
-	   (left(((convert(varchar(50), T2."employee_number"))))) + ' - ' + T2."name" as c98,
-	   CASE WHEN (T5."subsidiary" IS NOT NULL) THEN ('0' + (left(((convert(varchar(50), T5."subsidiary")))))) ELSE ('nicht zuzuordnen') END as c99,
-	   CASE WHEN ((('0' + ((convert(varchar(50), T1."subsidiary_to_company_ref"))))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as c100,
-	   T5."invoice_date" as c101,
-	   T5."subsidiary" as c102,
-	   T5."invoice_number" as c103,
-	   T5."invoice_type" as c104,
-	   T4."document_type_description" as c105,
-	   T4."document_type_in_journal" as c106,
-	   T3."family_name" as c107,
-	   T3."first_name" as c108,
-	   T3."is_supplier" as c109,
-	   T1."nominal_account_number" as c110,
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_count" / 100 * -1) ELSE (T1."posted_count" / 100) END as c111,
-	   ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((left(((convert(varchar(50), T2."employee_number"))))) + ' - ' + T2."name")) as c112,
-	   T1."accounting_date" as c113,
-	   T1."free_form_document_text" as c114,
-	   T1."free_form_accounting_text" as c115,
-	   T1."previously_used_account_no" as c116,
-	   T1."skr51_cost_unit" as c117,
-	   T1."skr51_sales_channel" as c118,
-	   T1."skr51_cost_center" as c119,
-	   T1."skr51_make" as c120,
-	   T1."skr51_branch" as c121,
-	   T1."day_of_actual_accounting" as c122,
-	   T1."days_for_cash_discount" as c123,
-	   T1."vat_key" as c124,
-	   T1."account_statement_page" as c125,
-	   T1."account_statement_number" as c126,
-	   T1."vat_id_number" as c127,
-	   T1."vehicle_reference" as c128,
-	   T1."posting_text" as c129,
-	   T1."term_of_payment" as c130,
-	   T1."cash_discount" as c131,
-	   T1."journal_line" as c132,
-	   T1."journal_page" as c133,
-	   T1."last_dunning_date" as c134,
-	   T1."dunning_level" as c135,
-	   T1."invoice_number" as c136,
-	   T1."invoice_date" as c137,
-	   T1."employee_number" as c138,
-	   T1."serial_number_each_month" as c139,
-	   T1."account_form_page_line" as c140,
-	   T1."account_form_page_number" as c141,
-	   T1."contra_account_text" as c142,
-	   T1."nominal_contra_account" as c143,
-	   T1."customer_contra_account" as c144,
-	   T1."branch_number" as c145,
-	   T1."posted_count" as c146,
-	   T1."debit_or_credit" as c147,
-	   T1."posted_value" as c148,
-	   T1."document_date" as c149,
-	   T1."clearing_number" as c150,
-	   T1."is_balanced" as c151,
-	   T1."customer_number" as c152,
-	   T1."position_in_document" as c153,
-	   (T1."document_number") as c154,
-	   T1."document_type" as c155
-from "ims"."OP_aus_LOC_Belege_8520" T6,
-	(((("journal_accountings" T1 left outer join "LOCOSOFT"."dbo"."employees" T2 on T1."employee_number" = T2."employee_number") left outer join "LOCOSOFT"."dbo"."customers_suppliers" T3 on T3."customer_number" = T1."customer_number") left outer join "document_types" T4 on T4."document_type_in_journal" = T1."document_type") left outer join "invoices" T5 on T5."invtype_invnr" = T1."invoice_number")
-where ((T1."invoice_number" = T6."invoice_number") and (T1."customer_number" = T6."customer_contra_account"))
-and (((((T1."nominal_account_number" IN (1400,1409,1451,1408,1525)) and (T1."clearing_number" = 0)) and (T1."customer_number" IS NOT NULL)) and (not T4."document_type_in_journal" IN ('A','E','U','V','L'))) and (T3."customer_number" IS NOT NULL))
-) D1
--- order by "Customer Number" asc,"Document Type In Journal" asc,"Nominal Account Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 196
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_ohne_8520.sql


+ 0 - 24
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Serviceberater_Rechnung.sql

@@ -1,24 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Serviceberater_Rechnung AS
-
-select distinct T1."invoice_type" as "Invoice Type",
-	   T1."invoice_number" as "Invoice Number",
-	   T2."order_taking_employee_no" as "Order Taking Employee No",
-	   T2."order_delivery_employee_no" as "Order Delivery Employee No",
-	   T1."invtype_invnr" as "Invoice_Type_Invoice_Number",
-	   T3."employee_number" as "Employee Number_Employees",
-	   T3."name" as "Name_Employees",
-	   (substring((convert(varchar(50), T3."employee_number")), 1, 4)) + ' - ' + T3."name" as "Serviceberater"
-from (("LOCOSOFT"."dbo"."order_positions" T2 left outer join "dbo"."invoices" T1 on T2."order_number" = T1."order_number") left outer join "LOCOSOFT"."dbo"."employees" T3 on T2."order_taking_employee_no" = T3."employee_number")
-where ((T1."invoice_type" BETWEEN 2 AND 6) and (T2."order_date" >= TIMESTAMP '2019-01-01 00:00:00.000'))
-order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 130
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Abwesenheit_neu.sql

@@ -1,130 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Zeit_Abwesenheit_neu AS
-
-select "Employee Number_Employees" as "Employee Number_Employees",
-	   "Name_Employees" as "Name_Employees",
-	   "Initials_Employees" as "Initials_Employees",
-	   "Mechanic Number_Employees" as "Mechanic Number_Employees",
-	   "Salesman Number_Employees" as "Salesman Number_Employees",
-	   "Employment Date_Employees" as "Employment Date_Employees",
-	   "Termination Date_Employees" as "Termination Date_Employees",
-	   "Leave Date_Employees" as "Leave Date_Employees",
-	   "Employee Number_Absence_Cal" as "Employee Number_Absence_Cal",
-	   "Date_Absence_Cal" as "Date_Absence_Cal",
-	   "Type_Absence_Cal" as "Type_Absence_Cal",
-	   "Is Payed_Absence_Cal" as "Is Payed_Absence_Cal",
-	   "Day Contingent_Absence_Cal" as "Day Contingent_Absence_Cal",
-	   "Reason_Absence_Cal" as "Reason_Absence_Cal",
-	   "Booking Flag_Absence_Cal" as "Booking Flag_Absence_Cal",
-	   "Id_Absence_Reas" as "Id_Absence_Reas",
-	   "Description_Absence_Reas" as "Description_Absence_Reas",
-	   "Is Annual Vacation_Absence_Reas" as "Is Annual Vacation_Absence_Reas",
-	   "Type_Absence_Types" as "Type_Absence_Types",
-	   "Description_Absence_Types" as "Description_Absence_Types",
-	   "Hauptbetrieb" as "Hauptbetrieb",
-	   "Standort" as "Standort",
-	   "Monteur" as "Monteur",
-	   "Dummy_Arbeitszeit_Tag" as "Dummy_Arbeitszeit_Tag",
-	   "Abwesenheit" as "Abwesenheit",
-	   "Zeitkategorie" as "Zeitkategorie",
-	   "Zeitkategorie2" as "Zeitkategorie2",
-	   "Ges. Std." as "Ges. Std.",
-	   "Datum" as "Datum",
-	   "Order Number" as "Order Number",
-	   "Wochentag_Datum" as "Wochentag_Datum",
-	   "Validity Date_Worktimes" as "Validity Date_Worktimes",
-	   "Dayofweek_Worktimes" as "Dayofweek_Worktimes",
-	   "Work Duration_Worktimes" as "Work Duration_Worktimes",
-	   "Worktime Start_Worktimes" as "Worktime Start_Worktimes",
-	   "Worktime End_Worktimes" as "Worktime End_Worktimes",
-	   MAX("Validity Date_Worktimes") OVER (partition by "Employee Number_Employees") as "Max_Validity_Date_Worktimes",
-	   "Arbeitszeit_Tag" as "Arbeitszeit_Tag"
-from 
-(select c42 as "Employee Number_Employees",
-	   c71 as "Name_Employees",
-	   c70 as "Initials_Employees",
-	   c69 as "Mechanic Number_Employees",
-	   c68 as "Salesman Number_Employees",
-	   c67 as "Employment Date_Employees",
-	   c66 as "Termination Date_Employees",
-	   c65 as "Leave Date_Employees",
-	   c64 as "Employee Number_Absence_Cal",
-	   c49 as "Date_Absence_Cal",
-	   c63 as "Type_Absence_Cal",
-	   c62 as "Is Payed_Absence_Cal",
-	   c61 as "Day Contingent_Absence_Cal",
-	   c60 as "Reason_Absence_Cal",
-	   c59 as "Booking Flag_Absence_Cal",
-	   c58 as "Id_Absence_Reas",
-	   c57 as "Description_Absence_Reas",
-	   c56 as "Is Annual Vacation_Absence_Reas",
-	   c55 as "Type_Absence_Types",
-	   c54 as "Description_Absence_Types",
-	   '1' as "Hauptbetrieb",
-	   c53 as "Standort",
-	   c52 as "Monteur",
-	   8 as "Dummy_Arbeitszeit_Tag",
-	   c50 as "Abwesenheit",
-	   'Abwesenheit' as "Zeitkategorie",
-	   c51 as "Zeitkategorie2",
-	   c50 as "Ges. Std.",
-	   c49 as "Datum",
-	   '' as "Order Number",
-	   c48 as "Wochentag_Datum",
-	   c47 as "Validity Date_Worktimes",
-	   c46 as "Dayofweek_Worktimes",
-	   c43 as "Work Duration_Worktimes",
-	   c45 as "Worktime Start_Worktimes",
-	   c44 as "Worktime End_Worktimes",
-	   c43 as "Arbeitszeit_Tag",
-	   MAX(c47) OVER (partition by c42) as c39
-from 
-(select T1."employee_number" as c42,
-	   T5."work_duration" as c43,
-	   T5."worktime_end" as c44,
-	   T5."worktime_start" as c45,
-	   T5."dayofweek" as c46,
-	   T5."validity_date" as c47,
-	   (dayofweek(T2."date")) as c48,
-	   T2."date" as c49,
-	   (T2."day_contingent" * T5."work_duration") as c50,
-	   T3."id" + ' - ' + T3."description" as c51,
-	   (rtrim(((convert(varchar(50), T1."employee_number"))))) + ' - ' + T1."name" as c52,
-	   '0' + (rtrim(((convert(varchar(50), T1."subsidiary"))))) as c53,
-	   T4."description" as c54,
-	   T4."type" as c55,
-	   T3."is_annual_vacation" as c56,
-	   T3."description" as c57,
-	   T3."id" as c58,
-	   T2."booking_flag" as c59,
-	   T2."reason" as c60,
-	   T2."day_contingent" as c61,
-	   T2."is_payed" as c62,
-	   T2."type" as c63,
-	   T2."employee_number" as c64,
-	   T1."leave_date" as c65,
-	   T1."termination_date" as c66,
-	   T1."employment_date" as c67,
-	   T1."salesman_number" as c68,
-	   T1."mechanic_number" as c69,
-	   T1."initials" as c70,
-	   T1."name" as c71
-from "dbo"."employees" T1,
-	"LOCOSOFT"."dbo"."employees_worktimes" T5,
-	(("dbo"."absence_calendar" T2 left outer join "dbo"."absence_reasons" T3 on T2."reason" = T3."id") left outer join "dbo"."absence_types" T4 on T2."type" = T4."type")
-where (T1."employee_number" = T2."employee_number") and (T1."employee_number" = T5."employee_number")
-and ((((dayofweek(T2."date"))) = T5."dayofweek") and ((cdate(T2."date")) <= (@CURRENT_DATE)))
-) D2
-) D1
-where ("Validity Date_Worktimes" = c39)
--- order by "Employee Number_Employees" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 181
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_Pausen.sql

@@ -1,181 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Zeit_Stempelungen_Pausen AS
-
-select "Employee Number_Employees" as "Employee Number_Employees",
-	   "Name_Employees" as "Name_Employees",
-	   "Initials_Employees" as "Initials_Employees",
-	   "Mechanic Number_Employees" as "Mechanic Number_Employees",
-	   "Salesman Number_Employees" as "Salesman Number_Employees",
-	   "Employment Date_Employees" as "Employment Date_Employees",
-	   "Termination Date_Employees" as "Termination Date_Employees",
-	   "Leave Date_Employees" as "Leave Date_Employees",
-	   "Employee Number_Times" as "Employee Number_Times",
-	   "Order Number_Times" as "Order Number_Times",
-	   "Start Time_Times" as "Start Time_Times",
-	   "Type_Times" as "Type_Times",
-	   "Order Positions_Times" as "Order Positions_Times",
-	   "End Time_Times" as "End Time_Times",
-	   "Duration Minutes_Times" as "Duration Minutes_Times",
-	   "Type_Time_Types" as "Type_Time_Types",
-	   "Description_Time_Types" as "Description_Time_Types",
-	   "Datum" as "Datum",
-	   "Hauptbetrieb" as "Hauptbetrieb",
-	   "Standort" as "Standort",
-	   "Monteur" as "Monteur",
-	   "Anwesenheit_" as "Anwesenheit_",
-	   "produktiv_" as "produktiv_",
-	   "unproduktiv_" as "unproduktiv_",
-	   "Zeitkategorie" as "Zeitkategorie",
-	   "Zeitkategorie2" as "Zeitkategorie2",
-	   "Ges. Std._" as "Ges. Std._",
-	   "Order Number" as "Order Number",
-	   "Wochentag_Datum" as "Wochentag_Datum",
-	   "Is Flextime_Employees" as "Is Flextime_Employees",
-	   "Break Time Registration_Employees" as "Break Time Registration_Employees",
-	   "Is Latest Record_break_times" as "Is Latest Record_break_times",
-	   "Dayofweek_break_times" as "Dayofweek_break_times",
-	   "Break Start_break_times" as "Break Start_break_times",
-	   "Break End_break_times" as "Break End_break_times",
-	   "Pause" as "Pause",
-	   "Start_Times_Stunde" as "Start_Times_Stunde",
-	   "Start_Times_Minute" as "Start_Times_Minute",
-	   "End_Times_Stunde" as "End_Times_Stunde",
-	   "End_Times_Minute" as "End_Times_Minute",
-	   "Start_Times_Minute_Dezimal" as "Start_Times_Minute_Dezimal",
-	   "Start_Times_Dezimal" as "Start_Times_Dezimal",
-	   "End_Times_Minute_Dezimal" as "End_Times_Minute_Dezimal",
-	   "End_Times_Dezimal" as "End_Times_Dezimal",
-	   "Pausenzeit_Stunde" as "Pausenzeit_Stunde",
-	   "Dayofweek_Worktimes" as "Dayofweek_Worktimes",
-	   "Work Duration_Worktimes" as "Work Duration_Worktimes",
-	   "Worktime Start_Worktimes" as "Worktime Start_Worktimes",
-	   "Worktime End_Worktimes" as "Worktime End_Worktimes",
-	   "Validity Date_Worktimes" as "Validity Date_Worktimes",
-	   MAX("Validity Date_Worktimes") OVER (partition by "Employee Number_Employees") as "Max_Validity_Date",
-	   "Validity Date_Break_times" as "Validity Date_Break_times",
-	   MAX("Validity Date_Break_times") OVER (partition by "Employee Number_Employees") as "Max_validity_date_Break_times",
-	   "Pausenzeit_Anw_mehr_als_6" as "Pausenzeit_Anw_mehr_als_6",
-	   "Anwesenheit" as "Anwesenheit"
-from 
-(select c61 as "Employee Number_Employees",
-	   c106 as "Name_Employees",
-	   c105 as "Initials_Employees",
-	   c104 as "Mechanic Number_Employees",
-	   c103 as "Salesman Number_Employees",
-	   c102 as "Employment Date_Employees",
-	   c101 as "Termination Date_Employees",
-	   c100 as "Leave Date_Employees",
-	   c99 as "Employee Number_Times",
-	   c85 as "Order Number_Times",
-	   c92 as "Start Time_Times",
-	   c98 as "Type_Times",
-	   c97 as "Order Positions_Times",
-	   c96 as "End Time_Times",
-	   c95 as "Duration Minutes_Times",
-	   c94 as "Type_Time_Types",
-	   c93 as "Description_Time_Types",
-	   c92 as "Datum",
-	   '1' as "Hauptbetrieb",
-	   c91 as "Standort",
-	   c90 as "Monteur",
-	   c88 as "Anwesenheit_",
-	   c89 as "produktiv_",
-	   c88 as "unproduktiv_",
-	   c87 as "Zeitkategorie",
-	   '' as "Zeitkategorie2",
-	   c86 as "Ges. Std._",
-	   c85 as "Order Number",
-	   c84 as "Wochentag_Datum",
-	   c83 as "Is Flextime_Employees",
-	   c82 as "Break Time Registration_Employees",
-	   c81 as "Is Latest Record_break_times",
-	   c80 as "Dayofweek_break_times",
-	   c79 as "Break Start_break_times",
-	   c78 as "Break End_break_times",
-	   c69 as "Pause",
-	   c77 as "Start_Times_Stunde",
-	   c76 as "Start_Times_Minute",
-	   c75 as "End_Times_Stunde",
-	   c74 as "End_Times_Minute",
-	   c73 as "Start_Times_Minute_Dezimal",
-	   c72 as "Start_Times_Dezimal",
-	   c71 as "End_Times_Minute_Dezimal",
-	   c70 as "End_Times_Dezimal",
-	   c69 as "Pausenzeit_Stunde",
-	   c68 as "Dayofweek_Worktimes",
-	   c67 as "Work Duration_Worktimes",
-	   c66 as "Worktime Start_Worktimes",
-	   c65 as "Worktime End_Worktimes",
-	   c64 as "Validity Date_Worktimes",
-	   c63 as "Validity Date_Break_times",
-	   c62 as "Pausenzeit_Anw_mehr_als_6",
-	   c62 as "Anwesenheit",
-	   MAX(c64) OVER (partition by c61) as c56,
-	   MAX(c63) OVER (partition by c61) as c57
-from 
-(select T1."employee_number" as c61,
-	   (CASE WHEN ((CASE WHEN (T3."type" = 1) THEN (T2."duration_minutes" / 60) ELSE (0) END) >= 6.1) THEN ((T4."break_end" - T4."break_start") * -1) ELSE (0) END) as c62,
-	   T4."validity_date" as c63,
-	   T5."validity_date" as c64,
-	   T5."worktime_end" as c65,
-	   T5."worktime_start" as c66,
-	   T5."work_duration" as c67,
-	   T5."dayofweek" as c68,
-	   T4."break_end" - T4."break_start" as c69,
-	   ((od_hour(T2."end_time"))) + (((od_minute(T2."end_time"))) / 60) as c70,
-	   ((od_minute(T2."end_time"))) / 60 as c71,
-	   ((od_hour(T2."start_time"))) + (((od_minute(T2."start_time"))) / 60) as c72,
-	   ((od_minute(T2."start_time"))) / 60 as c73,
-	   (od_minute(T2."end_time")) as c74,
-	   (od_hour(T2."end_time")) as c75,
-	   (od_minute(T2."start_time")) as c76,
-	   (od_hour(T2."start_time")) as c77,
-	   T4."break_end" as c78,
-	   T4."break_start" as c79,
-	   T4."dayofweek" as c80,
-	   T4."is_latest_record" as c81,
-	   T1."break_time_registration" as c82,
-	   T1."is_flextime" as c83,
-	   (dayofweek(T2."start_time")) as c84,
-	   T2."order_number" as c85,
-	   T2."duration_minutes" / 60 as c86,
-	   CASE WHEN (T2."type" = 2) THEN ('produktiv') ELSE ('unproduktiv') END as c87,
-	   CASE WHEN (T3."type" = 1) THEN (T2."duration_minutes" / 60) ELSE (0) END as c88,
-	   CASE WHEN (T3."type" = 2) THEN (T2."duration_minutes" / 60) ELSE (0) END as c89,
-	   (rtrim(((convert(varchar(50), T1."employee_number"))))) + ' - ' + T1."name" as c90,
-	   '0' + (rtrim(((convert(varchar(50), T1."subsidiary"))))) as c91,
-	   T2."start_time" as c92,
-	   T3."description" as c93,
-	   T3."type" as c94,
-	   T2."duration_minutes" as c95,
-	   T2."end_time" as c96,
-	   T2."order_positions" as c97,
-	   T2."type" as c98,
-	   T2."employee_number" as c99,
-	   T1."leave_date" as c100,
-	   T1."termination_date" as c101,
-	   T1."employment_date" as c102,
-	   T1."salesman_number" as c103,
-	   T1."mechanic_number" as c104,
-	   T1."initials" as c105,
-	   T1."name" as c106
-from "dbo"."employees" T1,
-	"LOCOSOFT"."dbo"."employees_breaktimes" T4,
-	"LOCOSOFT"."dbo"."employees_worktimes" T5,
-	("dbo"."times" T2 left outer join "dbo"."time_types" T3 on T2."type" = T3."type")
-where (T1."employee_number" = T2."employee_number") and (T1."employee_number" = T4."employee_number") and (T1."employee_number" = T5."employee_number")
-and ((((T2."type" = 1) and (((dayofweek(T2."start_time"))) = T4."dayofweek")) and (((dayofweek(T2."start_time"))) = T5."dayofweek")) and (T2."start_time" >= convert(datetime, '2017-01-01 00:00:00.000')))
-) D2
-) D1
-where (("Validity Date_Worktimes" = c56) and ("Validity Date_Break_times" = c57))
--- order by "Employee Number_Employees" asc,"Start Time_Times" asc,"Order Number_Times" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 184
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_Pausen_produktiv.sql

@@ -1,184 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Zeit_Stempelungen_Pausen_produktiv AS
-
-select "Employee Number_Employees" as "Employee Number_Employees",
-	   "Name_Employees" as "Name_Employees",
-	   "Initials_Employees" as "Initials_Employees",
-	   "Mechanic Number_Employees" as "Mechanic Number_Employees",
-	   "Salesman Number_Employees" as "Salesman Number_Employees",
-	   "Employment Date_Employees" as "Employment Date_Employees",
-	   "Termination Date_Employees" as "Termination Date_Employees",
-	   "Leave Date_Employees" as "Leave Date_Employees",
-	   "Employee Number_Times" as "Employee Number_Times",
-	   "Order Number_Times" as "Order Number_Times",
-	   "Start Time_Times" as "Start Time_Times",
-	   "Type_Times" as "Type_Times",
-	   "Order Positions_Times" as "Order Positions_Times",
-	   "End Time_Times" as "End Time_Times",
-	   "Duration Minutes_Times" as "Duration Minutes_Times",
-	   "Type_Time_Types" as "Type_Time_Types",
-	   "Description_Time_Types" as "Description_Time_Types",
-	   "Datum" as "Datum",
-	   "Hauptbetrieb" as "Hauptbetrieb",
-	   "Standort" as "Standort",
-	   "Monteur" as "Monteur",
-	   "Anwesenheit_" as "Anwesenheit_",
-	   "produktiv_" as "produktiv_",
-	   "unproduktiv_" as "unproduktiv_",
-	   "Zeitkategorie" as "Zeitkategorie",
-	   "Zeitkategorie2" as "Zeitkategorie2",
-	   "Ges. Std._" as "Ges. Std._",
-	   "Order Number" as "Order Number",
-	   "Wochentag_Datum" as "Wochentag_Datum",
-	   "Is Flextime_Employees" as "Is Flextime_Employees",
-	   "Break Time Registration_Employees" as "Break Time Registration_Employees",
-	   "Is Latest Record_break_times" as "Is Latest Record_break_times",
-	   "Dayofweek_break_times" as "Dayofweek_break_times",
-	   "Break Start_break_times" as "Break Start_break_times",
-	   "Break End_break_times" as "Break End_break_times",
-	   "Pause" as "Pause",
-	   "Start_Times_Stunde" as "Start_Times_Stunde",
-	   "Start_Times_Minute" as "Start_Times_Minute",
-	   "End_Times_Stunde" as "End_Times_Stunde",
-	   "End_Times_Minute" as "End_Times_Minute",
-	   "Start_Times_Minute_Dezimal" as "Start_Times_Minute_Dezimal",
-	   "Start_Times_Dezimal" as "Start_Times_Dezimal",
-	   "End_Times_Minute_Dezimal" as "End_Times_Minute_Dezimal",
-	   "End_Times_Dezimal" as "End_Times_Dezimal",
-	   "Pausenzeit_Stunde" as "Pausenzeit_Stunde",
-	   "Dayofweek_Worktimes" as "Dayofweek_Worktimes",
-	   "Work Duration_Worktimes" as "Work Duration_Worktimes",
-	   "Worktime Start_Worktimes" as "Worktime Start_Worktimes",
-	   "Worktime End_Worktimes" as "Worktime End_Worktimes",
-	   "Validity Date_Worktimes" as "Validity Date_Worktimes",
-	   MAX("Validity Date_Worktimes") OVER (partition by "Employee Number_Employees") as "Max_Validity_Date",
-	   "Validity Date_Break_times" as "Validity Date_Break_times",
-	   MAX("Validity Date_Break_times") OVER (partition by "Employee Number_Employees") as "Max_validity_date_Break_times",
-	   "Pausenzeit_Anw_mehr_als_6_" as "Pausenzeit_Anw_mehr_als_6_",
-	   "Anwesenheit" as "Anwesenheit",
-	   "Pausenzeit_während_produktiv" as "Pausenzeit_während_produktiv"
-from 
-(select c62 as "Employee Number_Employees",
-	   c108 as "Name_Employees",
-	   c107 as "Initials_Employees",
-	   c106 as "Mechanic Number_Employees",
-	   c105 as "Salesman Number_Employees",
-	   c104 as "Employment Date_Employees",
-	   c103 as "Termination Date_Employees",
-	   c102 as "Leave Date_Employees",
-	   c101 as "Employee Number_Times",
-	   c87 as "Order Number_Times",
-	   c94 as "Start Time_Times",
-	   c100 as "Type_Times",
-	   c99 as "Order Positions_Times",
-	   c98 as "End Time_Times",
-	   c97 as "Duration Minutes_Times",
-	   c96 as "Type_Time_Types",
-	   c95 as "Description_Time_Types",
-	   c94 as "Datum",
-	   '1' as "Hauptbetrieb",
-	   c93 as "Standort",
-	   c92 as "Monteur",
-	   c90 as "Anwesenheit_",
-	   c91 as "produktiv_",
-	   c90 as "unproduktiv_",
-	   c89 as "Zeitkategorie",
-	   '' as "Zeitkategorie2",
-	   c88 as "Ges. Std._",
-	   c87 as "Order Number",
-	   c86 as "Wochentag_Datum",
-	   c85 as "Is Flextime_Employees",
-	   c84 as "Break Time Registration_Employees",
-	   c83 as "Is Latest Record_break_times",
-	   c82 as "Dayofweek_break_times",
-	   c81 as "Break Start_break_times",
-	   c80 as "Break End_break_times",
-	   c71 as "Pause",
-	   c79 as "Start_Times_Stunde",
-	   c78 as "Start_Times_Minute",
-	   c77 as "End_Times_Stunde",
-	   c76 as "End_Times_Minute",
-	   c75 as "Start_Times_Minute_Dezimal",
-	   c74 as "Start_Times_Dezimal",
-	   c73 as "End_Times_Minute_Dezimal",
-	   c72 as "End_Times_Dezimal",
-	   c71 as "Pausenzeit_Stunde",
-	   c70 as "Dayofweek_Worktimes",
-	   c69 as "Work Duration_Worktimes",
-	   c68 as "Worktime Start_Worktimes",
-	   c67 as "Worktime End_Worktimes",
-	   c66 as "Validity Date_Worktimes",
-	   c65 as "Validity Date_Break_times",
-	   c64 as "Pausenzeit_Anw_mehr_als_6_",
-	   c64 as "Anwesenheit",
-	   c63 as "Pausenzeit_während_produktiv",
-	   MAX(c66) OVER (partition by c62) as c57,
-	   MAX(c65) OVER (partition by c62) as c58
-from 
-(select T1."employee_number" as c62,
-	   CASE WHEN (((CASE WHEN (T3."type" = 2) THEN (T2."duration_minutes" / 60) ELSE (0) END) > 0) and (T4."break_start" BETWEEN (((od_hour(T2."start_time"))) + (((od_minute(T2."start_time"))) / 60)) AND (((od_hour(T2."end_time"))) + (((od_minute(T2."end_time"))) / 60)))) THEN ((((T4."break_end" - T4."break_start") * -1))) ELSE (0) END as c63,
-	   (((T4."break_end" - T4."break_start") * -1)) as c64,
-	   T4."validity_date" as c65,
-	   T5."validity_date" as c66,
-	   T5."worktime_end" as c67,
-	   T5."worktime_start" as c68,
-	   T5."work_duration" as c69,
-	   T5."dayofweek" as c70,
-	   T4."break_end" - T4."break_start" as c71,
-	   ((od_hour(T2."end_time"))) + (((od_minute(T2."end_time"))) / 60) as c72,
-	   ((od_minute(T2."end_time"))) / 60 as c73,
-	   ((od_hour(T2."start_time"))) + (((od_minute(T2."start_time"))) / 60) as c74,
-	   ((od_minute(T2."start_time"))) / 60 as c75,
-	   (od_minute(T2."end_time")) as c76,
-	   (od_hour(T2."end_time")) as c77,
-	   (od_minute(T2."start_time")) as c78,
-	   (od_hour(T2."start_time")) as c79,
-	   T4."break_end" as c80,
-	   T4."break_start" as c81,
-	   T4."dayofweek" as c82,
-	   T4."is_latest_record" as c83,
-	   T1."break_time_registration" as c84,
-	   T1."is_flextime" as c85,
-	   (dayofweek(T2."start_time")) as c86,
-	   T2."order_number" as c87,
-	   T2."duration_minutes" / 60 as c88,
-	   CASE WHEN (T2."type" = 2) THEN ('produktiv') ELSE ('unproduktiv') END as c89,
-	   CASE WHEN (T3."type" = 1) THEN (T2."duration_minutes" / 60) ELSE (0) END as c90,
-	   CASE WHEN (T3."type" = 2) THEN (T2."duration_minutes" / 60) ELSE (0) END as c91,
-	   (rtrim(((convert(varchar(50), T1."employee_number"))))) + ' - ' + T1."name" as c92,
-	   '0' + (rtrim(((convert(varchar(50), T1."subsidiary"))))) as c93,
-	   T2."start_time" as c94,
-	   T3."description" as c95,
-	   T3."type" as c96,
-	   T2."duration_minutes" as c97,
-	   T2."end_time" as c98,
-	   T2."order_positions" as c99,
-	   T2."type" as c100,
-	   T2."employee_number" as c101,
-	   T1."leave_date" as c102,
-	   T1."termination_date" as c103,
-	   T1."employment_date" as c104,
-	   T1."salesman_number" as c105,
-	   T1."mechanic_number" as c106,
-	   T1."initials" as c107,
-	   T1."name" as c108
-from "dbo"."employees" T1,
-	"LOCOSOFT"."dbo"."employees_breaktimes" T4,
-	"LOCOSOFT"."dbo"."employees_worktimes" T5,
-	("dbo"."times" T2 left outer join "dbo"."time_types" T3 on T2."type" = T3."type")
-where (T1."employee_number" = T2."employee_number") and (T1."employee_number" = T4."employee_number") and (T1."employee_number" = T5."employee_number")
-and ((((T2."type" = 2) and (((dayofweek(T2."start_time"))) = T4."dayofweek")) and (((dayofweek(T2."start_time"))) = T5."dayofweek")) and (T2."start_time" >= convert(datetime, '2017-01-01 00:00:00.000')))
-) D2
-) D1
-where (("Validity Date_Worktimes" = c57) and ("Validity Date_Break_times" = c58))
--- order by "Employee Number_Employees" asc,"Start Time_Times" asc,"Order Number_Times" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 48
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_neu.sql

@@ -1,48 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Zeit_Stempelungen_neu AS
-
-select T1."employee_number" as "Employee Number_Employees",
-	   T1."name" as "Name_Employees",
-	   T1."initials" as "Initials_Employees",
-	   T1."mechanic_number" as "Mechanic Number_Employees",
-	   T1."salesman_number" as "Salesman Number_Employees",
-	   T1."employment_date" as "Employment Date_Employees",
-	   T1."termination_date" as "Termination Date_Employees",
-	   T1."leave_date" as "Leave Date_Employees",
-	   T2."employee_number" as "Employee Number_Times",
-	   T2."order_number" as "Order Number_Times",
-	   T2."start_time" as "Start Time_Times",
-	   T2."type" as "Type_Times",
-	   T3."Order Number" as "Order Positions_Times",
-	   T2."end_time" as "End Time_Times",
-	   T2."exact_duration_seconds" / 60 as "Duration Minutes_Times",
-	   T4."type" as "Type_Time_Types",
-	   T4."description" as "Description_Time_Types",
-	   T2."start_time" as "Datum",
-	   '1' as "Hauptbetrieb",
-	   '0' + (rtrim(((convert(varchar(50), T1."subsidiary"))))) as "Standort",
-	   (rtrim(((convert(varchar(50), T1."employee_number"))))) + ' - ' + T1."name" as "Monteur",
-	   CASE WHEN (T4."type" = 1) THEN ((T2."exact_duration_seconds" / 60) / 60) ELSE (0) END as "Anwesenheit",
-	   CASE WHEN (T4."type" = 2) THEN ((T2."exact_duration_seconds" / 60) / 60) ELSE (0) END as "produktiv",
-	   CASE WHEN (T4."type" = 1) THEN ((T2."exact_duration_seconds" / 60) / 60) ELSE (0) END as "unproduktiv",
-	   CASE WHEN (T2."type" = 2) THEN ('produktiv') ELSE ('unproduktiv') END as "Zeitkategorie",
-	   '' as "Zeitkategorie2",
-	   (T2."exact_duration_seconds" / 60) / 60 as "Ges. Std.",
-	   T2."order_number" as "Order Number",
-	   (dayofweek(T2."start_time")) as "Wochentag_Datum",
-	   T1."is_flextime" as "Is Flextime_Employees",
-	   T1."break_time_registration" as "Break Time Registration_Employees"
-from "dbo"."employees" T1,
-	(("dbo"."times" T2 left outer join "dbo"."time_types" T4 on T2."type" = T4."type") left outer join "ims"."offene_Auftraege_Ums_ben_AW_fuer_Monteure" T3 on T3."order_number" = T2."order_number")
-where (T1."employee_number" = T2."employee_number")
--- order by "Employee Number_Employees" asc,"Start Time_Times" asc,"Order Number_Times" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 88
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_ben_Std_LG.sql

@@ -1,88 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Zeit_ben_Std_LG AS
-
-select distinct "Order Number" as "Order Number",
-	   "Labour Type" as "Labour Type",
-	   "Code_Labour_Types" as "Code_Labour_Types",
-	   "Description_Labour_Types" as "Description_Labour_Types",
-	   "Order Number_Labours" as "Order Number_Labours",
-	   "Subsidiary_Labours" as "Subsidiary_Labours",
-	   "Invoice Type_Labours" as "Invoice Type_Labours",
-	   "Mechanic No_Labours" as "Mechanic No_Labours",
-	   "AW/Std." as "AW/Std.",
-	   "Zeitkategorie" as "Zeitkategorie",
-	   "Zeitkategorie2" as "Zeitkategorie2",
-	   "Employee Number_Employee" as "Employee Number_Employee",
-	   "Name_Employee" as "Name_Employee",
-	   "Monteur" as "Monteur",
-	   "Invoice Date_Invoices" as "Invoice Date_Invoices",
-	   "Datum" as "Datum",
-	   "Duration Minutes_Times" as "Duration Minutes_Times",
-	   "ben. Std." as "ben. Std.",
-	   "Invoice Number" as "Invoice Number",
-	   "Is Canceled" as "Is Canceled",
-	   "Cancelation Number" as "Cancelation Number",
-	   "Cancelation Date" as "Cancelation Date",
-	   "Start Time" as "Start Time",
-	   "End Time" as "End Time",
-	   MIN("Invoice Date_Invoices") OVER (partition by "Order Number","Mechanic No_Labours") as "Min_Invoice_Date"
-from 
-(select c31 as "Order Number",
-	   '' as "Labour Type",
-	   '' as "Code_Labour_Types",
-	   '' as "Description_Labour_Types",
-	   c44 as "Order Number_Labours",
-	   c43 as "Subsidiary_Labours",
-	   0 as "Invoice Type_Labours",
-	   c30 as "Mechanic No_Labours",
-	   10 as "AW/Std.",
-	   'ben. Std.' as "Zeitkategorie",
-	   '' as "Zeitkategorie2",
-	   c42 as "Employee Number_Employee",
-	   c41 as "Name_Employee",
-	   c40 as "Monteur",
-	   c39 as "Invoice Date_Invoices",
-	   c39 as "Datum",
-	   c38 as "Duration Minutes_Times",
-	   c37 as "ben. Std.",
-	   0 as "Invoice Number",
-	   c36 as "Is Canceled",
-	   c35 as "Cancelation Number",
-	   c34 as "Cancelation Date",
-	   c33 as "Start Time",
-	   c32 as "End Time",
-	   MIN(c39) OVER (partition by c31,c30) as c26
-from 
-(select T2."mechanic_no" as c30,
-	   T1."order_number" as c31,
-	   T5."end_time" as c32,
-	   T5."start_time" as c33,
-	   T4."cancelation_date" as c34,
-	   T4."cancelation_number" as c35,
-	   T4."is_canceled" as c36,
-	   (T5."exact_duration_seconds" / 60) / 60 as c37,
-	   T5."exact_duration_seconds" / 60 as c38,
-	   T4."invoice_date" as c39,
-	   (rtrim(((convert(varchar(50), T3."employee_number"))))) + ' - ' + T3."name" as c40,
-	   T3."name" as c41,
-	   T3."employee_number" as c42,
-	   '0' + (rtrim(((convert(varchar(50), T3."subsidiary"))))) as c43,
-	   T2."order_number" as c44
-from "LOCOSOFT"."dbo"."times" T5,
-	("dbo"."invoices" T4 left outer join (("dbo"."order_positions" T1 left outer join "dbo"."labours" T2 on T1."order_number" = T2."order_number") left outer join "dbo"."employees" T3 on T2."mechanic_no" = T3."employee_number") on (T2."invoice_number" = T4."invoice_number") and (T2."invoice_type" = T4."invoice_type"))
-where ((T2."order_number" = T5."order_number") and (T2."mechanic_no" = T5."employee_number"))
-and (((convert(float, T2."time_units"))) <> 0)
-) D2
-) D1
-where (c26 = "Invoice Date_Invoices")
--- order by "Order Number" asc,"Mechanic No_Labours" asc,"Start Time" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 49
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_verk_Std.sql

@@ -1,49 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.Zeit_verk_Std AS
-
-select T1."order_number" as "Order Number",
-	   T1."order_position" as "Order Position",
-	   T1."labour_type" as "Labour Type",
-	   T2."code" as "Code_Labour_Types",
-	   T2."description" as "Description_Labour_Types",
-	   T3."order_number" as "Order Number_Labours",
-	   T3."order_position" as "Order Position_Labours",
-	   T3."order_position_line" as "Order Position Line_Labours",
-	   '0' + (rtrim(((convert(varchar(50), T4."subsidiary"))))) as "Subsidiary_Labours",
-	   T3."is_invoiced" as "Is Invoiced_Labours",
-	   T3."invoice_type" as "Invoice Type_Labours",
-	   T3."invoice_number" as "Invoice Number_Labours",
-	   T3."employee_no" as "Employee No_Labours",
-	   T3."mechanic_no" as "Mechanic No_Labours",
-	   T3."labour_operation_id" as "Labour Operation Id_Labours",
-	   T3."is_nominal" as "Is Nominal_Labours",
-	   T3."net_price_in_order" as "Net Price In Order_Labours",
-	   T3."rebate_percent" as "Rebate Percent_Labours",
-	   T3."goodwill_percent" as "Goodwill Percent_Labours",
-	   T3."charge_type" as "Charge Type_Labours",
-	   T3."text_line" as "Text Line_Labours",
-	   10 as "AW/Std.",
-	   ((convert(float, T3."time_units"))) / 10 as "verk. Std.",
-	   'verk. Std.' as "Zeitkategorie",
-	   '' as "Zeitkategorie2",
-	   T4."employee_number" as "Employee Number_Employee",
-	   T4."name" as "Name_Employee",
-	   (rtrim(((convert(varchar(50), T4."employee_number"))))) + ' - ' + T4."name" as "Monteur",
-	   T5."invoice_number" as "Invoice Number_Invoices",
-	   T5."invoice_date" as "Invoice Date_Invoices",
-	   T5."invoice_date" as "Datum",
-	   T3."time_units" as "Time Units_Labours",
-	   (convert(float, T3."time_units")) as "Time_Units_Zahl"
-from ("dbo"."invoices" T5 left outer join ((("dbo"."order_positions" T1 left outer join "dbo"."labour_types" T2 on T1."labour_type" = T2."code") left outer join "dbo"."labours" T3 on T1."order_number" = T3."order_number") left outer join "dbo"."employees" T4 on T3."mechanic_no" = T4."employee_number") on (T3."invoice_number" = T5."invoice_number") and (T3."invoice_type" = T5."invoice_type"))
-where (((convert(float, T3."time_units"))) <> 0)
--- order by "Order Number" asc,"Order Position" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 73 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_0.sql

@@ -0,0 +1,73 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[aftersales_rechnungen_ben_aw_final_0]
+AS
+SELECT CAST([Hauptbetrieb_ID] AS VARCHAR(100)) AS [Hauptbetrieb_ID],
+	CAST([Hauptbetrieb_Name] AS VARCHAR(100)) AS [Hauptbetrieb_Name],
+	CAST([Standort_ID] AS VARCHAR(100)) AS [Standort_ID],
+	CAST([Standort_Name] AS VARCHAR(100)) AS [Standort_Name],
+	CAST([Employee_Function] AS VARCHAR(100)) AS [Employee_Function],
+	CAST([Serviceberater] AS VARCHAR(100)) AS [Serviceberater],
+	CAST([Order_Number] AS VARCHAR(100)) AS [Order_Number],
+	CAST([Invoice_Desc_100] AS VARCHAR(100)) AS [Invoice_Desc_100],
+	CAST([Fabrikat] AS VARCHAR(100)) AS [Fabrikat],
+	CAST([Model] AS VARCHAR(100)) AS [Model],
+	CAST([Fahrzeug] AS VARCHAR(100)) AS [Fahrzeug],
+	CAST([Kostenstelle] AS VARCHAR(100)) AS [Kostenstelle],
+	CAST([Marke] AS VARCHAR(100)) AS [Marke],
+	CAST([Umsatzart] AS VARCHAR(100)) AS [Umsatzart],
+	CAST([Auftragsart] AS VARCHAR(100)) AS [Auftragsart],
+	CAST([Auftragsposition] AS VARCHAR(100)) AS [Auftragsposition],
+	CAST([Kundenart] AS VARCHAR(100)) AS [Kundenart],
+	CAST([Kunde] AS VARCHAR(100)) AS [Kunde],
+	CAST([Order_Desc_30] AS VARCHAR(100)) AS [Order_Desc_30],
+	CAST([Invoice_Desc_30] AS VARCHAR(100)) AS [Invoice_Desc_30],
+	CAST([c21] AS VARCHAR(100)) AS [c21],
+	CAST([Produktbuchungsgruppe] AS VARCHAR(100)) AS [Produktbuchungsgruppe],
+	CAST([FZG_Altersstaffel] AS VARCHAR(100)) AS [FZG_Altersstaffel],
+	CAST([Repair_Group_Desc] AS VARCHAR(100)) AS [Repair_Group_Desc],
+	CAST([DB1____EK] AS VARCHAR(100)) AS [DB1____EK],
+	CAST([Rechnung_Gutschrift] AS VARCHAR(100)) AS [Rechnung_Gutschrift],
+	CAST([Parts_Focus_Group] AS VARCHAR(100)) AS [Parts_Focus_Group],
+	CAST([Parts_Make_Desc] AS VARCHAR(100)) AS [Parts_Make_Desc],
+	CAST([Parts_Group_Desc] AS VARCHAR(100)) AS [Parts_Group_Desc],
+	CAST([PLZ_1_Stelle] AS VARCHAR(100)) AS [PLZ_1_Stelle],
+	CAST([PLZ_2_Stelle] AS VARCHAR(100)) AS [PLZ_2_Stelle],
+	CAST([PLZ_3_Stelle] AS VARCHAR(100)) AS [PLZ_3_Stelle],
+	CAST([PLZ_4_Stelle] AS VARCHAR(100)) AS [PLZ_4_Stelle],
+	CAST([PLZ] AS VARCHAR(100)) AS [PLZ],
+	CAST([Zuordnung_Funktion] AS VARCHAR(100)) AS [Zuordnung_Funktion],
+	CAST([Order_Desc_100] AS VARCHAR(100)) AS [Order_Desc_100],
+	CAST(ROUND(ISNULL([Lohn], 0), 8) AS NUMERIC(19, 8)) AS [Lohn],
+	CAST(ROUND(ISNULL([Teile], 0), 8) AS NUMERIC(19, 8)) AS [Teile],
+	CAST(ROUND(ISNULL([EW_Teile], 0), 8) AS NUMERIC(19, 8)) AS [EW_Teile],
+	CAST(ROUND(ISNULL([Sonst_], 0), 8) AS NUMERIC(19, 8)) AS [Sonst_],
+	CAST(ROUND(ISNULL([TÜV], 0), 8) AS NUMERIC(19, 8)) AS [TÜV],
+	CAST(ROUND(ISNULL([Fremdl_], 0), 8) AS NUMERIC(19, 8)) AS [Fremdl_],
+	CAST(ROUND(ISNULL([Mietw_], 0), 8) AS NUMERIC(19, 8)) AS [Mietw_],
+	CAST(ROUND(ISNULL([Rädereinl_], 0), 8) AS NUMERIC(19, 8)) AS [Rädereinl_],
+	CAST(ROUND(ISNULL([verk__Std_], 0), 8) AS NUMERIC(19, 8)) AS [verk__Std_],
+	CAST(ROUND(ISNULL([ben__Std_], 0), 8) AS NUMERIC(19, 8)) AS [ben__Std_],
+	CAST(ROUND(ISNULL([NL_Lohn], 0), 8) AS NUMERIC(19, 8)) AS [NL_Lohn],
+	CAST(ROUND(ISNULL([NL_Teile], 0), 8) AS NUMERIC(19, 8)) AS [NL_Teile],
+	CAST(ROUND(ISNULL([NL_Sonst_], 0), 8) AS NUMERIC(19, 8)) AS [NL_Sonst_],
+	CAST(ROUND(ISNULL([DG], 0), 8) AS NUMERIC(19, 8)) AS [DG],
+	CAST(ROUND(ISNULL([NL_Sonst__], 0), 8) AS NUMERIC(19, 8)) AS [NL_Sonst__],
+	CAST(ROUND(ISNULL([Anz__AT], 0), 8) AS NUMERIC(19, 8)) AS [Anz__AT],
+	CAST(ROUND(ISNULL([Anwesenheit_Mech_Karo_Lack], 0), 8) AS NUMERIC(19, 8)) AS [Anwesenheit_Mech_Karo_Lack],
+	CAST(ROUND(ISNULL([Anwesenheit_Meister], 0), 8) AS NUMERIC(19, 8)) AS [Anwesenheit_Meister],
+	CAST([Invoice_Date] AS DATETIME) AS [Invoice_Date],
+	CAST([Rechnungsausgang] AS VARCHAR(100)) AS [Rechnungsausgang],
+	CAST([Fabrikat_Order_By] AS INT) AS [Fabrikat_Order_By],
+	CAST([Serviceberater_Rg_Steller] AS VARCHAR(100)) AS [Serviceberater_Rg_Steller]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_ben_aw_final_11]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 102 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_11.sql

@@ -0,0 +1,102 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_ben_aw_final_11]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
+	"GC_Department"."Standort_ID" AS "Standort_ID",
+	"GC_Department"."Standort_Name" AS "Standort_Name",
+	'Serviceberater' AS "Employee_Function",
+	"T2"."Serviceberater" AS "Serviceberater",
+	"T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121) AS "Order_Number",
+	'' AS "Invoice_Desc_100",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	"T2"."Model" AS "Model",
+	"T2"."Fahrzeug" AS "Fahrzeug",
+	"T2"."Kostenstelle" AS "Kostenstelle",
+	"T2"."Marke" AS "Marke",
+	"T2"."Umsatzart" AS "Umsatzart",
+	"T2"."Auftragsart" AS "Auftragsart",
+	'' AS "Auftragsposition",
+	'' AS "Kundenart",
+	"T2"."Kunde" AS "Kunde",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Order_Desc_30",
+	'' AS "Invoice_Desc_30",
+	"GC_Produktbuchungsgruppen"."Zuordnung" AS "c21",
+	"T2"."Kostenstelle" AS "Produktbuchungsgruppe",
+	'' AS "FZG_Altersstaffel",
+	'' AS "Repair_Group_Desc",
+	'' AS "DB1____EK",
+	'' AS "Rechnung_Gutschrift",
+	'' AS "Parts_Focus_Group",
+	'' AS "Parts_Make_Desc",
+	'' AS "Parts_Group_Desc",
+	left("T2"."Geschäftsart", 1) AS "PLZ_1_Stelle",
+	left("T2"."Geschäftsart", 2) AS "PLZ_2_Stelle",
+	left("T2"."Geschäftsart", 3) AS "PLZ_3_Stelle",
+	left("T2"."Geschäftsart", 4) AS "PLZ_4_Stelle",
+	"T2"."Geschäftsart" AS "PLZ",
+	'Serviceberater' AS "Zuordnung_Funktion",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 100
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 100 Tage'
+		END AS "Order_Desc_100",
+	0 AS "Lohn",
+	0 AS "Teile",
+	0 AS "EW_Teile",
+	0 AS "Sonst_",
+	0 AS "TÜV",
+	0 AS "Fremdl_",
+	0 AS "Mietw_",
+	0 AS "Rädereinl_",
+	0 AS "verk__Std_",
+	"T2"."ben. Std." AS "ben__Std_",
+	0 AS "NL_Lohn",
+	0 AS "NL_Teile",
+	0 AS "NL_Sonst_",
+	0 AS "DG",
+	0 AS "NL_Sonst__",
+	0 AS "Anz__AT",
+	0 AS "Anwesenheit_Mech_Karo_Lack",
+	0 AS "Anwesenheit_Meister",
+	"T2"."Invoice Date" AS "Invoice_Date",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Rechnungsausgang",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By",
+	"T2"."Kundenart" AS "Serviceberater_Rg_Steller"
+FROM (
+	(
+		[staging].[aftersales_rechnungen_ben_aw_final_80] "T2" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "T2"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb"
+			AND "T2"."Standort" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "T2"."Fabrikat" = "GC_Marken"."Description"
+	)
+LEFT OUTER JOIN "GC"."data"."GC_Produktbuchungsgruppen" "GC_Produktbuchungsgruppen" ON "T2"."Kostenstelle" = "GC_Produktbuchungsgruppen"."Produktbuchungsgruppe"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 48 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_80.sql

@@ -0,0 +1,48 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_ben_aw_final_80]
+AS
+SELECT c65 AS "Invoice Type",
+	c64 AS "Invoice Number",
+	c63 AS "Subsidiary",
+	c62 AS "Invoice Date",
+	c61 AS "Service Date",
+	c60 AS "Is Canceled",
+	c59 AS "Vehicle Number",
+	c58 AS "Invoice_Type_Invoice_Number",
+	c57 AS "Hauptbetrieb",
+	c56 AS "Standort",
+	c55 AS "Serviceberater",
+	c54 AS "Umsatzart",
+	c53 AS "Fabrikat",
+	c53 AS "Description_Makes",
+	c52 AS "Description_Models",
+	c51 AS "Model",
+	c50 AS "Fahrzeug",
+	c49 AS "Kostenstelle",
+	c48 AS "Marke",
+	'Service' AS "Auftragsart",
+	c47 AS "Geschäftsart",
+	c46 AS "Kunde",
+	c45 AS "Time Units",
+	c44 AS "Time Units_Zahl",
+	10 AS "AW/Std.",
+	c43 AS "verk. Std._",
+	c37 AS "Order Number",
+	c42 AS "Order Number_Rg_Ausg",
+	c41 AS "Kundenart",
+	c40 AS "Summe Duration Minutes",
+	c39 AS "Order Number_ben_AW",
+	1 AS "Anzahl_Datensätze_1",
+	COUNT(c39) OVER (PARTITION BY c37) AS "Anzahl_Datensätze_2",
+	(c38) / (COUNT(c39) OVER (PARTITION BY c37)) AS "ben. Std."
+FROM [staging].[aftersales_rechnungen_ben_aw_final_90]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 157 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_90.sql

@@ -0,0 +1,157 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_ben_aw_final_90]
+AS
+SELECT (
+		CASE 
+			WHEN (T2."Serviceberater" IS NOT NULL)
+				THEN (
+						(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+							CASE 
+								WHEN (T3."first_name" IS NULL)
+									THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+								ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+								END
+							)
+						)
+			ELSE (
+					(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+						CASE 
+							WHEN (T3."first_name" IS NULL)
+								THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+							ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+							END
+						)
+					)
+			END
+		) AS c37,
+	T9."Summe_Duration_Minutes" / 60 AS c38,
+	T9."order_number" AS c39,
+	T9."Summe_Duration_Minutes" AS c40,
+	(substring((convert(VARCHAR(50), T8."employee_number")), 1, 4)) + ' - ' + T8."name" AS c41,
+	CASE 
+		WHEN ((day((getdate()) - (convert(DATETIME, T1."invoice_date")))) <= 4)
+			THEN (
+					(
+						CASE 
+							WHEN (T2."Serviceberater" IS NOT NULL)
+								THEN (
+										(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+											CASE 
+												WHEN (T3."first_name" IS NULL)
+													THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+												ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+												END
+											)
+										)
+							ELSE (
+									(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+										CASE 
+											WHEN (T3."first_name" IS NULL)
+												THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+											ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+											END
+										)
+									)
+							END
+						)
+					)
+		ELSE NULL
+		END AS c42,
+	((convert(FLOAT, T7."time_units"))) / 10 AS c43,
+	(convert(FLOAT, T7."time_units")) AS c44,
+	T7."time_units" AS c45,
+	CASE 
+		WHEN (T3."first_name" IS NULL)
+			THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+		ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+		END AS c46,
+	T3."zip_code" AS c47,
+	CASE 
+		WHEN (T4."description" = 'Ford')
+			THEN ('1')
+		WHEN (T4."description" = 'Nissan')
+			THEN ('3')
+		WHEN (T4."description" = 'Suzuki')
+			THEN ('2')
+		ELSE ('9')
+		END AS c48,
+	CASE 
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('1', '6'))
+			THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+		WHEN (T6."type" IN (40, 41, 44, 45, 46, 47, 48, 49, 88, 89, 50, 90))
+			THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('2'))
+			THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+		WHEN (T6."type" IN (42, 92))
+			THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('3'))
+			THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+		WHEN (T6."type" IN (43, 93))
+			THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+		ELSE NULL
+		END AS c49,
+	(substring((substring((convert(VARCHAR(50), T1."vehicle_number")), 1, 5)) + ' - ' + T5."description", 1, 100)) AS c50,
+	(substring((upper(T5."description")), 1, 3)) AS c51,
+	T5."description" AS c52,
+	T4."description" AS c53,
+	CASE 
+		WHEN (T1."invoice_type" = 6)
+			THEN ('GWL')
+		WHEN (
+				(T1."invoice_type" = 4)
+				OR (T3."customer_number" = 100001)
+				)
+			THEN ('intern')
+		ELSE ('extern')
+		END AS c54,
+	T2."Serviceberater" AS c55,
+	'0' + (convert(VARCHAR(50), T1."subsidiary")) AS c56,
+	CASE 
+		WHEN ((substring((convert(VARCHAR(50), T1."invoice_number")), 1, 1)) = '2')
+			THEN ('15')
+		ELSE ('1')
+		END AS c57,
+	(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + '_' + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) AS c58,
+	T1."vehicle_number" AS c59,
+	T1."is_canceled" AS c60,
+	T1."service_date" AS c61,
+	T1."invoice_date" AS c62,
+	T1."subsidiary" AS c63,
+	T1."invoice_number" AS c64,
+	T1."invoice_type" AS c65
+FROM "dbo"."invoices" T1
+LEFT OUTER JOIN "dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."paying_customer"
+LEFT OUTER JOIN "dbo"."vehicles" T10 ON T1."vehicle_number" = T10."internal_number"
+LEFT OUTER JOIN "dbo"."makes" T4 ON T10."make_number" = T4."make_number"
+LEFT OUTER JOIN "dbo"."models" T5 ON (T10."make_number" = T5."make_number")
+	AND (T10."model_code" = T5."model_code")
+LEFT OUTER JOIN "dbo"."labours" T7 ON (T7."invoice_number" = T1."invoice_number")
+	AND (T7."invoice_type" = T1."invoice_type")
+LEFT OUTER JOIN "dbo"."charge_type_descriptions" T6 ON T6."type" = T7."charge_type"
+LEFT OUTER JOIN "dbo"."employees" T8 ON T1."creating_employee" = T8."employee_number"
+LEFT OUTER JOIN "ims"."Serviceberater_Rechnung" T2 ON T1."invtype_invnr" = T2."invtype_invnr"
+INNER JOIN "ims"."ben_AW_Order_Number" T9 ON (T7."order_number" = T9."order_number")
+WHERE (
+		(
+			(
+				(T1."invoice_type" BETWEEN 2 AND 6)
+				AND (T1."is_canceled" <> 1)
+				)
+			AND (T1."invoice_date" >= convert(DATE, '2017-01-01'))
+			)
+		AND (
+			(((convert(FLOAT, T7."time_units"))) <> 0)
+			AND (((convert(FLOAT, T7."time_units"))) IS NOT NULL)
+			)
+		)
+	-- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 102 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_fm.sql

@@ -0,0 +1,102 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_ben_aw_final_fm]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
+	"GC_Department"."Standort_ID" AS "Standort_ID",
+	"GC_Department"."Standort_Name" AS "Standort_Name",
+	'Serviceberater' AS "Employee_Function",
+	"T2"."Serviceberater" AS "Serviceberater",
+	"T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121) AS "Order_Number",
+	'' AS "Invoice_Desc_100",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	"T2"."Model" AS "Model",
+	"T2"."Fahrzeug" AS "Fahrzeug",
+	"T2"."Kostenstelle" AS "Kostenstelle",
+	"T2"."Marke" AS "Marke",
+	"T2"."Umsatzart" AS "Umsatzart",
+	"T2"."Auftragsart" AS "Auftragsart",
+	'' AS "Auftragsposition",
+	'' AS "Kundenart",
+	"T2"."Kunde" AS "Kunde",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Order_Desc_30",
+	'' AS "Invoice_Desc_30",
+	"GC_Produktbuchungsgruppen"."Zuordnung" AS "c21",
+	"T2"."Kostenstelle" AS "Produktbuchungsgruppe",
+	'' AS "FZG_Altersstaffel",
+	'' AS "Repair_Group_Desc",
+	'' AS "DB1____EK",
+	'' AS "Rechnung_Gutschrift",
+	'' AS "Parts_Focus_Group",
+	'' AS "Parts_Make_Desc",
+	'' AS "Parts_Group_Desc",
+	left("T2"."Geschäftsart", 1) AS "PLZ_1_Stelle",
+	left("T2"."Geschäftsart", 2) AS "PLZ_2_Stelle",
+	left("T2"."Geschäftsart", 3) AS "PLZ_3_Stelle",
+	left("T2"."Geschäftsart", 4) AS "PLZ_4_Stelle",
+	"T2"."Geschäftsart" AS "PLZ",
+	'Serviceberater' AS "Zuordnung_Funktion",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 100
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 100 Tage'
+		END AS "Order_Desc_100",
+	0 AS "Lohn",
+	0 AS "Teile",
+	0 AS "EW_Teile",
+	0 AS "Sonst_",
+	0 AS "TÜV",
+	0 AS "Fremdl_",
+	0 AS "Mietw_",
+	0 AS "Rädereinl_",
+	0 AS "verk__Std_",
+	"T2"."ben  Std " AS "ben__Std_",
+	0 AS "NL_Lohn",
+	0 AS "NL_Teile",
+	0 AS "NL_Sonst_",
+	0 AS "DG",
+	0 AS "NL_Sonst__",
+	0 AS "Anz__AT",
+	0 AS "Anwesenheit_Mech_Karo_Lack",
+	0 AS "Anwesenheit_Meister",
+	"T2"."Invoice Date" AS "Invoice_Date",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Rechnungsausgang",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By",
+	"T2"."Kundenart" AS "Serviceberater_Rg_Steller"
+FROM (
+	(
+		"GC"."locosoft"."Aftersales_Rechnungen_ben_AW_final" "T2" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "T2"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb"
+			AND "T2"."Standort" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "T2"."Fabrikat" = "GC_Marken"."Description"
+	)
+LEFT OUTER JOIN "GC"."data"."GC_Produktbuchungsgruppen" "GC_Produktbuchungsgruppen" ON "T2"."Kostenstelle" = "GC_Produktbuchungsgruppen"."Produktbuchungsgruppe"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 202 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_ben_aw_final_imr.sql

@@ -0,0 +1,202 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_ben_aw_final_imr]
+AS
+SELECT c65 AS "Invoice Type",
+	c64 AS "Invoice Number",
+	c63 AS "Subsidiary",
+	c62 AS "Invoice Date",
+	c61 AS "Service Date",
+	c60 AS "Is Canceled",
+	c59 AS "Vehicle Number",
+	c58 AS "Invoice_Type_Invoice_Number",
+	c57 AS "Hauptbetrieb",
+	c56 AS "Standort",
+	c55 AS "Serviceberater",
+	c54 AS "Umsatzart",
+	c53 AS "Fabrikat",
+	c53 AS "Description_Makes",
+	c52 AS "Description_Models",
+	c51 AS "Model",
+	c50 AS "Fahrzeug",
+	c49 AS "Kostenstelle",
+	c48 AS "Marke",
+	'Service' AS "Auftragsart",
+	c47 AS "Geschäftsart",
+	c46 AS "Kunde",
+	c45 AS "Time Units",
+	c44 AS "Time Units_Zahl",
+	10 AS "AW/Std.",
+	c43 AS "verk. Std._",
+	c37 AS "Order Number",
+	c42 AS "Order Number_Rg_Ausg",
+	c41 AS "Kundenart",
+	c40 AS "Summe Duration Minutes",
+	c39 AS "Order Number_ben_AW",
+	1 AS "Anzahl_Datensätze_1",
+	COUNT(c39) OVER (PARTITION BY c37) AS "Anzahl_Datensätze_2",
+	(c38) / (COUNT(c39) OVER (PARTITION BY c37)) AS "ben. Std."
+FROM (
+	SELECT (
+			CASE 
+				WHEN (T2."Serviceberater" IS NOT NULL)
+					THEN (
+							(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+								CASE 
+									WHEN (T3."first_name" IS NULL)
+										THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+									ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+									END
+								)
+							)
+				ELSE (
+						(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+							CASE 
+								WHEN (T3."first_name" IS NULL)
+									THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+								ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+								END
+							)
+						)
+				END
+			) AS c37,
+		T9."Summe_Duration_Minutes" / 60 AS c38,
+		T9."order_number" AS c39,
+		T9."Summe_Duration_Minutes" AS c40,
+		(substring((convert(VARCHAR(50), T8."employee_number")), 1, 4)) + ' - ' + T8."name" AS c41,
+		CASE 
+			WHEN ((day((getdate()) - (convert(DATETIME, T1."invoice_date")))) <= 4)
+				THEN (
+						(
+							CASE 
+								WHEN (T2."Serviceberater" IS NOT NULL)
+									THEN (
+											(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+												CASE 
+													WHEN (T3."first_name" IS NULL)
+														THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+													ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+													END
+												)
+											)
+								ELSE (
+										(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+											CASE 
+												WHEN (T3."first_name" IS NULL)
+													THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+												ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+												END
+											)
+										)
+								END
+							)
+						)
+			ELSE NULL
+			END AS c42,
+		((convert(FLOAT, T7."time_units"))) / 10 AS c43,
+		(convert(FLOAT, T7."time_units")) AS c44,
+		T7."time_units" AS c45,
+		CASE 
+			WHEN (T3."first_name" IS NULL)
+				THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+			ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+			END AS c46,
+		T3."zip_code" AS c47,
+		CASE 
+			WHEN (T4."description" = 'Ford')
+				THEN ('1')
+			WHEN (T4."description" = 'Nissan')
+				THEN ('3')
+			WHEN (T4."description" = 'Suzuki')
+				THEN ('2')
+			ELSE ('9')
+			END AS c48,
+		CASE 
+			WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('1', '6'))
+				THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+			WHEN (T6."type" IN (40, 41, 44, 45, 46, 47, 48, 49, 88, 89, 50, 90))
+				THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+			WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('2'))
+				THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+			WHEN (T6."type" IN (42, 92))
+				THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+			WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('3'))
+				THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+			WHEN (T6."type" IN (43, 93))
+				THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+			ELSE NULL
+			END AS c49,
+		(substring((substring((convert(VARCHAR(50), T1."vehicle_number")), 1, 5)) + ' - ' + T5."description", 1, 100)) AS c50,
+		(substring((upper(T5."description")), 1, 3)) AS c51,
+		T5."description" AS c52,
+		T4."description" AS c53,
+		CASE 
+			WHEN (T1."invoice_type" = 6)
+				THEN ('GWL')
+			WHEN (
+					(T1."invoice_type" = 4)
+					OR (T3."customer_number" = 100001)
+					)
+				THEN ('intern')
+			ELSE ('extern')
+			END AS c54,
+		T2."Serviceberater" AS c55,
+		'0' + (convert(VARCHAR(50), T1."subsidiary")) AS c56,
+		CASE 
+			WHEN ((substring((convert(VARCHAR(50), T1."invoice_number")), 1, 1)) = '2')
+				THEN ('15')
+			ELSE ('1')
+			END AS c57,
+		(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + '_' + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) AS c58,
+		T1."vehicle_number" AS c59,
+		T1."is_canceled" AS c60,
+		T1."service_date" AS c61,
+		T1."invoice_date" AS c62,
+		T1."subsidiary" AS c63,
+		T1."invoice_number" AS c64,
+		T1."invoice_type" AS c65
+	FROM "ims"."ben_AW_Order_Number" T9,
+		(
+			(
+				(
+					(
+						(
+							(
+								(
+									(
+										"dbo"."invoices" T1 LEFT OUTER JOIN "dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."paying_customer"
+										) LEFT OUTER JOIN "dbo"."vehicles" T10 ON T1."vehicle_number" = T10."internal_number"
+									) LEFT OUTER JOIN "dbo"."makes" T4 ON T10."make_number" = T4."make_number"
+								) LEFT OUTER JOIN "dbo"."models" T5 ON (T10."make_number" = T5."make_number")
+								AND (T10."model_code" = T5."model_code")
+							) LEFT OUTER JOIN "dbo"."labours" T7 ON (T7."invoice_number" = T1."invoice_number")
+							AND (T7."invoice_type" = T1."invoice_type")
+						) LEFT OUTER JOIN "dbo"."charge_type_descriptions" T6 ON T6."type" = T7."charge_type"
+					) LEFT OUTER JOIN "dbo"."employees" T8 ON T1."creating_employee" = T8."employee_number"
+				) LEFT OUTER JOIN "ims"."Serviceberater_Rechnung" T2 ON T1."invtype_invnr" = T2."invtype_invnr"
+			)
+	WHERE (T7."order_number" = T9."order_number")
+		AND (
+			(
+				(
+					(T1."invoice_type" BETWEEN 2 AND 6)
+					AND (T1."is_canceled" <> 1)
+					)
+				AND (T1."invoice_date" >= convert(DATE, '2017-01-01'))
+				)
+			AND (
+				(((convert(FLOAT, T7."time_units"))) <> 0)
+				AND (((convert(FLOAT, T7."time_units"))) IS NOT NULL)
+				)
+			)
+	) D1
+	-- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 74 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_0.sql

@@ -0,0 +1,74 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[aftersales_rechnungen_neu_0]
+AS
+SELECT CAST([Hauptbetrieb_ID] AS VARCHAR(100)) AS [Hauptbetrieb_ID],
+	CAST([Hauptbetrieb_Name] AS VARCHAR(100)) AS [Hauptbetrieb_Name],
+	CAST([Standort_ID] AS VARCHAR(100)) AS [Standort_ID],
+	CAST([Standort_Name] AS VARCHAR(100)) AS [Standort_Name],
+	CAST([Employee_Function] AS VARCHAR(100)) AS [Employee_Function],
+	CAST([Serviceberater] AS VARCHAR(100)) AS [Serviceberater],
+	CAST([Order_Number] AS VARCHAR(100)) AS [Order_Number],
+	CAST([Invoice_Desc_100] AS VARCHAR(100)) AS [Invoice_Desc_100],
+	CAST([Fabrikat] AS VARCHAR(100)) AS [Fabrikat],
+	CAST([Fabrikat_Order_By] AS INT) AS [Fabrikat_Order_By],
+	CAST([Model] AS VARCHAR(100)) AS [Model],
+	CAST([Fahrzeug] AS VARCHAR(100)) AS [Fahrzeug],
+	CAST([Kostenstelle] AS VARCHAR(100)) AS [Kostenstelle],
+	CAST([Marke] AS VARCHAR(100)) AS [Marke],
+	CAST([Umsatzart] AS VARCHAR(100)) AS [Umsatzart],
+	CAST([Auftragsart] AS VARCHAR(100)) AS [Auftragsart],
+	CAST([Auftragsposition] AS VARCHAR(100)) AS [Auftragsposition],
+	CAST([Kundenart] AS VARCHAR(100)) AS [Kundenart],
+	CAST([Kunde] AS VARCHAR(100)) AS [Kunde],
+	CAST([Order_Desc_30] AS VARCHAR(100)) AS [Order_Desc_30],
+	CAST([Invoice_Desc_30] AS VARCHAR(100)) AS [Invoice_Desc_30],
+	CAST([c22] AS VARCHAR(100)) AS [c22],
+	CAST([Produktbuchungsgruppe] AS VARCHAR(100)) AS [Produktbuchungsgruppe],
+	CAST([FZG_Altersstaffel] AS VARCHAR(100)) AS [FZG_Altersstaffel],
+	CAST([Repair_Group_Desc] AS VARCHAR(100)) AS [Repair_Group_Desc],
+	CAST([DB1____EK] AS VARCHAR(100)) AS [DB1____EK],
+	CAST([Rechnung_Gutschrift] AS VARCHAR(100)) AS [Rechnung_Gutschrift],
+	CAST([Parts_Focus_Group] AS VARCHAR(100)) AS [Parts_Focus_Group],
+	CAST([Parts_Make_Desc] AS VARCHAR(100)) AS [Parts_Make_Desc],
+	CAST([Parts_Group_Desc] AS VARCHAR(100)) AS [Parts_Group_Desc],
+	CAST([PLZ_1_Stelle] AS VARCHAR(100)) AS [PLZ_1_Stelle],
+	CAST([PLZ_2_Stelle] AS VARCHAR(100)) AS [PLZ_2_Stelle],
+	CAST([PLZ_3_Stelle] AS VARCHAR(100)) AS [PLZ_3_Stelle],
+	CAST([PLZ_4_Stelle] AS VARCHAR(100)) AS [PLZ_4_Stelle],
+	CAST([PLZ] AS VARCHAR(100)) AS [PLZ],
+	CAST([Zuordnung_Funktion] AS VARCHAR(100)) AS [Zuordnung_Funktion],
+	CAST([Order_Desc_100] AS VARCHAR(100)) AS [Order_Desc_100],
+	CAST(ROUND(ISNULL([Lohn], 0), 8) AS NUMERIC(19, 8)) AS [Lohn],
+	CAST(ROUND(ISNULL([Teile], 0), 8) AS NUMERIC(19, 8)) AS [Teile],
+	CAST(ROUND(ISNULL([EW_Teile], 0), 8) AS NUMERIC(19, 8)) AS [EW_Teile],
+	CAST(ROUND(ISNULL([Sonst_], 0), 8) AS NUMERIC(19, 8)) AS [Sonst_],
+	CAST(ROUND(ISNULL([TÜV], 0), 8) AS NUMERIC(19, 8)) AS [TÜV],
+	CAST(ROUND(ISNULL([Fremdl_], 0), 8) AS NUMERIC(19, 8)) AS [Fremdl_],
+	CAST(ROUND(ISNULL([Mietw_], 0), 8) AS NUMERIC(19, 8)) AS [Mietw_],
+	CAST(ROUND(ISNULL([Rädereinl_], 0), 8) AS NUMERIC(19, 8)) AS [Rädereinl_],
+	CAST(ROUND(ISNULL([verk__Std_], 0), 8) AS NUMERIC(19, 8)) AS [verk__Std_],
+	CAST(ROUND(ISNULL([ben__Std_], 0), 8) AS NUMERIC(19, 8)) AS [ben__Std_],
+	CAST(ROUND(ISNULL([NL_Lohn], 0), 8) AS NUMERIC(19, 8)) AS [NL_Lohn],
+	CAST(ROUND(ISNULL([NL_Teile], 0), 8) AS NUMERIC(19, 8)) AS [NL_Teile],
+	CAST(ROUND(ISNULL([NL_Sonst_], 0), 8) AS NUMERIC(19, 8)) AS [NL_Sonst_],
+	CAST(ROUND(ISNULL([DG], 0), 8) AS NUMERIC(19, 8)) AS [DG],
+	CAST(ROUND(ISNULL([NL_Sonst__], 0), 8) AS NUMERIC(19, 8)) AS [NL_Sonst__],
+	CAST(ROUND(ISNULL([Anz__AT], 0), 8) AS NUMERIC(19, 8)) AS [Anz__AT],
+	CAST(ROUND(ISNULL([Anwesenheit_Mech_Karo_Lack], 0), 8) AS NUMERIC(19, 8)) AS [Anwesenheit_Mech_Karo_Lack],
+	CAST(ROUND(ISNULL([Anwesenheit_Meister], 0), 8) AS NUMERIC(19, 8)) AS [Anwesenheit_Meister],
+	CAST([Invoice_Date] AS DATETIME) AS [Invoice_Date],
+	CAST([Rechnungsausgang] AS VARCHAR(100)) AS [Rechnungsausgang],
+	CAST(ROUND(ISNULL([EW_Fremdl_], 0), 8) AS NUMERIC(19, 8)) AS [EW_Fremdl_],
+	CAST([Serviceberater_Rg_Steller] AS VARCHAR(100)) AS [Serviceberater_Rg_Steller]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_neu_11]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 141 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_11.sql

@@ -0,0 +1,141 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_neu_11]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
+	"GC_Department"."Standort_ID" AS "Standort_ID",
+	"GC_Department"."Standort_Name" AS "Standort_Name",
+	'Serviceberater' AS "Employee_Function",
+	"Aftersales_Rechnungen_neu"."Serviceberater" AS "Serviceberater",
+	"Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121) AS "Order_Number",
+	'' AS "Invoice_Desc_100",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By",
+	"Aftersales_Rechnungen_neu"."Model" AS "Model",
+	"Aftersales_Rechnungen_neu"."Fahrzeug" AS "Fahrzeug",
+	"Aftersales_Rechnungen_neu"."Kostenstelle" AS "Kostenstelle",
+	"Aftersales_Rechnungen_neu"."Marke" AS "Marke",
+	"Aftersales_Rechnungen_neu"."Umsatzart" AS "Umsatzart",
+	"Aftersales_Rechnungen_neu"."Auftragsart" AS "Auftragsart",
+	'' AS "Auftragsposition",
+	"Aftersales_Rechnungen_neu"."Kundenart" AS "Kundenart",
+	"Aftersales_Rechnungen_neu"."Kunde" AS "Kunde",
+	CASE 
+		WHEN datediff(dd, "Aftersales_Rechnungen_neu"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Order_Desc_30",
+	'' AS "Invoice_Desc_30",
+	"GC_Produktbuchungsgruppen"."Zuordnung" AS "c22",
+	"Aftersales_Rechnungen_neu"."Kostenstelle" AS "Produktbuchungsgruppe",
+	'' AS "FZG_Altersstaffel",
+	'' AS "Repair_Group_Desc",
+	'' AS "DB1____EK",
+	'' AS "Rechnung_Gutschrift",
+	'' AS "Parts_Focus_Group",
+	'' AS "Parts_Make_Desc",
+	'' AS "Parts_Group_Desc",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 1) AS "PLZ_1_Stelle",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 2) AS "PLZ_2_Stelle",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 3) AS "PLZ_3_Stelle",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 4) AS "PLZ_4_Stelle",
+	"Aftersales_Rechnungen_neu"."Free Form Accounting Text" AS "PLZ",
+	'Serviceberater' AS "Zuordnung_Funktion",
+	CASE 
+		WHEN datediff(dd, "Aftersales_Rechnungen_neu"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 100
+			THEN "Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121)
+		ELSE 'älter 100 Tage'
+		END AS "Order_Desc_100",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz Lohn'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Lohn",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz Teile'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Teile",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Einsatz Teile'
+			THEN "Aftersales_Rechnungen_neu"."Betrag"
+		ELSE 0
+		END AS "EW_Teile",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz Sonst.'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Sonst_",
+	0 AS "TÜV",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz FL'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Fremdl_",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz MW'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Mietw_",
+	0 AS "Rädereinl_",
+	0 AS "verk__Std_",
+	0 AS "ben__Std_",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'NL Lohn'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "NL_Lohn",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'NL Teile'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "NL_Teile",
+	0 AS "NL_Sonst_",
+	"Aftersales_Rechnungen_neu"."DG" AS "DG",
+	0 AS "NL_Sonst__",
+	0 AS "Anz__AT",
+	'' AS "Anwesenheit_Mech_Karo_Lack",
+	'' AS "Anwesenheit_Meister",
+	"Aftersales_Rechnungen_neu"."Invoice Date" AS "Invoice_Date",
+	CASE 
+		WHEN datediff(dd, "Aftersales_Rechnungen_neu"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Rechnungsausgang",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Einsatz FL'
+			THEN "Aftersales_Rechnungen_neu"."Betrag"
+		ELSE 0
+		END AS "EW_Fremdl_",
+	"Aftersales_Rechnungen_neu"."Serviceberater_Rg_Steller" AS "Serviceberater_Rg_Steller"
+FROM (
+	(
+		(
+			[staging].[aftersales_rechnungen_neu_80] "Aftersales_Rechnungen_neu" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "Aftersales_Rechnungen_neu"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb"
+				AND "Aftersales_Rechnungen_neu"."Standort" = "GC_Department"."Standort"
+			) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "Aftersales_Rechnungen_neu"."Fabrikat" = "GC_Marken"."Description"
+		) LEFT OUTER JOIN "GC"."data"."GC_Produktbuchungsgruppen" "GC_Produktbuchungsgruppen" ON "Aftersales_Rechnungen_neu"."Kostenstelle" = "GC_Produktbuchungsgruppen"."Produktbuchungsgruppe"
+	)
+LEFT OUTER JOIN [staging].[kontenrahmen_gc_struct_skr_80] "Kontenrahmen_GC_Struct_SKR" ON "Aftersales_Rechnungen_neu"."Contra Account Text" = "Kontenrahmen_GC_Struct_SKR"."Konto Nr"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 151 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_80.sql

@@ -0,0 +1,151 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_neu_80]
+AS
+SELECT c254 AS "Invoice Type",
+	c253 AS "Type_Invoice_Types",
+	c252 AS "Description_Invoice_Types",
+	c251 AS "Invoice Number",
+	c250 AS "Subsidiary",
+	c249 AS "Paying Customer",
+	c248 AS "Order Customer",
+	c247 AS "Invoice Date",
+	c246 AS "Service Date",
+	c245 AS "Is Canceled",
+	c244 AS "Cancelation Number",
+	c243 AS "Cancelation Date",
+	c242 AS "Cancelation Employee",
+	c241 AS "Is Own Vehicle",
+	c240 AS "Is Credit",
+	c239 AS "Credit Invoice Type",
+	c238 AS "Credit Invoice Number",
+	c237 AS "Odometer Reading",
+	c236 AS "Creating Employee",
+	c235 AS "Internal Cost Account",
+	c234 AS "Vehicle Number",
+	c233 AS "Full Vat Basevalue",
+	c232 AS "Full Vat Percentage",
+	c231 AS "Full Vat Value",
+	c230 AS "Reduced Vat Basevalue",
+	c229 AS "Reduced Vat Percentage",
+	c228 AS "Reduced Vat Value",
+	c227 AS "Used Part Vat Value",
+	c226 AS "Job Amount Net",
+	c225 AS "Job Amount Gross",
+	c224 AS "Job Rebate",
+	c223 AS "Part Amount Net",
+	c222 AS "Part Amount Gross",
+	c221 AS "Part Rebate",
+	c220 AS "Part Disposal",
+	c219 AS "Total Gross",
+	c218 AS "Total Net",
+	c217 AS "Inv_Type_Invoice_Number",
+	c172 AS "Accounting Date",
+	c216 AS "Document Type",
+	c215 AS "Document Number",
+	c214 AS "Position In Document",
+	c213 AS "Customer Number",
+	c212 AS "Nominal Account Number",
+	c211 AS "Is Balanced",
+	c210 AS "Clearing Number",
+	c209 AS "Document Date",
+	c208 AS "Posted Value",
+	c207 AS "Debit Or Credit",
+	c206 AS "Posted Count",
+	c205 AS "Branch Number",
+	c204 AS "Customer Contra Account",
+	c203 AS "Nominal Contra Account",
+	c202 AS "Contra Account Text",
+	c201 AS "Account Form Page Number",
+	c200 AS "Account Form Page Line",
+	c199 AS "Serial Number Each Month",
+	c198 AS "Employee Number",
+	c197 AS "Invoice Date_falsch",
+	c196 AS "Invoice Number_1",
+	c195 AS "Dunning Level",
+	c194 AS "Last Dunning Date",
+	c193 AS "Journal Page",
+	c192 AS "Journal Line",
+	c191 AS "Cash Discount",
+	c190 AS "Term Of Payment",
+	c189 AS "Posting Text",
+	c188 AS "Vehicle Reference",
+	c187 AS "Vat Id Number",
+	c186 AS "Account Statement Number",
+	c185 AS "Account Statement Page",
+	c184 AS "Vat Key",
+	c183 AS "Days For Cash Discount",
+	c182 AS "Day Of Actual Accounting",
+	c181 AS "Skr51 Branch",
+	c158 AS "Skr51 Make",
+	c180 AS "Skr51 Cost Center",
+	c179 AS "Skr51 Sales Channel",
+	c178 AS "Skr51 Cost Unit",
+	c177 AS "Previously Used Account No",
+	c176 AS "Free Form Accounting Text",
+	c175 AS "Free Form Document Text",
+	c174 AS "Hauptbetrieb",
+	c173 AS "Standort",
+	c172 AS "Invoice Date_accounting",
+	c171 AS "Employee Number_Employees",
+	c170 AS "Name_Employees",
+	c169 AS "Mechanic Number_Employees",
+	c168 AS "Salesman Number_Employees",
+	c167 AS "Is Business Executive_Employees",
+	c166 AS "Is Master Craftsman_Employees",
+	c165 AS "Serviceberater_Rg_Steller",
+	c164 AS "Customer Number_Customers_Suppliers",
+	c163 AS "First Name_Customers_Suppliers",
+	c162 AS "Family Name_Customers_Suppliers",
+	c161 AS "Kunde",
+	c160 AS "Betrag",
+	c159 AS "Kostenstelle",
+	c158 AS "Marke",
+	c157 AS "Kundenart",
+	c156 AS "KST_1_Stelle",
+	c155 AS "Umsatzart",
+	c154 AS "Auftragsart",
+	'' AS "Geschäftsart",
+	c153 AS "Make Number",
+	c152 AS "Free Form Make Text",
+	c151 AS "Model Code",
+	c150 AS "Free Form Model Text",
+	c149 AS "Description_Makes",
+	c148 AS "Description_Models",
+	c149 AS "Fabrikat",
+	c148 AS "Model_Detail",
+	c147 AS "Model",
+	(0) AS "Umsatz Lohn",
+	(0) AS "Umsatz FL",
+	(0) AS "Einsatz FL",
+	(0) AS "Umsatz Teile",
+	(0) AS "Einsatz Teile",
+	(0) AS "Umsatz MW",
+	(0) AS "Einsatz MW",
+	(0) AS "Umsatz Sonst.",
+	(0) AS "Einsatz Sonst.",
+	1 AS "DG_1",
+	COUNT(c254) OVER (PARTITION BY c141) AS "DG_2",
+	1 / (COUNT(c254) OVER (PARTITION BY c141)) AS "DG",
+	c146 AS "Fahrzeug",
+	c141 AS "Order Number",
+	c145 AS "Invoice_Date_Uhrzeit",
+	c144 AS "Order Number_Rg_Ausg",
+	'' AS "Konto Nr",
+	'' AS "Konto Bezeichnung",
+	'' AS "Ebene1",
+	'' AS "Ebene2",
+	'' AS "Ebene3",
+	'' AS "Ebene4",
+	c143 AS "Serviceberater_order_pos",
+	c142 AS "Serviceberater"
+FROM [staging].[aftersales_rechnungen_neu_90]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 293 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_90.sql

@@ -0,0 +1,293 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_neu_90]
+AS
+SELECT (
+		CASE 
+			WHEN (
+					(
+						CASE 
+							WHEN (T1."invoice_type" = 5)
+								THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+							ELSE (T10."Serviceberater")
+							END
+						) IS NOT NULL
+					)
+				THEN (
+						((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+							CASE 
+								WHEN (T1."invoice_type" = 5)
+									THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+								ELSE (T10."Serviceberater")
+								END
+							) + ' - ' + (
+							CASE 
+								WHEN (T4."first_name" IS NULL)
+									THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+								ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+								END
+							)
+						)
+			ELSE (
+					((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+						CASE 
+							WHEN (T4."first_name" IS NULL)
+								THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+							ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+							END
+						)
+					)
+			END
+		) AS c141,
+	CASE 
+		WHEN (T1."invoice_type" = 5)
+			THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+		ELSE (T10."Serviceberater")
+		END AS c142,
+	T10."Serviceberater" AS c143,
+	CASE 
+		WHEN ((day((getdate()) - ((convert(DATETIME, T1."invoice_date"))))) <= 4)
+			THEN (
+					(
+						CASE 
+							WHEN (
+									(
+										CASE 
+											WHEN (T1."invoice_type" = 5)
+												THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+											ELSE (T10."Serviceberater")
+											END
+										) IS NOT NULL
+									)
+								THEN (
+										((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+											CASE 
+												WHEN (T1."invoice_type" = 5)
+													THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+												ELSE (T10."Serviceberater")
+												END
+											) + ' - ' + (
+											CASE 
+												WHEN (T4."first_name" IS NULL)
+													THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+												ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+												END
+											)
+										)
+							ELSE (
+									((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+										CASE 
+											WHEN (T4."first_name" IS NULL)
+												THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+											ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+											END
+										)
+									)
+							END
+						)
+					)
+		ELSE NULL
+		END AS c144,
+	(convert(DATETIME, T1."invoice_date")) AS c145,
+	(substring((substring((convert(VARCHAR(50), T1."vehicle_number")), 1, 5)) + ' - ' + T9."description", 1, 100)) AS c146,
+	(substring((upper(T9."description")), 1, 3)) AS c147,
+	T9."description" AS c148,
+	T8."description" AS c149,
+	T7."free_form_model_text" AS c150,
+	T7."model_code" AS c151,
+	T7."free_form_make_text" AS c152,
+	T7."make_number" AS c153,
+	CASE 
+		WHEN (T1."invoice_type" = 5)
+			THEN ('Teile')
+		ELSE ('Service')
+		END AS c154,
+	CASE 
+		WHEN (T1."invoice_type" = 6)
+			THEN ('GWL')
+		WHEN (
+				(T1."invoice_type" = 4)
+				OR (T4."customer_number" IN (1000000, 1000001, 1000002, 1000003, 1000010))
+				)
+			THEN ('intern')
+		ELSE ('extern')
+		END AS c155,
+	(substring(((rtrim((convert(VARCHAR(50), T3."skr51_cost_center")))) + ' - ' + T6."skr51_cost_center_name"), 1, 1)) AS c156,
+	(rtrim((convert(VARCHAR(50), T3."skr51_sales_channel")))) + ' - ' + T6."skr51_sales_channel_name" AS c157,
+	T3."skr51_make" AS c158,
+	(rtrim((convert(VARCHAR(50), T3."skr51_cost_center")))) + ' - ' + T6."skr51_cost_center_name" AS c159,
+	CASE 
+		WHEN (T3."debit_or_credit" = 'H')
+			THEN (((T3."posted_value")) / 100 * - 1)
+		ELSE (((T3."posted_value")) / 100)
+		END AS c160,
+	CASE 
+		WHEN (T4."first_name" IS NULL)
+			THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+		ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+		END AS c161,
+	T4."family_name" AS c162,
+	T4."first_name" AS c163,
+	T4."customer_number" AS c164,
+	(substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name" AS c165,
+	T5."is_master_craftsman" AS c166,
+	T5."is_business_executive" AS c167,
+	T5."salesman_number" AS c168,
+	T5."mechanic_number" AS c169,
+	T5."name" AS c170,
+	T5."employee_number" AS c171,
+	T3."accounting_date" AS c172,
+	'0' + (convert(VARCHAR(50), T3."branch_number")) AS c173,
+	T3."subsidiary_to_company_ref" AS c174,
+	CASE 
+		WHEN (T3."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN ('Neuwagen')
+		WHEN (T3."skr51_cost_unit" BETWEEN 50 AND 59)
+			THEN ('Gebrauchtwagen')
+		WHEN (T3."skr51_cost_unit" BETWEEN 60 AND 69)
+			THEN ('Teile & Zubehör')
+		WHEN (T3."skr51_cost_unit" BETWEEN 70 AND 79)
+			THEN ('Service')
+		WHEN (T3."skr51_cost_unit" = 0)
+			THEN ('Ohne Kostenträger')
+		ELSE NULL
+		END AS c175,
+	T4."zip_code" AS c176,
+	T3."previously_used_account_no" AS c177,
+	T3."skr51_cost_unit" AS c178,
+	T3."skr51_sales_channel" AS c179,
+	T3."skr51_cost_center" AS c180,
+	T3."skr51_branch" AS c181,
+	T3."day_of_actual_accounting" AS c182,
+	T3."days_for_cash_discount" AS c183,
+	T3."vat_key" AS c184,
+	T3."account_statement_page" AS c185,
+	T3."account_statement_number" AS c186,
+	T3."vat_id_number" AS c187,
+	T3."vehicle_reference" AS c188,
+	T3."posting_text" AS c189,
+	T3."term_of_payment" AS c190,
+	T3."cash_discount" AS c191,
+	T3."journal_line" AS c192,
+	T3."journal_page" AS c193,
+	T3."last_dunning_date" AS c194,
+	T3."dunning_level" AS c195,
+	T3."invoice_number" AS c196,
+	T3."invoice_date" AS c197,
+	T3."employee_number" AS c198,
+	T3."serial_number_each_month" AS c199,
+	T3."account_form_page_line" AS c200,
+	T3."account_form_page_number" AS c201,
+	CASE 
+		WHEN (T3."nominal_account_number" = 5701)
+			THEN ((rtrim((convert(VARCHAR(50), T3."nominal_account_number")))) + '_' + (rtrim((convert(VARCHAR(50), T3."skr51_cost_center")))))
+		ELSE ((rtrim((convert(VARCHAR(50), T3."nominal_account_number")))))
+		END AS c202,
+	T3."nominal_contra_account" AS c203,
+	T3."customer_contra_account" AS c204,
+	T3."branch_number" AS c205,
+	T3."posted_count" AS c206,
+	T3."debit_or_credit" AS c207,
+	(T3."posted_value") AS c208,
+	T3."document_date" AS c209,
+	T3."clearing_number" AS c210,
+	T3."is_balanced" AS c211,
+	T3."nominal_account_number" AS c212,
+	T3."customer_number" AS c213,
+	T3."position_in_document" AS c214,
+	T3."document_number" AS c215,
+	T3."document_type" AS c216,
+	(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) AS c217,
+	T1."total_net" AS c218,
+	T1."total_gross" AS c219,
+	T1."part_disposal" AS c220,
+	T1."part_rebate" AS c221,
+	T1."part_amount_gross" AS c222,
+	T1."part_amount_net" AS c223,
+	T1."job_rebate" AS c224,
+	T1."job_amount_gross" AS c225,
+	T1."job_amount_net" AS c226,
+	T1."used_part_vat_value" AS c227,
+	T1."reduced_vat_value" AS c228,
+	T1."reduced_vat_percentage" AS c229,
+	T1."reduced_vat_basevalue" AS c230,
+	T1."full_vat_value" AS c231,
+	T1."full_vat_percentage" AS c232,
+	T1."full_vat_basevalue" AS c233,
+	T1."vehicle_number" AS c234,
+	T1."internal_cost_account" AS c235,
+	T1."creating_employee" AS c236,
+	T1."odometer_reading" AS c237,
+	T1."credit_invoice_number" AS c238,
+	T1."credit_invoice_type" AS c239,
+	T1."is_credit" AS c240,
+	T1."is_own_vehicle" AS c241,
+	T1."cancelation_employee" AS c242,
+	T1."cancelation_date" AS c243,
+	T1."cancelation_number" AS c244,
+	T1."is_canceled" AS c245,
+	T1."service_date" AS c246,
+	T1."invoice_date" AS c247,
+	T1."order_customer" AS c248,
+	T1."paying_customer" AS c249,
+	T1."subsidiary" AS c250,
+	T1."invoice_number" AS c251,
+	T2."description" AS c252,
+	T2."type" AS c253,
+	T1."invoice_type" AS c254
+FROM (
+	(
+		(
+			(
+				(
+					(
+						(
+							(
+								(
+									"dbo"."invoices" T1 LEFT OUTER JOIN "dbo"."invoice_types" T2 ON T2."type" = T1."invoice_type"
+									) LEFT OUTER JOIN "dbo"."journal_accountings" T3 ON T3."invoice_number" = T1."invtype_invnr"
+								) LEFT OUTER JOIN "dbo"."customers_suppliers" T4 ON T4."customer_number" = T1."paying_customer"
+							) LEFT OUTER JOIN "dbo"."employees" T5 ON T1."creating_employee" = T5."employee_number"
+						) LEFT OUTER JOIN "dbo"."accounts_characteristics" T6 ON (
+							(
+								(
+									(
+										(T6."skr51_branch" = T3."skr51_branch")
+										AND (T6."skr51_make" = T3."skr51_make")
+										)
+									AND (T6."skr51_cost_center" = T3."skr51_cost_center")
+									)
+								AND (T6."skr51_sales_channel" = T3."skr51_sales_channel")
+								)
+							AND (T6."skr51_cost_unit" = T3."skr51_cost_unit")
+							)
+						AND (T6."subsidiary_to_company_ref" = T3."subsidiary_to_company_ref")
+					) LEFT OUTER JOIN "dbo"."vehicles" T7 ON T1."vehicle_number" = T7."internal_number"
+				) LEFT OUTER JOIN "dbo"."makes" T8 ON T7."make_number" = T8."make_number"
+			) LEFT OUTER JOIN "dbo"."models" T9 ON (T7."make_number" = T9."make_number")
+			AND (T7."model_code" = T9."model_code")
+		) LEFT OUTER JOIN "ims"."Serviceberater_Rechnung" T10 ON T1."invtype_invnr" = T10."invtype_invnr"
+	)
+WHERE (
+		(
+			(
+				(
+					(T1."invoice_type" BETWEEN 2 AND 6)
+					AND ((substring((convert(VARCHAR(50), T3."nominal_account_number")), 1, 1)) IN ('4', '5', '7', '8'))
+					)
+				AND (T1."invoice_date" >= convert(DATE, '2019-01-01'))
+				)
+			AND (T1."is_canceled" <> 1)
+			)
+		AND (((len((rtrim((convert(VARCHAR(50), T3."nominal_account_number"))))))) = 4)
+		)
+	-- order by c141 asc,c215 asc,c214 asc,c217 asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 141 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_fm.sql

@@ -0,0 +1,141 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_neu_fm]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
+	"GC_Department"."Standort_ID" AS "Standort_ID",
+	"GC_Department"."Standort_Name" AS "Standort_Name",
+	'Serviceberater' AS "Employee_Function",
+	"Aftersales_Rechnungen_neu"."Serviceberater" AS "Serviceberater",
+	"Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121) AS "Order_Number",
+	'' AS "Invoice_Desc_100",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By",
+	"Aftersales_Rechnungen_neu"."Model" AS "Model",
+	"Aftersales_Rechnungen_neu"."Fahrzeug" AS "Fahrzeug",
+	"Aftersales_Rechnungen_neu"."Kostenstelle" AS "Kostenstelle",
+	"Aftersales_Rechnungen_neu"."Marke" AS "Marke",
+	"Aftersales_Rechnungen_neu"."Umsatzart" AS "Umsatzart",
+	"Aftersales_Rechnungen_neu"."Auftragsart" AS "Auftragsart",
+	'' AS "Auftragsposition",
+	"Aftersales_Rechnungen_neu"."Kundenart" AS "Kundenart",
+	"Aftersales_Rechnungen_neu"."Kunde" AS "Kunde",
+	CASE 
+		WHEN datediff(dd, "Aftersales_Rechnungen_neu"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Order_Desc_30",
+	'' AS "Invoice_Desc_30",
+	"GC_Produktbuchungsgruppen"."Zuordnung" AS "c22",
+	"Aftersales_Rechnungen_neu"."Kostenstelle" AS "Produktbuchungsgruppe",
+	'' AS "FZG_Altersstaffel",
+	'' AS "Repair_Group_Desc",
+	'' AS "DB1____EK",
+	'' AS "Rechnung_Gutschrift",
+	'' AS "Parts_Focus_Group",
+	'' AS "Parts_Make_Desc",
+	'' AS "Parts_Group_Desc",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 1) AS "PLZ_1_Stelle",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 2) AS "PLZ_2_Stelle",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 3) AS "PLZ_3_Stelle",
+	left("Aftersales_Rechnungen_neu"."Free Form Accounting Text", 4) AS "PLZ_4_Stelle",
+	"Aftersales_Rechnungen_neu"."Free Form Accounting Text" AS "PLZ",
+	'Serviceberater' AS "Zuordnung_Funktion",
+	CASE 
+		WHEN datediff(dd, "Aftersales_Rechnungen_neu"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 100
+			THEN "Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121)
+		ELSE 'älter 100 Tage'
+		END AS "Order_Desc_100",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz Lohn'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Lohn",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz Teile'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Teile",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Einsatz Teile'
+			THEN "Aftersales_Rechnungen_neu"."Betrag"
+		ELSE 0
+		END AS "EW_Teile",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz Sonst.'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Sonst_",
+	0 AS "TÜV",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz FL'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Fremdl_",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Umsatz MW'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "Mietw_",
+	0 AS "Rädereinl_",
+	0 AS "verk__Std_",
+	0 AS "ben__Std_",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'NL Lohn'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "NL_Lohn",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'NL Teile'
+			THEN "Aftersales_Rechnungen_neu"."Betrag" * - 1
+		ELSE 0
+		END AS "NL_Teile",
+	0 AS "NL_Sonst_",
+	"Aftersales_Rechnungen_neu"."DG" AS "DG",
+	0 AS "NL_Sonst__",
+	0 AS "Anz__AT",
+	'' AS "Anwesenheit_Mech_Karo_Lack",
+	'' AS "Anwesenheit_Meister",
+	"Aftersales_Rechnungen_neu"."Invoice Date" AS "Invoice_Date",
+	CASE 
+		WHEN datediff(dd, "Aftersales_Rechnungen_neu"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "Aftersales_Rechnungen_neu"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "Aftersales_Rechnungen_neu"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Rechnungsausgang",
+	CASE 
+		WHEN "Kontenrahmen_GC_Struct_SKR"."Konto 2" = 'Einsatz FL'
+			THEN "Aftersales_Rechnungen_neu"."Betrag"
+		ELSE 0
+		END AS "EW_Fremdl_",
+	"Aftersales_Rechnungen_neu"."Serviceberater_Rg_Steller" AS "Serviceberater_Rg_Steller"
+FROM (
+	(
+		(
+			"GC"."locosoft"."Aftersales_Rechnungen_neu" "Aftersales_Rechnungen_neu" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "Aftersales_Rechnungen_neu"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb"
+				AND "Aftersales_Rechnungen_neu"."Standort" = "GC_Department"."Standort"
+			) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "Aftersales_Rechnungen_neu"."Fabrikat" = "GC_Marken"."Description"
+		) LEFT OUTER JOIN "GC"."data"."GC_Produktbuchungsgruppen" "GC_Produktbuchungsgruppen" ON "Aftersales_Rechnungen_neu"."Kostenstelle" = "GC_Produktbuchungsgruppen"."Produktbuchungsgruppe"
+	)
+LEFT OUTER JOIN "GC"."locosoft"."Kontenrahmen_GC_Struct_SKR" "Kontenrahmen_GC_Struct_SKR" ON "Aftersales_Rechnungen_neu"."Contra Account Text" = "Kontenrahmen_GC_Struct_SKR"."Konto Nr"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 432 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_neu_imr.sql

@@ -0,0 +1,432 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_neu_imr]
+AS
+SELECT c254 AS "Invoice Type",
+	c253 AS "Type_Invoice_Types",
+	c252 AS "Description_Invoice_Types",
+	c251 AS "Invoice Number",
+	c250 AS "Subsidiary",
+	c249 AS "Paying Customer",
+	c248 AS "Order Customer",
+	c247 AS "Invoice Date",
+	c246 AS "Service Date",
+	c245 AS "Is Canceled",
+	c244 AS "Cancelation Number",
+	c243 AS "Cancelation Date",
+	c242 AS "Cancelation Employee",
+	c241 AS "Is Own Vehicle",
+	c240 AS "Is Credit",
+	c239 AS "Credit Invoice Type",
+	c238 AS "Credit Invoice Number",
+	c237 AS "Odometer Reading",
+	c236 AS "Creating Employee",
+	c235 AS "Internal Cost Account",
+	c234 AS "Vehicle Number",
+	c233 AS "Full Vat Basevalue",
+	c232 AS "Full Vat Percentage",
+	c231 AS "Full Vat Value",
+	c230 AS "Reduced Vat Basevalue",
+	c229 AS "Reduced Vat Percentage",
+	c228 AS "Reduced Vat Value",
+	c227 AS "Used Part Vat Value",
+	c226 AS "Job Amount Net",
+	c225 AS "Job Amount Gross",
+	c224 AS "Job Rebate",
+	c223 AS "Part Amount Net",
+	c222 AS "Part Amount Gross",
+	c221 AS "Part Rebate",
+	c220 AS "Part Disposal",
+	c219 AS "Total Gross",
+	c218 AS "Total Net",
+	c217 AS "Inv_Type_Invoice_Number",
+	c172 AS "Accounting Date",
+	c216 AS "Document Type",
+	c215 AS "Document Number",
+	c214 AS "Position In Document",
+	c213 AS "Customer Number",
+	c212 AS "Nominal Account Number",
+	c211 AS "Is Balanced",
+	c210 AS "Clearing Number",
+	c209 AS "Document Date",
+	c208 AS "Posted Value",
+	c207 AS "Debit Or Credit",
+	c206 AS "Posted Count",
+	c205 AS "Branch Number",
+	c204 AS "Customer Contra Account",
+	c203 AS "Nominal Contra Account",
+	c202 AS "Contra Account Text",
+	c201 AS "Account Form Page Number",
+	c200 AS "Account Form Page Line",
+	c199 AS "Serial Number Each Month",
+	c198 AS "Employee Number",
+	c197 AS "Invoice Date_falsch",
+	c196 AS "Invoice Number_1",
+	c195 AS "Dunning Level",
+	c194 AS "Last Dunning Date",
+	c193 AS "Journal Page",
+	c192 AS "Journal Line",
+	c191 AS "Cash Discount",
+	c190 AS "Term Of Payment",
+	c189 AS "Posting Text",
+	c188 AS "Vehicle Reference",
+	c187 AS "Vat Id Number",
+	c186 AS "Account Statement Number",
+	c185 AS "Account Statement Page",
+	c184 AS "Vat Key",
+	c183 AS "Days For Cash Discount",
+	c182 AS "Day Of Actual Accounting",
+	c181 AS "Skr51 Branch",
+	c158 AS "Skr51 Make",
+	c180 AS "Skr51 Cost Center",
+	c179 AS "Skr51 Sales Channel",
+	c178 AS "Skr51 Cost Unit",
+	c177 AS "Previously Used Account No",
+	c176 AS "Free Form Accounting Text",
+	c175 AS "Free Form Document Text",
+	c174 AS "Hauptbetrieb",
+	c173 AS "Standort",
+	c172 AS "Invoice Date_accounting",
+	c171 AS "Employee Number_Employees",
+	c170 AS "Name_Employees",
+	c169 AS "Mechanic Number_Employees",
+	c168 AS "Salesman Number_Employees",
+	c167 AS "Is Business Executive_Employees",
+	c166 AS "Is Master Craftsman_Employees",
+	c165 AS "Serviceberater_Rg_Steller",
+	c164 AS "Customer Number_Customers_Suppliers",
+	c163 AS "First Name_Customers_Suppliers",
+	c162 AS "Family Name_Customers_Suppliers",
+	c161 AS "Kunde",
+	c160 AS "Betrag",
+	c159 AS "Kostenstelle",
+	c158 AS "Marke",
+	c157 AS "Kundenart",
+	c156 AS "KST_1_Stelle",
+	c155 AS "Umsatzart",
+	c154 AS "Auftragsart",
+	'' AS "Geschäftsart",
+	c153 AS "Make Number",
+	c152 AS "Free Form Make Text",
+	c151 AS "Model Code",
+	c150 AS "Free Form Model Text",
+	c149 AS "Description_Makes",
+	c148 AS "Description_Models",
+	c149 AS "Fabrikat",
+	c148 AS "Model_Detail",
+	c147 AS "Model",
+	(0) AS "Umsatz Lohn",
+	(0) AS "Umsatz FL",
+	(0) AS "Einsatz FL",
+	(0) AS "Umsatz Teile",
+	(0) AS "Einsatz Teile",
+	(0) AS "Umsatz MW",
+	(0) AS "Einsatz MW",
+	(0) AS "Umsatz Sonst.",
+	(0) AS "Einsatz Sonst.",
+	1 AS "DG_1",
+	COUNT(c254) OVER (PARTITION BY c141) AS "DG_2",
+	1 / (COUNT(c254) OVER (PARTITION BY c141)) AS "DG",
+	c146 AS "Fahrzeug",
+	c141 AS "Order Number",
+	c145 AS "Invoice_Date_Uhrzeit",
+	c144 AS "Order Number_Rg_Ausg",
+	'' AS "Konto Nr",
+	'' AS "Konto Bezeichnung",
+	'' AS "Ebene1",
+	'' AS "Ebene2",
+	'' AS "Ebene3",
+	'' AS "Ebene4",
+	c143 AS "Serviceberater_order_pos",
+	c142 AS "Serviceberater"
+FROM (
+	SELECT (
+			CASE 
+				WHEN (
+						(
+							CASE 
+								WHEN (T1."invoice_type" = 5)
+									THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+								ELSE (T10."Serviceberater")
+								END
+							) IS NOT NULL
+						)
+					THEN (
+							((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+								CASE 
+									WHEN (T1."invoice_type" = 5)
+										THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+									ELSE (T10."Serviceberater")
+									END
+								) + ' - ' + (
+								CASE 
+									WHEN (T4."first_name" IS NULL)
+										THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+									ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+									END
+								)
+							)
+				ELSE (
+						((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+							CASE 
+								WHEN (T4."first_name" IS NULL)
+									THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+								ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+								END
+							)
+						)
+				END
+			) AS c141,
+		CASE 
+			WHEN (T1."invoice_type" = 5)
+				THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+			ELSE (T10."Serviceberater")
+			END AS c142,
+		T10."Serviceberater" AS c143,
+		CASE 
+			WHEN ((day((getdate()) - ((convert(DATETIME, T1."invoice_date"))))) <= 4)
+				THEN (
+						(
+							CASE 
+								WHEN (
+										(
+											CASE 
+												WHEN (T1."invoice_type" = 5)
+													THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+												ELSE (T10."Serviceberater")
+												END
+											) IS NOT NULL
+										)
+									THEN (
+											((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+												CASE 
+													WHEN (T1."invoice_type" = 5)
+														THEN (((substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name"))
+													ELSE (T10."Serviceberater")
+													END
+												) + ' - ' + (
+												CASE 
+													WHEN (T4."first_name" IS NULL)
+														THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+													ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+													END
+												)
+											)
+								ELSE (
+										((substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9))) + ' - ' + (
+											CASE 
+												WHEN (T4."first_name" IS NULL)
+													THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+												ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+												END
+											)
+										)
+								END
+							)
+						)
+			ELSE NULL
+			END AS c144,
+		(convert(DATETIME, T1."invoice_date")) AS c145,
+		(substring((substring((convert(VARCHAR(50), T1."vehicle_number")), 1, 5)) + ' - ' + T9."description", 1, 100)) AS c146,
+		(substring((upper(T9."description")), 1, 3)) AS c147,
+		T9."description" AS c148,
+		T8."description" AS c149,
+		T7."free_form_model_text" AS c150,
+		T7."model_code" AS c151,
+		T7."free_form_make_text" AS c152,
+		T7."make_number" AS c153,
+		CASE 
+			WHEN (T1."invoice_type" = 5)
+				THEN ('Teile')
+			ELSE ('Service')
+			END AS c154,
+		CASE 
+			WHEN (T1."invoice_type" = 6)
+				THEN ('GWL')
+			WHEN (
+					(T1."invoice_type" = 4)
+					OR (T4."customer_number" IN (1000000, 1000001, 1000002, 1000003, 1000010))
+					)
+				THEN ('intern')
+			ELSE ('extern')
+			END AS c155,
+		(substring(((rtrim((convert(VARCHAR(50), T3."skr51_cost_center")))) + ' - ' + T6."skr51_cost_center_name"), 1, 1)) AS c156,
+		(rtrim((convert(VARCHAR(50), T3."skr51_sales_channel")))) + ' - ' + T6."skr51_sales_channel_name" AS c157,
+		T3."skr51_make" AS c158,
+		(rtrim((convert(VARCHAR(50), T3."skr51_cost_center")))) + ' - ' + T6."skr51_cost_center_name" AS c159,
+		CASE 
+			WHEN (T3."debit_or_credit" = 'H')
+				THEN (((T3."posted_value")) / 100 * - 1)
+			ELSE (((T3."posted_value")) / 100)
+			END AS c160,
+		CASE 
+			WHEN (T4."first_name" IS NULL)
+				THEN ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."family_name")
+			ELSE ((substring((convert(VARCHAR(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name")
+			END AS c161,
+		T4."family_name" AS c162,
+		T4."first_name" AS c163,
+		T4."customer_number" AS c164,
+		(substring((convert(VARCHAR(50), T5."employee_number")), 1, 4)) + ' - ' + T5."name" AS c165,
+		T5."is_master_craftsman" AS c166,
+		T5."is_business_executive" AS c167,
+		T5."salesman_number" AS c168,
+		T5."mechanic_number" AS c169,
+		T5."name" AS c170,
+		T5."employee_number" AS c171,
+		T3."accounting_date" AS c172,
+		'0' + (convert(VARCHAR(50), T3."branch_number")) AS c173,
+		T3."subsidiary_to_company_ref" AS c174,
+		CASE 
+			WHEN (T3."skr51_cost_unit" BETWEEN 1 AND 49)
+				THEN ('Neuwagen')
+			WHEN (T3."skr51_cost_unit" BETWEEN 50 AND 59)
+				THEN ('Gebrauchtwagen')
+			WHEN (T3."skr51_cost_unit" BETWEEN 60 AND 69)
+				THEN ('Teile & Zubehör')
+			WHEN (T3."skr51_cost_unit" BETWEEN 70 AND 79)
+				THEN ('Service')
+			WHEN (T3."skr51_cost_unit" = 0)
+				THEN ('Ohne Kostenträger')
+			ELSE NULL
+			END AS c175,
+		T4."zip_code" AS c176,
+		T3."previously_used_account_no" AS c177,
+		T3."skr51_cost_unit" AS c178,
+		T3."skr51_sales_channel" AS c179,
+		T3."skr51_cost_center" AS c180,
+		T3."skr51_branch" AS c181,
+		T3."day_of_actual_accounting" AS c182,
+		T3."days_for_cash_discount" AS c183,
+		T3."vat_key" AS c184,
+		T3."account_statement_page" AS c185,
+		T3."account_statement_number" AS c186,
+		T3."vat_id_number" AS c187,
+		T3."vehicle_reference" AS c188,
+		T3."posting_text" AS c189,
+		T3."term_of_payment" AS c190,
+		T3."cash_discount" AS c191,
+		T3."journal_line" AS c192,
+		T3."journal_page" AS c193,
+		T3."last_dunning_date" AS c194,
+		T3."dunning_level" AS c195,
+		T3."invoice_number" AS c196,
+		T3."invoice_date" AS c197,
+		T3."employee_number" AS c198,
+		T3."serial_number_each_month" AS c199,
+		T3."account_form_page_line" AS c200,
+		T3."account_form_page_number" AS c201,
+		CASE 
+			WHEN (T3."nominal_account_number" = 5701)
+				THEN ((rtrim((convert(VARCHAR(50), T3."nominal_account_number")))) + '_' + (rtrim((convert(VARCHAR(50), T3."skr51_cost_center")))))
+			ELSE ((rtrim((convert(VARCHAR(50), T3."nominal_account_number")))))
+			END AS c202,
+		T3."nominal_contra_account" AS c203,
+		T3."customer_contra_account" AS c204,
+		T3."branch_number" AS c205,
+		T3."posted_count" AS c206,
+		T3."debit_or_credit" AS c207,
+		(T3."posted_value") AS c208,
+		T3."document_date" AS c209,
+		T3."clearing_number" AS c210,
+		T3."is_balanced" AS c211,
+		T3."nominal_account_number" AS c212,
+		T3."customer_number" AS c213,
+		T3."position_in_document" AS c214,
+		T3."document_number" AS c215,
+		T3."document_type" AS c216,
+		(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) AS c217,
+		T1."total_net" AS c218,
+		T1."total_gross" AS c219,
+		T1."part_disposal" AS c220,
+		T1."part_rebate" AS c221,
+		T1."part_amount_gross" AS c222,
+		T1."part_amount_net" AS c223,
+		T1."job_rebate" AS c224,
+		T1."job_amount_gross" AS c225,
+		T1."job_amount_net" AS c226,
+		T1."used_part_vat_value" AS c227,
+		T1."reduced_vat_value" AS c228,
+		T1."reduced_vat_percentage" AS c229,
+		T1."reduced_vat_basevalue" AS c230,
+		T1."full_vat_value" AS c231,
+		T1."full_vat_percentage" AS c232,
+		T1."full_vat_basevalue" AS c233,
+		T1."vehicle_number" AS c234,
+		T1."internal_cost_account" AS c235,
+		T1."creating_employee" AS c236,
+		T1."odometer_reading" AS c237,
+		T1."credit_invoice_number" AS c238,
+		T1."credit_invoice_type" AS c239,
+		T1."is_credit" AS c240,
+		T1."is_own_vehicle" AS c241,
+		T1."cancelation_employee" AS c242,
+		T1."cancelation_date" AS c243,
+		T1."cancelation_number" AS c244,
+		T1."is_canceled" AS c245,
+		T1."service_date" AS c246,
+		T1."invoice_date" AS c247,
+		T1."order_customer" AS c248,
+		T1."paying_customer" AS c249,
+		T1."subsidiary" AS c250,
+		T1."invoice_number" AS c251,
+		T2."description" AS c252,
+		T2."type" AS c253,
+		T1."invoice_type" AS c254
+	FROM (
+		(
+			(
+				(
+					(
+						(
+							(
+								(
+									(
+										"dbo"."invoices" T1 LEFT OUTER JOIN "dbo"."invoice_types" T2 ON T2."type" = T1."invoice_type"
+										) LEFT OUTER JOIN "dbo"."journal_accountings" T3 ON T3."invoice_number" = T1."invtype_invnr"
+									) LEFT OUTER JOIN "dbo"."customers_suppliers" T4 ON T4."customer_number" = T1."paying_customer"
+								) LEFT OUTER JOIN "dbo"."employees" T5 ON T1."creating_employee" = T5."employee_number"
+							) LEFT OUTER JOIN "dbo"."accounts_characteristics" T6 ON (
+								(
+									(
+										(
+											(T6."skr51_branch" = T3."skr51_branch")
+											AND (T6."skr51_make" = T3."skr51_make")
+											)
+										AND (T6."skr51_cost_center" = T3."skr51_cost_center")
+										)
+									AND (T6."skr51_sales_channel" = T3."skr51_sales_channel")
+									)
+								AND (T6."skr51_cost_unit" = T3."skr51_cost_unit")
+								)
+							AND (T6."subsidiary_to_company_ref" = T3."subsidiary_to_company_ref")
+						) LEFT OUTER JOIN "dbo"."vehicles" T7 ON T1."vehicle_number" = T7."internal_number"
+					) LEFT OUTER JOIN "dbo"."makes" T8 ON T7."make_number" = T8."make_number"
+				) LEFT OUTER JOIN "dbo"."models" T9 ON (T7."make_number" = T9."make_number")
+				AND (T7."model_code" = T9."model_code")
+			) LEFT OUTER JOIN "ims"."Serviceberater_Rechnung" T10 ON T1."invtype_invnr" = T10."invtype_invnr"
+		)
+	WHERE (
+			(
+				(
+					(
+						(T1."invoice_type" BETWEEN 2 AND 6)
+						AND ((substring((convert(VARCHAR(50), T3."nominal_account_number")), 1, 1)) IN ('4', '5', '7', '8'))
+						)
+					AND (T1."invoice_date" >= convert(DATE, '2019-01-01'))
+					)
+				AND (T1."is_canceled" <> 1)
+				)
+			AND (((len((rtrim((convert(VARCHAR(50), T3."nominal_account_number"))))))) = 4)
+			)
+		-- order by c141 asc,c215 asc,c214 asc,c217 asc
+	) D1
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 73 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_0.sql

@@ -0,0 +1,73 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[aftersales_rechnungen_verk_aw_final_0]
+AS
+SELECT CAST([Hauptbetrieb_ID] AS VARCHAR(100)) AS [Hauptbetrieb_ID],
+	CAST([Hauptbetrieb_Name] AS VARCHAR(100)) AS [Hauptbetrieb_Name],
+	CAST([Standort_ID] AS VARCHAR(100)) AS [Standort_ID],
+	CAST([Standort_Name] AS VARCHAR(100)) AS [Standort_Name],
+	CAST([Employee_Function] AS VARCHAR(100)) AS [Employee_Function],
+	CAST([Serviceberater] AS VARCHAR(100)) AS [Serviceberater],
+	CAST([Order_Number] AS VARCHAR(100)) AS [Order_Number],
+	CAST([Invoice_Desc_100] AS VARCHAR(100)) AS [Invoice_Desc_100],
+	CAST([Fabrikat] AS VARCHAR(100)) AS [Fabrikat],
+	CAST([Model] AS VARCHAR(100)) AS [Model],
+	CAST([Fahrzeug] AS VARCHAR(100)) AS [Fahrzeug],
+	CAST([Kostenstelle] AS VARCHAR(100)) AS [Kostenstelle],
+	CAST([Marke] AS VARCHAR(100)) AS [Marke],
+	CAST([Umsatzart] AS VARCHAR(100)) AS [Umsatzart],
+	CAST([Auftragsart] AS VARCHAR(100)) AS [Auftragsart],
+	CAST([Auftragsposition] AS VARCHAR(100)) AS [Auftragsposition],
+	CAST([Kundenart] AS VARCHAR(100)) AS [Kundenart],
+	CAST([Kunde] AS VARCHAR(100)) AS [Kunde],
+	CAST([Order_Desc_30] AS VARCHAR(100)) AS [Order_Desc_30],
+	CAST([Invoice_Desc_30] AS VARCHAR(100)) AS [Invoice_Desc_30],
+	CAST([c21] AS VARCHAR(100)) AS [c21],
+	CAST([Produktbuchungsgruppe] AS VARCHAR(100)) AS [Produktbuchungsgruppe],
+	CAST([FZG_Altersstaffel] AS VARCHAR(100)) AS [FZG_Altersstaffel],
+	CAST([Repair_Group_Desc] AS VARCHAR(100)) AS [Repair_Group_Desc],
+	CAST([DB1____EK] AS VARCHAR(100)) AS [DB1____EK],
+	CAST([Rechnung_Gutschrift] AS VARCHAR(100)) AS [Rechnung_Gutschrift],
+	CAST([Parts_Focus_Group] AS VARCHAR(100)) AS [Parts_Focus_Group],
+	CAST([Parts_Make_Desc] AS VARCHAR(100)) AS [Parts_Make_Desc],
+	CAST([Parts_Group_Desc] AS VARCHAR(100)) AS [Parts_Group_Desc],
+	CAST([PLZ_1_Stelle] AS VARCHAR(100)) AS [PLZ_1_Stelle],
+	CAST([PLZ_2_Stelle] AS VARCHAR(100)) AS [PLZ_2_Stelle],
+	CAST([PLZ_3_Stelle] AS VARCHAR(100)) AS [PLZ_3_Stelle],
+	CAST([PLZ_4_Stelle] AS VARCHAR(100)) AS [PLZ_4_Stelle],
+	CAST([PLZ] AS VARCHAR(100)) AS [PLZ],
+	CAST([Zuordnung_Funktion] AS VARCHAR(100)) AS [Zuordnung_Funktion],
+	CAST([Order_Desc_100] AS VARCHAR(100)) AS [Order_Desc_100],
+	CAST(ROUND(ISNULL([Lohn], 0), 8) AS NUMERIC(19, 8)) AS [Lohn],
+	CAST(ROUND(ISNULL([Teile], 0), 8) AS NUMERIC(19, 8)) AS [Teile],
+	CAST(ROUND(ISNULL([EW_Teile], 0), 8) AS NUMERIC(19, 8)) AS [EW_Teile],
+	CAST(ROUND(ISNULL([Sonst_], 0), 8) AS NUMERIC(19, 8)) AS [Sonst_],
+	CAST(ROUND(ISNULL([TÜV], 0), 8) AS NUMERIC(19, 8)) AS [TÜV],
+	CAST(ROUND(ISNULL([Fremdl_], 0), 8) AS NUMERIC(19, 8)) AS [Fremdl_],
+	CAST(ROUND(ISNULL([Mietw_], 0), 8) AS NUMERIC(19, 8)) AS [Mietw_],
+	CAST(ROUND(ISNULL([Rädereinl_], 0), 8) AS NUMERIC(19, 8)) AS [Rädereinl_],
+	CAST(ROUND(ISNULL([verk__Std_], 0), 8) AS NUMERIC(19, 8)) AS [verk__Std_],
+	CAST(ROUND(ISNULL([ben__Std_], 0), 8) AS NUMERIC(19, 8)) AS [ben__Std_],
+	CAST(ROUND(ISNULL([NL_Lohn], 0), 8) AS NUMERIC(19, 8)) AS [NL_Lohn],
+	CAST(ROUND(ISNULL([NL_Teile], 0), 8) AS NUMERIC(19, 8)) AS [NL_Teile],
+	CAST(ROUND(ISNULL([NL_Sonst_], 0), 8) AS NUMERIC(19, 8)) AS [NL_Sonst_],
+	CAST(ROUND(ISNULL([DG], 0), 8) AS NUMERIC(19, 8)) AS [DG],
+	CAST(ROUND(ISNULL([NL_Sonst__], 0), 8) AS NUMERIC(19, 8)) AS [NL_Sonst__],
+	CAST(ROUND(ISNULL([Anz__AT], 0), 8) AS NUMERIC(19, 8)) AS [Anz__AT],
+	CAST(ROUND(ISNULL([Anwesenheit_Mech_Karo_Lack], 0), 8) AS NUMERIC(19, 8)) AS [Anwesenheit_Mech_Karo_Lack],
+	CAST(ROUND(ISNULL([Anwesenheit_Meister], 0), 8) AS NUMERIC(19, 8)) AS [Anwesenheit_Meister],
+	CAST([Invoice_Date] AS DATETIME) AS [Invoice_Date],
+	CAST([Rechnungsausgang] AS VARCHAR(100)) AS [Rechnungsausgang],
+	CAST([Fabrikat_Order_By] AS INT) AS [Fabrikat_Order_By],
+	CAST([Serviceberater_Rg_Steller] AS VARCHAR(100)) AS [Serviceberater_Rg_Steller]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_verk_aw_final_11]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 102 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_11.sql

@@ -0,0 +1,102 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_verk_aw_final_11]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
+	"GC_Department"."Standort_ID" AS "Standort_ID",
+	"GC_Department"."Standort_Name" AS "Standort_Name",
+	'Serviceberater' AS "Employee_Function",
+	"T2"."Serviceberater" AS "Serviceberater",
+	"T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121) AS "Order_Number",
+	'' AS "Invoice_Desc_100",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	"T2"."Model" AS "Model",
+	"T2"."Fahrzeug" AS "Fahrzeug",
+	"T2"."Kostenstelle" AS "Kostenstelle",
+	"T2"."Marke" AS "Marke",
+	"T2"."Umsatzart" AS "Umsatzart",
+	"T2"."Auftragsart" AS "Auftragsart",
+	'' AS "Auftragsposition",
+	'' AS "Kundenart",
+	"T2"."Kunde" AS "Kunde",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Order_Desc_30",
+	'' AS "Invoice_Desc_30",
+	"GC_Produktbuchungsgruppen"."Zuordnung" AS "c21",
+	"T2"."Kostenstelle" AS "Produktbuchungsgruppe",
+	'' AS "FZG_Altersstaffel",
+	'' AS "Repair_Group_Desc",
+	'' AS "DB1____EK",
+	'' AS "Rechnung_Gutschrift",
+	'' AS "Parts_Focus_Group",
+	'' AS "Parts_Make_Desc",
+	'' AS "Parts_Group_Desc",
+	left("T2"."Geschäftsart", 1) AS "PLZ_1_Stelle",
+	left("T2"."Geschäftsart", 2) AS "PLZ_2_Stelle",
+	left("T2"."Geschäftsart", 3) AS "PLZ_3_Stelle",
+	left("T2"."Geschäftsart", 4) AS "PLZ_4_Stelle",
+	"T2"."Geschäftsart" AS "PLZ",
+	'Serviceberater' AS "Zuordnung_Funktion",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 100
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 100 Tage'
+		END AS "Order_Desc_100",
+	0 AS "Lohn",
+	0 AS "Teile",
+	0 AS "EW_Teile",
+	0 AS "Sonst_",
+	0 AS "TÜV",
+	0 AS "Fremdl_",
+	0 AS "Mietw_",
+	0 AS "Rädereinl_",
+	"T2"."verk. Std." AS "verk__Std_",
+	0 AS "ben__Std_",
+	0 AS "NL_Lohn",
+	0 AS "NL_Teile",
+	0 AS "NL_Sonst_",
+	0 AS "DG",
+	0 AS "NL_Sonst__",
+	0 AS "Anz__AT",
+	0 AS "Anwesenheit_Mech_Karo_Lack",
+	0 AS "Anwesenheit_Meister",
+	"T2"."Invoice Date" AS "Invoice_Date",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Rechnungsausgang",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By",
+	"T2"."Kundenart" AS "Serviceberater_Rg_Steller"
+FROM (
+	(
+		[staging].[aftersales_rechnungen_verk_aw_final_80] "T2" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "T2"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb"
+			AND "T2"."Standort" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "T2"."Fabrikat" = "GC_Marken"."Description"
+	)
+LEFT OUTER JOIN "GC"."data"."GC_Produktbuchungsgruppen" "GC_Produktbuchungsgruppen" ON "T2"."Kostenstelle" = "GC_Produktbuchungsgruppen"."Produktbuchungsgruppe"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 44 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_80.sql

@@ -0,0 +1,44 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[aftersales_rechnungen_verk_aw_final_80]
+AS
+SELECT [Invoice Type],
+	[Invoice Number],
+	[Subsidiary],
+	[Invoice Date],
+	[Service Date],
+	[Is Canceled],
+	[Vehicle Number],
+	[Invoice_Type_Invoice_Number],
+	[Hauptbetrieb],
+	[Standort],
+	[Serviceberater],
+	[Umsatzart],
+	[Fabrikat],
+	[Description_Makes],
+	[Description_Models],
+	[Model],
+	[Fahrzeug],
+	[Kostenstelle],
+	[Marke],
+	[Auftragsart],
+	[Geschäftsart],
+	[Kunde],
+	[Time Units],
+	[Time Units_Zahl],
+	[AW/Std.],
+	[verk. Std.],
+	[Order Number],
+	[Order Number_Rg_Ausg],
+	[Kundenart]
+FROM [LOCOSOFT].[staging].[aftersales_rechnungen_verk_aw_final_imr]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 165 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_90.sql

@@ -0,0 +1,165 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_verk_aw_final_90]
+AS
+SELECT T1."invoice_type" AS "Invoice Type",
+	T1."invoice_number" AS "Invoice Number",
+	T1."subsidiary" AS "Subsidiary",
+	T1."invoice_date" AS "Invoice Date",
+	T1."service_date" AS "Service Date",
+	T1."is_canceled" AS "Is Canceled",
+	T1."vehicle_number" AS "Vehicle Number",
+	(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + '_' + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) AS "Invoice_Type_Invoice_Number",
+	CASE 
+		WHEN ((substring((convert(VARCHAR(50), T1."invoice_number")), 1, 1)) = '2')
+			THEN ('15')
+		ELSE ('1')
+		END AS "Hauptbetrieb",
+	'0' + (convert(VARCHAR(50), T1."subsidiary")) AS "Standort",
+	T2."Serviceberater" AS "Serviceberater",
+	CASE 
+		WHEN (T1."invoice_type" = 6)
+			THEN ('GWL')
+		WHEN (
+				(T1."invoice_type" = 4)
+				OR (T3."customer_number" = 100001)
+				)
+			THEN ('intern')
+		ELSE ('extern')
+		END AS "Umsatzart",
+	T4."description" AS "Fabrikat",
+	T4."description" AS "Description_Makes",
+	T5."description" AS "Description_Models",
+	(substring((upper(T5."description")), 1, 3)) AS "Model",
+	(substring((substring((convert(VARCHAR(50), T1."vehicle_number")), 1, 5)) + ' - ' + T5."description", 1, 100)) AS "Fahrzeug",
+	CASE 
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('1', '6'))
+			THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+		WHEN (T6."type" IN (40, 41, 44, 45, 46, 47, 48, 49, 88, 89, 50, 90))
+			THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('2'))
+			THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+		WHEN (T6."type" IN (42, 92))
+			THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('3'))
+			THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+		WHEN (T6."type" IN (43, 93))
+			THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+		ELSE NULL
+		END AS "Kostenstelle",
+	CASE 
+		WHEN (T4."description" = 'Ford')
+			THEN ('1')
+		WHEN (T4."description" = 'Nissan')
+			THEN ('3')
+		WHEN (T4."description" = 'Suzuki')
+			THEN ('2')
+		ELSE ('9')
+		END AS "Marke",
+	'Service' AS "Auftragsart",
+	T3."zip_code" AS "Geschäftsart",
+	CASE 
+		WHEN (T3."first_name" IS NULL)
+			THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+		ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+		END AS "Kunde",
+	T7."time_units" AS "Time Units",
+	(convert(FLOAT, T7."time_units")) AS "Time Units_Zahl",
+	10 AS "AW/Std.",
+	((convert(FLOAT, T7."time_units"))) / 10 AS "verk. Std.",
+	CASE 
+		WHEN (T2."Serviceberater" IS NOT NULL)
+			THEN (
+					(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+						CASE 
+							WHEN (T3."first_name" IS NULL)
+								THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+							ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+							END
+						)
+					)
+		ELSE (
+				(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+					CASE 
+						WHEN (T3."first_name" IS NULL)
+							THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+						ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+						END
+					)
+				)
+		END AS "Order Number",
+	CASE 
+		WHEN ((day((getdate()) - (convert(DATETIME, T1."invoice_date")))) <= 4)
+			THEN (
+					(
+						CASE 
+							WHEN (T2."Serviceberater" IS NOT NULL)
+								THEN (
+										(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+											CASE 
+												WHEN (T3."first_name" IS NULL)
+													THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+												ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+												END
+											)
+										)
+							ELSE (
+									(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+										CASE 
+											WHEN (T3."first_name" IS NULL)
+												THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+											ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+											END
+										)
+									)
+							END
+						)
+					)
+		ELSE NULL
+		END AS "Order Number_Rg_Ausg",
+	(substring((convert(VARCHAR(50), T8."employee_number")), 1, 4)) + ' - ' + T8."name" AS "Kundenart"
+FROM (
+	(
+		(
+			(
+				(
+					(
+						(
+							(
+								"dbo"."invoices" T1 LEFT OUTER JOIN "dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."paying_customer"
+								) LEFT OUTER JOIN "dbo"."vehicles" T9 ON T1."vehicle_number" = T9."internal_number"
+							) LEFT OUTER JOIN "dbo"."makes" T4 ON T9."make_number" = T4."make_number"
+						) LEFT OUTER JOIN "dbo"."models" T5 ON (T9."make_number" = T5."make_number")
+						AND (T9."model_code" = T5."model_code")
+					) LEFT OUTER JOIN "dbo"."labours" T7 ON (T7."invoice_number" = T1."invoice_number")
+					AND (T7."invoice_type" = T1."invoice_type")
+				) LEFT OUTER JOIN "dbo"."charge_type_descriptions" T6 ON T6."type" = T7."charge_type"
+			) LEFT OUTER JOIN "dbo"."employees" T8 ON T1."creating_employee" = T8."employee_number"
+		) LEFT OUTER JOIN "ims"."Serviceberater_Rechnung" T2 ON T1."invtype_invnr" = T2."invtype_invnr"
+	)
+WHERE (
+		(
+			(
+				(
+					(T1."invoice_type" BETWEEN 2 AND 6)
+					AND (T1."is_canceled" <> 1)
+					)
+				AND (T1."invoice_date" >= convert(DATE, '2017-01-01'))
+				)
+			AND (
+				(((convert(FLOAT, T7."time_units"))) <> 0)
+				AND (((convert(FLOAT, T7."time_units"))) IS NOT NULL)
+				)
+			)
+		AND (T7."mechanic_no" IS NOT NULL)
+		)
+	-- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 102 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_fm.sql

@@ -0,0 +1,102 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_verk_aw_final_fm]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Hauptbetrieb_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Hauptbetrieb_Name",
+	"GC_Department"."Standort_ID" AS "Standort_ID",
+	"GC_Department"."Standort_Name" AS "Standort_Name",
+	'Serviceberater' AS "Employee_Function",
+	"T2"."Serviceberater" AS "Serviceberater",
+	"T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121) AS "Order_Number",
+	'' AS "Invoice_Desc_100",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	"T2"."Model" AS "Model",
+	"T2"."Fahrzeug" AS "Fahrzeug",
+	"T2"."Kostenstelle" AS "Kostenstelle",
+	"T2"."Marke" AS "Marke",
+	"T2"."Umsatzart" AS "Umsatzart",
+	"T2"."Auftragsart" AS "Auftragsart",
+	'' AS "Auftragsposition",
+	'' AS "Kundenart",
+	"T2"."Kunde" AS "Kunde",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Order_Desc_30",
+	'' AS "Invoice_Desc_30",
+	"GC_Produktbuchungsgruppen"."Zuordnung" AS "c21",
+	"T2"."Kostenstelle" AS "Produktbuchungsgruppe",
+	'' AS "FZG_Altersstaffel",
+	'' AS "Repair_Group_Desc",
+	'' AS "DB1____EK",
+	'' AS "Rechnung_Gutschrift",
+	'' AS "Parts_Focus_Group",
+	'' AS "Parts_Make_Desc",
+	'' AS "Parts_Group_Desc",
+	left("T2"."Geschäftsart", 1) AS "PLZ_1_Stelle",
+	left("T2"."Geschäftsart", 2) AS "PLZ_2_Stelle",
+	left("T2"."Geschäftsart", 3) AS "PLZ_3_Stelle",
+	left("T2"."Geschäftsart", 4) AS "PLZ_4_Stelle",
+	"T2"."Geschäftsart" AS "PLZ",
+	'Serviceberater' AS "Zuordnung_Funktion",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 100
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 100 Tage'
+		END AS "Order_Desc_100",
+	0 AS "Lohn",
+	0 AS "Teile",
+	0 AS "EW_Teile",
+	0 AS "Sonst_",
+	0 AS "TÜV",
+	0 AS "Fremdl_",
+	0 AS "Mietw_",
+	0 AS "Rädereinl_",
+	"T2"."verk  Std " AS "verk__Std_",
+	0 AS "ben__Std_",
+	0 AS "NL_Lohn",
+	0 AS "NL_Teile",
+	0 AS "NL_Sonst_",
+	0 AS "DG",
+	0 AS "NL_Sonst__",
+	0 AS "Anz__AT",
+	0 AS "Anwesenheit_Mech_Karo_Lack",
+	0 AS "Anwesenheit_Meister",
+	"T2"."Invoice Date" AS "Invoice_Date",
+	CASE 
+		WHEN datediff(dd, "T2"."Invoice Date", convert(DATETIME, convert(CHAR(8), current_timestamp, 112), 112)) < 30
+			THEN "T2"."Order Number" + ' - ' + CONVERT(VARCHAR(10), "T2"."Invoice Date", 121)
+		ELSE 'älter 30 Tage'
+		END AS "Rechnungsausgang",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By",
+	"T2"."Kundenart" AS "Serviceberater_Rg_Steller"
+FROM (
+	(
+		"GC"."locosoft"."Aftersales_Rechnungen_verk_AW_final" "T2" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "T2"."Hauptbetrieb" = "GC_Department"."Hauptbetrieb"
+			AND "T2"."Standort" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "T2"."Fabrikat" = "GC_Marken"."Description"
+	)
+LEFT OUTER JOIN "GC"."data"."GC_Produktbuchungsgruppen" "GC_Produktbuchungsgruppen" ON "T2"."Kostenstelle" = "GC_Produktbuchungsgruppen"."Produktbuchungsgruppe"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 165 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.aftersales_rechnungen_verk_aw_final_imr.sql

@@ -0,0 +1,165 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[aftersales_rechnungen_verk_aw_final_imr]
+AS
+SELECT T1."invoice_type" AS "Invoice Type",
+	T1."invoice_number" AS "Invoice Number",
+	T1."subsidiary" AS "Subsidiary",
+	T1."invoice_date" AS "Invoice Date",
+	T1."service_date" AS "Service Date",
+	T1."is_canceled" AS "Is Canceled",
+	T1."vehicle_number" AS "Vehicle Number",
+	(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + '_' + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) AS "Invoice_Type_Invoice_Number",
+	CASE 
+		WHEN ((substring((convert(VARCHAR(50), T1."invoice_number")), 1, 1)) = '2')
+			THEN ('15')
+		ELSE ('1')
+		END AS "Hauptbetrieb",
+	'0' + (convert(VARCHAR(50), T1."subsidiary")) AS "Standort",
+	T2."Serviceberater" AS "Serviceberater",
+	CASE 
+		WHEN (T1."invoice_type" = 6)
+			THEN ('GWL')
+		WHEN (
+				(T1."invoice_type" = 4)
+				OR (T3."customer_number" = 100001)
+				)
+			THEN ('intern')
+		ELSE ('extern')
+		END AS "Umsatzart",
+	T4."description" AS "Fabrikat",
+	T4."description" AS "Description_Makes",
+	T5."description" AS "Description_Models",
+	(substring((upper(T5."description")), 1, 3)) AS "Model",
+	(substring((substring((convert(VARCHAR(50), T1."vehicle_number")), 1, 5)) + ' - ' + T5."description", 1, 100)) AS "Fahrzeug",
+	CASE 
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('1', '6'))
+			THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+		WHEN (T6."type" IN (40, 41, 44, 45, 46, 47, 48, 49, 88, 89, 50, 90))
+			THEN ('41 - After Sales Kundendienst eigene Werkstatt')
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('2'))
+			THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+		WHEN (T6."type" IN (42, 92))
+			THEN ('44 - After Sales Kundendienst eigene Karosserieabteilung')
+		WHEN ((substring((convert(VARCHAR(50), T6."type")), 1, 1)) IN ('3'))
+			THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+		WHEN (T6."type" IN (43, 93))
+			THEN ('45 - After Sales Kundendienst eigene Lackiererei')
+		ELSE NULL
+		END AS "Kostenstelle",
+	CASE 
+		WHEN (T4."description" = 'Ford')
+			THEN ('1')
+		WHEN (T4."description" = 'Nissan')
+			THEN ('3')
+		WHEN (T4."description" = 'Suzuki')
+			THEN ('2')
+		ELSE ('9')
+		END AS "Marke",
+	'Service' AS "Auftragsart",
+	T3."zip_code" AS "Geschäftsart",
+	CASE 
+		WHEN (T3."first_name" IS NULL)
+			THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+		ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+		END AS "Kunde",
+	T7."time_units" AS "Time Units",
+	(convert(FLOAT, T7."time_units")) AS "Time Units_Zahl",
+	10 AS "AW/Std.",
+	((convert(FLOAT, T7."time_units"))) / 10 AS "verk. Std.",
+	CASE 
+		WHEN (T2."Serviceberater" IS NOT NULL)
+			THEN (
+					(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+						CASE 
+							WHEN (T3."first_name" IS NULL)
+								THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+							ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+							END
+						)
+					)
+		ELSE (
+				(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+					CASE 
+						WHEN (T3."first_name" IS NULL)
+							THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+						ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+						END
+					)
+				)
+		END AS "Order Number",
+	CASE 
+		WHEN ((day((getdate()) - (convert(DATETIME, T1."invoice_date")))) <= 4)
+			THEN (
+					(
+						CASE 
+							WHEN (T2."Serviceberater" IS NOT NULL)
+								THEN (
+										(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + T2."Serviceberater" + ' - ' + (
+											CASE 
+												WHEN (T3."first_name" IS NULL)
+													THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+												ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+												END
+											)
+										)
+							ELSE (
+									(substring((convert(VARCHAR(50), T1."invoice_type")), 1, 1)) + (substring((convert(VARCHAR(50), T1."invoice_number")), 1, 9)) + ' - ' + (
+										CASE 
+											WHEN (T3."first_name" IS NULL)
+												THEN ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."family_name")
+											ELSE ((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
+											END
+										)
+									)
+							END
+						)
+					)
+		ELSE NULL
+		END AS "Order Number_Rg_Ausg",
+	(substring((convert(VARCHAR(50), T8."employee_number")), 1, 4)) + ' - ' + T8."name" AS "Kundenart"
+FROM (
+	(
+		(
+			(
+				(
+					(
+						(
+							(
+								"dbo"."invoices" T1 LEFT OUTER JOIN "dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."paying_customer"
+								) LEFT OUTER JOIN "dbo"."vehicles" T9 ON T1."vehicle_number" = T9."internal_number"
+							) LEFT OUTER JOIN "dbo"."makes" T4 ON T9."make_number" = T4."make_number"
+						) LEFT OUTER JOIN "dbo"."models" T5 ON (T9."make_number" = T5."make_number")
+						AND (T9."model_code" = T5."model_code")
+					) LEFT OUTER JOIN "dbo"."labours" T7 ON (T7."invoice_number" = T1."invoice_number")
+					AND (T7."invoice_type" = T1."invoice_type")
+				) LEFT OUTER JOIN "dbo"."charge_type_descriptions" T6 ON T6."type" = T7."charge_type"
+			) LEFT OUTER JOIN "dbo"."employees" T8 ON T1."creating_employee" = T8."employee_number"
+		) LEFT OUTER JOIN "ims"."Serviceberater_Rechnung" T2 ON T1."invtype_invnr" = T2."invtype_invnr"
+	)
+WHERE (
+		(
+			(
+				(
+					(T1."invoice_type" BETWEEN 2 AND 6)
+					AND (T1."is_canceled" <> 1)
+					)
+				AND (T1."invoice_date" >= convert(DATE, '2017-01-01'))
+				)
+			AND (
+				(((convert(FLOAT, T7."time_units"))) <> 0)
+				AND (((convert(FLOAT, T7."time_units"))) IS NOT NULL)
+				)
+			)
+		AND (T7."mechanic_no" IS NOT NULL)
+		)
+	-- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 0 - 19
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.ben_AW_Order_Number.sql

@@ -1,19 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.ben_AW_Order_Number AS
-
-select T1."order_number" as "Order Number",
-	   SUM(T1."duration_minutes") as "Summe_Duration_Minutes"
-from "dbo"."times" T1
-where (T1."order_number" <> 0)
-group by (T1."order_number")
-order by "Order Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 43
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_Prognose.sql

@@ -1,43 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.current_date_Prognose AS
-
-select "Bundeslaender Id" as "Bundeslaender Id",
-	   "Datum" as "Datum",
-	   "Wochentage Id" as "Wochentage Id",
-	   "Arbeitstag Mofr" as "Arbeitstag Mofr",
-	   "Zaehler Mofr" as "Zaehler Mofr",
-	   "Summe Mofr" as "Summe Mofr",
-	   "Arbeitstag Mosa" as "Arbeitstag Mosa",
-	   "Zaehler Mosa" as "Zaehler Mosa",
-	   "Summe Mosa" as "Summe Mosa",
-	   "Feiertage Id" as "Feiertage Id",
-	   "Jahr" as "Jahr",
-	   CASE WHEN ("Arbeitstag Mofr" = 1) THEN (RCOUNT("Arbeitstag Mofr")) ELSE null END as "Arbeitstag Nr Jahr",
-	   "Gesamt Arbeitstage" as "Gesamt Arbeitstage"
-from 
-(select T1."bundeslaender_id" as "Bundeslaender Id",
-	   T1."datum" as "Datum",
-	   T1."wochentage_id" as "Wochentage Id",
-	   T1."arbeitstag_mofr" as "Arbeitstag Mofr",
-	   T1."zaehler_mofr" as "Zaehler Mofr",
-	   T1."summe_mofr" as "Summe Mofr",
-	   T1."arbeitstag_mosa" as "Arbeitstag Mosa",
-	   T1."zaehler_mosa" as "Zaehler Mosa",
-	   T1."summe_mosa" as "Summe Mosa",
-	   T1."feiertage_id" as "Feiertage Id",
-	   (@CURRENT_DATE) - INTERVAL '001 00:00:00.000' as "Jahr",
-	   CASE WHEN (T1."datum" BETWEEN convert(datetime, '2008-01-01 00:00:00.000') AND convert(datetime, '2008-12-31 00:00:00.000')) THEN (252) WHEN (T1."datum" BETWEEN convert(datetime, '2009-01-01 00:00:00.000') AND convert(datetime, '2009-12-31 00:00:00.000')) THEN (252) WHEN (T1."datum" BETWEEN convert(datetime, '2010-01-01 00:00:00.000') AND convert(datetime, '2010-12-31 00:00:00.000')) THEN (253) WHEN (T1."datum" BETWEEN convert(datetime, '2011-01-01 00:00:00.000') AND convert(datetime, '2011-12-31 00:00:00.000')) THEN (250) WHEN (T1."datum" BETWEEN convert(datetime, '2012-01-01 00:00:00.000') AND convert(datetime, '2012-12-31 00:00:00.000')) THEN (249) ELSE (250) END as "Gesamt Arbeitstage"
-from "Arbeitstage" T1
-where (((((T1."bundeslaender_id" = '2') and (T1."arbeitstag_mofr" = 1)) and ((od_year(T1."datum")) = (year(((@CURRENT_DATE) - INTERVAL '001 00:00:00.000'))))) and (T1."datum" <= ((@CURRENT_DATE) - INTERVAL '001 00:00:00.000'))) or ((((T1."bundeslaender_id" = '2') and ((od_year(T1."datum")) = (year(((@CURRENT_DATE) - INTERVAL '001 00:00:00.000'))))) and (T1."datum" <= ((@CURRENT_DATE) - INTERVAL '001 00:00:00.000'))) and (T1."datum" IN (convert(datetime, '2022-01-01 00:00:00.000'),convert(datetime, '2023-01-01 00:00:00.000'),convert(datetime, '2024-01-01 00:00:00.000'),convert(datetime, '2025-01-01 00:00:00.000'),convert(datetime, '2026-01-01 00:00:00.000')))))
--- order by "Bundeslaender Id" asc,"Datum" asc,"Wochentage Id" asc,"Arbeitstag Mofr" asc,"Zaehler Mofr" asc,"Summe Mofr" asc,"Arbeitstag Mosa" asc,"Zaehler Mosa" asc,"Summe Mosa" asc,"Feiertage Id" asc,"Gesamt Arbeitstage" asc
-) D1
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 0 - 43
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_Prognose_operativ_VJ-2.sql

@@ -1,43 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.current_date_Prognose_operativ_VJ-2 AS
-
-select "Bundeslaender Id" as "Bundeslaender Id",
-	   "Datum" as "Datum",
-	   "Wochentage Id" as "Wochentage Id",
-	   "Arbeitstag Mofr" as "Arbeitstag Mofr",
-	   "Zaehler Mofr" as "Zaehler Mofr",
-	   "Summe Mofr" as "Summe Mofr",
-	   "Arbeitstag Mosa" as "Arbeitstag Mosa",
-	   "Zaehler Mosa" as "Zaehler Mosa",
-	   "Summe Mosa" as "Summe Mosa",
-	   "Feiertage Id" as "Feiertage Id",
-	   "Jahr" as "Jahr",
-	   CASE WHEN ("Arbeitstag Mofr" = 1) THEN (RCOUNT("Arbeitstag Mofr")) ELSE null END as "Arbeitstag Nr Jahr",
-	   "Gesamt Arbeitstage" as "Gesamt Arbeitstage"
-from 
-(select T1."bundeslaender_id" as "Bundeslaender Id",
-	   T1."datum" as "Datum",
-	   T1."wochentage_id" as "Wochentage Id",
-	   T1."arbeitstag_mofr" as "Arbeitstag Mofr",
-	   T1."zaehler_mofr" as "Zaehler Mofr",
-	   T1."summe_mofr" as "Summe Mofr",
-	   T1."arbeitstag_mosa" as "Arbeitstag Mosa",
-	   T1."zaehler_mosa" as "Zaehler Mosa",
-	   T1."summe_mosa" as "Summe Mosa",
-	   T1."feiertage_id" as "Feiertage Id",
-	   (@CURRENT_DATE) - INTERVAL '000 00:00:00.000' as "Jahr",
-	   CASE WHEN (T1."datum" BETWEEN convert(datetime, '2008-01-01 00:00:00.000') AND convert(datetime, '2008-12-31 00:00:00.000')) THEN (252) WHEN (T1."datum" BETWEEN convert(datetime, '2009-01-01 00:00:00.000') AND convert(datetime, '2009-12-31 00:00:00.000')) THEN (252) WHEN (T1."datum" BETWEEN convert(datetime, '2010-01-01 00:00:00.000') AND convert(datetime, '2010-12-31 00:00:00.000')) THEN (253) WHEN (T1."datum" BETWEEN convert(datetime, '2011-01-01 00:00:00.000') AND convert(datetime, '2011-12-31 00:00:00.000')) THEN (250) WHEN (T1."datum" BETWEEN convert(datetime, '2012-01-01 00:00:00.000') AND convert(datetime, '2012-12-31 00:00:00.000')) THEN (249) ELSE (250) END as "Gesamt Arbeitstage"
-from "Arbeitstage" T1
-where ((((T1."bundeslaender_id" = '4') and ((od_year(T1."datum")) = ((year(((@CURRENT_DATE) - INTERVAL '000 00:00:00.000'))) - 2))) and (T1."datum" <= ((@CURRENT_DATE) - INTERVAL '000 00:00:00.000'))) or ((((T1."bundeslaender_id" = '4') and ((od_year(T1."datum")) = ((year(((@CURRENT_DATE) - INTERVAL '000 00:00:00.000'))) - 2))) and (T1."datum" <= ((@CURRENT_DATE) - INTERVAL '000 00:00:00.000'))) and (T1."datum" IN (convert(datetime, '2012-01-01 00:00:00.000'),convert(datetime, '2013-01-01 00:00:00.000'),convert(datetime, '2014-01-01 00:00:00.000'),convert(datetime, '2015-01-01 00:00:00.000'),convert(datetime, '2016-01-01 00:00:00.000'),convert(datetime, '2017-01-01 00:00:00.000')))))
--- order by "Bundeslaender Id" asc,"Datum" asc,"Wochentage Id" asc,"Arbeitstag Mofr" asc,"Zaehler Mofr" asc,"Summe Mofr" asc,"Arbeitstag Mosa" asc,"Zaehler Mosa" asc,"Summe Mosa" asc,"Feiertage Id" asc,"Gesamt Arbeitstage" asc
-) D1
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 45 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_prognose_0.sql

@@ -0,0 +1,45 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[current_date_prognose_0]
+AS
+SELECT T1."bundeslaender_id" AS "Bundeslaender Id",
+	T1."datum" AS "Datum",
+	T1."wochentage_id" AS "Wochentage Id",
+	T1."arbeitstag_mofr" AS "Arbeitstag Mofr",
+	T1."zaehler_mofr" AS "Zaehler Mofr",
+	T1."summe_mofr" AS "Summe Mofr",
+	T1."arbeitstag_mosa" AS "Arbeitstag Mosa",
+	T1."zaehler_mosa" AS "Zaehler Mosa",
+	T1."summe_mosa" AS "Summe Mosa",
+	T1."feiertage_id" AS "Feiertage Id",
+	(getdate()) - 1 AS "Jahr",
+	CASE 
+		WHEN T1."arbeitstag_mofr" = '1'
+			THEN T1."zaehler_jahr_mofr"
+		ELSE 0
+		END AS "Arbeitstag Nr Jahr",
+	T1."summe_jahr_mofr" AS "Gesamt Arbeitstage"
+FROM "LOCOSOFT"."data"."Arbeitstage" T1
+WHERE (
+		(T1."bundeslaender_id" = '10')
+		AND (T1."arbeitstag_mofr" = 1)
+		AND (year(T1."datum") = (year(((getdate()) - 1))))
+		AND (T1."datum" <= ((getdate()) - 1))
+		AND (T1."datum" <= ((getdate()) - 1))
+		)
+	OR (
+		(T1."bundeslaender_id" = '10')
+		AND ((year(T1."datum")) = (year(((getdate()) - 1))))
+		AND (T1."datum" <= ((getdate()) - 1))
+		AND (T1."datum" IN (convert(DATETIME, '2019-01-01 00:00:00.000'), convert(DATETIME, '2020-01-01 00:00:00.000'), convert(DATETIME, '2021-01-01 00:00:00.000'), convert(DATETIME, '2022-01-01 00:00:00.000'), convert(DATETIME, '2023-01-01 00:00:00.000')))
+		)
+	-- order by "Bundeslaender Id" asc,"Datum" asc,"Wochentage Id" asc,"Arbeitstag Mofr" asc,"Zaehler Mofr" asc,"Summe Mofr" asc,"Arbeitstag Mosa" asc,"Zaehler Mosa" asc,"Summe Mosa" asc,"Feiertage Id" asc,"Gesamt Arbeitstage" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 57 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.current_date_prognose_imr.sql

@@ -0,0 +1,57 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[current_date_prognose_imr]
+AS
+SELECT T1."bundeslaender_id" AS "Bundeslaender Id",
+	T1."datum" AS "Datum",
+	T1."wochentage_id" AS "Wochentage Id",
+	T1."arbeitstag_mofr" AS "Arbeitstag Mofr",
+	T1."zaehler_mofr" AS "Zaehler Mofr",
+	T1."summe_mofr" AS "Summe Mofr",
+	T1."arbeitstag_mosa" AS "Arbeitstag Mosa",
+	T1."zaehler_mosa" AS "Zaehler Mosa",
+	T1."summe_mosa" AS "Summe Mosa",
+	T1."feiertage_id" AS "Feiertage Id",
+	(getdate()) - 1 AS "Jahr",
+	CASE 
+		WHEN T1."arbeitstag_mofr" = '1'
+			THEN T1."zaehler_jahr_mofr"
+		ELSE 0
+		END AS "Arbeitstag Nr Jahr",
+	T1."summe_jahr_mofr" AS "Gesamt Arbeitstage"
+FROM "LOCOSOFT"."data"."Arbeitstage" T1
+WHERE (
+		(
+			(
+				(
+					(
+						(T1."bundeslaender_id" = '10')
+						AND (T1."arbeitstag_mofr" = 1)
+						)
+					AND ((year(T1."datum")) = (year(((getdate()) - 1))))
+					)
+				AND (T1."datum" <= ((getdate()) - 1))
+				)
+			AND (T1."datum" <= ((getdate()) - 1))
+			)
+		OR (
+			(
+				(
+					(T1."bundeslaender_id" = '10')
+					AND ((year(T1."datum")) = (year(((getdate()) - 1))))
+					)
+				AND (T1."datum" <= ((getdate()) - 1))
+				)
+			AND (T1."datum" IN (convert(DATETIME, '2019-01-01 00:00:00.000'), convert(DATETIME, '2020-01-01 00:00:00.000'), convert(DATETIME, '2021-01-01 00:00:00.000'), convert(DATETIME, '2022-01-01 00:00:00.000'), convert(DATETIME, '2023-01-01 00:00:00.000')))
+			)
+		)
+	-- order by "Bundeslaender Id" asc,"Datum" asc,"Wochentage Id" asc,"Arbeitstag Mofr" asc,"Zaehler Mofr" asc,"Summe Mofr" asc,"Arbeitstag Mosa" asc,"Zaehler Mosa" asc,"Summe Mosa" asc,"Feiertage Id" asc,"Gesamt Arbeitstage" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 121 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_80.sql

@@ -0,0 +1,121 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[kontenrahmen_80]
+AS
+SELECT [Konto Nr],
+	[Konto Bezeichnung],
+	[Konto Art_ori],
+	[Kostenstelle],
+	[Stk],
+	[Konto 1],
+	[Konto 2],
+	[Konto 3],
+	[Konto 4],
+	[Konto 5],
+	[Ebene1],
+	[Ebene2],
+	[Ebene3],
+	[Ebene4],
+	[Ebene5],
+	[Ebene6],
+	[Ebene7],
+	[Ebene8],
+	[Ebene9],
+	[Ebene10],
+	[Ebene11],
+	[Ebene12],
+	[Ebene13],
+	[Ebene14],
+	[Ebene15],
+	[Ebene16],
+	[Ebene17],
+	[Ebene18],
+	[Ebene19],
+	[Ebene20],
+	[Ebene21],
+	[Ebene22],
+	[Ebene23],
+	[Ebene24],
+	[Ebene25],
+	[Ebene26],
+	[Ebene27],
+	[Ebene28],
+	[Ebene29],
+	[Ebene30],
+	[Ebene31],
+	[Ebene32],
+	[Ebene33],
+	[Ebene34],
+	[Ebene35],
+	[Ebene36],
+	[Ebene37],
+	[Ebene38],
+	[Ebene39],
+	[Ebene40],
+	[Ebene41],
+	[Ebene42],
+	[Ebene43],
+	[Ebene44],
+	[Ebene45],
+	[Ebene46],
+	[Ebene47],
+	[Ebene48],
+	[Ebene49],
+	[Ebene50],
+	[Ebene51],
+	[Ebene52],
+	[Ebene53],
+	[Ebene54],
+	[Ebene55],
+	[Ebene56],
+	[Ebene57],
+	[Ebene58],
+	[Ebene59],
+	[Ebene60],
+	[Ebene61],
+	[Ebene62],
+	[Ebene63],
+	[Ebene64],
+	[Ebene65],
+	[Ebene66],
+	[Ebene67],
+	[Ebene68],
+	[Ebene69],
+	[Ebene70],
+	[Ebene71],
+	[Ebene72],
+	[Ebene73],
+	[Ebene74],
+	[Ebene75],
+	[Ebene76],
+	[Ebene77],
+	[Ebene78],
+	[Ebene79],
+	[Ebene80],
+	[Ebene81],
+	[Ebene82],
+	[Ebene83],
+	[Ebene84],
+	[Ebene85],
+	[Ebene86],
+	[Ebene87],
+	[Ebene88],
+	[Ebene89],
+	[Ebene90],
+	[Anzahl Stellen_Konto_Nr],
+	[Konto Art],
+	[GuV_Bilanz],
+	[Acct Nr],
+	[Konto],
+	[Susa]
+FROM [LOCOSOFT].[staging].[kontenrahmen_90]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 121 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_90.sql

@@ -0,0 +1,121 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[kontenrahmen_90]
+AS
+SELECT T1."KONTO_NR" AS "Konto Nr",
+	T1."KONTO_BEZEICHNUNG" AS "Konto Bezeichnung",
+	T1."KONTO_ART" AS "Konto Art_ori",
+	T1."KOSTENSTELLE" AS "Kostenstelle",
+	T1."STK" AS "Stk",
+	T1."KONTO_1" AS "Konto 1",
+	T1."KONTO_2" AS "Konto 2",
+	T1."KONTO_3" AS "Konto 3",
+	T1."KONTO_4" AS "Konto 4",
+	T1."KONTO_5" AS "Konto 5",
+	T1."EBENE1" AS "Ebene1",
+	T1."EBENE2" AS "Ebene2",
+	T1."EBENE3" AS "Ebene3",
+	T1."EBENE4" AS "Ebene4",
+	T1."EBENE5" AS "Ebene5",
+	T1."EBENE6" AS "Ebene6",
+	T1."EBENE7" AS "Ebene7",
+	T1."EBENE8" AS "Ebene8",
+	T1."EBENE9" AS "Ebene9",
+	T1."EBENE10" AS "Ebene10",
+	T1."EBENE11" AS "Ebene11",
+	T1."EBENE12" AS "Ebene12",
+	T1."EBENE13" AS "Ebene13",
+	T1."EBENE14" AS "Ebene14",
+	T1."EBENE15" AS "Ebene15",
+	T1."EBENE16" AS "Ebene16",
+	T1."EBENE17" AS "Ebene17",
+	T1."EBENE18" AS "Ebene18",
+	T1."EBENE19" AS "Ebene19",
+	T1."EBENE20" AS "Ebene20",
+	T1."EBENE21" AS "Ebene21",
+	T1."EBENE22" AS "Ebene22",
+	T1."EBENE23" AS "Ebene23",
+	T1."EBENE24" AS "Ebene24",
+	T1."EBENE25" AS "Ebene25",
+	T1."EBENE26" AS "Ebene26",
+	T1."EBENE27" AS "Ebene27",
+	T1."EBENE28" AS "Ebene28",
+	T1."EBENE29" AS "Ebene29",
+	T1."EBENE30" AS "Ebene30",
+	T1."EBENE31" AS "Ebene31",
+	T1."EBENE32" AS "Ebene32",
+	T1."EBENE33" AS "Ebene33",
+	T1."EBENE34" AS "Ebene34",
+	T1."EBENE35" AS "Ebene35",
+	T1."EBENE36" AS "Ebene36",
+	T1."EBENE37" AS "Ebene37",
+	T1."EBENE38" AS "Ebene38",
+	T1."EBENE39" AS "Ebene39",
+	T1."EBENE40" AS "Ebene40",
+	T1."EBENE41" AS "Ebene41",
+	T1."EBENE42" AS "Ebene42",
+	T1."EBENE43" AS "Ebene43",
+	T1."EBENE44" AS "Ebene44",
+	T1."EBENE45" AS "Ebene45",
+	T1."EBENE46" AS "Ebene46",
+	T1."EBENE47" AS "Ebene47",
+	T1."EBENE48" AS "Ebene48",
+	T1."EBENE49" AS "Ebene49",
+	T1."EBENE50" AS "Ebene50",
+	T1."EBENE51" AS "Ebene51",
+	T1."EBENE52" AS "Ebene52",
+	T1."EBENE53" AS "Ebene53",
+	T1."EBENE54" AS "Ebene54",
+	T1."EBENE55" AS "Ebene55",
+	T1."EBENE56" AS "Ebene56",
+	T1."EBENE57" AS "Ebene57",
+	T1."EBENE58" AS "Ebene58",
+	T1."EBENE59" AS "Ebene59",
+	T1."EBENE60" AS "Ebene60",
+	T1."EBENE61" AS "Ebene61",
+	T1."EBENE62" AS "Ebene62",
+	T1."EBENE63" AS "Ebene63",
+	T1."EBENE64" AS "Ebene64",
+	T1."EBENE65" AS "Ebene65",
+	T1."EBENE66" AS "Ebene66",
+	T1."EBENE67" AS "Ebene67",
+	T1."EBENE68" AS "Ebene68",
+	T1."EBENE69" AS "Ebene69",
+	T1."EBENE70" AS "Ebene70",
+	T1."EBENE71" AS "Ebene71",
+	T1."EBENE72" AS "Ebene72",
+	T1."EBENE73" AS "Ebene73",
+	T1."EBENE74" AS "Ebene74",
+	T1."EBENE75" AS "Ebene75",
+	T1."EBENE76" AS "Ebene76",
+	T1."EBENE77" AS "Ebene77",
+	T1."EBENE78" AS "Ebene78",
+	T1."EBENE79" AS "Ebene79",
+	T1."EBENE80" AS "Ebene80",
+	T1."EBENE81" AS "Ebene81",
+	T1."EBENE82" AS "Ebene82",
+	T1."EBENE83" AS "Ebene83",
+	T1."EBENE84" AS "Ebene84",
+	T1."EBENE85" AS "Ebene85",
+	T1."EBENE86" AS "Ebene86",
+	T1."EBENE87" AS "Ebene87",
+	T1."EBENE88" AS "Ebene88",
+	T1."EBENE89" AS "Ebene89",
+	T1."EBENE90" AS "Ebene90",
+	(len(T1."KONTO_NR" + 'Z') - 1) AS "Anzahl Stellen_Konto_Nr",
+	T1."KONTO_ART" AS "Konto Art",
+	T1."KONTO_ART" AS "GuV_Bilanz",
+	T1."KONTO_NR" AS "Acct Nr",
+	T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" AS "Konto",
+	(left(T1."KONTO_NR", 1)) AS "Susa"
+FROM OPENROWSET(BULK 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv', FORMATFILE = 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv.xml', FIRSTROW = 2) T1
+WHERE (((left(T1."KONTO_NR", 1))) <> '9')
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 0 - 121
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_gc_struct_skr.sql

@@ -1,121 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.kontenrahmen_gc_struct_skr AS
-
-select T1."KONTO_NR" as "Konto Nr",
-	   T1."KONTO_BEZEICHNUNG" as "Konto Bezeichnung",
-	   T1."KONTO_ART" as "Konto Art_ori",
-	   T1."KOSTENSTELLE" as "Kostenstelle",
-	   T1."STK" as "Stk",
-	   T1."KONTO_1" as "Konto 1",
-	   T1."KONTO_2" as "Konto 2",
-	   T1."KONTO_3" as "Konto 3",
-	   T1."KONTO_4" as "Konto 4",
-	   T1."KONTO_5" as "Konto 5",
-	   T1."EBENE1" as "Ebene1",
-	   T1."EBENE2" as "Ebene2",
-	   T1."EBENE3" as "Ebene3",
-	   T1."EBENE4" as "Ebene4",
-	   T1."EBENE5" as "Ebene5",
-	   T1."EBENE6" as "Ebene6",
-	   T1."EBENE7" as "Ebene7",
-	   T1."EBENE8" as "Ebene8",
-	   T1."EBENE9" as "Ebene9",
-	   T1."EBENE10" as "Ebene10",
-	   T1."EBENE11" as "Ebene11",
-	   T1."EBENE12" as "Ebene12",
-	   T1."EBENE13" as "Ebene13",
-	   T1."EBENE14" as "Ebene14",
-	   T1."EBENE15" as "Ebene15",
-	   T1."EBENE16" as "Ebene16",
-	   T1."EBENE17" as "Ebene17",
-	   T1."EBENE18" as "Ebene18",
-	   T1."EBENE19" as "Ebene19",
-	   T1."EBENE20" as "Ebene20",
-	   T1."EBENE21" as "Ebene21",
-	   T1."EBENE22" as "Ebene22",
-	   T1."EBENE23" as "Ebene23",
-	   T1."EBENE24" as "Ebene24",
-	   T1."EBENE25" as "Ebene25",
-	   T1."EBENE26" as "Ebene26",
-	   T1."EBENE27" as "Ebene27",
-	   T1."EBENE28" as "Ebene28",
-	   T1."EBENE29" as "Ebene29",
-	   T1."EBENE30" as "Ebene30",
-	   T1."EBENE31" as "Ebene31",
-	   T1."EBENE32" as "Ebene32",
-	   T1."EBENE33" as "Ebene33",
-	   T1."EBENE34" as "Ebene34",
-	   T1."EBENE35" as "Ebene35",
-	   T1."EBENE36" as "Ebene36",
-	   T1."EBENE37" as "Ebene37",
-	   T1."EBENE38" as "Ebene38",
-	   T1."EBENE39" as "Ebene39",
-	   T1."EBENE40" as "Ebene40",
-	   T1."EBENE41" as "Ebene41",
-	   T1."EBENE42" as "Ebene42",
-	   T1."EBENE43" as "Ebene43",
-	   T1."EBENE44" as "Ebene44",
-	   T1."EBENE45" as "Ebene45",
-	   T1."EBENE46" as "Ebene46",
-	   T1."EBENE47" as "Ebene47",
-	   T1."EBENE48" as "Ebene48",
-	   T1."EBENE49" as "Ebene49",
-	   T1."EBENE50" as "Ebene50",
-	   T1."EBENE51" as "Ebene51",
-	   T1."EBENE52" as "Ebene52",
-	   T1."EBENE53" as "Ebene53",
-	   T1."EBENE54" as "Ebene54",
-	   T1."EBENE55" as "Ebene55",
-	   T1."EBENE56" as "Ebene56",
-	   T1."EBENE57" as "Ebene57",
-	   T1."EBENE58" as "Ebene58",
-	   T1."EBENE59" as "Ebene59",
-	   T1."EBENE60" as "Ebene60",
-	   T1."EBENE61" as "Ebene61",
-	   T1."EBENE62" as "Ebene62",
-	   T1."EBENE63" as "Ebene63",
-	   T1."EBENE64" as "Ebene64",
-	   T1."EBENE65" as "Ebene65",
-	   T1."EBENE66" as "Ebene66",
-	   T1."EBENE67" as "Ebene67",
-	   T1."EBENE68" as "Ebene68",
-	   T1."EBENE69" as "Ebene69",
-	   T1."EBENE70" as "Ebene70",
-	   T1."EBENE71" as "Ebene71",
-	   T1."EBENE72" as "Ebene72",
-	   T1."EBENE73" as "Ebene73",
-	   T1."EBENE74" as "Ebene74",
-	   T1."EBENE75" as "Ebene75",
-	   T1."EBENE76" as "Ebene76",
-	   T1."EBENE77" as "Ebene77",
-	   T1."EBENE78" as "Ebene78",
-	   T1."EBENE79" as "Ebene79",
-	   T1."EBENE80" as "Ebene80",
-	   T1."EBENE81" as "Ebene81",
-	   T1."EBENE82" as "Ebene82",
-	   T1."EBENE83" as "Ebene83",
-	   T1."EBENE84" as "Ebene84",
-	   T1."EBENE85" as "Ebene85",
-	   T1."EBENE86" as "Ebene86",
-	   T1."EBENE87" as "Ebene87",
-	   T1."EBENE88" as "Ebene88",
-	   T1."EBENE89" as "Ebene89",
-	   T1."EBENE90" as "Ebene90",
-	   (len(T1."KONTO_NR" + 'Z') - 1) as "Anzahl Stellen_Konto_Nr",
-	   T1."KONTO_ART" as "Konto Art",
-	   T1."KONTO_ART" as "GuV_Bilanz",
-	   T1."KONTO_NR" as "Acct Nr",
-	   T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" as "Konto",
-	   (left(T1."KONTO_NR",1)) as "Susa"
-from "Kontenrahmen.csv" T1
-where (((left(T1."KONTO_NR",1))) <> '9')
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 121 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_gc_struct_skr_80.sql

@@ -0,0 +1,121 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[kontenrahmen_gc_struct_skr_80]
+AS
+SELECT [Konto Nr],
+	[Konto Bezeichnung],
+	[Konto Art_ori],
+	[Kostenstelle],
+	[Stk],
+	[Konto 1],
+	[Konto 2],
+	[Konto 3],
+	[Konto 4],
+	[Konto 5],
+	[Ebene1],
+	[Ebene2],
+	[Ebene3],
+	[Ebene4],
+	[Ebene5],
+	[Ebene6],
+	[Ebene7],
+	[Ebene8],
+	[Ebene9],
+	[Ebene10],
+	[Ebene11],
+	[Ebene12],
+	[Ebene13],
+	[Ebene14],
+	[Ebene15],
+	[Ebene16],
+	[Ebene17],
+	[Ebene18],
+	[Ebene19],
+	[Ebene20],
+	[Ebene21],
+	[Ebene22],
+	[Ebene23],
+	[Ebene24],
+	[Ebene25],
+	[Ebene26],
+	[Ebene27],
+	[Ebene28],
+	[Ebene29],
+	[Ebene30],
+	[Ebene31],
+	[Ebene32],
+	[Ebene33],
+	[Ebene34],
+	[Ebene35],
+	[Ebene36],
+	[Ebene37],
+	[Ebene38],
+	[Ebene39],
+	[Ebene40],
+	[Ebene41],
+	[Ebene42],
+	[Ebene43],
+	[Ebene44],
+	[Ebene45],
+	[Ebene46],
+	[Ebene47],
+	[Ebene48],
+	[Ebene49],
+	[Ebene50],
+	[Ebene51],
+	[Ebene52],
+	[Ebene53],
+	[Ebene54],
+	[Ebene55],
+	[Ebene56],
+	[Ebene57],
+	[Ebene58],
+	[Ebene59],
+	[Ebene60],
+	[Ebene61],
+	[Ebene62],
+	[Ebene63],
+	[Ebene64],
+	[Ebene65],
+	[Ebene66],
+	[Ebene67],
+	[Ebene68],
+	[Ebene69],
+	[Ebene70],
+	[Ebene71],
+	[Ebene72],
+	[Ebene73],
+	[Ebene74],
+	[Ebene75],
+	[Ebene76],
+	[Ebene77],
+	[Ebene78],
+	[Ebene79],
+	[Ebene80],
+	[Ebene81],
+	[Ebene82],
+	[Ebene83],
+	[Ebene84],
+	[Ebene85],
+	[Ebene86],
+	[Ebene87],
+	[Ebene88],
+	[Ebene89],
+	[Ebene90],
+	[Anzahl Stellen_Konto_Nr],
+	[Konto Art],
+	[GuV_Bilanz],
+	[Acct Nr],
+	[Konto],
+	[Susa]
+FROM [LOCOSOFT].[staging].[kontenrahmen_gc_struct_skr_90]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 121 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_gc_struct_skr_imr.sql

@@ -0,0 +1,121 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[kontenrahmen_gc_struct_skr_imr]
+AS
+SELECT T1."KONTO_NR" AS "Konto Nr",
+	T1."KONTO_BEZEICHNUNG" AS "Konto Bezeichnung",
+	T1."KONTO_ART" AS "Konto Art_ori",
+	T1."KOSTENSTELLE" AS "Kostenstelle",
+	T1."STK" AS "Stk",
+	T1."KONTO_1" AS "Konto 1",
+	T1."KONTO_2" AS "Konto 2",
+	T1."KONTO_3" AS "Konto 3",
+	T1."KONTO_4" AS "Konto 4",
+	T1."KONTO_5" AS "Konto 5",
+	T1."EBENE1" AS "Ebene1",
+	T1."EBENE2" AS "Ebene2",
+	T1."EBENE3" AS "Ebene3",
+	T1."EBENE4" AS "Ebene4",
+	T1."EBENE5" AS "Ebene5",
+	T1."EBENE6" AS "Ebene6",
+	T1."EBENE7" AS "Ebene7",
+	T1."EBENE8" AS "Ebene8",
+	T1."EBENE9" AS "Ebene9",
+	T1."EBENE10" AS "Ebene10",
+	T1."EBENE11" AS "Ebene11",
+	T1."EBENE12" AS "Ebene12",
+	T1."EBENE13" AS "Ebene13",
+	T1."EBENE14" AS "Ebene14",
+	T1."EBENE15" AS "Ebene15",
+	T1."EBENE16" AS "Ebene16",
+	T1."EBENE17" AS "Ebene17",
+	T1."EBENE18" AS "Ebene18",
+	T1."EBENE19" AS "Ebene19",
+	T1."EBENE20" AS "Ebene20",
+	T1."EBENE21" AS "Ebene21",
+	T1."EBENE22" AS "Ebene22",
+	T1."EBENE23" AS "Ebene23",
+	T1."EBENE24" AS "Ebene24",
+	T1."EBENE25" AS "Ebene25",
+	T1."EBENE26" AS "Ebene26",
+	T1."EBENE27" AS "Ebene27",
+	T1."EBENE28" AS "Ebene28",
+	T1."EBENE29" AS "Ebene29",
+	T1."EBENE30" AS "Ebene30",
+	T1."EBENE31" AS "Ebene31",
+	T1."EBENE32" AS "Ebene32",
+	T1."EBENE33" AS "Ebene33",
+	T1."EBENE34" AS "Ebene34",
+	T1."EBENE35" AS "Ebene35",
+	T1."EBENE36" AS "Ebene36",
+	T1."EBENE37" AS "Ebene37",
+	T1."EBENE38" AS "Ebene38",
+	T1."EBENE39" AS "Ebene39",
+	T1."EBENE40" AS "Ebene40",
+	T1."EBENE41" AS "Ebene41",
+	T1."EBENE42" AS "Ebene42",
+	T1."EBENE43" AS "Ebene43",
+	T1."EBENE44" AS "Ebene44",
+	T1."EBENE45" AS "Ebene45",
+	T1."EBENE46" AS "Ebene46",
+	T1."EBENE47" AS "Ebene47",
+	T1."EBENE48" AS "Ebene48",
+	T1."EBENE49" AS "Ebene49",
+	T1."EBENE50" AS "Ebene50",
+	T1."EBENE51" AS "Ebene51",
+	T1."EBENE52" AS "Ebene52",
+	T1."EBENE53" AS "Ebene53",
+	T1."EBENE54" AS "Ebene54",
+	T1."EBENE55" AS "Ebene55",
+	T1."EBENE56" AS "Ebene56",
+	T1."EBENE57" AS "Ebene57",
+	T1."EBENE58" AS "Ebene58",
+	T1."EBENE59" AS "Ebene59",
+	T1."EBENE60" AS "Ebene60",
+	T1."EBENE61" AS "Ebene61",
+	T1."EBENE62" AS "Ebene62",
+	T1."EBENE63" AS "Ebene63",
+	T1."EBENE64" AS "Ebene64",
+	T1."EBENE65" AS "Ebene65",
+	T1."EBENE66" AS "Ebene66",
+	T1."EBENE67" AS "Ebene67",
+	T1."EBENE68" AS "Ebene68",
+	T1."EBENE69" AS "Ebene69",
+	T1."EBENE70" AS "Ebene70",
+	T1."EBENE71" AS "Ebene71",
+	T1."EBENE72" AS "Ebene72",
+	T1."EBENE73" AS "Ebene73",
+	T1."EBENE74" AS "Ebene74",
+	T1."EBENE75" AS "Ebene75",
+	T1."EBENE76" AS "Ebene76",
+	T1."EBENE77" AS "Ebene77",
+	T1."EBENE78" AS "Ebene78",
+	T1."EBENE79" AS "Ebene79",
+	T1."EBENE80" AS "Ebene80",
+	T1."EBENE81" AS "Ebene81",
+	T1."EBENE82" AS "Ebene82",
+	T1."EBENE83" AS "Ebene83",
+	T1."EBENE84" AS "Ebene84",
+	T1."EBENE85" AS "Ebene85",
+	T1."EBENE86" AS "Ebene86",
+	T1."EBENE87" AS "Ebene87",
+	T1."EBENE88" AS "Ebene88",
+	T1."EBENE89" AS "Ebene89",
+	T1."EBENE90" AS "Ebene90",
+	(len(T1."KONTO_NR" + 'Z') - 1) AS "Anzahl Stellen_Konto_Nr",
+	T1."KONTO_ART" AS "Konto Art",
+	T1."KONTO_ART" AS "GuV_Bilanz",
+	T1."KONTO_NR" AS "Acct Nr",
+	T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" AS "Konto",
+	(left(T1."KONTO_NR", 1)) AS "Susa"
+FROM OPENROWSET(BULK 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv', FORMATFILE = 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv.xml', FIRSTROW = 2) T1
+WHERE (((left(T1."KONTO_NR", 1))) <> '9')
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 121 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kontenrahmen_imr.sql

@@ -0,0 +1,121 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[kontenrahmen_imr]
+AS
+SELECT T1."KONTO_NR" AS "Konto Nr",
+	T1."KONTO_BEZEICHNUNG" AS "Konto Bezeichnung",
+	T1."KONTO_ART" AS "Konto Art_ori",
+	T1."KOSTENSTELLE" AS "Kostenstelle",
+	T1."STK" AS "Stk",
+	T1."KONTO_1" AS "Konto 1",
+	T1."KONTO_2" AS "Konto 2",
+	T1."KONTO_3" AS "Konto 3",
+	T1."KONTO_4" AS "Konto 4",
+	T1."KONTO_5" AS "Konto 5",
+	T1."EBENE1" AS "Ebene1",
+	T1."EBENE2" AS "Ebene2",
+	T1."EBENE3" AS "Ebene3",
+	T1."EBENE4" AS "Ebene4",
+	T1."EBENE5" AS "Ebene5",
+	T1."EBENE6" AS "Ebene6",
+	T1."EBENE7" AS "Ebene7",
+	T1."EBENE8" AS "Ebene8",
+	T1."EBENE9" AS "Ebene9",
+	T1."EBENE10" AS "Ebene10",
+	T1."EBENE11" AS "Ebene11",
+	T1."EBENE12" AS "Ebene12",
+	T1."EBENE13" AS "Ebene13",
+	T1."EBENE14" AS "Ebene14",
+	T1."EBENE15" AS "Ebene15",
+	T1."EBENE16" AS "Ebene16",
+	T1."EBENE17" AS "Ebene17",
+	T1."EBENE18" AS "Ebene18",
+	T1."EBENE19" AS "Ebene19",
+	T1."EBENE20" AS "Ebene20",
+	T1."EBENE21" AS "Ebene21",
+	T1."EBENE22" AS "Ebene22",
+	T1."EBENE23" AS "Ebene23",
+	T1."EBENE24" AS "Ebene24",
+	T1."EBENE25" AS "Ebene25",
+	T1."EBENE26" AS "Ebene26",
+	T1."EBENE27" AS "Ebene27",
+	T1."EBENE28" AS "Ebene28",
+	T1."EBENE29" AS "Ebene29",
+	T1."EBENE30" AS "Ebene30",
+	T1."EBENE31" AS "Ebene31",
+	T1."EBENE32" AS "Ebene32",
+	T1."EBENE33" AS "Ebene33",
+	T1."EBENE34" AS "Ebene34",
+	T1."EBENE35" AS "Ebene35",
+	T1."EBENE36" AS "Ebene36",
+	T1."EBENE37" AS "Ebene37",
+	T1."EBENE38" AS "Ebene38",
+	T1."EBENE39" AS "Ebene39",
+	T1."EBENE40" AS "Ebene40",
+	T1."EBENE41" AS "Ebene41",
+	T1."EBENE42" AS "Ebene42",
+	T1."EBENE43" AS "Ebene43",
+	T1."EBENE44" AS "Ebene44",
+	T1."EBENE45" AS "Ebene45",
+	T1."EBENE46" AS "Ebene46",
+	T1."EBENE47" AS "Ebene47",
+	T1."EBENE48" AS "Ebene48",
+	T1."EBENE49" AS "Ebene49",
+	T1."EBENE50" AS "Ebene50",
+	T1."EBENE51" AS "Ebene51",
+	T1."EBENE52" AS "Ebene52",
+	T1."EBENE53" AS "Ebene53",
+	T1."EBENE54" AS "Ebene54",
+	T1."EBENE55" AS "Ebene55",
+	T1."EBENE56" AS "Ebene56",
+	T1."EBENE57" AS "Ebene57",
+	T1."EBENE58" AS "Ebene58",
+	T1."EBENE59" AS "Ebene59",
+	T1."EBENE60" AS "Ebene60",
+	T1."EBENE61" AS "Ebene61",
+	T1."EBENE62" AS "Ebene62",
+	T1."EBENE63" AS "Ebene63",
+	T1."EBENE64" AS "Ebene64",
+	T1."EBENE65" AS "Ebene65",
+	T1."EBENE66" AS "Ebene66",
+	T1."EBENE67" AS "Ebene67",
+	T1."EBENE68" AS "Ebene68",
+	T1."EBENE69" AS "Ebene69",
+	T1."EBENE70" AS "Ebene70",
+	T1."EBENE71" AS "Ebene71",
+	T1."EBENE72" AS "Ebene72",
+	T1."EBENE73" AS "Ebene73",
+	T1."EBENE74" AS "Ebene74",
+	T1."EBENE75" AS "Ebene75",
+	T1."EBENE76" AS "Ebene76",
+	T1."EBENE77" AS "Ebene77",
+	T1."EBENE78" AS "Ebene78",
+	T1."EBENE79" AS "Ebene79",
+	T1."EBENE80" AS "Ebene80",
+	T1."EBENE81" AS "Ebene81",
+	T1."EBENE82" AS "Ebene82",
+	T1."EBENE83" AS "Ebene83",
+	T1."EBENE84" AS "Ebene84",
+	T1."EBENE85" AS "Ebene85",
+	T1."EBENE86" AS "Ebene86",
+	T1."EBENE87" AS "Ebene87",
+	T1."EBENE88" AS "Ebene88",
+	T1."EBENE89" AS "Ebene89",
+	T1."EBENE90" AS "Ebene90",
+	(len(T1."KONTO_NR" + 'Z') - 1) AS "Anzahl Stellen_Konto_Nr",
+	T1."KONTO_ART" AS "Konto Art",
+	T1."KONTO_ART" AS "GuV_Bilanz",
+	T1."KONTO_NR" AS "Acct Nr",
+	T1."KONTO_NR" + ' - ' + T1."KONTO_BEZEICHNUNG" AS "Konto",
+	(left(T1."KONTO_NR", 1)) AS "Susa"
+FROM OPENROWSET(BULK 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv', FORMATFILE = 'C:\GlobalCube_LOCOSOFT\GCStruct_SKR51\Kontenrahmen\Kontenrahmen.csv.xml', FIRSTROW = 2) T1
+WHERE (((left(T1."KONTO_NR", 1))) <> '9')
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 95 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kreditorenbewegungen_80.sql

@@ -0,0 +1,95 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[kreditorenbewegungen_80]
+AS
+SELECT c112 AS "Accounting Date",
+	c154 AS "Document Type",
+	c153 AS "Document Number",
+	c152 AS "Position In Document",
+	c109 AS "Nominal Account Number",
+	c151 AS "Customer Number",
+	c150 AS "Is Balanced",
+	c149 AS "Clearing Number",
+	c148 AS "Document Date",
+	c147 AS "Posted Value",
+	c146 AS "Debit Or Credit",
+	c145 AS "Posted Count",
+	c144 AS "Branch Number",
+	c143 AS "Customer Contra Account",
+	c142 AS "Nominal Contra Account",
+	c141 AS "Contra Account Text",
+	c140 AS "Account Form Page Number",
+	c139 AS "Account Form Page Line",
+	c138 AS "Serial Number Each Month",
+	c137 AS "Employee Number",
+	c136 AS "Invoice Date",
+	c135 AS "Invoice Number",
+	c134 AS "Dunning Level",
+	c133 AS "Last Dunning Date",
+	c132 AS "Journal Page",
+	c131 AS "Journal Line",
+	c130 AS "Cash Discount",
+	c129 AS "Term Of Payment",
+	c128 AS "Posting Text",
+	c127 AS "Vehicle Reference",
+	c126 AS "Vat Id Number",
+	c125 AS "Account Statement Number",
+	c124 AS "Account Statement Page",
+	c123 AS "Vat Key",
+	c122 AS "Days For Cash Discount",
+	c121 AS "Day Of Actual Accounting",
+	c120 AS "Skr51 Branch",
+	c119 AS "Skr51 Make",
+	c118 AS "Skr51 Cost Center",
+	c117 AS "Skr51 Sales Channel",
+	c116 AS "Skr51 Cost Unit",
+	c115 AS "Previously Used Account No",
+	c114 AS "Free Form Accounting Text",
+	c113 AS "Free Form Document Text",
+	'1' AS "Rechtseinheit",
+	c85 AS "Betrieb",
+	c112 AS "Bookkeep Date",
+	c111 AS "Text",
+	'1' AS "Mandant",
+	c97 AS "Betrag",
+	c110 AS "Menge",
+	c109 AS "Acct Nr",
+	c83 AS "Customer Number_suctomer_supplier",
+	c108 AS "Is Supplier",
+	c107 AS "First Name",
+	c106 AS "Family Name",
+	c105 AS "Document Type In Journal",
+	c104 AS "Document Type Description",
+	SUM(c97) OVER (PARTITION BY c83) AS "Debitorsaldo_",
+	c103 AS "Invoice Type_Invoices",
+	c102 AS "Invoice Number_Invoices",
+	c101 AS "Subsidiary_Invoices",
+	c100 AS "Invoice Date_Invoices",
+	'1' AS "Hauptbetrieb",
+	c99 AS "Standort_ori",
+	c98 AS "Sel Name",
+	c97 AS "OP-Saldo",
+	c96 AS "Kostenstelle",
+	c95 AS "Tage",
+	c94 AS "Staffel",
+	c93 AS "Kunde",
+	c92 AS "Beleg",
+	c91 AS "Employee Number_Employees_journal_accountings",
+	c90 AS "Name_Employees_journal_accountings",
+	c89 AS "Anzahl_Stellen_Invoice_Number",
+	c88 AS "Forderungsart_aus_erste_Stelle_Inv_Number",
+	c87 AS "Forderungsart",
+	c86 AS "Standort_aus_2_Stelle_Invoice_Number",
+	c85 AS "Standort",
+	c84 AS "Status Rechnung"
+FROM [staging].[kreditorenbewegungen_90]
+	-- order by "Customer Number" asc,"Invoice Number" asc,"Document Type In Journal" asc,"Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 277 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kreditorenbewegungen_90.sql

@@ -0,0 +1,277 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[kreditorenbewegungen_90]
+AS
+SELECT T3."customer_number" AS c83,
+	CASE 
+		WHEN (T1."clearing_number" = 0)
+			THEN ('offen')
+		ELSE ('bezahlt')
+		END AS c84,
+	('0' + (convert(VARCHAR(50), T1."branch_number"))) AS c85,
+	CASE 
+		WHEN (
+				(((len(T1."invoice_number"))) = 7)
+				AND ((substring(T1."invoice_number", 2, 1)) BETWEEN '1' AND '4')
+				)
+			THEN ('0' + (substring(T1."invoice_number", 2, 1)))
+		ELSE NULL
+		END AS c86,
+	CASE 
+		WHEN (
+				(
+					CASE 
+						WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+							THEN ('3')
+						WHEN (T5."invoice_type" IN (5))
+							THEN ('6')
+						WHEN (T5."invoice_type" IN (7))
+							THEN ('1')
+						WHEN (T5."invoice_type" IN (8))
+							THEN ('2')
+						WHEN (T4."document_type_in_journal" = 'R')
+							THEN ('7')
+						ELSE NULL
+						END
+					) = '1'
+				)
+			THEN ('Neuwagen')
+		WHEN (
+				(
+					CASE 
+						WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+							THEN ('3')
+						WHEN (T5."invoice_type" IN (5))
+							THEN ('6')
+						WHEN (T5."invoice_type" IN (7))
+							THEN ('1')
+						WHEN (T5."invoice_type" IN (8))
+							THEN ('2')
+						WHEN (T4."document_type_in_journal" = 'R')
+							THEN ('7')
+						ELSE NULL
+						END
+					) = '2'
+				)
+			THEN ('Gebrauchtwagen')
+		WHEN (
+				(
+					CASE 
+						WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+							THEN ('3')
+						WHEN (T5."invoice_type" IN (5))
+							THEN ('6')
+						WHEN (T5."invoice_type" IN (7))
+							THEN ('1')
+						WHEN (T5."invoice_type" IN (8))
+							THEN ('2')
+						WHEN (T4."document_type_in_journal" = 'R')
+							THEN ('7')
+						ELSE NULL
+						END
+					) = '3'
+				)
+			THEN ('Service')
+		WHEN (
+				(
+					CASE 
+						WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+							THEN ('3')
+						WHEN (T5."invoice_type" IN (5))
+							THEN ('6')
+						WHEN (T5."invoice_type" IN (7))
+							THEN ('1')
+						WHEN (T5."invoice_type" IN (8))
+							THEN ('2')
+						WHEN (T4."document_type_in_journal" = 'R')
+							THEN ('7')
+						ELSE NULL
+						END
+					) = '6'
+				)
+			THEN ('Teile')
+		ELSE ('nicht zuzuordnen')
+		END AS c87,
+	CASE 
+		WHEN (
+				(((len(T1."invoice_number"))) = 7)
+				AND ((substring(T1."invoice_number", 1, 1)) IN ('2', '3', '4'))
+				)
+			THEN ('Service')
+		WHEN (
+				(((len(T1."invoice_number"))) = 7)
+				AND ((substring(T1."invoice_number", 1, 1)) IN ('5'))
+				)
+			THEN ('Teile')
+		WHEN (
+				(((len(T1."invoice_number"))) = 7)
+				AND ((substring(T1."invoice_number", 1, 1)) IN ('6'))
+				)
+			THEN ('Garantie')
+		WHEN (
+				(((len(T1."invoice_number"))) = 7)
+				AND ((substring(T1."invoice_number", 1, 1)) IN ('7'))
+				)
+			THEN ('Neuwagen')
+		WHEN (
+				(((len(T1."invoice_number"))) = 7)
+				AND ((substring(T1."invoice_number", 1, 1)) IN ('8'))
+				)
+			THEN ('Gebrauchtwagen')
+		WHEN (T1."document_type" = 'R')
+			THEN ('Rent')
+		ELSE ('nicht zuzuordnen')
+		END AS c88,
+	(len(T1."invoice_number")) AS c89,
+	T2."name" AS c90,
+	T2."employee_number" AS c91,
+	CASE 
+		WHEN (T1."posting_text" IS NOT NULL)
+			THEN ((substring((convert(VARCHAR(50), T1."document_number")), 1, 7)) + ' - ' + T1."posting_text" + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))
+		ELSE ((convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))
+		END AS c92,
+	((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name") AS c93,
+	CASE 
+		WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 0 AND 14)
+			THEN ('< 2 Wochen')
+		WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 15 AND 28)
+			THEN ('2 - 4 Wochen')
+		WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 29 AND 42)
+			THEN ('4 - 6 Wochen')
+		WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 43 AND 84)
+			THEN ('6 - 12 Wochen')
+		WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) > 84)
+			THEN ('> 12 Wochen')
+		ELSE NULL
+		END AS c94,
+	(day((getdate()) - (convert(DATETIME, T1."accounting_date")))) AS c95,
+	CASE 
+		WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+			THEN ('3')
+		WHEN (T5."invoice_type" IN (5))
+			THEN ('6')
+		WHEN (T5."invoice_type" IN (7))
+			THEN ('1')
+		WHEN (T5."invoice_type" IN (8))
+			THEN ('2')
+		WHEN (T4."document_type_in_journal" = 'R')
+			THEN ('7')
+		ELSE NULL
+		END AS c96,
+	(
+		CASE 
+			WHEN (T1."debit_or_credit" = 'H')
+				THEN (T1."posted_value" / 100)
+			ELSE (T1."posted_value" / 100 * - 1)
+			END
+		) AS c97,
+	(substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name" AS c98,
+	CASE 
+		WHEN (T5."subsidiary" IS NOT NULL)
+			THEN ('0' + (substring((convert(VARCHAR(50), T5."subsidiary")), 1, 1)))
+		ELSE ('nicht zuzuordnen')
+		END AS c99,
+	T5."invoice_date" AS c100,
+	T5."subsidiary" AS c101,
+	T5."invoice_number" AS c102,
+	T5."invoice_type" AS c103,
+	T4."document_type_description" AS c104,
+	T4."document_type_in_journal" AS c105,
+	T3."family_name" AS c106,
+	T3."first_name" AS c107,
+	T3."is_supplier" AS c108,
+	T1."nominal_account_number" AS c109,
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_count" / 100 * - 1)
+		ELSE (T1."posted_count" / 100)
+		END AS c110,
+	((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))) AS c111,
+	T1."accounting_date" AS c112,
+	CASE 
+		WHEN (
+				(
+					(
+						(
+							((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%RG-BONUS%')
+							OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%GEBURTSTAGS%')
+							)
+						OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%STARTGUTHABEN%')
+						)
+					OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%BONUS F%')
+					)
+				OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%RG-ABZUG%')
+				)
+			THEN ('Bonus/Startguthaben')
+		ELSE ('ohne Bonus/Startguthaben')
+		END AS c113,
+	T1."free_form_accounting_text" AS c114,
+	T1."previously_used_account_no" AS c115,
+	T1."skr51_cost_unit" AS c116,
+	T1."skr51_sales_channel" AS c117,
+	T1."skr51_cost_center" AS c118,
+	T1."skr51_make" AS c119,
+	T1."skr51_branch" AS c120,
+	T1."day_of_actual_accounting" AS c121,
+	T1."days_for_cash_discount" AS c122,
+	T1."vat_key" AS c123,
+	T1."account_statement_page" AS c124,
+	T1."account_statement_number" AS c125,
+	T1."vat_id_number" AS c126,
+	T1."vehicle_reference" AS c127,
+	T1."posting_text" AS c128,
+	T1."term_of_payment" AS c129,
+	T1."cash_discount" AS c130,
+	T1."journal_line" AS c131,
+	T1."journal_page" AS c132,
+	T1."last_dunning_date" AS c133,
+	T1."dunning_level" AS c134,
+	T1."invoice_number" AS c135,
+	T1."invoice_date" AS c136,
+	T1."employee_number" AS c137,
+	T1."serial_number_each_month" AS c138,
+	T1."account_form_page_line" AS c139,
+	T1."account_form_page_number" AS c140,
+	T1."contra_account_text" AS c141,
+	T1."nominal_contra_account" AS c142,
+	T1."customer_contra_account" AS c143,
+	T1."branch_number" AS c144,
+	T1."posted_count" AS c145,
+	T1."debit_or_credit" AS c146,
+	T1."posted_value" AS c147,
+	T1."document_date" AS c148,
+	T1."clearing_number" AS c149,
+	T1."is_balanced" AS c150,
+	T1."customer_number" AS c151,
+	T1."position_in_document" AS c152,
+	T1."document_number" AS c153,
+	T1."document_type" AS c154
+FROM (
+	(
+		(
+			(
+				"journal_accountings" T1 LEFT OUTER JOIN "LOCOSOFT"."dbo"."employees" T2 ON T1."employee_number" = T2."employee_number"
+				) LEFT OUTER JOIN "LOCOSOFT"."dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."customer_number"
+			) LEFT OUTER JOIN "document_types" T4 ON T4."document_type_in_journal" = T1."document_type"
+		) LEFT OUTER JOIN "invoices" T5 ON T5."invtype_invnr" = T1."invoice_number"
+	)
+WHERE (
+		(
+			(
+				(T1."nominal_account_number" IN (1600, 1610))
+				AND (T1."customer_number" IS NOT NULL)
+				)
+			AND (T3."customer_number" IS NOT NULL)
+			)
+		AND (T1."document_type" IN ('W', 'E', 'L'))
+		)
+	-- order by "Customer Number" asc,"Invoice Number" asc,"Document Type In Journal" asc,"Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 359 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.kreditorenbewegungen_imr.sql

@@ -0,0 +1,359 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[kreditorenbewegungen_imr]
+AS
+SELECT c112 AS "Accounting Date",
+	c154 AS "Document Type",
+	c153 AS "Document Number",
+	c152 AS "Position In Document",
+	c109 AS "Nominal Account Number",
+	c151 AS "Customer Number",
+	c150 AS "Is Balanced",
+	c149 AS "Clearing Number",
+	c148 AS "Document Date",
+	c147 AS "Posted Value",
+	c146 AS "Debit Or Credit",
+	c145 AS "Posted Count",
+	c144 AS "Branch Number",
+	c143 AS "Customer Contra Account",
+	c142 AS "Nominal Contra Account",
+	c141 AS "Contra Account Text",
+	c140 AS "Account Form Page Number",
+	c139 AS "Account Form Page Line",
+	c138 AS "Serial Number Each Month",
+	c137 AS "Employee Number",
+	c136 AS "Invoice Date",
+	c135 AS "Invoice Number",
+	c134 AS "Dunning Level",
+	c133 AS "Last Dunning Date",
+	c132 AS "Journal Page",
+	c131 AS "Journal Line",
+	c130 AS "Cash Discount",
+	c129 AS "Term Of Payment",
+	c128 AS "Posting Text",
+	c127 AS "Vehicle Reference",
+	c126 AS "Vat Id Number",
+	c125 AS "Account Statement Number",
+	c124 AS "Account Statement Page",
+	c123 AS "Vat Key",
+	c122 AS "Days For Cash Discount",
+	c121 AS "Day Of Actual Accounting",
+	c120 AS "Skr51 Branch",
+	c119 AS "Skr51 Make",
+	c118 AS "Skr51 Cost Center",
+	c117 AS "Skr51 Sales Channel",
+	c116 AS "Skr51 Cost Unit",
+	c115 AS "Previously Used Account No",
+	c114 AS "Free Form Accounting Text",
+	c113 AS "Free Form Document Text",
+	'1' AS "Rechtseinheit",
+	c85 AS "Betrieb",
+	c112 AS "Bookkeep Date",
+	c111 AS "Text",
+	'1' AS "Mandant",
+	c97 AS "Betrag",
+	c110 AS "Menge",
+	c109 AS "Acct Nr",
+	c83 AS "Customer Number_suctomer_supplier",
+	c108 AS "Is Supplier",
+	c107 AS "First Name",
+	c106 AS "Family Name",
+	c105 AS "Document Type In Journal",
+	c104 AS "Document Type Description",
+	SUM(c97) OVER (PARTITION BY c83) AS "Debitorsaldo_",
+	c103 AS "Invoice Type_Invoices",
+	c102 AS "Invoice Number_Invoices",
+	c101 AS "Subsidiary_Invoices",
+	c100 AS "Invoice Date_Invoices",
+	'1' AS "Hauptbetrieb",
+	c99 AS "Standort_ori",
+	c98 AS "Sel Name",
+	c97 AS "OP-Saldo",
+	c96 AS "Kostenstelle",
+	c95 AS "Tage",
+	c94 AS "Staffel",
+	c93 AS "Kunde",
+	c92 AS "Beleg",
+	c91 AS "Employee Number_Employees_journal_accountings",
+	c90 AS "Name_Employees_journal_accountings",
+	c89 AS "Anzahl_Stellen_Invoice_Number",
+	c88 AS "Forderungsart_aus_erste_Stelle_Inv_Number",
+	c87 AS "Forderungsart",
+	c86 AS "Standort_aus_2_Stelle_Invoice_Number",
+	c85 AS "Standort",
+	c84 AS "Status Rechnung"
+FROM (
+	SELECT T3."customer_number" AS c83,
+		CASE 
+			WHEN (T1."clearing_number" = 0)
+				THEN ('offen')
+			ELSE ('bezahlt')
+			END AS c84,
+		('0' + (convert(VARCHAR(50), T1."branch_number"))) AS c85,
+		CASE 
+			WHEN (
+					(((len(T1."invoice_number"))) = 7)
+					AND ((substring(T1."invoice_number", 2, 1)) BETWEEN '1' AND '4')
+					)
+				THEN ('0' + (substring(T1."invoice_number", 2, 1)))
+			ELSE NULL
+			END AS c86,
+		CASE 
+			WHEN (
+					(
+						CASE 
+							WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+								THEN ('3')
+							WHEN (T5."invoice_type" IN (5))
+								THEN ('6')
+							WHEN (T5."invoice_type" IN (7))
+								THEN ('1')
+							WHEN (T5."invoice_type" IN (8))
+								THEN ('2')
+							WHEN (T4."document_type_in_journal" = 'R')
+								THEN ('7')
+							ELSE NULL
+							END
+						) = '1'
+					)
+				THEN ('Neuwagen')
+			WHEN (
+					(
+						CASE 
+							WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+								THEN ('3')
+							WHEN (T5."invoice_type" IN (5))
+								THEN ('6')
+							WHEN (T5."invoice_type" IN (7))
+								THEN ('1')
+							WHEN (T5."invoice_type" IN (8))
+								THEN ('2')
+							WHEN (T4."document_type_in_journal" = 'R')
+								THEN ('7')
+							ELSE NULL
+							END
+						) = '2'
+					)
+				THEN ('Gebrauchtwagen')
+			WHEN (
+					(
+						CASE 
+							WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+								THEN ('3')
+							WHEN (T5."invoice_type" IN (5))
+								THEN ('6')
+							WHEN (T5."invoice_type" IN (7))
+								THEN ('1')
+							WHEN (T5."invoice_type" IN (8))
+								THEN ('2')
+							WHEN (T4."document_type_in_journal" = 'R')
+								THEN ('7')
+							ELSE NULL
+							END
+						) = '3'
+					)
+				THEN ('Service')
+			WHEN (
+					(
+						CASE 
+							WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+								THEN ('3')
+							WHEN (T5."invoice_type" IN (5))
+								THEN ('6')
+							WHEN (T5."invoice_type" IN (7))
+								THEN ('1')
+							WHEN (T5."invoice_type" IN (8))
+								THEN ('2')
+							WHEN (T4."document_type_in_journal" = 'R')
+								THEN ('7')
+							ELSE NULL
+							END
+						) = '6'
+					)
+				THEN ('Teile')
+			ELSE ('nicht zuzuordnen')
+			END AS c87,
+		CASE 
+			WHEN (
+					(((len(T1."invoice_number"))) = 7)
+					AND ((substring(T1."invoice_number", 1, 1)) IN ('2', '3', '4'))
+					)
+				THEN ('Service')
+			WHEN (
+					(((len(T1."invoice_number"))) = 7)
+					AND ((substring(T1."invoice_number", 1, 1)) IN ('5'))
+					)
+				THEN ('Teile')
+			WHEN (
+					(((len(T1."invoice_number"))) = 7)
+					AND ((substring(T1."invoice_number", 1, 1)) IN ('6'))
+					)
+				THEN ('Garantie')
+			WHEN (
+					(((len(T1."invoice_number"))) = 7)
+					AND ((substring(T1."invoice_number", 1, 1)) IN ('7'))
+					)
+				THEN ('Neuwagen')
+			WHEN (
+					(((len(T1."invoice_number"))) = 7)
+					AND ((substring(T1."invoice_number", 1, 1)) IN ('8'))
+					)
+				THEN ('Gebrauchtwagen')
+			WHEN (T1."document_type" = 'R')
+				THEN ('Rent')
+			ELSE ('nicht zuzuordnen')
+			END AS c88,
+		(len(T1."invoice_number")) AS c89,
+		T2."name" AS c90,
+		T2."employee_number" AS c91,
+		CASE 
+			WHEN (T1."posting_text" IS NOT NULL)
+				THEN ((substring((convert(VARCHAR(50), T1."document_number")), 1, 7)) + ' - ' + T1."posting_text" + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))
+			ELSE ((convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))
+			END AS c92,
+		((substring((convert(VARCHAR(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name") AS c93,
+		CASE 
+			WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 0 AND 14)
+				THEN ('< 2 Wochen')
+			WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 15 AND 28)
+				THEN ('2 - 4 Wochen')
+			WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 29 AND 42)
+				THEN ('4 - 6 Wochen')
+			WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) BETWEEN 43 AND 84)
+				THEN ('6 - 12 Wochen')
+			WHEN (((day((getdate()) - (convert(DATETIME, T1."accounting_date"))))) > 84)
+				THEN ('> 12 Wochen')
+			ELSE NULL
+			END AS c94,
+		(day((getdate()) - (convert(DATETIME, T1."accounting_date")))) AS c95,
+		CASE 
+			WHEN (T5."invoice_type" IN (2, 4, 6, 3))
+				THEN ('3')
+			WHEN (T5."invoice_type" IN (5))
+				THEN ('6')
+			WHEN (T5."invoice_type" IN (7))
+				THEN ('1')
+			WHEN (T5."invoice_type" IN (8))
+				THEN ('2')
+			WHEN (T4."document_type_in_journal" = 'R')
+				THEN ('7')
+			ELSE NULL
+			END AS c96,
+		(
+			CASE 
+				WHEN (T1."debit_or_credit" = 'H')
+					THEN (T1."posted_value" / 100)
+				ELSE (T1."posted_value" / 100 * - 1)
+				END
+			) AS c97,
+		(substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name" AS c98,
+		CASE 
+			WHEN (T5."subsidiary" IS NOT NULL)
+				THEN ('0' + (substring((convert(VARCHAR(50), T5."subsidiary")), 1, 1)))
+			ELSE ('nicht zuzuordnen')
+			END AS c99,
+		T5."invoice_date" AS c100,
+		T5."subsidiary" AS c101,
+		T5."invoice_number" AS c102,
+		T5."invoice_type" AS c103,
+		T4."document_type_description" AS c104,
+		T4."document_type_in_journal" AS c105,
+		T3."family_name" AS c106,
+		T3."first_name" AS c107,
+		T3."is_supplier" AS c108,
+		T1."nominal_account_number" AS c109,
+		CASE 
+			WHEN (T1."debit_or_credit" = 'H')
+				THEN (T1."posted_count" / 100 * - 1)
+			ELSE (T1."posted_count" / 100)
+			END AS c110,
+		((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))) AS c111,
+		T1."accounting_date" AS c112,
+		CASE 
+			WHEN (
+					(
+						(
+							(
+								((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%RG-BONUS%')
+								OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%GEBURTSTAGS%')
+								)
+							OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%STARTGUTHABEN%')
+							)
+						OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%BONUS F%')
+						)
+					OR ((((rtrim((convert(VARCHAR(50), T1."document_number")))) + ' - ' + T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + ((substring((convert(VARCHAR(50), T2."employee_number")), 1, 4)) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date"))))) LIKE '%RG-ABZUG%')
+					)
+				THEN ('Bonus/Startguthaben')
+			ELSE ('ohne Bonus/Startguthaben')
+			END AS c113,
+		T1."free_form_accounting_text" AS c114,
+		T1."previously_used_account_no" AS c115,
+		T1."skr51_cost_unit" AS c116,
+		T1."skr51_sales_channel" AS c117,
+		T1."skr51_cost_center" AS c118,
+		T1."skr51_make" AS c119,
+		T1."skr51_branch" AS c120,
+		T1."day_of_actual_accounting" AS c121,
+		T1."days_for_cash_discount" AS c122,
+		T1."vat_key" AS c123,
+		T1."account_statement_page" AS c124,
+		T1."account_statement_number" AS c125,
+		T1."vat_id_number" AS c126,
+		T1."vehicle_reference" AS c127,
+		T1."posting_text" AS c128,
+		T1."term_of_payment" AS c129,
+		T1."cash_discount" AS c130,
+		T1."journal_line" AS c131,
+		T1."journal_page" AS c132,
+		T1."last_dunning_date" AS c133,
+		T1."dunning_level" AS c134,
+		T1."invoice_number" AS c135,
+		T1."invoice_date" AS c136,
+		T1."employee_number" AS c137,
+		T1."serial_number_each_month" AS c138,
+		T1."account_form_page_line" AS c139,
+		T1."account_form_page_number" AS c140,
+		T1."contra_account_text" AS c141,
+		T1."nominal_contra_account" AS c142,
+		T1."customer_contra_account" AS c143,
+		T1."branch_number" AS c144,
+		T1."posted_count" AS c145,
+		T1."debit_or_credit" AS c146,
+		T1."posted_value" AS c147,
+		T1."document_date" AS c148,
+		T1."clearing_number" AS c149,
+		T1."is_balanced" AS c150,
+		T1."customer_number" AS c151,
+		T1."position_in_document" AS c152,
+		T1."document_number" AS c153,
+		T1."document_type" AS c154
+	FROM (
+		(
+			(
+				(
+					"journal_accountings" T1 LEFT OUTER JOIN "LOCOSOFT"."dbo"."employees" T2 ON T1."employee_number" = T2."employee_number"
+					) LEFT OUTER JOIN "LOCOSOFT"."dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."customer_number"
+				) LEFT OUTER JOIN "document_types" T4 ON T4."document_type_in_journal" = T1."document_type"
+			) LEFT OUTER JOIN "invoices" T5 ON T5."invtype_invnr" = T1."invoice_number"
+		)
+	WHERE (
+			(
+				(
+					(T1."nominal_account_number" IN (1600, 1610))
+					AND (T1."customer_number" IS NOT NULL)
+					)
+				AND (T3."customer_number" IS NOT NULL)
+				)
+			AND (T1."document_type" IN ('W', 'E', 'L'))
+			)
+	) D1
+	-- order by "Customer Number" asc,"Invoice Number" asc,"Document Type In Journal" asc,"Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 0 - 82
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege.sql

@@ -1,82 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.loc_belege AS
-
-select T1."accounting_date" as "Accounting Date",
-	   T1."document_type" as "Document Type",
-	   (T1."document_number") as "Document Number",
-	   T1."position_in_document" as "Position In Document",
-	   T1."customer_number" as "Customer Number",
-	   T1."nominal_account_number" as "Nominal Account Number",
-	   T1."is_balanced" as "Is Balanced",
-	   T1."clearing_number" as "Clearing Number",
-	   T1."document_date" as "Document Date",
-	   T1."posted_value" as "Posted Value",
-	   T1."debit_or_credit" as "Debit Or Credit",
-	   T1."posted_count" as "Posted Count",
-	   T1."branch_number" as "Branch Number",
-	   T1."customer_contra_account" as "Customer Contra Account",
-	   T1."nominal_contra_account" as "Nominal Contra Account",
-	   T1."contra_account_text" as "Contra Account Text",
-	   T1."account_form_page_number" as "Account Form Page Number",
-	   T1."account_form_page_line" as "Account Form Page Line",
-	   T1."serial_number_each_month" as "Serial Number Each Month",
-	   T1."employee_number" as "Employee Number",
-	   T1."invoice_date" as "Invoice Date",
-	   T1."invoice_number" as "Invoice Number",
-	   T1."dunning_level" as "Dunning Level",
-	   T1."last_dunning_date" as "Last Dunning Date",
-	   T1."journal_page" as "Journal Page",
-	   T1."journal_line" as "Journal Line",
-	   T1."cash_discount" as "Cash Discount",
-	   T1."term_of_payment" as "Term Of Payment",
-	   CASE WHEN (T1."posting_text" IS NULL) THEN (' - ') ELSE (T1."posting_text") END as "Posting Text",
-	   CASE WHEN (T1."vehicle_reference" IS NULL) THEN (' - ') ELSE (T1."vehicle_reference") END as "Vehicle Reference",
-	   T1."vat_id_number" as "Vat Id Number",
-	   T1."account_statement_number" as "Account Statement Number",
-	   T1."account_statement_page" as "Account Statement Page",
-	   T1."vat_key" as "Vat Key",
-	   T1."days_for_cash_discount" as "Days For Cash Discount",
-	   T1."day_of_actual_accounting" as "Day Of Actual Accounting",
-	   T1."skr51_branch" as "Skr51 Branch",
-	   T1."skr51_make" as "Skr51 Make",
-	   T1."skr51_cost_center" as "Skr51 Cost Center",
-	   T1."skr51_sales_channel" as "Skr51 Sales Channel",
-	   T1."skr51_cost_unit" as "Skr51 Cost Unit",
-	   T1."previously_used_account_no" as "Previously Used Account No",
-	   T1."free_form_accounting_text" as "Free Form Accounting Text",
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN ('Neuwagen') WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59) THEN ('Gebrauchtwagen') WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69) THEN ('Teile & Zubehör') WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79) THEN ('Service') WHEN (T1."skr51_cost_unit" = 0) THEN ('Ohne Kostenträger') ELSE null END as "Free Form Document Text",
-	   T2."is_profit_loss_account" as "Nom_Account_Is Profit Loss Account",
-	   T1."subsidiary_to_company_ref" as "Rechtseinheit",
-	   '0' + ((convert(varchar(50), T1."skr51_branch"))) as "Betrieb",
-	   CASE WHEN (((CASE WHEN (T1."posting_text" IS NULL) THEN (' - ') ELSE (T1."posting_text") END) = 'Saldenübernahme CDK') or (T1."accounting_date" = convert(date, '2019-01-01'))) THEN (convert(date, '2019-12-01')) ELSE (T1."accounting_date") END as "Bookkeep Date",
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + T3."skr51_make_description" as "Marke",
-	   CASE WHEN ((day((getdate()) - (convert(datetime, (CASE WHEN (((CASE WHEN (T1."posting_text" IS NULL) THEN (' - ') ELSE (T1."posting_text") END) = 'Saldenübernahme CDK') or (T1."accounting_date" = convert(date, '2019-01-01'))) THEN (convert(date, '2019-12-01')) ELSE (T1."accounting_date") END))))) <= 90) THEN ((convert(varchar(50), ((T1."document_number")))) + ' - ' + (CASE WHEN (T1."posting_text" IS NULL) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN (T1."vehicle_reference" IS NULL) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + (left(((convert(varchar(50), T1."employee_number")))))) ELSE ('Buchungen älter 90 Tage') END as "Text",
-	   '1' as "Mandant",
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END as "Betrag",
-	   (left(((convert(varchar(50), T1."nominal_account_number"))))) + ' - ' + T2."account_description" as "Konto_mit_Bezeichnung",
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_count" / 100 * -1) ELSE (T1."posted_count" / 100) END as "Menge",
-	   (len(((convert(varchar(50), T1."skr51_cost_center"))) + 'Z') - 1) as "Stellen Cost Center",
-	   (rtrim(((convert(varchar(50), T1."skr51_cost_center"))))) + ' - ' + T3."skr51_cost_center_name" as "KST",
-	   (len(((convert(varchar(50), T1."skr51_sales_channel"))) + 'Z') - 1) as "Stellen Sales Channel",
-	   (rtrim(((convert(varchar(50), T1."skr51_sales_channel"))))) + ' - ' + T3."skr51_sales_channel_name" as "Absatzkanal",
-	   (len(((convert(varchar(50), T1."skr51_cost_unit"))) + 'Z') - 1) as "Stellen Cost Unit",
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name") as "Kostenträger_mit_Null",
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN (((rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name"))) ELSE ((rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name")) END as "Kostenträger",
-	   CASE WHEN (T2."is_profit_loss_account" = 'J') THEN ('2') ELSE ('1') END as "GuV_Bilanz",
-	   (left(((convert(varchar(50), T1."nominal_account_number"))))) as "Susa",
-	   CASE WHEN (T1."skr51_cost_center" <> 0) THEN ((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + '_' + (rtrim(((convert(varchar(50), T1."skr51_cost_center")))))) ELSE (((convert(varchar(50), T1."nominal_account_number")))) END as "Acct Nr"
-from "dbo"."nominal_accounts" T2,
-	("dbo"."journal_accountings" T1 left outer join "dbo"."accounts_characteristics" T3 on (((((T3."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref") and (T3."skr51_branch" = T1."skr51_branch")) and (T3."skr51_make" = T1."skr51_make")) and (T3."skr51_cost_center" = T1."skr51_cost_center")) and (T3."skr51_sales_channel" = T1."skr51_sales_channel")) and (T3."skr51_cost_unit" = T1."skr51_cost_unit"))
-where ((T2."nominal_account_number" = T1."nominal_account_number") and (T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref"))
-and ((T2."is_profit_loss_account" = 'J') and (not (CASE WHEN (T1."posting_text" IS NULL) THEN (' - ') ELSE (T1."posting_text") END) IN ('G&V-Abschlussbuchung')))
--- order by "Nominal Account Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 65 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_0.sql

@@ -0,0 +1,65 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[loc_belege_0]
+AS
+SELECT CAST([Rechtseinheit_ID] AS VARCHAR(100)) AS [Rechtseinheit_ID],
+	CAST([Rechtseinheit_Name] AS VARCHAR(100)) AS [Rechtseinheit_Name],
+	CAST([Betrieb_ID] AS VARCHAR(100)) AS [Betrieb_ID],
+	CAST([Betrieb_Name] AS VARCHAR(100)) AS [Betrieb_Name],
+	CAST([Ebene1] AS VARCHAR(100)) AS [Ebene1],
+	CAST([Ebene2] AS VARCHAR(100)) AS [Ebene2],
+	CAST([Ebene3] AS VARCHAR(100)) AS [Ebene3],
+	CAST([Ebene4] AS VARCHAR(100)) AS [Ebene4],
+	CAST([Ebene5] AS VARCHAR(100)) AS [Ebene5],
+	CAST([Ebene6] AS VARCHAR(100)) AS [Ebene6],
+	CAST([Konto] AS VARCHAR(100)) AS [Konto],
+	CAST([Acct_Nr] AS VARCHAR(100)) AS [Acct_Nr],
+	CAST([Text] AS VARCHAR(100)) AS [Text],
+	CAST([Kostenstelle] AS VARCHAR(100)) AS [Kostenstelle],
+	CAST([KST_mit_Bez] AS VARCHAR(100)) AS [KST_mit_Bez],
+	CAST([KST] AS VARCHAR(100)) AS [KST],
+	CAST([Markencode] AS VARCHAR(100)) AS [Markencode],
+	CAST([Fahrgestellnummer] AS VARCHAR(100)) AS [Fahrgestellnummer],
+	CAST([Konto_Buchung] AS VARCHAR(100)) AS [Konto_Buchung],
+	CAST([Marke_mit_Bez] AS VARCHAR(100)) AS [Marke_mit_Bez],
+	CAST([Marke] AS VARCHAR(100)) AS [Marke],
+	CAST([Ebene21] AS VARCHAR(100)) AS [Ebene21],
+	CAST([Absatzkanal_mit_Bez] AS VARCHAR(100)) AS [Absatzkanal_mit_Bez],
+	CAST([Absatzkanal] AS VARCHAR(100)) AS [Absatzkanal],
+	CAST([Ebene31] AS VARCHAR(100)) AS [Ebene31],
+	CAST([Kostenträger_mit_Bez] AS VARCHAR(100)) AS [Kostenträger_mit_Bez],
+	CAST([Kostenträger_FIBU] AS VARCHAR(100)) AS [Kostenträger_FIBU],
+	CAST([Ebene71] AS VARCHAR(100)) AS [Ebene71],
+	CAST([Ebene72] AS VARCHAR(100)) AS [Ebene72],
+	CAST([Ebene73] AS VARCHAR(100)) AS [Ebene73],
+	CAST([Ebene74] AS VARCHAR(100)) AS [Ebene74],
+	CAST([Ebene75] AS VARCHAR(100)) AS [Ebene75],
+	CAST([Ebene76] AS VARCHAR(100)) AS [Ebene76],
+	CAST([Ebene77] AS VARCHAR(100)) AS [Ebene77],
+	CAST([Ebene81] AS VARCHAR(100)) AS [Ebene81],
+	CAST([Ebene82] AS VARCHAR(100)) AS [Ebene82],
+	CAST([Ebene83] AS VARCHAR(100)) AS [Ebene83],
+	CAST([Ebene84] AS VARCHAR(100)) AS [Ebene84],
+	CAST([Ebene85] AS VARCHAR(100)) AS [Ebene85],
+	CAST([Ebene86] AS VARCHAR(100)) AS [Ebene86],
+	CAST([GuV_Bilanz] AS VARCHAR(100)) AS [GuV_Bilanz],
+	CAST([Susa] AS VARCHAR(100)) AS [Susa],
+	CAST([Mandant] AS VARCHAR(100)) AS [Mandant],
+	CAST(ROUND(ISNULL([Ist], 0), 8) AS NUMERIC(19, 8)) AS [Ist],
+	CAST(ROUND(ISNULL([Menge], 0), 8) AS NUMERIC(19, 8)) AS [Menge],
+	CAST([Gruppe_ID] AS VARCHAR(100)) AS [Gruppe_ID],
+	CAST([Gruppe_Name] AS VARCHAR(100)) AS [Gruppe_Name],
+	CAST([Invoice_Date] AS DATETIME) AS [Invoice_Date],
+	CAST([Fabrikat] AS VARCHAR(100)) AS [Fabrikat],
+	CAST([Fabrikat_Order_By] AS INT) AS [Fabrikat_Order_By]
+FROM [LOCOSOFT].[staging].[loc_belege_11]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 115 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_11.sql

@@ -0,0 +1,115 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[loc_belege_11]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Rechtseinheit_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Rechtseinheit_Name",
+	"GC_Department"."Standort_ID" AS "Betrieb_ID",
+	"GC_Department"."Standort_Name" AS "Betrieb_Name",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene1" AS "Ebene1",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene2" AS "Ebene2",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene3" AS "Ebene3",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene4" AS "Ebene4",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene5" AS "Ebene5",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene6" AS "Ebene6",
+	left("Kontenrahmen_GC_Struct_SKR"."Konto Nr", 4) + ' - ' + "Kontenrahmen_GC_Struct_SKR"."Konto Bezeichnung" AS "Konto",
+	"LOC_Belege"."Acct Nr" AS "Acct_Nr",
+	"LOC_Belege"."Text" AS "Text",
+	CASE 
+		WHEN left(left("LOC_Belege"."KST", 2), 1) = '1'
+			THEN 'Neuwagen'
+		WHEN left(left("LOC_Belege"."KST", 2), 1) = '2'
+			THEN 'Gebrauchtwagen'
+		WHEN left(left("LOC_Belege"."KST", 2), 1) = '3'
+			THEN 'Teile & Zubehör'
+		WHEN left(left("LOC_Belege"."KST", 2), 1) = '4'
+			THEN 'Service'
+		WHEN left(left("LOC_Belege"."KST", 2), 1) = '5'
+			THEN 'Weitere Bereiche'
+		WHEN left(left("LOC_Belege"."KST", 2), 1) = '0'
+			THEN 'ohne Herkunft'
+		ELSE 'Verwaltung'
+		END AS "Kostenstelle",
+	"LOC_Belege"."KST" AS "KST_mit_Bez",
+	left("LOC_Belege"."KST", 2) AS "KST",
+	left("LOC_Belege"."Marke", 1) AS "Markencode",
+	"LOC_Belege"."Vehicle Reference" AS "Fahrgestellnummer",
+	left("Kontenrahmen_GC_Struct_SKR"."Konto Nr", 4) + ' - ' + "Kontenrahmen_GC_Struct_SKR"."Konto Bezeichnung" AS "Konto_Buchung",
+	"LOC_Belege"."Marke" AS "Marke_mit_Bez",
+	left("LOC_Belege"."Marke", 1) AS "Marke",
+	CASE 
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '1'
+			THEN 'Privater Endkunde'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '2'
+			THEN 'Gewerbekunde'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '3'
+			THEN 'Großkunde'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '4'
+			THEN 'Sonderabnehmer'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '5'
+			THEN 'Wiederverkäufer'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '6'
+			THEN 'Wirtschaftsraum'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '9'
+			THEN 'Sonstige'
+		WHEN left(left("LOC_Belege"."Absatzkanal", 2), 1) = '0'
+			THEN 'ohne Absatzkanal'
+		ELSE NULL
+		END AS "Ebene21",
+	"LOC_Belege"."Absatzkanal" AS "Absatzkanal_mit_Bez",
+	left("LOC_Belege"."Absatzkanal", 2) AS "Absatzkanal",
+	"LOC_Belege"."Free Form Document Text" AS "Ebene31",
+	"LOC_Belege"."Kostenträger" AS "Kostenträger_mit_Bez",
+	"LOC_Belege"."Skr51 Cost Unit" AS "Kostenträger_FIBU",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene71" AS "Ebene71",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene72" AS "Ebene72",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene73" AS "Ebene73",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene74" AS "Ebene74",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene75" AS "Ebene75",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene76" AS "Ebene76",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene77" AS "Ebene77",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene81" AS "Ebene81",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene82" AS "Ebene82",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene83" AS "Ebene83",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene84" AS "Ebene84",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene85" AS "Ebene85",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene86" AS "Ebene86",
+	"LOC_Belege"."GuV_Bilanz" AS "GuV_Bilanz",
+	"LOC_Belege"."Susa" AS "Susa",
+	"LOC_Belege"."Mandant" AS "Mandant",
+	"LOC_Belege"."Betrag" AS "Ist",
+	"LOC_Belege"."Menge" AS "Menge",
+	"GC_Department"."Gruppe_ID" AS "Gruppe_ID",
+	"GC_Department"."Gruppe_Name" AS "Gruppe_Name",
+	"LOC_Belege"."Bookkeep Date" AS "Invoice_Date",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By"
+FROM (
+	(
+		[staging].[loc_belege_80] "LOC_Belege" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "LOC_Belege"."Rechtseinheit" = "GC_Department"."Hauptbetrieb"
+			AND "LOC_Belege"."Betrieb" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "LOC_Belege"."Marke" = "GC_Marken"."Marke_FIBU"
+		AND "LOC_Belege"."Rechtseinheit" = "GC_Marken"."Client_DB"
+	)
+LEFT OUTER JOIN [staging].[kontenrahmen_gc_struct_skr_imr] "Kontenrahmen_GC_Struct_SKR" ON "LOC_Belege"."Acct Nr" = "Kontenrahmen_GC_Struct_SKR"."Konto Nr"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 79 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_80.sql

@@ -0,0 +1,79 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[loc_belege_80]
+AS
+SELECT [Accounting Date],
+	[Document Type],
+	[Document Number],
+	[Position In Document],
+	[Customer Number],
+	[Nominal Account Number],
+	[Is Balanced],
+	[Clearing Number],
+	[Document Date],
+	[Posted Value],
+	[Debit Or Credit],
+	[Posted Count],
+	[Branch Number],
+	[Customer Contra Account],
+	[Nominal Contra Account],
+	[Contra Account Text],
+	[Account Form Page Number],
+	[Account Form Page Line],
+	[Serial Number Each Month],
+	[Employee Number],
+	[Invoice Date],
+	[Invoice Number],
+	[Dunning Level],
+	[Last Dunning Date],
+	[Journal Page],
+	[Journal Line],
+	[Cash Discount],
+	[Term Of Payment],
+	[Posting Text],
+	[Vehicle Reference],
+	[Vat Id Number],
+	[Account Statement Number],
+	[Account Statement Page],
+	[Vat Key],
+	[Days For Cash Discount],
+	[Day Of Actual Accounting],
+	[Skr51 Branch],
+	[Skr51 Make],
+	[Skr51 Cost Center],
+	[Skr51 Sales Channel],
+	[Skr51 Cost Unit],
+	[Previously Used Account No],
+	[Free Form Accounting Text],
+	[Free Form Document Text],
+	[Nom_Account_Is Profit Loss Account],
+	[Rechtseinheit],
+	[Betrieb],
+	[Bookkeep Date],
+	[Marke],
+	[Text],
+	[Mandant],
+	[Betrag],
+	[Konto_mit_Bezeichnung],
+	[Menge],
+	[Stellen Cost Center],
+	[KST],
+	[Stellen Sales Channel],
+	[Absatzkanal],
+	[Stellen Cost Unit],
+	[Kostenträger_mit_Null],
+	[Kostenträger],
+	[GuV_Bilanz],
+	[Susa],
+	[Acct Nr]
+FROM [LOCOSOFT].[staging].[loc_belege_90]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 159 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_90.sql

@@ -0,0 +1,159 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[loc_belege_90]
+AS
+SELECT T1."accounting_date" AS "Accounting Date",
+	T1."document_type" AS "Document Type",
+	T1."document_number" AS "Document Number",
+	T1."position_in_document" AS "Position In Document",
+	T1."customer_number" AS "Customer Number",
+	T1."nominal_account_number" AS "Nominal Account Number",
+	T1."is_balanced" AS "Is Balanced",
+	T1."clearing_number" AS "Clearing Number",
+	T1."document_date" AS "Document Date",
+	T1."posted_value" AS "Posted Value",
+	T1."debit_or_credit" AS "Debit Or Credit",
+	T1."posted_count" AS "Posted Count",
+	T1."branch_number" AS "Branch Number",
+	T1."customer_contra_account" AS "Customer Contra Account",
+	T1."nominal_contra_account" AS "Nominal Contra Account",
+	T1."contra_account_text" AS "Contra Account Text",
+	T1."account_form_page_number" AS "Account Form Page Number",
+	T1."account_form_page_line" AS "Account Form Page Line",
+	T1."serial_number_each_month" AS "Serial Number Each Month",
+	T1."employee_number" AS "Employee Number",
+	T1."invoice_date" AS "Invoice Date",
+	T1."invoice_number" AS "Invoice Number",
+	T1."dunning_level" AS "Dunning Level",
+	T1."last_dunning_date" AS "Last Dunning Date",
+	T1."journal_page" AS "Journal Page",
+	T1."journal_line" AS "Journal Line",
+	T1."cash_discount" AS "Cash Discount",
+	T1."term_of_payment" AS "Term Of Payment",
+	T1."posting_text" AS "Posting Text",
+	T1."vehicle_reference" AS "Vehicle Reference",
+	T1."vat_id_number" AS "Vat Id Number",
+	T1."account_statement_number" AS "Account Statement Number",
+	T1."account_statement_page" AS "Account Statement Page",
+	T1."vat_key" AS "Vat Key",
+	T1."days_for_cash_discount" AS "Days For Cash Discount",
+	T1."day_of_actual_accounting" AS "Day Of Actual Accounting",
+	T1."skr51_branch" AS "Skr51 Branch",
+	T1."skr51_make" AS "Skr51 Make",
+	T1."skr51_cost_center" AS "Skr51 Cost Center",
+	T1."skr51_sales_channel" AS "Skr51 Sales Channel",
+	T1."skr51_cost_unit" AS "Skr51 Cost Unit",
+	T1."previously_used_account_no" AS "Previously Used Account No",
+	T1."free_form_accounting_text" AS "Free Form Accounting Text",
+	CASE 
+		WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN ('Neuwagen')
+		WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59)
+			THEN ('Gebrauchtwagen')
+		WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69)
+			THEN ('Teile & Zubehör')
+		WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79)
+			THEN ('Service')
+		WHEN (T1."skr51_cost_unit" = 0)
+			THEN ('Ohne Kostenträger')
+		ELSE NULL
+		END AS "Free Form Document Text",
+	T2."is_profit_loss_account" AS "Nom_Account_Is Profit Loss Account",
+	T1."subsidiary_to_company_ref" AS "Rechtseinheit",
+	'0' + (convert(VARCHAR(50), T1."skr51_branch")) AS "Betrieb",
+	CASE 
+		WHEN (
+				(T1."posting_text" = 'Saldenübernahme CDK')
+				OR (T1."accounting_date" = convert(DATE, '2019-01-01'))
+				)
+			THEN (convert(DATE, '2019-12-01'))
+		ELSE (T1."accounting_date")
+		END AS "Bookkeep Date",
+	(rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + T3."skr51_make_description" AS "Marke",
+	CASE 
+		WHEN (
+				(
+					day((getdate()) - (
+							convert(DATETIME, (
+									CASE 
+										WHEN (
+												(T1."posting_text" = 'Saldenübernahme CDK')
+												OR (T1."accounting_date" = convert(DATE, '2019-01-01'))
+												)
+											THEN (convert(DATE, '2019-12-01'))
+										ELSE (T1."accounting_date")
+										END
+									))
+							))
+					) <= 90
+				)
+			THEN (T1."invoice_number" + ' - ' + T1."posting_text" + '/' + T1."vehicle_reference" + ' - ' + (substring((convert(VARCHAR(50), T1."employee_number")), 1, 4)))
+		ELSE ('Buchungen älter 90 Tage')
+		END AS "Text",
+	'1' AS "Mandant",
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_value" / 100 * - 1)
+		ELSE (T1."posted_value" / 100)
+		END AS "Betrag",
+	(substring((convert(VARCHAR(50), T1."nominal_account_number")), 1, 4)) + ' - ' + T2."account_description" AS "Konto_mit_Bezeichnung",
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_count" / 100 * - 1)
+		ELSE (T1."posted_count" / 100)
+		END AS "Menge",
+	(len((convert(VARCHAR(50), T1."skr51_cost_center")))) AS "Stellen Cost Center",
+	(rtrim((convert(VARCHAR(50), T1."skr51_cost_center")))) + ' - ' + T3."skr51_cost_center_name" AS "KST",
+	(len((convert(VARCHAR(50), T1."skr51_sales_channel")))) AS "Stellen Sales Channel",
+	(rtrim((convert(VARCHAR(50), T1."skr51_sales_channel")))) + ' - ' + T3."skr51_sales_channel_name" AS "Absatzkanal",
+	(len((convert(VARCHAR(50), T1."skr51_cost_unit")))) AS "Stellen Cost Unit",
+	(rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name") AS "Kostenträger_mit_Null",
+	CASE 
+		WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN (((rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name")))
+		ELSE ((rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name"))
+		END AS "Kostenträger",
+	CASE 
+		WHEN (T2."is_profit_loss_account" = 'J')
+			THEN ('2')
+		ELSE ('1')
+		END AS "GuV_Bilanz",
+	(substring((convert(VARCHAR(50), T1."nominal_account_number")), 1, 1)) AS "Susa",
+	CASE 
+		WHEN (T1."skr51_cost_center" <> 0)
+			THEN ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))) + '_' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_center")))))
+		ELSE ((convert(VARCHAR(50), T1."nominal_account_number")))
+		END AS "Acct Nr"
+FROM "dbo"."journal_accountings" T1
+LEFT OUTER JOIN "dbo"."accounts_characteristics" T3 ON (
+		(
+			(
+				(
+					(T3."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")
+					AND (T3."skr51_branch" = T1."skr51_branch")
+					)
+				AND (T3."skr51_make" = T1."skr51_make")
+				)
+			AND (T3."skr51_cost_center" = T1."skr51_cost_center")
+			)
+		AND (T3."skr51_sales_channel" = T1."skr51_sales_channel")
+		)
+	AND (T3."skr51_cost_unit" = T1."skr51_cost_unit")
+INNER JOIN "dbo"."nominal_accounts" T2 ON (
+		(T2."nominal_account_number" = T1."nominal_account_number")
+		AND (T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")
+		)
+WHERE (
+		(T2."is_profit_loss_account" = 'J')
+		AND (NOT T1."posting_text" IN ('G&V-Abschlussbuchung'))
+		)
+	-- order by "Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 0 - 83
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz.sql

@@ -1,83 +0,0 @@
-SET QUOTED_IDENTIFIER ON 
-GO
-SET ANSI_NULLS ON 
-GO
-CREATE VIEW staging.loc_belege_bilanz AS
-
-select T1."accounting_date" as "Accounting Date",
-	   T1."document_type" as "Document Type",
-	   T1."document_number" as "Document Number",
-	   T1."position_in_document" as "Position In Document",
-	   T1."customer_number" as "Customer Number",
-	   T1."nominal_account_number" as "Nominal Account Number",
-	   T1."is_balanced" as "Is Balanced",
-	   T1."clearing_number" as "Clearing Number",
-	   T1."document_date" as "Document Date",
-	   T1."posted_value" as "Posted Value",
-	   T1."debit_or_credit" as "Debit Or Credit",
-	   T1."posted_count" as "Posted Count",
-	   T1."branch_number" as "Branch Number",
-	   T1."customer_contra_account" as "Customer Contra Account",
-	   T1."nominal_contra_account" as "Nominal Contra Account",
-	   T1."contra_account_text" as "Contra Account Text",
-	   T1."account_form_page_number" as "Account Form Page Number",
-	   T1."account_form_page_line" as "Account Form Page Line",
-	   T1."serial_number_each_month" as "Serial Number Each Month",
-	   T1."employee_number" as "Employee Number",
-	   T1."invoice_date" as "Invoice Date",
-	   T1."invoice_number" as "Invoice Number",
-	   T1."dunning_level" as "Dunning Level",
-	   T1."last_dunning_date" as "Last Dunning Date",
-	   T1."journal_page" as "Journal Page",
-	   T1."journal_line" as "Journal Line",
-	   T1."cash_discount" as "Cash Discount",
-	   T1."term_of_payment" as "Term Of Payment",
-	   '-' as "Posting Text",
-	   T1."vehicle_reference" as "Vehicle Reference",
-	   T1."vat_id_number" as "Vat Id Number",
-	   T1."account_statement_number" as "Account Statement Number",
-	   T1."account_statement_page" as "Account Statement Page",
-	   T1."vat_key" as "Vat Key",
-	   T1."days_for_cash_discount" as "Days For Cash Discount",
-	   T1."day_of_actual_accounting" as "Day Of Actual Accounting",
-	   T1."skr51_branch" as "Skr51 Branch",
-	   T1."skr51_make" as "Skr51 Make",
-	   T1."skr51_cost_center" as "Skr51 Cost Center",
-	   T1."skr51_sales_channel" as "Skr51 Sales Channel",
-	   T1."skr51_cost_unit" as "Skr51 Cost Unit",
-	   T1."previously_used_account_no" as "Previously Used Account No",
-	   (left(T1."free_form_accounting_text",100)) as "Free Form Accounting Text",
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN ('Neuwagen') WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59) THEN ('Gebrauchtwagen') WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69) THEN ('Teile & Zubehör') WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79) THEN ('Service') WHEN (T1."skr51_cost_unit" = 0) THEN ('Ohne Kostenträger') ELSE null END as "Free Form Document Text",
-	   T2."is_profit_loss_account" as "Nom_Account_Is Profit Loss Account",
-	   T1."subsidiary_to_company_ref" as "Rechtseinheit",
-	   ('0' + ((convert(varchar(50), T1."skr51_branch")))) as "Betrieb",
-	   T1."accounting_date" as "Bookkeep Date",
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + T3."skr51_make_description" as "Marke",
-	   '' as "Text",
-	   '1' as "Mandant",
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END as "Betrag",
-	   (rtrim((CASE WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 1) THEN ('000' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 2) THEN ('00' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 3) THEN ('0' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) ELSE ((rtrim(((convert(varchar(50), T1."nominal_account_number")))))) END))) + ' - ' + T2."account_description" as "Konto_mit_Bezeichnung",
-	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_count" / 100 * -1) ELSE (T1."posted_count" / 100) END as "Menge",
-	   (len(((convert(varchar(50), T1."skr51_cost_center"))) + 'Z') - 1) as "Stellen Cost Center",
-	   (rtrim(((convert(varchar(50), T1."skr51_cost_center"))))) + ' - ' + T3."skr51_cost_center_name" as "KST",
-	   (len(((convert(varchar(50), T1."skr51_sales_channel"))) + 'Z') - 1) as "Stellen Sales Channel",
-	   (rtrim(((convert(varchar(50), T1."skr51_sales_channel"))))) + ' - ' + T3."skr51_sales_channel_name" as "Absatzkanal",
-	   (len(((convert(varchar(50), T1."skr51_cost_unit"))) + 'Z') - 1) as "Stellen Cost Unit",
-	   (rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name") as "Kostenträger_mit_Null",
-	   CASE WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49) THEN (((rtrim(((convert(varchar(50), T1."skr51_make"))))) + ' - ' + (rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name"))) ELSE ((rtrim(((convert(varchar(50), T1."skr51_cost_unit"))))) + ' - ' + (T3."skr51_cost_unit_name")) END as "Kostenträger",
-	   CASE WHEN (T2."is_profit_loss_account" = 'J') THEN ('2') ELSE ('1') END as "GuV_Bilanz",
-	   (substring((CASE WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 1) THEN ('000' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 2) THEN ('00' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 3) THEN ('0' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) ELSE ((rtrim(((convert(varchar(50), T1."nominal_account_number")))))) END), 1, 1)) as "Susa",
-	   CASE WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 1) THEN ('000' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 2) THEN ('00' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 3) THEN ('0' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) ELSE ((rtrim(((convert(varchar(50), T1."nominal_account_number")))))) END as "Acct Nr",
-	   (len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1) as "Stellen_Konto_Nr"
-from "dbo"."nominal_accounts" T2,
-	("dbo"."journal_accountings" T1 left outer join "dbo"."accounts_characteristics" T3 on (((((T3."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref") and (T3."skr51_branch" = T1."skr51_branch")) and (T3."skr51_make" = T1."skr51_make")) and (T3."skr51_cost_center" = T1."skr51_cost_center")) and (T3."skr51_sales_channel" = T1."skr51_sales_channel")) and (T3."skr51_cost_unit" = T1."skr51_cost_unit"))
-where ((T2."nominal_account_number" = T1."nominal_account_number") and (T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref"))
-and ((T2."is_profit_loss_account" = 'N') and (not ((rtrim((CASE WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 1) THEN ('000' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 2) THEN ('00' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) WHEN (((len((rtrim(((convert(varchar(50), T1."nominal_account_number"))))) + 'Z') - 1)) = 3) THEN ('0' + (rtrim(((convert(varchar(50), T1."nominal_account_number")))))) ELSE ((rtrim(((convert(varchar(50), T1."nominal_account_number")))))) END))) + ' - ' + T2."account_description") LIKE '9%'))
--- order by "Nominal Account Number" asc
-GO
-SET QUOTED_IDENTIFIER OFF 
-GO
-SET ANSI_NULLS OFF 
-GO
-
-GO

+ 65 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_0.sql

@@ -0,0 +1,65 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[loc_belege_bilanz_0]
+AS
+SELECT CAST([Rechtseinheit_ID] AS VARCHAR(100)) AS [Rechtseinheit_ID],
+	CAST([Rechtseinheit_Name] AS VARCHAR(100)) AS [Rechtseinheit_Name],
+	CAST([Betrieb_ID] AS VARCHAR(100)) AS [Betrieb_ID],
+	CAST([Betrieb_Name] AS VARCHAR(100)) AS [Betrieb_Name],
+	CAST([Ebene1] AS VARCHAR(100)) AS [Ebene1],
+	CAST([Ebene2] AS VARCHAR(100)) AS [Ebene2],
+	CAST([Ebene3] AS VARCHAR(100)) AS [Ebene3],
+	CAST([Ebene4] AS VARCHAR(100)) AS [Ebene4],
+	CAST([Ebene5] AS VARCHAR(100)) AS [Ebene5],
+	CAST([Ebene6] AS VARCHAR(100)) AS [Ebene6],
+	CAST([Konto] AS VARCHAR(100)) AS [Konto],
+	CAST([Acct_Nr] AS VARCHAR(100)) AS [Acct_Nr],
+	CAST([Text] AS VARCHAR(100)) AS [Text],
+	CAST([Kostenstelle] AS VARCHAR(100)) AS [Kostenstelle],
+	CAST([KST_mit_Bez] AS VARCHAR(100)) AS [KST_mit_Bez],
+	CAST([KST] AS VARCHAR(100)) AS [KST],
+	CAST([Markencode] AS VARCHAR(100)) AS [Markencode],
+	CAST([Fahrgestellnummer] AS VARCHAR(100)) AS [Fahrgestellnummer],
+	CAST([Konto_Buchung] AS VARCHAR(100)) AS [Konto_Buchung],
+	CAST([Marke_mit_Bez] AS VARCHAR(100)) AS [Marke_mit_Bez],
+	CAST([Marke] AS VARCHAR(100)) AS [Marke],
+	CAST([Ebene21] AS VARCHAR(100)) AS [Ebene21],
+	CAST([Absatzkanal_mit_Bez] AS VARCHAR(100)) AS [Absatzkanal_mit_Bez],
+	CAST([Absatzkanal] AS VARCHAR(100)) AS [Absatzkanal],
+	CAST([Ebene31] AS VARCHAR(100)) AS [Ebene31],
+	CAST([Kostenträger_mit_Bez] AS VARCHAR(100)) AS [Kostenträger_mit_Bez],
+	CAST([Kostenträger_FIBU] AS VARCHAR(100)) AS [Kostenträger_FIBU],
+	CAST([Ebene71] AS VARCHAR(100)) AS [Ebene71],
+	CAST([Ebene72] AS VARCHAR(100)) AS [Ebene72],
+	CAST([Ebene73] AS VARCHAR(100)) AS [Ebene73],
+	CAST([Ebene74] AS VARCHAR(100)) AS [Ebene74],
+	CAST([Ebene75] AS VARCHAR(100)) AS [Ebene75],
+	CAST([Ebene76] AS VARCHAR(100)) AS [Ebene76],
+	CAST([Ebene77] AS VARCHAR(100)) AS [Ebene77],
+	CAST([Ebene81] AS VARCHAR(100)) AS [Ebene81],
+	CAST([Ebene82] AS VARCHAR(100)) AS [Ebene82],
+	CAST([Ebene83] AS VARCHAR(100)) AS [Ebene83],
+	CAST([Ebene84] AS VARCHAR(100)) AS [Ebene84],
+	CAST([Ebene85] AS VARCHAR(100)) AS [Ebene85],
+	CAST([Ebene86] AS VARCHAR(100)) AS [Ebene86],
+	CAST([GuV_Bilanz] AS VARCHAR(100)) AS [GuV_Bilanz],
+	CAST([Susa] AS VARCHAR(100)) AS [Susa],
+	CAST([Mandant] AS VARCHAR(100)) AS [Mandant],
+	CAST(ROUND(ISNULL([Ist], 0), 8) AS NUMERIC(19, 8)) AS [Ist],
+	CAST(ROUND(ISNULL([Menge], 0), 8) AS NUMERIC(19, 8)) AS [Menge],
+	CAST([Gruppe_ID] AS VARCHAR(100)) AS [Gruppe_ID],
+	CAST([Gruppe_Name] AS VARCHAR(100)) AS [Gruppe_Name],
+	CAST([Invoice_Date] AS DATETIME) AS [Invoice_Date],
+	CAST([Fabrikat] AS VARCHAR(100)) AS [Fabrikat],
+	CAST([Fabrikat_Order_By] AS INT) AS [Fabrikat_Order_By]
+FROM [LOCOSOFT].[staging].[loc_belege_bilanz_11]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 115 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_11.sql

@@ -0,0 +1,115 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[loc_belege_bilanz_11]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Rechtseinheit_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Rechtseinheit_Name",
+	"GC_Department"."Standort_ID" AS "Betrieb_ID",
+	"GC_Department"."Standort_Name" AS "Betrieb_Name",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene1" AS "Ebene1",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene2" AS "Ebene2",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene3" AS "Ebene3",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene4" AS "Ebene4",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene5" AS "Ebene5",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene6" AS "Ebene6",
+	left("Kontenrahmen_GC_Struct_SKR"."Konto Nr", 4) + ' - ' + "Kontenrahmen_GC_Struct_SKR"."Konto Bezeichnung" AS "Konto",
+	"LOC_Belege_Bilanz"."Acct Nr" AS "Acct_Nr",
+	"LOC_Belege_Bilanz"."Text" AS "Text",
+	CASE 
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '1'
+			THEN 'Neuwagen'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '2'
+			THEN 'Gebrauchtwagen'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '3'
+			THEN 'Teile & Zubehör'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '4'
+			THEN 'Service'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '5'
+			THEN 'Weitere Bereiche'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '0'
+			THEN 'ohne Herkunft'
+		ELSE 'Verwaltung'
+		END AS "Kostenstelle",
+	"LOC_Belege_Bilanz"."KST" AS "KST_mit_Bez",
+	left("LOC_Belege_Bilanz"."KST", 2) AS "KST",
+	left("LOC_Belege_Bilanz"."Marke", 1) AS "Markencode",
+	"LOC_Belege_Bilanz"."Vehicle Reference" AS "Fahrgestellnummer",
+	left("Kontenrahmen_GC_Struct_SKR"."Konto Nr", 4) + ' - ' + "Kontenrahmen_GC_Struct_SKR"."Konto Bezeichnung" AS "Konto_Buchung",
+	"LOC_Belege_Bilanz"."Marke" AS "Marke_mit_Bez",
+	left("LOC_Belege_Bilanz"."Marke", 1) AS "Marke",
+	CASE 
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '1'
+			THEN 'Privater Endkunde'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '2'
+			THEN 'Gewerbekunde'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '3'
+			THEN 'Großkunde'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '4'
+			THEN 'Sonderabnehmer'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '5'
+			THEN 'Wiederverkäufer'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '6'
+			THEN 'Wirtschaftsraum'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '9'
+			THEN 'Sonstige'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '0'
+			THEN 'ohne Absatzkanal'
+		ELSE NULL
+		END AS "Ebene21",
+	"LOC_Belege_Bilanz"."Absatzkanal" AS "Absatzkanal_mit_Bez",
+	left("LOC_Belege_Bilanz"."Absatzkanal", 2) AS "Absatzkanal",
+	"LOC_Belege_Bilanz"."Free Form Document Text" AS "Ebene31",
+	"LOC_Belege_Bilanz"."Kostenträger" AS "Kostenträger_mit_Bez",
+	left("LOC_Belege_Bilanz"."Kostenträger", 2) AS "Kostenträger_FIBU",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene71" AS "Ebene71",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene72" AS "Ebene72",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene73" AS "Ebene73",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene74" AS "Ebene74",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene75" AS "Ebene75",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene76" AS "Ebene76",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene77" AS "Ebene77",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene81" AS "Ebene81",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene82" AS "Ebene82",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene83" AS "Ebene83",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene84" AS "Ebene84",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene85" AS "Ebene85",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene86" AS "Ebene86",
+	"LOC_Belege_Bilanz"."GuV_Bilanz" AS "GuV_Bilanz",
+	"LOC_Belege_Bilanz"."Susa" AS "Susa",
+	"LOC_Belege_Bilanz"."Mandant" AS "Mandant",
+	"LOC_Belege_Bilanz"."Betrag" AS "Ist",
+	"LOC_Belege_Bilanz"."Menge" AS "Menge",
+	"GC_Department"."Gruppe_ID" AS "Gruppe_ID",
+	"GC_Department"."Gruppe_Name" AS "Gruppe_Name",
+	"LOC_Belege_Bilanz"."Bookkeep Date" AS "Invoice_Date",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By"
+FROM (
+	(
+		[staging].[loc_belege_bilanz_80] "LOC_Belege_Bilanz" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "LOC_Belege_Bilanz"."Rechtseinheit" = "GC_Department"."Hauptbetrieb"
+			AND "LOC_Belege_Bilanz"."Betrieb" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "LOC_Belege_Bilanz"."Marke" = "GC_Marken"."Marke_FIBU"
+		AND "LOC_Belege_Bilanz"."Rechtseinheit" = "GC_Marken"."Client_DB"
+	)
+LEFT OUTER JOIN [staging].[kontenrahmen_gc_struct_skr_80] "Kontenrahmen_GC_Struct_SKR" ON "LOC_Belege_Bilanz"."Acct Nr" = "Kontenrahmen_GC_Struct_SKR"."Konto Nr"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 80 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_80.sql

@@ -0,0 +1,80 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+/****** Skript für SelectTopNRows-Befehl aus SSMS ******/
+CREATE VIEW [staging].[loc_belege_bilanz_80]
+AS
+SELECT [Accounting Date],
+	[Document Type],
+	[Document Number],
+	[Position In Document],
+	[Customer Number],
+	[Nominal Account Number],
+	[Is Balanced],
+	[Clearing Number],
+	[Document Date],
+	[Posted Value],
+	[Debit Or Credit],
+	[Posted Count],
+	[Branch Number],
+	[Customer Contra Account],
+	[Nominal Contra Account],
+	[Contra Account Text],
+	[Account Form Page Number],
+	[Account Form Page Line],
+	[Serial Number Each Month],
+	[Employee Number],
+	[Invoice Date],
+	[Invoice Number],
+	[Dunning Level],
+	[Last Dunning Date],
+	[Journal Page],
+	[Journal Line],
+	[Cash Discount],
+	[Term Of Payment],
+	[Posting Text],
+	[Vehicle Reference],
+	[Vat Id Number],
+	[Account Statement Number],
+	[Account Statement Page],
+	[Vat Key],
+	[Days For Cash Discount],
+	[Day Of Actual Accounting],
+	[Skr51 Branch],
+	[Skr51 Make],
+	[Skr51 Cost Center],
+	[Skr51 Sales Channel],
+	[Skr51 Cost Unit],
+	[Previously Used Account No],
+	[Free Form Accounting Text],
+	[Free Form Document Text],
+	[Nom_Account_Is Profit Loss Account],
+	[Rechtseinheit],
+	[Betrieb],
+	[Bookkeep Date],
+	[Marke],
+	[Text],
+	[Mandant],
+	[Betrag],
+	[Konto_mit_Bezeichnung],
+	[Menge],
+	[Stellen Cost Center],
+	[KST],
+	[Stellen Sales Channel],
+	[Absatzkanal],
+	[Stellen Cost Unit],
+	[Kostenträger_mit_Null],
+	[Kostenträger],
+	[GuV_Bilanz],
+	[Susa],
+	[Acct Nr],
+	[Stellen_Konto_Nr]
+FROM [LOCOSOFT].[staging].[loc_belege_bilanz_90]
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 179 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_90.sql

@@ -0,0 +1,179 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[loc_belege_bilanz_90]
+AS
+SELECT T1."accounting_date" AS "Accounting Date",
+	T1."document_type" AS "Document Type",
+	T1."document_number" AS "Document Number",
+	T1."position_in_document" AS "Position In Document",
+	T1."customer_number" AS "Customer Number",
+	T1."nominal_account_number" AS "Nominal Account Number",
+	T1."is_balanced" AS "Is Balanced",
+	T1."clearing_number" AS "Clearing Number",
+	T1."document_date" AS "Document Date",
+	T1."posted_value" AS "Posted Value",
+	T1."debit_or_credit" AS "Debit Or Credit",
+	T1."posted_count" AS "Posted Count",
+	T1."branch_number" AS "Branch Number",
+	T1."customer_contra_account" AS "Customer Contra Account",
+	T1."nominal_contra_account" AS "Nominal Contra Account",
+	T1."contra_account_text" AS "Contra Account Text",
+	T1."account_form_page_number" AS "Account Form Page Number",
+	T1."account_form_page_line" AS "Account Form Page Line",
+	T1."serial_number_each_month" AS "Serial Number Each Month",
+	T1."employee_number" AS "Employee Number",
+	T1."invoice_date" AS "Invoice Date",
+	T1."invoice_number" AS "Invoice Number",
+	T1."dunning_level" AS "Dunning Level",
+	T1."last_dunning_date" AS "Last Dunning Date",
+	T1."journal_page" AS "Journal Page",
+	T1."journal_line" AS "Journal Line",
+	T1."cash_discount" AS "Cash Discount",
+	T1."term_of_payment" AS "Term Of Payment",
+	'-' AS "Posting Text",
+	T1."vehicle_reference" AS "Vehicle Reference",
+	T1."vat_id_number" AS "Vat Id Number",
+	T1."account_statement_number" AS "Account Statement Number",
+	T1."account_statement_page" AS "Account Statement Page",
+	T1."vat_key" AS "Vat Key",
+	T1."days_for_cash_discount" AS "Days For Cash Discount",
+	T1."day_of_actual_accounting" AS "Day Of Actual Accounting",
+	T1."skr51_branch" AS "Skr51 Branch",
+	T1."skr51_make" AS "Skr51 Make",
+	T1."skr51_cost_center" AS "Skr51 Cost Center",
+	T1."skr51_sales_channel" AS "Skr51 Sales Channel",
+	T1."skr51_cost_unit" AS "Skr51 Cost Unit",
+	T1."previously_used_account_no" AS "Previously Used Account No",
+	(substring(T1."free_form_accounting_text", 1, 100)) AS "Free Form Accounting Text",
+	CASE 
+		WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN ('Neuwagen')
+		WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59)
+			THEN ('Gebrauchtwagen')
+		WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69)
+			THEN ('Teile & Zubehör')
+		WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79)
+			THEN ('Service')
+		WHEN (T1."skr51_cost_unit" = 0)
+			THEN ('Ohne Kostenträger')
+		ELSE NULL
+		END AS "Free Form Document Text",
+	T2."is_profit_loss_account" AS "Nom_Account_Is Profit Loss Account",
+	T1."subsidiary_to_company_ref" AS "Rechtseinheit",
+	('0' + (convert(VARCHAR(50), T1."skr51_branch"))) AS "Betrieb",
+	T1."accounting_date" AS "Bookkeep Date",
+	(rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + T3."skr51_make_description" AS "Marke",
+	'' AS "Text",
+	'1' AS "Mandant",
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_value" / 100 * - 1)
+		ELSE (T1."posted_value" / 100)
+		END AS "Betrag",
+	(
+		rtrim((
+				CASE 
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+						THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+						THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+						THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					END
+				))
+		) + ' - ' + T2."account_description" AS "Konto_mit_Bezeichnung",
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_count" / 100 * - 1)
+		ELSE (T1."posted_count" / 100)
+		END AS "Menge",
+	(len((convert(VARCHAR(50), T1."skr51_cost_center")))) AS "Stellen Cost Center",
+	(rtrim((convert(VARCHAR(50), T1."skr51_cost_center")))) + ' - ' + T3."skr51_cost_center_name" AS "KST",
+	(len((convert(VARCHAR(50), T1."skr51_sales_channel")))) AS "Stellen Sales Channel",
+	(rtrim((convert(VARCHAR(50), T1."skr51_sales_channel")))) + ' - ' + T3."skr51_sales_channel_name" AS "Absatzkanal",
+	(len((convert(VARCHAR(50), T1."skr51_cost_unit")))) AS "Stellen Cost Unit",
+	(rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name") AS "Kostenträger_mit_Null",
+	CASE 
+		WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN (((rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name")))
+		ELSE ((rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name"))
+		END AS "Kostenträger",
+	CASE 
+		WHEN (T2."is_profit_loss_account" = 'J')
+			THEN ('2')
+		ELSE ('1')
+		END AS "GuV_Bilanz",
+	(
+		substring((
+				CASE 
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+						THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+						THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+						THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					END
+				), 1, 1)
+		) AS "Susa",
+	CASE 
+		WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+			THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+			THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+			THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		END AS "Acct Nr",
+	(len((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))) AS "Stellen_Konto_Nr"
+FROM (
+	"dbo"."journal_accountings" T1 LEFT OUTER JOIN "dbo"."accounts_characteristics" T3 ON (
+			(
+				(
+					(
+						(T3."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")
+						AND (T3."skr51_branch" = T1."skr51_branch")
+						)
+					AND (T3."skr51_make" = T1."skr51_make")
+					)
+				AND (T3."skr51_cost_center" = T1."skr51_cost_center")
+				)
+			AND (T3."skr51_sales_channel" = T1."skr51_sales_channel")
+			)
+		AND (T3."skr51_cost_unit" = T1."skr51_cost_unit")
+	)
+INNER JOIN "dbo"."nominal_accounts" T2 ON (
+		(T2."nominal_account_number" = T1."nominal_account_number")
+		AND (T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")
+		)
+WHERE (
+		(T2."is_profit_loss_account" = 'N')
+		AND (
+			NOT (
+				(
+					rtrim((
+							CASE 
+								WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+									THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+									THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+									THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								END
+							))
+					) + ' - ' + T2."account_description"
+				) LIKE '9%'
+			)
+		)
+	-- order by "Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 115 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_fm.sql

@@ -0,0 +1,115 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[loc_belege_bilanz_fm]
+AS
+SELECT "GC_Department"."Hauptbetrieb_ID" AS "Rechtseinheit_ID",
+	"GC_Department"."Hauptbetrieb_Name" AS "Rechtseinheit_Name",
+	"GC_Department"."Standort_ID" AS "Betrieb_ID",
+	"GC_Department"."Standort_Name" AS "Betrieb_Name",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene1" AS "Ebene1",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene2" AS "Ebene2",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene3" AS "Ebene3",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene4" AS "Ebene4",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene5" AS "Ebene5",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene6" AS "Ebene6",
+	left("Kontenrahmen_GC_Struct_SKR"."Konto Nr", 4) + ' - ' + "Kontenrahmen_GC_Struct_SKR"."Konto Bezeichnung" AS "Konto",
+	"LOC_Belege_Bilanz"."Acct Nr" AS "Acct_Nr",
+	"LOC_Belege_Bilanz"."Text" AS "Text",
+	CASE 
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '1'
+			THEN 'Neuwagen'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '2'
+			THEN 'Gebrauchtwagen'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '3'
+			THEN 'Teile & Zubehör'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '4'
+			THEN 'Service'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '5'
+			THEN 'Weitere Bereiche'
+		WHEN left(left("LOC_Belege_Bilanz"."KST", 2), 1) = '0'
+			THEN 'ohne Herkunft'
+		ELSE 'Verwaltung'
+		END AS "Kostenstelle",
+	"LOC_Belege_Bilanz"."KST" AS "KST_mit_Bez",
+	left("LOC_Belege_Bilanz"."KST", 2) AS "KST",
+	left("LOC_Belege_Bilanz"."Marke", 1) AS "Markencode",
+	"LOC_Belege_Bilanz"."Vehicle Reference" AS "Fahrgestellnummer",
+	left("Kontenrahmen_GC_Struct_SKR"."Konto Nr", 4) + ' - ' + "Kontenrahmen_GC_Struct_SKR"."Konto Bezeichnung" AS "Konto_Buchung",
+	"LOC_Belege_Bilanz"."Marke" AS "Marke_mit_Bez",
+	left("LOC_Belege_Bilanz"."Marke", 1) AS "Marke",
+	CASE 
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '1'
+			THEN 'Privater Endkunde'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '2'
+			THEN 'Gewerbekunde'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '3'
+			THEN 'Großkunde'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '4'
+			THEN 'Sonderabnehmer'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '5'
+			THEN 'Wiederverkäufer'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '6'
+			THEN 'Wirtschaftsraum'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '9'
+			THEN 'Sonstige'
+		WHEN left(left("LOC_Belege_Bilanz"."Absatzkanal", 2), 1) = '0'
+			THEN 'ohne Absatzkanal'
+		ELSE NULL
+		END AS "Ebene21",
+	"LOC_Belege_Bilanz"."Absatzkanal" AS "Absatzkanal_mit_Bez",
+	left("LOC_Belege_Bilanz"."Absatzkanal", 2) AS "Absatzkanal",
+	"LOC_Belege_Bilanz"."Free Form Document Text" AS "Ebene31",
+	"LOC_Belege_Bilanz"."Kostenträger" AS "Kostenträger_mit_Bez",
+	left("LOC_Belege_Bilanz"."Kostenträger", 2) AS "Kostenträger_FIBU",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene71" AS "Ebene71",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene72" AS "Ebene72",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene73" AS "Ebene73",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene74" AS "Ebene74",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene75" AS "Ebene75",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene76" AS "Ebene76",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene77" AS "Ebene77",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene81" AS "Ebene81",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene82" AS "Ebene82",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene83" AS "Ebene83",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene84" AS "Ebene84",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene85" AS "Ebene85",
+	"Kontenrahmen_GC_Struct_SKR"."Ebene86" AS "Ebene86",
+	"LOC_Belege_Bilanz"."GuV_Bilanz" AS "GuV_Bilanz",
+	"LOC_Belege_Bilanz"."Susa" AS "Susa",
+	"LOC_Belege_Bilanz"."Mandant" AS "Mandant",
+	"LOC_Belege_Bilanz"."Betrag" AS "Ist",
+	"LOC_Belege_Bilanz"."Menge" AS "Menge",
+	"GC_Department"."Gruppe_ID" AS "Gruppe_ID",
+	"GC_Department"."Gruppe_Name" AS "Gruppe_Name",
+	"LOC_Belege_Bilanz"."Bookkeep Date" AS "Invoice_Date",
+	CASE 
+		WHEN "GC_Marken"."Fabrikat" IS NULL
+			THEN 'Fremd'
+		ELSE "GC_Marken"."Fabrikat"
+		END AS "Fabrikat",
+	CASE 
+		WHEN CASE 
+				WHEN "GC_Marken"."Fabrikat" IS NULL
+					THEN 'Fremd'
+				ELSE "GC_Marken"."Fabrikat"
+				END = 'Fremd'
+			THEN 9
+		ELSE "GC_Marken"."Order_By"
+		END AS "Fabrikat_Order_By"
+FROM (
+	(
+		"GC"."locosoft"."LOC_Belege_Bilanz" "LOC_Belege_Bilanz" LEFT OUTER JOIN "GC"."data"."GC_Department" "GC_Department" ON "LOC_Belege_Bilanz"."Rechtseinheit" = "GC_Department"."Hauptbetrieb"
+			AND "LOC_Belege_Bilanz"."Betrieb" = "GC_Department"."Standort"
+		) LEFT OUTER JOIN "GC"."data"."GC_Marken" "GC_Marken" ON "LOC_Belege_Bilanz"."Marke" = "GC_Marken"."Marke_FIBU"
+		AND "LOC_Belege_Bilanz"."Rechtseinheit" = "GC_Marken"."Client_DB"
+	)
+LEFT OUTER JOIN "GC"."locosoft"."Kontenrahmen_GC_Struct_SKR" "Kontenrahmen_GC_Struct_SKR" ON "LOC_Belege_Bilanz"."Acct Nr" = "Kontenrahmen_GC_Struct_SKR"."Konto Nr"
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 180 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz_imr.sql

@@ -0,0 +1,180 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW [staging].[loc_belege_bilanz_imr]
+AS
+SELECT T1."accounting_date" AS "Accounting Date",
+	T1."document_type" AS "Document Type",
+	T1."document_number" AS "Document Number",
+	T1."position_in_document" AS "Position In Document",
+	T1."customer_number" AS "Customer Number",
+	T1."nominal_account_number" AS "Nominal Account Number",
+	T1."is_balanced" AS "Is Balanced",
+	T1."clearing_number" AS "Clearing Number",
+	T1."document_date" AS "Document Date",
+	T1."posted_value" AS "Posted Value",
+	T1."debit_or_credit" AS "Debit Or Credit",
+	T1."posted_count" AS "Posted Count",
+	T1."branch_number" AS "Branch Number",
+	T1."customer_contra_account" AS "Customer Contra Account",
+	T1."nominal_contra_account" AS "Nominal Contra Account",
+	T1."contra_account_text" AS "Contra Account Text",
+	T1."account_form_page_number" AS "Account Form Page Number",
+	T1."account_form_page_line" AS "Account Form Page Line",
+	T1."serial_number_each_month" AS "Serial Number Each Month",
+	T1."employee_number" AS "Employee Number",
+	T1."invoice_date" AS "Invoice Date",
+	T1."invoice_number" AS "Invoice Number",
+	T1."dunning_level" AS "Dunning Level",
+	T1."last_dunning_date" AS "Last Dunning Date",
+	T1."journal_page" AS "Journal Page",
+	T1."journal_line" AS "Journal Line",
+	T1."cash_discount" AS "Cash Discount",
+	T1."term_of_payment" AS "Term Of Payment",
+	'-' AS "Posting Text",
+	T1."vehicle_reference" AS "Vehicle Reference",
+	T1."vat_id_number" AS "Vat Id Number",
+	T1."account_statement_number" AS "Account Statement Number",
+	T1."account_statement_page" AS "Account Statement Page",
+	T1."vat_key" AS "Vat Key",
+	T1."days_for_cash_discount" AS "Days For Cash Discount",
+	T1."day_of_actual_accounting" AS "Day Of Actual Accounting",
+	T1."skr51_branch" AS "Skr51 Branch",
+	T1."skr51_make" AS "Skr51 Make",
+	T1."skr51_cost_center" AS "Skr51 Cost Center",
+	T1."skr51_sales_channel" AS "Skr51 Sales Channel",
+	T1."skr51_cost_unit" AS "Skr51 Cost Unit",
+	T1."previously_used_account_no" AS "Previously Used Account No",
+	(substring(T1."free_form_accounting_text", 1, 100)) AS "Free Form Accounting Text",
+	CASE 
+		WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN ('Neuwagen')
+		WHEN (T1."skr51_cost_unit" BETWEEN 50 AND 59)
+			THEN ('Gebrauchtwagen')
+		WHEN (T1."skr51_cost_unit" BETWEEN 60 AND 69)
+			THEN ('Teile & Zubehör')
+		WHEN (T1."skr51_cost_unit" BETWEEN 70 AND 79)
+			THEN ('Service')
+		WHEN (T1."skr51_cost_unit" = 0)
+			THEN ('Ohne Kostenträger')
+		ELSE NULL
+		END AS "Free Form Document Text",
+	T2."is_profit_loss_account" AS "Nom_Account_Is Profit Loss Account",
+	T1."subsidiary_to_company_ref" AS "Rechtseinheit",
+	('0' + (convert(VARCHAR(50), T1."skr51_branch"))) AS "Betrieb",
+	T1."accounting_date" AS "Bookkeep Date",
+	(rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + T3."skr51_make_description" AS "Marke",
+	'' AS "Text",
+	'1' AS "Mandant",
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_value" / 100 * - 1)
+		ELSE (T1."posted_value" / 100)
+		END AS "Betrag",
+	(
+		rtrim((
+				CASE 
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+						THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+						THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+						THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					END
+				))
+		) + ' - ' + T2."account_description" AS "Konto_mit_Bezeichnung",
+	CASE 
+		WHEN (T1."debit_or_credit" = 'H')
+			THEN (T1."posted_count" / 100 * - 1)
+		ELSE (T1."posted_count" / 100)
+		END AS "Menge",
+	(len((convert(VARCHAR(50), T1."skr51_cost_center")))) AS "Stellen Cost Center",
+	(rtrim((convert(VARCHAR(50), T1."skr51_cost_center")))) + ' - ' + T3."skr51_cost_center_name" AS "KST",
+	(len((convert(VARCHAR(50), T1."skr51_sales_channel")))) AS "Stellen Sales Channel",
+	(rtrim((convert(VARCHAR(50), T1."skr51_sales_channel")))) + ' - ' + T3."skr51_sales_channel_name" AS "Absatzkanal",
+	(len((convert(VARCHAR(50), T1."skr51_cost_unit")))) AS "Stellen Cost Unit",
+	(rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name") AS "Kostenträger_mit_Null",
+	CASE 
+		WHEN (T1."skr51_cost_unit" BETWEEN 1 AND 49)
+			THEN (((rtrim((convert(VARCHAR(50), T1."skr51_make")))) + ' - ' + (rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name")))
+		ELSE ((rtrim((convert(VARCHAR(50), T1."skr51_cost_unit")))) + ' - ' + (T3."skr51_cost_unit_name"))
+		END AS "Kostenträger",
+	CASE 
+		WHEN (T2."is_profit_loss_account" = 'J')
+			THEN ('2')
+		ELSE ('1')
+		END AS "GuV_Bilanz",
+	(
+		substring((
+				CASE 
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+						THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+						THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+						THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+					END
+				), 1, 1)
+		) AS "Susa",
+	CASE 
+		WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+			THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+			THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+			THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+		END AS "Acct Nr",
+	(len((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))) AS "Stellen_Konto_Nr"
+FROM "dbo"."nominal_accounts" T2,
+	(
+		"dbo"."journal_accountings" T1 LEFT OUTER JOIN "dbo"."accounts_characteristics" T3 ON (
+				(
+					(
+						(
+							(T3."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")
+							AND (T3."skr51_branch" = T1."skr51_branch")
+							)
+						AND (T3."skr51_make" = T1."skr51_make")
+						)
+					AND (T3."skr51_cost_center" = T1."skr51_cost_center")
+					)
+				AND (T3."skr51_sales_channel" = T1."skr51_sales_channel")
+				)
+			AND (T3."skr51_cost_unit" = T1."skr51_cost_unit")
+		)
+WHERE (
+		(T2."nominal_account_number" = T1."nominal_account_number")
+		AND (T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref")
+		)
+	AND (
+		(T2."is_profit_loss_account" = 'N')
+		AND (
+			NOT (
+				(
+					rtrim((
+							CASE 
+								WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 1)
+									THEN ('000' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 2)
+									THEN ('00' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								WHEN (((len((rtrim((convert(VARCHAR(50), T1."nominal_account_number"))))))) = 3)
+									THEN ('0' + (rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								ELSE ((rtrim((convert(VARCHAR(50), T1."nominal_account_number")))))
+								END
+							))
+					) + ' - ' + T2."account_description"
+				) LIKE '9%'
+			)
+		)
+	-- order by "Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels