Friday, 27 January 2012

Purchase Order cancellation program(API)

Spec--

PROCEDURE XXXXXX_PO_STANDARD_CANCELLATION (errbuf out varchar2,retcode out varchar2,From_po_num varchar2,To_po_num varchar2);
--------------------------------------------------------------------------------------------
Body--


PROCEDURE XXXXXX_PO_STANDARD_CANCELLATION (errbuf out varchar2,retcode out varchar2,From_po_num varchar2,To_po_num varchar2)
IS
  x_result VARCHAR2(50);
cursor c_po_closed is
   SELECT ph.type_lookup_code, ph.segment1 po_num, ph.po_header_id,
          pll.quantity, pll.quantity_billed, pll.quantity_received,
          ph.start_date, ph.end_date, pll.po_line_id, pll.line_location_id
     FROM po_headers_all ph, po_line_locations_all pll                       --
    WHERE ph.po_header_id = pll.po_header_id
      AND ph.type_lookup_code = 'STANDARD'
      AND ph.enabled_flag = 'Y'
      AND ph.authorization_status = 'APPROVED'
      AND TRUNC (SYSDATE) - (ph.creation_date) > 90
      AND pll.quantity_received = pll.quantity_billed
      AND pll.quantity_cancelled = 0
      AND pll.quantity <> pll.quantity_billed
      AND pll.quantity <> pll.quantity_received
      AND pll.closed_code = 'OPEN'
      AND ph.po_header_id NOT IN (SELECT po_header_id
                                    FROM po_distributions
                                   WHERE project_id IS NOT NULL)
   UNION
   SELECT ph.type_lookup_code, ph.segment1 po_num, ph.po_header_id,
          pll.quantity, pll.quantity_billed, pll.quantity_received,
          ph.start_date, ph.end_date, pll.po_line_id, pll.line_location_id
     FROM po_headers_all ph, po_line_locations_all pll                       --
    WHERE ph.po_header_id = pll.po_header_id
      AND ph.type_lookup_code = 'STANDARD'
      AND ph.enabled_flag = 'Y'
      AND ph.authorization_status = 'APPROVED'
      AND TRUNC (SYSDATE) - (ph.creation_date) > 90
      AND pll.quantity_received = pll.quantity_billed
      AND pll.quantity_cancelled = 0
      AND pll.quantity <> pll.quantity_billed
      AND pll.quantity <> pll.quantity_received
      AND pll.closed_code = 'OPEN'
      AND ph.po_header_id NOT IN (SELECT po_header_id
                                    FROM po_distributions
                                   WHERE project_id IS NOT NULL);
      lc_cancel  VARCHAR2(25);
         ln_user_id number;
         ln_resp_id number;
         ln_resp_app_id number;
BEGIN
FND_FILE.PUT_LINE(fnd_file.log,fnd_global.user_id||','||From_po_num||','||From_po_num);
ln_user_id := APPS.FND_PROFILE.VALUE('USER_ID');
      IF ln_user_id IS NULL THEN
         ln_user_id := -1;
      END IF;
        ln_resp_id  := APPS.FND_PROFILE.VALUE('RESP_ID');
      ln_resp_app_id := APPS.FND_PROFILE.VALUE('RESP_APPL_ID');
Begin
               FND_GLOBAL.apps_initialize(ln_user_id,ln_resp_id,ln_resp_app_id);
     end;
FND_FILE.PUT_LINE(fnd_file.log,ln_user_id||','||ln_resp_id||','||ln_resp_app_id);
FND_FILE.PUT_LINE(fnd_file.output,'========================================================================================================');
FND_FILE.PUT_LINE(fnd_file.output,'PO_NUMBER'||'   |'||'PO_HEADER_ID'||'      |'||'PO_LINE_ID'||'    |'||'Qty'||'       |'||'quantity_billed'||'     |'||'quantity_received');        
FND_FILE.PUT_LINE(fnd_file.output,'========================================================================================================');        
For d_po_closed in c_po_closed loop
FND_FILE.PUT_LINE(fnd_file.log,d_po_closed.po_header_id||'    |    '
||d_po_closed.po_line_id||'   |   '||d_po_closed.po_num||','||lc_cancel);
po_document_control_pub.control_document(1.0, -- api version
FND_API.g_true, -- init msg
FND_API.g_true, -- commit
x_result, -- result
'PO', --doc type
d_po_closed.type_lookup_code, --'STANDARD', --sub doc type
d_po_closed.po_header_id, -- header_id
d_po_closed.po_num, -- po_number
NULL, -- release_id
NULL, -- release num
d_po_closed.po_line_id, -- po line id
NULL, -- line_num
d_po_closed.line_location_id, -- line_locaiton id
NULL, -- doc ship num
'CANCEL', -- action
SYSDATE, -- action date
'ADMN REASON', -- cancel reason
'N', -- cancel requisitions
'N', -- print flag
'100% Advance Payment', -- note to vendor
'N');
FND_FILE.PUT_LINE(fnd_file.output,Rpad(d_po_closed.po_num,12,' ')||'|'||Rpad(d_po_closed.po_header_id,18,' ')||'|'||Rpad(d_po_closed.po_line_id,11,' ')||'   |'
                  ||Rpad(d_po_closed.Quantity,10,' ')||'|'||Rpad(d_po_closed.quantity_billed,14,' ')||'      |'||d_po_closed.quantity_received);
   End loop;
End;


No comments:

Post a Comment