{% extends "company/company_base.html" %}
{% load static %}
{% load i18n %}

{% block details %}

{% include 'company/tabs.html' with tab='po' %}

<h4>{% trans "Purchase Orders" %}</h4>
<hr>

{% if roles.purchase_order.add %}
<div id='button-bar'>
    <div class='button-toolbar container-fluid' style='float: right;'>
        <button class='btn btn-primary' type='button' id='company-order2' title='{% trans "Create new purchase order" %}'>
            <span class='fas fa-plus-circle'></span> {% trans "New Purchase Order" %}</button>
        <div class='filter-list' id='filter-list-purchaseorder'>
            <!-- Empty div -->
        </div>
    </div>
</div>
{% endif %}

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

{% endblock %}

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

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


    function newOrder() {
        launchModalForm("{% url 'po-create' %}",
        {
            data: {
                supplier: {{ company.id }},
            },
            follow: true,
        });
    }

    $("#company-order").click(function() {
        newOrder();
    });

    $("#company-order2").click(function() {
        newOrder();
    });

{% endblock %}
