30
Enterprise Business Applications Version: Issue 2 ENTERPRISE BUSINESS APPLICATIONS OECOGS : OM : GENERATE COST OF GOODS SOLD ACCOUNT Author: Name Position Date and Signature xxxxxxx Consultant Control Number: Current Version: Issue 3 Supersedes: Issue 2 Effective Date: 08-Apr-2011 Approvals: Name Position Date and Signature 26-Jul-20121 File Size 338 KB Page 1 of 30

MD070 OECOGS Generate Cost of Goods Sold Account

Embed Size (px)

Citation preview

Page 1: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

ENTERPRISE BUSINESS APPLICATIONS

OECOGS : OM : GENERATE COST OF GOODS SOLD ACCOUNT

Author:

Name Position Date and Signature

xxxxxxx Consultant

Control Number:

Current Version: Issue 3

Supersedes: Issue 2

Effective Date: 08-Apr-2011

Approvals:

Name Position Date and Signature

26-Jul-20121 File Size 338 KB Page 1 of 24

Page 2: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Document Control

Change Record

Date Author Version Change Reference

Reviewers

Name Position

NA

Distribution

Approved controlled copies of this document should be distributed to the following:

Name Location

NOTE to Holders:

Controlled copy can only be obtained as hard copy from the Document Coordinator.

Only controlled copies will be used for execution of work

26-Jul-20121 File Size 338 KB Page 2 of 24

Page 3: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Notification List

List of people to be notified of changes applied to this version of the document

Notification List Location

NA

Training Required

List of people to be trained on changes applied to this version of the document

Training required: Location

NA

Reference Documents

26-Jul-20121 File Size 338 KB Page 3 of 24

Page 4: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Contents

Document Control..........................................................................................2

Installation...............................................................................................5

Installation Instructions for xx_q2c038 OECOGS_OM_Generate Cost of Goods Sold Account..................................................................................................6

Background..............................................................................................6Installation Steps.....................................................................................6Verification Steps.....................................................................................6

Appendix........................................................................................................7

Appendix 1.....................................................................................................8

26-Jul-20121 File Size 338 KB Page 4 of 24

Page 5: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Installation

All modules are installed as if part of a separate product. A UNIX directory structure is created under $APPL_TOP as shown in the following example:

$APPL_TOP | <xx> | 1.0.0

__________________________________|_________________________________________| | | | | | | | |install data bin lib forms sql reports log out| | |___ |___sql <module> | | | | |___ US FR US FR | | inbound outbound

The directories contain the components of the enhancement as shown below (directories not listed are empty). All future customizations will also be stored in these directories.

install/sql/

26-Jul-20121 File Size 338 KB Page 5 of 24

Page 6: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Installation Instructions for xx_q2c038 OECOGS_OM_Generate Cost of Goods Sold Account

Background

Grants

Grants are assumed to be correctly defined already in the Apps environment

Installation Steps

1. From the promotion folder (Oracle 11i 11.5.10\Q2C\Workflow Q2C038 - OECOGS_OM_Generate Cost of Goods Sold Account) pickup the q2c038.zip file. FTP this file over to the server and enter the following company from the $XX_TOP/install directory.

2. Unzip -a –o q2c038.zip

3. This will create the subdirectory q2c038, and place the extracted files into this new folder.

4. Change the permission to 775 for the xx_q2c038_inst.sh script using chmod 775 xx_q2c038_inst.sh

5. From within the new folder, execute the xx_q2c038_inst.sh script to begin the installation procedure. This shell script will execute each of the following scripts in order:

6. xx_q2c038_cp.sh

7. xx_q2c038_db.sh

8. xx_q2c038_fl.sh

9. After Installtion is successful , Follow this step

10. Login in apps with System Administrator responsibility

Navigate to concurrent Program definition and query for concurrent program.

Verification Steps

Open each log file and verify that no errors have occurred during the installation steps.

26-Jul-20121 File Size 338 KB Page 6 of 24

Page 7: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Appendix

Migration from 11.5.9 to 11.5.10

1. New Changes / Hardcode Analysis:

Suggested New Object Name by Functional Lead

Workflow Q2C038 - OECOGS_OM_Generate Cost of Goods Sold Account

Hard Code value Analysis by Developer

Package : xx_Q2C038_COGS1) wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'LEGACY_ITEM_GENERATED_CCID'); wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'LEGACY_ORDER_COMPANY_SEGMENT'); wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'LEGACY_ITEM_COMPANY_SEGMENT'); Line 105 to 107wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'LEGACY_ORDER_GENERATED_CCID') (line no 158)wf_engine.setItemAttrNumber(itemtype,itemkey,'LEGACY_S10_BULOB_SEGMENT_DRVD',l_s10_bulob_segment) line 718 oe_debug_pub.add('KH_LEGACY_ORDER_COMPANY_SEGMENT:'|| l_order_company_segment,2); line 748 oe_debug_pub.add('KH_LEGACY_ITEM_COMPANY_SEGMENT :'|| l_item_company_segment,2); line 749

