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

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

<h4>Open Purchase Orders</h4>
<hr>

<div id='button-bar'>
    <div class='btn-group'>
        <button class='btn btn-primary' type='button' id='company-order-2' title='Create new purchase order'>New Purchase Order</button>
    </div>
</div>

{% include "order/po_table.html" with orders=company.outstanding_purchase_orders.all toolbar='#button-bar' %}

{% if company.closed_purchase_orders.count > 0 %}
{% include "order/po_table_collapse.html" with title="Closed Orders" orders=company.closed_purchase_orders.all %}
{% endif %}

{% endblock %}

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

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

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

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

    $("#po-table").bootstrapTable({
        search: true,
        sortable: true,
    });

{% endblock %}