ALTER TABLE `permissions` 
CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT ,
ADD PRIMARY KEY (`id`);
;


ALTER TABLE `enquiries` 
DROP FOREIGN KEY `enquiries_ibfk_1`;
ALTER TABLE `enquiries` 
ADD CONSTRAINT `enquiries_ibfk_1`
  FOREIGN KEY (`office_id`)
  REFERENCES `office` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION;


ALTER TABLE `enquiries` 
DROP FOREIGN KEY `enquiries_ibfk_2`,
DROP FOREIGN KEY `enquiries_ibfk_3`,
DROP FOREIGN KEY `enquiries_ibfk_4`,
DROP FOREIGN KEY `enquiries_ibfk_5`;
ALTER TABLE `enquiries` 
ADD CONSTRAINT `enquiries_ibfk_2`
  FOREIGN KEY (`cat_one_id`)
  REFERENCES `category_level_one` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION,
ADD CONSTRAINT `enquiries_ibfk_3`
  FOREIGN KEY (`cat_two_id`)
  REFERENCES `category_level_two` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION,
ADD CONSTRAINT `enquiries_ibfk_4`
  FOREIGN KEY (`cat_three_id`)
  REFERENCES `category_level_three` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION,
ADD CONSTRAINT `enquiries_ibfk_5`
  FOREIGN KEY (`cat_four_id`)
  REFERENCES `category_level_four` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION;


ALTER TABLE `follow_up` 
ADD CONSTRAINT `enq_id_fk`
  FOREIGN KEY (`id`)
  REFERENCES `enquiries` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION;


ALTER TABLE `follow_up_products` 
ADD CONSTRAINT `follow_up_fk_id`
  FOREIGN KEY (`follow_up_id`)
  REFERENCES `follow_up` (`id`)
  ON DELETE CASCADE
  ON UPDATE NO ACTION;


ALTER TABLE follow_up ADD location JSON;

DROP TABLE user_location ;
CREATE TABLE user_location (id INT NOT NULL PRIMARY KEY auto_increment, user_id INT, location JSON, at_time TEXT);

ALTER TABLE permissions ADD location_report BOOL;


ALTER TABLE follow_up ADD dial_start_time DATETIME;
ALTER TABLE follow_up ADD dial_end_time DATETIME;

ALTER TABLE products ADD quantity INT, ADD supplier VARCHAR(255);

CREATE TABLE product_recevings (id int not null primary key auto_increment, quantity INT, date_recevings TEXT, product_id INT);

DROP TABLE product_service_charges ;
CREATE TABLE product_service_charges (id int not null primary key auto_increment, range_start INT, range_end INT, unit_price INT, product_id INT, unit varchar(50));

DROP TABLE config_kpis;
CREATE TABLE config_kpis (id INT NOT NULL PRIMARY KEY auto_increment, kpi_name varchar(255), description_kpis VARCHAR(500), weight INT, qualifying_criteria INT, on_report BOOL DEFAULT 0);
SELECT * FROM config_kpis;
INSERT INTO config_kpis (description_kpis, weight, qualifying_criteria, kpi_name) VALUES ("Measures how effectively the BDE/TSE utilizes CRM tools to manage leads, track interactions, and update client information.", 10, 5, "1.	CRM Utilization Rate");



-- -------------------------
alter table users add sf_user int;
alter table organization add category_levels int;
alter table organization add category_one_name varchar(50);
alter table organization add category_two_name varchar(50);
alter table organization add category_three_name varchar(50);
alter table organization add category_four_name varchar(50);
alter table organization add customer_name varchar(50);
alter table organization add products boolean;
alter table organization add enquiry_name varchar(50);
alter table organization add enquiries_name varchar(50);
alter table organization add enquiry_name varchar(50);
alter table organization add office_name varchar(50);


