-- Table structure for table `crm_contract_other_websites`
--

CREATE TABLE `crm_contract_other_websites` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `contract_code` varchar(255) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `is_promotion` enum('0','1') DEFAULT '0' COMMENT '0 :  Website không được khuyến mãi\n1 :  Website được khuyến mãi',
  `created_by_id` bigint(20) DEFAULT NULL,
  `language_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=274 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_package_fields`
--

CREATE TABLE `crm_contract_package_fields` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `package_ids` varchar(500) CHARACTER SET latin1 DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_package_fields_relation`
--

CREATE TABLE `crm_contract_package_fields_relation` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `field_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_pays`
--

CREATE TABLE `crm_contract_pays` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `percent` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `date_created` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10039 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_reminders`
--

CREATE TABLE `crm_contract_reminders` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_service_accompanieds`
--

CREATE TABLE `crm_contract_service_accompanieds` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `unit_id` bigint(20) DEFAULT NULL,
  `number` bigint(20) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=22655 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_service_discounts`
--

CREATE TABLE `crm_contract_service_discounts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  `symbol_id` bigint(20) DEFAULT NULL,
  `month` bigint(20) DEFAULT NULL,
  `discount` decimal(20,5) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_service_packages`
--

CREATE TABLE `crm_contract_service_packages` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` bigint(20) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `number_default` decimal(20,5) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `accompanied_ids` varchar(100) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `number_perform` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `service_id_old` bigint(20) DEFAULT NULL,
  `package_id_old` bigint(20) DEFAULT NULL,
  `template_ids` varchar(300) DEFAULT NULL,
  `interval_time` enum('days','weeks','months','years') NOT NULL DEFAULT 'months',
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`),
  KEY `package_id_old` (`package_id_old`),
  KEY `service_id_old` (`service_id_old`),
  KEY `service_id` (`service_id`)
) ENGINE=InnoDB AUTO_INCREMENT=47027 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_services`
--

CREATE TABLE `crm_contract_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(50) DEFAULT NULL,
  `type` enum('SERVICE','PRODUCT') DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  `website` varchar(500) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `desc` text,
  `template_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `field_ids` varchar(500) DEFAULT NULL,
  `contract_field_ids` varchar(500) DEFAULT NULL,
  `care_loop_day` bigint(20) DEFAULT NULL,
  `has_vat` enum('0','1') DEFAULT '0',
  `is_domain_service` enum('0','1') DEFAULT '0',
  `website_required` enum('0','1') DEFAULT '1',
  `template_ids` varchar(500) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `service_id_old` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`),
  KEY `service_id_old` (`service_id_old`)
) ENGINE=InnoDB AUTO_INCREMENT=32331 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_transference_requests`
--

CREATE TABLE `crm_contract_transference_requests` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_status` enum('0','1','2') DEFAULT NULL,
  `date_approved` datetime DEFAULT NULL,
  `date_transfered` datetime DEFAULT NULL,
  `approver_opinion` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_value_added_services`
--

CREATE TABLE `crm_contract_value_added_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) NOT NULL,
  `appendix_id` bigint(20) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL,
  `number` int(11) DEFAULT NULL,
  `unit` varchar(45) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `dynamic_price` enum('0','1') DEFAULT '0',
  `has_vat` enum('0','1') DEFAULT '0',
  `vat_percent` decimal(20,5) DEFAULT '0.00000',
  `_total_price` decimal(20,5) DEFAULT '0.00000',
  `total_vat_price` decimal(20,5) DEFAULT '0.00000',
  `total_price` decimal(20,5) DEFAULT NULL,
  `date_started` date DEFAULT NULL,
  `date_expired` date DEFAULT NULL,
  `value_added_id_old` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3284 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_warning_times`
--

CREATE TABLE `crm_contract_warning_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `day` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contracts`
--

CREATE TABLE `crm_contracts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `type` enum('UPGRADE','RESIGN','NEW') DEFAULT 'NEW' COMMENT 'NEW : mới, Resign : gia hạn, upgrade : nâng cấp',
  `type_upgrade` varchar(50) DEFAULT NULL,
  `root_id` bigint(20) DEFAULT NULL,
  `code_number` varchar(150) DEFAULT NULL,
  `code_auto` varchar(300) DEFAULT NULL,
  `code` varchar(300) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `date_sign` datetime DEFAULT NULL COMMENT 'ngày ký',
  `condition_type` enum('CANCEL','CLOSE','OPEN','LIQUIDATION','OTHER') DEFAULT 'OPEN' COMMENT 'Hủy, Đóng, Mở',
  `vat_percent` decimal(20,5) DEFAULT '0.00000',
  `total_price_tmp` decimal(20,5) DEFAULT NULL,
  `total_price_appendix` decimal(20,5) DEFAULT NULL,
  `total_price_fix` decimal(20,5) DEFAULT '0.00000',
  `total_price` decimal(10,0) DEFAULT NULL,
  `total_price_internal_tmp` decimal(20,5) DEFAULT NULL,
  `total_price_internal` decimal(20,5) DEFAULT NULL,
  `website` varchar(300) DEFAULT NULL,
  `pay_type` enum('TRANSFER','MONEY') DEFAULT 'MONEY' COMMENT 'hình thức thanh toán : chuyển khoản / tiền mặt',
  `pay_duration_type` enum('MULTI','SINGER') DEFAULT 'SINGER' COMMENT 'Thời hạn thanh toán :  một lần hoặc nhiều lần',
  `contract_old_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `discount` decimal(20,5) DEFAULT NULL,
  `date_start` datetime DEFAULT NULL,
  `date_end` datetime DEFAULT NULL,
  `date_expired` datetime DEFAULT NULL,
  `package_number` bigint(20) DEFAULT NULL,
  `package_interval` enum('days','weeks','months','years') DEFAULT 'months',
  `package_number_bonus` bigint(20) DEFAULT NULL,
  `package_bonus_interval` enum('days','weeks','months','years') DEFAULT 'months',
  `service_origin_id` bigint(20) DEFAULT NULL,
  `status` enum('APPROVER','SAVE','NO_APPROVER','DELETED') DEFAULT 'SAVE',
  `status_desc` varchar(500) DEFAULT NULL,
  `date_save_tmp` datetime DEFAULT NULL,
  `date_save` datetime DEFAULT NULL,
  `date_approver` datetime DEFAULT NULL,
  `date_deleted` datetime DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `work_request_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `sale_support_id` bigint(20) DEFAULT NULL,
  `coordination_id` bigint(20) DEFAULT NULL,
  `sale_ids` varchar(500) DEFAULT NULL,
  `telesale_ids` varchar(500) DEFAULT NULL,
  `sale_support_ids` varchar(500) DEFAULT NULL,
  `is_notice_end` tinyint(4) DEFAULT NULL,
  `is_effect` enum('NO','YES') DEFAULT 'YES',
  `site_status_count` bigint(20) DEFAULT NULL COMMENT 'So lan gui duyet site',
  `site_status` enum('-1','2','1','0') DEFAULT '-1' COMMENT '-1 : chưa duyệt, 0 : chờ duyệt, 1: đã duyệt, 2: không duyệt',
  `site_status_1` tinyint(4) DEFAULT NULL,
  `site_date_request_1` datetime DEFAULT NULL,
  `site_user_request_1` bigint(20) DEFAULT NULL,
  `site_date_approver_1` datetime DEFAULT NULL,
  `site_user_approver_1` bigint(20) DEFAULT NULL,
  `site_desc_approver_1` text,
  `site_status_2` tinyint(4) DEFAULT NULL,
  `site_date_request_2` datetime DEFAULT NULL,
  `site_user_request_2` bigint(20) DEFAULT NULL,
  `site_date_approver_2` datetime DEFAULT NULL,
  `site_user_approver_2` bigint(20) DEFAULT NULL,
  `site_desc_approver_2` text,
  `region_id` bigint(20) DEFAULT NULL,
  `is_notice_charge_money` enum('0','1') DEFAULT '1',
  `number_of_websites` int(11) DEFAULT '1',
  `is_wait_to_operate` enum('0','1') DEFAULT '0',
  `is_notice_wait_to_operate` enum('0','1') DEFAULT '0',
  `potential_id` bigint(20) DEFAULT NULL,
  `sale_created_income` enum('0','1') DEFAULT '0',
  `last_approve_internal_date` datetime DEFAULT NULL,
  `time_append_request_site` datetime DEFAULT NULL COMMENT 'Thời gian gia hạn gửi duyệt site',
  `user_can_view` varchar(100) DEFAULT NULL,
  `transfer_status` enum('0','1','2') DEFAULT NULL,
  `transfer_customer_id` bigint(20) DEFAULT NULL,
  `transfer_request_id` bigint(20) DEFAULT NULL,
  `date_transfered` datetime DEFAULT NULL,
  `initial_price` decimal(20,5) DEFAULT '0.00000' COMMENT 'Phí khởi tạo của HĐ',
  `discount_percent` decimal(20,5) DEFAULT '0.00000' COMMENT '% chiết khấu của HĐ',
  `discount_money` decimal(20,5) DEFAULT '0.00000' COMMENT 'Số tiền chiết khấu của HĐ tính theo VNĐ',
  `added_discount_total_price` decimal(20,5) DEFAULT '0.00000' COMMENT 'Tổng tiền sau khi chiết khấu và chưa tính VAT',
  `final_vat_percent` decimal(20,5) DEFAULT '0.00000' COMMENT 'Thuế VAT của hợp đồng',
  `final_total_price` decimal(20,5) DEFAULT '0.00000' COMMENT 'Tổng tiền của HĐ trước thuế, chiết khấu',
  PRIMARY KEY (`ID`),
  UNIQUE KEY `contract_code` (`code`(20)),
  KEY `contract_old_id` (`contract_old_id`),
  KEY `Code_Index` (`code`(255)),
  KEY `company_id` (`company_id`) USING BTREE,
  KEY `created_by_id` (`created_by_id`) USING BTREE,
  KEY `date_created` (`date_created`),
  KEY `date_expired` (`date_expired`),
  KEY `potential_id` (`potential_id`) USING BTREE,
  KEY `root_id` (`root_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=33428 DEFAULT CHARSET=utf8;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`tientq`@`%`*/ /*!50003 TRIGGER contract_expired_create
	BEFORE INSERT
	ON crm_contracts
	FOR EACH ROW
BEGIN
	IF NEW.date_start IS NOT NULL AND NEW.date_end IS NOT NULL THEN
		IF NEW.package_number_bonus = -1 THEN
			SET NEW.date_expired = NULL;
		ELSEIF NEW.package_number_bonus > 0 AND NEW.package_bonus_interval = 'years' THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus YEAR;
		ELSEIF NEW.package_number_bonus > 0 AND NEW.package_bonus_interval = 'weeks' THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus WEEK;
		ELSEIF NEW.package_number_bonus > 0 AND NEW.package_bonus_interval = 'days' THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus DAY;
		ELSEIF NEW.package_number_bonus > 0 THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus MONTH;
		ELSE
			SET NEW.date_expired = NEW.date_end;
		END IF;
	ELSE
		SET NEW.date_expired = NULL;
  END IF;

  
  IF NEW.`type` = 'NEW' AND NEW.`condition_type` IN ('OPEN', 'CLOSE', 'OTHER') AND EXISTS (
    SELECT `a`.`ID` FROM `crm_contract_services` `a` WHERE `a`.`contract_id` = NEW.`ID` AND `a`.`code` IN ('Bizweb')
  ) AND NEW.`code` NOT LIKE 'A%'
  THEN
    SET NEW.`date_expired` = DATE_ADD(NEW.`date_expired`, INTERVAL (
      SELECT `s`.`value` FROM `settings` `s` WHERE `s`.`name` = 'NUMBER_DAYS_APPEND_TO_EXPIRED_DATE') DAY);
  END IF;

  SET NEW.`date_expired` = DATE_ADD(NEW.`date_expired`, INTERVAL -1 DAY);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`tientq`@`%`*/ /*!50003 TRIGGER contract_expired_update
	BEFORE UPDATE
	ON crm_contracts
	FOR EACH ROW
BEGIN
	IF NEW.date_start IS NOT NULL AND NEW.date_end IS NOT NULL THEN
		IF NEW.package_number_bonus = -1 THEN
			SET NEW.date_expired = NULL;
		ELSEIF NEW.package_number_bonus > 0 AND NEW.package_bonus_interval = 'years' THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus YEAR;
		ELSEIF NEW.package_number_bonus > 0 AND NEW.package_bonus_interval = 'weeks' THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus WEEK;
		ELSEIF NEW.package_number_bonus > 0 AND NEW.package_bonus_interval = 'days' THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus DAY;
		ELSEIF NEW.package_number_bonus > 0 THEN
			SET NEW.date_expired = NEW.date_end + INTERVAL NEW.package_number_bonus MONTH;
		ELSE
			SET NEW.date_expired = NEW.date_end;
		END IF;
	ELSE
		SET NEW.date_expired = NULL;
  END IF;

  
  IF NEW.`type` = 'NEW' AND NEW.`condition_type` IN ('OPEN', 'CLOSE', 'OTHER') AND EXISTS (
    SELECT `a`.`ID` FROM `crm_contract_services` `a` WHERE `a`.`contract_id` = NEW.`ID` AND `a`.`code` IN ('Bizweb')
  ) AND NEW.`code` NOT LIKE 'A%'
  THEN
    SET NEW.`date_expired` = DATE_ADD(NEW.`date_expired`, INTERVAL (
      SELECT `s`.`value` FROM `settings` `s` WHERE `s`.`name` = 'NUMBER_DAYS_APPEND_TO_EXPIRED_DATE') DAY);
  END IF;

  SET NEW.`date_expired` = DATE_ADD(NEW.`date_expired`, INTERVAL -1 DAY);
END */;;
DELIMITER ;

--
-- Table structure for table `crm_cross_sales`
--

CREATE TABLE `crm_cross_sales` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `product_service_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UK_crm_cross_sales` (`user_id`,`product_service_id`),
  KEY `product` (`product_service_id`),
  KEY `user` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8 COMMENT='Cấu hình kinh doanh nào được bán sản phẩm dịch vụ nào';

--
-- Table structure for table `crm_customer_additional_configs`
--

CREATE TABLE `crm_customer_additional_configs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `input_type` varchar(20) DEFAULT NULL,
  `value` varchar(2000) DEFAULT NULL COMMENT 'lưu trữ dạng json',
  `required` enum('0','1') DEFAULT '0' COMMENT 'bắt buộc nhập trên form',
  `activated` enum('0','1') DEFAULT '1' COMMENT 'hiển thị trên form',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_customer_additional_fields`
--

CREATE TABLE `crm_customer_additional_fields` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customer_id` int(11) DEFAULT NULL,
  `config_id` int(11) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `value` varchar(255) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `customer_id` (`customer_id`),
  KEY `config_id` (`config_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Thông tin bổ sung cho khách hàng';

--
-- Table structure for table `crm_customer_origins`
--

CREATE TABLE `crm_customer_origins` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_customer_titles`
--

CREATE TABLE `crm_customer_titles` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `title` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_customers`
--

CREATE TABLE `crm_customers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `condition_type` enum('NORMAL','DELETED') NOT NULL DEFAULT 'NORMAL',
  `code` varchar(200) NOT NULL,
  `type` enum('0','1') DEFAULT '0' COMMENT '0: Cá nhân, 1: T? ch?c',
  `formal_name` int(11) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `represent_id` bigint(20) DEFAULT NULL,
  `formal_represent` int(11) DEFAULT NULL,
  `represent` varchar(200) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `phones` varchar(600) DEFAULT NULL,
  `emails` varchar(600) DEFAULT NULL,
  `websites` varchar(600) DEFAULT NULL,
  `address` text,
  `trade_id` int(11) DEFAULT NULL,
  `private_code` varchar(200) DEFAULT NULL,
  `private_date` date DEFAULT NULL,
  `private_place` int(11) DEFAULT NULL,
  `job_tax` varchar(200) DEFAULT NULL,
  `job_date` date DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `telesale_department_id` int(11) DEFAULT NULL,
  `desc` text,
  `created_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `sale_id` varchar(500) DEFAULT NULL,
  `telesale_id` varchar(500) DEFAULT NULL,
  `care_id` varchar(500) DEFAULT NULL,
  `region_id` int(11) DEFAULT NULL,
  `care_last_id` bigint(20) DEFAULT NULL,
  `care_last_date` datetime DEFAULT NULL,
  `root_id` bigint(20) DEFAULT NULL,
  `count_action_care` int(11) DEFAULT NULL,
  `potential_id` varchar(500) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `sale_id_old` bigint(20) DEFAULT NULL,
  `sale_date_old` datetime DEFAULT NULL,
  `sale_support_id` bigint(20) DEFAULT NULL,
  `sale_support_ids` varchar(500) DEFAULT NULL,
  `location_ids` varchar(200) DEFAULT NULL,
  `rs_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `rs_id_index` (`rs_id`),
  KEY `sale_id` (`sale_id`(255)) USING BTREE,
  KEY `telesale_id` (`telesale_id`(255)) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=24443 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_debug_domain_contracts`
--

CREATE TABLE `crm_debug_domain_contracts` (
  `ID` double NOT NULL AUTO_INCREMENT,
  `domain` varchar(255) DEFAULT NULL,
  `started_date` datetime DEFAULT NULL,
  `expired_date` datetime DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `email2` varchar(255) DEFAULT NULL,
  `phone_mobile` varchar(255) DEFAULT NULL,
  `phone_other` double DEFAULT NULL,
  `identity` double DEFAULT NULL,
  `tax_identity` double DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_debug_domain_id_jobtax`
--

CREATE TABLE `crm_debug_domain_id_jobtax` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `domain` varchar(255) DEFAULT NULL,
  `service` varchar(255) DEFAULT NULL,
  `start_end` varchar(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `identity` varchar(255) DEFAULT NULL,
  `job_tax` varchar(255) DEFAULT NULL,
  `phone` varchar(255) DEFAULT NULL,
  `contract_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_divide_configs`
--

CREATE TABLE `crm_divide_configs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `round` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `type` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_divide_regions`
--

CREATE TABLE `crm_divide_regions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `round` bigint(20) DEFAULT NULL,
  `priority` decimal(20,0) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `type` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=243 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_domain_sync_datas`
--

CREATE TABLE `crm_domain_sync_datas` (
  `id` double NOT NULL AUTO_INCREMENT,
  `domain` varchar(255) DEFAULT NULL,
  `service` varchar(255) DEFAULT NULL,
  `started_date` timestamp(6) NULL DEFAULT NULL,
  `expired_date` timestamp(6) NULL DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `phone_mobile` varchar(255) DEFAULT NULL,
  `identity` varchar(255) DEFAULT NULL,
  `tax_identity` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `sync_status` int(11) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7006 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_executable_accompanieds`
--

CREATE TABLE `crm_executable_accompanieds` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `unit_id` bigint(20) DEFAULT NULL,
  `number` bigint(20) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `executable_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `active_user_id` bigint(20) DEFAULT NULL,
  `active_date` datetime DEFAULT NULL,
  `active_desc` varchar(500) DEFAULT NULL,
  `active_date_appointment` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=275 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_executable_accompany_feedbacks`
--

CREATE TABLE `crm_executable_accompany_feedbacks` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `executable_id` bigint(20) DEFAULT NULL,
  `accompany_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_executable_status_histories`
--

CREATE TABLE `crm_executable_status_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `status` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=266 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_executable_warning_times`
--

CREATE TABLE `crm_executable_warning_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `hour` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_executables`
--

CREATE TABLE `crm_executables` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(50) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL COMMENT '-1: chua trien khai, 0: dang trien khai, 1 : Hoan thanh',
  `manager_id` bigint(20) DEFAULT NULL,
  `date_manager` datetime DEFAULT NULL,
  `assign_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `status_last_date` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=271 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_extend_requests`
--

CREATE TABLE `crm_extend_requests` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `item_id` int(11) NOT NULL COMMENT 'potential_id / contract_id',
  `website` varchar(255) NOT NULL,
  `type` varchar(20) DEFAULT NULL COMMENT 'potential / contract',
  `expired_date` datetime DEFAULT NULL COMMENT 'Gia hạn đến ngày',
  `extend_days` int(11) DEFAULT '0',
  `description` varchar(500) DEFAULT NULL,
  `status` int(11) DEFAULT '0',
  `created_by_id` int(11) NOT NULL,
  `created_date` datetime NOT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `updated_date` datetime DEFAULT NULL,
  `approved_by_id` int(11) DEFAULT '-1',
  `approved_date` datetime DEFAULT NULL,
  `approved_description` varchar(500) DEFAULT NULL,
  `service_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=646 DEFAULT CHARSET=utf8 COMMENT='Yêu cầu gia hạn dùng thử, mở thêm ngày sử dụng dành cho Kinh doanh gửi tới CSKH';

--
-- Table structure for table `crm_free_settings`
--

CREATE TABLE `crm_free_settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `type` varchar(16) NOT NULL COMMENT 'lead hoặc opportunity',
  `status` varchar(16) NOT NULL,
  `max_due_date` int(11) NOT NULL COMMENT 'số ngày đặt lịch due date tối đa phần task',
  `free_date` int(11) NOT NULL COMMENT 'số ngày bắt đầu bị tính thả nổi',
  `created_by` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='cấu hình thời gian thả nổi lead, opportunity';

--
-- Table structure for table `crm_histories`
--

CREATE TABLE `crm_histories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lead_id` int(11) DEFAULT NULL,
  `account_id` int(11) DEFAULT NULL,
  `activity_type` varchar(10) DEFAULT NULL,
  `activity_id` int(11) DEFAULT NULL,
  `action` varchar(255) NOT NULL,
  `message` varchar(255) DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `account` (`account_id`,`created`),
  KEY `lead` (`lead_id`,`created`)
) ENGINE=InnoDB AUTO_INCREMENT=2917972 DEFAULT CHARSET=utf8 COMMENT='lịch sử thao tác lên lead/opportunity, bao gồm cả task';

--
-- Table structure for table `crm_income_event_generators`
--

CREATE TABLE `crm_income_event_generators` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ratio_id` int(11) NOT NULL,
  `event_name` varchar(32) NOT NULL,
  `income_percent` decimal(18,5) NOT NULL DEFAULT '0.00000' COMMENT 'Phần trăm doanh số',
  `commision_percent` decimal(18,5) NOT NULL DEFAULT '0.00000' COMMENT 'Phần trăm hoa hồng',
  `approved` enum('0','1') NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=91557 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_events`
--

CREATE TABLE `crm_income_events` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL,
  `user_id` int(11) NOT NULL,
  `amount` decimal(18,5) NOT NULL,
  `income_percent` decimal(18,5) NOT NULL DEFAULT '0.00000' COMMENT 'Phần trăm doanh số',
  `commision_percent` decimal(18,5) NOT NULL DEFAULT '0.00000' COMMENT 'Phần trăm hoa hồng',
  `date_income` date DEFAULT NULL,
  `approved` enum('0','1') NOT NULL,
  `contract_id` int(11) NOT NULL,
  `internal_id` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43398 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_get_services`
--

CREATE TABLE `crm_income_get_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT '0',
  `date` datetime DEFAULT NULL,
  `date_approver` datetime DEFAULT NULL,
  `date_since` datetime DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `percent` decimal(20,5) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT '0',
  `commision` decimal(20,5) DEFAULT NULL,
  `money_commision` decimal(20,5) DEFAULT NULL,
  `type` enum('INTERNAL','CONTRACT') DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  `set_id` bigint(20) DEFAULT NULL,
  `target_person_id` bigint(20) DEFAULT NULL,
  `target_money` decimal(20,0) DEFAULT NULL,
  `target_date_from` datetime DEFAULT NULL,
  `target_date_to` datetime DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `contract_type` varchar(50) DEFAULT NULL,
  `contract_type_upgrade` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `post_id` (`post_id`,`type`),
  KEY `personnel_id` (`personnel_id`) USING BTREE,
  KEY `user_id` (`user_id`) USING BTREE,
  KEY `date` (`date`)
) ENGINE=InnoDB AUTO_INCREMENT=55791 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_gets`
--

CREATE TABLE `crm_income_gets` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` enum('INTERNAL') DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `date_since` datetime DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `commision` float(20,0) DEFAULT NULL,
  `money_commision` decimal(20,5) DEFAULT NULL,
  `percent` float(20,0) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `set_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `personnel_id` (`personnel_id`),
  KEY `post_id` (`post_id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=55880 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_prefix`
--

CREATE TABLE `crm_income_prefix` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `service_id` int(11) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `date_income` date DEFAULT NULL,
  `money` decimal(10,0) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `service_user` (`service_id`,`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4108 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_ratio`
--

CREATE TABLE `crm_income_ratio` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `contract_id` int(11) NOT NULL,
  `internal_id` int(11) NOT NULL DEFAULT '-1',
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=87429 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_set_services`
--

CREATE TABLE `crm_income_set_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT '0',
  `package_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `date_since` datetime DEFAULT NULL,
  `percent` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `commision` decimal(20,5) DEFAULT NULL,
  `money_commision` decimal(20,5) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT '0',
  `type` enum('INTERNAL','CONTRACT') DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `contract_type` varchar(255) DEFAULT NULL,
  `contract_type_upgrade` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=76005 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_sets`
--

CREATE TABLE `crm_income_sets` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` enum('ORDER','INTERNAL','CONTRACT','UNTIL_SITE_APPROVED') DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `date_since` datetime DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `percent` float(20,0) DEFAULT NULL,
  `commision` float(20,0) DEFAULT NULL,
  `group` varchar(20) DEFAULT NULL,
  `income_type` enum('BIZWEB','APPS','THEMES') NOT NULL DEFAULT 'BIZWEB' COMMENT 'Doanh s? ???c tính cho Bizweb, Apps ho?c Themes',
  PRIMARY KEY (`ID`),
  KEY `personnel_id` (`personnel_id`),
  KEY `post_id` (`post_id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=147786 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_upload_file`
--

CREATE TABLE `crm_income_upload_file` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` varchar(300) DEFAULT NULL,
  `size` varchar(100) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `filename` varchar(300) DEFAULT NULL,
  `module` varchar(100) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `date_created` date DEFAULT NULL,
  `date_updated` date DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=342 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_upload_file_detail`
--

CREATE TABLE `crm_income_upload_file_detail` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date_income` varchar(6) DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `personnel_id` int(11) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `uploaded_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `sheet_name` varchar(100) DEFAULT NULL,
  `file_name` varchar(100) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `department` bigint(20) DEFAULT NULL,
  `file_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7032 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_income_user_views`
--

CREATE TABLE `crm_income_user_views` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `service_ids` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=740 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_job_reminder_potentials`
--

CREATE TABLE `crm_job_reminder_potentials` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `potential_id` bigint(20) DEFAULT NULL,
  `reminder_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `is_color` smallint(1) DEFAULT '1',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_job_reminders`
--

CREATE TABLE `crm_job_reminders` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `position_Id` bigint(20) DEFAULT NULL COMMENT 'Mã chức vụ',
  `color_code` varchar(50) DEFAULT NULL COMMENT 'Mã màu',
  `description` varchar(150) DEFAULT NULL COMMENT 'Đặc tả',
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_job_reminders_contact`
--

CREATE TABLE `crm_job_reminders_contact` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contact_Id` bigint(20) DEFAULT NULL,
  `reminder_ID` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `is_color` smallint(1) DEFAULT '1',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=296 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_lead2opportunity_accounts`
--

CREATE TABLE `crm_lead2opportunity_accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `account_id` int(11) NOT NULL,
  `name` varchar(45) NOT NULL COMMENT 'merge|convert',
  `action` varchar(45) NOT NULL COMMENT 'create|exist',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_leads`
--

CREATE TABLE `crm_leads` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(16) NOT NULL DEFAULT 'lead' COMMENT 'Lead, Opportunity',
  `status` varchar(16) NOT NULL DEFAULT 'new' COMMENT 'New, Dead, Converted, Won, Lost',
  `is_company` bit(1) NOT NULL DEFAULT b'0',
  `name` varchar(255) DEFAULT NULL,
  `subject` varchar(255) DEFAULT NULL,
  `category_id` int(11) DEFAULT NULL,
  `title` varchar(16) DEFAULT NULL COMMENT 'Danh xưng: cô, gì, chú, bác, ông',
  `job_position` varchar(255) DEFAULT NULL,
  `birthdate` date DEFAULT NULL,
  `description` varchar(1024) DEFAULT NULL,
  `website` varchar(255) DEFAULT NULL,
  `service_id` int(11) DEFAULT NULL,
  `account_id` int(11) DEFAULT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `phone_mobile` varchar(45) NOT NULL,
  `phone_work` varchar(45) DEFAULT NULL,
  `phone_home` varchar(45) DEFAULT NULL,
  `phone_other` varchar(45) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `email2` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `address2` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  `source_type` int(11) NOT NULL DEFAULT '1' COMMENT '1 Tự liên hệ , 2 Từ hệ thống , 3 Kinh doanh tự nhập , 4 Telesale nhập , 5 Từ web master, TK liên kết, CTV , 6 Tự nhập , 7 Chăm sóc khách hàng nhập , 8 Affiliate',
  `last_activity_date` datetime DEFAULT NULL COMMENT 'lần chăm sóc cuối',
  `last_activity_due_date` datetime DEFAULT NULL COMMENT 'hạn của lần chăm sóc cuối',
  `has_open_activity` bit(1) NOT NULL DEFAULT b'0' COMMENT 'có task nào chưa thực hiện không',
  `has_overdue_task` bit(1) NOT NULL DEFAULT b'0' COMMENT 'có task nào quá hạn không',
  `free_date` datetime DEFAULT NULL COMMENT 'ngày cơ sở để tính thả nổi, tính bằng max của last_activity_date và last_activity_due_date',
  `pull_lead_date` datetime DEFAULT NULL COMMENT 'ngày kéo thả nổi về, dùng để tính đặt cuộc hẹn',
  PRIMARY KEY (`id`),
  KEY `modified` (`modified`),
  KEY `free_date` (`status`,`free_date`),
  KEY `service_id` (`service_id`),
  KEY `created` (`created`)
) ENGINE=InnoDB AUTO_INCREMENT=1072904 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_math_symbols`
--

CREATE TABLE `crm_math_symbols` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_notes`
--

CREATE TABLE `crm_notes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `reference_type` varchar(8) NOT NULL,
  `reference_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `body` text NOT NULL,
  `created_by` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `query` (`reference_type`,`reference_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=9872 DEFAULT CHARSET=utf8 COMMENT='note cho lead/opportunity/account';

--
-- Table structure for table `crm_object_notes`
--

CREATE TABLE `crm_object_notes` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `content` text,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `object` enum('CUSTOMER','POTENTIAL','CONTACT') DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `QueryIndex` (`object`,`post_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=727750 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_object_properties`
--

CREATE TABLE `crm_object_properties` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(100) DEFAULT NULL,
  `title` text,
  `post_id` bigint(20) DEFAULT NULL,
  `object` enum('CUSTOMER','POTENTIAL','CUSTOMER_CONTRACT','CONTACT','LOCATION','CONTRACT') DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `hidden` bit(1) DEFAULT b'0',
  PRIMARY KEY (`ID`),
  KEY `QueryIndex` (`object`,`post_id`,`type`),
  KEY `post_id` (`post_id`) USING BTREE,
  KEY `compare` (`title`(50),`type`,`object`)
) ENGINE=InnoDB AUTO_INCREMENT=5802711 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_object_represents`
--

CREATE TABLE `crm_object_represents` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `object` enum('CUSTOMER','POTENTIAL','CUSTOMER_CONTRACT','CONTACT') DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `formal_id` int(11) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `job_title` varchar(200) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `email` varchar(500) DEFAULT NULL,
  `phone` varchar(500) DEFAULT NULL,
  `address` varchar(600) DEFAULT NULL,
  `is_main` enum('0','1') DEFAULT '0' COMMENT '1: Người liên hệ chính',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=119500 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_open_service_requests`
--

CREATE TABLE `crm_open_service_requests` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `service` enum('BIZWEB') DEFAULT 'BIZWEB',
  `type` enum('OPENSERVICE','EXTEND','PAYMENT_OFFLINE','PAYMENT_ONLINE') DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL COMMENT 'chuỗi json',
  `description` varchar(255) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `approved_date` datetime DEFAULT NULL,
  `approved_by_id` int(11) DEFAULT NULL,
  `module` varchar(30) DEFAULT NULL,
  `post_id` int(11) DEFAULT NULL,
  `check_exists` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3139 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_opportunity_share_histories`
--

CREATE TABLE `crm_opportunity_share_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `opportunity_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `service_id` int(20) DEFAULT NULL,
  `created_by` bigint(20) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified_by` bigint(20) DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=486 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_perform_counts`
--

CREATE TABLE `crm_perform_counts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `value` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_perform_extend_dates`
--

CREATE TABLE `crm_perform_extend_dates` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `date` int(11) DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `created_date` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `updated_date` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_perform_site_times`
--

CREATE TABLE `crm_perform_site_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `value` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_perform_warning_times`
--

CREATE TABLE `crm_perform_warning_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `hour` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_performs`
--

CREATE TABLE `crm_performs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `code` varchar(50) DEFAULT NULL,
  `desc` text,
  `website` varchar(500) DEFAULT NULL,
  `template` varchar(500) DEFAULT NULL,
  `condition_type` enum('2','1','0') DEFAULT '0' COMMENT '0: chưa thực hiện, 1: đang thực hiện, 2: hoàn thành',
  `status` enum('1','0') DEFAULT '0' COMMENT '0 : Chờ xác nhận, 1 : Xác nhận',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `responsibility_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `care_id` bigint(20) DEFAULT NULL,
  `sale_support_id` bigint(20) DEFAULT NULL,
  `coordination_id` bigint(20) DEFAULT NULL,
  `date_deadline` datetime DEFAULT NULL,
  `work_created` bigint(20) DEFAULT NULL,
  `work_date_created` datetime DEFAULT NULL,
  `work_date_finish` datetime DEFAULT NULL,
  `is_send_notice_warning` enum('0','1') DEFAULT '0',
  `origin` enum('SALE','CARE','COORDINATION') DEFAULT 'COORDINATION',
  `has_done_task` enum('0','1') DEFAULT '0' COMMENT '0: Chưa có , 1 : Đã có công việc được hoàn thành',
  PRIMARY KEY (`ID`),
  KEY `Idx_contract_id` (`contract_id`),
  KEY `Idx_sale_id` (`sale_id`),
  KEY `Idx_coordination_id` (`coordination_id`)
) ENGINE=InnoDB AUTO_INCREMENT=14609 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_comments`
--

CREATE TABLE `crm_potential_comments` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `content` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_free_times`
--

CREATE TABLE `crm_potential_free_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `month` bigint(20) DEFAULT NULL,
  `day` bigint(20) DEFAULT NULL,
  `hour` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_origins`
--

CREATE TABLE `crm_potential_origins` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL,
  `desc` varchar(255) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `is_fixed` enum('1','0') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_properties`
--

CREATE TABLE `crm_potential_properties` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(100) DEFAULT NULL,
  `title` text,
  `potential_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_share_calendars`
--

CREATE TABLE `crm_potential_share_calendars` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date` date DEFAULT NULL,
  `user_ids` varchar(600) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_share_histories`
--

CREATE TABLE `crm_potential_share_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `potential_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `sms_status` enum('NONE','PENDING','SENT','INVALID') DEFAULT 'NONE' COMMENT 'NONE: Chưa gửi, ''PENDING'': Đang gửi, ''SENT'': Đã gửi, ''INVALID'': Không hợp lệ',
  PRIMARY KEY (`ID`),
  KEY `SMS_STATUS` (`sms_status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1418 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_share_top`
--

CREATE TABLE `crm_potential_share_top` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `sale_id` bigint(20) NOT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `sale_id_UNIQUE` (`sale_id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_status`
--

CREATE TABLE `crm_potential_status` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `desc` varchar(300) DEFAULT NULL,
  `is_appointment` enum('0','1') DEFAULT '0',
  `is_fixed` enum('1','0') DEFAULT '0',
  `color` varchar(50) DEFAULT '#FFFFFF',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `is_activated` enum('0','1') DEFAULT '1',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potential_status_histories`
--

CREATE TABLE `crm_potential_status_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `potential_id` bigint(20) DEFAULT NULL,
  `status_id` bigint(20) DEFAULT NULL,
  `date_appointment` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `desc` varchar(500) CHARACTER SET utf8 DEFAULT NULL,
  `status_type` enum('POTENTIAL','CONTACT') CHARACTER SET utf8 DEFAULT 'POTENTIAL',
  `meeting_status` enum('1','2','3','4') CHARACTER SET utf8 DEFAULT NULL COMMENT '1: xác nhận\n2: không xác nhận\n3: hủy\n4: đã thả nổi, chỉ view',
  `meeting_confirm_desc` varchar(500) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `potential_id` (`potential_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Table structure for table `crm_potential_warning_times`
--

CREATE TABLE `crm_potential_warning_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `hour` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_potentials`
--

CREATE TABLE `crm_potentials` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `condition_type` enum('FREE','WARNING','NORMAL','TRASH','DELETED') DEFAULT 'NORMAL' COMMENT 'tinh trang contact : free : th? n?i, warning : canh bao, normal : binh thuong, trash : rac, deleted ; da xoa',
  `code` varchar(200) DEFAULT NULL COMMENT '0:ca nhan, 1 : to chuc',
  `type` enum('0','1') DEFAULT '0' COMMENT '0: Cá nhân, 1: T? ch?c',
  `formal_name` int(11) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `represent_id` bigint(20) DEFAULT NULL,
  `formal_represent` int(11) DEFAULT NULL,
  `represent` varchar(200) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `phones` varchar(600) DEFAULT NULL,
  `emails` varchar(600) DEFAULT NULL,
  `websites` varchar(600) DEFAULT NULL,
  `address` text,
  `trade_id` int(11) DEFAULT NULL,
  `private_code` varchar(200) DEFAULT NULL,
  `private_date` date DEFAULT NULL,
  `private_place` int(11) DEFAULT NULL,
  `job_tax` varchar(200) DEFAULT NULL,
  `job_date` date DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `telesale_department_id` int(11) DEFAULT NULL,
  `desc` text,
  `status_id` bigint(20) DEFAULT NULL,
  `status_last_date` datetime DEFAULT NULL,
  `contact_status_id` int(11) DEFAULT NULL,
  `status_last_type` enum('POTENTIAL','CONTACT') NOT NULL DEFAULT 'POTENTIAL',
  `contact_status_last_date` datetime DEFAULT NULL,
  `date_appointment` datetime DEFAULT NULL,
  `origin_id` bigint(20) DEFAULT NULL COMMENT 'Nguon goc contact : Lay tu bang crm_contact_orgins : do KD nhap, telesale nhap, tu web...',
  `origin_desc` varchar(500) DEFAULT NULL COMMENT 'Mô t? lo?i ngu?n g?c',
  `created_by_id` int(11) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `date_action_updated` datetime NOT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `care_id` bigint(20) DEFAULT NULL,
  `region_id` int(11) DEFAULT NULL,
  `condition_type_old` varchar(200) DEFAULT NULL,
  `is_merge` enum('yes','no') DEFAULT 'no',
  `care_last_id` bigint(20) DEFAULT NULL,
  `care_last_date` datetime DEFAULT NULL,
  `root_id` bigint(20) DEFAULT NULL,
  `note_last_id` bigint(20) DEFAULT NULL,
  `note_last_date` datetime DEFAULT NULL,
  `count_note` bigint(20) DEFAULT NULL,
  `count_history_status` int(11) DEFAULT NULL,
  `count_action_care` int(11) DEFAULT NULL,
  `contact_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `sale_id_old` bigint(20) DEFAULT NULL,
  `sale_date_old` datetime DEFAULT NULL,
  `convert_customer` enum('0','1') NOT NULL DEFAULT '0',
  `convert_date` datetime DEFAULT NULL,
  `convert_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `date_assign` datetime DEFAULT NULL,
  `child_merge_ids` text,
  `time_cron` datetime DEFAULT NULL,
  `free_time` datetime DEFAULT NULL,
  `free_type` int(11) DEFAULT '0',
  `rs_id` int(11) DEFAULT NULL,
  `f_1` varchar(300) DEFAULT NULL,
  `f_2` varchar(300) DEFAULT NULL,
  `f_3` varchar(300) DEFAULT NULL,
  `f_4` varchar(300) DEFAULT NULL,
  `first_meeting_id` bigint(20) DEFAULT NULL,
  `is_created_action` enum('0','1') DEFAULT NULL,
  `last_meeting_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `rs_id_index` (`rs_id`),
  KEY `sale_id` (`sale_id`),
  KEY `telesale_id` (`telesale_id`) USING BTREE,
  KEY `created_by_id` (`created_by_id`),
  KEY `care_id` (`care_id`),
  KEY `date_created` (`date_created`),
  KEY `root_id` (`root_id`) USING BTREE,
  KEY `date_action_updated` (`date_action_updated`),
  KEY `date_appointment` (`date_appointment`),
  KEY `contact_id` (`contact_id`) USING BTREE,
  KEY `customer_id` (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=160012 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_product_package_date_ranges`
--

CREATE TABLE `crm_product_package_date_ranges` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `package_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `from_date` date DEFAULT NULL,
  `to_date` date DEFAULT NULL,
  `status` enum('0','1') DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_product_service_discounts`
--

CREATE TABLE `crm_product_service_discounts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  `symbol_id` bigint(20) DEFAULT NULL,
  `month` bigint(20) DEFAULT NULL,
  `discount` decimal(20,5) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_product_service_fields`
--

CREATE TABLE `crm_product_service_fields` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `type` varchar(50) DEFAULT NULL,
  `params` text,
  `is_required` enum('1','0') DEFAULT '0',
  `is_many` enum('0','1') DEFAULT '0',
  `is_contract_required` enum('0','1') DEFAULT '0',
  `is_contract_many` enum('0','1') DEFAULT '0',
  `is_fix` enum('0','1') DEFAULT '0',
  `key` varchar(100) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_product_service_packages`
--

CREATE TABLE `crm_product_service_packages` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` bigint(20) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `interval_time` enum('days','weeks','months','years') NOT NULL DEFAULT 'months',
  `number_default` decimal(20,5) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `accompanied_ids` varchar(100) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `number_perform` bigint(20) DEFAULT NULL,
  `template_ids` varchar(300) DEFAULT NULL,
  `status` enum('0','1') DEFAULT NULL COMMENT '0 : active\n1 : inactive',
  PRIMARY KEY (`ID`),
  KEY `service_id` (`service_id`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_product_services`
--

CREATE TABLE `crm_product_services` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(50) DEFAULT NULL,
  `type` enum('SERVICE','PRODUCT') DEFAULT NULL,
  `company_id` int(11) DEFAULT NULL,
  `website` varchar(500) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `desc` text,
  `created_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `field_ids` varchar(500) DEFAULT NULL,
  `contract_field_ids` varchar(500) DEFAULT NULL,
  `care_loop_day` int(11) DEFAULT NULL,
  `has_vat` enum('0','1') DEFAULT '0',
  `is_domain_service` enum('0','1') DEFAULT '0',
  `website_required` enum('0','1') DEFAULT '1',
  `template_ids` varchar(500) DEFAULT NULL,
  `other_websites` enum('0','1') DEFAULT '0' COMMENT '''0'' : Không hiển thị nhập nhiều website khác\n''1'' : Hiển thị nhập nhiều website khác',
  `customizable_package` enum('0','1') DEFAULT '0',
  `has_initial_price` enum('0','1') DEFAULT '0' COMMENT '0 : Không hiển thị trường "Chi phí khởi tạo" khi tạo HĐ.  1: Có hiển thị',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_region_types`
--

CREATE TABLE `crm_region_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(300) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_report_time_configs`
--

CREATE TABLE `crm_report_time_configs` (
  `ID` bigint(20) NOT NULL,
  `title` varchar(500) DEFAULT NULL,
  `time` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `type` enum('CUSTOMER','POTENTIAL') DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_sapo_sync_datas`
--

CREATE TABLE `crm_sapo_sync_datas` (
  `id` int(11) DEFAULT NULL,
  `sapo_id` int(11) DEFAULT NULL,
  `name` text,
  `phone_mobile` text,
  `email` text,
  `address` text,
  `city` text,
  `sale` text,
  `website` text,
  `package_name` text,
  `started_date` datetime DEFAULT NULL,
  `expired_date` datetime DEFAULT NULL,
  `sync_status` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_service_accompanieds`
--

CREATE TABLE `crm_service_accompanieds` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `unit_id` bigint(20) DEFAULT NULL,
  `number` bigint(20) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_service_bonus`
--

CREATE TABLE `crm_service_bonus` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  `symbol_id` bigint(20) DEFAULT NULL,
  `bonus_condition` bigint(20) DEFAULT NULL,
  `bonus_time` bigint(20) DEFAULT NULL,
  `bonus_interval_time` enum('days','weeks','months','years') NOT NULL DEFAULT 'months',
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_service_bonus_times`
--

CREATE TABLE `crm_service_bonus_times` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `month` varchar(255) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_setting_warning_charge_money`
--

CREATE TABLE `crm_setting_warning_charge_money` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `time_warning` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `is_active` enum('0','1') DEFAULT '1',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_setting_warning_deadline_approve_sites`
--

CREATE TABLE `crm_setting_warning_deadline_approve_sites` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `time_warning` float DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `format` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_sharing_cycles`
--

CREATE TABLE `crm_sharing_cycles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(16) NOT NULL,
  `user_id` int(11) NOT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `var_long` bigint(20) DEFAULT NULL,
  `var_char` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  KEY `var_long` (`var_long`)
) ENGINE=InnoDB AUTO_INCREMENT=1151 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_sharing_histories`
--

CREATE TABLE `crm_sharing_histories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trial_service_id` int(11) NOT NULL,
  `lead_id` int(11) DEFAULT NULL,
  `user_id` int(11) NOT NULL,
  `previous_user_id` int(11) DEFAULT NULL,
  `description` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `created` (`created`),
  KEY `lead` (`lead_id`),
  KEY `trial_service_id` (`trial_service_id`)
) ENGINE=InnoDB AUTO_INCREMENT=126595 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_sharing_rows`
--

CREATE TABLE `crm_sharing_rows` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `service_id` int(11) NOT NULL,
  `type` varchar(16) NOT NULL,
  `user_id` int(11) NOT NULL,
  `expected` int(11) NOT NULL DEFAULT '0',
  `actual` int(11) NOT NULL DEFAULT '0',
  `round` int(11) NOT NULL DEFAULT '0',
  `condition_time` bigint(20) NOT NULL,
  `last_time` bigint(20) NOT NULL DEFAULT '0',
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `type` (`type`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3354 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_staff_roles`
--

CREATE TABLE `crm_staff_roles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `role` varchar(20) NOT NULL COMMENT 'Sale (SALES), Telesales (TELE), Sale support (SUPPORT), Customer service (CARE)',
  `lineage` varchar(50) NOT NULL,
  `lead_id` int(11) NOT NULL,
  `account_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_id` (`lead_id`,`role`),
  KEY `IDX_crm_staff_roles_account_id` (`account_id`),
  KEY `lead_id` (`lead_id`),
  KEY `lineage` (`lineage`)
) ENGINE=InnoDB AUTO_INCREMENT=2795804 DEFAULT CHARSET=utf8 COMMENT='check quyền trên contact/cơ hội';

--
-- Table structure for table `crm_support_topics`
--

CREATE TABLE `crm_support_topics` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_target_approver_configs`
--

CREATE TABLE `crm_target_approver_configs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_target_configs`
--

CREATE TABLE `crm_target_configs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `date_from` datetime DEFAULT NULL,
  `date_to` datetime DEFAULT NULL,
  `date_deadline` datetime DEFAULT NULL,
  `type` enum('MONEY','NUMBER') DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `status` enum('2','1','0') DEFAULT '0' COMMENT '0 : chờ duyệt, 1 : duyệt, 2 : không duyệt',
  `is_effect` enum('1','0') DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `date_approver` datetime DEFAULT NULL,
  `approver_user_id` int(11) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `group_types` varchar(255) DEFAULT NULL,
  `user_register_ids` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_target_persons`
--

CREATE TABLE `crm_target_persons` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `target_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `type` varchar(255) DEFAULT NULL,
  `number` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `date_register` datetime DEFAULT NULL,
  `date_from` datetime DEFAULT NULL,
  `date_to` datetime DEFAULT NULL,
  `status` enum('0','-1','1') DEFAULT '0' COMMENT '-1 : add vao, 0 : cho duyet, 1 : da duyet',
  `approver_id` bigint(20) DEFAULT NULL,
  `date_approver` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_task_results`
--

CREATE TABLE `crm_task_results` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(10) NOT NULL,
  `name` varchar(50) NOT NULL,
  `order_no` int(11) NOT NULL DEFAULT '1',
  `created_by` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='các kết quả khác nhau tùy theo kiểu task khác nhau';

--
-- Table structure for table `crm_tasks`
--

CREATE TABLE `crm_tasks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `reference_type` varchar(16) DEFAULT NULL COMMENT 'LEAD,CONTRACT',
  `reference_id` int(11) DEFAULT NULL,
  `priority` varchar(1) NOT NULL DEFAULT 'N' COMMENT 'mức ưu tiên bình thường(0) hoặc cao(1)',
  `owner_id` int(11) NOT NULL,
  `delegated` bit(1) NOT NULL DEFAULT b'0',
  `due_date` datetime DEFAULT NULL,
  `closed` bit(1) NOT NULL DEFAULT b'0' COMMENT 'trạng thái: open, in progress, close',
  `subject` varchar(255) NOT NULL,
  `type` varchar(10) NOT NULL COMMENT 'Call,Email,Task',
  `result` int(11) DEFAULT NULL COMMENT 'tùy theo type khác nhau mà tập result khác nhau',
  `result_description` varchar(255) DEFAULT NULL,
  `description` text,
  `created_by` int(11) NOT NULL,
  `created` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `owner` (`owner_id`,`due_date`),
  KEY `owner_id` (`owner_id`) USING BTREE,
  KEY `created` (`created`),
  KEY `reference_id` (`reference_id`),
  KEY `created_by` (`created_by`) USING BTREE,
  KEY `reference_type` (`reference_type`) USING BTREE,
  KEY `meeting` (`owner_id`,`type`,`result`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2299393 DEFAULT CHARSET=utf8 COMMENT='các chăm sóc dạng task';

--
-- Table structure for table `crm_telesale_divides`
--

CREATE TABLE `crm_telesale_divides` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `telesale_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `round` bigint(20) DEFAULT NULL,
  `priority` decimal(20,0) DEFAULT NULL,
  `type` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1517 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_template_exports`
--

CREATE TABLE `crm_template_exports` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) NOT NULL,
  `type` varchar(300) NOT NULL,
  `size` varchar(100) NOT NULL,
  `name` varchar(200) NOT NULL,
  `filename` varchar(300) NOT NULL,
  `module` varchar(100) NOT NULL,
  `type_contract` enum('UPGRADE','RESIGN','NEW','WHITE','LIQUIDATION','APPENDIX') DEFAULT 'WHITE' COMMENT 'NEW : mới, Resign : gia hạn, upgrade : nâng cấp,white: hợp đồng trắng, LIQUIDATION :thanh lý, APPENDIX : tính năng cộng thêm ',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_trade_types`
--

CREATE TABLE `crm_trade_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT '-1',
  `depth` int(20) DEFAULT '0',
  `lineage` varchar(200) DEFAULT '/',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_trash_filter`
--

CREATE TABLE `crm_trash_filter` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` varchar(1) NOT NULL COMMENT 'PHONE (P), EMAIL (E)',
  `value` varchar(255) NOT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique` (`type`,`value`)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8 COMMENT='Bảng lọc rác số điện thoại và email';

--
-- Table structure for table `crm_trial_service_meta`
--

CREATE TABLE `crm_trial_service_meta` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trial_service_id` int(11) NOT NULL,
  `meta_key` varchar(20) NOT NULL,
  `meta_value` text,
  PRIMARY KEY (`id`),
  KEY `trial_service_id` (`trial_service_id`),
  KEY `meta_key` (`meta_key`) USING BTREE,
  FULLTEXT KEY `meta_value` (`meta_value`)
) ENGINE=InnoDB AUTO_INCREMENT=1528933 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_trial_services`
--

CREATE TABLE `crm_trial_services` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `service` varchar(20) NOT NULL,
  `website` varchar(255) NOT NULL,
  `status` varchar(20) NOT NULL DEFAULT 'UNKNOWN',
  `started_date` datetime DEFAULT NULL COMMENT 'Ngày bắt đầu dùng thử dịch vụ',
  `expired_date` datetime DEFAULT NULL COMMENT 'Ngày hết hạn dùng thử dịch vụ',
  `lead_id` int(11) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `lead_id` (`lead_id`)
) ENGINE=InnoDB AUTO_INCREMENT=202503 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_units`
--

CREATE TABLE `crm_units` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_user_group_positions`
--

CREATE TABLE `crm_user_group_positions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `group_type` enum('CARE','TELESALE','SALE','SALE_SUPPORT','COORDINATION') DEFAULT NULL,
  `position_ids` varchar(500) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_user_groups`
--

CREATE TABLE `crm_user_groups` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `group_type` enum('CARE','TELESALE','SALE') DEFAULT NULL,
  `region_id` int(11) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_user_relations`
--

CREATE TABLE `crm_user_relations` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `sale_support_id` bigint(20) DEFAULT NULL,
  `coordination_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=549 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_value_added_packages`
--

CREATE TABLE `crm_value_added_packages` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `package_id` bigint(20) NOT NULL,
  `value_added_id` bigint(20) NOT NULL,
  `price` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `dynamic_price` enum('0','1') DEFAULT '0',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `unique` (`package_id`,`value_added_id`),
  KEY `package_id` (`package_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10197 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_value_added_services`
--

CREATE TABLE `crm_value_added_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `unit` varchar(45) DEFAULT NULL,
  `has_vat` enum('1','0') DEFAULT '0',
  `is_activated` enum('1','0') NOT NULL DEFAULT '1',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=246 DEFAULT CHARSET=utf8;

--
-- Table structure for table `cron_emails`
--

CREATE TABLE `cron_emails` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `data` longtext,
  `date` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crons`
--

CREATE TABLE `crons` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `uid` varchar(50) DEFAULT NULL,
  `url` varchar(500) DEFAULT NULL,
  `repeat_type` enum('NONE','DAILY','WEEKLY','MONTHLY','QUARTERLY','YEARLY','MINUTELY','HOURLY') DEFAULT 'NONE',
  `start` datetime DEFAULT NULL,
  `repeat_condition` varchar(500) DEFAULT NULL COMMENT 'desc accepted value: 1,2,3,4,5,6,7,INTERVAL,LAST_MONTH,DATE_IN_MONTH,DATE_IN_YEAR,LAST_QUARTER,FIRST_QUARTER',
  `repeat_end_type` enum('DATE','FOREVER','COUNT') DEFAULT NULL,
  `repeat_interval` int(11) DEFAULT NULL,
  `repeat_end_count` int(11) DEFAULT NULL,
  `repeat_end_date` datetime DEFAULT NULL,
  `data` text,
  `last_time` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `repeat_type` (`repeat_type`),
  KEY `start` (`start`)
) ENGINE=InnoDB AUTO_INCREMENT=378975 DEFAULT CHARSET=utf8;

--
-- Table structure for table `currencies`
--

CREATE TABLE `currencies` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `code` varchar(50) DEFAULT NULL,
  `symbol` varchar(50) DEFAULT NULL,
  `unit` varchar(50) DEFAULT NULL,
  `number_basic` int(11) DEFAULT NULL,
  `rate` decimal(20,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `departments`
--

CREATE TABLE `departments` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(200) DEFAULT NULL,
  `parent_id` bigint(20) NOT NULL DEFAULT '0',
  `is_fund` tinyint(4) DEFAULT '0',
  `is_company` enum('0','1') DEFAULT '0',
  `company_id` bigint(20) NOT NULL DEFAULT '0',
  `ord` bigint(20) DEFAULT '1',
  `desc` varchar(500) DEFAULT NULL,
  `lineage` varchar(255) DEFAULT '/',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1756 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_authorized`
--

CREATE TABLE `diploma_authorized` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `user_authorized_diploma` bigint(20) DEFAULT NULL,
  `user_authorized_task` bigint(20) DEFAULT NULL,
  `date_start` date NOT NULL,
  `date_end` date NOT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_comment_files`
--

CREATE TABLE `diploma_comment_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `comment_id` bigint(20) NOT NULL,
  `name` varchar(500) DEFAULT NULL,
  `filename` varchar(500) DEFAULT NULL,
  `type` varchar(300) DEFAULT NULL,
  `size` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_comments`
--

CREATE TABLE `diploma_comments` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `post_id` bigint(20) NOT NULL,
  `module` enum('internal','external') DEFAULT 'internal',
  `date_created` datetime NOT NULL,
  `content` text,
  `date_updated` datetime NOT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_confidential_types`
--

CREATE TABLE `diploma_confidential_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_files`
--

CREATE TABLE `diploma_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(300) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL DEFAULT '0',
  `filename` varchar(300) DEFAULT NULL,
  `size` varchar(200) DEFAULT NULL,
  `type` varchar(300) DEFAULT NULL,
  `post_id` bigint(20) NOT NULL,
  `module` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_histories`
--

CREATE TABLE `diploma_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `file_id` bigint(20) NOT NULL DEFAULT '0',
  `user_id` bigint(20) NOT NULL,
  `process_id` bigint(20) DEFAULT NULL,
  `step_id` bigint(20) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `ord` tinyint(4) DEFAULT NULL,
  `date` datetime NOT NULL,
  `desc` text,
  `process_deadline` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_internal_writers`
--

CREATE TABLE `diploma_internal_writers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `ord` tinyint(4) NOT NULL DEFAULT '0',
  `parent_id` int(11) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_persons`
--

CREATE TABLE `diploma_persons` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `user_auth` bigint(20) DEFAULT NULL,
  `module` varchar(50) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process`
--

CREATE TABLE `diploma_process` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process_step_facts`
--

CREATE TABLE `diploma_process_step_facts` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `step` varchar(200) NOT NULL,
  `action_id` int(11) DEFAULT NULL,
  `step_next` varchar(200) DEFAULT NULL,
  `action_next_id` int(11) DEFAULT NULL,
  `is_person` enum('0','1') DEFAULT '0',
  `is_person_too` enum('0','1') DEFAULT '0',
  `date_started` datetime DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process_step_sees`
--

CREATE TABLE `diploma_process_step_sees` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `diploma_id` bigint(20) DEFAULT NULL,
  `process_id` bigint(20) DEFAULT NULL,
  `step` tinyint(4) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process_step_too_users`
--

CREATE TABLE `diploma_process_step_too_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `diploma_id` bigint(20) NOT NULL,
  `process_id` bigint(20) NOT NULL,
  `step` tinyint(4) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process_step_users`
--

CREATE TABLE `diploma_process_step_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `diploma_id` bigint(20) NOT NULL,
  `process_id` bigint(20) NOT NULL,
  `step` tinyint(4) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  `process_deadline` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process_steps`
--

CREATE TABLE `diploma_process_steps` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `is_initialize` tinyint(1) NOT NULL DEFAULT '0',
  `post_id` bigint(20) NOT NULL,
  `step` int(11) DEFAULT NULL,
  `action_id` int(11) DEFAULT NULL,
  `step_next` int(11) DEFAULT NULL,
  `action_next_id` int(11) DEFAULT NULL,
  `is_person` enum('0','1') DEFAULT '0',
  `is_person_too` enum('0','1') DEFAULT '0',
  `date_started` datetime DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_process_types`
--

CREATE TABLE `diploma_process_types` (
  `ID` int(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `action` enum('0','1') DEFAULT '0',
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_recipient_users`
--

CREATE TABLE `diploma_recipient_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `type` enum('internal','external') NOT NULL DEFAULT 'internal',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_step_users`
--

CREATE TABLE `diploma_step_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `step_id` bigint(20) NOT NULL COMMENT '`step_id` is `ID` in `diploma_steps`',
  `user_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_steps`
--

CREATE TABLE `diploma_steps` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `process_id` bigint(20) NOT NULL,
  `step` tinyint(4) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diploma_types`
--

CREATE TABLE `diploma_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `ord` tinyint(4) DEFAULT NULL,
  `parent_id` tinyint(4) DEFAULT '0',
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diplomas`
--

CREATE TABLE `diplomas` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `type` enum('internal','external') DEFAULT 'internal',
  `user_id` bigint(20) NOT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `priority` tinyint(4) DEFAULT '0',
  `code` varchar(150) DEFAULT NULL,
  `code1` varchar(150) DEFAULT NULL,
  `place` varchar(300) DEFAULT NULL,
  `status` enum('0','1','2','3','4') DEFAULT '0',
  `about` text,
  `writer` bigint(20) DEFAULT NULL,
  `abstract` text,
  `desc` text,
  `is_process` tinyint(4) DEFAULT '0',
  `process_id` int(11) DEFAULT NULL,
  `step_id` bigint(20) DEFAULT NULL,
  `step` int(11) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `date_finish` date DEFAULT NULL,
  `time_planned` time DEFAULT NULL,
  `date_planned` date DEFAULT NULL,
  `deadline_planned` datetime DEFAULT NULL,
  `last_action` int(11) DEFAULT '0',
  `last_step` tinyint(4) DEFAULT '0',
  `current_step` tinyint(4) DEFAULT '0',
  `datetime_checked` datetime DEFAULT NULL,
  `date_ceo_started` datetime DEFAULT NULL,
  `deadline` datetime DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_status` enum('0','1','2') NOT NULL DEFAULT '0',
  `approver_desc` text,
  `approver_date` datetime DEFAULT NULL,
  `rollback_id` bigint(20) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `rollback_date` datetime DEFAULT NULL,
  `rollback_desc` text,
  `rollback_ord` tinyint(4) DEFAULT NULL COMMENT '0:person is ceo',
  `recipient_id` bigint(20) DEFAULT NULL,
  `recipient_date` datetime DEFAULT NULL,
  `relative` enum('0','1','2') DEFAULT '0' COMMENT '''1'' is ''external'', ''2'' is task',
  `relative_id` bigint(20) DEFAULT NULL,
  `paper_number` text NOT NULL,
  `save_diploma` text NOT NULL,
  `recipient_dep` text NOT NULL,
  `diploma_types` enum('1','2','3','4') NOT NULL,
  `con_type` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `diplomas_reads`
--

CREATE TABLE `diplomas_reads` (
  `user_id` bigint(20) NOT NULL,
  `diploma_id` bigint(20) NOT NULL,
  `date_read` datetime DEFAULT NULL,
  `date_active` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `diplomas_users`
--

CREATE TABLE `diplomas_users` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `diploma_id` bigint(32) NOT NULL,
  `user_id` bigint(32) NOT NULL,
  `is_approver` enum('yes','no') NOT NULL DEFAULT 'no',
  `is_processor` enum('yes','no') NOT NULL DEFAULT 'no',
  `is_main_processor` enum('yes','no') NOT NULL DEFAULT 'no',
  `is_guest` enum('yes','no') NOT NULL DEFAULT 'no',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `document_files`
--

CREATE TABLE `document_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(300) DEFAULT NULL,
  `filename` varchar(300) DEFAULT NULL,
  `size` varchar(200) DEFAULT NULL,
  `type` varchar(300) DEFAULT NULL,
  `document_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `document_labels`
--

CREATE TABLE `document_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(250) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `document_reads`
--

CREATE TABLE `document_reads` (
  `user_id` bigint(20) NOT NULL,
  `document_id` bigint(20) NOT NULL,
  `module` varchar(20) NOT NULL,
  `first_date` datetime DEFAULT NULL,
  `last_date` datetime DEFAULT NULL,
  PRIMARY KEY (`user_id`,`document_id`,`module`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `document_types`
--

CREATE TABLE `document_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `ord` tinyint(4) NOT NULL DEFAULT '0',
  `parent_id` int(11) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `documents`
--

CREATE TABLE `documents` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `is_deleted` enum('yes','no') DEFAULT 'no',
  `folder` enum('USER','COMPANY','COMMON') NOT NULL DEFAULT 'USER',
  `type` enum('FILE','FOLDER') NOT NULL DEFAULT 'FOLDER',
  `parent_id` bigint(20) NOT NULL,
  `child_ids` text,
  `title` varchar(500) DEFAULT NULL,
  `file_id` bigint(20) DEFAULT NULL,
  `user_owners` text,
  `user_edits` text,
  `user_shares` text,
  `user_views` text,
  `department_owners` text,
  `department_edits` text,
  `department_shares` text,
  `department_views` text,
  `department_exclude_views` text,
  `uroot` text,
  `droot` text,
  `troot` enum('1','0') DEFAULT NULL,
  `my_documents` text,
  `owner_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `caches` (`folder`,`type`,`parent_id`,`file_id`)
) ENGINE=InnoDB AUTO_INCREMENT=513 DEFAULT CHARSET=utf8;

--
-- Table structure for table `documents_document_labels`
--

CREATE TABLE `documents_document_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `document_id` bigint(20) NOT NULL,
  `label_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8;

--
-- Table structure for table `documents_users`
--

CREATE TABLE `documents_users` (
  `ID` bigint(33) NOT NULL AUTO_INCREMENT,
  `document_id` bigint(33) NOT NULL,
  `user_id` bigint(33) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `domain_accounts`
--

CREATE TABLE `domain_accounts` (
  `id` int(11) NOT NULL DEFAULT '0',
  `company` bit(1) NOT NULL DEFAULT b'0',
  `category_id` int(11) DEFAULT NULL COMMENT 'lĩnh vực kinh doanh',
  `name` varchar(255) NOT NULL,
  `title` varchar(16) DEFAULT NULL COMMENT 'Danh xưng: cô, gì, chú, bác, ông',
  `birthdate` date DEFAULT NULL,
  `description` varchar(1024) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL COMMENT 'mã công ty',
  `use_parent_address` bit(1) DEFAULT NULL,
  `display_name` varchar(255) NOT NULL COMMENT 'tên hiển thị (= tên công ty, tên cá nhân)',
  `job_position` varchar(45) DEFAULT NULL,
  `phone_mobile` varchar(45) NOT NULL,
  `phone_work` varchar(45) DEFAULT NULL,
  `phone_home` varchar(45) DEFAULT NULL,
  `phone_other` varchar(45) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `email2` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `address2` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `domain_customers`
--

CREATE TABLE `domain_customers` (
  `ID` int(11) NOT NULL DEFAULT '0',
  `condition_type` enum('NORMAL','DELETED') NOT NULL DEFAULT 'NORMAL',
  `code` varchar(200) NOT NULL,
  `type` enum('0','1') DEFAULT '0' COMMENT '0: Cá nhân, 1: T? ch?c',
  `formal_name` int(11) DEFAULT NULL,
  `name` varchar(200) DEFAULT NULL,
  `represent_id` bigint(20) DEFAULT NULL,
  `formal_represent` int(11) DEFAULT NULL,
  `represent` varchar(200) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `phones` varchar(600) DEFAULT NULL,
  `emails` varchar(600) DEFAULT NULL,
  `websites` varchar(600) DEFAULT NULL,
  `address` text,
  `trade_id` int(11) DEFAULT NULL,
  `private_code` varchar(200) DEFAULT NULL,
  `private_date` date DEFAULT NULL,
  `private_place` int(11) DEFAULT NULL,
  `job_tax` varchar(200) DEFAULT NULL,
  `job_date` date DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `telesale_department_id` int(11) DEFAULT NULL,
  `desc` text,
  `created_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `sale_id` varchar(500) DEFAULT NULL,
  `telesale_id` varchar(500) DEFAULT NULL,
  `care_id` varchar(500) DEFAULT NULL,
  `region_id` int(11) DEFAULT NULL,
  `care_last_id` bigint(20) DEFAULT NULL,
  `care_last_date` datetime DEFAULT NULL,
  `root_id` bigint(20) DEFAULT NULL,
  `count_action_care` int(11) DEFAULT NULL,
  `potential_id` varchar(500) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `sale_id_old` bigint(20) DEFAULT NULL,
  `sale_date_old` datetime DEFAULT NULL,
  `sale_support_id` bigint(20) DEFAULT NULL,
  `sale_support_ids` varchar(500) DEFAULT NULL,
  `location_ids` varchar(200) DEFAULT NULL,
  `rs_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `domain_mapping_ids`
--

CREATE TABLE `domain_mapping_ids` (
  `customer_id` int(11) NOT NULL DEFAULT '0',
  `lead_id` int(11) NOT NULL DEFAULT '0',
  `contract_id` bigint(20) DEFAULT NULL,
  `phone` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `email_messages`
--

CREATE TABLE `email_messages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `subject` varchar(255) DEFAULT NULL,
  `data` text NOT NULL,
  `status` varchar(8) NOT NULL DEFAULT 'PENDING',
  `error` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime NOT NULL,
  `modified_by` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `status` (`status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=76571 DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_details`
--

CREATE TABLE `evaluation_details` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `evaluation_id` int(11) DEFAULT NULL,
  `percent` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_groups`
--

CREATE TABLE `evaluation_groups` (
  `post_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_mark_properties`
--

CREATE TABLE `evaluation_mark_properties` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `mark_id` int(11) DEFAULT NULL,
  `evaluation_id` int(11) DEFAULT NULL,
  `percent` int(11) DEFAULT NULL,
  `mark` varchar(100) DEFAULT NULL,
  `desc` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_marks`
--

CREATE TABLE `evaluation_marks` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `relationship` varchar(500) DEFAULT NULL,
  `point` float DEFAULT NULL,
  `charge_status` enum('0','1') NOT NULL DEFAULT '0',
  `desc_13` text,
  `desc_15` text,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_mutuals`
--

CREATE TABLE `evaluation_mutuals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `evaluator_id` int(11) DEFAULT NULL,
  `receive_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_properties`
--

CREATE TABLE `evaluation_properties` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `post_id` int(11) DEFAULT NULL,
  `deadline` date DEFAULT NULL,
  `type` enum('0','1') DEFAULT '0',
  `charge_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_report_descs`
--

CREATE TABLE `evaluation_report_descs` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `report_id` int(11) DEFAULT NULL,
  `mark_id` int(11) DEFAULT NULL,
  `evaluation_id` int(11) DEFAULT NULL,
  `desc` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_reports`
--

CREATE TABLE `evaluation_reports` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `mark_04` float DEFAULT NULL,
  `mark_05` float DEFAULT NULL,
  `mark_06` float DEFAULT NULL,
  `mark_07` float DEFAULT NULL,
  `desc_12` text,
  `desc_13` text,
  `desc_14` text,
  `desc_15` text,
  `desc_16` text,
  `charge_status` enum('0','1') NOT NULL DEFAULT '0',
  `approve_status` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_title_detail_results`
--

CREATE TABLE `evaluation_title_detail_results` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title_detail_id` int(11) DEFAULT NULL,
  `content` text,
  `mark_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_title_details`
--

CREATE TABLE `evaluation_title_details` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_types`
--

CREATE TABLE `evaluation_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `type` enum('0','1') NOT NULL DEFAULT '0',
  `unit` enum('1','2','3') NOT NULL DEFAULT '1',
  `type_unit` int(11) DEFAULT NULL,
  `desc` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_units`
--

CREATE TABLE `evaluation_units` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `units` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluation_users`
--

CREATE TABLE `evaluation_users` (
  `post_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `evaluations`
--

CREATE TABLE `evaluations` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `desc` text,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_mark_properties`
--

CREATE TABLE `exam_mark_properties` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `mark_id` int(11) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `point` float DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_marks`
--

CREATE TABLE `exam_marks` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `candidate_id` int(11) DEFAULT NULL,
  `point` float DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_points`
--

CREATE TABLE `exam_points` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `exam_id` bigint(20) DEFAULT NULL,
  `recruiment_id` bigint(20) DEFAULT NULL,
  `candidate_id` bigint(20) DEFAULT NULL,
  `type_id` bigint(20) DEFAULT NULL,
  `point` float DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_properties`
--

CREATE TABLE `exam_properties` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_recruiment_candidates`
--

CREATE TABLE `exam_recruiment_candidates` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `exam_id` bigint(20) DEFAULT NULL,
  `recruiment_id` bigint(20) DEFAULT NULL,
  `candidate_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_types`
--

CREATE TABLE `exam_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exam_users`
--

CREATE TABLE `exam_users` (
  `post_id` int(11) DEFAULT NULL,
  `candidate_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `exams`
--

CREATE TABLE `exams` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `desc` text,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `faqs`
--

CREATE TABLE `faqs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `is_menu` varchar(50) NOT NULL DEFAULT 'no',
  `title` varchar(300) DEFAULT NULL,
  `content` text,
  `parent_id` bigint(20) NOT NULL,
  `ord` bigint(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `field_logs`
--

CREATE TABLE `field_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `table` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `column` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `row_id` int(11) DEFAULT NULL,
  `value` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `created` (`created`),
  KEY `Idx_row_id` (`row_id`),
  FULLTEXT KEY `TableColumnRow` (`table`,`column`)
) ENGINE=InnoDB AUTO_INCREMENT=57827 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Table structure for table `files`
--

CREATE TABLE `files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `filename` varchar(300) DEFAULT NULL,
  `name` varchar(300) DEFAULT NULL,
  `path` text,
  `mime_type` varchar(100) DEFAULT NULL,
  `extension` varchar(100) DEFAULT NULL,
  `size` double(20,10) DEFAULT NULL,
  `desc` text,
  `url` varchar(300) DEFAULT NULL,
  `date` datetime NOT NULL,
  `module` varchar(50) DEFAULT NULL,
  `object` varchar(20) DEFAULT 'none',
  `object_id` bigint(20) DEFAULT NULL,
  `object1` varchar(20) DEFAULT NULL,
  `object1_id` bigint(20) DEFAULT NULL,
  `object2` varchar(20) DEFAULT NULL,
  `object2_id` bigint(20) DEFAULT NULL,
  `status` enum('PUBLIC','SECURE') NOT NULL DEFAULT 'SECURE',
  `created_by_id` bigint(20) NOT NULL,
  `is_deleted` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`),
  KEY `module` (`module`,`object`,`object_id`,`object1`,`object1_id`,`object2`,`object2_id`)
) ENGINE=InnoDB AUTO_INCREMENT=36816 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_approvers`
--

CREATE TABLE `finance_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `type` enum('approve','created') NOT NULL DEFAULT 'approve',
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=197 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_banks`
--

CREATE TABLE `finance_banks` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_bill_externals`
--

CREATE TABLE `finance_bill_externals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `ord` tinyint(4) DEFAULT '0',
  `parent_id` int(11) DEFAULT '0',
  `type` enum('EXTRA_EX','FADIN_EX') DEFAULT NULL COMMENT 'EXTRA_EX : Chi bất thường, FADIN_EX: Chi thường xuyên',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_bill_internals`
--

CREATE TABLE `finance_bill_internals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `ord` tinyint(4) DEFAULT '0',
  `parent_id` int(11) DEFAULT '0',
  `type` enum('EXTRA_IN','FADIN_IN') DEFAULT NULL COMMENT 'EXTRA_IN : Thu bất thường, FADIN_IN: Thu thường xuyên',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_bills`
--

CREATE TABLE `finance_bills` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `bill_id` int(11) DEFAULT NULL,
  `module` varchar(50) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_comment_externals`
--

CREATE TABLE `finance_comment_externals` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `post_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `content` text,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_comment_internals`
--

CREATE TABLE `finance_comment_internals` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `post_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `content` text,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_deleted_internals`
--

CREATE TABLE `finance_deleted_internals` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `internal_id_old` bigint(11) DEFAULT NULL COMMENT 'ID của phiếu thu cũ, để map sang 1 số bảng khác',
  `title` varchar(150) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `type` enum('CONTRACT','OTHER') DEFAULT 'CONTRACT',
  `contract_id` bigint(20) DEFAULT NULL,
  `bill_id` bigint(20) DEFAULT NULL,
  `type_bill_id` int(11) DEFAULT NULL,
  `type_fund_id` bigint(20) DEFAULT NULL,
  `type_money` enum('face','bank','baokim') DEFAULT 'face',
  `bank_id` bigint(20) DEFAULT NULL,
  `bank_id_desc` text,
  `is_bill` enum('0','1','2') DEFAULT '0',
  `is_bill_number` varchar(500) DEFAULT NULL,
  `is_bill_date` date DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `reason` text,
  `address` text,
  `total` decimal(20,5) DEFAULT NULL,
  `code` varchar(150) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `parent_id` int(11) DEFAULT NULL,
  `desc` text,
  `approver_id` bigint(20) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `rollback_id` bigint(20) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `rollback_date` datetime DEFAULT NULL,
  `rollback_desc` text,
  `date_approver` datetime DEFAULT NULL,
  `desc_approver` varchar(500) DEFAULT NULL,
  `date_income` datetime DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `account_date` datetime DEFAULT NULL,
  `accounting_id` bigint(20) DEFAULT NULL,
  `account_type` varchar(200) DEFAULT NULL COMMENT 'Loại quỹ,ngân hàng',
  `sale_id` bigint(20) DEFAULT NULL,
  `region_id` bigint(20) DEFAULT NULL,
  `date_income_second` date DEFAULT NULL,
  `label` smallint(6) DEFAULT '0',
  `note` varchar(255) DEFAULT NULL,
  `face_money_type_id` bigint(20) DEFAULT NULL COMMENT 'Loại tiền mặt được cấu hình',
  `finance_internal_bills` text COMMENT 'Dữ liệu map sang bảng `finance_internal_bills`',
  `disapproved_by_id` bigint(20) DEFAULT NULL COMMENT 'Người không duyệt phiếu thu-người xóa phiếu thu',
  `date_disapproved` datetime DEFAULT NULL COMMENT 'Ngày chọn trạng thái là không duyệt phiếu thu và xóa phiếu thu',
  `finance_reads` text COMMENT 'Lưu bản ghi trong bảng `finance_reads` dứoi dạng JSON trước khi xóa phiếu thu',
  `finance_bills` text COMMENT 'Lưu bản ghi trong bảng `finance_bills` dứoi dạng JSON trước khi xóa phiếu thu',
  `crm_income_sets` text COMMENT 'Lưu bản ghi trong bảng crm_income_sets trước khi xóa bảng này',
  `crm_income_gets` text COMMENT 'Các bản ghi của bảng crm_income_gets trước khi xóa',
  `crm_income_set_services` text COMMENT 'Các bản ghi của bảng `crm_income_set_services` trước khi xóa',
  `crm_income_get_services` text COMMENT 'Các bản ghi của bảng `crm_income_get_services` trước khi xóa',
  `crm_contract_bill_types` text COMMENT 'Các bản ghi của bảng `crm_contract_bill_types` trước khi xóa',
  `crm_contract_appendixs` text COMMENT 'Các bản ghi của bảng `crm_contract_appendixs` trước khi xóa',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=261 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_allocations`
--

CREATE TABLE `finance_external_allocations` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `department_id` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `external_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_bill_types`
--

CREATE TABLE `finance_external_bill_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `ord` int(11) DEFAULT '0',
  `parent_id` int(11) DEFAULT '0',
  `type` enum('EXTRA_EX','FADIN_EX') DEFAULT NULL COMMENT 'EXTRA_EX : Chi bất thường, FADIN_EX: Chi thường xuyên',
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_bills`
--

CREATE TABLE `finance_external_bills` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `external_id` bigint(20) NOT NULL,
  `value` decimal(20,5) DEFAULT '0.00000',
  `date_paid` date DEFAULT NULL,
  `code` smallint(6) DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT '0',
  `bill_id` bigint(20) DEFAULT '0',
  `bill_type_id` int(11) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_label_users`
--

CREATE TABLE `finance_external_label_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(150) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_labels`
--

CREATE TABLE `finance_external_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `label_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_lists`
--

CREATE TABLE `finance_external_lists` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `external_id` bigint(20) NOT NULL,
  `external_title` varchar(500) DEFAULT NULL,
  `external_bill` int(11) DEFAULT NULL,
  `external_amount` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `external_price` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `external_vat` int(11) NOT NULL,
  `external_total` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `external_desc` varchar(500) DEFAULT NULL,
  `external_bill_type_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_external_users`
--

CREATE TABLE `finance_external_users` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `external_id` bigint(32) NOT NULL,
  `user_id` bigint(32) NOT NULL,
  `is_approver` enum('yes','no') NOT NULL DEFAULT 'no',
  `is_processor` enum('yes','no') NOT NULL DEFAULT 'no',
  `is_main_processor` enum('yes','no') NOT NULL DEFAULT 'no',
  `is_guest` enum('yes','no') NOT NULL DEFAULT 'no',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_externals`
--

CREATE TABLE `finance_externals` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `list` text NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `type` enum('CONTRACT','OTHER') NOT NULL DEFAULT 'CONTRACT',
  `contract_id` bigint(20) DEFAULT NULL,
  `type_bill_id` int(11) DEFAULT NULL,
  `type_fund_id` bigint(20) DEFAULT NULL,
  `type_money` enum('face','bank','baokim') DEFAULT 'face',
  `is_bill` enum('0','1','2') DEFAULT '0',
  `is_bill_number` varchar(500) DEFAULT NULL,
  `is_bill_date` date DEFAULT NULL,
  `reason` text,
  `total` decimal(20,5) DEFAULT NULL,
  `code` varchar(150) DEFAULT NULL,
  `status` enum('0','1','2','3') DEFAULT '0',
  `parent_id` int(11) DEFAULT NULL,
  `date_public` date DEFAULT NULL,
  `date_send` date DEFAULT NULL,
  `date_get` date DEFAULT NULL,
  `priority` enum('0','1','2') NOT NULL DEFAULT '1',
  `abstract` text,
  `writer` varchar(200) DEFAULT NULL,
  `desc` text,
  `processor_id` bigint(20) DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `public_id` bigint(20) DEFAULT NULL,
  `date_process` datetime DEFAULT NULL,
  `date_approval` datetime DEFAULT NULL,
  `date_active` datetime DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `approver_id_1` bigint(20) DEFAULT NULL,
  `approver_status_1` enum('0','1','2') NOT NULL DEFAULT '0',
  `approver_desc_1` text,
  `approver_date_1` datetime DEFAULT NULL,
  `approver_id_2` bigint(20) DEFAULT NULL,
  `approver_status_2` enum('0','1','2') NOT NULL DEFAULT '0',
  `approver_desc_2` text,
  `approver_date_2` datetime DEFAULT NULL,
  `approver_id_3` bigint(20) DEFAULT NULL,
  `approver_status_3` enum('0','1','2') NOT NULL DEFAULT '0',
  `approver_desc_3` text,
  `approver_date_3` datetime DEFAULT NULL,
  `total_money` decimal(20,0) DEFAULT NULL,
  `allocation_money` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `bank_id` int(11) DEFAULT NULL,
  `rollback_id` bigint(20) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `rollback_date` datetime DEFAULT NULL,
  `rollback_desc` text,
  `account_date` datetime DEFAULT NULL,
  `accounting_id` bigint(20) DEFAULT NULL,
  `account_type` varchar(200) DEFAULT NULL COMMENT 'Loại quỹ,ngân hàng',
  `sale_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `ID` (`ID`,`date_created`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_face_money_types`
--

CREATE TABLE `finance_face_money_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL COMMENT 'Tên loại tiền mặt được cài đặt',
  `created_by_id` int(11) DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_files`
--

CREATE TABLE `finance_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(300) DEFAULT NULL,
  `filename` varchar(300) DEFAULT NULL,
  `size` varchar(200) DEFAULT NULL,
  `type` varchar(200) DEFAULT NULL,
  `post_id` bigint(20) NOT NULL,
  `module` varchar(100) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_allocations`
--

CREATE TABLE `finance_fund_allocations` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `fund_id` int(11) NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_approvers`
--

CREATE TABLE `finance_fund_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `fund_id` int(11) NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  `ord` tinyint(4) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=982 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_banks`
--

CREATE TABLE `finance_fund_banks` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(500) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `fund_id` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT '0.00000',
  `desc` varchar(500) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_checks`
--

CREATE TABLE `finance_fund_checks` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `fund_id` int(11) NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_reset_details`
--

CREATE TABLE `finance_fund_reset_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL,
  `post_id` int(11) NOT NULL,
  `fund_id` int(11) NOT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `value` decimal(20,5) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_resets`
--

CREATE TABLE `finance_fund_resets` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL,
  `fund_id` int(11) NOT NULL,
  `face` decimal(20,5) DEFAULT NULL,
  `baokim` decimal(20,5) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_fund_users`
--

CREATE TABLE `finance_fund_users` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `fund_id` int(11) NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=407 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_funds`
--

CREATE TABLE `finance_funds` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `max_limit` decimal(20,5) DEFAULT '0.00000',
  `department_id` bigint(20) NOT NULL,
  `face` decimal(20,5) DEFAULT '0.00000',
  `bank` decimal(20,5) DEFAULT '0.00000',
  `baokim` decimal(20,5) DEFAULT '0.00000',
  `ord` tinyint(4) DEFAULT '0',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_history_fund_banks`
--

CREATE TABLE `finance_history_fund_banks` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `fund_id` int(11) NOT NULL,
  `date` date NOT NULL,
  `bank_id` int(11) NOT NULL,
  `money` decimal(20,5) NOT NULL COMMENT 'tiền thủ quỹ ngân hàng lưu',
  `money_balance` decimal(20,5) DEFAULT NULL COMMENT 'Tiền kiểm quỹ lưu',
  `money_history` decimal(20,5) NOT NULL COMMENT 'tiền office lưu',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_history_funds`
--

CREATE TABLE `finance_history_funds` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `fund_id` int(11) NOT NULL,
  `date` date NOT NULL,
  `total_money_face` decimal(20,5) DEFAULT NULL COMMENT 'tiền thủ quỹ',
  `total_face_balance` decimal(25,5) DEFAULT NULL COMMENT 'tiền kiểm quỹ',
  `money_history_face` decimal(20,5) DEFAULT NULL COMMENT 'tiền mặt office lưu',
  `total_money_baokim` decimal(20,5) DEFAULT NULL COMMENT 'tiền thủ quỹ bảo kim kiểm',
  `total_baokim_balance` decimal(20,5) DEFAULT NULL COMMENT 'tiền bảo kim kiểm quỹ lưu',
  `money_history_baokim` decimal(20,5) DEFAULT NULL COMMENT 'tiền bảo kim office lưu',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_internal_bills`
--

CREATE TABLE `finance_internal_bills` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `internal_id` bigint(20) NOT NULL,
  `value` decimal(20,5) DEFAULT '0.00000',
  `date_paid` date DEFAULT NULL,
  `code` smallint(6) DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT '0',
  `bill_id` bigint(20) DEFAULT '0',
  `desc` varchar(500) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  `service_id` bigint(20) DEFAULT '0',
  `contract_service_type_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=15979 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_internal_label_users`
--

CREATE TABLE `finance_internal_label_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(150) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_internal_labels`
--

CREATE TABLE `finance_internal_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `label_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_internal_lists`
--

CREATE TABLE `finance_internal_lists` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `internal_id` bigint(20) NOT NULL,
  `internal_title` varchar(500) DEFAULT NULL,
  `internal_bill` int(11) DEFAULT NULL,
  `internal_amount` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `internal_price` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `internal_vat` int(11) NOT NULL,
  `internal_total` decimal(20,5) NOT NULL DEFAULT '0.00000',
  `internal_desc` varchar(500) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_internal_personnel_percents`
--

CREATE TABLE `finance_internal_personnel_percents` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `internal_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `money` decimal(20,3) DEFAULT NULL,
  `is_last` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_internals`
--

CREATE TABLE `finance_internals` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `type` enum('CONTRACT','OTHER') DEFAULT 'CONTRACT',
  `contract_id` bigint(20) DEFAULT NULL,
  `bill_id` bigint(20) DEFAULT NULL,
  `type_bill_id` int(11) DEFAULT NULL,
  `type_fund_id` bigint(20) DEFAULT NULL,
  `type_money` enum('face','bank','baokim') DEFAULT 'face',
  `bank_id` bigint(20) DEFAULT NULL,
  `bank_id_desc` text,
  `is_bill` enum('0','1','2') DEFAULT '0',
  `is_bill_number` varchar(500) DEFAULT NULL,
  `is_bill_date` date DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `reason` text,
  `address` text,
  `total` decimal(20,5) DEFAULT NULL,
  `code` varchar(150) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `parent_id` int(11) DEFAULT NULL,
  `desc` text,
  `approver_id` bigint(20) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `rollback_id` bigint(20) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `rollback_date` datetime DEFAULT NULL,
  `rollback_desc` text,
  `date_approver` datetime DEFAULT NULL,
  `desc_approver` varchar(500) DEFAULT NULL,
  `date_income` datetime DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `account_date` datetime DEFAULT NULL,
  `accounting_id` bigint(20) DEFAULT NULL,
  `account_type` varchar(200) DEFAULT NULL COMMENT 'Loại quỹ,ngân hàng',
  `sale_id` bigint(20) DEFAULT NULL,
  `region_id` bigint(20) DEFAULT NULL,
  `date_income_second` date DEFAULT NULL,
  `label` smallint(6) DEFAULT '0',
  `note` varchar(255) DEFAULT NULL,
  `face_money_type_id` bigint(20) DEFAULT NULL COMMENT 'Loại tiền mặt được cấu hình',
  PRIMARY KEY (`ID`),
  KEY `ID` (`ID`,`date_created`),
  KEY `Idx_finance_internals_contract_id` (`contract_id`),
  KEY `Idx_date_approver` (`date_approver`)
) ENGINE=InnoDB AUTO_INCREMENT=14100 DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_moneys`
--

CREATE TABLE `finance_moneys` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_move_users`
--

CREATE TABLE `finance_move_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `move_id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `is_guest` enum('yes','no') NOT NULL DEFAULT 'no',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_moves`
--

CREATE TABLE `finance_moves` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `personnel_id` bigint(20) NOT NULL,
  `fund_target` int(11) DEFAULT NULL,
  `fund_origin` int(11) DEFAULT NULL,
  `type` enum('in','out') DEFAULT 'in',
  `type_money_origin` enum('face','bank','baokim') DEFAULT 'face',
  `type_money_target` enum('face','bank','baokim') DEFAULT 'face',
  `bank_id_origin` int(11) DEFAULT NULL,
  `bank_id_target` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `status` enum('0','1','2','3') DEFAULT '0',
  `approver_id_1` bigint(20) NOT NULL,
  `approver_date_1` datetime DEFAULT NULL,
  `approver_desc_1` varchar(500) DEFAULT NULL,
  `approver_status_1` enum('0','1','2') DEFAULT '0',
  `approver_id_2` bigint(20) NOT NULL,
  `approver_date_2` datetime DEFAULT NULL,
  `approver_desc_2` varchar(500) DEFAULT NULL,
  `approver_status_2` enum('0','1','2') DEFAULT '0',
  `rollback_id` bigint(20) DEFAULT NULL,
  `rollback_status` enum('0','1') DEFAULT '0',
  `rollback_date` datetime DEFAULT NULL,
  `rollback_desc` text,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_reads`
--

CREATE TABLE `finance_reads` (
  `user_id` bigint(20) NOT NULL,
  `external_id` bigint(20) DEFAULT NULL,
  `internal_id` bigint(20) DEFAULT NULL,
  `date_read` datetime DEFAULT NULL,
  `date_active` datetime DEFAULT NULL,
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_rollback_externals`
--

CREATE TABLE `finance_rollback_externals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_rollback_internals`
--

CREATE TABLE `finance_rollback_internals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_rollback_moves`
--

CREATE TABLE `finance_rollback_moves` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_template_exports`
--

CREATE TABLE `finance_template_exports` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) NOT NULL,
  `type` varchar(300) NOT NULL,
  `size` varchar(100) NOT NULL,
  `name` varchar(200) NOT NULL,
  `filename` varchar(300) NOT NULL,
  `module` varchar(100) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_types`
--

CREATE TABLE `finance_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `money` decimal(20,0) DEFAULT '0',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `finance_vats`
--

CREATE TABLE `finance_vats` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

--
-- Table structure for table `groups`
--

CREATE TABLE `groups` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) DEFAULT NULL,
  `roles` text,
  `max_size_upload` bigint(20) unsigned NOT NULL DEFAULT '0',
  `max_memory_upload` bigint(20) unsigned DEFAULT '0',
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime NOT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8;

--
-- Table structure for table `histories`
--

CREATE TABLE `histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `module` varchar(100) DEFAULT NULL COMMENT 'WORK,CALENDAR,...',
  `object` varchar(20) DEFAULT NULL COMMENT 'Project,...',
  `object_id` bigint(20) DEFAULT NULL,
  `object1` varchar(20) DEFAULT NULL COMMENT 'Task,...',
  `object1_id` bigint(20) DEFAULT NULL,
  `object2` varchar(20) DEFAULT NULL COMMENT 'Sub_task,...',
  `object2_id` bigint(20) DEFAULT NULL,
  `action` text,
  `msg` longtext,
  `date` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `QueryIndex` (`module`,`object`,`object_id`,`object1`,`ID`) USING BTREE,
  KEY `FullQueryIndex` (`module`,`object`,`object_id`,`object1`,`object1_id`,`ID`) USING BTREE,
  KEY `EvaluationIndex` (`object2_id`,`object1`,`object2`)
) ENGINE=InnoDB AUTO_INCREMENT=4292910 DEFAULT CHARSET=utf8;

--
-- Table structure for table `holidays`
--

CREATE TABLE `holidays` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL COMMENT 'Tên ngày nghỉ',
  `from` datetime DEFAULT NULL,
  `to` datetime DEFAULT NULL,
  `repeat` enum('0','1') DEFAULT '0' COMMENT 'Có lặp lại theo năm hay không',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='Cấu hình lịch nghỉ theo lịch nhà nước';

--
-- Table structure for table `imported_histories`
--

CREATE TABLE `imported_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `module` varchar(200) DEFAULT NULL,
  `type` tinyint(4) DEFAULT '1' COMMENT '1: imported, 2: preview',
  `data` text,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `update_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2557 DEFAULT CHARSET=utf8;

--
-- Table structure for table `languages`
--

CREATE TABLE `languages` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8;

--
-- Table structure for table `locations`
--

CREATE TABLE `locations` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(150) NOT NULL,
  `type` tinyint(2) NOT NULL DEFAULT '1' COMMENT '1: country ; 2: state; 3: district',
  `parent_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`),
  KEY `type` (`type`)
) ENGINE=InnoDB AUTO_INCREMENT=1150 DEFAULT CHARSET=utf8;

--
-- Table structure for table `log_services`
--

CREATE TABLE `log_services` (
  `time` datetime NOT NULL,
  `ip` varchar(150) DEFAULT NULL,
  `desc` varchar(300) DEFAULT NULL,
  `service` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `logs`
--

CREATE TABLE `logs` (
  `date` datetime NOT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `username` varchar(150) DEFAULT NULL,
  `ip` varchar(150) DEFAULT NULL,
  `message` varchar(300) DEFAULT NULL,
  `browser` varchar(150) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `mailbox`
--

CREATE TABLE `mailbox` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `to` text,
  `from` text,
  `subject` varchar(1024) DEFAULT NULL,
  `content` text,
  `status` enum('pending','outgoing','sent','error') DEFAULT 'pending',
  `error` text,
  `created_on` datetime DEFAULT NULL,
  `modify_on` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=8119 DEFAULT CHARSET=utf8;

--
-- Table structure for table `mailbox_details`
--

CREATE TABLE `mailbox_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `mailbox_id` bigint(20) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `status` enum('sent','queued','scheduled','rejected','invalid','error','fatal') DEFAULT NULL,
  `reject_reason` varchar(512) DEFAULT NULL,
  `_id` varchar(255) DEFAULT NULL,
  `error_code` int(11) DEFAULT NULL,
  `error_name` varchar(45) DEFAULT NULL,
  `error_message` varchar(512) DEFAULT NULL,
  `created_on` datetime DEFAULT NULL,
  `modify_on` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `mailbox_id` (`mailbox_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=48704 DEFAULT CHARSET=utf8;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`tientq`@`%`*/ /*!50003 TRIGGER mailbox_details_insert BEFORE INSERT ON `mailbox_details`
FOR EACH ROW
BEGIN
	SET NEW.`created_on` = SYSDATE();
	SET NEW.`modify_on` = NULL;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`tientq`@`%`*/ /*!50003 TRIGGER mailbox_details_update BEFORE UPDATE ON `mailbox_details`
FOR EACH ROW
BEGIN
	SET NEW.`created_on` = OLD.`created_on`;
	SET NEW.`modify_on` = SYSDATE();
END */;;
DELIMITER ;

--
-- Table structure for table `merge_emails`
--

CREATE TABLE `merge_emails` (
  `title` varchar(255) NOT NULL,
  `ids` varchar(1024) NOT NULL,
  PRIMARY KEY (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `merge_phones`
--

CREATE TABLE `merge_phones` (
  `title` varchar(45) NOT NULL,
  `ids` varchar(1024) NOT NULL,
  PRIMARY KEY (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `notice_receivers`
--

CREATE TABLE `notice_receivers` (
  `notice_id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `is_read` tinyint(1) DEFAULT NULL,
  `date_read` datetime DEFAULT NULL,
  `is_view` tinyint(4) DEFAULT '0' COMMENT '''0'': chua xem , 1: dã xem',
  `date_view` datetime DEFAULT NULL,
  PRIMARY KEY (`notice_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `notices`
--

CREATE TABLE `notices` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `module` varchar(100) DEFAULT NULL COMMENT 'task,calendar,...',
  `sub_module` varchar(100) DEFAULT NULL,
  `action` varchar(100) DEFAULT NULL,
  `step` varchar(50) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `url` varchar(300) DEFAULT NULL,
  `url2` varchar(300) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `last_sender_id` bigint(20) DEFAULT NULL,
  `where` varchar(300) DEFAULT NULL,
  `msg` varchar(500) DEFAULT NULL COMMENT 'quick msg in notice box',
  `sent_mobile` tinyint(4) NOT NULL DEFAULT '0',
  `author_id` bigint(20) DEFAULT NULL,
  `pattens` varchar(1024) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `sent_mobile` (`sent_mobile`),
  KEY `date` (`date`)
) ENGINE=InnoDB AUTO_INCREMENT=580057 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_confirm_contents`
--

CREATE TABLE `perform_confirm_contents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `confirm_id` int(11) NOT NULL,
  `describe_id` int(11) DEFAULT NULL COMMENT 'describe_group_id',
  `describe_title` varchar(255) DEFAULT NULL COMMENT 'describe_group_title',
  `status` bit(1) DEFAULT NULL COMMENT '0: Không xác nh?n - 1: Xác nh?n',
  `reason` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3724 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_confirms`
--

CREATE TABLE `perform_confirms` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contract_id` int(11) DEFAULT NULL,
  `status` int(11) DEFAULT '0' COMMENT '0: Đang chờ - 1: Xác nhận - 2: Không xác nhận',
  `created` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_ip` varchar(30) DEFAULT NULL,
  `feedback` datetime DEFAULT NULL,
  `feedback_by` varchar(100) DEFAULT NULL,
  `feedback_ip` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1811 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_describe_groups`
--

CREATE TABLE `perform_describe_groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` enum('NORMAL','LATER','UPGRADE') DEFAULT 'NORMAL' COMMENT 'LATER: Triển khai sau',
  `title` varchar(255) NOT NULL,
  `has_amount` bit(1) NOT NULL DEFAULT b'0',
  `add_new` bit(1) NOT NULL DEFAULT b'0',
  `order_number` int(11) NOT NULL DEFAULT '1',
  `description` varchar(500) DEFAULT NULL,
  `confirm_title` varchar(255) DEFAULT NULL COMMENT 'Tiêu đề hiển thị trên form xác nhận bàn giao',
  `display_in_confirm` bit(1) DEFAULT b'1' COMMENT 'Có hiển thị trên form xác nhận bàn giao hay không',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_describes`
--

CREATE TABLE `perform_describes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `group_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `amount` int(11) NOT NULL DEFAULT '0',
  `order_number` int(11) DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_logs`
--

CREATE TABLE `perform_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `require_id` int(11) NOT NULL,
  `action` varchar(255) NOT NULL,
  `message` varchar(255) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` varchar(100) NOT NULL,
  `created_ip` varchar(30) NOT NULL,
  `source_type` char(1) NOT NULL DEFAULT 'S' COMMENT 'S: staff, C: customer',
  PRIMARY KEY (`id`),
  KEY `IDX_perform_logs_require_id` (`require_id`)
) ENGINE=InnoDB AUTO_INCREMENT=30497 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_no_requires`
--

CREATE TABLE `perform_no_requires` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contract_id` int(11) NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `reason` varchar(500) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `approved` datetime DEFAULT NULL,
  `approved_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_reports`
--

CREATE TABLE `perform_reports` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contract_id` int(11) NOT NULL,
  `type` enum('LATER','NORMAL','UPGRADE') DEFAULT NULL COMMENT 'LATER: Triển khai sau, NORMAL: triển khai thường',
  `require_date` datetime DEFAULT NULL,
  `confirm_date` datetime DEFAULT NULL,
  `require_status` int(11) DEFAULT '-1' COMMENT '-1: Chưa triển khai; 0: Đang triển khai; 1: Triển khai đúng hạn; 2: Triển khai chậm; 3: Triển khai sau',
  `confirm_status` int(11) DEFAULT '-1' COMMENT '-1: Chưa bàn giao; 0: Chờ xử lý; 1: Đã bàn giao; 2: Không xác nhận',
  `service_rating` float DEFAULT '-1',
  `support_rating` float DEFAULT '-1',
  `comment` varchar(500) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=19338 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_require_details`
--

CREATE TABLE `perform_require_details` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `require_id` int(11) NOT NULL,
  `describe_group_id` int(11) DEFAULT NULL,
  `contract_id` int(11) NOT NULL,
  `describe_id` int(11) NOT NULL DEFAULT '0' COMMENT 'Các đầu mục trong form (-1 mục thêm mới)',
  `describe_title` varchar(255) NOT NULL COMMENT 'Tên các mục',
  `amount` int(11) NOT NULL DEFAULT '0' COMMENT 'Số lượng (không có = 0)',
  `description` varchar(2000) DEFAULT NULL,
  `file_id` int(11) DEFAULT '-1',
  `attached_file` varchar(255) DEFAULT NULL,
  `status` bit(1) NOT NULL COMMENT '0: Không đồng ý - 1: Đồng ý',
  `feedback` varchar(2000) DEFAULT NULL COMMENT 'Ý kiến khách hàng',
  `feedback_file` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=46296 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_requires`
--

CREATE TABLE `perform_requires` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` enum('NORMAL','LATER','UPGRADE') DEFAULT 'NORMAL' COMMENT 'LATER: Triển khai sau; UPGRADE: Nâng cấp',
  `contract_id` int(11) NOT NULL COMMENT 'Hợp đồng',
  `website` varchar(255) NOT NULL COMMENT 'Tên miền sử dụng',
  `template_id` varchar(50) DEFAULT NULL COMMENT 'Giao diện sử dụng',
  `status` int(11) DEFAULT '0' COMMENT '0: Đang chờ - 1: Xác nhận - 2: Không xác nhận - 3: Bản nháp',
  `require_no` int(11) DEFAULT NULL,
  `deploy_date` datetime DEFAULT NULL COMMENT 'Ngày hẹn triển khai sau',
  `created` datetime DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `modified_by` int(11) DEFAULT NULL,
  `feedback` datetime DEFAULT NULL,
  `feedback_by` varchar(100) DEFAULT NULL,
  `feedback_ip` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `Idx_contract_id` (`contract_id`),
  KEY `Idx_status` (`status`),
  KEY `Idx_type` (`type`),
  KEY `Idx_require_no` (`require_no`),
  KEY `Idx_created` (`created`),
  FULLTEXT KEY `Idx_feedbak_by` (`feedback_by`)
) ENGINE=InnoDB AUTO_INCREMENT=3635 DEFAULT CHARSET=utf8;

--
-- Table structure for table `perform_reviews`
--

CREATE TABLE `perform_reviews` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contract_id` int(11) DEFAULT NULL,
  `service_rating` float DEFAULT '0',
  `support_rating` float DEFAULT '0',
  `comment` varchar(500) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `created_by` varchar(100) DEFAULT NULL,
  `ip_address` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=666 DEFAULT CHARSET=utf8 COMMENT='Thông tin đánh giá của khách hàng';

--
-- Table structure for table `personnel_application_ccmail_settings`
--

CREATE TABLE `personnel_application_ccmail_settings` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_army_positions`
--

CREATE TABLE `personnel_army_positions` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_attendance_checkdates`
--

CREATE TABLE `personnel_attendance_checkdates` (
  `personnel_code` varchar(50) NOT NULL,
  `date` date NOT NULL,
  `real_time_start` time DEFAULT NULL,
  `real_time_end` time DEFAULT NULL,
  `time_start` time DEFAULT NULL,
  `time_end` time DEFAULT NULL,
  PRIMARY KEY (`personnel_code`,`date`),
  KEY `personnel_code` (`personnel_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_attendance_checktimes`
--

CREATE TABLE `personnel_attendance_checktimes` (
  `personnel_code` varchar(50) NOT NULL,
  `time` datetime NOT NULL,
  `type` enum('I','O','M','N') NOT NULL DEFAULT 'N',
  KEY `personnel_code` (`personnel_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_attendance_setting`
--

CREATE TABLE `personnel_attendance_setting` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `type` enum('see','seeall','edit','editall') NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_blood_groups`
--

CREATE TABLE `personnel_blood_groups` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_comment_files`
--

CREATE TABLE `personnel_candidate_comment_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `comment_id` bigint(20) NOT NULL,
  `name` varchar(500) DEFAULT NULL,
  `filename` varchar(500) DEFAULT NULL,
  `type` varchar(300) DEFAULT NULL,
  `size` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_comments`
--

CREATE TABLE `personnel_candidate_comments` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `post_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `content` text,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_in_interviews`
--

CREATE TABLE `personnel_candidate_in_interviews` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `interview_id` bigint(20) unsigned NOT NULL COMMENT 'id cua lich phong van',
  `candidate_id` bigint(20) DEFAULT NULL COMMENT 'ID của ngươi được pv',
  `recruiment_id` bigint(20) DEFAULT NULL COMMENT 'ID của yêu cầu tuyển dụng',
  `hour_interview` time DEFAULT NULL COMMENT 'giờ pv',
  `date_interview` date DEFAULT NULL COMMENT 'Ngày pv',
  `status` tinyint(2) DEFAULT '0' COMMENT '0: chưa phỏng vấn, 1: Đã phỏng vấn, 2: Không đến',
  `comment` varchar(500) DEFAULT NULL COMMENT 'Nhận xét',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='Nhung user tham gia phong van';

--
-- Table structure for table `personnel_candidate_interviews`
--

CREATE TABLE `personnel_candidate_interviews` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(250) DEFAULT NULL,
  `recruiment_id` bigint(20) unsigned NOT NULL COMMENT 'id của yêu cầu tuyển dụng',
  `user_ids` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `status` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_label_users`
--

CREATE TABLE `personnel_candidate_label_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(300) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_labels`
--

CREATE TABLE `personnel_candidate_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `label_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_users`
--

CREATE TABLE `personnel_candidate_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `candidate_id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `is_guest` enum('yes','no') NOT NULL DEFAULT 'no',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidate_users_interviews`
--

CREATE TABLE `personnel_candidate_users_interviews` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) unsigned NOT NULL COMMENT 'Người pv',
  `interview_id` bigint(20) DEFAULT NULL COMMENT 'Mã lịch pv',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_candidates`
--

CREATE TABLE `personnel_candidates` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(100) NOT NULL,
  `photo` varchar(55) DEFAULT NULL,
  `title` varchar(250) NOT NULL,
  `recruiment_id` int(11) DEFAULT NULL,
  `origin_id` int(11) DEFAULT NULL,
  `work_place` int(20) DEFAULT NULL,
  `place_of_birth` int(11) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `birthday` varchar(100) DEFAULT NULL,
  `private_code` varchar(20) DEFAULT NULL,
  `private_code_date` date DEFAULT NULL,
  `private_code_place` int(11) DEFAULT NULL,
  `train_year` varchar(150) DEFAULT NULL,
  `train_degree` int(11) DEFAULT NULL,
  `train_place` int(11) DEFAULT NULL,
  `place` int(100) DEFAULT NULL,
  `gender` enum('0','1','2') DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date_interview` date DEFAULT NULL,
  `working_day` date DEFAULT NULL,
  `strengths` varchar(500) DEFAULT NULL,
  `weaknesses` varchar(500) DEFAULT NULL,
  `favorite` varchar(500) DEFAULT NULL,
  `rules` varchar(500) DEFAULT NULL,
  `contract_req` text,
  `train_level` int(11) DEFAULT NULL,
  `contact_person` varchar(150) NOT NULL,
  `email` varchar(255) NOT NULL,
  `phone` varchar(30) DEFAULT NULL,
  `facebook` varchar(50) DEFAULT NULL,
  `home_address` varchar(250) DEFAULT NULL,
  `current_address` varchar(250) DEFAULT NULL,
  `train_institutions` int(11) DEFAULT NULL,
  `train_discripline` int(11) DEFAULT NULL,
  `charge_id` bigint(20) DEFAULT NULL,
  `charge_type` enum('-1','0','1','2','5','4','3') DEFAULT NULL COMMENT '-1: bị loại, 0 chưa xác nhận, 1: Cho thi, 2: Cho phỏng vấn',
  `charge_status` enum('1','0') DEFAULT '0',
  `comment_charge` text,
  `date_charge` datetime DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `added` enum('1','0') DEFAULT '0',
  `add_id` bigint(20) DEFAULT NULL,
  `date_approved` datetime DEFAULT NULL,
  `status` enum('W','A','C') NOT NULL DEFAULT 'W',
  `comment` text,
  `is_train` int(11) DEFAULT '0',
  `train_type` bigint(20) DEFAULT NULL,
  `train_status` enum('C','W') DEFAULT NULL,
  `train_result` bigint(20) DEFAULT NULL,
  `fast_contact_name` varchar(250) DEFAULT NULL,
  `fast_contact_relation` int(11) DEFAULT NULL,
  `fast_contact_phone` varchar(250) DEFAULT NULL,
  `fast_contact_address` varchar(250) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contact_relations`
--

CREATE TABLE `personnel_contact_relations` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_appendix`
--

CREATE TABLE `personnel_contract_appendix` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(100) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `position_id` bigint(20) DEFAULT NULL,
  `job_title` bigint(20) DEFAULT NULL,
  `serial` int(11) DEFAULT NULL,
  `appendix_type` enum('TRIAL_WORK_FIRST_MONTH','END_CONTRACT') DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=177 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_deadlines`
--

CREATE TABLE `personnel_contract_deadlines` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_files`
--

CREATE TABLE `personnel_contract_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(300) DEFAULT NULL,
  `filename` varchar(300) DEFAULT NULL,
  `size` varchar(200) DEFAULT NULL,
  `type` varchar(200) DEFAULT NULL,
  `post_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_label_users`
--

CREATE TABLE `personnel_contract_label_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(300) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_labels`
--

CREATE TABLE `personnel_contract_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) NOT NULL,
  `label_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_status`
--

CREATE TABLE `personnel_contract_status` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_times`
--

CREATE TABLE `personnel_contract_times` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `time` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_training_users`
--

CREATE TABLE `personnel_contract_training_users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `post_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_trainings`
--

CREATE TABLE `personnel_contract_trainings` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `place` varchar(500) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_types`
--

CREATE TABLE `personnel_contract_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(300) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `month` int(11) DEFAULT NULL,
  `ord` int(20) DEFAULT NULL,
  `has_insurance` enum('N','Y') DEFAULT NULL,
  `leave` enum('Y','N') DEFAULT NULL,
  `first_month_warning` enum('N','Y') DEFAULT 'N',
  `has_first_month_appendix` enum('Y','N') DEFAULT NULL,
  `template_mail_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contract_works`
--

CREATE TABLE `personnel_contract_works` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(250) DEFAULT NULL,
  `title` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_contracts`
--

CREATE TABLE `personnel_contracts` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `code` varchar(150) DEFAULT NULL,
  `type` int(20) DEFAULT NULL,
  `work_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date_reg` date DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_finish` date DEFAULT NULL,
  `deadline` int(11) DEFAULT NULL,
  `work_type` int(11) DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `position_id` int(11) DEFAULT NULL,
  `salary` decimal(10,0) DEFAULT NULL,
  `salary_premium_id` int(11) DEFAULT NULL,
  `salary_premium` decimal(10,0) DEFAULT NULL,
  `salary_method` int(11) DEFAULT NULL,
  `salary_allowances` decimal(10,0) DEFAULT NULL,
  `insurance_social_percent_company` int(11) DEFAULT NULL,
  `insurance_social_percent_person` int(11) DEFAULT NULL,
  `insurance_health_percent_company` int(11) DEFAULT NULL,
  `insurance_health_percent_person` int(11) DEFAULT NULL,
  `insurance_unemployment_percent_company` int(11) DEFAULT NULL,
  `insurance_unemployment_percent_person` int(11) DEFAULT NULL,
  `representative_id` bigint(20) DEFAULT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `insurance_f2_percent` float DEFAULT '30',
  `insurance_f2_person` float DEFAULT '10',
  `insurance_f2_company` float DEFAULT '10',
  `insurance_f3_percent` float DEFAULT '20',
  `insurance_f3_person` float DEFAULT '10',
  `insurance_f3_company` float DEFAULT '10',
  `insurance_f4_percent` float DEFAULT '15',
  `insurance_f4_person` float DEFAULT '10',
  `insurance_f4_company` float DEFAULT '10',
  `insurance_f7_percent` float DEFAULT '2',
  `insurance_f7_person` float DEFAULT '0',
  `insurance_f7_company` float DEFAULT '2',
  `status` enum('EFFECT','LIQUIDATION') DEFAULT 'EFFECT',
  `code_liquidation` varchar(150) DEFAULT NULL,
  `date_liquidation` datetime DEFAULT NULL,
  `desc_liquidation` varchar(500) DEFAULT NULL,
  `is_notice_end` enum('0','1') DEFAULT '0',
  `is_notice_first_month` enum('0','1') DEFAULT '0',
  `date_end_appendix` date DEFAULT NULL,
  `date_end_contract` date DEFAULT NULL,
  `contract_status` int(11) DEFAULT '2',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2619 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_degree_posts`
--

CREATE TABLE `personnel_degree_posts` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date_from` date DEFAULT NULL,
  `date_to` date DEFAULT NULL,
  `level_id` int(11) DEFAULT NULL,
  `place` varchar(600) DEFAULT NULL,
  `specialization_id` int(11) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6575 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_degrees`
--

CREATE TABLE `personnel_degrees` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_earlys`
--

CREATE TABLE `personnel_earlys` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `money` decimal(7,0) NOT NULL,
  `workday` float DEFAULT NULL,
  `time` time DEFAULT NULL,
  `days` varchar(50) DEFAULT NULL,
  `is_report` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_backs`
--

CREATE TABLE `personnel_evaluation_backs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `cottar_id` bigint(20) DEFAULT NULL,
  `user_ids` varchar(20) DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL,
  `deadline` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `evaluation_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=149 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_cottars`
--

CREATE TABLE `personnel_evaluation_cottars` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `evaluation_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `cottar_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_cottars_eval`
--

CREATE TABLE `personnel_evaluation_cottars_eval` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `evaluation_id` bigint(20) DEFAULT NULL,
  `group_id` bigint(11) DEFAULT NULL,
  `user_id` bigint(11) DEFAULT NULL,
  `content` text,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `cottar_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_details`
--

CREATE TABLE `personnel_evaluation_details` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `evaluation_id` int(11) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `percent` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=978 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_groups`
--

CREATE TABLE `personnel_evaluation_groups` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `desc` text,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_mark_properties`
--

CREATE TABLE `personnel_evaluation_mark_properties` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `mark_id` int(11) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `percent` int(11) DEFAULT NULL,
  `mark` varchar(100) DEFAULT NULL,
  `desc` text,
  PRIMARY KEY (`ID`),
  KEY `mark_id` (`mark_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=238950 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_marks`
--

CREATE TABLE `personnel_evaluation_marks` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `group_id` bigint(11) DEFAULT NULL,
  `evaluation_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(11) DEFAULT NULL,
  `total_point` decimal(20,5) DEFAULT NULL,
  `action` enum('COTTAR','OWNER','MANAGER','USER') DEFAULT NULL,
  `action_user_id` bigint(20) DEFAULT NULL,
  `desc` text,
  `status` enum('1','0') DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `manager_id` bigint(20) DEFAULT NULL,
  `owner_id` bigint(20) DEFAULT NULL,
  `root_id` bigint(20) DEFAULT NULL,
  `is_back` enum('0','1') DEFAULT '0',
  `deadline_back` datetime DEFAULT NULL,
  `manager_ids` text,
  `owner_ids` text,
  `feedback_date` datetime DEFAULT NULL,
  `feedback_comment` varchar(500) DEFAULT NULL,
  `minus_id` int(11) DEFAULT NULL,
  `minus_point` float DEFAULT NULL,
  `minus_desc` text,
  PRIMARY KEY (`ID`),
  KEY `evaluation_id` (`evaluation_id`) USING BTREE,
  KEY `user_id` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3504 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_members`
--

CREATE TABLE `personnel_evaluation_members` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `group_id` bigint(20) DEFAULT NULL,
  `evaluation_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `owner_ids` text COLLATE utf8_unicode_ci,
  `manager_ids` text COLLATE utf8_unicode_ci,
  `user_point` decimal(20,5) DEFAULT NULL,
  `manager_point` decimal(20,5) DEFAULT NULL,
  `owner_point` decimal(20,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2290 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Table structure for table `personnel_evaluation_minus`
--

CREATE TABLE `personnel_evaluation_minus` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `period` int(11) DEFAULT '0',
  `symbol_id` int(11) DEFAULT NULL,
  `minus_point` float DEFAULT '0',
  `desc` text,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_scales`
--

CREATE TABLE `personnel_evaluation_scales` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `value` text NOT NULL,
  `is_active` bit(1) DEFAULT b'1',
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_types`
--

CREATE TABLE `personnel_evaluation_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `type` enum('0','1') NOT NULL DEFAULT '0',
  `unit` enum('1','2','3') NOT NULL DEFAULT '1',
  `type_unit` int(11) DEFAULT NULL,
  `desc` text,
  `reason` varchar(500) DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT '0',
  `group_id` bigint(20) DEFAULT NULL,
  `scale` bigint(20) DEFAULT '0',
  `id_before_copy` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=609 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluation_units`
--

CREATE TABLE `personnel_evaluation_units` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `units` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_evaluations`
--

CREATE TABLE `personnel_evaluations` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `group_id` int(11) DEFAULT NULL,
  `deadline_user` date DEFAULT NULL,
  `deadline_manager` date DEFAULT NULL,
  `deadline_owner` date DEFAULT NULL,
  `type` enum('0','1') DEFAULT '0',
  `cottar_ids` text,
  `user_ids` text,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `manager_ids` text,
  `owner_ids` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_files`
--

CREATE TABLE `personnel_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(300) DEFAULT NULL,
  `filename` varchar(300) DEFAULT NULL,
  `size` varchar(200) DEFAULT NULL,
  `type` varchar(200) DEFAULT NULL,
  `personnel_id` bigint(20) NOT NULL,
  `comment_id` bigint(20) DEFAULT NULL,
  `training_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_gov_positions`
--

CREATE TABLE `personnel_gov_positions` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(40) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_holiday_abnormals`
--

CREATE TABLE `personnel_holiday_abnormals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `date2` varchar(8) DEFAULT NULL COMMENT 'Định dạng năm tháng ngày hoặc tháng ngày cho ngày nghỉ lặp hàng năm',
  `repeat` tinyint(1) NOT NULL DEFAULT '0',
  `type` tinyint(1) DEFAULT '0',
  `has_salary` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER personnel_holiday_abnormals_before_insert
BEFORE INSERT
ON personnel_holiday_abnormals
FOR EACH ROW
BEGIN
  IF (NEW.`repeat` = FALSE) THEN
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%Y%m%d');
  ELSE
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%m%d');
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER personnel_holiday_abnormals_before_update
BEFORE UPDATE
ON personnel_holiday_abnormals
FOR EACH ROW
BEGIN
  IF (NEW.`repeat` = FALSE) THEN
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%Y%m%d');
  ELSE
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%m%d');
  END IF;
END */;;
DELIMITER ;

--
-- Table structure for table `personnel_holidays`
--

CREATE TABLE `personnel_holidays` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `date2` varchar(8) DEFAULT NULL COMMENT 'Định dạng năm tháng ngày hoặc tháng ngày cho ngày nghỉ lặp hàng năm',
  `repeat` tinyint(1) NOT NULL DEFAULT '0',
  `type` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER personnel_holidays_before_insert
BEFORE INSERT
ON personnel_holidays
FOR EACH ROW
BEGIN
  IF (NEW.`repeat` = FALSE) THEN
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%Y%m%d');
  ELSE
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%m%d');
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER personnel_holidays_before_update
BEFORE UPDATE
ON personnel_holidays
FOR EACH ROW
BEGIN
  IF (NEW.`repeat` = FALSE) THEN
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%Y%m%d');
  ELSE
    SET NEW.date2 = DATE_FORMAT(NEW.date, '%m%d');
  END IF;
END */;;
DELIMITER ;

--
-- Table structure for table `personnel_incomes`
--

CREATE TABLE `personnel_incomes` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) DEFAULT NULL,
  `money_type` enum('0','1','2') DEFAULT '0' COMMENT '0: chi cho nhân viên, 1: nv dc nhận, 2: nv bị thu ',
  `money` decimal(20,5) DEFAULT NULL,
  `type` varchar(20) DEFAULT NULL,
  `type_id` bigint(20) DEFAULT NULL,
  `status` enum('0','1') DEFAULT '0' COMMENT '0: chưa xác nhận, 1: đã xác nhận',
  `desc` varchar(300) DEFAULT NULL,
  `datetime` datetime DEFAULT NULL COMMENT 'ngày xảy ra',
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_institutions`
--

CREATE TABLE `personnel_institutions` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_insurance_label_users`
--

CREATE TABLE `personnel_insurance_label_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(150) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_insurance_labels`
--

CREATE TABLE `personnel_insurance_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) NOT NULL,
  `label_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=85 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_insurance_type_groups`
--

CREATE TABLE `personnel_insurance_type_groups` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `money` decimal(20,3) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_insurance_types`
--

CREATE TABLE `personnel_insurance_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `type` enum('LABOUR','UNEMPLOYMENT','HEALTH','SOCIAL') DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `percent_person` float DEFAULT NULL,
  `percent_company` float DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_interview_feedbacks`
--

CREATE TABLE `personnel_interview_feedbacks` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `interview_id` bigint(20) DEFAULT NULL,
  `candidate_id` bigint(20) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_job_histories`
--

CREATE TABLE `personnel_job_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date_from` datetime DEFAULT NULL,
  `date_to` datetime DEFAULT NULL,
  `job_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6269 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_job_titles`
--

CREATE TABLE `personnel_job_titles` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_jobleave_cc_users`
--

CREATE TABLE `personnel_jobleave_cc_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `Post_Id_Index` (`post_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=288 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_jobleave_reasons`
--

CREATE TABLE `personnel_jobleave_reasons` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_labels`
--

CREATE TABLE `personnel_labels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `label` varchar(300) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_lates`
--

CREATE TABLE `personnel_lates` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `money` decimal(20,5) DEFAULT NULL,
  `workday` float DEFAULT NULL,
  `time` time DEFAULT NULL,
  `days` varchar(50) DEFAULT NULL,
  `is_report` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_application_charge`
--

CREATE TABLE `personnel_leave_application_charge` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `leave_application_id` bigint(20) DEFAULT NULL,
  `charge_id` bigint(20) DEFAULT NULL,
  `desc` text CHARACTER SET utf8 COLLATE utf8_bin,
  `status` enum('0','1') CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_confirm` datetime DEFAULT NULL,
  `note` text CHARACTER SET utf8 COLLATE utf8_bin,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=974 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_applications`
--

CREATE TABLE `personnel_leave_applications` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `charge` bigint(20) NOT NULL,
  `charge_two` bigint(20) NOT NULL,
  `reason` bigint(20) NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  `department_id` bigint(20) NOT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `approver_id` bigint(20) NOT NULL,
  `date_approved` datetime DEFAULT NULL,
  `status` enum('0','1','2') NOT NULL DEFAULT '0',
  `desc` text NOT NULL,
  `department_head_id_old` bigint(20) DEFAULT NULL,
  `department_head_id_new` bigint(20) DEFAULT NULL,
  `status_decide` bigint(20) DEFAULT '-1',
  `status_approved_new` bigint(20) DEFAULT NULL,
  `status_approved_old` bigint(20) DEFAULT NULL,
  `comment` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `status_account` enum('1','0') DEFAULT '0',
  `status_email` enum('0','1') DEFAULT '0',
  `status_charge` enum('1','0') DEFAULT '0',
  `status_asset` enum('1','0') DEFAULT '0',
  `status_insurance_key` enum('1','0') DEFAULT '0',
  `status_insurance_pay` enum('0','1') DEFAULT '0',
  `status_mortgage` enum('0','1') DEFAULT '0',
  `status_insurance_health` enum('0','1') DEFAULT '0',
  `status_ledger` enum('0','1') DEFAULT '0',
  `status_staff_card` enum('0','1') DEFAULT '0',
  `status_asset_sign` enum('0','1') DEFAULT '0',
  `status_reseller_account` enum('0','1') DEFAULT '0',
  `status_salary_pay` enum('0','1') DEFAULT '0',
  `status_salary_sign` enum('0','1') DEFAULT '0',
  `status_salary_note` varchar(500) DEFAULT NULL,
  `user_id_decide` bigint(20) DEFAULT NULL,
  `comment_decide` varchar(500) DEFAULT NULL,
  `date_decide` datetime DEFAULT NULL,
  `type` varchar(100) NOT NULL DEFAULT 'Leaveapplication',
  `action_history` text,
  `send_confirm_status` enum('0','1') DEFAULT '0',
  `charge_note` text,
  `charge_status` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=721 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_approver_fixeds`
--

CREATE TABLE `personnel_leave_approver_fixeds` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `job_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_approvers`
--

CREATE TABLE `personnel_leave_approvers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `ord` tinyint(4) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `desc` varchar(300) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10808 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_cc_users`
--

CREATE TABLE `personnel_leave_cc_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `post_id` (`post_id`,`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=7742 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_checks`
--

CREATE TABLE `personnel_leave_checks` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) NOT NULL,
  `status_decide` bigint(20) DEFAULT NULL,
  `status_account` enum('1','0') NOT NULL DEFAULT '0',
  `status_email` enum('0','1') NOT NULL DEFAULT '0',
  `status_charge` enum('1','0') NOT NULL DEFAULT '0',
  `status_asset` enum('1','0') NOT NULL DEFAULT '0',
  `status_insurance_key` enum('1','0') NOT NULL DEFAULT '0',
  `status_insurance_pay` enum('0','1') NOT NULL DEFAULT '0',
  `status_mortgage` enum('0','1') NOT NULL DEFAULT '0',
  `status_insurance_health` enum('0','1') DEFAULT '0',
  `status_ledger` enum('0','1') DEFAULT '0',
  `status_staff_card` enum('0','1') DEFAULT '0',
  `status_asset_sign` enum('0','1') DEFAULT '0',
  `status_reseller_account` enum('0','1') DEFAULT '0',
  `status_salary_pay` enum('0','1') DEFAULT '0',
  `status_salary_sign` enum('0','1') DEFAULT '0',
  `status_salary_note` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `Personnel_Id_Index` (`personnel_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1773 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_comments`
--

CREATE TABLE `personnel_leave_comments` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `post_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `content` text,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `post_id` (`post_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_setting_approvers`
--

CREATE TABLE `personnel_leave_setting_approvers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `symbol_id` int(4) DEFAULT NULL,
  `day` float DEFAULT NULL,
  `number_person` int(11) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=225 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_setting_cc_users`
--

CREATE TABLE `personnel_leave_setting_cc_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `Post_Id_Index` (`post_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=169 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_setting_limits`
--

CREATE TABLE `personnel_leave_setting_limits` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `month_id` int(11) DEFAULT NULL,
  `number` float DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=108 DEFAULT CHARSET=utf8;

--
-- Table structure for table `personnel_leave_types`
--

CREATE TABLE `personnel_leave_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `sign` varchar(10) DEFAULT NULL,
  `max_day` int(11) DEFAULT NULL,
  `has_salary` enum('0','1') DEFAULT '0',
  `has_premium` enum('0','1') DEFAULT '1',
  `salary_percent` float DEFAULT NULL,
  `type_day` enum('YEAR','MONTH') DEFAULT 'YEAR',
  `is_cal` enum('0','1') DEFAULT '0',
  `is_add` enum('0','1') DEFAULT '0' COMMENT 'Có tính thêm ngày nghỉ hay ko',
  `is_addoff` enum('0','1') DEFAULT '0',
  `type` int(11) DEFAULT NULL COMMENT 'Loại ngày công',
  `is_limit` enum('0','1') DEFAULT '0',
  `desc` varchar(500) DEFAULT NULL,
  `limit_day` float DEFAULT NULL,
  `limit_type` enum('1','2') DEFAULT '1',
  `default_days` int(11) DEFAULT '1',
  `default_unit` varchar(10) DEFAULT 'DAY',
  `confirm_ids` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;

--
