--
-- Host: 10.10.2.35    Database: 10.10.2.35
-- ------------------------------------------------------


--
-- Table structure for table `accounting_account_money_contracts`
--

CREATE TABLE `accounting_account_money_contracts` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `year` int(11) DEFAULT NULL COMMENT 'Số dư đầu kỳ của năm',
  `money` decimal(20,5) DEFAULT NULL,
  `is_account` enum('1','2') DEFAULT '1' COMMENT '1:Tk nợ, 2: Tk có',
  `is_created` enum('0','1') DEFAULT '0' COMMENT '0: Tạo tự động; 1:Tạo thủ công',
  `is_contract` enum('0','1') DEFAULT '1',
  `contract_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Số dư đầu kì';

--
-- Table structure for table `accounting_account_money_customers`
--

CREATE TABLE `accounting_account_money_customers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `year` int(11) DEFAULT NULL COMMENT 'Số dư đầu kỳ của năm',
  `money` decimal(20,5) DEFAULT NULL,
  `is_account` enum('1','2') DEFAULT '1' COMMENT '1:Tk nợ, 2: Tk có',
  `is_created` enum('0','1') DEFAULT '0' COMMENT '0: Tạo tự động; 1:Tạo thủ công',
  `customer_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Số dư đầu kì';

--
-- Table structure for table `accounting_account_money_goods`
--

CREATE TABLE `accounting_account_money_goods` (
  `ID` int(11) NOT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `year` int(11) DEFAULT NULL COMMENT 'Số dư đầu kỳ của năm',
  `amount` float DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `is_account` enum('1','2') DEFAULT '1' COMMENT '1:Tk nợ, 2: Tk có',
  `is_created` enum('0','1') DEFAULT '0' COMMENT '0: Tạo tự động; 1:Tạo thủ công',
  `goods_id` bigint(20) DEFAULT NULL,
  `warehouse_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
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Số dư đầu kì';

--
-- Table structure for table `accounting_account_moneys`
--

CREATE TABLE `accounting_account_moneys` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `year` int(11) DEFAULT NULL COMMENT 'Số dư đầu kỳ của năm',
  `money` decimal(20,5) DEFAULT NULL,
  `money_debt` decimal(20,5) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `is_account` enum('1','2','3') DEFAULT '1' COMMENT '1:Tk nợ, 2: Tk có, 3: Trung gian(khách hàng,hàng hóa)',
  `is_created` enum('0','1') DEFAULT '0' COMMENT '0: Tạo tự động; 1:Tạo thủ công',
  `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 COMMENT='Số dư đầu kì';

--
-- Table structure for table `accounting_account_types`
--

CREATE TABLE `accounting_account_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `parent_code` varchar(200) DEFAULT NULL,
  `debt` enum('0','1') DEFAULT '0',
  `had` enum('0','1') DEFAULT '0',
  `liability` enum('0','1') DEFAULT '0',
  `ledger` enum('0','1') DEFAULT '0',
  `detail` enum('0','1') DEFAULT '0',
  `parent_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_advances_employees`
--

CREATE TABLE `accounting_advances_employees` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `in_money` decimal(20,5) DEFAULT NULL,
  `ex_money` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Tiền lương ứng và trả';

--
-- Table structure for table `accounting_asset_adjustments`
--

CREATE TABLE `accounting_asset_adjustments` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `type` enum('PRICE','TIME','METHOD') DEFAULT 'PRICE' COMMENT 'Điều chỉnh nguyên giá và giá trị khấu hao - Điều chỉnh thời gian khấu hao - Điều chỉnh phương pháp tính khấu hao',
  `purchase_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT '0.00000',
  `money_new` decimal(20,5) DEFAULT NULL,
  `time_type` enum('ASC','DESC') DEFAULT 'ASC',
  `time_number` float DEFAULT NULL,
  `month` int(11) DEFAULT NULL,
  `month_new` int(11) DEFAULT NULL,
  `method` enum('1','2') DEFAULT '1' COMMENT '1: khấu hao theo đường thẳng, 2: khâu hao theo số dư giảm dần',
  `method_new` enum('1','2') DEFAULT '1',
  `status` enum('0','1') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_date` datetime DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `desc` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_asset_decreases`
--

CREATE TABLE `accounting_asset_decreases` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `type` enum('0','1') DEFAULT '0',
  `invoice_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT '0.00000',
  `money_end` decimal(20,5) DEFAULT NULL COMMENT 'Số tiền còn lại khi làm phiếu ghi giảm',
  `money_origin` decimal(20,5) DEFAULT NULL,
  `asset_title` varchar(200) DEFAULT NULL,
  `asset_code` varchar(100) DEFAULT NULL,
  `asset_reduction` float DEFAULT NULL,
  `status` enum('0','1') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_date` datetime DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `desc` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_asset_request_approvers`
--

CREATE TABLE `accounting_asset_request_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  `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=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_asset_request_destructions`
--

CREATE TABLE `accounting_asset_request_destructions` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_date` datetime DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `reason` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_asset_request_keepings`
--

CREATE TABLE `accounting_asset_request_keepings` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_date` datetime DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `type` enum('DEPART','PRIVATE') DEFAULT 'DEPART',
  `user_id` bigint(20) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `asset_title` varchar(200) DEFAULT NULL,
  `model` varchar(500) DEFAULT NULL,
  `maker` varchar(500) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `reason` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_asset_request_liquidations`
--

CREATE TABLE `accounting_asset_request_liquidations` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_date` datetime DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `reason` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_asset_request_repairs`
--

CREATE TABLE `accounting_asset_request_repairs` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_date` datetime DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `type` enum('REPAIR','FIX') DEFAULT 'REPAIR',
  `date_fix_from` datetime DEFAULT NULL,
  `date_fix_to` datetime DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `money_plan` decimal(20,5) DEFAULT NULL,
  `reason` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_exchanges`
--

CREATE TABLE `accounting_bank_exchanges` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_external_bill_drafts`
--

CREATE TABLE `accounting_bank_external_bill_drafts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `purchase_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money_theory` decimal(20,5) DEFAULT NULL,
  `money_theory_fact` decimal(20,5) DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_external_bills`
--

CREATE TABLE `accounting_bank_external_bills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `purchase_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money_theory` decimal(20,5) DEFAULT NULL,
  `money_theory_fact` decimal(20,5) DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_external_drafts`
--

CREATE TABLE `accounting_bank_external_drafts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `is_customer` enum('0','1') DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` varchar(200) DEFAULT NULL,
  `personnel_address` varchar(600) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `is_bill` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `total_money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_bank_external_nobills`
--

CREATE TABLE `accounting_bank_external_nobills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `money_change` decimal(20,5) DEFAULT NULL,
  `type_other` enum('PERSON','CUSTOMER','OTHER') DEFAULT 'OTHER',
  `personnel_id` bigint(20) DEFAULT NULL,
  `type` enum('LOAN','SALE','DEBT','OTHER') DEFAULT 'LOAN' COMMENT 'Vay vốn, mua hàng, nợ, khác',
  `contract_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `contract_money` decimal(20,5) DEFAULT NULL,
  `contract_money_had` decimal(20,5) DEFAULT NULL,
  `contract_money_debt` decimal(20,5) DEFAULT NULL,
  `inventory_id` bigint(20) DEFAULT NULL,
  `inventory_money` decimal(20,5) DEFAULT NULL,
  `inventory_money_used` decimal(20,5) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_bank_externals`
--

CREATE TABLE `accounting_bank_externals` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `is_customer` enum('0','1') DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` varchar(200) DEFAULT NULL,
  `personnel_address` varchar(600) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `is_bill` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `total_money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `finance_tc` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_internal_bill_drafts`
--

CREATE TABLE `accounting_bank_internal_bill_drafts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `purchase_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money_theory` decimal(20,5) DEFAULT NULL,
  `money_theory_fact` decimal(20,5) DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_internal_bills`
--

CREATE TABLE `accounting_bank_internal_bills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `invoice_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money_theory` decimal(20,5) DEFAULT NULL,
  `money_theory_fact` decimal(20,5) DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_internal_drafts`
--

CREATE TABLE `accounting_bank_internal_drafts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `is_customer` enum('0','1') DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` varchar(200) DEFAULT NULL,
  `personnel_address` varchar(600) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `is_bill` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `total_money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_bank_internal_nobills`
--

CREATE TABLE `accounting_bank_internal_nobills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `money_change` decimal(20,5) DEFAULT NULL,
  `type_other` enum('PERSON','CUSTOMER','OTHER') DEFAULT 'OTHER',
  `personnel_id` bigint(20) DEFAULT NULL,
  `type` enum('LOAN','SALE','DEBT','OTHER') DEFAULT 'LOAN' COMMENT 'Vay vốn, bán hàng, nợ, khác',
  `contract_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `contract_money` decimal(20,5) DEFAULT NULL,
  `contract_money_had` decimal(20,5) DEFAULT NULL,
  `contract_money_debt` decimal(20,5) DEFAULT NULL,
  `inventory_id` bigint(20) DEFAULT NULL,
  `inventory_money` decimal(20,5) DEFAULT NULL,
  `inventory_money_used` decimal(20,5) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_bank_internals`
--

CREATE TABLE `accounting_bank_internals` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `is_customer` enum('0','1') DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` varchar(200) DEFAULT NULL,
  `personnel_address` varchar(600) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `is_bill` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `total_money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `finance_tc` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bank_types`
--

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

--
-- Table structure for table `accounting_baseunit_types`
--

CREATE TABLE `accounting_baseunit_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `company_id` int(11) DEFAULT NULL,
  `address` varchar(500) DEFAULT NULL,
  `tax` varchar(200) DEFAULT NULL,
  `director_id` bigint(20) DEFAULT NULL,
  `chief_id` bigint(20) DEFAULT NULL,
  `created_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_bill_type_externals`
--

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

--
-- Table structure for table `accounting_bill_type_internals`
--

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

--
-- Table structure for table `accounting_booklogs`
--

CREATE TABLE `accounting_booklogs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `payment_id` bigint(20) DEFAULT NULL,
  `date_begin` date DEFAULT NULL,
  `month` tinyint(4) DEFAULT NULL,
  `year` year(4) DEFAULT NULL,
  `reduction` int(11) DEFAULT NULL COMMENT 'Thời gian tính khấu hao',
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type` varchar(200) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `date_receipt` date DEFAULT NULL,
  `number_receipt` varchar(100) DEFAULT NULL,
  `bill_number` varchar(200) DEFAULT NULL,
  `is_ledger` enum('0','1') DEFAULT '1' COMMENT '0: Chưa vào sổ cái, 1: Đã vào sổ cái',
  `personnel_id` bigint(20) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `is_account` enum('1','2') DEFAULT '1' COMMENT '1: Tài khoản có, 2: Tài khoản nợ',
  `money_debt` decimal(20,5) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `ord` tinyint(4) NOT NULL DEFAULT '1',
  `goods_id` bigint(20) DEFAULT NULL,
  `goods_amount` bigint(20) DEFAULT NULL,
  `warehouse_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_budget_external_types`
--

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

--
-- Table structure for table `accounting_budget_internal_types`
--

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

--
-- Table structure for table `accounting_capital_types`
--

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

--
-- Table structure for table `accounting_contract_buy_types`
--

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

--
-- Table structure for table `accounting_contract_credit_types`
--

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

--
-- Table structure for table `accounting_contract_loan_types`
--

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

--
-- Table structure for table `accounting_contract_sale_types`
--

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

--
-- Table structure for table `accounting_cost_factor_types`
--

CREATE TABLE `accounting_cost_factor_types` (
  `ID` int(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL COMMENT 'Tài khoản kế toán',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_cost_logs`
--

CREATE TABLE `accounting_cost_logs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `cost_id` int(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `number_receipt` varchar(100) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `type` varchar(100) NOT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `desc` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_cost_types`
--

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

--
-- Table structure for table `accounting_crm_action_care_files`
--

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

--
-- Table structure for table `accounting_crm_action_cares`
--

CREATE TABLE `accounting_crm_action_cares` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type_action` int(11) NOT NULL,
  `type_result` int(11) DEFAULT NULL,
  `type_related` enum('0','1','2') NOT NULL DEFAULT '0',
  `potential_id` bigint(20) DEFAULT NULL,
  `business_id` bigint(20) DEFAULT NULL,
  `individual_id` bigint(20) DEFAULT NULL,
  `desc` text,
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) NOT 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 `accounting_crm_action_type_results`
--

CREATE TABLE `accounting_crm_action_type_results` (
  `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 `accounting_crm_action_types`
--

CREATE TABLE `accounting_crm_action_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `ord` tinyint(4) NOT NULL 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_actions`
--

CREATE TABLE `accounting_crm_actions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `type` varchar(30) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `action` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_campaign_types`
--

CREATE TABLE `accounting_crm_campaign_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contact_label_contacts`
--

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

--
-- Table structure for table `accounting_crm_contact_labels`
--

CREATE TABLE `accounting_crm_contact_labels` (
  `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 `accounting_crm_contact_properties`
--

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

--
-- Table structure for table `accounting_crm_contact_users`
--

CREATE TABLE `accounting_crm_contact_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contact_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 `accounting_crm_contacts`
--

CREATE TABLE `accounting_crm_contacts` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `private_code` varchar(50) DEFAULT NULL,
  `formal_name` int(11) DEFAULT NULL,
  `fax` varchar(100) DEFAULT NULL,
  `country_id` int(11) DEFAULT NULL,
  `state_id` int(11) DEFAULT NULL,
  `district_id` int(11) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `yahoo` varchar(100) DEFAULT NULL,
  `skype` varchar(100) DEFAULT NULL,
  `position_id` int(11) DEFAULT NULL,
  `desc` text,
  `created_by_id` bigint(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_active_logs`
--

CREATE TABLE `accounting_crm_contract_active_logs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `finance_id` bigint(20) DEFAULT NULL,
  `bill_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_active_users`
--

CREATE TABLE `accounting_crm_contract_active_users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) 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 `accounting_crm_contract_approver_users`
--

CREATE TABLE `accounting_crm_contract_approver_users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) 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 `accounting_crm_contract_approvers`
--

CREATE TABLE `accounting_crm_contract_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `department_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) 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 `accounting_crm_contract_assets`
--

CREATE TABLE `accounting_crm_contract_assets` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `name` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `percent_limit` decimal(5,2) DEFAULT NULL,
  `money_fact` 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 `accounting_crm_contract_bill_types`
--

CREATE TABLE `accounting_crm_contract_bill_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `finance_id` bigint(20) DEFAULT NULL,
  `module` enum('internal','external','contract') DEFAULT 'contract',
  `number` varchar(200) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `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 `accounting_crm_contract_bills`
--

CREATE TABLE `accounting_crm_contract_bills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date_fixed` date DEFAULT NULL,
  `date_paid` date DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `value` decimal(20,5) DEFAULT '0.00000',
  `currency_id` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `updated_by_id` bigint(20) NOT NULL,
  `date_updated` datetime NOT NULL,
  `code` smallint(6) DEFAULT NULL,
  `is_paid` tinyint(4) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_capitals`
--

CREATE TABLE `accounting_crm_contract_capitals` (
  `contract_id` bigint(20) NOT NULL,
  `method` enum('0','1') DEFAULT '0' COMMENT '0 - Tài sản, 1 - Tiền',
  `percentage_enjoy` decimal(5,2) DEFAULT NULL,
  `method_enjoy` enum('1','2','3') DEFAULT '1' COMMENT '1 - Bằng tiền, 2 - Sản phẩm, 3 - Tài sản',
  `periodic_dividend` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`contract_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_cares`
--

CREATE TABLE `accounting_crm_contract_cares` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) DEFAULT NULL,
  `contract_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 `accounting_crm_contract_code`
--

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

--
-- Table structure for table `accounting_crm_contract_comments`
--

CREATE TABLE `accounting_crm_contract_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,
  `contract_id` bigint(20) DEFAULT NULL,
  `content` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_credit_disbursements`
--

CREATE TABLE `accounting_crm_contract_credit_disbursements` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `desc` varchar(600) CHARACTER SET latin1 DEFAULT NULL,
  `date_expired` date DEFAULT NULL,
  `percent` decimal(10,5) DEFAULT NULL,
  `price` decimal(15,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_credits`
--

CREATE TABLE `accounting_crm_contract_credits` (
  `contract_id` bigint(20) NOT NULL,
  `method` enum('0','1') DEFAULT '0' COMMENT '0 - TS đảm bảo, 1 - Tín chấp',
  `interest_per_year` decimal(5,2) DEFAULT NULL,
  `percentage_overdue_interest` decimal(5,2) DEFAULT NULL,
  PRIMARY KEY (`contract_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_currencies`
--

CREATE TABLE `accounting_crm_contract_currencies` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `currency_id` int(11) DEFAULT NULL,
  `rate` decimal(10,2) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_files`
--

CREATE TABLE `accounting_crm_contract_files` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_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 `accounting_crm_contract_finance_payments`
--

CREATE TABLE `accounting_crm_contract_finance_payments` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) NOT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `price` decimal(15,5) DEFAULT NULL,
  `percent` decimal(5,2) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_incomes`
--

CREATE TABLE `accounting_crm_contract_incomes` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) unsigned DEFAULT NULL,
  `percent` float DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL COMMENT 'ID tham chiếu',
  `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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_label_contracts`
--

CREATE TABLE `accounting_crm_contract_label_contracts` (
  `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 `accounting_crm_contract_labels`
--

CREATE TABLE `accounting_crm_contract_labels` (
  `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 `accounting_crm_contract_reads`
--

CREATE TABLE `accounting_crm_contract_reads` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `date_read` datetime DEFAULT NULL,
  `date_active` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_sale_users`
--

CREATE TABLE `accounting_crm_contract_sale_users` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) unsigned NOT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `amount` decimal(20,5) DEFAULT '0.00000',
  `percent` float DEFAULT '0',
  `contract_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_sales`
--

