@using MrCMS.Web.Apps.Ecommerce
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Models
@model MrCMS.Web.Apps.Ecommerce.Entities.Orders.Order
@{
    var orderShipping = Model.ShippingTotal.GetValueOrDefault() - Model.ShippingTax.GetValueOrDefault();
    var nonSystemSalesChannel = Model.SalesChannel != EcommerceApp.DefaultSalesChannel;
}
<div class="row">
    <div class="@(nonSystemSalesChannel ? "col-lg-6" : "col-lg-12")">
        <table class="table table-condensed table-striped">
            <tr>
                <td>Sales Channel</td>
                <td>@Model.SalesChannel</td>
            </tr>
            <tr>
                <td>Customer</td>
                <td>
                    @Html.Raw((Model.User != null ? string.Format("<a href='/Admin/User/Edit/{0}'>", @Model.User.Id) : ""))
                    @Model.OrderEmail
                    @Html.Raw((Model.User != null ? "</a>" : ""))
                </td>
            </tr>
            <tr>
                <td>Order GUID</td>
                <td>@Model.Guid</td>
            </tr>
            <tr>
                <td>Order Date</td>
                <td>@Model.OrderDate</td>
            </tr>
            <tr>
                <td>Status</td>
                <td>@Model.OrderStatus</td>
            </tr>
            <tr>
                <td>Order Subtotal (ex Tax)</td>
                <td>@Model.Subtotal.ToCurrencyFormat()</td>
            </tr>
            <tr>
                <td>Order Shipping (ex Tax)</td>
                <td>@orderShipping.ToCurrencyFormat()</td>
            </tr>
            <tr>
                <td>Order Shipping Tax</td>
                <td>@Model.ShippingTax.ToCurrencyFormat()</td>
            </tr>
            @if (Model.ShippingDiscountAmount > decimal.Zero)
            {
                <tr>
                    <td>Order Shipping Subtotal</td>
                    <td>@Model.ShippingSubtotal.ToCurrencyFormat()</td>
                </tr>
                <tr>
                    <td>Order Shipping Discount</td>
                    <td>@Model.ShippingDiscountAmount.ToCurrencyFormat()</td>
                </tr>
            }
            <tr>
                <td>Order Shipping Total</td>
                <td>@Model.ShippingTotal.ToCurrencyFormat()</td>
            </tr>
            <tr>
                <td>Order Tax</td>
                <td>@Model.Tax.ToCurrencyFormat()</td>
            </tr>
            @if (Model.DiscountAmount != 0)
            {
                <tr>
                    <td>Order Discount</td>
                    <td>@Model.DiscountAmount.ToCurrencyFormat()</td>
                </tr>
            }
            <tr>
                <td>Order Total</td>
                <td>@Model.Total.ToCurrencyFormat()</td>
            </tr>
            @if (Model.TotalPaid != Model.Total)
            {
                <tr>
                    <td>Total Paid</td>
                    <td>@Model.TotalPaid.ToCurrencyFormat()</td>
                </tr>
            }
            @if (Model.RewardPointsAppliedAmount > 0)
            {
                <tr>
                    <td>Reward Point Contribution</td>
                    <td>@Model.RewardPointsAppliedAmount.ToCurrencyFormat()</td>
                </tr>
            }
            @if (Model.TotalRefunds > 0)
            {
                <tr>
                    <td>Order Refunds</td>
                    <td>@Model.TotalRefunds.ToCurrencyFormat()</td>
                </tr>
                <tr>
                    <td>Order Total After refunds</td>
                    <td>@Model.TotalAfterRefunds.ToCurrencyFormat()</td>
                </tr>
            }
            @if (!string.IsNullOrWhiteSpace(Model.GiftMessage))
            {
                <tr>
                    <td>Gift Message</td>
                    <td>@Model.GiftMessage</td>
                </tr>
            }
        </table>
        @{Html.RenderPartial("OrderGiftCards", Model);}
    </div>
    @if (nonSystemSalesChannel)
    {
        <div class="col-lg-6">
            @Html.GetSalesChannelInfo()
        </div>
    }
