diff --git a/api/suppliers.php b/api/suppliers.php
new file mode 100644
index 0000000..d337041
--- /dev/null
+++ b/api/suppliers.php
@@ -0,0 +1,26 @@
+ false, 'error' => tr('الاسم مطلوب', 'Name is required')]);
+ exit;
+ }
+
+ try {
+ $pdo = db();
+ $stmt = $pdo->prepare('INSERT INTO suppliers (name, phone) VALUES (?, ?)');
+ $stmt->execute([$name, $phone]);
+ $id = $pdo->lastInsertId();
+
+ echo json_encode(['success' => true, 'supplier' => ['id' => $id, 'name' => $name, 'phone' => $phone]]);
+ } catch (Throwable $e) {
+ echo json_encode(['success' => false, 'error' => $e->getMessage()]);
+ }
+ exit;
+}
\ No newline at end of file
diff --git a/includes/app.php b/includes/app.php
index 1bc51e7..6a430e3 100644
--- a/includes/app.php
+++ b/includes/app.php
@@ -230,6 +230,7 @@ function catalog(): array
"name_ar" => $item["name"],
"name_en" => $item["name"],
"price" => (float)$item["price"],
+ "cost_price" => (float)($item["cost_price"] ?? 0),
"base_stock" => (int)$item["base_stock"],
"vat" => (float)$item["vat"],
"category_id" => $item["category_id"],
@@ -488,6 +489,7 @@ function stock_snapshot(): array
'sold' => $used,
'available' => max(0, $base - $used),
'price' => $item['price'],
+ 'cost_price' => $item['cost_price'] ?? 0,
'category_id' => $item['category_id'],
'supplier_id' => $item['supplier_id'],
'image_url' => $item['image_url'],
@@ -525,3 +527,47 @@ function receipt_code(): string
{
return 'AR-' . date('ymd-His') . '-' . random_int(100, 999);
}
+
+function create_purchase(array $data): int
+{
+ db()->beginTransaction();
+ try {
+ $stmt = db()->prepare("INSERT INTO purchase_orders
+ (reference_no, branch_code, user_username, user_name, role_name, supplier_name, items_json, item_count, subtotal, total_amount, status, notes, purchase_date)
+ VALUES
+ (:reference_no, :branch_code, :user_username, :user_name, :role_name, :supplier_name, :items_json, :item_count, :subtotal, :total_amount, :status, :notes, NOW())");
+
+ $stmt->bindValue(":reference_no", $data["reference_no"]);
+ $stmt->bindValue(":branch_code", $data["branch_code"]);
+ $stmt->bindValue(":user_username", $data["user_username"]);
+ $stmt->bindValue(":user_name", $data["user_name"]);
+ $stmt->bindValue(":role_name", $data["role_name"]);
+ $stmt->bindValue(":supplier_name", $data["supplier_name"]);
+ $stmt->bindValue(":items_json", json_encode($data["items"], JSON_UNESCAPED_UNICODE));
+ $stmt->bindValue(":item_count", $data["item_count"], PDO::PARAM_INT);
+ $stmt->bindValue(":subtotal", $data["subtotal"]);
+ $stmt->bindValue(":total_amount", $data["total_amount"]);
+ $stmt->bindValue(":status", $data["status"] ?? "completed");
+ $stmt->bindValue(":notes", $data["notes"]);
+ $stmt->execute();
+
+ $purchaseId = (int) db()->lastInsertId();
+
+ // Update stock
+ foreach ($data["items"] as $item) {
+ $qty = (int) $item["qty"];
+ $sku = $item["sku"];
+ $updateStmt = db()->prepare("UPDATE items SET base_stock = base_stock + :qty, cost_price = :price WHERE sku = :sku");
+ $updateStmt->bindValue(":qty", $qty, PDO::PARAM_INT);
+ $updateStmt->bindValue(":price", $item["price"]);
+ $updateStmt->bindValue(":sku", $sku);
+ $updateStmt->execute();
+ }
+
+ db()->commit();
+ return $purchaseId;
+ } catch (Throwable $e) {
+ db()->rollBack();
+ throw $e;
+ }
+}
diff --git a/includes/header.php b/includes/header.php
index 5f1277c..86cb7ae 100644
--- a/includes/header.php
+++ b/includes/header.php
@@ -70,16 +70,8 @@ $isPublic = !isset($user) || !$user;
= h(tr('لوحة التحكم', 'Dashboard')) ?>
-
- = h(tr('نقاط البيع', 'POS Sale')) ?>
-
-
- = h(tr('بيع عادي', 'Normal Sale')) ?>
-
-
- = h(tr('المبيعات', 'Sales')) ?>
-
-
+
+
= h(tr('نظام متكامل لتسجيل المبيعات، وإدارة المخزون، والتقارير في واجهة واحدة.', 'Integrated system for logging sales, managing inventory, and reports in one interface.')) ?>
- -= h(tr('أدخل اسم المستخدم أو البريد الإلكتروني وسنقوم بإرسال رابط لإعادة تعيين كلمة المرور الخاصة بك.', 'Enter your username or email and we will send you a link to reset your password.')) ?>
= h(tr('هذه صفحة تمهيدية منظمة للمشتريات حتى تكون كل وحدة في صفحة مستقلة من البداية.', 'This is a structured starter page for purchases so every module already has a dedicated screen.')) ?>
+= h(tr('عرض المشتريات من الموردين وتحديث المخزون.', 'View supplier purchases and inventory updates.')) ?>