DBA Data[Home] [Help]

PACKAGE BODY: APPS.ARP_CMERGE

Source


1 package body ARP_CMERGE as
2 /* $Header: ARPLARMB.pls 120.6 2010/07/28 12:09:41 spdixit ship $ */
3 
4 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
5 
6 /*--------------------------------------------------------------------------+
7  | Procedure Name : insert_full_merge_event				    |
8  | Description    : Create THIRD_PARTY_MERGE entity if it do not exists.    |
9  |                  Create FULL_MERGE events for the customer sites merged. |
10  +--------------------------------------------------------------------------+
11  | History        :							    |
12  | 12-JUL-2010       Sachin Dixit      Created for bug 9338111		    |
13  +--------------------------------------------------------------------------+
14  |									    |
15  | Details	  :							    |
16  | 1) p_third_party_type : values can be 'C' (Customer) or 'S' (Supplier)   |
17  |									    |
18  | 2) p_type_of_third_party_merge : Can be FULL or PARTIAL                  |
19  |									    |
20  | 3) p_execution_mode : values can be  SYNC, ASYNC_NOREQ and ASYNC_REQ     |
21  |    3.1) In 'SYNC' mode code will call API to create accounting	    |
22  |    3.2) In 'ASYNC_REQ' mode code will submit the concurrent program -    |
23  |             Create Third Party Merge Accounting			    |
24  |    3.3) In 'ASYNC_NOREQ' code will keep the events in unprocessed status |
25  |									    |
26  | 4) p_accounting_mode : Values can be 'D' (Draft) or 'F' (Final)	    |
27  |									    |
28  +-------------------------------------------------------------------------*/
29 
30 Procedure insert_full_merge_event (req_id NUMBER, set_num NUMBER, process_mode VARCHAR2) IS
31 
32 x_errbuf			VARCHAR2(1000);
33 x_retcode			VARCHAR2(1000);
34 x_event_ids			xla_third_party_merge_pub.t_event_ids;
35 x_request_id			NUMBER;
36 p_ledger_id			NUMBER;
37 p_third_party_type		VARCHAR2(100) := 'C';
38 p_type_of_third_party_merge	VARCHAR2(100) := 'FULL';
39 p_mapping_flag			VARCHAR2(100) := 'N';
40 p_execution_mode		VARCHAR2(100) := 'ASYNC_REQ';
41 p_accounting_mode		VARCHAR2(100);
42 p_transfer_to_gl_flag		VARCHAR2(100);
43 p_post_in_gl_flag		VARCHAR2(100);
44 
45 l_valid_gl_date			DATE;
46 l_defaulting_rule_used		VARCHAR2(50);
47 l_error_message			VARCHAR2(128);
48 error_defaulting_gl_date        EXCEPTION;
49 
50 Cursor select_merge_cust (req_id NUMBER , set_num NUMBER ) IS
51 SELECT * FROM ra_customer_merges
52 WHERE process_flag = 'N'
53 AND request_id = req_id
54 AND set_number = set_num ;
55 
56 BEGIN
57 
58 IF PG_DEBUG in ('Y', 'C') THEN
59 	arp_message.set_line( 'ARP_CMERGE.INSERT_FULL_MERGE_EVENT()+');
60 END IF;
61 
62 IF process_mode='LOCK' THEN
63 	NULL;
64 ELSE
65 
66 	IF (arp_util.validate_and_default_gl_date(
67               trunc(sysdate),
68               NULL,
69               NULL,
70               NULL,
71               NULL,
72               trunc(sysdate),
73               NULL,
74               NULL,
75               'N',
76               NULL,
77               arp_global.set_of_books_id,
78               222,
79               l_valid_gl_date,
80               l_defaulting_rule_used,
81               l_error_message) = TRUE) THEN
82 	   null;
83 	ELSE
84 	   RAISE error_defaulting_gl_date;
85 	END IF;
86 
87 	IF PG_DEBUG in ('Y', 'C') THEN
88 	   arp_message.set_line( 'GL Date : '|| l_valid_gl_date);
89 	END IF ;
90 
91 	INSERT INTO xla_events_gt
92 	    (application_id
93 	    ,ledger_id
94 	    ,entity_code
95 	    ,source_id_int_1
96 	    ,valuation_method)
97 	VALUES
98 	    (222
99 	    ,arp_global.set_of_books_id
100 	    ,'THIRD_PARTY_MERGE'
101 	    ,NULL
102 	    ,NULL);
103 
104 
105 	BEGIN
106 	    SELECT ACCOUNTING_MODE_CODE, SUBMIT_TRANSFER_TO_GL_FLAG, SUBMIT_GL_POST_FLAG
107 	    INTO   p_accounting_mode, p_transfer_to_gl_flag, p_post_in_gl_flag
108 	    FROM   XLA_SUBLEDGER_OPTIONS_V
109 	    WHERE  APPLICATION_ID =  222
110 	    AND    LEDGER_ID      =  arp_global.set_of_books_id;
111 	EXCEPTION WHEN OTHERS THEN
112             arp_message.set_line( 'Error in getting XLA subledger options');
113 	    arp_message.set_line( 'Parameters:- Application id: 222, Ledger id: ' || arp_global.set_of_books_id);
114 	    arp_message.set_line( 'SQl Error : ' || sqlerrm);
115 	END;
116 
117 	IF PG_DEBUG in ('Y', 'C') THEN
118 	   arp_message.set_line ('p_accounting_mode = '|| p_accounting_mode);
119 	   arp_message.set_line ('p_transfer_to_gl_flag = '|| p_transfer_to_gl_flag);
120 	   arp_message.set_line ('p_post_in_gl_flag = '|| p_post_in_gl_flag);
121 	END IF;
122 
123 	For C1 IN select_merge_cust(req_id , set_num) LOOP
124 
125 	IF PG_DEBUG in ('Y', 'C') THEN
126 	   arp_message.set_line ('Calling xla_third_party_merge_pub.third_party_merge');
127 	   arp_message.set_line ('p_original_third_party_id = '|| C1.duplicate_id);
128 	   arp_message.set_line ('p_original_site_id = '|| C1.duplicate_site_id);
129 	   arp_message.set_line ('p_new_third_party_id = '|| C1.customer_id);
130 	   arp_message.set_line ('p_new_site_id = '|| C1.customer_site_id);
131 	END IF;
132 
133 	   xla_third_party_merge_pub.third_party_merge(
134 		x_errbuf			=> x_errbuf,
135 		x_retcode			=> x_retcode,
136 		x_event_ids			=> x_event_ids,
137 		x_request_id			=> x_request_id,
138 		p_source_application_id		=> 222,
139 		p_application_id		=> 222,
140 		p_ledger_id			=> arp_global.set_of_books_id,
141 		p_third_party_merge_date	=> l_valid_gl_date,
142 		p_third_party_type		=> p_third_party_type,
143 		p_original_third_party_id	=> C1.duplicate_id,
144 		p_original_site_id		=> C1.duplicate_site_id,
145 		p_new_third_party_id		=> C1.customer_id,
146 		p_new_site_id			=> C1.customer_site_id,
147 		p_type_of_third_party_merge	=> p_type_of_third_party_merge,
148 		p_mapping_flag			=> p_mapping_flag,
149 		p_execution_mode		=> p_execution_mode,
150 		p_accounting_mode		=> p_accounting_mode,
151 		p_transfer_to_gl_flag		=> p_transfer_to_gl_flag,
152 		p_post_in_gl_flag		=> p_post_in_gl_flag);
153 
154 		IF PG_DEBUG in ('Y', 'C') THEN
155 		   arp_message.set_line ('x_retcode = '|| x_retcode);
156 		END IF ;
157 
158 		IF x_retcode <> 'S' THEN
159 		   RAISE fnd_api.g_exc_error;
160 		END IF;
161 
162 	END LOOP;
163 
164 END IF ;
165 
166 IF PG_DEBUG in ('Y', 'C') THEN
167 	arp_message.set_line( 'ARP_CMERGE.INSERT_FULL_MERGE_EVENT()-');
168 END IF;
169 
170 EXCEPTION
171   WHEN error_defaulting_gl_date THEN
172 	arp_message.set_line( 'default_gl_date Error in insert_full_merge_event ' || sqlerrm);
173 	RAISE;
174   WHEN OTHERS THEN
175 	arp_message.set_line( 'Others Error in insert_full_merge_event '|| sqlerrm);
176 	RAISE;
177 
178 END insert_full_merge_event ;
179 
180 
181 procedure MERGE (req_id NUMBER, set_num NUMBER, process_mode VARCHAR2) is
182 
183 -- bug2778646 created
184 procedure MERGE_VALIDATION (req_id NUMBER, set_num NUMBER) is
185 
186    l_dummy   NUMBER;
187    draft_cbi EXCEPTION;
188 
189    CURSOR c IS
190      SELECT 1
191      FROM   ra_customer_merges m
192      WHERE  m.request_id = req_id
193      AND    m.set_number = set_num
194      AND EXISTS
195      (
196       SELECT 1
197       FROM  ar_cons_inv ci
198       WHERE ci.site_use_id IN (m.customer_site_id, m.duplicate_site_id)
199       AND   ci.status = 'DRAFT'
200      );
201 
202  BEGIN
203 
204    -- check if there is DRAFT CBI for merged customer site
205    OPEN c;
206    FETCH c INTO l_dummy;
207    IF (c%FOUND) THEN
208      RAISE draft_cbi;
209    END IF;
210    CLOSE c;
211 
212 EXCEPTION
213    WHEN DRAFT_CBI THEN
214       arp_message.set_name('AR','AR_CUST_SITE_DRAFT_CBI') ;
215       arp_message.set_error('ARP_CMERGE_ARCON.AR_CIN') ;
216       raise;
217 
218 end MERGE_VALIDATION;
219 
220 begin
221 
222   arp_message.set_line( 'ARP_CMERGE.MERGE()+' );
223 
224   merge_validation(req_id , set_num );
225 
226   arp_cmerge_aratc.merge(req_id, set_num, process_mode);
227   arp_cmerge_arcol.merge(req_id, set_num, process_mode);
228   arp_cmerge_ardun.merge(req_id, set_num, process_mode);
229   arp_cmerge_artax.merge(req_id, set_num, process_mode);
230   arp_cmerge_arcon.merge(req_id, set_num, process_mode);
231   arp_cmerge_artrx.merge(req_id, set_num, process_mode);
232 
233   insert_full_merge_event(req_id, set_num, process_mode);
234 
235   arp_message.set_line( 'ARP_CMERGE.MERGE()-' );
236 
237 EXCEPTION
238   when others then
239     raise;
240 end MERGE;
241 
242 end ARP_CMERGE;