Saturday, January 25, 2020

Oracle Approval Graph



   PROCEDURE getapprovalgraph (preqno IN VARCHAR2, o_appr_graph OUT VARCHAR2)
   IS
      approvalgraph             VARCHAR2 (10000);
      image_path                VARCHAR2 (100)
                                   := 'http://companyURL/OA_MEDIA';
      person_name               VARCHAR2 (300);
      vl_final_status           VARCHAR2 (300) := 'In Process';
      vl_arrow_img              VARCHAR2 (1000);
      vl_line_img               VARCHAR2 (1000);
      vl_header                 VARCHAR2 (2000);
      vl_fotter                 VARCHAR2 (2000);
      vl_start_approved_table   VARCHAR2 (2000);
      vl_approved_table         VARCHAR2 (2000);
      vl_inprocess_table        VARCHAR2 (2000);
      vl_max_squence            NUMBER;

      CURSOR c1
      IS
           SELECT (SELECT NVL (full_name, user_name)
                     FROM per_all_people_f papf, fnd_user fu
                    WHERE     fu.user_id = bcr.user_id
                          AND fu.employee_id = papf.person_id
                          AND ROWNUM = 1)
                     employee_name,
                  bcr.sequence_no,
                  bcr.action_meaning
             FROM xxbg_asset_disp_appr_history_t bcr
            WHERE request_number = preqno
         ORDER BY 2;
   BEGIN
      vl_line_img :=
         '<td><img src=' || image_path || '/ag_line_horizontal.gif ></td>';
      vl_arrow_img :=
         '<td><img src=' || image_path || '/ag_arrow_horizontal.gif ></td>';

      /*  Header */
      vl_header :=
         '<table border=''0'' cellpadding=''0'' cellspacing=''0''><tr><td align=center><img src='
         || image_path
         || '/ag_transparentpixel.gif width=''0'' height=''56'' align=''middle'' alt=''Blank image''><img src='
         || image_path
         || '/tree_document.gif align=''middle'' alt=''Image for document''></td>';


      /*  Fotter */
      vl_fotter :=
            vl_line_img
         || vl_arrow_img
         || '<td><span class=''OraLinkText''>'
         || vl_final_status
         || '</span></td></tr></table>';

      FOR i IN c1
      LOOP
         IF i.sequence_no = 0
         THEN
            vl_header := NULL;

            vl_start_approved_table := NULL;
            vl_inprocess_table := NULL;
            vl_approved_table := NULL;

            SELECT MAX (sequence_no)
              INTO vl_max_squence
              FROM xxbg_asset_disp_appr_history_t bcr
             WHERE request_number = preqno AND sequence_no <> 99;

            vl_header :=
               '<table border=''0'' cellpadding=''0'' cellspacing=''0''><tr><td align=center><img src='
               || image_path
               || '/ag_transparentpixel.gif width=''0'' height=''56'' align=''middle'' alt=''Blank image''><img src='
               || image_path
               || '/tree_document.gif align=''middle'' alt=''Image for document''></td>';


            vl_start_approved_table :=
               '<td><table width=''100%'' border=''0'' cellspacing=''0'' cellpadding=''0'' bgcolor=''#003399'' height=''44''><tr><td><span><table width=''100%'' border=''0'' cellspacing=''1'' cellpadding=''0''><tr><td width=''10%'' bgcolor=''#E9F5FF''> <div align=''center''><img src='
               || image_path
               || '/okind_status.gif width=''16'' height=''16'' alt=''Approved''></div></td><td height=''22'' bgcolor=''#C3D9EE''><div align=''center''><img src='
               || image_path
               || '/tree_person.gif width=''16'' height=''16'' alt=''Image for approver type''></div></td></tr><tr><td colspan=2 height=''22'' bgcolor=''#FFFFFF'' nowrap><p align=''center''><span class=''OraInstructionText''>'
               || i.employee_name
               || '</span></p></td></tr></table></span></td></tr></table></td>';
         END IF;

         IF i.sequence_no NOT IN (0, 99)
         THEN
            IF vl_max_squence = i.sequence_no
            THEN
               vl_inprocess_table :=
                  vl_inprocess_table || vl_line_img || vl_arrow_img
                  || '<td><table width=''100%'' border=''0'' cellspacing=''0'' cellpadding=''0'' bgcolor=''#003399'' height=''44''><tr><td><span><table width=''100%'' border=''0'' cellspacing=''1'' cellpadding=''0''><tr><td width=''10%'' bgcolor=''#E9F5FF''> <div align=''center''><img src='
                  || image_path
                  || '/inprogressind_status.gif width=''16'' height=''16'' alt=''Pending''></div></td><td height=''22'' bgcolor=''#C3D9EE''><div align=''center''><img src='
                  || image_path
                  || '/tree_person.gif width=''16'' height=''16''></div></td></tr><tr><td colspan=2 height=''22'' bgcolor=''#FFFFFF'' nowrap><p align=''center''><span class=''OraInstructionText''>'
                  || i.employee_name
                  || '</span></p></td></tr></table></span></td></tr></table></td>';
            ELSE
               vl_approved_table :=
                  vl_approved_table || vl_line_img || vl_arrow_img
                  || '<td><table width=''100%'' border=''0'' cellspacing=''0'' cellpadding=''0'' bgcolor=''#003399'' height=''44''><tr><td><span><table width=''100%'' border=''0'' cellspacing=''1'' cellpadding=''0''><tr><td width=''10%'' bgcolor=''#E9F5FF''> <div align=''center''><img src='
                  || image_path
                  || '/okind_status.gif width=''16'' height=''16'' alt=''Approved''></div></td><td height=''22'' bgcolor=''#C3D9EE''><div align=''center''><img src='
                  || image_path
                  || '/tree_person.gif width=''16'' height=''16'' alt=''Image for approver type''></div></td></tr><tr><td colspan=2 height=''22'' bgcolor=''#FFFFFF'' nowrap><p align=''center''><span class=''OraInstructionText''>'
                  || i.employee_name
                  || '</span></p></td></tr></table></span></td></tr></table></td>';
            END IF;
         END IF;

         IF i.sequence_no = 99
         THEN
            vl_fotter := NULL;
            vl_fotter :=
                  vl_line_img
               || vl_arrow_img
               || '<td><span class=''OraLinkText''>'
               || i.action_meaning
               || '</span></td></tr></table>';
         END IF;
      END LOOP;



      approvalgraph :=
            vl_header
         || vl_arrow_img
         || vl_start_approved_table
         || vl_approved_table
         || vl_inprocess_table
         || vl_fotter;


      o_appr_graph := approvalgraph;
   END;

Oracle Api to upload Attachments (fnd_attached_documents )



