Friday 6 July 2018

Script to delete iExpense report/ How to delete expense report

This script will delete iexpense report from backend, also it will realesed credit card (if any) transaction related to this expense report. So we can create new expense report against that credit card transaction.

Script:

DECLARE
  P_ReportID NUMBER := &report_header_id;
  l_TempReportHeaderID   NUMBER;
  l_TempReportLineID     NUMBER; 
  l_childItemKeySeq      NUMBER;
  l_wf_active  BOOLEAN := FALSE;
  l_wf_exist  BOOLEAN := FALSE;
  l_end_date  wf_items.end_date%TYPE;
  l_child_item_key varchar2(2000);
  CURSOR ReportLines IS
    (SELECT REPORT_HEADER_ID, REPORT_LINE_ID FROM AP_EXPENSE_REPORT_LINES_ALL WHERE REPORT_HEADER_ID = P_ReportID);
 

BEGIN 

  DBMS_OUTPUT.PUT_LINE('Start Deleting Report ' || P_ReportID);

  DBMS_OUTPUT.PUT('Delete Distributions - ');
  DELETE FROM AP_EXP_REPORT_DISTS_ALL WHERE REPORT_HEADER_ID = P_ReportID;
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  DBMS_OUTPUT.PUT('Delete Attendees - ');
  DELETE FROM OIE_ATTENDEES_ALL oat WHERE oat.REPORT_LINE_ID IN ( SELECT REPORT_LINE_ID FROM ap_expense_report_lines_all WHERE  report_header_id = P_ReportID);
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  DBMS_OUTPUT.PUT('Delete Add on Mileage Rates - ');
  DELETE FROM OIE_ADDON_MILEAGE_RATES addon WHERE addon.REPORT_LINE_ID IN ( SELECT REPORT_LINE_ID FROM ap_expense_report_lines_all WHERE  report_header_id = P_ReportID);
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  DBMS_OUTPUT.PUT('Delete Perdiem Daily Breakup - ');
  DELETE FROM OIE_PDM_DAILY_BREAKUPS db WHERE db.REPORT_LINE_ID IN ( SELECT REPORT_LINE_ID FROM ap_expense_report_lines_all WHERE  report_header_id = P_ReportID);
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  DBMS_OUTPUT.PUT('Delete Perdiem Destinations - ');
  DELETE FROM OIE_PDM_DESTINATIONS db WHERE db.REPORT_LINE_ID IN ( SELECT REPORT_LINE_ID FROM ap_expense_report_lines_all WHERE  report_header_id = P_ReportID);
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  DBMS_OUTPUT.PUT('Delete Policy Violations - ');
  DELETE FROM AP_POL_VIOLATIONS_ALL WHERE REPORT_HEADER_ID = P_ReportID;
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  
  DBMS_OUTPUT.PUT('Update CC transactions, make them available for future reports - ');
  UPDATE AP_CREDIT_CARD_TRXNS_ALL SET REPORT_HEADER_ID = NULL, EXPENSED_AMOUNT = 0 WHERE REPORT_HEADER_ID  = P_ReportID;
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);

  OPEN ReportLines;
  
  DBMS_OUTPUT.PUT_LINE('Delete Attachments');
  LOOP
    FETCH ReportLines into l_TempReportHeaderID, l_TempReportLineID;
    EXIT WHEN ReportLines%NOTFOUND;
    
    /* Delete attachments assocated with the line */
    fnd_attached_documents2_pkg.delete_attachments(
      X_entity_name => 'OIE_LINE_ATTACHMENTS',
      X_pk1_value => l_TempReportLineID,
      X_delete_document_flag => 'Y'
    );     
  END LOOP;  
  
  CLOSE ReportLines;

  DBMS_OUTPUT.PUT('Delete Report Lines - ');
  DELETE FROM ap_expense_report_lines_all WHERE  report_header_id = P_ReportID;
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);

  AP_WEB_NOTES_PKG.DeleteERNotes (
    p_src_report_header_id       => P_ReportID
  );

  fnd_attached_documents2_pkg.delete_attachments(
    X_entity_name => 'OIE_HEADER_ATTACHMENTS',
    X_pk1_value => P_ReportID,
    X_delete_document_flag => 'Y'
  );
  
  DBMS_OUTPUT.PUT('Delete Report - ');
  DELETE FROM ap_expense_report_headers_all WHERE  report_header_id = P_ReportID;
  DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
  
  DBMS_OUTPUT.PUT_LINE('Stop and purge all workflows');
  begin
 select   end_date
 into     l_end_date
 from     wf_items
 where    item_type = 'APEXP'
 and      item_key  = to_char(P_ReportID);
 if l_end_date is NULL then
  l_wf_active := TRUE;
 else
  l_wf_active := FALSE;
 end if;
 l_wf_exist  := TRUE;
  exception
 when no_data_found then
  l_wf_active := FALSE;
  l_wf_exist  := FALSE;
  end;
  IF l_wf_exist THEN
 IF l_wf_active THEN
  wf_engine.AbortProcess (itemtype => 'APEXP',
    itemkey  => to_char(P_ReportID),
    cascade  => TRUE);
 END IF;

 begin
   l_childItemKeySeq := WF_ENGINE.GetItemAttrNumber('APEXP',
      P_ReportID,
      'AME_CHILD_ITEM_KEY_SEQ');
 exception
   when others then
      if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
  l_childItemKeySeq := 0;
      else
  raise;
      end if;
 end;

 IF (l_childItemKeySeq IS NOT NULL AND l_childItemKeySeq > 0) THEN
  FOR i in 1 .. l_childItemKeySeq LOOP
   l_child_item_key := to_char(P_ReportID) || '-' || to_char(i);
   begin
    select   end_date
    into     l_end_date
    from     wf_items
    where    item_type = 'APEXP'
    and      item_key  = l_child_item_key;
    if l_end_date is NULL then
     l_wf_active := TRUE;
    else
     l_wf_active := FALSE;
    end if;
    l_wf_exist  := TRUE;
   exception
    when no_data_found then
     l_wf_active := FALSE;
     l_wf_exist  := FALSE;
   end;
   IF (l_wf_exist) THEN
    IF l_wf_active THEN
     wf_engine.AbortProcess (itemtype => 'APEXP',
       itemkey  => l_child_item_key,
       cascade  => TRUE);
    END IF;
    wf_purge.Items(itemtype => 'APEXP',
     itemkey  => l_child_item_key);

    wf_purge.TotalPerm(itemtype => 'APEXP',
     itemkey  => l_child_item_key,
     runtimeonly => TRUE);
   END IF;
  END LOOP;
 END IF;

 wf_purge.Items(itemtype => 'APEXP',
   itemkey  => to_char(P_ReportID));

 wf_purge.TotalPerm(itemtype => 'APEXP',
   itemkey  => to_char(P_ReportID),
   runtimeonly => TRUE);
