fixed a bug on the data collection for the quotation, was not correctly gathering the delivery costs, also added labour costs. Pointed the generate_detailed_pdf_quote to store the pdf in the APEX_APPLICATION_FILES table, also added code to place the ngm logo and DH's signature to the pages.

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3151 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
PriestJ
2008-01-07 18:06:19 +00:00
parent daeef4b148
commit ac7fe30db1

View File

@@ -74,7 +74,7 @@ CREATE OR REPLACE PACKAGE mip_quotation_document IS
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 BOOLEAN;
FUNCTION generate_detailed_quote_pdf(p_quote_data in quote_data) RETURN NUMBER;
END mip_quotation_document;
/
CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
@@ -312,7 +312,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
p_quote_data.quote_costs(l_counter).cost_description := 'Base Materials cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.selling_price;
if not (quote_item_rec.delivery_price is null) then
p_quote_data.quote_costs(l_counter).cost_description := 'Base Labour cost';
l_counter:=l_counter +1;
p_quote_data.quote_costs(l_counter).cost_description := 'Base Delivery cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.delivery_price;
end if;
--get the base details
@@ -338,7 +339,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
p_quote_data.quote_costs(l_counter).cost_description := 'Housing Materials cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.selling_price;
if not (quote_item_rec.delivery_price is null) then
p_quote_data.quote_costs(l_counter).cost_description := 'Housing Labour cost';
l_counter:=l_counter +1;
p_quote_data.quote_costs(l_counter).cost_description := 'Housing Delivery cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.delivery_price;
end if;
--get the housing code and return the housing details into p_quote_data
@@ -363,7 +365,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
p_quote_data.quote_costs(l_counter).cost_description := l_add_item_row.description||' Materials cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.selling_price;
if not(quote_item_rec.delivery_price is null) then
p_quote_data.quote_costs(l_counter).cost_description := l_add_item_row.description||' Labour cost';
l_counter:=l_counter +1;
p_quote_data.quote_costs(l_counter).cost_description := l_add_item_row.description||' Delivery cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.delivery_price;
end if;
--set the list of add-ons for this quote
@@ -373,7 +376,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
p_quote_data.quote_costs(l_counter).cost_description := 'Module Materials cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.selling_price;
if not(quote_item_rec.delivery_price is null) then
p_quote_data.quote_costs(l_counter).cost_description := 'Module Labour cost';
l_counter:=l_counter +1;
p_quote_data.quote_costs(l_counter).cost_description := 'Module Delivery cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.delivery_price;
end if;
--other module details
@@ -405,6 +409,15 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
p_quote_data.module_qmax := l_meter_row.qmax;
p_quote_data.module_qmin := l_meter_row.qmin;
when 'LQI' then --Labour cost
--get costs
p_quote_data.quote_costs(l_counter).cost_description := 'Labour Costs';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.selling_price;
if not(quote_item_rec.delivery_price is null) then
l_counter:=l_counter +1;
p_quote_data.quote_costs(l_counter).cost_description := 'Labour Delivery cost';
p_quote_data.quote_costs(l_counter).cost_price := quote_item_rec.delivery_price;
end if;
end case;
@@ -590,9 +603,11 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
%param p_quote_data in - The current data for this quote
%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_vertical_offset - the top margin measurement.
%param p_logo_blob - the logo(image) to display at the top of the page
%param p_signature_blob - the signature(image) to display at the bottom of the page
*/
PROCEDURE build_covering_letter(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number) is
PROCEDURE build_covering_letter(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number,p_logo_blob blob,p_signature_blob blob) is
l_contracts_text varchar2(500);
begin
plpdf.NewPage;
@@ -603,6 +618,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.SetPrintFont(p_font,null,7);
-- Set header stuff up
plpdf.PutImage('ngmlogo',p_logo_blob,p_indent,10,52,18);
plpdf.PrintText(140,10,'4 Abbotts Lane ');
plpdf.PrintText(140,13,'Coventry');
plpdf.PrintText(140,16,'CV1 4AY');
@@ -654,6 +670,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
--
plpdf.PrintText(p_indent,p_vertical_offset+188,'If you have any queries, please contact the team on the number above');
plpdf.PrintText(p_indent,p_vertical_offset+196,'Yours sincerely');
--put on daves signature
plpdf.PutImage('dhsignature',p_signature_blob,p_indent,230,40,10);
plpdf.PrintText(p_indent,p_vertical_offset+216,'David Harper');
plpdf.PrintText(p_indent,p_vertical_offset+220,'I&C Technical Manager');
plpdf.PrintText(p_indent,p_vertical_offset+224,'National Grid Metering');
@@ -670,6 +688,8 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
PROCEDURE build_costs_page(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number) is
l_cost_line_counter number;
l_vertical_offset_for_costs number := p_vertical_offset+110;
l_works_counter number;
l_vertical_offset_for_works number := p_vertical_offset+52;
l_cost_totals_offset number; --used to position the cost totals after the cost line items
begin
--Page 2
@@ -688,13 +708,13 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintText(p_indent,p_vertical_offset+38,'Re: '||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
plpdf.SetPrintFont(p_font,'U',10); --set underline
plpdf.PrintText(p_indent,p_vertical_offset+48,'Full Description of Works to be carried out by National Grid Metering:');
plpdf.SetPrintFont(p_font,'B',10); --set bold
plpdf.PrintText(p_indent,p_vertical_offset+56, p_quote_data.quote_works(1));
plpdf.PrintText(p_indent,p_vertical_offset+60, p_quote_data.quote_works(2));
plpdf.PrintText(p_indent,p_vertical_offset+64, p_quote_data.quote_works(3));
plpdf.PrintText(p_indent,p_vertical_offset+68, p_quote_data.quote_works(4));
plpdf.PrintText(p_indent,p_vertical_offset+72, p_quote_data.quote_works(5));
plpdf.PrintText(p_indent,p_vertical_offset+76, p_quote_data.quote_works(6));
plpdf.SetPrintFont(p_font,'B',10); --set bold
l_works_counter := 1;
while p_quote_data.quote_works(l_works_counter) is not null
loop
plpdf.PrintText(p_indent,l_vertical_offset_for_works+(l_works_counter*4), p_quote_data.quote_works(l_works_counter));
l_works_counter := l_works_counter +1;
end loop;
plpdf.SetPrintFont(p_font,null,10); --unset bold
plpdf.PrintText(p_indent,p_vertical_offset+90, 'Indicative Lead Time from Acceptance to Physical Commencement: ');
plpdf.SetPrintFont(p_font,'B',10); --set bold
@@ -702,7 +722,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.SetPrintFont(p_font,null,10); --unset bold
plpdf.PrintText(p_indent,p_vertical_offset+98,'Contract sum (excluding V.A.T): ');
plpdf.SetPrintFont(p_font,'B',10); --set bold
plpdf.PrintText(85,p_vertical_offset+98,'<27>'||p_quote_data.total_cost);
plpdf.PrintText(85,p_vertical_offset+98,'<27>'||to_char(p_quote_data.total_cost,'FM999999D90'));
plpdf.SetPrintFont(p_font,null,10); --unset bold
plpdf.PrintText(p_indent,p_vertical_offset+106,'Analysis of Costs (all costs exclude V.A.T)');
plpdf.SetPrintFont(p_font,'B',10); --set bold
@@ -710,7 +730,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
while p_quote_data.quote_costs(l_cost_line_counter).cost_description is not null
loop
plpdf.PrintText(p_indent,l_vertical_offset_for_costs+l_cost_line_counter*4,p_quote_data.quote_costs(l_cost_line_counter).cost_description);
plpdf.PrintText(120,l_vertical_offset_for_costs+l_cost_line_counter*4,'<27>'||p_quote_data.quote_costs(l_cost_line_counter).cost_price);
plpdf.PrintText(120,l_vertical_offset_for_costs+l_cost_line_counter*4,'<27>'||to_char(p_quote_data.quote_costs(l_cost_line_counter).cost_price,'FM999999D90'));
l_cost_line_counter := l_cost_line_counter +1;
end loop;
l_cost_totals_offset := l_vertical_offset_for_costs+l_cost_line_counter*4;
@@ -720,7 +740,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintText(120,l_cost_totals_offset,'<27>220');
plpdf.DrawLine(p_indent,l_cost_totals_offset+2,185,l_cost_totals_offset+2);
plpdf.PrintText(p_indent,l_cost_totals_offset+6,'Total costs:');
plpdf.PrintText(120,l_cost_totals_offset+6,'<27>'||p_quote_data.total_cost||' excluding lifting gear if required');
plpdf.PrintText(120,l_cost_totals_offset+6,'<27>'||to_char(p_quote_data.total_cost,'FM999999D90')||' excluding lifting gear if required');
end build_costs_page;
/*
PROCEDURE build_caveats_page
@@ -745,7 +765,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.PrintText(p_indent,p_vertical_offset+18,'Length: '||p_quote_data.house_length||' mm');
plpdf.PrintText(p_indent+40,p_vertical_offset+18,'Depth: '||p_quote_data.house_depth||' mm');
plpdf.PrintText(p_indent+80,p_vertical_offset+18,'Height: '||p_quote_data.house_height||' mm');
plpdf.PrintText(p_indent,p_vertical_offset+26,'Minimum Ventilation: '||p_quote_data.house_ventilation||' sq. cm');
plpdf.PrintText(p_indent,p_vertical_offset+26,'Minimum Ventilation: '||p_quote_data.house_ventilation/10||' sq. cm');
--base
plpdf.PrintText(p_indent,p_vertical_offset+42,'Meter Housing Base (if required):');
plpdf.PrintText(p_indent,p_vertical_offset+50,'Length: '||p_quote_data.base_length||' mm');
@@ -960,9 +980,10 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
%param p_quote_data in - The current data for this quote
%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_vertical_offset - the top margin measurement.
%param p_logo_blob - the logo(image) to display at the top of the page
*/
PROCEDURE build_acceptance_page(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number) is
PROCEDURE build_acceptance_page(p_quote_data in quote_data, p_font in varchar2, p_indent in number, p_vertical_offset in number,p_logo_blob blob) is
begin
---weeeeee last page
plpdf.NewPage;
@@ -971,6 +992,7 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
plpdf.SetRightMargin(31.7);
plpdf.SetTopMargin(25.4);
-- Set header stuff up
plpdf.PutImage('ngmlogo',p_logo_blob,p_indent,10,52,18);
plpdf.SetPrintFont(p_font,null,7);
plpdf.PrintText(140,10,'4 Abbotts Lane ');
plpdf.PrintText(140,13,'Coventry');
@@ -1031,31 +1053,55 @@ CREATE OR REPLACE PACKAGE BODY mip_quotation_document IS
--The generate_detailed_quote_pdf builds the pdf document for the quotation from
--the supplied data and stores the resulting pdf document in the database.
%param p_quote_data - the data to build into the quote.
%return - true if we created and stored the pdf(perhaps should be the id of the pdf file
%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 BOOLEAN is
FUNCTION generate_detailed_quote_pdf(p_quote_data in quote_data) RETURN NUMBER is
l_blob blob;
l_logo_blob blob;
l_signature_blob blob;
l_pdf_id number; -- 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
CURSOR c_get_logo(cp_logo varchar2) IS
SELECT blob_content
FROM wwv_flow_files
WHERE filename = cp_logo;
CURSOR c_get_signature(cp_signature varchar2) IS
SELECT blob_content
FROM wwv_flow_files
WHERE filename = cp_signature;
begin
-- Get the blob from somewhere
--Simple example to retrieve and use template:
IF NOT c_get_logo%ISOPEN THEN
OPEN c_get_logo('quote_logo.jpg');
END IF;
FETCH c_get_logo
INTO l_logo_blob;
CLOSE c_get_logo;
IF NOT c_get_signature%ISOPEN THEN
OPEN c_get_signature('quote_signature.jpg');
END IF;
FETCH c_get_signature
INTO l_signature_blob;
CLOSE c_get_signature;
-- Initialize PDF
plpdf.init;
--build the pages for the quote
build_covering_letter(p_quote_data,l_font,l_indent,l_vertical_offset); --1
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); --4
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); --6
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
plpdf.SendDoc(l_blob);
--punt the created pdf into the testpdf table
insert into testpdf (id, pdf_report)
values (11, l_blob);
return true; -- perhaps we should return the id of the newly created blob record?
--punt the created pdf into the APEX files table
insert into wwv_flow_files( name, filename, title, mime_type, flow_id, doc_size ,description, blob_content )
values (TO_CHAR(SYSDATE,'SSSSS')||'/quote',p_quote_data.quote_ref||'_quote.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;
return l_pdf_id; -- return the id of the newly created blob pdf record
end generate_detailed_quote_pdf;