CREATE TABLE IF NOT EXISTS `crm_quotation` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `name` char(100) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `version` smallint(6) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `version` (`version`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ALTER TABLE `ameba_budget` ADD `month` char(2) NOT NULL AFTER `year`;
ALTER TABLE `ameba_budget` ADD `week` char(2) NOT NULL AFTER `month`;
ALTER TABLE `ameba_budget` ADD `product` mediumint(8) unsigned NOT NULL AFTER `line`;
ALTER TABLE `ameba_budget` ADD `sharedDept` mediumint(8) unsigned NOT NULL;

ALTER TABLE `ameba_category` ADD `origin` mediumint(8) unsigned NOT NULL AFTER `id`;
ALTER TABLE `ameba_category` ADD `year` char(4) NOT NULL AFTER `origin`;

ALTER TABLE `ameba_setting` ADD `laborCategory` mediumint(8) unsigned NOT NULL DEFAULT 0 AFTER `shareDepts`;
ALTER TABLE `ameba_setting` ADD `reportType` varchar(20) NOT NULL DEFAULT '';
ALTER TABLE `ameba_setting` ADD `reportNum` smallint(5) NOT NULL DEFAULT 0;

ALTER TABLE `ameba_statement` ADD `item` varchar(30) NOT NULL AFTER `category`;

ALTER TABLE `crm_order` ADD `quotation` mediumint(8) unsigned NOT NULL DEFAULT '0' AFTER `customer`;
ALTER TABLE `crm_contract` ADD `quotation` char(255) NOT NULL AFTER `code`;
ALTER TABLE `psi_orderproduct` ADD `app` char(30) NOT NULL DEFAULT 'psi' AFTER `id`;
ALTER TABLE `psi_orderproduct` ADD `quotation` mediumint(8) unsigned NOT NULL DEFAULT '0' AFTER `id`;
ALTER TABLE `psi_orderproduct` ADD `unit` text NOT NULL AFTER `product`;
ALTER TABLE `psi_orderproduct` ADD `version` smallint(6) NOT NULL DEFAULT '1';

ALTER TABLE `sys_team` CHANGE `rate` `rate` decimal(6,2) NOT NULL DEFAULT '0' AFTER `contribution`;

ALTER TABLE `ameba_budget` DROP INDEX `category_dept`;
ALTER TABLE `ameba_budget` DROP INDEX `deptCategory`;
ALTER TABLE `ameba_budget` DROP INDEX `amebaBudget`;
ALTER TABLE `ameba_budget` ADD UNIQUE `amebaBudget` (`year`, `month`, `week`, `dept`, `amebaAccount`, `tradeDept`, `line`, `product`, `category`);
ALTER TABLE `ameba_category` ADD INDEX `origin` (`origin`);
ALTER TABLE `ameba_category` ADD INDEX `year` (`year`);
ALTER TABLE `ameba_statement` ADD INDEX `date` (`date`);

ALTER TABLE `cash_fund` CHANGE `parent` `parent` int(11) signed NOT NULL;
ALTER TABLE `cash_fund` ADD `custom` enum('0', '1') NOT NULL DEFAULT '0' AFTER `balance`;
ALTER TABLE `cash_fund` DROP `in`;
ALTER TABLE `cash_fund` DROP `out`;

ALTER TABLE `crm_plan` ADD `invoice` char(255) NOT NULL AFTER `contract`;
ALTER TABLE `crm_plan` CHANGE `trade` `trade` char(255) NOT NULL;

CREATE TABLE IF NOT EXISTS `cash_tradeinvoice` (
  `trade` mediumint(8) unsigned NOT NULL,
  `invoice` mediumint(8) unsigned NOT NULL,
  UNIQUE KEY `tradeInvoice` (`trade`, `invoice`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
