@using PantheonRA.BackOffice
@using PantheonRA.BackOffice.Enums
@using PantheonRA.WebApi.Contracts.Enums
@using PantheonRA.BackOffice.Models
@using PAW.Contracts.Enums;
@model PantheonRA.BackOffice.Models.TaxCreateViewModel
@{
    ViewBag.Title = string.IsNullOrEmpty(Model.VATCode) ? Loc.NewTax : Loc.EditTax;
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { @id = "taxForm", enctype = "multipart/form-data" }))
{
    <div class="tabs-container">
        @Html.Partial("~/Views/Products/_CodeListTabNavigation.cshtml")
        <div class="tab-content">
            <div class="row buttons-tabbed">
                @Html.Partial("_FormButtons", new FormButtonsViewModel
                {
                    BackUrl = Url.Action("Index", "Taxes"),
                    SaveButtonGroup = new FormButtonGroup
                    {
                        Buttons = new List<FormButton>
                        {
                            new FormButton { Text = Loc.Save, Icon = "fa fa-save fa-lg", IsSubmit = true, OnClick="$('#taxForm').submit();" }
                        }
                    }
                })

                <a href="@Url.Action("Create", "Taxes")" title="@Loc.New"
                   class="btn btn-primary btn-outline pull-right @(string.IsNullOrEmpty(Model.VATCode) ? "hidden" : string.Empty)">
                    <i class="fas fa-plus m-r-xs"></i>
                    <span class="visible-lg-inline visible-md-inline">@Loc.NewTax</span>
                </a>

                <button id="invoiceDelete" type="button" onclick="removeTax()" 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>
            </div>
            <div class="divided-content">
                <div class="divided-content-main divided-content-full">
                    <div class="form-horizontal form-md m-t-md">
                        <div class="row">
                            <div class="col-xs-12 col-md-7 col-lg-5">
                                <div class="row">
                                    <div class="col-xs-12">
                                        @Html.HiddenFor(model => model.IsEdit)
                                        <h3 class="m-b-md">@Loc.TaxBasicData</h3>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.Active, Loc.IsActive, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @Html.CheckBoxFor(model => model.Active, new { @id = "Active", @class = "form-control js-switch" })
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.VATCode, Loc.Code, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                @if (!string.IsNullOrEmpty(Model.VATCode) && Model.IsEdit)
                                                {
                                                    @Html.TextBoxFor(model => model.VATCode, new { @id = "VATCode", @class = "form-control", @readonly = "readonly", @placeholder = Loc.Code })
                                                    @Html.ValidationMessageFor(model => model.VATCode, "", new { @class = "text-danger" })
                                                }
                                                else
                                                {
                                                    @Html.TextBoxFor(model => model.VATCode, new { @id = "VATCode", @class = "form-control", @placeholder = Loc.Code, maxlength = "2", autocomplete = "off" })
                                                    @Html.ValidationMessageFor(model => model.VATCode, "", new { @class = "text-danger" })
                                                }
                                            </div>
                                        </div>

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

                                        <div class="form-group">
                                            @Html.LabelFor(model => model.VAT, Loc.TaxPercent, new { @class = "col-md-4 control-label" })
                                            <div class="col-md-8">
                                                <input id="savedVAT" value="@Model.VAT" hidden />
                                                @Html.TextBoxFor(model => model.VAT, new { @id = "VAT", @class = "form-control numberInput", @placeholder = Loc.TaxPercent, autocomplete = "off" })
                                                @Html.ValidationMessageFor(model => model.VAT, "", new { @class = "text-danger" })
                                            </div>
                                        </div>

                                        @if (PantheonRA.BackOffice.CurrentUser.Localization == Localization.Code.RS)
                                        {
                                            <div class="form-group">
                                                @Html.LabelFor(model => model.FiscalCode, Loc.FiscalNumber, new { @class = "col-md-4 control-label" })
                                                <div class="col-md-8">
                                                    @Html.TextBoxFor(model => model.FiscalCode, new { @id = "FiscalCode", @class = "form-control", @placeholder = Loc.FiscalNumber, autocomplete = "off" })
                                                    @Html.ValidationMessageFor(model => model.FiscalCode, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.NameFisk, Loc.FiscalizationName, new { @class = "col-md-4 control-label" })
                                                <div class="col-md-8">
                                                    @Html.TextBoxFor(model => model.NameFisk, new { @id = "NameFisk", @class = "form-control", @placeholder = Loc.FiscalizationName, autocomplete = "off" })
                                                    @Html.ValidationMessageFor(model => model.NameFisk, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.EDocument, Loc.EDocument, new { @class = "col-md-4 control-label" })
                                                <div class="col-md-8">
                                                    @Html.DropDownListFor(model => model.EDocument, new List<SelectListItem>
                                                    {

                                                        new SelectListItem{ Text="S - " + Loc.StandardTaxRate, Value = "S" },
                                                        new SelectListItem{ Text="E - " + Loc.ExemptFromVAT, Value = "E" },
                                                        new SelectListItem{ Text="O - " + Loc.TheSubjectIsNotInTheVATSystem, Value = "O" },
                                                        new SelectListItem{ Text="Z - " + Loc.ZeroVATRate, Value = "Z" },
                                                        new SelectListItem{ Text="G - " + Loc.ExemptFromVATDueToExport, Value = "G" },
                                                        new SelectListItem{ Text="AE - " + Loc.TransferOfTaxLiability, Value = "AE" },
                                                        new SelectListItem{ Text="B - " + Loc.ExemptFromVAT, Value = "B" },
                                                        new SelectListItem{ Text="R - " + Loc.ExemptionFromVAT, Value = "R" },
                                                    }, HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "EDocument", false, Loc.EDocument, false, null))
                                                    @Html.ValidationMessageFor(model => model.EDocument, "", new { @class = "text-danger" })
                                                </div>
                                            </div>

                                            <div class="form-group">
                                                @Html.LabelFor(model => model.Statement, Loc.Text, new { @class = "col-md-4 control-label" })
                                                <div class="col-md-8">
                                                    @Html.DropDownList("Statement", new SelectList(ViewBag.DocTexts != null ? ViewBag.DocTexts : new List<string>(), "Id", "Code"), Loc.Select,
                                                        HtmlAttributesHelper.CreateInputAttributes("form-control custom-select", "Statement", false, Loc.Text, true, new { @title = Loc.Select }))
                                                    @Html.ValidationMessageFor(model => model.Statement, "", new { @class = "text-danger" })
                                                </div>
                                            </div>
                                        }
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}

