Untitled
unknown
plain_text
a year ago
7.0 kB
1
Indexable
Never
PROCEDURE Insert_Structure___ ( mch_code_ IN VARCHAR2, mch_contract_ IN VARCHAR2, cost_type_db_ IN VARCHAR2, cre_date_ IN DATE, amount_ IN NUMBER, order_contract_ IN VARCHAR2, percent_of_source_ IN NUMBER, cost_source_ IN VARCHAR2, source_ref1_ IN VARCHAR2, source_ref2_ IN VARCHAR2, source_ref3_ IN VARCHAR2, source_ref4_ IN VARCHAR2, cost_revenue_ IN VARCHAR2, row_checked_ IN VARCHAR2 ) IS company_ VARCHAR2(20); current_company_ VARCHAR2(20); company_contract_ VARCHAR2(30); currency_code_ VARCHAR2(20); coverted_amount_ NUMBER; project_no_ VARCHAR2(30); order_company_ VARCHAR2(20); current_mch_contract_ VARCHAR2(30); current_mch_code_ VARCHAR2(300); current_equip_obj_sq_ NUMBER; current_sup_contract_ VARCHAR2(30); current_sup_mch_code_ VARCHAR2(300); current_func_obj_sq_ NUMBER; attr_ VARCHAR2(32000); save_attr_ VARCHAR2(32000); newrec_ EQUIPMENT_STRUCTURE_COST_TAB%ROWTYPE; indrec_ Indicator_Rec; objid_ VARCHAR2(20); objversion_ VARCHAR2(2000); CURSOR get_parent_objects_(sup_contract_ VARCHAR2 ,sup_mch_code_ VARCHAR2) IS SELECT contract,mch_code,sup_contract,sup_mch_code, equipment_object_seq, functional_object_seq FROM Equipment_Object WHERE contract = sup_contract_ AND mch_code = sup_mch_code_; BEGIN current_company_ := NULL; company_contract_ := NULL; order_company_:=Site_api.Get_Company(order_contract_); $IF Component_Wo_SYS.INSTALLED $THEN IF (cost_source_ = 'WO') THEN IF (source_ref2_ IS NOT NULL) THEN project_no_ := Work_Order_API.Get_Project_No(Jt_Task_API.Get_Wo_No(source_ref2_)); ELSIF (source_ref1_ IS NOT NULL AND source_ref1_ != '*') THEN project_no_ := Work_Order_API.Get_Project_No(source_ref1_); END IF; END IF; $ELSE NULL; $END ----Creating Attr String Client_SYS.Clear_Attr(attr_); Client_Sys.Add_To_Attr('CRE_DATE',cre_date_,attr_); Client_Sys.Add_To_Attr('PERCENT_OF_SOURCE',percent_of_source_,attr_); IF project_no_ IS NOT NULL THEN Client_Sys.Add_To_Attr('PROJECT_ID',project_no_,attr_); END IF; Client_Sys.Add_To_Attr('EQUIPMENT_OBJ_COST_TYPE_DB',cost_type_db_,attr_); -- Client_Sys.Add_To_Attr('CURRENCY_CODE',currency_code_,attr_); Client_Sys.Add_To_Attr('COST_SOURCE',cost_source_,attr_); Client_Sys.Add_To_Attr('ROW_CHECKED',row_checked_,attr_); --Adding Customer Order Information when cost coming from Direct sales... Client_Sys.Add_To_Attr('SOURCE_REF1', source_ref1_, attr_); Client_Sys.Add_To_Attr('SOURCE_REF2', source_ref2_, attr_); Client_Sys.Add_To_Attr('SOURCE_REF3', source_ref3_, attr_); Client_Sys.Add_To_Attr('SOURCE_REF4', source_ref4_, attr_); Client_Sys.Add_To_Attr('ORDER_CONTRACT',order_contract_,attr_); save_attr_ := attr_; -- Look for all the parent objects in the tabel and add a cost line for each of them. -- Cost will be added in object's site currency. current_mch_contract_ := mch_contract_; current_mch_code_ := mch_code_; LOOP OPEN get_parent_objects_(current_mch_contract_,current_mch_code_); FETCH get_parent_objects_ INTO current_mch_contract_,current_mch_code_,current_sup_contract_,current_sup_mch_code_, current_equip_obj_sq_, current_func_obj_sq_; EXIT WHEN get_parent_objects_%NOTFOUND; ------ -- The coverted_amount_ only has to be calculated if company changes for object, -- this is if object site is on a different company than the previous site IF ( company_contract_ IS NULL OR company_contract_ != current_mch_contract_ ) THEN company_contract_ := current_mch_contract_; company_:=Site_API.Get_Company(company_contract_); IF current_company_ IS NULL OR current_company_ != company_ THEN current_company_ := company_; currency_code_ := Company_Finance_API.Get_Currency_Code(company_); -- Get the cost amount in Object's site currency coverted_amount_ := Service_Pricing_API.Convert_To_Currency(order_company_,nvl(amount_, 0),currency_code_); END IF; END IF; ------ IF (mch_code_= current_mch_code_)THEN Client_SYS.Clear_Attr(attr_); -- For first record we use check_insert___ to get checks etc... Client_Sys.Add_To_Attr('CONTRACT',current_mch_contract_,attr_); Client_Sys.Add_To_Attr('MCH_CODE',current_mch_code_,attr_); Client_Sys.Add_To_Attr('EQUIPMENT_OBJECT_SEQ',current_equip_obj_sq_,attr_); Client_Sys.Add_To_Attr('SUP_MCH_CODE',current_sup_mch_code_,attr_); Client_Sys.Add_To_Attr('SUP_CONTRACT',current_sup_contract_,attr_); Client_Sys.Add_To_Attr('SUP_EQU_OBJECT_SEQ',current_func_obj_sq_,attr_); Client_Sys.Add_To_Attr('CURRENCY_CODE',currency_code_,attr_); IF cost_revenue_ = 'COST' THEN Client_Sys.Add_To_Attr('COST',coverted_amount_,attr_); ELSE Client_Sys.Add_To_Attr('REVENUE',coverted_amount_,attr_); END IF; attr_ := attr_ || save_attr_; Unpack___(newrec_, indrec_, attr_); Check_Insert___(newrec_, indrec_, attr_); Insert___(objid_, objversion_, newrec_, attr_); ELSE Client_SYS.Clear_Attr(attr_); -- ...but for the rest we dont need the checks as we know that the objects etc exists and is correct newrec_.seq_no := NULL; -- to be set by Insert___ newrec_.cost := NULL; newrec_.cost_from_structure := NULL; newrec_.revenue := NULL; newrec_.revenue_from_structure := NULL; newrec_.sup_equ_object_seq := Equipment_Object_API.Get_Equipment_Object_Seq(current_sup_contract_, current_sup_mch_code_); newrec_.equipment_object_seq := Equipment_Object_API.Get_Equipment_Object_Seq(current_mch_contract_, current_mch_code_); newrec_.currency_code := currency_code_; IF cost_revenue_ = 'COST' THEN newrec_.cost_from_structure := coverted_amount_; ELSE newrec_.revenue_from_structure := coverted_amount_; END IF; attr_ := attr_ || save_attr_; Insert___(objid_, objversion_, newrec_, attr_); END IF; current_mch_contract_ := current_sup_contract_; current_mch_code_ := current_sup_mch_code_; CLOSE get_parent_objects_; END LOOP; CLOSE get_parent_objects_; END Insert_Structure___;