{% 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 %}
	&raquo; <a href="/supplier_contracts">Supplier Contracts</a> &raquo; 
	<a
		href="/supplier_contracts/{{read.bill.batch.contract.id}}"
		>{{read.bill.batch.contract.name}}</a> &raquo; 
	<a
			href="/supplier_batches?supplier_contract_id={{read.bill.batch.contract.id}}"
			>Batches</a> &raquo; 
	<a
	 		href="/supplier_batches/{{read.bill.batch.id}}"
			>{{read.bill.batch.reference}}</a> &raquo; 
	<a href="/supplier_bills/{{read.bill.id}}">Bill {{read.bill.id}}</a> &raquo; 
 	Read {{read.id}} Edit
{% endblock %}

{% block content %}
	{% if request.values.confirm_delete %}
		<!-- Layer Section -->
		<div class="layer-section">
			<!-- Section Header -->
			<div class="section-header">
				<h2>Are you sure you want to delete this register read?</h2>	
			</div>
			<!-- End Section Header -->
			<!-- Section Content -->
			<div class="section-content">
				<div class="section-data">
					<form method="post" action="/reads/{{read.id}}/edit">
						<fieldset>
							<input type="submit" name="delete" value="Delete">
							<a href="/reads/{{read.id}}/edit">Cancel</a>
						</fieldset>
					</form>
				</div>
			</div>
			<!-- End Section Content -->
		</div>
		<!-- End Layer Section -->
	
	{% else %}
		<!-- Layer Section -->
		<div class="layer-section">
			<!-- Section Header -->
			<div class="section-header">
				<h2>Update this read</h2>	
			</div>
			<!-- End Section Header -->
			<!-- Section Content -->
			<div class="section-content">
				<div class="section-data">
					<form action="/reads/{{read.id}}/edit" method="post">
						<fieldset>
							<div class="standardForm">
								<div class="row">
									<div class="col-sm-4">
										<label>MPAN</label> 
										{{input_text('mpan', read.mpan_str)}}
									</div>
									<div class="col-sm-4">
										<label>Coefficient</label>
										{{input_text('coefficient', read.coefficient)}}
									</div>
									<div class="col-sm-4">
										<label>Meter Serial Number</label>
										{{input_text('msn', read.msn)}}
									</div>
								</div>
								<div class="row">
									<div class="col-sm-4">
										<label>Units</label>
										{{input_text('units', read.units_as_str())}}
									</div>
									<div class="col-sm-4">
										<label>TPR</label>
										<select name="tpr_id">
											{% for tpr in tprs %}
												{{input_option('tpr_id', tpr.id, tpr.code, read.tpr.id)}}
											{% endfor %}
										</select>
									</div>
									<div class="col-sm-4">
									</div>
								</div>
								<fieldset>
									<legend>Previous Read</legend>
									<fieldset>
											<div class="standardForm textWidthAuto">
												<label>Date</label>
												{{input_date('previous', read.previous_date)}}
										</div>
									</fieldset>
									<div class="standardForm">
										<div class="row">
											<div class="col-sm-6">
												<label>Value</label>
												{{input_text('previous_value', read.previous_value)}}
											</div>
											<div class="col-sm-6">
												<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>
											</div>
										</div>
									</div>
								</fieldset>
								<fieldset>
									<legend>Present Read</legend>
									<fieldset>
										<div class="standardForm textWidthAuto">
											<label>Date</label>
											{{input_date('present', read.present_date)}}
										</div>
									</fieldset>
									<div class="standardForm">
										<div class="row">
											<div class="col-sm-6">
												<label>Value</label>
												{{input_text('present_value', read.present_value)}}
											</div>
										<div class="col-sm-6">
											<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>
										</div>
									</div>
								</fieldset>
								<input type="submit" name="update" value="Update">
							</fieldset>
						</form>
					</div>
				</div>
			<!-- End Section Content -->
		</div>
		<!-- End Layer Section -->
        
		<!-- Layer Section -->
		<div class="layer-section">
			<!-- Section Header -->
			<div class="section-header">
				<h2>Delete this read</h2>	
			</div>
			<!-- End Section Header -->
			<!-- Section Content -->
			<div class="section-content">
				<div class="section-data">
					<div class="standardForm">
						<form action="/reads/{{read.id}}/edit">
							<fieldset>
								<input name="confirm_delete" type="submit" value="Delete">
							</fieldset>
						</form>
					</div>
				</div>
			</div>
			<!-- End Section Content -->
		</div>
		<!-- End Layer Section -->

	{% endif %}
{% endblock %}
