/*order 502513*/      
      /*
      CHANGE REPORT for Table PURCHASEORDERHEADER
          - Changing column definition of ORIGIN
      ACTION is ALTER or modify Table PURCHASEORDERHEADER
      */

COMMENT ON COLUMN PURCHASEORDERHEADER.ORIGIN IS '1 = Purchase request
2 = Manual created
3 = Conversion
4 = Work order approval
5 = Work order status control';


update purchaseorderheader h
set    h.ordertype = 0
where  h.ordertype is null
or     h.ordertype not between 0 and 2;

alter table purchaseorderheader
  add ( constraint ORDERTYPE_VALID
                   CHECK (ORDERTYPE BETWEEN 0 AND 2));


update purchaseorderheader h
set    h.origin = 2
where  h.origin is null
or     h.origin not between 1 and 5;
  
alter table purchaseorderheader
  add ( constraint ORIGIN_VALID
                   CHECK (ORIGIN BETWEEN 1 AND 5));


update purchaseorderheader h
set    h.priority = 2
where  h.priority is null
or     h.priority not in (1, 2, 3);
  
alter table purchaseorderheader
  add ( constraint PRIORITY_VALIDATION
                   CHECK (PRIORITY BETWEEN 1 AND 3));


