diff --git a/Modules/MIP_FILES.pck b/Modules/MIP_FILES.pck index fe4e468..20ff506 100644 --- a/Modules/MIP_FILES.pck +++ b/Modules/MIP_FILES.pck @@ -21,6 +21,64 @@ PROCEDURE export_table_to_csv(p_table IN VARCHAR2, end MIP_FILES; / create or replace package body MIP_FILES as + /* + FUNCTION drawing_file_exists + - takes the drawing code and searches for associated file in APEX Application + - Files, returns true if the file exists or false if it does not exist + %param p_drwg_code - the drawing code + */ + function drawing_file_exists(p_drwg_code varchar2) return boolean is + l_file_exists number; + CURSOR c_file_exists(cp_drwg_code varchar2) IS + select 1 + from wwv_flow_files + where name=(select d.uri + from mip_dev_e.documents d, mip_dev_e.document_roles dr + where dr.drwg_code = cp_drwg_code and d.id = dr.docu_id); + begin + IF NOT c_file_exists%ISOPEN THEN + OPEN c_file_exists(p_drwg_code); + END IF; + FETCH c_file_exists + INTO l_file_exists; + CLOSE c_file_exists; + if l_file_exists is not null and l_file_exists>0 then + return true; + end if; + end drawing_file_exists; + /* + FUNCTION update_file_association + - updates the association between a object within webmip to a file held in the + - APEX application files view and ophans any existing files. + %param p_uri - the uri of the file (the contents of the name column in APEX application files) + %param p_description - description of the file, will be set in documents and document_roles table + %param p_docu_type - INDO (held within webmip db), EXDO (held outside webmip), FIDO (on file system) + %param p_qute_id - the quote id if applicable otherwise supply null + %param p_enqu_id - the enquiry id if applicable otherwise supply null + %param p_drwg_code - the drawing code if applicable otherwise supply null + */ + function update_file_association(p_uri in varchar2, + p_description in varchar2, + p_docu_type in varchar2, + p_qute_id in number, + p_enqu_id in number, + p_drwg_code in varchar2) return boolean is + l_doc_id number; + + begin + --reference it in the documents table + insert into documents( uri, description, id, docu_type ) + values (p_uri, + p_description, + docu_seq.NEXTVAL, + p_docu_type) + returning id into l_doc_id; + --set up a role for the document + update document_roles set docu_id = l_doc_id + where drwg_code = p_drwg_code or qute_id = p_qute_id or enqu_id = p_enqu_id; + --if it works then return true + return true; + end update_file_association; /* FUNCTION set_file_association - sets the association between a object within webmip to a file held in the