瀏覽代碼

Entwicklungsumgebung

- iqd_convert.py eingebaut
- SQL lauffähig
gc-server6 1 年之前
父節點
當前提交
b191229031
共有 67 個文件被更改,包括 8296 次插入8 次删除
  1. 227 0
      GCStruct_SKR51/Kontenrahmen/kontenrahmen.csv.xml
  2. 108 0
      System/LOCOSOFT/IQD/Belege/Kontenrahmen.sql
  3. 30 0
      System/LOCOSOFT/IQD/Belege/current_date_Prognose.sql
  4. 108 0
      System/LOCOSOFT/IQD/Belege/kontenrahmen_gc_struct_skr.sql
  5. 69 0
      System/LOCOSOFT/IQD/Belege/loc_belege.sql
  6. 70 0
      System/LOCOSOFT/IQD/Belege/loc_belege_bilanz.sql
  7. 406 0
      System/LOCOSOFT/IQD/NW/LOC_Belege_NW_GW_VK.sql
  8. 545 0
      System/LOCOSOFT/IQD/NW/LOC_Belege_NW_GW_VK_Stk_FIBU.sql
  9. 545 0
      System/LOCOSOFT/IQD/NW/LOC_Belege_NW_GW_VK_Stk_FIBU_Vorlage.sql
  10. 252 0
      System/LOCOSOFT/IQD/NW/NW_GW_BE_auf_NW_GW_Bestand_Cat.sql
  11. 111 0
      System/LOCOSOFT/IQD/OP/Kreditorenbewegungen.sql
  12. 13 0
      System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_8520.sql
  13. 190 0
      System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_Deb_Saldo.sql
  14. 160 0
      System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_nur_8520.sql
  15. 190 0
      System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_ohne_8520.sql
  16. 70 0
      System/LOCOSOFT/IQD/Serv_Teile/Aftersales_Rechnungen_ben_AW_final.sql
  17. 256 0
      System/LOCOSOFT/IQD/Serv_Teile/Aftersales_Rechnungen_neu.sql
  18. 32 0
      System/LOCOSOFT/IQD/Serv_Teile/Aftersales_Rechnungen_verk_AW_final.sql
  19. 7 0
      System/LOCOSOFT/IQD/Serv_Teile/Imvoice_No_Order_No.sql
  20. 11 0
      System/LOCOSOFT/IQD/Serv_Teile/Serviceberater_Rechnung.sql
  21. 6 0
      System/LOCOSOFT/IQD/Serv_Teile/ben_AW_Order_Number.sql
  22. 93 0
      System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_DG_Anz_Tage.sql
  23. 100 0
      System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_Teile.sql
  24. 104 0
      System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_Ums_ben_AW.sql
  25. 18 0
      System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql
  26. 118 0
      System/LOCOSOFT/IQD/Zeit/Zeit_Abwesenheit_neu.sql
  27. 168 0
      System/LOCOSOFT/IQD/Zeit/Zeit_Stempelungen_Pausen.sql
  28. 171 0
      System/LOCOSOFT/IQD/Zeit/Zeit_Stempelungen_Pausen_produktiv.sql
  29. 35 0
      System/LOCOSOFT/IQD/Zeit/Zeit_Stempelungen_neu.sql
  30. 75 0
      System/LOCOSOFT/IQD/Zeit/Zeit_ben_Std_LG.sql
  31. 36 0
      System/LOCOSOFT/IQD/Zeit/Zeit_verk_Std.sql
  32. 20 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Imvoice_No_Order_No.sql
  33. 121 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Kontenrahmen.sql
  34. 26 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.OP_aus_LOC_Belege_8520.sql
  35. 24 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.Serviceberater_Rechnung.sql
  36. 19 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.ben_AW_Order_Number.sql
  37. 31 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql
  38. 83 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_ben_AW_final.sql
  39. 269 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_neu.sql
  40. 45 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Aftersales_Rechnungen_verk_AW_final.sql
  41. 20 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Imvoice_No_Order_No.sql
  42. 125 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kontenrahmen.sql
  43. 117 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kreditorenbewegungen.sql
  44. 419 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.LOC_Belege_NW_GW_VK.sql
  45. 558 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.LOC_Belege_NW_GW_VK_Stk_FIBU.sql
  46. 265 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.NW_GW_BE_auf_NW_GW_Bestand_Cat.sql
  47. 26 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_8520.sql
  48. 196 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_Deb_Saldo.sql
  49. 173 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_nur_8520.sql
  50. 196 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_ohne_8520.sql
  51. 24 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Serviceberater_Rechnung.sql
  52. 131 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Abwesenheit_neu.sql
  53. 181 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_Pausen.sql
  54. 184 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_Pausen_produktiv.sql
  55. 48 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_Stempelungen_neu.sql
  56. 88 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_ben_Std_LG.sql
  57. 49 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Zeit_verk_Std.sql
  58. 19 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.ben_AW_Order_Number.sql
  59. 82 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege.sql
  60. 83 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.loc_belege_bilanz.sql
  61. 106 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.offene_Auftraege_DG_Anz_Tage.sql
  62. 113 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.offene_Auftraege_Teile.sql
  63. 31 0
      System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql
  64. 1 2
      Tasks/LOCOSOFT_Cubes.bat
  65. 9 5
      Tasks/scripts/Tools/controllers/ImpromptuController.php
  66. 2 1
      Tasks/scripts/impromptu.bat
  67. 88 0
      Tasks/scripts/iqd_convert.py

+ 227 - 0
GCStruct_SKR51/Kontenrahmen/kontenrahmen.csv.xml

@@ -0,0 +1,227 @@
+<?xml version="1.0"?>
+<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<RECORD>
+  <FIELD ID="1" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="2" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="3" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="4" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="5" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="6" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="7" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="8" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="9" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="10" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="11" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="12" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="13" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="14" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="15" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="16" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="17" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="18" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="19" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="20" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="21" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="22" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="23" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="24" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="25" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="26" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="27" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="28" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="29" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="30" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="31" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="32" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="33" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="34" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="35" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="36" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="37" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="38" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="39" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="40" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="41" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="42" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="43" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="44" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="45" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="46" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="47" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="48" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="49" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="50" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="51" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="52" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="53" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="54" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="55" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="56" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="57" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="58" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="59" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="60" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="61" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="62" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="63" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="64" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="65" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="66" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="67" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="68" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="69" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="70" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="71" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="72" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="73" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="74" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="75" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="76" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="77" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="78" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="79" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="80" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="81" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="82" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="83" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="84" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="85" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="86" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="87" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="88" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="89" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="90" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="91" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="92" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="93" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="94" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="95" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="96" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="97" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="98" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="99" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="100" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="101" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="102" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="103" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="104" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="105" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="106" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="107" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="108" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="109" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+  <FIELD ID="110" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="255" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
+</RECORD>
+<ROW>
+  <COLUMN SOURCE="1" NAME="KONTO_NR" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="2" NAME="KONTO_BEZEICHNUNG" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="3" NAME="KONTO_ART" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="4" NAME="KOSTENSTELLE" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="5" NAME="STK" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="6" NAME="KONTO_1" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="7" NAME="KONTO_2" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="8" NAME="KONTO_3" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="9" NAME="KONTO_4" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="10" NAME="KONTO_5" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="11" NAME="EBENE1" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="12" NAME="EBENE2" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="13" NAME="EBENE3" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="14" NAME="EBENE4" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="15" NAME="EBENE5" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="16" NAME="EBENE6" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="17" NAME="EBENE7" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="18" NAME="EBENE8" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="19" NAME="EBENE9" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="20" NAME="EBENE10" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="21" NAME="EBENE11" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="22" NAME="EBENE12" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="23" NAME="EBENE13" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="24" NAME="EBENE14" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="25" NAME="EBENE15" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="26" NAME="EBENE16" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="27" NAME="EBENE17" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="28" NAME="EBENE18" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="29" NAME="EBENE19" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="30" NAME="EBENE20" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="31" NAME="EBENE21" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="32" NAME="EBENE22" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="33" NAME="EBENE23" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="34" NAME="EBENE24" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="35" NAME="EBENE25" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="36" NAME="EBENE26" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="37" NAME="EBENE27" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="38" NAME="EBENE28" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="39" NAME="EBENE29" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="40" NAME="EBENE30" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="41" NAME="EBENE31" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="42" NAME="EBENE32" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="43" NAME="EBENE33" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="44" NAME="EBENE34" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="45" NAME="EBENE35" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="46" NAME="EBENE36" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="47" NAME="EBENE37" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="48" NAME="EBENE38" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="49" NAME="EBENE39" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="50" NAME="EBENE40" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="51" NAME="EBENE41" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="52" NAME="EBENE42" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="53" NAME="EBENE43" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="54" NAME="EBENE44" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="55" NAME="EBENE45" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="56" NAME="EBENE46" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="57" NAME="EBENE47" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="58" NAME="EBENE48" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="59" NAME="EBENE49" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="60" NAME="EBENE50" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="61" NAME="EBENE51" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="62" NAME="EBENE52" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="63" NAME="EBENE53" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="64" NAME="EBENE54" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="65" NAME="EBENE55" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="66" NAME="EBENE56" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="67" NAME="EBENE57" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="68" NAME="EBENE58" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="69" NAME="EBENE59" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="70" NAME="EBENE60" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="71" NAME="EBENE61" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="72" NAME="EBENE62" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="73" NAME="EBENE63" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="74" NAME="EBENE64" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="75" NAME="EBENE65" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="76" NAME="EBENE66" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="77" NAME="EBENE67" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="78" NAME="EBENE68" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="79" NAME="EBENE69" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="80" NAME="EBENE70" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="81" NAME="EBENE71" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="82" NAME="EBENE72" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="83" NAME="EBENE73" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="84" NAME="EBENE74" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="85" NAME="EBENE75" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="86" NAME="EBENE76" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="87" NAME="EBENE77" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="88" NAME="EBENE78" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="89" NAME="EBENE79" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="90" NAME="EBENE80" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="91" NAME="EBENE81" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="92" NAME="EBENE82" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="93" NAME="EBENE83" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="94" NAME="EBENE84" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="95" NAME="EBENE85" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="96" NAME="EBENE86" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="97" NAME="EBENE87" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="98" NAME="EBENE88" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="99" NAME="EBENE89" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="100" NAME="EBENE90" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="101" NAME="EBENE91" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="102" NAME="EBENE92" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="103" NAME="EBENE93" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="104" NAME="EBENE94" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="105" NAME="EBENE95" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="106" NAME="EBENE96" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="107" NAME="EBENE97" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="108" NAME="EBENE98" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="109" NAME="EBENE99" xsi:type="SQLVARYCHAR"/>
+  <COLUMN SOURCE="110" NAME="EBENE100" xsi:type="SQLVARYCHAR"/>
+</ROW>
+</BCPFORMAT>

