{% extends 'base.html' %}
{% block body %}
<!-- <form method="POST" action="{{ request.path }}"> -->
    <div class="container">
    <form method="POST" action="{% url 'Invoice:save_inv' %}" class="modal-content">
    {% csrf_token %}
        <div class="modal-header">
            <!-- <h1>Choose Items</h1> -->
            <h2>{{ customer_fullname }}</h2>
            <div>
            <h3>               <label class="form-check-label">Ref Number</label> <input type="text" name="ref_number" value="">
            </h3>
            </div>
            <div>
                <h3>               <label class="form-check-label">Date</label> <input type="date" name="date" required>
                </h3>
                </div>
        </div>
        <div class="modal-body">
            <div class="mb-3 mt-3">
                <input type="hidden" name="customer_fullname" value="{{ customer_fullname }}">
                
                <!-- <input name="customerreffullname" type='text' list='itemname'  value='{{customer_name}}' id='id_CustomerRefFullName' class='textinput form-control' autofocus> -->
                <table class="table table-striped">
                    <thead>
                        <tr>
                          <th scope="col">Item</th>
                          <th scope="col">Date</th>
                          <th scope="col">SO Number</th>
                          <th scope="col">Ordered</th>
                          <th scope="col">Prev. Inv</th>
                          <th scope="col">To Invoice</th>
                          <th scope="col">UOM</th>
                          <th scope="col">Rate</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for so_dict in objects %}
                            <!-- {{so_dict}} -->
                            {% for so_line in so_dict.SalesOrderLineRet %}
                            <tr>
                                <td>
                                <input type="hidden" name="RefNumber" value="{{ so_dict.RefNumber }}">
                                <input type="hidden" name="CustomerFullName" value="{{ so_dict.CustomerFullName }}">
                                <input type="hidden" name="TxnID" value="{{ so_dict.TxnID }}">
                                <input type="hidden" name="TxnDate" value="{{ so_dict.TxnDate }}">
                                <input type="hidden" name="TotalAmount" value="{{ so_dict.TotalAmount }}">
                                {% for k, v in so_line.items %} 
                                    <input type="hidden" name="{{ k }}" value="{{ v }}">
                                {% endfor %}
                                <div class="form-check">
                                    <input type="checkbox" name="so_field" value="{{ so_line.TxnLineID }}" id="id_so_field_{{forloop.counter}}" class="form-check-input" checked>
                                    <label for="id_so_field_{{ forloop.counter }}" class="form-check-label">{{so_line.ItemFullName}}
                                    </label>
                                </div>
                                </td>
                                <td>{{ so_dict.TxnDate }}</td>
                                <td>{{ so_dict.RefNumber }}</td>
                                <td>{% widthratio so_line.Quantity so_line.convertQTY 1 %}</td>
                                <td>{% widthratio  so_line.Invoiced so_line.convertQTY 1 %}</td>
                                <td><input type="number" name="backordered" required value="{% widthratio so_line.BackOrdered so_line.convertQTY 1 %}" min="0" max="{% widthratio so_line.BackOrdered so_line.convertQTY 1 %}"> </td>
                                <td>{{ so_line.UOM }}</td>
                                <td><input type="number" name="rate" required value="{% widthratio so_line.Rate 1 so_line.convertQTY %}" min="0" > </td>
                            </tr>
                            {% endfor %}
                        {% endfor %}
                        <tr>    
                            <!-- bisa jadikan for loop jika banyak item lagi -->
                            <td>
                                <input type="hidden" name="other_items" value="peti">
                                <div class="form-check">
                                    <input type="checkbox" name="selected_items" value="peti"  class="form-check-input peti">
                                    <label class="form-check-label">PETI</label>
                                </div>
                            </td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td><input type="number" name="other_qty" required value="1" min="0" max="100"> </td>
                            <td>PETI</td>
                            <td><input type="number" name="other_rate" required value="40000" min="0" max="40000000"> </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="hidden" name="other_items" value="expedition">
                                <div class="form-check">
                                    <input type="checkbox" name="selected_items" value="expedition" class="form-check-input expedition">
                                    <label  class="form-check-label">Ekspedisi</label>
                                </div>
                            </td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td><input type="number" name="other_qty" required value="1" min="0" max="1"> </td>
                            <td></td>
                            <td><input type="number" name="other_rate" required value="0" min="0" max="10000000"> </td>
                        </tr>
                    </tbody>
                </table>
                
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary mt-2 me-2 ms-2" id="id_btnsave" >Save to Invoice</button>
        </div>
    </form>
</div>
{% endblock %}