@model PantheonRA.BackOffice.Models.DocTypeCreateViewModel
@using PantheonRA.BackOffice.Models
@using PantheonRA.BackOffice.Enums
@using PantheonRA.WebApi.Contracts.Enums
@using PAW.Contracts.Enums;
@{
    ViewBag.Title = Model.IsEdit ? Loc.CreateNewDocumentType : Loc.EditDocumentType;
    var isInFiscalPrinterLocalization = Localization.IsInFiscalPrinterLocalization(PantheonRA.BackOffice.CurrentUser.DatabaseLocalization, PantheonRA.BackOffice.CurrentUser.IsInServerFiscalization);
    bool isTravelOrder = Model.IsTravelOrder;
    bool showArchive = Model.ShowArchive;
    var showOnTO = isTravelOrder ? string.Empty : "hidden";
    var hideOnTO = !isTravelOrder ? string.Empty : "hidden";
    var newExpenseRowNum = -1;
}

@Html.Hidden("PreSelectedSerialNumbers", Model.SelectedSerialNumbers != null ? string.Join(",", Model.SelectedSerialNumbers) : null)
@Html.Hidden("LocName", Loc.Name)
@Html.Hidden("LocNoResults", Loc.NoResults)
@Html.Hidden("UrlFindCommodityPackages", Url.Action("FindCommodityPackages", "DocumentType"))

