# دليل إصلاح وتشغيل موديول HR

## المشكلة الحالية

هناك مشكلة في جدول `migrations` في قاعدة البيانات MySQL تمنع تشغيل الmigrations الجديدة.

## الحل 1: إصلاح جدول migrations يدويًا

### الخطوات:

1. **فتح phpMyAdmin أو MySQL CLI**

2. **تشغيل الأوامر التالية:**

```sql
-- إنشاء نسخة احتياطية
CREATE TABLE migrations_backup AS SELECT * FROM migrations;

-- حذف الجدول القديم
DROP TABLE IF EXISTS migrations;

-- إعادة إنشاء الجدول بالبنية الصحيحة
CREATE TABLE migrations (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    migration VARCHAR(255) NOT NULL,
    batch INT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- استرجاع البيانات
INSERT INTO migrations (migration, batch)
SELECT migration, batch FROM migrations_backup;
```

3. **بعد ذلك، تشغيل migrations:**

```bash
cd "d:\My Work\Laravel\Adly-Pos-Invdntory"
php artisan migrate
```

---

## الحل 2: تشغيل migrations يدويًا

إذا استمرت المشكلة، يمكنك تشغيل migrations يدويًا:

```bash
# تشغيل كل migration على حدة
php artisan migrate --path=database/migrations/2026_03_25_100001_create_hr_departments_table.php
php artisan migrate --path=database/migrations/2026_03_25_100002_create_hr_job_titles_table.php
php artisan migrate --path=database/migrations/2026_03_25_100003_create_hr_employees_table.php
php artisan migrate --path=database/migrations/2026_03_25_100004_add_manager_id_to_hr_departments_table.php
php artisan migrate --path=database/migrations/2026_03_25_100005_create_hr_employee_documents_table.php
php artisan migrate --path=database/migrations/2026_03_25_100006_create_hr_attendances_table.php
php artisan migrate --path=database/migrations/2026_03_25_100007_create_hr_leaves_table.php
php artisan migrate --path=database/migrations/2026_03_25_100008_create_hr_salary_components_table.php
php artisan migrate --path=database/migrations/2026_03_25_100009_create_hr_employee_salary_components_table.php
php artisan migrate --path=database/migrations/2026_03_25_100010_create_hr_payrolls_table.php
php artisan migrate --path=database/migrations/2026_03_25_100011_create_hr_overtime_table.php
php artisan migrate --path=database/migrations/2026_03_25_100012_create_hr_employee_evaluations_table.php
```

---

## الحل 3: تشغيل SQL مباشرة

يمكنك أيضًا تشغيل SQL commands مباشرة في phpMyAdmin:

1. افتح ملف: `fix_migrations_table.sql`
2. نفذ الأوامر في phpMyAdmin

---

## بعد حل المشكلة

### 1. تنظيف Cache:
```bash
php artisan optimize:clear
```

### 2. إنشاء Permissions:
```bash
php artisan shield:generate --all
```

### 3. التحقق من الجداول:
```bash
php artisan migrate:status
```

---

## التحقق من نجاح التثبيت

يجب أن تظهر الجداول التالية في قاعدة البيانات:

- ✅ `hr_departments`
- ✅ `hr_job_titles`
- ✅ `hr_employees`
- ✅ `hr_employee_documents`
- ✅ `hr_attendances`
- ✅ `hr_leaves`
- ✅ `hr_overtime`
- ✅ `hr_salary_components`
- ✅ `hr_employee_salary_components`
- ✅ `hr_payrolls`
- ✅ `hr_employee_evaluations`

---

## الوصول إلى الموديول

بعد حل المشكلة، ستجد في لوحة التحكم Filament:

**مجموعة "الموارد البشرية" تحتوي على:**
- الأقسام
- الموظفين

---

## ملاحظات

- جميع الجداول تدعم Multi-Tenancy
- جميع الأكواد تُنشأ تلقائيًا
- دعم كامل للغة العربية والإنجليزية
- تكامل مع Filament Shield للصلاحيات
