@model PantheonRA.BackOffice.Models.PayOrdersGridFilterModel
@using PantheonRA.BackOffice.Models
@using PantheonRA.WebApi.Contracts

@{
    ViewBag.Title = "PayOrdersIndex";
    Layout = null;
    var date = DateTime.Now.AddYears(-1).ToString("{0:dd.MM.yyyy}");
}

@Html.Hidden("ExportXml", Url.Action("DownloadXml", "PayOrders"))
@Html.Hidden("DeletePN", Url.Action("Delete", "PayOrders"))
@Html.Hidden("AcKeyFromMove", Model.AcKey)
@Html.Hidden("ButtonNameReturnToPreparation", Loc.ReturnToPreparation)
@Html.Hidden("ButtonNameReturnToPayment", Loc.ReturnToPayment)
@Html.Hidden("ButtonNameReturnToShipped", Loc.ReturnToShipped)
@Html.Hidden("StatusError", PayOrderStatusCode.Errors)
@Html.HiddenFor(model => model.DefaultDecimalPlacesPrice)
@Html.HiddenFor(model => model.DefaultDecimalPlacesQuantity)
@Html.HiddenFor(model => model.DefaultDecimalPlacesValue)


@{
    var docTypeFull = Model.DocTypes.Where(x => x.Key.ToString() == Model.DocumentType).FirstOrDefault().Text;
}

<style>
    .select2-selection__rendered {
        max-width: 250px !important;
    }
</style>

<div id="payOrdersData">
    <div class="row document-head">

        <div class="col-md-3 m-l-md">
            <div class="form-group">
                <label class="control-label">@Loc.SearchFilter</label>
                @Html.TextBoxFor(model => model.Keywords, new { @id = "Keywords", @class = "form-control search-input", @placeholder = Loc.EnterSearchString, autocomplete = "off" })
            </div>
        </div>

        <div class="col-md-3 m-l-md">
            <div class="form-group">
                @Html.LabelFor(model => model.DocumentType, Loc.DocumentType, new { @class = "control-label select2-label" })
                <select id="DocTypes"
                        name="DocTypes"
                        data-placeholder="@Loc.DocumentType"
                        class="form-control select2withAPI"
                        data-selector-separator=" - "
                        data-url=@Url.Action("GetDocTypes", "PayOrders")>
                    <option value="@Model.DocumentType" selected="selected">@docTypeFull</option>
                </select>
            </div>
        </div>
        <div class="col-md-2 m-l-md" id="datePicker">
            <div class="form-group">
                @Html.LabelFor(model => model.DateFrom, Loc.Date, new { @class = "control-label" })
                <div class="input-group">
                    <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                    @Html.TextBoxFor(model => model.DateFrom, Model.DateFrom.ToString(Loc.DateFormat),
                        HtmlAttributesHelper.CreateInputAttributes("form-control filter-datepicker", "DateFrom", false, Loc.DateFrom))
                </div>
            </div>
        </div>
    </div>
    <div class="document-body">
        <table id="payorders" data-grid-id="payorders" data-url="@Url.Action("PayOrdersList", "PayOrders", new { docType = Model.DocumentType })" class="table table-hover table-striped">
            <thead>
                <tr>
                    <th class="dt-head-center"></th>
                    <th data-url="@Url.Action("Edit","PayOrders")?acKey=">@Loc.AcKey</th>
                    <th><span class="m-l">@Loc.Bank</span></th>
                    <th class="text-left">@Loc.Date</th>
                    <th class="text-right">@Loc.Amount</th>
                    <th>@Loc.DateDue</th>
                    <th class="text-left">@Loc.Recipient</th>
                    <th class="text-left" data-url="@Url.Action("Edit","ReceivedBills")?id=">@Loc.LinkDoc</th>
                    <th class="text-left">@Model.PurposeLabel</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<div id="payOrdersErrors" class="m-t-lg">
    <table class="list-table">
        <thead>
            <tr>
                <th style="width: 10%">@Loc.Number</th>
                <th style="width: 20%">@Loc.AcKey</th>
                <th style="width: 70%">@Loc.Error</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var err in TempData["DownloadXml"] as IEnumerable<PayOrderXmlError> ?? new List<PayOrderXmlError>())
            {
                <tr>
                    <td>
                        @err.OrdinalNumber
                    </td>
                    <td>
                        @err.AcKey
                    </td>
                    <td>
                        @err.ErrorText
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>


@Scripts.Render("~/bundles/payOrders")
@Html.Hidden("status", Model.Status, new { id = "status" })
@Html.Hidden("docType", Model.DocumentType, new { id = "docType" })

<script src="~/Scripts/custom/global-helpers.js"></script>
<script src="~/Scripts/custom/initializers.js"></script>

<script>
    $(document).ready(function () {
        initializePayOrders();
    });
</script>

@* TODO: remove after refactor *@
@section pageScripts
                            {
    @Scripts.Render("~/bundles/validation")
}

<script>
    $(document).ready(function () {
        clearMessages();
    });
</script>

<style>
    .select2-selection, .select2-selection--single {
        max-height: 10px;
    }

    .select2-selection__rendered {
        border: none !important;
    }
    /* This will be removed after select2 corrections. */
    .select2-selection {
        padding-top: 0px !important;
        margin-bottom: 5px !important;
        background-color: unset !important;
    }
</style>