#!/usr/bin/ksh
#whatwfstatus_detail ()
#------------------------------------------------------------------------------#
#    Module Name:  whatwfstatus_detail                                         #
#                                                                              #
#    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_detail:       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_detail_$$.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

	COLUMN	AllRows		FORMAT 999999999 HEADING "WorkFlow|Rows"
	COLUMN	Purgeable	FORMAT 999999999 HEADING "Purgeable|Rows"
	COLUMN	Item_Type	FORMAT A20	 HEADING "Workflow|Type"
	COLUMN	Display_Name	FORMAT A34	 HEADING "Workflow Display Name"

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

	SELECT	TO_CHAR(sysdate, 'DD-MON-YY')                   datevalue,
                TO_CHAR(sysdate, 'HH24:MI:SS')                  timevalue,
		count (*) AllRows,
		WF_PURGE.getpurgeablecount (WFI.ITEM_TYPE) PurgeableRows,
		WFI.item_type,
		WFT.display_name
	FROM	WF_ITEMS WFI,
	 	WF_ITEM_TYPES_VL WFT
	WHERE WFI.item_type = WFT.name
	GROUP BY WFI.item_type, WFT.display_name;

EXIT;
END_FILE

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