{% extends "page_base.html" %}

{% load inventree_extras %}
{% load static %}
{% load i18n %}

{% block page_title %}
{% inventree_title %} | {% trans "Purchase Orders" %}
{% endblock %}

{% block heading %}
{% trans "Purchase Orders" %}
{% endblock %}

{% block actions %}
{% if roles.purchase_order.add %}
<button class='btn btn-success' type='button' id='po-create' title='{% trans "Create new purchase order" %}'>
    <span class='fas fa-plus-circle'></span> {% trans "New Purchase Order" %}
</button>
{% endif %}
{% endblock %}

{% block page_info %}

<div class='panel-content'>
    <div id='table-buttons'>
        <div class='button-toolbar container-fluid' style='float: right;'>
            <div class='btn-group' role='group'>
                {% if report_enabled %}
                <button id='order-print' class='btn btn-outline-secondary' title='{% trans "Print Order Reports" %}'>
                    <span class='fas fa-print'></span>
                </button>
                {% endif %}
                {% include "filter_list.html" with id="purchaseorder" %}
            </div>
        </div>
    </div>

    <table class='table table-striped table-condensed po-table' data-toolbar='#table-buttons' id='purchase-order-table'>
    </table>

    <div id='purchase-order-calendar'></div>

</div>

{% endblock %}

{% block js_load %}
{{ block.super }}

{% endblock %}

{% block js_ready %}
{{ block.super }}

{% if report_enabled %}
$("#order-print").click(function() {
    var rows = getTableData('#purchase-order-table');

    var orders = [];

    rows.forEach(function(row) {
        orders.push(row.pk);
    });

    printPurchaseOrderReports(orders);
})
{% endif %}

$("#po-create").click(function() {
    createPurchaseOrder();
});

loadPurchaseOrderTable("#purchase-order-table", {
    url: "{% url 'api-po-list' %}",
});

{% endblock %}
