Wednesday, June 24, 2015

Program to Cancel or close the Notification

CREATE OR REPLACE PROCEDURE Remove_Notifications(
   p_errbuf           OUT VARCHAR2,
   p_retcode          OUT NUMBER,
   p_user_name     IN     VARCHAR2,
   l_from_date     IN     VARCHAR2,
   l_to_date       IN     VARCHAR2,
   p_notifi_type   IN     VARCHAR2)
AS
   --DECLARE
   -- declare Cursor
   p_from_date         DATE := fnd_date.canonical_to_date (l_from_date);
   p_to_date           DATE := fnd_date.canonical_to_date (l_to_date);

   CURSOR get_notif
   IS
      SELECT *
        FROM wf_notifications
       WHERE     recipient_role = p_user_Name
             AND status = 'OPEN'
             AND TRUNC (NVL(Sent_date,begin_date)) BETWEEN p_from_date AND p_to_date;

   i                   NUMBER (10) := 1;
   notification_type   VARCHAR2 (20) := p_notifi_type;        --CANCEL default
BEGIN
   --FND_FILE.PUT_LINE.('Executing Procedure');
   FND_FILE.put_line (FND_FILE.LOG, 'PASSED PARAMERTERS ARE');
   FND_FILE.put_line (FND_FILE.LOG, 'USER NAME' || P_USER_NAME);
   FND_FILE.put_line (FND_FILE.LOG, 'FROM DATE' || P_FROM_DATE);
   FND_FILE.put_line (FND_FILE.LOG, 'TO DATE' || P_TO_DATE);
   FND_FILE.put_line (FND_FILE.LOG, 'NOTIFICATION TYPE' || p_notifi_type);

   -- open cursor to check open notifications which needs to be closed
   FOR c_get_notif IN get_notif
   LOOP
      BEGIN
         -- CLOSE  -  This will close information notifications only, all action required notification will not be close
         -- CANCEL -  This will cancel notification, action required notification such as Approve/Reject will be cancelled and cannot be rollback,
         --users will not be able to take action on such notifications later

         IF UPPER (notification_type) = 'CLOSE'
         THEN
            wf_notification.Close (c_get_notif.notification_id,
                                   c_get_notif.recipient_role);
            i := i + 1;
            COMMIT;
         ELSIF UPPER (notification_type) = 'CANCEL'
         THEN
            wf_notification.cancel (c_get_notif.notification_id,
                                    c_get_notif.recipient_role);
            i := i + 1;
            COMMIT;
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            FND_FILE.put_line (FND_FILE.LOG, SQLERRM);
      END;
   END LOOP;

   COMMIT;
   -- DBMS_OUTPUT.put_line (TO_CHAR  || ' records effected');
   --DBMS_OUTPUT.put_line ('Procedure Executed Successfully');
END;
/

Query to get PO Requisition, PO and Receipt details in R12

Query to get PO Requisition, PO and Receipt details in R12

I had to provide data to auditors on the
  1. Internal & Purchase Requisitions created by users
  2. Purchase Orders created for the requisitions (inventory and non inventory items)
  3. Receiving transactions with PO and Requisition information
Purchase Requisition details

SELECT prh.segment1 "Req #", prh.creation_date, prh.created_by, poh.segment1 "PO #", ppx.full_name "Requestor Name",prh.description "Req Description", prh.authorization_status, prh.note_to_authorizer, prh.type_lookup_code, prl.line_num,prl.line_type_id, prl.item_description, prl.unit_meas_lookup_code, prl.unit_price, prl.quantity, prl.quantity_delivered,prl.need_by_date, prl.note_to_agent, prl.currency_code, prl.rate_type, prl.rate_date, prl.quantity_cancelled, prl.cancel_date,prl.cancel_reason
  FROM po_requisition_headers_all prh,
       po_requisition_lines_all prl,
       po_req_distributions_all prd,
       per_people_x ppx,
       po_headers_all poh,
       po_distributions_all pda
 WHERE prh.requisition_header_id = prl.requisition_header_id
   AND ppx.person_id = prh.preparer_id
   AND prh.type_lookup_code = 'PURCHASE'
   AND prd.requisition_line_id = prl.requisition_line_id
   AND pda.req_distribution_id = prd.distribution_id
   AND pda.po_header_id = poh.po_header_id
   AND TO_CHAR (prh.creation_date, 'YYYY') IN ('2010', '2011')