+ 108 - 0
System/LOCOSOFT/IQD/Belege/Kontenrahmen.sql

@@ -0,0 +1,108 @@
+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",
+	   (length(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",
+	   (od_left(T1."KONTO_NR",1)) as "Susa"
+from "Kontenrahmen.csv" T1
+where (((od_left(T1."KONTO_NR",1))) <> '9')

+ 30 - 0
System/LOCOSOFT/IQD/Belege/current_date_Prognose.sql

@@ -0,0 +1,30 @@
+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

+ 108 - 0
System/LOCOSOFT/IQD/Belege/kontenrahmen_gc_struct_skr.sql

@@ -0,0 +1,108 @@
+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",
+	   (length(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",
+	   (od_left(T1."KONTO_NR",1)) as "Susa"
+from "Kontenrahmen.csv" T1
+where (((od_left(T1."KONTO_NR",1))) <> '9')

+ 69 - 0
System/LOCOSOFT/IQD/Belege/loc_belege.sql

@@ -0,0 +1,69 @@
+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"."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 T1."posting_text" IN ('G&V-Abschlussbuchung')))
+-- order by "Nominal Account Number" asc

+ 70 - 0
System/LOCOSOFT/IQD/Belege/loc_belege_bilanz.sql

@@ -0,0 +1,70 @@
+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

+ 406 - 0
System/LOCOSOFT/IQD/NW/LOC_Belege_NW_GW_VK.sql

@@ -0,0 +1,406 @@
+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 (substring(T1."vehicle_reference", 1, 7)) + '_' + (right(T1."vehicle_reference",17)) as c150,
+	   (convert(datetime, (((substring(T1."invoice_date", 1, 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,
+	   ((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + ' - ' + T4."account_description") as c178,
+	   (substring(((substring(T1."vehicle_reference", 1, 7)) + '_' + (right(T1."vehicle_reference",17))), 1, 7)) + ' / ' + ((substring((convert(varchar(50), T8."internal_number")), 1, 5))) + ' - ' + T10."description" + ' - ' + (((substring((convert(varchar(50), T8."holder_number")), 1, 7)) + ' - ' + (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,
+	   (substring((convert(varchar(50), T8."salesman_number")), 1, 4)) + ' - ' + 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,
+	   ((substring((convert(varchar(50), T8."holder_number")), 1, 7)) + ' - ' + (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,
+	   (substring((upper(T10."description")), 1, 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 (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c202,
+	   CASE WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END as c203,
+	   (substring(T1."vehicle_reference", 1, 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 (((convert(datetime, (((substring(T1."invoice_date", 1, 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,
+	   (substring((convert(varchar(50), T1."nominal_account_number")), 1, 1)) 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")))) 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")))) 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")))) 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 (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

+ 545 - 0
System/LOCOSOFT/IQD/NW/LOC_Belege_NW_GW_VK_Stk_FIBU.sql

@@ -0,0 +1,545 @@
+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 (substring(T1."vehicle_reference", 1, 8)) + '_' + (right(T1."vehicle_reference",17)) as c149,
+	   (((convert(float, (substring(T1."invoice_date", 1, 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,
+	   (reverse(rtrim(reverse(((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + '_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,
+	   ((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + ' - ' + T2."account_description") as c176,
+	   (right(T6."vin",5)) + ' / ' + ((substring((convert(varchar(50), T6."internal_number")), 1, 5))) + ' - ' + T8."description" + ' - ' + (CASE WHEN (T10."first_name" <> ' ') THEN ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + 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,
+	   (substring((convert(varchar(50), T6."salesman_number")), 1, 3)) + ' - ' + 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 ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + 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,
+	   (substring((upper(T8."description")), 1, 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 (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c198,
+	   CASE WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END as c199,
+	   (substring(T1."vehicle_reference", 1, 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 (((((convert(float, (substring(T1."invoice_date", 1, 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,
+	   (substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + '_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")))) 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")))) 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")))) 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 (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

+ 545 - 0
System/LOCOSOFT/IQD/NW/LOC_Belege_NW_GW_VK_Stk_FIBU_Vorlage.sql

@@ -0,0 +1,545 @@
+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 (substring(T1."vehicle_reference", 1, 8)) + '_' + (right(T1."vehicle_reference",17)) as c149,
+	   (convert(datetime, (((substring(T1."invoice_date", 1, 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,
+	   (reverse(rtrim(reverse(((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + '_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,
+	   ((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + ' - ' + T2."account_description") as c176,
+	   (right(T6."vin",5)) + ' / ' + ((substring((convert(varchar(50), T6."internal_number")), 1, 5))) + ' - ' + T8."description" + ' - ' + (CASE WHEN (T10."first_name" <> ' ') THEN ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + 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,
+	   (substring((convert(varchar(50), T6."salesman_number")), 1, 3)) + ' - ' + 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 ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + 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,
+	   (substring((upper(T8."description")), 1, 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 (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c198,
+	   CASE WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END as c199,
+	   (substring(T1."vehicle_reference", 1, 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 (((convert(datetime, (((substring(T1."invoice_date", 1, 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,
+	   (substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + '_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")))) 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")))) 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")))) 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 (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

+ 252 - 0
System/LOCOSOFT/IQD/NW/NW_GW_BE_auf_NW_GW_Bestand_Cat.sql

@@ -0,0 +1,252 @@
+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,
+	   (substring((convert(varchar(50), T5."customer_number")), 1, 7)) + ' - ' + 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 ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('N')) THEN ('NW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('V')) THEN ('VFW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('D')) THEN ('GW diff.') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('G')) THEN ('GW regel.') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c179,
+	   CASE WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('N')) THEN ('NW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('V')) THEN ('VFW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('D')) THEN ('GW diff.') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('G')) THEN ('GW regel.') WHEN ((substring(T2."dealer_vehicle_type", 1, 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

文件差異過大導致無法顯示
+ 111 - 0
System/LOCOSOFT/IQD/OP/Kreditorenbewegungen.sql


+ 13 - 0
System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_8520.sql

@@ -0,0 +1,13 @@
+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

文件差異過大導致無法顯示
+ 190 - 0
System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_Deb_Saldo.sql


+ 160 - 0
System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_nur_8520.sql

@@ -0,0 +1,160 @@
+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"))) = 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"))) = 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)) 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,
+	   CASE WHEN (T3."first_name" <> ' ') THEN ((substring((convert(varchar(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name") ELSE ((substring((convert(varchar(50), T3."customer_number")), 1, 7)) + ' - ' + 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,
+	   (substring((convert(varchar(50), T2."employee_number")), 1, 3)) + ' - ' + 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,
+	   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" + ' - ' + ((substring((convert(varchar(50), T2."employee_number")), 1, 3)) + ' - ' + 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

文件差異過大導致無法顯示
+ 190 - 0
System/LOCOSOFT/IQD/OP/OP_aus_LOC_Belege_ohne_8520.sql


+ 70 - 0
System/LOCOSOFT/IQD/Serv_Teile/Aftersales_Rechnungen_ben_AW_final.sql

@@ -0,0 +1,70 @@
+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

+ 256 - 0
System/LOCOSOFT/IQD/Serv_Teile/Aftersales_Rechnungen_neu.sql

@@ -0,0 +1,256 @@
+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",
+	   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

+ 32 - 0
System/LOCOSOFT/IQD/Serv_Teile/Aftersales_Rechnungen_verk_AW_final.sql

@@ -0,0 +1,32 @@
+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

+ 7 - 0
System/LOCOSOFT/IQD/Serv_Teile/Imvoice_No_Order_No.sql

@@ -0,0 +1,7 @@
+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

+ 11 - 0
System/LOCOSOFT/IQD/Serv_Teile/Serviceberater_Rechnung.sql

@@ -0,0 +1,11 @@
+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" >= convert(datetime, '2019-01-01 00:00:00.000')))
+-- order by "Invoice_Type_Invoice_Number" asc,"Invoice Number" asc

+ 6 - 0
System/LOCOSOFT/IQD/Serv_Teile/ben_AW_Order_Number.sql

@@ -0,0 +1,6 @@
+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

+ 93 - 0
System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_DG_Anz_Tage.sql

@@ -0,0 +1,93 @@
+select c51 as "Order Number_ori",
+	   c91 as "Order Position",
+	   c90 as "Labour Type",
+	   c89 as "Subsidiary",
+	   c88 as "Is Invoiced",
+	   c87 as "Invoice Type",
+	   c86 as "Invoice Number",
+	   c85 as "Order Date",
+	   c84 as "Estimated Inbound Time",
+	   c83 as "Estimated Outbound Time",
+	   c82 as "Order Print Date",
+	   c81 as "Order Taking Employee No",
+	   c80 as "Order Delivery Employee No",
+	   c79 as "Vehicle Number",
+	   c78 as "Order Mileage",
+	   c77 as "Order Customer",
+	   c76 as "Paying Customer",
+	   c75 as "Holder Number",
+	   c74 as "Parts Rebate Group Sell",
+	   c73 as "Clearing Delay Type",
+	   c72 as "Code_Labour_Type",
+	   c71 as "Description_Labour_Type",
+	   c70 as "Hauptbetrieb",
+	   c69 as "Standort",
+	   c68 as "Name_Serviceberater",
+	   c67 as "Serviceberater",
+	   c66 as "Umsatzart",
+	   c65 as "Customer Number_Cust",
+	   c64 as "First Name_Cust",
+	   c63 as "Family Name_Cust",
+	   c62 as "Kunde",
+	   c61 as "Order Number",
+	   c60 as "Internal Number_Vehicle",
+	   c59 as "Vin_Vehicle",
+	   c58 as "License Plate_Vehicle",
+	   c57 as "Make Number_Vehicle",
+	   'Service' as "Auftragsart",
+	   c56 as "Make Number_Makes",
+	   c55 as "Description_Makes",
+	   c55 as "Fabrikat",
+	   c54 as "Description_Models",
+	   c53 as "Model",
+	   1 as "DG_1",
+	   COUNT(c89) OVER (partition by c51) as "DG_2",
+	   1 / (COUNT(c89) OVER (partition by c51)) as "DG",
+	   c52 as "Anzahl Tage_1",
+	   (c52) / (COUNT(c89) OVER (partition by c51)) as "Anzahl Tage"
+from 
+(select T1."order_number" as c51,
+	   (day((getdate()) - T1."order_date")) as c52,
+	   (substring((upper(T8."description")), 1, 3)) as c53,
+	   T8."description" as c54,
+	   T7."description" as c55,
+	   T7."make_number" as c56,
+	   T6."make_number" as c57,
+	   T6."license_plate" as c58,
+	   T6."vin" as c59,
+	   T6."internal_number" as c60,
+	   CASE WHEN (T6."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)) + ' - ' + T4."name") END) + ' - ' + T5."family_name" + ' - ' + (convert(varchar(50), year(T1."order_date")) + '-' + convert(varchar(50), month(T1."order_date")) + '-' + convert(varchar(50), day(T1."order_date"))) + ' - ' + T6."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)) + ' - ' + T4."name") END) + ' - ' + T5."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 c61,
+	   (substring((convert(varchar(50), T5."customer_number")), 1, 7)) + ' - ' + T5."first_name" + ' ' + T5."family_name" as c62,
+	   T5."family_name" as c63,
+	   T5."first_name" as c64,
+	   T5."customer_number" as c65,
+	   T3."code" + ' - ' + T3."description" as c66,
+	   CASE WHEN (T1."order_taking_employee_no" = 0) THEN ('SB fehlt') ELSE ((substring((convert(varchar(50), T1."order_taking_employee_no")), 1, 4)) + ' - ' + T4."name") END as c67,
+	   T4."name" as c68,
+	   '0' + (convert(varchar(50), T1."subsidiary")) as c69,
+	   CASE WHEN (('0' + (convert(varchar(50), T1."subsidiary"))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as c70,
+	   T3."description" as c71,
+	   T3."code" as c72,
+	   T1."clearing_delay_type" as c73,
+	   T1."parts_rebate_group_sell" as c74,
+	   T1."holder_number" as c75,
+	   T1."paying_customer" as c76,
+	   T1."order_customer" as c77,
+	   T1."order_mileage" as c78,
+	   T1."vehicle_number" as c79,
+	   T1."order_delivery_employee_no" as c80,
+	   T1."order_taking_employee_no" as c81,
+	   T1."order_print_date" as c82,
+	   T1."estimated_outbound_time" as c83,
+	   T1."estimated_inbound_time" as c84,
+	   T1."order_date" as c85,
+	   T2."invoice_number" as c86,
+	   T2."invoice_type" as c87,
+	   T2."is_invoiced" as c88,
+	   T1."subsidiary" as c89,
+	   T2."labour_type" as c90,
+	   T1."order_position" as c91
+from ((((((("dbo"."order_positions" T1 left outer join "dbo"."labours" T2 on T1."order_number" = T2."order_number") left outer join "dbo"."labour_types" T3 on T3."code" = T2."labour_type") left outer join "dbo"."employees" T4 on T1."order_taking_employee_no" = T4."employee_number") left outer join "dbo"."customers_suppliers" T5 on T1."order_customer" = T5."customer_number") left outer join "dbo"."vehicles" T6 on T1."vehicle_number" = T6."internal_number") left outer join "dbo"."makes" T7 on T6."make_number" = T7."make_number") left outer join "dbo"."models" T8 on (T6."make_number" = T8."make_number") and (T6."model_code" = T8."model_code"))
+where (((T2."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2020-01-01 00:00:00.000'))) and (T2."labour_type" <> 'F'))
+-- order by c51 asc
+) D1

+ 100 - 0
System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_Teile.sql

@@ -0,0 +1,100 @@
+select distinct c55 as "Order Number_ori",
+	   c97 as "Order Position",
+	   '' as "Labour Type",
+	   c96 as "Subsidiary",
+	   c95 as "Is Invoiced",
+	   c94 as "Invoice Type",
+	   c93 as "Invoice Number",
+	   c92 as "Order Date",
+	   c91 as "Estimated Inbound Time",
+	   c90 as "Estimated Outbound Time",
+	   c89 as "Order Print Date",
+	   c88 as "Order Taking Employee No",
+	   c87 as "Order Delivery Employee No",
+	   c86 as "Vehicle Number",
+	   c85 as "Order Mileage",
+	   c84 as "Order Customer",
+	   c83 as "Paying Customer",
+	   c82 as "Holder Number",
+	   c81 as "Parts Rebate Group Sell",
+	   c80 as "Clearing Delay Type",
+	   '' as "Code_Labour_Type",
+	   '' as "Description_Labour_Type",
+	   c79 as "Hauptbetrieb",
+	   c78 as "Standort",
+	   c77 as "Name_Serviceberater",
+	   c76 as "Serviceberater",
+	   'Teile' as "Umsatzart",
+	   c75 as "Customer Number_Cust",
+	   c74 as "First Name_Cust",
+	   c73 as "Family Name_Cust",
+	   c72 as "Kunde",
+	   c71 as "Order Number",
+	   c70 as "Internal Number_Vehicle",
+	   c69 as "Vin_Vehicle",
+	   c68 as "License Plate_Vehicle",
+	   c67 as "Make Number_Vehicle",
+	   'Service' as "Auftragsart",
+	   c66 as "Make Number_Makes",
+	   c65 as "Description_Makes",
+	   c65 as "Fabrikat",
+	   c64 as "Description_Models",
+	   c63 as "Model",
+	   1 as "DG_1",
+	   COUNT('') OVER (partition by c55) as "DG_2",
+	   c62 as "Part Number",
+	   c61 as "Stock No",
+	   c60 as "Stock Removal Date",
+	   c59 as "Amount",
+	   c56 as "Sum",
+	   c58 as "Parts Type",
+	   c57 as "Text Line",
+	   c56 as "Teile"
+from 
+(select T1."order_number" as c55,
+	   T2."sum" as c56,
+	   T2."text_line" as c57,
+	   T2."parts_type" as c58,
+	   T2."amount" as c59,
+	   T2."stock_removal_date" as c60,
+	   T2."stock_no" as c61,
+	   T2."part_number" as c62,
+	   (substring((upper(T7."description")), 1, 3)) as c63,
+	   T7."description" as c64,
+	   T6."description" as c65,
+	   T6."make_number" as c66,
+	   T5."make_number" as c67,
+	   T5."license_plate" as c68,
+	   T5."vin" as c69,
+	   T5."internal_number" as c70,
+	   CASE WHEN (T5."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"))) + ' - ' + T5."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 c71,
+	   (substring((convert(varchar(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name" as c72,
+	   T4."family_name" as c73,
+	   T4."first_name" as c74,
+	   T4."customer_number" as c75,
+	   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 as c76,
+	   T3."name" as c77,
+	   '0' + (convert(varchar(50), T1."subsidiary")) as c78,
+	   CASE WHEN (('0' + (convert(varchar(50), T1."subsidiary"))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as c79,
+	   T1."clearing_delay_type" as c80,
+	   T1."parts_rebate_group_sell" as c81,
+	   T1."holder_number" as c82,
+	   T1."paying_customer" as c83,
+	   T1."order_customer" as c84,
+	   T1."order_mileage" as c85,
+	   T1."vehicle_number" as c86,
+	   T1."order_delivery_employee_no" as c87,
+	   T1."order_taking_employee_no" as c88,
+	   T1."order_print_date" as c89,
+	   T1."estimated_outbound_time" as c90,
+	   T1."estimated_inbound_time" as c91,
+	   T1."order_date" as c92,
+	   T2."invoice_number" as c93,
+	   T2."invoice_type" as c94,
+	   T2."is_invoiced" as c95,
+	   T1."subsidiary" as c96,
+	   T2."order_position" as c97
+from (((((("dbo"."order_positions" T1 left outer join "dbo"."parts" T2 on T1."order_number" = T2."order_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"."vehicles" T5 on T1."vehicle_number" = T5."internal_number") left outer join "dbo"."makes" T6 on T5."make_number" = T6."make_number") left outer join "dbo"."models" T7 on (T5."make_number" = T7."make_number") and (T5."model_code" = T7."model_code"))
+where ((((T2."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2017-01-01 00:00:00.000'))) and (T2."sum" IS NOT NULL)) and ('' <> 'F'))
+) D1
+-- order by "Order Number_ori" asc

+ 104 - 0
System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_Ums_ben_AW.sql

@@ -0,0 +1,104 @@
+select "Order Number_ori",
+	   "Order Position",
+	   "Labour Type",
+	   "Subsidiary",
+	   "Is Invoiced",
+	   "Invoice Type",
+	   "Invoice Number",
+	   "Order Date",
+	   "Estimated Inbound Time",
+	   "Estimated Outbound Time",
+	   "Order Print Date",
+	   "Order Taking Employee No",
+	   "Order Delivery Employee No",
+	   "Vehicle Number",
+	   "Order Mileage",
+	   "Order Customer",
+	   "Paying Customer",
+	   "Holder Number",
+	   "Parts Rebate Group Sell",
+	   "Clearing Delay Type",
+	   "Code_Labour_Type",
+	   "Description_Labour_Type",
+	   "Hauptbetrieb",
+	   "Standort",
+	   "Name_Serviceberater",
+	   "Serviceberater",
+	   "Umsatzart",
+	   "Customer Number_Cust",
+	   "First Name_Cust",
+	   "Family Name_Cust",
+	   "Kunde",
+	   "Order Number",
+	   "Internal Number_Vehicle",
+	   "Vin_Vehicle",
+	   "License Plate_Vehicle",
+	   "Make Number_Vehicle",
+	   'Service' as "Auftragsart",
+	   "Make Number_Makes",
+	   "Description_Makes",
+	   "Description_Makes" as "Fabrikat",
+	   "Description_Models",
+	   "Model",
+	   1 as "DG_1",
+	   COUNT("Subsidiary") OVER (partition by "Order Number_ori") as "DG_2",
+	   "Order Number_Labours",
+	   "Order Position_Labours",
+	   "Net Price In Order",
+	   "Text Line",
+	   "Order Number_ben_AW",
+	   "Summe Duration Minutes_ben_AW",
+	   c57 / (COUNT("Subsidiary") OVER (partition by "Order Number_ori")) as "ben. Std",
+	   "Net Price In Order" as "Umsatz Lohn"
+from 
+(select T1."order_number" as "Order Number_ori",
+	   T2."net_price_in_order" as "Net Price In Order",
+	   T9."Summe_Duration_Minutes" / 60 as c57,
+	   T9."Summe_Duration_Minutes" as "Summe Duration Minutes_ben_AW",
+	   T9."order_number" as "Order Number_ben_AW",
+	   T2."text_line" as "Text Line",
+	   T2."order_position" as "Order Position_Labours",
+	   T2."order_number" as "Order Number_Labours",
+	   (substring((upper(T8."description")), 1, 3)) as "Model",
+	   T8."description" as "Description_Models",
+	   T7."description" as "Description_Makes",
+	   T7."make_number" as "Make Number_Makes",
+	   T6."make_number" as "Make Number_Vehicle",
+	   T6."license_plate" as "License Plate_Vehicle",
+	   T6."vin" as "Vin_Vehicle",
+	   T6."internal_number" as "Internal Number_Vehicle",
+	   CASE WHEN (T6."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)) + ' - ' + T4."name") END) + ' - ' + T5."family_name" + ' - ' + (convert(varchar(50), year(T1."order_date")) + '-' + convert(varchar(50), month(T1."order_date")) + '-' + convert(varchar(50), day(T1."order_date"))) + ' - ' + T6."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)) + ' - ' + T4."name") END) + ' - ' + T5."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 "Order Number",
+	   (substring((convert(varchar(50), T5."customer_number")), 1, 7)) + ' - ' + T5."first_name" + ' ' + T5."family_name" as "Kunde",
+	   T5."family_name" as "Family Name_Cust",
+	   T5."first_name" as "First Name_Cust",
+	   T5."customer_number" as "Customer Number_Cust",
+	   T3."code" + ' - ' + T3."description" as "Umsatzart",
+	   CASE WHEN (T1."order_taking_employee_no" = 0) THEN ('SB fehlt') ELSE ((substring((convert(varchar(50), T1."order_taking_employee_no")), 1, 4)) + ' - ' + T4."name") END as "Serviceberater",
+	   T4."name" as "Name_Serviceberater",
+	   '0' + (convert(varchar(50), T1."subsidiary")) as "Standort",
+	   CASE WHEN (('0' + (convert(varchar(50), T1."subsidiary"))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as "Hauptbetrieb",
+	   T3."description" as "Description_Labour_Type",
+	   T3."code" as "Code_Labour_Type",
+	   T1."clearing_delay_type" as "Clearing Delay Type",
+	   T1."parts_rebate_group_sell" as "Parts Rebate Group Sell",
+	   T1."holder_number" as "Holder Number",
+	   T1."paying_customer" as "Paying Customer",
+	   T1."order_customer" as "Order Customer",
+	   T1."order_mileage" as "Order Mileage",
+	   T1."vehicle_number" as "Vehicle Number",
+	   T1."order_delivery_employee_no" as "Order Delivery Employee No",
+	   T1."order_taking_employee_no" as "Order Taking Employee No",
+	   T1."order_print_date" as "Order Print Date",
+	   T1."estimated_outbound_time" as "Estimated Outbound Time",
+	   T1."estimated_inbound_time" as "Estimated Inbound Time",
+	   T1."order_date" as "Order Date",
+	   T2."invoice_number" as "Invoice Number",
+	   T2."invoice_type" as "Invoice Type",
+	   T2."is_invoiced" as "Is Invoiced",
+	   T1."subsidiary" as "Subsidiary",
+	   T2."labour_type" as "Labour Type",
+	   T1."order_position" as "Order Position"
+from (((((((("dbo"."order_positions" T1 left outer join "dbo"."labours" T2 on T1."order_number" = T2."order_number") left outer join "dbo"."labour_types" T3 on T3."code" = T2."labour_type") left outer join "dbo"."employees" T4 on T1."order_taking_employee_no" = T4."employee_number") left outer join "dbo"."customers_suppliers" T5 on T1."order_customer" = T5."customer_number") left outer join "dbo"."vehicles" T6 on T1."vehicle_number" = T6."internal_number") left outer join "dbo"."makes" T7 on T6."make_number" = T7."make_number") left outer join "dbo"."models" T8 on (T6."make_number" = T8."make_number") and (T6."model_code" = T8."model_code")) left outer join "ims"."ben_AW_Order_Number" T9 on T2."order_number" = T9."order_number")
+where ((((T2."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2017-01-01 00:00:00.000'))) and (T2."net_price_in_order" IS NOT NULL)) and (T2."labour_type" <> 'F'))
+-- order by "Order Number_ori" asc
+) D1

+ 18 - 0
System/LOCOSOFT/IQD/Serv_Teile/offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql

@@ -0,0 +1,18 @@
+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

+ 118 - 0
System/LOCOSOFT/IQD/Zeit/Zeit_Abwesenheit_neu.sql

@@ -0,0 +1,118 @@
+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",
+	   c72 as "Name_Employees",
+	   c71 as "Initials_Employees",
+	   c70 as "Mechanic Number_Employees",
+	   c69 as "Salesman Number_Employees",
+	   c68 as "Employment Date_Employees",
+	   c67 as "Termination Date_Employees",
+	   c66 as "Leave Date_Employees",
+	   c65 as "Employee Number_Absence_Cal",
+	   c49 as "Date_Absence_Cal",
+	   c64 as "Type_Absence_Cal",
+	   c63 as "Is Payed_Absence_Cal",
+	   c62 as "Day Contingent_Absence_Cal",
+	   c61 as "Reason_Absence_Cal",
+	   c60 as "Booking Flag_Absence_Cal",
+	   c59 as "Id_Absence_Reas",
+	   c58 as "Description_Absence_Reas",
+	   c57 as "Is Annual Vacation_Absence_Reas",
+	   c56 as "Type_Absence_Types",
+	   c55 as "Description_Absence_Types",
+	   c54 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,
+	   (datepart({weekday},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,
+	   CASE WHEN (('0' + (rtrim((convert(varchar(50), T1."subsidiary"))))) IN ('015')) THEN ('15') ELSE ('1') END as c54,
+	   T4."description" as c55,
+	   T4."type" as c56,
+	   T3."is_annual_vacation" as c57,
+	   T3."description" as c58,
+	   T3."id" as c59,
+	   T2."booking_flag" as c60,
+	   T2."reason" as c61,
+	   T2."day_contingent" as c62,
+	   T2."is_payed" as c63,
+	   T2."type" as c64,
+	   T2."employee_number" as c65,
+	   T1."leave_date" as c66,
+	   T1."termination_date" as c67,
+	   T1."employment_date" as c68,
+	   T1."salesman_number" as c69,
+	   T1."mechanic_number" as c70,
+	   T1."initials" as c71,
+	   T1."name" as c72
+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 ((((datepart({weekday},T2."date"))) = T5."dayofweek") and ((cdate(T2."date")) <= (@CURRENT_DATE)))
+) D2
+) D1
+where ("Validity Date_Worktimes" = c39)
+-- order by "Employee Number_Employees" asc

+ 168 - 0
System/LOCOSOFT/IQD/Zeit/Zeit_Stempelungen_Pausen.sql

@@ -0,0 +1,168 @@
+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,
+	   ((datepart({hour},T2."end_time"))) + (((datepart({minute},T2."end_time"))) / 60) as c70,
+	   ((datepart({minute},T2."end_time"))) / 60 as c71,
+	   ((datepart({hour},T2."start_time"))) + (((datepart({minute},T2."start_time"))) / 60) as c72,
+	   ((datepart({minute},T2."start_time"))) / 60 as c73,
+	   (datepart({minute},T2."end_time")) as c74,
+	   (datepart({hour},T2."end_time")) as c75,
+	   (datepart({minute},T2."start_time")) as c76,
+	   (datepart({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,
+	   (datepart({weekday},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 (((datepart({weekday},T2."start_time"))) = T4."dayofweek")) and (((datepart({weekday},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

+ 171 - 0
System/LOCOSOFT/IQD/Zeit/Zeit_Stempelungen_Pausen_produktiv.sql

@@ -0,0 +1,171 @@
+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 (((datepart({hour},T2."start_time"))) + (((datepart({minute},T2."start_time"))) / 60)) AND (((datepart({hour},T2."end_time"))) + (((datepart({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,
+	   ((datepart({hour},T2."end_time"))) + (((datepart({minute},T2."end_time"))) / 60) as c72,
+	   ((datepart({minute},T2."end_time"))) / 60 as c73,
+	   ((datepart({hour},T2."start_time"))) + (((datepart({minute},T2."start_time"))) / 60) as c74,
+	   ((datepart({minute},T2."start_time"))) / 60 as c75,
+	   (datepart({minute},T2."end_time")) as c76,
+	   (datepart({hour},T2."end_time")) as c77,
+	   (datepart({minute},T2."start_time")) as c78,
+	   (datepart({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,
+	   (datepart({weekday},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 (((datepart({weekday},T2."start_time"))) = T4."dayofweek")) and (((datepart({weekday},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

+ 35 - 0
System/LOCOSOFT/IQD/Zeit/Zeit_Stempelungen_neu.sql

@@ -0,0 +1,35 @@
+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",
+	   CASE WHEN (('0' + (rtrim((convert(varchar(50), T1."subsidiary"))))) IN ('015')) THEN ('15') ELSE ('1') END 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",
+	   (datepart({weekday},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

+ 75 - 0
System/LOCOSOFT/IQD/Zeit/Zeit_ben_Std_LG.sql

@@ -0,0 +1,75 @@
+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

+ 36 - 0
System/LOCOSOFT/IQD/Zeit/Zeit_verk_Std.sql

@@ -0,0 +1,36 @@
+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

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

@@ -0,0 +1,20 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+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",
+	   (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

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

@@ -0,0 +1,121 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+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",
+	   (length(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",
+	   (od_left(T1."KONTO_NR",1)) as "Susa"
+from "Kontenrahmen.csv" T1
+where (((od_left(T1."KONTO_NR",1))) <> '9')
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

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

@@ -0,0 +1,26 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+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'))
+-- order by "Invoice Number" asc,"Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

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

@@ -0,0 +1,24 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+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",
+	   (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
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

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

@@ -0,0 +1,19 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+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
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 31 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/ims.offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql

@@ -0,0 +1,31 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+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 ((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
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

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

@@ -0,0 +1,83 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW staging.Aftersales_Rechnungen_ben_AW_final 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

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

@@ -0,0 +1,269 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW staging.Aftersales_Rechnungen_neu 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",
+	   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

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

@@ -0,0 +1,45 @@
+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",
+	   (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

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

@@ -0,0 +1,20 @@
+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

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

@@ -0,0 +1,125 @@
+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

文件差異過大導致無法顯示
+ 117 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.Kreditorenbewegungen.sql


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

@@ -0,0 +1,419 @@
+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 (substring(T1."vehicle_reference", 1, 7)) + '_' + (right(T1."vehicle_reference",17)) as c150,
+	   (convert(datetime, (((substring(T1."invoice_date", 1, 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,
+	   ((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + ' - ' + T4."account_description") as c178,
+	   (substring(((substring(T1."vehicle_reference", 1, 7)) + '_' + (right(T1."vehicle_reference",17))), 1, 7)) + ' / ' + ((substring((convert(varchar(50), T8."internal_number")), 1, 5))) + ' - ' + T10."description" + ' - ' + (((substring((convert(varchar(50), T8."holder_number")), 1, 7)) + ' - ' + (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,
+	   (substring((convert(varchar(50), T8."salesman_number")), 1, 4)) + ' - ' + 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,
+	   ((substring((convert(varchar(50), T8."holder_number")), 1, 7)) + ' - ' + (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,
+	   (substring((upper(T10."description")), 1, 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 (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c202,
+	   CASE WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END as c203,
+	   (substring(T1."vehicle_reference", 1, 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 (((convert(datetime, (((substring(T1."invoice_date", 1, 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,
+	   (substring((convert(varchar(50), T1."nominal_account_number")), 1, 1)) 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")))) 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")))) 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")))) 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 (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

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

@@ -0,0 +1,558 @@
+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 (substring(T1."vehicle_reference", 1, 8)) + '_' + (right(T1."vehicle_reference",17)) as c149,
+	   (((convert(float, (substring(T1."invoice_date", 1, 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,
+	   (reverse(rtrim(reverse(((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + '_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,
+	   ((substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + ' - ' + T2."account_description") as c176,
+	   (right(T6."vin",5)) + ' / ' + ((substring((convert(varchar(50), T6."internal_number")), 1, 5))) + ' - ' + T8."description" + ' - ' + (CASE WHEN (T10."first_name" <> ' ') THEN ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + 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,
+	   (substring((convert(varchar(50), T6."salesman_number")), 1, 3)) + ' - ' + 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 ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + T10."first_name" + ' ' + T10."family_name") ELSE ((substring((convert(varchar(50), T6."holder_number")), 1, 6)) + ' - ' + 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,
+	   (substring((upper(T8."description")), 1, 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 (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c198,
+	   CASE WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('N')) THEN ('NW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('V')) THEN ('VFW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('G','D')) THEN ('GW') WHEN (((substring(T1."vehicle_reference", 1, 1))) IN ('T')) THEN ('TZ') ELSE null END as c199,
+	   (substring(T1."vehicle_reference", 1, 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 (((((convert(float, (substring(T1."invoice_date", 1, 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,
+	   (substring((convert(varchar(50), T1."nominal_account_number")), 1, 4)) + '_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")))) 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")))) 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")))) 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 (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

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

@@ -0,0 +1,265 @@
+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,
+	   (substring((convert(varchar(50), T5."customer_number")), 1, 7)) + ' - ' + 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 ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('N')) THEN ('NW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('V')) THEN ('VFW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('D')) THEN ('GW diff.') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('G')) THEN ('GW regel.') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('T')) THEN ('TZ') ELSE null END) IN ('VFW','TZ','NW')) THEN ('Neuwagen') ELSE ('Gebrauchtwagen') END as c179,
+	   CASE WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('N')) THEN ('NW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('V')) THEN ('VFW') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('D')) THEN ('GW diff.') WHEN ((substring(T2."dealer_vehicle_type", 1, 1)) IN ('G')) THEN ('GW regel.') WHEN ((substring(T2."dealer_vehicle_type", 1, 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

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

@@ -0,0 +1,26 @@
+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'))
+-- order by "Invoice Number" asc,"Nominal Account Number" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

文件差異過大導致無法顯示
+ 196 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_Deb_Saldo.sql


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

@@ -0,0 +1,173 @@
+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"))) = 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"))) = 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)) 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,
+	   CASE WHEN (T3."first_name" <> ' ') THEN ((substring((convert(varchar(50), T3."customer_number")), 1, 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name") ELSE ((substring((convert(varchar(50), T3."customer_number")), 1, 7)) + ' - ' + 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,
+	   (substring((convert(varchar(50), T2."employee_number")), 1, 3)) + ' - ' + 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,
+	   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" + ' - ' + ((substring((convert(varchar(50), T2."employee_number")), 1, 3)) + ' - ' + 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

文件差異過大導致無法顯示
+ 196 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.OP_aus_LOC_Belege_ohne_8520.sql


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

@@ -0,0 +1,24 @@
+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

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

@@ -0,0 +1,131 @@
+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",
+	   c72 as "Name_Employees",
+	   c71 as "Initials_Employees",
+	   c70 as "Mechanic Number_Employees",
+	   c69 as "Salesman Number_Employees",
+	   c68 as "Employment Date_Employees",
+	   c67 as "Termination Date_Employees",
+	   c66 as "Leave Date_Employees",
+	   c65 as "Employee Number_Absence_Cal",
+	   c49 as "Date_Absence_Cal",
+	   c64 as "Type_Absence_Cal",
+	   c63 as "Is Payed_Absence_Cal",
+	   c62 as "Day Contingent_Absence_Cal",
+	   c61 as "Reason_Absence_Cal",
+	   c60 as "Booking Flag_Absence_Cal",
+	   c59 as "Id_Absence_Reas",
+	   c58 as "Description_Absence_Reas",
+	   c57 as "Is Annual Vacation_Absence_Reas",
+	   c56 as "Type_Absence_Types",
+	   c55 as "Description_Absence_Types",
+	   c54 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,
+	   (datepart({weekday},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,
+	   CASE WHEN (('0' + (rtrim((convert(varchar(50), T1."subsidiary"))))) IN ('015')) THEN ('15') ELSE ('1') END as c54,
+	   T4."description" as c55,
+	   T4."type" as c56,
+	   T3."is_annual_vacation" as c57,
+	   T3."description" as c58,
+	   T3."id" as c59,
+	   T2."booking_flag" as c60,
+	   T2."reason" as c61,
+	   T2."day_contingent" as c62,
+	   T2."is_payed" as c63,
+	   T2."type" as c64,
+	   T2."employee_number" as c65,
+	   T1."leave_date" as c66,
+	   T1."termination_date" as c67,
+	   T1."employment_date" as c68,
+	   T1."salesman_number" as c69,
+	   T1."mechanic_number" as c70,
+	   T1."initials" as c71,
+	   T1."name" as c72
+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 ((((datepart({weekday},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

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

@@ -0,0 +1,181 @@
+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,
+	   ((datepart({hour},T2."end_time"))) + (((datepart({minute},T2."end_time"))) / 60) as c70,
+	   ((datepart({minute},T2."end_time"))) / 60 as c71,
+	   ((datepart({hour},T2."start_time"))) + (((datepart({minute},T2."start_time"))) / 60) as c72,
+	   ((datepart({minute},T2."start_time"))) / 60 as c73,
+	   (datepart({minute},T2."end_time")) as c74,
+	   (datepart({hour},T2."end_time")) as c75,
+	   (datepart({minute},T2."start_time")) as c76,
+	   (datepart({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,
+	   (datepart({weekday},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 (((datepart({weekday},T2."start_time"))) = T4."dayofweek")) and (((datepart({weekday},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

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

@@ -0,0 +1,184 @@
+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 (((datepart({hour},T2."start_time"))) + (((datepart({minute},T2."start_time"))) / 60)) AND (((datepart({hour},T2."end_time"))) + (((datepart({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,
+	   ((datepart({hour},T2."end_time"))) + (((datepart({minute},T2."end_time"))) / 60) as c72,
+	   ((datepart({minute},T2."end_time"))) / 60 as c73,
+	   ((datepart({hour},T2."start_time"))) + (((datepart({minute},T2."start_time"))) / 60) as c74,
+	   ((datepart({minute},T2."start_time"))) / 60 as c75,
+	   (datepart({minute},T2."end_time")) as c76,
+	   (datepart({hour},T2."end_time")) as c77,
+	   (datepart({minute},T2."start_time")) as c78,
+	   (datepart({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,
+	   (datepart({weekday},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 (((datepart({weekday},T2."start_time"))) = T4."dayofweek")) and (((datepart({weekday},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

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

@@ -0,0 +1,48 @@
+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",
+	   CASE WHEN (('0' + (rtrim((convert(varchar(50), T1."subsidiary"))))) IN ('015')) THEN ('15') ELSE ('1') END 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",
+	   (datepart({weekday},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

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

@@ -0,0 +1,88 @@
+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

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

@@ -0,0 +1,49 @@
+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

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

@@ -0,0 +1,19 @@
+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

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

@@ -0,0 +1,82 @@
+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",
+	   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"."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 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

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

@@ -0,0 +1,83 @@
+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",
+	   (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

+ 106 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.offene_Auftraege_DG_Anz_Tage.sql

@@ -0,0 +1,106 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW staging.offene_Auftraege_DG_Anz_Tage AS
+
+select c51 as "Order Number_ori",
+	   c91 as "Order Position",
+	   c90 as "Labour Type",
+	   c89 as "Subsidiary",
+	   c88 as "Is Invoiced",
+	   c87 as "Invoice Type",
+	   c86 as "Invoice Number",
+	   c85 as "Order Date",
+	   c84 as "Estimated Inbound Time",
+	   c83 as "Estimated Outbound Time",
+	   c82 as "Order Print Date",
+	   c81 as "Order Taking Employee No",
+	   c80 as "Order Delivery Employee No",
+	   c79 as "Vehicle Number",
+	   c78 as "Order Mileage",
+	   c77 as "Order Customer",
+	   c76 as "Paying Customer",
+	   c75 as "Holder Number",
+	   c74 as "Parts Rebate Group Sell",
+	   c73 as "Clearing Delay Type",
+	   c72 as "Code_Labour_Type",
+	   c71 as "Description_Labour_Type",
+	   c70 as "Hauptbetrieb",
+	   c69 as "Standort",
+	   c68 as "Name_Serviceberater",
+	   c67 as "Serviceberater",
+	   c66 as "Umsatzart",
+	   c65 as "Customer Number_Cust",
+	   c64 as "First Name_Cust",
+	   c63 as "Family Name_Cust",
+	   c62 as "Kunde",
+	   c61 as "Order Number",
+	   c60 as "Internal Number_Vehicle",
+	   c59 as "Vin_Vehicle",
+	   c58 as "License Plate_Vehicle",
+	   c57 as "Make Number_Vehicle",
+	   'Service' as "Auftragsart",
+	   c56 as "Make Number_Makes",
+	   c55 as "Description_Makes",
+	   c55 as "Fabrikat",
+	   c54 as "Description_Models",
+	   c53 as "Model",
+	   1 as "DG_1",
+	   COUNT(c89) OVER (partition by c51) as "DG_2",
+	   1 / (COUNT(c89) OVER (partition by c51)) as "DG",
+	   c52 as "Anzahl Tage_1",
+	   (c52) / (COUNT(c89) OVER (partition by c51)) as "Anzahl Tage"
+from 
+(select T1."order_number" as c51,
+	   (day((getdate()) - T1."order_date")) as c52,
+	   (substring((upper(T8."description")), 1, 3)) as c53,
+	   T8."description" as c54,
+	   T7."description" as c55,
+	   T7."make_number" as c56,
+	   T6."make_number" as c57,
+	   T6."license_plate" as c58,
+	   T6."vin" as c59,
+	   T6."internal_number" as c60,
+	   CASE WHEN (T6."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)) + ' - ' + T4."name") END) + ' - ' + T5."family_name" + ' - ' + (convert(varchar(50), year(T1."order_date")) + '-' + convert(varchar(50), month(T1."order_date")) + '-' + convert(varchar(50), day(T1."order_date"))) + ' - ' + T6."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)) + ' - ' + T4."name") END) + ' - ' + T5."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 c61,
+	   (substring((convert(varchar(50), T5."customer_number")), 1, 7)) + ' - ' + T5."first_name" + ' ' + T5."family_name" as c62,
+	   T5."family_name" as c63,
+	   T5."first_name" as c64,
+	   T5."customer_number" as c65,
+	   T3."code" + ' - ' + T3."description" as c66,
+	   CASE WHEN (T1."order_taking_employee_no" = 0) THEN ('SB fehlt') ELSE ((substring((convert(varchar(50), T1."order_taking_employee_no")), 1, 4)) + ' - ' + T4."name") END as c67,
+	   T4."name" as c68,
+	   '0' + (convert(varchar(50), T1."subsidiary")) as c69,
+	   CASE WHEN (('0' + (convert(varchar(50), T1."subsidiary"))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as c70,
+	   T3."description" as c71,
+	   T3."code" as c72,
+	   T1."clearing_delay_type" as c73,
+	   T1."parts_rebate_group_sell" as c74,
+	   T1."holder_number" as c75,
+	   T1."paying_customer" as c76,
+	   T1."order_customer" as c77,
+	   T1."order_mileage" as c78,
+	   T1."vehicle_number" as c79,
+	   T1."order_delivery_employee_no" as c80,
+	   T1."order_taking_employee_no" as c81,
+	   T1."order_print_date" as c82,
+	   T1."estimated_outbound_time" as c83,
+	   T1."estimated_inbound_time" as c84,
+	   T1."order_date" as c85,
+	   T2."invoice_number" as c86,
+	   T2."invoice_type" as c87,
+	   T2."is_invoiced" as c88,
+	   T1."subsidiary" as c89,
+	   T2."labour_type" as c90,
+	   T1."order_position" as c91
+from ((((((("dbo"."order_positions" T1 left outer join "dbo"."labours" T2 on T1."order_number" = T2."order_number") left outer join "dbo"."labour_types" T3 on T3."code" = T2."labour_type") left outer join "dbo"."employees" T4 on T1."order_taking_employee_no" = T4."employee_number") left outer join "dbo"."customers_suppliers" T5 on T1."order_customer" = T5."customer_number") left outer join "dbo"."vehicles" T6 on T1."vehicle_number" = T6."internal_number") left outer join "dbo"."makes" T7 on T6."make_number" = T7."make_number") left outer join "dbo"."models" T8 on (T6."make_number" = T8."make_number") and (T6."model_code" = T8."model_code"))
+where (((T2."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2020-01-01 00:00:00.000'))) and (T2."labour_type" <> 'F'))
+-- order by c51 asc
+) D1
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 113 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.offene_Auftraege_Teile.sql

@@ -0,0 +1,113 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW staging.offene_Auftraege_Teile AS
+
+select distinct c55 as "Order Number_ori",
+	   c97 as "Order Position",
+	   '' as "Labour Type",
+	   c96 as "Subsidiary",
+	   c95 as "Is Invoiced",
+	   c94 as "Invoice Type",
+	   c93 as "Invoice Number",
+	   c92 as "Order Date",
+	   c91 as "Estimated Inbound Time",
+	   c90 as "Estimated Outbound Time",
+	   c89 as "Order Print Date",
+	   c88 as "Order Taking Employee No",
+	   c87 as "Order Delivery Employee No",
+	   c86 as "Vehicle Number",
+	   c85 as "Order Mileage",
+	   c84 as "Order Customer",
+	   c83 as "Paying Customer",
+	   c82 as "Holder Number",
+	   c81 as "Parts Rebate Group Sell",
+	   c80 as "Clearing Delay Type",
+	   '' as "Code_Labour_Type",
+	   '' as "Description_Labour_Type",
+	   c79 as "Hauptbetrieb",
+	   c78 as "Standort",
+	   c77 as "Name_Serviceberater",
+	   c76 as "Serviceberater",
+	   'Teile' as "Umsatzart",
+	   c75 as "Customer Number_Cust",
+	   c74 as "First Name_Cust",
+	   c73 as "Family Name_Cust",
+	   c72 as "Kunde",
+	   c71 as "Order Number",
+	   c70 as "Internal Number_Vehicle",
+	   c69 as "Vin_Vehicle",
+	   c68 as "License Plate_Vehicle",
+	   c67 as "Make Number_Vehicle",
+	   'Service' as "Auftragsart",
+	   c66 as "Make Number_Makes",
+	   c65 as "Description_Makes",
+	   c65 as "Fabrikat",
+	   c64 as "Description_Models",
+	   c63 as "Model",
+	   1 as "DG_1",
+	   COUNT('') OVER (partition by c55) as "DG_2",
+	   c62 as "Part Number",
+	   c61 as "Stock No",
+	   c60 as "Stock Removal Date",
+	   c59 as "Amount",
+	   c56 as "Sum",
+	   c58 as "Parts Type",
+	   c57 as "Text Line",
+	   c56 as "Teile"
+from 
+(select T1."order_number" as c55,
+	   T2."sum" as c56,
+	   T2."text_line" as c57,
+	   T2."parts_type" as c58,
+	   T2."amount" as c59,
+	   T2."stock_removal_date" as c60,
+	   T2."stock_no" as c61,
+	   T2."part_number" as c62,
+	   (substring((upper(T7."description")), 1, 3)) as c63,
+	   T7."description" as c64,
+	   T6."description" as c65,
+	   T6."make_number" as c66,
+	   T5."make_number" as c67,
+	   T5."license_plate" as c68,
+	   T5."vin" as c69,
+	   T5."internal_number" as c70,
+	   CASE WHEN (T5."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"))) + ' - ' + T5."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 c71,
+	   (substring((convert(varchar(50), T4."customer_number")), 1, 7)) + ' - ' + T4."first_name" + ' ' + T4."family_name" as c72,
+	   T4."family_name" as c73,
+	   T4."first_name" as c74,
+	   T4."customer_number" as c75,
+	   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 as c76,
+	   T3."name" as c77,
+	   '0' + (convert(varchar(50), T1."subsidiary")) as c78,
+	   CASE WHEN (('0' + (convert(varchar(50), T1."subsidiary"))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as c79,
+	   T1."clearing_delay_type" as c80,
+	   T1."parts_rebate_group_sell" as c81,
+	   T1."holder_number" as c82,
+	   T1."paying_customer" as c83,
+	   T1."order_customer" as c84,
+	   T1."order_mileage" as c85,
+	   T1."vehicle_number" as c86,
+	   T1."order_delivery_employee_no" as c87,
+	   T1."order_taking_employee_no" as c88,
+	   T1."order_print_date" as c89,
+	   T1."estimated_outbound_time" as c90,
+	   T1."estimated_inbound_time" as c91,
+	   T1."order_date" as c92,
+	   T2."invoice_number" as c93,
+	   T2."invoice_type" as c94,
+	   T2."is_invoiced" as c95,
+	   T1."subsidiary" as c96,
+	   T2."order_position" as c97
+from (((((("dbo"."order_positions" T1 left outer join "dbo"."parts" T2 on T1."order_number" = T2."order_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"."vehicles" T5 on T1."vehicle_number" = T5."internal_number") left outer join "dbo"."makes" T6 on T5."make_number" = T6."make_number") left outer join "dbo"."models" T7 on (T5."make_number" = T7."make_number") and (T5."model_code" = T7."model_code"))
+where ((((T2."invoice_number" IS NULL) and (T1."order_date" >= convert(datetime, '2017-01-01 00:00:00.000'))) and (T2."sum" IS NOT NULL)) and ('' <> 'F'))
+) D1
+-- order by "Order Number_ori" asc
+GO
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 31 - 0
System/LOCOSOFT/SQL/schema/LOCOSOFT/views/staging.offene_Auftraege_Ums_ben_AW_fuer_Monteure.sql

@@ -0,0 +1,31 @@
+SET QUOTED_IDENTIFIER ON 
+GO
+SET ANSI_NULLS ON 
+GO
+CREATE VIEW staging.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" >= TIMESTAMP '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" + ' - ' + (asciiz(extract(YEAR FROM T1."order_date"),4) + '-' + asciiz(extract(MONTH FROM T1."order_date"),2) + '-' + asciiz(extract(DAY FROM T1."order_date"),2)) + ' - ' + 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" + ' - ' + (asciiz(extract(YEAR FROM T1."order_date"),4) + '-' + asciiz(extract(MONTH FROM T1."order_date"),2) + '-' + asciiz(extract(DAY FROM T1."order_date"),2))) 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" >= TIMESTAMP '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
+SET QUOTED_IDENTIFIER OFF 
+GO
+SET ANSI_NULLS OFF 
+GO
+
+GO

+ 1 - 2
Tasks/LOCOSOFT_Cubes.bat

@@ -1,8 +1,7 @@
 @call "%~dp0"scripts\config.bat 0 > nul
 
 
-  call transformer11.bat F_Belege_SKR_Moll_Automobile.pyj
-  call transformer11.bat F_Belege_SKR_Moll_Motors.pyj
+  call transformer11.bat F_Belege_SKR.pyj
   call transformer11.bat F_Forderungen.pyj
   call transformer11.bat S_Aftersales.pyj
   rem call transformer11.bat S_Dashboard.pyj

+ 9 - 5
Tasks/scripts/Tools/controllers/ImpromptuController.php

@@ -26,27 +26,31 @@ class ImpromptuController
 			$impCtrl->OpenCatalog($newCat, str_rot13($user), str_rot13($pw));
 			$impCtrl->RenameCatalog($imrPath, strtolower($cat));
 			$impCtrl->Quit();
-		} else {
+			return;
+		}
+		try {
 			$impCtrl->OpenReport($imr, str_rot13($user), str_rot13($pw), $cat);
-
+			$impCtrl->SaveAsIqd($imr);
+			
 			switch ($export) {
 				case "csv":
 					$impCtrl->SaveAsCsv($imr);
-					$impCtrl->SaveAsIqd($imr);
 					break;
 				case "iqd":
-					$impCtrl->SaveAsIqd($imr);
 					break;
 				case "ims":
 				default:
 					$impCtrl->SaveAsIms($imr);
-					$impCtrl->SaveAsIqd($imr);
 					break;
 			}
 			$impCtrl->Quit();
 			$imr = basename($imr);
 			echo "  {$imr} als {$export} exportiert\r\n";
+		} catch (Exception $e) {
+			echo "Fehler in {$imr}:\r\n";
+			echo $e->getMessage() . "\r\n";
 		}
+		
 	}
 
 	public function __construct () 

+ 2 - 1
Tasks/scripts/impromptu.bat

@@ -3,4 +3,5 @@ if [%1]==[] (
   echo Aufruf: call impromptu.bat <Abfrage.imr> [csv|ims] [Catalog.cat]
   goto :eof
 )
-%PHP%\php Tools\run.php impromptu %PORTAL%\System\LOCOSOFT\IQD\%1 %2 %CAT_U% %CAT_P% %3
+%PHP%\php Tools\run.php impromptu %PORTAL%\System\LOCOSOFT\IQD\%1 %2 %CAT_U% %CAT_P% %3
+..\python\python iqd_convert.py convert %PORTAL%\System\LOCOSOFT\IQD\%1 %2

+ 88 - 0
Tasks/scripts/iqd_convert.py

@@ -0,0 +1,88 @@
+from pathlib import Path
+import re
+import plac
+
+
+class IqdConverter:
+    commands = ['convert']
+    target_schema_by_type = {
+        'csv': 'staging',
+        'ims': 'ims'
+    }
+    output_dir = 'C:\\GlobalCube_LOCOSOFT\\System\\LOCOSOFT\\SQL\\schema\\LOCOSOFT\\views'
+
+    def convert(self, iqd_file, target_type='csv'):
+        query = self.get_query_from_iqdfile(iqd_file)
+        query = self.cleanup_query(query)
+
+        output_file = iqd_file[:-4] + '.sql'
+        with open(output_file, 'w') as fwh:
+            fwh.write(query)
+
+        table = Path(iqd_file).stem
+        schema = self.target_schema_by_type[target_type]
+
+        create_view = "SET QUOTED_IDENTIFIER ON \nGO\nSET ANSI_NULLS ON \nGO\n" + \
+            f"CREATE VIEW {schema}.{table} AS\n\n{query}\n" + \
+            "GO\nSET QUOTED_IDENTIFIER OFF \nGO\nSET ANSI_NULLS OFF \nGO\n\nGO"
+
+        view_file = f"{self.output_dir}\\{schema}.{table}.sql"
+        with open(view_file, 'w') as fwh:
+            fwh.write(create_view)
+
+    def get_query_from_iqdfile(self, iqd_file):
+        if iqd_file[-4:].lower() == '.imr':
+            iqd_file = iqd_file[:-4] + '.iqd'
+        iqd = open(iqd_file, 'r', encoding='latin-1').read()
+        res = re.findall(r'BEGIN SQL\n(.*)\n\nEND SQL', iqd, re.MULTILINE | re.DOTALL)
+        query = ''
+        if len(res) > 0:
+            query = res[0]
+
+        columns = re.findall(r'COLUMN,\d+,(.*)', iqd)
+        col_keys = [f'c{i}' for i in range(len(columns), 0, -1)]
+        col_names = [f'"{c}"' for c in reversed(columns)]
+
+        for col_key, col_name in zip(col_keys, col_names):
+            query = re.sub(col_key + r'([^\d])', col_name + r'\1', query)
+        return query
+
+    def cleanup_query(self, query):
+        query = re.sub(r' from (\d+) for (\d+)\)', r', \1, \2)', query)
+        query = query.replace(' || ', ' + ')
+        query = query.replace('truncate(', 'rtrim(')
+        query = query.replace('char_length(', 'len(')
+        query = query.replace('ascii(', 'convert(varchar(50), ')
+        query = query.replace('extract(DAY FROM ', 'day(')
+        query = query.replace('extract(MONTH FROM ', 'month(')
+        query = query.replace('extract(YEAR FROM ', 'year(')
+        query = query.replace('cdatetime(', 'convert(datetime, ')
+        query = query.replace('cast_float(', 'convert(float, ')
+        query = query.replace('sy_right(', 'right(')
+
+        query = re.sub(r'intdiv\(([^\)]+)\,1\)', r'\1', query)
+        query = re.sub(r'XCOUNT\(([^\)]+) for ', r'COUNT(\1) OVER (partition by ', query)
+        query = re.sub(r'XSUM\(([^\)]+) for ', r'SUM(\1) OVER (partition by ', query)
+        query = re.sub(r'XMIN\(([^\)]+) for ', r'MIN(\1) OVER (partition by ', query)
+        query = re.sub(r'XMAX\(([^\)]+) for ', r'MAX(\1) OVER (partition by ', query)
+
+        query = re.sub(r'QSS\.\"[^\"]+\\([^\\]+)\.ims\"', r'"ims"."\1"', query)
+        query = re.sub(r"DATE '([\d-]+)'", r"convert(date, '\1')", query)
+        query = re.sub(r"TIMESTAMP '([\d\s\-\:\.]+)'", r"convert(datetime, '\1')", query)
+
+        query = re.sub(r'asciiz\(([^\,]*)\,\d+\)', r'convert(varchar(50), \1)', query)
+        query = re.sub(r'asciiz\(([^\+]*)\)', r'convert(varchar(50), \1)', query)
+        query = re.sub(r'convert\(varchar\(50\)\, ([^,]+)\,\d+\)', r'convert(varchar(50), \1)', query)
+        query = query.replace('cdate((convert(float, ', 'convert(datetime, ((')
+
+        query = re.sub(r'(order by .*)', r'-- \1', query)
+        return query
+
+    def run_folder(base_dir: str):
+        files = sorted([(f.stat().st_mtime, f) for f in Path(base_dir).rglob('*.iqd')])
+        print(files)
+
+
+if __name__ == '__main__':
+    # IqdConverter().convert('C:\\GlobalCube_LOCOSOFT\\System\\LOCOSOFT\\IQD\\NW\\LOC_Belege_NW_GW_VK_Stk_FIBU.iqd')
+    plac.Interpreter.call(IqdConverter)

部分文件因文件數量過多而無法顯示