2) name LIKE 'AT%MD%OU' (Line 17)

3) select organization_id from hr_organization_unitswhere name = 'LEGACY OU CA SA Skype ABI JV' (Line 415)

4) lookup_type = 'LEGACY INTERCOMPANY COGS' (Line No 486)

Suggested Hard Code Values by Functional Lead

Package : xx_Q2C038_COGS1)New naming: Internal package naming (PL/SQL variable), developer can change it as appropriate following naming convention

2) name LIKE 'AT%MD%OU' (Line 17)New Name: name like ‘MD%OU’

3) select organization_id from hr_organization_unitswhere name = 'LEGACY OU CA SA Skype ABI JV' (Line 415)[Ana] This operating unit does not exist anymore, so this piece of the code can be removed4) lookup_type = 'LEGACY INTERCOMPANY COGS' (Line No 486)New name: COMP INTERCOMPANY COGS

Old component names with no naming conventions i.e Package, Value Set etc

NA

Revised component names with naming conventions i.e Package, Value Set etc

NA

26-Jul-20121 File Size 338 KB Page 7 of 24

Page 8: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

Appendix 1

The following changes have been made OM: Generate Cost of Goods Sold Account Workflow and the custom package (Body only) XX_Q2C038_COGS to implement the following new functional requirements:

1/ To derive COGS Site Segment (Segment6) from the Customer Bill-To Site default Receivables account (Site Segment) – SKYPE only

2/ To derive COGS Account Segment (Segment4) from the Order Type default COGS Account (Account Segment) – SKYPE only

3/ If Order created in MD but shipped from SKYPE get the COGS account from the Item (Item Master COGS)

New Attribute:

Account Generator ConfigurationItem Type: OM : Generate Cost of Goods Sale AccountName / Display Name Internal Name Description Type SizeCOMP Customer Site Segment

COMP_SITE_SEGMENT COMP Customer Site Segment

Text

Generate Default Account (DEFAULT_ACCOUNT_GENERATION) Process:

26-Jul-20121 File Size 338 KB Page 8 of 24

Page 9: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

XX_Q2C038_COGS Package Body:

CREATE OR REPLACE PACKAGE BODY APPS.xx_Q2C038_COGS AS

/**------------------------------------------------------------------------------- Check to see if the sales order is for DevComp.-------------------------------------------------------------------------------*/

procedure is_DevComp_Order_Line ( p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is cursor c_is_DevComp (c_org_id number) is select 1 from hr_operating_units hou where name LIKE 'MD%OU' AND organization_id=c_org_id;

r_is_DevComp c_is_DevComp%ROWTYPE;

l_result varchar2(1) :='N'; l_opunit_org_id NUMBER; l_order_hdr_id NUMBER; l_num_internal_order_flag NUMBER := 0;

26-Jul-20121 File Size 338 KB Page 9 of 24

Page 10: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

BEGIN fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_type=' || p_itemtype); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_key=' || p_itemkey); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : actid=' || p_actid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : funmode=' || p_funmode);

l_opunit_org_id := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'ORG_ID'); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.is_DevComp_order_Line <start> :' || 'org_id=' || l_opunit_org_id);

OPEN c_is_DevComp(l_opunit_org_id); FETCH c_is_DevComp INTO r_is_DevComp; IF c_is_DevComp%found THEN l_result := 'Y'; --l_result := 'N'; END IF; CLOSE c_is_DevComp;

--Modified 1-May-09, Rekha l_order_hdr_id := wf_engine.GetitemAttrNumber(p_itemtype,p_itemkey,'HEADER_ID');

BEGIN

SELECT 1 INTO l_num_internal_order_flag FROM oe_order_headers_all oeh WHERE header_id = l_order_hdr_id AND org_id = l_opunit_org_id AND EXISTS (select 1 from oe_order_sources oes where name = 'Internal' and oes.order_source_id = oeh.order_source_id); EXCEPTION WHEN OTHERS THEN l_num_internal_order_flag := 0; END;

IF l_num_internal_order_flag = 1 THEN l_result := 'N'; END IF;

--------End Modification

p_result := 'COMPLETE:' || l_result; fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.is_DevComp_order_Line : p_result :' || p_result);

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.is_DevComp_Order_Line <error> :' || substr(SQLERRM,1,200)); oe_debug_pub.add('Error in xx_q2c038_cogs.is_DevComp_order_line [genErr] : ' || substr(SQLERRM,1,200), 1); RAISE;end;

/**------------------------------------------------------------------------------- Log the values of item attributes----------------------------------------------------------------------------------*/

26-Jul-20121 File Size 338 KB Page 10 of 24

Page 11: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

procedure DevComp_Log1 ( p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is l_item_ccid VARCHAR2(240); l_COMP_item_ccid VARCHAR2(240); --l_COMP_order_type_account_derived VARCHAR2(240); l_order_company_segment VARCHAR(4); l_item_company_segment VARCHAR(4);

BEGIN

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_type=' || p_itemtype); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_key=' || p_itemkey); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : actid=' || p_actid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : funmode=' || p_funmode);

