{% extends "base.html" %}

{% block title %}
	&raquo; Report Runs &raquo; {{run.id}}
{% endblock %}

{% block nav %}
	<a href="/report_runs">Report Runs</a> &raquo; {{run.id}}
{% endblock %}

{% block content %}
	{% if request.method == "GET" and request.values.delete %}
		<div class="layer-section">
			<div class="section-header">
				<h2>
					Are you sure you want to delete this report run?
				</h2>
			</div>
			<div class="section-content">
				<div class="section-data">
					<div class="standardForm textWidthAuto">
						<form method="post" action="/report_runs/{{run.id}}">
							<fieldset>
								<input type="submit" name="delete" value="delete"> 
								<a href="/report_runs/{{run.id}}">Cancel</a>
							</fieldset>
						</form>
					</div>
				</div>
			</div>
		</div>
	{% else %}
		<!-- Layer Section -->
		<div class="layer-section">
			<!-- Section Header -->
			<div class="section-header">
				<h2>ECOES Comparison</h2>
			</div>
			<!-- End Section Header -->
			<!-- Section Content -->
			<div class="section-content">
				<div class="section-data">
					<table class="etheling">
						<thead>
							<tr>
								<th>Date Created</th>
								<th>Created By</th>
								<th>State</th>
								<th>Number Of Rows</th>
								<th>Delete</th>
								<th>Download Spreadsheet</th>
								<th>Re-run Report</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>{{run.date_created|hh_format}}</td>
								<td>{{run.creator}}</td>
								<td>{{run.state}}</td>
								<td>{{rows|length}}</td>
								<td>
									<form action="/report_runs/{{run.id}}">
										<fieldset style="border: none;">
											<input type="submit" name="delete" value="Delete">
										</fieldset>
									</form>
								</td>
								<td>
									<a href="/report_runs/{{run.id}}/spreadsheet">Download</a>
								</td>
								<td>
									<a href="/reports/ecoes_comparison">Re-run</a>
								</td>
							</tr>
						</tbody>
					</table>
					<br>
					{% for row in rows %}
						{% set vals = row.data['values'] %}
						<table class="etheling">
							<caption>{{vals['mpan_core_no_spaces']}}</caption>
							<thead>
								<tr>
									<th rowspan="2">Mpan Core</th>
									<th rowspan="2">Supplier Contract</th>
									<th rowspan="2">Edit Era</th>
									<th rowspan="2">Edit Supply</th>
									{% for diff in vals['diffs'] %}
										<th colspan="2">{{diff}}</th>
									{% endfor %}
									<th rowspan="2">Problem</th>
								</tr>
								<tr>
									{% for diff in vals['diffs'] %}
										<th>Chellow</th>
										<th>ECOES</th>
									{% endfor %}
								</tr>
							</thead>
							<tbody>
							<tr>
								<td>
									<a href="/supplies/{{vals['chellow_supply_id']}}">{{vals['mpan_core']}}</a>
								</td>
								<td>
									<a href="/supplier_contracts/{{vals['chellow_supplier_contract_id']}}">{{vals['chellow_supplier_contract_name']}}</a>
								</td>
								<td>[<a href="/eras/{{vals['chellow_era_id']}}/edit">edit</a>]</td>
								<td>
									[<a href="/supplies/{{vals['chellow_supply_id']}}/edit">edit</a>]
								</td>
								{% for diff in vals['diffs'] %}
									<td>{{vals['chellow_' + diff]}}</td>
									<td>{{vals['ecoes_' + diff]}}
										{% if diff == 'msn' %}
											- {{vals['ecoes_msn_install_date']}}
										{% elif diff == 'supplier' %}
											- {{vals['ecoes_registration_from']}}
										{% elif diff == 'mtc' %}
											- {{vals['ecoes_mtc_date']}}
										{% elif diff == 'llfc' %}
											- {{vals['ecoes_llfc_from']}}
										{% elif diff == 'mop' %}
											- {{vals['ecoes_mop_appoint_date']}}
										{% elif diff == 'gsp_group' %}
											- {{vals['ecoes_gsp_effective_from']}}
										{% endif %}
									</td>
								{% endfor %}
								<td>{{vals['problem']}}</td>
							</tr>
							</tbody>
						</table>
					{% endfor %}
				</div>
				
			</div>
			<!-- End Section Content -->
		</div>
		<!-- End Layer Section -->
	{% endif %}
{% endblock %}
