--ABSN-1932
CREATE TABLE ERP_I_INVOICEHEADER_OPENAMOUNT
(
  TRANSFER_ID          NUMBER NOT NULL,
  TRANSFER_STATUS      NUMBER DEFAULT 0 NOT NULL,
  INVOICENUMBER        NUMBER NOT NULL,
  BILLTOCUSTOMERNUMBER NUMBER NOT NULL,
  DELTOCUSTOMERNUMBER  NUMBER,
  OPENAMOUNT           NUMBER(28,6) NOT NULL,
  TIMESTAMP            DATE DEFAULT SYSDATE NOT NULL
);
CREATE INDEX INDX_ERP_I_INVOICEHEADER_OPENAMOUNT ON ERP_I_INVOICEHEADER_OPENAMOUNT (TRANSFER_STATUS);
ALTER TABLE ERP_I_INVOICEHEADER_OPENAMOUNT ADD CONSTRAINT PK_ERP_I_INVOICEHEADER_OPENAMOUNT PRIMARY KEY (TRANSFER_ID);
comment on column ERP_I_INVOICEHEADER_OPENAMOUNT.openamount
  is 'will be used to update the paid amount of the invoiceheader, paythisamount-openamount';
  
CREATE TABLE ERP_I_INVOICEHEADER_OPENAMOUNT_LOG
(
  TRANSFER_ID     NUMBER NOT NULL,
  TRANSFER_STATUS NUMBER DEFAULT 0 NOT NULL,
  TEXT            VARCHAR2(1000),
  PROCESS_STATUS  NUMBER NOT NULL,
  TIMESTAMP       DATE NOT NULL
);
ALTER TABLE ERP_I_INVOICEHEADER_OPENAMOUNT_LOG
  ADD CONSTRAINT PK_ERP_I_INVOICEHEADER_OPENAMOUNT_LOG PRIMARY KEY (TRANSFER_ID);
ALTER TABLE ERP_I_INVOICEHEADER_OPENAMOUNT_LOG
  ADD CONSTRAINT FK_ERP_I_INVOICEHEADER_OPENAMOUNT_LOG FOREIGN KEY (TRANSFER_ID)
  REFERENCES ERP_I_INVOICEHEADER_OPENAMOUNT (TRANSFER_ID) ON DELETE CASCADE;
ALTER TABLE ERP_I_INVOICEHEADER_OPENAMOUNT_LOG
  ADD CONSTRAINT CHK_INVHEADER_OPENAMOUNT_TRANSFERSTATUS
  CHECK (TRANSFER_STATUS IN (-1,0,1));  
