-- ABS-63328

--------------- PLANTTAXEXPORTSETTINGS ---------------
CREATE TABLE PLANTTAXEXPORTSETTINGS
( PLANT_ID          NUMBER NOT NULL,
  REQUESTSEQUENCENR NUMBER NOT NULL,
  LOGINNAME         VARCHAR2(15) NOT NULL,
  PASSWORDHASH      VARCHAR2(128) NOT NULL,
  TAXNUMBER         VARCHAR2(8) NOT NULL,
  SIGNATUREKEY      VARCHAR2(16) NOT NULL,
  REPLACEMENTKEY    VARCHAR2(16) NOT NULL,
  ENVIRONMENT       VARCHAR2(50) NOT NULL,
  SYSTEMUSER_ID     NUMBER NOT NULL,
  TIMESTAMP         DATE NOT NULL);

COMMENT ON COLUMN PLANTTAXEXPORTSETTINGS.REQUESTSEQUENCENR
  IS 'The requestnumber will consist of [Plantcode][year][RequestSequencenr]';

ALTER TABLE PLANTTAXEXPORTSETTINGS
  ADD CONSTRAINT XPKPLANTTAXEXPORTSETTINGS PRIMARY KEY (PLANT_ID);
ALTER TABLE PLANTTAXEXPORTSETTINGS
  ADD CONSTRAINT PLANTTAXEXPORTSETTINGS_PLANT FOREIGN KEY (PLANT_ID)
  REFERENCES PLANT (PLANT_ID) ON DELETE CASCADE;


--------------- INVOICEHEADERTAXEXPORT ---------------
CREATE TABLE INVOICEHEADERTAXEXPORT
( INVOICEHEADER_ID NUMBER NOT NULL,
  REQUESTNUMBER    VARCHAR2(20) NOT NULL,
  EXPORTSTATUS     NUMBER(1) NOT NULL
                   CONSTRAINT EXPORTSTATUS_VALID1_1 CHECK (EXPORTSTATUS IN (0,1,2)),
  ERRORCODE        VARCHAR2(50) NULL,
  MESSAGE          CLOB NULL,
  TRANSACTIONID    VARCHAR2(30) NULL,
  SYSTEMUSER_ID    NUMBER NOT NULL,
  TIMESTAMP        DATE NOT NULL);

COMMENT ON COLUMN INVOICEHEADERTAXEXPORT.REQUESTNUMBER
  IS 'The requestnumber will consist of [Plantcode][year][Plant.RequestSequencenr]';
COMMENT ON COLUMN INVOICEHEADERTAXEXPORT.EXPORTSTATUS
  IS '0 = OK
1 = Warning
2 = Error';
COMMENT ON COLUMN INVOICEHEADERTAXEXPORT.MESSAGE
  IS 'Warning / Error message';

ALTER TABLE INVOICEHEADERTAXEXPORT
  ADD CONSTRAINT XPKINVOICEHEADERTAXEXPORT PRIMARY KEY (INVOICEHEADER_ID);
  
ALTER TABLE INVOICEHEADERTAXEXPORT
  ADD CONSTRAINT INVOICEHEADERTAXEXPORT_IH FOREIGN KEY (INVOICEHEADER_ID)
  REFERENCES INVOICEHEADER (INVOICEHEADER_ID) ON DELETE CASCADE;

