locosoft.LOC_Belege.sql 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. SET QUOTED_IDENTIFIER ON
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. CREATE VIEW locosoft.LOC_Belege AS
  6. select
  7. T1."accounting_date" as "Accounting Date",
  8. T1."document_type" as "Document Type",
  9. T1."document_number" as "Document Number",
  10. T1."position_in_document" as "Position In Document",
  11. T1."customer_number" as "Customer Number",
  12. T1."nominal_account_number" as "Nominal Account Number",
  13. T1."is_balanced" as "Is Balanced",
  14. T1."clearing_number" as "Clearing Number",
  15. T1."document_date" as "Document Date",
  16. T1."posted_value" as "Posted Value",
  17. T1."debit_or_credit" as "Debit Or Credit",
  18. T1."posted_count" as "Posted Count",
  19. T1."branch_number" as "Branch Number",
  20. T1."customer_contra_account" as "Customer Contra Account",
  21. T1."nominal_contra_account" as "Nominal Contra Account",
  22. T1."contra_account_text" as "Contra Account Text",
  23. T1."account_form_page_number" as "Account Form Page Number",
  24. T1."account_form_page_line" as "Account Form Page Line",
  25. T1."serial_number_each_month" as "Serial Number Each Month",
  26. T1."employee_number" as "Employee Number",
  27. T1."invoice_date" as "Invoice Date",
  28. T1."invoice_number" as "Invoice Number",
  29. T1."dunning_level" as "Dunning Level",
  30. T1."last_dunning_date" as "Last Dunning Date",
  31. T1."journal_page" as "Journal Page",
  32. T1."journal_line" as "Journal Line",
  33. T1."cash_discount" as "Cash Discount",
  34. T1."term_of_payment" as "Term Of Payment",
  35. T1."posting_text" as "Posting Text",
  36. T1."vehicle_reference" as "Vehicle Reference",
  37. T1."vat_id_number" as "Vat Id Number",
  38. T1."account_statement_number" as "Account Statement Number",
  39. T1."account_statement_page" as "Account Statement Page",
  40. T1."vat_key" as "Vat Key",
  41. T1."days_for_cash_discount" as "Days For Cash Discount",
  42. T1."day_of_actual_accounting" as "Day Of Actual Accounting",
  43. T1."skr51_branch" as "Skr51 Branch",
  44. T1."skr51_make" as "Skr51 Make",
  45. T1."skr51_cost_center" as "Skr51 Cost Center",
  46. T1."skr51_sales_channel" as "Skr51 Sales Channel",
  47. T1."skr51_cost_unit" as "Skr51 Cost Unit",
  48. T1."previously_used_account_no" as "Previously Used Account No",
  49. T1."free_form_accounting_text" as "Free Form Accounting Text",
  50. case
  51. when T1."skr51_cost_unit" between 1 and 49 then 'Neuwagen'
  52. when T1."skr51_cost_unit" between 50 and 59 then 'Gebrauchtwagen'
  53. when T1."skr51_cost_unit" between 60 and 69 then 'Teile & Zubehör'
  54. when T1."skr51_cost_unit" between 70 and 79 then 'Service'
  55. when T1."skr51_cost_unit" = 0 then 'Ohne Kostenträger'
  56. else NULL
  57. end as "Free Form Document Text",
  58. T2."is_profit_loss_account" as "Nom_Account_Is Profit Loss Account",
  59. '1' as "Rechtseinheit",
  60. { fn CONCAT(
  61. '0',
  62. CAST(
  63. CAST(T1."subsidiary_to_company_ref" AS INTEGER) AS CHAR(254)
  64. )
  65. ) } as "Betrieb",
  66. case
  67. when T1."posting_text" = 'Saldenübernahme CDK'
  68. or T1."accounting_date" = '2019-01-01' then convert(datetime, '2019-12-01')
  69. else T1."accounting_date"
  70. end as "Bookkeep Date",
  71. { fn CONCAT(
  72. { fn CONCAT(
  73. { fn RTRIM(
  74. CAST(CAST(T1."skr51_make" AS INTEGER) AS CHAR(254))
  75. ) },
  76. ' - '
  77. ) },
  78. T3."skr51_make_description"
  79. ) } as "Marke",
  80. isnull(CAST(T1."invoice_number" as VARCHAR(100)), '') + ' - ' + T1."posting_text" + '/' + isnull(T1."vehicle_reference",'') + ' - ' + isnull(CAST(T1."employee_number" as VARCHAR(50)), '') as "Text",
  81. '1' as "Mandant",
  82. case
  83. when T1."debit_or_credit" = 'H' then (CAST(T1."posted_value" AS FLOAT) / 100) * -1
  84. else CAST(T1."posted_value" AS FLOAT) / 100
  85. end as "Betrag",
  86. { fn CONCAT(
  87. { fn CONCAT(
  88. { fn LEFT(
  89. CAST(
  90. CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
  91. ),
  92. 4
  93. ) },
  94. ' - '
  95. ) },
  96. T2."account_description"
  97. ) } as "Konto_mit_Bezeichnung",
  98. case
  99. when T1."debit_or_credit" = 'H' then (CAST(T1."posted_count" AS FLOAT) / 100) * -1
  100. else CAST(T1."posted_count" AS FLOAT) / 100
  101. end as "Menge",
  102. { fn LENGTH(
  103. { fn CONCAT(
  104. CAST(
  105. CAST(T1."skr51_cost_center" AS INTEGER) AS CHAR(254)
  106. ),
  107. 'Z'
  108. ) }
  109. ) } - 1 as "Stellen Cost Center",
  110. { fn CONCAT(
  111. { fn CONCAT(
  112. { fn RTRIM(
  113. CAST(
  114. CAST(T1."skr51_cost_center" AS INTEGER) AS CHAR(254)
  115. )
  116. ) },
  117. ' - '
  118. ) },
  119. T3."skr51_cost_center_name"
  120. ) } as "KST",
  121. { fn LENGTH(
  122. { fn CONCAT(
  123. CAST(
  124. CAST(T1."skr51_sales_channel" AS INTEGER) AS CHAR(254)
  125. ),
  126. 'Z'
  127. ) }
  128. ) } - 1 as "Stellen Sales Channel",
  129. { fn CONCAT(
  130. { fn CONCAT(
  131. { fn RTRIM(
  132. CAST(
  133. CAST(T1."skr51_sales_channel" AS INTEGER) AS CHAR(254)
  134. )
  135. ) },
  136. ' - '
  137. ) },
  138. T3."skr51_sales_channel_name"
  139. ) } as "Absatzkanal",
  140. { fn LENGTH(
  141. { fn CONCAT(
  142. CAST(
  143. CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
  144. ),
  145. 'Z'
  146. ) }
  147. ) } - 1 as "Stellen Cost Unit",
  148. { fn CONCAT(
  149. { fn CONCAT(
  150. { fn CONCAT(
  151. { fn CONCAT(
  152. { fn RTRIM(
  153. CAST(CAST(T1."skr51_make" AS INTEGER) AS CHAR(254))
  154. ) },
  155. ' - '
  156. ) },
  157. { fn RTRIM(
  158. CAST(
  159. CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
  160. )
  161. ) }
  162. ) },
  163. ' - '
  164. ) },
  165. T3."skr51_cost_unit_name"
  166. ) } as "Kostenträger_mit_Null",
  167. case
  168. when T1."skr51_cost_unit" between 1 and 49 then { fn CONCAT(
  169. { fn CONCAT(
  170. { fn CONCAT(
  171. { fn CONCAT(
  172. { fn RTRIM(
  173. CAST(CAST(T1."skr51_make" AS INTEGER) AS CHAR(254))
  174. ) },
  175. ' - '
  176. ) },
  177. { fn RTRIM(
  178. CAST(
  179. CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
  180. )
  181. ) }
  182. ) },
  183. ' - '
  184. ) },
  185. T3."skr51_cost_unit_name"
  186. ) }
  187. else { fn CONCAT(
  188. { fn CONCAT(
  189. { fn RTRIM(
  190. CAST(
  191. CAST(T1."skr51_cost_unit" AS INTEGER) AS CHAR(254)
  192. )
  193. ) },
  194. ' - '
  195. ) },
  196. T3."skr51_cost_unit_name"
  197. ) }
  198. end as "Kostenträger",
  199. case
  200. when T2."is_profit_loss_account" = 'J' then '2'
  201. else '1'
  202. end as "GuV_Bilanz",
  203. { fn LEFT(
  204. CAST(
  205. CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
  206. ),
  207. 1
  208. ) } as "Susa",
  209. case
  210. when T1."skr51_cost_center" <> 0 then { fn CONCAT(
  211. { fn CONCAT(
  212. { fn RTRIM(
  213. CAST(
  214. CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
  215. )
  216. ) },
  217. '_'
  218. ) },
  219. { fn RTRIM(
  220. CAST(
  221. CAST(T1."skr51_cost_center" AS INTEGER) AS CHAR(254)
  222. )
  223. ) }
  224. ) }
  225. else CAST(
  226. CAST(T1."nominal_account_number" AS INTEGER) AS CHAR(254)
  227. )
  228. end as "Acct Nr"
  229. from "dbo"."journal_accountings" T1
  230. INNER JOIN "dbo"."nominal_accounts" T2 ON T2."nominal_account_number" = T1."nominal_account_number"
  231. and T2."subsidiary_to_company_ref" = T1."subsidiary_to_company_ref"
  232. LEFT OUTER JOIN "dbo"."accounts_characteristics" T3 on T1."subsidiary_to_company_ref" = T3."subsidiary_to_company_ref"
  233. and T1."skr51_branch" = T3."skr51_branch"
  234. and T1."skr51_make" = T3."skr51_make"
  235. and T1."skr51_cost_center" = T3."skr51_cost_center"
  236. and T1."skr51_sales_channel" = T3."skr51_sales_channel"
  237. and T1."skr51_cost_unit" = T3."skr51_cost_unit"
  238. where
  239. T2."is_profit_loss_account" = 'J'
  240. GO
  241. SET QUOTED_IDENTIFIER OFF
  242. GO
  243. SET ANSI_NULLS OFF
  244. GO
  245. GO