<commit_before>{% extends "base.html" %}

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

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

{% block content %}

<h3>{% trans "Sales Orders" %}</h3>
<hr>

<div class='calendar-container' style="width: 80%; align-items: center; align-content: center;">
    <div id='calendar'></div>
</div>

<div id='table-buttons'>
    <div class='button-toolbar container-fluid' style='float: right;'>
        {% if roles.sales_order.add %}
        <button class='btn btn-primary' type='button' id='so-create' title='{% trans "Create new sales order" %}'>
            <span class='fas fa-plus-circle'></span> {% trans "New Sales Order" %}</button>
        {% endif %}
        <div class='filter-list' id='filter-list-salesorder'>
            <!-- An empty div in which the filter list will be constructed -->
        </div>
    </div>
</div>

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

{% endblock %}

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

<script type='text/javascript'>

    function startDate(calendar) {
        return calendar.currentData.dateProfile.activeRange.start.toISOString().split("T")[0];
    }

    function endDate(calendar) {
        return calendar.currentData.dateProfile.activeRange.end.toISOString().split("T")[0];
    }

    function loadOrderEvents(calendar) {

        var start = startDate(calendar);
        var end = endDate(calendar);

        // Clear existing orders from the calendar
        var events = calendar.getEvents();

        events.forEach(function(event) {
            event.remove();
        });

        // Request orders from the server within specified date range
        inventreeGet(
            '{% url "api-so-list" %}',
            {
                customer_detail: true,
                min_date: start,
                max_date: end,
            },
            {
                success: function(response) {

                    var prefix = '{% settings_value "SALESORDER_REFERENCE_PREFIX" %}';

                    for (var idx = 0; idx < response.length; idx++) {
                        var order = response[idx];

                        var date = order.creation_date;

                        if (order.shipment_date) {
                            date = order.shipment_date;
                        } else if (order.target_date) {
                            date = order.target_date;
                        }

                        var title = `${prefix}${order.reference} - ${order.customer_detail.name}`;

                        // Default color is blue
                        var color = '#4c68f5';

                        // Overdue orders are red
                        if (order.overdue) {
                            color = '#c22525';
                        } else if (order.status == {{ SalesOrderStatus.SHIPPED }}) {
                            color = '#25c235';
                        }

                        var event = {
                            title: title,
                            start: date,
                            end: date,
                            url: `/order/sales-order/${order.pk}/`,
                            backgroundColor: color,
                        };

                        calendar.addEvent(event);
                    }
                }
            }
        );
    }

    var calendar = null;

    document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');
        calendar = new FullCalendar.Calendar(calendarEl, {
            initialView: 'dayGridMonth',
            nowIndicator: true,
            aspectRatio: 2,
            width: '80%',
            datesSet: function() {
                loadOrderEvents(calendar);
            },
        });

        calendar.render();

    });
</script>
{% endblock %}

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


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

$("#so-create").click(function() {
    launchModalForm("{% url 'so-create' %}",
        {
            follow: true,
        }
    );
});

{% endblock %}<commit_msg>Switch between calendar and list view for sales orders<commit_after>{% extends "base.html" %}

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

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

{% block content %}

<h3>{% trans "Sales Orders" %}</h3>
<hr>
    

<div id='table-buttons'>
    <div class='button-toolbar container-fluid' style='float: right;'>
        {% if roles.sales_order.add %}
        <button class='btn btn-primary' type='button' id='so-create' title='{% trans "Create new sales order" %}'>
            <span class='fas fa-plus-circle'></span> {% trans "New Sales Order" %}</button>
        {% endif %}
        <button class='btn btn-default' type='button' id='view-calendar' title='{% trans "Display calendar view" %}'>
            <span class='fas fa-calendar-alt'></span>
        </button>
        <button class='btn btn-default' type='button' id='view-list' title='{% trans "Display list view" %}'>
            <span class='fas fa-th-list'></span>
        </button>
        <div class='filter-list' id='filter-list-salesorder'>
            <!-- An empty div in which the filter list will be constructed -->
        </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>



{% endblock %}

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

<script type='text/javascript'>

    function startDate(calendar) {
        return calendar.currentData.dateProfile.activeRange.start.toISOString().split("T")[0];
    }

    function endDate(calendar) {
        return calendar.currentData.dateProfile.activeRange.end.toISOString().split("T")[0];
    }

    function loadOrderEvents(calendar) {

        var start = startDate(calendar);
        var end = endDate(calendar);

        // Clear existing orders from the calendar
        var events = calendar.getEvents();

        events.forEach(function(event) {
            event.remove();
        });

        // Request orders from the server within specified date range
        inventreeGet(
            '{% url "api-so-list" %}',
            {
                customer_detail: true,
                min_date: start,
                max_date: end,
            },
            {
                success: function(response) {

                    var prefix = '{% settings_value "SALESORDER_REFERENCE_PREFIX" %}';

                    for (var idx = 0; idx < response.length; idx++) {
                        var order = response[idx];

                        var date = order.creation_date;

                        if (order.shipment_date) {
                            date = order.shipment_date;
                        } else if (order.target_date) {
                            date = order.target_date;
                        }

                        var title = `${prefix}${order.reference} - ${order.customer_detail.name}`;

                        // Default color is blue
                        var color = '#4c68f5';

                        // Overdue orders are red
                        if (order.overdue) {
                            color = '#c22525';
                        } else if (order.status == {{ SalesOrderStatus.SHIPPED }}) {
                            color = '#25c235';
                        }

                        var event = {
                            title: title,
                            start: date,
                            end: date,
                            url: `/order/sales-order/${order.pk}/`,
                            backgroundColor: color,
                        };

                        calendar.addEvent(event);
                    }
                }
            }
        );
    }

    var calendar = null;

    document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('sales-order-calendar');
        calendar = new FullCalendar.Calendar(calendarEl, {
            initialView: 'dayGridMonth',
            nowIndicator: true,
            aspectRatio: 2.5,
            width: '80%',
            datesSet: function() {
                loadOrderEvents(calendar);
            },
        });

        calendar.render();

    });
</script>
{% endblock %}

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

$("#sales-order-calendar").hide();
$("#view-list").hide();

$('#view-calendar').click(function() {
    // Hide the list view, show the calendar view
    $("#sales-order-table").hide();
    $("#view-calendar").hide();
    $(".fixed-table-pagination").hide();
    $(".columns-right").hide();
    $(".search").hide();
    
    $("#sales-order-calendar").show();
    $("#view-list").show();
});

$("#view-list").click(function() {
    // Hide the calendar view, show the list view
    $("#sales-order-calendar").hide();
    $("#view-list").hide();

    $(".fixed-table-pagination").show();
    $(".columns-right").show();
    $(".search").show();
    $("#sales-order-table").show();
    $("#view-calendar").show();
});

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

$("#so-create").click(function() {
    launchModalForm("{% url 'so-create' %}",
        {
            follow: true,
        }
    );
});

{% endblock %}
{'fraction_non_alphanumeric': 0.14886494403180248, 'fraction_numerical': 0.005335286117794749, 'mean_word_length': 1.6526082130965594, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1209329', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2524, 'n_words': 551}