This commit is contained in:
lubiana 2025-05-31 21:43:13 +02:00
parent e958163a4a
commit b8a5a1ff58
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
79 changed files with 15113 additions and 0 deletions

View file

@ -0,0 +1,204 @@
{% extends 'layout.twig' %}
{% import 'components/form.twig' as form %}
{% block title %}Create Order - {{ parent() }}{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col">
<h2>Create New Order</h2>
</div>
<div class="col-auto">
<div class="btn-group" role="group">
<a href="/orders" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Orders
</a>
<a href="/orders/create-from-stock" class="btn btn-primary">
<i class="fas fa-magic"></i> Create from Stock Levels
</a>
</div>
</div>
</div>
<div class="card">
<div class="card-body">
{{ form.errors(error) }}
<form action="/orders" method="post" id="orderForm">
<div class="order-items">
<div class="row mb-3">
<div class="col">
<h5>Order Items</h5>
</div>
<div class="col-auto">
<button type="button" class="btn btn-sm btn-success add-item-btn">
<i class="fas fa-plus"></i> Add Item
</button>
</div>
</div>
<div class="order-item-template d-none">
<div class="card mb-3 order-item">
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Drink Type</label>
<select name="items[{index}][drink_type_id]" class="form-control drink-type-select" required>
<option value="">-- Select Drink Type --</option>
{% for drinkType in drinkTypes %}
<option value="{{ drinkType.id }}" data-desired-stock="{{ drinkType.desiredStock }}" data-current-stock="{{ drinkType.currentStock|default(0) }}">
{{ drinkType.name }}
</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label>Quantity</label>
<input type="number" name="items[{index}][quantity]" class="form-control quantity-input" min="1" required>
<small class="form-text text-muted stock-info"></small>
</div>
</div>
<div class="col-md-1 d-flex align-items-end">
<button type="button" class="btn btn-sm btn-danger remove-item-btn mb-2">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="order-items-container">
<!-- Order items will be added here -->
<div class="card mb-3 order-item">
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Drink Type</label>
<select name="items[0][drink_type_id]" class="form-control drink-type-select" required>
<option value="">-- Select Drink Type --</option>
{% for drinkType in drinkTypes %}
<option value="{{ drinkType.id }}" data-desired-stock="{{ drinkType.desiredStock }}" data-current-stock="{{ drinkType.currentStock|default(0) }}">
{{ drinkType.name }}
</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label>Quantity</label>
<input type="number" name="items[0][quantity]" class="form-control quantity-input" min="1" required>
<small class="form-text text-muted stock-info"></small>
</div>
</div>
<div class="col-md-1 d-flex align-items-end">
<button type="button" class="btn btn-sm btn-danger remove-item-btn mb-2" disabled>
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="alert alert-info d-none no-items-alert">
<i class="fas fa-info-circle"></i> Please add at least one item to the order.
</div>
</div>
<div class="form-group mt-4">
{{ form.submit('Create Order') }}
<a href="/orders" class="btn btn-link">Cancel</a>
</div>
</form>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', function() {
const orderItemsContainer = document.querySelector('.order-items-container');
const orderItemTemplate = document.querySelector('.order-item-template');
const addItemBtn = document.querySelector('.add-item-btn');
const noItemsAlert = document.querySelector('.no-items-alert');
// Add item button click handler
addItemBtn.addEventListener('click', function() {
const newIndex = document.querySelectorAll('.order-item').length;
const newItem = orderItemTemplate.querySelector('.order-item').cloneNode(true);
// Update name attributes with the correct index
newItem.querySelectorAll('[name]').forEach(input => {
input.name = input.name.replace('{index}', newIndex);
});
// Enable the remove button
newItem.querySelector('.remove-item-btn').disabled = false;
// Add the new item to the container
orderItemsContainer.appendChild(newItem);
// Hide the no items alert
noItemsAlert.classList.add('d-none');
// Add event listeners to the new item
addItemEventListeners(newItem);
});
// Add event listeners to initial item
addItemEventListeners(orderItemsContainer.querySelector('.order-item'));
// Form submission handler
document.getElementById('orderForm').addEventListener('submit', function(e) {
const items = document.querySelectorAll('.order-item');
if (items.length === 0) {
e.preventDefault();
noItemsAlert.classList.remove('d-none');
}
});
// Function to add event listeners to an item
function addItemEventListeners(item) {
// Remove item button click handler
item.querySelector('.remove-item-btn').addEventListener('click', function() {
if (document.querySelectorAll('.order-item').length > 1) {
item.remove();
} else {
noItemsAlert.classList.remove('d-none');
}
});
// Drink type select change handler
item.querySelector('.drink-type-select').addEventListener('change', function() {
const option = this.options[this.selectedIndex];
const stockInfo = item.querySelector('.stock-info');
const quantityInput = item.querySelector('.quantity-input');
if (option.value) {
const desiredStock = parseInt(option.dataset.desiredStock);
const currentStock = parseInt(option.dataset.currentStock);
const difference = desiredStock - currentStock;
if (difference > 0) {
stockInfo.textContent = `Current: ${currentStock}, Desired: ${desiredStock}, Suggested order: ${difference}`;
quantityInput.value = difference;
} else {
stockInfo.textContent = `Current: ${currentStock}, Desired: ${desiredStock}, Stock is adequate`;
quantityInput.value = '';
}
} else {
stockInfo.textContent = '';
quantityInput.value = '';
}
});
}
});
</script>
{% endblock %}

