Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- DocumentInventoryExpense.Ref AS Ref,
- DocumentInventoryExpense.DeletionMark AS DeletionMark,
- DocumentInventoryExpense.Number AS Number,
- DocumentInventoryExpense.Date AS Date,
- DocumentInventoryExpense.Posted AS Posted,
- DocumentInventoryExpense.AccountsPayableGLAccount_GL AS AccountsPayableGLAccount_GL,
- DocumentInventoryExpense.AccountsReceivableGLAccount_GL AS AccountsReceivableGLAccount_GL,
- DocumentInventoryExpense.AdvancesPaidGLAccount_GL AS AdvancesPaidGLAccount_GL,
- DocumentInventoryExpense.AdvancesReceivedGLAccount_GL AS AdvancesReceivedGLAccount_GL,
- DocumentInventoryExpense.AmountVATIn AS AmountVATIn,
- DocumentInventoryExpense.Author AS Author,
- DocumentInventoryExpense.BankAccount AS BankAccount,
- DocumentInventoryExpense.BaseUnit AS BaseUnit,
- DocumentInventoryExpense.BaseUnitPosition AS BaseUnitPosition,
- DocumentInventoryExpense.Cell AS Cell,
- DocumentInventoryExpense.Comment AS Comment,
- DocumentInventoryExpense.Company AS Company,
- DocumentInventoryExpense.Consignee AS Consignee,
- DocumentInventoryExpense.Contract AS Contract,
- DocumentInventoryExpense.CustomerOrderPosition AS CustomerOrderPosition,
- DocumentInventoryExpense.DeliveryAddress AS DeliveryAddress,
- DocumentInventoryExpense.DeliveryTerms AS DeliveryTerms,
- DocumentInventoryExpense.Department AS Department,
- DocumentInventoryExpense.DiscountMarkupKind AS DiscountMarkupKind,
- DocumentInventoryExpense.DocumentAmount AS DocumentAmount,
- DocumentInventoryExpense.DocumentBasis AS DocumentBasis,
- DocumentInventoryExpense.DocumentCurrency AS DocumentCurrency,
- DocumentInventoryExpense.Entity AS Entity,
- DocumentInventoryExpense.ExchangeRate AS ExchangeRate,
- DocumentInventoryExpense.GoodsOrder AS GoodsOrder,
- DocumentInventoryExpense.IncludeVATInCost AS IncludeVATInCost,
- DocumentInventoryExpense.IncomingDocumentDate AS IncomingDocumentDate,
- DocumentInventoryExpense.IncomingDocumentInfoPosition AS IncomingDocumentInfoPosition,
- DocumentInventoryExpense.IncomingDocumentNumber AS IncomingDocumentNumber,
- DocumentInventoryExpense.Lead AS Lead,
- DocumentInventoryExpense.OffsetAdvancesDebtsAutomatically AS OffsetAdvancesDebtsAutomatically,
- DocumentInventoryExpense.PaymentTerms AS PaymentTerms,
- DocumentInventoryExpense.PaymentTermsStagesChanged AS PaymentTermsStagesChanged,
- DocumentInventoryExpense.PositionCell AS PositionCell,
- DocumentInventoryExpense.PriceDate AS PriceDate,
- DocumentInventoryExpense.PriceKind AS PriceKind,
- DocumentInventoryExpense.Project AS Project,
- DocumentInventoryExpense.ProjectPosition AS ProjectPosition,
- DocumentInventoryExpense.Repetition AS Repetition,
- DocumentInventoryExpense.Responsible AS Responsible,
- DocumentInventoryExpense.Shipper AS Shipper,
- DocumentInventoryExpense.TaxationVAT AS TaxationVAT,
- DocumentInventoryExpense.TransactionType AS TransactionType,
- DocumentInventoryExpense.PointInTime AS PointInTime,
- CASE
- WHEN DocumentInventoryExpense.TransactionType = VALUE(Enum.TransactionTypesSalesInvoice.SaleToCustomer)
- AND DocumentInventoryExpense.Posted
- THEN CASE
- WHEN &UsePaymentTerms
- AND ISNULL(AccountsReceivablePaymentTermsBalance.AmountCurBalance, 0) > 0
- THEN CASE
- WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) = ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
- THEN 4
- WHEN ISNULL(CustomerAccountsBalance.AmountCurBalance, 0) = 0
- AND ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) > 0
- THEN 3
- WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) / 2 > ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
- THEN 6
- ELSE 5
- END
- ELSE CASE
- WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) = ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
- THEN 0
- WHEN ISNULL(CustomerAccountsBalance.AmountCurBalance, 0) = 0
- AND ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) > 0
- THEN 3
- WHEN ISNULL(SalesByCustomerOrdersTurnovers.AmountCurTurnover, 0) / 2 > ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
- THEN 2
- ELSE 1
- END
- END
- ELSE 7
- END AS PaymentPictureNumber,
- CASE
- WHEN Bitrix24ObjectsMapping.ID IS NULL
- THEN 1
- ELSE 0
- END AS Bitrix24Mapped,
- TaxInvoiceByBasis.TaxInvoice AS TaxInvoice,
- DocumentInventoryExpense.TaxInvoiceIsRequired AS TaxInvoiceIsRequired,
- CASE
- WHEN ISNULL(AccountsReceivableDeferredBalance.AmountCurBalance, 0) + ISNULL(CustomerAccountsBalance.AmountCurBalance, 0) > 0
- THEN ISNULL(AccountsReceivableDeferredBalance.AmountCurBalance, 0) + ISNULL(CustomerAccountsBalance.AmountCurBalance, 0)
- ELSE 0
- END AS OSBalance
- FROM
- Document.InventoryExpense AS DocumentInventoryExpense
- LEFT JOIN AccumulationRegister.SalesByCustomerOrders.Turnovers(, , , ) AS SalesByCustomerOrdersTurnovers
- ON DocumentInventoryExpense.Ref = SalesByCustomerOrdersTurnovers.InventoryExpense
- LEFT JOIN AccumulationRegister.CustomerAccounts.Balance(, ) AS CustomerAccountsBalance
- ON DocumentInventoryExpense.Ref = CustomerAccountsBalance.Document
- LEFT JOIN AccumulationRegister.AccountsReceivablePaymentTerms.Balance(&CurrentDate, ) AS AccountsReceivablePaymentTermsBalance
- ON DocumentInventoryExpense.Ref = AccountsReceivablePaymentTermsBalance.InventoryExpense
- LEFT JOIN InformationRegister.Bitrix24ObjectsMapping AS Bitrix24ObjectsMapping
- ON DocumentInventoryExpense.Ref = Bitrix24ObjectsMapping.Ref
- LEFT JOIN InformationRegister.TaxInvoiceByBasis AS TaxInvoiceByBasis
- ON DocumentInventoryExpense.Ref = TaxInvoiceByBasis.DocumentBasis
- LEFT JOIN AccumulationRegister.AccountsReceivableDeferred.Balance AS AccountsReceivableDeferredBalance
- ON DocumentInventoryExpense.Ref = AccountsReceivableDeferredBalance.Document
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement