diff --git a/index.php b/index.php index cc557df..f1f46a9 100644 --- a/index.php +++ b/index.php @@ -18,6 +18,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } + if (isset($_POST['edit_customer'])) { + $id = (int)$_POST['id']; + $name = $_POST['name'] ?? ''; + $email = $_POST['email'] ?? ''; + $phone = $_POST['phone'] ?? ''; + $balance = (float)($_POST['balance'] ?? 0); + if ($id && $name) { + $stmt = db()->prepare("UPDATE customers SET name = ?, email = ?, phone = ?, balance = ? WHERE id = ?"); + $stmt->execute([$name, $email, $phone, $balance, $id]); + $message = "Record updated successfully!"; + } + } + + if (isset($_POST['delete_customer'])) { + $id = (int)$_POST['id']; + if ($id) { + $stmt = db()->prepare("DELETE FROM customers WHERE id = ?"); + $stmt->execute([$id]); + $message = "Record deleted successfully!"; + } + } + if (isset($_POST['add_category'])) { $name_en = $_POST['name_en'] ?? ''; $name_ar = $_POST['name_ar'] ?? ''; @@ -122,6 +144,77 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $message = "Item updated successfully!"; } } + + if (isset($_POST['import_items'])) { + if (isset($_FILES['excel_file']) && $_FILES['excel_file']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['excel_file']['tmp_name']; + $handle = fopen($file, 'r'); + $header = fgetcsv($handle); // Skip header row + + $count = 0; + while (($row = fgetcsv($handle)) !== FALSE) { + // Mapping: sku, eng name, arabic name, sale price, cost price + if (count($row) < 5) continue; + + $sku = trim($row[0]); + $name_en = trim($row[1]); + $name_ar = trim($row[2]); + $sale_price = (float)trim($row[3]); + $purchase_price = (float)trim($row[4]); + + if ($name_en && $name_ar) { + // Check if SKU exists to update or insert + $existingId = null; + if ($sku !== "") { + $check = db()->prepare("SELECT id FROM stock_items WHERE sku = ?"); + $check->execute([$sku]); + $existingId = $check->fetchColumn(); + } + + if ($existingId) { + $stmt = db()->prepare("UPDATE stock_items SET name_en = ?, name_ar = ?, sale_price = ?, purchase_price = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $sale_price, $purchase_price, $existingId]); + } else { + $stmt = db()->prepare("INSERT INTO stock_items (sku, name_en, name_ar, sale_price, purchase_price) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$sku, $name_en, $name_ar, $sale_price, $purchase_price]); + } + $count++; + } + } + fclose($handle); + $message = "$count items processed successfully!"; + } + } + + if (isset($_POST['add_payment_method'])) { + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + if ($name_en && $name_ar) { + $stmt = db()->prepare("INSERT INTO payment_methods (name_en, name_ar) VALUES (?, ?)"); + $stmt->execute([$name_en, $name_ar]); + $message = "Payment method added successfully!"; + } + } + + if (isset($_POST['edit_payment_method'])) { + $id = (int)$_POST['id']; + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + if ($id && $name_en && $name_ar) { + $stmt = db()->prepare("UPDATE payment_methods SET name_en = ?, name_ar = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $id]); + $message = "Payment method updated successfully!"; + } + } + + if (isset($_POST['delete_payment_method'])) { + $id = (int)$_POST['id']; + if ($id) { + $stmt = db()->prepare("DELETE FROM payment_methods WHERE id = ?"); + $stmt->execute([$id]); + $message = "Payment method deleted successfully!"; + } + } } // Routing & Data Fetching @@ -154,6 +247,9 @@ switch ($page) { LEFT JOIN customers s ON i.supplier_id = s.id ORDER BY i.id DESC")->fetchAll(); break; + case 'payment_methods': + $data['payment_methods'] = db()->query("SELECT * FROM payment_methods ORDER BY id DESC")->fetchAll(); + break; default: $data['customers'] = db()->query("SELECT * FROM customers WHERE type = 'customer' ORDER BY id DESC LIMIT 5")->fetchAll(); // Dashboard stats @@ -206,6 +302,9 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; Suppliers + + Payment Methods + Sales @@ -229,6 +328,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; 'categories' => ['en' => 'Stock Categories', 'ar' => 'فئات المخزون'], 'units' => ['en' => 'Stock Units', 'ar' => 'وحدات المخزون'], 'items' => ['en' => 'Stock Items', 'ar' => 'أصناف المخزون'], + 'payment_methods' => ['en' => 'Payment Methods', 'ar' => 'طرق الدفع'], ]; $currTitle = $titles[$page] ?? $titles['dashboard']; ?> @@ -327,6 +427,9 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; + @@ -350,6 +453,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
| ID | +Name (EN) | +Name (AR) | +Actions | +
|---|---|---|---|
| = $pm['id'] ?> | += htmlspecialchars($pm['name_en'] ?? '') ?> | += htmlspecialchars($pm['name_ar'] ?? '') ?> | +
+
+
+
+
+
+
+
+
+
+
+
+ |
+