{% extends 'dashboard_screen/base.html' %}

{% block content %}

            <!-- ============================================================== -->
            <!-- Start right Content here -->
            <!-- ============================================================== -->
            <div class="content-page">
                <!-- Start content -->
                <div class="content">
                    <div class="container">
                        <div class="row">

                            <div class="col-lg-12">
                                 <!-- Basic Form Wizard -->

                            	<div class="card-box">

                                <div class="panel">
                                        {% if Client %}

                                        <div class="panel-body">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="panel panel-default">
                                                        <!-- <div class="panel-heading">
                                                            <h4>Invoice</h4>
                                                        </div> -->
                                                        <div class="panel-body">
                                                        <form  id="id_create_invoice" action="/dashboard/invoice/{{ Client.client_id }}/{{ month }}/" class="form-horizontal" method="post" enctype="multipart/form-data">
                                                            {% csrf_token %}
                                                            <input type="hidden"  name="month" value="{{ month }}"/>
                                                            <input type="hidden"  name="client_id" value="{{ Client.client_id }}"/>
                                                            <div class="clearfix">
                                                                <div class="pull-left">
                                                                    <img src="/static/dashboard/images/logo.png" width="400" height="160">
                                                                </div>
                                                                <div class="pull-right">
                                                                    <h4>Invoice for:  <strong>{{ Client.client_code }}</strong>
                                                                    </h4>
                                                                </div>
                                                            </div>
                                                            <hr>
                                                            <div class="row">
                                                                <div class="col-md-12">
                                                                    <div class="pull-left m-t-30">
                                                                        <address>
                                                                          <strong>{{ Lab.lab_name }}</strong><br>
                                                                          {{ Lab.lab_address }} {% if Lab.lab_address2 %}{{ Lab.lab_address2 }} {% endif %}<br>
                                                                          {{ Lab.lab_city }}, {{ Lab.lab_state }} {{ Lab.lab_zipcode }}<br>
                                                                          <abbr title="Phone">P:</abbr> {{ Lab.lab_phone }}
                                                                        </address>
                                                                    </div>
                                                                    <div class="pull-right m-t-30">
                                                                        <address>
                                                                            <strong>Invoiced To:</strong><br>
                                                                            {{ Client.business_legal_name }}
                                                                            <p>Month:<strong> {% if month == 1 %} January{% elif month == 2 %} February{% elif month == 3 %} March{% elif  month == 4 %} April{% elif month == 5 %} May{% elif month == 6 %} June{% elif month == 7 %} July{% elif month == 8 %} Agost{% elif month == 9 %} September{% elif month == 10 %} October{% elif month == 11 %} November{% elif month == 12 %} December{% endif %}</strong> </p>
                                                                            <p class="m-t-10"><strong> Status: </strong> <span class="label label-pink">Pending</span></p>
                                                                         <!--   <p class="m-t-10"><strong>Order ID: </strong> #123456</p> -->
                                                                        </address>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="m-h-50"></div>

                                                            <div class="row">
                                                                <div class="col-md-12">
                                                                    <div class="table-responsive">
                                                                        <table class="table m-t-30">
                                                                            <thead>
                                                                                <tr>
                                                                                    <th>Patient ID</th>
                                                                                    <th>Patient</th>
                                                                                    <th>Accession #</th>
                                                                                    <th>Exam</th>
                                                                                    <th>Exam Type</th>
                                                                                    <th>Price</th>
                                                                                    <th>Total</th>
                                                                                </tr>
                                                                            </thead>
                                                                            <tbody>
                                                                            {% if Entries %}
                                                                                {% for Entry in Entries %}

                                                                                       {% if Entry.accession_number.all %}
                                                                                           {% for accession in Entry.accession_number.all %}
                                                                                               {% if accession.exam_in.exam_casetype.case_type_id == 1 and accession.GYN_completed == 1 %}
                                                                                                   <tr>
                                                                                                        <td>{{ Entry.patient.ext_id }}</td>
                                                                                                        <td>{{ Entry.patient.full_name }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_name }}</td>
                                                                                                        <td>{{ accession.accession_number }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_casetype.case_type_name }}</td>
                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                    </tr>
                                                                                               {% elif accession.exam_in.exam_casetype.case_type_id == 2 and accession.Non_gyn_completed == 1 %}
                                                                                                   <tr>
                                                                                                        <td>{{ Entry.patient.ext_id }}</td>
                                                                                                        <td>{{ Entry.patient.full_name }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_name }}</td>
                                                                                                        <td>{{ accession.accession_number }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_casetype.case_type_name }}</td>

                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                    </tr>
                                                                                               {% elif accession.exam_in.exam_casetype.case_type_id == 3 and accession.MP_completed == 1 %}
                                                                                                   <tr>
                                                                                                        <td>{{ Entry.patient.ext_id }}</td>
                                                                                                        <td>{{ Entry.patient.full_name }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_name }}</td>
                                                                                                        <td>{{ accession.accession_number }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_casetype.case_type_name }}</td>

                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                    </tr>
                                                                                               {% elif accession.exam_in.exam_casetype.case_type_id == 4 and accession.SP_completed == 1 %}
                                                                                                   <tr>
                                                                                                        <td>{{ Entry.patient.ext_id }}</td>
                                                                                                        <td>{{ Entry.patient.full_name }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_name }}</td>
                                                                                                        <td>{{ accession.accession_number }}</td>
                                                                                                        <td>{{ accession.exam_in.exam_casetype.case_type_name }}</td>

                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                        <td>{% for price in accession.exam_in.clienexamprice_set.all %}
                                                                                                               {% if price.created_for_client.client_id == Client.client_id and accession.exam_in.exam_id == price.client_exam_id.exam_id%}
                                                                                                                  {{ price.price }}
                                                                                                               {% endif %}
                                                                                                            {% endfor %}
                                                                                                        </td>
                                                                                                    </tr>

                                                                                               {% endif %}

                                                                                           {% endfor %}
                                                                                       {% endif %}

                                                                                {% endfor %}

                                                                            {% endif %}








                                                                            </tbody>
                                                                        </table>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="row" style="border-radius: 0px;">
                                                                <div class="col-md-3 col-md-offset-9">
                                                                    <hr>
                                                                    <h3 class="text-right">Total: USD {{ Total }}</h3>
                                                                </div>
                                                            </div>
                                                            <hr>
                                                            <div class="hidden-print">
                                                                <div class="pull-right">
                                                                  <!--  <a href="#" class="btn btn-inverse waves-effect waves-light"><i class="fa fa-print"></i></a> -->
                                                                    <button type="submit" name="generate_invoice" class="btn btn-default waves-effect waves-light">Create Invoice</button>

                                                                </div>
                                                            </div>
                                                        </form>
                                                        </div>
                                                    </div>

                                                </div>

                                            </div>



                                        </div>
                                        <!-- end: page -->
                                        {% endif %}

                                    </div> <!-- end Panel -->



                            	</div>


                            <!-- End row -->

                            </div> <!-- end col -->
                        </div>

						<!-- end row -->



                    </div> <!-- container -->

                </div> <!-- content -->


{% endblock %}