Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT ALLOWED
- CASE
- WHEN PaymentCalendar.SecondPeriod < &WorkingDate
- THEN 1
- ELSE 2
- END AS PaymentOrder,
- CASE
- WHEN PaymentCalendar.SecondPeriod < &WorkingDate
- THEN &OverduePayments
- ELSE &ScheduledPayments
- END AS PaymentStatus,
- PaymentCalendar.DayPeriod AS Day,
- PaymentCalendar.SecondPeriod AS PaymentDate,
- PaymentCalendar.Recorder.Date AS DocumentDate,
- PaymentCalendar.Recorder AS Document,
- PaymentCalendar.Currency AS Currency,
- PaymentCalendar.Currency AS CurrencyOfPayment,
- PaymentCalendar.BankAccountPettyCash AS BankAccountPettyCash,
- PaymentCalendar.CashType AS CashType,
- CASE
- WHEN PaymentCalendar.InvoiceForPayment = UNDEFINED
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef)
- THEN PaymentCalendar.Article.Presentation
- ELSE PaymentCalendar.InvoiceForPayment.Presentation
- END AS Payment,
- PaymentCalendar.PaymentConfirmationStatus AS PaymentConfirmationStatus,
- FALSE AS RowCurrentBalance,
- ISNULL(PaymentCalendar.Recorder.Company.Presentation, "") AS CompanyPresentation,
- PaymentCalendar.Article.Presentation AS ArticlePresentation,
- SUBSTRING(PaymentCalendar.Recorder.Comment, 1, 100) AS Comment,
- &TextSummary AS TextSummary,
- SUBSTRING("", 1, 200) AS PaymentData,
- MAX(PaymentCalendar.AmountTurnover) AS AmountTurnover,
- SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0)) AS TotalTurnOverSumm,
- MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) AS AmountOfPaymentTurnover,
- CASE
- WHEN MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) > 0
- THEN CASE
- WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) >= 0
- THEN MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0))
- WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) < 0
- THEN 0
- ELSE SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0))
- END
- ELSE CASE
- WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) <= 0
- THEN MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0))
- WHEN SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0)) > 0
- THEN 0
- ELSE SUM(ISNULL(PaymentScheduleRegistrations.AmountTurnover, 0) + ISNULL(Cancellations.AmountTurnover, 0)) + MAX(PaymentCalendar.AmountTurnover + ISNULL(Cancellations.AmountTurnover, 0)) - MAX(ISNULL(PaymentCalendarPay.AmountOfPaymentTurnover, 0))
- END
- END AS Amount,
- MAX(CASE
- WHEN PaymentCalendar.Recorder REFS Document.CashTransferPlan
- AND PaymentCalendar.AmountTurnover < 0
- THEN -PaymentCalendar.AmountTurnover
- ELSE PaymentCalendar.AmountTurnover
- END) AS PaymentAmount,
- 0 AS AmountReceipt,
- 0 AS AmountExpense,
- 0 AS OpeningBalanceByAccount,
- 0 AS ClosingBalanceOfAccount,
- 0 AS InitialCurrencyBallance,
- 0 AS ClosingBalanceByCurrency,
- 0 AS OpeningBalanceByCashAssetsType,
- 0 AS ClosingBalanceByCashAssetsType
- FROM
- AccumulationRegister.PaymentCalendar.Turnovers(
- &StartDate,
- &EndDate,
- Auto,
- Entity = &Entity
- AND PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved)) AS PaymentCalendar
- LEFT JOIN AccumulationRegister.PaymentCalendar.Turnovers(
- &StartDate,
- &EndDate,
- Auto,
- Entity = &Entity
- AND PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved)) AS PaymentScheduleRegistrations
- ON (PaymentCalendar.SecondPeriod > PaymentScheduleRegistrations.SecondPeriod
- OR PaymentCalendar.SecondPeriod = PaymentScheduleRegistrations.SecondPeriod
- AND PaymentCalendar.Recorder > PaymentScheduleRegistrations.Recorder)
- AND (CASE
- WHEN (PaymentScheduleRegistrations.InvoiceForPayment = UNDEFINED
- OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.InvoiceForPayment.ПустаяСсылка)
- OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.PurchaseInvoiceForPayment.ПустаяСсылка)
- OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.CustomerOrder.ПустаяСсылка)
- OR PaymentScheduleRegistrations.InvoiceForPayment = VALUE(Документ.PurchaseOrder.ПустаяСсылка))
- AND (PaymentCalendar.InvoiceForPayment = UNDEFINED
- OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.InvoiceForPayment.ПустаяСсылка)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.PurchaseInvoiceForPayment.ПустаяСсылка)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.CustomerOrder.ПустаяСсылка)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Документ.PurchaseOrder.ПустаяСсылка))
- AND PaymentScheduleRegistrations.Article <> VALUE(Справочник.CashFlowItems.ПустаяСсылка)
- AND PaymentScheduleRegistrations.Article = PaymentCalendar.Article
- THEN TRUE
- WHEN PaymentScheduleRegistrations.InvoiceForPayment <> UNDEFINED
- AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.InvoiceForPayment.ПустаяСсылка)
- AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.PurchaseInvoiceForPayment.ПустаяСсылка)
- AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.CustomerOrder.ПустаяСсылка)
- AND PaymentScheduleRegistrations.InvoiceForPayment <> VALUE(Документ.PurchaseOrder.ПустаяСсылка)
- AND PaymentCalendar.InvoiceForPayment = PaymentScheduleRegistrations.InvoiceForPayment
- THEN TRUE
- ELSE FALSE
- END)
- LEFT JOIN AccumulationRegister.PaymentCalendar.Turnovers(
- &StartDate,
- &EndDate,
- Auto,
- Entity = &Entity
- AND PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved)) AS PaymentCalendarPay
- ON (PaymentCalendar.PaymentConfirmationStatus = VALUE(Enum.PaymentApprovalStatuses.Approved))
- AND (CASE
- WHEN (PaymentCalendarPay.InvoiceForPayment = UNDEFINED
- OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
- OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
- OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
- OR PaymentCalendarPay.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef))
- AND (PaymentCalendar.InvoiceForPayment = UNDEFINED
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef))
- AND PaymentCalendarPay.Article <> VALUE(Catalog.CashFlowItems.EmptyRef)
- AND PaymentCalendarPay.Article = PaymentCalendar.Article
- THEN TRUE
- WHEN PaymentCalendarPay.InvoiceForPayment <> UNDEFINED
- AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.InvoiceForPayment.EmptyRef)
- AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
- AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.CustomerOrder.EmptyRef)
- AND PaymentCalendarPay.InvoiceForPayment <> VALUE(Document.PurchaseOrder.EmptyRef)
- AND PaymentCalendar.InvoiceForPayment = PaymentCalendarPay.InvoiceForPayment
- THEN TRUE
- ELSE FALSE
- END)
- LEFT JOIN Cancellations AS Cancellations
- ON PaymentCalendar.Recorder = Cancellations.InvoiceForPayment
- WHERE
- NOT PaymentCalendar.Recorder REFS Document.PlanningDocumentCancellation
- GROUP BY
- CASE
- WHEN PaymentCalendar.SecondPeriod < &WorkingDate
- THEN 1
- ELSE 2
- END,
- PaymentCalendar.DayPeriod,
- PaymentCalendar.SecondPeriod,
- PaymentCalendar.Recorder,
- PaymentCalendar.Currency,
- PaymentCalendar.BankAccountPettyCash,
- PaymentCalendar.CashType,
- CASE
- WHEN PaymentCalendar.InvoiceForPayment = UNDEFINED
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.InvoiceForPayment.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseInvoiceForPayment.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.CustomerOrder.EmptyRef)
- OR PaymentCalendar.InvoiceForPayment = VALUE(Document.PurchaseOrder.EmptyRef)
- THEN PaymentCalendar.Article.Presentation
- ELSE PaymentCalendar.InvoiceForPayment.Presentation
- END,
- PaymentCalendar.Recorder.Date,
- SUBSTRING(PaymentCalendar.Recorder.Comment, 1, 100),
- PaymentCalendar.Article.Presentation,
- CASE
- WHEN PaymentCalendar.SecondPeriod < &WorkingDate
- THEN &OverduePayments
- ELSE &ScheduledPayments
- END,
- PaymentCalendar.PaymentConfirmationStatus,
- ISNULL(PaymentCalendar.Recorder.Company.Presentation, ""),
- PaymentCalendar.Currency
- ORDER BY
- PaymentOrder,
- PaymentCalendar.DayPeriod,
- PaymentCalendar.SecondPeriod,
- PaymentCalendar.Recorder,
- PaymentCalendar.BankAccountPettyCash
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement