-- Default Taxes 
ALTER TABLE `tbltaxes` ADD `is_default` TINYINT(1) NOT NULL DEFAULT '0' AFTER `taxrate`;
ALTER TABLE `tbltaxes_static` ADD `is_default` TINYINT(1) NOT NULL DEFAULT '1' AFTER `taxrate`;

-- Tool Library 

ALTER TABLE tbltools MODIFY COLUMN tool_type ENUM('single_tool','tool_set','equipment','fleet_vehicle') NOT NULL DEFAULT 'single_tool';
   
ALTER TABLE tbltools ADD description text DEFAULT NULL AFTER name;

ALTER TABLE tbltools ADD asset_vin varchar(100) DEFAULT NULL AFTER description;

ALTER TABLE tbltools ADD purchase_price decimal(15,2) NOT NULL DEFAULT 0.00 AFTER asset_vin;

ALTER TABLE tbltools ADD purchase_date date DEFAULT NULL AFTER purchase_price;

ALTER TABLE tbltools ADD unit varchar(191) DEFAULT 'fixed_price' AFTER purchase_date;

ALTER TABLE tbltools MODIFY COLUMN price decimal(15,2) DEFAULT 0.00;

-- Estimate/Invoice/Change Order V2
ALTER TABLE tblestimate_tasks ADD task_type ENUM('line_item','material','equipment','text') DEFAULT 'line_item' AFTER title;
ALTER TABLE tblinvoice_tasks ADD task_type ENUM('line_item','material','equipment','text') DEFAULT 'line_item' AFTER title;
ALTER TABLE tblchange_order_tasks ADD task_type ENUM('line_item','material','equipment','text') DEFAULT 'line_item' AFTER title;

ALTER TABLE tblestimate_tasks ADD is_ratio_lock TINYINT(1) NOT NULL DEFAULT 0 AFTER task_type;
ALTER TABLE tblinvoice_tasks ADD is_ratio_lock TINYINT(1) NOT NULL DEFAULT 0 AFTER task_type;
ALTER TABLE tblchange_order_tasks ADD is_ratio_lock TINYINT(1) NOT NULL DEFAULT 0 AFTER task_type;

ALTER TABLE tblestimate_supplies ADD is_ratio_lock TINYINT(1) NOT NULL DEFAULT 0 AFTER TYPE;
ALTER TABLE tblinvoice_supplies ADD is_ratio_lock TINYINT(1) NOT NULL DEFAULT 0 AFTER TYPE;
ALTER TABLE tblchange_order_supplies ADD is_ratio_lock TINYINT(1) NOT NULL DEFAULT 0 AFTER TYPE;

ALTER TABLE tblestimate_tasks ADD is_round_off_ratio TINYINT(1) NOT NULL DEFAULT 0 AFTER is_ratio_lock;
ALTER TABLE tblinvoice_tasks ADD is_round_off_ratio TINYINT(1) NOT NULL DEFAULT 0 AFTER is_ratio_lock;
ALTER TABLE tblchange_order_tasks ADD is_round_off_ratio TINYINT(1) NOT NULL DEFAULT 0 AFTER is_ratio_lock;

ALTER TABLE tblestimate_tasks ADD is_optional TINYINT(1) NOT NULL DEFAULT 0 AFTER task_type;
ALTER TABLE tblestimate_tasks ADD is_recommended TINYINT(1) NOT NULL DEFAULT 0 AFTER task_type;
ALTER TABLE tblestimate_tasks ADD is_optional_selected TINYINT(1) DEFAULT NULL AFTER is_optional;

ALTER TABLE tblestimates ADD is_multi_optional TINYINT(1) NOT NULL DEFAULT 0 AFTER is_grouping_on;
ALTER TABLE tblestimate_groups ADD is_multi_optional TINYINT(1) NOT NULL DEFAULT 0 AFTER name;

-- Permissions 
INSERT INTO tblplan_features (name, codename, description,type,added_on) 
VALUES('Ratio Lock', 'ratio_lock_allowed', 'Ratio Lock','restrict',UTC_TIMESTAMP());

