--ABS-77806
CREATE TABLE ERP_O_ARTRANSACTION
(
  TRANSFER_ID              NUMBER NOT NULL,
  TRANSFER_STATUS          NUMBER DEFAULT 0 NOT NULL CONSTRAINT CHK_ERP_O_ARTRANSACTION_V1 CHECK (TRANSFER_STATUS IN (-1,0,1)),
  BUSINESSUNITCODE         VARCHAR2(6) NOT NULL,
  LEGALENTITYCODE          VARCHAR2(10) NULL,
  BILL2BUSINESSUNITCODE    VARCHAR2(6) NOT NULL,
  BILL2LEGALENTITYCODE     VARCHAR2(10) NULL,
  BILLTO_CUSTOMER          NUMBER NOT NULL,
  BILLTO_NAME              VARCHAR2(40) NOT NULL,
  DELTOBUSINESSUNITCODE    VARCHAR2(6) NULL,
  DELTOLEGALENTITYCODE     VARCHAR2(10) NULL,
  CUSTOMERNUMBER           NUMBER NULL,
  NAME                     VARCHAR2(40) NULL,
  ARTRANSACTIONDATE        DATE NOT NULL,
  INVOICEDATE              DATE NULL,
  INVOICENUMBER            NUMBER NOT NULL,
  CURRENCY                 VARCHAR2(3) NOT NULL,
  AMOUNT                   NUMBER NULL,
  DEBITCREDIT              VARCHAR2(1) NOT NULL,
  PAYMENTTYPE              VARCHAR2(20) NULL,
  ARTRANSACTIONTYPE        NUMBER NOT NULL,
  ARTRANSACTIONTYPE_CODE   VARCHAR2(3) NOT NULL,
  ARTRANSACTIONTYPE_DESC   VARCHAR2(30) NULL,
  REMITIDENTIFICATION      VARCHAR2(16) NULL,
  REMARK                   VARCHAR2(250) NULL,
  TURNOVERGROUP            VARCHAR2(12) NULL,
  LEGACYCODE               VARCHAR2(6) NULL,
  MAXACCOUNTNUMBER         NUMBER NULL,
  ARTRANSACTION_LEGACYCODE VARCHAR2(6) NULL,
  CREDITEDINV              NUMBER NULL,
  CREDITINV_DATE           DATE NULL,
  CREDIT_PAYMENTTYPE       VARCHAR2(20) NULL,
  PAYMENTREFERENCE         VARCHAR2(250) NULL,
  MULE_ERR_CODE            VARCHAR2(20) NULL,
  MULE_ERR_DESC            VARCHAR2(200) NULL,
  MULE_BATCH_ID            NUMBER NULL,
  MULE_STATUS              VARCHAR2(1) DEFAULT 'C' NULL,
  MULE_TIMESTAMP           DATE NULL
);
ALTER TABLE ERP_O_ARTRANSACTION
  ADD CONSTRAINT PK_ERP_O_ARTRANSACTION PRIMARY KEY (TRANSFER_ID);
CREATE INDEX INDX_ERP_O_ARTRANSACTION_STAT ON ERP_O_ARTRANSACTION(TRANSFER_STATUS);

-- ERP_O_ARTRANSACTION_LOG --
CREATE TABLE ERP_O_ARTRANSACTION_LOG
(
  TRANSFER_ID     NUMBER NOT NULL,
  TRANSFER_STATUS NUMBER DEFAULT 0 NOT NULL CONSTRAINT CHK_ERP_O_ARTRANS_LOG2_LOG_V1 CHECK (TRANSFER_STATUS IN (-1,0,1)),
  TEXT            VARCHAR2(1000) NULL,
  PROCESS_STATUS  NUMBER DEFAULT 0 NOT NULL,
  TIMESTAMP       DATE DEFAULT SYSDATE NOT NULL
);
COMMENT ON COLUMN  ERP_O_ARTRANSACTION_LOG.TRANSFER_STATUS
  IS '0 = ready to be read, 1 = read correctly';
COMMENT ON COLUMN  ERP_O_ARTRANSACTION_LOG.PROCESS_STATUS
  IS '0 = processed correctly, 1 = process stopped with errors';
ALTER TABLE ERP_O_ARTRANSACTION_LOG
  ADD CONSTRAINT PK_ERP_O_ARTRANSACTION_LOG PRIMARY KEY (TRANSFER_ID);
ALTER TABLE ERP_O_ARTRANSACTION_LOG
  ADD CONSTRAINT FK_ERP_O_ARTRANSACTION_LOG FOREIGN KEY (TRANSFER_ID)
  REFERENCES ERP_O_ARTRANSACTION(TRANSFER_ID) ON DELETE CASCADE;