Saturday, 9 July 2011

Workflow Tables and Queries

SELECT SUM(TOTAL_PENDING) PENDING_LESS_THAN_5DAYS

FROM

(SELECT B.ACTIVITY_NAME,

       TRUNC(SYSDATE) - TRUNC(BEGIN_DATE) PENDING_FROM_NO_OF_DAYS,

       COUNT(B.ACTIVITY_NAME) TOTAL_PENDING

FROM WF_ITEM_ACTIVITY_STATUSES A,

     WF_PROCESS_ACTIVITIES B

WHERE A.PROCESS_ACTIVITY = B.INSTANCE_ID

AND B.PROCESS_ITEM_TYPE = A.ITEM_TYPE

AND A.ITEM_TYPE = 'ERP'

--AND A.ITEM_KEY = 1131

AND END_DATE IS NULL

AND ACTIVITY_STATUS != 'ERROR'

AND ACTIVITY_NAME IN ('PLANNING','PURCHASING','MFGFINANCE','CSD','TAX')

GROUP BY ACTIVITY_NAME,

TRUNC(SYSDATE) - TRUNC(BEGIN_DATE)

ORDER BY ACTIVITY_NAME,

         PENDING_FROM_NO_OF_DAYS ) FIVE_DAYS

WHERE FIVE_DAYS.PENDING_FROM_NO_OF_DAYS < 5

Procure to Pay Cycle Query

ncludes two scripts to fetch all the transactions information related with in a procure to pay cycle.
Two scripts are provided to use one with receipts and other when receipts are not created.

Few important fields that were included in the script are Requisition Number, Purchase Order Number, Invoice Number, Customer Number, Invoice Amount, GL Transfer flag e.t.c

WITH OUT RECEIPTS
–Procure to Pay query without receipts

select distinct

           reqh.segment1 REQ_NUM,

           reqh.AUTHORIZATION_STATUS REQ_STATUS,

    --       poh.po_header_id,

           poh.segment1 PO_NUM,

           pol.line_num,

           poh.AUTHORIZATION_STATUS PO_STATUS,

    --       i.invoice_id,

           i.invoice_num,

           i.invoice_amount,

           i.amount_paid,

            i.vendor_id,

    --       v.vendor_name,

    --       p.check_id,

           c.check_number,

           h.gl_transfer_flag,

           h.period_name

    from ap_invoices_all i,

         ap_invoice_distributions_all invd,

         po_headers_all poh,

         po_lines_all pol,

         po_distributions_all pod,

         po_vendors v,

         po_requisition_headers_all reqh,

         po_requisition_lines_all reql,

         po_req_distributions_all reqd,    

         ap_invoice_payments_all p,

         ap_checks_all c,

         ap_ae_headers_all h,

         ap_ae_lines_all l

    where 1=1    

    and i.vendor_id = v.vendor_id

    and c.check_id = p.check_id

    and p.invoice_id = i.invoice_id

    and poh.PO_HEADER_ID = pol.PO_HEADER_ID

    and reqh.REQUISITION_HEADER_ID = reql.REQUISITION_HEADER_ID

    and reqd.REQUISITION_LINE_ID = reql.REQUISITION_LINE_ID

    and pod.REQ_DISTRIBUTION_ID = reqd.DISTRIBUTION_ID

    and pod.PO_HEADER_ID = poh.PO_HEADER_ID

    and pod.PO_DISTRIBUTION_ID = invd.PO_DISTRIBUTION_ID

    and invd.INVOICE_ID = i.INVOICE_ID

    and h.ae_header_id = l.ae_header_id

    and l.SOURCE_TABLE = 'AP_INVOICES'

    AND l.SOURCE_ID = i.invoice_id

    --and poh.segment1 = 4033816 -- PO NUMBER

    and reqh.segment1 = '501'   -- REQ NUMBER

    --and i.invoice_num = 3114     -- INVOICE NUMBER

    --and c.check_number =     -- CHECK NUMBER

        --and vendor_id =          -- VENDOR ID

WITH RECEIPTS
– PROCURE TO PAY CYCLE QUERY WITH RECEIPTS

