--ABS-158408
ALTER TABLE ERP_I_WORKORDERLINE MODIFY WORKORDERNUMBER NULL;
ALTER TABLE ERP_I_WORKORDERLINE MODIFY QUANTITYCANCELED NULL;
ALTER TABLE ERP_I_WORKORDER MODIFY WORKORDERNUMBER NULL;
COMMENT ON COLUMN ERP_I_WORKORDER.WORKORDERNUMBER IS 'When filled it is an update of an existing workorder cancelling qty''s. When left blank, it is inserting a new workorder';

ALTER TABLE ERP_I_WORKORDER ADD( 
 CUSTOMERNUMBER         NUMBER NULL,
 WEAREREMPLOYMENTNUMBER NUMBER NULL,
 REASONCODE             VARCHAR2(6) DEFAULT '-' NULL,
 ROUTENUMBER            NUMBER NULL,
 ROUTEDAYNUMBER         NUMBER NULL,
 REQUESTDATE            DATE NULL,
 ENTRYDATE              DATE NULL,
 NEEDEDDATE             DATE NULL,
 EXPECTEDCOMPLETIONDATE DATE NULL,
 REFERENCENUMBER        VARCHAR2(15) NULL,
 BILLTOCUSTOMERRELATED  VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WO_BILLTOCUSTOMERRELATED CHECK (BILLTOCUSTOMERRELATED IN ('Y', 'N')),
 DELIVERFROM            NUMBER DEFAULT 3 NULL CONSTRAINT CHK_ERP_I_WO_DELIVERFROM CHECK (DELIVERFROM BETWEEN 0 AND 3),
 CUSTOMEROWNED          VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WO_CUSTOMEROWNED CHECK (CUSTOMEROWNED IN ('Y', 'N')),
 ALLOWPHASEDELIVERY     VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WO_ALLOWPHASEDELIVERY CHECK (ALLOWPHASEDELIVERY IN ('Y','N')),
 LABELSPRINTED          VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WO_LABELSPRINTED CHECK (LABELSPRINTED IN ('Y','N')),
 EMBLEMPICKLISTPRINTED  VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WO_EMBLEMPICKLISTPRINTED CHECK (EMBLEMPICKLISTPRINTED IN ('Y','N')),
 PICKLISTPRINTED        VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WO_PICKLISTPRINTED CHECK (PICKLISTPRINTED IN ('Y','N')),
 REMARK                 VARCHAR2(1000) NULL,
 STARTRENTFROM          NUMBER DEFAULT 0 NULL,
 STARTRENTDATE          DATE NULL
);
COMMENT ON COLUMN ERP_I_WORKORDER.DELIVERFROM IS '0=To be determined
1=Direct order from supplier 
2=Stock 
3=N/A (Not applicable) default';
COMMENT ON COLUMN ERP_I_WORKORDER.STARTRENTFROM IS '0=N/A (Not applicable) default
1=Date of Issue
2=Moment of delivery (outscan)
3=Moment of taking in use (inscan or desk issue, dispenser issue)
4=Date <enter future date>
5=Requested delivery date';

ALTER TABLE ERP_I_WORKORDERLINE ADD(
FINISHINGMETHODCODE VARCHAR2(6) NULL,
REASONCODE          VARCHAR2(6) DEFAULT '-' NULL,
CODEUNIQUELY        VARCHAR2(1) DEFAULT 'N' NULL CONSTRAINT CHK_ERP_I_WOL_CODEUNIQUELYD CHECK (CODEUNIQUELY IN ('Y','N')),
QUANTITYORDERED     NUMBER NULL,
QUANTITYFILLED      NUMBER DEFAULT 0 NULL,
EXPECTEDDATE        DATE NULL,
MODIFICATIONCODE1   VARCHAR2(10) NULL,
MODIFICATIONCODE2   VARCHAR2(10) NULL,
MODIFICATIONCODE3   VARCHAR2(10) NULL,
INSTRUCTIONS        VARCHAR2(300) NULL,
EMBLEMTEMPLATECODE  VARCHAR2(6) NULL
);

ALTER TABLE ERP_I_WORKORDERLINE DROP CONSTRAINT PK_ERP_I_WORKORDERLINE;
ALTER TABLE ERP_I_WORKORDERLINE ADD 
 CONSTRAINT PK_ERP_I_WORKORDERLINE UNIQUE (TRANSFER_ID, WORKORDERNUMBER, QUALITYGRADECODE, PRODUCTCODE, SIZECODE, FINISHINGMETHODCODE);
