CREATE TABLE `tblchange_order_files` (
    `id` BIGINT(20) UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `change_order_id` bigint(20) UNSIGNED DEFAULT NULL,
  `invoice_id` bigint(20) UNSIGNED DEFAULT NULL,
  `file_name` varchar(191) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `description` longtext DEFAULT NULL,
  `filetype` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `visible_to_customer` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `attachment_key` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `external` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `external_link` text CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `thumbnail_link` text CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'For external usage',
  `original_file_name` varchar(191) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `dateadded` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE `tblchange_order_image_files` (
    `id` BIGINT(20) UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL,
  `change_order_id` bigint(20) UNSIGNED DEFAULT NULL,
  `invoice_id` bigint(20) UNSIGNED DEFAULT NULL,
  `file_name` varchar(191) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `description` longtext DEFAULT NULL,
  `filetype` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `visible_to_customer` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `attachment_key` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `external` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `external_link` text CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `thumbnail_link` text CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'For external usage',
  `original_file_name` varchar(191) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `dateadded` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;




INSERT INTO tblapad_options (type, name, value, autoload)
VALUES('change_order_files','allowed_file_extention','{"image":["jpeg","jpg","png","gif"],"video":["mp4","mpeg","webp", "avi"],"audio":[],"document":["pdf","doc","docx","csv","ppt","pptx","xls","xlsx","txt"]}',1),
      ('change_order_files','allowed_file_size','16000',1),
      ('change_order_image_files','allowed_file_extention','{"image": ["jpeg", "jpg", "png", "gif"]}',1),
      ('change_order_image_files','allowed_file_size','16000',1);


INSERT INTO tblplan_features (name, codename, description,type,added_on) 
VALUES('No of Change Order Images', 'no_of_change_order_images_allowed', 'No of Change Order images allowed in plan.','restrict',UTC_TIMESTAMP());

SET @no_of_change_order_images_allowed = LAST_INSERT_ID();

INSERT INTO tblplan_features_value (plans_id, plans_features_id, value,other_data,added_on) 
VALUES(9, @no_of_change_order_images_allowed, 0,'{"outside_message":"If you want to add photos please upgrade to Pro.","inside_message":"If you want to add photos please upgrade to Pro.","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(10, @no_of_change_order_images_allowed, 5,'{"outside_message":"You have limit of 5 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 5 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"5"}',UTC_TIMESTAMP()),
(11, @no_of_change_order_images_allowed, 10,'{"outside_message":"You have limit of 10 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 10 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"10"}',UTC_TIMESTAMP()),
(12, @no_of_change_order_images_allowed, 20,'{"outside_message":"You have limit of 20 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 20 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"","link":"https:\/\/my.contractorplus.app\/","count":"20"}',UTC_TIMESTAMP()),
(13, @no_of_change_order_images_allowed, 0,'{"outside_message":"You have limit of 0 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 0 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(14, @no_of_change_order_images_allowed, 10,'{"outside_message":"You have limit of 10 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 10 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"10"}',UTC_TIMESTAMP()),
(15, @no_of_change_order_images_allowed, 20,'{"outside_message":"You have limit of 20 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 20 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"","link":"https:\/\/my.contractorplus.app\/","count":"20"}',UTC_TIMESTAMP()); 

INSERT INTO tblplan_features (name, codename, description,type,added_on) 
VALUES('No of Change Order Files', 'no_of_change_order_files_allowed', 'No of Change Order files allowed in plan.','restrict',UTC_TIMESTAMP());

SET @no_of_change_order_files_allowed = LAST_INSERT_ID();
INSERT INTO tblplan_features_value (plans_id, plans_features_id, value,other_data,added_on) 
VALUES(9, @no_of_change_order_files_allowed, 0,'{ "outside_message":"If you want to add files please upgrade to Pro.", "inside_message":"If you want to add files please upgrade to Pro.","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(10, @no_of_change_order_files_allowed, 5,'{ "outside_message":"You have limit of 5 files on your plan. If you want to add more please upgrade.", "inside_message":"You have limit of 5 files on your plan, we have selected first {!current_count!} files. If you want to add more please upgrade.", "tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"5"}',UTC_TIMESTAMP()),
(11, @no_of_change_order_files_allowed, 10,'{ "outside_message":"You have limit of 10 files on your plan. If you want to add more please upgrade.", "inside_message":"You have limit of 10 photos on your plan, we have selected first {!current_count!} files. If you want to add more please upgrade.", "tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"10"}',UTC_TIMESTAMP()),
(12, @no_of_change_order_files_allowed, 20,'{ "outside_message":"You have limit of 20 files on your plan. If you want to add more please upgrade.", "inside_message":"You have limit of 20 files on your plan, we have selected first {!current_count!} files. If you want to add more please upgrade.", "tag_color":"#eb0e0e","tag_title":"","link":"https:\/\/my.contractorplus.app\/","count":"20"}',UTC_TIMESTAMP()),
(13, @no_of_change_order_files_allowed, 0,'{"outside_message":"You have limit of 0 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 0 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(14, @no_of_change_order_files_allowed, 10,'{"outside_message":"You have limit of 10 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 10 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"UPGRADE","link":"https:\/\/my.contractorplus.app\/","count":"10"}',UTC_TIMESTAMP()),
(15, @no_of_change_order_files_allowed, 20,'{"outside_message":"You have limit of 20 photos on your plan. If you want to add more please upgrade.","inside_message":"You have limit of 20 photos on your plan, we have selected first {!current_count!} photos. If you want to add more please upgrade.","tag_color":"#eb0e0e","tag_title":"","link":"https:\/\/my.contractorplus.app\/","count":"20"}',UTC_TIMESTAMP()); 



UPDATE tblstaff SET refresh_permissions = 1;