@using PantheonRA.BackOffice.Models

@model PantheonRA.BackOffice.Models.CustTariffViewModel
@{
    ViewBag.Title = string.IsNullOrEmpty(Model.CustTariff) ? Loc.CreateCustomsTariff : Loc.EditCustomsTariff;
}

<div class="wrapper wrapper-content">
    <div class="tabs-container">
        @Html.Partial("~/Views/Products/_CodeListTabNavigation.cshtml")
        <div class="row">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <div class="buttons-ribbon floating-buttons">
                        @Html.Partial("_FormButtons", new FormButtonsViewModel
                        {
                            BackUrl = Url.Action("Index", "CustTariff"),
                            SaveButtonGroup = new FormButtonGroup
                            {
                                Buttons = new List<FormButton>
                                {
                                    new FormButton { Text = Loc.Save, Icon = "far fa-print fa-lg", OnClick = "confirm()"},
                                }
                            }
                        })
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <form method="post" id="CustTariffForm">
                                <div class="ibox">
                                    <div class="ibox-content">
                                        @Html.HiddenFor(model => model.DefaultDecimalPlacesValue)
                                        @Html.HiddenFor(model => model.DefaultDecimalPlacesPrice)
                                        @Html.HiddenFor(model => model.DefaultDecimalPlacesQuantity)
                                        @Html.HiddenFor(model => model.Currency)
                                        <div class="row">
                                            <div class="form-horizontal form-md">
                                                <div class="col-sm-8 col-md-6 col-lg-4">
                                                    <div class="row">
                                                        <div class="col-xs-12">
                                                            <div class="form-group">
                                                                @Html.LabelFor(model => model.CustTariff, Loc.Code, new { @class = "col-md-4 control-label" })
                                                                <div class="col-md-8">
                                                                    @Html.HiddenFor(model => model.IsEdit)
                                                                    @Html.TextBoxFor(model => model.CustTariff,
                                                                        HtmlAttributesHelper.CreateInputAttributes("form-control", "CustTariff", Model.IsEdit ? true : false, Loc.Code, false,
                                                                        new { @maxlength = 12, @autocomplete = "off" }))
                                                                    @Html.ValidationMessageFor(model => model.CustTariff, "", new { @class = "text-danger", @id = "CustTariff-validation" })
                                                                </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,
                                                                        HtmlAttributesHelper.CreateInputAttributes("form-control", "Name", false, Loc.Name, false, new { @autocomplete = "off" }))
                                                                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger", @id = "Name-validation" })
                                                                </div>
                                                            </div>
                                                            <div class="form-group">
                                                                @Html.LabelFor(model => model.Rate, Loc.CustomsTariffRate, new { @class = "col-md-4 control-label" })
                                                                <div class="col-md-8">
                                                                    @Html.TextBoxFor(model => model.Rate, new { @id = "Rate", @class = "form-control",
                                                                        @placeholder = Loc.CustomsTariffRate, @autocomplete = "off" })
                                                                    @Html.ValidationMessageFor(model => model.Rate, "", new { @class = "text-danger", @id = "Rate-validation" })
                                                                </div>
                                                            </div>
                                                            <div class="form-group">
                                                                @Html.LabelFor(model => model.Unit, Loc.UnitOfMeasurement, new { @class = "col-md-4 control-label" })
                                                                <div class="col-md-8">
                                                                    @Html.DropDownListFor(model => model.Unit, new SelectList(ViewBag.MeasurementUnits != null ? ViewBag.MeasurementUnits : new List<string>(), "Id", "Name"),
                                                                        HtmlAttributesHelper.CreateInputAttributes("form-control", "Unit", false, Loc.Reference, true))
                                                                    @Html.ValidationMessageFor(model => model.Unit, "", new { @class = "text-danger", @id = "Unit-validation" })
                                                                </div>
                                                            </div>
                                                            <div class="form-group">
                                                                @Html.LabelFor(model => model.Disabled, Loc.InactiveStatus, new { @class = "col-md-4 control-label" })
                                                                <div class="col-md-8">
                                                                    @Html.CheckBoxFor(model => model.Disabled, new { @id = "Disabled", @class = "form-control js-switch" })
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="m-t-none" />
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="row">
                                                            <div class="col-md-8 col-sm-10 col-xs-12">
                                                                <table id="identSearchTable" class="table table-bordered cash-register-search ident-search" role="grid">
                                                                    <thead>
                                                                        <tr role="row">
                                                                            <th style="width: 40%">@Loc.Search</th>
                                                                            <th></th>
                                                                        </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                        <tr role="row">
                                                                            <td>
                                                                                <input type="text" class="typeahead_3 form-control" id="DutySearch" dataUrl="@Url.Action("SearchDuties", "Duty")"
                                                                                       placeholder="@Loc.Excise" autocomplete="off" />
                                                                            </td>
                                                                            <td>
                                                                                <button type="button" class="btn btn-success" id="add-excise">
                                                                                    <i id="add-excise-icon" class="glyphicon glyphicon-plus"></i><span class="visible-lg-inline visible-md-inline m-l-xs">
                                                                                        @Loc.AddExcise
                                                                                    </span>
                                                                                </button>
                                                                            </td>
                                                                        </tr>
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-12 col-lg-12">
                                                        <div class="table-responsive m-b-md">
                                                            <div class="dt-bootstrap" style="position:relative">
                                                                <table id="idents" class="table table-bordered cash-register-invocation" role="grid">
                                                                    <thead>
                                                                        <tr role="row">
                                                                            <th style="width:18%" colspan="2" class="text-center headerColumnWithBorder">@Loc.Benefits</th>
                                                                            <th style="width:20%" colspan="2" class="text-center headerColumnWithBorder">@Loc.Date</th>
                                                                            <th style="width:15%" colspan="2" class="text-center headerColumnWithBorder">@Loc.RatePerUnit</th>
                                                                            <th style="width:32%" colspan="4" class="text-center headerColumnWithBorder">@Loc.Value</th>
                                                                            <th style="width:10%" colspan="1" class="text-center headerColumnWithBorder">@Loc.Currency</th>
                                                                            <th style="min-width:75px;width:75px"></th>
                                                                        </tr>
                                                                        <tr role="row">
                                                                            <th style="width:8%">@Loc.BenefitKind</th>
                                                                            <th style="width:10%">@Loc.BenefitType</th>

                                                                            <th style="width:10%">@Loc.From</th>
                                                                            <th style="width:10%">@Loc.To</th>

                                                                            <th style="width:6%">%</th>
                                                                            <th style="width:9%">@Loc.BaseAmountShort</th>

                                                                            <th style="width:8%">@Loc.Value</th>
                                                                            <th style="width:8%">@Loc.Quantity</th>
                                                                            <th style="width:8%">@Loc.MeasUnit</th>
                                                                            <th style="width:8%">@Loc.UnitConverter</th>

                                                                            <th style="width:10%"></th>
                                                                            <th style="min-width:75px;width:75px"></th>
                                                                        </tr>
                                                                    </thead>
                                                                    <tbody id="identRows"></tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="baseOptions" hidden>
    <option value="R">@Loc.RetailPrice</option>
    <option value="S">@Loc.SellingPrice</option>
