From d4d01c3b93439c2ceb4bd641a7825d759dfaf359 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Thu, 19 Aug 2021 10:07:53 +0200 Subject: [PATCH] Show total charge table in html page --- app/db_mgr.py | 16 ++++++++++++---- app/main/routes.py | 3 ++- app/main/templates/total_charge.html | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/db_mgr.py b/app/db_mgr.py index f40da9d..0f91e97 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -145,15 +145,23 @@ def charges_for_all_agents(): . , . , . , . , . , ..., . agent_n , agent_status, agent_bap, tot_c_1 , tot_c_2 , ..., tot_c_n """ - agents_sql = """select id, firstname, secondname from agent;""" + agents_sql = ''' + select agent.id, firstname, secondname, agent_status.name as status, agent_bap.name as bap + from agent + join agent_status on agent.status_id = agent_status.id + join agent_bap on agent.bap_id = agent_bap.id; + ''' + agents_res = db.session.execute(agents_sql) - headers = ['Nom', 'Statut'] + headers = ['Nom', 'Statut', 'Bap'] for (period_id, period_name) in get_periods(): headers.append(period_name) res_table = [headers] - for i, f, s in agents_res: + for i, f, s, st, b in agents_res: agent_id = i agent_name = f + " " + s + agent_status = st + bap_name = b totcharge_sql = """ select p.name, IFNULL(sum(charge_rate),0) from period p @@ -165,7 +173,7 @@ def charges_for_all_agents(): order by p.id; """.format(agent_id) tot_charge_res = db.session.execute(totcharge_sql) - agent_charge = [agent_name, 'statut'] + agent_charge = [agent_id, agent_name, agent_status, bap_name] for n, c in tot_charge_res: agent_charge.append(c) res_table.append(agent_charge) diff --git a/app/main/routes.py b/app/main/routes.py index cdddd1d..66a2298 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -97,7 +97,8 @@ def index(): @bp.route('/total_charge') @role_required('service') def total_charge(): - return render_template('total_charge.html', subtitle="Charge des agents") + return render_template('total_charge.html', subtitle="Charge des agents", + total_charges=db_mgr.charges_for_all_agents()) @bp.route('/services') diff --git a/app/main/templates/total_charge.html b/app/main/templates/total_charge.html index 039420e..49415fa 100644 --- a/app/main/templates/total_charge.html +++ b/app/main/templates/total_charge.html @@ -3,4 +3,36 @@ + + + + + {% for h in total_charges[0] %} + + {% endfor %} + + + + {% for h in total_charges[1:] %} + + + {% for i in h[2:] %} + {% if i is number %} + {% set unit = ' %' %} + {% if i == 0 %} + {% set cell_style = 'table-warning' %} + {% elif i <= 75 %} + {% set cell_style = 'table-info' %} + {% elif i <= 100 %} + {% set cell_style = 'table-success' %} + {% else %} + {% set cell_style = 'table-danger' %} + {% endif %} + {% endif %} + + {% endfor %} + + {% endfor %} + +
{{ h }}
{{ h[1] }}{{ i }}{{ unit }}
{% endblock %} -- libgit2 0.21.2