# ✅ حل المشكلة: إصلاح جدول migrations بدون حذف أي بيانات

## 🔴 المشكلة
الـ migration نفسها تعمل بنجاح، لكن عند محاولة إضافة سجل في جدول `migrations`:
```
SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value
```

**السبب:** جدول `migrations` حقل `id` فيه مش معمول AUTO_INCREMENT

---

## ✅ الحل السريع (إصلاح جدول migrations)

### الخطوة 1: إصلاح جدول migrations ✨

افتح **phpMyAdmin** واذهب لقاعدة البيانات `adly` ونفذ هذا الأمر:

```sql
-- إصلاح جدول migrations بدون حذف أي بيانات
ALTER TABLE `migrations` MODIFY COLUMN `id` INT UNSIGNED AUTO_INCREMENT;
```

**هذا الأمر:**
- ✅ لا يحذف أي بيانات موجودة
- ✅ يضيف AUTO_INCREMENT للحقل id فقط
- ✅ يحفظ كل السجلات الموجودة (118 migration سابقة)
- ⚡ يستغرق ثوان قليلة

### الخطوة 2: تشغيل HR Migrations

بعد تنفيذ الخطوة 1، ارجع لـ Terminal ونفذ:

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

🎉 **سيعمل بنجاح الآن!** كل الـ 12 جدول HR سيتم إنشاؤها تلقائيًا.

---

## ✅ حل بديل: SQL مباشر (إذا لم يعمل الحل الأول)

### الخيار 1: تشغيل SQL مباشرة + إضافة سجلات migrations يدويًا

#### الخطوة 1: تشغيل SQL Commands مباشرة

افتح **phpMyAdmin** أو **MySQL Workbench** ونفذ الأوامر التالية:

