--# from spRptLabour
SELECT tInvoice.CustomerID,
	ltrim(rtrim(substring(tInvoiceReportTransaction.Var03,7,2))) + '/' +
	ltrim(rtrim(substring(tInvoiceReportTransaction.Var03,5,2))) + '/' +
	ltrim(rtrim(substring(tInvoiceReportTransaction.Var03,1,4))) AS LogDatTime,
    	tInvoiceReportTransaction.Var01 AS CallNumber,
   	tInvoiceReportTransaction.Var04 AS Reference,
	ltrim(isnull(tInvoiceReportTransaction.Var10, ' ') + ' ' + isnull(tInvoiceReportTransaction.Var05,' ') + ' ' + isnull(tInvoiceReportTransaction.Var13,' ')) AS Descr,
  	tInvoiceReportTransaction.Var14 AS LastName,
	tInvoiceReportTransaction.amountexGST,
	tInvoiceReportTransaction.BatchID,
	tInvoiceDetail.Description as InvDetailDesc,
	tBatchType.SupplierDisplayedName,
	tInvoiceDetail.Period

FROM tInvoice (NOLOCK)
INNER JOIN tInvoiceDetail (NOLOCK) 		ON tInvoice.ID = tInvoiceDetail.InvoiceID
LEFT OUTER /*INNER*/ JOIN tInvoiceReportTransaction  (NOLOCK)	ON tInvoiceReportTransaction.InvoiceDetailID = tInvoiceDetail.ID
INNER JOIN tBatchType (NOLOCK)			ON tBatchType.ID = tInvoiceDetail.BatchTypeID


WHERE tInvoice.PlatinumInvoiceNo =  'INV003239'
AND  tBatchType.ReportGroupID = 3

ORDER BY tInvoiceDetail.Description,tInvoiceReportTransaction.BatchID, tInvoiceReportTransaction.Var01
