@model OrderDetailsModel

@using Nop.Core.Domain.Catalog
@using Nop.Core.Domain.Media

@inject MediaSettings mediaSettings

@{
    if (!Model.PrintMode)
    {
        Layout = "_ColumnsOne";
    }
    else
    {
        Layout = "_Print";
    }
    //title
    NopHtml.AddTitleParts(T("PageTitle.OrderDetails").Text);
    //page class
    NopHtml.AppendPageCssClassParts("html-order-details-page");
}
@if (Model.PrintMode)
{
    <script asp-location="Footer">
        $(function () {
            window.print();
        });
    </script>
}
<div class="page order-details-page">
    @if (!Model.PrintMode)
    {
        <div class="page-title">
            <h1>@T("Order.OrderInformation")</h1>
            <a href="@Url.RouteUrl("PrintOrderDetails", new { orderId = Model.Id })" target="_blank" class="btn btn-primary button-2 print-order-button"><i class="fa fa-print" aria-hidden="true"></i> @T("Order.Print")</a>
            @if (!Model.PdfInvoiceDisabled)
            {
                <a href="@Url.RouteUrl("GetOrderPdfInvoice", new { orderId = Model.Id })" class="btn btn-primary button-2 pdf-invoice-button"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> @T("Order.GetPDFInvoice")</a>
            }
        </div>
    }
    <div class="page-body">
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsPageTop, additionalData = Model })
        <div class="order-overview">
            <div class="order-number">
                <strong>@T("Order.Order#")@Model.CustomOrderNumber</strong>
            </div>
            <ul class="order-overview-content">
                <li class="order-date">
                    @T("Order.OrderDate"): @Model.CreatedOn.ToString("D")
                </li>
                <li class="order-status">
                    @T("Order.OrderStatus"): @Model.OrderStatus
                </li>
                <li class="order-total">
                    @T("Order.OrderTotal"): <strong>@Model.OrderTotal</strong>
                </li>
            </ul>
            @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsPageOverview, additionalData = Model })
        </div>
        <div class="order-details-area row">
            <div class="billing-info-wrap col-xs-12 col-sm-6 col-sm-6 col-lg-3 col-xl-3">
                <div class="billing-info">
                    <div class="title">
                        <strong>@T("Order.BillingAddress")</strong>
                    </div>
                    <ul class="info-list">
                        <li class="name">
                            @Model.BillingAddress.FirstName @Model.BillingAddress.LastName
                        </li>
                        <li class="email">
                            @T("Order.Email"): @Model.BillingAddress.Email
                        </li>
                        @if (Model.BillingAddress.PhoneEnabled)
                        {
                            <li class="phone">
                                @T("Order.Phone"): @Model.BillingAddress.PhoneNumber
                            </li>
                        }
                        @if (Model.BillingAddress.FaxEnabled)
                        {
                            <li class="fax">
                                @T("Order.Fax"): @Model.BillingAddress.FaxNumber
                            </li>
                        }
                        @if (Model.BillingAddress.CompanyEnabled && !string.IsNullOrEmpty(Model.BillingAddress.Company))
                        {
                            <li class="company">
                                @Model.BillingAddress.Company
                            </li>
                        }
                        @foreach (var item in Model.BillingAddress.AddressFields)
                        {
                            <li class=@item.Key.ToString().ToLower()>@item.Value</li>
                        }
                        @if (!string.IsNullOrEmpty(Model.VatNumber))
                        {
                            <li class="vat">
                                <span class="label">
                                    @T("Order.VATNumber")
                                </span>
                                <span class="value">
                                    @Model.VatNumber
                                </span>
                            </li>
                        }
                        @if (!string.IsNullOrEmpty(Model.BillingAddress.FormattedCustomAddressAttributes))
                        {
                            <li class="custom-attributes-view">
                                @Html.Raw(Model.BillingAddress.FormattedCustomAddressAttributes)
                            </li>
                        }
                        @if (Model.CustomValues != null)
                        {
                            foreach (var item in Model.CustomValues)
                            {
                                <li class="custom-value">
                                    <span class="label">
                                        @item.Key:
                                    </span>
                                    <span class="value">
                                        @(item.Value != null ? item.Value.ToString() : "")
                                    </span>
                                </li>
                            }
                        }
                    </ul>
                </div>
            </div>
            @if (Model.IsShippable)
            {
                <div class="shipping-info-wrap col-xs-12 col-sm-6 col-sm-6 col-lg-3 col-xl-3">
                    <div class="shipping-method-info">
                        <div class="shipping-info">
                            <div class="title">
                                <strong>@(Model.PickupInStore ? T("Order.PickupAddress") : T("Order.ShippingAddress"))</strong>
                            </div>
                            <ul class="info-list">
                                @if (!Model.PickupInStore)
                                {
                                    <li class="name">
                                        @Model.ShippingAddress.FirstName @Model.ShippingAddress.LastName
                                    </li>
                                    <li class="email">
                                        @T("Order.Email"): @Model.ShippingAddress.Email
                                    </li>
                                    if (Model.ShippingAddress.PhoneEnabled)
                                    {
                                        <li class="phone">
                                            @T("Order.Phone"): @Model.ShippingAddress.PhoneNumber
                                        </li>
                                    }
                                    if (Model.ShippingAddress.FaxEnabled)
                                    {
                                        <li class="fax">
                                            @T("Order.Fax"): @Model.ShippingAddress.FaxNumber
                                        </li>
                                    }
                                    if (Model.ShippingAddress.CompanyEnabled && !string.IsNullOrEmpty(Model.ShippingAddress.Company))
                                    {
                                        <li class="company">
                                            @Model.ShippingAddress.Company
                                        </li>
                                    }
                                    @foreach (var item in Model.ShippingAddress.AddressFields)
                                    {
                                        <li class=@item.Key.ToString().ToLower()>@item.Value</li>
                                    }
                                    if (!string.IsNullOrEmpty(Model.ShippingAddress.FormattedCustomAddressAttributes))
                                    {
                                        <li class="custom-attributes-view">
                                            @Html.Raw(Model.ShippingAddress.FormattedCustomAddressAttributes)
                                        </li>
                                    }
                                    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsShippingAddress, additionalData = Model })
                                }
                                else
                                {
                                    @foreach (var item in Model.PickupAddress.AddressFields)
                                    {
                                        <li class=@item.Key.ToString().ToLower()>@item.Value</li>
                                    }
                                }
                                @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsBillingAddress, additionalData = Model })
                            </ul>
                        </div>
                    </div>
                </div>
            }
            @if (!string.IsNullOrEmpty(Model.PaymentMethod))
            {
                <div class="payment-method-info col-xs-12 col-sm-6 col-sm-6 col-lg-3 col-xl-3">
                    <div class="title">
                        <strong>@T("Order.Payment")</strong>
                    </div>
                    <ul class="info-list">
                        <li class="payment-method">
                            <span class="label">
                                @T("Order.Payment.Method"):
                            </span>
                            <span class="value">
                                @Model.PaymentMethod
                            </span>
                        </li>
                        @if (!Model.PrintMode)
                        {
                            <li class="payment-method-status">
                                <span class="label">
                                    @T("Order.Payment.Status"):
                                </span>
                                <span class="value">
                                    @Model.PaymentMethodStatus
                                </span>
                            </li>
                        }
                        @if (!Model.PrintMode && Model.CanRePostProcessPayment)
                        {
                            @*Complete payment (for redirection payment methods)*@
                            <li class="repost">
                                <form asp-route="OrderDetails" method="post">
                                    <button type="submit" name="repost-payment" class="btn btn-primary button-2 re-order-button">@T("Order.RetryPayment")</button>
                                    <p class="hint">
                                        <em>@T("Order.RetryPayment.Hint")</em>
                                    </p>
                                </form>
                            </li>
                        }
                    </ul>
                </div>
            }
            <div class="shipping-method-info col-xs-12 col-sm-6 col-sm-6 col-lg-3 col-xl-3">
                <div class="title">
                    <strong>@T("Order.Shipping")</strong>
                </div>
                <ul class="info-list">
                    <li class="shipping-method">
                        <span class="label">
                            @T("Order.Shipping.Name"):
                        </span>
                        <span class="value">
                            @Model.ShippingMethod
                        </span>
                    </li>
                    @if (!Model.PrintMode)
                    {
                        <li class="shipping-status">
                            <span class="label">
                                @T("Order.Shipping.Status"):
                            </span>
                            <span class="value">
                                @Model.ShippingStatus
                            </span>
                        </li>
                    }
                </ul>
            </div>
        </div>
        @if (!Model.PrintMode && Model.Shipments.Count > 0)
        {
            <div class="section shipments">
                <div class="title">
                    <strong>@T("Order.Shipments")</strong>
                </div>
                <div class="table-wrapper">
                    <table class="data-table table table-bordered table-hover">
                        <colgroup>
                            <col width="1" />
                            <col />
                            <col />
                            <col />
                            <col />
                        </colgroup>
                        <thead>
                            <tr>
                                <th class="shipment-id">
                                    @T("Order.Shipments.ID")
                                </th>
                                <th class="tracking-number">
                                    @T("Order.Shipments.TrackingNumber")
                                </th>
                                @if (Model.PickupInStore)
                                {
                                    <th class="ready-for-pickup-date">
                                        @T("Order.Shipments.ReadyForPickupDate")
                                    </th>
                                }
                                else
                                {
                                    <th class="shipping-date">
                                        @T("Order.Shipments.ShippedDate")
                                    </th>
                                }
                                <th class="delivery-date">
                                    @T("Order.Shipments.DeliveryDate")
                                </th>
                                <th class="view-details">
                                    @T("Order.Shipments.ViewDetails")
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.Shipments)
                            {
                                <tr>
                                    <td class="shipment-id">
                                        <label>@T("Order.Shipments.ID"):</label>
                                        <span>@item.Id.ToString()</span>
                                    </td>
                                    <td class="tracking-number">
                                        <label>@T("Order.Shipments.TrackingNumber"):</label>
                                        @item.TrackingNumber
                                    </td>
                                    @if (Model.PickupInStore)
                                    {
                                        <td class="ready-for-pickup-date">
                                            <label>@T("Order.Shipments.ReadyForPickupDate"):</label>
                                            @if (item.ReadyForPickupDate.HasValue)
                                            {
                                                <span>@item.ReadyForPickupDate.Value.ToString("D")</span>
                                            }
                                            else
                                            {
                                                <span>@T("Order.Shipments.ReadyForPickupDate.NotYet")</span>
                                            }
                                        </td>
                                    }
                                    else
                                    {
                                        <td class="shipped-date">
                                            <label>@T("Order.Shipments.ShippedDate"):</label>
                                            @if (item.ShippedDate.HasValue)
                                            {
                                                <span>@item.ShippedDate.Value.ToString("D")</span>
                                            }
                                            else
                                            {
                                                <span>@T("Order.Shipments.ShippedDate.NotYet")</span>
                                            }
                                        </td>
                                    }
                                    <td class="delivery-date">
                                        <label>@T("Order.Shipments.DeliveryDate"):</label>
                                        @if (item.DeliveryDate.HasValue)
                                        {
                                            <span>@item.DeliveryDate.Value.ToString("D")</span>
                                        }
                                        else
                                        {
                                            <span>@T("Order.Shipments.DeliveryDate.NotYet")</span>
                                        }
                                    </td>
                                    <td class="view-details">
                                        <a href="@Url.RouteUrl("ShipmentDetails", new { shipmentId = item.Id })" title="@T("Order.Shipments.ViewDetails")">@T("Order.Shipments.ViewDetails")</a>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        }
        @if (Model.Items.Count > 0)
        {
            if (!Model.PrintMode && Model.OrderNotes.Count > 0)
            {
                <div class="section order-notes">
                    <div class="title">
                        <strong>@T("Order.Notes")</strong>
                    </div>
                    <div class="table-wrapper">
                        <table class="data-table table table-bordered table-hover">
                            <colgroup>
                                <col />
                                <col />
                            </colgroup>
                            <thead>
                                <tr>
                                    <th class="created-on">
                                        @T("Order.Notes.CreatedOn")
                                    </th>
                                    <th class="note">
                                        @T("Order.Notes.Note")
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model.OrderNotes)
                                {
                                    <tr>
                                        <td class="created-on">
                                            @item.CreatedOn.ToString()
                                        </td>
                                        <td class="note">
                                            @Html.Raw(item.Note)
                                            @if (item.HasDownload)
                                            {
                                                <p class="download">
                                                    <a href="@Url.RouteUrl("GetOrderNoteFile", new { ordernoteid = item.Id })">@T("Order.Notes.Download")</a>
                                                </p>
                                            }
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            }
            @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsPageBeforeproducts, additionalData = Model })
            <div class="section products">
                <div class="title">
                    <strong>@T("Order.Product(s)")</strong>
                </div>
                <div class="table-wrapper">
                    <table class="data-table table table-bordered table-hover">
                        <colgroup>
                            @if (Model.ShowSku)
                            {
                                <col width="1" />
                            }

                            @if (Model.ShowProductThumbnail)
                            {
                                <col width="1" />
                            }

                            <col />
                            @if (Model.ShowVendorName)
                            {
                                <col width="1" />
                            }
                            <col width="1" />
                            <col width="1" />
                            <col width="1" />
                        </colgroup>
                        <thead>
                            <tr>
                                @if (Model.ShowSku)
                                {
                                    <th class="sku">
                                        @T("Order.Product(s).SKU")
                                    </th>
                                }
                                @if (Model.ShowProductThumbnail)
                                {
                                    <th class="picture">
                                        @T("Order.Product(s).Image")
                                    </th>
                                }
                                <th class="name">
                                    @T("Order.Product(s).Name")
                                </th>
                                @if (Model.ShowVendorName)
                                {
                                    <th class="vendor">
                                        @T("Order.Product(s).VendorName")
                                    </th>
                                }
                                <th class="price">
                                    @T("Order.Product(s).Price")
                                </th>
                                <th class="quantity">
                                    @T("Order.Product(s).Quantity")
                                </th>
                                <th class="total">
                                    @T("Order.Product(s).Total")
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.Items)
                            {
                                <tr>
                                    @if (Model.ShowSku)
                                    {
                                        <td class="sku">
                                            <label class="td-title">@T("Order.Product(s).SKU"):</label>
                                            <span class="sku-number">@item.Sku</span>
                                        </td>
                                    }
                                    @if (Model.ShowProductThumbnail)
                                    {
                                        <td class="picture">
                                            <a href="@(Url.RouteUrl<Product>(new {SeName = item.ProductSeName}))">
                                                <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" width="@mediaSettings.DefaultImageQuality" />
                                            </a>
                                        </td>
                                    }
                                    <td class="product">
                                        @if (!Model.PrintMode)
                                        {
                                            <em><a href="@(Url.RouteUrl<Product>(new { SeName = item.ProductSeName }))">@item.ProductName</a></em>
                                        }
                                        else
                                        {
                                            @item.ProductName
                                        }
                                        @if (!string.IsNullOrEmpty(item.AttributeInfo))
                                        {
                                            <div class="attributes">
                                                @Html.Raw(item.AttributeInfo)
                                            </div>
                                        }
                                        @if (!string.IsNullOrEmpty(item.RentalInfo))
                                        {
                                            <div class="rental-info">
                                                @Html.Raw(item.RentalInfo)
                                            </div>
                                        }
                                        @if (item.DownloadId > 0)
                                        {
                                            <div class="download">
                                                <a class="btn btn-secondary" href="@Url.RouteUrl("GetDownload", new { orderItemId = item.OrderItemGuid })">@T("DownloadableProducts.Fields.Download")</a>
                                            </div>
                                        }
                                        @if (item.LicenseId > 0)
                                        {
                                            <div class="download license">
                                                <a class="btn btn-secondary" href="@Url.RouteUrl("GetLicense", new {orderItemId = item.OrderItemGuid})">@T("DownloadableProducts.Fields.DownloadLicense")</a>
                                            </div>
                                        }
                                        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsProductLine, additionalData = item })
                                    </td>
                                    @if (Model.ShowVendorName)
                                    {
                                        <td class="vendor">
                                            <label class="td-title">@T("Order.Product(s).VendorName"):</label>
                                            <span class="vendor-name">@item.VendorName</span>
                                        </td>
                                    }
                                    <td class="unit-price">
                                        <label class="td-title">@T("Order.Product(s).Price"):</label>
                                        <span class="product-unit-price">@item.UnitPrice</span>
                                    </td>
                                    <td class="quantity">
                                        <label class="td-title">@T("Order.Product(s).Quantity"):</label>
                                        <span class="product-quantity">@item.Quantity</span>
                                    </td>
                                    <td class="total">
                                        <label class="td-title">@T("Order.Product(s).Total"):</label>
                                        <span class="product-subtotal">@item.SubTotal</span>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                @if (Model.Items.Count > 0 && Model.DisplayTaxShippingInfo)
                {
                    var inclTax = Model.PricesIncludeTax;
                    //tax info is already included in the price (incl/excl tax). that's why we display only shipping info here
                    //of course, you can modify appropriate locales to include VAT info there
                    <div class="tax-shipping-info">
                        @T(inclTax ? "Order.TaxShipping.InclTax" : "Order.TaxShipping.ExclTax", Url.RouteTopicUrl("shippinginfo"))
                    </div>
                }
            </div>
            @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsPageAfterproducts, additionalData = Model })
            <div class="section options">
                @if (!string.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
                    <div class="selected-checkout-attributes">
                        @Html.Raw(Model.CheckoutAttributeInfo)
                    </div>
                }
            </div>
            <div class="section totals">
                <div class="total-info">
                    <table class="cart-total table table-bordered table-hover">
                        <tbody>
                            <tr>
                                <td class="cart-total-left">
                                    <label>@T("Order.SubTotal"):</label>
                                </td>
                                <td class="cart-total-right">
                                    <span>@Model.OrderSubtotal</span>
                                </td>
                            </tr>
                            @if (!string.IsNullOrEmpty(Model.OrderSubTotalDiscount))
                            {
                                <tr>
                                    <td class="cart-total-left">
                                        <label>@T("Order.SubTotalDiscount"):</label>
                                    </td>
                                    <td class="cart-total-right">
                                        <span>@Model.OrderSubTotalDiscount</span>
                                    </td>
                                </tr>
                            }
                            @if (Model.IsShippable)
                            {
                                <tr>
                                    <td class="cart-total-left">
                                        <label>@T("Order.Shipping"):</label>
                                    </td>
                                    <td class="cart-total-right">
                                        <span>@Model.OrderShipping</span>
                                    </td>
                                </tr>
                            }
                            @if (!string.IsNullOrEmpty(Model.PaymentMethodAdditionalFee))
                            {
                                <tr>
                                    <td class="cart-total-left">
                                        <label>@T("Order.PaymentMethodAdditionalFee"):</label>
                                    </td>
                                    <td class="cart-total-right">
                                        <span>@Model.PaymentMethodAdditionalFee</span>
                                    </td>
                                </tr>
                            }
                            @if (Model.DisplayTaxRates && Model.TaxRates.Count > 0)
                            {
                                foreach (var taxRate in Model.TaxRates)
                                {
                                    <tr>
                                        <td class="cart-total-left">
                                            <label>@string.Format(T("Order.TaxRateLine").Text, taxRate.Rate):</label>
                                        </td>
                                        <td class="cart-total-right">
                                            <span>@taxRate.Value</span>
                                        </td>
                                    </tr>
                                }
                            }
                            @if (Model.DisplayTax)
                            {
                                <tr>
                                    <td class="cart-total-left">
                                        <label>@T("Order.Tax"):</label>
                                    </td>
                                    <td class="cart-total-right">
                                        <span>@Model.Tax</span>
                                    </td>
                                </tr>
                            }
                            @if (!string.IsNullOrEmpty(Model.OrderTotalDiscount))
                            {
                                <tr>
                                    <td class="cart-total-left">
                                        <label>@T("Order.TotalDiscount"):</label>
                                    </td>
                                    <td class="cart-total-right">
                                        <span>@Model.OrderTotalDiscount</span>
                                    </td>
                                </tr>
                            }
                            @if (Model.GiftCards.Count > 0)
                            {
                                foreach (var gc in Model.GiftCards)
                                {
                                    <tr>
                                        <td class="cart-total-left">
                                            <label>@string.Format(T("Order.GiftCardInfo").Text, gc.CouponCode):</label>
                                        </td>
                                        <td class="cart-total-right">
                                            <span>@gc.Amount</span>
                                        </td>
                                    </tr>
                                }
                            }
                            @if (Model.RedeemedRewardPoints > 0)
                            {
                                <tr>
                                    <td class="cart-total-left">
                                        <label>@string.Format(T("Order.RewardPoints").Text, Model.RedeemedRewardPoints):</label>
                                    </td>
                                    <td class="cart-total-right">
                                        <span>@Model.RedeemedRewardPointsAmount</span>
                                    </td>
                                </tr>
                            }
                            <tr>
                                <td class="cart-total-left">
                                    <label>@T("Order.OrderTotal"):</label>
                                </td>
                                <td class="cart-total-right">
                                    <span><strong>@Model.OrderTotal</strong></span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                @if (!Model.PrintMode)
                {
                    <div class="actions">
                        @if (Model.IsReOrderAllowed)
                        {
                            <button type="button" class="btn btn-primary button-1 re-order-button" onclick="setLocation('@Url.RouteUrl("ReOrder", new { orderId = Model.Id })')">@T("Order.Reorder")</button>
                        }
                        @if (Model.IsReturnRequestAllowed)
                        {
                            <button type="button" class="btn btn-secondary button-2 return-items-button" onclick="setLocation('@Url.RouteUrl("ReturnRequest", new { orderId = Model.Id })')">@T("Order.ReturnItems")</button>
                        }
                    </div>
                }
            </div>
        }
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.OrderDetailsPageBottom, additionalData = Model })
    </div>
</div>
