Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- CASE
- WHEN ShipmentOrdersStatuses.Status = &PartShipment
- THEN 1
- WHEN ShipmentOrdersStatuses.Status = &FullShipment
- THEN 2
- ELSE 0
- END AS ShipmentPictureNumber,
- CASE
- WHEN ISNULL(AccountsPayablePaymentTermsBalance.AmountCurBalance, 0) > 0
- THEN CASE
- WHEN ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover, 0) + ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover, 0) = 0
- THEN 4
- WHEN ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountCurTurnover, 0) <= ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover, 0) + ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover, 0)
- THEN 3
- WHEN ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover, 0) + ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover, 0) < ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountCurTurnover, 0) / 2
- THEN 5
- ELSE 6
- END
- ELSE CASE
- WHEN ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover, 0) + ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover, 0) = 0
- THEN 0
- WHEN ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountCurTurnover, 0) <= ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover, 0) + ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover, 0)
- THEN 3
- WHEN ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover, 0) + ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover, 0) < ISNULL(InvoicesAndOrdersPaymentTurnovers.AmountCurTurnover, 0) / 2
- THEN 1
- ELSE 2
- END
- END AS PaymentPictureNumber,
- DocumentPurchaseOrder.Ref,
- DocumentPurchaseOrder.DeletionMark,
- DocumentPurchaseOrder.Number,
- DocumentPurchaseOrder.Date,
- DocumentPurchaseOrder.Posted,
- DocumentPurchaseOrder.Entity AS Entity,
- DocumentPurchaseOrder.TransactionType,
- DocumentPurchaseOrder.Company,
- DocumentPurchaseOrder.Company.ContactPerson AS ContactPerson,
- DocumentPurchaseOrder.Contract,
- DocumentPurchaseOrder.ReceiptDate AS ReceiptDate,
- DocumentPurchaseOrder.DocumentCurrency,
- DocumentPurchaseOrder.AmountVATIn,
- DocumentPurchaseOrder.IncludeVATInCost,
- DocumentPurchaseOrder.ExchangeRate,
- DocumentPurchaseOrder.Repetition,
- DocumentPurchaseOrder.CustomerOrder,
- DocumentPurchaseOrder.DocumentAmount,
- DocumentPurchaseOrder.CompanyPriceKind,
- DocumentPurchaseOrder.Event,
- DocumentPurchaseOrder.Responsible,
- DocumentPurchaseOrder.BaseUnit,
- DocumentPurchaseOrder.Comment,
- DocumentPurchaseOrder.AddToPaymentCalendar,
- DocumentPurchaseOrder.PettyCash,
- DocumentPurchaseOrder.BankAccount,
- DocumentPurchaseOrder.CashType,
- DocumentPurchaseOrder.StatusOfOrder,
- DocumentPurchaseOrder.StatusOfOrder.OrderStatus AS StatusOfOrderState,
- CASE
- WHEN (DocumentPurchaseOrder.StatusOfOrder.OrderStatus = VALUE(Enum.OrderStatuses.Open)
- OR DocumentPurchaseOrder.StatusOfOrder.OrderStatus = VALUE(Enum.OrderStatuses.InProcess))
- AND NOT DocumentPurchaseOrder.IsClosed
- THEN "In Process"
- ELSE CASE
- WHEN DocumentPurchaseOrder.StatusOfOrder.OrderStatus = VALUE(Enum.OrderStatuses.Completed)
- THEN "Completed"
- ELSE "Cancelled"
- END
- END AS OrderStatus,
- DocumentPurchaseOrder.IsClosed,
- DocumentPurchaseOrder.IncomingDocumentNo,
- DocumentPurchaseOrder.IncomingDocumentDate,
- DocumentPurchaseOrder.Author,
- DocumentPurchaseOrder.Inventory.(
- Ref,
- LineNumber,
- Item,
- Characteristic,
- Quantity,
- UnitOfMeasure,
- Price,
- Amount,
- VATRate,
- VATAmount,
- ReceiptDate,
- AmountTotal
- ),
- DocumentPurchaseOrder.Materials.(
- Ref,
- LineNumber,
- Item,
- Characteristic,
- Quantity,
- UnitOfMeasure,
- ShippingDate
- ),
- DocumentPurchaseOrder.PaymentCalendar.(
- Ref,
- LineNumber,
- PayDate,
- PaymentPercentage,
- AmountOfPayment,
- PayVATAmount
- ),
- DocumentPurchaseOrder.PointInTime,
- PurchaseOrdersBalanceAndTurnovers.QuantityClosingBalance AS ToReceive,
- InvoicesAndOrdersPaymentTurnovers.AmountCurTurnover - InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover - InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover AS ForPayment,
- CASE
- WHEN DocumentPurchaseOrder.Posted
- AND DocumentPurchaseOrder.DocumentAmount > 0
- THEN CAST((InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover + InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover) * 100 / DocumentPurchaseOrder.DocumentAmount AS NUMBER(15, 2))
- ELSE 0
- END AS PaymentPercentage,
- CASE
- WHEN VendorAccountsBalances.AmountBalance < 0
- AND CustomerAccountsBalances.AmountBalance > 0
- THEN -1 * VendorAccountsBalances.AmountBalance + CustomerAccountsBalances.AmountBalance
- WHEN VendorAccountsBalances.AmountBalance < 0
- THEN -VendorAccountsBalances.AmountBalance
- WHEN CustomerAccountsBalances.AmountBalance > 0
- THEN CustomerAccountsBalances.AmountBalance
- ELSE 0
- END AS CompanyDebt,
- CASE
- WHEN VendorAccountsBalances.AmountBalance > 0
- AND CustomerAccountsBalances.AmountBalance < 0
- THEN -1 * CustomerAccountsBalances.AmountBalance + VendorAccountsBalances.AmountBalance
- WHEN VendorAccountsBalances.AmountBalance > 0
- THEN VendorAccountsBalances.AmountBalance
- WHEN CustomerAccountsBalances.AmountBalance < 0
- THEN -CustomerAccountsBalances.AmountBalance
- ELSE 0
- END AS OurDebt,
- DocumentPurchaseOrder.Company.Presentation AS PresentationOfCompany,
- CompanyEmail.Presentation AS CompanyEmail,
- CompanyPhone.Presentation AS CompanyPhone,
- CompanyFax.Presentation AS CompanyFax,
- CompanyLegalAddress.Presentation AS CompanyLegalAddress,
- CompanyDeliveryAddress.Presentation AS CompanyDeliveryAddress,
- OtherCompanyInfo.Presentation AS OtherCompanyInfo,
- DocumentPurchaseOrder.Company.ContactPerson.Presentation AS PresentationOfContactPerson,
- ContactPersonEmail.Presentation AS ContactPersonEmail,
- ContactPersonMobile.Presentation AS ContactPersonMobile,
- ContactPersonPhone.Presentation AS ContactPersonPhone,
- InvoicesAndOrdersPaymentTurnovers.AmountOfPaymentCurTurnover + InvoicesAndOrdersPaymentTurnovers.AmountOfAdvanceCurTurnover AS AmountOfPaymentTurnover,
- DocumentPurchaseOrder.CustomerOrderPosition,
- DocumentPurchaseOrder.ReceiptDatePosition
- FROM
- Constant.NationalCurrency AS ConstantNationalCurrency,
- Document.PurchaseOrder AS DocumentPurchaseOrder
- LEFT JOIN AccumulationRegister.PurchaseOrders.BalanceAndTurnovers(, , Auto, , ) AS PurchaseOrdersBalanceAndTurnovers
- ON (PurchaseOrdersBalanceAndTurnovers.PurchaseOrder = DocumentPurchaseOrder.Ref)
- LEFT JOIN AccumulationRegister.VendorAccounts.Balance(, ) AS VendorAccountsBalances
- ON DocumentPurchaseOrder.Company = VendorAccountsBalances.Company
- LEFT JOIN AccumulationRegister.CustomerAccounts.Balance(, ) AS CustomerAccountsBalances
- ON DocumentPurchaseOrder.Company = CustomerAccountsBalances.Company
- LEFT JOIN AccumulationRegister.InvoicesAndOrdersPayment.Turnovers AS InvoicesAndOrdersPaymentTurnovers
- ON DocumentPurchaseOrder.Ref = InvoicesAndOrdersPaymentTurnovers.InvoiceForPayment
- LEFT JOIN AccumulationRegister.Purchasing.Turnovers AS PurchasingTurnovers
- ON DocumentPurchaseOrder.Ref = PurchasingTurnovers.PurchaseOrder
- LEFT JOIN InformationRegister.CurrencyRates.SliceLast(
- ,
- Currency IN
- (SELECT
- ConstantDefaultCurrency.Value
- FROM
- Constant.DefaultCurrency AS ConstantDefaultCurrency)) AS ManagCurrencyRates
- ON (TRUE)
- LEFT JOIN InformationRegister.CurrencyRates.SliceLast(
- ,
- Currency IN
- (SELECT
- ConstantNationalCurrency.Value
- FROM
- Constant.NationalCurrency AS ConstantNationalCurrency)) AS RegCurrencyRates
- ON (TRUE)
- LEFT JOIN Catalog.Companies.ContactInformation AS CompanyEmail
- ON DocumentPurchaseOrder.Company = CompanyEmail.Ref
- AND (CompanyEmail.Kind = VALUE(Catalog.ContactInformationKinds.CompanyEmail))
- LEFT JOIN Catalog.Companies.ContactInformation AS CompanyPhone
- ON DocumentPurchaseOrder.Company = CompanyPhone.Ref
- AND (CompanyPhone.Kind = VALUE(Catalog.ContactInformationKinds.CompanyPhone))
- LEFT JOIN Catalog.Companies.ContactInformation AS CompanyFax
- ON DocumentPurchaseOrder.Company = CompanyFax.Ref
- AND (CompanyFax.Kind = VALUE(Catalog.ContactInformationKinds.CompanyFax))
- LEFT JOIN Catalog.Addresses AS CompanyLegalAddress
- ON DocumentPurchaseOrder.Company.LegalAddress = CompanyLegalAddress.Ref
- LEFT JOIN Catalog.Addresses AS CompanyDeliveryAddress
- ON DocumentPurchaseOrder.Company.DeliveryAddress = CompanyDeliveryAddress.Ref
- LEFT JOIN Catalog.Companies.ContactInformation AS OtherCompanyInfo
- ON DocumentPurchaseOrder.Company = OtherCompanyInfo.Ref
- AND (OtherCompanyInfo.Kind = VALUE(Catalog.ContactInformationKinds.CompanyOtherInformation))
- LEFT JOIN Catalog.ContactPersons.ContactInformation AS ContactPersonEmail
- ON DocumentPurchaseOrder.Company.ContactPerson = ContactPersonEmail.Ref
- AND (ContactPersonEmail.Kind = VALUE(Catalog.ContactInformationKinds.ContactPersonEmail))
- LEFT JOIN Catalog.ContactPersons.ContactInformation AS ContactPersonMobile
- ON DocumentPurchaseOrder.Company.ContactPerson = ContactPersonMobile.Ref
- AND (ContactPersonMobile.Kind = VALUE(Catalog.ContactInformationKinds.ContactPersonMobile))
- LEFT JOIN Catalog.ContactPersons.ContactInformation AS ContactPersonPhone
- ON DocumentPurchaseOrder.Company.ContactPerson = ContactPersonPhone.Ref
- AND (ContactPersonPhone.Kind = VALUE(Catalog.ContactInformationKinds.ContactPersonPhone))
- LEFT JOIN InformationRegister.ShipmentOrdersStatuses AS ShipmentOrdersStatuses
- ON (ShipmentOrdersStatuses.Order = DocumentPurchaseOrder.Ref)
- LEFT JOIN AccumulationRegister.AccountsPayablePaymentTerms.Balance(&CurrentDate, ) AS AccountsPayablePaymentTermsBalance
- ON DocumentPurchaseOrder.Ref = AccountsPayablePaymentTermsBalance.PurchaseOrder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement