SELECT
    `cn`.`id` AS `transaction_id`,
    `cn`.`file_id` AS `file_id`,
    `cn`.`credited_date` AS `transaction_date`,
    `cn`.`customer_id` AS `customer_id`,
    `customer`.`customer_name` AS `customer_name`,
    'Credit Note' AS `checkin_frm`,
    'CN' AS `status`
FROM    (        `erp_creditnote` `cn`    
JOIN `erp_customer` `customer`    ON        ((`customer`.`id` = `cn`.`customer_id`))    )
WHERE    (`cn`.`is_updated_store` = 'N')
UNION ALL
SELECT
    `pgr`.`id` AS `transaction_id`,
    `pgr`.`file_id` AS `file_id`,
    `pgr`.`goods_receipt_date` AS `transaction_date`,
    `pgr`.`customer_id` AS `customer_id`,
    `customer`.`customer_name` AS `customer_name`,
    'Production Goods Receipt' AS `checkin_frm`,
    'PGR' AS `status`
FROM    (       `erp_production_goods_receipt` `pgr`
    LEFT JOIN `erp_customer` `customer`
    ON        (            (`customer`.`id` = `pgr`.`customer_id`)        )    )
WHERE    (`pgr`.`is_updated_store` = 'N')
UNION ALL
SELECT
    `igr`.`id` AS `transaction_id`,
    `igr`.`file_id` AS `file_id`,
    `igr`.`goods_receipt_date` AS `transaction_date`,
    `igr`.`customer_id` AS `customer_id`,
    `customer`.`customer_name` AS `customer_name`,
    'Inventory Goods Receipt' AS `checkin_frm`,
    'IGR' AS `status`
FROM
    (
        `erp_inventory_goods_receipt` `igr`
    LEFT JOIN `erp_customer` `customer`
    ON
        (
            (`customer`.`id` = `igr`.`customer_id`)
        )
    )
WHERE
    (`igr`.`stock_updated` = 'N')
UNION ALL
SELECT
    `dt`.`id` AS `transaction_id`,
    'N/A' AS `file_id`,
    `dt`.`transfer_date` AS `transaction_date`,
    0 AS `customer_id`,
    'N/A' AS `customer_name`,
    'Direct Transfer' AS `checkin_frm`,
    'DTCK' AS `status`
FROM
    `erp_inventory_direct_transfer` `dt`
WHERE
    (`dt`.`status` = 'P')
UNION ALL
SELECT
    `idt`.`id` AS `transaction_id`,
    'N/A' AS `file_id`,
    `idt`.`transfer_date` AS `transaction_date`,
    0 AS `customer_id`,
    'N/A' AS `customer_name`,
    'Indirect Transfer' AS `checkin_frm`,
    'IDTCK' AS `status`
FROM
   `erp_inventory_indirect_transfer` `idt`
WHERE
    (`idt`.`is_complete` = 'P')