l_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'GENERATED_CCID'); l_COMP_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_GENERATED_CCID'); l_order_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ORDER_COMPANY_SEGMENT'); l_item_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_COMPANY_SEGMENT');

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log1 : GENERATED_CCID=' || l_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log1 : COMP_ITEM_GENERATED_CCID=' || l_COMP_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log1 : COMP_ORDER_COMPANY_SEGMENT=' || l_order_company_segment); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log1 : COMP_ITEM_COMPANY_SEGMENT=' || l_ITEM_company_segment);

P_result := 'COMPLETE';

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log1 <error> :' || substr(SQLERRM,1,200)); P_result := 'ERROR';

end;

procedure DevComp_Log2 ( p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is l_item_ccid VARCHAR2(240); l_COMP_item_ccid VARCHAR2(240); l_COMP_ORDER_ccid VARCHAR2(240);

--l_COMP_order_type_account_derived VARCHAR2(240);

26-Jul-20121 File Size 338 KB Page 11 of 24

Page 12: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

l_order_company_segment VARCHAR(4); l_item_company_segment VARCHAR(4);

BEGIN

l_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'GENERATED_CCID'); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_type=' || p_itemtype); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_key=' || p_itemkey); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : actid=' || p_actid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : funmode=' || p_funmode);

/*wf_engine.setItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_GENERATED_CCID',TO_NUMBER(l_item_ccid));--wf_engine.setItemAttrNumber(P_itemtype,P_itemkey,'COMP_ORDER_GENERATED_CCID',TO_NUMBER(l_ITEM_CCID));wf_engine.setItemAttrNumber(P_itemtype,P_itemkey,'COMP_ORDER_GENERATED_CCID',TO_NUMBER('126270'));wf_engine.setItemAttrNumber(P_itemtype,P_itemkey,'COMP_ORDER_COMPANY_SEGMENT',TO_NUMBER('0'));wf_engine.setItemAttrNumber(P_itemtype,P_itemkey,'COMP_ITEM_COMPANY_SEGMENT',TO_NUMBER('6011'));wf_engine.setItemAttrNumber(P_itemtype,P_itemkey,'COMP_S10_BULOB_SEGMENT_DRVD',9999);*/

l_COMP_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_GENERATED_CCID'); l_COMP_ORDER_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ORDER_GENERATED_CCID');

l_order_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ORDER_COMPANY_SEGMENT'); l_item_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_COMPANY_SEGMENT');

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log2 : GENERATED_CCID=' || l_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log2 : COMP_ITEM_GENERATED_CCID=' || l_COMP_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log2 : COMP_ORDER_GENERATED_CCID=' || l_COMP_ORDER_ccid);

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log2 : COMP_ORDER_COMPANY_SEGMENT=' || l_order_company_segment); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log2 : COMP_ITEM_COMPANY_SEGMENT=' || l_ITEM_company_segment);

P_result := 'COMPLETE:SUCCESS';

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log2 <error> :' || substr(SQLERRM,1,200)); P_result := 'COMPLETE:FAILURE';

end;

procedure DevComp_Log3 (

26-Jul-20121 File Size 338 KB Page 12 of 24

Page 13: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is l_item_ccid VARCHAR2(240); l_COMP_item_ccid VARCHAR2(240); --l_COMP_order_type_account_derived VARCHAR2(240); l_order_company_segment VARCHAR(4); l_item_company_segment VARCHAR(4);

BEGIN

l_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'GENERATED_CCID'); l_COMP_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_GENERATED_CCID'); l_order_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ORDER_COMPANY_SEGMENT'); l_item_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_COMPANY_SEGMENT');

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_type=' || p_itemtype);fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_key=' || p_itemkey);fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : actid=' || p_actid);fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : funmode=' || p_funmode);

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log3 : GENERATED_CCID=' || l_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log3 : COMP_ITEM_GENERATED_CCID=' || l_COMP_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log3 : COMP_ORDER_COMPANY_SEGMENT=' || l_order_company_segment); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log3 : COMP_ITEM_COMPANY_SEGMENT=' || l_ITEM_company_segment);

P_result := 'COMPLETE';

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log3 <error> :' || substr(SQLERRM,1,200)); P_result := 'ERROR';

end;

