LocalGovIMS_localgov-ims/src/Admin/Views/Transfer/Index.cshtml
@using Microsoft.Ajax.Utilities
@model Admin.Models.Transfer.TransferViewModel
@{
    ViewBag.Title = "Transfer";
}

@section Header { Transfer }

@section Subheader { Move money between funds and accounts }

<div>

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

    <div class="border rounded p-2 mb-3">
        <h3>Source transactions</h3>
        <div class="table-responsive-sm">
            <table id="source-table" class="table table-striped table-bordered mt-2">
                <thead>
                    <tr>
                        <th scope="col" id="SourceItemFundCode">Fund type</th>
                        <th scope="col">Account</th>
                        <th scope="col">Name</th>
                        <th scope="col">Outstanding balance (£)</th>
                        <th scope="col" id="SourceItemVatCode">VAT code</th>
                        <th scope="col">Amount (£)</th>
                        <th scope="col"><span class="visually-hidden">Actions</span></th>
                    </tr>
                </thead>
                <tbody id="source-table-body"></tbody>
                <tfoot>
                    <tr>
                        <td>
                            <select id="SourceItem_FundCode" name="SourceItem_FundCode" aria-labelledby="SourceFundCode">
                                <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.SourceItem != null && !Model.SourceItem.FundCode.IsNullOrEmpty() && Model.SourceItem.FundCode.Equals(item.Value) ? "selected" : String.Empty) @dataAttributes>@item.Text</option>
                                }
                            </select>
                        </td>
                        <td colspan="3">
                            @Html.TextBoxFor(m => m.SourceItem.AccountReference, new { @placeholder = "Enter account reference", @class = "form-control", @maxlength = 32 })
                            @Html.ValidationMessageFor(x => x.SourceItem.AccountReference)
                        </td>
                        <td>
                            <select id="SourceItem_VatCode" name="SourceItem_VatCode" aria-labelledby="SourceVatCode">
                                <option value="">None</option>
                                @foreach (var item in Model.VatCodes.Items)
                                {
                                    <option class="item" value="@item.Value" @(Model.SourceItem != null && !Model.SourceItem.VatCode.IsNullOrEmpty() && Model.SourceItem.VatCode.Equals(item.Value) ? "selected" : String.Empty)>@item.Text</option>
                                }
                            </select>
                        </td>
                        <td>
                            @Html.TextBoxFor(m => m.SourceItem.Amount, null, new { @placeholder = "0.00", @class = "form-control monetary-amount" })
                            @Html.ValidationMessageFor(x => x.SourceItem.Amount)
                        </td>
                        <td class="text-end">
                            <button class="btn btn-primary add-source">Add</button>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>

    <div class="text-center mb-3">
        <i class="icon fa fa-long-arrow-down fa-5x"></i>
    </div>

    <div class="alert alert-info mb-3">
        <div class="fw-bold pb-1">
            Remaining balance
        </div>
        <p class="mb-0">You still have <strong id="amount-available-to-transfer">£0.00</strong> left to allocate</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 target transaction
        </div>
        <p id="transfer-message-text" class="mb-0 transfer-message-text"></p>
    </div>

    <div class="border rounded p-2 mb-3">
        <h3>Target transactions</h3>
        <div class="table-responsive-sm">
            <table id="transfer-table" class="table table-striped table-bordered mt-2">
                <thead>
                    <tr>
                        <th scope="col" id="TransferItemFundCode">Fund type</th>
                        <th scope="col">Account</th>
                        <th scope="col">Name</th>
                        <th scope="col">Outstanding balance (£)</th>
                        <th scope="col" id="TransferItemVatCode">VAT code</th>
                        <th scope="col">Amount (£)</th>
                        <th scope="col">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.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>

    <div class="text-center">
        <button type="submit" class="btn btn-success submit-transfer" disabled="true">Complete transfer</button>
    </div>

</div>

@section Scripts {
    @Scripts.Render("~/bundles/app/transfer")
}