{% extends "page_base.html" %}

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

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

{% block breadcrumb_list %}
{% endblock %}

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

{% block actions %}
{% if roles.sales_order.add %}
<button class='btn btn-success' type='button' id='so-create' title='{% trans "Create new sales order" %}'>
    <span class='fas fa-plus-circle'></span> {% trans "New Sales 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'>
                {% 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="salesorder" %}
            </div>
        </div>
    </div>

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

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

{% endblock %}

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

loadSalesOrderTable("#sales-order-table", {
    url: "{% url 'api-so-list' %}",
});

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

    var orders = [];

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

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

$("#so-create").click(function() {
    createSalesOrder();
});

{% endblock %}
