LocalGovIMS_localgov-ims/src/Admin/Views/Transaction/Receipt.cshtml
@using Microsoft.Ajax.Utilities
@model Admin.Models.Transaction.DetailsViewModel
@{
    ViewBag.Title = "Transaction receipt";
    Layout = "~/Views/Shared/_PrintLayout.cshtml";
}

@section Header { @Model.Transaction.PspReference }

@section Subheader { Payment receipt }

@section Logo {
    <img style="max-height: 75px; max-width: 200px;" src="@(System.Configuration.ConfigurationManager.AppSettings["Organisation.Logo.Printable"])" alt="@(System.Configuration.ConfigurationManager.AppSettings["Organisation.ShortName"]) logo" />
}

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

<div>
    
    <div class="p-3">
        
        <div class="row">
            <div class="col col-3 p-2">
                @Html.Label("Date", new { @class = "form-label fw-bold" })
                <div class="form-label">
                    @Html.DisplayFor(m => m.Transaction.EntryDate, new { @class = "form-label mb-0" })
                </div>
            </div>
            <div class="col col-4 offset-5 p-2">
                @if (!Model.Transaction.AddressLine1.IsNullOrWhiteSpace())
                {
                    @Html.Label("Address", new { @class = "form-label fw-bold" })
                    <br />
                    @Html.Raw(Model.Transaction.FormattedAddress.Replace(",", ",<br />"))
                }
            </div>
        </div>
    
        <div class="row border mt-3">
            <div class="col col-8 p-2 fw-bold border-end">
                Description
            </div>
            <div class="col col-2 p-2 fw-bold border-end">
                VAT Rate
            </div>
            <div class="col col-2 p-2 fw-bold">
                Amount (£)
            </div>
        </div>

        @{
            var vatTotals = new Dictionary<string, decimal>();
        }

        @foreach (var transactionLine in Model.Transaction.TransactionLines)
        {
            <div class="row border border-top-0">
                <div class="col col-8 p-2 border-end">
                    @(transactionLine.Fund != null ? transactionLine.Fund.FundName : "") - @transactionLine.AccountReference
                </div>
                <div class="col col-2 p-2 border-end text-end">
                    @(transactionLine.VatRate * 100)%
                </div>
                <div class="col col-2 p-2 text-end">
                    £@Html.ToCurrency(transactionLine.Amount - transactionLine.VatAmount)

                    @{
                        var vatKey = (transactionLine.VatRate * 100).ToString();
                        if (!vatTotals.ContainsKey(vatKey))
                        {
                            vatTotals.Add(vatKey, 0);
                        }
                        vatTotals[vatKey] = vatTotals[vatKey] + (transactionLine.VatAmount ?? 0);
                    }
                </div>
            </div>
        }

        <div class="row mt-3">
            <div class="col col-8 p-2">
                @Html.Label("VAT Registered Address:", new { @class = "form-label fw-bold" })
                <br />
                @(System.Configuration.ConfigurationManager.AppSettings["Organisation.VatRegisteredAddress.AddressLine1"])
                <br />
                @(System.Configuration.ConfigurationManager.AppSettings["Organisation.VatRegisteredAddress.AddressLine2"])
                <br />
                @(System.Configuration.ConfigurationManager.AppSettings["Organisation.VatRegisteredAddress.AddressLine3"])
                <br />
                @(System.Configuration.ConfigurationManager.AppSettings["Organisation.VatRegisteredAddress.PostCode"])
                <br />
                @Html.Label("VAT Numbesr: ", new { @class = "form-label fw-bold mt-2" })
                @(System.Configuration.ConfigurationManager.AppSettings["Organisation.VatNumber"])
            </div>
            <div class="col col-4">
                <div class="row border">
                    <div class="col col-6 p-2 border-end fw-bold">
                        Sub Total
                    </div>
                    <div class="col col-6 p-2 text-end">
                        £@(Model.Transaction.Total - Model.Transaction.TotalVat)
                    </div>
                </div>
                @foreach (var vatRow in vatTotals)
                {
                    <div class="row border border-top-0">
                        <div class="col col-6 p-2 border-end fw-bold">
                            VAT (@vatRow.Key%)
                        </div>
                        <div class="col col-6 p-2 text-end">
                            £@Html.ToCurrency(vatRow.Value)
                        </div>
                    </div>
                }
                <div class="row border border-top-0">
                    <div class="col col-6 p-2 border-end fw-bold">
                        Total
                    </div>
                    <div class="col col-6 p-2 text-end">
                        £@Model.Transaction.Total
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
