create or replace view v_reportorder as
select wo.webordernumber, wo.deliverydate, wo.weborder_id,
       (select dd.description from day_desc dd where dd.language_id = lan.language_id and dd.day_id =  to_char(wo.deliverydate, 'D')) daydesc,
       wo.customerreference, wol.quantityordered,
       wd.department_id webuserdepartment_id,
       wu.webuser_id, wus.websession_id,
       (select p.code from product_link p where p.product_link_id = wol.product_link_id) productcode,
       (select pd.description from product_link_desc pd where wol.product_link_id = pd.product_link_id and pd.language_id = lan.language_id) productdesc,
       (select s.code from sizedefinition_link s where s.sizedefinition_link_id = wol.sizedefinition_link_id) sizecode,
       (select f.code from finishingmethod f where f.finishingmethod_id = wol.finishingmethod_id) fm_code,
       distr.distributionpointnumber, distr.description distr_desc,
       cl.customernumber, cl.name customername,
       dep.departmentnumber, dep.description dep_desc, dep.department_id ,
       lan.code languagecode
from weborder wo, weborderline wol, customer_link cl, languages lan,
     department dep , distributionpoint_link distr,
     webuser wu,
     webusercustomer wuc left outer join webuserdepartment wd on (wuc.webusercustomer_id=wd.webusercustomer_id) , --!!!
     webusersession wus
where wo.weborder_id = wol.weborder_id
      and wo.customer_link_id = cl.customer_link_id
      and wuc.customer_id = cl.customer_id
      and wuc.webuser_id = wu.webuser_id
      and dep.customer_id = cl.customer_id
      and distr.department_link_id = dep.department_id
      and wol.distributionpoint_link_id = distr.distributionpoint_link_id
      and wus.customer_id = cl.customer_id
/