CREATE TABLE `accounting_crm_contract_sales` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) NOT NULL,
  `personnel_id` bigint(20) NOT NULL,
  `personnel_name` varchar(255) NOT NULL,
  `price` decimal(20,5) NOT NULL,
  `percent` decimal(5,2) NOT NULL,
  `desc` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_services`
--

CREATE TABLE `accounting_crm_contract_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `product_id` bigint(20) DEFAULT NULL,
  `amount` float DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `vat` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `sale_off` float DEFAULT '0',
  `price_fix` decimal(20,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_services_type`
--

CREATE TABLE `accounting_crm_contract_services_type` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `services_id` bigint(20) DEFAULT NULL,
  `booth` varchar(500) DEFAULT NULL,
  `number` float DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `vat` bigint(20) DEFAULT NULL,
  `total_price` decimal(20,5) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `reduction` float DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contract_types`
--

CREATE TABLE `accounting_crm_contract_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_contracts`
--

CREATE TABLE `accounting_crm_contracts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `crm_contract_id` int(11) DEFAULT NULL,
  `code` varchar(100) DEFAULT NULL,
  `code_crm` varchar(150) DEFAULT NULL,
  `title` varchar(150) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `type` enum('trade','credit','capital') DEFAULT 'trade' COMMENT 'trade: Thương mại, credit: Tín dụng, capital: Góp vốn',
  `type_sub` enum('0','1','2','3','4','5') DEFAULT '0' COMMENT '0:Mua, 1: Bán, 2:Vay, 3: Cho vay, 4: Góp vốn, 5: Nhận góp vốn',
  `formality` enum('0','1') DEFAULT '0' COMMENT '0: Tài sản đảm bảo, 1: Tín chấp',
  `number` varchar(200) DEFAULT NULL,
  `check_title` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `vat_id` int(11) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `total_price` decimal(20,5) DEFAULT NULL,
  `finance_money` decimal(20,5) DEFAULT '0.00000',
  `accounting_money` decimal(20,5) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `asset_money` decimal(20,5) DEFAULT NULL,
  `asset_norm` float DEFAULT NULL,
  `type_money` enum('VND','OTHER') NOT NULL DEFAULT 'VND',
  `currency_id` bigint(20) DEFAULT NULL,
  `rate` decimal(20,5) DEFAULT NULL,
  `money_rate` decimal(20,5) DEFAULT NULL,
  `date_reg` date DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `desc` text,
  `interest_rate` float DEFAULT NULL COMMENT 'Lãi suất',
  `percent_over` float DEFAULT NULL COMMENT '% quá hạn',
  `project_id` bigint(20) DEFAULT NULL,
  `dividend_percent` float DEFAULT NULL,
  `dividend_formality` enum('MONEY','PRODUCT','ASSET') DEFAULT NULL,
  `dividend_periodic` text,
  `status` enum('0','1','2') DEFAULT '0',
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_crm_count_services`
--

CREATE TABLE `accounting_crm_count_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `internal_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `contract_service_type_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `is_new` tinyint(4) DEFAULT '0',
  `is_resign` tinyint(4) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_groups`
--

CREATE TABLE `accounting_crm_customer_groups` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_label_customers`
--

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

--
-- Table structure for table `accounting_crm_customer_labels`
--

CREATE TABLE `accounting_crm_customer_labels` (
  `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 `accounting_crm_customer_origins`
--

CREATE TABLE `accounting_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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_properties`
--

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

--
-- Table structure for table `accounting_crm_customer_ratings`
--

CREATE TABLE `accounting_crm_customer_ratings` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_statuses`
--

CREATE TABLE `accounting_crm_customer_statuses` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_titles`
--

CREATE TABLE `accounting_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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_types`
--

CREATE TABLE `accounting_crm_customer_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customer_users`
--

CREATE TABLE `accounting_crm_customer_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_customers`
--

CREATE TABLE `accounting_crm_customers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `crm_customer_id` int(11) DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  `type` tinyint(1) DEFAULT '0',
  `code` varchar(50) DEFAULT NULL,
  `formal_name` int(11) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `formal_represent` int(11) DEFAULT NULL,
  `represent` varchar(100) DEFAULT NULL,
  `position_id` int(11) DEFAULT NULL,
  `fax` varchar(50) DEFAULT NULL,
  `tax` varchar(500) DEFAULT NULL,
  `private_code` varchar(300) DEFAULT NULL,
  `income` decimal(20,5) DEFAULT NULL,
  `private_date` date DEFAULT NULL,
  `private_place` varchar(300) DEFAULT NULL,
  `number_of_staff` int(11) DEFAULT NULL,
  `state_id` int(11) DEFAULT NULL,
  `district_id` int(11) DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT NULL,
  `first_contact` enum('0','1') NOT NULL DEFAULT '0',
  `origin_id` int(11) DEFAULT NULL,
  `group_id` int(11) DEFAULT NULL,
  `status_id` int(11) DEFAULT NULL,
  `trade_id` int(11) DEFAULT NULL,
  `rating_id` int(11) DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  `desc` text 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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_events`
--

CREATE TABLE `accounting_crm_events` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `address` varchar(300) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `type` varchar(50) DEFAULT NULL,
  `object_id` bigint(20) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `alert` enum('0','1') DEFAULT '0',
  `alert_time` datetime DEFAULT NULL,
  `desc` text,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_feedback_approvers`
--

CREATE TABLE `accounting_crm_feedback_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `object_id` bigint(20) NOT NULL DEFAULT '0',
  `feedback_id` int(10) NOT NULL DEFAULT '0',
  `is_group` tinyint(4) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_feedback_origins`
--

CREATE TABLE `accounting_crm_feedback_origins` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_feedback_reasons`
--

CREATE TABLE `accounting_crm_feedback_reasons` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_feedback_type_approvers`
--

CREATE TABLE `accounting_crm_feedback_type_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `object_id` bigint(20) NOT NULL DEFAULT '0',
  `type_id` int(10) NOT NULL DEFAULT '0',
  `is_group` tinyint(4) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_feedback_types`
--

CREATE TABLE `accounting_crm_feedback_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_feedbacks`
--

CREATE TABLE `accounting_crm_feedbacks` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `origin_id` int(11) DEFAULT NULL,
  `reason_id` int(11) DEFAULT NULL,
  `priority_type` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `contact_id` bigint(20) DEFAULT NULL,
  `process_type` int(20) DEFAULT NULL,
  `user_id` int(20) DEFAULT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_files`
--

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

--
-- Table structure for table `accounting_crm_income_services`
--

CREATE TABLE `accounting_crm_income_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `personnel_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT '0',
  `date` datetime DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT '0',
  `internal_id` bigint(20) DEFAULT '0',
  `type` enum('INTERNAL','CONTRACT') DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_incomes`
--

CREATE TABLE `accounting_crm_incomes` (
  `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `target_person_id` bigint(20) DEFAULT '0',
  `target_money` decimal(20,5) DEFAULT '0.00000',
  `target_number_new` int(11) DEFAULT '0',
  `target_number_resign` int(11) DEFAULT '0',
  `target_date_from` datetime DEFAULT NULL,
  `target_date_to` datetime DEFAULT NULL,
  `personnel_id` bigint(20) unsigned DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `contract_date` datetime DEFAULT NULL,
  `contract_money` decimal(20,5) DEFAULT NULL,
  `service_id` varchar(500) DEFAULT NULL,
  `internal_id` bigint(20) NOT NULL,
  `internal_date` datetime DEFAULT NULL,
  `internal_money` decimal(20,5) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_marketing_plans`
--

CREATE TABLE `accounting_crm_marketing_plans` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `marketing_id` bigint(20) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  `quantity` int(11) DEFAULT NULL,
  `percent_desired` decimal(5,2) DEFAULT NULL,
  `percent_actual` decimal(5,2) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_marketing_status`
--

CREATE TABLE `accounting_crm_marketing_status` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_marketing_types`
--

CREATE TABLE `accounting_crm_marketing_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_marketings`
--

CREATE TABLE `accounting_crm_marketings` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `estimate_cost` decimal(20,0) DEFAULT NULL,
  `actual_cost` decimal(20,0) DEFAULT NULL,
  `desired_profit` decimal(20,0) 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 `accounting_crm_opportunities`
--

CREATE TABLE `accounting_crm_opportunities` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `potential_id` bigint(20) DEFAULT NULL,
  `marketing_id` bigint(20) DEFAULT NULL,
  `date_expired` date DEFAULT NULL,
  `stage_id` int(11) DEFAULT NULL,
  `success_percent` decimal(5,2) DEFAULT NULL,
  `desired_price` decimal(12,2) DEFAULT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_opportunity_types`
--

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

--
-- Table structure for table `accounting_crm_order_details`
--

CREATE TABLE `accounting_crm_order_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) NOT NULL,
  `type` varchar(20) DEFAULT 'PRODUCT',
  `object_id` bigint(20) NOT NULL,
  `object_name` varchar(200) NOT NULL,
  `quantity` int(11) DEFAULT '0',
  `price` decimal(20,5) DEFAULT '0.00000',
  `sales` decimal(20,5) DEFAULT '0.00000',
  `vat` decimal(20,5) DEFAULT '0.00000',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_order_methods`
--

CREATE TABLE `accounting_crm_order_methods` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_orders`
--

CREATE TABLE `accounting_crm_orders` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `customer_id` bigint(20) NOT NULL,
  `date` date DEFAULT NULL,
  `deliver_address` varchar(300) DEFAULT NULL,
  `total_price` decimal(20,5) DEFAULT NULL,
  `adjust_price` 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 `accounting_crm_potential_label_potentials`
--

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

--
-- Table structure for table `accounting_crm_potential_labels`
--

CREATE TABLE `accounting_crm_potential_labels` (
  `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 `accounting_crm_potential_properties`
--

CREATE TABLE `accounting_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 `accounting_crm_potentials`
--

CREATE TABLE `accounting_crm_potentials` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(100) DEFAULT NULL,
  `personal_formal_name` int(11) DEFAULT NULL,
  `personal_name` varchar(100) DEFAULT NULL,
  `personal_birthday` date DEFAULT NULL,
  `personal_address` varchar(500) DEFAULT NULL,
  `business_name` varchar(300) DEFAULT NULL,
  `business_formal_represent` int(11) DEFAULT NULL,
  `business_represent` varchar(300) DEFAULT NULL,
  `business_address` varchar(300) DEFAULT NULL,
  `business_position_id` int(11) DEFAULT NULL,
  `number_of_staff` int(11) DEFAULT NULL,
  `status_id` int(11) DEFAULT NULL,
  `origin_id` int(11) DEFAULT NULL,
  `trade_id` int(11) DEFAULT NULL,
  `rating_id` int(11) DEFAULT NULL,
  `desc` text 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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_pricebook_details`
--

CREATE TABLE `accounting_crm_pricebook_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `pricebook_id` bigint(20) NOT NULL,
  `product_id` bigint(20) NOT NULL,
  `product_name` varchar(250) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT '0.00000',
  `currency_id` int(11) DEFAULT '0',
  PRIMARY KEY (`ID`,`pricebook_id`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_pricebooks`
--

CREATE TABLE `accounting_crm_pricebooks` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` enum('0','1') NOT NULL DEFAULT '0',
  `title` varchar(250) 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(600) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_product_label_products`
--

CREATE TABLE `accounting_crm_product_label_products` (
  `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 `accounting_crm_product_labels`
--

CREATE TABLE `accounting_crm_product_labels` (
  `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 `accounting_crm_product_manufacturers`
--

CREATE TABLE `accounting_crm_product_manufacturers` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_product_types`
--

CREATE TABLE `accounting_crm_product_types` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_product_units`
--

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

--
-- Table structure for table `accounting_crm_products`
--

CREATE TABLE `accounting_crm_products` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type_id` int(11) NOT NULL,
  `code` varchar(100) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `barcode` varchar(100) DEFAULT NULL,
  `manufacturer_id` int(11) DEFAULT NULL,
  `supplier_id` int(11) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT '0.00000',
  `vat` decimal(20,5) DEFAULT '0.00000',
  `sales` decimal(20,5) DEFAULT '0.00000',
  `desc` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_projects`
--

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

--
-- Table structure for table `accounting_crm_purchase_details`
--

CREATE TABLE `accounting_crm_purchase_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `purchase_id` bigint(20) NOT NULL,
  `product_id` bigint(20) NOT NULL,
  `quantity` int(11) DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_purchase_types`
--

CREATE TABLE `accounting_crm_purchase_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_purchases`
--

CREATE TABLE `accounting_crm_purchases` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `customer_id` bigint(20) NOT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `deliver_address` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_report_time_configs`
--

CREATE TABLE `accounting_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 `accounting_crm_sale_services`
--

CREATE TABLE `accounting_crm_sale_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `personnel_sale_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 `accounting_crm_service_label_products`
--

CREATE TABLE `accounting_crm_service_label_products` (
  `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 `accounting_crm_service_labels`
--

CREATE TABLE `accounting_crm_service_labels` (
  `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 `accounting_crm_service_types`
--

CREATE TABLE `accounting_crm_service_types` (
  `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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_service_units`
--

CREATE TABLE `accounting_crm_service_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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_services`
--

CREATE TABLE `accounting_crm_services` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type_id` int(11) NOT NULL,
  `title` varchar(300) DEFAULT NULL,
  `unit_id` int(11) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT '0.00000',
  `vat` decimal(20,5) DEFAULT '0.00000',
  `sales` decimal(20,5) DEFAULT '0.00000',
  `desc` varchar(600) DEFAULT NULL,
  `amount` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_services_labels`
--

CREATE TABLE `accounting_crm_services_labels` (
  `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 `accounting_crm_services_units`
--

CREATE TABLE `accounting_crm_services_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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_solutions`
--

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

--
-- Table structure for table `accounting_crm_stages`
--

CREATE TABLE `accounting_crm_stages` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_statuses`
--

CREATE TABLE `accounting_crm_statuses` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` 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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_target_approvers`
--

CREATE TABLE `accounting_crm_target_approvers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL COMMENT 'Lấy ID của bảng ''accounting_crm_contract_approvers''',
  `user_id` bigint(20) DEFAULT NULL,
  `company_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) 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 `accounting_crm_target_configs`
--

CREATE TABLE `accounting_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,
  `company_id` bigint(20) DEFAULT NULL,
  `service_id` 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 `accounting_crm_target_person_details`
--

CREATE TABLE `accounting_crm_target_person_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `target_id` bigint(20) DEFAULT NULL,
  `target_person_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `number_service` bigint(20) DEFAULT NULL,
  `date_from` datetime DEFAULT NULL,
  `date_to` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_target_persons`
--

CREATE TABLE `accounting_crm_target_persons` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `target_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `number_new` int(11) DEFAULT NULL,
  `number_resign` int(11) DEFAULT NULL,
  `date_from` datetime DEFAULT NULL,
  `date_to` decimal(10,0) DEFAULT NULL,
  `status` enum('0','1') DEFAULT '0',
  `approver_id` bigint(20) DEFAULT NULL,
  `approver_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,
  `company_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_template_exports`
--

CREATE TABLE `accounting_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_trade_types`
--

CREATE TABLE `accounting_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_crm_transaction_types`
--

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

--
-- Table structure for table `accounting_crm_transactions`
--

CREATE TABLE `accounting_crm_transactions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(200) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `created_by_id` bigint(20) NOT NULL,
  `date_created` datetime 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 `accounting_currency_types`
--

CREATE TABLE `accounting_currency_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `rate` decimal(20,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_expense_costs`
--

CREATE TABLE `accounting_expense_costs` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `code` varchar(100) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `rate_goods` float DEFAULT NULL,
  `rate_direct` float DEFAULT NULL,
  `rate_machine` float DEFAULT NULL,
  `rate_expense` 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 `accounting_expense_directs`
--

CREATE TABLE `accounting_expense_directs` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `money` 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 `accounting_expense_genarals`
--

CREATE TABLE `accounting_expense_genarals` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `money` 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 `accounting_expense_machines`
--

CREATE TABLE `accounting_expense_machines` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `account_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `rate` 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 `accounting_expense_products`
--

CREATE TABLE `accounting_expense_products` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `account_id` int(11) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `amount` decimal(20,5) DEFAULT NULL,
  `money` 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 `accounting_expense_types`
--

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

--
-- Table structure for table `accounting_external_types`
--

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

--
-- Table structure for table `accounting_finance_account_books`
--

CREATE TABLE `accounting_finance_account_books` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `money_book` decimal(20,5) DEFAULT NULL,
  `title_book` varchar(600) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `contract_sale_id` int(11) DEFAULT NULL,
  `cost_factor_id` int(11) DEFAULT NULL,
  `warehouse_type_id` int(11) DEFAULT NULL,
  `warehouse_goods_id` int(11) DEFAULT NULL,
  `desc` varchar(600) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Hạch toán trong phiếu kế toán';

--
-- Table structure for table `accounting_finance_accounts`
--

CREATE TABLE `accounting_finance_accounts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `date_receipt` date DEFAULT NULL,
  `number_receipt` varchar(100) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `bank_id` int(11) DEFAULT NULL,
  `bank_exchange_id` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `status` enum('0','1','2') DEFAULT '0',
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_finance_external_bills`
--

CREATE TABLE `accounting_finance_external_bills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `purchase_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money_theory` decimal(20,5) DEFAULT NULL,
  `money_theory_fact` decimal(20,5) DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_finance_external_nobills`
--

CREATE TABLE `accounting_finance_external_nobills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `money_change` decimal(20,5) DEFAULT NULL,
  `type_other` enum('PERSON','CUSTOMER','OTHER') DEFAULT 'OTHER',
  `personnel_id` bigint(20) DEFAULT NULL,
  `type` enum('LOAN','SALE','DEBT','OTHER') DEFAULT 'LOAN' COMMENT 'Vay vốn, bán hàng, nợ, khác',
  `contract_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `contract_money` decimal(20,5) DEFAULT NULL,
  `contract_money_had` decimal(20,5) DEFAULT NULL,
  `contract_money_debt` decimal(20,5) DEFAULT NULL,
  `inventory_id` bigint(20) DEFAULT NULL,
  `inventory_money` decimal(20,5) DEFAULT NULL,
  `inventory_money_used` decimal(20,5) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_finance_externals`
--

CREATE TABLE `accounting_finance_externals` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `date_created_external` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` varchar(200) DEFAULT NULL,
  `personnel_address` varchar(600) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `is_bill` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `total_money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `finance_tc` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_finance_internal_bills`
--

CREATE TABLE `accounting_finance_internal_bills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `invoice_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `money_theory` decimal(20,5) DEFAULT NULL,
  `money_theory_fact` decimal(20,5) DEFAULT NULL,
  `money_fact` decimal(20,5) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `contract_sale_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_finance_internal_nobills`
--

CREATE TABLE `accounting_finance_internal_nobills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `money_change` decimal(20,5) DEFAULT NULL,
  `type_other` enum('PERSON','CUSTOMER','OTHER') DEFAULT 'OTHER',
  `personnel_id` bigint(20) DEFAULT NULL,
  `type` enum('LOAN','SALE','DEBT','OTHER') DEFAULT 'LOAN' COMMENT 'Vay vốn, bán hàng, nợ, khác',
  `contract_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `contract_money` decimal(20,5) DEFAULT NULL,
  `contract_money_had` decimal(20,5) DEFAULT NULL,
  `contract_money_debt` decimal(20,5) DEFAULT NULL,
  `inventory_id` bigint(20) DEFAULT NULL,
  `inventory_money` decimal(20,5) DEFAULT NULL,
  `inventory_money_used` decimal(20,5) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_finance_internals`
--

CREATE TABLE `accounting_finance_internals` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `date_created_internal` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` varchar(200) DEFAULT NULL,
  `personnel_address` varchar(600) DEFAULT NULL,
  `reason` varchar(500) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `is_bill` enum('0','1') DEFAULT '0',
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `total_money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `finance_tc` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_fixed_asset_types`
--

CREATE TABLE `accounting_fixed_asset_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `month_start` int(11) DEFAULT NULL,
  `month_end` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_fund_book_settings`
--

CREATE TABLE `accounting_fund_book_settings` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `number` int(11) DEFAULT '100',
  `line` int(11) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_fund_types`
--

CREATE TABLE `accounting_fund_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `account_id` int(20) DEFAULT NULL,
  `department_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_insurance_types`
--

CREATE TABLE `accounting_insurance_types` (
  `ID` int(20) NOT NULL AUTO_INCREMENT,
  `percent` int(11) DEFAULT '0',
  `title` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_interest_types`
--

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

--
-- Table structure for table `accounting_interests`
--

CREATE TABLE `accounting_interests` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `percent` int(11) DEFAULT '0',
  `type` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_internal_types`
--

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

--
-- Table structure for table `accounting_inventory_adjust_goods`
--

CREATE TABLE `accounting_inventory_adjust_goods` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` int(11) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `unit_id` int(11) DEFAULT NULL,
  `account_warehouse` int(11) DEFAULT NULL,
  `number_exist` int(11) DEFAULT NULL,
  `number_inventoried` int(11) DEFAULT NULL,
  `number_disparity` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_adjusts`
--

CREATE TABLE `accounting_inventory_adjusts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `warehouse_id` int(11) DEFAULT NULL,
  `date_inventoried` datetime DEFAULT NULL,
  `account_adjust_increase` int(11) DEFAULT NULL,
  `account_adjust_decrease` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_deliveries`
--

CREATE TABLE `accounting_inventory_deliveries` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` tinyint(4) DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` text,
  `name` varchar(200) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `total_amount` int(11) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `vat_id` int(11) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `total_money_all` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `transfer_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_delivery_expenses`
--

CREATE TABLE `accounting_inventory_delivery_expenses` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `warehouse_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `money_expense` decimal(20,5) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_delivery_goods`
--

CREATE TABLE `accounting_inventory_delivery_goods` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `warehouse_id` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `money_vnd` decimal(20,5) DEFAULT NULL,
  `money_change` decimal(20,5) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `transfer_id` bigint(20) DEFAULT NULL COMMENT 'ID của phiếu điều chuyển kho',
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_delivery_taxs`
--

CREATE TABLE `accounting_inventory_delivery_taxs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `template_id` int(11) DEFAULT NULL,
  `report_id` int(11) DEFAULT NULL,
  `number` varchar(100) DEFAULT NULL,
  `seri` varchar(100) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `vat_id` int(11) DEFAULT NULL,
  `money_vat` int(11) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_goods`
--

CREATE TABLE `accounting_inventory_goods` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(100) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  `unit_id` int(11) DEFAULT NULL,
  `number_exist` bigint(20) DEFAULT NULL,
  `account_goods` int(11) DEFAULT NULL,
  `account_revenue` int(11) DEFAULT NULL,
  `account_capital` int(11) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `number_delivery` int(11) DEFAULT NULL,
  `number_receive` int(11) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_receive_goods`
--

CREATE TABLE `accounting_inventory_receive_goods` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `warehouse_id` bigint(20) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `money_vnd` decimal(20,5) DEFAULT NULL,
  `money_change` decimal(20,5) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `transfer_id` bigint(20) DEFAULT NULL COMMENT 'ID của phiếu điều chuyển kho',
  `type_transfer` tinyint(4) DEFAULT NULL,
  `delivery_goods` varchar(100) DEFAULT NULL COMMENT 'TK:Lấy từ bảng tồn kho, PS: Lấy từ phiếu nhập',
  `money_goods` decimal(20,5) DEFAULT NULL,
  `total_money_goods` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_receives`
--

CREATE TABLE `accounting_inventory_receives` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `type` enum('GOODS','EXPENSE','TAX') DEFAULT 'GOODS',
  `date_account` date DEFAULT NULL,
  `book_number` int(11) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `is_personnel` tinyint(4) DEFAULT '0',
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_name` text,
  `name` varchar(200) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` varchar(200) DEFAULT NULL,
  `total_amount` int(11) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `auto_created` enum('0','1') DEFAULT '0',
  `transfer_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_reports`
--

CREATE TABLE `accounting_inventory_reports` (
  `goods_id` bigint(20) NOT NULL DEFAULT '0',
  `warehouse_id` bigint(20) NOT NULL DEFAULT '0',
  `amount` double DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `type` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`goods_id`,`warehouse_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_storages`
--

CREATE TABLE `accounting_inventory_storages` (
  `goods_id` bigint(20) NOT NULL DEFAULT '0',
  `warehouse_id` bigint(20) NOT NULL DEFAULT '0',
  `amount` double DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `type` varchar(100) DEFAULT NULL COMMENT 'Tác động lần cuối từ bảng nào',
  PRIMARY KEY (`goods_id`,`warehouse_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_transfer_goods`
--

CREATE TABLE `accounting_inventory_transfer_goods` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `unit_id` int(11) DEFAULT NULL,
  `project_id` int(11) DEFAULT NULL,
  `number_inventory` int(11) DEFAULT NULL,
  `number_transfer` int(11) DEFAULT NULL,
  `type_transfer` varchar(100) DEFAULT NULL,
  `delivery_goods` varchar(100) DEFAULT NULL,
  `money_goods` decimal(20,5) DEFAULT NULL,
  `total_money_goods` decimal(20,5) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_transfers`
--

CREATE TABLE `accounting_inventory_transfers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `delivery_id` bigint(20) DEFAULT NULL,
  `receive_id` bigint(20) DEFAULT NULL,
  `is_personnel` enum('0','1') DEFAULT '0',
  `personnel_id` int(11) DEFAULT NULL,
  `personnel_name` varchar(300) DEFAULT NULL,
  `is_personnel_rece` enum('0','1') DEFAULT '0',
  `personnel_id_rece` int(11) DEFAULT NULL,
  `personnel_name_rece` varchar(300) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `date_transfer_created` datetime DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `type_money` enum('VND','OTHER') DEFAULT 'VND',
  `currency_id` int(11) DEFAULT NULL,
  `rate` float DEFAULT NULL,
  `total_number` int(11) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `f_account_had` bigint(20) DEFAULT NULL COMMENT 'Lấy tài khoản có cho bên phiếu xuất',
  `f_customer_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_inventory_warehouses`
--

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

--
-- Table structure for table `accounting_project_assigns`
--

CREATE TABLE `accounting_project_assigns` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `project_id` int(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `module` varchar(100) 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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_project_details`
--

CREATE TABLE `accounting_project_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `project_id` int(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `number_receipt` varchar(100) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `type` varchar(100) NOT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `desc` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_project_types`
--

CREATE TABLE `accounting_project_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(100) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_report_templates`
--

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

--
-- Table structure for table `accounting_report_types`
--

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

--
-- Table structure for table `accounting_salaries`
--

CREATE TABLE `accounting_salaries` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(11) NOT NULL,
  `month` tinyint(4) NOT NULL,
  `year` year(4) NOT NULL,
  `salary_money` decimal(20,5) DEFAULT NULL,
  `workday` float DEFAULT NULL,
  `workday_month` tinyint(4) DEFAULT NULL,
  `salary_real` decimal(20,5) DEFAULT NULL,
  `salary_premium` decimal(20,5) DEFAULT NULL,
  `trade_union_fees` decimal(20,5) DEFAULT NULL,
  `salary_allowances` decimal(20,5) DEFAULT NULL,
  `salary_all` decimal(20,5) DEFAULT NULL,
  `insurance_social_percent` float DEFAULT NULL,
  `insurance_social_money` decimal(20,5) DEFAULT NULL,
  `insurance_social_percent_company` float DEFAULT NULL,
  `insurance_social_money_company` decimal(20,5) DEFAULT NULL,
  `insurance_social_percent_person` float DEFAULT NULL,
  `insurance_social_money_person` decimal(20,5) DEFAULT NULL,
  `insurance_health_percent` float DEFAULT NULL,
  `insurance_health_money` decimal(20,5) DEFAULT NULL,
  `insurance_health_percent_company` float DEFAULT NULL,
  `insurance_health_money_company` decimal(20,5) DEFAULT NULL,
  `insurance_health_percent_person` float DEFAULT NULL,
  `insurance_health_money_person` decimal(20,5) DEFAULT NULL,
  `insurance_unemployment_percent` float DEFAULT NULL,
  `insurance_unemployment_money` decimal(20,5) DEFAULT NULL,
  `insurance_unemployment_percent_company` float DEFAULT NULL,
  `insurance_unemployment_money_company` decimal(10,0) DEFAULT NULL,
  `insurance_unemployment_percent_person` float DEFAULT NULL,
  `insurance_unemployment_money_person` decimal(10,0) DEFAULT NULL,
  `advances_employees` decimal(20,5) DEFAULT NULL,
  `advances_employees_sub_wage` decimal(20,5) DEFAULT NULL,
  `wage_reduct_total` decimal(20,5) DEFAULT NULL,
  `money_person_reduction` decimal(20,5) DEFAULT NULL,
  `money_depend_reduction` decimal(20,5) DEFAULT NULL,
  `money_number_reduction` decimal(20,5) DEFAULT NULL,
  `money_reduction_all` decimal(20,5) DEFAULT NULL,
  `income_tax` decimal(20,5) DEFAULT NULL,
  `income_tax_person` decimal(20,5) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `f52` int(30) DEFAULT NULL,
  `f53` decimal(20,5) DEFAULT NULL,
  `f54` decimal(20,5) DEFAULT NULL,
  `f57` decimal(20,5) DEFAULT NULL,
  `f58` decimal(20,5) DEFAULT NULL,
  `f59` int(30) DEFAULT NULL,
  `insurance_f2_percent` float DEFAULT NULL,
  `insurance_f2_money` decimal(20,3) DEFAULT NULL,
  `insurance_f2_percent_person` float DEFAULT '10',
  `insurance_f2_money_person` decimal(20,3) DEFAULT NULL,
  `insurance_f2_percent_company` float DEFAULT '10',
  `insurance_f2_money_company` decimal(20,3) DEFAULT NULL,
  `insurance_f3_percent` float DEFAULT NULL,
  `insurance_f3_money` decimal(20,3) DEFAULT NULL,
  `insurance_f3_percent_person` float DEFAULT '10',
  `insurance_f3_money_person` decimal(20,3) DEFAULT NULL,
  `insurance_f3_percent_company` float DEFAULT '10',
  `insurance_f3_money_company` decimal(20,3) DEFAULT NULL,
  `insurance_f4_percent` float DEFAULT NULL,
  `insurance_f4_money` decimal(20,3) DEFAULT NULL,
  `insurance_f4_percent_person` float DEFAULT '10',
  `insurance_f4_money_person` decimal(20,3) DEFAULT NULL,
  `insurance_f4_percent_company` float DEFAULT '10',
  `insurance_f4_money_company` decimal(20,3) DEFAULT NULL,
  `insurance_f7_percent` float DEFAULT NULL,
  `insurance_f7_money` decimal(20,3) DEFAULT NULL,
  `insurance_f7_percent_person` float DEFAULT '0',
  `insurance_f7_money_person` decimal(20,3) DEFAULT NULL,
  `insurance_f7_percent_company` float DEFAULT '2',
  `insurance_f7_money_company` decimal(20,3) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `personnel_id` (`personnel_id`,`month`,`year`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_salary_books`
--

CREATE TABLE `accounting_salary_books` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `month` tinyint(4) DEFAULT NULL,
  `year` year(4) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `date_receipt` date DEFAULT NULL,
  `number_receipt` varchar(100) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `account_debt` int(11) DEFAULT NULL,
  `account_had` int(11) DEFAULT NULL,
  `money_debt` decimal(20,5) DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `factor_type` int(11) DEFAULT NULL,
  `is_autocreated` enum('0','1') DEFAULT '0',
  `desc` varchar(600) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_salary_data_types`
--

CREATE TABLE `accounting_salary_data_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `money_private` decimal(20,5) DEFAULT NULL COMMENT 'Mức giảm trừ chi phí cá nhân người nộp thuế',
  `money_person` decimal(20,5) DEFAULT NULL COMMENT 'Mức giảm trừ gia cảnh đối với  1  người phụ thuộc',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_salary_fields`
--

CREATE TABLE `accounting_salary_fields` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `type_salary` enum('NONE','ASC','DESC') DEFAULT 'NONE',
  `type_tax` enum('NO','YES') DEFAULT 'NO',
  `ord` int(11) DEFAULT '0',
  `type` varchar(10) DEFAULT NULL,
  `title` varchar(250) NOT NULL COMMENT 'tên cột hiển thị trên danh sách',
  `parent_id` int(11) DEFAULT NULL,
  `is_time` enum('0','1') DEFAULT '0',
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `display` tinyint(4) DEFAULT '0',
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_salary_item_types`
--

CREATE TABLE `accounting_salary_item_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `percent_company` float DEFAULT NULL,
  `percent_private` float DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_salary_tax_phases`
--

CREATE TABLE `accounting_salary_tax_phases` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `tax_id` bigint(20) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `money_start` decimal(20,5) DEFAULT NULL,
  `money_end` decimal(20,5) DEFAULT NULL,
  `percent` float 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 `accounting_salary_tax_types`
--

CREATE TABLE `accounting_salary_tax_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `date_end` date 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 `accounting_salary_workdays`
--

CREATE TABLE `accounting_salary_workdays` (
  `personnel_id` bigint(11) NOT NULL,
  `date` date NOT NULL,
  `amount` float DEFAULT NULL,
  PRIMARY KEY (`personnel_id`,`date`),
  KEY `personnel_id` (`personnel_id`,`date`,`amount`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_sale_invoice_receives`
--

CREATE TABLE `accounting_sale_invoice_receives` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `receive_id` bigint(20) DEFAULT NULL,
  `receive_goods_id` bigint(20) DEFAULT NULL,
  `goods_id` bigint(20) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_sale_invoice_services`
--

CREATE TABLE `accounting_sale_invoice_services` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `money_fact` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_sale_invoices`
--

CREATE TABLE `accounting_sale_invoices` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `number_receipt` varchar(200) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `type_money` enum('CASH','BANK') DEFAULT 'CASH',
  `account_debt` bigint(20) DEFAULT NULL,
  `account_had` bigint(20) DEFAULT NULL,
  `account_had_vat` bigint(20) DEFAULT NULL,
  `type` enum('GOODS','SERVICE') DEFAULT 'GOODS',
  `is_contract` enum('0','1') DEFAULT '0',
  `project_id` int(11) DEFAULT NULL COMMENT 'Mã vụ việc chỉ lấy khi chọn không có hợp đồng',
  `contract_id` bigint(20) DEFAULT NULL,
  `vat_id` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `accounting_money` decimal(20,5) DEFAULT '0.00000',
  `finance_id` bigint(20) DEFAULT NULL,
  `type_finance` varchar(200) DEFAULT NULL,
  `finance_tc` bigint(20) DEFAULT NULL COMMENT 'Phiếu thu bên tài chính',
  `type_discount` enum('NO','TRADE','PAYMENT') DEFAULT 'NO',
  `discount_percent` int(11) DEFAULT NULL,
  `discount_account` int(11) DEFAULT NULL,
  `discount_money` decimal(20,5) DEFAULT NULL,
  `discount_money_vat` decimal(20,5) DEFAULT NULL,
  `discount_money_all` decimal(20,5) DEFAULT NULL,
  `is_finance` enum('0','1') DEFAULT '0' COMMENT 'Sinh tự động phiếu thu',
  `report_template_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_sale_purchase_services`
--

CREATE TABLE `accounting_sale_purchase_services` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `cost_id` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `money_fact` 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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_sale_purchases`
--

CREATE TABLE `accounting_sale_purchases` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `number_receipt` varchar(200) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `type_money` enum('CASH','BANK') DEFAULT 'CASH',
  `account_had` bigint(20) DEFAULT NULL,
  `account_debt` bigint(20) DEFAULT NULL,
  `account_debt_vat` bigint(20) DEFAULT NULL,
  `vat_id` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `accounting_money` decimal(20,5) DEFAULT '0.00000',
  `finance_id` bigint(20) DEFAULT NULL,
  `type_finance` varchar(20) DEFAULT NULL,
  `finance_tc` bigint(20) DEFAULT NULL COMMENT 'Phiếu chi bên tài chính',
  `type_discount` enum('NO','TRADE','PAYMENT') DEFAULT 'NO',
  `discount_percent` int(11) DEFAULT NULL,
  `discount_account` int(11) DEFAULT NULL,
  `discount_money` decimal(20,5) DEFAULT NULL,
  `discount_money_vat` decimal(20,5) DEFAULT NULL,
  `discount_money_all` decimal(20,5) DEFAULT NULL,
  `is_contract` enum('0','1') DEFAULT '0',
  `project_id` int(11) DEFAULT NULL COMMENT 'Mã vụ việc chỉ lấy khi chọn không có hợp đồng',
  `cost_id` int(11) DEFAULT NULL COMMENT 'Mã phí chỉ lấy khi chọn không có hợp đồng',
  `is_finance` enum('0','1') DEFAULT '0',
  `report_template_id` int(11) DEFAULT NULL,
  `report_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_shareholder_buy_shares`
--

CREATE TABLE `accounting_shareholder_buy_shares` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `amount_purchased` int(11) DEFAULT NULL,
  `amount_register` int(11) DEFAULT NULL,
  `amount_approved` int(11) DEFAULT NULL,
  `type_id` bigint(20) DEFAULT NULL,
  `post_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_shareholder_issuances`
--

CREATE TABLE `accounting_shareholder_issuances` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(600) DEFAULT NULL,
  `date` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_shareholder_issued_share_parents`
--

CREATE TABLE `accounting_shareholder_issued_share_parents` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `issuan_id` int(11) DEFAULT NULL,
  `share_id` bigint(20) DEFAULT NULL,
  `total_money` decimal(10,0) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `update_by_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_shareholder_issued_shares_details`
--

CREATE TABLE `accounting_shareholder_issued_shares_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) DEFAULT NULL,
  `type_id` int(11) DEFAULT NULL,
  `price` decimal(10,0) DEFAULT NULL,
  `amount` int(11) DEFAULT NULL,
  `money` decimal(10,0) DEFAULT NULL,
  `year_transfer` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_shareholder_types`
--

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

--
-- Table structure for table `accounting_tax_updatebills`
--

CREATE TABLE `accounting_tax_updatebills` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `title` varchar(250) DEFAULT NULL,
  `number` varchar(200) DEFAULT NULL,
  `date_account` date DEFAULT NULL,
  `number_receipt` varchar(200) DEFAULT NULL,
  `customer_id` bigint(20) DEFAULT NULL,
  `type` enum('IN','EX') DEFAULT 'IN',
  `report_id` int(11) DEFAULT NULL,
  `vat_id` int(11) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `money_vat` decimal(20,5) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) 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 `accounting_template_exports`
--

CREATE TABLE `accounting_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 `accounting_tool_types`
--

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

--
-- Table structure for table `accounting_unit_types`
--

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

--
-- Table structure for table `accounting_vats`
--

CREATE TABLE `accounting_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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_warehouse_goods`
--

CREATE TABLE `accounting_warehouse_goods` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `unit_id` int(11) DEFAULT NULL,
  `account_id` int(11) DEFAULT NULL,
  `goods_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `accounting_warehouse_goods_types`
--

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

--
-- Table structure for table `accounting_warehouse_types`
--

CREATE TABLE `accounting_warehouse_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `department_id` int(11) DEFAULT NULL,
  `title` varchar(500) DEFAULT NULL,
  `code` varchar(200) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_actions`
--

CREATE TABLE `asset_actions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(150) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `amount` bigint(20) DEFAULT NULL,
  `total_amount` bigint(20) DEFAULT NULL,
  `action` enum('TH','CP') DEFAULT NULL,
  `source_id` bigint(20) DEFAULT NULL COMMENT 'Người cấp phát hoặc người thu hồi',
  `disk_id` bigint(20) DEFAULT NULL COMMENT 'cấp phát từ | Thu hồi từ',
  `type` enum('DEPART','PRIVATE') DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `company_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,
  `location` varchar(500) DEFAULT NULL,
  `reasons` varchar(500) DEFAULT NULL,
  `deposit_id` bigint(20) DEFAULT NULL,
  `real_id` bigint(20) DEFAULT NULL COMMENT 'type = CP , real_id : ID của thu hồi /  type = TH, real_id : ID cua lan cap phat ',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1357 DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_assets_labels`
--

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

--
-- Table structure for table `asset_depreciation_balances`
--

CREATE TABLE `asset_depreciation_balances` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `adjustment_id` bigint(20) DEFAULT NULL,
  `ord` tinyint(4) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `money_year` decimal(20,5) DEFAULT NULL,
  `money_month` decimal(20,5) DEFAULT NULL,
  `money_day` decimal(20,5) DEFAULT NULL,
  `money_year_end` decimal(20,5) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_files`
--

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

--
-- Table structure for table `asset_labels`
--

CREATE TABLE `asset_labels` (
  `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 `asset_log_reductions`
--

CREATE TABLE `asset_log_reductions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) DEFAULT NULL,
  `adjustment_id` bigint(20) DEFAULT NULL,
  `date` varchar(50) DEFAULT NULL COMMENT 'Chỉ lưu tháng và năm',
  `price` decimal(20,5) DEFAULT NULL,
  `reduction_money` decimal(20,5) DEFAULT NULL COMMENT 'Số tiền khấu hao',
  `remain_money` decimal(20,5) DEFAULT NULL COMMENT 'Số tiền còn lại',
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_logs`
--

CREATE TABLE `asset_logs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `asset_id` bigint(20) DEFAULT NULL,
  `adjustment_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `money_new` decimal(20,5) DEFAULT NULL,
  `month` int(11) DEFAULT NULL,
  `month_new` int(11) DEFAULT NULL,
  `date_used` date DEFAULT NULL,
  `date_used_new` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `date_end_new` date DEFAULT NULL,
  `reduction_type` enum('1','2') DEFAULT '1',
  `reduction_type_new` enum('1','2') DEFAULT '1',
  `date` date DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_projects`
--

CREATE TABLE `asset_projects` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  `project_id` bigint(20) DEFAULT NULL,
  `percent` float DEFAULT NULL,
  `money_had` decimal(20,5) DEFAULT NULL,
  `date_start` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `adjustment_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_status`
--

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

--
-- Table structure for table `asset_template_exports`
--

CREATE TABLE `asset_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 AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `asset_types`
--

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

--
-- Table structure for table `asset_use_status`
--

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

--
-- Table structure for table `assets`
--

CREATE TABLE `assets` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `code` varchar(300) DEFAULT NULL,
  `title` text,
  `title_2` varchar(500) DEFAULT NULL,
  `mac_code` varchar(500) DEFAULT NULL,
  `unit_id` bigint(20) DEFAULT NULL,
  `date_begin_use` datetime DEFAULT NULL,
  `location_id` bigint(20) DEFAULT NULL,
  `model` varchar(300) DEFAULT NULL,
  `maker` varchar(300) DEFAULT NULL,
  `price` decimal(20,5) DEFAULT NULL,
  `price_last` decimal(20,5) DEFAULT NULL,
  `price_origin` decimal(20,5) DEFAULT NULL,
  `is_adjustment` enum('0','1') DEFAULT '0',
  `balance` decimal(20,5) DEFAULT NULL,
  `currency_id` int(11) DEFAULT NULL,
  `date_bought` date DEFAULT NULL,
  `date_used` date DEFAULT NULL,
  `date_used_last` date DEFAULT NULL,
  `date_used_origin` date DEFAULT NULL,
  `date_end` date DEFAULT NULL,
  `date_end_last` date DEFAULT NULL,
  `date_end_origin` date DEFAULT NULL,
  `time_warranty` int(11) DEFAULT NULL,
  `code_warranty` varchar(150) DEFAULT NULL,
  `money_all` decimal(20,5) DEFAULT NULL,
  `reduction_time_all` int(11) DEFAULT NULL,
  `condition_warranty` text,
  `country_id` bigint(20) DEFAULT NULL,
  `purchase_id` bigint(20) DEFAULT NULL,
  `capital_id` bigint(20) DEFAULT NULL,
  `factor_id` bigint(20) DEFAULT NULL,
  `time` date DEFAULT NULL,
  `address` varchar(150) DEFAULT NULL,
  `suppliers` varchar(150) DEFAULT NULL,
  `reduction_time` int(11) DEFAULT NULL,
  `reduction_time_last` int(11) DEFAULT NULL,
  `reduction_time_origin` int(11) DEFAULT NULL,
  `reduction_year` float DEFAULT NULL,
  `reduction_year_last` float DEFAULT NULL,
  `reduction_year_origin` int(11) DEFAULT NULL,
  `reduction_type` enum('1','2','3') DEFAULT '1' COMMENT '''1'' khấu hao đường thẳng, ''2'' khấu hao theo số dư giảm dần',
  `reduction_type_last` tinyint(4) DEFAULT NULL,
  `reduction_type_origin` tinyint(4) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  `group_id` int(11) DEFAULT NULL,
  `status_id` int(11) DEFAULT '0' COMMENT '0 : Tồn kho, 1: Cấp phát',
  `use_status_id` int(11) DEFAULT NULL,
  `date_tranfer` datetime DEFAULT NULL,
  `desc` text,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `count_allocation` int(11) DEFAULT NULL,
  `count_recovery` int(11) DEFAULT NULL,
  `account_asset` bigint(20) DEFAULT NULL,
  `account_depreciation` bigint(20) DEFAULT NULL,
  `account_cost` bigint(20) DEFAULT NULL,
  `amount` bigint(20) DEFAULT NULL,
  `amount_free` bigint(20) DEFAULT NULL,
  `asset_parent_id` bigint(20) DEFAULT NULL,
  `asset_parent_type` enum('CHILDREN','PARENT') DEFAULT 'PARENT',
  `note` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `code_unique` (`code`(50)),
  KEY `code` (`code`(255))
) ENGINE=InnoDB AUTO_INCREMENT=1301 DEFAULT CHARSET=utf8;

--
-- Table structure for table `assets_assign_deposits`
--

CREATE TABLE `assets_assign_deposits` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) 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 `assets_assigns`
--

CREATE TABLE `assets_assigns` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) DEFAULT NULL,
  `asset_id` bigint(20) DEFAULT NULL,
  `status` bigint(20) DEFAULT NULL,
  `code_assign` varchar(250) DEFAULT NULL,
  `code_back` varchar(250) DEFAULT NULL,
  `personnel_assign_id` bigint(20) NOT NULL,
  `personnel_get_back_id` bigint(20) NOT NULL,
  `date_assign` datetime DEFAULT NULL,
  `date_back` date DEFAULT NULL,
  `date_back_fixed` date DEFAULT NULL,
  `status_assigns` tinyint(10) DEFAULT '0',
  `is_deposit` tinyint(10) DEFAULT '0',
  `is_deposit_back` tinyint(10) DEFAULT '0',
  `deposit_id` bigint(20) DEFAULT NULL,
  `personnel_id` bigint(20) DEFAULT NULL,
  `personnel_back_id` bigint(20) DEFAULT NULL,
  `use_status_back_id` int(11) DEFAULT NULL,
  `use_status_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `reasons` varchar(500) DEFAULT NULL,
  `reasons_back` varchar(500) DEFAULT NULL,
  `location_back` varchar(500) DEFAULT NULL,
  `location_assign` varchar(250) DEFAULT NULL,
  `department_id` bigint(20) DEFAULT NULL,
  `department_back_id` bigint(20) DEFAULT NULL,
  `type` enum('PRIVATE','DEPART') DEFAULT 'PRIVATE',
  `type_back` enum('PRIVATE','DEPART') DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `assets_units`
--

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

--
-- Table structure for table `backup_crm_accounts`
--

CREATE TABLE `backup_crm_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 `backup_crm_contract_customers`
--

CREATE TABLE `backup_crm_contract_customers` (
  `ID` bigint(20) NOT NULL DEFAULT '0',
  `code` varchar(300) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  `formal_name` bigint(20) DEFAULT NULL,
  `formal_name_title` varchar(300) DEFAULT NULL,
  `name` varchar(300) DEFAULT NULL,
  `phone` varchar(300) DEFAULT NULL,
  `email` varchar(300) DEFAULT NULL,
  `address` varchar(300) DEFAULT NULL,
  `trade_id` bigint(20) DEFAULT NULL,
  `trade_title` varchar(300) DEFAULT NULL,
  `private_code` varchar(300) DEFAULT NULL,
  `job_tax` varchar(300) DEFAULT NULL,
  `represent_formal_id` bigint(20) DEFAULT NULL,
  `represent_formal_title` varchar(300) DEFAULT NULL,
  `represent_name` varchar(300) DEFAULT NULL,
  `represent_job_title` varchar(200) DEFAULT NULL,
  `represent_birthday` datetime DEFAULT NULL,
  `represent_email` varchar(300) DEFAULT NULL,
  `represent_phone` varchar(300) DEFAULT NULL,
  `represent_address` varchar(300) DEFAULT NULL,
  `customer_id_old` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `backup_crm_contracts`
--

CREATE TABLE `backup_crm_contracts` (
  `ID` bigint(20) NOT NULL DEFAULT '0',
  `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'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `backup_crm_leads`
--

CREATE TABLE `backup_crm_leads` (
  `id` int(11) NOT NULL DEFAULT '0',
  `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'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `backup_crm_object_properties`
--

CREATE TABLE `backup_crm_object_properties` (
  `ID` int(11) NOT NULL DEFAULT '0',
  `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'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `cache_files`
--

CREATE TABLE `cache_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,
  `created_by_id` bigint(20) NOT NULL,
  `date_created` datetime NOT NULL,
  `module` varchar(50) NOT NULL,
  `path` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=40601 DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendar_configs`
--

CREATE TABLE `calendar_configs` (
  `alias` varchar(50) NOT NULL,
  `user_id` bigint(20) NOT NULL DEFAULT '0',
  `color` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`alias`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendar_events`
--

CREATE TABLE `calendar_events` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `uid` bigint(20) DEFAULT NULL,
  `alias` varchar(50) DEFAULT 'PRIVATE',
  `user_ids` text,
  `title` varchar(300) DEFAULT NULL,
  `color` varchar(20) DEFAULT NULL,
  `access` varchar(20) DEFAULT 'PUBLIC',
  `repeat_type` enum('NONE','DAILY','WEEKLY','MONTHLY','QUARTERLY','YEARLY') DEFAULT 'NONE',
  `allday` tinyint(1) NOT NULL DEFAULT '0',
  `desc` varchar(500) NOT NULL,
  `location` varchar(200) DEFAULT NULL,
  `room_id` bigint(20) DEFAULT NULL,
  `start` datetime DEFAULT NULL,
  `end` datetime DEFAULT NULL,
  `invitors` longtext,
  `invitor_ids` text,
  `reminders` text,
  `repeat_condition` varchar(500) DEFAULT NULL,
  `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` date DEFAULT NULL,
  `repeat_end_at` datetime DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `repeat_type` (`repeat_type`),
  KEY `start` (`start`),
  KEY `end` (`end`),
  KEY `repeat_end_at` (`repeat_end_at`)
) ENGINE=InnoDB AUTO_INCREMENT=4176 DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendar_reminders`
--

CREATE TABLE `calendar_reminders` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) DEFAULT NULL,
  `time` varchar(20) DEFAULT NULL,
  `unit` varchar(15) DEFAULT NULL,
  `before` varchar(15) DEFAULT NULL,
  `method` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendar_rooms`
--

CREATE TABLE `calendar_rooms` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(250) DEFAULT NULL,
  `desc` text,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendar_triggers`
--

CREATE TABLE `calendar_triggers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `event_id` int(11) NOT NULL,
  `time` datetime DEFAULT NULL,
  `method` varchar(50) DEFAULT NULL,
  `to` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `event_id` (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendars`
--

CREATE TABLE `calendars` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `ord` int(11) NOT NULL,
  `color` varchar(20) DEFAULT NULL,
  `icon` varchar(20) DEFAULT NULL,
  `alias` varchar(50) DEFAULT NULL,
  `type` enum('STATIC','USER','GLOBAL') NOT NULL DEFAULT 'USER',
  `department_ids` text,
  `user_ids` text,
  `title` varchar(250) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `can_config` enum('0','1') NOT NULL DEFAULT '1',
  `can_add` enum('0','1') NOT NULL DEFAULT '1',
  `can_delete` enum('0','1') NOT NULL DEFAULT '1',
  `desc` text,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `alias` (`alias`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendars_confirms`
--

CREATE TABLE `calendars_confirms` (
  `user_id` bigint(20) DEFAULT NULL,
  `event_id` bigint(20) DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `confirm` enum('ACCEPT','DECLINE','TENTATIVE') DEFAULT NULL,
  `confirm_msg` varchar(200) DEFAULT NULL,
  KEY `user_id` (`user_id`,`event_id`,`date`),
  KEY `user_id_2` (`user_id`,`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `calendars_types`
--

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

--
-- Table structure for table `calendars_users`
--

CREATE TABLE `calendars_users` (
  `user_id` bigint(20) NOT NULL,
  `calendar_id` bigint(20) NOT NULL,
  `is_guest` enum('yes','no') NOT NULL DEFAULT 'no',
  `status` enum('yes','no','waiting') NOT NULL DEFAULT 'waiting',
  `quote` varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `change_package_requests`
--

CREATE TABLE `change_package_requests` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contract_id` int(11) DEFAULT '-1',
  `website` varchar(255) DEFAULT NULL,
  `body` text,
  `retry` int(11) DEFAULT '0',
  `created` datetime DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  `response_code` varchar(10) DEFAULT NULL,
  `response_error` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6408 DEFAULT CHARSET=utf8;

--
-- Table structure for table `comments`
--

CREATE TABLE `comments` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `parent_id` bigint(20) DEFAULT NULL,
  `has_sub` tinyint(1) NOT NULL DEFAULT '0',
  `content` text,
  `module` varchar(50) DEFAULT NULL,
  `object` varchar(20) DEFAULT NULL,
  `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,
  `created_by_id` bigint(20) DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `module` (`module`,`object1_id`),
  KEY `sub_module` (`object`,`object2`)
) ENGINE=InnoDB AUTO_INCREMENT=53747 DEFAULT CHARSET=utf8;

--
-- Table structure for table `configs`
--

CREATE TABLE `configs` (
  `version` varchar(5) DEFAULT NULL,
  `title` varchar(300) DEFAULT NULL,
  `desc` varchar(300) DEFAULT NULL,
  `time_notice` int(10) unsigned NOT NULL DEFAULT '5',
  `time_chat` int(10) unsigned NOT NULL DEFAULT '5',
  `security_code` varchar(300) DEFAULT NULL,
  `email_host` varchar(250) DEFAULT NULL,
  `email_port` varchar(10) DEFAULT NULL,
  `email_account` varchar(250) DEFAULT NULL,
  `email_password` varchar(250) DEFAULT NULL,
  `email_name` varchar(250) DEFAULT NULL,
  `email_smtpsecure` enum('ssl','tls') NOT NULL DEFAULT 'ssl',
  `posts_per_page` int(10) DEFAULT NULL,
  `color_default` varchar(20) DEFAULT NULL,
  `max_size_upload` varchar(20) DEFAULT NULL,
  `reset_password_expired_time` int(10) DEFAULT NULL,
  `login_https` tinyint(4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `contact_labels`
--

CREATE TABLE `contact_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 DEFAULT CHARSET=utf8;

--
-- Table structure for table `contact_properties`
--

CREATE TABLE `contact_properties` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `p_name` varchar(300) DEFAULT NULL,
  `p_value` varchar(250) DEFAULT NULL,
  `contact_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `contacts`
--

CREATE TABLE `contacts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `job_title` varchar(300) DEFAULT NULL,
  `company` varchar(300) DEFAULT NULL,
  `department` varchar(300) DEFAULT NULL,
  `email` varchar(300) DEFAULT NULL,
  `address` varchar(300) DEFAULT NULL,
  `position_id` int(11) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `mobile` varchar(30) DEFAULT NULL,
  `fax` varchar(20) DEFAULT NULL,
  `homepage` varchar(300) DEFAULT NULL,
  `desc` varchar(600) NOT NULL,
  `birthday` date DEFAULT NULL,
  `img` varchar(100) DEFAULT NULL,
  `country` bigint(20) DEFAULT NULL,
  `origin_id` bigint(20) NOT NULL,
  `created_by_id` bigint(20) unsigned NOT NULL,
  `updated_by_id` bigint(20) unsigned NOT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;

--
-- Table structure for table `contacts_contact_labels`
--

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

--
-- Table structure for table `contacts_users`
--

CREATE TABLE `contacts_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contact_id` bigint(20) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `contracts_representative`
--

CREATE TABLE `contracts_representative` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `type` enum('user_contract','comp_contract') NOT NULL,
  `name` varchar(300) DEFAULT NULL,
  `nation` varchar(100) DEFAULT NULL,
  `functions` varchar(50) DEFAULT NULL,
  `mirror_for` varchar(50) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `address` text,
  `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `convert_mappers`
--

CREATE TABLE `convert_mappers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contact_id` int(11) DEFAULT NULL,
  `potential_id` int(11) DEFAULT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `lead_id` int(11) DEFAULT NULL,
  `opportunity_id` int(11) DEFAULT NULL,
  `account_id` int(11) DEFAULT NULL,
  `trial_service_id` int(11) DEFAULT NULL,
  `status` varchar(16) NOT NULL DEFAULT 'PENDING',
  `message` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contact_id` (`contact_id`),
  KEY `customer_id` (`customer_id`),
  KEY `potential_id` (`potential_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_accounts`
--

CREATE TABLE `crm_accounts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `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,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=33715 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_action_care_files`
--

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

--
-- Table structure for table `crm_action_cares`
--

CREATE TABLE `crm_action_cares` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type_action` int(11) NOT NULL,
  `type_result` int(11) DEFAULT NULL,
  `type` enum('CONTACT','POTENTIAL','CUSTOMER') NOT NULL DEFAULT 'CONTACT',
  `post_id` bigint(20) NOT NULL,
  `date_result` date DEFAULT NULL,
  `desc` text,
  `created_from` enum('MOBILE','WEBSITE') DEFAULT 'WEBSITE',
  `date_created` datetime NOT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` bigint(20) DEFAULT NULL,
  `care_shift_date` date DEFAULT NULL,
  `care_shift_id` bigint(20) DEFAULT NULL,
  `care_is_last_date` enum('0','1') DEFAULT '0',
  `service_id` bigint(20) DEFAULT NULL,
  `support_topic_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `PostId_Index` (`type`,`post_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=62662 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_action_type_results`
--

CREATE TABLE `crm_action_type_results` (
  `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,
  `type` enum('DATE','NORMAL') NOT NULL DEFAULT 'NORMAL',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_action_types`
--

CREATE TABLE `crm_action_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `ord` tinyint(4) 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=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_actions`
--

CREATE TABLE `crm_actions` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `type` varchar(30) DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `action` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_activities`
--

CREATE TABLE `crm_activities` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lead_id` int(11) NOT NULL,
  `subtype` varchar(10) NOT NULL COMMENT 'Task, Email, Call, Event',
  `type` varchar(10) NOT NULL COMMENT 'Call, Meeting, Other',
  `origin_id` int(11) NOT NULL,
  `closed` bit(1) NOT NULL DEFAULT b'0',
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  `account_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lead` (`lead_id`,`closed`,`modified`),
  UNIQUE KEY `lead_subtypes` (`lead_id`,`subtype`,`closed`,`modified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='chứa các thông tin chăm sóc cho lead và opportunity';

--
-- Table structure for table `crm_affiliate_assigns`
--

CREATE TABLE `crm_affiliate_assigns` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `personnel_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `partner_id` int(11) NOT NULL,
  `partner_email` varchar(255) NOT NULL,
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `partner_email` (`partner_email`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_affiliate_receive_contact_registers`
--

CREATE TABLE `crm_affiliate_receive_contact_registers` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `personnel_id` int(11) NOT NULL,
  `status` enum('inactive','active') NOT NULL DEFAULT 'inactive',
  `date_created` datetime NOT NULL,
  `created_by_id` int(11) DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `updated_by_id` int(11) DEFAULT NULL,
  `is_deleted` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_affiliate_share_histories`
--

CREATE TABLE `crm_affiliate_share_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `potential_id` bigint(20) NOT NULL,
  `contact_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `old_sale_id` bigint(20) DEFAULT NULL,
  `old_telesale_id` bigint(20) DEFAULT NULL,
  `valid` enum('valid','invalid') DEFAULT 'valid',
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_bizweb_sync_datas`
--

CREATE TABLE `crm_bizweb_sync_datas` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `bizweb_id` varchar(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `phone_mobile` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `status` varchar(255) DEFAULT NULL,
  `category_id` varchar(255) DEFAULT NULL,
  `sale` varchar(255) DEFAULT NULL,
  `website` varchar(255) DEFAULT NULL,
  `package_name` varchar(255) DEFAULT NULL,
  `started_date` varchar(255) DEFAULT NULL,
  `expired_date` varchar(255) DEFAULT NULL,
  `description` varchar(255) DEFAULT NULL,
  `category_name` varchar(255) DEFAULT NULL,
  `sync_status` int(11) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_care_approvers`
--

CREATE TABLE `crm_care_approvers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `month` bigint(20) DEFAULT NULL,
  `year` bigint(20) DEFAULT NULL,
  `approver_id` bigint(20) DEFAULT NULL,
  `date_approver` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_care_calendars`
--

CREATE TABLE `crm_care_calendars` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date` date DEFAULT NULL,
  `shift_id` bigint(20) 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_care_divides`
--

CREATE TABLE `crm_care_divides` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `care_id` bigint(20) DEFAULT NULL,
  `sale_id` bigint(20) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `priority` decimal(20,0) DEFAULT NULL,
  `round` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=117 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_care_shift_details`
--

CREATE TABLE `crm_care_shift_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `shift_id` bigint(20) DEFAULT NULL,
  `month_from` bigint(20) DEFAULT NULL,
  `year_from` bigint(20) DEFAULT NULL,
  `month_to` bigint(20) DEFAULT NULL,
  `year_to` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_care_shifts`
--

CREATE TABLE `crm_care_shifts` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `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 AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_alert_calls`
--

CREATE TABLE `crm_contact_alert_calls` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `target` 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_contact_approver_not_enounghs`
--

CREATE TABLE `crm_contact_approver_not_enounghs` (
  `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 AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_free_times`
--

CREATE TABLE `crm_contact_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 AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_not_enough_levels`
--

CREATE TABLE `crm_contact_not_enough_levels` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `symbol_id` bigint(20) DEFAULT NULL,
  `number` bigint(20) DEFAULT NULL,
  `title` 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_contact_origins`
--

CREATE TABLE `crm_contact_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_contact_share_histories`
--

CREATE TABLE `crm_contact_share_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contact_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,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=52598 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_share_incomes`
--

CREATE TABLE `crm_contact_share_incomes` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` int(11) NOT NULL,
  `symbol_id` bigint(20) DEFAULT NULL,
  `money` bigint(20) DEFAULT NULL,
  `number` 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 AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_share_priorites`
--

CREATE TABLE `crm_contact_share_priorites` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_ids` varchar(600) DEFAULT NULL,
  `date` date 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_contact_status`
--

CREATE TABLE `crm_contact_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('0','1') 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=23 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_status_histories`
--

CREATE TABLE `crm_contact_status_histories` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contact_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) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  KEY `contact_id` (`contact_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1683861 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_trash`
--

CREATE TABLE `crm_contact_trash` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `type` enum('EMAIL','PHONE') DEFAULT NULL COMMENT 'Type : Email , Phone',
  `value` varchar(300) DEFAULT NULL,
  `created_by_id` bigint(20) DEFAULT NULL,
  `created_date` datetime DEFAULT NULL,
  `last_update_date` datetime DEFAULT NULL COMMENT 'Ngày thoát khỏi contact rác',
  `status` enum('TRASH','FREE') DEFAULT 'TRASH' COMMENT 'Trạng thái : là rác hoặc không là rác',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='bảng lưu thông tin các contact rác';

--
-- Table structure for table `crm_contact_user_filters`
--

CREATE TABLE `crm_contact_user_filters` (
  `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 AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_user_priorities`
--

CREATE TABLE `crm_contact_user_priorities` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `service_id` int(11) NOT NULL,
  `user_id` bigint(11) NOT NULL,
  `amount` int(11) NOT NULL DEFAULT '1' COMMENT 'Sô lượng contact/ngày',
  `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_contact_user_receives`
--

CREATE TABLE `crm_contact_user_receives` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `sale_id` bigint(20) DEFAULT NULL,
  `amount` float DEFAULT NULL,
  `date` date DEFAULT '0000-00-00',
  `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=165 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_users`
--

CREATE TABLE `crm_contact_users` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contact_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 `crm_contact_warning_times`
--

CREATE TABLE `crm_contact_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_contact_write_dates`
--

CREATE TABLE `crm_contact_write_dates` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `date` date DEFAULT NULL,
  `user_id` bigint(20) DEFAULT NULL,
  `group_id` varchar(50) DEFAULT NULL,
  `is_ok` enum('1','0') DEFAULT '0',
  `reason` varchar(500) DEFAULT NULL,
  `is_approver` enum('1','0') DEFAULT '0',
  `date_approver` datetime DEFAULT NULL,
  `user_approver` bigint(20) DEFAULT NULL,
  `contact_write` int(11) DEFAULT '0',
  `contact_write_real` int(11) DEFAULT '0',
  `contact_target` int(11) DEFAULT '0',
  `contact_owe` int(11) DEFAULT '0',
  PRIMARY KEY (`ID`),
  KEY `user_id_index` (`user_id`) USING BTREE,
  KEY `user_id_date_index` (`user_id`,`date`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=110684 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contact_write_targets`
--

CREATE TABLE `crm_contact_write_targets` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `group_type` enum('CARE','TELESALE','SALE','SALE_LIMIT','TELESALE_LIMIT') DEFAULT NULL,
  `target` 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=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contacts`
--

CREATE TABLE `crm_contacts` (
  `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,
  `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,
  `date_appointment` datetime DEFAULT NULL COMMENT 'Lịch hẹn',
  `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',
  `origin_root` enum('UNKNOWN','SALE','AFFILIATE') DEFAULT 'SALE',
  `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,
  `potential_ids` tinytext,
  `has_potentials` enum('0','1') NOT NULL DEFAULT '0',
  `sale_id` bigint(20) DEFAULT NULL,
  `telesale_id` bigint(20) DEFAULT NULL,
  `region_id` int(11) 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,
  `share_last_date` datetime DEFAULT NULL,
  `condition_type_old` varchar(200) DEFAULT NULL,
  `is_merge` enum('yes','no') NOT NULL DEFAULT 'no',
  `care_last_id` bigint(20) DEFAULT NULL,
  `care_last_date` datetime DEFAULT NULL,
  `root_id` bigint(20) 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,
  `is_created_action` enum('0','1') DEFAULT '0',
  `is_potential` enum('0','1') DEFAULT '0' COMMENT 'đánh dấu là contact tiềm năng',
  `has_normal_potentials` enum('0','1') DEFAULT '0',
  PRIMARY KEY (`ID`),
  KEY `rs_id` (`rs_id`) USING BTREE,
  KEY `created_by_id` (`created_by_id`) USING BTREE,
  KEY `root_id` (`root_id`) USING BTREE,
  KEY `date_action_updated` (`date_action_updated`),
  KEY `date_appointment` (`date_appointment`),
  KEY `sale_id` (`sale_id`) USING BTREE,
  KEY `telesale_id` (`telesale_id`) USING BTREE,
  KEY `date_created` (`date_created`),
  KEY `condition_type` (`condition_type`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=986359 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_appendix_configs`
--

CREATE TABLE `crm_contract_appendix_configs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `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 AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_appendix_details`
--

CREATE TABLE `crm_contract_appendix_details` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) DEFAULT NULL,
  `config_id` bigint(20) DEFAULT NULL,
  `money` decimal(20,5) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_appendixs`
--

CREATE TABLE `crm_contract_appendixs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(500) DEFAULT NULL,
  `total_money` decimal(20,5) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `service_id` bigint(20) DEFAULT NULL,
  `date_request_finish` datetime DEFAULT NULL,
  `date_sign` datetime DEFAULT NULL,
  `date_number` bigint(20) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  `is_auto` enum('0','1') NOT NULL DEFAULT '0',
  `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`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1714 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_bill_requests`
--

CREATE TABLE `crm_contract_bill_requests` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contract_id` int(11) NOT NULL,
  `bill_type_id` int(11) DEFAULT NULL,
  `status` enum('0','1','2') NOT NULL DEFAULT '0' COMMENT '0: Chờ xử lý - 1: Đã xuất hóa đơn - 2: Đã xem chưa xuất',
  `comment` varchar(500) DEFAULT NULL,
  `created` datetime NOT NULL,
  `created_by` int(11) NOT NULL,
  `modified` datetime DEFAULT NULL,
  `modified_by` int(11) DEFAULT NULL,
  `exported_by` int(11) DEFAULT NULL COMMENT 'Người xuất hóa đơn gần nhất, là người chọn trạng thái "Đã xuất" khi cập nhật hóa đơn gần nhất',
  `exported` datetime DEFAULT NULL COMMENT 'Ngày xuất hóa đơn gần nhất, là ngày mà người chọn trạng thái "Đã xuất" khi cập nhật hóa đơn gần nhất',
  PRIMARY KEY (`id`) USING HASH
) ENGINE=InnoDB AUTO_INCREMENT=1178 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_bill_types`
--

CREATE TABLE `crm_contract_bill_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `finance_id` bigint(20) DEFAULT NULL,
  `module` enum('internal','external','contract') DEFAULT 'contract',
  `number` varchar(200) DEFAULT NULL,
  `date` date DEFAULT NULL,
  `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 AUTO_INCREMENT=1692 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_charge_money`
--

CREATE TABLE `crm_contract_charge_money` (
  `contract_id` bigint(20) DEFAULT NULL,
  `user_receive_charge_notice` varchar(500) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_complain_settings`
--

CREATE TABLE `crm_contract_complain_settings` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL COMMENT 'Tên của cấu hình',
  `type` enum('RESOURCE','REASON','REQUIRE') DEFAULT NULL COMMENT 'Loại cấu hình. RESOURCE : Nguồn khiếu nại , REASON : Nguyên nhân , REQUIRE : Yêu cầu của khách hàng',
  `created_by_id` bigint(11) DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_complains`
--

CREATE TABLE `crm_contract_complains` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(255) DEFAULT NULL COMMENT 'Mã khiếu nại',
  `title` varchar(255) DEFAULT NULL COMMENT 'Tiêu đề khiếu nại',
  `service_type` enum('Bizweb','Sapo') DEFAULT NULL,
  `status` enum('DOING','CLOSE') DEFAULT NULL COMMENT 'Trạng thái khiếu nại. Mặc định khi vừa được tạo là DOING(đang xử lý) , CLOSE (trạng thái đóng )',
  `contract_id` bigint(11) DEFAULT NULL COMMENT 'Hợp đồng bị khiếu nại',
  `website` varchar(300) DEFAULT NULL COMMENT 'Tên miền trỏ về',
  `date_complained` datetime DEFAULT NULL COMMENT 'Ngày khiếu nại',
  `complain_resource_id` bigint(11) DEFAULT NULL COMMENT 'ID của các nguồn tiếp nhận khiếu nại được cấu hình',
  `complain_reason_ids` varchar(300) DEFAULT NULL COMMENT 'ID của các nguyên nhân khiếu nại được cấu hình',
  `customer_require_ids` varchar(300) DEFAULT NULL COMMENT 'ID của các yêu cầu của khách hàng được cấu hình',
  `assigned_user_ids` varchar(300) DEFAULT NULL COMMENT 'ID của các users chịu trách nhiệm',
  `description` text COMMENT 'Mô tả',
  `created_by_id` bigint(11) DEFAULT NULL,
  `updated_by_id` bigint(11) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_customers`
--

CREATE TABLE `crm_contract_customers` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `code` varchar(300) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  `formal_name` bigint(20) DEFAULT NULL,
  `formal_name_title` varchar(300) DEFAULT NULL,
  `name` varchar(300) DEFAULT NULL,
  `phone` varchar(300) DEFAULT NULL,
  `email` varchar(300) DEFAULT NULL,
  `address` varchar(300) DEFAULT NULL,
  `trade_id` bigint(20) DEFAULT NULL,
  `trade_title` varchar(300) DEFAULT NULL,
  `private_code` varchar(300) DEFAULT NULL,
  `job_tax` varchar(300) DEFAULT NULL,
  `represent_formal_id` bigint(20) DEFAULT NULL,
  `represent_formal_title` varchar(300) DEFAULT NULL,
  `represent_name` varchar(300) DEFAULT NULL,
  `represent_job_title` varchar(200) DEFAULT NULL,
  `represent_birthday` datetime DEFAULT NULL,
  `represent_email` varchar(300) DEFAULT NULL,
  `represent_phone` varchar(300) DEFAULT NULL,
  `represent_address` varchar(300) DEFAULT NULL,
  `customer_id_old` bigint(20) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  `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`),
  KEY `contract_id` (`contract_id`) USING BTREE,
  KEY `customer_id` (`customer_id_old`)
) ENGINE=InnoDB AUTO_INCREMENT=45547 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_domain_type_configs`
--

CREATE TABLE `crm_contract_domain_type_configs` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` varchar(45) NOT NULL,
  `title` varchar(255) NOT NULL,
  `init_price` decimal(20,5) DEFAULT '0.00000',
  `maintain_price` decimal(20,5) DEFAULT '0.00000',
  `has_vat` enum('0','1') DEFAULT '0',
  `regex` varchar(1024) DEFAULT NULL,
  `ord` int(11) DEFAULT NULL,
  `priority` 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=27 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_domain_types`
--

CREATE TABLE `crm_contract_domain_types` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) NOT NULL,
  `type` varchar(45) DEFAULT NULL,
  `title` varchar(45) DEFAULT NULL,
  `init_price` decimal(20,5) DEFAULT NULL,
  `maintain_price` decimal(20,5) DEFAULT NULL,
  `number` int(11) DEFAULT NULL,
  `total_init_price` decimal(20,5) DEFAULT '0.00000',
  `total_maintain_price` decimal(20,5) DEFAULT '0.00000',
  `_total_price` decimal(20,5) DEFAULT '0.00000',
  `has_vat` enum('0','1') DEFAULT '0',
  `vat_percent` decimal(20,5) DEFAULT '0.00000',
  `total_vat_price` decimal(20,5) DEFAULT '0.00000',
  `total_price` decimal(20,5) DEFAULT '0.00000',
  `ord` 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`),
  KEY `contract_id` (`contract_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4108 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_domains`
--

CREATE TABLE `crm_contract_domains` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) NOT NULL,
  `type` varchar(45) NOT NULL,
  `domain` varchar(255) DEFAULT NULL,
  `domain_duration` int(11) DEFAULT NULL,
  `date_started` date DEFAULT NULL,
  `date_expired` date 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=10862 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_editing_request_types`
--

CREATE TABLE `crm_contract_editing_request_types` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL COMMENT 'Tên loại yêu cầu chỉnh sửa HĐ',
  `user_ids` varchar(500) DEFAULT NULL COMMENT 'Người được cấu hình nhận yêu cầu chỉnh sửa HĐ',
  `created_by` int(11) DEFAULT NULL,
  `modified_by` int(11) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_editing_requests`
--

CREATE TABLE `crm_contract_editing_requests` (
  `ID` bigint(11) NOT NULL AUTO_INCREMENT,
  `request_type_id` bigint(11) DEFAULT NULL COMMENT 'ID của loại yêu cầu chỉnh sửa được chọn từ phần cấu hình loại yêu cầu chỉnh sửa',
  `user_ids` varchar(500) DEFAULT NULL COMMENT 'ID của nhân viên được chọn để thực hiện yêu cầu chỉnh sửa HĐ',
  `desc` text COMMENT 'Mô tả cho yêu cầu',
  `created_by_id` bigint(11) DEFAULT NULL COMMENT 'ID của người tạo yêu cầu',
  `updated_by_id` bigint(11) DEFAULT NULL COMMENT 'ID của người sửa yêu cầu',
  `date_created` datetime DEFAULT NULL,
  `date_updated` datetime DEFAULT NULL,
  `approver_id` bigint(11) DEFAULT NULL COMMENT 'ID của người chuyển trạng thái, chuyển trạng thái rồi thì không chuyển lại trạng thái được nữa',
  `approver_desc` text COMMENT 'Ý kiến khi chuyển trạng thái',
  `date_approved` datetime DEFAULT NULL COMMENT 'Ngày chuyển trạng thái',
  `contract_id` bigint(11) DEFAULT NULL COMMENT 'ID của hợp đồng mà tạo yêu cầu chỉnh sửa',
  `status` enum('0','1','2') DEFAULT NULL COMMENT 'Trạng thái của yêu cầu chỉnh sửa ( 0: chưa sửa , 1: đã sửa , 2: không sửa )',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_fields_relation`
--

CREATE TABLE `crm_contract_fields_relation` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `field_id` bigint(20) DEFAULT NULL,
  `package_id` bigint(20) DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL,
  `contract_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=138 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_liquidation_approver_fixeds`
--

CREATE TABLE `crm_contract_liquidation_approver_fixeds` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL,
  `job_title_id` bigint(20) DEFAULT NULL,
  `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 AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_liquidation_user_receives`
--

CREATE TABLE `crm_contract_liquidation_user_receives` (
  `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 AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_liquidations`
--

CREATE TABLE `crm_contract_liquidations` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `contract_id` bigint(20) DEFAULT NULL,
  `date_liquidation` datetime DEFAULT NULL,
  `cause_type` enum('B','A') DEFAULT NULL,
  `website_new` varchar(300) DEFAULT NULL,
  `pay_type` enum('MONEY','TRANSFER') DEFAULT NULL,
  `date_stop` datetime DEFAULT NULL,
  `approver_id_tos` varchar(500) DEFAULT NULL,
  `code` 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,
  `number_rest` bigint(20) unsigned DEFAULT NULL,
  `price_back` decimal(20,5) DEFAULT NULL,
  `approver_id_1` bigint(20) DEFAULT NULL,
  `approver_id_1_status` enum('2','1','0') DEFAULT '0' COMMENT '0 chờ duyệt, 1 duyệt, 2 không duyệt',
  `approver_id_1_date` datetime DEFAULT NULL,
  `approver_id_1_comment` varchar(500) DEFAULT NULL,
  `approver_id_2` bigint(20) DEFAULT NULL,
  `approver_id_2_status` enum('1','2','0') DEFAULT NULL COMMENT '0 chờ duyệt, 1 duyệt, 2 không duyệt',
  `approver_id_2_date` datetime DEFAULT NULL,
  `approver_id_2_comment` varchar(500) DEFAULT NULL,
  `desc` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `crm_contract_locked_websites`
--

CREATE TABLE `crm_contract_locked_websites` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(300) DEFAULT NULL COMMENT 'Tên website bị khóa/tạm ngừng',
  `contract_id` bigint(20) DEFAULT NULL COMMENT 'ID của HĐ có site bị khóa/tạm ngừng',
  `type` enum('LOCKED','PAUSE') DEFAULT NULL,
  `date_created` datetime DEFAULT NULL COMMENT 'Ngày hủy/tạm đóng site',
  `created_by` bigint(20) DEFAULT NULL COMMENT 'Người thực hiện việc khóa/tạm ngừng',
  `description` varchar(500) DEFAULT NULL COMMENT 'Mô tả',
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