</div>

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

<div id="tariffType" hidden>
    <option value="C">@Loc.Customs</option>
    <option value="D">@Loc.Tax</option>
    <option value="T">@Loc.Excise</option>
    <option value="0">@Loc.OtherData</option>
</div>

<div id="currencyOptions" hidden>
    @foreach (var currency in ViewBag.Currencies)
    {
        <option value="@currency.Id">
            @currency.Id
        </option>
    }
</div>

<input id="UpdateCustTariffUrl" value="@Url.Action("Edit", "CustTariff")" hidden />
<input id="CreateCustTariffUrl" value="@Url.Action("Create", "CustTariff")" hidden />
<input id="CustTariffItemsUrl" value="@Url.Action("ItemsList", "CustTariffSaleEx")" hidden />
<input id="CreateCustTariffItemUrl" value="@Url.Action("CreateItem", "CustTariffSaleEx")" hidden />
<input id="UpdateItemUrl" value="@Url.Action("UpdateItem", "CustTariffSaleEx")" hidden />
<input id="RemoveItemUrl" value="@Url.Action("RemoveItem", "CustTariffSaleEx")" hidden />
<input id="RemoveItemMsg" value="@Loc.ConfirmDeleteItemMessage" hidden />
<input id="YesLoc" value="@Loc.Yes" hidden />
<input id="NoLoc" value="@Loc.No" hidden />

@section pageScripts{
    @Scripts.Render("~/bundles/product")
    @Scripts.Render("~/bundles/invoiceIdent")

    <script>
        $(document).ready(function () {
            initializeCustTariffsEdit();
        });
    </script>
}
