Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT ALLOWED
- CASE
- WHEN SalesTurnovers.Recorder = UNDEFINED
- THEN NULL
- ELSE SalesTurnovers.Recorder
- END AS Recorder,
- SalesTurnovers.Item AS Item,
- SalesTurnovers.Item AS ItemWithSKU,
- SalesTurnovers.Item.Description AS ItemPresentation,
- CASE
- WHEN SalesTurnovers.Characteristic = VALUE(Catalog.ItemCharacteristics.EmptyRef)
- THEN CASE
- WHEN SalesTurnovers.Batch <> VALUE(Catalog.ItemBatches.EmptyRef)
- THEN "N/A"
- ELSE NULL
- END
- ELSE SalesTurnovers.Characteristic
- END AS Characteristic,
- SalesTurnovers.Characteristic AS CharacteristicGrossProfit,
- CASE
- WHEN SalesTurnovers.Batch = VALUE(Catalog.ItemBatches.EmptyRef)
- THEN NULL
- ELSE SalesTurnovers.Batch
- END AS Batch,
- SalesTurnovers.Batch AS BatchGrossProfit,
- SalesTurnovers.Document AS Document,
- SalesTurnovers.VATRate AS VATRate,
- SalesTurnovers.Entity AS Entity,
- SalesTurnovers.CustomerOrder AS CustomerOrder,
- SalesTurnovers.QuantityTurnover AS Quantity,
- SalesTurnovers.AmountTurnover AS Amount,
- SalesTurnovers.AmountTurnover - SalesTurnovers.VATAmountTurnover AS AmountWithoutVAT,
- SalesTurnovers.VATAmountTurnover AS VATAmount,
- SalesTurnovers.CostPriceTurnover AS CostPrice,
- SalesTurnovers.Item.UnitOfMeasure AS ItemUnitOfMeasure,
- SalesTurnovers.Item.SKU AS ItemSKU,
- Companies.Ref AS Company,
- SalesTurnovers.Project AS Project,
- SalesTurnovers.Document.Date AS DocumentDate,
- SalesTurnovers.Document.Number AS DocumentNumber,
- SalesTurnovers.CustomerOrder.Date AS CustomerOrderDate,
- SalesTurnovers.CustomerOrder.Number AS CustomerOrderNumber,
- SalesTurnovers.WeekPeriod AS WeekPeriod,
- SalesTurnovers.MonthPeriod AS MonthPeriod,
- SalesTurnovers.QuarterPeriod AS QuarterPeriod,
- SalesTurnovers.HalfYearPeriod AS HalfYearPeriod,
- SalesTurnovers.YearPeriod AS YearPeriod,
- CASE
- WHEN SalesTurnovers.Item.Commissionable
- THEN SalesTurnovers.AmountTurnover - SalesTurnovers.VATAmountTurnover
- ELSE 0
- END AS AmountWithoutVATCI,
- CASE
- WHEN NOT SalesTurnovers.Item.Commissionable
- THEN SalesTurnovers.AmountTurnover - SalesTurnovers.VATAmountTurnover
- ELSE 0
- END AS AmountWithoutVATNCI,
- 0 AS Payment,
- SalesTurnovers.Document.Department AS Department,
- NULL AS AmountCancelled
- INTO Sales
- FROM
- AccumulationRegister.Sales.Turnovers(, , Auto, ) AS SalesTurnovers
- LEFT JOIN Catalog.Companies AS Companies
- ON SalesTurnovers.Document.Company = Companies.Ref
- UNION ALL
- SELECT
- AccountsReceivableDeferredTurnovers.Recorder,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- AccountsReceivableDeferredTurnovers.Document,
- NULL,
- AccountsReceivableDeferredTurnovers.Entity,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- AccountsReceivableDeferredTurnovers.Company,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- AccountsReceivableDeferredTurnovers.AmountExpense,
- AccountsReceivableDeferredTurnovers.Document.Department,
- NULL
- FROM
- AccumulationRegister.AccountsReceivableDeferred.Turnovers(, , Auto, &IncludingCheques) AS AccountsReceivableDeferredTurnovers
- WHERE
- AccountsReceivableDeferredTurnovers.Recorder REFS Document.ChequeReceipt
- UNION ALL
- SELECT
- CustomerAccountsTurnovers.Recorder,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- CustomerAccountsTurnovers.Document,
- NULL,
- CustomerAccountsTurnovers.Entity,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- CustomerAccountsTurnovers.Company,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- CustomerAccountsTurnovers.AmountExpense,
- CustomerAccountsTurnovers.Document.Department,
- NULL
- FROM
- AccumulationRegister.CustomerAccounts.Turnovers(, , Auto, ) AS CustomerAccountsTurnovers
- WHERE
- CASE
- WHEN &IncludingCheques
- THEN NOT CustomerAccountsTurnovers.Recorder.DocumentBasis REFS Document.ChequeReceipt
- ELSE TRUE
- END
- AND (CustomerAccountsTurnovers.Recorder REFS Document.PettyCashReceipt
- OR CustomerAccountsTurnovers.Recorder REFS Document.PaymentReceipt)
- UNION ALL
- SELECT
- AccountsReceivableDeferredTurnovers.Recorder,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- AccountsReceivableDeferredTurnovers.Document,
- NULL,
- AccountsReceivableDeferredTurnovers.Entity,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- AccountsReceivableDeferredTurnovers.Company,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- AccountsReceivableDeferredTurnovers.Document.Department,
- AccountsReceivableDeferredTurnovers.AmountReceipt
- FROM
- AccumulationRegister.AccountsReceivableDeferred.Turnovers(, , Auto, &IncludingCheques) AS AccountsReceivableDeferredTurnovers
- WHERE
- AccountsReceivableDeferredTurnovers.Recorder REFS Document.ChequeCancellation
- ;
- ////////////////////////////////////////////////////////////////////////////////
- SELECT ALLOWED
- CustomerAccountsBalance.Company AS Company,
- CustomerAccountsBalance.Entity AS Entity,
- SUM(CustomerAccountsBalance.AmountBalance) AS AmountBalance,
- CustomerAccountsBalance.Document.Department AS Department,
- CustomerAccountsBalance.Document AS Document
- INTO CustomerBalance
- FROM
- AccumulationRegister.CustomerAccounts.Balance(
- ,
- (Company, Entity) IN
- (SELECT
- Sales.Company AS Company,
- Sales.Entity AS Entity
- FROM
- Sales AS Sales)) AS CustomerAccountsBalance
- GROUP BY
- CustomerAccountsBalance.Entity,
- CustomerAccountsBalance.Company,
- CustomerAccountsBalance.Document,
- CustomerAccountsBalance.Document.Department
- UNION ALL
- SELECT
- AccountsReceivableDeferredBalance.Company,
- AccountsReceivableDeferredBalance.Entity,
- SUM(AccountsReceivableDeferredBalance.AmountBalance),
- AccountsReceivableDeferredBalance.Document.Department,
- AccountsReceivableDeferredBalance.Document
- FROM
- AccumulationRegister.AccountsReceivableDeferred.Balance(
- ,
- (Company, Entity) IN
- (SELECT
- Sales.Company AS Company,
- Sales.Entity AS Entity
- FROM
- Sales AS Sales)) AS AccountsReceivableDeferredBalance
- WHERE
- &IncludingCheques
- GROUP BY
- AccountsReceivableDeferredBalance.Entity,
- AccountsReceivableDeferredBalance.Company,
- AccountsReceivableDeferredBalance.Document,
- AccountsReceivableDeferredBalance.Document.Department
- ;
- ////////////////////////////////////////////////////////////////////////////////
- SELECT ALLOWED
- Sales.Entity AS Entity,
- SUM(Sales.Amount) AS Amount,
- SUM(Sales.AmountWithoutVAT) AS AmountWithoutVAT,
- Sales.Document.Responsible AS Responsible,
- Sales.Document.SalesExecutive AS SalesExecutive,
- Sales.Company AS Company,
- Sales.MonthPeriod AS MonthPeriod,
- Sales.QuarterPeriod AS QuarterPeriod,
- Sales.HalfYearPeriod AS HalfYearPeriod,
- Sales.YearPeriod AS YearPeriod,
- SUM(Sales.AmountWithoutVATCI) AS AmountWithoutVATCI,
- SUM(Sales.AmountWithoutVATNCI) AS AmountWithoutVATNCI,
- SUM(Sales.Payment) AS Payment,
- NULL AS ARBalance,
- Sales.Department AS Department,
- Sales.Document AS Document,
- Sales.Document.Date AS DocumentDate,
- Sales.Document.Number AS DocumentNumber,
- SUM(CASE
- WHEN Sales.Document.Date < DATETIME(2018, 1, 1)
- THEN Sales.Payment
- ELSE 0
- END) AS PaymentOB,
- SUM(CASE
- WHEN Sales.Document.Date >= DATETIME(2018, 1, 1)
- OR Sales.Document.Date IS NULL
- THEN Sales.Payment
- ELSE 0
- END) AS PaymentWOB,
- SUM(Sales.AmountCancelled) AS AmountCancelled,
- SUM(CASE
- WHEN Sales.Document.Date < DATETIME(2018, 1, 1)
- THEN Sales.Payment
- ELSE Sales.Payment / (1 + &VATRateByDefault / 100)
- END) AS PaymentExclVAT
- FROM
- Sales AS Sales
- WHERE
- CASE
- WHEN &RespType = 0
- THEN Sales.Document.Responsible = &Employee
- OR Sales.Document.SalesExecutive = &Employee
- WHEN &RespType = 1
- THEN Sales.Document.Responsible = &Employee
- AND Sales.Document.SalesExecutive <> &Employee
- WHEN &RespType = 2
- THEN Sales.Document.Responsible <> &Employee
- AND Sales.Document.SalesExecutive = &Employee
- WHEN &RespType = 3
- THEN Sales.Document.Responsible = &Employee
- AND Sales.Document.SalesExecutive = &Employee
- ELSE TRUE
- END
- GROUP BY
- Sales.Company,
- Sales.YearPeriod,
- Sales.HalfYearPeriod,
- Sales.MonthPeriod,
- Sales.Entity,
- Sales.QuarterPeriod,
- Sales.Department,
- Sales.Document,
- Sales.Document.Date,
- Sales.Document.Number,
- Sales.Document.Responsible,
- Sales.Document.SalesExecutive
- UNION ALL
- SELECT
- CustomerBalance.Entity,
- NULL,
- NULL,
- CustomerBalance.Document.Responsible,
- CustomerBalance.Document.SalesExecutive,
- CustomerBalance.Company,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- SUM(CustomerBalance.AmountBalance),
- CustomerBalance.Department,
- CustomerBalance.Document,
- CustomerBalance.Document.Date,
- CustomerBalance.Document.Number,
- NULL,
- NULL,
- NULL,
- NULL
- FROM
- CustomerBalance AS CustomerBalance
- WHERE
- CASE
- WHEN &RespType = 0
- THEN CustomerBalance.Document.Responsible = &Employee
- OR CustomerBalance.Document.SalesExecutive = &Employee
- WHEN &RespType = 1
- THEN CustomerBalance.Document.Responsible = &Employee
- AND CustomerBalance.Document.SalesExecutive <> &Employee
- WHEN &RespType = 2
- THEN CustomerBalance.Document.Responsible <> &Employee
- AND CustomerBalance.Document.SalesExecutive = &Employee
- WHEN &RespType = 3
- THEN CustomerBalance.Document.Responsible = &Employee
- AND CustomerBalance.Document.SalesExecutive = &Employee
- ELSE TRUE
- END
- GROUP BY
- CustomerBalance.Company,
- CustomerBalance.Document,
- CustomerBalance.Entity,
- CustomerBalance.Department,
- CustomerBalance.Document.Date,
- CustomerBalance.Document.Number,
- CustomerBalance.Document.Responsible,
- CustomerBalance.Document.SalesExecutive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement