@using PantheonRA.BackOffice
@using PantheonRA.WebApi.Contracts.Enums
@using PAW.Contracts.Enums

@inherits PantheonRA.BackOffice.Pages.AuthPage<PantheonRA.BackOffice.Models.TravelOrdersPrintFilterModel>
@{
    bool canAccessOthers = _authInfo.CanAccess(Permissions.DENARPOTNALIZPISI);
    bool canAccessOwn = _authInfo.CanAccess(Permissions.DENARPNSSIZPISI);
}

<div class="wrapper wrapper-content">
    <div class="tabs-container">

        @Html.Partial("~/Views/TravelOrders/_TravelOrdersTabNavigation.cshtml")

        @if (canAccessOthers || canAccessOwn)
        {
            <div class="tab-content full-height">
                <div class="row buttons-tabbed">

                    <a href="@Url.Action("Index", "TravelOrders")" class="btn btn-transparent pull-right close-btn"><i class="fal fa-times"></i></a>

                    <button id="printButton" type="button" onclick="print()" title="@Loc.Print"
                            class="btn btn-primary pull-right">
                        <i class="far fa-print m-r-xs"></i>
                        <span class="visible-lg-inline visible-md-inline">@Loc.Print</span>
                    </button>

                </div>

                <div class="row full-height margin-b-none">

                    <div class="col-md-3 col-xs-6 tabs-column-container full-height overflow-x-auto column-full-height-border-right">
                        <div class="tabs-container">
                            <ul class="nav nav-tabs horizontal-menu">
                                <li class="active divided-tab-1"><a data-toggle="tab" href="#printOptions" class="local-tab">@Loc.PrintoutType</a></li>
                            </ul>
                        </div>
                        <div class="tab-content">
                            <input id="ReportType" hidden />
                            <div id="printOptions" class="tab-pane fade in active m-l-n m-r-n">
                                <div class="print-options-container">
                                    @if (Model.ReportTree != null)
                                    {
                                        foreach (var report in Model.ReportTree)
                                        {
                                            <div class="print-option-group report-type" id="@report.Id">
                                                <div class="print-option-label p-l-sm" onclick="togglePrintOptionGroup(this)">
                                                    <div class="print-option-border"></div>
                                                    <span class="caret caret-left"></span>
                                                    <span>
                                                        @report.Category
                                                    </span>
                                                </div>
                                                @foreach (var formReport in report.FormReports)
                                                {
                                                    <div onclick="selectPrintTypeTravelOrders(this, '@formReport.Report')" id="@formReport.Report" class="preview-print-option cursor-pointer" data-print="@formReport.Report" data-fisc="@formReport.Fiscalize">
                                                        <div class="print-option-border"></div>
                                                        <div class="print-option-border-horizontal"></div>
                                                        <a title="@formReport.Report - @formReport.Name">
                                                            @formReport.Report - @formReport.Name
                                                        </a>
                                                    </div>
                                                }
                                                @if (report.SubCategory != null)
                                                {
                                                    var subCategoryCounter = 0;
                                                    foreach (var subCategory in report.SubCategory)
                                                    {
                                                        var notFirstSubCategory = subCategoryCounter == 0 ? false : true;
                                                        <div class="print-option-group" id="subCategory-@subCategory.SubCategory">
                                                            <div class="print-option-label p-l-md" onclick="togglePrintOptionGroup(this)">
                                                                <div class="print-option-border"></div>
                                                                <div class="print-option-border-horizontal" @(notFirstSubCategory ? "hidden" : "")></div>
                                                                <span class="caret caret-left"></span>
                                                                <span>
                                                                    @subCategory.SubCategory
                                                                </span>
                                                            </div>
                                                            @foreach (var subFormReport in subCategory.FormReports)
                                                            {
                                                                <div onclick="selectPrintTypeTravelOrders(this, '@subFormReport.Report')" class="preview-print-option cursor-pointer p-l-md" data-print="@subFormReport.Report" data-fisc="@subFormReport.Fiscalize">
                                                                    <div class="print-option-border"></div>
                                                                    <div class="print-option-border-horizontal"></div>
                                                                    <a title="@subFormReport.Report - @subFormReport.Name">
                                                                        @subFormReport.Report - @subFormReport.Name
                                                                    </a>
                                                                </div>
                                                            }
                                                        </div>
                                                        subCategoryCounter++;
                                                    }
                                                }
                                            </div>
                                        }
                                    }
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-9 col-xs-6">
                        <h3 class="m-t-md">@Loc.Criteria</h3>
                        <div class="row">
                            <div class="form-horizontal form-md">
                                <div class="col-md-8">
                                    <div class="form-group">
                                        @Html.Label("DocumentTypes", Loc.DocumentType, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("DocumentTypes",
                                            new SelectList(Model.DocTypes, "DocType", "DocName", null), Loc.ShowAll,
                                            HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker clear-select",
                                             "DocumentTypes",
                                             false,
                                             Loc.DocumentType,
                                             true,
                                             new
                                             {
                                                 @multiple = "multiple",
                                                 data_live_search = "true",
                                                 @title = Loc.ShowAll
                                             },
                                             false)
                                            )
                                        </div>
                                    </div>

                                    @*Selectpickers*@
                                    <div class="form-group selectpicker-dropdown key-from-to">
                                        @Html.Label("AcKeyFrom", Loc.Number, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <select id="AcKeyFrom"
                                                    name="AcKeyFrom"
                                                    data-placeholder="@Loc.Number"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("GetTravelOrdersKeysLookupItems", "TravelOrders")"
                                                    data-column-names="@string.Format("{0}", Loc.AcKey)"
                                                    data-bootstrap-columns="col-md-12"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                        @Html.Label("AcKeyTo", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <select id="AcKeyTo"
                                                    name="AcKeyTo"
                                                    data-placeholder="@Loc.Number"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("GetTravelOrdersKeysLookupItems", "TravelOrders")"
                                                    data-column-names="@string.Format("{0}", Loc.AcKey)"
                                                    data-bootstrap-columns="col-md-12"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                    </div>

                                    @*Datepickers*@
                                    <div class="form-group travel-orders-dates">
                                        @Html.Label("From", Loc.TravelOrdersFrom, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("TravelOrdersFrom", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "TravelOrdersFrom",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                        @Html.Label("To", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("TravelOrdersTo", null,
                                                HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                "TravelOrdersTo",
                                                false,
                                                Loc.To))
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group calc-form-dates">
                                        @Html.Label("From", Loc.CalcFrom, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("DateCalcFrom", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "DateCalcFrom",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                        @Html.Label("To", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("DateCalcTo", null,
                                                HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                "DateCalcTo",
                                                false,
                                                Loc.To))
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group departures-dates">
                                        @Html.Label("From", Loc.DeparturesFrom, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("DeparturesFrom", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "DeparturesFrom",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                        @Html.Label("To", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("DeparturesTo", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "DeparturesTo",
                                                    false,
                                                    Loc.To))
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group arrivals-dates">
                                        @Html.Label("From", Loc.ArrivalsFrom, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("ArrivalsFrom", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "ArrivalsFrom",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                        @Html.Label("To", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("ArrivalsTo", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "ArrivalsTo",
                                                    false,
                                                    Loc.To))
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group payouts-dates">
                                        @Html.Label("From", Loc.PayoutsFrom, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("PayoutsFrom", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "PayoutsFrom",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                        @Html.Label("To", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("PayoutsTo", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "PayoutsTo",
                                                    false,
                                                    Loc.To))
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group costs-dates">
                                        @Html.Label("From", Loc.CostsFrom, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("CostsFrom", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "CostsFrom",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                        @Html.Label("To", Loc.To, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("CostsTo", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "CostsTo",
                                                    false,
                                                    Loc.To))
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group payment-date">
                                        @Html.Label("From", Loc.PaymentDateTo, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <span class="input-group-addon">
                                                    <i class="far fa-calendar alt"></i>
                                                </span>
                                                @Html.TextBox("PaymentDateTo", null,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control custom-datepicker",
                                                    "PaymentDateTo",
                                                    false,
                                                    Loc.From))
                                            </div>
                                        </div>
                                    </div>

                                    @*Dropdownds*@
                                    @*TODO: Changes content of dropdowns*@
                                    <div class="form-group expense-type">
                                        @Html.Label("ExpenseType", Loc.ExpenseType, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("ExpenseType",
                                                 new SelectList(Model.ExpenseTypes.Select(item => new { Value = item, Text = item }).ToList(), "Value", "Text", null), Loc.ShowAll,
                                                 HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker clear-select",
                                                     "ExpenseType",
                                                     false,
                                                     Loc.ExpenseType,
                                                     true,
                                                     new
                                                     {
                                                         @multiple = "multiple",
                                                         data_live_search = "true",
                                                         @title = Loc.ShowAll
                                                     },
                                                     false)
                                                 )
                                        </div>
                                    </div>

                                    <div class="form-group employee">
                                        @Html.Label("Employee", Loc.Worker, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("Employee",
                                            new SelectList(Model.Employees, "WorkerCode", "WorkerName", (canAccessOwn && !canAccessOthers ? _authInfo.WorkerCode() : null)), Loc.ShowAll,
                                            HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker clear-select",
                                                "Employee",
                                                canAccessOwn && !canAccessOthers,
                                                Loc.Worker,
                                                true,
                                                new
                                                {
                                                    @multiple = "multiple",
                                                    data_live_search = "true",
                                                    @title = Loc.ShowAll,
                                                    data_size = "8"
                                                },
                                                canAccessOwn && !canAccessOthers)
                                            )
                                        </div>
                                    </div>

                                    <div class="form-group daily-allow">
                                        @Html.Label("DailyAllow", Loc.DailyAllow, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            <select id="DailyAllow"
                                                    name="DailyAllow"
                                                    data-placeholder="@Loc.DailyAllow"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("GetDailyAllowTypes", "TravelOrdersDailyAllows")"
                                                    data-column-names="@string.Format("{0},{1}", Loc.DailyAllow, Loc.Country)"
                                                    data-bootstrap-columns="col-md-6, col-md-6"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group car-reg-no">
                                        @Html.Label("CarRegNo", Loc.RegNoShort, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("CarRegNo",
                                                 new SelectList(Model.Vehicles, "CarRegNo", "Name", null), Loc.ShowAll,
                                                 HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                                                     "CarRegNo",
                                                     false,
                                                     Loc.CarRegNo,
                                                     true,
                                                     new
                                                     {
                                                         data_live_search = "true",
                                                         @title = Loc.ShowAll
                                                     },
                                                     false)
                                                 )
                                        </div>
                                    </div>

                                    <div class="form-group status">
                                        @Html.Label("Status", Loc.Status, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("Status",
                                                 new SelectList(Model.Statuses, "VerifyStatusName", "VerifyStatusName", null),
                                                 HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                                                     "Status",
                                                     false,
                                                     Loc.Status,
                                                     true,
                                                     new
                                                     {
                                                         data_live_search = "true",
                                                         @title = Loc.Status,
                                                         data_size = "8"
                                                     },
                                                     true)
                                                 )
                                        </div>
                                    </div>

                                    <div class="form-group currencies">
                                        @Html.Label("ForCurrency", Loc.ForCurrency, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-4">
                                            <select id="ForCurrency"
                                                    name="ForCurrency"
                                                    data-placeholder="@Loc.Currency"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("GetCurrencies", "TravelOrdersExpenses")"
                                                    data-column-names="@string.Format("{0}", Loc.Currency)"
                                                    data-bootstrap-columns="col-md-12"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                        @Html.Label("ToCurrency", Loc.ToCurrency, new { @class = "col-sm-1 control-label" })
                                        <div class="col-sm-4">
                                            <select id="ToCurrency"
                                                    name="ToCurrency"
                                                    data-placeholder="@Loc.Currency"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("GetCurrencies", "TravelOrdersExpenses")"
                                                    data-column-names="@string.Format("{0}", Loc.Currency)"
                                                    data-bootstrap-columns="col-md-12"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group country">
                                        @Html.Label("Country", Loc.Country, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("Country", Model.Countries, Loc.ShowAll,
                                                 HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                                                     "Country",
                                                     false,
                                                     Loc.Country,
                                                     true,
                                                     new
                                                     {
                                                         data_live_search = "true",
                                                         @title = Loc.ShowAll,
                                                         data_size = "8"
                                                     },
                                                     false)
                                                 )
                                        </div>
                                    </div>

                                    <div class="form-group cost-carrier">
                                        @Html.Label("CostCarrier", Loc.CostCarrier, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("CostCarrier", Model.CostCarriers, Loc.ShowAll,
                                                 HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker clear-select",
                                                     "CostCarrier",
                                                     false,
                                                     Loc.CostCarrier,
                                                     true,
                                                     new
                                                     {
                                                         @multiple = "multiple",
                                                         data_live_search = "true",
                                                         @title = Loc.ShowAll,
                                                         data_size = "8"
                                                     },
                                                     false)
                                                 )
                                        </div>
                                    </div>

                                    <div class="form-group department">
                                        @Html.Label("Department", Loc.Department, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("Department", Model.Departments, Loc.ShowAll,
                                                  HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker clear-select",
                                                      "Department",
                                                      false,
                                                      Loc.Department,
                                                      true,
                                                      new
                                                      {
                                                          @multiple = "multiple",
                                                          data_live_search = "true",
                                                          @title = Loc.ShowAll,
                                                          data_size = "8"
                                                      },
                                                      false)
                                                  )
                                        </div>
                                    </div>

                                    <div class="form-group irek">
                                        @Html.Label("IREK", Loc.IREK, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.DropDownList("IREK", Model.IREKItems, Loc.ShowAll,
                                                 HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                                                     "IREK",
                                                     false,
                                                     Loc.IREK,
                                                     true,
                                                     new
                                                     {
                                                         data_live_search = "true",
                                                         @title = Loc.ShowAll,
                                                         data_size = "8"
                                                     },
                                                     false)
                                                 )
                                        </div>
                                    </div>

                                    <div class="form-group type">
                                        @Html.Label("Type", Loc.TypeShort, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            <select id="Type" name="Type" class="form-control selectpicker">
                                                <option value="-1" selected>@Loc.ShowAll</option>
                                                <option value="1">@Loc.IsReportedToIREK</option>
                                                <option value="0">@Loc.IsNotReportedToIREK</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group trip-to">
                                        @Html.Label("TripTo", Loc.TripTo, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            <select id="TripTo"
                                                    name="TripTo"
                                                    data-placeholder="@Loc.TripTo"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("SubjectDropdownValues", "Subjects")"
                                                    data-column-names="@string.Format("{0}", Loc.Subject)"
                                                    data-bootstrap-columns="col-md-12"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group costs"
                                         @(CurrentUser.Localization != Localization.Code.SI ? "hidden" : string.Empty)>
                                        @Html.Label("Costs", Loc.Costs, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            <select id="Costs" name="Costs" class="form-control selectpicker">
                                                <option value="-1" selected>@Loc.All</option>
                                                <option value="1">@Loc.IsReportedToIREK</option>
                                                <option value="0">@Loc.IsNotReportedToIREK</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group place">
                                        @Html.Label("Place", Loc.Place, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            <select id="Place"
                                                    name="Place"
                                                    data-placeholder="@Loc.Place"
                                                    class="form-control select2withAPI"
                                                    data-url="@Url.Action("SearchPostsLookup", "Post")"
                                                    data-column-names="@string.Format("{0},{1}", Loc.Post, Loc.Name)"
                                                    data-bootstrap-columns="col-md-6, col-md-6"
                                                    data-splitter=","
                                                    data-search-width="200"
                                                    allow-clear="true">
                                            </select>
                                        </div>
                                    </div>

                                    @*Inputs*@
                                    <div class="form-group tolerance">
                                        @Html.Label("Tolerance", Loc.Tolerance, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.Editor("Tolerance", new { htmlAttributes = new { @class = "form-control numberInput", @autocomplete = "off", @placeholder = @Loc.Tolerance } })
                                        </div>
                                    </div>

                                    @*Checkboxes*@
                                    <div class="form-group confirmed-chx">
                                        @Html.Label("Confirmed", Loc.Confirmed, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9 neutral-cb-bg">
                                            @Html.CheckBox("Confirmed", new { @id = "Confirmed", @class = "form-control js-switch neutral-cb", @onchange = "handleThreeStateCheckbox(this)" })
                                        </div>
                                    </div>

                                    <div class="form-group approved-chx">
                                        @Html.Label("Approved", Loc.Approved, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9 neutral-cb-bg">
                                            @Html.CheckBox("Approved", new { @id = "Approved", @class = "form-control js-switch neutral-cb", @onchange = "handleThreeStateCheckbox(this)" })
                                        </div>
                                    </div>

                                    <div class="form-group company-vehicle-chx">
                                        @Html.Label("CompanyVehicles", Loc.CompanyVehicles, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9 neutral-cb-bg">
                                            @Html.CheckBox("CompanyVehicles", new { @id = "CompanyVehicles", @class = "form-control js-switch neutral-cb", @onchange = "handleThreeStateCheckbox(this)" })
                                        </div>
                                    </div>

                                    <h3 class="m-t-lg display-on-print-title">@Loc.DisplayOnPrint</h3>

                                    <div class="form-group not-for-payout-chx">
                                        @Html.Label("NotForPayout", Loc.NotForPayout, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9 neutral-cb-bg">
                                            @Html.CheckBox("NotForPayout", new { @id = "NotForPayout", @class = "form-control js-switch neutral-cb", @onchange = "handleThreeStateCheckbox(this)" })
                                        </div>
                                    </div>

                                    <div class="form-group return-report-chx">
                                        @Html.Label("ReturnReport", Loc.ReturnReport, new { @class = "col-sm-3 control-label" })
                                        <div class="col-sm-9">
                                            @Html.CheckBox("ReturnReport", new { @id = "ReturnReport", @class = "form-control js-switch" })
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        }
        else
        {
            ViewBag.Permissions = Permissions.DENARPOTNALIZPISI + ", " + Permissions.DENARPNSSIZPISI;
            @Html.Partial("~/Views/Account/NoPermissionsTab.cshtml")
        }
    </div>
</div>

@Html.Hidden("LastPrint", Model.LastPrint)
@Html.Hidden("TravelOrdersPrintHelpUrl", SiteHelpAttributeHelper.GetHelpUrl(PantheonRA.BackOffice.Enums.HelpIds.TravelOrdersPrint))

@section pageScripts{
    <script>
        $(document).ready(function () {
            $("#Confirmed").val('');
            $("#Approved").val('');
            $("#CompanyVehicles").val('');
            $("#NotForPayout").val('');

            var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
            elems.forEach(function (html, index) {
                var switchery = new Switchery(html, { size: 'small' });
            });

            var printParts = $("#LastPrint").val() ? $("#LastPrint").val().split("_") : "";
            if (printParts && printParts.length > 1) {
                var lastPrint = printParts[1];
                selectPrintTypeTravelOrders($(".preview-print-option[data-print='" + lastPrint + "']")[0], lastPrint);
            } else
                selectPrintTypeTravelOrders();

            setGlobalHelpUrl($("#TravelOrdersPrintHelpUrl").val())
        });

        function togglePrintOptionGroup(element) {
            $(element).parent().toggleClass("print-group-closed");
        }

        function selectPrintTypeTravelOrders($element, type) {
            if (!$element || $element.length <= 0) {
                $element = $(".preview-print-option").first();
                type = $element.attr("data-print");
            }

            $("#printOptions div.custom-option-selected").removeClass("custom-option-selected");
            $($element).addClass("custom-option-selected");
            $("#ReportType").val(type);
            displayFilters($element.closest('.report-type').id, $element.closest('.preview-print-option').id);
        }

        function displayFilters(id, printOptionId) {
            id = setIdForSingleReportFilters(printOptionId) ?? id;

            const classFiltersConfig = {
                "TPotNalIzpisKriterijPotNalIzpis": {
                    show: ["key-from-to", "travel-orders-dates", "calc-form-dates", "employee", "car-reg-no", "status", "confirmed-chx", "approved-chx", "company-vehicle-chx", "not-for-payout-chx", "return-report-chx", "display-on-print-title"],
                    hide: ["arrivals-dates", "payouts-dates", "costs-dates", "departures-dates", "payment-date", "expense-type", "currencies", "country", "cost-carrier", "department", "irek", "type", "trip-to", "costs", "place", "tolerance", "daily-allow"]
                },
                "TPotNalIzpisKriterijPotNalIzpisVoz": {
                    show: ["key-from-to", "travel-orders-dates", "calc-form-dates", "expense-type", "employee", "car-reg-no", "status", "confirmed-chx", "approved-chx", "company-vehicle-chx", ],
                    hide: ["arrivals-dates", "payouts-dates", "costs-dates", "departures-dates", "payment-date", "currencies", "country", "cost-carrier", "department", "irek", "type", "trip-to", "costs", "place", "tolerance", "not-for-payout-chx", "return-report-chx", "display-on-print-title", "daily-allow"]
                },
                "TPotNalIzpisKriterijPotNalObracun": {
                    show: ["travel-orders-dates", "calc-form-dates", "arrivals-dates", "payouts-dates", "departures-dates", "currencies", "employee", "trip-to", "country", "cost-carrier", "department", "status", "confirmed-chx", "approved-chx", "daily-allow"],
                    hide: ["key-from-to", "costs-dates", "expense-type", "payment-date", "car-reg-no", "place", "irek", "type", "costs", "place", "tolerance", "company-vehicle-chx", "not-for-payout-chx", "return-report-chx", "display-on-print-title"]
                },
                "TPotNalIzpisKriterijPotNalObracunNe": {
                    show: ["travel-orders-dates", "calc-form-dates", "arrivals-dates", "payouts-dates", "departures-dates", "payment-date", "currencies", "employee", "trip-to", "country", "cost-carrier", "department", "status", "tolerance", "confirmed-chx", "approved-chx", "daily-allow"],
                    hide: ["key-from-to", "costs-dates", "expense-type", "place", "irek", "car-reg-no", "type", "costs", "place", "company-vehicle-chx", "not-for-payout-chx", "return-report-chx", "display-on-print-title"]
                },
                "TPotNalIzpisKriterijPotNalStroski": {
                    show: ["travel-orders-dates", "calc-form-dates", "costs-dates", "expense-type", "car-reg-no", "currencies", "employee", "trip-to", "country", "cost-carrier", "department", "status", "place", "costs", "confirmed-chx", "approved-chx", "not-for-payout-chx"],
                    hide: ["key-from-to", "arrivals-dates", "payouts-dates", "departures-dates", "payment-date", "type", "irek", "tolerance", "company-vehicle-chx", "return-report-chx", "display-on-print-title", "daily-allow"]
                },
                "TPotNalIzpisKriterijPotNalIREK": {
                    show: ["travel-orders-dates", "calc-form-dates", "departures-dates", "expense-type", "car-reg-no", "currencies", "employee", "trip-to", "country", "cost-carrier", "department", "status", "place", "irek", "type", "confirmed-chx", "approved-chx", "not-for-payout-chx"],
                    hide: ["key-from-to", "arrivals-dates", "payouts-dates", "costs-dates", "payment-date", "costs", "tolerance", "company-vehicle-chx", "return-report-chx", "display-on-print-title", "daily-allow"]
                },
                "TPotNalIzpisKriterijPotNalStrosSum": {
                    show: ["travel-orders-dates", "calc-form-dates", "costs-dates",  "expense-type", "car-reg-no", "employee", "trip-to", "cost-carrier", "department", "status", "place", "confirmed-chx", "approved-chx", "not-for-payout-chx", "display-on-print-title"],
                    hide: ["key-from-to", "arrivals-dates", "payouts-dates", "departures-dates", "payment-date", "currencies", "country", "costs", "irek", "type", "tolerance", "company-vehicle-chx", "return-report-chx", "daily-allow"]
                },
                "TPotNalIzpisKriterijPotNalDnevi": {
                    show: ["travel-orders-dates", "calc-form-dates", "arrivals-dates", "departures-dates", "employee", "trip-to", "cost-carrier", "department", "status", "place", "confirmed-chx", "approved-chx", "country"],
                    hide: ["key-from-to", "payouts-dates", "costs-dates", "payment-date", "expense-type", "car-reg-no", "currencies", "costs", "irek", "type", "tolerance", "company-vehicle-chx", "not-for-payout-chx", "return-report-chx", "display-on-print-title", "daily-allow"]
                }
            };

            const form = classFiltersConfig[id];
            if (!form) return;

            form.show.forEach(classSelector => $(document.getElementsByClassName(classSelector)).removeClass("hidden"));
            form.hide.forEach(classSelector => $(document.getElementsByClassName(classSelector)).addClass("hidden"));
        };

        let printWindow;
        function print() {
            swapLoadingIcon(true, "printButton", "far fa-print");

            var url = "@Url.Action("Print", "TravelOrders")"
                + "?PrintType=" + $("#ReportType").val();

            var params = printRequestParams();
            url += "&" + $.param(params);

            printWindow = window.open();
            printWindow.document.write(generatePrintingPage());
            printPAAS("", false, false, url, false);
            swapLoadingIcon(false, "printButton", "far fa-print");
        }

        function swapLoadingIcon(loading, buttonId, icon) {
            var $button = $("#" + buttonId);
            var $buttonIcon = $button.find("i");
            var $buttonGroupButtons = $button.parent().find("button");

            if (loading) {
                $buttonIcon.removeClass(icon).addClass("fa fa-spinner fa-spin fa-fw");
                $buttonGroupButtons.attr("disabled", true);
            }
            else {
                $buttonIcon.removeClass("fa fa-spinner fa-spin fa-fw").addClass(icon);
                $buttonGroupButtons.removeAttr("disabled");
            }
        }

        function handleThreeStateCheckbox(cb) {
            const states = ['', 'T', 'F'];
            let currentStateIndex;

            if ($(cb).hasClass('neutral-cb')) {
                currentStateIndex = 0;
            } else if ($(cb).hasClass('true-cb')) {
                currentStateIndex = 1;
            } else {
                currentStateIndex = 2;
            }

            currentStateIndex = (currentStateIndex + 1) % states.length;

            $(cb).removeClass('neutral-cb true-cb false-cb');
            if (states[currentStateIndex] === '') {
                $(cb).addClass('neutral-cb');
                $(cb).prop('checked', false);
            } else if (states[currentStateIndex] === 'T') {
                $(cb).addClass('true-cb');
            } else {
                $(cb).addClass('false-cb');
            }

            $(cb).val(states[currentStateIndex]);
        }

        function printRequestParams() {
            var params = {
                //Dropdowns and textboxes
                KeyFrom: $("#AcKeyFrom").val() ? $("#AcKeyFrom").val().toString() : null,
                KeyTo: $("#AcKeyTo").val() ? $("#AcKeyTo").val().toString() : null,
                DocumentTypes: $("#DocumentTypes").val() ? $("#DocumentTypes").val().toString().replace(/,/g, ";") : null,
                ExpenseType: $("#ExpenseType").val() ? $("#ExpenseType").val().toString() : null,
                Workers: $("#Employee").val() ? $("#Employee").val().toString() : null,
                CarRegNo: $("#CarRegNo").val() ? $("#CarRegNo").val().toString() : null,
                Status: $("#Status").val() ? $("#Status").val().toString() : null,
                ForCurrency: $("#ForCurrency").val() ? $("#ForCurrency").val().toString() : null,
                ToCurrency: $("#ToCurrency").val() ? $("#ToCurrency").val().toString() : null,
                Country: $("#Country").val() ? $("#Country").val().toString() : null,
                CostCarrier: $("#CostCarrier").val() ? $("#CostCarrier").val().toString() : null,
                Department: $("#Department").val() ? $("#Department").val().toString() : null,
                IREK: $("#IREK").val() ? $("#IREK").val().toString() : null,
                Type: $("#Type").val() ? $("#Type").val().toString() : null,
                TripTo: $("#TripTo").val() ? $("#TripTo").val().toString() : null,
                Costs: $("#Costs").val() ? $("#Costs").val().toString() : null,
                Place: $("#Place").val() ? $("#Place").val().toString() : null,
                DailyAllow: $("#DailyAllow").val() ? $("#DailyAllow").val().toString() : null,
                Tolerance: $("#Tolerance").val() ? $("#Tolerance").val().toString() : null,
                //Checkboxes
                Confirmed: $("#Confirmed").val(),
                Approved: $("#Approved").val(),
                CompanyVehicles: $("#CompanyVehicles").val(),
                NotForPayout: $("#NotForPayout").val(),
                ReturnReport: $("#ReturnReport").is(':checked'),
                //Dates
                DateFrom: reformatDate($("#TravelOrdersFrom").val()),
                DateTo: reformatDate($("#TravelOrdersTo").val()),
                DateCalcFrom: reformatDate($("#DateCalcFrom").val()),
                DateCalcTo: reformatDate($("#DateCalcTo").val()),
                DeparturesFrom: reformatDate($("#DeparturesFrom").val()),
                DeparturesTo: reformatDate($("#DeparturesTo").val()),
                ArrivalsFrom: reformatDate($("#ArrivalsFrom").val()),
                ArrivalsTo: reformatDate($("#ArrivalsTo").val()),
                PayoutsFrom: reformatDate($("#PayoutsFrom").val()),
                PayoutsTo: reformatDate($("#PayoutsTo").val()),
                CostsFrom: reformatDate($("#CostsFrom").val()),
                CostsTo: reformatDate($("#CostsTo").val()),
                PaymentDateTo: reformatDate($("#PaymentDateTo").val())
            }

            Object.keys(params).forEach(key => {
                if (!params[key]) {
                    delete params[key];
                }
            });

            return params;
        }

        function setIdForSingleReportFilters(printOptionId) {
            const reportFilterFormId = {
                "3CR": "TPotNalIzpisKriterijPotNalIREK"
            }

            return reportFilterFormId[printOptionId];
        }
    </script>
}