CREATE OR REPLACE package body APPS.xxcust_position_upload_pkg
as
   procedure validate_position
   is
      cursor c1
      is
         select rowid row_id, new_position_name from xxcust_position_upload;

      temp_position_id   number;
   begin
      for i in c1
      loop
         temp_position_id := null;

         begin
            select position_id
              into temp_position_id
              from hr_all_positions_f y
             where 1 = 1
                   and sysdate between effective_start_date
                                   and effective_end_date
                   and name = i.new_position_name;
         exception
            when others
            then
               update xxcust_position_upload
                  set valid_flag = 'INVALID'
                where rowid = i.row_id;
         end;

         if temp_position_id is null
         then
            update xxcust_position_upload
               set valid_flag = 'INVALID'
             where rowid = i.row_id;
         else
            update xxcust_position_upload
               set new_position_id = temp_position_id
             where rowid = i.row_id;

            update xxcust_position_upload
               set valid_flag = 'VALID'
             where rowid = i.row_id;
         end if;
      end loop;
   exception
      when others
      then
         null;
   end validate_position;


   procedure validate_attahement
   is
      cursor c1
      is
         select cpos.new_position_id, cpos.new_position_name
           from fnd_attached_documents x,
                hr_all_positions_f y,
                fnd_documents fd_l,
                fnd_documents_tl fdt_l,
                fnd_lobs fl_l,
                xxcust_position_upload cpos
          where     entity_name = 'PER_POSITIONS'
                and y.position_id = to_number (x.pk1_value)
                and y.position_id = cpos.new_position_id
                and fd_l.document_id = x.document_id
                and fdt_l.document_id = fd_l.document_id
                and fdt_l.language = 'US'
                and fd_l.media_id = fl_l.file_id
                and sysdate between effective_start_date
                                and effective_end_date;

      cursor c2
      is
           select position_id, position_name
             from fnd_attached_documents x,
                  (select distinct position_id, position_name
                     from xxcust_position_upload) y,
                  fnd_documents fd_l,
                  fnd_documents_tl fdt_l,
                  fnd_lobs fl_l
            where     entity_name = 'PER_POSITIONS'
                  and y.position_id = to_number (x.pk1_value)
                  --    and    y.position_id = 28772
                  and fd_l.document_id = x.document_id
                  and fdt_l.document_id = fd_l.document_id
                  and fdt_l.language = 'US'
                  and fd_l.media_id = fl_l.file_id
         group by position_id, position_name
           having count (position_id) > 1;
   begin
      for i in c1
      loop
         begin
            update xxcust_position_upload
               set error_flag = 'E',
                   error_message =
                      'Attachement Already Exists For This Position'
             where new_position_id = i.new_position_id;
         exception
            when others
            then
               null;
         end;
      end loop;


      for j in c2
      loop
         begin
            update xxcust_position_upload
               set error_flag = 'E',
                   error_message =
                      'More Than One Attachement is available for the Parent Position'
             where position_id = j.position_id;
         exception
            when others
            then
               null;
         end;
      end loop;
   exception
      when others
      then
         null;
   end validate_attahement;


   procedure attache_position_doc
   is
      l_rowid                  rowid;
      l_attached_document_id   number;
      l_document_id            number;
      l_file_id                number;
      l_media_id               number;
      l_seq_num                number;

      cursor c1
      is
         select fl_l.file_id,
                fl_l.file_name,
                fl_l.file_content_type,
                fl_l.file_data,
                fl_l.upload_date,
                fl_l.expiration_date,
                fl_l.program_name,
                fl_l.program_tag,
                fl_l.language,
                fl_l.oracle_charset,
                fl_l.file_format,
                usage_type,
                publish_flag,
                x.category_id,
                datatype_id,
                fd_l.security_id,
                fd_l.security_type,
                description,
                title,
                y.position_id,
                y.position_name,
                y.new_position_id
           from fnd_attached_documents x,
                (select distinct position_id,
                                 position_name,
                                 new_position_id,
                                 valid_flag,
                                 error_flag,
                                 processed_flag
                   from xxcust_position_upload) y,
                fnd_documents fd_l,
                fnd_documents_tl fdt_l,
                fnd_lobs fl_l
          where     entity_name = 'PER_POSITIONS'
                and y.position_id = to_number (x.pk1_value)
                --    and    y.position_id = 28772
                and fd_l.document_id = x.document_id
                and fdt_l.document_id = fd_l.document_id
                and fdt_l.language = 'US'
                and fd_l.media_id = fl_l.file_id
                and nvl (error_flag, 'A') <> 'E'
                and nvl (processed_flag, 'A') <> 'P'
                and valid_flag = 'VALID'
                and rownum <= 2;
   begin
      for r1 in c1
      loop
         fnd_global.apps_initialize (user_id, responsibility_id, applicaiton_id);

         begin
            select fnd_lobs_s.nextval into l_file_id from dual;

            select fnd_documents_s.nextval into l_document_id from dual;

            select fnd_attached_documents_s.nextval
              into l_attached_document_id
              from dual;

            select nvl (max (seq_num), 0) + 10
              into l_seq_num
              from fnd_attached_documents
             where pk1_value = r1.new_position_id
                   and entity_name = 'PER_POSITIONS';

            insert into fnd_lobs (file_id,
                                  file_name,
                                  file_content_type,
                                  file_data,
                                  upload_date,
                                  expiration_date,
                                  program_name,
                                  program_tag,
                                  language,
                                  oracle_charset,
                                  file_format)
                 values (l_file_id,
                         r1.file_name,
                         r1.file_content_type,
                         r1.file_data,
                         sysdate,
                         r1.expiration_date,
                         r1.program_name,
                         r1.program_tag,
                         r1.language,
                         r1.oracle_charset,
                         r1.file_format);


            fnd_documents_pkg.insert_row (
               x_rowid               => l_rowid,
               x_document_id         => l_document_id,
               x_creation_date       => sysdate,
               x_created_by          => fnd_profile.value ('USER_ID'),
               x_last_update_date    => sysdate,
               x_last_updated_by     => fnd_profile.value ('USER_ID'),
               x_last_update_login   => fnd_profile.value ('LOGIN_ID'),
               x_datatype_id         => r1.datatype_id,
               x_category_id         => r1.category_id,
               x_security_type       => r1.security_type,
               x_publish_flag        => r1.publish_flag,
               x_usage_type          => r1.usage_type,
               x_language            => 'US',
               x_description         => r1.description,
               x_file_name           => r1.file_name,
               x_media_id            => l_file_id);

            fnd_documents_pkg.insert_tl_row (
               x_document_id         => l_document_id,
               x_creation_date       => sysdate,
               x_created_by          => fnd_profile.value ('USER_ID'),
               x_last_update_date    => sysdate,
               x_last_updated_by     => fnd_profile.value ('USER_ID'),
               x_last_update_login   => fnd_profile.value ('LOGIN_ID'),
               x_language            => 'US',
               x_description         => r1.description--, x_file_name                    => l_filename
                                                      --, x_media_id                     => l_media_id
               );

            fnd_attached_documents_pkg.insert_row (
               x_rowid                      => l_rowid,
               x_attached_document_id       => l_attached_document_id,
               x_document_id                => l_document_id,
               x_creation_date              => sysdate,
               x_created_by                 => fnd_profile.value ('USER_ID'),
               x_last_update_date           => sysdate,
               x_last_updated_by            => fnd_profile.value ('USER_ID'),
               x_last_update_login          => fnd_profile.value ('LOGIN_ID'),
               x_seq_num                    => l_seq_num,
               x_entity_name                => 'PER_POSITIONS',
               x_column1                    => null,
               x_pk1_value                  => r1.new_position_id,
               x_pk2_value                  => null,
               x_pk3_value                  => null,
               x_pk4_value                  => null,
               x_pk5_value                  => null,
               x_automatically_added_flag   => 'N',
               x_datatype_id                => r1.datatype_id,
               x_category_id                => r1.category_id,
               x_security_type              => r1.security_type,
               x_publish_flag               => 'Y',
               x_language                   => 'US',
               x_description                => r1.description,
               x_file_name                  => r1.file_name,
               x_media_id                   => l_file_id,
               x_title                      => r1.title);

            update xxcust_position_upload
               set processed_flag = 'P', processed_date = sysdate
             where new_position_id = r1.new_position_id;
         exception
            when others
            then
               update xxcust_position_upload
                  set processed_flag = 'E', processed_date = sysdate
                where new_position_id = r1.new_position_id;
         end;
      end loop;
   end attache_position_doc;
end xxcust_position_upload_pkg;
/

Wednesday, November 20, 2019

OAF Customization

package oracle.apps.eam.workorder.webui;

import java.sql.Timestamp;
import java.util.Calendar;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageChoiceBean;
import oracle.jbo.Row;
import oracle.jbo.ViewObject;

