CREATE TABLE supplier_ms.CONTRACT_INVOICE (
  ID INT NOT NULL AUTO_INCREMENT,
  CODE VARCHAR(50) NULL,
  NAME VARCHAR(200) NULL,
  CONTRACT_ID INT NULL,
  INVOICE_ID INT NULL,
  AMOUNT DOUBLE NULL,
  SETUP_PERSON_ID INT NULL,
  SETUP_DATE DATE NULL,
  UPDATE_PERSON_ID INT NULL,
  UPDATE_DATE DATE NULL,
  REMARK VARCHAR(500) NULL,
  PRIMARY KEY (ID),
  INDEX FK_CONTRACT_INVOICE_CONTRACT_idx (CONTRACT_ID ASC) VISIBLE,
  INDEX FK_CONTRACT_INVOICE_INVOICE_idx (INVOICE_ID ASC) VISIBLE,
  INDEX FK_CONTRACT_INVOICE_SETUP_PERSON_idx (SETUP_PERSON_ID ASC) VISIBLE,
  INDEX FK_CONTRACT_INVOICE_UPDATE_PERSON_idx (UPDATE_PERSON_ID ASC) VISIBLE,
  CONSTRAINT FK_CONTRACT_INVOICE_CONTRACT
    FOREIGN KEY (CONTRACT_ID)
    REFERENCES supplier_ms.CONTRACT (ID)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT FK_CONTRACT_INVOICE_INVOICE
    FOREIGN KEY (INVOICE_ID)
    REFERENCES supplier_ms.INVOICE (ID)
    ON DELETE SET NULL
    ON UPDATE NO ACTION,
  CONSTRAINT FK_CONTRACT_INVOICE_SETUP_PERSON
    FOREIGN KEY (SETUP_PERSON_ID)
    REFERENCES supplier_ms.EMPLOYEE (ID)
    ON DELETE SET NULL
    ON UPDATE NO ACTION,
  CONSTRAINT FK_CONTRACT_INVOICE_UPDATE_PERSON
    FOREIGN KEY (UPDATE_PERSON_ID)
    REFERENCES supplier_ms.EMPLOYEE (ID)
    ON DELETE SET NULL
    ON UPDATE NO ACTION);