SELECT
  JL.CMSJournalNo,
  JL.CMSJournalLineNo,
  JL.CMSInvNo,
  JL.ItemNumber,
  JL.CMSLineNo,
  JL.Description,
  JL.DebitAccount,
  JL.DebitBranchRegion,
  JL.DebitProductCategory,
  JL.DebitTaxType,
  JL.CreditAccount,
  JL.CreditBranchRegion,
  JL.CreditProductCategory,
  JL.CreditTaxType,
  JL.LineAmount
FROM
  taManualJournalLine AS JL
    LEFT JOIN taManualJournalHeader AS JH ON (JH.CMSJournalNo = JL.CMSJournalNo)
    LEFT JOIN taInvoiceHeader AS IH ON (IH.CMSInvNo = JH.CMSInvNo)
WHERE
  (JH.AccountBookType = 'Xero') AND
  ((IH.CMSInvNo IS NULL) OR (IH.Updated = 1)) AND
  ((IH.CMSInvNo IS NULL) OR (IH.DocumentNumber <> 'VOID')) AND
  (JH.Updated = 0)
  @pFilter
ORDER BY
  JL.CMSJournalNo,
  JL.CMSJournalLineNo