Autosave: 20260216-082758
This commit is contained in:
parent
a57cb68d98
commit
5089493915
265
index.php
265
index.php
@ -10,10 +10,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'] ?? '';
|
||||
$phone = $_POST['phone'] ?? '';
|
||||
$balance = (float)($_POST['balance'] ?? 0);
|
||||
$type = $_POST['type'] ?? 'customer';
|
||||
if ($name) {
|
||||
$stmt = db()->prepare("INSERT INTO customers (name, email, phone, balance) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $email, $phone, $balance]);
|
||||
$message = "Customer added successfully!";
|
||||
$stmt = db()->prepare("INSERT INTO customers (name, email, phone, balance, type) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$name, $email, $phone, $balance, $type]);
|
||||
$message = ucfirst($type) . " added successfully!";
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,21 +84,67 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$stmt->execute([$id]);
|
||||
$message = "Item deleted successfully!";
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_item'])) {
|
||||
$id = (int)$_POST['id'];
|
||||
$cat_id = $_POST['category_id'] ?: null;
|
||||
$unit_id = $_POST['unit_id'] ?: null;
|
||||
$supplier_id = $_POST['supplier_id'] ?: null;
|
||||
$name_en = $_POST['name_en'] ?? '';
|
||||
$name_ar = $_POST['name_ar'] ?? '';
|
||||
$sku = $_POST['sku'] ?? '';
|
||||
$p_price = (float)($_POST['purchase_price'] ?? 0);
|
||||
$s_price = (float)($_POST['sale_price'] ?? 0);
|
||||
$qty = (float)($_POST['stock_quantity'] ?? 0);
|
||||
$min_stock = (float)($_POST['min_stock_level'] ?? 0);
|
||||
$expiry = $_POST['expiry_date'] ?: null;
|
||||
|
||||
$stmt = db()->prepare("SELECT image_path FROM stock_items WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$image_path = $stmt->fetchColumn();
|
||||
|
||||
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
|
||||
// Delete old image
|
||||
if ($image_path && file_exists($image_path)) {
|
||||
unlink($image_path);
|
||||
}
|
||||
$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
|
||||
$filename = uniqid('item_') . '.' . $ext;
|
||||
$target = 'uploads/items/' . $filename;
|
||||
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
|
||||
$image_path = $target;
|
||||
}
|
||||
}
|
||||
|
||||
if ($name_en && $name_ar) {
|
||||
$stmt = db()->prepare("UPDATE stock_items SET category_id = ?, unit_id = ?, supplier_id = ?, name_en = ?, name_ar = ?, sku = ?, purchase_price = ?, sale_price = ?, stock_quantity = ?, min_stock_level = ?, expiry_date = ?, image_path = ? WHERE id = ?");
|
||||
$stmt->execute([$cat_id, $unit_id, $supplier_id, $name_en, $name_ar, $sku, $p_price, $s_price, $qty, $min_stock, $expiry, $image_path, $id]);
|
||||
$message = "Item updated successfully!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Routing & Data Fetching
|
||||
$page = $_GET['page'] ?? 'dashboard';
|
||||
$data = [];
|
||||
|
||||
// Global data for modals
|
||||
$data['categories'] = db()->query("SELECT * FROM stock_categories ORDER BY name_en ASC")->fetchAll();
|
||||
$data['units'] = db()->query("SELECT * FROM stock_units ORDER BY name_en ASC")->fetchAll();
|
||||
$data['suppliers'] = db()->query("SELECT * FROM customers WHERE type = 'supplier' ORDER BY name ASC")->fetchAll();
|
||||
|
||||
switch ($page) {
|
||||
case 'suppliers':
|
||||
$data['customers'] = db()->query("SELECT * FROM customers WHERE type = 'supplier' ORDER BY id DESC")->fetchAll();
|
||||
break;
|
||||
case 'customers':
|
||||
$data['customers'] = db()->query("SELECT * FROM customers ORDER BY id DESC")->fetchAll();
|
||||
$data['customers'] = db()->query("SELECT * FROM customers WHERE type = 'customer' ORDER BY id DESC")->fetchAll();
|
||||
break;
|
||||
case 'categories':
|
||||
$data['categories'] = db()->query("SELECT * FROM stock_categories ORDER BY id DESC")->fetchAll();
|
||||
// Already fetched globally
|
||||
break;
|
||||
case 'units':
|
||||
$data['units'] = db()->query("SELECT * FROM stock_units ORDER BY id DESC")->fetchAll();
|
||||
// Already fetched globally
|
||||
break;
|
||||
case 'items':
|
||||
$data['items'] = db()->query("SELECT i.*, c.name_en as cat_en, c.name_ar as cat_ar, u.short_name_en as unit_en, u.short_name_ar as unit_ar, s.name as supplier_name
|
||||
@ -106,18 +153,12 @@ switch ($page) {
|
||||
LEFT JOIN stock_units u ON i.unit_id = u.id
|
||||
LEFT JOIN customers s ON i.supplier_id = s.id
|
||||
ORDER BY i.id DESC")->fetchAll();
|
||||
$data['categories'] = db()->query("SELECT * FROM stock_categories ORDER BY name_en ASC")->fetchAll();
|
||||
$data['units'] = db()->query("SELECT * FROM stock_units ORDER BY name_en ASC")->fetchAll();
|
||||
$data['suppliers'] = db()->query("SELECT * FROM customers ORDER BY name ASC")->fetchAll();
|
||||
break;
|
||||
default:
|
||||
$data['customers'] = db()->query("SELECT * FROM customers ORDER BY id DESC LIMIT 5")->fetchAll();
|
||||
$data['categories'] = db()->query("SELECT * FROM stock_categories ORDER BY name_en ASC")->fetchAll();
|
||||
$data['units'] = db()->query("SELECT * FROM stock_units ORDER BY name_en ASC")->fetchAll();
|
||||
$data['suppliers'] = db()->query("SELECT * FROM customers ORDER BY name ASC")->fetchAll();
|
||||
$data['customers'] = db()->query("SELECT * FROM customers WHERE type = 'customer' ORDER BY id DESC LIMIT 5")->fetchAll();
|
||||
// Dashboard stats
|
||||
$data['stats'] = [
|
||||
'total_customers' => db()->query("SELECT COUNT(*) FROM customers")->fetchColumn(),
|
||||
'total_customers' => db()->query("SELECT COUNT(*) FROM customers WHERE type = 'customer'")->fetchColumn(),
|
||||
'total_items' => db()->query("SELECT COUNT(*) FROM stock_items")->fetchColumn(),
|
||||
];
|
||||
break;
|
||||
@ -162,7 +203,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
</a>
|
||||
|
||||
<div class="nav-section-title px-4 mt-3 mb-1 text-uppercase small text-muted" data-en="Other" data-ar="أخرى">Other</div>
|
||||
<a href="#" class="nav-link">
|
||||
<a href="index.php?page=suppliers" class="nav-link <?= isset($_GET['page']) && $_GET['page'] === 'suppliers' ? 'active' : '' ?>">
|
||||
<i class="bi bi-truck"></i> <span data-en="Suppliers" data-ar="الموردون">Suppliers</span>
|
||||
</a>
|
||||
<a href="#" class="nav-link">
|
||||
@ -184,6 +225,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
$titles = [
|
||||
'dashboard' => ['en' => 'Dashboard', 'ar' => 'لوحة القيادة'],
|
||||
'customers' => ['en' => 'Customers', 'ar' => 'العملاء'],
|
||||
'suppliers' => ['en' => 'Suppliers', 'ar' => 'الموردون'],
|
||||
'categories' => ['en' => 'Stock Categories', 'ar' => 'فئات المخزون'],
|
||||
'units' => ['en' => 'Stock Units', 'ar' => 'وحدات المخزون'],
|
||||
'items' => ['en' => 'Stock Items', 'ar' => 'أصناف المخزون'],
|
||||
@ -292,12 +334,12 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($page === 'customers'): ?>
|
||||
<?php elseif ($page === 'customers' || $page === 'suppliers'): ?>
|
||||
<div class="card p-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h5 class="m-0" data-en="Customer Management" data-ar="إدارة العملاء">Customer Management</h5>
|
||||
<h5 class="m-0" data-en="<?= $currTitle['en'] ?> Management" data-ar="إدارة <?= $currTitle['ar'] ?>"><?= $currTitle['en'] ?> Management</h5>
|
||||
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addCustomerModal">
|
||||
<i class="bi bi-plus-lg"></i> <span data-en="Add Customer" data-ar="إضافة عميل">Add Customer</span>
|
||||
<i class="bi bi-plus-lg"></i> <span data-en="Add <?= $currTitle['en'] ?>" data-ar="إضافة <?= $currTitle['ar'] ?>">Add <?= $currTitle['en'] ?></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
@ -440,13 +482,107 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<button class="btn btn-outline-info" title="View" data-bs-toggle="modal" data-bs-target="#viewItemModal<?= $item['id'] ?>"><i class="bi bi-eye"></i></button>
|
||||
<button class="btn btn-outline-primary" title="Edit"><i class="bi bi-pencil"></i></button>
|
||||
<button class="btn btn-outline-primary" title="Edit" data-bs-toggle="modal" data-bs-target="#editItemModal<?= $item['id'] ?>"><i class="bi bi-pencil"></i></button>
|
||||
<form method="POST" class="d-inline" onsubmit="return confirm('Are you sure?')">
|
||||
<input type="hidden" name="id" value="<?= $item['id'] ?>">
|
||||
<button type="submit" name="delete_item" class="btn btn-outline-danger" title="Delete"><i class="bi bi-trash"></i></button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Edit Item Modal -->
|
||||
<div class="modal fade" id="editItemModal<?= $item['id'] ?>" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" data-en="Edit Item" data-ar="تعديل الصنف">Edit Item</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="id" value="<?= $item['id'] ?>">
|
||||
<div class="modal-body">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" data-en="Name (EN)" data-ar="الاسم (إنجليزي)">Name (EN)</label>
|
||||
<input type="text" name="name_en" class="form-control" value="<?= htmlspecialchars($item['name_en']) ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" data-en="Name (AR)" data-ar="الاسم (عربي)">Name (AR)</label>
|
||||
<input type="text" name="name_ar" class="form-control" value="<?= htmlspecialchars($item['name_ar']) ?>" required>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Category" data-ar="الفئة">Category</label>
|
||||
<select name="category_id" class="form-select">
|
||||
<option value="">---</option>
|
||||
<?php foreach ($data['categories'] ?? [] as $c): ?>
|
||||
<option value="<?= $c['id'] ?>" <?= $item['category_id'] == $c['id'] ? 'selected' : '' ?>><?= htmlspecialchars($c['name_en']) ?> / <?= htmlspecialchars($c['name_ar']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Unit" data-ar="الوحدة">Unit</label>
|
||||
<select name="unit_id" class="form-select">
|
||||
<option value="">---</option>
|
||||
<?php foreach ($data['units'] ?? [] as $u): ?>
|
||||
<option value="<?= $u['id'] ?>" <?= $item['unit_id'] == $u['id'] ? 'selected' : '' ?>><?= htmlspecialchars($u['short_name_en']) ?> / <?= htmlspecialchars($u['short_name_ar']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Supplier" data-ar="المورد">Supplier</label>
|
||||
<select name="supplier_id" class="form-select">
|
||||
<option value="">---</option>
|
||||
<?php foreach ($data['suppliers'] ?? [] as $s): ?>
|
||||
<option value="<?= $s['id'] ?>" <?= $item['supplier_id'] == $s['id'] ? 'selected' : '' ?>><?= htmlspecialchars($s['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" data-en="SKU / Barcode" data-ar="الباركود">SKU / Barcode</label>
|
||||
<div class="input-group">
|
||||
<input type="text" name="sku" class="form-control" value="<?= htmlspecialchars($item['sku']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" data-en="Sale Price" data-ar="سعر البيع">Sale Price</label>
|
||||
<input type="number" step="0.01" name="sale_price" class="form-control" value="<?= (float)$item['sale_price'] ?>">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" data-en="Purchase Price" data-ar="سعر الشراء">Purchase Price</label>
|
||||
<input type="number" step="0.01" name="purchase_price" class="form-control" value="<?= (float)$item['purchase_price'] ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Stock Quantity" data-ar="الكمية">Stock Quantity</label>
|
||||
<input type="number" step="0.01" name="stock_quantity" class="form-control" value="<?= (float)$item['stock_quantity'] ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Min Stock Level" data-ar="الحد الأدنى للمخزون">Min Stock Level</label>
|
||||
<input type="number" step="0.01" name="min_stock_level" class="form-control" value="<?= (float)$item['min_stock_level'] ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Change Picture" data-ar="تغيير الصورة">Change Picture</label>
|
||||
<input type="file" name="image" class="form-control" accept="image/*">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-check form-switch mt-4">
|
||||
<input class="form-check-input hasExpiryToggleEdit" type="checkbox" id="hasExpiryToggle<?= $item['id'] ?>" <?= $item['expiry_date'] ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="hasExpiryToggle<?= $item['id'] ?>" data-en="Has Expiry Date?" data-ar="هل له تاريخ انتهاء؟">Has Expiry Date?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 expiryDateContainerEdit" style="<?= $item['expiry_date'] ? 'display: block;' : 'display: none;' ?>">
|
||||
<label class="form-label" data-en="Expiry Date" data-ar="تاريخ الانتهاء">Expiry Date</label>
|
||||
<input type="date" name="expiry_date" class="form-control" value="<?= $item['expiry_date'] ?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal" data-en="Cancel" data-ar="إلغاء">Cancel</button>
|
||||
<button type="submit" name="edit_item" class="btn btn-primary" data-en="Update Item" data-ar="تحديث الصنف">Update Item</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- View Item Modal -->
|
||||
<div class="modal fade" id="viewItemModal<?= $item['id'] ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
@ -493,13 +629,20 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" data-en="Add New Customer" data-ar="إضافة عميل جديد">Add New Customer</h5>
|
||||
<h5 class="modal-title">
|
||||
<?php if ($page === 'suppliers'): ?>
|
||||
<span data-en="Add New Supplier" data-ar="إضافة مورد جديد">Add New Supplier</span>
|
||||
<?php else: ?>
|
||||
<span data-en="Add New Customer" data-ar="إضافة عميل جديد">Add New Customer</span>
|
||||
<?php endif; ?>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="type" value="<?= $page === 'suppliers' ? 'supplier' : 'customer' ?>">
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" data-en="Customer Name" data-ar="اسم العميل">Customer Name</label>
|
||||
<label class="form-label" data-en="Name" data-ar="الاسم">Name</label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
@ -517,7 +660,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal" data-en="Cancel" data-ar="إلغاء">Cancel</button>
|
||||
<button type="submit" name="add_customer" class="btn btn-primary" data-en="Save Customer" data-ar="حفظ العميل">Save Customer</button>
|
||||
<button type="submit" name="add_customer" class="btn btn-primary" data-en="Save" data-ar="حفظ">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -526,7 +669,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
|
||||
<!-- Add Item Modal -->
|
||||
<div class="modal fade" id="addItemModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content border-0 shadow">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" data-en="Add New Item" data-ar="إضافة صنف جديد">Add New Item</h5>
|
||||
@ -543,7 +686,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<label class="form-label" data-en="Name (AR)" data-ar="الاسم (عربي)">Name (AR)</label>
|
||||
<input type="text" name="name_ar" class="form-control" required>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Category" data-ar="الفئة">Category</label>
|
||||
<select name="category_id" class="form-select">
|
||||
<option value="">---</option>
|
||||
@ -552,7 +695,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Unit" data-ar="الوحدة">Unit</label>
|
||||
<select name="unit_id" class="form-select">
|
||||
<option value="">---</option>
|
||||
@ -561,7 +704,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Supplier" data-ar="المورد">Supplier</label>
|
||||
<select name="supplier_id" class="form-select">
|
||||
<option value="">---</option>
|
||||
@ -572,13 +715,16 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" data-en="SKU / Barcode" data-ar="الباركود">SKU / Barcode</label>
|
||||
<input type="text" name="sku" class="form-control">
|
||||
<div class="input-group">
|
||||
<input type="text" name="sku" id="skuInput" class="form-control">
|
||||
<button class="btn btn-outline-secondary" type="button" id="suggestSkuBtn" data-en="Suggest" data-ar="اقتراح">Suggest</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" data-en="Sale Price" data-ar="سعر البيع">Sale Price</label>
|
||||
<input type="number" step="0.01" name="sale_price" class="form-control" value="0.00">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label" data-en="Purchase Price" data-ar="سعر الشراء">Purchase Price</label>
|
||||
<input type="number" step="0.01" name="purchase_price" class="form-control" value="0.00">
|
||||
</div>
|
||||
@ -590,14 +736,20 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<label class="form-label" data-en="Min Stock Level" data-ar="الحد الأدنى للمخزون">Min Stock Level</label>
|
||||
<input type="number" step="0.01" name="min_stock_level" class="form-control" value="0.00">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Expiry Date" data-ar="تاريخ الانتهاء">Expiry Date</label>
|
||||
<input type="date" name="expiry_date" class="form-control">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" data-en="Item Picture" data-ar="صورة الصنف">Item Picture</label>
|
||||
<input type="file" name="image" class="form-control" accept="image/*">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-check form-switch mt-4">
|
||||
<input class="form-check-input" type="checkbox" id="hasExpiryToggle">
|
||||
<label class="form-check-label" for="hasExpiryToggle" data-en="Has Expiry Date?" data-ar="هل له تاريخ انتهاء؟">Has Expiry Date?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6" id="expiryDateContainer" style="display: none;">
|
||||
<label class="form-label" data-en="Expiry Date" data-ar="تاريخ الانتهاء">Expiry Date</label>
|
||||
<input type="date" name="expiry_date" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
@ -677,5 +829,52 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?= time() ?>"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const hasExpiryToggle = document.getElementById('hasExpiryToggle');
|
||||
const expiryDateContainer = document.getElementById('expiryDateContainer');
|
||||
const suggestSkuBtn = document.getElementById('suggestSkuBtn');
|
||||
const skuInput = document.getElementById('skuInput');
|
||||
|
||||
// Toggle Expiry Date visibility
|
||||
if (hasExpiryToggle && expiryDateContainer) {
|
||||
hasExpiryToggle.addEventListener('change', function() {
|
||||
expiryDateContainer.style.display = this.checked ? 'block' : 'none';
|
||||
if (!this.checked) {
|
||||
expiryDateContainer.querySelector('input').value = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// SKU Suggestion
|
||||
if (suggestSkuBtn && skuInput) {
|
||||
const existingSkus = <?= json_encode(db()->query("SELECT sku FROM stock_items WHERE sku IS NOT NULL AND sku != ''")->fetchAll(PDO::FETCH_COLUMN)) ?>;
|
||||
|
||||
suggestSkuBtn.addEventListener('click', function() {
|
||||
let sku;
|
||||
let attempts = 0;
|
||||
do {
|
||||
sku = Math.floor(10000000 + Math.random() * 90000000).toString();
|
||||
attempts++;
|
||||
} while (existingSkus.includes(sku) && attempts < 100);
|
||||
|
||||
skuInput.value = sku;
|
||||
});
|
||||
}
|
||||
|
||||
// Handle Expiry toggle in Edit Modals
|
||||
document.querySelectorAll('.hasExpiryToggleEdit').forEach(toggle => {
|
||||
toggle.addEventListener('change', function() {
|
||||
const container = this.closest('.row').querySelector('.expiryDateContainerEdit');
|
||||
if (container) {
|
||||
container.style.display = this.checked ? 'block' : 'none';
|
||||
if (!this.checked) {
|
||||
container.querySelector('input').value = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
BIN
uploads/items/item_6992d1c375bb8.jfif
Normal file
BIN
uploads/items/item_6992d1c375bb8.jfif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
Loading…
x
Reference in New Issue
Block a user