SELECT DISTINCT reqh.segment1 req_num, reqh.authorization_status req_status,              

      --       POH.PO_HEADER_ID,

                poh.segment1 po_num, pol.line_num,

                poh.authorization_status po_status, rcvh.receipt_num,

                rcv.inspection_status_code,

      --       I.INVOICE_ID,

                i.invoice_num, i.invoice_amount,

                i.amount_paid, i.vendor_id,

      --       V.VENDOR_NAME,

      --       P.CHECK_ID,

                c.check_number, h.gl_transfer_flag,

                h.period_name

           FROM ap_invoices_all i,

                ap_invoice_distributions_all invd,

                po_headers_all poh,

                po_lines_all pol,

                po_distributions_all pod,

                po_vendors v,

                po_requisition_headers_all reqh,

                po_requisition_lines_all reql,

                po_req_distributions_all reqd,

                rcv_transactions rcv,

                rcv_shipment_headers rcvh,

                rcv_shipment_lines rcvl,

                ap_invoice_payments_all p,

                ap_checks_all c,

                ap_ae_headers_all h,

                ap_ae_lines_all l

          WHERE 1 = 1

            AND i.vendor_id = v.vendor_id

            AND c.check_id = p.check_id

            AND p.invoice_id = i.invoice_id

            AND poh.po_header_id = pol.po_header_id

            AND reqh.requisition_header_id = reql.requisition_header_id

            AND reqd.requisition_line_id = reql.requisition_line_id

            AND pod.req_distribution_id = reqd.distribution_id

            AND pod.po_header_id = poh.po_header_id

            --AND POH.PO_HEADER_ID = RCV.PO_HEADER_ID

            AND rcvh.shipment_header_id = rcv.shipment_header_id(+)

            --AND RCVH.SHIPMENT_HEADER_ID = RCVL.SHIPMENT_HEADER_ID

            --AND RCV.TRANSACTION_TYPE = 'RECEIVE'

            --AND RCV.SOURCE_DOCUMENT_CODE = 'PO'

            --AND POL.PO_LINE_ID = RCV.PO_LINE_ID

            --AND POD.PO_DISTRIBUTION_ID = RCV.PO_DISTRIBUTION_ID

            AND pod.po_distribution_id = invd.po_distribution_id

            AND invd.invoice_id = i.invoice_id

            AND h.ae_header_id = l.ae_header_id

            AND l.source_table = 'AP_INVOICES'

            AND l.source_id = i.invoice_id

            --AND POH.SEGMENT1 = 36420 -- PO NUMBER

            AND reqh.segment1 = '501'  -- REQ NUMBER

            --AND I.INVOICE_NUM = 3114     -- INVOICE NUMBER

            --AND C.CHECK_NUMBER =     -- CHECK NUMBER

            --AND VENDOR_ID =          -- VENDOR ID

            --AND RECEIPT_NUM = 692237

Concurrent Program Registration Scripts


BEGIN
 
              FND_PROGRAM.executable('XXMZ_ERPSCHOOLS_EMPLOYEE' -- executable
 
                                                              , 'XXMZ Custom' -- application
 
                                                              , 'XXMZ_ERPSCHOOLS_EMPLOYEE' -- short_name
 
                                                              , 'Executable for ERPSCHOOLS Employee INFORMATION' -- description
 
                                                              , 'PL/SQL Stored Procedure' -- execution_method
 
                                                              , 'XXMZ_ERPSCHOOLS_EMPLOYEE' -- execution_file_name
 
                                                              , '' -- subroutine_name
 
                                                              , '' -- Execution File Path
 
                                                              , 'US' -- language_code 
 
                                                              , '');
 
             COMMIT;
 
         END;

Get On Hand Quantities through API

This script can be used to get the below quantities.
1. On-hand Quantity
2. Available to Reserve
3. Quantity Reserved
4. Quantity Suggested
5. Available to Transact
6. Available to Reserve

You can also get the On-hand quantities from the table mtl_onhand_quantities

GET ON-HAND QUANTITIES API

DECLARE

   x_return_status         VARCHAR2 (50);

   x_msg_count             VARCHAR2 (50);

   x_msg_data              VARCHAR2 (50);

   v_item_id               NUMBER;

   v_org_id                NUMBER;

   v_qoh                   NUMBER;

   v_rqoh                  NUMBER;

   v_atr                   NUMBER;

   v_att                   NUMBER;

   v_qr                    NUMBER;

   v_qs                    NUMBER;

   v_lot_control_code      BOOLEAN;

   v_serial_control_code   BOOLEAN;

BEGIN



   -- Set the variable values

   v_item_id := '6566';

   v_org_id := 61;

   v_qoh := NULL;

   v_rqoh := NULL;

   v_atr := NULL;

   v_lot_control_code := FALSE;

   v_serial_control_code := FALSE;



   -- Set the org context

   fnd_client_info.set_org_context (1);



   -- Call API

   inv_quantity_tree_pub.query_quantities

   (p_api_version_number       => 1.0,

    p_init_msg_lst             => 'F',

    x_return_status            => x_return_status,

    x_msg_count                => x_msg_count,

    x_msg_data                 => x_msg_data,

    p_organization_id          => v_org_id,

    p_inventory_item_id        => v_item_id,

    p_tree_mode                => apps.inv_quantity_tree_pub.g_transaction_mode,

    -- or 3

    p_is_revision_control      => FALSE,

    p_is_lot_control           => v_lot_control_code,

    -- is_lot_control,

    p_is_serial_control        => v_serial_control_code,

    p_revision                 => NULL,        -- p_revision,

    p_lot_number               => NULL,           -- p_lot_number,

    p_lot_expiration_date      => SYSDATE,

    p_subinventory_code        => NULL,    -- p_subinventory_code,

    p_locator_id               => NULL,           -- p_locator_id,

    -- p_cost_group_id            => NULL,       -- cg_id,

    p_onhand_source            => 3,

    x_qoh                      => v_qoh,      -- Quantity on-hand

    x_rqoh                     => v_rqoh,           --reservable quantity on-hand

    x_qr                       => v_qr,

    x_qs                       => v_qs,

    x_att                      => v_att,  -- available to transact

    x_atr                      => v_atr    -- available to reserve

   );



   DBMS_OUTPUT.put_line ('On-Hand Quantity: ' || v_qoh);

   DBMS_OUTPUT.put_line ('Available to reserve: ' || v_atr);

   DBMS_OUTPUT.put_line ('Quantity Reserved: ' || v_qr);

   DBMS_OUTPUT.put_line ('Quantity Suggested: ' || v_qs);

   DBMS_OUTPUT.put_line ('Available to Transact: ' || v_att);

   DBMS_OUTPUT.put_line ('Available to Reserve: ' || v_atr);