<div class="tabs-container">
    @Html.Partial("~/Views/Company/_CompanySettingsTabNavigation.cshtml")
    <div class="tab-content">
        <form id="mainForm" method="post">
            @Html.HiddenFor(model => model.MachineName)
            @Html.HiddenFor(model => model.SetOf)
            @Html.HiddenFor(model => model.ShowFiscalizeOptions)
            @Html.HiddenFor(model => model.IsTravelOrder, isTravelOrder)
            @Html.HiddenFor(model => model.IsWorkPlaceClosed)
            <div class="row buttons-tabbed">
                @Html.Partial("_FormButtons", new FormButtonsViewModel
                {
                    BackUrl = Url.Action("Index", "DocumentType"),
                    SaveButtonGroup = new FormButtonGroup
                    {
                        Buttons = new List<FormButton>
                        {
                            new FormButton { Text = Loc.Save, Icon = "fa fa-save fa-lg", IsSubmit = false }
                        }
                    }
                })

                <button id="invoiceDelete" type="button" onclick="checkRemoveDocType()" title="@Loc.Delete"
                        class="btn btn-danger btn-outline pull-right collapsable-form-button @(Model.IsEdit ? string.Empty : " hidden")">
                    <i class="far fa-trash-alt m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.Delete</span>
                </button>

                <a title="@Loc.New" id="newDocTypeButton" onclick="createNewDocType()"
                   class="btn btn-primary btn-outline pull-right collapsable-form-button @(string.IsNullOrEmpty(Model.Id) ? " hidden" : string.Empty)"
                   data-dtp="Write">
                    <i class="fas fa-plus m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.New</span>
                </a>
            </div>

            <div class="divided-content clearfix">
                <div class="divided-content-main divided-content-full">
                    <div class="row document-head margin-b-none">
                        <div class="prev-next-key-display doctype-prev-next-display bg-grey">
                            <div class="inline m-l-md">
                                <i id="nav-chev-left" class="fa fa-chevron-left @(Model.TypeOfDocument != null && Model.TypeOfDocument != TypeOfDocument.POS ? "" : "hidden")" onclick="prevNavNeighbour(this)"></i>
                            </div>
                            <div class="inline input-s-lg m-l-sm m-r-sm">
                                @Html.HiddenFor(model => model.Type)
                                @Html.HiddenFor(model => model.TypeOfDocument)
                                <select id="TypeOfDocumentSelect" value="@Model.TypeOfDocument" class="form-control custom-select" @(Model.IsEdit == true ? "disabled" : "")>
                                    <option value="" @(Model.TypeOfDocument == null ? "selected" : "")>@Loc.Select</option>
                                    <option value="@TypeOfDocument.POS" data-type="@DocumentTypeAcType.Retail" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.POS ? "selected" : "")>@Loc.Retail</option>
                                    <option value="@TypeOfDocument.Wholesale" data-type="@DocumentTypeAcType.Wholesale" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.Wholesale ? "selected" : "")>@Loc.Wholesale</option>
                                    <option value="@TypeOfDocument.ReceivedBills" data-type="@DocumentTypeAcType.Supply" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.ReceivedBills ? "selected" : "")>@Loc.Receive</option>
                                    <option value="@TypeOfDocument.IssuedAdvancePayment" data-type="@DocumentTypeAcType.Supply" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.IssuedAdvancePayment ? "selected" : "")>@Loc.IssuedAdvancePayments</option>
                                    <option value="@TypeOfDocument.ReceivingAdvancePayment" data-type="@DocumentTypeAcType.Wholesale" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.ReceivingAdvancePayment ? "selected" : "")>@Loc.ReceivedAdvancePayments</option>
                                    <option value="@TypeOfDocument.Transfer" data-type="@DocumentTypeAcType.Transfer" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.Transfer ? "selected" : "")>@Loc.Transfer</option>
                                    <option value="@TypeOfDocument.PriceChange" data-type="@DocumentTypeAcType.PriceChange" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.PriceChange ? "selected" : "")>@Loc.PriceChange</option>
                                    <option value="@TypeOfDocument.Inventory" data-type="@DocumentTypeAcType.Inventory" data-setOf="F" @(Model.TypeOfDocument == TypeOfDocument.Inventory ? "selected" : "")>@Loc.InventoryCount</option>
                                    <option value="@TypeOfDocument.BuyerOrder" data-type="@DocumentTypeAcType.Supply" data-setOf="N" @(Model.TypeOfDocument == TypeOfDocument.BuyerOrder ? "selected" : "")>@Loc.OrderBuyer</option>
                                    <option value="@TypeOfDocument.SupplierOrder" data-type="@DocumentTypeAcType.Wholesale" data-setOf="N" @(Model.TypeOfDocument == TypeOfDocument.SupplierOrder ? "selected" : "")>@Loc.OrdersSupplier</option>
                                    <option value="@TypeOfDocument.TravelOrder" data-type="@DocumentTypeAcType.Supply" data-setOf="S" @(Model.TypeOfDocument == TypeOfDocument.TravelOrder ? "selected" : "")>@Loc.TravelOrders</option>
                                    <option value="@TypeOfDocument.PayOrder" data-type="@DocumentTypeAcType.Supply" data-setOf="L" @(Model.TypeOfDocument == TypeOfDocument.PayOrder ? "selected" : "")>@Loc.PayOrders</option>
                                    <option value="@TypeOfDocument.CashTransaction" data-type="@DocumentTypeAcType.Supply" data-setOf="B" @(Model.TypeOfDocument == TypeOfDocument.CashTransaction ? "selected" : "")>@Loc.CashTransactions</option>
                                    <option value="@TypeOfDocument.Wage" data-type="@DocumentTypeAcType.Supply" data-setOf="B" @(Model.TypeOfDocument == TypeOfDocument.Wage ? "selected" : "")>@Loc.DocTypeTreeWages</option>
                                    <option value="@TypeOfDocument.WorkOrder" data-type="@DocumentTypeAcType.Supply" data-setOf="B" @(Model.TypeOfDocument == TypeOfDocument.WorkOrder ? "selected" : "")>@Loc.DocTypeTreeWorkOrders</option>
                                    <option value="@TypeOfDocument.Archive" data-type="@DocumentTypeAcType.Retail" data-setOf="Y" @(Model.TypeOfDocument == TypeOfDocument.Archive ? "selected" : "")>@Loc.Archive</option>
                                </select>
                            </div>
                            <div class="inline">
                                <i id="nav-chev-right" class="fa fa-chevron-right @(Model.TypeOfDocument != TypeOfDocument.Archive ? "" : "hidden")" onclick="nextNavNeighbour(this)"></i>
                            </div>
                        </div>
                    </div>
                    <div class="form-horizontal form-md row">
                        <div class="col-sm-6 col-lg-6 column-full-height-border-right">
                            <h3 class="m-b-md m-t-md">@Loc.BasicData</h3>
                            @Html.HiddenFor(model => model.IsEdit)
                            @Html.HiddenFor(model => model.AnQid)
                            <div class="form-group">
                                @Html.LabelFor(model => model.Id, Loc.Code, new { @class = "col-md-3 control-label" })
                                <div class="col-md-9">
                                    @Html.HiddenFor(model => model.Id)
                                    @if (Model.IsEdit)
                                    {
                                        @Html.TextBoxFor(model => model.IdView, new { @id = "IdView", @class = "form-control", @readonly = "readonly", maxlength = Model.IdLength })
                                    }
                                    else
                                    {
                                        @Html.TextBoxFor(model => model.IdView, new { @id = "IdView", @class = "form-control", maxlength = Model.IdLength })
                                    }
                                    @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger", @id = "Id-validation" })
                                </div>
                            </div>

                            <div class="form-group">
                                @Html.LabelFor(model => model.ShortName, Loc.ShortName, new { @class = "col-md-3 control-label" })
                                <div class="col-md-9">
                                    @Html.TextBoxFor(model => model.ShortName, new { @class = "form-control", autocomplete = "off", maxlength = 13 })
                                    @Html.ValidationMessageFor(model => model.ShortName, "", new { @class = "text-danger", @id = "ShortName-validation" })
                                </div>
                            </div>

                            <div class="form-group">
                                @Html.LabelFor(model => model.Name, Loc.Name, new { @class = "col-md-3 control-label" })
                                <div class="col-md-9">
                                    @Html.TextBoxFor(model => model.Name, new { @class = "form-control", autocomplete = "off" })
                                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger", @id = "Name-validation" })
                                </div>
                            </div>

                            <div class="form-group">
                                @Html.LabelFor(model => model.Evidence, Loc.Evidence, new { @class = "col-md-3" })
                                <div class="col-md-9">
                                    @Html.CheckBoxFor(model => model.Evidence, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    @Html.ValidationMessageFor(model => model.Evidence, "", new { @class = "text-danger block", @id = "Evidence-validation" })
                                </div>
                            </div>

                            @if (Model.SetOf == "N" || Model.TypeOfDocument == TypeOfDocument.BuyerOrder || Model.TypeOfDocument == TypeOfDocument.SupplierOrder)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Receiver, (Model.Type == "P" ? Loc.Buyer : Loc.Recipient), new { @class = "col-md-3 control-label" })
                                    <div class="col-md-5">
                                        <select id="Receiver"
                                                name="Receiver"
                                                class="form-control select2withAPI"
                                                data-placeholder="@(Model.Type == "P" ? Loc.Buyer : Loc.Recipient)"
                                                data-column-names="@Loc.Company,@Loc.Name,@Loc.Address,@Loc.Post"
                                                data-bootstrap-columns="col-md-4,col-md-3,col-md-3,col-md-2"
                                                data-search-width="450"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("SubjectDropdownValues", "Subjects")>
                                            <option selected value="@Model.Receiver">@Model.Receiver</option>
                                        </select>
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.IsObligReceiver, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.ReceiverName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.ReceiverName, "", new { @class = "text-danger", @id = "ReceiverName-validation" })
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Issuer, Loc.Warehouse, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-9">
                                        @Html.DropDownListFor(model => model.Issuer, new SelectList(ViewBag.Warehouses, "Id", "Name"), "", new { @class = "form-control custom-select" })
                                    </div>
                                </div>
                            }
                            else if ((Model.SetOf == "F" && Model.Type == "P") || Model.TypeOfDocument == TypeOfDocument.ReceivedBills)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Receiver, Loc.Recipient, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-6">
                                        @Html.DropDownListFor(model => model.Receiver, new SelectList(ViewBag.Warehouses, "Id", "Name"), "", new { @class = "form-control custom-select" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.ReceiverName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.ReceiverName, "", new { @class = "text-danger", @id = "ReceiverName-validation" })
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Issuer, Loc.Issuer, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-5">
                                        <select id="Issuer"
                                                name="Issuer"
                                                class="form-control select2withAPI"
                                                data-placeholder="@Loc.Issuer"
                                                data-column-names="@Loc.Company,@Loc.Name,@Loc.Address,@Loc.Post"
                                                data-bootstrap-columns="col-md-4,col-md-3,col-md-3,col-md-2"
                                                data-search-width="450"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("SubjectDropdownValues", "Subjects")>
                                            <option selected value="@Model.Issuer">@Model.Issuer</option>
                                        </select>
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.IsObligIssuer, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.IssuerName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.IssuerName, "", new { @class = "text-danger", @id = "IssuerName-validation" })
                                    </div>
                                </div>
                            }
                            else if ((Model.SetOf == "F" && (Model.Type == "I" || Model.Type == "M")) || Model.TypeOfDocument == TypeOfDocument.Wholesale || Model.TypeOfDocument == TypeOfDocument.POS)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Issuer, Loc.Issuer, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-6">
                                        @Html.DropDownListFor(model => model.Issuer, new SelectList(ViewBag.Warehouses, "Id", "Name"), "", new { @class = "form-control custom-select" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.IssuerName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.IssuerName, "", new { @class = "text-danger", @id = "IssuerName-validation" })
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Receiver, Loc.Recipient, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-5">
                                        <select id="Receiver"
                                                name="Receiver"
                                                class="form-control select2withAPI"
                                                data-placeholder="@Loc.Buyer"
                                                data-column-names="@Loc.Company,@Loc.Name,@Loc.Address,@Loc.Post"
                                                data-bootstrap-columns="col-md-4,col-md-3,col-md-3,col-md-2"
                                                data-search-width="450"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("SubjectDropdownValues", "Subjects")>
                                            <option selected value="@Model.Receiver">@Model.Receiver</option>
                                        </select>
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.IsObligReceiver, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.ReceiverName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.ReceiverName, "", new { @class = "text-danger", @id = "ReceiverName-validation" })
                                    </div>
                                </div>
                            }
                            else if ((Model.SetOf == "F" && Model.Type == "E") || Model.TypeOfDocument == TypeOfDocument.Transfer)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Issuer, Loc.Issuer, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-6">
                                        @Html.DropDownListFor(model => model.Issuer, new SelectList(ViewBag.Warehouses, "Id", "Name"), "", new { @class = "form-control custom-select" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.IssuerName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.IssuerName, "", new { @class = "text-danger", @id = "IssuerName-validation" })
                                    </div>
                                </div>
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Receiver, Loc.Recipient, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-6">
                                        @Html.DropDownListFor(model => model.Receiver, new SelectList(ViewBag.Warehouses, "Id", "Name"), "", new { @class = "form-control custom-select" })
                                    </div>
                                    <div class="col-md-3">
                                        @Html.TextBoxFor(model => model.ReceiverName, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.ReceiverName, "", new { @class = "text-danger", @id = "ReceiverName-validation" })
                                    </div>
                                </div>
                            }

                            @if (showArchive)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Archive, Loc.Archive, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-9">
                                        <select id="Archive"
                                                name="Archive"
                                                class="form-control select2withAPI"
                                                data-placeholder="@Loc.Archive"
                                                data-column-names="@Loc.DocType, @Loc.Name"
                                                data-bootstrap-columns="col-md-6, col-md-6"
                                                data-search-width="450"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("DocumentTypeDropDownValues", "DocumentType", new { setOf = "Y", type = "M" })>
                                            <option selected value="@Model.Archive">@Model.ArchiveFullName</option>
                                        </select>
                                    </div>
                                </div>
                            }

                            <div class="form-group">
                                @Html.LabelFor(model => model.Classification, Loc.Classification, new { @class = "col-md-3 control-label" })
                                <div class="col-md-9">
                                    <select id="Classification"
                                            name="Classification"
                                            class="form-control select2withAPI"
                                            data-placeholder="@Loc.Classification"
                                            data-column-names="@Loc.Description,@Loc.Code"
                                            data-bootstrap-columns="col-md-10, col-md-2"
                                            data-search-width="450"
                                            data-allow-clear="true"
                                            data-url=@Url.Action("ClassificationDropdownValues", "Classification")>
                                        <option selected value="@Model.Classification">@Model.ClassificationFullName</option>
                                    </select>
                                </div>
                            </div>

                            @if (isTravelOrder)
                            {
                                <div class="form-group">
                                    <label class="col-md-3 control-label">@Loc.TravelPurpose</label>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.PrintOpt, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                    <div class="col-md-8">
                                        @Html.TextAreaFor(model => model.Name2, new { @class = "form-control", rows = 3, maxlength = 40 })
                                    </div>
                                </div>

                                <div class="form-group">
                                    @Html.LabelFor(model => model.Receiver, Loc.Payer, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-9">
                                        <select id="Receiver"
                                                name="Receiver"
                                                class="form-control select2withAPI"
                                                data-placeholder="@Loc.Payer"
                                                data-column-names="@Loc.Company,@Loc.Name,@Loc.Address,@Loc.Post"
                                                data-bootstrap-columns="col-md-4,col-md-3,col-md-3,col-md-2"
                                                data-search-width="450"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("SubjectDropdownValues", "Subjects")>
                                            <option selected value="@Model.Receiver">@Model.Receiver</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    @Html.LabelFor(model => model.Department, Loc.Department, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-8">
                                        <select id="Department"
                                                name="Department"
                                                class="form-control select2withAPI"
                                                data-placeholder="@Loc.Department"
                                                data-search-width="350"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("GetDepartments", "Employees")>
                                            <option selected value="@Model.Department">@Model.Department</option>
                                        </select>
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.ISObligDept, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                </div>

                                <div class="form-group">
                                    @Html.LabelFor(model => model.IsObligCostDrv, Loc.CostCarrierFull, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-9">
                                        @Html.CheckBoxFor(model => model.IsObligCostDrv, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                </div>
                            }
                            else if ((Model.SetOf == "F" && (Model.Type == "I" || Model.Type == "P" || Model.Type == "M")) || Model.SetOf == "N")
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Department, Loc.Department, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-8">
                                        <select id="Department"
                                                name="Department"
                                                class="form-control select2withAPI"
                                                data-placeholder="@Loc.Department"
                                                data-search-width="350"
                                                data-allow-clear="true"
                                                data-url=@Url.Action("GetDepartments", "Employees")>
                                            <option selected value="@Model.Department">@Model.Department</option>
                                        </select>
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.ISObligDept, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                </div>
                            }

                            @if (Model.TypeOfDocument != TypeOfDocument.POS && Model.TypeOfDocument != TypeOfDocument.Archive
                                && Model.TypeOfDocument != TypeOfDocument.TravelOrder && Model.TypeOfDocument != TypeOfDocument.PayOrder
                                && Model.TypeOfDocument != TypeOfDocument.CashTransaction && Model.TypeOfDocument != TypeOfDocument.Wage
                                && Model.TypeOfDocument != TypeOfDocument.WorkOrder)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.LinkDocName1, Loc.DocumentOne, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-8">
                                        @Html.TextBoxFor(model => model.LinkDocName1, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.LinkDocName1, "", new { @class = "text-danger", @id = "LinkDocName1-validation" })
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.IsObligDoc1, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                </div>

                                <div class="form-group">
                                    @Html.LabelFor(model => model.LinkDocName2, Loc.DocumentTwo, new { @class = "col-md-3 control-label" })
                                    <div class="col-md-8">
                                        @Html.TextBoxFor(model => model.LinkDocName2, new { @class = "form-control", autocomplete = "off" })
                                        @Html.ValidationMessageFor(model => model.LinkDocName2, "", new { @class = "text-danger", @id = "LinkDocName2-validation" })
                                    </div>
                                    <div class="col-md-1 m-t-sm">
                                        @Html.CheckBoxFor(model => model.IsObligDoc2, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                </div>
                            }
                            @if (Model.TypeOfDocument == TypeOfDocument.ReceivedBills || Model.TypeOfDocument == TypeOfDocument.Wholesale
                                || Model.TypeOfDocument == TypeOfDocument.BuyerOrder || Model.TypeOfDocument == TypeOfDocument.SupplierOrder
                                || Model.TypeOfDocument == TypeOfDocument.IssuedAdvancePayment || Model.TypeOfDocument == TypeOfDocument.ReceivingAdvancePayment)
                            {
                                <div class="form-group">
                                    @Html.LabelFor(model => model.CheckLinkDoc, Loc.SeparateLinksControl, new { @class = "col-md-3" })
                                    <div class="col-md-9">
                                        @Html.CheckBoxFor(model => model.CheckLinkDoc, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                    </div>
                                </div>
                            }

                            @if (!(Model.SetOf == "Y" && Model.Type == "M"))
                            {
                                if (Model.ShowEInvoiceExportType == true)
                                {
                                    if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.RS)
                                    {
                                        <div class="form-group" id="acEInvoiceExportTypeContainer">
                                            @Html.LabelFor(model => model.EInvoiceExportType2, Loc.ExportTypeEDocument, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.DropDownListFor(model => model.EInvoiceExportType2, new List<SelectListItem> {
                                                    new SelectListItem{ Text = "0 - " + Loc.GeneralDocument, Value = "0"},
                                                    new SelectListItem{ Text = "4 - " + Loc.WarningType, Value = "4"},
                                                    new SelectListItem{ Text = "7 - " + Loc.AnswerConsentOrRefusal, Value = "7"},
                                                    new SelectListItem{ Text = "105 - " + Loc.OrderFormExportType, Value = "105"},
                                                    new SelectListItem{ Text = "226 - " + Loc.OrderRevocation, Value = "226"},
                                                    new SelectListItem{ Text = "230 - " + Loc.OrderChange, Value = "230"},
                                                    new SelectListItem{ Text = "231 - " + Loc.OrderResponse, Value = "231"},
                                                    new SelectListItem{ Text = "325 - " + Loc.OrderBuyer, Value = "325"},
                                                    new SelectListItem{ Text = "326 - " + Loc.PartialAccount, Value = "326"},
                                                    new SelectListItem{ Text = "351 - " + Loc.OrderForm, Value = "351"},
                                                    new SelectListItem{ Text = "380 - " + Loc.CommercialFinalAccount, Value = "380"},
                                                    new SelectListItem{ Text = "381 - " + Loc.Approval, Value = "381"},
                                                    new SelectListItem{ Text = "383 - " + Loc.Indebtedness, Value = "383"},
                                                    new SelectListItem{ Text = "384 - " + Loc.CorrectiveAccount, Value = "384"},
                                                    new SelectListItem{ Text = "386 - " + Loc.AdvancePaymentInvoice, Value = "386"},
                                                    new SelectListItem{ Text = "394 - " + Loc.LeasingAccount, Value = "394"},
                                                    new SelectListItem{ Text = "632 - " + Loc.ReceiptType, Value = "632"},
                                                }, "", new { @class = "form-control custom-select" })
                                            </div>
                                        </div>
                                    }
                                    else if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.SI)
                                    {
                                        <div class="form-group" id="acEInvoiceExportTypeContainer">
                                            @Html.LabelFor(model => model.DocTypeESLOG, Loc.ESlogAccountType, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.DropDownListFor(model => model.DocTypeESLOG, new List<SelectListItem> {
                                                    new SelectListItem{ Text = "82 - " + Loc.EInvoiceType82, Value = "82" },
                                                    new SelectListItem{ Text = "83 - " + Loc.EInvoiceType83, Value = "83"},
                                                    new SelectListItem{ Text = "84 - " + Loc.EInvoiceType84, Value = "84"},
                                                    new SelectListItem{ Text = "130 - " + Loc.EInvoiceType130, Value = "130"},
                                                    new SelectListItem{ Text = "325 - " + Loc.EInvoiceType325, Value = "325"},
                                                    new SelectListItem{ Text = "380 - " + Loc.EInvoiceType380, Value = "380"},
                                                    new SelectListItem{ Text = "381 - " + Loc.EInvoiceType381, Value = "381"},
                                                    new SelectListItem{ Text = "382 - " + Loc.EInvoiceType382, Value = "382"},
                                                    new SelectListItem{ Text = "383 - " + Loc.EInvoiceType383, Value = "383"},
                                                    new SelectListItem{ Text = "384 - " + Loc.EInvoiceType384, Value = "384"},
                                                    new SelectListItem{ Text = "385 - " + Loc.EInvoiceType385, Value = "385"},
                                                    new SelectListItem{ Text = "386 - " + Loc.EInvoiceType386, Value = "386"},
                                                    new SelectListItem{ Text = "387 - " + Loc.EInvoiceType387, Value = "387"},
                                                    new SelectListItem{ Text = "389 - " + Loc.EInvoiceType389, Value = "389"},
                                                    new SelectListItem{ Text = "38P - " + Loc.EInvoiceType38P, Value = "38P"},
                                                    new SelectListItem{ Text = "390 - " + Loc.EInvoiceType390, Value = "390"},
                                                    new SelectListItem{ Text = "393 - " + Loc.EInvoiceType393, Value = "393"},
                                                }, "", new { @class = "form-control custom-select" })
                                            </div>
                                        </div>
                                    }
                                    else if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.HR)
                                    {
                                        <div class="form-group" id="acEInvoiceExportTypeContainer">
                                            @Html.LabelFor(model => model.EInvoiceExportType, Loc.EInvoiceExportType, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.DropDownListFor(model => model.EInvoiceExportType, new List<SelectListItem> {
                                                    new SelectListItem{ Text = Loc.Invoice, Value = "" },
                                                    new SelectListItem{ Text = Loc.CreditNotification, Value = "C"},
                                                    new SelectListItem{ Text = Loc.Charge, Value = "D"},
                                                    new SelectListItem{ Text = Loc.AdvancePaymentInvoice, Value = "B"},
                                                }, null, new { @class = "form-control custom-select" })
                                            </div>
                                        </div>
                                    }
                                }

                                if (isTravelOrder)
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.Worker, Loc.EmployeeTR, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            <select id="Worker"
                                                    name="Worker"
                                                    class="form-control select2withAPI"
                                                    data-placeholder="@Loc.EmployeeTR"
                                                    data-column-names="@Loc.Code,@Loc.LastName,@Loc.FirstName,@Loc.Job,@Loc.Department"
                                                    data-bootstrap-columns="col-md-3,col-md-2,col-md-2,col-md-2,col-md-3"
                                                    data-search-width="700"
                                                    data-allow-clear="true"
                                                    data-url=@Url.Action("EmployeeDropDownValues", "Employees")>
                                                <option selected value="@Model.Worker">@Model.Worker</option>
                                            </select>
                                        </div>
                                    </div>
                                }

                                if (Model.IsEdit
                                    && !isTravelOrder
                                    && PantheonRA.BackOffice.CurrentUser.DatabaseLocalization != Localization.Code.SI)
                                {
                                    <div class="form-group" id="printSettings">
                                        <label class="col-md-3">@Loc.PrintSettings</label>
                                        <div class="col-md-9">
                                            @if (isInFiscalPrinterLocalization)
                                            {
                                                <div>
                                                    <span>@Loc.InvoicePrint</span>
                                                    @Html.DropDownListFor(model => model.DefaultFiscalDevice,
                                                     new SelectList(ViewBag.FiscalDevices, "AnQid", "AcDeviceName"), "- " + Loc.Select + " -",
                                                     new { @class = "form-control custom-select auto-width m-l-sm", disabled = "disabled" })
                                                </div>
                                            }
                                            else
                                            {
                                                <select id="DefaultReport" name="DefaultReport" class="form-control custom-select">
                                                    @foreach (var item in ViewBag.ReportPrintOptions)
                                                    {
                                                        <option value="@item.Report" @(Model.DefaultReport == item.Report ? "selected" : string.Empty)>
                                                            @(item.Report) - @(item.Name)
                                                        </option>
                                                    }
                                                </select>
                                            }
                                        </div>
                                    </div>
                                }

                                if (!isTravelOrder)
                                {
                                    if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.RS)
                                    {
                                        <div class="form-group fiscalData @(Model.CanFiscalize == false ? "hidden" : "")">
                                            @Html.LabelFor(model => model.Note, Loc.Note, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.TextAreaFor(model => model.Note, new { @class = "form-control", rows = 3, autocomplete = "off" })
                                            </div>
                                        </div>
                                    }

                                    <div class="form-group">
                                        <label class="col-md-3 control-label">@Loc.DefaultNote</label>
                                        <div class="col-md-9">
                                            @Html.TextAreaFor(model => model.DefaultNote, new { @class = "form-control", rows = 3 })
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        @Html.LabelFor(model => model.PayMethod, Loc.DefaultPaymentMethod, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            <select id="PayMethod" name="PayMethod" class="form-control custom-select">
                                                <option></option>
                                                @foreach (var item in ViewBag.PaymentMethods)
                                                {
                                                    <option value="@item.PaymentMethod" @(Model.PayMethod == item.PaymentMethod ? "selected" : string.Empty)>
                                                        @(item.PaymentMethod) - @(string.IsNullOrEmpty(item.FiscalGroup) ? item.Name : item.FiscalGroup + " - " + item.Name)
                                                    </option>
                                                }
                                            </select>
                                            @Html.ValidationMessageFor(model => model.PayMethod, "", new { @class = "text-danger", @id = "PayMethod-validation" })
                                        </div>
                                    </div>

                                    <div class="form-group pos-settings">
                                        @Html.LabelFor(model => model.PayMethodRefund, Loc.DefaultPaymentMethodRefund, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            <select id="PayMethodRefund" name="PayMethodRefund" class="form-control custom-select">
                                                <option value=" "></option>
                                                @foreach (var item in ViewBag.PaymentMethods)
                                                {
                                                    <option value="@item.PaymentMethod" @(Model.PayMethodRefund == item.PaymentMethod ? "selected" : string.Empty)>
                                                        @(item.PaymentMethod) - @(string.IsNullOrEmpty(item.FiscalGroup) ? item.Name : item.FiscalGroup + " - " + item.Name)
                                                    </option>
                                                }
                                            </select>
                                            @Html.ValidationMessageFor(model => model.PayMethodRefund, "", new { @class = "text-danger", @id = "PayMethodRefund-validation" })
                                        </div>
                                    </div>

                                    <div class="form-group" id="allowZeroTotalContainer">
                                        @Html.LabelFor(model => model.Evidence, Loc.AllowZeroSumDocument, new { @class = "col-md-3" })
                                        <div class="col-md-9">
                                            @Html.CheckBoxFor(model => model.AllowZeroTotal, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                            @Html.ValidationMessageFor(model => model.AllowZeroTotal, "", new { @class = "text-danger block", @id = "AllowZeroTotal-validation" })
                                        </div>
                                    </div>

                                    if (Model.SetOf == "N")
                                    {
                                        <div class="form-group" style="margin-bottom: 30px">
                                            <label class="col-md-3 control-label">@Loc.EnterSerialNumber</label>
                                            <div class="col-md-9">
                                                @Html.DropDownListFor(model => model.SelectedSerialNumbers,
                                                     new SelectList(Model.SerialNumbers, "Id", "Name", Model.SelectedSerialNumbers),
                                                     HtmlAttributesHelper.CreateInputAttributes("form-control selectpicker",
                                                         "SelectedSerialNumbers", false, Loc.ProductMenuSerialNoTitle, true, new { @multiple = "multiple", data_live_search = "true", @title = Loc.ProductMenuSerialNoTitle }))
                                                @Html.ValidationMessageFor(model => model.SelectedSerialNumbers, "", new { @class = "text-danger", @id = "SelectedSerialNumbers-validation" })
                                            </div>
                                        </div>
                                    }

                                    if (Model.TypeOfDocument != TypeOfDocument.Archive && Model.TypeOfDocument != TypeOfDocument.CashTransaction
                                        && Model.TypeOfDocument != TypeOfDocument.TravelOrder && Model.TypeOfDocument != TypeOfDocument.PayOrder
                                        && Model.TypeOfDocument != TypeOfDocument.Wage && Model.TypeOfDocument != TypeOfDocument.WorkOrder
                                        && Model.TypeOfDocument != TypeOfDocument.BuyerOrder && Model.TypeOfDocument != TypeOfDocument.SupplierOrder)
                                    {
                                        <div class="form-group" id="checkPositionPriceQtyContainer">
                                            @Html.LabelFor(model => model.CheckPositionPriceQty, Loc.CheckPositionPriceAndQuantity, new { @class = "col-md-3" })
                                            <div class="col-md-9">
                                                @Html.CheckBoxFor(model => model.CheckPositionPriceQty, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.CheckPositionPriceQty, "", new { @class = "text-danger block", @id = "CheckPositionPriceQty-validation" })
                                            </div>
                                        </div>
                                    }
                                    if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.HR && (Model.Id == "8100" || Model.Id == "8010"))
                                    {
                                        <div class="form-group" id="checkCashRegIsTip">
                                            @Html.LabelFor(model => model.IsCashRegisTip, Loc.CashRegIsTip, new { @class = "col-md-3" })
                                            <div class="col-md-9">
                                                @Html.CheckBoxFor(model => model.IsCashRegisTip, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.IsCashRegisTip, "", new { @class = "text-danger block", @id = "IsCashRegisTip-validation" })
                                            </div>
                                        </div>
                                    }

                                    if (Model.SetOf == "N" && Model.Type == "P")
                                    {
                                        <div class="form-group" id="orderCalendarContainer">
                                            @Html.LabelFor(model => model.IsOrderCalendar, Loc.OrderCalendarLabel, new { @class = "col-md-3" })
                                            <div class="col-md-9">
                                                @Html.CheckBoxFor(model => model.IsOrderCalendar, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.IsOrderCalendar, "", new { @class = "text-danger block", @id = "IsOrderCalendar-validation" })
                                            </div>
                                        </div>

                                        <div class="form-group @(!Model.IsOrderCalendar ? "hidden" : "")" id="DocTypeForPOS-container">
                                            @Html.LabelFor(model => model.DocTypeForPOS, Loc.DocTypeForPOS, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                <select id="DocTypeForPOS"
                                                        name="DocTypeForPOS"
                                                        class="form-control select2withAPI"
                                                        data-placeholder="@Loc.DocTypeForPOS"
                                                        data-column-names="@Loc.DocType, @Loc.Name"
                                                        data-bootstrap-columns="col-md-4, col-md-8"
                                                        data-search-width="450"
                                                        data-allow-clear="true"
                                                        data-url=@Url.Action("POSDocumentTypeDropdownValues", "DocumentType")>
                                                    <option selected value="@Model.DocTypeForPOS">@Model.DocTypeNameForPOS</option>
                                                </select>
                                            </div>
                                        </div>
                                    }

                                    if (Model.TypeOfDocument == TypeOfDocument.Wholesale || Model.TypeOfDocument == TypeOfDocument.ReceivedBills ||
                                        Model.TypeOfDocument == TypeOfDocument.SupplierOrder || Model.TypeOfDocument == TypeOfDocument.BuyerOrder)
                                    {
                                        <div class="form-group" id="orderCalendarContainer">
                                            @Html.LabelFor(model => model.CheckIdentDpl, Loc.EnterDuplicateIdentWarning, new { @class = "col-md-3" })
                                            <div class="col-md-9">
                                                @Html.CheckBoxFor(model => model.CheckIdentDpl, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.CheckIdentDpl, "", new { @class = "text-danger block", @id = "CheckIdentDpl-validation" })
                                            </div>
                                        </div>
                                    }

                                    if (Model.TypeOfDocument == TypeOfDocument.POS)
                                    {
                                        <div class="form-group">
                                            @Html.LabelFor(model => model.MaximumCashAmount, Loc.MaximumCashAmount, new { @class = "col-md-3" })
                                            <div class="col-md-9">
                                                @Html.HiddenFor(model => model.MaximumCashAmount)
                                                @Html.TextBox("MaximumCashAmountInput", Model.MaximumCashAmount, HtmlAttributesHelper.CreateInputAttributes(
                                                    "form-control numberInput"
                                                ))
                                                @Html.ValidationMessageFor(model => model.MaximumCashAmount, "", new { @class = "text-danger block", @id = "MaximumCashAmount-validation" })
                                            </div>
                                        </div>
                                    }
                                }

                                if (Model.TypeOfDocument != TypeOfDocument.POS && Model.TypeOfDocument != TypeOfDocument.Transfer
                                    && Model.TypeOfDocument != TypeOfDocument.PriceChange && Model.TypeOfDocument != TypeOfDocument.Inventory
                                    && Model.TypeOfDocument != TypeOfDocument.BuyerOrder && Model.TypeOfDocument != TypeOfDocument.SupplierOrder
                                    && Model.TypeOfDocument != TypeOfDocument.TravelOrder && Model.TypeOfDocument != TypeOfDocument.PayOrder
                                    && Model.TypeOfDocument != TypeOfDocument.CashTransaction && Model.TypeOfDocument != TypeOfDocument.Archive
                                    && Model.TypeOfDocument != TypeOfDocument.Wage && Model.TypeOfDocument != TypeOfDocument.WorkOrder)
                                {
                                    <div class="form-group">
                                        @Html.Label("ReceiveTypeDocLabel", Model.TypeOfDocument == TypeOfDocument.ReceivedBills ||
                                        Model.TypeOfDocument == TypeOfDocument.IssuedAdvancePayment ? Loc.Receive : Loc.Issue, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.DropDownList("TypeDoc", new List<SelectListItem> {
                                                new SelectListItem{ Text = Loc.Document, Value = TypeDoc.Document },
                                                new SelectListItem{ Text = Loc.Internal, Value = TypeDoc.Internal },
                                                new SelectListItem{ Text = Loc.ServiceBuyer, Value = TypeDoc.BuyerRMA },
                                                new SelectListItem{ Text = Loc.ServiceSupplier, Value = TypeDoc.SupplRMA },
                                            }, new { @class = "form-control custom-select" })
                                        </div>
                                    </div>
                                    if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.SI || PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.HR)
                                    {
                                        <div id="deferredStorageContainer" class="form-group hidden">
                                            @Html.LabelFor(model => model.ISReprieve, Loc.DeferredStorage, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.CheckBoxFor(model => model.ISReprieve, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                            </div>
                                        </div>
                                    }
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.TypeOfDoc, Loc.DocType, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.DropDownListFor(model => model.TypeOfDoc, new List<SelectListItem> {
                                                new SelectListItem{ Text = Loc.TypeMaterial, Value = TypeOfDoc.Material },
                                                new SelectListItem{ Text = Loc.TypeOfDocSummary, Value = TypeOfDoc.Summary },
                                                new SelectListItem{ Text = Loc.AdvancePayment, Value = TypeOfDoc.AdvancePayment },
                                                new SelectListItem{ Text = Loc.OwnConsumption, Value = TypeOfDoc.OwnConsumption }, // TODO: wholesale only
                                            }, new { @class = "form-control custom-select" })
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.FillPrice, Loc.FillPriceReceive, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.DropDownListFor(model => model.FillPrice, new List<SelectListItem> {
                                                new SelectListItem{ Text = Loc.EnterFillPrice, Value = FillPrice.EnterPrice },
                                                new SelectListItem{ Text = Loc.FillPriceFromCurrentWarehouse, Value = FillPrice.FromWarehouse },
                                                new SelectListItem{ Text = Loc.AutomaticFillPrice, Value = FillPrice.Automatic },
                                            }, new { @class = "form-control custom-select" })
                                        </div>
                                    </div>
                                    // TODO: FillPurPrice for receive only
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.FillPurPrice, Loc.FillPriceIdent, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.DropDownListFor(model => model.FillPurPrice, new List<SelectListItem> {
                                                new SelectListItem{ Text = Loc.FillPriceOnIdent, Value = FillPrice.PriceOnIdent },
                                                new SelectListItem{ Text = Loc.FillPriceCalcOnIdent, Value = FillPrice.CalcOnIdent },
                                                new SelectListItem{ Text = Loc.NoFillPrice, Value = FillPrice.None },
                                            }, new { @class = "form-control custom-select" })
                                        </div>
                                    </div>
                                }

                                if (Model.TypeOfDocument == TypeOfDocument.PriceChange)
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.FillPCDept, Loc.FillDepartment, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.DropDownListFor(model => model.FillPCDept, new List<SelectListItem> {
                                                new SelectListItem{ Text = Loc.DocumentSettings, Value = "S" },
                                                new SelectListItem{ Text = Loc.DocumentFromPriceChangeCreate, Value = "O" },
                                                new SelectListItem{ Text = Loc.DoesNotFill, Value = "N" },
                                            }, new { @class = "form-control custom-select" })
                                        </div>
                                    </div>
                                }

                                if (Model.TypeOfDocument == TypeOfDocument.Inventory)
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.DocTypeRef, Loc.InventoryShortage, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.TextBoxFor(model => model.DocTypeRef, new { @class = "form-control", autocomplete = "off" })
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.DocTypeWaste, Loc.InventoryExcess, new { @class = "col-md-3 control-label" })
                                        <div class="col-md-9">
                                            @Html.TextBoxFor(model => model.DocTypeWaste, new { @class = "form-control", autocomplete = "off" })
                                        </div>
                                    </div>
                                }
                            }

                            <div class="form-group">
                                <div class="col-md-offset-3 col-md-9">
                                    @Html.ValidationSummary(true)
                                </div>
                            </div>
                        </div>

                        @if (Model.ShowFiscalizeOptions == true && !PantheonRA.BackOffice.CurrentUser.IsDemo && !isTravelOrder && PantheonRA.BackOffice.CurrentUser.Localization != Localization.Code.EU)
                        {
                            <div class="col-sm-6 col-lg-4">
                                <h3 class="m-b-md m-t-md">@Loc.Fiscalization</h3>

                                @if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization != Localization.Code.RS || !PantheonRA.BackOffice.CurrentUser.IsInServerFiscalization)
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.CanFiscalize, Loc.FiscalizeInvoices, new { @class = "col-md-3" })
                                        <div class="col-md-9">
                                            @Html.CheckBoxFor(model => model.CanFiscalize, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                            @Html.ValidationMessageFor(model => model.CanFiscalize, "", new { @class = "text-danger block", @id = "CanFiscalize-validation" })
                                        </div>
                                    </div>
                                }
                                else
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.CanFiscalize, Loc.FiscalizeInvoices, new { @class = "col-md-3", title = Loc.FiscalizeInvoices })
                                        <div class="col-md-9">
                                            <input value="@Model.FiscalType" id="FiscalTypeSaved" hidden />
                                            @if ((Model.SetOf == "N" && (Model.Type == "I" || Model.Type == "P")) || (Model.SetOf == "F" && Model.TypeOfDoc == "A" && Model.Type == "I"))
                                            {
                                                @Html.DropDownListFor(model => model.FiscalType,
                                                    new SelectList(new List<dynamic> {
                                                        new { Value = PantheonRA.BackOffice.Enums.FiscalTypeRS.WithoutFiscalization, Text = Loc.WithoutFiscalization },
                                                        new { Value = PantheonRA.BackOffice.Enums.FiscalTypeRS.ProductionEnvironment, Text = Loc.ProductionEnvironment }
                                                    }, "Value", "Text"), "",
                                                    new { @class = "form-control custom-select" })
                                            }
                                            else
                                            {
                                                @Html.DropDownListFor(model => model.FiscalType,
                                                    new SelectList(new List<dynamic> {
                                                        new { Value = PantheonRA.BackOffice.Enums.FiscalTypeRS.WithoutFiscalization, Text = Loc.WithoutFiscalization },
                                                        new { Value = PantheonRA.BackOffice.Enums.FiscalTypeRS.TestEnvironment, Text = Loc.TestEnvironment },
                                                        new { Value = PantheonRA.BackOffice.Enums.FiscalTypeRS.ProductionEnvironment, Text = Loc.ProductionEnvironment }
                                                    }, "Value", "Text"), "",
                                                    new { @class = "form-control custom-select" })
                                            }
                                            @Html.ValidationMessageFor(model => model.FiscalType, "", new { @class = "text-danger", @id = "FiscalType-validation" })
                                        </div>
                                    </div>
                                }

                                @if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.HR)
                                {
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.FiscAll, Loc.FiscalizeAllDocuments, new { @class = "col-md-3" })
                                        <div class="col-md-9">
                                            @Html.CheckBoxFor(model => model.FiscAll, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                            @Html.ValidationMessageFor(model => model.FiscAll, "", new { @class = "text-danger block", @id = "FiscAll-validation" })
                                        </div>
                                    </div>
                                }

                                @if (!isInFiscalPrinterLocalization && PantheonRA.BackOffice.CurrentUser.DatabaseLocalization != Localization.Code.RS)
                                {
                                    <div id="fiscalData">
                                        <div class="form-group">
                                            @Html.LabelFor(model => model.FiscalWorkplaceId, Loc.CompanyUnit, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.DropDownListFor(model => model.FiscalWorkplaceId,
                                                  new SelectList(ViewBag.FiscalWorkPlaces, "Value", "Text"), "",
                                                  HtmlAttributesHelper.CreateInputAttributes(
                                                    @class: "form-control custom-select",
                                                    @id: "FiscalWorkplaceId",
                                                    @readonly: Model.IsWorkPlaceClosed == true,
                                                    @disabled: Model.IsWorkPlaceClosed == true,
                                                    @placeholder: Loc.CompanyUnit))
                                                @Html.ValidationMessageFor(model => model.FiscalWorkplaceId, "", new { @class = "text-danger", @id = "FiscalWorkplaceId-validation" })
                                            </div>
                                        </div>

                                        @if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization != Localization.Code.ME)
                                        {
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.FiscalDevice, Loc.DeviceTag, new { @class = "col-md-3 control-label" })
                                                <div class="col-md-9">
                                                    @Html.TextBoxFor(model => model.FiscalDevice,
                                                         new { @class = "form-control", autocomplete = "off", placeholder = Loc.DeviceTag })
                                                    @Html.ValidationMessageFor(model => model.FiscalDevice, "", new { @class = "text-danger", @id = "FiscalDevice-validation" })
                                                </div>
                                            </div>
                                        }
                                        @Html.HiddenFor(model => model.UseFiscalRounding)

                                        @if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization == Localization.Code.HR)
                                        {
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.DocTypeTipFiscalization, Loc.BPTipDocType, new { @class = "col-md-3" })
                                                <div class="col-md-9">
                                                    @Html.DropDownListFor(model => model.DocTypeTipFiscalization,
                                                        new SelectList(ViewBag.TipFiscalizationDocTypes != null ? ViewBag.TipFiscalizationDocTypes : new List<string>(), "Id", "Name"),
                                                        "", new { @class = "form-control custom-select" })
                                                    @Html.ValidationMessageFor(model => model.DocTypeTipFiscalization, "", new { @class = "text-danger block", @id = "DocTypeTipFiscalization-validation" })
                                                </div>
                                            </div>
                                        }
                                    </div>
                                }
                                else
                                {
                                    @Html.HiddenFor(model => model.FiscalWorkplaceId)
                                    @Html.HiddenFor(model => model.FiscalDevice)

                                    if (!PantheonRA.BackOffice.CurrentUser.IsInServerFiscalization)
                                    {
                                        <div id="fiscalData">
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.UseFiscalRounding, Loc.FiscalPrinterRounding, new { @class = "col-md-3" })
                                                <div class="col-md-9">
                                                    @Html.CheckBoxFor(model => model.UseFiscalRounding, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                                    @Html.ValidationMessageFor(model => model.UseFiscalRounding, "", new { @class = "text-danger block", @id = "UseFiscalRounding-validation" })
                                                </div>
                                            </div>
                                        </div>
                                    }
                                    else
                                    {
                                        @Html.HiddenFor(model => model.CanFiscalize)
                                        @Html.HiddenFor(model => model.FiscalType)
                                        @Html.HiddenFor(model => model.UseFiscalRounding)
                                        @Html.HiddenFor(model => model.FiscalDevice)
                                        @Html.HiddenFor(model => model.FiscalWorkplaceId)
                                    }

                                    if (!PantheonRA.BackOffice.CurrentUser.IsInServerFiscalization)
                                    {
                                        if (PantheonRA.BackOffice.CurrentUser.DatabaseLocalization != Localization.Code.MK)
                                        {
                                            <h3 class="m-b-md m-t-md">@Loc.Note</h3>
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.FiscalNote1, Loc.UnfiscalizedTextBeforeInvoice, new { @class = "col-md-3" })
                                                <div class="col-md-9">
                                                    @Html.TextAreaFor(model => model.FiscalNote1, new { @class = "form-control", autocomplete = "off", rows = "4" })
                                                    @Html.ValidationMessageFor(model => model.FiscalNote1, "", new { @class = "text-danger block", @id = "FiscalNote1-validation" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.FiscalNote2, Loc.UnfiscalizedTextAfterInvoice, new { @class = "col-md-3" })
                                                <div class="col-md-9">
                                                    @Html.TextAreaFor(model => model.FiscalNote2, new { @class = "form-control", autocomplete = "off", rows = "4" })
                                                    @Html.ValidationMessageFor(model => model.FiscalNote2, "", new { @class = "text-danger block", @id = "FiscalNote2-validation" })
                                                </div>
                                            </div>
                                        }
                                        else
                                        {
                                            @Html.HiddenFor(model => model.FiscalNote1)
                                            @Html.HiddenFor(model => model.FiscalNote2)
                                        }
                                    }
                                    else
                                    {
                                        @Html.HiddenFor(model => model.FiscalNote1)
                                        @Html.HiddenFor(model => model.FiscalNote2)

                                        <div class="form-group">
                                            <label class="col-md-3 control-label" title="@Loc.Links">@Loc.Links</label>
                                            <div class="col-md-9">
                                                <div class="input-group">
                                                    <input disabled class="form-control" value="@Model.FiscalServerByDoc" title="@Model.FiscalServerByDoc, @Model.FiscalTaxServerByDoc, @Model.FiscalCheckConnectionServerByDoc" autocomplete="off" onclick="$(this).closest('.input-group').find('button').trigger('click'); $(this).blur();" />
                                                    @Html.HiddenFor(model => model.FiscalServerByDoc)
                                                    @Html.HiddenFor(model => model.FiscalCheckConnectionServerByDoc)
                                                    @Html.HiddenFor(model => model.FiscalTaxServerByDoc)
                                                    <span class="input-group-addon">
                                                        <button type="button" class="btn btn-ghost btn-xs padding-bottom-none" onclick="openLPFRServerDataModal($('#FiscalServerByDoc'), $('#FiscalTaxServerByDoc'), $('#FiscalCheckConnectionServerByDoc'), '@Loc.Links', ['@Loc.TypeShort', '@Loc.Link'], ['@Loc.FiscalServer', '@Loc.TaxServer', '@Loc.CheckConnectionServer']);">
                                                            <i class="fas fa-pencil-alt"></i>
                                                        </button>
                                                    </span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            @Html.LabelFor(model => model.IsLPFREnabled, Loc.IsLPFR, new { @class = "col-md-3" })
                                            <div class="col-md-9">
                                                @Html.CheckBoxFor(model => model.IsLPFREnabled, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.IsLPFREnabled, "", new { @class = "text-danger block", @id = "IsLPFREnabled-validation" })
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.AnQIDCert, Loc.Certificate, new { @class = "col-md-3 control-label" })
                                            <div class="col-md-9">
                                                @Html.HiddenFor(model => model.AnQIDCert)
                                                <input class="form-control typeahead_3" id="certificateInputView" value="@Model.CertSerialNumber" autocomplete="off" placeholder="@Loc.Search" />
                                            </div>
                                        </div>
                                    }
                                }


                                <div id="docTypeCompGdsContainer">
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.DocTypeCompGds, Loc.DocTypeCompGds, new { @class = "col-md-3" })
                                        @Html.HiddenFor(model => model.DocTypeCompGds)
                                        <div class="col-md-9">
                                            <input id="docTypeCompGdsSearch" class="form-control custom-typeahead" type="text" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.NewDocForEachPackage, Loc.DocTypeNewDocEachIssue, new { @class = "col-md-3" })

                                        <div class="col-md-9">
                                            @Html.CheckBoxFor(model => model.NewDocForEachPackage, new { @class = "form-control js-switch js-switch-small", autocomplete = "off" })
                                        </div>
                                    </div>
                                </div>
                            </div>
                        }
                        else
                        {
                            @Html.HiddenFor(model => model.CanFiscalize)
                        }

                        @if (isTravelOrder)
                        {
                            <div class="col-sm-6 col-lg-6">
                                <h3 class="m-b-md m-t-md">@Loc.Costs</h3>
                                <table id="travelorders-expenses"
                                       data-grid-id="travelorders-expense-types"
                                       class="table table-condensed table-bordered showhidecolumns">
                                    <thead class="module-bg">
                                        <tr>
                                            <th data-column-id="Hidden1" class="hidden"></th>
                                            <th data-column-id="Active" width="5%">@Loc.ActiveShort</th>
                                            <th data-column-id="Type" width="10%">@Loc.CostTypes</th>
                                            <th data-column-id="Name" width="20%">@Loc.Name</th>
                                            <th data-column-id="NotForPayout" width="20%">@Loc.NotForPayout</th>
                                            <th data-column-id="EarningType" data-default-hidden="true" width="20%">@Loc.SalaryTypeShort</th>
                                            <th data-column-id="Account" data-default-hidden="true" width="20%">@Loc.Account</th>
                                            <th data-column-id="AddDelete" width="5%" data-sortable="false"></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr id="doctype-expenses-new-row">
                                            <td class="hidden">
                                                <input id="DocType-@newExpenseRowNum"
                                                       value="@Model.Id" />
                                            </td>
                                            <td>
                                                @Html.CheckBox("Active-" + @newExpenseRowNum,
                                                            new
                                                                 {
                                                                     @class = "form-control custom-checkbox",
                                                                id = "Active-" + @newExpenseRowNum,
                                                                autocomplete = "off"
                                                                 })
                                            </td>
                                            <td>
                                                <input id="Type-@newExpenseRowNum"
                                                       type="text"
                                                       class="form-control contact-data-input"
                                                       onclick="setNewCostTypeNumber()" />
                                            </td>
                                            <td>
                                                <input id="Name-@newExpenseRowNum"
                                                       type="text"
                                                       class="form-control contact-data-input" />
                                            </td>
                                            <td>
                                                @Html.CheckBox("NotForPay-" + @newExpenseRowNum,
                                                            new
                                                                 {
                                                                     @class = "form-control custom-checkbox",
                                                                id = "NotForPay-" + @newExpenseRowNum,
                                                                autocomplete = "off"
                                                                 })
                                            </td>
                                            <td>
                                                <div class="contact-data-selects select2HideColumns">
                                                    <select id="EarningType-@newExpenseRowNum"
                                                            data-placeholder="@Loc.SalaryTypeShort"
                                                            class="form-control select2withAPI contact-data-input"
                                                            data-column-names="@Loc.Code,@Loc.Name"
                                                            data-url=@Url.Action("GetSalaryTypes", "SetCalendarEntryTypes")
                                                            data-allow-clear="true"
                                                            data-first-column-only="true"
                                                            data-search-width="350"
                                                            data-mobile-width="200"
                                                            data-bootstrap-columns="col-md-3,col-md-9"></select>
                                                </div>
                                            </td>
                                            <td>
                                                <div class="contact-data-selects select2HideColumns">
                                                    <select id="Account-@newExpenseRowNum"
                                                            data-placeholder="@Loc.Account"
                                                            class="form-control select2withAPI contact-data-input"
                                                            data-column-names="@Loc.Account,@Loc.Name"
                                                            data-url=@Url.Action("SearchAccounts", "AccountCard")
                                                            data-allow-clear="true"
                                                            data-first-column-only="true"
                                                            data-search-width="350"
                                                            data-mobile-width="200"
                                                            data-bootstrap-columns="col-md-3,col-md-9"></select>
                                                </div>
                                            </td>
                                            <td id="btn-col" class="add-btn-td">
                                                <a class="btn btn-success"
                                                   title="@Loc.Add"
                                                   onclick="addNewExpenseType()"
                                                   href="#">
                                                    <i class="fa fa-plus"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        @if (Model.Expenses != null)
                                        {
                                            var index = 0;
                                            foreach (var expense in Model.Expenses)
                                            {
                                                var expensesNameFormat = "Expenses[" + index + "].{0}";
                                                var hideOnDefault = index == 0 ? "hidden" : string.Empty;
                                                <tr id="doctype-expenses-row-@index" class="doctype-expenses">
                                                    <td class="hidden">
                                                        <input id="AnQId-@index"
                                                               name="@string.Format(expensesNameFormat, "AnQId")"
                                                               value="@expense.AnQId">
                                                        <input id="DocType-@index"
                                                               name="@string.Format(expensesNameFormat, "DocType")"
                                                               value="@expense.DocType">
                                                    </td>
                                                    <td>
                                                        @Html.CheckBoxFor(model => expense.Active,
                                                            new
                                                                 {
                                                                     @class = "form-control custom-checkbox",
                                                                id = "Active-" + index,
                                                                Name = string.Format(expensesNameFormat, "Active"),
                                                                autocomplete = "off"
                                                                 })
                                                        @Html.ValidationMessageFor(model => expense.Active, "", new { @class = "text-danger block", @id = "Active-validation" })
                                                    </td>
                                                    <td>
                                                        <input id="Type-@index"
                                                               name="@string.Format(expensesNameFormat, "Type")"
                                                               type="text"
                                                               class="form-control contact-data-input"
                                                               value="@expense.Type" />
                                                    </td>
                                                    <td>
                                                        <input id="Name-@index"
                                                               name="@string.Format(expensesNameFormat, "Name")"
                                                               type="text"
                                                               class="form-control contact-data-input"
                                                               value="@expense.Name" />
                                                    </td>
                                                    <td>
                                                        @Html.CheckBoxFor(model => expense.NotForPay,
                                                            new
                                                                 {
                                                                     @class = "form-control custom-checkbox",
                                                                id = "NotForPay-" + index,
                                                                Name = string.Format(expensesNameFormat, "NotForPay"),
                                                                autocomplete = "off"
                                                                 })
                                                        @Html.ValidationMessageFor(model => expense.NotForPay, "", new { @class = "text-danger block", @id = "NotForPay-validation" })
                                                    </td>
                                                    <td>
                                                        <div class="contact-data-selects select2HideColumns">
                                                            <select id="EarningType-@index"
                                                                    name="@string.Format(expensesNameFormat, "EarningType")"
                                                                    data-placeholder="@Loc.SalaryTypeShort"
                                                                    class="form-control select2withAPI contact-data-input"
                                                                    data-column-names="@Loc.Code,@Loc.Name"
                                                                    data-url=@Url.Action("GetSalaryTypes", "SetCalendarEntryTypes")
                                                                    data-allow-clear="true"
                                                                    data-search-width="350"
                                                                    data-mobile-width="200"
                                                                    data-first-column-only="true"
                                                                    data-bootstrap-columns="col-md-3,col-md-9">
                                                                <option selected="@expense.EarningType">@expense.EarningType</option>
                                                            </select>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="contact-data-selects select2HideColumns">
                                                            <select id="Account-@index"
                                                                    name="@string.Format(expensesNameFormat, "Account")"
                                                                    data-placeholder="@Loc.Account"
                                                                    class="form-control select2withAPI contact-data-input"
                                                                    data-column-names="@Loc.Account,@Loc.Name"
                                                                    data-url=@Url.Action("SearchAccounts", "AccountCard")
                                                                    data-allow-clear="true"
                                                                    data-search-width="350"
                                                                    data-mobile-width="200"
                                                                    data-first-column-only="true"
                                                                    data-bootstrap-columns="col-md-3,col-md-9">
                                                                <option selected="@expense.Account">@expense.Account</option>
                                                            </select>
                                                        </div>
                                                    </td>
                                                    <td class="@hideOnDefault">
                                                        <a class="a-outline"
                                                           title="@Loc.Delete"
                                                           onclick="deleteExpenseType('@index')">
                                                            <i class="far fa-trash-alt"></i>
                                                        </a>
                                                    </td>
                                                </tr>

                                                index++;
                                            }

                                        }
                                    </tbody>
                                </table>
                            </div>
                        }
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="modal inmodal fade" id="copyStatusModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="iris-title">
                <div class="row">
                    <div class="col-xs-11">
                        <h4 class="m-l-sm m-t-sm"><strong>@Loc.CopyStatuses</strong></h4>
                    </div>
                    <div class="col-xs-1 pull-right">
                        <i class="fa fa-times clickable-icon m-l-xs m-t-sm" data-dismiss="modal"></i>
                    </div>
                </div>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-6">
                        <label class="form-control">@Loc.DocumentType</label>
                        <select id="copyStatusDocTypeSelect" class="form-control selectpicker m-t-sm" title="" data-live-search="true">
                            <option></option>
                            @foreach (var item in ViewBag.DocumentTypes)
                            {
                                <option value="@item.Id">
                                    @item.Value
                                </option>
                            }
                        </select>
                    </div>
                    <div class="col-xs-6">
                        <label class="form-control m-b-sm">@Loc.TransferMethod</label>
                        <input type="radio" id="copyTypeAdd" name="copyStatusRadio" value="copy" checked>
                        <label for="copyTypeAdd">@Loc.ImportTypeAdding</label><br>
                        <input type="radio" id="copyTypeOverlapping" name="copyStatusRadio" value="overlapping">
                        <label for="age2">@Loc.Overlapping</label><br>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="copyStatus()">@Loc.Copy</button>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="printSettingsUrl" value="@Url.Action("GetPrintSettings", "DocumentType", new { docType = Model.Id })" />