179
templates/orders/index.twig Normal file
View file

@ -0,0 +1,179 @@
{% extends 'layout.twig' %}
{% block title %}Orders - {{ parent() }}{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col">
<h2>Orders</h2>
</div>
<div class="col-auto">
<div class="btn-group" role="group">
<a href="/orders/create" class="btn btn-success">
<i class="fas fa-plus"></i> Create Order
</a>
<a href="/orders/create-from-stock" class="btn btn-primary">
<i class="fas fa-magic"></i> Create from Stock Levels
</a>
</div>
</div>
</div>
{% if orders is empty %}
<div class="alert alert-info">
No orders found. Click one of the buttons above to create your first order.
</div>
{% else %}
<div class="card">
<div class="card-header">
<div class="row">
<div class="col">
<h5 class="card-title mb-0">Order List</h5>
</div>
<div class="col-auto">
<div class="dropdown">
<button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="filterDropdown" data-bs-toggle="dropdown" aria-expanded="false">
Filter
</button>
<ul class="dropdown-menu" aria-labelledby="filterDropdown">
<li><a class="dropdown-item" href="/orders">All Orders</a></li>
<li><hr class="dropdown-divider"></li>
<li><h6 class="dropdown-header">By Status</h6></li>
<li><a class="dropdown-item" href="/orders?status=pending">Pending</a></li>
<li><a class="dropdown-item" href="/orders?status=completed">Completed</a></li>
<li><a class="dropdown-item" href="/orders?status=cancelled">Cancelled</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Items</th>
<th>Total Quantity</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for order in orders %}
<tr>
<td>{{ order.id }}</td>
<td>{{ order.createdAt|date('Y-m-d H:i:s') }}</td>
<td>{{ order.orderItems|length }}</td>
<td>
{% set totalQuantity = 0 %}
{% for item in order.orderItems %}
{% set totalQuantity = totalQuantity + item.quantity %}
{% endfor %}
{{ totalQuantity }}
</td>
<td>
{% if order.status == 'pending' %}
<span class="badge bg-warning">Pending</span>
{% elseif order.status == 'completed' %}
<span class="badge bg-success">Completed</span>
{% elseif order.status == 'cancelled' %}
<span class="badge bg-danger">Cancelled</span>
{% else %}
<span class="badge bg-secondary">{{ order.status }}</span>
{% endif %}
</td>
<td>
<div class="btn-group btn-group-sm" role="group">
<a href="/orders/{{ order.id }}" class="btn btn-outline-info">
<i class="fas fa-eye"></i>
</a>
{% if order.status == 'pending' %}
<form action="/orders/{{ order.id }}/status" method="post" class="d-inline">
<input type="hidden" name="status" value="completed">
<button type="submit" class="btn btn-outline-success" title="Mark as Completed">
<i class="fas fa-check"></i>
</button>
</form>
<form action="/orders/{{ order.id }}/status" method="post" class="d-inline">
<input type="hidden" name="status" value="cancelled">
<button type="submit" class="btn btn-outline-danger" title="Cancel Order">
<i class="fas fa-times"></i>
</button>
</form>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="card-footer">
<small class="text-muted">Showing {{ orders|length }} orders</small>
</div>
</div>
<div class="row mt-4">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0">Order Statistics</h5>
</div>
<div class="card-body">
{% set pendingCount = 0 %}
{% set completedCount = 0 %}
{% set cancelledCount = 0 %}
{% for order in orders %}
{% if order.status == 'pending' %}
{% set pendingCount = pendingCount + 1 %}
{% elseif order.status == 'completed' %}
{% set completedCount = completedCount + 1 %}
{% elseif order.status == 'cancelled' %}
{% set cancelledCount = cancelledCount + 1 %}
{% endif %}
{% endfor %}
<div class="mb-3">
<div class="d-flex justify-content-between mb-1">
<span>Pending Orders:</span>
<span class="text-warning">{{ pendingCount }}</span>
</div>
<div class="d-flex justify-content-between mb-1">
<span>Completed Orders:</span>
<span class="text-success">{{ completedCount }}</span>
</div>
<div class="d-flex justify-content-between mb-1">
<span>Cancelled Orders:</span>
<span class="text-danger">{{ cancelledCount }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header bg-primary text-white">
<h5 class="card-title mb-0">Quick Actions</h5>
</div>
<div class="card-body">
<div class="d-grid gap-2">
<a href="/orders/create" class="btn btn-success">
<i class="fas fa-plus"></i> Create New Order
</a>
<a href="/orders/create-from-stock" class="btn btn-primary">
<i class="fas fa-magic"></i> Create Order from Stock Levels
</a>
<a href="/inventory" class="btn btn-info">
<i class="fas fa-boxes"></i> View Inventory
</a>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}

