OP_aus_LOC_Belege_Deb_Saldo.sql 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. SELECT "Accounting Date" AS "Accounting Date",
  2. "Document Type" AS "Document Type",
  3. "Document Number" AS "Document Number",
  4. "Position In Document" AS "Position In Document",
  5. "Nominal Account Number" AS "Nominal Account Number",
  6. "Customer Number" AS "Customer Number",
  7. "Is Balanced" AS "Is Balanced",
  8. "Clearing Number" AS "Clearing Number",
  9. "Document Date" AS "Document Date",
  10. "Posted Value" AS "Posted Value",
  11. "Debit Or Credit" AS "Debit Or Credit",
  12. "Posted Count" AS "Posted Count",
  13. "Branch Number" AS "Branch Number",
  14. "Customer Contra Account" AS "Customer Contra Account",
  15. "Nominal Contra Account" AS "Nominal Contra Account",
  16. "Contra Account Text" AS "Contra Account Text",
  17. "Account Form Page Number" AS "Account Form Page Number",
  18. "Account Form Page Line" AS "Account Form Page Line",
  19. "Serial Number Each Month" AS "Serial Number Each Month",
  20. "Employee Number" AS "Employee Number",
  21. "Invoice Date" AS "Invoice Date",
  22. "Invoice Number" AS "Invoice Number",
  23. "Dunning Level" AS "Dunning Level",
  24. "Last Dunning Date" AS "Last Dunning Date",
  25. "Journal Page" AS "Journal Page",
  26. "Journal Line" AS "Journal Line",
  27. "Cash Discount" AS "Cash Discount",
  28. "Term Of Payment" AS "Term Of Payment",
  29. "Posting Text" AS "Posting Text",
  30. "Vehicle Reference" AS "Vehicle Reference",
  31. "Vat Id Number" AS "Vat Id Number",
  32. "Account Statement Number" AS "Account Statement Number",
  33. "Account Statement Page" AS "Account Statement Page",
  34. "Vat Key" AS "Vat Key",
  35. "Days For Cash Discount" AS "Days For Cash Discount",
  36. "Day Of Actual Accounting" AS "Day Of Actual Accounting",
  37. "Skr51 Branch" AS "Skr51 Branch",
  38. "Skr51 Make" AS "Skr51 Make",
  39. "Skr51 Cost Center" AS "Skr51 Cost Center",
  40. "Skr51 Sales Channel" AS "Skr51 Sales Channel",
  41. "Skr51 Cost Unit" AS "Skr51 Cost Unit",
  42. "Previously Used Account No" AS "Previously Used Account No",
  43. "Free Form Accounting Text" AS "Free Form Accounting Text",
  44. "Free Form Document Text" AS "Free Form Document Text",
  45. "Rechtseinheit" AS "Rechtseinheit",
  46. "Betrieb" AS "Betrieb",
  47. "Bookkeep Date" AS "Bookkeep Date",
  48. "Text" AS "Text",
  49. "Mandant" AS "Mandant",
  50. "Betrag" AS "Betrag",
  51. "Menge" AS "Menge",
  52. "Acct Nr" AS "Acct Nr",
  53. "Customer Number_suctomer_supplier" AS "Customer Number_suctomer_supplier",
  54. "Is Supplier" AS "Is Supplier",
  55. "First Name" AS "First Name",
  56. "Family Name" AS "Family Name",
  57. "Document Type In Journal" AS "Document Type In Journal",
  58. "Document Type Description" AS "Document Type Description",
  59. SUM("Betrag") OVER (PARTITION BY "Customer Number_suctomer_supplier") AS "Debitorsaldo",
  60. "Invoice Type_Invoices" AS "Invoice Type_Invoices",
  61. "Invoice Number_Invoices" AS "Invoice Number_Invoices",
  62. "Subsidiary_Invoices" AS "Subsidiary_Invoices",
  63. "Invoice Date_Invoices" AS "Invoice Date_Invoices",
  64. "Hauptbetrieb" AS "Hauptbetrieb",
  65. "Standort_ori" AS "Standort_ori",
  66. "Sel Name" AS "Sel Name",
  67. "OP-Saldo_" AS "OP-Saldo_",
  68. "Kostenstelle" AS "Kostenstelle",
  69. "Tage" AS "Tage",
  70. "Staffel" AS "Staffel",
  71. "Kunde" AS "Kunde",
  72. "Beleg" AS "Beleg",
  73. "Employee Number_Employees_journal_accountings" AS "Employee Number_Employees_journal_accountings",
  74. "Name_Employees_journal_accountings" AS "Name_Employees_journal_accountings",
  75. "Anzahl_Stellen_Invoice_Number" AS "Anzahl_Stellen_Invoice_Number",
  76. "Forderungsart_aus_erste_Stelle_Inv_Number" AS "Forderungsart_aus_erste_Stelle_Inv_Number",
  77. "Forderungsart" AS "Forderungsart",
  78. "Standort_aus_2_Stelle_Invoice_Number" AS "Standort_aus_2_Stelle_Invoice_Number",
  79. "Standort" AS "Standort"
  80. FROM (
  81. SELECT "Accounting Date",
  82. "Document Type",
  83. "Document Number",
  84. "Position In Document",
  85. "Nominal Account Number",
  86. "Customer Number",
  87. "Is Balanced",
  88. "Clearing Number",
  89. "Document Date",
  90. "Posted Value",
  91. "Debit Or Credit",
  92. "Posted Count",
  93. "Branch Number",
  94. "Customer Contra Account",
  95. "Nominal Contra Account",
  96. "Contra Account Text",
  97. "Account Form Page Number",
  98. "Account Form Page Line",
  99. "Serial Number Each Month",
  100. "Employee Number",
  101. "Invoice Date",
  102. "Invoice Number",
  103. "Dunning Level",
  104. "Last Dunning Date",
  105. "Journal Page",
  106. "Journal Line",
  107. "Cash Discount",
  108. "Term Of Payment",
  109. "Posting Text",
  110. "Vehicle Reference",
  111. "Vat Id Number",
  112. "Account Statement Number",
  113. "Account Statement Page",
  114. "Vat Key",
  115. "Days For Cash Discount",
  116. "Day Of Actual Accounting",
  117. "Skr51 Branch",
  118. "Skr51 Make",
  119. "Skr51 Cost Center",
  120. "Skr51 Sales Channel",
  121. "Skr51 Cost Unit",
  122. "Previously Used Account No",
  123. "Free Form Accounting Text",
  124. "Free Form Document Text",
  125. '1' AS "Rechtseinheit",
  126. "Betrieb",
  127. "Accounting Date" AS "Bookkeep Date",
  128. "Text",
  129. '1' AS "Mandant",
  130. "Betrag",
  131. "Menge",
  132. "Nominal Account Number" AS "Acct Nr",
  133. "Customer Number_suctomer_supplier",
  134. "Is Supplier",
  135. "First Name",
  136. "Family Name",
  137. "Document Type In Journal",
  138. "Document Type Description",
  139. "Invoice Type_Invoices",
  140. "Invoice Number_Invoices",
  141. "Subsidiary_Invoices",
  142. "Invoice Date_Invoices",
  143. "Hauptbetrieb",
  144. "Standort_ori",
  145. "Sel Name",
  146. "Betrag" AS "OP-Saldo_",
  147. "Kostenstelle",
  148. "Tage",
  149. "Staffel",
  150. "Kunde",
  151. "Beleg",
  152. "Employee Number_Employees_journal_accountings",
  153. "Name_Employees_journal_accountings",
  154. "Anzahl_Stellen_Invoice_Number",
  155. "Forderungsart_aus_erste_Stelle_Inv_Number",
  156. "Forderungsart",
  157. "Standort_aus_2_Stelle_Invoice_Number",
  158. "Betrieb" AS "Standort",
  159. SUM("Betrag") OVER (PARTITION BY "Customer Number_suctomer_supplier") AS c80
  160. FROM (
  161. SELECT T3."customer_number" AS "Customer Number_suctomer_supplier",
  162. ('0' + (((T1."branch_number")))) AS "Betrieb",
  163. CASE
  164. WHEN (
  165. (
  166. (
  167. (
  168. len((
  169. CASE
  170. WHEN (
  171. (T1."invoice_number" IS NULL)
  172. OR (T1."invoice_number" = ' ')
  173. )
  174. THEN (' - ')
  175. ELSE (T1."invoice_number")
  176. END
  177. ))
  178. )
  179. ) = 7
  180. )
  181. AND (
  182. (
  183. substring((
  184. CASE
  185. WHEN (
  186. (T1."invoice_number" IS NULL)
  187. OR (T1."invoice_number" = ' ')
  188. )
  189. THEN (' - ')
  190. ELSE (T1."invoice_number")
  191. END
  192. ), 2, 1)
  193. ) BETWEEN '1' AND '4'
  194. )
  195. )
  196. THEN (
  197. '0' + (
  198. substring((
  199. CASE
  200. WHEN (
  201. (T1."invoice_number" IS NULL)
  202. OR (T1."invoice_number" = ' ')
  203. )
  204. THEN (' - ')
  205. ELSE (T1."invoice_number")
  206. END
  207. ), 2, 1)
  208. )
  209. )
  210. ELSE NULL
  211. END AS "Standort_aus_2_Stelle_Invoice_Number",
  212. CASE
  213. WHEN (
  214. (
  215. CASE
  216. WHEN (T5."invoice_type" IN (2, 4, 6, 3))
  217. THEN ('3')
  218. WHEN (T5."invoice_type" IN (5))
  219. THEN ('6')
  220. WHEN (T5."invoice_type" IN (7))
  221. THEN ('1')
  222. WHEN (T5."invoice_type" IN (8))
  223. THEN ('2')
  224. WHEN (T4."document_type_in_journal" = 'R')
  225. THEN ('7')
  226. ELSE NULL
  227. END
  228. ) = '1'
  229. )
  230. THEN ('Neuwagen')
  231. WHEN (
  232. (
  233. CASE
  234. WHEN (T5."invoice_type" IN (2, 4, 6, 3))
  235. THEN ('3')
  236. WHEN (T5."invoice_type" IN (5))
  237. THEN ('6')
  238. WHEN (T5."invoice_type" IN (7))
  239. THEN ('1')
  240. WHEN (T5."invoice_type" IN (8))
  241. THEN ('2')
  242. WHEN (T4."document_type_in_journal" = 'R')
  243. THEN ('7')
  244. ELSE NULL
  245. END
  246. ) = '2'
  247. )
  248. THEN ('Gebrauchtwagen')
  249. WHEN (
  250. (
  251. CASE
  252. WHEN (T5."invoice_type" IN (2, 4, 6, 3))
  253. THEN ('3')
  254. WHEN (T5."invoice_type" IN (5))
  255. THEN ('6')
  256. WHEN (T5."invoice_type" IN (7))
  257. THEN ('1')
  258. WHEN (T5."invoice_type" IN (8))
  259. THEN ('2')
  260. WHEN (T4."document_type_in_journal" = 'R')
  261. THEN ('7')
  262. ELSE NULL
  263. END
  264. ) = '3'
  265. )
  266. THEN ('Service')
  267. WHEN (
  268. (
  269. CASE
  270. WHEN (T5."invoice_type" IN (2, 4, 6, 3))
  271. THEN ('3')
  272. WHEN (T5."invoice_type" IN (5))
  273. THEN ('6')
  274. WHEN (T5."invoice_type" IN (7))
  275. THEN ('1')
  276. WHEN (T5."invoice_type" IN (8))
  277. THEN ('2')
  278. WHEN (T4."document_type_in_journal" = 'R')
  279. THEN ('7')
  280. ELSE NULL
  281. END
  282. ) = '6'
  283. )
  284. THEN ('Teile')
  285. ELSE ('nicht zuzuordnen')
  286. END AS "Forderungsart",
  287. CASE
  288. WHEN (
  289. (
  290. (
  291. (
  292. len((
  293. CASE
  294. WHEN (
  295. (T1."invoice_number" IS NULL)
  296. OR (T1."invoice_number" = ' ')
  297. )
  298. THEN (' - ')
  299. ELSE (T1."invoice_number")
  300. END
  301. ))
  302. )
  303. ) = 7
  304. )
  305. AND (
  306. (
  307. substring((
  308. CASE
  309. WHEN (
  310. (T1."invoice_number" IS NULL)
  311. OR (T1."invoice_number" = ' ')
  312. )
  313. THEN (' - ')
  314. ELSE (T1."invoice_number")
  315. END
  316. ), 1, 1)
  317. ) IN ('2', '3', '4')
  318. )
  319. )
  320. THEN ('Service')
  321. WHEN (
  322. (
  323. (
  324. (
  325. len((
  326. CASE
  327. WHEN (
  328. (T1."invoice_number" IS NULL)
  329. OR (T1."invoice_number" = ' ')
  330. )
  331. THEN (' - ')
  332. ELSE (T1."invoice_number")
  333. END
  334. ))
  335. )
  336. ) = 7
  337. )
  338. AND (
  339. (
  340. substring((
  341. CASE
  342. WHEN (
  343. (T1."invoice_number" IS NULL)
  344. OR (T1."invoice_number" = ' ')
  345. )
  346. THEN (' - ')
  347. ELSE (T1."invoice_number")
  348. END
  349. ), 1, 1)
  350. ) IN ('5')
  351. )
  352. )
  353. THEN ('Teile')
  354. WHEN (
  355. (
  356. (
  357. (
  358. len((
  359. CASE
  360. WHEN (
  361. (T1."invoice_number" IS NULL)
  362. OR (T1."invoice_number" = ' ')
  363. )
  364. THEN (' - ')
  365. ELSE (T1."invoice_number")
  366. END
  367. ))
  368. )
  369. ) = 7
  370. )
  371. AND (
  372. (
  373. substring((
  374. CASE
  375. WHEN (
  376. (T1."invoice_number" IS NULL)
  377. OR (T1."invoice_number" = ' ')
  378. )
  379. THEN (' - ')
  380. ELSE (T1."invoice_number")
  381. END
  382. ), 1, 1)
  383. ) IN ('6')
  384. )
  385. )
  386. THEN ('Garantie')
  387. WHEN (
  388. (
  389. (
  390. (
  391. len((
  392. CASE
  393. WHEN (
  394. (T1."invoice_number" IS NULL)
  395. OR (T1."invoice_number" = ' ')
  396. )
  397. THEN (' - ')
  398. ELSE (T1."invoice_number")
  399. END
  400. ))
  401. )
  402. ) = 7
  403. )
  404. AND (
  405. (
  406. substring((
  407. CASE
  408. WHEN (
  409. (T1."invoice_number" IS NULL)
  410. OR (T1."invoice_number" = ' ')
  411. )
  412. THEN (' - ')
  413. ELSE (T1."invoice_number")
  414. END
  415. ), 1, 1)
  416. ) IN ('7')
  417. )
  418. )
  419. THEN ('Neuwagen')
  420. WHEN (
  421. (
  422. (
  423. (
  424. len((
  425. CASE
  426. WHEN (
  427. (T1."invoice_number" IS NULL)
  428. OR (T1."invoice_number" = ' ')
  429. )
  430. THEN (' - ')
  431. ELSE (T1."invoice_number")
  432. END
  433. ))
  434. )
  435. ) = 7
  436. )
  437. AND (
  438. (
  439. substring((
  440. CASE
  441. WHEN (
  442. (T1."invoice_number" IS NULL)
  443. OR (T1."invoice_number" = ' ')
  444. )
  445. THEN (' - ')
  446. ELSE (T1."invoice_number")
  447. END
  448. ), 1, 1)
  449. ) IN ('8')
  450. )
  451. )
  452. THEN ('Gebrauchtwagen')
  453. WHEN (T1."document_type" = 'R')
  454. THEN ('Rent')
  455. ELSE ('nicht zuzuordnen')
  456. END AS "Forderungsart_aus_erste_Stelle_Inv_Number",
  457. (
  458. len((
  459. CASE
  460. WHEN (
  461. (T1."invoice_number" IS NULL)
  462. OR (T1."invoice_number" = ' ')
  463. )
  464. THEN (' - ')
  465. ELSE (T1."invoice_number")
  466. END
  467. ))
  468. ) AS "Anzahl_Stellen_Invoice_Number",
  469. T2."name" AS "Name_Employees_journal_accountings",
  470. T2."employee_number" AS "Employee Number_Employees_journal_accountings",
  471. (
  472. (
  473. CASE
  474. WHEN (
  475. (T1."posting_text" IS NULL)
  476. OR (T1."posting_text" = ' ')
  477. )
  478. THEN (' - ')
  479. ELSE (T1."posting_text")
  480. END
  481. ) + '/' + (
  482. CASE
  483. WHEN (
  484. (T1."vehicle_reference" IS NULL)
  485. OR (T1."vehicle_reference" = ' ')
  486. )
  487. THEN (' - ')
  488. ELSE (T1."vehicle_reference")
  489. END
  490. )
  491. ) AS "Beleg",
  492. CASE
  493. WHEN (T3."first_name" IS NOT NULL)
  494. THEN ((left((((T3."customer_number"))), 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
  495. ELSE ((left((((T3."customer_number"))), 7)) + ' ' + T3."family_name")
  496. END AS "Kunde",
  497. CASE
  498. WHEN (((- 1 * datediff(day, (getdate()), (convert(DATETIME, T1."accounting_date"))))) BETWEEN 0 AND 14)
  499. THEN ('< 2 Wochen')
  500. WHEN (((- 1 * datediff(day, (getdate()), (convert(DATETIME, T1."accounting_date"))))) BETWEEN 15 AND 28)
  501. THEN ('2 - 4 Wochen')
  502. WHEN (((- 1 * datediff(day, (getdate()), (convert(DATETIME, T1."accounting_date"))))) BETWEEN 29 AND 42)
  503. THEN ('4 - 6 Wochen')
  504. WHEN (((- 1 * datediff(day, (getdate()), (convert(DATETIME, T1."accounting_date"))))) BETWEEN 43 AND 84)
  505. THEN ('6 - 12 Wochen')
  506. WHEN (((- 1 * datediff(day, (getdate()), (convert(DATETIME, T1."accounting_date"))))) > 84)
  507. THEN ('> 12 Wochen')
  508. ELSE NULL
  509. END AS "Staffel",
  510. (- 1 * datediff(day, (getdate()), (convert(DATETIME, T1."accounting_date")))) AS "Tage",
  511. CASE
  512. WHEN (T5."invoice_type" IN (2, 4, 6, 3))
  513. THEN ('3')
  514. WHEN (T5."invoice_type" IN (5))
  515. THEN ('6')
  516. WHEN (T5."invoice_type" IN (7))
  517. THEN ('1')
  518. WHEN (T5."invoice_type" IN (8))
  519. THEN ('2')
  520. WHEN (T4."document_type_in_journal" = 'R')
  521. THEN ('7')
  522. ELSE NULL
  523. END AS "Kostenstelle",
  524. (
  525. CASE
  526. WHEN (T1."debit_or_credit" = 'H')
  527. THEN (T1."posted_value" / 100 * - 1)
  528. ELSE (T1."posted_value" / 100)
  529. END
  530. ) AS "Betrag",
  531. (left((((T2."employee_number"))), 4)) + ' - ' + T2."name" AS "Sel Name",
  532. CASE
  533. WHEN (T5."subsidiary" IS NOT NULL)
  534. THEN ('0' + (left((((T5."subsidiary"))), 1)))
  535. ELSE ('nicht zuzuordnen')
  536. END AS "Standort_ori",
  537. CASE
  538. WHEN ((('0' + (((T1."branch_number"))))) IN ('015 '))
  539. THEN ('15')
  540. ELSE ('1')
  541. END AS "Hauptbetrieb",
  542. T5."invoice_date" AS "Invoice Date_Invoices",
  543. T5."subsidiary" AS "Subsidiary_Invoices",
  544. T5."invoice_number" AS "Invoice Number_Invoices",
  545. T5."invoice_type" AS "Invoice Type_Invoices",
  546. T4."document_type_description" AS "Document Type Description",
  547. T4."document_type_in_journal" AS "Document Type In Journal",
  548. T3."family_name" AS "Family Name",
  549. T3."first_name" AS "First Name",
  550. T3."is_supplier" AS "Is Supplier",
  551. T1."nominal_account_number" AS "Nominal Account Number",
  552. CASE
  553. WHEN (T1."debit_or_credit" = 'H')
  554. THEN (T1."posted_count" / 100 * - 1)
  555. ELSE (T1."posted_count" / 100)
  556. END AS "Menge",
  557. CASE
  558. WHEN (
  559. (
  560. CASE
  561. WHEN (
  562. (T1."posting_text" IS NULL)
  563. OR (T1."posting_text" = ' ')
  564. )
  565. THEN (' - ')
  566. ELSE (T1."posting_text")
  567. END
  568. ) IS NOT NULL
  569. )
  570. THEN (
  571. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  572. CASE
  573. WHEN (
  574. (T1."posting_text" IS NULL)
  575. OR (T1."posting_text" = ' ')
  576. )
  577. THEN (' - ')
  578. ELSE (T1."posting_text")
  579. END
  580. ) + '/' + (
  581. CASE
  582. WHEN (
  583. (T1."vehicle_reference" IS NULL)
  584. OR (T1."vehicle_reference" = ' ')
  585. )
  586. THEN (' - ')
  587. ELSE (T1."vehicle_reference")
  588. END
  589. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  590. )
  591. ELSE (
  592. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  593. CASE
  594. WHEN (
  595. (T1."vehicle_reference" IS NULL)
  596. OR (T1."vehicle_reference" = ' ')
  597. )
  598. THEN (' - ')
  599. ELSE (T1."vehicle_reference")
  600. END
  601. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  602. )
  603. END AS "Text",
  604. T1."accounting_date" AS "Accounting Date",
  605. CASE
  606. WHEN (
  607. (
  608. (
  609. (
  610. (
  611. (
  612. CASE
  613. WHEN (
  614. (
  615. CASE
  616. WHEN (
  617. (T1."posting_text" IS NULL)
  618. OR (T1."posting_text" = ' ')
  619. )
  620. THEN (' - ')
  621. ELSE (T1."posting_text")
  622. END
  623. ) IS NOT NULL
  624. )
  625. THEN (
  626. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  627. CASE
  628. WHEN (
  629. (T1."posting_text" IS NULL)
  630. OR (T1."posting_text" = ' ')
  631. )
  632. THEN (' - ')
  633. ELSE (T1."posting_text")
  634. END
  635. ) + '/' + (
  636. CASE
  637. WHEN (
  638. (T1."vehicle_reference" IS NULL)
  639. OR (T1."vehicle_reference" = ' ')
  640. )
  641. THEN (' - ')
  642. ELSE (T1."vehicle_reference")
  643. END
  644. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  645. )
  646. ELSE (
  647. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  648. CASE
  649. WHEN (
  650. (T1."vehicle_reference" IS NULL)
  651. OR (T1."vehicle_reference" = ' ')
  652. )
  653. THEN (' - ')
  654. ELSE (T1."vehicle_reference")
  655. END
  656. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  657. )
  658. END
  659. ) LIKE '%RG-BONUS%'
  660. )
  661. OR (
  662. (
  663. CASE
  664. WHEN (
  665. (
  666. CASE
  667. WHEN (
  668. (T1."posting_text" IS NULL)
  669. OR (T1."posting_text" = ' ')
  670. )
  671. THEN (' - ')
  672. ELSE (T1."posting_text")
  673. END
  674. ) IS NOT NULL
  675. )
  676. THEN (
  677. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  678. CASE
  679. WHEN (
  680. (T1."posting_text" IS NULL)
  681. OR (T1."posting_text" = ' ')
  682. )
  683. THEN (' - ')
  684. ELSE (T1."posting_text")
  685. END
  686. ) + '/' + (
  687. CASE
  688. WHEN (
  689. (T1."vehicle_reference" IS NULL)
  690. OR (T1."vehicle_reference" = ' ')
  691. )
  692. THEN (' - ')
  693. ELSE (T1."vehicle_reference")
  694. END
  695. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  696. )
  697. ELSE (
  698. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  699. CASE
  700. WHEN (
  701. (T1."vehicle_reference" IS NULL)
  702. OR (T1."vehicle_reference" = ' ')
  703. )
  704. THEN (' - ')
  705. ELSE (T1."vehicle_reference")
  706. END
  707. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  708. )
  709. END
  710. ) LIKE '%GEBURTSTAGS%'
  711. )
  712. )
  713. OR (
  714. (
  715. CASE
  716. WHEN (
  717. (
  718. CASE
  719. WHEN (
  720. (T1."posting_text" IS NULL)
  721. OR (T1."posting_text" = ' ')
  722. )
  723. THEN (' - ')
  724. ELSE (T1."posting_text")
  725. END
  726. ) IS NOT NULL
  727. )
  728. THEN (
  729. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  730. CASE
  731. WHEN (
  732. (T1."posting_text" IS NULL)
  733. OR (T1."posting_text" = ' ')
  734. )
  735. THEN (' - ')
  736. ELSE (T1."posting_text")
  737. END
  738. ) + '/' + (
  739. CASE
  740. WHEN (
  741. (T1."vehicle_reference" IS NULL)
  742. OR (T1."vehicle_reference" = ' ')
  743. )
  744. THEN (' - ')
  745. ELSE (T1."vehicle_reference")
  746. END
  747. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  748. )
  749. ELSE (
  750. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  751. CASE
  752. WHEN (
  753. (T1."vehicle_reference" IS NULL)
  754. OR (T1."vehicle_reference" = ' ')
  755. )
  756. THEN (' - ')
  757. ELSE (T1."vehicle_reference")
  758. END
  759. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  760. )
  761. END
  762. ) LIKE '%STARTGUTHABEN%'
  763. )
  764. )
  765. OR (
  766. (
  767. CASE
  768. WHEN (
  769. (
  770. CASE
  771. WHEN (
  772. (T1."posting_text" IS NULL)
  773. OR (T1."posting_text" = ' ')
  774. )
  775. THEN (' - ')
  776. ELSE (T1."posting_text")
  777. END
  778. ) IS NOT NULL
  779. )
  780. THEN (
  781. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  782. CASE
  783. WHEN (
  784. (T1."posting_text" IS NULL)
  785. OR (T1."posting_text" = ' ')
  786. )
  787. THEN (' - ')
  788. ELSE (T1."posting_text")
  789. END
  790. ) + '/' + (
  791. CASE
  792. WHEN (
  793. (T1."vehicle_reference" IS NULL)
  794. OR (T1."vehicle_reference" = ' ')
  795. )
  796. THEN (' - ')
  797. ELSE (T1."vehicle_reference")
  798. END
  799. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  800. )
  801. ELSE (
  802. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  803. CASE
  804. WHEN (
  805. (T1."vehicle_reference" IS NULL)
  806. OR (T1."vehicle_reference" = ' ')
  807. )
  808. THEN (' - ')
  809. ELSE (T1."vehicle_reference")
  810. END
  811. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  812. )
  813. END
  814. ) LIKE '%BONUS F%'
  815. )
  816. )
  817. OR (
  818. (
  819. CASE
  820. WHEN (
  821. (
  822. CASE
  823. WHEN (
  824. (T1."posting_text" IS NULL)
  825. OR (T1."posting_text" = ' ')
  826. )
  827. THEN (' - ')
  828. ELSE (T1."posting_text")
  829. END
  830. ) IS NOT NULL
  831. )
  832. THEN (
  833. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  834. CASE
  835. WHEN (
  836. (T1."posting_text" IS NULL)
  837. OR (T1."posting_text" = ' ')
  838. )
  839. THEN (' - ')
  840. ELSE (T1."posting_text")
  841. END
  842. ) + '/' + (
  843. CASE
  844. WHEN (
  845. (T1."vehicle_reference" IS NULL)
  846. OR (T1."vehicle_reference" = ' ')
  847. )
  848. THEN (' - ')
  849. ELSE (T1."vehicle_reference")
  850. END
  851. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  852. )
  853. ELSE (
  854. (rtrim((convert(VARCHAR(50), ((T1."document_number")))))) + ' - ' + (
  855. CASE
  856. WHEN (
  857. (T1."vehicle_reference" IS NULL)
  858. OR (T1."vehicle_reference" = ' ')
  859. )
  860. THEN (' - ')
  861. ELSE (T1."vehicle_reference")
  862. END
  863. ) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(VARCHAR(50), year(T1."document_date")) + '-' + convert(VARCHAR(50), month(T1."document_date")) + '-' + convert(VARCHAR(50), day(T1."document_date")))
  864. )
  865. END
  866. ) LIKE '%RG-ABZUG%'
  867. )
  868. )
  869. THEN ('Bonus/Startguthaben')
  870. ELSE ('ohne Bonus/Startguthaben')
  871. END AS "Free Form Document Text",
  872. T1."free_form_accounting_text" AS "Free Form Accounting Text",
  873. T1."previously_used_account_no" AS "Previously Used Account No",
  874. T1."skr51_cost_unit" AS "Skr51 Cost Unit",
  875. T1."skr51_sales_channel" AS "Skr51 Sales Channel",
  876. T1."skr51_cost_center" AS "Skr51 Cost Center",
  877. T1."skr51_make" AS "Skr51 Make",
  878. T1."skr51_branch" AS "Skr51 Branch",
  879. T1."day_of_actual_accounting" AS "Day Of Actual Accounting",
  880. (convert(VARCHAR(50), year(T1."accounting_date")) + '-' + convert(VARCHAR(50), month(T1."accounting_date")) + '-' + convert(VARCHAR(50), day(T1."accounting_date"))) AS "Days For Cash Discount",
  881. T1."vat_key" AS "Vat Key",
  882. T1."account_statement_page" AS "Account Statement Page",
  883. T1."account_statement_number" AS "Account Statement Number",
  884. T1."vat_id_number" AS "Vat Id Number",
  885. CASE
  886. WHEN (
  887. (T1."vehicle_reference" IS NULL)
  888. OR (T1."vehicle_reference" = ' ')
  889. )
  890. THEN (' - ')
  891. ELSE (T1."vehicle_reference")
  892. END AS "Vehicle Reference",
  893. CASE
  894. WHEN (
  895. (T1."posting_text" IS NULL)
  896. OR (T1."posting_text" = ' ')
  897. )
  898. THEN (' - ')
  899. ELSE (T1."posting_text")
  900. END AS "Posting Text",
  901. T1."term_of_payment" AS "Term Of Payment",
  902. T1."cash_discount" AS "Cash Discount",
  903. T1."journal_line" AS "Journal Line",
  904. T1."journal_page" AS "Journal Page",
  905. T1."last_dunning_date" AS "Last Dunning Date",
  906. T1."dunning_level" AS "Dunning Level",
  907. CASE
  908. WHEN (
  909. (T1."invoice_number" IS NULL)
  910. OR (T1."invoice_number" = ' ')
  911. )
  912. THEN (' - ')
  913. ELSE (T1."invoice_number")
  914. END AS "Invoice Number",
  915. T1."invoice_date" AS "Invoice Date",
  916. T1."employee_number" AS "Employee Number",
  917. T1."serial_number_each_month" AS "Serial Number Each Month",
  918. T1."account_form_page_line" AS "Account Form Page Line",
  919. T1."account_form_page_number" AS "Account Form Page Number",
  920. T1."contra_account_text" AS "Contra Account Text",
  921. T1."nominal_contra_account" AS "Nominal Contra Account",
  922. T1."customer_contra_account" AS "Customer Contra Account",
  923. T1."branch_number" AS "Branch Number",
  924. T1."posted_count" AS "Posted Count",
  925. T1."debit_or_credit" AS "Debit Or Credit",
  926. T1."posted_value" AS "Posted Value",
  927. T1."document_date" AS "Document Date",
  928. T1."clearing_number" AS "Clearing Number",
  929. T1."is_balanced" AS "Is Balanced",
  930. T1."customer_number" AS "Customer Number",
  931. T1."position_in_document" AS "Position In Document",
  932. (T1."document_number") AS "Document Number",
  933. T1."document_type" AS "Document Type"
  934. FROM (
  935. (
  936. (
  937. (
  938. "journal_accountings" T1 LEFT JOIN "LOCOSOFT"."dbo"."employees" T2 ON T1."employee_number" = T2."employee_number"
  939. ) LEFT JOIN "LOCOSOFT"."dbo"."customers_suppliers" T3 ON T3."customer_number" = T1."customer_number"
  940. ) LEFT JOIN "document_types" T4 ON T4."document_type_in_journal" = T1."document_type"
  941. ) LEFT JOIN "invoices" T5 ON T5."invtype_invnr" = T1."invoice_number"
  942. )
  943. WHERE (
  944. (
  945. (
  946. (
  947. (T1."nominal_account_number" IN (1400, 1409, 1451, 1408, 1525))
  948. AND (T1."clearing_number" = 0)
  949. )
  950. AND (T1."customer_number" IS NOT NULL)
  951. )
  952. AND (NOT T4."document_type_in_journal" IN ('A', 'E', 'U', 'V'))
  953. )
  954. AND (T3."customer_number" IS NOT NULL)
  955. )
  956. ) D2
  957. ) D1
  958. WHERE (c80 <> 0)
  959. -- order by "Customer Number" asc,"Document Type In Journal" asc,"Nominal Account Number" asc