procedure DevComp_Log4 ( p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is l_item_ccid VARCHAR2(240); l_COMP_item_ccid VARCHAR2(240); --l_COMP_order_type_account_derived VARCHAR2(240); l_order_company_segment VARCHAR(4); l_item_company_segment VARCHAR(4);

26-Jul-20121 File Size 338 KB Page 13 of 24

Page 14: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

BEGIN

l_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'GENERATED_CCID'); l_COMP_item_ccid := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_GENERATED_CCID'); l_order_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ORDER_COMPANY_SEGMENT'); l_item_company_segment := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'COMP_ITEM_COMPANY_SEGMENT'); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_type=' || p_itemtype); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : item_key=' || p_itemkey); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : actid=' || p_actid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log : funmode=' || p_funmode);

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log4 : GENERATED_CCID=' || l_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log4 : COMP_ITEM_GENERATED_CCID=' || l_COMP_item_ccid); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log4 : COMP_ORDER_COMPANY_SEGMENT=' || l_order_company_segment); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log4 : COMP_ITEM_COMPANY_SEGMENT=' || l_ITEM_company_segment);

P_result := 'COMPLETE';

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.DevComp_log4 <error> :' || substr(SQLERRM,1,200)); P_result := 'ERROR';

end;

/**--------------------------------------------------------------------------------- Check to see if item on line has has a top model item.---------------------------------------------------------------------------------*/procedure has_DevComp_topModel_Line ( p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is --find only non-null values for top model line id cursor c_topModel (c_line_id number) is SELECT TOP_MODEL_LINE_ID FROM oe_order_lines_all WHERE line_id = c_line_id AND top_model_line_id IS NOT NULL; r_topModel c_topModel%ROWTYPE;

l_result VARCHAR2(1) :='N'; l_line_id NUMBER; l_top_model_line_id NUMBER; e_orderLine_not_found EXCEPTION;BEGIN

l_line_id := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'LINE_ID');

26-Jul-20121 File Size 338 KB Page 14 of 24

Page 15: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_topModel_Line <start> :' || 'line_id=' || l_line_id);

OPEN c_topModel(l_line_id); FETCH c_topModel INTO r_topModel; IF c_topModel%found THEN l_top_model_line_id := r_topModel.top_model_line_id; --ELSE --no top model line. END IF; CLOSE c_topModel;

--if top model line is not null -- check to see if it references itself -- i.e only top model line exists if l_line_id != top_model_line_id IF l_top_model_line_id IS NOT NULL THEN IF l_top_model_line_id != l_line_id THEN l_result :='Y'; END IF; END IF;

fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_topModel_Line : line_id=' || l_line_id); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_topModel_Line : top_model_line_id=' || l_top_model_line_id);

p_result := 'COMPLETE:' || l_result; fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_topModel_Line : p_result :' || p_result);

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_topModel_Line <error> :' || substr(SQLERRM,1,200)); oe_debug_pub.add('Error in xx_q2c038_cogs.has_DevComp_topModel_line [others] : ' || substr(SQLERRM,1,200), 1); raise;end;

/**------------------------------------------------------------------------------- Check to see if the header order type has a cost of goods sold account. New requirement: April 2011 If Order shipped from MD get COGS account from Order Type If Order shipped from SX get COGS account from the Item ------------------------------------------------------------------------------*/procedure has_DevComp_OrderType_COGS ( p_itemtype in varchar2 ,p_itemkey in varchar2 ,p_actid in number ,p_funmode in varchar2 ,p_result out nocopy varchar2 ) is --get only non-null values for cogs cursor c1 (c_order_type_id number) is SELECT COST_OF_GOODS_SOLD_ACCOUNT FROM OE_TRANSACTION_TYPES_ALL WHERE TRANSACTION_TYPE_ID = c_order_type_id AND cost_of_goods_sold_account IS NOT NULL; ---M. Smith, April 7 2011 NEW CURSOR

26-Jul-20121 File Size 338 KB Page 15 of 24

Page 16: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

cursor c2 (c_organization_id number) is SELECT organization_id from mtl_parameters where organization_code in ('S01','S30','EKS') and organization_id = c_organization_id; --M. Smith, April 7 2011 END NEW CURSOR

r1 c1%ROWTYPE; r2 c2%ROWTYPE; --April 7, M. Smith

l_result varchar2(1) :='N'; l_orderType_ID NUMBER; l_orderType_cogs NUMBER; l_organization_id NUMBER; --April 7, M. Smith

BEGIN

l_orderType_id := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'ORDER_TYPE_ID'); fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_orderType_cogs <start> :' || 'Order_type_id=' || l_orderType_id); l_organization_id := wf_engine.GetItemAttrNumber(p_itemtype,p_itemkey,'ORGANIZATION_ID'); --April 7, M. Smith

OPEN c1(l_orderType_id); FETCH c1 INTO r1; IF c1%found THEN l_orderType_cogs := r1.cost_of_goods_sold_account; l_result :='Y'; END IF; CLOSE c1; ---M. Smith, April 7 2011: NEW CONDITION: OPEN c2(l_organization_id); FETCH c2 INTO r2; IF c2%found THEN l_result :='N'; END IF; CLOSE c2; -- M. Smith, April 7 2011 END p_result := 'COMPLETE:' || l_result; fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_orderType_cogs : p_result :' || p_result);

