CREATE PROCEDURE dbo.CityTaxGetAmount @AProductWareLinkNumber INT, @ACityTaxWareNumber INT OUTPUT, @ACityTaxAmount MONEY OUTPUT AS
SET NOCOUNT ON
/*
  Created by Kent Johansen, November 2017
  Changes:
*/
DECLARE @CityTaxResultAccountNumber INT

SELECT @ACityTaxWareNumber = WareNumber, @CityTaxResultAccountNumber = ResultAccountNumber
FROM Ware WITH (NOLOCK)
INNER JOIN ACCOUNTS WITH (NOLOCK) ON  Ware.ResultAccountNumber = Accounts.AccountNumber
WHERE Type = 28 -- City Tax

SELECT @ACityTaxAmount = SUM(Transactions.PriceOverwrite * (CASE Transactions.Debit WHEN 1 THEN -1 ELSE 1 END)*
  CASE WHEN Accounts.AccountType IN (4,5,6) THEN 1 ELSE 1+(VatValue/100) END)
FROM Accounts (NOLOCK)
FULL OUTER JOIN Transactions (NOLOCK) ON Accounts.AccountNumber = Transactions.AccountNumber
WHERE Transactions.ProductWareLinkNumber = @AProductWareLinkNumber
AND Transactions.WareNumber = @ACityTaxWareNumber
AND Transactions.AccountNumber = @CityTaxResultAccountNumber
AND ISNULL(MovedDeleted, 0) = 0