SELECT 'I' as Ind,inventory_item_id,(select item_name FROM $master_db.Sales_Inventory_Items where item_id = Inventory_Item_ID) as Item,SUM(Quantity) as Quantity FROM (SELECT Inventory_Item_ID,Quantity FROM $trans_db.Purchase_Order_Main main JOIN $trans_db.Purchase_Order_Details det ON main.Voucher_No = det.Voucher_No WHERE main.Voucher_Date <= str_to_date('$toDateTime','%Y-%m-%d %H:%i:%s') AND main.Voucher_Date >= str_to_date('$fromDateTime','%Y-%m-%d %H:%i:%s')) items GROUP BY Inventory_Item_ID order by 1