Files
orion/app/templates/admin/orders.html
Samir Boulahtit 6c6b5d259d feat: add admin orders management
- Add admin API endpoints for order management
- Add orders page with vendor selector and filtering
- Add order schemas for admin operations
- Support order status tracking and management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 21:05:27 +01:00

441 lines
21 KiB
HTML

{# app/templates/admin/orders.html #}
{% extends "admin/base.html" %}
{% from 'shared/macros/pagination.html' import pagination %}
{% from 'shared/macros/headers.html' import page_header %}
{% from 'shared/macros/alerts.html' import loading_state, error_state %}
{% from 'shared/macros/tables.html' import table_wrapper %}
{% from 'shared/macros/modals.html' import modal_simple %}
{% from 'shared/macros/inputs.html' import vendor_selector %}
{% block title %}Orders{% endblock %}
{% block alpine_data %}adminOrders(){% endblock %}
{% block content %}
{{ page_header('Orders', subtitle='Manage orders across all vendors') }}
{{ loading_state('Loading orders...') }}
{{ error_state('Error loading orders') }}
<!-- Stats Cards -->
<div x-show="!loading" class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
<!-- Card: Total Orders -->
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="p-3 mr-4 text-purple-500 bg-purple-100 rounded-full dark:text-purple-100 dark:bg-purple-500">
<span x-html="$icon('clipboard-list', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
Total Orders
</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.total_orders || 0">
0
</p>
</div>
</div>
<!-- Card: Pending -->
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="p-3 mr-4 text-orange-500 bg-orange-100 rounded-full dark:text-orange-100 dark:bg-orange-500">
<span x-html="$icon('clock', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
Pending
</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.pending_orders || 0">
0
</p>
</div>
</div>
<!-- Card: Processing -->
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="p-3 mr-4 text-blue-500 bg-blue-100 rounded-full dark:text-blue-100 dark:bg-blue-500">
<span x-html="$icon('refresh', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
Processing
</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.processing_orders || 0">
0
</p>
</div>
</div>
<!-- Card: Revenue -->
<div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="p-3 mr-4 text-green-500 bg-green-100 rounded-full dark:text-green-100 dark:bg-green-500">
<span x-html="$icon('currency-euro', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
Total Revenue
</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="formatPrice(stats.total_revenue || 0)">
0
</p>
</div>
</div>
</div>
<!-- Search and Filters Bar -->
<div x-show="!loading" class="mb-6 p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4">
<!-- Search Input -->
<div class="flex-1 max-w-xl">
<div class="relative">
<span class="absolute inset-y-0 left-0 flex items-center pl-3">
<span x-html="$icon('search', 'w-5 h-5 text-gray-400')"></span>
</span>
<input
type="text"
x-model="filters.search"
@input="debouncedSearch()"
placeholder="Search by order number or customer..."
class="w-full pl-10 pr-4 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none dark:bg-gray-700 dark:text-gray-300"
>
</div>
</div>
<!-- Filters -->
<div class="flex flex-wrap gap-3">
<!-- Vendor Filter (Tom Select) -->
{{ vendor_selector(
ref_name='vendorSelect',
id='orders-vendor-select',
placeholder='Filter by vendor...',
width='w-64'
) }}
<!-- Status Filter -->
<select
x-model="filters.status"
@change="pagination.page = 1; loadOrders()"
class="px-4 py-2 text-sm text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none"
>
<option value="">All Statuses</option>
<option value="pending">Pending</option>
<option value="processing">Processing</option>
<option value="shipped">Shipped</option>
<option value="delivered">Delivered</option>
<option value="cancelled">Cancelled</option>
<option value="refunded">Refunded</option>
</select>
<!-- Channel Filter -->
<select
x-model="filters.channel"
@change="pagination.page = 1; loadOrders()"
class="px-4 py-2 text-sm text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none"
>
<option value="">All Channels</option>
<option value="direct">Direct</option>
<option value="letzshop">Letzshop</option>
</select>
<!-- Refresh Button -->
<button
@click="refresh()"
class="flex items-center px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none transition-colors"
title="Refresh orders"
>
<span x-html="$icon('refresh', 'w-4 h-4 mr-2')"></span>
Refresh
</button>
</div>
</div>
</div>
<!-- Orders Table with Pagination -->
<div x-show="!loading">
{% call table_wrapper() %}
<thead>
<tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800">
<th class="px-4 py-3">Order</th>
<th class="px-4 py-3">Customer</th>
<th class="px-4 py-3">Vendor</th>
<th class="px-4 py-3">Channel</th>
<th class="px-4 py-3 text-right">Total</th>
<th class="px-4 py-3">Status</th>
<th class="px-4 py-3">Date</th>
<th class="px-4 py-3">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
<!-- Empty State -->
<template x-if="orders.length === 0">
<tr>
<td colspan="8" class="px-4 py-8 text-center text-gray-600 dark:text-gray-400">
<div class="flex flex-col items-center">
<span x-html="$icon('clipboard-list', 'w-12 h-12 mb-2 text-gray-300')"></span>
<p class="font-medium">No orders found</p>
<p class="text-xs mt-1" x-text="filters.search || filters.vendor_id || filters.status || filters.channel ? 'Try adjusting your filters' : 'Orders will appear here when customers place orders'"></p>
</div>
</td>
</tr>
</template>
<!-- Order Rows -->
<template x-for="order in orders" :key="order.id">
<tr class="text-gray-700 dark:text-gray-400">
<!-- Order Info -->
<td class="px-4 py-3">
<div>
<p class="font-semibold text-sm font-mono" x-text="order.order_number"></p>
<p class="text-xs text-gray-500" x-text="order.item_count + ' item(s)'"></p>
</div>
</td>
<!-- Customer Info -->
<td class="px-4 py-3 text-sm">
<p class="font-medium" x-text="order.customer_name || 'Guest'"></p>
<p class="text-xs text-gray-500 dark:text-gray-400 truncate max-w-[150px]" x-text="order.customer_email || '-'"></p>
</td>
<!-- Vendor Info -->
<td class="px-4 py-3 text-sm">
<p class="font-medium" x-text="order.vendor_name || 'Unknown'"></p>
<p class="text-xs text-gray-500 dark:text-gray-400 font-mono" x-text="order.vendor_code || ''"></p>
</td>
<!-- Channel -->
<td class="px-4 py-3 text-sm">
<span class="px-2 py-1 text-xs font-medium rounded-full"
:class="order.channel === 'letzshop' ? 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400' : 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300'"
x-text="order.channel"></span>
</td>
<!-- Total -->
<td class="px-4 py-3 text-sm text-right font-mono font-semibold">
<span x-text="formatPrice(order.total_amount, order.currency)"></span>
</td>
<!-- Status -->
<td class="px-4 py-3 text-sm">
<span class="px-2 py-1 font-semibold leading-tight rounded-full text-xs"
:class="getStatusClass(order.status)"
x-text="order.status"></span>
</td>
<!-- Date -->
<td class="px-4 py-3 text-sm">
<p x-text="formatDate(order.created_at)"></p>
<p class="text-xs text-gray-500" x-text="formatTime(order.created_at)"></p>
</td>
<!-- Actions -->
<td class="px-4 py-3 text-sm">
<div class="flex items-center space-x-2">
<button
@click="viewOrder(order)"
class="flex items-center justify-center px-2 py-1 text-xs font-medium leading-5 text-purple-600 rounded-lg dark:text-purple-400 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700"
title="View Details"
>
<span x-html="$icon('eye', 'w-4 h-4')"></span>
</button>
<button
@click="openStatusModal(order)"
class="flex items-center justify-center px-2 py-1 text-xs font-medium leading-5 text-blue-600 rounded-lg dark:text-blue-400 focus:outline-none hover:bg-gray-100 dark:hover:bg-gray-700"
title="Update Status"
>
<span x-html="$icon('pencil', 'w-4 h-4')"></span>
</button>
</div>
</td>
</tr>
</template>
</tbody>
{% endcall %}
{{ pagination(show_condition="!loading && pagination.total > 0") }}
</div>
<!-- Update Status Modal -->
{% call modal_simple('updateStatusModal', 'Update Order Status', show_var='showStatusModal', size='sm') %}
<div class="space-y-4">
<div class="text-sm text-gray-600 dark:text-gray-400">
<p class="font-medium text-gray-700 dark:text-gray-300">Order: <span x-text="selectedOrder?.order_number"></span></p>
<p class="text-xs">Current Status: <span class="font-medium" x-text="selectedOrder?.status"></span></p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
New Status
</label>
<select
x-model="statusForm.status"
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none dark:bg-gray-700 dark:text-gray-300"
>
<option value="pending">Pending</option>
<option value="processing">Processing</option>
<option value="shipped">Shipped</option>
<option value="delivered">Delivered</option>
<option value="cancelled">Cancelled</option>
<option value="refunded">Refunded</option>
</select>
</div>
<div x-show="statusForm.status === 'shipped'">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Tracking Number
</label>
<input
type="text"
x-model="statusForm.tracking_number"
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none dark:bg-gray-700 dark:text-gray-300"
placeholder="Enter tracking number"
>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
Reason (optional)
</label>
<input
type="text"
x-model="statusForm.reason"
class="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg focus:border-purple-400 focus:outline-none dark:bg-gray-700 dark:text-gray-300"
placeholder="e.g., Customer requested cancellation"
>
</div>
<div class="flex items-center justify-end gap-3 pt-4 border-t border-gray-200 dark:border-gray-700">
<button
@click="showStatusModal = false"
class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-600 transition-colors"
>
Cancel
</button>
<button
@click="updateStatus()"
:disabled="saving || statusForm.status === selectedOrder?.status"
class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700 transition-colors disabled:opacity-50"
>
<span x-text="saving ? 'Updating...' : 'Update Status'"></span>
</button>
</div>
</div>
{% endcall %}
<!-- Order Detail Modal -->
{% call modal_simple('orderDetailModal', 'Order Details', show_var='showDetailModal', size='lg') %}
<div x-show="selectedOrderDetail" class="space-y-4">
<!-- Order Header -->
<div class="flex items-center justify-between pb-4 border-b border-gray-200 dark:border-gray-700">
<div>
<p class="text-lg font-semibold text-gray-800 dark:text-gray-200" x-text="selectedOrderDetail?.order_number"></p>
<p class="text-sm text-gray-500" x-text="formatDateTime(selectedOrderDetail?.created_at)"></p>
</div>
<span class="px-3 py-1 text-sm font-semibold rounded-full"
:class="getStatusClass(selectedOrderDetail?.status)"
x-text="selectedOrderDetail?.status"></span>
</div>
<!-- Customer & Vendor Info -->
<div class="grid grid-cols-2 gap-4">
<div>
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase">Customer</p>
<p class="text-sm font-medium text-gray-800 dark:text-gray-200" x-text="selectedOrderDetail?.customer?.first_name + ' ' + selectedOrderDetail?.customer?.last_name"></p>
<p class="text-xs text-gray-500" x-text="selectedOrderDetail?.customer?.email"></p>
</div>
<div>
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase">Vendor</p>
<p class="text-sm font-medium text-gray-800 dark:text-gray-200" x-text="selectedOrderDetail?.vendor?.name"></p>
<p class="text-xs text-gray-500 font-mono" x-text="selectedOrderDetail?.vendor?.vendor_code"></p>
</div>
</div>
<!-- Items -->
<div>
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase mb-2">Items</p>
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg overflow-hidden">
<template x-for="item in selectedOrderDetail?.items || []" :key="item.id">
<div class="flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-gray-600 last:border-0">
<div>
<p class="text-sm font-medium text-gray-800 dark:text-gray-200" x-text="item.product_name"></p>
<p class="text-xs text-gray-500" x-text="'SKU: ' + (item.product_sku || '-')"></p>
</div>
<div class="text-right">
<p class="text-sm font-medium text-gray-800 dark:text-gray-200" x-text="formatPrice(item.total_price)"></p>
<p class="text-xs text-gray-500" x-text="item.quantity + ' x ' + formatPrice(item.unit_price)"></p>
</div>
</div>
</template>
</div>
</div>
<!-- Totals -->
<div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4">
<div class="flex justify-between text-sm mb-1">
<span class="text-gray-600 dark:text-gray-400">Subtotal</span>
<span x-text="formatPrice(selectedOrderDetail?.subtotal)"></span>
</div>
<div class="flex justify-between text-sm mb-1">
<span class="text-gray-600 dark:text-gray-400">Tax</span>
<span x-text="formatPrice(selectedOrderDetail?.tax_amount)"></span>
</div>
<div class="flex justify-between text-sm mb-1">
<span class="text-gray-600 dark:text-gray-400">Shipping</span>
<span x-text="formatPrice(selectedOrderDetail?.shipping_amount)"></span>
</div>
<template x-if="selectedOrderDetail?.discount_amount > 0">
<div class="flex justify-between text-sm mb-1 text-green-600">
<span>Discount</span>
<span x-text="'-' + formatPrice(selectedOrderDetail?.discount_amount)"></span>
</div>
</template>
<div class="flex justify-between text-sm font-semibold pt-2 border-t border-gray-200 dark:border-gray-600">
<span>Total</span>
<span x-text="formatPrice(selectedOrderDetail?.total_amount, selectedOrderDetail?.currency)"></span>
</div>
</div>
<!-- Shipping Address -->
<div x-show="selectedOrderDetail?.shipping_address">
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase mb-2">Shipping Address</p>
<div class="text-sm text-gray-700 dark:text-gray-300">
<p x-text="selectedOrderDetail?.shipping_address?.first_name + ' ' + selectedOrderDetail?.shipping_address?.last_name"></p>
<p x-text="selectedOrderDetail?.shipping_address?.address_line_1"></p>
<p x-show="selectedOrderDetail?.shipping_address?.address_line_2" x-text="selectedOrderDetail?.shipping_address?.address_line_2"></p>
<p x-text="selectedOrderDetail?.shipping_address?.postal_code + ' ' + selectedOrderDetail?.shipping_address?.city"></p>
<p x-text="selectedOrderDetail?.shipping_address?.country"></p>
</div>
</div>
<!-- Tracking Info -->
<div x-show="selectedOrderDetail?.tracking_number">
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase mb-1">Tracking Number</p>
<p class="text-sm font-mono text-gray-800 dark:text-gray-200" x-text="selectedOrderDetail?.tracking_number"></p>
</div>
<!-- Notes -->
<div x-show="selectedOrderDetail?.internal_notes">
<p class="text-xs font-medium text-gray-500 dark:text-gray-400 uppercase mb-1">Internal Notes</p>
<p class="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap" x-text="selectedOrderDetail?.internal_notes"></p>
</div>
<div class="flex items-center justify-end gap-3 pt-4 border-t border-gray-200 dark:border-gray-700">
<button
@click="showDetailModal = false"
class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-600 transition-colors"
>
Close
</button>
<button
@click="showDetailModal = false; openStatusModal(selectedOrderDetail)"
class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-lg hover:bg-purple-700 transition-colors"
>
Update Status
</button>
</div>
</div>
{% endcall %}
{% endblock %}
{% block extra_scripts %}
<script src="{{ url_for('static', path='admin/js/orders.js') }}"></script>
{% endblock %}