 		exception when others then
 			ll_bgt_justi_clob:=null;
 		end;
-  
+  /* Commented this now obsolete
   select count(DOCUMENT_NUMBER) into li_count_bud_doc from BUDGET_DOCUMENT 
   where PARENT_DOCUMENT_KEY in (select document_number from eps_proposal where proposal_number = ls_proposal_number )
   and   VER_NBR = li_version_number;
+  */
+	select count(t1.budget_id) into li_count_bud_doc  from budget t1 
+	inner join eps_proposal_budget_ext t2 on t1.budget_id = t2.budget_id
+	where t2.proposal_number = ls_proposal_number
+	and t1.version_number = li_version_number; 
+  
+  
   
  ------------ I N S E R T 
     if li_count_bud_doc = 0 then 

								where PARENT_DOCUMENT_KEY in (select document_number from eps_proposal where proposal_number = ls_proposal_number )
								and   VER_NBR = li_version_number
							   );
	
	UPDATE EPS_PROPOSAL_BUDGET_EXT
	SET FINAL_VERSION_FLAG = r_budget.FINAL_VERSION_FLAG
	WHERE   BUDGET_ID in (SELECT BUDGET_ID FROM BUDGET WHERE DOCUMENT_NUMBER IN(

							where PARENT_DOCUMENT_KEY in (select document_number from eps_proposal where proposal_number = ls_proposal_number )
							and   VER_NBR = li_version_number)
						   );
	*/
	
	begin
		select BUDGET_STATUS into ls_budget_status FROM EPS_PROPOSAL 
		WHERE PROPOSAL_NUMBER = ls_proposal_number;		
	exception
	when others then
		ls_budget_status := 'C';
	end;	
	
	UPDATE EPS_PROPOSAL_BUDGET_EXT
	SET FINAL_VERSION_FLAG = r_budget.FINAL_VERSION_FLAG,
	STATUS_CODE = ls_budget_status
	WHERE BUDGET_ID IN (
		select t1.budget_id  from budget t1 
		inner join eps_proposal_budget_ext t2 on t1.budget_id = t2.budget_id
		where t2.proposal_number = ls_proposal_number
		and t1.version_number = li_version_number);
			
	
	
end if;