END IF;

DBMS_OUTPUT.PUT_LINE('Done Deleting Report ' || P_ReportID);
COMMIT;

EXCEPTION
  WHEN OTHERS THEN
    Dbms_Output.put_line(SQLERRM);

END;

Monday 2 July 2018

Script to delete AR transaction (Invoice/CM)

declare
l_org_id   NUMBER := &org_id;
l_trx_id          NUMBER := &customer_trx_id;

begin

mo_global.init('AR');
mo_global.set_policy_context('S',l_org_id);
arp_global.g_allow_datafix := TRUE ; 

delete from xla_distribution_links
where event_id in (select event_id
                     from   xla_events
                     where  entity_id in (select entity_id from xla_transaction_entities
                                          where source_id_int_1 = l_trx_id
                                          and   application_id = 222)
                     and    application_id = 222)
and application_id = 222;

delete from xla_ae_lines
where ae_header_id in (select ae_header_id
                         from xla_ae_headers
                         where entity_id in (select entity_id
                                             from xla_transaction_entities
                                             where source_id_int_1 = l_trx_id
                                             and   application_id = 222)
                         and application_id = 222)
and   application_id = 222;


delete from xla_ae_headers
where entity_id in (select entity_id
                      from xla_transaction_entities
                      where source_id_int_1 = l_trx_id
                      and   application_id = 222)
and application_id = 222;


delete from xla_events
where  entity_id in (select entity_id
                      from xla_transaction_entities
                      where source_id_int_1 = l_trx_id
                      and   application_id = 222)
and application_id = 222;


delete from xla_transaction_entities
where   source_id_int_1 = l_trx_id
and   application_id = 222;


delete from ar_payment_schedules_all
where customer_trx_id in (l_trx_id);


delete from ar_distributions_all
where source_id in (select receivable_application_id
                    from   ar_receivable_applications_all
                    where  customer_trx_id = l_trx_id
                    and    application_type = 'CM');


delete from ar_receivable_applications_all
where customer_trx_id in (l_trx_id);

delete from zx_lines_det_factors
where  trx_id in (l_trx_id);

