530 lines
22 KiB
PHP
530 lines
22 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/app.php';
|
||
$user = require_permission('sales', 'show');
|
||
ensure_sales_table();
|
||
|
||
$activeNav = 'eid_orders';
|
||
$pageTitle = tr('طلبات العيد', 'Eid Orders');
|
||
$metaDescription = tr('متابعة طلبات العيد مع الفلاتر والمدى الزمني.', 'Track Eid orders with filters and date range.');
|
||
|
||
$mode = isset($_GET['mode']) && in_array($_GET['mode'], ['pos', 'normal'], true) ? $_GET['mode'] : null;
|
||
$branch = isset($_GET['branch']) && array_key_exists($_GET['branch'], branches()) ? $_GET['branch'] : null;
|
||
$search = trim((string) ($_GET['q'] ?? ''));
|
||
$paymentStatus = trim((string) ($_GET['payment_status'] ?? ''));
|
||
$deliveryStatus = trim((string) ($_GET['delivery_status'] ?? ''));
|
||
$dateFrom = trim((string) ($_GET['date_from'] ?? ''));
|
||
$dateTo = trim((string) ($_GET['date_to'] ?? ''));
|
||
$sort = trim((string) ($_GET['sort'] ?? 'delivery_date'));
|
||
$dir = strtolower(trim((string) ($_GET['dir'] ?? 'asc')));
|
||
$sortMap = [
|
||
'receipt_no' => 'receipt_no',
|
||
'customer' => 'customer_name',
|
||
'branch' => 'branch_code',
|
||
'delivery_date' => 'COALESCE(delivery_date, DATE(sale_date))',
|
||
'delivery_status' => 'delivery_status',
|
||
'item_count' => 'item_count',
|
||
'total_amount' => 'total_amount',
|
||
];
|
||
if (!isset($sortMap[$sort])) {
|
||
$sort = 'delivery_date';
|
||
}
|
||
if (!in_array($dir, ['asc', 'desc'], true)) {
|
||
$dir = 'asc';
|
||
}
|
||
$page = max(1, (int) ($_GET['p'] ?? 1));
|
||
$limit = 15;
|
||
$offset = ($page - 1) * $limit;
|
||
$allowedBranches = $user && $user['role'] !== 'owner' ? get_user_branches($user) : [];
|
||
$deliveryOptions = eid_delivery_status_options();
|
||
$dbError = null;
|
||
$totalPages = 1;
|
||
$orders = [];
|
||
$summary = [
|
||
'total_orders' => 0,
|
||
'total_items' => 0,
|
||
'total_amount' => 0,
|
||
'prep_orders' => 0,
|
||
];
|
||
|
||
try {
|
||
$params = [':order_type' => 'eid'];
|
||
$where = ' WHERE order_type = :order_type ';
|
||
|
||
if ($mode) {
|
||
$where .= ' AND sale_mode = :sale_mode ';
|
||
$params[':sale_mode'] = $mode;
|
||
}
|
||
|
||
if ($branch) {
|
||
$where .= ' AND branch_code = :branch_code ';
|
||
$params[':branch_code'] = $branch;
|
||
}
|
||
|
||
if ($user && $user['role'] !== 'owner') {
|
||
if ($allowedBranches === []) {
|
||
$where .= ' AND 1=0 ';
|
||
} else {
|
||
$namedParams = [];
|
||
foreach ($allowedBranches as $i => $allowedBranch) {
|
||
$key = ':v_branch_' . $i;
|
||
$namedParams[] = $key;
|
||
$params[$key] = $allowedBranch;
|
||
}
|
||
$where .= ' AND branch_code IN (' . implode(', ', $namedParams) . ') ';
|
||
}
|
||
}
|
||
|
||
if ($search !== '') {
|
||
$where .= ' AND (receipt_no LIKE :search OR customer_name LIKE :search OR cashier_name LIKE :search OR notes LIKE :search) ';
|
||
$params[':search'] = '%' . $search . '%';
|
||
}
|
||
|
||
if (in_array($paymentStatus, ['paid', 'partial', 'unpaid'], true)) {
|
||
$where .= ' AND payment_status = :payment_status ';
|
||
$params[':payment_status'] = $paymentStatus;
|
||
}
|
||
|
||
if (isset($deliveryOptions[$deliveryStatus])) {
|
||
$where .= ' AND delivery_status = :delivery_status ';
|
||
$params[':delivery_status'] = $deliveryStatus;
|
||
}
|
||
|
||
if ($dateFrom !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateFrom)) {
|
||
$where .= ' AND DATE(COALESCE(delivery_date, sale_date)) >= :date_from ';
|
||
$params[':date_from'] = $dateFrom;
|
||
} else {
|
||
$dateFrom = '';
|
||
}
|
||
|
||
if ($dateTo !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateTo)) {
|
||
$where .= ' AND DATE(COALESCE(delivery_date, sale_date)) <= :date_to ';
|
||
$params[':date_to'] = $dateTo;
|
||
} else {
|
||
$dateTo = '';
|
||
}
|
||
|
||
$summarySql = "SELECT COUNT(*) AS total_orders, COALESCE(SUM(item_count), 0) AS total_items, COALESCE(SUM(total_amount), 0) AS total_amount, COALESCE(SUM(CASE WHEN delivery_status IN ('pending', 'preparing') THEN 1 ELSE 0 END), 0) AS prep_orders FROM sales_orders" . $where;
|
||
$summaryStmt = db()->prepare($summarySql);
|
||
foreach ($params as $key => $value) {
|
||
$summaryStmt->bindValue($key, $value);
|
||
}
|
||
$summaryStmt->execute();
|
||
$summary = $summaryStmt->fetch() ?: $summary;
|
||
|
||
$countSql = 'SELECT COUNT(*) FROM sales_orders' . $where;
|
||
$countStmt = db()->prepare($countSql);
|
||
foreach ($params as $key => $value) {
|
||
$countStmt->bindValue($key, $value);
|
||
}
|
||
$countStmt->execute();
|
||
$total = (int) $countStmt->fetchColumn();
|
||
$totalPages = max(1, (int) ceil($total / $limit));
|
||
|
||
$primarySort = $sortMap[$sort] . ' ' . strtoupper($dir);
|
||
$secondarySort = $sort === 'delivery_date'
|
||
? ', sale_date DESC'
|
||
: ', COALESCE(delivery_date, DATE(sale_date)) ASC, sale_date DESC';
|
||
|
||
$sql = 'SELECT * FROM sales_orders' . $where . ' ORDER BY ' . $primarySort . $secondarySort . ' LIMIT :limit OFFSET :offset';
|
||
$stmt = db()->prepare($sql);
|
||
foreach ($params as $key => $value) {
|
||
$stmt->bindValue($key, $value);
|
||
}
|
||
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
|
||
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||
$stmt->execute();
|
||
$orders = $stmt->fetchAll();
|
||
|
||
foreach ($orders as &$order) {
|
||
$order['items'] = json_decode((string) ($order['items_json'] ?? '[]'), true) ?: [];
|
||
|
||
$itemPreview = [];
|
||
foreach ($order['items'] as $item) {
|
||
$name = trim((string) ($item['name'] ?? $item['name_ar'] ?? $item['name_en'] ?? $item['sku'] ?? ''));
|
||
$qty = max(0, (int) ($item['qty'] ?? 0));
|
||
if ($name === '') {
|
||
continue;
|
||
}
|
||
|
||
$itemPreview[] = $qty > 0 ? $name . ' ×' . $qty : $name;
|
||
if (count($itemPreview) >= 2) {
|
||
break;
|
||
}
|
||
}
|
||
|
||
$remainingItems = max(0, count($order['items']) - count($itemPreview));
|
||
$order['item_preview'] = $itemPreview;
|
||
$order['item_preview_more'] = $remainingItems;
|
||
}
|
||
unset($order);
|
||
} catch (Throwable $e) {
|
||
$dbError = $e->getMessage();
|
||
}
|
||
|
||
$queryState = static function (array $extra = []) use ($search, $branch, $mode, $paymentStatus, $deliveryStatus, $dateFrom, $dateTo, $sort, $dir): array {
|
||
$params = [
|
||
'q' => $search,
|
||
'branch' => $branch,
|
||
'mode' => $mode,
|
||
'payment_status' => $paymentStatus,
|
||
'delivery_status' => $deliveryStatus,
|
||
'date_from' => $dateFrom,
|
||
'date_to' => $dateTo,
|
||
'sort' => $sort,
|
||
'dir' => $dir,
|
||
];
|
||
|
||
foreach ($extra as $key => $value) {
|
||
$params[$key] = $value;
|
||
}
|
||
|
||
return array_filter($params, static fn($value) => $value !== null && $value !== '');
|
||
};
|
||
|
||
$sortUrl = static function (string $column) use ($sort, $dir, $queryState): string {
|
||
$nextDir = $sort === $column && $dir === 'asc' ? 'desc' : 'asc';
|
||
return url_for('eid_orders.php', $queryState(['sort' => $column, 'dir' => $nextDir, 'p' => 1]));
|
||
};
|
||
|
||
$sortIcon = static function (string $column) use ($sort, $dir): string {
|
||
if ($sort !== $column) {
|
||
return 'bi-arrow-down-up text-muted';
|
||
}
|
||
|
||
return $dir === 'asc' ? 'bi-sort-down-alt' : 'bi-sort-up';
|
||
};
|
||
|
||
require __DIR__ . '/includes/header.php';
|
||
?>
|
||
<section class="surface-card mb-4">
|
||
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-3">
|
||
<div>
|
||
<h1 class="h4 mb-1"><i class="bi bi-stars me-2"></i><?= h(tr('طلبات العيد', 'Eid Orders')) ?></h1>
|
||
</div>
|
||
<div class="d-flex gap-2 flex-wrap">
|
||
<span class="badge text-bg-success-subtle border border-success-subtle text-success-emphasis px-3 py-2"><?= h(tr('المرحلة الحالية: إنشاء الطلبات', 'Current phase: order creation')) ?></span>
|
||
<a class="btn btn-dark" href="<?= h(url_for('eid_sale.php')) ?>"><i class="bi bi-plus-circle me-1"></i><?= h(tr('طلب عيد جديد', 'New Eid Order')) ?></a>
|
||
<a class="btn btn-outline-dark" href="<?= h(url_for('eid_print.php', $queryState())) ?>"><i class="bi bi-printer me-1"></i><?= h(tr('طباعة ملخص التجهيز', 'Print prep summary')) ?></a>
|
||
<a class="btn btn-outline-secondary" href="<?= h(url_for('sales.php', ['status' => 'order'])) ?>"><i class="bi bi-journal-text me-1"></i><?= h(tr('عرض الطلبات العادية', 'View regular orders')) ?></a>
|
||
</div>
|
||
</div>
|
||
|
||
<?php $hasAdvancedFilters = $mode !== null || $paymentStatus !== ''; ?>
|
||
<style>
|
||
.eid-filter-shell {
|
||
border: 1px solid rgba(15, 23, 42, 0.08);
|
||
border-radius: 1rem;
|
||
background: linear-gradient(180deg, rgba(248, 250, 252, 0.96), rgba(255, 255, 255, 0.98));
|
||
padding: 1rem;
|
||
}
|
||
.eid-filter-row {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: .75rem;
|
||
align-items: end;
|
||
}
|
||
.eid-filter-item {
|
||
flex: 1 1 180px;
|
||
min-width: 0;
|
||
}
|
||
.eid-filter-item--search {
|
||
flex: 2.2 1 320px;
|
||
}
|
||
.eid-filter-item--date {
|
||
flex: 1.6 1 280px;
|
||
}
|
||
.eid-filter-actions {
|
||
flex: 0 1 auto;
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: .5rem;
|
||
align-items: end;
|
||
}
|
||
.eid-date-range {
|
||
display: grid;
|
||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||
gap: .5rem;
|
||
}
|
||
.eid-advanced-toggle summary {
|
||
list-style: none;
|
||
cursor: pointer;
|
||
}
|
||
.eid-advanced-toggle summary::-webkit-details-marker {
|
||
display: none;
|
||
}
|
||
.eid-advanced-panel {
|
||
border-top: 1px dashed rgba(15, 23, 42, 0.12);
|
||
margin-top: .85rem;
|
||
padding-top: .85rem;
|
||
}
|
||
.eid-grid-card {
|
||
border: 1px solid rgba(15, 23, 42, 0.08);
|
||
border-radius: 1rem;
|
||
overflow: hidden;
|
||
box-shadow: 0 1rem 2rem rgba(15, 23, 42, 0.05);
|
||
}
|
||
.eid-grid-toolbar {
|
||
background: linear-gradient(135deg, rgba(248, 250, 252, 0.96), rgba(241, 245, 249, 0.92));
|
||
}
|
||
.eid-table thead th {
|
||
white-space: nowrap;
|
||
font-size: .82rem;
|
||
text-transform: uppercase;
|
||
letter-spacing: .03em;
|
||
border-bottom-width: 1px;
|
||
}
|
||
.eid-sort-link {
|
||
color: inherit;
|
||
text-decoration: none;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: .35rem;
|
||
font-weight: 600;
|
||
}
|
||
.eid-sort-link:hover {
|
||
color: var(--bs-dark);
|
||
}
|
||
.eid-order-id {
|
||
font-variant-numeric: tabular-nums;
|
||
letter-spacing: .02em;
|
||
}
|
||
.eid-customer-cell,
|
||
.eid-items-cell {
|
||
min-width: 190px;
|
||
}
|
||
.eid-items-list {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: .35rem;
|
||
}
|
||
.eid-items-list .badge {
|
||
max-width: 100%;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
@media (max-width: 767.98px) {
|
||
.eid-filter-actions {
|
||
width: 100%;
|
||
}
|
||
.eid-filter-actions .btn {
|
||
flex: 1 1 auto;
|
||
}
|
||
.eid-date-range {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
}
|
||
</style>
|
||
<form class="eid-filter-shell mb-4" method="GET" action="eid_orders.php">
|
||
<div class="d-flex justify-content-end align-items-center mb-3">
|
||
<details class="eid-advanced-toggle" <?= $hasAdvancedFilters ? 'open' : '' ?>>
|
||
<summary class="btn btn-sm btn-outline-secondary">
|
||
<i class="bi bi-sliders me-1"></i><?= h(tr('فلاتر إضافية', 'More filters')) ?>
|
||
</summary>
|
||
<div class="eid-advanced-panel">
|
||
<div class="row g-2">
|
||
<div class="col-12 col-md-6">
|
||
<label class="form-label mb-1" for="eid-mode"><?= h(tr('القناة', 'Channel')) ?></label>
|
||
<select id="eid-mode" class="form-select" name="mode">
|
||
<option value=""><?= h(tr('الكل', 'All')) ?></option>
|
||
<option value="normal" <?= $mode === 'normal' ? 'selected' : '' ?>><?= h(tr('فاتورة', 'Invoice')) ?></option>
|
||
<option value="pos" <?= $mode === 'pos' ? 'selected' : '' ?>>POS</option>
|
||
</select>
|
||
</div>
|
||
<div class="col-12 col-md-6">
|
||
<label class="form-label mb-1" for="eid-payment-status"><?= h(tr('حالة الدفع', 'Payment')) ?></label>
|
||
<select id="eid-payment-status" class="form-select" name="payment_status">
|
||
<option value=""><?= h(tr('كل الحالات', 'All statuses')) ?></option>
|
||
<option value="paid" <?= $paymentStatus === 'paid' ? 'selected' : '' ?>><?= h(tr('مدفوع', 'Paid')) ?></option>
|
||
<option value="partial" <?= $paymentStatus === 'partial' ? 'selected' : '' ?>><?= h(tr('جزئي', 'Partial')) ?></option>
|
||
<option value="unpaid" <?= $paymentStatus === 'unpaid' ? 'selected' : '' ?>><?= h(tr('غير مدفوع', 'Unpaid')) ?></option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</details>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="eid-filter-row">
|
||
<div class="eid-filter-item eid-filter-item--search">
|
||
<label class="form-label mb-1" for="eid-search"><?= h(tr('بحث سريع', 'Quick search')) ?></label>
|
||
<input id="eid-search" type="text" class="form-control" name="q" value="<?= h($search) ?>" placeholder="<?= h(tr('فاتورة، عميل، كاشير، أو ملاحظة', 'Invoice, customer, cashier, or note')) ?>">
|
||
</div>
|
||
<div class="eid-filter-item">
|
||
<label class="form-label mb-1" for="eid-branch"><?= h(tr('الفرع', 'Branch')) ?></label>
|
||
<select id="eid-branch" class="form-select" name="branch">
|
||
<option value=""><?= h(tr('كل الفروع', 'All branches')) ?></option>
|
||
<?php foreach (branches() as $branchCode => $branchLabel): ?>
|
||
<?php if ($user['role'] !== 'owner' && !in_array($branchCode, $allowedBranches, true)) { continue; } ?>
|
||
<option value="<?= h($branchCode) ?>" <?= $branch === $branchCode ? 'selected' : '' ?>><?= h($branchLabel) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div class="eid-filter-item">
|
||
<label class="form-label mb-1" for="eid-delivery-status"><?= h(tr('التجهيز', 'Prep')) ?></label>
|
||
<select id="eid-delivery-status" class="form-select" name="delivery_status">
|
||
<option value=""><?= h(tr('كل الحالات', 'All statuses')) ?></option>
|
||
<?php foreach ($deliveryOptions as $value => $label): ?>
|
||
<option value="<?= h($value) ?>" <?= $deliveryStatus === $value ? 'selected' : '' ?>><?= h($label) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div class="eid-filter-item eid-filter-item--date">
|
||
<label class="form-label mb-1"><?= h(tr('فترة التسليم', 'Delivery window')) ?></label>
|
||
<div class="eid-date-range">
|
||
<input id="eid-date-from" type="date" class="form-control" name="date_from" value="<?= h($dateFrom) ?>" aria-label="<?= h(tr('من تاريخ', 'From date')) ?>">
|
||
<input id="eid-date-to" type="date" class="form-control" name="date_to" value="<?= h($dateTo) ?>" aria-label="<?= h(tr('إلى تاريخ', 'To date')) ?>">
|
||
</div>
|
||
</div>
|
||
<div class="eid-filter-actions">
|
||
<button type="submit" class="btn btn-dark"><i class="bi bi-funnel me-1"></i><?= h(tr('تطبيق', 'Apply')) ?></button>
|
||
<a class="btn btn-outline-secondary" href="<?= h(url_for('eid_orders.php')) ?>"><?= h(tr('إعادة ضبط', 'Reset')) ?></a>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<div class="row g-3 mb-4">
|
||
<div class="col-12 col-md-6 col-xl-3">
|
||
<div class="surface-card h-100 border">
|
||
<div class="small text-muted mb-2"><?= h(tr('إجمالي الطلبات', 'Total orders')) ?></div>
|
||
<div class="display-6 fw-bold"><?= (int) ($summary['total_orders'] ?? 0) ?></div>
|
||
</div>
|
||
</div>
|
||
<div class="col-12 col-md-6 col-xl-3">
|
||
<div class="surface-card h-100 border">
|
||
<div class="small text-muted mb-2"><?= h(tr('عدد القطع', 'Total items')) ?></div>
|
||
<div class="display-6 fw-bold"><?= (int) ($summary['total_items'] ?? 0) ?></div>
|
||
</div>
|
||
</div>
|
||
<div class="col-12 col-md-6 col-xl-3">
|
||
<div class="surface-card h-100 border">
|
||
<div class="small text-muted mb-2"><?= h(tr('قيد التجهيز', 'Pending prep')) ?></div>
|
||
<div class="display-6 fw-bold"><?= (int) ($summary['prep_orders'] ?? 0) ?></div>
|
||
</div>
|
||
</div>
|
||
<div class="col-12 col-md-6 col-xl-3">
|
||
<div class="surface-card h-100 border">
|
||
<div class="small text-muted mb-2"><?= h(tr('إجمالي القيمة', 'Total value')) ?></div>
|
||
<div class="display-6 fw-bold"><?= h(number_format((float) ($summary['total_amount'] ?? 0), 3)) ?></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if ($dbError): ?>
|
||
<div class="alert alert-danger"><?= h($dbError) ?></div>
|
||
<?php elseif ($orders === []): ?>
|
||
<div class="text-center py-5 text-muted">
|
||
<div class="mb-3"><i class="bi bi-calendar-heart" style="font-size: 2rem;"></i></div>
|
||
<h2 class="h5"><?= h(tr('لا توجد طلبات عيد حتى الآن', 'No Eid orders yet')) ?></h2>
|
||
<p class="mb-0"><?= h(tr('لا توجد طلبات عيد حتى الآن. ابدأ بإنشاء أول طلب عيد ليظهر هنا مع الفلاتر والتواريخ.', 'There are no Eid orders yet. Create your first Eid order to see it here with filters and dates.')) ?></p>
|
||
<a class="btn btn-dark mt-3" href="<?= h(url_for('eid_sale.php')) ?>"><i class="bi bi-plus-circle me-1"></i><?= h(tr('إنشاء طلب عيد', 'Create Eid Order')) ?></a>
|
||
</div>
|
||
<?php else: ?>
|
||
<div class="eid-grid-card bg-white mb-3">
|
||
<div class="eid-grid-toolbar px-3 px-lg-4 py-3 border-bottom d-flex justify-content-end">
|
||
<span class="badge rounded-pill text-bg-light border px-3 py-2">
|
||
<?= h((int) ($summary['total_orders'] ?? 0)) ?> <?= h(tr('طلب', 'orders')) ?>
|
||
</span>
|
||
</div>
|
||
<div class="table-responsive">
|
||
<table class="table table-hover align-middle mb-0 eid-table">
|
||
<thead class="table-light">
|
||
<tr>
|
||
<th>
|
||
<a class="eid-sort-link" href="<?= h($sortUrl('receipt_no')) ?>">
|
||
<?= h(tr('الفاتورة', 'Invoice')) ?>
|
||
<i class="bi <?= h($sortIcon('receipt_no')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th>
|
||
<a class="eid-sort-link" href="<?= h($sortUrl('customer')) ?>">
|
||
<?= h(tr('العميل', 'Customer')) ?>
|
||
<i class="bi <?= h($sortIcon('customer')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th>
|
||
<a class="eid-sort-link" href="<?= h($sortUrl('delivery_date')) ?>">
|
||
<?= h(tr('تسليم', 'Delivery')) ?>
|
||
<i class="bi <?= h($sortIcon('delivery_date')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th>
|
||
<a class="eid-sort-link" href="<?= h($sortUrl('delivery_status')) ?>">
|
||
<?= h(tr('حالة التجهيز', 'Prep status')) ?>
|
||
<i class="bi <?= h($sortIcon('delivery_status')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th>
|
||
<a class="eid-sort-link" href="<?= h($sortUrl('branch')) ?>">
|
||
<?= h(tr('الفرع', 'Branch')) ?>
|
||
<i class="bi <?= h($sortIcon('branch')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th>
|
||
<a class="eid-sort-link" href="<?= h($sortUrl('item_count')) ?>">
|
||
<?= h(tr('الأصناف', 'Items')) ?>
|
||
<i class="bi <?= h($sortIcon('item_count')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th class="text-end">
|
||
<a class="eid-sort-link justify-content-end" href="<?= h($sortUrl('total_amount')) ?>">
|
||
<?= h(tr('الإجمالي', 'Total')) ?>
|
||
<i class="bi <?= h($sortIcon('total_amount')) ?>"></i>
|
||
</a>
|
||
</th>
|
||
<th class="text-end"><?= h(tr('إجراءات', 'Actions')) ?></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($orders as $order): ?>
|
||
<?php $effectiveDelivery = $order['delivery_date'] ?: date('Y-m-d', strtotime((string) $order['sale_date'])); ?>
|
||
<tr>
|
||
<td>
|
||
<div class="fw-semibold eid-order-id"><?= h($order['receipt_no']) ?></div>
|
||
</td>
|
||
<td class="eid-customer-cell">
|
||
<div class="fw-semibold"><?= h((string) ($order['customer_name'] ?: tr('عميل نقدي', 'Walk-in customer'))) ?></div>
|
||
</td>
|
||
<td>
|
||
<div class="fw-semibold"><?= h(date('Y-m-d', strtotime((string) $effectiveDelivery))) ?></div>
|
||
</td>
|
||
<td>
|
||
<span class="badge <?= h(eid_delivery_status_badge_class((string) ($order['delivery_status'] ?? 'pending'))) ?> px-3 py-2"><?= h(eid_delivery_status_label((string) ($order['delivery_status'] ?? 'pending'))) ?></span>
|
||
</td>
|
||
<td>
|
||
<span class="badge rounded-pill text-bg-light border"><?= h(branch_label((string) $order['branch_code'])) ?></span>
|
||
</td>
|
||
<td class="eid-items-cell">
|
||
<span class="badge rounded-pill text-bg-light border px-3 py-2 fw-semibold">
|
||
<?= (int) ($order['item_count'] ?? 0) ?> <?= h(tr('صنف', 'items')) ?>
|
||
</span>
|
||
</td>
|
||
<td class="text-end fw-semibold"><?= h(number_format((float) ($order['total_amount'] ?? 0), 3)) ?></td>
|
||
<td>
|
||
<div class="d-flex justify-content-end gap-2">
|
||
<a class="btn btn-sm btn-light border text-primary" href="<?= h(url_for('sale.php', ['id' => $order['id']])) ?>" title="<?= h(tr('تفاصيل', 'Detail')) ?>"><i class="bi bi-eye"></i></a>
|
||
<a class="btn btn-sm btn-outline-secondary" href="<?= h(url_for('edit_sale.php', ['id' => $order['id']])) ?>" title="<?= h(tr('تعديل', 'Edit')) ?>"><i class="bi bi-pencil"></i></a>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if ($totalPages > 1): ?>
|
||
<nav class="mt-4" aria-label="<?= h(tr('صفحات طلبات العيد', 'Eid order pages')) ?>">
|
||
<ul class="pagination justify-content-center mb-0">
|
||
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
|
||
<li class="page-item <?= $i === $page ? 'active' : '' ?>">
|
||
<a class="page-link" href="<?= h(url_for('eid_orders.php', $queryState(['p' => $i]))) ?>"><?= $i ?></a>
|
||
</li>
|
||
<?php endfor; ?>
|
||
</ul>
|
||
</nav>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
</section>
|
||
<?php require __DIR__ . '/includes/footer.php'; ?>
|