create or replace package totals is
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE login;
-- -------------------------------------------------------------------------------------
-- Procedure: Exit Application
-- Author: Brian Griffin
-- Created: March 1, 2007
-- Purpose: To exit the application
-- Source: Taken from app.logout at HRDW@PROD8
-- -------------------------------------------------------------------------------------
procedure exit_application;
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE authenticate/*(t_username IN varchar2)*/;
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE auth(ticket IN VARCHAR2 DEFAULT NULL);
-- -------------------------------------------------------------------------------------
-- Procedure: Get a field's friendly name
-- Purpose: To return a given field's user-friendly name
-- Programmer: Brian G
-- Date: Feb 17, 2007
-- Parameters: p_FieldName - The table's field name
-- Note: The table alias j must be in lower case when you formulate the query expression
-- -------------------------------------------------------------------------------------
FUNCTION get_FriendlyFieldName(p_FieldName IN VARCHAR2, p_FormatFor IN VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;
-- -------------------------------------------------------------------------------------
-- Procedure: Get a field's original name from the friendly name
-- Purpose: To return a given field's table column name from the user-friendly name
-- Programmer: Brian G
-- Date: Feb 17, 2007
-- Parameters: p_FieldName - The table's field name
-- -------------------------------------------------------------------------------------
FUNCTION get_TableFieldName(p_FieldName IN VARCHAR2) RETURN VARCHAR2 ;
-- -------------------------------------------------------------------------------------
-- Procedure: Get PO Header Info
-- Purpose: To retrieve the PO header information
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_POHeaderInfo(p_po_id IN VARCHAR2 DEFAULT 'x') ;
-- -------------------------------------------------------------------------------------
-- Procedure: Get SIS Info
-- Purpose: To retrieve the SIS information
-- Programmer: Brian G
-- Date: April 27, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_SISInfo(p_journal_id IN VARCHAR2 DEFAULT 'x',
p_sis_id IN VARCHAR2 DEFAULT 'x') ;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Crosstab Info
-- Purpose: To retrieve information from the JOURNAL table for a certain cell in
-- the crosstab
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_CrosstabInfo(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_WhereClause IN VARCHAR2 DEFAULT '') ;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Journal Header Info
-- Purpose: To retrieve the journal header information
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_JournalHeaderInfo(p_journal_id IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get PAN Journal Header Info
-- Purpose: To retrieve the PAN journal header information
-- Programmer: Brian G
-- Date: Feb 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_PANJournalInfo(p_journal_id IN VARCHAR2 DEFAULT 'x',
p_journal_line IN NUMBER DEFAULT 0);
-- -------------------------------------------------------------------------------------
-- Procedure: Get Vendor Info
-- Purpose: To retrieve the Vendor information
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_VendorInfo(p_vendor_id IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get Voucher Header Info
-- Purpose: To retrieve the voucher header information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_VoucherHeaderInfo(p_voucher_id IN VARCHAR2 DEFAULT 'x') ;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Paid Vouchers Info
-- Purpose: To retrieve the paid vouchers information
-- Programmer: Brian G
-- Date: Feb 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_PaidVoucherInfo(p_payment_id IN VARCHAR2 DEFAULT 'x', p_voucher_id IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get Account Info
-- Purpose: To retrieve the account's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_AccountInfo(p_account IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get Activity Info
-- Purpose: To retrieve the activity's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_ActivityInfo(p_activity IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get Fund Info
-- Purpose: To retrieve the fund's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_FundInfo(p_fund IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get Function Info
-- Purpose: To retrieve the function's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_FunctionInfo(p_func IN VARCHAR2 DEFAULT 'x');
-- -------------------------------------------------------------------------------------
-- Procedure: Get Cost Center Info
-- Purpose: To retrieve the cost center's information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_CostCenterInfo(p_code IN VARCHAR2 DEFAULT 'x') ;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Drilldown Info
-- Purpose: To retrieve the drilldown information for given summary line
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- Parameter:
-- p_drilldown_id - The WHERE clause
--
-- Example of p_drilldown_id:
-- j.FISCAL_YEAR= '2008' AND j.ACCOUNT= '119501' AND LPAD(j.ACCOUNTING_PERIOD,3,'0')= '007' AND j.DEPTID= 'A01372' AND j.PROGRAM_CODE= 'ZZ' AND j.FUND_CODE= 'ZZZZZ' AND j.LEDGER= 'ACTUALS' AND j.SOURCE= 'JRV' AND
-- This parameter was generated in a loop and thus has a trailing AND statement,
-- hence the 1=1, as opposed to trimming it off.
-- -------------------------------------------------------------------------------------
PROCEDURE get_DrilldownInfo(p_drilldown_id IN VARCHAR2 DEFAULT '1=1');
-- -------------------------------------------------------------------------------------
-- Procedure: Preferences
-- -------------------------------------------------------------------------------------
PROCEDURE preferences(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL);
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE execute_query(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_action IN varchar2 DEFAULT NULL,
p_clause IN varchar2 default null,
p_dd_query IN LONG default NULL);
-- -------------------------------------------------------------------------------------
-- Procedure: Execute Query into a CLOB
-- Programmer: Brian Griffin
-- Description: Given that the user has made their selections, run their query
--
-- Modifications:
-- Programmer: Brian Griffin
-- Date: Jan, 2008
-- Purpose: Use a CLOB
--
-- -------------------------------------------------------------------------------------
PROCEDURE exec_query_clob(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_action IN varchar2 DEFAULT NULL,
p_clause IN varchar2 default null,
p_dd_query IN LONG default NULL) ;
-- -------------------------------------------------------------------------------------
-- Procedure: execute_crosstab
-- Programmer: Brian Griffin
-- Create On: March 13, 2007
-- Purpose: To run a crosstab query in Oracle and display the results on a webpage
-- -------------------------------------------------------------------------------------
PROCEDURE execute_crosstab(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_RunCrosstab IN VARCHAR2 DEFAULT 'FALSE',
p_crosstab_xaxis IN VARCHAR2 DEFAULT 'x',
p_crosstab_yaxis IN VARCHAR2 DEFAULT 'y',
p_Btn_Submit IN VARCHAR2 DEFAULT NULL,
p_Btn_FlipAxis IN VARCHAR2 DEFAULT NULL,
p_Btn_ExportExcel IN VARCHAR2 DEFAULT NULL);
-- -------------------------------------------------------------------------------------
-- Procedure: execute_report
-- Programmer: Brian Griffin
-- Create On: August 13, 2007
-- Purpose: To run a report from the Report tab
-- -------------------------------------------------------------------------------------
/* PROCEDURE execute_report(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_FiscalYear IN VARCHAR2 DEFAULT NULL,
p_AccountingPeriod IN VARCHAR2 DEFAULT NULL,
p_OrgCode IN VARCHAR2 DEFAULT NULL,
p_Function IN VARCHAR2 DEFAULT NULL,
p_FundCode IN VARCHAR2 DEFAULT NULL,
p_SubCode IN VARCHAR2 DEFAULT NULL) ;
*/
PROCEDURE execute_report(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_Report_Name IN totals_settings.session_id%TYPE DEFAULT NULL,
p_SISDetail_Options IN owa_util.vc_arr,
p_RunControlID IN totals_settings.session_id%TYPE DEFAULT NULL);
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE settings(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL);
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE redirect( p_link IN varchar2,
p_session_id IN totals_settings.session_id%TYPE);
end totals;
/
create or replace package body totals AS
-- -------------------------------------------------------------------------------------
-- Procedure: login
-- -------------------------------------------------------------------------------------
PROCEDURE login IS
BEGIN
-- Get the
SELECT l.url
INTO declarations.gv_link
FROM ucrfs_link l
WHERE TYPE = 'iviews';
-- htp.p('');
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.title('Welcome to UCRFStotals');
htp.p('');
-- WAS: htp.meta(chttp_equiv => 'refresh',cname => 'Redirect to iViews',ccontent => '0; URL='||declarations.gv_link);
htp.meta(chttp_equiv => 'refresh',
cname => 'Redirect to Login ',
ccontent => '0; URL='||declarations.gk_APPLICATION_URL);
htp.headClose;
htp.bodyOpen;
/*
htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.comment('END table for UCRFStotals title graphic');
--htp.p('
This page is deprecated. Please use CAS/EACS to access this application.
');
htp.tableData(cvalue => '');
htp.tableData(cvalue => '');
htp.formClose;
htp.p('');
htp.tableClose;
*/
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_SQLERRM => SQLERRM, p_CalledFrom => 'login.login');
RETURN;
END login;
-- -------------------------------------------------------------------------------------
-- Procedure: Exit Application
-- Author: Brian Griffin
-- Created: March 1, 2007
-- Purpose: To exit the application
-- Source: Taken from app.logout at HRDW@PROD8
-- -------------------------------------------------------------------------------------
procedure exit_application IS
BEGIN
-- set logout_time
--update totals_settings
--set logout_time = sysdate
--where session_id = p_session_id;
--commit;
-- delete cookie
--owa_util.mime_header('text/html', false);
--owa_cookie.remove('hrdw_id', g_session_id);
--owa_util.http_header_close();
-- self close
--owa_util.redirect_url(hrdw.g_app_login_page, true);
htp.p(declarations.gk_DOCTYPE);
htp.p('
Now Exiting UCRFStotals
Internet Explorer users: Please click "Yes" to close this window and exit UCRFStotals...
Firefox users: Please close this window manually to exit UCRFStotals...
');
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_SQLERRM => SQLERRM, p_CalledFrom => 'login.exit_application');
RETURN;
end exit_application;
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE authenticate/*(t_username IN varchar2)*/ IS
/*
Verifies current user is authorized
if authorized, creates session_id and inserts
record in totals_settings table
*/
/*v_session_id_date date;
v_session_id totals_settings.session_id%TYPE;
v_seq varchar2(4);
fiscal_year number;
v_setting number;
CURSOR c_usr IS
--Check to see if this user has stored preferences
SELECT * FROM totals_user_prefs WHERE user_id = t_username;
r_usr_row totals_user_prefs%ROWTYPE;*/
BEGIN
htp.p(declarations.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - Authenticating');
htp.p('');
htp.headClose;
htp.bodyOpen;
/*
htp.formOpen(curl => 'totals_tabs.query',cmethod => 'POST');
htp.formHidden(cname => 'p_session_id');
htp.formHidden(cname => 'p_already_open',cvalue => 'FALSE');
htp.formClose;
--session_id uses a portion of the current date
SELECT SYSDATE INTO v_session_id_date FROM DUAL;
--get a four-digit number to append the date to create a session_id
SELECT TO_CHAR(SESSION_SEQ.NEXTVAL) INTO v_seq FROM DUAL;
v_session_id := TO_CHAR(v_session_id_date, 'DMMDDYYHHmiSS') || v_seq;
BEGIN
--see if user has authorization to use this application
SELECT setting_value INTO v_setting FROM eacs_user_info WHERE username = UPPER(t_username);
EXCEPTION WHEN NO_DATA_FOUND THEN
v_setting := 0;
htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.comment('END table for UCRFStotals title graphic');
htp.p('You are not authorized to access this application. ');
htp.anchor(curl => 'http://oasdev.ucr.edu/rptdb/owa/ucrfs.login',ctext => 'Return to Login page');
END;
IF v_setting = 1 THEN
--if authorized, insert sessio in totals_settings table
INSERT INTO totals_settings
(session_id, login_time, user_id)
VALUES
(v_session_id, SYSDATE, t_username);
\*
if there is not already an entry in the user_prefs table insert one
*\
OPEN c_usr;
FETCH c_usr INTO r_usr_row;
IF c_usr%NOTFOUND THEN
INSERT INTO totals_user_prefs (user_id) VALUES (t_username);
COMMIT;
FETCH c_usr INTO r_usr_row;
END IF;
CLOSE c_usr;
--set the fiscal year
fiscal_year := TO_NUMBER(TO_CHAR(sysdate,'YYYY'));
IF TO_DATE(TO_CHAR(sysdate,'MONTH'),'MONTH') >= TO_DATE('JULY','MONTH') THEN
fiscal_year := fiscal_year +1;
END IF;
UPDATE totals_settings
SET fiscal_years = fiscal_year
WHERE session_id = v_session_id;
COMMIT;
htp.p('
');
END IF;
*/
SELECT l.url INTO declarations.gv_link FROM ucrfs_link l WHERE l.TYPE = 'ucrfstotals';
htp.p('
This page is deprecated. Please use ' || htf.anchor(curl => declarations.gv_link,ctext => 'CASified UCRFStotals.') || '
');
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_SQLERRM => SQLERRM, p_CalledFrom => 'totals.authenticate');
RETURN;
END authenticate;
-- -------------------------------------------------------------------------------------
-- Procedure: Auth
-- Purpose: To check the existence of the ticket and if none, require the user to log in
-- via CAS / authenticate their privileges via EACS
-- -------------------------------------------------------------------------------------
PROCEDURE auth(ticket IN VARCHAR2 DEFAULT NULL) IS
v_results varchar2(50);
v_valid VARCHAR2(3);
v_userid totals_settings.user_id%TYPE;
v_session_id_date date;
--v_Previous_Login date;
v_session_id totals_settings.session_id%TYPE;
v_seq varchar2(4);
fiscal_year number;
v_setting number;
nCount NUMBER;
-- for the Emergency Notification System (ENS)
v_Error varchar2(200);
--Check to see if this user has stored preferences
CURSOR c_usr IS
SELECT *
FROM totals_user_prefs
WHERE user_id = v_userid;
r_usr_row totals_user_prefs%ROWTYPE;
BEGIN
htp.p(declarations.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - Authenticating');
htp.p('');
htp.headClose;
htp.bodyOpen(cattributes => 'topmargin=0 leftmargin=0 onLoad="getBrowserType();" ');
htp.formOpen(curl => 'totals_tabs.query',cmethod => 'POST');
htp.formHidden(cname => 'p_session_id');
htp.formHidden(cname => 'p_already_open',cvalue => 'FALSE');
htp.formClose;
-- Get the URL, such as http://hug.ucr.edu/totals_dev/
SELECT l.url
INTO declarations.gv_link
FROM totals_link l
WHERE l.TYPE = 'totals2';
IF ticket IS NULL THEN
--owa_util.redirect_url('https://auth.ucr.edu/cas/login?service='|| 'http://oasdev.ucr.edu/rptdb/owa/' ||'ucrfs.auth',FALSE);
htp.script(clanguage => 'javascript',cscript => 'window.location.href="https://auth.ucr.edu/cas/login?service='|| declarations.gv_link || 'totals.auth"');
htp.p('Ticket was empty');
htp.bodyClose;
htp.htmlClose;
-- RETURN;
END IF;
--htp.p(ticket);
--RETURN;
-- Take the ticket and check to see if there is an associated user id
BEGIN
SELECT sso_validation_ticket@sso_auth(REPLACE(declarations.gv_link || 'totals.auth', ':', '%3a'), ticket)
INTO v_results
FROM dual;
EXCEPTION
WHEN OTHERS THEN
htp.p('SQL Error: ' || SQLERRM);
END;
v_valid := upper(substr(v_results,1,3));
--v_valid := 'YES';
IF v_valid <> 'YES' THEN
-- Web Page HEAD
--htp.p('');
--htp.htmlOpen;
--htp.headOpen;
-- Set the webpage title
--htp.title(ctitle => 'UCRFStotals - Error Logging Into UCRFStotals');
--htp.bodyOpen();
totals_util.get_TitleImages;
htp.htitle(ctitle => 'Error!', nsize => 2);
htp.p('There was a problem logging you into this application (the response code was, ' || v_results || '). Please be patient while we resolve this situation. ') ;
htp.bodyClose;
htp.htmlClose;
RETURN;
END IF;
v_userid := (upper(substr(v_results,5, length(v_results)- 5)));
-- IF is_active_employee@fsacct(v_userid) = 0 THEN -- 0 -invalid;1-valid
/* IF is_active_employee@acctuser(v_userid) = 0 THEN -- 0 -invalid;1-valid
-- Web Page HEAD
htp.p('');
htp.htmlOpen;
htp.headOpen;
-- Set the webpage title
htp.title(ctitle => 'UCRFStotals - Error Logging Into UCRFStotals');
htp.bodyOpen();
totals_util.get_TitleImages;
htp.para;
htp.p('
The user, ' || v_userid || ', has been inactivated. If this is an error, please see your department adminstrator.
');
htp.p('Technical information: '); htp.br;
htp.p(' declarations.gv_link: ' || declarations.gv_link);htp.br;
htp.p(' v_valid: ' || v_valid);htp.br;
htp.p(' v_results: ' || v_results);htp.br;
htp.bodyClose;
htp.htmlClose;
RETURN;
END IF;
*/
--see if user has authorization to use this application
-- This has a hard-coded APP_ID of 49
BEGIN
SELECT COUNT(*)
INTO nCount
FROM eacs_user_info
WHERE username = UPPER(v_userid);
EXCEPTION
WHEN OTHERS THEN
nCount := 0;
END;
IF nCount > 0 THEN
v_setting := 1;
ELSE
v_setting := 0;
totals_util.get_TitleImages;
/* htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.comment('END table for UCRFStotals title graphic');
*/ htp.p('You are not authorized to access UCRFStotals. Please contact your departmental SAA to set you up in EACS. ');
htp.anchor(curl => declarations.gv_link || 'totals.login',ctext => 'Return to Login page');
htp.bodyClose;
htp.htmlClose;
RETURN;
END IF;
-- If the user has EACS access...
IF v_setting = 1 THEN
-- If the user already has an old login entry, then delete it
/* select t.Login_Time
INTO v_Previous_Login
from totals_settings t
WHERE t.User_Id = UPPER(v_userid)
AND t.login_time - SYSDATE > 1
;
*/
-- Ensure that the user has opted in/out of the Emergency Notification System
IF CheckIsActiveEmployee@acctuser(v_userid, v_Error) < 1 THEN
-- they're not active
htp.p(v_Error);
RETURN;
END IF ;
--session_id uses a portion of the current date
SELECT SYSDATE
INTO v_session_id_date
FROM DUAL;
--get a four-digit number to append the date to create a session_id
SELECT TO_CHAR(SESSION_SEQ.NEXTVAL)
INTO v_seq
FROM DUAL;
v_session_id := TO_CHAR(v_session_id_date, 'DMMDDYYHHmiSS') || v_seq;
--if authorized, insert sessiom in totals_settings table
INSERT INTO totals_settings(session_id, login_time, user_id)
VALUES (v_session_id, SYSDATE, v_userid);
/*
if there is not already an entry in the user_prefs table insert one
*/
OPEN c_usr;
FETCH c_usr INTO r_usr_row;
IF c_usr%NOTFOUND THEN
INSERT INTO totals_user_prefs (user_id, func_pref, selection_mode, mark_restricted_approp_funds, mark_unrestricted_approp_funds)
VALUES (v_userid, 'F', 'E', 'N', 'N');
COMMIT;
FETCH c_usr INTO r_usr_row;
ELSE
UPDATE totals_user_prefs p
SET p.func_pref = 'F',
p.selection_mode = 'E',
p.mark_restricted_approp_funds = 'N',
p.mark_unrestricted_approp_funds = 'N'
WHERE p.user_id = v_userid;
COMMIT;
FETCH c_usr INTO r_usr_row;
END IF;
CLOSE c_usr;
--set the fiscal year
fiscal_year := TO_NUMBER(TO_CHAR(sysdate,'YYYY'));
IF TO_DATE(TO_CHAR(sysdate,'MONTH'),'MONTH') >= TO_DATE('JULY','MONTH') THEN
fiscal_year := fiscal_year +1;
-- BG : temporary override on the fiscal year
--fiscal_year := 2014; Commented back out per Bobbi's request (juan 20140709)
END IF;
-- Update the fiscal year and set the default fields to fiscal year and accounting period
UPDATE totals_settings
SET fiscal_years = fiscal_year,
-- standard_tab_fields = 'j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, TO_CHAR(j.FOREIGN_AMOUNT,''9999999999D99'','' NLS_NUMERIC_CHARACTERS = ''''.,'''' NLS_CURRENCY = ''''$''''''), '
standard_tab_fields = 'j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, ' || declarations.gk_FOREIGN_AMOUNT
WHERE session_id = v_session_id;
COMMIT;
htp.p('
');
END IF;
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_SQLERRM => SQLCODE || ' ' || SQLERRM, p_CalledFrom => 'totals.auth');
RETURN;
END auth;
-- -------------------------------------------------------------------------------------
-- Function: Get cookie information
-- -------------------------------------------------------------------------------------
FUNCTION get_cookie(v_cookie_name IN VARCHAR2) RETURN VARCHAR2 IS
v_cookie_val owa_cookie.cookie;
BEGIN
v_cookie_val := owa_cookie.get(v_cookie_name);
IF v_cookie_val.num_vals > 0 THEN
RETURN (v_cookie_val.vals(1));
ELSE
RETURN ('zero');
END IF;
END get_cookie;
-- -------------------------------------------------------------------------------------
-- Procedure: Set cookie information
-- -------------------------------------------------------------------------------------
PROCEDURE set_cookie(v_cookie_name IN VARCHAR2, v_cookie_val IN VARCHAR2) IS
BEGIN
owa_util.mime_header('text/html', FALSE);
owa_cookie.send(v_cookie_name, v_cookie_val);
END set_cookie;
-- -------------------------------------------------------------------------------------
-- Procedure: Get a field's friendly name
-- Purpose: To return a given field's user-friendly name
-- Programmer: Brian G
-- Date: Feb 17, 2007
-- Parameters: p_FieldName - The table's field name
-- Note: The table alias j must be in lower case when you formulate the query expression
-- -------------------------------------------------------------------------------------
FUNCTION get_FriendlyFieldName(p_FieldName IN VARCHAR2, p_FormatFor IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2 IS
BEGIN
-- Some of the look up fields break the rule due to fancy formatting
IF instr(upper(p_FieldName),'DESCR254,') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Description';
elsIF instr(upper(p_FieldName), 'ACCOUNTING_PERIOD') <> 0 THEN
IF p_FormatFor = 'excel' THEN
DECLARATIONS.gv_user_friendly := 'Per';
ELSE
DECLARATIONS.gv_user_friendly := 'Accounting Period';
END if;
elsIF instr(upper(p_FieldName), 'PERM') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'PERM Amount';
elsIF instr(upper(p_FieldName), 'TEMP') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'TEMP Amount';
elsIF instr(upper(p_FieldName), 'ACTUALS') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'ACTUAL Amount';
elsIF instr(upper(p_FieldName), 'FOREIGN_AMOUNT') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Amount';
elsIF instr(upper(p_FieldName), 'STATISTIC_AMOUNT') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Total FTE';
-- Journal Date
elsIF instr(upper(p_FieldName), 'JOURNAL_DATE') <> 0 THEN
IF p_FormatFor = 'excel' THEN
DECLARATIONS.gv_user_friendly := 'Date';
ELSE
DECLARATIONS.gv_user_friendly := 'Journal Date';
END if;
elsIF instr(upper(p_FieldName), 'TERM_YEAR') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Term Year';
elsIF instr(upper(p_FieldName), 'TRANSACTION_AMT') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Trans Amt';
elsIF instr(upper(p_FieldName), 'PAID_DATE') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Paid Date';
elsIF instr(upper(p_FieldName), 'PAID_AMT') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Paid Amt';
elsIF instr(upper(p_FieldName), 'BILL_DATE') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Bill Date';
elsIF instr(upper(p_FieldName), 'RECEIPT_NUM') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Receipt';
elsIF instr(upper(p_FieldName), 'EXT_IND') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Ext Ind';
elsIF instr(upper(p_FieldName), 'CHARGE_PAYMENT') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Type';
elsIF instr(upper(p_FieldName), 'SUBCODE_DESCR') <> 0 THEN
DECLARATIONS.gv_user_friendly := 'Subcode Descr';
ELSE
-- Try to match the parameter p_FieldName with an entry in the table,
BEGIN
SELECT
CASE trim(lower(p_FormatFor)) WHEN 'excel' THEN nvl(trim(replace(fl.excel_friendly, ',')), p_FieldName)
ELSE nvl(trim(replace(fl.user_friendly, ',')), p_FieldName)
END
INTO DECLARATIONS.gv_user_friendly
FROM totals_field_lookup fl
WHERE fl.table_field = TRIM(upper(replace(replace(p_FieldName, 'j.'), ',')))
OR fl.table_field = TRIM(upper(replace(replace(p_FieldName, 's.'), ',')))
OR fl.table_field = TRIM(upper(replace(replace(p_FieldName, 'sj.'), ',')));
EXCEPTION
WHEN OTHERS THEN
-- If no data was found then return the parameter at least
DECLARATIONS.gv_user_friendly := p_FieldName;
END;
END IF;
RETURN DECLARATIONS.gv_user_friendly;
END; --get_FriendlyFieldName
-- -------------------------------------------------------------------------------------
-- Procedure: Get a field's original name from the friendly name
-- Purpose: To return a given field's table column name from the user-friendly name
-- Programmer: Brian G
-- Date: Feb 17, 2007
-- Parameters: p_FieldName - The table's field name
-- -------------------------------------------------------------------------------------
FUNCTION get_TableFieldName(p_FieldName IN VARCHAR2) RETURN VARCHAR2 IS
v_table_field totals_field_lookup.table_field%TYPE DEFAULT '';
BEGIN
-- Get the original field name from the friendly name
SELECT fl.table_field
INTO v_table_field
FROM totals_field_lookup fl
WHERE upper(trim(fl.user_friendly)) = upper(TRIM(p_FieldName)) || ',';
RETURN v_table_field;
END; --get_TableFieldName
-- -------------------------------------------------------------------------------------
-- Procedure: Get Voucher Header Info
-- Purpose: To retrieve the voucher header information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_VoucherHeaderInfo(p_voucher_id IN VARCHAR2 DEFAULT 'x') IS
TYPE t_voucher_tbl IS REF CURSOR;
cv_voucher_tbl t_voucher_tbl;
rec_voucher_tbl voucher_tbl%ROWTYPE;
v_SQL VARCHAR2(2000);
BEGIN
v_SQL := 'SELECT DISTINCT * FROM VOUCHER_TBL V WHERE V.VAL_BUSINESS_UNIT = ''UCR'' AND V.VAL_VOUCHER_ID = :1';
OPEN cv_voucher_tbl FOR v_SQL USING p_voucher_id;
htp.p(htf.bold('Voucher Header Information'));
-- Should only be one row of data
FETCH cv_voucher_tbl INTO rec_voucher_tbl;
IF trim(rec_voucher_tbl.val_voucher_id) IS NOT NULL THEN
htp.br;
htp.p('Voucher: ' || rec_voucher_tbl.val_voucher_id);
htp.br;
htp.p('Invoice: ' || nvl(trim(rec_voucher_tbl.v_invoice_id), '(No invoice found)') );
htp.br;
htp.p('Invoice Date: ' || nvl(trim(to_char(rec_voucher_tbl.v_invoice_dt, declarations.gk_FRIENDLY_DATE)), '(No date found)') );
htp.br;
htp.p('Vendor ID: ' || nvl(trim(rec_voucher_tbl.v_vendor_id), '(No vendor found)') );
htp.br;
--htp.p('Operator: ' || nvl(trim(rec_voucher_tbl.v_oprid), '(No operator found)') );
--htp.br;
htp.p('Lines: ' || trim(rec_voucher_tbl.v_vchr_ttl_lines) );
htp.br;
htp.p('Amount: $' || trim(to_char(rec_voucher_tbl.v_merchandise_amt, declarations.gk_MONEYFORMAT)) );
htp.br;
htp.br;
htp.p(htf.img(curl => 'docs/magglass.png', calign => 'left') || htf.italic('Click now to drill down for more information in this voucher...'));
ELSE
htp.br;
htp.p('No data was found for this voucher. The most likely solution is to update the VOUCHER_TBL.');
htp.br;
END IF;
CLOSE cv_voucher_tbl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Paid Vouchers Info
-- Purpose: To retrieve the paid vouchers information
-- Programmer: Brian G
-- Date: Feb 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_PaidVoucherInfo(p_payment_id IN VARCHAR2 DEFAULT 'x', p_voucher_id IN VARCHAR2 DEFAULT 'x') IS
v_TotalAmount NUMBER(13,2) DEFAULT 0.0;
v_Counter INTEGER DEFAULT 1;
CURSOR c_PaidVouchers IS
-- Originally
/* SELECT DISTINCT vp.val_voucher_id, sum(vp.val_foreign_amount) amount
FROM rpt_user.voucher_pymnt_tbl vp
WHERE vp.pat_pymnt_id_ref = p_payment_id
GROUP BY vp.val_voucher_id
ORDER BY vp.val_voucher_id;
*/
SELECT DISTINCT p.voucher_id, sum(p.PAID_AMT_GROSS) amount
FROM PAYMENT_VW p
WHERE p.check_id = p_payment_id
GROUP BY p.voucher_id
ORDER BY p.voucher_id;
BEGIN
htp.p(htf.bold('Paid Vouchers for Check ' || p_payment_id || ': '));
FOR c1rec IN c_PaidVouchers LOOP
--htp.br;
--htp.p('No paid vouchers were found for this check. The most likely solution is to update the VOUCHER_PYMNT_TBL.');
htp.br;
-- If the current voucher being listed matches the one on the page, then flag it with a *.
-- Doing a straight = between the 2 values didn't seem to work
IF instr(trim(p_voucher_id), trim(c1rec.voucher_id)) <> 0 OR instr(trim(c1rec.voucher_id), trim(p_voucher_id)) <> 0 THEN
htp.p('*(' || v_Counter || ') Voucher: ' || c1rec.voucher_id || ' for $' || trim(to_char(c1rec.amount, declarations.gk_MONEYFORMAT)) );
ELSE
htp.p(' (' || v_Counter || ') Voucher: ' || c1rec.voucher_id || ' for $' || trim(to_char(c1rec.amount, declarations.gk_MONEYFORMAT)) );
END IF;
v_TotalAmount := v_TotalAmount + c1rec.amount;
v_Counter := v_Counter + 1;
END LOOP;
v_Counter := v_Counter - 1;
htp.br;
htp.br;
htp.p('Total for ' || v_Counter || ' voucher(s): $' || trim(to_char(v_TotalAmount, declarations.gk_MONEYFORMAT)) );
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Journal Header Info
-- Purpose: To retrieve the journal header information
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_JournalHeaderInfo(p_journal_id IN VARCHAR2 DEFAULT 'x') IS
TYPE t_journal_tbl IS REF CURSOR;
cv_journal_tbl t_journal_tbl;
rec_journal_tbl journal_tbl%ROWTYPE;
v_SQL VARCHAR2(2000);
BEGIN
v_SQL := 'SELECT J.* FROM JOURNAL_TBL J WHERE J.BUSINESS_UNIT = ''UCR'' AND J.JOURNAL_ID = :1';
OPEN cv_journal_tbl FOR v_SQL USING p_journal_id;
htp.p(htf.bold('Journal Header Information'));
-- Should only be one row of data
FETCH cv_journal_tbl INTO rec_journal_tbl;
IF trim(rec_journal_tbl.journal_id) IS NOT NULL THEN
htp.br;
htp.p('Journal: ' || rec_journal_tbl.journal_id);
htp.br;
htp.p('Date: ' || nvl(trim(rec_journal_tbl.journal_date), htf.italic('(No date found)')) );
htp.br;
htp.p('Reference: ' || nvl(trim(rec_journal_tbl.trans_ref_num), htf.italic('(No reference found)')) );
htp.br;
htp.p('Ledger: ' || nvl(trim(rec_journal_tbl.ledger), htf.italic('(No ledger found)')) );
htp.br;
htp.p('Description: ' || nvl(trim(rec_journal_tbl.descr254), htf.italic('(No description found)')) );
htp.br;
htp.p('Posted: ' || trim(rec_journal_tbl.posted_date) );
htp.br;
htp.p('Operator: ' || nvl(trim(rec_journal_tbl.oprid), htf.italic('No operator found')) );
htp.br;
htp.p('Source: ' || nvl(trim(rec_journal_tbl.source), htf.italic('No source found')) );
htp.br;
ELSE
htp.br;
htp.p('No data was found for this journal. The most likely solution is to update the JOURNAL_TBL.');
htp.br;
END IF;
CLOSE cv_journal_tbl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get PAN Journal Line Info
-- Purpose: To retrieve the PAN journal line information
-- Programmer: Brian G
-- Date: Feb 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_PANJournalInfo(p_journal_id IN VARCHAR2 DEFAULT 'x',
p_journal_line IN NUMBER DEFAULT 0) IS
TYPE t_pan_journal_tbl IS REF CURSOR;
cv_pan_journal_tbl t_pan_journal_tbl;
rec_pan_journal_tbl rpt_user.pan_jrnl_ln%ROWTYPE;
v_SQL VARCHAR2(2000);
v_ActivityDescr varchar2(30); -- This didn't seem to work: PS_UCR_ACTV_LV_TBL.ucr_actv%TYPE DEFAULT '';
v_last_first varchar2(30); -- This didn't seem to work: ucr_netid@fsacct.last_first%TYPE DEFAULT '';
v_primary_title varchar2(30); -- This didn't seem to work: ucr_netid@fsacct.primary_title%TYPE DEFAULT '';
v_primary_dept_name varchar2(30); -- This didn't seem to work: ucr_netid@fsacct.primary_dept_name%TYPE DEFAULT '';
v_primary_phone varchar2(30); -- This didn't seem to work: ucr_netid@fsacct.primary_phone%TYPE DEFAULT '';
BEGIN
v_SQL := 'SELECT P.* FROM RPT_USER.PAN_JRNL_LN P WHERE P.BUSINESS_UNIT = ''UCR'' AND P.JOURNAL_ID = :1 AND P.JOURNAL_LINE = :2 ';
OPEN cv_pan_journal_tbl FOR v_SQL USING p_journal_id, p_journal_line;
htp.p(htf.bold('PAN Journal Line Information'));
-- Should only be one row of data
FETCH cv_pan_journal_tbl INTO rec_pan_journal_tbl;
IF trim(rec_pan_journal_tbl.journal_id) IS NOT NULL THEN
htp.br;
htp.p('Journal: ' || rec_pan_journal_tbl.journal_id);
htp.br;
htp.p('Line: ' || nvl(trim(rec_pan_journal_tbl.journal_line), htf.italic('(No line found)')) );
htp.br;
-- Display the description of the PAN review status
IF trim(rec_pan_journal_tbl.pan_review_status) = 'C' THEN
htp.p('Status: Reviewed');
ELSIF trim(rec_pan_journal_tbl.pan_review_status) = 'N' THEN
htp.p('Status: Not Reviewed');
ELSIF trim(rec_pan_journal_tbl.pan_review_status) = 'P' THEN
htp.p('Status: Follow up with further review');
ELSE
htp.italic('No status found');
END IF;
htp.br;
htp.br;
-- Get information on the transactor
BEGIN
SELECT last_first, primary_title, primary_dept_name, primary_phone
INTO v_last_first, v_primary_title, v_primary_dept_name, v_primary_phone
FROM ucr_netid@FSACCT
WHERE upper(trim(net_id)) = upper(trim(rec_pan_journal_tbl.oprid)) ;
htp.p('Transactor: ' || v_last_first || ' (' || trim(rec_pan_journal_tbl.oprid) ||')' );
htp.br;
htp.p(' Phone: ' || v_primary_phone );
htp.br;
htp.p(' Title: ' || v_primary_title );
htp.br;
htp.p(' Department: ' || v_primary_dept_name );
EXCEPTION
WHEN OTHERS THEN
htp.p('Transactor: ' || nvl(trim(rec_pan_journal_tbl.oprid), htf.italic('No transactor found')) );
END;
htp.br;
-- Get information on the reviewer
BEGIN
SELECT last_first, primary_title, primary_dept_name, primary_phone
INTO v_last_first, v_primary_title, v_primary_dept_name, v_primary_phone
FROM ucr_netid@fsacct n
WHERE upper(trim(n.net_id)) = upper(trim(rec_pan_journal_tbl.reviewer)) ;
htp.p('Reviewer: ' || v_last_first || ' (' || trim(rec_pan_journal_tbl.reviewer) ||')' );
htp.br;
htp.p(' Phone: ' || v_primary_phone );
htp.br;
htp.p(' Title: ' || v_primary_title );
htp.br;
htp.p(' Department: ' || v_primary_dept_name );
EXCEPTION
WHEN OTHERS THEN
htp.p('Reviewer: ' || nvl(trim(rec_pan_journal_tbl.reviewer), htf.italic('No reviewer found')) );
END;
htp.br;
htp.br;
-- Get the activity description
BEGIN
SELECT ucr_actv_desc
INTO v_ActivityDescr
FROM PS_UCR_ACTV_LV_TBL a
WHERE a.ucr_actv = trim(rec_pan_journal_tbl.deptid);
EXCEPTION
WHEN OTHERS THEN
v_ActivityDescr := '(No description found)';
END;
htp.p('Activity: ' || nvl(trim(rec_pan_journal_tbl.deptid), '') || ' - ' || v_ActivityDescr );
htp.br;
htp.p('Application Type: ' || nvl(trim(rec_pan_journal_tbl.application_type), htf.italic('(No application type found)')) );
htp.br;
-- Help wrap the long description by inserting a line break
htp.p('Description: ' || nvl(trim(replace(rec_pan_journal_tbl.descr254_mixed, 'marked', ' marked')), htf.italic('(No description found)')) );
htp.br;
htp.p('Reviewed: ' || trim(rec_pan_journal_tbl.review_date) );
htp.br;
--htp.p('Lines: ' || nvl(to_char(rec_journal_tbl.jrnl_total_lines), htf.italic('No total lines found')) );
--htp.br;
--htp.p('Amount: ' || nvl(to_char(rec_journal_tbl.jrnl_total_debits), htf.italic('No total amount found')) );
--htp.br;
htp.br;
htp.p(htf.img(curl => 'docs/magglass.png', calign => 'left') || htf.italic('Click now to drill down for more information in this journal and line...'));
ELSE
htp.br;
htp.p(htf.italic('(This Journal Type does not use PAN)') );
htp.br;
END IF;
CLOSE cv_pan_journal_tbl;
END; -- get_PANJournalInfo()
-- -------------------------------------------------------------------------------------
-- Procedure: Get Vendor Info
-- Purpose: To retrieve the Vendor information
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_VendorInfo(p_vendor_id IN VARCHAR2 DEFAULT 'x') IS
TYPE t_vendor_tbl IS REF CURSOR;
cv_vendor_tbl t_vendor_tbl;
rec_vendor_tbl PS_VENDOR@UCRFS%ROWTYPE;
v_SQL VARCHAR2(2000);
v_vendor_status VARCHAR2(50);
v_vendor_class VARCHAR2(50);
v_vendor_persistence VARCHAR2(50);
-- Further employee information
v_primary_phone ucr_netid.primary_phone@fsacct%TYPE;
v_primary_title ucr_netid.primary_title@fsacct%TYPE;
v_primary_dept_name ucr_netid.primary_dept_name@fsacct%TYPE;
BEGIN
v_SQL := 'SELECT * FROM PS_VENDOR@UCRFS V WHERE V.SETID = ''UCR'' AND V.VENDOR_ID = :1';
OPEN cv_vendor_tbl FOR v_SQL USING p_vendor_id;
htp.p(htf.bold('Vendor Information'));
-- Should only be one row of data
FETCH cv_vendor_tbl INTO rec_vendor_tbl;
IF trim(rec_vendor_tbl.vendor_id) IS NOT NULL THEN
htp.br;
htp.p('Vendor: ' || rec_vendor_tbl.vendor_id);
htp.br;
htp.p('Name: ' || rec_vendor_tbl.name1);
htp.br;
-- Vendor's status
IF rec_vendor_tbl.vendor_status = 'A' THEN
v_vendor_status := 'Approved';
ELSIF rec_vendor_tbl.vendor_status = 'E' THEN
v_vendor_status := 'Unapproved';
ELSIF rec_vendor_tbl.vendor_status = 'I' THEN
v_vendor_status := 'Inactive';
ELSIF rec_vendor_tbl.vendor_persistence = 'X' THEN
v_vendor_status := 'To archive';
ELSE
v_vendor_status := ' (Unknown) ';
END IF;
--htp.p('Status: ' || v_vendor_status || ' (' || rec_vendor_tbl.vendor_status || ')');
--htp.br;
-- Vendor's class
IF rec_vendor_tbl.vendor_class = 'A' THEN
v_vendor_class := 'Attorney';
ELSIF rec_vendor_tbl.vendor_class = 'E' THEN
v_vendor_class := 'Employee';
ELSIF rec_vendor_tbl.vendor_class = 'H' THEN
v_vendor_class := 'HRMS';
ELSIF rec_vendor_tbl.vendor_class = 'R' THEN
v_vendor_class := 'Supplier';
ELSE
v_vendor_class := ' (Unknown) ';
END IF;
--htp.p('Class: ' || v_vendor_class || ' (' || rec_vendor_tbl.vendor_class || ')');
--htp.br;
-- Vendor's persistence
IF rec_vendor_tbl.vendor_persistence = 'O' THEN
v_vendor_persistence := 'One Time';
ELSIF rec_vendor_tbl.vendor_persistence = 'P' THEN
v_vendor_persistence := 'Permanent';
ELSIF rec_vendor_tbl.vendor_persistence = 'R' THEN
v_vendor_persistence := 'Regular';
ELSIF rec_vendor_tbl.vendor_persistence = 'S' THEN
v_vendor_persistence := 'Single Pay Vendor';
ELSE
v_vendor_persistence := ' (Unknown) ';
END IF;
--htp.p('Persistence: ' || v_vendor_persistence || ' (' || rec_vendor_tbl.vendor_persistence || ')');
--htp.br;
htp.p(v_vendor_status || ' ' || v_vendor_persistence || ' ' || v_vendor_class );
htp.br;
-- For employee's get their phone number and department
IF rec_vendor_tbl.vendor_class = 'E' THEN
BEGIN
SELECT primary_phone, primary_title, primary_dept_name
INTO v_primary_phone, v_primary_title, v_primary_dept_name
-- FROM ucr_netid@fsacct_PROD
FROM ucr_netid@fsacct
WHERE emp_id = replace(rec_vendor_tbl.vendor_id, 'E', '');
htp.p('Phone: ' || v_primary_phone );
htp.br;
htp.p('Title: ' || v_primary_title );
htp.br;
htp.p('Department: ' || v_primary_dept_name );
htp.br;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END IF;
htp.br;
--htp.p(htf.italic('Click now to drill down for more information in this journal...'));
ELSE
htp.br;
htp.p('No data was found for this vendor. The most likely solution is to review the PS_VENDOR_TBL.');
htp.br;
END IF;
CLOSE cv_vendor_tbl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get PO Header Info
-- Purpose: To retrieve the PO header information
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_POHeaderInfo(p_po_id IN VARCHAR2 DEFAULT 'x') IS
v_PO_Type VARCHAR2(10) := '';
-- PO Type legend, 9 different types
v_POTypes_eBuy CONSTANT VARCHAR2(6) := 'xCDPQR'; --eBuy: C, D, P, Q, R, x means none was found
v_POTypes_POLite CONSTANT VARCHAR2(3) := 'BLO'; --POLite: B, L, O
v_POTypes_SubPO CONSTANT VARCHAR2(1) := 'S'; --SubPO: S
TYPE t_pohdr_tbl IS REF CURSOR;
cv_pohdr_tbl t_pohdr_tbl;
rec_pohdr_ebuy_tbl po_header@ebuy%ROWTYPE;
rec_pohdr_subpo_tbl subpo@subpo%ROWTYPE;
rec_pohdr_polite_tbl po_info@polite%ROWTYPE;
v_SQL VARCHAR2(2000);
BEGIN
-- Get the PO Type to determine from which table we can SELECT FROM
BEGIN
-- Originally this SQL was used, but if an old PO is changed then a new PO in eBuy is created yielding
-- the error: ORA-01422: exact fetch returns more than requested number of rows
--SELECT DISTINCT TRIM(po_type)
--INTO v_PO_Type
--FROM warehouse_header@ebuy_prod t
--WHERE TRIM(t.po_number) = TRIM(p_PO_ID) ;
-- So this SQL is used to select the maximum dated PO
SELECT DISTINCT TRIM(po_type)
INTO v_PO_Type
FROM warehouse_header@ebuy t
WHERE t.primary_key =
(SELECT wd.primary_key
FROM warehouse_dates@ebuy wd, warehouse_header@ebuy wh
WHERE wh.primary_key = wd.primary_key
AND wh.po_number = p_po_id
AND
wd.change_date =
(SELECT MAX(change_date)
FROM warehouse_dates@ebuy wd2, warehouse_header@ebuy wh2
WHERE wh2.primary_key = wd2.primary_key
AND wh2.po_number = p_po_id));
EXCEPTION
WHEN no_data_found THEN
v_PO_Type := 'x'; -- assume an eBuy PO
END;
htp.p(htf.bold('PO Header Information'));
-- Is this an eBuy PO?
IF INSTR(v_POTypes_eBuy, v_PO_Type) <> 0 THEN
v_SQL := 'SELECT * FROM po_header@ebuy poh WHERE trim(poh.po_number) = trim(:1)' ;
OPEN cv_pohdr_tbl FOR v_SQL USING p_po_id;
FETCH cv_pohdr_tbl INTO rec_pohdr_ebuy_tbl;
IF trim(rec_pohdr_ebuy_tbl.po_number) IS NOT NULL THEN
htp.br;
htp.p('PO ID: ' || rec_pohdr_ebuy_tbl.po_number || ' (from eBuy)' );
htp.br;
htp.p('Description: ' || nvl(trim(rec_pohdr_ebuy_tbl.descr), htf.italic('(No description found)')) );
htp.br;
htp.p('Vendor: ' || trim(rec_pohdr_ebuy_tbl.vendor_code) || ' - ' || trim(rec_pohdr_ebuy_tbl.vendor_name) );
htp.br;
htp.p('User Contact: ' || trim(rec_pohdr_ebuy_tbl.user_contact) || ' @ ' || trim(rec_pohdr_ebuy_tbl.user_extension) );
htp.br;
htp.p('Payment Total: $' || TRIM(to_char(rec_pohdr_ebuy_tbl.payment_total, declarations.gk_MONEYFORMAT)) );
htp.br;
htp.br;
htp.p(htf.img(curl => 'docs/magglass.png', calign => 'left') || htf.italic('Click now to drill down for more information in this purchase order...'));
ELSE
htp.br;
htp.p('No data was found for this PO. The most likely solution is to update the eBuy datawarehouse.');
htp.br;
END IF;
-- Otherwise, is this a SubPO?
ELSIF INSTR(v_POTypes_SubPO, v_PO_Type) <> 0 THEN
v_SQL := 'SELECT * FROM subpo_nolob_vw@subpo s WHERE trim(S.SUBPO_NUMBER) = trim(:1)';
OPEN cv_pohdr_tbl FOR v_SQL USING p_po_id;
FETCH cv_pohdr_tbl INTO rec_pohdr_subpo_tbl;
--IF trim(rec_pohdr_subpo_tbl.po_number) IS NOT NULL THEN
htp.br;
htp.p('PO ID: ' || p_po_id || ' (from SubPO)' );
htp.br;
htp.p('Description: ' || nvl(trim(rec_pohdr_subpo_tbl.description), htf.italic('(No description found)')) );
htp.br;
htp.p('Vendor: ' || nvl(trim(rec_pohdr_subpo_tbl.vendor_id), htf.italic('(No vendor found)')) );
htp.br;
htp.p('Total: ' || nvl(trim(rec_pohdr_subpo_tbl.total), htf.italic('(No total found)')) );
htp.br;
htp.p('Notes: ' || nvl(trim(rec_pohdr_subpo_tbl.notes), htf.italic('(No notes found)')) );
--ELSE
-- htp.br;
-- htp.p('No data was found for this PO. The most likely solution is to update the Sub PO datawarehouse.');
-- htp.br;
--END IF;
-- If the above fails, then is this a POLite PO?
-- POLite POs have an extraneous leading digit which needs to be removed
ELSIF INSTR(v_POTypes_POLite, v_PO_Type) <> 0 THEN
v_SQL := 'SELECT * FROM po_info@polite p WHERE trim(p.ponumber) = substr(trim(:1), -6)';
OPEN cv_pohdr_tbl FOR v_SQL USING p_po_id;
FETCH cv_pohdr_tbl INTO rec_pohdr_polite_tbl;
IF trim(rec_pohdr_polite_tbl.ponumber) IS NOT NULL THEN
htp.br;
htp.p('PO ID: ' || rec_pohdr_polite_tbl.ponumber || ' (from POLite)' );
htp.br;
htp.p('Delivery Location: ' || nvl(trim(rec_pohdr_polite_tbl.delivery_location), htf.italic('(No location found)')) );
htp.br;
htp.p('User Contact: ' || nvl(trim(rec_pohdr_polite_tbl.users_name), htf.italic('(No user found)')) || ' @ ' || nvl(trim(rec_pohdr_polite_tbl.extension1), htf.italic('(No extension found)')));
htp.br;
htp.p('Total Amount: $' || trim(to_char(rec_pohdr_polite_tbl.po_total, declarations.gk_MONEYFORMAT)) );
htp.br;
ELSE
htp.br;
htp.p('No data was found for this PO. The most likely solution is to update the POLite datawarehouse.');
htp.br;
END IF;
END IF;
CLOSE cv_pohdr_tbl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get SIS Info
-- Purpose: To retrieve the SIS information
-- Programmer: Brian G
-- Date: April 27, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_SISInfo(p_journal_id IN VARCHAR2 DEFAULT 'x',
p_sis_id IN VARCHAR2 DEFAULT 'x') IS
TYPE t_sis_vw_tbl IS REF CURSOR;
cv_sis_vw_tbl t_sis_vw_tbl;
rec_sis_vw_tbl SIS_SUBCODE_DESCR_JRNL_VW%ROWTYPE;
v_SQL VARCHAR2(2000);
v_Counter INTEGER := 0;
BEGIN
--v_SQL := 'SELECT DISTINCT * FROM RPT_USER.SISFS_TBL S WHERE S.ACCT_REF = :1 ';
v_SQL := 'SELECT *
FROM SIS_SUBCODE_DESCR_JRNL_VW S
WHERE S.jrnl_ln_ref = :1
AND S.jrnl_ln_ref = s.acct_ref
ORDER BY 1, 2, 3, 4 ';
BEGIN
OPEN cv_sis_vw_tbl FOR v_SQL USING trim(p_sis_id);
END;
htp.p(htf.bold('SIS Information'));
LOOP
BEGIN
FETCH cv_sis_vw_tbl INTO rec_sis_vw_tbl;
END;
EXIT WHEN cv_sis_vw_tbl%NOTFOUND;
IF trim(rec_sis_vw_tbl.acct_ref) IS NOT NULL THEN
v_Counter := v_Counter + 1;
htp.br;
--htp.p('Subcode Description: ' || nvl(trim(rec_sis_vw_tbl.SUBCODE_DESCR), '(No description found)'));
--htp.br;
--htp.p('Subtotalled Amount: $' || nvl(trim(to_char(rec_sis_vw_tbl.SUM_TRANSACTION_AMT, declarations.gk_MONEYFORMAT)), '(No amount found)'));
htp.p(' (' || v_Counter || ') ' || nvl(trim(rec_sis_vw_tbl.SUBCODE_DESCR), '(No description found)') || ', $' || nvl(trim(to_char(rec_sis_vw_tbl.SUM_TRANSACTION_AMT, declarations.gk_MONEYFORMAT)), '(No amount found)'));
--htp.br;
ELSE
htp.br;
htp.p('No data was found. The most likely solution is to update the SISFS table.');
htp.br;
END IF;
END LOOP;
htp.br;
htp.p(htf.img(curl => 'docs/magglass.png', calign => 'left') || htf.italic('Click now to drill down for more information in this record...'));
CLOSE cv_sis_vw_tbl;
END; -- get_SISInfo
-- -------------------------------------------------------------------------------------
-- Procedure: Get Crosstab Info
-- Purpose: To retrieve information from the JOURNAL table for a certain cell in
-- the crosstab
-- Programmer: Brian G
-- Date: Jan 24, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_CrosstabInfo(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_WhereClause IN VARCHAR2 DEFAULT '') IS
v_query totals_settings.ucrfs_query%TYPE; -- The overall SQL query from which we will extract the WHERE clause from
v_query_type TOTALS_SETTINGS.Query_Type%TYPE DEFAULT 'D' ; -- The query type
v_WhereClause VARCHAR2(500) DEFAULT NULL;
cv_jrnl_purchas_vw declarations.gt_jrnl_purchas_vw;
rec_jrnl_purchas_vw jrnl_purchas_vw%ROWTYPE;
v_RegExp VARCHAR2(100); -- The regular expression pattern to match for extracting the WHERE clause
BEGIN
v_WhereClause := replace(p_WhereClause, ' AND ', ' ');
v_WhereClause := replace(v_WhereClause, 'j.', '');
v_WhereClause := replace(v_WhereClause, '~', '"');
-- Pull out the current query's WHERE clause
BEGIN
SELECT ts.ucrfs_query, upper(trim(ts.query_type))
INTO v_query, v_query_type
FROM totals_settings ts
WHERE ts.session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
htp.p('v_query: ' || v_query );
htp.br;
htp.p('p_session_id: ' || p_session_id );
--totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => 'totals.get_CrosstabInfo');
RETURN ;
END;
-- Get the WHERE clause
-- Need to replace all single quotes with 2 single quotes
IF v_query IS NOT NULL THEN
v_query := REPLACE(v_query, '''', '''''');
-- If this is a Summary query then pattern the reg exp accordingly
IF v_query_type = 'S' THEN
v_RegExp := 'SELECT(.*)FROM(.*)WHERE(.*)GROUP BY(.*)ORDER BY(.*)';
ELSE
v_RegExp := 'SELECT(.*)FROM(.*)WHERE(.*)ORDER BY(.*)';
END if;
BEGIN
-- Use regular expressions to pull out the third back reference, meaning the WHERE clause
SELECT trim(REGEXP_REPLACE(v_query, v_RegExp, '\3') )
INTO declarations.gv_SQL_Where
FROM dual;
EXCEPTION
WHEN OTHERS THEN
htp.p('Where Clause: ' || declarations.gv_SQL_Where);
RETURN ;
END;
-- Now replace the double single quotes with a single quote
declarations.gv_SQL_Where := ' WHERE ' || REPLACE(declarations.gv_SQL_Where, '''''', '''');
END IF;
-- Create the SQL
-- I used a tilde ~ in the parameter because I got confused with all those darn single apostrophes
declarations.gv_SQL := 'SELECT * FROM JRNL_PURCHAS_VW J ' || declarations.gv_SQL_Where || replace(p_WhereClause, '~', '''');
-- j.DATE_CREATED, j.LINE_DESCR, j.ledger, j.FOREIGN_AMOUNT, j.JOURNAL_ID, j.JOURNAL_DATE, j.VOUCHER_ID, j.po_id, j.po_ref,
-- j.VENDOR_ID, j.VENDOR_NAME1, j.ACCOUNT, j.ACCT_DESCR, j.DEPTID, j.DEPTID_DESCR, j.FUND_CODE, j.FUND_DESCR, j.PROGRAM_CODE
htp.tableOpen(cborder => '1', cnowrap => '', cattributes => 'border=1, cols=7');
htp.tableRowOpen;
htp.tableData(cvalue => 'Crosstab Detail Information for ' || v_WhereClause || '', ccolspan => '7' );
htp.tableRowClose;
htp.tableRowOpen;
htp.tableData('Journal ID ');
htp.tableData('Date ');
--htp.tableData('Voucher ID ' );
--htp.tableData('PO ID ' );
--htp.tableData('Vendor ID ');
--htp.tableData('Vendor Name ' );
htp.tableData('Account ');
htp.tableData('Activity ');
htp.tableData('Fund ' );
htp.tableData('Function ');
htp.tableData('Amount' );
htp.tableRowClose;
OPEN cv_jrnl_purchas_vw FOR declarations.gv_SQL;
LOOP
FETCH cv_jrnl_purchas_vw INTO rec_jrnl_purchas_vw;
EXIT WHEN cv_jrnl_purchas_vw%NOTFOUND;
htp.tableRowOpen;
htp.tableData(rec_jrnl_purchas_vw.journal_id );
htp.tableData(to_char(rec_jrnl_purchas_vw.JOURNAL_DATE, declarations.gk_FRIENDLY_DATE) );
--htp.tableData(nvl(trim(rec_jrnl_purchas_vw.VOUCHER_ID), '(None)') );
--htp.tableData(nvl(trim(rec_jrnl_purchas_vw.PO_ID), '(None)') );
--htp.tableData(nvl(trim(rec_jrnl_purchas_vw.po_ref), '(None)') );
--htp.tableData(nvl(trim(rec_jrnl_purchas_vw.VENDOR_ID), '(None)') );
--htp.tableData(nvl(trim(rec_jrnl_purchas_vw.VENDOR_NAME1), '(None)') );
htp.tableData(rec_jrnl_purchas_vw.ACCOUNT || ' - ' || rec_jrnl_purchas_vw.ACCT_DESCR );
htp.tableData(rec_jrnl_purchas_vw.DEPTID || ' - ' || rec_jrnl_purchas_vw.DEPTID_DESCR );
htp.tableData(rec_jrnl_purchas_vw.FUND_CODE || ' - ' || rec_jrnl_purchas_vw.Fund_DESCR );
htp.tableData(rec_jrnl_purchas_vw.PROGRAM_CODE );
htp.tableData(calign => 'right', cvalue => trim(to_char(rec_jrnl_purchas_vw.FOREIGN_AMOUNT, declarations.gk_MONEYFORMAT)) );
htp.tableRowClose;
/*
--IF trim(rec_jrnl_purchas_vw.journal_id) IS NOT NULL THEN
htp.br;
htp.p('Amount: $' || trim(to_char(rec_jrnl_purchas_vw.FOREIGN_AMOUNT, declarations.gk_MONEYFORMAT)) );
htp.br;
htp.p('Journal ID: ' || rec_jrnl_purchas_vw.journal_id );
htp.br;
htp.p('Date: ' || to_char(rec_jrnl_purchas_vw.JOURNAL_DATE, declarations.gk_FRIENDLY_DATE) );
htp.br;
htp.p('Voucher ID: ' || nvl(trim(rec_jrnl_purchas_vw.VOUCHER_ID), '(None)') );
htp.br;
htp.p('PO ID: ' || nvl(trim(rec_jrnl_purchas_vw.PO_ID), '(None)') );
htp.br;
htp.p('PO Reference: ' || nvl(trim(rec_jrnl_purchas_vw.po_ref), '(None)') );
htp.br;
htp.p('Vendor ID: ' || nvl(trim(rec_jrnl_purchas_vw.VENDOR_ID), '(None)') );
htp.br;
htp.p('Vendor Name: ' || nvl(trim(rec_jrnl_purchas_vw.VENDOR_NAME1), '(None)') );
htp.br;
htp.br;
--htp.p(htf.hr(cattributes => 'width="60px" '));
htp.p('Account: ' || rec_jrnl_purchas_vw.ACCOUNT || ' - ' || rec_jrnl_purchas_vw.ACCT_DESCR );
htp.br;
htp.p('Activity: ' || rec_jrnl_purchas_vw.DEPTID || ' - ' || rec_jrnl_purchas_vw.DEPTID_DESCR );
htp.br;
htp.p('Fund Code: ' || rec_jrnl_purchas_vw.FUND_CODE || ' - ' || rec_jrnl_purchas_vw.Fund_DESCR );
htp.br;
htp.p('Function: ' || rec_jrnl_purchas_vw.PROGRAM_CODE );
htp.br;
htp.p(htf.hr(cattributes => 'width="200px" '));
*/ END LOOP;
htp.tableClose;
--htp.p('gv_SQL = ' || gv_SQL);
CLOSE cv_jrnl_purchas_vw;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Account Info
-- Purpose: To retrieve the account's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_AccountInfo(p_account IN VARCHAR2 DEFAULT 'x') IS
TYPE t_account_lvl IS REF CURSOR;
cv_account_lvl t_account_lvl;
rec_account_lvl ps_ucr_acct_lv_tbl%ROWTYPE;
v_SQL VARCHAR2(500);
BEGIN
v_SQL := 'SELECT * FROM ps_ucr_acct_lv_tbl a WHERE a.ucr_acct = :1';
OPEN cv_account_lvl FOR v_SQL USING p_account;
htp.p(htf.bold('Hierarchical Account Information'));
-- Should only be one row of data
LOOP
FETCH cv_account_lvl INTO rec_account_lvl;
EXIT WHEN cv_account_lvl%NOTFOUND;
htp.br;
htp.p(' ' || rec_account_lvl.Ucr_Acct_Type || ' ' || rec_account_lvl.ucr_acct_type_dsc);
htp.br;
htp.p(' ' || nvl(trim(rec_account_lvl.ucr_acct_cat), '(No category defined)') || ' ' || rec_account_lvl.ucr_acct_cat_dsc);
htp.br;
htp.p(' ' || nvl(trim(rec_account_lvl.ucr_acct_sum), '(No summary level defined)') || ' ' || rec_account_lvl.ucr_acct_sum_dsc);
htp.br;
htp.p(' ' || nvl(trim(rec_account_lvl.ucr_acct_bdgt), '(No budget category defined)') || ' ' || rec_account_lvl.ucr_acct_bdgt_dsc);
htp.br;
htp.p(' ' || nvl(trim(rec_account_lvl.ucr_acct_group), '(No group defined)') || ' ' || rec_account_lvl.ucr_acct_group_dsc);
htp.br;
htp.p(' ' || trim(rec_account_lvl.ucr_acct) || ' ' || rec_account_lvl.ucr_acct_dsc);
htp.br;
END LOOP;
CLOSE cv_account_lvl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Activity Info
-- Purpose: To retrieve the activity's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_ActivityInfo(p_activity IN VARCHAR2 DEFAULT 'x') IS
TYPE t_activity_lvl IS REF CURSOR;
cv_activity_lvl t_activity_lvl;
rec_activity_lvl ps_ucr_actv_lv_tbl%ROWTYPE;
v_SQL VARCHAR2(500);
BEGIN
v_SQL := 'SELECT * FROM ps_ucr_actv_lv_tbl a WHERE a.ucr_actv = :1';
OPEN cv_activity_lvl FOR v_SQL USING p_activity;
htp.p(htf.bold('Hierarchical Activity Information'));
-- Should only be one row of data
LOOP
FETCH cv_activity_lvl INTO rec_activity_lvl;
EXIT WHEN cv_activity_lvl%NOTFOUND;
htp.br;
htp.p(' ' || rec_activity_lvl.ucr_org || ' ' || rec_activity_lvl.ucr_org_desc);
htp.br;
htp.p(' ' || nvl(trim(rec_activity_lvl.ucr_div), '(No division defined)') || ' ' || rec_activity_lvl.ucr_div_desc);
htp.br;
htp.p(' ' || nvl(trim(rec_activity_lvl.ucr_dept), '(No department defined)') || ' ' || rec_activity_lvl.ucr_dept_desc);
htp.br;
htp.p(' ' || trim(rec_activity_lvl.ucr_actv) || ' ' || rec_activity_lvl.ucr_actv_desc);
htp.br;
END LOOP;
CLOSE cv_activity_lvl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Fund Info
-- Purpose: To retrieve the fund's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_FundInfo(p_fund IN VARCHAR2 DEFAULT 'x') IS
TYPE t_fund_lvl IS REF CURSOR;
cv_fund_lvl t_fund_lvl;
rec_fund_lvl ps_ucr_fund_lv_tbl%ROWTYPE;
v_SQL VARCHAR2(500);
BEGIN
v_SQL := 'SELECT * FROM ps_ucr_fund_lv_tbl a WHERE a.ucr_fund = :1';
OPEN cv_fund_lvl FOR v_SQL USING p_fund;
htp.p(htf.bold('Hierarchical Fund Information'));
-- Should only be one row of data
LOOP
FETCH cv_fund_lvl INTO rec_fund_lvl;
EXIT WHEN cv_fund_lvl%NOTFOUND;
htp.br;
htp.p(' ' || rec_fund_lvl.ucr_fundtype || ' ' || rec_fund_lvl.ucr_fundtype_descr);
htp.br;
htp.p(' ' || nvl(trim(rec_fund_lvl.ucr_category), '(No category defined)') || ' ' || rec_fund_lvl.ucr_category_descr);
htp.br;
htp.p(' ' || nvl(trim(rec_fund_lvl.ucr_group), '(No group defined)') || ' ' || rec_fund_lvl.ucr_group_descr);
htp.br;
htp.p(' ' || trim(rec_fund_lvl.ucr_fund) || ' ' || rec_fund_lvl.ucr_fund_descr);
htp.br;
END LOOP;
CLOSE cv_fund_lvl;
END get_FundInfo;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Function Info
-- Purpose: To retrieve the function's Golden Tree (hierarchical) information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_FunctionInfo(p_func IN VARCHAR2 DEFAULT 'x') IS
TYPE t_func_lvl IS REF CURSOR;
cv_func_lvl t_func_lvl;
rec_func_lvl ps_ucr_func_lv_tbl%ROWTYPE;
v_SQL VARCHAR2(500);
BEGIN
v_SQL := 'SELECT * FROM ps_ucr_func_lv_tbl a WHERE a.ucr_funccode = :1';
OPEN cv_func_lvl FOR v_SQL USING p_func;
htp.p(htf.bold('Hierarchical Function Information'));
-- Should only be one row of data
LOOP
FETCH cv_func_lvl INTO rec_func_lvl;
EXIT WHEN cv_func_lvl%NOTFOUND;
htp.br;
htp.p(' ' || rec_func_lvl.ucr_functype || ' ' || rec_func_lvl.ucr_functype_descr);
htp.br;
htp.p(' ' || nvl(trim(rec_func_lvl.ucr_funcgroup), '(No group defined)') || ' ' || rec_func_lvl.ucr_funcgroup_desc);
htp.br;
htp.p(' ' || trim(rec_func_lvl.ucr_funccode) || ' ' || rec_func_lvl.ucr_funccode_descr);
htp.br;
END LOOP;
CLOSE cv_func_lvl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Cost Center Info
-- Purpose: To retrieve the cost center's information
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- -------------------------------------------------------------------------------------
PROCEDURE get_CostCenterInfo(p_code IN VARCHAR2 DEFAULT 'x') IS
TYPE t_costcenter_lvl IS REF CURSOR;
cv_costcenter_lvl t_costcenter_lvl;
rec_costcenter_lvl UCR_COST_CENTER_LVL3_VW%ROWTYPE;
v_SQL VARCHAR2(500);
BEGIN
v_SQL := 'SELECT * FROM UCR_COST_CENTER_LVL3_VW A WHERE A.COST_CENTER = :1';
OPEN cv_costcenter_lvl FOR v_SQL USING p_code;
htp.p(htf.bold('Cost Center Information'));
-- Should only be one row of data
LOOP
FETCH cv_costcenter_lvl INTO rec_costcenter_lvl;
EXIT WHEN cv_costcenter_lvl%NOTFOUND;
htp.br;
htp.p(' ' || p_code || ' ' || nvl(trim(rec_costcenter_lvl.cost_center_desc), '(No description found)') );
htp.br;
END LOOP;
CLOSE cv_costcenter_lvl;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Get Drilldown Info
-- Purpose: To retrieve the drilldown information for given summary line
-- Programmer: Brian G
-- Date: Jan 17, 2007
-- Parameter:
-- p_drilldown_id - The WHERE clause
--
-- Example of p_drilldown_id:
-- j.FISCAL_YEAR= '2008' AND j.ACCOUNT= '119501' AND LPAD(j.ACCOUNTING_PERIOD,3,'0')= '007' AND j.DEPTID= 'A01372' AND j.PROGRAM_CODE= 'ZZ' AND j.FUND_CODE= 'ZZZZZ' AND j.LEDGER= 'ACTUALS' AND j.SOURCE= 'JRV' AND
-- This parameter was generated in a loop and thus has a trailing AND statement,
-- hence the 1=1, as opposed to trimming it off.
-- -------------------------------------------------------------------------------------
PROCEDURE get_DrilldownInfo(p_drilldown_id IN VARCHAR2 DEFAULT '1=1') IS
TYPE t_ExplainPlan IS REF CURSOR;
v_ExplainPlan t_ExplainPlan;
rec_jrnl_purchas_vw JRNL_PURCHAS_VW%ROWTYPE;
v_ExplainPlan_SQL VARCHAR2(4000);
v_QuerySize VARCHAR2(4000) := '';
-- Since we are passing a variable that contains apostrophes via javascript, replace them with a /
-- and then turn the / back into ' when finished
v_drilldown_id VARCHAR2(4000) := REPLACE(p_drilldown_id, '/', '''');
v_StatementID VARCHAR2(20) := '';
BEGIN
/* -- Since we're not passing the session id, generate a random string for the statement id
-- select '''' || dbms_random.string('U', 10) || ''''
select substr(to_char(dbms_random.value), 2, 10)
INTO v_StatementID
from dual;
v_ExplainPlan_SQL := 'EXPLAIN PLAN SET STATEMENT_ID = ''' || v_StatementID || ''' FOR ';
v_ExplainPlan_SQL := v_ExplainPlan_SQL || 'SELECT ' || declarations.gk_DRILLDOWN_FIELDS;
v_ExplainPlan_SQL := v_ExplainPlan_SQL || 'FROM JRNL_PURCHAS_VW J ';
v_ExplainPlan_SQL := v_ExplainPlan_SQL || 'WHERE J.BUSINESS_UNIT = ''UCR'' AND ' || v_drilldown_id || ' 1=1 ';
--htp.p(v_ExplainPlan_SQL);
EXECUTE IMMEDIATE v_ExplainPlan_SQL;
--OPEN v_ExplainPlan FOR v_ExplainPlan_SQL;
-- A simpler way to get the byte size of a query
BEGIN
SELECT DISTINCT round(bytes/1024, 0)
INTO v_QuerySize
FROM plan_table pt
WHERE pt.statement_id = ''|| v_StatementID || ''
AND pt.operation = 'SELECT STATEMENT'
AND pt.timestamp = (SELECT MAX(pt2.timestamp)
FROM plan_table pt2
WHERE pt.statement_id = pt2.statement_id
AND pt.operation = pt2.operation
AND pt.id = pt2.id
) ;
EXCEPTION
WHEN OTHERS THEN
v_QuerySize := 'Unknown (' || SQLERRM || ')' ;
END;
--CLOSE */
htp.p('Est. Query Size: ' || v_QuerySize || 'Kb');
htp.p(' Click now to drilldown into this summary row...');
EXCEPTION
WHEN OTHERS THEN
htp.p('Error in procedure, get_DrilldownInfo: ' || SQLERRM);
END get_DrilldownInfo;
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
/*PROCEDURE login IS
\*Simply displays a message stating this screen is deprecated and
provides a link to iVIEWS. *\
BEGIN
SELECT l.url INTO declarations.gv_link FROM ucrfs_link l WHERE TYPE = 'iviews';
htp.p('');
htp.htmlOpen;
htp.headOpen;
htp.title('Welcome to UCRFStotals');
htp.p('');
htp.meta(chttp_equiv => 'refresh',cname => 'Redirect to iViews',ccontent => '0; URL='||declarations.gv_link);
htp.headClose;
htp.bodyOpen;
\*
htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.comment('END table for UCRFStotals title graphic');
--htp.p('
This page is deprecated. Please use CAS/EACS to access this application.
');
htp.tableData(cvalue => '');
htp.tableData(cvalue => '');
htp.formClose;
htp.p('');
htp.tableClose;
*\
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => 'totals.login');
RETURN;
END;*/
/* -- -------------------------------------------------------------------------------------
-- Procedure: Exit Application
-- Author: Brian Griffin
-- Created: March 1, 2007
-- Purpose: To exit the application
-- Source: Taken from app.logout at HRDW@PROD8
-- -------------------------------------------------------------------------------------
procedure exit_application IS
BEGIN
-- set logout_time
--update totals_settings
--set logout_time = sysdate
--where session_id = p_session_id;
--commit;
-- delete cookie
--owa_util.mime_header('text/html', false);
--owa_cookie.remove('hrdw_id', g_session_id);
--owa_util.http_header_close();
-- self close
--owa_util.redirect_url(hrdw.g_app_login_page, true);
htp.p(declarations.gk_DOCTYPE);
htp.p('
Now Exiting UCRFStotals
Internet Explorer users: Please click "Yes" to close this window and exit UCRFStotals...
Firefox users: Please close this window manually to exit UCRFStotals...
');
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => 'totals.exit_application');
RETURN;
end exit_application;
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE authenticate\*(t_username IN varchar2)*\ IS
\*
Verifies current user is authorized
if authorized, creates session_id and inserts
record in totals_settings table
*\
\*v_session_id_date date;
v_session_id totals_settings.session_id%TYPE;
v_seq varchar2(4);
fiscal_year number;
v_setting number;
CURSOR c_usr IS
--Check to see if this user has stored preferences
SELECT * FROM totals_user_prefs WHERE user_id = t_username;
r_usr_row totals_user_prefs%ROWTYPE;*\
BEGIN
htp.p('');
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - Authenticating');
htp.p('');
htp.headClose;
htp.bodyOpen;
\*
htp.formOpen(curl => 'totals_tabs.query',cmethod => 'POST');
htp.formHidden(cname => 'p_session_id');
htp.formHidden(cname => 'p_already_open',cvalue => 'FALSE');
htp.formClose;
--session_id uses a portion of the current date
SELECT SYSDATE INTO v_session_id_date FROM DUAL;
--get a four-digit number to append the date to create a session_id
SELECT TO_CHAR(SESSION_SEQ.NEXTVAL) INTO v_seq FROM DUAL;
v_session_id := TO_CHAR(v_session_id_date, 'DMMDDYYHHmiSS') || v_seq;
BEGIN
--see if user has authorization to use this application
SELECT setting_value INTO v_setting FROM eacs_user_info WHERE username = UPPER(t_username);
EXCEPTION WHEN NO_DATA_FOUND THEN
v_setting := 0;
htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.comment('END table for UCRFStotals title graphic');
htp.p('You are not authorized to access this application. ');
htp.anchor(curl => 'http://oasdev.ucr.edu/rptdb/owa/ucrfs.login',ctext => 'Return to Login page');
END;
IF v_setting = 1 THEN
--if authorized, insert sessio in totals_settings table
INSERT INTO totals_settings
(session_id, login_time, user_id)
VALUES
(v_session_id, SYSDATE, t_username);
\*
if there is not already an entry in the user_prefs table insert one
*\
OPEN c_usr;
FETCH c_usr INTO r_usr_row;
IF c_usr%NOTFOUND THEN
INSERT INTO totals_user_prefs (user_id) VALUES (t_username);
COMMIT;
FETCH c_usr INTO r_usr_row;
END IF;
CLOSE c_usr;
--set the fiscal year
fiscal_year := TO_NUMBER(TO_CHAR(sysdate,'YYYY'));
IF TO_DATE(TO_CHAR(sysdate,'MONTH'),'MONTH') >= TO_DATE('JULY','MONTH') THEN
fiscal_year := fiscal_year +1;
END IF;
UPDATE totals_settings
SET fiscal_years = fiscal_year
WHERE session_id = v_session_id;
COMMIT;
htp.p('
');
END IF;
*\
SELECT l.url INTO declarations.gv_link FROM ucrfs_link l WHERE l.TYPE = 'ucrfstotals';
htp.p('
This page is deprecated. Please use ' || htf.anchor(curl => declarations.gv_link,ctext => 'CASified UCRFStotals.') || '
');
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => 'totals.authenticate');
RETURN;
END;
-- -------------------------------------------------------------------------------------
-- Procedure:
-- -------------------------------------------------------------------------------------
PROCEDURE auth(ticket IN VARCHAR2 DEFAULT NULL) IS
v_results varchar2(50);
v_valid VARCHAR2(3);
v_userid totals_settings.user_id%TYPE;
v_session_id_date date;
--v_Previous_Login date;
v_session_id totals_settings.session_id%TYPE;
v_seq varchar2(4);
fiscal_year number;
v_setting number;
nCount NUMBER;
--Check to see if this user has stored preferences
CURSOR c_usr IS
SELECT *
FROM totals_user_prefs
WHERE user_id = v_userid;
r_usr_row totals_user_prefs%ROWTYPE;
BEGIN
htp.p('');
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - Authenticating');
htp.p('');
htp.headClose;
htp.bodyOpen(cattributes => 'topmargin=0 leftmargin=0');
htp.formOpen(curl => 'totals_tabs.query',cmethod => 'POST');
htp.formHidden(cname => 'p_session_id');
htp.formHidden(cname => 'p_already_open',cvalue => 'FALSE');
htp.formClose;
-- Get the URL
SELECT l.url
INTO declarations.gv_link
FROM totals_link l
WHERE l.TYPE = 'totals2';
IF ticket IS NULL THEN
--owa_util.redirect_url('https://auth.ucr.edu/cas/login?service='|| 'http://oasdev.ucr.edu/rptdb/owa/' ||'ucrfs.auth',FALSE);
htp.script(clanguage => 'javascript',cscript => 'window.location.href="https://auth.ucr.edu/cas/login?service='|| declarations.gv_link || 'totals.auth"');
htp.p('Ticket was empty');
htp.bodyClose;
htp.htmlClose;
-- RETURN;
END IF;
BEGIN
SELECT sso_validation_ticket@sso_auth(REPLACE(declarations.gv_link || 'totals.auth', ':', '%3a'), ticket)
INTO v_results
FROM dual;
EXCEPTION
WHEN OTHERS THEN
htp.p('SQL Error: ' || SQLERRM);
END;
v_valid := upper(substr(v_results,1,3));
--v_valid := 'YES';
IF v_valid <> 'YES' THEN
-- Web Page HEAD
--htp.p('');
--htp.htmlOpen;
--htp.headOpen;
-- Set the webpage title
--htp.title(ctitle => 'UCRFStotals - Error Logging Into UCRFStotals');
--htp.bodyOpen();
totals_util.get_TitleImages;
htp.htitle(ctitle => 'Error!', nsize => 2);
htp.p('There was a problem logging you into this application (the response code was, ' || v_results || '). Please be patient while we resolve this situation. ') ;
htp.bodyClose;
htp.htmlClose;
RETURN;
END IF;
v_userid := (upper(substr(v_results,5, length(v_results)- 5)));
-- IF is_active_employee@fsacct(v_userid) = 0 THEN -- 0 -invalid;1-valid
\* IF is_active_employee@acctuser(v_userid) = 0 THEN -- 0 -invalid;1-valid
-- Web Page HEAD
htp.p('');
htp.htmlOpen;
htp.headOpen;
-- Set the webpage title
htp.title(ctitle => 'UCRFStotals - Error Logging Into UCRFStotals');
htp.bodyOpen();
totals_util.get_TitleImages;
htp.para;
htp.p('
The user, ' || v_userid || ', has been inactivated. If this is an error, please see your department adminstrator.
');
htp.p('Technical information: '); htp.br;
htp.p(' declarations.gv_link: ' || declarations.gv_link);htp.br;
htp.p(' v_valid: ' || v_valid);htp.br;
htp.p(' v_results: ' || v_results);htp.br;
htp.bodyClose;
htp.htmlClose;
RETURN;
END IF;
*\ --see if user has authorization to use this application
-- This has a hard-coded APP_ID of 49
BEGIN
SELECT COUNT(*)
INTO nCount
FROM eacs_user_info
WHERE username = UPPER(v_userid);
EXCEPTION
WHEN OTHERS THEN
nCount := 0;
END;
IF nCount > 0 THEN
v_setting := 1;
ELSE
v_setting := 0;
totals_util.get_TitleImages;
\* htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.comment('END table for UCRFStotals title graphic');
*\ htp.p('You are not authorized to access UCRFStotals. Please contact your departmental SAA to set you up in EACS. ');
htp.anchor(curl => declarations.gv_link || 'totals.login',ctext => 'Return to Login page');
htp.bodyClose;
htp.htmlClose;
RETURN;
END IF;
IF v_setting = 1 THEN
-- If the user already has an old login entry, then delete it
\* select t.Login_Time
INTO v_Previous_Login
from totals_settings t
WHERE t.User_Id = UPPER(v_userid)
AND t.login_time - SYSDATE > 1
;
*\
--session_id uses a portion of the current date
SELECT SYSDATE
INTO v_session_id_date
FROM DUAL;
--get a four-digit number to append the date to create a session_id
SELECT TO_CHAR(SESSION_SEQ.NEXTVAL)
INTO v_seq
FROM DUAL;
v_session_id := TO_CHAR(v_session_id_date, 'DMMDDYYHHmiSS') || v_seq;
--if authorized, insert sessiom in totals_settings table
INSERT INTO totals_settings(session_id, login_time, user_id)
VALUES (v_session_id, SYSDATE, v_userid);
\*
if there is not already an entry in the user_prefs table insert one
*\
OPEN c_usr;
FETCH c_usr INTO r_usr_row;
IF c_usr%NOTFOUND THEN
INSERT INTO totals_user_prefs (user_id) VALUES (v_userid);
COMMIT;
FETCH c_usr INTO r_usr_row;
END IF;
CLOSE c_usr;
--set the fiscal year
fiscal_year := TO_NUMBER(TO_CHAR(sysdate,'YYYY'));
IF TO_DATE(TO_CHAR(sysdate,'MONTH'),'MONTH') >= TO_DATE('JULY','MONTH') THEN
fiscal_year := fiscal_year +1;
END IF;
-- Update the fiscal year and set the default fields to fiscal year and accounting period
UPDATE totals_settings
SET fiscal_years = fiscal_year,
standard_tab_fields = 'j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, '
WHERE session_id = v_session_id;
COMMIT;
htp.p('
');
END IF;
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLCODE || ' ' || SQLERRM, p_CalledFrom => 'totals.auth');
RETURN;
END auth;
*/
-- -------------------------------------------------------------------------------------
-- Procedure: Preferences
-- -------------------------------------------------------------------------------------
PROCEDURE preferences(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL) IS
/*
Presents various options to the user. The settings are stored in user_prefs
*/
v_updated varchar(25);
v_USER_ID totals_settings.user_id%TYPE;
CURSOR c_usr IS
SELECT *
FROM totals_user_prefs
WHERE user_id = v_USER_ID;
r_usr_row totals_user_prefs%ROWTYPE;
BEGIN
-- htp.p('');
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - User Preferences');
htp.p('');
htp.headClose;
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
SELECT user_id INTO v_USER_ID FROM totals_settings WHERE session_id = p_session_id;
--get user's preferences
OPEN c_usr;
FETCH c_usr INTO r_usr_row;
CLOSE c_usr;
htp.p('
');
htp.bodyOpen(cattributes => 'onload="document.forms[0].connection.disabled=true;"');
--display 'prefs' header
htp.p(totals_util.tab_headers(p_session_id => p_session_id,
p_tab => 'prefs',
p_sub_section => '',
p_query_tab_selection => ''));
htp.comment('Encompasing Table');
htp.tableOpen(cattributes => 'cellpadding="5" width="650"');
htp.formOpen(cmethod => 'POST',
curl => 'totals_update.update_preferences',
cattributes => 'name="frm_pref"');
htp.formHidden(cname => 'p_session_id', cvalue => p_session_id);
htp.formHidden(cname => 'p_link', cvalue => '');
htp.formHidden(cname => 'p_usr', cvalue => '');
htp.tableRowOpen;
htp.p('
)
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.tableData(cvalue => 'Use these settings to customize how you want UCRFStotals to look.',cattributes => 'class="subHead"');
htp.tableRowClose;
htp.p('
');
htp.tableOpen;
htp.tableRowOpen;
IF r_usr_row.auto_open = 'y' THEN
htp.tableData(htf.formCheckbox(cname => 'p_auto_open',cvalue => 'y',cattributes => 'id="p_auto_open" checked="checked" onclick="turn_auto_open();"'));
ELSE
htp.tableData(htf.formCheckbox(cname => 'p_auto_open',cvalue => 'y',cattributes => 'id="p_auto_open" onclick="turn_auto_open();"'));
END IF;
htp.tableData(cvalue => 'When starting, automatically re-open last saved settings.',ccolspan => '2',cattributes => 'id="td_ao" onclick="turn(''p_auto_open'');"');
htp.tableRowClose;
htp.tableRowOpen;
IF r_usr_row.auto_execute = 'y' THEN
htp.tableData(cvalue => '
' || htf.formCheckbox(cname => 'p_auto_execute',cvalue => 'y',cattributes => 'id="p_auto_execute" checked="checked"') ||
htf.tableData(cvalue => '...and then automatically run this query.',cattributes => 'id="td_ae" onclick="turn(''p_auto_execute'');"'));
ELSE
htp.tableData(cvalue => '
' || r_usr_row.auto_execute || htf.formCheckbox(cname => 'p_auto_execute',cvalue => 'y',cattributes => 'id="p_auto_execute"') ||
htf.tableData(cvalue => '...and then automatically run this query.',cattributes => 'id="td_ae" onclick="turn(''p_auto_execute'');"'));
END IF;
htp.tablerowclose;
htp.tableClose;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
--end form data (
)
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.tableData(cvalue => 'You may opt to select functions, transaction codes, or both for your queries.',cattributes => 'class="subHead"');
htp.tableRowClose;
htp.p('
');
htp.tableOpen;
htp.tableRowOpen;
IF r_usr_row.func_pref = 'F' THEN
htp.tableData(htf.formRadio(cname => 'p_function_pref',cvalue => 'F',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_function_pref',cvalue => 'F'));
END IF;
htp.tableData(cvalue => 'Functions only',cattributes => 'onclick="select_func(''F'');"');
htp.tableRowClose;
htp.tableRowOpen;
IF r_usr_row.func_pref = 'T' THEN
htp.tableData(htf.formRadio(cname => 'p_function_pref',cvalue => 'T',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_function_pref',cvalue => 'T'));
END IF;
htp.tableData(cvalue => 'Transaction codes only',cattributes => 'onclick="select_func(''T'');"');
htp.tableRowClose;
htp.tableRowOpen;
IF r_usr_row.func_pref = 'B' THEN
htp.tableData(htf.formRadio(cname => 'p_function_pref',cvalue => 'B',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_function_pref',cvalue => 'B'));
END IF;
htp.tableData(cvalue => 'Both functions and transaction codes',cattributes => 'onclick="select_func(''B'');"');
htp.tableRowClose;
htp.tableClose;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
--end form data (
)
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.tableData(cvalue => 'Within the Activity, Fund and Account FAU Selection popup windows,
you may select how Totals queries the data',
cattributes => 'class="subHead"');
htp.tableRowClose;
htp.p('
');
htp.tableOpen;
htp.tableRowOpen;
-- Express mode
IF r_usr_row.selection_mode = 'E' THEN
htp.tableData(htf.formRadio(cname => 'p_selection_mode',cvalue => 'E',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_selection_mode',cvalue => 'E'));
END IF;
htp.tableData(cvalue => 'Express Mode - Before displaying the data (activity, fund or account),
Totals waits until you Find and Mark a value and then will display the FAU data with your selection highlighted. ',
cattributes => 'onclick="select_mode(''E'');"');
htp.tableRowClose;
htp.tableRowOpen;
-- Standard mode
IF r_usr_row.selection_mode = 'S' THEN
htp.tableData(htf.formRadio(cname => 'p_selection_mode',cvalue => 'S',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_selection_mode',cvalue => 'S'));
END IF;
htp.tableData(cvalue => 'Standard Mode - Totals will automatically display the FAU data
(activity, fund or account) when the popup window displays. This may take quite awhile if
no other hierarchical values have already been selected. ',
cattributes => 'onclick="select_mode(''S'');"');
htp.tableRowClose;
htp.tableClose;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
--end form data (
)
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.tableData(cvalue => 'Choose how you would like to view the FAU data being selected.',cattributes => 'class="subHead"');
htp.tableRowClose;
htp.p('
');
htp.tableOpen;
htp.tableRowOpen;
IF r_usr_row.fau_view = 'T' THEN
htp.tableData(htf.formRadio(cname => 'p_fau_view',cvalue => 'T',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_fau_view',cvalue => 'T'));
END IF;
htp.tableData(cvalue => 'Traditional Style',cattributes => 'onclick="select_fau(''T'');"');
htp.tableRowClose;
htp.tableRowOpen;
IF r_usr_row.fau_view = 'H' THEN
htp.tableData(htf.formRadio(cname => 'p_fau_view',cvalue => 'H',cchecked => 'checked'));
ELSE
htp.tableData(htf.formRadio(cname => 'p_fau_view',cvalue => 'H'));
END IF;
htp.tableData(cvalue => 'Hierarchical Style',cattributes => 'onclick="select_fau(''H'');"');
htp.tableRowClose;
htp.tableClose;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
--end form data (
');
--At this time, this has not been implemented
\* --begin form data table (
)
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.tableData(cvalue => 'Choose how you would like to view the FAU data being selected.',cattributes => 'class="subHead"');
htp.tableRowClose;
htp.p('
)
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.tableData(cvalue => 'Overriding SQL Indexes',cattributes => 'class="Heading"');
htp.tableRowClose;
htp.tableRowOpen;
htp.tableData(cvalue => 'If your queries are taking too long to run, you may opt to use Override SQL Index feature. This feature reformats your query statement and overrides Oracle index with UCRFStotals index in your queries. ' ||
'This may, for example, cut a 4 hour query down to 20 minutes. In general, this is only recommended for very long running queries and may actually worsen query performance.',cattributes => 'class="subHead"');
htp.tableRowClose;
htp.p('
');
htp.tableOpen;
htp.tableRowOpen;
IF r_usr_row.override = 'y' THEN
htp.tableData(htf.formCheckbox(cname => 'p_override',cvalue => 'y',cchecked => 'checked'));
ELSE
htp.tableData(htf.formCheckbox(cname => 'p_override',cvalue => 'y'));
END IF;
htp.tableData(cvalue => 'Override Oracle''s SQL Index with UCRFStotals Index.',ccolspan => 2,cattributes => 'onclick="turn(''p_override'');"');
htp.tableRowClose;
htp.tableClose;
htp.p('
');
htp.tableRowClose;
htp.tableRowOpen;
htp.tableData(cvalue => ' Connection Made',ccolspan => 2,cattributes => 'class="Heading"');
htp.tablerowclose;
htp.tableRowOpen;
htp.tableData(cvalue => 'The following information simply shows which connection was made to the UCRFStotals database.',ccolspan => 2,cattributes => 'class="subHead"');
htp.tableRowClose;
htp.tableRowOpen;
htp.p('
');
htp.tableRowClose;
htp.tableClose;
--end form data (
)
htp.p('
');
htp.tableData(htf.img( declarations.gk_IMAGE_PATH || 'transparent_pixel.gif',
calt => '',
cattributes => ' width="15" height="1" border="0"'),
cattributes => ' width="15" background="'|| declarations.gk_IMAGE_PATH || 'tbl_right_stretch.gif"');
htp.tableRowClose;
htp.tableRowOpen;
htp.tableData(htf.img( declarations.gk_IMAGE_PATH || 'tbl_bottom_left_corner.gif',
calt => '',
cattributes => ' width="14" height="13" border="0"'),
cattributes => ' width="14" valign="top"');
htp.tableData(htf.img( declarations.gk_IMAGE_PATH || 'transparent_pixel.gif',
calt => '',
cattributes => ' width="1" height="13" border="0"'),
cattributes => ' width="100%" valign="top" background="'|| declarations.gk_IMAGE_PATH || 'tbl_bottom_stretch.gif"');
htp.tableData(htf.img( declarations.gk_IMAGE_PATH || 'tbl_bottom_right_corner.gif',
calt => '',
cattributes => ' width="14" height="13" border="0"'),
cattributes => ' width="14" valign="top"');
htp.tableRowClose;
htp.tableClose;
htp.comment('End Advanced Table');
htp.p('');
htp.tableRowClose;
*/
htp.formClose;
htp.tableClose;
htp.p('');
--get date journal_tbl was updated
SELECT TO_CHAR(MAX(posted_date), 'Dy, Mon DD ''YY')
INTO v_updated
FROM journal_tbl;
htp.p('');
htp.bodyClose;
htp.htmlClose;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => 'totals.preferences');
RETURN;
END;
-- -------------------------------------------------------------------------------------
-- Procedure: Display PO Information from eBuy
-- Purpose: To allow the user to drill down on a particular PO and display its data
-- from eBuy
-- Programmer: Brian
-- Date: Nov 13, 2006
-- Parameters: Session ID
-- PO ID
-- -------------------------------------------------------------------------------------
/*PROCEDURE drilldown_po_details_ORIG(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_PO_ID IN totals_settings.po_id%TYPE DEFAULT NULL)
IS
-- Get the PO Line information from PO_LINES for eBuy order only
-- ORA-22992: cannot use LOB locators selected from remote tables
CURSOR crsr_eBuyPOLines(v_PO_ID VARCHAR2) IS
SELECT pol.po_line, \*to_char(pol.descr) "descr",*\ pol.catalog_number, pol.unit_of_measure, pol.quantity, '$' || to_char(pol.unit_price, declarations.gk_MONEYFORMAT) "unit_price",
pol.taxable, '$' || to_char(pol.total_price, declarations.gk_MONEYFORMAT) "total_price", pol.quantity_received, pol.delivered, pol.status_id, (select DISTINCT po_status_description from po_status_type@ebuy_prod t WHERE t.po_status_id = pol.status_id),
pol.change_date, pol.change_user, pol.expected_delivery, pol.po_line_display
\* INTO v_po_line, v_descr, v_catalog_number, v_unit_of_measure, v_quantity, v_unit_price,
v_taxable, v_total_price, v_quantity_received, v_delivered, v_status_id, v_po_status_descr,
v_change_date, v_change_user, v_expected_delivery, v_po_line_display *\
FROM po_lines@ebuy_prod pol, po_header@ebuy_prod poh
WHERE poh.order_id = pol.Order_Id
AND trim(poh.po_number) = trim(v_PO_ID) ;
v_SQL LONG := '';
n_RowCounter NUMBER := 1;
-- PO variables; since we are pulling PO data from either the po_header@ebuy_prod or subpo@subpo or po_info@polite,
-- we cannot use table.field@link%TYPE effectively
v_PO_Type VARCHAR2(10) := '';
v_PO_Type_Descr VARCHAR2(500) := '';
d_PO_Request_Date DATE := '';
v_Vendor_ID VARCHAR2(200) := '';
v_Vendor_Name VARCHAR2(400) := '';
v_PO_Transactor VARCHAR2(160) := '';
v_PO_Trans_Phone VARCHAR2(100) := '';
v_PO_Requestor VARCHAR2(160) := '';
v_PO_Req_Phone VARCHAR2(100) := '';
v_PO_Delivery_Code VARCHAR2(200) := '';
v_Delivery_Code_Descr VARCHAR2(500) := '';
v_DeliveryAddress1 VARCHAR2(500) := '';
v_DeliveryAddress2 VARCHAR2(500) := '';
v_DeliveryAddress3 VARCHAR2(500) := '';
v_DeliveryAddress4 VARCHAR2(500) := '';
v_PO_Descr VARCHAR2(500) := '';
v_PO_Amount VARCHAR2(200) := '0.0';
-- eBuy PO Line variables
v_po_line po_lines.po_line@ebuy_prod%TYPE;
v_descr po_lines.descr@ebuy_prod%TYPE;
v_catalog_number po_lines.catalog_number@ebuy_prod%TYPE;
v_unit_of_measure po_lines.unit_of_measure@ebuy_prod%TYPE;
v_quantity po_lines.quantity@ebuy_prod%TYPE;
v_unit_price po_lines.unit_price@ebuy_prod%TYPE;
v_taxable po_lines.taxable@ebuy_prod%TYPE;
v_total_price po_lines.total_price@ebuy_prod%TYPE;
v_quantity_received po_lines.quantity_received@ebuy_prod%TYPE;
v_delivered po_lines.delivered@ebuy_prod%TYPE;
v_status_id po_lines.status_id@ebuy_prod%TYPE;
v_po_status_descr po_status_type.po_status_description@ebuy_prod%TYPE;
v_change_date po_lines.change_date@ebuy_prod%TYPE;
v_change_user po_lines.change_user@ebuy_prod%TYPE;
v_expected_delivery po_lines.expected_delivery@ebuy_prod%TYPE;
v_po_line_display po_lines.po_line_display@ebuy_prod%TYPE;
n_SumQuantity NUMBER(4) := 0;
n_SumAmount NUMBER(13,2) := 0;
v_ErrMsgValue VARCHAR2(4) := 0;
BEGIN
-- In trying to determine which table to get the PO information from, we start with
-- po_header@ebuy_prod, if an EXCEPTION of no_data_found is thrown, then start another BEGIN SELECT INTO END;
BEGIN
-- Get the PO information from PO_HEADER for eBuy orders only
SELECT DISTINCT poh.po_type, (select ctd.code_descr from code_type_descriptors@ebuy_prod ctd where ctd.column_name = 'PO_TYPE' AND ctd.column_value = poh.po_type),
poh.request_date, poh.vendor_code, poh.vendor_name,
poh.transactor, \*(SELECT primary_phone FROM ucr_netid@acctuser WHERE upper(TRIM(net_id)) = upper(TRIM(poh.transactor)) )*\ ' '"Phone",
poh.requestor, (SELECT primary_phone FROM ucr_netid@acctuser WHERE upper(TRIM(net_id)) = upper(TRIM(poh.requestor)) ) "Phone",
poh.delivery_code, (select dc.delivery_location from delivery_codes@ebuy_prod dc WHERE dc.delivery_code = upper(trim(poh.delivery_code)) ) "Delivered To",
poh.descr, '$' || to_char(poh.total, declarations.gk_MONEYFORMAT) "Total"
INTO v_PO_Type, v_PO_Type_Descr, d_PO_Request_Date, v_Vendor_ID, v_Vendor_Name, v_PO_Transactor, v_PO_Trans_Phone, v_PO_Requestor, v_PO_Req_Phone,
v_PO_Delivery_Code, v_Delivery_Code_Descr, v_PO_Descr, v_PO_Amount
FROM po_header@ebuy_prod poh
WHERE trim(poh.po_number) = trim(p_PO_ID) ;
COMMIT;
EXECUTE IMMEDIATE 'alter session close database link ebuy';
gv_Title := 'eBuy Information on PO Number ' || trim(p_PO_ID);
EXCEPTION
-- If no data was found in the PO_HEADER then try the SubPO and POLite tables
WHEN no_data_found THEN
-- A Sub PO?
BEGIN
SELECT DISTINCT 'S', 'SubPO', s.vendor_id, s.vendor_name, s.username, s.delivery_code, s.description, '$' || to_char(s.total, declarations.gk_MONEYFORMAT) "Total",
s.del_address1, s.del_address2, s.del_address3, s.del_address4
INTO v_PO_Type, v_PO_Type_Descr, v_Vendor_ID, v_Vendor_Name, v_PO_Requestor, v_PO_Delivery_Code, v_PO_Descr, v_PO_Amount,
v_DeliveryAddress1, v_DeliveryAddress2, v_DeliveryAddress3, v_DeliveryAddress4
FROM subpo@subpo s
WHERE S.SUBPO_NUMBER = p_PO_ID;
COMMIT;
EXECUTE IMMEDIATE 'alter session close database link subpo';
gv_Title := 'SubPO Information on PO Number ' || trim(p_PO_ID);
EXCEPTION
WHEN no_data_found THEN
-- A POLite PO?
BEGIN
SELECT p.vendor_code, p.vendor_name, p.users_name, p.delivery_location, p.date_send, p.po_total
INTO v_Vendor_ID, v_Vendor_Name, v_PO_Requestor, v_DeliveryAddress1, d_PO_Request_Date, v_PO_Amount
FROM po_info@polite p
-- POLite POs have an extraneous leading digit which needs to be removed
WHERE p.ponumber = substr(p_PO_ID, -6);
COMMIT;
EXECUTE IMMEDIATE 'alter session close database link polite';
gv_Title := 'POLite Information on PO Number ' || substr(p_PO_ID, -6);
EXCEPTION
WHEN OTHERS THEN
gv_Title := 'No Information on PO: ' || trim(p_PO_ID);
END;
END;
END;
-- Web Page HEAD
htp.p('');
htp.htmlOpen;
htp.headOpen;
--htp.p('');
-- If the session is bad, then return
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
-- If the PO is blank, then return
IF totals_util.bad_login(p_session_id) THEN
htp.p('');
RETURN;
END IF;
-- Set the webpage title
htp.title(ctitle => 'UCRFStotals - ' || gv_Title);
htp.p('
');
htp.headClose;
-- Declare RICO, Prototype Javascript functions
htp.p('
');
htp.bodyOpen(cattributes => 'onload="javascript:bodyOnLoad()" ');
-- Table for graphic
htp.comment('BEGIN table for UCRFStotals title graphic');
htp.tableOpen(cattributes => 'width="100%" border="0" cellpadding="0" cellspacing="0"');
htp.tableRowOpen;
htp.p('
PO Header and Line Information
for:
2248940
- KONG Consulting FY05-06
Order
7432
Requestor
LINDAGU
Vendor
U000021525
KONG CONSULTING INC
User Contact
Josee Larochelle
Transactor
LINDAGU
Type
P
Buyer
220
Payment Totals
38700.00
Change User
LINDAGU
Date Needed
2/22/2006
Expected Delivery
7/29/2005
');
htp.tableOpen(cborder => 0, calign => 'left', cattributes => 'width=700');
-- The table headers
htp.tableRowOpen();
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => ' ' );
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => 'Type' );
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => 'Status' );
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => 'Buyer' );
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => 'Order Description' );
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => 'Vendor' );
htp.tableHeader(cattributes => 'width="11" scope="col" class="resultgrid" ', cvalue => 'Total' );
htp.tableRowClose;
-- The table data
-- Loop thru the data and display the information
n_RowCounter := 1;
FOR CPOrec IN crsr_DisplayPOHeaderLines(p_PO_ID) LOOP
htp.tableRowOpen(cattributes => 'class="resultgrid" ');
htp.tableHeader(cvalue => n_RowCounter, cattributes => 'scope="row" class="resultgrid" ');
htp.tableData(CPOrec.Po_Type, cattributes => 'class="resultgrid" ');
htp.tableData(CPOrec.Status, cattributes => 'class="resultgrid" ');
IF CPOrec.Buyer_Number IS NOT NULL THEN
htp.tableData(CPOIDrec.Buyer_Number, cattributes => 'class="resultgrid" ');
ELSE
htp.tableData(' ', cattributes => 'class="resultgrid" ');
END IF;
htp.tableData(CPOrec.Order_Description, cattributes => 'class="resultgrid" ');
htp.tableData(CPOrec.Vendor_Name, cattributes => 'class="resultgrid" ');
htp.tableData(CPOrec.Order_Total, cattributes => 'class="resultgrid" ');
htp.tableRowClose;
n_RowCounter := n_RowCounter + 1;
END LOOP;
htp.tableClose;
*\
htp.bodyClose;
htp.htmlClose;
EXCEPTION
-- Catch any errors
WHEN OTHERS THEN
SELECT SEQ_ERR_MSG.NEXTVAL
INTO v_ErrMsgValue
FROM dual;
-- INSERT INTO totals_err_msgs VALUES (v_ErrMsgValue, SYSDATE, );
-- htp.p(DBMS_APPLICATION_INFO.read_client_info(client_info => '') );
-- dbms_session.list_context();
v_PLSQL_LineNumber := $$PLSQL_LINE;
V_PLSQL_Package := $$PLSQL_UNIT;
htp.p('An error occured on this page. See package: ' || V_PLSQL_Package || ', on line: '|| v_PLSQL_LineNumber || '. Please see the Error Messages table for more information, [' || v_ErrMsgValue || '] ');
-- htp.p(dbms_utility.get_time);
END;*/
-- -------------------------------------------------------------------------------------
-- Procedure: Execute Query
-- Programmer: Luis Baquera ?
-- Description: Given that the user has made their selections, run their query
--
-- Modifications:
-- Programmer: Brian Griffin
-- Date: Jan 2, 2007
-- Purpose: Added tooltips Based on what data is being returned
--
-- Modifications:
-- Programmer: Brian Griffin
-- Date: Jan 30, 2007
-- Purpose: Instrumented the code using DBMS_APPLICATION_INFO.SET_MODULE();
-- This allows the DBA to query session_longops to view the progress in case of long running queries
-- -------------------------------------------------------------------------------------
PROCEDURE execute_query(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_action IN varchar2 DEFAULT NULL,
p_clause IN varchar2 default null,
p_dd_query IN LONG default NULL) IS
nStart number;
nPos number;
v_UCRFS_QUERY totals_settings.ucrfs_query%TYPE;
v_FIELDS long;
v_Ledgers totals_settings.ledgers%TYPE;
v_query_type totals_settings.query_type%TYPE;
v_USER_ID totals_settings.user_id%TYPE;
v_separate_columns totals_settings.separate%TYPE;
v_source totals_settings.sources%TYPE;
v_count integer :=0;
rowCnt integer :=0; -- row counter
label integer :=0; -- a label for the row number
ddl_cursor integer :=0; -- SQL cursor
rows_processed integer :=0; -- number of rows processed
v_data varchar2(4000); -- Current data from SQL statement to be printed out
v_friendly totals_field_lookup.user_friendly%TYPE; -- Friendly name of current field
sField varchar2(100);
v_CurrentField varchar2(1000) := ''; -- Current field being analyzed
v_dd_fields long; -- drilldown fields
v_Drilldown_Clause LONG DEFAULT '';
-- Final row for grand total amounts
n_SumAmount NUMBER(17,2); -- journal_tbl.foreign_amount%TYPE DEFAULT 0; -- Sum the amount column for a final row
v_PrepareAmount NUMBER(17,2); -- journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumTEMPAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumPERMAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumACTUALSAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumFTEAmount NUMBER DEFAULT 0;
n_SumRECORDSAmount NUMBER DEFAULT 0;
-- Column positions
n_ColAmount INTEGER DEFAULT 1;
n_ColTEMPAmount INTEGER DEFAULT 1;
n_ColPERMAmount INTEGER DEFAULT 1;
n_ColACTUALSAmount INTEGER DEFAULT 1;
n_ColFTEAmount INTEGER DEFAULT 1;
n_ColRECORDSAmount INTEGER DEFAULT 1;
n_TotalColumns INTEGER DEFAULT 1;
v_Journal_ID journal_tbl.journal_id%TYPE DEFAULT ''; -- The current journal ID
-- Added by Brian for Encumbrance related queries (note: f/by is short for followed by:
--v_RegExpColumnAliases VARCHAR2(50) DEFAULT ' "[A-Za-z_]+"'; -- match a space f/by a " f/by 1 or more characters f/by underscore f/by another "
--v_RegExpDECODE VARCHAR2(50) DEFAULT 'DECODE\([jJ]\.LEDGER.+\)'; -- match the DECODE(J.LEDGER blah ) stuff
--n_CountFields NUMBER DEFAULT 0;
v_rowclass VARCHAR2(60) DEFAULT ' class="tabledatarow" '; -- for alternating row colors
v_HeaderClass VARCHAR2(60) DEFAULT ' class="tablehead" '; -- for table column headers
-- Variables for instrumenting this procedure
i_longops_row BINARY_INTEGER := dbms_application_info.set_session_longops_nohint;
i_slno BINARY_INTEGER;
v_SumDrillDown VARCHAR2(200); -- a string for adding the onclick event for summary drilldown rows
-- A timer feature
t_StartTime timestamp(1) ;
t_EndTime timestamp(1) ;
BEGIN
-- Check login status
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
-- Collect various variables
BEGIN
SELECT trim(ts.ledgers), trim(ts.selected_fields), trim(ts.query_type), trim(ts.user_id), trim(ts.separate)
INTO v_Ledgers, v_fields, v_query_type, v_user_id, v_separate_columns
FROM totals_settings ts
WHERE ts.session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
--htp.p('p_action = ' || p_action);
-- extend the transfer time from 1 minute to 5 minutes
UTL_HTTP.set_transfer_timeout(60*15);
-- A p_action of null means the user is running a normal non-ENCUMB query
IF p_action IS NULL THEN
-- Determine if the ENCUMB ledger was selected and if so, go to that procedure to generate the query
-- IF v_Ledgers IS NULL OR INSTR(v_Ledgers, 'ENCUMB') > 0 THEN
-- v_UCRFS_QUERY := totals_util.gen_detail_encumb_query(p_session_id => p_session_id);
-- b_ENCUMBQuery := TRUE;
-- If not an ENCUMB query, then generate the SQL per usual...
--ELSE
dbms_application_info.set_action( 'Generating UCRFStotals query' );
-- Generate and return the sql string that represents the user's query
v_ucrfs_query := totals_util.generate_query(p_session_id => p_session_id);
--END IF;
-- Reordering the data based on a column selection
ELSIF p_action = 'reorder' THEN
IF p_dd_query IS NULL THEN
BEGIN
SELECT ucrfs_query
INTO v_ucrfs_query
FROM totals_settings
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
ELSE
v_UCRFS_QUERY := p_dd_query;
END IF;
-- Drilldown into a row of data. The parameter p_clause contains the fully qualified detail drilldown WHERE clause
ELSIF p_action = 'p_drilldown' THEN -- Was 'dd'
dbms_application_info.set_action( 'Collecting drilldown data' );
BEGIN
SELECT trim(ts.drilldown_fields)
INTO v_fields
FROM totals_settings ts
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
v_query_type := 'D';
-- If the user did not select any drilldown fields, then assume all fields
IF v_fields IS NULL OR v_fields = ',' THEN
-- v_fields := 'j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, j.LEDGER, j.JOURNAL_ID, j.JOURNAL_DATE, j.SOURCE, j.ACCOUNT, j.DEPTID, j.FUND_CODE, j.PROGRAM_CODE, j.APPROPRIATION_NBR, j.PROJECT_ID, j.LINE_DESCR, j.JRNL_LN_REF, j.TRANSACTION_CLASS, j.TRANSACTION_TYPES, j.FOREIGN_AMOUNT, j.STATISTIC_AMOUNT,';
v_fields := declarations.gk_DRILLDOWN_FIELDS;
UPDATE totals_settings
SET drilldown_fields = v_fields
WHERE session_id = p_session_id;
COMMIT;
END IF;
nStart := 1;
nPos := instr(v_fields, ', ');
WHILE nPos > 0 LOOP
sField := substr(v_FIELDS, nStart, nPos - nStart);
IF sField = 'j.JOURNAL_DATE' THEN
v_dd_fields := v_dd_fields || 'TO_CHAR(' || sField || ',''MM/DD/YYYY''), ';
ELSIF sField = 'j.ACCOUNTING_PERIOD' THEN
v_dd_fields := v_dd_fields || 'LPAD(' || sField || ',3,''0''), ';
ELSIF sField = 'j.FOREIGN_AMOUNT' OR sField = 'j.STATISTIC_AMOUNT' THEN
v_dd_fields := v_dd_fields || 'TO_CHAR('||sField ||',''99999999999D99'','' NLS_NUMERIC_CHARACTERS = ''''.,'''' NLS_CURRENCY = ''''$''''''), ';
ELSE
v_dd_fields := v_dd_fields || sField || ', ';
END IF;
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP;
-- If no values for v_dd_fields were found, then show all possible
IF trim(v_dd_fields) IS NULL THEN
v_ucrfs_query := 'SELECT j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, j.LEDGER, j.JOURNAL_ID, j.JOURNAL_DATE, j.SOURCE, j.ACCOUNT, j.DEPTID, j.FUND_CODE, j.PROGRAM_CODE, j.APPROPRIATION_NBR, j.PROJECT_ID, j.LINE_DESCR, j.JRNL_LN_REF, j.TRANSACTION_CLASS, j.TRANSACTION_TYPES, j.FOREIGN_AMOUNT, j.STATISTIC_AMOUNT FROM JRNL_PURCHAS_VW j ' || p_clause;
ELSE
v_ucrfs_query := 'SELECT ' || rtrim(v_dd_fields, ', ') || ' FROM JRNL_PURCHAS_VW j ' || p_clause;
END IF;
--htp.p(' v_ucrfs_query = ' || v_ucrfs_query);
--RETURN;
/* htp.br;htp.p;
htp.p('v_UCRFS_QUERY = ' || v_UCRFS_QUERY);
htp.br;htp.p;
htp.p('p_session_id = ' || p_session_id);
htp.br;htp.p;
htp.p('p_action = ' || p_action);
htp.br;htp.p;
htp.p('p_clause = ' || p_clause);
htp.br;htp.p;
htp.p('p_dd_query = ' || p_dd_query);
htp.br;htp.p; */
ELSIF p_action = 'dd_reorder' THEN
v_query_type := 'D';
v_UCRFS_QUERY := p_dd_query;
END IF; --IF p_action IS NULL THEN
-- Instrumenting the procedure
dbms_application_info.set_module(module_name => 'execute_query', action_name => 'STARTING');
-- htp.p('');
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.p('');
-- If the variable does not contain any fields, we may want to prevent them from running the query
IF length(trim(v_fields)) < 2 THEN
htp.script(clanguage => 'javascript',
cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");
window.location.href="totals_tabs.standard_fields?p_session_id='||p_session_id||'"; ');
RETURN;
END IF;
-- Set the webpage title
IF instr(p_action, 'p_drilldown') <> 0 THEN
htp.title(ctitle => 'UCRFStotals - Drilldown Detail Query Results');
ELSE
htp.title(ctitle => 'UCRFStotals - Query Results');
END IF;
-- Get the CSS information
totals_dhtml.get_CSS(p_session_id, 'RESULT_GRID');
-- Javascript for sorting a table by clicking on the table header
htp.p('');
htp.headClose;
-- Get the javascript functions for the result grid
totals_dhtml.get_resultgrid_js(p_action, v_USER_ID, v_UCRFS_QUERY, p_session_id);
htp.bodyOpen(cbackground => 'white', cattributes => 'topmargin=0 leftmargin=0');
-- Declare Javascript functions
totals_dhtml.get_tooltip_js(p_session_id);
totals_dhtml.get_drilldown_js(p_session_id);
-- Get the
');
htp.tableRowOpen;
-- IF p_action <> 'p_drilldown' THEN
-- Make a determine of whether this is an ENCUMB query or not
-- Parse thru the variable v_UCRFS_QUERY and
-- strip out the SELECT clause's fields in order to work with the individual fields
-- Then parse thru those fields and do a look up in the Friendly Field table (totals_field_lookup)
-- to get the user-friendly name to use as a column header
/* IF b_ENCUMBQuery = TRUE THEN
-- A bit confusing here... In order to use the ENCUMB query which is a UNION ALL type of statement
-- the columns must have alias names. But these alias names confuse the parsing below which tries to
-- do a lookup in the Friendly Fields table based on the SELECT's fields names, ie: J.JOURNALID, etc
-- Thus, regular expressions are used to strip out the column alias and just return the field names
-- Remove the preceding SELECT DISTINCT
v_FIELDS := substr(v_UCRFS_QUERY, LENGTH('SELECT DISTINCT '), LENGTH(v_UCRFS_QUERY));
-- Remove everything including and after the FROM statement
v_FIELDS := ltrim(substr(v_FIELDS, 1, instr(v_FIELDS, 'FROM')-2)) || ', ';
-- Strip out any pattern that matches the v_RegExpColumnAliases variable, such as "JOURNAL_ID"
v_FIELDS := REGEXP_REPLACE(v_FIELDS, v_RegExpColumnAliases, '');
-- Strip out any DECODE(J.LEDGER, blah) stuff and replace it with J.FOREIGN_AMOUNT instead
v_FIELDS := REGEXP_REPLACE(v_FIELDS, v_RegExpDECODE, 'J.FOREIGN_AMOUNT');
-- Replace the last 0 which represents the ENCUMB Amount in the other part of the SQL statement
v_FIELDS := replace(v_FIELDS, ', 0', ', J.FOREIGN_AMOUNT');
-- A useful trick to count the number of occurances of a comma
-- Get the length of the string (without any spaces) minus the length of the string without any spaces or delimiters (a comma)
SELECT (LENGTH(REPLACE(v_FIELDS, ' ', '')) - LENGTH(REPLACE(upper(REPLACE(v_FIELDS, ' ', '')), upper(','), ''))) / LENGTH(',')
INTO n_CountFields
FROM dual;
*/
-- Per usual query
--ELSE
v_FIELDS := substr(v_ucrfs_query, LENGTH('SELECT '), LENGTH(v_UCRFS_QUERY));
v_FIELDS := ltrim(substr(v_FIELDS, 1, instr(v_FIELDS, 'FROM')-2)) || ', ';
--END IF;
-- END IF;
--htp.p('v_ucrfs_query = ' || v_ucrfs_query ||' ');
--htp.p('/2/ v_fields = ' || v_fields ||' ');
-- For now the STATS button is disabled since the sorttable.js program erases all the radio buttons
-- in the column headers. These radio buttons are used to determine which column the user wants stats on
-- Header for checkboxes used for Stats
/* htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => 'Stats',
cattributes => v_rowclass || 'valign="top" width="5px" ');
*/ htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => 'Row',
cattributes => v_rowclass || 'valign="top" width="10px" ');
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- If v_Fields is just a comma, then the user didn't actually select any fields to display
IF TRIM(v_fields) = ',' THEN
-- Clean up and reset MODULE and ACTION as we exit.
dbms_application_info.set_module( null,null );
--htp.script(clanguage => 'javascript',
-- cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");
-- window.location.href="totals_tabs.standard_fields?p_session_id='||p_session_id||'"; ');
htp.script(clanguage => 'javascript',
cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");');
ELSE
-- Start the timer
t_StartTime := systimestamp;
-- Loop thru the selected fields and start creating the column headers
WHILE nPos > 0 LOOP
dbms_application_info.set_action( 'Creating column headers' );
v_count := v_count + 1;
v_data := substr(v_FIELDS, nStart, nPos - nStart);
-- If the current piece of data contains 'DECODE(j.LEDGER,' then we are using split columns for the PERM/TEMP/PERM amounts and the ENCUMB amounts
--IF instr(v_data, 'ENCUMB') <> 0 THEN
-- v_friendly := 'Encumbered Amount';
--IF instr(v_data, 'PERM') <> 0 THEN
-- v_friendly := 'Amount';
-- If LPAD is in the SQL, then remove it
IF instr(v_data, 'LPAD') <> 0 THEN
v_data := substr(v_data, LENGTH('LPAD(')+1, LENGTH(v_data));
-- Remove the trailing )
v_data := substr(v_data, 1, instr(v_data, ',')-1) || ' ';
-- If TO_CHAR is in the SQL, then remove it
ELSIF instr(v_data, 'TO_CHAR') <> 0 THEN
v_data := substr(v_data, LENGTH('TO_CHAR(')+1, LENGTH(v_data));
-- Remove the trailing )
v_data := substr(v_data, 1, instr(v_data, ',')-1) || ' ';
END IF;
-- Get the "friendly" name of the field in question
BEGIN
SELECT user_friendly
INTO v_friendly
FROM totals_field_lookup
-- WHERE table_field /*v_friendly:*/= upper(rtrim(ltrim(ltrim(v_data), 'j.'), ', '));
WHERE table_field = replace(UPPER(trim(v_data)), 'J.', '');
EXCEPTION
WHEN OTHERS THEN
htp.p('There was a problem finding this field: '|| v_data || '. The most likely solution is to update the totals_field_lookup table');
htp.br;
END;
-- If we are drilling down
IF instr(p_action, 'p_drilldown') <> 0 THEN
IF instr(upper(v_friendly), 'TOTAL') <> 0
OR instr(upper(v_friendly), 'TEMP') <> 0
OR instr(upper(v_friendly), 'PERM') <> 0
OR instr(upper(v_friendly), 'ACTUALS') <> 0
OR instr(upper(v_friendly), 'BALANCE') <> 0
--OR instr(upper(v_friendly), 'ENCUMB') <> 0
OR instr(upper(v_friendly), 'AMOUNT') <> 0 THEN
htp.tableHeader(calign => 'center',
cvalue => rtrim(v_friendly, ', ')||' ' || htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
-- cattributes => 'class="heading" valign="bottom" ');
cattributes => v_HeaderClass || 'valign="bottom" ');
ELSE
htp.tableHeader(calign => 'left',
cvalue => ''||rtrim(v_friendly, ', ')||' '||htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
END IF; --IF instr(upper(v_friendly), 'TOTAL') <> 0
-- Otherwise
ELSE
-- If the column name contains the following
IF instr(upper(v_friendly), 'TOTAL') <> 0
OR instr(upper(v_friendly), 'TEMP') <> 0
OR instr(upper(v_friendly), 'PERM') <> 0
OR instr(upper(v_friendly), 'ACTUALS') <> 0
OR instr(upper(v_friendly), 'BALANCE') <> 0
--OR instr(upper(v_friendly), 'ENCUMB') <> 0
OR instr(upper(v_friendly), 'AMOUNT') <> 0 THEN
htp.tableHeader(calign => 'CENTER',
cvalue => '' || rtrim(v_friendly, ', ') || ' ' ||
htf.formRadio(cname => 'p_column', cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
-- The following columns need to be narrow (ie: width="80px") since the column header is longer than the data contained
ELSE
IF INSTR(upper(v_friendly), 'PAN JOURNAL') <> 0
THEN
htp.tableHeader(calign => 'CENTER',
cvalue => ''||rtrim(v_friendly, ', ')||' ' ||
htf.formRadio(cname => 'p_column', cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" width="100px"');
ELSE
htp.tableHeader(calign => 'center',
cvalue => ''||rtrim(v_friendly, ', ')||' '||htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
END IF;
END IF;
END IF; --IF instr(p_action, 'p_drilldown') <> 0 THEN
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP; --WHILE nPos > 0 LOOP
END IF; --IF TRIM(v_FIELDS) = ',' THEN
htp.tableRowClose;
-- Check for broadness of criteria
IF totals_util.check_broad(p_session_id) THEN
dbms_application_info.set_action( 'Defining and opening cursor' );
BEGIN
ddl_cursor := dbms_sql.open_cursor;
dbms_sql.parse(ddl_cursor, v_ucrfs_query, dbms_sql.native);
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_Message => 'Problem with dbms_sql.parse; v_ucrfs_query = ' || v_ucrfs_query || ' v_dd_fields = ' || v_dd_fields || ' v_fields = ' || v_fields);
RETURN;
END;
-- Loop thru all the fields and define their columns
FOR i IN 1..v_count LOOP
dbms_sql.define_column(ddl_cursor, i, v_data, 1000);
END LOOP;
--HTP.p('(there are ' || v_count || ' data columns)');
BEGIN
rows_processed := dbms_sql.execute(ddl_cursor);
EXCEPTION
WHEN NO_DATA_NEEDED THEN
htp.p('No more data needed. ');
END;
rowCnt := 0;
-- Loop thru all the sql rows and create an HTML table row for the data
LOOP
dbms_application_info.set_action( 'Looping thru data' );
-- Clear out and reconstruct the drilldown clause for this row
v_Drilldown_Clause := ' ';
IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
label := rowCnt;
rowCnt := rowCnt + 1;
-- Record progress in session_longops
dbms_application_info.set_session_longops(
rindex => i_longops_row,
slno => i_slno,
op_name => 'LOOPING THRU QUERY DATA',
target => 0,
context => 0,
sofar => rowCnt,
totalwork => dbms_sql.last_row_count,
target_desc => 'Using data: ' || v_data,
units => 'rows of data'
);
-- If a summary query, then highlight the row?
IF v_query_type = 'S' THEN
htp.tableRowOpen(cattributes => 'onmouseover=mouseover(this); onmouseout=mouseout(this);');
ELSE
htp.tableRowOpen;
END IF;
-- Alternating row colors
IF rowCnt MOD 2 = 0 THEN
v_rowclass := ' id="datarow" class="tabledatarow" ';
ELSE
v_rowclass := ' id="datarow" class="tabledatarowlight" ';
END IF;
-- The checkbox and row number
-- For now the STATS button is disabled since the sorttable.js program erases all the radio buttons
-- in the column headers. These radio buttons are used to determine which column the user wants stats on
/* htp.tableData(calign => 'center',
cvalue => htf.formCheckbox(cname => 'p_rows',cvalue => rowCnt),
cattributes => v_rowclass);
*/ htp.tableData(calign => 'center',
cvalue => rowCnt,
cattributes => v_rowclass);
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- Loop thru all the columns and create a HTML table cell and place the data there
FOR i IN 1..v_count LOOP
-- The current field in the v_FIELDS variable
v_CurrentField := substr(v_FIELDS, nStart, nPos - nStart);
dbms_sql.column_value(ddl_cursor, i, v_data);
v_data := RTRIM(LTRIM(v_data));
-- If the data returned has no real value
IF v_data = '' OR v_data IS NULL THEN
v_data := ' ';
-- If a summary query, then assign an onClick event for drilling down??
IF v_query_type = 'S' THEN
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass || ' onclick="drilldown_row(this,'|| label ||');"');
-- Detail query
ELSE
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass);
END IF;
-- Otherwise, check for the query type
ELSE
-- For summary
CASE v_query_type
WHEN 'S' THEN
-- Used to drilldown on summary rows of data
v_SumDrillDown := ' ';
ELSE
v_SumDrillDown := '';
END CASE;
-- If the current field is a PO number, then create a link to drilldown into the WAREHOUSE_HEADER for eBuy POs
-- or subpo@devdb / po_info@devdb for legacy POs
IF instr(upper(v_CurrentField), 'PO_ID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
-- Was cvalue => '' || htf.escape_sc(v_data) || '',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is a journal id, then create a link to drilldown into the journal_tbl table
ELSIF instr(upper(v_CurrentField), 'JOURNAL_ID') <> 0 THEN
htp.tableData(calign => 'center',
-- WAS: cvalue => '' || v_data || '',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Save the current journal ID
v_Journal_ID := v_data;
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is a journal line number, then create a tooltip for PAN information
ELSIF instr(upper(v_CurrentField), 'JOURNAL_LINE') <> 0 THEN
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass );
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
ELSIF instr(upper(v_CurrentField), 'VENDOR_ID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
ELSIF instr(upper(v_CurrentField), 'VOUCHER_ID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
-- Was: cvalue => '' || htf.escape_sc(v_data) || '',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is the source, then simply notate that for the Line Ref column in case it is SIS
ELSIF instr(upper(v_CurrentField), 'SOURCE') <> 0 THEN
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
v_source := v_data;
-- If the current field is an account number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'ACCOUNT') <> 0 AND instr(upper(v_CurrentField), 'ACCOUNTING') = 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || ' style="cursor:hand" ');
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an activity number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'DEPTID') <> 0 AND instr(upper(v_CurrentField), 'DESCR') = 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an fund number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'FUND_CODE') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an function number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'PROGRAM_CODE') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an cost center then add a tooltip
ELSIF instr(upper(v_CurrentField), 'APPROPRIATION_NBR') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is the Journal Line Ref then add a tooltip for SIS data
ELSIF instr(upper(v_CurrentField), 'JRNL_LN_REF') <> 0 THEN
-- If this is a SIS Journal Create the table cell element
IF instr(v_source, 'SIS') > 0 THEN
htp.tableData(calign => 'center',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- Otherwise, don't include a hyperlink for drilling down on SIS detail information
ELSE
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
END IF;
-- Left align description columns
ELSIF instr(upper(v_CurrentField), 'DESC') <> 0 THEN
htp.tableData(calign => 'left',
cvalue => htf.escape_sc(v_data) ,
cattributes => v_rowclass);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- Right align amount columns
ELSIF INSTR(upper(v_CurrentField), 'J.FOREIGN_AMOUNT') <> 0 THEN
-- Strip out extraneous characters for doing a sum
--v_PrepareAmount := replace(v_data, '$', '');
--v_PrepareAmount := replace(v_PrepareAmount, ',', '');
BEGIN
v_PrepareAmount := replace(v_data, ',', '');
n_SumAmount := n_SumAmount + v_PrepareAmount;
EXCEPTION WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_Message => 'v_data = ' || v_data);
RETURN;
END;
-- Remember the column number
n_ColAmount := i;
htp.tableData(calign => 'right',
cvalue => to_char(htf.escape_sc(v_PrepareAmount), declarations.gk_MONEYFORMAT),
-- cvalue => htf.escape_sc(v_PrepareAmount),
cattributes => v_rowclass);
-- Perm Amounts
ELSIF INSTR(upper(v_CurrentField), 'PERM') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumPERMAmount := n_SumPermAmount + v_PrepareAmount;
-- Remember the column number
n_ColPERMAmount := i;
htp.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Temp Amounts (excluding the BALANCE which is TEMP - ACTUALS in the alias table)
ELSIF INSTR(upper(v_CurrentField), 'TEMP') <> 0 AND INSTR(upper(v_CurrentField), 'ACTUALS') = 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumTEMPAmount := n_SumTEMPAmount + v_PrepareAmount;
-- htp.p(' = ' || v_CurrentField);
-- Remember the column number
n_ColTEMPAmount := i;
htp.tableData(calign => 'right',
--cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Actuals Amounts
ELSIF INSTR(upper(v_CurrentField), 'ACTUALS') <> 0 AND INSTR(upper(v_CurrentField), 'TEMP') = 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumACTUALSAmount := n_SumACTUALSAmount + v_PrepareAmount;
-- Remember the column number
n_ColACTUALSAmount := i;
htp.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Total FTE
ELSIF INSTR(upper(v_CurrentField), 'STATISTIC_AMOUNT') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumFTEAmount := n_SumFTEAmount + v_PrepareAmount;
-- Remember the column number
n_ColFTEAmount := i;
htp.tableData(calign => 'right',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass || v_SumDrillDown);
-- Total Records
ELSIF INSTR(upper(v_CurrentField), 'COUNT(*)') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumRECORDSAmount := n_SumRECORDSAmount + v_PrepareAmount;
-- Remember the column number
n_ColRECORDSAmount := i;
htp.tableData(calign => 'right',
cvalue => '' ||
'
',
cattributes => v_rowclass ); --|| 'style="cursor:hand" onclick="summary_drilldown(this,'|| label ||');"' );
ELSE
htp.tableData(calign => 'center',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
--htp.p('v_CurrentField = ' || v_CurrentField);
END IF; --IF instr(upper(v_CurrentField), 'PO_ID') <> 0 THEN
-- END IF; --IF v_query_type = 'S' THEN
END IF; --IF v_data = '' OR v_data IS NULL THEN
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
-- DEBUG: htp.p('v_CurrentField = ' || v_CurrentField);
n_TotalColumns := i;
END LOOP; --FOR i IN 1..v_count LOOP
-- htp.tableData(cvalue => v_Drilldown_Clause, cattributes => 'style="visibility: hidden" ');
htp.tableRowClose;
ELSE
EXIT;
END IF; -- IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
END LOOP; -- Loop thru all the sql rows and create an HTML table row for the data
-- End the timer
t_EndTime := systimestamp;
/*
--IF n_SumAmount <> 0 THEN
-- A final summary row
IF v_query_type = 'S' THEN
-- Summary queries have an additional column at the end for Total Rows
htp.tableData(ccolspan => v_count -1 , cattributes => 'class="tablehead"' );
htp.tableData(cvalue => 'Grand Totals:', ccolspan => '1', cattributes => 'class="tablehead"' );
ELSE
htp.tableData(ccolspan => v_count, cattributes => 'class="tablehead"' );
htp.tableData(cvalue => 'Grand Total:', ccolspan => '1', cattributes => 'class="tablehead"' );
END IF; -- IF v_query_type = 'S' THEN
htp.tableData(calign => 'right',
cvalue => to_char(n_SumAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
htp.tableRowClose;
-- END IF; --IF n_SumAmount <> 0 THEN
*/
/* -- A new small table for just the grandtotals. This is meant to be a separate table from the above results grid .
-- htp.tableOpen;
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- When separating columns, shave off three for the TEMP, PERM and ACTUALS columns
IF v_separate_columns = 1 THEN
htp.tableData(ccolspan => v_count-3 , cattributes => 'class="tablehead"' );
ELSE
htp.tableData(ccolspan => n_ColAmount+1 , cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
END IF; -- IF v_separate_columns = 1 THEN
-- Loop thru all the columns and create a HTML table cell and place the data there
FOR i IN 1..v_count LOOP
-- The current field in the v_FIELDS variable
v_CurrentField := substr(v_FIELDS, nStart, nPos - nStart);
-- Perm Amounts
IF INSTR(upper(v_CurrentField), 'PERM') <> 0 THEN
htp.tableData(calign => 'right',
cvalue => to_char(n_SumPERMAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
-- Temp Amounts
ELSIF INSTR(upper(v_CurrentField), 'TEMP') <> 0 THEN
htp.tableData(calign => 'right',
cvalue => to_char(n_SumTEMPAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
-- Actuals Amounts
ELSIF INSTR(upper(v_CurrentField), 'ACTUALS') <> 0 THEN
htp.tableData(calign => 'right',
cvalue => to_char(n_SumACTUALSAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
-- Total FTE
ELSIF INSTR(upper(v_CurrentField), 'STATISTIC_AMOUNT') <> 0 THEN
htp.tableData(calign => 'right',
cvalue => n_SumFTEAmount,
cattributes => 'class="tablehead"' );
-- Total Records
ELSIF INSTR(upper(v_CurrentField), 'COUNT(*)') <> 0 THEN
htp.tableData(calign => 'right',
cvalue => n_SumRECORDSAmount,
cattributes => 'class="tablehead"' );
ELSE
htp.tableData(calign => 'right',
cvalue => ' ',
cattributes => 'class="tablehead"' );
END IF; -- IF INSTR(upper(v_CurrentField), 'PERM') <> 0 THEN
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP; -- FOR i IN 1..v_count LOOP*/
dbms_sql.close_cursor(ddl_cursor);
ELSE
htp.script(clanguage => 'javascript',
cscript => 'alert("The current search selections are too broad.\nPlease select additional search criteria to narrow the search results.\nYou will now be redirected to the query tab.");
window.location.href="totals_tabs.query?p_session_id='||p_session_id||'";
');
END IF;
-- End of result grid
htp.p('');
htp.tableClose;
-- Grand Totals
htp.p(' Grand Totals:');
IF n_ColPERMAmount > 1 THEN
htp.p(' PERM: ' || to_char(n_SumPERMAmount, '$' || declarations.gk_MONEYFORMAT));
END IF;
-- TEMP column
IF n_ColTEMPAmount > 1 THEN
htp.p(' TEMP: ' || to_char(n_SumTEMPAmount, '$' || declarations.gk_MONEYFORMAT));
END IF;
-- ACTUALS column
IF n_ColACTUALSAmount > 1 THEN
htp.p(' ACTUALS: ' || to_char(n_SumACTUALSAmount, '$' || declarations.gk_MONEYFORMAT));
END IF;
-- BALANCE column
IF n_ColTEMPAmount > 1 AND n_ColACTUALSAmount > 1 THEN
htp.p(' BALANCE: ' || to_char(n_SumTEMPAmount - n_SumACTUALSAmount, '$' || declarations.gk_MONEYFORMAT));
END IF;
-- For Summary queries...
IF v_query_type = 'S' THEN
htp.p(' FTE: ' || to_char(n_SumFTEAmount));
htp.p(' Records: ' || to_char(n_SumRECORDSAmount));
END IF; -- IF v_query_type = 'S' THEN
/*
-- Grand totals
htp.tableRowOpen;
-- When separating columns, shave off three for the TEMP, PERM and ACTUALS columns
IF v_separate_columns = 1 THEN
htp.tableData(ccolspan => v_count-3 , cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumPERMAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumTEMPAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumACTUALSAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
ELSE
htp.tableData(ccolspan => n_ColAmount+1 , cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
END IF; -- IF v_separate_columns = 1 THEN
-- For Summary queries...
IF v_query_type = 'S' THEN
htp.tableData(calign => 'right',
cvalue => n_SumFTEAmount,
cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => n_SumRECORDSAmount,
cattributes => 'class="tablehead"' );
END IF; -- IF v_query_type = 'S' THEN
-- End of subtotal table
htp.tableRowClose;
htp.tableClose;*/
-- End of overall encompassing table
htp.p('');
htp.tableRowClose;
htp.tableClose;
CASE v_query_type
WHEN 'S' THEN
v_CurrentField := 'Summary ';
ELSE
v_CurrentField := 'Detail ';
END CASE;
htp.p('');
htp.formHidden(cname => 'rowCnt',cvalue => rowCnt);
htp.formClose;
htp.para;htp.br;htp.para;htp.br;htp.para;htp.br;htp.para;htp.br;htp.para;htp.br;
-- Tab footer information
totals_util.tab_footer(p_session_id);
htp.bodyClose;
htp.htmlClose;
-- Clean up and reset MODULE and ACTION as we exit.
dbms_application_info.set_module( null,null );
EXCEPTION
WHEN OTHERS THEN
-- htp.p('v_UCRFS_QUERY = ' || v_UCRFS_QUERY);
totals_util.error(p_session_id => p_session_id);
RETURN;
END execute_query;
-- -------------------------------------------------------------------------------------
-- Procedure: Execute Query into a CLOB
-- Programmer: Brian Griffin
-- Description: Given that the user has made their selections, run their query
--
-- Modifications:
-- Programmer: Brian Griffin
-- Date: Jan, 2008
-- Purpose: Use a CLOB
--
-- -------------------------------------------------------------------------------------
PROCEDURE exec_query_clob(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_action IN varchar2 DEFAULT NULL,
p_clause IN varchar2 default null,
p_dd_query IN LONG default NULL) IS
-- CLOB related variables
v_clob CLOB := EMPTY_CLOB;
v_blob bLOB := EMPTY_bLOB;
v_LineLength BINARY_INTEGER;
v_line_buffer VARCHAR2(4000) := '';
nStart number;
nPos number;
v_UCRFS_QUERY totals_settings.ucrfs_query%TYPE;
v_FIELDS long;
v_Ledgers totals_settings.ledgers%TYPE;
v_query_type totals_settings.query_type%TYPE;
v_USER_ID totals_settings.user_id%TYPE;
v_separate_columns totals_settings.separate%TYPE;
v_count integer :=0;
rowCnt integer :=0; -- row counter
label integer :=0; -- a label for the row number
ddl_cursor integer :=0; -- SQL cursor
rows_processed integer :=0; -- number of rows processed
v_data varchar2(4000); -- Current data from SQL statement to be printed out
v_friendly totals_field_lookup.user_friendly%TYPE; -- Friendly name of current field
sField varchar2(100);
v_CurrentField varchar2(1000) := ''; -- Current field being analyzed
v_dd_fields long; -- drilldown fields
v_Drilldown_Clause LONG DEFAULT '';
-- Final row for grand total amounts
n_SumAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- Sum the amount column for a final row
v_PrepareAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumTEMPAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumPERMAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumACTUALSAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumFTEAmount NUMBER DEFAULT 0;
n_SumRECORDSAmount NUMBER DEFAULT 0;
-- Column positions
n_ColAmount INTEGER DEFAULT 1;
n_ColTEMPAmount INTEGER DEFAULT 1;
n_ColPERMAmount INTEGER DEFAULT 1;
n_ColACTUALSAmount INTEGER DEFAULT 1;
n_ColFTEAmount INTEGER DEFAULT 1;
n_ColRECORDSAmount INTEGER DEFAULT 1;
n_TotalColumns INTEGER DEFAULT 1;
v_Journal_ID journal_tbl.journal_id%TYPE DEFAULT ''; -- The current journal ID
-- Added by Brian for Encumbrance related queries (note: f/by is short for followed by:
--v_RegExpColumnAliases VARCHAR2(50) DEFAULT ' "[A-Za-z_]+"'; -- match a space f/by a " f/by 1 or more characters f/by underscore f/by another "
--v_RegExpDECODE VARCHAR2(50) DEFAULT 'DECODE\([jJ]\.LEDGER.+\)'; -- match the DECODE(J.LEDGER blah ) stuff
--n_CountFields NUMBER DEFAULT 0;
v_rowclass VARCHAR2(60) DEFAULT ' class="tabledatarow" '; -- for alternating row colors
v_HeaderClass VARCHAR2(60) DEFAULT ' class="tablehead" '; -- for table column headers
-- Variables for instrumenting this procedure
i_longops_row BINARY_INTEGER := dbms_application_info.set_session_longops_nohint;
i_slno BINARY_INTEGER;
v_SumDrillDown VARCHAR2(200); -- a string for adding the onclick event for summary drilldown rows
-- A timer feature
t_StartTime timestamp(1) ;
t_EndTime timestamp(1) ;
BEGIN
-- Check login status
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
-- Create a CLOB to hold the data
dbms_lob.createtemporary(v_clob, TRUE);
dbms_lob.open(v_clob, dbms_lob.lob_readwrite);
-- Collect various variables
BEGIN
SELECT trim(ts.ledgers), trim(ts.selected_fields), trim(ts.query_type), trim(ts.user_id), trim(ts.separate)
INTO v_Ledgers, v_fields, v_query_type, v_user_id, v_separate_columns
FROM totals_settings ts
WHERE ts.session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
-- A p_action of null means the user is running a normal non-ENCUMB query
IF p_action IS NULL THEN
-- Generate and return the sql string that represents the user's query
v_ucrfs_query := totals_util.generate_query(p_session_id => p_session_id);
-- Reordering the data based on a column selection
ELSIF p_action = 'reorder' THEN
IF p_dd_query IS NULL THEN
BEGIN
SELECT ucrfs_query
INTO v_ucrfs_query
FROM totals_settings
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
ELSE
v_UCRFS_QUERY := p_dd_query;
END IF;
-- Drilldown into a row of data. The parameter p_clause contains the fully qualified detail drilldown WHERE clause
ELSIF p_action = 'p_drilldown' THEN -- Was 'dd'
BEGIN
SELECT trim(ts.drilldown_fields)
INTO v_fields
FROM totals_settings ts
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
v_query_type := 'D';
-- If the user did not select any drilldown fields, then assume all fields
IF v_fields IS NULL OR v_fields = ',' THEN
v_fields := 'j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, j.LEDGER, j.JOURNAL_ID, j.JOURNAL_DATE, j.SOURCE, j.ACCOUNT, j.DEPTID, j.FUND_CODE, j.PROGRAM_CODE, j.APPROPRIATION_NBR, j.PROJECT_ID, j.LINE_DESCR, j.JRNL_LN_REF, j.TRANSACTION_CLASS, j.TRANSACTION_TYPES, j.FOREIGN_AMOUNT, j.STATISTIC_AMOUNT,';
UPDATE totals_settings
SET drilldown_fields = v_fields
WHERE session_id = p_session_id;
COMMIT;
END IF;
nStart := 1;
nPos := instr(v_fields, ', ');
WHILE nPos > 0 LOOP
sField := substr(v_FIELDS, nStart, nPos - nStart);
IF sField = 'j.JOURNAL_DATE' THEN
v_dd_fields := v_dd_fields || 'TO_CHAR(' || sField || ',''MM/DD/YYYY''), ';
ELSIF sField = 'j.ACCOUNTING_PERIOD' THEN
v_dd_fields := v_dd_fields || 'LPAD(' || sField || ',3,''0''), ';
ELSIF sField = 'j.FOREIGN_AMOUNT' OR sField = 'j.STATISTIC_AMOUNT' THEN
v_dd_fields := v_dd_fields || 'TO_CHAR('||sField ||',''99999999999D99'','' NLS_NUMERIC_CHARACTERS = ''''.,'''' NLS_CURRENCY = ''''$''''''), ';
ELSE
v_dd_fields := v_dd_fields || sField || ', ';
END IF;
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP;
-- If no values for v_dd_fields were found, then show all possible
IF trim(v_dd_fields) IS NULL THEN
v_ucrfs_query := 'SELECT j.FISCAL_YEAR, j.ACCOUNTING_PERIOD, j.LEDGER, j.JOURNAL_ID, j.JOURNAL_DATE, j.SOURCE, j.ACCOUNT, j.DEPTID, j.FUND_CODE, j.PROGRAM_CODE, j.APPROPRIATION_NBR, j.PROJECT_ID, j.LINE_DESCR, j.JRNL_LN_REF, j.TRANSACTION_CLASS, j.TRANSACTION_TYPES, j.FOREIGN_AMOUNT, j.STATISTIC_AMOUNT FROM JRNL_PURCHAS_VW j ' || p_clause;
ELSE
v_ucrfs_query := 'SELECT ' || rtrim(v_dd_fields, ', ') || ' FROM JRNL_PURCHAS_VW j ' || p_clause;
END IF;
ELSIF p_action = 'dd_reorder' THEN
v_query_type := 'D';
v_UCRFS_QUERY := p_dd_query;
END IF; --IF p_action IS NULL THEN
v_line_buffer := htf.plaintext(ctext => DECLARATIONS.gk_DOCTYPE);
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.htmlOpen;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.headOpen;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.plaintext('');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- If the variable does not contain any fields, we may want to prevent them from running the query
IF length(trim(v_fields)) < 2 THEN
v_line_buffer := htf.script(clanguage => 'javascript',
cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");
window.location.href="totals_tabs.standard_fields?p_session_id='||p_session_id||'"; ');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
RETURN;
END IF;
-- Set the webpage title
IF instr(p_action, 'p_drilldown') <> 0 THEN
v_line_buffer := htf.title(ctitle => 'UCRFStotals - Drilldown Detail Query Results');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
ELSE
v_line_buffer := htf.title(ctitle => 'UCRFStotals - Query Results');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
END IF;
-- Get the CSS information
-- v_line_buffer := totals_dhtml.get_CSS(p_session_id, 'RESULT_GRID');
--v_LineLength := length(v_line_buffer);
--dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Javascript for sorting a table by clicking on the table header
v_line_buffer :=htf.plaintext('');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer :=htf.headClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Get the javascript functions for the result grid
-- v_line_buffer :=totals_dhtml.get_resultgrid_js(p_action, v_USER_ID, v_UCRFS_QUERY, p_session_id);
--v_LineLength := length(v_line_buffer);
--dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.bodyOpen(cbackground => 'white', cattributes => 'topmargin=0 leftmargin=0');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Declare Javascript functions
-- v_line_buffer := totals_dhtml.get_tooltip_js(p_session_id);
--v_LineLength := length(v_line_buffer);
--dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- v_line_buffer := totals_dhtml.get_drilldown_js(p_session_id);
--v_LineLength := length(v_line_buffer);
--dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Get the
');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.tableRowOpen;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_FIELDS := substr(v_ucrfs_query, LENGTH('SELECT '), LENGTH(v_UCRFS_QUERY));
v_FIELDS := ltrim(substr(v_FIELDS, 1, instr(v_FIELDS, 'FROM')-2)) || ', ';
v_line_buffer := htf.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => 'Row',
cattributes => v_rowclass || 'valign="top" width="10px" ');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- If v_Fields is just a comma, then the user didn't actually select any fields to display
IF TRIM(v_fields) = ',' THEN
v_line_buffer := htf.script(clanguage => 'javascript',
cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
ELSE
-- Loop thru the selected fields and start creating the column headers
WHILE nPos > 0 LOOP
v_count := v_count + 1;
v_data := substr(v_FIELDS, nStart, nPos - nStart);
IF instr(v_data, 'LPAD') <> 0 THEN
v_data := substr(v_data, LENGTH('LPAD(')+1, LENGTH(v_data));
-- Remove the trailing )
v_data := substr(v_data, 1, instr(v_data, ',')-1) || ' ';
-- If TO_CHAR is in the SQL, then remove it
ELSIF instr(v_data, 'TO_CHAR') <> 0 THEN
v_data := substr(v_data, LENGTH('TO_CHAR(')+1, LENGTH(v_data));
-- Remove the trailing )
v_data := substr(v_data, 1, instr(v_data, ',')-1) || ' ';
END IF;
-- Get the "friendly" name of the field in question
BEGIN
SELECT user_friendly
INTO v_friendly
FROM totals_field_lookup
WHERE table_field /*v_friendly:*/= rtrim(ltrim(ltrim(v_data), 'j.'), ', ');
EXCEPTION
WHEN OTHERS THEN
v_line_buffer := htf.plaintext('There was a problem finding this field: '|| v_data || '. The most likely solution is to update the totals_field_lookup table');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.br;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
END;
-- If the column name contains the following
IF instr(upper(v_friendly), 'TOTAL') <> 0
OR instr(upper(v_friendly), 'TEMP') <> 0
OR instr(upper(v_friendly), 'PERM') <> 0
OR instr(upper(v_friendly), 'ACTUALS') <> 0
OR instr(upper(v_friendly), 'BALANCE') <> 0
--OR instr(upper(v_friendly), 'ENCUMB') <> 0
OR instr(upper(v_friendly), 'AMOUNT') <> 0 THEN
-- Write out the line to the CLOB
v_line_buffer := htf.tableHeader(calign => 'CENTER',
cvalue => '' || rtrim(v_friendly, ', ') || ' ' ||
htf.formRadio(cname => 'p_column', cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- The following columns need to be narrow (ie: width="80px") since the column header is longer than the data contained
ELSE
IF INSTR(upper(v_friendly), 'PAN JOURNAL') <> 0
THEN
v_line_buffer := htf.tableHeader(calign => 'CENTER',
cvalue => ''||rtrim(v_friendly, ', ')||' ' ||
htf.formRadio(cname => 'p_column', cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" width="100px"');
ELSE
v_line_buffer := htf.tableHeader(calign => 'center',
cvalue => ''||rtrim(v_friendly, ', ')||' '||htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
END IF;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
END IF;
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP; --WHILE nPos > 0 LOOP
END IF; --IF TRIM(v_FIELDS) = ',' THEN
v_line_buffer := htf.tableRowClose;
-- Check for broadness of criteria
IF totals_util.check_broad(p_session_id) THEN
BEGIN
ddl_cursor := dbms_sql.open_cursor;
dbms_sql.parse(ddl_cursor, v_ucrfs_query, dbms_sql.native);
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_Message => 'Problem with dbms_sql.parse; v_ucrfs_query = ' || v_ucrfs_query || ' v_dd_fields = ' || v_dd_fields || ' v_fields = ' || v_fields);
RETURN;
END;
-- Loop thru all the fields and define their columns
FOR i IN 1..v_count LOOP
dbms_sql.define_column(ddl_cursor, i, v_data, 1000);
END LOOP;
BEGIN
rows_processed := dbms_sql.execute(ddl_cursor);
EXCEPTION
WHEN NO_DATA_NEEDED THEN
v_line_buffer := htf.plaintext('No more data needed. ');
END;
rowCnt := 0;
-- Loop thru all the sql rows and create an HTML table row for the data
LOOP
-- Clear out and reconstruct the drilldown clause for this row
v_Drilldown_Clause := ' ';
IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
label := rowCnt;
rowCnt := rowCnt + 1;
v_line_buffer := htf.tableRowOpen;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Alternating row colors
IF rowCnt MOD 2 = 0 THEN
v_rowclass := ' id="datarow" class="tabledatarow" ';
ELSE
v_rowclass := ' id="datarow" class="tabledatarowlight" ';
END IF;
v_line_buffer := htf.tableData(calign => 'center',
cvalue => rowCnt,
cattributes => v_rowclass);
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- Loop thru all the columns and create a HTML table cell and place the data there
FOR i IN 1..v_count LOOP
-- The current field in the v_FIELDS variable
v_CurrentField := substr(v_FIELDS, nStart, nPos - nStart);
dbms_sql.column_value(ddl_cursor, i, v_data);
v_data := RTRIM(LTRIM(v_data));
-- If the data returned has no real value
IF v_data = '' OR v_data IS NULL THEN
v_data := ' ';
-- If a summary query, then assign an onClick event for drilling down??
IF v_query_type = 'S' THEN
v_line_buffer :=htf.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass || ' onclick="drilldown_row(this,'|| label ||');"');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- Detail query
ELSE
v_line_buffer :=htf.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass);
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
END IF;
-- Otherwise, check for the query type
ELSE
-- For summary
CASE v_query_type
WHEN 'S' THEN
-- Used to drilldown on summary rows of data
v_SumDrillDown := ' ';
ELSE
v_SumDrillDown := '';
END CASE;
-- If the current field is a PO number, then create a link to drilldown into the WAREHOUSE_HEADER for eBuy POs
-- or subpo@devdb / po_info@devdb for legacy POs
IF instr(upper(v_CurrentField), 'PO_ID') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
-- Was cvalue => '' || htf.escape_sc(v_data) || '',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is a journal id, then create a link to drilldown into the journal_tbl table
ELSIF instr(upper(v_CurrentField), 'JOURNAL_ID') <> 0 THEN
v_line_buffer := htf.tableData(calign => 'center',
-- WAS: cvalue => '' || v_data || '',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Save the current journal ID
v_Journal_ID := v_data;
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is a journal line number, then create a tooltip for PAN information
ELSIF instr(upper(v_CurrentField), 'JOURNAL_LINE') <> 0 THEN
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass );
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
ELSIF instr(upper(v_CurrentField), 'VENDOR_ID') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
ELSIF instr(upper(v_CurrentField), 'VOUCHER_ID') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
-- Was: cvalue => '' || htf.escape_sc(v_data) || '',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an account number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'ACCOUNT') <> 0 AND instr(upper(v_CurrentField), 'ACCOUNTING') = 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || ' style="cursor:hand" ');
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an activity number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'DEPTID') <> 0 AND instr(upper(v_CurrentField), 'DESCR') = 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an fund number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'FUND_CODE') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an function number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'PROGRAM_CODE') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is an cost center then add a tooltip
ELSIF instr(upper(v_CurrentField), 'APPROPRIATION_NBR') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- If the current field is the Journal Line Ref then add a tooltip for SIS data
ELSIF instr(upper(v_CurrentField), 'JRNL_LN_REF') <> 0 THEN
-- Create the table cell element
v_line_buffer := htf.tableData(calign => 'center',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- Left align description columns
ELSIF instr(upper(v_CurrentField), 'DESC') <> 0 THEN
v_line_buffer := htf.tableData(calign => 'left',
cvalue => htf.escape_sc(v_data) ,
cattributes => v_rowclass);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
-- Right align amount columns
ELSIF INSTR(upper(v_CurrentField), 'J.FOREIGN_AMOUNT') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumAmount := n_SumAmount + v_PrepareAmount;
-- Remember the column number
n_ColAmount := i;
v_line_buffer := htf.tableData(calign => 'right',
cvalue => to_char(htf.escape_sc(v_PrepareAmount), declarations.gk_MONEYFORMAT),
-- cvalue => htf.escape_sc(v_PrepareAmount),
cattributes => v_rowclass);
-- Perm Amounts
ELSIF INSTR(upper(v_CurrentField), 'PERM') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumPERMAmount := n_SumPermAmount + v_PrepareAmount;
-- Remember the column number
n_ColPERMAmount := i;
v_line_buffer := htf.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Temp Amounts
ELSIF INSTR(upper(v_CurrentField), 'TEMP') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumTEMPAmount := n_SumTEMPAmount + v_PrepareAmount;
-- Remember the column number
n_ColTEMPAmount := i;
v_line_buffer := htf.tableData(calign => 'right',
--cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Actuals Amounts
ELSIF INSTR(upper(v_CurrentField), 'ACTUALS') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumACTUALSAmount := n_SumACTUALSAmount + v_PrepareAmount;
-- Remember the column number
n_ColACTUALSAmount := i;
v_line_buffer := htf.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Total FTE
ELSIF INSTR(upper(v_CurrentField), 'STATISTIC_AMOUNT') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumFTEAmount := n_SumFTEAmount + v_PrepareAmount;
-- Remember the column number
n_ColFTEAmount := i;
v_line_buffer := htf.tableData(calign => 'right',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass || v_SumDrillDown);
-- Total Records
ELSIF INSTR(upper(v_CurrentField), 'COUNT(*)') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumRECORDSAmount := n_SumRECORDSAmount + v_PrepareAmount;
-- Remember the column number
n_ColRECORDSAmount := i;
v_line_buffer := htf.tableData(calign => 'right',
cvalue => '
',
cattributes => v_rowclass ); --|| 'style="cursor:hand" onclick="summary_drilldown(this,'|| label ||');"' );
ELSE
v_line_buffer := htf.tableData(calign => 'center',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass);
-- Construct the Summary query drilldown WHERE clause
v_Drilldown_Clause := v_Drilldown_Clause || v_CurrentField || '= ''' || v_data || ''' AND ';
--htp.p('v_CurrentField = ' || v_CurrentField);
END IF; --IF instr(upper(v_CurrentField), 'PO_ID') <> 0 THEN
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
END IF; --IF v_data = '' OR v_data IS NULL THEN
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
-- DEBUG: htp.p('v_CurrentField = ' || v_CurrentField);
n_TotalColumns := i;
END LOOP; --FOR i IN 1..v_count LOOP
v_line_buffer := htf.tableRowClose;
ELSE
EXIT;
END IF; -- IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
END LOOP; -- Loop thru all the sql rows and create an HTML table row for the data
dbms_sql.close_cursor(ddl_cursor);
ELSE
v_line_buffer := htf.script(clanguage => 'javascript',
cscript => 'alert("The current search selections are too broad.\nPlease select additional search criteria to narrow the search results.\nYou will now be redirected to the query tab.");
window.location.href="totals_tabs.query?p_session_id='||p_session_id||'";
');
END IF;
-- End of result grid
v_line_buffer := htf.plaintext('');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.tableClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
-- End of overall encompassing table
v_line_buffer := htf.plaintext('');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.tableRowClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer := htf.tableClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
CASE v_query_type
WHEN 'S' THEN
v_CurrentField := 'Summary ';
ELSE
v_CurrentField := 'Detail ';
END CASE;
v_line_buffer :=htf.plaintext('');
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer :=htf.formHidden(cname => 'rowCnt',cvalue => rowCnt);
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer :=htf.formClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer :=htf.bodyClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_line_buffer :=htf.htmlClose;
v_LineLength := length(v_line_buffer);
dbms_lob.writeappend(lob_loc => v_clob, amount => v_LineLength, buffer => v_line_buffer );
v_blob := totals_util.clob_to_blob(v_clob);
BEGIN
INSERT INTO totals_documents
(NAME, mime_type, doc_size, dad_charset, last_updated, content_type, blob_content, net_id, descr, total_rows, total_amount)
VALUES
('My Query', 'text/html', dbms_lob.getlength(v_blob), 'ascii', SYSDATE, 'BLOB', v_blob, 'griff', 'My query executed on ' || to_char(SYSDATE, 'Mon DD, YYYY, HH:MIam'), 0, 0);
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_Message => 'There was a INSERTing INTO the TOTALS_DOCUMENTS table. ');
END;
-- Close the CLOB
dbms_lob.close(v_clob);
dbms_lob.freetemporary(v_clob);
EXCEPTION
WHEN OTHERS THEN
-- htp.p('v_UCRFS_QUERY = ' || v_UCRFS_QUERY);
totals_util.error(p_session_id => p_session_id);
RETURN;
END exec_query_clob;
-- -------------------------------------------------------------------------------------
-- Procedure: Execute Query
-- Programmer: Luis Baquera ?
-- Description: Given that the user has made their selections, run their query
--
-- Modifications:
-- Programmer: Brian Griffin
-- Date: Jan 2, 2007
-- Purpose: Added tooltips Based on what data is being returned
--
-- Modifications:
-- Programmer: Brian Griffin
-- Date: Jan 30, 2007
-- Purpose: Instrumented the code using DBMS_APPLICATION_INFO.SET_MODULE();
-- This allows the DBA to query session_longops to view the progress in case of long running queries
-- -------------------------------------------------------------------------------------
PROCEDURE DIV_execute_query(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_action IN varchar2 DEFAULT NULL,
p_clause IN varchar2 default null,
p_dd_query IN LONG default NULL) IS
nStart number;
nPos number;
v_UCRFS_QUERY totals_settings.ucrfs_query%TYPE;
v_FIELDS long;
v_Ledgers totals_settings.ledgers%TYPE;
v_query_type totals_settings.query_type%TYPE;
v_USER_ID totals_settings.user_id%TYPE;
v_separate_columns totals_settings.separate%TYPE;
v_count integer :=0;
rowCnt integer :=0; -- row counter
label integer :=0; -- a label for the row number
ddl_cursor integer :=0; -- SQL cursor
rows_processed integer :=0; -- number of rows processed
v_data varchar2(4000); -- Current data from SQL statement to be printed out
v_friendly totals_field_lookup.user_friendly%TYPE; -- Friendly name of current field
sField varchar2(100);
v_CurrentField varchar2(1000) := ''; -- Current field being analyzed
v_dd_fields long; -- drilldown fields
-- Final row for grand total amounts
n_SumAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- Sum the amount column for a final row
v_PrepareAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumTEMPAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumPERMAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumACTUALSAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- temp amount column for a final row
n_SumFTEAmount NUMBER DEFAULT 0;
n_SumRECORDSAmount NUMBER DEFAULT 0;
-- Column positions
n_ColAmount INTEGER DEFAULT 1;
n_ColTEMPAmount INTEGER DEFAULT 1;
n_ColPERMAmount INTEGER DEFAULT 1;
n_ColACTUALSAmount INTEGER DEFAULT 1;
n_ColFTEAmount INTEGER DEFAULT 1;
n_ColRECORDSAmount INTEGER DEFAULT 1;
n_TotalColumns INTEGER DEFAULT 1;
v_Journal_ID journal_tbl.journal_id%TYPE DEFAULT ''; -- The current journal ID
-- Added by Brian for Encumbrance related queries (note: f/by is short for followed by:
--v_RegExpColumnAliases VARCHAR2(50) DEFAULT ' "[A-Za-z_]+"'; -- match a space f/by a " f/by 1 or more characters f/by underscore f/by another "
--v_RegExpDECODE VARCHAR2(50) DEFAULT 'DECODE\([jJ]\.LEDGER.+\)'; -- match the DECODE(J.LEDGER blah ) stuff
--n_CountFields NUMBER DEFAULT 0;
v_rowclass VARCHAR2(60) DEFAULT ' class="tabledatarow" '; -- for alternating row colors
v_HeaderClass VARCHAR2(60) DEFAULT ' class="tablehead" '; -- for table column headers
-- Variables for instrumenting this procedure
i_longops_row BINARY_INTEGER := dbms_application_info.set_session_longops_nohint;
i_slno BINARY_INTEGER;
v_SumDrillDown VARCHAR2(50); -- a string for adding the onclick event for summary drilldown rows
-- A timer feature
t_StartTime timestamp(1) ;
t_EndTime timestamp(1) ;
BEGIN
-- Check login status
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
-- Collect various variables
BEGIN
SELECT ts.ledgers, ts.selected_fields, ts.query_type, ts.user_id, ts.separate
INTO v_Ledgers, v_fields, v_query_type, v_USER_ID, v_separate_columns
FROM totals_settings ts
WHERE ts.session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
--htp.p('p_action = ' || p_action);
-- A p_action of null means the user is running a normal non-ENCUMB query
IF p_action IS NULL THEN
NULL;
-- Determine if the ENCUMB ledger was selected and if so, go to that procedure to generate the query
-- IF v_Ledgers IS NULL OR INSTR(v_Ledgers, 'ENCUMB') > 0 THEN
-- v_UCRFS_QUERY := totals_util.gen_detail_encumb_query(p_session_id => p_session_id);
-- b_ENCUMBQuery := TRUE;
-- If not an ENCUMB query, then generate the SQL per usual...
--ELSE
--dbms_application_info.set_action( 'Generating UCRFStotals query' );
-- Generate and return the sql string that represents the user's query
--v_UCRFS_QUERY := totals_util.generate_query(p_session_id => p_session_id);
--END IF;
-- Reordering the data based on a column selection
ELSIF p_action = 'reorder' THEN
IF p_dd_query IS NULL THEN
BEGIN
SELECT ucrfs_query
INTO v_UCRFS_QUERY
FROM totals_settings
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
ELSE
v_UCRFS_QUERY := p_dd_query;
END IF;
-- Drilldown into a row of data
ELSIF p_action = 'p_drilldown' THEN -- Was 'dd'
dbms_application_info.set_action( 'Collecting drilldown data' );
BEGIN
SELECT trim(DRILLDOWN_FIELDS)
INTO v_fields
FROM totals_settings
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
v_query_type := 'D';
v_UCRFS_QUERY := 'SELECT ';
--htp.p('/1/ v_fields = ' || v_fields);
--RETURN;
nStart := 1;
nPos := instr(v_FIELDS, ', ');
WHILE nPos > 0 LOOP
sField := substr(v_FIELDS, nStart, nPos - nStart);
IF sField = 'j.JOURNAL_DATE' THEN
v_dd_fields := v_dd_fields || 'TO_CHAR(' || sField || ',''MM/DD/YYYY''), ';
ELSIF sField = 'j.ACCOUNTING_PERIOD' THEN
v_dd_fields := v_dd_fields || 'LPAD(' || sField || ',3,''0''), ';
ELSIF sField = 'j.FOREIGN_AMOUNT' OR sField = 'j.STATISTIC_AMOUNT' THEN
v_dd_fields := v_dd_fields || 'TO_CHAR('||sField ||',''99999999999D99'','' NLS_NUMERIC_CHARACTERS = ''''.,'''' NLS_CURRENCY = ''''$''''''), ';
ELSE
v_dd_fields := v_dd_fields || sField || ', ';
END IF;
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP;
-- WAS v_UCRFS_QUERY := v_UCRFS_QUERY || rtrim(v_dd_fields, ', ') || ' FROM JOURNAL_TBL j ' || p_clause;
v_UCRFS_QUERY := v_UCRFS_QUERY || rtrim(v_dd_fields, ', ') || ' FROM JRNL_PURCHAS_VW j ' || p_clause;
/* htp.br;htp.p;
htp.p('v_UCRFS_QUERY = ' || v_UCRFS_QUERY);
htp.br;htp.p;
htp.p('p_session_id = ' || p_session_id);
htp.br;htp.p;
htp.p('p_action = ' || p_action);
htp.br;htp.p;
htp.p('p_clause = ' || p_clause);
htp.br;htp.p;
htp.p('p_dd_query = ' || p_dd_query);
htp.br;htp.p;
*/
ELSIF p_action = 'dd_reorder' THEN
v_query_type := 'D';
v_UCRFS_QUERY := p_dd_query;
END IF; --IF p_action IS NULL THEN
-- Instrumenting the procedure
dbms_application_info.set_module(module_name => 'execute_query', action_name => 'STARTING');
-- htp.p('');
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.p('');
-- If the variable does not contain any fields, we may want to prevent them from running the query
IF length(trim(v_fields)) < 2 THEN
htp.script(clanguage => 'javascript',
cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");
window.location.href="totals_tabs.standard_fields?p_session_id='||p_session_id||'";
');
RETURN;
END IF;
-- Set the webpage title
IF instr(p_action, 'p_drilldown') <> 0 THEN
htp.title(ctitle => 'UCRFStotals - Drilldown Detail Query Results');
ELSE
htp.title(ctitle => 'UCRFStotals - Query Results');
END IF;
-- Get the CSS information
totals_dhtml.get_CSS(p_session_id, 'RESULT_GRID');
-- Javascript for sorting a table by clicking on the table header
htp.p('');
htp.headClose;
-- Get the javascript functions for the result grid
totals_dhtml.get_resultgrid_js(p_action, v_USER_ID, v_UCRFS_QUERY, p_session_id);
htp.bodyOpen(cbackground => 'white', cattributes => 'topmargin=0 leftmargin=0');
-- Get the
element for the tooltip information
totals_dhtml.get_tooltip_DIV;
-- Declare Javascript functions
totals_dhtml.get_tooltip_js(p_session_id);
totals_dhtml.get_drilldown_js(p_session_id);
htp.formOpen(curl => 'totals_util.prepare_dd', cmethod => 'POST',ctarget => 'p_drilldown');
htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
htp.formHidden(cname => 'p_headers');
htp.formHidden(cname => 'p_fields');
htp.formHidden(cname => 'p_descr_columns');
htp.formClose;
htp.formOpen(curl => 'totals_util.reorder', cmethod => 'POST');
htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
htp.formHidden(cname => 'p_col');
htp.formHidden(cname => 'p_action');
htp.formHidden(cname => 'p_dd_query');
htp.formClose;
-- Form for exporting to excel
--htp.formOpen(curl => 'totals_util.export_to_excel',cmethod => 'POST',ctarget => 'export_to_excel', cattributes => 'name="export_to_excel"');
--htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
-- Originally, we called the procedure excel
htp.formOpen(curl => 'totals_util.excel',cmethod => 'POST',ctarget => 'excel');
htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
htp.formHidden(cname => 'p_clause',cvalue => p_clause);
IF instr(p_action, 'p_drilldown') <> 0 THEN
htp.formHidden(cname => 'p_drilldown',cvalue => 1);
ELSE
htp.formHidden(cname => 'p_drilldown',cvalue => 0);
END IF;
htp.formClose;
htp.formOpen(curl => 'totals_util.sort',cmethod => 'POST',ctarget => 'sort');
htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
IF instr(p_action, 'p_drilldown') <> 0 THEN
htp.formHidden(cname => 'p_drilldown',cvalue => 1);
ELSE
htp.formHidden(cname => 'p_drilldown',cvalue => 0);
END IF;
htp.formHidden(cname => 'p_dd_query',cvalue => v_UCRFS_QUERY);
htp.formClose;
-- For now the STATS button is disabled since the sorttable.js program erases all the radio buttons
-- in the column headers. These radio buttons are used to determine which column the user wants stats on
/* htp.formOpen(curl => 'totals_util.stats',cmethod => 'post',ctarget => 'stats');
htp.formHidden(cname => 'p_rows');
htp.formClose;
*/
IF instr(p_action, 'p_drilldown') <> 0 THEN
htp.p(totals_util.tab_headers(p_session_id => p_session_id,
p_tab => 'execute',
p_sub_section => 'p_drilldown',
p_query_tab_selection => ''));
ELSE
htp.p(totals_util.tab_headers(p_session_id => p_session_id,
p_tab => 'execute',
p_sub_section => '',
p_query_tab_selection => ''));
END IF;
htp.comment('Encompassing Table');
htp.tableOpen(cattributes => 'cellpadding="5" width="100%" border="0" bgcolor=white ');
--htp.tableCaption(ccaption => htf.bold('Query Results'), calign => 'top');
htp.tableRowOpen;
htp.p('
');
-- Data table for the returning rows
--htp.tableOpen(cattributes => 'width="100%" border="2" class="sortable" id="data" bgcolor="white"');
--htp.p('
');
--htp.tableRowOpen;
-- /1/ Using a DIV to render the tabular data
htp.p('
');
-- IF p_action <> 'p_drilldown' THEN
-- Make a determine of whether this is an ENCUMB query or not
-- Parse thru the variable v_UCRFS_QUERY and
-- strip out the SELECT clause's fields in order to work with the individual fields
-- Then parse thru those fields and do a look up in the Friendly Field table (totals_field_lookup)
-- to get the user-friendly name to use as a column header
/* IF b_ENCUMBQuery = TRUE THEN
-- A bit confusing here... In order to use the ENCUMB query which is a UNION ALL type of statement
-- the columns must have alias names. But these alias names confuse the parsing below which tries to
-- do a lookup in the Friendly Fields table based on the SELECT's fields names, ie: J.JOURNALID, etc
-- Thus, regular expressions are used to strip out the column alias and just return the field names
-- Remove the preceding SELECT DISTINCT
v_FIELDS := substr(v_UCRFS_QUERY, LENGTH('SELECT DISTINCT '), LENGTH(v_UCRFS_QUERY));
-- Remove everything including and after the FROM statement
v_FIELDS := ltrim(substr(v_FIELDS, 1, instr(v_FIELDS, 'FROM')-2)) || ', ';
-- Strip out any pattern that matches the v_RegExpColumnAliases variable, such as "JOURNAL_ID"
v_FIELDS := REGEXP_REPLACE(v_FIELDS, v_RegExpColumnAliases, '');
-- Strip out any DECODE(J.LEDGER, blah) stuff and replace it with J.FOREIGN_AMOUNT instead
v_FIELDS := REGEXP_REPLACE(v_FIELDS, v_RegExpDECODE, 'J.FOREIGN_AMOUNT');
-- Replace the last 0 which represents the ENCUMB Amount in the other part of the SQL statement
v_FIELDS := replace(v_FIELDS, ', 0', ', J.FOREIGN_AMOUNT');
-- A useful trick to count the number of occurances of a comma
-- Get the length of the string (without any spaces) minus the length of the string without any spaces or delimiters (a comma)
SELECT (LENGTH(REPLACE(v_FIELDS, ' ', '')) - LENGTH(REPLACE(upper(REPLACE(v_FIELDS, ' ', '')), upper(','), ''))) / LENGTH(',')
INTO n_CountFields
FROM dual;
*/
-- Per usual query
--ELSE
v_FIELDS := substr(v_ucrfs_query, LENGTH('SELECT '), LENGTH(v_UCRFS_QUERY));
v_FIELDS := ltrim(substr(v_FIELDS, 1, instr(v_FIELDS, 'FROM')-2)) || ', ';
--END IF;
-- END IF;
--htp.p('v_ucrfs_query = ' || v_ucrfs_query ||' ');
--htp.p('/2/ v_fields = ' || v_fields ||' ');
/* -- Header for checkboxes used for Stats
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => 'Stats',
cattributes => v_rowclass || 'valign="top" width="5px" ');
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => 'Row',
cattributes => v_rowclass || 'valign="top" width="10px" ');
*/
-- /2/ Using a DIV to render the header row of data
htp.p('
');
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- If v_Fields is just a comma, then the user didn't actually select any fields to display
IF TRIM(v_fields) = ',' THEN
-- Clean up and reset MODULE and ACTION as we exit.
dbms_application_info.set_module( null,null );
--htp.script(clanguage => 'javascript',
-- cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");
-- window.location.href="totals_tabs.standard_fields?p_session_id='||p_session_id||'"; ');
htp.script(clanguage => 'javascript',
cscript => 'alert("No fields were selected for output.\nPlease select at least one field for output before running your query.\nYou will now be redirected to the Standard Fields tab where you will make your selections.");');
ELSE
-- Start the timer
t_StartTime := systimestamp;
-- Loop thru the selected fields and start creating the column headers
WHILE nPos > 0 LOOP
dbms_application_info.set_action( 'Creating column headers' );
v_count := v_count + 1;
v_data := substr(v_FIELDS, nStart, nPos - nStart);
-- If the current piece of data contains 'DECODE(j.LEDGER,' then we are using split columns for the PERM/TEMP/PERM amounts and the ENCUMB amounts
--IF instr(v_data, 'ENCUMB') <> 0 THEN
-- v_friendly := 'Encumbered Amount';
--IF instr(v_data, 'PERM') <> 0 THEN
-- v_friendly := 'Amount';
-- If LPAD is in the SQL, then remove it
IF instr(v_data, 'LPAD') <> 0 THEN
v_data := substr(v_data, LENGTH('LPAD(')+1, LENGTH(v_data));
-- Remove the trailing )
v_data := substr(v_data, 1, instr(v_data, ',')-1) || ' ';
-- If TO_CHAR is in the SQL, then remove it
ELSIF instr(v_data, 'TO_CHAR') <> 0 THEN
v_data := substr(v_data, LENGTH('TO_CHAR(')+1, LENGTH(v_data));
-- Remove the trailing )
v_data := substr(v_data, 1, instr(v_data, ',')-1) || ' ';
END IF;
-- Get the "friendly" name of the field in question
BEGIN
SELECT user_friendly
INTO v_friendly
FROM totals_field_lookup
WHERE table_field /*v_friendly:*/= rtrim(ltrim(ltrim(v_data), 'j.'), ', ');
EXCEPTION
WHEN OTHERS THEN
htp.p('There was a problem finding this field: '|| v_data || '. The most likely solution is to update the totals_field_lookup table');
htp.br;
END;
-- If we are drilling down
IF instr(p_action, 'p_drilldown') <> 0 THEN
IF instr(upper(v_friendly), 'TOTAL') <> 0
OR instr(upper(v_friendly), 'TEMP') <> 0
OR instr(upper(v_friendly), 'PERM') <> 0
OR instr(upper(v_friendly), 'ACTUALS') <> 0
OR instr(upper(v_friendly), 'BALANCE') <> 0
--OR instr(upper(v_friendly), 'ENCUMB') <> 0
OR instr(upper(v_friendly), 'AMOUNT') <> 0 THEN
htp.tableHeader(calign => 'center',
cvalue => rtrim(v_friendly, ', ')||' ' || htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
-- cattributes => 'class="heading" valign="bottom" ');
cattributes => v_HeaderClass || 'valign="bottom" ');
ELSE
htp.tableHeader(calign => 'left',
cvalue => ''||rtrim(v_friendly, ', ')||' '||htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
END IF; --IF instr(upper(v_friendly), 'TOTAL') <> 0
-- Otherwise
ELSE
-- If the column name contains the following
IF instr(upper(v_friendly), 'TOTAL') <> 0
OR instr(upper(v_friendly), 'TEMP') <> 0
OR instr(upper(v_friendly), 'PERM') <> 0
OR instr(upper(v_friendly), 'ACTUALS') <> 0
OR instr(upper(v_friendly), 'BALANCE') <> 0
--OR instr(upper(v_friendly), 'ENCUMB') <> 0
OR instr(upper(v_friendly), 'AMOUNT') <> 0 THEN
htp.tableHeader(calign => 'CENTER',
cvalue => '' || rtrim(v_friendly, ', ') || ' ' ||
htf.formRadio(cname => 'p_column', cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
-- The following columns need to be narrow (ie: width="80px") since the column header is longer than the data contained
ELSE
IF INSTR(upper(v_friendly), 'PAN JOURNAL') <> 0
THEN
htp.tableHeader(calign => 'CENTER',
cvalue => ''||rtrim(v_friendly, ', ')||' ' ||
htf.formRadio(cname => 'p_column', cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" width="100px"');
ELSE
/*htp.tableHeader(calign => 'center',
cvalue => ''||rtrim(v_friendly, ', ')||' '||htf.formRadio(cname => 'p_column',
cvalue => rtrim(v_friendly, ', ')),
cattributes => v_HeaderClass || 'valign="bottom" ');
*/
-- /3/ Using a DIV to render the header row of data
htp.p('
' || rtrim(v_friendly, ', ') || '
');
END IF;
END IF;
END IF; --IF instr(p_action, 'p_drilldown') <> 0 THEN
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
END LOOP; --WHILE nPos > 0 LOOP
END IF; --IF TRIM(v_FIELDS) = ',' THEN
htp.tableRowClose;
-- Check for broadness of criteria
IF totals_util.check_broad(p_session_id) THEN
dbms_application_info.set_action( 'Defining and opening cursor' );
ddl_cursor := dbms_sql.open_cursor;
dbms_sql.parse(ddl_cursor, v_UCRFS_QUERY, dbms_sql.native);
-- Loop thru all the fields and define their columns
FOR i IN 1..v_count LOOP
dbms_sql.define_column(ddl_cursor, i, v_data, 1000);
END LOOP;
--HTP.p('(there are ' || v_count || ' data columns)');
rows_processed := dbms_sql.execute(ddl_cursor);
rowCnt := 0;
-- Loop thru all the sql rows and create an HTML table row for the data
LOOP
dbms_application_info.set_action( 'Looping thru data' );
IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
label := rowCnt;
rowCnt := rowCnt + 1;
-- Record progress in session_longops
dbms_application_info.set_session_longops(
rindex => i_longops_row,
slno => i_slno,
op_name => 'LOOPING THRU QUERY DATA',
target => 0,
context => 0,
sofar => rowCnt,
totalwork => dbms_sql.last_row_count,
target_desc => 'Using data: ' || v_data,
units => 'rows of data'
);
-- If a summary query, then highlight the row?
IF v_query_type = 'S' THEN
htp.tableRowOpen(cattributes => 'onmouseover=mouseover(this); onmouseout=mouseout(this);');
ELSE
htp.tableRowOpen;
END IF;
-- Alternating row colors
IF rowCnt MOD 2 = 0 THEN
v_rowclass := ' id="datarow" class="tabledatarow" ';
ELSE
v_rowclass := ' id="datarow" class="tabledatarowlight" ';
END IF;
/*-- The checkbox and row number
htp.tableData(calign => 'center',
cvalue => htf.formCheckbox(cname => 'p_rows',cvalue => rowCnt),
cattributes => v_rowclass);
htp.tableData(calign => 'center',
cvalue => rowCnt,
cattributes => v_rowclass);
*/
-- /4/ Using a DIV to render the start of a row of data
htp.p('
');
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := 1;
nPos := instr(v_FIELDS, ', ');
-- Loop thru all the columns and create a HTML table cell and place the data there
FOR i IN 1..v_count LOOP
-- The current field in the v_FIELDS variable
v_CurrentField := substr(v_FIELDS, nStart, nPos - nStart);
dbms_sql.column_value(ddl_cursor, i, v_data);
v_data := RTRIM(LTRIM(v_data));
-- If the data returned has no real value
IF v_data = '' OR v_data IS NULL THEN
v_data := ' ';
-- If a summary query, then assign an onClick event for drilling down??
IF v_query_type = 'S' THEN
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass || ' onclick="drilldown_row(this,'|| label ||');"');
-- Detail query
ELSE
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => v_rowclass);
END IF;
-- Otherwise, check for the query type
ELSE
-- For summary
IF v_query_type = 'S' THEN
-- Used to drilldown on summary rows of data
v_SumDrillDown := ' style="cursor:hand" onclick="drilldown_row(this,'|| label ||');" ';
ELSE
v_SumDrillDown := '';
END IF;
-- If the current field is a PO number, then create a link to drilldown into the WAREHOUSE_HEADER for eBuy POs
-- or subpo@devdb / po_info@devdb for legacy POs
IF instr(upper(v_CurrentField), 'PO_ID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
-- Was cvalue => '' || htf.escape_sc(v_data) || '',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- If the current field is a journal id, then create a link to drilldown into the journal_tbl table
ELSIF instr(upper(v_CurrentField), 'JOURNAL_ID') <> 0 THEN
htp.tableData(calign => 'center',
-- WAS: cvalue => '' || v_data || '',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- Save the current journal ID
v_Journal_ID := v_data;
-- If the current field is a journal line number, then create a tooltip for PAN information
ELSIF instr(upper(v_CurrentField), 'JOURNAL_LINE') <> 0 THEN
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
-- From the original Journal ID line
-- cvalue => '' || v_data || '',
cattributes => v_rowclass );
ELSIF instr(upper(v_CurrentField), 'VENDOR_ID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
ELSIF instr(upper(v_CurrentField), 'VOUCHER_ID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
-- Was: cvalue => '' || htf.escape_sc(v_data) || '',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => v_rowclass || v_SumDrillDown);
-- If the current field is an account number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'ACCOUNT') <> 0 AND instr(upper(v_CurrentField), 'ACCOUNTING') = 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || ' style="cursor:hand" ');
-- If the current field is an activity number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'DEPTID') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- If the current field is an fund number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'FUND_CODE') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- If the current field is an function number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'PROGRAM_CODE') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- If the current field is an cost center then add a tooltip
ELSIF instr(upper(v_CurrentField), 'APPROPRIATION_NBR') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || v_data || '',
cattributes => v_rowclass || v_SumDrillDown);
-- If the current field is the Journal Line Ref then add a tooltip for SIS data
--ELSIF instr(upper(v_CurrentField), 'JRNL_LN_REF') <> 0 THEN
-- Create the table cell element
-- htp.tableData(calign => 'center',
-- cvalue => '' || htf.escape_sc(v_data) || '',
-- cattributes => v_rowclass || v_SumDrillDown);
-- Left align description columns
ELSIF instr(upper(v_CurrentField), 'DESC') <> 0 THEN
htp.tableData(calign => 'left',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass);
-- Right align amount columns
ELSIF INSTR(upper(v_CurrentField), 'J.FOREIGN_AMOUNT') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumAmount := n_SumAmount + v_PrepareAmount;
-- Remember the column number
n_ColAmount := i;
htp.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Perm Amounts
ELSIF INSTR(upper(v_CurrentField), 'PERM') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumPERMAmount := n_SumPermAmount + v_PrepareAmount;
-- Remember the column number
n_ColPERMAmount := i;
htp.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Temp Amounts
ELSIF INSTR(upper(v_CurrentField), 'TEMP') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumTEMPAmount := n_SumTEMPAmount + v_PrepareAmount;
-- Remember the column number
n_ColTEMPAmount := i;
htp.tableData(calign => 'right',
--cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Actuals Amounts
ELSIF INSTR(upper(v_CurrentField), 'ACTUALS') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumACTUALSAmount := n_SumACTUALSAmount + v_PrepareAmount;
-- Remember the column number
n_ColACTUALSAmount := i;
htp.tableData(calign => 'right',
-- cvalue => htf.escape_sc(v_data),
cvalue => to_char(htf.escape_sc(v_data), declarations.gk_MONEYFORMAT),
cattributes => v_rowclass || v_SumDrillDown);
-- Total FTE
ELSIF INSTR(upper(v_CurrentField), 'STATISTIC_AMOUNT') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumFTEAmount := n_SumFTEAmount + v_PrepareAmount;
-- Remember the column number
n_ColFTEAmount := i;
htp.tableData(calign => 'right',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass || v_SumDrillDown);
-- Total Records
ELSIF INSTR(upper(v_CurrentField), 'COUNT(*)') <> 0 THEN
-- Strip out extraneous characters for doing a sum
v_PrepareAmount := replace(v_data, '$', '');
v_PrepareAmount := replace(v_PrepareAmount, ',', '');
n_SumRECORDSAmount := n_SumRECORDSAmount + v_PrepareAmount;
-- Remember the column number
n_ColRECORDSAmount := i;
htp.tableData(calign => 'right',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass || v_SumDrillDown);
ELSE
/* htp.tableData(calign => 'center',
cvalue => htf.escape_sc(v_data),
cattributes => v_rowclass);
*/
-- /5/ Using a DIV to render some element in a row of data
htp.p('
' || htf.escape_sc(v_data) || '
');
--htp.p('v_CurrentField = ' || v_CurrentField);
END IF; --IF instr(upper(v_CurrentField), 'PO_ID') <> 0 THEN
-- END IF; --IF v_query_type = 'S' THEN
END IF; --IF v_data = '' OR v_data IS NULL THEN
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
nStart := nPos + 2;
nPos := instr(v_FIELDS, ', ', nStart);
-- DEBUG: htp.p('v_CurrentField = ' || v_CurrentField);
n_TotalColumns := i;
END LOOP; --FOR i IN 1..v_count LOOP
/* htp.tableRowClose;
*/
-- /6/ Using a DIV to render the end of a row of data
htp.p('');
htp.p('
');
ELSE
EXIT;
END IF; -- IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
END LOOP; -- Loop thru all the sql rows and create an HTML table row for the data
-- End the timer
t_EndTime := systimestamp;
/*
--IF n_SumAmount <> 0 THEN
-- A final summary row
IF v_query_type = 'S' THEN
-- Summary queries have an additional column at the end for Total Rows
htp.tableData(ccolspan => v_count -1 , cattributes => 'class="tablehead"' );
htp.tableData(cvalue => 'Grand Totals:', ccolspan => '1', cattributes => 'class="tablehead"' );
ELSE
htp.tableData(ccolspan => v_count, cattributes => 'class="tablehead"' );
htp.tableData(cvalue => 'Grand Total:', ccolspan => '1', cattributes => 'class="tablehead"' );
END IF; -- IF v_query_type = 'S' THEN
htp.tableData(calign => 'right',
cvalue => to_char(n_SumAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
htp.tableRowClose;
-- END IF; --IF n_SumAmount <> 0 THEN
*/
dbms_sql.close_cursor(ddl_cursor);
ELSE
htp.script(clanguage => 'javascript',
cscript => 'alert("The current search selections are too broad.\nPlease select additional search criteria to narrow the search results.\nYou will now be redirected to the query tab.");
window.location.href="totals_tabs.query?p_session_id='||p_session_id||'";
');
END IF;
-- End of result grid
/* htp.p('
');
htp.tableClose;
*/
-- /7/ Using a DIV to render the end of a row of data
htp.p('
');
/*
-- A new small table for just the grandtotals. This is meant to be a separate table from the above results grid .
htp.tableOpen;
-- Grand totals
htp.tableRowOpen;
-- When separating columns, shave off three for the TEMP, PERM and ACTUALS columns
IF v_separate_columns = 1 THEN
htp.tableData(ccolspan => v_count-3 , cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumPERMAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumTEMPAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumACTUALSAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
ELSE
htp.tableData(ccolspan => n_ColAmount+1 , cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => to_char(n_SumAmount, '$' || declarations.gk_MONEYFORMAT),
cattributes => 'class="tablehead"' );
END IF; -- IF v_separate_columns = 1 THEN
-- For Summary queries...
IF v_query_type = 'S' THEN
htp.tableData(calign => 'right',
cvalue => n_SumFTEAmount,
cattributes => 'class="tablehead"' );
htp.tableData(calign => 'right',
cvalue => n_SumRECORDSAmount,
cattributes => 'class="tablehead"' );
END IF; -- IF v_query_type = 'S' THEN
-- End of subtotal table
htp.tableRowClose;
htp.tableClose;
*/
-- End of overall encompassing table
htp.p('');
htp.tableRowClose;
htp.tableClose;
htp.p('');
htp.formHidden(cname => 'rowCnt',cvalue => rowCnt);
htp.formClose;
-- Calculate the number of rows and the run time
htp.p('<');
htp.para;htp.br;htp.para;htp.br;htp.para;htp.br;htp.para;htp.br;htp.para;htp.br;
htp.bodyClose;
htp.htmlClose;
-- Clean up and reset MODULE and ACTION as we exit.
dbms_application_info.set_module( null,null );
EXCEPTION
WHEN OTHERS THEN
-- htp.p('v_UCRFS_QUERY = ' || v_UCRFS_QUERY);
totals_util.error(p_session_id => p_session_id);
RETURN;
END DIV_execute_query;
-- -------------------------------------------------------------------------------------
-- Procedure: Crosstab
-- Programmer: Brian Griffin
-- Description: Create a crosstab report
-- Parameters:
-- p_xaxis - The values going down the grid, ie: j.VOUCHER_ID
-- p_yaxis - The values going across the grid ie: j.DEPTID
-- Example we are following: Voucher by Activity
/*
SELECT DECODE(GROUPING(J.VOUCHER_ID), 1, 'All Vouchers', J.VOUCHER_ID) AS "Voucher ID",
SUM(CASE WHEN J.DEPTID = 'A01372' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01372",
SUM(CASE WHEN J.DEPTID = 'A01373' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01373",
SUM(CASE WHEN J.DEPTID = 'A01374' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01374",
SUM(CASE WHEN J.DEPTID = 'A01375' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01375",
SUM(CASE WHEN J.DEPTID = 'A01376' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01376",
SUM(CASE WHEN J.DEPTID = 'A01377' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01377",
SUM(CASE WHEN J.DEPTID = 'A01378' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01378",
SUM(CASE WHEN J.DEPTID = 'A01379' THEN J.FOREIGN_AMOUNT ELSE NULL END) "A01379",
SUM(CASE WHEN 1 = 1 THEN J.FOREIGN_AMOUNT ELSE NULL END) "Total"
FROM JRNL_PURCHAS_VW J
WHERE BUSINESS_UNIT = 'UCR'
AND J.FISCAL_YEAR IN (2007)
AND J.ACCOUNTING_PERIOD IN ('07')
AND J.ORG_CODE IN ('ORG21')
AND J.SOURCE IN ('ATP')
AND J.LEDGER IN ('ACTUALS')
GROUP BY ROLLUP(J.VOUCHER_ID)
ORDER BY J.VOUCHER_ID
*/
-- -------------------------------------------------------------------------------------
PROCEDURE create_crosstab_sql(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_xaxis IN varchar2 DEFAULT NULL,
p_yaxis IN varchar2 DEFAULT NULL) AS
--rc_Crosstab SYS_REFCURSOR;
v_Counter INTEGER := 0;
v_SQL VARCHAR2(32000) DEFAULT ' '; -- The crosstab SQL
--v_SQL_Select VARCHAR2(32000) DEFAULT ' '; -- The crosstab SQL
v_SQL_From VARCHAR2(90) DEFAULT ' FROM JRNL_PURCHAS_VW J '; -- The crosstab SQL
-- v_SQL_Where VARCHAR2(32000) DEFAULT ' '; -- The crosstab SQL
v_SQL_GroupBy VARCHAR2(32000) DEFAULT ' '; -- The crosstab SQL
--v_SQL_YAxisFields LONG DEFAULT ' '; -- The crosstab SQL
-- v_SQL_xAxisFields VARCHAR2(32000) DEFAULT ' '; -- The crosstab SQL
v_SQL_xAxisFields LONG DEFAULT ' '; -- The crosstab SQL
-- v_query totals_settings.ucrfs_query%TYPE;
rc_xAxisValues SYS_REFCURSOR;
v_xAxisValues VARCHAR2(32000) DEFAULT ''; -- The crosstab SQL values that go across the result grid
v_CrosstabColumns VARCHAR2(32000) DEFAULT ''; -- The concatenated list of crosstab SQL values that go across the result grid
v_Friendly_Field VARCHAR2(32000) DEFAULT ''; -- The friendly name of the Y axis field
x_ViewAlreadyExists EXCEPTION;
v_xaxis VARCHAR2(90) DEFAULT p_xaxis; -- A copy of the parameter
v_yaxis VARCHAR2(90) DEFAULT p_yaxis; -- A copy of the parameter
-- array of anydata
TYPE t_xAxisValues IS TABLE OF LONG
INDEX BY BINARY_INTEGER;
a_xAxisValues t_xAxisValues;
-- TYPE t_YAxisFields AS OBJECT (v_Fields VARCHAR2(10) );
-- va_YAxisFields VARRAY(100) t_YAxisFields;
BEGIN
-- Check login status
--IF totals_util.bad_login(p_session_id) then
-- RETURN;
--END IF;
-- Pull out the current query's WHERE clause
BEGIN
SELECT ts.ucrfs_query, upper(trim(ts.query_type))
INTO declarations.gv_query, declarations.gv_query_type
FROM totals_settings ts
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => '/1/ totals.create_crosstab_sql');
RETURN ;
END;
-- Get the WHERE clause
IF declarations.gv_query IS NOT NULL THEN
-- Need to replace all single quotes with 2 single quotes
declarations.gv_query := REPLACE(declarations.gv_query, '''', '''''');
-- Use regular expressions to pull out the third back reference, meaning the WHERE clause
IF declarations.gv_query_type = 'D' THEN
declarations.gv_regexp := 'SELECT(.*)FROM(.*)WHERE(.*)ORDER BY(.*)';
ELSE
declarations.gv_regexp := 'SELECT(.*)FROM(.*)WHERE(.*)GROUP BY(.*)ORDER BY(.*)';
END IF;
BEGIN
SELECT trim(REGEXP_REPLACE(declarations.gv_query, declarations.gv_regexp, '\3') )
INTO declarations.gv_SQL_Where
FROM dual;
EXCEPTION
WHEN no_data_found THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => '/2/ totals.create_crosstab_sql');
RETURN ;
END;
-- Now replace the double single quotes with a single quote
declarations.gv_SQL_Where := ' WHERE ' || REPLACE(declarations.gv_SQL_Where, '''''', '''');
-- These are the values that go across, called the Y axis
/* -- Example:
SELECT DISTINCT J.PO_ID
FROM JRNL_PURCHAS_VW J
WHERE BUSINESS_UNIT = 'UCR'
AND J.FISCAL_YEAR IN (2007)
AND J.ACCOUNTING_PERIOD IN ('07')
AND J.ORG_CODE IN ('ORG21')
AND J.SOURCE IN ('ATP')
AND J.LEDGER IN ('ACTUALS')
ORDER BY J.PO_ID
*/
-- Get a list of y axis values based on the WHERE clause
-- and collect this into an array of values that represent the x axis in the crosstab grid
--IF INSTR(upper(trim(p_xaxis)), '_DESCR') <> 0 THEN
-- OPEN rc_xAxisValues FOR 'SELECT DISTINCT ' || p_xaxis || ' (' || REPLACE(upper(p_xaxis), '_DESCR') || ') ' || v_SQL_From || gv_SQL_Where || ' ORDER BY 1';
--ELSE
-- Replace those apos with a null
BEGIN
SELECT trim(translate(p_xaxis, '".&', ' '))
INTO v_xaxis
FROM dual;
END;
BEGIN
OPEN rc_xAxisValues FOR 'SELECT DISTINCT ' || v_xaxis || v_SQL_From || declarations.gv_SQL_Where || ' ORDER BY 1';
END;
--END IF;
LOOP
FETCH rc_xAxisValues INTO v_xAxisValues;
EXIT WHEN rc_xAxisValues%NOTFOUND;
-- one must ward against null values in the query
IF TRIM(v_xAxisValues) IS NOT NULL THEN
a_xAxisValues(v_Counter) := v_xAxisValues;
-- Get rid of any commas since we're going to later parse on those for column headers
v_CrosstabColumns := v_CrosstabColumns || replace(v_xAxisValues, ',', '') || ',';
ELSE
-- use the word (Empty) for now to signify an empty value on the X axis.
a_xAxisValues(v_Counter) := '(Empty)';
v_CrosstabColumns := v_CrosstabColumns || '(Empty)' || ',';
END IF;
v_Counter := v_Counter + 1;
END LOOP;
CLOSE rc_xAxisValues;
-- This is used for empty values going across the grid,
--v_SQL_xAxisFields := 'SUM(CASE WHEN nvl(TRIM(' || REPLACE(p_xaxis, '''', '') || '), ''(Empty)'') = ''(Empty)'' THEN J.FOREIGN_AMOUNT ELSE NULL END) "(Empty)",';
-- Replace those apos with a null
v_xaxis := REPLACE(p_xaxis, '''', '');
-- Now that we have the values, construct a string that will be used in the main crosstab SQL
-- v_SQL_xAxisFields := v_SQL_xAxisFields || ', ' || v_xAxisValues;
FOR v_Counter IN 0..a_xAxisValues.COUNT LOOP
IF a_xAxisValues.exists(v_Counter) THEN
-- If a blank was found then use IS NULL instead of = 'something'
IF instr(upper(a_xAxisValues(v_Counter)), 'EMPTY') <> 0 THEN
v_SQL_xAxisFields := v_SQL_xAxisFields || ' SUM(CASE WHEN TRIM(' || v_xaxis || ') IS NULL THEN J.FOREIGN_AMOUNT ELSE NULL END) "(Empty)", ';
ELSE
-- 8 single apostrophes...
v_SQL_xAxisFields := v_SQL_xAxisFields || ' SUM(CASE WHEN TRIM(REPLACE(' || p_xaxis || ', '''''''', NULL)) = ''' || trim(replace(a_xAxisValues(v_Counter), '''', '')) || ''' THEN J.FOREIGN_AMOUNT ELSE NULL END) "' || nvl(trim(a_xAxisValues(v_Counter)), 'NONE') || '", ';
END IF;
END IF;
END LOOP;
-- Get the friendly name of the Y axis fields
v_Friendly_Field := get_FriendlyFieldName(p_yaxis);
/*
BEGIN
SELECT f.User_Friendly
INTO v_Friendly_Field
FROM totals_field_lookup f
WHERE f.table_field = TRIM(upper(p_yaxis));
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => '\1\ totals.crosstab');
RETURN;
END;
*/
-- We must ward against null values in our query
v_yaxis := 'TRIM(' || p_yaxis || ')';
-- The main crosstab SQL, for example
-- SELECT DECODE(GROUPING(J.VOUCHER_ID), 1, 'All Vouchers', J.VOUCHER_ID) AS "Voucher ID",
-- Also, embed the session id as a column
-- v_SQL := 'SELECT ''' || p_session_id || ''' SESSION_ID,''' || to_char(SYSDATE, 'DD-MON-YYYY HH:MI:SS') || ''' CREATE_DATE, ' || ' DECODE(GROUPING(' || p_yaxis || '), 1, ''All Values'', ' || p_yaxis || ') AS "' || v_Friendly_Field || '", ' || v_SQL_xAxisFields ;
-- v_SQL := 'SELECT DECODE(GROUPING(' || v_yaxis || '), 1, ''[·Column Totals·]'', NVL(' || v_yaxis || ','' (Empty)'')) AS "' || v_Friendly_Field || '", ' || v_SQL_xAxisFields ;
v_SQL := 'SELECT DECODE(GROUPING(' || v_yaxis || '), 1, ''[Column Totals]'', NVL(' || v_yaxis || ','' (Empty)'')) AS "' || v_Friendly_Field || '", ' || v_SQL_xAxisFields ;
-- v_SQL := 'SELECT DECODE(GROUPING(' || v_yaxis || '), 1, ''_Column Totals'', NVL(' || v_yaxis || ','' (Empty)'')) AS "' || v_Friendly_Field || '", ' || v_SQL_xAxisFields ;
v_SQL_GroupBy := ' GROUP BY ROLLUP(' || v_yaxis || ') ';
v_SQL := v_SQL || ' SUM(CASE WHEN 1 = 1 THEN J.FOREIGN_AMOUNT ELSE NULL END) "Total" ' || v_SQL_From || declarations.gv_SQL_Where || v_SQL_GroupBy || ' ORDER BY 1';
-- DBMS_OUTPUT.put_line(v_SQL);
-- DEBUG - Cannot assume we can overwrite an existing view. But for now...
--BEGIN
-- EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW TMP_CROSSTAB_VW AS ' || v_SQL;
--END;
-- Return a ref cursor to the calling program which will do the actual fetching of data
--OPEN rc_Crosstab FOR v_SQL;
-- RETURN rc_Crosstab;
-- Clean up the crosstab settings table for this session in order to insert new data for this run
BEGIN
EXECUTE IMMEDIATE 'DELETE FROM totals_crosstab_settings xt WHERE xt.session_id = :1' USING p_session_id;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
htp.p('There was an error deleting from the totals_crosstab_settings table; ' || SQLERRM);
END;
BEGIN
EXECUTE IMMEDIATE 'INSERT INTO totals_crosstab_settings xt VALUES (:1, :2, :3, :4, :5, :6)'
-- NO: The v_Counter + 1 is for the (Empty) column used in
USING p_session_id, v_SQL, v_CrosstabColumns, upper(p_xaxis), upper(p_yaxis), v_Counter;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
htp.p('There was an error inserting into the totals_crosstab_settings table; ' || SQLERRM);
htp.p('p_session_id = ' || p_session_id);
htp.p('v_SQL = ' || v_SQL);
htp.p('v_CrosstabColumns = ' || v_CrosstabColumns);
htp.p('p_xaxis = ' || p_xaxis);
htp.p('p_yaxis = ' || p_yaxis);
htp.p('v_Counter = ' || v_Counter);
RETURN;
END;
--RETURN v_SQL;
ELSE
--RETURN
NULL;
END IF; --IF v_query IS NOT NULL THEN
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id, p_SQLERRM => SQLERRM, p_CalledFrom => '/3/ totals.create_crosstab_sql');
RETURN ;
END; -- create_crosstab_view
-- -------------------------------------------------------------------------------------
-- Procedure: execute_crosstab
-- Programmer: Brian Griffin
-- Create On: March 13, 2007
-- Purpose: To run a crosstab query in Oracle and display the results on a webpage
-- -------------------------------------------------------------------------------------
PROCEDURE execute_crosstab(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_RunCrosstab IN VARCHAR2 DEFAULT 'FALSE',
p_crosstab_xaxis IN VARCHAR2 DEFAULT 'x',
p_crosstab_yaxis IN VARCHAR2 DEFAULT 'y',
p_Btn_Submit IN VARCHAR2 DEFAULT NULL,
p_Btn_FlipAxis IN VARCHAR2 DEFAULT NULL,
p_Btn_ExportExcel IN VARCHAR2 DEFAULT NULL) IS
v_Start NUMBER DEFAULT 0; -- String parsing
v_Pos NUMBER DEFAULT 0; -- String parsing
v_selected_tab_fields VARCHAR2(32000) DEFAULT ''; -- The selected fields from the tabs used for crosstab x and y axes
v_Column_Name VARCHAR2(50);
v_friendly VARCHAR2(50);
v_SQL VARCHAR2(32000) DEFAULT ''; -- The crosstab SQL
v_CrosstabColumns VARCHAR2(32000) DEFAULT ''; -- The crosstab SQL columns
v_ddl_cursor INTEGER :=0; -- SQL cursor
v_data VARCHAR2(4000); -- Current data from SQL statement to be printed out
v_NumRows INTEGER;
v_Counter INTEGER;
v_rowclass VARCHAR2(30) DEFAULT ' class="tabledatarow" '; -- for alternating row colors
v_crosstab_xaxis VARCHAR2(30) DEFAULT ' ';
v_crosstab_yaxis VARCHAR2(30) DEFAULT ' ';
v_CurrentRowField VARCHAR2(100) DEFAULT ' '; -- The current row's header value, ie: A01375
v_CrosstabWhere LONG DEFAULT ' '; -- The current row x column intersecting values put into a WHERE clause, ie: ' AND (FUND_CODE = '19900' and JOURNAL_ID = '0000123456' )
v_SQL_Num_Columns totals_crosstab_settings.Sql_Num_Columns%TYPE DEFAULT 0; -- The number of SQL columns to parse thru
v_ErrorMsg LONG DEFAULT ''; -- any error message that might occur whilst processing
-- array of anydata
TYPE t_CrosstabColumns IS TABLE OF VARCHAR2(32000)
INDEX BY BINARY_INTEGER;
a_CrosstabColumns t_CrosstabColumns; -- The crosstab SQL columns
BEGIN
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
-- If the user is flipping the axis...
IF p_Btn_FlipAxis IS NOT NULL THEN
v_crosstab_xaxis := p_crosstab_yaxis;
v_crosstab_yaxis := p_crosstab_xaxis;
-- Otherwise...
ELSE
v_crosstab_xaxis := p_crosstab_xaxis;
v_crosstab_yaxis := p_crosstab_yaxis;
END IF;
-- If the user is exporting to Excel
IF p_Btn_ExportExcel IS NOT NULL THEN
owa_util.mime_header(ccontent_type => 'application/vnd.ms-excel');
-- Otherwise, render the page normally.
ELSE
-- Start rendering the webpage
-- htp.p('');
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - Crosstab Results');
-- Get the CSS information
totals_dhtml.get_CSS(p_session_id, 'CROSSTAB_GRID');
htp.headClose;
-- Get the javascript functions for the result grid
-- totals.get_resultgrid_js(p_action, v_USER_ID, v_UCRFS_QUERY, p_session_id);
htp.bodyOpen(cbackground => 'white', cattributes => 'topmargin=0 leftmargin=0');
totals_util.get_TitleImages;
htp.para;
-- Show default page options menu
totals_util.get_PageOptionsMenu(TRUE);
-- Get the
element for the tooltip information
totals_dhtml.get_tooltip_DIV;
-- Declare Javascript functions
totals_dhtml.get_tooltip_js(p_session_id);
totals_dhtml.get_drilldown_js(p_session_id);
-- Get the "Standard Fields" and create 2 drop down lists populated with this data
BEGIN
SELECT standard_tab_fields || descr_tab_fields
INTO v_selected_tab_fields
FROM totals_settings ts
WHERE ts.session_id = p_session_id
ORDER BY 1;
END;
-- Break this string of comma delimited values into an array that we can loop thru
-- Using the "Standard Fields" selections, create 2 drop down lists populated with this data
htp.formOpen(curl => 'totals.execute_crosstab',
cmethod => 'POST',
cattributes => 'name="frm_crosstab_fields" ');
htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
htp.formHidden(cname => 'p_RunCrosstab', cvalue => 'TRUE');
v_Start := 1;
v_Pos := instr(v_selected_tab_fields, ', ');
-- A table to contain the form elements in a nice format
htp.p('
');
htp.p('
Column Headers
');
htp.p('
Row Headers
');
htp.p('
');
htp.p('
');
--htp.p('
');
htp.p('
');
htp.p('
');
-- The first drop down list box for the x axis
htp.formSelectOpen(cname => 'p_crosstab_xaxis',
nsize => 1,
cattributes => 'id="p_crosstab_xaxis" class="tabledatarow" ' );
-- Loop thru the comma delimited values to populate the drop down list box
WHILE v_Pos > 0 LOOP
v_Column_Name := substr(v_selected_tab_fields, v_Start, v_Pos - v_Start) || ', ';
BEGIN
v_friendly := get_FriendlyFieldName(v_Column_Name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
htp.p('');
END;
-- Exclude amounts
IF INSTR(v_Column_Name, 'AMOUNT') = 0 THEN
IF v_crosstab_xaxis = v_Column_Name THEN
htp.p('');
ELSE
htp.p('');
END if;
END IF;
v_Start := v_Pos + 2;
v_Pos := instr(v_selected_tab_fields, ', ', v_Start);
END LOOP;
htp.formSelectClose;
-- A table to contain the form elements in a nice format
htp.p('
');
v_Start := 1;
v_Pos := instr(v_selected_tab_fields, ', ');
-- The second drop down list box for the y axis
htp.formSelectOpen(cname => 'p_crosstab_yaxis',
nsize => 1,
cattributes => 'id="p_crosstab_yaxis" class="tabledatarowlight" ' );
-- Loop thru the comma delimited values to populate the drop down list box
WHILE v_Pos > 0 LOOP
v_Column_Name := substr(v_selected_tab_fields, v_Start, v_Pos - v_Start) || ', ';
BEGIN
v_friendly := get_FriendlyFieldName(v_Column_Name);
EXCEPTION
WHEN NO_DATA_FOUND THEN
htp.p('');
END;
-- Exclude amounts
IF INSTR(v_Column_Name, 'AMOUNT') = 0 THEN
IF v_crosstab_yaxis = v_Column_Name THEN
htp.p('');
ELSE
htp.p('');
END if;
END IF;
v_Start := v_Pos + 2;
v_Pos := instr(v_selected_tab_fields, ', ', v_Start);
END LOOP;
htp.formSelectClose;
-- A table to contain the form elements in a nice format
htp.p('
');
-- A button to flip the axis
htp.formSubmit(cname => 'p_Btn_FlipAxis', cvalue => ' Flip ', cattributes => ' class="tablehead" ');
htp.p('
');
-- A button to export to excel
htp.formSubmit(cname => 'p_Btn_ExportExcel', cvalue => ' Excel ', cattributes => ' class="tablehead" ');
htp.p('
');
-- A table to contain the form elements in a nice format
htp.p('
');
htp.formClose;
END IF; --IF p_Btn_ExportExcel IS NOT NULL THEN
-- If the user has made a selection and is now running the query
-- or they choose to flip their query selections
IF p_RunCrosstab = 'TRUE' OR p_Btn_FlipAxis IS NOT NULL THEN
-- Certain look up values need to be handled differently than just stripping off the commas and j.
CASE TRIM(UPPER(v_crosstab_xaxis))
WHEN 'SUBSTR(J.DESCR254,1,30),'
THEN v_crosstab_xaxis := 'SUBSTR(J.DESCR254,1,30)';
WHEN 'DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00) TEMP'
THEN v_crosstab_xaxis := 'DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)';
WHEN 'DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00) PERM'
THEN v_crosstab_xaxis := 'DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00)';
WHEN 'DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00) ACTUALS'
THEN v_crosstab_xaxis := 'DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00)';
WHEN 'SUM(J.FOREIGN_AMOUNT)'
THEN v_crosstab_xaxis := 'SUM(J.FOREIGN_AMOUNT)';
WHEN 'SUM(J.STATISTIC_AMOUNT)'
THEN v_crosstab_xaxis := 'SUM(J.STATISTIC_AMOUNT)';
WHEN 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)) TEMP'
THEN v_crosstab_xaxis := 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00))';
WHEN 'SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00)) ACTUALS'
THEN v_crosstab_xaxis := 'SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00))';
WHEN 'SUM(DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00)) PERM'
THEN v_crosstab_xaxis := 'SUM(DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00))';
WHEN 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)) - SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00))'
THEN v_crosstab_xaxis := 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)) - SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00))';
ELSE
-- Cut out the leading j. and trailing comma
v_crosstab_xaxis := REPLACE(REPLACE(v_crosstab_xaxis, 'j.'), ',', '') ;
END CASE;
--if trim(upper(v_crosstab_xaxis)) = 'SUBSTR(J.DESCR254,1,30),' then
-- v_crosstab_xaxis := 'SUBSTR(J.DESCR254,1,30)';
--else
-- v_crosstab_xaxis := REPLACE(REPLACE(v_crosstab_xaxis, 'j.'), ',', '') ;
--end if;
-- Certain look up values need to be handled differently than just stripping off the commas and j.
CASE TRIM(UPPER(v_crosstab_yaxis))
WHEN 'SUBSTR(J.DESCR254,1,30),'
THEN v_crosstab_yaxis := 'SUBSTR(J.DESCR254,1,30)';
WHEN 'DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00) TEMP'
THEN v_crosstab_yaxis := 'DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)';
WHEN 'DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00) PERM'
THEN v_crosstab_yaxis := 'DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00)';
WHEN 'DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00) ACTUALS'
THEN v_crosstab_yaxis := 'DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00)';
WHEN 'SUM(J.FOREIGN_AMOUNT)'
THEN v_crosstab_yaxis := 'SUM(J.FOREIGN_AMOUNT)';
WHEN 'SUM(J.STATISTIC_AMOUNT)'
THEN v_crosstab_yaxis := 'SUM(J.STATISTIC_AMOUNT)';
WHEN 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)) TEMP'
THEN v_crosstab_yaxis := 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00))';
WHEN 'SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00)) ACTUALS'
THEN v_crosstab_yaxis := 'SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00))';
WHEN 'SUM(DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00)) PERM'
THEN v_crosstab_yaxis := 'SUM(DECODE(LEDGER,''PERM'',FOREIGN_AMOUNT,0.00))';
WHEN 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)) - SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00))'
THEN v_crosstab_yaxis := 'SUM(DECODE(LEDGER,''TEMP'',FOREIGN_AMOUNT,0.00)) - SUM(DECODE(LEDGER,''ACTUALS'',FOREIGN_AMOUNT,0.00))';
ELSE
-- Cut out the leading j. and trailing comma
v_crosstab_yaxis := REPLACE(REPLACE(v_crosstab_yaxis, 'j.'), ',', '') ;
END CASE;
-- Create the sql for the crosstab
create_crosstab_sql(p_session_id => p_session_id, p_xaxis => v_crosstab_xaxis, p_yaxis => v_crosstab_yaxis );
-- and pull it out of the crosstab table
BEGIN
SELECT tcs.sql_statement, tcs.sql_column_names, tcs.sql_num_columns
INTO v_SQL, v_CrosstabColumns, v_SQL_Num_Columns
FROM totals_crosstab_settings tcs
WHERE session_id = p_session_id;
EXCEPTION
WHEN OTHERS THEN
v_ErrorMsg := v_ErrorMsg || 'There was a problem with the crosstab SQL near line ' || $$PLSQL_LINE || '. ' ;
v_ErrorMsg := v_ErrorMsg || ' v_SQL = ' || v_SQL || ' v_CrosstabColumns = ' || v_CrosstabColumns || ' v_SQL_Num_Columns = ' || v_SQL_Num_Columns || ' ';
END;
-- Ensure that the SQL statement is there
IF v_SQL IS NOT NULL AND v_SQL_Num_Columns > 0 THEN
v_ddl_cursor := dbms_sql.open_cursor;
BEGIN
dbms_sql.parse(v_ddl_cursor, v_SQL, dbms_sql.native);
EXCEPTION
WHEN OTHERS THEN
htp.p('Error in SQL Parse: ' || SQLERRM);
htp.br;
htp.p('SQL : ' || v_SQL);
RETURN;
END;
-- Use regular expressions to remove any letters or numbers, leaving only commas
-- Count the number of commas left behind, plus 2 for the first and last columns
-- THE FOLLOWING WAS REPLACED BY USING v_SQL_Num_Columns
--SELECT LENGTH(REGEXP_REPLACE(v_CrosstabColumns, '[A-Z|0-9]', '')) + 2
--INTO v_count
--FROM dual t;
-- Loop thru all the fields and define their columns
BEGIN
FOR v_Counter IN 1..v_SQL_Num_Columns + 2 LOOP
dbms_sql.define_column(v_ddl_cursor, v_Counter, v_data, 1000);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
v_ErrorMsg := v_ErrorMsg || 'There was a problem with defining columns near line ' || $$PLSQL_LINE || '; SQL Error: ' || SQLERRM || '. ' ;
END;
v_NumRows := dbms_sql.execute(v_ddl_cursor);
htp.comment('Encompassing Table');
htp.tableOpen(cattributes => 'cellpadding="5" xwidth="100%" border="0" bgcolor=white ');
-- Replace all spaces with non-breaking spaces to force the caption to be one single line of text and not shrunken up if this is a small crosstab grid
htp.tableCaption(ccaption => htf.bold(REPLACE('Crosstab Results for ' || get_FriendlyFieldName(v_crosstab_xaxis) || ' by ' || get_FriendlyFieldName(v_crosstab_yaxis), ' ', ' ') ), cattributes => 'class="rowheader" ' );
--htp.tableCaption(ccaption => v_crosstab_xaxis || ' ' || v_crosstab_yaxis);
htp.tableRowOpen;
-- If the user is not exporting to Excel
IF p_Btn_ExportExcel IS NULL THEN
-- The first column is the y axis column
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => 'Row' ,
cattributes => 'class="tablehead" valign="top" width="45px" ');
END IF;
-- Within this cell, create a 2 row, 1 column mini table for labelling the x and y axis fields, each a slightly different color
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
-- cvalue => replace(get_FriendlyFieldName(v_crosstab_xaxis), ' ID', '') ||'s:' || htf.hr(cattributes => 'width="100%"') || replace(get_FriendlyFieldName(v_crosstab_yaxis), ' ID', '') ||'s:',
cvalue => '
',
cattributes => 'class="rowheader" valign="top" align="center" xwidth="40px" ');
-- Create headers based on v_CrosstabColumns
v_Start := 1;
v_Pos := instr(v_CrosstabColumns, ',');
v_Counter := 1;
WHILE v_Pos > 0 LOOP
v_Column_Name := substr(v_CrosstabColumns, v_Start, v_Pos - v_Start);
-- Create and populate an array of the column headers. This will be used for a tooltip on the amount cells
a_CrosstabColumns(v_Counter) := replace(v_Column_Name, ',');
-- If the user is exporting to Excel
IF p_Btn_ExportExcel IS NOT NULL THEN
htp.tableData(calign => 'CENTER',
ccolspan => '1',
cvalue => v_Column_Name,
cattributes => ' valign="top" align="center" width="100px" ');
-- Otherwise the standard web page
ELSE
-- Don't put a tooltip on an empty row header
IF INSTR(upper(v_Column_Name), 'EMPTY') = 0 THEN
-- If the column value is...
IF instr(upper(v_crosstab_xaxis), 'PO_ID') <> 0 THEN
-- ... a PO Number
htp.tableData(calign => 'center',
cvalue => '' || htf.escape_sc(v_Column_Name) || '',
cattributes => 'class="xaxis_tablehead" valign="top" align="center" width="100px" ');
-- If the current field is a journal number, then create a link to drilldown into the journal_tbl table
ELSIF instr(upper(v_crosstab_xaxis), 'JOURNAL_ID') <> 0 THEN
htp.tableData(calign => 'center',
cvalue => '' || v_Column_Name || '',
cattributes => 'class="xaxis_tablehead" valign="top" align="center" width="100px" ');
-- a vendor number
ELSIF instr(upper(v_crosstab_xaxis), 'VENDOR_ID') <> 0 THEN
htp.tableData(calign => 'center',
cvalue => '' || v_Column_Name || '',
cattributes => 'class="xaxis_tablehead" valign="top" align="center" width="100px" ');
-- a voucher number
ELSIF instr(upper(v_crosstab_xaxis), 'VOUCHER_ID') <> 0 THEN
htp.tableData(calign => 'center',
cvalue => '' || htf.escape_sc(v_Column_Name) || '',
cattributes => 'class="xaxis_tablehead" valign="top" align="center" width="100px" ');
-- Otherwise, we don't know what it is...
ELSE
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => v_Column_Name,
cattributes => 'class="xaxis_tablehead" valign="top" align="center" width="100px" ');
END IF; --IF instr(upper(v_crosstab_xaxis), 'PO_ID') <> 0 THEN
ELSE
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => v_Column_Name,
cattributes => 'class="xaxis_tablehead" valign="top" align="center" width="100px" ');
END IF; -- IF INSTR(upper(v_Column_Name), 'EMPTY') <> 0 THEN
END IF; --IF p_Btn_ExportExcel IS NOT NULL THEN
v_Start := v_Pos + 1;
v_Pos := instr(v_CrosstabColumns, ',', v_Start);
v_Counter := v_Counter + 1;
END LOOP; --WHILE v_Pos > 0 LOOP
-- If the user is exporting to Excel
IF p_Btn_ExportExcel IS NOT NULL THEN
-- The last column for the row totals
htp.tableData(calign => 'CENTER',
ccolspan => '1',
cvalue => '[Row Totals]',
cattributes => 'valign="top" width="100px" ');
ELSE
-- The last column for the row totals
htp.tableHeader(calign => 'CENTER',
ccolspan => '1',
cvalue => '[Row Totals]',
cattributes => 'class="tablehead" valign="top" width="100px" ');
END IF; -- IF p_Btn_ExportExcel IS NOT NULL THEN
-- End of the row header
htp.tableRowClose;
-- Loop thru all the sql rows and create an HTML table row for the data
LOOP
IF dbms_sql.fetch_rows(v_ddl_cursor) > 0 THEN
htp.tableRowOpen;
-- If the user is exporting to Excel
IF p_Btn_ExportExcel IS NOT NULL THEN
-- Row number
--htp.tableData(calign => 'center',
-- cvalue => dbms_sql.last_row_count,
-- cattributes => ' width="45px" ');
NULL;
ELSE
-- Row number
htp.tableData(calign => 'center',
cvalue => dbms_sql.last_row_count,
cattributes => 'class="tablehead" width="45px" ');
END IF; --IF p_Btn_ExportExcel IS NOT NULL THEN
-- Loop thru all the columns and create a HTML table cell and place the data there
-- Add 2 for the first and last columns, which are the row header and row total columns
FOR v_Counter IN 1..v_SQL_Num_Columns + 2 LOOP
BEGIN
dbms_sql.column_value(v_ddl_cursor, v_Counter, v_data);
EXCEPTION
WHEN OTHERS THEN
--v_ErrorMsg := v_ErrorMsg || 'There was a problem with getting the column value near line ' || $$PLSQL_LINE || ', with counter = ' || v_Counter || ', and SQL Error: ' || SQLERRM || ', v_data = ' || v_data || '
' ;
-- htp.p(v_SQL);
htp.p('Error in getting column value, v_Counter = ' || v_Counter || '; v_data = ' || v_data);htp.br;
END;
-- If the user is exporting to Excel
IF p_Btn_ExportExcel IS NOT NULL THEN
-- If the first column...
IF v_Counter = 1 THEN
htp.tableData(calign => 'center',
cvalue => v_data,
cattributes => '' );
ELSE
v_data := nvl(TRIM(v_data), 0);
htp.tableData(calign => 'right',
cvalue => to_char(v_data, declarations.gk_MONEYFORMAT) ,
cattributes => v_rowclass );
END IF;
-- Otherwise...
ELSE
-- If the first column...
IF v_Counter = 1 THEN
v_CurrentRowField := v_data;
-- ... is a PO Number
-- and don't allow a hyperlink in the bottom row of data where the Column Totals label goes
IF instr(upper(v_crosstab_yaxis), 'PO_ID') <> 0 AND ( instr(upper(v_CurrentRowField), 'COLUMN') = 0 AND instr(upper(v_CurrentRowField), 'EMPTY') = 0) THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' || htf.escape_sc(v_data) || '',
cattributes => 'class="tablehead" valign="top" width="100px" ');
-- Left align description row headers
ELSIF instr(upper(v_crosstab_yaxis), 'DESCR') <> 0 THEN
htp.tableData(calign => 'left',
cvalue => v_data ,
cattributes => 'class="tablehead"');
ELSE
htp.tableData(calign => 'center',
cvalue => v_data ,
cattributes => 'class="tablehead"');
END IF;
-- If the last column
ELSIF v_Counter = v_SQL_Num_Columns + 2 THEN
v_data := nvl(TRIM(v_data), 0);
htp.tableData(calign => 'right',
cvalue => to_char(v_data, declarations.gk_MONEYFORMAT) ,
--cvalue => v_data,
cattributes => v_rowclass );
-- Otherwise in the middle
ELSE
-- if a blank cell
IF v_data IS NULL OR v_data = 0 THEN
htp.tableData(calign => 'right',
cvalue => ' ',
cattributes => 'class="tabledatarowlight"');
-- if an actual dollar amount
ELSE
-- if either x or y axis is a DESCRiption field, then don't allow drilldown on the amount in the cell
IF (INSTR(upper(v_crosstab_xaxis), 'DESCR') = 0 OR INSTR(upper(v_crosstab_yaxis), 'DESCR') = 0) THEN
-- A tilde is used in place of the single apostrophe since I get confused trying to figure that out. Later, REPLACE(v_SQL, '~', '''') is used to restore the string
BEGIN
v_CrosstabWhere := ' AND j.' || v_crosstab_xaxis || '=' || '~' || a_CrosstabColumns(v_Counter-1) || '~' || ' AND j.' || v_crosstab_yaxis || '=' || '~' || v_CurrentRowField || '~' || '';
EXCEPTION
WHEN OTHERS THEN
htp.p('Error near line: ' || $$PLSQL_LINE || ' ' || v_crosstab_xaxis);
END;
END IF;
-- If there is a '(Empty)' value on the Y axis, then don't hyperlink the value
-- If we are using a description in either the column or row header, then don't allow drilldown
IF INSTR(upper(v_CrosstabWhere), 'EMPTY') = 0 AND (INSTR(upper(v_crosstab_xaxis), 'DESCR') = 0 OR INSTR(upper(v_crosstab_yaxis), 'DESCR') = 0) THEN
htp.tableData(calign => 'right',
-- cvalue => to_char(v_data, declarations.gk_MONEYFORMAT) || '(' || v_crosstab_xaxis || '=' || a_CrosstabColumns(v_Counter-1) || ', ' || v_crosstab_yaxis || '=' || v_CurrentRowField || ')',
-- cvalue => '' || to_char(v_data, declarations.gk_MONEYFORMAT) || '',
cvalue => '' || to_char(v_data, declarations.gk_MONEYFORMAT) || '',
cattributes => 'class="tabledatarowlight"');
ELSE
htp.tableData(calign => 'right',
cvalue => to_char(v_data, declarations.gk_MONEYFORMAT),
cattributes => 'class="tabledatarowlight"');
END IF; -- IF INSTR(upper(v_CrosstabWhere), 'EMPTY') = 0 AND ... THEN
END IF; -- IF v_data IS NULL /*OR v_data = 0 */THEN
END IF; -- IF v_Counter = 1 THEN
END IF;
END LOOP; -- FOR v_Counter IN 1..v_SQL_Num_Columns + 2 LOOP
htp.tableRowClose;
ELSE
EXIT;
END IF;
END LOOP;
htp.tableClose;
htp.p;htp.br;
htp.italic('Please Note:');
htp.p;htp.br;
htp.italic('If you see an (Empty) row or column in the query above, then that represents the summarization of all blank values per the other crosstab field. ');
htp.p;htp.br;
--htp.p;htp.br;
--htp.italic('Tip:');
--htp.p;htp.br;
--htp.italic('Press the control (Ctrl) and scroll your mouse wheel to increase or decrease the font size of this page.');
ELSE ----IF v_SQL IS NOT NULL THEN
v_ErrorMsg := v_ErrorMsg || 'There was a problem with v_SQL near line: ' || $$PLSQL_LINE || ', v_SQL = ' || v_SQL || ', and SQL Error: ' || SQLERRM || '. ' ;
END IF; --IF v_SQL IS NOT NULL THEN
ELSE --IF p_RunCrosstab = TRUE THEN
htp.p('
');
htp.p('Instructions:');
htp.p;htp.br;
htp.p('To run a crosstab query, first select the field that you would like to see going horizontally across the grid. Then, select the field you would like to see going vertically down the grid. Then click the "Run" button to see the data.');
htp.p('The financial data within the grid is based on your latest query criteria. If you change the criteria, please rerun your Detail/Summary query and then refresh this page to load the most current settings.');
htp.p('
');
END IF; --IF p_RunCrosstab = TRUE THEN
-- If there are any errors to show
IF v_ErrorMsg IS NOT NULL THEN
htp.p(v_ErrorMsg);htp.br;
htp.p('v_SQL= ' || v_SQL);htp.br;
END if;
htp.p;htp.br;htp.p;htp.br;htp.p;htp.br;
-- htp.p('v_SQL= ' || v_SQL);htp.br;
htp.bodyClose;
htp.htmlClose;
-- COMMENT: This section of code attempts to use dynamic SQL, which proved to be too difficult
/* -- Create a crosstab view
rc_Crosstab := create_crosstab_view(p_session_id => p_session_id, p_xaxis => 'DEPTID', p_yaxis => 'VOUCHER_ID');
IF rc_Crosstab IS NOT NULL THEN
-- Loop thru all the rows
LOOP
FETCH rc_Crosstab INTO r_Crosstab;
EXIT WHEN rc_Crosstab%NOTFOUND;
DBMS_OUTPUT.put_line(' Session = ' || r_Crosstab."SESSION_ID");
-- If the session id of the crosstab view matches the current session id
IF r_Crosstab."SESSION_ID" = p_session_id THEN
FOR c_Rec IN c_ViewColumns LOOP
v_Column_Name := c_Rec.Column_Name;
r_Crosstab. v_Column_Name;
END LOOP;
END IF;
DBMS_OUTPUT.put_line(' Date = ' || r_Crosstab."CREATE_DATE");
DBMS_OUTPUT.put_line(' Total = ' || r_Crosstab."Total");
END LOOP;
-- Get rid of this user's view so another user may create their own
BEGIN
EXECUTE IMMEDIATE 'DROP VIEW TMP_CROSSTAB_VW ';
END;
CLOSE rc_Crosstab;
END IF; -- IF rc_Crosstab IS NOT NULL THEN
*/
END; -- execute_crosstab
-- -------------------------------------------------------------------------------------
-- Procedure: execute_report
-- Programmer: Brian Griffin
-- Create On: August 13, 2007
-- Purpose: To run a report from the Report tab
-- Parameters:
-- p_session_id
-- p_ReportName - The hard coded name of the report to run
-- p_RunControlID - The users run control id
--
-- Issue #6343 : Remove the Excel Web Functionality in IE
--
-- -------------------------------------------------------------------------------------
PROCEDURE execute_report(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL,
p_Report_Name IN totals_settings.session_id%TYPE DEFAULT NULL,
p_SISDetail_Options IN owa_util.vc_arr,
p_RunControlID IN totals_settings.session_id%TYPE DEFAULT NULL)
IS
n_SumAmount journal_tbl.foreign_amount%TYPE DEFAULT 0; -- Sum the amount column for a final row
v_rowclass VARCHAR2(60) DEFAULT ' class="tabledatarow" '; -- for alternating row colors
v_HeaderClass VARCHAR2(60) DEFAULT ' class="tablehead" '; -- for table column headers
v_NumCols INTEGER := 0; -- Number of columns
rowCnt INTEGER := 0; -- row counter
label INTEGER := 0; -- a label for the row number
--ddl_cursor INTEGER :=0; -- SQL cursor
rows_processed INTEGER := 0; -- number of rows processed
--v_data VARCHAR2(4000); -- Current data from SQL statement to be printed out
v_StartPos INTEGER := 0;
v_Pos INTEGER := 0;
v_CurrentField VARCHAR2(1000) := ''; -- Current field being analyzed
n_TableWidth CONSTANT NUMBER := 1200;
BEGIN
IF totals_util.bad_login(p_session_id) THEN
RETURN;
END IF;
-- Before running the report, update the report's SQL
totals_update.update_reports_tab(p_session_id => p_session_id,
p_link => '', -- use a null so as to not redirect away from this procedure
p_report_name => p_Report_Name,
p_RunControlID => 'ADHOC',
-- p_SISDetail_Options => p_SISDetail_Options,
p_RunReport_SISJournal => '');
v_NumCols := 11; -- 11 columns across
-- Start rendering the webpage
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.p('');
htp.title(ctitle => 'UCRFStotals - Report Results');
-- Get the CSS information
totals_dhtml.get_CSS(p_session_id, 'RESULT_GRID');
htp.p('
');
htp.headClose;
-- Get the javascript functions for the result grid
htp.bodyOpen(cbackground => 'white',
cattributes => 'topmargin=0 leftmargin=0');
-- Declare Javascript functions
totals_dhtml.get_excel_js(p_session_id);
totals_util.get_TitleImages;
htp.para;
-- Table for title
htp.tableOpen(cattributes => 'width="100%" border="0" class="" id="header" cols=4');
htp.tableRowOpen();
htp.tableData(cvalue => 'SIS Detail Report ', ccolspan => 4);
htp.tableRowClose;
htp.tableRowOpen();
htp.tableData(cvalue => 'Parameters: Fiscal Year=' || '?' ||
', Accounting Period=' || '?' ||
', Org Code=' || '?' || ', Fund Code=' ||
'?' || ', Function=' || '?' || ', Subcode=' || '?',
ccolspan => 4);
htp.tableRowClose;
htp.tableClose;
-- Table for buttons
htp.tableOpen();
htp.tableRowOpen();
-- The OK button
htp.p('
');
-- The OK button
htp.p('');
htp.p('
');
-- The Print button
htp.p('
');
-- The Print button
htp.p('');
htp.p('
');
-- Cell for Excel button and the ? button
htp.p('
');
-- Form for
htp.formOpen(curl => 'exportquery.xls',
cmethod => 'POST',
ctarget => 'excel',
cattributes => 'name="frm_excel" xstyle="top: 0px; margin-top: -10px;"');
htp.formHidden(cname => 'p_session_id', cvalue => p_session_id);
htp.formClose;
-- Excel buttons
/* -- If the users browser is Internet Explorer, then paint 3 buttons: [Excel | Excel as Web | ?]
-- All the buttons are written together so that no gaps between the button show in the rendered HTML
IF instr(DECLARATIONS.gk_BROWSER_TYPE, 'msie') <> 0 THEN
htp.p('');
-- If the users browser is anything else, then paint 2 buttons: [Excel | ?]
-- since Firefox will always open Excel directly
ELSE
htp.p('');
END IF;
*/
-- Updated May 2013 to remove Excel Web functionality:
-- Issue #6343
htp.p('');
htp.p('
');
-- Cell for Tooltips
htp.p('
');
-- A checkbox to allow the user to choose whether or not tooltips will show
htp.p('');
htp.p('Show tooltips');
htp.p('
');
htp.tableRowClose;
htp.tableClose;
htp.p;
htp.br;
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- Create a table for the SIS Lines
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
htp.COMMENT('SIS Lines table');
htp.tableOpen(cattributes => ' id="data" class="sortable" width=' ||
n_TableWidth || 'px ');
-- Line information
htp.tableCaption(ccaption => htf.bold('SIS Lines Detail'),
cattributes => 'class="rowheader" ');
htp.tableRowOpen();
htp.tableHeader(cvalue => ' ',
cattributes => 'class="tablehead" xwidth="15px" ');
htp.tableHeader(cvalue => 'Student ID',
cattributes => 'align="center" class="tablehead" width="15px"');
htp.tableHeader(cvalue => 'Student Name',
cattributes => 'align="left" class="tablehead" width="30px"');
htp.tableHeader(cvalue => 'Year Term',
cattributes => 'class="tablehead" width="15px" ');
htp.tableHeader(cvalue => 'Trans Amount',
cattributes => 'class="tablehead" width="35px" ');
htp.tableHeader(cvalue => 'Paid Date',
cattributes => 'class="tablehead" xwidth="35px" ');
htp.tableHeader(cvalue => 'Paid Amount',
cattributes => 'class="tablehead" xwidth="35px" ');
htp.tableHeader(cvalue => 'Bill Date',
cattributes => 'class="tablehead" xwidth="35px" ');
--htp.tableHeader(cvalue => 'Due Date', cattributes => 'class="tablehead" ');
htp.tableHeader(cvalue => 'Receipt No.',
cattributes => 'class="tablehead" xwidth="25px" ');
htp.tableHeader(cvalue => 'Ext. Indicator',
cattributes => 'class="tablehead" width="15px" ');
htp.tableHeader(cvalue => 'Subcode Type ',
cattributes => 'class="tablehead" width="15px" ');
htp.tableHeader(cvalue => 'Subcode and Description',
cattributes => 'align="left" class="tablehead" xwidth="50px" ');
--htp.tableHeader(cvalue => 'Subcode Description', cattributes => 'class="tablehead" xwidth="50px"');
--htp.tableHeader(cvalue => 'Subcode Type', cattributes => 'class="tablehead" xwidth="25px" ');
htp.tableRowClose;
-- Get the SQL query to run from the Totals Reports table for this user
BEGIN
SELECT tr.SQL_SIS_JOURNALS
INTO DECLARATIONS.gv_query
FROM REPORT_PARAMS_SIS_DETAIL tr
WHERE tr.user_id = (SELECT DISTINCT s.user_id
FROM totals_settings s
WHERE s.session_id = p_session_id);
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id);
RETURN;
END;
BEGIN
DECLARATIONS.gv_cursor_handle := dbms_sql.open_cursor;
dbms_sql.parse(DECLARATIONS.gv_cursor_handle,
DECLARATIONS.gv_query,
dbms_sql.native);
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id,
p_Message => 'Problem with dbms_sql.parse; v_ucrfs_query = ' ||
DECLARATIONS.gv_query);
RETURN;
END;
BEGIN
-- Loop thru all the fields and define their columns
FOR i IN 1 .. v_NumCols LOOP
dbms_sql.define_column(DECLARATIONS.gv_cursor_handle,
i,
DECLARATIONS.gv_cursor_data,
1000);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
totals_util.error(p_session_id => p_session_id,
p_Message => 'Problem with dbms_sql.define_column; v_ucrfs_query = ' ||
DECLARATIONS.gv_query);
RETURN;
END;
rows_processed := dbms_sql.EXECUTE(DECLARATIONS.gv_cursor_handle);
rowCnt := 0;
-- When using Reg Exp on the query string, it must not have any carriage returns or else the reg expression will return the whole string
-- and not the part you wanted from the mask
BEGIN
SELECT TRIM(REGEXP_REPLACE(DECLARATIONS.gv_query,
'SELECT DISTINCT(.*)FROM(.*)WHERE(.*)ORDER BY(.*)',
'\1')) || ', '
INTO DECLARATIONS.gv_SQL_SELECT
FROM dual;
EXCEPTION
WHEN no_data_found THEN
totals_util.error(p_session_id => p_session_id,
p_Message => 'Problem using regexp on ' ||
DECLARATIONS.gv_query);
RETURN;
END;
-- Loop thru all the sql rows and create an HTML table row for the data
LOOP
IF dbms_sql.fetch_rows(DECLARATIONS.gv_cursor_handle) > 0 THEN
label := rowCnt;
rowCnt := rowCnt + 1;
-- Open the row
htp.tableRowOpen;
-- Alternating row colors
IF rowCnt MOD 2 = 0 THEN
v_rowclass := ' id="datarow" class="tabledatarow" ';
ELSE
v_rowclass := ' id="datarow" class="tabledatarowlight" ';
END IF;
-- Row number
htp.tableData(calign => 'center',
cvalue => rowCnt,
cattributes => v_rowclass);
-- Track which field we are on so we know when to hyperlink the Journal ID, or Voucher ID, etc...
-- Amble thru the list of selected fields and convert them into their friendly values
v_StartPos := 1;
v_Pos := instr(DECLARATIONS.gv_SQL_SELECT, ', ');
-- Report: Loop thru all the columns and create a HTML table cell and place the data there
FOR i IN 1 .. v_NumCols LOOP
-- Get the data
dbms_sql.column_value(DECLARATIONS.gv_cursor_handle,
i,
DECLARATIONS.gv_cursor_data);
DECLARATIONS.gv_cursor_data := TRIM(htf.escape_sc(DECLARATIONS.gv_cursor_data));
-- The current field in the gv_SQL_SELECT variable
v_CurrentField := substr(DECLARATIONS.gv_SQL_SELECT,
v_StartPos,
v_Pos - v_StartPos);
-- If the data returned has no real value
IF DECLARATIONS.gv_cursor_data = '' OR
DECLARATIONS.gv_cursor_data IS NULL THEN
DECLARATIONS.gv_cursor_data := ' ';
htp.tableData(calign => 'center',
cvalue => DECLARATIONS.gv_cursor_data,
cattributes => v_rowclass);
-- Otherwise a column with data in it
ELSE
-- If the last column, which is the Amount
--IF i = v_NumCols THEN
-- htp.tableData(calign => 'right',
-- cvalue => to_char(htf.escape_sc(DECLARATIONS.gv_cursor_data),
-- declarations.gk_MONEYFORMAT),
-- cattributes => v_rowclass);
--ELSE
-- If the current field is a journal id, then create a link to drilldown into the journal_tbl table
IF instr(upper(v_CurrentField), 'JOURNAL_ID') <> 0 THEN
htp.tableData(calign => 'center',
-- WAS: cvalue => '' || v_data || '',
cvalue => '' ||
DECLARATIONS.gv_cursor_data ||
'',
cattributes => v_rowclass);
-- If the current field is an account number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'ACCOUNT') <> 0 AND
instr(upper(v_CurrentField), 'ACCOUNTING') = 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' ||
DECLARATIONS.gv_cursor_data ||
'',
cattributes => v_rowclass ||
' style="cursor:hand" ');
-- If the current field is an activity number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'DEPTID') <> 0 AND
instr(upper(v_CurrentField), 'DESCR') = 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' ||
DECLARATIONS.gv_cursor_data ||
'',
cattributes => v_rowclass);
-- If the current field is an fund number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'FUND_CODE') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' ||
DECLARATIONS.gv_cursor_data ||
'',
cattributes => v_rowclass);
-- If the current field is an function number, then add a tooltip
ELSIF instr(upper(v_CurrentField), 'PROGRAM_CODE') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'center',
cvalue => '' ||
DECLARATIONS.gv_cursor_data ||
'',
cattributes => v_rowclass);
-- If the current field is the student name, then left align
ELSIF instr(upper(v_CurrentField), 'NAME') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'left',
cvalue => DECLARATIONS.gv_cursor_data ,
cattributes => v_rowclass);
-- If the current field is some amount, then right align
ELSIF instr(upper(v_CurrentField), '_AMT') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'right',
cvalue => '$' || to_char(DECLARATIONS.gv_cursor_data, declarations.gk_MONEYFORMAT) ,
cattributes => v_rowclass);
--n_SumAmount := n_SumAmount + DECLARATIONS.gv_cursor_data;
-- If the current field is a description field
ELSIF instr(upper(v_CurrentField), 'DESCR') <> 0 THEN
-- Create the table cell element
htp.tableData(calign => 'left',
cvalue => '' ||
DECLARATIONS.gv_cursor_data ||
'',
cattributes => v_rowclass);
ELSE
htp.tableData(calign => 'center',
cvalue => nvl(DECLARATIONS.gv_cursor_data, ' '),
cattributes => v_rowclass);
END IF; -- then add a tooltip
--END IF; -- IF i = v_NumCols THEN
END IF; -- IF DECLARATIONS.gv_cursor_data = '' OR DECLARATIONS.gv_cursor_data IS NULL THEN
v_StartPos := v_Pos + 2;
v_Pos := instr(DECLARATIONS.gv_SQL_SELECT, ', ', v_StartPos);
END LOOP; --FOR i IN 1..v_NumCols LOOP
htp.tableRowClose;
ELSE
EXIT;
END IF; -- IF dbms_sql.fetch_rows(ddl_cursor) > 0 THEN
END LOOP; -- Loop thru all the sql rows and create an HTML table row for the data
-- End Table data
htp.tableclose;
IF rowCnt = 0 THEN
htp.p('No data was found based on your report parameters. Please review your selections and try again...');
/* ELSE
-- Total amount table
htp.tableOpen(cattributes => 'cols=' || v_NumCols ||
' width="100%" border="0" class="" id="data" ');
htp.tableRowOpen;
htp.tableData(cvalue => 'Grand Total:',
ccolspan => v_NumCols - 1,
cattributes => v_rowclass);
htp.tableData(calign => 'right',
cvalue => to_char(htf.escape_sc(n_SumAmount),
declarations.gk_MONEYFORMAT),
cattributes => v_rowclass);
htp.tableRowClose;
htp.tableclose;
*/ END IF; -- IF rowCnt = 0 THEN
htp.p;
htp.br;
htp.p;
htp.br;
htp.p;
htp.br;
-- DEBUG:
-- htp.p('Query: ' || DECLARATIONS.gv_query);
-- Javascript for sorting a table by clicking on the table header
htp.p('');
-- Declare Javascript functions
totals_dhtml.get_tooltip_js(p_session_id);
totals_dhtml.get_drilldown_js(p_session_id);
-- Get the
element for the tooltip information
totals_dhtml.get_tooltip_DIV;
-- Javascript for sorting a table by clicking on the table header
htp.bodyClose;
htp.htmlClose;
END execute_report;
-- -------------------------------------------------------------------------------------
--
-- -------------------------------------------------------------------------------------
PROCEDURE settings(p_session_id IN totals_settings.session_id%TYPE DEFAULT NULL) IS
v_user_id totals_settings.user_id%type;
v_selected_fields totals_settings.selected_fields%type;
v_query_tab_fields totals_settings.query_tab_fields%type;
v_standard_tab_flds totals_settings.standard_tab_fields%type;
v_ucrfs_fa_flds totals_settings.fundaward_tab_fields%type;
v_ucrfs_desc_flds totals_settings.descr_tab_fields%type;
v_fiscal_years totals_settings.fiscal_years%type;
v_accounting_periods totals_settings.accounting_periods%type;
v_fund_types totals_settings.fund_types%type;
v_fund_categories totals_settings.fund_categories%type;
v_fund_groups totals_settings.fund_groups%type;
v_funds totals_settings.funds%type;
v_pi_codes totals_settings.pi_codes%type;
v_budgeted totals_settings.budgeted%type;
v_functions totals_settings.functions%type;
v_cost_centers totals_settings.cost_centers%type;
v_project_codes totals_settings.project_codes%type;
v_organization_codes totals_settings.organization_codes%type;
v_division_codes totals_settings.division_codes%type;
v_department_codes totals_settings.department_codes%type;
v_activity_codes totals_settings.activity_codes%type;
v_trans_classes totals_settings.trans_classes%type;
v_trans_types totals_settings.trans_types%type;
v_ledgers totals_settings.ledgers%type;
v_sources totals_settings.sources%type;
v_account_types totals_settings.account_types%type;
v_summary_accounts totals_settings.summary_accounts%type;
v_budget_categories totals_settings.budget_categories%type;
v_expense_groups totals_settings.expense_groups%type;
v_accounts totals_settings.accounts%type;
v_account_classes totals_settings.account_classes%type;
v_query_type totals_settings.query_type%type;
v_jid totals_settings.journal_ids%type;
v_voucherid totals_settings.voucher_id%type;
v_poid totals_settings.po_id%type;
v_vendorid totals_settings.vendor_id%type;
v_ucrfs_query totals_settings.ucrfs_query%type;
v_pretty_query long; --totals_settings.ucrfs_query%type;
v_mark_ITD_funds totals_user_prefs.mark_restricted_approp_funds%TYPE := '';
v_mark_approp_funds totals_user_prefs.mark_unrestricted_approp_funds%TYPE := '';
v_query_type_descr varchar2(10);
v_updated varchar2(20);
v_friendly varchar2(100);
v_selected long;
v_data long;
nstart number;
npos number;
BEGIN
IF totals_util.bad_login(p_session_id) then
RETURN;
END IF;
-- htp.p('');
htp.p(DECLARATIONS.gk_DOCTYPE);
htp.htmlOpen;
htp.headOpen;
htp.title(ctitle => 'UCRFStotals - Current Query Settings');
htp.p('');
htp.headClose;
SELECT USER_ID,
selected_fields,
QUERY_TAB_FIELDS,
STANDARD_TAB_FIELDS,
FUNDAWARD_TAB_FIELDS,
DESCR_TAB_FIELDS,
FISCAL_YEARS,
ACCOUNTING_PERIODS,
FUND_TYPES,
FUND_CATEGORIES,
FUND_GROUPS,
FUNDS,
PI_CODES,
BUDGETED,
FUNCTIONS,
COST_CENTERS,
PROJECT_CODES,
ORGANIZATION_CODES,
DIVISION_CODES,
DEPARTMENT_CODES,
ACTIVITY_CODES,
TRANS_CLASSES,
TRANS_TYPES,
LEDGERS,
SOURCES,
ACCOUNT_TYPES,
SUMMARY_ACCOUNTS,
BUDGET_CATEGORIES,
EXPENSE_GROUPS,
ACCOUNTS,
ACCOUNT_CLASSES,
QUERY_TYPE,
JOURNAL_IDS,
ts.voucher_id,
ts.po_id,
ts.vendor_id,
UCRFS_QUERY
INTO v_USER_ID,
v_selected_fields,
v_QUERY_TAB_FIELDS,
v_standard_tab_flds,
v_ucrfs_fa_flds,
v_ucrfs_desc_flds,
v_FISCAL_YEARS,
v_ACCOUNTING_PERIODS,
v_FUND_TYPES,
v_FUND_CATEGORIES,
v_FUND_GROUPS,
v_FUNDS,
v_PI_CODES,
v_BUDGETED,
v_FUNCTIONS,
v_COST_CENTERS,
v_PROJECT_CODES,
v_ORGANIZATION_CODES,
v_DIVISION_CODES,
v_DEPARTMENT_CODES,
v_ACTIVITY_CODES,
v_TRANS_CLASSES,
v_TRANS_TYPES,
v_LEDGERS,
v_SOURCES,
v_ACCOUNT_TYPES,
v_SUMMARY_ACCOUNTS,
v_BUDGET_CATEGORIES,
v_EXPENSE_GROUPS,
v_ACCOUNTS,
v_ACCOUNT_CLASSES,
v_QUERY_TYPE,
v_JID,
v_VoucherID,
v_POID,
v_VendorID,
v_UCRFS_QUERY
FROM TOTALS_SETTINGS ts
WHERE session_id = p_session_id;
-- Determine if the Appropriation / ITD type funds were selected
BEGIN
SELECT p.mark_restricted_approp_funds, p.mark_unrestricted_approp_funds
INTO v_mark_ITD_funds, v_mark_approp_funds
FROM totals_user_prefs p
WHERE p.user_id = v_USER_ID;
EXCEPTION WHEN OTHERS THEN
v_mark_ITD_funds := 'N';
v_mark_approp_funds := 'N';
END;
/*SELECT fiscal_years, accounting_periods, fund_types, fund_categories, fund_groups, funds, pi_codes, functions, cost_centers, project_codes, organization_codes, division_codes, department_codes, activity_codes, trans_classes, trans_types, ledgers, sources, account_types, summary_accounts, budget_categories, expense_groups, accounts, account_classes
INTO settingsFields(1), settingsFields(2), settingsFields(3), settingsFields(4), settingsFields(5), settingsFields(6), settingsFields(7), settingsFields(8), settingsFields(9), settingsFields(10), settingsFields(11), settingsFields(12), settingsFields(13), settingsFields(14), settingsFields(15), settingsFields(16), settingsFields(17), settingsFields(18), settingsFields(19), settingsFields(20), settingsFields(21), settingsFields(22), settingsFields(23), settingsFields(24)
FROM totals_settings
WHERE session_id = p_session_id;*/
IF v_QUERY_TYPE = 'D' THEN
v_Query_Type_Descr := 'Detail';
ELSIF v_QUERY_TYPE = 'S' THEN
v_Query_Type_Descr := 'Summary';
END IF;
-- force to null for debugging
v_UCRFS_QUERY := '';
IF v_UCRFS_QUERY IS NULL THEN
v_UCRFS_QUERY := totals_util.generate_query(p_session_id);
END IF;
htp.p('
');
htp.bodyOpen;
htp.p(totals_util.tab_headers(p_session_id => p_session_id,
p_tab => 'settings',
p_sub_section => '',
p_query_tab_selection => ''));
htp.formOpen(curl => 'totals.redirect',cmethod => 'POST');
htp.formHidden(cname => 'p_session_id',cvalue => p_session_id);
htp.formHidden(cname => 'p_link');
htp.formClose;
htp.comment('Begin Encompassing Table');
htp.tableOpen(cattributes => ' width="650" cellpadding="5"');
htp.tableRowOpen;
htp.p('