public class XXCreateUpdateWOCO
  extends CreateUpdateWOCO
{
  public static final String RCS_ID = "$Header: CreateUpdateWOCO.java 120.15.12010000.5 2008/12/31 08:26:12 dsingire ship $";
  public static final boolean RCS_IDRECORDED = VersionInfo.recordClassVersion("$Header: CreateUpdateWOCO.java 120.15.12010000.5 2008/12/31 08:26:12 dsingire ship $", "oracle.apps.eam.workorder.webui");
 
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
   

    OAMessageChoiceBean priority = (OAMessageChoiceBean)webBean.findChildRecursive("Priority");
    pageContext.writeDiagnostics(pageContext, " priority " + priority, 4);
    if (priority != null) {
      priority.setFireActionForSubmit("prioritySelected", null, null, true);
    }
    OAApplicationModule rootAM = pageContext.getRootApplicationModule();
    OAViewObject createUpdateVO = (OAViewObject)rootAM.findViewObject("WOCreateUpdateVO");
    if ((createUpdateVO != null) && (createUpdateVO.getCurrentRow() != null))
    {
      Row row = createUpdateVO.getCurrentRow();
      if ((row.getAttribute("RequestNumber") != null) && (row.getAttribute("InstanceNumber") != null))
      {
        String sqlQueryStatement = null;
        if (row.getAttribute("AssetActivity") == null) {
          sqlQueryStatement = "SELECT  xxasas_updatewo_pkg.get_customer_name ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_customer_number ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "')" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "')" + " FROM DUAL ";
        } else {
          sqlQueryStatement = "SELECT  xxasas_updatewo_pkg.get_customer_name ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_customer_number ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "' ,'" + row.getAttribute("AssetActivity") + "')" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "' ,'" + row.getAttribute("AssetActivity") + "')" + " FROM DUAL ";
        }
        if (rootAM.findViewObject("XXGetCustDtlsVO") != null) {
          rootAM.findViewObject("XXGetCustDtlsVO").remove();
        }
        ViewObject getCustDtlsVO = rootAM.createViewObjectFromQueryStmt("XXGetCustDtlsVO", sqlQueryStatement);
        getCustDtlsVO.executeQuery();
       
        pageContext.writeDiagnostics(pageContext, " getRowCount " + getCustDtlsVO.getRowCount(), 4);
        if (getCustDtlsVO.first() != null)
        {
          row.setAttribute("Attribute1", getCustDtlsVO.first().getAttribute(0));
          row.setAttribute("Attribute2", getCustDtlsVO.first().getAttribute(1));
          row.setAttribute("Attribute3", getCustDtlsVO.first().getAttribute(2));
          row.setAttribute("Attribute4", getCustDtlsVO.first().getAttribute(3));
        }
      }
    }
  }
 
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    pageContext.writeDiagnostics(pageContext, " LovInputSourceId " + pageContext.getLovInputSourceId(), 4);
    OAApplicationModule rootAM = pageContext.getRootApplicationModule();
    OAViewObject createUpdateVO = (OAViewObject)rootAM.findViewObject("WOCreateUpdateVO");
    if ("prioritySelected".equals(pageContext.getParameter("event")))
    {
      if ((createUpdateVO != null) && (createUpdateVO.getCurrentRow() != null))
      {
        oracle.jbo.domain.Date startDate = (oracle.jbo.domain.Date)createUpdateVO.getCurrentRow().getAttribute("ScheduledStartDate");
        pageContext.writeDiagnostics(pageContext, " startDate " + startDate.timestampValue(), 4);
        pageContext.writeDiagnostics(pageContext, " priority " + createUpdateVO.getCurrentRow().getAttribute("Priority"), 4);
       

        Calendar cal = Calendar.getInstance();
        cal.setTime(new java.util.Date(startDate.timestampValue().getTime()));
        String sqlQueryStatement = "SELECT DESCRIPTION  FROM fnd_lookup_values_vl WHERE lookup_code = " + createUpdateVO.getCurrentRow().getAttribute("Priority") + "  AND lookup_type = 'WIP_EAM_ACTIVITY_PRIORITY' ";
        if (rootAM.findViewObject("XXGetSCDforPriorityVO") != null) {
          rootAM.findViewObject("XXGetSCDforPriorityVO").remove();
        }
        ViewObject getTimeVO = rootAM.createViewObjectFromQueryStmt("XXGetSCDforPriorityVO", sqlQueryStatement);
        getTimeVO.executeQuery();
       
        pageContext.writeDiagnostics(pageContext, " getRowCount " + getTimeVO.getRowCount(), 4);
        if (getTimeVO.first() != null) {
          cal.add(10, Integer.parseInt(getTimeVO.first().getAttribute(0) + ""));
        }
        pageContext.writeDiagnostics(pageContext, " endDate " + cal.getTime(), 4);
       

        oracle.jbo.domain.Date newDate = new oracle.jbo.domain.Date(new Timestamp(cal.getTime().getTime()));
        createUpdateVO.getCurrentRow().setAttribute("ScheduledCompletionDate", newDate);
       
        pageContext.writeDiagnostics(pageContext, " newDate " + newDate, 4);
       
        pageContext.writeDiagnostics(pageContext, " SCD " + createUpdateVO.getCurrentRow().getAttribute("ScheduledCompletionDate"), 4);
      }
    }
    else if ((pageContext.isLovEvent()) && ("AssetNumber".equals(pageContext.getLovInputSourceId())))
    {
      if ((createUpdateVO != null) && (createUpdateVO.getCurrentRow() != null))
      {
        Row row = createUpdateVO.getCurrentRow();
        pageContext.writeDiagnostics(pageContext, " InstanceNumber " + createUpdateVO.getCurrentRow().getAttribute("InstanceNumber"), 4);
       
        String sqlQueryStatement = null;
        if (row.getAttribute("AssetActivity") == null) {
          sqlQueryStatement = "SELECT  xxasas_updatewo_pkg.get_customer_name ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_customer_number ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "')" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "')" + " FROM DUAL ";
        } else {
          sqlQueryStatement = "SELECT  xxasas_updatewo_pkg.get_customer_name ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_customer_number ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "' ,'" + row.getAttribute("AssetActivity") + "')" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "' ,'" + row.getAttribute("AssetActivity") + "')" + " FROM DUAL ";
        }
        if (rootAM.findViewObject("XXGetCustDtlsVO") != null) {
          rootAM.findViewObject("XXGetCustDtlsVO").remove();
        }
        ViewObject getCustDtlsVO = rootAM.createViewObjectFromQueryStmt("XXGetCustDtlsVO", sqlQueryStatement);
        getCustDtlsVO.executeQuery();
       
        pageContext.writeDiagnostics(pageContext, " getRowCount " + getCustDtlsVO.getRowCount(), 4);
        if (getCustDtlsVO.first() != null)
        {
          row.setAttribute("Attribute1", getCustDtlsVO.first().getAttribute(0));
          row.setAttribute("Attribute2", getCustDtlsVO.first().getAttribute(1));
          row.setAttribute("Attribute3", getCustDtlsVO.first().getAttribute(2));
          row.setAttribute("Attribute4", getCustDtlsVO.first().getAttribute(3));
        }
      }
    }
    else if ((pageContext.isLovEvent()) && ("Activity".equals(pageContext.getLovInputSourceId()))) {
      if ((createUpdateVO != null) && (createUpdateVO.getCurrentRow() != null))
      {
        Row row = createUpdateVO.getCurrentRow();
        pageContext.writeDiagnostics(pageContext, " InstanceNumber " + createUpdateVO.getCurrentRow().getAttribute("InstanceNumber"), 4);
        pageContext.writeDiagnostics(pageContext, " AssetActivity " + createUpdateVO.getCurrentRow().getAttribute("AssetActivity"), 4);
       

        String sqlQueryStatement = null;
        if (row.getAttribute("AssetActivity") != null) {
          sqlQueryStatement = "SELECT   xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "' ,'" + row.getAttribute("AssetActivity") + "')" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "' ,'" + row.getAttribute("AssetActivity") + "')" + " FROM DUAL ";
        } else {
          sqlQueryStatement = "SELECT   xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "' )" + " FROM DUAL ";
        }
        if (rootAM.findViewObject("XXGetCustDtlsVO") != null) {
          rootAM.findViewObject("XXGetCustDtlsVO").remove();
        }
        ViewObject getCustDtlsVO = rootAM.createViewObjectFromQueryStmt("XXGetCustDtlsVO", sqlQueryStatement);
        getCustDtlsVO.executeQuery();
       
        pageContext.writeDiagnostics(pageContext, " getRowCount " + getCustDtlsVO.getRowCount(), 4);
        if (getCustDtlsVO.first() != null)
        {
          row.setAttribute("Attribute3", getCustDtlsVO.first().getAttribute(0));
          row.setAttribute("Attribute4", getCustDtlsVO.first().getAttribute(1));
        }
      }
    }
  }
}


=========================================================

package oracle.apps.eam.workrequest.webui;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.jbo.Row;
import oracle.jbo.ViewObject;

public class XXWorkRequestDffCO
  extends WorkRequestDffCO
{
  public static final String RCS_ID = "$Header: WorkRequestDffCO.java 120.0.12010000.2 2009/05/27 13:18:56 somitra ship $";
  public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: WorkRequestDffCO.java 120.0.12010000.2 2009/05/27 13:18:56 somitra ship $", "oracle.apps.eam.workrequest.webui");
 
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
  }
 
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    pageContext.writeDiagnostics(pageContext, " LovInputSourceId " + pageContext.getLovInputSourceId(), 4);
    if ((pageContext.isLovEvent()) && ("AssetNumber".equals(pageContext.getLovInputSourceId())))
    {
      OAApplicationModule rootAM = pageContext.getRootApplicationModule();
      OAViewObject requestDetailsVO = (OAViewObject)rootAM.findViewObject("RequestDetailsVO");
      pageContext.writeDiagnostics(pageContext, " requestDetailsVO " + requestDetailsVO, 4);
      if ((requestDetailsVO != null) && (requestDetailsVO.getCurrentRow() != null))
      {
        Row row = requestDetailsVO.getCurrentRow();
        pageContext.writeDiagnostics(pageContext, " InstanceNumber " + requestDetailsVO.getCurrentRow().getAttribute("InstanceNumber"), 4);
       

        String sqlQueryStatement = "SELECT  xxasas_updatewo_pkg.get_customer_name ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_customer_number ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_type ( '" + row.getAttribute("InstanceNumber") + "' )" + " ,xxasas_updatewo_pkg.get_contract_supplier ( '" + row.getAttribute("InstanceNumber") + "' )" + " FROM DUAL ";
        if (rootAM.findViewObject("XXGetCustDtlsVO") != null) {
          rootAM.findViewObject("XXGetCustDtlsVO").remove();
        }
        ViewObject getCustDtlsVO = rootAM.createViewObjectFromQueryStmt("XXGetCustDtlsVO", sqlQueryStatement);
        getCustDtlsVO.executeQuery();
       
        pageContext.writeDiagnostics(pageContext, " getRowCount " + getCustDtlsVO.getRowCount(), 4);
        if (getCustDtlsVO.first() != null)
        {
          row.setAttribute("Attribute1", getCustDtlsVO.first().getAttribute(0));
          row.setAttribute("Attribute2", getCustDtlsVO.first().getAttribute(1));
          row.setAttribute("Attribute3", getCustDtlsVO.first().getAttribute(2));
          row.setAttribute("Attribute4", getCustDtlsVO.first().getAttribute(3));
        }
      }
    }
  }
}

Tuesday, June 25, 2019

API TO UPDATE CUSTOMER CONTACTS ON A PROJECT - Projects (pa_customers_contacts_pub)



DECLARE
   p_api_version                 NUMBER;
   p_init_msg_list               VARCHAR2 (200);
   p_commit                      VARCHAR2 (200);
   p_validate_only               VARCHAR2 (200);
   p_validation_level            NUMBER;
   p_calling_module              VARCHAR2 (200);
   p_debug_mode                  VARCHAR2 (200);
   p_max_msg_count               NUMBER;
   p_project_id                  NUMBER;
   p_customer_id                 NUMBER;
   p_bill_ship_customer_id       NUMBER;
   p_contact_id                  NUMBER;
   p_contact_name                VARCHAR2 (200);
   p_project_contact_type_code   VARCHAR2 (200);
   p_project_contact_type_name   VARCHAR2 (200);
   x_return_status               VARCHAR2 (200);
   x_msg_count                   NUMBER;
   x_msg_data                    VARCHAR2 (200);
   CURSOR c1
   IS
      SELECT ppa.project_id, ppcust.customer_id, ppa.project_type, ppcust.bill_to_customer_id, acv.contact_id,
             acv.contact_name names
      FROM   pa_project_customers_v ppcust, pa_projects_all ppa, pa_customer_contact_names_v acv
       WHERE 1 = 1
         AND ppcust.project_id = ppa.project_id
         AND acv.customer_id = ppcust.customer_id
         AND (SELECT COUNT (contact_id)
                FROM pa_customer_contact_names_v ppcn
               WHERE ppcn.customer_id = ppcust.customer_id) = 1
         AND NOT EXISTS (SELECT ppco.contact_id
                       FROM pa_project_contacts ppco
                      WHERE ppco.project_id = ppa.project_id);
BEGIN
--  fnd_global.apps_initialize (0,0 ,0);
   mo_global.init ('AR');
   FOR i IN c1
   LOOP
      BEGIN
         p_api_version := 1.0;
         p_init_msg_list := NULL;
         p_commit := 'FND_API.G_FALSE';
         p_validate_only := 'FND_API.G_TRUE';
         p_validation_level := fnd_api.g_valid_level_full;
         p_calling_module := 'SELF_SERVICE';
         p_debug_mode := 'N';
         p_max_msg_count := fnd_api.g_miss_num;
         p_project_id := i.project_id;
         p_customer_id := i.customer_id;
         p_bill_ship_customer_id := i.bill_to_customer_id;
         p_contact_id := i.contact_id;
         p_contact_name := i.names;
         p_project_contact_type_code := 'BILLING';
         x_return_status := NULL;
         x_msg_count := NULL;
         x_msg_data := NULL;
         apps.pa_customers_contacts_pub.create_customer_contact (p_api_version,
                                                                 p_init_msg_list,
                                                                 p_commit,
                                                                 p_validate_only,
                                                                 p_validation_level,
                                                                 p_calling_module,
                                                                 p_debug_mode,
                                                                 p_max_msg_count,
                                                                 p_project_id,
                                                                 p_customer_id,
                                                                 p_bill_ship_customer_id,
                                                                 p_contact_id,
                                                                 p_contact_name,
                                                                 p_project_contact_type_code,
                                                                 p_project_contact_type_name,
                                                                 x_return_status,
                                                                 x_msg_count,
                                                                 x_msg_data
                                                                );
         DBMS_OUTPUT.put_line (   'Project ID  :- '
                               || p_project_id
                               || '    x_return_status :- '
                               || x_return_status
                               || '  x_msg_count :- '
                               || x_msg_count
                               || '   x_msg_data :- '
                               || x_msg_data
                              );
         COMMIT;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (   'Error :  Project ID  :- '
                                  || p_project_id
                                  || '    x_return_status :- '
                                  || x_return_status
                                  || '  x_msg_count :- '
                                  || x_msg_count
                                  || '   x_msg_data :- '
                                  || x_msg_data
                                 );
      END;
   END LOOP;
END;

Sunday, June 9, 2019

GL Breakup

GL - AR Breakup
================================


SELECT gjh.name jv_name,
       gjh.je_category jv_category,
       gjh.je_source jv_source,
       gsl.je_line_num,
       gjl.period_name period,
       TO_CHAR (gsl.accounting_date, 'DD-Mon-YYYY') accounting_date,
       NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0) gl_amount,
       DECODE (gsl.gl_sl_link_id,
               NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
               NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
          sla_amount,
       rcta.interface_header_attribute2 plot_number,
       rcta.trx_number invoice_number,
       NULL adjustiment_number,
       NULL receipt_number,
       ac.customer_name,
       ac.customer_number,
       gsl.description
  FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
              ir.je_header_id,
               ir.je_line_num,
               TO_NUMBER (te.source_id_int_1) transaction_id,
               l.code_combination_id,
               l.accounted_dr,
               l.accounted_cr,
               l.currency_code,
               h.accounting_date,
               l.gl_sl_link_id,
               l.gl_sl_link_table,
               h.period_name,
               h.je_category_name,
               h.application_id,
               h.description
          FROM xla.xla_ae_headers h,
               xla.xla_ae_lines l,
               xla.xla_events e,
               xla.xla_transaction_entities te,
               apps.gl_import_references ir
         WHERE     e.entity_id = te.entity_id
               AND e.application_id = te.application_id
               AND te.application_id = h.application_id
               AND te.entity_id = h.entity_id
               AND e.event_id = h.event_id
               AND e.application_id = h.application_id
               AND h.ae_header_id = l.ae_header_id
               AND h.application_id = l.application_id
               AND l.gl_sl_link_id = ir.gl_sl_link_id
               AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
       apps.gl_je_headers gjh,
       apps.gl_je_lines gjl,
       apps.ra_customer_trx_all rcta,
       apps.ar_customers ac
 WHERE     gsl.je_header_id(+) = gjl.je_header_id
       AND gjl.je_header_id = gjh.je_header_id
       AND gjl.je_line_num = gsl.je_line_num(+)
       AND gjl.code_combination_id = :p_code_combination_id
       AND gjl.period_name LIKE '%' || :p_year
       AND gjh.status = 'P'          --This will pick all posted journal entry
       AND gjh.actual_flag = 'A' -- This is for Actual entry A-Actual, B-Budget
       AND rcta.customer_trx_id(+) = transaction_id
       AND ac.customer_id(+) = rcta.bill_to_customer_id
       AND je_category = 'Sales Invoices'
UNION ALL
SELECT gjh.name jv_name,
       gjh.je_category jv_category,
       gjh.je_source jv_source,
       gsl.je_line_num,
       gjl.period_name period,
       TO_CHAR (gsl.accounting_date, 'DD-Mon-YYYY') accounting_date,
       NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0) gl_amount,
       DECODE (gsl.gl_sl_link_id,
               NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
               NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
          sla_amount,
       rcta.interface_header_attribute2 plot_number,
       rcta.trx_number invoice_number,
       NULL adjustiment_number,
       NULL receipt_number,
       ac.customer_name,
       ac.customer_number,
       gsl.description
  FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
              ir.je_header_id,
               ir.je_line_num,
               TO_NUMBER (te.source_id_int_1) transaction_id,
               l.code_combination_id,
               l.accounted_dr,
               l.accounted_cr,
               l.currency_code,
               h.accounting_date,
               l.gl_sl_link_id,
               l.gl_sl_link_table,
               h.period_name,
               h.je_category_name,
               h.application_id,
               h.description
          FROM xla.xla_ae_headers h,
               xla.xla_ae_lines l,
               xla.xla_events e,
               xla.xla_transaction_entities te,
               apps.gl_import_references ir
         WHERE     e.entity_id = te.entity_id
               AND e.application_id = te.application_id
               AND te.application_id = h.application_id
               AND te.entity_id = h.entity_id
               AND e.event_id = h.event_id
               AND e.application_id = h.application_id
               AND h.ae_header_id = l.ae_header_id
               AND h.application_id = l.application_id
               AND l.gl_sl_link_id = ir.gl_sl_link_id
               AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
       apps.gl_je_headers gjh,
       apps.gl_je_lines gjl,
       apps.ra_customer_trx_all rcta,
       apps.ar_customers ac
 WHERE     gsl.je_header_id(+) = gjl.je_header_id
       AND gjl.je_header_id = gjh.je_header_id
       AND gjl.je_line_num = gsl.je_line_num(+)
       AND gjl.code_combination_id = :p_code_combination_id
       AND gjl.period_name LIKE '%' || :p_year
       AND gjh.status = 'P'          --This will pick all posted journal entry
       AND gjh.actual_flag = 'A' -- This is for Actual entry A-Actual, B-Budget
       AND rcta.customer_trx_id(+) = transaction_id
       AND ac.customer_id(+) = rcta.bill_to_customer_id
       AND je_category = 'Credit Memos'
UNION ALL
SELECT gjh.name jv_name,
       gjh.je_category jv_category,
       gjh.je_source jv_source,
       gsl.je_line_num,
       gjl.period_name period,
       TO_CHAR (gsl.accounting_date, 'DD-Mon-YYYY') accounting_date,
       NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0) gl_amount,
       DECODE (gsl.gl_sl_link_id,
               NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
               NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
          sla_amount,
       rcta.interface_header_attribute2 plot_number,
       rcta.trx_number invoice_number,
       NULL adjustiment_number,
       NULL receipt_number,
       ac.customer_name,
       ac.customer_number,
       gsl.description
  FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
              ir.je_header_id,
               ir.je_line_num,
               TO_NUMBER (te.source_id_int_1) transaction_id,
               l.code_combination_id,
               l.accounted_dr,
               l.accounted_cr,
               l.currency_code,
               h.accounting_date,
               l.gl_sl_link_id,
               l.gl_sl_link_table,
               h.period_name,
               h.je_category_name,
               h.application_id,
               h.description
          FROM xla.xla_ae_headers h,
               xla.xla_ae_lines l,
               xla.xla_events e,
               xla.xla_transaction_entities te,
               apps.gl_import_references ir
         WHERE     e.entity_id = te.entity_id
               AND e.application_id = te.application_id
               AND te.application_id = h.application_id
               AND te.entity_id = h.entity_id
               AND e.event_id = h.event_id
               AND e.application_id = h.application_id
               AND h.ae_header_id = l.ae_header_id
               AND h.application_id = l.application_id
               AND l.gl_sl_link_id = ir.gl_sl_link_id
               AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
       apps.gl_je_headers gjh,
       apps.gl_je_lines gjl,
       apps.ra_customer_trx_all rcta,
       apps.ar_customers ac
 WHERE     gsl.je_header_id(+) = gjl.je_header_id
       AND gjl.je_header_id = gjh.je_header_id
       AND gjl.je_line_num = gsl.je_line_num(+)
       AND gjl.code_combination_id = :p_code_combination_id
       AND gjl.period_name LIKE '%' || :p_year
       AND gjh.status = 'P'          --This will pick all posted journal entry
       AND gjh.actual_flag = 'A' -- This is for Actual entry A-Actual, B-Budget
       AND rcta.customer_trx_id(+) = transaction_id
       AND ac.customer_id(+) = rcta.bill_to_customer_id
       AND je_category = 'Debit Memos'
UNION ALL
SELECT gjh.name jv_name,
       gjh.je_category jv_category,
       gjh.je_source jv_source,
       gsl.je_line_num,
       gjl.period_name period,
       TO_CHAR (gsl.accounting_date, 'DD-Mon-YYYY') accounting_date,
       NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0) gl_amount,
       DECODE (gsl.gl_sl_link_id,
               NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
               NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
          sla_amount,
       rcta.interface_header_attribute2 plot_number,
       rcta.trx_number invoice_number,
       ADJUSTMENT_NUMBER  adjustiment_number,
       NULL receipt_number,
       ac.customer_name,
       ac.customer_number,
       gsl.description
  FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
              ir.je_header_id,
               ir.je_line_num,
               TO_NUMBER (te.source_id_int_1) transaction_id,
               l.code_combination_id,
               l.accounted_dr,
               l.accounted_cr,
               l.currency_code,
               h.accounting_date,
               l.gl_sl_link_id,
               l.gl_sl_link_table,
               h.period_name,
               h.je_category_name,
               h.application_id,
               h.description
          FROM xla.xla_ae_headers h,
               xla.xla_ae_lines l,
               xla.xla_events e,
               xla.xla_transaction_entities te,
               apps.gl_import_references ir
         WHERE     e.entity_id = te.entity_id
               AND e.application_id = te.application_id
               AND te.application_id = h.application_id
               AND te.entity_id = h.entity_id
               AND e.event_id = h.event_id
               AND e.application_id = h.application_id
               AND h.ae_header_id = l.ae_header_id
               AND h.application_id = l.application_id
               AND l.gl_sl_link_id = ir.gl_sl_link_id
               AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
       apps.gl_je_headers gjh,
       apps.gl_je_lines gjl,
       apps.ar_adjustments_all aaa,
       apps.ra_customer_trx_all rcta,
       apps.ar_customers ac
 WHERE     gsl.je_header_id(+) = gjl.je_header_id
       AND gjl.je_header_id = gjh.je_header_id
       AND gjl.je_line_num = gsl.je_line_num(+)
       AND gjl.code_combination_id = :p_code_combination_id
       AND gjl.period_name LIKE '%' || :p_year
       AND gjh.status = 'P'          --This will pick all posted journal entry
       AND gjh.actual_flag = 'A' -- This is for Actual entry A-Actual, B-Budget
       AND aaa.adjustment_id(+) = transaction_id
       AND rcta.customer_trx_id(+) = aaa.customer_trx_id
       AND ac.customer_id(+) = rcta.bill_to_customer_id
       AND je_category = 'Adjustment'
UNION ALL
SELECT gjh.name jv_name,
       gjh.je_category jv_category,
       gjh.je_source jv_source,
       gsl.je_line_num,
       gjl.period_name period,
       TO_CHAR (gsl.accounting_date, 'DD-Mon-YYYY') accounting_date,
       NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0) gl_amount,
       DECODE (gsl.gl_sl_link_id,
               NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
               NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
          sla_amount,
       (SELECT location_code
          FROM apps.pn_locations_all
         WHERE TO_CHAR (location_id) = rcta.attribute2)
          plot_number,
       NULL invoice_number,
       NULL adjustiment_number,
       rcta.receipt_number receipt_number,
       ac.customer_name,
       ac.customer_number,
       gsl.description
  FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
              ir.je_header_id,
               ir.je_line_num,
               TO_NUMBER (te.source_id_int_1) transaction_id,
               l.code_combination_id,
               l.accounted_dr,
               l.accounted_cr,
               l.currency_code,
               h.accounting_date,
               l.gl_sl_link_id,
               l.gl_sl_link_table,
               h.period_name,
               h.je_category_name,
               h.application_id,
               h.description
          FROM xla.xla_ae_headers h,
               xla.xla_ae_lines l,
               xla.xla_events e,
               xla.xla_transaction_entities te,
               apps.gl_import_references ir
         WHERE     e.entity_id = te.entity_id
               AND e.application_id = te.application_id
               AND te.application_id = h.application_id
               AND te.entity_id = h.entity_id
               AND e.event_id = h.event_id
               AND e.application_id = h.application_id
               AND h.ae_header_id = l.ae_header_id
               AND h.application_id = l.application_id
               AND l.gl_sl_link_id = ir.gl_sl_link_id
               AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
       apps.gl_je_headers gjh,
       apps.gl_je_lines gjl,
       apps.ar_cash_receipts_all rcta,
       apps.ar_customers ac
 WHERE     gsl.je_header_id(+) = gjl.je_header_id
       AND gjl.je_header_id = gjh.je_header_id
       AND gjl.je_line_num = gsl.je_line_num(+)
       AND gjl.code_combination_id = :p_code_combination_id
       AND gjl.period_name LIKE '%' || :p_year
       AND gjh.status = 'P'          --This will pick all posted journal entry
       AND gjh.actual_flag = 'A' -- This is for Actual entry A-Actual, B-Budget
       AND rcta.cash_receipt_id(+) = transaction_id
       AND ac.customer_id(+) = rcta.pay_from_customer
       AND je_category = 'Receipts'
UNION ALL
SELECT gjh.name jv_name,
       gjh.je_category jv_category,
       gjh.je_source jv_source,
       gsl.je_line_num,
       gjl.period_name period,
       TO_CHAR (gsl.accounting_date, 'DD-Mon-YYYY') accounting_date,
       NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0) gl_amount,
       DECODE (gsl.gl_sl_link_id,
               NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
               NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
          sla_amount,
       NULL plot_number,
       NULL invoice_number,
       NULL adjustiment_number,
       NULL receipt_number,
       NULL customer_name,
       NULL customer_number,
       NULL description
  FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
              ir.je_header_id,
               ir.je_line_num,
               TO_NUMBER (te.source_id_int_1) transaction_id,
               l.code_combination_id,
               l.accounted_dr,
               l.accounted_cr,
               l.currency_code,
               h.accounting_date,
               l.gl_sl_link_id,
               l.gl_sl_link_table,
               h.period_name,
               h.je_category_name,
               h.application_id,
               h.description
          FROM xla.xla_ae_headers h,
               xla.xla_ae_lines l,
               xla.xla_events e,
               xla.xla_transaction_entities te,
               apps.gl_import_references ir
         WHERE     e.entity_id = te.entity_id
               AND e.application_id = te.application_id
               AND te.application_id = h.application_id
               AND te.entity_id = h.entity_id
               AND e.event_id = h.event_id
               AND e.application_id = h.application_id
               AND h.ae_header_id = l.ae_header_id
               AND h.application_id = l.application_id
               AND l.gl_sl_link_id = ir.gl_sl_link_id
               AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
       apps.gl_je_headers gjh,
       apps.gl_je_lines gjl,
       apps.ar_cash_receipts_all rcta,
       apps.ar_customers ac
 WHERE     gsl.je_header_id(+) = gjl.je_header_id
       AND gjl.je_header_id = gjh.je_header_id
       AND gjl.je_line_num = gsl.je_line_num(+)
       AND gjl.code_combination_id = :p_code_combination_id
       AND gjl.period_name LIKE '%' || :p_year
       AND gjh.status = 'P'          --This will pick all posted journal entry
       AND gjh.actual_flag = 'A' -- This is for Actual entry A-Actual, B-Budget
       AND rcta.cash_receipt_id(+) = transaction_id
       AND ac.customer_id(+) = rcta.pay_from_customer
       AND je_category = '210'

===========================================================

Encumbrance Query

=============

/* Formatted on 18/09/2017 09:21:20 (QP5 v5.256.13226.35510) */
  SELECT 'Requisitions' "GL Entry Type",
         prha.creation_date,
         prha.segment1 "REQ Number",
         TO_CHAR (prha.creation_date, 'DD-Mon-YYYY') "REQ Creation Date",
         gsl.description "JV REQ Number",
         SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1)
            "Amount"
    FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
                ir.je_header_id,
                 ir.je_line_num,
                 TO_NUMBER (te.source_id_int_1) transaction_id,
                 l.code_combination_id,
                 l.accounted_dr,
                 l.accounted_cr,
                 l.currency_code,
                 h.accounting_date,
                 l.gl_sl_link_id,
                 l.gl_sl_link_table,
                 h.period_name,
                 h.je_category_name,
                 h.application_id,
                 h.description,
                 e.event_id,
                 h.ae_header_id,
                 l.ae_line_num
            FROM xla.xla_ae_headers h,
                 xla.xla_ae_lines l,
                 xla.xla_events e,
                 xla.xla_transaction_entities te,
                 apps.gl_import_references ir
           WHERE     e.entity_id = te.entity_id
                 AND e.application_id = te.application_id
                 AND te.application_id = h.application_id
                 AND te.entity_id = h.entity_id
                 AND e.event_id = h.event_id
                 AND e.application_id = h.application_id
                 AND h.ae_header_id = l.ae_header_id
                 AND h.application_id = l.application_id
                 AND l.gl_sl_link_id = ir.gl_sl_link_id
                 AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
         apps.gl_je_headers gjh,
         apps.gl_je_lines gjl,
         apps.po_requisition_headers_all prha
   WHERE     gsl.je_header_id(+) = gjl.je_header_id
         AND gjl.je_header_id = gjh.je_header_id
         AND gjl.je_line_num = gsl.je_line_num(+)
         AND gjl.code_combination_id = :p_code_combination_id
         AND gjl.period_name LIKE '%' || :p_year
         AND gjh.status = 'P'        --This will pick all posted journal entry
         AND gjh.actual_flag = 'E' -- This is for Actual entry A-Actual, B-Budget
         AND je_category = 'Requisitions'
         AND prha.requisition_header_id(+) = gsl.transaction_id
GROUP BY prha.segment1, gsl.description, prha.creation_date
  HAVING SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1) <> 0
UNION ALL
  SELECT 'Purchases',
         prha.creation_date,
         prha.segment1 "PO Number",
         TO_CHAR (prha.creation_date, 'DD-Mon-YYYY') "PO Creation Date",
         gsl.description "JV PO Number",
         SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1)
            "Amount"
    FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
                ir.je_header_id,
                 ir.je_line_num,
                 TO_NUMBER (te.source_id_int_1) transaction_id,
                 l.code_combination_id,
                 l.accounted_dr,
                 l.accounted_cr,
                 l.currency_code,
                 h.accounting_date,
                 l.gl_sl_link_id,
                 l.gl_sl_link_table,
                 h.period_name,
                 h.je_category_name,
                 h.application_id,
                 h.description,
                 e.event_id,
                 h.ae_header_id,
                 l.ae_line_num
            FROM xla.xla_ae_headers h,
                 xla.xla_ae_lines l,
                 xla.xla_events e,
                 xla.xla_transaction_entities te,
                 apps.gl_import_references ir
           WHERE     e.entity_id = te.entity_id
                 AND e.application_id = te.application_id
                 AND te.application_id = h.application_id
                 AND te.entity_id = h.entity_id
                 AND e.event_id = h.event_id
                 AND e.application_id = h.application_id
                 AND h.ae_header_id = l.ae_header_id
                 AND h.application_id = l.application_id
                 AND l.gl_sl_link_id = ir.gl_sl_link_id
                 AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
         apps.gl_je_headers gjh,
         apps.gl_je_lines gjl,
         apps.po_headers_all prha
   WHERE     gsl.je_header_id(+) = gjl.je_header_id
         AND gjl.je_header_id = gjh.je_header_id
         AND gjl.je_line_num = gsl.je_line_num(+)
         AND gjl.code_combination_id = :p_code_combination_id
         AND gjl.period_name LIKE '%' || :p_year
         AND gjh.status = 'P'        --This will pick all posted journal entry
         AND gjh.actual_flag = 'E' -- This is for Actual entry A-Actual, B-Budget
         AND je_category = 'Purchases'
         AND prha.po_header_id(+) = gsl.transaction_id
GROUP BY prha.segment1, gsl.description, prha.creation_date
  HAVING SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1) <> 0
UNION ALL
  SELECT 'Receiving',
         pha.creation_date,
         pha.segment1 "PO Number",
         TO_CHAR (pha.creation_date, 'DD-Mon-YYYY') "PO Creation Date",
         gsl.description "JV PO Number",
         SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1)
            "Amount"
    FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
                ir.je_header_id,
                 ir.je_line_num,
                 TO_NUMBER (te.source_id_int_1) transaction_id,
                 l.code_combination_id,
                 l.accounted_dr,
                 l.accounted_cr,
                 l.currency_code,
                 h.accounting_date,
                 l.gl_sl_link_id,
                 l.gl_sl_link_table,
                 h.period_name,
                 h.je_category_name,
                 h.application_id,
                 h.description,
                 e.event_id,
                 h.ae_header_id,
                 l.ae_line_num,
                 prha.source_distribution_id_num_1,
                 TO_NUMBER (rrsl.reference3) po_dist_id
            FROM xla.xla_ae_headers h,
                 xla.xla_ae_lines l,
                 xla.xla_events e,
                 xla.xla_transaction_entities te,
                 apps.gl_import_references ir,
                 apps.xla_distribution_links prha,
                 apps.rcv_receiving_sub_ledger rrsl
           WHERE     e.entity_id = te.entity_id
                 AND e.application_id = te.application_id
                 AND te.application_id = h.application_id
                 AND te.entity_id = h.entity_id
                 AND e.event_id = h.event_id
                 AND e.application_id = h.application_id
                 AND h.ae_header_id = l.ae_header_id
                 AND h.application_id = l.application_id
                 AND l.gl_sl_link_id = ir.gl_sl_link_id
                 AND l.gl_sl_link_table = ir.gl_sl_link_table
                 AND prha.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER'
                 AND prha.ae_header_id = h.ae_header_id
                 AND prha.ae_line_num = l.ae_line_num
                 AND rrsl.rcv_sub_ledger_id = prha.source_distribution_id_num_1)
         gsl,
         apps.gl_je_headers gjh,
         apps.gl_je_lines gjl,
         apps.po_distributions_all pda,
         apps.po_headers_all pha
   WHERE     gsl.je_header_id(+) = gjl.je_header_id
         AND gjl.je_header_id = gjh.je_header_id
         AND gjl.je_line_num = gsl.je_line_num(+)
         AND gjl.code_combination_id = :p_code_combination_id
         AND gjl.period_name LIKE '%' || :p_year
         AND gjh.status = 'P'        --This will pick all posted journal entry
         AND gjh.actual_flag = 'E' -- This is for Actual entry A-Actual, B-Budget
         AND je_category = 'Receiving'
         AND gsl.po_dist_id = pda.po_distribution_id(+)
         AND pda.po_header_id = pha.po_header_id(+)
GROUP BY pha.segment1, gsl.description, pha.creation_date
  HAVING SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1) <> 0
UNION ALL
  SELECT 'Purchase Invoices',
         prha.creation_date,
         prha.invoice_num "Invoice Number",
         TO_CHAR (prha.creation_date, 'DD-Mon-YYYY') "Invoice Creation Date",
         gsl.description "JV INV Number",
         SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1)
            "Amount"
    FROM (SELECT /*+ leading(ir,l,h) cardinality(ir,10)  */
                ir.je_header_id,
                 ir.je_line_num,
                 TO_NUMBER (te.source_id_int_1) transaction_id,
                 l.code_combination_id,
                 l.accounted_dr,
                 l.accounted_cr,
                 l.currency_code,
                 h.accounting_date,
                 l.gl_sl_link_id,
                 l.gl_sl_link_table,
                 h.period_name,
                 h.je_category_name,
                 h.application_id,
                 h.description,
                 e.event_id,
                 h.ae_header_id,
                 l.ae_line_num
            FROM xla.xla_ae_headers h,
                 xla.xla_ae_lines l,
                 xla.xla_events e,
                 xla.xla_transaction_entities te,
                 apps.gl_import_references ir
           WHERE     e.entity_id = te.entity_id
                 AND e.application_id = te.application_id
                 AND te.application_id = h.application_id
                 AND te.entity_id = h.entity_id
                 AND e.event_id = h.event_id
                 AND e.application_id = h.application_id
                 AND h.ae_header_id = l.ae_header_id
                 AND h.application_id = l.application_id
                 AND l.gl_sl_link_id = ir.gl_sl_link_id
                 AND l.gl_sl_link_table = ir.gl_sl_link_table) gsl,
         apps.gl_je_headers gjh,
         apps.gl_je_lines gjl,
         apps.ap_invoices_all prha
   WHERE     gsl.je_header_id(+) = gjl.je_header_id
         AND gjl.je_header_id = gjh.je_header_id
         AND gjl.je_line_num = gsl.je_line_num(+)
         AND gjl.code_combination_id = :p_code_combination_id
         AND gjl.period_name LIKE '%' || :p_year
         AND gjh.status = 'P'        --This will pick all posted journal entry
         AND gjh.actual_flag = 'E' -- This is for Actual entry A-Actual, B-Budget
         AND je_category = 'Purchase Invoices'
         AND prha.invoice_id(+) = gsl.transaction_id
GROUP BY prha.invoice_num, gsl.description, prha.creation_date
  HAVING SUM (
              DECODE (
                 gsl.gl_sl_link_id,
                 NULL, NVL (gjl.accounted_cr, 0) - NVL (gjl.accounted_dr, 0),
                 NVL (gsl.accounted_cr, 0) - NVL (gsl.accounted_dr, 0))
            * -1) <> 0
ORDER BY 1, 2


============================

Remove Next Line from Sql
=============================

   regexp_replace(acr.comments ,'[[:space:]]',' ')

KEY: 3-28634-01281-67446-26577
MSG: ARABIAN DANISH PAINT COMPANY
KEY: 1-49900-63081-22632-88752
MSG: DUBAI WORLD


Print Negitive amount in Bracket - select to_char(-133133,'9999999999D99PR')  from dual


PDC
======================

 SELECT ac.customer_name,
         ac.customer_number,
         acr.receipt_number,
         acr.receipt_date,
         aps.due_date,
         acr.amount,
         SUM (NVL (ad.amount_dr, 0) - NVL (ad.amount_cr, 0))
    FROM apps.ar_cash_receipts_all acr,
         apps.ar_receipt_method_accounts_all arma,
         apps.gl_code_combinations_kfv gc,
         apps.ar_payment_schedules_all aps,
         apps.ar_customers ac,
         apps.ar_cash_receipt_history_all crh,
         apps.ar_distributions_all ad,
         apps.gl_code_combinations_kfv gc2
   WHERE     acr.org_id = 2965
         AND ac.customer_id = acr.pay_from_customer
         AND arma.receipt_method_id = acr.receipt_method_id
         AND arma.remit_bank_acct_use_id = acr.remit_bank_acct_use_id
         AND arma.cash_ccid = gc.code_combination_id
         AND aps.cash_receipt_id = acr.cash_receipt_id
         AND crh.cash_receipt_id = acr.cash_receipt_id
         AND gc.segment1 = '0811'
         AND ad.source_table = 'CRH'
         AND ad.source_id = crh.cash_receipt_history_id
         AND gc2.code_combination_id = ad.code_combination_id
         AND gc2.concatenated_segments =
--         AND crh.gl_date <= '30-JUN-2016'
         AND crh.gl_posted_date between '01-SEP-2016'  AND '30-SEP-2016'
GROUP BY ac.customer_name,
         ac.customer_number,
         acr.receipt_number,
         acr.receipt_date,
         aps.due_date,
         acr.amount
  HAVING SUM (NVL (ad.amount_dr, 0) - NVL (ad.amount_cr, 0)) <> 0
================================

AR Aging 
==============

