@using PAW.Contracts.Enums;
@model PantheonRA.BackOffice.Models.TravelOrdersDailyAllowsViewModel

@{
    ViewBag.Title = Loc.Create;
    Layout = null;
    var currentLoc = Loc.CurrentLocalization;
}

<div class="table-responsive">

    <a class="btn btn-success hide" id="refresh-dailyAllows-@Model.anNo" data-ajax="true" data-ajax-mode="replace"
       data-ajax-update="#TravelOrdersDailyAllowsID-@Model.anNo"
       data-ajax-success="select2withAPI();"
       href="@Url.Action("Create", "TravelOrdersDailyAllows", new { acKey = Model.acKey })">
    </a>

    <a class="hide" id="refresh-totals" onclick="getTotals('@Model.acKey')"></a>

    @Html.HiddenFor(m => m.acKey)

    <table id="dailyAllowsTable" class="table table-bordered dailyallow-table" role="grid">
        <thead>
            <tr>
                <th>@Loc.DailyAllow</th>
                <th>@Loc.DailyAllowNo</th>
                <th>@Loc.DailyAllowAmount</th>
                <th>
                    @if (currentLoc != Localization.Code.HR)
                    {
                        @Loc.Breakfast
                    }
                </th>
                <th>@Loc.Lunch</th>
                <th>@Loc.Dinner</th>
                <th>@Loc.Factor</th>
                <th>@Loc.DailyAllowBonus</th>
                <th>@Loc.Value</th>
                <th>@Loc.Currency</th>
                <th>@Loc.FxRate</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @Html.HiddenFor(m => m.acKey)
            @foreach (var item in Model.travelOrderDailyAllowsList)
            {
                @Html.Hidden("AnNo-" + item.anId, item.AnNo)
                @Html.Hidden("TotalHours-" + item.anId, item.TotalHours)
                @Html.Hidden("DateHourFrom-" + item.anId, item.DateHourFrom)
                @Html.Hidden("DateHourTo-" + item.anId, item.DateHourTo)
                @Html.Hidden("CZakonodaja-" + item.anId, item.CZakonodaja)
                @Html.Hidden("DailyAllowNo-" + item.anId, item.DailyAllowNo)
                @Html.Hidden("lIsInstallGE-" + item.anId, item.lIsInstallGE)
                @Html.Hidden("QId-" + item.anId, item.QId)
                @Html.Hidden("anId-" + item.anId, item.anId)

                <tr>

                    <td style="min-width:100px;">
                        <div class="">
                            <select id="DailyAllow-@item.anId"
                                    name="DailyAllow-@item.anId"
                                    data-placeholder="@Loc.DailyAllow"
                                    class="form-control select2withAPI"
                                    data-url=@Url.Action("GetDailyAllowTypes", "TravelOrdersDailyAllows")
                                    data-column-names="@Loc.DailyAllow,@Loc.Name"
                                    data-bootstrap-columns="col-md-6,col-md-6"
                                    onchange="checkAndSave(@item.anId, 'dailyAllows')">

                                <option selected>@item.DailyAllow</option>
                            </select>

                        </div>
                    </td>

                    <td style="width:30px;">
                        @Html.TextBox("anDailyAllowNo-" + item.anId, item.anDailyAllowNo,
                        new { @class = "form-control", @autocomplete = "off", @placeholder = Loc.DailyAllowNo, @onchange = "checkAndSave(" + @item.anId + ", 'dailyAllows')" })
                    </td>

                    <td style="max-width:20px;">
                        @Html.TextBox("anPriceDailyAllow-" + item.anId, string.Format("{0:,0.00}", item.anPriceDailyAllow),
                        new { @class = "form-control", @autocomplete = "off", @placeholder = Loc.DailyAllowAmount, @onchange = "checkAndSave(" + @item.anId + ", 'dailyAllows')" })
                    </td>

                    <td class="text-center travelorders-checkbox">
                        @if (!item.IsFromSixToEight && currentLoc != Localization.Code.HR)
                        {
                            @Html.CheckBox("IsBreakfastIncluded-" + item.anId, item.IsBreakfastIncluded, new { @onchange = "checkAndSave(" + item.anId + ", 'dailyAllows')", @Class= "custom-checkbox" })
                        }
                    </td>

                    <td class="text-center travelorders-checkbox">
                        @Html.CheckBox("IsLunchIncluded-" + item.anId, item.IsLunchIncluded, new { @onchange = "checkAndSave(" + item.anId + ", 'dailyAllows')", @Class = "custom-checkbox" })
                    </td>

                    <td class="text-center travelorders-checkbox">
                        @Html.CheckBox("IsDinnerIncluded-" + item.anId, item.IsDinnerIncluded, new { @onchange = "checkAndSave(" + item.anId + ", 'dailyAllows')", @Class = "custom-checkbox" })
                    </td>

                    <td style="max-width:20px; padding:0px !important;background-color:#eee">
                        @Html.TextBox("CalcFactor-x", item.CalcFactor, new { @class = "form-control", @autocomplete = "off", @readonly = "readonly" })
                    </td>

                    <td style="width:30px;">
                        <div class="">
                            @Html.TextBox("anPriceFieldBonus-" + item.anId, item.anPriceFieldBonus,
                            new { @class = "form-control", @autocomplete = "off", @placeholder = Loc.DailyAllowBonus, @onchange = "checkAndSave(" + @item.anId + ", 'dailyAllows')" })
                        </div>
                    </td>

                    <td style="max-width:20px;">
                        @Html.TextBox("Value-" + item.anId, string.Format("{0:,0.00}", item.Value),
                        new { @class = "form-control", @autocomplete = "off", @placeholder = Loc.Value, @onchange = "checkAndSave(" + @item.anId + ", 'dailyAllows')" })
                    </td>

                    <td class="travelorders-width-12">
                        <div class="">
                            <select id="Currency-@item.anId"
                                    name="Currency-@item.anId"
                                    data-placeholder="@Loc.Currency"
                                    class="form-control select2withAPI"
                                    data-url=@Url.Action("GetCurrencies", "TravelOrdersExpenses")
                                    onchange="checkAndSave(@item.anId, 'dailyAllows')"
                                    required>
                                <option selected>@item.Currency</option>

                            </select>
                        </div>
                    </td>

                    <td class="travelorders-width-11" style="max-width:80px;">
                        @Html.TextBox("FxRate-" + item.anId, item.anFxRate, new { @class = "form-control", @autocomplete = "off", @placeholder = Loc.FxRate })
                    </td>

                    <td class="travelorders-remove-button">
                        <a class="btn btn-outline" data-ajax="true" data-ajax-method="POST"
                           data-ajax-mode="replace" data-ajax-success="select2withAPI();dateTimePicker();getKilometers();getTotals('@Model.acKey');updateDailyAllows();"
                           data-ajax-update="#TravelOrdersDailyAllowsID-@Model.anNo"
                           href="@Url.Action("Delete", "TravelOrdersDailyAllows", new { acKey = item.AcKey, qId = item.QId})">
                            <span class="far fa-trash-alt" aria-hidden="true"></span>
                        </a>
                    </td>
                </tr>
            }
        </tbody>
    </table>

</div>