CREATE VIEW [dbo].[TTransactionGoView]
AS
-- nb20210812: Created Grouped by OriginalTransactionNumber
SELECT SUM(FLOOR(T.Pieces)) AS Pcs
, CAST(SUM(T.PriceOverwrite/T.Pieces*ABS(T.Pieces) * VS.SignedValue) AS MONEY) AS Total
, (COUNT(*) - 1) AS SplitCount
--helper fields
, T.OriginalGlobalTransactionNumber AS MGTN
, T.FolioNumber
FROM Transactions T WITH (NOLOCK) 
  LEFT JOIN TransactionTransactionXtab TX WITH (NOLOCK) ON TX.FK_TransactionNumber2 = T.TransactionNumber
  LEFT JOIN TSignPaymentWGWView VS (NOLOCK) ON VS.TransactionNumber = T.TransactionNumber
WHERE T.ShowOnBillflag = 1 
GROUP BY T.OriginalGlobalTransactionNumber, T.FolioNumber