SELECT a.*,
       CASE WHEN (TRUNC (SYSDATE) - due_date + 1) <= 0 THEN tot ELSE 0 END
          future_payment,
       CASE
          WHEN (TRUNC (SYSDATE) - due_date + 1) BETWEEN 1 AND 30 THEN tot
          ELSE 0
       END
          day_1_30,
       CASE
          WHEN (TRUNC (SYSDATE) - due_date + 1) BETWEEN 31 AND 60 THEN tot
          ELSE 0
       END
          day_31_60,
       CASE
          WHEN (TRUNC (SYSDATE) - due_date + 1) BETWEEN 61 AND 90 THEN tot
          ELSE 0
       END
          day_61_90,
       CASE
          WHEN (TRUNC (SYSDATE) - due_date + 1) BETWEEN 91 AND 180 THEN tot
          ELSE 0
       END
          day_91_180,
       CASE
          WHEN (TRUNC (SYSDATE) - due_date + 1) BETWEEN 181 AND 365 THEN tot
          ELSE 0
       END
          day_181_365,
       CASE WHEN (TRUNC (SYSDATE) - due_date + 1) > 365 THEN tot ELSE 0 END
          day_above_365
  FROM (  SELECT ac.customer_name,
                 ac.customer_number,
                 rct.trx_number,
                 rct.trx_date,
                 rct.ct_reference,
                 aps.due_date,
                 aps.amount_due_original,
                 SUM (
                      (aps.amount_due_original)
                    + (NVL (
                          (SELECT SUM (amount)
                             FROM apps.ar_adjustments_all
                            WHERE     customer_trx_id = rct.customer_trx_id --           AND apply_date   < = :p_date
                                  AND gl_date <= TO_DATE ( :p_date)),
                          0))
                    - (NVL (
                          (SELECT SUM (acctd_amount_applied_from)
                             FROM apps.ar_receivable_applications_all
                            WHERE     1 = 1
                                  --                                             apply_date                 < =to_date(:p_date)
                                  AND gl_date <= TO_DATE ( :p_date)
                                  AND application_type = 'CASH'
                                  AND applied_payment_schedule_id =
                                         aps.payment_schedule_id),
                          0))
                    + (NVL (
                          (SELECT SUM (acctd_amount_applied_from)
                             FROM apps.ar_receivable_applications_all
                            WHERE     1 = 1
                                  --                                             apply_date                 < =to_date(:p_date)
                                  AND gl_date <= TO_DATE ( :p_date)
                                  AND application_type = 'CM'
                                  AND customer_trx_id = aps.customer_trx_id),
                          0))
                    - (NVL (
                          (SELECT SUM (acctd_amount_applied_from)
                             FROM apps.ar_receivable_applications_all
                            WHERE     1 = 1
                                  --                                             apply_date                 < =to_date(:p_date)
                                  AND gl_date <= TO_DATE ( :p_date)
                                  AND application_type = 'CM'
                                  AND applied_customer_trx_id =
                                         aps.customer_trx_id),
                          0))                               --             ,0)
                             )
                    tot
            FROM apps.ra_customer_trx_all rct,
                 apps.ra_cust_trx_line_gl_dist_all rctgl,
                 apps.gl_code_combinations_kfv gc,
                 apps.ar_payment_schedules_all aps,
                 apps.ar_customers ac
           WHERE     rct.customer_trx_id = rctgl.customer_trx_id
                 AND ac.customer_id = rct.bill_to_customer_id
                 AND 'Y' =
                        DECODE (rct.invoicing_rule_id,
                                NULL, 'Y',
                                rctgl.account_set_flag)
                 AND rctgl.code_combination_id = gc.code_combination_id
                 AND gc.segment1 = '0811'
                 AND gc.segment3 = '121100'
                 AND rctgl.account_class = 'REC'
                 AND aps.customer_trx_id = rct.customer_trx_id
                 AND rct.org_id = 2965
                 AND aps.gl_date <= :p_date
        GROUP BY ac.customer_name,
                 rct.trx_number,
                 rct.trx_date,
                 rct.ct_reference,
                     ac.customer_number,
                 aps.due_date,
                 aps.amount_due_original
          HAVING SUM (
                      (aps.amount_due_original)
                    + (NVL (
                          (SELECT SUM (amount)
                             FROM apps.ar_adjustments_all
                            WHERE     customer_trx_id = rct.customer_trx_id --           AND apply_date   < = :p_date
                                  AND gl_date <= TO_DATE ( :p_date)),
                          0))
                    - (NVL (
                          (SELECT SUM (acctd_amount_applied_from)
                             FROM apps.ar_receivable_applications_all
                            WHERE     1 = 1
                                  --                                             apply_date                 < =to_date(:p_date)
                                  AND gl_date <= TO_DATE ( :p_date)
                                  AND application_type = 'CASH'
                                  AND applied_payment_schedule_id =
                                         aps.payment_schedule_id),
                          0))
                    + (NVL (
                          (SELECT SUM (acctd_amount_applied_from)
                             FROM apps.ar_receivable_applications_all
                            WHERE     1 = 1
                                  --                                             apply_date                 < =to_date(:p_date)
                                  AND gl_date <= TO_DATE ( :p_date)
                                  AND application_type = 'CM'
                                  AND customer_trx_id = aps.customer_trx_id),
                          0))
                    - (NVL (
                          (SELECT SUM (acctd_amount_applied_from)
                             FROM apps.ar_receivable_applications_all
                            WHERE     1 = 1
                                  --                                             apply_date                 < =to_date(:p_date)
                                  AND gl_date <= TO_DATE ( :p_date)
                                  AND application_type = 'CM'
                                  AND applied_customer_trx_id =
                                         aps.customer_trx_id),
                          0))                               --             ,0)
                             ) <> 0) a

==========================

AR Revenue

============

SELECT gc.segment1 bu,
         gc.concatenated_segments,
         --gc.segment3  Account,
         rct.trx_number,
         ac.customer_name,
         ac.customer_number,
         pl.lease_num,
         plu.location_code,
         space_type plot_type,
         (SELECT ptta.name
            FROM apps.pn_term_templates_all ptta
           WHERE ptta.term_template_id(+) = ppt.term_template_id)
            payment_term_type,
         gc.segment2,
         gc.segment3 gl_account,
         TO_CHAR ( (rctg.gl_date)) gl_date,
         SUM (rctg.amount) gl_amount
    FROM apps.ra_customer_trx_all rct,
         apps.ra_cust_trx_line_gl_dist_all rctg,
         apps.gl_code_combinations_kfv gc,
         apps.ra_customer_trx_lines_all rctl,
         apps.pn_leases_all pl,
         apps.pn_payment_items_all ppi,
         apps.pn_payment_terms_all ppt,
         apps.xxfin_pn_locations_pub_v plu,
         apps.ar_customers ac
   WHERE     rct.batch_source_id = 24
         AND ac.customer_id = pl.customer_id
         AND ppt.location_id = plu.location_id
         AND rct.customer_trx_id = rctg.customer_trx_id
         AND rctl.customer_trx_id = rct.customer_trx_id
         AND rctl.customer_trx_line_id = rctg.customer_trx_line_id
         AND gc.code_combination_id = rctg.code_combination_id
         AND NVL (rctg.account_set_flag, 'N') <> 'Y'
         AND rctg.account_class = 'REV'
         AND rctl.interface_line_attribute10 = pl.lease_num
         AND ppt.lease_id = pl.lease_id
         AND rct.org_id = 2965
         AND gc.segment3 = '612530'
         AND rctg.org_id = rct.org_id
         --and NVL(fnd_profile.value('XXFIN_PN_SALE_ACCESS'),'N') = decode(tenure_code,'L','N','Y')
         AND ppi.payment_term_id = ppt.payment_term_id
         AND rctl.interface_line_attribute1 =
                pl.lease_num || ' - ' || ppi.payment_item_id
         --and gc.segment3 = nvl(:p_seg3,gc.segment3)
         AND rctg.gl_date >= NVL ( :p_from_date, rctg.gl_date)
         AND rctg.gl_date <= NVL ( :p_to_date, rctg.gl_date)
GROUP BY gc.segment1,
         rct.trx_number,
         ac.customer_name,
         gc.concatenated_segments,
         ac.customer_number,
         pl.lease_num,
         plu.location_code,
         space_type,
         gc.segment2,
         gc.segment3,
         rctg.gl_date,
         ppt.term_template_id
UNION ALL
  SELECT gc.segment1 bu,
         gc.concatenated_segments,
         --gc.segment3  Account,
         rct.trx_number,
         ac.customer_name,
         ac.customer_number,
         NULL lease_num,
         NULL location_code,
         NULL plot_type,
         NULL payment_term_type,
         gc.segment2,
         gc.segment3 gl_account,
         TO_CHAR ( (rctg.gl_date)) gl_date,
         SUM (rctg.amount) gl_amount
    FROM apps.ra_customer_trx_all rct,
         apps.ra_cust_trx_line_gl_dist_all rctg,
         apps.gl_code_combinations_kfv gc,
         apps.ra_customer_trx_lines_all rctl,
         --         apps.pn_leases_all pl,
         --         apps.pn_payment_items_all ppi,
         --         apps.pn_payment_terms_all ppt,
         --         apps.xxfin_pn_locations_pub_v plu,
         apps.ar_customers ac
   WHERE    1=1
--   AND  rct.batch_source_id = 24
         AND ac.customer_id = rct.bill_to_customer_id
         --         AND ppt.location_id = plu.location_id
         AND rct.customer_trx_id = rctg.customer_trx_id
         AND rctl.customer_trx_id = rct.customer_trx_id
         AND rctl.customer_trx_line_id = rctg.customer_trx_line_id
         AND gc.code_combination_id = rctg.code_combination_id
         AND NVL (rctg.account_set_flag, 'N') <> 'Y'
         AND rctg.account_class = 'REV'
         AND rctl.interface_line_attribute10 IS NULL
         --         AND ppt.lease_id = pl.lease_id
         AND rct.org_id = 2965
         AND gc.segment3 = '612530'
         AND rctg.org_id = rct.org_id
         --and NVL(fnd_profile.value('XXFIN_PN_SALE_ACCESS'),'N') = decode(tenure_code,'L','N','Y')
         --         AND ppi.payment_term_id = ppt.payment_term_id
         AND rctl.interface_line_attribute1 IS NULL
         --and gc.segment3 = nvl(:p_seg3,gc.segment3)
         AND rctg.gl_date >= NVL ( :p_from_date, rctg.gl_date)
         AND rctg.gl_date <= NVL ( :p_to_date, rctg.gl_date)
GROUP BY gc.segment1,
         rct.trx_number,
         ac.customer_name,
         gc.concatenated_segments,
         ac.customer_number,
         --         pl.lease_num,
         --         plu.location_code,
         --         space_type,
         gc.segment2,
         gc.segment3,
         rctg.gl_date
--         ppt.term_template_id