


CREATE TABLE fin_payment_plan (
                                  id bigint(20) auto_increment NOT NULL COMMENT '付款计划主键',
                                  payment_plan_no varchar(50) NULL COMMENT '付款计划单号',
                                  payment_plan_year varchar(10) NULL COMMENT '付款计划年份',
                                  payment_plan_month varchar(10) NULL COMMENT '付款计划月份',
                                  status int NULL COMMENT '数据状态：',
                                  plan_type varchar(4) NULL COMMENT '计划类型: S:区分汇总,N:不区分汇总',
                                  purchase_confirm_time datetime DEFAULT NULL COMMENT '采购确认时间',
                                  purchase_confirm_user_id bigint(20) DEFAULT NULL COMMENT '采购确认人',
                                  finance_confirm_time datetime DEFAULT NULL COMMENT '财务确认时间',
                                  finance_confirm_user_id bigint(20) DEFAULT NULL COMMENT '财务确认人',
                                  create_user_id bigint(20) NULL COMMENT '创建用户ID',
                                  create_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '创建用户编码',
                                  create_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '创建用户姓名',
                                  create_time datetime NULL COMMENT '创建时间',
                                  update_user_id bigint(20) NULL COMMENT '最后更新用户ID',
                                  update_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '最后更新用户编码',
                                  update_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '最后更新用户姓名',
                                  update_time datetime NULL COMMENT '最后更新时间',
                                  delete_flag int(11) DEFAULT 0 NULL COMMENT '删除标识 0:未删除 1:已删除',
                                  oa_process_id varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'OA审批流程ID',
                                  oa_process_no varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'OA审批流程号',
                                  push_oa_num int(11) DEFAULT 0 NULL COMMENT '推送OA次数(后续推送OA时赋值价格组审批流程号, 价格组审批流程号: 计划单号+推送OA次数)',
                                  push_oa_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '推送OA员工工号',
                                  push_oa_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '推送OA员工姓名',
                                  remark varchar(500) NULL COMMENT '备注',
                                  PRIMARY KEY (`id`) USING BTREE
)
    ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin
COMMENT='付款计划主表';



CREATE TABLE fin_payment_plan_detail (
                                         id bigint(20) auto_increment NOT NULL COMMENT '付款计划明细表主键',
                                         payment_plan_detail_no int(11) NULL COMMENT '付款计划明细行号按主表单号自动增加',
                                         payment_plan_no varchar(50) NULL COMMENT '付款计划单号',
                                         payment_plan_id bigint(20) NULL COMMENT '付款计划主键',
                                         status int NULL COMMENT '行状态1待提交 2已提交 3删除',
                                         account_statement_year varchar(10) NULL COMMENT '对账单的对账年份',
                                         account_statement_month varchar(10) NULL COMMENT '对账单的对账月份',
                                         account_statement_ym varchar(10) NULL COMMENT '对账单的年月',
                                         account_statement_id bigint(20) NULL COMMENT '付款计划主键',
                                         account_statement_no varchar(30) NULL COMMENT '对账单编号',
                                         company_code varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '采购公司代码',
                                         company_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '采购公司名称',
                                         supplier_code varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '供应商代码',
                                         supplier_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '供应商名称',
                                         factory_code varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '工厂编码',
                                         factory_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '工厂名称',
                                         currency_code varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '货币代码',

                                         actual_pay_amount decimal(20,6) NULL COMMENT '应付金额',
                                         applied_unpaid_amount decimal(20,6) NULL COMMENT '已请款未付金额（历史）',
                                         payment_term_code varchar(50) NULL COMMENT '付款条件',
                                         payment_way varchar(50) NULL COMMENT '付款方式',
                                         purchase_group varchar(255) NULL COMMENT '采购组编码',
                                         payment_plan_week varchar(10) NULL COMMENT '付款计划周(对账单上付款到期日所在周)',
                                         payment_expire_date datetime NULL COMMENT '付款到期日',
                                         create_user_id bigint(20) NULL COMMENT '创建用户ID',
                                         create_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '创建用户编码',
                                         create_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '创建用户姓名',
                                         create_time datetime NULL COMMENT '创建时间',
                                         update_user_id bigint(20) NULL COMMENT '最后更新用户ID',
                                         update_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '最后更新用户编码',
                                         update_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '最后更新用户姓名',
                                         update_time datetime NULL COMMENT '最后更新时间',
                                         delete_flag int(11) DEFAULT 0 NULL COMMENT '删除标识 0:未删除 1:已删除',
                                         new_sign varchar(4) NULL COMMENT '新增标识',
                                         payment_type varchar(4) NULL COMMENT '汇总类型: D 对账单明细，Y 预付款明细',
                                         remark varchar(500) NULL COMMENT '备注',
                                         PRIMARY KEY (`id`) USING BTREE
)
    ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin
COMMENT='付款计划明细表';


CREATE TABLE fin_payment_plan_summary (
                                          id bigint(20) auto_increment NOT NULL COMMENT '付款计划汇总主键',
                                          payment_plan_no varchar(50) NULL COMMENT '付款计划单号',
                                          payment_plan_id bigint(20) NULL COMMENT '付款计划主键',
                                          supplier_code varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '供应商代码',
                                          supplier_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '供应商名称',
                                          company_code varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '采购公司代码',
                                          company_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '采购公司名称',
                                          currency_code varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '货币代码',
                                          actual_pay_amount decimal(20,6) NULL COMMENT '应付金额',
                                          applied_unpaid_amount decimal(20,6) NULL COMMENT '已请款未付金额（历史）',
                                          applied_payment_amount decimal(20,6) NULL COMMENT '本月已请款金额',
                                          difference_amount decimal(20,6) NULL COMMENT '差异金额',
                                          difference_percent decimal(20,6) NULL COMMENT '差异比例',
                                          paid_amount_month decimal(20,6) NULL COMMENT '本月已付金额',
                                          remark varchar(500) NULL COMMENT '备注',
                                          create_user_id bigint(20) NULL COMMENT '创建用户ID',
                                          create_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '创建用户编码',
                                          create_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '创建用户姓名',
                                          create_time datetime NULL COMMENT '创建时间',
                                          update_user_id bigint(20) NULL COMMENT '最后更新用户ID',
                                          update_user_code varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '最后更新用户编码',
                                          update_user_name varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '最后更新用户姓名',
                                          update_time datetime NULL COMMENT '最后更新时间',
                                          delete_flag int(11) DEFAULT 0 NULL COMMENT '删除标识 0:未删除 1:已删除',
                                          new_sign varchar(4) NULL COMMENT '新增标识',
                                          payment_type varchar(4) NULL COMMENT '汇总类型: D 对账单汇总，Y 预付款汇总',
                                          PRIMARY KEY (`id`) USING BTREE
)
    ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin
COMMENT='付款计划汇总表';


CREATE TABLE `fin_payment_plan_approve` (
                                            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '数据主键ID',
                                            `pp_id` bigint(20) DEFAULT NULL COMMENT '付款计划单ID',
                                            `pp_no` varchar(30) DEFAULT NULL COMMENT '付款计划单号',
                                            `approve_result` int(11) DEFAULT NULL COMMENT '审批结果 0:拒绝 1:同意 2:财务撤销',
                                            `approve_opinion` varchar(255) DEFAULT NULL COMMENT '审批意见',
                                            `approve_user_id` bigint(20) DEFAULT NULL COMMENT '审批用户ID',
                                            `approve_user_code` varchar(60) DEFAULT NULL COMMENT '审批用户编码',
                                            `approve_user_name` varchar(60) DEFAULT NULL COMMENT '审批用户姓名',
                                            `approve_node` int(11) DEFAULT NULL COMMENT '审批节点 1:采购节点 2:财务节点',
                                            `approve_time` datetime DEFAULT NULL COMMENT '审批时间',
                                            PRIMARY KEY (`id`) USING BTREE,
                                            KEY `i_pp_id` (`pp_id`) USING BTREE,
                                            KEY `i_pp_no` (`pp_no`) USING BTREE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_bin
COMMENT='付款计划审批记录表';


ALTER TABLE fin_payment_cod_apply ADD pay_plan_money decimal(20,6) NULL COMMENT '付款计划金额';
ALTER TABLE fin_payment_advance_apply ADD pay_plan_money decimal(20,6) NULL COMMENT '付款计划金额';
ALTER TABLE fin_invoiced_apply ADD new_payment_expire_date datetime NULL COMMENT '新的付款到期日';



