#!/usr/bin/ksh
#whatwfstatus ()
#------------------------------------------------------------------------------#
#    Module Name:  whatwfstatus                                                #
#                                                                              #
#    Purpose:      Report on the WorkFlow Services (Status).                   #
#                                                                              #
#    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)

        #----------------------------------------------------------------------#
        #  TEST:  Number ($#) of arguments passed to this function?            #
        #----------------------------------------------------------------------#
	if      [ $# = 0 ]
	then
	    clear
	    echo
	    echo  " #--------------------------------------------------------#"
	    echo  " # whatwfstatus:              Oracle Apps WorkFlow Status #"
	    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 Passwd: "

	    stty echo
	    echo
	    #------------------------------------------------------------------#
	    #  Trap:  Reset CNTL-C CNTL-D CNTL-\ After Password Protection     #
	    #------------------------------------------------------------------#
	    trap        2
	    trap        3
	    clear
	else
	    PASSWD=$1
	    clear
	fi


#------------------------------------------------------------------------------#
#  Initialize                                                                  #
#------------------------------------------------------------------------------#
	SPOOLNM=/tmp/whatwfstatus_$$.txt

#------------------------------------------------------------------------------#
#  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	pagesize        9000
	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 ${SPOOLNM}
	COLUMN  datevalue       NOPRINT NEW_VALUE       DATEVAR
	COLUMN  timevalue       NOPRINT NEW_VALUE       TIMEVAR

        TTITLE  CENTER  '${ORASID} (${HNAME}) WF_ITEMs Status '         -
                LEFT    DATEVAR                                         -
                RIGHT   'Page:'    FORMAT 999 SQL.pno           skip 1  -
		CENTER  'WF_Items (PERM/TEMP) That Might Be Purgeable'  -
                LEFT    TIMEVAR                                 skip 2


	SELECT	TO_CHAR(sysdate, 'DD-MON-YY')                   datevalue,
                TO_CHAR(sysdate, 'HH24:MI:SS')                  timevalue,
		WFI.item_type ITEM_TYPE,
		WFT.persistence_type P_TYPE,
		decode (WFI.end_date, NULL, 'OPEN', 'CLOSED') Status,
		count(*) COUNT
	FROM	wf_items WFI,
		wf_item_types WFT
	WHERE	WFT.name = WFI.item_type
	GROUP BY item_type,
	WFT.persistence_type,
	       WFT.PERSISTENCE_DAYS,
	         decode (WFI.end_date, NULL, 'OPEN', 'CLOSED')
	ORDER BY decode (WFI.end_date, NULL, 'OPEN', 'CLOSED'), 4 desc;

EXIT;
END_FILE

print
print  "Please see  /tmp/whatwfstatus_$$.txt"
print
}

