CREATE TABLE supplier_ms.CONTRACT_SALES_ORDER (
    ID INT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    CONTRACT_ID INT NOT NULL COMMENT '合同ID',
    EMPLOYEE_ID INT COMMENT '业务员ID',
    CODE VARCHAR(50) COMMENT '单据编号',
    REF_ID INT COMMENT '引用ID',
    TAX_RATE FLOAT COMMENT '税率',
    CUSTOMER_ID INT COMMENT '客户ID',
    CUSTOMER_PERSON_ID INT COMMENT '客户联系人ID',
    CUSTOMER_ADDRESS VARCHAR(255) COMMENT '客户地址',
    MAKER_ID INT COMMENT '制单人ID',
    MAKER_DATE DATE COMMENT '制单日期',
    VERIFIER_ID INT COMMENT '审核人ID',
    VERIFIED_DATE DATE COMMENT '审核日期',
    MODIFIER_ID INT COMMENT '修改人ID',
    MODIFIED_DATE DATE COMMENT '修改日期',
    CLOSER_ID INT COMMENT '关闭人ID',
    CLOSED_DATE DATE COMMENT '关闭日期',
    DESCRIPTION TEXT COMMENT '备注',
    PRIMARY KEY (ID),
    INDEX IDX_SALES_ORDER_CONTRACT (CONTRACT_ID),
    INDEX IDX_SALES_ORDER_EMPLOYEE (EMPLOYEE_ID),
    INDEX IDX_SALES_ORDER_CUSTOMER (CUSTOMER_ID),
    INDEX IDX_SALES_ORDER_CUSTOMER_PERSON (CUSTOMER_PERSON_ID),
    INDEX IDX_SALES_ORDER_MAKER (MAKER_ID),
    INDEX IDX_SALES_ORDER_VERIFIER (VERIFIER_ID),
    INDEX IDX_SALES_ORDER_MODIFIER (MODIFIER_ID),
    INDEX IDX_SALES_ORDER_CLOSER (CLOSER_ID),
    CONSTRAINT FK_SALES_ORDER_CONTRACT FOREIGN KEY (CONTRACT_ID) REFERENCES supplier_ms.CONTRACT (ID) ON DELETE CASCADE ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_EMPLOYEE FOREIGN KEY (EMPLOYEE_ID) REFERENCES supplier_ms.EMPLOYEE (ID) ON DELETE SET NULL ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_CUSTOMER FOREIGN KEY (CUSTOMER_ID) REFERENCES supplier_ms.COMPANY (ID) ON DELETE SET NULL ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_CUSTOMER_PERSON FOREIGN KEY (CUSTOMER_PERSON_ID) REFERENCES supplier_ms.EMPLOYEE (ID) ON DELETE SET NULL ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_MAKER FOREIGN KEY (MAKER_ID) REFERENCES supplier_ms.EMPLOYEE (ID) ON DELETE SET NULL ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_VERIFIER FOREIGN KEY (VERIFIER_ID) REFERENCES supplier_ms.EMPLOYEE (ID) ON DELETE SET NULL ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_MODIFIER FOREIGN KEY (MODIFIER_ID) REFERENCES supplier_ms.EMPLOYEE (ID) ON DELETE SET NULL ON UPDATE NO ACTION,
    CONSTRAINT FK_SALES_ORDER_CLOSER FOREIGN KEY (CLOSER_ID) REFERENCES supplier_ms.EMPLOYEE (ID) ON DELETE SET NULL ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='销售订单表';