Internal Requisition details

SELECT prh.segment1 "Req #", prh.creation_date, prh.created_by, poh.segment1 "PO #", ppx.full_name "Requestor Name",
       prh.description "Req Description", prh.authorization_status, prh.note_to_authorizer, prl.line_num,
       prl.line_type_id, prl.source_type_code, prl.item_description, prl.unit_meas_lookup_code, prl.unit_price, prl.quantity, prl.quantity_delivered,
       prl.need_by_date, prl.note_to_agent, prl.currency_code, prl.rate_type, prl.rate_date, prl.quantity_cancelled, prl.cancel_date,
       prl.cancel_reason
  FROM po_requisition_headers_all prh,
       po_requisition_lines_all prl,
       po_req_distributions_all prd,
       per_people_x ppx,
       po_headers_all poh,
       po_distributions_all pda
 WHERE prh.requisition_header_id = prl.requisition_header_id
   AND ppx.person_id = prh.preparer_id
   AND prh.type_lookup_code = 'INTERNAL'
   AND prd.requisition_line_id = prl.requisition_line_id
   AND pda.req_distribution_id (+) = prd.distribution_id
   AND pda.po_header_id = poh.po_header_id (+)
   AND TO_CHAR (prh.creation_date, 'YYYY') IN ('2010', '2011')
Purchase Order details

SELECT
    ph.SEGMENT1 po_num
  , ph.CREATION_DATE
  , hou.name  "Operating Unit"
  , ppx.full_name "Buyer Name"
  , ph.type_lookup_code "PO Type"
  , plc.displayed_field "PO Status"
  , ph.COMMENTS
  , pl.line_num
  , plt.order_type_lookup_code "Line Type"
  , NULL "Item Code"
  , pl.item_description
  , pl.unit_meas_lookup_code "UOM"
  , pl.base_unit_price
  , pl.unit_price
  , pl.quantity
  , ood.organization_code "Shipment Org Code"
  , ood.organization_name "Shipment Org Name"
  , pv.vendor_name supplier
  , pvs.vendor_site_code
  , (pl.unit_price * pl.quantity) "Line Amount"
  , prh.segment1 req_num
  , prh.type_lookup_code req_method
  , ppx1.full_name "Requisition requestor"
FROM  po_headers_all ph
    , po_lines_all pl
    , po_distributions_all pda
    , po_vendors pv
    , po_vendor_sites_all pvs
    , po_distributions_all pd
    , po_req_distributions_all prd
    , po_requisition_lines_all prl
    , po_requisition_headers_all prh
    , hr_operating_units hou
    , per_people_x ppx
    , po_line_types_b plt
    , org_organization_definitions ood
    , per_people_x ppx1
    , po_lookup_codes plc
WHERE
  1=1
  AND TO_CHAR(ph.creation_date, 'YYYY') IN (2010, 2011)
  AND ph.vendor_id = pv.vendor_id
  AND ph.po_header_id = pl.po_header_id
  AND ph.vendor_site_id = pvs.vendor_site_id
  AND ph.po_header_id = pd.po_header_id
  and pl.po_line_id = pd.po_line_id
  AND pd.req_distribution_id = prd.distribution_id (+)
  AND prd.requisition_line_id = prl.requisition_line_id (+)
  AND prl.requisition_header_id = prh.requisition_header_id (+)
 and hou.organization_id = ph.org_id
 and ph.agent_id = ppx.person_id
 and pda.po_header_id = ph.po_header_id
 and pda.po_line_id = pl.po_line_id
 and pl.line_type_id = plt.line_type_id
 and ood.organization_id = pda.destination_organization_id
 and ppx1.person_id (+) = prh.preparer_id
 and plc.lookup_type = 'DOCUMENT STATE'
 and plc.LOOKUP_CODE = ph.closed_code
 and pl.item_id is null
UNION
-- Purchase Orders for inventory items
SELECT
    ph.SEGMENT1 po_num
  , ph.CREATION_DATE
  , hou.name  "Operating Unit"
  , ppx.full_name "Buyer Name"
  , ph.type_lookup_code "PO Type"
  , plc.displayed_field "PO Status"
  , ph.COMMENTS
  , pl.line_num
  , plt.order_type_lookup_code "Line Type"
  , msi.segment1 "Item Code"
  , pl.item_description
  , pl.unit_meas_lookup_code "UOM"
  , pl.base_unit_price
  , pl.unit_price
  , pl.quantity
  , ood.organization_code "Shipment Org Code"
  , ood.organization_name "Shipment Org Name"
  , pv.vendor_name supplier
  , pvs.vendor_site_code
  , (pl.unit_price * pl.quantity) "Line Amount"
  , prh.segment1 req_num
  , prh.type_lookup_code req_method
  , ppx1.full_name "Requisition requestor"
