
CREATE TABLE IF NOT EXISTS `tblclient_app_usage_data` (
  `id` varchar(191) NOT NULL,
  `tenant_id` bigint(20) UNSIGNED NOT NULL,
  `client_id` bigint(20) UNSIGNED NOT NULL,
  `token` varchar(300) NOT NULL,
  `added_on` datetime NOT NULL,
  `last_used_on` datetime NOT NULL,
  `device_info` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `idx_tenant_id` (`tenant_id`),
  INDEX `idx_client_id` (`client_id`),
  INDEX `idx_token` (`token`),
  INDEX `idx_added_on` (`added_on`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


INSERT INTO `tblapad_emailtemplates` (`emailtemplateid`, `type`, `slug`, `language`, `name`, `subject`, `message`, `fromname`, `fromemail`, `plaintext`, `active`, `order`, `is_tenant_email_config_allowed`, `is_tenant`) VALUES (NULL, 'client', 'invite-to-client-portal', 'english', 'Invite Client to Portal', '{subject}', '<p style=\"font-size: 12pt\">Hello {client_name},</p><p style=\"font-size: 12pt\">You\'ve been invited to log in to our Client Portal.</p><p style=\"font-size: 12pt\">The Client Portal is a self-service online experience where you can access your account details. Log in at any time to view things like recent Requests, Estimates, Invoices, Payments, and much more.</p><br /><br /><div class=\"o_col_i\" style=\"vertical-align: top\"><div class=\"o_px-xs\" style=\"padding-left: 8px; padding-right: 8px\"><table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" role=\"presentation\"><tbody><tr><td class=\"o_btn o_bg-primary o_br o_heading o_text\" align=\"center\" style=\"font-family: Helvetica, Arial, sans-serif; font-weight: bold; margin-top: 0px; margin-bottom: 0px; font-size: 16px; line-height: 24px; mso-padding-alt: 12px 24px; background-color: #c81e1e; border-radius: 4px\"><a class=\"o_text-white\" href=\"{invite_url}\" style=\"color: #ffffff !important; text-decoration: none; outline: none; color: #ffffff; display: block; padding: 12px 24px; mso-text-raise: 3px\">Log in to Client Portal</a></td></tr></tbody></table></div></div><br /><span style=\"font-size: 12pt\"><b>What is Contractor+?</b></span><br /><span style=\"font-size: 12pt\">Contractor+ is a complete field service management app solution that helps you manage your client relationships and work productively as a team. All your Estimates, Invoices, Client Contracts, Post-Inspections, and everything else you need to run your business is accessible on one dashboard, like it should be. <a href=\"{cp_website}\">Learn More About Contractor+.</a></span>', '', NULL, '0', '1', '0', '0', '0');

ALTER TABLE `tblclient_app_usage_data` ADD `expire_in_days` INT NOT NULL DEFAULT '1' AFTER `device_info`;


INSERT INTO tblplan_features (name, codename, description,type,is_highlight,added_on) 
VALUES('Client Portal', 'client_portal_module', 'Client Portal','restrict',1,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":"Client Portal is an ultimate feature, in order to use it Upgrade to ULTIMATE","inside_message":"Client Portal 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":"Client Portal is an ultimate feature, in order to use it Upgrade to ULTIMATE","inside_message":"Client Portal 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":"Client Portal is an ultimate feature, in order to use it Upgrade to ULTIMATE","inside_message":"Client Portal 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":"Client Portal is an ultimate feature, in order to use it Upgrade to ULTIMATE","inside_message":"Client Portal 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":"Client Portal is an ultimate feature, in order to use it Upgrade to ULTIMATE","inside_message":"Client Portal 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());

UPDATE tblstaff SET refresh_permissions = 1;


-- Recaptcha Options

INSERT INTO `tblapad_options` (`id`, `type`, `name`, `value`, `autoload`) VALUES (NULL, NULL, 'client_portal_recaptcha_site_key', '6Le0y2wpAAAAAOrxPMrSgWc4Ru9ttiAPHrFG1J_R', '1'), (NULL, NULL, 'client_portal_recaptcha_secret_key', '6Le0y2wpAAAAABQ2eyHsK2x-UQ5Hefn3oyNPUbvt', '1')