mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
* Improve receipt info display Displays the info in correct order and adds optional info if tip was given with a percentage. * Test fix --------- Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
115 lines
4.6 KiB
Text
115 lines
4.6 KiB
Text
@model (Dictionary<string, object> Items, int Level)
|
|
|
|
@functions {
|
|
private bool IsValidURL(string source)
|
|
{
|
|
return Uri.TryCreate(source, UriKind.Absolute, out var uriResult) &&
|
|
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
|
|
}
|
|
}
|
|
|
|
@if (Model.Items.Any())
|
|
{
|
|
var hasCart = Model.Items.ContainsKey("Cart");
|
|
<table class="table my-0" v-pre>
|
|
@if (hasCart || (Model.Items.ContainsKey("Subtotal") && Model.Items.ContainsKey("Total")))
|
|
{
|
|
@if (hasCart)
|
|
{
|
|
<tbody>
|
|
@foreach (var (key, value) in (Dictionary<string, object>)Model.Items["Cart"])
|
|
{
|
|
<tr>
|
|
<th>@key</th>
|
|
<td class="text-end">@value</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
}
|
|
<tfoot style="border-top-width:@(hasCart ? "3px" : "0")">
|
|
@if (Model.Items.ContainsKey("Subtotal"))
|
|
{
|
|
<tr>
|
|
<th>Subtotal</th>
|
|
<td class="text-end">@Model.Items["Subtotal"]</td>
|
|
</tr>
|
|
}
|
|
@if (Model.Items.ContainsKey("Discount"))
|
|
{
|
|
<tr>
|
|
<th>Discount</th>
|
|
<td class="text-end">@Model.Items["Discount"]</td>
|
|
</tr>
|
|
}
|
|
@if (Model.Items.ContainsKey("Tip"))
|
|
{
|
|
<tr>
|
|
<th>Tip</th>
|
|
<td class="text-end">@Model.Items["Tip"]</td>
|
|
</tr>
|
|
}
|
|
@if (Model.Items.ContainsKey("Total"))
|
|
{
|
|
<tr style="border-top-width:3px">
|
|
<th>Total</th>
|
|
<td class="text-end">@Model.Items["Total"]</td>
|
|
</tr>
|
|
}
|
|
</tfoot>
|
|
}
|
|
else
|
|
{
|
|
foreach (var (key, value) in Model.Items)
|
|
{
|
|
<tr>
|
|
@if (value is string str)
|
|
{
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
<th>@key</th>
|
|
}
|
|
<td style="white-space:pre-wrap">@* Explicitely remove whitespace at front here *@@if (IsValidURL(str)){<a href="@str" target="_blank" rel="noreferrer noopener">@str</a>}else {@str.Trim()}</td>
|
|
}
|
|
else if (value is Dictionary<string, object> { Count: > 0 } subItems)
|
|
{
|
|
<td colspan="2">
|
|
@{
|
|
@if (!string.IsNullOrEmpty(key))
|
|
{
|
|
Write(Html.Raw($"<h{Model.Level + 3} class=\"mb-3 fw-semibold\">"));
|
|
Write(key);
|
|
Write(Html.Raw($"</h{Model.Level + 3}>"));
|
|
}
|
|
}
|
|
<partial name="PosData" model="@((subItems, Model.Level + 1))" />
|
|
</td>
|
|
}
|
|
else if (value is IEnumerable<object> valueArray)
|
|
{
|
|
<td colspan="2">
|
|
@{
|
|
@if (!string.IsNullOrEmpty(key))
|
|
{
|
|
Write(Html.Raw($"<h{Model.Level + 3} class=\"mb-3 fw-semibold\">"));
|
|
Write(key);
|
|
Write(Html.Raw($"</h{Model.Level + 3}>"));
|
|
}
|
|
}
|
|
@foreach (var item in valueArray)
|
|
{
|
|
@if (item is Dictionary<string, object> { Count: > 0 } subItems2)
|
|
{
|
|
<partial name="PosData" model="@((subItems2, Model.Level + 1))" />
|
|
}
|
|
else
|
|
{
|
|
<partial name="PosData" model="@((new Dictionary<string, object> { { "", item } }, Model.Level + 1))" />
|
|
}
|
|
}
|
|
</td>
|
|
}
|
|
</tr>
|
|
}
|
|
}
|
|
</table>
|
|
}
|