SELECT DISTINCT
`a`.`ID` AS `ID`,
`a`.`companyID` AS `companyID`,
`a`.`reference` AS `referenceNo`,
'comp_gst_transaction' AS `tableName`,
`b`.`journalID` AS `journalID`,
`b`.`formNo` AS `formNo`
FROM
`comp_gst_transaction` `a` JOIN `comp_journal` `b`
ON CONVERT(`a`.`journalNo` USING UTF8) = `b`.`journalID` AND `a`.`companyID` = `b`.`companyID`
WHERE
`a`.`is_delete` = 0;

SELECT DISTINCT
`a`.`ID` AS `ID`,
`a`.`companyID` AS `companyID`,
'' AS `referenceNo`,
'comp_sales_bad_debt' AS `tableName`,
`b`.`journalID` AS `journalID`,
`b`.`formNo` AS `formNo`
FROM
`comp_sales_bad_debt` `a` JOIN `comp_journal` `b`
ON CONVERT(`a`.`journalNo` USING UTF8) = `b`.`journalID` AND `a`.`companyID` = `b`.`companyID`
WHERE
`a`.`is_delete` = 0

SELECT DISTINCT
`a`.`ID` AS `ID`,
`a`.`companyID` AS `companyID`,
'' AS `referenceNo`,
'comp_purchase_bad_debt' AS `tableName`,
`b`.`journalID` AS `journalID`,
`b`.`formNo` AS `formNo`
FROM
`comp_purchase_bad_debt` `a` JOIN `comp_journal` `b`
ON CONVERT(`a`.`journalNo` USING UTF8) = `b`.`journalID` AND `a`.`companyID` = `b`.`companyID`
WHERE
`a`.`is_delete` = 0

SELECT DISTINCT
`a`.`ID` AS `ID`,
`a`.`companyID` AS `companyID`,
'' AS `referenceNo`,
'comp_sales_debt_recover' AS `tableName`,
`b`.`journalID` AS `journalID`,
`b`.`formNo` AS `formNo`
FROM
`comp_sales_debt_recover` `a` JOIN `comp_journal` `b`
ON `b`.`journalID` = `a`.`journalNo` AND `a`.`companyID` = `b`.`companyID`
WHERE
`a`.`is_delete` = 0

SELECT DISTINCT
`a`.`ID` AS `ID`,
`a`.`companyID` AS `companyID`,
'' AS `referenceNo`,
'comp_purchase_debt_recover' AS `tableName`,
`b`.`journalID` AS `journalID`,
`b`.`formNo` AS `formNo`
FROM
`comp_purchase_debt_recover` `a` JOIN `comp_journal` `b`
ON `b`.`journalID` = `a`.`journalNo` AND `a`.`companyID` = `b`.`companyID`
WHERE
`a`.`is_delete` = 0

