@using PantheonRA.BackOffice.Models
@using PantheonRA.BackOffice.Enums
@using PantheonRA.BackOffice;
@using PantheonRA.WebApi.Contracts.Enums
@using PAW.Contracts.Enums;
@model InvoiceViewModel
@{
    ViewBag.Title = Loc.CashRegister;
    var isInFiscalPrinterLocalization = Localization.IsInFiscalPrinterLocalization(PantheonRA.BackOffice.CurrentUser.DatabaseLocalization, CurrentUser.IsInServerFiscalization);
}

<div class="wrapper wrapper-content">
    <div class="tabs-container">
        @Html.Partial("_CashRegisterTabNavigation")
        <div class="tab-content">
            <form id="cashRegForm">
                @if (Model.CertificateExists && Model.Devices != null && Model.Devices.Any())
                {
                    @Html.HiddenFor(model => model.CurrentClerk)
                    @Html.HiddenFor(model => model.IsTaxPayer)
                    @Html.HiddenFor(model => model.IsCashRegisterOpened)
                    @Html.HiddenFor(model => model.CanFiscalize)
                    @Html.HiddenFor(model => model.UseFiscalPrinterRounding)
                    @Html.HiddenFor(model => model.DefaultDecimalPlacesValue)
                    @Html.HiddenFor(model => model.DefaultDecimalPlacesPrice)
                    @Html.HiddenFor(model => model.DefaultDecimalPlacesQuantity)
                    @Html.HiddenFor(model => model.RoundPos)
                    @Html.HiddenFor(model => model.RoundPosItem)
                    @Html.HiddenFor(model => model.SelectedCountry)
                    @Html.HiddenFor(model => model.PaymentMethodId)
                    @Html.HiddenFor(model => model.IsObligDept)
                    @Html.HiddenFor(model => model.UserDepartment)
                    @Html.HiddenFor(model => model.Warehouse)
                    @Html.HiddenFor(model => model.CustomerRabatAllowed)
                    @Html.HiddenFor(model => model.FiscalWorkplaceId)
                    @Html.HiddenFor(model => model.IsInitialized)
                    @Html.HiddenFor(model => model.IsCanceled)
                    @Html.HiddenFor(model => model.CorrType)
                    @Html.HiddenFor(model => model.DefaultReport)
                    @Html.HiddenFor(model => model.AllowZeroTotal)
                    @Html.HiddenFor(model => model.CheckPositionPriceQty)
                    @Html.HiddenFor(model => model.PinUrlLPFR)
                    @Html.HiddenFor(model => model.AttentionUrlPFR)
                    @Html.HiddenFor(model => model.FiscTraining)
                    @Html.HiddenFor(model => model.FiscalStatus)
                    @Html.Hidden("MoveNonMatOpenDate", Model.MoveNonMatOpenDate.HasValue ? Model.MoveNonMatOpenDate.Value.ToString(Loc.DateFormat) : null, new { @class = "datepicker" })
                    @Html.Hidden("MoveAdvancePaymentSum", Model.MoveAdvancePayment != null && Model.MoveAdvancePayment.Where(x => x.Type == "G").Any() ? Model.MoveAdvancePayment.Where(x => x.Type == "G").Sum(x => x.LinkValue) : 0)
                    <input type="hidden" id="PrintSettings" value="@(Model.PrintSettings != null ? string.Join(",", Model.PrintSettings.ToArray()) : null)" />

                    <div class="row buttons-tabbed">
                        @*//TODO: uncomment for PAAS*@
                        @*@if (!isInFiscalPrinterLocalization)
                        {
                            <div class="pull-right">
                                <div id="printersDropdown" class="@(Model.CanFiscalize ? "hidden" : string.Empty)">
                                    <div class="btn-group dropdown">
                                       @Html.Partial("_FormButtons", new FormButtonsViewModel
                                       {
                                           ShowCloseBtn = false,
                                           PrintSettings = Model.PrintSettings,
                                           PrintType = ReportFormName.POS,
                                           PrintMenuButtonGroup = ReportsHelper.FormatReportTree(
                                              Model.ReportTreeViewModel,
                                              "invoiceSubmit('{0}')",
                                              ""
                                          )
                                       })
                                    </div>
                                </div>
                            </div>
                        }
                        else
                        {
                            <div class="pull-right">
                                <div id="printersDropdown" class="@(Model.CanFiscalize ? "hidden" : string.Empty)">
                                    <div class="btn-group dropdown">
                                        <button type="button" class="btn btn-primary printDropdown" onClick="invoiceSubmit()" title="@Loc.Print">
                                            <i class="far fa-print print-loader-icon"></i><span class="visible-lg-inline m-l-xs">@Loc.Print</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 class="print-option" data-print="@PantheonRA.BackOffice.Enums.PaperSizeType.A4"><a onClick="invoiceSubmit('@PantheonRA.BackOffice.Enums.PaperSizeType.A4')"><i class="far fa-print fa-lg"></i>&nbsp;&nbsp; @Loc.Print A4</a></li>
                                            <li class="print-option" data-print="@PantheonRA.BackOffice.Enums.PaperSizeType.mm80"><a onClick="invoiceSubmit('@PantheonRA.BackOffice.Enums.PaperSizeType.mm80')"><i class="far fa-print fa-lg"></i>&nbsp;&nbsp; @Loc.Print 80</a></li>
                                            <li class="print-option" data-print="@PantheonRA.BackOffice.Enums.PaperSizeType.mm58"><a onClick="invoiceSubmit('@PantheonRA.BackOffice.Enums.PaperSizeType.mm58')"><i class="far fa-print fa-lg"></i>&nbsp;&nbsp; @Loc.Print 58</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        }*@
                        <div class="pull-right">
                            <div id="printersDropdown" class="@(Model.CanFiscalize ? "hidden" : string.Empty)">
                                <div class="btn-group dropdown">
                                    <button type="button" class="btn btn-primary printDropdown" onClick="invoiceSubmit()" title="@Loc.Print">
                                        <i class="far fa-print print-loader-icon"></i><span class="visible-lg-inline m-l-xs">@Loc.Print</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 class="print-option" data-print="@PantheonRA.BackOffice.Enums.PaperSizeType.A4"><a onClick="invoiceSubmit('@PantheonRA.BackOffice.Enums.PaperSizeType.A4')">@Loc.Print A4</a></li>
                                        <li class="print-option" data-print="@PantheonRA.BackOffice.Enums.PaperSizeType.mm80"><a onClick="invoiceSubmit('@PantheonRA.BackOffice.Enums.PaperSizeType.mm80')">@Loc.Print 80mm</a></li>
                                        <li class="print-option" data-print="@PantheonRA.BackOffice.Enums.PaperSizeType.mm58"><a onClick="invoiceSubmit('@PantheonRA.BackOffice.Enums.PaperSizeType.mm58')">@Loc.Print 57mm</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        @*--*@

                        <div class="pull-right">
                            <a class="btn btn-primary btn-outline operations journalButton" href="@Url.Action("Index", "Journal")" title="@Loc.CashRegisterJournal">
                                <i class="fas fa-cash-register"></i>
                                <span class="m-l-xs hidden-md hidden-sm hidden-xs">@Loc.CashRegisterJournal</span>
                            </a>
                        </div>
                        @if (Model.CanFiscalize)
                        {
                            <button id="saveButton" type="button" class="btn btn-primary btn-danger pull-right" title="@Loc.Save" onclick="onlySave(this)">
                                <i class="fa fa-save m-r-xs"></i><span class="hidden-md hidden-sm hidden-xs">@Loc.Save</span>
                            </button>
                            <button id="deleteButton" type="button" onclick="invokeRemoveInvoice(this)"
                                    class="btn btn-outline btn-danger pull-right" title="@Loc.Delete">
                                <i class="far fa-trash-alt m-r-xs"></i><span class="hidden-md hidden-sm hidden-xs">@Loc.Delete</span>
                            </button>
                        }

                        <div id="cancelButton" class="pull-right @(Model.CanCancel ? "" : "hidden")">
                            <div class="dropdown btn-group">
                                <button type="button" class="btn btn-outline btn-danger pull-right"
                                        title="@Loc.CancelInvoice" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    <i class="fa fa-ban"></i><span class="visible-lg-inline visible-md-inline m-l-xs">@Loc.CancelInvoice</span>
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a onclick="invokeCancelInvoice(this, @(Model.CashierId == PantheonRA.BackOffice.CurrentUser.Id), false)">
                                            <span class="m-l-xs">@Loc.CancelDocumentAndCreateInvoice</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a onclick="invokeCancelInvoice(this, @(Model.CashierId == PantheonRA.BackOffice.CurrentUser.Id), true)">
                                            <span class="m-l-xs">@Loc.CancelDocumentCreateInvoiceAndCopy</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a onclick="openPartialCancelInvoice()">
                                            <span class="m-l-xs">@Loc.PartialCancelInvoice</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>

                        @Html.Partial("_FormButtons", new FormButtonsViewModel
                        {
                            ShowCloseBtn = false,
                            IsWizardHidden = string.IsNullOrEmpty(Model.AcKey),
                            IsWizardVisible = true,
                            WizardButtonGroup = new FormButtonGroup
                            {
                                Buttons = new List<FormButton>
                                {
                                    new FormButton { Text = Loc.AdvancePayments, Icon = "", OnClick = "moveAdvancePaymentLinks()" },
                                    new FormButton { Text = Loc.DepositInput, Icon = "", OnClick = "initDepositModal('I')", HideForLoc = CurrentUser.Localization != Localization.Code.ME },
                                    new FormButton { Text = Loc.DepositOutput, Icon = "", OnClick = "initDepositModal('W')", HideForLoc = CurrentUser.Localization != Localization.Code.ME },
                                    new FormButton { Text = Loc.CreatePriceChange, Icon = "", OnClick = "onCreatePriceChange()", HideForLoc = PantheonRA.BackOffice.CurrentUser.Localization != Localization.Code.RS },
                                }
                            },
                            //IsFiscalPrinterWizardVisible = isInFiscalPrinterLocalization && PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.RS
                        })

                        <a href="@Url.Action("Index")" id="newDocumentButton" class="btn btn-primary btn-outline pull-right @(string.IsNullOrEmpty(Model.AcKey) || Model.CanFiscalize ? "hidden" : "")" title="@Loc.CreateNewInvoice">
                            <i class="fas fa-plus m-r-xs"></i>
                            <span class="visible-lg-inline">@Loc.New</span>
                        </a>
                    </div>

                    <div class="divided-content divided-content-side-closed">
                        <div class="divided-content-main">
                            <div class="placeholder placeholder-shopping-bag"><span class="placeholder-text">@Loc.CashRegPlaceholder</span></div>
                            <div class="row document-head">
                                <div id="cashRegisterLoginContainer" class="col-md-2 col-sm-6 @(string.IsNullOrEmpty(Model.AcKey) ?  string.Empty : "document-head-disabled-input")">
                                    <div class="form-group">
                                        <label class="control-label">@Loc.CashRegister</label>
                                        <div>
                                            <input type="hidden" id="DocType" value="@Model.Device.Id" />
                                            @Html.DropDownListFor(model => model.Device.Id, Model.Devices,
                                               HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "loginDevice", !Model.CanFiscalize,
                                               "", false, new { onChange = "cashierRegisterLogin()" }, !Model.CanFiscalize))
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-3 col-sm-6 @(Model.CanFiscalize ?  string.Empty : "document-head-disabled-input")">
                                    <input type="hidden" id="defaultPartnerId" value="@Model.PartnerId" />
                                    <input type="hidden" id="defaultPartnerName" value="@Model.PartnerName" />
                                    <input type="hidden" id="defaultPartnerRebate" value="@Model.PartnerRebate" />
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.PartnerName, Loc.Buyer, new { @class = "control-label", @title = Loc.Supplier })
                                        @Html.ValidationMessageFor(model => model.PartnerId, "", new { @class = "text-danger m-l-xs" })
                                        <div>
                                            @Html.HiddenFor(model => model.PartnerId)
                                            @Html.TextBoxFor(model => model.PartnerName,
                                                HtmlAttributesHelper.CreateInputAttributes("form-control typeahead_3 typeahead_large addable-input", "PartnerName", false, Loc.EnterPartner, true,
                                                new { dataUrl = Url.Action("SearchPartners", "Wholesale"), @title = Model.PartnerName }, !Model.CanFiscalize))
                                            <div class="addable-button">
                                                <button type="button" title="@Loc.AddingNewPartner"
                                                        id="NewPartner" class="btn createNewButton" onclick="openSubjectModal()">
                                                    <i class="fas fa-building"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-3 col-sm-6 @(Model.CanFiscalize ?  string.Empty : "document-head-disabled-input")">
                                    <div class="form-group">
                                        <label class="control-label">@Loc.Cashier</label>
                                        <div>
                                            @Html.DropDownListFor(model => model.CashierId, Model.Cashiers,
                                                HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "CashRegisterCashiersSelect", !Model.CanFiscalize,
                                                "", false, new { onChange = "cashierChanged(this)" }, !Model.CanFiscalize))
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-2 col-sm-6 @(Model.CanFiscalize ?  string.Empty : "document-head-disabled-input")">
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.Status, Loc.Status, new { @class = "control-label" })
                                        <div>
                                            @Html.DropDownListFor(model => model.Status,
                                                new SelectList(ViewBag.DocumentStatuses != null ? ViewBag.DocumentStatuses : new List<string>(), "Status", "Name"),
                                                HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "Status", false, Loc.Status, false, new { @title = Model.StatusDisplay }, !Model.CanFiscalize))
                                            @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-2 col-sm-12 document-head-disabled-input">
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.AcKey, Loc.InvoiceNumber, new { @class = "control-label m-t-xs" })
                                        <div>
                                            @Html.HiddenFor(model => model.AcKey)
                                            @Html.HiddenFor(model => model.AcKeyDisplay)
                                            <h4 class="control-label" id="AcKeyDisplayContainer">
                                                @{
                                                    Html.RenderPartial("~/Views/Shared/Components/_PrevNextKeyDisplay.cshtml",
                                                    new PrevNextKeyDisplayViewModel
                                                    {
                                                        KeyDisplayHint = Loc.OpenListOfInvoices,
                                                        KeyDisplayValue = Model.AcKeyDisplay,
                                                        NextNavigation = Url.Action("Next", "Move", new
                                                        {
                                                            Id = string.IsNullOrEmpty(Model.AcKey) ? "{modelId}" : Model.AcKey,
                                                            DocType = Model.Device.Id,
                                                            RedirectUrl = Url.Action("Index", "CashRegister", new { acKey = "{id}" })
                                                        }),
                                                        PrevNavigation = Url.Action("Prev", "Move", new
                                                        {
                                                            Id = string.IsNullOrEmpty(Model.AcKey) ? "{modelId}" : Model.AcKey,
                                                            DocType = Model.Device.Id,
                                                            RedirectUrl = Url.Action("Index", "CashRegister", new { acKey = "{id}" })
                                                        }),
                                                        KeyNavigation = Url.Action("IssuedBills", "CashRegister", new { acKey = Model.AcKey, date = Model.InvoiceDate.Date.ToString("o") })
                                                    });
                                                }
                                            </h4>
                                            @Html.ValidationMessageFor(model => model.AcKey, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="document-body document-body-with-info">
                                <div class="row">
                                    <div class="col-lg-8 col-md-10 col-sm-11 col-xs-12">
                                        @Html.Partial("_InvoiceIdentInput", new DecimalPlacesViewModel
                                        {
                                            DefaultDecimalPlacesPrice = Model.DefaultDecimalPlacesPrice,
                                            DefaultDecimalPlacesQuantity = Model.DefaultDecimalPlacesQuantity,
                                            DefaultDecimalPlacesValue = Model.DefaultDecimalPlacesValue,
                                            Price1Text = Model.Price1Text,
                                            Price2Text = Model.Price2Text,
                                            Price3Text = Model.Price3Text,
                                            Price4Text = Model.Price4Text,
                                            DisplayPaymentButton = Model.CanFiscalize,
                                            Author = AuthorType.POS,
                                            PosCustomerRabatAllowed = Model.CustomerRabatAllowed
                                        })
                                    </div>
                                </div>

                                <div class="table-responsive document-table m-b-xs">
                                    <div id="identTableLoader" class="table-overlay-loader hidden"><i class="fa fa-spinner fa-spin fa-2x text-muted"></i></div>
                                    <div class="dt-bootstrap" style="position:relative">
                                        <table id="invoice" data-grid-id="cashregister" class="table table-bordered showhidecolumns" role="grid">
                                            <thead>
                                                <tr role="row">
                                                    <th data-column-id="Position" style="width:5%" data-sortable="false">@Loc.PositionShort</th>
                                                    <th data-column-id="Item" style="width:17%">@Loc.Item</th>
                                                    <th data-column-id="Name" style="width:@(Model.IsTaxPayer? "18%" : "23%")">@Loc.Name</th>
                                                    <th data-column-id="Quantity" class="text-right">@Loc.Quantity</th>
                                                    <th data-column-id="MeasUnit" style="width:7%; min-width: 78px">@Loc.MeasUnit</th>
                                                    <th data-column-id="Price/MeasUnit" style="width:7%; min-width: 78px" class="text-right">@Loc.Price / @Loc.MeasUnit</th>
                                                    <th data-column-id="Discount" style="width:7%; min-width: 78px" class="text-right">@Loc.Discount %</th>
                                                    @if (Model.IsTaxPayer)
                                                    {
                                                        <th data-column-id="VAT" style="width:6%; min-width: 68px">@Loc.VAT</th>
                                                    }
                                                    <th data-column-id="Value" class="text-right">@Loc.Value</th>
                                                    <th data-column-id="CommentDelete" style="min-width:72px; width:72px;" data-sortable="false"></th>
                                                </tr>
                                            </thead>
                                            <tbody></tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-xs-12">
                                    @if (!Model.CanFiscalize &&
                                        !isInFiscalPrinterLocalization &&
                                        !PantheonRA.BackOffice.CurrentUser.IsDemo)
                                    {
                                        if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.RS)
                                        {
                                            <div class="addable-button">
                                                @Html.HiddenFor(model => model.ProtectionCode)
                                                @Html.HiddenFor(model => model.FiscalizationCode)
                                                <label>@Loc.SDCShort:</label> <span>@Model.FiscalizationCode</span>
                                            </div>
                                        }
                                        else
                                        {
                                            <div class="addable-button">
                                                @Html.HiddenFor(model => model.ProtectionCode)
                                                <label>@Loc.ProtectionCodeShort:</label> <span>@Model.ProtectionCode</span>
                                            </div>
                                            <div class="addable-button">
                                                @Html.HiddenFor(model => model.FiscalizationCode)
                                                <label>@Loc.FiscalizationCodeShort:</label> <span>@Model.FiscalizationCode</span>
                                            </div>
                                        }
                                    }
                                </div>
                            </div>

                            <div class="row document-footer">
                                <div class="col-md-1 col-sm-4">
                                    <div class="form-group text-center text-left-xs" onclick="openInvoiceNoteModal()">
                                        @Html.LabelFor(model => model.Note, Loc.Note, new { @class = "m-r-xs" })
                                        <i id="noteIcon" class="fa fa-comment clickable-icon @(string.IsNullOrEmpty(Model.Note) ? string.Empty : "btn-active")"></i>
                                        @Html.TextAreaFor(model => model.Note,
                                            HtmlAttributesHelper.CreateInputAttributes("form-control", "Note", !Model.CanFiscalize, Loc.Note, false, new { @rows = 3, @maxlength = "4096", @class = "hidden" }))
                                        @Html.ValidationMessageFor(model => model.Note, "", new { @class = "text-danger", @id = "Note-validation" })
                                    </div>
                                </div>
                                <div class="col-md-3 col-sm-4">
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.Statement, Loc.TextMessage, new { @class = "control-label m-t-sm" })
                                        <div>
                                            @Html.HiddenFor(model => model.Statement)
                                            @Html.DropDownList("Statements", new SelectList(ViewBag.DocTexts != null ? ViewBag.DocTexts : new List<string>(), "Id", "Code"),
                                                HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker", "Statements", !Model.CanFiscalize,
                                                Loc.TextMessage, true, new { @multiple = "multiple", @title = Loc.Select }, !Model.CanFiscalize))
                                            @Html.ValidationMessageFor(model => model.Statement, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-1 col-sm-4 document-head-disabled-input text-right" title="@Loc.Total">
                                    <div class="form-group">
                                        <label>@Loc.Total</label>
                                        <input type="text" id="TotalAmount" step="@Model.DefaultDecimalPlacesPrice" class="form-control text-right numberInput" disabled />
                                    </div>
                                </div>
                                <div class="col-md-1 col-sm-4 text-right  @(Model.CanFiscalize ? string.Empty : "document-head-disabled-input")">
                                    <div class="form-group">
                                        <label>@Loc.Discount %</label>
                                        <input type="text" id="DiscountPercentage" onchange="invoiceDiscountChange()" step="@Model.DefaultDecimalPlacesPrice" class="form-control text-right numberInput" autocomplete="off" @(Model.CanFiscalize ? string.Empty : "disabled") />
                                    </div>
                                </div>
                                <div class="col-md-1 col-sm-4 text-right  @(Model.CanFiscalize ? string.Empty : "document-head-disabled-input")">
                                    <div class="form-group">
                                        <label>@Loc.Discount</label>
                                        <input type="text" id="DiscountAmount" onchange="invoiceDiscountValueChange()" step="@Model.DefaultDecimalPlacesPrice" class="form-control text-right numberInput" autocomplete="off" @(Model.CanFiscalize ? string.Empty : "disabled") />
                                    </div>
                                </div>
                                <div class="col-md-2 col-sm-4 document-head-disabled-input text-right" title="@Loc.Value">
                                    <div class="form-group">
                                        <label>@Loc.Value</label>
                                        <input type="text" id="TotalValue" value="" step="@Model.DefaultDecimalPlacesPrice" class="form-control text-right numberInput" disabled />
                                    </div>
                                </div>
                                @if (Model.IsTaxPayer)
                                {
                                    <div class="col-md-1 col-sm-4 document-head-disabled-input text-right">
                                        <div class="form-group">
                                            <label>@Loc.VAT</label>
                                            <input type="text" id="TaxAmount" step="@Model.DefaultDecimalPlacesPrice" class="form-control text-right numberInput" disabled />
                                        </div>
                                    </div>
                                }
                                <div class="@(Model.IsTaxPayer ? "col-md-2 col-sm-8" : "col-md-3 col-sm-12") document-head-highlight-input">
                                    <div class="form-group text-right">
                                        <label>@Loc.ToPay</label>
                                        <div>
                                            <span id="ToPayAmountDisplay"></span>
                                            <input type="hidden" class="form-control" id="ToPayAmount" step="2" autocomplete="off" style="width:20%" disabled>
                                            <span>@Model.Currency</span>
                                            <input type="hidden" class="form-control" id="Currency" value="@Model.Currency" autocomplete="off" style="width:20%" disabled>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="divided-content-side">
                            <div class="tabs-container">
                                <ul class="nav nav-tabs horizontal-menu">
                                    <li class="active divided-tab-2"><a data-toggle="tab" href="#home" class="local-tab">@Loc.BasicData</a></li>
                                    <li class="divided-tab-2">
                                        <a data-toggle="tab" href="#connections" class="local-tab">
                                            @Loc.Connected <span class="badge" id="connectionsCount">
                                                @(Model.OrderConnections != null || Model.MoveAdvancePayment != null ?
                                                    (Model.OrderConnections != null ? Model.OrderConnections.Count() : 0) +
                                                    (Model.MoveAdvancePayment != null ? Model.MoveAdvancePayment.Count() : 0) +
                                                    (Model.CanceledLinkAcKey != null ? Model.CanceledLinkAcKey.Count() : 0) +
                                                    (Model.CanceledLinkAcKeyLnk != null ? Model.CanceledLinkAcKeyLnk.Count() : 0)
                                                    : (Model.CanceledLinkAcKey != null ? Model.CanceledLinkAcKey.Count() : 0) +
                                                    (Model.CanceledLinkAcKeyLnk != null ? Model.CanceledLinkAcKeyLnk.Count() : 0))
                                            </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                            <div class="tab-content">
                                <div id="home" class="tab-pane fade in active">
                                    <div class="form-horizontal form-md form-right m-t-lg">

                                        <div class="form-group invoice-form">
                                            <input type="hidden" id="defaultInvoiceDate" value="@Model.InvoiceDate.ToString("o")" />
                                            <label class="col-md-4 control-label">@Loc.InvoiceDate</label>
                                            <div class="col-md-8">
                                                <div class="input-group">
                                                    <span class="input-group-addon"><i class="far fa-calendar alt"></i></span>
                                                    @if (Model.CanFiscalize || Model.IsFiscalSalesBookSelected)
                                                    {
                                                        @Html.TextBoxFor(model => model.InvoiceDate, "{0:" + Loc.DateFormat + "}",
                                                            HtmlAttributesHelper.CreateInputAttributes("form-control datepicker",
                                                            "InvoiceDate", !Model.CanFiscalize))
                                                    }
                                                    else
                                                    {
                                                        @Html.TextBoxFor(model => model.InvoiceDate, "{0:" + Loc.DateFormat + "}",
                                                            HtmlAttributesHelper.CreateInputAttributes("form-control datepicker hidden",
                                                            "InvoiceDate", !Model.CanFiscalize))

                                                        @Html.TextBoxFor(model => model.FiscalDate, "{0:" + Loc.DateTimeFormatFull + "}",
                                                        HtmlAttributesHelper.CreateInputAttributes("form-control",
                                                        null, !Model.CanFiscalize, null, false, null, true))
                                                    }
                                                </div>
                                            </div>
                                        </div>

                                        @if (!string.IsNullOrEmpty(Model.InvoiceNumber))
                                        {
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.InvoiceNumber, Loc.Invoice, new { @class = "col-md-4 control-label" })
                                                <div class="col-md-8">
                                                    @Html.TextBoxFor(model => model.InvoiceNumber, HtmlAttributesHelper.CreateInputAttributes("form-control", null, true,
                                                    "", false, null, true))
                                                    @Html.ValidationMessageFor(model => model.InvoiceNumber, "", new { @class = "text-danger" })
                                                </div>
                                            </div>
                                        }

                                        @Html.HiddenFor(model => model.PartnerWayOfSale)

                                        @if (!isInFiscalPrinterLocalization && CurrentUser.Localization != Localization.Code.ME && CurrentUser.Localization != Localization.Code.RS)
                                        {
                                            <hr class="hr-dashed" />

                                            <div class="form-group">
                                                <div class="col-md-4 col-sm-12 m-t-xs text-right-lg text-right-md">
                                                    @if (Model.IsFiscalSalesBookSelected)
                                                    {
                                                        @Html.CheckBoxFor(model => model.IsFiscalSalesBookSelected,
                                                            HtmlAttributesHelper.CreateInputAttributes("js-switch", "IsFiscalSalesBookSelected",
                                                            !Model.CanFiscalize, "", true, new { @checked = true }))
                                                    }
                                                    else
                                                    {
                                                        @Html.CheckBoxFor(model => model.IsFiscalSalesBookSelected,
                                                            HtmlAttributesHelper.CreateInputAttributes("js-switch", "IsFiscalSalesBookSelected", !Model.CanFiscalize))
                                                    }
                                                    <label class="hidden-lg hidden-md m-l-sm">@Loc.FiscalSalesBook</label>
                                                </div>
                                                <label class="col-xs-8 hidden-xs hidden-sm control-label">@Loc.FiscalSalesBook</label>
                                            </div>

                                            <div id="fiscalSalesBookData" class="@(Model.IsFiscalSalesBookSelected ? string.Empty : "hidden")">
                                                <div class="form-group form-group-horizontal invoice-form hidden">
                                                    <label class="col-md-4 control-label">@Loc.FiscalSalesBookShort</label>
                                                    @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.SI)
                                                    {
                                                        <div class="col-md-2">
                                                            @Html.TextBoxFor(model => model.FiscSalesBookSetNo,
                                                                HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscSalesBookSetNo",
                                                                !Model.CanFiscalize, Loc.FiscalSalesBookSetNumber, true, new { @maxlength = "2", title = @Model.FiscSalesBookSetNo }))
                                                        </div>
                                                        <div class="col-md-3 padding-none-lg padding-none-md">
                                                            @Html.TextBoxFor(model => model.FiscSalesBookSerNo,
                                                                HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscSalesBookSerNo",
                                                                !Model.CanFiscalize, Loc.FiscalSalesBookSerialNumber, true, new { @maxlength = "12", title = @Model.FiscSalesBookSerNo }))
                                                        </div>
                                                        <div class="col-md-3">
                                                            @Html.TextBoxFor(model => model.FiscSalesBookDocNo,
                                                                HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscSalesBookDocNo",
                                                                !Model.CanFiscalize, Loc.FiscalSalesBookDocumentNumber, true, new { minlength = "1", maxLength = "20", title = @Model.FiscSalesBookDocNo }))
                                                        </div>
                                                    }
                                                    else
                                                    {
                                                        <div class="col-md-8">
                                                            @Html.TextBoxFor(model => model.FiscSalesBookDocNo,
                                                                HtmlAttributesHelper.CreateInputAttributes("form-control", "FiscSalesBookDocNo",
                                                                !Model.CanFiscalize, Loc.FiscalSalesBookDocumentNumber, true, new { minlength = "1", maxLength = "20", title = @Model.FiscSalesBookDocNo }))
                                                        </div>
                                                    }
                                                </div>
                                            </div>
                                        }

                                        <hr class="hr-dashed" />

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.Department, Loc.Department, new
                                            {
                                                @class = "col-md-4 control-label",
                                                @title = Loc.Department
                                            })
                                            <div class="col-md-8">
                                                <input type="hidden" id="defaultDepartment" value="@Model.Department" />
                                                <select id="Department" name="Department" class="form-control custom-select" @(Model.CanFiscalize ? string.Empty : "disabled")>
                                                    <option></option>
                                                    @foreach (var item in ViewBag.Departments)
                                                    {
                                                        <option value="@item.Id" @(Model.Department == item.Id ? "selected" : string.Empty)>
                                                            @item.Name
                                                        </option>
                                                    }
                                                </select>
                                                @Html.ValidationMessageFor(model => model.Department, "", new { @class = "text-danger", @id = "Department-validation" })
                                            </div>
                                        </div>

                                        @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.RS)
                                        {
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.BuyerIdDef, Loc.IdBuyer, new { @class = "col-md-4 col-sm-12 text-left-sm control-label" })
                                                <div class="col-md-2 col-sm-4">
                                                    <select id="BuyerIdDef" name="BuyerIdDef" class="form-control custom-select" @(!Model.CanFiscalize ? "readonly" : string.Empty)>
                                                        <option></option>
                                                        @foreach (var item in ViewBag.BuyerTypeLookup)
                                                        {
                                                            <option value="@item.Id" @(Model.BuyerIdDef.HasValue ? (Model.BuyerIdDef.Value.ToString() == item.Id ? "selected" : string.Empty) : string.Empty)>
                                                                @item.Name
                                                            </option>
                                                        }
                                                    </select>
                                                    @Html.ValidationMessageFor(model => model.BuyerIdDef, "", new { @class = "text-danger" })
                                                </div>
                                                <div class="col-md-6 col-sm-8 padding-left-none-sm padding-left-none-md padding-left-none-lg">
                                                    @Html.TextBoxFor(model => model.BuyerID,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control", "BuyerID", !Model.CanFiscalize, Loc.CostCarrierBuyer))
                                                    @Html.ValidationMessageFor(model => model.BuyerID, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.BuyerCostCenterIdDef, Loc.OptionalBuyerField, new { @class = "col-md-4 col-sm-12 text-left-sm control-label" })
                                                <div class="col-md-2 col-sm-4">
                                                    <select id="BuyerCostCenterIdDef" name="BuyerCostCenterIdDef" class="form-control custom-select" @(!Model.CanFiscalize ? "readonly" : string.Empty)>
                                                        <option></option>
                                                        @foreach (var item in ViewBag.BuyerCostCenterTypeLookup)
                                                        {
                                                            <option value="@item.Id" @(Model.BuyerCostCenterIdDef.HasValue ? (Model.BuyerCostCenterIdDef.Value.ToString() == item.Id ? "selected" : string.Empty) : string.Empty)>
                                                                @item.Name
                                                            </option>
                                                        }
                                                    </select>
                                                    @Html.ValidationMessageFor(model => model.BuyerCostCenterIdDef, "", new { @class = "text-danger" })
                                                </div>
                                                <div class="col-md-6 col-sm-8 padding-left-none-sm padding-left-none-md padding-left-none-lg">
                                                    @Html.TextBoxFor(model => model.BuyerCostCenterId,
                                                    HtmlAttributesHelper.CreateInputAttributes("form-control", "BuyerCostCenterId", !Model.CanFiscalize, Loc.OptionalBuyerField))
                                                    @Html.ValidationMessageFor(model => model.BuyerCostCenterId, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.SpecPayment, Loc.SpecialTraffic, new { @class = "col-md-4 col-sm-12 text-left-sm control-label" })
                                                <div class="col-md-8 col-sm-12">
                                                    @Html.DropDownListFor(model => model.SpecPayment, new List<SelectListItem>
                                                    {
                                                        new SelectListItem{ Text="", Value = null },
                                                        new SelectListItem{ Text="N - " + Loc.TrafficFreeOfCharge, Value = "N" },
                                                        new SelectListItem{ Text="V - " + Loc.SinglePurposeVouchers, Value = "V" },
                                                    }, HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "SpecPayment", !Model.CanFiscalize, Loc.SpecialTraffic))
                                                    @Html.ValidationMessageFor(model => model.SpecPayment, "", new { @class = "text-danger" })
                                                </div>
                                            </div>
                                        }

                                        @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.RS)
                                        {
                                            <div id="referenceDocCancellationContainer" class="form-group">
                                                @Html.LabelFor(model => model.RefundRelatedDoc, Loc.ReferenceDocCancellation, new
                                                {
                                                    @class = "col-md-4 col-sm-12 control-label",
                                                    @title = Loc.ReferenceDocCancellation
                                                })
                                                <div class="col-md-4 col-sm-6">
                                                    @Html.TextBoxFor(model => model.RefundRelatedDoc,
                                                        HtmlAttributesHelper.CreateInputAttributes("form-control", "RefundRelatedDoc", !Model.CanFiscalize, Loc.CancellationReferenceDocumentNumber, false,
                                                        new { @autocomplete = "off" }))
                                                    @Html.ValidationMessageFor(model => model.RefundRelatedDoc, "", new { @class = "text-danger" })
                                                </div>
                                                <div class="col-md-4 col-sm-6 padding-left-none-sm padding-left-none-md padding-left-none-lg">
                                                    <div class="input-group">
                                                        <span class="input-group-addon">
                                                            <i class="far fa-calendar alt"></i>
                                                        </span>
                                                        @Html.TextBoxFor(model => model.RefundRelatedDocDate, Model.RefundRelatedDocDate.HasValue ? Model.RefundRelatedDocDate.Value.ToString(Loc.DateTimeFormatFull) : null,
                                                        HtmlAttributesHelper.CreateInputAttributes("form-control cashregister-dt-picker", "RefundRelatedDocDate", false, Loc.DocumentDate))
                                                    </div>
                                                    @Html.ValidationMessageFor(model => model.RefundRelatedDocDate, "", new { @class = "text-danger", @id = "OrderFormDate-validation" })
                                                </div>
                                            </div>
                                        }

                                        @if (!string.IsNullOrEmpty(Model.LinkedJournal))
                                        {
                                            <div class="form-group invoice-form">
                                                <label class="col-md-4 control-label">@Loc.CashRevenueShort</label>
                                                <div class="col-md-8">
                                                    @Html.TextBoxFor(model => model.LinkedJournal, new { @class = "form-control", disabled = "disabled" })
                                                </div>
                                            </div>
                                        }

                                        @if (!Model.CanFiscalize)
                                        {
                                            <hr class="hr-dashed" />
                                            <div class="form-group">
                                                @{ var displayLabel = true; }
                                                @foreach (var paymentMethod in Model.PaymentMethods)
                                                {
                                                    if (!paymentMethod.IsRefund)
                                                    {
                                                        <label class="col-md-4 p-top-none control-label">@(displayLabel ? Loc.PaymentMethod : string.Empty)</label>
                                                        displayLabel = false;
                                                        <div class="col-md-8 m-b-xs">
                                                            <div class="row">
                                                                <div class="col-xs-7">
                                                                    <span title="@paymentMethod.Name">@paymentMethod.Name</span>
                                                                </div>
                                                                <div class="col-xs-5 text-right">
                                                                    <span>@string.Format("{0:n2}", paymentMethod.Amount)</span>
                                                                    <span class="text-muted">@Model.Currency</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    }
                                                }

                                            </div>
                                            if (Model.PaymentMethods.Any(x => x.IsRefund))
                                            {
                                                <hr class="hr-dashed" />
                                                <div class="form-group invoice-form">
                                                    <label class="col-md-4 text-right control-label p-none">@Loc.Return</label>
                                                    <div class="col-md-8 text-right">
                                                        <input class="highlighted-input text-right form-control" disabled value="@string.Format("{0:n2}", Math.Abs(Model.PaymentMethods.Where(x => x.IsRefund).Sum(s => s.Amount))) @Model.Currency" />
                                                    </div>
                                                </div>
                                            }
                                        }
                                    </div>
                                </div>
                                <div id="connections" class="row tab-pane fade in">
                                    @if (Model.IsCanceled)
                                    {
                                        <div class="form-group">
                                            @if (Model.CanceledLinkAcKey != null && Model.CanceledLinkAcKey.Count() > 0)
                                            {
                                                for (var x = 0; x < Model.CanceledLinkAcKey.Count(); x++)
                                                {
                                                    <h4 class="form-control clickable-icon connectionContainer" id="canceledLinkAcKey" disabled>
                                                        <a class="text-danger" onclick="canceledLink('@Model.CanceledLinkAcKey[x].AcLinkKey')">
                                                            @Model.CanceledLinkAcKey[x].AcLinkKeyDisplay
                                                        </a>
                                                        <span class="pull-right text-danger">@Model.CanceledLinkAcKey[x].LinkValue.ToString("n2") @Model.Currency</span>
                                                    </h4>
                                                }
                                            }
                                            else
                                            {
                                                for (var y = 0; y < Model.CanceledLinkAcKeyLnk.Count(); y++)
                                                {
                                                    <h4 class="form-control clickable-icon connectionContainer" id="canceledLinkAcKeyLnk" disabled>
                                                        <a class="text-danger" onclick="canceledLink('@Model.CanceledLinkAcKeyLnk[y].AcKey')">
                                                            @Model.CanceledLinkAcKeyLnk[y].AcKeyDisplay
                                                        </a>
                                                        <span class="pull-right text-danger">@Model.CanceledLinkAcKeyLnk[y].Value.ToString("n2") @Model.Currency</span>
                                                    </h4>
                                                }
                                            }
                                        </div>
                                    }
                                    @if (Model.MoveAdvancePayment != null)
                                    {
                                        for (var i = 0; i < Model.MoveAdvancePayment.Count(); i++)
                                        {
                                            <div class="form-group">
                                                <h4 class="form-control clickable-icon connectionContainer advPayConn" disabled>
                                                    <a onclick="redirectToAdvancePayment('@Model.MoveAdvancePayment[i].AcLinkKey')">
                                                        @Model.MoveAdvancePayment[i].AcLinkKeyDisplay
                                                    </a>
                                                    <span class="pull-right">@Model.MoveAdvancePayment[i].LinkValue.ToString("n2") @Model.Currency</span>
                                                </h4>
                                            </div>
                                        }
                                    }
                                    @if (Model.OrderConnections != null)
                                    {
                                        for (var i = 0; i < Model.OrderConnections.Count(); i++)
                                        {
                                            <div class="form-group">
                                                <h4 class="form-control clickable-icon connectionContainer" disabled>
                                                    <a onclick="redirectToOrderDocument('@Model.OrderConnections[i].AcLnkKey', '@Model.OrderConnections[i].OrderType')">
                                                        @Model.OrderConnections[i].AcLnkKeyDisplay
                                                    </a>
                                                    <span class="pull-right">@Model.OrderConnections[i].Price.ToString("n2") @Model.Currency</span>
                                                </h4>
                                            </div>
                                        }
                                    }
                                </div>
                            </div>
                        </div>
                    </div>

                    Html.RenderPartial("~/Views/Wizard/Wizard.cshtml");

                    <div id="SaveInvoiceJson" data-url="@Url.Action("SaveInvoiceJson", "CashRegister")" style="display:none"></div>
                    <div id="LPFRUpdateInvoice" data-url="@Url.Action("LPFRUpdateInvoice", "Move")" style="display:none"></div>
                    <div id="lpfrFiscalizationDataUrl" data-url="@Url.Action("GetLpfrFiscalizationData", "Move")" style="display:none"></div>
                    <div id="PrintPreview" data-url="@Url.Action("PrintInvoicePdf", "CashRegister")" style="display:none"></div>
                    <div id="InvoiceIdents" data-url="@Url.Action("GetInvoiceIdents", "CashRegister")" style="display:none"></div>
                    <div id="CashRegisterLogin" data-url="@Url.Action("CashRegisterLogin", "CashRegister")" style="display:none"></div>
                    <div id="CashRegisterLogOut" data-url="@Url.Action("CashRegisterLogout", "CashRegister")" style="display:none"></div>
                    <div id="CashRegisterIndex" data-url="@Url.Action("Index", "CashRegister")" style="display:none"></div>
                    <div id="CashRegisterCancelInvoice" data-url="@Url.Action("CancelInvoice", "CashRegister")" style="display:none"></div>
                    <div id="CashRegisterRemoveInvoice" data-url="@Url.Action("RemoveInvoice", "CashRegister")" style="display:none"></div>
                    <div id="CashRegisterLoginLoc" data-text="@Loc.CodeLogin" style="display:none"></div>
                    <div id="CashRegisterLogoutLoc" data-text="@Loc.CashRegisterLogout" style="display:none"></div>
                    <div id="LoginLoc" data-text="@Loc.Login" style="display:none"></div>
                    <div id="LoggingInLoc" data-text="@Loc.LoggingIn" style="display:none"></div>
                    <div id="InvalidLoginLoc" data-text="@Loc.InvalidLogin" style="display:none"></div>
                    <div id="RequestErrorLoc" data-text="@Loc.RequestError" style="display:none"></div>
                    <div id="CreateJournal" data-url="@Url.Action("Create", "Journal")" style="display:none"></div>
                    <div id="NewJournal" data-text="@Loc.NewJournal" style="display:none"></div>
                    <div id="openNewJournalInitialAmount" data-text="@Loc.CashRegisterMoneyDeposit" style="display:none"></div>
                    <div id="open" data-text="@Loc.Open" style="display:none"></div>
                    <div id="openNewJournalFailed" data-text="@Loc.OpenNewJournalFailed" style="display:none"></div>
                    <div id="LoadingLoc" data-text="@Loc.Loading" style="display:none"></div>
                    <div id="InvoiceDisplayErrorLoc" data-text="@Loc.InvoiceDisplayError"></div>
                    <div id="GeneralErrorLoc" data-text="@Loc.GeneralError"></div>
                    <div id="CancelationOfInvoiceLoc" data-text="@Loc.CancelationOfInvoice"></div>
                    <div id="CancelInvoiceWillBecreatedByCurrentUserLoc" data-text="@(string.Format(Loc.CancelInvoiceWillBecreatedByCurrentUser, PantheonRA.BackOffice.CurrentUser.DisplayName))"></div>
                    <div id="RabateValidationError" data-text="@Loc.RabateAmountValidation" style="display:none"></div>
                    <div id="CancelInvoiceConfirmLoc" data-text="@Loc.ConfirmCancelInvoice" style="display:none"></div>
                    <div id="BuyerChangedChangeIdentRebate" data-text="@Loc.BuyerChangedChangeIdentRebate" style="display:none"></div>
                    <input id="DocTextsUrl" value="@Url.Action("GetDocTextsForDocType", "DocumentText")" type="hidden" />
                    <input id="CreatePriceChangeDoc" value="@Url.Action("CreatePriceChangeDoc", "PriceChange")" type="hidden" />
                    <input id="EditPriceChange" value="@Url.Action("Edit", "PriceChange")" type="hidden" />
                    <input type="hidden" id="AjpesUrl" value="@Url.Action("AjpesSearch", "Subjects")" />
                    <input type="hidden" id="ValidPaymentMethods" value="@Url.Action("GetValidPaymentMethods", "CashRegister")" />
                    <input type="hidden" id="SubjectRewriteDataLoc" value="@Loc.RewriteSubjectData" />
                    <input type="hidden" id="YesLoc" value="@Loc.Yes" />
                    <input type="hidden" id="NoLoc" value="@Loc.No" />
                    <input type="hidden" id="OkLoc" value="@Loc.OK" />
                    <input type="hidden" id="ConfirmLoc" value="@Loc.Confirm" />
                    <input type="hidden" id="ErrorLoc" value="@Loc.Error" />
                    <input type="hidden" id="CancelLoc" value="@Loc.Cancel" />
                    <input type="hidden" id="CancelInvoiceLoc" value="@Loc.CancelInvoice" />
                    <input type="hidden" id="EnterPinLoc" value="@Loc.EnterPin" />
                    <input type="hidden" id="WayOfSaleTaxCommitted" value="@WayOfSale.IsTaxComitted" />
                    <input type="hidden" id="CreateSubjectUrl" value="@Url.Action("CreateFromPartial", "Subjects")" />
                    <input type="hidden" id="IdentEditUrl" value="@Url.Action("Edit", "Products")" />
                    <input type="hidden" id="CentralApiUrl" value="@(Url.Action("Index", "CashRegister") == "/" ? "/CashRegister" : Url.Action("Index", "CashRegister"))" />
                    <input type="hidden" id="LocalApiUrl" value="@System.Configuration.ConfigurationManager.AppSettings.Get("FiscalizationLocalApiUrl")" />
                    <input type="hidden" id="InvoicePrintSuccessLoc" value="@Loc.InvoicePrintSuccess" />
                    <input type="hidden" id="RequiredInputLoc" value="@Loc.RequiredInput" />
                    <input type="hidden" id="PaymentMethodsModalHelpUrl" value="@PantheonRA.BackOffice.Helpers.SiteHelpAttributeHelper.GetHelpUrl(PantheonRA.BackOffice.Enums.HelpIds.MultiplePaymentMethods)" />
                    <input type="hidden" id="BuyerEnum" value="@SubjectType.Buyer" />
                    <input type="hidden" id="UrlRegisterDeposit" value="@Url.Action("Register", "Deposit")" />
                    <input type="hidden" id="posPartialCancelHelp" value="@Loc.HelpUrl@HelpIds.POSPartialCancel" />
                    <input type="hidden" id="LocOk" value="@Loc.OK" />
                    <input type="hidden" id="LocME" value="@Localization.Code.ME.ToString()" />
                    <input type="hidden" id="LocRS" value="@Localization.Code.RS.ToString()" />
                    <input type="hidden" id="UserLoc" value="@CurrentUser.Localization.ToString()" />
                    <input type="hidden" id="CurrentUserIsDemo" value="@CurrentUser.IsDemo.ToString()" />
                    <input type="hidden" id="FiscalizationFailedIdentWithoutMeasUnitLoc" value="@Loc.FiscalizationFailedIdentWithoutMeasUnit" />
                    <input type="hidden" id="InvoiceIdentNegativeQuantityErrorLoc" value="@Loc.InvoiceIdentNegativeQuantityError" />
                    <input type="hidden" id="PAASPrintByAcKeyAndTypeUrl" value="@Url.Action("PAASPrintByAcKeyAndType", "Move")" />
                    <input type="hidden" id="GetCostDrvUrl" value="@Url.Action("GetCostDrv", "CostDrv")" />
                    <input type="hidden" id="InoicePositionQuantityOrPrice0WarningLoc" value="@Loc.InoicePositionQuantityOrPrice0Warning" />
                    <input type="hidden" id="DifferentOperatersLoc" value="@Loc.DifferentOperaters" />
                    <input type="hidden" id="DifferentOperatersTaxingfailedLoc" value="@Loc.DifferentOperatersTaxingfailed" />
                    <input type="hidden" id="PositiveAndNegativeQuantityCannotBeOnTheSameDocumentLoc" value="@Loc.PositiveAndNegativeQuantityCannotBeOnTheSameDocument" />
                    <input type="hidden" id="AllTaxesNeedFiscalCodeLoc" value="@Loc.AllTaxesNeedFiscalCode" />
                    <input type="hidden" id="PrintingCopyNotAllowedLoc" value="@Loc.PrintingCopyNotAllowed" />
                    <input type="hidden" id="BuyerHasOpenAdvancePaymentsIRISLoc" value="@Loc.BuyerHasOpenAdvancePayments" />
                    <input type="hidden" id="BuyerOnDocumentHasOpenAdvancePaymentsLoc" value="@Loc.BuyerOnDocumentHasOpenAdvancePayments" />
                    <input type="hidden" id="MoveAdvancePaymentLinksPOSUrl" value="@Loc.HelpUrl@HelpIds.MoveAdvancePaymentLinksPOS" />
                    <input type="hidden" id="AdvancePaymentMoveLinksTypeWholesale" value="@AdvancePaymentMoveLinksType.Wholesale" />
                    <input type="hidden" id="MoveAdvancePaymentLinksUrl" value="@Url.Action("MoveAdvancePaymentLinks", "AdvancePayment")" />
                    <input type="hidden" id="EditReceivingAdvancePaymentUrl" value="@Url.Action("EditReceivingAdvancePayment", "AdvancePayment")" />
                    <input type="hidden" id="GetIdentFxRateUrl" value="@Url.Action("GetIdentFxRate", "Currency")" />
                    <input type="hidden" id="EditBuyerOrderUrl" value="@Url.Action("EditBuyerOrder", "Order")" />
                    <input type="hidden" id="EditSupplierOrderUrl" value="@Url.Action("EditSupplierOrder", "Order")" />
                    <input type="hidden" id="OrderTypeBuyer" value="@OrderType.Buyer" />
                    <input type="hidden" id="OrderTypeSupplier" value="@OrderType.Supplier" />
                    <input type="hidden" id="AdvancePaymentTypeOfDoc" value="@TypeOfDoc.AdvancePayment" />
                    <input type="hidden" id="posPartialCancelUserManualHelp" value="@SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ExamplePosCancel)" />
                }
                else
                {
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="ibox">
                                <div class="ibox-content">
                                    <div class="alert alert-warning m-b-none">
                                        @if (!Model.CertificateExists)
                                        {
                                            <h3>@Loc.NoCertificate.ToUpper()</h3>
                                            <span>@Loc.YouDoNotHaveAValidCertificate</span>
                                        }
                                        else if (!Model.Devices.Any())
                                        {
                                            <h3>@Loc.NoDevices.ToUpper()</h3>
                                            <span>@Loc.NoActiveDevices</span>
                                        }
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                }
            </form>
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="noteModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form onSubmit="identNoteSubmit(event)">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="note-title"></h4>
                </div>
                <div class="modal-body">

                    <div class="form-group">
                        <label for="item-note" class="control-label">@Loc.Note:</label>
                        <textarea class="form-control" id="item-note" rows="3"> </textarea>
                    </div>

                </div>
                @if (Model.CanFiscalize)
                {
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">@Loc.Save</button>
                    </div>
                }
            </form>
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="invoiceNoteModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel"></h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="item-note" class="control-label">@Loc.Note:</label>
                        <textarea class="form-control" id="item-note" rows="3"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="saveInvoiceNote()" data-dismiss="modal">@Loc.Save</button>
            </div>
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="cashierLoginModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" onclick="resetCashier(@PantheonRA.BackOffice.CurrentUser.Id)" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="font-size:20px;">&times;</span></button>
            </div>
            <form id="loginForm" method="post" action="@Url.Action("ReLogin", "CashRegister")" onSubmit="cashierRegisterLogin(event)">
                <div class="modal-body">
                    <div class="form-group">
                        <label for="password" class="control-label">@Loc.Password:</label>
                        <input type="password" class="form-control" id="loginPassword" name="Password" autocomplete="off" />
                        <input type="hidden" class="form-control" id="userId" name="UserId" autocomplete="off" />
                    </div>
                    <span class="text-danger" id="login-modal-validation"></span>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-success">
                        <span class="m-r-xs"></span><i class="fa"></i>
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="subjectModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-xxl" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <a class="btn-transparent m-r-xs pull-right" href="@SiteHelpAttributeHelper.GetHelpUrl(HelpIds.ExampleSubjectsNewInModal)" target="_blank"><i class="fas fa-book-reader"></i></a>
                <h3 class="text-left container">@Loc.CreateNewSubject</h3>
            </div>
            <div class="modal-body">
                @{Html.RenderPartial("~/Views/Subjects/_CreateSubjectFormPartial.cshtml",
                    new SubjectCreateViewModel()
                    {
                        SubjectEditData = new SubjectEditData()
                        {
                            SelectedCountryId = Model.SelectedCountry,
                            WayOfSale = Model.DefaultSubjWayOfSale,
                            WayOfSaleSupplier = Model.DefaultSubjWayOfSaleSupplier,
                            IsBuyer = true,
                            IsSupplier = false,
                        },
                        Countries = ViewBag.Countries,
                        ForCountry = PantheonRA.BackOffice.CurrentUser.Localization.ToString()
                    });
                }
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="saveSubject()"><i class="fa fa-check m-r-xs"></i>@Loc.Add</button>
                <button type="button" data-dismiss="modal" class="btn btn-link"><i class="fa fa-times m-r-xs text-primary"></i>@Loc.Cancel</button>
            </div>
        </div>
    </div>
