{% extends "base.html" %}

{% block title %}
	&raquo; Supplier Contracts &raquo; {{batch.contract.name}} &raquo; Batches
	&raquo; {{batch.reference}} &raquo; Upload Bill File
{% endblock %}

{% block nav %}
	<a href="/e/supplier_contracts">Supplier Contracts</a> &raquo; 
	<a href="/e/supplier_contracts/{{batch.contract.id}}">{{batch.contract.name}}</a> &raquo; 
	<a href="/e/supplier_batches/{{batch.contract.id}}/batches">Batches</a> &raquo; 
	<a href="/e/supplier_batches/{{batch.id}}">{{batch.reference}}</a> &raquo; Upload Bill File
{% endblock %}

{% block content %}
	<form enctype="multipart/form-data" method="post"
			action="/e/supplier_batches/{{batch.id}}/upload_file">
		<fieldset>
			<legend>Upload Bill File</legend>	
			<label>File</label>
			<input type="file" name="import_file" value="{{request.values.import_file}}">
			<label>Parser</label>
			<select name="parser_name">
				{% for parser_name in parser_names  %}
					{{input_option(
						'bill_parser_name', parser_name, parser_name,
						initial=default_parser_name)}}
				{% endfor %}
			</select>
			<input type="submit" value="Upload">
		</fieldset>
	</form>

	<table>
		<caption>The '.csv' Format</caption>
		<tbody>
			<tr>
				<td># Bill Type (N - Normal, W - Withdrawn or F -Final)</td>
				<td>Account Reference</td>
				<td>MPAN Core</td>
				<td>Invoice Reference</td>
				<td>Issue Date (YYYY-mm-dd HH:MM)</td>
				<td>Start Date (YYYY-mm-dd HH:MM)</td>
				<td>Finish Date (YYYY-mm-dd HH:MM)</td>
				<td>kWh</td>
				<td>Net</td>
				<td>VAT</td>
				<td>Gross</td>
				<td>Breakdown</td>
				<td>read</td>
				<td>R1 Meter Serial Number</td>
				<td>R1 MPAN</td>
				<td>R1 Coefficient</td>
				<td>R1 Units (kWh, kW, kVA or kVArh)</td>
				<td>R1 TPR (Blank if kW or kVA)</td>
				<td>R1 Previous Read Date</td>
				<td>R1 Previous Read Value</td>
				<td>R1 Previous Read Type</td>
				<td>R1 Present Read Date</td>
				<td>R1 Present Read Value</td>
				<td>R1 Present Read Type</td>
				<td>element</td>
				<td>Name</td>
				<td>Start Date (YYY-mm-dd HH:MM)</td>
				<td>Finish Date (YYY-mm-dd HH:MM)</td>
				<td>Net</td>
				<td>Breakdown</td>
			</tr>
		</tbody>
	</table>

	<p>
		The columns after 'read' can be repeated for each register, or can be left out
	 	entirely if the bill doesn't have any readings associated with it. The same applies to the 
		columns after 'element'. Here's an example:
	</p>

	<table>
		<caption>Example CSV File</caption>
		<tbody>
			<tr>
				<td>N</td>
				<td>JJih988</td>
				<td>22 7338 1192 184</td>
				<td>jhl449</td>
				<td>2025-07-13 03:26</td>
				<td>2025-06-01 00:00</td>
				<td>2025-06-30 23:30</td>
				<td>288</td>
				<td>13.76</td>
				<td>1.56</td>
				<td>15.82</td>
				<td>{}</td>
				<td>element</td>
				<td>nrg</td>
				<td>2025-06-01 00:00</td>
				<td>2025-06-30 23:30</td>
				<td>5.88</td>
				<td>{"kwh": 55, 'rate': 0.05}</td>
				<td>element</td>
				<td>ccl</td>
				<td>2025-06-01 00:00</td>
				<td>2025-06-30 23:30</td>
				<td>0.92</td>
				<td>{"kwh": 55, 'rate': 0.075}</td>
			</tr>
			<tr>
				<td>N</td>
				<td>jhgjfj8i</td>
				<td>22 9981 4881 118</td>
				<td>khghl</td>
				<td>2025-07-13 03:26</td>
				<td>2025-06-01 00:00</td>
				<td>2025-06-30 23:30</td>
				<td>8892</td>
				<td>885.71</td>
				<td>32.87</td>
				<td>15.82</td>
				<td>{}</td>
				<td>element</td>
				<td>day</td>
				<td>2025-06-01 00:00</td>
				<td>2025-06-30 23:30</td>
				<td>881.77</td>
				<td>{"kwh": 81, 'rate': 0.12}</td>
				<td>read</td>
				<td>xxiE90</td>
				<td>22 9981 4881 118</td>
				<td>1</td>
				<td>kWh</td>
				<td>00041</td>
				<td>2025-05-31 00:00</td>
				<td>276766</td>
				<td>A</td>
				<td>2025-06-30 00:00</td>
				<td>277298</td>
				<td>C</td>
				<td>element</td>
				<td>aahedc</td>
				<td>2025-06-01 00:00</td>
				<td>2025-06-30 23:30</td>
				<td>88</td>
				<td>{"kwh": 7754, 'rate': 0.0511}</td>
			</tr>
		</tbody>
	</table>
	<table>
		<caption>
			Mapping Between Read Types
		</caption>
		<thead>
			<tr>
				<th colspan="2">Chellow</th>
				<th colspan="2">
					<a href="https://www.electralink.co.uk/items">J0171</a>
				</th>
				<th colspan="2">SSE EDI</th>
				<th colspan="2">BGB EDI</th>
				<th colspan="2">Haven CSV</th>
				<th colspan="2">Haven EDI</th>
			</tr>
			<tr>
				<th>Code</th>
				<th>Description</th>
				<th>Code</th>
				<th>Description</th>
				<th>Code</th>
				<th>Description</th>
				<th>Code</th>
				<th>Description</th>
				<th>Code</th>
				<th>Description</th>
				<th>Code</th>
				<th>Description</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>A</td>
				<td>Actual Change of Supplier Read</td>
				<td>A</td>
				<td>Actual Change of Supplier Read</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>A</td>
				<td>Actual Read</td>
				<td>00</td>
				<td>Actual Read</td>
			</tr>
			<tr>
				<td>C</td>
				<td>Customer</td>
				<td>C</td>
				<td>Customer own read</td>
				<td>04</td>
				<td>Customer's Own Reading</td>
				<td>04</td>
				<td>Customer's own reading</td>
				<td>C</td>
				<td>Customer's Own Read</td>
				<td>04</td>
				<td>Customer's Own Read</td>
			</tr>
			<tr>
				<td>CP</td>
				<td>Computer</td>
				<td></td>
				<td></td>
				<td>05</td>
				<td>Computer Reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>D</td>
				<td>
					Deemed (Settlement Registers) or Estimated (Non-Settlement
					Registers)
				</td>
				<td>D</td>
				<td>
					Deemed (Settlement Registers) or Estimated (Non-Settlement
					Registers)
				</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>D</td>
				<td>Deemed Read</td>
				<td>02</td>
				<td>Deemed Read</td>
			</tr>
			<tr>
				<td>E</td>
				<td>Estimated</td>
				<td></td>
				<td></td>
				<td>02</td>
				<td>Estimated (Computer) Reading</td>
				<td>02</td>
				<td>Estimated (computer)</td>
				<td>E</td>
				<td>Estimated</td>
				<td>02</td>
				<td>Estimated</td>
			</tr>
			<tr>
				<td>E3</td>
				<td>Estimated 3rd Party</td>
				<td></td>
				<td></td>
				<td>11</td>
				<td>Third Party Estimated (Computer) Reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>EM</td>
				<td>Estimated Manual</td>
				<td></td>
				<td></td>
				<td>01</td>
				<td>Estimated (manual)</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>F</td>
				<td>Final</td>
				<td>F</td>
				<td>Final</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>F</td>
				<td>Final Read</td>
				<td>03</td>
				<td>Final Read</td>
			</tr>
			<tr>
				<td>H</td>
				<td>Data Collector Reading Queried By Supplier</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>X</td>
				<td>Data Collector Reading Queried By Haven</td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>I</td>
				<td>Initial</td>
				<td>I</td>
				<td>Initial</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>I</td>
				<td>Initial Read</td>
				<td>06</td>
				<td>Initial Read</td>
			</tr>
			<tr>
				<td>IF</td>
				<td>Information</td>
				<td></td>
				<td></td>
				<td>12</td>
				<td>Reading for Information only</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td>M</td>
				<td>MAR</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>05</td>
				<td>MAR</td>
			</tr>
			<tr>
				<td>N</td>
				<td>Normal</td>
				<td>R</td>
				<td>Routine</td>
				<td>00</td>
				<td>Normal Reading</td>
				<td>00</td>
				<td>Normal Reading - Default</td>
				<td>R</td>
				<td>Routine</td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>N3</td>
				<td>Normal 3rd Party</td>
				<td></td>
				<td></td>
				<td>09</td>
				<td>Third Party Normal Reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>O</td>
				<td>Old Supplier's Estimated CoS Reading</td>
				<td>O</td>
				<td>Old Supplier's Estimated CoS Reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>O</td>
				<td>Old Suppliers Estimated Change of Supplier Reading</td>
				<td>02</td>
				<td>Old Suppliers Estimated Change of Supplier Reading</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td>P</td>
				<td>Electronically collected via PPMIP</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>Q</td>
				<td>Meter Reading modified manually by DC</td>
				<td>Q</td>
				<td>Meter Reading modified manually by DC</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>Q</td>
				<td>Reading Modified Manually by DC</td>
				<td>01</td>
				<td>Reading Modified Manually by DC</td>
			</tr>
			<tr>
				<td>S</td>
				<td>Special</td>
				<td>S</td>
				<td>Special</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>S</td>
				<td>Actual Read</td>
				<td>00</td>
				<td>Actual Read</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td>T</td>
				<td>Proving Test Reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>00</td>
				<td>Proving Test Reading</td>
			</tr>
			<tr>
				<td>W</td>
				<td>Withdrawn</td>
				<td>W</td>
				<td>Withdrawn</td>
				<td>03</td>
				<td>Removed meter reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>X</td>
				<td>Exchange</td>
				<td></td>
				<td></td>
				<td>06</td>
				<td>Exchange Meter Reading</td>
				<td>06</td>
				<td>Exchange Meter Reading</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td>Z</td>
				<td>Actual Change of Tenancy Read</td>
				<td>Z</td>
				<td>Actual Change of Tenancy Read</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>Z</td>
				<td>Actual Change of Tenancy Read</td>
				<td>04</td>
				<td>Actual Change of Tenancy Read</td>
			</tr>
		</tbody>
	</table>
{% endblock %}