<input type="hidden" id="changePrintSettingsUrl" value="@Url.Action("ChangePrintSettings", "DocumentType")" />
<input type="hidden" id="ErrorWhileSavingSettingsLoc" value="@Loc.ErrorWhileSavingSettings" />
<input type="hidden" id="ErrorLoc" value="@Loc.Error" />
<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="CancelLoc" value="@Loc.Cancel" />
<input type="hidden" id="WorkPlaceFiscaliteRequiredWorkplaceLoc" value="@Loc.WorkPlaceFiscaliteRequiredWorkplace" />
<input type="hidden" id="FiscalWorkplaceAndDeviceCombinationAlreadyExistsLoc" value="@Loc.FiscalWorkplaceAndDeviceCombinationAlreadyExists" />
<input type="hidden" id="checkFiscalWorkplaceUrl" value="@Url.Action("CheckFiscalWorkplace", "DocumentType")" />
<input type="hidden" id="canChangeIsEvidence" value="@Url.Action("CanChangeIsEvidence", "DocumentType")" />
<input type="hidden" id="docTypeHasFiscalDocsUrl" value="@Url.Action("DocTypeHasFiscalDocs", "DocumentType")" />
<input type="hidden" id="removeUrl" value="@Url.Action("Remove", "DocumentType")" />
<input type="hidden" id="indexUrl" value="@Url.Action("Index", "DocumentType")" />
<input type="hidden" id="createUrl" value="@Url.Action("Create", "DocumentType")" />
<input type="hidden" id="copyStatusUrl" value="@Url.Action("CopyStatus", "DocumentType")" />
<input type="hidden" id="documentTypeRetail" value="@DocumentTypeAcType.Retail" />
<input type="hidden" id="documentTypeWholesale" value="@DocumentTypeAcType.Wholesale" />
<input type="hidden" id="thereAreAlreadyDocumentsForThisDocumentLoc" value="@Loc.ThereAreAlreadyDocumentsForThisDocumentTypeChangeNotPossible" />
<input type="hidden" id="cannotChangeCanFiscalizeSettingLoc" value="@Loc.CannotChangeCanFiscalizeSetting" />
<input type="hidden" id="ConfirmDeleteMessageLoc" value="@Loc.ConfirmDeleteMessage" />
<input type="hidden" id="DeleteWasNotSuccessfulLoc" value="@Loc.DeleteWasNotSuccessful" />
<input type="hidden" id="CopyCompletedLoc" value="@Loc.CopyCompleted" />
<input type="hidden" id="typeDocInternal" value="@TypeDoc.Internal" />
<input type="hidden" id="typeOfDocumentReceivedBills" value="@TypeOfDocument.ReceivedBills" />
<input type="hidden" id="getFirstForTypeOfDocumentUrl" value="@Url.Action("GetFirstForTypeOfDocument", "DocumentType")" />
<input type="hidden" id="currentUserLoc" value="@PantheonRA.BackOffice.CurrentUser.Localization" />
<input type="hidden" id="locHR" value="@Localization.Code.HR" />
<input type="hidden" id="fiscalisationOfOrdersIsNotPossibleAnymoreLoc" value="@Loc.FiscalisationOfOrdersIsNotPossibleAnymore" />
<input type="hidden" id="typeOfDocumentBuyerOrder" value="@TypeOfDocument.BuyerOrder" />
<input type="hidden" id="typeOfDocumentSupplierOrder" value="@TypeOfDocument.SupplierOrder" />


