LocalGovIMS_localgov-ims/src/Admin/Views/Suspense/_CreditNote.cshtml
@model Admin.Models.Suspense.JournalViewModel

@if (User.IsInRole(Role.Finance))
{
    <div class="modal fade modal-lg" id="creditNoteModal" tabindex="-1" aria-labelledby="creditNoteModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="creditNoteModalLabel">Credit notes</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">You have <strong><span id="amount-available-to-credit">0</span></strong> worth of credit notes added</p>
                    </div>

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

                    <div class="table-responsive-xl">
                        <table id="credit-table" class="table table-striped table-bordered mt-2">
                            <thead>
                                <tr>
                                    <th scope="col" id="CreditNoteFundCode" style="min-width:150px;">Fund type</th>
                                    <th scope="col">Account</th>
                                    <th scope="col" id="CreditNoteVatCode" style="min-width:150px;">VAT code</th>
                                    <th scope="col">Amount (£)</th>
                                    <th scope="col"><span class="visually-hidden">Actions</span></th>
                                </tr>
                            </thead>
                            <tbody id="credit-table-body"></tbody>
                            <tfoot>
                                <tr>
                                    <td>
                                        @Html.Label("CreditNote_FundCode", "Fund type", new { @class = "form-label visually-hidden" })
                                        <select id="CreditNote_FundCode" name="CreditNote_FundCode" aria-labelledby="CreditNoteFundCode">
                                            <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.CreditNote != null && !Model.CreditNote.FundCode.IsNullOrEmpty() && Model.CreditNote.FundCode.Equals(item.Value) ? "selected" : String.Empty) @dataAttributes>@item.Text</option>
                                            }
                                        </select>
                                    </td>
                                    <td>
                                        @Html.TextBoxFor(m => m.CreditNote.AccountReference, new { @placeholder = "Enter account reference", @class = "form-control", @maxlength = 32 })
                                        @Html.ValidationMessageFor(x => x.CreditNote.AccountReference)
                                    </td>
                                    <td>
                                        @Html.Label("CreditNote_VatCode", "VAT code", new { @class = "form-label visually-hidden" })
                                        <select id="CreditNote_VatCode" name="CreditNote_VatCode" aria-labelledby="CreditNoteVatCode">
                                            <option value="">None</option>
                                            @foreach (var item in Model.VatCodes.Items)
                                            {
                                                <option class="item" value="@item.Value" @(Model.CreditNote != null && Model.CreditNote.VatCode != null && !Model.CreditNote.VatCode.IsNullOrEmpty() && Model.CreditNote.VatCode.Equals(item.Value) ? "selected" : String.Empty)>@item.Text</option>
                                            }
                                        </select>
                                    </td>
                                    <td>
                                        @Html.TextBoxFor(m => m.CreditNote.Amount, null, new { @placeholder = "0.00", @class = "form-control monetary-amount" })
                                        @Html.ValidationMessageFor(x => x.CreditNote.Amount)
                                    </td>
                                    <td class="text-end">
                                        <button class="btn btn-primary add-credit">Add</button>
                                    </td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>

                    <div class="modal-footer pb-0 pe-0">
                        <button type="button" class="btn btn-secondary" id="clearAllCreditNotes">Clear all</button>
                        <button type="button" class="btn btn-secondary me-0" data-bs-dismiss="modal">Close</button>
                        @*<button type="button" class="btn btn-primary submit-credit" id="submit-credit">Save credit notes</button>*@
                    </div>

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

}
