Advertisement
bytecoded

Top 1 Query (1C)

Nov 9th, 2019
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 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. ISNULL(InventoryToShip_ShajiTurnovers.QuantityReceipt, 0) AS ReceiptQTY,
  93. ISNULL(InventoryToShip_ShajiTurnovers.QuantityExpense, 0) AS ExpenseQTY,
  94. CASE
  95. WHEN DocumentInventoryExpense.TransactionType = VALUE(Enum.TransactionTypesSalesInvoice.SaleToCustomer)
  96. THEN CASE
  97. WHEN DocumentInventoryExpense.Posted
  98. THEN CASE
  99. WHEN DocumentInventoryExpense.RequiresDeliveryNote
  100. THEN CASE
  101. WHEN ISNULL(InventoryToShip_ShajiTurnovers.QuantityExpense, 0) <= 0
  102. THEN 0
  103. WHEN ISNULL(InventoryToShip_ShajiTurnovers.QuantityExpense, 0) / ISNULL(InventoryToShip_ShajiTurnovers.QuantityReceipt, 0) <= 0.5
  104. THEN 1
  105. WHEN ISNULL(InventoryToShip_ShajiTurnovers.QuantityExpense, 0) / ISNULL(InventoryToShip_ShajiTurnovers.QuantityReceipt, 0) < 1
  106. THEN 2
  107. WHEN ISNULL(InventoryToShip_ShajiTurnovers.QuantityExpense, 0) / ISNULL(InventoryToShip_ShajiTurnovers.QuantityReceipt, 0) >= 1
  108. THEN 3
  109. END
  110. ELSE 3
  111. END
  112. ELSE 0
  113. END
  114. ELSE 7
  115. END AS ShipmentPictureNumber
  116.  
  117. FROM
  118. Document.InventoryExpense AS DocumentInventoryExpense
  119. LEFT JOIN AccumulationRegister.SalesByCustomerOrders.Turnovers(, , , ) AS SalesByCustomerOrdersTurnovers
  120. ON DocumentInventoryExpense.Ref = SalesByCustomerOrdersTurnovers.InventoryExpense
  121. LEFT JOIN AccumulationRegister.CustomerAccounts.Balance(, ) AS CustomerAccountsBalance
  122. ON DocumentInventoryExpense.Ref = CustomerAccountsBalance.Document
  123. LEFT JOIN AccumulationRegister.AccountsReceivablePaymentTerms.Balance(&CurrentDate, ) AS AccountsReceivablePaymentTermsBalance
  124. ON DocumentInventoryExpense.Ref = AccountsReceivablePaymentTermsBalance.InventoryExpense
  125. LEFT JOIN InformationRegister.Bitrix24ObjectsMapping AS Bitrix24ObjectsMapping
  126. ON DocumentInventoryExpense.Ref = Bitrix24ObjectsMapping.Ref
  127. LEFT JOIN InformationRegister.TaxInvoiceByBasis AS TaxInvoiceByBasis
  128. ON DocumentInventoryExpense.Ref = TaxInvoiceByBasis.DocumentBasis
  129. LEFT JOIN AccumulationRegister.AccountsReceivableDeferred.Balance AS AccountsReceivableDeferredBalance
  130. ON DocumentInventoryExpense.Ref = AccountsReceivableDeferredBalance.Document
  131. LEFT JOIN AccumulationRegister.InventoryToShip_Shaji.Turnovers AS InventoryToShip_ShajiTurnovers
  132. ON (InventoryToShip_ShajiTurnovers.Document = DocumentInventoryExpense.Ref)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement