@using PantheonRA.BackOffice.Enums
@using PantheonRA.BackOffice.Models
@using PAW.Contracts.Enums;
@model PantheonRA.BackOffice.Models.Reports.IssuedBillsListViewModel<PantheonRA.BackOffice.Models.Reports.IssuedBillsSummaryFilterModel>

@{
    string unconfirmedBillsDateFrom = Model.Filter.UnconfirmedBillsDateFrom.HasValue
        ? Model.Filter.UnconfirmedBillsDateFrom.Value.ToString(Loc.DateFormat)
        : DateTime.Now.Date.AddMonths(-1).ToString(Loc.DateFormat);
}

@Html.HiddenFor(model => model.Filter.AcKey)
@Html.Hidden("UnconfirmedBillsDateFrom", unconfirmedBillsDateFrom)
@Html.Hidden("DateFromDefault", DateTime.Now.Date.AddMonths(-1).ToString(Loc.DateFormat))
@Html.Hidden("DefaultDecimalPlacesPrice", Model.Filter.DefaultDecimalPlacesPrice)
@Html.Hidden("DefaultDecimalPlacesQuantity", Model.Filter.DefaultDecimalPlacesQuantity)
@Html.Hidden("DefaultDecimalPlacesValue", Model.Filter.DefaultDecimalPlacesValue)

<div class="row buttons-tabbed">
    <a id="downloadIssuedBills" class="btn btn-primary btn-outline pull-right">
        <i class="fas fa-file-excel" title="@Loc.ExportToExcel"></i>
        <span class="bold visible-lg-inline visible-md-inline m-l-xs">@Loc.Export</span>
    </a>

    <a href="@(Model.Filter.Author == AuthorType.POS ? Url.Action("Index", "CashRegister") :
       Model.Filter.Author == AuthorType.ReceivedBills ? Url.Action("Create", "ReceivedBills") : Url.Action("Create", "Wholesale"))" title="@Loc.New" id="newInvoiceButton"
       class="btn btn-primary btn-outline pull-right">
        <i class="fas fa-plus m-r-xs"></i>
        <span class="visible-lg-inline visible-md-inline">@Loc.New</span>
    </a>

    <a id="fiscalizeSelectedBills" onclick="onClickFiscalizeSelectedBills()" class="btn btn-primary btn-outline pull-right hidden">
        <i class="fas fa-cash-register" title="@Loc.FiscalizeSelected"></i>
        <span class="bold visible-lg-inline visible-md-inline m-l-xs">@Loc.FiscalizeSelected</span>
    </a>
</div>

