-- DROP TABLE IF EXISTS `ameba_budget`;
CREATE TABLE IF NOT EXISTS `ameba_budget` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `year` char(4) NOT NULL,
  `month` char(2) NOT NULL,
  `week` char(2) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `amebaAccount` varchar(30) NOT NULL,
  `tradeDept` mediumint(8) unsigned NOT NULL,
  `line` varchar(60) NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `category` varchar(30) NOT NULL,
  `money` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `sharedDept` mediumint(8) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `amebaBudget` (`year`, `month`, `week`, `dept`, `amebaAccount`, `tradeDept`, `line`, `product`, `category`),
  KEY `year` (`year`),
  KEY `dept` (`dept`),
  KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_category`;
CREATE TABLE IF NOT EXISTS `ameba_category` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `origin` mediumint(8) unsigned NOT NULL,
  `year` char(4) NOT NULL,
  `root` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `parent` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `path` char(255) NOT NULL DEFAULT '',
  `grade` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `order` smallint(5) unsigned NOT NULL DEFAULT '0',
  `type` char(30) NOT NULL DEFAULT 'amebaAccount',
  `amebaAccount` varchar(30) NOT NULL,
  `category` mediumint(8) unsigned NOT NULL,
  `desc` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `origin` (`origin`),
  KEY `year` (`year`),
  KEY `parent` (`parent`),
  KEY `path` (`path`),
  KEY `grade` (`grade`),
  KEY `order` (`order`),
  KEY `type` (`type`),
  KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_deal`;
CREATE TABLE IF NOT EXISTS `ameba_deal` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `from` mediumint(8) unsigned NOT NULL,
  `date` date NOT NULL,
  `amebaAccount` varchar(30) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `category` mediumint(8) unsigned NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `type` varchar(30) NOT NULL,
  `trade` mediumint(8) unsigned NOT NULL,
  `contract` mediumint(8) unsigned NOT NULL,
  `money` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  `status` enum('wait', 'normal') NOT NULL DEFAULT 'wait',
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `confirmedBy` varchar(30) NOT NULL,
  `confirmedDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `date` (`date`),
  KEY `amebaAccount` (`amebaAccount`),
  KEY `dept` (`dept`),
  KEY `category` (`category`),
  KEY `type` (`type`),
  KEY `contract` (`contract`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_fee`;