```sql
-- ===== جداول HR =====

-- 1. hr_departments
CREATE TABLE `hr_departments` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `code` VARCHAR(50) NULL,
    `description` TEXT NULL,
    `parent_id` BIGINT UNSIGNED NULL,
    `manager_id` BIGINT UNSIGNED NULL,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `hr_departments_tenant_id_code_unique` (`tenant_id`, `code`),
    INDEX `hr_departments_tenant_id_is_active_index` (`tenant_id`, `is_active`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`parent_id`) REFERENCES `hr_departments`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 2. hr_job_titles
CREATE TABLE `hr_job_titles` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `code` VARCHAR(50) NULL,
    `description` TEXT NULL,
    `min_salary` DECIMAL(15, 2) NULL,
    `max_salary` DECIMAL(15, 2) NULL,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `hr_job_titles_tenant_id_code_unique` (`tenant_id`, `code`),
    INDEX `hr_job_titles_tenant_id_is_active_index` (`tenant_id`, `is_active`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 3. hr_employees
CREATE TABLE `hr_employees` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `user_id` BIGINT UNSIGNED NULL,
    `employee_code` VARCHAR(255) NOT NULL UNIQUE,
    `first_name` VARCHAR(255) NOT NULL,
    `middle_name` VARCHAR(255) NULL,
    `last_name` VARCHAR(255) NOT NULL,
    `full_name_ar` VARCHAR(255) NULL,
    `national_id` VARCHAR(14) NULL,
    `birth_date` DATE NULL,
    `gender` ENUM('male', 'female') NULL,
    `marital_status` ENUM('single', 'married', 'divorced', 'widowed') NULL,
    `email` VARCHAR(255) NULL,
    `phone` VARCHAR(20) NULL,
    `mobile` VARCHAR(20) NULL,
    `emergency_contact` VARCHAR(255) NULL,
    `emergency_phone` VARCHAR(20) NULL,
    `address` TEXT NULL,
    `governorate_id` BIGINT UNSIGNED NULL,
    `city_id` BIGINT UNSIGNED NULL,
    `department_id` BIGINT UNSIGNED NULL,
    `job_title_id` BIGINT UNSIGNED NULL,
    `direct_manager_id` BIGINT UNSIGNED NULL,
    `hire_date` DATE NOT NULL,
    `employment_start_date` DATE NULL,
    `probation_end_date` DATE NULL,
    `termination_date` DATE NULL,
    `employment_status` ENUM('active', 'probation', 'suspended', 'terminated', 'resigned') NOT NULL DEFAULT 'active',
    `employment_type` ENUM('full_time', 'part_time', 'contract', 'temporary', 'internship') NOT NULL DEFAULT 'full_time',
    `basic_salary` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `bank_name` VARCHAR(255) NULL,
    `bank_account_number` VARCHAR(255) NULL,
    `iban` VARCHAR(34) NULL,
    `work_hours_per_day` INT NOT NULL DEFAULT 8,
    `work_days_per_week` INT NOT NULL DEFAULT 5,
    `annual_leave_days` INT NOT NULL DEFAULT 21,
    `social_insurance_number` VARCHAR(255) NULL,
    `social_insurance_start_date` DATE NULL,
    `notes` TEXT NULL,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `hr_employees_tenant_id_employee_code_unique` (`tenant_id`, `employee_code`),
    UNIQUE KEY `hr_employees_tenant_id_national_id_unique` (`tenant_id`, `national_id`),
    INDEX `hr_employees_tenant_id_employment_status_index` (`tenant_id`, `employment_status`),
    INDEX `hr_employees_tenant_id_department_id_index` (`tenant_id`, `department_id`),
    INDEX `hr_employees_tenant_id_is_active_index` (`tenant_id`, `is_active`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    FOREIGN KEY (`governorate_id`) REFERENCES `governorates`(`id`) ON DELETE SET NULL,
    FOREIGN KEY (`city_id`) REFERENCES `cities`(`id`) ON DELETE SET NULL,
    FOREIGN KEY (`department_id`) REFERENCES `hr_departments`(`id`) ON DELETE SET NULL,
    FOREIGN KEY (`job_title_id`) REFERENCES `hr_job_titles`(`id`) ON DELETE SET NULL,
    FOREIGN KEY (`direct_manager_id`) REFERENCES `hr_employees`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 4. إضافة manager_id إلى hr_departments
ALTER TABLE `hr_departments` 
ADD CONSTRAINT `hr_departments_manager_id_foreign` 
FOREIGN KEY (`manager_id`) REFERENCES `hr_employees`(`id`) ON DELETE SET NULL;

-- 5. hr_employee_documents
CREATE TABLE `hr_employee_documents` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `document_type` VARCHAR(255) NOT NULL,
    `title` VARCHAR(255) NOT NULL,
    `description` TEXT NULL,
    `file_path` VARCHAR(255) NOT NULL,
    `file_name` VARCHAR(255) NOT NULL,
    `file_type` VARCHAR(50) NULL,
    `file_size` INT NULL,
    `issue_date` DATE NULL,
    `expiry_date` DATE NULL,
    `notes` TEXT NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    INDEX `hr_employee_documents_tenant_id_employee_id_index` (`tenant_id`, `employee_id`),
    INDEX `hr_employee_documents_tenant_id_document_type_index` (`tenant_id`, `document_type`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 6. hr_attendances
CREATE TABLE `hr_attendances` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `date` DATE NOT NULL,
    `check_in` TIME NULL,
    `check_out` TIME NULL,
    `work_hours` INT NULL,
    `late_minutes` INT NOT NULL DEFAULT 0,
    `early_leave_minutes` INT NOT NULL DEFAULT 0,
    `overtime_minutes` INT NOT NULL DEFAULT 0,
    `status` ENUM('present', 'absent', 'late', 'half_day', 'on_leave', 'weekend', 'holiday') NOT NULL DEFAULT 'present',
    `notes` TEXT NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `hr_attendances_tenant_id_employee_id_date_unique` (`tenant_id`, `employee_id`, `date`),
    INDEX `hr_attendances_tenant_id_date_index` (`tenant_id`, `date`),
    INDEX `hr_attendances_tenant_id_employee_id_date_index` (`tenant_id`, `employee_id`, `date`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 7. hr_leaves
CREATE TABLE `hr_leaves` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `leave_type` ENUM('annual', 'sick', 'emergency', 'unpaid', 'maternity', 'paternity', 'other') NOT NULL DEFAULT 'annual',
    `start_date` DATE NOT NULL,
    `end_date` DATE NOT NULL,
    `days` INT NOT NULL,
    `reason` TEXT NULL,
    `document_path` VARCHAR(255) NULL,
    `status` ENUM('pending', 'approved', 'rejected', 'cancelled') NOT NULL DEFAULT 'pending',
    `approved_by` BIGINT UNSIGNED NULL,
    `approved_at` TIMESTAMP NULL,
    `approval_notes` TEXT NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    INDEX `hr_leaves_tenant_id_employee_id_index` (`tenant_id`, `employee_id`),
    INDEX `hr_leaves_tenant_id_status_index` (`tenant_id`, `status`),
    INDEX `hr_leaves_tenant_id_start_date_end_date_index` (`tenant_id`, `start_date`, `end_date`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`approved_by`) REFERENCES `users`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 8. hr_salary_components
CREATE TABLE `hr_salary_components` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `code` VARCHAR(50) NULL,
    `type` ENUM('allowance', 'deduction', 'bonus') NOT NULL,
    `description` TEXT NULL,
    `is_recurring` TINYINT(1) NOT NULL DEFAULT 1,
    `is_taxable` TINYINT(1) NOT NULL DEFAULT 1,
    `affects_social_insurance` TINYINT(1) NOT NULL DEFAULT 0,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `hr_salary_components_tenant_id_code_unique` (`tenant_id`, `code`),
    INDEX `hr_salary_components_tenant_id_type_index` (`tenant_id`, `type`),
    INDEX `hr_salary_components_tenant_id_is_active_index` (`tenant_id`, `is_active`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 9. hr_employee_salary_components
CREATE TABLE `hr_employee_salary_components` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `salary_component_id` BIGINT UNSIGNED NOT NULL,
    `amount` DECIMAL(15, 2) NOT NULL,
    `amount_type` ENUM('fixed', 'percentage') NOT NULL DEFAULT 'fixed',
    `start_date` DATE NOT NULL,
    `end_date` DATE NULL,
    `is_active` TINYINT(1) NOT NULL DEFAULT 1,
    `notes` TEXT NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    INDEX `hr_employee_salary_components_tenant_id_employee_id_index` (`tenant_id`, `employee_id`),
    INDEX `hr_employee_salary_components_tenant_id_salary_component_id_index` (`tenant_id`, `salary_component_id`),
    INDEX `hr_employee_salary_components_tenant_id_is_active_index` (`tenant_id`, `is_active`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`salary_component_id`) REFERENCES `hr_salary_components`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 10. hr_payrolls
CREATE TABLE `hr_payrolls` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `year` INT NOT NULL,
    `month` INT NOT NULL,
    `period_name` VARCHAR(255) NULL,
    `basic_salary` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `total_allowances` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `total_bonuses` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `total_deductions` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `overtime_amount` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `working_days` INT NOT NULL DEFAULT 0,
    `present_days` INT NOT NULL DEFAULT 0,
    `absent_days` INT NOT NULL DEFAULT 0,
    `late_days` INT NOT NULL DEFAULT 0,
    `total_late_minutes` INT NOT NULL DEFAULT 0,
    `overtime_hours` INT NOT NULL DEFAULT 0,
    `paid_leave_days` INT NOT NULL DEFAULT 0,
    `unpaid_leave_days` INT NOT NULL DEFAULT 0,
    `gross_salary` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `net_salary` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `payment_status` ENUM('pending', 'paid', 'cancelled') NOT NULL DEFAULT 'pending',
    `payment_date` DATE NULL,
    `payment_method` VARCHAR(50) NULL,
    `payment_reference` VARCHAR(255) NULL,
    `notes` TEXT NULL,
    `details` JSON NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    UNIQUE KEY `hr_payrolls_tenant_id_employee_id_year_month_unique` (`tenant_id`, `employee_id`, `year`, `month`),
    INDEX `hr_payrolls_tenant_id_year_month_index` (`tenant_id`, `year`, `month`),
    INDEX `hr_payrolls_tenant_id_payment_status_index` (`tenant_id`, `payment_status`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 11. hr_overtime
CREATE TABLE `hr_overtime` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `date` DATE NOT NULL,
    `start_time` TIME NOT NULL,
    `end_time` TIME NOT NULL,
    `hours` INT NOT NULL,
    `rate_multiplier` DECIMAL(5, 2) NOT NULL DEFAULT 1.50,
    `amount` DECIMAL(15, 2) NOT NULL DEFAULT 0,
    `reason` TEXT NULL,
    `status` ENUM('pending', 'approved', 'rejected', 'paid') NOT NULL DEFAULT 'pending',
    `approved_by` BIGINT UNSIGNED NULL,
    `approved_at` TIMESTAMP NULL,
    `approval_notes` TEXT NULL,
    `payroll_id` BIGINT UNSIGNED NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    INDEX `hr_overtime_tenant_id_employee_id_index` (`tenant_id`, `employee_id`),
    INDEX `hr_overtime_tenant_id_date_index` (`tenant_id`, `date`),
    INDEX `hr_overtime_tenant_id_status_index` (`tenant_id`, `status`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`approved_by`) REFERENCES `users`(`id`) ON DELETE SET NULL,
    FOREIGN KEY (`payroll_id`) REFERENCES `hr_payrolls`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- 12. hr_employee_evaluations
CREATE TABLE `hr_employee_evaluations` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `tenant_id` BIGINT UNSIGNED NOT NULL,
    `employee_id` BIGINT UNSIGNED NOT NULL,
    `evaluator_id` BIGINT UNSIGNED NOT NULL,
    `evaluation_period` VARCHAR(255) NOT NULL,
    `evaluation_date` DATE NOT NULL,
    `evaluation_type` ENUM('probation', 'annual', 'quarterly', 'special') NOT NULL DEFAULT 'annual',
    `overall_rating` INT NULL,
    `performance_rating` INT NULL,
    `quality_rating` INT NULL,
    `attendance_rating` INT NULL,
    `teamwork_rating` INT NULL,
    `communication_rating` INT NULL,
    `strengths` TEXT NULL,
    `weaknesses` TEXT NULL,
    `recommendations` TEXT NULL,
    `goals` TEXT NULL,
    `notes` TEXT NULL,
    `created_at` TIMESTAMP NULL,
    `updated_at` TIMESTAMP NULL,
    `deleted_at` TIMESTAMP NULL,
    `created_by` BIGINT UNSIGNED NULL,
    `updated_by` BIGINT UNSIGNED NULL,
    `deleted_by` BIGINT UNSIGNED NULL,
    INDEX `hr_employee_evaluations_tenant_id_employee_id_index` (`tenant_id`, `employee_id`),
    INDEX `hr_employee_evaluations_tenant_id_evaluation_date_index` (`tenant_id`, `evaluation_date`),
    FOREIGN KEY (`tenant_id`) REFERENCES `tenants`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`employee_id`) REFERENCES `hr_employees`(`id`) ON DELETE CASCADE,
    FOREIGN KEY (`evaluator_id`) REFERENCES `users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