@section pageScripts{
    @Scripts.Render("~/bundles/admin")
    <script>
    $(document).ready(function () {
        initializeDocumentTypeEdit('@isInFiscalPrinterLocalization' === '@Boolean.TrueString', '@PantheonRA.BackOffice.CurrentUser.Localization' !== '@Localization.Code.MK' && '@PantheonRA.BackOffice.CurrentUser.Localization' !== '@Localization.Code.BA' && '@PantheonRA.BackOffice.CurrentUser.Localization' !== '@Localization.Code.BG');
        $.ajax({
            url: "@System.Configuration.ConfigurationManager.AppSettings.Get("FiscalizationLocalApiUrl")/getMachineName",
            type: 'GET',
            cache: false,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Basic QUQ6YTIxODQwNzZDRTczNzlEOUZERkVEYXRhTGFiMTIz'
            }
        }).done(function (data) {
            if (data && data.machineName) {
                $("#MachineName").val(data.machineName);
                $.ajax({
                    url: '@Url.Action("GetDefaultFiscalDevice", "DocumentType")?docType=@Model.Id&machineName=' + data.machineName,
                    type: 'GET',
                    cache: false
                }).done(function (data) {
                    if (data && data.defaultFiscalDevice) {
                        $("#DefaultFiscalDevice").val(data.defaultFiscalDevice.AnQid);
                    }
                    $("#DefaultFiscalDevice").prop("disabled", false);
                }).fail(function () {
                    $("#DefaultFiscalDevice").prop("disabled", false);
                });
            } else {
                $("#DefaultFiscalDevice").prop("disabled", false);
            }
        }).fail(function () {
            $("#DefaultFiscalDevice").prop("disabled", false);
        });

        let preSelectedSerialNumbers = $("#PreSelectedSerialNumbers").val();
        if (preSelectedSerialNumbers)
            $("#SelectedSerialNumbers").selectpicker('val', preSelectedSerialNumbers.split(","));

        initializeCertificatesTypeahead('@Url.Action("GetCertificatesTypeahead", "Certificate")', $('#certificateInputView'), $("#AnQIDCert"), function (certificate) { });

        $("#IsOrderCalendar").on("change", function () {
            $(this)[0].checked ? $("#DocTypeForPOS-container").removeClass("hidden") : $("#DocTypeForPOS-container").addClass("hidden");
        });

        $("#saveButton").on("click", function () {
            if ($("#TypeOfDocumentSelect option:selected").val() === "") {
                $().customModal({
                    destroyOnClose: true,
                    showCloseButton: true,
                    type: "alert",
                    text: "@Loc.ChooseDocType",
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: "@Loc.Confirm",
                            closeOnAction: true,
                            type: 'primary'
                        }
                    ]
                });
                return;
            }

            if ($("#IsOrderCalendar")[0] && !$("#IsOrderCalendar")[0].checked) {
                $("#DocTypeForPOS").val("");
            }

            $("#saveButton i").addClass("fa-spin fa-spinner").removeClass("fa-save");
            var formData = $("#mainForm").serializeArray();
            if ($("#IsEdit").val() !== "True") {
                formData = changeFormDataValue(formData, 'Id', $("#IdView").val().toString().padEnd(4, "0"));
                formData = changeFormDataValue(formData, 'SetOf', $("#TypeOfDocumentSelect option:selected").attr("data-setOf"));
            }

            var url = "@Url.Action("Create", "DocumentType")";
            if ($("#IsEdit").val() === "True")
                url = "@Url.Action("Edit", "DocumentType")";

            $.post(url, formData)
                .done(function (response) {
                    if (response && response.Success === true)
                        location.href = '@Url.Action("Index", "DocumentType")?search=' + response.Id;
                    else {
                        $("#saveButton i").removeClass("fa-spin fa-spinner").addClass("fa-save");

                        if (!response.Success) {
                            clearValidationErrors();

                            if (response.errors)
                                displayResponseValidationErrors(response);
                        } else if ($("#IsEdit").val() !== "True") {
                            $("#Id").val(response.id);
                            $("#copyStatusModal").modal("show");
                            $('#copyStatusModal .modal-dialog').draggable();
                        }
                    }
                });
            });
        });

        $('#MaximumCashAmountInput').on('change', function () {
            var val = paw.utils.value.strToNum($(this).val());
            $('#MaximumCashAmount').val(val);
        });
    </script>
}

<style>
    button[data-id="SelectedSerialNumbers"] {
        border-bottom: none !important;
    }
</style>