@Html.HiddenFor(model => model.Filter.Author)
@*<div class="">
        <div class="ibox-content">
            <div class="row form-horizontal">
                <div class="col-lg-9 col-md-12">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="m-b">
                                @Html.LabelFor(model => model.Filter.DateFrom, Loc.From, new { @class = "control-label" })
                                @Html.TextBoxFor(m => m.Filter.DateFrom, "{0:dd.MM.yyyy}", new { @class = "form-control datepicker input-horizontal-small-label pull-right", @autocomplete = "off" })
                            </div>
                            <div class="m-b">
                                @Html.LabelFor(model => model.Filter.DateTo, Loc.To, new { @class = "control-label" })
                                @Html.TextBoxFor(m => m.Filter.DateTo, "{0:dd.MM.yyyy}", new { @class = "form-control datepicker input-horizontal-small-label pull-right", @autocomplete = "off" })
                            </div>
                        </div>
                        <div class="col-md-2">
                            <div class="m-b-xs">
                                @Html.HiddenFor(model => model.Filter.DocType)
                                @Html.DropDownListFor(model => model.Filter.DocType, new SelectList(ViewBag.DocumentTypes != null ? ViewBag.DocumentTypes : new List<string>(), "Id", "Value"),
                                    Loc.All, HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker", "DocType", false, Loc.DocTypeShort, true, new { @multiple = "multiple", @title = Loc.Select }))

                            </div>
                        </div>
                        <div class="col-md-2">
                            <div class="m-b-xs">

                            </div>
                        </div>
                        <div class="col-md-2" id="additional-filter"></div>
                        <div class="col-md-6" id="long-filter"></div>
                        <div class="col-lg-2 col-md-3 col-sm-12"></div>
                    </div>
                </div>
                <div class="col-lg-3 pull-right">
                    <div id="confirmBillsDropdown" class="btn-group pull-right m-l-xs">
                        <div class="dropdown btn-group">
                            <button id="confirmBills" type="button" class="btn btn-primary">
                                <span class="visible-lg-inline visible-md-inline">@Loc.SendBillsToConfirm</span>
                            </button>
                            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li><a href="javascript:void(0);" onclick="onClickFiscalizeSelectedBills()">@Loc.FiscalizeSelectedBills</a></li>
                                <li><a href="javascript:void(0);" onclick="onClickFiscalizeAllUnconfirmedBills()">@Loc.FiscalizeAllUnconfirmedBills</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>*@

<div class="row document-head">
    <div class="col-md-2 col-xs-4">
        @Html.Partial("~/Views/Reports/_IssuedBillsTabNavigation.cshtml", new IssuedBillsTabModel() { Type = IssuedBillsTabType.Detailed, Author = Model.Filter.Author })
    </div>
    <div class="col-md-2 col-xs-4">
        <div class="form-group">
            <label class="control-label">@Loc.SearchFilter</label>
            @Html.TextBoxFor(model => model.Filter.Keywords, new { @id = "Keywords", @class = "form-control search-input", @placeholder = Loc.Search, autocomplete = "off" })
        </div>
    </div>

    <div class="col-md-2 col-xs-4">
        <div class="form-group">
            @Html.LabelFor(model => model.Filter.DocType, Loc.DocType, new { @class = "control-label" })
            @Html.HiddenFor(model => model.Filter.DocType)
            @Html.DropDownListFor(model => model.Filter.DocType, new SelectList(ViewBag.DocumentTypes != null ? ViewBag.DocumentTypes : new List<string>(), "Id", "Value"),
                HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker", "DocType", false, Loc.DocTypeShort, true, new { @multiple = "multiple", @data_Actions_Box = "true", @data_select_All_Text = Loc.SelectAll, @title = Loc.Select }))
        </div>
    </div>

    <div class="col-md-2 col-xs-4">
        <div class="form-group">
            <label class="control-label">@Loc.DetailedReview</label>
            <select id="documentCategory" class="form-control custom-select">
                <option value="@Url.Action("IssuedBillsDetailed", "Reports", new { author = Model.Filter.Author })"
                        data-method="initializeReportsIssuedBillsDetailed">
                    @(Model.Filter.Author == AuthorType.ReceivedBills ? Loc.BillsDetailed : Loc.BillsByFiscalNum)
                </option>
                <option value="@Url.Action("IssuedBillsByItems", "Reports")">@Loc.BillsByItems</option>
                @if (Model.Filter.Author != AuthorType.ReceivedBills)
                {
                    <option value="@Url.Action("IssuedBillsByCashiers", "Reports")">@Loc.BillsByCashiers</option>
                    <option value="@Url.Action("IssuedBillsByPaymentMethods", "Reports")">@Loc.BillsByPaymentMethods</option>
                    if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.SI)
                    {
                        <option value="@Url.Action("IssuedBillsChronologicallyByCopiesWithFisc", "Reports")">@Loc.BillsChronologicallyByCopiesWithFiscalNum</option>
                    }
                    <option class="unconfirmed-bills" value="@Url.Action("IssuedBillsUnconfirmed", "Reports")" @(Model.Filter.ShowUnconfirmedBills == true ? "selected" : "")>
                        @Loc.UnconfirmedDocuments
                    </option>
                }
            </select>
        </div>
    </div>

    <div class="col-md-2 col-xs-4 dateFilter">
        <div class="form-group">
            <label class="control-label">@Loc.DateFrom</label>
            <div class="input-group">
                <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                <input class="form-control datepicker" id="Filter_DateFrom" name="Filter.DateFrom" type="text" value="@DateTime.Now.Date.AddMonths(-1).ToString(Loc.DateFormat)">
            </div>
        </div>
    </div>
    <div class="col-md-2 col-xs-4 dateFilter">
        <div class="form-group">
            <label class="control-label">@Loc.DateTo</label>
            <div class="input-group">
                <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                <input class="form-control datepicker" id="Filter_DateTo" name="Filter.DateTo" type="text" value="@DateTime.Now.Date.ToString(Loc.DateFormat)">
            </div>
        </div>
    </div>
</div>

<div id="issuedBillsContent" class="project-list"></div>

<input id="AuthorTypePOS" type="hidden" value="@AuthorType.POS" />
<input id="AuthorTypeWS" type="hidden" value="@AuthorType.Wholesale" />
<input id="AuthorTypeRB" type="hidden" value="@AuthorType.ReceivedBills" />
<input type="hidden" id="primaryClassifText" value="@Loc.PrimaryClassification" />
<input type="hidden" id="secondaryClassifText" value="@Loc.SecondaryClassification" />
<input type="hidden" id="bothClassifText" value="@Loc.BothClassifications" />
<input type="hidden" id="itemsDisplayFilterTypeCustomDate" value="@ItemsDisplayFilterType.CustomDate" />
<input type="hidden" id="IsInFiscalPrinterLocalization" value="@(string.Empty + Localization.IsInFiscalPrinterLocalization(PantheonRA.BackOffice.CurrentUser.Localization, PantheonRA.BackOffice.CurrentUser.IsInServerFiscalization))" />
<input type="hidden" id="SuccessfullyFiscalizedDocumentsLocalization" value="@Loc.SuccessfullyFiscalizedDocuments" />
@Html.Partial("~/Views/Shared/Components/_PreviewPrintMenuButton.cshtml", new PantheonRA.BackOffice.Models.PreviewReportTreeViewModel { ReportTree = Model.Filter.ReportTree })