-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Mar 09, 2026 at 12:46 PM
-- Server version: 11.8.3-MariaDB-log
-- PHP Version: 7.2.34

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `u133207124_ERP`
--

-- --------------------------------------------------------

--
-- Table structure for table `accounts`
--

CREATE TABLE `accounts` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `code` varchar(30) NOT NULL,
  `name` varchar(190) NOT NULL,
  `type` enum('ASSET','LIABILITY','EQUITY','REVENUE','EXPENSE') NOT NULL,
  `normal_side` enum('DEBIT','CREDIT') NOT NULL,
  `parent_id` int(11) DEFAULT NULL,
  `is_cash` tinyint(1) NOT NULL DEFAULT 0,
  `is_locked` tinyint(1) NOT NULL DEFAULT 1,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `accounts`
--

INSERT INTO `accounts` (`id`, `company_id`, `code`, `name`, `type`, `normal_side`, `parent_id`, `is_cash`, `is_locked`, `is_active`, `created_at`) VALUES
(1, 1, '1000', 'الأصول', 'ASSET', 'DEBIT', NULL, 0, 1, 1, '2026-03-06 14:45:18'),
(2, 1, '1100', 'الأصول المتداولة', 'ASSET', 'DEBIT', 1, 0, 1, 1, '2026-03-06 14:45:18'),
(3, 1, '1110', 'النقدية وما في حكمها', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(4, 1, '1111', 'خزينة رئيسية', 'ASSET', 'DEBIT', 3, 1, 1, 1, '2026-03-06 14:45:18'),
(5, 1, '1112', 'خزينة فرع / نقطة بيع', 'ASSET', 'DEBIT', 3, 1, 1, 1, '2026-03-06 14:45:18'),
(6, 1, '1120', 'البنوك', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(7, 1, '1121', 'حساب بنكي - جاري', 'ASSET', 'DEBIT', 6, 1, 1, 1, '2026-03-06 14:45:18'),
(8, 1, '1122', 'حساب بنكي - بطاقة/بوابة دفع', 'ASSET', 'DEBIT', 6, 1, 1, 1, '2026-03-06 14:45:18'),
(9, 1, '1130', 'عهد الموظفين', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(10, 1, '1140', 'مدفوعات مقدمة (مصاريف مقدمة)', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(11, 1, '1150', 'دفعات مقدمة لموردين', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(12, 1, '1200', 'الذمم المدينة', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(13, 1, '1210', 'عملاء (ذمم مدينة)', 'ASSET', 'DEBIT', 12, 0, 1, 1, '2026-03-06 14:45:18'),
(14, 1, '1220', 'ذمم موظفين', 'ASSET', 'DEBIT', 12, 0, 1, 1, '2026-03-06 14:45:18'),
(15, 1, '1230', 'تأمينات لدى الغير', 'ASSET', 'DEBIT', 12, 0, 1, 1, '2026-03-06 14:45:18'),
(16, 1, '1300', 'مخزون ومهمات تشغيل', 'ASSET', 'DEBIT', 2, 0, 1, 1, '2026-03-06 14:45:18'),
(17, 1, '1310', 'مستلزمات تشغيل الشقق/الفندق', 'ASSET', 'DEBIT', 16, 0, 1, 1, '2026-03-06 14:45:18'),
(18, 1, '1320', 'قطع غيار وصيانة سيارات', 'ASSET', 'DEBIT', 16, 0, 1, 1, '2026-03-06 14:45:18'),
(19, 1, '1400', 'الأصول غير المتداولة', 'ASSET', 'DEBIT', 1, 0, 1, 1, '2026-03-06 14:45:18'),
(20, 1, '1410', 'أصول ثابتة', 'ASSET', 'DEBIT', 19, 0, 1, 1, '2026-03-06 14:45:18'),
(21, 1, '1411', 'أثاث وتجهيزات', 'ASSET', 'DEBIT', 20, 0, 1, 1, '2026-03-06 14:45:18'),
(22, 1, '1412', 'أجهزة ومعدات', 'ASSET', 'DEBIT', 20, 0, 1, 1, '2026-03-06 14:45:18'),
(23, 1, '1413', 'سيارات (أصول ثابتة)', 'ASSET', 'DEBIT', 20, 0, 1, 1, '2026-03-06 14:45:18'),
(24, 1, '1420', 'مجمع الإهلاك', 'ASSET', 'CREDIT', 19, 0, 1, 1, '2026-03-06 14:45:18'),
(25, 1, '1421', 'مجمع إهلاك الأثاث والتجهيزات', 'ASSET', 'CREDIT', 24, 0, 1, 1, '2026-03-06 14:45:18'),
(26, 1, '1422', 'مجمع إهلاك الأجهزة والمعدات', 'ASSET', 'CREDIT', 24, 0, 1, 1, '2026-03-06 14:45:18'),
(27, 1, '1423', 'مجمع إهلاك السيارات', 'ASSET', 'CREDIT', 24, 0, 1, 1, '2026-03-06 14:45:18'),
(28, 1, '2000', 'الخصوم', 'LIABILITY', 'CREDIT', NULL, 0, 1, 1, '2026-03-06 14:45:18'),
(29, 1, '2100', 'الخصوم المتداولة', 'LIABILITY', 'CREDIT', 28, 0, 1, 1, '2026-03-06 14:45:18'),
(30, 1, '2110', 'ذمم دائنة / موردين', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(31, 1, '2120', 'مصاريف مستحقة', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(32, 1, '2130', 'رواتب مستحقة', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(33, 1, '2140', 'إيرادات مقدمة (حجوزات مقدمة)', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(34, 1, '2150', 'تأمينات العملاء (ودائع)', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(35, 1, '2160', 'ضرائب ورسوم مستحقة', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(36, 1, '2170', 'عمولات مستحقة للغير', 'LIABILITY', 'CREDIT', 29, 0, 1, 1, '2026-03-06 14:45:18'),
(37, 1, '3000', 'حقوق الملكية', 'EQUITY', 'CREDIT', NULL, 0, 1, 1, '2026-03-06 14:45:18'),
(38, 1, '3100', 'رأس المال', 'EQUITY', 'CREDIT', 37, 0, 1, 1, '2026-03-06 14:45:18'),
(39, 1, '3200', 'جاري الشركاء / المسحوبات', 'EQUITY', 'DEBIT', 37, 0, 1, 1, '2026-03-06 14:45:18'),
(40, 1, '3300', 'أرباح وخسائر مرحلة', 'EQUITY', 'CREDIT', 37, 0, 1, 1, '2026-03-06 14:45:18'),
(41, 1, '4000', 'الإيرادات', 'REVENUE', 'CREDIT', NULL, 0, 1, 1, '2026-03-06 14:45:18'),
(42, 1, '4100', 'إيرادات الإقامة', 'REVENUE', 'CREDIT', 41, 0, 1, 1, '2026-03-06 14:45:18'),
(43, 1, '4110', 'إيرادات تأجير شقق فندقية', 'REVENUE', 'CREDIT', 42, 0, 1, 1, '2026-03-06 14:45:18'),
(44, 1, '4120', 'إيرادات حجوزات فنادق', 'REVENUE', 'CREDIT', 42, 0, 1, 1, '2026-03-06 14:45:18'),
(45, 1, '4200', 'إيرادات النقل والسيارات', 'REVENUE', 'CREDIT', 41, 0, 1, 1, '2026-03-06 14:45:18'),
(46, 1, '4210', 'إيرادات تأجير سيارات', 'REVENUE', 'CREDIT', 45, 0, 1, 1, '2026-03-06 14:45:18'),
(47, 1, '4220', 'إيرادات انتقالات / ليموزين', 'REVENUE', 'CREDIT', 45, 0, 1, 1, '2026-03-06 14:45:18'),
(48, 1, '4300', 'إيرادات الرحلات السياحية', 'REVENUE', 'CREDIT', 41, 0, 1, 1, '2026-03-06 14:45:18'),
(49, 1, '4310', 'إيرادات الرحلات الداخلية', 'REVENUE', 'CREDIT', 48, 0, 1, 1, '2026-03-06 14:45:18'),
(50, 1, '4320', 'إيرادات برامج سياحية', 'REVENUE', 'CREDIT', 48, 0, 1, 1, '2026-03-06 14:45:18'),
(51, 1, '4400', 'إيرادات الطيران', 'REVENUE', 'CREDIT', 41, 0, 1, 1, '2026-03-06 14:45:18'),
(52, 1, '4410', 'عمولات تذاكر طيران', 'REVENUE', 'CREDIT', 51, 0, 1, 1, '2026-03-06 14:45:18'),
(53, 1, '4500', 'إيرادات الحج والعمرة', 'REVENUE', 'CREDIT', 41, 0, 1, 1, '2026-03-06 14:45:18'),
(54, 1, '4510', 'إيرادات العمرة', 'REVENUE', 'CREDIT', 53, 0, 1, 1, '2026-03-06 14:45:18'),
(55, 1, '4520', 'إيرادات الحج', 'REVENUE', 'CREDIT', 53, 0, 1, 1, '2026-03-06 14:45:18'),
(56, 1, '4600', 'إيرادات أخرى', 'REVENUE', 'CREDIT', 41, 0, 1, 1, '2026-03-06 14:45:18'),
(57, 1, '4610', 'إيرادات خدمات (تأشيرات/تأمين)', 'REVENUE', 'CREDIT', 56, 0, 1, 1, '2026-03-06 14:45:18'),
(58, 1, '4620', 'إيرادات غرامات/إلغاء', 'REVENUE', 'CREDIT', 56, 0, 1, 1, '2026-03-06 14:45:18'),
(59, 1, '5000', 'المصروفات', 'EXPENSE', 'DEBIT', NULL, 0, 1, 1, '2026-03-06 14:45:18'),
(60, 1, '5100', 'مصروفات تشغيل الإقامة', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(61, 1, '5110', 'مشتريات ومستلزمات النظافة', 'EXPENSE', 'DEBIT', 60, 0, 1, 1, '2026-03-06 14:45:18'),
(62, 1, '5120', 'صيانة الشقق/الفندق', 'EXPENSE', 'DEBIT', 60, 0, 1, 1, '2026-03-06 14:45:18'),
(63, 1, '5130', 'مفروشات صغيرة/استبدال', 'EXPENSE', 'DEBIT', 60, 0, 1, 1, '2026-03-06 14:45:18'),
(64, 1, '5200', 'مصروفات تشغيل السيارات', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(65, 1, '5210', 'بنزين وزيوت', 'EXPENSE', 'DEBIT', 64, 0, 1, 1, '2026-03-06 14:45:18'),
(66, 1, '5220', 'صيانة وإصلاح سيارات', 'EXPENSE', 'DEBIT', 64, 0, 1, 1, '2026-03-06 14:45:18'),
(67, 1, '5230', 'تأمين وترخيص سيارات', 'EXPENSE', 'DEBIT', 64, 0, 1, 1, '2026-03-06 14:45:18'),
(68, 1, '5240', 'مخالفات/غرامات سيارات', 'EXPENSE', 'DEBIT', 64, 0, 1, 1, '2026-03-06 14:45:18'),
(69, 1, '5300', 'مصروفات موظفين', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(70, 1, '5310', 'رواتب وأجور', 'EXPENSE', 'DEBIT', 69, 0, 1, 1, '2026-03-06 14:45:18'),
(71, 1, '5320', 'بدلات ومأموريات', 'EXPENSE', 'DEBIT', 69, 0, 1, 1, '2026-03-06 14:45:18'),
(72, 1, '5330', 'تأمينات اجتماعية', 'EXPENSE', 'DEBIT', 69, 0, 1, 1, '2026-03-06 14:45:18'),
(73, 1, '5400', 'مصروفات إدارية وعمومية', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(74, 1, '5410', 'إيجار مكتب', 'EXPENSE', 'DEBIT', 73, 0, 1, 1, '2026-03-06 14:45:18'),
(75, 1, '5420', 'كهرباء', 'EXPENSE', 'DEBIT', 73, 0, 1, 1, '2026-03-06 14:45:18'),
(76, 1, '5430', 'مياه', 'EXPENSE', 'DEBIT', 73, 0, 1, 1, '2026-03-06 14:45:18'),
(77, 1, '5440', 'غاز', 'EXPENSE', 'DEBIT', 73, 0, 1, 1, '2026-03-06 14:45:18'),
(78, 1, '5450', 'إنترنت واتصالات', 'EXPENSE', 'DEBIT', 73, 0, 1, 1, '2026-03-06 14:45:18'),
(79, 1, '5460', 'أدوات مكتبية', 'EXPENSE', 'DEBIT', 73, 0, 1, 1, '2026-03-06 14:45:18'),
(80, 1, '5500', 'مصروفات تسويق ومبيعات', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(81, 1, '5510', 'إعلانات ممولة', 'EXPENSE', 'DEBIT', 80, 0, 1, 1, '2026-03-06 14:45:18'),
(82, 1, '5520', 'عمولات مبيعات', 'EXPENSE', 'DEBIT', 80, 0, 1, 1, '2026-03-06 14:45:18'),
(83, 1, '5530', 'منصات حجز/بوابات دفع (رسوم)', 'EXPENSE', 'DEBIT', 80, 0, 1, 1, '2026-03-06 14:45:18'),
(84, 1, '5600', 'مصروفات مالية', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(85, 1, '5610', 'مصروفات بنكية', 'EXPENSE', 'DEBIT', 84, 0, 1, 1, '2026-03-06 14:45:18'),
(86, 1, '5620', 'فروق عملة', 'EXPENSE', 'DEBIT', 84, 0, 1, 1, '2026-03-06 14:45:18'),
(87, 1, '5700', 'إهلاك', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(88, 1, '5710', 'إهلاك أثاث وتجهيزات', 'EXPENSE', 'DEBIT', 87, 0, 1, 1, '2026-03-06 14:45:18'),
(89, 1, '5720', 'إهلاك أجهزة ومعدات', 'EXPENSE', 'DEBIT', 87, 0, 1, 1, '2026-03-06 14:45:18'),
(90, 1, '5730', 'إهلاك سيارات', 'EXPENSE', 'DEBIT', 87, 0, 1, 1, '2026-03-06 14:45:18'),
(91, 1, '5800', 'مصروفات أخرى', 'EXPENSE', 'DEBIT', 59, 0, 1, 1, '2026-03-06 14:45:18'),
(92, 1, '5810', 'ضيافة', 'EXPENSE', 'DEBIT', 91, 0, 1, 1, '2026-03-06 14:45:18'),
(93, 1, '5820', 'مصاريف قانونية/محاسبية', 'EXPENSE', 'DEBIT', 91, 0, 1, 1, '2026-03-06 14:45:18'),
(94, 1, '5830', 'خسائر/مردودات', 'EXPENSE', 'DEBIT', 91, 0, 1, 1, '2026-03-06 14:45:18');

--
-- Triggers `accounts`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_accounts_delete` AFTER DELETE ON `accounts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'accounts', 'DELETE', 'accounts', COALESCE(OLD.id, NULL), 'DELETE on accounts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_accounts_insert` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'accounts', 'INSERT', 'accounts', COALESCE(NEW.id, NULL), 'INSERT on accounts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_accounts_update` AFTER UPDATE ON `accounts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'accounts', 'UPDATE', 'accounts', COALESCE(NEW.id, NULL), 'UPDATE on accounts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `attendance`
--

CREATE TABLE `attendance` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `employee_id` int(11) NOT NULL,
  `work_date` date NOT NULL,
  `check_in` time DEFAULT NULL,
  `check_out` time DEFAULT NULL,
  `notes` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `attendance`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_attendance_delete` AFTER DELETE ON `attendance` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'attendance', COALESCE(OLD.id, NULL), 'DELETE on attendance', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_attendance_insert` AFTER INSERT ON `attendance` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'attendance', COALESCE(NEW.id, NULL), 'INSERT on attendance', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_attendance_update` AFTER UPDATE ON `attendance` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'attendance', COALESCE(NEW.id, NULL), 'UPDATE on attendance', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `audit_logs`
--

CREATE TABLE `audit_logs` (
  `id` bigint(20) NOT NULL,
  `company_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `module` varchar(100) NOT NULL,
  `action` varchar(100) NOT NULL,
  `table_name` varchar(100) DEFAULT NULL,
  `record_id` varchar(100) DEFAULT NULL,
  `entity_type` varchar(100) DEFAULT NULL,
  `entity_id` varchar(100) DEFAULT NULL,
  `description` varchar(255) DEFAULT NULL,
  `ip_address` varchar(64) DEFAULT NULL,
  `request_method` varchar(10) DEFAULT NULL,
  `request_uri` varchar(255) DEFAULT NULL,
  `page_path` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `audit_logs`
--

INSERT INTO `audit_logs` (`id`, `company_id`, `user_id`, `module`, `action`, `table_name`, `record_id`, `entity_type`, `entity_id`, `description`, `ip_address`, `request_method`, `request_uri`, `page_path`, `created_at`) VALUES
(1, 1, 1, 'backup', 'CREATE', NULL, NULL, 'backup', '8', 'إنشاء نسخة احتياطية داخلية جديدة', '102.43.33.157', NULL, NULL, '/settings/database.php', '2026-03-08 09:47:34'),
(2, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '102.43.33.157', NULL, NULL, '/auth/logout.php', '2026-03-08 10:14:12'),
(3, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 10:14:19'),
(4, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 10:23:27'),
(5, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 10:26:26'),
(6, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '102.43.33.157', NULL, NULL, '/auth/logout.php', '2026-03-08 10:26:31'),
(7, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 10:26:51'),
(8, 1, NULL, 'journal', 'INSERT', 'journal_entries', '10', NULL, NULL, 'INSERT on journal_entries', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:19'),
(9, 1, NULL, 'journal', 'INSERT', 'journal_lines', '1', NULL, NULL, 'INSERT on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:19'),
(10, 1, NULL, 'journal', 'INSERT', 'journal_lines', '2', NULL, NULL, 'INSERT on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:19'),
(11, NULL, NULL, 'cash', 'INSERT', 'cash_tx_journal_map', NULL, NULL, NULL, 'INSERT on cash_tx_journal_map', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:19'),
(12, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:19'),
(13, 1, NULL, 'journal', 'DELETE', 'journal_lines', '1', NULL, NULL, 'DELETE on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:32'),
(14, 1, NULL, 'journal', 'DELETE', 'journal_lines', '2', NULL, NULL, 'DELETE on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:32'),
(15, 1, NULL, 'journal', 'DELETE', 'journal_entries', '10', NULL, NULL, 'DELETE on journal_entries', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:32'),
(16, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:37:32'),
(17, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 10:39:12'),
(18, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:50:29'),
(19, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 10:51:52'),
(20, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:52:18'),
(21, 1, NULL, 'journal', 'INSERT', 'journal_entries', '11', NULL, NULL, 'INSERT on journal_entries', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:54:13'),
(22, 1, NULL, 'journal', 'INSERT', 'journal_lines', '3', NULL, NULL, 'INSERT on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:54:13'),
(23, 1, NULL, 'journal', 'INSERT', 'journal_lines', '4', NULL, NULL, 'INSERT on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:54:13'),
(24, NULL, NULL, 'cash', 'INSERT', 'cash_tx_journal_map', NULL, NULL, NULL, 'INSERT on cash_tx_journal_map', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:54:13'),
(25, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 10:54:13'),
(26, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '102.43.33.157', NULL, NULL, '/auth/logout.php', '2026-03-08 11:39:09'),
(27, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 11:39:16'),
(28, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 12:11:46'),
(29, 1, NULL, 'journal', 'DELETE', 'journal_lines', '3', NULL, NULL, 'DELETE on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:13:47'),
(30, 1, NULL, 'journal', 'DELETE', 'journal_lines', '4', NULL, NULL, 'DELETE on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:13:47'),
(31, 1, NULL, 'journal', 'DELETE', 'journal_entries', '11', NULL, NULL, 'DELETE on journal_entries', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:13:47'),
(32, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:13:47'),
(33, 1, NULL, 'users', 'INSERT', 'users', '2', NULL, NULL, 'INSERT on users', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:22:22'),
(34, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '102.43.33.157', NULL, NULL, '/auth/logout.php', '2026-03-08 12:22:37'),
(35, 1, 2, 'auth', 'LOGIN', NULL, NULL, 'user', '2', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 12:22:40'),
(36, 1, NULL, 'journal', 'INSERT', 'journal_entries', '12', NULL, NULL, 'INSERT on journal_entries', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:27:59'),
(37, 1, NULL, 'journal', 'INSERT', 'journal_lines', '5', NULL, NULL, 'INSERT on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:27:59'),
(38, 1, NULL, 'journal', 'INSERT', 'journal_lines', '6', NULL, NULL, 'INSERT on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:27:59'),
(39, NULL, NULL, 'cash', 'INSERT', 'cash_tx_journal_map', NULL, NULL, NULL, 'INSERT on cash_tx_journal_map', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:27:59'),
(40, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:27:59'),
(41, 1, NULL, 'journal', 'DELETE', 'journal_lines', '5', NULL, NULL, 'DELETE on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:28:53'),
(42, 1, NULL, 'journal', 'DELETE', 'journal_lines', '6', NULL, NULL, 'DELETE on journal_lines', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:28:53'),
(43, 1, NULL, 'journal', 'DELETE', 'journal_entries', '12', NULL, NULL, 'DELETE on journal_entries', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:28:53'),
(44, 1, NULL, 'cash', 'UPDATE', 'cash_transactions', '6', NULL, NULL, 'UPDATE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:28:53'),
(45, 1, NULL, 'cash', 'DELETE', 'cash_transactions', '6', NULL, NULL, 'DELETE on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:28:55'),
(46, 1, NULL, 'settings', 'UPDATE', 'companies', '1', NULL, NULL, 'UPDATE on companies', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:35:46'),
(47, 1, 1, 'settings', 'UPDATE_COMPANY', NULL, NULL, 'company', '1', 'تحديث بيانات الشركة الأساسية', '102.43.33.157', NULL, NULL, '/settings/company.php', '2026-03-08 12:35:46'),
(48, 1, NULL, 'settings', 'UPDATE', 'companies', '1', NULL, NULL, 'UPDATE on companies', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 12:36:06'),
(49, 1, 1, 'settings', 'UPDATE_COMPANY', NULL, NULL, 'company', '1', 'تحديث بيانات الشركة الأساسية', '102.43.33.157', NULL, NULL, '/settings/company.php', '2026-03-08 12:36:06'),
(50, 1, NULL, 'fleet', 'INSERT', 'vehicles', '1', NULL, NULL, 'INSERT on vehicles', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 13:13:59'),
(51, 1, NULL, 'tourism', 'INSERT', 'customers', '1', NULL, NULL, 'INSERT on customers', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 13:17:53'),
(52, 1, NULL, 'hotel', 'INSERT', 'hotel_hotels', '1', NULL, NULL, 'INSERT on hotel_hotels', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 13:27:01'),
(53, 1, NULL, 'hotel', 'INSERT', 'hotel_rooms', '1', NULL, NULL, 'INSERT on hotel_rooms', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 13:28:10'),
(54, 1, NULL, 'hotel', 'INSERT', 'hotel_bookings', '1', NULL, NULL, 'INSERT on hotel_bookings', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 13:29:37'),
(55, 1, NULL, 'fleet', 'UPDATE', 'vehicles', '1', NULL, NULL, 'UPDATE on vehicles', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 14:32:39'),
(56, 1, NULL, 'fleet', 'UPDATE', 'vehicles', '1', NULL, NULL, 'UPDATE on vehicles', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 14:33:03'),
(57, 1, NULL, 'cash', 'INSERT', 'cash_transactions', '7', NULL, NULL, 'INSERT on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 14:33:34'),
(58, 1, NULL, 'cash', 'INSERT', 'cash_transactions', '8', NULL, NULL, 'INSERT on cash_transactions', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 14:51:01'),
(59, 1, 1, 'cash', 'CREATE', NULL, NULL, 'cash_transaction', '8', 'إنشاء حركة مالية | النوع: وارد | المبلغ: 5,000.00 | حساب النقدية: 1112 - خزينة فرع / نقطة بيع | الحساب المقابل: 3100 - رأس المال | البيان: تمويل | التاريخ: 2026-03-08', '102.43.33.157', NULL, NULL, '/cash/index.php', '2026-03-08 14:51:01'),
(60, 1, NULL, 'fleet', 'INSERT', 'vehicle_contracts', '1', NULL, NULL, 'INSERT on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 15:39:49'),
(61, 1, NULL, 'fleet', 'UPDATE', 'vehicle_contracts', '1', NULL, NULL, 'UPDATE on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 15:40:14'),
(62, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '102.43.33.157', NULL, NULL, '/auth/logout.php', '2026-03-08 15:41:50'),
(63, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '102.43.33.157', NULL, NULL, '/auth/login.php', '2026-03-08 15:42:04'),
(64, 1, NULL, 'fleet', 'INSERT', 'vehicle_contracts', '2', NULL, NULL, 'INSERT on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 17:21:33'),
(65, 1, NULL, 'fleet', 'UPDATE', 'vehicle_contracts', '2', NULL, NULL, 'UPDATE on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 17:21:46'),
(66, 1, NULL, 'fleet', 'DELETE', 'vehicle_contracts', '2', NULL, NULL, 'DELETE on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 17:55:36'),
(67, 1, NULL, 'fleet', 'INSERT', 'vehicle_contracts', '3', NULL, NULL, 'INSERT on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 18:00:32'),
(68, 1, 1, 'fleet', 'CREATE_ORDER', NULL, NULL, 'vehicle_contract', '3', 'إصدار أمر تشغيل | رقم الأمر: 2 | النوع: أمر توصيلة | السيارة: 1 | القيمة: 0.00', '102.43.33.157', NULL, NULL, '/fleet/contracts.php', '2026-03-08 18:00:32'),
(69, 1, NULL, 'fleet', 'UPDATE', 'vehicle_contracts', '3', NULL, NULL, 'UPDATE on vehicle_contracts', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-08 18:29:08'),
(70, 1, 2, 'fleet', 'UPDATE_ORDER', NULL, NULL, 'vehicle_contract', '3', 'تعديل أمر تشغيل | رقم الأمر: 2 | النوع: أمر توصيلة | السيارة: 1 | القيمة: 500.00', '102.43.33.157', NULL, NULL, '/fleet/contracts.php', '2026-03-08 18:29:08'),
(71, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '154.178.21.185', NULL, NULL, '/auth/logout.php', '2026-03-09 00:16:50'),
(72, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '154.178.21.185', NULL, NULL, '/auth/login.php', '2026-03-09 00:16:58'),
(73, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '154.178.21.185', NULL, NULL, '/auth/logout.php', '2026-03-09 00:28:33'),
(74, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '154.178.21.185', NULL, NULL, '/auth/login.php', '2026-03-09 00:28:44'),
(75, 1, NULL, 'tourism', 'INSERT', 'customers', '2', NULL, NULL, 'INSERT on customers', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-09 08:15:22'),
(76, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '154.178.21.185', NULL, NULL, '/auth/login.php', '2026-03-09 08:31:02'),
(77, 1, NULL, 'hr', 'INSERT', 'employees', '1', NULL, NULL, 'INSERT on employees', 'u133207124_ERP', NULL, NULL, NULL, '2026-03-09 09:02:49'),
(78, 1, 1, 'auth', 'LOGOUT', NULL, NULL, 'user', '1', 'تسجيل خروج', '154.178.21.185', NULL, NULL, '/auth/logout.php', '2026-03-09 10:33:52'),
(79, 1, 1, 'auth', 'LOGIN', NULL, NULL, 'user', '1', 'تسجيل دخول ناجح', '154.178.21.185', NULL, NULL, '/auth/login.php', '2026-03-09 10:34:00'),
(80, 1, 1, 'fleet', 'CREATE_RENTAL_CONTRACT', NULL, NULL, 'vehicle_rental_contract', '1', 'إنشاء عقد تأجير RENT-1', '154.178.21.185', NULL, NULL, '/fleet/rentals.php', '2026-03-09 10:49:18');

-- --------------------------------------------------------

--
-- Table structure for table `backups`
--

CREATE TABLE `backups` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `file_name` varchar(255) NOT NULL,
  `original_name` varchar(255) DEFAULT NULL,
  `file_size` bigint(20) NOT NULL DEFAULT 0,
  `notes` varchar(255) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `restored_at` datetime DEFAULT NULL,
  `restored_by` int(11) DEFAULT NULL,
  `restore_count` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `backups`
--

INSERT INTO `backups` (`id`, `company_id`, `file_name`, `original_name`, `file_size`, `notes`, `created_by`, `created_at`, `restored_at`, `restored_by`, `restore_count`) VALUES
(7, 1, 'backup_1_20260308_085822.json', 'backup_1_20260308_085822.json', 37638, NULL, 1, '2026-03-08 08:58:22', '2026-03-08 08:58:27', 1, 1),
(8, 1, 'company_backup_1_20260308_094734_1e887215.json', 'company_backup_1_20260308_094734_1e887215.json', 96269, 'نسخة احتياطية شاملة لبيانات الشركة والملفات المرتبطة', 1, '2026-03-08 09:47:34', NULL, NULL, 0);

-- --------------------------------------------------------

--
-- Table structure for table `backup_logs`
--

CREATE TABLE `backup_logs` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `backup_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `action` varchar(50) DEFAULT NULL,
  `ip_address` varchar(50) DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

-- --------------------------------------------------------

--
-- Table structure for table `bookings`
--

CREATE TABLE `bookings` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `booking_no` varchar(30) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `booking_date` date NOT NULL,
  `status` enum('DRAFT','CONFIRMED','CANCELLED') NOT NULL DEFAULT 'DRAFT',
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `bookings`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_bookings_delete` AFTER DELETE ON `bookings` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'tourism', 'DELETE', 'bookings', COALESCE(OLD.id, NULL), 'DELETE on bookings', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_bookings_insert` AFTER INSERT ON `bookings` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'INSERT', 'bookings', COALESCE(NEW.id, NULL), 'INSERT on bookings', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_bookings_update` AFTER UPDATE ON `bookings` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'UPDATE', 'bookings', COALESCE(NEW.id, NULL), 'UPDATE on bookings', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `booking_items`
--

CREATE TABLE `booking_items` (
  `id` int(11) NOT NULL,
  `booking_id` int(11) NOT NULL,
  `service_id` int(11) NOT NULL,
  `supplier_id` int(11) DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `qty` decimal(14,2) NOT NULL DEFAULT 1.00,
  `unit_price` decimal(14,2) NOT NULL DEFAULT 0.00,
  `supplier_cost` decimal(14,2) NOT NULL DEFAULT 0.00,
  `notes` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `booking_items`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_booking_items_delete` AFTER DELETE ON `booking_items` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'tourism', 'DELETE', 'booking_items', COALESCE(OLD.id, NULL), 'DELETE on booking_items', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_booking_items_insert` AFTER INSERT ON `booking_items` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'tourism', 'INSERT', 'booking_items', COALESCE(NEW.id, NULL), 'INSERT on booking_items', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_booking_items_update` AFTER UPDATE ON `booking_items` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'tourism', 'UPDATE', 'booking_items', COALESCE(NEW.id, NULL), 'UPDATE on booking_items', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `cash_transactions`
--

CREATE TABLE `cash_transactions` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `tx_date` date NOT NULL,
  `tx_type` enum('IN','OUT') NOT NULL,
  `cash_account_id` int(11) NOT NULL,
  `counter_account_id` int(11) NOT NULL,
  `amount` decimal(14,2) NOT NULL,
  `memo` varchar(255) DEFAULT NULL,
  `attachment` varchar(255) DEFAULT NULL,
  `status` enum('ACTIVE','VOID') NOT NULL DEFAULT 'ACTIVE',
  `reversed_by_tx_id` int(11) DEFAULT NULL,
  `reverse_of_tx_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `cash_transactions`
--

INSERT INTO `cash_transactions` (`id`, `company_id`, `tx_date`, `tx_type`, `cash_account_id`, `counter_account_id`, `amount`, `memo`, `attachment`, `status`, `reversed_by_tx_id`, `reverse_of_tx_id`, `created_by`, `created_at`) VALUES
(7, 1, '2026-03-08', 'IN', 5, 38, 5000.00, 'تمويل', NULL, 'ACTIVE', NULL, NULL, 1, '2026-03-08 14:33:34'),
(8, 1, '2026-03-08', 'IN', 5, 38, 5000.00, 'تمويل', NULL, 'ACTIVE', NULL, NULL, 1, '2026-03-08 14:51:01');

--
-- Triggers `cash_transactions`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_cash_transactions_delete` AFTER DELETE ON `cash_transactions` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'cash', 'DELETE', 'cash_transactions', COALESCE(OLD.id, NULL), 'DELETE on cash_transactions', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_cash_transactions_insert` AFTER INSERT ON `cash_transactions` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'cash', 'INSERT', 'cash_transactions', COALESCE(NEW.id, NULL), 'INSERT on cash_transactions', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_cash_transactions_update` AFTER UPDATE ON `cash_transactions` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'cash', 'UPDATE', 'cash_transactions', COALESCE(NEW.id, NULL), 'UPDATE on cash_transactions', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `cash_tx_journal_map`
--

CREATE TABLE `cash_tx_journal_map` (
  `cash_tx_id` int(11) NOT NULL,
  `entry_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `cash_tx_journal_map`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_cash_tx_journal_map_delete` AFTER DELETE ON `cash_tx_journal_map` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'cash', 'DELETE', 'cash_tx_journal_map', NULL, 'DELETE on cash_tx_journal_map', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_cash_tx_journal_map_insert` AFTER INSERT ON `cash_tx_journal_map` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'cash', 'INSERT', 'cash_tx_journal_map', NULL, 'INSERT on cash_tx_journal_map', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_cash_tx_journal_map_update` AFTER UPDATE ON `cash_tx_journal_map` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'cash', 'UPDATE', 'cash_tx_journal_map', NULL, 'UPDATE on cash_tx_journal_map', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `companies`
--

CREATE TABLE `companies` (
  `id` int(11) NOT NULL,
  `name` varchar(150) NOT NULL,
  `currency` char(3) NOT NULL DEFAULT 'EGP',
  `tax_file_no` varchar(120) DEFAULT NULL,
  `commercial_register_no` varchar(120) DEFAULT NULL,
  `phone1` varchar(60) DEFAULT NULL,
  `phone2` varchar(60) DEFAULT NULL,
  `logo` varchar(255) DEFAULT NULL,
  `logo_path` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `companies`
--

INSERT INTO `companies` (`id`, `name`, `currency`, `tax_file_no`, `commercial_register_no`, `phone1`, `phone2`, `logo`, `logo_path`, `created_at`) VALUES
(1, 'Adnan Hotel', 'EGP', '123-456-789', '123-456', '01004566304', '01004566304', NULL, '/uploads/company/company_2_1772885796.png', '2026-03-06 14:45:18');

--
-- Triggers `companies`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_companies_delete` AFTER DELETE ON `companies` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.id, @audit_company_id), @audit_user_id, 'settings', 'DELETE', 'companies', COALESCE(OLD.id, NULL), 'DELETE on companies', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_companies_insert` AFTER INSERT ON `companies` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.id, @audit_company_id), @audit_user_id, 'settings', 'INSERT', 'companies', COALESCE(NEW.id, NULL), 'INSERT on companies', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_companies_update` AFTER UPDATE ON `companies` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.id, @audit_company_id), @audit_user_id, 'settings', 'UPDATE', 'companies', COALESCE(NEW.id, NULL), 'UPDATE on companies', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `customers`
--

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `code` varchar(60) DEFAULT NULL,
  `full_name` varchar(190) NOT NULL,
  `phone` varchar(60) DEFAULT NULL,
  `email` varchar(190) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `status` enum('ACTIVE','INACTIVE') NOT NULL DEFAULT 'ACTIVE',
  `account_id` int(11) DEFAULT NULL,
  `opening_balance` decimal(14,2) NOT NULL DEFAULT 0.00,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `customers`
--

INSERT INTO `customers` (`id`, `company_id`, `code`, `full_name`, `phone`, `email`, `address`, `status`, `account_id`, `opening_balance`, `notes`, `created_at`) VALUES
(1, 1, '١', 'Mahmoud Hassan', '01004566304', 'acc.mhm.egy@gmail.com', 'ش الجمعية', 'ACTIVE', NULL, 0.00, '', '2026-03-08 13:17:53'),
(2, 1, NULL, 'نزيل الفندق', NULL, NULL, NULL, 'ACTIVE', NULL, 0.00, 'عميل افتراضي لتشغيل الليموزين', '2026-03-09 08:15:22');

--
-- Triggers `customers`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_customers_delete` AFTER DELETE ON `customers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'tourism', 'DELETE', 'customers', COALESCE(OLD.id, NULL), 'DELETE on customers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_customers_insert` AFTER INSERT ON `customers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'INSERT', 'customers', COALESCE(NEW.id, NULL), 'INSERT on customers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_customers_update` AFTER UPDATE ON `customers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'UPDATE', 'customers', COALESCE(NEW.id, NULL), 'UPDATE on customers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `employees`
--

CREATE TABLE `employees` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `code` varchar(30) DEFAULT NULL,
  `full_name` varchar(190) NOT NULL,
  `phone` varchar(60) DEFAULT NULL,
  `email` varchar(190) DEFAULT NULL,
  `national_id` varchar(80) DEFAULT NULL,
  `hire_date` date DEFAULT NULL,
  `birth_date` date DEFAULT NULL,
  `job_title` varchar(120) DEFAULT NULL,
  `salary_monthly` decimal(12,2) NOT NULL DEFAULT 0.00,
  `salary_currency` varchar(10) NOT NULL DEFAULT 'LE',
  `status` enum('ACTIVE','INACTIVE') NOT NULL DEFAULT 'ACTIVE',
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `employees`
--

INSERT INTO `employees` (`id`, `company_id`, `code`, `full_name`, `phone`, `email`, `national_id`, `hire_date`, `birth_date`, `job_title`, `salary_monthly`, `salary_currency`, `status`, `notes`, `created_at`, `updated_at`) VALUES
(1, 1, NULL, 'محمود حسن', '01004566304', 'acc.mhm.egy@gmail.com', NULL, '2026-03-09', NULL, 'مدير مالي', 15000.00, 'LE', 'ACTIVE', NULL, '2026-03-09 09:02:49', NULL);

--
-- Triggers `employees`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_employees_delete` AFTER DELETE ON `employees` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'employees', COALESCE(OLD.id, NULL), 'DELETE on employees', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employees_insert` AFTER INSERT ON `employees` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'employees', COALESCE(NEW.id, NULL), 'INSERT on employees', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employees_update` AFTER UPDATE ON `employees` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'employees', COALESCE(NEW.id, NULL), 'UPDATE on employees', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `employee_advances`
--

CREATE TABLE `employee_advances` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `employee_id` int(11) NOT NULL,
  `tx_date` date NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `currency` varchar(10) NOT NULL DEFAULT 'LE',
  `memo` varchar(255) DEFAULT NULL,
  `status` enum('OPEN','SETTLED','VOID') NOT NULL DEFAULT 'OPEN',
  `attachment_path` varchar(255) DEFAULT NULL,
  `cash_tx_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `employee_advances`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advances_delete` AFTER DELETE ON `employee_advances` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'employee_advances', COALESCE(OLD.id, NULL), 'DELETE on employee_advances', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advances_insert` AFTER INSERT ON `employee_advances` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'employee_advances', COALESCE(NEW.id, NULL), 'INSERT on employee_advances', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advances_update` AFTER UPDATE ON `employee_advances` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'employee_advances', COALESCE(NEW.id, NULL), 'UPDATE on employee_advances', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `employee_advance_settlements`
--

CREATE TABLE `employee_advance_settlements` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `advance_id` int(11) NOT NULL,
  `settle_date` date NOT NULL,
  `kind` enum('EXPENSE','RETURN') NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `expense_account_id` int(11) DEFAULT NULL,
  `memo` varchar(255) DEFAULT NULL,
  `attachment_path` varchar(255) DEFAULT NULL,
  `cash_tx_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `employee_advance_settlements`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advance_settlements_delete` AFTER DELETE ON `employee_advance_settlements` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'employee_advance_settlements', COALESCE(OLD.id, NULL), 'DELETE on employee_advance_settlements', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advance_settlements_insert` AFTER INSERT ON `employee_advance_settlements` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'employee_advance_settlements', COALESCE(NEW.id, NULL), 'INSERT on employee_advance_settlements', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advance_settlements_update` AFTER UPDATE ON `employee_advance_settlements` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'employee_advance_settlements', COALESCE(NEW.id, NULL), 'UPDATE on employee_advance_settlements', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `employee_advance_transfers`
--

CREATE TABLE `employee_advance_transfers` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `source_advance_id` int(11) NOT NULL,
  `target_advance_id` int(11) NOT NULL,
  `from_employee_id` int(11) NOT NULL,
  `to_employee_id` int(11) NOT NULL,
  `transfer_date` date NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `memo` varchar(255) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `employee_advance_transfers`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advance_transfers_delete` AFTER DELETE ON `employee_advance_transfers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'employee_advance_transfers', COALESCE(OLD.id, NULL), 'DELETE on employee_advance_transfers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advance_transfers_insert` AFTER INSERT ON `employee_advance_transfers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'employee_advance_transfers', COALESCE(NEW.id, NULL), 'INSERT on employee_advance_transfers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_employee_advance_transfers_update` AFTER UPDATE ON `employee_advance_transfers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'employee_advance_transfers', COALESCE(NEW.id, NULL), 'UPDATE on employee_advance_transfers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `financial_events`
--

CREATE TABLE `financial_events` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `event_date` date NOT NULL,
  `event_type` enum('INVOICE','PAYMENT') NOT NULL,
  `ref_table` varchar(50) DEFAULT NULL,
  `ref_id` int(11) DEFAULT NULL,
  `memo` varchar(255) DEFAULT NULL,
  `status` enum('DRAFT','POSTED') NOT NULL DEFAULT 'DRAFT',
  `entry_id` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `financial_events`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_financial_events_delete` AFTER DELETE ON `financial_events` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'journal', 'DELETE', 'financial_events', COALESCE(OLD.id, NULL), 'DELETE on financial_events', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_financial_events_insert` AFTER INSERT ON `financial_events` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'journal', 'INSERT', 'financial_events', COALESCE(NEW.id, NULL), 'INSERT on financial_events', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_financial_events_update` AFTER UPDATE ON `financial_events` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'journal', 'UPDATE', 'financial_events', COALESCE(NEW.id, NULL), 'UPDATE on financial_events', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `financial_event_lines`
--

CREATE TABLE `financial_event_lines` (
  `id` int(11) NOT NULL,
  `event_id` int(11) NOT NULL,
  `account_id` int(11) NOT NULL,
  `debit` decimal(14,2) NOT NULL DEFAULT 0.00,
  `credit` decimal(14,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `financial_event_lines`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_financial_event_lines_delete` AFTER DELETE ON `financial_event_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'journal', 'DELETE', 'financial_event_lines', COALESCE(OLD.id, NULL), 'DELETE on financial_event_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_financial_event_lines_insert` AFTER INSERT ON `financial_event_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'journal', 'INSERT', 'financial_event_lines', COALESCE(NEW.id, NULL), 'INSERT on financial_event_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_financial_event_lines_update` AFTER UPDATE ON `financial_event_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'journal', 'UPDATE', 'financial_event_lines', COALESCE(NEW.id, NULL), 'UPDATE on financial_event_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `fleet_limo_serials`
--

CREATE TABLE `fleet_limo_serials` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `serial_no` int(11) NOT NULL,
  `trip_date` date DEFAULT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `status` enum('OPEN','DONE','CANCELLED') NOT NULL DEFAULT 'OPEN',
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `fleet_limo_serials`
--

INSERT INTO `fleet_limo_serials` (`id`, `company_id`, `serial_no`, `trip_date`, `customer_id`, `status`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 1, '2026-03-09', 2, 'OPEN', 1, '2026-03-09 09:01:01', NULL);

-- --------------------------------------------------------

--
-- Table structure for table `fleet_limo_trips`
--

CREATE TABLE `fleet_limo_trips` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `serial_id` int(11) NOT NULL,
  `trip_no` int(11) NOT NULL DEFAULT 1,
  `display_no` varchar(60) NOT NULL,
  `vehicle_id` int(11) NOT NULL,
  `driver_id` int(11) DEFAULT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `trip_status` enum('REQUESTED','DONE','COLLECTED','CANCELLED') NOT NULL DEFAULT 'REQUESTED',
  `trip_date` date NOT NULL,
  `pickup_time` time DEFAULT NULL,
  `pickup_location_id` int(11) DEFAULT NULL,
  `dropoff_location_id` int(11) DEFAULT NULL,
  `km_out` decimal(12,2) NOT NULL DEFAULT 0.00,
  `km_in` decimal(12,2) DEFAULT NULL,
  `used_km` decimal(12,2) NOT NULL DEFAULT 0.00,
  `trip_amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `payment_type` enum('CASH','CREDIT') NOT NULL DEFAULT 'CASH',
  `expected_collection_date` date DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `attachment_path` varchar(255) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `fleet_limo_trips`
--

INSERT INTO `fleet_limo_trips` (`id`, `company_id`, `serial_id`, `trip_no`, `display_no`, `vehicle_id`, `driver_id`, `customer_id`, `trip_status`, `trip_date`, `pickup_time`, `pickup_location_id`, `dropoff_location_id`, `km_out`, `km_in`, `used_km`, `trip_amount`, `payment_type`, `expected_collection_date`, `notes`, `attachment_path`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 1, 1, '1-1', 1, 1, 2, 'REQUESTED', '2026-03-09', '11:00:00', 1, 1, 1000.00, 1200.00, 200.00, 0.00, 'CASH', NULL, '', NULL, 1, '2026-03-09 09:01:01', '2026-03-09 09:03:10'),
(2, 1, 1, 2, '1-2', 1, 1, 1, 'DONE', '2026-03-09', '11:12:00', 1, 1, 1200.00, 1300.00, 100.00, 100.00, 'CREDIT', '2026-03-09', '', NULL, 1, '2026-03-09 09:12:52', NULL);

-- --------------------------------------------------------

--
-- Table structure for table `fleet_locations`
--

CREATE TABLE `fleet_locations` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `name` varchar(190) NOT NULL,
  `is_pickup` tinyint(1) NOT NULL DEFAULT 1,
  `is_dropoff` tinyint(1) NOT NULL DEFAULT 1,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `fleet_locations`
--

INSERT INTO `fleet_locations` (`id`, `company_id`, `name`, `is_pickup`, `is_dropoff`, `is_active`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 'وسط البلد', 1, 1, 1, 1, '2026-03-09 08:15:17', NULL);

-- --------------------------------------------------------

--
-- Table structure for table `fleet_rentals`
--

CREATE TABLE `fleet_rentals` (
  `id` int(11) NOT NULL,
  `company_id` int(11) DEFAULT NULL,
  `serial_id` varchar(50) DEFAULT NULL,
  `car_id` int(11) DEFAULT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `contract_type` enum('commercial','service') DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `expected_end_date` date DEFAULT NULL,
  `km_out` int(11) DEFAULT NULL,
  `km_in` int(11) DEFAULT NULL,
  `extra_day_price` decimal(10,2) DEFAULT NULL,
  `extra_km_price` decimal(10,2) DEFAULT NULL,
  `deposit_amount` decimal(10,2) DEFAULT NULL,
  `insurance_type` enum('company','customer') DEFAULT NULL,
  `status` enum('open','closed') DEFAULT 'open',
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `fleet_rental_services`
--

CREATE TABLE `fleet_rental_services` (
  `id` int(11) NOT NULL,
  `rental_id` int(11) DEFAULT NULL,
  `service_type` varchar(100) DEFAULT NULL,
  `price` decimal(10,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `hotel_bookings`
--

CREATE TABLE `hotel_bookings` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `request_no` varchar(60) NOT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `hotel_id` int(11) NOT NULL,
  `room_id` int(11) DEFAULT NULL,
  `request_date` date NOT NULL,
  `checkin_date` date NOT NULL,
  `checkout_date` date NOT NULL,
  `nights` int(11) NOT NULL DEFAULT 1,
  `adults_count` int(11) NOT NULL DEFAULT 1,
  `children_count` int(11) NOT NULL DEFAULT 0,
  `meal_plan` varchar(100) DEFAULT NULL,
  `booking_type` enum('ROOM','PACKAGE') NOT NULL DEFAULT 'ROOM',
  `payment_type` enum('CASH','CREDIT') NOT NULL DEFAULT 'CREDIT',
  `status` enum('PENDING','PRICED','CONFIRMED','CANCELLED','CHECKED_IN','CHECKED_OUT') NOT NULL DEFAULT 'PENDING',
  `cost_price` decimal(14,2) NOT NULL DEFAULT 0.00,
  `sale_price` decimal(14,2) NOT NULL DEFAULT 0.00,
  `total_cost` decimal(14,2) NOT NULL DEFAULT 0.00,
  `total_sale` decimal(14,2) NOT NULL DEFAULT 0.00,
  `voucher_notes` text DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `posted_entry_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `hotel_bookings`
--

INSERT INTO `hotel_bookings` (`id`, `company_id`, `request_no`, `customer_id`, `hotel_id`, `room_id`, `request_date`, `checkin_date`, `checkout_date`, `nights`, `adults_count`, `children_count`, `meal_plan`, `booking_type`, `payment_type`, `status`, `cost_price`, `sale_price`, `total_cost`, `total_sale`, `voucher_notes`, `notes`, `posted_entry_id`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 'HB-00001', 1, 1, 1, '2026-03-08', '2026-03-08', '2026-03-09', 1, 1, 25, 'AI', 'ROOM', 'CASH', 'PENDING', 25.00, 100.00, 150.00, 200.00, '', '', NULL, 1, '2026-03-08 13:29:37', NULL);

--
-- Triggers `hotel_bookings`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_bookings_delete` AFTER DELETE ON `hotel_bookings` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hotel', 'DELETE', 'hotel_bookings', COALESCE(OLD.id, NULL), 'DELETE on hotel_bookings', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_bookings_insert` AFTER INSERT ON `hotel_bookings` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'INSERT', 'hotel_bookings', COALESCE(NEW.id, NULL), 'INSERT on hotel_bookings', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_bookings_update` AFTER UPDATE ON `hotel_bookings` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'UPDATE', 'hotel_bookings', COALESCE(NEW.id, NULL), 'UPDATE on hotel_bookings', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `hotel_hotels`
--

CREATE TABLE `hotel_hotels` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `code` varchar(50) DEFAULT NULL,
  `name` varchar(190) NOT NULL,
  `ownership_type` enum('OWNED','THIRD_PARTY') NOT NULL DEFAULT 'THIRD_PARTY',
  `city` varchar(120) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `contact_person` varchar(120) DEFAULT NULL,
  `phone` varchar(60) DEFAULT NULL,
  `email` varchar(190) DEFAULT NULL,
  `status` enum('ACTIVE','INACTIVE') NOT NULL DEFAULT 'ACTIVE',
  `notes` text DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `hotel_hotels`
--

INSERT INTO `hotel_hotels` (`id`, `company_id`, `code`, `name`, `ownership_type`, `city`, `address`, `contact_person`, `phone`, `email`, `status`, `notes`, `created_by`, `created_at`) VALUES
(1, 1, '١', 'Adnan Hotel', 'OWNED', 'Cairo', 'Cairo', 'MHM', '01004566304', 'Acc.mhm.egy@gmail.com', 'ACTIVE', '', 1, '2026-03-08 13:27:01');

--
-- Triggers `hotel_hotels`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_hotels_delete` AFTER DELETE ON `hotel_hotels` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hotel', 'DELETE', 'hotel_hotels', COALESCE(OLD.id, NULL), 'DELETE on hotel_hotels', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_hotels_insert` AFTER INSERT ON `hotel_hotels` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'INSERT', 'hotel_hotels', COALESCE(NEW.id, NULL), 'INSERT on hotel_hotels', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_hotels_update` AFTER UPDATE ON `hotel_hotels` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'UPDATE', 'hotel_hotels', COALESCE(NEW.id, NULL), 'UPDATE on hotel_hotels', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `hotel_receipts`
--

CREATE TABLE `hotel_receipts` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `receipt_no` varchar(60) NOT NULL,
  `booking_id` int(11) DEFAULT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `receipt_date` date NOT NULL,
  `cash_account_id` int(11) NOT NULL,
  `amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `payment_method` enum('CASH','BANK') NOT NULL DEFAULT 'CASH',
  `notes` text DEFAULT NULL,
  `posted_entry_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `hotel_receipts`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_receipts_delete` AFTER DELETE ON `hotel_receipts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hotel', 'DELETE', 'hotel_receipts', COALESCE(OLD.id, NULL), 'DELETE on hotel_receipts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_receipts_insert` AFTER INSERT ON `hotel_receipts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'INSERT', 'hotel_receipts', COALESCE(NEW.id, NULL), 'INSERT on hotel_receipts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_receipts_update` AFTER UPDATE ON `hotel_receipts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'UPDATE', 'hotel_receipts', COALESCE(NEW.id, NULL), 'UPDATE on hotel_receipts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `hotel_rooms`
--

CREATE TABLE `hotel_rooms` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `hotel_id` int(11) NOT NULL,
  `room_no` varchar(60) NOT NULL,
  `room_name` varchar(120) DEFAULT NULL,
  `room_type` varchar(120) DEFAULT NULL,
  `ownership_type` enum('OWNED','THIRD_PARTY') NOT NULL DEFAULT 'THIRD_PARTY',
  `capacity_adults` int(11) NOT NULL DEFAULT 2,
  `capacity_children` int(11) NOT NULL DEFAULT 0,
  `base_cost` decimal(14,2) NOT NULL DEFAULT 0.00,
  `base_price` decimal(14,2) NOT NULL DEFAULT 0.00,
  `status` enum('AVAILABLE','OUT_OF_SERVICE','INACTIVE') NOT NULL DEFAULT 'AVAILABLE',
  `notes` text DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `hotel_rooms`
--

INSERT INTO `hotel_rooms` (`id`, `company_id`, `hotel_id`, `room_no`, `room_name`, `room_type`, `ownership_type`, `capacity_adults`, `capacity_children`, `base_cost`, `base_price`, `status`, `notes`, `created_by`, `created_at`) VALUES
(1, 1, 1, 'B1', 'غرفة الروقان', 'Double', 'OWNED', 2, 2, 50.00, 100.00, 'AVAILABLE', '', 1, '2026-03-08 13:28:10');

--
-- Triggers `hotel_rooms`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_rooms_delete` AFTER DELETE ON `hotel_rooms` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hotel', 'DELETE', 'hotel_rooms', COALESCE(OLD.id, NULL), 'DELETE on hotel_rooms', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_rooms_insert` AFTER INSERT ON `hotel_rooms` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'INSERT', 'hotel_rooms', COALESCE(NEW.id, NULL), 'INSERT on hotel_rooms', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_hotel_rooms_update` AFTER UPDATE ON `hotel_rooms` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hotel', 'UPDATE', 'hotel_rooms', COALESCE(NEW.id, NULL), 'UPDATE on hotel_rooms', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `invoices`
--

CREATE TABLE `invoices` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `invoice_no` varchar(30) NOT NULL,
  `invoice_date` date NOT NULL,
  `customer_id` int(11) NOT NULL,
  `booking_id` int(11) DEFAULT NULL,
  `status` enum('DRAFT','ISSUED','PAID','CANCELLED') NOT NULL DEFAULT 'DRAFT',
  `total` decimal(14,2) NOT NULL DEFAULT 0.00,
  `paid` decimal(14,2) NOT NULL DEFAULT 0.00,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `invoices`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_invoices_delete` AFTER DELETE ON `invoices` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'tourism', 'DELETE', 'invoices', COALESCE(OLD.id, NULL), 'DELETE on invoices', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_invoices_insert` AFTER INSERT ON `invoices` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'INSERT', 'invoices', COALESCE(NEW.id, NULL), 'INSERT on invoices', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_invoices_update` AFTER UPDATE ON `invoices` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'UPDATE', 'invoices', COALESCE(NEW.id, NULL), 'UPDATE on invoices', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `invoice_lines`
--

CREATE TABLE `invoice_lines` (
  `id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `description` varchar(255) NOT NULL,
  `revenue_account_id` int(11) NOT NULL,
  `qty` decimal(14,2) NOT NULL DEFAULT 1.00,
  `unit_price` decimal(14,2) NOT NULL DEFAULT 0.00,
  `line_total` decimal(14,2) NOT NULL DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `invoice_lines`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_invoice_lines_delete` AFTER DELETE ON `invoice_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'tourism', 'DELETE', 'invoice_lines', COALESCE(OLD.id, NULL), 'DELETE on invoice_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_invoice_lines_insert` AFTER INSERT ON `invoice_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'tourism', 'INSERT', 'invoice_lines', COALESCE(NEW.id, NULL), 'INSERT on invoice_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_invoice_lines_update` AFTER UPDATE ON `invoice_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (@audit_company_id, @audit_user_id, 'tourism', 'UPDATE', 'invoice_lines', COALESCE(NEW.id, NULL), 'UPDATE on invoice_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `journal_entries`
--

CREATE TABLE `journal_entries` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `entry_date` date NOT NULL,
  `ref` varchar(60) DEFAULT NULL,
  `memo` varchar(255) DEFAULT NULL,
  `source` enum('MANUAL','CASH_TX') NOT NULL DEFAULT 'CASH_TX',
  `source_id` int(11) DEFAULT NULL,
  `status` enum('DRAFT','POSTED','VOID') NOT NULL DEFAULT 'POSTED',
  `reversed_entry_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `journal_entries`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_journal_entries_delete` AFTER DELETE ON `journal_entries` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'journal', 'DELETE', 'journal_entries', COALESCE(OLD.id, NULL), 'DELETE on journal_entries', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_journal_entries_insert` AFTER INSERT ON `journal_entries` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'journal', 'INSERT', 'journal_entries', COALESCE(NEW.id, NULL), 'INSERT on journal_entries', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_journal_entries_update` AFTER UPDATE ON `journal_entries` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'journal', 'UPDATE', 'journal_entries', COALESCE(NEW.id, NULL), 'UPDATE on journal_entries', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `journal_lines`
--

CREATE TABLE `journal_lines` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `entry_id` int(11) NOT NULL,
  `line_no` int(11) NOT NULL,
  `account_id` int(11) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `debit` decimal(14,2) NOT NULL DEFAULT 0.00,
  `credit` decimal(14,2) NOT NULL DEFAULT 0.00,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `journal_lines`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_journal_lines_delete` AFTER DELETE ON `journal_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'journal', 'DELETE', 'journal_lines', COALESCE(OLD.id, NULL), 'DELETE on journal_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_journal_lines_insert` AFTER INSERT ON `journal_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'journal', 'INSERT', 'journal_lines', COALESCE(NEW.id, NULL), 'INSERT on journal_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_journal_lines_update` AFTER UPDATE ON `journal_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'journal', 'UPDATE', 'journal_lines', COALESCE(NEW.id, NULL), 'UPDATE on journal_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `missions`
--

CREATE TABLE `missions` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `employee_id` int(11) NOT NULL,
  `mission_date` date NOT NULL,
  `title` varchar(190) NOT NULL,
  `location` varchar(190) DEFAULT NULL,
  `from_time` time DEFAULT NULL,
  `to_time` time DEFAULT NULL,
  `allowance` decimal(12,2) NOT NULL DEFAULT 0.00,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `missions`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_missions_delete` AFTER DELETE ON `missions` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'missions', COALESCE(OLD.id, NULL), 'DELETE on missions', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_missions_insert` AFTER INSERT ON `missions` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'missions', COALESCE(NEW.id, NULL), 'INSERT on missions', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_missions_update` AFTER UPDATE ON `missions` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'missions', COALESCE(NEW.id, NULL), 'UPDATE on missions', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `operation_serials`
--

CREATE TABLE `operation_serials` (
  `id` int(11) NOT NULL,
  `company_id` int(11) DEFAULT NULL,
  `serial` varchar(50) DEFAULT NULL,
  `type` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `payments`
--

CREATE TABLE `payments` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `invoice_id` int(11) NOT NULL,
  `pay_date` date NOT NULL,
  `cash_account_id` int(11) NOT NULL,
  `amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `payments`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_payments_delete` AFTER DELETE ON `payments` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'tourism', 'DELETE', 'payments', COALESCE(OLD.id, NULL), 'DELETE on payments', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_payments_insert` AFTER INSERT ON `payments` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'INSERT', 'payments', COALESCE(NEW.id, NULL), 'INSERT on payments', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_payments_update` AFTER UPDATE ON `payments` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'UPDATE', 'payments', COALESCE(NEW.id, NULL), 'UPDATE on payments', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `payroll_lines`
--

CREATE TABLE `payroll_lines` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `payroll_id` int(11) NOT NULL,
  `employee_id` int(11) NOT NULL,
  `base_salary` decimal(12,2) NOT NULL DEFAULT 0.00,
  `additions` decimal(12,2) NOT NULL DEFAULT 0.00,
  `deductions` decimal(12,2) NOT NULL DEFAULT 0.00,
  `advances_deduction` decimal(12,2) NOT NULL DEFAULT 0.00,
  `net_salary` decimal(12,2) NOT NULL DEFAULT 0.00,
  `notes` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `payroll_lines`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_payroll_lines_delete` AFTER DELETE ON `payroll_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'payroll_lines', COALESCE(OLD.id, NULL), 'DELETE on payroll_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_payroll_lines_insert` AFTER INSERT ON `payroll_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'payroll_lines', COALESCE(NEW.id, NULL), 'INSERT on payroll_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_payroll_lines_update` AFTER UPDATE ON `payroll_lines` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'payroll_lines', COALESCE(NEW.id, NULL), 'UPDATE on payroll_lines', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `payroll_runs`
--

CREATE TABLE `payroll_runs` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `period_year` int(11) NOT NULL,
  `period_month` int(11) NOT NULL,
  `run_date` date NOT NULL,
  `status` enum('DRAFT','POSTED') NOT NULL DEFAULT 'DRAFT',
  `notes` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `payroll_runs`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_payroll_runs_delete` AFTER DELETE ON `payroll_runs` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'hr', 'DELETE', 'payroll_runs', COALESCE(OLD.id, NULL), 'DELETE on payroll_runs', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_payroll_runs_insert` AFTER INSERT ON `payroll_runs` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'INSERT', 'payroll_runs', COALESCE(NEW.id, NULL), 'INSERT on payroll_runs', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_payroll_runs_update` AFTER UPDATE ON `payroll_runs` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'hr', 'UPDATE', 'payroll_runs', COALESCE(NEW.id, NULL), 'UPDATE on payroll_runs', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `services`
--

CREATE TABLE `services` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `name` varchar(190) NOT NULL,
  `kind` enum('HOTEL','APARTMENT','CAR','FLIGHT','TOUR','UMRAH','OTHER') DEFAULT 'OTHER',
  `revenue_account_id` int(11) DEFAULT NULL,
  `default_price` decimal(14,2) NOT NULL DEFAULT 0.00,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `services`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_services_delete` AFTER DELETE ON `services` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'tourism', 'DELETE', 'services', COALESCE(OLD.id, NULL), 'DELETE on services', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_services_insert` AFTER INSERT ON `services` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'INSERT', 'services', COALESCE(NEW.id, NULL), 'INSERT on services', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_services_update` AFTER UPDATE ON `services` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'UPDATE', 'services', COALESCE(NEW.id, NULL), 'UPDATE on services', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `suppliers`
--

CREATE TABLE `suppliers` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `name` varchar(190) NOT NULL,
  `kind` enum('HOTEL','APARTMENT','CAR','FLIGHT','TOUR','UMRAH','OTHER') DEFAULT 'OTHER',
  `phone` varchar(60) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `suppliers`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_suppliers_delete` AFTER DELETE ON `suppliers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'tourism', 'DELETE', 'suppliers', COALESCE(OLD.id, NULL), 'DELETE on suppliers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_suppliers_insert` AFTER INSERT ON `suppliers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'INSERT', 'suppliers', COALESCE(NEW.id, NULL), 'INSERT on suppliers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_suppliers_update` AFTER UPDATE ON `suppliers` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'tourism', 'UPDATE', 'suppliers', COALESCE(NEW.id, NULL), 'UPDATE on suppliers', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `name` varchar(150) NOT NULL,
  `email` varchar(190) NOT NULL,
  `phone` varchar(60) DEFAULT NULL,
  `avatar_path` varchar(255) DEFAULT NULL,
  `password_hash` varchar(255) NOT NULL,
  `role` enum('owner','admin','user') NOT NULL DEFAULT 'owner',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `last_login_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `company_id`, `name`, `email`, `phone`, `avatar_path`, `password_hash`, `role`, `is_active`, `created_at`, `last_login_at`) VALUES
(1, 1, 'MHM', 'acc.mhm.egy@gmail.com', NULL, NULL, '$2y$10$9uTH7EOCmrOKifAlgf5s6ez.Tybzjd9b0MNGgsRLPFyoIBPaOZ5hC', 'owner', 1, '2026-03-07 12:46:55', NULL),
(2, 1, 'Maher', 'maher@gmail.com', NULL, NULL, '$2y$10$nx4fTLt5G.5CHpL/bKG.V.SDA.E9cG34F1n7QVoW/gVIbPwK83ANO', 'user', 1, '2026-03-08 12:22:22', NULL);

--
-- Triggers `users`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_users_delete` AFTER DELETE ON `users` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'users', 'DELETE', 'users', COALESCE(OLD.id, NULL), 'DELETE on users', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_users_insert` AFTER INSERT ON `users` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'users', 'INSERT', 'users', COALESCE(NEW.id, NULL), 'INSERT on users', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_users_update` AFTER UPDATE ON `users` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'users', 'UPDATE', 'users', COALESCE(NEW.id, NULL), 'UPDATE on users', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `vehicles`
--

CREATE TABLE `vehicles` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `plate_no` varchar(80) NOT NULL,
  `brand` varchar(120) DEFAULT NULL,
  `model` varchar(120) DEFAULT NULL,
  `model_year` varchar(20) DEFAULT NULL,
  `color` varchar(80) DEFAULT NULL,
  `chassis_no` varchar(120) DEFAULT NULL,
  `engine_no` varchar(120) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `vehicles`
--

INSERT INTO `vehicles` (`id`, `company_id`, `plate_no`, `brand`, `model`, `model_year`, `color`, `chassis_no`, `engine_no`, `notes`, `created_by`, `created_at`) VALUES
(1, 1, '378', 'رينو', '2018', '2019', 'بني', '١٢٣٤٥٦٧٨٩', '١٢٣٤٥٦', '', 1, '2026-03-08 13:13:59');

--
-- Triggers `vehicles`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_vehicles_delete` AFTER DELETE ON `vehicles` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'fleet', 'DELETE', 'vehicles', COALESCE(OLD.id, NULL), 'DELETE on vehicles', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_vehicles_insert` AFTER INSERT ON `vehicles` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'fleet', 'INSERT', 'vehicles', COALESCE(NEW.id, NULL), 'INSERT on vehicles', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_vehicles_update` AFTER UPDATE ON `vehicles` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'fleet', 'UPDATE', 'vehicles', COALESCE(NEW.id, NULL), 'UPDATE on vehicles', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `vehicle_operation_contracts`
--

CREATE TABLE `vehicle_operation_contracts` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `vehicle_id` int(11) NOT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `contract_type` enum('rental','transfer','stop_order','maintenance_order') NOT NULL,
  `contract_no` varchar(60) DEFAULT NULL,
  `from_location` varchar(190) DEFAULT NULL,
  `to_location` varchar(190) DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `start_time` time DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `end_time` time DEFAULT NULL,
  `days_count` int(11) DEFAULT NULL,
  `amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `payment_type` enum('cash','credit') NOT NULL DEFAULT 'cash',
  `status` enum('draft','active','closed','cancelled') NOT NULL DEFAULT 'draft',
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Triggers `vehicle_operation_contracts`
--
DELIMITER $$
CREATE TRIGGER `tr_audit_vehicle_operation_contracts_delete` AFTER DELETE ON `vehicle_operation_contracts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(OLD.company_id, @audit_company_id), @audit_user_id, 'fleet', 'DELETE', 'vehicle_operation_contracts', COALESCE(OLD.id, NULL), 'DELETE on vehicle_operation_contracts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_vehicle_operation_contracts_insert` AFTER INSERT ON `vehicle_operation_contracts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'fleet', 'INSERT', 'vehicle_operation_contracts', COALESCE(NEW.id, NULL), 'INSERT on vehicle_operation_contracts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;
DELIMITER $$
CREATE TRIGGER `tr_audit_vehicle_operation_contracts_update` AFTER UPDATE ON `vehicle_operation_contracts` FOR EACH ROW BEGIN
  INSERT INTO `audit_logs` (`company_id`,`user_id`,`module`,`action`,`table_name`,`record_id`,`description`,`ip_address`,`request_method`,`request_uri`,`created_at`)
  VALUES (COALESCE(NEW.company_id, @audit_company_id), @audit_user_id, 'fleet', 'UPDATE', 'vehicle_operation_contracts', COALESCE(NEW.id, NULL), 'UPDATE on vehicle_operation_contracts', SUBSTRING_INDEX(USER(),'@',1), NULL, NULL, NOW());
END
$$
DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `vehicle_order_types`
--

CREATE TABLE `vehicle_order_types` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `code` varchar(60) NOT NULL,
  `name` varchar(120) NOT NULL,
  `revenue_account_id` int(11) DEFAULT NULL,
  `start_no` int(11) NOT NULL DEFAULT 1,
  `end_no` int(11) NOT NULL DEFAULT 1000,
  `current_no` int(11) NOT NULL DEFAULT 0,
  `is_system` tinyint(1) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `vehicle_order_types`
--

INSERT INTO `vehicle_order_types` (`id`, `company_id`, `code`, `name`, `revenue_account_id`, `start_no`, `end_no`, `current_no`, `is_system`, `is_active`, `created_at`, `updated_at`) VALUES
(1, 1, 'LIMO', 'أمر تشغيل', 47, 1, 1000, 0, 1, 1, '2026-03-09 00:33:26', '2026-03-09 06:27:19'),
(2, 1, 'RENT', 'أمر تأجير', 46, 1, 1000, 1, 1, 1, '2026-03-09 00:33:26', '2026-03-09 10:49:18'),
(3, 1, 'MAINT', 'أمر صيانة', NULL, 1, 1000, 0, 1, 1, '2026-03-09 00:33:26', NULL),
(4, 1, 'STOP', 'أمر توقف', NULL, 1, 1000, 0, 1, 1, '2026-03-09 00:33:26', '2026-03-09 06:41:13');

-- --------------------------------------------------------

--
-- Table structure for table `vehicle_rental_contracts`
--

CREATE TABLE `vehicle_rental_contracts` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `order_type_id` int(11) NOT NULL,
  `order_serial_no` int(11) NOT NULL,
  `contract_serial` varchar(60) NOT NULL,
  `vehicle_id` int(11) NOT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `km_out` decimal(12,2) NOT NULL DEFAULT 0.00,
  `km_in` decimal(12,2) DEFAULT NULL,
  `used_km` decimal(12,2) NOT NULL DEFAULT 0.00,
  `contract_kind` enum('COMMERCIAL','SERVICE') NOT NULL DEFAULT 'COMMERCIAL',
  `rental_duration` enum('MONTHLY','DAILY') NOT NULL DEFAULT 'MONTHLY',
  `base_rent_amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `extra_day_rate` decimal(14,2) NOT NULL DEFAULT 0.00,
  `extra_km_rate` decimal(14,2) NOT NULL DEFAULT 0.00,
  `contract_date` date NOT NULL,
  `expected_end_date` date NOT NULL,
  `actual_end_date` date DEFAULT NULL,
  `expected_days` int(11) NOT NULL DEFAULT 30,
  `actual_days` int(11) NOT NULL DEFAULT 0,
  `extra_days` int(11) NOT NULL DEFAULT 0,
  `extra_km` decimal(12,2) NOT NULL DEFAULT 0.00,
  `additional_driver_1_id` int(11) DEFAULT NULL,
  `additional_driver_2_id` int(11) DEFAULT NULL,
  `insurance_party` enum('COMPANY','CLIENT') NOT NULL DEFAULT 'COMPANY',
  `insurance_amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `insurance_refund` decimal(14,2) NOT NULL DEFAULT 0.00,
  `return_condition` enum('GOOD','DAMAGED') DEFAULT NULL,
  `maintenance_charge` decimal(14,2) NOT NULL DEFAULT 0.00,
  `gross_amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `net_amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `payment_type` enum('CASH','CREDIT') DEFAULT NULL,
  `payment_due_date` date DEFAULT NULL,
  `status` enum('ACTIVE','CLOSED','CANCELLED') NOT NULL DEFAULT 'ACTIVE',
  `notes` text DEFAULT NULL,
  `closed_notes` text DEFAULT NULL,
  `posted_entry_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Dumping data for table `vehicle_rental_contracts`
--

INSERT INTO `vehicle_rental_contracts` (`id`, `company_id`, `order_type_id`, `order_serial_no`, `contract_serial`, `vehicle_id`, `customer_id`, `km_out`, `km_in`, `used_km`, `contract_kind`, `rental_duration`, `base_rent_amount`, `extra_day_rate`, `extra_km_rate`, `contract_date`, `expected_end_date`, `actual_end_date`, `expected_days`, `actual_days`, `extra_days`, `extra_km`, `additional_driver_1_id`, `additional_driver_2_id`, `insurance_party`, `insurance_amount`, `insurance_refund`, `return_condition`, `maintenance_charge`, `gross_amount`, `net_amount`, `payment_type`, `payment_due_date`, `status`, `notes`, `closed_notes`, `posted_entry_id`, `created_by`, `created_at`, `updated_at`) VALUES
(1, 1, 2, 1, 'RENT-1', 1, 1, 100.00, NULL, 0.00, 'COMMERCIAL', 'MONTHLY', 1000.00, 100.00, 50.00, '2026-03-09', '2026-04-07', NULL, 29, 0, 0, 0.00, 1, 1, 'COMPANY', 0.00, 0.00, NULL, 0.00, 0.00, 0.00, NULL, NULL, 'ACTIVE', '', NULL, NULL, 1, '2026-03-09 10:49:18', NULL);

-- --------------------------------------------------------

--
-- Table structure for table `vehicle_rental_maintenance_items`
--

CREATE TABLE `vehicle_rental_maintenance_items` (
  `id` int(11) NOT NULL,
  `company_id` int(11) NOT NULL,
  `contract_id` int(11) NOT NULL,
  `item_name` varchar(190) NOT NULL,
  `charge_to` enum('CLIENT','COMPANY') NOT NULL DEFAULT 'CLIENT',
  `amount` decimal(14,2) NOT NULL DEFAULT 0.00,
  `notes` varchar(255) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `accounts`
--
ALTER TABLE `accounts`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_accounts_company_code` (`company_id`,`code`),
  ADD KEY `idx_accounts_company_parent` (`company_id`,`parent_id`),
  ADD KEY `fk_accounts_parent` (`parent_id`);

--
-- Indexes for table `attendance`
--
ALTER TABLE `attendance`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_att_emp_date` (`company_id`,`employee_id`,`work_date`),
  ADD KEY `idx_att_date` (`company_id`,`work_date`);

--
-- Indexes for table `audit_logs`
--
ALTER TABLE `audit_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_audit_company` (`company_id`),
  ADD KEY `idx_audit_user` (`user_id`),
  ADD KEY `idx_audit_module` (`module`),
  ADD KEY `idx_audit_created_at` (`created_at`);

--
-- Indexes for table `backups`
--
ALTER TABLE `backups`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_backups_company` (`company_id`),
  ADD KEY `idx_backups_created_at` (`created_at`),
  ADD KEY `fk_backups_restored_by` (`restored_by`);

--
-- Indexes for table `backup_logs`
--
ALTER TABLE `backup_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `company_id` (`company_id`),
  ADD KEY `backup_id` (`backup_id`);

--
-- Indexes for table `bookings`
--
ALTER TABLE `bookings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_booking_company_no` (`company_id`,`booking_no`),
  ADD KEY `idx_booking_company_date` (`company_id`,`booking_date`);

--
-- Indexes for table `booking_items`
--
ALTER TABLE `booking_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_bi_booking` (`booking_id`);

--
-- Indexes for table `cash_transactions`
--
ALTER TABLE `cash_transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_cash_company_date` (`company_id`,`tx_date`),
  ADD KEY `fk_cash_user` (`created_by`),
  ADD KEY `fk_cash_cashacc` (`cash_account_id`),
  ADD KEY `fk_cash_counteracc` (`counter_account_id`);

--
-- Indexes for table `cash_tx_journal_map`
--
ALTER TABLE `cash_tx_journal_map`
  ADD PRIMARY KEY (`cash_tx_id`),
  ADD KEY `fk_map_entry` (`entry_id`);

--
-- Indexes for table `companies`
--
ALTER TABLE `companies`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_customers_company` (`company_id`);

--
-- Indexes for table `employees`
--
ALTER TABLE `employees`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_emp_company` (`company_id`),
  ADD KEY `idx_emp_status` (`status`);

--
-- Indexes for table `employee_advances`
--
ALTER TABLE `employee_advances`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_adv_emp` (`company_id`,`employee_id`),
  ADD KEY `idx_adv_status` (`company_id`,`status`);

--
-- Indexes for table `employee_advance_settlements`
--
ALTER TABLE `employee_advance_settlements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_set_adv` (`company_id`,`advance_id`);

--
-- Indexes for table `employee_advance_transfers`
--
ALTER TABLE `employee_advance_transfers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_adv_transfer_source` (`company_id`,`source_advance_id`),
  ADD KEY `idx_adv_transfer_target` (`company_id`,`target_advance_id`);

--
-- Indexes for table `financial_events`
--
ALTER TABLE `financial_events`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_fe_company_date` (`company_id`,`event_date`),
  ADD KEY `idx_fe_company_status` (`company_id`,`status`);

--
-- Indexes for table `financial_event_lines`
--
ALTER TABLE `financial_event_lines`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_fel_event` (`event_id`);

--
-- Indexes for table `fleet_limo_serials`
--
ALTER TABLE `fleet_limo_serials`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_fleet_limo_serials_company_serial` (`company_id`,`serial_no`);

--
-- Indexes for table `fleet_limo_trips`
--
ALTER TABLE `fleet_limo_trips`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `fleet_locations`
--
ALTER TABLE `fleet_locations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_fleet_locations_company_name` (`company_id`,`name`);

--
-- Indexes for table `fleet_rentals`
--
ALTER TABLE `fleet_rentals`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `fleet_rental_services`
--
ALTER TABLE `fleet_rental_services`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `hotel_bookings`
--
ALTER TABLE `hotel_bookings`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_hotel_bookings_company` (`company_id`),
  ADD KEY `idx_hotel_bookings_dates` (`company_id`,`request_date`,`checkin_date`,`checkout_date`);

--
-- Indexes for table `hotel_hotels`
--
ALTER TABLE `hotel_hotels`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_hotel_hotels_company` (`company_id`);

--
-- Indexes for table `hotel_receipts`
--
ALTER TABLE `hotel_receipts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_hotel_receipts_company` (`company_id`),
  ADD KEY `idx_hotel_receipts_date` (`company_id`,`receipt_date`);

--
-- Indexes for table `hotel_rooms`
--
ALTER TABLE `hotel_rooms`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_hotel_rooms_company` (`company_id`),
  ADD KEY `idx_hotel_rooms_hotel` (`hotel_id`);

--
-- Indexes for table `invoices`
--
ALTER TABLE `invoices`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_invoice_company_no` (`company_id`,`invoice_no`),
  ADD KEY `idx_invoice_company_date` (`company_id`,`invoice_date`);

--
-- Indexes for table `invoice_lines`
--
ALTER TABLE `invoice_lines`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `journal_entries`
--
ALTER TABLE `journal_entries`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_je_company_date` (`company_id`,`entry_date`),
  ADD KEY `fk_je_user` (`created_by`);

--
-- Indexes for table `journal_lines`
--
ALTER TABLE `journal_lines`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_jl_entry` (`entry_id`),
  ADD KEY `idx_jl_account` (`account_id`),
  ADD KEY `fk_jl_company` (`company_id`);

--
-- Indexes for table `missions`
--
ALTER TABLE `missions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_mis_date` (`company_id`,`mission_date`);

--
-- Indexes for table `operation_serials`
--
ALTER TABLE `operation_serials`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `payments`
--
ALTER TABLE `payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pay_company_date` (`company_id`,`pay_date`);

--
-- Indexes for table `payroll_lines`
--
ALTER TABLE `payroll_lines`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_pl_pay` (`company_id`,`payroll_id`),
  ADD KEY `idx_pl_emp` (`company_id`,`employee_id`);

--
-- Indexes for table `payroll_runs`
--
ALTER TABLE `payroll_runs`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_payroll_period` (`company_id`,`period_year`,`period_month`);

--
-- Indexes for table `services`
--
ALTER TABLE `services`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_services_company` (`company_id`);

--
-- Indexes for table `suppliers`
--
ALTER TABLE `suppliers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_suppliers_company` (`company_id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_users_company_email` (`company_id`,`email`);

--
-- Indexes for table `vehicles`
--
ALTER TABLE `vehicles`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehicle_company` (`company_id`),
  ADD KEY `idx_vehicle_plate` (`company_id`),
  ADD KEY `idx_vehicle_status` (`company_id`);

--
-- Indexes for table `vehicle_operation_contracts`
--
ALTER TABLE `vehicle_operation_contracts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehicle_contracts_company` (`company_id`),
  ADD KEY `idx_vehicle_contracts_vehicle` (`vehicle_id`),
  ADD KEY `idx_vehicle_contracts_customer` (`customer_id`);

--
-- Indexes for table `vehicle_order_types`
--
ALTER TABLE `vehicle_order_types`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_vehicle_order_types_company_code` (`company_id`,`code`),
  ADD KEY `idx_vehicle_order_types_company` (`company_id`);

--
-- Indexes for table `vehicle_rental_contracts`
--
ALTER TABLE `vehicle_rental_contracts`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_vehicle_rental_contracts_serial` (`company_id`,`order_type_id`,`order_serial_no`),
  ADD UNIQUE KEY `uniq_vehicle_rental_contracts_contract_serial` (`company_id`,`contract_serial`),
  ADD KEY `idx_vehicle_rental_contracts_company` (`company_id`),
  ADD KEY `idx_vehicle_rental_contracts_vehicle` (`vehicle_id`),
  ADD KEY `idx_vehicle_rental_contracts_customer` (`customer_id`);

--
-- Indexes for table `vehicle_rental_maintenance_items`
--
ALTER TABLE `vehicle_rental_maintenance_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_vehicle_rental_maint_company` (`company_id`),
  ADD KEY `idx_vehicle_rental_maint_contract` (`contract_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `accounts`
--
ALTER TABLE `accounts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=444;

--
-- AUTO_INCREMENT for table `attendance`
--
ALTER TABLE `attendance`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `audit_logs`
--
ALTER TABLE `audit_logs`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=81;

--
-- AUTO_INCREMENT for table `backups`
--
ALTER TABLE `backups`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `backup_logs`
--
ALTER TABLE `backup_logs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `bookings`
--
ALTER TABLE `bookings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `booking_items`
--
ALTER TABLE `booking_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cash_transactions`
--
ALTER TABLE `cash_transactions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `companies`
--
ALTER TABLE `companies`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `employees`
--
ALTER TABLE `employees`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `employee_advances`
--
ALTER TABLE `employee_advances`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `employee_advance_settlements`
--
ALTER TABLE `employee_advance_settlements`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `employee_advance_transfers`
--
ALTER TABLE `employee_advance_transfers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `financial_events`
--
ALTER TABLE `financial_events`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `financial_event_lines`
--
ALTER TABLE `financial_event_lines`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `fleet_limo_serials`
--
ALTER TABLE `fleet_limo_serials`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `fleet_limo_trips`
--
ALTER TABLE `fleet_limo_trips`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `fleet_locations`
--
ALTER TABLE `fleet_locations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `fleet_rentals`
--
ALTER TABLE `fleet_rentals`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `fleet_rental_services`
--
ALTER TABLE `fleet_rental_services`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `hotel_bookings`
--
ALTER TABLE `hotel_bookings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `hotel_hotels`
--
ALTER TABLE `hotel_hotels`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `hotel_receipts`
--
ALTER TABLE `hotel_receipts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `hotel_rooms`
--
ALTER TABLE `hotel_rooms`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `invoices`
--
ALTER TABLE `invoices`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `invoice_lines`
--
ALTER TABLE `invoice_lines`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `journal_entries`
--
ALTER TABLE `journal_entries`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;

--
-- AUTO_INCREMENT for table `journal_lines`
--
ALTER TABLE `journal_lines`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT for table `missions`
--
ALTER TABLE `missions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `operation_serials`
--
ALTER TABLE `operation_serials`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `payments`
--
ALTER TABLE `payments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `payroll_lines`
--
ALTER TABLE `payroll_lines`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `payroll_runs`
--
ALTER TABLE `payroll_runs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `services`
--
ALTER TABLE `services`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `suppliers`
--
ALTER TABLE `suppliers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `vehicles`
--
ALTER TABLE `vehicles`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `vehicle_operation_contracts`
--
ALTER TABLE `vehicle_operation_contracts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `vehicle_order_types`
--
ALTER TABLE `vehicle_order_types`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `vehicle_rental_contracts`
--
ALTER TABLE `vehicle_rental_contracts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `vehicle_rental_maintenance_items`
--
ALTER TABLE `vehicle_rental_maintenance_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `accounts`
--
ALTER TABLE `accounts`
  ADD CONSTRAINT `fk_accounts_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_accounts_parent` FOREIGN KEY (`parent_id`) REFERENCES `accounts` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `backups`
--
ALTER TABLE `backups`
  ADD CONSTRAINT `fk_backups_restored_by` FOREIGN KEY (`restored_by`) REFERENCES `users` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `cash_transactions`
--
ALTER TABLE `cash_transactions`
  ADD CONSTRAINT `fk_cash_cashacc` FOREIGN KEY (`cash_account_id`) REFERENCES `accounts` (`id`),
  ADD CONSTRAINT `fk_cash_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_cash_counteracc` FOREIGN KEY (`counter_account_id`) REFERENCES `accounts` (`id`),
  ADD CONSTRAINT `fk_cash_user` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `cash_tx_journal_map`
--
ALTER TABLE `cash_tx_journal_map`
  ADD CONSTRAINT `fk_map_entry` FOREIGN KEY (`entry_id`) REFERENCES `journal_entries` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_map_tx` FOREIGN KEY (`cash_tx_id`) REFERENCES `cash_transactions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `journal_entries`
--
ALTER TABLE `journal_entries`
  ADD CONSTRAINT `fk_je_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_je_user` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `journal_lines`
--
ALTER TABLE `journal_lines`
  ADD CONSTRAINT `fk_jl_account` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`),
  ADD CONSTRAINT `fk_jl_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_jl_entry` FOREIGN KEY (`entry_id`) REFERENCES `journal_entries` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `fk_users_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
