Advertisement
bytecoded

Top Query #3 (1C)

Mar 19th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. SELECT
  2. DocumentInventoryExpense.Ref AS Ref,
  3. DocumentInventoryExpense.DeletionMark AS DeletionMark,
  4. DocumentInventoryExpense.Number AS Number,
  5. DocumentInventoryExpense.Date AS Date,
  6. DocumentInventoryExpense.Posted AS Posted,
  7. DocumentInventoryExpense.AccountsPayableGLAccount_GL AS AccountsPayableGLAccount_GL,
  8. DocumentInventoryExpense.AccountsReceivableGLAccount_GL AS AccountsReceivableGLAccount_GL,
  9. DocumentInventoryExpense.AdvancesPaidGLAccount_GL AS AdvancesPaidGLAccount_GL,
  10. DocumentInventoryExpense.AdvancesReceivedGLAccount_GL AS AdvancesReceivedGLAccount_GL,
  11. DocumentInventoryExpense.AmountVATIn AS AmountVATIn,
  12. DocumentInventoryExpense.Author AS Author,
  13. DocumentInventoryExpense.BankAccount AS BankAccount,
  14. DocumentInventoryExpense.BaseUnit AS BaseUnit,
  15. DocumentInventoryExpense.BaseUnitPosition AS BaseUnitPosition,
  16. DocumentInventoryExpense.Cell AS Cell,
  17. DocumentInventoryExpense.Comment AS Comment,
  18. DocumentInventoryExpense.Company AS Company,
  19. DocumentInventoryExpense.Consignee AS Consignee,
  20. DocumentInventoryExpense.Contract AS Contract,
  21. DocumentInventoryExpense.CustomerOrderPosition AS CustomerOrderPosition,
  22. DocumentInventoryExpense.DeliveryAddress AS DeliveryAddress,
  23. DocumentInventoryExpense.DeliveryTerms AS DeliveryTerms,
  24. DocumentInventoryExpense.Department AS Department,
  25. DocumentInventoryExpense.DiscountMarkupKind AS DiscountMarkupKind,
  26. DocumentInventoryExpense.DocumentAmount AS DocumentAmount,
  27. DocumentInventoryExpense.DocumentBasis AS DocumentBasis,
  28. DocumentInventoryExpense.DocumentCurrency AS DocumentCurrency,
  29. DocumentInventoryExpense.Entity AS Entity,
  30. DocumentInventoryExpense.ExchangeRate AS ExchangeRate,
  31. DocumentInventoryExpense.GoodsOrder AS GoodsOrder,
  32. DocumentInventoryExpense.IncludeVATInCost AS IncludeVATInCost,
  33. DocumentInventoryExpense.IncomingDocumentDate AS IncomingDocumentDate,
  34. DocumentInventoryExpense.IncomingDocumentInfoPosition AS IncomingDocumentInfoPosition,
  35. DocumentInventoryExpense.IncomingDocumentNumber AS IncomingDocumentNumber,
  36. DocumentInventoryExpense.Lead AS Lead,
  37. DocumentInventoryExpense.OffsetAdvancesDebtsAutomatically AS OffsetAdvancesDebtsAutomatically,
  38. DocumentInventoryExpense.PaymentTerms AS PaymentTerms,
  39. DocumentInventoryExpense.PaymentTermsStagesChanged AS PaymentTermsStagesChanged,
  40. DocumentInventoryExpense.PositionCell AS PositionCell,
  41. DocumentInventoryExpense.PriceDate AS PriceDate,
  42. DocumentInventoryExpense.PriceKind AS PriceKind,
  43. DocumentInventoryExpense.Project AS Project,
  44. DocumentInventoryExpense.ProjectPosition AS ProjectPosition,
  45. DocumentInventoryExpense.Repetition AS Repetition,
  46. DocumentInventoryExpense.Responsible AS Responsible,
  47. DocumentInventoryExpense.Shipper AS Shipper,
  48. DocumentInventoryExpense.TaxationVAT AS TaxationVAT,
  49. DocumentInventoryExpense.TransactionType AS TransactionType,
  50. DocumentInventoryExpense.PointInTime AS PointInTime,
  51. CASE
  52. WHEN DocumentInventoryExpense.TransactionType = VALUE(Enum.TransactionTypesSalesInvoice.SaleToCustomer)
  53. AND DocumentInventoryExpense.Posted
  54. THEN CASE
  55. WHEN &UsePaymentTerms
  56. AND ISNULL(AccountsReceivablePaymentTermsBalance.AmountCurBalance, 0) > 0
  57. THEN CASE
  58. WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) = ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
  59. THEN 4
  60. WHEN ISNULL(CustomerAccountsBalance.AmountCurBalance, 0) = 0
  61. AND ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) > 0
  62. THEN 3
  63. WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) / 2 > ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
  64. THEN 6
  65. ELSE 5
  66. END
  67. ELSE CASE
  68. WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) = ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
  69. THEN 0
  70. WHEN ISNULL(CustomerAccountsBalance.AmountCurBalance, 0) = 0
  71. AND ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) > 0
  72. THEN 3
  73. WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) / 2 > ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
  74. THEN 2
  75. ELSE 1
  76. END
  77. END
  78. ELSE 7
  79. END AS PaymentPictureNumber,
  80. CASE
  81. WHEN Bitrix24ObjectsMapping.ID IS NULL
  82. THEN 1
  83. ELSE 0
  84. END AS Bitrix24Mapped,
  85. TaxInvoiceByBasis.TaxInvoice AS TaxInvoice,
  86. DocumentInventoryExpense.TaxInvoiceIsRequired AS TaxInvoiceIsRequired,
  87. CASE
  88. WHEN ISNULL(AccountsReceivableDeferredBalance.AmountCurBalance, 0) + ISNULL(CustomerAccountsBalance.AmountCurBalance, 0) > 0
  89. THEN ISNULL(AccountsReceivableDeferredBalance.AmountCurBalance, 0) + ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
  90. ELSE 0
  91. END AS OSBalance
  92. FROM
  93. Document.InventoryExpense AS DocumentInventoryExpense
  94. LEFT JOIN AccumulationRegister.SalesByCustomerOrders.Turnovers(, , , ) AS SalesByCustomerOrdersTurnovers
  95. ON DocumentInventoryExpense.Ref = SalesByCustomerOrdersTurnovers.InventoryExpense
  96. LEFT JOIN AccumulationRegister.CustomerAccounts.Balance(, ) AS CustomerAccountsBalance
  97. ON DocumentInventoryExpense.Ref = CustomerAccountsBalance.Document
  98. LEFT JOIN AccumulationRegister.AccountsReceivablePaymentTerms.Balance(&CurrentDate, ) AS AccountsReceivablePaymentTermsBalance
  99. ON DocumentInventoryExpense.Ref = AccountsReceivablePaymentTermsBalance.InventoryExpense
  100. LEFT JOIN InformationRegister.Bitrix24ObjectsMapping AS Bitrix24ObjectsMapping
  101. ON DocumentInventoryExpense.Ref = Bitrix24ObjectsMapping.Ref
  102. LEFT JOIN InformationRegister.TaxInvoiceByBasis AS TaxInvoiceByBasis
  103. ON DocumentInventoryExpense.Ref = TaxInvoiceByBasis.DocumentBasis
  104. LEFT JOIN AccumulationRegister.AccountsReceivableDeferred.Balance AS AccountsReceivableDeferredBalance
  105. ON DocumentInventoryExpense.Ref = AccountsReceivableDeferredBalance.Document
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement