CREATE TABLE `mymdt_reg_vehicle_damages` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `vehicle_id` INT NOT NULL DEFAULT 0,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT '',
  `content` TEXT NULL,
  `exhaust_system` TINYINT(1) NOT NULL DEFAULT 0,
  `front_bumper` TINYINT(1) NOT NULL DEFAULT 0,
  `front_grill` TINYINT(1) NOT NULL DEFAULT 0,
  `bonnet` TINYINT(1) NOT NULL DEFAULT 0,
  `roof` TINYINT(1) NOT NULL DEFAULT 0,
  `front_right_mudguard` TINYINT(1) NOT NULL DEFAULT 0,
  `front_left_mudguard` TINYINT(1) NOT NULL DEFAULT 0,
  `right_rear_panel` TINYINT(1) NOT NULL DEFAULT 0,
  `left_rear_panel` TINYINT(1) NOT NULL DEFAULT 0,
  `left_under_trim` TINYINT(1) NOT NULL DEFAULT 0,
  `right_under_trim` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_panel` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_bumper` TINYINT(1) NOT NULL DEFAULT 0,
  `front_left_headlight` TINYINT(1) NOT NULL DEFAULT 0,
  `front_right_headlight` TINYINT(1) NOT NULL DEFAULT 0,
  `right_rear_light` TINYINT(1) NOT NULL DEFAULT 0,
  `left_rear_light` TINYINT(1) NOT NULL DEFAULT 0,
  `right_window_01` TINYINT(1) NOT NULL DEFAULT 0,
  `right_window_02` TINYINT(1) NOT NULL DEFAULT 0,
  `right_window_03` TINYINT(1) NOT NULL DEFAULT 0,
  `left_window_01` TINYINT(1) NOT NULL DEFAULT 0,
  `left_window_02` TINYINT(1) NOT NULL DEFAULT 0,
  `left_window_03` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_window` TINYINT(1) NOT NULL DEFAULT 0,
  `windscreen` TINYINT(1) NOT NULL DEFAULT 0,
  `right_door_01` TINYINT(1) NOT NULL DEFAULT 0,
  `right_door_02` TINYINT(1) NOT NULL DEFAULT 0,
  `left_door_01` TINYINT(1) NOT NULL DEFAULT 0,
  `left_door_02` TINYINT(1) NOT NULL DEFAULT 0,
  `right_front_tyre` TINYINT(1) NOT NULL DEFAULT 0,
  `right_rear_tyre` TINYINT(1) NOT NULL DEFAULT 0,
  `left_front_tyre` TINYINT(1) NOT NULL DEFAULT 0,
  `left_rear_tyre` TINYINT(1) NOT NULL DEFAULT 0,
  `right_front_rim` TINYINT(1) NOT NULL DEFAULT 0,
  `right_rear_rim` TINYINT(1) NOT NULL DEFAULT 0,
  `left_front_rim` TINYINT(1) NOT NULL DEFAULT 0,
  `left_rear_rim` TINYINT(1) NOT NULL DEFAULT 0,
  `repaired` TINYINT(1) NOT NULL DEFAULT 0,
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`id`));

CREATE TABLE `mymdt_reg_vehicle_motdata` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `vehicle_id` INT NOT NULL,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT '',
  `headlights` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_lights` TINYINT(1) NOT NULL DEFAULT 0,
  `indicators` TINYINT(1) NOT NULL DEFAULT 0,
  `front_brakes` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_brakes` TINYINT(1) NOT NULL DEFAULT 0,
  `front_tyres` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_tyres` TINYINT(1) NOT NULL DEFAULT 0,
  `windscreen` TINYINT(1) NOT NULL DEFAULT 0,
  `rear_window` TINYINT(1) NOT NULL DEFAULT 0,
  `side_windows` TINYINT(1) NOT NULL DEFAULT 0,
  `horn` TINYINT(1) NOT NULL DEFAULT 0,
  `exhaust_system` TINYINT(1) NOT NULL DEFAULT 0,
  `engine` TINYINT(1) NOT NULL DEFAULT 0,
  `bodywork` TINYINT(1) NOT NULL DEFAULT 0,
  `passed` TINYINT(1) NOT NULL DEFAULT 0,
  `note` TEXT NULL,
  `old_mot` VARCHAR(90) NOT NULL DEFAULT '',
  `new_mot` VARCHAR(90) NOT NULL DEFAULT '',
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`id`));


