CREATE TABLE `settlement_his_goods_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `settlement_his_info_id` bigint(20) NOT NULL COMMENT '结算单历史信息表ID',
  `acceptance_basic_info_id` bigint(20) NOT NULL COMMENT '验收单基础信息表ID',
  `acceptance_goods_info_id` bigint(20) NOT NULL COMMENT '验收单货物信息表ID',
  `sales_price` decimal(17,4) DEFAULT NULL COMMENT '销售单价',
  `sales_total_price` decimal(17,4) DEFAULT NULL COMMENT '销售总价',
  `sales_guarantee_money` decimal(17,4) DEFAULT NULL COMMENT '销售质保金',
  `purchase_price` decimal(17,4) DEFAULT NULL COMMENT '采购单价',
  `purchase_total_price` decimal(17,4) DEFAULT NULL COMMENT '采购总价',
  `purchase_guarantee_money` decimal(17,4) DEFAULT NULL COMMENT '采购质保金',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  `reference_price` decimal(17,2) DEFAULT NULL COMMENT '参考价格',
  `floating_price` decimal(17,2) DEFAULT NULL COMMENT '浮动价格',
  `acceptance_goods_number` varchar(30) DEFAULT NULL COMMENT '验收单编号',
  `goods_quantity` decimal(17,4) DEFAULT NULL COMMENT '数量',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='结算单-下游历史结算货物信息表';

CREATE TABLE `c_settlement_basic_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `settlement_number` varchar(50) DEFAULT NULL COMMENT '结算单号',
  `business_number` varchar(50) DEFAULT NULL COMMENT '业务编号',
  `supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
  `enterprise_customer_info_id` bigint(20) DEFAULT NULL COMMENT '核心企业Id',
  `trading_platform_id` bigint(20) DEFAULT NULL COMMENT '贸易平台Id',
  `settlement_date` datetime DEFAULT NULL COMMENT '结算日期',
  `settlement_amount` decimal(17,2) DEFAULT NULL COMMENT '结算金额',
  `settlement_start_date` datetime DEFAULT NULL COMMENT '对账开始日期',
  `settlement_end_date` datetime DEFAULT NULL COMMENT '对账结束日期',
  `operator_supplier` varchar(200) DEFAULT NULL COMMENT '经办人（供应商）',
  `operator_enterprise` varchar(200) DEFAULT NULL COMMENT '经办人（核心企业）',
  `additional_remarks` varchar(500) DEFAULT NULL COMMENT '补充说明信息',
  `settlement_status` varchar(100) DEFAULT NULL COMMENT '状态: 已录入、已驳回、待签署，已签署，签署已审核',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  `contract_id` varchar(1024) DEFAULT NULL COMMENT '结算单合同id',
  `business_name` varchar(50) DEFAULT '' COMMENT '业务名称',
  `count_the_goods` varchar(255) DEFAULT NULL COMMENT '结算货物数量',
  `settle_total_sales_price` decimal(17,2) DEFAULT NULL COMMENT '结算销售总价',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=518 DEFAULT CHARSET=utf8 COMMENT='结算单-基础信息表';

CREATE TABLE `c_settlement_goods_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_settlement_basic_info_id` bigint(20) NOT NULL COMMENT '结算单基础信息表ID',
  `acceptance_goods_number` varchar(30) DEFAULT NULL COMMENT '验收单编号',
  `c_acceptance_basic_info_id` bigint(20) NOT NULL COMMENT '验收单基础信息表ID',
  `c_acceptance_goods_info_id` bigint(20) NOT NULL COMMENT '验收单货物信息表ID',
  `sales_price` decimal(17,4) DEFAULT NULL COMMENT '销售单价',
  `sales_total_price` decimal(17,4) DEFAULT NULL COMMENT '销售总价',
  `sales_guarantee_money` decimal(17,4) DEFAULT NULL COMMENT '销售质保金',
  `purchase_price` decimal(17,4) DEFAULT NULL COMMENT '采购单价',
  `purchase_total_price` decimal(17,4) DEFAULT NULL COMMENT '采购总价',
  `purchase_guarantee_money` decimal(17,4) DEFAULT NULL COMMENT '采购质保金',
  `is_invoiced` tinyint(1) DEFAULT NULL COMMENT '是否已开票，0:未开票 1:开票被选中未审核完成 2:已开票（审核完成）',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  `reference_price` decimal(17,2) DEFAULT NULL COMMENT '参考价格',
  `floating_price` decimal(17,2) DEFAULT NULL COMMENT '浮动价格',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8 COMMENT='结算单-下游结算货物信息表';


CREATE TABLE `c_settlement_electronic_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_settlement_basic_info_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表id',
  `certify_link` varchar(1024) DEFAULT NULL COMMENT '认证链接',
  `certify_status` tinyint(1) DEFAULT NULL COMMENT '认证状态',
  `contract_link` varchar(1024) DEFAULT NULL COMMENT '合同链接',
  `sign_status` tinyint(1) DEFAULT NULL COMMENT '签署状态',
  `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  `short_contract_link` varchar(1024) DEFAULT NULL COMMENT '签署短链接',
  `short_contract_link_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '签署短链接创建时间',
  `transaction_id` varchar(255) DEFAULT NULL COMMENT '客户合同交易id',
  `sign_comment` varchar(3000) DEFAULT '' COMMENT '审批意见',
  `sign_conclusion` varchar(50) DEFAULT '' COMMENT '审批结论',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='结算单-电子合同信息表';


