{% extends "base.html" %}

{% block inside_head %}
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<script type="text/javascript" language="javascript">

		function hideText() {
			document.getElementById('full_note').style.display='none';
			document.getElementById('truncated_note').style.display='inline';
		}

		function showText() {
			document.getElementById('truncated_note').style.display='none';
			document.getElementById('full_note').style.display='inline';
		}

		function collapseBills(collapseId) {
			var collapsibles = document.getElementsByClassName('collapsible_' + collapseId);
			for (var i = 0; i < collapsibles.length; i++) {
				collapsibles[i].style.display = 'none';
			}
			var expanders = document.getElementsByClassName('expander_' + collapseId);
			for (var i = 0; i < expanders.length; i++) {
				expanders[i].style.display = 'table-cell';
			}
			var collapsers = document.getElementsByClassName('collapser_' + collapseId);
			for (var i = 0; i < collapsers.length; i++) {
				collapsers[i].style.display = 'none';
			}
		}

		function expandBills(collapseId) {
			var collapsibles = document.getElementsByClassName('collapsible_' + collapseId);
			for (var i = 0; i < collapsibles.length; i++) {
				collapsibles[i].style.display = 'table-row';
			}
			var expanders = document.getElementsByClassName('expander_' + collapseId);
			for (var i = 0; i < expanders.length; i++) {
				expanders[i].style.display = 'none';
			}
			var collapsers = document.getElementsByClassName('collapser_' + collapseId);
			for (var i = 0; i < collapsers.length; i++) {
				collapsers[i].style.display = 'table-cell';
			}
		}

	</script>
{% endblock %}

{% block title %}
    &raquo; Supplies &raquo; {{supply.id}}
{% endblock %}

{% block nav %}
	&raquo; <a href="/supplies">Supplies</a> &raquo;
{{supply.id}}
 	[<a href="/supplies/{{supply.id}}/edit">edit</a>]
{% endblock %}