FROM  po_headers_all ph
    , po_lines_all pl
    , po_distributions_all pda
    , po_vendors pv
    , po_vendor_sites_all pvs
    , po_distributions_all pd
    , po_req_distributions_all prd
    , po_requisition_lines_all prl
    , po_requisition_headers_all prh
    , hr_operating_units hou
    , per_people_x ppx
    , mtl_system_items_b msi
    , po_line_types_b plt
    , org_organization_definitions ood
    , per_people_x ppx1
    , po_lookup_codes plc
WHERE
  1=1
  AND TO_CHAR(ph.creation_date, 'YYYY') IN (2010, 2011)
  AND ph.vendor_id = pv.vendor_id
  AND ph.po_header_id = pl.po_header_id
  AND ph.vendor_site_id = pvs.vendor_site_id
  AND ph.po_header_id = pd.po_header_id
  and pl.po_line_id = pd.po_line_id
  AND pd.req_distribution_id = prd.distribution_id (+)
  AND prd.requisition_line_id = prl.requisition_line_id (+)
  AND prl.requisition_header_id = prh.requisition_header_id (+)
 and hou.organization_id = ph.org_id
 and ph.agent_id = ppx.person_id
 and pda.po_header_id = ph.po_header_id
 and pda.po_line_id = pl.po_line_id
 and pl.line_type_id = plt.line_type_id
 and ood.organization_id = pda.destination_organization_id
 and ppx1.person_id (+) = prh.preparer_id
 and pda.destination_organization_id = msi.organization_id (+)
 and msi.inventory_item_id = nvl(pl.item_id, msi.inventory_item_id)-- OR pl.item_id is null)
 and plc.lookup_type = 'DOCUMENT STATE'
 and plc.LOOKUP_CODE = ph.closed_code
 and pl.item_id is not null
Receiving transactions with PO and requisition information

SELECT
ph.segment1 po_num,
ood.organization_name,
pol.po_line_id,
pll.quantity,
rsh. receipt_source_code,
rsh. vendor_id,
rsh. vendor_site_id,
rsh. organization_id,
rsh. shipment_num,
rsh. receipt_num,
rsh. ship_to_location_id,
rsh. bill_of_lading,
rsl.shipment_line_id,
rsl.QUANTITY_SHIPPED,
rsl.QUANTITY_RECEIVED ,
rct.transaction_type,
rct.transaction_id,
nvl(rct.source_doc_quantity,0) transaction_qty
from rcv_transactions rct
, rcv_shipment_headers rsh
, rcv_shipment_lines rsl
, po_lines_all pol
, po_line_locations_all pll
, po_headers_all ph
, org_organization_definitions ood
where 1=1
and to_char(rct.creation_date, 'YYYY') in ('2010', '2011')
and rct.po_header_id = ph.po_header_id
and rct.po_line_location_id = pll.line_location_id
and rct.po_line_id = pol.po_line_id
and rct.shipment_line_id=rsl.shipment_line_id
and rsl.shipment_header_id=rsh.shipment_header_id
and rsh.ship_to_org_id = ood.organization_id
order by rct.transaction_id

Tuesday, June 23, 2015

checking accounting detail based invoice number and its payment accounting details

select * from xla_ae_lines where ae_header_id in (select ae_header_id from
xla_ae_headers where event_id in ( select accounting_event_id from
ap_invoice_distributions_all where invoice_id in ( select invoice_id from
ap_invoices_all where invoice_num='200408-2127757' )));


select * from xla.XLA_TRIAL_BALANCES where ae_header_id = 455892602



(select ae_header_id from
xla_ae_headers where event_id in
(select accounting_event_id from ap_invoice_payments_all where invoice_id =15671141))

Sunday, June 21, 2015

Query to check the status of the Periods

select a.period_name,
       a.period_num,
       a.gl_status,
       b.po_status,
       c.ap_status
