{% macro render_purchase_table(purchases, supplier, formatLang) %}
    {% if purchases %}
        <table class="table">
            <thead>
                <th>PO No.</th>
                <th>State</th>
                {% if not supplier %}
                  <th>Supplier</th>
                {% endif %}
                <th>Address</th>
                <th>Product</th>
                <th>Quantity</th>
                <th class="text-right">Amount</th>
            </thead>
            <tbody>
                {% for purchase in purchases %}
                    <tr>
                        <td>{{ purchase.reference }}</td>
                        <td class="text-capitalize">{{ purchase.state }}</td>
                        {% if not supplier %}
                          <td>{{ purchase.party.name }}</td>
                        {% endif %}
                        <td colspan="3"><i class="fa fa-map-marker">&nbsp;{{ purchase.invoice_address.rec_name }}</i></td>
                        <td class="text-right">{{ purchase.total_amount|currencyformat(purchase.currency.code) }}</td>
                    </tr>
                    {% for line in purchase.lines|rejectattr("product", "none") %}
                      <tr>
                          <td {% if not supplier %}colspan="4"{% else %}colspan="3"{% endif %}></td>
                          <td>{{ line.product.name }}</td>
                          <td class="text-right">{{ formatLang(line.quantity, purchase.party.lang, digits=line.unit_digits) }} {% if line.unit.symbol != 'u' %}{{ line.unit.symbol }}{% endif %}</td>
                          <td></td>
                      </tr>
                    {% endfor %}
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
{% endmacro %}
