ALTER TABLE `zh_rpt_tree_node_cust`
ADD COLUMN `tender_id` INT NULL DEFAULT -1 COMMENT '新需求，跟标段走，不跟客户走' AFTER `cust_acc_id`,
ADD INDEX `tender` (`tender_id` ASC);
;

CREATE TABLE `zh_stage_yjcl`  (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `uuid` varchar(36) NOT NULL DEFAULT '' COMMENT 'uuid',
  `add_sid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增期id',
  `add_sorder` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '新增期序号',
  `add_uid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建人id',
  `tid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '标段id',
  `sid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '期id',
  `sorder` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '期序号',
  `name` varchar(255) NOT NULL DEFAULT '' COMMENT '名称',
  `m_order` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '排序',
  `spec` varchar(255) NOT NULL DEFAULT '' COMMENT '规格型号',
  `unit` varchar(20) NOT NULL DEFAULT '' COMMENT '单位',
  `tax` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '税率',
  `arrive_time` varchar(50) NOT NULL DEFAULT '' COMMENT '到场时间',
  `source` varchar(255) NOT NULL DEFAULT '' COMMENT '材料来源',
  `bills_code` varchar(255) NOT NULL DEFAULT '' COMMENT '单据号',
  `location` varchar(50) NOT NULL DEFAULT '' COMMENT '存放位置',
  `prepare_pos` varchar(255) NOT NULL DEFAULT '' COMMENT '拟用于部位',
  `memo` varchar(1000) NOT NULL DEFAULT '' COMMENT '备注',
  `arrive_qty` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '到场数量',
  `arrive_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '到场金额',
  `unit_price` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '单价',
  `ex_tax_up` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '除税单价',
  `qty` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '本期数量',
  `tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '本期金额',
  `pre_qty` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '截止上期数量',
  `pre_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '截止上期金额',
  `pre_used` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '上期是否使用',
  `shistory` text NULL COMMENT '审批历史',
  PRIMARY KEY (`id`)
);

ALTER TABLE `zh_budget_std`
ADD COLUMN `ht_project_template_id` varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT '合同-项目合同模版-id列表（‘,’分隔）' AFTER `zb_bills_id`,
ADD COLUMN `ht_tender_template_id` varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT '合同-标段合同模版-id列表（‘,’分隔）' AFTER `ht_project_template_id`;

ALTER TABLE `zh_shenpi_audit`
ADD COLUMN `audit_ledger_id` varchar(5000) NOT NULL DEFAULT '' COMMENT '审批台账id' AFTER `audit_order`;

ALTER TABLE `zh_stage_audit`
ADD COLUMN `audit_ledger_id` varchar(5000) NOT NULL DEFAULT '' COMMENT '审批台账id' AFTER `audit_order`,
ADD COLUMN `audit_locked` tinyint(1) NOT NULL DEFAULT 0  COMMENT '审批锁定（仅协审用）' AFTER `audit_ledger_id`;

ALTER TABLE `zh_ledger_audit`
ADD COLUMN `audit_type` tinyint(4) NOT NULL DEFAULT 1  COMMENT '审批类型' AFTER `audit_order`,
ADD COLUMN `audit_ledger_id` varchar(5000) NOT NULL DEFAULT '' COMMENT '审批台账id' AFTER `audit_id`;

ALTER TABLE `zh_revise_audit`
ADD COLUMN `audit_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '审批类型' AFTER `audit_order`,
ADD COLUMN `audit_ledger_id` varchar(5000) NOT NULL DEFAULT '' COMMENT '审批台账id' AFTER `audit_type`;

ALTER TABLE `zh_tender_cache`
MODIFY COLUMN `ledger_flow_cur_uid` varchar(1000) NOT NULL DEFAULT '0' COMMENT '台账-当前流程人id' AFTER `ledger_status`,
MODIFY COLUMN `ledger_flow_pre_uid` varchar(1000) NOT NULL DEFAULT '0' COMMENT '台账-上一流程人id' AFTER `ledger_flow_cur_info`;

CREATE TABLE `zh_contract_tree` (
  `id` varchar(100) CHARACTER SET utf8 NOT NULL COMMENT '自增id',
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) NOT NULL COMMENT '合同类型(1是支出，2是收入)',
  `contract_id` int(11) NOT NULL COMMENT '节点id',
  `contract_pid` int(11) NOT NULL COMMENT '父节点id',
  `level` tinyint(4) NOT NULL COMMENT '层级',
  `order` mediumint(4) NOT NULL DEFAULT '0' COMMENT '同级排序',
  `full_path` varchar(255) CHARACTER SET utf8 DEFAULT '' COMMENT '层级定位辅助字段parent.full_path.contract_id',
  `is_leaf` tinyint(1) NOT NULL COMMENT '是否叶子节点，界面显示辅助字段',
  `code` varchar(50) CHARACTER SET utf8 DEFAULT '' COMMENT '节点编号',
  `name` varchar(255) CHARACTER SET utf8 DEFAULT '' COMMENT '名称',
  `unit` varchar(255) CHARACTER SET utf8 DEFAULT '' COMMENT '单位',
  `remark` varchar(1000) CHARACTER SET utf8 DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`),
  KEY `sub_id` (`spid`),
  KEY `tid` (`tid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT = '合同管理树结构表';

CREATE TABLE `zh_contract` (
  `id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) DEFAULT NULL COMMENT '合同类型(1是支出，2是收入)',
  `uid` int(11) DEFAULT NULL COMMENT '创建人id',
  `contract_id` int(11) NOT NULL COMMENT '节点id',
  `contract_pid` int(11) NOT NULL COMMENT '父节点id',
  `level` tinyint(4) NOT NULL COMMENT '层级',
  `is_leaf` tinyint(1) DEFAULT '1' COMMENT '是否是子节点',
  `order` mediumint(4) NOT NULL DEFAULT '0' COMMENT '同级排序',
  `full_path` varchar(255) CHARACTER SET utf8 DEFAULT '' COMMENT '层级定位辅助字段parent.full_path.contract_id',
  `c_code` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '合同编号',
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同名称',
  `total_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '合同金额',
  `pay_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '累计支付（回款）金额',
  `debit_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '累计扣款金额',
  `yf_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '累计应付（应回）金额',
  `sf_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '累计已付（已回）金额',
  `party_a` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '甲方',
  `party_a_user` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '甲方签约人',
  `party_b` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '乙方',
  `party_b_user` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '乙方签约人',
  `sign_date` datetime DEFAULT NULL COMMENT '签订日期',
  `address` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '签约地点',
  `entity` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '单位',
  `bank` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '开户行',
  `bank_account` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '收款账号',
  `settle_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '结算书编号',
  `remark` varchar(1000) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '备注',
  `exist_pay` tinyint(1) DEFAULT '0' COMMENT '是否存在合同支付（回款）',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='合同详情表';

CREATE TABLE `zh_contract_pay` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) NOT NULL COMMENT '合同类型(1是支出，2是收入)',
  `cid` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '合同详情id',
  `uid` int(11) DEFAULT NULL COMMENT '创建人id',
  `pay_time` datetime DEFAULT NULL COMMENT '支付日期',
  `pay_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '付款金额',
  `debit_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '扣款金额',
  `yf_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '应付（回）金额',
  `sf_price` decimal(30,8) DEFAULT '0.00000000' COMMENT '实付金额',
  `pay_type` varchar(50) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '支付方式',
  `remark` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '备注',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT = '合同支付表';

CREATE TABLE `zh_contract_pay_attachment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) NOT NULL COMMENT '合同类型(1是支出，2是收入)',
  `cid` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '合同详情id',
  `cpid` int(11) NOT NULL COMMENT '合同支付id',
  `uid` int(11) NOT NULL COMMENT '上传者id',
  `filename` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件名称',
  `fileext` varchar(5) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
  `filesize` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件大小',
  `filepath` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
  `upload_time` datetime NOT NULL COMMENT '上传时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_cid` (`cpid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '合同支付附件表';

CREATE TABLE `zh_contract_attachment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) NOT NULL COMMENT '合同类型(1是支出，2是收入)',
  `cid` varchar(100) COLLATE utf8_unicode_ci NOT NULL COMMENT '合同详情id',
  `uid` int(11) NOT NULL COMMENT '上传者id',
  `filename` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件名称',
  `fileext` varchar(5) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
  `filesize` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件大小',
  `filepath` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
  `upload_time` datetime NOT NULL COMMENT '上传时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_cid` (`cid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '合同文件表';

CREATE TABLE `zh_contract_audit` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `uid` int(11) NOT NULL COMMENT '用户id',
  `permission_add` tinyint(1) DEFAULT '0' COMMENT '添加合同权限',
  `permission_edit` tinyint(1) DEFAULT '0' COMMENT '编辑节点权限',
  `permission_show_unit` tinyint(1) DEFAULT '0' COMMENT '查看该节点下同单位下合同权限',
  `permission_show_node` tinyint(1) DEFAULT '0' COMMENT '查看该节点下所有合同权限',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '合同权限用户表';

CREATE TABLE `zh_contract_tree_audit` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `spid` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '项目id',
  `tid` int(11) DEFAULT NULL COMMENT '标段id',
  `contract_type` tinyint(1) DEFAULT NULL COMMENT '合同类型(1是支出，2是收入)',
  `contract_id` int(11) DEFAULT NULL COMMENT '节点id',
  `uid` int(11) DEFAULT NULL COMMENT '节点授权人id',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '合同节点授权用户表';

-- update请放在最后

Update zh_filing_template SET is_fixed = 1 WHERE tree_level = 1;