```

#### الخطوة 2: إضافة سجلات migrations يدويًا

بعد تشغيل SQL أعلاه بنجاح، نفذ هذا الأمر لتسجيل الـ migrations:

```sql
-- احصل على آخر batch number
SELECT MAX(batch) FROM migrations;
-- لنفترض أن النتيجة 11، إذن نستخدم 12 للجديد

-- إضافة سجلات migrations
INSERT INTO migrations (migration, batch) VALUES
('2026_03_25_100001_create_hr_departments_table', 12),
('2026_03_25_100002_create_hr_job_titles_table', 12),
('2026_03_25_100003_create_hr_employees_table', 12),
('2026_03_25_100004_add_manager_id_to_hr_departments_table', 12),
('2026_03_25_100005_create_hr_employee_documents_table', 12),
('2026_03_25_100006_create_hr_attendances_table', 12),
('2026_03_25_100007_create_hr_leaves_table', 12),
('2026_03_25_100008_create_hr_salary_components_table', 12),
('2026_03_25_100009_create_hr_employee_salary_components_table', 12),
('2026_03_25_100010_create_hr_payrolls_table', 12),
('2026_03_25_100011_create_hr_overtime_table', 12),
('2026_03_25_100012_create_hr_employee_evaluations_table', 12);
```

---

### الخيار 2: استخدام artisan migrate مع تجاهل الأخطاء

يمكنك محاولة تشغيل كل migration على حدة:

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

php artisan migrate:refresh --path=database/migrations/2026_03_25_100001_create_hr_departments_table.php --force
php artisan migrate:refresh --path=database/migrations/2026_03_25_100002_create_hr_job_titles_table.php --force
php artisan migrate:refresh --path=database/migrations/2026_03_25_100003_create_hr_employees_table.php --force
# ... وهكذا لبقية الملفات
```

