
INSERT INTO `ohrm_event_listener` (`event`, `listener_class`, `enabled`, `position`) VALUES
('pim.custom_field_section_add', 'PIMCustomFieldSectionAuditListener', 1, 1),
('pim.custom_field_section_delete', 'PIMCustomFieldSectionAuditListener', 1, 1),
('pim.custom_field_section_update', 'PIMCustomFieldSectionAuditListener', 1, 1),
('pim.custom_field_add', 'PIMCustomFieldAuditListener', 1, 1),
('pim.custom_field_delete', 'PIMCustomFieldAuditListener', 1, 1),
('pim.custom_field_update', 'PIMCustomFieldAuditListener', 1, 1),
('pim.custom_field_value_update', 'PIMCustomFieldValueAuditListener', 1, 1),
('pim.custom_field_add', 'CustomFieldReportListener', 1, 1),
('pim.custom_field_delete', 'CustomFieldReportListener', 1, 1),
('pim.custom_field_update', 'CustomFieldReportListener', 1, 1),
('pim.custom_field_section_add', 'CustomFieldReportListener', 1, 1),
('pim.custom_field_section_delete', 'CustomFieldReportListener', 1, 1),
('pim.custom_field_section_update', 'CustomFieldReportListener', 1, 1);

UPDATE `ohrm_event_listener` SET `position` = `id` WHERE `event` LIKE 'pim.custom_field%';

CREATE TABLE `ohrm_audittrail_pim_custom_field_section_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_personal_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_contact_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_emergency_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_dependents_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_immigration_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_job_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_salary_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_reportto_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_qualifications_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_membership_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_audittrail_pim_tax_custom_field_trail` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `action_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `action_owner_id` varchar(6),
  `action_owner_name` VARCHAR(300),
  `version_id` INT NOT NULL DEFAULT 0,
  `action` varchar(255) NOT NULL,
  `affected_entity_id` VARCHAR(20),
  `affected_entity_name` VARCHAR(300) NOT NULL DEFAULT '',
  `action_description` VARCHAR(3000) CHARSET UTF8,
  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

SET @pim_module_id := (SELECT `id` FROM `ohrm_audittrail_module` WHERE `name`='PIM');

INSERT INTO `ohrm_audittrail_section` (`name`, `description`, `affected_entity`, `module_id`) VALUES
('CustomFieldSection', 'Configure - Custom Field Section', 'Custom Field Section', @pim_module_id),
('CustomField', 'Configure - Custom Field', 'Custom Field', @pim_module_id),
('PersonalCustomField', 'Personal Details Custom Fields', 'Employee', @pim_module_id),
('ContactCustomField', 'Contact Custom Fields', 'Employee', @pim_module_id),
('EmergencyCustomField', 'Emergency Custom Fields', 'Employee', @pim_module_id),
('DependentsCustomField', 'Dependent Custom Fields', 'Employee', @pim_module_id),
('ImmigrationCustomField', 'Immigration Custom Fields', 'Employee', @pim_module_id),
('JobCustomField', 'Job Custom Fields', 'Employee', @pim_module_id),
('SalaryCustomField', 'Salary Custom Fields', 'Employee', @pim_module_id),
('ReportToCustomField', 'Supervisor/Subordinate Custom Fields', 'Employee', @pim_module_id),
('QualificationsCustomField', 'Qualifications Custom Fields', 'Employee', @pim_module_id),
('MembershipCustomField', 'Membership Custom Fields', 'Employee', @pim_module_id),
('TaxCustomField', 'Tax Custom Fields', 'Employee', @pim_module_id);

CREATE TABLE `ohrm_datagroup_audittrail_section` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `audit_section_id` SMALLINT NOT NULL,
  `datagroup_id` INT NOT NULL,
  `permission` SMALLINT NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY(`audit_section_id`) REFERENCES ohrm_audittrail_section(`id`) ON DELETE CASCADE,
  FOREIGN KEY(`datagroup_id`) REFERENCES `ohrm_data_group`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


SET @personal_details_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='PersonalDetails' AND `module_id` = @pim_module_id);

SET @contact_information_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='ContactInformation' AND `module_id` = @pim_module_id);
SET @report_to_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='ReportTo' AND `module_id` = @pim_module_id);
SET @qualification_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='Qualification' AND `module_id` = @pim_module_id);
SET @emergency_contact_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='EmergencyContact' AND `module_id` = @pim_module_id);
SET @emp_dependent_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='EmpDependent' AND `module_id` = @pim_module_id);
SET @emp_immigration_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='EmpImmigration' AND `module_id` = @pim_module_id);
SET @emp_membership_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='EmpMembership' AND `module_id` = @pim_module_id);
SET @emp_tax_exemption_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='EmpTaxExemption' AND `module_id` = @pim_module_id);
SET @employee_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='Employee' AND `module_id` = @pim_module_id);
SET @custom_field_section_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='CustomFieldSection' AND `module_id` = @pim_module_id);
SET @custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='CustomField' AND `module_id` = @pim_module_id);
SET @personal_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'PersonalCustomField' AND `module_id` = @pim_module_id);
SET @contact_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'ContactCustomField' AND `module_id` = @pim_module_id);
SET @emergency_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'EmergencyCustomField' AND `module_id` = @pim_module_id);
SET @dependents_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'DependentsCustomField' AND `module_id` = @pim_module_id);
SET @immigration_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'ImmigrationCustomField' AND `module_id` = @pim_module_id);
SET @job_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'JobCustomField' AND `module_id` = @pim_module_id);
SET @salary_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'SalaryCustomField' AND `module_id` = @pim_module_id);
SET @reportTo_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'ReportToCustomField' AND `module_id` = @pim_module_id);
SET @qualifications_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'QualificationsCustomField' AND `module_id` = @pim_module_id);
SET @membership_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'MembershipCustomField' AND `module_id` = @pim_module_id);
SET @tax_custom_field_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name` = 'TaxCustomField' AND `module_id` = @pim_module_id);
SET @all_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='All' AND `module_id` = @pim_module_id);

