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
app/db_mgr.py
... ... @@ -3,36 +3,38 @@ from app.models import db
3 3  
4 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 7 :return:
8 8 """
  9 + current_period_id = get_current_period()
9 10 sql_txt = """
10 11 select p.id, p.name, sum(tc.charge_rate) as total_charge
11 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 14 tc
14 15 on p.id = tc.project_id
15 16 group by p.id
16 17 order by total_charge desc;
17   - """
  18 + """.format(current_period_id)
18 19 all_projects = db.session.execute(sql_txt).fetchall()
19 20 return all_projects
20 21  
21 22  
22 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 26 :return:
26 27 """
  28 + current_period_id = get_current_period()
27 29 sql_txt = """
28 30 select a.id, a.firstname, a.secondname, sum(tc.charge_rate) as total_charge
29 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 33 tc
32 34 on a.id = tc.agent_id
33 35 group by a.id
34 36 order by total_charge desc;
35   - """
  37 + """.format(current_period_id)
36 38 all_agents = db.session.execute(sql_txt).fetchall()
37 39  
38 40 return all_agents
... ...