Commit 8ffdad81fdd868b13dc52a5936d8ac41143ef829

Authored by hitier
1 parent aec65e04

Show current period charge in projects and agents lists

Showing 1 changed file with 8 additions and 6 deletions   Show diff stats
@@ -3,36 +3,38 @@ from app.models import db @@ -3,36 +3,38 @@ from app.models import db
3 3
4 def projects(): 4 def projects():
5 """ 5 """
6 - Build the list of all agents, with their charges summed up in one total 6 + Build the list of all agents, with their charges for the current period
7 :return: 7 :return:
8 """ 8 """
  9 + current_period_id = get_current_period()
9 sql_txt = """ 10 sql_txt = """
10 select p.id, p.name, sum(tc.charge_rate) as total_charge 11 select p.id, p.name, sum(tc.charge_rate) as total_charge
11 from project as p left join 12 from project as p left join
12 - ( select c.project_id, c.charge_rate from charge c ) 13 + ( select c.project_id, c.charge_rate from charge c where c.period_id = {})
13 tc 14 tc
14 on p.id = tc.project_id 15 on p.id = tc.project_id
15 group by p.id 16 group by p.id
16 order by total_charge desc; 17 order by total_charge desc;
17 - """ 18 + """.format(current_period_id)
18 all_projects = db.session.execute(sql_txt).fetchall() 19 all_projects = db.session.execute(sql_txt).fetchall()
19 return all_projects 20 return all_projects
20 21
21 22
22 def agents(): 23 def agents():
23 """ 24 """
24 - Build the list of all agents, with their charges summed up in one total 25 + Build the list of all agents, with their charges for the current period
25 :return: 26 :return:
26 """ 27 """
  28 + current_period_id = get_current_period()
27 sql_txt = """ 29 sql_txt = """
28 select a.id, a.firstname, a.secondname, sum(tc.charge_rate) as total_charge 30 select a.id, a.firstname, a.secondname, sum(tc.charge_rate) as total_charge
29 from agent as a left join 31 from agent as a left join
30 - ( select c.agent_id, c.charge_rate from charge c ) 32 + ( select c.agent_id, c.charge_rate from charge c where c.period_id = {})
31 tc 33 tc
32 on a.id = tc.agent_id 34 on a.id = tc.agent_id
33 group by a.id 35 group by a.id
34 order by total_charge desc; 36 order by total_charge desc;
35 - """ 37 + """.format(current_period_id)
36 all_agents = db.session.execute(sql_txt).fetchall() 38 all_agents = db.session.execute(sql_txt).fetchall()
37 39
38 return all_agents 40 return all_agents