LocalGovIMS_localgov-ims/src/Admin/Views/Transaction/_Transfer.cshtml
@model Admin.Models.Transaction.TransferViewModel

@if (User.IsInRole(Role.TransactionJournal))
{

    <div class="modal fade modal-xl" id="transferModal" tabindex="-1" aria-labelledby="transferModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="transferModalLabel">Create journal</h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>

                <div class="modal-body">

                    <div class="alert alert-info mb-3">
                        <p class="mb-0">
                            There is <strong><span id="amount-available-to-transfer">0</span></strong> available to journal
                        </p>
                    </div>

                    <div class="alert alert-danger mb-3 transfer-message" style="display:none">
                        <div class="fw-bold pb-1 transfer-message-header">
                            Unable to add the journal
                        </div>
                        <p id="transfer-message-text" class="mb-0 transfer-message-text"></p>
                    </div>

                    <div class="table-responsive-xl">
                        <table id="transfer-table" class="table table-striped table-bordered mt-2">
                            <thead>
                                <tr>
                                    <th scope="col" id="TransferItemFundCode" style="min-width:200px;">Fund type</th>
                                    <th scope="col">Account</th>
                                    <th scope="col">Name</th>
                                    <th scope="col">Outstanding balance (£)</th>
                                    <th scope="col" id="TransferItemVatCode" style="min-width:200px;">VAT code</th>
                                    <th scope="col">Amount (£)</th>
                                    <th scope="col" style="min-width:200px;">Narrative</th>
                                    <th scope="col"><span class="visually-hidden">Actions</span></th>
                                </tr>
                            </thead>
                            <tbody id="transfer-table-body"></tbody>
                            <tfoot>
                                <tr>
                                    <td>
                                        <select id="TransferItem_FundCode" name="TransferItem_FundCode" aria-labelledby="TransferItemFundCode">
                                            <option value="">None</option>
                                            @foreach (var item in Model.Funds.Items)
                                            {
                                                var dataAttributes = item.DataAttributes.Aggregate("", (current, attribute) => current + ("data-" + attribute.Key.ToLower() + "=" + attribute.Value + " "));

                                                <option class="item" value="@item.Value" @(Model.TransferItem != null && !Model.TransferItem.FundCode.IsNullOrEmpty() && Model.TransferItem.FundCode.Equals(item.Value) ? "selected" : String.Empty) @dataAttributes>@item.Text</option>
                                            }
                                        </select>
                                    </td>
                                    <td colspan="3">
                                        @Html.TextBoxFor(m => m.TransferItem.AccountReference, new { @placeholder = "Enter account reference", @class = "form-control", @maxlength = 32 })
                                        @Html.ValidationMessageFor(x => x.TransferItem.AccountReference)
                                    </td>
                                    <td>
                                        <select id="TransferItem_VatCode" name="TransferItem_VatCode" aria-labelledby="TransferItemVatCode">
                                            <option value="">None</option>
                                            @foreach (var item in Model.VatCodes.Items)
                                            {
                                                <option class="item" value="@item.Value" @(Model.TransferItem != null && Model.TransferItem.VatCode != null && !Model.TransferItem.VatCode.IsNullOrEmpty() && Model.TransferItem.VatCode.Equals(item.Value) ? "selected" : String.Empty)>@item.Text</option>
                                            }
                                        </select>
                                    </td>
                                    <td>
                                        @Html.TextBoxFor(m => m.TransferItem.Amount, null, new { @placeholder = "0.00", @class = "form-control monetary-amount" })
                                        @Html.ValidationMessageFor(x => x.TransferItem.Amount)
                                    </td>
                                    <td>
                                        @Html.TextBoxFor(m => m.TransferItem.Narrative, null, new { @placeholder = "Enter narrative", @class = "form-control" })
                                        @Html.ValidationMessageFor(x => x.TransferItem.Narrative)
                                    </td>
                                    <td class="text-end">
                                        <button class="btn btn-primary add-transfer">Add</button>
                                    </td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary submit-transfer one-click-submit-button" id="submit-transfer">Submit journal</button>
                    </div>

                </div>
            </div>
        </div>
    </div>

}