delete from zx_lines
where  trx_id in (l_trx_id);

delete from ra_cust_trx_line_salesreps_all
where customer_trx_id in (l_trx_id);

delete from ra_cust_trx_line_gl_dist_all
where customer_trx_id in (l_trx_id);

delete from ra_customer_trx_lines_all
where customer_trx_id in (l_trx_id);

delete from ra_customer_trx_all
where customer_trx_id in (l_trx_id);

arp_global.g_allow_datafix := FALSE; 

end;

/

Thursday 26 April 2018

Customer Credit Limit Failure Hold

Understanding Credit Check Failure Hold Message in messaging window: 

During credit checking process, first the ‘Overdue invoice’s’ is validated, if it fails then the Order goes on hold. The credit check failure hold message will indicate the hold applied due to ‘Overdue invoice’. 
- If the first validation passes through then ‘Order Credit Limit’ is checked, if the order amount is greater than ‘Order Credit Limit’ set then Order goes on hold. The credit check failure hold message will indicate the hold applied due to ‘Order Credit Limit’. 
- 
If second level validation passes then the 'exposure/outstanding' balance is calculated based on the ‘Credit Check Rule' set up and it is validated with the 'Overall Credit Limit' defined. If exposure is found to be exceeding the overall 
Credit Limit then the order goes on hold. The credit check failure hold message will indicate the hold applied due to exceed in Overall Credit Limit. At this stage to find available the following formula explain this...Available = Overall Limit 
- Exposure Positive Exposure means Customer Outstanding and Negative 
Exposure means Customer balances/advance.The exposure amount calculated will depend on the Attributes checked in credit check rule in Exposure Tab. 
If customer has overall limit of $1000 and exposure is 500 then 
Available = 1000 - 500 = 500 
If customer has overall limit of $1000 
and exposure is -500 (advance paid bycustomer) then 
Available = 1000 -( - 500) = 1500. 

The Credit exposure report will show the total exposure amount based on the attributed checked in the credit check rule, this report does not show the exposure amount of each individual attribute. The simple method is to toggle the attributes on the credit check rule and rerun the credit exposure report and examine the impact. For example if the report shows current exposure amount of $1000 and the credit check rule used has ‘Include Open Receivables Balance’ and ‘Include un-invoiced Orders’ 
checked, you may uncheck one of the attributes and then rerun the credit exposure report to see the impact. If the exposure amount is due to ‘Include Open Receivables Balance’ then customer will need to check the AR balances in AR by running the aging reports in AR. If the exposure amount is due to ‘Include un-invoiced Orders’ this means exposure of all orders currently Booked and Not Invoiced. Term ‘Not Invoiced’ means Orders which are closed from OM and data for the same lying in RA_INTERFACE_LINES_ALL waiting for the invoicing. 

For checking the open receivable balances you can run AIGING FORM 
Receivables> collections>collections 
Use flash light, enter account number, and then do search. 
Click on Aiging TAB. 
Check Include Receipts at Risk check box and hit display button. 

Tuesday 20 March 2018

Query to find OAF form personalization details from backend.

SELECT
    jp.path_docid ,
    jdr_mds_internal.getdocumentname(jp.path_docid) Personalization_path,
    jp.path_name,
    Jp.Path_Owner_Docid,
    Jp.Path_Seq,
    Jp.Path_Type,
    Jp.Path_Xml_Encoding,
    Jp.Path_Xml_Version,
    Jp.Created_By,
    Jp.Creation_Date,
    Jp.Last_Updated_By,
    Jp.Last_Update_Date    
  FROM jdr_paths jp
WHERE jp.path_docid IN (
        SELECT DISTINCT comp_docid
        FROM jdr_components
        WHERE
            comp_seq = 0
            AND   comp_element = 'customization'
            AND   comp_id IS NULL
    )
    AND   upper(jdr_mds_internal.getdocumentname(jp.path_docid) ) LIKE upper('%USER%ByrMainPG%');

Monday 22 January 2018

Query to get details for Vacation Rule /Delegation in oracle apps

This query will give you details for user if any vacation rule is set.


select * from apps.WF_ROUTING_RULES
where role = &P_USER_NAME;
====================================
Below given query used to get details of notification send to delegates using vacation rules.