{% block content %}
<div class="layer-section">
    <div class="section-header">
        <!-- <h2>{{supply.id}}</h2> -->
        <h2>Supply Details</h2>
    </div>
    <div class="section-content">
        <div class="section-data">
            <table class="DataTable widthAuto noMarginBottom">
                <tr>
                    <th>Name</th>
                    <td>{{ supply.name }}</td>
                </tr>
                <tr>
                    <th>Source</th>
                    <td>
                        {{ supply.source.code }} - {{ supply.source.name }}
                        {% if supply.source.code == 'gen' %}
                        ( {{ supply.generator_type.code }} {{ supply.generator_type.name }})
                        {% endif %}
                    </td>
                </tr>
                <tr>
                    <th>GSP Group</th>
                    <td>
                        {{ supply.gsp_group.code }} {{ supply.gsp_group.description }}
                    </td>
                </tr>
                {% if system_properties['supply_links'] %}
                <tr>
                    <th>Links</th>
                    <td>
                        <ul>
                            {% for link in system_properties['supply_links'] %}
                            <li>
                                <a href="{{link.url}}supply_id={{site.id}}">{{link.name}}</a>
                            </li>
                            {% endfor %}
                        </ul>
                    </td>
                </tr>
                {% endif %}
                <tr>
                    <th>
                        <a href="/supplies/{{supply.id}}/notes">Notes</a>
                    </th>
                    <td>
                        {% if note %}
                        {% if is_truncated %}
                        <div id="truncated_note">
                            {{ truncated_note }}
                        </div>
                        <div id="full_note" style="display: none;">
                            <pre style=" white-space pre-wrap;">{{ supply.note }}</pre>
                            <a href="JavaScript:void()" onClick="hideText()" />Less...</a>
                        </div>
                        {% else %}
                        Category: {{note.category}}
                        {% if note.is_important %}
                        Important
                        {% else %}
                        Not important
                        {% endif %}
                        <pre style="display: inline;">{{note.body}}</pre>
                        {% endif %}
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>

        {% for era_bundle in era_bundles %}
        {% set era = era_bundle['era'] %}
        {% set physical_site = era_bundle['physical_site'] %}
        {% set other_sites = era_bundle['other_sites'] %}
        <div class="section-data">
        <table  class="DataTable widthAuto noMarginBottom">
            <caption>
                Era [<a href="/eras/{{era.id}}/edit">edit</a>]
            </caption>
            <thead>
                <tr>
                    <th rowspan="2">From</th>
                    <th rowspan="2">To</th>
                    <th rowspan="2">Sites</th>
                    <th rowspan="2">
											<a title="Energisation Status">ES</a>
										</th>
                    <th rowspan="2"><a title="Profile Class">PC</a></th>
                    <th rowspan="2"><a title="Meter Serial Number">MSN</a></th>
                    <th rowspan="2"><a title="Meter Timeswitch Class">MTC</a></th>
                    <th rowspan="2"><a title="Metering Code Of Practice">CoP</a></th>
                    <th rowspan="2"><a title="Communications Type">Comm</a></th>
                    <th rowspan="2">
                        <a title="Standard Settlement Configuration">SSC</a>
                    </th>
                    <th rowspan="2"><a title="Properties">Props</a></th>
                    <th colspan="2">
                        <a title="Meter Operator">MOP</a>
                    </th>
                    <th colspan="2">
                        <a title="Data Collector">DC</a>
                    </th>
                    <th rowspan="2">
                        Channels
                        [<a href="/eras/{{era.id}}/add_channel">add</a>]
                    </th>
                    <th rowspan="2">
                        <a title="Line Loss Factor Class">LLFC</a>
                    </th>
                    <th rowspan="2">MPAN Core</th>
                    <th rowspan="2">kVA</th>
                    <th colspan="2">Supplier</th>
                </tr>
                <tr>
                    <th>Contract</th>
                    <th>Account</th>
                    <th>Contract</th>
                    <th>Account</th>
                    <th>Contract</th>
                    <th>Account</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td rowspan="4">
                        <a title="{{ era.start_date|hh_format }}">{{ era.start_date|hh_format(modifier='date') }}</a>
                    </td>
                    <td rowspan="4">
                        <a title="{{ era.finish_date|hh_format }}">{{ era.finish_date|hh_format(modifier='date') }}</a>
                    </td>
                    <td rowspan="4">
                        <a href="/sites/{{physical_site.id}}"
                           title="{{physical_site.name}}">{{ physical_site.code }}</a>
                        {% if other_sites %}
                        (also
                        {% for other_site in other_sites %}
                        <a href="/sites/{{ other_site.id }}"
                           title="{{other_site.name}}">{{ other_site.code }}</a>
                        {%- endfor -%}
                        )
                        {% endif %}
                    </td>
                    <td rowspan="4">
											<a
													href="/energisation_statuses/{{era.energisation_status.id}}"
													title="{{era.energisation_status.description}}"
											>{{era.energisation_status.code}}</a>
                    </td>
                    <td rowspan="4">
                        <a href="/pcs/{{era.pc.id}}"
                           title="{{era.pc.name}}">{{era.pc.code}}</a>
                    </td>
                    <td rowspan="4">{{ era.msn }}</td>
                    <td rowspan="4">
                        <a href="/mtcs/{{era.mtc.id}}" title="{{era.mtc.description}}">{{era.mtc.code}}</a>
                    </td>
                    <td rowspan="4">
                        <a href="/cops/{{era.cop.id}}" title="{{era.cop.description}}">{{era.cop.code}}</a>
                    </td>
                    <td rowspan="4">
                        <a href="/comms/{{era.comm.id}}" title="{{era.comm.description}}">{{era.comm.code}}</a>
                    </td>
                    <td rowspan="4">
                        {% if era.ssc %}
                        <a href="/sscs/{{era.ssc.id}}" title="{{era.ssc.description}}">{{era.ssc.code}}</a>
                        {% endif %}
                    </td>
                    <td rowspan="4">{{era.properties}}</td>
                    <td rowspan="4">
                        <a href="/mop_contracts/{{era.mop_contract.id}}">{{era.mop_contract.name}}</a>
                    </td>
                    <td rowspan="4">
                        {{era.mop_account}}
                    </td>
                    <td rowspan="4">
                        <a href="/dc_contracts/{{era.dc_contract.id}}">{{era.dc_contract.name}}</a>
                    </td>
                    <td rowspan="4">{{era.dc_account}}</td>
                    <th colspan="6">Import</th>
                </tr>
                <tr>
									<td>
										{% for channel in era_bundle['imp_channels'] %}
											<a href="/channels/{{channel.id}}">{{channel.channel_type}}</a>
										{% endfor %}
									</td>
									<td>
											{% if era.imp_mpan_core %}
											<a href="/llfcs/{{era.imp_llfc.id}}" title="{{era.imp_llfc.description}}">
													{{era.imp_llfc.code}}
											</a>
											{% endif %}
									</td>
									<td>
											{% if era.imp_mpan_core %}
											<a title="{{supply.dno.dno_name}}" href="/dnos/{{supply.dno.id}}">{{supply.dno.dno_code}}</a> {{era.imp_mpan_core[3:]}}
											{% endif %}
									<td>
										{% if era.imp_mpan_core %}
											{{ era.imp_sc }}
										{% endif %}
									</td>
									<td>
										{% if era.imp_mpan_core %}
											<a href="/supplier_contracts/{{era.imp_supplier_contract.id}}">{{era.imp_supplier_contract.name}}</a>
										{% endif %}
									</td>
									<td>
										{% if era.imp_mpan_core %}
											{{ era.imp_supplier_account }}
											{% if era_bundle['imp_shared_supplier_accounts'] %}(
												{%- for sup in era_bundle['imp_shared_supplier_accounts'] -%}
												{%- if not loop.first    -%} {%- endif -%}
											<a href="/supplies/{{sup.id}}">{{sup.id}}</a>
											{%- endfor -%}
											)
											{% endif %}
										{% endif %}
									</td>
                </tr>
                <tr>
                    <th colspan="6">Export</th>
                </tr>
                <tr>
                    <td>
                        {% for channel in era_bundle['exp_channels'] %}
                        <a href="/channels/{{channel.id}}">{{channel.channel_type}}</a>
                        {% endfor %}
                    </td>
                    <td>
                        {% if era.exp_mpan_core %}
                        <a href="/llfcs/{{era.exp_llfc.id}}" title="{{era.exp_llfc.description}}">{{era.exp_llfc.code}}</a>
                        {% endif %}
                    </td>
                    <td>
                        {% if era.exp_mpan_core %}
                        <a title="{{era.supply.dno.dno_code}}" href="/dnos/{{era.supply.dno.id}}">{{era.supply.dno.dno_code}}</a> {{era.exp_mpan_core[3:]}}
                        {% endif %}
                    </td>
                    <td>
											{% if era.exp_mpan_core %}
                        {{ era.exp_sc }}
											{% endif %}
                    </td>
                    <td>
                        {% if era.exp_mpan_core %}
                        <a href="/supplier_contracts/{{era.exp_supplier_contract.id}}">{{era.exp_supplier_contract.name}}</a>
                        {% endif %}
                    </td>
                    <td>
											{% if era.exp_mpan_core %}
                        {{ era.exp_supplier_account }}
                        {% if era_bundle['exp_shared_supplier_accounts'] %}(
                        {%- for sup in era_bundle['exp_shared_supplier_accounts'] -%}
                        {%- if not loop.first    -%} {%- endif -%}
                        <a href="/supplies/{{sup.id}}">{{sup.id}}</a>
                        {%- endfor -%}
                        )
                        {% endif %}
                        {% endif %}
                    </td>
                </tr>
            </tbody>
        </table>
        </div>
        <div class="section-data">
            <div class="noWrap">
                <table class="DataTable widthAuto noMarginBottom">
                    {% set imp_bills = era_bundle['imp_bills'] %}
                    <caption>
											Import Supplier Bills
											[<a href="/eras/{{era.id}}/add_supplier_bill">add</a>]
										</caption>
                    <thead>
                        <tr>
                            <th rowspan="2">View</th>
                            <th rowspan="2">From</th>
                            <th rowspan="2">To</th>
                            <th rowspan="2">Batch</th>
                            <th rowspan="2">Reference</th>
                            <th rowspan="2">kWh</th>
                            <th rowspan="2">Net</th>
                            <th rowspan="2">VAT</th>
                            <th rowspan="2">Type</th>
                            {% for tpr in imp_bills['inner_headers'] %}
                            <th colspan="4">
                                {% if tpr == None %}
                                MD
                                {% else %}
                                <a href="/tprs/{{tpr.id}}">{{tpr.code}}</a>
                                {% endif %}
                            </th>
                            {% endfor %}
                            {% for i in range(imp_bills['num_outer_cols']) %}
                            <th colspan="5">
                                {{ loop.index }}
                            </th>
                            {% endfor %}
                        </tr>
                        <tr>
                            {% for tpr in imp_bills['inner_headers'] %}
                            <th colspan="2">Previous</th>
                            <th colspan="2">Present</th>
                            {% endfor %}
                            {% for i in range(imp_bills['num_outer_cols']) %}
                            <th>TPR</th>
                            <th colspan="2">Previous</th>
                            <th colspan="2">Present</th>
                            {% endfor %}
                        </tr>
                    </thead>
                    <tbody>
                        {% for bill_dict in imp_bills['bill_dicts'] %}
                        {% set read_rows = bill_dict['read_rows'] %}
                        {% set bill = bill_dict['bill'] %}
                        {% set rows_high = bill_dict['rows_high'] %}
                        {% if bill_dict.first_collapsible %}
                        <tr style="background-color: silver; cursor: pointer;">
                            <td style="text-decoration: none; padding-top: 0px; padding-bottom: 0px; font-size: x-small;"
                                colspan="{{9 + imp_bills['inner_headers']|length * 4 + imp_bills['num_outer_cols'] * 5}}"
                                class="expander_{{bill_dict.collapse_id}}"
                                onClick="expandBills({{bill_dict.collapse_id}})">
                                +
                            </td>
                            <td style="text-decoration: none; display: none; padding-top: 0px; padding-bottom: 0px; font-size: x-small;"
                                colspan="{{9 + imp_bills['inner_headers']|length * 4 + imp_bills['num_outer_cols'] * 5}}"
                                class="collapser_{{bill_dict.collapse_id}}"
                                onClick="collapseBills({{bill_dict.collapse_id}})">
                                -
                            </td>
                        </tr>
                        {% endif %}

                        <tr {% if bill_dict.collapsible %}
                            class="collapsible_{{bill_dict.collapse_id}}"
                            style="display: none; background-color: silver;"
                            {% endif %}>
                            <td rowspan="{{ rows_high }}">
                                <a href="/supplier_bills/{{bill.id}}">View</a>
                            </td>
                            <td rowspan="{{ rows_high }}">
                                <label title="{{bill.start_date|hh_format}}">{{bill.start_date|hh_format('date')}}</label>
                            </td>
                            <td rowspan="{{ rows_high }}">
                                <label title="{{ bill.finish_date|hh_format }}">{{ bill.finish_date|hh_format('date') }}</label>
                            </td>
                            <td rowspan="{{ rows_high }}">
                                <a href="/supplier_batches/{{bill.batch.id}}">{{bill.batch.reference}}</a>
                            </td>
                            <td rowspan="{{ rows_high }}">{{ bill.reference }}</td>
                            <td rowspan="{{ rows_high }}">{{ bill.kwh }}</td>
                            <td rowspan="{{ rows_high }}">{{ bill.net }}</td>
                            <td rowspan="{{ rows_high }}">{{ bill.vat }}</td>
                            <td rowspan="{{ rows_high }}">
                                <a href="/bill_types/{{bill.bill_type.id}}"
                                   title="{{bill.bill_type.description}}">{{bill.bill_type.code}}</a>
                            </td>
                            {% for read_row in read_rows %}
                            {% if not loop.first %}
                        <tr {% if bill_dict.collapsible %}
                            class="collapsible_{{bill_dict.collapse_id}}"
                            style="display: none; background-color: silver;"
                            {% endif %}>
                            {% endif %}
                            {% for read in read_row['inner_reads'] %}
                            <td style="border-right: none;">
                                {% if read %}
                                <a title="{{ read.previous_date|hh_format }} {{ read.msn }}">{{ read.previous_value }}</a>
                                {% endif %}
                            </td>
                            <td style="border-left: none; text-align: right;">
                                {% if read %}
                                {{ read.previous_type.code }}
                                {% endif %}
                            </td>
                            <td style="border-right: none;">
                                {% if read %}
                                <a title="{{ read.present_date|hh_format }} {{ read.msn }}">{{ read.present_value }}</a>
                                {% endif %}
                            </td>
                            <td style="border-left: none; text-align: right;">
                                {% if read %}
                                {{ read.present_type.code }}
                                {% endif %}
                            </td>
                            {% endfor %}
                            {% for read in read_row['outer_reads'] %}
                            <td>
                                {% if read %}
                                {% if read.tpr %}
                                <a href="/tprs/{{read.tpr.id}}">{{read.tpr.code}}</a>
                                {% else %}
                                MD
                                {% endif %}
                                {% endif %}
                            </td>
                            <td style="border-right: none;">
                                {% if read %}
                                <a title="{{read.previous_date|hh_format}} {{read.msn}}">{{read.previous_value}}</a>
                                {% endif %}
                            </td>
                            <td style="border-left: none; text-align: right;">
                                {% if read %}
                                {{read.previous_type.code}}
                                {% endif %}
                            </td>
                            <td style="border-right: none;">
                                {% if read %}
                                <a title="{{read.present_date|hh_format}} {{read.msn}}">{{read.present_value}}</a>
                                {% endif %}
                            </td>
                            <td style="border-left: none; text-align: right;">
                                {% if read %}
                                {{read.present_type.code}}
                                {% endif %}
                            </td>
                            {% if not loop.first %}
                        </tr>
                        {% endif %}
                        {% endfor %}
                        {% endfor %}
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="section-data">
            <div class="noWrap">
                <table class="DataTable widthAuto noMarginBottom">
                    {% set exp_bills = era_bundle['exp_bills'] %}
                    <caption>Export Supplier Bills</caption>
                    <thead>
                        <tr>
                            <th rowspan="2">View</th>
                            <th rowspan="2">From</th>
                            <th rowspan="2">To</th>
                            <th rowspan="2">Batch</th>
                            <th rowspan="2">Reference</th>
                            <th rowspan="2">kWh</th>
                            <th rowspan="2">Net</th>
                            <th rowspan="2">VAT</th>
                            <th rowspan="2">Type</th>
                            {% for tpr in exp_bills['inner_headers'] %}
                            <th colspan="4">
                                {% if tpr == None %}
                                MD
                                {% else %}
                                <a href="/tprs/{{tpr.id}}">{{tpr.code}}</a>
                                {% endif %}
                            </th>
                            {% endfor %}
                            {% for i in range(exp_bills['num_outer_cols']) %}
                            <th colspan="5">
                                {{ loop.index }}
                            </th>
                            {% endfor %}
                        </tr>

                        <tr>
                            {% for tpr in exp_bills['inner_headers'] %}
                            <th colspan="2">Previous</th>
                            <th colspan="2">Present</th>
                            {% endfor %}
                            {% for i in range(exp_bills['num_outer_cols']) %}
                            <th>TPR</th>
                            <th colspan="2">Previous</th>
                            <th colspan="2">Present</th>
                            {% endfor %}
                        </tr>
                    </thead>
                    <tbody>
                        {% for bill_dict in exp_bills['bill_dicts'] %}
                        {% set read_rows = bill_dict['read_rows'] %}
                        {% set bill = bill_dict['bill'] %}
                        {% set rows_high = bill_dict['rows_high'] %}
                        <tr>
                            <td rowspan="{{ rows_high }}">
                                <a href="/supplier_bills/{{bill.id}}">View</a>
                            </td>
                            <td rowspan="{{ rows_high }}">
                                <label title="{{ bill.start_date|hh_format }}">{{ bill.start_date|hh_format('date') }}</label>
                            </td>
                            <td rowspan="{{ rows_high }}">
                                <label title="{{ bill.finish_date|hh_format }}">{{ bill.finish_date|hh_format('date') }}</label>
                            </td>
                            <td rowspan="{{ rows_high }}">
                                <a href="/supplier_batches/{{bill.batch.id}}">{{bill.batch.reference}}</a>
                            </td>
                            <td rowspan="{{ rows_high }}">{{ bill.reference }}</td>
                            <td rowspan="{{ rows_high }}">{{ bill.kwh }}</td>
                            <td rowspan="{{ rows_high }}">{{ bill.net }}</td>
                            <td rowspan="{{ rows_high }}">{{ bill.vat }}</td>
                            <td rowspan="{{ rows_high }}">
                                <a href="/bill_types/{{bill.bill_type.id}}" title="{{bill.bill_type.description}}">{{bill.bill_type.code}}</a>
                            </td>

                            {% for read_row in read_rows %}
                            {% for read in read_row['inner_reads'] %}
                            <td style="border-right: none;">
                                {% if read %}
                                <label title="{{ read.previous_date|hh_format }} {{ read.msn }}">{{ read.previous_value }}</label>
                                {% endif %}
                            </td>
                            <td style="border-left: none;">
                                {% if read %}
                                {{ read.previousType.code }}
                                {% endif %}
                            </td>
                            <td style="border-right: none;">
                                {% if read %}
                                <label title="{{ read.presentDate|hh_format }} {{ read.msn }}">{{ read.presentValue }}</label>
                                {% endif %}
                            </td>
                            <td style="border-left: none;">
                                {% if read %}
                                {{ read.presentType.code }}
                                {% endif %}
                            </td>
                            {% endfor %}
                            {% if loop.first %}
                            {% for read in read_row['outer_reads'] %}
                            <td>
                                {% if read.tpr %}
                                <a href="/tprs/{{read.tpr.id}}">{{read.tpr.code}}</a>
                                {% else %}
                                MD
                                {% endif %}
                            </td>
                            <td style="border-right: none;">
                                <label title="{{ read.previous_date|hh_format }} {{ read.msn }}">{{ read.previous_value }}</label>
                            </td>
                            <td style="border-left: none;">
                                {{ read.previous_type.code }}
                            </td>
                            <td style="border-right: none;">
                                <label title="{{ read.present_date|hh_format }} {{ read.msn }}">{{ read.present_value }}</label>
                            </td>
                            <td style="border-left: none;">
                                {{ read.present_type.code }}
                            </td>
                            {% endfor %}
                            {% endif %}
                            {% endfor %}
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="section-data">
            <div class="noWrap">
                <table class="DataTable widthAuto noMarginBottom">
                    <caption>DC Bills</caption>
                    <thead>
                        <tr>
                            <th>View</th>
                            <th>Batch</th>
                            <th>Reference</th>
                            <th>Account</th>
                            <th>Issue Date</th>
                            <th>From</th>
                            <th>To</th>
                            <th>kWh</th>
                            <th>Net</th>
                            <th>VAT</th>
                            <th>Gross</th>
                            <th>Type</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for bill_dict in era_bundle['dc_bills']['bill_dicts'] %}
                        {% set bill = bill_dict['bill'] %}
                        <tr>
                            <td>
                                <a href="/dc_bills/{{bill.id}}">view</a>
                            </td>
                            <td>
                                <a href="/dc_batches/{{bill.batch.id}}">{{bill.batch.reference}}</a>
                            </td>
                            <td>{{ bill.reference }}</td>
                            <td>{{ bill.account }}</td>
                            <td>{{ bill.issue_date|hh_format }}</td>
                            <td>{{ bill.start_date|hh_format }}</td>
                            <td>{{ bill.finish_date|hh_format }}</td>
                            <td>{{ bill.kwh }}</td>
                            <td>{{ bill.net }}</td>
                            <td>{{ bill.vat }}</td>
                            <td>{{ bill.gross }}</td>
                            <td>
                                <a href="/bill_types/{{bill.bill_type.id}}" title="{{bill.bill_type.description}}">{{bill.bill_type.code}}</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="section-data">
            <div class="noWrap">
                <table class="DataTable widthAuto noMarginBottom">
                    <caption>MOP Bills</caption>
                    <thead>
                        <tr>
                            <th>View</th>
                            <th>Batch</th>
                            <th>Reference</th>
                            <th>Account</th>
                            <th>Issue Date</th>
                            <th>From</th>
                            <th>To</th>
                            <th>kWh</th>
                            <th>Net</th>
                            <th>VAT</th>
                            <th>Gross</th>
                            <th>Type</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for bill_dict in era_bundle['mop_bills']['bill_dicts'] %}
                        {% set bill = bill_dict['bill'] %}
											<tr>
											<td><a href="/mop_bills/{{bill.id}}">view</a></td>
											<td>
												<a href="/mop_batches/{{bill.batch.id}}">{{bill.batch.reference}}</a>
											</td>
											<td>{{ bill.reference }}</td>
											<td>{{ bill.account }}</td>
											<td>{{ bill.issue_date|hh_format }}</td>
											<td>{{ bill.start_date|hh_format }}</td>
											<td>{{ bill.finish_date|hh_format }}</td>
											<td>{{ bill.kwh }}</td>
											<td>{{ bill.net }}</td>
											<td>{{ bill.vat }}</td>
											<td>{{ bill.gross }}</td>
											<td>
											<a href="/bill_types/{{bill.bill_type.id}}" title="{{bill.bill_type.description}}">{{bill.bill_type.code}}</a>
										</td>
									</tr>
								{% endfor %}
							</tbody>
						</table>
					</div>
        </div>
			{% endfor %}
		</div>
	</div>
	<div class="layer-section">
    <div class="section-content">
			<div class="section-data">
				<ul>
					<li>
						kWh, kVA, MD etc. by month:
						<a href="/supplies/{{supply.id}}/months?is_import=true&amp;year={{last_month_start.year}}&amp;years=1">Import</a>
						<a href="/supplies/{{supply.id}}/months?is_import=false&amp;year={{last_month_start.year}}&amp;years=1">Export</a>
					</li>
					<li>
						<a href="/supplies/{{ supply.id }}/hh_data?months=1&amp;finish_year={{ now.year }}&amp;finish_month={{ now.month }}">Raw HH data</a>
					</li>
					<li>
						<a href="/supplies/{{supply.id}}/virtual_bill?start_year={{last_month_start.year}}&amp;start_month={{last_month_start.month}}&amp;start_day={{last_month_start.day}}&amp;start_hour={{last_month_start.hour}}&amp;start_minute={{last_month_start.minute}}&amp;finish_year={{last_month_finish.year}}&amp;finish_month={{last_month_finish.month}}&amp;finish_day={{last_month_finish.day}}&amp;finish_hour={{last_month_finish.hour}}&amp;finish_minute={{last_month_finish.minute}}">Supplier Virtual Bill</a>
					</li>
				</ul>
			</div>
    </div>
	</div>
	<div class="layer-section">
    <div class="section-header">
			<h2>CSV Downloads</h2>
    </div>
			<div class="standardForm textWidthAuto">
        <div class="section-content">
					<div class="section-data ">
						<form action="/reports/291">
							<fieldset>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								<legend>Virtual Bills</legend>
								From {{input_date('start', last_month_start)}} to
								{{input_date('finish', last_month_finish)}}
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/241">
							<fieldset>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								<legend>Daily Supplier Virtual Bills</legend>
								<select name="is_import">
									<option value="true">Import</option>
									<option value="false">Export</option>
								</select>
								from {{input_date('start', last_month_start, 'day')}}
								to {{input_date('finish', last_month_finish, 'day')}}
								<input type="submit" value="Download">
								(Note that unless a month is entirely in the past, all the days
								for that month will be estimates)
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/387">
							<fieldset>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								<legend>Virtual Bills By Half-Hour</legend>
								From {{input_date('start', last_month_start)}} to
								{{input_date('finish', last_month_finish)}}
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/169">
							<fieldset>
								<legend>HH Data: Day Per Row</legend>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								<select name="imp_related">
									<option value="true">Import</option>
									<option value="false">Export</option>
								</select>
								<select name="channel_type">
									<option value="ACTIVE">ACTIVE</option>
									<option value="REACTIVE_IMP">REACTIVE_IMP</option>
									<option value="REACTIVE_EXP">REACTIVE_EXP</option>
								</select>
								from {{
								input_date('start', last_month_start, resolution='day') }} to
								{{ input_date('finish', last_month_finish, resolution='day') }}
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/187" method="post">
							<fieldset>
								<legend>HH Data: HH Per Row</legend>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								From {{ input_date('start', last_month_start) }} to
								{{ input_date('finish', last_month_finish) }}
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/41?supply_id">
							<fieldset>
								<legend>TRIAD</legend>
								<input type="hidden" name="supply_id" value="{{ supply.id }}">
								<br>
								For financial year ending March
								<input
							 			name="year" value="{{triad_year}}" size="4" maxlength="4">
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/149">
							<fieldset>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								<legend>Duration</legend>
								<p>
									From {{ input_date('start', last_month_start) }}
									to {{ input_date('finish', last_month_finish) }}
									<input type="submit" value="Download">
								</p>
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/247" method="post">
							<fieldset>
								<input type="hidden" name="supply_id" value="{{supply.id}}">
								<legend>Monthly Duration</legend>
								<br />
								For <input name="months" maxlength="2" size="2" value="1">
								month(s) finishing at the end of
								{{ input_date('finish', last_month_finish, 'month') }}
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
						<form action="/reports/33">
							<input type="hidden" name="supply_id" value="{{supply.id}}">
							<fieldset>
								<legend>Snapshot</legend>
								<br>
								For {{ input_date('date', last_month_finish) }}
								<input type="submit" value="Download">
							</fieldset>
						</form>
					</div>
					<div class="section-data ">
					<form action="/reports/219">
						<input type="hidden" name="supply_id" value="{{ supply.id }}">
						<fieldset>
							<legend>Register Reads</legend>
							<br>
							<br>
							For <input name="months" maxlength="2" size="2" value="1">
							month(s) finishing at the end of
							{{ input_date('end', last_month_finish, 'month') }}
							<input type="submit" value="Download">
						</fieldset>
					</form>
				</div>
				<div class="section-data ">
					<form action="/reports/207">
						<input type="hidden" name="supply_id" value="{{supply.id}}">
						<fieldset>
							<legend>CRC</legend>
							<br>
							For financial year starting April
							<input
									name="year" value="{{ last_month_start.year }}" size="4"
									maxlength="4">
							<input type="submit" value="Download">
						</fieldset>
					</form>
				</div>
			</div>
		</div>
	</div>
{% endblock %}
