Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- Limits.LimitType AS LimitType,
- Limits.Amount AS Amount,
- Limits.CurrencyLimit AS CurrencyLimit,
- SUM(ISNULL(CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN CAST(ARWithCheques.AmountCurBalance * Rates.ExchangeRate * Limits.MultiplicityLimit / (Limits.RateLimit * ISNULL(Rates.Multiplicity, 1)) AS NUMBER(15, 2))
- ELSE ARWithCheques.AmountCurBalance
- END, 0)) AS AmountBalance,
- Limits.Contract AS Contract
- INTO LimitBalance
- FROM
- Limits AS Limits
- LEFT JOIN ARWithCheques AS ARWithCheques
- LEFT JOIN Rates AS Rates
- ON (ARWithCheques.Contract.AccountsCurrency = Rates.Currency)
- ON (CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN TRUE
- ELSE Limits.Contract = ARWithCheques.Contract
- END)
- WHERE
- Limits.LimitType = VALUE(Enum.LimitType.Debit)
- GROUP BY
- Limits.LimitType,
- Limits.Amount,
- Limits.Contract,
- Limits.CurrencyLimit
- UNION ALL
- SELECT
- Limits.LimitType,
- Limits.Amount,
- Limits.CurrencyLimit,
- SUM(ISNULL(CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN CAST(VendorAccountsBalance.AmountCurBalance * Rates.ExchangeRate * Limits.MultiplicityLimit / (Limits.RateLimit * ISNULL(Rates.Multiplicity, 1)) AS NUMBER(15, 2))
- ELSE VendorAccountsBalance.AmountCurBalance
- END, 0)),
- Limits.Contract
- FROM
- Limits AS Limits
- LEFT JOIN AccumulationRegister.VendorAccounts.Balance(
- &Period,
- Entity = &Entity
- AND Company = &Company) AS VendorAccountsBalance
- LEFT JOIN Rates AS Rates
- ON VendorAccountsBalance.Contract.AccountsCurrency = Rates.Currency
- ON (CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN TRUE
- ELSE Limits.Contract = VendorAccountsBalance.Contract
- END)
- WHERE
- Limits.LimitType = VALUE(Enum.LimitType.Credit)
- GROUP BY
- Limits.LimitType,
- Limits.Amount,
- Limits.Contract,
- Limits.CurrencyLimit
- UNION ALL
- SELECT
- Limits.LimitType,
- Limits.Amount,
- Limits.CurrencyLimit,
- SUM(ISNULL(CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN CAST(SalesByCustomerOrdersTurnovers.AmountCurTurnover * Rates.ExchangeRate * Limits.MultiplicityLimit / (Limits.RateLimit * ISNULL(Rates.Multiplicity, 1)) AS NUMBER(15, 2))
- ELSE SalesByCustomerOrdersTurnovers.AmountCurTurnover
- END, 0)),
- Limits.Contract
- FROM
- Limits AS Limits
- LEFT JOIN AccumulationRegister.SalesByCustomerOrders.Turnovers(
- ,
- &Period,
- ,
- Entity = &Entity
- AND Company = &Company) AS SalesByCustomerOrdersTurnovers
- LEFT JOIN Rates AS Rates
- ON SalesByCustomerOrdersTurnovers.Contract.AccountsCurrency = Rates.Currency
- ON (CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN TRUE
- ELSE Limits.Contract = SalesByCustomerOrdersTurnovers.Contract
- END)
- WHERE
- Limits.LimitType = VALUE(enum.limittype.income)
- GROUP BY
- Limits.LimitType,
- Limits.Amount,
- Limits.Contract,
- Limits.CurrencyLimit
- UNION ALL
- SELECT
- Limits.LimitType,
- Limits.Amount,
- Limits.CurrencyLimit,
- SUM(ISNULL(CAST(PurchasingTurnovers.AmountTurnover * Rates.ExchangeRate * Limits.MultiplicityLimit / (Limits.RateLimit * ISNULL(Rates.Multiplicity, 1)) AS NUMBER(15, 2)), 0)),
- Limits.Contract
- FROM
- Limits AS Limits
- LEFT JOIN AccumulationRegister.Purchasing.Turnovers(
- ,
- &Period,
- ,
- Entity = &Entity
- AND Document.Company = &Company) AS PurchasingTurnovers
- LEFT JOIN Rates AS Rates
- ON (Rates.Currency = &RegCurr)
- ON (CASE
- WHEN Limits.Contract = VALUE(Catalog.CompanyContracts.EmptyRef)
- THEN TRUE
- ELSE Limits.Contract = PurchasingTurnovers.Document.Contract
- END)
- WHERE
- Limits.LimitType = VALUE(Enum.LimitType.Expense)
- GROUP BY
- Limits.LimitType,
- Limits.Amount,
- Limits.Contract,
- Limits.CurrencyLimit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement