Commit 0d6506cbbf6e000e4d76f5d3298de7c92a956944

Authored by hitier
1 parent 709006af

New project_charges to fill project's charges table

app/db_mgr.py
... ... @@ -18,6 +18,7 @@ def projects():
18 18 all_projects = db.session.execute(sql_txt).fetchall()
19 19 return all_projects
20 20  
  21 +
21 22 def agents():
22 23 """
23 24 Build the list of all agents, with their charges summed up in one total
... ... @@ -37,6 +38,41 @@ def agents():
37 38 return all_agents
38 39  
39 40  
  41 +def charges_by_project(project_id):
  42 + """
  43 + Build the flatten list of charges for one project, period by period
  44 + :param project_id:
  45 + :return:
  46 + """
  47 +
  48 + req_sql = f"""
  49 + select p.name as period_name,
  50 + a.firstname ||" "|| a.secondname as agent_name,
  51 + s.name as service_name,
  52 + c2.name as capacity_name,
  53 + c.charge_rate as charge_rate
  54 + from charge as c
  55 + join period p on c.period_id = p.id
  56 + join project p2 on c.project_id = p2.id
  57 + join service s on c.service_id = s.id
  58 + join agent a on a.id = c.agent_id
  59 + join capacity c2 on c2.id = c.capacity_id
  60 + where project_id = {project_id}
  61 + order by c.period_id
  62 + """
  63 + print(req_sql)
  64 + req_res = db.session.execute(req_sql)
  65 + results = list(req_res)
  66 + # Remove comma
  67 + nocomma_results = []
  68 + for line in results:
  69 + nocomma_line = [str(cell) for cell in line]
  70 + nocomma_results.append(nocomma_line)
  71 + headers = ["Period", "Agent", "Service", "Capacity", "Charge"]
  72 + nocomma_results.insert(0, headers)
  73 + return nocomma_results
  74 +
  75 +
40 76 def charges_by_agent_tabled(agent_id):
41 77 """
42 78 Build the flatten list of charges for one agent, period by period
... ...
app/main/routes.py
... ... @@ -98,9 +98,10 @@ def charge_add():
98 98 def project(project_id):
99 99 # TODO: am i the project manager ?
100 100 this_project = Project.query.get(int(project_id))
101   - # charges_table=db_mgr.charges_by_agent_tabled(agent_id)
  101 + charges_table = db_mgr.charges_by_project(project_id)
102 102 return render_template('project.html',
103 103 project=this_project,
  104 + charges=charges_table,
104 105 subtitle="{}".format(this_project.name))
105 106  
106 107 @bp.route('/agent/<agent_id>')
... ...
app/main/templates/project.html
1 1 {% extends "base_page.html" %}
2 2  
3 3 {% block more_heads %}
  4 +<link href="{{ url_for('main.static', filename='css/style.css') }}" rel="stylesheet" type="text/css"/>
4 5 {% endblock %}
5 6  
6 7 {% block content %}
  8 +<table id="charge_table">
  9 + <thead>
  10 + <tr>
  11 + {% for header in charges[0] %}
  12 + <td>{{header}}</td>
  13 + {% endfor %}
  14 + </tr>
  15 + </thead>
  16 + <tbody>
  17 + {% for line in charges[1:] %}
  18 + <tr>
  19 + {% for cell in line %}
  20 + <td>{{cell}}</td>
  21 + {% endfor %}
  22 + </tr>
  23 + {% endfor %}
  24 + </tbody>
  25 +</table>
7 26 {% endblock %}
8 27  
9 28 {% block more_scripts %}
... ...