Advertisement
bytecoded

Top Query #1 (1C)

Mar 19th, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.91 KB | None | 0 0
  1. SELECT ALLOWED
  2. CASE
  3. WHEN PaymentCalendar.SecondPeriod < &WorkingDate
  4. THEN 1
  5. ELSE 2
  6. END AS PaymentOrder,
  7. CASE
  8. WHEN PaymentCalendar.SecondPeriod < &WorkingDate
  9. THEN &OverduePayments
  10. ELSE &ScheduledPayments
  11. END AS PaymentStatus,
  12. PaymentCalendar.DayPeriod AS Day,
  13. PaymentCalendar.SecondPeriod AS PaymentDate,
  14. PaymentCalendar.Recorder.Date AS DocumentDate,
  15. PaymentCalendar.Recorder AS Document,
  16. PaymentCalendar.Currency AS Currency,
  17. PaymentCalendar.Currency AS CurrencyOfPayment,
  18. PaymentCalendar.BankAccountPettyCash AS BankAccountPettyCash,
  19. PaymentCalendar.CashType AS CashType,
  20. CASE
  21. WHEN PaymentCalendar.InvoiceForPayment = UNDEFINED
  22. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
  23. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
  24. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
  25. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef)
  26. THEN PaymentCalendar.Article.Presentation
  27. ELSE PaymentCalendar.InvoiceForPayment.Presentation
  28. END AS Payment,
  29. PaymentCalendar.PaymentConfirmationStatus AS PaymentConfirmationStatus,
  30. FALSE AS RowCurrentBalance,
  31. ISNULL(PaymentCalendar.Recorder.Company.Presentation, "") AS CompanyPresentation,
  32. PaymentCalendar.Article.Presentation AS ArticlePresentation,
  33. SUBSTRING(PaymentCalendar.Recorder.Comment, 1, 100) AS Comment,
  34. &TextSummary AS TextSummary,
  35. SUBSTRING("", 1, 200) AS PaymentData,
  36. MAX(PaymentCalendar.AmountTurnover) AS AmountTurnover,
  37. SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0)) AS TotalTurnOverSumm,
  38. MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) AS AmountOfPaymentTurnover,
  39. CASE
  40. WHEN MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) > 0
  41. THEN CASE
  42. WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) >= 0
  43. THEN MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0))
  44. WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) < 0
  45. THEN 0
  46. ELSE SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0))
  47. END
  48. ELSE CASE
  49. WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) <= 0
  50. THEN MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0))
  51. WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) > 0
  52. THEN 0
  53. ELSE SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0))
  54. END
  55. END AS Amount,
  56. MAX(CASE
  57. WHEN PaymentCalendar.Recorder REFS Document.CashTransferPlan
  58. AND PaymentCalendar.AmountTurnover < 0
  59. THEN -PaymentCalendar.AmountTurnover
  60. ELSE PaymentCalendar.AmountTurnover
  61. END) AS PaymentAmount,
  62. 0 AS AmountReceipt,
  63. 0 AS AmountExpense,
  64. 0 AS OpeningBalanceByAccount,
  65. 0 AS ClosingBalanceOfAccount,
  66. 0 AS InitialCurrencyBallance,
  67. 0 AS ClosingBalanceByCurrency,
  68. 0 AS OpeningBalanceByCashAssetsType,
  69. 0 AS ClosingBalanceByCashAssetsType
  70. FROM
  71. AccumulationRegister.PaymentCalendar.Turnovers(
  72. &StartDate,
  73. &EndDate,
  74. Auto,
  75. Entity = &Entity
  76. AND PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved)) AS PaymentCalendar
  77. LEFT JOIN AccumulationRegister.PaymentCalendar.Turnovers(
  78. &StartDate,
  79. &EndDate,
  80. Auto,
  81. Entity = &Entity
  82. AND PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved)) AS PaymentScheduleRegistrations
  83. ON (PaymentCalendar.SecondPeriod > PaymentScheduleRegistrations.SecondPeriod
  84. OR PaymentCalendar.SecondPeriod = PaymentScheduleRegistrations.SecondPeriod
  85. AND PaymentCalendar.Recorder > PaymentScheduleRegistrations.Recorder)
  86. AND (CASE
  87. WHEN (PaymentScheduleRegistrations.InvoiceForPayment = UNDEFINED
  88. OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.InvoiceForPayment.ПустаяСсылка)
  89. OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.PurchaseInvoiceForPayment.ПустаяСсылка)
  90. OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.CustomerOrder.ПустаяСсылка)
  91. OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.PurchaseOrder.ПустаяСсылка))
  92. AND (PaymentCalendar.InvoiceForPayment = UNDEFINED
  93. OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.InvoiceForPayment.ПустаяСсылка)
  94. OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.PurchaseInvoiceForPayment.ПустаяСсылка)
  95. OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.CustomerOrder.ПустаяСсылка)
  96. OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.PurchaseOrder.ПустаяСсылка))
  97. AND PaymentScheduleRegistrations.Article <> VALUE(Справочник.CashFlowItems.ПустаяСсылка)
  98. AND PaymentScheduleRegistrations.Article = PaymentCalendar.Article
  99. THEN TRUE
  100. WHEN PaymentScheduleRegistrations.InvoiceForPayment <> UNDEFINED
  101. AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.InvoiceForPayment.ПустаяСсылка)
  102. AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.PurchaseInvoiceForPayment.ПустаяСсылка)
  103. AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.CustomerOrder.ПустаяСсылка)
  104. AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.PurchaseOrder.ПустаяСсылка)
  105. AND PaymentCalendar.InvoiceForPayment = PaymentScheduleRegistrations.InvoiceForPayment
  106. THEN TRUE
  107. ELSE FALSE
  108. END)
  109. LEFT JOIN AccumulationRegister.PaymentCalendar.Turnovers(
  110. &StartDate,
  111. &EndDate,
  112. Auto,
  113. Entity = &Entity
  114. AND PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved)) AS PaymentCalendarPay
  115. ON (PaymentCalendar.PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved))
  116. AND (CASE
  117. WHEN (PaymentCalendarPay.InvoiceForPayment = UNDEFINED
  118. OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
  119. OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
  120. OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
  121. OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef))
  122. AND (PaymentCalendar.InvoiceForPayment = UNDEFINED
  123. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
  124. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
  125. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
  126. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef))
  127. AND PaymentCalendarPay.Article <> VALUE(Catalog.CashFlowItems.EmptyRef)
  128. AND PaymentCalendarPay.Article = PaymentCalendar.Article
  129. THEN TRUE
  130. WHEN PaymentCalendarPay.InvoiceForPayment <> UNDEFINED
  131. AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.InvoiceForPayment.EmptyRef)
  132. AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
  133. AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.CustomerOrder.EmptyRef)
  134. AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.PurchaseOrder.EmptyRef)
  135. AND PaymentCalendar.InvoiceForPayment = PaymentCalendarPay.InvoiceForPayment
  136. THEN TRUE
  137. ELSE FALSE
  138. END)
  139. LEFT JOIN Cancellations AS Cancellations
  140. ON PaymentCalendar.Recorder = Cancellations.InvoiceForPayment
  141. WHERE
  142. NOT PaymentCalendar.Recorder REFS Document.PlanningDocumentCancellation
  143.  
  144. GROUP BY
  145. CASE
  146. WHEN PaymentCalendar.SecondPeriod < &WorkingDate
  147. THEN 1
  148. ELSE 2
  149. END,
  150. PaymentCalendar.DayPeriod,
  151. PaymentCalendar.SecondPeriod,
  152. PaymentCalendar.Recorder,
  153. PaymentCalendar.Currency,
  154. PaymentCalendar.BankAccountPettyCash,
  155. PaymentCalendar.CashType,
  156. CASE
  157. WHEN PaymentCalendar.InvoiceForPayment = UNDEFINED
  158. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
  159. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
  160. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
  161. OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef)
  162. THEN PaymentCalendar.Article.Presentation
  163. ELSE PaymentCalendar.InvoiceForPayment.Presentation
  164. END,
  165. PaymentCalendar.Recorder.Date,
  166. SUBSTRING(PaymentCalendar.Recorder.Comment, 1, 100),
  167. PaymentCalendar.Article.Presentation,
  168. CASE
  169. WHEN PaymentCalendar.SecondPeriod < &WorkingDate
  170. THEN &OverduePayments
  171. ELSE &ScheduledPayments
  172. END,
  173. PaymentCalendar.PaymentConfirmationStatus,
  174. ISNULL(PaymentCalendar.Recorder.Company.Presentation, ""),
  175. PaymentCalendar.Currency
  176.  
  177. ORDER BY
  178. PaymentOrder,
  179. PaymentCalendar.DayPeriod,
  180. PaymentCalendar.SecondPeriod,
  181. PaymentCalendar.Recorder,
  182. PaymentCalendar.BankAccountPettyCash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement