now does drawings (requires more testing), hides drawings page if OFMAT or ADD-ON. More tidying up and bug fixing

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3179 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
PriestJ
2008-01-09 16:52:54 +00:00
parent 2a0da18162
commit 177b3d818e

View File

@@ -6,6 +6,8 @@ CREATE OR REPLACE PACKAGE mip_quotation_document IS
-- Public type declarations
--type <TypeName> is <Datatype>;
type img_props is record(width number,
height number);
type cost_line is record(
cost_description varchar2(80),
cost_price number);
@@ -66,25 +68,94 @@ CREATE OR REPLACE PACKAGE mip_quotation_document IS
-- Public variable declarations
--<VariableName> <Datatype>;
function get_total_cost(p_quoteid number) return number;
--function get_total_cost(p_quoteid number) return number;
-- Public function and procedure declarations
-- function <FunctionName>(<Parameter> <Datatype>) return <Datatype>;
function get_mam(p_region_code varchar2) return varchar2;
function get_module_row(p_code varchar2) return modules%ROWTYPE;
function get_max_lead_time(p_quoteid number) return number;
FUNCTION determine_caveats(p_enquiryid in number) RETURN BOOLEAN;
PROCEDURE set_quote_items_data (p_quote_data in out quote_data, p_quoteid number, p_enqu_row enquiries%ROWTYPE);
FUNCTION get_detailed_quote_data(p_quoteid in number) RETURN quote_data;
FUNCTION generate_detailed_quote_pdf(p_quote_data in quote_data) RETURN NUMBER;
--function get_mam(p_region_code varchar2) return varchar2;
--function get_module_row(p_code varchar2) return modules%ROWTYPE;
--function get_max_lead_time(p_quoteid number) return number;
--FUNCTION determine_caveats(p_enquiryid in number) RETURN BOOLEAN;
--PROCEDURE set_quote_items_data (p_quote_data in out quote_data, p_quoteid number, p_enqu_row enquiries%ROWTYPE);
--FUNCTION get_detailed_quote_data(p_quoteid in number) RETURN quote_data;
--FUNCTION generate_detailed_quote_pdf(p_quote_data in quote_data) RETURN VARCHAR2;
FUNCTION generate_quote_pdf(p_quote_id in number) RETURN VARCHAR2;
END mip_quotation_document;
/
CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
/*
FUNCTION scale_image_dimensions
--The scale_image_dimensions provides the width and height of an image to
--correctly scale into a specified size.
%param p_req_width - The maximum width required for the image
%param p_req_height - The maximum height required for the image
%param p_image_blob - The image we may need to scale down
%return img_props - the new width and height of the image
*/
function scale_image_dimensions(p_req_width in number, p_req_height in number, p_image_blob in blob) return img_props is
l_new_width number;
l_ratio number;
l_new_height number;
l_cur_width number;
l_image_props plpdf_type.t_imageprops;
l_new_dimensions img_props;
begin
--Get the properties for the image from plpdf
l_image_props:=plpdf_img.getimageprops(p_image_blob);
--if the image is too heigh cut it down to the limit and record the ratio
--and cutting the width by the recored ratio
if l_image_props.height > p_req_height then
l_new_height := p_req_height;
l_ratio := l_image_props.height/p_req_height;
l_cur_width := l_image_props.width/l_ratio;
else
l_new_height := l_image_props.height;
l_cur_width := l_image_props.width;
end if;
--if it's too wide then cut it down to the limit and record the ratio
--and cutting the height by the recored ratio
if l_cur_width > p_req_width then
l_new_width := p_req_width;
l_ratio := l_cur_width/p_req_width;
l_new_height := l_new_height/l_ratio;
else
l_new_width := l_cur_width;
end if;
l_new_dimensions.width := l_new_width;
l_new_dimensions.height := l_new_height;
return l_new_dimensions;
end scale_image_dimensions;
/*
FUNCTION get_drawing
--The get_drawing function returns a blob of the drawing code
%param p_drwg_code - the code of the drawing you want the blob of.
%return blob the drawing image
*/
function get_drawing(p_drwg_code varchar2) return blob is
l_blob blob;
CURSOR c_get_drawing(cp_drwg varchar2) IS
SELECT blob_content
FROM wwv_flow_files
WHERE name = (SELECT uri
FROM documents
WHERE (SELECT docu_id
FROM document_roles
WHERE cp_drwg = drwg_code)=id);
begin
IF NOT c_get_drawing%ISOPEN THEN
OPEN c_get_drawing(p_drwg_code);
END IF;
FETCH c_get_drawing
INTO l_blob;
CLOSE c_get_drawing;
return l_blob;
end get_drawing;
/*
FUNCTION get_mam
--The get_mam function returns a meter asset manager description for the supplied region code.
%param p_region_code - the code of the region you want to get the mam description of.
%return varchar(80)description of the supplied regions code mam
*/
*/
function get_mam(p_region_code varchar2) return varchar2 is
l_mam_desc varchar2(80);
CURSOR c_get_mam(cp_region_code varchar2) IS
@@ -822,8 +893,12 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
%param p_font - the type of font to use - typically 'Arial'.
%param p_indent - the left margin measurement.
%param p_vertical_offset - the top margin measurement.
%param p_base_blob - the image of the base
%param p_house_blob - the image of the house
%param p_module_blob - the image of the module
*/
PROCEDURE build_drawings_page(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number, p_module_blob blob) is
PROCEDURE build_drawings_page(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number, p_base_blob blob, p_house_blob blob, p_module_blob blob) is
l_img_props img_props;
begin
--Okay here come the pretty pictures, the technical spec for the module, house & base
--this will be page 4 for the quotation
@@ -836,6 +911,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintText(p_indent,p_vertical_offset,'Technical Specification for '||p_quote_data.quote_ref);
plpdf.SetPrintFont(p_font,'B',10); --set back to 10pt
plpdf.PrintText(p_indent,p_vertical_offset+6,'Re: '||rtrim(ltrim(p_quote_data.site_address(1)||', '||p_quote_data.site_address(2)||', '||p_quote_data.site_address(3)||', '||p_quote_data.site_address(4)||', '||p_quote_data.site_address(5)||', '||p_quote_data.site_address(6)||', '||p_quote_data.site_address(7),', '),', ')); --site address --Base Details
--Base Details
plpdf.SetPrintFont(p_font,'BU',12); --set bold,underline and 12pt
plpdf.PrintText(p_indent,p_vertical_offset+12,'Floor Area/Base Requirements');
plpdf.SetPrintFont(p_font,null,10); --set back to 10pt plain
@@ -860,6 +936,12 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintCell(15,6,p_quote_data.base_dimensions(9),1,1,'R',0);
plpdf.PrintCell(15,6,'Dim I:',1,0,'L',0);
plpdf.PrintCell(15,6,p_quote_data.base_dimensions(10),1,1,'R',0);
if p_base_blob is null then
plpdf.PrintText(p_indent+50,p_vertical_offset+50,'No Base Diagram Available');
else
l_img_props := scale_image_dimensions(100, 60, p_module_blob );
plpdf.PutImage('base',p_base_blob,p_indent,10,l_img_props.width,l_img_props.height);
end if;
--House Details
plpdf.SetPrintFont(p_font,'BU',12); --set bold,underline and 12pt
plpdf.PrintText(p_indent,p_vertical_offset+100,'Housing / Work Area');
@@ -873,6 +955,12 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintCell(15,6,p_quote_data.house_dimensions(3),1,1,'R',0);
plpdf.PrintCell(15,6,'Weight:',1,0,'L',0);
plpdf.PrintCell(15,6,p_quote_data.house_dimensions(4),1,1,'R',0);
if p_house_blob is null then
plpdf.PrintText(p_indent+50,p_vertical_offset+132,'No House Diagram Available');
else
l_img_props := scale_image_dimensions(100, 60, p_module_blob );
plpdf.PutImage('house',p_house_blob,p_indent+50,108,l_img_props.width,l_img_props.height);
end if;
--Module details
plpdf.SetPrintFont(p_font,'BU',12); --set bold,underline and 12pt
plpdf.PrintText(p_indent,p_vertical_offset+168,'Module Dimensions');
@@ -896,7 +984,12 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintCell(15,6,p_quote_data.module_dimensions(8),1,1,'R',0);
plpdf.PrintCell(15,6,'Weight:',1,0,'L',0);
plpdf.PrintCell(15,6,p_quote_data.module_dimensions(9),1,1,'R',0);
plpdf.PutImage('module',p_module_blob,p_indent,10,52,18);
if p_module_blob is null then
plpdf.PrintText(p_indent+50,p_vertical_offset+205,'No Module Diagram Available');
else
l_img_props := scale_image_dimensions(100, 60, p_module_blob );
plpdf.PutImage('module',p_module_blob,p_indent+50,p_vertical_offset+180,l_img_props.width,l_img_props.height);
end if;
plpdf.SetPrintFont(p_font,null,9); --set to 9pt
plpdf.PrintText(p_indent,p_vertical_offset+245,'Note: All weights are in kg and all dimensions in mm Module Ref: '||p_quote_data.module_reference);
plpdf.PrintText(p_indent,p_vertical_offset+260,'National Grid Metering, Abbotts Lane, Coventry, West Midlands, CV1 4AY Tel 02476 286000 Fax 02476 286022');
@@ -979,8 +1072,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintCell(35,6,p_quote_data.module_outlet_size||'mm',1,1,'C',0);
plpdf.SetCurrentX(91.7);
plpdf.PrintCell(30,6,'Type',1,0,'C',0);
plpdf.PrintCell(35,6,p_quote_data.module_inlet_type||'mm',1,0,'C',0);
plpdf.PrintCell(35,6,p_quote_data.module_outlet_type||'mm',1,1,'C',0);
plpdf.PrintCell(35,6,p_quote_data.module_inlet_type,1,0,'C',0);
plpdf.PrintCell(35,6,p_quote_data.module_outlet_type,1,1,'C',0);
plpdf.SetCurrentX(91.7);
plpdf.PrintCell(30,6,'Orientation',1,0,'C',0);
plpdf.PrintCell(35,6,p_quote_data.module_inlet_orientation,1,0,'C',0);
@@ -1085,13 +1178,16 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
%param p_quote_data - the data to build into the quote.
%return - l_pdf_id the id of the pdf file we have created
*/
FUNCTION generate_detailed_quote_pdf(p_quote_data in quote_data) RETURN NUMBER is
l_doc_id number; -- the id of the stored pdf
FUNCTION generate_detailed_quote_pdf(p_quote_data in quote_data,p_quote_id in number) RETURN VARCHAR2 is
l_blob blob;
l_enty_code varchar(80); --the type of enquiry
l_logo_blob blob;
l_signature_blob blob;
l_success boolean; --holds whether the quote was saved i nthe docuemnts tables or not
l_base_blob blob; --the base drawing
l_house_blob blob; --the house drawing
l_module_blob blob; --the module drawing
l_pdf_id number; -- the id of the quote we generate
l_pdf_name varchar(90); -- the id of the quote we generate
l_indent number := 31.7;
l_vertical_offset number := 30;
l_font varchar2(40) := 'Arial'; --arial not daz
@@ -1103,14 +1199,11 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
SELECT blob_content
FROM wwv_flow_files
WHERE filename = cp_signature;
--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
--This will not work need to reference through the
--document roles table to get the file name (uri) then
--we can search the wwv_flow_files
CURSOR c_get_module(cp_module varchar2) IS
SELECT blob_content
FROM wwv_flow_files
WHERE filename = cp_module;
CURSOR c_get_enty(cp_quid varchar2) IS
SELECT enty_code
FROM quote_items
WHERE qute_id = cp_quid and quit_type = 'LQI' ;
begin
IF NOT c_get_logo%ISOPEN THEN
OPEN c_get_logo('quote_logo.jpg');
@@ -1124,20 +1217,26 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
FETCH c_get_signature
INTO l_signature_blob;
CLOSE c_get_signature;
IF NOT c_get_module%ISOPEN THEN
OPEN c_get_module(p_quote_data.module_diagram);
IF NOT c_get_enty%ISOPEN THEN
OPEN c_get_enty(p_quote_id);
END IF;
FETCH c_get_module
INTO l_module_blob;
CLOSE c_get_module;
FETCH c_get_enty
INTO l_enty_code;
CLOSE c_get_enty;
--get the quote diagrams
l_base_blob := get_drawing(p_quote_data.base_diagram);
l_house_blob := get_drawing(p_quote_data.house_diagram);
l_module_blob := get_drawing(p_quote_data.module_diagram);
-- Initialize PDF
plpdf.init;
--build the pages for the quote
build_covering_letter(p_quote_data,l_font,l_indent,l_vertical_offset,l_logo_blob, l_signature_blob);--1
build_costs_page(p_quote_data,l_font,l_indent,l_vertical_offset); --2
build_caveats_page(p_quote_data,l_font,l_indent,l_vertical_offset); --3
build_drawings_page(p_quote_data,l_font,l_indent,l_vertical_offset, l_module_blob); --4
--OFMAT, Addon jobs don't have module diagrams
if not (l_enty_code = 'OFMAT' or l_enty_code = 'AMR' or l_enty_code = 'EMS') then
build_drawings_page(p_quote_data,l_font,l_indent,l_vertical_offset, l_base_blob, l_house_blob, l_module_blob); --4
end if;
build_module_specs_page(p_quote_data,l_font,l_indent,l_vertical_offset); --5
build_acceptance_page(p_quote_data,l_font,l_indent,l_vertical_offset,l_logo_blob); --6
--get our beautiful pdf into the local var l_blob
@@ -1145,26 +1244,31 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
--punt the created pdf into the APEX files table
insert into wwv_flow_files( name, title, mime_type, flow_id, doc_size ,description, blob_content )
values (TO_CHAR(SYSDATE,'SSSSS')||'/quote_'||p_quote_data.quote_ref||'.pdf', 'Quotation - '||p_quote_data.quote_ref, 'application/pdf', 190, DBMS_LOB.GETLENGTH(l_blob),'this is an auto generated quotation from mip_quotation_document.generate_detailed_quote for quotation '||p_quote_data.quote_ref, l_blob)
returning id into l_pdf_id;
--reference it in the documents table
insert into documents( uri, description, id, docu_type )
values (TO_CHAR(SYSDATE,'SSSSS')||'/quote_'||p_quote_data.quote_ref||'.pdf',
'Automatically Generated Quotation for quote '||p_quote_data.quote_ref,
docu_seq.NEXTVAL,
'INDO')
returning id into l_doc_id;
--set up a role for the document
insert into document_roles(rt_code, start_date,description,qute_id,id,doro_type,docu_id)
values ('GENERATED QUOTATION',
sysdate,
'Automatically Generated Quotation for quote '||p_quote_data.quote_ref,
p_quote_data.quote_ref,
doro_seq.NEXTVAL,
'QUDO',
l_doc_id);
return l_pdf_id; -- return the id of the newly created blob pdf record
returning name into l_pdf_name;
--set up the file associations within our documents tables
l_success:= mip_files.set_file_association(l_pdf_name,
'Automatically Generated Quotation for quote '||p_quote_data.quote_ref,
'INDO',
'GENERATED QUOTATION',
p_quote_data.quote_ref,
null,
null,
'QUDO');
return l_pdf_name; -- return the id of the newly created blob pdf record
end generate_detailed_quote_pdf;
/*
FUNCTION generate_quote_pdf
--The generate_detailed_quote_pdf builds the pdf document for the quotation from
--the supplied quote id and stores the resulting pdf document in the database.
%param p_quote_id - the id of the quote you want to build a pdf for.
%return - the name of the pdf file we have created. This is a unique value within the wwv_flow_files table
*/
FUNCTION generate_quote_pdf(p_quote_id in number) RETURN VARCHAR2 is
l_quote_data quote_data;
begin
l_quote_data := get_detailed_quote_data(p_quote_id);
return generate_detailed_quote_pdf(l_quote_data, p_quote_id);
end generate_quote_pdf;
BEGIN