EXCEPTION when others then --should never happen fnd_file.put_line(fnd_file.log, 'xx_q2c038_cogs.has_DevComp_OrderType_cogs <error> :' || substr(SQLERRM,1,200)); oe_debug_pub.add('Error in xx_q2c038_cogs.has_DevComp_orderType_COGS [others] : ' || substr(SQLERRM,1,200), 1); RAISE;end;

26-Jul-20121 File Size 338 KB Page 16 of 24

Page 17: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

/*===========================================================================+ | Name: Get_COMP_invitm_Org_derived | Purpose: Derives a cost of sales account for an inventory Item ID | | and Selling Operating Unit New requirements: March 2011 Assign Site segment from the Customer's BILL TO Receivables account. +===========================================================================*/

PROCEDURE Get_COMP_Invitm_Org_Derived( itemtype IN VARCHAR2, itemkey IN VARCHAR2, actid IN NUMBER, funcmode IN VARCHAR2, result OUT VARCHAR2)IS l_item_account_derived VARCHAR2(240) DEFAULT NULL; l_order_type_account_derived VARCHAR2(240) DEFAULT NULL; l_inv_item_id NUMBER; l_order_type_id NUMBER; l_ship_from_org_id NUMBER; fb_error_msg VARCHAR2(240) DEFAULT NULL; l_error_msg VARCHAR2(240) DEFAULT NULL; l_line_id NUMBER; l_header_id NUMBER; --M.Smith March 17 - NEW!!!! l_order_company_segment VARCHAR(4); l_item_company_segment VARCHAR(4); l_opunit_org_id NUMBER; l_sales_rep_id NUMBER; l_sales_rep_id2 NUMBER; l_s10_bulob_segment NUMBER := 9999; l_segment6 VARCHAR2(3) := '000'; --M.Smith March 17 - NEW!!!!

-- m_jv_ou1 VARCHAR2(100) := 'COMP OU CA SA Skype ABI JV'; m_jv_ou1_id number; m_bulob VARCHAR2(100); m_ccid number;

l_selling_to_org_id NUMBER; l_bulob_segment_indicator varchar2(50);/* commented as per migratation sheet comment Zensar 22-jul-2010cursor c1 isselectorganization_idfrom hr_organization_unitswhere name = m_jv_ou1;*/---- (HHO) 20-Dec-2005 version 1.1---- if Company of the COGS account from sales order type != Company of COGS account from Ship From Org + item-- and Ship From Org = S01 or S03-- and Order type Default Warehouse = S01

26-Jul-20121 File Size 338 KB Page 17 of 24

Page 18: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

-- then COGS extract from Order Type and substitute BULOB from COGS account from Ship From Org + item--cursor c2 (c_line_id number) isselectgc2.segment2 item_bulobfromoe_order_headers_all ooh, oe_transaction_types_all ott, gl_code_combinations gc1, oe_order_lines_all ool, mtl_system_items_b msi, gl_code_combinations gc2, mtl_parameters mp1, mtl_parameters mp2whereool.line_id = c_line_idand msi.organization_id = ool.ship_from_org_idand msi.inventory_item_id = ool.inventory_item_idand msi.cost_of_sales_account = gc2.code_combination_idand ooh.header_id = ool.header_idand ott.transaction_type_id = ooh.order_type_idand ott.cost_of_goods_sold_account = gc1.code_combination_idand mp1.organization_id = ool.ship_from_org_idand gc1.segment1 != gc2.segment1and ott.warehouse_id = mp2.organization_idand mp1.organization_code in ('S01','S30')and mp2.organization_code = 'S01';

cursor c3 (c_ccid number, c_bulob varchar2) isselectgc2.code_combination_idfromgl_code_combinations gc1, gl_code_combinations gc2wheregc1.code_combination_id = c_ccidand gc2.segment1 = gc1.segment1and gc2.segment2 = c_buloband gc2.segment3 = gc1.segment3and gc2.segment4 = gc1.segment4and gc2.segment5 = gc1.segment5and gc2.segment6 = gc1.segment6and gc2.segment7 = gc1.segment7;

Cursor C00 (c_line_id number) isselectott.warehouse_id selling_to_org_id, ool.ship_from_org_id ship_from_org_idfromoe_order_headers_all ooh, oe_transaction_types_all ott, oe_order_lines_all oolwhereool.line_id = c_line_idand ooh.header_id = ool.header_idand ott.transaction_type_id = ooh.order_type_id;

---- Lookup Exception Setup--Cursor C01 (c_selling_to_org_id number, c_ship_from_org_id number) isselectattribute5 bulob_segment_indicator

26-Jul-20121 File Size 338 KB Page 18 of 24

Page 19: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

from FND_LOOKUP_VALUES_VLwherelookup_type = 'COMP INTERCOMPANY COGS'and enabled_flag = 'Y'and start_date_active <= sysdateand nvl(end_date_active,sysdate) >= sysdateand attribute1 = c_selling_to_org_idand attribute2 = c_ship_from_org_idand attribute5 is not null;