</div>

<div class="modal inmodal fade" id="errorModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-md" role="document">
        <div class="modal-content">
            <div class="modal-body"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">@Loc.OK</button>
            </div>
        </div>
    </div>
</div>

<div id="taxOptions" hidden>
    @foreach (var tax in ViewBag.Taxes)
    {
        <option value="@tax.VATCode" data-vat="@tax.VAT" data-fiscalCode="@tax.FiscalCode" data-displaytext="@(tax.VATCode + "  " + tax.VAT + "% - " + tax.Name)">
            @tax.VATCode
        </option>
    }
</div>

<div id="measUnitOptions" hidden>
    @foreach (var unit in ViewBag.MeasurementUnits)
    {
        <option value="@unit.Id">
            @unit.Id
        </option>
    }
</div>

<div id="paymentMethodsModalContent" hidden>
    <div class="payment-methods-modal-content">
        <div class="payment-methods-modal-list">
            <table class="payment-method-table">
                @if (ViewBag.PaymentTypes != null)
                {
                    foreach (var paymentMethod in (List<PantheonRA.BackOffice.Models.PaymentMethodViewModel>)ViewBag.PaymentTypes)
                    {
                        <tr onclick="paymentMethodRowClicked(event)">
                            <td>
                                @if (paymentMethod.Icon != null && paymentMethod.Icon.Length > 0)
                                {
                                    <img class="image-payment-type" src="data:image/png;base64,@System.Convert.ToBase64String(paymentMethod.Icon)" />
                                }
                                else
                                {
                                    if (paymentMethod.PaymentTypeCode == PaymentType.Cash)
                                    {
                                        <div class="icon-payment-type-cash"></div>
                                    }
                                    else if (paymentMethod.PaymentTypeCode == PaymentType.CreditCard)
                                    {
                                        <div class="icon-payment-type-card"></div>
                                    }
                                    else
                                    {
                                        <div class="icon-payment-type"></div>
                                    }
                                }
                            </td>
                            <td>@paymentMethod.Name</td>
                            <td>
                                <input type="text"
                                       data-name="@paymentMethod.Name"
                                       data-id="@paymentMethod.PaymentMethod"
                                       data-fiscalize="@paymentMethod.FiscalGroup"
                                       value="@(Model.PaymentMethods != null && Model.PaymentMethods.SingleOrDefault(x => x.AcPayMethod == paymentMethod.PaymentMethod && !x.IsRefund) != null ? Math.Abs(Model.PaymentMethods.SingleOrDefault(x => x.AcPayMethod == paymentMethod.PaymentMethod && !x.IsRefund).Amount).ToString() : string.Empty)"
                                       class="form-control pull-right numberInput paymentTypeInput"
                                       onkeyup="paymentMethodOnKeyUp(event)"
                                       onblur="paymentMethodOnBlur(event)" />
                            </td>
                        </tr>
                    }
                }
            </table>
        </div>
        <div>
            <table class="payment-methods-modal-sums">
                <tr>
                    <td style="width:58%"><h2>@Loc.ToPay: <span id="PaymentMethodsModalToPay" class="m-r-xs"></span><span>@Model.Currency</span></h2></td>
                    <td>
                        <table class="payment-methods-modal-paid-totals">
                            <tr>
                                <td><label>@Loc.Payment</label></td>
                                <td><input id="paymentModalPaidValue" type="text" class="form-control" disabled /></td>
                            </tr>
                            <tr>
                                <td><label id="toPayLabel">@Loc.ToPay</label><label id="toReturnLabel">@Loc.ToReturn</label></td>
                                <td><input id="paymentModalOverpaidValue" type="text" class="form-control" disabled /></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>

