Query report from Attendance doctype

I wrote a sql query in query report for calculating total working hours, absent days, leave days for all the employees,from attendance doctype but when logged in as a respective user(eg:project head) he is able to visible the report of the all the employees. In order to filter the visibility(When logged in as respective user, he should able to see only the report of the employees under his departments) I tried to get the current user from frappe.session.user as a function which is defined in the script area of the query report.But when run the report It doesnt shows anything.

how it works ?
In query report , how query part and script part is connected?
How it is possible to view the report of the employees under their respective departments for the respective Users(Project Heads)