BEGIN oe_debug_pub.add('Entering OE_FLEX_COGS_PUB.Get_Invitm_Org_Derived',1); IF (FUNCMODE = 'RUN') THEN

l_inv_item_id := wf_engine.GetItemAttrNumber(itemtype,itemkey,'INVENTORY_ITEM_ID'); l_ship_from_org_id:= wf_engine.GetItemAttrNumber(itemtype,itemkey,'ORGANIZATION_ID'); l_line_id := wf_engine.GetItemAttrNumber(itemtype,itemkey,'LINE_ID'); l_order_type_id := wf_engine.GetItemAttrNumber(itemtype,itemkey,'ORDER_TYPE_ID'); l_opunit_org_id := wf_engine.GetItemAttrNumber(itemtype,itemkey,'ORG_ID'); l_sales_rep_id := wf_engine.GetItemAttrNumber(itemtype,itemkey,'SALESREP_ID'); l_header_id := wf_engine.GetItemAttrNumber(itemtype,itemkey,'HEADER_ID'); --M.Smith March 17 - NEW!!!! --NEW SITE SEGMENT M.SMITH March 17, 2011 --M.Smith March 17 - NEW!!!! begin SELECT gl.segment6 into l_segment6 FROM oe_order_headers_all ord, oe_order_lines_all lin, hz_cust_site_uses_all su, hr_operating_units ou, gl_code_combinations gl WHERE ord.org_id = su.org_id AND su.org_id = ou.organization_id and ord.header_id = lin.header_id and ord.org_id = lin.org_id AND lin.invoice_to_org_id = site_use_id AND ord.header_id = l_header_id AND lin.line_id = l_line_id -- and invoice_to_org_id = 3589 --this is site_use_id from hz_cust_site_uses_all AND gl_id_rec = gl.code_combination_id AND ou.name IN ('SX CA OU', 'SX SG OU'); EXCEPTION WHEN NO_DATA_FOUND THEN null; end; wf_engine.SetItemAttrText ( itemtype => itemType, itemkey => itemkey, aname => 'COMP_SITE_SEGMENT' , avalue => l_segment6); --END NEW SITE SEGMENT M.SMITH March 17, 2011

-- hho: overridden the salesrep if it is "No Sales Credit"

26-Jul-20121 File Size 338 KB Page 19 of 24

Page 20: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

l_sales_rep_id2 := l_sales_rep_id; begin select nvl(ool.SALESREP_ID,ooh.SALESREP_ID) into l_sales_rep_id2 from oe_order_headers_all ooh , oe_order_lines_all ool where ool.line_id = l_line_id and ooh.header_id = ool.header_id; EXCEPTION WHEN NO_DATA_FOUND THEN null; end;

if l_sales_rep_id2 != l_sales_rep_id then l_sales_rep_id := l_sales_rep_id2; wf_engine.SetItemAttrNumber ( itemtype => itemType, itemkey => itemkey, aname => 'SALESREP_ID' , avalue => l_sales_rep_id); end if;

oe_debug_pub.add('Input Paramerers : ',2); oe_debug_pub.add('Inventory Item ID :'|| to_char(l_inv_item_id),2); oe_debug_pub.add('Organization ID :'|| to_char(l_ship_from_org_id),2); oe_debug_pub.add('Order Line ID :'|| to_char(l_line_id),2); oe_debug_pub.add('Order Type ID :'|| to_char(l_order_type_id),2); oe_debug_pub.add('Sales REP ID :'|| to_char(l_sales_rep_id),2); oe_debug_pub.add('OPERATING UNIT ID :'|| to_char(l_opunit_org_id),2);

L_ITEM_ACCOUNT_DERIVED := NULL; IF (L_INV_ITEM_ID IS NOT NULL) THEN BEGIN -- -- 1. Get COGS from Ship-from-org and item -- SELECT NVL(COST_OF_SALES_ACCOUNT, 0) INTO l_item_account_derived FROM MTL_SYSTEM_ITEMS WHERE INVENTORY_ITEM_ID = l_inv_item_id AND ORGANIZATION_ID = l_ship_from_org_id; EXCEPTION WHEN NO_DATA_FOUND THEN FND_MESSAGE.SET_NAME('ONT','OE_COGS_CCID_GEN_FAILED'); FND_MESSAGE.SET_TOKEN('PARAM1','Inventory Item id'); FND_MESSAGE.SET_TOKEN('PARAM2','/Warehouse err1'); FND_MESSAGE.SET_TOKEN('VALUE1',l_inv_item_id); FND_MESSAGE.SET_TOKEN('VALUE2',l_ship_from_org_id); fb_error_msg := FND_MESSAGE.GET_ENCODED; FND_MESSAGE.SET_ENCODED(fb_error_msg); l_error_msg := FND_MESSAGE.GET; wf_engine.setItemAttrText(itemtype,itemkey,'ERROR_MESSAGE',l_error_msg); result := 'COMPLETE:FAILURE'; RETURN; END;