CREATE TABLE `mymdt_reg_vehicle_part_acceptance_head` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `unique_id` varchar(90) NOT NULL DEFAULT '',
  `vehicle_id` int(11) NOT NULL DEFAULT 0,
  `fromsystem` varchar(50) NOT NULL DEFAULT '',
  `content` text DEFAULT NULL,
  `total_price` INT DEFAULT 0 NOT NULL,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
PRIMARY KEY (`fromsystem`, `unique_id`));

CREATE TABLE `mymdt_reg_vehicle_part_acceptance_pos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` varchar(50) NOT NULL DEFAULT '',
  `head_unique_id` varchar(90) NOT NULL DEFAULT '',
  `part_acceptance_id` INT NOT NULL DEFAULT -1,
  `price` INT DEFAULT 0 NOT NULL,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`));

CREATE TABLE `mymdt_pricelist_groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` varchar(50) NOT NULL DEFAULT '',
  `name` varchar(512) NOT NULL DEFAULT '',
  `deleted` tinyint(1) NOT NULL DEFAULT 0,
  `createdby` varchar(90) NOT NULL DEFAULT '',
  `createddate` timestamp NOT NULL DEFAULT current_timestamp(),
  `changedby` varchar(90) NOT NULL DEFAULT '',
  `changeddate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`));


CREATE TABLE `mymdt_pricelist` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT '',
  `pricelist_group_id` INT NOT NULL DEFAULT -1,
  `description` TEXT NULL,
  `price` INT NOT NULL DEFAULT 0,
  `max_discount` INT NOT NULL DEFAULT 0,
  `deleted` TINYINT(1) NOT NULL DEFAULT 0,
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`id`));

CREATE TABLE `mymdt_tuning_options` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `fromsystem` VARCHAR(50) NOT NULL DEFAULT '',
  `name` VARCHAR(512) NOT NULL DEFAULT '',
  `price` int NOT NULL DEFAULT 0,
  `deleted` TINYINT(1) NOT NULL DEFAULT 0,
  `createdby` VARCHAR(90) NOT NULL DEFAULT '',
  `createddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `changedby` VARCHAR(90) NOT NULL DEFAULT '',
  `changeddate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`id`));


INSERT INTO `myemergency_possible_rights` (`fromsystem`, `right_key`, `sortorder`) VALUES 
('mechanic','files.view',1000),
('mechanic','files.edit',1010),
('mechanic','files.delete',1020),
('mechanic','regvehicles.view',2000),
('mechanic','regvehicles.edit',2010),
('mechanic','regvehicles.delete',2020),
('mechanic','regvehicles_mot.view',3000),
('mechanic','regvehicles_mot.add',3010),
('mechanic','regvehicles_orders.view',4000),
('mechanic','regvehicles_orders.add',4010),
('mechanic','regvehicles_parts_registered.view',5000),
('mechanic','regvehicles_parts_registered.add',5010),
('mechanic','regvehicles_parts_registered.delete',5020),
('mechanic','regvehicles_damage_reports.view',6000),
('mechanic','regvehicles_damage_reports.add',6010),
('mechanic','employees.view',7000),
('mechanic','employees.edit',7010),
('mechanic','employees.suspend',7020),
('mechanic','employeesentries.view',8000),
('mechanic','employeesentries.edit',8010),
('mechanic','employeesentries.delete',8020),
('mechanic','employeesentries.finish',8030),
('mechanic','trainings.view',9000),
('mechanic','trainings.edit',9010),
('mechanic','trainings.delete',9020),
('mechanic','trainingsemployees.view',10000),
('mechanic','trainingsemployees.edit',10010),
('mechanic','missionreport.view',11000),
('mechanic','missionreport.edit',11010),
('mechanic','missionreport.delete',11020),
('mechanic','missionreport.viewall',11030),
('mechanic','radiostate.edit',12000),
('mechanic','radiostate.delete',12010),
('mechanic','emergencyvehicle.view',13000),
('mechanic','emergencyvehicle.delete',13010),
('mechanic','controlcentre.view',14000),
('mechanic','controlcentre.take',14010),
('mechanic','pricelists.view',15000),
('mechanic','pricelists.edit',15010),
('mechanic','pricelists.delete',15020),
('mechanic','parts_acceptance.view',16000),
('mechanic','parts_acceptance.edit',16010),
('mechanic','parts_acceptance.delete',16020),
('mechanic','notes.edit',17000),
('mechanic','notes.delete',17010)
;