---------THE BEGINNING------------------------------------------
-- Create ITABLE database script                              --
-- Remark, script itself is compatible with 9.06.02 and higher--
-- Version 9.07.00         26-10-2023                         --
----------------------------------------------------------------
ALTER SESSION SET NLS_LENGTH_SEMANTICS=CHAR;

prompt
prompt Adding unique constraints to codes
prompt ==================================
prompt
/**********************************************************\
---Optional script to fix foreign key links
alter table COUNTRY add constraint SKCOUNTRY unique (CODE);
alter table CURRENCY add constraint SKCURRENCY unique (CODE);
alter table BUSINESSUNIT add constraint XUNIQUEBUCODE unique (CODE);
alter table STOCKROOM add constraint SKSTOCKROOMCODE unique (CODE);
alter table USERGROUP add constraint XAK1USERGROUP unique (GROUPNAME);
alter table PLANT add constraint XAK2PLANT unique (CODE);
alter table LANGUAGES add constraint XAK2LANGUAGES unique (CODE);
alter table REASONCODE add constraint XAK1REASONCODE unique (CODE);
alter table SIZEBILLINGGROUP add constraint XAK1SIZEBILLINGGROUP unique (CODE);
alter table DIALOGS add constraint XAK1DIALOGS unique (CODE);
--Set default for customer
alter table CUSTOMER modify DEPRECIATIONLOSSCHARGE default 'N';
\**********************************************************/
declare
begin
  execute immediate 'alter table COUNTRY add constraint SKCOUNTRY unique (CODE)';
exception
  when others then
    null;
end;
/
declare
begin
  execute immediate 'alter table CURRENCY add constraint SKCURRENCY unique (CODE)';
exception
  when others then
    null;
end;
/
declare
begin
  execute immediate 'alter table BUSINESSUNIT add constraint XUNIQUEBUCODE unique (CODE)';
exception
  when others then
    null;
end;
/
declare
begin
  execute immediate 'alter table STOCKROOM add constraint SKSTOCKROOMCODE unique (CODE)';
exception
  when others then
    null;
end;
/
declare
begin
  execute immediate 'alter table USERGROUP add constraint XAK1USERGROUP unique (GROUPNAME)';
exception
  when others then
    null;
end;
/
begin
  execute immediate 'alter table REASONCODE add constraint XAK1REASONCODE unique (CODE)';
exception
  when others then
    null;
end;
/
begin
  execute immediate 'alter table SIZEBILLINGGROUP add constraint XAK1SIZEBILLINGGROUP unique (CODE)';
exception
  when others then
    null;
end;
/
begin
  execute immediate 'alter table DIALOGS add constraint XAK1DIALOGS unique (CODE)';
exception
  when others then
    null;
end;
/
--One language from table languages should have conversionlanguage_yn = 'Y'
prompt
prompt Adding conversionlanguage_yn to table languages
prompt ===============================================
prompt
begin
  execute immediate 'alter table languages add conversionlanguage_yn varchar2(1) default ''N''';
exception
  when others then
    null;
end;
/ 
---------------------Start create I-Tables----------------------------
prompt
prompt Creating table I_IMAGE
prompt ======================
prompt
create table I_IMAGE
(
  IMAGETYPE   NUMBER DEFAULT 1,
  IMAGECODE   VARCHAR2(12) NOT NULL,
  IMAGENAME   VARCHAR2(60),
  DESCRIPTION VARCHAR2(40),
  FREETEXT    VARCHAR2(1000),
  IMAGE       BLOB
);
-- Add comments to the columns 
comment on column I_IMAGE.IMAGETYPE
  is '1 = Product 2 = Placement 3 = Garment 4 = Unique Residential Item';
-- Create/Recreate primary, unique and foreign key constraints 
alter table I_IMAGE
  add constraint PK_I_IMAGE primary key (IMAGETYPE, IMAGECODE);

prompt
prompt Creating table I_ACTIVESTOCKLOCATION
prompt ====================================
prompt
create table I_ACTIVESTOCKLOCATION
(
  BUSINESSUNIT               VARCHAR2(6) not null,
  SECTION                    VARCHAR2(10) not null,
  LOCATION                   VARCHAR2(10) not null,
  UNIQUEID                   VARCHAR2(12),
  PRIORITY                   NUMBER(4) default 9999 not null,
  ACTIVE                     VARCHAR2(2) default 'Y' not null,
  MAXIMUMLENGTH              NUMBER default 99.99 not null,
  MAXIMUMWIDTH               NUMBER default 99.99 not null,
  MULTIPLESTORAGEALLOWED     VARCHAR2(1) default 'N' not null,
  MULTIPLECUSTOMERALLOWED    VARCHAR2(1) default 'N' not null,
  MULTIPLEPRODUCTSIZEALLOWED VARCHAR2(1) default 'N' not null
);
alter table I_ACTIVESTOCKLOCATION
  add constraint PKI_ACTIVESTOCKLLOCATION primary key (BUSINESSUNIT, SECTION, LOCATION);
alter table I_ACTIVESTOCKLOCATION
  add constraint UN_I_ACTIVESTOCKLLOCATION unique (BUSINESSUNIT, UNIQUEID);
alter table I_ACTIVESTOCKLOCATION
  add constraint FK_I_ACTIVESTOCKLOCATION_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_ACTIVESTOCKLOCATION
  add constraint I_ACTIVESTKLOC_BU
  check (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);
alter table I_ACTIVESTOCKLOCATION
  add constraint IMAXIMUMLENGTH
  check (MAXIMUMLENGTH BETWEEN 0 AND 99.99);
alter table I_ACTIVESTOCKLOCATION
  add constraint IMAXIMUMWIDTH
  check (MAXIMUMWIDTH BETWEEN 0 AND 99.99);
alter table I_ACTIVESTOCKLOCATION
  add constraint IMULTIPLECUSTOMERALLOWED
  check (MULTIPLECUSTOMERALLOWED IN ('Y','N'));
alter table I_ACTIVESTOCKLOCATION
  add constraint IMULTIPLEPRODUCTSIZEALLOWED
  check (MULTIPLEPRODUCTSIZEALLOWED IN ('Y','N'));
alter table I_ACTIVESTOCKLOCATION
  add constraint IMULTIPLESTORAGEALLOWED
  check (MULTIPLESTORAGEALLOWED IN ('Y','N'));
create index INDX_I_ACTIVESTOCKLOCATION_BU on I_ACTIVESTOCKLOCATION (BUSINESSUNIT);

prompt
prompt Creating table I_ALTERNATIVESIZES
prompt =================================
prompt
CREATE TABLE I_ALTERNATIVESIZES
(
  SIZE_TYPE           VARCHAR2(6),
  SIZECODE            VARCHAR2(12) NOT NULL,
  DESCRIPTION         VARCHAR2(30),
  ALTERNATIVESIZECODE VARCHAR2(12),
  SEQUENCE            NUMBER DEFAULT 1,
  UNFINISHEDSIZECODE  VARCHAR2(12)
);
comment on column I_ALTERNATIVESIZES.size_type
  is 'Size type for the sizecode and the alternative size code';
comment on column I_ALTERNATIVESIZES.description
  is 'If left empty and it is a new size the size code will be taken';
comment on column I_ALTERNATIVESIZES.unfinishedsizecode
  is 'When filled the flag UNFINISHEDLENGTH must be set to N and the related size must have Y';
create index INDX_I_ALTERNATIVESIZES_ALSIZE on I_ALTERNATIVESIZES (ALTERNATIVESIZECODE);
create index INDX_I_ALTERNATIVESIZES_UNSIZE on I_ALTERNATIVESIZES (UNFINISHEDSIZECODE);
alter table I_ALTERNATIVESIZES
  add constraint PK_I_ALTERNATIVESIZES unique (SIZECODE, ALTERNATIVESIZECODE);
alter table I_ALTERNATIVESIZES
  add constraint CHK_I_ALTERNATIVESIZES_ALTSIZE
  check (ALTERNATIVESIZECODE = upper(trim(ALTERNATIVESIZECODE)));
alter table I_ALTERNATIVESIZES
  add constraint CHK_I_ALTERNATIVESIZES_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
alter table I_ALTERNATIVESIZES
  add constraint CHK_I_ALTERNATIVESIZES_UNFSIZE
  check (UNFINISHEDSIZECODE = upper(trim(UNFINISHEDSIZECODE)));

prompt
prompt Creating table I_CUSTOMER
prompt =========================
prompt
create table I_CUSTOMER
(
  CUSTOMERNUMBER              NUMBER not null,
  BUSINESSUNIT                VARCHAR2(6) not null,
  ACCOUNTNUMBER               NUMBER not null,
  NAME                        VARCHAR2(40) not null,
  LEGALNAME                   VARCHAR2(80),
  SEARCHNAME                  VARCHAR2(10) not null,
  LEGACYCUSTOMERNUMBER        VARCHAR2(12),
  PHONENO                     VARCHAR2(30) default '-' not null,
  FAXNO                       VARCHAR2(30),
  EMAIL                       VARCHAR2(300),
  DATEACTIVE                  DATE default TRUNC(SYSDATE)-1 not null,
  DATEINACTIVE                DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null,
  ACTIVE                      VARCHAR2(1) default 'Y' not null,
  REMARK                      VARCHAR2(1000),
  SICCODE                     VARCHAR2(6),
  MASTERACCOUNT               NUMBER default 1 not null,
  MASTERACCOUNTNUMBER         NUMBER,
  MARKETSEGMENTCODE           VARCHAR2(6) default '-' not null,
  MARKETSEGMENTDESC           VARCHAR2(40) default '-' not null,
  SALESAREACODE               VARCHAR2(6) default '-' not null,
  SALESAREADESC               VARCHAR2(40) default '-' not null,
  MAILADDRESS                 VARCHAR2(40),
  MAILADDRESS2                VARCHAR2(40),
  MAILZIPCODE                 VARCHAR2(15),
  MAILCITY                    VARCHAR2(30) default '-' not null,
  MAILCOUNTY                  VARCHAR2(20),
  MAILSTATE                   VARCHAR2(20),
  COUNTRY                     VARCHAR2(3) not null,
  CURRENCY                    VARCHAR2(3) not null,
  DELIVERYADDRESS             VARCHAR2(40),
  DELIVERYADDRESS2            VARCHAR2(40),
  DELIVERYZIPCODE             VARCHAR2(15),
  DELIVERYCITY                VARCHAR2(30),
  DELIVERYCOUNTY              VARCHAR2(20),
  DELIVERYSTATE               VARCHAR2(20),
  COMMUNICATIONMETHODCODE     VARCHAR2(6) default '-' not null,
  COMMUNICATIONMETHODDESC     VARCHAR2(30) default '-' not null,
  SOILCOUNT                   VARCHAR2(1) default 'N' not null,
  RETURNLINEN                 NUMBER default 1 not null,
  RETURNGARMENTS              NUMBER default 1 not null,
  STARTDATEHOLIDAY            DATE,
  ENDDATEHOLIDAY              DATE,
  DAYSNOPREPCHARGE            NUMBER default 0 not null,
  DAYSSPECIALGRADE            NUMBER default 0 not null,
  FIRSTDAYSGRADECODE          VARCHAR2(1),
  FIRSTISSUEGRADECODE         VARCHAR2(1),
  QUALITYGRADECODE            VARCHAR2(1),
  CHARGEREPAIRS               NUMBER default 0 not null,
  GARMENTRENTSPECIFICATION    NUMBER default 1 not null,
  SWINGSUITDELIVERY           VARCHAR2(1) default 'N' not null,
  CUSTOMERMAKINGGARMENT       VARCHAR2(30),
  USEGARMENTDISPENSER         VARCHAR2(1) default 'N' not null,
  USEDISPENSEROBLIGATED       VARCHAR2(1) default 'N' not null,
  CORRECTSHORTAGES            VARCHAR2(1) default 'N' not null,
  CORRECTOVERDELIVERIES       VARCHAR2(1) default 'N' not null,
  LOCKERMANAGEMENT            VARCHAR2(1) default 'N' not null,
  CODEGARMENTSUNIQUELY        VARCHAR2(1) default 'N' not null,
  STANDARDQTYDEFINITION       NUMBER default 1 not null,
  PAYMENTTYPE                 NUMBER,
  PAYMENTMETHOD               NUMBER default 2 not null,
  MINIMUMINVOICEAMOUNT        NUMBER(15,6) default 0 not null,
  INVOICELAYOUTCODE           VARCHAR2(6) default '-' not null,
  INVOICECOPIES               NUMBER default 1 not null,
  OLDSPECIFICADJPERCENTAGE    NUMBER(15,2),
  MINADJAMOUNT                NUMBER(15,6),
  MAXADJAMOUNT                NUMBER(15,6),
  NEWSPECIFICADJPERCENTAGE    NUMBER(15,2),
  STARTDATENEWPERCENTAGE      DATE,
  REMARKONINVOICE             VARCHAR2(300),
  TAXABLE                     VARCHAR2(1) default 'Y' not null,
  STATETAXAUTHORITYCODE       VARCHAR2(12),
  CITYTAXAUTHORITYCODE        VARCHAR2(12),
  COUNTYTAXAUTHORITYCODE      VARCHAR2(12),
  CONTRACTCODE                VARCHAR2(12),
  CONTRACTDATEACTIVE          DATE default TRUNC(SYSDATE)-1,
  CONTRACTDATEINACTIVE        DATE default TO_DATE('31-12-2099','DD-MM-YYYY'),
  CONTRACTSIGNDATE            DATE,
  CONTRACTCONTINUESERVICE     VARCHAR2(1),
  CONTRACTSIGNALINGWEEKS      NUMBER,
  NEXTANNIVERSARYDATE         DATE,
  GAINREASONCODE              VARCHAR2(6),
  GAINREASONDESC              VARCHAR2(30),
  LOSTREASONCODE              VARCHAR2(6),
  LOSTREASONDESC              VARCHAR2(30),
  GAINCOMPETITORCODE          VARCHAR2(6),
  GAINCOMPETITORNAME          VARCHAR2(40),
  LOSTCOMPETITORCODE          VARCHAR2(6),
  LOSTCOMPETITORNAME          VARCHAR2(40),
  PURCHASEORDER               VARCHAR2(30),
  PURCHASEORDEREXPIRATIONDATE DATE,
  PURCHASEORDERVALUE          NUMBER(15,6),
  ESTIMATEDWEEKLYSALES        NUMBER default 0 not null,
  ANNIVERSARYPRICEADJ         NUMBER(1) default 1 not null,
  CPIBASED                    VARCHAR2(1) default 'N' not null,
  FIXEDWEIGHTPERC             NUMBER(5,2) default 0 not null,
  FIXEDSALESPERC              NUMBER(5,2) default 0 not null,
  FIXEDREPLACEPERC            NUMBER(5,2) default 0 not null,
  FIXEDRENTPERC               NUMBER(5,2) default 0 not null,
  FIXEDWASHPERC               NUMBER(5,2) default 0 not null,
  PREPCHARGE                  NUMBER(15,6),
  CHAINCODE                   VARCHAR2(6),
  CHAINNAME                   VARCHAR2(30),
  INVOICECLUSTERINGCODE       VARCHAR2(6),
  RENTPERIOD                  NUMBER default 0 not null,
  VATNUMBER                   VARCHAR2(15),
  GARMENTINSURANCE            NUMBER default 0 not null,
  GARMENTINSURANCEPRICE       NUMBER(15,6) default 0 not null,
  USESBUNDLES                 VARCHAR2(1) default 'N' not null,
  EXTRANAME1                  VARCHAR2(40),
  EXTRANAME2                  VARCHAR2(40),
  LASTSURVEYDATE              DATE,
  SURVEYFREQUENCY             NUMBER,
  ILNNUMBER                   NUMBER(13),
  RESTOCKINGPRICE             NUMBER(15,6),
  RESTOCKINGSTARTDATE         DATE,
  SALESEMPLOYEENUMBER         NUMBER,
  SALESEMPLOYEENAME           VARCHAR2(40),
  SIGNATUREREQUIRED           VARCHAR2(1) default 'Y' not null,
  CHARGEWASHFIRSTISSUE        VARCHAR2(1) default 'N' not null,
  NATIONALACCOUNTCODE         VARCHAR2(15),
  NATIONALACCOUNTNAME         VARCHAR2(40),
  INVOICEFREQUENCY            NUMBER default 0,
  COCNUMBER                   VARCHAR2(20) default '0',
  PNUMBER                     VARCHAR2(20) default '0',
  SERVICEEMPLOYEENUMBER       NUMBER,
  SERVICEEMPLOYEENAME         VARCHAR2(40),
  PRIORITY                    NUMBER,
  RANKING                     VARCHAR2(10),
  CHARGERESIDUALVALUE         VARCHAR2(1) default 'N' not null,
  CHARGELOSSCHARGE            VARCHAR2(1) default 'N',
  CUTOFFDATE                  DATE,
  EDIMETHOD                   NUMBER default 0,
  EDICONTACTPERSONNUMBER      NUMBER,
  REQUISITIONNUMBER           VARCHAR2(30),
  ACCOUNTINGSTRING            VARCHAR2(30),
  TAXEXEMPTCODE               VARCHAR2(18),
  SPLITINVOICES               NUMBER default 0 not null,
  ROUTEDESCRIPTION            VARCHAR2(200),
  INHERITMAPRICELIST          VARCHAR2(1) default 'N',
  RESTRICTONMAPRODUCTS        VARCHAR2(1) default 'N',
  SALESEMPLOYEENUMBER1        NUMBER,
  SALESEMPLOYEENAME1          VARCHAR2(40),
  SALESEMPLOYEENUMBER2        NUMBER,
  SALESEMPLOYEENAME2          VARCHAR2(40),
  SPLITINVOICESPERACTIVITY    VARCHAR2(1) default 'N' not null,
  CHARGEREPAIRCOG             NUMBER default 0 not null,
  CODELABELLAYOUTCODE         VARCHAR2(6),
  CODELABELLAYOUTDESC         VARCHAR2(60),
  NAMELABELLAYOUTCODE         VARCHAR2(6),
  NAMELABELLAYOUTDESC         VARCHAR2(60),
  CONTRACT_NOTICEWEEKS        NUMBER default 0,
  AUTOAPPROVEWEBWORKORDER     NUMBER,
  PRINTINVOICE                NUMBER default 1 not null,
  INTERNALBUSINESSUNITCODE    VARCHAR2(6),
  INVOICEBUSINESSUNITCODE     VARCHAR2(6),
  CUSTOMERRELATED             NUMBER default 0 not null,
  DIRECTINVALLSERVICES        VARCHAR2(1) default 'N' not null,
  DIRECTINVCLEANWEIGHTS       VARCHAR2(1) default 'N' not null,
  DIRECTINVDELIVERIES         VARCHAR2(1) default 'N' not null,
  DIRECTINVMINIMUMAMOUNT      NUMBER default 0 not null,
  DIRECTINVSALESNOTES         VARCHAR2(1) default 'N' not null,
  DIRECTINVSOILWEIGHTS        VARCHAR2(1) default 'N' not null,
  DELIVERYNOTELAYOUT          VARCHAR2(6) default 'DN' not null,
  SCANSONDELIVERYNOTE         NUMBER default 0 not null,
  DEPOSITSTOCKALLOWED         VARCHAR2(1) default 'N' not null,
  ALTERNATESORTING            VARCHAR2(1) default 'Y' not null,
  INTERNALCALCPERCENTAGELOG   NUMBER(4,1),
  INTERNALCALCPERCENTAGECOG   NUMBER(4,1),
  SORTCUSTOMERNUMBER          NUMBER,
  INFORMPRICEUPDATE           VARCHAR2(1) default 'N' not null,
  MAINCUSTOMERTYPE            NUMBER default 1 not null,
  ALLOWAUTOMATICSALES         VARCHAR2(1) default 'N' not null,
  LANGUAGECODE                VARCHAR2(5),
  LINENREDUCEFACTOR           NUMBER default 0,
  USECONTRACTCOEFFICIENT      VARCHAR2(1) default 'N',
  CONTRACTCOEFFICIENT         NUMBER(15,3) default 1.000,
  RETURNSAMECONTAINER         VARCHAR2(1) default 'N',
  OWNBATCH                    VARCHAR2(1) default 'N',
  INVOICECURRENCY             VARCHAR2(3),
  MATERIALMAINTENANCEPERCENTAGE NUMBER DEFAULT 0,
  GARMENTSETUP                  VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTMAINTENANCE            VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTLOSS                   VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTREPAIR                 VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CUSTOMGARMENTCHARGE           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  USEPRODSIZESURCHARGEPRICING   VARCHAR2(1) DEFAULT 'N',
  FIXEDIMAGECAREPERC            NUMBER DEFAULT 0,
  COMMONCUSTOMER                NUMBER,
  OTHERCUSTOMER                 NUMBER,
  MERCHANDISEBUYOUTCHARGE       VARCHAR2(1) DEFAULT 'N' NOT NULL,
  MBYOPPERCENTAGE               NUMBER,
  USELOCKEROBLIGATED            VARCHAR2(1) DEFAULT 'N' NOT NULL,
  AUTOSOILPERCENTAGE            NUMBER DEFAULT 0 NOT NULL,
  GARMENTLOSSPERCENTAGE         NUMBER DEFAULT 100 NOT NULL,
  GARMENTEMBLEM                 VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SPECIALSIZECHARGE             VARCHAR2(1) DEFAULT 'N' NOT NULL,
  TAXEXEMPTCERTIFICATEDOCUMENT  VARCHAR2(1000),
  EXCHANGECHARGE                NUMBER(15,6),
  EXCHANGECHARGE_STARTDATE      DATE,
  NONGARMENTCHARGERESIDUALVALUE VARCHAR2(1),
  NONGARMENTCHARGELOSSCHARGE    VARCHAR2(1),
  ASSOCIATIONTYPE               NUMBER(1) DEFAULT 0,
  MASTERACCOUNTRELATION         NUMBER(1) DEFAULT 0,
  MAILTAXAREAID                 VARCHAR2(9),
  MAILCONFIDENCEINDICATOR       NUMBER DEFAULT 0,
  DELIVERYTAXAREAID             VARCHAR2(9),
  DELIVERYCONFIDENCEINDICATOR   NUMBER DEFAULT 0,
  SEASONAUTOFLAGALLOWED     VARCHAR2(1) DEFAULT 'N',
  CONTRACTDOCUMENT        VARCHAR2(255),
  CONTACTPERSONNUMBER     NUMBER,
  RAATEMPLATEHEADER             VARCHAR2(10),
  PASSERBYCUSTOMER              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  FIRSTSERVICEDATE              DATE,
  INTERNETORDERING              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTSWEBPORTAL             VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PRICEUPDATEMETHOD             NUMBER DEFAULT 0 NOT NULL,
  PRICEINDEXCODE                VARCHAR2(6),
  CLEANROOMCUSTOMERTYPE         VARCHAR2(12),
  STERILIZATIONEXPIRATIONPERIOD NUMBER DEFAULT 0 NOT NULL,
  MAILADDRESS3                  VARCHAR2(40),
  DELIVERYADDRESS3              VARCHAR2(40)
);
comment on column I_CUSTOMER.legalname
  is 'The name field will be the one used in all forms. Additionalname will be used only on i.e. deliverynote and invoice.';
comment on column I_CUSTOMER.legacycustomernumber
  is 'Customer number from DOS table';
comment on column I_CUSTOMER.siccode
  is '4 digits  SIC= Standard Industrial Code telling what line of business a firm is in';
comment on column I_CUSTOMER.masteraccount
  is '1 = not applicable
2 = self master account
3 = belongs to a parent master account';
comment on column I_CUSTOMER.soilcount
  is 'Soil count for delayed even exchange';
comment on column I_CUSTOMER.returnlinen
  is '1=next visit (default), 2=next week same day, 3=10 day delay, 4=return route in route schedule, 5 = 14 day delay basis, 6 = 28 day delay basis, 7 = according to delivery scheme';
comment on column I_CUSTOMER.returngarments
  is '1=next visit (default), 2=next week same day, 3=10 day delay, 4=return route in route schedule, 5 = 14 day delay basis, 6 = 28 day delay basis, 7 = according to delivery scheme';
comment on column I_CUSTOMER.chargerepairs
  is 'only for LOG
0 = No Repair allowed  and No charge repair
1 = Repair allowed and No charge repair
2 = Repair allowed and Charge repair';
comment on column I_CUSTOMER.garmentrentspecification
  is '1=Products per Wearer
2=Products per Wearer Condensed
3=Wearer totals only
4=Quantities per Product
5=Number of men per total price
LL combine SUMMARY PERSON BILLING and TOTALCODE';
comment on column I_CUSTOMER.correctshortages
  is 'Correct shortages with next delivery';
comment on column I_CUSTOMER.correctoverdeliveries
  is 'Correct overdeliveries with next delivery';
comment on column I_CUSTOMER.standardqtydefinition
  is '1 = Delivery standards, 2 = Usage standards';
comment on column i_customer.paymenttype
  is '1=Check
2=Credit Card
3=EFT
4=EDI
5=Accept Giro
6=Automatic Collection
7=Via Pay by Customer
8=(Post)Bank
9=BACS
10=Approval for payment
11=letter of intent to pay
12 = ACH (Automated Clearing House)
13 = Direct Treaty';
comment on column I_CUSTOMER.PAYMENTMETHOD
  is '2= Charge (=default), 1 = Cash On Delivery';
comment on column I_CUSTOMER.minimuminvoiceamount
  is 'Minimum amount for invoice';
comment on column I_CUSTOMER.invoicecopies
  is '1-9';
comment on column I_CUSTOMER.contractsignalingweeks
  is 'Number of weeks before of contract end date this contract should be on a signaling list for ending contracts.';
comment on column I_CUSTOMER.anniversarypriceadj
  is '1=Never
2=Automatic
3=Signal Only';
comment on column I_CUSTOMER.cpibased
  is 'Y=Consumer Price Index
N=Fixed';
comment on column I_CUSTOMER.rentperiod
  is '0 = In A arrear (default)
4 = 4 weeks in advance
5 = 5 weeks in advance
8 = 8 weeks in advance
13 = 13 weeks in advance
26 = 26 weeks in advance
52 = 52 weeks in advance';
comment on column I_CUSTOMER.garmentinsurance
  is '0= Garment Insurance Not Applicable, 1= For Repairs 2= For Loss charges 3= For Repairs and Loss charges 4= For Residual Value 5= For Repair and Residual Value 6= For Residual Value and Loss Charge 7= For Repair Loss Charge and Residual Value';
comment on column I_CUSTOMER.chargeresidualvalue
  is 'Charge residual value yes or no (for garments)';
comment on column I_CUSTOMER.chargelosscharge
  is 'Charge loss charges yes or no (for garments)';
comment on column I_CUSTOMER.cutoffdate
  is 'The default cut off date for the customer activities';
comment on column I_CUSTOMER.edimethod
  is '0 = not applicable
1 = Ripplinger
2 = Seeburger
3 = EDI
4 = OIO';
comment on column I_CUSTOMER.taxexemptcode
  is 'Optional US field for Tax Exempt customers';
comment on column I_CUSTOMER.splitinvoicesperactivity
  is 'Possible values ''N'',''Y''';
comment on column I_CUSTOMER.chargerepaircog
  is 'only for COG
0 = No Repair allowed  and No charge repair
1 = Repair allowed and No charge repair
2 = Repair allowed and Charge repair';
comment on column I_CUSTOMER.contract_noticeweeks
  is 'Contractspercustomer.noticeweeks number default 0';
comment on column I_CUSTOMER.autoapprovewebworkorder
  is 'Only available for the module BKLINTERNET,
  0=No, work order created in state Waiting for approval
  1=Yes, work order created in state New';
comment on column I_CUSTOMER.printinvoice
  is '0=Don''t print invoice1=Print invoice locally 2=Print invoice external (by printingcompany)';
comment on column I_CUSTOMER.internalbusinessunitcode
  is 'Internal business unit, can be left empty then the businessunit code will be taken.';
comment on column I_CUSTOMER.invoicebusinessunitcode
  is 'Default invoice business unit, can be left empty then the businessunit code will be taken.';
comment on column I_CUSTOMER.customerrelated
  is '0=Not applicable
1=Relate to this customer
2=Relate to bill to customer (only valid when bill to customer <> customer)
3=Relate to master account (only valid if customer is connected to master account)
4=Relate to common customer, please also fill field common customer then!
5=Relate to other customer';
comment on column I_CUSTOMER.deliverynotelayout
  is 'Fromlayout code. By default the code = ''DN''';
comment on column I_CUSTOMER.scansondeliverynote
  is '0=Quantities per Product
1=Quantities per Product/Size
2=Quantities per Product + Outscanned items from Stock
3=Quantities per Product/Size + Outscanned items from Stock
4=Quantities per Product + all Outscanned items
5=Quantities per Product/Size + all Outscanned items
6= Quantities per Product+ Outscanned items from Stock+ all Outscanned items
7= Quantities per Product/Size + Outscanned items from Stock+ all Outscanned items
8=Quantities per Product + Items returned to stock
9=Quantities per Product/Size + Items returned to stock?
10= Quantities per Product + Items returned to stock+ Outscanned items from Stock
11= Quantities per Product/Size + Items returned to stock?+ Outscanned items from Stock
12= Quantities per Product + Items returned to stock?+ all Outscanned items
13= Quantities per Product/Size + Items returned to stock?+ all Outscanned items
14= Quantities per Product + Items returned to stock?+ Outscanned items from Stock+ all Outscanned items
15 = Quantities per Product/Size + Items returned to stock?+ Outscanned items from Stock+ all Outscanned items';
comment on column I_CUSTOMER.internalcalcpercentagelog
  is 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active';
comment on column I_CUSTOMER.internalcalcpercentagecog
  is 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active';
comment on column I_CUSTOMER.sortcustomernumber
  is 'Optional sortcustomer number, remark must be an existing (i)customer';
comment on column I_CUSTOMER.informpriceupdate
  is 'Optional field inform priceupdate default N otherwise Y';
comment on column I_CUSTOMER.maincustomertype
  is 'Possible values: 1=not applicable 2=main customer 3=belongs to a parent (main)customer';
comment on column I_CUSTOMER.languagecode
  is 'Optional Language code in ISO format e.g. EN_US for English (United States), remark language code must exist!';
comment on column I_CUSTOMER.linenreducefactor
  is '0 = Not applicable (Linen delivery smoothener not used) 
1 = Reduce factor A 
2 = Reduce factor B 
3 = Reduce factor C 
4 = No reduce allowed 
5 = Allow use of reduction (factor not used) 
6 = No reduce allowes (factor not used)';
comment on column I_CUSTOMER.MATERIALMAINTENANCEPERCENTAGE is 'Between 0.0 and 100.0, default 0.0, 0.0 means no budget protection';
comment on column I_CUSTOMER.USEPRODSIZESURCHARGEPRICING is 'Only for module CHARGESPECIALSIZE';
comment on column I_CUSTOMER.COMMONCUSTOMER is 'Must be filled when field EZ customer related is set to option 4= Relate to common customer';
comment on column I_CUSTOMER.OTHERCUSTOMER is 'Must be filled when field EZ customer related is set to option 5= Relate to other customer';
comment on column I_CUSTOMER.AUTOSOILPERCENTAGE is 'Used as the default for PLPC';
comment on column I_CUSTOMER.SPECIALSIZECHARGE is 'Only used for module SPECIALSIZECHARGE';
comment on column I_CUSTOMER.NONGARMENTCHARGERESIDUALVALUE is 'Charge residual value yes or no (for non-garments)';
comment on column I_CUSTOMER.NONGARMENTCHARGELOSSCHARGE is 'Charge loss charges yes or no (for non-garments))';
comment on column I_CUSTOMER.ASSOCIATIONTYPE is 'Enabled if MasterAccount = 2 and systemsetting CUSTOMERASSOCIATION is a default setting.
0 = not applicable
1 = Association
2 = Autonomous Member of Association
3 = Semi-Autonomous Member of Association
Default is determined by this systemsetting';
comment on column I_CUSTOMER.MASTERACCOUNTRELATION is 'Enabled if MasterAccount = 3 and MasterAccount_ID.AssociationType = 1 (Association).
If not enabled then store 0 (Not applicable).
1 = Fixed, 
2 = Free 
0 = Not applicable when the customer is not a master account or if the plant does not use this module';
comment on column I_CUSTOMER.PRICEUPDATEMETHOD 
is '0 = Use fixed (contract) percentages
1 = Use Consumer Price Index
2 = Use Price Index';
comment on column I_CUSTOMER.PRICEINDEXCODE
is 'Must be filled with a valid Price Index Code when PRICEUPDATEMETHOD = 2.';
comment on column I_CUSTOMER.STERILIZATIONEXPIRATIONPERIOD 
is '0 = Not Applicable
1 = 6 Months
2 = 12 Months';
alter table I_CUSTOMER
  add constraint XPKI_CUSTOMER primary key (CUSTOMERNUMBER);
create index XIF1I_CUSTOMER on I_CUSTOMER (CURRENCY);
create index XIF2I_CUSTOMER on I_CUSTOMER (INVOICECURRENCY);
create index XIF3I_CUSTOMER on I_CUSTOMER (COUNTRY);
create index XIF5I_CUSTOMER on I_CUSTOMER (INTERNALBUSINESSUNITCODE);
create index XIF6I_CUSTOMER on I_CUSTOMER (INVOICEBUSINESSUNITCODE);
create index XIF7I_CUSTOMER on I_CUSTOMER (LANGUAGECODE);
alter table I_CUSTOMER
  add constraint FK_I_CUST_INTBUSINESSUNITCODE foreign key (INTERNALBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_CUSTOMER
  add constraint FK_I_CUST_INVBUSINESSUNITCODE foreign key (INVOICEBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_CUSTOMER
  add constraint I_CUSTOMER_COUNTRY foreign key (COUNTRY)
  references COUNTRY (CODE);
alter table I_CUSTOMER
  add constraint I_CUSTOMER_CURRENCY foreign key (CURRENCY)
  references CURRENCY (CODE);
alter table I_CUSTOMER
  add constraint I_CUSTOMER_INVOICECURRENCY foreign key (INVOICECURRENCY)
  references CURRENCY (CODE);  
alter table I_CUSTOMER
  add constraint I_CUSTOMER_INVOICEFREQ foreign key (INVOICEFREQUENCY)
  references INVOICEFREQUENCY (INVOICEFREQUENCY_ID);
alter table I_CUSTOMER
  add constraint FK_I_CUSTOMER_LANGUAGECODE foreign key (LANGUAGECODE)
  references LANGUAGES (CODE) on delete cascade; 
alter table I_CUSTOMER
  add constraint I_FK_CUSTOMER_BUCODE foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
create index INDX_I_CUSTOMER_BUCODE on I_CUSTOMER (BUSINESSUNIT);
alter table I_CUSTOMER
  add constraint ANNIVERSARYPRICEADJ_VALIDATION
  check (ANNIVERSARYPRICEADJ IN (1,2,3,4));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_ALLOWAUTOMATICSALES
  check (ALLOWAUTOMATICSALES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_AUTOAPPROVEWEBWORK
  check (AUTOAPPROVEWEBWORKORDER IN (0,1));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_INFORMPRICEUPDATE
  check (INFORMPRICEUPDATE IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_LINENREDUCEFACTOR
  check (LINENREDUCEFACTOR BETWEEN 0 AND 6);
alter table I_CUSTOMER
  add constraint CHK_I_CUST_MAINCUSTOMERTYPE
  check (MAINCUSTOMERTYPE IN (1,2,3));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_MAINCUSTTYPE_SORT
  check (( MAINCUSTOMERTYPE=1 ) OR (MAINCUSTOMERTYPE=2 AND SORTCUSTOMERNUMBER IS NULL) OR (MAINCUSTOMERTYPE=3 AND SORTCUSTOMERNUMBER IS NOT NULL));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_OWNBATCH
  check (OWNBATCH IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_RETSAMECONT
  check (RETURNSAMECONTAINER IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_USECONTCOEF
  check (USECONTRACTCOEFFICIENT IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint CI_CHARGELOSSCHARGE
  check (CHARGELOSSCHARGE IS NOT NULL);
alter table I_CUSTOMER
  add constraint CI_EDIMETHOD
  check (EDIMETHOD IS NOT NULL);
alter table I_CUSTOMER
  add constraint GARMENTINSURANCE_VALIDATION
  check (GARMENTINSURANCE BETWEEN 0 AND 7777777);
alter table I_CUSTOMER
  add constraint I_CUST_BU
  check (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);
alter table I_CUSTOMER
  add constraint I_CUST_CHARGEREPAIRS
  check (CHARGEREPAIRS IN (0,1,2));
alter table I_CUSTOMER
  add constraint I_CUST_CHK_CUSTOMERRELATED
  check (CUSTOMERRELATED IN (0,1,2,3,4,5));
alter table I_CUSTOMER
  add constraint I_CUST_CHK_DIRECTINVMINAMOUNT
  check (DIRECTINVMINIMUMAMOUNT >= 0);
alter table I_CUSTOMER
  add constraint I_CUST_CHK_SCANSONDELNOTE
  check (SCANSONDELIVERYNOTE between 0 and 15);
alter table I_CUSTOMER
  add constraint I_CUST_MASTERACCOUNTCHECK
  check ((MASTERACCOUNT < 3 AND MASTERACCOUNTNUMBER = CUSTOMERNUMBER) OR (MASTERACCOUNT = 3 AND MASTERACCOUNTNUMBER <> CUSTOMERNUMBER));
alter table I_CUSTOMER
  add constraint ICUSTOMEREDIMETHOD
  check (EDIMETHOD IN (0,1,2,3,4));
alter table I_CUSTOMER
  add constraint I_CUST_PRINTINVOICE
  check (PRINTINVOICE in (0,1,2));
alter table I_CUSTOMER
  add constraint ICUST_RETURNGARMENTS
  check (RETURNGARMENTS BETWEEN 1 AND 8);
alter table I_CUSTOMER
  add constraint ICUST_RETURNLINEN
  check (RETURNLINEN BETWEEN 1 AND 8);
alter table I_CUSTOMER
  add constraint I_CUST_SPLITINVOICES
  check (SPLITINVOICES IN (0,1,2,3, 4, 5));
alter table I_CUSTOMER
  add constraint I_CUST_SPLITINVOICESPERACT
  check (SPLITINVOICESPERACTIVITY IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_ALTERNATESORTING
  check (ALTERNATESORTING IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_CHARGELOSSCHARGE
  check (CHARGELOSSCHARGE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_CHARGERESIDUALVALUE
  check (CHARGERESIDUALVALUE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_CHARGEWASHFIRSTISSUE
  check (CHARGEWASHFIRSTISSUE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_DEPOSITSTOCKALLOWED
  check (DEPOSITSTOCKALLOWED IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_DIRECTINVALLSERV
  check (DIRECTINVALLSERVICES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_DIRECTINVCLEANWGHTS
  check (DIRECTINVCLEANWEIGHTS IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_DIRECTINVDELIVERIES
  check (DIRECTINVDELIVERIES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_DIRECTINVSALESNOTES
  check (DIRECTINVSALESNOTES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_DIRECTINVSOILWEIGHTS
  check (DIRECTINVSOILWEIGHTS IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_INHERITMAPRICELIST
  check (INHERITMAPRICELIST IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_RESTRICTONMAPRODUCTS
  check (RESTRICTONMAPRODUCTS IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint I_CUST_YN_SIGNATURE
  check (SIGNATUREREQUIRED IN ('Y','N'));
alter table I_CUSTOMER
  add constraint MASTERACCOUNT_VALIDATION
  check (masteraccount IN (1, 2, 3));
alter table I_CUSTOMER
  add constraint PAYMENTTYPE_VALIDATION
  check (PAYMENTTYPE IN (0,1,2,3,4,5,6,7,8,9,10,11,12,13));
alter table I_CUSTOMER
  add constraint YNNULL_VALIDATION1
  check (CONTRACTCONTINUESERVICE IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION4497
  check (USESBUNDLES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION550
  check (ACTIVE IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION551
  check (CPIBASED IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION552
  check (SOILCOUNT IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION554
  check (CORRECTSHORTAGES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION555
  check (CORRECTOVERDELIVERIES IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION556
  check (TAXABLE IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION557
  check (USEDISPENSEROBLIGATED IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION558
  check (USEGARMENTDISPENSER IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION559
  check (SWINGSUITDELIVERY IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION560
  check (CODEGARMENTSUNIQUELY IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint YN_VALIDATION561
  check (LOCKERMANAGEMENT IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_MATERIALMAINPERC
  check (MATERIALMAINTENANCEPERCENTAGE BETWEEN 0 AND 100); 
alter table I_CUSTOMER
  add constraint CHK_I_CUST_GARMENTSETUP
  check (GARMENTSETUP IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_GARMMAIN
  check (GARMENTMAINTENANCE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_GARMLOSS
  check (GARMENTLOSS IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_GARMREPAIR
  check (GARMENTREPAIR IN ('Y','N'));  
alter table I_CUSTOMER
  add constraint CHK_I_CUSTOMERGARMENTCHARGE
  check (CUSTOMGARMENTCHARGE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint YN_USEPRODSIZESURCHARGEPRC
  check (USEPRODSIZESURCHARGEPRICING IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_MERBUYOUTCHARGE
  check (MERCHANDISEBUYOUTCHARGE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_MBYOPPERCENTAGE
  check (MBYOPPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_CUSTOMER
  add constraint CHK_I_CUST_AUTOSOILPERC
  check (AUTOSOILPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_CUSTOMER
  add constraint CHK_I_CUSTOMER_GRMLOSSPERC
  check (GARMENTLOSSPERCENTAGE BETWEEN 0 AND 100);
alter table I_CUSTOMER
  add constraint CHK_I_CUSTOMER_GARMEMB
  check (GARMENTEMBLEM IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_SPECIALSIZECHRG
  check (SPECIALSIZECHARGE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_CUST_TAX_EXEMPTCERTDOC
  check (TAXEXEMPTCERTIFICATEDOCUMENT IS NULL OR (TAXEXEMPTCERTIFICATEDOCUMENT IS NOT NULL AND TAXABLE = 'N'));
alter table I_CUSTOMER
  add constraint CHK_ICUSTGEN_CHRES CHECK (NONGARMENTCHARGERESIDUALVALUE  IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_ICUSTGEN_CHLOSS CHECK (NONGARMENTCHARGELOSSCHARGE IN ('Y','N'));
alter table I_CUSTOMER
  add constraint CHK_I_ASSOCIATIONTYPE
  check (ASSOCIATIONTYPE IN (0,1,2,3));
alter table I_CUSTOMER
  add constraint CHK_I_MASTERACCOUNTRELATION
  check (MASTERACCOUNTRELATION IN (0,1,2));
ALTER TABLE I_CUSTOMER ADD CONSTRAINT CHK_I_CUST_MAILCONFCEINDICATOR
  CHECK (MAILCONFIDENCEINDICATOR BETWEEN 0.0 AND 100.0);
ALTER TABLE I_CUSTOMER ADD CONSTRAINT CHK_I_CUST_DELCONFCEINDICATOR
  CHECK (DELIVERYCONFIDENCEINDICATOR BETWEEN 0.0 AND 100.0);
alter table I_CUSTOMER
  add constraint CHK_ICUST_SEASONFLAGALLOW CHECK (SEASONAUTOFLAGALLOWED IN ('Y','N'));
ALTER TABLE I_CUSTOMER
  ADD CONSTRAINT CHK_I_CUST_INTERNETORDERING CHECK (INTERNETORDERING IN ('Y', 'N'));
ALTER TABLE I_CUSTOMER
  ADD CONSTRAINT CHK_I_CUST_GARMENTSWEBPORTAL CHECK (GARMENTSWEBPORTAL IN ('Y', 'N'));
alter table I_CUSTOMER
  add constraint CHK_I_PRICEUPDATEMETHOD
  check (PRICEUPDATEMETHOD IN (0,1,2));
alter table I_CUSTOMER
  add constraint CHK_I_STERILIZATIONEXPIRATIONPERIOD 
  check(STERILIZATIONEXPIRATIONPERIOD IN (0,1,2));

prompt
prompt Creating table I_CUSTOMERACH
prompt ==================================
prompt  
CREATE TABLE I_CUSTOMERACH
(
  CUSTOMERNUMBER NUMBER NOT NULL,
  TOKEN          VARCHAR2(19),
  ACCOUNTNUMBER  VARCHAR2(114) NOT NULL,
  ROUTINGNUMBER  VARCHAR2(54) NOT NULL,
  CREATEDDATE    DATE
);
ALTER TABLE I_CUSTOMERACH
  ADD CONSTRAINT PK_I_CUSTOMERACH PRIMARY KEY (CUSTOMERNUMBER);
ALTER TABLE I_CUSTOMERACH
  ADD CONSTRAINT FK_I_CUSTOMERACH FOREIGN KEY (CUSTOMERNUMBER)
  REFERENCES I_CUSTOMER(CUSTOMERNUMBER);

prompt
prompt Creating table I_CUSTOMERCREDITCARD
prompt ==================================
prompt  
CREATE TABLE I_CUSTOMERCREDITCARD
(
  CUSTOMERNUMBER   NUMBER NOT NULL,
  MASKEDCARDNUMBER VARCHAR2(100) NULL,
  TOKEN            VARCHAR2(100) NULL,
  TOKENCREATEDATE  DATE NULL,
  TOKENEXPIRYDATE  DATE NULL,
  CARDEXPIRYMONTH  NUMBER NULL,
  CARDEXPIRYYEAR   NUMBER NULL,
  TYPE             NUMBER NULL,
  DAYOFMONTH       NUMBER NULL,
  DAYOFWEEK        NUMBER NULL,
  DAYOFWEEKINMONTH NUMBER NULL
);
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT PK_I_CUSTOMERCREDITCARD PRIMARY KEY (CUSTOMERNUMBER);
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT FK_I_CUSTOMERCREDIT_CUST FOREIGN KEY (CUSTOMERNUMBER)
  REFERENCES I_CUSTOMER(CUSTOMERNUMBER);
COMMENT ON COLUMN I_CUSTOMERCREDITCARD.MASKEDCARDNUMBER
  IS 'Note, this is masked data, not full card number, 
Must contain at least one masked * field';
COMMENT ON COLUMN I_CUSTOMERCREDITCARD.TYPE
  IS 'For chargeschedule, options
1 = Day of Month 
2 = Last day of Month 
3 = Day of week within month 
4 = Day of week 
5 = Day after billing day 
6 = Fixed scheme';
COMMENT ON COLUMN I_CUSTOMERCREDITCARD.DAYOFMONTH
  IS 'For chargeschedule, must be filled when type is
1 = Day of Month';
COMMENT ON COLUMN I_CUSTOMERCREDITCARD.DAYOFWEEK
  IS 'For chargeschedule, must be filled when type is
4 = Day of week';
COMMENT ON COLUMN I_CUSTOMERCREDITCARD.DAYOFWEEKINMONTH
  IS 'For chargeschedule, must be filled when type is
3 = Day of week within month';
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT CHK_I_CUSTOMERCREDIT_CCARD
  CHECK (MASKEDCARDNUMBER <> REPLACE(MASKEDCARDNUMBER,'*'));
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT CHK_I_CUSTOMERCREDIT_DAYOFMO
  CHECK (DAYOFMONTH BETWEEN 0 AND 28);
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT CHK_I_CUSTOMERCREDIT_DAYOFWEEK
  CHECK (DAYOFWEEK BETWEEN 0 AND 7);
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT CHK_I_CUSTOMERCREDIT_DAYOFWINM
  CHECK (DAYOFWEEKINMONTH BETWEEN 0 AND 4);
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT CHK_I_CUSTOMERCREDIT_TYPE
  CHECK (TYPE IN (1,2,3,4,5,6));
ALTER TABLE I_CUSTOMERCREDITCARD
  ADD CONSTRAINT CHK_I_CUSTOMERCREDIT_CHK1
  CHECK ((TYPE=1 AND DAYOFMONTH>0) OR (TYPE=3 AND DAYOFWEEKINMONTH>0)
OR (TYPE=4 AND DAYOFWEEK>0) OR (TYPE IN (2,5,6)));

prompt
prompt Creating table I_DIALOGFLEXFLIELDS
prompt ==================================
prompt  
CREATE TABLE I_DIALOGFLEXFLIELDS
(
  DIALOGCODE          VARCHAR2(40) NOT NULL, -->Refers to DIALOGS.CODE field --> So dialog_id via its code.
  CHARACTERISTICCODE  VARCHAR2(12) NOT NULL, --> Refers to CHARACTERISTIC.CODE field
  NUMBERVALUE         NUMBER,
  STRINGVALUE         VARCHAR2(255),
  DATEVALUE           DATE,
  ENTITY_NUMBER1      NUMBER,
  ENTITY_NUMBER2      NUMBER,
  ENTITY_NUMBER3      NUMBER,
  ENTITY_CODE1        VARCHAR2(12),
  ENTITY_CODE2        VARCHAR2(12),
  ENTITY_CODE3        VARCHAR2(12),
  PREDEFINEDVALUE     VARCHAR2(1)  default 'N' NOT NULL
);
create index INDX_I_DIALOGFLEXFLIELDS_DIAL on I_DIALOGFLEXFLIELDS (DIALOGCODE);
create index INDX_I_DIALOGFLEXFLS_CHAR on I_DIALOGFLEXFLIELDS (CHARACTERISTICCODE);
comment on column I_DIALOGFLEXFLIELDS.NUMBERVALUE
  is 'if flexfield is a number, fill it here';
comment on column I_DIALOGFLEXFLIELDS.STRINGVALUE
  is 'if flexfield is a string, fill it here';
comment on column I_DIALOGFLEXFLIELDS.DATEVALUE
  is 'if flexfield is a date, fill it here';
comment on column I_DIALOGFLEXFLIELDS.ENTITY_NUMBER1
  is 'For example for customernumber, at least 1 entity number or code must be filled';
comment on column I_DIALOGFLEXFLIELDS.ENTITY_NUMBER2
  is 'For example department number';
comment on column I_DIALOGFLEXFLIELDS.ENTITY_NUMBER3
  is 'For example consumptionpoint number';
comment on column I_DIALOGFLEXFLIELDS.ENTITY_CODE1
  is 'For example for product.code, at least 1 entity number or code must be filled';
comment on column I_DIALOGFLEXFLIELDS.ENTITY_CODE2
  is 'For example size code';
comment on column I_DIALOGFLEXFLIELDS.ENTITY_CODE3
  is 'For example finishingmethodcode';  
alter table I_DIALOGFLEXFLIELDS
  add constraint CHK_FLEXFLIELDS_DIALOGCODE
  check (DIALOGCODE in ('Contract','Customer','Product','ProductListPerCustomer'));
alter table I_DIALOGFLEXFLIELDS
  add constraint CHK_FLEXFLIELDS_DIALOGCHECK
  check ((DIALOGCODE = 'Contract' and ENTITY_CODE1 is not null) OR
  (DIALOGCODE = 'Customer' and ENTITY_NUMBER1 is not null) OR
  (DIALOGCODE = 'Product' and ENTITY_CODE1 is not null) OR
  (DIALOGCODE = 'ProductListPerCustomer' and ENTITY_NUMBER1 is not null and ENTITY_CODE1 is not null));
alter table I_DIALOGFLEXFLIELDS
  add constraint CHK_I_DIALOGFLEX_PREDEF
  check (PREDEFINEDVALUE IN ('Y','N'));

prompt
prompt Creating table I_INVOICEHEADER
prompt ==============================
prompt
create table I_INVOICEHEADER
(
  BUSINESSUNIT             VARCHAR2(6) NOT NULL,
  DOCUMENTTYPE             NUMBER NOT NULL,    
  INVOICENUMBER            NUMBER NOT NULL,
  INVOICEDATE              DATE NOT NULL,  
  BILLTOCUSTOMERNUMBER     NUMBER NOT NULL,
  DELTOCUSTOMERNUMBER      NUMBER,
  STREET                   VARCHAR2(40),
  STREET2                  VARCHAR2(40),
  ZIPCODE                  VARCHAR2(15),
  CITY                     VARCHAR2(30) NOT NULL,
  STATE                    VARCHAR2(20),
  COUNTY                   VARCHAR2(20),
  FREQUENCY                NUMBER NOT NULL,
  STARTMONTH               NUMBER,
  ENDMONTH                 NUMBER,
  STARTWEEK                NUMBER,
  ENDWEEK                  NUMBER,
  ROUTENUMBER              NUMBER,
  STOPNUMBER               NUMBER,
  CONTACTPERSONNAME        VARCHAR2(90),
  EMAILADDRESS             VARCHAR2(300),
  EMAILSTATUS              NUMBER NOT NULL,
  CONTACTPERSONPHONE       VARCHAR2(30),
  STATESTAXRATE            NUMBER(7,3),
  CITYTAXRATE              NUMBER(7,3),
  COUNTYTAXRATE            NUMBER(7,3),
  INVOICETYPE              NUMBER NOT NULL,
  ORIGINALCOLLECTIONTYPE   NUMBER NOT NULL,
  REALCOLLECTIONTYPE       NUMBER NOT NULL,  
  STATUS                   NUMBER NOT NULL,
  ADJUSTMENTREASONCODE     VARCHAR2(6),
  PREBILLAMOUNT            NUMBER(15,6) NOT NULL,
  PAYTHISAMOUNT            NUMBER(15,6) NOT NULL,
  CASHCOLLECTED            NUMBER(15,6) NOT NULL,
  TOTALPLUSADJUSTMENT      NUMBER(15,6) NOT NULL,
  TOTALMINUSADJUSTMENT     NUMBER(15,6) NOT NULL,
  INVOICECOMMENTS          VARCHAR2(300),
  DELIVERINSTRUCTIONS      VARCHAR2(80),
  DRIVERREMARK             VARCHAR2(80),
  ARRIVALDATETIME          DATE,
  DEPARTDATETIME           DATE,
  DISTANCEFROMPREVIOUSSTOP NUMBER(15,6),
  PURCHASEORDER            VARCHAR2(30),
  EXPORTED                 VARCHAR2(1) NOT NULL,
  STARTYEAR                NUMBER,
  ENDYEAR                  NUMBER,
  STARTDATE                DATE,
  ENDDATE                  DATE,
  CREDITSQUEEZE            NUMBER(15,6) NOT NULL,
  CREDITSQUEEZEPERC        NUMBER(15,2) NOT NULL,
  TOTALAMOUNTEXCLVAT       NUMBER(15,6) NOT NULL,
  PAYMENTTERMSDUEDATE      DATE,
  STREET3                  VARCHAR2(40)
);
comment on column I_INVOICEHEADER.DOCUMENTTYPE
  is '1=Invoice, 2=Statement';
comment on column I_INVOICEHEADER.EMAILSTATUS
  is '0=Not applicable (email address empty)
1=Ready to be send
2=Exported/Send
3=Confirmation received (to define later)';
comment on column I_INVOICEHEADER.STATUS
  is '1= Test Invoice / Unsettled Invoice
2= Final Invoice / Settled Invoice
3= Cancelled';
comment on column I_INVOICEHEADER.REALCOLLECTIONTYPE
  is '1=COD, 2=Charge';
comment on column I_INVOICEHEADER.ORIGINALCOLLECTIONTYPE
  is '1=COD, 2=Charge';
comment on column I_INVOICEHEADER.INVOICETYPE
  is '1=Generated, 2=Manual';
comment on column I_INVOICEHEADER.FREQUENCY
  is 'Frequency number of frequency table:
0=direct=US invoice/EU cons.note';
comment on column I_INVOICEHEADER.PAYMENTTERMSDUEDATE
  is 'DUE DATE';
create index XIE1I_INVOICEHEADER on I_INVOICEHEADER (INVOICENUMBER);
create index XIE2I_INVOICEHEADER on I_INVOICEHEADER (INVOICEDATE);
create index XIF1940I_INVOICEHEADER on I_INVOICEHEADER (BILLTOCUSTOMERNUMBER);
create index XIF1941I_INVOICEHEADER on I_INVOICEHEADER (DELTOCUSTOMERNUMBER);
create index INDX_I_INVOICEHEAD_BU on I_INVOICEHEADER (BUSINESSUNIT);  
alter table I_INVOICEHEADER
  add constraint XPKI_INVOICEHEADER primary key (INVOICENUMBER, DOCUMENTTYPE);
alter table I_INVOICEHEADER
  add constraint FK_I_INVOICEHEADER_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_INVOICEHEADER
  add constraint FK_I_INVOICEHEADER_INVFREQ foreign key (FREQUENCY)
  references INVOICEFREQUENCY (INVOICEFREQUENCY_ID);
alter table I_INVOICEHEADER
  add constraint I_INVOICEHEADER_BILLTOCUSTOMER foreign key (BILLTOCUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_INVOICEHEADER
  add constraint I_INVOICEHEADER_DELTOCUSTOMERN foreign key (DELTOCUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_INVOICEHEADER
  add constraint CHK_I_INVH_DOCUMENTTYPE
  check (DOCUMENTTYPE IN (1,2));
alter table I_INVOICEHEADER 
  add constraint CHK_I_INVOICEHEADER_INVOICETYPE 
  check (INVOICETYPE in (1,2));
alter table I_INVOICEHEADER
  add constraint I_INVOICEHEADER_BU
  check (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);
alter table I_INVOICEHEADER
  add constraint ORIGINALCOLTYPE_VALIDATION
  check (ORIGINALCOLLECTIONTYPE IN (1,2));
alter table I_INVOICEHEADER
  add constraint REALCOLTYPE_VALIDATION
  check (REALCOLLECTIONTYPE IN (1,2));
alter table I_INVOICEHEADER
  add constraint STATUS_VALIDATION
  check (STATUS IN (1,2,3));
alter table I_INVOICEHEADER
  add constraint YN_VALIDATION563
  check (EXPORTED IN ('Y', 'N'));

prompt
prompt Creating table I_INVOICELINE
prompt ==============================
prompt
create table I_INVOICELINE
(
  invoicenumber NUMBER,
  linenumber    NUMBER,
  code          VARCHAR2(16),
  description   VARCHAR2(40),
  extend        VARCHAR2(1),
  amount        NUMBER(15,6),
  price         NUMBER(15,6),
  billedqty     NUMBER,
  taxtype       NUMBER,
  taxgroupcode  VARCHAR2(6),
  linetype      NUMBER,
  subtype       NUMBER
);  
create unique index XIE1I_INVOICELIVE on I_INVOICELINE (INVOICENUMBER, LINENUMBER, CODE);

prompt
prompt Creating table I_ARTRANSACTION
prompt ==============================
prompt
create table I_ARTRANSACTION
(
  BUSINESSUNIT         VARCHAR2(6) NOT NULL,
  ARTRANSACTIONNO      NUMBER NOT NULL,
  BILLTOCUSTOMERNUMBER NUMBER,
  DELTOCUSTOMERNUMBER  NUMBER,
  ARTRANSACTIONDATE    DATE NOT NULL,
  DEBITCREDIT          VARCHAR2(1) NOT NULL,
  ARTRANSACTIONTYPE    NUMBER,
  AMOUNT               NUMBER(15,6) NOT NULL,
  ROUTENUMBER          NUMBER,
  REMITIDENTIFICATION  VARCHAR2(16),  
  PAYMENTTYPE          NUMBER NOT NULL,
  INVOICENUMBER        NUMBER,
  DOCUMENTTYPE         NUMBER,  
  REMARK               VARCHAR2(30),
  REMITBATCHNO         NUMBER,
  TOTALAPPLIEDAMOUNT   NUMBER(15,6) DEFAULT 0,
  ARTRANSACTION_ID     NUMBER
);
comment on column I_ARTRANSACTION.DEBITCREDIT
  is 'C=Credit (payment), D=Debit (charge)';
comment on column I_ARTRANSACTION.ARTRANSACTIONTYPE
  is 'Debit (Charge)
1=Invoice
3=Statement/Finance Charge
4=Discount charge
Credit
4=Discount
5=Payment';
comment on column I_ARTRANSACTION.PAYMENTTYPE
  is 'DebitCredit = C 
0 = Cash 
1 = Check 
2 = Credit card 
3 = EFT
4 = EDI
5 = Acceptgiro
6 = Automatic collection
7 = Pay-by customer
8 = Credit Card Portal
9 = Not applicable
DebitCredit = D
0 = COD
1 = Charge
9 = Not applicable';
comment on column I_ARTRANSACTION.REMITIDENTIFICATION
  is 'Checknr,Creditcardnr etc. Only filled
when DEBITCREDIT=C';
comment on column I_ARTRANSACTION.REMARK
  is 'Free description field to put a comment.';
comment on column I_ARTRANSACTION.DOCUMENTTYPE
  is '1=Invoice, 2=Statement';
alter table I_ARTRANSACTION
  add constraint CHK_I_ART_PAYMENTTYPE
  check ((DEBITCREDIT = 'C' and PAYMENTTYPE IN (0,1,2,3,4,5,6,7,8,9)) or (DEBITCREDIT = 'D' and PAYMENTTYPE IN (0,1,9)));
create index XIE11I_ARTRANSACTION on I_ARTRANSACTION (ARTRANSACTION_ID);
create index XIE3I_ARTRANSACTION on I_ARTRANSACTION (ARTRANSACTIONTYPE, DEBITCREDIT);
create index XIE4I_ARTRANSACTION on I_ARTRANSACTION (ROUTENUMBER);
create index XIE5I_ARTRANSACTION on I_ARTRANSACTION (REMITIDENTIFICATION);
create index XIE6I_ARTRANSACTION on I_ARTRANSACTION (INVOICENUMBER);
create index XIE7I_ARTRANSACTION on I_ARTRANSACTION (ARTRANSACTIONNO);
create index XIE9I_ARTRANSACTION on I_ARTRANSACTION (BUSINESSUNIT);
create index XIF1957I_ARTRANSACTION on I_ARTRANSACTION (INVOICENUMBER, DOCUMENTTYPE);
create index XIF1958I_ARTRANSACTION on I_ARTRANSACTION (BILLTOCUSTOMERNUMBER);
create index XIF1959I_ARTRANSACTION on I_ARTRANSACTION (DELTOCUSTOMERNUMBER);
alter table I_ARTRANSACTION
  add constraint PK_I_ARTRANSACTION primary key (ARTRANSACTIONNO);
alter table I_ARTRANSACTION
  add constraint UK_I_ARTRANSACTION unique (ARTRANSACTIONNO, DEBITCREDIT);
alter table I_ARTRANSACTION
  add constraint FK_I_ARTRANSACTION_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_ARTRANSACTION
  add constraint I_ARTRANSACTION_BILLTOCUSTOMER foreign key (BILLTOCUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_ARTRANSACTION
  add constraint I_ARTRANSACTION_DELTOCUSTOMERN foreign key (DELTOCUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_ARTRANSACTION
  add constraint I_ARTRANSACTION_INVOICENUMBER_ foreign key (INVOICENUMBER, DOCUMENTTYPE)
  references I_INVOICEHEADER (INVOICENUMBER, DOCUMENTTYPE);
alter table I_ARTRANSACTION
  add constraint CHK_I_ART_ARTRANSACTIONTYPE
  check (ARTRANSACTIONTYPE <> 2);
alter table I_ARTRANSACTION
  add constraint CHK_I_ART_DOCUMENTTYPE
  check (DOCUMENTTYPE IN (1,2,NULL));
alter table I_ARTRANSACTION
  add constraint DEBITCREDIT_VALIDATION11
  check (DEBITCREDIT IN ('D', 'C'));
alter table I_ARTRANSACTION
  add constraint I_ARTRANSACTION_BU
  check (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);

prompt
prompt Creating table I_PAYBYCUSTOMER
prompt =============================
prompt
create table I_PAYBYCUSTOMER
(
  CUSTOMERNUMBER        NUMBER NOT NULL,
  BONUSAGREEMENT        VARCHAR2(1) DEFAULT 'N',
  ACQUISTIONCODE        VARCHAR2(2),
  ACQUISTIONDESCRIPTION VARCHAR2(30),
  TDCCODE               VARCHAR2(9),
  ISPAYBYCUSTOMER       NUMBER DEFAULT 0 NOT NULL,
  PAYBYCUSTOMERNUMBER   NUMBER
);
COMMENT ON COLUMN I_PAYBYCUSTOMER.CUSTOMERNUMBER
  IS 'Link to I_CUSTOMER.NUMBER';
COMMENT ON COLUMN I_PAYBYCUSTOMER.BONUSAGREEMENT
  IS 'Must be ''Y'' or ''N''';
COMMENT ON COLUMN I_PAYBYCUSTOMER.ISPAYBYCUSTOMER
  IS '0=No pay-by customer / not applicable 1=Pay-by customer, no list';
COMMENT ON COLUMN I_PAYBYCUSTOMER.PAYBYCUSTOMERNUMBER
  IS 'Optional link to I_CUSTOMER.NUMBER or empty';
CREATE INDEX INDX_I_PAYBYCUSTOMER ON I_PAYBYCUSTOMER (PAYBYCUSTOMERNUMBER);
ALTER TABLE I_PAYBYCUSTOMER
  ADD CONSTRAINT PKI_PAYBYCUSTOMER PRIMARY KEY (CUSTOMERNUMBER);
ALTER TABLE I_PAYBYCUSTOMER
  ADD CONSTRAINT FKI_PAYBYCUSTOMER_CUSTOMER FOREIGN KEY (CUSTOMERNUMBER)
  REFERENCES I_CUSTOMER (CUSTOMERNUMBER) ON DELETE CASCADE;
ALTER TABLE I_PAYBYCUSTOMER
  ADD CONSTRAINT FKI_PAYBYCUSTOMER_ISPAYBYCUST FOREIGN KEY (PAYBYCUSTOMERNUMBER)
  REFERENCES I_CUSTOMER (CUSTOMERNUMBER) ON DELETE CASCADE;
ALTER TABLE I_PAYBYCUSTOMER
  ADD CONSTRAINT CHECK_I_PAYBYCUSTISPAYBYCUST
  CHECK (ISPAYBYCUSTOMER IN (0,1));
ALTER TABLE I_PAYBYCUSTOMER
  ADD CONSTRAINT CHKI_PAYBYCUSTOMERBONUSAGRMNT
  CHECK (BONUSAGREEMENT IN ('Y','N'));
ALTER TABLE I_PAYBYCUSTOMER
  ADD CONSTRAINT CHKI_PAYBYCUST_PAYBYCUSTOMER
  CHECK (ISPAYBYCUSTOMER = 0 OR (ISPAYBYCUSTOMER <> 0 AND PAYBYCUSTOMERNUMBER IS NULL));

prompt
prompt Creating table I_BILLTOACCOUNT
prompt ==============================
prompt
create table I_BILLTOACCOUNT
(
  CUSTOMERNUMBER               NUMBER NOT NULL,
  BILLINGADDRESS               VARCHAR2(40),
  BILLINGADDRESS2              VARCHAR2(40),
  BILLINGZIPCODE               VARCHAR2(15),
  BILLINGCITY                  VARCHAR2(30) NOT NULL,
  BILLINGCOUNTY                VARCHAR2(20),
  BILLINGSTATE                 VARCHAR2(20),
  INVOICEFREQUENCY             NUMBER DEFAULT 0,
  CREDITLIMIT                  NUMBER(15,6) DEFAULT 0 NOT NULL,
  FINANCECHARGEDAYS            NUMBER DEFAULT 0 NOT NULL,
  FINANCECHARGEPUTON           NUMBER DEFAULT 1 NOT NULL,
  DELINQUENTMARKAFTER          NUMBER DEFAULT 0 NOT NULL,
  STATEMENTCOPIES              NUMBER DEFAULT 1 NOT NULL,
  STATEMENTPERCUSTOMER         VARCHAR2(1) DEFAULT 'N' NOT NULL,
  ATTACHINVOICECOPIES          VARCHAR2(1) DEFAULT 'N' NOT NULL,
  STATEMENTFREQUENCY           NUMBER NOT NULL,
  SENDSTATEMENT                NUMBER NOT NULL,
  SENDSTATEMENTBYEMAIL         VARCHAR2(1) DEFAULT 'N' NOT NULL,
  STATEMENTLAYOUT              VARCHAR2(6) DEFAULT '-' NOT NULL,
  REMARKONSTATEMENT            VARCHAR2(300),
  PAYMENTTERMDESC              VARCHAR2(40) DEFAULT '-' NOT NULL,
  PAYMENTTERMCODE              VARCHAR2(6) DEFAULT '-' NOT NULL,
  BANKACCOUNT                  VARCHAR2(30),
  CREDITSQUEEZEPER             NUMBER(15,6) DEFAULT 0 NOT NULL,
  CONSOLIDATEDINVOICE          VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CONSOLIDATEDINVREPORT        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  COLLECTIONRESPONSIBLE_NUMBER NUMBER,
  COLLECTIONRESPONSIBLE_NAME   VARCHAR2(40),
  SENDINVOICEBY                NUMBER DEFAULT 0 NOT NULL,
  CONSOLIDATEDINVOICELAYOUT    VARCHAR2(6),
  BILLINGTAXAREAID             VARCHAR2(9),
  BILLINGCONFIDENCEINDICATOR   NUMBER DEFAULT 0,
  GENERATEPAYMENT              NUMBER(1) DEFAULT 0,
  BILLINGADDRESS3              VARCHAR2(40),
  SENDDIRECTINVOICEBYEMAIL     VARCHAR2(1) DEFAULT 'N' NOT NULL	  
);
comment on column I_BILLTOACCOUNT.invoicefrequency
  is '1=Monthly
2=Period
3=Weekly
4=Direct';
comment on column I_BILLTOACCOUNT.financechargedays
  is '0=No finance charges';
comment on column I_BILLTOACCOUNT.financechargeputon
  is '1=Invoice
2=Statement';
comment on column I_BILLTOACCOUNT.statementcopies
  is '1-9';
comment on column I_BILLTOACCOUNT.statementpercustomer
  is 'Fill in Y when account has multiple locations and statement per location is required';
comment on column I_BILLTOACCOUNT.statementfrequency
  is '1=Monthly
2=Periodically
3=Weekly';
comment on column I_BILLTOACCOUNT.sendstatement
  is '1=Always
2=Only if pas due
3=Never';
comment on column I_BILLTOACCOUNT.sendinvoiceby
 is '0 = Send by Mail
1 = Send by Fax
2 = Send by E-mail
3 = Send by EDI';
comment on column I_BILLTOACCOUNT.consolidatedinvoicelayout
  is 'Optional consolidated invoice layout. Link to FORMLAYOUT of FORMTYPE=''CI''';
comment on column I_BILLTOACCOUNT.GENERATEPAYMENT 
is '0=Payment for statement or invoice must be created manually via the cash application. 
1=Payment is generated when the statement is generated or the invoice is settled 
  if the customer is a credit card customer. The payment is not yet applied. 
2=Payment is taken automatically via a scheduled process on a predefined frequency. 
Default 0';
alter table I_BILLTOACCOUNT
  add constraint XPKI_BILLTOACCOUNT primary key (CUSTOMERNUMBER);
alter table I_BILLTOACCOUNT
  add constraint I_BILLTOACCOUNT_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_BILLTOACCOUNT
  add constraint FINANCECHARGEPUTON_VALIDATION
  check (financechargeputon IN (1,2));
alter table I_BILLTOACCOUNT
  add constraint I_BILLTO_SENDINVOICEBY
  check (SENDINVOICEBY in (0,1,2,3));
alter table I_BILLTOACCOUNT
  add constraint SENDSTATEMENT_VALIDATION
  check (sendstatement IN (1,2,3));
alter table I_BILLTOACCOUNT
  add constraint STATEMENTFREQUENCY_VALIDATION
  check (statementfrequency IN (1,2,3));
alter table I_BILLTOACCOUNT
  add constraint YN_VALIDATION4498
  check (CONSOLIDATEDINVOICE IN ('Y', 'N'));
alter table I_BILLTOACCOUNT
  add constraint YN_VALIDATION4499
  check (CONSOLIDATEDINVREPORT IN ('Y', 'N'));
alter table I_BILLTOACCOUNT
  add constraint YN_VALIDATION546
  check (STATEMENTPERCUSTOMER IN ('Y', 'N'));
alter table I_BILLTOACCOUNT
  add constraint YN_VALIDATION547
  check (ATTACHINVOICECOPIES IN ('Y', 'N'));
alter table I_BILLTOACCOUNT
  add constraint YN_VALIDATION548
  check (SENDSTATEMENTBYEMAIL IN ('Y', 'N'));
alter table i_billtoaccount add constraint CHK_I_CUST_BILCONFCEINDICATOR
  check (BILLINGCONFIDENCEINDICATOR BETWEEN 0.0 AND 100.0);
alter table i_billtoaccount add constraint CHK_I_CUST_BILGENERATEPAYMENT
  check (GENERATEPAYMENT IN (0,1,2));
alter table I_BILLTOACCOUNT
  add constraint CHK_I_BILLTO_SENDDIRECTINVOICEBYEMAIL
  check (SENDDIRECTINVOICEBYEMAIL IN ('Y', 'N'));
  
prompt
prompt Creating table I_CASHAPPLICATION
prompt ================================
prompt
create table I_CASHAPPLICATION
(
  debitartransaction_no  NUMBER not null,
  creditartransaction_no NUMBER not null,
  applydate              DATE not null,
  amount                 NUMBER(15,6) not null,
  cashapplication_id     NUMBER
);
comment on column I_CASHAPPLICATION.debitartransaction_no
  is 'Must be I_ARTransaction of type Debit (DebitCredit = ?D?)';
comment on column I_CASHAPPLICATION.creditartransaction_no
  is 'Must be I_ARTransaction of type Credit (DebitCredit = ?C?)';
comment on column I_CASHAPPLICATION.amount
  is 'Must be <= Amount from debit transaction and <= Amount from credit transaction (in case of negative amounts then >= Amount from debit and >= Amount from credit)';
comment on column I_CASHAPPLICATION.cashapplication_id
  is 'Hidden link to the table CASHAPPLICATION when this record is created via the conversion.';
alter table I_CASHAPPLICATION
  add constraint FK_I_CASHAPPLICATION_ARTRANS foreign key (CREDITARTRANSACTION_NO)
  references I_ARTRANSACTION (ARTRANSACTIONNO);

prompt
prompt Creating table I_PRODUCT
prompt ========================
prompt
CREATE TABLE I_PRODUCT
(
  CODE                          VARCHAR2(12) NOT NULL,
  DESCRIPTION                   VARCHAR2(30) NOT NULL,
  LONGDESCRIPTION               VARCHAR2(60),
  SHORTDESCRIPTION              VARCHAR2(6),
  LEGACYCODE                    VARCHAR2(12),
  PACKINGSEQUENCE               NUMBER DEFAULT 0 NOT NULL,
  OCCUPANCYRELATED              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  BUNDLEQUANTITY                NUMBER DEFAULT 1 NOT NULL,
  ACTIVE                        VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  THEORETICALWEIGHT             NUMBER(15,6) DEFAULT 0 NOT NULL,
  COLORDESC                     VARCHAR2(50) DEFAULT '-' NOT NULL,
  COLORCODE                     VARCHAR2(12) DEFAULT '-' NOT NULL,
  FABRICCODE                    VARCHAR2(12) DEFAULT '-' NOT NULL,
  FABRICDESC                    VARCHAR2(40) DEFAULT '-' NOT NULL,
  PRODUCTGROUPCODE              VARCHAR2(6) DEFAULT '-' NOT NULL,
  PRODUCTGROUPDESC              VARCHAR2(30) DEFAULT '-' NOT NULL,
  WASHPROCESSCODE               VARCHAR2(6) DEFAULT '-' NOT NULL,
  WASHPROCESSDESC               VARCHAR2(40) DEFAULT '-' NOT NULL,
  SUPPLIERNUMBER                NUMBER DEFAULT 1 NOT NULL,
  SUPPLIERNAME                  VARCHAR2(40) DEFAULT '-' NOT NULL,
  REGISTRATIONUNITCODE          VARCHAR2(6) DEFAULT '-' NOT NULL,
  REGISTRATIONUNITDESC          VARCHAR2(30) DEFAULT '-' NOT NULL,
  SOILCOUNT                     VARCHAR2(1) DEFAULT 'Y',
  RECORDPASSIVESTOCK            VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PERMITINVOICEADJUST           VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  TYPEOFMERCHANDISE             NUMBER NOT NULL,
  MINIMUMTURNAROUND             NUMBER(15,6) DEFAULT 0 NOT NULL,
  AUTOREPLACEMENT               NUMBER DEFAULT 0 NOT NULL,
  TAXGROUPCODE                  VARCHAR2(6),
  TAXGROUPDESC                  VARCHAR2(30) DEFAULT '-',
  FINISHINGMETHODCODE           VARCHAR2(6) DEFAULT '-' NOT NULL,
  FINISHINGMETHODDESC           VARCHAR2(30) DEFAULT '-' NOT NULL,
  DEFAULTSALESPRICE             NUMBER(15,6),
  DEFAULTREPLACEPRICE           NUMBER(15,6),
  DEFAULTRENTPRICE              NUMBER(15,6),
  SPECCHARGEAPPLICABLE          VARCHAR2(1) DEFAULT 'N' NOT NULL,
  TURNOVERGROUPRENT             VARCHAR2(12),
  TURNOVERGROUPWASH             VARCHAR2(12),
  TURNOVERGROUPREPL             VARCHAR2(12),
  TURNOVERGROUPSALES            VARCHAR2(12),
  PRODUCTEANNUMBER              NUMBER,
  PUTUPTYPE                     NUMBER DEFAULT 1 NOT NULL,
  MAXWASHES                     NUMBER DEFAULT 0,
  EXCHANGEMETHOD                NUMBER DEFAULT 1 NOT NULL,
  SOILCOUNTMETHOD               NUMBER DEFAULT 0 NOT NULL,
  UNIQUEPOOLITEM                VARCHAR2(1) DEFAULT 'N' NOT NULL,
  STOREACTIVESTOCKLOCATION      VARCHAR2(1) DEFAULT 'N' NOT NULL,
  FINISHINGCODE                 VARCHAR2(6),
  FINISHINGDESCRIPTION          VARCHAR2(30),
  EMBLEMTYPE                    NUMBER DEFAULT 3,
  EMBLEMTEXTCOLOR               VARCHAR2(12),
  EMBLEMBORDERCOLOR             VARCHAR2(12),
  EMBLEMFONTDESCRIPTION         VARCHAR2(30),
  PARENTPRODUCTCODE             VARCHAR2(12),
  PROVISIONGROUPCODE            VARCHAR2(6),
  PGACTIVITYTYPECODE            VARCHAR2(6) DEFAULT '-',
  USEGRADECATEGORYDEFECT        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DEFAULTRETURNGRADECODE        VARCHAR2(1),
  MOUNTINGPRODUCT               VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SHOWONMOUNTINGORDER           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SHOWONDISMOUNTINGORDER        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SHOWONPICKLISTRSC             VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DEFAULTSALESGRADECODE         VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DEFAULTMOUNTINGORDERGRADECODE VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PERCENTAGEFIRSTDELIVERY       NUMBER(3) DEFAULT 100,
  FULFILLMENTGROUP              NUMBER,
  TURNOVERGROUPLOSS             VARCHAR2(12),
  TURNOVERGROUPADVANCE          VARCHAR2(12),
  TURNOVERGROUPCORRECTIONS      VARCHAR2(12),
  TURNOVERGROUPWASHCOG          VARCHAR2(12),
  TREATMENTCHECKSCHEMECODE      VARCHAR2(6),
  LOTNUMBERREQUIREDYN           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PACKTYPE                      NUMBER DEFAULT 0 NOT NULL,
  STERILE                       NUMBER DEFAULT 0 NOT NULL,
  TREATMENTTYPE                 VARCHAR2(12),
  EXPIRATIONCODE                VARCHAR2(6),
  ASSEMBLYLAYOUT                VARCHAR2(6),
  MINACTIVESTOCKLEVEL           NUMBER DEFAULT 0 NOT NULL,
  DEFAULTSTOCKROOM              VARCHAR2(12),
  FIXEDSTOCKROOM                VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PRODUCTSORTGROUPCODE          VARCHAR2(6),
  PRODUCTRANKINGPRIO            NUMBER DEFAULT 1 NOT NULL,
  TURNOVERGROUPLOAN             VARCHAR2(12),
  SIZEBREAKDOWN                 VARCHAR2(1) DEFAULT 'N',
  MISPRODUCTCODE                VARCHAR2(16),
  MISPRODUCTDESCRIPTION         VARCHAR2(30),
  DEFAULT_RESIDUALVALUESCHEME   VARCHAR2(6),
  DEFAULT_RESIDUALVALUESCH_DESC VARCHAR2(30),
  CONFIRMPRODUCTONPDA           NUMBER DEFAULT 1,
  TOTALPACKWEIGHT               NUMBER(15,6),
  PACKVOLUMEUNITS               NUMBER(15,6),
  TURNOVERGROUPRENTNOTRET       VARCHAR2(12),
  IMAGECODE                     VARCHAR2(12),
  CUSTOMGARMENTCHARGE           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  MODIFICATIONGROUP1            VARCHAR2(6),
  MODIFICATIONGROUP2            VARCHAR2(6),
  MODIFICATIONGROUP3            VARCHAR2(6),
  MATERIALMAINTENANCEPROTECTION NUMBER(1) DEFAULT 0 NOT NULL,
  SIZEBILLINGGROUPCODE1         VARCHAR2(12),
  SURCHARGEPERCENTAGE1          NUMBER,
  SIZEBILLINGGROUPCODE2         VARCHAR2(12),
  SURCHARGEPERCENTAGE2          NUMBER,
  SIZEBILLINGGROUPCODE3         VARCHAR2(12),
  SURCHARGEPERCENTAGE3          NUMBER,
  SIZEBILLINGGROUPCODE4         VARCHAR2(12),
  SURCHARGEPERCENTAGE4          NUMBER,
  DELIVERYTOBILLRELATIONSHIP    VARCHAR2(1),
  REMARK                        CLOB,
  EMBLEMTEXTCOLOR_DESCRIPTION   VARCHAR2(50),
  EMBLEMBORDERCOLOR_DESCRIPTION VARCHAR2(50),
  SALESONLY                     VARCHAR2(1) DEFAULT 'N',
  MRPCODE                       VARCHAR2(8),
  MMPDEFAULTPERCENTAGE          NUMBER,
  CABINET_TYPE                  NUMBER(1),
  PRODUCTBARCODE                VARCHAR2(30),
  SECONDARYPRODUCTBARCODE       VARCHAR2(30),
  ALLOWONEOFFORDERINGONRA       VARCHAR2(1) DEFAULT 'N' NOT NULL
);
comment on column I_PRODUCT.MATERIALMAINTENANCEPROTECTION
  is '0 = Not applicable or No MMP (default)
1 = MMP allowed.
MMP is only used for BUDGETPROTECTION and only for non-garments';
comment on column I_PRODUCT.PACKINGSEQUENCE
  is 'Must be between 0 and 999999';
comment on column I_PRODUCT.TYPEOFMERCHANDISE
  is '1=linen/dust control,2=garments,3=disposables/sales only 4=emblem';
comment on column I_PRODUCT.PUTUPTYPE
  is '1 = Put up per customer (Packingnote)
2 = Bulk put up
3 = Packer
4 = Bulk putup scan per route
5 = Packer (Loose Linen)';
comment on column I_PRODUCT.EXCHANGEMETHOD
  is '1 = Delayed even exchange (default),2 = Straight Even Exchange or 3 = Delivery Based on Order/Standards';
comment on column I_PRODUCT.SOILCOUNTMETHOD
  is '0=no soil count,
1=manual,
2=auto return assumed,
3=weight based';
comment on column I_PRODUCT.EMBLEMTYPE
  is '1= Company
2 = Name
3 = Other/ Not Defined';
comment on column I_PRODUCT.emblemtextcolor
  is 'Emblem text color for emblems, type of merchandise 4';
comment on column I_PRODUCT.emblembordercolor
  is 'Emblem border color for emblems, type of merchandise 4';
comment on column I_PRODUCT.emblemfontdescription
  is 'Emblem font description for emblems, type of merchandise 4';
comment on column I_PRODUCT.parentproductcode
  is 'When this is filled it means the product is a model and this code indicates what the parent product code is';
comment on column I_PRODUCT.pgactivitytypecode
  is 'Activity type of the product group';
comment on column I_PRODUCT.usegradecategorydefect
  is 'Product can be identified with a grade connected to category ?Defect?';
comment on column I_PRODUCT.defaultreturngradecode
  is 'Return Quality Grade';
comment on column I_PRODUCT.mountingproduct
  is 'Product is a mounting product Y/N';
comment on column I_PRODUCT.showonmountingorder
  is 'Product may be added to a Mounting Order Y/N';
comment on column I_PRODUCT.showondismountingorder
  is 'Product may be added to a Dismounting Order Y/N';
comment on column I_PRODUCT.showonpicklistrsc
  is 'Product will be displayed on a Route Status Control Pick List Y/N';
comment on column I_PRODUCT.defaultsalesgradecode
  is 'Optional default Sales Quality Grade';
comment on column I_PRODUCT.defaultmountingordergradecode
  is 'Optional default Mounting order Quality Grade';
comment on column I_PRODUCT.treatmentcheckschemecode
  is 'Makes field maxwashes obsolete';
comment on column I_PRODUCT.packtype
  is '0 = No pack (default)
1 = Non-OR Pack
2 = OR Pack
3 = Clean room product';
comment on column I_PRODUCT.sterile
  is '0 = Not sterile (default)
1 = Sterile';
comment on column I_PRODUCT.treatmenttype
  is 'TreatmentType (sterilization process).
Must be defined if Sterile <> 0, and empty if sterile = 0';
comment on column I_PRODUCT.expirationcode
  is 'ExpirationCode must be defined if Sterile <> 0, and empty if sterile = 0';
comment on column I_PRODUCT.assemblylayout
  is 'Labellayout of labeltype=4';
comment on column I_PRODUCT.productrankingprio
  is 'ProductRanking.prio default 1';
comment on column I_PRODUCT.sizebreakdown
  is 'This attribute is used to specify whether size breakdown must be done. Only used for module SOILCOUNTSIZESPLIT.';
comment on column I_PRODUCT.confirmproductonpda
  is '1 = Yes 2 = No';
comment on column I_PRODUCT.IMAGECODE 
  is 'Optional link to I_IMAGE table where this code must exist to be able to link it';
comment on column I_PRODUCT.MODIFICATIONGROUP1
  is 'productmodificationgroup sequence 1';
comment on column I_PRODUCT.MODIFICATIONGROUP2
  is 'productmodificationgroup sequence 2';
comment on column I_PRODUCT.MODIFICATIONGROUP3
  is 'productmodificationgroup sequence 3';
comment on column I_PRODUCT.SIZEBILLINGGROUPCODE1
  is 'Stores the relationship and percentage between SizeBillingGroup and ProductGroup';
comment on column I_PRODUCT.SURCHARGEPERCENTAGE1
  is 'The percentage must be <100%,The percentage must be the same for each SBG and product group';
comment on column I_PRODUCT.SIZEBILLINGGROUPCODE2
  is 'Stores the relationship and percentage between SizeBillingGroup and ProductGroup';
comment on column I_PRODUCT.SURCHARGEPERCENTAGE2
  is 'The percentage must be <100%,The percentage must be the same for each SBG and product group';
comment on column I_PRODUCT.SIZEBILLINGGROUPCODE3
  is 'Stores the relationship and percentage between SizeBillingGroup and ProductGroup';
comment on column I_PRODUCT.SURCHARGEPERCENTAGE3
  is 'The percentage must be <100%,The percentage must be the same for each SBG and product group';
comment on column I_PRODUCT.SIZEBILLINGGROUPCODE4
  is 'Stores the relationship and percentage between SizeBillingGroup and ProductGroup';
comment on column I_PRODUCT.SURCHARGEPERCENTAGE4
  is 'The percentage must be <100%,The percentage must be the same for each SBG and product group';  
comment on column I_PRODUCT.SALESONLY
  is 'If this is set, only Billing Method 4 is allowed';
comment on column I_PRODUCT.STOREACTIVESTOCKLOCATION
  IS 'N = default
Y = Yes no extra options,
0 = Not applicable (StoreActiveStockLocation=N),
1 = Customer logo mat (Unique item in location, not Bulk) (StoreActiveStockLocation=Y),
2 = Customer Pool logo mat (Bulk Multi Customer) (StoreActiveStockLocation=Y),
3 = Bulk (Pool) product (Bulk No Customer) (StoreActiveStockLocation=Y)';
comment on column I_PRODUCT.MMPDEFAULTPERCENTAGE
IS 'Material Maintenance Protection (MMP) default percentage. Optional, so may be left empty. 
Must be filled with a value between 0.1 and 100.0 when MaterialMaintenanceProtection = 1 
Or must be filled with 0 or left empty (null) when MaterialMaintenanceProtection = 0
Only used for module BPMMPENHANCED';
COMMENT ON COLUMN I_PRODUCT.CABINET_TYPE
  IS '1 = Cabinet
2 = Cabinet content';
alter table I_PRODUCT
  add constraint CHK_I_PRODUCT_SALESONLY
  check (SALESONLY IN ('Y','N'));   
alter table I_PRODUCT
  add constraint XPKI_PRODUCT primary key (CODE);
alter table I_PRODUCT
  add constraint XI_PRODUCT unique (CODE, TYPEOFMERCHANDISE);
alter table I_PRODUCT
  add constraint FK_I_PRODUCTPARENT foreign key (PARENTPRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_PRODUCT
  add constraint FK_SIZEBILLINGGROUPCODE1 foreign key (SIZEBILLINGGROUPCODE1)
  references sizebillinggroup(CODE);
alter table I_PRODUCT
  add constraint FK_SIZEBILLINGGROUPCODE2 foreign key (SIZEBILLINGGROUPCODE2)
  references sizebillinggroup(CODE);
alter table I_PRODUCT
  add constraint FK_SIZEBILLINGGROUPCODE3 foreign key (SIZEBILLINGGROUPCODE3)
  references sizebillinggroup(CODE);
alter table I_PRODUCT
  add constraint FK_SIZEBILLINGGROUPCODE4 foreign key (SIZEBILLINGGROUPCODE4)
  references sizebillinggroup(CODE);  
alter table I_PRODUCT
  add constraint CHK_I_PROD_SIZEBREAKDOWN
  check (SIZEBREAKDOWN IN  ('Y', 'N'));
alter table I_PRODUCT
  add constraint CHK_I_PRODUCT_PACKINGSEQUENCE
  check (PACKINGSEQUENCE between 0 and 999999);
alter table I_PRODUCT
  add constraint I_PROD_DEFAULTRETURNGRADECODE
  check (DEFAULTRETURNGRADECODE = UPPER(DEFAULTRETURNGRADECODE));
alter table I_PRODUCT
  add constraint I_PROD_EXPIRATIONCODE
  check (EXPIRATIONCODE IS NULL OR (EXPIRATIONCODE IS NOT NULL AND STERILE<>0));
alter table I_PRODUCT
  add constraint I_PROD_LOTNUMBERREQUIREDYN
  check (LOTNUMBERREQUIREDYN IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint I_PROD_MOUNTINGPRODUCT
  check (MOUNTINGPRODUCT IN ('Y','N'));
alter table I_PRODUCT
  add constraint I_PROD_ORPACK_LABEL
  check ((PACKTYPE <> 2) OR (PACKTYPE=2 AND ASSEMBLYLAYOUT IS NOT NULL));
alter table I_PRODUCT
  add constraint I_PROD_PACKTYPE
  check (PACKTYPE IN (0,1,2,3));
alter table I_PRODUCT
  add constraint I_PROD_SHOWONDISMOUNTINGORDER
  check (SHOWONDISMOUNTINGORDER IN ('Y','N'));
alter table I_PRODUCT
  add constraint I_PROD_SHOWONMOUNTINGORDER
  check (SHOWONMOUNTINGORDER IN ('Y','N'));
alter table I_PRODUCT
  add constraint I_PROD_SHOWONPICKLISTRSC
  check (SHOWONPICKLISTRSC IN ('Y','N'));
alter table I_PRODUCT
  add constraint I_PROD_SOILCOUNTMETHOD
  check (SOILCOUNTMETHOD IN (0,1,2,3));
alter table I_PRODUCT
  add constraint I_PROD_STERILE
  check (STERILE IN (0,1));
ALTER TABLE I_PRODUCT
  ADD CONSTRAINT I_PROD_STOREACTIVESTOCKLOC
  CHECK (STOREACTIVESTOCKLOCATION IN ('Y','N','0','1','2','3') 
  AND ((PUTUPTYPE IN (2,4) AND TYPEOFMERCHANDISE IN (1,3)) OR STOREACTIVESTOCKLOCATION IN ('Y','N','0')));
alter table I_PRODUCT
  add constraint I_PRODUCT_CHEC_PRODUCTCODE
  check (code = upper(trim(code)));
alter table I_PRODUCT
  add constraint I_PRODUCTPARENT_CHECK
  check (PARENTPRODUCTCODE IS NULL OR TYPEOFMERCHANDISE IN (1, 2, 3));
alter table I_PRODUCT
  add constraint I_PRODUCTPERCFIRSTDELIVERY
  check (PERCENTAGEFIRSTDELIVERY between 1 and 100);
alter table I_PRODUCT
  add constraint I_PROD_UNIQUEPOOLITEM
  check (UNIQUEPOOLITEM IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint I_PROD_USEGRADECATEGORYDEFECT
  check (USEGRADECATEGORYDEFECT IN ('Y','N'));
alter table I_PRODUCT
  add constraint PRODUCT_EXCHANGEMETHOD
  check (EXCHANGEMETHOD in (1,2,3));
alter table I_PRODUCT
  add constraint PUTUPTYPE_VALIDATION
  check (putuptype IN (1, 2, 3, 4, 5));
alter table I_PRODUCT
  add constraint TYPEOFMERCHANDISE_VALIDATION1
  check (TYPEOFMERCHANDISE IN (1, 2, 3, 4, 5));
alter table I_PRODUCT
  add constraint YN_VALIDATION568
  check (ACTIVE IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint YN_VALIDATION569
  check (OCCUPANCYRELATED IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint YN_VALIDATION570
  check (SPECCHARGEAPPLICABLE IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint YN_VALIDATION571
  check (PERMITINVOICEADJUST IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint YN_VALIDATION572
  check (RECORDPASSIVESTOCK IN ('Y', 'N'));
alter table I_PRODUCT
  add constraint CHK_I_PROD_CUSTOMGARMCHARGE
  check (CUSTOMGARMENTCHARGE IN ('Y','N'));
alter table I_PRODUCT
  add constraint CHK_I_PROD_MMPROTECTION
  check ((MATERIALMAINTENANCEPROTECTION IN(0,1) AND TYPEOFMERCHANDISE=1) OR (MATERIALMAINTENANCEPROTECTION=0));
alter table I_PRODUCT
  add constraint CHK_I_PROD_SURCHRGPER1
  check (SURCHARGEPERCENTAGE1 BETWEEN 0 AND 99.99);
alter table I_PRODUCT
  add constraint CHK_I_PROD_SURCHRGPER2
  check (SURCHARGEPERCENTAGE2 BETWEEN 0 AND 99.99);  
alter table I_PRODUCT
  add constraint CHK_I_PROD_SURCHRGPER3
  check (SURCHARGEPERCENTAGE3 BETWEEN 0 AND 99.99);  
alter table I_PRODUCT
  add constraint CHK_I_PROD_SURCHRGPER4
  check (SURCHARGEPERCENTAGE4 BETWEEN 0 AND 99.99); 
alter table I_PRODUCT
  add constraint I_PROD_DELTOBILLRELATIONSHIP
  check (DELIVERYTOBILLRELATIONSHIP IN ('Y','N'));  
ALTER TABLE I_PRODUCT
  ADD CONSTRAINT CHK_I_PRODUCT_FINMETHODCODE
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_PRODUCT 
  ADD CONSTRAINT CHK_I_PROD_MMPDEFAULTPERCENT 
  CHECK (MMPDEFAULTPERCENTAGE BETWEEN 0 AND 100);
ALTER TABLE I_PRODUCT 
   ADD CONSTRAINT CHK_I_PRODUCT_MMP 
   CHECK ((MATERIALMAINTENANCEPROTECTION=0 AND NVL(MMPDEFAULTPERCENTAGE,0)=0) OR (MATERIALMAINTENANCEPROTECTION=1 AND NVL(MMPDEFAULTPERCENTAGE,0.1) BETWEEN 0.1 AND 100));
ALTER TABLE I_PRODUCT 
   ADD CONSTRAINT CHK_I_PRODUCT_CABINETY CHECK (CABINET_TYPE IN (1, 2));

prompt
prompt Creating table I_CUSTOMERBUDGETDEFINITION
prompt =========================================
prompt
create table I_CUSTOMERBUDGETDEFINITION
(
  customernumber        NUMBER not null,
  budgetcode            VARCHAR2(6) not null,
  budgetdescription     VARCHAR2(30) not null,
  budgetunitcode        VARCHAR2(6),
  budgetunitdescription VARCHAR2(30),
  startdate             DATE default TRUNC(SYSDATE)-1 not null,
  enddate               DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null,
  usedforinvoicing      VARCHAR2(1) default 'Y' not null,
  usedforreporting      VARCHAR2(1) default 'Y' not null,
  price                 NUMBER(15,6),
  pricestartdate        DATE default TRUNC(SYSDATE)-1
);
comment on column I_CUSTOMERBUDGETDEFINITION.budgetcode
  is 'Must be uppercase no spaces';
comment on column I_CUSTOMERBUDGETDEFINITION.budgetunitcode
  is 'BUDGETTYPE = 0 = Piece Rate when BUDGETUNITCODE is filled
BUDGETTYPE = 1 = Fixed fee when BUDGETUNITCODE is empty';
comment on column I_CUSTOMERBUDGETDEFINITION.usedforinvoicing
  is 'Y / N default Y';
comment on column I_CUSTOMERBUDGETDEFINITION.usedforreporting
  is 'Y / N default Y';
comment on column I_CUSTOMERBUDGETDEFINITION.pricestartdate
  is 'Must be between STARTDATE and ENDDATE of this BUDGETCODE';
alter table I_CUSTOMERBUDGETDEFINITION
  add constraint PK_I_CUSTOMERBUDGETDEFINITION primary key (CUSTOMERNUMBER, BUDGETCODE);
create index XIF1I_CUSTOMERBUDGETDEFINITION on  I_CUSTOMERBUDGETDEFINITION(CUSTOMERNUMBER);  
alter table I_CUSTOMERBUDGETDEFINITION
  add constraint FK_I_CUSTOMERBUDGETDEF_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_CUSTOMERBUDGETDEFINITION
  add constraint CHK_I_CUSTBUDGETDEF_CODE
  check (BUDGETCODE = UPPER(RTRIM(LTRIM(BUDGETCODE))));
alter table I_CUSTOMERBUDGETDEFINITION
  add constraint CHK_I_CUSTBUDGETDEF_PRICEDATE
  check (PRICESTARTDATE BETWEEN STARTDATE AND ENDDATE);
alter table I_CUSTOMERBUDGETDEFINITION
  add constraint CHK_I_CUSTBUDGETDEF_USED4INV
  check (USEDFORINVOICING IN ('Y','N'));
alter table I_CUSTOMERBUDGETDEFINITION
  add constraint CHK_I_CUSTBUDGETDEF_USED4REP
  check (USEDFORREPORTING IN ('Y','N'));

prompt
prompt Creating table I_PRODUCTLISTPERCUSTOMER
prompt =======================================
prompt
create table I_PRODUCTLISTPERCUSTOMER
(
  CUSTOMERNUMBER               NUMBER NOT NULL,
  PRODUCTCODE                  VARCHAR2(12) NOT NULL,
  SIZECODE                     VARCHAR2(12) NOT NULL,
  SIZEDESCRIPTION              VARCHAR2(30) NOT NULL,
  FINISHINGMETHODCODE          VARCHAR2(6) DEFAULT '-' NOT NULL,
  FINISHINGMETHODDESCRIPTION   VARCHAR2(30) DEFAULT '-' NOT NULL,
  DATEACTIVE                   DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  DATEINACTIVE                 DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  CODEUNIQUELY                 VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SOILWEIGHT                   NUMBER(15,6) DEFAULT 0 NOT NULL,
  ONSITEINVENTORYCOUNT         VARCHAR2(1) DEFAULT 'N' NOT NULL,
  BILLINGMETHOD                NUMBER NOT NULL,
  CIRCULATINGINVENTORY         NUMBER,
  CHANGESPERWEEK               VARCHAR2(1) NOT NULL,
  FIXEDQUANTITY                NUMBER NOT NULL,
  CHARGEOVERUSE                VARCHAR2(1) NOT NULL,
  MINIMUMFREQUENCY             NUMBER NOT NULL,
  SPARE                        VARCHAR2(30),
  MINIMUMTURNAROUND            NUMBER(15,6) DEFAULT 0 NOT NULL,
  MINIMUMQUANTITY              NUMBER DEFAULT 0 NOT NULL,
  INVENTORYBILLINGTYPE         NUMBER DEFAULT 0 NOT NULL,
  PERCENTAFTERDEPRECIATION     NUMBER(15,2) DEFAULT 0 NOT NULL,
  SOILCOUNTMETHOD              NUMBER DEFAULT 0 NOT NULL,
  CLEANCOUNT                   VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SRCMETHOD                    NUMBER DEFAULT 0 NOT NULL,
  SRCFREQUENCY                 NUMBER DEFAULT 0 NOT NULL,
  SRCPERCENTAGESOILCOUNT       NUMBER(15,2) DEFAULT 0 NOT NULL,
  SRCPERCENTAGEINVENTORY       NUMBER(15,2) DEFAULT 0 NOT NULL,
  SRCQUANTITY                  NUMBER DEFAULT 0 NOT NULL,
  DELIVERREPLACEMENTQTY        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CHARGESTOCKROOMINVENTORY     VARCHAR2(1) DEFAULT 'N' NOT NULL,
  QTYFREEOFCHARGE              NUMBER DEFAULT 0 NOT NULL,
  CUSTOMCODE                   VARCHAR2(16),
  CUSTOMDESCRIPTION            VARCHAR2(30),
  CUSTOMBUNDLESIZE             NUMBER DEFAULT 0 NOT NULL,
  GAINCOMPETITORCODE           VARCHAR2(6),
  GAINCOMPETITORNAME           VARCHAR2(30),
  LOSTCOMPETITORCODE           VARCHAR2(6),
  LOSTCOMPETITORNAME           VARCHAR2(30),
  GAINREASONCODE               VARCHAR2(6),
  GAINREASONDESCRIPTION        VARCHAR2(30),
  LOSTREASONCODE               VARCHAR2(6),
  LOSTREASONDESCRIPTION        VARCHAR2(30),
  RESIDUALVALUESCHEMECODE      VARCHAR2(6) DEFAULT '-' NOT NULL,
  DELAYEVENEXCHANGE            NUMBER DEFAULT 0 NOT NULL,
  DELIVERYSCHEDULECODE         VARCHAR2(6),
  RENTPRICESTARTDATE           DATE,
  RENTPRICENEW                 NUMBER(15,6),
  RENTPRICEOLD                 NUMBER(15,6),
  WASHPRICESTARTDATE           DATE,
  WASHPRICENEW                 NUMBER(15,6),
  WASHPRICEOLD                 NUMBER(15,6),
  REPLACEMENTPRICESTARTDATE    DATE,
  REPLACEMENTPRICENEW          NUMBER(15,6),
  REPLACEMENTPRICEOLD          NUMBER(15,6),
  SALESPRICESTARTDATE          DATE,
  SALESPRICENEW                NUMBER(15,6),
  SALESPRICEOLD                NUMBER(15,6),
  DELIVERYDAYMO                VARCHAR2(1),
  DELIVERYDAYTU                VARCHAR2(1),
  DELIVERYDAYWE                VARCHAR2(1),
  DELIVERYDAYTH                VARCHAR2(1),
  DELIVERYDAYFR                VARCHAR2(1),
  DELIVERYDAYSA                VARCHAR2(1),
  DELIVERYDAYSU                VARCHAR2(1),
  STDDELIVERYQTYMO             NUMBER,
  STDDELIVERYQTYTU             NUMBER,
  STDDELIVERYQTYWE             NUMBER,
  STDDELIVERYQTYTH             NUMBER,
  STDDELIVERYQTYFR             NUMBER,
  STDDELIVERYQTYSA             NUMBER,
  STDDELIVERYQTYSU             NUMBER,
  QUANTITYRETURNED             NUMBER DEFAULT 0 NOT NULL,
  PLPCEANNUMBER                NUMBER(4),
  SPECIFICPUTUPTYPE            NUMBER DEFAULT 0 NOT NULL,
  SALESEMPLOYEENUMBER          NUMBER,
  SALESEMPLOYEENAME            VARCHAR2(40),
  RETURNSTOCKALLOWED           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  STRAIGHTEVENEXCHANGE         VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CUSTOMERRELATED              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  TYPEOFMERCHANDISE            NUMBER DEFAULT 2 NOT NULL,
  DDEDELIVERYSCHEMECODE        VARCHAR2(6),
  DISCOUNTPERCENTAGEWASH       NUMBER(15,2),
  DISCOUNTPERCENTAGERENT       NUMBER(15,2),
  REMARK                       VARCHAR2(80),
  LOCATION                     VARCHAR2(6),
  WASHPRICECOGSTARTDATE        DATE,
  WASHPRICECOGNEW              NUMBER(15,6),
  WASHPRICECOGOLD              NUMBER(15,6),
  CHARGEWASHESONLYFORCOG       NUMBER DEFAULT 0 NOT NULL,
  RENTPRICEPERFREQUENCY        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PRICEUSAGE                   NUMBER DEFAULT 0 NOT NULL,
  EMBLEMTEMPLATE               VARCHAR2(6),
  SRCCHARGERENT                NUMBER DEFAULT 0 NOT NULL,
  TREATMENTCHECKSCHEMECODE     VARCHAR2(6),
  DELIVERYLABELLAYOUT          VARCHAR2(6),
  SALESEMPLOYEENUMBER2         NUMBER,
  SALESEMPLOYEENAME2           VARCHAR2(40),
  DEFAULTSTOCKROOM             VARCHAR2(12),
  FIXEDSTOCKROOM               VARCHAR2(1) DEFAULT 'N' NOT NULL,
  ORDERVIAWEB                  NUMBER(1) DEFAULT 0 NOT NULL,
  FREEQTYFREQUENCY             NUMBER(1) DEFAULT 0 NOT NULL,
  INTERNALCALCPERCENTAGELOG    NUMBER(4,1),
  INTERNALCALCPERCENTAGECOG    NUMBER(4,1),
  LOANPRICE                    NUMBER(15,6),
  CHARGEEXCESS                 NUMBER(1) DEFAULT 0 NOT NULL,
  BUDGETUSAGE                  NUMBER DEFAULT 0 NOT NULL,
  BUDGETCODE                   VARCHAR2(6),
  DEPOSITSTOCKALLOWED          VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DEPOSITSTOCKCHARGEPERCENTAGE NUMBER DEFAULT 0 NOT NULL,
  VOLUMEPRICE                  NUMBER(6) DEFAULT 1 NOT NULL,
  BM1FIXEDWEARERS              VARCHAR2(1) DEFAULT 'N',
  STERILISATIONREQUIRED        VARCHAR2(1) DEFAULT 'N',
  MMPSPECIFICPERCENTAGE        NUMBER,
  GARMENTSETUP                 VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTMAINTENANCE           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTLOSS                  VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTREPAIR                VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CONTRACTCODE                 VARCHAR2(15),
  IMAGECARE                    NUMBER(1) DEFAULT 0 NOT NULL,
  ALLOWRETURNTOSTOCK           NUMBER(1) DEFAULT 0 NOT NULL,
  MBYOPPERCENTAGE              NUMBER,
  SEASONTYPECODE               VARCHAR2(6),
  SEASONALRENT                 NUMBER DEFAULT 0 NOT NULL,
  CHARGEWASHINACTIVESEASON     VARCHAR2(1) DEFAULT 'N' NOT NULL,
  AUTOSOILPERCENTAGE           NUMBER DEFAULT 0 NOT NULL,
  LOSSCHARGEPERCENTAGE         NUMBER(5,2),
  SRCHARGEPERCENTAGE           NUMBER(5,2),
  DEFAULT_SUPPLIERNUMBER       NUMBER,
  GARMENTLOSSPERCENTAGE        NUMBER DEFAULT 100 NULL,
  GARMENTEMBLEM                VARCHAR2(1) DEFAULT 'N' NULL,
  SPECIFICBULKPACKINGTYPE      NUMBER NULL,
  SERVICEBILLING               VARCHAR2(1) DEFAULT 'N',
  BM1RENTCPWMAX                NUMBER(1) DEFAULT 0 NOT NULL,
  PRODUCTINSTALLDATE           DATE,
  DEPOSITSTOCKLOCATION         VARCHAR2(6),
  SIZEBILLINGGROUPCODE         VARCHAR2(12)
);
comment on column I_PRODUCTLISTPERCUSTOMER.billingmethod
  is '1 = Flat rated rent
2 = Rent based on minimum
3 = Circulating inventory
4 = Piece rate only
5 = Lease';
comment on column I_PRODUCTLISTPERCUSTOMER.delayevenexchange
  is '0=Fixed delivery scheme,1=Next Visit,2=Next week same day,3=10 day delay,4=Return route of route,5=14 day delay basis,6=28 day delay basis,7 = according to delivery scheme,8 = Next visit including same date';
comment on column I_PRODUCTLISTPERCUSTOMER.specificputuptype
  is '0 = No Specific, inherit from Product
1 = Put up per customer (Packingnote)
2 = Bulk put up
3 = Packer
4 = Bulk putup scan per route
5 = Packer (Loose Linen)';
comment on column I_PRODUCTLISTPERCUSTOMER.inventorybillingtype
  is '0 - circulating inventory
1 - real quantity
2 - max inventory qty
3 - on-site inventory qty
4 - Non-returned pool after n weeks
(for BM2 only 0,1,2)';
comment on column I_PRODUCTLISTPERCUSTOMER.typeofmerchandise
  is '1=linen/dust control,2=garments,3=disposables/sales only 4=emblem';
comment on column I_PRODUCTLISTPERCUSTOMER.location
  is 'Default location for consumptionpoint logistics';
comment on column I_PRODUCTLISTPERCUSTOMER.chargewashesonlyforcog
  is '0 = Both LOG and COG, same washprice (default)1 = Both LOG and COG, distinct washprice2 = LOG only3 = COG only';
comment on column I_PRODUCTLISTPERCUSTOMER.priceusage
  is '0 = Not applicable
1 = Split price
2 = Rent price only
3 = Wash price only';
comment on column I_PRODUCTLISTPERCUSTOMER.emblemtemplate
  is 'Optional default emblem template.';
comment on column I_PRODUCTLISTPERCUSTOMER.deliverylabellayout
  is 'FK to labellayout table, module ORS, labeltype=5';
comment on column I_PRODUCTLISTPERCUSTOMER.orderviaweb
  is '0 = No (default) 1 = Yes';
comment on column I_PRODUCTLISTPERCUSTOMER.freeqtyfrequency
  is '0 = per week
1 = per invoice';
comment on column I_PRODUCTLISTPERCUSTOMER.internalcalcpercentagelog
  is 'Internal calculation percentage for LOG items, only relevant when module INTERNALCALC is active';
comment on column I_PRODUCTLISTPERCUSTOMER.internalcalcpercentagecog
  is 'Internal calculation percentage for COG items, only relevant when module INTERNALCALC is active';
comment on column I_PRODUCTLISTPERCUSTOMER.chargeexcess
  is '0 = Do not charge excess / not applicable (default)
1 = Charge excess per size
2 = Charge excess over all sizes';
comment on column I_PRODUCTLISTPERCUSTOMER.budgetusage
  is '(Only for module  textilecontrolling) 0 = Not in Budget 1 = Self paid, not in Budget 2 = In Budget';
comment on column I_PRODUCTLISTPERCUSTOMER.budgetcode
  is '(Only for module  textilecontrolling) Optional link to I_CUSTOMERBUDGETDEFINITION';
comment on column I_PRODUCTLISTPERCUSTOMER.depositstockchargepercentage
  is 'Between 0 and 100';
comment on column I_PRODUCTLISTPERCUSTOMER.volumeprice
  is 'Related to the Salesprice, and only used when
there is a Salesprice, then the default value is 1';
comment on column I_PRODUCTLISTPERCUSTOMER.MMPSPECIFICPERCENTAGE is 'Material Maintenance Protection (MMP) specific percentage. 
Between 0.0 and 100.0, if empty (Null) then take the percentage defined on Customer level.
If on customer level is defined 0.0 (no MMP) then must be set to Null';
comment on column I_PRODUCTLISTPERCUSTOMER.IMAGECARE is '0= Not charged / not applicable (default)
1= For Repairs
2= For Loss charges
3= For Repairs and Loss charges
4= For Residual Value
5= For Repair and Residual Value
6= For Residual Value and Loss Charge
7= For Repair Loss Charge and Residual Value';
comment on column I_PRODUCTLISTPERCUSTOMER.ALLOWRETURNTOSTOCK
  is 'Possible values: 0 = Yes (default) 1 = Yes, excluding special sizes 2 = No 3 = Yes, Size 4 = No, MBYO Charge';
comment on column I_PRODUCTLISTPERCUSTOMER.SEASONALRENT
  is 'Allowed values
0 = Not applicable 
1 = Only charge rent during active season 
2 = Charge rent for both active and inactive season)';
comment on column I_PRODUCTLISTPERCUSTOMER.CHARGEWASHINACTIVESEASON
  is 'Remark this field is called chargerentinactiveseason in productlistpercustomer!';
comment on column I_PRODUCTLISTPERCUSTOMER.LOSSCHARGEPERCENTAGE
  is ' LOSSCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99, DEFAULT 100';
comment on column I_PRODUCTLISTPERCUSTOMER.SRCHARGEPERCENTAGE
  is ' SRCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99, DEFAULT 100';
comment on column I_PRODUCTLISTPERCUSTOMER.SPECIFICBULKPACKINGTYPE
  is '0 = Inherit / NA 
1 = Type 1 (Customer logo mat) 
2 = Type 2 (Customer related logo mat) Only used with module BULKPACKINGASSISTANT';
COMMENT ON COLUMN I_PRODUCTLISTPERCUSTOMER.SERVICEBILLING
  IS 'Y / N (BM1) used for module CABINETSERVICE only';
comment on column I_PRODUCTLISTPERCUSTOMER.BM1RENTCPWMAX
  is '0 = Not applicable
1 = Rent Price based on charges per week and Max Inventory, rent based on real quantity in circulation
2 = Rent Price based on charges per week and Max Inventory, rent based on max quantity
Option 1 and 2 are only available for the module RENTBM1CPWMAX and can only be set if BillingMethod = 1 and ChangesPerWeek = Y. In all other cases it should be set to 0 or left empty.';
create index XIF3799I_PRODUCTLISTPERCUSTOME on I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER);
create index XIF3800I_PRODUCTLISTPERCUSTOME on I_PRODUCTLISTPERCUSTOMER (PRODUCTCODE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint XPKI_PRODUCTLISTPERCUSTOMER primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint FK_I_PRODUCTLISTPERCUST_BUDGET foreign key (CUSTOMERNUMBER, BUDGETCODE)
  references I_CUSTOMERBUDGETDEFINITION (CUSTOMERNUMBER, BUDGETCODE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DEFAULTSTOCKROOM foreign key (DEFAULTSTOCKROOM)
  references STOCKROOM (CODE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_TOM foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PRODUCTLISTPERCUSTOMER_CUSTO foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PRODUCTLISTPERCUSTOMER_PRODU foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint BILLINGMETHOD_VALIDATION1
  check (BILLINGMETHOD IN (1, 2, 3, 4, 5));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_BM1FIXEDWEARERS
  check (BM1FIXEDWEARERS IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_BUDGETUSAGE
  check (BUDGETUSAGE in (0,1,2));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_CHARGEEXCESS
  check (CHARGEEXCESS IN (0,1,2));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_DELIVERREPLACTQTY
  check ((SRCCHARGERENT =1 and DELIVERREPLACEMENTQTY ='Y') or (srcchargerent = 0));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_FREEQTYFREQUENCY
  check (FREEQTYFREQUENCY IN (0,1));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_STERILISATIONREQ
  check (STERILISATIONREQUIRED IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_VOLUMEPRICE
  check (VOLUMEPRICE BETWEEN 1 AND 999999);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_PLPC_BILLMETHOD1
  check (sizecode <> '*' or changesperweek <> 'N' or  billingmethod <> 1);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_PLPC_DEPOSITSTOCKALLOWED
  check ((DEPOSITSTOCKALLOWED = 'N') or (DEPOSITSTOCKALLOWED='Y' and BILLINGMETHOD=3));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint DELAYEVENEXCHANGE_VALIDATION15
  check (delayevenexchange between 0 and 8);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint INVBILLINGTYPE_VALIDATION
  check ((INVENTORYBILLINGTYPE = 0 and BILLINGMETHOD <> 3) or (BILLINGMETHOD=3 and INVENTORYBILLINGTYPE IN (0, 1, 2, 3, 4)) or
(BILLINGMETHOD=2 and INVENTORYBILLINGTYPE IN (0, 1, 2)));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PCPC_SIZECODE
  check (sizecode = upper(rtrim(ltrim(sizecode))));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_CHANGESPERWEEK
  check ((TYPEOFMERCHANDISE = 2 and changesperweek = 'Y' and billingmethod in (1,5)) or changesperweek = 'N');
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_CHARGEWASHESONLYFORCOG
  check (CHARGEWASHESONLYFORCOG in (0,1,2,3,4));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_CHK_DEPOSITSTOCKALLOWED
  check (DEPOSITSTOCKALLOWED IN ('N','Y'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_CHK_DEPOSITSTOCKCHRPERC
  check (DEPOSITSTOCKCHARGEPERCENTAGE BETWEEN 0 AND 100);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DATES_CHECK
  check (DATEINACTIVE >= DATEACTIVE);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DDEDELIVERYSCHEMECODE
  check ((DDEDELIVERYSCHEMECODE is null) or (DDEDELIVERYSCHEMECODE is not null and delayevenexchange = 7));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELAYEDEVENEXCHANGE
  check ((DELAYEVENEXCHANGE > 0 and STRAIGHTEVENEXCHANGE = 'N') or (DELAYEVENEXCHANGE = 0));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYFR
  check (DELIVERYDAYFR IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYMO
  check (DELIVERYDAYMO IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYSA
  check (DELIVERYDAYSA IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYSU
  check (DELIVERYDAYSU IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYTH
  check (DELIVERYDAYTH IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYTU
  check (DELIVERYDAYTU IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYDAYWE
  check (DELIVERYDAYWE IN ('D','B','P'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DELIVERYSCHEDULECODE
  check ((DELIVERYSCHEDULECODE is null) or (DELAYEVENEXCHANGE IN (0,7) and DELIVERYSCHEDULECODE  is not null));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DISCOUNTPERCENTAGERENT
  check ((DISCOUNTPERCENTAGERENT IS NULL) OR (DISCOUNTPERCENTAGERENT BETWEEN 0 AND 100));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_DISCOUNTPERCENTAGEWASH
  check ((DISCOUNTPERCENTAGEWASH  IS NULL) OR (DISCOUNTPERCENTAGEWASH BETWEEN 0 AND 100));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_FINISHINGMETCODE
  check (FINISHINGMETHODCODE = upper(trim(FINISHINGMETHODCODE)));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_MINIMUM_CHECK
  CHECK ((((MINIMUMQUANTITY = 0 AND MINIMUMTURNAROUND >= 0) OR
             (MINIMUMQUANTITY >= 0 AND MINIMUMTURNAROUND = 0)) AND BILLINGMETHOD = 2) OR
             BILLINGMETHOD <> 2);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_MINIMUMFREQ_CHECK
  check ((MINIMUMFREQUENCY <> 5) or (MINIMUMFREQUENCY=5 and DELAYEVENEXCHANGE = 7));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_PRICEUSAGE
  check (PRICEUSAGE BETWEEN 0 AND 4);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_PRODUCTCODE
  check (productcode = upper(trim(productcode)));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_PRODUCT_TOM_NOT_4
  check (TYPEOFMERCHANDISE <> 4);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_PRODUCT_TOM_NOT_5
  check (TYPEOFMERCHANDISE <> 5);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint I_PLPC_RENTPRICEPERFREQ
  check (RENTPRICEPERFREQUENCY IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint ISOILCOUNT_VALIDATION14
  check (SOILCOUNTMETHOD IN (1, 2, 3, 0));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint ISOILCOUNT_VALIDATION15
  check (SRCMETHOD IN (1, 2, 3, 4, 0));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint MINIMUMFREQUENCY_VALIDATION15
  check (minimumfrequency between 1 and 5);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint SIZE_BILLINGCHECK
  check ((SIZECODE <> '*') or (SIZECODE='*' and BILLINGMETHOD IN (1,2,3,4,5)));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint SIZESTAR_CHECK
  check ((SIZECODE = '*' and TYPEOFMERCHANDISE = 2) or (SIZECODE <> '*'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint SPECIFICPUTUPTYPE_VALIDATION15
  check (specificputuptype IN (0, 1, 2, 3, 4, 5));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint SRCFREQUENCY_VALIDATION15
  check (srcfrequency IN (0, 1, 2, 3));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint X_I_PLPC_RESIDUALVALUE
  check (RESIDUALVALUESCHEMECODE = UPPER(RTRIM(LTRIM(RESIDUALVALUESCHEMECODE))));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_CUSTOMERRELATED
  check (CUSTOMERRELATED IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_STRAIGHTEXHCANGE
  check (STRAIGHTEVENEXCHANGE  IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION_RETSTOCKALL
  check (RETURNSTOCKALLOWED IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION574
  check (CHARGEOVERUSE IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION575
  check (CHANGESPERWEEK IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION576
  check (ONSITEINVENTORYCOUNT IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION577
  check (CODEUNIQUELY IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION580
  check (CHARGESTOCKROOMINVENTORY IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION581
  check (DELIVERREPLACEMENTQTY IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint YN_VALIDATION582
  check (CLEANCOUNT IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_MATERIALMAINPERC
  check (MMPSPECIFICPERCENTAGE BETWEEN 0 AND 100); 
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_GARMENTSETUP
  check (GARMENTSETUP IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_GARMMAIN
  check (GARMENTMAINTENANCE IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_GARMLOSS
  check (GARMENTLOSS IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_GARMREPAIR
  check (GARMENTREPAIR IN ('Y','N')); 
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_CONTRACTCODE
  check (CONTRACTCODE IS NULL OR CONTRACTCODE = upper(trim(CONTRACTCODE)));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_FIXEDSTOCKROOM
  check (FIXEDSTOCKROOM IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_ALLOWRETURNTOSTOCK
  check (ALLOWRETURNTOSTOCK in (0,1,2,3,4));  
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_MBYOPPERCENTAGE
  check (MBYOPPERCENTAGE BETWEEN 0.0 AND 100.0);
ALTER TABLE I_PRODUCTLISTPERCUSTOMER
  ADD CONSTRAINT CHK_I_PLPC_SEASONALRENT
  CHECK (SEASONALRENT IN (0,1,2));
ALTER TABLE I_PRODUCTLISTPERCUSTOMER
  ADD CONSTRAINT CHK_I_PLPC_CHRWASHINACTSEASON
  CHECK (CHARGEWASHINACTIVESEASON IN ('Y','N'));
ALTER TABLE I_PRODUCTLISTPERCUSTOMER
  ADD CONSTRAINT CHK_I_PLPC_CAUTOSOILPERC
  CHECK (AUTOSOILPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_LOSSCHARGEPERC
  check (LOSSCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_SRCHARGEPERC
  check (SRCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_GRMLOSSPERC check (GARMENTLOSSPERCENTAGE BETWEEN 0 AND 100);
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_GARMEMB check (GARMENTEMBLEM IN ('Y','N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_SPECBULKP check (SPECIFICBULKPACKINGTYPE IN (0,1,2));
ALTER TABLE I_PRODUCTLISTPERCUSTOMER
  ADD CONSTRAINT CHK_I_PLPC_SERVBILL CHECK (SERVICEBILLING IN ('Y', 'N'));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint CHK_I_PLPC_BM1RENTCPWMAX check (BM1RENTCPWMAX IN (0,1,2));
alter table I_PRODUCTLISTPERCUSTOMER
  add constraint FK_I_PRODUCTLISTPERCUSTOMER_SIZEBILLINGGROUPCODE foreign key (SIZEBILLINGGROUPCODE)
  references SIZEBILLINGGROUP(CODE); 

prompt
prompt Creating table I_PLPCTEMPRENTSTOP
prompt ========================================
prompt
create table I_PLPCTEMPRENTSTOP
(
  CUSTOMERNUMBER               NUMBER NOT NULL,
  PRODUCTCODE                  VARCHAR2(12) NOT NULL,
  SIZECODE                     VARCHAR2(12) NOT NULL,
  FINISHINGMETHODCODE          VARCHAR2(6) DEFAULT '-' NOT NULL,
  TEMPORARYRENTSTOPSTARTDATE   DATE NOT NULL,
  TEMPORARYRENTSTOPENDDATE     DATE NOT NULL
);
alter table I_PLPCTEMPRENTSTOP
  add constraint XPKI_PLPCTEMPRENTSTOP primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_PLPCTEMPRENTSTOP
  add constraint I_PLPCTEMPRENTSTOP_PLPC foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_PLPCTEMPRENTSTOP
  add constraint CHK_I_PLPCTEMPRENTSTOP check (TEMPORARYRENTSTOPSTARTDATE <=TEMPORARYRENTSTOPENDDATE);

prompt
prompt Creating table I_CUSTOMERIMAGECAREPRICE
prompt ========================================
prompt
create table I_CUSTOMERIMAGECAREPRICE
(
  CUSTOMERNUMBER      NUMBER NOT NULL,
  PRODUCTCODE         VARCHAR2(12) NOT NULL,
  SIZECODE            VARCHAR2(12) NOT NULL,
  STARTDATE           DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  PRICE               NUMBER(15,6) NOT NULL
);
create index XI_CUSTOMERIMAGECAREPRICE on I_CUSTOMERIMAGECAREPRICE (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE);
alter table I_CUSTOMERIMAGECAREPRICE
  add constraint XPKI_CUSTOMERIMAGECAREPRICE primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, STARTDATE);
alter table I_CUSTOMERIMAGECAREPRICE
  add constraint FK_I_CUSTIMAGECAREPRICE_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CUSTOMERIMAGECAREPRICE
  add constraint FK_I_CUSTIMAGECAREPRICE_PROD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);  
alter table I_CUSTOMERIMAGECAREPRICE
  add constraint CHK_I_CUSTIMAGECAREPRC_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));  

prompt
prompt Creating table I_CHANGESPERWEEKRENTPRICE
prompt ========================================
prompt
create table I_CHANGESPERWEEKRENTPRICE
(
  CUSTOMERNUMBER      NUMBER NOT NULL,
  PRODUCTCODE         VARCHAR2(12) NOT NULL,
  SIZECODE            VARCHAR2(12) NOT NULL,
  FINISHINGMETHODCODE VARCHAR2(6) DEFAULT '-' NOT NULL,
  CHANGES             NUMBER NOT NULL,
  STARTDATE           DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  PRICE               NUMBER(15,6) NOT NULL,
  CONTRACTCOEFFICIENT NUMBER(6,3),
  MAXINVENTORY        NUMBER,
  SIZEBILLINGGROUPCODE VARCHAR2(12)
);
comment on column I_CHANGESPERWEEKRENTPRICE.maxinventory
  is 'Only used for rent price per changes per week per max inventory';
create index XIF1I_CHANGESPERWEEKRENTPRICE on I_CHANGESPERWEEKRENTPRICE (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_CHANGESPERWEEKRENTPRICE
  add constraint XPKI_CHANGESPERWEEKRENTPRICE primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, CHANGES, MAXINVENTORY , STARTDATE);
alter table I_CHANGESPERWEEKRENTPRICE
  add constraint I_CHANGESPERWEEKRENTPRICE_CUST foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE) on delete cascade;
ALTER TABLE I_CHANGESPERWEEKRENTPRICE ADD CONSTRAINT CHK_I_CHANGESPERWEEKREN_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_CHANGESPERWEEKRENTPRICE
  add constraint FK_I_CHANGESPERWEEKRENPRICE_SIZEBILLINGGROUPCODE foreign key (SIZEBILLINGGROUPCODE)
  references SIZEBILLINGGROUP(CODE); 
alter table I_CHANGESPERWEEKRENTPRICE
  add constraint CHK_I_CHANGESPERWKRNTPRC_SIZE
  check (SIZECODE = upper(trim(SIZECODE))); 
alter table I_CHANGESPERWEEKRENTPRICE
  add constraint CHK_I_CHANGESPERWKRNTPRC_FIN
  check (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
alter table I_CHANGESPERWEEKRENTPRICE
  add constraint CHK_I_CHANGESPERWEEKREN_MAX
  check (MAXINVENTORY >= 0); 

prompt
prompt Creating table I_CUSTOMERRESIDENTIALSETTINGS
prompt ============================================
prompt
create table I_CUSTOMERRESIDENTIALSETTINGS
(
  customernumber                NUMBER not null,
  delivery_mo                   VARCHAR2(1) default 'N',
  delivery_tu                   VARCHAR2(1) default 'N',
  delivery_we                   VARCHAR2(1) default 'N',
  delivery_th                   VARCHAR2(1) default 'N',
  delivery_fr                   VARCHAR2(1) default 'N',
  delivery_sa                   VARCHAR2(1) default 'N',
  delivery_su                   VARCHAR2(1) default 'N',
  customerclients               NUMBER default 0,
  labellayout                   VARCHAR2(6) default '-',
  labellayoutdescription        VARCHAR2(60) default '-',
  firsttimefreeofchargelabels   NUMBER(4) default 0,
  remark                        VARCHAR2(80),
  printstickersatpackingstation VARCHAR2(1) default 'Y',
  printnote                     VARCHAR2(1) default 'N',
  printlatepieces               VARCHAR2(1) default 'N',
  inscanbulkallowed             NUMBER default 0,
  acceptallproducts             VARCHAR2(1) default 'N',
  acceptotherclients            NUMBER default 0,
  resortcustomer                VARCHAR2(1) default 'N',
  sortorder                     NUMBER default 1,
  outscanbulk                   VARCHAR2(1) default 'N',
  returnitems                   NUMBER default 1,
  printqtyreceived              VARCHAR2(1) default 'N',
  printidcode                   VARCHAR2(1) default 'N',
  printpriceondelnote           VARCHAR2(1) default 'N',
  delnoteformlayout             VARCHAR2(6) default '-',
  clientinvoiceformlayout       VARCHAR2(6) default '-',
  customerlabelprice            NUMBER(15,6),
  customerpatchprice            NUMBER(15,6),
  outscansort                   NUMBER default 3 not null,
  printclientdeliverynote       NUMBER default 1 not null,
  deliverynotelayout            VARCHAR2(6)
);
comment on column I_CUSTOMERRESIDENTIALSETTINGS.customernumber
  is 'Must exist in I_CUSTOMER';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.delivery_mo
  is '''Y'' if customer is visited for residential services on Monday, else ''N''.Note: at least one day of the week must be set to ''Y''';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.customerclients
  is '(0,1) 0 = Residents, 1 = Private persons. All clients that are attached to this customer will be residents or private persons. Option ''private persons'' can be used in case of a depot or shop. Use ''Residents'' for all other customers.';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.labellayout
  is 'Code for customer label';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.firsttimefreeofchargelabels
  is 'Number of labels that can be issued free for the customer';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.printlatepieces
  is 'Print late pieces on client delivery note';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.inscanbulkallowed
  is '(0,1,2) 0 = Customer is not scanned in, 1 = Customer is scanned in, bulk allowed.2 = Customer is scanned in, per client only (bulk inscan not allowed)';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.acceptallproducts
  is 'In case ''N'' it is not possible to scan or count products other than those that are defined in the product list per customer. In case ''Y'' all residential products can be scanned or counted.';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.acceptotherclients
  is '(0,1,2) Scanning in per client: 0 = It is not allowed to accept items from another client. 1 = Items from another client are accepted and will be returned to the sender. 2 = Items from another client are accepted and will be returned to owner';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.resortcustomer
  is 'If ''Y'' customer is set using (manual) presorting';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.sortorder
  is '(0,1,2,3,4) Sorting at outscan:
  0 = Sort on delivery note number.
  1 = Sort on client number.
  2 = Sort on client search name.
  3 = Sort on department / room number (this option is not allowed if I is set to 1 (private persons don''t have a room number).
  4 = Department / Sequence number / Room number (this option is not allowed if I is set to 1 (private persons don''t have a room number)';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.returnitems
  is '1 = Next visit. 2 = Same route next week. 3 = Return route';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.delnoteformlayout
  is 'Layout code for client delivery note, FormType=DC';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.clientinvoiceformlayout
  is 'Layout code for client invoice, FormType=IC';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.outscansort
  is '0 = No Sorting info
1 = Department Number
2 = Room Number
3 = Box Number
4 = Delivery Point
5 = Service Team
6 = Client Number
7 = Box Number + Department Number';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.printclientdeliverynote
  is '0 = Manual
1 = Outscan / sort, Upon closing batch
2 = Soil receiving, upon change of batch
3 = Soil receiving, upon change of client
4 = Outscan / sort, upon change of client
5 = Both soil receiving and outscan / sort, upon change of client.';
comment on column I_CUSTOMERRESIDENTIALSETTINGS.deliverynotelayout
  is 'Layout code for delivery note, FormType=DN';
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint XPI_RESIDENTIALSETTINGS primary key (CUSTOMERNUMBER);
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint XFK_I_RESIDENTIAL_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_ACCEPTALLPROD
  check (ACCEPTALLPRODUCTS IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_ACCEPTOTHERCL
  check (ACCEPTOTHERCLIENTS IN (0,1,2));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_CLIENTINVOICE
  check (CLIENTINVOICEFORMLAYOUT= UPPER(LTRIM(RTRIM(CLIENTINVOICEFORMLAYOUT))));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_CUSTCLIENT
  check (CUSTOMERCLIENTS IN (0,1));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_DELIVERYNOTE
  check (DELIVERYNOTELAYOUT=UPPER(TRIM(DELIVERYNOTELAYOUT)));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_DELNOTFORM
  check (DELNOTEFORMLAYOUT = UPPER(LTRIM(RTRIM(DELNOTEFORMLAYOUT))));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_FR
  check (DELIVERY_FR IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_INSCANBULKAL
  check (INSCANBULKALLOWED IN (0,1,2));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_LABELLAYOUT
  check (LABELLAYOUT = UPPER(LTRIM(RTRIM(LABELLAYOUT))));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_MO
  check (DELIVERY_MO IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_OUTSCANBULK
  check (OUTSCANBULK IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_OUTSCANSORT
  check (OUTSCANSORT IN (0,1,2,3,4,5,6,7));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_PRINTIDCODE
  check (PRINTIDCODE IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_PRINTLATEPIEC
  check (PRINTLATEPIECES IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_PRINTNOTE
  check (PRINTNOTE IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_PRINTQTYRECEIV
  check (PRINTQTYRECEIVED IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_PRTCLTDELNOTE
  check (PRINTCLIENTDELIVERYNOTE IN (0,1,2,3,4,5));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_PRTPRCONDELNTE
  check (PRINTPRICEONDELNOTE IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_RESORTCUSTOMER
  check (RESORTCUSTOMER IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_RETURNITEMS
  check (RETURNITEMS IN (1,2,3));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_SA
  check (DELIVERY_SA IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_SORTORDER
  check (SORTORDER IN (0,1,2) OR (SORTORDER in(3,4) AND CUSTOMERCLIENTS <> 1));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_STICKSTAT
  check (PRINTSTICKERSATPACKINGSTATION IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_SU
  check (DELIVERY_SU IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_TH
  check (DELIVERY_TH IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_TU
  check (DELIVERY_TU IN ('Y','N'));
alter table I_CUSTOMERRESIDENTIALSETTINGS
  add constraint X_I_RESIDENTIAL_WE
  check (DELIVERY_WE IN ('Y','N'));

prompt
prompt Creating table I_CONTACTPERSON
prompt ==============================
prompt
create table I_CONTACTPERSON
(
  CUSTOMERNUMBER             NUMBER NOT NULL,
  CONTACTPERSONNUMBER        NUMBER NOT NULL,
  EMAIL                      VARCHAR2(300),
  FAX                        VARCHAR2(30),
  MOBILEPHONE                VARCHAR2(30),
  PHONE                      VARCHAR2(30),
  INVOICECONTACTPERSON       VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CONTACTPERSONNAME          VARCHAR2(90) NOT NULL,
  CONTACTPERSONFUNCTIONCODE  VARCHAR2(6),
  CONTACTPERSONFUNCTIONDESCR VARCHAR2(30),
  STATEMENTCONTACTPERSON     VARCHAR2(1) DEFAULT 'N' NOT NULL
);
create index XIF892I_CONTACTPERSON on I_CONTACTPERSON (CUSTOMERNUMBER);
alter table I_CONTACTPERSON
  add constraint XPKI_CONTACTPERSON primary key (CUSTOMERNUMBER, CONTACTPERSONNUMBER);
alter table I_CONTACTPERSON
  add constraint I_CONTACTPERSON_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CONTACTPERSON
  add constraint I_CONTACTPERSONFUNCTION
  check ((CONTACTPERSONFUNCTIONCODE is null) or (CONTACTPERSONFUNCTIONCODE = upper(rtrim(ltrim(CONTACTPERSONFUNCTIONCODE)))));
alter table I_CONTACTPERSON
  add constraint YN_VALIDATION549
  check (INVOICECONTACTPERSON IN ('Y', 'N'));
alter table I_CONTACTPERSON
  add constraint CHK_I_CONTPER_STATEMNTPER_YN
  check (STATEMENTCONTACTPERSON IN ('Y', 'N'));
COMMENT ON COLUMN I_CONTACTPERSON.STATEMENTCONTACTPERSON
IS 'Allowed Y/N. Default N. Only 1 contact person for a customer may have a Y';

prompt
prompt Creating table I_DEPARTMENT
prompt ===========================
prompt
create table I_DEPARTMENT
(
  customernumber           NUMBER not null,
  departmentnumber         NUMBER(6) not null,
  departmentname           VARCHAR2(40) not null,
  occupancylevel           NUMBER,
  delivernotetoemail       VARCHAR2(1) default 'N' not null,
  delivery_mo              VARCHAR2(1) default 'Y' not null,
  delivery_tu              VARCHAR2(1) default 'Y' not null,
  delivery_we              VARCHAR2(1) default 'Y' not null,
  delivery_th              VARCHAR2(1) default 'Y' not null,
  delivery_fr              VARCHAR2(1) default 'Y' not null,
  delivery_sa              VARCHAR2(1) default 'Y' not null,
  delivery_su              VARCHAR2(1) default 'Y' not null,
  active                   VARCHAR2(1) default 'Y' not null,
  contactpersonnumber      NUMBER,
  standardpackqty          VARCHAR2(1),
  deliverypointnumber      VARCHAR2(12),
  deliverypointdescription VARCHAR2(30),
  deliveryaddress          VARCHAR2(40),
  deliveryaddress2         VARCHAR2(40),
  deliveryzipcode          VARCHAR2(15),
  deliverycity             VARCHAR2(30),
  deliverycounty           VARCHAR2(20),
  deliverystate            VARCHAR2(20),
  legacydepartmentcode     VARCHAR2(12),
  stockcountsequence_mo    NUMBER,
  stockcountsequence_tu    NUMBER,
  stockcountsequence_we    NUMBER,
  stockcountsequence_th    NUMBER,
  stockcountsequence_fr    NUMBER,
  stockcountsequence_sa    NUMBER,
  stockcountsequence_su    NUMBER,
  deliveryaddress3         VARCHAR2(40)
);
comment on column I_DEPARTMENT.occupancylevel
  is 'Current occupancy level in percentages.
The default percentage is 100.';
comment on column I_DEPARTMENT.legacydepartmentcode
  is 'Optional field for department code from old system';
create index XIF1I_DEPARTMENT on I_DEPARTMENT (CUSTOMERNUMBER);
create index XIF3I_DEPARTMENT on I_DEPARTMENT (CUSTOMERNUMBER, CONTACTPERSONNUMBER);
alter table I_DEPARTMENT
  add constraint XPKI_DEPARTMENT primary key (CUSTOMERNUMBER, DEPARTMENTNUMBER);
alter table I_DEPARTMENT
  add constraint I_DEPARTMENT_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_DEPARTMENT
  add constraint I_DEPARTMENT_CUSTOMERNUMBER___ foreign key (CUSTOMERNUMBER, CONTACTPERSONNUMBER)
  references I_CONTACTPERSON (CUSTOMERNUMBER, CONTACTPERSONNUMBER);
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3186
  check (DELIVERNOTETOEMAIL IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3187
  check (DELIVERY_MO IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3188
  check (DELIVERY_TU IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3189
  check (DELIVERY_WE IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3190
  check (DELIVERY_TH IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3191
  check (DELIVERY_FR IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3192
  check (DELIVERY_SA IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3193
  check (DELIVERY_SU IN ('Y', 'N'));
alter table I_DEPARTMENT
  add constraint YN_VALIDATION3194
  check (ACTIVE IN ('Y', 'N'));

prompt
prompt Creating table I_CLIENT
prompt =======================
prompt
create table I_CLIENT
(
  customernumber            NUMBER not null,
  clientnumber              NUMBER(6) not null,
  departmentnumber          NUMBER(6) not null,
  distributionpointnumber   NUMBER,
  clientstreet              VARCHAR2(40),
  clientzipcode             VARCHAR2(15),
  clientcity                VARCHAR2(30),
  roomnumber                VARCHAR2(12),
  legacycode                VARCHAR2(12),
  name                      VARCHAR2(40) not null,
  firstname                 VARCHAR2(40),
  searchname                VARCHAR2(20) not null,
  gender                    NUMBER default 3,
  clientemail               VARCHAR2(300),
  clientphonenumber         VARCHAR2(30),
  clientmobilephone         VARCHAR2(30),
  remark                    VARCHAR2(80),
  dateactive                DATE default TRUNC(SYSDATE)-1,
  dateinactive              DATE default TO_DATE('31-12-2099','DD-MM-YYYY'),
  presortnumber             NUMBER default 0,
  adminnumber               VARCHAR2(20),
  labelname                 VARCHAR2(40),
  birthdate                 DATE,
  dateoutofservice          DATE,
  clientcategorycode        VARCHAR2(6),
  clientcategorydesc        VARCHAR2(30),
  clientinvoicecategorycode VARCHAR2(6),
  clientinvoicecategorydesc VARCHAR2(30),
  invoiceto                 NUMBER default 0,
  sendinvoiceto             NUMBER default 0,
  bankaccoutnumber          VARCHAR2(30),
  residentialserviceallowed VARCHAR2(1) default 'Y',
  ibannumber                VARCHAR2(20),
  freelabelsissued          NUMBER default 0,
  contactname               VARCHAR2(40),
  contactstreet             VARCHAR2(40),
  contactzipcode            VARCHAR2(15),
  contactcity               VARCHAR2(30),
  contactphone              VARCHAR2(30),
  contactinvoicereceiver    VARCHAR2(1) default 'N',
  flagcode                  VARCHAR2(6),
  flagdesription            VARCHAR2(50) default '-',
  flagstartdate             DATE default TRUNC(SYSDATE)-1,
  deliverypointnumber       VARCHAR2(12),
  paymenttype               NUMBER default 0 not null,
  budgetclient              NUMBER default 0 not null,
  publicservicenumber       VARCHAR2(20),
  selfpayment               NUMBER default 0 not null
);
comment on column I_CLIENT.customernumber
  is 'Must exist in I_CUSTOMER';
comment on column I_CLIENT.clientnumber
  is 'Must be unique per customer';
comment on column I_CLIENT.departmentnumber
  is 'Must exist in I_DEPARTMENT together with CUSTOMERNUMBER';
comment on column I_CLIENT.distributionpointnumber
  is 'Obligated for private person';
comment on column I_CLIENT.clientstreet
  is 'Obligated for private person';
comment on column I_CLIENT.clientzipcode
  is 'Obligated for private person';
comment on column I_CLIENT.clientcity
  is 'Obligated for private person';
comment on column I_CLIENT.roomnumber
  is 'Obligated for residents,when not known fill ''-''';
comment on column I_CLIENT.gender
  is '1 = Male 2 = Female 3 = Unknown (default)';
comment on column I_CLIENT.presortnumber
  is 'Presort group number. Only applicable if customer is set to using presorting (if not store 0).';
comment on column I_CLIENT.dateoutofservice
  is 'Do not fill when client active, but leave empty!';
comment on column I_CLIENT.invoiceto
  is '0 = All to customer, 1 = All to client, 2 = Split';
comment on column I_CLIENT.sendinvoiceto
  is '0 = Customer, 1 = Client contact person, 2 = Client';
comment on column I_CLIENT.residentialserviceallowed
  is 'If set to ''N'' the client should not be serviced';
comment on column I_CLIENT.freelabelsissued
  is 'Number of labels that have been issued free so far for this client';
comment on column I_CLIENT.contactname
  is 'Contact person. In case invoice is send to contact person';
comment on column I_CLIENT.deliverypointnumber
  is 'Only for clientprivateperson, default will otherwise be the clientnumber';
comment on column I_CLIENT.paymenttype
  is '0 = Cash /Not applicable
1 = Check
2 = Credit Card
3 = EFT
4 = EDI
5 = Accept Giro
6 = Automatic Collection
Default 0 (paid via Customer) ';
comment on column I_CLIENT.budgetclient
  is 'This attribute is only used for module TEXTILECONTROLLING
  0 = Client is not using budget and no self payer
  1 = Client is not using budget and is self payer
  2 = Client is using budget';
comment on column I_CLIENT.publicservicenumber
  is 'When system setting PUBLISERVICENOVALIDATION = 1, then the field should be validated to verify if it is a correct number according to the Danish CPR standard';
comment on column I_CLIENT.selfpayment
  is '0=Inherit from PLPC(Default), 1 = Customer Pays, 2 = Client pays';
create index INDX_CLIENT_DEPARTMENT on I_CLIENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);
alter table I_CLIENT
  add constraint XPK_I_CLIENT primary key (CUSTOMERNUMBER, CLIENTNUMBER);
alter table I_CLIENT
  add constraint FK_I_CLIENT_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMERRESIDENTIALSETTINGS (CUSTOMERNUMBER);
alter table I_CLIENT
  add constraint FK_I_CLIENT_DEPARTMENTNUMBER foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER)
  references I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);
alter table I_CLIENT
  add constraint CHK_I_CLIENT_BUDGETCLIENT
  check (BUDGETCLIENT IN (0,1,2));
alter table I_CLIENT
  add constraint X_I_CLIENT_CHECK
  check ((DISTRIBUTIONPOINTNUMBER IS NOT NULL AND CLIENTSTREET IS NOT NULL AND CLIENTZIPCODE IS NOT NULL AND CLIENTCITY IS NOT NULL) OR (ROOMNUMBER IS NOT NULL));
alter table I_CLIENT
  add constraint X_I_CLIENT_CONTACTINVOICEREC
  check (CONTACTINVOICERECEIVER IN ('Y','N'));
alter table I_CLIENT
  add constraint X_I_CLIENT_DATECHECK
  check (DATEINACTIVE >= DATEACTIVE);
alter table I_CLIENT
  add constraint X_I_CLIENT_FLAGCODE
  check (FLAGCODE = UPPER(LTRIM(RTRIM(FLAGCODE))));
alter table I_CLIENT
  add constraint X_I_CLIENT_GENDERCHECK
  check (GENDER IN (1, 2, 3));
alter table I_CLIENT
  add constraint X_I_CLIENT_INVOICETO
  check (INVOICETO IN (0,1,2));
alter table I_CLIENT
  add constraint X_I_CLIENT_RESIDENTIALSERV
  check (RESIDENTIALSERVICEALLOWED IN ('Y','N'));
alter table I_CLIENT
  add constraint X_I_CLIENT_SELFPAYMENT
  check (SELFPAYMENT in (0,1,2));
alter table I_CLIENT
  add constraint X_I_CLIENT_SENDINVOICETO
  check (SENDINVOICETO IN (0,1,2));

prompt
prompt Creating table I_CONSUMPTIONPOINT
prompt =================================
prompt
create table I_CONSUMPTIONPOINT
(
  CONSUMPTIONPOINTNUMBER       NUMBER(2) NOT NULL,
  CUSTOMERNUMBER               NUMBER NOT NULL,
  DEPARTMENTNUMBER             NUMBER(6) NOT NULL,
  CONSUMPTIONPOINTDESCRIPTION  VARCHAR2(30) NOT NULL,
  DELIVERYPOINTNUMBER          VARCHAR2(12),
  REMARKONDELIVERYNOTE         VARCHAR2(1000),
  REMARKONPACKINGNOTE          VARCHAR2(1000),
  CLEANRETURN                  VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CORRECTSHORTAGES             VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CORRECTOVERDELIVERIES        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  TRUCKLOADPOSITION            VARCHAR2(6),
  TRANSPORTARTICLECODE         VARCHAR2(6),
  NUMBEROFTRANSPORTARTICLES    NUMBER DEFAULT 1 NOT NULL,
  GENERATEZEROLINES            VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DELIVERSTERILE               VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PROOFOFVISITBARCODE          VARCHAR2(12),
  DRIVERINSTRUCTION            VARCHAR2(1000),
  LEGACYCONSUMPTIONPOINTNUMBER VARCHAR2(6),
  MATERIALMAINTENANCE          VARCHAR2(1),
  GARMENTSETUP                 VARCHAR2(1),
  GARMENTMAINTENANCE           VARCHAR2(1),
  GARMENTLOSS                  VARCHAR2(1),
  GARMENTREPAIR                VARCHAR2(1),
  MBYOPROTECTION               VARCHAR2(1) DEFAULT 'N' NOT NULL,
  GARMENTEMBLEM                VARCHAR2(1) DEFAULT 'N' NOT NULL
);
comment on column I_CONSUMPTIONPOINT.legacyconsumptionpointnumber
  is 'LEGACYDISTRIBUTIONPOINTNUMBER2';
alter table I_CONSUMPTIONPOINT
  add constraint XPKI_CONSUMPTIONPOINT primary key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_CONSUMPTIONPOINT
  add constraint I_CONSUMPTIONPOINT_CUSTOMERNUM foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER)
  references I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);
alter table I_CONSUMPTIONPOINT
  add constraint NUMBER_TRANSPORTARTICLES
  check (NUMBEROFTRANSPORTARTICLES >= 1);
alter table I_CONSUMPTIONPOINT
  add constraint YN_VALIDATION3195
  check (CLEANRETURN IN ('Y', 'N'));
alter table I_CONSUMPTIONPOINT
  add constraint YN_VALIDATION3196
  check (CORRECTSHORTAGES IN ('Y', 'N'));
alter table I_CONSUMPTIONPOINT
  add constraint YN_VALIDATION3197
  check (CORRECTOVERDELIVERIES IN ('Y', 'N'));
alter table I_CONSUMPTIONPOINT
  add constraint YN_VALIDATION3198
  check (GENERATEZEROLINES IN ('Y', 'N'));
alter table I_CONSUMPTIONPOINT
  add constraint YN_VALIDATION3199
  check (DELIVERSTERILE IN ('Y', 'N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_MATMAIN
  check (MATERIALMAINTENANCE IN ('Y','N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_GARMSETUP
  check (GARMENTSETUP IN ('Y','N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_GARMMAIN
  check (GARMENTMAINTENANCE IN ('Y','N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_GARMLOSS
  check (GARMENTLOSS IN ('Y','N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_GARMREPAIR
  check (GARMENTREPAIR IN ('Y','N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_MBYOPROTECTION
  check (MBYOPROTECTION IN ('Y','N'));
alter table I_CONSUMPTIONPOINT
  add constraint CHK_I_CONS_GARMEMB
  check (GARMENTEMBLEM IN ('Y','N'));

PROMPT
PROMPT CREATING TABLE I_CONTACTCALLS
PROMPT =============================
PROMPT
CREATE TABLE I_CONTACTCALLS
(
  CALLNUMBER                 NUMBER NOT NULL,
  BUSINESSUNIT               VARCHAR2(6) NOT NULL,
  CUSTOMER                   NUMBER NOT NULL,
  CONTACTCATEGORYCODE        VARCHAR2(6) DEFAULT '-' NOT NULL,
  DEPARTMENT                 NUMBER(6),
  STATUS                     NUMBER NOT NULL,
  CONTACTCATEGORYDESCRIPTION VARCHAR2(30),
  CREATEDATE                 DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  CREATEDBY                  VARCHAR2(20) NOT NULL,
  CREATEDBYFULLNAME          VARCHAR2(30) NOT NULL,
  FOLLOWUPDATE               DATE,
  FOLLOWUPNEEDEDBY           VARCHAR2(20),
  INPROGRESSDATE             DATE,
  FOLLOWUPNEEDEDBYFULLNAME   VARCHAR2(30),
  CLOSEDATE                  DATE,
  CUSTOMERCONTACTPERSON      NUMBER,
  CONTACTNOTES               VARCHAR2(500) NOT NULL,
  FOLLOWUPNOTES              VARCHAR2(500),
  GROUPNAME                  VARCHAR2(20) DEFAULT 'SYSADM' NOT NULL,
  SHOWONROUTELIST            VARCHAR2(1) DEFAULT 'N' NOT NULL CONSTRAINT CHK_I_CONT_SHOWONROUTELIST CHECK(SHOWONROUTELIST IN('Y','N')),
  INPROGRESSBYUSER           VARCHAR2(20),
  CLOSEDBYUSER               VARCHAR2(20),
  PRIORITY                   NUMBER DEFAULT 1 NOT NULL,
  CONTACTCAUSE_CODE          VARCHAR2(6),
  COMPLETEDDATE              DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  COMPLETEDBYUSER            VARCHAR2(20),
  REVIEWDATE                 DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  REVIEWEDBYUSER             VARCHAR2(20),
  BLOCKDEPARTUREONSTOP       NUMBER DEFAULT 0 NOT NULL CONSTRAINT CHK_I_CONT_BLOCKDEPARTUREONST CHECK(BLOCKDEPARTUREONSTOP IN(0,1)),
  FOLLOWUPBYROUTE            VARCHAR2(1) DEFAULT 'N' NOT NULL CONSTRAINT CHK_I_CONT_FOLLOWUPBYROUTE CHECK(FOLLOWUPBYROUTE IN('Y','N')),
  ORIGINALCALLNUMBER         NUMBER,
  CHECKBEFOREROUTESTART      NUMBER DEFAULT 0 NOT NULL CONSTRAINT CHK_I_CONT_CHECKBEFOREROUTEST CHECK (CHECKBEFOREROUTESTART IN (0,1))
);
comment on column I_CONTACTCALLS.STATUS
  is '1=new 
2=need follow up
3=in progress 
4=completed
5=reviewed by manager
6=closed';
comment on column I_CONTACTCALLS.GROUPNAME
  is 'Usergroup that must exist in ABSSolute as a usergroup';
comment on column I_CONTACTCALLS.PRIORITY
  is '1 = Low
2 = Medium
3 = High';
comment on column I_CONTACTCALLS.REVIEWEDBYUSER
  is 'System User (Manager) that reviewed this contact';
comment on column I_CONTACTCALLS.BLOCKDEPARTUREONSTOP
  is 'Defines if contact needs to be changed before departure on stop is allowed on RA. 
Possible values: 
0 = Do not block/not applicable (default) 
1 = Do block departure on stop';
comment on column I_CONTACTCALLS.ORIGINALCALLNUMBER
  is 'Optional, so may be left empty. Default null. Will only be filled when created automatically as a result of a mass creation';
comment on column I_CONTACTCALLS.CHECKBEFOREROUTESTART  is 'Defines if contact needs to be read before route is started on RA. 
0 = Do not check/not applicable (default) 
1 = Do check before route start';
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT XAK1I_CONTACTCALLS PRIMARY KEY (CALLNUMBER);
CREATE INDEX XIF1I_CONTACTCALLS ON I_CONTACTCALLS (CUSTOMER);
CREATE INDEX XIF2I_CONTACTCALLS ON I_CONTACTCALLS (CUSTOMER, DEPARTMENT);
CREATE INDEX XIF3I_CONTACTCALLS ON I_CONTACTCALLS (CUSTOMER, CUSTOMERCONTACTPERSON);
CREATE INDEX INDX_I_CONTACTCALLS_BU ON I_CONTACTCALLS (BUSINESSUNIT);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT I_CONTACTCALLS_BUSINESSUNIT FOREIGN KEY (BUSINESSUNIT)
  REFERENCES BUSINESSUNIT (CODE);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT I_CONTACTCALLS_CONTACTNUMBER FOREIGN KEY (CUSTOMER, CUSTOMERCONTACTPERSON)
  REFERENCES I_CONTACTPERSON (CUSTOMERNUMBER, CONTACTPERSONNUMBER);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT I_CONTACTCALLS_CUSTOMERNUMBER FOREIGN KEY (CUSTOMER)
  REFERENCES I_CUSTOMER (CUSTOMERNUMBER);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT I_CONTACTCALLS_DEPARTMENTNUMBE FOREIGN KEY (CUSTOMER, DEPARTMENT)
  REFERENCES I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT I_CONTACTCALLS_USERGROUP FOREIGN KEY (GROUPNAME)
  REFERENCES USERGROUP (GROUPNAME);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT I_CONTACTCALLS_BU
  CHECK (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);
ALTER TABLE I_CONTACTCALLS
  ADD CONSTRAINT STATUSCONTACTCALLS
  CHECK (STATUS IN (1,2,3,4,5,6));

PROMPT
PROMPT CREATING TABLE I_CONTACTCALLS_FOLLOWUP
PROMPT ======================================
PROMPT  
CREATE TABLE I_CONTACTCALLS_FOLLOWUP
(
  CALLNUMBER                 NUMBER NOT NULL,
  CREATEDATE                 DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,  
  CREATEDBY                  VARCHAR2(20) NOT NULL,  
  CREATEDBYFULLNAME          VARCHAR2(30) NOT NULL,
  FOLLOWUPNOTES              VARCHAR2(500) NOT NULL
);
ALTER TABLE I_CONTACTCALLS_FOLLOWUP
  ADD CONSTRAINT PK_I_CONTACTCALLS_FOLLOWUP PRIMARY KEY (CALLNUMBER, CREATEDATE, CREATEDBY);
ALTER TABLE I_CONTACTCALLS_FOLLOWUP
  ADD CONSTRAINT FK_I_CONTACTCALLS_FOLLOWUP FOREIGN KEY (CALLNUMBER)
  REFERENCES I_CONTACTCALLS (CALLNUMBER);
CREATE INDEX INDX_I_CONTACTCALLS_FOLLOWUP ON I_CONTACTCALLS_FOLLOWUP (CALLNUMBER);

prompt
prompt Creating table I_CONTAINER
prompt ==========================
prompt
create table I_CONTAINER
(
  primaryid                VARCHAR2(24) not null,
  secondaryid              VARCHAR2(24),
  containertype_code       VARCHAR2(6) not null,
  containertype_desc       VARCHAR2(30) not null,
  containertype_tareweight NUMBER default 0,
  containertype_disinfect  VARCHAR2(1) default 'N',
  stay                     NUMBER default 10 not null,
  dateactive               DATE default TRUNC(SYSDATE)-1,
  dateinactive             DATE default TO_DATE('31-12-2099','DD-MM-YYYY'),
  tareweight               NUMBER,
  ownercustomernumber      NUMBER,
  ownerbusinessunitcode    VARCHAR2(6),
  usedbyotherbu            VARCHAR2(1) default 'N',
  customernumber           NUMBER,
  departmentnumber         NUMBER(6),
  distributionpoint        NUMBER,
  lastinscandate           DATE,
  lastoutscandate          DATE,
  lastdisinfectiondate     DATE,
  numberofdifinfections    NUMBER default 0,
  numberofshipments        NUMBER default 0
);
comment on column I_CONTAINER.stay
  is '10 InScan(default)  20 OutScan/At Customer  30 Disinfection  40 OR Load41 OR Sterile  50 Maintenance';
alter table I_CONTAINER
  add constraint PK_I_CONTAINER primary key (PRIMARYID);
alter table I_CONTAINER
  add constraint FK_I_CONTAINER_CUSTOMER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CONTAINER
  add constraint FK_I_CONTAINER_DEPARTMENT foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER)
  references I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);
alter table I_CONTAINER
  add constraint FK_I_CONTAINER_DISTRIBUTION foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER, DISTRIBUTIONPOINT)
  references I_CONSUMPTIONPOINT (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_CONTAINER
  add constraint FK_I_CONTAINER_OWNCUST foreign key (OWNERCUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CONTAINER
  add constraint CONTAINERTYPE_DISINFECT
  check (CONTAINERTYPE_DISINFECT in ('Y','N'));
alter table I_CONTAINER
  add constraint I_CONTAINER_STAY
  check (STAY in (10,20,30,40,41,50));
alter table I_CONTAINER
  add constraint USEDBYOTHERBU
  check (USEDBYOTHERBU in ('Y','N'));

prompt
prompt Creating table I_CONTRACT
prompt =========================
prompt
create table I_CONTRACT
(
  CONTRACTCODE                VARCHAR2(15) NOT NULL,
  CONTRACTDESCRIPTION         VARCHAR2(50) NOT NULL,
  CONTRACTTYPECODE            VARCHAR2(6) NOT NULL,
  CONTRACTTYPEDESC            VARCHAR2(30) NOT NULL,
  USERGROUPNAME               VARCHAR2(20),
  CONTRACTDOCUMENT            VARCHAR2(255),
  COMMISSIONPAYABLESALESYN    VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SALESEMPLOYEENUMBER         NUMBER,
  SALESEMPLOYEENAME           VARCHAR2(40),
  COMMISSIONPAYABLEACCMGRYN   VARCHAR2(1) DEFAULT 'N' NOT NULL,
  ACCOUNTMANAGERNUMBER        NUMBER,
  ACCOUNTMANAGERNAME          VARCHAR2(40),
  CUSTOMERNUMBER              NUMBER,
  OWNER                       VARCHAR2(40),
  OWNER_STREET                VARCHAR2(40),
  OWNER_ZIPCODE               VARCHAR2(15),
  OWNER_CITY                  VARCHAR2(30),
  OWNER_STATE                 VARCHAR2(20),
  OWNER_COUNTY                VARCHAR2(20),
  OWNER_COUNTRYCODE           VARCHAR2(3),
  CVRNUMBER                   VARCHAR2(15),
  PHONENUMBER                 VARCHAR2(30),
  SIGNDATE                    DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  STARTDATE                   DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  ENDDATE                     DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  DURATION                    NUMBER(3) DEFAULT 48 NOT NULL,
  TERMOFNOTICE                NUMBER(2) DEFAULT 3 NOT NULL,
  TERMINATIONDATE             DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  AUTEXTENSIONPERIOD          NUMBER(2) DEFAULT 12 NOT NULL,
  CUSTOMERCONTACTPERSONNUMBER NUMBER,
  CONTACTPERSONNAME           VARCHAR2(30),
  GAINREASONCODE              VARCHAR2(6),
  GAINREASONDESCRIPTION       VARCHAR2(30),
  LOSTREASONCODE              VARCHAR2(6),
  LOSTREASONDESCRIPTION       VARCHAR2(30),
  GAINCOMPETITORCODE          VARCHAR2(6),
  GAINCOMPETITORNAME          VARCHAR2(40),
  LOSTCOMPETITORCODE          VARCHAR2(6),
  LOSTCOMPETITORNAME          VARCHAR2(40),
  STARTDATEPRICEINCREASE      DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  UPDATEEVERY                 NUMBER(2) DEFAULT 6 NOT NULL,
  PREVIOUSPRICEINCREASE       DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  NEXTSCHEDULEDPRICEINCREASE  DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  AGREEDPRICEINDEXCODE        VARCHAR2(6) DEFAULT '1' NOT NULL,
  AGREEDPRICEINDEXDESC        VARCHAR2(50) DEFAULT '-' NOT NULL,
  NOTAGREEDPRICEINDEXCODE     VARCHAR2(6) DEFAULT '2',
  NOTAGREEDPRICEINDEXDESC     VARCHAR2(50) DEFAULT '-',
  ALLOWNOTAGREEDPRICEINDEXYN  VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PURCHASEORDER               VARCHAR2(30),
  PURCHASEORDERVALUE          NUMBER,
  PURCHASEORDEREXPIRATIONDATE DATE,
  ESTIMATEDWEEKLYSALES        NUMBER,
  REMARK                      VARCHAR2(300),
  RENEGOTIATIONDATE           DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  WARNDAYSPRICEINCREASE       NUMBER(2) DEFAULT 0 NOT NULL,
  WARNPRICEINCREASE           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CATEGORY                    NUMBER DEFAULT 3 NOT NULL,
  CURRENCY                    VARCHAR2(3),
  EMAIL                       VARCHAR2(300),
  GARMENTSCONTRACT            NUMBER DEFAULT 0 NOT NULL,
  SALESEMPLOYEENUMBER2        NUMBER,
  SALESEMPLOYEENAME2          VARCHAR2(40),
  SALESEMPLOYEE1PERCENTAGE    NUMBER,
  SALESEMPLOYEE2PERCENTAGE    NUMBER,
  SALESLEADEMPLOYEENUMBER     NUMBER,
  SALESLEADEMPLOYEENAME       VARCHAR2(40),
  PRIMARYCONTRACTCODE         VARCHAR2(15),
  USEPRODSIZESURCHARGEPRICING VARCHAR2(1) DEFAULT 'N',
  ALLOWNONCONTRACTPRODUCTS    VARCHAR2(1) DEFAULT 'Y',
  ALLOWNONCONTRACTEMBTEMP     VARCHAR2(1) DEFAULT 'Y',
  ALLOWNONCONTRACTWEARERFUNC  VARCHAR2(1) DEFAULT 'Y',
  COMPLIANCYTEMPLATE_CODE     VARCHAR2(6),
  COMMON_PRODUCTBILLING_COMPL NUMBER,
  COMMON_PRODUCTPRICING_COMPL NUMBER,
  COMMON_PRODUCTLOGISTI_COMPL NUMBER,
  COMMON_PRODUCTMISCELL_COMPL NUMBER,
  COMMON_PRODUCTBUDGETP_COMPL NUMBER,
  COMMON_EMBLEMTEMPLATE_COMPL NUMBER,
  COMMON_WEARERFUNCTION_COMPL NUMBER,
  CONTRACTDOCUMENTURL         VARCHAR2(1000)
);
comment on column I_CONTRACT.contractcode
  is 'Unique contract code';
comment on column I_CONTRACT.contracttypecode
  is 'Contract type table code';
comment on column I_CONTRACT.contracttypedesc
  is 'Contract type table description';
comment on column I_CONTRACT.usergroupname
  is 'Foreign key to usergroup table name';
comment on column I_CONTRACT.contractdocument
  is 'Document name including full path';
comment on column I_CONTRACT.commissionpayablesalesyn
  is 'Y,N Default N';
comment on column I_CONTRACT.salesemployeenumber
  is 'Employee table';
comment on column I_CONTRACT.salesemployeename
  is 'Employee table';
comment on column I_CONTRACT.commissionpayableaccmgryn
  is 'Y,N Default N';
comment on column I_CONTRACT.accountmanagernumber
  is 'Employee table';
comment on column I_CONTRACT.accountmanagername
  is 'Employee table';
comment on column I_CONTRACT.customernumber
  is 'FK to I_CUSTOMER if not null';
comment on column I_CONTRACT.owner
  is 'Only linked to a customer or OWNER fields filled';
comment on column I_CONTRACT.owner_street
  is 'FK to address';
comment on column I_CONTRACT.owner_zipcode
  is 'FK to address';
comment on column I_CONTRACT.owner_city
  is 'FK to address';
comment on column I_CONTRACT.owner_state
  is 'FK to address';
comment on column I_CONTRACT.owner_county
  is 'FK to address';
comment on column I_CONTRACT.owner_countrycode
  is 'FK to country table';
comment on column I_CONTRACT.enddate
  is 'Must be >= STARTDATE';
comment on column I_CONTRACT.duration
  is 'Duration in months default 48, between 1 and 999';
comment on column I_CONTRACT.termofnotice
  is 'Between 0 and duration';
comment on column I_CONTRACT.terminationdate
  is 'Default ''31-12-2099'', must be > signdate';
comment on column I_CONTRACT.autextensionperiod
  is 'Duration in months default 3, between 0 and 99';
comment on column I_CONTRACT.customercontactpersonnumber
  is 'Must exist in I_CONTACTPERSON, in case customernumber is not null';
comment on column I_CONTRACT.contactpersonname
  is 'In case customernumber is null';
comment on column I_CONTRACT.gainreasoncode
  is 'FK gainlost reason';
comment on column I_CONTRACT.gainreasondescription
  is 'FK gainlost reason desc';
comment on column I_CONTRACT.lostreasoncode
  is 'FK gainlost reason';
comment on column I_CONTRACT.lostreasondescription
  is 'FK gainlost reason desc';
comment on column I_CONTRACT.gaincompetitorcode
  is 'FK competitor';
comment on column I_CONTRACT.gaincompetitorname
  is 'FK competitor';
comment on column I_CONTRACT.lostcompetitorcode
  is 'FK competitor';
comment on column I_CONTRACT.lostcompetitorname
  is 'FK competitor';
comment on column I_CONTRACT.updateevery
  is 'Duration in months default 6, between 0 and 99';
comment on column I_CONTRACT.previouspriceincrease
  is 'Default ''31-12-2099'', means no previous price increase';
comment on column I_CONTRACT.nextscheduledpriceincrease
  is 'Must be > STARTDATEPRICEINCREASE';
comment on column I_CONTRACT.agreedpriceindexcode
  is 'FK priceindex';
comment on column I_CONTRACT.agreedpriceindexdesc
  is 'FK priceindex';
comment on column I_CONTRACT.notagreedpriceindexcode
  is 'FK priceindex';
comment on column I_CONTRACT.notagreedpriceindexdesc
  is 'FK priceindex';
comment on column I_CONTRACT.allownotagreedpriceindexyn
  is 'Y,N Default N';
comment on column I_CONTRACT.remark
  is 'Free text';
comment on column I_CONTRACT.warndayspriceincrease
  is '0 - 99, default 0';
comment on column I_CONTRACT.warnpriceincrease
  is 'Y / N default N';
comment on column I_CONTRACT.CATEGORY
  is '1 = Secondary 
2 = Not used 
3 = Primary (default) 
4 = Route Service Contract';
comment on column I_CONTRACT.GARMENTSCONTRACT
  is '0 = No Garments 
1 = Include Garments in Contract';
comment on column I_CONTRACT.COMMON_PRODUCTBILLING_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.COMMON_PRODUCTPRICING_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.COMMON_PRODUCTLOGISTI_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.COMMON_PRODUCTMISCELL_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.COMMON_PRODUCTBUDGETP_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.COMMON_EMBLEMTEMPLATE_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.COMMON_WEARERFUNCTION_COMPL
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACT.USEPRODSIZESURCHARGEPRICING is 'Only for module CHARGESPECIALSIZE';
alter table I_CONTRACT
  add constraint PK_I_CONTRACT primary key (CONTRACTCODE);
alter table I_CONTRACT
  add constraint FK_I_CONTRACT_COUNTRYCODE foreign key (OWNER_COUNTRYCODE)
  references COUNTRY (CODE);
alter table I_CONTRACT
  add constraint I_CONTRACT_CURRENCY foreign key (CURRENCY)
  references CURRENCY (CODE);
alter table I_CONTRACT
  add constraint FK_I_CONTRACT_CUSTOMER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_CONTRACT
  add constraint I_CONTRACT_ALLOWNOTAGRPRCINDYN
  check (ALLOWNOTAGREEDPRICEINDEXYN IN ('Y','N'));
alter table I_CONTRACT
  add constraint I_CONTRACT_COMMPAYABLEACCMGRYN
  check (COMMISSIONPAYABLEACCMGRYN IN ('Y','N'));
alter table I_CONTRACT
  add constraint I_CONTRACT_COMMPAYABLESALESYN
  check (COMMISSIONPAYABLESALESYN IN ('Y','N'));
alter table I_CONTRACT
  add constraint I_CONTRACT_DATECHECK
  check (ENDDATE >= STARTDATE);
alter table I_CONTRACT
  add constraint I_CONTRACT_OWNER
  check ((OWNER IS NULL) OR (OWNER_ZIPCODE IS NOT NULL AND OWNER_CITY IS NOT NULL AND OWNER_COUNTY IS NOT NULL));
alter table I_CONTRACT
  add constraint I_CONTRACT_OWNER_CUSTOMER
  check ((OWNER IS NOT NULL AND CUSTOMERNUMBER IS NULL) OR (OWNER IS NULL AND CUSTOMERNUMBER IS NOT NULL));
alter table I_CONTRACT
  add constraint CHK_I_CONTRACT_CONTRACTCODE
  check (CONTRACTCODE = upper(trim(CONTRACTCODE)));
alter table I_CONTRACT
  add constraint CHK_I_CONTRACT_CATEGORY
  check ((CATEGORY = 1 AND PRIMARYCONTRACTCODE IS NOT NULL) OR (CATEGORY IN (3,4)));
alter table I_CONTRACT
  add constraint CHK_I_CONTRACT_USEPSCSIZE
  check (USEPRODSIZESURCHARGEPRICING IN ('Y','N'));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_BILLCOMPL
  CHECK (COMMON_PRODUCTBILLING_COMPL IN (NULL, 0, 1, 2));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_PRICCOMPL
  CHECK (COMMON_PRODUCTPRICING_COMPL IN (NULL, 0, 1, 2));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_PRODCOMPL
  CHECK (COMMON_PRODUCTLOGISTI_COMPL IN (NULL, 0, 1, 2));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_MISCCOMPL
  CHECK (COMMON_PRODUCTMISCELL_COMPL IN (NULL, 0, 1, 2));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_BUDGCOMPL
  CHECK (COMMON_PRODUCTBUDGETP_COMPL IN (NULL, 0, 1, 2));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_EMBLCOMPL
  CHECK (COMMON_EMBLEMTEMPLATE_COMPL IN (NULL, 0, 1, 2));
ALTER TABLE I_CONTRACT
  ADD CONSTRAINT CHK_I_CONTRACT_WEARCOMPL
  CHECK (COMMON_WEARERFUNCTION_COMPL IN (NULL, 0, 1, 2));

prompt
prompt Creating table I_CONTRACTATTRIBUTE
prompt ==================================
prompt
create table I_CONTRACTATTRIBUTE
(
  CONTRACTCODE                  VARCHAR2(15) NOT NULL,
  ATTRIBUTEID                   NUMBER NOT NULL,
  COMPLIANCERULE                NUMBER DEFAULT 0
);
comment on column I_CONTRACTATTRIBUTE.CONTRACTCODE
  is 'Must exist in I_CONTRACTPRODUCT';
comment on column I_CONTRACTATTRIBUTE.ATTRIBUTEID
  is 'Must exist in CONTRACTATTRIBUTE';
comment on column I_CONTRACTATTRIBUTE.COMPLIANCERULE
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced';
alter table I_CONTRACTATTRIBUTE
  add constraint PK_I_CONTRACTATTRIBUTE primary key (CONTRACTCODE, ATTRIBUTEID);
alter table I_CONTRACTATTRIBUTE
  add constraint COMPLIANCERULE_VALID
  check (COMPLIANCERULE IN (0, 1, 2));
alter table I_CONTRACTATTRIBUTE
  add constraint I_CONTRATTR_ATTRIBUTE foreign key (ATTRIBUTEID)
  references CONTRACTATTRIBUTE (CONTRACTATTRIBUTE_ID);
create index INDX_I_CONTRACTATTRIB_ATTR on I_CONTRACTATTRIBUTE (ATTRIBUTEID);  

prompt
prompt Creating table I_CONTRACTUSERGROUP
prompt =========================
prompt
create table I_CONTRACTUSERGROUP
(
  CONTRACTCODE                VARCHAR2(15) NOT NULL,
  USERGROUPNAME               VARCHAR2(20) NOT NULL
);
comment on column I_CONTRACTUSERGROUP.CONTRACTCODE
  is 'Unique contract code';
comment on column I_CONTRACTUSERGROUP.USERGROUPNAME
  is 'Usergroup that exist in ABSSolute as a usergroup';
alter table I_CONTRACTUSERGROUP
  add constraint PK_I_CONTRACTUSERGROUP primary key (CONTRACTCODE,USERGROUPNAME);
alter table I_CONTRACTUSERGROUP
  add constraint FK_I_CONTRACTUSERGROUP_CONTRACTCODE foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE) on delete cascade;
alter table I_CONTRACTUSERGROUP
  add constraint FK_I_CONTRACTUSERGROUP_USERGROUP foreign key (USERGROUPNAME)
  references USERGROUP (GROUPNAME);
alter table I_CONTRACTUSERGROUP
  add constraint CHK_CONTRACTUSERGROUP_CC
  check (TRIM(UPPER(CONTRACTCODE))= CONTRACTCODE);
alter table I_CONTRACTUSERGROUP
  add constraint CHK_CONTRACTUSERGROUP_USRGRP
  check (TRIM(UPPER(USERGROUPNAME))= USERGROUPNAME);
create index XIF1I_CONTRACTUSERGROUP on I_CONTRACTUSERGROUP (USERGROUPNAME);  
create index XIF2I_CONTRACTUSERGROUP on I_CONTRACTUSERGROUP (CONTRACTCODE);  

prompt
prompt Creating table I_CONTRACTCOMPONENT
prompt ==================================
prompt
create table I_CONTRACTCOMPONENT
(
  CONTRACTCODE                  VARCHAR2(15) NOT NULL,
  ALLOWAUTOMATICSALES           VARCHAR2(1),
  DEPOSITSTOCKALLOWED           VARCHAR2(1),
  CHARGEREPAIRS                 NUMBER,
  CHARGEREPAIRCOG               NUMBER,
  VARIABLESERVICES              NUMBER,
  CHARGERESIDUALVALUE           VARCHAR2(1),
  CHARGEWASHFIRSTISSUE          VARCHAR2(1),
  CHARGELOSSCHARGE              VARCHAR2(1),
  ALLOWCHARGERETURNRENT         NUMBER,
  RETURNRENTWEEKS               NUMBER,
  ALLOWCHARGEMINRENT            NUMBER,
  MINRENTWEEKS                  NUMBER,
  CHARGESERVICECOSTS            VARCHAR2(1),
  DAYSSPECIALGRADE              NUMBER,
  FIRSTDAYSGRADE_CODE           VARCHAR2(1),
  FIRSTISSUEGRADE_CODE          VARCHAR2(1),
  QUALITYGRADE_CODE             VARCHAR2(1),
  GARMENTRENTSPECIFICATION      NUMBER,
  CHARGEPREPCHARGE              VARCHAR2(1) DEFAULT 'N',
  INVOICEFREQUENCY              NUMBER,
  MINIMUMINVOICEAMOUNT          NUMBER DEFAULT 0,
  SENDSTATEMENT                 NUMBER DEFAULT 3,
  STATEMENTFREQUENCY            NUMBER,
  ATTACHINVOICECOPIES           VARCHAR2(1) DEFAULT 'N',
  STATEMENTPERCUSTOMER          VARCHAR2(1) DEFAULT 'N',  
  SENDSTATEMENTBYEMAIL          VARCHAR2(1),
  SENDSTATEMENTBYFAX            VARCHAR2(1),
  SPLITINVOICESPERACTIVITY      VARCHAR2(1),
  CHARGELOSSFORPOOLITEMS        NUMBER,
  CHARGELOSSFORUNIQUEPOOLDAYS   NUMBER,
  PAYMENTTERMCODE               VARCHAR2(6),
  FINANCECHARGEDAYS             NUMBER DEFAULT 0,
  PUTFINANCECHARGEON            NUMBER DEFAULT 1,
  CUSTOMERRELATED               NUMBER,
  RELATEDCUSTOMERNUMBER         NUMBER,
  POREQUIRED                    NUMBER,
  SOILCOUNT                     VARCHAR2(1),
  INTERNETORDERING              VARCHAR2(1),
  CUSTOMGARMENTCHARGE           VARCHAR2(1),
  MATERIALMAINTENANCEPERCENTAGE NUMBER,
  GARMENTSETUP                  VARCHAR2(1),
  GARMENTMAINTENANCE            VARCHAR2(1),
  GARMENTLOSS                   VARCHAR2(1),
  GARMENTREPAIR                 VARCHAR2(1),
  USEPRODSIZESURCHARGEPRICING   VARCHAR2(1),
  MERCHANDISEBUYOUTCHARGE       VARCHAR2(1),
  MBYOPPERCENTAGE               NUMBER,
  AUTOSOILPERCENTAGE            NUMBER DEFAULT 0 NOT NULL,
  GARMENTLOSSPERCENTAGE         NUMBER DEFAULT 100 NOT NULL,
  GARMENTEMBLEM                 VARCHAR2(1),
  SPECIALSIZECHARGE             VARCHAR2(1) DEFAULT 'N' NOT NULL,
  INVOICEBILLING_TYPE           NUMBER(1),
  INVOICEBILLING_STARTDATE      DATE,
  INVOICEBILLING_ENDDATE        DATE,
  INVOICEBILLING_DESCRIPTION    VARCHAR2(300),
  CHARGEEXCHANGECHARGE          VARCHAR2(1),
  NONGARMENTCHARGERESIDUALVALUE VARCHAR2(1),
  NONGARMENTCHARGELOSSCHARGE    VARCHAR2(1),
  RAATEMPLATEHEADER             VARCHAR2(10)
);
comment on column I_CONTRACTCOMPONENT.CHARGEREPAIRS
  is '0 = No Repair allowed and No charge repair 
1 = Repair allowed and No charge repair 
2 = Repair allowed and Charge repair';
comment on column I_CONTRACTCOMPONENT.CHARGEREPAIRCOG
  is '0 = No Repair allowed and No charge repair 
1 = Repair allowed and No charge repair 
2 = Repair allowed and Charge repair';
comment on column I_CONTRACTCOMPONENT.VARIABLESERVICES
  is '0 = No Repair allowed and No charge repair 
1 = Repair allowed and No charge repair 
2 = Repair allowed and Charge repair';
comment on column I_CONTRACTCOMPONENT.ALLOWCHARGERETURNRENT
  is 'Flag that indicates whether return rent should be charged for this customer. Possible values: 0 = Do not charge return rent 1 = Do charge return rent';
comment on column I_CONTRACTCOMPONENT.RETURNRENTWEEKS
  is '0 - 999. This attributes indicates the number of weeks that still rent may be charged after the item has been taken out of circulation.';
comment on column I_CONTRACTCOMPONENT.ALLOWCHARGEMINRENT
  is 'Flag that indicates whether min rent should be charged for this customer. 
Possible values: 0 = Do not charge return rent 1 = Do charge return rent';
comment on column I_CONTRACTCOMPONENT.MINRENTWEEKS
  is '0 - 999. This attribute indicates the minimum number of weeks that rent will be charged for this customer. 
When an item has been taken out of circulation prior to reaching this number of weeks then still rent will be charged (as compensation) during this period.';
comment on column I_CONTRACTCOMPONENT.DAYSSPECIALGRADE
  is '0 - 999';
comment on column I_CONTRACTCOMPONENT.GARMENTRENTSPECIFICATION
  is '0 = Not applicable 1 = Products per Wearer
2 = Products per Wearer Condensed
3 = Wearer totals only
4 = Quantities per Product
5 = Number of men per total price
6 = Wearer function
7 = Wearer Function Fixed Total Price';
comment on column I_CONTRACTCOMPONENT.SENDSTATEMENT
  is '1 = Always, with frequency
2 = Only if invoices are Past Due
3 = Never';
comment on column I_CONTRACTCOMPONENT.CHARGELOSSFORPOOLITEMS
  is '0 = Not applicable / do not charge loss for pool
1 = Charge loss for pool items';
comment on column I_CONTRACTCOMPONENT.CHARGELOSSFORUNIQUEPOOLDAYS
  is '1 - 999';
comment on column I_CONTRACTCOMPONENT.PUTFINANCECHARGEON
  is '1 = Invoice 2 = Statement';
comment on column I_CONTRACTCOMPONENT.CUSTOMERRELATED
  is 'Possible values: 0=Not applicable
1=Related to this customer
2=Related to bill to customer (only valid when bill to customer <> customer)
3=Related to master account (only valid if customer is connected to master account)
4=Related to common customer (only valid if customer is connected to common customer)
5=Related to other customer (only valid if customer is connected to other customer)';
comment on column I_CONTRACTCOMPONENT.RELATEDCUSTOMERNUMBER
  is 'Only filled when CustomerRelated > 1.';
comment on column I_CONTRACTCOMPONENT.POREQUIRED is '0 = PO is not required 1 = PO is required';
comment on column I_CONTRACTCOMPONENT.AUTOSOILPERCENTAGE is 'Used as a default for ContractProduct and also compliancy for customers';
comment on column I_CONTRACTCOMPONENT.SPECIALSIZECHARGE is 'Only used for module SPECIALSIZECHARGE';
comment on column I_CONTRACTCOMPONENT.INVOICEBILLING_TYPE is '1 = Invoice
2 = Statement';
comment on column I_CONTRACTCOMPONENT.CHARGEEXCHANGECHARGE
  is 'Only used for module GARMENTEXCHANGECHARGE';
comment on column I_CONTRACTCOMPONENT.NONGARMENTCHARGERESIDUALVALUE is 'Charge residual value yes or no (for non-garments)';
comment on column I_CONTRACTCOMPONENT.NONGARMENTCHARGELOSSCHARGE is 'Charge loss charges yes or no (for non-garments))';
comment on column I_CONTRACTCOMPONENT.SENDSTATEMENTBYFAX is 'Obsolete column, not used anymore';
alter table I_CONTRACTCOMPONENT
  add constraint PK_I_CONTRACTCOMPONENT primary key (CONTRACTCODE);
alter table I_CONTRACTCOMPONENT
  add constraint FK_I_CONTRACTCOMPONENT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE) on delete cascade;
alter table I_CONTRACTCOMPONENT
  add constraint FK_I_CONTRACTCOMP_RELCUST foreign key (RELATEDCUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCOMP_STATEMENTFREQ foreign key (STATEMENTFREQUENCY)
  references INVOICEFREQUENCY (INVOICEFREQUENCY_ID) on delete cascade;
alter table I_CONTRACTCOMPONENT
  add constraint I_CONTRACTCOMP_INVFREQ foreign key (INVOICEFREQUENCY)
  references INVOICEFREQUENCY (INVOICEFREQUENCY_ID) on delete cascade;
alter table I_CONTRACTCOMPONENT
  add constraint ALLOWCHARGEMINRENT_VALID2_2
  check (ALLOWCHARGEMINRENT IN (0, 1));
alter table I_CONTRACTCOMPONENT
  add constraint ALLOWCHARGERETURNRENT_VALID2_2
  check (ALLOWCHARGERETURNRENT IN (0, 1));
alter table I_CONTRACTCOMPONENT
  add constraint CHARGEREPAIRS_VALID2_1
  check (CHARGEREPAIRS BETWEEN 0 AND 2);
alter table I_CONTRACTCOMPONENT
  add constraint DAYSSPECIALGRADE_VALID2_1
  check (DAYSSPECIALGRADE BETWEEN 0 AND 999);
alter table I_CONTRACTCOMPONENT
  add constraint GARMENTRENTSPECIFIC_VALID2_1
  check (GARMENTRENTSPECIFICATION BETWEEN 0 AND 7);
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_CHRLOSSFORPOOLITEMS_VALID
  check (CHARGELOSSFORPOOLITEMS IN (0, 1));
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_CHRLOSSFORUNIQPOOL_VALID
  check (CHARGELOSSFORUNIQUEPOOLDAYS BETWEEN 1 AND 999);
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_CUSTOMERRELATED_VALID1_1
  check (CUSTOMERRELATED BETWEEN 0 AND 5);
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_FINANCECHARGEDAYS_VALID
  check (FINANCECHARGEDAYS BETWEEN 0 AND 999);
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_MINRENTWEEKS_VALID
  check (MINRENTWEEKS BETWEEN 0 AND 999);
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_POREQUIRED_VALID1_1
  check (POREQUIRED IN (0, 1));
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_PUTFINANCECHARGEON_VALID
  check (PUTFINANCECHARGEON IN (1, 2));
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_RETURNRENTWEEKS_VALID
  check (RETURNRENTWEEKS BETWEEN 0 AND 999);
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_SENDSTATEMENT_VALID
  check (SENDSTATEMENT IN (1, 2, 3));
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_YN_VALIDATIONFIELD349
  check (SOILCOUNT IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CC_YN_VALIDATIONFIELD350
  check (INTERNETORDERING IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENT296
  check (ATTACHINVOICECOPIES IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENT297
  check (STATEMENTPERCUSTOMER IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENT304
  check (SENDSTATEMENTBYEMAIL IN ('Y', 'N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENT348
  check (SPLITINVOICESPERACTIVITY IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN295
  check (CHARGEPREPCHARGE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN342
  check (ALLOWAUTOMATICSALES IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN343
  check (DEPOSITSTOCKALLOWED IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN344
  check (CHARGERESIDUALVALUE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN345
  check (CHARGEWASHFIRSTISSUE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN346
  check (CHARGELOSSCHARGE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN347
  check (CHARGESERVICECOSTS IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN391
  check (CUSTOMGARMENTCHARGE IN ('Y','N'));  
alter table I_CONTRACTCOMPONENT
  add constraint I_CONTRCOMPBGPROTECT_CHECK1
  check ((MATERIALMAINTENANCEPERCENTAGE IS NULL) OR (MATERIALMAINTENANCEPERCENTAGE IS NOT NULL AND MATERIALMAINTENANCEPERCENTAGE BETWEEN 0 AND 100));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN392
  check (GARMENTSETUP IN ('Y', 'N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN393
  check (GARMENTMAINTENANCE IN ('Y', 'N'));
alter table I_CONTRACTCOMPONENT
  add constraint YI_CNTRCTCMPONENTYN394
  check (GARMENTLOSS IN ('Y', 'N'));
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN395
  check (GARMENTREPAIR IN ('Y', 'N'));  
alter table I_CONTRACTCOMPONENT
  add constraint I_CNTRCTCMPONENTYN396
  check (USEPRODSIZESURCHARGEPRICING IN ('Y', 'N'));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_MERBUYOUTCHARGE
  check (MERCHANDISEBUYOUTCHARGE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC__MBYOPPERCENTAGE
  check (MBYOPPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_AUTOSOILPERC
  check (AUTOSOILPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_GRMLOSSPERC
  check (GARMENTLOSSPERCENTAGE BETWEEN 0 AND 100);
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_GARMEMB
  check (GARMENTEMBLEM IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_SPECSIZECHRG
  check (SPECIALSIZECHARGE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_INVOICEBILING_TYPE
  check (INVOICEBILLING_TYPE IN (1, 2));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_INVBILL_DATECHECK
  check (INVOICEBILLING_ENDDATE >= INVOICEBILLING_STARTDATE);
alter table I_CONTRACTCOMPONENT
  add constraint CHK_I_CONC_CHREXCHANCHR
  check (CHARGEEXCHANGECHARGE IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_ICONTRCOMP_CHRES CHECK (NONGARMENTCHARGERESIDUALVALUE  IN ('Y','N'));
alter table I_CONTRACTCOMPONENT
  add constraint CHK_ICONTRCOMP_CHLOSS CHECK (NONGARMENTCHARGELOSSCHARGE IN ('Y','N'));

prompt
prompt Creating table I_CONTRACTCUSTOMER
prompt =================================
prompt
create table I_CONTRACTCUSTOMER
(
  CONTRACTCODE   VARCHAR2(15) NOT NULL,
  CUSTOMERNUMBER NUMBER NOT NULL,
  STARTDATE      DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  ENDDATE        DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  CONTRACTUSAGE  NUMBER DEFAULT 1 NOT NULL,
  EXPIRATIONDATE DATE,
  POSTARTDATE    DATE,
  INSTALLDATE    DATE
);
comment on column I_CONTRACTCUSTOMER.contractcode
  is 'Unique contract code';
comment on column I_CONTRACTCUSTOMER.contractusage
  is 'Must be between 0-1';
alter table I_CONTRACTCUSTOMER
  add constraint PK_I_CONTRACTCUSTOMER primary key (CONTRACTCODE, CUSTOMERNUMBER);
alter table I_CONTRACTCUSTOMER
  add constraint FK_I_CONTRACTCUST_CONTRACT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE) on delete cascade;
alter table I_CONTRACTCUSTOMER
  add constraint FK_I_CONTRACTCUST_CUSTOMER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_CONTRACTCUSTOMER
  add constraint I_CONTRACTCUSTOMER_CNTRUSAGE
  check (CONTRACTUSAGE BETWEEN 0 AND 1);
alter table I_CONTRACTCUSTOMER
  add constraint I_CONTRACTCUSTOMER_DATECHECK
  check (ENDDATE >= STARTDATE);

prompt
prompt Creating table I_CONTRACTPRICELIST
prompt ==================================
prompt
create table I_CONTRACTPRICELIST
(
  CONTRACTCODE                  VARCHAR2(15) NOT NULL,
  GENERALPRICELISTCODE          VARCHAR2(15) NOT NULL,
  GENERALPRICETYPE              NUMBER NOT NULL,
  GENERALPRICECURRENCY          VARCHAR2(3) NOT NULL,
  GENERALPRICEINDEXCODE         VARCHAR2(6),
  GENERALPRICEAUTOPRICEUPDATEYN VARCHAR2(1) DEFAULT 'N' NOT NULL,
  STARTDATE                     DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  ENDDATE                       DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  AGREED                        VARCHAR2(1) DEFAULT 'N' NOT NULL,
  USAGE                         NUMBER DEFAULT 0 NOT NULL,
  PRIORITY                      NUMBER DEFAULT 1 NOT NULL,
  PRICETYPE                     NUMBER DEFAULT 0 NOT NULL,
  PRICELISTDESCRIPTION          VARCHAR2(50) NULL
);
comment on column I_CONTRACTPRICELIST.CONTRACTCODE
  is 'Link to I_CONTRACT';
comment on column I_CONTRACTPRICELIST.GENERALPRICELISTCODE
  is 'Generalpricelist code';
comment on column I_CONTRACTPRICELIST.GENERALPRICETYPE
  is '1 = Wash 
2 = Rent 
3 = Replacement 
4 = Sales 
5 = Weight 
6 = Repair 
7 = Emblem 
8 = Emblem Template 
9 = Garment Insurance 
10 = Special Charge 
11 = Wearer Function Special Type 
12 = Special Size Charge';
comment on column I_CONTRACTPRICELIST.GENERALPRICECURRENCY
  is 'Generalpricelist currency';
comment on column I_CONTRACTPRICELIST.GENERALPRICEINDEXCODE
  is 'Optional Generalpricelist priceindexcode';
comment on column I_CONTRACTPRICELIST.GENERALPRICEAUTOPRICEUPDATEYN
  is 'Y,N Default N';
comment on column I_CONTRACTPRICELIST.STARTDATE
  is 'contractprice list start date';
comment on column I_CONTRACTPRICELIST.ENDDATE
  is 'contractprice list end date';
comment on column I_CONTRACTPRICELIST.AGREED
  is 'Y,N Default N';
comment on column I_CONTRACTPRICELIST.USAGE
  is '0,1 Default 0, 1 is contract only generalpricelist';
comment on column I_CONTRACTPRICELIST.PRICETYPE
  is '0 = Undefined / inherited
1 = Wash
2 = Rent
3 = Replacement
4 = Sales
5 = Weight
6 = Repair
7 = Emblem
8 = Emblem Template
9 = Garment Insurance
10 = Special Charge
11 = Wearer Function Special Type 
12 = Special Size Charge';
comment on column I_CONTRACTPRICELIST.PRIORITY
  is 'Must be between 1 and 9999';
comment on column I_CONTRACTPRICELIST.PRICELISTDESCRIPTION
  is 'Contract (General price) list description'; 
alter table I_CONTRACTPRICELIST
  add constraint PK_I_CONTRACTPRICELIST primary key (CONTRACTCODE, GENERALPRICELISTCODE, GENERALPRICETYPE);
alter table I_CONTRACTPRICELIST
  add constraint FK_I_CONTRACTPRCLST_CURRENCY foreign key (GENERALPRICECURRENCY)
  references CURRENCY (CODE);
alter table I_CONTRACTPRICELIST
  add constraint FK_I_CONTRACTPRCLST_I_CONTRACT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE) on delete cascade;
alter table I_CONTRACTPRICELIST
  add constraint I_CNTRPRCLST_AGREED
  check (AGREED in ('Y','N'));
alter table I_CONTRACTPRICELIST
  add constraint I_CNTRPRCLST_DATECHECK
  check (ENDDATE >= STARTDATE);
alter table I_CONTRACTPRICELIST
  add constraint I_CNTRPRCLST_GENERALPRICETYPE
  check (GENERALPRICETYPE IN (0,1,2,3,4,5,6,7,8,9,10,11,12));
alter table I_CONTRACTPRICELIST
  add constraint I_CNTRPRCLST_GNRLPRCAUTOPRCUPD
  check (GENERALPRICEAUTOPRICEUPDATEYN in ('Y','N'));
alter table I_CONTRACTPRICELIST
  add constraint I_CNTRPRCLST_PRICETYPE
  check (PRICETYPE IN (0,1,2,3,4,5,6,7,8,9,10,11,12));
alter table I_CONTRACTPRICELIST
  add constraint I_CNTRPRCLST_PRIORITY
  check (PRIORITY BETWEEN 1 AND 9999);

prompt
prompt Creating table I_CONTRACTPRICE
prompt ==================================
prompt
create table I_CONTRACTPRICE
(
  CONTRACTCODE VARCHAR2(15) NOT NULL,
  CATEGORY     NUMBER DEFAULT 0 NOT NULL,
  PRICETYPE    NUMBER DEFAULT 0 NOT NULL,
  REASONCODE   VARCHAR2(6),
  STARTDATE    DATE NOT NULL,
  PRICE        NUMBER(15,6) NOT NULL
);
comment on column I_CONTRACTPRICE.CONTRACTCODE
  is 'Link to I_CONTRACT';
comment on column I_CONTRACTPRICE.CATEGORY
  is '0 = Not applicable
1 = Service Costs LOG
2 = Insurance - Weekly fee per piece
3 = Restocking Fee
4 = Stock Charge
5 = Locker
6 = General Prep Charge
7 = Surcharge Price
8 = Label Price
9 = Cash DelayCharge 
10 = Exchange Charge';
comment on column I_CONTRACTPRICE.PRICETYPE
  is '0 = Not applicable
For Category = 1 (Service Costs)
1 = Service Costs LOG
2 = Service Costs COG
For Category = 5 (Locker)
1 = Rent price per week
2 = Service Price
For Category = 7 (Surcharge price)
1 = Non Standard Size Surcharge
2 = Special Cut Surcharge
For Category = 8 (Label Price)
1 = Code Label Price
2 = Name Label Price
3 = Residential Label
5 = Patch Price
Note : option 4 is not used to keep the numbering the same as in CustomerLabelLayoutPrice table.';
comment on column I_CONTRACTPRICE.REASONCODE
  is 'link to Reasoncode';
ALTER TABLE I_CONTRACTPRICE
  ADD CONSTRAINT XPKICONTRACTPRICE PRIMARY KEY (CONTRACTCODE, CATEGORY, STARTDATE);  
alter table I_CONTRACTPRICE
  add constraint FK_CONTRACTPRICE_CONTRACT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE);  
ALTER TABLE I_CONTRACTPRICE
  ADD CONSTRAINT CONTRPR_CAT_VALID
  CHECK (CATEGORY IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
ALTER TABLE I_CONTRACTPRICE
  ADD CONSTRAINT CONTRPR_PRTYPE_VALID
  CHECK (PRICETYPE IN (0,1,2,3,4,5));  
alter table I_CONTRACTPRICE
  add constraint CONTRPR_CATTYPE_VALID
  check (PRICETYPE = 0 or
(CATEGORY in (1,5,7) and PRICETYPE IN (1,2)) or
(CATEGORY = 8 and PRICETYPE IN (1,2,3,5)));  

prompt
prompt Creating table I_CONTRACTPRODUCT
prompt ===========================
prompt
create table I_CONTRACTPRODUCT
(
  CONTRACTCODE                   VARCHAR2(15) NOT NULL,
  PRODUCTCODE                    VARCHAR2(12) NOT NULL,
  SIZECODE                       VARCHAR2(12) DEFAULT '-' NOT NULL,
  FINISHINGMETHOD                VARCHAR2(12) DEFAULT '-' NOT NULL,
  STARTDATE                      DATE DEFAULT TRUNC(SYSDATE),
  ENDDATE                        DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY'),
  BILLINGMETHOD                  NUMBER,
  CHANGESPERWEEK                 VARCHAR2(1),
  CHARGEOVERUSE                  VARCHAR2(1),
  RENTPRICEPERFREQUENCY          VARCHAR2(1),
  CHARGEWASHESONLYFORCOG         NUMBER(1),
  INVENTORYBILLINGTYPE           NUMBER(1),
  MINIMUMTURNAROUND              NUMBER,
  MINIMUMQUANTITY                NUMBER,
  MINIMUMFREQUENCY               NUMBER(1),
  CHARGELOSSFORPOOL_YN           VARCHAR2(1),
  CHARGELOSSUNIQUEPOOLDAYS       NUMBER(3),
  PRICEUSAGE                     NUMBER(1),
  CHARGERENTNORETURNPOOLAFTERWKS NUMBER,
  CHARGERENTNOTRETURNED          NUMBER(1),
  PERCENTAGEAFTERDEPRECIATION    NUMBER,
  INVOICEFREQRELATEDRENTPRICE    VARCHAR2(1),
  INVWASHBASEDONSOILCOUNT        VARCHAR2(1),
  CHARGEWASHESPACK               NUMBER(1),
  RETURNSTOCKALLOWED             VARCHAR2(1),
  SEASONTYPECODE                 VARCHAR2(6),
  SEASONALRENT                   NUMBER(1),
  CHARGEWASHINACTIVESEASON       VARCHAR2(1),
  RESIDUALVALUESCHEMECODE        VARCHAR2(6),
  SRCMETHOD                      NUMBER(1),
  SRCPERCENTAGESOILCOUNT         NUMBER(15,2),
  SRCPERCENTAGEINVENTORY         NUMBER(15,2),
  SRCPERCENTAGEBILLEDQTY         NUMBER(15,2),
  DELIVERREPLACEMENTQTY          VARCHAR2(1),
  SRCFREQUENCY                   NUMBER(1),
  SRCCHARGERENT                  NUMBER(1),
  SHOWFOCRENTONINVOICE           VARCHAR2(1),
  RESETRVUPONREISSUE             NUMBER(1),
  DELAYEDEVENEXCHANGE            NUMBER(1),
  DEEDELIVERYSCHEME              NUMBER(1),
  STRAIGHTEVENEXCHANGE           VARCHAR2(1),
  ORDERVIAWEB                    NUMBER(1),
  SOILCOUNTMETHOD                NUMBER(1),
  CLEANCOUNT                     VARCHAR2(1),
  CODEUNIQUELY                   VARCHAR2(1),
  ONSITEINVENTORYCOUNT           VARCHAR2(1),
  AUTOMATICSALES                 VARCHAR2(1),
  CUSTOMERRELATED                VARCHAR2(1),
  AUTOREPLAFTERLIFETIME          VARCHAR2(1),
  ALLOWRETURNTOSTOCK             NUMBER(1),
  RAGGEDITEMACTION               NUMBER(1),
  CUSTOMCODE                     VARCHAR2(16),
  CUSTOMDESCRIPTION              VARCHAR2(30),
  EANNUMBER                      NUMBER,
  NANNUMBER                      NUMBER,
  SALESEMPLOYEENUMBER            NUMBER,
  SALESEMPLOYEENAME              VARCHAR2(40),
  SALESEMPLOYEEPLANTCODE         VARCHAR2(6),
  SALESEMPLOYEE2NUMBER           NUMBER,
  SALESEMPLOYEE2NAME             VARCHAR2(40),
  SALESEMPLOYEE2PLANTCODE        VARCHAR2(6),
  COMMISSIONPAYABLE              VARCHAR2(1),
  GAINREASONCODE                 VARCHAR2(6),
  GAINREASONDESCRIPTION          VARCHAR2(30),
  GAINCOMPETITORCODE             VARCHAR2(6),
  GAINCOMPETITORNAME             VARCHAR2(30),
  LOSTREASONCODE                 VARCHAR2(6),
  LOSTREASONDESCRIPTION          VARCHAR2(30),
  LOSTCOMPETITORCODE             VARCHAR2(6),
  LOSTCOMPETITORNAME             VARCHAR2(30),
  COMPLIANCYRULEMISC             NUMBER,
  REMARK                         VARCHAR2(80),
  COMPLIANCYRULEPRICING          NUMBER,
  GARMENTSETUP                   VARCHAR2(1), --CONTRACTPRODUCTBGPROTECTION
  GARMENTMAINTENANCE             VARCHAR2(1), --CONTRACTPRODUCTBGPROTECTION
  GARMENTLOSS                    VARCHAR2(1), --CONTRACTPRODUCTBGPROTECTION
  GARMENTREPAIR                  VARCHAR2(1), --CONTRACTPRODUCTBGPROTECTION
  MMPSPECIFICPERCENTAGE          NUMBER,      --CONTRACTPRODUCTBGPROTECTION
  TYPEOFMERCHANDISE              NUMBER DEFAULT 2 NOT NULL,
  MBYOPPERCENTAGE                NUMBER,
  RELEASED                       VARCHAR2(1) DEFAULT 'N' NOT NULL,
  AUTOSOILPERCENTAGE             NUMBER DEFAULT 0 NOT NULL,
  IMAGECARE                      NUMBER,
  LOSSCHARGEPERCENTAGE           NUMBER(5,2),
  SRCHARGEPERCENTAGE             NUMBER(5,2),
  COMPLIANCYRULEORDERDELIVERY    NUMBER,
  COMPLIANCYRULEIMAGECARE        NUMBER,
  COMPLIANCYRULEBILLING          NUMBER,
  COMPLIANCYRULEBGPROTECTION     NUMBER,
  GARMENTLOSSPERCENTAGE          NUMBER DEFAULT 100 NOT NULL,
  GARMENTEMBLEM                  VARCHAR2(1)
);
alter table I_CONTRACTPRODUCT
  add constraint PK_CONTRACTPRODUCT primary key (CONTRACTCODE, PRODUCTCODE, SIZECODE, FINISHINGMETHOD);
create index XIF1I_CONTRACTPRODUCT on I_CONTRACTPRODUCT (PRODUCTCODE);
create index XIF2I_CONTRACTPRODUCT on I_CONTRACTPRODUCT (CONTRACTCODE);
create index XIF3I_CONTRACTPRODUCT on I_CONTRACTPRODUCT (SALESEMPLOYEEPLANTCODE);
create index XIF4I_CONTRACTPRODUCT on I_CONTRACTPRODUCT (SALESEMPLOYEE2PLANTCODE);
alter table I_CONTRACTPRODUCT
  add constraint FK_CONTRACTPRODUCT_PRODUCT foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_CONTRACTPRODUCT
  add constraint FK_CONTRACTPRODUCT_CONTRACT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE);
alter table I_CONTRACTPRODUCT
  add constraint FK_CONTRACTPRODUCT_PLANTCODE1 foreign key (SALESEMPLOYEEPLANTCODE)
  references PLANT (CODE) on delete cascade;
alter table I_CONTRACTPRODUCT
  add constraint FK_CONTRACTPRODUCT_PLANTCODE2 foreign key (SALESEMPLOYEE2PLANTCODE)
  references PLANT (CODE) on delete cascade;
-- Create/Recreate check constraints 
alter table I_CONTRACTPRODUCT
  add constraint I_BILLINGMETHOD_VALID
  check (BILLINGMETHOD BETWEEN 1 AND 5);
alter table I_CONTRACTPRODUCT
  add constraint I_CHARGERENTNOTRETURNED_VALID
  check (CHARGERENTNOTRETURNED BETWEEN 0 AND 2);
alter table I_CONTRACTPRODUCT
  add constraint I_CHARGEWASHESPACK_VALID
  check (CHARGEWASHESPACK BETWEEN 1 AND 3);
alter table I_CONTRACTPRODUCT
  add constraint I_CHARGEWASHSONLYFORCOG_VALID
  check (CHARGEWASHESONLYFORCOG BETWEEN 0 AND 4);
alter table I_CONTRACTPRODUCT
  add constraint I_CHRLOSSUNIQUEPOOLDAYS_VALID
  check (CHARGELOSSUNIQUEPOOLDAYS BETWEEN 0 AND 999);
alter table I_CONTRACTPRODUCT
  add constraint I_INVENTORYBILLINGTYPE_VALID
  check (INVENTORYBILLINGTYPE BETWEEN 0 AND 4);
alter table I_CONTRACTPRODUCT
  add constraint I_MINIMUMFREQUENCY_VALID
  check (MINIMUMFREQUENCY BETWEEN 1 AND 5);
alter table I_CONTRACTPRODUCT
  add constraint I_PRICEUSAGE_VALID
  check (PRICEUSAGE BETWEEN 0 AND 3);
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD324
  check (CHANGESPERWEEK IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD325
  check (CHARGEOVERUSE IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD326
  check (RENTPRICEPERFREQUENCY IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD327
  check (CHARGELOSSFORPOOL_YN IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD328
  check (INVOICEFREQRELATEDRENTPRICE IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD329
  check (INVWASHBASEDONSOILCOUNT IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD330
  check (RETURNSTOCKALLOWED IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD341
  check (COMMISSIONPAYABLE IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_ALLOWRETURNTOSTOCK_VALID
  check (ALLOWRETURNTOSTOCK in (0,1,2,3,4));
alter table I_CONTRACTPRODUCT
  add constraint I_DEEDDELIVERYSCHEME_VALID
  check (DEEDELIVERYSCHEME IN (0, 1));
alter table I_CONTRACTPRODUCT
  add constraint I_DELAYEDEVENEXCHANGE_VALID
  check (DELAYEDEVENEXCHANGE BETWEEN 0 AND 8);
alter table I_CONTRACTPRODUCT
  add constraint I_ORDERVIAWEB_VALID
  check (ORDERVIAWEB IN (0, 1));
alter table I_CONTRACTPRODUCT
  add constraint I_RAGGEDITEMACTION_VALID
  check (RAGGEDITEMACTION BETWEEN 0 AND 6);
alter table I_CONTRACTPRODUCT
  add constraint I_SOILCOUNTMETHOD_VALID
  check (SOILCOUNTMETHOD BETWEEN 0 AND 3);
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD334
  check (STRAIGHTEVENEXCHANGE IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD335
  check (CLEANCOUNT IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD336
  check (CODEUNIQUELY IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD337
  check (ONSITEINVENTORYCOUNT IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD338
  check (AUTOMATICSALES IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD339
  check (CUSTOMERRELATED IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_YN_VALIDATIONFIELD340
  check (AUTOREPLAFTERLIFETIME IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTRACTPRODUCT_SIZESTAR_CHK
  check ((SIZECODE = '*' AND TYPEOFMERCHANDISE = 2) OR (SIZECODE <> '*'));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_SIZE_BILLINGCHECK
  check ((SIZECODE <> '*') or (SIZECODE='*' and BILLINGMETHOD IN (1,2,3,4,5)));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTRACTPRODUCT_TOM_CHK
  check (TYPEOFMERCHANDISE NOT IN (4));
alter table I_CONTRACTPRODUCT 
  add constraint CHK_I_CONTRACTPRODUCT_PROD 
  check (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_SIZECODE_CHK
  check (SIZECODE = UPPER(TRIM(SIZECODE)));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_FINISHINGMETHOD_CHK
  check (FINISHINGMETHOD = UPPER(TRIM(FINISHINGMETHOD)));  
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_CHSPWEEK_CHK
  check ((TYPEOFMERCHANDISE = 2 AND CHANGESPERWEEK = 'Y' AND BILLINGMETHOD IN (1,5)) OR CHANGESPERWEEK = 'N');
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_DEEDELSCHEME_CHK
  check ((DEEDELIVERYSCHEME is null) or (DEEDELIVERYSCHEME is not null and DELAYEDEVENEXCHANGE = 7));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_EXCHANGE_CHK
  check ((DELAYEDEVENEXCHANGE > 0 and STRAIGHTEVENEXCHANGE = 'N') or (DELAYEDEVENEXCHANGE = 0));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_DATES_CHK
  check (STARTDATE <= ENDDATE);
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_INVBILLING_CHK
  check ((INVENTORYBILLINGTYPE = 0 and BILLINGMETHOD <> 3) or (BILLINGMETHOD=3 and INVENTORYBILLINGTYPE IN (0, 1, 2, 3, 4)) or (BILLINGMETHOD=2 and INVENTORYBILLINGTYPE IN (0, 1, 2)));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_MINIMUMFREQ_CHECK
  check ((MINIMUMFREQUENCY <> 5) OR (MINIMUMFREQUENCY=5 AND DELAYEDEVENEXCHANGE = 7));
alter table I_CONTRACTPRODUCT
  add constraint I_PRODCONT_MINIMUM_CHECK
  check ((((MINIMUMQUANTITY = 0 AND MINIMUMTURNAROUND >= 0) OR
             (MINIMUMQUANTITY >= 0 AND MINIMUMTURNAROUND = 0)) AND BILLINGMETHOD = 2) OR
             BILLINGMETHOD <> 2);
alter table I_CONTRACTPRODUCT
  add constraint CHK_PRODCONT_COMPLIANCYRULE
  check (COMPLIANCYRULEMISC IN (NULL, 0, 1, 2));
alter table I_CONTRACTPRODUCT
  add constraint CHK_PRODCONT_COMPLIANCYPRICING
  check (COMPLIANCYRULEPRICING IN (NULL, 0, 1, 2));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTRACTPRODUCT_MMPS
  check ((MMPSPECIFICPERCENTAGE BETWEEN 0.0 AND 100.0) OR (MMPSPECIFICPERCENTAGE IS NULL));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_GARMENTSETUP
  check (GARMENTSETUP IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_GARMENTMAINTENANCE
  check (GARMENTMAINTENANCE IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_GARMENTLOSS
  check (GARMENTLOSS IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_GARMENTREPAIR
  check (GARMENTREPAIR IN ('Y','N'));
alter table I_CONTRACTPRODUCT
  add constraint CHK_CONTPROD_MBYOPPERCENTAGE
  check (MBYOPPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_CONTRACTPRODUCT
  add constraint CHK_CONTPROD_AUTOSOILPERC
  check (AUTOSOILPERCENTAGE BETWEEN 0.0 AND 100.0);
alter table I_CONTRACTPRODUCT
  add constraint I_CONTPROD_IMAGECARE_VALID
  check (IMAGECARE BETWEEN 0 AND 7);
alter table I_CONTRACTPRODUCT
  add constraint CHK_ICONPROD_LOSSCHARGEPERC
  check (LOSSCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99);
alter table I_CONTRACTPRODUCT
  add constraint CHK_ICONPROD_SRCHARGEPERC
  check (SRCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99);
alter table I_CONTRACTPRODUCT
  add constraint CHK_PRODCONT_COMPLCYRULEORDDEL
  check (COMPLIANCYRULEORDERDELIVERY IN (NULL, 0, 1, 2));
alter table I_CONTRACTPRODUCT
  add constraint CHK_PRODCONT_COMPLYRULEMAGCARE
  check (COMPLIANCYRULEIMAGECARE IN (NULL, 0, 1, 2));
alter table I_CONTRACTPRODUCT
  add constraint CHK_PRODCONT_COMPLIANCYRULEBIL
  check (COMPLIANCYRULEBILLING IN (NULL, 0, 1, 2));
alter table I_CONTRACTPRODUCT
  add constraint CHK_PRODCONT_COMPLIANCYBGPROT
  check (COMPLIANCYRULEBGPROTECTION IN (NULL, 0, 1, 2));
alter table I_CONTRACTPRODUCT
  add constraint CHK_I_CONTPROD_GRMLOSSPERC
  check (GARMENTLOSSPERCENTAGE BETWEEN 0 AND 100);
alter table I_CONTRACTPRODUCT
  add constraint CHK_I_CONTPROD_GARMEMB
  check (GARMENTEMBLEM IN ('Y','N'));
comment on column I_CONTRACTPRODUCT.CONTRACTCODE
  is 'Must exist in I_CONTRACT';
comment on column I_CONTRACTPRODUCT.PRODUCTCODE
  is 'Must exist in I_PRODUCT';
comment on column I_CONTRACTPRODUCT.BILLINGMETHOD
  is '1 = Flat rated rent 
2 = Rent based on minimum 
3 = Circulating Inventory 
4 = Piece rate only 
5 = Lease';
comment on column I_CONTRACTPRODUCT.CHANGESPERWEEK
  is 'BM1, BM5';
comment on column I_CONTRACTPRODUCT.CHARGEOVERUSE
  is 'BM1, BM3, BM5';
comment on column I_CONTRACTPRODUCT.RENTPRICEPERFREQUENCY
  is 'BM1';
comment on column I_CONTRACTPRODUCT.CHARGEWASHESONLYFORCOG
  is '0 = Both LOG and COG same wash price 
1 = Both LOG and COG distinct wash price 
2 = LOG only 
3 = COG only 
4 = Sales only (BM1, BM3, BM4, BM5)';
comment on column I_CONTRACTPRODUCT.inventorybillingtype
  is '0 - circulating inventory
1 - real quantity
2 - max inventory qty
3 - on-site inventory qty
4 - Rent for Non-returned items after n weeks (BM3, BM5)
(for BM2 only 0,1,2)';
comment on column I_CONTRACTPRODUCT.minimumturnaround
  is 'Percentage (BM2)';
comment on column I_CONTRACTPRODUCT.minimumquantity
  is 'The Quantity itself is not defined in the contract, this is only used as a flag to indicate whether the percentage (MinimumTurnAround) is used or a fixed quantity. (BM2)';
comment on column I_CONTRACTPRODUCT.minimumfrequency
  is '1 = Every week 
2 = Every delivery 
3 = Every month (BM2) 
4 = Every delivery Qty > 0 
5 = Delivery Scheme based';
comment on column I_CONTRACTPRODUCT.chargelossforpool_yn
  is 'BM2, BM3, BM4';
comment on column I_CONTRACTPRODUCT.chargelossuniquepooldays
  is '0 - 999 
(BM2, BM3, BM4)';
comment on column I_CONTRACTPRODUCT.priceusage
  is '0 = Not applicable 
1 = Split price 
2 = Rent price only 
3 = Wash price only (BM3)';
comment on column I_CONTRACTPRODUCT.chargerentnoreturnpoolafterwks
  is 'BM3';
comment on column I_CONTRACTPRODUCT.chargerentnotreturned
  is 'Used in combination with BM3 and InventoryBillingType = 4 
0 = Charge Rent for not returned Pool 
1 = Charge Rent for not returned Garments (non-pool) 
2 = Charge Rent for not returned Pool and Garments';
comment on column I_CONTRACTPRODUCT.percentageafterdepreciation
  is 'BM3';
comment on column I_CONTRACTPRODUCT.invoicefreqrelatedrentprice
  is 'BM3';
comment on column I_CONTRACTPRODUCT.invwashbasedonsoilcount
  is 'BM3';
comment on column I_CONTRACTPRODUCT.chargewashespack
  is '1 = Pack 
2 = Content 
3 = Both (BM4)';
comment on column I_CONTRACTPRODUCT.returnstockallowed
  is 'BM5';
comment on column I_CONTRACTPRODUCT.seasonalrent
  is '0 = Not applicable 
1 = Only charge rent during active season 
2 = Charge rent for both active and inactive season)';
comment on column I_CONTRACTPRODUCT.chargewashinactiveseason
  is 'Note: in PLPC this attribute is called ChargeRentInactiveSeason but used for charging wash) .';
comment on column I_CONTRACTPRODUCT.residualvalueschemecode
  is 'Best would be if it already exists in the database, we do not know how to set it up correctly if it does not exist it will be created and it will get the default values';
comment on column I_CONTRACTPRODUCT.srcmethod
  is '0 = No Systematic Replacement, 
1 = Percentage of Soil Count, 
2 = Percentage of Circulating Inventory, 
3 = Fixed Quantity 
4 = Percentage of Billed Quantity';
comment on column I_CONTRACTPRODUCT.srcpercentagesoilcount
  is 'Used for SRCMethod = 1';
comment on column I_CONTRACTPRODUCT.srcpercentageinventory
  is 'Used for SRCMethod = 2';
comment on column I_CONTRACTPRODUCT.srcpercentagebilledqty
  is 'Used for SRCMethod = 4';
comment on column I_CONTRACTPRODUCT.srcfrequency
  is '1 = Every Delivery, 
2 = Every Week First Delivery, 
3 = Every Week Last Delivery. Only applicable if SRCMethod = 2 or 3';
comment on column I_CONTRACTPRODUCT.srcchargerent
  is '0 = No Rent is charged for Replacements 
1 = Additional Rent is charged for Replacements in addition to SRC. Additional Rent is charged only once.';
comment on column I_CONTRACTPRODUCT.showfocrentoninvoice
  is 'Y / N (FOC = Free Of Charge)';
comment on column I_CONTRACTPRODUCT.resetrvuponreissue
  is 'Indicates whether commercial Residual Value should be reset upon Reissue of a garment Possible values: 
0 = No 
1 = Yes';
comment on column I_CONTRACTPRODUCT.delayedevenexchange
  is '0 = No delay
1 = Next visit
2 = Next week same day
3 = 10 day delay
4 = Return route in route schedule
5 = 14 delay basis
6 = 28 delay basis
7 = According to delivery scheme
8 = Next visit including same day';
comment on column I_CONTRACTPRODUCT.deedeliveryscheme
  is '0 = Delivery frequency is not considered in calculation for next delivery date (unchecked, default)
1 = Delivery Frequency is used in calculation for next delivery date (checked)';
comment on column I_CONTRACTPRODUCT.orderviaweb
  is '0 = No
1 = Yes';
comment on column I_CONTRACTPRODUCT.soilcountmethod
  is '0 = no soil count
1 = manual
2 = auto return assumed
3 = weight based';
comment on column I_CONTRACTPRODUCT.allowreturntostock
  is '0 = Yes (default)
1 = Yes, excluding special sizes
2 = No';
comment on column I_CONTRACTPRODUCT.raggeditemaction
  is '0 = Not defined (follow system setting)
1 = No Action - Default
2 = Decrease Max Inventory - Default
3 = Create Work Order for Replacement - Default
4 = No Action - Fixed
5 = Decrease Max Inventory - Fixed
6 = Create Work Order for Replacement - Fixed';
comment on column I_CONTRACTPRODUCT.COMPLIANCYRULEMISC
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACTPRODUCT.COMPLIANCYRULEPRICING  
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user 
2 = Contract enforced No default 
(Null = no compliancy rule)';
comment on column I_CONTRACTPRODUCT.IMAGECARE
  is '0 = Not charged
1 = For repairs
2 = For Loss Charges
3 = For Repairs and Loss Charges
4 = For Residual Value
5 = For Repair and Residual Value
6 = For Residual Value and Loss Charge
7 = For Repairs and Loss Charges and Residual Value';
comment on column I_CONTRACTPRODUCT.LOSSCHARGEPERCENTAGE
  is ' LOSSCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99, DEFAULT 100';
comment on column I_CONTRACTPRODUCT.SRCHARGEPERCENTAGE
  is ' SRCHARGEPERCENTAGE BETWEEN 0.00 AND 999.99, DEFAULT 100';
comment on column I_CONTRACTPRODUCT.COMPLIANCYRULEORDERDELIVERY
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACTPRODUCT.COMPLIANCYRULEIMAGECARE
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACTPRODUCT.COMPLIANCYRULEBILLING
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';
comment on column I_CONTRACTPRODUCT.COMPLIANCYRULEBGPROTECTION
  is '0 = Contract suggested, can be overruled 
1 = Contract enforced, can only be overruled by maintenance user
2 = Contract enforced
No default (Null)';

prompt
prompt Creating table I_CONTRACTPRODUCTQMGROUP
prompt =======================================
prompt
create table I_CONTRACTPRODUCTQMGROUP
(
  contractcode            varchar2(15) not null,
  productcode             varchar2(12) not null,
  sizecode                varchar2(12) not null,
  finishingmethod         varchar2(12) not null,
  contractqmgrpcode       varchar2(15) not null,
  contractqmgrpdesc       varchar2(50) not null,
  maxcirculatinginventory number,
  maxbillingquantity      number,
  maxdeliveryquantity     number
);
alter table I_CONTRACTPRODUCTQMGROUP
  add constraint PK_CONTRPRODQMG primary key (CONTRACTCODE, PRODUCTCODE, SIZECODE, FINISHINGMETHOD, CONTRACTQMGRPCODE);
alter table I_CONTRACTPRODUCTQMGROUP
  add constraint FK_CONTRACTPROD foreign key (CONTRACTCODE, PRODUCTCODE, SIZECODE, FINISHINGMETHOD)
  references i_contractproduct (CONTRACTCODE, PRODUCTCODE, SIZECODE, FINISHINGMETHOD) on delete cascade;

prompt
prompt Creating table I_CONTRACTEMBLEMTEMPLATE
prompt =======================================
prompt
create table I_CONTRACTEMBLEMTEMPLATE
(
  CONTRACTCODE                  VARCHAR2(15) NOT NULL,
  TEMPLATECODE                  VARCHAR2(6) NOT NULL,
  TEMPLATEDESCRIPTION           VARCHAR2(30) NOT NULL,
  PRINTNAMELABEL                VARCHAR2(1) DEFAULT 'N' NOT NULL,
  RENTEMBLEM                    VARCHAR2(1) DEFAULT 'N' NOT NULL,
  EMBROIDERY                    VARCHAR2(1) DEFAULT 'N' NOT NULL,
  COMPLIANCYRULE                NUMBER, 
  CONTRACTEMBTEMPPRICE          NUMBER(15,6),
  CONTRACTEMBTEMPPRICESTARTDATE DATE,
  ACTIVE                        VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  PRODUCTCODE                   VARCHAR2(12),
  SIZECODE                      VARCHAR2(12) NOT NULL,
  DESCRIPTION                   VARCHAR2(80),  
  TEXTCOLORCODE                 VARCHAR2(12),
  BORDERCOLORCODE               VARCHAR2(12),
  BACKGROUNDCOLORCODE           VARCHAR2(12),
  FABRICCODE                    VARCHAR2(12) NOT NULL,
  PLACEMENTCODE                 VARCHAR2(6),
  PLACEMENTDESCRIPTION          VARCHAR2(40),
  EMBLEMTYPE                    NUMBER DEFAULT 3 NOT NULL, 
  ATTACHMENTBY                  NUMBER DEFAULT 1 NOT NULL,
  QTYPERGARMENT                 NUMBER DEFAULT 1 NOT NULL,
  EMBLEMIMAGECODE               VARCHAR2(12),
  PLACEMENTIMAGECODE            VARCHAR2(12),
  EMBLEMFONTDESCRIPTION         VARCHAR2(30),
  EMBLEMFONTSIZE                NUMBER DEFAULT 8 NOT NULL,
  EMBROIDERYFILEPATHORIGINAL    VARCHAR2(60),
  EMBROIDERYFILEPATHPRODUCTION  VARCHAR2(60),
  STITCHCOUNT                   NUMBER DEFAULT 0 NOT NULL,
  SETUPFEE                      NUMBER DEFAULT 0 NOT NULL,
  COLORPALETTE                  VARCHAR2(30),
  EMBROIDERYLETTERING           VARCHAR2(1) DEFAULT 'N' NOT NULL,
  EMBROIDERYLETTERINGLINE1      VARCHAR2(35),
  EMBROIDERYLETTERINGLINE2      VARCHAR2(35),
  EMBROIDERYLETTERINGLINE3      VARCHAR2(35), 
  CONTRACTEMBTEMPLINEPIECEPRICE NUMBER(15,6),
  EMTEMPLINEPIECEPRICESTARTDATE DATE,
  CONTRACTEMBTEMPSALESPRICE     NUMBER(15,6),
  EMTEMPSALESPRICESTARTDATE     DATE,
  TYPEOFMERCHANDISE             NUMBER DEFAULT 4 NOT NULL,
  CUSTOMCOLOR                   VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CUSTOMSIZE                    VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DESCRIPTION2                  VARCHAR2(80),
  STYLECODE                     NUMBER DEFAULT 0 NOT NULL,
  CUSTOMERSUPPLIED              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CONTRACTEMBTEMPLINE_ID        NUMBER
);
comment on column I_CONTRACTEMBLEMTEMPLATE.PRODUCTCODE
  is 'When filled must be type of merchandise 4 = Emblem';
comment on column I_CONTRACTEMBLEMTEMPLATE.EMBLEMTYPE
  is '1= Company
2 = Name
3 = Other/ Not Defined
4 = Title';
comment on column I_CONTRACTEMBLEMTEMPLATE.ATTACHMENTBY
  is '0 = Unknown
1 = Local Stockroom (default)
2 = Central Stockroom
3 = Supplier
4 = Stocked';
comment on column I_CONTRACTEMBLEMTEMPLATE.QTYPERGARMENT
  is 'Default 1 Must be >= 1';
comment on column I_CONTRACTEMBLEMTEMPLATE.EMBLEMFONTSIZE
  is 'Font size in mm. Default 8. Fontsize must be >=8';
comment on column I_CONTRACTEMBLEMTEMPLATE.TYPEOFMERCHANDISE
  is 'Always TOM 4, for the product is always an emblem!';
comment on column I_CONTRACTEMBLEMTEMPLATE.CONTRACTEMBTEMPLINE_ID
  is 'will be filled when converted, so it will not be converted again'; 
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint PK_I_CONTRACTEMBLEMTEMP unique (CONTRACTCODE, TEMPLATECODE, PRODUCTCODE, SIZECODE, TEXTCOLORCODE, BORDERCOLORCODE, BACKGROUNDCOLORCODE, FABRICCODE, PLACEMENTCODE, EMBLEMFONTDESCRIPTION, EMBLEMTYPE);
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint FK_I_CONTRACTEMBLEMTEMP_CONT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE) on delete cascade;
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint FK_I_CONTRACTEMBLEMTEMP_PROD foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
CREATE INDEX INDX_I_CONTRACTEMBLEMTEMPLATE ON I_CONTRACTEMBLEMTEMPLATE(CONTRACTEMBTEMPLINE_ID);
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CONTRACTEMBLEMTEMP_CMPRL
  check (COMPLIANCYRULE IN (NULL, 0, 1, 2));  
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNTEMBLEMTEMP_ATTACHMTBY
  check (ATTACHMENTBY in (0,1,2,3,4));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNTEMBLEMTEMP_EMBLEMTYPE
  check (EMBLEMTYPE in (1,2,3,4));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CONTRACTEMBLEMPLATE_FONT
  check (EMBLEMFONTSIZE >=8);
alter table I_CONTRACTEMBLEMTEMPLATE 
  add constraint CHK_I_CONTRACTEMBLEMTEMP_PROD 
  check (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNTEMBLEMTEMP_QTYPERGARM
  check (QTYPERGARMENT >= 1);
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNTMBLEMTEMP_SIZECODE
  check (SIZECODE = UPPER(TRIM(SIZECODE)));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNMBLEMTEMPLINEMBROID_YN
  check (EMBROIDERYLETTERING IN ('Y', 'N'));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNBTEMPLINE_CUSTOMCOLOR
  check (CUSTOMCOLOR IN ('Y','N'));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNBTEMPLINE_CUSTOMSIZE
  check (CUSTOMSIZE IN ('Y','N'));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNBTEMPLINE_STYLECODE
  check (STYLECODE IN (0,1,2,3));
alter table I_CONTRACTEMBLEMTEMPLATE
  add constraint CHK_I_CNBTEMPLINE_CUSTSUPPLIED
  check (CUSTOMERSUPPLIED IN ('Y','N'));

prompt  
prompt Creating table I_CONTRACTPURCHASEORDER
prompt ======================================
prompt
create table I_CONTRACTPURCHASEORDER
(
  CONTRACTCODE          VARCHAR2(15) NOT NULL,
  PURCHASEORDERNUMBER   VARCHAR2(40) NOT NULL,
  STARTDATE             DATE NOT NULL,
  EXPIRATIONDATE        DATE NOT NULL,
  VALUE                 NUMBER DEFAULT 0 NOT NULL,
  INVOICEDAMOUNT        NUMBER DEFAULT 0 NOT NULL,
  WARNPERCENTAGE        NUMBER(5,2) DEFAULT 0.00 NOT NULL,
  WARNDAYS              NUMBER(4) DEFAULT 0 NOT NULL,
  CLOSEACTION           NUMBER DEFAULT 1 NOT NULL,
  MAXPERCENTAGE         NUMBER(5,2) DEFAULT 100.00 NOT NULL,
  INVOICELINETYPESPERPO VARCHAR2(1) DEFAULT 'N' NOT NULL,
  BUSINESSUNIT          VARCHAR2(6),
  MANUALPO              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SINGLECUSTOMERPO      VARCHAR2(1) DEFAULT 'N' NOT NULL
);
-- Add comments to the columns 
comment on column I_CONTRACTPURCHASEORDER.CLOSEACTION
  is '0 = PO is closed when value is reached 1 = Continue until expired (exceed PO value) 2 = Continue until expired or maximum percentage';
comment on column I_CONTRACTPURCHASEORDER.SINGLECUSTOMERPO
  is 'WHEN SET TO Y THERE CAN ONLY BE 1 ROW AT MOST IN CONTRACTPOCUSTOMER TABLE LINKED TO THIS CONTRACTPURCHASEORDER';
-- Create/Recreate primary, unique and foreign key constraints 
alter table I_CONTRACTPURCHASEORDER
  add constraint PK_I_CONTRACTPURCHASEORDER primary key (CONTRACTCODE, PURCHASEORDERNUMBER);
alter table I_CONTRACTPURCHASEORDER
  add constraint FK_CONTRACTPO_CONTRACT foreign key (CONTRACTCODE)
  references I_CONTRACT (CONTRACTCODE);  
alter table I_CONTRACTPURCHASEORDER
  add constraint FK_I_CONTPO__BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE) on delete set null;
create index INDX_I_CONTRACTPURCHASEORDER_BU on I_CONTRACTPURCHASEORDER (BUSINESSUNIT);  
-- Create/Recreate check constraints 
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_CLOSEACTION
  check (CLOSEACTION IN (0, 1, 2));
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_INVLINETYPESPERPO
  check (INVOICELINETYPESPERPO IN ('Y', 'N'));
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_MANUALPO
  check (MANUALPO IN ('Y', 'N'));
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_MAXPERCENTAGE
  check (MAXPERCENTAGE BETWEEN 100.00 and 999.00);
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_SINGLECUSTOMERPO
  check (SINGLECUSTOMERPO IN ('Y','N'));
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_WARNDAYS
  check (WARNDAYS BETWEEN 0 AND 9999);
alter table I_CONTRACTPURCHASEORDER
  add constraint CHK_I_CONTPO_WARNPERCENTAGE
  check (WARNPERCENTAGE BETWEEN 0.00 AND 100.00);

prompt
prompt Creating table I_CONTRACTPOCUSTOMER
prompt ===================================
prompt  
create table I_CONTRACTPOCUSTOMER
(
  CONTRACTCODE        VARCHAR2(15) NOT NULL,
  PURCHASEORDERNUMBER VARCHAR2(40) NOT NULL,
  CUSTOMERNUMBER      NUMBER NOT NULL,
  CUS_STARTDATE       DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  STARTDATE           DATE NOT NULL,
  ENDDATE             DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL
);
-- Add comments to the columns 
comment on column I_CONTRACTPOCUSTOMER.CONTRACTCODE
  is 'contract code for customer and PO';
comment on column I_CONTRACTPOCUSTOMER.CUS_STARTDATE
  is 'Customer contract start date, to find the right customer contract';
comment on column I_CONTRACTPOCUSTOMER.STARTDATE
  is 'Startdate CONTRACTPOCUSTOMER';
comment on column I_CONTRACTPOCUSTOMER.ENDDATE
  is 'Enddate CONTRACTPOCUSTOMER';
-- Create/Recreate primary, unique and foreign key constraints 
alter table I_CONTRACTPOCUSTOMER
  add constraint PK_I_CONTRACTPOCUSTOMER primary key (CONTRACTCODE, PURCHASEORDERNUMBER, CUSTOMERNUMBER, CUS_STARTDATE);
alter table I_CONTRACTPOCUSTOMER
  add constraint FK_I_CONTRPOCUST_CONPURORD foreign key (CONTRACTCODE, PURCHASEORDERNUMBER)
  references I_CONTRACTPURCHASEORDER (CONTRACTCODE, PURCHASEORDERNUMBER) on delete cascade;
alter table I_CONTRACTPOCUSTOMER
  add constraint FK_I_CONTRACTPOCUST_CONCUST foreign key (CONTRACTCODE, CUSTOMERNUMBER)
  references I_CONTRACTCUSTOMER (CONTRACTCODE, CUSTOMERNUMBER) on delete cascade;
-- Create/Recreate check constraints 
alter table I_CONTRACTPOCUSTOMER
  add constraint CHK_I_CONTRACTPOCUST_DATES
  check (STARTDATE <= ENDDATE);  

prompt
prompt Creating table I_COSTCENTER
prompt ===========================
prompt
create table I_COSTCENTER
(
  customernumber             NUMBER not null,
  departmentnumber           NUMBER(6) not null,
  consumptionpointnumber     NUMBER not null,
  costcentercode             VARCHAR2(12) not null,
  costcenterdescription      VARCHAR2(30) default '-' not null,
  deliverypointcode          VARCHAR2(12) default 1,
  ponumber                   VARCHAR2(50),
  requisitionnumber          VARCHAR2(30),
  accountingstring           VARCHAR2(30),
  eannumber                  VARCHAR2(13),
  exportedi                  NUMBER default 0 not null,
  costcentergroupcode        VARCHAR2(12),
  costcentergroupdescription VARCHAR2(30)
);
comment on column I_COSTCENTER.departmentnumber
  is 'Must exists in I_DEPARTMENT with same CUSTOMERNUMBER';
comment on column I_COSTCENTER.consumptionpointnumber
  is 'Use 1 if its not known';
comment on column I_COSTCENTER.deliverypointcode
  is 'Default is ''1''';
comment on column I_COSTCENTER.eannumber
  is 'Only visible if the plant has license EDIFAKTOIO';
comment on column I_COSTCENTER.exportedi
  is 'EDI Export 0 = Via customer or not applicable 1 = Specific on cost center';
comment on column I_COSTCENTER.costcentergroupcode
  is 'Optional costcenter group of the costcenter';
comment on column I_COSTCENTER.costcentergroupdescription
  is 'Optional costcenter group description ';
alter table I_COSTCENTER
  add constraint PK_I_COSTCENTER primary key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER, COSTCENTERCODE);
alter table I_COSTCENTER
  add constraint FK_I_COSTCENTER_DEPARTMENT foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER)
  references I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);
alter table I_COSTCENTER
  add constraint CHK_I_COSTCENTER_EXPORTEDI
  check (EXPORTEDI in (0,1));

prompt
prompt Creating table I_COSTPRICELIST
prompt ==============================
prompt
create table I_COSTPRICELIST
(
  COSTPRICELISTCODE           VARCHAR2(15) NOT NULL,
  DESCRIPTION                 VARCHAR2(40) NOT NULL,
  ACTIVE                      VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  COSTPRICELISTTYPE           NUMBER NOT NULL,
  CURRENCYCODE                VARCHAR2(3) NOT NULL,
  SERVICETYPE                 NUMBER DEFAULT 0 NOT NULL,
  PROCESSBUSINESSUNIT         VARCHAR2(6),
  INTERNALPROCESSINGBU        VARCHAR2(6),
  PRODUCTCODE                 VARCHAR2(12) NOT NULL,
  SIZECODE                    VARCHAR2(12) NOT NULL,
  FINISHINGMETHOD             VARCHAR2(6) NOT NULL,
  PRICE                       NUMBER(15,6),
  STARTDATE                   DATE DEFAULT SYSDATE NOT NULL,
  DEPRECIATIONPERCENTAGESTOCK NUMBER(15,3) DEFAULT 0 NOT NULL,
  DEPRECIATIONSTARTWEEK       NUMBER DEFAULT 0 NOT NULL,
  DEPRECIATIONPERCENTAGEPOOL  NUMBER(15,3) DEFAULT 0 NOT NULL,
  COSTPRICELISTDETAILTYPE     NUMBER DEFAULT 0 NOT NULL,
  INVOICEBUSINESSUNIT         VARCHAR2(6)
);
comment on column I_COSTPRICELIST.costpricelisttype
  is '1 = Merchandise Cost
2 = Processing Cost
3 = Internal Calculation';
comment on column I_COSTPRICELIST.servicetype
  is '0 = Not applicable (default)
1 = Wash
2 = All-in-Rent';
comment on column I_COSTPRICELIST.costpricelistdetailtype
  is '0 = All items (default)
1 = LOG only
2 = COG only';
alter table I_COSTPRICELIST
  add constraint PK_I_COSTPRICELIST primary key (COSTPRICELISTCODE, COSTPRICELISTTYPE, SERVICETYPE, PRODUCTCODE, SIZECODE, FINISHINGMETHOD, STARTDATE, COSTPRICELISTDETAILTYPE);
alter table I_COSTPRICELIST
  add constraint FK_I_COSTPRICELIST_CURRENCY foreign key (CURRENCYCODE)
  references CURRENCY (CODE);
alter table I_COSTPRICELIST
  add constraint FK_I_COSTPRICELIST_INTERNALBU foreign key (INTERNALPROCESSINGBU)
  references BUSINESSUNIT (CODE);
alter table I_COSTPRICELIST
  add constraint FK_I_COSTPRICELIST_PROCESSBU foreign key (PROCESSBUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_COSTPRICELIST
  add constraint FK_I_COSTPRICELIST_PRODUCT foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
create index INDX_I_COSTPRICELIST_IBU on I_COSTPRICELIST (INTERNALPROCESSINGBU);
create index INDX_I_COSTPRICELIST_PBU on I_COSTPRICELIST (PROCESSBUSINESSUNIT);
create index INDX_I_COSTPRICELIST_BBU on I_COSTPRICELIST (INVOICEBUSINESSUNIT);
alter table I_COSTPRICELIST
  add constraint CHK_I_COSTPRICELIST_ACTIVE
  check (ACTIVE in ('Y','N'));
alter table I_COSTPRICELIST
  add constraint CHK_I_COSTPRICELIST_COSTPLTYPE
  check (COSTPRICELISTTYPE in (1,2,3));
alter table I_COSTPRICELIST
  add constraint CHK_I_COSTPRICELIST_DETAILTYPE
  check (COSTPRICELISTDETAILTYPE in (0,1,2));
alter table I_COSTPRICELIST
  add constraint CHK_I_COSTPRICELIST_SERVTYPE
  check (SERVICETYPE in (0,1,2));
alter table I_COSTPRICELIST
  add constraint FK_I_COSTPRICELIST_INVOICEBU foreign key (INVOICEBUSINESSUNIT)
  references BUSINESSUNIT (CODE);  
alter table I_COSTPRICELIST
  add constraint CHK_I_COSTPRICELIST_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
ALTER TABLE I_COSTPRICELIST
  ADD CONSTRAINT CHK_I_COSTPRICELIST_FINM
  CHECK (FINISHINGMETHOD=UPPER(TRIM(FINISHINGMETHOD))); 
ALTER TABLE I_COSTPRICELIST ADD CONSTRAINT CHK_I_COSTPRICELIST_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_CREDITCARD
prompt ===========================
prompt
create table I_CREDITCARD
(
  customernumber                 NUMBER not null,
  creditcardtype                 NUMBER default 0 not null,
  creditcardnumber               VARCHAR2(80) not null,
  experationyear                 NUMBER(2) not null,
  experationmonth                NUMBER(2) not null,
  verificationvalue              VARCHAR2(80),
  creditcardname                 VARCHAR2(30) not null,
  createtransactionfromstatement VARCHAR2(1) default 'Y' not null
);
comment on column I_CREDITCARD.customernumber
  is 'Customer that must exist in I_BILLTOACCOUNT';
comment on column I_CREDITCARD.creditcardtype
  is '0 = Not defined / unknown
1 = VISA
2 = MasterCard
3 = American Express
4 = Dinner''s Club
9 = Other
Note: the card type is also included in the credit card number';
comment on column I_CREDITCARD.creditcardnumber
  is 'Will be encrypted in database';
comment on column I_CREDITCARD.verificationvalue
  is 'Will be encrypted in database';
comment on column I_CREDITCARD.createtransactionfromstatement
  is 'Y,N Default Y. Automatically charge credit card yes or no';
alter table I_CREDITCARD
  add constraint PKICREDITCARD primary key (CUSTOMERNUMBER, CREDITCARDTYPE, CREDITCARDNUMBER, EXPERATIONYEAR, EXPERATIONMONTH);
alter table I_CREDITCARD
  add constraint FK_BILLTO foreign key (CUSTOMERNUMBER)
  references I_BILLTOACCOUNT (CUSTOMERNUMBER);
alter table I_CREDITCARD
  add constraint ICREATETRANSACTIONFROM
  check (CREATETRANSACTIONFROMSTATEMENT IN ('Y','N'));
alter table I_CREDITCARD
  add constraint ICREDITCARDTYPE
  check (CREDITCARDTYPE IN (0,1,2,3,4,9));
alter table I_CREDITCARD
  add constraint IEXPERATIONMONTH
  check (EXPERATIONMONTH BETWEEN 1 AND 12);
alter table I_CREDITCARD
  add constraint IEXPERATIONYEAR
  check (EXPERATIONYEAR BETWEEN 0 AND 99);

prompt
prompt Creating table I_CUSTOMERACTIVITIES
prompt ===================================
prompt
create table I_CUSTOMERACTIVITIES
(
  customernumber           NUMBER not null,
  activitycode             VARCHAR2(6) default '-' not null,
  processbusinessunitcode  VARCHAR2(6) not null,
  invoicebusinessunitcode  VARCHAR2(6) not null,
  cutoffdate               DATE,
  invoicefrequency         NUMBER default 0 not null,
  salesemployeenumber1     NUMBER,
  salesemployeename1       VARCHAR2(40),
  salesemployeenumber2     NUMBER,
  salesemployeename2       VARCHAR2(40),
  internalbusinessunitcode VARCHAR2(6)
);
comment on column I_CUSTOMERACTIVITIES.internalbusinessunitcode
  is 'Internal business unit, can be left empty';
alter table I_CUSTOMERACTIVITIES
  add constraint PK_I_CUSTOMERACTIVITIES primary key (CUSTOMERNUMBER, ACTIVITYCODE, PROCESSBUSINESSUNITCODE);
create index INDX_I_CUSTOMERACTIVITIES_PBU on I_CUSTOMERACTIVITIES (processbusinessunitcode);
create index INDX_I_CUSTOMERACTIVITIES_BBU on I_CUSTOMERACTIVITIES (invoicebusinessunitcode);
create index INDX_I_CUSTOMERACTIVITIES_IBU on I_CUSTOMERACTIVITIES (internalbusinessunitcode);
alter table I_CUSTOMERACTIVITIES
  add constraint FK_I_ACTIVESTOCKLOC_INT_BU foreign key (INTERNALBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_CUSTOMERACTIVITIES
  add constraint FK_I_ACTIVESTOCKLOC_INV_BU foreign key (INVOICEBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_CUSTOMERACTIVITIES
  add constraint FK_I_ACTIVESTOCKLOC_PROC_BU foreign key (PROCESSBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_CUSTOMERACTIVITIES
  add constraint FK_I_CUSTOMERACT_INVFREQ foreign key (INVOICEFREQUENCY)
  references INVOICEFREQUENCY (INVOICEFREQUENCY_ID);
alter table I_CUSTOMERACTIVITIES
  add constraint FK_I_CUSTOMERACTIVITIES_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;

prompt
prompt Creating table I_CUSTOMERGARMENTCHARGES
prompt ===================================
prompt
create table I_CUSTOMERGARMENTCHARGES
(
  CUSTOMERNUMBER             NUMBER NOT NULL,
  DEFAULTBM1RENTCPWMAX       NUMBER DEFAULT 0 NOT NULL,
  RENTCALCMETHODPOSITIVEMOVE NUMBER DEFAULT 0 NOT NULL,
  RENTCALCMETHODNEGATIVEMOVE NUMBER DEFAULT 0 NOT NULL
);
comment on column I_CUSTOMERGARMENTCHARGES.DEFAULTBM1RENTCPWMAX
  is '0 = Not applicable
1 = Rent Price based on charges per week and Max Inventory, rent based on real quantity in circulation
2 = Rent Price based on charges per week and Max Inventory, rent based on max quantity';
comment on column I_CUSTOMERGARMENTCHARGES.RENTCALCMETHODPOSITIVEMOVE
  is '0 - Default, no calculation
1 - Active part of month billing (Pro rata)
2 - Whole of month bill
3 - No bill';
comment on column I_CUSTOMERGARMENTCHARGES.RENTCALCMETHODNEGATIVEMOVE
  is '0 - Default, no calculation
1 - Active part of month billing (Pro rata)
2 - Whole of month bill
3 - No bill';
alter table I_CUSTOMERGARMENTCHARGES
  add constraint ICUSTGARMCHDEFBM1
  check (DEFAULTBM1RENTCPWMAX in (0,1,2));
alter table I_CUSTOMERGARMENTCHARGES
  add constraint ICUSTGARMCHRENTCALCPOS
  check (RENTCALCMETHODPOSITIVEMOVE in (0,1,2,3));
alter table I_CUSTOMERGARMENTCHARGES
  add constraint ICUSTGARMCHRENTCALCNEG
  check (RENTCALCMETHODNEGATIVEMOVE in (0,1,2,3));
alter table I_CUSTOMERGARMENTCHARGES
  add constraint PK_I_CUSTOMERGARMENTCHARGES primary key (CUSTOMERNUMBER);
alter table I_CUSTOMERGARMENTCHARGES
  add constraint FK_I_CUSTOMERGARMENTCHARGES_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;

prompt
prompt Creating table I_CUSTOMERSURVEY
prompt ===================================
prompt
create table I_CUSTOMERSURVEY
(
  CUSTOMERNUMBER       NUMBER NOT NULL,
  SURVEYTYPECODE       VARCHAR2(6) NOT NULL,
  CONTACTPERSONNUMBER  NUMBER,
  EMPLOYEENUMBER       NUMBER,
  SURVEYINTERVAL       NUMBER NOT NULL,
  NEXTSURVEYDATE       DATE   NOT NULL
);
alter table I_CUSTOMERSURVEY
  add constraint FKI_CUSTOMERSURVEY_CUSTNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_CUSTOMERSURVEY
  add constraint PK_I_CUSTOMERSURVEY primary key (CUSTOMERNUMBER, SURVEYTYPECODE);  

prompt
prompt Creating table I_CUSTOMERPREPCHARGE
prompt ===================================
prompt
create table I_CUSTOMERPREPCHARGE
(
  CUSTOMERNUMBER   NUMBER NOT NULL,
  PRICE            NUMBER(15,6) NOT NULL,
  STARTDATE        DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  REASONCODE       VARCHAR2(6)
);
create unique index PKI_CUSTOMERPREPCHARGE on I_CUSTOMERPREPCHARGE (CUSTOMERNUMBER, STARTDATE, REASONCODE);
alter table I_CUSTOMERPREPCHARGE
  add constraint FKI_CUSTOMERPREPCHR_CUSTN foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;  

prompt
prompt Creating table I_CUSTOMERENVINFO
prompt ================================
prompt
create table I_CUSTOMERENVINFO
(
  customernumber          NUMBER not null,
  wasteperyear            NUMBER(7),
  startdatepowerofatt     DATE,
  enddatepowerofatt       DATE,
  municipalitycode        VARCHAR2(6),
  municipalitydescription VARCHAR2(30),
  wastcode                VARCHAR2(6),
  wastdescription         VARCHAR2(30)
);
alter table I_CUSTOMERENVINFO
  add constraint PKI_CUSTOMERENVINFO primary key (CUSTOMERNUMBER);
alter table I_CUSTOMERENVINFO
  add constraint FKI_CUSTOMERENVINFO_CUSTNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_CUSTOMERENVINFO
  add constraint CHECKFKI_CUSTOMERENVINFODATES
  check ((ENDDATEPOWEROFATT >= STARTDATEPOWEROFATT) or (STARTDATEPOWEROFATT IS NULL AND ENDDATEPOWEROFATT IS NULL));

prompt
prompt Creating table I_CUSTOMERCHARGES
prompt ====================================
prompt
create table I_CUSTOMERCHARGES
(
  CUSTOMERNUMBER NUMBER NOT NULL,
  CHARGETYPE     NUMBER(1) NOT NULL,
  PRICE          NUMBER(15,6) NOT NULL,
  STARTDATE      DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL
);
comment on column I_CUSTOMERCHARGES.CHARGETYPE
  is '0=Stock Charge
1=Exchange Charge
2=Cash Delay Charge';
alter table I_CUSTOMERCHARGES
  add constraint XPKI_CUSTOMERCHARGES primary key (CUSTOMERNUMBER, CHARGETYPE, STARTDATE);
alter table I_CUSTOMERCHARGES
  add constraint CHK_I_CUSTOMERCHARGES_CHRTYPE
  check (CHARGETYPE IN (0,1,2));
create index INDX_I_CUSTOMERCHARGES_CUST on I_CUSTOMERCHARGES(CUSTOMERNUMBER);
create index XIND_I_CUSTOMERCHARGESTYPE on I_CUSTOMERCHARGES (CHARGETYPE);
alter table I_CUSTOMERCHARGES
  add constraint FK_I_CUSTOMERCHR_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER(CUSTOMERNUMBER);

prompt
prompt Creating table I_CUSTOMERSTOCKCHARGE
prompt ====================================
prompt
create table I_CUSTOMERSTOCKCHARGE
(
  CUSTOMERNUMBER NUMBER NOT NULL,
  PRICE          NUMBER(15,6) NOT NULL,
  STARTDATE      DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL
);
alter table I_CUSTOMERSTOCKCHARGE
  add constraint XPKI_CUSTOMERSTOCKCHARGE primary key (CUSTOMERNUMBER, STARTDATE);

prompt
prompt Creating table I_GENERALUSERINSTRUCTION
prompt ========================================
prompt
create table I_GENERALUSERINSTRUCTION
(
  CODE            VARCHAR2(6) NOT NULL,
  DATEACTIVE      DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  DATEINACTIVE    DATE DEFAULT TO_DATE('31/12/2099','DD/MM/YYYY') NOT NULL,
  ENDDATEAUTOMSG  DATE DEFAULT TRUNC(SYSDATE) NOT NULL,
  LANGUAGECODE    VARCHAR2(5) DEFAULT 'EN_US' NOT NULL,
  DESCRIPTION     VARCHAR2(30) NOT NULL,
  INSTRUCTION     VARCHAR2(300) NOT NULL,
  CUSTOMERNUMBER  NUMBER NOT NULL,
  DIALOGCODE     VARCHAR2(40),
  IMPORTED_YN    VARCHAR2(1) DEFAULT 'N' NOT NULL
);
create index INDX_I_GENERALUSERINSTRUCTION on I_GENERALUSERINSTRUCTION (CUSTOMERNUMBER, DATEACTIVE);
alter table I_GENERALUSERINSTRUCTION
  add constraint FK_I_GENERALUSERINSTRUCTION foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_GENERALUSERINSTRUCTION
  add constraint FK_I_GENUSERINSTR_LANGUAGE foreign key (LANGUAGECODE)
  references LANGUAGES (CODE) on delete cascade;
alter table I_GENERALUSERINSTRUCTION
  add constraint FK_I_GENUSERINSTR_DIALOGS foreign key (DIALOGCODE)
  references DIALOGS (CODE) on delete cascade; 
alter table I_GENERALUSERINSTRUCTION
  add constraint CHECK_I_GENUSERINST_IMP_YN
  check (IMPORTED_YN IN ('N','Y'));

prompt
prompt Creating table I_CUSTOMERUSERINSTRUCTION
prompt ========================================
prompt

create table I_CUSTOMERUSERINSTRUCTION
(
  CUSTOMERNUMBER NUMBER NOT NULL,
  INSTRUCTION    VARCHAR2(1000) NOT NULL,
  DATEACTIVE     DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  DATEINACTIVE   DATE DEFAULT TO_DATE('31/12/2099','DD/MM/YYYY') NOT NULL,
  LANGUAGECODE   VARCHAR2(5) DEFAULT 'EN_US' NOT NULL,
  ENDDATEAUTOMSG DATE DEFAULT TO_DATE('31/12/2099','DD/MM/YYYY') NOT NULL,
  DIALOGCODE     VARCHAR2(40),
  IMPORTED_YN    VARCHAR2(1) DEFAULT 'N' NOT NULL,
  USERINSTRUCTIONTYPE VARCHAR2(12)
);
comment on column I_CUSTOMERUSERINSTRUCTION.USERINSTRUCTIONTYPE
  is 'UserInstruction Type Code , can be left empty';

create index INDX_I_CUSTOMERUSERINST_CUST on I_CUSTOMERUSERINSTRUCTION (CUSTOMERNUMBER);
create index INDX_I_CUSTOMERUSERINST_IMP_YN on I_CUSTOMERUSERINSTRUCTION (IMPORTED_YN);
create index INDX_I_CUSTOMERUSERINSTRUCTION on I_CUSTOMERUSERINSTRUCTION (CUSTOMERNUMBER, DATEACTIVE);
alter table I_CUSTOMERUSERINSTRUCTION
  add constraint FK_I_CUSTOMERUSERINSTRUCTION foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CUSTOMERUSERINSTRUCTION
  add constraint FK_I_CUSTUSERINSTR_LANGUAGE foreign key (LANGUAGECODE)
  references LANGUAGES (CODE) on delete cascade;
alter table I_CUSTOMERUSERINSTRUCTION
  add constraint FK_I_CUSTUSERINSTR_DIALOGS foreign key (DIALOGCODE)
  references DIALOGS (CODE) on delete cascade;  
alter table I_CUSTOMERUSERINSTRUCTION
  add constraint CHECK_I_CUSTOMERUSERINSTR
  check (DATEINACTIVE >= DATEACTIVE);
alter table I_CUSTOMERUSERINSTRUCTION
  add constraint CHECK_I_CUSTUSERINSTR_MSG
  check (ENDDATEAUTOMSG BETWEEN DATEACTIVE AND DATEINACTIVE);
alter table I_CUSTOMERUSERINSTRUCTION
  add constraint CHECK_I_CUSTUSERINST_IMP_YN
  check (IMPORTED_YN IN ('N','Y'));


prompt
prompt Creating table I_DELIVERYDAYS
prompt =============================
prompt
create table I_DELIVERYDAYS
(
  CUSTOMERNUMBER        NUMBER NOT NULL,
  DAYNUMBER             NUMBER NOT NULL,
  DELIVERYSCHEMECODE    VARCHAR2(6),
  DELNOGARMENTS         VARCHAR2(1) NOT NULL,
  DELGARMENTS           VARCHAR2(1) NOT NULL,
  ROUTENUMBER           NUMBER,
  STOPNUMBER            NUMBER,
  SOILTICKETS           NUMBER(2) DEFAULT 0 NOT NULL,
  CONTACTPERSONNAME     VARCHAR2(90),
  ROUTELISTINSTRUCTIONS VARCHAR2(1000),
  STOPTYPE              NUMBER DEFAULT 3 NOT NULL,
  CHARGEDELIVERYFEE     NUMBER DEFAULT 0 NOT NULL,
  DRIVERNUMBER          NUMBER,
  DRIVERNAME            VARCHAR2(40),
  ROUTEMANAGER          NUMBER,
  ROUTEMANAGERNAME      VARCHAR2(40),
  DISTRICT              VARCHAR2(6) DEFAULT '-' NOT NULL,
  DISTRICTDESCRIPTION   VARCHAR2(30),
  DELIVERYPOINTCODE     VARCHAR2(12),
  CONTACTPERSONNUMBER   NUMBER,
  DEPOTCODE             VARCHAR2(12),
  DEPOTDESCRIPTION      VARCHAR2(30),
  RETURNROUTE           NUMBER,
  RETURNDAYNUMBER       NUMBER,
  PLANTCODE_ROUTE       VARCHAR2(6),
  ROUTE_DESCRIPTION     VARCHAR2(30),
  ROUTECODE             VARCHAR2(6),
  SORTSEQUENCE          NUMBER(2) DEFAULT 0 NOT NULL,
  SORTBATCHROUTE        NUMBER,
  SORTBATCHROUTESTOP    NUMBER
);
comment on column I_DELIVERYDAYS.STOPTYPE
  is '1=Bring
2=Get
3=Mixed
4=Incidental';
comment on column I_DELIVERYDAYS.CHARGEDELIVERYFEE
  is '0 = No Charge
1 = Normal Delivery Charge
2 = Special Delivery Charge';
comment on column I_DELIVERYDAYS.ROUTEMANAGER
  is 'Optional ''employee'' thats the route manager';
comment on column I_DELIVERYDAYS.DISTRICT
  is 'Obligated district thats linked to the route';
comment on column I_DELIVERYDAYS.RETURNROUTE
  is 'Return Route, must be an existing or to be created route';
comment on column I_DELIVERYDAYS.RETURNDAYNUMBER
  is 'Return Route Daynumber, must be filled when field RETURNROUTE is filled';
comment on column I_DELIVERYDAYS.PLANTCODE_ROUTE
  is 'Optional plant code that is linked to the route number';
comment on column I_DELIVERYDAYS.ROUTECODE
  is 'Used as an alpha route identifier'; 
comment on column I_DELIVERYDAYS.SORTBATCHROUTE
  is 'sort batch definition'; 
comment on column I_DELIVERYDAYS.SORTBATCHROUTESTOP
  is 'specific sort batch definition';   
create unique index XAK1I_DELIVERYDAYS on I_DELIVERYDAYS (CUSTOMERNUMBER, DAYNUMBER, ROUTENUMBER, STOPNUMBER, DELIVERYSCHEMECODE);
create index XIF2I_DELIVERYDAYS on I_DELIVERYDAYS (CUSTOMERNUMBER);
create index XIF3I_DELIVERYDAYS on I_DELIVERYDAYS (PLANTCODE_ROUTE);
alter table I_DELIVERYDAYS
  add constraint FK_I_DELIVERYDAYS_PLANTCODE foreign key (PLANTCODE_ROUTE)
  references PLANT (CODE);
alter table I_DELIVERYDAYS
  add constraint I_DELIVERYDAYS_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_DELIVERYDAYS
  add constraint CHK_I_DELDAY_RETURNROUTE
  check ((RETURNROUTE IS NULL AND RETURNDAYNUMBER IS NULL ) OR (RETURNDAYNUMBER IS NOT NULL AND RETURNROUTE IS NOT NULL));
alter table I_DELIVERYDAYS
  add constraint CHK_IDELDAYS_CHARGEDELIVERYFEE
  check (CHARGEDELIVERYFEE IN (0,1,2));
alter table I_DELIVERYDAYS
  add constraint CHK_IDELDAYS_RETURNDAYNUMBER
  check (RETURNDAYNUMBER IN (1,2,3,4,5,6,7));
alter table I_DELIVERYDAYS
  add constraint DAYNUMBER_VALIDATION
  check (daynumber IN (1,2,3,4,5,6,7));
alter table I_DELIVERYDAYS
  add constraint DELGARMENTS_VALIDATION
  check (delgarments IN ('N','D','B','C','P'));
alter table I_DELIVERYDAYS
  add constraint DELNOGARMENTS_VALIDATION
  check (delnogarments IN ('N','D','B','P'));
alter table I_DELIVERYDAYS
  add constraint STOPTYPE_VALIDATION
  check (stoptype IN (1,2,3, 4));
alter table I_DELIVERYDAYS
  add constraint CHK_I_DELDAYS_SORTSEQUENCE
  check (SORTSEQUENCE between 0 and 99);  

prompt
prompt Creating table I_DELIVERYHISTORY
prompt ================================
prompt
create table I_DELIVERYHISTORY
(
  businessunitnumber     VARCHAR2(6) not null,
  customernumber         NUMBER not null,
  departmentnumber       NUMBER(6) not null,
  productcode            VARCHAR2(12) not null,
  sizecode               VARCHAR2(12) default '-' not null,
  finishingmethodcode    VARCHAR2(6) default '-' not null,
  deliverydate           DATE not null,
  amount                 NUMBER not null,
  consumptionpointnumber NUMBER default 1 not null
);
comment on column I_DELIVERYHISTORY.businessunitnumber
  is 'Default 1';
comment on column I_DELIVERYHISTORY.departmentnumber
  is 'Default 1';
comment on column I_DELIVERYHISTORY.sizecode
  is 'Default ''-''';
comment on column I_DELIVERYHISTORY.finishingmethodcode
  is 'Default ''-''';
comment on column I_DELIVERYHISTORY.consumptionpointnumber
  is 'Default 1';
create index FK_I_DELHISTORY_CUSTOMER on I_DELIVERYHISTORY (CUSTOMERNUMBER);
create index FK_I_DELHISTORY_PRODUCT on I_DELIVERYHISTORY (PRODUCTCODE);
create index FK_I_DELHISTORY_BUCODE on I_DELIVERYHISTORY (BUSINESSUNITNUMBER);
alter table I_DELIVERYHISTORY
  add constraint PK_I_DELIVERYHISTORY primary key (BUSINESSUNITNUMBER, CUSTOMERNUMBER, DEPARTMENTNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, DELIVERYDATE);
alter table I_DELIVERYHISTORY
  add constraint FK_I_DELIVERYHIST_CUSTOMER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_DELIVERYHISTORY
  add constraint FK_I_DELIVERYHISTORY_BU foreign key (BUSINESSUNITNUMBER)
  references BUSINESSUNIT (CODE);
alter table I_DELIVERYHISTORY
  add constraint FK_I_DELIVERYHIST_PRODUCT foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_DELIVERYHISTORY
  add constraint CHK_I_DELIVERYHISTORY_SIZESTAR
  check (SIZECODE <> '*');
alter table I_DELIVERYHISTORY
  add constraint I_DELIVERYHISTORY_BU
  check (TRIM(UPPER(BUSINESSUNITNUMBER))=BUSINESSUNITNUMBER);
alter table I_DELIVERYHISTORY
  add constraint CHK_I_DELIVERYHISTORY_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));  
alter table I_DELIVERYHISTORY
  add constraint CHK_I_DELIVERYHISTORY_FINM
  check (FINISHINGMETHODCODE = upper(trim(FINISHINGMETHODCODE)));  
ALTER TABLE I_DELIVERYHISTORY ADD CONSTRAINT CHK_I_DELIVERYHISTORY_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_DELIVERYPOINT
prompt ==============================
prompt
create table I_DELIVERYPOINT
(
  customernumber            NUMBER not null,
  deliverypointcode         VARCHAR2(12) not null,
  deliverypointdescription  VARCHAR2(30) default '-',
  deliveryaddress_street    VARCHAR2(40),
  deliveryaddress_zipcode   VARCHAR2(15),
  deliveryaddress_city      VARCHAR2(30),
  sortaddress               VARCHAR2(6),
  mondayopen                DATE,
  mondayclosed              DATE,
  tuesdayopen               DATE,
  tuesdayclosed             DATE,
  wednesdayopen             DATE,
  wednesdayclosed           DATE,
  thursdayopen              DATE,
  thursdayclosed            DATE,
  fridayopen                DATE,
  fridayclosed              DATE,
  saterdayopen              DATE,
  saterdayclosed            DATE,
  breakfrom                 DATE,
  breakto                   DATE,
  sundayopen                DATE,
  sundayclosed              DATE,
  maincustomerdeliverypoint VARCHAR2(12),
  deliveryaddress_street2   VARCHAR2(40),
  deliveryaddress_street3   VARCHAR2(40)
);
comment on column I_DELIVERYPOINT.customernumber
  is 'Linked to i_customer';
comment on column I_DELIVERYPOINT.deliverypointcode
  is 'Delivery point code';
comment on column I_DELIVERYPOINT.deliveryaddress_street
  is 'Delivery point address can be left empty';
comment on column I_DELIVERYPOINT.mondayopen
  is 'Time fields date is always 01-01-1900';
comment on column I_DELIVERYPOINT.maincustomerdeliverypoint
  is 'Link to another deliverypoint that must also be delivered, for the sort customer of the I_DELIVERYPOINT.CUSTOMERNUMBER';
alter table I_DELIVERYPOINT
  add constraint PK_I_DELIVERYPOINT primary key (CUSTOMERNUMBER, DELIVERYPOINTCODE);
alter table I_DELIVERYPOINT
  add constraint FK_I_DELIVERYPOINT_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_DELIVERYPOINT
  add constraint CHK_I_DELIVERYPOINT
  check (DELIVERYPOINTCODE = TRIM(UPPER(DELIVERYPOINTCODE)));

prompt
prompt Creating table I_DELIVERYSTANDARDS
prompt ==================================
prompt
create table I_DELIVERYSTANDARDS
(
  CUSTOMERNUMBER               NUMBER NOT NULL,
  DEPARTMENTNUMBER             NUMBER(6) NOT NULL,
  CONSUMPTIONPOINTNUMBER       NUMBER NOT NULL,
  PRODUCTCODE                  VARCHAR2(12) NOT NULL,
  SIZECODE                     VARCHAR2(12) NOT NULL,
  FINISHINGMETHODCODE          VARCHAR2(6) DEFAULT '-' NOT NULL,
  SEASONTYPECODE               VARCHAR2(6),
  SEASONCODE                   VARCHAR2(6),
  DATEACTIVE                   DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  DATEINACTIVE                 DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  DELIVERYSCHEMECODE           VARCHAR2(6),
  ORDERINGMETHOD               NUMBER DEFAULT 2 NOT NULL,
  COUNTSEQUENCENUMBER          NUMBER,
  QUANTITY_MO                  NUMBER,
  QUANTITY_TU                  NUMBER,
  QUANTITY_WE                  NUMBER,
  QUANTITY_TH                  NUMBER,
  QUANTITY_FR                  NUMBER,
  QUANTITY_SA                  NUMBER,
  QUANTITY_SU                  NUMBER,
  NORMSTOCKLEVEL_MO            NUMBER,
  NORMSTOCKLEVEL_TU            NUMBER,
  NORMSTOCKLEVEL_WE            NUMBER,
  NORMSTOCKLEVEL_TH            NUMBER,
  NORMSTOCKLEVEL_FR            NUMBER,
  NORMSTOCKLEVEL_SA            NUMBER,
  NORMSTOCKLEVEL_SU            NUMBER,
  HOLIDAYUSEAGEFACTOR          NUMBER(15,2),
  RENTALQUANTITY               NUMBER,
  CIRCULATINGINVENTORY         NUMBER,
  LOCATION                     VARCHAR2(6),
  REMARKFORPACKINGINSTRUCTIONS VARCHAR2(80),
  DELIVERSTOPSTARTDATE         DATE,
  DELIVERSTOPENDDATE           DATE,
  DELIVERYSTOPSTARTWEEK        NUMBER,
  DELIVERYSTOPENDWEEK          NUMBER,
  RENEWALSTARTDATE             DATE,
  RENEWALENDDATE               DATE,
  QTYFREEOFCHARGE              NUMBER DEFAULT 0,
  CONTRACTPERIOD               NUMBER DEFAULT 0 NOT NULL,
  PROLONGATIONPERIOD           NUMBER DEFAULT 0 NOT NULL,
  CANCELADVANCEPERIOD          NUMBER DEFAULT 0 NOT NULL,
  FREEQTYFREQUENCY             NUMBER(1) DEFAULT 0 NOT NULL,
  COUNTSEQUENCE_SCS            NUMBER,
  DELIVERYPERCENTAGE           NUMBER,
  BILLINGPERCENTAGE            NUMBER
);
comment on column I_DELIVERYSTANDARDS.CONTRACTPERIOD
  is 'Between 0 and 9999';
comment on column I_DELIVERYSTANDARDS.PROLONGATIONPERIOD
  is 'Between 0 and 9999';
comment on column I_DELIVERYSTANDARDS.CANCELADVANCEPERIOD
  is 'Between 0 and 9999';
comment on column I_DELIVERYSTANDARDS.FREEQTYFREQUENCY
  is '0 = per week
1 = per invoice';
comment on column I_DELIVERYSTANDARDS.COUNTSEQUENCE_SCS
  is 'COUNTSEQUENCE STOCKCOUNTSCHEDULEDIST';
comment on column I_DELIVERYSTANDARDS.DELIVERYPERCENTAGE
  is 'Optional. When filled the possible values are 0..100 Only used for module FIXEDDELIVERYANDBILLING';
comment on column I_DELIVERYSTANDARDS.BILLINGPERCENTAGE
  is 'Optional. When filled the possible values are 0..100 Only used for module FIXEDDELIVERYANDBILLING';
create index XIF3I_DELIVERYSTANDARDS on I_DELIVERYSTANDARDS (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
create index XIF4I_DELIVERYSTANDARDS on I_DELIVERYSTANDARDS (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_DELIVERYSTANDARDS
  add constraint XAK1I_DELIVERYSTANDARDS unique (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, DATEACTIVE, DELIVERYSCHEMECODE, SEASONTYPECODE, SEASONCODE);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELIVERYSTANDARDS_CUSTOMERNU foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER)
  references I_CONSUMPTIONPOINT (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELIVERYSTANDARDS_PLPC foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_DELIVERYSTANDARDS
  add constraint CHK_I_DELSTD_FREEQTYFREQUENCY
  check (FREEQTYFREQUENCY IN (0,1));
alter table I_DELIVERYSTANDARDS
  add constraint CHK_I_DELSTD_QTYFREEOFCHARGE
  check (QTYFREEOFCHARGE between 0 and 999 or QTYFREEOFCHARGE is null);
alter table I_DELIVERYSTANDARDS
  add constraint CHK_I_DELSTD_1DAY_ACTIVE
  check (NVL(QUANTITY_MO,-1)>=0 OR NVL(QUANTITY_TU,-1)>=0 OR NVL(QUANTITY_WE,-1)>=0 OR NVL(QUANTITY_TH,-1)>=0 OR NVL(QUANTITY_FR,-1)>=0 OR NVL(QUANTITY_SA,-1)>=0 OR
  NVL(QUANTITY_SU,-1)>=0);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_SIZESTAR
  check (SIZECODE <> '*');
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_CANCELADVANCEPERIOD
  check (CANCELADVANCEPERIOD between 0 and 9999);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_CONTRACTPERIOD
  check (CONTRACTPERIOD between 0 and 9999);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_COUNTSEQUENCENUMBER
  check (COUNTSEQUENCENUMBER between 1 and 255 or COUNTSEQUENCENUMBER is null);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_PROLONGATIONPERIOD
  check (PROLONGATIONPERIOD between 0 and 9999);
alter table I_DELIVERYSTANDARDS
  add constraint ORDERINGMETHOD_VALIDATION
  check (orderingmethod IN (1,2));
alter table I_DELIVERYSTANDARDS
  add constraint CHK_II_DELIVERYSTANDARDS_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_BILLINGPERCENTAGE
  check (BILLINGPERCENTAGE BETWEEN 0 AND 100);
alter table I_DELIVERYSTANDARDS
  add constraint I_DELSTD_DELIVERYPERCENTAGE
  check (DELIVERYPERCENTAGE BETWEEN 0 AND 100);
ALTER TABLE I_DELIVERYSTANDARDS
  ADD CONSTRAINT CHK_I_DELIVERYSTANDARDS_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_DELIVERYSTANDARDS ADD CONSTRAINT CHK_I_DELIVERYSTANDARDS_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_DELIVERYVARIATION
prompt ==================================
prompt
create table I_DELIVERYVARIATION
(
  CUSTOMERNUMBER         NUMBER NOT NULL,
  DEPARTMENTNUMBER       NUMBER(6) NOT NULL,
  CONSUMPTIONPOINTNUMBER NUMBER NOT NULL,
  PRODUCTCODE            VARCHAR2(12) NOT NULL,
  SIZECODE               VARCHAR2(12) NOT NULL,
  FINISHINGMETHODCODE    VARCHAR2(6) NOT NULL,
  DELIVERYDATE           DATE NOT NULL,
  QUANTITY               NUMBER NOT NULL,
  REFERENCE              VARCHAR2(15),
  PROCESSED              VARCHAR2(1) NOT NULL,
  ADJUSTMENTREASON       VARCHAR2(6),
  ORIGIN                 NUMBER NOT NULL,
  FIXEDQUANTITY          VARCHAR2(1) NOT NULL,
  PROCESSBUSINESSUNITCODE VARCHAR2(6),
  INTERNALBUSINESSUNITCODE VARCHAR2(6)
);
comment on column I_DELIVERYVARIATION.ORIGIN
  is '1 Soil Count
2 Stock Count
3 Manual
4 Packing Note
5 Delivery Note
6 Electronic Order
7 Replacement
8 Settlement
9 Shortage
10  Rejected
11  Heavy soil
12  Clean return
13  Loss
14  Inscan';
create index XIF1I_DELIVERYVARIATION on I_DELIVERYVARIATION (CUSTOMERNUMBER);
create index XIF2I_DELIVERYVARIATION on I_DELIVERYVARIATION (PRODUCTCODE);
create index XIF3I_DELIVERYVARIATION on I_DELIVERYVARIATION (PROCESSBUSINESSUNITCODE);
create index XIF4I_DELIVERYVARIATION on I_DELIVERYVARIATION (INTERNALBUSINESSUNITCODE);
alter table I_DELIVERYVARIATION
  add constraint I_DELIVERYVARIATION_CUSTOMERNU foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_DELIVERYVARIATION
  add constraint I_DELIVERYVARIATION_PROCBUCODE foreign key (PROCESSBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_DELIVERYVARIATION
  add constraint I_DELIVERYVARIATION_INTRBUCODE foreign key (INTERNALBUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_DELIVERYVARIATION
  add constraint I_DELIVERYVARIATION_PRODUCTCOD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_DELIVERYVARIATION
  add constraint CHK_I_DELIVERYVAR_SIZESTAR
  check (SIZECODE <> '*');
alter table I_DELIVERYVARIATION
  add constraint I_DELIVERYVAR_SIZECHECK
  check (sizecode = upper(trim(sizecode)));
alter table I_DELIVERYVARIATION
  add constraint ORIGIN_VALIDATION
  check (origin IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14));
alter table I_DELIVERYVARIATION
  add constraint YN_VALIDATION2815
  check (PROCESSED IN ('Y', 'N'));
alter table I_DELIVERYVARIATION
  add constraint YN_VALIDATION3113
  check (FIXEDQUANTITY IN ('Y', 'N'));
ALTER TABLE I_DELIVERYVARIATION
  ADD CONSTRAINT CHK_I_DELIVERYVARIATION_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_DELIVERYVARIATION ADD CONSTRAINT CHK_I_DELIVERYVARIATION_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_EMBLEM
prompt =======================
prompt
create table I_EMBLEM
(
  CODE           VARCHAR2(12) NOT NULL,
  CUSTOMERNUMBER NUMBER NOT NULL,
  PRICE          NUMBER(15,6) NOT NULL
);
create index XIF1I_EMBLEM on I_EMBLEM (CODE);
create index XIF2I_EMBLEM on I_EMBLEM (CUSTOMERNUMBER);
alter table I_EMBLEM
  add constraint XPKI_EMBLEM primary key (CUSTOMERNUMBER, CODE);
alter table I_EMBLEM
  add constraint I_EMBLEM_CODE foreign key (CODE)
  references I_PRODUCT (CODE);
alter table I_EMBLEM
  add constraint I_EMBLEM_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);

prompt
prompt Creating table I_EMBLEMTEMPLATE
prompt ===============================
prompt
create table I_EMBLEMTEMPLATE
(
  CUSTOMERNUMBER               NUMBER NOT NULL,
  TEMPLATECODE                 VARCHAR2(6) NOT NULL,
  TEMPLATEDESCRIPTION          VARCHAR2(30) NOT NULL,
  PRINTNAMELABEL               VARCHAR2(1) DEFAULT 'N' NOT NULL,
  RENTEMBLEM                   VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PRODUCTCODE                  VARCHAR2(12),
  SIZECODE                     VARCHAR2(12) NOT NULL,
  TEXTCOLORCODE                VARCHAR2(12),
  BORDERCOLORCODE              VARCHAR2(12),
  BACKGROUNDCOLORCODE          VARCHAR2(12),
  FABRICCODE                   VARCHAR2(12) NOT NULL,
  PLACEMENTCODE                VARCHAR2(6),
  PLACEMENTDESCRIPTION         VARCHAR2(40),
  EMBLEMFONTDESCRIPTION        VARCHAR2(30),
  DESCRIPTION                  VARCHAR2(80),
  EMBLEMTYPE                   NUMBER DEFAULT 3 NOT NULL,
  ATTACHMENTBY                 NUMBER DEFAULT 1 NOT NULL,
  QTYPERGARMENT                NUMBER DEFAULT 1 NOT NULL,
  FONTSIZE                     NUMBER DEFAULT 8 NOT NULL,
  EMBROIDERYFILEPATHORIGINAL   VARCHAR2(60),
  EMBROIDERYFILEPATHPRODUCTION VARCHAR2(60),
  STITCHCOUNT                  NUMBER DEFAULT 0 NOT NULL,
  SETUPFEE                     NUMBER DEFAULT 0 NOT NULL,
  COLORPALETTE                 VARCHAR2(30),
  PRICE                        NUMBER(15,6),
  TYPEOFMERCHANDISE            NUMBER DEFAULT 4 NOT NULL,
  TEMPLATERENTPRICE            NUMBER(15,6),
  EMBROIDERYLETTERING          VARCHAR2(1) DEFAULT 'N' NOT NULL,
  EMBROIDERYLETTERINGLINE1     VARCHAR2(35),
  EMBROIDERYLETTERINGLINE2     VARCHAR2(35),
  EMBROIDERYLETTERINGLINE3     VARCHAR2(35),
  CUSTOMCOLOR                  VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CUSTOMSIZE                   VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DESCRIPTION2                 VARCHAR2(80),
  STYLECODE                    NUMBER DEFAULT 0 NOT NULL,
  CUSTOMERSUPPLIED             VARCHAR2(1) DEFAULT 'N' NOT NULL,
  EMBLEMTEMPLATELINE_ID        NUMBER
);
comment on column I_EMBLEMTEMPLATE.productcode
  is 'When filled must be type of merchandise 4 = Emblem';
comment on column I_EMBLEMTEMPLATE.emblemtype
  is '1= Company
2 = Name
3 = Other/ Not Defined
4 = Title';
comment on column I_EMBLEMTEMPLATE.attachmentby
  is '0 = Unknown
1 = Local Stockroom (default)
2 = Central Stockroom
3 = Supplier
4 = Stocked';
comment on column I_EMBLEMTEMPLATE.qtypergarment
  is 'Default 1 Must be >= 1';
comment on column I_EMBLEMTEMPLATE.fontsize
  is 'Font size in mm. Default 8. Fontsize must be >=8';
comment on column I_EMBLEMTEMPLATE.typeofmerchandise
  is 'Always TOM 4, for the product is always an emblem!';
comment on column I_EMBLEMTEMPLATE.emblemtemplateline_id
  is 'will be filled when converted, so it will not be converted again';  
alter table I_EMBLEMTEMPLATE
  add constraint PK_I_EMBLEMTEMPLATE unique (CUSTOMERNUMBER, TEMPLATECODE, PRODUCTCODE, SIZECODE, TEXTCOLORCODE, BORDERCOLORCODE, BACKGROUNDCOLORCODE, FABRICCODE, PLACEMENTCODE, EMBLEMFONTDESCRIPTION, EMBLEMTYPE);
CREATE INDEX INDX_I_EMBLEMTEMPLATE ON I_EMBLEMTEMPLATE(EMBLEMTEMPLATELINE_ID);
alter table I_EMBLEMTEMPLATE
  add constraint FK_I_EMBLEMTEMPLATE_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_EMBLEMTEMPLATE
  add constraint FK_I_EMBLEMTEMPLATE_PRODUCT foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBLEMTEMP_ATTACHMENTBY
  check (ATTACHMENTBY in (0, 1,2,3,4));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBLEMTEMP_EMBLEMTYPE
  check (EMBLEMTYPE in (1,2,3,4));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBLEMTEMPLATE_FONT
  check (FONTSIZE >=8);
ALTER TABLE I_EMBLEMTEMPLATE ADD CONSTRAINT CHK_I_EMBLEMTEMPLATE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBLEMTEMP_QTYPERGARMENT
  check (QTYPERGARMENT >= 1);
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBLEMTEMP_SIZECODE
  check (SIZECODE = UPPER(TRIM(SIZECODE)));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBLTEMPLINEEMBROID_YN
  check (EMBROIDERYLETTERING IN ('Y', 'N'));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBTEMPLINE_CUSTOMCOLOR
  check (CUSTOMCOLOR IN ('Y','N'));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBTEMPLINE_CUSTOMSIZE
  check (CUSTOMSIZE IN ('Y','N'));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBTEMPLINE_STYLECODE
  check (STYLECODE IN (0,1,2,3));
alter table I_EMBLEMTEMPLATE
  add constraint CHK_I_EMBTEMPLINE_CUSTSUPPLIED
  check (CUSTOMERSUPPLIED IN ('Y','N'));

prompt
prompt Creating table I_FIXEDWEARERS
prompt =============================               
prompt
create table I_FIXEDWEARERS
(
  CUSTOMERNUMBER      NUMBER not null,
  PRODUCTCODE         VARCHAR2(12) not null,
  SIZECODE            VARCHAR2(12) not null,
  FINISHINGMETHODCODE VARCHAR2(6) default '-' not null,
  COSTCENTERCODE      VARCHAR2(12) not null,
  NROFWEARERS         NUMBER not null,
  NROFCHANGES         NUMBER not null,
  STARTDATE           DATE default trunc(SYSDATE) not null,
  ENDDATE             DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null
);
comment on table I_FIXEDWEARERS
  is 'Refers to PLPCFIXEDWEARERS';
comment on column I_FIXEDWEARERS.customernumber
  is 'Customer number, must exist in customer.csv';
comment on column I_FIXEDWEARERS.productcode
  is 'Code must exist in product.csv';
comment on column I_FIXEDWEARERS.sizecode
  is 'Code of the size. If unknown use minus -.
Size star * is only allowed for products with type of merchandise 2';
comment on column I_FIXEDWEARERS.finishingmethodcode
  is 'Use - if unknown (put up code), this and previous 3 fields link to I_PRODUCTLISTPERCUSTOMER';
comment on column I_FIXEDWEARERS.costcentercode
  is 'Must exist as a costcenter not added while converting this table.';
alter table I_FIXEDWEARERS
  add constraint PK_I_FIXEDWEARERS primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, COSTCENTERCODE, NROFWEARERS, NROFCHANGES);
alter table I_FIXEDWEARERS
  add constraint FK_I_FIXEDWEARERS_PLPC foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_FIXEDWEARERS
  add constraint CHK_I_FIXEDWEARERS_DATES
  check (STARTDATE<=ENDDATE);
alter table I_FIXEDWEARERS
  add constraint CHK_I_FIXEDWEARERS_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
alter table I_FIXEDWEARERS
  add constraint CHK_I_FIXEDWEARERS_FINM
  check (FINISHINGMETHODCODE = upper(trim(FINISHINGMETHODCODE))); 
ALTER TABLE I_FIXEDWEARERS ADD CONSTRAINT CHK_I_FIXEDWEARERS_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_FREQUENCYRELATEDRENTPRICES
prompt ===========================================
prompt
create table I_FREQUENCYRELATEDRENTPRICES
(
  customernumber      NUMBER not null,
  productcode         VARCHAR2(12) not null,
  sizecode            VARCHAR2(12) not null,
  finishingmethodcode VARCHAR2(6) not null,
  frequency           NUMBER not null,
  startdate           DATE default TRUNC(SYSDATE)-1 not null,
  price               NUMBER(15,6) not null,
  contractcoefficient NUMBER(6,3)
);
comment on column I_FREQUENCYRELATEDRENTPRICES.FREQUENCY
  is '1 = weekly
2 = every 2 weeks
etc.';
create index XIF1I_FREQUENCYRELATEDRENTPRIC on I_FREQUENCYRELATEDRENTPRICES (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_FREQUENCYRELATEDRENTPRICES
  add constraint XPKI_FREQUENCYRELATEDRENTPRICE primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, FREQUENCY, STARTDATE);
alter table I_FREQUENCYRELATEDRENTPRICES
  add constraint I_FREQUENCYRELATEDRENTPRICES_C foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE) on delete cascade;
alter table I_FREQUENCYRELATEDRENTPRICES
  add constraint CHK_I_FREQRELATEDRENTPRC_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
ALTER TABLE I_FREQUENCYRELATEDRENTPRICES
  ADD CONSTRAINT CHK_I_FREQRELATEDRENTPRC_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));   
ALTER TABLE I_FREQUENCYRELATEDRENTPRICES ADD CONSTRAINT CHK_I_FREQUENCYRELATEDR_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_CUSTOMERBGPROTECTIONPRICE
prompt ==========================================
prompt
CREATE TABLE I_CUSTOMERBGPROTECTIONPRICE
(
  CUSTOMERNUMBER NUMBER NOT NULL,
  PRODUCTCODE    VARCHAR2(12) NOT NULL,
  SIZECODE       VARCHAR2(12) NOT NULL,
  PRICECOMPONENT NUMBER DEFAULT 1 NOT NULL,
  STARTDATE      DATE NOT NULL,
  PRICE          NUMBER NOT NULL
);
comment on column I_CUSTOMERBGPROTECTIONPRICE.PRICECOMPONENT
  is '1 = Garment Maintenance Protection (GMP) 
2 = Garment Setup Protection (GSP) 
3 = Garment Loss Protection (GLP) 
4 = Garment Repair Protection (GRP)
5 = Merchandize buy out protection(MBYO)
6 = Garment Emblem Protection (GEP)';
alter table I_CUSTOMERBGPROTECTIONPRICE
  add constraint XPK_I_CUSTOMERBGPROTPRICE primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, PRICECOMPONENT, STARTDATE);
alter table I_CUSTOMERBGPROTECTIONPRICE
  add constraint I_CUSTOMERBGPROTPRICE_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CUSTOMERBGPROTECTIONPRICE
  add constraint I_CUSTOMERBGPROTPRICE_PRODU foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_CUSTOMERBGPROTECTIONPRICE
  add constraint CHK_I_CUSTOMERBGPROTPRICE_PC
  check (PRICECOMPONENT IN (1,2,3,4,5,6));
alter table I_CUSTOMERBGPROTECTIONPRICE
  add constraint CHK_I_CUSTBGPROTPRICE_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));  
ALTER TABLE I_CUSTOMERBGPROTECTIONPRICE ADD CONSTRAINT CHK_I_CUSTOMERBGPROTECT_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_LOCKER
prompt =======================
prompt
create table I_LOCKER
(
  customernumber        NUMBER not null,
  deliverypointcode     VARCHAR2(12) not null,
  bank                  VARCHAR2(6),
  locker                VARCHAR2(6) not null,
  remark                VARCHAR2(40),
  sortaddress           VARCHAR2(6),
  lockersortgroupnumber NUMBER(3),
  lockersortgroupdescr  VARCHAR2(30),
  lockerstatus          NUMBER(1) default 1 not null,
  keycombination        VARCHAR2(20)
);
comment on column I_LOCKER.lockerstatus
  is 'The following possibilities are available for
status
1= Available
2= Occupied (employment_id must be <> null)
3= Out of use';
alter table I_LOCKER
  add constraint PK_I_LOCKER unique (CUSTOMERNUMBER, DELIVERYPOINTCODE, BANK, LOCKER);
alter table I_LOCKER
  add constraint FK_I_LOCKER_DELPOINT foreign key (CUSTOMERNUMBER, DELIVERYPOINTCODE)
  references I_DELIVERYPOINT (CUSTOMERNUMBER, DELIVERYPOINTCODE);
alter table I_LOCKER
  add constraint CHK_I_LOCKER_LOCKERSTATUS
  check (LOCKERSTATUS IN (1,2,3));

prompt
prompt Creating table I_MATORDERINGINFO
prompt ================================
prompt
create table I_MATORDERINGINFO
(
  customernumber         NUMBER not null,
  productcode            VARCHAR2(12) not null,
  finishingmethodcode    VARCHAR2(6) default '-' not null,
  sizecode               VARCHAR2(12) not null,
  matorderinginfotype    NUMBER default 1 not null,
  customizationreason    NUMBER default 1 not null,
  qualitygradecode       VARCHAR2(1) default 1 not null,
  suppliernumber         NUMBER default 1 not null,
  backing                NUMBER default 1 not null,
  borderwidth            NUMBER default 1 not null,
  bordermaterial         VARCHAR2(30),
  thickness              NUMBER not null,
  actualwidth            NUMBER(5,1),
  actuallength           NUMBER(5,1),
  shape                  NUMBER default 1 not null,
  customcut              VARCHAR2(1) default 'N' not null,
  logofilepathoriginal   VARCHAR2(60),
  logofilepathproduction VARCHAR2(60),
  direction              NUMBER default 1 not null,
  colorpalettelogo       VARCHAR2(30),
  colorpalettebackground VARCHAR2(30)
);
comment on column I_MATORDERINGINFO.matorderinginfotype
  is '1 = Custom
2 = Logo
3 = Other';
comment on column I_MATORDERINGINFO.customizationreason
  is '1 = Not Applicable
2 = Customer Damaged
3 = Always Match';
comment on column I_MATORDERINGINFO.backing
  is '1 = Cleated
2 = Smooth
3 = Picture Frame';
comment on column I_MATORDERINGINFO.borderwidth
  is '1 = Standard
2 = None';
comment on column I_MATORDERINGINFO.thickness
  is '1 = 45
2 = 65
3 = 90
4 = 120';
comment on column I_MATORDERINGINFO.shape
  is '1 = Rectangular
2 = Round
3 = Oval
4 = Curved Corners';
comment on column I_MATORDERINGINFO.customcut
  is '''Y'' = yes
''N'' = no';
comment on column I_MATORDERINGINFO.direction
  is '1 = Horizontal
2 = Vertical';
alter table I_MATORDERINGINFO
  add constraint XPKI_MATORDERINGINFO primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_MATORDERINGINFO
  add constraint FKI_MATORDERINGINFO_PLPC foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE) on delete cascade;
alter table I_MATORDERINGINFO
  add constraint I_BACKING
  check (BACKING in (1,2,3));
alter table I_MATORDERINGINFO
  add constraint I_BORDERWIDTH
  check (BORDERWIDTH in (1,2));
alter table I_MATORDERINGINFO
  add constraint I_CUSTOMCUT
  check (CUSTOMCUT in ('Y','N'));
alter table I_MATORDERINGINFO
  add constraint I_CUSTOMIZATIONREASON
  check (CUSTOMIZATIONREASON in (1,2,3));
alter table I_MATORDERINGINFO
  add constraint I_DIRECTION
  check (DIRECTION in (1,2));
alter table I_MATORDERINGINFO
  add constraint I_MATORDERINGINFOTYPE
  check (MATORDERINGINFOTYPE in (1,2));
alter table I_MATORDERINGINFO
  add constraint I_SHAPE
  check (SHAPE in (1,2,3,4));
alter table I_MATORDERINGINFO
  add constraint I_THICKNESS
  check (THICKNESS in (1,2,3,4));
alter table I_MATORDERINGINFO
  add constraint CHK_I_MATORDERINGINFO_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
ALTER TABLE I_MATORDERINGINFO
  ADD CONSTRAINT CHK_I_MATORDERINGINFO_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_MATORDERINGINFO ADD CONSTRAINT CHK_I_MATORDERINGINFO_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_MISCCHARGE
prompt ===========================
prompt
create table I_MISCCHARGE
(
  businessunitnumber VARCHAR2(6) not null,
  deltocustnumber    NUMBER not null,
  creationdate       DATE not null,
  description        VARCHAR2(40) not null,
  taxgroupcode       VARCHAR2(6),
  turnovergroupcode  VARCHAR2(12),
  quantity           NUMBER not null,
  price              NUMBER(15,6) not null,
  discountpercentage NUMBER(15,2) not null,
  amount             NUMBER(15,6) not null,
  chargestatus       NUMBER not null,
  costcenter         VARCHAR2(12)
);
comment on column I_MISCCHARGE.businessunitnumber
  is 'Plant number';
comment on column I_MISCCHARGE.deltocustnumber
  is 'Must exist in customer.csv i_customer.';
comment on column I_MISCCHARGE.creationdate
  is 'Creation date of this record.';
comment on column I_MISCCHARGE.description
  is 'Desription that will be printed on the invoice.';
comment on column I_MISCCHARGE.taxgroupcode
  is 'Empty if not taxable. If taxable then fill in the same taxgroupcode as for taxable products.';
comment on column I_MISCCHARGE.discountpercentage
  is '0 if not used.';
comment on column I_MISCCHARGE.amount
  is 'Total invoice amount (PRICE*QTY)-DISC%';
comment on column I_MISCCHARGE.chargestatus
  is '0=To be charged/charged 1=Charge canceled';
comment on column I_MISCCHARGE.costcenter
  is 'Optional costcenter';
create index XIF2I_MISCCHARGE on I_MISCCHARGE (DELTOCUSTNUMBER);
create index INDX_I_MISCCHARGE_BU ON I_MISCCHARGE (businessunitnumber);
alter table I_MISCCHARGE
  add constraint FK_I_MISCCHARGE_BU foreign key (BUSINESSUNITNUMBER)
  references BUSINESSUNIT (CODE);
alter table I_MISCCHARGE
  add constraint I_MISCCHARGE_DELTOCUSTNUMBER foreign key (DELTOCUSTNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_MISCCHARGE
  add constraint I_MISCCHARGE_BU
  check (TRIM(UPPER(BUSINESSUNITNUMBER))=BUSINESSUNITNUMBER);

prompt
prompt Creating table I_MISCELLANEOUS
prompt ==============================
prompt
create table I_MISCELLANEOUS
(
  processtype   NUMBER default 0 not null,
  process       VARCHAR2(255) not null,
  tablename     VARCHAR2(30),
  stringvalue1  VARCHAR2(1000),
  stringvalue2  VARCHAR2(40),
  stringvalue3  VARCHAR2(40),
  stringvalue4  VARCHAR2(40),
  stringvalue5  VARCHAR2(40),
  stringvalue6  VARCHAR2(255),
  stringvalue7  VARCHAR2(255),
  stringvalue8  VARCHAR2(255),
  stringvalue9  VARCHAR2(255),
  stringvalue10 VARCHAR2(255),
  numbervalue1  NUMBER,
  numbervalue2  NUMBER,
  numbervalue3  NUMBER,
  numbervalue4  NUMBER,
  numbervalue5  NUMBER,
  numbervalue6  NUMBER,
  numbervalue7  NUMBER,
  numbervalue8  NUMBER,
  numbervalue9  NUMBER,
  numbervalue10 NUMBER,
  datevalue1    DATE,
  datevalue2    DATE,
  datevalue3    DATE,
  datevalue4    DATE,
  datevalue5    DATE,
  booleanvalue1 VARCHAR2(1) default 'N' not null,
  booleanvalue2 VARCHAR2(1) default 'N' not null,
  booleanvalue3 VARCHAR2(1) default 'N' not null,
  booleanvalue4 VARCHAR2(1) default 'N' not null,
  booleanvalue5 VARCHAR2(1) default 'N' not null
);
comment on column I_MISCELLANEOUS.processtype
  is '1 Process type that can have many records in this table';
comment on column I_MISCELLANEOUS.process
  is 'Description and or sql statement of the process type';
comment on column I_MISCELLANEOUS.tablename
  is 'Optional description for the table that is to be used for update/insert/delete';
comment on column I_MISCELLANEOUS.booleanvalue1
  is 'Y, N';
comment on column I_MISCELLANEOUS.booleanvalue2
  is 'Y, N';
comment on column I_MISCELLANEOUS.booleanvalue3
  is 'Y, N';
comment on column I_MISCELLANEOUS.booleanvalue4
  is 'Y, N';
comment on column I_MISCELLANEOUS.booleanvalue5
  is 'Y, N';
create index INDX_I_MISCELLANEOUS1 on I_MISCELLANEOUS (PROCESSTYPE, TABLENAME);
create index INDX_I_MISCELLANEOUS2 on I_MISCELLANEOUS (PROCESSTYPE, PROCESS);
alter table I_MISCELLANEOUS
  add constraint CHK_I_MISCELLANEOUS_BOOLEAN1
  check (BOOLEANVALUE1 IN ('Y','N'));
alter table I_MISCELLANEOUS
  add constraint CHK_I_MISCELLANEOUS_BOOLEAN2
  check (BOOLEANVALUE2 IN ('Y','N'));
alter table I_MISCELLANEOUS
  add constraint CHK_I_MISCELLANEOUS_BOOLEAN3
  check (BOOLEANVALUE3 IN ('Y','N'));
alter table I_MISCELLANEOUS
  add constraint CHK_I_MISCELLANEOUS_BOOLEAN4
  check (BOOLEANVALUE4 IN ('Y','N'));
alter table I_MISCELLANEOUS
  add constraint CHK_I_MISCELLANEOUS_BOOLEAN5
  check (BOOLEANVALUE5 IN ('Y','N'));

prompt
prompt Creating table I_NOBUDGETCLIENT
prompt ===============================
prompt
create table I_NOBUDGETCLIENT
(
  customernumber NUMBER not null,
  budgetcode     VARCHAR2(6) not null,
  clientnumber   NUMBER not null
);
alter table I_NOBUDGETCLIENT
  add constraint PK_I_NOBUDGETCLIENT primary key (CUSTOMERNUMBER, BUDGETCODE, CLIENTNUMBER);
alter table I_NOBUDGETCLIENT
  add constraint FK_I_NOBUDGETCLIENT_BUDGET foreign key (CUSTOMERNUMBER, BUDGETCODE)
  references I_CUSTOMERBUDGETDEFINITION (CUSTOMERNUMBER, BUDGETCODE);
alter table I_NOBUDGETCLIENT
  add constraint FK_I_NOBUDGETCLIENT_CLIENT foreign key (CUSTOMERNUMBER, CLIENTNUMBER)
  references I_CLIENT (CUSTOMERNUMBER, CLIENTNUMBER);

prompt
prompt Creating table I_NOBUDGETDEPARTMENT
prompt ===================================
prompt
create table I_NOBUDGETDEPARTMENT
(
  customernumber   NUMBER not null,
  budgetcode       VARCHAR2(6) not null,
  departmentnumber NUMBER(6) not null
);
alter table I_NOBUDGETDEPARTMENT
  add constraint PK_I_NOBUDGETDEPARTMENT primary key (CUSTOMERNUMBER, BUDGETCODE, DEPARTMENTNUMBER);
alter table I_NOBUDGETDEPARTMENT
  add constraint FK_I_NOBUDGETDEPART_BUDGET foreign key (CUSTOMERNUMBER, BUDGETCODE)
  references I_CUSTOMERBUDGETDEFINITION (CUSTOMERNUMBER, BUDGETCODE);
alter table I_NOBUDGETDEPARTMENT
  add constraint FK_I_NOBUDGETDEPART_DEP foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER)
  references I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER);

prompt
prompt Creating table I_NONBUSINESSDAY
prompt ===============================
prompt
create table I_NONBUSINESSDAY
(
  customernumber   NUMBER not null,
  departmentnumber NUMBER(6),
  nonbusinessdate  DATE not null,
  closestatus      NUMBER default 2 not null
);
comment on column I_NONBUSINESSDAY.nonbusinessdate
  is 'None business day';
comment on column I_NONBUSINESSDAY.closestatus
  is '1 = Closed
2 = Closed for delivery (default)
3 = Open';
alter table I_NONBUSINESSDAY
  add constraint PK_I_NONBUSINESSDAY unique (CUSTOMERNUMBER, DEPARTMENTNUMBER, NONBUSINESSDATE);
alter table I_NONBUSINESSDAY
  add constraint FK_I_NONBUSINESSDAY_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_NONBUSINESSDAY
  add constraint FK_I_NONBUSINESSDAY_DEPT foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER)
  references I_DEPARTMENT (CUSTOMERNUMBER, DEPARTMENTNUMBER) on delete cascade;
alter table I_NONBUSINESSDAY
  add constraint I_NONBUSINESSDAY_STATUS
  check (CLOSESTATUS in (1,2,3));

prompt
prompt Creating table I_ONSITEINVADJUSTMENT
prompt ====================================
prompt
create table I_ONSITEINVADJUSTMENT
(
  customernumber         NUMBER not null,
  departmentnumber       NUMBER(6) not null,
  consumptionpointnumber NUMBER not null,
  productcode            VARCHAR2(12) not null,
  sizecode               VARCHAR2(12) not null,
  finishingmethodcode    VARCHAR2(6) not null,
  inventorydate          DATE not null,
  quantity               NUMBER not null,
  reference              VARCHAR2(20)
);
alter table I_ONSITEINVADJUSTMENT
  add constraint PK_I_ONSITEINVADJUSTMENT primary key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_ONSITEINVADJUSTMENT
  add constraint FK_I_ONSITEINVADJ_PLPC foreign key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE)
  references I_PRODUCTLISTPERCUSTOMER (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);  
create index XIF1I_ONSITEINVADJUSTMENT on I_ONSITEINVADJUSTMENT (CUSTOMERNUMBER);
create index XIF2I_ONSITEINVADJUSTMENT on I_ONSITEINVADJUSTMENT (PRODUCTCODE);
alter table I_ONSITEINVADJUSTMENT
  add constraint I_ONSITEINVADJUSTMENT_CUSTOMER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_ONSITEINVADJUSTMENT
  add constraint I_ONSITEINVADJUSTMENT_PRODUCTC foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_ONSITEINVADJUSTMENT
  add constraint CHK_I_ONSITEINVADJUSTMENT_SIZE
  check (SIZECODE = upper(trim(SIZECODE))); 
alter table I_ONSITEINVADJUSTMENT
  add constraint CHK_I_ONSITEINVADJUSTMENT_FINM
  check (FINISHINGMETHODCODE = upper(trim(FINISHINGMETHODCODE)));
ALTER TABLE I_ONSITEINVADJUSTMENT ADD CONSTRAINT CHK_I_ONSITEINVADJUSTME_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_PACKCONTENT
prompt ============================
prompt
create table I_PACKCONTENT
(
  packcode            VARCHAR2(12) not null,
  packsequence        NUMBER default 1,
  productcode         VARCHAR2(12) not null,
  sizecode            VARCHAR2(12) default '-' not null,
  finishingmethodcode VARCHAR2(6) default '-' not null,
  amount              NUMBER default 1 not null,
  remark              VARCHAR2(80),
  location            VARCHAR2(6),
  dateactive          DATE default TRUNC(SYSDATE)-1 not null,
  dateinactive        DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null,
  uniquelycoded       VARCHAR2(1) default 'N' not null,
  rownumber           NUMBER,
  positionnumber      NUMBER,
  allowpackcontents   NUMBER(1) default 0
);
comment on column I_PACKCONTENT.packcode
  is 'FK to I_PRODUCT';
comment on column I_PACKCONTENT.packsequence
  is 'If used, then rownumber and positionnumber must be null';
comment on column I_PACKCONTENT.productcode
  is 'FK to I_PRODUCT';
comment on column I_PACKCONTENT.amount
  is 'Pack amount';
comment on column I_PACKCONTENT.rownumber
  is 'Only used in ORS module for OR packs, if used PACKSEQUENCE will be made null';
comment on column I_PACKCONTENT.positionnumber
  is 'Only used in ORS module for OR packs, if used PACKSEQUENCE will be made null';
comment on column I_PACKCONTENT.allowpackcontents
  is '0 = Allow general pool only
1 = Allow customer related pool
2 = Allow wearer related items
3 = Allow customer related pool and wearer related items';
alter table I_PACKCONTENT
  add constraint PK_I_PACKCONTENT unique (PACKCODE, PACKSEQUENCE, ROWNUMBER, POSITIONNUMBER, DATEACTIVE);
alter table I_PACKCONTENT
  add constraint FK_I_PACKCONTENT_PACKCODE foreign key (PACKCODE)
  references I_PRODUCT (CODE) on delete cascade;
alter table I_PACKCONTENT
  add constraint FK_I_PACKCONTENT_PRODUCT foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE) on delete cascade;
alter table I_PACKCONTENT
  add constraint CHK_I_PACKCONTENT_DATECHECK
  check (DATEACTIVE <= DATEINACTIVE);
alter table I_PACKCONTENT
  add constraint CHK_I_PACKCONTENT_FIN
  check (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_PACKCONTENT ADD CONSTRAINT CHK_I_PACKCONTENT_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_PACKCONTENT
  add constraint CHK_I_PACKCONTENT_SEQUENCE
  check (((PACKSEQUENCE IS NULL AND ROWNUMBER IS NOT NULL AND POSITIONNUMBER IS NOT NULL) OR
 (PACKSEQUENCE IS NOT NULL AND ROWNUMBER IS NULL AND POSITIONNUMBER IS NULL)));
alter table I_PACKCONTENT
  add constraint CHK_I_PACKCONTENT_SIZE
  check (SIZECODE=UPPER(TRIM(SIZECODE)));
alter table I_PACKCONTENT
  add constraint CHK_I_PACKCONTENT_UNIQUECODED
  check (UNIQUELYCODED IN ('Y', 'N'));

prompt
prompt Creating table I_PACKCONTENTSALTERNATIVE
prompt ========================================
prompt
create table I_PACKCONTENTSALTERNATIVE
(
  packcode               VARCHAR2(12) not null,
  packsequence           NUMBER default 1,
  productcode            VARCHAR2(12) not null,
  sizecode               VARCHAR2(12) default '-' not null,
  finishingmethodcode    VARCHAR2(6) default '-' not null,
  sequencenumber         NUMBER(1) default 1 not null,
  dateactive             DATE default TRUNC(SYSDATE)-1 not null,
  alternativeproductcode VARCHAR2(12) not null,
  alternativesizecode    VARCHAR2(12) default '-' not null,
  rownumber              NUMBER,
  positionnumber         NUMBER
);
comment on column I_PACKCONTENTSALTERNATIVE.packcode
  is 'FK to I_PRODUCT';
comment on column I_PACKCONTENTSALTERNATIVE.productcode
  is 'FK to I_PRODUCT';
comment on column I_PACKCONTENTSALTERNATIVE.sequencenumber
  is 'Priority 1 is first, max is 9';
alter table I_PACKCONTENTSALTERNATIVE
  add constraint PK_I_PACKCONTENTSALTERNATIVE unique (PACKCODE, PACKSEQUENCE, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, SEQUENCENUMBER, ROWNUMBER, POSITIONNUMBER);
alter table I_PACKCONTENTSALTERNATIVE
  add constraint FK_I_PACKCONTENTALTERNATVE_PCK foreign key (PACKCODE, PACKSEQUENCE, ROWNUMBER, POSITIONNUMBER, DATEACTIVE)
  references I_PACKCONTENT (PACKCODE, PACKSEQUENCE, ROWNUMBER, POSITIONNUMBER, DATEACTIVE) on delete cascade;
alter table I_PACKCONTENTSALTERNATIVE
  add constraint FK_I_PACKCONTENTALTERNATVE_PRD foreign key (ALTERNATIVEPRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PACKCONTENTSALTERNATIVE
  add constraint CHK_I_PACKCONTENTALTERNAT_ALSZ
  check (ALTERNATIVESIZECODE=UPPER(TRIM(ALTERNATIVESIZECODE)));
alter table I_PACKCONTENTSALTERNATIVE
  add constraint CHK_I_PACKCONTENTALTERNAT_ALT
  check (PRODUCTCODE || SIZECODE <> ALTERNATIVEPRODUCTCODE || ALTERNATIVESIZECODE);
alter table I_PACKCONTENTSALTERNATIVE
  add constraint CHK_I_PACKCONTENTALTERNAT_FIN
  check (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_PACKCONTENTSALTERNATIVE ADD CONSTRAINT CHK_I_PACKCONTENTSALTER_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_PACKCONTENTSALTERNATIVE
  add constraint CHK_I_PACKCONTENTALTERNAT_SEQ
  check (SEQUENCENUMBER between 1 and 9);
alter table I_PACKCONTENTSALTERNATIVE
  add constraint CHK_I_PACKCONTENTALTERNAT_SIZE
  check (SIZECODE=UPPER(TRIM(SIZECODE)));

prompt
prompt Creating table I_EXTERNALSTERILIZATIONLOT
prompt ========================================
prompt 
CREATE TABLE I_EXTERNALSTERILIZATIONLOT(BUSINESSUNIT VARCHAR2(6) NOT NULL,
                                       LOTNUMBER VARCHAR2(50) NOT NULL,
                                       STERILIZATIONDATE DATE NOT NULL,
									   STERILIZATIONLOTTYPE VARCHAR2(2) NOT NULL,
									   STATUS NUMBER NOT NULL,
									   CREATIONDATE DATE NOT NULL
									   );
									   
COMMENT ON COLUMN I_EXTERNALSTERILIZATIONLOT.STATUS IS '0 = Open,1 = Closed,2 = Active';
COMMENT ON COLUMN I_EXTERNALSTERILIZATIONLOT.STERILIZATIONLOTTYPE IS 'YN = 6 Months,NY= 12 Months,YY = 6 and 12 Months,
                                                                      YN characters allowed. First char is for 6 Months and second is for 12 Months.';
ALTER TABLE I_EXTERNALSTERILIZATIONLOT
ADD CONSTRAINT PK_I_EXTERNALSTERILIZATIONLOT PRIMARY KEY(LOTNUMBER);
CREATE INDEX XIF1I_EXTERNALSTERILIZATIONLOT ON I_EXTERNALSTERILIZATIONLOT
(BUSINESSUNIT ASC);
ALTER TABLE I_EXTERNALSTERILIZATIONLOT
ADD CONSTRAINT I_EXTERNALSTERILIZATIONLOT_BU FOREIGN KEY(BUSINESSUNIT) REFERENCES BUSINESSUNIT(CODE) ON DELETE CASCADE;
ALTER TABLE I_EXTERNALSTERILIZATIONLOT         
  ADD CONSTRAINT CHK_I_EXTERNALSTERILIZATIONLOT_STATUS
  CHECK(STATUS IN(0,1,2));
ALTER TABLE I_EXTERNALSTERILIZATIONLOT         
  ADD CONSTRAINT CHK_I_EXTERNALSTERILIZATIONLOT_STERILIZATIONLOTTYPE
  CHECK(STERILIZATIONLOTTYPE IN('YN','NY', 'YY'));  
  
prompt
prompt Creating table I_CLEANROOMBATCH
prompt ======================
prompt
create table I_CLEANROOMBATCH
  (
   CLEANROOMBATCHNUMBER  NUMBER NOT NULL,
   BUSINESSUNIT  		 VARCHAR2(6) NOT NULL,
   PLANTDEPARTMENTCODE 	 VARCHAR2(6) NOT NULL,
   CREATIONDATE  		 DATE NOT NULL,
   CREATIONWORKSTATION   VARCHAR2(12) NOT NULL,
   CREATIONUSER  		 VARCHAR2(20) NOT NULL,
   LASTUPDATEWORKSTATION VARCHAR2(12) NOT NULL,
   CUSTOMERNUMBER    	 NUMBER NOT NULL,
   DELIVERYDATE 		 DATE NOT NULL,
   CREATIONREASONCODE 	 VARCHAR2(6) NOT NULL,
   ROUTENUMBER  		 NUMBER NOT NULL,
   DEPARTMENTNUMBER      NUMBER(6),
   CONSUMPTIONPOINTNUMBER NUMBER(2)
   );
   comment on column I_CLEANROOMBATCH.CUSTOMERNUMBER
   is 'Must exist in I_CUSTOMER';
   comment on column I_CLEANROOMBATCH.PLANTDEPARTMENTCODE
   is 'Must be an existing plant department code in this plant';
   comment on column I_CLEANROOMBATCH.CREATIONREASONCODE
   is 'Must be an existing Reason Code';
   create index INDX_I_CLEANROOMBATCH_BU ON I_CLEANROOMBATCH (BUSINESSUNIT);
   ALTER TABLE I_CLEANROOMBATCH
    ADD CONSTRAINT PK_I_CLEANROOMBATCH PRIMARY KEY(CLEANROOMBATCHNUMBER,BUSINESSUNIT);
    ALTER TABLE I_CLEANROOMBATCH
    ADD CONSTRAINT FK_I_CLEANROOMBATCH_CUSTOMERNUMBER FOREIGN KEY (CUSTOMERNUMBER)
    REFERENCES I_CUSTOMER(CUSTOMERNUMBER);
    ALTER TABLE I_CLEANROOMBATCH
	ADD CONSTRAINT I_CLEANROOMBATCH_BU FOREIGN KEY(BUSINESSUNIT) REFERENCES BUSINESSUNIT(CODE);
	ALTER TABLE I_CLEANROOMBATCH
    ADD CONSTRAINT FK_I_CLEANROOMBATCH_CREATIONREASONCODE FOREIGN KEY (CREATIONREASONCODE)
    REFERENCES REASONCODE(CODE);
	ALTER TABLE I_CLEANROOMBATCH
    ADD CONSTRAINT CHK_I_CLEANROOMBATCH_BUSINESSUNIT
    CHECK (BUSINESSUNIT = UPPER(TRIM(BUSINESSUNIT)));
    ALTER TABLE I_CLEANROOMBATCH
    ADD CONSTRAINT CHK_I_CLEANROOMBATCH_CREATIONREASONCODE
    CHECK (CREATIONREASONCODE = UPPER(TRIM(CREATIONREASONCODE)));
    ALTER TABLE I_CLEANROOMBATCH
    ADD CONSTRAINT CHK_I_CLEANROOMBATCH_CREATIONUSER
    CHECK (CREATIONUSER = UPPER(TRIM(CREATIONUSER)));
    ALTER TABLE I_CLEANROOMBATCH ADD CONSTRAINT CHK_I_CLEANROOMBATCH_DEPARTMENTCONSUMPTIONPOINT
    CHECK ((DEPARTMENTNUMBER IS NOT NULL AND CONSUMPTIONPOINTNUMBER IS NOT NULL) OR (DEPARTMENTNUMBER IS  NULL AND CONSUMPTIONPOINTNUMBER IS  NULL));

prompt
prompt Creating table I_PACKINGNOTE
prompt ============================
prompt
create table I_PACKINGNOTE
(
  notenumber             NUMBER not null,
  processingbusinessunit VARCHAR2(6) not null,
  internalprocessingbu   VARCHAR2(6) not null,
  invoicebusinessunit    VARCHAR2(6) not null,
  status                 VARCHAR2(2) default '30' not null,
  productiondate         DATE not null,
  deliverydate           DATE not null,
  customernumber         NUMBER not null,
  departmentnumber       NUMBER default 1 not null,
  consumptionpointnumber NUMBER default 1 not null,
  deliverypoint          VARCHAR2(12) not null,
  plantdepartmentcode    VARCHAR2(6) not null,
  transportarticle       VARCHAR2(6) not null,
  routenumber            NUMBER,
  stopnumber             NUMBER,
  referencenumber        VARCHAR2(30),
  straightevenreturn     VARCHAR2(1) default 'N' not null,
  showoninvoiceappendix  VARCHAR2(1) default 'Y' not null,
  remark                 VARCHAR2(1000),
  pnremark               VARCHAR2(1000),
  freeofchargereasoncode VARCHAR2(6),
  cleanroombatchnumber   NUMBER,
  externalsterilizationlot VARCHAR2(50)  
);
comment on column I_PACKINGNOTE.status
  is 'Status processed';
comment on column I_PACKINGNOTE.productiondate
  is 'Date of packing note';
comment on column I_PACKINGNOTE.deliverydate
  is 'Date of delivery note';
comment on column I_PACKINGNOTE.plantdepartmentcode
  is 'Must be an existing plant department code';
comment on column I_PACKINGNOTE.transportarticle
  is 'Transport article code';
comment on column I_PACKINGNOTE.freeofchargereasoncode
  is 'Must be an existing reason code';
create index indx_i_packingnote_tbu on i_packingnote (INTERNALPROCESSINGBU);
create index indx_i_packingnote_ibu on i_packingnote (INVOICEBUSINESSUNIT);
create index indx_i_packingnote_pbu on i_packingnote (PROCESSINGBUSINESSUNIT);
alter table I_PACKINGNOTE
  add constraint PK_I_PACKINGNOTE primary key (NOTENUMBER);
alter table I_PACKINGNOTE
  add constraint FK_I_PN_CONSUMPTIONPOINT foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER)
  references I_CONSUMPTIONPOINT (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_PACKINGNOTE
  add constraint CHK_I_PN_STATUS
  check (STATUS ='30');
alter table I_PACKINGNOTE
  add constraint FK_I_PN_FREEOFCHARGEREASONCODE foreign key (FREEOFCHARGEREASONCODE)
  references REASONCODE (CODE);
alter table I_PACKINGNOTE
  add constraint FK_I_PN_INTERNALPROCESSINGBU foreign key (INTERNALPROCESSINGBU)
  references BUSINESSUNIT (CODE);
alter table I_PACKINGNOTE
  add constraint FK_I_PN_INVOICEBUSINESSUNIT foreign key (INVOICEBUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_PACKINGNOTE
  add constraint FK_I_PN_PROCESSINGBUSINESSUNIT foreign key (PROCESSINGBUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table  I_PACKINGNOTE
  add constraint FK_I_CLEANROOMBATCHNUMBER foreign key (CLEANROOMBATCHNUMBER,PROCESSINGBUSINESSUNIT)
  references I_CLEANROOMBATCH (CLEANROOMBATCHNUMBER,BUSINESSUNIT);
alter table  I_PACKINGNOTE
  add constraint FK_I_EXTERNALSTERILIZATIONLOT foreign key (EXTERNALSTERILIZATIONLOT)
  references I_EXTERNALSTERILIZATIONLOT (LOTNUMBER);
prompt
prompt Creating table I_PACKINGNOTECONTAINER
prompt =====================================
prompt
create table I_PACKINGNOTECONTAINER
(
  NOTENUMBER           NUMBER NOT NULL,
  SEQUENCENUMBER       NUMBER DEFAULT 1 NOT NULL,
  WEIGHINGCATEGORYCODE VARCHAR2(6),
  TAREWEIGHT           NUMBER NOT NULL,
  GROSSWEIGHT          NUMBER NOT NULL,
  WEIGHTDECIMALS       NUMBER DEFAULT 1 NOT NULL,
  SPECIALQUANTITY      NUMBER,
  SPECIALLENGTH        NUMBER,
  SPECIALWIDTH         NUMBER,
  CONTAINERPRIMARYID_ID VARCHAR2(24),
  WEIGHINGTIMESTAMP    DATE, 
  INVOICENUMBER        NUMBER   
);
alter table I_PACKINGNOTECONTAINER
  add constraint PK_I_PACKINGNOTECONTAINER primary key (NOTENUMBER, SEQUENCENUMBER);
alter table I_PACKINGNOTECONTAINER
  add constraint FK_I_PNC_NOTENUMBER foreign key (NOTENUMBER)
  references I_PACKINGNOTE (NOTENUMBER) on delete cascade;
alter table I_PACKINGNOTECONTAINER
  add constraint CHK_I_PNC_WEIGHTS
  check (ABS(TAREWEIGHT)<=ABS(GROSSWEIGHT));

prompt
prompt Creating table I_PACKINGNOTELINE
prompt ================================
prompt
create table I_PACKINGNOTELINE
(
  NOTENUMBER                   NUMBER NOT NULL,
  PRODUCTCODE                  VARCHAR2(12) NOT NULL,
  SIZECODE                     VARCHAR2(12) NOT NULL,
  FINISHINGMETHOD              VARCHAR2(6) DEFAULT '-' NOT NULL,
  STANDARDAMOUNT               NUMBER DEFAULT 0 NOT NULL,
  VARIATIONAMOUNT              NUMBER DEFAULT 0 NOT NULL,
  DELIVEREDAMOUNT              NUMBER DEFAULT 0 NOT NULL,
  TOBEDELIVEREDAMOUNT          NUMBER DEFAULT 0 NOT NULL,
  REMARKFORPACKINGINSTRUCTIONS VARCHAR2(80),
  CUSTOMCODE                   VARCHAR2(16),
  CUSTOMDESCRIPTION            VARCHAR2(30),
  PUTUPTYPE                    NUMBER DEFAULT 1 NOT NULL,
  NOCHARGEFIRSTISSUE           NUMBER DEFAULT 0 NOT NULL,
  DELIVEREDCOGQTY              NUMBER DEFAULT 0 NOT NULL,
  NOCHARGEFIRSTISSUECOG        NUMBER DEFAULT 0 NOT NULL,
  PACKINGSEQUENCE              NUMBER DEFAULT 0 NOT NULL
);
comment on column I_PACKINGNOTELINE.standardamount
  is 'Quantity from standard delivery';
comment on column I_PACKINGNOTELINE.variationamount
  is 'Sum of quantities from delivery variations';
comment on column I_PACKINGNOTELINE.putuptype
  is '1 = Put up per customer (Packingnote)
2 = Bulk put up
3 = Bundle tag';
comment on column I_PACKINGNOTELINE.PACKINGSEQUENCE
  is 'The items will be packed in this sequence';
alter table I_PACKINGNOTELINE
  add constraint PK_I_PACKINGNOTELINE primary key (NOTENUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHOD);
alter table I_PACKINGNOTELINE
  add constraint FK_I_PNL_NOTENUMBER foreign key (NOTENUMBER)
  references I_PACKINGNOTE (NOTENUMBER) on delete cascade;
alter table I_PACKINGNOTELINE
  add constraint FK_I_PNL_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_FINISHINGMETHOD
  check (FINISHINGMETHOD = UPPER(TRIM(FINISHINGMETHOD)));
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_NOCHARGEFIRSTISSCOG
  check (NOCHARGEFIRSTISSUECOG >= 0);
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_NOCHARGEFIRSTISSUE
  check (NOCHARGEFIRSTISSUE >= 0);
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_PRODUCTCODE
  check (PRODUCTCODE = UPPER(TRIM(PRODUCTCODE)));
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_PUTUPTYPE
  check (PUTUPTYPE in (0,1,2,3));
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_SIZECODE
  check (SIZECODE = UPPER(TRIM(SIZECODE)));
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_STANDARDAMOUNT
  check (STANDARDAMOUNT >= 0);
alter table I_PACKINGNOTELINE
  add constraint CHK_I_PKL_VARIATIONAMOUNT
  check (VARIATIONAMOUNT >= 0);

prompt
prompt Creating table I_PACKINGNOTELINECONTENT
prompt =======================================
prompt
create table I_PACKINGNOTELINECONTENT
(
  notenumber             NUMBER not null,
  productcode            VARCHAR2(12) not null,
  sizecode               VARCHAR2(12) not null,
  finishingmethod        VARCHAR2(6) default '-' not null,
  contentproductcode     VARCHAR2(12) not null,
  contentsizecode        VARCHAR2(12) not null,
  contentfinishingmethod VARCHAR2(6) default '-' not null,
  quantity               NUMBER default 1 not null
);
alter table I_PACKINGNOTELINECONTENT
  add constraint PK_I_PACKINGNOTELINECONTENT primary key (NOTENUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHOD, CONTENTPRODUCTCODE, CONTENTSIZECODE, CONTENTFINISHINGMETHOD);
alter table I_PACKINGNOTELINECONTENT
  add constraint FK_I_PNLC_CONTENTPRODUCTCODE foreign key (CONTENTPRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PACKINGNOTELINECONTENT
  add constraint FK_I_PNLC_PNL foreign key (NOTENUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHOD)
  references I_PACKINGNOTELINE (NOTENUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHOD) on delete cascade;
alter table I_PACKINGNOTELINECONTENT
  add constraint CHK_I_PKLC_COFINISHINGMETHOD
  check (CONTENTFINISHINGMETHOD = UPPER(TRIM(CONTENTFINISHINGMETHOD)));
alter table I_PACKINGNOTELINECONTENT
  add constraint CHK_I_PKLC_COPRODUCTCODE
  check (CONTENTPRODUCTCODE = UPPER(TRIM(CONTENTPRODUCTCODE)));
alter table I_PACKINGNOTELINECONTENT
  add constraint CHK_I_PKLC_COSIZECODE
  check (CONTENTSIZECODE = UPPER(TRIM(CONTENTSIZECODE)));
alter table I_PACKINGNOTELINECONTENT
  add constraint CHK_I_PNLC_QUANTITY
  check (QUANTITY >= 1);
alter table I_PACKINGNOTELINECONTENT
  add constraint CHK_I_PACKNOTELINECONTENT_SIZE
  check (SIZECODE = upper(trim(SIZECODE)));
ALTER TABLE I_PACKINGNOTELINECONTENT
  ADD CONSTRAINT CHK_I_PACKINGNOTELINECONT_FINM
  CHECK (FINISHINGMETHOD=UPPER(TRIM(FINISHINGMETHOD)));
ALTER TABLE I_PACKINGNOTELINECONTENT ADD CONSTRAINT CHK_I_PACKINGNOTELINECO_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_PRICELIST
prompt ==========================
prompt
create table I_PRICELIST
(
  PRICELISTCODE        VARCHAR2(15) NOT NULL,
  PRICELISTTYPE        NUMBER NOT NULL,
  PRICELISTDESCRIPTION VARCHAR2(50) NOT NULL,
  CURRENCYCODE         VARCHAR2(3) NOT NULL,
  PRODUCTCODE          VARCHAR2(12),
  SIZECODE             VARCHAR2(12),
  FINISHINGMETHODCODE  VARCHAR2(6),
  WEIGHINGCATEGORYCODE VARCHAR2(6),
  REPAIRTYPECODE       VARCHAR2(6),
  RENTPRICETYPE        NUMBER DEFAULT 1,
  RENTCHANGESPERWEEK   NUMBER,
  PRICE                NUMBER(15,6) NOT NULL,
  PRICEPERMINUTE       NUMBER(15,6),
  STARTDATEPRICE       DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  WASHPRICETYPE        NUMBER DEFAULT 1,
  CHAINCODE            VARCHAR2(6),
  PRICEINDEXCODE       VARCHAR2(6),
  PRICEUPDATELOCKDATE  DATE,
  VOLUMEPRICE          NUMBER(6) DEFAULT 1 NOT NULL,
  SPECIALCHARGECODE    VARCHAR2(6),
  PERCENTAGE           NUMBER,
  PRICECOMPONENT       NUMBER,
  DEFAULTPRICELIST     VARCHAR2(1) DEFAULT 'N',
  MAXINVENTORY         NUMBER,
  SIZEBILLINGGROUPCODE VARCHAR2(12)
);
comment on column I_PRICELIST.PRICELISTTYPE
  is '1 = Wash 
2 = Rent 
3 = Replacement 
4 = Sales 
5 = Weight 
6 = Repair 
7 = Emblem 
8 = Emblem Template 
9 = Garment Insurance 
10 = Special Charge
12 = Special Size Charge';
comment on column I_PRICELIST.finishingmethodcode
  is 'For 1,2 Obligated.';
comment on column I_PRICELIST.weighingcategorycode
  is 'For 5=Weight obligated';
comment on column I_PRICELIST.repairtypecode
  is 'For 6=Repair obligated';
comment on column I_PRICELIST.rentpricetype
  is 'For 2=Rent obligated.
Possible values 1=Piece price
2=Changes/Wk
3=Overuse price
4=Per Frequency
5=Under use Price
6=Lease
7=Split price
8=Per Invoice Frequency
10=Loan
11=Changes per week per max inventory';
comment on column I_PRICELIST.rentchangesperweek
  is 'Obligated when J=2 or 4 or 11
If 2 then number of changes
If 4 then frequency in weeks';
comment on column I_PRICELIST.priceperminute
  is 'Can only be used for 6.';
comment on column I_PRICELIST.washpricetype
  is 'For 1=Wash obligated. Possible values 1 = All items
2 = COG items only
4 = Split price
5 = Heavy Soil';
comment on column I_PRICELIST.chaincode
  is 'Optional chain code that is linked to this pricelist';
comment on column I_PRICELIST.priceindexcode
  is 'Optional price index code that is linked to this pricelist';
comment on column I_PRICELIST.priceupdatelockdate
  is 'Optional price lock date code that is linked to this pricelist';
comment on column I_PRICELIST.volumeprice
  is 'Related to the Salesprice, and only used when
there is a Salesprice, then the default value is 1';
comment on column I_PRICELIST.specialchargecode
  is 'Must be filled when PRICELISTTYPE = 10';
comment on column I_PRICELIST.percentage
  is 'Will only be used when PRICELISTTYPE = 10 and when the special charge is of the type Percentage';
comment on column I_PRICELIST.PRICECOMPONENT
  is '1 = Garment Maintenance Protection (GMP)
2 = Garment Setup Protection (GSP)
3 = Garment Loss Protection (GLP)
4 = Garment Repair Protection (GRP)
5 = Merchandize buy out protection(MBYO)
6 = Garment Emblem Protection (GEP)';
comment on column I_PRICELIST.maxinventory
  is 'Obligated when RENTPRICETYPE = 11. Only used in combination with RENTPRICETYPE = 11.';
create unique index XAK1I_PRICELIST on I_PRICELIST (PRICELISTCODE, PRICELISTTYPE, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, WEIGHINGCATEGORYCODE, REPAIRTYPECODE, RENTPRICETYPE, RENTCHANGESPERWEEK, STARTDATEPRICE, WASHPRICETYPE, SPECIALCHARGECODE, PRICECOMPONENT);
create index XIF1I_PRICELIST on I_PRICELIST (PRODUCTCODE);
alter table I_PRICELIST
  add constraint I_PRICELIST_CURRENCY foreign key (CURRENCYCODE)
  references CURRENCY (CODE);
alter table I_PRICELIST
  add constraint I_PRICELIST_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PRICELIST
  add constraint CHK_I_PRICELIST_VOLUMEPRICE
  check (VOLUMEPRICE BETWEEN 1 AND 999999);
alter table I_PRICELIST
  add constraint PRICETYPE_VALIDATION1
  check (PRICELISTTYPE IN (1,2,3,4,5,6,7,8,9,10,12));
alter table I_PRICELIST
  add constraint CHK_I_PRICELIST_RENTPRICETYPE
  check (RENTPRICETYPE between 1 and 11);  
alter table I_PRICELIST
  add constraint PRICETYPE_VAL_RENTPRICETYPE
  check (PRICELISTTYPE <> 2 or (RENTPRICETYPE BETWEEN 1 AND 11 AND PRICELISTTYPE = 2));
alter table I_PRICELIST
  add constraint PRICETYPE_VAL_WASHPRICETYPE
  check (PRICELISTTYPE <> 1 OR (WASHPRICETYPE BETWEEN 1 AND 5 AND PRICELISTTYPE = 1));
alter table I_PRICELIST
  add constraint CHK_I_PRICELIST_PC
  check (PRICECOMPONENT IN (1,2,3,4,5,6));
alter table I_PRICELIST
  add constraint CHK_I_PRICELISTT_SIZE
  check (SIZECODE is null or SIZECODE = UPPER(TRIM(SIZECODE)));
alter table I_PRICELIST
  add constraint CHK_I_PRICELIST_FINISHNGMETHOD
  check (FINISHINGMETHODCODE is null or FINISHINGMETHODCODE = UPPER(RTRIM(LTRIM(FINISHINGMETHODCODE))));
alter table I_PRICELIST add constraint CHK_I_PRICELIST_PROD check (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
alter table I_PRICELIST
  add constraint CHK_I_PRICELIST_CODE
  check (PRICELISTCODE = UPPER(TRIM(PRICELISTCODE)));
alter table I_PRICELIST
  add constraint CHK_I_PRICELIST_DEFAULTYN
  check (DEFAULTPRICELIST IN ('Y', 'N'));
alter table I_PRICELIST
  add constraint MAXINV_VAL_RENTPRICETYPE
  check (MAXINVENTORY IS NULL OR (MAXINVENTORY>=0 AND RENTPRICETYPE = 11));
alter table I_PRICELIST
  add constraint FK_I_PRICELIST_SIZEBILLINGGROUPCODE foreign key (SIZEBILLINGGROUPCODE)
  references SIZEBILLINGGROUP(CODE); 

prompt
prompt Creating table I_PRICELISTPERCUSTOMER
prompt =====================================
prompt
CREATE TABLE I_PRICELISTPERCUSTOMER
(
  CUSTOMERNUMBER      NUMBER NOT NULL,
  PRICELISTTYPE       NUMBER NOT NULL,
  PRIORITY            NUMBER NOT NULL,
  PRICELISTCODE       VARCHAR2(15),
  STARTDATE           DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  PRICEINDEXCODE      VARCHAR2(6),
  PRICEUPDATELOCKDATE DATE
);
comment on column I_PRICELISTPERCUSTOMER.PRICELISTTYPE
  is '1 = Wash 
2 = Rent 
3 = Replacement 
4 = Sales 
5 = Weight 
6 = Repair 
7 = Emblem 
8 = Emblem Template 
9 = Garment Insurance 
10 = Special Charge
12 = Special Size Charge';
comment on column I_PRICELISTPERCUSTOMER.priority
  is 'between 2 and 99';
comment on column I_PRICELISTPERCUSTOMER.priceindexcode
  is 'Optional price index code that is linked to this customer-pricelist';
comment on column I_PRICELISTPERCUSTOMER.priceupdatelockdate
  is 'Optional price lock date code that is linked to this customer-pricelist';
create unique index XPKI_PRICELISTPERCUSTOMER on I_PRICELISTPERCUSTOMER (CUSTOMERNUMBER, PRICELISTTYPE, PRICELISTCODE);
create unique index XPKI2_PRICELISTPERCUSTOMER on I_PRICELISTPERCUSTOMER (CUSTOMERNUMBER, PRICELISTTYPE, PRIORITY);
alter table I_PRICELISTPERCUSTOMER
  add constraint I_PRICELISTPERCUSTOMER_CUSTOME foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_PRICELISTPERCUSTOMER
  add constraint PRICELISTPLPC_PRIORITY_VAL
  check ((PRICELISTCODE IS NULL and PRIORITY BETWEEN 1 and 99) or (PRICELISTCODE is not null and PRIORITY BETWEEN 2 and 99));
alter table I_PRICELISTPERCUSTOMER
  add constraint PRICETYPE_VALIDATION2
  check (PRICELISTTYPE IN (1,2,3,4,5,6,7,8,9,10,12));

prompt
prompt Creating table I_PRODUCTCONVERSIONSIZE
prompt ======================================
prompt
create table I_PRODUCTCONVERSIONSIZE
(
  customernumber         NUMBER not null,
  sourceproductcode      VARCHAR2(12) not null,
  destinationproductcode VARCHAR2(12) not null,
  sourcesizecode         VARCHAR2(12) not null,
  destinationsizecode    VARCHAR2(12) not null,
  startdate              DATE default TRUNC(SYSDATE) not null,
  finishingmethodcode    VARCHAR2(6) not null
);
comment on column I_PRODUCTCONVERSIONSIZE.customernumber
  is 'CUSTOMERSELECTION 0 = CUSTOMER
1 = DEBTOR
2 = MASTER ACCOUNT';
comment on column I_PRODUCTCONVERSIONSIZE.sourceproductcode
  is 'STATUS IN PRODUCTCONVERSION = 1 = Completed';
alter table I_PRODUCTCONVERSIONSIZE
  add constraint PK_I_PRODUCTCONVERSIONSIZE primary key (CUSTOMERNUMBER, SOURCEPRODUCTCODE, DESTINATIONPRODUCTCODE, SOURCESIZECODE, DESTINATIONSIZECODE);
alter table I_PRODUCTCONVERSIONSIZE
  add constraint FK_I_PRODUCTCONVSIZE_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_PRODUCTCONVERSIONSIZE
  add constraint FK_I_PRODUCTCONVSIZE_DPROD foreign key (DESTINATIONPRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PRODUCTCONVERSIONSIZE
  add constraint FK_I_PRODUCTCONVSIZE_SPROD foreign key (SOURCEPRODUCTCODE)
  references I_PRODUCT (CODE);
ALTER TABLE I_PRODUCTCONVERSIONSIZE
  ADD CONSTRAINT CHK_I_PRODCNVSZ_SOURCESIZECODE
  CHECK (SOURCESIZECODE = UPPER(TRIM(SOURCESIZECODE)));
ALTER TABLE I_PRODUCTCONVERSIONSIZE
  ADD CONSTRAINT CHK_I_PRODCNVSZ_DESTSIZECODE
  CHECK (DESTINATIONSIZECODE = UPPER(TRIM(DESTINATIONSIZECODE))); 
alter table I_PRODUCTCONVERSIONSIZE
  add constraint CHK_I_PRODCNVSZ_FINM
  check (FINISHINGMETHODCODE = upper(trim(FINISHINGMETHODCODE)));    

prompt
prompt Creating table I_PRODUCTSIZE
prompt ============================
prompt
create table I_PRODUCTSIZE
(
  PRODUCTCODE                    VARCHAR2(12) NOT NULL,
  SIZECODE                       VARCHAR2(12) NOT NULL,
  DESCRIPTION                    VARCHAR2(30) DEFAULT '-' NOT NULL,
  LEGACYCODE                     VARCHAR2(12),
  DEFAULTSALESPRICE              NUMBER(15,6),
  DEFAULTREPLACEPRICE            NUMBER(15,6),
  DEFAULTRENTPRICE               NUMBER(15,6),
  SIZEGROUPCODE                  VARCHAR2(6) DEFAULT '-' NOT NULL,
  SIZEGROUPDESCRIPTION           VARCHAR2(40) DEFAULT '-' NOT NULL,
  USEFOREMBLEMS                  VARCHAR2(1) DEFAULT 'N' NOT NULL,
  LENGTH                         VARCHAR2(6),
  WIDTH                          VARCHAR2(6),
  PROVISIONGROUPCODE             VARCHAR2(6),
  TYPEOFMERCHANDISE              NUMBER DEFAULT 2 NOT NULL,
  MAXCARTQTY                     NUMBER DEFAULT 0 NOT NULL,
  SPECIALSIZE                    VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SEQUENCENUMBER                 NUMBER,
  STANDARDLENGTH                 VARCHAR2(1) DEFAULT 'N' NOT NULL,
  SIZEBILLINGGROUPCODE           VARCHAR2(12),
  DEFAULT_SIZEBILLGROUP_FOR_SIZE VARCHAR2(12),
  SIZEGROUPINGCODE               VARCHAR2(12),
  THEORETICALWEIGHT              NUMBER
  );
comment on column I_PRODUCTSIZE.TYPEOFMERCHANDISE
  is '1=linen/dust control,2=garments,3=disposables/sales only 4=emblem';
comment on column I_PRODUCTSIZE.MAXCARTQTY
  is 'Optional quantity per bag (cart)
Must be between 0 and 9999, default value is 0';
comment on column I_PRODUCTSIZE.SPECIALSIZE
  is 'Possible values Y or N';
comment on column I_PRODUCTSIZE.SEQUENCENUMBER
  is 'Sizes will be added to the producted ordered by this sequence';
comment on column I_PRODUCTSIZE.SIZEBILLINGGROUPCODE
  is 'Stores the relationship and percentage between SizeBillingGroup and Productsize';
comment on column I_PRODUCTSIZE.DEFAULT_SIZEBILLGROUP_FOR_SIZE
  is 'Default SizeBillingGroup on sizecode';  
create index XIF889I_PRODUCTSIZE on I_PRODUCTSIZE (PRODUCTCODE);
create index XPKI_PRODUCTSIZETYPE on I_PRODUCTSIZE (PRODUCTCODE, SIZEGROUPCODE);
alter table I_PRODUCTSIZE
  add constraint FK_SIZEBILLINGGROUPCODE foreign key (SIZEBILLINGGROUPCODE)
  references SIZEBILLINGGROUP(CODE);  
alter table I_PRODUCTSIZE
  add constraint FK_DEFAULT_SIZEBILLGRP_FR_SIZE foreign key (DEFAULT_SIZEBILLGROUP_FOR_SIZE)
  references SIZEBILLINGGROUP(CODE);
alter table I_PRODUCTSIZE
  add constraint XPKI_PRODUCTSIZE primary key (PRODUCTCODE, SIZECODE);
alter table I_PRODUCTSIZE
  add constraint FKI_PRODUCTSIZE_TOM foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_PRODUCTSIZE
  add constraint I_PRODUCTSIZE_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_PRODUCTSIZE
  add constraint CHK_I_PRODSIZE_SPECIALSIZE
  check (SPECIALSIZE IN ('Y', 'N'));
ALTER TABLE I_PRODUCTSIZE ADD CONSTRAINT CHK_I_PRODUCTSIZE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_PRODUCTSIZE
  ADD CONSTRAINT I_PRODUCTSIZE_CHECK_SIZE
  CHECK (SIZECODE = UPPER(RTRIM(LTRIM(SIZECODE))));
ALTER TABLE I_PRODUCTSIZE
  ADD CONSTRAINT I_PRODSIZE_SIZEGROUPCODE
  CHECK (SIZEGROUPINGCODE = UPPER(RTRIM(LTRIM(SIZEGROUPINGCODE))));  
alter table I_PRODUCTSIZE
  add constraint I_PRODUCTSIZE_MAXCARTQTY
  check (MAXCARTQTY BETWEEN 0 AND 9999);
ALTER TABLE I_PRODUCTSIZE
  ADD CONSTRAINT I_PRODUCTSIZESTAR
  CHECK ((SIZECODE = '*' AND TYPEOFMERCHANDISE = 2) OR (SIZECODE <> '*'));
alter table I_PRODUCTSIZE
  add constraint USEFOREMBLEMSYN
  check (USEFOREMBLEMS IN ('Y', 'N')); 

prompt
prompt Creating table I_PURCHASEORDERHEADER
prompt ====================================
prompt
create table I_PURCHASEORDERHEADER
(
  purchaseordernumber  NUMBER not null,
  suppliernumber       NUMBER not null,
  businessunitcode     VARCHAR2(6) not null,
  stockroomcode        VARCHAR2(12),
  orderdate            DATE not null,
  requesteddate        DATE not null,
  status               NUMBER,
  ordertype            NUMBER not null,
  purchaseordertype    NUMBER not null,
  origin               NUMBER not null,
  priority             NUMBER not null,
  confirmeddate        DATE not null,
  customernumber       NUMBER,
  approvaldate         DATE,
  currencycode         VARCHAR2(3) not null,
  canceldate           DATE,
  orderamount          NUMBER(15,6) not null,
  remark               VARCHAR2(300),
  processedtoworkorder VARCHAR2(1) default 'N' not null,
  approvaluser         VARCHAR2(20),
  canceluser           VARCHAR2(20),
  orderuser            VARCHAR2(20),
  confirmeduser        VARCHAR2(20),
  exportuser           VARCHAR2(20),
  exportdate           DATE,
  exportbatchnumber    NUMBER
);
comment on column I_PURCHASEORDERHEADER.status
  is '5  = Waiting for approval
10 = New (approved)
20 = Send
25 = Confirmed
30 = Partly received
40 = Completed
50 = CancelledStatus
type PO (purchase order)';
comment on column I_PURCHASEORDERHEADER.ordertype
  is '0 = Manual / no AC / not applicable
1 = Personalized order
2 = Standard order';
comment on column I_PURCHASEORDERHEADER.purchaseordertype
  is '0 = External
1 = Internal';
comment on column I_PURCHASEORDERHEADER.origin
  is '1 = Purchase request
2 = Manual created
3 = Conversion
4 = Work order approval
5 = Work order status control';
comment on column I_PURCHASEORDERHEADER.priority
  is '1 = Replacement purchase order
2 = Others
3 = Direct orders';
comment on column I_PURCHASEORDERHEADER.exportbatchnumber
  is 'Will be used to fill the EXTERNAL ORACLE PO number!';
alter table I_PURCHASEORDERHEADER
  add constraint INDX_I_PURCHASEORDERHEADER primary key (PURCHASEORDERNUMBER);
alter table I_PURCHASEORDERHEADER
  add constraint CHK_I_PURCHASEORDERHEAD_OI
  check (ORIGIN between 1 and 5);
alter table I_PURCHASEORDERHEADER
  add constraint CHK_I_PURCHASEORDERHEAD_OR
  check (ORDERTYPE IN (0,1,2));
alter table I_PURCHASEORDERHEADER
  add constraint CHK_I_PURCHASEORDERHEAD_OT
  check (PURCHASEORDERTYPE IN (0,1));
alter table I_PURCHASEORDERHEADER
  add constraint CHK_I_PURCHASEORDERHEAD_PR
  check (PRIORITY in (1,2,3));
alter table I_PURCHASEORDERHEADER
  add constraint CHK_I_PURCHASEORDERHEAD_ST
  check (STATUS IN (5, 10, 20, 25, 30, 40, 50));
alter table I_PURCHASEORDERHEADER
  add constraint CHK_I_PURCHASEORDERHEAD_WO
  check (PROCESSEDTOWORKORDER IN ('Y','N'));

prompt
prompt Creating table I_PURCHASEORDERLINE
prompt ==================================
prompt
create table I_PURCHASEORDERLINE
(
  purchaseordernumber NUMBER not null,
  productcode         VARCHAR2(12) not null,
  sizecode            VARCHAR2(12) not null,
  requestedgrade      VARCHAR2(1) not null,
  quantityordered     NUMBER,
  quantitycancelled   NUMBER,
  quantityconfirmed   NUMBER,
  purchaseprice       NUMBER(15,6),
  confirmeddate       DATE,
  remark              VARCHAR2(300),
  uniqueitem          VARCHAR2(1) default 'N' not null
);
comment on column I_PURCHASEORDERLINE.productcode
  is 'Link to product code';
comment on column I_PURCHASEORDERLINE.sizecode
  is 'Link to size code';
comment on column I_PURCHASEORDERLINE.requestedgrade
  is 'Link to qualitygrade code';
alter table I_PURCHASEORDERLINE
  add constraint INDX_I_PURCHASEORDERLINE primary key (PURCHASEORDERNUMBER, PRODUCTCODE, SIZECODE, REQUESTEDGRADE);
alter table I_PURCHASEORDERLINE
  add constraint FK_I_PURCHASEORDERLINE foreign key (PURCHASEORDERNUMBER)
  references I_PURCHASEORDERHEADER (PURCHASEORDERNUMBER) on delete cascade;  
ALTER TABLE I_PURCHASEORDERLINE
  ADD CONSTRAINT CHK_I_PURCHASEORDLINE_PRODCODE
  CHECK (PRODUCTCODE = UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_PURCHASEORDERLINE
  ADD CONSTRAINT CHK_I_PURCHASEORDLINE_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_PURCHASEORDERLINE ADD CONSTRAINT CHK_I_PURCHASEORDERLINE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE))); 

prompt
prompt Creating table I_RESIDENTIALPLPC
prompt ================================
prompt
create table I_RESIDENTIALPLPC
(
  customernumber               NUMBER not null,
  productcode                  VARCHAR2(12) not null,
  typeofmerchandise            NUMBER default 5,
  sizecode                     VARCHAR2(12) not null,
  finishingmethodcode          VARCHAR2(6) default '-' not null,
  dateactive                   DATE default TRUNC(SYSDATE)-1,
  dateinactive                 DATE default TO_DATE('31-12-2099','DD-MM-YYYY'),
  codeuniquely                 VARCHAR2(1) default 'N',
  customcode                   VARCHAR2(12),
  customdescription            VARCHAR2(30),
  washpricestartdate           DATE,
  washpricenew                 NUMBER(15,6),
  washpriceold                 NUMBER(15,6),
  comes_from_i_residentialitem NUMBER default 0 not null,
  budgetusage                  NUMBER default 0 not null,
  budgetcode                   VARCHAR2(6),
  selfpayment                  NUMBER default 1 not null,
  discountpercentagewash       NUMBER(15,2)
);
comment on column I_RESIDENTIALPLPC.customernumber
  is 'Must exist in I_CUSTOMER';
comment on column I_RESIDENTIALPLPC.productcode
  is 'Must exist in I_PRODUCT met Typeofmerchandise=5';
comment on column I_RESIDENTIALPLPC.typeofmerchandise
  is 'Type of merchandise is always 5';
comment on column I_RESIDENTIALPLPC.customcode
  is 'Product code used by customer';
comment on column I_RESIDENTIALPLPC.customdescription
  is 'Description used by customer';
comment on column I_RESIDENTIALPLPC.comes_from_i_residentialitem
  is '0=from this table i_residentialplpc OR 1=from i_uniqueresitem';
comment on column I_RESIDENTIALPLPC.budgetusage
  is '(Only for module  textilecontrolling) 0 = Not in Budget 1 = Self paid, not in Budget 2 = In Budget';
comment on column I_RESIDENTIALPLPC.budgetcode
  is '(Only for module  textilecontrolling) Optional link to I_CUSTOMERBUDGETDEFINITION';
comment on column I_RESIDENTIALPLPC.selfpayment
  is '1 = Customer Pays (default value), 2 = Client pays';
create index XINDX_I_RESIDENTIALPLPC_CUST on I_RESIDENTIALPLPC (CUSTOMERNUMBER);
create index XINDX_I_RESIDENTIALPLPC_PROD on I_RESIDENTIALPLPC (PRODUCTCODE, TYPEOFMERCHANDISE);
alter table I_RESIDENTIALPLPC
  add constraint XPK_I_RESIDENTIALPLPC primary key (CUSTOMERNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_RESIDENTIALPLPC
  add constraint FK_I_RESIDENTIALPLPC_BUDGET foreign key (CUSTOMERNUMBER, BUDGETCODE)
  references I_CUSTOMERBUDGETDEFINITION (CUSTOMERNUMBER, BUDGETCODE);
alter table I_RESIDENTIALPLPC
  add constraint FK_I_RESIDENTIALPLPC_CUSTOMER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_RESIDENTIALPLPC
  add constraint FK_I_RESIDENTIALPLPC_PRODUCT foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_RESIDENTIALPLPC
  add constraint CHK_I_RESIPLPC_BUDGETUSAGE
  check (BUDGETUSAGE in (0,1,2));
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_DATECHECK
  check (DATEINACTIVE >= DATEACTIVE);
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_FINMETHOD
  check (FINISHINGMETHODCODE=upper(trim(FINISHINGMETHODCODE)));
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_PRODCHECK
  check (productcode = upper(rtrim(ltrim(productcode))));
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_SELFPAYM
  check (SELFPAYMENT in (1,2));
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_SIZECHECK
  check (sizecode = upper(rtrim(ltrim(sizecode))));
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_UNIQUELY
  check (CODEUNIQUELY IN ('Y','N'));
alter table I_RESIDENTIALPLPC
  add constraint X_I_RESIDENTIALPLPC_WSHDATECHK
  check (NVL(WASHPRICESTARTDATE, TO_DATE('31-12-2099','DD-MM-YYYY')) >= DATEACTIVE);

prompt
prompt Creating table I_SCAN
prompt =====================
prompt
create table I_SCAN
(
  scandate     NUMBER(8) not null,
  scantime     VARCHAR2(6) not null,
  barcode      VARCHAR2(24) not null,
  plantcode    VARCHAR2(6) not null,
  locationcode VARCHAR2(6) not null,
  nextlocation VARCHAR2(6),
  statusout    NUMBER,
  processed_yn VARCHAR2(1) default 'N' not null
);
comment on column I_SCAN.scandate
  is 'IN->YYYYMMDD e.g. 20110509';
comment on column I_SCAN.scantime
  is 'IN->HH24MISS e.g. 142359 for 14:23:59';
comment on column I_SCAN.barcode
  is 'IN->Primary ID or barcode/chipcode etc';
comment on column I_SCAN.plantcode
  is 'IN->Plant code';
comment on column I_SCAN.locationcode
  is 'IN->Location, for example in- or out-scan location from table sortingimportdefinition';
comment on column I_SCAN.nextlocation
  is 'IN->Next location, default empty (NULL) optionally used';
comment on column I_SCAN.statusout
  is 'OUT->Status out from sendtrackinfo';
comment on column I_SCAN.processed_yn
  is 'PROCESS->record processed by sendtrackinfo';
create index INDX_I_SCAN_1 on I_SCAN (PROCESSED_YN);
alter table I_SCAN
  add constraint PK_I_SCAN primary key (SCANDATE, SCANTIME, BARCODE);
alter table I_SCAN
  add constraint CHK_I_SCAN_PROCESSED_YN
  check (PROCESSED_YN in ('N','Y'));

prompt
prompt Creating table I_WEARER
prompt =======================
prompt
create table I_WEARER
(
  CUSTOMERNUMBER            NUMBER NOT NULL,
  WEARERNUMBER              NUMBER NOT NULL,
  WEAREREMPLOYMENTNUMBER    NUMBER DEFAULT 1 NOT NULL,
  FULLNAME                  VARCHAR2(40) NOT NULL,
  SEARCHNAME                VARCHAR2(20) NOT NULL,
  EMBLEMNAME                VARCHAR2(40),
  CUSTOMEREMPLOYEENUMBER    VARCHAR2(10),
  SEX                       VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DUMMYFORPOOL              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DATEACTIVE                DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  DATEINACTIVE              DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  REMARK                    VARCHAR2(300),
  WEARERFUNCTIONCODE        VARCHAR2(6),
  WEARERFUNCTIONDESCRIPTION VARCHAR2(30),
  FLAGCODE                  VARCHAR2(6),
  FLAGDESCRIPTION           VARCHAR2(50),
  LOCKERBANK                VARCHAR2(6),
  LOCKER                    VARCHAR2(6),
  PRICESTARTDATE            DATE,
  PRICE                     NUMBER(15,6),
  WEARERPRICE               VARCHAR2(1) DEFAULT 'N' NOT NULL,
  DISPENSECREDIT            NUMBER DEFAULT 0 NOT NULL,
  GARMENTDISPENSERDESC      VARCHAR2(30),
  GARMENTDISPENSERCODE      VARCHAR2(6),
  DEPARTMENTNUMBER          NUMBER(6),
  LOCKERSORTADDRESS         VARCHAR2(6),
  FIRSTNAME                 VARCHAR2(24),
  EMPLOYMENTFLAGCODE        VARCHAR2(6),
  EMPLOYMENTFLAGDESCRIPTION VARCHAR2(50),
  DELIVERYPOINTNUMBER       VARCHAR2(12) DEFAULT '1' NOT NULL,
  DELIVERYPOINTDESCRIPTION  VARCHAR2(30) DEFAULT '-' NOT NULL,
  EMBROIDERYLETTERINGLINE1  VARCHAR2(35),
  EMBROIDERYLETTERINGLINE2  VARCHAR2(35),
  EMBROIDERYLETTERINGLINE3  VARCHAR2(35),
  LOCKERSORTGROUPNUMBER     NUMBER(3),
  LOCKERSORTGROUPDESCR      VARCHAR2(30),
  EXTERNALLOCKERBANK        VARCHAR2(6),
  EXTERNALLOCKER            VARCHAR2(6),
  CONSUMPTIONPOINTNUMBER    NUMBER(2),
  KEYCOMBINATION            VARCHAR2(20),
  EMBLEMNAMELINE2           VARCHAR2(40)
);
comment on column I_WEARER.EXTERNALLOCKERBANK
  is 'Optional external locker. Remark only possible for customer of maincustomer type = 3 and links to a maincustomer type = 2 locker';
comment on column I_WEARER.CONSUMPTIONPOINTNUMBER
  is 'Optional consumptionpoint number, if it is empty the first consumptionpoint of the department is taken';
comment on column I_WEARER.EMBLEMNAMELINE2
IS '2nd emblem name line, optional, so may be left empty. 
May only be filled when EMBLEMNAME is not null';
create index XIE1I_WEARER on I_WEARER (DATEACTIVE);
create index XIE2I_WEARER on I_WEARER (DATEINACTIVE);
create index XIF4026I_WEARER on I_WEARER (CUSTOMERNUMBER);
alter table I_WEARER
  add constraint XPKI_WEARER primary key (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
alter table I_WEARER
  add constraint I_WEARER_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_WEARER
  add constraint CHK_I_WEARER
  check ((LOCKER is not null and GARMENTDISPENSERCODE is null) or
         (LOCKER is null and GARMENTDISPENSERCODE is not null) or
         (LOCKER is null and GARMENTDISPENSERCODE is null));
alter table I_WEARER
  add constraint CHK_I_WEARER_DATES
  check (dateinactive >= dateactive);
alter table I_WEARER
  add constraint CHK_I_WEARER_DELIVERYPOINT
  check (DELIVERYPOINTNUMBER = TRIM(UPPER(DELIVERYPOINTNUMBER)));
alter table I_WEARER
  add constraint CHK_I_WEARER_EXTLOCKER
  check ((LOCKER IS NULL AND EXTERNALLOCKER IS NOT NULL) OR (EXTERNALLOCKER IS NULL));
alter table I_WEARER
  add constraint CHK_I_WEARER_SEX
  check (SEX IN ('F','M','X','T','I','S','U','N'));
alter table I_WEARER
  add constraint I_WEAREREMPLOYMENT
  check (weareremploymentnumber between 1 and 5);
alter table I_WEARER
  add constraint I_WEARERFUNCTIONCODE
  check ((WEARERFUNCTIONCODE is null) or
(WEARERFUNCTIONCODE = upper(rtrim(ltrim(WEARERFUNCTIONCODE)))));
alter table I_WEARER
  add constraint YN_VALIDATION100
  check (WEARERPRICE IN ('Y', 'N'));
alter table I_WEARER
  add constraint YN_VALIDATION101
  check (DUMMYFORPOOL IN ('Y', 'N'));

prompt
prompt Creating table I_UNIQUEITEM
prompt ===========================
prompt
create table I_UNIQUEITEM
(
  BUSINESSUNIT             VARCHAR2(6) NOT NULL,
  PRIMARYID                VARCHAR2(24) NOT NULL,
  IDCODESEQUENCENUMBER     NUMBER DEFAULT 1 NOT NULL,
  SECONDARYID              VARCHAR2(24),
  STATUS                   NUMBER NOT NULL,
  STAY                     NUMBER NOT NULL,
  CUSTOMERNUMBER           NUMBER,
  WEARERNUMBER             NUMBER,
  WEAREREMPLOYMENTNUMBER   NUMBER,
  PRODUCTCODE              VARCHAR2(12) NOT NULL,
  SIZECODE                 VARCHAR2(12) NOT NULL,
  FINISHINGMETHODCODE      VARCHAR2(6) DEFAULT '-',
  GARMENTSEQUENCENUMBER    NUMBER,
  WASHESTOTAL              NUMBER DEFAULT 0 NOT NULL,
  REPAIRTOTAL              NUMBER DEFAULT 0 NOT NULL,
  REWASHESTOTAL            NUMBER DEFAULT 0 NOT NULL,
  WASHESTHISISSUE          NUMBER,
  REPAIRTHISISSUE          NUMBER,
  REWASHESTHISISSUE        NUMBER,
  CUSTOMEROWNED            VARCHAR2(1) DEFAULT 'N' NOT NULL,
  RELATEDCUSTOMERNUMBER    NUMBER,
  DELIVERFROMSTOCK         VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  LASTINSCANDATE           DATE,
  STARTRENTFROM            NUMBER DEFAULT 2 NOT NULL,
  LASTOUTSCANDATE          DATE,
  LASTSCANDATE             DATE,
  STATUSCHANGEDATE         DATE,
  STAYCHANGEDATE           DATE,
  PURCHASEDATE             DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  NUMBEROFISSUES           NUMBER DEFAULT 1 NOT NULL,
  FIRSTISSUEDATE           DATE,
  LASTISSUEDATE            DATE,
  ENDDATEFULLRENT          DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY'),
  DAYSINCIRCPREVISSUE      NUMBER DEFAULT 0 NOT NULL,
  DAYSINSTOCKPREVISSUE     NUMBER DEFAULT 0 NOT NULL,
  SUPPLIERNUMBER           NUMBER DEFAULT 1 NOT NULL,
  PURCHASEPRICE            NUMBER(15,6) DEFAULT 0 NOT NULL,
  CURRENCYCODE             VARCHAR2(3) NOT NULL,
  QUALITYGRADECODE         VARCHAR2(1),
  FREEEXTRAGARMENTS        VARCHAR2(1) DEFAULT 'N',
  ENDDATEFREEEXTRA         DATE,
  MODIFICATIONCODE1        VARCHAR2(10),
  MODIFICATIONDESCRIPTION1 VARCHAR2(40),
  MODIFICATIONCODE2        VARCHAR2(10),
  MODIFICATIONDESCRIPTION2 VARCHAR2(40),
  MODIFICATIONCODE3        VARCHAR2(10),
  REASONCODE               VARCHAR2(6),
  MODIFICATIONDESCRIPTION3 VARCHAR2(40),
  FLAGCODE                 VARCHAR2(6),
  FLAGDESCRIPTION          VARCHAR2(50),
  FLAGSTARTDATE            DATE,
  FLAGFREETEXT             VARCHAR2(40),
  REMARK                   VARCHAR2(30),
  STOCKROOMCODE            VARCHAR2(12),
  LOCATIONCODE             VARCHAR2(12),
  ROWCODE                  VARCHAR2(12),
  POOLITEM                 NUMBER DEFAULT 2 NOT NULL,
  LEASEWEEKS               NUMBER,
  RESIDUALVALUEAMOUNT      NUMBER(15,6),
  REPLACEMENTPRICE         NUMBER(15,6),
  SECTION                  VARCHAR2(10),
  LOCATION                 VARCHAR2(10),
  CONSUMPTIONPOINTNUMBER   NUMBER(2),
  TYPEOFMERCHANDISE        NUMBER DEFAULT 2 NOT NULL,
  STOCKROOMAREACODE        VARCHAR2(12),
  EMBLEMTEMPLATE           VARCHAR2(6),
  LASTDELIVERYNOTENUMBER   NUMBER
);
comment on column I_UNIQUEITEM.STATUS
  is '10 Stock
20 In Circulation
30 Assigned (assigned to be in circ in future)
40 Ragged';
comment on column I_UNIQUEITEM.STAY
  is '10  In Stockroom
11  STOCKROOM/PICKED
20  Outscan/At Customer
22  Clean in Garment Dispenser
23  Desk Scan/Issue to Wearer
24  Out of Garment Dispenser
25  Soiled in Garment Dispenser
26  OUTSCAN/TRANSFER STOCK
27  On-site at Customer
28  Sent to Laundry
30  In Scan/Soiled Received
31  Rewash
32  Repair/Mending
33  Checkpoint/Inspection
34  Sorted
35  OR Packing
36  Late Piece
37  Deposit Stock
38  Treatment
39  Bundle Scan
40  ON SHELF';
comment on column I_UNIQUEITEM.STARTRENTFROM
  is '2 = Moment of delivery  (outscan)
3 = Moment of taking in use (inscan or desk issue, dispenser issue)
4 = Specific future date (date stored in issue date)
5 = Requested delivery date  (date stored in issue date)';
comment on column I_UNIQUEITEM.POOLITEM
  is '0 = Stock
1 = Pool
2 = Non Pool
3 = OR Pack';
comment on column I_UNIQUEITEM.TYPEOFMERCHANDISE
  is 'TYPEOFMERCHANDISE Can 1 or 2, DEFAULT=2, 1=FOR POOL';
comment on column I_UNIQUEITEM.STOCKROOMAREACODE
  is 'This areacode together with stockroom-,row- and location-code determines the stockroomlocation';
comment on column I_UNIQUEITEM.EMBLEMTEMPLATE
  is 'Optional emblem template, that must exist';  
create index XIF1I_UNIQUEITEM on I_UNIQUEITEM (CUSTOMERNUMBER);
create index XIF2I_UNIQUEITEM on I_UNIQUEITEM (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
create index XIF3I_UNIQUEITEM on I_UNIQUEITEM (PRODUCTCODE);
create index XIF4I_UNIQUEITEM on I_UNIQUEITEM (BUSINESSUNIT);
create index XIF5I_UNIQUEITEM on I_UNIQUEITEM (STOCKROOMCODE);
create index XIF6I_UNIQUEITEM on I_UNIQUEITEM (SECONDARYID);
alter table I_UNIQUEITEM
  add constraint PK_I_UNIQUEITEM primary key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_UNIQUEITEM
  add constraint FK_I_UNIQUEITEM_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_UNIQUEITEM
  add constraint FK_I_UNIQUEITEM_STOCKROOM foreign key (STOCKROOMCODE)
  references STOCKROOM (CODE);
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_CURRENCY foreign key (CURRENCYCODE)
  references CURRENCY (CODE);
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_PRODUCTCODETOM foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_WEARER foreign key (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER)
  references I_WEARER (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
alter table I_UNIQUEITEM
  add constraint CHECK_POOLCOMBINATION
  check ((POOLITEM = 0 and STATUS = 10) or POOLITEM <> 0);
alter table I_UNIQUEITEM
  add constraint CHK_I_UNIQUEITEM_ISSUEDATES
  check ((POOLITEM = 3) or
(FIRSTISSUEDATE is not null and LASTISSUEDATE is not null and FIRSTISSUEDATE <= LASTISSUEDATE) or
(FIRSTISSUEDATE is null and LASTISSUEDATE is null and status <> '20'));
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_BU
  check (BUSINESSUNIT=UPPER(TRIM(BUSINESSUNIT)));
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_CUSTRELATED
  check ((customerowned = 'N') or (customerowned = 'Y' and relatedcustomernumber is not null));
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_POOLITEM
  check (POOLITEM IN (0,1,2,3));
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_SIZECHECK
  check (sizecode = upper(trim(sizecode)));
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_STAR
  check (sizecode <> '*');
alter table I_UNIQUEITEM
  add constraint I_UNIQUEITEM_TYPEOFMERCHANDISE
  check (TYPEOFMERCHANDISE=2 OR (TYPEOFMERCHANDISE=1 AND POOLITEM=1) or poolitem in (0, 3));
alter table I_UNIQUEITEM
  add constraint I_UNIQUESTOCKCHECK
  check ((status = 10 and stockroomcode is not null and rowcode is not null and locationcode is not null) or status <> 10);
alter table I_UNIQUEITEM
  add constraint STARTRENTFROM_VALIDATION
  check (startrentfrom in (0,2,3,4,5));
alter table I_UNIQUEITEM
  add constraint UNIQUESTATUS_VALIDATION
  check (((status IN (10,20) and startrentfrom = 0) or (status = 30 and startrentfrom in (2,3,4,5)) or (POOLITEM in (1,3)) or (status='40')));
alter table I_UNIQUEITEM
  add constraint UNIQUESTAY_VALIDATION
  check (stay between 10 and 99);
alter table I_UNIQUEITEM
  add constraint YN_VALIDATION3114
  check (CUSTOMEROWNED IN ('Y', 'N'));
alter table I_UNIQUEITEM
  add constraint YN_VALIDATION3115
  check (DELIVERFROMSTOCK IN ('Y', 'N'));
alter table I_UNIQUEITEM
  add constraint YN_VALIDATION3116
  check (FREEEXTRAGARMENTS IN ('Y', 'N'));
alter table I_UNIQUEITEM
  add constraint CHK_I_UNIQUEITEM_FINMETHOD
  check (FINISHINGMETHODCODE=upper(trim(FINISHINGMETHODCODE)));
ALTER TABLE I_UNIQUEITEM ADD CONSTRAINT CHK_I_UNIQUEITEM_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_UNIQUEITEM
  ADD CONSTRAINT CHK_I_UNIQUEITEM_WEARER
  CHECK ((WEARERNUMBER IS NOT NULL AND WEAREREMPLOYMENTNUMBER IS NOT NULL) or (WEARERNUMBER IS NULL AND WEAREREMPLOYMENTNUMBER IS NULL)); 

prompt
prompt Creating table I_SCANHISTORY
prompt ============================
prompt
CREATE TABLE I_SCANHISTORY
(
  SCANDATETIME         DATE NOT NULL,
  BUSINESSUNIT         VARCHAR2(6) NOT NULL,
  PRIMARYID            VARCHAR2(24) NOT NULL,
  IDCODESEQUENCENUMBER NUMBER DEFAULT 1 NOT NULL,
  IN_OUT_SCAN          NUMBER NOT NULL,
  SCANSTATION          VARCHAR2(12) DEFAULT 'CONVERSION',
  DELIVERYNOTENUMBER   NUMBER,
  PROCESSED_YN         VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CUSTOMERNUMBER       NUMBER,
  WEARERNUMBER         NUMBER,
  DEPARTMENTNUMBER     NUMBER,
  PRODUCTCODE          VARCHAR2(24),
  SIZECODE             VARCHAR2(24),
  STAYNR               NUMBER,
  STATUSCODE           VARCHAR2(2),
  ISSUEDATE            DATE,
  REASONCODE           VARCHAR2(6),
  YEAR                 NUMBER,
  WEEK                 NUMBER,
  DAYNO                NUMBER,
  BATCHNUMBER	       VARCHAR2(24)
);
comment on column I_SCANHISTORY.scandatetime
  is 'Scan date time (Oracle date)';
comment on column I_SCANHISTORY.businessunit
  is 'Linked to the Primary ID';
comment on column I_SCANHISTORY.primaryid
  is 'Barcode or Primary ID or barcode/chipcode etc';
comment on column I_SCANHISTORY.idcodesequencenumber
  is 'Linked to the Primary ID default value 1';
comment on column I_SCANHISTORY.in_out_scan
  is '1=Inscan 2=Outscan 3=Repairscan 4=RewashScan 75=OnsitesoilScan(PDA) and 76=On-siteInventoryScan';
comment on column I_SCANHISTORY.scanstation
  is 'Optional work station code';
comment on column I_SCANHISTORY.deliverynotenumber
  is 'In case of an outscan can be filled with the delivery note number. (Default null)';  
comment on column I_SCANHISTORY.processed_yn
  is 'Indicate if import record has been processed, to prevent duplicate import errors, not part of the import definition';
create index INDX_I_SCANHIST_PROCESS_YN on I_SCANHISTORY (PROCESSED_YN);
create index INDX_I_SCANHISTORY_BU ON I_SCANHISTORY (BUSINESSUNIT);
alter table I_SCANHISTORY
  add constraint PK_I_SCANHISTORY primary key (SCANDATETIME, BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_SCANHISTORY
  add constraint FK_I_SCANHISTORY_IDCODE foreign key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  references I_UNIQUEITEM (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_SCANHISTORY
  add constraint CHK_I_SCANHISTORY_IN_OUT
  check (IN_OUT_SCAN IN (1,2,3,4,75,76));
alter table I_SCANHISTORY
  add constraint CHK_I_SCANHISTORY_PROCESSED
  check (PROCESSED_YN IN ('N','Y', 'E'));

prompt
prompt Creating table I_CONTRACTPURCHASEORDERLINE
prompt ==========================================
prompt  
create table I_CONTRACTPURCHASEORDERLINE
(
  CONTRACTCODE           VARCHAR2(15) NOT NULL,
  PURCHASEORDERNUMBER    VARCHAR2(40) NOT NULL,
  LINENUMBER             NUMBER NOT NULL,
  CUSTOMERNUMBER         NUMBER NOT NULL,
  PRODUCTCODE            VARCHAR2(6) NOT NULL,
  SIZECODE               VARCHAR2(6) NOT NULL,
  FINISHINGMETHOD        VARCHAR2(6),
  WEARERNUMBER           NUMBER,
  WEAREREMPLOYMENTNUMBER NUMBER DEFAULT 1,
  QUANTITY               NUMBER,
  PRICE                  NUMBER
);
create index INDX_I_CONTRACTPOLINE on I_CONTRACTPURCHASEORDERLINE (CONTRACTCODE, PURCHASEORDERNUMBER);
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint FK_I_CNTRPOLINE_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint FK_I_CNTRPOLINE_HEADER foreign key (CONTRACTCODE, PURCHASEORDERNUMBER)
  references I_CONTRACTPURCHASEORDER (CONTRACTCODE, PURCHASEORDERNUMBER);
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint FK_I_CNTRPOLINE_PROD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint FK_I_CNTRPOLINE_WEARER foreign key (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER)
  references I_WEARER (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint CHK_I_CONTRACTPOLINE_PRODUCT
  check (PRODUCTCODE is null OR PRODUCTCODE = upper(trim(PRODUCTCODE)));  
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint CHK_I_CONTRACTPOLINE_SIZE
  check (SIZECODE is null or SIZECODE = upper(trim(SIZECODE)));  
alter table I_CONTRACTPURCHASEORDERLINE
  add constraint CHK_I_CONTRACTPOLINE_FM
  check (FINISHINGMETHOD is null or FINISHINGMETHOD = upper(trim(FINISHINGMETHOD)));    

prompt
prompt Creating table I_SOILREASONABILITY
prompt ==================================
prompt
create table I_SOILREASONABILITY
(
  businessunitnumber  VARCHAR2(6) not null,
  customernumber      NUMBER not null,
  productcode         VARCHAR2(12) not null,
  sizecode            VARCHAR2(12) not null,
  finishingmethodcode VARCHAR2(6) not null,
  daynumber           NUMBER not null,
  pickupqty           NUMBER,
  soilticketnumber    NUMBER not null,
  pickupdate          DATE not null,
  inventoryqty        NUMBER not null,
  pickupqty1          NUMBER,
  pickupqty2          NUMBER,
  pickupqty3          NUMBER,
  pickupqty4          NUMBER,
  pickupqty5          NUMBER,
  pickupqty6          NUMBER,
  pickupqty7          NUMBER,
  pickupqty8          NUMBER,
  pickupqty9          NUMBER,
  pickupqty10         NUMBER,
  pickupqty11         NUMBER,
  pickupqty12         NUMBER,
  pickupqty13         NUMBER
);
create index XIF1I_SOILREASONABILITY on I_SOILREASONABILITY (CUSTOMERNUMBER);
create index XIF2I_SOILREASONABILITY on I_SOILREASONABILITY (PRODUCTCODE, SIZECODE);
create index INDX_I_SOILREASONABILITY_BU ON I_SOILREASONABILITY (businessunitnumber);
alter table I_SOILREASONABILITY
  add constraint FK_I_SOILREASONABILITY_BU foreign key (BUSINESSUNITNUMBER)
  references BUSINESSUNIT (CODE);
alter table I_SOILREASONABILITY
  add constraint I_SOILREASONABILITY_CUSTOMERNU foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_SOILREASONABILITY
  add constraint I_SOILREASONABILITY_PRODUCTCOD foreign key (PRODUCTCODE, SIZECODE)
  references I_PRODUCTSIZE (PRODUCTCODE, SIZECODE);
alter table I_SOILREASONABILITY
  add constraint I_SOILREASONABILITY_BU
  check (TRIM(UPPER(BUSINESSUNITNUMBER))=BUSINESSUNITNUMBER);
ALTER TABLE I_SOILREASONABILITY
  ADD CONSTRAINT CHK_I_SOILREASABILITY_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE))); 
alter table I_SOILREASONABILITY
  add constraint CHK_I_SOILREASABILITY_FINM
  check (FINISHINGMETHODCODE=upper(trim(FINISHINGMETHODCODE)));  
ALTER TABLE I_SOILREASONABILITY ADD CONSTRAINT CHK_I_SOILREASONABILITY_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));

prompt
prompt Creating table I_SOILTICKET
prompt ===========================
prompt
create table I_SOILTICKET
(
  soilticketnumber   NUMBER not null,
  businessunitnumber VARCHAR2(6) not null,
  customernumber     NUMBER not null,
  routenumber        NUMBER not null,
  stopnumber         NUMBER,
  invoicenumber      NUMBER,
  documenttype       NUMBER,
  invoicedate        DATE not null,
  countdate          DATE,
  importdate         DATE,
  exportdate         DATE
);
comment on column I_SOILTICKET.documenttype
  is '1=Invoice, 2=Statement';
create index XIF1I_SOILTICKET on I_SOILTICKET (CUSTOMERNUMBER);
create index XIF2I_SOILTICKET on I_SOILTICKET (INVOICENUMBER, DOCUMENTTYPE);
create index INDX_I_SOILTICKET_BU ON I_SOILTICKET (businessunitnumber);
alter table I_SOILTICKET
  add constraint XPKI_SOILTICKET primary key (SOILTICKETNUMBER);
alter table I_SOILTICKET
  add constraint FK_I_SOILTICKET_BU foreign key (BUSINESSUNITNUMBER)
  references BUSINESSUNIT (CODE);
alter table I_SOILTICKET
  add constraint I_SOILTICKET_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_SOILTICKET
  add constraint I_SOILTICKET_INVOICENUMBER____ foreign key (INVOICENUMBER, DOCUMENTTYPE)
  references I_INVOICEHEADER (INVOICENUMBER, DOCUMENTTYPE);
alter table I_SOILTICKET
  add constraint I_SOILTICKET_BU
  check (TRIM(UPPER(BUSINESSUNITNUMBER))=BUSINESSUNITNUMBER);

prompt
prompt Creating table I_SOILTICKETLINE
prompt ===============================
prompt
create table I_SOILTICKETLINE
(
  soilticketnumber    NUMBER not null,
  productcode         VARCHAR2(12) not null,
  sizecode            VARCHAR2(12) not null,
  finishingmethodcode VARCHAR2(6) not null,
  countkeypad         NUMBER,
  countlightframe     NUMBER,
  countconverted      NUMBER,
  countabused         NUMBER not null,
  soilweight          NUMBER(15,6) not null,
  inventory           NUMBER not null,
  invoicelinenumver   NUMBER not null
);
create index XIF1I_SOILTICKETLINE on I_SOILTICKETLINE (SOILTICKETNUMBER);
create index XIF2I_SOILTICKETLINE on I_SOILTICKETLINE (PRODUCTCODE);
alter table I_SOILTICKETLINE
  add constraint XPKI_SOILTICKETLINE primary key (SOILTICKETNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
alter table I_SOILTICKETLINE
  add constraint I_SOILTICKETLINE_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_SOILTICKETLINE
  add constraint I_SOILTICKETLINE_SOILTICKETNUM foreign key (SOILTICKETNUMBER)
  references I_SOILTICKET (SOILTICKETNUMBER);
alter table I_SOILTICKETLINE
  add constraint CHK_I_SOILTICKETLINE_SIZESTAR
  check (SIZECODE <> '*');
ALTER TABLE I_SOILTICKETLINE
  ADD CONSTRAINT CHK_I_SOILTICKETLINE_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_SOILTICKETLINE
  ADD CONSTRAINT CHK_I_SOILTICKETLINE_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_SOILTICKETLINE ADD CONSTRAINT CHK_I_SOILTICKETLINE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_SPECIALCHARGEPERPRODUCT
prompt ========================================
prompt
create table I_SPECIALCHARGEPERPRODUCT
(
  productcode         VARCHAR2(12) not null,
  specialchargecode   VARCHAR2(6) not null,
  finishingmethodcode VARCHAR2(6) not null
);
create unique index XAK1I_SPECIALCHARGEPERPRODUCT on I_SPECIALCHARGEPERPRODUCT (PRODUCTCODE, FINISHINGMETHODCODE, SPECIALCHARGECODE);
create index XIF2I_SPECIALCHARGEPERPRODUCT on I_SPECIALCHARGEPERPRODUCT (PRODUCTCODE);
alter table I_SPECIALCHARGEPERPRODUCT
  add constraint I_SPECIALCHARGEPERPRODUCT_PROD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_SPECIALCHARGEPERPRODUCT
  add constraint CHK_I_SPECIALCHARGEPPROD_FINM
  check (FINISHINGMETHODCODE=upper(trim(FINISHINGMETHODCODE))); 
ALTER TABLE I_SPECIALCHARGEPERPRODUCT ADD CONSTRAINT CHK_I_SPECIALCHARGEPERP_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_SPECIALCHARGESPERCUSTOMER
prompt ==========================================
prompt
create table I_SPECIALCHARGESPERCUSTOMER
(
  customernumber           NUMBER not null,
  specialchargecode        VARCHAR2(6) not null,
  specialchargedescription VARCHAR2(40) not null,
  specialchargeamount      NUMBER(15,6),
  specialchargepercentage  NUMBER(15,2),
  startdate                DATE default TRUNC(SYSDATE)-1 not null,
  frequency                NUMBER not null,
  minimumamount            NUMBER(15,6),
  maximumamount            NUMBER(15,6),
  overruled                VARCHAR2(1) default 'Y' not null
);
comment on column I_SPECIALCHARGESPERCUSTOMER.frequency
  is '1 = Weekly
2 = Every Delivery
3 = Every Invoice
4 = Every direct invoice only
5 = Per Delivered Piece
6 = Every Printed (finalized) Delivery Note
7 = Every Normal Visit
8 = Every Special Visit
9 = Every active wearer for every invoice
10 = Per Registered Weight';
comment on column I_SPECIALCHARGESPERCUSTOMER.minimumamount
  is 'only applicable in case of percentage,
and frequency = 3
if used the calculated amount to be charged
will be adjusted to these min and max amounts when outside these limits.';
comment on column I_SPECIALCHARGESPERCUSTOMER.maximumamount
  is 'only applicable in case of percentage,
and frequency = 3
if used the calculated amount to be charged
will be adjusted to these min and max amounts when outside these limits.';
comment on column I_SPECIALCHARGESPERCUSTOMER.overruled
  is 'Customer specific Y/N, default Y';
alter table I_SPECIALCHARGESPERCUSTOMER
  add constraint XPKI_SPECIALCHARGESPERCUSTOMER primary key (CUSTOMERNUMBER, SPECIALCHARGECODE);
alter table I_SPECIALCHARGESPERCUSTOMER
  add constraint I_SPECIALCHARGESPERCUSTOMER_CU foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_SPECIALCHARGESPERCUSTOMER
  add constraint I_CUSTSPECIALCHARGEFREQ
  check (FREQUENCY between 1 and 10);

prompt
prompt Creating table I_STANDARDINVENTORY
prompt ==================================
prompt
create table I_STANDARDINVENTORY
(
  CUSTOMERNUMBER      NUMBER NOT NULL,
  PRODUCTCODE         VARCHAR2(12) NOT NULL,
  FUNCTIONCODE        VARCHAR2(6) NOT NULL,
  FUNCTIONDESCRIPTION VARCHAR2(30) NOT NULL,
  TEMPLATECODE        VARCHAR2(6),
  MAXINVENTORY        NUMBER DEFAULT 1 NOT NULL,
  CHANGESPERWEEK      NUMBER DEFAULT 1 NOT NULL,
  TYPEOFMERCHANDISE   NUMBER DEFAULT 2 NOT NULL
);
comment on column I_STANDARDINVENTORY.maxinventory
  is 'MAXINVENTORY = PUTINUSE >= 1';
comment on column I_STANDARDINVENTORY.changesperweek
  is 'CHANGESPERWEEK >= 1';
comment on column I_STANDARDINVENTORY.typeofmerchandise
  is 'Always TOM; 2=Garments';
create index INDX_I_STANDARDINVENTORY on I_STANDARDINVENTORY (CUSTOMERNUMBER, TEMPLATECODE, PRODUCTCODE);
alter table I_STANDARDINVENTORY
  add constraint PK_I_STANDARDINVENTORY primary key (CUSTOMERNUMBER, FUNCTIONCODE, PRODUCTCODE);
alter table I_STANDARDINVENTORY
  add constraint FK_I_STANDARDINVENTORY_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_STANDARDINVENTORY
  add constraint FK_I_STANDARDINVENTORY_PROD foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE) on delete cascade;
alter table I_STANDARDINVENTORY
  add constraint CHK_I_STANDARDINV_CHANGESPERWK
  check (CHANGESPERWEEK >= 1);
alter table I_STANDARDINVENTORY
  add constraint CHK_I_STANDARDINV_MAXINVENTORY
  check (MAXINVENTORY >= 1);
ALTER TABLE I_STANDARDINVENTORY ADD CONSTRAINT CHK_I_STANDARDINVENTORY_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_STDLOCATIONPERPRODUCTSIZE
prompt ==========================================
prompt
create table I_STDLOCATIONPERPRODUCTSIZE
(
  stockroomcode     VARCHAR2(12) not null,
  rowcode           VARCHAR2(12),
  locationcode      VARCHAR2(12) not null,
  areacode          VARCHAR2(12),
  productcode       VARCHAR2(12) not null,
  priority          NUMBER default 1 not null,
  customerowned     VARCHAR2(1) default 'N' not null,
  customernumber    NUMBER,
  allowedgrade      VARCHAR2(1) default 'B' not null,
  standardtruckload NUMBER default 0 not null,
  sizecode          VARCHAR2(12)
);
comment on column I_STDLOCATIONPERPRODUCTSIZE.areacode
  is 'Optional area code that determines the stockroomlocation with stockroom-, row- and location-code';
comment on column I_STDLOCATIONPERPRODUCTSIZE.allowedgrade
  is 'N = only new allowed
U = only used allowed
B = both new and used allowed
D = only defect items
Default B';
comment on column I_STDLOCATIONPERPRODUCTSIZE.standardtruckload
  is 'Standard quantity per location. Default value 0. This attribute will only be used for locations of type ?Service? (Truck).';
comment on column I_STDLOCATIONPERPRODUCTSIZE.sizecode
  is 'Optional location per size, when used per product, then allways use the size for that given product';
create unique index PK_I_STDLOCATIONPERPRODUCTSIZE on I_STDLOCATIONPERPRODUCTSIZE (STOCKROOMCODE, ROWCODE, LOCATIONCODE, AREACODE, PRODUCTCODE, SIZECODE);
alter table I_STDLOCATIONPERPRODUCTSIZE
  add constraint FK_I_STDLOCPPRODSIZE_STCKROOM foreign key (STOCKROOMCODE)
  references STOCKROOM (CODE) on delete cascade;
alter table I_STDLOCATIONPERPRODUCTSIZE
  add constraint FK_I_STDLOCPPRODSIZE_PRODU foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_STDLOCATIONPERPRODUCTSIZE
  add constraint CHK_I_STDLOCPERPRODSIZE_GRADE
  check (ALLOWEDGRADE IN ('B','N','U','D'));
alter table I_STDLOCATIONPERPRODUCTSIZE
  add constraint CHK_I_STDLOCPERPRODSIZE_OWN
  check (CUSTOMEROWNED IN ('Y','N'));
ALTER TABLE I_STDLOCATIONPERPRODUCTSIZE
  ADD CONSTRAINT CHK_I_STDLOCPRPRDSIZE_PRODCODE
  CHECK (PRODUCTCODE = UPPER(TRIM(PRODUCTCODE)));  
ALTER TABLE I_STDLOCATIONPERPRODUCTSIZE
  ADD CONSTRAINT CHK_I_STDLOCPRPRDSIZE_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE))); 

prompt
prompt Creating table I_STOCKCOUNTSCHEDULE
prompt ===================================
prompt
create table I_STOCKCOUNTSCHEDULE
(
  CUSTOMERNUMBER           NUMBER NOT NULL,
  STOCKCOUNTSCHEDULECODE   VARCHAR2(6) NOT NULL,
  STOCKCOUNTSCHEDULEDESC   VARCHAR2(30),
  PACKONCOUNTDAY           VARCHAR2(1) DEFAULT 'N',
  REPLENISHMENTTYPE        NUMBER DEFAULT 0,
  DELIVERYDAYDETERMINATION NUMBER DEFAULT 0
);
comment on column I_STOCKCOUNTSCHEDULE.PACKONCOUNTDAY
  is '''Y'' or ''N''';
comment on column I_STOCKCOUNTSCHEDULE.REPLENISHMENTTYPE
  is '0 = Stock Count / Ordering 1 = Reallocation';
comment on column I_STOCKCOUNTSCHEDULE.DELIVERYDAYDETERMINATION
  is '0 = Determine automatically 1 = Define manually Only applicable in case of ReplenishmentType = 0 (Stock Count / Ordering)';
alter table I_STOCKCOUNTSCHEDULE
  add constraint PK_I_STOCKCOUNTSCHEDULE primary key (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE);
alter table I_STOCKCOUNTSCHEDULE
  add constraint CHK_I_DELIVERYDAYDETERMINATION
  check (DELIVERYDAYDETERMINATION IN (0,1));
alter table I_STOCKCOUNTSCHEDULE
  add constraint CHK_I_PACKONCOUNTDAY
  check (PACKONCOUNTDAY IN ('N','Y'));
alter table I_STOCKCOUNTSCHEDULE
  add constraint CHK_I_REPLENISHMENTTYPE
  check (REPLENISHMENTTYPE IN (0,1));

prompt
prompt Creating table I_STOCKCOUNTSCHEDULEDAY
prompt ======================================
prompt
create table I_STOCKCOUNTSCHEDULEDAY
(
  CUSTOMERNUMBER         NUMBER NOT NULL,
  STOCKCOUNTSCHEDULECODE VARCHAR2(6) NOT NULL,
  DAY                    NUMBER(1) NOT NULL,
  DELIVERYDAY            NUMBER(1),
  ORDERINGDEADLINE       DATE DEFAULT TO_DATE('12:00:00','HH24:MI:SS'),
  COMPULSORYORDERDAY     NUMBER(1) DEFAULT 0
);
comment on column I_STOCKCOUNTSCHEDULEDAY.ORDERINGDEADLINE
  is 'Only the time is stored';
comment on column I_STOCKCOUNTSCHEDULEDAY.COMPULSORYORDERDAY
  is '0 = Optional Order Day or not applicable 1 = Compulsory Order Day';  
alter table I_STOCKCOUNTSCHEDULEDAY
  add constraint PK_I_STOCKCOUNTSCHEDULEDAY primary key (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE, DAY);
alter table I_STOCKCOUNTSCHEDULEDAY
  add constraint FK_I_STOCKCOUNTSCHEDULEDAY foreign key (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE)
  references I_STOCKCOUNTSCHEDULE (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE) on delete cascade;
alter table I_STOCKCOUNTSCHEDULEDAY
  add constraint CHK_I_STOCKCOUNTSCH_DELDAY
  check (DELIVERYDAY IN (1,2,3,4,5,6,7));
alter table I_STOCKCOUNTSCHEDULEDAY
  add constraint CHK_I_STOCKCOUNTSCHEDULE_DAY
  check (DAY IN (1,2,3,4,5,6,7));
alter table I_STOCKCOUNTSCHEDULEDAY
  add constraint CHK_I_STOCKCOUNTSCHED_COMDAY
  check (COMPULSORYORDERDAY IN (0,1));

prompt
prompt Creating table I_STOCKCOUNTSCHEDULEDIST
prompt =======================================
prompt
create table I_STOCKCOUNTSCHEDULEDIST
(
  customernumber         NUMBER not null,
  stockcountschedulecode VARCHAR2(6) not null,
  departmentnumber       NUMBER(6) not null,
  consumptionpointnumber NUMBER(2) not null,
  countsequence          NUMBER
);
comment on column I_STOCKCOUNTSCHEDULEDIST.countsequence
  is 'Sequence number the distribution point is intended to be processed within schedule';
alter table I_STOCKCOUNTSCHEDULEDIST
  add constraint PK_I_STOCKCOUNTSCHEDULEDIST primary key (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_STOCKCOUNTSCHEDULEDIST
  add constraint UI_I_STOCKCOUNTSCHEDULEDIST unique (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE, COUNTSEQUENCE);
alter table I_STOCKCOUNTSCHEDULEDIST
  add constraint FK_I_STOCKCOUNTSCHEDULEDIST foreign key (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE)
  references I_STOCKCOUNTSCHEDULE (CUSTOMERNUMBER, STOCKCOUNTSCHEDULECODE) on delete cascade;

prompt
prompt Creating table I_STOCKDEFINITIONPERITEM
prompt =======================================
prompt
create table I_STOCKDEFINITIONPERITEM
(
  stockroomcode         VARCHAR2(12) not null,
  productcode           VARCHAR2(12) not null,
  sizecode              VARCHAR2(12) not null,
  customernumber        NUMBER,
  customerowned         VARCHAR2(1) default 'N' not null,
  minqtynew             NUMBER(8) default 0 not null,
  minqtyused            NUMBER(8) default 0 not null,
  maxqtynew             NUMBER(8) default 9999 not null,
  maxqtyused            NUMBER(8) default 9999 not null,
  defaultsuppliernumber NUMBER(8) not null
);
alter table I_STOCKDEFINITIONPERITEM
  add constraint UK2I_STOCKDEFINITIONPERITEM unique (STOCKROOMCODE, PRODUCTCODE, SIZECODE, CUSTOMERNUMBER, CUSTOMEROWNED);
alter table I_STOCKDEFINITIONPERITEM
  add constraint FKI_STOCKDEFPERITEM_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_STOCKDEFINITIONPERITEM
  add constraint FKI_STOCKDEFPERITEM_PROD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_STOCKDEFINITIONPERITEM
  add constraint CHKI_STOCKDEFIPERITEM_SIZESTAR
  check (SIZECODE <> '*');
alter table I_STOCKDEFINITIONPERITEM
  add constraint CHKI_STOCKDEFPERITEMCUSTOWNED
  check (CUSTOMEROWNED IN ('Y','N'));
alter table I_STOCKDEFINITIONPERITEM
  add constraint CHKI_STOCKDEFPERITEMMAXQTYNEW
  check (MAXQTYNEW BETWEEN 0 AND 99999999);
alter table I_STOCKDEFINITIONPERITEM
  add constraint CHKI_STOCKDEFPERITEMMAXQTYUSED
  check (MAXQTYUSED BETWEEN 0 AND 99999999);
alter table I_STOCKDEFINITIONPERITEM
  add constraint CHKI_STOCKDEFPERITEMMINQTYNEW
  check (MINQTYNEW BETWEEN 0 AND 99999999);
alter table I_STOCKDEFINITIONPERITEM
  add constraint CHKI_STOCKDEFPERITEMMINQTYUSED
  check (MINQTYUSED BETWEEN 0 AND 99999999);
ALTER TABLE I_STOCKDEFINITIONPERITEM
  ADD CONSTRAINT CHK_I_STOCKDEFPERITEM_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_STOCKDEFINITIONPERITEM ADD CONSTRAINT CHK_I_STOCKDEFINITIONPE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_STOCKROOMLOCATION
prompt ==================================
prompt  
create table I_STOCKROOMLOCATION
(
  STOCKROOMCODE               VARCHAR2(12) NOT NULL,
  ROWCODE                     VARCHAR2(12),
  LOCATIONCODE                VARCHAR2(12) NOT NULL,
  AREACODE                    VARCHAR2(12),
  PICKINGSEQUENCE             NUMBER DEFAULT 0,
  VOLUME                      NUMBER DEFAULT 9999,
  UNIQUEID                    VARCHAR2(38),
  MAKEEMPTY                   VARCHAR2(1) DEFAULT 'N',
  OVERFLOWLOCATION            VARCHAR2(1) DEFAULT 'N',
  STANDARDCHECKINLOCATION     VARCHAR2(1) DEFAULT 'N',
  STANDARDPREWASHLOCATION     VARCHAR2(1) DEFAULT 'N',
  STANDARDWMSOVERFLOWLOCATION VARCHAR2(1) DEFAULT 'N'
);
comment on column I_STOCKROOMLOCATION.STANDARDCHECKINLOCATION
  is 'This attribute indicates if this location is the standard check-in location for the stockroom it belongs to.';
comment on column I_STOCKROOMLOCATION.STANDARDPREWASHLOCATION
  is 'This attribute indicates if this location is the standard prewash location for the stockroom it belongs to.';
comment on column I_STOCKROOMLOCATION.STANDARDWMSOVERFLOWLOCATION
  is 'This attribute indicates if this location is the standard WMS overflow location for the stockroom it belongs to.';
create unique index XAK1I_STOCKROOMLOCATION on I_STOCKROOMLOCATION (STOCKROOMCODE, ROWCODE, LOCATIONCODE, AREACODE);
alter table I_STOCKROOMLOCATION
  add constraint I_STOCKROOMLOCATION_STOCKROOM foreign key (STOCKROOMCODE) references STOCKROOM (CODE);
alter table I_STOCKROOMLOCATION
  add constraint YN_I_MAKEEMPTY
  check (MAKEEMPTY IN ('Y', 'N'));
alter table I_STOCKROOMLOCATION
  add constraint YN_I_OVERFLOWLOCATION
  check (OVERFLOWLOCATION IN ('Y', 'N'));
alter table I_STOCKROOMLOCATION
  add constraint YN_I_STANDARDCHECKINLOCATION
  check (STANDARDCHECKINLOCATION IN ('Y', 'N'));
alter table I_STOCKROOMLOCATION
  add constraint YN_I_STANDARDPREWASHLOCATION
  check (STANDARDPREWASHLOCATION IN ('Y', 'N'));
alter table I_STOCKROOMLOCATION
  add constraint YN_I_STANDARDWMSOVERFLOWLOCAT
  check (STANDARDWMSOVERFLOWLOCATION IN ('Y', 'N'));    

prompt
prompt Creating table I_STOCKROOMQUANTITY
prompt ==================================
prompt
create table I_STOCKROOMQUANTITY
(
  STOCKROOMCODE       VARCHAR2(12) NOT NULL,
  ROWCODE             VARCHAR2(12) ,
  LOCATIONCODE        VARCHAR2(12) NOT NULL,
  AREACODE            VARCHAR2(12),
  CUSTOMERNUMBER      NUMBER,
  PRODUCTCODE         VARCHAR2(12) NOT NULL,
  SIZECODE            VARCHAR2(12) NOT NULL,
  CUSTOMEROWNED       VARCHAR2(1) NOT NULL,
  QUANTITYNONUNIQUE   NUMBER NOT NULL,
  SUPPLIERNUMBER      NUMBER NOT NULL,
  QUALITYGRADECODE    VARCHAR2(1),
  PICKINGSEQUENCE     NUMBER DEFAULT 0 NOT NULL,
  VOLUME              NUMBER DEFAULT 0 NOT NULL,
  AVGPURCHASEPRICE    NUMBER(15,6),
  STOCKVALUE_CURRENCY VARCHAR2(3)
);
create unique index XAK1I_STOCKROOMQUANTITY on I_STOCKROOMQUANTITY (STOCKROOMCODE, ROWCODE, LOCATIONCODE, AREACODE, PRODUCTCODE, SIZECODE, CUSTOMERNUMBER, CUSTOMEROWNED, QUALITYGRADECODE);
create index XIF1I_STOCKROOMQUANTITY on I_STOCKROOMQUANTITY (CUSTOMERNUMBER);
create index XIF2I_STOCKROOMQUANTITY on I_STOCKROOMQUANTITY (PRODUCTCODE);
create index XIF3I_STOCKROOMQUANTITY on I_STOCKROOMQUANTITY (STOCKVALUE_CURRENCY);
alter table I_STOCKROOMQUANTITY
  add constraint I_STOCKROOMQUANTITY_CUSTOMERNU foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_STOCKROOMQUANTITY
  add constraint I_STOCKROOMQUANTITY_PRODUCTCOD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_STOCKROOMQUANTITY
  add constraint I_STOCKROOMQUANTITY_STOCKROOM foreign key (STOCKROOMCODE)
  references STOCKROOM (CODE);
alter table I_STOCKROOMQUANTITY
  add constraint I_STOCKVALUE_CURRENCY foreign key (STOCKVALUE_CURRENCY)
  references CURRENCY (CODE);
alter table I_STOCKROOMQUANTITY
  add constraint YN_VALIDATION105
  check (CUSTOMEROWNED IN ('Y', 'N'));
alter table I_STOCKROOMQUANTITY
  add constraint CHK_STOCKVALUE_CURRENCY
  check ((AVGPURCHASEPRICE IS NULL) or (AVGPURCHASEPRICE IS NOT NULL AND STOCKVALUE_CURRENCY IS NOT NULL));
ALTER TABLE I_STOCKROOMQUANTITY
  ADD CONSTRAINT CHK_I_STOCKROOMQUANT_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_STOCKROOMQUANTITY ADD CONSTRAINT CHK_I_STOCKROOMQUANTITY_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_SUPPLIER
prompt =========================
prompt
create table I_SUPPLIER
(
  SUPPLIERNUMBER       NUMBER NOT NULL,
  NAME                 VARCHAR2(40) NOT NULL,
  SUPPLIERTYPE         NUMBER DEFAULT 0 NOT NULL,
  PHONE                VARCHAR2(30),
  FAX                  VARCHAR2(30),
  EMAIL                VARCHAR2(40),
  WEBSITE              VARCHAR2(40),
  STREET               VARCHAR2(40),
  STREET2              VARCHAR2(40),
  ZIPCODE              VARCHAR2(15),
  CITY                 VARCHAR2(30) NOT NULL,
  COUNTRY              VARCHAR2(3) NOT NULL,
  CURRENCYCODE         VARCHAR2(3) NOT NULL,
  AVERAGESHIPMENTCOSTS NUMBER DEFAULT 0,
  SENDPURCHASEORDER    NUMBER DEFAULT 0 NOT NULL,
  PRINTPRICEONPO       VARCHAR2(1),
  ORDERFORMREMARK      VARCHAR2(80),
  PAYMENTTERMS         VARCHAR2(80),
  DELIVERYTERMS        VARCHAR2(80),
  DATEACTIVE           DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  DATEINACTIVE         DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  STATE                VARCHAR2(20),
  LANGUAGECODE         VARCHAR2(5),
  STREET3              VARCHAR2(40)
);
comment on column I_SUPPLIER.SUPPLIERTYPE
  is '0 = External, 1 = Internal (stockroom)';
comment on column I_SUPPLIER.AVERAGESHIPMENTCOSTS
  is 'Default 0';
comment on column I_SUPPLIER.SENDPURCHASEORDER
  is '0 = By regular mail(default)
2 = By e-mail
5 = Electronic data transfer only';
comment on column I_SUPPLIER.LANGUAGECODE
  is 'Optional Language code in ISO format e.g. EN_US for English (United States), remark language code must exist!';
alter table I_SUPPLIER
  add constraint PK_I_SUPPLIER primary key (SUPPLIERNUMBER);
create index INDX_I_SUPPLIER_LANGUAGE on I_SUPPLIER (LANGUAGECODE);
alter table I_SUPPLIER
  add constraint FK_I_SUPPLIER_COUNTRY foreign key (COUNTRY)
  references COUNTRY (CODE) on delete cascade;
alter table I_SUPPLIER
  add constraint FK_I_SUPPLIER_CURRENCY foreign key (CURRENCYCODE)
  references CURRENCY (CODE) on delete cascade;
alter table I_SUPPLIER
  add constraint FK_I_SUPPLIER_LANGUAGE foreign key (LANGUAGECODE)
  references LANGUAGES(CODE) on delete cascade;
alter table I_SUPPLIER
  add constraint CHK_I_SUPPLIER_SENDPURCHASEO
  check (SENDPURCHASEORDER in (0,2,5));
alter table I_SUPPLIER
  add constraint CHK_I_SUPPLIER_TYPE
  check (SUPPLIERTYPE in (0,1));

prompt
prompt Creating table I_SUPPLIERPRODUCT
prompt ================================
prompt
create table I_SUPPLIERPRODUCT
(
  suppliernumber                 NUMBER not null,
  supplierproductcode            VARCHAR2(30) not null,
  supplierproductdescription     VARCHAR2(50),
  suppliersizecode               VARCHAR2(20) default '-' not null,
  laundryproductcode             VARCHAR2(12) default '-' not null,
  laundrysizecode                VARCHAR2(12) default '-' not null,
  supplierproductprice           NUMBER,
  deliverydays                   NUMBER default 1 not null,
  minorderqty                    NUMBER default 1 not null,
  boxquantity                    NUMBER default 1 not null,
  uniqueitem                     VARCHAR2(1) default 'N' not null,
  remark                         VARCHAR2(300),
  active                         VARCHAR2(1) default 'Y' not null,
  supplierproductprice_startdate DATE default to_date('1-1-2000', 'dd-mm-yyyy') not null
);
create index XIE1I_SUPPLIERPRODUCT on I_SUPPLIERPRODUCT (LAUNDRYPRODUCTCODE, LAUNDRYSIZECODE);
alter table I_SUPPLIERPRODUCT
  add constraint XPKI_SUPPLIERPRODUCT primary key (SUPPLIERNUMBER, SUPPLIERPRODUCTCODE, SUPPLIERSIZECODE, LAUNDRYPRODUCTCODE, LAUNDRYSIZECODE);
alter table I_SUPPLIERPRODUCT
  add constraint I_SUPPLIERPRODUCT_LAUNDRYPRODU foreign key (LAUNDRYPRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_SUPPLIERPRODUCT
  add constraint GREATERTHANZERO7
  check (DELIVERYDAYS >= 1);
alter table I_SUPPLIERPRODUCT
  add constraint GREATERTHANZERO8
  check (MINORDERQTY >= 1);
alter table I_SUPPLIERPRODUCT
  add constraint GREATERTHANZERO9
  check (BOXQUANTITY >= 1);
alter table I_SUPPLIERPRODUCT
  add constraint YN_VALIDATION8074
  check (UNIQUEITEM IN ('Y', 'N'));
alter table I_SUPPLIERPRODUCT
  add constraint YN_VALIDATION8075
  check (ACTIVE IN ('Y', 'N'));
ALTER TABLE I_SUPPLIERPRODUCT
  ADD CONSTRAINT CHK_I_SUPPRODUCT_SIZECODE
  CHECK (LAUNDRYSIZECODE = UPPER(TRIM(LAUNDRYSIZECODE)));  

prompt
prompt Creating table I_TAXAUTHORITIES
prompt ===============================
prompt
create table I_TAXAUTHORITIES
(
  LINETYPE         NUMBER NOT NULL,
  STATECODE        VARCHAR2(6) NOT NULL,
  STATENAME        VARCHAR2(20) NOT NULL,
  CITYCOUNTYNAME   VARCHAR2(30) DEFAULT '-' NOT NULL,
  TAXAUTHORITYCODE VARCHAR2(12) NOT NULL,
  TAXRATE          NUMBER(7,3) NOT NULL,
  COUNTRY          VARCHAR2(3)
);
comment on column I_TAXAUTHORITIES.LINETYPE
  is '1=State2=City3=County(If not known if it is a city or county choose 2, City)Note: a city and county records should always be preceded by the State-record of the state they are located in.';
comment on column I_TAXAUTHORITIES.CITYCOUNTYNAME
  is 'Empty if  TYPE=1 ElseCITY or COUNTY name';
comment on column I_TAXAUTHORITIES.COUNTRY
  is 'Must be an existing country code';  
alter table I_TAXAUTHORITIES
  add constraint XPKI_TAXAUTHORITIES primary key (LINETYPE, STATECODE, CITYCOUNTYNAME);
alter table I_TAXAUTHORITIES
  add constraint FK_I_TAXAUTHORITIES_COUNTRY foreign key (COUNTRY)
  references COUNTRY (CODE);  
alter table I_TAXAUTHORITIES
  add constraint LINETYPE_VALIDATION
  check (linetype IN (1, 2, 3));

prompt
prompt Creating table I_TAXDEFINITION
prompt ==============================
prompt
create table I_TAXDEFINITION
(
  statecode    VARCHAR2(6) not null,
  taxgroupcode VARCHAR2(6) not null
);
alter table I_TAXDEFINITION
  add constraint XPKI_TAXDEFINITION primary key (STATECODE, TAXGROUPCODE);

prompt
prompt Creating table I_TEMPORARYDELIVERYSTOP
prompt ======================================
prompt
create table I_TEMPORARYDELIVERYSTOP
(
  customernumber         NUMBER not null,
  departmentnumber       NUMBER(6) not null,
  consumptionpointnumber NUMBER not null,
  productcode            VARCHAR2(12) not null,
  sizecode               VARCHAR2(12) not null,
  finishingmethodcode    VARCHAR2(6) default '-' not null,
  seasontypecode         VARCHAR2(6),
  seasoncode             VARCHAR2(6),
  dateactive             DATE default TRUNC(SYSDATE)-1 not null,
  dateinactive           DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null,
  deliveryschemecode     VARCHAR2(6) not null,
  tempstopstartyear      NUMBER(4),
  tempstopstartyearweek  NUMBER(2),
  tempstopendyear        NUMBER(4),
  tempstopendyearweek    NUMBER(2),
  tempstopyearrent       VARCHAR2(1) default 'N' not null,
  tempstopstartweek      NUMBER(2),
  tempstopendweek        NUMBER(2),
  tempstopreturnweek     NUMBER(2),
  tempstopweekrent       VARCHAR2(1) default 'N' not null,
  startdate              DATE,
  enddate                DATE,
  tempstoprentfordate    VARCHAR2(1) default 'N'
);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint PKI_TEMPORARYDELIVERYSTOP unique (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, DATEACTIVE, DELIVERYSCHEMECODE, SEASONTYPECODE, SEASONCODE, TEMPSTOPSTARTYEAR, TEMPSTOPSTARTYEARWEEK, TEMPSTOPENDYEAR, TEMPSTOPENDYEARWEEK, TEMPSTOPSTARTWEEK, TEMPSTOPENDWEEK, TEMPSTOPRETURNWEEK, ENDDATE, STARTDATE);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint FKI_TEMPORARYDELIVERYSTOP foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, DATEACTIVE, DELIVERYSCHEMECODE, SEASONTYPECODE, SEASONCODE)
  references I_DELIVERYSTANDARDS (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE, DATEACTIVE, DELIVERYSCHEMECODE, SEASONTYPECODE, SEASONCODE);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint CHK_I_TEMPORARYDELSTOP_TSRFD
  check (TEMPSTOPRENTFORDATE  IN ('Y', 'N'));
alter table I_TEMPORARYDELIVERYSTOP
  add constraint CHK_TEMPSTOPENDWEEK
  check (TEMPSTOPENDWEEK is null or TEMPSTOPENDWEEK between 1 and 53);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint CHK_TEMPSTOPENDYEARWEEK
  check (TEMPSTOPENDYEARWEEK is null or TEMPSTOPENDYEARWEEK between 1 and 53);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint CHK_TEMPSTOPRETURNWEEK
  check (TEMPSTOPRETURNWEEK is null or TEMPSTOPRETURNWEEK between 1 and 53);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint CHK_TEMPSTOPSTARTWEEK
  check (TEMPSTOPSTARTWEEK is null or TEMPSTOPSTARTWEEK between 1 and 53);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint CHK_TEMPSTOPSTARTYEARWEEK
  check (TEMPSTOPSTARTYEARWEEK is null or TEMPSTOPSTARTYEARWEEK between 1 and 53);
alter table I_TEMPORARYDELIVERYSTOP
  add constraint YNI_TEMPSTOPWEEKRENT
  check (TEMPSTOPWEEKRENT IN ('Y','N'));
alter table I_TEMPORARYDELIVERYSTOP
  add constraint YNI_TEMPSTOPYEARRENT
  check (TEMPSTOPYEARRENT IN ('Y', 'N'));
ALTER TABLE I_TEMPORARYDELIVERYSTOP
  ADD CONSTRAINT CHK_I_TEMPDELSTOP_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE))); 
ALTER TABLE I_TEMPORARYDELIVERYSTOP
  ADD CONSTRAINT CHK_I_TEMPDELSTOP_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_TEMPORARYDELIVERYSTOP ADD CONSTRAINT CHK_I_TEMPORARYDELIVERY_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_TURNOVER_PLPC
prompt ==============================
prompt
create table I_TURNOVER_PLPC
(
  CUSTOMERNUMBER    NUMBER NOT NULL,
  PRODUCTCODE       VARCHAR2(12) NOT NULL,
  TURNOVERGROUPCODE VARCHAR2(12) NOT NULL,
  TURNOVERGROUPTYPE NUMBER DEFAULT 1 NOT NULL,
  PERCENTAGE        NUMBER(15,2) DEFAULT 100 NOT NULL,
  TAXGROUP          VARCHAR2(6)
);
comment on column I_TURNOVER_PLPC.turnovergrouptype
  is '1 = Rent
2 = Wash
3 = Replacement
4 = Sales
5 = Wash COG';
comment on column I_TURNOVER_PLPC.taxgroup
  is 'Optional Taxgroup.code for the turnovergroup';
alter table I_TURNOVER_PLPC
  add constraint PK_I_TURNOVER_PLPC primary key (CUSTOMERNUMBER, PRODUCTCODE, TURNOVERGROUPCODE, TURNOVERGROUPTYPE);
alter table I_TURNOVER_PLPC
  add constraint FK_I_TURNOVER_PLPC_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER) on delete cascade;
alter table I_TURNOVER_PLPC
  add constraint FK_I_TURNOVER_PLPC_PRODUCT foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE) on delete cascade;
alter table I_TURNOVER_PLPC
  add constraint CHK_I_TURNOVERPLPC_TYPE
  check (TURNOVERGROUPTYPE IN (1,2,3,4,5));
ALTER TABLE I_TURNOVER_PLPC ADD CONSTRAINT CHK_I_TURNOVER_PLPC_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));

prompt
prompt Creating table I_TURNOVERGROUP
prompt ==============================
prompt
create table I_TURNOVERGROUP
(
  TURNOVERGROUP_CODE        VARCHAR2(12) NOT NULL,
  TURNOVERGROUP_DESCRIPTION VARCHAR2(30),  
  TURNOVERGROUP_LEGACYCODE  VARCHAR2(6),
  ACTIVE                    VARCHAR2(1) DEFAULT 'Y',
  TAXGROUPCODE              VARCHAR2(6),
  SALESJOURNALGROUP_CODE    VARCHAR2(6),
  SALESJOURNALGROUP_DESC    VARCHAR2(30)
);
comment on column I_TURNOVERGROUP.TURNOVERGROUP_LEGACYCODE
  is 'Optional field';
comment on column I_TURNOVERGROUP.ACTIVE
  is 'Values Y or N default Y';
comment on column I_TURNOVERGROUP.TAXGROUPCODE
  is 'Optional TAX group code, if used it must exist';
comment on column I_TURNOVERGROUP.SALESJOURNALGROUP_CODE
  is 'Will be created if it does not exist';
alter table I_TURNOVERGROUP
  add constraint PK_I_TURNOVERGROUP primary key (TURNOVERGROUP_CODE);
alter table I_TURNOVERGROUP
  add constraint CHK_I_TURNOVERGROUP_ACTIVE
  check (ACTIVE IN ('Y', 'N')); 
alter table I_TURNOVERGROUP
  add constraint CHK_I_TURNOVERGROUP_CODE
  check (TURNOVERGROUP_CODE = UPPER(TRIM(TURNOVERGROUP_CODE)));
alter table I_TURNOVERGROUP
  add constraint CHK_I_TURNOVERGROUP_SALESJOURG
  check (SALESJOURNALGROUP_CODE = UPPER(TRIM(SALESJOURNALGROUP_CODE)));  

prompt
prompt Creating table I_UNIQUEITEMFLAGS
prompt ================================
prompt
create table I_UNIQUEITEMFLAGS
(
  businessunit             VARCHAR2(6) not null,
  primaryid                VARCHAR2(24) not null,
  idcodesequencenumber     NUMBER default 1 not null,
  flagcode                 VARCHAR2(6) not null,
  flagdescription          VARCHAR2(50) not null,
  flagstartdate            DATE default TRUNC(SYSDATE)-1 not null,
  flagfreetext             VARCHAR2(40),
  treatmentcheckschemecode VARCHAR2(6)
);
create index INDX_I_UNIQUEITEMFLAGS_BU ON I_UNIQUEITEMFLAGS (businessunit);
alter table I_UNIQUEITEMFLAGS
  add constraint PK_I_UNIQUEITEMFLAGS primary key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER, FLAGCODE);
alter table I_UNIQUEITEMFLAGS
  add constraint FK_I_UNIQUEITEMFLAGS foreign key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  references I_UNIQUEITEM (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);

prompt
prompt Creating table I_UNIQUEPOOL
prompt ===========================
prompt
create table I_UNIQUEPOOL
(
  businessunit           VARCHAR2(6) not null,
  primaryid              VARCHAR2(24) not null,
  idcodesequencenumber   NUMBER default 1 not null,
  secondaryid            VARCHAR2(24),
  status                 NUMBER default 20 not null,
  stay                   NUMBER not null,
  customernumber         NUMBER,
  departmentnumber       NUMBER(6),
  productcode            VARCHAR2(12) not null,
  sizecode               VARCHAR2(12) not null,
  finishingmethodcode    VARCHAR2(6) not null,
  washestotal            NUMBER not null,
  repairtotal            NUMBER not null,
  customerowned          VARCHAR2(1) not null,
  relatedcustomernumber  NUMBER,
  lastinscandate         DATE,
  lastoutscandate        DATE,
  lastscandate           DATE,
  statuschangedate       DATE,
  staychangedate         DATE,
  purchasedate           DATE not null,
  numberofissues         NUMBER not null,
  firstissuedate         DATE,
  lastissuedate          DATE,
  enddatefullrent        DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null,
  daysincircprevissue    NUMBER not null,
  daysinstockprevious    NUMBER not null,
  suppliernumber         NUMBER not null,
  purchaseprice          NUMBER(15,6) not null,
  currencycode           VARCHAR2(3) not null,
  remark                 VARCHAR2(30),
  reasoncode             VARCHAR2(6),
  leaseweeks             NUMBER,
  residualvalueamount    NUMBER(15,6),
  replacementprice       NUMBER(15,6),
  section                VARCHAR2(10),
  location               VARCHAR2(10),
  qualitygradecode       VARCHAR2(1),
  consumptionpointnumber NUMBER(2),
  poolitem               NUMBER default 1 not null,
  typeofmerchandise      NUMBER default 2 not null
);
comment on column I_UNIQUEPOOL.status
  is '20 In Circulation
30 Assigned (assigned to be in circ in future)';
comment on column I_UNIQUEPOOL.stay
  is '10=In Stockroom   (only for status 30) ? 20=Outscan /At Customer?
21=Clean in Garment Dispenser? 22=Desk Scan/Issue to wearer? 23=Soiled in Garment Dispenser? 24-29=User defined?
30=In Scan / Soil Received?
31=Rewash?
32=Repair / Mending?
33=Checkpoint / Inspection?
34=Sorted?
35=OR Packing?
36=Late Piece?
36-99=User defined';
comment on column I_UNIQUEPOOL.poolitem
  is '1 = Pool, 3 = OR Pack';
comment on column I_UNIQUEPOOL.typeofmerchandise
  is 'TYPEOFMERCHANDISE Can be 1 or 2 only';
create unique index XAK1I_UNIQUEPOOL on I_UNIQUEPOOL (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
create index XIF1I_UNIQUEPOOL on I_UNIQUEPOOL (CUSTOMERNUMBER);
create index XIF2I_UNIQUEPOOL on I_UNIQUEPOOL (PRODUCTCODE);
create index XIF3I_UNIQUEPOOL on I_UNIQUEPOOL (CUSTOMERNUMBER, DEPARTMENTNUMBER);
create index INDX_I_UNIQUEPOOL_BU ON I_UNIQUEPOOL (businessunit);
alter table I_UNIQUEPOOL
  add constraint PK_I_UNIQUEPOOL primary key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_UNIQUEPOOL
  add constraint FK_I_UNIQUEPOOL_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_PRODUCTCODE foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_UNIQUEPOOL
  add constraint I_UNQUEPOOL_ACTIVESTOCK foreign key (BUSINESSUNIT, SECTION, LOCATION)
  references I_ACTIVESTOCKLOCATION (BUSINESSUNIT, SECTION, LOCATION);
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_CURRENCY foreign key (CURRENCYCODE)
  references CURRENCY (CODE);  
alter table I_UNIQUEPOOL
  add constraint CHK_I_UNIQUEPOOL_ISSUEDATES
  check ((POOLITEM = 3) or
(FIRSTISSUEDATE is not null and LASTISSUEDATE is not null and FIRSTISSUEDATE <= LASTISSUEDATE) or
(FIRSTISSUEDATE is null and LASTISSUEDATE is null and status <> '20'));
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_BU
  check (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_POOLITEM
  check (POOLITEM in (1, 3));
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_RELATEDCUSTOMER
  check ((RELATEDCUSTOMERNUMBER is not null or (RELATEDCUSTOMERNUMBER is null  and CUSTOMERNUMBER is not null and DEPARTMENTNUMBER is not null)) or (STAY between 30 and 37) or (stay=10));
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_SIZECHECK
  check (sizecode = upper(trim(sizecode)));
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_STATUS_CHECK
  check ((POOLITEM=1 and status in ('20','30')) or (POOLITEM=3 and status in ('10','20','25','30','40','50','60','70')));
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_STAY_CHECK
  check (STAY BETWEEN 10 AND 99);
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_STAY_CUST_CHECK
  check (STAY <> 20 or (STAY = 20 and CUSTOMERNUMBER is not null and DEPARTMENTNUMBER is not null));
alter table I_UNIQUEPOOL
  add constraint I_UNIQUEPOOL_TYPEOFMERCHANDISE
  check (TYPEOFMERCHANDISE IN (1,2));
alter table I_UNIQUEPOOL
  add constraint YN_VALIDATION104
  check (CUSTOMEROWNED IN ('Y', 'N'));
ALTER TABLE I_UNIQUEPOOL
  ADD CONSTRAINT CHK_I_UNIQUEPOOL_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_UNIQUEPOOL ADD CONSTRAINT CHK_I_UNIQUEPOOL_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_UNIQUEITEMLOSS
prompt ===============================
prompt
CREATE TABLE I_UNIQUEITEMLOSS
(
  BUSINESSUNIT            VARCHAR2(6) NOT NULL,
  PRIMARYID               VARCHAR2(24) NOT NULL,
  IDCODESEQUENCENUMBER    NUMBER DEFAULT 1 NOT NULL,
  CUSTOMERNUMBER          NUMBER NOT NULL,
  DEPARTMENTNUMBER        NUMBER(6) NOT NULL,
  DISTRIBUTIONPOINTNUMBER NUMBER NOT NULL,
  PERIODYEAR              NUMBER(4),
  PERIOD                  NUMBER(2),
  OUTSCANDATE             DATE NOT NULL,
  LOSSAMOUNT              NUMBER(15,2) NOT NULL,
  LOSSSTATUS              NUMBER,
  RETURNEDDATE            DATE,
  LOSSINVOICENUMBER       NUMBER,
  CREDITINVOICENUMBER     NUMBER,
  CREDITAMOUNT            NUMBER(15,2),
  LOSSCHARGETRIGGER       NUMBER,
  LASTSCANDATE            DATE,
  LOSSCHARGEDATE          DATE,
  LASTDELIVERYDATE        DATE
);
alter table I_UNIQUEITEMLOSS
  add constraint PK_I_UNIQUEITEMLOSS primary key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
create index INDX_I_UNIQUEITEMLOSS_BU ON I_UNIQUEITEMLOSS (businessunit);
alter table I_UNIQUEITEMLOSS
  add constraint FK_I_UNIQUEITEMLOSS_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_UNIQUEITEMLOSS
  add constraint FK_I_UNIQUEITEMLOSS_CONSUM foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER, DISTRIBUTIONPOINTNUMBER)
  references I_CONSUMPTIONPOINT (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_UNIQUEITEMLOSS
  add constraint FK_I_UNIQUEITEMLOSS_PRIMARYID foreign key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  references I_UNIQUEPOOL (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_UNIQUEITEMLOSS
  add constraint CHK_I_UNIQUEITEMLOSS_PDYEAR
  check (PERIODYEAR between 1900 and 2099);
alter table I_UNIQUEITEMLOSS
  add constraint CHK_I_UNIQUEITEMLOSS_PERIOD
  check (PERIOD between 1 and 13);

prompt
prompt Creating table I_UNIQUEORPACK
prompt =============================
prompt
create table I_UNIQUEORPACK
(
  businessunit           VARCHAR2(6) not null,
  primaryid              VARCHAR2(24) not null,
  idcodesequencenumber   NUMBER default 1 not null,
  expirationdate         DATE default TO_DATE('31-12-2099','DD-MM-YYYY') not null,
  treatmenttype          VARCHAR2(12),
  stockexpirationdate    DATE,
  creationtimestamp      DATE default SYSDATE not null,
  creationemployeenumber NUMBER default 1 not null,
  assemblylayout         VARCHAR2(6),
  assembletimestamp      DATE,
  assembleemployeenumber NUMBER,
  loadtimestamp          DATE,
  loademployeenumber     NUMBER,
  deliverytimestamp      DATE,
  deliveryemployeenumber NUMBER,
  canceltimestamp        DATE,
  cancelemployeenumber   NUMBER,
  recalltimestamp        DATE,
  recallemployeenumber   NUMBER,
  reasoncode             VARCHAR2(6),
  typeofmerchandise      NUMBER default 2 not null
);
comment on column I_UNIQUEORPACK.businessunit
  is 'Must exist in the I_UNIQUEPOOL';
comment on column I_UNIQUEORPACK.primaryid
  is 'Must exist in the I_UNIQUEPOOL';
comment on column I_UNIQUEORPACK.idcodesequencenumber
  is 'Must exist in the I_UNIQUEPOOL';
comment on column I_UNIQUEORPACK.creationtimestamp
  is 'Date / time of creation';
comment on column I_UNIQUEORPACK.assembletimestamp
  is 'Date / time of assembly';
comment on column I_UNIQUEORPACK.loadtimestamp
  is 'Date / time of loading pack on cart';
comment on column I_UNIQUEORPACK.deliverytimestamp
  is 'Date / time of deliverynote';
comment on column I_UNIQUEORPACK.canceltimestamp
  is 'Date / time of canceling the pack';
comment on column I_UNIQUEORPACK.recalltimestamp
  is 'Date / time of recalling the pack';
comment on column I_UNIQUEORPACK.reasoncode
  is 'Reason code for canceling or recall';
CREATE INDEX INDX_I_UNIQUEORPACK_BU ON I_UNIQUEORPACK (BUSINESSUNIT);
alter table I_UNIQUEORPACK
  add constraint PK_I_UNIQUEORPACK primary key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_UNIQUEORPACK
  add constraint FK_I_UNIQUEORPACK foreign key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  references I_UNIQUEPOOL (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
alter table I_UNIQUEORPACK
  add constraint FK_I_UNIQUEORPACK_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);

prompt
prompt Creating table I_UNIQUEORPACKCONTENTS
prompt =====================================
prompt
create table I_UNIQUEORPACKCONTENTS
(
  businessunit           VARCHAR2(6) not null,
  primaryid              VARCHAR2(24) not null,
  idcodesequencenumber   NUMBER default 1 not null,
  packsequence           NUMBER(4),
  productcode            VARCHAR2(12) not null,
  sizedefinitioncode     VARCHAR2(12) not null,
  finishingmethod        VARCHAR2(6) default '-' not null,
  remark                 VARCHAR2(80),
  lotnumber              VARCHAR2(20),
  qtynonunique           NUMBER(4) default 0 not null,
  rownumber              NUMBER,
  positionnumber         NUMBER,
  contentbusinessunit    VARCHAR2(6),
  contentprimaryid       VARCHAR2(24),
  contentidcodeseqnumber NUMBER
);
comment on column I_UNIQUEORPACKCONTENTS.businessunit
  is 'Link to I_UNIQUEPOOL';
comment on column I_UNIQUEORPACKCONTENTS.contentbusinessunit
  is 'Optional content barcode';
comment on column I_UNIQUEORPACKCONTENTS.contentprimaryid
  is 'Optional content barcode';
comment on column I_UNIQUEORPACKCONTENTS.contentidcodeseqnumber
  is 'Optional content barcode';
CREATE INDEX INDX_I_UNIQUEORPACKCONTENTS_BU ON I_UNIQUEORPACKCONTENTS (BUSINESSUNIT);  
alter table I_UNIQUEORPACKCONTENTS
  add constraint PK_I_UNIQUEORPACKCONTENTS unique (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER, PACKSEQUENCE, ROWNUMBER, POSITIONNUMBER);
alter table I_UNIQUEORPACKCONTENTS
  add constraint FK_CONTENTBARCODE foreign key (CONTENTBUSINESSUNIT, CONTENTPRIMARYID, CONTENTIDCODESEQNUMBER)
  references I_UNIQUEPOOL (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER) on delete cascade;
alter table I_UNIQUEORPACKCONTENTS
  add constraint FK_I_UNIQUEORPACKCONTENTS foreign key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  references I_UNIQUEORPACK (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER) on delete cascade;
alter table I_UNIQUEORPACKCONTENTS
  add constraint FK_I_UNIQUEORPACKCONT_PROD foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_UNIQUEORPACKCONTENTS
  add constraint CHK_I_UNIQUEORPACKCONTENTS
  check (( (PACKSEQUENCE IS NULL AND ROWNUMBER IS NOT NULL AND POSITIONNUMBER IS NOT NULL) OR (PACKSEQUENCE IS NOT NULL AND ROWNUMBER IS NULL AND POSITIONNUMBER IS NULL) ));
alter table I_UNIQUEORPACKCONTENTS
  add constraint CHK_I_UNIQUEORPACKCONTENTSQTY
  check ((QTYNONUNIQUE=0 and
 CONTENTBUSINESSUNIT is not null and
 CONTENTPRIMARYID is not null and
 CONTENTIDCODESEQNUMBER is not null) or
(QTYNONUNIQUE>0 and
 CONTENTBUSINESSUNIT is null and
 CONTENTPRIMARYID is null and
 CONTENTIDCODESEQNUMBER is null));
ALTER TABLE I_UNIQUEORPACKCONTENTS
  ADD CONSTRAINT CHK_I_UNIQUEORPACKCONT_FINM
  CHECK (FINISHINGMETHOD=UPPER(TRIM(FINISHINGMETHOD)));
ALTER TABLE I_UNIQUEORPACKCONTENTS ADD CONSTRAINT CHK_I_UNIQUEORPACKCONTE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));  

prompt
prompt Creating table I_UNIQUEORSTERILE
prompt ================================
prompt
create table I_UNIQUEORSTERILE
(
  businessunit                VARCHAR2(6) not null,
  primaryid                   VARCHAR2(24) not null,
  idcodesequencenumber        NUMBER default 1 not null,
  chargenumber                VARCHAR2(15) not null,
  sterilizercode              VARCHAR2(6) not null,
  sterilizationtimestamp      DATE not null,
  sterilizationemployeenumber NUMBER not null,
  rejectionreasoncode         VARCHAR2(6),
  carttype                    VARCHAR2(6) not null,
  cartnumber                  NUMBER not null,
  rejectemployee              NUMBER,
  approvalemployeenumber      NUMBER
);
comment on column I_UNIQUEORSTERILE.businessunit
  is 'Must exist in I_UNIQUEORPACK';
comment on column I_UNIQUEORSTERILE.primaryid
  is 'Must exist in I_UNIQUEORPACK';
comment on column I_UNIQUEORSTERILE.idcodesequencenumber
  is 'Must exist in I_UNIQUEORPACK';
comment on column I_UNIQUEORSTERILE.chargenumber
  is 'Must be uppercase, and no spaces allowed CHK_I_UNIQUEORSTERILE_CHARGE';
comment on column I_UNIQUEORSTERILE.sterilizationtimestamp
  is 'Date / time of sterilization';
comment on column I_UNIQUEORSTERILE.rejectionreasoncode
  is 'Optional rejection reason code';
comment on column I_UNIQUEORSTERILE.rejectemployee
  is 'optional REJECTEMPLOYEE for the STERILIZATIONRUN';
comment on column I_UNIQUEORSTERILE.approvalemployeenumber
  is 'optioanl APPROVALEMPLOYEENUMBER for the STERILIZATIONRUN';
CREATE INDEX INDX_I_UNIQUEORSTERILE_BU ON I_UNIQUEORSTERILE (BUSINESSUNIT); 
alter table I_UNIQUEORSTERILE
  add constraint PK_I_UNIQUEORSTERILE primary key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER, CHARGENUMBER);
alter table I_UNIQUEORSTERILE
  add constraint FK_I_UNIQUEORSTERILE foreign key (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  references I_UNIQUEORPACK (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER) on delete cascade;
alter table I_UNIQUEORSTERILE
  add constraint FK_I_UNIQUEORSTERILE_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_UNIQUEORSTERILE
  add constraint CHK_I_UNIQUEORSTERILE_CHARGE
  check (CHARGENUMBER = UPPER(TRIM(CHARGENUMBER)));

prompt
prompt Creating table I_UNIQUERESITEM
prompt ==============================
prompt
create table I_UNIQUERESITEM
(
  businessunitcode    VARCHAR2(6) not null,
  primaryid           VARCHAR2(24) not null,
  sequencenumber      NUMBER not null,
  secondaryid         VARCHAR2(24),
  customernumber      NUMBER not null,
  clientnumber        NUMBER not null,
  productcode         VARCHAR2(12),
  typeofmerchandise   NUMBER default 5 not null,
  sizecode            VARCHAR2(12),
  finishingmethodcode VARCHAR2(6) default '-',
  wasprocesscode      VARCHAR2(6) default '-',
  colorcode           VARCHAR2(6) default '-',
  assigndate          DATE default TRUNC(SYSDATE)-1,
  printdate           DATE,
  status              VARCHAR2(2) default '10',
  statuschangedate    DATE default SYSDATE,
  stay                VARCHAR2(2) default '90',
  staychangedate      DATE default SYSDATE,
  lastinscandate      DATE,
  lastoutscandate     DATE,
  lastrewashdate      DATE,
  lastrepairdate      DATE,
  numberofwashes      NUMBER default 0,
  numberofrewashes    NUMBER default 0,
  numberofrepairs     NUMBER default 0,
  lastchangedate      DATE default SYSDATE,
  remark              VARCHAR2(80),
  price               NUMBER,
  flagcode            VARCHAR2(6),
  flagdescription     VARCHAR2(50) default '-',
  flagstartdate       DATE default TRUNC(SYSDATE)-1,
  flagremark          VARCHAR2(40)
);
comment on column I_UNIQUERESITEM.businessunitcode
  is 'Process business unit, must exist in database';
comment on column I_UNIQUERESITEM.primaryid
  is 'Primary ID, barcode or chipcode';
comment on column I_UNIQUERESITEM.customernumber
  is 'Must exist as customer in client';
comment on column I_UNIQUERESITEM.clientnumber
  is 'Must exist as client in client for the same customer';
comment on column I_UNIQUERESITEM.productcode
  is 'Must exist in I_PRODUCT';
comment on column I_UNIQUERESITEM.status
  is '10=Incirculation (default), 20=No product assigned';
comment on column I_UNIQUERESITEM.stay
  is '10=Inscan/Laundry, 20=Outscan/Customer, 90=Not scanned(label) (default)';
create index XIF1_I_UNIQUERESITEM on I_UNIQUERESITEM (CUSTOMERNUMBER, CLIENTNUMBER);
create index XIF2_I_UNIQUERESITEM on I_UNIQUERESITEM (BUSINESSUNITCODE);
alter table I_UNIQUERESITEM
  add constraint XPI_UNIQUERESITEM primary key (BUSINESSUNITCODE, PRIMARYID, SEQUENCENUMBER);
alter table I_UNIQUERESITEM
  add constraint FKI_UNIQUERESITEM_BUSINESSUNIT foreign key (BUSINESSUNITCODE)
  references BUSINESSUNIT (CODE);
alter table I_UNIQUERESITEM
  add constraint FKI_UNIQUERESITEM_CLIENT foreign key (CUSTOMERNUMBER, CLIENTNUMBER)
  references I_CLIENT (CUSTOMERNUMBER, CLIENTNUMBER);
alter table I_UNIQUERESITEM
  add constraint FKI_UNIQUERESITEM_PRODUCT foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_COLORCODE
  check (COLORCODE=UPPER(RTRIM(LTRIM(COLORCODE))));
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_FINISHINGMET
  check (FINISHINGMETHODCODE=UPPER(LTRIM(RTRIM(FINISHINGMETHODCODE))));
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_PRODUCTCODE
  check (PRODUCTCODE=UPPER(LTRIM(RTRIM(PRODUCTCODE))));
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_SIZE
  check (SIZECODE=UPPER(LTRIM(RTRIM(SIZECODE))));
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_STATUS
  check (STATUS IN ('10','20'));
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_STAY
  check (STAY IN ('10','20','90'));
alter table I_UNIQUERESITEM
  add constraint X_I_UNIQUERESITEM_WASHPROCESS
  check (WASPROCESSCODE=UPPER(LTRIM(RTRIM(WASPROCESSCODE))));

prompt
prompt Creating table I_USERDEFINEDEMBLEM
prompt ==================================
prompt
create table I_USERDEFINEDEMBLEM
(
  customernumber        NUMBER not null,
  emblemtype            NUMBER not null,
  emblemdescription     VARCHAR2(80) not null,
  sizecode              VARCHAR2(12) not null,
  textcolorcode         VARCHAR2(12) not null,
  bordercolorcode       VARCHAR2(12) not null,
  backgroundcolorcode   VARCHAR2(12) not null,
  fabriccode            VARCHAR2(12) not null,
  placementcode         VARCHAR2(6),
  attachmentby          NUMBER not null,
  qtypergarment         NUMBER not null,
  price                 NUMBER(15,6),
  fontsize              NUMBER default 8 not null,
  emblemfontdescription VARCHAR2(30)
);
comment on column I_USERDEFINEDEMBLEM.emblemtype
  is '1=Company
2=Name
3=Other (default)';
comment on column I_USERDEFINEDEMBLEM.attachmentby
  is '0 = Unknown
1 = Local Stockroom (default)
2 = Central Stockroom
3 = Supplier
4 = Stocked';
comment on column I_USERDEFINEDEMBLEM.fontsize
  is 'Emblem font size default 8. >= 8';
create unique index XAK1I_USERDEFINEDEMBLEM on I_USERDEFINEDEMBLEM (CUSTOMERNUMBER, EMBLEMDESCRIPTION);
create index XAK2I_USERDEFINEDEMBLEM on I_USERDEFINEDEMBLEM (CUSTOMERNUMBER, EMBLEMTYPE, SIZECODE, TEXTCOLORCODE, BORDERCOLORCODE, BACKGROUNDCOLORCODE, FABRICCODE, PLACEMENTCODE);
create index XIF1I_USERDEFINEDEMBLEM on I_USERDEFINEDEMBLEM (CUSTOMERNUMBER);
alter table I_USERDEFINEDEMBLEM
  add constraint I_USERDEFINEDEMBLEM_CUSTOMERNU foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_USERDEFINEDEMBLEM
  add constraint I_USERDEFEMBLEM_FONTSIZECHECK
  check (FONTSIZE >=8);
ALTER TABLE I_USERDEFINEDEMBLEM
  ADD CONSTRAINT CHK_I_USERDEFEMBLEM_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));  

prompt
prompt Creating table I_VISITMONTH
prompt ===========================
prompt
CREATE TABLE I_VISITMONTH
(
CUSTOMERNUMBER       NUMBER NOT NULL,
MONTH                NUMBER(2) NOT NULL CONSTRAINT CHECKI_VISITMONTHMONTHS CHECK (MONTH BETWEEN 1 AND 12)
);
COMMENT ON COLUMN I_VISITMONTH.CUSTOMERNUMBER IS 'Customer number must exist in I_CUSTOMER';
COMMENT ON COLUMN I_VISITMONTH.MONTH IS 'Month between 1 and 12';
CREATE UNIQUE INDEX PKI_VISITMONTH ON I_VISITMONTH(CUSTOMERNUMBER ASC,MONTH ASC);
ALTER TABLE I_VISITMONTH ADD CONSTRAINT PKI_VISITMONTH PRIMARY KEY (CUSTOMERNUMBER,MONTH);

prompt
prompt Creating table I_WEARERINVENTORY
prompt ================================
prompt
create table I_WEARERINVENTORY
(
  CUSTOMERNUMBER             NUMBER NOT NULL,
  WEARERNUMBER               NUMBER NOT NULL,
  WEAREREMPLOYMENTNUMBER     NUMBER DEFAULT 1 NOT NULL,
  PRODUCTCODE                VARCHAR2(12) NOT NULL,
  SIZECODE                   VARCHAR2(12) NOT NULL,
  SIZEDESCRIPTION            VARCHAR2(30) DEFAULT '-' NOT NULL,
  FINISHINGMETHODCODE        VARCHAR2(6) DEFAULT '-' NOT NULL,
  FINISHINGMETHODDESCRIPTION VARCHAR2(30) DEFAULT '-' NOT NULL,
  MODIFICATIONCODE1          VARCHAR2(10),
  MODIFICATIONDESCRIPTION1   VARCHAR2(40),
  MODIFICATIONCODE2          VARCHAR2(10),
  MODIFICATIONDESCRIPTION2   VARCHAR2(40),
  MODIFICATIONCODE3          VARCHAR2(10),
  MODIFICATIONDESCRIPTION3   VARCHAR2(40),
  MAXINVENTORY               NUMBER NOT NULL,
  FREEOFCHARGEQTY            NUMBER DEFAULT 0,
  CIRCINVENTORY              NUMBER,
  CHANGESPERWEEK             NUMBER,
  SPECIALQUALITYGRADE        VARCHAR2(1) DEFAULT 'N',
  STARTDATE                  DATE DEFAULT TRUNC(SYSDATE)-1 NOT NULL,
  ENDDATE                    DATE DEFAULT TO_DATE('31-12-2099','DD-MM-YYYY') NOT NULL,
  SWINGSUITSTATUS            NUMBER DEFAULT 0 NOT NULL,
  MAXFREEOFCHARGE            NUMBER DEFAULT 0 NOT NULL,
  WEARERINVENTORYPRICE       VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PRICESTARTDATE             DATE,
  PRICE                      NUMBER(15,6),
  QUANTITYRETURNED           NUMBER DEFAULT 0 NOT NULL,
  WEARERINVREMARK            VARCHAR2(40),
  EMBLEMTEMPLATE             VARCHAR2(6),
  TYPEOFMERCHANDISE          NUMBER DEFAULT 2 NOT NULL,
  QTYTOBERETURNEDDECREASEMAX NUMBER DEFAULT 0,
  QTYTOBERETURNEDREPLACEMENT NUMBER DEFAULT 0,
  WEARERINVOICECATEGORYCODE  VARCHAR2(6),
  WEARERINVOICECATEGORYDESC  VARCHAR2(30),
  WIC_EMPLOYERPERCENTAGE     NUMBER DEFAULT 0,
  WIC_MAXEMPLOYERAMOUNT      NUMBER DEFAULT 0,
  PHASEIN_PRODUCTCODE        VARCHAR2(12),
  PHASEIN_SIZECODE           VARCHAR2(12),
  PHASEIN_DATEACTIVE_WIL     DATE,
  TEMPORARYRENTSTOPSTARTDATE DATE,
  TEMPORARYRENTSTOPENDDATE   DATE,
  WEARERINVENTORY_ID         NUMBER
);
comment on column I_WEARERINVENTORY.swingsuitstatus
  is '0=no swing suit yet
1=charge swing suit next invoice
2=swing suit charged';
comment on column I_WEARERINVENTORY.emblemtemplate
  is 'Optional emblem template';
comment on column I_WEARERINVENTORY.typeofmerchandise
  is '1=linen/dust control,2=garments,3=disposables/sales only 4=emblem';
comment on column I_WEARERINVENTORY.wearerinvoicecategorycode
  is 'WEARERINVOICECATEGORY.CODE';
comment on column I_WEARERINVENTORY.wearerinvoicecategorydesc
  is 'WEARERINVOICECATEGORY.DESCRIPTION';
comment on column I_WEARERINVENTORY.wic_employerpercentage
  is 'WEARERINVOICECATEGORY.EMPLOYERPERCENTAGE between 0 and 100';
comment on column I_WEARERINVENTORY.wic_maxemployeramount
  is 'WEARERINVOICECATEGORY.MAXEMPLOYERAMOUNT';
comment on column I_WEARERINVENTORY.phasein_dateactive_wil
  is 'NEW PHASE-IN WEARERINVENTORY LINE START DATE';
comment on column I_WEARERINVENTORY.wearerinventory_id
  is 'Linked wearer inventory id that was created';
create index XIE2I_WEARERINVENTORY on I_WEARERINVENTORY (SIZECODE);
create index XIE3I_WEARERINVENTORY on I_WEARERINVENTORY (FINISHINGMETHODCODE);
create index XIE4I_WEARERINVENTORY on I_WEARERINVENTORY (WEARERNUMBER);
create index XIE5I_WEARERINVENTORY on I_WEARERINVENTORY (CUSTOMERNUMBER);
create index XIFI_WEARERINVPHASE on I_WEARERINVENTORY (PHASEIN_PRODUCTCODE, PHASEIN_SIZECODE);
create index XIF1I_WEARERINVENTORY on I_WEARERINVENTORY (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
create index XIF2I_WEARERINVENTORY on I_WEARERINVENTORY (PRODUCTCODE);
alter table I_WEARERINVENTORY
  add constraint XPKI_WEARERINVENTORY primary key (CUSTOMERNUMBER, WEARERNUMBER, PRODUCTCODE, SIZECODE, WEAREREMPLOYMENTNUMBER);
alter table I_WEARERINVENTORY
  add constraint FK_I_WEARERINVENTORY_PIPROD foreign key (PHASEIN_PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_WEARERINVENTORY
  add constraint I_WEARERINVENTORY_CUSTOMERNUMB foreign key (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER)
  references I_WEARER (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
alter table I_WEARERINVENTORY
  add constraint I_WEARERINVENTORY_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_WEARERINVENTORY
  add constraint I_WEARERINVENTORY_TOM foreign key (PRODUCTCODE, TYPEOFMERCHANDISE)
  references I_PRODUCT (CODE, TYPEOFMERCHANDISE);
alter table I_WEARERINVENTORY
  add constraint CHK_I_WEARERINV_CIRCINVENTORY
  check (CIRCINVENTORY>=0);
alter table I_WEARERINVENTORY
  add constraint CHK_I_WEARERINVENTORY_DATES
  check (enddate >= startdate);
alter table I_WEARERINVENTORY
  add constraint CHK_I_WEARERINV_FREEOFCHRQTY
  check (FREEOFCHARGEQTY>=0);
alter table I_WEARERINVENTORY
  add constraint CHK_I_WEARERINV_MAXFREEOFCHR
  check (FREEOFCHARGEQTY<=MAXFREEOFCHARGE);
alter table I_WEARERINVENTORY
  add constraint CHK_I_WEARERINV_WIC_EMPLPERC
  check (WIC_EMPLOYERPERCENTAGE between 0 and 100);
alter table I_WEARERINVENTORY
  add constraint CI_CHANGESPERWEEK
  check ("CHANGESPERWEEK" IS NOT NULL);
alter table I_WEARERINVENTORY
  add constraint CI_CIRCINVENTORY
  check ("CIRCINVENTORY" IS NOT NULL);
alter table I_WEARERINVENTORY
  add constraint CI_FREEOFCHARGEQTY
  check ("FREEOFCHARGEQTY" IS NOT NULL);
alter table I_WEARERINVENTORY
  add constraint GREATERTHANZERO4
  check (CHANGESPERWEEK >= 0);
alter table I_WEARERINVENTORY
  add constraint I_WEARERINV_SIZECHECK
  check (sizecode = upper(trim(sizecode)));
alter table I_WEARERINVENTORY
  add constraint I_WEARERINV_SIZESTAR
  check (sizecode <> '*');
alter table I_WEARERINVENTORY
  add constraint SWINGSUITSTATUS_VALIDATION
  check (swingsuitstatus IN (0,1,2));
alter table I_WEARERINVENTORY
  add constraint YN_VALIDATION9000
  check (WEARERINVENTORYPRICE IN ('Y', 'N'));
alter table I_WEARERINVENTORY
  add constraint I_WEARERINV_PHASEINSIZECHECK
  check (phasein_sizecode = upper(trim(phasein_sizecode)));
ALTER TABLE I_WEARERINVENTORY
  ADD CONSTRAINT CHK_I_WEARERINVENTORY_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_WEARERINVENTORY ADD CONSTRAINT CHK_I_WEARERINVENTORY_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_WEARERINVENTORY
  ADD CONSTRAINT CHK_I_WEARERINV_TEMPDATES
  CHECK (TEMPORARYRENTSTOPSTARTDATE<=TEMPORARYRENTSTOPENDDATE);  

prompt
prompt Creating table I_WEBUSER
prompt ========================
prompt
create table I_WEBUSER
(
  plantcode                  VARCHAR2(6) not null,
  languagecode               VARCHAR2(5) not null,
  loginname                  VARCHAR2(20) not null,
  convertedpassword          VARCHAR2(40) not null,
  active                     VARCHAR2(1) default 'Y' not null,
  readonly                   VARCHAR2(1) default 'Y' not null,
  emailaddress               VARCHAR2(300) default '-' not null,
  welcomemessage             VARCHAR2(80),
  accessgarments             VARCHAR2(1) default 'N' not null,
  accessnongarments          VARCHAR2(1) default 'N' not null,
  accesssalesitems           VARCHAR2(1) default 'N' not null,
  showgarments               NUMBER default 0 not null,
  passwordexpiresdays        NUMBER default 30 not null,
  changepasswordnextlogin    VARCHAR2(1) default 'N' not null,
  showgarmentgrade           VARCHAR2(1) default 'N' not null,
  showgarmentissuedate       VARCHAR2(1) default 'N' not null,
  showgarmentstay            VARCHAR2(1) default 'N' not null,
  showgarmentwashesissue     VARCHAR2(1) default 'N' not null,
  showgarmentwashestotal     VARCHAR2(1) default 'N' not null,
  showgarmentrepairsissue    VARCHAR2(1) default 'N' not null,
  showgarmentrepairstotal    VARCHAR2(1) default 'N' not null,
  showgarmentrewashesissue   VARCHAR2(1) default 'N' not null,
  showgarmentrewashestotal   VARCHAR2(1) default 'N' not null,
  showgarmentweeksinuseissue VARCHAR2(1) default 'N' not null,
  showgarmentweeksinusetotal VARCHAR2(1) default 'N' not null,
  showgarmentfreeofcharge    VARCHAR2(1) default 'N' not null,
  productdescriptiononly     VARCHAR2(1) default 'N' not null,
  allowsales                 VARCHAR2(1) default 'N' not null,
  webreportpreviewer         NUMBER default 0 not null,
  laundryrepresent           VARCHAR2(1) default 'N' not null,
  custominfoaccess           VARCHAR2(1) default 'N' not null,
  userfolderaccess           VARCHAR2(1) default 'N' not null,
  securefolderaccess         VARCHAR2(1) default 'N' not null,
  phoneid                    VARCHAR2(50)
);
comment on column I_WEBUSER.convertedpassword
  is 'Will be encrypted by the application into the real PASSWORD field.';
comment on column I_WEBUSER.showgarments
  is '0 = All
1 = Rent only
2 = COG only';
comment on column I_WEBUSER.webreportpreviewer
  is 'Indicates which kind of report previewer should be used for web reports. Possible values:
0 = PDF preview
1 = Advanced preview (export to (PDF, CSV etc)';
alter table I_WEBUSER
  add constraint PK_I_WEBUSER_LOGINNAME primary key (LOGINNAME);
create index XIF1I_WEBUSER on I_WEBUSER (LANGUAGECODE);
create index XIF2I_WEBUSER on I_WEBUSER (PLANTCODE);
alter table I_WEBUSER
  add constraint FK_I_WEBUSER_LANGAUGE foreign key (LANGUAGECODE)
  references LANGUAGES (CODE) on delete cascade;
alter table I_WEBUSER
  add constraint FK_I_WEBUSER_PLANTCODE foreign key (PLANTCODE)
  references PLANT (CODE) on delete cascade;
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_27
  check (LAUNDRYREPRESENT IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_28
  check (CUSTOMINFOACCESS IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_29
  check (USERFOLDERACCESS IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_30
  check (SECUREFOLDERACCESS IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_31
  check (SHOWGARMENTWASHESISSUE IN ('Y','N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_32
  check (SHOWGARMENTWASHESTOTAL IN ('Y','N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_33
  check (SHOWGARMENTREPAIRSISSUE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_34
  check (SHOWGARMENTREPAIRSTOTAL IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_35
  check (SHOWGARMENTREWASHESISSUE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_36
  check (SHOWGARMENTREWASHESTOTAL IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_37
  check (SHOWGARMENTWEEKSINUSEISSUE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_38
  check (SHOWGARMENTWEEKSINUSETOTAL IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_39
  check (SHOWGARMENTFREEOFCHARGE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_40
  check (PRODUCTDESCRIPTIONONLY  IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_41
  check (ALLOWSALES IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_42
  check (SHOWGARMENTS IN (0,1,2));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_7849
  check (ACTIVE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_7850
  check (ACCESSGARMENTS IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_7851
  check (ACCESSNONGARMENTS IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_7852
  check (ACCESSSALESITEMS IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_7853
  check (READONLY IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_8541
  check (SHOWGARMENTISSUEDATE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_8542
  check (SHOWGARMENTSTAY IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_8543
  check (CHANGEPASSWORDNEXTLOGIN IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint CHK_I_WEBUSER_8544
  check (SHOWGARMENTGRADE IN ('Y', 'N'));
alter table I_WEBUSER
  add constraint I_WEBREPORTPREVIEWER_VALID
  check (WEBREPORTPREVIEWER IN (0, 1));

prompt
prompt Creating table I_WEBUSERCUSTOMER
prompt ================================
prompt
create table I_WEBUSERCUSTOMER
(
  customernumber NUMBER not null,
  loginname      VARCHAR2(20) not null
);
create index XIF1I_WEBUSERCUSTOMER on I_WEBUSERCUSTOMER (CUSTOMERNUMBER);
alter table I_WEBUSERCUSTOMER
  add constraint PK_I_WEBUSERCUSTOMER primary key (CUSTOMERNUMBER, LOGINNAME);
alter table I_WEBUSERCUSTOMER
  add constraint FK_I_WEBUSERCUST_CUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_WEBUSERCUSTOMER
  add constraint FK_I_WEBUSERCUST_WEBUSER foreign key (LOGINNAME)
  references I_WEBUSER (LOGINNAME);

prompt
prompt Creating table I_WEIGHINGCATEGPERCUSTOMER
prompt =========================================
prompt
create table I_WEIGHINGCATEGPERCUSTOMER
(
  weighingcategorycode        VARCHAR2(6) not null,
  weighingcategorydescription VARCHAR2(30) not null,
  weighingcategoryrewash      VARCHAR2(1) default 'Y' not null,
  weighingcategorylegacycode  VARCHAR2(6),
  weighingcategoryeannumber   NUMBER,
  weighingcatturnovergroup    VARCHAR2(12),
  customernumber              NUMBER not null,
  weightclean                 VARCHAR2(1) default 'N',
  weightsoiled                VARCHAR2(1) default 'Y',
  invoicemethod               NUMBER default 1 not null,
  soilpercentage              NUMBER default 0,
  dateactive                  DATE default TRUNC(SYSDATE)-1,
  dateinactive                DATE default TO_DATE('31-12-2099','DD-MM-YYYY'),
  invoicegroupingcode         VARCHAR2(12),
  eannumber                   NUMBER,
  taxgroupcode                VARCHAR2(6),
  price                       NUMBER,
  pricestartdate              DATE,
  internalcalcpercentage      NUMBER(4,1),
  weighingcat_activitycode    VARCHAR2(6),
  discount                    NUMBER(15,2),
  discountstartdate           DATE
);
comment on column I_WEIGHINGCATEGPERCUSTOMER.invoicemethod
  is '1 = NO INVOICING WEIGHTS (Default)2 = INVOICE SOILED WEIGHTS 3 = INVOICE CLEAN WEIGHTS 4 = INVOICE SOIL VIA TRANSFER TO CLEAN';
comment on column I_WEIGHINGCATEGPERCUSTOMER.internalcalcpercentage
  is 'Internal calculation percentage for all weighed items, only relevant when module INTERNALCALC is active.';
comment on column I_WEIGHINGCATEGPERCUSTOMER.weighingcat_activitycode
  is 'If it is a new WEIGHINGCATEGORY, it will be linked to this activity code';
alter table I_WEIGHINGCATEGPERCUSTOMER
  add constraint XP_I_WEIGHINGCATEGPERCUST primary key (WEIGHINGCATEGORYCODE, CUSTOMERNUMBER);
create index XIF1I_WEIGHINGCATEGPERCUSTOMER on I_WEIGHINGCATEGPERCUSTOMER (CUSTOMERNUMBER);  
alter table I_WEIGHINGCATEGPERCUSTOMER
  add constraint FK_I_WEIGHINGCATEGPERCUST foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_WEIGHINGCATEGPERCUSTOMER
  add constraint INVOICEMETHOD
  check (INVOICEMETHOD in (1,2,3,4));
alter table I_WEIGHINGCATEGPERCUSTOMER
  add constraint WEIGHINGCATEGORYREWASH_YN
  check (WEIGHINGCATEGORYREWASH in ('Y','N'));
alter table I_WEIGHINGCATEGPERCUSTOMER
  add constraint WEIGHTCLEAN_YN
  check (WEIGHTCLEAN in ('Y','N'));
alter table I_WEIGHINGCATEGPERCUSTOMER
  add constraint WEIGHTSOILED_YN
  check (WEIGHTSOILED in ('Y','N'));

prompt
prompt Creating table I_WORKORDER
prompt ==========================
prompt
create table I_WORKORDER
(
  workordernumber          NUMBER not null,
  businessunit             VARCHAR2(6) not null,
  customernumber           NUMBER not null,
  wearernumber             NUMBER,
  weareremploymentnumber   NUMBER,
  status                   VARCHAR2(2) not null,
  routenumber              NUMBER,
  routedaynumber           NUMBER,
  requestdate              DATE not null,
  entrydate                DATE not null,
  neededdate               DATE not null,
  expectedcompletiondate   DATE not null,
  completiondate           DATE not null,
  referencenumber          VARCHAR2(15),
  billtocustomerrelated    VARCHAR2(1) not null,
  deliverfrom              NUMBER,
  customerowned            VARCHAR2(1) not null,
  allowedfhaseddeilvery    VARCHAR2(1) not null,
  labelsprinted            VARCHAR2(1) not null,
  emblempicklistprinted    VARCHAR2(1) not null,
  picklistprinted          VARCHAR2(1) not null,
  remark                   VARCHAR2(80),
  processingstockroom_code VARCHAR2(12),
  shipmenttypecode         VARCHAR2(12),
  departmentnumber         NUMBER(6),
  consumptionpointnumber   NUMBER(2)
);
comment on column I_WORKORDER.wearernumber
  is 'Either wearernumber or for sales note consumption/departmentnumber needs to be filled';
create index XIF1I_WORKORDER on I_WORKORDER (CUSTOMERNUMBER);
create index XIF2I_WORKORDER on I_WORKORDER (WEARERNUMBER, CUSTOMERNUMBER, WEAREREMPLOYMENTNUMBER);
create index XIF3I_WORKORDER on I_WORKORDER (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
create index INDX_I_WORKORDER_BU on I_WORKORDER (BUSINESSUNIT); 
alter table I_WORKORDER
  add constraint XPKI_WORKORDER primary key (WORKORDERNUMBER);
alter table I_WORKORDER
  add constraint FK_I_WORKORDER_BU foreign key (BUSINESSUNIT)
  references BUSINESSUNIT (CODE);
alter table I_WORKORDER
  add constraint I_WORKORDER_CUSTOMERNUMBER foreign key (CUSTOMERNUMBER)
  references I_CUSTOMER (CUSTOMERNUMBER);
alter table I_WORKORDER
  add constraint I_WORKORDER_CUSTOMERNUMBER____ foreign key (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER)
  references I_WEARER (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
alter table I_WORKORDER
  add constraint I_WORKORDER_CONSUMPTIONPOINT foreign key (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER)
  references I_CONSUMPTIONPOINT (CUSTOMERNUMBER, DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
alter table I_WORKORDER
  add constraint CHK_I_WORKORDER_DELIVERFROM
  check (DELIVERFROM in (0,1,2));
alter table I_WORKORDER
  add constraint DELIVERFROM_VALIDATION
  check (deliverfrom in (1,2));
alter table I_WORKORDER
  add constraint I_WORKORDER_BU
  check (TRIM(UPPER(BUSINESSUNIT))=BUSINESSUNIT);
alter table I_WORKORDER
  add constraint ROUTEDAYNUMBER_VALIDATION
  check (routedaynumber in (1,2,3,4,5,6,7));
alter table I_WORKORDER
  add constraint WORKORDERSTATUS_VALIDATION
  check (status in ('05','10','15','20','25','30','40'));
alter table I_WORKORDER
  add constraint YN_VALIDATION3200
  check (BILLTOCUSTOMERRELATED IN ('Y', 'N'));
alter table I_WORKORDER
  add constraint YN_VALIDATION3201
  check (CUSTOMEROWNED IN ('Y', 'N'));
alter table I_WORKORDER
  add constraint YN_VALIDATION3202
  check (ALLOWEDFHASEDDEILVERY IN ('Y', 'N'));
alter table I_WORKORDER
  add constraint YN_VALIDATION3203
  check (LABELSPRINTED IN ('Y', 'N'));
alter table I_WORKORDER
  add constraint YN_VALIDATION3204
  check (EMBLEMPICKLISTPRINTED IN ('Y', 'N'));
alter table I_WORKORDER
  add constraint YN_VALIDATION3205
  check (PICKLISTPRINTED IN ('Y', 'N'));
alter table I_WORKORDER
  add constraint CHK_I_WORKORDER_SALES
  check (WEARERNUMBER IS NOT NULL OR (DEPARTMENTNUMBER IS NOT NULL AND CONSUMPTIONPOINTNUMBER IS NOT NULL));

prompt
prompt Creating table I_WORKORDERLINE
prompt ==============================
prompt
create table I_WORKORDERLINE
(
  workordernumber          NUMBER not null,
  productcode              VARCHAR2(12) not null,
  sizecode                 VARCHAR2(12) not null,
  qualitygradecode         VARCHAR2(1) not null,
  reasoncode               VARCHAR2(6) not null,
  codeuniquely             VARCHAR2(1) not null,
  quantityordered          NUMBER not null,
  quantityfilled           NUMBER not null,
  quantitypedingorder      NUMBER not null,
  quantitycanceled         NUMBER not null,
  completiondate           DATE not null,
  modificationcode1        VARCHAR2(10),
  modificationcode2        VARCHAR2(10),
  modificationdescription2 VARCHAR2(40),
  modificationdescription1 VARCHAR2(40),
  modificationcode3        VARCHAR2(10),
  modificationdescription3 VARCHAR2(40),
  instructions             VARCHAR2(80),
  finishingmethodcode      VARCHAR2(6) default '-',
  emblemtemplate           VARCHAR2(6),
  salesprice               NUMBER(15,6),  --if filled MANUALPRICECHANGE=1 and SALESPRICEORIGIN=1 General Sales Price List
  quantitytobecredited     NUMBER --should be >=1 when there is a salesprice
);
comment on column I_WORKORDERLINE.emblemtemplate
  is 'Optional emblem template';
create index XIF3I_WORKORDERLINE on I_WORKORDERLINE (PRODUCTCODE);
alter table I_WORKORDERLINE
  add constraint XPKI_WORKORDERLINE primary key (WORKORDERNUMBER, PRODUCTCODE, SIZECODE, QUALITYGRADECODE, REASONCODE);
alter table I_WORKORDERLINE
  add constraint I_WORKORDERLINE_PRODUCTCODE foreign key (PRODUCTCODE)
  references I_PRODUCT (CODE);
alter table I_WORKORDERLINE
  add constraint I_WORKORDERLINE_PRODUCTCODE___ foreign key (PRODUCTCODE, SIZECODE)
  references I_PRODUCTSIZE (PRODUCTCODE, SIZECODE);
alter table I_WORKORDERLINE
  add constraint I_WORKORDERLINE_WORKORDERNUMBE foreign key (WORKORDERNUMBER)
  references I_WORKORDER (WORKORDERNUMBER);
alter table I_WORKORDERLINE
  add constraint YN_VALIDATION3206
  check (CODEUNIQUELY IN ('Y', 'N'));
ALTER TABLE I_WORKORDERLINE
  ADD CONSTRAINT CHK_I_WORKORDERLINE_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_WORKORDERLINE
  ADD CONSTRAINT CHK_I_WORKORDERLINE_FINM
  CHECK (FINISHINGMETHODCODE=UPPER(TRIM(FINISHINGMETHODCODE)));
ALTER TABLE I_WORKORDERLINE ADD CONSTRAINT CHK_I_WORKORDERLINE_PROD CHECK (PRODUCTCODE=UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_WORKORDERLINE ADD CONSTRAINT CHK_I_WORKORDERLINE_SALES CHECK (SALESPRICE IS NULL OR (SALESPRICE IS NOT NULL AND NVL(QUANTITYTOBECREDITED,1) > 0));

prompt
prompt Creating table I_PLANT
prompt ======================
prompt
create table I_PLANT
(
  PLANT_CODE                  VARCHAR2(6) NOT NULL,
  PLANT_NAME                  VARCHAR2(60) NOT NULL,
  PLANT_PHONENO               VARCHAR2(30),
  PLANT_FAXNO                 VARCHAR2(30),
  PLANT_EMAIL                 VARCHAR2(300),
  PLANT_STREET                VARCHAR2(40),
  PLANT_STREET2               VARCHAR2(40),
  PLANT_HOUSENUMBER           NUMBER(5) DEFAULT 0 NOT NULL,
  PLANT_CITY                  VARCHAR2(30) NOT NULL,
  PLANT_ZIPCODE               VARCHAR2(15),
  PLANT_STATE                 VARCHAR2(20),
  PLANT_COUNTY                VARCHAR2(20),
  PLANT_COUNTRY               VARCHAR2(3) NOT NULL,
  PLANT_LANGUAGECODE          VARCHAR2(5),
  PLANT_FINANCECHARGEPERCENT  NUMBER,
  PLANT_WEBSITE               VARCHAR2(40),
  PLANT_TIMEZONE              VARCHAR2(40),
  PLANT_STREET3               VARCHAR2(40)
);
-- Create/Recreate primary, unique and foreign key constraints 
alter table I_PLANT
  add constraint PK_I_PLANT primary key (PLANT_CODE);
alter table I_PLANT
  add constraint FK_I_PLANT_LANGUAGECODE foreign key (PLANT_LANGUAGECODE)
  references LANGUAGES (CODE) on delete cascade; 
-- Create/Recreate check constraints   
alter table I_PLANT
  add constraint CHK_I_PLANT_CODE
  check (PLANT_CODE=UPPER(TRIM(PLANT_CODE)));
alter table I_PLANT
  add constraint FK_I_PLANT_COUNTRY foreign key (PLANT_COUNTRY)
  references COUNTRY (CODE) on delete cascade;  
-- Add comments to the columns  
comment on column I_PLANT.PLANT_HOUSENUMBER
  is 'Use 0 if not used';
comment on column I_PLANT.PLANT_COUNTRY
  is 'Must exist as country code';
comment on column I_PLANT.PLANT_LANGUAGECODE
  is 'Must exists as language code';
comment on column I_PLANT.PLANT_TIMEZONE
  is 'May be not null only when system setting ROUNDTOTALAMNTINVOICE = Y';

prompt
prompt Creating table I_PLANTPRODUCTSETTINGS
prompt ======================
prompt
create table I_PLANTPRODUCTSETTINGS
(
  PLANT_CODE                  VARCHAR2(6) NOT NULL,
  PRODUCTCODE                 VARCHAR2(12) NOT NULL,
  PACKINGSEQUENCE             NUMBER NULL,
  MAXCARTQTY                  NUMBER NULL,
  FULFILLMENTGROUP            NUMBER(1) NULL,
  FILLPERCENTAGE              NUMBER(3) NULL,
  PUTUPTYPE                   NUMBER DEFAULT 0 NOT NULL,
  ACTIVE                      VARCHAR2(1) DEFAULT 'Y' NOT NULL,
  WASHINGPROCESSCODE          VARCHAR2(6) NULL,
  TREATMENTCHECKSCHEMECODE    VARCHAR2(6) NULL,
  DEFAULTSTOCKROOMCODE        VARCHAR2(12) NULL,
  FIXEDSTOCKROOM              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  ALLOWROUTEASSISTANTADD      VARCHAR2(1) DEFAULT 'N' NOT NULL,
  MINAPPROVALQTY              NUMBER DEFAULT 0 NOT NULL,
  PACKINGGROUP                NUMBER NULL,
  PACKINGPRODUCTTYPE          NUMBER(1) NULL,
  CLEANROOMBATCHPAIRSCAN      VARCHAR2(1) DEFAULT 'N' NOT NULL,
  PRODUCTPLACEMENTCODE        VARCHAR2(4) NULL
);
COMMENT ON COLUMN I_PLANTPRODUCTSETTINGS.FULFILLMENTGROUP
  IS '1 = Garments are stocked at the Apparel Center and the Apparel Center is the exclusive supplier for the plant
3 = Not stocked at the Apparel Center , however if the item requires embroidery or prep work , for new and renew contracts at the Apparel Center
4 = Never handled by the Apparel Center';
COMMENT ON COLUMN I_PLANTPRODUCTSETTINGS.PUTUPTYPE
  IS '0 = Not defined per plant, copy from product
1 = Put up per customer (Packingnote)
2 = Bulk put up
2 = Bundle tag
4 = Bulk put up scan per route
5 = Packer - Loose linen';
COMMENT ON COLUMN I_PLANTPRODUCTSETTINGS.PACKINGGROUP
  IS 'Products will be grouped together based on this number when generating packing notes in case Optimized Load packing is used.';
COMMENT ON COLUMN I_PLANTPRODUCTSETTINGS.PACKINGPRODUCTTYPE
  IS 'Defines the type of product with respect to packing. Possible values:
1 = Base product
2 = Supplementary product';
COMMENT ON COLUMN I_PLANTPRODUCTSETTINGS.PRODUCTPLACEMENTCODE
  IS 'used for export only';
CREATE INDEX XIF1_I_PLANTPRODUCTSETTINGS ON I_PLANTPRODUCTSETTINGS (PLANT_CODE);
CREATE INDEX XIF2_I_PLANTPRODUCTSETTINGS ON I_PLANTPRODUCTSETTINGS (PRODUCTCODE);
CREATE INDEX XIF3_I_PLANTPRODUCTSETTINGS ON I_PLANTPRODUCTSETTINGS (TREATMENTCHECKSCHEMECODE ASC);
CREATE INDEX XIF4_I_PLANTPRODUCTSETTINGS ON I_PLANTPRODUCTSETTINGS (WASHINGPROCESSCODE ASC);
CREATE INDEX XIF5_I_PLANTPRODUCTSETTINGS ON I_PLANTPRODUCTSETTINGS (DEFAULTSTOCKROOMCODE ASC);
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT PK_I_PLANTPRODUCTSETTINGS PRIMARY KEY (PLANT_CODE, PRODUCTCODE);
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT FK_I_PPRODCODE_PROD FOREIGN KEY (PRODUCTCODE)
  REFERENCES PRODUCT (CODE) ON DELETE CASCADE;
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT FK_I_PPRODCODE_PLANT FOREIGN KEY (PLANT_CODE)
  REFERENCES PLANT (CODE) ON DELETE CASCADE;
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT FK_I_PRODCODE_STOCK FOREIGN KEY (DEFAULTSTOCKROOMCODE)
  REFERENCES STOCKROOM (CODE);
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT CHK_I_DEFAULT_STOCK_FIXED_PPS
 CHECK ((FIXEDSTOCKROOM = 'Y' AND DEFAULTSTOCKROOMCODE IS NOT NULL)  OR  (FIXEDSTOCKROOM = 'N'));
ALTER TABLE I_PLANTPRODUCTSETTINGS 
  ADD CONSTRAINT CHK_I_PPROD_FILLPERC
  CHECK (FILLPERCENTAGE BETWEEN 0 AND 100);
ALTER TABLE I_PLANTPRODUCTSETTINGS 
  ADD CONSTRAINT CHK_I_PPROD_PUTUPTYP
  CHECK (PUTUPTYPE BETWEEN 0 AND 5);
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT CHK_YN_I_VALIDATIONFIELD195
  CHECK (FIXEDSTOCKROOM IN ('Y', 'N'));
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT CHK_YN_I_VALIDATIONFIELD196
  CHECK (ALLOWROUTEASSISTANTADD IN ('Y','N'));
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT CHK_I_YN_VALIDATIONFIELD382
  CHECK (CLEANROOMBATCHPAIRSCAN IN ('Y','N'));
ALTER TABLE I_PLANTPRODUCTSETTINGS
  ADD CONSTRAINT CHK_I_YN_VALIDATIONNEW185
  CHECK (ACTIVE IN ('Y', 'N'));

prompt
prompt Creating table I_PLANTPRODUCTSIZESETTINGS
prompt ======================
prompt
create table I_PLANTPRODUCTSIZESETTINGS
(
  PLANT_CODE                  VARCHAR2(6) NOT NULL,
  PRODUCTCODE                 VARCHAR2(12) NOT NULL,
  SIZECODE                    VARCHAR2(12) NOT NULL,
  PACKINGAMOUNT               NUMBER NULL,
  DEFAULTSTOCKROOMCODE        VARCHAR2(12) NULL,
  FIXEDSTOCKROOM              VARCHAR2(1) DEFAULT 'N' NOT NULL,
  MAXCARTQTY                  NUMBER DEFAULT 0 NOT NULL
);
CREATE INDEX XIF1_I_PLANTPRODUCTSIZESETTINGS ON I_PLANTPRODUCTSIZESETTINGS (PLANT_CODE);
CREATE INDEX XIF2_I_PLANTPRODUCTSIZESETTINGS ON I_PLANTPRODUCTSIZESETTINGS (PRODUCTCODE);
CREATE INDEX XIF3_I_PLANTPRODUCTSIZESETTINGS ON I_PLANTPRODUCTSIZESETTINGS (SIZECODE);
CREATE INDEX XIF4_I_PLANTPRODUCTSIZESETTINGS ON I_PLANTPRODUCTSIZESETTINGS (DEFAULTSTOCKROOMCODE ASC);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS 
  ADD  CONSTRAINT XPK_I_PLANTPRODUCTSIZESETTINGS PRIMARY KEY (PLANT_CODE, PRODUCTCODE, SIZECODE);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS
  ADD CONSTRAINT I_PLANTPRODUCTSIZESETTINGS_DEF FOREIGN KEY (DEFAULTSTOCKROOMCODE)
  REFERENCES STOCKROOM (CODE);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS
  ADD CONSTRAINT I_PLANTPRODSIZESETTINGS_PLANT FOREIGN KEY (PLANT_CODE)
  REFERENCES PLANT (CODE);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS
  ADD CONSTRAINT I_PLANTPRODSIZESETTINGS_PROD FOREIGN KEY (PRODUCTCODE)
  REFERENCES PRODUCT (CODE);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS
  ADD CONSTRAINT I_PLANTPRODSIZESETTINGS_SIZED FOREIGN KEY (SIZECODE)
  REFERENCES SIZEDEFINITION (CODE);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS 
  ADD CONSTRAINT CHK_I_DEF_STOCK_FIXED_PPSS
 CHECK ((FIXEDSTOCKROOM = 'Y' AND DEFAULTSTOCKROOMCODE IS NOT NULL)  OR  (FIXEDSTOCKROOM = 'N')) ;
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS 
  ADD CONSTRAINT I_MAXCARTQTY_VALID1_2
  CHECK (MAXCARTQTY BETWEEN 0 AND 9999);
ALTER TABLE I_PLANTPRODUCTSIZESETTINGS 
  ADD CONSTRAINT I_YN_VALIDATION196
  CHECK (FIXEDSTOCKROOM IN ('Y', 'N'));

prompt
prompt Creating table I_BUSINESSUNIT
prompt =============================
prompt
create table I_BUSINESSUNIT
(
  BUSINESSUNIT                VARCHAR2(6) NOT NULL,
  DESCRIPTION                 VARCHAR2(30) NOT NULL,
  DIVISION_CODE               VARCHAR2(6) NOT NULL,
  REGION_CODE                 VARCHAR2(6) NOT NULL,
  PLANT_CODE                  VARCHAR2(6) NOT NULL,
  ILNNUMBER                   NUMBER,
  INTERNALVATNUMBER           VARCHAR2(30),
  VATNUMBER                   VARCHAR2(30),
  LABELLAYOUTSTOCK            VARCHAR2(6),
  CONTACTCATEGORY_CODE        VARCHAR2(6),
  FOLLOWUPUSER_NAME           VARCHAR2(20),
  DEFAULTBANKINST_IDCODE      VARCHAR2(30),
  ORSERVICINGBU               NUMBER(1),
  ORPLANTDEPARTMENT_CODE      VARCHAR2(6),
  ORPLANTDEPARTMENT_DESCR     VARCHAR2(30),
  ORPRODUCTIONLABELLAYOUT     VARCHAR2(6),
  ORCONTENTSREASONCODE        VARCHAR2(6),
  MERCHANTID                  NUMBER(15) DEFAULT 0 NOT NULL,
  BUNDLESORTLABELLAYOUT_CODE  VARCHAR2(6),
  LEGALENTITY_CODE            VARCHAR2(10),
  LEGALENTITY_NAME            VARCHAR2(40),
  LEGALENTITY_LEGALNAME       VARCHAR2(80),
  LEGALENTITY_STREET          VARCHAR2(40),
  LEGALENTITY_STREET2         VARCHAR2(40),
  LEGALENTITY_HOUSENUMBER     NUMBER(5) DEFAULT 0,
  LEGALENTITY_CITY            VARCHAR2(30),
  LEGALENTITY_ZIPCODE         VARCHAR2(15),
  LEGALENTITY_STATE           VARCHAR2(20),
  LEGALENTITY_COUNTY          VARCHAR2(20),
  LEGALENTITY_COUNTRY         VARCHAR2(3),
  LEGALENTITY_PHONE           VARCHAR2(30),
  LEGALENTITY_FAX             VARCHAR2(30),
  LEGALENTITY_EMAIL           VARCHAR2(300),
  LEGALENTITY_WEBSITE         VARCHAR2(80),
  LEGALENTITY_VATNUMBER       VARCHAR2(30),
  LEGALENTITY_COCNUMBER       VARCHAR2(20),
  LEGALENTITY_BANKINST_IDCODE VARCHAR2(30),
  LEGALENTITY_ACTIVE          VARCHAR2(1),
  LEGALENTITY_EXTRANAME1      VARCHAR2(40),
  LEGALENTITY_EXTRANAME2      VARCHAR2(40),
  LEGALENTITY_STREET3         VARCHAR2(40)
);
-- Add comments to the columns 
comment on column I_BUSINESSUNIT.LABELLAYOUTSTOCK
  is 'LabelLayout.LabelType = 1 (code label).';
comment on column I_BUSINESSUNIT.FOLLOWUPUSER_NAME
  is 'System user that must exist';
comment on column I_BUSINESSUNIT.DEFAULTBANKINST_IDCODE
  is 'DEFAULTBANKINSTITUTION_IDCODE';
comment on column I_BUSINESSUNIT.ORSERVICINGBU
  is '0 = No OR servicing business unit (default)
1 = OR servicing business unit';
comment on column I_BUSINESSUNIT.ORPLANTDEPARTMENT_DESCR
  is 'ORPLANTDEPARTMENT_DESCRIPTION';
comment on column I_BUSINESSUNIT.ORPRODUCTIONLABELLAYOUT
  is 'ORPRODUCTIONLABELLAYOUT_CODE';
comment on column I_BUSINESSUNIT.LEGALENTITY_BANKINST_IDCODE
  is 'LEGALENTITY_BANKINSTITUTION_IDCODE';
-- Create/Recreate primary, unique and foreign key constraints 
alter table I_BUSINESSUNIT
  add constraint PK_I_BUSINESSUNIT primary key (BUSINESSUNIT);
alter table I_BUSINESSUNIT
  add constraint FK_I_BUS_PLANT_CODE foreign key (PLANT_CODE)
  references i_plant (PLANT_CODE);
alter table I_BUSINESSUNIT
  add constraint FK_I_BUS_LEGALENTITY_COUNTRY foreign key (LEGALENTITY_COUNTRY)
  references COUNTRY (CODE) on delete cascade;
-- Create/Recreate check constraints 
alter table I_BUSINESSUNIT
  add constraint CHK_I_BUSINESSUNIT_CODE
  check (BUSINESSUNIT=upper(trim(BUSINESSUNIT)));
alter table I_BUSINESSUNIT
  add constraint CHK_I_BU_LEGAL_BANKINST_ID
  check (LEGALENTITY_CODE is null or (LEGALENTITY_CODE is not null and LEGALENTITY_BANKINST_IDCODE is not null));  

prompt
prompt Creating table I_DEPOT
prompt =============================
prompt
create table I_DEPOT
(
  DEPOT_CODE        VARCHAR2(12) NOT NULL,
  DESCRIPTION       VARCHAR2(30),
  PLANT_CODE        VARCHAR2(6) NOT NULL,
  PHONENO           VARCHAR2(30),
  FAXNO             VARCHAR2(30),
  DEPOT_STREET      VARCHAR2(40),
  DEPOT_STREET2     VARCHAR2(40),
  DEPOT_HOUSENUMBER NUMBER(5) DEFAULT 0 NOT NULL,
  DEPOT_CITY        VARCHAR2(30) NOT NULL,
  DEPOT_ZIPCODE     VARCHAR2(15),
  DEPOT_STATE       VARCHAR2(20),
  DEPOT_COUNTY      VARCHAR2(20),
  DEPOT_STREET3     VARCHAR2(40)
);
-- Create/Recreate primary, unique and foreign key constraints 
alter table I_DEPOT
  add constraint PK_I_DEPOT primary key (DEPOT_CODE, PLANT_CODE);
alter table I_DEPOT
  add constraint FK_I_DEPOT_PLANT_CODE foreign key (PLANT_CODE)
  references I_PLANT (PLANT_CODE);
-- Create/Recreate check constraints   
alter table I_DEPOT
  add constraint CHK_I_DEPOT_CODE
  check (DEPOT_CODE=upper(trim(DEPOT_CODE)));  

prompt
prompt Creating table I_OUTOFCIRCULATIONHISTORY
prompt ========================================
prompt
CREATE TABLE I_OUTOFCIRCULATIONHISTORY
(
  PROCESSBUSINESSUNIT    VARCHAR2(6) NOT NULL,
  FORBUSINESSUNIT        VARCHAR2(6) NOT NULL,
  PRIMARYID              VARCHAR2(24),
  OUTOFCIRCDATE          DATE NOT NULL,  
  INCIRCDATE             DATE,
  REASONCODE             VARCHAR2(6),
  QUANTITY               NUMBER NOT NULL,
  OUTOFCIRCYEAR          NUMBER NOT NULL,
  OUTOFCIRCWEEK          NUMBER NOT NULL,
  OUTOFCIRCDAY           NUMBER NOT NULL,
  WEEKSINUSEPREVISSUE    NUMBER NOT NULL,
  WEEKSINUSETHISISSUE    NUMBER NOT NULL,
  NORMLIFETIME           NUMBER NOT NULL,
  ENDDATEFULLRENT        DATE,
  THEORETICALPERCENTAGE  NUMBER(19,6) NOT NULL,
  ENTEREDPERCENTAGE      NUMBER(19,6) NOT NULL,
  TOBECHARGEDPERCENTAGE  NUMBER(19,6) NOT NULL,
  RAGREASONCODE          VARCHAR2(6),
  CUSTOMERNUMBER         NUMBER NOT NULL,
  DEPARTMENTNUMBER       NUMBER(6) NOT NULL,  
  CONSUMPTIONPOINTNUMBER NUMBER(2) NOT NULL,
  WEARERNUMBER           NUMBER NULL,
  WEAREREMPLOYMENTNUMBER NUMBER DEFAULT 1 NULL,
  STATUS                 NUMBER NOT NULL,
  PRODUCTCODE            VARCHAR2(12) NOT NULL,
  SIZECODE               VARCHAR2(12) NOT NULL,
  WORKSTATIONCODE        VARCHAR2(12) NOT NULL,
  CUSTOMEROWNED          VARCHAR2(1) NOT NULL,
  CUSTOMERRELATED        VARCHAR2(1) NOT NULL,
  QUALITYGRADECODE       VARCHAR2(1),
  RESIDUALVALUE          NUMBER(15,6),
  CURRENCYCODE           VARCHAR2(3),
  INVOICEBUSINESSUNIT    VARCHAR2(6) NOT NULL,
  AMOUNT                 NUMBER(15,6) NOT NULL,
  STOCKROOMCODE          VARCHAR2(12),
  CHARGETYPE             NUMBER NOT NULL,
  ROWCODE                VARCHAR2(12),
  LOCATIONCODE           VARCHAR2(12),
  AREACODE               VARCHAR2(12),
  MINIMUMAMOUNTCHARGED   VARCHAR2(1)
);
COMMENT ON COLUMN I_OUTOFCIRCULATIONHISTORY.PRIMARYID
  IS 'Can also be a ragged item';
COMMENT ON COLUMN I_OUTOFCIRCULATIONHISTORY.STATUS
  IS '0 = Charge
1 = Free of Charge
2 = Charge Cancelled
3 = Nothing to be charged
4 = No residual value charge';
COMMENT ON COLUMN I_OUTOFCIRCULATIONHISTORY.AMOUNT
  IS 'Round(ResidualValue * Quantity)';
COMMENT ON COLUMN I_OUTOFCIRCULATIONHISTORY.CHARGETYPE
  IS '1 = residual value charge
2 = restocking fee charge
3 = Lease ragged from stock
4 = Buy out';
CREATE INDEX INDX_I_OUTOFCIRCHIST_PROCBU ON I_OUTOFCIRCULATIONHISTORY (PROCESSBUSINESSUNIT);
CREATE INDEX INDX_I_OUTOFCIRCHIST_FORBU ON I_OUTOFCIRCULATIONHISTORY (FORBUSINESSUNIT);
CREATE INDEX INDX_I_OUTOFCIRCHIST_INVBU ON I_OUTOFCIRCULATIONHISTORY (INVOICEBUSINESSUNIT);
CREATE INDEX INDX_I_OUTOFCIRCHIST_REASC ON I_OUTOFCIRCULATIONHISTORY (REASONCODE);
CREATE INDEX INDX_I_OUTOFCIRCHIST_CUST ON I_OUTOFCIRCULATIONHISTORY (CUSTOMERNUMBER);
CREATE INDEX INDX_I_OUTOFCIRCHIST_CONSUMP ON I_OUTOFCIRCULATIONHISTORY (DEPARTMENTNUMBER, CONSUMPTIONPOINTNUMBER);
CREATE INDEX INDX_I_OUTOFCIRCHIST_CURR ON I_OUTOFCIRCULATIONHISTORY (CURRENCYCODE);
CREATE INDEX INDX_I_OUTOFCIRCHIST_PROD ON I_OUTOFCIRCULATIONHISTORY (PRODUCTCODE);
CREATE INDEX INDX_I_OUTOFCIRCHIST_STOCKR ON I_OUTOFCIRCULATIONHISTORY (STOCKROOMCODE);
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT FK_I_OUTHIS_PROCBU FOREIGN KEY (PROCESSBUSINESSUNIT)
  REFERENCES BUSINESSUNIT(CODE);
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT FK_I_OUTHIS_FORBU FOREIGN KEY (FORBUSINESSUNIT)
  REFERENCES BUSINESSUNIT(CODE); 
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT FK_I_OUTHIS_INVBU FOREIGN KEY (INVOICEBUSINESSUNIT)
  REFERENCES BUSINESSUNIT(CODE);
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT FK_I_OUTHIS_CURR FOREIGN KEY (CURRENCYCODE)
  REFERENCES CURRENCY(CODE);
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT FK_I_OUTHIS_STOCKROOM FOREIGN KEY (STOCKROOMCODE)
  REFERENCES STOCKROOM(CODE);
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT FK_I_OUTHIS_REASONCODE  FOREIGN KEY (REASONCODE)
  REFERENCES REASONCODE (CODE);
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_PRODUCTCODE
  CHECK (PRODUCTCODE = UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_CUSTOWNED
  CHECK (CUSTOMEROWNED IN ('Y', 'N'));
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_CUSTRELATED
  CHECK (CUSTOMERRELATED IN ('Y', 'N'));
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_MINAMCHARGED
  CHECK (MINIMUMAMOUNTCHARGED IN ('Y','N'));
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_STATUS
  CHECK (STATUS IN (0,1,2,3,4));
ALTER TABLE I_OUTOFCIRCULATIONHISTORY
  ADD CONSTRAINT CHK_I_OUTHIS_CHARGETYPE
  CHECK (CHARGETYPE IN (1,2,3,4));

prompt
prompt Creating table I_ISSUEHISTORY
prompt ========================================
prompt
CREATE TABLE I_ISSUEHISTORY
(
  PROCESSBUSINESSUNITCODE         VARCHAR2(6)       NOT NULL,
  FORBUSINESSUNITCODE             VARCHAR2(6)       NOT NULL,
  PRIMARYID                       VARCHAR2(24)      NULL,
  REASONCODE                      VARCHAR2(6)       DEFAULT '-' NOT NULL,
  CUSTOMERNUMBER                  NUMBER            NOT NULL,
  WEARERNUMBER                    NUMBER            NULL,
  WEAREREMPLOYMENTNUMBER          NUMBER DEFAULT 1  NULL,
  DISTRIBUTIONPOINTNUMBER         NUMBER            NULL,
  PRODUCTCODE                     VARCHAR2(12)      NOT NULL,
  ASSIGNDATE                      DATE              NOT NULL,
  INCIRCDATE                      DATE              NULL,
  QUANTITY                        NUMBER            NOT NULL,
  ASSIGNYEAR                      NUMBER            NOT NULL,
  ASSIGNWEEK                      NUMBER            NOT NULL,
  ASSIGNDAY                       NUMBER            NOT NULL,
  INCIRCYEAR                      NUMBER            NOT NULL,
  INCIRCWEEK                      NUMBER            NOT NULL,
  INCIRCDAY                       NUMBER            NOT NULL,
  ISSUESTATUS                     NUMBER            NOT NULL,
  WORKSTATIONCODE                 VARCHAR2(12)      NOT NULL,
  CUSTOMEROWNED                   VARCHAR2(1)       NOT NULL,
  CUSTOMERRELATED                 VARCHAR2(1)       NOT NULL,
  ISSUEGRADE                      VARCHAR2(1)       NOT NULL,
  REQUESTEDGRADE                  VARCHAR2(1)       NOT NULL,
  PREPCHARGE                      NUMBER(15,6)      NULL,
  CURRENCY                        VARCHAR2(3)       NULL,
  INVOICEBUSINESSUNITCODE         VARCHAR2(6)       NULL,
  INVOICENUMBER                   NUMBER            NULL,
  AMOUNT                          NUMBER(15,6)      NOT NULL,
  SIZECODE                        VARCHAR2(12)      NOT NULL,
  STOCKROOM                       VARCHAR2(12)      NULL,
  SUBSTITUTEFORPRODUCTCODE        VARCHAR2(12)      NULL,
  SUBFORSIZECODE                  VARCHAR2(12)      NULL,
  WORKORDERNUMBER                 NUMBER            DEFAULT 0 NOT NULL,
  EXPORTDATE                      DATE              NOT NULL,
  SHIPMENTLISTLINE                NUMBER            NULL,
  ORIGINALGRADE                   VARCHAR2(1)       NULL,
  ORIGINALSTOCKDEFPERITEM         VARCHAR2(12)      NULL,
  STOCKROOMLOCATION               VARCHAR2(12)      NULL,
  FROMNONUNIQUESTOCK              VARCHAR2(1)       NULL,
  SPECIALSIZECHARGESTATUS         NUMBER            DEFAULT 0 NOT NULL,
  SPECIALSIZEPRICE                NUMBER            NULL,
  EXCHANGECHARGESTATUS            NUMBER            DEFAULT 0 NOT NULL,
  EXCHANGECHARGEPRICE             NUMBER            NULL
);
COMMENT ON COLUMN I_ISSUEHISTORY.PRIMARYID
  IS 'Can also be a ragged item';
COMMENT ON COLUMN I_ISSUEHISTORY.ISSUESTATUS
  IS '0 = Charge
1 = Free of Charge
2 = Charge Cancelled
3 = Reason code not charged
4 = In free period
5 = No prep price defined';
COMMENT ON COLUMN I_ISSUEHISTORY.AMOUNT
  IS 'Round(PrepCharge * Quantity)';
COMMENT ON COLUMN I_ISSUEHISTORY.SHIPMENTLISTLINE
  IS 'Only filled when the module SHIPMENTLIST is in the license';
COMMENT ON COLUMN I_ISSUEHISTORY.FROMNONUNIQUESTOCK
  IS 'Indicates if item has been made unique upon issue from non-unique stock';
COMMENT ON COLUMN I_ISSUEHISTORY.SPECIALSIZECHARGESTATUS
  IS 'Only used for module SPECIALSIZECHARGE 
0 = Charge
1 = Free of Charge
2 = Charge Cancelled
3 = Reason code not charged
4 = In free period
5 = No prep price defined
6 = Customer set as no charge';
COMMENT ON COLUMN I_ISSUEHISTORY.SPECIALSIZEPRICE
  IS'Only used for module SPECIALSIZECHARGE';
COMMENT ON COLUMN I_ISSUEHISTORY.EXCHANGECHARGESTATUS
  IS 'Only used for module GARMENTEXCHANGECHARGE
0 = Charge
1 = Free of Charge
2 = Charge Cancelled
3 = Reason code not charged
4 = not used (but kept for commonality with issuesstatus)
5 = No exchange charge price defined
6 = Customer set as no charge';
COMMENT ON COLUMN I_ISSUEHISTORY.EXCHANGECHARGEPRICE
  IS 'Only used for module GARMENTEXCHANGECHARGE';
CREATE INDEX INDX_I_ISSUEHIST_PROCBU ON I_ISSUEHISTORY (PROCESSBUSINESSUNITCODE);
CREATE INDEX INDX_I_ISSUEHIST_FORBU ON I_ISSUEHISTORY (FORBUSINESSUNITCODE);
CREATE INDEX INDX_I_ISSUEHIST_INVBU ON I_ISSUEHISTORY (INVOICEBUSINESSUNITCODE);
CREATE INDEX INDX_I_ISSUEHIST_REASC ON I_ISSUEHISTORY (REASONCODE);
CREATE INDEX INDX_I_ISSUEHIST_CUST ON I_ISSUEHISTORY (CUSTOMERNUMBER);
CREATE INDEX INDX_I_ISSUEHIST_CURR ON I_ISSUEHISTORY (CURRENCY);
CREATE INDEX INDX_I_ISSUEHIST_PROD ON I_ISSUEHISTORY (PRODUCTCODE);
CREATE INDEX INDX_I_ISSUEHIST_STOCKR ON I_ISSUEHISTORY (STOCKROOM);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUEHIS_PROCBU FOREIGN KEY (PROCESSBUSINESSUNITCODE)
  REFERENCES BUSINESSUNIT(CODE);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUEHIS_FORBU FOREIGN KEY (FORBUSINESSUNITCODE)
  REFERENCES BUSINESSUNIT(CODE); 
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUEHIS_INVBU FOREIGN KEY (INVOICEBUSINESSUNITCODE)
  REFERENCES BUSINESSUNIT(CODE);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUEHIS_CURR FOREIGN KEY (CURRENCY)
  REFERENCES CURRENCY(CODE);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUE_STOCKROOM FOREIGN KEY (STOCKROOM)
  REFERENCES STOCKROOM(CODE);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUE_REASONCODE  FOREIGN KEY (REASONCODE)
  REFERENCES REASONCODE (CODE);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT FK_I_ISSUE_WEARER  FOREIGN KEY (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER)
  REFERENCES I_WEARER (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_PRODUCTCODE
  CHECK (PRODUCTCODE = UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_SUBSTPRCODE
  CHECK (SUBSTITUTEFORPRODUCTCODE = UPPER(TRIM(SUBSTITUTEFORPRODUCTCODE)));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_SUBSTSZECODE
  CHECK (SUBFORSIZECODE = UPPER(TRIM(SUBFORSIZECODE)));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_CUSTOWNED
  CHECK (CUSTOMEROWNED IN ('Y', 'N'));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_CUSTRELATED
  CHECK (CUSTOMERRELATED IN ('Y', 'N'));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_ISSUESTATUS
  CHECK (ISSUESTATUS IN (0,1,2,3,4,5));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_SPSIZECHRGSTATUS
  CHECK (SPECIALSIZECHARGESTATUS IN (0,1,2,3,4,5,6));
ALTER TABLE I_ISSUEHISTORY
  ADD CONSTRAINT CHK_I_ISSHIS_EXCHGCHRGSTATUS
  CHECK (EXCHANGECHARGESTATUS IN (0,1,2,3,4,5,6));

prompt
prompt Creating table I_EMBLEMHISTORY
prompt ========================================
prompt
CREATE TABLE I_EMBLEMHISTORY
(
  BUSINESSUNITCODE                VARCHAR2(6)       NOT NULL,
  INVOICEBUSINESSUNITCODE         VARCHAR2(6)       NOT NULL,
  PRIMARYID                       VARCHAR2(24)      NULL,
  ISSUEDATE                       DATE              NOT NULL,
  EMBLEMTYPE                      NUMBER            NOT NULL,
  QUANTITY                        NUMBER            NOT NULL,
  YEAR                            NUMBER            NOT NULL,
  WEEK                            NUMBER            NOT NULL,
  DAY                             NUMBER            NOT NULL,
  CUSTOMERNUMBER                  NUMBER            NULL,
  STATUS                          NUMBER            NOT NULL,
  WEARERNUMBER                    NUMBER            NULL,
  WEAREREMPLOYMENTNUMBER          NUMBER DEFAULT 1  NULL,
  DISTRIBUTIONPOINTNUMBER         NUMBER            NULL,
  PRODUCTCODE                     VARCHAR2(12)      NOT NULL,
  SIZECODE                        VARCHAR2(12)      NULL,
  WORKSTATIONCODE                 VARCHAR(12)       NOT NULL,
  REASONCODE                      VARCHAR2(6)       NOT NULL,
  EMBLEMCHARGE                    NUMBER(15,6)      NULL,
  CURRENCYCODE                    VARCHAR2(3)       NULL,
  EMBLEMPRODUCTCODE               VARCHAR2(12)      NULL,
  EMBLEMTEMPLATE                  VARCHAR2(6)       NULL,
  INVOICENUMBER                   NUMBER            NULL,
  AMOUNT                          NUMBER(15,6)      NOT NULL,
  STOCKROOMCODE                   VARCHAR2(12)      NULL,
  FORBUSINESSUNITCODE             VARCHAR2(6)       NOT NULL,
  ASSIGNDATE                      DATE              NOT NULL,
  INCIRCDATE                      DATE              NULL,
  ISSUEHISTORYQUANTITY            NUMBER            NOT NULL,
  ASSIGNYEAR                      NUMBER            NOT NULL,
  ASSIGNWEEK                      NUMBER            NOT NULL,
  ASSIGNDAY                       NUMBER            NOT NULL,
  INCIRCYEAR                      NUMBER            NOT NULL,
  INCIRCWEEK                      NUMBER            NOT NULL,
  INCIRCDAY                       NUMBER            NOT NULL,
  ISSUESTATUS                     NUMBER            NOT NULL,
  CUSTOMEROWNED                   VARCHAR2(1)       NOT NULL,
  CUSTOMERRELATED                 VARCHAR2(1)       NOT NULL,
  ISSUEGRADE                      VARCHAR2(1)       NOT NULL,
  REQUESTEDGRADE                  VARCHAR2(1)       NOT NULL,
  PREPCHARGE                      NUMBER(15,6)      NULL,
  CURRENCY                        VARCHAR2(3)       NULL,
  ISSUEHISTORYAMOUNT              NUMBER(15,6)      NOT NULL,
  SUBSTITUTEFORPRODUCTCODE        VARCHAR2(12)      NULL,
  SUBFORSIZECODE                  VARCHAR2(12)      NULL,
  WORKORDERNUMBER                 NUMBER            DEFAULT 0 NOT NULL,
  EXPORTDATE                      DATE              NOT NULL,
  SHIPMENTLISTLINE                NUMBER            NULL,
  ORIGINALGRADE                   VARCHAR2(1)       NULL,
  ORIGINALSTOCKDEFPERITEM         NUMBER            NULL,
  STOCKROOMLOCATION               VARCHAR2(12)      NULL,
  FROMNONUNIQUESTOCK              VARCHAR2(1)       NULL,
  SPECIALSIZECHARGESTATUS         NUMBER            DEFAULT 0 NOT NULL,
  SPECIALSIZEPRICE                NUMBER            NULL,
  EXCHANGECHARGESTATUS            NUMBER            DEFAULT 0 NOT NULL,
  EXCHANGECHARGEPRICE             NUMBER            NULL
);
COMMENT ON COLUMN I_EMBLEMHISTORY.PRIMARYID
  IS 'Can also be a ragged item';
COMMENT ON COLUMN I_EMBLEMHISTORY.EMBLEMTYPE
  IS '1= Company
2 = Name
3 = Other/ Not Defined';
COMMENT ON COLUMN I_EMBLEMHISTORY.STATUS
  IS '0 = Charge
1 = Free of Charge
2 = Charge Cancelled';
CREATE INDEX INDX_I_EMBLHIST_BU ON I_EMBLEMHISTORY (BUSINESSUNITCODE);
CREATE INDEX INDX_I_EMBLHIST_INVBU ON I_EMBLEMHISTORY (INVOICEBUSINESSUNITCODE);
CREATE INDEX INDX_I_EMBLHIST_REASC ON I_EMBLEMHISTORY (REASONCODE);
CREATE INDEX INDX_I_EMBLHIST_CUST ON I_EMBLEMHISTORY (CUSTOMERNUMBER);
CREATE INDEX INDX_I_EMBLHIST_CURR ON I_EMBLEMHISTORY (CURRENCYCODE);
CREATE INDEX INDX_I_EMBLHIST_PROD ON I_EMBLEMHISTORY (PRODUCTCODE);
CREATE INDEX INDX_I_EMBLHIST_EPROD ON I_EMBLEMHISTORY (EMBLEMPRODUCTCODE);
CREATE INDEX INDX_I_EMBLHIST_STOCKR ON I_EMBLEMHISTORY (STOCKROOMCODE);
CREATE INDEX INDX_I_EMBLHIST_DP ON I_EMBLEMHISTORY (DISTRIBUTIONPOINTNUMBER);
CREATE INDEX INDX_I_EMBLHIST_ET ON I_EMBLEMHISTORY (EMBLEMTEMPLATE);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT FK_I_EMBLHIS_BU FOREIGN KEY (BUSINESSUNITCODE)
  REFERENCES BUSINESSUNIT(CODE);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT FK_I_EMBLHIS_INVBU FOREIGN KEY (INVOICEBUSINESSUNITCODE)
  REFERENCES BUSINESSUNIT(CODE);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT FK_I_EMBLHIS_REASONCODE  FOREIGN KEY (REASONCODE)
  REFERENCES REASONCODE (CODE);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT FK_I_EMBLHIS_CURR FOREIGN KEY (CURRENCYCODE)
  REFERENCES CURRENCY(CODE);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT FK_I_EMBLHIS_STOCKROOM FOREIGN KEY (STOCKROOMCODE)
  REFERENCES STOCKROOM(CODE);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT FK_I_EMBLHIS_WEARER FOREIGN KEY (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER)
  REFERENCES I_WEARER (CUSTOMERNUMBER, WEARERNUMBER, WEAREREMPLOYMENTNUMBER);
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT CHK_I_EMBLHIS_PRODUCTCODE
  CHECK (PRODUCTCODE = UPPER(TRIM(PRODUCTCODE)));
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT CHK_I_EMBLHIS_EPRODCODE
  CHECK (EMBLEMPRODUCTCODE = UPPER(TRIM(EMBLEMPRODUCTCODE)));
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT CHK_I_EMBLHIS_SIZECODE
  CHECK (SIZECODE = UPPER(TRIM(SIZECODE)));
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT CHK_I_EMBLHIS_ETYPE
  CHECK (EMBLEMTYPE IN (1,2,3));
ALTER TABLE I_EMBLEMHISTORY
  ADD CONSTRAINT CHK_I_EMBLHIS_STATUS
  CHECK (STATUS IN (0,1,2));

prompt
prompt Creating table I_PRICEINDEX
prompt ========================================
prompt
CREATE TABLE I_PRICEINDEX 
(
   PRICEINDEXCODE    VARCHAR2(6) NOT NULL,
   DESCRIPTION       VARCHAR2(30)NOT NULL,
   STARTDATE         DATE,
   PERCWASHLOG       NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCWASHCOG       NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCRENT          NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCSALES         NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCREPLACE       NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCWEIGHT        NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCEMBLEM        NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCREPAIR        NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCINSURANCE    NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCSPECIALCHARGE NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCWEARER        NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCWEARERINV     NUMBER(8,4) DEFAULT 0.0000 NOT NULL,
   PERCSPECIALSIZECHARGE  NUMBER(8,4) DEFAULT 0.0000 NOT NULL
);
COMMENT ON COLUMN I_PRICEINDEX.PERCWASHLOG
  IS 'Percentage Wash Laundry Owned Between -100.0000 and +100.0000';
COMMENT ON COLUMN I_PRICEINDEX.PERCWASHCOG
  IS 'Percentage Wash Laundry Owned Between -100.0000 and +100.0000';
COMMENT ON COLUMN I_PRICEINDEX.PERCRENT
  IS 'Percentage Rent Between -100.0000 and +100.0000';
COMMENT ON COLUMN I_PRICEINDEX.PERCSALES
  IS 'Percentage Sales Between -100.0000 and +100.0000';
COMMENT ON COLUMN I_PRICEINDEX.PERCREPLACE
   IS 'Percentage Replacement Between -100.0000 and +100.0000';
COMMENT ON COLUMN I_PRICEINDEX.PERCWEIGHT
   IS 'Percentage Weight Between -100.0000 and +100.0000';
COMMENT ON COLUMN I_PRICEINDEX.PERCEMBLEM
   IS 'Percentage Emblem Between -100.0000 and +100.0000'; 
COMMENT ON COLUMN I_PRICEINDEX.PERCREPAIR
   IS 'Percentage Repair Between -100.0000 and +100.0000';  
COMMENT ON COLUMN I_PRICEINDEX.PERCINSURANCE
   IS 'Percentage Insurance Between -100.0000 and +100.0000';     
COMMENT ON COLUMN I_PRICEINDEX.PERCSPECIALCHARGE
   IS 'Percentage Special Charges Between -100.0000 and +100.0000';  
COMMENT ON COLUMN I_PRICEINDEX.PERCWEARER
   IS 'Percentage Wearer Between -100.0000 and +100.0000'; 
COMMENT ON COLUMN I_PRICEINDEX.PERCWEARERINV
   IS 'Percentage Wearer Inventory Between -100.0000 and +100.0000'; 
COMMENT ON COLUMN I_PRICEINDEX.PERCSPECIALSIZECHARGE
   IS 'Percentage Special Size Charge Between -100.0000 and +100.0000'; 
ALTER TABLE I_PRICEINDEX
  ADD CONSTRAINT XPK_I_PRICEINDEX PRIMARY KEY (PRICEINDEXCODE, STARTDATE);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCWASHLOG
  CHECK (PERCWASHLOG BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCWASHCOG
  CHECK (PERCWASHCOG BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCRENT
  CHECK (PERCRENT BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCSALES
  CHECK (PERCSALES BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCREPLACE
  CHECK (PERCREPLACE BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCWEIGHT
  CHECK (PERCWEIGHT BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCEMBLEM
  CHECK (PERCEMBLEM BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCREPAIR
  CHECK (PERCREPAIR BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCINSURANCE
  CHECK (PERCINSURANCE BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCSPECIALCHARGE
  CHECK (PERCSPECIALCHARGE BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCWEARER
  CHECK (PERCWEARER BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCWEARERINV
  CHECK (PERCWEARERINV BETWEEN -100.0000 AND 100.0000);
ALTER TABLE I_PRICEINDEX ADD CONSTRAINT CHK_I_PRICEINDEX_PERCSPECIALSIZECHARGE
  CHECK (PERCSPECIALSIZECHARGE BETWEEN -100.0000 AND 100.0000);

prompt
prompt
prompt Creating table I_CLEANROOMUIDELIVERY
prompt ======================
prompt
CREATE TABLE I_CLEANROOMUIDELIVERY
(
SCANDATETIME    DATE           NOT NULL,
PRIMARYID       VARCHAR2(24)   NOT NULL,
BUSINESSUNIT    VARCHAR2(6) NOT NULL,
IDCODESEQUENCENUMBER NUMBER DEFAULT 1 NOT NULL,
PACKINGNOTENUMBER   NUMBER     NOT NULL
);
comment on column I_CLEANROOMUIDELIVERY.scandatetime
  is 'Scan date time (Oracle date)';
comment on column I_CLEANROOMUIDELIVERY.PRIMARYID
 is 'Barcode or Primary ID or barcode/chipcode etc';
comment on column I_CLEANROOMUIDELIVERY.PACKINGNOTENUMBER
 is 'Must exist in I_PACKINGNOTE';
CREATE INDEX INDX_I_CLEANROOMUIDELIVERY_BU ON I_CLEANROOMUIDELIVERY (BUSINESSUNIT);
ALTER TABLE I_CLEANROOMUIDELIVERY
ADD CONSTRAINT PK_I_CLEANROOMUIDELIVERY PRIMARY KEY(PRIMARYID,PACKINGNOTENUMBER,BUSINESSUNIT);
ALTER TABLE I_CLEANROOMUIDELIVERY
ADD CONSTRAINT FK_I_CLEANROOMUIDELIVERY_PRIMARYID FOREIGN KEY(BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
REFERENCES I_UNIQUEITEM(BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)ON DELETE CASCADE;
ALTER TABLE I_CLEANROOMUIDELIVERY
ADD CONSTRAINT FK_I_CLEANROOMUIDELIVERY_PNNUMBER FOREIGN KEY(PACKINGNOTENUMBER)
REFERENCES I_PACKINGNOTE(NOTENUMBER);

prompt
prompt Creating table I_ALLOCATIONTRANS
prompt ========================================
prompt 
CREATE TABLE I_ALLOCATIONTRANS
(
  ALLOCATIONDATE         DATE,
  FROMCUSTOMERNUMBER     NUMBER,
  FROMDEPARTMENTNUMBER   NUMBER NOT NULL,
  FROMDISTRIBPOINTNUMBER NUMBER,
  TOCUSTOMERNUMBER       NUMBER,
  TODEPARTMENTNUMBER     NUMBER,
  TODISTRIBPOINTNUMBER   NUMBER,
  PRODUCTCODE            VARCHAR2(12),
  SIZECODE               VARCHAR2(12),
  FMCODE                 VARCHAR2(12),
  STOCKCOUNTCODE         VARCHAR2(6),
  CSCUSTOMERNUMBER       NUMBER,
  TRANSACTIONTYPE        NUMBER,
  PARLEVEL               NUMBER,
  ONHAND                 NUMBER,
  STOCKED                NUMBER,
  ORIGIN                 NUMBER,
  LOGINNAME              VARCHAR2(80),
  EMERGENCY              NUMBER,
  RETURNED               NUMBER
);  
create unique index INDX1_I_ALLOCTRANS on I_ALLOCATIONTRANS (ALLOCATIONDATE, FROMCUSTOMERNUMBER, TODEPARTMENTNUMBER, TODISTRIBPOINTNUMBER, PRODUCTCODE, SIZECODE, FMCODE);

prompt
prompt Creating table I_UNIQUEITEMIMAGE
prompt ========================================
prompt 
CREATE TABLE I_UNIQUEITEMIMAGE
(
  BUSINESSUNIT         VARCHAR2(6) NOT NULL,
  PRIMARYID            VARCHAR2(24) NOT NULL,
  IDCODESEQUENCENUMBER NUMBER DEFAULT 1 NOT NULL,
  IMAGECODE            VARCHAR2(12) NOT NULL,
  SCAN_ID              NUMBER,
  IMAGETYPE            NUMBER DEFAULT 3 NOT NULL
);
COMMENT ON COLUMN I_UNIQUEITEMIMAGE.IMAGETYPE IS 'Always 3 Garments ( Hidden column )';
ALTER TABLE I_UNIQUEITEMIMAGE ADD CONSTRAINT PK_I_UNIQUEITEMIMAGE PRIMARY KEY (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER, IMAGECODE);
CREATE INDEX INDX_FK_I_UNIQUEITEMIMAGE_IMAGE ON I_UNIQUEITEMIMAGE (IMAGETYPE, IMAGECODE);
CREATE INDEX INDX_FK_I_UNIQUEITEMIMAGE_PRIMARYID ON I_UNIQUEITEMIMAGE (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER);
CREATE INDEX INDX_I_UNIQUEITEMIMAGE_BU ON I_UNIQUEITEMIMAGE (BUSINESSUNIT);
ALTER TABLE I_UNIQUEITEMIMAGE ADD CONSTRAINT FK_I_UNIQUEITEMIMAGE_UNIQUEITEM FOREIGN KEY (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER)
  REFERENCES I_UNIQUEITEM (BUSINESSUNIT, PRIMARYID, IDCODESEQUENCENUMBER) ON DELETE CASCADE;
ALTER TABLE I_UNIQUEITEMIMAGE  ADD CONSTRAINT FK_PK_I_UNIQUEITEMIMAGE_IMAGE FOREIGN KEY (IMAGETYPE, IMAGECODE)
  REFERENCES I_IMAGE (IMAGETYPE, IMAGECODE) ON DELETE CASCADE;
ALTER TABLE I_UNIQUEITEMIMAGE ADD CONSTRAINT CHK_I_UNIQUEITEMIMAGE_IMAGETYPE CHECK (IMAGETYPE = 3);

----Triggers-----------------------------------------------
prompt
prompt Creating triggers for Product TOM 
prompt =================================
prompt
create or replace trigger i_productlistpercustomer_tom
  before insert on i_productlistpercustomer
  for each row
begin
  select p.typeofmerchandise
  into   :new.typeofmerchandise
  from   i_product p
  where  p.code = :new.productcode;
exception
  when others then
    :new.typeofmerchandise := 2;
end i_productlistpercustomer_tom;
/
create or replace trigger i_contractproduct_tom
  before insert on i_contractproduct
  for each row
begin
  select p.typeofmerchandise
  into   :new.typeofmerchandise
  from   i_product p
  where  p.code = :new.productcode;
exception
  when others then
    :new.typeofmerchandise := 2;
end i_contractproduct_tom;
/
create or replace trigger i_productsize_tom
  before insert on i_productsize
  for each row
begin
  select p.typeofmerchandise
  into   :new.typeofmerchandise
  from   i_product p
  where  p.code = :new.productcode;
exception
  when others then
    :new.typeofmerchandise := 2;
end i_productsize_tom;
/
create or replace trigger i_uniquepool_tom
  before insert on i_uniquepool
  for each row
begin
  select p.typeofmerchandise
  into   :new.typeofmerchandise
  from   i_product p
  where  p.code = :new.productcode;
exception
  when others then
    :new.typeofmerchandise := 2;
end i_uniquepool_tom;
/
create or replace trigger trg_i_uniqueitem_tom
  before insert on i_uniqueitem
  for each row
begin
  select p.typeofmerchandise
  into   :new.typeofmerchandise
  from   i_product p
  where  p.code = :new.productcode;
exception
  when others then
    :new.typeofmerchandise := 2;
end trg_i_uniqueitem_tom;
/
create or replace trigger trg_address_streetlength_check
  before insert or update on address
  for each row
declare
  --trg_address_streetlength_check version 0.1
  gv_value systemsetting.value%type;
begin
  select max(st.value) into gv_value from systemsetting st where st.name = 'STREETMAXLENGTH';
  if nvl(gv_value, 0) = 0 then
    begin
      if length(:new.street) > 30 then
        begin
          :new.street := substr(trim(:new.street), 1, 30);
        end;
      end if;
      if length(:new.street2) > 30 then
        begin
          :new.street2 := substr(trim(:new.street2), 1, 30);
        end;
      end if;
      if length(:new.street3) > 30 then
        begin
          :new.street3 := substr(trim(:new.street3), 1, 30);
        end;
      end if;
    end;
  end if;
end trg_address_streetlength_check;
/
create or replace function abs_encrypt wrapped 
a000000
369
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
8
253 1ad
TTq8X+MPE9wE9YQKiXU9NsqcM6gwg/D3Lq5qfHRAOj68Yvfo5dX9Dz3I8XdMCjKhiRqEAOmp
U7imNnHO/hSM9brGN3ZR2zMeemReYQlTo6FTqs6lrpbQuw8gTxp3GeU850ajFaeIzH+3zHx9
owMoZ3n79YuxtHmTHSQeeKHJMZSl/6gCE2xZw38Xfn+YibFUJsHqbl2mNcELAoFAVUTetPpC
YIQ5Y3yQSlQZMqs1eDyxJe6eLoorpfCBmJ6NS8ofcTDtb58tnOBSUCEM64mLduqvsndsdrQD
ygXo++prX9LtagQFgcXmOr3eyhFMttD0cDxCsAZYdLcOSQTviyKh2PNLNHMDMalasC9gL9lg
hFgVtStwGPzvmfdLxHs/z86ddeeu5eG2/1aHR/j9rcJg3hyw21OBEHok+Dm+ixOD
/
create or replace trigger trg_i_customerach
  before insert on i_customerach
  for each row
begin
  :new.routingnumber := abs_encrypt(:new.routingnumber);
  :new.accountnumber := abs_encrypt(:new.accountnumber);
end trg_i_customerach;
/
---------THE END--------------------------------------------