<input type="hidden" id="YesLoc" value="@Loc.Yes" />
<input type="hidden" id="NoLoc" value="@Loc.No" />
<input type="hidden" id="ConfirmLoc" value="@Loc.Confirm" />
<input type="hidden" id="CancelLoc" value="@Loc.Cancel" />
<input type="hidden" id="GeneralErrorMessage" value="@Loc.GeneralError" />
<input type="hidden" id="ConfirmChangeTaxPercentLoc" value="@Loc.ConfirmChangeTaxPercent" />
<input type="hidden" id="InItemPricingRetailPriceWillBeChangedLoc" value="@Loc.InItemPricingRetailPriceWillBeChanged" />
<input type="hidden" id="ChangeTaxPercentUrl" value="@Url.Action("ChangeTaxPercent", "Taxes")" />
<input type="hidden" id="RemoveTaxUrl" value="@Url.Action("Remove", "Taxes")" />
<input type="hidden" id="TaxIndexUrl" value="@Url.Action("Index", "Taxes")" />
<input type="hidden" id="DeleteWasNotSuccessfulLoc" value="@Loc.TaxAlreadyInUse" />
<input type="hidden" id="ConfirmDeleteLoc" value="@Loc.ConfirmDeleteMessage" />
<input type="hidden" id="GeneralErrorLoc" value="@Loc.GeneralError" />

@section pageScripts{
    @Scripts.Render("~/bundles/product")
    <script>
        $(document).ready(function () {
            initializeTaxesEdit();
        });
    </script>
}