ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Shared/Components/OrderReportLatestOrder/Default.cshtml
@model bool

<div id="latest-orders-grid"></div>

<script>
    $(document).ready(function () {
        $("#latest-orders-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("OrderList", "Order"))",
                            type: "POST",
                            dataType: "json",
                            data: additionalData
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors"
                    },
                    requestEnd: function (e) {
                        if (e.type == "read") {
                            var response = e.response;
                            if (response) {
                                //store extra data
                                reportAggregates = e.response["ExtraData"];
                            }
                        }
                    },
                    error: function(e) {
                        display_kendoui_grid_error(e);
                        // Cancel the changes
                        this.cancelChanges();
                    },
                    pageSize: 5,
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                pageable: {
                    refresh: true,
                    pageSizes: [5,10,15]
                },
                editable: {
                    confirmation: false,
                    mode: "inline"
                },
                scrollable: false,
                columns: [
                    {
                        field: "OrderNumber",
                        title: "@T("Admin.Orders.Fields.Id")",
                        width: 50,
                        template: '<a class="k-link" href="Admin/Order/Edit/#=Id#">#=OrderNumber#</a>',
                    },
                    {
                        field: "CustomerEmail",
                        title: "@T("Admin.Orders.Fields.Customer")",
                        width: 300,
                        @if (!Model)
                        {
                            <text>
                                template: '<a class="k-link" href="@Url.Action("Edit", "Customer")/#=CustomerId#">#=CustomerFullName# (#=CustomerEmail#)</a>'
                            </text>
                        }
                    },
                    {
                        field: "StoreName",
                        title: "@T("Admin.Orders.Fields.Store")",
                        width: 200,
                        headerAttributes: { style: "text-align:center" },
                        attributes: { style: "text-align:center" },
                    },
                    {
                        field: "PaymentStatus",
                        title: "@T("Admin.Orders.Fields.PaymentStatus")",
                        width: 120,
                        headerAttributes: { style: "text-align:center" },
                        attributes: { style: "text-align:center" },
                    },

                    @if (!Model)
                    {
                        //a vendor does not have access to this functionality
                        <text>{
                        field: "OrderTotal",
                        title: "@T("Admin.Orders.Fields.OrderTotal")",
                        width: 200,
                        headerAttributes: { style: "text-align:center" },
                        attributes: { style: "text-align:center" }
                        },</text>
                    }
                    {
                        field: "CreatedOn",
                        title: "@T("Admin.Orders.Fields.CreatedOn")",
                        width: 200,
                        type: "date",
                        format: "{0:G}",
                        headerAttributes: { style: "text-align:center" },
                        attributes: { style: "text-align:center" },
                    }
                ]
            } );


        function additionalData() {
            var data = {
                startdate: $('#dashboard-report-range').data('daterangepicker').startDate.format('YYYY-MM-DD'),
                endDate: $('#dashboard-report-range').data('daterangepicker').endDate.format('YYYY-MM-DD'),
            };
            addAntiForgeryToken(data);
            return data;
        }
    });

</script>
