
SELECT
 tElement.Description AS Element,
 tServiceID.ServiceID AS ServiceIDDesc,
 tFinalisedTransaction201008.BatchID AS Batch,
 tBatchType.SupplierDisplayedName,
 tLocation.Description AS Location,
 tPerson.Person,
 tCentre.Description AS CustCentre,
 tActivity.Description AS CustActivity,
 tElement_1.Description AS CustElement,
 tSubledger.Description AS CustSubledger,
 tFinalisedTransaction201008.PayType,
 tServiceType.Description AS ServiceType,
 '' AS InvDetailDesc,
 tBatch.BillingPeriod AS Period,
 tCustomer.ShipTo,
 'VRT999999' AS PlatinumInvoiceNo,
 SUM(tFinalisedTransaction201008.AmountExGST) AS ExGST,
 SUM(tFinalisedTransaction201008.GSTAmount) AS GST,
 SUM(tFinalisedTransaction201008.AmountIncGST) AS IncGST,
 tTransactionGroup.Description AS TxnGrp,
 tFinalisedTransaction201008.Var01,
 tFinalisedTransaction201008.Var02,
 tFinalisedTransaction201008.Var03,
 tFinalisedTransaction201008.Var04,
 tFinalisedTransaction201008.Var05,
 tBatchType.Description,
 tReportGroup.GroupDesc,
 tDepartment.Description AS DeptDesc
FROM
 tFinalisedTransaction201008
 INNER JOIN ( tBatch
	LEFT JOIN ( tBatchType
		LEFT OUTER JOIN tReportGroup
			ON tBatchType.ReportGroupID = tReportGroup.ID
		) ON tBatch.BatchTypeID = tBatchType.ID
	) ON tBatch.ID = tFinalisedTransaction201008.BatchID
 LEFT JOIN tServiceID
        ON tFinalisedTransaction201008.ServiceID = tServiceID.ID
 LEFT JOIN tTransactionType
	ON tFinalisedTransaction201008.TransactionTypeID = tTransactionType.ID
 LEFT JOIN tTransactionGroup
	ON tTransactionType.TransactionGroupID = tTransactionGroup.ID

 LEFT JOIN tElement
	ON tFinalisedTransaction201008.ElementID = tElement.ID
 LEFT JOIN tElement tElement_1
        ON tFinalisedTransaction201008.CustomerElementID = tElement_1.ID
 LEFT JOIN tServiceType
        ON tFinalisedTransaction201008.ServiceTypeID = tServiceType.ID

 LEFT JOIN tCustomer
        ON tFinalisedTransaction201008.CustomerID = tCustomer.ID
 LEFT JOIN tCentre
        ON tFinalisedTransaction201008.CustomerCentreID = tCentre.ID
 LEFT JOIN tActivity
        ON tFinalisedTransaction201008.CustomerActivityID = tActivity.ID
 LEFT JOIN tSubledger
        ON tFinalisedTransaction201008.CustomerSubledgerID = tSubledger.ID
 LEFT JOIN tDepartment
        ON tFinalisedTransaction201008.DepartmentID = tDepartment.ID
 LEFT JOIN tLocation
        ON tFinalisedTransaction201008.LocationID = tLocation.ID
 LEFT JOIN tPerson
        ON tFinalisedTransaction201008.PersonID = tPerson.ID
GROUP BY
 tElement.Description, tServiceID.ServiceID,
 tFinalisedTransaction201008.BatchID,
 tBatchType.SupplierDisplayedName, tLocation.Description, 
 tPerson.Person, tCentre.Description, tServiceType.Description,
 tSubledger.Description, 
 tBatch.BillingPeriod, tCustomer.ShipTo,
 tFinalisedTransaction201008.Var01, tFinalisedTransaction201008.Var02,
 tFinalisedTransaction201008.Var03, tFinalisedTransaction201008.Var04, 
 tFinalisedTransaction201008.Var05,
 tBatchType.Description, tReportGroup.GroupDesc, tTransactionGroup.Description, 
 tDepartment.Description, tFinalisedTransaction201008.PayType,
 tActivity.Description, tElement_1.Description
HAVING
 (tCustomer.ShipTo = 'VRT')
ORDER BY
 tCentre.Description

