@model PantheonRA.BackOffice.Models.TravelOrdersExpensesViewModel

@{
    ViewBag.Title = "Create";
    Layout = null;
    var decimalFormat = "{0:N2}";
}
@Html.Hidden("AddNewExpense", @Url.Action("CreateExpense", "TravelOrdersExpenses"))

    <div class="table-responsive">
        <table id="expensesTable" class="table table-bordered expense-table" role="grid">
            <thead>
                <tr>
                    <th>@Loc.Cost</th>
                    <th>@Loc.Amount</th>
                    <th>@Loc.Currency</th>
                    <th>@Loc.DateAndTime</th>
                    <th>@Loc.FxRate</th>
                    <th>@Loc.Value</th>
                    <th>@Loc.NotInCurrency</th>
                    <th>@Loc.NotForPayout</th>
                    <th>@Loc.Description</th>
                    <th>
                        <a class="btn btn-success hide" id="refresh-expense-@Model.anNo" data-ajax="true" data-ajax-mode="replace"
                           data-ajax-update="#TravelOrdersExpensesId-@Model.anNo"
                           data-ajax-success="select2withAPI();dateTimePicker();getKilometers();getTotals('@Model.acKey');"
                           href="@Url.Action("Create", "TravelOrdersExpenses", new { anNo = Model.anNo, acKey = Model.acKey })">
                            <i class="fa fa-refresh" title="@Loc.Refresh"></i>
                        </a>
                    </th>
                </tr>
            </thead>
            <tbody>
                <!--create-->
                <tr>
                    <td class="travelorders-width-16">
                        @Html.HiddenFor(m => m.acKey)

                        <select name="CostType"
                                id="add-CostType-@Model.anNo"
                                data-placeholder="@Loc.Cost"
                                class="form-control select2withAPI"
                                style="width:200px !important;"
                                data-url=@Url.Action("GetExpenseTypes", "TravelOrdersExpenses", new { acKey = Model.acKey }) required></select>

                    </td>
                    <td class="travelorders-width-10">
                        @Html.TextBox("PriceCurrency", Model.travelOrderExpenseSingle.PriceCurrency,
                            new { @class = "form-control", @autocomplete = "off", @required = "required", @id = "add-PriceCurrency-" + Model.anNo, @placeholder = @Loc.Amount })

                    </td>
                    <td class="travelorders-width-9">
                        <select id="add-Currency-@Model.anNo"
                                name="Currency"
                                data-placeholder="@Loc.Currency"
                                class="form-control select2withAPI"
                                data-url=@Url.Action("GetCurrencies", "TravelOrdersExpenses")
                                onchange="getFxRate()"
                                required>

                            <option value="@Model.travelOrderExpenseSingle.Currency" selected>
                                @Model.travelOrderExpenseSingle.Currency
                            </option>
                        </select>
                    </td>

                    <td class="travelorders-width-14">
                        @{ Html.EnableClientValidation(false); }
                        @Html.TextBox("DateCost", Model.travelOrderExpenseSingle.DateCost.ToString("dd.MM.yyyy HH:mm"),
                       new { @class = "form-control datetimepicker", @id = "add-DateCost-" + Model.anNo, @placeholder = Loc.DateAndTime, @onchange = "getFxRate()" })
                        @{ Html.EnableClientValidation(true); }
                    </td>

                    <td class="travelorders-width-9">
                        @Html.TextBox("FxRate", "1,000000", new { @class = "form-control", @autocomplete = "off", id = "add-FxRate-" + Model.anNo, @placeholder = Loc.FxRate, @onchange = "calculateValue(-1);" })
                    </td>

                    <td class="travelorders-width-12" style="background-color:#eee">
                        @Html.TextBox("Vrednost", "", new { @class = "form-control", @autocomplete = "off", @placeholder = Loc.Value, @readonly = "readonly" })
                    </td>

                    <td class="travelorders-checkbox travelorders-width-6">
                        @Html.CheckBox("NotInCurrency", Model.travelOrderExpenseSingle.NotInCurrency, new { @id = "add-NotInCurrency-" + Model.anNo, @Class = "custom-checkbox" })

                    </td>

                    <td class="travelorders-checkbox travelorders-width-6">
                        @Html.CheckBox("NotForPayment", Model.travelOrderExpenseSingle.NotForPayment, new { @id = "add-NotForPayment-" + Model.anNo, @Class = "custom-checkbox" })
                    </td>

                    <td class="travelorders-width-14">
                        @Html.TextBox("Note", Model.travelOrderExpenseSingle.Note,
                            new { @class = "form-control", @autocomplete = "off", @id = "add-Note-" + Model.anNo, @placeholder = @Loc.Description })
                    </td>

                    <td>
                        <button class="btn btn-success" type="button">
                            <i class="fa fa-plus" title="@Loc.AddExpense" onclick="addNewExpense(@Model.anNo)"></i>
                        </button>

                    </td>
                </tr>
                <!--list and edit-->
                @foreach (var item in Model.travelOrderExpensesList)
                {
                    <tr class="expensesTable-@item.AnCostNo">
                        <td class="travelorders-padding" style="width:200px !important;">
                            @Html.DisplayFor(modelitem => item.Name)
                        </td>

                        <td class="travelorders-input-width" style="width:80px;">
                            <input class="form-control"
                                   onchange="checkAndSave(@item.QId, 'expenses')"
                                   id="editPriceCurrency-@item.QId"
                                   value="@string.Format(decimalFormat, item.PriceCurrency)" />
                        </td>

                        <td class="travelorders-currency">
                            <select id="editCurrency-@item.QId" data-placeholder="@Loc.Currency"
                                    class="form-control select2withAPI"
                                    data-url=@Url.Action("GetCurrencies", "TravelOrdersExpenses")
                                    onchange="checkAndSave(@item.QId, 'expenses')"
                                    required>
                                <option value="@item.Currency" selected> @Html.DisplayFor(modelitem => item.Currency)</option>
                            </select>
                        </td>

                        <td class="travelorders-input-width">
                            <input id="editDateCost-@item.QId" onchange="checkAndSave(@item.QId, 'expenses')" class="form-control datetimepicker" type="text" value="@item.DateCost.ToString("dd.MM.yyyy HH:mm")" />
                        </td>

                        <td style="max-width:80px;">
                            <input id="editFxRate-@item.QId"
                                   onchange="checkAndSave(@item.QId, 'expenses')"
                                   class="form-control"
                                   value="@string.Format("{0:0.000000}", item.FxRate)" />
                        </td>

                        <td style="max-width:80px;">
                            <input id="Vrednost"
                                   readonly
                                   class="form-control"
                                   value="@string.Format(decimalFormat, item.Value)" />
                        </td>

                        <td class="text-center travelorders-checkbox">
                            <input id="editNotInCurrency-@item.QId"
                                   onchange="checkAndSave(@item.QId, 'expenses')"
                                   type="checkbox"
                                   value="@item.NotInCurrency" @(item.NotInCurrency == true ? "checked" : string.Empty) />
                        </td>

                        <td class="text-center travelorders-checkbox">
                            <input id="editNotForPayment-@item.QId"
                                   class="custom-checkbox"
                                   onchange="checkAndSave(@item.QId, 'expenses')"
                                   type="checkbox"
                                   value="@item.NotForPayment" @(item.NotForPayment == true ? "checked" : string.Empty) />
                        </td>

                        <td>
                            <input id="editExpenseNote-@item.QId"
                                   onchange="checkAndSave(@item.QId, 'expenses')"
                                   class="form-control"
                                   value="@Html.DisplayFor(modelitem => item.Note)" />
                        </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();getTotals('@Model.acKey');"
                               data-ajax-update="#TravelOrdersExpensesId-@Model.anNo"
                               href="@Url.Action("Delete", "TravelOrdersExpenses", new { qId = item.QId, anNo = item.AnCostNo, acKey = item.AcKey })">
                                <span class="far fa-trash-alt" aria-hidden="true"></span>
                            </a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>