SELECT 'I' as Ind, itemID, INV.item_name as Item ,
trans.difference as Stock FROM $master_db.Sales_Inventory_Items as INV LEFT OUTER JOIN (SELECT itemID, 
SUM(COALESCE(Cr_Qty,0) -COALESCE(Dr_Qty,0)) AS difference FROM $trans_db.Transaction_Item_Helper 
  WHERE VoucherDate<= str_to_date('$toDateTime','%Y-%m-%d') Group BY ItemID)
 as trans on INV.Item_Id=trans.ItemID  WHERE trans.difference<0  AND Inv.isStockItem = 1 order by Item