from
   (select period_name, period_num,
    decode(closing_status,'O','Open',
                          'C','Closed',
                          'F','Future',
                          'N','Never',
           closing_status) gl_status
    from gl_period_statuses
    where application_id = 101
    and start_date >= '01-JAN-98'
    and end_date < '01-JAN-99'
    and set_of_books_id = &&set_of_books_id) a,
   (select period_name,
    decode(closing_status,'O','Open',
                          'C','Closed',
                          'F','Future',
                          'N','Never',
           closing_status) po_status
    from gl_period_statuses
    where application_id = 201
    and start_date >= '01-JAN-98'
    and end_date < '01-JAN-99'
    and set_of_books_id = &&set_of_books_id) b,
   (select period_name,
    decode(closing_status,'O','Open',
                          'C','Closed',
                          'F','Future',
                          'N','Never',
           closing_status) ap_status
    from gl_period_statuses
    where application_id = 200
    and start_date >= '01-JAN-98'
    and end_date < '01-JAN-99'
    and set_of_books_id = &&set_of_books_id) c
where a.period_name = b.period_name
and   a.period_name = c.period_name
order by a.period_num;

Friday, June 19, 2015

How to get Version of Programs, Files, and Objects

Oracle Applications:
To obtain version of form from any applications form, navigate to the form. Then in the Menu tool bar .
Help --> About Oracle Applications
Or
select release_name from fnd_product_groups;

Database Objects:
select text from user_source where name='&package_name' and text like '%$Header%';

Views:
select VIEW_NAME, TEXT 
from 
USER_VIEWS 
where VIEW_NAME = '&VIEW_NAME';

Oracle Workflow:
$FND_TOP/sql/wfver.sql
OR
select TEXT from WF_RESOURCES where NAME='WF_VERSION';

Unix:
uname -a

Windows:
Start => Parameters => Control Panel => System

Java:
java -version 

Sqlplus :
start --> Run --> cmd
sqlplus 

TnsPing:
start --> Run --> cmd
TNSPING 

D2k version:
ORACLE_HOME\Orainst\nt.rgs 

File versions:
On Unix: strings -a "File name" | grep Header
On Windows : find "Header" File_name

Saturday, June 6, 2015

ASL (Approved Supplier List) Query

SELECT hou.NAME operating_unit,
       asl.vendor_business_type,
       pov.segment1 vendor_code,
       pov.vendor_name,
       sites.vendor_site_code,
       msi.segment1 item_code,
       msi.description item_desc,
       using_organization_id,
       owning_organization_id,
       plc.displayed_field,
       past.status Supplier_Status
  FROM po_approved_supplier_list asl,
       po_vendors pov,
       po_vendor_sites_all sites,
       mtl_system_items_b msi,
       hr_operating_units hou,
       po_lookup_codes plc,
       po_asl_statuses past
 WHERE     asl.vendor_id = pov.vendor_id
       AND asl.vendor_site_id = sites.vendor_site_id
       AND msi.inventory_item_id = asl.item_id
       AND msi.organization_id = asl.using_organization_id
       AND sites.org_id = hou.organization_id
       AND asl.vendor_business_type = plc.lookup_code
       AND asl.asl_status_id = past.status_id
       AND plc.lookup_type = 'ASL_VENDOR_BUSINESS_TYPE'
       AND past.status = 'Approved'
       AND msi.inventory_item_id  = 222315;

Thursday, June 4, 2015

Fixed Assets Query

SELECT distinct
fab.model_number,
FAB.ASSET_TYPE ASSET_CLASS,
FAB.ASSET_NUMBER ASSET,
FAT.DESCRIPTION ASSET_DESCRITPION,
FB.BOOK_TYPE_CODE BOOK,
FB.ORIGINAL_COST ASSET_COST,
FDS.DEPRN_RESERVE ACCUMULATED_DEPRECIATION,
fds.deprn_amount The_last_depreciation_amount,
(FB.ORIGINAL_COST-FDS.DEPRN_RESERVE) Net_Book_Value,
fb.salvage_value Residual_value,
to_char(fb.prorate_date,'DD-MON-RRRR') prorate_date,
fb.life_in_months||' Motnhs'  Life_of_asset,
FAB.SERIAL_NUMBER SERIAL_NUMBER,
round((DECODE (
          fb.period_counter_fully_retired,
          NULL, GREATEST (
                   NVL (fb.life_in_months, 0)
                   - TRUNC (
                        MONTHS_BETWEEN (SYSDATE,
                                        fb.date_placed_in_service)),
                   0),
          0)) /12,1)
          remaining_life_in_years
