create sequence seq_invoicelinesubtype start with 1 increment by 1;
     
      /*
      ACTION is CREATE Table INVOICELINESUBTYPE
      */

CREATE TABLE INVOICELINESUBTYPE (
       INVOICELINESUBTYPE_ID NUMBER NOT NULL,
       INVOICELINETYPE_ID   NUMBER NOT NULL,
       SUBTYPE              NUMBER NOT NULL,
       FACTORYDESCRIPTION   VARCHAR2(60) NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE UNIQUE INDEX XAK1INVOICELINESUBTYPE ON INVOICELINESUBTYPE
(
       INVOICELINETYPE_ID             ,
       SUBTYPE                        
);

CREATE INDEX XIF1INVOICELINESUBTYPE ON INVOICELINESUBTYPE
(
       INVOICELINETYPE_ID             ASC
);


ALTER TABLE INVOICELINESUBTYPE
       ADD  ( CONSTRAINT XPKINVOICELINESUBTYPE PRIMARY KEY (
              INVOICELINESUBTYPE_ID) ) ;

      
      /*
      ACTION is CREATE Table INVOICELINESUBTYPE_DESC
      */

CREATE TABLE INVOICELINESUBTYPE_DESC (
       INVOICELINESUBTYPE_ID NUMBER NOT NULL,
       LANGUAGE_ID          NUMBER NOT NULL,
       DESCRIPTION          VARCHAR2(60) NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE INDEX XIF1INVOICELINESUBTYPE_DESC ON INVOICELINESUBTYPE_DESC
(
       INVOICELINESUBTYPE_ID          ASC
);

CREATE INDEX XIF2INVOICELINESUBTYPE_DESC ON INVOICELINESUBTYPE_DESC
(
       LANGUAGE_ID                    ASC
);


ALTER TABLE INVOICELINESUBTYPE_DESC
       ADD  ( CONSTRAINT XPKINVOICELINESUBTYPE_DESC PRIMARY KEY (
              INVOICELINESUBTYPE_ID, LANGUAGE_ID) ) ;

      
      /*
      ACTION is CREATE Table TURNOVERGROUPSPERINVOICELINE
      */

CREATE TABLE TURNOVERGROUPSPERINVOICELINE (
       INVOICELINE_ID       NUMBER NOT NULL,
       TURNOVERGROUP_ID     NUMBER NOT NULL,
       PERCENTAGE           NUMBER(15,2) NOT NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

CREATE INDEX XIF1TURNOVERGROUPSPERINVOICELI ON TURNOVERGROUPSPERINVOICELINE
(
       INVOICELINE_ID                 ASC
);

CREATE INDEX XIF2TURNOVERGROUPSPERINVOICELI ON TURNOVERGROUPSPERINVOICELINE
(
       TURNOVERGROUP_ID               ASC
);


ALTER TABLE TURNOVERGROUPSPERINVOICELINE
       ADD  ( CONSTRAINT XPKTURNOVERGROUPSPERINVOICELIN PRIMARY KEY (
              INVOICELINE_ID, TURNOVERGROUP_ID) ) ;


ALTER TABLE INVOICELINESUBTYPE
       ADD  ( CONSTRAINT INVOICELINESUBTYPE_INVOICELINE
              FOREIGN KEY (INVOICELINETYPE_ID)
                             REFERENCES INVOICELINETYPE ) ;


ALTER TABLE INVOICELINESUBTYPE_DESC
       ADD  ( CONSTRAINT INVOICELINESUBTYPE_D_LANGUAGE_
              FOREIGN KEY (LANGUAGE_ID)
                             REFERENCES LANGUAGES ) ;


ALTER TABLE INVOICELINESUBTYPE_DESC
       ADD  ( CONSTRAINT INVOICELINESUBTYPE_D_INVOICELI
              FOREIGN KEY (INVOICELINESUBTYPE_ID)
                             REFERENCES INVOICELINESUBTYPE ) ;


ALTER TABLE TURNOVERGROUPSPERINVOICELINE
       ADD  ( CONSTRAINT TURNOVERGROUPSPERINVOICELINE_T
              FOREIGN KEY (TURNOVERGROUP_ID)
                             REFERENCES TURNOVERGROUP ) ;


ALTER TABLE TURNOVERGROUPSPERINVOICELINE
       ADD  ( CONSTRAINT TURNOVERGROUPSPERINVOICELINE_I
              FOREIGN KEY (INVOICELINE_ID)
                             REFERENCES INVOICELINE
                             ON DELETE CASCADE ) ;







