Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

15.6 KB
Raw Blame
@model OrderListModel
@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = Loc["Admin.Orders"];
}
<form asp-area="@Constants.AreaAdmin" asp-controller="Order" asp-action="List" method="post">
    @* The product list's shape: exports and invoices in the overflow menu, the billing email as
       the quick search with the rest of the criteria behind the Filters toggle, and the grid in a
       flush card above a bulk bar. There is no Add new, so Search is the one primary action. The
       ids the scripts below look up are unchanged. *@
    <admin-page title="@Loc["Admin.Orders"]" icon="bi-basket">
        <page-actions>
            <admin-action-menu text="@Loc["Admin.Common.Export"]">
                <admin-action submit="true" name="exportexcel-all"
                              url="@Url.Action("ExportExcelAll", new { area = Constants.AreaAdmin })"
                              icon="bi-download" text="@Loc["Admin.Common.ExportToExcel.All"]"/>
                <admin-action id="exportexcel-selected" icon="bi-download"
                              text="@Loc["Admin.Common.ExportToExcel.Selected"]"/>
                <admin-action submit="true" name="pdf-invoice-all"
                              url="@Url.Action("PdfInvoiceAll", new { area = Constants.AreaAdmin })"
                              icon="bi-file-earmark-pdf" text="@Loc["Admin.Orders.PdfInvoice.All"]"/>
                <admin-action id="pdf-invoice-selected" icon="bi-file-earmark-pdf"
                              text="@Loc["Admin.Orders.PdfInvoice.Selected"]"/>
            </admin-action-menu>
            <vc:admin-widget widget-zone="order_list_buttons" additional-data="null"/>
        </page-actions>

        <admin-filters id="order-filters" submit-id="search-orders">
            <filters-search>
                <admin-input asp-for="BillingEmail"/>
            </filters-search>
            <admin-field asp-for="GoDirectlyToNumber">
                <div class="input-group">
                    <admin-input asp-for="GoDirectlyToNumber"/>
                    <input type="submit" name="go-to-order-by-number" id="gotoorderbynumber" asp-action="GoToOrderId"
                           class="btn btn-outline-secondary" value="@Loc["Admin.Common.Go"]"/>
                </div>
            </admin-field>
            <div class="grand-range">
                <admin-field asp-for="StartDate"/>
                <admin-field asp-for="EndDate"/>
            </div>
            <admin-field asp-for="OrderGuid"/>
            <admin-field asp-for="BillingCountryId" asp-items="Model.AvailableCountries"/>
            <admin-field asp-for="ProductId">
                <input class="form-control" type="text" id="search-product-name" autocomplete="off"/>
                <span id="search-product-friendly-name"></span>
                <input type="button" id="search-product-clear" class="btn btn-outline-secondary btn-sm" style="display:none;" value="@Loc["Admin.Common.Clear"]"/>
                @Html.TextBoxFor(model => model.ProductId, new { autocomplete = "off", style = "display:none;" })
                <script>
                    $(document).ready(function() {
                        $('#search-product-name').autocomplete({
                            delay: 500,
                            minLength: 3,
                            source: '@(Url.Action("ProductSearchAutoComplete", new { area = Constants.AreaAdmin }))',
                            select: function(event, ui) {
                                $('#@Html.IdFor(model => model.ProductId)').val(ui.item.productid);
                                $('#search-product-friendly-name').text(ui.item.label);

                                $('#search-product-clear').show();
                                return false;
                            }
                        });

                        //remove button
                        $('#search-product-clear').click(function () {
                            $('#@Html.IdFor(model => model.ProductId)').val('0');
                            $('#search-product-friendly-name').text('');
                            $('#search-product-clear').hide();
                            return false;
                        });
                    });
                </script>
            </admin-field>
            <admin-field asp-for="BillingLastName"/>
            <admin-field asp-for="OrderStatusId" asp-items="Model.AvailableOrderStatuses"/>
            <admin-field asp-for="VendorId" asp-items="Model.AvailableVendors"/>
            <admin-field asp-for="ShippingStatusId" asp-items="Model.AvailableShippingStatuses"/>
            <admin-field asp-for="StoreId" asp-items="Model.AvailableStores"/>
            <admin-field asp-for="PaymentStatusId" asp-items="Model.AvailablePaymentStatuses"/>
            <admin-field asp-for="WarehouseId" asp-items="Model.AvailableWarehouses"/>
            <admin-field asp-for="PaymentMethodSystemName" asp-items="Model.AvailablePaymentMethods"/>
            <admin-field asp-for="OrderTag" asp-items="Model.AvailableOrderTags"/>
        </admin-filters>

        <admin-card flush>
            <admin-bulkbar grid-id="orders-grid">
                <button type="button" name="delete-selected" id="delete-selected" class="btn btn-outline-danger btn-sm">
                    <i class="bi bi-trash"></i> @Loc["Admin.Common.Delete.Selected"]
                </button>
            </admin-bulkbar>
            <admin-grid id="orders-grid"
                        read-url="@Url.Action("OrderList", "Order", new { area = Constants.AreaAdmin })"
                        additional-data="additionalData"
                        selectable="Checkbox"
                        on-change="onOrdersSelectionChange">
                <grid-column field="OrderNumber" title="@Loc["Admin.Orders.Fields.Id"]" width="50">
                    <cell-template>
                        <a class="text-decoration-none" href="Edit/{{ Id }}">{{ OrderNumber }}</a>
                    </cell-template>
                </grid-column>
                @* a status is a chip: pending waits, complete is done, cancelled is stopped *@
                <grid-column field="OrderStatus" title="@Loc["Admin.Orders.Fields.OrderStatus"]" width="120">
                    <cell-template>
                        <a class="text-decoration-none orderstatuslist" href="Edit/{{ Id }}">
                            <span data-if="OrderStatusId == 10" class="grand-chip grand-chip--amber">{{ OrderStatus }}</span>
                            <span data-if="OrderStatusId == 30" class="grand-chip grand-chip--green">{{ OrderStatus }}</span>
                            <span data-if="OrderStatusId == 40" class="grand-chip grand-chip--red">{{ OrderStatus }}</span>
                            <span data-if="OrderStatusId != 10 && OrderStatusId != 30 && OrderStatusId != 40" class="grand-chip">{{ OrderStatus }}</span>
                        </a>
                    </cell-template>
                </grid-column>
                <grid-column field="PaymentStatus" title="@Loc["Admin.Orders.Fields.PaymentStatus"]" width="120">
                    <cell-template>
                        <a class="text-decoration-none" href="Edit/{{ Id }}">{{ PaymentStatus }}</a>
                    </cell-template>
                </grid-column>
                <grid-column field="ShippingStatus" title="@Loc["Admin.Orders.Fields.ShippingStatus"]" width="120">
                    <cell-template>
                        <a class="text-decoration-none" href="Edit/{{ Id }}">{{ ShippingStatus }}</a>
                    </cell-template>
                </grid-column>
                @* the name carries the email underneath it *@
                <grid-column field="CustomerEmail" title="@Loc["Admin.Orders.Fields.Customer"]" width="220">
                    <cell-template>
                        <a class="text-decoration-none" href="@Url.Action("Edit", "Customer", new { area = Constants.AreaAdmin })/{{ CustomerId }}">
                            <div class="grand-cell-title">{{ CustomerFullName }}</div>
                        </a>
                        <div class="grand-cell-sub">{{ CustomerEmail }}</div>
                    </cell-template>
                </grid-column>
                @if (!adminAreaSettings.HideStoreColumn)
                {
                    <grid-column field="StoreName" title="@Loc["Admin.Orders.Fields.Store"]" width="150" min-screen-width="770"/>
                }
                <grid-column field="CreatedOn" title="@Loc["Admin.Orders.Fields.CreatedOn"]" width="180" format="{0:G}"/>
                <grid-column field="OrderTotal" title="@Loc["Admin.Orders.Fields.OrderTotal"]" width="150" align="Right"/>
            </admin-grid>
        </admin-card>
    </admin-page>
    <script>
        $(document).ready(function () {

            $('.extend-collapse').hide();
            $('.filter-extend-button').click(function () {
                $('.extend-collapse').toggle("slow");
                $('.filter-text-close').toggle();
            });


        });
    </script>

    <script>

        var selectedIds = [];

        function onOrdersSelectionChange(e) {
            selectedIds = e.selectedIds;
        }

        $(document).ready(function () {

            //search button
            $('#search-orders').click(function () {
                //search
                var grid = GrandAdmin.grids.get('#orders-grid');
                grid.dataSource.page(1); //new search. Set page size to 1
                //grid.dataSource.read(); we already loaded the grid above using "page" function
                GrandAdmin.grids.get('#orders-grid').clearSelection();
                return false;
            });

            $("#@Html.IdFor(model => model.BillingEmail)").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#search-orders").click();
                    return false;
                }
            });

            $("#@Html.IdFor(model => model.BillingLastName)").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#search-orders").click();
                    return false;
                }
            });

            $("#@Html.IdFor(model => model.OrderGuid)").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#search-orders").click();
                    return false;
                }
            });
            $("#@Html.IdFor(model => model.StartDate)").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#search-orders").click();
                    return false;
                }
            });
            $("#@Html.IdFor(model => model.EndDate)").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#search-orders").click();
                    return false;
                }
            });

            $("#@Html.IdFor(model => model.GoDirectlyToNumber)").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#gotoorderbynumber").click();
                    return false;
                }
            });

            $("#search-product-name").keydown(function (event) {
                if (event.keyCode == 13) {
                    $("#search-orders").click();
                    return false;
                }
            });

            $('#delete-selected').click(function(e) {
                GrandAdmin.modal.confirm('@Loc["Admin.Common.AreYouSure"]', {
                    title: '@Loc["Admin.Common.Delete.Selected"]',
                    confirmText: '@Loc["Admin.Common.Delete"]',
                    cancelText: '@Loc["Admin.Common.Cancel"]'
                }).then(function (confirmed) {
                    if (!confirmed) return;

                    var postData = {
                        selectedIds: selectedIds
                    };
                    addAntiForgeryToken(postData);
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: "@(Url.Action("DeleteSelected", "Order", new { area = Constants.AreaAdmin }))",
                        data: postData,
                        complete: function (data) {
                            //reload grid
                            var grid = GrandAdmin.grids.get('#orders-grid');
                            grid.dataSource.read();
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            alert(thrownError);
                        },
                        traditional: true
                    });
                });
                return false;
            });


        });

        function additionalData() {
            var data = {
                StartDate: $('#@Html.IdFor(model => model.StartDate)').val(),
                EndDate: $('#@Html.IdFor(model => model.EndDate)').val(),
                OrderStatusId: $('#@Html.IdFor(model => model.OrderStatusId)').val(),
                PaymentStatusId: $('#@Html.IdFor(model => model.PaymentStatusId)').val(),
                ShippingStatusId: $('#@Html.IdFor(model => model.ShippingStatusId)').val(),
                StoreId: $('#@Html.IdFor(model => model.StoreId)').val(),
                VendorId: $('#@Html.IdFor(model => model.VendorId)').val(),
                WarehouseId: $('#@Html.IdFor(model => model.WarehouseId)').val(),
                BillingEmail: $('#@Html.IdFor(model => model.BillingEmail)').val(),
                BillingLastName: $('#@Html.IdFor(model => model.BillingLastName)').val(),
                BillingCountryId: $('#@Html.IdFor(model => model.BillingCountryId)').val(),
                PaymentMethodSystemName: $('#@Html.IdFor(model => model.PaymentMethodSystemName)').val(),
                ProductId: $('#@Html.IdFor(model => model.ProductId)').val(),
                OrderGuid: $('#@Html.IdFor(model => model.OrderGuid)').val(),
                GoDirectlyToNumber: $('#@Html.IdFor(model => model.GoDirectlyToNumber)').val(),
                OrderTag: $('#@Html.IdFor(model => model.OrderTag)').val(),
            };
            addAntiForgeryToken(data);
            return data;
        }


    </script>
