Belege_Autoline_Verkauf_Erfolgsrechnung_operativ.sql 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. select T1."CostCentre" as "Costcentre",
  2. T1."ExpenseCode" as "Expensecode",
  3. T1."Suffix" as "Suffix",
  4. T1."AccountsModule" as "Accountsmodule",
  5. T1."DaybookNumber" as "Daybooknumber",
  6. T1."ItemNumber" as "Itemnumber",
  7. T1."PostingDate" as "Postingdate",
  8. T1."AccountsCompany" as "Accountscompany",
  9. T1."SLPLAccountCode" as "Slplaccountcode",
  10. T1."Period" as "Period",
  11. T1."JournalReference" as "Journalreference",
  12. T1."Narrative" as "Narrative",
  13. T1."Year" as "Year",
  14. T1."BaseValue" as "Basevalue",
  15. T1."CurrencyValue" as "Currencyvalue",
  16. T1."SequenceNumber" as "Sequencenumber",
  17. T1."Reconciled" as "Reconciled",
  18. T1."JournalType" as "Journaltype",
  19. T1."TransferBatch" as "Transferbatch",
  20. T1."GroupDrValue" as "Groupdrvalue",
  21. T1."GroupCrValue" as "Groupcrvalue",
  22. T1."CurrencyLogSerial" as "Currencylogserial",
  23. T1."SourceCompany" as "Sourcecompany",
  24. T1."StatementDate" as "Statementdate",
  25. T1."SourceModule" as "Sourcemodule",
  26. T1."VATCode" as "Vatcode",
  27. T1."LegalAnalytic" as "Legalanalytic",
  28. T1."LatinSequence" as "Latinsequence",
  29. T1."LatinSequenceLine" as "Latinsequenceline",
  30. T1."ReconciledDate" as "Reconcileddate",
  31. T1."ReconciledTime" as "Reconciledtime",
  32. T1."ReconciledUser" as "Reconcileduser",
  33. T1."ChequeValueDate" as "Chequevaluedate",
  34. T1."DocumentNumber" as "Documentnumber",
  35. T1."JournalClass" as "Journalclass",
  36. T1."JournalSeqType" as "Journalseqtype",
  37. T1."VATGroup" as "Vatgroup",
  38. T1."CustomerReference" as "Customerreference",
  39. T1."ReconciledReference" as "Reconciledreference",
  40. T1."CashFlowGroup" as "Cashflowgroup",
  41. T1."CashFlowCode" as "Cashflowcode",
  42. T1."ConsSourceCompany" as "Conssourcecompany",
  43. T1."ConsSourceDaybook" as "Conssourcedaybook",
  44. T1."BranchCode" as "Branchcode",
  45. T1."DocumentDate" as "Documentdate",
  46. T1."Client_DB" as "Client Db",
  47. T1."AccountCode" as "Accountcode",
  48. T1."PostingDate" as "Bookkeep Date",
  49. T1."Client_DB" as "Rechtseinheit_ID",
  50. T2."Description002" as "Description002_Expense_Code_Kto_Bez",
  51. T2."AccountType" as "Accounttype_Expense_Code",
  52. T3."CostCentre" as "Costcentre_Department",
  53. T3."ShortName" as "Shortname_Department",
  54. T3."Description001" as "Description001_Department",
  55. T3."Description002" as "Description002_Department",
  56. T3."Description003" as "Description003_Department",
  57. T3."Description004" as "Description004_Department",
  58. T3."CostCentreGroup" as "Costcentregroup_Department",
  59. T4."CostCentreGroup" as "Costcentregroup_Costcentergr",
  60. T4."Description001" as "Description001_Costcentergr",
  61. T4."Description002" as "Description002_Costcentergr",
  62. T4."Description003" as "Description003_Costcentergr",
  63. T4."Description004" as "Description004_Costcentergr",
  64. T5."LocationCode" as "Locationcode_GB_company",
  65. T5."Description" as "Description_GB_company",
  66. T5."LocationName" as "Locationname_GB_company",
  67. '' as "Rechtseinheit_Name",
  68. T5."LocationCode" as "Standort_ID",
  69. T5."LocationCode" + ' - ' + T5."Description" as "Standort_Name",
  70. T1."ExpenseCode" as "Acct Nr",
  71. CASE WHEN ((-1 * datediff(day, (getdate()), T1."PostingDate")) <= 90) THEN ((rtrim((((T1."DocumentNumber"))))) + ' - ' + T1."JournalClass" + ' - ' + T1."CustomerReference") ELSE ('Belege älter 90 Tage') END as "Text",
  72. T4."CostCentreGroup" + ' - ' + T4."Description002" as "Kostenstelle_alt",
  73. (rtrim((((T3."CostCentre"))))) + ' - ' + T3."Description002" as "KST_Detail",
  74. T6."KONTO_1" as "Konto 1",
  75. T6."EBENE1" as "Ebene1",
  76. T6."EBENE2" as "Ebene2",
  77. T6."EBENE3" as "Ebene3",
  78. T6."EBENE4" as "Ebene4",
  79. T6."KONTO_2" as "Konto 2",
  80. T1."PostingDate" as "Invoice Date",
  81. T1."Client_DB" as "Hauptbetrieb_ID",
  82. '' as "Hauptbetrieb_Name",
  83. 'Serviceberater' as "Zuordnung_Funktion",
  84. T6."KONTO_BEZEICHNUNG" as "Konto Bezeichnung",
  85. T1."CustomerReference" as "Kunde_FIBU",
  86. T7."AccountCode" as "Accountcode_SL_Sales_Ledger_Acct_FIBU",
  87. T7."CustomerSName" as "Customersname_SL_Sales_Ledger_Acct_FIBU",
  88. CASE WHEN ((T1."Suffix" = '') and (T7."AccountCode" IS NULL)) THEN ('Buchungen ohne Auftrag') WHEN (((T1."Suffix" <> '') and (T7."AccountCode" IS NULL)) and (T1."AccountsModule" <> 'SL')) THEN ('Buchungen ohne Auftrag') ELSE (T7."AccountCode" + ' - ' + T7."CustomerSName") END as "Kunde_Rg",
  89. T8."Franchise" as "Franchise_MK_Vehiclerecords",
  90. CASE WHEN (T8."Franchise" = 'M') THEN ('Mercedes PKW') WHEN (T8."Franchise" = 'T') THEN ('Mercedes TRAPO') WHEN (T8."Franchise" = 'Z') THEN ('Fremd') WHEN (T8."Franchise" = 'S') THEN ('Smart') WHEN (T8."Franchise" = 'F') THEN ('Fremd TRAPO') ELSE null END as "Fabrikat",
  91. T8."Description" as "Description_MK_Vehiclerecords",
  92. (left((ucase(T8."Description")),4)) as "Model",
  93. T3."ShortName" + ' - ' + T3."Description001" as "Kostenstelle",
  94. T7."Postcode" as "Postcode_Slsalesledgeraccount",
  95. (left(T7."Postcode",1)) as "PLZ_1_Stelle",
  96. (left(T7."Postcode",2)) as "PLZ_2_Stelle",
  97. (left(T7."Postcode",3)) as "PLZ_3_Stelle",
  98. (left(T7."Postcode",4)) as "PLZ_4_Stelle",
  99. T7."Postcode" as "PLZ"
  100. from "ims"."Kontenrahmen_Verkauf_Erfolgsrechnung" T6,
  101. ((((((("AUTOLINE"."import"."NL_NominalTransactionFile" T1 left outer join "AUTOLINE"."import"."NL_NominalExpenseCodes" T2 on (T2."ExpenseCode" = T1."ExpenseCode") and (T2."Client_DB" = T1."Client_DB")) left outer join "AUTOLINE"."import"."NL_NominalDepartmentCodes" T3 on (T1."CostCentre" = T3."CostCentre") and (T1."Client_DB" = T3."Client_DB")) left outer join "AUTOLINE"."import"."NL_DepartmentCodeGroups" T4 on (T3."CostCentreGroup" = T4."CostCentreGroup") and (T3."Client_DB" = T4."Client_DB")) left outer join "AUTOLINE"."import"."GB_CompanyLocations" T5 on (left((((T1."CostCentre"))),2)) = T5."LocationCode") left outer join "AUTOLINE"."import"."SL_SalesLedgerAccounts" T7 on (T1."SLPLAccountCode" = T7."AccountCode") and (T1."Client_DB" = T7."Client_DB")) left outer join "AUTOLINE"."import"."SO_HeaderRecords" T9 on (T1."Suffix" = (((T9."WIPNumber")))) and (T1."Client_DB" = T9."Client_DB")) left outer join "AUTOLINE"."import"."MK_VehicleRecords" T8 on T8."VehicleNumber" = T9."MagicMKVehicle")
  102. where (T1."ExpenseCode" = (cinteger(nconvert(T6."KONTO_NR"),0)))
  103. and (T1."PostingDate" >= convert(datetime, '2024-06-01 00:00:00.000'))
  104. -- order by "Documentnumber" asc,"Suffix" asc