Files
mip/Data/BulkLoad/EFT/Nominations/Changes/Aug_2010/efnow095$.bdy

1196 lines
46 KiB
Plaintext

CREATE OR REPLACE PACKAGE BODY efnow095$ IS
--
--
--
PROCEDURE calendar( z_field_name IN VARCHAR2
, z_caller_url IN VARCHAR2
, z_field_value IN VARCHAR2 DEFAULT NULL
, z_field_format IN VARCHAR2 DEFAULT NULL
, z_field_prompt IN VARCHAR2 DEFAULT NULL )
IS
--
field_caption VARCHAR2(2000);
--
BEGIN
--
IF z_field_prompt IS NULL THEN
--
field_caption := initcap(REPLACE( substr( z_field_name
, 3
, length(z_field_name) - 2)
, '_'
, ' ' ));
--
ELSE
--
field_caption := initcap(REPLACE( z_field_prompt
, '_'
, ' ' ));
--
END IF;
--
wsgl.registerurl( g_package_name || '.calendar');
wsgl.addurlparam( 'Z_FIELD_NAME', z_field_name );
wsgl.addurlparam( 'Z_CALLER_URL', z_caller_url );
--
IF wsgl.notlowercase THEN
RETURN;
END IF;
--
wsgl.output_calendar( z_field_name
, z_field_value
, z_field_format
, wsgl.msggettext( 123
, wsglm.dsp128_cal_caption
, field_caption )
, NULL
, g_package_name
, 'Close'
, TRUE
, 'DD-MON-RRRR' );
--
wsgl.output_calendar( z_field_name
, z_field_value
, z_field_format
, wsgl.msggettext( 123
, wsglm.dsp128_cal_caption
, field_caption )
, NULL
, g_package_name
, 'Close'
, FALSE
, 'DD-MON-RRRR' );
--
EXCEPTION
WHEN OTHERS THEN
wsgl.displaymessage( wsgl.mess_exception
, SQLERRM
, ''
, NULL
, g_package_name || '.calendar' );
END calendar;
--
--
--
PROCEDURE format_cal_date( z_field_name IN VARCHAR2
, z_field_format IN VARCHAR2
, DAY IN VARCHAR2
, MONTH IN VARCHAR2
, YEAR IN VARCHAR2 )
IS
--
field_caption VARCHAR2(2000) := initcap(REPLACE( substr( z_field_name
, 3
, length(z_field_name) - 2 )
, '_'
, ' ' ));
l_day VARCHAR2(15) := DAY;
--
PROCEDURE output_format_cal_js( page_header IN VARCHAR2
, body_attributes IN VARCHAR2
, chosen_date IN VARCHAR2
, field_format IN VARCHAR2 )
IS
--
-- Copied from WSGL
--
the_date DATE := to_date(chosen_date, 'DD-MONTH-YYYY');
--
BEGIN
--
wsgl.openpagehead(page_header);
wsgl.closepagehead;
wsgl.openpagebody(FALSE, p_attributes => body_attributes);
htp.p('<SCRIPT>');
htp.p ('opener.dateField.value = "' || to_char (the_date, Field_Format) || '";');
htp.p('opener.dateField.focus();');
htp.p('if(opener.dateField.onchange != null) { opener.dateField.onchange(); }');
htp.p('window.close();');
htp.p('</SCRIPT>');
wsgl.closepagebody;
--
END output_format_cal_js;
BEGIN
--
IF l_day = '0' THEN
l_day := '01';
END IF;
--
output_format_cal_js( wsgl.msggettext( 123
, wsglm.dsp128_cal_caption
, field_caption )
, NULL
, l_day || '-' || MONTH || '-' || YEAR
, z_field_format );
--
END format_cal_date;
--
--
FUNCTION dad_path
RETURN VARCHAR2
IS
BEGIN
RETURN(lower(owa_util.get_cgi_env('REQUEST_PROTOCOL') || '://' ||
owa_util.get_cgi_env('HTTP_HOST') ||
owa_util.get_cgi_env('SCRIPT_NAME') || '/'));
END dad_path;
--
--
--
PROCEDURE approve_conf_css
IS
BEGIN
-- Check we have permission to be using this module.
IF NOT caco_security.security_check(g_package_name) THEN
RETURN;
END IF;
--
htp.p('
h2 {
color : #F21C0A;
}
.confTable {
border : 1px solid;
}
.confTable td {
border : 1px solid;
}
.confTable th {
background-color : #D9D9D9;
border-left-width : 1px;
border-left-style : solid;
border-left-color : #F21C0A;
border-right-width : 1px;
border-right-style : solid;
border-right-color : #F21C0A;
border-top-width : 1px;
border-top-style : solid;
border-top-color : #F21C0A;
border-bottom-width : 1px;
border-bottom-style : solid;
border-bottom-color : #F21C0A;
}
.confTH {
font-weight : normal;
padding : 2px;
background-color : #D9D9D9;
border-left-width : 1px;
border-left-style : solid;
border-left-color : #F21C0A;
border-right-width : 1px;
border-right-style : solid;
border-right-color : #F21C0A;
border-top-width : 1px;
border-top-style : solid;
border-top-color : #F21C0A;
border-bottom-width : 1px;
border-bottom-style : solid;
border-bottom-color : #F21C0A;
height : 20px;
}
.confTHCreatedDate {
font-weight : normal;
padding : 2px;
background-color : #D9D9D9;
border-left-width : 1px;
border-left-style : solid;
border-left-color : #F21C0A;
border-right-width : 1px;
border-right-style : solid;
border-right-color : #F21C0A;
border-top-width : 1px;
border-top-style : solid;
border-top-color : #F21C0A;
border-bottom-width : 1px;
border-bottom-style : solid;
border-bottom-color : #F21C0A;
height : 20px;
width : 170px;
}
.confTHCentre {
text-align : center;
padding : 2px;
font-weight : normal;
background-color : #D9D9D9;
border-left-width : 1px;
border-left-style : solid;
border-left-color : #F21C0A;
border-right-width : 1px;
border-right-style : solid;
border-right-color : #F21C0A;
border-top-width : 1px;
border-top-style : solid;
border-top-color : #F21C0A;
border-bottom-width : 1px;
border-bottom-style : solid;
border-bottom-color : #F21C0A;
height : 20px;
width : 50px;
}
.smallTextButton {
font-size : smaller;
}
.nomValidTR1 {
background-color : #FFFFFF;
border-style : none;
height : 20px;
}
.nomValidTR2 {
background-color : #F5F5F5;
border-style : none;
height : 20px;
}
.nomInvalid {
background-color : #FF9F98;
padding : 2px;
height : 20px;
}
.nomTDCentre {
text-align : center;
padding : 2px;
}
.nomTDGasDay {
text-align : center;
padding : 2px;
width : 100px
}
.nomTDValid {
text-align : center;
padding : 2px;
width : 60px;
}
');
END approve_conf_css;
--
--
--
PROCEDURE approve_conf_js
IS
BEGIN
-- Check we have permission to be using this module.
IF NOT caco_security.security_check(g_package_name) THEN
RETURN;
END IF;
--
htp.p('
function checkDateThenGo( dadPath ) {
var theDate = document.getElementById(''p_gas_day'');
if ( theDate.value != "" ) {
location.href = dadPath + ''efnow095$.startup?p_gas_day='' + theDate.value;
}
else {
alert('''||caco_utilities.get_module_text(2422)||''');'); -- Select a Gas Day
htp.p(' }
}
function changeCheckBox( obj ) {
var prevInput = obj.previousSibling;
if (obj.checked) {
prevInput.value = "Y";
}
else {
prevInput.value = "N";
}
}
function checkAll( field )
{
var i=0
var x=new Array()
while (document.getElementById(field+i)!=null){
x[i]= document.getElementById(field+i)
i++
}
for (i = 0; i < x.length; i++)
{
x[i].checked = true;
changeCheckBox(x[i]);
}
}
function setApp( obj ) {
var appItem = obj.previousSibling;
var allAppItems = document.getElementsByName( ''p_approve'' );
var allDelItems = document.getElementsByName( ''p_delete'' );
var appIndex = -1; // to hold the index of the approval item we are interested in
for (i=0;i<allAppItems.length;i++) {
if (allAppItems[i] == appItem) {
appIndex = i;
}
}
if (appIndex > -1) {
if (obj.checked) {
appItem.value = ''Y'';
allDelItems[appIndex].value = ''N'';
allDelItems[appIndex].nextSibling.checked = false;
}
else {
appItem.value = ''N'';
}
}
}
function setDel( obj ) {
var delItem = obj.previousSibling;
var allDelItems = document.getElementsByName( ''p_delete'' );
var allAppItems = document.getElementsByName( ''p_approve'' );
var delIndex = -1; // to hold the index of the delete item we are interested in
for (i=0;i<allDelItems.length;i++) {
if (allDelItems[i] == delItem) {
delIndex = i;
}
}
if (delIndex > -1) {
if (obj.checked) {
delItem.value = ''Y'';
allAppItems[delIndex].value = ''N'';
allAppItems[delIndex].nextSibling.checked = false;
}
else {
delItem.value = ''N'';
}
}
}
function checkAppAll( field )
{
var i=0
var x=new Array()
while (document.getElementById(field+i)!=null){
x[i]= document.getElementById(field+i)
i++
}
for (i = 0; i < x.length; i++)
{
x[i].checked = true;
if (field == "p_approve_disp") {
setApp(x[i])}
else {
setDel(x[i])};
}
}
');
END approve_conf_js;
--
--
PROCEDURE conf_approve_tabhead IS
BEGIN
htp.p('<form id="appOrDel" name="appOrDel" method="POST" action="efno_confirmations.app_or_del_comm_conf">
<input type="submit" value="'||caco_utilities.get_module_text(1147)||'" />
<table>
<tr><td colspan=6 style="border: none;"></td><td style="border: none;"><input type="button" class="smallTextButton" value="'||caco_utilities.get_module_text(1148)||'" onClick="checkAppAll(''p_approve_disp'')"></td><td style="border: none;"><input type="button" class="smallTextButton" value="'||caco_utilities.get_module_text(1148)||'" onClick="checkAppAll(''p_delete_disp'')"></td></tr>
<tr>
<th class="confTHCreatedDate">'||caco_utilities.get_module_text(118)||'&nbsp;</th>'); -- Created On
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(1047)||'&nbsp;</th>'); -- Customer
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2013)||'&nbsp;</th>'); -- Contract Number
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2286)||'&nbsp;</th>'); -- Nomination ID
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(1142)||'&nbsp;</th>'); -- Gas Day
htp.p(' <th class="confTHCentre">'||caco_utilities.get_module_text(2062)||'</th>'); -- View
htp.p(' <th class="confTHCentre">'||caco_utilities.get_module_text(3559)||'</th>'); -- Send
htp.p(' <th class="confTHCentre">'||caco_utilities.get_module_text(838)||'</th>'); -- Delete
htp.p(' </tr>');
END conf_approve_tabhead;
--
--
PROCEDURE conf_approve_tabclose IS
BEGIN
htp.p('
</table>
<p></p>
<input type="submit" value="'||caco_utilities.get_module_text(1147)||'" />'); -- Submit
htp.p(' </form>');
END conf_approve_tabclose;
--
--
PROCEDURE approve_confirmations( p_call_type IN VARCHAR2 DEFAULT 'EXISTING'
, p_s_conf_id IN owa_util.vc_arr DEFAULT g_vc_arr
, p_f_nomi_id IN owa_util.vc_arr DEFAULT g_vc_arr
, p_f_nom_identifier IN owa_util.vc_arr DEFAULT g_vc_arr
, p_f_cont_num IN owa_util.vc_arr DEFAULT g_vc_arr
, p_f_conf_error IN owa_util.vc_arr DEFAULT g_vc_arr )
IS
--
CURSOR c_conf( cp_conf_id IN NUMBER ) IS
SELECT conf.created_on
, cust.name
, cont.contract_number
, nomi.identifier
, ( SELECT MIN(gas_day)
FROM conf_net_point_cat_vals cnpcv
WHERE cnpcv.conf_id = conf.conf_id ) gas_day
FROM nominations nomi
, contracts cont
, confirmations conf
, customers cust
WHERE conf.conf_id = cp_conf_id
AND nomi.nomi_id(+) = conf.nomi_id
AND cont.cont_id = conf.cont_id
AND cont.cust_id = cust.cust_id
AND cust.cuty_id = caco_utilities.cuty_id_for_user;
--
-- Cursor to list all unapproved commercial confirmations
CURSOR c_unapproved_conf IS
SELECT conf.conf_id
, conf.created_on
, cust.name
, nomi.identifier
, cont.contract_number
, ( SELECT MIN(gas_day)
FROM conf_net_point_cat_vals cnpcv
WHERE cnpcv.conf_id = conf.conf_id ) gas_day
FROM confirmations conf
, nominations nomi
, contracts cont
, customers cust
WHERE conf.confirmation_type = 'CO'
AND NVL(conf.approved,'N') = 'N'
AND conf.nomi_id = nomi.nomi_id (+)
AND conf.cont_id = cont.cont_id
AND cont.cust_id = cust.cust_id
AND cust.cuty_id = caco_utilities.cuty_id_for_user
ORDER BY cust.name
, gas_day DESC
, conf.created_on DESC
, cont.contract_number
, nomi.identifier;
--
CURSOR c_custname( cp_cont_num IN VARCHAR2 ) IS
SELECT cust.name,
cont.contract_number
FROM customers cust
, contracts cont
WHERE cont.cont_id = cp_cont_num
AND cust.cust_id = cont.cust_id
AND cust.cuty_id = caco_utilities.cuty_id_for_user;
--
--
l_conf_rec c_conf%ROWTYPE;
l_dummy_rec c_unapproved_conf%ROWTYPE;
l_cust_name customers.name%TYPE;
l_cont_num contracts.contract_number%TYPE;
--
l_count NUMBER := 0;
--
l_approve_idx NUMBER := 0;
l_delete_idx NUMBER := 0;
--
BEGIN
--
-- Check we have permission to be using this module.
IF NOT caco_security.security_check(g_package_name) THEN
RETURN;
END IF;
--
--
-- htp.p(' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
-- htp.p(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
htp.p(' <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">');
--
wsgl.openpagehead(caco_utilities.get_module_text(2426)); -- Approve Commercial Confirmation
--wsgl.metatag;
--htp.p('<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><LINK REL=stylesheet HREF="caco_system.css?p_type=content" >');
caco_system.content_type;
htp.p('<LINK REL=stylesheet HREF="caco_system.css?p_type=content" >');
htp.p(' <link rel="stylesheet" media="all" type="text/css" href="'||g_package_name||'.approve_conf_css" />');
htp.p(' <script type="text/javascript" src="'||g_package_name||'.approve_conf_js"></script>');
--
wsgl.closepagehead;
wsgl.openpagebody(FALSE);
htp.p(caco_system.menu);
--
htp.p('
<div style="margin:15px;">
<h2>'||caco_utilities.get_module_text(2426)||'</h2>'); -- Approve Commercial Confirmation
--
--
IF p_call_type = 'EXISTING' THEN
-- We haven't created new commercial confirmations for approval,
-- we are looking for any unapproved commercial confirmation
OPEN c_unapproved_conf;
FETCH c_unapproved_conf INTO l_dummy_rec;
IF c_unapproved_conf%FOUND THEN
CLOSE c_unapproved_conf;
--
-- Open a form and the table with its header row.
conf_approve_tabhead;
--
FOR r IN c_unapproved_conf LOOP
--
l_count := l_count + 1;
--
htp.p('<input type="hidden" name="p_conf_id" value="'||r.conf_id||'" />');
--
-- Open the row
IF MOD(l_count,2) = 0 THEN
htp.p('<tr class="nomValidTR2">');
ELSE
htp.p('<tr class="nomValidTR1">');
END IF;
--
htp.p('<td>'||TO_CHAR(r.created_on, cout_system_configuration.get_configuration_item('G_DATE_FORMAT')||' HH24:MI:SS')||'</td>');
htp.p('<td>'||r.name||'</td>');
htp.p('<td>'||r.contract_number||'</td>');
htp.p('<td>'||r.identifier||'</td>');
htp.p('<td>'||TO_CHAR(r.gas_day, cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))||'</td>');
htp.p('<td>
<input class="smallTextButton" type="button" value="'||caco_utilities.get_module_text(2062)||'" onclick="window.open(''' -- View
||dad_path||'efnow099$.startup?p_conf_id='||r.conf_id
||'&p_approved=N''),''View Confirmation'',''status=yes''" /></td>'); -- Window name will be overwritten
htp.p('<td class="nomTDCentre">
<input type="hidden" name="p_approve" value="N" /><input id="p_approve_disp'||TO_CHAR(l_approve_idx)||'" type="checkbox" unchecked onclick="setApp(this);" /></td>');
htp.p('<td class="nomTDCentre">
<input type="hidden" name="p_delete" value="N" /><input id="p_delete_disp'||TO_CHAR(l_delete_idx)||'" type="checkbox" unchecked onclick="setDel(this);" /></td>');
--
l_approve_idx := l_approve_idx + 1;
l_delete_idx := l_delete_idx + 1;
--
-- Close the row
htp.p('</tr>');
--
END LOOP;
--
-- Close the table, show a submit button and close the form
conf_approve_tabclose;
--
ELSE
CLOSE c_unapproved_conf;
--
htp.p('<p></p><p><b><i>'||caco_utilities.get_module_text(2427)||'</i></b></p>');
-- No unapproved confirmations exist
--
END IF;
--
ELSE
-- We have been called from the create commercial confirmations routine
IF NVL(p_s_conf_id.COUNT,0) = 0
AND NVL(p_f_nomi_id.COUNT,0) = 0
THEN
--
htp.p('<p></p><p><b><i>'||caco_utilities.get_module_text(2281)||'</i></b></p>');
-- No nominations were submitted
--
ELSE
-- List successful Send Confirmations
IF NVL(p_s_conf_id.COUNT,0) > 0 THEN
--
htp.p('<b><font size="+1" color="#008000"><i>'||caco_utilities.get_module_text(2428)||'</i></font></b><p></p>');
-- Successfully created confirmations
--
-- Open a form and the table with its header row.
conf_approve_tabhead;
--
FOR i IN 1..p_s_conf_id.COUNT LOOP
--
htp.p('<input type="hidden" name="p_conf_id" value="'||p_s_conf_id(i)||'" />');
--
-- Open the row
IF MOD(i,2) = 0 THEN
htp.p('<tr class="nomValidTR2">');
ELSE
htp.p('<tr class="nomValidTR1">');
END IF;
--
OPEN c_conf( p_s_conf_id(i) );
FETCH c_conf INTO l_conf_rec;
IF c_conf%FOUND THEN
--
htp.p('<td>'||TO_CHAR(l_conf_rec.created_on, cout_system_configuration.get_configuration_item('G_DATE_FORMAT')||' HH24:MI:SS')||'</td>');
htp.p('<td>'||l_conf_rec.name||'</td>');
htp.p('<td>'||l_conf_rec.contract_number||'</td>');
htp.p('<td>'||l_conf_rec.identifier||'</td>');
htp.p('<td>'||TO_CHAR(l_conf_rec.gas_day, cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))||'</td>');
htp.p('<td>
<input class="smallTextButton" type="button" value="'||caco_utilities.get_module_text(2062)||'" onclick="window.open(''' -- View
||dad_path||'efnow099$.startup?p_conf_id='||p_s_conf_id(i)
||'&p_approved=N''),''View Confirmation'',''status=yes''" /></td>'); -- Window title will be overwritten
htp.p('<td class="nomTDCentre">
<input type="hidden" name="p_approve" value="N" /><input id="p_approve_disp'||TO_CHAR(l_approve_idx)||'" type="checkbox" unchecked onclick="setApp(this);" /></td>');
htp.p('<td class="nomTDCentre">
<input type="hidden" name="p_delete" value="N" /><input id="p_delete_disp'||TO_CHAR(l_delete_idx)||'" type="checkbox" unchecked onclick="setDel(this);" /></td>');
--
l_approve_idx := l_approve_idx + 1;
l_delete_idx := l_delete_idx + 1;
--
ELSE
-- Span an error message across all columns
htp.p('<td colspan="9">'||caco_utilities.get_module_text(2072)||' : ' -- Confirmation
||p_s_conf_id(i)||' : '||caco_utilities.get_module_text(2429)||'</td>'); -- not found
END IF;
CLOSE c_conf;
--
-- Close the row
htp.p('</tr>');
--
END LOOP;
--
-- Close the table, show a submit button and close the form
conf_approve_tabclose;
--
--
END IF;
--
-- List unsuccessful send confirmations
IF NVL(p_f_nomi_id.COUNT,0) > 0
AND NVL(p_f_nomi_id.COUNT,0) = NVL(p_f_nom_identifier.COUNT,0)
AND NVL(p_f_nomi_id.COUNT,0) = NVL(p_f_cont_num.COUNT,0)
AND NVL(p_f_nomi_id.COUNT,0) = NVL(p_f_conf_error.COUNT,0)
THEN
-- Failed to create the following commercial confirmations
htp.p('<b><font size="+1" color="#840201"><i>'||caco_utilities.get_module_text(2430)||'</i></font><p></p></b>');
--
htp.p('<table>
<tr>
<th class="confTH">'||caco_utilities.get_module_text(1047)||'&nbsp;</th>'); -- Customer
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2013)||'&nbsp;</th>'); -- Contract Number
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2286)||'&nbsp;</th>'); -- Nomination ID
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2259)||'</th>'); -- Exception Message
htp.p(' </tr>');
--
FOR i IN 1..p_f_nomi_id.COUNT LOOP
-- get the customer name
l_cust_name := NULL;
OPEN c_custname(p_f_cont_num(i));
FETCH c_custname INTO l_cust_name, l_cont_num;
CLOSE c_custname;
--
IF MOD(i,2) = 0 THEN
htp.p('<tr class="nomValidTR2">');
ELSE
htp.p('<tr class="nomValidTR1">');
END IF;
--
htp.p('<td>'||l_cust_name||'</td>');
htp.p('<td>'||l_cont_num||'</td>');
htp.p('<td>'||p_f_nom_identifier(i)||'</td>');
htp.p('<td>'||p_f_conf_error(i)||'</td>');
--
htp.p('</tr>');
--
END LOOP;
--
htp.p('</table>');
--
END IF;
--
END IF;
--
END IF; -- called from create commercial confirmations
--
-- Close the margin div
htp.p('</div>');
--
-- Close centrecontent div
htp.p('</div>');
--
-- Close outer div
htp.p('</div>');
--
wsgl.closepagebody;
--
--
END approve_confirmations;
--
--
PROCEDURE find_nom_button IS
BEGIN
-- Find Nominations
htp.p('<p><input type="button" value="'||caco_utilities.get_module_text(2036)
||'" onclick="checkDateThenGo('''||dad_path||''');" /></p>');
--
END find_nom_button;
--
--
--
--
PROCEDURE startup( p_gas_day IN VARCHAR2 DEFAULT NULL
, p_error IN VARCHAR2 DEFAULT 'N'
, p_error_text IN VARCHAR2 DEFAULT NULL )
IS
--
CURSOR c_contracts( cp_gas_day IN DATE ) IS
SELECT cust.name customer_name
, cont.cont_id contract_id
, cont.contract_number contract_number
-- , nomi.nomi_id nom_id
-- , nomi.status nom_status
-- , nomi.identifier nom_identifier
-- , nomi.created_on nom_created_on
-- , nomi.nom_gas_day_from nom_gas_day_from
-- , nomi.nom_gas_day_to nom_gas_day_to
FROM contracts cont
, customers cust
/*
, ( SELECT cont.cust_id
, nomi.cont_id
, nomi.nomi_id
, nomi.status status
, nomi.identifier identifier
, nomi.created_on created_on
, MIN(nnpcv.gas_day) nom_gas_day_from
, MAX(nnpcv.gas_day) nom_gas_day_to
FROM nominations nomi
,nom_net_point_cat_vals nnpcv
,contracts cont
WHERE nnpcv.nomi_id = nomi.nomi_id
AND nomi.status = 'A'
AND cont.cont_id = nomi.cont_id
GROUP BY cont.cust_id
, nomi.cont_id
, nomi.nomi_id
, nomi.status
, nomi.identifier
, nomi.created_on
HAVING cp_gas_day BETWEEN MIN(nnpcv.gas_day) AND MAX(nnpcv.gas_day)
) nomi
*/
WHERE cont.cust_id = cust.cust_id
-- AND cont.cont_id = nomi.cont_id
-- AND cust.cust_id = nomi.cust_id (+)
AND cust.cuty_id = caco_utilities.cuty_id_for_user
AND (cust.cust_id = caco_utilities.get_cust_id OR caco_utilities.get_cust_id = cout_system_configuration.get_configuration_item('G_OMT_CUST_ID'))
AND cp_gas_day BETWEEN cont.valid_from AND cont.valid_until
AND cont.status = 'O'
GROUP BY cust.name
, cont.cont_id
, cont.contract_number
-- , nomi.nomi_id
-- , nomi.status
-- , nomi.identifier
-- , nomi.created_on
-- , nomi.nom_gas_day_from
-- , nomi.nom_gas_day_to
ORDER BY cust.name
, cont.contract_number;
--, nomi.nom_gas_day_from DESC /* fix for 49980 */
--, nomi.created_on DESC;
-- /* AG */
/* CURSOR cur_last_nomi ( cp_cont_id IN contracts.cont_id%TYPE
, cp_gas_day IN DATE ) IS
SELECT MAX(nnpcv.gas_day) gas_day
,nomi.nomi_id
FROM nom_net_point_cat_vals nnpcv
,nominations nomi
,contracts cont1
,contracts cont2
WHERE nnpcv.nomi_id = nomi.nomi_id
AND cont1.cust_id = cont2.cust_id
AND cont1.cont_id = cp_cont_id
AND nnpcv.gas_day <= cp_gas_day
AND nomi.cont_id = cont2.cont_id
GROUP BY nomi.nomi_id
, nomi.created_on
ORDER BY MAX(nnpcv.gas_day) DESC
, nomi.created_on DESC;*/
--
CURSOR cur_last_nomi ( cp_cont_id IN contracts.cont_id%TYPE
, cp_gas_day IN DATE
, cp_nomi_id IN nominations.nomi_id%TYPE) IS
SELECT MAX(nnpcv.gas_day) gas_day
,nomi.nomi_id
FROM nom_net_point_cat_vals nnpcv
,nominations nomi
-- ,contracts cont
WHERE nnpcv.nomi_id = nomi.nomi_id
-- AND nomi.cont_id = cont.cont_id
AND nomi.cont_id IN (SELECT cont2.cont_id
FROM contracts cont2
CONNECT BY PRIOR cont2.prev_cont_id = cont2.cont_id
START WITH cont2.cont_id = cp_cont_id)
-- AND cont.cust_id = (SELECT cust_id FROM contracts where cont_id= cp_cont_id)
AND nnpcv.gas_day <= cp_gas_day
AND nomi.nomi_id <> NVL(cp_nomi_id,-1)
GROUP BY nomi.nomi_id
, nomi.created_on
ORDER BY MAX(nnpcv.gas_day) DESC
, nomi.created_on DESC;
--
--
CURSOR cur_nomi (cp_gas_day IN DATE
,c_cont_id IN contracts.cont_id%TYPE) IS
SELECT nomi.nomi_id nom_id
, nomi.status nom_status
, nomi.identifier nom_identifier
, nomi.created_on nom_created_on
, MIN(nnpcv.gas_day) nom_gas_day_from
, MAX(nnpcv.gas_day) nom_gas_day_to
FROM nominations nomi
, nom_net_point_cat_vals nnpcv
WHERE nnpcv.nomi_id = nomi.nomi_id
AND nomi.status = 'A'
AND nomi.cont_id = c_cont_id
GROUP BY nomi.nomi_id
, nomi.status
, nomi.identifier
, nomi.created_on
HAVING cp_gas_day BETWEEN MIN(nnpcv.gas_day) AND MAX(nnpcv.gas_day);
l_nom_rec cur_nomi%ROWTYPE;
l_last_nomi_rec cur_last_nomi%ROWTYPE;
--
l_gas_day DATE;
gas_day_chosen BOOLEAN := FALSE;
date_in_past BOOLEAN := FALSE;
l_noms_found BOOLEAN := FALSE;
l_nom_count NUMBER := 0;
l_prev_contract contracts.contract_number%TYPE;
l_prev_customer customers.name%TYPE;
l_return_error VARCHAR2(255) := NULL;
--
nom_valid BOOLEAN := FALSE;
--
l_force_idx NUMBER := 0;
l_accept_idx NUMBER := 0;
--
BEGIN
--
-- Check we have permission to be using this module.
IF NOT caco_security.security_check(g_package_name) THEN
RETURN;
END IF;
--
--
IF p_gas_day IS NOT NULL THEN
-- Convert the varchar gas day into a date
BEGIN
SELECT TO_DATE(p_gas_day, cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))
INTO l_gas_day
FROM dual;
--
-- Successful so we have chosen a gas day to look for
-- Check its today or the future
/*
IF (l_gas_day) < TRUNC(SYSDATE-(cout_system_configuration.get_configuration_item('GAS_DAY_OFFSET')/24)) THEN
date_in_past := TRUE;
ELSE
gas_day_chosen := TRUE;
END IF;
*/
gas_day_chosen := TRUE;
--
EXCEPTION
WHEN others THEN
-- Invalid date - but we dont have to do anything.
NULL;
END;
--
END IF;
--
-- htp.p(' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
-- htp.p(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
htp.p(' <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">');
--
wsgl.openpagehead(g_title);
--wsgl.metatag;
--htp.p('<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><LINK REL=stylesheet HREF="caco_system.css?p_type=content" >');
caco_system.content_type;
htp.p('<LINK REL=stylesheet HREF="caco_system.css?p_type=content" >');
htp.p(' <link rel="stylesheet" media="all" type="text/css" href="'||g_package_name||'.approve_conf_css" />');
htp.p(' <script type="text/javascript" src="'||g_package_name||'.approve_conf_js"></script>');
--
-- Following required to show a calender screen
htp.p(wsgjsl.openscript);
wsgjsl.output_invoke_cal_js(g_package_name
,'scrollbars=no,resizable=no,width=320,height=350');
htp.p(wsgjsl.closescript);
--
wsgl.closepagehead;
wsgl.openpagebody(FALSE);
htp.p(caco_system.menu);
--
htp.p('
<div style="margin:15px;">
<h2>'||caco_utilities.get_module_text(2431)||'</h2>'); -- Create Commercial Confirmation
--
IF p_error = 'Y' THEN
htp.p('<b><font size="+2" color="#800000"><i>Send Failed</i></font><br /></b>');
htp.p('<b>'||p_error_text||'<br /></b><p></p>');
END IF;
--
htp.p('<table>
<tr>
<td><b>'||caco_utilities.get_module_text(1142)||'&nbsp;&nbsp;</b></td>'); -- Gas Day
htp.p(' <td style="border: 1px solid;">
<form>
<input id="p_gas_day" name="p_gas_day" type="text" value="'||TO_CHAR(l_gas_day, cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))||'" />
</form>
</td>
<td>');
--
htp.p(wsgjsl.calbutton(field_name => 'p_gas_day'
,p_calbut => htf.img(curl => caco_system.images_path||'lov.gif'
,calign => 'TOP'
,cattributes => 'ALT="List Values" WIDTH=18 HEIGHT=22 BORDER')
,field_format => cout_system_configuration.get_configuration_item('G_DATE_FORMAT')
,p_field_prompt => caco_utilities.get_module_text(1142) )); -- Gas Day
--
htp.p(' </td>
</tr>
</table>');
--
-- Now show the nominations that are available to confirm
IF gas_day_chosen THEN
-- Loop through each nomination found
-- Validate it and give a check box for the valid noms
-- need to ensure only select one nom for a given contract for a given day..
--
htp.p('<form name="nomForm" action="efno_confirmations.send_comm_conf" method="post">');
--
-- Lets just check if there is any data....
FOR rec_contracts IN c_contracts( l_gas_day )
LOOP
OPEN cur_last_nomi (rec_contracts.contract_id
,l_gas_day
,NULL);
FETCH cur_last_nomi INTO l_last_nomi_rec;
IF cur_last_nomi%FOUND
THEN
l_noms_found := TRUE;
END IF;
CLOSE cur_last_nomi;
END LOOP;
--
--
IF l_noms_found THEN
--
l_prev_contract := '~@?^$&';
--
-- Put out the gas day selected to pass to the commercial confirmation creation routine.
-- We know it is in the correct format or we wouldnt be here.
--
htp.p('<input name="p_gas_day" type="hidden" value="'||p_gas_day||'" />');
-- Put the submit button at the top in case there are many nominations that overflow the visible page
htp.p('<p>
<input type="button" value="'||caco_utilities.get_module_text(2036) -- Find Nominations
||'" onclick="checkDateThenGo('''||dad_path||''');" />
<input type="Submit" value="'||caco_utilities.get_module_text(2301)||'" />'); -- Submit Selected
htp.p(' </p>');
--
-- If we found any data then Open the table with a header row.
--
htp.p('<table class="confTable" style="border: none;">
<tr><td colspan=7 style="border: none;"></td><td style="border: none;"><input type="button" class="smallTextButton" value="'||caco_utilities.get_module_text(1148)||'" onClick="checkAll(''p_accept_disp'')"></td><td style="border: none;"><input type="button" class="smallTextButton" value="'||caco_utilities.get_module_text(1148)||'" onClick="checkAll(''p_force_disp'')"></td></tr>
<tr>
<th class="confTH">'||caco_utilities.get_module_text(2081)||'</th>'); -- Customer
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2013)||'</th>'); -- Contract Number
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2038)||'</th>'); -- Nom Identifier
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2039)||'</th>'); -- Nom Created On
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2058)||'</th>'); -- Gas Day From
htp.p(' <th class="confTH">'||caco_utilities.get_module_text(2059)||'</th>'); -- Gas Day To
htp.p(' <th class="confTHCentre">'||caco_utilities.get_module_text(2040)||'</th>'); -- Valid?
htp.p(' <th class="confTHCentre">'||caco_utilities.get_module_text(2042)||'</th>'); -- Accept
htp.p(' <th class="confTHCentre">'||caco_utilities.get_module_text(2043)||'</th>'); -- Force
htp.p(' </tr>');
--
-- Loop through all the noms/contracts
caco_debug.putline('-----EFNOW095$ c_contracts LOOP START');
FOR r IN c_contracts( l_gas_day ) LOOP
--
l_nom_rec := NULL;
OPEN cur_nomi (l_gas_day
,r.contract_id);
FETCH cur_nomi INTO l_nom_rec;
CLOSE cur_nomi;
nom_valid := FALSE;
l_nom_count := l_nom_count + 1;
--
-- The below ensures that only the tip nomination is shown for each contract
-- Should you ever need to show all Nominations, remove this IF
-- and remove status=A from the c_contracts cursor
IF l_prev_contract != r.contract_number THEN
-- Only want the "tips"
-- Validate the nomination
IF l_nom_rec.nom_id IS NOT NULL THEN
--
nom_valid := efno_contracts.validate_nomination( r.contract_id
, l_nom_rec.nom_id
, l_return_error ); -- not used in this program unit
--
ELSE
--
-- No nomination therefore not valid.
--
--
nom_valid := FALSE;
--
END IF;
--
-- Write out the details
IF nom_valid THEN
IF MOD(l_nom_count,2) = 0 THEN
htp.p('<tr class="nomValidTR2">');
ELSE
htp.p('<tr class="nomValidTR1">');
END IF;
ELSE
htp.p('<tr class="nomInvalid">');
END IF;
--
IF l_prev_customer = r.customer_name THEN
htp.p(' <td>&nbsp;</td>');
ELSE
htp.p(' <td>'||r.customer_name||'</td>');
END IF;
--
IF l_prev_contract = r.contract_number THEN
htp.p(' <td>&nbsp;</td>');
ELSE
htp.p(' <td>'||r.contract_number||'</td>');
END IF;
--
IF l_nom_rec.nom_identifier IS NOT NULL
AND nom_valid THEN
--
htp.p(' <td>'||l_nom_rec.nom_identifier||'</td>
<td>'||TO_CHAR(l_nom_rec.nom_created_on, cout_system_configuration.get_configuration_item('G_DATE_FORMAT')||' HH24:MI:SS')||'</td>
<td class="nomTDGasDay">'||TO_CHAR(l_nom_rec.nom_gas_day_from, cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))||'</td>
<td class="nomTDGasDay">'||TO_CHAR(l_nom_rec.nom_gas_day_to, cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))||'</td>');
--
ELSE
BEGIN
l_last_nomi_rec := NULL;
OPEN cur_last_nomi ( r.contract_id
, l_gas_day
, l_nom_rec.nom_id);
FETCH cur_last_nomi
INTO l_last_nomi_rec;
CLOSE cur_last_nomi;
--
EXCEPTION
WHEN OTHERS THEN
--
l_last_nomi_rec := NULL; -- continue processing if an error occurs finding the last nomination, it is purely for information only
--
END;
--
IF l_last_nomi_rec.nomi_id IS NOT NULL THEN
htp.p('<td colspan=4>'||caco_utilities.get_module_text(2037)||'. '||REPLACE(REPLACE(REPLACE(caco_utilities.get_module_text(3557), '<P1>',TO_CHAR(l_gas_day,cout_system_configuration.get_configuration_item('G_DATE_FORMAT'))),'<P2>',l_last_nomi_rec.nomi_id),'<P3>',TO_CHAR(l_last_nomi_rec.gas_day,cout_system_configuration.get_configuration_item('G_DATE_FORMAT')))||'</td>');
l_last_nomi_rec.nomi_id := NULL;
ELSE
htp.p('<td colspan=4>'||caco_utilities.get_module_text(2037)||'. '||REPLACE(caco_utilities.get_module_text(3558), '<P1>', TO_CHAR(l_gas_day,cout_system_configuration.get_configuration_item('G_DATE_FORMAT')))||'</td>');
END IF;
--
END IF;
--
-- Check if valid again
-- NOTE: there must NOT be a carriage return or space between p_accept and the checkbox
-- (otherwise the changeCheckBox javascript function does not work)
IF nom_valid THEN
htp.p('<td class="nomTDValid">'||RTRIM(caco_utilities.get_module_text(2040),'?')||'</td>');
htp.p('<td class="nomTDCentre">
<input name="p_nomi_id" type="hidden" value="'||l_nom_rec.nom_id||'" />
<input name="p_cont_id" type="hidden" value="'||r.contract_id||'" />
<input name="p_accept" type="hidden" value="N" /><input id="p_accept_disp'||TO_CHAR(l_accept_idx)||'" type="checkbox" onclick="changeCheckBox(this);"/>
<input name="p_force" type="hidden" value="N" />
</td>');
htp.p('<td>&nbsp;</td>');
l_accept_idx := l_accept_idx + 1;
ELSE
htp.p('<td class="nomTDValid">'||caco_utilities.get_module_text(2041)||'</td>');
htp.p('<td>&nbsp;</td>');
htp.p('<td class="nomTDCentre">
<input name="p_nomi_id" type="hidden" value="" />
<input name="p_cont_id" type="hidden" value="'||r.contract_id||'" />
<input name="p_accept" type="hidden" value="N" />
<input name="p_force" type="hidden" value="N" /><input id="p_force_disp'||TO_CHAR(l_force_idx)||'" type="checkbox" onclick="changeCheckBox(this);"/>
</td>');
l_force_idx := l_force_idx + 1;
END IF;
--
htp.p('</tr>');
--
l_prev_contract := r.contract_number;
l_prev_customer := r.customer_name;
--
END IF;
--
END LOOP;
caco_debug.putline('-----EFNOW095$ c_contracts LOOP END');
--
-- Close the table
htp.p('</table>');
--
ELSE
-- Need a button to recall the screen with a chosen gas day
find_nom_button;
-- No Nominations found - put out a message to that effect
-- There are no nominations for the chosen gas day
htp.p('<p><i>'||caco_utilities.get_module_text(2037)||'</i></p>');
END IF;
--
htp.p('</form>');
--
ELSIF date_in_past THEN
--
find_nom_button;
-- You may only create commercial confirmations for today and future gas days
htp.p('<p><i>'||caco_utilities.get_module_text(2432)||'</i></p>');
--
ELSE
-- Need a button to recall the screen with a chosen gas day
find_nom_button;
--
END IF; -- gas day chosen
--
-- Close the margin div
htp.p('</div>');
--
-- Close centrecontent div
htp.p('</div>');
--
-- Close outer div
htp.p('</div>');
--
wsgl.closepagebody;
--
END startup;
--
--
/**
-- FUNCTION about --
-- Returns the version number and VSS header for this package
--
-- %return The version number and VSS header for this package
*/
FUNCTION about RETURN VARCHAR2 IS
BEGIN
RETURN ( g_package_name || CHR(10) ||g_revision||chr(10)|| g_header );
END about;
--
--
--
BEGIN
-- Initialization
NULL;
--
END efnow095$;
/