CREATE TABLE IF NOT EXISTS `ameba_fee` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `type` varchar(20) NOT NULL,
  `category` varchar(30) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `period` varchar(10) NOT NULL DEFAULT 'month',
  `shareType` varchar(30) NOT NULL DEFAULT 'person',
  `money` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `amebaFee` (`month`, `category`, `dept`),
  KEY `month` (`month`),
  KEY `type` (`type`),
  KEY `category` (`category`),
  KEY `dept` (`dept`),
  KEY `period` (`period`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_rule`;
CREATE TABLE IF NOT EXISTS `ameba_rule` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `parent` mediumint(8) unsigned NOT NULL,
  `month` char(6) NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `category` mediumint(8) unsigned NOT NULL,
  `from` mediumint(8) unsigned NOT NULL,
  `fromCategory` mediumint(8) unsigned NOT NULL,
  `to` mediumint(8) unsigned NOT NULL,
  `toCategory` mediumint(8) unsigned NOT NULL,
  `rate` decimal(6,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `amebaRule` (`parent`, `month`, `product`, `category`, `to`),
  KEY `month` (`month`),
  KEY `product` (`product`),
  KEY `category` (`category`),
  KEY `to` (`to`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_sharefee`;
CREATE TABLE IF NOT EXISTS `ameba_sharefee` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `fee` mediumint(8) unsigned NOT NULL,
  `month` char(6) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `rate` decimal(6,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `feeDept` (`fee`, `dept`),
  KEY `fee` (`fee`),
  KEY `month` (`month`),
  KEY `dept` (`dept`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_statement`;
CREATE TABLE IF NOT EXISTS `ameba_statement` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `type` varchar(30) NOT NULL,
  `amebaAccount` varchar(30) NOT NULL,
  `category` varchar(30) NOT NULL,
  `item` varchar(30) NOT NULL,
  `date` date NOT NULL,
  `expect` decimal(12,2) NOT NULL,
  `actual` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `archived` enum('0', '1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `amebaStatement` (`month`, `dept`, `type`, `amebaAccount`, `category`, `date`),
  KEY `month` (`month`),
  KEY `dept` (`dept`),
  KEY `type` (`type`),
  KEY `amebaAccount` (`amebaAccount`),
  KEY `category` (`category`),
  KEY `date` (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_dept`;
CREATE TABLE IF NOT EXISTS `ameba_dept` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `dept` mediumint(8) unsigned NOT NULL,
  `month` char(6) NOT NULL,
  `name` char(30) NOT NULL,
  `root` mediumint(8) unsigned NOT NULL,
  `parent` mediumint(8) unsigned NOT NULL,
  `path` char(255) NOT NULL,
  `grade` tinyint(3) unsigned NOT NULL,
  `order` smallint(5) unsigned NOT NULL,
  `moderators` varchar(255) NOT NULL,
  `isAmebaDept` enum('0', '1') NOT NULL DEFAULT '0',
  `amebaDept` varchar(10) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `deptMonth` (`dept`, `month`),
  KEY `dept` (`dept`),
  KEY `month` (`month`),
  KEY `parent` (`parent`),
  KEY `path` (`path`),
  KEY `grade` (`grade`),
  KEY `order` (`order`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_user`;
CREATE TABLE IF NOT EXISTS `ameba_user` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `parent` varchar(30) NOT NULL,
  `unofficial` enum('0', '1') NOT NULL DEFAULT '0',
  `dept` mediumint(8) unsigned NOT NULL,
  `account` char(30) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `monthAccount` (`month`, `account`),
  KEY `parent` (`parent`),
  KEY `dept` (`dept`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `ameba_setting`;
CREATE TABLE IF NOT EXISTS `ameba_setting` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `taxRate` decimal(5, 2) unsigned NOT NULL,
  `shareDepts` varchar(255) NOT NULL,
  `laborCategory` mediumint(8) unsigned NOT NULL,
  `excludeCategories` text NOT NULL,
  `reportType` varchar(20) NOT NULL,
  `reportNum` smallint(5) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `month` (`month`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_fund`;
CREATE TABLE IF NOT EXISTS `cash_fund` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(20) NOT NULL DEFAULT 'receivable',
  `origin` varchar(20) NOT NULL,
  `parent` int(11) signed NOT NULL,
  `trader` mediumint(8) unsigned NOT NULL,
  `contract` mediumint(8) unsigned NOT NULL,
  `order` mediumint(8) unsigned NOT NULL,
  `batch` mediumint(8) unsigned NOT NULL,
  `deserved` decimal(15,2) NOT NULL,
  `actual` decimal(15,2) NOT NULL,
  `balance` decimal(15,2) NOT NULL,
  `custom` enum('0', '1') NOT NULL DEFAULT '0',
  `desc` text NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  KEY `origin` (`origin`),
  KEY `parent` (`parent`),
  KEY `trader` (`trader`),
  KEY `order` (`order`),
  KEY `batch` (`batch`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_invoice`;
CREATE TABLE IF NOT EXISTS `cash_invoice` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `sn` varchar(20) NOT NULL,
  `company` mediumint(8) unsigned NOT NULL,
  `customer` mediumint(8) unsigned NOT NULL,
  `contract` mediumint(8) unsigned NOT NULL,
  `contact` mediumint(8) unsigned NOT NULL,
  `address` mediumint(8) unsigned NOT NULL,
  `money` decimal(12,2) NOT NULL,
  `type` varchar(30) NOT NULL,
  `saleType` varchar(30) NOT NULL,
  `taxRate` tinyint(3) unsigned NOT NULL,
  `invoiceTitle` varchar(100) NOT NULL,
  `taxNumber` varchar(20) NOT NULL,
  `registedAddress` varchar(90) NOT NULL,
  `phone` varchar(50) NOT NULL,
  `bankName` varchar(100) NOT NULL,
  `bankAccount` varchar(30) NOT NULL,
  `express` varchar(30) NOT NULL,
  `waybill` varchar(30) NOT NULL,
  `sendway` varchar(30) NOT NULL,
  `sendAccount` varchar(100) NOT NULL,
  `status` varchar(30) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `receivedBy` varchar(30) NOT NULL,
  `receivedDate` datetime NOT NULL,
  `checkedBy` varchar(30) NOT NULL,
  `checkedDate` datetime NOT NULL,
  `drawnBy` varchar(30) NOT NULL,
  `drawnDate` datetime NOT NULL,
  `expressedBy` varchar(30) NOT NULL,
  `expressedDate` datetime NOT NULL,
  `taxRefundedBy` varchar(30) NOT NULL,
  `taxRefundedDate` datetime NOT NULL,
  `deleted` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `customer` (`customer`),
  KEY `contract` (`contract`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_invoicedetail`;
CREATE TABLE IF NOT EXISTS `cash_invoicedetail` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `invoice` mediumint(8) unsigned NOT NULL,
  `item` varchar(100) NOT NULL,
  `itemType` varchar(10) NOT NULL,
  `itemID` mediumint(8) unsigned NOT NULL,
  `model` varchar(100) NOT NULL,
  `unit` varchar(20) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `price` decimal(12,2) NOT NULL,
  `money` decimal(12,2) NOT NULL,
  `taxRate` tinyint(3) unsigned NOT NULL,
  `taxMoney` decimal(12,2) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `invoice` (`invoice`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_tradeinvoice`;
CREATE TABLE IF NOT EXISTS `cash_tradeinvoice` (
  `trade` mediumint(8) unsigned NOT NULL,
  `invoice` mediumint(8) unsigned NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  UNIQUE KEY `tradeInvoice` (`trade`,`invoice`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_kingdeeaccount`;
CREATE TABLE IF NOT EXISTS `cash_kingdeeaccount` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `company` mediumint(8) unsigned NOT NULL,
  `number` varchar(128) NOT NULL,
  `name` varchar(160) NOT NULL,
  `helperCode` varchar(40) NOT NULL,
  `groupID` varchar(255) NOT NULL,
  `dc` varchar(10) NOT NULL,
  `currencyID` varchar(255) NOT NULL,
  `adjustRate` varchar(10) NOT NULL,
  `contact` varchar(10) NOT NULL,
  `quantities` varchar(10) NOT NULL,
  `unitGroupID` varchar(255) NOT NULL,
  `measureUnitID` varchar(255) NOT NULL,
  `isCash` varchar(10) NOT NULL,
  `isBank` varchar(10) NOT NULL,
  `journal` varchar(10) NOT NULL,
  `detailID` varchar(10) NOT NULL,
  `isBalance` varchar(10) NOT NULL,
  `mainItemID` varchar(255) NOT NULL,
  `subItemID` varchar(255) NOT NULL,
  `itemClassNumber` varchar(255) NOT NULL,
  `itemClassName` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_mappingrelation`;
CREATE TABLE IF NOT EXISTS `cash_mappingrelation` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `company` mediumint(8) unsigned NOT NULL,
  `type` varchar(10) NOT NULL,
  `depositor` mediumint(8) unsigned NOT NULL,
  `category` mediumint(8) unsigned NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `invoice` varchar(50) NOT NULl,
  `saleType` varchar(30) NOT NULl,
  `account` varchar(255) NOT NULL,
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY (`company`, `type`, `depositor`, `category`, `product`, `invoice`, `saleType`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_voucher`;
CREATE TABLE IF NOT EXISTS `cash_voucher` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `company` mediumint(8) unsigned NOT NULL,
  `origin` varchar(10) NOT NULL,
  `date` date NOT NULL COMMENT '凭证日期',
  `type` char(3) NOT NULL COMMENT '凭证字',
  `number` smallint(5) unsigned NOT NULL COMMENT '凭证号',
  `currency` varchar(5) NOT NULL DEFAULT 'RMB' COMMENT '币别代码',
  `debit` decimal(12,2) NOT NULL COMMENT '借方',
  `credit` decimal(12,2) NOT NULL COMMENT '贷方',
  `preparer` varchar(30) NOT NULL COMMENT '制单',
  `checker` varchar(30) NOT NULL COMMENT '审核',
  `approve` varchar(30) NOT NULL COMMENT '核准',
  `cashier` varchar(30) NOT NULL COMMENT '出纳',
  `handler` varchar(30) NOT NULL COMMENT '经办',
  `settleType` varchar(10) NOT NULL COMMENT '结算方式',
  `settleNo` varchar(10) NOT NULL COMMENT '结算号',
  `explanation` text NOT NULL COMMENT '凭证摘要',
  `reference` varchar(10) NOT NULL COMMENT '参考信息',
  `transDate` date NOT NULL COMMENT '业务日期',
  `transNo` varchar(10) NOT NULL COMMENT '往来业务编号',
  `attachments` tinyint(3) NOT NULL COMMENT '附件数',
  `serialNum` smallint(5) unsigned NOT NULL COMMENT '序号',
  `objectName` varchar(10) NOT NULL COMMENT '系统模块',
  `parameter` varchar(10) NOT NULL COMMENT '业务描述',
  `exchangeRate` decimal(12,4) NOT NULL COMMENT '汇率',
  `posted` tinyint(3) unsigned NOT NULL COMMENT '过账',
  `internalInd` varchar(10) NOT NULL COMMENT '机制凭证',
  `cashFlow` varchar(10) NOT NULL COMMENT '现金流量',
  `status` varchar(10) NOT NULL DEFAULT 'wait',
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `confirmedBy` char(30) NOT NULL,
  `confirmedDate` datetime NOT NULL,
  PRIMARY KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `cash_voucherdetail`;
CREATE TABLE IF NOT EXISTS `cash_voucherdetail` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `voucher` mediumint(8) unsigned NOT NULL,
  `trade` varchar(255) NOT NULL,
  `invoice` varchar(255) NOT NULL,
  `account` varchar(255) NOT NULL COMMENT '科目代码',
  `debit` decimal(12,2) NOT NULL COMMENT '借方',
  `credit` decimal(12,2) NOT NULL COMMENT '贷方',
  `quantity` decimal(12,2) NOT NULL COMMENT '数量',
  `measureUnitID` varchar(10) NOT NULL COMMENT '数量单位',
  `unitPrice` decimal(12,2) NOT NULL COMMENT '单价',
  `exchangeRate` decimal(12,4) NOT NULL COMMENT '汇率',
  `entryID`  tinyint(3) unsigned NOT NULL COMMENT '分录序号',
  `explanation` text NOT NULL COMMENT '凭证摘要',
  `item` varchar(255) NOT NULL COMMENT '核算项目',
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `crm_orderaction`;
CREATE TABLE IF NOT EXISTS `crm_orderaction` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `product` mediumint(8) unsigned NOT NULL,
  `action` char(30) NOT NULL,
  `name` char(100) NOT NULL,
  `conditions` text NOT NULL,
  `inputs` text NOT NULL,
  `results` text NOT NULL,
  `tasks` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `product` (`product`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `crm_orderfield`;
CREATE TABLE IF NOT EXISTS `crm_orderfield` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `product` mediumint(8) unsigned NOT NULL,
  `field` varchar(50) NOT NULL,
  `name` varchar(50) NOT NULL,
  `order` tinyint(3) unsigned NOT NULL,
  `control` varchar(10) NOT NULL,
  `options` text NOT NULL,
  `default` varchar(100) NOT NULL,
  `rules` varchar(255) NOT NULL,
  `placeholder` varchar(100) NOT NULL,
  `desc` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `product` (`product`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `crm_customerinvoice`;
CREATE TABLE IF NOT EXISTS `crm_customerinvoice` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `customer` mediumint(8) unsigned NOT NULL,
  `invoiceTitle` char(100) NOT NULL,
  `taxNumber` char(20) NOT NULL,
  `registedAddress` varchar(255) NOT NULL,
  `phone` char(20) NOT NULL,
  `bankName` char(30) NOT NULL,
  `bankAccount` char(90) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `taxNumber` (`customer`, `taxNumber`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `crm_quotation`;
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(5) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `version` (`version`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `hr_bonus`;
CREATE TABLE IF NOT EXISTS `hr_bonus` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `account` char(30) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `performance` decimal(12,2) NOT NULL,
  `bonus` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `status` enum('wait', 'confirmed') NOT NULL DEFAULT 'wait',
  PRIMARY KEY (`id`),
  KEY `month` (`month`),
  KEY `account` (`account`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `hr_salary`;
CREATE TABLE IF NOT EXISTS `hr_salary` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `account` char(30) NOT NULL,
  `dept` mediumint(8) unsigned NOT NULL,
  `basic` decimal(12,2) NOT NULL,
  `performance` decimal(12,2) NOT NULL,
  `bonus` decimal(12,2) NOT NULL,
  `allowance` decimal(12,2) NOT NULL,
  `exemption` decimal(12,2) NOT NULL,
  `deduction` decimal(12,2) NOT NULL,
  `deserved` decimal(12,2) NOT NULL,
  `actual` decimal(12,2) NOT NULL,
  `companySSF` decimal(12,2) NOT NULL,
  `companyHPF` decimal(12,2) NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `desc` text NOT NULL,
  `status` varchar(20) NOT NULL DEFAULT 'wait',
  PRIMARY KEY (`id`),
  KEY `month` (`month`),
  KEY `account` (`account`),
  KEY `dept` (`dept`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `hr_salarydetail`;
CREATE TABLE IF NOT EXISTS `hr_salarydetail` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `salary` mediumint(8) unsigned NOT NULL,
  `item` enum('bonus', 'allowance', 'exemption', 'deduction') NOT NULL,
  `type` varchar(100) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `salary` (`salary`),
  KEY `item` (`item`),
  KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `hr_salarycommission`;
CREATE TABLE IF NOT EXISTS `hr_salarycommission` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `salary` mediumint(8) unsigned NOT NULL,
  `type` varchar(10) NOT NULL DEFAULT 'sale',
  `line` varchar(60) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `rate` decimal(12,2) NOT NULL,
  `commission` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `salarycommission` (`salary`, `type`, `line`),
  KEY `salary` (`salary`),
  KEY `line` (`line`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `hr_tradecommission`;
CREATE TABLE IF NOT EXISTS `hr_tradecommission` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(10) NOT NULL DEFAULT 'sale',
  `trade` mediumint(8) unsigned NOT NULL,
  `account` char(30) NOT NULL,
  `contribution` decimal(12,2) NOT NULL,
  `rate` decimal(12,2) NOT NULL,
  `amount` decimal(12,2) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `account` (`account`),
  KEY `trade` (`trade`),
  UNIQUE KEY `tradecommission` (`type`, `trade`,`account`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `hr_commissionrule`;
CREATE TABLE IF NOT EXISTS `hr_commissionrule` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `month` char(6) NOT NULL,
  `account` char(30) NOT NULL,
  `sale` text NOT NULL,
  `line` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `month` (`month`),
  KEY `account` (`account`),
  UNIQUE KEY `monthaccount` (`month`, `account`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `psi_batch`;
CREATE TABLE IF NOT EXISTS `psi_batch` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `batchNo` varchar(255) NOT NULL,
  `type` enum('in', 'out') NOT NULL DEFAULT 'in',
  `trader` mediumint(8) unsigned NOT NULL,
  `order` mediumint(8) unsigned NOT NULL,
  `fund` mediumint(8) unsigned NOT NULL,
  `money` decimal(15,2) NOT NULL,
  `pickedBy` char(30) NOT NULL,
  `pickedDate` date  NOT NULL,
  `expressedBy` char(30) NOT NULL,
  `expressedDate` date NOT NULL,
  `express` smallint(5) unsigned NOT NULL,
  `waybill` char(50) NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `assignedTo` char(30) NOT NULL,
  `assignedBy` char(30) NOT NULL,
  `assignedDate` datetime NOT NULL,
  `status` char(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `order` (`order`),
  KEY `trader` (`trader`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `psi_batchproduct`;
CREATE TABLE IF NOT EXISTS `psi_batchproduct` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `order` mediumint(8) unsigned NOT NULL,
  `trader` mediumint(8) unsigned NOT NULL,
  `batch` mediumint(8) unsigned NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `price` decimal(15,2) NOT NULL,
  `amount` decimal(15,2) NOT NULL,
  `money` decimal(15,2) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `batch` (`batch`),
  KEY `order` (`order`),
  KEY `trader` (`trader`),
  KEY `product` (`product`),
  UNIQUE KEY `batchProduct` (`batch`,`product`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `psi_order`;
CREATE TABLE IF NOT EXISTS `psi_order` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `orderNo` varchar(255) NOT NULL,
  `type` enum('sale', 'purchase') NOT NULL DEFAULT 'sale',
  `trader` mediumint(8) unsigned NOT NULL,
  `contract` mediumint(8) unsigned NOT NULL,
  `money` decimal(15,2) NOT NULL,
  `taxed` enum('0', '1') NOT NULL DEFAULT '1',
  `settlement` char(30) NOT NULL,
  `desc` text NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `assignedTo` char(30) NOT NULL,
  `assignedBy` char(30) NOT NULL,
  `assignedDate` datetime NOT NULL,
  `finishedDate` date NOT NULL,
  `status` char(20) NOT NULL,
  `deleted` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `trader` (`trader`),
  KEY `status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `psi_orderproduct`;
CREATE TABLE IF NOT EXISTS `psi_orderproduct` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `app` char(30) NOT NULL,
  `order` mediumint(8) unsigned NOT NULL,
  `quotation` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `trader` mediumint(8) unsigned NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `unit` text NOT NULL,
  `amount` decimal(15,2) NOT NULL,
  `price` decimal(15,2) NOT NULL,
  `money` decimal(15,2) NOT NULL,
  `version` smallint(5) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `order` (`order`),
  KEY `trader` (`trader`),
  KEY `product` (`product`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `psi_purchaseproduct`;
CREATE TABLE IF NOT EXISTS `psi_purchaseproduct` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `order` mediumint(8) unsigned NOT NULL,
  `product` mediumint(8) unsigned NOT NULL,
  `amount` decimal(15,2) NOT NULL,
  `assignedTo` char(30) NOT NULL,
  `status` char(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `order` (`order`),
  KEY `product` (`product`),
  UNIQUE KEY `orderProduct` (`order`,`product`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `sys_company` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `name` char(100) NOT NULL,
  `major` enum('0','1') NOT NULL DEFAULT '0',
  `content` text NOT NULL,
  `taxNumber` char(20) NOT NULL,
  `registedAddress` varchar(255) NOT NULL,
  `phone` char(20) NOT NULL,
  `bankName` char(100) NOT NULL,
  `bankAccount` char(90) NOT NULL,
  `status` char(90) NOT NULL,
  `createdBy` char(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `sys_issue`;
CREATE TABLE IF NOT EXISTS `sys_issue` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `product` mediumint(8) unsigned NOT NULL,
  `category` mediumint(8) unsigned NOT NULL,
  `customer` mediumint(8) unsigned NOT NULL,
  `contact` mediumint(8) unsigned NOT NULL,
  `pri` tinyint(3) unsigned DEFAULT NULL,
  `title` varchar(255) NOT NULL,
  `desc` text NOT NULL,
  `type` varchar(30) NOT NULL,
  `addedBy` char(30) NOT NULL,
  `addedDate` datetime NOT NULL,
  `viewedDate` datetime NOT NULL,
  `assignedTo` char(30) NOT NULL,
  `assignedBy` char(30) NOT NULL,
  `assignedDate` datetime NOT NULL,
  `repliedBy` char(30) NOT NULL,
  `repliedDate` datetime NOT NULL,
  `transferedBy` char(30) NOT NULL,
  `transferedDate` datetime NOT NULL,
  `editedBy` char(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  `closedBy` char(30) NOT NULL,
  `closedDate` datetime NOT NULL,
  `closedReason` varchar(30) NOT NULL,
  `activatedBy` char(30) NOT NULL,
  `activatedDate` datetime NOT NULL,
  `toObjectType` varchar(30) NOT NULL,
  `toObjectID` mediumint(8) unsigned NOT NULL,
  `status` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `sys_searchdict`;
CREATE TABLE IF NOT EXISTS `sys_searchdict` (
  `key` smallint(5) unsigned NOT NULL,
  `value` char(3) NOT NULL,
  PRIMARY KEY (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `sys_searchindex`;
CREATE TABLE IF NOT EXISTS `sys_searchindex` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `objectType` char(20) NOT NULL,
  `objectID` mediumint(8) unsigned NOT NULL,
  `title` text NOT NULL,
  `content` text NOT NULL,
  `addedDate` datetime NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `object` (`objectType`,`objectID`),
  KEY `addedDate` (`addedDate`),
  FULLTEXT KEY `content` (`title`,`content`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `sys_store`;
CREATE TABLE IF NOT EXISTS `sys_store` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `location` varchar(255) NOT NULL,
  `desc` text NOT NULL,
  `manager` varchar(100) NOT NULL,
  `deleted` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS `sys_weekly`;
CREATE TABLE IF NOT EXISTS `sys_weekly` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `summary` text NOT NULL,
  `content` text NOT NULL,
  `begin` date NOT NULL,
  `end` date NOT NULL,
  `status` enum('draft', 'normal') NOT NULL DEFAULT 'normal',
  `createdBy` varchar(30) NOT NULL,
  `createdDate` datetime NOT NULL,
  `editedBy` varchar(30) NOT NULL,
  `editedDate` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;

-- DROP TABLE IF EXISTS `sys_effort`;
CREATE TABLE IF NOT EXISTS `sys_effort` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `objectType` varchar(30) NOT NULL,
  `objectID` mediumint(8) unsigned NOT NULL,
  `project` mediumint(8) unsigned NOT NULL,
  `account` varchar(30) NOT NULL,
  `work` varchar(255) NOT NULL,
  `date` date NOT NULL,
  `left` float NOT NULL,
  `consumed` float NOT NULL,
  `begin` smallint(4) unsigned ZEROFILL NOT NULL,
  `end` smallint(4) unsigned ZEROFILL NOT NULL,
  KEY `effort` (`project`,`objectID`,`date`,`account`)
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;

-- DROP TABLE IF EXISTS `sys_oauth`;
CREATE TABLE IF NOT EXISTS `sys_oauth` (
  `account` varchar(30) NOT NULL,
  `provider` varchar(30) NOT NULL,
  `openID` varchar(60) NOT NULL,
  UNIQUE KEY `openID` (`provider`,`openID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ALTER TABLE `cash_trade`     ADD `noInvoice` enum('0', '1') NOT NULL DEFAULT '0' AFTER `currency`;
ALTER TABLE `cash_trade`     ADD `commission` decimal(12,2) NOT NULL AFTER `money`;
ALTER TABLE `cash_trade`     ADD `alipayTradeNo` varchar(50) NOT NULL AFTER `category`;
ALTER TABLE `cash_trade`     ADD `shareStatus` varchar(10) NOT NULL DEFAULT 'wait';
ALTER TABLE `cash_trade`     ADD `sharedDate` datetime NOT NULL AFTER `shareStatus`;
ALTER TABLE `cash_depositor` ADD `company` mediumint(8) unsigned NOT NULL AFTER `id`;
ALTER TABLE `crm_order`      ADD `quotation` mediumint(8) unsigned NOT NULL DEFAULT '0' AFTER `customer`;
ALTER TABLE `crm_contact`    ADD `register` datetime NOT NULL;
ALTER TABLE `crm_contact`    ADD `last` datetime NOT NULL;
ALTER TABLE `crm_contact`    ADD `visits` mediumint(8) NOT NULL;
ALTER TABLE `crm_contact`    ADD `ip` char(50) NOT NULL;
ALTER TABLE `crm_contract`   ADD `fund` mediumint(8) unsigned NOT NULL AFTER `contact`;
ALTER TABLE `crm_contract`   ADD `company` mediumint(8) unsigned NOT NULL AFTER `id`;
ALTER TABLE `crm_contract`   ADD `quotation` char(255) NOT NULL AFTER `code`;
ALTER TABLE `crm_plan`       ADD `invoice` char(255) NOT NULL AFTER `contract`;
ALTER TABLE `oa_leave`       ADD `level` tinyint(3) unsigned NOT NULL;
ALTER TABLE `oa_leave`       ADD `assignedTo` varchar(30) NOT NULL;
ALTER TABLE `oa_leave`       ADD `reviewers` text NOT NULL;
ALTER TABLE `oa_leave`       ADD `backReviewers` text NOT NULL;
ALTER TABLE `oa_lieu`        ADD `level` tinyint(3) unsigned NOT NULL;
ALTER TABLE `oa_lieu`        ADD `assignedTo` varchar(30) NOT NULL;
ALTER TABLE `oa_lieu`        ADD `reviewers` text NOT NULL;
ALTER TABLE `oa_overtime`    ADD `level` tinyint(3) unsigned NOT NULL;
ALTER TABLE `oa_overtime`    ADD `assignedTo` varchar(30) NOT NULL;
ALTER TABLE `oa_overtime`    ADD `reviewers` text NOT NULL;
ALTER TABLE `oa_refund`      ADD `refundCompany` mediumint(8) unsigned NOT NULL AFTER `id`;
ALTER TABLE `oa_refund`      ADD `type` enum('reimburse', 'deduction') NOT NULL DEFAULT 'reimburse' AFTER `refundCompany`;
ALTER TABLE `oa_refund`      ADD `deductionMonth` char(6) NOT NULL AFTER `type`;
ALTER TABLE `oa_refund`      ADD `level` tinyint(3) unsigned NOT NULL;
ALTER TABLE `oa_refund`      ADD `assignedTo` varchar(30) NOT NULL;
ALTER TABLE `oa_refund`      ADD `reviewers` text NOT NULL;
ALTER TABLE `sys_action`     ADD `origin` varchar(256) NOT NULL;
ALTER TABLE `sys_action`     ADD `efforted` BOOL NOT NULL DEFAULT  '0';
ALTER TABLE `sys_category`   ADD `wechatDept` varchar(100) NOT NULL AFTER `id`;
ALTER TABLE `sys_category`   ADD `isAmebaDept` enum('0', '1') NOT NULL DEFAULT '0';
ALTER TABLE `sys_category`   ADD `amebaDept` varchar(10) NOT NUll;
ALTER TABLE `sys_product`    ADD `roles` varchar(255) NOT NULL;
ALTER TABLE `sys_product`    ADD `pinyin` char(200) NOT NULL AFTER `category`;
ALTER TABLE `sys_product`    ADD `model` char(30) NOT NULL AFTER `pinyin`;
ALTER TABLE `sys_product`    ADD `unit` char(30) NOT NULL AFTER `model`;
ALTER TABLE `sys_product`    ADD `barcode` char(30) NOT NULL AFTER `unit`;
ALTER TABLE `sys_product`    ADD `brand` varchar(100) NOT NULL AFTER `barcode`;
ALTER TABLE `sys_product`    ADD `store` smallint(5) unsigned NOT NULL AFTER `brand`;
ALTER TABLE `sys_product`    ADD `price` decimal(15,2) NOT NULL AFTER `store`;
ALTER TABLE `sys_product`    ADD `amount` decimal(15,2) NOT NULL AFTER `price`;
ALTER TABLE `sys_user`       ADD `parent` varchar(30) NOT NULL AFTER `id`;
ALTER TABLE `sys_user`       ADD `unofficial` enum('0', '1') NOT NULL DEFAULT '0' AFTER `parent`;
ALTER TABLE `sys_user`       ADD `noSalary` enum('0', '1') NOT NULL DEFAULT '0' AFTER `unofficial`;

ALTER TABLE `crm_plan` CHANGE `trade` `trade` char(255) NOT NULL;

INSERT INTO `ameba_category` (`id`, `parent`, `path`, `grade`, `order`, `type`, `amebaAccount`, `category`) VALUES
(1, 0, ',1,',   1, 1, 'amebaAccount', 'income',          830001),
(2, 1, ',1,2,', 2, 1, 'amebaAccount', 'externalIncome',  830002),
(3, 1, ',1,3,', 2, 2, 'amebaAccount', 'internalIncome',  830003),
(4, 0, ',4,',   1, 2, 'amebaAccount', 'expense',         830004),
(5, 4, ',4,5,', 2, 1, 'amebaAccount', 'internalDeal',    830005),
(6, 4, ',4,6,', 2, 2, 'amebaAccount', 'internalExpense', 830006),
(7, 4, ',4,7,', 2, 3, 'amebaAccount', 'shareExpense',    830007);

INSERT INTO `sys_category` (`id`, `name`, `type`) VALUES
(830001, '收入',     'amebaAccount'),
(830002, '外部收入', 'amebaAccount'),
(830003, '内部收入', 'amebaAccount'),
(830004, '支出',     'amebaAccount'),
(830005, '巴巴交易', 'amebaAccount'),
(830006, '巴内支出', 'amebaAccount'),
(830007, '公摊费用', 'amebaAccount');

INSERT INTO `sys_config` (`owner`, `app`, `module`, `section`, `key`, `value`) VALUES ('system','psi','order','orderNo','sale','[{\"type\":\"fixed\",\"fixed\":\"SO\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"year\",\"fixed\":\"\",\"yearLength\":\"4\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"month\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"day\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"AI\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"3\",\"AIClearType\":\"day\"}]'),('system','psi','order','orderNo','purchase','[{\"type\":\"fixed\",\"fixed\":\"PI\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"year\",\"fixed\":\"\",\"yearLength\":\"4\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"month\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"day\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"AI\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"3\",\"AIClearType\":\"day\"}]'),('system','psi','order','orderNo','out','[{\"type\":\"fixed\",\"fixed\":\"IO\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"year\",\"fixed\":\"\",\"yearLength\":\"4\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"month\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"day\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"AI\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"3\",\"AIClearType\":\"day\"}]'),('system','psi','order','orderNo','in','[{\"type\":\"fixed\",\"fixed\":\"II\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"year\",\"fixed\":\"\",\"yearLength\":\"4\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"month\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"day\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"\",\"AIClearType\":\"\"},{\"type\":\"AI\",\"fixed\":\"\",\"yearLength\":\"\",\"AILength\":\"3\",\"AIClearType\":\"day\"}]');

INSERT INTO `sys_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`, `lastTime`) VALUES
('1', '1', '*', '*', '*', 'appName=crm&moduleName=leads&methodName=sync',                    '名单同步任务',      'zdoo', 1, 'normal', '0000-00-00 00:00:00'),
('1', '1', '*', '*', '*', 'appName=cash&moduleName=trade&methodName=syncAlipay',             '支付宝同步任务',    'zdoo', 1, 'normal', '0000-00-00 00:00:00'),
('1', '1', '*', '*', '*', 'appName=ameba&moduleName=deal&methodName=batchShare',             '分配收入/分摊支出', 'zdoo', 1, 'normal', '0000-00-00 00:00:00'),
('1', '1', '*', '*', '*', 'appName=ameba&moduleName=amebareport&methodName=updateStatement', '更新阿米巴核算表',  'zdoo', 1, 'normal', '0000-00-00 00:00:00');

INSERT INTO `sys_entry` (`name`, `abbr`, `code`, `buildin`, `integration`, `open`, `key`, `ip`, `logo`, `login`, `control`, `size`, `position`, `visible`, `order`) VALUES
('人力资源', '人资',   'hr',    1, 1, 'iframe', '70a4ec7bf82d831b09578f554141eed0', '*', 'theme/default/images/ips/app-hr.png',    '../hr/',    'simple', 'max', 'default', 1, 70),
('进销存',   '进销存', 'psi',   1, 1, 'iframe', 'be546d3fbb91fa8236b53a8c5fa90884', '*', 'theme/default/images/ips/app-psi.png',   '../psi/',   'simple', 'max', 'default', 1, 80),
('工作流',   '工作流', 'flow',  1, 1, 'iframe', '68149a7806b73b5b0e16bc0a42bfcf43', '*', 'theme/default/images/ips/app-flow.png',  '../flow/',  'simple', 'max', 'default', 1, 90),
('阿米巴',   '阿米巴', 'ameba', 1, 1, 'iframe', 'c73507819a054358b6f45f3f522bd8d3', '*', 'theme/default/images/ips/app-ameba.png', '../ameba/', 'simple', 'max', 'default', 1, 100);

REPLACE INTO `sys_grouppriv` VALUES
(1,'ameba','setting'),
(1,'amebareport','archive'),
(1,'amebareport','dailyReport'),
(1,'amebareport','export'),
(1,'amebareport','monthlyReport'),
(1,'amebareport','showDetail'),
(1,'amebareport','updateStatement'),
(1,'amebareport','weeklyReport'),
(1,'apppriv','ameba'),
(1,'apppriv','hr'),
(1,'apppriv','psi'),
(1,'attend','import'),
(1,'attend','importSettings'),
(1,'attend','showImportError'),
(1,'batch','browse'),
(1,'batch','browseFinished'),
(1,'batch','browsePurchaseOrders'),
(1,'batch','deliver'),
(1,'batch','detail'),
(1,'batch','editDeliver'),
(1,'batch','editPick'),
(1,'batch','editReceive'),
(1,'batch','printBatch'),
(1,'batch','receive'),
(1,'bonus','batchCreate'),
(1,'bonus','browse'),
(1,'bonus','confirm'),
(1,'bonus','delete'),
(1,'bonus','edit'),
(1,'bonus','viewAll'),
(1,'budget','batchCreate'),
(1,'budget','browse'),
(1,'budget','create'),
(1,'budget','delete'),
(1,'budget','edit'),
(1,'budget','export'),
(1,'budget','report'),
(1,'budget','share'),
(1,'budget','view'),
(1,'commission','batchSwitchIgnore'),
(1,'commission','browse'),
(1,'commission','create'),
(1,'commission','export'),
(1,'commission','report'),
(1,'commission','setCategory'),
(1,'commission','setLineCommission'),
(1,'commission','setSaleCommission'),
(1,'commission','setting'),
(1,'commission','switchIgnore'),
(1,'company','browse'),
(1,'company','cancel'),
(1,'company','create'),
(1,'company','edit'),
(1,'company','setMajor'),
(1,'contract','createQuotation'),
(1,'contract','editQuotation'),
(1,'contract','expense'),
(1,'contract','invoice'),
(1,'contract','setting'),
(1,'customer','createInvoice'),
(1,'customer','deleteInvoice'),
(1,'customer','editInvoice'),
(1,'customer','exportTemplate'),
(1,'customer','import'),
(1,'customer','invoice'),
(1,'customer','invoiceInfo'),
(1,'deal','batchCreate'),
(1,'deal','batchShare'),
(1,'deal','batchSwitchTradeStatus'),
(1,'deal','browse'),
(1,'deal','browseExpense'),
(1,'deal','browseIncome'),
(1,'deal','browseWait'),
(1,'deal','confirm'),
(1,'deal','create'),
(1,'deal','delete'),
(1,'deal','edit'),
(1,'deal','export'),
(1,'deal','switchTradeStatus'),
(1,'deal','view'),
(1,'fee','browse'),
(1,'fee','create'),
(1,'fee','delete'),
(1,'fee','edit'),
(1,'fee','export'),
(1,'fee','view'),
(1,'feedback','activate'),
(1,'feedback','assignTo'),
(1,'feedback','close'),
(1,'feedback','company'),
(1,'feedback','create'),
(1,'feedback','delete'),
(1,'feedback','doubt'),
(1,'feedback','edit'),
(1,'feedback','reply'),
(1,'feedback','transfer'),
(1,'feedback','view'),
(1,'invoice','browse'),
(1,'invoice','create'),
(1,'invoice','delete'),
(1,'invoice','drawn'),
(1,'invoice','edit'),
(1,'invoice','export'),
(1,'invoice','express'),
(1,'invoice','report'),
(1,'invoice','taxRefund'),
(1,'invoice','view'),
(1,'leads','adminSites'),
(1,'leads','createSite'),
(1,'leads','deleteSite'),
(1,'leads','editSite'),
(1,'leads','sync'),
(1,'my','deptSalary'),
(1,'order','team'),
(1,'payable','create'),
(1,'payable','delete'),
(1,'payable','edit'),
(1,'payable','paid'),
(1,'payable','pay'),
(1,'payable','payable'),
(1,'payable','view'),
(1,'product','actionconditions'),
(1,'product','actioninputs'),
(1,'product','actionresults'),
(1,'product','actiontasks'),
(1,'product','adminaction'),
(1,'product','adminfield'),
(1,'product','adminroles'),
(1,'product','batchCreate'),
(1,'product','batchCreateProperties'),
(1,'product','browseProperties'),
(1,'product','copy'),
(1,'product','createaction'),
(1,'product','createfield'),
(1,'product','createFromOrder'),
(1,'product','createresult'),
(1,'product','deleteaction'),
(1,'product','deletefield'),
(1,'product','deleteProperty'),
(1,'product','deleteresult'),
(1,'product','editaction'),
(1,'product','editfield'),
(1,'product','editProperty'),
(1,'product','editresult'),
(1,'purchase','activate'),
(1,'purchase','browse'),
(1,'purchase','cancel'),
(1,'purchase','create'),
(1,'purchase','delete'),
(1,'purchase','detail'),
(1,'purchase','edit'),
(1,'purchase','finish'),
(1,'purchase','printOrder'),
(1,'purchase','purchase'),
(1,'purchase','report'),
(1,'purchase','sendMail'),
(1,'receivable','create'),
(1,'receivable','delete'),
(1,'receivable','edit'),
(1,'receivable','receivable'),
(1,'receivable','receive'),
(1,'receivable','received'),
(1,'receivable','view'),
(1,'rule','browse'),
(1,'rule','create'),
(1,'rule','delete'),
(1,'rule','edit'),
(1,'rule','export'),
(1,'rule','view'),
(1,'salary','batchConfirm'),
(1,'salary','batchCreate'),
(1,'salary','batchDelete'),
(1,'salary','batchEdit'),
(1,'salary','company'),
(1,'salary','confirm'),
(1,'salary','delete'),
(1,'salary','dept'),
(1,'salary','edit'),
(1,'salary','export'),
(1,'salary','report'),
(1,'salary','setAllowance'),
(1,'salary','setBasic'),
(1,'salary','setBonus'),
(1,'salary','setExemption'),
(1,'salary','setSSF'),
(1,'sale','activate'),
(1,'sale','assignToPick'),
(1,'sale','assignToPurchase'),
(1,'sale','browse'),
(1,'sale','cancel'),
(1,'sale','create'),
(1,'sale','delete'),
(1,'sale','detail'),
(1,'sale','edit'),
(1,'sale','finish'),
(1,'sale','printOrder'),
(1,'sale','report'),
(1,'sales','admin'),
(1,'sales','browse'),
(1,'sales','create'),
(1,'sales','delete'),
(1,'sales','edit'),
(1,'store','browse'),
(1,'store','create'),
(1,'store','delete'),
(1,'store','edit'),
(1,'trade','incomeAndReceive'),
(1,'trade','invoice'),
(1,'trade','invoiceStatistics'),
(1,'trade','share'),
(1,'trade','syncAlipay'),
(1,'user','importLDAP'),
(2,'apppriv','hr'),
(2,'bonus','batchCreate'),
(2,'bonus','browse'),
(2,'bonus','confirm'),
(2,'bonus','delete'),
(2,'bonus','edit'),
(2,'bonus','viewAll'),
(2,'commission','batchSwitchIgnore'),
(2,'commission','browse'),
(2,'commission','create'),
(2,'commission','export'),
(2,'commission','report'),
(2,'commission','setCategory'),
(2,'commission','setLineCommission'),
(2,'commission','setSaleCommission'),
(2,'commission','setting'),
(2,'commission','switchIgnore'),
(2,'salary','batchConfirm'),
(2,'salary','batchCreate'),
(2,'salary','batchDelete'),
(2,'salary','batchEdit'),
(2,'salary','company'),
(2,'salary','confirm'),
(2,'salary','delete'),
(2,'salary','dept'),
(2,'salary','edit'),
(2,'salary','export'),
(2,'salary','report'),
(2,'salary','setAllowance'),
(2,'salary','setBasic'),
(2,'salary','setBonus'),
(2,'salary','setExemption'),
(2,'salary','setSSF'),
(2,'trade','incomeAndReceive'),
(2,'trade','invoice'),
(2,'trade','invoiceStatistics'),
(2,'trade','share'),
(2,'trade','syncAlipay'),
(3,'bonus','batchCreate'),
(3,'bonus','browse'),
(3,'bonus','confirm'),
(3,'bonus','delete'),
(3,'bonus','edit'),
(3,'bonus','viewAll'),
(3,'contract','createQuotation'),
(3,'contract','editQuotation'),
(3,'contract','expense'),
(3,'contract','invoice'),
(3,'contract','setting'),
(3,'customer','createInvoice'),
(3,'customer','deleteInvoice'),
(3,'customer','editInvoice'),
(3,'customer','exportTemplate'),
(3,'customer','import'),
(3,'customer','invoice'),
(3,'customer','invoiceInfo'),
(3,'feedback','activate'),
(3,'feedback','assignTo'),
(3,'feedback','close'),
(3,'feedback','company'),
(3,'feedback','create'),
(3,'feedback','delete'),
(3,'feedback','doubt'),
(3,'feedback','edit'),
(3,'feedback','reply'),
(3,'feedback','transfer'),
(3,'feedback','view'),
(3,'invoice','browse'),
(3,'invoice','create'),
(3,'invoice','delete'),
(3,'invoice','edit'),
(3,'invoice','export'),
(3,'invoice','express'),
(3,'invoice','report'),
(3,'invoice','view'),
(3,'leads','adminSites'),
(3,'leads','createSite'),
(3,'leads','deleteSite'),
(3,'leads','editSite'),
(3,'leads','sync'),
(3,'order','team'),
(3,'product','actionconditions'),
(3,'product','actioninputs'),
(3,'product','actionresults'),
(3,'product','actiontasks'),
(3,'product','adminaction'),
(3,'product','adminfield'),
(3,'product','adminroles'),
(3,'product','batchCreate'),
(3,'product','batchCreateProperties'),
(3,'product','browseProperties'),
(3,'product','copy'),
(3,'product','createaction'),
(3,'product','createfield'),
(3,'product','createFromOrder'),
(3,'product','createresult'),
(3,'product','deleteaction'),
(3,'product','deletefield'),
(3,'product','deleteProperty'),
(3,'product','deleteresult'),
(3,'product','editaction'),
(3,'product','editfield'),
(3,'product','editProperty'),
(3,'product','editresult'),
(4,'contract','createQuotation'),
(4,'contract','editQuotation'),
(4,'contract','expense'),
(4,'contract','invoice'),
(4,'customer','createInvoice'),
(4,'customer','deleteInvoice'),
(4,'customer','editInvoice'),
(4,'customer','exportTemplate'),
(4,'customer','import'),
(4,'customer','invoice'),
(4,'customer','invoiceInfo'),
(4,'feedback','activate'),
(4,'feedback','assignTo'),
(4,'feedback','close'),
(4,'feedback','company'),
(4,'feedback','create'),
(4,'feedback','delete'),
(4,'feedback','doubt'),
(4,'feedback','edit'),
(4,'feedback','reply'),
(4,'feedback','transfer'),
(4,'feedback','view'),
(4,'invoice','browse'),
(4,'invoice','create'),
(4,'invoice','delete'),
(4,'invoice','drawn'),
(4,'invoice','edit'),
(4,'invoice','export'),
(4,'invoice','express'),
(4,'invoice','report'),
(4,'invoice','taxRefund'),
(4,'invoice','view');

UPDATE `sys_action` SET `action` = 'submitted' WHERE `objectType` IN ('attend', 'leave', 'lieu', 'makeup', 'overtime', 'refund') AND `action` = 'commited';
