diff --git a/app/db_mgr.py b/app/db_mgr.py index f55f7d0..f3c801b 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -18,6 +18,7 @@ def projects(): all_projects = db.session.execute(sql_txt).fetchall() return all_projects + def agents(): """ Build the list of all agents, with their charges summed up in one total @@ -37,6 +38,41 @@ def agents(): return all_agents +def charges_by_project(project_id): + """ + Build the flatten list of charges for one project, period by period + :param project_id: + :return: + """ + + req_sql = f""" + select p.name as period_name, + a.firstname ||" "|| a.secondname as agent_name, + s.name as service_name, + c2.name as capacity_name, + c.charge_rate as charge_rate + from charge as c + join period p on c.period_id = p.id + join project p2 on c.project_id = p2.id + join service s on c.service_id = s.id + join agent a on a.id = c.agent_id + join capacity c2 on c2.id = c.capacity_id + where project_id = {project_id} + order by c.period_id + """ + print(req_sql) + req_res = db.session.execute(req_sql) + results = list(req_res) + # Remove comma + nocomma_results = [] + for line in results: + nocomma_line = [str(cell) for cell in line] + nocomma_results.append(nocomma_line) + headers = ["Period", "Agent", "Service", "Capacity", "Charge"] + nocomma_results.insert(0, headers) + return nocomma_results + + def charges_by_agent_tabled(agent_id): """ Build the flatten list of charges for one agent, period by period diff --git a/app/main/routes.py b/app/main/routes.py index 4599b18..f40c5b9 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -98,9 +98,10 @@ def charge_add(): def project(project_id): # TODO: am i the project manager ? this_project = Project.query.get(int(project_id)) - # charges_table=db_mgr.charges_by_agent_tabled(agent_id) + charges_table = db_mgr.charges_by_project(project_id) return render_template('project.html', project=this_project, + charges=charges_table, subtitle="{}".format(this_project.name)) @bp.route('/agent/') diff --git a/app/main/templates/project.html b/app/main/templates/project.html index ec107ed..1c50e76 100644 --- a/app/main/templates/project.html +++ b/app/main/templates/project.html @@ -1,9 +1,28 @@ {% extends "base_page.html" %} {% block more_heads %} + {% endblock %} {% block content %} + + + + {% for header in charges[0] %} + + {% endfor %} + + + + {% for line in charges[1:] %} + + {% for cell in line %} + + {% endfor %} + + {% endfor %} + +
{{header}}
{{cell}}
{% endblock %} {% block more_scripts %} -- libgit2 0.21.2