CREATE TABLE `c_settlement_repayment_plan` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_settlement_basic_info_id` bigint(20) NOT NULL COMMENT '结算单基础信息表ID',
  `repayment_amount` decimal(17,2) DEFAULT NULL COMMENT '回款金额',
  `repayment_date` datetime DEFAULT NULL COMMENT '回款日期',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=449 DEFAULT CHARSET=utf8 COMMENT='结算单-回款计划表';

CREATE TABLE `c_invoice_basic_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `business_number` varchar(50) DEFAULT NULL COMMENT '业务编号',
  `enterprise_customer_info_id` bigint(20) DEFAULT NULL COMMENT '核心企业Id',
  `trading_platform_id` bigint(20) DEFAULT NULL COMMENT '贸易平台Id',
  `tax_identify_number` varchar(64) DEFAULT NULL COMMENT '纳税识别号',
  `address` varchar(500) DEFAULT NULL COMMENT '地址',
  `phone` varchar(50) DEFAULT NULL COMMENT '电话',
  `account_bank_name` varchar(500) DEFAULT NULL COMMENT '开户行名称',
  `account_number` varchar(50) DEFAULT NULL COMMENT '开户账号',
  `invoice_type` varchar(50) DEFAULT NULL COMMENT '发票类型',
  `amount_kind` varchar(50) DEFAULT NULL COMMENT '金额种类',
  `invoice_status` bigint(20) unsigned DEFAULT '0' COMMENT '发票状态 已申请、已驳回、已开票',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `product_broad_info` varchar(255) DEFAULT NULL COMMENT '商品大类信息',
  `open_amount` decimal(17,2) DEFAULT NULL COMMENT '开票金额',
  `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=205 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='发票管理-基本信息表';


CREATE TABLE `c_invoice_customer_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `customer_id` bigint(20) NOT NULL COMMENT '核心企业Id',
  `enterprise_name` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '公司名称',
  `social_credit_code` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '纳税识别号',
  `address` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '地址',
  `phone_number` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '电话',
  `account_bank_name` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '开户行名称',
  `account_number` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '开户行名称',
  `user_create` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(32) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  `remark` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '备注信息',
  `business_basic_info_id` bigint(20) DEFAULT NULL COMMENT '项目基本信息表id',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='发票管理-核心企业开票信息表';

CREATE TABLE `c_invoice_goods_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_invoice_basic_info_id` bigint(20) DEFAULT NULL COMMENT '发票基础信息表ID',
  `c_settlement_basic_info_id` bigint(20) DEFAULT NULL COMMENT '结算单基础信息表ID',
  `c_settlement_goods_info_id` bigint(20) DEFAULT NULL COMMENT '结算单货物信息表ID',
  `settlement_number` varchar(50) DEFAULT NULL COMMENT '验收单编号',
  `goods_name` varchar(500) DEFAULT NULL COMMENT '货物名称',
  `goods_factory` varchar(500) DEFAULT NULL COMMENT '厂家',
  `goods_type` varchar(500) DEFAULT NULL COMMENT '型号',
  `goods_unit` varchar(250) DEFAULT NULL COMMENT '单位',
  `goods_quantity` decimal(17,4) DEFAULT NULL COMMENT '数量',
  `sales_price` decimal(17,2) DEFAULT NULL COMMENT '销售单价',
  `sales_total_price` decimal(17,2) DEFAULT NULL COMMENT '销售总价',
  `open_quantity` decimal(17,4) DEFAULT NULL COMMENT '开票数量',
  `open_amount` decimal(17,2) DEFAULT NULL COMMENT '开票金额',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=5050 DEFAULT CHARSET=utf8 COMMENT='发票管理-货物历史信息表';

