LocalGovIMS_localgov-ims/src/Admin/Views/Transaction/Details.cshtml
@using Microsoft.Ajax.Utilities
@model Admin.Models.Transaction.DetailsViewModel
@{
    ViewBag.Title = "Transaction";
}

@section Messages {
    @if (TempData.ContainsKey("Message") && TempData["Message"] != null) { Html.RenderPartial("_Message", TempData["Message"]); }
}

@section Header { @Model.Transaction.PspReference }

@section Subheader { Transaction details }

@section Actions {
    @if (!string.IsNullOrEmpty(Model.Transaction.ParentPspReference))
    {
        @Html.ActionLink("Origin", "Origin", new { id = Model.Transaction.ParentPspReference }, new { @class = "btn btn-warning" })
    }

    @if (Model.Transaction.SuspenseId.HasValue)
    {
        @Html.ActionLink("View suspense", "Details", "Suspense", new { id = Model.Transaction.SuspenseId }, new { @class = "btn btn-warning" })
    }

    @if (User.IsInRole(Role.TransactionRefund) && Model.IsRefund == false)
    {
        if (Model.Transaction.RefundEnabled)
        {
            <button id="refund" type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#refundModal">
                Refund
            </button>
        }
        else
        {
            <div class="btn btn-danger" disabled="disabled" data-tooltip="A refund is already in progress" data-position="left center">
                Refund
            </div>
        }
    }

    <button id="email-receipt" type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#emailReceiptModal">
        Email receipt
    </button>

    <a href="@Url.Action("Receipt", new {id = Model.Transaction.PspReference })" 
       onclick="window.open(this.href).print(); return false"
       class="btn btn-secondary">Print receipt</a>

}

@Html.HiddenFor(m => m.Transaction.PspReference)

<div class="mb-3">
    @Html.Partial("_Header", Model)
</div>

<div class="d-flex flex-wrap mb-3">
    <div class="me-auto p-0">
        <h3>
            Payments
        </h3>
    </div>
</div>

<div class="mb-3">
    @Html.Partial("_PaymentsList", Model)
</div>

@if (Model.Transaction.CreditNotes.Any())
{
    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h3>
                Credit Notes
            </h3>
        </div>
    </div>

    @Html.Partial("_CreditNoteList", Model)
}

@if (Model.Transaction.ProcessedRefunds.Any() || Model.Transaction.PendingRefunds.Any() || Model.Transaction.FailedRefunds.Any())
{
    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h3>
                Refunds
            </h3>
        </div>
    </div>

    @Html.Partial("_RefundList", Model)
}

@if (Model.Transaction.Transfers.Any())
{
    <div class="d-flex flex-wrap mb-3">
        <div class="me-auto p-0">
            <h3>
                Journals
            </h3>
        </div>
    </div>

    @Html.Partial("_TransferList", Model)

}

@{ Html.RenderPartial("_EmailReceipt", new Admin.Models.Transaction.EmailReceiptViewModel()); }

@if (User.IsInRole(Role.TransactionRefund) && Model.Transaction.RefundEnabled)
{
    Html.RenderPartial("_Refund", Model.Refund);
}

@if (User.IsInRole(Role.TransactionJournal))
{
    <div id="transfer-details">
        @Html.Action("_Transfer", new { id = Model.Transaction.PspReference })
    </div>
}

@Html.ActionLink("Back", "Back", "Transaction", null, new { @class = "btn btn-secondary" })

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

    <script type="text/javascript">
        $(document).ready(function () {
            transcationDetails.mainPspReference = '@Model.Transaction.PspReference';
        });
    </script>
}