EXCEPTION

   WHEN OTHERS

   THEN

      DBMS_OUTPUT.put_line ('ERROR: ' || SQLERRM);

END;

UTL_FILE example

CREATE OR REPLACE PROCEDURE load_data(errbuff varchar2,errcode number)

AS

v_line VARCHAR2(2000); -- Data line read from input file

v_file UTL_FILE.FILE_TYPE; -- Data file handle

v_dir VARCHAR2(250); -- Directory containing the data file

v_filename VARCHAR2(50); -- Data filename

v_1st_Comma number;

v_2nd_Comma number;

v_3rd_Comma number;

v_4th_Comma number;

v_5th_Comma number;

v_empno sample_emp.empno%type;

v_ename sample_emp.ename%type;

v_job sample_emp.job%type;

v_mgr sample_emp.mgr%type;

v_hiredate sample_emp.hiredate%type;

--v_sal sample_emp.sal%type;

BEGIN

v_dir := '/usr/tmp';

v_filename := 'sample.dat';

v_file := UTL_FILE.FOPEN(v_dir, v_filename, 'r');

-- --------------------------------------------------------

-- Loop over the file, reading in each line. GET_LINE will

-- raise NO_DATA_FOUND when it is done, so we use that as

-- the exit condition for the loop.

-- --------------------------------------------------------

LOOP

BEGIN

UTL_FILE.GET_LINE(v_file, v_line);

EXCEPTION

WHEN no_data_found THEN

exit;

END;

-- ----------------------------------------------------------

Send e mail through PL SQL code

CREATE OR REPLACE PROCEDURE erpschools_send_email

IS

mailhost varchar2 (30) := 'smtp.erpschools.com';

crlf varchar2(2)Â := CHR (13) || CHR (10);

v_email varchar2(16000);

message_1 LONG;

mail_conn utl_smtp.connection;

BEGIN

mail_conn := utl_smtp.open_connection (mailhost, 25);

utl_smtp.helo (mail_conn, mailhost);

utl_smtp.mail (mail_conn, 'sender@erpschools.com');

utl_smtp.rcpt (mail_conn, 'receiver@erpschools.com');

message_1 := 'From: Mr Sender < sender@erpschools.com >' || crlf ||

'Subject: Testing Hyperlink' || crlf ||

'To: Mrs Receiver <Receiver@erpschools.com>' || crlf ||

'<a href="http://www.erpschools.com" target="new" www.erpschools.com</a>' || crlf || crlf ;

utl_smtp.data(mail_conn, 'MIME-Version: 1.0' ||CHR(13)||CHR(10)||'Content-type: text/html' || CHR(13)||CHR(10)||message_1);

utl_smtp.quit (mail_conn);

END;

Menu and Functions Related Scripts

SELECT DISTINCT

fmep.menu_id,

DECODE(fmep.function_id,NULL, DECODE(fmec.function_id, NULL,DECODE(fmec1.function_id,NULL,

'No Func',fmec1.function_id ),

fmec.function_id),

fmep.function_id) funcID,

fff.user_function_name,

fff.description

FROM fnd_form_functions_tl fff,

fnd_menu_entries fmec1,

fnd_menu_entries fmec,

fnd_menu_entries fmep

WHERE fmep.menu_id = (SELECT menu_id

FROM fnd_menus

WHERE menu_name='INV_NAVIGATE'Â --Change the menu according to your requirement

AND ROWNUM=1)

AND fmep.sub_menu_id = fmec .menu_id(+)

AND fmec.sub_menu_id = fmec1 .menu_id (+)

AND fff.function_id = DECODE (fmep.function_id,NULL,DECODE(fmec.function_id, NULL,

DECODE(fmec1.function_id,NULL,-999,fmec1.function_id),

fmec.function_id),

fmep.function_id)

ORDER BY DECODE(fmep .function_id,NULL, DECODE(fmec.function_id, NULL,

DECODE(fmec1.function_id,NULL, 'No Func',fmec1.function_id ),

fmec.function_id),

fmep.function_id)