252
templates/orders/show.twig Normal file
View file

@ -0,0 +1,252 @@
{% extends 'layout.twig' %}
{% import 'components/form.twig' as form %}
{% block title %}Order #{{ order.id }} - {{ parent() }}{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col">
<h2>Order #{{ order.id }}</h2>
</div>
<div class="col-auto">
<div class="btn-group" role="group">
<a href="/orders" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Orders
</a>
{% if order.status == 'pending' %}
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#completeOrderModal">
<i class="fas fa-check"></i> Complete Order
</button>
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#cancelOrderModal">
<i class="fas fa-times"></i> Cancel Order
</button>
{% endif %}
</div>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div class="card mb-4">
<div class="card-header">
<h5 class="card-title mb-0">Order Items</h5>
</div>
<div class="card-body">
{% if order.orderItems is empty %}
<div class="alert alert-warning">
<i class="fas fa-exclamation-triangle"></i> This order has no items.
</div>
{% else %}
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Drink Type</th>
<th>Quantity</th>
{% if order.status == 'pending' %}
<th>Actions</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for item in order.orderItems %}
<tr>
<td>
<a href="/drink-types/{{ item.drinkType.id }}">
{{ item.drinkType.name }}
</a>
</td>
<td>{{ item.quantity }}</td>
{% if order.status == 'pending' %}
<td>
<form action="/orders/{{ order.id }}/items/{{ item.id }}/remove" method="post" class="d-inline" onsubmit="return confirm('Are you sure you want to remove this item?');">
<button type="submit" class="btn btn-sm btn-danger">
<i class="fas fa-trash"></i> Remove
</button>
</form>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="table-active">
<th>Total</th>
<th>
{% set totalQuantity = 0 %}
{% for item in order.orderItems %}
{% set totalQuantity = totalQuantity + item.quantity %}
{% endfor %}
{{ totalQuantity }}
</th>
{% if order.status == 'pending' %}
<th></th>
{% endif %}
</tr>
</tfoot>
</table>
</div>
{% endif %}
{% if order.status == 'pending' %}
<div class="mt-4">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addItemModal">
<i class="fas fa-plus"></i> Add Item
</button>
</div>
{% endif %}
</div>
</div>
</div>
<div class="col-md-4">
<div class="card mb-4">
<div class="card-header">
<h5 class="card-title mb-0">Order Details</h5>
</div>
<div class="card-body">
<table class="table table-bordered">
<tr>
<th style="width: 40%">Order ID</th>
<td>{{ order.id }}</td>
</tr>
<tr>
<th>Status</th>
<td>
{% if order.status == 'pending' %}
<span class="badge bg-warning">Pending</span>
{% elseif order.status == 'completed' %}
<span class="badge bg-success">Completed</span>
{% elseif order.status == 'cancelled' %}
<span class="badge bg-danger">Cancelled</span>
{% else %}
<span class="badge bg-secondary">{{ order.status }}</span>
{% endif %}
</td>
</tr>
<tr>
<th>Created At</th>
<td>{{ order.createdAt|date('Y-m-d H:i:s') }}</td>
</tr>
<tr>
<th>Updated At</th>
<td>{{ order.updatedAt|date('Y-m-d H:i:s') }}</td>
</tr>
<tr>
<th>Total Items</th>
<td>{{ order.orderItems|length }}</td>
</tr>
<tr>
<th>Total Quantity</th>
<td>
{% set totalQuantity = 0 %}
{% for item in order.orderItems %}
{% set totalQuantity = totalQuantity + item.quantity %}
{% endfor %}
{{ totalQuantity }}
</td>
</tr>
</table>
</div>
</div>
{% if order.status == 'pending' %}
<div class="card">
<div class="card-header bg-danger text-white">
<h5 class="card-title mb-0">Danger Zone</h5>
</div>
<div class="card-body">
<form action="/orders/{{ order.id }}/delete" method="post" onsubmit="return confirm('Are you sure you want to delete this order? This action cannot be undone.');">
<div class="d-grid">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash"></i> Delete Order
</button>
</div>
</form>
</div>
</div>
{% endif %}
</div>
</div>
{% if order.status == 'pending' %}
<!-- Add Item Modal -->
<div class="modal fade" id="addItemModal" tabindex="-1" aria-labelledby="addItemModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addItemModalLabel">Add Item to Order</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="/orders/{{ order.id }}/items" method="post">
<div class="modal-body">
<div class="form-group mb-3">
<label for="drink_type_id">Drink Type</label>
<select id="drink_type_id" name="drink_type_id" class="form-control" required>
<option value="">-- Select Drink Type --</option>
{% for drinkType in drinkTypes|default([]) %}
<option value="{{ drinkType.id }}">{{ drinkType.name }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" id="quantity" name="quantity" class="form-control" min="1" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Add Item</button>
</div>
</form>
</div>
</div>
</div>
<!-- Complete Order Modal -->
<div class="modal fade" id="completeOrderModal" tabindex="-1" aria-labelledby="completeOrderModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="completeOrderModalLabel">Complete Order</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to mark this order as completed?</p>
<p class="text-muted">This will update the inventory levels accordingly.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<form action="/orders/{{ order.id }}/status" method="post">
<input type="hidden" name="status" value="completed">
<button type="submit" class="btn btn-success">Complete Order</button>
</form>
</div>
</div>
</div>
</div>
<!-- Cancel Order Modal -->
<div class="modal fade" id="cancelOrderModal" tabindex="-1" aria-labelledby="cancelOrderModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="cancelOrderModalLabel">Cancel Order</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to cancel this order?</p>
<p class="text-muted">This action cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No, Keep Order</button>
<form action="/orders/{{ order.id }}/status" method="post">
<input type="hidden" name="status" value="cancelled">
<button type="submit" class="btn btn-danger">Yes, Cancel Order</button>
</form>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}