CREATE OR REPLACE VIEW V_WORKORDERSPERPURCHASEORDER AS
select WO.WORKORDER_ID,
       WO.WORKORDERNUMBER,
       WO.REQUESTDATE,
       WO.NEEDEDDATE,
       CU.CUSTOMER_ID,
       CU.CUSTOMERNUMBER,
       CU.NAME CUSTOMERNAME,
       W.WEARER_ID,
       W.WEARERNUMBER,
       W.FULLNAME WEARERNAME,
       W.SEARCHNAME,
       PRD.CODE PRODCODE,
       SD.CODE SIZECODE,
       (select PD.DESCRIPTION
          from PRODUCT_DESC PD
         where PRD.PRODUCT_ID = PD.PRODUCT_ID
           and PD.LANGUAGE_ID = LAN.LANGUAGE_ID) PRODDESC,
       POH.PURCHASEORDERNUMBER,
       WOL.QUANTITYORDERED WOLORDERED,
       POL.QUANTITYORDERED POLORDERED,
       SU.SUPPLIERNUMBER,
       SU.NAME SUPPNAME,
       LAN.CODE LAN_CODE
  from WORKORDER           WO,
       WORKORDERLINE       WOL,
       PURCHASEORDERLINE   POL,
       WEAREREMPLOYMENT    WE,
       WEARER              W,
       CUSTOMER            CU,
       PRODUCT             PRD,
       SIZEDEFINITION      SD,
       PURCHASEORDERHEADER POH,
       SUPPLIER            SU,
       LANGUAGES           LAN
where WO.WORKORDER_ID = WOL.WORKORDER_ID
   and WO.WEAREREMPLOYMENT_LINK_ID = WE.WEAREREMPLOYMENT_ID
   and WE.WEARER_ID = W.WEARER_ID
   and W.CUSTOMER_ID = CU.CUSTOMER_ID
   and WOL.PURCHASEORDERLINE_ID = POL.PURCHASEORDERLINE_ID
   and WOL.PRODUCT_LINK_ID = PRD.PRODUCT_ID
   and WOL.SIZEDEFINITION_LINK_ID = SD.SIZEDEFINITION_ID
   and POL.PURCHASEORDERHEADER_ID = POH.PURCHASEORDERHEADER_ID
   and POH.SUPPLIER_ID = SU.SUPPLIER_ID
union all
select WO.WORKORDER_ID,
       WO.WORKORDERNUMBER,
       WO.REQUESTDATE,
       WO.NEEDEDDATE,
       CU.CUSTOMER_ID,
       CU.CUSTOMERNUMBER,
       CU.NAME CUSTOMERNAME,
       W.WEARER_ID,
       W.WEARERNUMBER,
       W.FULLNAME WEARERNAME,
       W.SEARCHNAME,
       PRD.CODE PRODCODE,
       SD.CODE SIZECODE,
       (select PD.DESCRIPTION
          from PRODUCT_DESC PD
         where PRD.PRODUCT_ID = PD.PRODUCT_ID
           and PD.LANGUAGE_ID = LAN.LANGUAGE_ID) PRODDESC,
       POH.PURCHASEORDERNUMBER,
       WOL.QUANTITYORDERED WOLORDERED,
       POL.QUANTITYORDERED POLORDERED,
       SU.SUPPLIERNUMBER,
       SU.NAME SUPPNAME,
       LAN.CODE LAN_CODE
  from WORKORDER                 WO,
       WORKORDERLINE             WOL,
       WORKORDERLINEPURCHORDLINE WOLPOL,
       PURCHASEORDERLINE         POL,
       WEAREREMPLOYMENT          WE,
       WEARER                    W,
       CUSTOMER                  CU,
       PRODUCT                   PRD,
       SIZEDEFINITION            SD,
       PURCHASEORDERHEADER       POH,
       SUPPLIER                  SU,
       LANGUAGES                 LAN
where WO.WORKORDER_ID = WOL.WORKORDER_ID
   and WO.WEAREREMPLOYMENT_LINK_ID = WE.WEAREREMPLOYMENT_ID
   and WE.WEARER_ID = W.WEARER_ID
   and W.CUSTOMER_ID = CU.CUSTOMER_ID
   and WOL.WORKORDERLINE_ID = WOLPOL.WORKORDERLINE_ID
   and WOLPOL.PURCHASEORDERLINE_ID = POL.PURCHASEORDERLINE_ID
   and WOL.PRODUCT_LINK_ID = PRD.PRODUCT_ID
   and WOL.SIZEDEFINITION_LINK_ID = SD.SIZEDEFINITION_ID
   and POL.PURCHASEORDERHEADER_ID = POH.PURCHASEORDERHEADER_ID
   and POH.SUPPLIER_ID = SU.SUPPLIER_ID
/