---

## ✅ بعد التنفيذ

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

### 2. التحقق من الجداول
```sql
SHOW TABLES LIKE 'hr_%';
```

يجب أن ترى 12 جدول:
- hr_departments
- hr_job_titles
- hr_employees
- hr_employee_documents
- hr_attendances
- hr_leaves
- hr_salary_components
- hr_employee_salary_components
- hr_payrolls
- hr_overtime
- hr_employee_evaluations

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

### 4. الوصول للموديول

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

---

## ⚠️ ملاحظات مهمة

1. ✅ **لا يوجد حذف للبيانات** - هذا الحل لا يمس أي جداول موجودة
2. ✅ **الجداول الجديدة فقط** - يتم إنشاء جداول HR الجديدة فقط
3. ✅ **آمن تمامًا** - لا يؤثر على أي بيانات موجودة
4. ⚠️ **تحقق من الـ Foreign Keys** - تأكد أن جداول tenants, users, governorates, cities موجودة

---

## 🎊 الخلاصة

هذا الحل:
- ✅ لا يحذف أي بيانات موجودة
- ✅ يضيف جداول HR فقط
- ✅ يسجل الـ migrations بشكل صحيح
- ✅ آمن 100%

بعد التنفيذ، الموديول سيعمل بشكل طبيعي! 🚀
