Record 'reasoning' process in the quote_reasoning table!

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3053 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
hardya
2007-12-20 17:29:10 +00:00
parent e3f9c1e5ff
commit 7926c9cbd7

View File

@@ -6,6 +6,10 @@ CREATE OR REPLACE PACKAGE mip_quotation IS
FUNCTION ready_for_quote(p_id IN enquiries.id%TYPE) RETURN BOOLEAN; FUNCTION ready_for_quote(p_id IN enquiries.id%TYPE) RETURN BOOLEAN;
PROCEDURE ready_for_quote(p_id IN enquiries.id%TYPE
,p_mandatory_checks OUT mip_mandatory.t_mandatory_checks
,p_quote_is_ready OUT BOOLEAN);
PROCEDURE produce_quotes(p_id IN enquiries.id%TYPE); PROCEDURE produce_quotes(p_id IN enquiries.id%TYPE);
END mip_quotation; END mip_quotation;
/ /
@@ -14,14 +18,9 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
SUBTYPE t_reason IS VARCHAR2(240); SUBTYPE t_reason IS VARCHAR2(240);
SUBTYPE t_internal_or_external IS VARCHAR2(8); SUBTYPE t_internal_or_external IS VARCHAR2(8);
TYPE t_manual_quote_reason IS RECORD(
reason t_reason
,internal_or_external t_internal_or_external);
g_internal_reason CONSTANT t_internal_or_external := 'INTERNAL'; g_internal_reason CONSTANT t_internal_or_external := 'INTERNAL';
g_external_reason CONSTANT t_internal_or_external := 'EXTERNAL'; g_external_reason CONSTANT t_internal_or_external := 'EXTERNAL';
TYPE t_tab_manual_quote_reasons IS TABLE OF t_manual_quote_reason INDEX BY BINARY_INTEGER;
SUBTYPE t_manual_or_automatic_quote IS VARCHAR2(9); SUBTYPE t_manual_or_automatic_quote IS VARCHAR2(9);
SUBTYPE t_enqu IS enquiries%ROWTYPE; SUBTYPE t_enqu IS enquiries%ROWTYPE;
@@ -29,13 +28,14 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
g_manual_quote CONSTANT t_manual_or_automatic_quote := 'MANUAL'; g_manual_quote CONSTANT t_manual_or_automatic_quote := 'MANUAL';
g_automatic_quote CONSTANT t_manual_or_automatic_quote := 'AUTOMATIC'; g_automatic_quote CONSTANT t_manual_or_automatic_quote := 'AUTOMATIC';
TYPE t_rec_costs IS RECORD( TYPE t_rec_additional_item_costs IS RECORD(
selling_price costs.selling_price%TYPE adit_code additional_items.code%TYPE
,lead_time additional_items.lead_time%TYPE
,selling_price costs.selling_price%TYPE
,cost_price costs.cost_price%TYPE ,cost_price costs.cost_price%TYPE
,delivery_cost costs.delivery_cost%TYPE); ,delivery_cost costs.delivery_cost%TYPE);
PROCEDURE request_manual_quote(p_id IN enquiries.id%TYPE PROCEDURE request_manual_quote(p_id IN enquiries.id%TYPE) IS
,p_tab_manual_quote_reasons IN t_tab_manual_quote_reasons) IS
BEGIN BEGIN
NULL; NULL;
END request_manual_quote; END request_manual_quote;
@@ -59,16 +59,23 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
RETURN l_quote_is_ready; RETURN l_quote_is_ready;
END ready_for_quote; END ready_for_quote;
PROCEDURE add_manual_quote_reason(p_tab_manual_quote_reasons IN OUT t_tab_manual_quote_reasons PROCEDURE add_quote_reason(p_enqu_id IN enquiries.id%TYPE
,p_reason IN VARCHAR2 ,p_reason IN quote_reasoning.reason%TYPE
,p_internal_or_external IN VARCHAR2 DEFAULT g_external_reason) IS ,p_internal_or_external IN quote_reasoning.internal_or_external%TYPE DEFAULT g_external_reason) IS
l_idx BINARY_INTEGER;
BEGIN BEGIN
l_idx := nvl(p_tab_manual_quote_reasons.LAST
,0) + 1; INSERT INTO quote_reasoning
p_tab_manual_quote_reasons(l_idx).reason := p_reason; (enqu_id
p_tab_manual_quote_reasons(l_idx).internal_or_external := p_internal_or_external; ,reason
END add_manual_quote_reason; ,internal_or_external
,id)
VALUES
(p_enqu_id
,p_reason
,p_internal_or_external
,qure_seq.NEXTVAL);
END add_quote_reason;
FUNCTION get_u_meter_size(p_qmax IN NUMBER) FUNCTION get_u_meter_size(p_qmax IN NUMBER)
RETURN meter_size_codes.code%TYPE IS RETURN meter_size_codes.code%TYPE IS
@@ -112,7 +119,6 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
END valid_meter_size_upgrade; END valid_meter_size_upgrade;
PROCEDURE survey_required(p_enqu IN t_enqu PROCEDURE survey_required(p_enqu IN t_enqu
,p_tab_manual_quote_reasons IN OUT t_tab_manual_quote_reasons
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS ,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
l_svcpt_code service_pressure_types.code%TYPE; l_svcpt_code service_pressure_types.code%TYPE;
l_existing_meter_size_code meter_size_codes.code%TYPE; l_existing_meter_size_code meter_size_codes.code%TYPE;
@@ -130,7 +136,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
IF l_svcpt_code = 'LP' THEN IF l_svcpt_code = 'LP' THEN
IF p_enqu.enty_code = 'RELOCATE' THEN IF p_enqu.enty_code = 'RELOCATE' THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Site Survey is required for relocation.'); ,'Site Survey is required for relocation.');
END IF; -- RELOCATE END IF; -- RELOCATE
IF p_enqu.enty_code IN ('EXCHANGE', 'STD EXCHANGE') THEN IF p_enqu.enty_code IN ('EXCHANGE', 'STD EXCHANGE') THEN
@@ -143,7 +149,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
valid_meter_size_upgrade(p_existing_meter_size_code => l_existing_meter_size_code valid_meter_size_upgrade(p_existing_meter_size_code => l_existing_meter_size_code
,p_required_meter_size_code => l_required_meter_size_code) THEN ,p_required_meter_size_code => l_required_meter_size_code) THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Site Survey is required for exchange of meter from size ' || ,'Site Survey is required for exchange of meter from size ' ||
l_existing_meter_size_code || ' to ' || l_existing_meter_size_code || ' to ' ||
l_required_meter_size_code || '.'); l_required_meter_size_code || '.');
@@ -153,72 +159,75 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
END survey_required; END survey_required;
PROCEDURE manual_or_automatic_quote(p_enqu IN t_enqu PROCEDURE manual_or_automatic_quote(p_enqu IN t_enqu
,p_manual_or_automatic_quote OUT t_manual_or_automatic_quote ,p_manual_or_automatic_quote OUT t_manual_or_automatic_quote) IS
,p_tab_manual_quote_reasons OUT t_tab_manual_quote_reasons) IS
BEGIN BEGIN
p_manual_or_automatic_quote := g_automatic_quote; p_manual_or_automatic_quote := g_automatic_quote;
survey_required(p_enqu => p_enqu survey_required(p_enqu => p_enqu
,p_tab_manual_quote_reasons => p_tab_manual_quote_reasons
,p_manual_or_automatic_quote => p_manual_or_automatic_quote); ,p_manual_or_automatic_quote => p_manual_or_automatic_quote);
IF p_enqu.twin_stream_required = 'YES' THEN IF p_enqu.twin_stream_required = 'YES' THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Twin stream required.'); ,'Twin stream required.');
END IF; END IF;
IF p_enqu.bypass_required = 'YES' THEN IF p_enqu.bypass_required = 'YES' THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Bypass required.'); ,'Bypass required.');
END IF; END IF;
IF p_enqu.required_metering_pressure > 21 THEN IF p_enqu.required_metering_pressure > 21 THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Required metering pressure is greater than 21mbar.'); ,'Required metering pressure is greater than 21mbar.');
END IF; END IF;
IF p_enqu.job_description IS NOT NULL THEN IF p_enqu.job_description IS NOT NULL THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Job Description field was entered.'); ,'Job Description field was entered.');
END IF; END IF;
IF p_enqu.downstream_booster_or_compress = 'YES' THEN IF p_enqu.downstream_booster_or_compress = 'YES' THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Booster or compressor is present downstream of the meter module.'); ,'Booster or compressor is present downstream of the meter module.');
END IF; END IF;
IF p_enqu.annual_quantity > 732 THEN IF p_enqu.annual_quantity > 732 THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Required Annual Quantity is in excess of 732MWh.'); ,'Required Annual Quantity is in excess of 732MWh.');
END IF; END IF;
-- check postcode -- check postcode
IF NOT mip_regions.valid_postcode_format(p_enqu.install_postcode) THEN IF NOT mip_regions.valid_postcode_format(p_enqu.install_postcode) THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Installation postcode is of an unrecognized format.'); ,'Installation postcode is of an unrecognized format.');
ELSIF mip_regions.get_region_for_postcode(p_enqu.install_postcode) IS NULL THEN ELSIF mip_regions.get_region_for_postcode(p_enqu.install_postcode) IS NULL THEN
p_manual_or_automatic_quote := g_manual_quote; p_manual_or_automatic_quote := g_manual_quote;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,'Unable to determine pricing region for given installation postcode.'); ,'Unable to determine pricing region for given installation postcode.');
END IF; END IF;
END manual_or_automatic_quote; END manual_or_automatic_quote;
FUNCTION get_aico(p_aico_code IN costs.aico_code%TYPE FUNCTION get_aico(p_adit_code IN costs.adit_code%TYPE
,p_regi_code IN regions.code%TYPE) RETURN t_rec_costs IS ,p_regi_code IN regions.code%TYPE)
l_rec_costs t_rec_costs; RETURN t_rec_additional_item_costs IS
l_rec_costs t_rec_additional_item_costs;
BEGIN BEGIN
SELECT selling_price SELECT lead_time
,selling_price
,cost_price ,cost_price
,delivery_cost ,delivery_cost
INTO l_rec_costs.selling_price ,adit_code
INTO l_rec_costs.lead_time
,l_rec_costs.selling_price
,l_rec_costs.cost_price ,l_rec_costs.cost_price
,l_rec_costs.delivery_cost ,l_rec_costs.delivery_cost
,l_rec_costs.adit_code
FROM (SELECT decode(regi_code FROM (SELECT decode(regi_code
,p_regi_code ,p_regi_code
,1 ,1
@@ -226,13 +235,16 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
,selling_price ,selling_price
,cost_price ,cost_price
,delivery_cost ,delivery_cost
,adit_code
FROM v_aico cost FROM v_aico cost
WHERE aico_code = p_aico_code WHERE adit_code = p_adit_code
AND SYSDATE BETWEEN cost.effective_from AND cost.effective_to AND SYSDATE BETWEEN cost.effective_from AND cost.effective_to
AND regi_code = p_regi_code AND regi_code = p_regi_code
OR regi_code IS NULL OR regi_code IS NULL
ORDER BY 1) ORDER BY 1) cost
WHERE rownum < 2; ,additional_items adit
WHERE adit.code = cost.adit_code
AND rownum < 2;
RETURN l_rec_costs; RETURN l_rec_costs;
@@ -242,14 +254,13 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
END get_aico; END get_aico;
PROCEDURE produce_install_quotes(p_enqu IN t_enqu PROCEDURE produce_install_quotes(p_enqu IN t_enqu
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote ,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
,p_tab_manual_quote_reasons IN OUT t_tab_manual_quote_reasons) IS
l_produced_automatic_quote BOOLEAN; l_produced_automatic_quote BOOLEAN;
l_this_is_automatic_quote BOOLEAN; l_this_is_automatic_quote BOOLEAN;
l_regi_code regions.code%TYPE := mip_regions.get_region_for_postcode(p_enqu.install_postcode); l_regi_code regions.code%TYPE := mip_regions.get_region_for_postcode(p_enqu.install_postcode);
l_qute_id quotes.id%TYPE; l_qute_id quotes.id%TYPE;
l_item_sequence NUMBER; l_item_sequence NUMBER;
l_aico_costs t_rec_costs; l_aico_costs t_rec_additional_item_costs;
BEGIN BEGIN
cout_assert.istrue(p_enqu.enty_code IN ('INSTALL', 'STD INSTALL') cout_assert.istrue(p_enqu.enty_code IN ('INSTALL', 'STD INSTALL')
,'Attempted to produce an install quote for enquiry of type ' || ,'Attempted to produce an install quote for enquiry of type ' ||
@@ -263,6 +274,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
,modu.selling_price AS modu_selling_price ,modu.selling_price AS modu_selling_price
,modu.cost_price AS modu_cost_price ,modu.cost_price AS modu_cost_price
,modu.delivery_cost AS modu_delivery_cost ,modu.delivery_cost AS modu_delivery_cost
,modu.lead_time AS modu_lead_time
,hou.code AS hou_code ,hou.code AS hou_code
,hou.selling_price AS hou_selling_price ,hou.selling_price AS hou_selling_price
,hou.cost_price AS hou_cost_price ,hou.cost_price AS hou_cost_price
@@ -278,18 +290,26 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
,metr.selling_price AS metr_selling_price ,metr.selling_price AS metr_selling_price
,metr.cost_price AS metr_cost_price ,metr.cost_price AS metr_cost_price
,metr.delivery_cost AS metr_delivery_cost ,metr.delivery_cost AS metr_delivery_cost
,NULL AS amr_cost_id
,NULL AS amr_selling_price ,NULL AS amr_selling_price
,NULL AS amr_cost_price ,NULL AS amr_cost_price
,NULL AS amr_delivery_cost ,NULL AS amr_delivery_cost
,NULL AS amr_lead_time
,NULL AS ems_cost_id
,NULL AS ems_selling_price ,NULL AS ems_selling_price
,NULL AS ems_cost_price ,NULL AS ems_cost_price
,NULL AS ems_delivery_cost ,NULL AS ems_delivery_cost
,NULL AS ems_lead_time
,NULL AS bypass_cost_id
,NULL AS bypass_selling_price ,NULL AS bypass_selling_price
,NULL AS bypass_cost_price ,NULL AS bypass_cost_price
,NULL AS bypass_delivery_cost ,NULL AS bypass_delivery_cost
,NULL AS bypass_lead_time
,NULL AS logger_cost_id
,NULL AS logger_selling_price ,NULL AS logger_selling_price
,NULL AS logger_cost_price ,NULL AS logger_cost_price
,NULL AS logger_delivery_cost ,NULL AS logger_delivery_cost
,NULL AS logger_lead_time
FROM (SELECT modu.code FROM (SELECT modu.code
,modu.metr_code ,modu.metr_code
,modu.hou_code ,modu.hou_code
@@ -299,6 +319,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
,selling_price ,selling_price
,cost_price ,cost_price
,delivery_cost ,delivery_cost
,lead_time
FROM modules modu FROM modules modu
,(SELECT modu_code ,(SELECT modu_code
,selling_price ,selling_price
@@ -422,91 +443,131 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
p_enqu.housing_required <> 'YES')) p_enqu.housing_required <> 'YES'))
AND modu.hou_code = hou.code(+)) LOOP AND modu.hou_code = hou.code(+)) LOOP
l_this_is_automatic_quote := TRUE; l_this_is_automatic_quote := TRUE;
add_quote_reason(p_enqu.id
,p_reason => 'Considering module : ' ||
l_rec_module.modu_code
,p_internal_or_external => g_external_reason);
-- --
-- check whether we have the required prices -- check whether we have the required prices
-- if we do not, then we may need to produce a manual quote -- if we do not, then we may need to produce a manual quote
-- --
IF l_rec_module.modu_selling_price IS NULL THEN IF l_rec_module.modu_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for module ' || ,p_reason => 'Unable to find selling price for module ' ||
l_rec_module.modu_code l_rec_module.modu_code || '.'
,p_internal_or_external => g_external_reason);
END IF;
IF l_rec_module.modu_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 module ' ||
l_rec_module.modu_code || '.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
IF l_rec_module.metr_selling_price IS NULL THEN IF l_rec_module.metr_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for meter ' || ,p_reason => 'Unable to find selling price for meter ' ||
l_rec_module.metr_code l_rec_module.metr_code || '.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
IF p_enqu.base_required = 'YES' IF p_enqu.base_required = 'YES'
AND l_rec_module.bas_selling_price IS NULL THEN AND l_rec_module.bas_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for base ' || ,p_reason => 'Unable to find selling price for base ' ||
l_rec_module.bas_code l_rec_module.bas_code || '.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
IF p_enqu.housing_required = 'YES' IF p_enqu.housing_required = 'YES'
AND l_rec_module.hou_selling_price IS NULL THEN AND l_rec_module.hou_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for housing ' || ,p_reason => 'Unable to find selling price for housing ' ||
l_rec_module.hou_code l_rec_module.hou_code || '.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
IF p_enqu.amr_required = 'YES' THEN IF p_enqu.amr_required = 'YES' THEN
l_aico_costs := get_aico(p_aico_code => 'AMR' l_aico_costs := get_aico(p_adit_code => 'AMR'
,p_regi_code => l_regi_code); ,p_regi_code => l_regi_code);
l_rec_module.amr_selling_price := l_aico_costs.selling_price; l_rec_module.amr_selling_price := l_aico_costs.selling_price;
l_rec_module.amr_cost_price := l_aico_costs.cost_price; l_rec_module.amr_cost_price := l_aico_costs.cost_price;
l_rec_module.amr_delivery_cost := l_aico_costs.delivery_cost; l_rec_module.amr_delivery_cost := l_aico_costs.delivery_cost;
l_rec_module.amr_lead_time := l_aico_costs.lead_time;
IF l_rec_module.amr_selling_price IS NULL THEN IF l_rec_module.amr_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for AMR' ,p_reason => 'Unable to find selling price for AMR.'
,p_internal_or_external => g_external_reason);
END IF;
IF l_rec_module.amr_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 AMR.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
END IF; END IF;
IF p_enqu.ems_required = 'YES' THEN IF p_enqu.ems_required = 'YES' THEN
l_aico_costs := get_aico(p_aico_code => 'EMS' l_aico_costs := get_aico(p_adit_code => 'EMS'
,p_regi_code => l_regi_code); ,p_regi_code => l_regi_code);
l_rec_module.ems_selling_price := l_aico_costs.selling_price; l_rec_module.ems_selling_price := l_aico_costs.selling_price;
l_rec_module.ems_cost_price := l_aico_costs.cost_price; l_rec_module.ems_cost_price := l_aico_costs.cost_price;
l_rec_module.ems_delivery_cost := l_aico_costs.delivery_cost; l_rec_module.ems_delivery_cost := l_aico_costs.delivery_cost;
l_rec_module.ems_lead_time := l_aico_costs.lead_time;
IF l_rec_module.ems_selling_price IS NULL THEN IF l_rec_module.ems_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for EMS' ,p_reason => 'Unable to find selling price for EMS.'
,p_internal_or_external => g_external_reason);
END IF;
IF l_rec_module.amr_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 AMR.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
END IF; END IF;
IF p_enqu.bypass_required = 'YES' THEN IF p_enqu.bypass_required = 'YES' THEN
l_aico_costs := get_aico(p_aico_code => 'BYPASS' l_aico_costs := get_aico(p_adit_code => 'BYPASS'
,p_regi_code => l_regi_code); ,p_regi_code => l_regi_code);
l_rec_module.bypass_selling_price := l_aico_costs.selling_price; l_rec_module.bypass_selling_price := l_aico_costs.selling_price;
l_rec_module.bypass_cost_price := l_aico_costs.cost_price; l_rec_module.bypass_cost_price := l_aico_costs.cost_price;
l_rec_module.bypass_delivery_cost := l_aico_costs.delivery_cost; l_rec_module.bypass_delivery_cost := l_aico_costs.delivery_cost;
l_rec_module.bypass_lead_time := l_aico_costs.lead_time;
IF l_rec_module.bypass_selling_price IS NULL THEN IF l_rec_module.bypass_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for BYPASS' ,p_reason => 'Unable to find selling price for BYPASS.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
IF l_rec_module.bypass_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 BYPASS.'
,p_internal_or_external => g_external_reason);
END IF;
END IF; END IF;
IF p_enqu.logger_required = 'YES' THEN IF p_enqu.logger_required = 'YES' THEN
l_aico_costs := get_aico(p_aico_code => 'LOGGER' l_aico_costs := get_aico(p_adit_code => 'LOGGER'
,p_regi_code => l_regi_code); ,p_regi_code => l_regi_code);
l_rec_module.logger_selling_price := l_aico_costs.selling_price; l_rec_module.logger_selling_price := l_aico_costs.selling_price;
l_rec_module.logger_cost_price := l_aico_costs.cost_price; l_rec_module.logger_cost_price := l_aico_costs.cost_price;
l_rec_module.logger_delivery_cost := l_aico_costs.delivery_cost; l_rec_module.logger_delivery_cost := l_aico_costs.delivery_cost;
IF l_rec_module.logger_selling_price IS NULL THEN IF l_rec_module.logger_selling_price IS NULL THEN
l_this_is_automatic_quote := FALSE; l_this_is_automatic_quote := FALSE;
add_manual_quote_reason(p_tab_manual_quote_reasons add_quote_reason(p_enqu.id
,p_reason => 'Unable to find selling price for LOGGER' ,p_reason => 'Unable to find selling price for LOGGER.'
,p_internal_or_external => g_external_reason); ,p_internal_or_external => g_external_reason);
END IF; END IF;
IF l_rec_module.logger_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 LOGGER.'
,p_internal_or_external => g_external_reason);
END IF;
END IF; END IF;
IF l_this_is_automatic_quote THEN IF l_this_is_automatic_quote THEN
@@ -515,11 +576,15 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
INSERT INTO quotes INSERT INTO quotes
(id (id
,qute_type ,qute_type
,enqu_id) ,enqu_id
,valid_from
,valid_until)
VALUES VALUES
(qute_seq.NEXTVAL (qute_seq.NEXTVAL
,'AQ' -- automatic quote ,'AQ' -- automatic quote
,p_enqu.id) ,p_enqu.id
,trunc(SYSDATE)
,trunc(SYSDATE + 90))
RETURNING id INTO l_qute_id; RETURNING id INTO l_qute_id;
INSERT INTO quote_events INSERT INTO quote_events
@@ -584,26 +649,99 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
END IF; END IF;
IF p_enqu.amr_required = 'YES' THEN IF p_enqu.amr_required = 'YES' THEN
l_item_sequence := l_item_sequence + 1;
NULL; INSERT INTO quote_items
(item_sequence
,qute_id
,adit_code
,cost_price
,selling_price
,delivery_price
,lead_time)
VALUES
(l_item_sequence
,l_qute_id
,'AMR'
,l_rec_module.amr_cost_price
,l_rec_module.amr_selling_price
,l_rec_module.amr_delivery_cost
,l_rec_module.amr_lead_time);
END IF; END IF;
IF p_enqu.ems_required = 'YES' THEN
l_item_sequence := l_item_sequence + 1;
INSERT INTO quote_items
(item_sequence
,qute_id
,adit_code
,cost_price
,selling_price
,delivery_price
,lead_time)
VALUES
(l_item_sequence
,l_qute_id
,'EMS'
,l_rec_module.ems_cost_price
,l_rec_module.ems_selling_price
,l_rec_module.ems_delivery_cost
,l_rec_module.ems_lead_time);
END IF; END IF;
IF p_enqu.bypass_required = 'YES' THEN
l_item_sequence := l_item_sequence + 1;
INSERT INTO quote_items
(item_sequence
,qute_id
,adit_code
,cost_price
,selling_price
,delivery_price
,lead_time)
VALUES
(l_item_sequence
,l_qute_id
,'BYPASS'
,l_rec_module.bypass_cost_price
,l_rec_module.bypass_selling_price
,l_rec_module.bypass_delivery_cost
,l_rec_module.bypass_lead_time);
END IF;
IF p_enqu.logger_required = 'YES' THEN
l_item_sequence := l_item_sequence + 1;
INSERT INTO quote_items
(item_sequence
,qute_id
,adit_code
,cost_price
,selling_price
,delivery_price
,lead_time)
VALUES
(l_item_sequence
,l_qute_id
,'LOGGER'
,l_rec_module.logger_cost_price
,l_rec_module.logger_selling_price
,l_rec_module.logger_delivery_cost
,l_rec_module.logger_lead_time);
END IF;
END IF; -- automatic quote
END LOOP; END LOOP;
END produce_install_quotes; END produce_install_quotes;
PROCEDURE produce_automatic_quotes(p_enqu IN t_enqu PROCEDURE produce_automatic_quotes(p_enqu IN t_enqu
,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote ,p_manual_or_automatic_quote IN OUT t_manual_or_automatic_quote) IS
,p_tab_manual_quote_reasons IN OUT t_tab_manual_quote_reasons) IS
BEGIN BEGIN
cout_assert.istrue(p_manual_or_automatic_quote = g_automatic_quote cout_assert.istrue(p_manual_or_automatic_quote = g_automatic_quote
,p_message => 'Attempted to produce automatic quote for enquiry marked as manual only'); ,p_message => 'Attempted to produce automatic quote for enquiry marked as manual only');
IF p_enqu.enty_code IN ('INSTALL', 'STD INSTALL') THEN IF p_enqu.enty_code IN ('INSTALL', 'STD INSTALL') THEN
produce_install_quotes(p_enqu => p_enqu produce_install_quotes(p_enqu => p_enqu
,p_manual_or_automatic_quote => p_manual_or_automatic_quote ,p_manual_or_automatic_quote => p_manual_or_automatic_quote);
,p_tab_manual_quote_reasons => p_tab_manual_quote_reasons);
ELSE ELSE
cout_err.report_and_stop(p_exception_message => 'Attempted to produce automatic quote for unexpected enquiry type of ' || cout_err.report_and_stop(p_exception_message => 'Attempted to produce automatic quote for unexpected enquiry type of ' ||
p_enqu.enty_code); p_enqu.enty_code);
@@ -612,7 +750,6 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
PROCEDURE produce_quotes(p_id IN enquiries.id%TYPE) IS PROCEDURE produce_quotes(p_id IN enquiries.id%TYPE) IS
l_manual_or_automatic_quote t_manual_or_automatic_quote; l_manual_or_automatic_quote t_manual_or_automatic_quote;
l_tab_manual_quote_reasons t_tab_manual_quote_reasons;
l_enqu t_enqu; l_enqu t_enqu;
BEGIN BEGIN
@@ -626,19 +763,15 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation IS
WHERE id = p_id; WHERE id = p_id;
manual_or_automatic_quote(p_enqu => l_enqu manual_or_automatic_quote(p_enqu => l_enqu
,p_manual_or_automatic_quote => l_manual_or_automatic_quote ,p_manual_or_automatic_quote => l_manual_or_automatic_quote);
,p_tab_manual_quote_reasons => l_tab_manual_quote_reasons);
IF l_manual_or_automatic_quote = g_manual_quote THEN IF l_manual_or_automatic_quote = g_manual_quote THEN
request_manual_quote(p_id => l_enqu.id request_manual_quote(p_id => l_enqu.id);
,p_tab_manual_quote_reasons => l_tab_manual_quote_reasons);
ELSE ELSE
produce_automatic_quotes(p_enqu => l_enqu produce_automatic_quotes(p_enqu => l_enqu
,p_manual_or_automatic_quote => l_manual_or_automatic_quote ,p_manual_or_automatic_quote => l_manual_or_automatic_quote);
,p_tab_manual_quote_reasons => l_tab_manual_quote_reasons);
IF l_manual_or_automatic_quote = g_manual_quote THEN IF l_manual_or_automatic_quote = g_manual_quote THEN
request_manual_quote(p_id => l_enqu.id request_manual_quote(p_id => l_enqu.id);
,p_tab_manual_quote_reasons => l_tab_manual_quote_reasons);
END IF; END IF;
-- --