SET @persoanl_details_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='personal_information');
SET @contact_info_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='contact_details');
SET @supervisor_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='supervisor');
SET @subordinate_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='subordinates');
SET @qualification_work_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='qualification_work');
SET @qualification_edu_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='qualification_education');
SET @emergency_contact_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='emergency_contacts');
SET @emp_dependent_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='dependents');
SET @emp_immigration_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='immigration');
SET @emp_membership_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='membership');
SET @emp_tax_exemption_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='tax_exemptions');
SET @contact_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'contact_custom_fields');
SET @dependents_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'dependents_custom_fields');
SET @emergency_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'emergency_custom_fields');
SET @immigration_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'immigration_custom_fields');
SET @job_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'job_custom_fields');
SET @membership_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'membership_custom_fields');
SET @personal_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'personal_custom_fields');
SET @qualifications_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'qualifications_custom_fields');
SET @report_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'report-to_custom_fields');
SET @salary_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'salary_custom_fields');
SET @tax_custom_fields_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name` = 'tax_custom_fields');
SET @pim_configure_custom_fields := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='pim_configure_custom_fields');


INSERT INTO `ohrm_datagroup_audittrail_section`(`audit_section_id`,`datagroup_id`,`permission`) VALUES
(@personal_details_section_id,@persoanl_details_datagroup_id,1),
(@contact_information_section_id,@contact_info_datagroup_id,1),
(@report_to_section_id,@supervisor_datagroup_id,1),
(@report_to_section_id,@subordinate_datagroup_id,1),
(@qualification_section_id,@qualification_work_datagroup_id,1),
(@qualification_section_id,@qualification_edu_datagroup_id,1),
(@emergency_contact_section_id,@emergency_contact_datagroup_id,1),
(@emp_dependent_section_id,@emp_dependent_datagroup_id,1),
(@emp_immigration_section_id,@emp_immigration_datagroup_id,1),
(@emp_membership_section_id,@emp_membership_datagroup_id,1),


(@emp_tax_exemption_section_id,@emp_tax_exemption_datagroup_id,1),
(@custom_field_section_section_id,@pim_configure_custom_fields,1),
(@custom_field_section_id,@pim_configure_custom_fields,1),
(@personal_custom_field_section_id, @personal_custom_fields_datagroup_id, 1),
(@contact_custom_field_section_id, @contact_custom_fields_datagroup_id, 1),
(@emergency_custom_field_section_id, @emergency_custom_fields_datagroup_id, 1),
(@dependents_custom_field_section_id, @dependents_custom_fields_datagroup_id, 1),
(@immigration_custom_field_section_id, @immigration_custom_fields_datagroup_id, 1),

(@job_custom_field_section_id, @job_custom_fields_datagroup_id, 1),
(@salary_custom_field_section_id, @salary_custom_fields_datagroup_id, 1),
(@reportTo_custom_field_section_id, @report_datagroup_id, 1),
(@qualifications_custom_field_section_id, @qualifications_custom_fields_datagroup_id, 1),
(@membership_custom_field_section_id, @membership_custom_fields_datagroup_id, 1),
(@tax_custom_field_section_id, @tax_custom_fields_datagroup_id, 1);


SET @job_title_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='job_history_details');
SET @salary_datagroup_id := (SELECT `id` FROM `ohrm_data_group` WHERE `name`='salary_history_details');

SET @job_title_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='JobRecord' AND `module_id` = @pim_module_id);
SET @salary_section_id := (SELECT `id` FROM `ohrm_audittrail_section` WHERE `name`='SalaryRecord' AND `module_id` = @pim_module_id);

INSERT INTO `ohrm_datagroup_audittrail_section`(`audit_section_id`,`datagroup_id`,`permission`) VALUES
(@job_title_section_id,@job_title_datagroup_id,1),
(@salary_section_id,@salary_datagroup_id,1);

INSERT INTO `ohrm_audittrail_section_actions` (`section_id`, `action`, `description`) VALUES
(@custom_field_section_section_id, 'ADD CUSTOM FIELD SECTION', 'Add Custom Field Section'),
(@custom_field_section_section_id, 'DELETE CUSTOM FIELD SECTION', 'Delete Custom Field Section'),
(@custom_field_section_section_id, 'UPDATE CUSTOM FIELD SECTION', 'Update Custom Field Section'),
(@custom_field_section_id, 'ADD CUSTOM FIELD', 'Add Custom Field'),
(@custom_field_section_id, 'DELETE CUSTOM FIELD', 'Delete Custom Field'),
(@custom_field_section_id, 'UPDATE CUSTOM FIELD', 'Update Custom Field'),
(@personal_custom_field_section_id, 'UPDATE PERSONAL DETAILS CUSTOM FIELDS', 'Update Personal Details Custom Fields'),
(@contact_custom_field_section_id, 'UPDATE CONTACT CUSTOM FIELDS', 'Update Contact Custom Fields'),
(@emergency_custom_field_section_id, 'UPDATE EMEREGENCY CUSTOM FIELDS', 'Update Emergency Custom Fields'),
(@dependents_custom_field_section_id, 'UPDATE DEPENDENTS CUSTOM_FIELDS', 'Update Dependents Custom Fields'),
(@immigration_custom_field_section_id, 'UPDATE IMMIGRATION CUSTOM FIELDS', 'Update Immigration Custom Fields'),
(@job_custom_field_section_id, 'UPDATE JOB CUSTOM FIELDS', 'Update Job Custom Fields'),
(@salary_custom_field_section_id, 'UPDATE SALARY CUSTOM FIELDS', 'Update Salary Custom Fields'),
(@reportTo_custom_field_section_id, 'UPDATE SUPERVISOR/SUBORDINATE CUSTOM FIELDS', 'Update Supervisor/Subordinate Custom Fields'),
(@qualifications_custom_field_section_id, 'UPDATE QUALIFICATIONS CUSTOM FIELDS', 'Update Qualifications Custom Fields'),
(@membership_custom_field_section_id, 'UPDATE MEMBERSHIP CUSTOM FIELDS', 'Update Membership Custom Fields'),
(@tax_custom_field_section_id, 'UPDATE TAX CUSTOM FIELDS', 'Update Tax Custom Fields');

DROP VIEW IF EXISTS `ohrm_audittrail_all_tables`;

CREATE VIEW `ohrm_audittrail_all_tables` AS 
(SELECT 'Contact Information' AS SECTION, pci.* FROM `ohrm_audittrail_pim_contact_info_trail` pci) 
UNION (SELECT 'Dependent' AS SECTION, pdt.* FROM `ohrm_audittrail_pim_dependents_trail` pdt) 
UNION (SELECT 'Direct Deposit' AS SECTION, pddt.* FROM `ohrm_audittrail_pim_direct_deposit_record_trail` pddt) 
UNION (SELECT 'Emergency Contacts' AS SECTION, ect.* FROM `ohrm_audittrail_pim_emergency_contacts_trail` ect) 
UNION (SELECT 'Membership' AS SECTION, emd.* FROM `ohrm_audittrail_pim_emp_member_detail_trail` emd) 
UNION (SELECT 'Job Details' AS SECTION, jtt.* FROM `ohrm_audittrail_pim_job_record_trail` jtt) 
UNION (SELECT 'Immigration' AS SECTION, ppt.* FROM `ohrm_audittrail_pim_passport_trail` ppt) 
UNION (SELECT 'Personal Details' AS SECTION, ppd.* FROM `ohrm_audittrail_pim_personal_details_trail` ppd) 
UNION (SELECT 'Qualification' AS SECTION, pqt.* FROM `ohrm_audittrail_pim_qualification_trail` pqt) 
UNION (SELECT 'Supervisor/Subordinate' AS SECTION, prt.* FROM `ohrm_audittrail_pim_reportto_trail` prt) 
UNION (SELECT 'Salary' AS SECTION, pst.* FROM `ohrm_audittrail_pim_salary_record_trail` pst) 
UNION (SELECT 'Tax Exemptions' AS SECTION, put.* FROM `ohrm_audittrail_pim_us_tax_trail` put)
UNION (SELECT 'Employee' AS SECTION, pet.* FROM `ohrm_audittrail_pim_employee_trail` pet)
UNION (SELECT 'Configure - Custom Field Section' AS SECTION, cfs.* FROM `ohrm_audittrail_pim_custom_field_section_trail` cfs)
UNION (SELECT 'Configure - Custom Field' AS SECTION, cf.* FROM `ohrm_audittrail_pim_custom_field_trail` cf)
UNION (SELECT 'Personal Details Custom Fields' AS SECTION, pdcf.* FROM ohrm_audittrail_pim_personal_custom_field_trail pdcf)
UNION (SELECT 'Contact Custom Fields' AS SECTION, ccf.* FROM ohrm_audittrail_pim_emergency_custom_field_trail ccf)
UNION (SELECT 'Emergency Custom Fields' AS SECTION, ecf.* FROM ohrm_audittrail_pim_contact_custom_field_trail ecf)
UNION (SELECT 'Dependent Custom Fields' AS SECTION, dcf.* FROM ohrm_audittrail_pim_dependents_custom_field_trail dcf)
UNION (SELECT 'Immigration Custom Fields' AS SECTION, icf.* FROM ohrm_audittrail_pim_immigration_custom_field_trail icf)
UNION (SELECT 'Job Custom Fields' AS SECTION, jcf.* FROM ohrm_audittrail_pim_job_custom_field_trail jcf)
UNION (SELECT 'Salary Custom Fields' AS SECTION, scf.* FROM ohrm_audittrail_pim_salary_custom_field_trail scf)
UNION (SELECT 'Supervisor/Subordinate Custom Fields' AS SECTION, sscf.* FROM ohrm_audittrail_pim_reportto_custom_field_trail sscf)
UNION (SELECT 'Qualifications Custom Fields' AS SECTION, qcf.* FROM ohrm_audittrail_pim_qualifications_custom_field_trail qcf)
UNION (SELECT 'Membership Custom Fields' AS SECTION, mcf.* FROM ohrm_audittrail_pim_membership_custom_field_trail mcf)
UNION (SELECT 'Tax Custom Fields' AS SECTION, tcf.* FROM ohrm_audittrail_pim_tax_custom_field_trail tcf);

