140 lines
5.4 KiB
PHP
140 lines
5.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/app.php';
|
|
$user = require_roles(['owner', 'manager']);
|
|
$pageTitle = tr('المشتريات', 'Purchases');
|
|
$activeNav = 'purchases';
|
|
|
|
$allPurchases = purchase_pipeline();
|
|
|
|
// Search logic
|
|
$search = $_GET['q'] ?? '';
|
|
$filteredPurchases = [];
|
|
if ($search) {
|
|
$lowerSearch = strtolower($search);
|
|
foreach ($allPurchases as $key => $row) {
|
|
if (
|
|
str_contains(strtolower((string)$row['supplier']), $lowerSearch) ||
|
|
str_contains(strtolower((string)$row['reference']), $lowerSearch)
|
|
) {
|
|
$filteredPurchases[$key] = $row;
|
|
}
|
|
}
|
|
} else {
|
|
$filteredPurchases = $allPurchases;
|
|
}
|
|
|
|
// Pagination logic
|
|
$page = max(1, (int)($_GET['p'] ?? 1));
|
|
$limit = 10;
|
|
$total = count($filteredPurchases);
|
|
$totalPages = max(1, ceil($total / $limit));
|
|
$offset = ($page - 1) * $limit;
|
|
$purchaseRows = array_slice($filteredPurchases, $offset, $limit, true);
|
|
|
|
require __DIR__ . '/includes/header.php';
|
|
?>
|
|
<section class="surface-card mb-4">
|
|
<div class="row g-4 align-items-center mb-3">
|
|
<div class="col-lg-8">
|
|
<h3 class="h5 mb-2"><i class="bi bi-bag-plus me-2"></i><?= h(tr('لوحة استلام الموردين', 'Supplier receiving board')) ?></h3>
|
|
<p class="text-muted mb-0"><?= h(tr('هذه صفحة تمهيدية منظمة للمشتريات حتى تكون كل وحدة في صفحة مستقلة من البداية.', 'This is a structured starter page for purchases so every module already has a dedicated screen.')) ?></p>
|
|
</div>
|
|
<div class="col-lg-4 text-lg-end">
|
|
<button type="button" class="btn btn-primary" onclick="mockEdit()">
|
|
<i class="bi bi-plus-lg"></i> <?= h(tr('إضافة أمر شراء', 'Add Purchase Order')) ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<form class="d-flex mb-3" method="GET" action="purchases.php">
|
|
<div class="input-group" style="max-width: 400px;">
|
|
<input type="text" name="q" class="form-control" placeholder="<?= h(tr('بحث...', 'Search...')) ?>" value="<?= h($search) ?>">
|
|
<button class="btn btn-outline-secondary" type="submit"><i class="bi bi-search"></i></button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<section class="surface-card">
|
|
<div class="table-responsive">
|
|
<table class="table app-table align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th><?= h(tr('المورد', 'Supplier')) ?></th>
|
|
<th><?= h(tr('المرجع', 'Reference')) ?></th>
|
|
<th><?= h(tr('الفرع', 'Branch')) ?></th>
|
|
<th><?= h(tr('الحالة', 'Status')) ?></th>
|
|
<th><?= h(tr('الوصول المتوقع', 'ETA')) ?></th>
|
|
<th><?= h(tr('إجراءات', 'Actions')) ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if(empty($purchaseRows)): ?>
|
|
<tr><td colspan="6" class="text-center text-muted py-4"><?= h(tr('لا توجد بيانات', 'No data found')) ?></td></tr>
|
|
<?php endif; ?>
|
|
<?php foreach ($purchaseRows as $row): ?>
|
|
<tr>
|
|
<td><?= h($row['supplier']) ?></td>
|
|
<td><?= h($row['reference']) ?></td>
|
|
<td><?= h(branch_label($row['branch'])) ?></td>
|
|
<td><span class="badge text-bg-light border"><?= h($row['status']) ?></span></td>
|
|
<td><?= h($row['eta']) ?></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-light text-primary border" onclick="mockEdit()" title="<?= h(tr('تعديل', 'Edit')) ?>">
|
|
<i class="bi bi-pencil"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-light text-danger border" onclick="mockDelete()" title="<?= h(tr('حذف', 'Delete')) ?>">
|
|
<i class="bi bi-trash"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<?php if ($totalPages > 1): ?>
|
|
<nav class="mt-4">
|
|
<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('purchases.php', ['p' => $i, 'q' => $search])) ?>"><?= $i ?></a>
|
|
</li>
|
|
<?php endfor; ?>
|
|
</ul>
|
|
</nav>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<script>
|
|
function mockEdit() {
|
|
Swal.fire({
|
|
title: '<?= h(tr('تعديل (تجريبي)', 'Edit (Demo)')) ?>',
|
|
text: '<?= h(tr('هذه الميزة غير مفعلة للبيانات التجريبية.', 'This feature is mock data and not active yet.')) ?>',
|
|
icon: 'info',
|
|
confirmButtonText: '<?= h(tr('حسناً', 'OK')) ?>'
|
|
});
|
|
}
|
|
|
|
function mockDelete() {
|
|
Swal.fire({
|
|
title: '<?= h(tr('هل أنت متأكد؟', 'Are you sure?')) ?>',
|
|
text: '<?= h(tr('لن تتمكن من التراجع عن هذا!', "You won't be able to revert this!")) ?>',
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#dc3545',
|
|
cancelButtonColor: '#6c757d',
|
|
confirmButtonText: '<?= h(tr('نعم، احذف', 'Yes, delete it!')) ?>',
|
|
cancelButtonText: '<?= h(tr('إلغاء', 'Cancel')) ?>'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
Swal.fire(
|
|
'<?= h(tr('محذوف!', 'Deleted!')) ?>',
|
|
'<?= h(tr('حساب تجريبي لا يمكن حذفه.', 'Demo account cannot be deleted.')) ?>',
|
|
'success'
|
|
);
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<?php require __DIR__ . '/includes/footer.php'; ?>
|