-- ABS-43652/ ABS-47400

---INVOICELINECURRENCY table---
CREATE TABLE INVOICELINECURRENCY
(
  INVOICELINE_ID       NUMBER NOT NULL,
  INVOICECURRENCYTYPE  NUMBER DEFAULT 0 NOT NULL CONSTRAINT INVOICECURRENCYTYPE_VALID1_3
                       CHECK (INVOICECURRENCYTYPE BETWEEN 0 AND 2),
  CURRENCY_ID          NUMBER NOT NULL,
  PRICE                NUMBER(15,6) DEFAULT 0 NOT NULL,
  AMOUNT               NUMBER(15,6) DEFAULT 0 NOT NULL,
  REPAIRPRICEPERMINUTE NUMBER(15,6) DEFAULT 0 NOT NULL,
  SYSTEMUSER_ID        NUMBER NOT NULL,
  TIMESTAMP            DATE NOT NULL
)
;

COMMENT ON COLUMN INVOICELINECURRENCY.INVOICECURRENCYTYPE
  IS '0 = Customer currency
1 = Customer invoice currency
2 = Plant country currency
';

ALTER TABLE INVOICELINECURRENCY
  ADD CONSTRAINT XPKINVOICELINECURRENCY PRIMARY KEY (INVOICELINE_ID, INVOICECURRENCYTYPE, CURRENCY_ID);
  
CREATE INDEX XIF1INVOICELINECURRENCY ON INVOICELINECURRENCY (INVOICELINE_ID ASC);
CREATE INDEX XIF2INVOICELINECURRENCY ON INVOICELINECURRENCY (CURRENCY_ID ASC);
  
ALTER TABLE INVOICELINECURRENCY
  ADD CONSTRAINT INVOICELINECURRENCY_C FOREIGN KEY (CURRENCY_ID)
  REFERENCES CURRENCY (CURRENCY_ID);
  
ALTER TABLE INVOICELINECURRENCY
  ADD CONSTRAINT INVOICELINECURRENCY_IL FOREIGN KEY (INVOICELINE_ID)
  REFERENCES INVOICELINE (INVOICELINE_ID) ON DELETE CASCADE;