Files
OneForMe/Views/Order/Join.cshtml

151 lines
6.7 KiB
Plaintext

@model OneForMe.Models.Order
@{
ViewData["Title"] = "Join Order";
}
<div class="container mt-5">
<div class="row">
<div class="col-md-8">
<div class="card shadow mb-4">
<div class="card-body">
<h2>@Model.CreatorName</h2>
<p class="text-muted">Order Code: <strong>@Model.OrderCode</strong></p>
<p>Created by: <strong>@Model.CreatorName</strong></p>
</div>
</div>
<div class="card shadow mb-4">
<div class="card-header bg-primary text-white">
<h5 class="mb-0">Available Items</h5>
</div>
<div class="card-body">
@if (Model.MenuItems.Any())
{
<form method="post" action="/order/additem">
<input type="hidden" name="orderId" value="@Model.Id">
<div class="mb-3">
<label for="participantName" class="form-label">Your Name</label>
<input type="text" class="form-control" id="participantName" name="participantName" placeholder="Enter your name" required>
</div>
<div class="mb-3">
<label for="participantEmail" class="form-label">Your Email (optional)</label>
<input type="email" class="form-control" id="participantEmail" name="participantEmail" placeholder="Enter your email">
</div>
<div class="mb-3">
<label for="menuItemId" class="form-label">Select Item</label>
<select class="form-select" id="menuItemId" name="menuItemId" required onchange="updatePrice()">
<option value="">-- Choose an item --</option>
@foreach (var item in Model.MenuItems)
{
<option value="@item.Id" data-price="@item.Price.ToString("F2")">@item.Name - $@item.Price.ToString("F2")</option>
}
</select>
</div>
<div class="mb-3">
<label for="quantity" class="form-label">Quantity</label>
<input type="number" class="form-control" id="quantity" name="quantity" value="1" min="1" required>
</div>
<div class="alert alert-info">
<strong>Total:</strong> $<span id="totalPrice">0.00</span>
</div>
<button type="submit" class="btn btn-success">Add to Order</button>
<a href="/Home/Dashboard" class="btn btn-secondary">Back to Dashboard</a>
</form>
}
else
{
<p class="text-muted">No items available for this order</p>
}
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow mb-4">
<div class="card-header bg-info text-white">
<h5 class="mb-0">Current Orders (@Model.OrderItems.Count)</h5>
</div>
<div class="card-body">
@if (Model.OrderItems.Any())
{
<table class="table table-sm table-hover">
<thead>
<tr>
<th>Name</th>
<th>Item</th>
<th>Qty</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@foreach (var orderItem in Model.OrderItems)
{
<tr>
<td>@orderItem.ParticipantName</td>
<td>@orderItem.MenuItem?.Name</td>
<td>@orderItem.Quantity</td>
<td>$@(orderItem.MenuItem?.Price * orderItem.Quantity ?? 0).ToString("F2")</td>
</tr>
}
</tbody>
</table>
<hr>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<tr>
<th>Person</th>
<th>Owes</th>
</tr>
</thead>
<tbody>
@foreach (var person in Model.OrderItems.GroupBy(oi => oi.ParticipantName))
{
<tr>
<td>@person.Key</td>
<td>$@person.Sum(oi => oi.MenuItem.Price * oi.Quantity).ToString("F2")</td>
</tr>
}
</tbody>
</table>
</div>
}
else
{
<p class="text-muted">No one has ordered yet</p>
}
</div>
</div>
<div class="card shadow">
<div class="card-body">
<h5>Order Total</h5>
<h3 class="text-success">$@Model.OrderItems.Sum(oi => oi.MenuItem.Price * oi.Quantity).ToString("F2")</h3>
</div>
</div>
</div>
</div>
</div>
<script>
function updatePrice() {
const select = document.getElementById('menuItemId');
const quantity = document.getElementById('quantity').value;
const selectedOption = select.options[select.selectedIndex];
const price = parseFloat(selectedOption.dataset.price) || 0;
const total = (price * quantity).toFixed(2);
document.getElementById('totalPrice').textContent = total;
}
document.getElementById('quantity').addEventListener('change', updatePrice);
document.getElementById('menuItemId').addEventListener('change', updatePrice);
</script>