@using PantheonRA.BackOffice.Models
@using PantheonRA.BackOffice.Enums
@using PantheonRA.WebApi.Contracts.Enums

@model DecimalPlacesViewModel

@functions{
    public string GetUrlByAuthorType(UrlHelper url, string authorType)
    {
        switch (authorType)
        {
            case AuthorType.OrdersSupplier:
            case AuthorType.OrdersBuyer:
                return Url.Action("SearchIdentsIncludeSerial", "SetItem");
            case AuthorType.Inventory:
                return Url.Action("SearchInventoryIdents", "SetItem");
            default:
                return Url.Action("SearchIdents", "SetItem");
        }
    }
}

<table id="identSearchTable" class="table table-bordered ident-search" role="grid">
    <thead>
        <tr role="row">
            <th style="width: @(Model.DisplayCreateIdentButton ? "35%" : "40%")">@Loc.AddIdentProduct</th>
            @if (Model.DisplayCreateIdentButton)
            {
                <th style="width: 5%"></th>
            }
            <th class="InputField-Quantity" style="width: 20%">@Loc.Quantity</th>
            <th class="InputField-Price" style="width: 20%">@Loc.Price</th>
            @if (Model.Author != AuthorType.Inventory && !PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule))
            {
                <th class="InputField-Discount" style="width: 20%">@Loc.Discount %</th>
            }
            <th class="order-calendar-th hidden InputField-Begin">@Loc.TaBegin</th>
            <th class="order-calendar-th hidden InputField-Duration">@Loc.Duration</th>
            @if (Model.Workers != null && Model.Workers.Count() > 0)
            {
                <th class="order-calendar-th hidden InputField-Contractor">@Loc.Contractor</th>
            }
            @if (Model.FixedAssets != null && Model.FixedAssets.Count() > 0)
            {
                <th class="order-calendar-th hidden InputField-Means">@Loc.Means</th>
            }
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr role="row">
            <td>
                <input type="text" class="form-control custom-dirty-checker-ignore" id="IdentSearch"
                       dataUrl="@GetUrlByAuthorType(Url, Model.Author)"
                       placeholder="@Loc.EnterIdentProduct" autocomplete="off" />
            </td>
            @if (Model.DisplayCreateIdentButton)
            {
                <td>
                    <div class="addable-icon">
                        <button type="button" title="@Loc.CreateNewProduct" id="NewIdent" class="btn btn-outline btn-primary createNewButton" onclick="createNewIdentModal()">
                            <i class="fas fa-layer-plus"></i>
                        </button>
                    </div>
                </td>
            }
            <td class="InputField-Quantity"><input type="text" class="form-control numberInput input-border-left custom-dirty-checker-ignore" step="@Model.DefaultDecimalPlacesQuantity" id="SelectedItemQuantity" @(Model.Disabled ? "disabled" : "") autocomplete="off" /></td>
            @if (Model.Author == AuthorType.Wholesale || Model.Author == AuthorType.OrdersBuyer || (Model.Author == AuthorType.POS && Model.PosCustomerRabatAllowed == true))
            {
                <td class="InputField-Price">
                    @{Html.RenderPartial("~/Views/Shared/Components/_InputWithSelect.cshtml", new InputWithSelectModel()
                        {
                            Id = "SelectedItemPrice",
                            SelectId = "SelectedItemPriceSelect",
                            Step = Model.DefaultDecimalPlacesPrice,
                            Items = new List<DropdownModel>(),
                            IsDisabled = PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule),
                            InputClass = "custom-dirty-checker-ignore",
                            SelectClass = "custom-dirty-checker-ignore"
                        });}
                </td>
            }
            else
            {
                <td class="InputField-Price"><input type="text" class="form-control numberInput custom-dirty-checker-ignore" step="@Model.DefaultDecimalPlacesPrice" id="SelectedItemPrice" @(Model.Disabled ? "disabled" : "") autocomplete="off" /></td>
            }
            @if (Model.Author != AuthorType.Inventory && !PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule))
            {
                <td class="InputField-Discount"><input type="text" class="form-control numberInput custom-dirty-checker-ignore" step="@Model.DefaultDecimalPlacesPrice" data-min="0" data-max="100" id="SelectedItemRebate" @(Model.Disabled ? "disabled" : "") autocomplete="off" /></td>
            }
            <td class="order-calendar-td hidden InputField-Begin">
                <input id="TimeStart" type="time" class="custom-dirty-checker-ignore">
            </td>
            <td class="order-calendar-td hidden InputField-Duration">
                <input id="TimeDuration" type="time" class="custom-dirty-checker-ignore">
            </td>
            @if (Model.Workers != null && Model.Workers.Count() > 0)
            {
                <td class="order-calendar-td hidden InputField-Contractor">
                    <select id="Contractor"
                            name="Worker"
                            class="form-control selectpicker ident-dropdowns custom-dirty-checker-ignore"
                            data-live-search="true"
                            title="">
                        <option></option>
                        @foreach (var item in Model.Workers)
                        {
                            <option value="@item.Worker">@item.FullName</option>
                        }
                    </select>
                </td>
            }
            @if (Model.FixedAssets != null && Model.FixedAssets.Count() > 0)
            {
                <td class="order-calendar-td hidden InputField-Means">
                    <select id="Tools"
                            style="width:75px"
                            class="form-control selectpicker ident-dropdowns custom-dirty-checker-ignore"
                            data-live-search="true"
                            title="">
                        <option></option>
                        @foreach (var item in Model.FixedAssets)
                        {
                            <option value="@item.InventNum">@item.InventNum - @item.Name.Trim()</option>
                        }
                    </select>
                </td>
            }
            <td>
                <button type="button" class="btn btn-success createNewButton" id="add-position" title="@Loc.AddPosition" @(Model.DisabledAddButton ? "disabled" : "")>
                    <i id="add-position-icon" class="fa fa-plus"></i>
                </button>
            </td>
            <td>
                <button type="button" id="cashRegisterPaymentBtn" class="btn btn-success m-l-sm printDropdown @(Model.DisplayPaymentButton ? string.Empty : "hidden")" title="@Loc.Payment" onclick="cashRegisterPayment()">
                    <i class="fa fa-coins" title="@Loc.Payment"></i><span class="m-l-sm hidden-sm hidden-xs">@Loc.Payment</span>
                </button>
            </td>
        </tr>
    </tbody>
</table>

<input id="SellingPriceLoc" value="@Model.Price1Text" hidden />
<input id="WSPriceLoc" value="@Model.Price2Text" hidden />
<input id="WS2PriceLoc" value="@Model.Price3Text" hidden />
<input id="PrStPriceLoc" value="@Model.Price4Text" hidden />
<input id="ContractPriceLoc" value="@Loc.ContractPrice" hidden />