SELECT 'I' as Ind, inventory_item_id as 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.Sales_Order_Main main  JOIN $trans_db.Sales_Order_Details det  ON main.Voucher_No = det.Voucher_No WHERE Delivery_Date <= str_to_date('$toDateTime','%Y-%m-%d %H:%i:%s') AND Delivery_Date >= str_to_date('$fromDateTime','%Y-%m-%d %H:%i:%s') AND VoucherStatus < 170 ) items GROUP BY Inventory_Item_ID