Saturday 24 March 2012

po print correct

select poh.segment1 PO_Number,poh.REVISION_NUM, papf.full_name,aps.vendor_name Vendor_Name,apsa.address_line1||','||apsa.address_line2||','||apsa.address_line3
||','||apsa.address_line4||','||apsa.city||','||apsa.zip Vendor_Address,TO_CHAR(TO_DATE(poh.CREATION_DATE,'DD-MON-RRRR'))CREATION_DATE,
TO_CHAR(TO_DATE(SYSDATE,'DD-MON-RRRR')) PRINT_DATE,TO_CHAR(TO_DATE(poh.REVISED_DATE,'DD-MON-RRRR'))REVISED_DATE,
decode(poh.authorization_status ,'APPROVED',poh.authorization_status,'DRAFT') Status, poh.type_lookup_code PO_Type,poh.currency_code,
poh.user_hold_flag on_hold, poh.freight_terms_lookup_code delivery_mode,poh.quote_vendor_quote_number supplier_quote_number,
poh.attribute1 Insurance,apt.name payment_term,pol.line_num||'.'||rsl.line_num line_number,pltv.line_type line_type
,(select segment1
  from mtl_system_items_b
  where inventory_item_id=pol.item_id
  and organization_id =prl.destination_organization_id) Item_code
, pol.item_description,
pol.vendor_product_num vendor_item_code,mcb.concatenated_segments item_category,pol.quantity,pol.UNIT_MEAS_LOOKUP_CODE Purchasing_uom,pol.unit_price,
pol.quantity*pol.unit_price line_total,poll.PROMISED_DATE,prh.segment1||'.'||prl.LINE_NUM PR_Ref,
hrl.ADDRESS_LINE_1||','||hrl.address_line_2||','||hrl.address_line_3||','||hrl.TOWN_OR_CITY||','||hrl.country Ship_to_location,pol.NOTE_TO_VENDOR Line_comments,
decode(poh.authorization_status ,'APPROVED','','This PO is in draft status and should not be considered as a confirmed Purchase Order from HMC') COMMENTS
from po_headers_all poh,
po_lines_all pol,
ap_terms_tl apt,
ap_suppliers aps,
ap_supplier_sites_all apsa,
per_all_people_f papf,
--mtl_system_items_b msib,
mtl_categories_b_kfv mcb,
po_line_locations_all poll,
hr_locations hrl,
po_distributions_all pod,
po_req_distributions_all prd,
po_requisition_lines_all prl,
po_requisition_headers_all prh,
rcv_shipment_lines rsl,
rcv_shipment_headers rsh,fnd_user fnd,po_line_types_vl pltv
where poh.PO_HEADER_ID = pol.po_header_id and
      pol.line_type_id= pltv.LINE_TYPE_ID and
      poh.terms_id = apt.term_id and
      poh.VENDOR_ID  = aps.vendor_id and
      poh.VENDOR_SITE_ID =apsa.vendor_site_id and
      aps.vendor_id =apsa.vendor_id and
      poh.AGENT_ID  = papf.person_id and
      fnd.employee_id(+)=PAPF.PERSON_ID and
      --pol.ITEM_ID  = msib.INVENTORY_ITEM_ID and
      pol.category_id= mcb.category_id and
      pol.po_line_id=poll.po_line_id and
      poll.LINE_LOCATION_ID = pod.LINE_LOCATION_ID
      and prh.requisition_header_id(+)=prl.requisition_header_id
      and prl.requisition_line_id(+)=prd.requisition_line_id
      and prd.distribution_id(+)=pod.req_distribution_id
      --and prl.DESTINATION_ORGANIZATION_ID = msib.ORGANIZATION_ID
      and poll.ship_to_location_id = hrl.location_id
      AND pod.po_distribution_id=rsl.po_distribution_id(+)
      AND rsl.shipment_header_id = rsh.shipment_header_id(+) and
      apt.language='US'
     and poh.PO_HEADER_ID = nvl(:SEG,poh.PO_HEADER_ID)
      and aps.vendor_id = nvl(:VEND,aps.vendor_id)
and TRUNC(poh.CREATION_DATE) >= to_date(substr(:DAT,1,instr(:DAT,' ')),'yyyy/mm/dd')
and trunc(poh.CREATION_DATE) <= to_date(substr(:DAT1,1,instr(:DAT1,' ')),'yyyy/mm/dd')
     --AND poh.CREATION_DATE between to_date(:dat,'dd/mon/yyyy hh24:mi:ss')
      --and  to_date(:dat1,'dd/mon/yyyy hh24:mi:ss')
      and trunc(sysdate) between trunc(papf.EFFECTIVE_START_DATE) and trunc(papf.EFFECTIVE_END_DATE)    
      and fnd.user_id=FND_GLOBAL.USER_ID
 order by poh.segment1,pol.line_num



function BeforeReport return boolean is
begin
  SRW.USER_EXIT('FND SRWINIT');
  /*:P_USERID:=FND_GLOBAL.USER_ID;
  :P1:='AND FND.USER_ID = '''||:P_USERID||'''';
  return (TRUE);
exception
    when others then
    :P1:='';*/
     return (TRUE);   
end;



function AfterReport return boolean is
begin
     SRW.MESSAGE(000,'*****************PO Print Report***************');
  if :CS_COUNTRCP>0 then
  SRW.MESSAGE(000,'Number of PO Printed:'||:CS_COUNTRCP);
  else
  SRW.MESSAGE(000,'No Data Found:');   
  end if;
  SRW.MESSAGE(000,'*****************End Of Report**********************');
  SRW.USER_EXIT('FND SRWEXIT');
  return (TRUE);
end;

No comments:

Post a Comment