{% extends "base.html" %}

{% block title %}
	Gas Contracts &raquo; {{g_read.g_bill.g_batch.g_contract.name}} &raquo;
 	Batches &raquo; {{g_read.g_bill.g_batch.reference}} &raquo; Bills &raquo;
 	{{g_read.g_bill.id}} &raquo; Read {{g_read.id}} Edit
{% endblock %}

{% block nav %}
	<a href="/g/supplier_contracts">Gas Supplier Contracts</a> &raquo;
	<a
			href="/g/contracts/{{g_read.g_bill.g_batch.g_contract.id}}"
			>{{g_read.g_bill.g_batch.g_contract.name}}</a> &raquo;
	<a
			href="/g/batches?g_contract_id={{g_read.g_bill.g_batch.g_contract.id}}"
			>Batches</a> &raquo;
	<a
	 		href="/g/batches/{{g_read.g_bill.g_batch.id}}"
			>{{g_read.g_bill.g_batch.reference}}</a> &raquo;
	<a href="/g/bills/{{g_read.g_bill.id}}">Bill {{g_read.g_bill.id}}</a>
 	&raquo; Read {{g_read.id}} Edit
{% endblock %}

{% block content %}
	{% if request.values.confirm_delete %}
		<form method="post" action="/g/reads/{{g_read.id}}/edit">
			<fieldset>
				<legend>
					Are you sure you want to delete this register read?
				</legend>
				<input type="submit" name="delete" value="Delete">
			</fieldset>
		</form>
		<p><a href="/g/reads/{{g_read.id}}/edit">Cancel</a></p>
	{% else %}
		<form action="/g/reads/{{g_read.id}}/edit" method="post">
			<fieldset>
				<legend>Update this read</legend>
				<label>Meter Serial Number</label>
				{{input_text('msn', g_read.msn)}}
				<label>Unit</label>
				<select name="g_unit_id">
					{% for g_unit in g_units %}
						{{input_option(
							'g_unit_id', g_unit.id, g_unit.code, g_read.g_unit.id)}}
					{% endfor %}
				</select>
				<label>Correction Factor</label>
				{{input_text('correction_factor', g_read.correction_factor)}}
				<label>Calorific Value</label>
				{{input_text('calorific_value', g_read.calorific_value)}}
				<fieldset>
					<legend>Previous Read</legend>
					<fieldset>
						<legend>Date</legend>
						{{input_date('prev_date', g_read.prev_date)}}
					</fieldset>
					<label>Value</label>
					{{input_text('prev_value', g_read.prev_value)}}
					<label>Type</label>
					<select name="prev_type_id">
						{% for g_read_type in g_read_types %}
							{{
								input_option(
									'prev_type_id', g_read_type.id,
									g_read_type.code + ' ' + g_read_type.description,
									g_read.prev_type.id)}}
						{% endfor %}
					</select>
				</fieldset>
				<fieldset>
					<legend>Present Read</legend>
					<fieldset>
						<legend>Date</legend>
						{{input_date('pres_date', g_read.pres_date)}}
					</fieldset>
					<label>Value</label>
					{{input_text('pres_value', g_read.pres_value)}}
					<label>Type</label>
					<select name="pres_type_id">
						{% for g_read_type in g_read_types %}
							{{
								input_option(
									'pres_type_id', g_read_type.id,
									g_read_type.code + ' ' + g_read_type.description,
									g_read.pres_type.id)}}
						{% endfor %}
					</select>
				</fieldset>
				<input type="submit" name="update" value="Update">
			</fieldset>
		</form>

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