-- anna 20/03/2020
--

INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('MEETING_MAINTAIN', 'Meeting', 'Maintain Meeting');
INSERT INTO `tbmsdb`.`users_authorities` (`userId`, `authority`) VALUES ('1', 'MEETING_MAINTAIN');
ALTER TABLE `tbmsdb`.`meeting` CHANGE COLUMN `datetime` `date` DATE NOT NULL ;

-- anna 23/03/2020
--
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('ORDER_MAINTAIN', 'order', 'Maintain order');
UPDATE `tbmsdb`.`authorities` SET `module`='customer' WHERE `authority`='CUSTOMER_MAINTAIN';
UPDATE `tbmsdb`.`authorities` SET `module`='meeting' WHERE `authority`='MEETING_MAINTAIN';
INSERT INTO `tbmsdb`.`users_authorities` (`userId`, `authority`) VALUES ('1', 'ORDER_MAINTAIN');
ALTER TABLE `tbmsdb`.`order` RENAME TO  `tbmsdb`.`orders` ;

-- anna 31/03/2020
--

ALTER TABLE `tbmsdb`.`orders` 
ADD COLUMN `refNo` VARCHAR(100) NULL DEFAULT NULL AFTER `ref`;

-- anna 07/04/2020
--

ALTER TABLE `tbmsdb`.`files` 
ADD COLUMN `skey` VARCHAR(16) NOT NULL AFTER `description`;

-- anna 09/04/2020
--

ALTER TABLE `tbmsdb`.`customer` 
ADD COLUMN `companyName` VARCHAR(255) NULL AFTER `phone2`;

-- anna 14/04/2020
-- 
ALTER TABLE `tbmsdb`.`customer` 
CHANGE COLUMN `surname` `surname` VARCHAR(255) NULL DEFAULT NULL ,
CHANGE COLUMN `firstName` `firstName` VARCHAR(255) NULL DEFAULT NULL ;

-- anna 11/05/2020
--

ALTER TABLE `tbmsdb`.`orders` 
ADD INDEX `cust_order` (`id` ASC, `custId` ASC);
ALTER TABLE `tbmsdb`.`orders` 
ADD INDEX `order_ref` (`id` ASC, `ref` ASC);
ALTER TABLE `tbmsdb`.`customer` 
ADD INDEX `cust_ref` (`id` ASC, `ref` ASC);

-- anna 15/05/2020
--

INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`, `description`) VALUES ('AMOUNT_REMIND', 'order', 'Order Amount Remind', NULL);

DROP TABLE IF EXISTS `audit_log`;
CREATE TABLE `audit_log` (
  `tableName` varchar(30) NOT NULL,
  `recordId` int(11) NOT NULL,
  `modifiedBy` int(11) DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `oldData` json DEFAULT NULL,
  `newData` json DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- anna 28/05/2020
ALTER TABLE `tbmsdb`.`meeting` 
CHANGE COLUMN `date` `date` DATETIME NOT NULL ;


-- Matthew
-- 09/06/2020 
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('ORDER_CANCEL', 'order', 'Order Cancel');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('MEETING_DELETE', 'meeting', 'Meeting Delete');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('CUSTOMER_DELETE', 'customer', 'Customer Delete');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('FILE_DELETE', 'file', 'File Delete');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('PAYMENT_REPORT', 'report', 'Payment Report Auth');

-- Jason Lam
-- 10/06/2020
ALTER TABLE `tbmsdb`.`orders` 
ADD COLUMN `outDate` DATE NULL AFTER `status`,
ADD COLUMN `outRemark` VARCHAR(255) NULL AFTER `outDate`,
ADD COLUMN `inDate` DATE NULL AFTER `outRemark`,
ADD COLUMN `inRemark` VARCHAR(255) NULL AFTER `inDate`;

--Jason Lam
--11/06/2020
ALTER TABLE `tbmsdb`.`orders` 
ADD COLUMN `ignore` TINYINT(1) '0' AFTER `inRemark`;
ALTER TABLE `tbmsdb`.`orders` 
CHANGE COLUMN `ignore` `ignoreC` TINYINT(1) NULL DEFAULT '0' ;


-- anna 
-- 15/06/2020
ALTER TABLE `tbmsdb`.`audit_log` 
DROP COLUMN `oldData`,
CHANGE COLUMN `newData` `dataStr` JSON NULL DEFAULT NULL ,
ADD COLUMN `actionStr` VARCHAR(255) NULL DEFAULT NULL AFTER `modified`,
ADD COLUMN `refId` INT(11) NULL DEFAULT NULL AFTER `dataStr`,
ADD COLUMN `refType` VARCHAR(255) NULL DEFAULT NULL AFTER `refId`;

-- anna
-- 23/06/2020
ALTER TABLE `tbmsdb`.`orders` 
ADD COLUMN `workshopStatus` INT(11) NULL DEFAULT NULL AFTER `ignoreC`;


-- anna
-- 29/06/2020

INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('ORDER_ITEM_DELETE', 'order', 'Order Item Delete');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('PAYMENT_DELETE', 'order', 'Payment Delete');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('WORKSHOP_MAINTAIN', 'workshop', 'Maintain Workshop');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('CALENDAR_VIEW', 'calendar', 'View Calendar');


-- anna
-- 13/07/2020
ALTER TABLE `tbmsdb`.`orders`
ADD COLUMN `targetCompleteDate` DATE NULL DEFAULT NULL AFTER `workshopStatus`;

-- anna
-- 21/07/2020
ALTER TABLE `tbmsdb`.`customer` 
ADD COLUMN `tag` VARCHAR(255) NULL DEFAULT NULL AFTER `ref`;

-- matthew
-- 07/09/2020
INSERT INTO `tbmsdb`.`settings` (`name`, `value`) VALUES ('JS.version', '1');


-- anna
-- 01/12/2020
ALTER TABLE `tbmsdb`.`meeting` 
ADD COLUMN `staffName` VARCHAR(45) NULL DEFAULT NULL AFTER `remarks`;

ALTER TABLE `tbmsdb`.`orders` 
ADD COLUMN `inStatus` INT(11) NULL DEFAULT NULL AFTER `targetCompleteDate`,
ADD COLUMN `outStatus` INT(11) NULL DEFAULT NULL AFTER `inStatus`;

-- anna
-- 10/06/2021
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('MATERIAL_MAINTAIN', 'price_list', 'Maintain Material');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('BAND_DELETE', 'price_list', 'Delete Band');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('VIEW_EXPECTED_PRICE', 'price_list', 'View Expected Price');

-- anna
-- 29/06/2021
INSERT INTO `tbmsdb`.`settings` (`name`, `value`) VALUES ('MAIL.temp.subject', '[INVOICE] Order No.: {$orderNo}');

-- anna
-- 06/07/2021
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('MATERIAL_MAIL_TEMPLATE', 'setup', 'Maintain Mail Template');
INSERT INTO `tbmsdb`.`authorities` (`authority`, `module`, `name`) VALUES ('PRICE_LIST_VIEW', 'price_list', 'View Price List');
UPDATE `tbmsdb`.`authorities` SET `authority`='PRICE_LIST_MAINTAIN', `name`='Maintain Price List' WHERE `authority`='MATERIAL_MAINTAIN';

-- anna
-- 19/07/2021
CREATE TABLE `material_band` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `versionId` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  `createdBy` int(11) DEFAULT NULL,
  `modifiedBy` int(11) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `name` varchar(255) NOT NULL,
  `fileId` int(11) DEFAULT NULL,
  `expectedPriceFormula` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

CREATE TABLE `material_item` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `versionId` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  `createdBy` int(11) DEFAULT NULL,
  `modifiedBy` int(11) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `bandId` int(11) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `bunch` varchar(255) DEFAULT NULL,
  `itemNo` varchar(255) DEFAULT NULL,
  `cost` decimal(18,4) DEFAULT '0.0000',
  `suitPrice` decimal(18,4) DEFAULT NULL,
  `jacketPrice` decimal(18,4) DEFAULT NULL,
  `overcoatPrice` decimal(18,4) DEFAULT NULL,
  `pantsPrice` decimal(18,4) DEFAULT NULL,
  `otherPrice` decimal(18,4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

-- anna
-- 10/01/2022

ALTER TABLE `tbmsdb`.`material_item` 
ADD COLUMN `fabricNum` VARCHAR(255) NULL DEFAULT NULL AFTER `bunch`;

-- anna
-- 4/03/2022

ALTER TABLE `tbmsdb`.`material_item` 
ADD COLUMN `orderIdx` INT(11) NOT NULL DEFAULT 0 AFTER `otherPrice`;
                                                                                                                                                                                                                                             
CREATE TABLE `user_settings` (
  `userId` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `value` varchar(1000) DEFAULT NULL,
  `category` varchar(50) DEFAULT NULL,
  `type` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`userId`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- anna
-- 22/03/2022

CREATE TABLE `sys_groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `deleted` tinyint(1) NOT NULL,
  `versionId` mediumint(8) unsigned NOT NULL,
  `created` datetime DEFAULT NULL,
  `createdBy` int(11) DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `modifiedBy` int(11) DEFAULT NULL,
  `name` varchar(50) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

ALTER TABLE `tbmsdb`.`groups` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`users` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`customer` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`files` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`files_blob` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`files_ref` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`material_band` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`material_item` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`meeting` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`order_item` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`orders` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`payment` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

ALTER TABLE `tbmsdb`.`message` 
ADD COLUMN `sysGroupId` INT(11) NOT NULL DEFAULT 0 AFTER `id`;

-- anna
-- 18/05/2022

ALTER TABLE `tbmsdb`.`sys_groups` 
ADD COLUMN `mailBody` TEXT NULL DEFAULT NULL AFTER `description`,
ADD COLUMN `mailSubject` TEXT NULL DEFAULT NULL AFTER `mailBody`;

ALTER TABLE `tbmsdb`.`sys_groups` 
ADD COLUMN `companyName` VARCHAR(255) NULL DEFAULT NULL AFTER `mailSubject`,
ADD COLUMN `phone` VARCHAR(255) NULL DEFAULT NULL AFTER `companyName`,
ADD COLUMN `fax` VARCHAR(255) NULL DEFAULT NULL AFTER `phone`,
ADD COLUMN `email` VARCHAR(255) NULL DEFAULT NULL AFTER `fax`,
ADD COLUMN `address` VARCHAR(500) NULL DEFAULT NULL AFTER `email`;

-- anna
-- 23/05/2022

ALTER TABLE `tbmsdb`.`sys_groups` 
ADD COLUMN `smtp_host` VARCHAR(255) NULL DEFAULT NULL AFTER `address`,
ADD COLUMN `smtp_port` VARCHAR(5) NULL DEFAULT NULL AFTER `smtp_host`,
ADD COLUMN `smtp_username` VARCHAR(255) NULL DEFAULT NULL AFTER `smtp_port`,
ADD COLUMN `smtp_password` VARCHAR(255) NULL DEFAULT NULL AFTER `smtp_username`;