</div>
@{
    if (Model.OrderRefunds.Count > 0)
    {
        <div class="row">
            <div class="col-lg-12">
                @if (Model.OrderRefunds.Count > 0)
                {
                    <h4>Refunds</h4>
                    <table class="table table-condensed table-striped">
                        <thead>
                            <tr>
                                <th>
                                    Amount
                                </th>
                                <th>
                                    Note
                                </th>
                                <th>
                                    Actions
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.OrderRefunds)
                            {
                                <tr>
                                    <td>
                                        @item.Amount.ToCurrencyFormat()
                                    </td>
                                    <td>
                                        @item.Note
                                    </td>
                                    <td>
                                        <div class="btn-group">
                                            @Html.ActionLink("Delete", "Delete", "OrderRefund", new { id = item.Id }, new { @class = "btn btn-danger btn-xs", data_toggle = "fb-modal" })
                                        </div>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                }
            </div>
        </div>
    }
}
<hr class="small-margin" />
<div class="row">
    <div class="col-lg-6">
        <h4>@Resource("Payment")</h4>

        <table class="table table-condensed table-striped">
            <tr>
                <td>@Resource("Method")</td>
                <td>@Html.DisplayFor(x => x.PaymentMethod)</td>
            </tr>
            <tr>
                <td>@Resource("Status")</td>
                <td>@Html.DisplayFor(x => x.PaymentStatus)</td>
            </tr>
        </table>
        @if (Model.PaymentStatus == PaymentStatus.Pending)
        {
            @Html.ActionLink("Mark as Paid", "MarkAsPaid", "Order", new { id = Model.Id, index = false }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
            <span></span>
            @Html.ActionLink("Void", "MarkAsVoided", "Order", new { id = Model.Id, index = false }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
        }
        @if (Model.PaymentStatus == PaymentStatus.Paid)
        {
            <a href="@Url.Action("Add", "OrderRefund", new { orderID = Model.Id, index = false })" class="btn btn-xs btn-default" data-toggle="fb-modal">Add Refund</a>
        }
        @if (Model.PaymentStatus == PaymentStatus.Voided)
        {
            @Html.ActionLink("Mark as Paid", "MarkAsPaid", "Order", new { id = Model.Id, index = false }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
            <span></span>
        }

    </div>
    <div class="col-lg-6">
        <h4>@Resource("Shipping")</h4>

        <table class="table table-condensed">
            <tr>
                <td>@Resource("Method")</td>
                <td>@(!string.IsNullOrWhiteSpace(Model.ShippingMethodName) ? Model.ShippingMethodName : "-")</td>
            </tr>
            <tr>
                <td>@Resource("Status")</td>
                <td>@Html.DisplayFor(x => x.ShippingStatus)</td>
            </tr>
            <tr>
                <td>@Resource("Requested Shipping Date")</td>
                <td>
                    @if (Model.RequestedShippingDate.HasValue)
                    {
                        @Model.RequestedShippingDate.Value.ToString("dd/MM/yyyy")
                    }
                    else
                    {
                        <span>
                            ASAP
                        </span>
                    }
                </td>
            </tr>
            @if (Model.ShippingDate.HasValue)
            {
                <tr>
                    <td>@Resource("Shipped On")</td>
                    <td>@Html.DisplayFor(x => x.ShippingDate)</td>
                </tr>
            }
            @{
                if (!string.IsNullOrEmpty(Model.TrackingNumber))
                {
                    <tr>
                        <td>@Resource("Tracking Number")</td>
                        <td>@Html.DisplayFor(x => x.TrackingNumber)</td>
                    </tr>
                }
            }
        </table>
        @if (Model.ShippingStatus != ShippingStatus.Shipped)
        {
            @Html.ActionLink("Mark as Shipped", "MarkAsShipped", "Order", new { id = Model.Id, index = false }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
        }
        @Html.ActionLink("Set tracking number", "SetTrackingNumber", "Order", new { id = Model.Id }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
    </div>
</div>
<hr />
<div class="row">
    <div class="col-lg-6">
        <h4>
            Shipping Address
            @Html.ActionLink("Edit", "Edit", "Address", new { Id = Model.Id }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
        </h4>
        <div class="pull-left">
            @if (Model.ShippingAddress != null)
            {
                @Html.Raw(Model.ShippingAddress.GetDescriptionHtml())

                <p>@Model.ShippingAddress.PhoneNumber</p>
            }
        </div>
    </div>
    <div class="col-lg-6">
        <h4>
            Billing Address
            @Html.ActionLink("Edit", "Edit", "Address", new { Id = Model.Id }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
        </h4>
        <div class="pull-left">
            @if (Model.BillingAddress != null)
            {
                @Html.Raw(Model.BillingAddress.GetDescriptionHtml())

                <p>@Model.BillingAddress.PhoneNumber</p>
            }
        </div>
    </div>
</div>
