{% extends "base.html" %}

{% block title %}
	&raquo; Supplier Contracts &raquo; {{contract.name}}
{% endblock %}

{% block nav %}
	<a href="/e/supplier_contracts">Supplier Contracts</a> &raquo; {{contract.name}}
 	[<a href="/e/supplier_contracts/{{contract.id}}/edit">edit</a>]
{% endblock %}

{% block content %}
	<table>
		<caption>Supplier Contract</caption>	
		<tbody>
			<tr>
				<th>Name</th>
				<td>{{contract.name }}</td>
			</tr>
			<tr>
				<th>Supplier</th>
				<td>
					<a href="/e/parties/{{contract.party.id}}">{{contract.party.name}}</a>
				</td>
			</tr>
			<tr>
				<th>Start Date</th>
				<td>{{contract.start_rate_script.start_date|hh_format}}</td>
			</tr>
			<tr>
				<th>Finish Date</th>
				<td>{{contract.finish_rate_script.finish_date|hh_format}}</td>
			</tr>
		</tbody>
	</table>

	<table>
		<caption>
			Rate Scripts [<a href="/e/supplier_contracts/{{contract.id}}/add_rate_script"
			>add</a>]
		</caption>
		<thead>
			<tr>
				<th></th>
				<th>From</th>
				<th>To</th>
			</tr>
		</thead>
		<tbody>
			{% for rate_script in rate_scripts %}
				<tr>
					<td><a href="/e/supplier_rate_scripts/{{rate_script.id}}">view</a></td>
					<td>{{rate_script.start_date|hh_format}}</td>
					<td>{{rate_script.finish_date|hh_format}}</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>	

	<ul>
		<li>
			<a href="/e/supplier_contracts/{{contract.id}}/batches">Batches</a>
		</li>
		<li>
			<a href="/e/supplier_contracts/{{contract.id}}/issues">Issues</a>
		</li>
	</ul>

	<h2>CSV Downloads</h2>	

	<form action="/reports/87">
		<fieldset>
			<input type="hidden" name="supplier_contract_id" value="{{contract.id}}">
			<legend>Download Supply Level Virtual Bills</legend>
			<label>From</label> {{ input_date('start', month_start) }}
			<label>to</label> {{ input_date('finish', month_finish) }}
			<input type="submit" value="Download">
		</fieldset>
	</form>

	<form action="/reports/109">
		<fieldset>
			<input type="hidden" name="supplier_contract_id" value="{{contract.id}}">
			<legend>Download Displaced Virtual Bills</legend>
			<label>Months</label> <input name="months" value="1" maxlength="2" size="2">
			<label>Final Month</label> {{ input_date('finish', month_finish, 'month') }}
			<input type="submit" value="Download">
		</fieldset>
	</form>

	<form action="/reports/111" method="POST">
		<fieldset>
			<input type="hidden" name="contract_id" value="{{contract.id}}">
			<legend>Download Bill Check</legend>
			<label>From</label> {{input_date('start_date', month_start)}}
			<label>to</label> {{input_date('finish_date', month_finish)}}
			<label>MPAN Cores</label>
			{{input_textarea('mpan_cores', '', 5, 40, placeholder='One on each line, includes all if left blank')}}
			<input type="submit" value="Download">
		</fieldset>
	</form>

	<form action="/reports/missing_bills">
		<fieldset>
			<legend>Download Missing Bills</legend>
			<input type="hidden" name="contract_id" value="{{contract.id}}">
			
			<label>Months</label> <input name="months" value="1" maxlength="2" size="2">
			<label>Last Month</label> {{input_date('finish', month_finish, 'month')}}
			<input type="submit" value="Download">
		</fieldset>
	</form>

	{% if rate_script_example %}
			<h2>Elements</h2>
			<pre>{{rate_script_example}}</pre>
	{% endif %}

	<h2>Script</h2>	

	<pre>{{contract.charge_script}}</pre>

	<h2 id="properties">Properties</h2>	

	<pre>{{contract.properties}}</pre>

{% endblock %}