@{Html.RenderPartial("~/Views/AdvancePayment/_MoveAdvancePaymentLinksModal.cshtml");}
@{Html.RenderPartial("~/Views/Shared/Components/_PartialCancelInvoice.cshtml", new PartialCancelInvoiceModalModel()
    {
        Type = InvoiceType.POS,
        PartialCancelDefaultDecimalPlacesPrice = Model.DefaultDecimalPlacesPrice,
        PartialCancelDefaultDecimalPlacesQuantity = Model.DefaultDecimalPlacesQuantity,
        PartialCancelDefaultDecimalPlacesValue = Model.DefaultDecimalPlacesValue,
    });
}

@section pageScripts{
    @Scripts.Render("~/bundles/lpfr")
    @Scripts.Render("~/bundles/app/cash_register", "~/bundles/moment", "~/bundles/qrcode")
    <script type="text/javascript" src="~/Scripts/plugins/sweetAlert/sweetalert.min.js"></script>
    @Scripts.Render("~/bundles/depositModal")
    @Scripts.Render("~/bundles/invoiceIdent")
    @Scripts.Render("~/bundles/cashRegister")
    @Scripts.Render("~/bundles/reports")
    @Scripts.Render("~/bundles/wizardHelper")

    <script>
        $(document).ready(function () {
            let isInFiscalCashRegister = '@isInFiscalPrinterLocalization' === '@Boolean.TrueString'
            initializeCashRegisterCashRegister(isInFiscalCashRegister,
                {
                    invoicePayment: '@Loc.InvoicePayment',
                    value: '@Loc.Value',
                    depositInput: '@Loc.DepositInput',
                    depositOutput: '@Loc.DepositOutput',
                    currency: '@Model.Currency',
                    noResults: '@Loc.NoResults',
                    name: '@Loc.Name',
                    ident: '@Loc.Ident',
                    price: '@Loc.Price',
                    stock: '@Loc.Stock',
                    pfrConnectionSuccessful: '@Loc.CommunicationWithPfrSuccessful',
                    lpfrConnectionSuccessful: '@Loc.PinCorrectCommunicationWithLpfrSuccessful',
                    lpfrConnectionFailed: '@Loc.ErrorCommunicationWithPfr',
                    fiscalSalesBookError: '@Loc.FiscalSalesBookError'
                },
                '@string.IsNullOrEmpty(Model.PinUrlLPFR)' === '@Boolean.FalseString',
                {
                    lpfrLocalization: {
                        2100: '@Loc.lpfrError2100',
                        2110: '@Loc.lpfrError2110',
                        1300: '@Loc.lpfrError1300',
                        2220: '@Loc.lpfrError2220',
                        2400: '@Loc.lpfrError2400',
                        communicationModalTitle: '@Loc.CommunicationWithLpfr',
                        communicationModalErrorMessage: '@Loc.ErrorCommunicationWithLpfr',
                        communicationButtonTitle: '@Loc.ErrorCommunicationWithLpfr',
                        communicationButtonActionText: '@Loc.ClickToCorrectAction',
                        manualButtonTitle: '@Loc.LpfrCommunicationInstruction',
                        manualButtonActionText: '@Loc.LpfrCommunicationErrorInstruction',
                        lpfrCommunicationHelp: '@SiteHelpAttributeHelper.GetHelpUrl(PantheonRA.BackOffice.Enums.HelpIds.LpfrCommunicationError)'
                    }
                }
            );
        });
    </script>
}
