{% extends "base.html" %}

{% block inner_header %}
	<style>
		label {
			width: 11em;
			float: left;
		}
	</style>
{% endblock %}

{% block title %}
	&raquo; Supplier Contracts &raquo;  {{read.bill.batch.contract.name}} &raquo;
	Batches &raquo; 
	{{read.bill.batch.reference}} &raquo; Bills &raquo; {{read.bill.id}} &raquo; 
 	Read {{read.id}} Edit
{% endblock %}

{% block nav %}
	<a href="/e/supplier_contracts">Supplier Contracts</a> &raquo; 
	<a
		href="/e/supplier_contracts/{{read.bill.batch.contract.id}}"
		>{{read.bill.batch.contract.name}}</a> &raquo; 
	<a
			href="/e/supplier_batches?supplier_contract_id={{read.bill.batch.contract.id}}"
			>Batches</a> &raquo; 
	<a
	 		href="/e/supplier_batches/{{read.bill.batch.id}}"
			>{{read.bill.batch.reference}}</a> &raquo; 
	<a href="/e/supplier_bills/{{read.bill.id}}">Bill {{read.bill.id}}</a> &raquo; 
 	Read {{read.id}} Edit
{% endblock %}

{% block content %}
	{% if request.values.confirm_delete %}

		<form method="post" action="/e/reads/{{read.id}}/edit">
			<fieldset>
				<legend>Are you sure you want to delete this register read?</legend>	
				<input type="submit" name="delete" value="Delete">
				<a href="/e/reads/{{read.id}}/edit">Cancel</a>
			</fieldset>
		</form>
	
	{% else %}
		<form action="/e/reads/{{read.id}}/edit" method="post">
			<fieldset>
				<legend>Update this read</legend>	
				<label>MPAN</label> {{input_text('mpan', read.mpan_str)}}
				<label>Coefficient</label> {{input_text('coefficient', read.coefficient)}}
				<label>Meter Serial Number</label> {{input_text('msn', read.msn)}}
				<label>Units</label> {{input_text('units', read.units_as_str())}}
				<label>TPR</label>
				<select name="tpr_id">
					{% for tpr in tprs %}
						{{input_option('tpr_id', tpr.id, tpr.code, read.tpr.id)}}
					{% endfor %}
				</select>
				<fieldset>
					<legend>Previous Read</legend>
					<fieldset>
						<label>Date</label>
						{{input_date('previous', read.previous_date)}}
					</fieldset>
					<label>Value</label> {{input_text('previous_value', read.previous_value)}}
					<label>Type</label>
					<select name="previous_type_id">
						{% for read_type in read_types %}
							{{input_option('previous_type_id', read_type.id, read_type.code + ' ' + read_type.description, read.previous_type.id)}}
						{% endfor %}
					</select>
				</fieldset>
				<fieldset>
					<legend>Present Read</legend>
					<fieldset>
						<label>Date</label> {{input_date('present', read.present_date)}}
					</fieldset>
					<label>Value</label> {{input_text('present_value', read.present_value)}}
					<label>Type</label>
					<select name="present_type_id">
						{% for read_type in read_types %}
							{{input_option('present_type_id', read_type.id, read_type.code + ' ' + read_type.description, read.present_type.id)}}
						{% endfor %}
					</select>
				</fieldset>
				<input type="submit" name="update" value="Update">
			</fieldset>
		</form>

		<form action="/e/reads/{{read.id}}/edit">
			<fieldset>
				<legend>Delete this read</legend>	
				<input name="confirm_delete" type="submit" value="Delete">
			</fieldset>
		</form>
	{% endif %}
{% endblock %}
