2024-04-24 10:22:00 +02:00
@using Microsoft.AspNetCore.Mvc.TagHelpers
2022-11-25 02:42:55 +01:00
@model (Dictionary<string, object> Items, int Level)
2023-08-10 14:57:54 +03:00
@if (Model.Items.Any())
2023-04-11 13:21:02 +09:00
{
2024-04-24 10:22:00 +02:00
@* Use titlecase and lowercase versions for backwards-compatibility *@
string[] cartKeys = ["cart", "subtotal", "discount", "tip", "total"];
2023-05-08 11:02:13 +02:00
<table class="table my-0" v-pre>
2024-04-24 10:22:00 +02:00
@if (Model.Items.Keys.Any(key => cartKeys.Contains(key.ToLowerInvariant())))
2023-05-08 11:02:13 +02:00
{
2024-04-24 10:22:00 +02:00
_ = Model.Items.TryGetValue("cart", out var cart) || Model.Items.TryGetValue("Cart", out cart);
var hasTotal = Model.Items.TryGetValue("total", out var total) || Model.Items.TryGetValue("Total", out total);
var hasSubtotal = Model.Items.TryGetValue("subtotal", out var subtotal) || Model.Items.TryGetValue("subTotal", out subtotal) || Model.Items.TryGetValue("Subtotal", out subtotal);
var hasDiscount = Model.Items.TryGetValue("discount", out var discount) || Model.Items.TryGetValue("Discount", out discount);
var hasTip = Model.Items.TryGetValue("tip", out var tip) || Model.Items.TryGetValue("Tip", out tip);
if (cart is Dictionary<string, object> { Keys.Count: > 0 } cartDict)
2023-09-26 15:50:04 +02:00
{
<tbody>
2024-04-24 10:22:00 +02:00
@foreach (var (key, value) in cartDict)
2022-11-25 02:42:55 +01:00
{
2023-08-10 14:57:54 +03:00
<tr>
2024-09-12 04:27:02 +01:00
<partial name="PosDataEntry" model="(key, value, Model.Level)"/>
2023-08-10 14:57:54 +03:00
</tr>
2023-05-08 11:02:13 +02:00
}
2023-09-26 15:50:04 +02:00
</tbody>
}
2024-04-24 10:22:00 +02:00
else if (cart is ICollection<object> { Count: > 0 } cartCollection)
{
<tbody>
@foreach (var value in cartCollection)
2023-08-10 14:57:54 +03:00
{
<tr>
2024-09-12 04:27:02 +01:00
<partial name="PosDataEntry" model="(string.Empty, value, Model.Level)"/>
2023-08-10 14:57:54 +03:00
</tr>
}
2024-04-24 10:22:00 +02:00
</tbody>
}
<tfoot style="border-top-width:0">
@if (hasSubtotal && (hasDiscount || hasTip))
{
<tr style="border-top-width:3px">
<th>Subtotal</th>
<td class="text-end">@subtotal</td>
</tr>
}
@if (hasDiscount)
{
<tr>
<th>Discount</th>
<td class="text-end">@discount</td>
</tr>
}
@if (hasTip)
{
<tr>
<th>Tip</th>
<td class="text-end">@tip</td>
</tr>
}
@if (hasTotal)
{
<tr style="border-top-width:3px">
<th>Total</th>
<td class="text-end">@total</td>
</tr>
}
2023-08-10 14:57:54 +03:00
</tfoot>
}
else
{
foreach (var (key, value) in Model.Items)
{
<tr>
2024-09-12 04:27:02 +01:00
<partial name="PosDataEntry" model="(key, value, Model.Level)"/>
2023-08-10 14:57:54 +03:00
</tr>
}
2023-05-08 11:02:13 +02:00
}
</table>
2023-04-11 13:21:02 +09:00
}