{% extends "base.html" %}

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

{% block nav %}
	<a href="/e/mop_contracts">MOP Contracts</a> &raquo;
	<a
			href="/e/mop_contracts/{{bill.batch.contract.id}}"
			>{{bill.batch.contract.name}}</a> &raquo;
	<a
			href="/e/mop_batches?mop_contract_id={{bill.batch.contract.id}}"
			>Batches</a> &raquo;
	<a
			href="/e/mop_batches/{{bill.batch.id}}"
			>{{bill.batch.reference}}</a> &raquo;

	<a href="/e/mop_bills/{{bill.id}}">Bill {{bill.id}}</a> &raquo; Edit
{% endblock %}

{% block content %}

	{% if 'confirm_delete' in request.values %}

		<form method="post">
			<fieldset>
				<legend>Are you sure you want to delete this bill?</legend>	
				<input type="submit" name="delete" value="Delete">
				<a href="/e/mop_bills/{{bill.id}}/edit">Cancel</a>
			</fieldset>
		</form>
      
	{% else %}

		<p><a href="/e/supplies/{{bill.supply.id}}">Supply</a></p>

		<form method="post">
			<fieldset>
				<legend>Update This Bill</legend>
				<label>Reference</label> {{input_text('reference', bill.reference)}}
				<label>Account</label> {{input_text('account', bill.account)}}
				<fieldset>
					<legend>Issue Date</legend>
					{{input_date('issue', bill.issue_date)}}
				</fieldset>
								
				<fieldset>
					<legend>Start Date</legend>
					{{input_date('start', bill.start_date)}}
				</fieldset>
								
				<fieldset>
					<legend>Finish Date</legend>
						{{input_date('finish', bill.finish_date)}}
					</fieldset>
					<label>kWh</label> {{input_text('kwh', '' ~ bill.kwh)}}
					<label>Net</label> {{input_text('net', '' ~ bill.net)}}
					<label>VAT</label> {{input_text('vat', '' ~ bill.vat)}}
					<label>Gross</label> {{input_text('gross', '' ~ bill.gross)}}
					<label>Type</label>
					<select name="bill_type_id">
						{% for type in bill_types %}
							{{ input_option('type_id', type.id,
									type.code + ' ' + type.description, initial=bill.bill_type.id)}}
						{% endfor %}
					</select>
					<label>Breakdown</label>
					{{input_textarea('breakdown', bill.breakdown, 10, 80)}}
					<label>Example Breakdown</label>
					<pre>
{
  "raw-lines": [
    "'net-gbp', 'unrestricted-kwh', 'unrestricted-rate', 'unrestricted-gbp'",
    "'100', '1000', '0.1', '100'"],
  "unrestricted-kwh": 1000,
  "unrestricted-rate": 0.1,
  "unrestricted-gbp": 100
}
							</pre>
						</div>
					</div>
				<input type="submit" name="update" value="Update">
			</div>
		</fieldset>
		</form>

		<form>
			<fieldset>
				<legend>Delete This Bill</legend>	
				<input type="submit" name="confirm_delete" value="Delete">
			</fieldset>
		</form>

	{% endif %}

{% endblock %}
