#!/usr/bin/ksh
# whatsetofbooks ()
#------------------------------------------------------------------------------#
#    Module Name:  whatsob                                                     #
#                                                                              #
#    Purpose:      Report on the Set Of Books and Accounting-Period-Statuses.  #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    10-Oct-2009   M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        HNAME=$(uname -n)
                
        clear
        echo
        echo  " #--------------------------------------------------------#"
        echo  " # whatsetofbooks:  Oracle Apps Set Of Books and Periods  #"
        echo  " #--------------------------------------------------------#"
        echo
        #------------------------------------------------------------------#
        #  Trap:  Set CNTL-C CNTL-D CNTL-\ Before Password Protection      #
        #------------------------------------------------------------------#
        trap        "stty echo; return"     2
        trap        "stty echo; return"     3
        stty -echo
        read PASSWD?" Please Enter the Oracle APPS Passwd: " 
            
        stty echo
        echo
        #------------------------------------------------------------------#
        #  Trap:  Reset CNTL-C CNTL-D CNTL-\ After Password Protection     #
        #------------------------------------------------------------------#
        trap        2
        trap        3
        clear
        ORANAM=${ORASID}

#------------------------------------------------------------------------------#
#  SQL*Plus ("Here-Document")                                                  #
#------------------------------------------------------------------------------#
sqlplus  -s  /nolog  <<-END_FILE
        CONNECT  APPS/$PASSWD
        
        clear   BREAKS
        clear   BUFFER
        clear   COLUMNS
        clear   COMPUTES
        clear   SCREEN
        clear   SQL
        clear   TIMING

        set     feedback        off
        set     flush           on
        set     heading         on
        set     pause           off
        set     space           1
        set     termout         on
        set     verify          on
        set     linesize        80
        set     pagesize        999
        
        SPOOL /tmp/whatsetofbooks_$$.txt
        
        COLUMN  datevalue       NOPRINT NEW_VALUE       DATEVAR
        COLUMN  timevalue       NOPRINT NEW_VALUE       TIMEVAR
        
        BREAK   ON  set_of_books_id     skip 0  ON REPORT
        
        COMPUTE SUM LABEL 'Total' OF ccount ON ccount
        
        COLUMN set_of_books_id  FORMAT 9999     HEADING 'Set|Of|Bks|ID'
        COLUMN period_set_name  FORMAT A15      HEADING 'Period|Set Name'
        COLUMN name             FORMAT A22      HEADING 'GL Period|Name'
        COLUMN description      FORMAT A22      HEADING 'GL Description'
        COLUMN cstatus          FORMAT A7       HEADING 'GL SOB|Status'
        COLUMN ccount           FORMAT 999      HEADING 'Co-|unt'
        
        TTITLE  CENTER  'Oracle E-Business Suite SetsOfBooks'           -
                LEFT    DATEVAR                                         -
                RIGHT   'Page:'         FORMAT 999 SQL.pno      skip 1  -
                CENTER  'whatsetofbooks -- Sorted by Org_ID’            -
                LEFT    TIMEVAR                                 skip 2
        
        SELECT  TO_CHAR(sysdate, 'DD-MON-YY')   datevalue,
                TO_CHAR(sysdate, 'HH24:MI:SS')  timevalue,
                gsob.set_of_books_id, gsob.period_set_name,
                gsob.name, gsob.description,
                DECODE (gps.closing_status,
                    'O', 'Open',
                    'C', 'Closed',
                    'F', 'Future',
                    'N', 'Never',
                    'P', 'Permanently Closed') cstatus,
                    count(gps.closing_status)  ccount
        FROM    gl_period_statuses gps,
                gl_sets_of_books   gsob
        WHERE   gps.application_id   = 101 and
                gsob.set_of_books_id = gps.set_of_books_id
        GROUP BY gsob.set_of_books_id, gsob.period_set_name, gsob.name,
                gsob.description, gps.closing_status
        ORDER BY set_of_books_id,
                 gps.closing_status;
EXIT;
END_FILE
print
print "Please see /tmp/whatsetofbooks_$$.txt"
print
}