SELECT
    wit.display_name workflow_process,
    nvl(wi.user_key, (
        SELECT
            user_key
        FROM
            apps.wf_items w
        WHERE
            w.item_key = wi.parent_item_key
            AND   w.item_type = wi.item_type
    ) ) document_number,
    from_role,
    recipient_role,
    from_user,
    to_user,
    status,
    mail_status,
    original_recipient,    
    wias.activity_result_code notification_status,
    wn.subject,
    wn.begin_date notification_begin_date,
    wn.end_date notification_end_date,
    wrr.begin_date delegation_start_date,
    wrr.end_date delegation_end_date
FROM
    apps.wf_notifications wn,
    apps.wf_routing_rules wr,
    apps.wf_routing_rules wrr,
    apps.wf_item_activity_statuses wias,
    apps.wf_items wi,
    apps.wf_item_types_vl wit
WHERE
    wn.from_role =wr.role
    AND   wrr.role = wn.from_role
    AND   wrr.action_argument = wn.recipient_role
    AND   wias.item_key = wn.item_key                       
    AND   wias.notification_id = wn.notification_id
    AND   wn.item_key = wi.item_key
    AND   wn.message_type = wi.item_type
    AND   wit.name = wi.item_type
    AND   original_recipient =&P_USER_NAME
    AND   wn.begin_date > SYSDATE - 10
ORDER BY
    original_recipient,
    wn.begin_date DESC;

Wednesday 17 January 2018

AR and OM link in oracle apps / AR transaction and Sales Order join query

SELECT
    rcta.customer_trx_id,
    rcta.trx_number,
    rcta.trx_date,
    ac.customer_name,
    rctla.line_number inv_line_number,
    rctla.unit_selling_price inv_unit_selling_price,
    ooha.header_id,
    ooha.order_number,
    oola.line_number so_line_number,
    oola.line_id,
    oola.ordered_item,
    oola.ordered_quantity * oola.unit_selling_price so_amount
FROM
    apps.ra_customer_trx_all rcta,
    apps.ra_customer_trx_lines_all rctla,
    apps.ar_customers ac,
    apps.oe_order_headers_all ooha,
    apps.oe_order_lines_all oola
WHERE
    1 = 1
    AND   rcta.customer_trx_id = rctla.customer_trx_id
    AND   rcta.bill_to_customer_id = ac.customer_id
    AND   ooha.header_id = oola.header_id
    AND   rctla.interface_line_attribute6 = TO_CHAR(oola.line_id)
    AND   rctla.interface_line_attribute1 = TO_CHAR(ooha.order_number)
    AND   rcta.trx_number = nvl(:p_trx_number,rcta.trx_number)
    AND   ooha.order_number = nvl(:p_order_number,ooha.order_number);

Wednesday 10 January 2018

Query for responsibility list attached to user in oracle apps

SELECT
    fu.user_name,
    frt.responsibility_name,
    furg.start_date,
    furg.end_date,
    fr.responsibility_key,
    fa.application_short_name
FROM
    apps.fnd_user_resp_groups_direct furg,
    applsys.fnd_user fu,
    applsys.fnd_responsibility_tl frt,
    applsys.fnd_responsibility fr,
    applsys.fnd_application_tl fat,
    applsys.fnd_application fa
WHERE
    1 = 1
    AND   furg.user_id = fu.user_id
    AND   furg.responsibility_id = frt.responsibility_id
    AND   fr.responsibility_id = frt.responsibility_id
    AND   fa.application_id = fat.application_id
    AND   fr.application_id = fat.application_id
    AND   frt.language = userenv('LANG')
    AND   upper(fu.user_name) = upper(&P_USER_NAME)
    AND   SYSDATE BETWEEN nvl(furg.start_date,SYSDATE) AND nvl(furg.end_date,SYSDATE + 1)
ORDER BY  1,2;

Friday 5 January 2018

Oracle apps Valueset details Query

SELECT
    ffvs.flex_value_set_id,
    ffvs.flex_value_set_name,
    ffvs.description set_description,
    ffvs.validation_type,
    ffvt.value_column_name,
    ffvt.meaning_column_name,
    ffvt.id_column_name,
    ffvt.application_table_name,
    ffvt.additional_where_clause
FROM
    apps.fnd_flex_value_sets ffvs,
    apps.fnd_flex_validation_tables ffvt
WHERE
    ffvs.flex_value_set_id = ffvt.flex_value_set_id
    AND   ffvs.flex_value_set_name LIKE 'IBY_YES_NO';

How to resolve issue for BIP RTF template XML tags showing value as <?ref: 0000xx?>

 How to resolve issue for BIP RTF template XML tags showing value as <?ref: 0000xx?>  Sometime these xml data tags automatically chang...