diff --git a/app/db_mgr.py b/app/db_mgr.py index 8b3dee0..87bb545 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -3,36 +3,38 @@ from app.models import db def projects(): """ - Build the list of all agents, with their charges summed up in one total + Build the list of all agents, with their charges for the current period :return: """ + current_period_id = get_current_period() sql_txt = """ select p.id, p.name, sum(tc.charge_rate) as total_charge from project as p left join - ( select c.project_id, c.charge_rate from charge c ) + ( select c.project_id, c.charge_rate from charge c where c.period_id = {}) tc on p.id = tc.project_id group by p.id order by total_charge desc; - """ + """.format(current_period_id) all_projects = db.session.execute(sql_txt).fetchall() return all_projects def agents(): """ - Build the list of all agents, with their charges summed up in one total + Build the list of all agents, with their charges for the current period :return: """ + current_period_id = get_current_period() sql_txt = """ select a.id, a.firstname, a.secondname, sum(tc.charge_rate) as total_charge from agent as a left join - ( select c.agent_id, c.charge_rate from charge c ) + ( select c.agent_id, c.charge_rate from charge c where c.period_id = {}) tc on a.id = tc.agent_id group by a.id order by total_charge desc; - """ + """.format(current_period_id) all_agents = db.session.execute(sql_txt).fetchall() return all_agents -- libgit2 0.21.2