26-Jul-20121 File Size 338 KB Page 20 of 24

Page 21: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

IF l_item_account_derived = 0 THEN

FND_MESSAGE.SET_NAME('ONT','OE_COGS_CCID_GEN_FAILED'); FND_MESSAGE.SET_TOKEN('PARAM1','Inventory Item id'); FND_MESSAGE.SET_TOKEN('PARAM2','/Warehouse err2'); FND_MESSAGE.SET_TOKEN('VALUE1',l_inv_item_id); FND_MESSAGE.SET_TOKEN('VALUE2',l_ship_from_org_id); FND_MESSAGE.SET_TOKEN('VALUE3',l_line_id); FND_MESSAGE.SET_TOKEN('VALUE4',l_order_type_id);

fb_error_msg := FND_MESSAGE.GET_ENCODED; FND_MESSAGE.SET_ENCODED(fb_error_msg); l_error_msg := FND_MESSAGE.GET;

wf_engine.setItemAttrText(itemtype,itemkey,'ERROR_MESSAGE',l_error_msg); result := 'COMPLETE:FAILURE'; RETURN;

END IF;

-- -- 2. Override the COGS from Order Type -- L_ORDER_TYPE_ACCOUNT_DERIVED := NULL; BEGIN SELECT NVL(COST_OF_GOODS_SOLD_ACCOUNT, 0) INTO l_order_type_account_derived FROM OE_TRANSACTION_TYPES_ALL WHERE TRANSACTION_TYPE_ID = l_order_type_id; EXCEPTION WHEN NO_DATA_FOUND THEN FND_MESSAGE.SET_NAME('ONT','OE_COGS_CCID_GEN_FAILED'); FND_MESSAGE.SET_TOKEN('PARAM1','Inventory Item id'); FND_MESSAGE.SET_TOKEN('PARAM2','/Warehouse err3'); FND_MESSAGE.SET_TOKEN('VALUE1',l_inv_item_id); FND_MESSAGE.SET_TOKEN('VALUE2',l_ship_from_org_id); FND_MESSAGE.SET_TOKEN('VALUE3',l_line_id); FND_MESSAGE.SET_TOKEN('VALUE4',l_order_type_id); fb_error_msg := FND_MESSAGE.GET_ENCODED; FND_MESSAGE.SET_ENCODED(fb_error_msg); l_error_msg := FND_MESSAGE.GET; wf_engine.setItemAttrText(itemtype,itemkey,'ERROR_MESSAGE',l_error_msg); result := 'COMPLETE:FAILURE'; RETURN; END;

-- get the company segment for the Order Type CCID BEGIN SELECT segment5 INTO l_order_company_segment FROM gl.gl_code_combinations WHERE code_combination_id = l_order_type_account_derived; EXCEPTION WHEN NO_DATA_FOUND THEN FND_MESSAGE.SET_NAME('ONT','OE_COGS_CCID_GEN_FAILED'); FND_MESSAGE.SET_TOKEN('PARAM1','Inventory Item id'); FND_MESSAGE.SET_TOKEN('PARAM2','/Warehouse err4'); FND_MESSAGE.SET_TOKEN('VALUE1',l_inv_item_id); FND_MESSAGE.SET_TOKEN('VALUE2',l_ship_from_org_id);

26-Jul-20121 File Size 338 KB Page 21 of 24

Page 22: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

FND_MESSAGE.SET_TOKEN('VALUE3',l_line_id); FND_MESSAGE.SET_TOKEN('VALUE4',l_order_type_id); fb_error_msg := FND_MESSAGE.GET_ENCODED; FND_MESSAGE.SET_ENCODED(fb_error_msg); l_error_msg := FND_MESSAGE.GET; wf_engine.setItemAttrText(itemtype,itemkey,'ERROR_MESSAGE',l_error_msg); result := 'COMPLETE:FAILURE'; RETURN; END;

-- -- 3. Get the company segment for the Ship-from-org Item CCID -- BEGIN SELECT segment1 INTO l_item_company_segment FROM gl.gl_code_combinations WHERE code_combination_id = l_item_account_derived; EXCEPTION WHEN NO_DATA_FOUND THEN FND_MESSAGE.SET_NAME('ONT','OE_COGS_CCID_GEN_FAILED'); FND_MESSAGE.SET_TOKEN('PARAM1','Inventory Item id'); FND_MESSAGE.SET_TOKEN('PARAM2','/Warehouse err5'); FND_MESSAGE.SET_TOKEN('VALUE1',l_inv_item_id); FND_MESSAGE.SET_TOKEN('VALUE2',l_ship_from_org_id); FND_MESSAGE.SET_TOKEN('VALUE3',l_line_id); FND_MESSAGE.SET_TOKEN('VALUE4',l_order_type_id); fb_error_msg := FND_MESSAGE.GET_ENCODED; FND_MESSAGE.SET_ENCODED(fb_error_msg); l_error_msg := FND_MESSAGE.GET; wf_engine.setItemAttrText(itemtype,itemkey,'ERROR_MESSAGE',l_error_msg); result := 'COMPLETE:FAILURE'; RETURN; END;