SET @plans_features_id = LAST_INSERT_ID();
INSERT INTO tblplan_features_value (plans_id, plans_features_id, value,other_data,added_on) 
VALUES(9, @plans_features_id, 0,'{"outside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(10, @plans_features_id, 0,'{"outside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(11, @plans_features_id, 0,'{"outside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(12, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(13, @plans_features_id, 0,'{"outside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(14, @plans_features_id, 0,'{"outside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"Ratio Lock is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(15, @plans_features_id, 1,NULL,UTC_TIMESTAMP());

INSERT INTO tblplan_features (name, codename, description,type,added_on) 
VALUES('AI Based Description', 'ai_based_description_allowed', 'AI Based Description','restrict',UTC_TIMESTAMP());

SET @plans_features_id = LAST_INSERT_ID();
INSERT INTO tblplan_features_value (plans_id, plans_features_id, value,other_data,added_on) 
VALUES(9, @plans_features_id, 0,'{"outside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(10, @plans_features_id, 0,'{"outside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(11, @plans_features_id, 0,'{"outside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(12, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(13, @plans_features_id, 0,'{"outside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(14, @plans_features_id, 0,'{"outside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","inside_message":"AI Based Description is an ULTIMATE feature, In order to use it Upgrade to ULTIMATE","tag_color":"#eb0e0e","tag_title":"ULTIMATE","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(15, @plans_features_id, 1,NULL,UTC_TIMESTAMP());


-- Estimate Refer As Settings 
INSERT INTO tbloptions_static (name, value, autoload) VALUES('estimate_refer_as', 'estimate', 1);

INSERT INTO tbloptions (tenant_id, name, value, autoload)
SELECT t.id,s.name,s.value,s.autoload
FROM tbltenants t
JOIN tbloptions_static s ON 1 = 1 AND s.name in('estimate_refer_as');


INSERT INTO `tblplan_features` (`name`, `codename`, `description`, `type`, `added_on`) VALUES ('Estimate Refer As', 'estimate_refer_as', 'Refer to Quote as Estimate in PDFs, client hub and customer communications', 'restrict', NOW());
SET @estimate_refer_as  = LAST_INSERT_ID();
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('9', @estimate_refer_as , '0', UTC_TIMESTAMP());
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('10', @estimate_refer_as , '1', UTC_TIMESTAMP());
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('11', @estimate_refer_as , '1', UTC_TIMESTAMP());
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('12', @estimate_refer_as , '1', UTC_TIMESTAMP());
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('13', @estimate_refer_as , '0', UTC_TIMESTAMP());
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('14', @estimate_refer_as , '1', UTC_TIMESTAMP());
INSERT INTO `tblplan_features_value` (`plans_id`, `plans_features_id`, `value`, `added_on`) VALUES ('15', @estimate_refer_as , '1', UTC_TIMESTAMP());

-- Work Order V2
ALTER TABLE tblwork_orders ADD is_grouping_on TINYINT(1) NOT NULL DEFAULT 0 AFTER title;

CREATE TABLE IF NOT EXISTS `tblwork_order_groups` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint(20) unsigned NOT NULL,
  `work_order_id` bigint(20) unsigned NOT NULL,  
  `name` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
  `datecreated` datetime NOT NULL,
  `item_order` bigint(20) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `tenant_id` (`tenant_id`),
  KEY `work_order_id` (`work_order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE IF NOT EXISTS `tblwork_order_tasks` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint(20) unsigned NOT NULL,
  `work_order_id` bigint(20) unsigned NOT NULL,
  `group_id` bigint(20) DEFAULT NULL,  
  `task_type` enum('line_item','material','equipment','text') DEFAULT 'line_item',
  `title` varchar(200) COLLATE utf8_general_ci DEFAULT NULL,
  `description` text COLLATE utf8_general_ci DEFAULT NULL,
  `comment` text COLLATE utf8_general_ci DEFAULT NULL,
  `quantity` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT 'Quantity',
  `rate` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT 'Rate',
  `unit` varchar(191) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'hour',
  `datecreated` datetime NOT NULL,
  `item_order` bigint(20) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `tenant_id` (`tenant_id`),
  KEY `work_order_id` (`work_order_id`),
  KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

CREATE TABLE IF NOT EXISTS `tblwork_order_supplies` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `tenant_id` BIGINT(20) UNSIGNED NOT NULL,
  `work_order_id` BIGINT(20) UNSIGNED NOT NULL,
  `group_id` BIGINT(20) DEFAULT NULL, 
  `task_id` BIGINT(20) DEFAULT NULL,    
  `cp_supply_id` BIGINT(20) UNSIGNED DEFAULT NULL,
  `my_supply_id` BIGINT(20) UNSIGNED DEFAULT NULL,
  `type` ENUM('my_supply','cp_supply','local_pricing','my_local_supply') COLLATE utf8_unicode_ci DEFAULT NULL,
  `name` VARCHAR(191) COLLATE utf8_unicode_ci NOT NULL,
  `source_product_sku` VARCHAR(500) COLLATE utf8_unicode_ci DEFAULT NULL,
  `product_upc` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL,
  `image` VARCHAR(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `image_url` VARCHAR(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `product_url` VARCHAR(800) COLLATE utf8_unicode_ci DEFAULT NULL,
  `category_id` BIGINT(20) UNSIGNED DEFAULT NULL,
  `category_name` VARCHAR(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `supplier_id` BIGINT(20) UNSIGNED DEFAULT NULL,
  `supplier_name` VARCHAR(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `supplier_image` VARCHAR(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `tag` VARCHAR(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `price` DECIMAL(15,2) DEFAULT 0.00,
  `quantity` BIGINT(20) UNSIGNED NOT NULL,
  `uom` varchar(191) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'unit',
  `markup_total` DECIMAL(15,2) DEFAULT 0.00 ,
  `supply_total_price` DECIMAL(15,2) NOT NULL,
  `dateadded` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `item_order` BIGINT(20) UNSIGNED NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `tenant_id` (`tenant_id`),
  KEY `work_order_id` (`work_order_id`),
  KEY `group_id` (`group_id`),
  KEY `task_id` (`task_id`),
  KEY `cp_supply_id` (`cp_supply_id`),
  KEY `my_supply_id` (`my_supply_id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

CREATE TABLE IF NOT EXISTS `tblwork_order_task_files` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint(20) unsigned NOT NULL,
  `work_order_id` bigint(20) unsigned NOT NULL,
  `task_id` bigint(20) NOT NULL,
  `file_name` varchar(191) COLLATE utf8_unicode_ci NOT NULL,
  `filetype` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
  `task_file_type` enum('pre_photos','post_photos') COLLATE utf8_unicode_ci DEFAULT NULL,
  `visible_to_customer` bigint(20) unsigned NOT NULL DEFAULT 0,
  `attachment_key` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `external` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
  `external_link` text COLLATE utf8_unicode_ci DEFAULT NULL,
  `thumbnail_link` text COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'For external usage',
  `original_file_name` varchar(191) COLLATE utf8_unicode_ci DEFAULT NULL,
  `dateadded` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `tenant_id` (`tenant_id`),
  KEY `work_order_id` (`work_order_id`),
  KEY `task_id` (`task_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


INSERT INTO `tblapad_options`
  (`type`, `name`, `value`, `autoload`)
  VALUES ('hybrid_work_orders', 'allowed_file_extention', '{"image":["jpeg","jpg","png","gif","webp"],"video":[],"audio":[],"document":[]}', 1),
  ('hybrid_work_orders', 'allowed_file_size', '16000', 1),
  ('hybrid_work_orders', 'total_file_count', '10', 1),
  ('hybrid_work_orders', 'allowed_file_count', '10', 1);

 -- Permit Related Queries

ALTER TABLE tblestimate_tasks MODIFY COLUMN task_type ENUM('line_item','material','equipment','text','permit') DEFAULT 'line_item';
ALTER TABLE tblinvoice_tasks MODIFY COLUMN task_type ENUM('line_item','material','equipment','text','permit') DEFAULT 'line_item';
ALTER TABLE tblchange_order_tasks MODIFY COLUMN task_type ENUM('line_item','material','equipment','text','permit') DEFAULT 'line_item';

CREATE TABLE IF NOT EXISTS tblpermits_static (
    id          bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    title        varchar(191)        NOT NULL,
    description text DEFAULT NULL,
    price decimal(15,2) NOT NULL DEFAULT '0.00',
    PRIMARY KEY (id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8;

CREATE TABLE IF NOT EXISTS tblpermits (   
    id          BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    tenant_id   BIGINT(20) UNSIGNED NOT NULL DEFAULT 1,
    title       VARCHAR(191) NOT NULL,
    description TEXT DEFAULT NULL,
    price DECIMAL(15,2) NOT NULL DEFAULT '0.00',
    added_by   BIGINT(20) UNSIGNED NOT NULL,
    updated_by BIGINT(20) UNSIGNED NOT NULL,
    added_on   DATETIME   NOT NULL,
    updated_on DATETIME   NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (tenant_id) REFERENCES tbltenants(id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = INNODB DEFAULT CHARSET = utf8;


INSERT INTO tblpermits_static(title, description)
VALUES  ('Building Permit', 'A building permit is required for new construction projects, significant additions, or major alterations to existing structures. This ensures that your project complies with local building codes and safety standards. We\'ll pull the necessary permits for this phase of the project.'),
        ('Electrical Permit', 'An electrical permit is necessary for any electrical work, including new installations, upgrades, or modifications to existing electrical systems. This permit guarantees that electrical work meets safety regulations. We\'ll pull the necessary permits for this phase of the project.'),
        ('Plumbing Permit', 'For any plumbing installations, repairs, or modifications, a plumbing permit is required. This ensures that all plumbing work adheres to the appropriate codes and standards. We\'ll pull the necessary permits for this phase of the project.'),
        ('Mechanical Permit', 'A mechanical permit is needed for installing, repairing, or altering HVAC systems. This ensures that heating, ventilation, and air conditioning work meets safety and efficiency standards. We\'ll pull the necessary permits for this phase of the project.'),
        ('Demolition Permit', 'Before demolishing any structure or part of a structure, a demolition permit is required. This permit ensures that the demolition process is conducted safely and in compliance with regulations. We\'ll pull the necessary permits for this phase of the project.'),
        ('Roofing Permit', 'For new roofing installations or major roof repairs and replacements, a roofing permit is required. This ensures that all roofing work meets local building codes and safety standards. We\'ll pull the necessary permits for this phase of the project.'),
        ('Foundation Permit', 'A foundation permit is necessary for laying or altering the foundation of a building. This ensures that the foundation work is structurally sound and complies with building regulations. We\'ll pull the necessary permits for this phase of the project.'),
        ('Sign Permit', 'Installing or altering signs on a property requires a sign permit. This ensures that the signage meets local zoning and safety regulations. We\'ll pull the necessary permits for this phase of the project.'),
        ('Fence Permit', 'For building or modifying fences on your property, a fence permit is required. This ensures that the fence complies with local height and boundary regulations. We\'ll pull the necessary permits for this phase of the project.'),
        ('Pool/Spa Permit', 'A pool/spa permit is necessary for installing or modifying swimming pools and spas. This ensures that these installations meet safety and health standards. We\'ll pull the necessary permits for this phase of the project.'),
        ('Grading Permit', 'A grading permit is required for any land grading or earthmoving activities. This ensures that the grading work complies with local regulations and does not negatively impact the environment. We\'ll pull the necessary permits for this phase of the project.'),
        ('Landscaping Permit', 'For significant landscaping projects, a landscaping permit may be required. This ensures that the landscaping work adheres to local regulations, especially those affecting water usage or drainage. We\'ll pull the necessary permits for this phase of the project.'),
        ('Solar Permit', 'Installing solar panels or other solar energy systems requires a solar permit. This ensures that the installation meets local codes and safety standards. We\'ll pull the necessary permits for this phase of the project.'),
        ('Fire Protection Permit', 'A fire protection permit is necessary for installing or modifying fire protection systems like sprinklers or alarms. This ensures that fire safety measures are up to code. We\'ll pull the necessary permits for this phase of the project.'),
        ('Temporary Structure Permit', 'For erecting temporary structures such as tents or stages for events, a temporary structure permit is required. This ensures that temporary installations are safe and comply with regulations. We\'ll pull the necessary permits for this phase of the project.'),
        ('Occupancy Permit', 'Before occupying a new building or space after construction or major renovations, an occupancy permit is required. This confirms that the space is safe and ready for use. We\'ll pull the necessary permits for this phase of the project.'),  
        ('Environmental Permit', 'Projects that might impact the environment require an environmental permit. This ensures that the project complies with environmental protection regulations. We\'ll pull the necessary permits for this phase of the project.'),  
        ('Zoning Permit', 'A zoning permit ensures that your construction project complies with local zoning regulations. This permit is required to ensure that land use is consistent with community plans. We\'ll pull the necessary permits for this phase of the project.'),  
        ('Historic Preservation Permit', 'For any work on properties designated as historic or located in a historic district, a historic preservation permit is required. This ensures that changes respect the historical significance of the property. We\'ll pull the necessary permits for this phase of the project.'),  
        ('Septic System Permit', 'Installing or modifying septic systems requires a septic system permit. This ensures that the septic system is designed and installed to code, protecting public health and the environment. We\'ll pull the necessary permits for this phase of the project.');

INSERT INTO tblpermits(tenant_id, title, description,added_by,updated_by,added_on,updated_on)
SELECT t.id, a.title, a.description, s.staffid, s.staffid, UTC_TIMESTAMP(),UTC_TIMESTAMP()
FROM tblpermits_static a
CROSS JOIN tbltenants t
JOIN tblstaff s ON s.tenant_id = t.id AND s.is_tenant = 1
ORDER BY t.id,a.id;

-- Update Tax Type as for_item for all Tenants
UPDATE tbloptions SET VALUE = 'for_item' WHERE NAME = 'default_invoice_tax_type' ;

UPDATE tbloptions SET VALUE = 'for_item' WHERE NAME = 'default_estimate_tax_type' ;


--- Optional Line Items Feature
INSERT INTO tblplan_features (name, codename, description,type,added_on) 
VALUES('Optional Line Items', 'optional_line_items_allowed', 'Optional Line Items','restrict',UTC_TIMESTAMP());

SET @plans_features_id = LAST_INSERT_ID();
INSERT INTO tblplan_features_value (plans_id, plans_features_id, value,other_data,added_on) 
VALUES(9, @plans_features_id, 0,'{"outside_message":"Optional Line Items is a PRO feature, In order to use it Upgrade to PRO","inside_message":"Optional Line Items is a PRO feature, In order to use it Upgrade to PRO","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(10, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(11, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(12, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(13, @plans_features_id, 0,'{"outside_message":"Optional Line Items is a PRO feature, In order to use it Upgrade to PRO","inside_message":"Optional Line Items is a PRO feature, In order to use it Upgrade to PRO","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(14, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(15, @plans_features_id, 1,NULL,UTC_TIMESTAMP());


-- Permits Feature
INSERT INTO tblplan_features (name, codename, description,type,added_on) 
VALUES('Permits', 'permits_allowed', 'Permits','restrict',UTC_TIMESTAMP());

SET @plans_features_id = LAST_INSERT_ID();
INSERT INTO tblplan_features_value (plans_id, plans_features_id, value,other_data,added_on) 
VALUES(9, @plans_features_id, 0,'{"outside_message":"Permits is a PRO feature, In order to use it Upgrade to PRO","inside_message":"Permits is a PRO feature, In order to use it Upgrade to PRO","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(10, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(11, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(12, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(13, @plans_features_id, 0,'{"outside_message":"Permits is a PRO feature, In order to use it Upgrade to PRO","inside_message":"Permits is a PRO feature, In order to use it Upgrade to PRO","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}',UTC_TIMESTAMP()),
(14, @plans_features_id, 1,NULL,UTC_TIMESTAMP()),
(15, @plans_features_id, 1,NULL,UTC_TIMESTAMP());


-- Tool & Equipment Feature
UPDATE tblplan_features_value SET VALUE = 0 , other_data = '{"outside_message":"Tool & Equipment is a PRO feature, In order to use it Upgrade to PRO","inside_message":"Tool & Equipment is a PRO feature, In order to use it Upgrade to PRO","tag_color":"#eb0e0e","tag_title":"PRO","link":"https:\/\/my.contractorplus.app\/","count":"0"}'
WHERE plans_features_id = 9 AND plans_id IN (13,9);


UPDATE `tbltools`  SET unit = 'fixed_price' WHERE IFNULL(unit,'') = '';





