Add general debug routines (mip_debug.pck, mip_debug_constants.pks)

Send email attachments (mip_quotation.pck, mip_email.pck - templates from WebMIP Email templates.doc)
Add Lifting Gear to 'labour' quotes (mip_quotation.pck)

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3860 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
hardya
2008-03-06 11:53:45 +00:00
parent 824ac1cf55
commit 6604eb2831
11 changed files with 501 additions and 265 deletions

View File

@@ -83,7 +83,7 @@ CREATE OR REPLACE PACKAGE mip_quotation IS
/** Reject all quotes associated with enquiry
%param p_enqu_id id of the enquiry for qhich all quotes are to be rejected
%param p_prty_id id of the person rejecting the quotes
%param p_prty_id id of the person rejecting the quotes
%param p_owner_prty_id id of the person who owns the rejected quotes (defaults to rejector)
%param p_description optional description to be recorded with the event
%param p_event_date optional date for this event (defaults to now)
@@ -127,7 +127,7 @@ END mip_quotation;
/
CREATE OR REPLACE PACKAGE BODY mip_quotation IS
PROCEDURE email_agent_aq_available(p_enqu_id IN enquiries.id%TYPE);
PROCEDURE email_agent_q_sel(p_enqu_id IN enquiries.id%TYPE);
PROCEDURE email_agent_quote_acceptance(p_enqu_id enquiries.id%TYPE);
PROCEDURE email_agent_mq_available(p_enqu_id enquiries.id%TYPE);
@@ -153,7 +153,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
SUBTYPE t_email_reason IS VARCHAR2(80);
gc_agent_rmq_notification t_email_reason := 'AGENT_RMQ_NOTIFICATION';
gc_agent_qa_notification t_email_reason := 'AGENT_QA_NOTIFICATION';
gc_agent_q_sel_notification t_email_reason := 'AGENT_Q_SEL_NOTIFICATION';
gc_agent_mqa_notification t_email_reason := 'AGENT_MQA_NOTIFICATION';
gc_internal_qa_notification t_email_reason := 'INTERNAL_QA_NOTIFICATION';
gc_internal_rmq_notification t_email_reason := 'AGENT_RMQ_NOTIFICATION';
@@ -168,18 +168,21 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
SUBTYPE t_quote_row IS quotes%ROWTYPE;
PROCEDURE pl(p_in VARCHAR2) IS
l_fh utl_file.file_type;
TYPE t_rec_attachment IS RECORD(
content wwv_flow_files.blob_content%TYPE := empty_blob
,filename wwv_flow_files.filename%TYPE
,mime_type wwv_flow_files.mime_type%TYPE);
PROCEDURE pl(p_in VARCHAR2
,p_line IN NUMBER DEFAULT NULL) IS
BEGIN
dbms_application_info.set_module('MIP_QUOTATION'
,p_in);
l_fh := utl_file.fopen(location => 'WEBMIP_BULK_LOAD'
,filename => 'MIP_QUOTATION.txt'
,open_mode => 'A');
utl_file.put_line(l_fh
,to_char(SYSDATE
,'DD/MM/YYYY HH24:MI:SS') || ',' || p_in);
utl_file.fclose(l_fh);
NULL;
/* $IF mip_debug_constants.debugging OR mip_debug_constants.quotation
$THEN*/
mip_debug.pl(p_unit => $$PLSQL_UNIT
,p_line => p_line
,p_in => p_in);
/* $END*/
END pl;
PROCEDURE add_quote_event(p_qute_id IN quotes.id%TYPE
@@ -187,6 +190,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
,p_description quote_events.description%TYPE DEFAULT NULL
,p_event_date DATE DEFAULT SYSDATE) IS
BEGIN
pl('add_quote_event:entry:' || p_qute_id || ':' || p_qust_code);
INSERT INTO quote_events
(qute_id
,qust_code
@@ -333,6 +337,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
,p_event_date IN DATE DEFAULT SYSDATE) IS
l_enqu_id enquiries.id%TYPE;
BEGIN
pl('select_quote:entry:' || p_qute_id
,$$PLSQL_LINE);
add_quote_event(p_qute_id => p_qute_id
,p_qust_code => 'SELECTED'
,p_event_date => p_event_date
@@ -361,7 +367,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
FROM quotes
WHERE id = p_qute_id;
email_agent_aq_available(l_enqu_id);
email_agent_q_sel(l_enqu_id);
END select_quote;
@@ -460,7 +466,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
l_qute_type quotes.qute_type%TYPE;
l_enqu_id enquiries.id%TYPE;
BEGIN
pl('make_quote_available');
pl('make_quote_available'
,$$PLSQL_LINE);
add_quote_event(p_qute_id => p_qute_id
,p_qust_code => 'AV'
@@ -481,7 +488,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
PROCEDURE mark_enquiry_submitted(p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
pl('mark_enquiry_submitted');
pl('mark_enquiry_submitted'
,$$PLSQL_LINE);
add_enquiry_event(p_enqu_id => p_enqu_id
,p_enst_code => 'SUBMITTED'
@@ -491,7 +499,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
PROCEDURE mark_enquiry_quoted(p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
pl('mark_enquiry_quoted');
pl('mark_enquiry_quoted'
,$$PLSQL_LINE);
add_enquiry_event(p_enqu_id => p_enqu_id
,p_enst_code => 'QUOTED'
@@ -501,7 +510,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
PROCEDURE mark_enquiry_invalid(p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
pl('mark_enquiry_invalid');
pl('mark_enquiry_invalid'
,$$PLSQL_LINE);
add_enquiry_event(p_enqu_id => p_enqu_id
,p_enst_code => 'INVALID'
@@ -521,7 +531,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
EXCEPTION
WHEN no_data_found THEN
pl('SYSTEM_CONFIGURATION ERROR - PARAMETER ''' || p_parameter ||
''' NOT FOUND');
''' NOT FOUND'
,$$PLSQL_LINE);
RETURN 'SYSTEM_CONFIGURATION ERROR - PARAMETER ''' || p_parameter || ''' NOT FOUND';
END get_system_configuration_value;
@@ -577,6 +588,55 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
RETURN l_description;
END get_enty_description;
FUNCTION get_quote_document(p_enqu_id IN enquiries.id%TYPE
,p_docu_id IN documents.id%TYPE DEFAULT NULL)
RETURN t_rec_attachment IS
l_docu_id documents.id%TYPE;
l_doc_details t_rec_attachment;
BEGIN
pl('get_quote_document:entry:p_enqu_id=' || p_enqu_id
,$$PLSQL_LINE);
l_docu_id := p_docu_id;
IF l_docu_id IS NULL THEN
-- find the 'selected' quote document
SELECT doro.docu_id
INTO l_docu_id
FROM document_roles doro
,quote_events quev
,quotes qute
WHERE qute.enqu_id = p_enqu_id
AND quev.qute_id = qute.id
AND quev.qust_code = 'SELECTED'
AND doro.qute_id = quev.qute_id;
END IF;
pl('l_docu_id=' || l_docu_id
,$$PLSQL_LINE);
-- get the document details and content
SELECT wff.filename
,wff.mime_type
,wff.blob_content
INTO l_doc_details.filename
,l_doc_details.mime_type
,l_doc_details.content
FROM documents docu
,apex_application_files wff
WHERE docu.uri = wff.NAME
AND docu.id = l_docu_id;
pl('l_doc_details.content.length=' ||
dbms_lob.getlength(l_doc_details.content)
,$$PLSQL_LINE);
pl('get_quote_document:exit:filename=' || l_doc_details.filename
,$$PLSQL_LINE);
RETURN l_doc_details;
END get_quote_document;
PROCEDURE al(p_in IN VARCHAR2) IS
BEGIN
dbms_lob.writeappend(g_email_plain_body
@@ -626,7 +686,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
PROCEDURE produce_quote_summary(p_qute_id IN quotes.id%TYPE) IS
l_quote_row t_quote_row;
BEGIN
pl('produce_quote_summary');
pl('produce_quote_summary'
,$$PLSQL_LINE);
l_quote_row := get_quote_row(p_qute_id);
@@ -727,7 +788,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
END return_value;
BEGIN
pl('produce_enquiry_entry_details');
pl('produce_enquiry_entry_details'
,$$PLSQL_LINE);
al(' ');
al(' ');
al(get_system_name ||
@@ -752,7 +814,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
PROCEDURE produce_reasoning_summary(p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
pl('produce_reasoning_summary');
pl('produce_reasoning_summary'
,$$PLSQL_LINE);
al(' ');
al(' ');
al(get_system_name ||
@@ -777,15 +840,18 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_email_recipient VARCHAR2(240);
l_agent_first_name parties.first_name%TYPE;
l_agent_last_name parties.last_name%TYPE;
l_attachment t_rec_attachment;
BEGIN
pl('email_to_agent:enter:p_enqu_id=' || p_enqu_id ||
', p_email_reason=' || p_email_reason);
', p_email_reason=' || p_email_reason
,$$PLSQL_LINE);
BEGIN
l_agent_prty_id := mip_enquiry.get_enquiry_role(p_enquiryid => p_enqu_id
,p_rolecode => 'ENQ OWN');
EXCEPTION
WHEN OTHERS THEN
pl('mip_enquiry.get_enquiry_role returned ' || SQLERRM);
pl('mip_enquiry.get_enquiry_role returned ' || SQLERRM
,$$PLSQL_LINE);
RAISE;
END;
@@ -820,7 +886,32 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
al(' ');
END IF;
IF p_email_reason = gc_agent_qa_notification THEN
IF p_email_reason = gc_agent_q_sel_notification THEN
--Scenario one: Automatic quote generation notification
l_email_subject := get_system_name || ': Automatic Quote Available';
l_attachment := get_quote_document(p_enqu_id => p_enqu_id);
al('Dear Sir/Madam,');
al(' ');
al('Enquiry reference number: ' || p_enqu_id);
al(' ');
al('Thank you for using the National Grid Metering Online I&C quotations system. Your enquiry has generated an automatic quotation. To accept this quotation; either submit a work request via IX, complete the acceptance form on the quotation letter, or click the accept button on the Online I&C quotations system. Please note that this quotation is valid for 90 days from the date specified in the quotation.');
al(' ');
al('Please use the Enquiry reference number at the top of this email on any future correspondence relating to this request.');
al(' ');
al('Regards');
al(' ');
al('The I&C Non Standard Team');
al('National Grid Metering');
al('Abbotts Lane');
al('Coventry');
al('CV1 4AY');
al(' ');
al('Phone: 02476 286 322');
al('Fax: 02476 286 044');
al('Email: ic.nonstandard1@uk.ngrid.com');
l_attachment := get_quote_document(p_enqu_id => p_enqu_id);
ELSIF p_email_reason = gc_agent_q_sel_notification THEN
-- Scenario two: Quotation acceptance notification
l_email_subject := get_system_name || ': Quote Acceptance';
al('Dear Sir/Madam,');
al(' ');
@@ -844,6 +935,7 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
al('Fax: 02476 286 044');
al('Email: ic.nonstandard1@uk.ngrid.com');
ELSIF p_email_reason = gc_agent_rmq_notification THEN
-- Scenario three: Manual quote requested
l_email_subject := get_system_name || ': Request for Manual Quote';
al('Dear Sir/Madam,');
al(' ');
@@ -865,7 +957,9 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
al('Fax: 02476 286 044');
al('Email: ic.nonstandard1@uk.ngrid.com');
ELSIF p_email_reason = gc_agent_mqa_notification THEN
-- Scenario four: Manual quote produced and ready to view.
l_email_subject := get_system_name || ': Manual Quote Available';
l_attachment := get_quote_document(p_enqu_id => p_enqu_id);
al('Dear Sir/Madam,');
al(' ');
al('Enquiry reference number: ' || p_enqu_id);
@@ -874,44 +968,6 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
al(' ');
al('Please note that this quotation is valid for 90 days from the date specified in the quotation. To accept this quotation, please submit a work request via IX, complete the acceptance form on the quotation letter, or click the accept button on the Online I&C quotations system. Please note that this quotation is valid for 90 days from the date specified in the quotation.');
al(' ');
al('Please use the Enquiry reference number at the top of this email on any future correspondence relating to this request.');
al(' ');
al('Regards');
al(' ');
al('The I&C Non Standard Team');
al('National Grid Metering');
al('Abbotts Lane');
al('Coventry');
al('CV1 4AY');
al(' ');
al('Phone: 02476 286 322');
al('Fax: 02476 286 044');
al('Email: ic.nonstandard1@uk.ngrid.com');
ELSIF p_email_reason = gc_agent_qa_notification THEN
l_email_subject := get_system_name || ': Automatic Quote Available';
al('Dear Sir/Madam,');
al(' ');
al('Enquiry reference number: ' || p_enqu_id);
al(' ');
al('Thank you for using the National Grid Metering Online I&C quotations system. Your enquiry has generated an automatic quotation. To accept this quotation; either submit a work request via IX, complete the acceptance form on the quotation letter, or click the accept button on the Online I&C quotations system. Please note that this quotation is valid for 90 days from the date specified in the quotation.');
al(' ');
al('The following quotations are available:');
FOR l_qute IN (SELECT id
FROM quotes
,v_quote_details v
,v_current_quote_status s
WHERE enqu_id = p_enqu_id
AND v.quote_id = id
AND s.qute_id = id
AND s.qust_code = 'AV'
ORDER BY total_cost) LOOP
produce_quote_summary(l_qute.id);
al(' ');
END LOOP;
al('Please use the Enquiry reference number at the top of this email on any future correspondence relating to this request.');
al(' ');
al('Regards');
@@ -930,17 +986,27 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
BEGIN
pl('email_to_agent:l_email_recipient=' || l_email_recipient || ':' ||
'l_email_subject=' || l_email_subject);
'l_email_subject=' || l_email_subject
,$$PLSQL_LINE);
mip_email.send_email_clob(p_recipient => l_email_recipient
,p_body => g_email_plain_body
,p_body_html => g_email_html_body
,p_subject => l_email_subject);
IF dbms_lob.getlength(lob_loc => l_attachment.content) > 0 THEN
mip_email.add_attachment(p_attachment => l_attachment.content
,p_filename => l_attachment.filename
,p_mime_type => l_attachment.mime_type);
END IF;
EXCEPTION
WHEN OTHERS THEN
pl('mip_email.send_email_clob returned ' || SQLERRM);
pl('mip_email.send_email_clob returned ' || SQLERRM
,$$PLSQL_LINE);
END;
pl('email_to_agent:exit');
pl('email_to_agent:exit'
,$$PLSQL_LINE);
END email_to_agent;
PROCEDURE email_to_internal_users(p_enqu_id IN enquiries.id%TYPE
@@ -950,9 +1016,11 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_qute_id quotes.id%TYPE;
BEGIN
pl('email_internal_users:entry:p_enqu_id=' || p_enqu_id ||
', p_email_reason=' || p_email_reason);
', p_email_reason=' || p_email_reason
,$$PLSQL_LINE);
open_body;
IF p_email_reason = gc_internal_qa_notification THEN
-- Scenario five: Accepted quote + system data
l_email_subject := get_system_name ||
': Quote Acceptance Notification';
al('Hi team,');
@@ -978,6 +1046,7 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
al(' ');
al('I&C Online Quotations System');
ELSIF p_email_reason = gc_internal_rmq_notification THEN
-- Scenario six: Request for manual quote + system data
l_email_subject := get_system_name ||
': Request For Manual Quotation Notification';
al('Hi team,');
@@ -1006,27 +1075,32 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
close_body;
BEGIN
pl('email_to_internal_users:l_email_recipient=' || l_email_recipient || ':' ||
'l_email_subject=' || l_email_subject);
'l_email_subject=' || l_email_subject
,$$PLSQL_LINE);
mip_email.send_email_clob(p_recipient => l_email_recipient
,p_body => g_email_plain_body
,p_body_html => g_email_html_body
,p_subject => l_email_subject);
EXCEPTION
WHEN OTHERS THEN
pl('mip_email.send_email_clob returned ' || SQLERRM);
pl('mip_email.send_email_clob returned ' || SQLERRM
,$$PLSQL_LINE);
END;
pl('email_internal_users:exit');
pl('email_internal_users:exit'
,$$PLSQL_LINE);
END email_to_internal_users;
PROCEDURE email_agent_aq_available(p_enqu_id IN enquiries.id%TYPE) IS
PROCEDURE email_agent_q_sel(p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
pl('email_agent_aq_available:entry');
pl('email_agent_q_sel:entry'
,$$PLSQL_LINE);
email_to_agent(p_enqu_id => p_enqu_id
,p_email_reason => gc_agent_qa_notification);
,p_email_reason => gc_agent_q_sel_notification);
pl('email_agent_aq_available:exit');
END email_agent_aq_available;
pl('email_agent_q_sel:exit'
,$$PLSQL_LINE);
END email_agent_q_sel;
PROCEDURE email_agent_mq_available(p_enqu_id enquiries.id%TYPE) IS
BEGIN
@@ -1038,7 +1112,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_system_name system_configuration.VALUE%TYPE := get_system_name;
l_quote_row quotes%ROWTYPE;
BEGIN
pl('email_request_for_mq:enter');
pl('email_request_for_mq:enter'
,$$PLSQL_LINE);
email_to_agent(p_enqu_id => p_enqu_id
,p_email_reason => gc_agent_rmq_notification);
@@ -1046,13 +1121,14 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
email_to_internal_users(p_enqu_id => p_enqu_id
,p_email_reason => gc_internal_rmq_notification);
pl('email_request_for_mq:exit');
pl('email_request_for_mq:exit'
,$$PLSQL_LINE);
END email_agent_request_for_mq;
PROCEDURE email_agent_quote_acceptance(p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
email_to_agent(p_enqu_id => p_enqu_id
,p_email_reason => gc_agent_qa_notification);
,p_email_reason => gc_agent_q_sel_notification);
END email_agent_quote_acceptance;
PROCEDURE email_iu_quote_acceptance(p_enqu_id enquiries.id%TYPE) IS
@@ -1070,7 +1146,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
PROCEDURE email_support(p_subject IN VARCHAR2
,p_enqu_id IN enquiries.id%TYPE) IS
BEGIN
pl('email_support');
pl('email_support'
,$$PLSQL_LINE);
open_body;
@@ -1097,7 +1174,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
p_enqu_id);
EXCEPTION
WHEN OTHERS THEN
pl('mip_email.send_email_clob returned ' || SQLERRM);
pl('mip_email.send_email_clob returned ' || SQLERRM
,$$PLSQL_LINE);
END;
END email_support;
@@ -1106,7 +1184,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_owner_prty_id IN parties.id%TYPE DEFAULT NULL) IS
l_qute_id quotes.id%TYPE;
BEGIN
pl('request_manual_quote');
pl('request_manual_quote'
,$$PLSQL_LINE);
l_qute_id := start_quote(p_enqu_id => p_enqu_id
,p_manual_or_automatic => gc_manual_quote
@@ -1121,7 +1200,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_mandatory_checks OUT mip_mandatory.t_mandatory_checks
,p_enquiry_is_ready OUT BOOLEAN) IS
BEGIN
pl('ready_for_quote(1) - enqu_id=' || p_enqu_id);
pl('ready_for_quote(1) - enqu_id=' || p_enqu_id
,$$PLSQL_LINE);
p_enquiry_is_ready := mip_enquiries_helper.check_mandatory(p_id => p_enqu_id
,p_mandatory_checks => p_mandatory_checks);
@@ -1131,7 +1211,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_mandatory_checks mip_mandatory.t_mandatory_checks;
l_enquiry_is_ready BOOLEAN;
BEGIN
pl('ready_for_quote(2) - enqu_id=' || p_enqu_id);
pl('ready_for_quote(2) - enqu_id=' || p_enqu_id
,$$PLSQL_LINE);
ready_for_quote(p_enqu_id => p_enqu_id
,p_mandatory_checks => l_mandatory_checks
@@ -1167,7 +1248,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
EXCEPTION
WHEN OTHERS THEN
pl('validate:' || SQLERRM);
pl('validate:' || SQLERRM
,$$PLSQL_LINE);
RAISE;
END validate;
@@ -1190,7 +1272,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
/* pl('Nothing found');*/
RETURN NULL;
WHEN OTHERS THEN
pl('validation_result:' || SQLERRM);
pl('validation_result:' || SQLERRM
,$$PLSQL_LINE);
RAISE;
END validation_result;
@@ -1201,7 +1284,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_enquiry_is_ready BOOLEAN;
l_idx INTEGER;
BEGIN
pl('return_mandatory_messages');
pl('return_mandatory_messages'
,$$PLSQL_LINE);
ready_for_quote(p_enqu_id => p_enqu_id
,p_mandatory_checks => l_mandatory_checks
@@ -1224,7 +1308,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_reason IN quote_reasoning.reason%TYPE
,p_internal_or_external IN quote_reasoning.internal_or_external%TYPE DEFAULT gc_external_reason) IS
BEGIN
pl('add_quote_reason:' || p_enqu_id || ':' || p_reason);
pl('add_quote_reason:' || p_enqu_id || ':' || p_reason
,$$PLSQL_LINE);
INSERT INTO quote_reasoning
(enqu_id
,reason
@@ -1242,7 +1327,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
RETURN meter_size_codes.code%TYPE IS
l_meter_size_code meter_size_codes.code%TYPE;
BEGIN
pl('get_u_meter_size');
pl('get_u_meter_size'
,$$PLSQL_LINE);
-- get the smallest meter code that will support the given Qmax
SELECT code
@@ -1302,7 +1388,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
RETURN BOOLEAN IS
l_dummy NUMBER;
BEGIN
pl('valid_meter_size_upgrade');
pl('valid_meter_size_upgrade'
,$$PLSQL_LINE);
IF p_existing_meter_size_code = p_required_meter_size_code THEN
RETURN TRUE;
@@ -1328,7 +1415,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_existing_meter_size_code meter_size_codes.code%TYPE;
l_required_meter_size_code meter_size_codes.code%TYPE;
BEGIN
pl('survey_required');
pl('survey_required'
,$$PLSQL_LINE);
-- Low Pressure Rules
-- Site survey required for:
@@ -1395,7 +1483,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_idx INTEGER;
BEGIN
pl('tripartite_agreement_message');
pl('tripartite_agreement_message'
,$$PLSQL_LINE);
l_valid := mip_tripartite.valid_enquiry(p_rec => p_rec
,p_tab_messages => l_tab_messages);
@@ -1422,7 +1511,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_idx INTEGER;
BEGIN
pl('tripartite_agreement_satisfied');
pl('tripartite_agreement_satisfied'
,$$PLSQL_LINE);
l_valid := mip_tripartite.valid_enquiry(p_enqu_id => p_enqu_id
,p_tab_messages => l_tab_messages);
@@ -1451,7 +1541,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
PROCEDURE manual_or_automatic_quote(p_enqu IN t_enqu
,p_manual_or_automatic_quote OUT t_manual_or_automatic_quote) IS
BEGIN
pl('manual_or_automatic_quote');
pl('manual_or_automatic_quote'
,$$PLSQL_LINE);
p_manual_or_automatic_quote := gc_automatic_quote;
IF p_enqu.enty_code IN ('OTHER', 'CHANGE CAPACITY') THEN
@@ -1555,7 +1646,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
RETURN t_rec_additional_costs IS
l_rec_costs t_rec_additional_costs;
BEGIN
pl('get_housing');
pl('get_housing'
,$$PLSQL_LINE);
SELECT selling_price
,cost_price
,delivery_cost
@@ -1593,7 +1685,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
RETURN t_rec_additional_costs IS
l_rec_costs t_rec_additional_costs;
BEGIN
pl('get_base');
pl('get_base'
,$$PLSQL_LINE);
SELECT selling_price
,cost_price
,delivery_cost
@@ -1632,7 +1725,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
RETURN t_rec_additional_costs IS
l_rec_costs t_rec_additional_costs;
BEGIN
pl('get_aico:' || p_adit_code || ':' || p_regi_code);
pl('get_aico:' || p_adit_code || ':' || p_regi_code
,$$PLSQL_LINE);
SELECT lead_time
,selling_price
,cost_price
@@ -1667,15 +1761,18 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
WHERE adit.code = cost.adit_code
AND adit.code = p_adit_code;
pl('get_aico:exit');
pl('get_aico:exit'
,$$PLSQL_LINE);
RETURN l_rec_costs;
EXCEPTION
WHEN no_data_found THEN
pl('get_aico:exit:NDF');
pl('get_aico:exit:NDF'
,$$PLSQL_LINE);
RETURN l_rec_costs;
WHEN OTHERS THEN
pl('get_aico:exit:' || SQLERRM);
pl('get_aico:exit:' || SQLERRM
,$$PLSQL_LINE);
RAISE;
END get_aico;
@@ -1687,7 +1784,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
RETURN t_rec_additional_costs IS
l_rec_costs t_rec_additional_costs;
BEGIN
pl('get_laco');
pl('get_laco'
,$$PLSQL_LINE);
SELECT selling_price
,cost_price
,delivery_cost
@@ -1743,7 +1841,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
BEGIN
pl('get_lead_time:' || p_enty_code || ':' || p_mety_code || ':' ||
p_svcp_code || ':' || p_qmax);
p_svcp_code || ':' || p_qmax
,$$PLSQL_LINE);
SELECT days
INTO l_days
FROM (SELECT enty_code
@@ -1764,15 +1863,18 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
AND ((v.svcp_code = p_svcp_code) OR
(v.svcp_code IS NULL AND p_svcp_code IS NULL));
pl('get_lead_time:exit:' || l_days);
pl('get_lead_time:exit:' || l_days
,$$PLSQL_LINE);
RETURN l_days;
EXCEPTION
WHEN no_data_found THEN
pl('get_lead_time:exit:NDF');
pl('get_lead_time:exit:NDF'
,$$PLSQL_LINE);
RETURN NULL;
WHEN OTHERS THEN
pl('get_lead_time:exit:' || SQLERRM);
pl('get_lead_time:exit:' || SQLERRM
,$$PLSQL_LINE);
RAISE;
END get_lead_time;
@@ -1829,7 +1931,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_required_mesc_code meter_size_codes.code%TYPE;
l_required_qmax meter_size_codes.qmax%TYPE;
BEGIN
pl('produce_module_quotes');
pl('produce_module_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_enqu.enty_code IN ('INSTALL', 'STD INSTALL',
'EXCHANGE', 'CAPACITY CHANGE')
,'Attempted to produce an install or exchange quote for enquiry of type ' ||
@@ -1883,6 +1986,9 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_required_qmax := p_enqu.qmax;
END IF;
pl('Required Qmax=' || l_required_qmax
,$$PLSQL_LINE);
IF p_enqu.enty_code = 'EXCHANGE' THEN
IF p_enqu.existing_mesc_code IS NULL THEN
l_required_mesc_code := get_next_u_meter_size(get_u_meter_size(l_required_qmax));
@@ -2392,7 +2498,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
END IF;
pl('produce_module_quotes:exit');
pl('produce_module_quotes:exit'
,$$PLSQL_LINE);
END produce_module_quotes;
PROCEDURE produce_install_quotes(p_enqu IN t_enqu
@@ -2401,7 +2508,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
l_regi_code regions.code%TYPE := mip_regions.get_region_for_postcode(p_enqu.install_postcode);
BEGIN
pl('produce_install_quotes');
pl('produce_install_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_enqu.enty_code IN ('STD INSTALL', 'INSTALL')
,'Attempted to produce an installation quote for enquiry of type ' ||
p_enqu.enty_code);
@@ -2415,7 +2523,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_owner_prty_id => p_owner_prty_id
,p_manual_or_automatic_quote => p_manual_or_automatic_quote);
pl('produce_install_quotes:exit');
pl('produce_install_quotes:exit'
,$$PLSQL_LINE);
END produce_install_quotes;
PROCEDURE produce_exchange_quotes(p_enqu IN t_enqu
@@ -2424,7 +2533,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
l_regi_code regions.code%TYPE := mip_regions.get_region_for_postcode(p_enqu.install_postcode);
BEGIN
pl('produce_exchange_quotes');
pl('produce_exchange_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_enqu.enty_code IN ('EXCHANGE')
,'Attempted to produce an exchange quote for enquiry of type ' ||
p_enqu.enty_code);
@@ -2446,7 +2556,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
l_regi_code regions.code%TYPE := mip_regions.get_region_for_postcode(p_enqu.install_postcode);
BEGIN
pl('produce_change_capacity_quotes');
pl('produce_change_capacity_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_enqu.enty_code IN ('CHANGE CAPACITY')
,'Attempted to produce a change capacity quote for enquiry of type ' ||
p_enqu.enty_code);
@@ -2474,8 +2585,10 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_labour_costs t_rec_additional_costs;
l_quote_document VARCHAR2(240);
l_existing_mesc_code meter_size_codes.code%TYPE;
l_additional_costs t_rec_additional_costs;
BEGIN
pl('produce_labour_only_quotes');
pl('produce_labour_only_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_enqu.enty_code IN
('REMOVE', 'STD REMOVE', 'ADVERSARIAL', 'OFMAT',
'ALTERATION')
@@ -2538,12 +2651,28 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_internal_or_external => gc_internal_reason);
END IF;
/* Always get costs for LIFTING GEAR */
l_additional_costs := get_aico(p_adit_code => 'LIFTING GEAR'
,p_regi_code => l_regi_code);
IF l_additional_costs.selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE;
add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for LIFTING GEAR.'
,p_internal_or_external => gc_internal_reason);
END IF;
IF l_additional_costs.lead_time IS NULL THEN
l_this_is_automatic_quote := FALSE;
add_quote_reason(p_enqu.id
,p_reason => 'Unable to find lead time for LIFTING GEAR.'
,p_internal_or_external => gc_internal_reason);
END IF;
IF l_this_is_automatic_quote THEN
l_produced_automatic_quote := TRUE;
add_quote_reason(p_enqu_id => p_enqu.id
,p_reason => '
producing an automatic quote. '
,p_reason => 'producing an automatic quote. '
,p_internal_or_external => gc_internal_reason);
l_qute_id := start_quote(p_enqu_id => p_enqu.id
@@ -2576,11 +2705,31 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,l_lead_time
,'LQI');
/* Always include LIFTING GEAR */
INSERT INTO quote_items
(id
,qute_id
,adit_code
,cost_price
,selling_price
,delivery_price
,lead_time
,quit_type)
VALUES
(quit_seq.NEXTVAL
,l_qute_id
,'LIFTING GEAR'
,l_additional_costs.cost_price
,l_additional_costs.selling_price
,l_additional_costs.delivery_cost
,l_additional_costs.lead_time
,'AQI');
-- Generate the quote PDF
l_quote_document := mip_quotation_document.generate_quote_pdf(p_quote_id => l_qute_id);
add_quote_reason(p_enqu_id => p_enqu.id
,p_reason => '
produced quote document ' ||
,p_reason => 'produced quote document ' ||
l_quote_document || ' . '
,p_internal_or_external => gc_internal_reason);
@@ -2664,7 +2813,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_bypass_costs t_rec_additional_costs;
l_quote_document VARCHAR2(240);
BEGIN
pl('produce_addon_quotes');
pl('produce_addon_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_enqu.enty_code IN ('ADDON')
,'Attempted to produce an ADDON quote for enquiry of type ' ||
@@ -2882,7 +3032,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_owner_prty_id IN parties.id%TYPE DEFAULT NULL
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
BEGIN
pl('produce_automatic_quotes');
pl('produce_automatic_quotes'
,$$PLSQL_LINE);
cout_assert.istrue(p_manual_or_automatic_quote = gc_automatic_quote
,p_message => 'Attempted to produce automatic quote for enquiry marked as manual only');
@@ -2916,7 +3067,8 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
cout_err.report_and_stop(p_exception_message => 'Attempted to produce automatic quote for unexpected enquiry type of ' ||
p_enqu.enty_code);
END IF;
pl('produce_automatic_quotes:exit');
pl('produce_automatic_quotes:exit'
,$$PLSQL_LINE);
END produce_automatic_quotes;
PROCEDURE produce_quotes(p_enqu_id IN enquiries.id%TYPE
@@ -2925,10 +3077,12 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
l_manual_or_automatic_quote t_manual_or_automatic_quote;
l_enqu t_enqu;
BEGIN
pl('produce_quotes');
pl('produce_quotes'
,$$PLSQL_LINE);
IF NOT ready_for_quote(p_enqu_id) THEN
pl('Not all mandatory fields for Enquiry ID=' || p_enqu_id ||
' have been completed');
' have been completed'
,$$PLSQL_LINE);
END IF;
cout_assert.istrue(ready_for_quote(p_enqu_id)
,'Not all mandatory fields for Enquiry ID=' ||
@@ -2960,7 +3114,6 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
,p_manual_or_automatic_quote => l_manual_or_automatic_quote);
IF l_manual_or_automatic_quote = gc_automatic_quote THEN
mark_enquiry_quoted(p_enqu_id);
email_agent_aq_available(p_enqu_id);
ELSE
request_manual_quote(p_enqu_id => l_enqu.id
,p_rfq_prty_id => p_rfq_prty_id
@@ -2971,15 +3124,18 @@ RECEIVED AT THIS ADDRESS CANNOT BE RESPONDED TO.');
END IF; -- tripartite agreement
pl('exit without error');
pl('exit without error'
,$$PLSQL_LINE);
EXCEPTION
WHEN OTHERS THEN
pl(SQLERRM);
pl(SQLERRM
,$$PLSQL_LINE);
RAISE;
END produce_quotes;
BEGIN
-- Initialization
pl('mip_quotation');
pl('mip_quotation'
,$$PLSQL_LINE);
END mip_quotation;
/