@using PantheonRA.BackOffice.Enums
@using PantheonRA.WebApi.Contracts.Enums
@using PantheonRA.BackOffice.Models
@using PAW.Contracts.Enums;
@model PantheonRA.BackOffice.Models.OrderFilterModel
@{
    ViewBag.Title = Loc.OrdersBuyersIssued;
}

<div class="wrapper wrapper-content">
    @Html.HiddenFor(x => x.OrderType)
    <div class="tabs-container">
        @Html.Partial("_OrderBuyersTabNavigation", new Dictionary<string, bool> { { "IsOrderCalendar", Model.HasOrderCalendar }, { "IsIndexView", true } })
        <div class="row buttons-tabbed">
            @Html.Partial("_GridButtons", new GridButtonsViewModel
            {
                AddButton = new PantheonRA.BackOffice.Models.FormButton
                {
                    Url = Url.Action("CreateBuyerOrder", "Order"),
                    Icon = "fa fa-plus",
                    Text = Loc.New
                },
                GridActionsGroup = new FormButtonGroup
                {
                    IsActive = false,
                    Buttons = new List<FormButton>()
                    {
                        new FormButton
                        {
                            Text = Loc.Print,
                            Icon = "far fa-print",
                            OnClick = "printOrders()"
                        }
                    }
                }
            })
        </div>

        @Html.HiddenFor(model => model.DefaultDecimalPlacesPrice)
        @Html.HiddenFor(model => model.DefaultDecimalPlacesQuantity)
        @Html.HiddenFor(model => model.DefaultDecimalPlacesValue)
        <div class="row document-head">
            <div class="col-md-3 col-xs-6">
                <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.Search, autocomplete = "off" })
                </div>
            </div>

            <div class="col-lg-2 col-md-3 col-xs-6 @(PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule) ? "hidden" : string.Empty)">
                <div class="form-group">
                    @Html.LabelFor(model => model.DocType, Loc.DocType, new { @class = "control-label" })
                    @Html.DropDownListFor(model => model.DocType, new SelectList(ViewBag.DocumentTypes != null ? ViewBag.DocumentTypes : new List<string>(), "Id", "Value"), Loc.All,
                        HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "DocType", false, Loc.DocTypeShort))
                    @Html.ValidationMessageFor(model => model.DocType, "", new { @class = "text-danger" })
                </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 class="project-list">
            <div id="issuedBillsContent" class="document-list document-list-double-footer-xs">
                <table id="order-grid" data-grid-id="buyer-orders-report" data-url="@Url.Action("BuyerOrdersReportData", "Order")">
                    <thead>
                        <tr>
                            <th width="2%" class="dt-body-center"></th>
                            <th width="3%" data-function="openPdfPreview('@Url.Action("PAASPrintByAcKeyAndType", "Move")?fiscalize=false&preview={2}&acKey={0}&type={1}')"></th>
                            <th width="10%">@Loc.FiscNumber</th>
                            <th width="10%" data-url="@Url.Action("EditBuyerOrder", "Order")?returnUrl=@Url.Encode(Url.Action("BuyerOrdersReport", "Orders"))&id=">
                                @Loc.Number
                            </th>
                            <th width="20%">@Loc.Buyer</th>
                            <th class="dt-head-right">@Loc.Total</th>
                            <th class="dt-head-right">@Loc.ForPayment</th>
                            <th>@Loc.OrderDate</th>
                            <th>@Loc.OrderValidity</th>
                            <th width="8%">@Loc.Status</th>
                        </tr>
                    </thead>
                </table>
            </div>

            <div class="row document-footer document-footer-sm">
                <div class="col-sm-9">
                    <div class="form-group">
                        <span class="pull-left"><span>@Loc.NumberOfOrders:</span> <b class="grid-data-total-items"></b></span>
                        <span class="pull-right m-r-md"><span>@Loc.Total:</span> <b id="grid-data-total-sum"></b></span>
                    </div>
                </div>
                <div class="col-sm-3 document-head-highlight-input">
                    <div class="form-group text-right">
                        <span>@Loc.TotalWithTax:</span> <label id="grid-data-vat-total-sum"></label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="orderStatusOffer" value="@OrderStatusType.Offer" />
<input type="hidden" id="orderStatusConfirmed" value="@OrderStatusType.ConfirmedOrder" />
<input type="hidden" id="orderStatusShipped" value="@OrderStatusType.Shipped" />
<input type="hidden" id="orderStatusFinished" value="@OrderStatusType.Finished" />
<input type="hidden" id="orderTypeBuyer" value="@OrderType.Buyer" />
<input type="hidden" id="userLoc" value="@PantheonRA.BackOffice.CurrentUser.Localization.ToString()" />
<input type="hidden" id="hrLoc" value="@Localization.Code.HR.ToString()" />
<input type="hidden" id="customDateEnum" value="@PantheonRA.BackOffice.Enums.ItemsDisplayFilterType.CustomDate" />
<input id="locRS" value="@Localization.Code.RS" type="hidden" />

@Html.Partial("~/Views/Shared/Components/_sidePanel.cshtml", new PantheonRA.BackOffice.Models.SidePanelViewModel { Id = "pdfPanel" })
@Html.Partial("~/Views/Shared/Components/_PreviewPrintMenuButton.cshtml", new PantheonRA.BackOffice.Models.PreviewReportTreeViewModel { ReportTree = Model.ReportTree })

@Html.Hidden("Print", Url.Action("PrintMultipleOrderPDF", "Order"))

@section pageScripts{
    @Scripts.Render("~/bundles/orders")
    <script>
        $(document).ready(function () {
            initializeOrderReport('@PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule)' !== '@Boolean.TrueString');
        });
    </script>
}