-- -- org_id of 'COMP OU CA SA Skype ABI JV' -- -- 4. Pick up BULOB from salesrep revenue account for SX JV -- /* open c1; fetch c1 into m_jv_ou1_id; close c1; */ /********************************************************************************************* --hho: BULOB is driven by the exemption quickcode setup under "COMP INTERCOMPANY COGS"

--if l_opunit_org_id = 395 -- and l_sales_rep_id > 0 if l_opunit_org_id = m_jv_ou1_id then begin select to_number(segment2) into l_s10_bulob_segment from gl.gl_code_combinations gcc,jtf_rs_srp_vl sr where sr.GL_ID_REV = gcc.CODE_COMBINATION_ID and sr.SALESREP_ID = l_sales_rep_id -- hho 25-feb-06 and l_sales_rep_id > 0 and sr.ORG_ID = l_opunit_org_id; EXCEPTION

26-Jul-20121 File Size 338 KB Page 22 of 24

Page 23: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

WHEN NO_DATA_FOUND THEN l_s10_bulob_segment := 9999; end;

wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_S10_BULOB_SEGMENT_DRVD',l_s10_bulob_segment);

oe_debug_pub.add('BULOB Stuff :'|| l_s10_bulob_segment,2); end if; ************************************************************************************************/

-- from Orgs from order line open C00(l_line_id); fetch C00 into l_selling_to_org_id, l_ship_from_org_id; close C00;

open C01(l_selling_to_org_id, l_ship_from_org_id); fetch C01 into l_bulob_segment_indicator; if C01%found then if l_bulob_segment_indicator = 'Salesrep revenue Account' then begin select to_number(segment2) into l_s10_bulob_segment from gl.gl_code_combinations gcc,jtf_rs_srp_vl sr where sr.GL_ID_REV = gcc.CODE_COMBINATION_ID and sr.SALESREP_ID = l_sales_rep_id --and l_sales_rep_id > 0 and sr.ORG_ID = l_opunit_org_id; EXCEPTION WHEN NO_DATA_FOUND THEN l_s10_bulob_segment := 9999; end; end if; end if; close C01;

wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_S10_BULOB_SEGMENT_DRVD',l_s10_bulob_segment);

--wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_S10_BULOB_SEGMENT_DRVD',l_s10_bulob_segment);

--oe_debug_pub.add('BULOB Stuff :'|| '1725',2);

--Move the two CCID's back to Workflow

-- -- V1.1 -- open c2(l_line_id); fetch c2 into m_bulob; if c2%found then open c3(l_order_type_account_derived, m_bulob); fetch c3 into m_ccid; if c3%found then l_order_type_account_derived := m_ccid;

26-Jul-20121 File Size 338 KB Page 23 of 24

Page 24: MD070 OECOGS Generate Cost of Goods Sold Account

Enterprise Business Applications Version: Issue 2

end if; close c3; end if; close c2;

wf_engine.setItemAttrNumber(itemtype,itemkey,'GENERATED_CCID',TO_NUMBER(l_item_account_derived));

wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_ITEM_GENERATED_CCID',TO_NUMBER(l_item_account_derived)); wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_ORDER_GENERATED_CCID',TO_NUMBER(l_order_type_account_derived)); wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_ORDER_COMPANY_SEGMENT',TO_NUMBER(l_order_company_segment)); wf_engine.setItemAttrNumber(itemtype,itemkey,'COMP_ITEM_COMPANY_SEGMENT',TO_NUMBER(l_item_company_segment)); -- wf_engine.setItemAttrNumber(itemtype,itemkey,'ORG_ID',l_opunit_org_id);

oe_debug_pub.add('KH_COMP_ORDER_COMPANY_SEGMENT:'|| l_order_company_segment,2); oe_debug_pub.add('KH_COMP_ITEM_COMPANY_SEGMENT :'|| l_item_company_segment,2);

result := 'COMPLETE:SUCCESS'; ELSE

result := 'COMPLETE:FAILURE'; RETURN; END IF; -- IF (L_INV_ITEM_ID IS NOT NULL) THEN

oe_debug_pub.add('Output : ',2); oe_debug_pub.add('Generated CCID :'|| l_order_type_account_derived,2); RETURN; ELSIF (funcmode = 'CANCEL') THEN result := wf_engine.eng_completed; RETURN; ELSE result := ''; RETURN; END IF;EXCEPTION WHEN OTHERS THEN wf_core.context('OE_FLEX_COGS_PUB','Get_Invitm_Org_Derived', itemtype,itemkey,TO_CHAR(actid),funcmode); result := 'COMPLETE:FAILURE'; RAISE;

END Get_COMP_Invitm_Org_Derived;

END xx_Q2C038_COGS;

/

26-Jul-20121 File Size 338 KB Page 24 of 24