CREATE PROCEDURE dbo.GiftTokenGetBalance @AGiftTokenNumber VARCHAR(50), @AAmount MONEY OUTPUT AS
SET NOCOUNT ON
/*
  Created by Kent Johansen January 2013
  Returns the balance for at gift certificate
  Changes:
*/
SELECT @AAmount = SUM(Transactions.PriceOverwrite*Pieces)*-1
FROM GiftToken WITH (NOLOCK)
INNER JOIN GiftTokenTransactionsXTab WITH (NOLOCK) ON GiftTokenTransactionsXTab.FK_GiftTokenId = GiftToken.Id
  AND GiftToken.GiftTokenNumber = @AGiftTokenNumber
INNER JOIN Transactions WITH (NOLOCK) ON Transactions.OriginalGlobalTransactionNumber = GiftTokenTransactionsXTab.FK_OriginalGlobalTransactionNumber
  AND Transactions.ShowOnBillFlag = 1