FROM
FA_ADDITIONS_B FAB,
FA_ADDITIONS_TL FAT,
FA_BOOKS FB,
FA_DISTRIBUTION_HISTORY FDH,
PER_ALL_PEOPLE_F PAPF,
FA_LOCATIONS_KFV FLK,
GL_CODE_COMBINATIONS_KFV GCCK,
FA_DEPRN_SUMMARY FDS,
GL_ledgers  GSOB
WHERE
FAB.ASSET_ID=FAT.ASSET_ID
AND FAB.ASSET_ID=FDH.ASSET_ID
AND FAB.ASSET_ID=FB.ASSET_ID
AND FDH.DATE_INEFFECTIVE IS NULL
AND FDS.ASSET_ID=FB.ASSET_ID
AND FDS.BOOK_TYPE_CODE = FB.BOOK_TYPE_CODE
AND FDS.DEPRN_SOURCE_CODE='DEPRN'
AND FDS.PERIOD_COUNTER =(SELECT MAX(PERIOD_COUNTER) FROM FA_DEPRN_SUMMARY FDSS WHERE FDSS.DEPRN_SOURCE_CODE='DEPRN' AND FDSS.ASSET_ID=FB.ASSET_ID AND FDSS.BOOK_TYPE_CODE=FB.BOOK_TYPE_CODE)
AND FB.TRANSACTION_HEADER_ID_IN=(SELECT MAX(TRANSACTION_HEADER_ID_IN) FROM FA_BOOKS FB1 WHERE FB1.ASSET_ID=FB.ASSET_ID AND FB1.BOOK_TYPE_CODE=FB.BOOK_TYPE_CODE)
AND FB.PERIOD_COUNTER_FULLY_RETIRED IS NULL
AND FDH.LOCATION_ID=FLK.LOCATION_ID
AND GCCK.CODE_COMBINATION_ID = FDH.CODE_COMBINATION_ID
AND GCCK.CHART_OF_ACCOUNTS_ID=GSOB.CHART_OF_ACCOUNTS_ID
AND FDH.ASSIGNED_TO = PAPF.PERSON_ID (+)
AND FAT.LANGUAGE = USERENV('LANG')
AND FB.BOOK_TYPE_CODE <>'ACE TAX'
and fb.asset_id = 3316768
and fb.book_type_code = 'NEW MTN'
ORDER BY fb.ASSET_ID ;


Detele Transaction in Account receivables

declare

   v_msg_data      varchar2(4000)  := null;
    v_msg_count     number          := 0;
    v_msg_index     number          := 0;
    v_ret_status    varchar2(1)     := null;  
    v_message_tbl   arp_trx_validate.message_tbl_type;
   
begin
    dbms_output.put_line('Detele Transaction...');
   
     ---- Setting the org context for the particular session
        apps.mo_global.set_policy_context('S', 5001);
       
         apps.fnd_global.apps_initialize(1281564,50828,222);   
       
       
       
       
         ar_invoice_api_pub.delete_transaction(
                                                 p_api_name             => 'Delete_Transaction',
                                                 p_api_version          => 1.0,
                                                 p_init_msg_list        => fnd_api.g_true,
                                                 p_commit               => fnd_api.g_true,
                                                 p_validation_level     => fnd_api.g_valid_level_full,
                                                 p_customer_trx_id      => 32340430,
                                                 p_return_status        => v_ret_status,
                                                 p_msg_count            => v_msg_count,
                                                 p_msg_data             => v_msg_data,
                                                 p_errors               => v_message_tbl
                                             );
                                           
                                           
                                           
     if v_ret_status <> 'S' then
            dbms_output.put_line( '   Status: '||v_ret_status);
            for i in 1 .. v_msg_count loop
                apps.fnd_msg_pub.get( i, apps.fnd_api.g_false, v_msg_data, v_msg_index);
                dbms_output.put_line( '   Error : '||v_msg_data);
            end loop;
            dbms_output.put_line ('   '||v_msg_data);
        else
            dbms_output.put_line ('   Deleted.');
          
         end if;      
       
        commit;
        exception
    when others then
        dbms_output.put_line('Error : '||sqlerrm);
end;