Commit d4d01c3b93439c2ceb4bd641a7825d759dfaf359

Authored by hitier
1 parent 72049262

Show total charge table in html page

app/db_mgr.py
... ... @@ -145,15 +145,23 @@ def charges_for_all_agents():
145 145 . , . , . , . , . , ..., .
146 146 agent_n , agent_status, agent_bap, tot_c_1 , tot_c_2 , ..., tot_c_n
147 147 """
148   - agents_sql = """select id, firstname, secondname from agent;"""
  148 + agents_sql = '''
  149 + select agent.id, firstname, secondname, agent_status.name as status, agent_bap.name as bap
  150 + from agent
  151 + join agent_status on agent.status_id = agent_status.id
  152 + join agent_bap on agent.bap_id = agent_bap.id;
  153 + '''
  154 +
149 155 agents_res = db.session.execute(agents_sql)
150   - headers = ['Nom', 'Statut']
  156 + headers = ['Nom', 'Statut', 'Bap']
151 157 for (period_id, period_name) in get_periods():
152 158 headers.append(period_name)
153 159 res_table = [headers]
154   - for i, f, s in agents_res:
  160 + for i, f, s, st, b in agents_res:
155 161 agent_id = i
156 162 agent_name = f + " " + s
  163 + agent_status = st
  164 + bap_name = b
157 165 totcharge_sql = """
158 166 select p.name, IFNULL(sum(charge_rate),0)
159 167 from period p
... ... @@ -165,7 +173,7 @@ def charges_for_all_agents():
165 173 order by p.id;
166 174 """.format(agent_id)
167 175 tot_charge_res = db.session.execute(totcharge_sql)
168   - agent_charge = [agent_name, 'statut']
  176 + agent_charge = [agent_id, agent_name, agent_status, bap_name]
169 177 for n, c in tot_charge_res:
170 178 agent_charge.append(c)
171 179 res_table.append(agent_charge)
... ...
app/main/routes.py
... ... @@ -97,7 +97,8 @@ def index():
97 97 @bp.route('/total_charge')
98 98 @role_required('service')
99 99 def total_charge():
100   - return render_template('total_charge.html', subtitle="Charge des agents")
  100 + return render_template('total_charge.html', subtitle="Charge des agents",
  101 + total_charges=db_mgr.charges_for_all_agents())
101 102  
102 103  
103 104 @bp.route('/services')
... ...
app/main/templates/total_charge.html
... ... @@ -3,4 +3,36 @@
3 3  
4 4 <!-- Invisible span to define wich ul and a in the navbar are actived -->
5 5 <span id="nav_actived" style="display: none">cds,total_charge</span>
  6 +
  7 + <table class="table_datatables table table-hover">
  8 + <thead>
  9 + <tr>
  10 + {% for h in total_charges[0] %}
  11 + <th scope="col">{{ h }}</th>
  12 + {% endfor %}
  13 + </tr>
  14 + </thead>
  15 + <tbody>
  16 + {% for h in total_charges[1:] %}
  17 + <tr>
  18 + <td><a href="{{ url_for('main.agent', agent_id=h[0]) }}">{{ h[1] }}</a></td>
  19 + {% for i in h[2:] %}
  20 + {% if i is number %}
  21 + {% set unit = ' %' %}
  22 + {% if i == 0 %}
  23 + {% set cell_style = 'table-warning' %}
  24 + {% elif i <= 75 %}
  25 + {% set cell_style = 'table-info' %}
  26 + {% elif i <= 100 %}
  27 + {% set cell_style = 'table-success' %}
  28 + {% else %}
  29 + {% set cell_style = 'table-danger' %}
  30 + {% endif %}
  31 + {% endif %}
  32 + <td class={{ cell_style }}>{{ i }}{{ unit }}</td>
  33 + {% endfor %}
  34 + </tr>
  35 + {% endfor %}
  36 + </tbody>
  37 + </table>
6 38 {% endblock %}
... ...