CREATE TABLE `c_invoice_possession_cost_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_invoice_basic_info_id` bigint(20) DEFAULT NULL COMMENT '发票基础信息表ID',
  `possession_cost_type` bigint(20) DEFAULT NULL COMMENT '资金占用费类型',
  `possession_cost` decimal(17,2) DEFAULT NULL COMMENT '资金占用费',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=202 DEFAULT CHARSET=utf8 COMMENT='发票管理-资金占用费信息表';


CREATE TABLE `c_invoice_supplier_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_invoice_basic_info_id` bigint(20) DEFAULT NULL COMMENT '发票基础信息表ID',
  `c_supplier_id` bigint(20) DEFAULT NULL COMMENT '供应商Id',
  `c_supplier_name` varchar(50) DEFAULT NULL COMMENT '供应商名称',
  `open_amount` decimal(17,2) DEFAULT NULL COMMENT '开票金额',
  `user_create` varchar(50) DEFAULT '' COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT '' COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='发票管理-供应商信息表';


CREATE TABLE `c_purchase_invoice_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_invoice_basic_info_id` bigint(20) DEFAULT NULL COMMENT '发票基础信息表ID',
  `invoice_number` varchar(50) DEFAULT NULL COMMENT '发票号码',
  `invoice_num` bigint(20) DEFAULT NULL COMMENT '数量',
  `amount` decimal(17,2) DEFAULT NULL COMMENT '金额',
  `tax_amount` decimal(17,2) DEFAULT NULL COMMENT '税额',
  `price_tax_total` decimal(17,2) DEFAULT NULL COMMENT '价税合计',
  `seller_name` varchar(100) DEFAULT NULL COMMENT '销售方名称',
  `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=207 DEFAULT CHARSET=utf8 COMMENT='发票管理-采购发票信息表';

CREATE TABLE `c_sales_invoice_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `c_invoice_basic_info_id` bigint(20) DEFAULT NULL COMMENT '发票基础信息表ID',
  `sales_invoice_num` bigint(20) DEFAULT NULL COMMENT '数量',
  `amount` decimal(17,2) DEFAULT NULL COMMENT '金额',
  `tax_amount` decimal(17,2) DEFAULT NULL COMMENT '税额',
  `price_tax_total` decimal(17,2) DEFAULT NULL COMMENT '价税合计',
  `invoice_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
  `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=188 DEFAULT CHARSET=utf8 COMMENT='发票管理-财务审核-销售发票信息';

CREATE TABLE `purchase_invoice_his_info` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `invoice_his_info_id` bigint(20) DEFAULT NULL COMMENT '发票历史信息表ID',
  `invoice_number` varchar(50) DEFAULT NULL COMMENT '发票号码',
  `invoice_num` bigint(20) DEFAULT NULL COMMENT '数量',
  `amount` decimal(17,2) DEFAULT NULL COMMENT '金额',
  `tax_amount` decimal(17,2) DEFAULT NULL COMMENT '税额',
  `price_tax_total` decimal(17,2) DEFAULT NULL COMMENT '价税合计',
  `seller_name` varchar(100) DEFAULT NULL COMMENT '销售方名称',
  `user_create` varchar(50) DEFAULT NULL COMMENT '创建人',
  `user_modified` varchar(50) DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=209 DEFAULT CHARSET=utf8 COMMENT='发票管理-采购发票信息历史表';

INSERT INTO `t_dictionary`( `name`,  `code`, `value`, `gradation`) VALUES ( '发票状态',  'invoice_status', NULL, 0);

INSERT INTO `t_dictionary`(`name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '处理中', (select t.id from t_dictionary t where t.code = 'invoice_status'), 'invoice_processing', NULL, 0);
INSERT INTO `t_dictionary`(`name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '已完成',  (select t.id from t_dictionary t where t.code = 'invoice_status'), 'invoice_completed', NULL, 1);
INSERT INTO `t_dictionary`( `name`, `parentId`, `code`, `value`, `gradation`) VALUES ( '已终止',  (select t.id from t_dictionary t where t.code = 'invoice_status'), 'invoice_terminated', NULL, 2);