{% extends "base.html" %}

{% block title %}
	&raquo; MOP Contracts &raquo; {{batch.contract.name}} &raquo; Batches &raquo; 
 	{{batch.reference}}
{% endblock %}

{% block nav %}
	<a href="/e/mop_contracts">MOP Contracts</a> &raquo; 
	<a href="/e/mop_contracts/{{batch.contract.id}}">{{batch.contract.name}}</a>
	&raquo; 
	<a href="/e/mop_contracts/{{batch.contract.id}}/batches">Batches</a>
	&raquo; {{batch.reference}}
	[<a href="/e/mop_batches/{{batch.id}}/edit">edit</a>]
{% endblock %}

{% block content %}

	<table>
		<caption>Batch</caption>
		<tr>
			<th>Reference</th>
			<td>{{ batch.reference }}</td>
		</tr>
		<tr>
			<th>Description</th>
			<td>{{ batch.description }}</td>
		</tr>
		<tr>
			<th>Date Created</th>
			<td>{{batch.date_created|date_format(fmt='microsecond_res')}}</td>
		</tr>
		<tr>
			<th>Number Of Bills</th>
			<td>{{ bills|length }}</td>
		</tr>
		{% if batch_reports %}
			<tr>
				<th>Custom Reports</th>
				<td>
					<ul>
						{% for report in batch_reports %}
							<li>
								<a href="/local_reports/{{report.id}}/output?batch_id={{batch.id}}">{{report.name}}</a>
							</li>
						{% endfor %}
					</ul>
				</td>
			</tr>
		{% endif %}
	</table>

	<table>
		<caption>
			Billing Files [<a href="/e/mop_batches/{{batch.id}}/upload_file">upload</a>]
		</caption>
		<thead>
			<tr>
				<th>View</th>
				<th>Filename</th>
				<th>Upload Timestamp</th>
				<th>Parser Name</th>
			</tr>
		</thead>
		<tbody>
			{% for file in batch.files %}
				<tr>
					<td><a href="/e/mop_batch_files/{{file.id}}"/>View</td>
					<td>{{file.filename}}</td>
					<td>{{file.upload_timestamp|date_format}}</td>
					<td>{{file.parser_name}}</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>

	<table>
		<caption>Imports</caption>
		<thead>
			<th>View</th>
			<th>Id</th>
		</thead>
		<tbody>
			{% for id in importer_ids %}
				<tr>
					<td><a href="/e/mop_bill_imports/{{id}}">View</a></td>
					<td>{{id}}</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>

	<table>
		<caption>Previous Bill Checks</caption>
		<thead>
			<th>View</th>
			<th>Date Created</th>
			<th>Created By</th>
			<th>Title</th>
		</thead>
		<tbody>
			{% for report_run in report_runs %}
				<tr>
					<td><a href="/report_runs/{{report_run.id}}">View</a></td>
					<td>{{report_run.date_created|date_format}}</td>
					<td>{{report_run.creator}}</td>
					<td>{{report_run.title}}</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>

	<ul>
		<li><a href="/reports/111?batch_id={{batch.id}}">Check Bills</a></li>
		<li><a href="/reports/bills?batch_id={{batch.id}}/ods">Download Bills</a></li>
	</ul>

	<table class="sticky">
		<caption>Bills [<a href="/e/mop_batches/{{batch.id}}/add_bill">add</a>]</caption>
		<thead>
			<tr>
				<th>View</th>
				<th>Reference</th>
				<th>Supply</th>
				<th>Account</th>
				<th>Issue Date</th>
				<th>From</th>
				<th>To</th>
				<th>kWh</th>
				<th>Net</th>
				<th>VAT</th>
				<th>Gross</th>
				<th>Type</th>
			</tr>
		</thead>
		<tbody>
			{% for bill in bills %}
				<tr>
					<td><a href="/e/mop_bills/{{bill.id}}">View</a></td>
					<td>{{bill.reference}}</td>
					<td><a href="/e/supplies/{{bill.supply.id}}">supply</a></td>
					<td>{{ bill.account }}</td>
					<td>{{ bill.issue_date|date_format }}</td>
					<td>{{ bill.start_date|date_format }}</td>
					<td>{{ bill.finish_date|date_format }}</td>
					<td>{{ bill.kwh }}</td>
					<td>{{ bill.net }}</td>
					<td>{{ bill.vat }}</td>
					<td>{{ bill.gross }}</td>
					<td>
						<a href="/bill_types/{{bill.bill_type.id}}"
							title="{{bill.bill_type.description}}">{{bill.bill_type.code}}</a>
					</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>

{% endblock %}
