{% extends "base.html" %}

{% block title %}
	&raquo; Report Runs &raquo; {{row.report_run.id}} &raquo; Row {{row.id}}
{% endblock %}

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

{% block content %}
	{% set values = row.data['values'] %}
	{% if row.report_run.name == 'bill_check' %}
		<table>
			<caption>Bill Check</caption>	
			<thead>
				<tr>
					<th rowspan="2">Batch</th>
					<th colspan="8">Bill</th>
					<th colspan="2">MPAN Core</th>
					<th colspan="2">Site</th>
				</tr>
				<tr>
					<th>Reference</th>
					<th>Type</th>
					<th>kWh</th>
					<th>Net GBP</th>
					<th>VAT GBP</th>
					<th>Gross GBP</th>
					<th>Start</th>
					<th>Finish</th>
					<th>Import</th>
					<th>Export</th>
					<th>Code</th>
					<th>Name</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>
						{% if values.batch_id != None %}
							<a href="/e/supplier_batches/{{values.batch_id}}">{{
								values['batch']}}</a>
						{% endif %}
					</td>
					<td>
						{% if values.bill_id != None %}
							<a href="/e/supplier_bills/{{values.bill_id}}">{{
								values['bill-reference']}}</a>
						{% endif %}
					</td>
					<td>{{values['bill-type']}}</td>
					<td>{{values['bill-kwh']}}</td>
					<td>{{values['bill-net-gbp']}}</td>
					<td>{{values['bill-vat-gbp']}}</td>
					<td>{{values['bill-gross-gbp']}}</td>
					<td>{{values['bill-start-date']}}</td>
					<td>{{values['bill-finish-date']}}</td>
					<td>
						{% if values['imp-mpan-core'] != None %}
						<a href="/e/supplies/{{values.supply_id}}">{{
							values['imp-mpan-core']}}</a>
						{% endif %}
					</td>
					<td>
						{% if values['exp-mpan-core'] != None %}
							<a href="/e/supplies/{{values.supply_id}}">{{
								values['exp-mpan-core']}}</a>
						{% endif %}
					</td>
					<td>
						{% if values.site_id != None %}
							<a href="/sites/{{values.site_id}}">{{
								values['site-code']}}</a>
						{% endif %}
					</td>
					<td>{{values['site-name']}}</td>
				</tr>
			</tbody>
		</table>

		<table>
			<caption>Covered</caption>
			<thead>
				<tr>
					<th>From</th>
					<th>To</th>
					<th>Bills</th>
					<th>Metered kWh</th>
					<th>Net GBP</th>
					<th>Virtual Net GBP</th>
					<th>Difference GBP</th>
					<th>Problem</th>
					<th>Virtual Problem</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>{{values['covered-from']}}</td>
					<td>{{values['covered-to']}}</td>
					<td>
						<ul>
							{% for bill_id in values['covered-bills'] %}
								<li>
									<a href="/e/supplier_bills/{{bill_id}}">{{bill_id}}</a>
									{% if bill_id == values.bill_id %}
										(This bill)
									{% endif %}
								</li>
							{% endfor %}
						</ul>
					</td>
					<td>{{values['metered-kwh']}}</td>
					<td>{{values['covered-net-gbp']}}</td>
					<td>{{values['virtual-net-gbp']}}</td>
					<td>{{values['difference-net-gbp']}}</td>
					<td>{{values['covered-problem']}}</td>
					<td>{{values['virtual-problem']}}</td>
				</tr>
			</tbody>
		</table>

		{% for table in tables %}
			<table>
				<caption>{{table.name}}</caption>
				<thead>
					<tr>
						{% for title in table.titles %}
							<th>{{title}}</th>
						{% endfor %}
					</tr>
				</thead>
				<tbody>
					<tr>
						{% for v in table['values'] %}
							<td>{{v}}</th>
						{% endfor %}
					</tr>
				</tbody>
			</table>
		{% endfor %}

		<h3>Raw</h3>

		<pre>{{raw_data}}</pre>

	{% else %}
		<table>
			<caption>Report Run Row</caption>	
			<tbody>
				{% for title in row.data.titles %}
					<tr>
						<th>{{title}}</th>
						<td>{{row.data['values'][title]}}</td>
					</tr>
				{% endfor %}
			</tbody>
		</table>
	{% endif %}
{% endblock %}