</form>
<script>

    $(document).ready(function () {
        $('#exportxml-selected').click(function (e) {
            e.preventDefault();
            var ids = selectedIds.join(",");
            $('#export-xml-selected-form #selectedIds').val(ids);
            $('#export-xml-selected-form').submit();
            return false;
        });
    });

</script>
<form asp-area="@Constants.AreaAdmin" asp-controller="Order" asp-action="ExportExcelSelected" method="post" id="export-excel-selected-form">

    <input type="hidden" id="selectedIds" name="selectedIds" value=""/>
</form>
<script>

    $(document).ready(function () {
        $('#exportexcel-selected').click(function (e) {
            e.preventDefault();
            var ids = selectedIds.join(",");
            $('#export-excel-selected-form #selectedIds').val(ids);
            $('#export-excel-selected-form').submit();
            return false;
        });
    });

</script>
<form asp-area="@Constants.AreaAdmin" asp-controller="Order" asp-action="PdfInvoiceSelected" method="post" id="pdf-invoice-selected-form">

    <input type="hidden" id="selectedIds" name="selectedIds" value=""/>
</form>

<script>

    $(document).ready(function () {
        $('#pdf-invoice-selected').click(function (e) {
            e.preventDefault();
            var ids = selectedIds.join(",");
            $('#pdf-invoice-selected-form #selectedIds').val(ids);
            $('#pdf-invoice-selected-form').submit();
            return false;
        });
    });

</script>