[Home] [Help]
PACKAGE BODY: APPS.CN_COLLECTION_AR_GEN
Source
4 --------------------------------------------------------+
1 PACKAGE BODY CN_COLLECTION_AR_GEN AS
2 -- $Header: cnargenb.pls 120.5 2005/10/18 01:23:33 apink noship $
3
5 -- Public procedures
6 --------------------------------------------------------+
7
8 -- Procedure Name
9 -- insert_trx
10 -- Purpose
11 -- This procedure inserts into the CN_TRX headers table
12 -- History
13 -- 11-17-93 Devesh Khatu Created
14 -- 08-01-95 Amy Erickson Updated
15
16 g_cn_apply_non_rev_split VARCHAR2(1);
17 l_org_id NUMBER;
18
19 PROCEDURE insert_trx (
20 procedure_name cn_obj_procedures_v.name%TYPE,
21 x_module_id cn_modules.module_id%TYPE,
22 x_event_id cn_events.event_id%TYPE,
23 code IN OUT NOCOPY cn_utils.code_type,
24 x_org_id IN NUMBER) IS
25
26 x_module_type cn_modules.module_type%TYPE;
27 i INTEGER;
28
29 -- This cursor fetches source and destination column names
30 -- required to insert into the trx headers table.
31 -- This is done by joining cn_obj_columns_v with cn_column_maps.
32 -- It is assumed that each column map has a single level foreign key
33 -- map associated with it.
34
35
36 CURSOR header_direct_maps IS
37 SELECT LOWER(destcol.name) dest_column,
38 cm.expression expression
39 FROM cn_table_maps tm,
40 cn_column_maps cm,
41 cn_objects destcol
42 WHERE tm.mapping_type = 'INV1'
43 AND cm.table_map_id = tm.table_map_id
44 AND cm.expression IS NOT NULL
45 AND cm.destination_column_id = destcol.object_id
46 AND lower(destcol.NAME) <> 'sold_to_customer_id'
47 -- Added Last Where Clause For Bug Fix 3681852 Hithanki
48 -- Added for MOAC by Ashley
49 AND tm.org_id = x_org_id
50 AND cm.org_id = tm.org_id
51 AND destcol.org_id = cm.org_id
52 ORDER BY destcol.name;
53
54 BEGIN
55
56 l_org_id := x_org_id;
57 cn_utils.set_org_id(p_org_id => l_org_id);
58 cn_utils.appendcr(code);
59 cn_utils.appendcr(code, '--******** INSERT CN_TRX ********-- ');
60 cn_utils.unset_org_id();
61
62 cn_debug.print_msg('insert_trx>>', 1);
63 fnd_file.put_line(fnd_file.Log, 'insert_trx>>');
64
65 SELECT module_type --AE 11-16-95
66 INTO x_module_type
67 FROM cn_modules
68 WHERE module_id = x_module_id
69 --Added for MOAC by Ashley
70 AND org_id = x_org_id;
71
72 cn_debug.print_msg('insert_trx: x_module_id = ' || x_module_id, 1);
73
74 -- Generate the insert statement
75 cn_debug.print_msg('insert_trx: Generating INSERT statement. ', 1);
76 fnd_file.put_line(fnd_file.Log, 'insert_trx: Generating INSERT statement. ');
77
78 cn_utils.set_org_id(p_org_id => l_org_id);
79 cn_utils.appindcr(code, 'cn_message_pkg.debug('''|| procedure_name || ': Inserting into CN_TRX.'');');
80 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, '''|| procedure_name || ': Inserting into CN_TRX.'');');
81 cn_utils.appendcr(code);
82 cn_utils.appindcr(code, 'INSERT INTO cn_trx(');
83 cn_utils.indent(code, 1);
84
85 -- First fill in some standard fields such as
86 -- status, collection_run_id in the headers table
87 cn_utils.appindcr(code, 'trx_id,');
88 -- Added For MOAC by Ashley
89 cn_utils.appindcr(code, 'org_id,');
93 cn_utils.appindcr(code, 'status,');
90 cn_utils.appindcr(code, 'not_trx_id,');
91 cn_utils.appindcr(code, 'batch_id,');
92 cn_utils.appindcr(code, 'transfer_batch_id,');
94 cn_utils.appindcr(code, 'trx_type,'); --AE 11-16-95
95 cn_utils.appindcr(code, 'event_id,');
96 cn_utils.appindcr(code, 'notified_date,');
97 cn_utils.appindcr(code, 'processed_date,');
98 cn_utils.appindcr(code, 'collection_run_id,');
99
100
101 IF (x_event_id = cn_global.inv_event_id) THEN
102 -- Populate the mapping-driven columns
103 FOR h IN header_direct_maps LOOP
104 cn_utils.appindcr(code, h.dest_column || ',');
105 END LOOP;
106
107 cn_utils.appindcr(code, 'sold_to_customer_id,'); -- Added For Bug Fix 3681852 Hithanki
108
109 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
110 cn_utils.appindcr(code, ')');
111 cn_utils.unindent(code, 1);
112
113 ELSIF ((x_event_id = cn_global.pmt_event_id) OR
114 (x_event_id = cn_global.cbk_event_id) OR
115 (x_event_id = cn_global.wo_event_id)) THEN
116
117 cn_utils.appindcr(code, 'gl_posted_date,');
118 cn_utils.appindcr(code, 'gl_date,');
119 cn_utils.appindcr(code, 'prorated_amount,');
120 cn_utils.appindcr(code, 'line_amount_applied,');
121 cn_utils.appindcr(code, 'spare_column1,');
122 cn_utils.appindcr(code, 'source_trx_id,');
123 cn_utils.appindcr(code, 'source_payment_schedule_id,');
124 cn_utils.appindcr(code, 'due_date ');
125 cn_utils.appindcr(code, ')');
126 cn_utils.unindent(code, 1);
127 END IF;
128
129 cn_utils.appindcr(code, 'SELECT');
130 cn_utils.indent(code, 1);
131 cn_utils.appindcr(code, 'cn_trx_s.NEXTVAL,');
132 --Added for MOAC by Ashley
133 cn_utils.appindcr(code, 'cnt.org_id,');
134 cn_utils.appindcr(code, 'cnt.not_trx_id,');
135 cn_utils.appindcr(code, 'cnt.batch_id,');
136 cn_utils.appindcr(code, 'FLOOR(cn_trx_s.CURRVAL/cn_global.xfer_batch_size),');
137 cn_utils.appindcr(code, '''COL'',');
138 cn_utils.appindcr(code, '''' || x_module_type || ''','); --AE 11-16-95
139 cn_utils.appindcr(code, 'cnt.event_id,'); --AE 01-16-96
140 cn_utils.appindcr(code, 'cnt.notified_date,');
141 cn_utils.appindcr(code, 'cnt.processed_date,'); --AE 01-05-96
142 cn_utils.appindcr(code, 'x_proc_audit_id,');
143
144
145 IF (x_event_id = cn_global.inv_event_id) THEN
146 -- Select the mapping-driven columns.
147 FOR h IN header_direct_maps LOOP
148 cn_utils.appindcr(code, h.expression || ',');
149 END LOOP;
150
151 cn_utils.appindcr(code, 'NVL(rct.sold_to_customer_id,rct.bill_to_customer_id),');
152 ---- Added For Bug Fix 3681852 Hithanki
153
154 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
155 cn_utils.appendcr(code);
156 cn_utils.unindent(code, 1);
157
158 ELSIF (x_event_id = cn_global.pmt_event_id) THEN
159 cn_utils.appindcr(code, 'ara.gl_posted_date,');
160 cn_utils.appindcr(code, 'ara.gl_date,');
161 cn_utils.appindcr(code, 'ara.line_applied,');
162 cn_utils.appindcr(code, 'ara.line_applied,');
163 cn_utils.appindcr(code, 'ara.receivable_application_id,');
164 cn_utils.appindcr(code, 'ara.applied_customer_trx_id,');
165 cn_utils.appindcr(code, 'ara.applied_payment_schedule_id,');
166 cn_utils.appindcr(code, 'NULL ');
167 cn_utils.appendcr(code);
168 cn_utils.unindent(code, 1);
169
170 ELSIF (x_event_id = cn_global.wo_event_id) THEN
171 cn_utils.appindcr(code, 'aa.gl_posted_date,');
172 cn_utils.appindcr(code, 'aa.gl_date,');
173 cn_utils.appindcr(code, 'NVL(aa.line_adjusted, 0),'); --AE 02-05-96
174 cn_utils.appindcr(code, 'NVL(aa.line_adjusted, 0),'); --AE 02-05-96
175 cn_utils.appindcr(code, 'aa.adjustment_id,');
176 cn_utils.appindcr(code, 'aa.customer_trx_id,');
177 cn_utils.appindcr(code, 'aa.payment_schedule_id,');
178 cn_utils.appindcr(code, 'NULL ');
179 cn_utils.appendcr(code);
180 cn_utils.unindent(code, 1);
181
182 ELSIF (x_event_id = cn_global.cbk_event_id) THEN
183 cn_utils.appindcr(code, 'NULL,');
184 cn_utils.appindcr(code, 'NULL,');
185 cn_utils.appindcr(code, 'aps.amount_line_items_remaining,');
186 cn_utils.appindcr(code, 'NULL,');
187 cn_utils.appindcr(code, 'NULL,');
188 cn_utils.appindcr(code, 'aps.customer_trx_id,');
189 cn_utils.appindcr(code, 'aps.payment_schedule_id,');
190 cn_utils.appindcr(code, 'aps.due_date ');
191 cn_utils.appendcr(code);
192 cn_utils.unindent(code, 1);
193 END IF;
194
195 -- generate the from statements
196 IF (x_event_id = cn_global.inv_event_id) THEN
197 cn_utils.appindcr(code, ' FROM cn_not_trx cnt, ra_customer_trx rct');
198 cn_utils.appindcr(code, 'WHERE cnt.source_trx_id = rct.customer_trx_id');
199 -- Added for MOAC by Ashley
200 cn_utils.appindcr(code, 'AND cnt.org_id = '||x_org_id);
201 cn_utils.appindcr(code, 'AND rct.org_id = cnt.org_id');
202
203
204 ELSIF (x_event_id = cn_global.pmt_event_id) THEN
205 cn_utils.appindcr(code, ' FROM cn_not_trx cnt, ar_receivable_applications ara');
206 cn_utils.appindcr(code, 'WHERE cnt.source_trx_id = ara.receivable_application_id');
207
208 --Added For MOAC By Ashley
209 cn_utils.appindcr(code, 'AND cnt.org_id = '||x_org_id);
210 cn_utils.appindcr(code, 'AND ara.org_id = cnt.org_id');
211
212 cn_utils.appindcr(code, ' AND NOT EXISTS (');
213 cn_utils.appindcr(code, ' SELECT trx_id');
214 cn_utils.appindcr(code, ' FROM cn_trx ct');
218 cn_utils.appindcr(code, ' AND ct.trx_type = ''CBK'')');
215 cn_utils.appindcr(code, ' WHERE ct.source_payment_schedule_id = ara.applied_payment_schedule_id');
216 --Added For MOAC By Ashley
217 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
219
220 ELSIF (x_event_id = cn_global.wo_event_id) THEN
221 cn_utils.appindcr(code, ' FROM cn_not_trx cnt, ar_adjustments aa');
222 cn_utils.appindcr(code, 'WHERE cnt.source_trx_id = aa.adjustment_id');
223 --Added For MOAC By Ashley
224 cn_utils.appindcr(code, 'AND cnt.org_id = '||x_org_id);
225 cn_utils.appindcr(code, 'AND aa.org_id = cnt.org_id');
226
227 ELSIF (x_event_id = cn_global.cbk_event_id) THEN
228 cn_utils.appindcr(code, ' FROM cn_not_trx cnt, ar_payment_schedules aps');
229 cn_utils.appindcr(code, 'WHERE cnt.source_trx_id = aps.payment_schedule_id');
230 --Added For MOAC By Ashley
231 cn_utils.appindcr(code, 'AND cnt.org_id = '||x_org_id);
232 cn_utils.appindcr(code, 'AND aps.org_id = cnt.org_id');
233
234 cn_utils.appindcr(code, ' AND NOT EXISTS (');
235 cn_utils.appindcr(code, ' SELECT trx_id');
236 cn_utils.appindcr(code, ' FROM cn_trx ct');
237 cn_utils.appindcr(code, ' WHERE ct.source_payment_schedule_id = aps.payment_schedule_id');
238 --Added For MOAC By Ashley
239 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
240
241 cn_utils.appindcr(code, ' AND ct.trx_type = ''CBK'')');
242 END IF;
243
244 cn_utils.appindcr(code, ' AND cnt.event_id = ' || x_event_id);
245 cn_utils.appindcr(code, ' AND cnt.collected_flag = ''N''');
246 cn_utils.appindcr(code, ' AND cnt.batch_id = x_batch_id;');
247 cn_utils.appendcr(code);
248
249 -- Generate code to update the trx_count variable
250 cn_utils.appindcr(code, 'trx_count := SQL%ROWCOUNT;');
251 cn_utils.appendcr(code);
252 cn_utils.appendcr(code);
253
254 --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
255 -- AE 03-01-96 If event_type = Payments do Givebacks at the same time.
256 IF (x_event_id = cn_global.pmt_event_id) THEN
257
258 cn_utils.appindcr(code, 'INSERT INTO cn_trx(');
259 cn_utils.indent(code, 1);
260
261 -- First fill in some standard fields such as
262 -- status, collection_run_id in the headers table
263 cn_utils.appindcr(code, 'trx_id,');
264 --Added For MOAC by Ashley
265 cn_utils.appindcr(code, 'org_id,');
266 cn_utils.appindcr(code, 'not_trx_id,');
267 cn_utils.appindcr(code, 'batch_id,');
268 cn_utils.appindcr(code, 'transfer_batch_id,');
269 cn_utils.appindcr(code, 'status,');
270 cn_utils.appindcr(code, 'trx_type,'); --AE 11-16-95
271 cn_utils.appindcr(code, 'event_id,');
272 cn_utils.appindcr(code, 'notified_date,');
273 cn_utils.appindcr(code, 'processed_date,');
274 cn_utils.appindcr(code, 'collection_run_id,');
275
276 cn_utils.appindcr(code, 'gl_posted_date,');
277 cn_utils.appindcr(code, 'gl_date,');
278 cn_utils.appindcr(code, 'prorated_amount,');
279 cn_utils.appindcr(code, 'line_amount_applied,');
280 cn_utils.appindcr(code, 'spare_column1,');
281 cn_utils.appindcr(code, 'source_trx_id,');
282 cn_utils.appindcr(code, 'source_payment_schedule_id,');
283 cn_utils.appindcr(code, 'due_date ');
284 cn_utils.appindcr(code, ')');
285 cn_utils.unindent(code, 1);
286
287 cn_utils.appindcr(code, 'SELECT');
288 cn_utils.indent(code, 1);
289 cn_utils.appindcr(code, 'cn_trx_s.NEXTVAL,');
290 --Added for MOAC by Ashley
291 cn_utils.appindcr(code, 'cnt.org_id,');
292 cn_utils.appindcr(code, 'cnt.not_trx_id,');
293 cn_utils.appindcr(code, 'cnt.batch_id,');
294 cn_utils.appindcr(code, 'FLOOR(cn_trx_s.CURRVAL/cn_global.xfer_batch_size),');
295 cn_utils.appindcr(code, '''COL'',');
296 cn_utils.appindcr(code, '''GBK'',');
297 cn_utils.appindcr(code, 'cn_global.gbk_event_id,');
298 cn_utils.appindcr(code, 'cnt.notified_date,');
299 cn_utils.appindcr(code, 'cnt.processed_date,');
300 cn_utils.appindcr(code, 'x_proc_audit_id,');
301
302 cn_utils.appindcr(code, 'ara.gl_posted_date,');
303 cn_utils.appindcr(code, 'ara.gl_date,');
307 cn_utils.appindcr(code, 'ara.applied_customer_trx_id,');
304 cn_utils.appindcr(code, 'ara.line_applied,');
305 cn_utils.appindcr(code, 'ara.line_applied,');
306 cn_utils.appindcr(code, 'ara.receivable_application_id,');
308 cn_utils.appindcr(code, 'ara.applied_payment_schedule_id,');
309 cn_utils.appindcr(code, 'NULL ');
310 cn_utils.appendcr(code);
311 cn_utils.unindent(code, 1);
312
313 -- generate the from statements
314 cn_utils.appindcr(code, ' FROM cn_not_trx cnt, ar_receivable_applications ara');
315 cn_utils.appindcr(code, 'WHERE cnt.source_trx_id = ara.receivable_application_id');
316 --Added For MOAC By Ashley
317 cn_utils.appindcr(code, 'AND cnt.org_id = '||x_org_id);
318 cn_utils.appindcr(code, 'AND ara.org_id = cnt.org_id');
319
320 cn_utils.appindcr(code, ' AND EXISTS (');
321 cn_utils.appindcr(code, ' SELECT trx_id');
322 cn_utils.appindcr(code, ' FROM cn_trx ct');
323 cn_utils.appindcr(code, ' WHERE ct.source_payment_schedule_id = ara.applied_payment_schedule_id');
324 --Added for MOAC by Ashley
325 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
326
327 cn_utils.appindcr(code, ' AND ct.trx_type = ''CBK'')');
328
329 cn_utils.appindcr(code, ' AND cnt.event_id = ' || x_event_id);
330 cn_utils.appindcr(code, ' AND cnt.collected_flag = ''N''');
331 cn_utils.appindcr(code, ' AND cnt.batch_id = x_batch_id;');
332 cn_utils.appendcr(code);
333
334 -- Generate code to update the trx_count variable
335 cn_utils.appindcr(code, 'trx_count := trx_count + SQL%ROWCOUNT;');
336 cn_utils.appendcr(code);
337 cn_utils.appendcr(code);
338 END IF; -- (x_event_id = cn_global.pmt_event_id)
339 --++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
340
341 cn_utils.unset_org_id();
342 cn_debug.print_msg('insert_trx: Generated INSERT statement.', 1);
343 fnd_file.put_line(fnd_file.Log, 'insert_trx: Generated INSERT statement.');
344
345 cn_utils.set_org_id(p_org_id => l_org_id);
346 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserted '' || trx_count || '' records into cn_trx.'');');
347 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log,''' || procedure_name || ': Inserted '' || trx_count || '' records into cn_trx.'');');
348 cn_utils.appendcr(code);
349 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updating collected_flag in CN_NOT_TRX .'');');
350 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log,''' || procedure_name || ': Updating collected_flag in CN_NOT_TRX .'');');
351 cn_utils.appendcr(code);
352
353 cn_utils.appindcr(code, 'UPDATE cn_not_trx cnt');
354 cn_utils.appindcr(code, ' SET collected_flag = ''Y''');
355 cn_utils.appindcr(code, ' WHERE cnt.event_id = ' || x_event_id);
356 --Added for MOAC by Ashley
357 cn_utils.appindcr(code, ' AND cnt.org_id = ' || x_org_id);
358
359 cn_utils.appindcr(code, ' AND cnt.collected_flag = ''N''');
360 cn_utils.appindcr(code, ' AND cnt.batch_id = x_batch_id;');
361 cn_utils.appendcr(code);
362 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updated collected_flag in cn_not_trx.'');');
363 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log,''' || procedure_name || ': Updated collected_flag in cn_not_trx.'');');
364 cn_utils.appendcr(code);
365 cn_utils.unset_org_id();
366
367 cn_debug.print_msg('insert_trx<<', 1);
368 fnd_file.put_line(fnd_file.Log, 'insert_trx<<');
369
370 EXCEPTION
371 WHEN NO_DATA_FOUND THEN
372 cn_debug.print_msg('insert_trx: in exception handler for NO_DATA_FOUND', 1);
373 fnd_file.put_line(fnd_file.Log, 'insert_trx: in exception handler for NO_DATA_FOUND');
374 RETURN;
375 END insert_trx;
376
377
378
379 -- Procedure Name
380 -- update_trx
381 -- Purpose
382 -- This procedure updates the CN_TRX headers table
383 -- History
384 -- 17-NOV-93 Devesh Khatu Created
385
386 PROCEDURE update_trx (
387 procedure_name cn_obj_procedures_v.name%TYPE,
388 x_module_id cn_modules.module_id%TYPE,
389 x_event_id cn_events.event_id%TYPE,
390 code IN OUT NOCOPY cn_utils.code_type,
391 x_org_id IN NUMBER) IS
392
393
394
395 CURSOR header_direct_maps IS
396 SELECT LOWER(destcol.name) dest_column,
397 cm.expression expression
398 FROM cn_table_maps tm,
399 cn_column_maps cm,
400 cn_objects destcol
401 WHERE tm.mapping_type = 'INV1'
402 AND cm.table_map_id = tm.table_map_id
403 AND cm.expression IS NOT NULL
404 AND cm.destination_column_id = destcol.object_id
405 -- Added for MOAC by Ashley
406 AND tm.org_id = x_org_id
407 AND cm.org_id = tm.org_id
408 AND destcol.org_id = cm.org_id
409 ORDER BY destcol.name;
410
411
412 BEGIN
413 l_org_id := x_org_id;
414 cn_utils.set_org_id(p_org_id => l_org_id);
415 cn_utils.appendcr(code);
416 cn_utils.appendcr(code, '--******** UPDATE CN_TRX ********-- ');
417 cn_utils.unset_org_id();
418
419 cn_debug.print_msg('update_trx>>', 1);
420 fnd_file.put_line(fnd_file.Log, 'update_trx>>');
421 -- Initialize value of table_map_id
422 -- Note: This assumes that there is exactly one header table in the
423 -- repository
424
425 cn_debug.print_msg('update_trx: x_module_id = ' || x_module_id, 1);
426
427
428 -- Generate the update statement
429 cn_debug.print_msg('update_trx: Generating UPDATE statement. ', 1);
430 fnd_file.put_line(fnd_file.Log, 'update_trx: Generating UPDATE statement. ');
431
435 cn_utils.appendcr(code);
432 cn_utils.set_org_id(p_org_id => l_org_id);
433 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updating CN_TRX .'');');
434 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updating CN_TRX .'');');
436
437
438 IF (x_event_id = cn_global.inv_event_id) THEN
439
440 -- update trx_type for Invoices and Credit Memos. --AE 01-26-96
441 -- Note: Sort out the Credit Memos from the Invoices.
442 -- Up to this point, the ct.trx_type = INV for both.
443 cn_utils.appindcr(code, 'UPDATE cn_trx ct');
444 cn_utils.appindcr(code, ' SET trx_type = (');
445 cn_utils.appindcr(code, ' SELECT rctt.type');
446 cn_utils.appindcr(code, ' FROM ra_cust_trx_types rctt');
447 cn_utils.appindcr(code, ' WHERE rctt.cust_trx_type_id = ct.trx_type_id ');
448 --Added for MOAC by Ashley
449 cn_utils.appindcr(code, ' AND rctt.org_id = '||x_org_id||') ');
450 cn_utils.appindcr(code, ' WHERE ct.collection_run_id = x_proc_audit_id ');
451 --Added for MOAC by Ashley
452 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id||' ;');
453 cn_utils.appendcr(code);
454
455
456 -- update rollup date for Invoices. --AE 01-26-96
457 cn_utils.appindcr(code, 'UPDATE cn_trx ct');
458 cn_utils.appindcr(code, ' SET rollup_date = NVL(date_ordered, trx_date)');
459 cn_utils.appindcr(code, ' WHERE ct.collection_run_id = x_proc_audit_id ');
460 --Added for MOAC by Ashley
461 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
462 cn_utils.appindcr(code, ' AND ct.trx_type IN (''INV'',''DM''); ');
463 cn_utils.appendcr(code);
464
465 -- update rollup date for Credit Memos.
466 cn_utils.appindcr(code, 'UPDATE cn_trx ct');
467 cn_utils.appindcr(code, ' SET rollup_date = (');
468 cn_utils.appindcr(code, ' SELECT rct.trx_date');
469 cn_utils.appindcr(code, ' FROM ra_customer_trx rct');
470 cn_utils.appindcr(code, ' WHERE rct.customer_trx_id = ct.source_parent_trx_id ');
471 --Added for MOAC by Ashley
472 cn_utils.appindcr(code, ' AND rct.org_id = '||x_org_id||') ');
473
474 cn_utils.appindcr(code, ' WHERE ct.collection_run_id = x_proc_audit_id ');
475 --Added for MOAC by Ashley
476 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id );
477 cn_utils.appindcr(code, ' AND ct.trx_type = ''CM'' ');
478 cn_utils.appindcr(code, ' AND ct.source_parent_trx_id IS NOT NULL; ');
479 cn_utils.appendcr(code);
480
481 END IF; -- for cn_global.inv_event_id compare
482
483
484 -- Update the columns whose mappings have been defined for invoices
485 -- For all event types other than Invoices.
486 IF (x_event_id <> cn_global.inv_event_id) THEN
487
488 cn_utils.appindcr(code, 'UPDATE cn_trx ct');
489 cn_utils.appindcr(code, ' SET');
490
491 -- Update the custom-columns. This needs to be done by joining to other
492 -- tables, by using information in the foreign key maps table.
493 cn_utils.indent(code, 1);
494 cn_utils.appindcr(code, '(');
495 FOR i IN header_direct_maps LOOP
496 cn_utils.appindcr(code, i.dest_column || ',');
497 END LOOP;
498 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma or '('
499
500 cn_utils.appindcr(code, ') = (');
501 cn_utils.unindent(code, 2);
502 cn_utils.appindcr(code, 'SELECT');
503 cn_utils.indent(code, 2);
504
505 FOR i IN header_direct_maps LOOP
506 cn_utils.appindcr(code, i.expression || ',');
507 END LOOP;
508 cn_utils.unindent(code, 1);
509 IF (SQL%FOUND) THEN
510 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
511 END IF;
512
513 cn_utils.appendcr(code);
514 cn_utils.appindcr(code, ' FROM ra_customer_trx rct');
515 cn_utils.appindcr(code, ' WHERE rct.customer_trx_id = ct.source_trx_id');
516 --Added for MOAC by Ashley
517 cn_utils.appindcr(code, ' AND rct.org_id = '||x_org_id||'),');
518
519 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
520 cn_utils.appendcr(code);
521
522 cn_utils.unindent(code, 1);
523 cn_utils.appindcr(code, 'WHERE ct.collection_run_id = x_proc_audit_id');
524 --Added for MOAC by Ashley
525 cn_utils.appindcr(code, 'AND ct.org_id = '||x_org_id||';');
526
527 cn_utils.appendcr(code);
528
529 END IF; -- for cn_global compare
530
531
532 -- Generate code to update the trx_update_count variable
533 cn_utils.appendcr(code);
534 cn_utils.appindcr(code, 'trx_update_count := SQL%ROWCOUNT;');
535 cn_utils.unset_org_id();
536 cn_debug.print_msg('update_trx: Generated UPDATE statement.', 1);
537 fnd_file.put_line(fnd_file.Log, 'update_trx: Generated UPDATE statement.');
538 cn_utils.set_org_id(p_org_id => l_org_id);
539 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updated '' || trx_update_count || '' cn_trx.'');');
540 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log,''' || procedure_name || ': Updated '' || trx_update_count || '' cn_trx.'');');
541 cn_utils.appendcr(code);
542 cn_utils.unset_org_id();
543 cn_debug.print_msg('update_trx<<', 1);
544 fnd_file.put_line(fnd_file.Log, 'update_trx<<');
545 EXCEPTION
546 WHEN NO_DATA_FOUND THEN
547 cn_debug.print_msg('update_trx: in exception handler for NO_DATA_FOUND', 1);
548 fnd_file.put_line(fnd_file.Log, 'update_trx: in exception handler for NO_DATA_FOUND');
549 RETURN;
550 END update_trx;
551
552
553 -- Procedure Name
554 -- insert_lines
555 -- Purpose
559
556 -- Generates code to insert into the CN_TRX_LINES table
557 -- History
558 -- 17-NOV-93 Devesh Khatu Created
560 PROCEDURE insert_lines (
561 procedure_name cn_obj_procedures_v.name%TYPE,
562 x_module_id cn_modules.module_id%TYPE,
563 x_event_id cn_events.event_id%TYPE,
564 code IN OUT NOCOPY cn_utils.code_type,
565 x_org_id IN NUMBER) IS
566
567
568 -- Declare cursor for inserting into the trx lines table
569 CURSOR lines_direct_maps IS
570 SELECT LOWER(destcol.name) dest_column,
571 cm.expression expression
572 FROM cn_table_maps tm,
573 cn_column_maps cm,
574 cn_objects destcol
575 WHERE tm.mapping_type = 'INV2'
576 AND cm.table_map_id = tm.table_map_id
577 AND cm.expression IS NOT NULL
578 AND cm.destination_column_id = destcol.object_id
579 -- Added for MOAC by Ashley
580 AND tm.org_id = x_org_id
581 AND cm.org_id = tm.org_id
582 AND destcol.org_id = cm.org_id
583 ORDER BY destcol.name;
584
585 BEGIN
586 l_org_id := x_org_id;
587 cn_utils.set_org_id(p_org_id => l_org_id);
588 cn_utils.appendcr(code);
589 cn_utils.appendcr(code, '--******** INSERT CN_TRX_LINES *********-- ');
590
591 cn_debug.print_msg('insert_lines>>', 1);
592 fnd_file.put_line(fnd_file.Log, 'insert_lines>>');
593 cn_debug.print_msg('insert_lines: x_module_id = ' || x_module_id, 1);
594
595 -- Generate the INSERT statement
596 cn_debug.print_msg('insert_lines: Generating INSERT statement.', 1);
597 fnd_file.put_line(fnd_file.Log, 'insert_lines: Generating INSERT statement.');
598
599 cn_utils.set_org_id(p_org_id => l_org_id);
600
601 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserting into CN_TRX_LINES .'');');
602 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log,''' || procedure_name || ': Inserting into CN_TRX_LINES .'');');
603 cn_utils.appendcr(code);
604
605 cn_utils.appindcr(code, 'INSERT INTO cn_trx_lines(');
606 cn_utils.indent(code, 1);
607 -- Insert fixed columns first
608 cn_utils.appindcr(code, 'trx_line_id,');
609 --Added for MOAC by Ashley
610 cn_utils.appindcr(code, 'org_id,');
611
612 cn_utils.appindcr(code, 'trx_id,');
613 cn_utils.appindcr(code, 'event_id,');
614 cn_utils.appindcr(code, 'collection_run_id,');
615
616 -- Insert custom columns using lines_direct_maps cursor
617 FOR l IN lines_direct_maps LOOP
618 cn_utils.appindcr(code, l.dest_column || ',');
619 END LOOP;
620
621 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
622 cn_utils.appindcr(code, ')');
623 cn_utils.unindent(code, 1);
624
625 -- Generate the SELECT clause required for the insert statement
626 cn_utils.appindcr(code, 'SELECT');
627 cn_utils.indent(code, 1);
628 -- Select fixed columns
629 cn_utils.appindcr(code, 'cn_trx_lines_s.NEXTVAL,');
630 --Added for MOAC by Ashley
631 cn_utils.appindcr(code, 'ct.org_id,');
632
633 cn_utils.appindcr(code, 'ct.trx_id,');
634 cn_utils.appindcr(code, 'ct.event_id,');
635 cn_utils.appindcr(code, 'x_proc_audit_id,');
636
637
638 -- Select other columns using the lines_direct_maps cursors. Note that
639 -- we fetch the records in the cursor in the same order as before due to
640 -- the order by column_id in the cursor where clause.
641 FOR l IN lines_direct_maps LOOP
642 cn_utils.appindcr(code, l.expression || ',');
643 END LOOP;
644
645 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
646 cn_utils.appendcr(code);
647 cn_utils.unindent(code, 1);
648
649 -- Generate the FROM and WHERE clauses
650 cn_utils.appindcr(code, ' FROM cn_trx ct, ra_customer_trx_lines rctl');
651
652 cn_utils.appindcr(code, 'WHERE ct.source_trx_id = rctl.customer_trx_id');
653 cn_utils.appindcr(code, ' AND ct.collection_run_id = x_proc_audit_id ');
654 --Added for MOAC by Ashley
655 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
656 cn_utils.appindcr(code, ' AND rctl.org_id = ct.org_id ');
657
658 cn_utils.appindcr(code, ' AND rctl.line_type = ''LINE'';');
659
660 -- Generate code to update the trx_line_count variable
661 cn_utils.appendcr(code);
662 cn_utils.appindcr(code, 'trx_line_count := SQL%ROWCOUNT;');
663 cn_debug.print_msg('insert_lines: Generated INSERT statement.', 1);
664 fnd_file.put_line(fnd_file.Log, 'insert_lines: Generated INSERT statement.');
665 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserted '' || trx_line_count || '' records into cn_trx_lines.'');');
666 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log,''' || procedure_name || ': Inserted '' || trx_line_count || '' records into cn_trx_lines.'');');
667 cn_utils.appendcr(code);
668
669 cn_debug.print_msg('insert_lines<<', 1);
670 fnd_file.put_line(fnd_file.Log, 'insert_lines<<');
671 EXCEPTION
672 WHEN NO_DATA_FOUND THEN
673 cn_debug.print_msg('insert_lines: in exception handler for NO_DATA_FOUND', 1);
674 fnd_file.put_line(fnd_file.Log, 'insert_lines: in exception handler for NO_DATA_FOUND');
675 RETURN;
676 END insert_lines;
677
678
679
680 -- Procedure Name
681 -- update_lines
682 -- Purpose
683 -- Generates code to update the CN_TRX_LINES table
684 -- History
685 -- 17-NOV-93 Devesh Khatu Created
686
687 PROCEDURE update_lines (
688 procedure_name cn_obj_procedures_v.name%TYPE,
689 x_module_id cn_modules.module_id%TYPE,
690 x_event_id cn_events.event_id%TYPE,
691 code IN OUT NOCOPY cn_utils.code_type,
695 BEGIN
692 x_org_id IN NUMBER) IS
693
694
696 l_org_id := x_org_id;
697 cn_utils.set_org_id(p_org_id => l_org_id);
698 cn_utils.appendcr(code);
699 cn_utils.appendcr(code, '--******** UPDATE CN_TRX_LINES ********-- ');
700
701 cn_debug.print_msg('update_lines>>', 1);
702 fnd_file.put_line(fnd_file.Log, 'update_lines>>');
703 cn_debug.print_msg('update_lines: x_module_id = ' || x_module_id, 1);
704
705
706 -- Generate the UPDATE statement
707 cn_debug.print_msg('update_lines: Generating UPDATE statement.', 1);
708 fnd_file.put_line(fnd_file.Log, 'update_lines: Generating UPDATE statement.');
709
710 cn_utils.set_org_id(p_org_id => l_org_id);
711 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updating CN_TRX_LINES .'');');
712 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updating CN_TRX_LINES .'');');
713 cn_utils.appendcr(code);
714
715 IF x_event_id <> cn_global.inv_event_id THEN
716
717 cn_utils.appindcr(code, 'UPDATE cn_trx_lines ctl');
718 cn_utils.appindcr(code, ' SET');
719 cn_utils.indent(code, 1);
720 cn_utils.appindcr(code, '(revenue_amount, extended_amount) = (');
721 cn_utils.appindcr(code, ' SELECT ');
722 cn_utils.appindcr(code, ' DECODE(ct.invoice_total, 0, 0, (ct.prorated_amount/ct.invoice_total) * ctl.revenue_amount),');
723 cn_utils.appindcr(code, ' DECODE(ct.invoice_total, 0, 0, (ct.prorated_amount/ct.invoice_total) * ctl.extended_amount)');
724 cn_utils.appindcr(code, ' FROM cn_trx ct');
725 cn_utils.appindcr(code, ' WHERE ctl.trx_id = ct.trx_id');
726 --Added for MOAC by Ashley
727 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id||')');
728
729 cn_utils.appendcr(code);
730 cn_utils.unindent(code, 1);
731 cn_utils.appindcr(code, 'WHERE ctl.collection_run_id = x_proc_audit_id');
732 --Added for MOAC by Ashley
733 cn_utils.appindcr(code, 'AND ctl.org_id = '||x_org_id||';');
734
735 cn_utils.appendcr(code);
736
737 END IF; --AE 08-21-95 end of empty cursor check.
738
739
740 -- Generate code to update the trx_line_update_count variable
741 cn_utils.appendcr(code);
742 cn_utils.appindcr(code, 'trx_line_update_count := SQL%ROWCOUNT;');
743 cn_debug.print_msg('update_lines: Generated UPDATE statement.', 1);
744 fnd_file.put_line(fnd_file.Log, 'update_lines: Generated UPDATE statement.');
745 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updated '' || trx_line_update_count || '' cn_trx_lines.'');');
746 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updated '' || trx_line_update_count || '' cn_trx_lines.'');');
747 cn_utils.appendcr(code);
748
749 cn_debug.print_msg('update_lines<<', 1);
750 fnd_file.put_line(fnd_file.Log, 'update_lines<<');
751 EXCEPTION
752 WHEN NO_DATA_FOUND THEN
753 cn_debug.print_msg('update_lines: in exception handler for NO_DATA_FOUND', 1);
754 fnd_file.put_line(fnd_file.Log, 'update_lines: in exception handler for NO_DATA_FOUND');
755 RETURN;
756 END update_lines;
757
758
759
760 -- Procedure Name
761 -- insert_sales_lines
762 -- Purpose
763 -- Generates code to insert into the CN_TRX_SALES_LINES table
764 -- History
765 -- 17-NOV-93 Devesh Khatu Created
766
767 PROCEDURE insert_sales_lines (
768 procedure_name cn_obj_procedures_v.name%TYPE,
769 x_module_id cn_modules.module_id%TYPE,
770 x_event_id cn_events.event_id%TYPE,
771 code IN OUT NOCOPY cn_utils.code_type,
772 x_org_id IN NUMBER) IS
773
774
775 -- Declare cursor for inserting into the sales_lines table
776 CURSOR sales_lines_direct_maps IS
777 SELECT LOWER(destcol.name) dest_column,
778 cm.expression expression
779 FROM cn_table_maps tm,
780 cn_column_maps cm,
781 cn_objects destcol
782 WHERE tm.mapping_type = 'INV3'
783 AND cm.table_map_id = tm.table_map_id
784 AND cm.expression IS NOT NULL
785 AND cm.destination_column_id = destcol.object_id
786 -- Added for MOAC by Ashley
787 AND tm.org_id = x_org_id
788 AND cm.org_id = tm.org_id
789 AND destcol.org_id = cm.org_id
790
791 AND destcol.name <> 'QUANTITY' -- Fix bug 2809039
792 ORDER BY destcol.name;
793
794 BEGIN
795 l_org_id := x_org_id;
796 cn_utils.set_org_id(p_org_id => l_org_id);
797 cn_utils.appendcr(code);
798 cn_utils.appendcr(code, '--******** INSERT CN_TRX_SALES_LINES ********-- ');
799
800 cn_debug.print_msg('insert_sales_lines>>', 1);
801 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines>>');
802 -- Initialize value of table_map_id, etc.
803 -- Assumption: there is exactly 1 table at the sales credit level
804 -- in each repository.
805
806 cn_debug.print_msg('insert_sales_lines: x_module_id = ' || x_module_id, 1);
807 cn_debug.print_msg('insert_sales_lines: Updating object dependencies and module object maps.', 1);
808 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines: Updating object dependencies and module object maps.');
809
810 -- Generate the insert clause
811 cn_debug.print_msg('insert_sales_lines: Generating INSERT statement.', 1);
812 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines: Generating INSERT statement.');
813
814 cn_utils.set_org_id(p_org_id => l_org_id);
815 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserting into CN_TRX_SALES_LINES .'');');
816 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Inserting into CN_TRX_SALES_LINES .'');');
817 cn_utils.appendcr(code);
818
822 cn_utils.appindcr(code, 'trx_sales_line_id,');
819 cn_utils.appindcr(code, 'INSERT INTO cn_trx_sales_lines (');
820 cn_utils.indent(code, 1);
821 -- Insert fixed columns first
823 cn_utils.appindcr(code, 'sales_line_batch_id,');
824 --Added for MOAC by Ashley
825 cn_utils.appindcr(code, 'org_id,');
826 cn_utils.appindcr(code, 'trx_line_id,');
827 cn_utils.appindcr(code, 'trx_id,');
828 cn_utils.appindcr(code, 'event_id,');
829 cn_utils.appindcr(code, 'collection_run_id,');
830 IF (x_event_id = cn_global.ram_event_id) THEN
831 cn_utils.appindcr(code, 'adj_collection_run_id,');
832 cn_utils.appindcr(code, 'created_by,');
833 cn_utils.appindcr(code, 'creation_date,');
834 cn_utils.appindcr(code, 'last_updated_by,');
835 cn_utils.appindcr(code, 'last_update_date,');
836 cn_utils.appindcr(code, 'last_update_login,');
837 END IF;
838
839 -- Insert custom columns using sales_lines_direct_maps cursor
840 FOR s IN sales_lines_direct_maps LOOP
841 cn_utils.appindcr(code, s.dest_column || ',');
842 END LOOP;
843
844 cn_utils.appindcr(code, 'quantity,');
845
846 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
847 cn_utils.appindcr(code, ')');
848 cn_utils.unindent(code, 1);
849
850 -- Generate the SELECT clause for the insert statement
851 cn_utils.appindcr(code, 'SELECT');
852 cn_utils.indent(code, 1);
853
854 -- Select fixed columns
855 cn_utils.appindcr(code, 'cn_trx_sales_lines_s.NEXTVAL,');
856 cn_utils.appindcr(code, 'FLOOR(cn_trx_sales_lines_s.CURRVAL/cn_global.cls_batch_size),');
857 --Added for MOAC by Ashley
858 cn_utils.appindcr(code, 'ctl.org_id,');
859 cn_utils.appindcr(code, 'ctl.trx_line_id,');
860 cn_utils.appindcr(code, 'ctl.trx_id,');
861 cn_utils.appindcr(code, 'ctl.event_id,');
862 IF (x_event_id = cn_global.ram_event_id) THEN
863 cn_utils.appindcr(code, 'null,');
864 cn_utils.appindcr(code, 'x_proc_audit_id,');
865 cn_utils.appindcr(code, 'x_created_by,');
866 cn_utils.appindcr(code, 'x_creation_date,');
867 cn_utils.appindcr(code, 'x_last_updated_by,');
868 cn_utils.appindcr(code, 'x_last_update_date,');
869 cn_utils.appindcr(code, 'x_last_update_login,');
870 ELSE
871 cn_utils.appindcr(code, 'x_proc_audit_id,');
872 END IF;
873
874
875 -- Select custom columns using sales_lines_direct_maps cursor.
876 -- we fetch the records in the cursor in the same order as before due to
877 -- the order by column_id in the cursor where clause.
878 FOR s IN sales_lines_direct_maps LOOP
879 cn_utils.appindcr(code, s.expression || ',');
880 END LOOP;
881
882 -- Fix bug 2809039
883 --Added for R12 release
884 g_cn_apply_non_rev_split := CN_SYSTEM_PARAMETERS.value('CN_NON_REVENUE_SPLIT',x_org_id);
885
886 IF (g_cn_apply_non_rev_split = 'N') THEN
887 cn_utils.appindcr(code, 'NVL(ctl.quantity, 0) * NVL(rctls.revenue_percent_split, 0)/100 ,');
888 ELSE
889 cn_utils.appindcr(code, '(NVL(ctl.quantity, 0) * NVL(rctls.revenue_percent_split, 0)/100) + (NVL(ctl.quantity, 0) * NVL(rctls.non_revenue_percent_split, 0)/100) ,');
890 END IF;
891
892 cn_utils.strip_prev(code, 1); --AE 08-24-95 remove trailing comma
893 cn_utils.appendcr(code);
894 cn_utils.unindent(code, 1);
895
896 -- Generate FROM and WHERE clauses
897 IF (x_event_id = cn_global.ram_event_id) THEN
898 cn_utils.appindcr(code, ' FROM cn_trx_lines ctl, ra_cust_trx_line_salesreps rctls ');
899 cn_utils.appindcr(code, 'WHERE ctl.source_trx_id = rctls.customer_trx_id ');
900 --cn_utils.appindcr(code, ' AND rctls.revenue_adjustment_id is NOT NULL'); -- Added Bug : 3331479
901 -- Commented By Hithanki QA Bug 4234180
902 cn_utils.appindcr(code, ' AND ctl.source_trx_line_id = rctls.customer_trx_line_id ');
903 cn_utils.appindcr(code, ' AND ctl.adj_collection_run_id = x_proc_audit_id ');
904 cn_utils.appindcr(code, ' AND ctl.adjusted_flag = ''Y'' ');
905 cn_utils.appindcr(code, ' AND ctl.negated_flag = ''Y'' ');
906 cn_utils.appindcr(code, ' AND ctl.collected_flag = ''N'' ');
907 cn_utils.appindcr(code, ' AND ctl.event_id = cn_global.inv_event_id ');
908 cn_utils.appindcr(code, ' AND ctl.adj_batch_id = x_adj_batch_id ');
909 --Added for MOAC by Ashley
910 cn_utils.appindcr(code, ' AND ctl.org_id = '||x_org_id );
911 cn_utils.appindcr(code, ' AND rctls.org_id = ctl.org_id ');
912
913 cn_utils.appindcr(code, ' AND ((x_ram_negate_profile = ''Y'') OR');
914 cn_utils.appindcr(code, ' (x_ram_negate_profile = ''N'' AND');
915 cn_utils.appindcr(code, ' NOT EXISTS ');
916 cn_utils.appindcr(code, ' (SELECT 1 ');
917 cn_utils.appindcr(code, ' FROM cn_trx_sales_lines ctsl ');
918 cn_utils.appindcr(code, ' WHERE ctsl.source_trx_sales_line_id = rctls.cust_trx_line_salesrep_id');
919 --cn_utils.appindcr(code, ' AND ctsl.adj_collection_run_id is NOT NULL'); -- Added Bug : 3331479
920 cn_utils.appindcr(code, ' AND ctsl.event_id = cn_global.inv_event_id'); -- Added Bug : 3331479
921 --Added for MOAC by Ashley
922 cn_utils.appindcr(code, ' AND ctsl.org_id = '||x_org_id||')');
923 cn_utils.appindcr(code, ' )');
924 cn_utils.appindcr(code, ' );');
925 ELSIF (x_event_id = cn_global.inv_event_id) THEN
926 cn_utils.appindcr(code, ' FROM cn_trx_lines ctl, ra_cust_trx_line_salesreps rctls');
927 cn_utils.appindcr(code, 'WHERE ctl.source_trx_id = rctls.customer_trx_id');
928 cn_utils.appindcr(code, ' AND ctl.source_trx_line_id = rctls.customer_trx_line_id');
929 cn_utils.appindcr(code, ' AND ctl.collection_run_id = x_proc_audit_id');
933
930 --Added for MOAC by Ashley
931 cn_utils.appindcr(code, ' AND ctl.org_id = '||x_org_id);
932 cn_utils.appindcr(code, ' AND rctls.org_id = ctl.org_id;');
934 ELSIF (x_event_id = cn_global.pmt_event_id) THEN
935 cn_utils.appindcr(code, ' FROM cn_trx_lines ctl, ra_cust_trx_line_salesreps rctls');
936 cn_utils.appindcr(code, 'WHERE ctl.source_trx_id = rctls.customer_trx_id');
937 cn_utils.appindcr(code, ' AND ctl.source_trx_line_id = rctls.customer_trx_line_id');
938 cn_utils.appindcr(code, ' AND ctl.collection_run_id = x_proc_audit_id');
939 --cn_utils.appindcr(code, ' AND rctls.revenue_adjustment_id is null');
940 cn_utils.appindcr(code, ' AND (ctl.event_id = cn_global.gbk_event_id');
941 --Added for MOAC by Ashley
942 cn_utils.appindcr(code, ' AND ctl.org_id = '||x_org_id);
943 cn_utils.appindcr(code, ' AND rctls.org_id = ctl.org_id');
944
945 cn_utils.appindcr(code, ' AND EXISTS');
946 cn_utils.appindcr(code, ' (select 1');
947 cn_utils.appindcr(code, ' from cn_trx_sales_lines rctls_in');
948 cn_utils.appindcr(code, ' where rctls_in.source_trx_sales_line_id = rctls.cust_trx_line_salesrep_id');
949 cn_utils.appindcr(code, ' and rctls_in.event_id = cn_global.cbk_event_id');
950 --Added for MOAC by Ashley
951 cn_utils.appindcr(code, ' and rctls_in.org_id = '||x_org_id||')');
952
953 cn_utils.appindcr(code, ' OR (ctl.event_id = cn_global.pmt_event_id and rctls.revenue_adjustment_id is null));');
954 ELSE
955 cn_utils.appindcr(code, ' FROM cn_trx_lines ctl, ra_cust_trx_line_salesreps rctls');
956 cn_utils.appindcr(code, 'WHERE ctl.source_trx_id = rctls.customer_trx_id');
957 cn_utils.appindcr(code, ' AND ctl.source_trx_line_id = rctls.customer_trx_line_id');
958 --Added for MOAC by Ashley
959 cn_utils.appindcr(code, ' AND ctl.org_id = '||x_org_id);
960 cn_utils.appindcr(code, ' AND rctls.org_id = ctl.org_id');
961
962 cn_utils.appindcr(code, ' AND ctl.collection_run_id = x_proc_audit_id;');
963 --cn_utils.appindcr(code, ' AND rctls.revenue_adjustment_id is null;');
964 /*ELSE
965 cn_utils.appindcr(code, ' FROM cn_trx_lines ctl, ra_cust_trx_line_salesreps rctls');
966 cn_utils.appindcr(code, 'WHERE ctl.source_trx_id = rctls.customer_trx_id');
967 cn_utils.appindcr(code, ' AND ctl.source_trx_line_id = rctls.customer_trx_line_id');
968 cn_utils.appindcr(code, ' AND ctl.collection_run_id = x_proc_audit_id');
969 --cn_utils.appindcr(code, ' AND rctls.revenue_adjustment_id is null;');
970 cn_utils.appindcr(code, ' AND (ctl.event_id <> cn_global.pmt_event_id ');
971 cn_utils.appindcr(code, ' AND EXISTS');
972 cn_utils.appindcr(code, ' (SELECT 1');
973 cn_utils.appindcr(code, ' FROM cn_trx_sales_lines rctls_in');
974 cn_utils.appindcr(code, ' WHERE rctls_in.source_trx_sales_line_id = rctls.cust_trx_line_salesrep_id');
975 cn_utils.appindcr(code, ' AND rctls_in.event_id = cn_global.inv_event_id)');
976 cn_utils.appindcr(code, ' OR (ctl.event_id = cn_global.pmt_event_id AND');
977 cn_utils.appindcr(code, ' rctls.revenue_adjustment_id IS NULL))');
978 cn_utils.appindcr(code, ' AND rctls.salesrep_id <> 0;'); */
979 END IF; --IF (x_event_id = cn_global.ram_event_id)
980
981 -- Update trx_sales_line_count variable
982 cn_utils.appendcr(code);
983 cn_utils.appindcr(code, 'trx_sales_line_count := SQL%ROWCOUNT;');
984 cn_debug.print_msg('insert_sales_lines: Generated INSERT statement.', 1);
985 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines: Generated INSERT statement.');
986 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserted '' || trx_sales_line_count || '' records into cn_trx_sales_lines.'');');
987 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Inserted '' || trx_sales_line_count || '' records into cn_trx_sales_lines.'');');
988 cn_utils.appendcr(code);
989
990 cn_debug.print_msg('insert_sales_lines<<', 1);
991 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines<<');
992
993 IF (x_event_id = cn_global.ram_event_id) THEN
994 cn_utils.appindcr(code, 'UPDATE cn_trx_lines');
995 cn_utils.appindcr(code, ' SET collected_flag = ''Y''');
996 cn_utils.appindcr(code, ' WHERE adjusted_flag = ''Y'' ');
997 --Added for MOAC by Ashley
998 cn_utils.appindcr(code, ' AND org_id = '||x_org_id);
999 cn_utils.appindcr(code, ' AND negated_flag = ''Y'' ');
1000 cn_utils.appindcr(code, ' AND collected_flag = ''N'' ');
1001 cn_utils.appindcr(code, ' AND event_id = cn_global.inv_event_id ');
1002 cn_utils.appindcr(code, ' AND adj_batch_id = x_adj_batch_id;');
1003 cn_utils.appendcr(code);
1004 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updated collected_flag in cn_trx_lines.'');');
1005 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updated collected_flag in cn_trx_lines.'');');
1006 END IF; --IF (x_event_id = cn_global.ram_event_id)
1007
1008 EXCEPTION
1009 WHEN NO_DATA_FOUND THEN
1010 cn_debug.print_msg('insert_sales_lines: in exception handler for NO_DATA_FOUND', 1);
1011 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines: in exception handler for NO_DATA_FOUND');
1012 RETURN;
1013 END insert_sales_lines;
1014
1015
1016
1017 -- Procedure Name
1018 -- update_sales_lines
1019 -- Purpose
1020 -- Generates code to update the CN_TRX_SALES_LINES table
1021 -- History
1022 -- 17-NOV-93 Devesh Khatu Created
1023
1024 PROCEDURE update_sales_lines (
1025 procedure_name cn_obj_procedures_v.name%TYPE,
1026 x_module_id cn_modules.module_id%TYPE,
1027 x_event_id cn_events.event_id%TYPE,
1028 code IN OUT NOCOPY cn_utils.code_type,
1029 x_org_id IN NUMBER) IS
1030
1031
1032
1033 BEGIN
1034 l_org_id := x_org_id;
1035 cn_utils.set_org_id(p_org_id => l_org_id);
1036 cn_utils.appendcr(code);
1040 fnd_file.put_line(fnd_file.Log, 'update_sales_lines>>');
1037 cn_utils.appendcr(code, '--******** UPDATE CN_TRX_SALES_LINES ********-- ');
1038
1039 cn_debug.print_msg('update_sales_lines>>', 1);
1041 cn_debug.print_msg('update_sales_lines: x_module_id = ' || x_module_id, 1);
1042
1043 cn_debug.print_msg('update_sales_lines: Generating UPDATE statement.', 1);
1044 fnd_file.put_line(fnd_file.Log, 'update_sales_lines: Generating UPDATE statement.');
1045
1046 cn_utils.set_org_id(p_org_id => l_org_id);
1047 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updating CN_TRX_SALES_LINES .'');');
1048 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updating CN_TRX_SALES_LINES .'');');
1049 cn_utils.appendcr(code);
1050
1051 -- Generate the UPDATE statement
1052 cn_utils.appindcr(code, 'UPDATE cn_trx_sales_lines ctsl');
1053 cn_utils.appindcr(code, ' SET');
1054 cn_utils.indent(code, 1);
1055
1056 -- Prorate Amount, Revenue_amount_split and Non_revenue_amount_split
1057 -- columns for all trx types except invoices.
1058 IF ((x_event_id <> cn_global.inv_event_id) and
1059 (x_event_id <> cn_global.ram_event_id)) THEN
1060 cn_utils.appindcr(code, '(amount, revenue_amount_split, non_revenue_amount_split) = (');
1061 cn_utils.appindcr(code, ' SELECT ');
1062 cn_utils.appindcr(code, ' DECODE(ct.invoice_total, 0, 0, (ct.prorated_amount/ct.invoice_total) * ctsl.amount),');
1063 cn_utils.appindcr(code, ' DECODE(ct.invoice_total, 0, 0, (ct.prorated_amount/ct.invoice_total) * ctsl.revenue_amount_split),');
1064 cn_utils.appindcr(code, ' DECODE(ct.invoice_total, 0, 0, (ct.prorated_amount/ct.invoice_total) * ctsl.non_revenue_amount_split)');
1065 cn_utils.appindcr(code, ' FROM cn_trx ct');
1066 cn_utils.appindcr(code, ' WHERE ct.trx_id = ctsl.trx_id');
1067 --Added by Ashley for MOAC
1068 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id||'),');
1069
1070 cn_utils.appendcr(code);
1071 END IF;
1072
1073 cn_utils.appindcr(code, '(processed_date, rollup_date) = (');
1074 cn_utils.appindcr(code, ' SELECT ct.processed_date, ct.rollup_date');
1075 cn_utils.appindcr(code, ' FROM cn_trx ct');
1076 cn_utils.appindcr(code, ' WHERE ct.trx_id = ctsl.trx_id');
1077 --Added by Ashley for MOAC
1078 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id||'),');
1079
1080 cn_utils.appendcr(code);
1081
1082 cn_utils.appindcr(code, 'processed_period_id = (');
1083 cn_utils.appindcr(code, ' SELECT cp.period_id');
1084 cn_utils.appindcr(code, ' FROM cn_trx ct, cn_acc_period_statuses_v cp');
1085 cn_utils.appindcr(code, ' WHERE ct.trx_id = ctsl.trx_id');
1086 cn_utils.appindcr(code, ' AND ct.processed_date BETWEEN cp.start_date AND cp.end_date');
1087 --Added for MOAC by Ashley
1088 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
1089 cn_utils.appindcr(code, ' AND cp.org_id = ct.org_id),');
1090
1091 cn_utils.appendcr(code);
1092
1093 cn_utils.appindcr(code, 'rollup_period_id = (');
1094 cn_utils.appindcr(code, ' SELECT cp.period_id');
1095 cn_utils.appindcr(code, ' FROM cn_trx ct, cn_acc_period_statuses_v cp');
1096 cn_utils.appindcr(code, ' WHERE ct.trx_id = ctsl.trx_id');
1097 cn_utils.appindcr(code, ' AND ct.rollup_date BETWEEN cp.start_date AND cp.end_date');
1098 --Added for MOAC by Ashley
1099 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
1100 cn_utils.appindcr(code, ' AND cp.org_id = ct.org_id)');
1101
1102 cn_utils.appendcr(code);
1103 cn_utils.unindent(code, 1);
1104
1105 IF (x_event_id = cn_global.ram_event_id) THEN
1106 cn_utils.appindcr(code, 'WHERE ctsl.adj_collection_run_id = x_proc_audit_id');
1107 --Added for MOAC by Ashley
1108 cn_utils.appindcr(code, 'AND ctsl.org_id = '||x_org_id||';');
1109 ELSE
1110 cn_utils.appindcr(code, 'WHERE ctsl.collection_run_id = x_proc_audit_id');
1111 --Added for MOAC by Ashley
1112 cn_utils.appindcr(code, 'AND ctsl.org_id = '||x_org_id||';');
1113 END IF;
1114
1115 -- For clawbacks only, negate the amounts
1116 IF (x_event_id = cn_global.cbk_event_id) THEN
1117 cn_utils.appindcr(code, 'UPDATE cn_trx_sales_lines ctsl');
1118 cn_utils.appindcr(code, ' SET');
1119 cn_utils.indent(code, 1);
1120 cn_utils.appindcr(code, 'amount = amount * -1,');
1121 cn_utils.appindcr(code, 'revenue_amount_split = revenue_amount_split * -1,');
1122 cn_utils.appindcr(code, 'non_revenue_amount_split = non_revenue_amount_split * -1');
1123 cn_utils.unindent(code, 1);
1124 cn_utils.appindcr(code, 'WHERE ctsl.collection_run_id = x_proc_audit_id');
1125 --Added for MAOC By Ashley
1126 cn_utils.appindcr(code, 'AND ctsl.org_id = '||x_org_id||';');
1127 END IF;
1128
1129
1130 -- Update trx_sales_line_update_count variable
1131 cn_utils.appendcr(code);
1132 cn_utils.appindcr(code, 'trx_sales_line_update_count := SQL%ROWCOUNT;');
1133 cn_debug.print_msg('update_sales_lines: Generated UPDATE statement.', 1);
1134 fnd_file.put_line(fnd_file.Log, 'update_sales_lines: Generated UPDATE statement.');
1135 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updated '' || trx_sales_line_update_count || '' records in cn_trx_sales_lines.'');');
1136 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updated '' || trx_sales_line_update_count || '' records in cn_trx_sales_lines.'');');
1137 cn_utils.appendcr(code);
1138
1139 cn_debug.print_msg('update_sales_lines<<', 1);
1140 fnd_file.put_line(fnd_file.Log, 'update_sales_lines<<');
1141 EXCEPTION
1142 WHEN NO_DATA_FOUND THEN
1143 cn_debug.print_msg('update_sales_lines: in exception handler for NO_DATA_FOUND', 1);
1144 fnd_file.put_line(fnd_file.Log, 'update_sales_lines: in exception handler for NO_DATA_FOUND');
1145 RETURN;
1146 END update_sales_lines;
1150 -- Procedure Name
1147
1148
1149
1151 -- update_invoice_total
1152 -- Purpose
1153 -- Updates the invoice_total column in the trx headers table
1154 -- History
1155 -- 15-JUN-93 Devesh Khatu Created
1156
1157 PROCEDURE update_invoice_total (
1158 procedure_name cn_obj_procedures_v.name%TYPE,
1159 code IN OUT NOCOPY cn_utils.code_type,
1160 x_org_id IN NUMBER) IS
1161
1162
1163 BEGIN
1164 l_org_id := x_org_id;
1165 cn_utils.set_org_id(p_org_id => l_org_id);
1166 cn_utils.appendcr(code);
1167 cn_utils.appendcr(code, '--******** UPDATE INVOICE TOTAL ********-- ');
1168
1169 -- Generate the update statement for updating invoice_total.
1170 -- This could not be done when we updated cn_trx earlier since we had not
1171 -- collected lines then
1172 cn_debug.print_msg('update_invoice_total: Generating UPDATE statement.', 1);
1173 fnd_file.put_line(fnd_file.Log, 'update_invoice_total: Generating UPDATE statement.');
1174
1175 cn_utils.set_org_id(p_org_id => l_org_id);
1176 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updating CN_TRX invoice_total.'');');
1177 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updating CN_TRX invoice_total.'');');
1178 cn_utils.appindcr(code, '-- This could not be done when we updated cn_trx earlier ');
1179 cn_utils.appindcr(code, '-- since we had not collected lines then');
1180 cn_utils.appendcr(code);
1181 cn_utils.appindcr(code, 'UPDATE cn_trx ct');
1182 cn_utils.appindcr(code, ' SET invoice_total = (');
1183 cn_utils.appindcr(code, ' SELECT SUM(ctl.extended_amount)');
1184 cn_utils.appindcr(code, ' FROM cn_trx_lines ctl');
1185 cn_utils.appindcr(code, ' WHERE ctl.trx_id = ct.trx_id');
1186 --Added for MOAC by Ashley
1187 cn_utils.appindcr(code, ' AND ctl.org_id = '||x_org_id||')');
1188
1189 cn_utils.appindcr(code, ' WHERE ct.collection_run_id = x_proc_audit_id');
1190 --Added for MOAC by Ashley
1191 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id||';');
1192
1193 cn_utils.appendcr(code);
1194 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Updated cn_trx invoice_total.'');');
1195 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Updated cn_trx invoice_total.'');');
1196 cn_utils.appendcr(code);
1197 cn_debug.print_msg('update_invoice_total: Generated UPDATE statement.', 1);
1198 fnd_file.put_line(fnd_file.Log, 'update_invoice_total: Generated UPDATE statement.');
1199
1200 END update_invoice_total;
1201
1202
1203 -- Procedure Name
1204 -- insert_comm_lines
1205 -- Purpose
1206 -- Generates code to insert into the CN_COMM_LINES_API table
1207 -- History
1208 -- 08-29-95 Amy Erickson Created
1209
1210 PROCEDURE insert_comm_lines (
1211 procedure_name cn_obj_procedures_v.name%TYPE,
1212 x_module_id cn_modules.module_id%TYPE,
1213 x_event_id cn_events.event_id%TYPE,
1214 code IN OUT NOCOPY cn_utils.code_type,
1215 x_org_id IN NUMBER) IS
1216
1217 x_row_count NUMBER := 0;
1218 x_rct_alias cn_obj_tables_v.alias%TYPE;
1219 x_rctl_alias cn_obj_tables_v.alias%TYPE;
1220 x_rctls_alias cn_obj_tables_v.alias%TYPE;
1221 x_cnt_alias cn_obj_tables_v.alias%TYPE;
1222
1223
1224 -- Cursor which finds all user-defined direct mappings for
1225 -- receivables. These are actually implemented as a post-insert
1226 -- update operation
1227
1228 CURSOR header_direct_maps IS
1229 SELECT LOWER(destcol.name) dest_column,
1230 ccm.expression
1231 FROM cn_column_maps ccm,
1232 cn_table_maps tm,
1233 cn_objects destcol
1234 WHERE tm.mapping_type = 'AR'
1235 AND ccm.table_map_id = tm.table_map_id
1236 AND (ccm.column_map_id > 0 -- New mappings to Attribute columns
1237 OR ccm.modified = 'Y') -- User has modified a seeded mapping
1238 AND ccm.expression IS NOT NULL
1239 AND ccm.calc_ext_table_id IS NULL -- Not a foreign-key indirect mapping
1240 AND ccm.update_clause IS NULL -- Not a free-form indirect mapping
1241 AND destcol.object_id = ccm.destination_column_id
1242 AND destcol.table_id = -1008 -- cn_comm_lines_api (exclude any old mappings to cn_trx etc.)
1243 -- Added for MOAC by Ashley
1244 AND tm.org_id = x_org_id
1245 AND ccm.org_id = tm.org_id
1246 AND destcol.org_id = ccm.org_id
1247 ORDER BY destcol.name;
1248
1249 BEGIN
1250 l_org_id := x_org_id;
1251 cn_utils.set_org_id(p_org_id => l_org_id);
1252 cn_utils.appendcr(code);
1253 cn_utils.appendcr(code, '--******** INSERT CN_COMM_LINES_API ********-- ');
1254
1255 cn_debug.print_msg('insert_comm_lines_api>>', 1);
1256 fnd_file.put_line(fnd_file.Log, 'insert_comm_lines_api>>');
1257
1258 -- Generate the insert statement.
1259
1260 cn_debug.print_msg('insert_sales_lines: Generating INSERT statement.', 1);
1261 fnd_file.put_line(fnd_file.Log, 'insert_sales_lines: Generating INSERT statement.');
1262
1263 cn_utils.set_org_id(p_org_id => l_org_id);
1264 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserting into CN_COMM_LINES_API .'');');
1265 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Inserting into CN_COMM_LINES_API .'');');
1266 cn_utils.appendcr(code);
1267 cn_utils.appindcr(code, 'INSERT INTO cn_comm_lines_api (');
1268 cn_utils.indent(code, 1);
1269 cn_utils.appindcr(code, 'comm_lines_api_id,');
1270 cn_utils.appindcr(code, 'conc_batch_id,'); --AE 01-18-96
1271 cn_utils.appindcr(code, 'process_batch_id,'); --AE 01-18-96
1272 cn_utils.appindcr(code, 'trx_type,');
1276 cn_utils.appindcr(code, 'salesrep_id,');
1273 cn_utils.appindcr(code, 'exchange_rate,'); --AE 02-15-96
1274 cn_utils.appindcr(code, 'transaction_currency_code,'); --AE 02-23-96
1275 cn_utils.appindcr(code, 'transaction_amount,');
1277 cn_utils.appindcr(code, 'revenue_class_id,');
1278 cn_utils.appindcr(code, 'processed_date,');
1279 cn_utils.appindcr(code, 'processed_period_id,');
1280 cn_utils.appindcr(code, 'rollup_date,');
1281 -- cn_utils.appindcr(code, 'rollup_period_id,'); No longer needed - dmaskell 26-Nov-99
1282 cn_utils.appindcr(code, 'source_doc_id,');
1283 cn_utils.appindcr(code, 'source_doc_type,');
1284 cn_utils.appindcr(code, 'revenue_type,');
1285 cn_utils.appindcr(code, 'trx_id,');
1286 cn_utils.appindcr(code, 'trx_line_id,');
1287 cn_utils.appindcr(code, 'trx_sales_line_id,');
1288 cn_utils.appindcr(code, 'source_trx_number,');
1289 cn_utils.appindcr(code, 'source_trx_id,');
1290 cn_utils.appindcr(code, 'source_trx_line_id,');
1291 cn_utils.appindcr(code, 'source_trx_sales_line_id,');
1292 cn_utils.appindcr(code, 'line_number,');
1293 cn_utils.appindcr(code, 'quantity,');
1294 cn_utils.appindcr(code, 'customer_id,');
1295 cn_utils.appindcr(code, 'inventory_item_id,');
1296 cn_utils.appindcr(code, 'order_number,');
1297 cn_utils.appindcr(code, 'booked_date,');
1298 cn_utils.appindcr(code, 'invoice_number,');
1299 cn_utils.appindcr(code, 'invoice_date,');
1300 cn_utils.appindcr(code, 'split_pct,');
1301 cn_utils.appindcr(code, 'created_by,');
1302 cn_utils.appindcr(code, 'creation_date,');
1303 cn_utils.appindcr(code, 'last_updated_by,');
1304 cn_utils.appindcr(code, 'last_update_date,');
1305 cn_utils.appindcr(code, 'last_update_login,');
1306 --Added for MOAC by Ashley
1307 cn_utils.appindcr(code, 'org_id,');
1308
1309 cn_utils.strip_prev(code, 1); -- remove trailing comma
1310 cn_utils.appindcr(code, ')');
1311 cn_utils.unindent(code, 1);
1312
1313
1314 -- Generate the SELECT clause for the insert statement
1315
1316 IF (x_event_id = cn_global.ram_event_id) THEN
1317 cn_utils.appindcr(code, 'SELECT /*+ ordered index(CTSL CN_TRX_SALES_LINES_N3) index(CTL CN_TRX_LINES_N4) */');
1318 ELSE
1319 cn_utils.appindcr(code, 'SELECT /*+ ordered index(CTSL CN_TRX_SALES_LINES_N2) index(CTL CN_TRX_LINES_N3) */');
1320 END IF;
1321
1322 cn_utils.indent(code, 1);
1323
1324 cn_utils.appindcr(code, 'cn_comm_lines_api_s.NEXTVAL,');
1325 cn_utils.appindcr(code, 'x_conc_program_id,'); --AE 01-18-96
1326 cn_utils.appindcr(code, 'x_proc_audit_id,'); --AE 01-18-96
1327 cn_utils.appindcr(code, 'ct.trx_type,');
1328 cn_utils.appindcr(code, 'ct.exchange_rate,'); --AE 02-15-96
1329 cn_utils.appindcr(code, 'ct.transaction_currency_code,'); --AE 02-23-96
1330 cn_utils.appindcr(code, 'ctsl.amount,');
1331 cn_utils.appindcr(code, 'ctsl.salesrep_id,');
1332 cn_utils.appindcr(code, 'ctsl.revenue_class_id,');
1333 cn_utils.appindcr(code, 'ctsl.processed_date,');
1334 cn_utils.appindcr(code, 'ctsl.processed_period_id,');
1335 cn_utils.appindcr(code, 'ctsl.rollup_date,');
1336 --cn_utils.appindcr(code, 'ctsl.rollup_period_id,'); --no longer needed - dmaskell 26-Nov-99
1337 cn_utils.appindcr(code, 'ctsl.source_trx_sales_line_id,');
1338 cn_utils.appindcr(code, '''AR'',');
1339 cn_utils.appindcr(code, 'DECODE(ctsl.revenue_amount_percent, 0, DECODE(ctsl.non_revenue_amount_percent, 0, NULL, ''NONREVENUE''), DECODE(ctsl.non_revenue_amount_percent, 0, ''REVENUE'', NULL)),');
1340 cn_utils.appindcr(code, 'ct.trx_id,');
1341 cn_utils.appindcr(code, 'ctl.trx_line_id,');
1342 cn_utils.appindcr(code, 'ctsl.trx_sales_line_id,');
1343 cn_utils.appindcr(code, 'ct.source_trx_number,');
1344 cn_utils.appindcr(code, 'ct.source_trx_id,');
1345 cn_utils.appindcr(code, 'ctl.source_trx_line_id,');
1346 cn_utils.appindcr(code, 'ctsl.source_trx_sales_line_id,');
1347 cn_utils.appindcr(code, 'ctl.line_number,');
1348 cn_utils.appindcr(code, 'ctsl.quantity,');
1349 cn_utils.appindcr(code, 'ct.sold_to_customer_id,');
1350 cn_utils.appindcr(code, 'ctl.inventory_id,');
1351 cn_utils.appindcr(code, 'null,');
1352 cn_utils.appindcr(code, 'null,');
1353 cn_utils.appindcr(code, 'ct.source_trx_number,');
1354 cn_utils.appindcr(code, 'ct.trx_date,');
1355 cn_utils.appindcr(code, 'DECODE(ctsl.revenue_amount_percent, 0, ctsl.non_revenue_amount_percent, ctsl.revenue_amount_percent),');
1356 cn_utils.appindcr(code, 'x_created_by,');
1357 cn_utils.appindcr(code, 'x_creation_date,');
1358 cn_utils.appindcr(code, 'x_last_updated_by,');
1359 cn_utils.appindcr(code, 'x_last_update_date,');
1360 cn_utils.appindcr(code, 'x_last_update_login,');
1361 --Added for MOAC by Ashley
1362 cn_utils.appindcr(code, 'ct.org_id,');
1363
1364 cn_utils.strip_prev(code, 1); -- remove trailing comma
1365 cn_utils.appendcr(code);
1366 cn_utils.unindent(code, 1);
1367
1368 -- Generate FROM clause
1369 cn_utils.appindcr(code, ' FROM cn_trx_sales_lines ctsl,');
1370 cn_utils.appindcr(code, ' cn_trx_lines ctl,');
1371 cn_utils.appindcr(code, ' cn_trx ct');
1372
1373 -- Generate WHERE clause
1374 IF (x_event_id = cn_global.ram_event_id) THEN
1375 cn_utils.appindcr(code, 'WHERE ct.trx_id = ctsl.trx_id' );
1376 cn_utils.appindcr(code, ' AND ctl.trx_line_id = ctsl.trx_line_id' );
1377 cn_utils.appindcr(code, ' AND ct.adj_collection_run_id = x_proc_audit_id' );
1378 cn_utils.appindcr(code, ' AND ctl.adj_collection_run_id = x_proc_audit_id' );
1379 cn_utils.appindcr(code, ' AND ctsl.adj_collection_run_id = x_proc_audit_id' );
1380 --Added for MOAC by Ashley
1384
1381 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
1382 cn_utils.appindcr(code, ' AND ctl.org_id = ct.org_id' );
1383 cn_utils.appindcr(code, ' AND ctsl.org_id = ctl.org_id;' );
1385 ELSE
1386 cn_utils.appindcr(code, 'WHERE ct.trx_id = ctsl.trx_id' );
1387 cn_utils.appindcr(code, ' AND ctl.trx_line_id = ctsl.trx_line_id');
1388 cn_utils.appindcr(code, ' AND ct.collection_run_id = x_proc_audit_id');
1389 cn_utils.appindcr(code, ' AND ctl.collection_run_id = x_proc_audit_id');
1390 cn_utils.appindcr(code, ' AND ctsl.collection_run_id = x_proc_audit_id');
1391 --Added for MOAC by Ashley
1392 cn_utils.appindcr(code, ' AND ct.org_id = '||x_org_id);
1393 cn_utils.appindcr(code, ' AND ctl.org_id = ct.org_id' );
1394 cn_utils.appindcr(code, ' AND ctsl.org_id = ctl.org_id;');
1395 END IF;
1396
1397 cn_utils.appendcr(code);
1398
1399 -- Update comm_lines_api_count variable
1400 cn_utils.appendcr(code);
1401 cn_utils.appindcr(code, 'comm_lines_api_count := SQL%ROWCOUNT;');
1402
1403 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': Inserted '' || comm_lines_api_count || '' records into CN_COMM_LINES_API.'');');
1404 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': Inserted '' || comm_lines_api_count || '' records into CN_COMM_LINES_API.'');');
1405 cn_utils.appendcr(code);
1406
1407
1408 -- Update columns populated by user-defined DIRECT mappings. We do this with a query
1409 -- which joins the cn_comm_lines_api table row back to the AR direct tables
1410 -- (ra_customer_trx etc.)
1411
1412 cn_utils.appindcr(code, '--*** Update columns populated by user-defined DIRECT mappings');
1413
1414 -- Check first for empty cursor
1415
1416 x_row_count := 0;
1417 FOR i IN header_direct_maps LOOP
1418 x_row_count := SQL%ROWCOUNT;
1419 IF x_row_count > 0 THEN EXIT;
1420 END IF;
1421 END LOOP;
1422
1423 IF x_row_count > 0 THEN --cursor was not empty
1424
1425 -- Get aliases of join tables
1426
1427 SELECT LOWER(NVL(alias,name)) INTO x_cnt_alias
1428 FROM cn_obj_tables_v
1429 WHERE name = 'CN_NOT_TRX' AND org_id = x_org_id; --Added for MOAC by Ashley
1430
1431 SELECT LOWER(NVL(alias,name)) INTO x_rct_alias
1432 FROM cn_obj_tables_v
1433 WHERE name = 'RA_CUSTOMER_TRX' AND org_id = x_org_id; --Added for MOAC by Ashley
1434
1435 SELECT LOWER(NVL(alias,name)) INTO x_rctl_alias
1436 FROM cn_obj_tables_v
1437 WHERE name = 'RA_CUSTOMER_TRX_LINES' AND org_id = x_org_id; --Added for MOAC by Ashley
1438
1439 SELECT LOWER(NVL(alias,name)) INTO x_rctls_alias
1440 FROM cn_obj_tables_v
1441 WHERE name = 'RA_CUST_TRX_LINE_SALESREPS' AND org_id = x_org_id; --Added for MOAC by Ashley
1442
1443 cn_utils.appindcr(code, 'UPDATE cn_comm_lines_api api');
1444 cn_utils.appindcr(code, 'SET');
1445 cn_utils.indent(code, 1);
1446 cn_utils.appindcr(code, '(');
1447 cn_utils.appindcr(code, '--*** Direct Mapping Destination Columns');
1448 FOR i IN header_direct_maps LOOP
1449 cn_utils.appindcr(code, i.dest_column || ',');
1450 END LOOP;
1451 cn_utils.strip_prev(code, 1); -- remove trailing comma
1452
1453 cn_utils.appindcr(code, ') = (');
1454 cn_utils.indent(code, 1);
1455 cn_utils.appindcr(code, 'SELECT');
1456 cn_utils.indent(code, 1);
1457
1458 cn_utils.appindcr(code, '--*** Direct Mapping Source Expressions');
1459 FOR i IN header_direct_maps LOOP
1460 cn_utils.appindcr(code, i.expression || ',');
1461 END LOOP;
1462 cn_utils.unindent(code, 1);
1463 cn_utils.strip_prev(code, 1); -- remove trailing comma
1464
1465 cn_utils.appendcr(code);
1466 cn_utils.appindcr(code, 'FROM ra_customer_trx ' || x_rct_alias || ',');
1467 cn_utils.appindcr(code, ' ra_customer_trx_lines ' || x_rctl_alias || ',');
1468 cn_utils.appindcr(code, ' ra_cust_trx_line_salesreps ' || x_rctls_alias);
1469 cn_utils.appindcr(code, 'WHERE '||x_rct_alias||'.customer_trx_id = api.source_trx_id');
1470 cn_utils.appindcr(code, ' AND '||x_rctls_alias||'.cust_trx_line_salesrep_id = api.source_doc_id');
1471 cn_utils.appindcr(code, ' AND '||x_rctl_alias||'.customer_trx_line_id = '||x_rctls_alias||'.customer_trx_line_id');
1472 --Added for MOAC by Ashley
1473 cn_utils.appindcr(code, ' AND '||x_rct_alias||'.org_id = '||x_org_id);
1474 cn_utils.appindcr(code, ' AND '||x_rctl_alias||'.org_id = '||x_rct_alias||'.org_id');
1475 cn_utils.appindcr(code, ' AND '||x_rctls_alias||'.org_id = '||x_rctl_alias||'.org_id)');
1476
1477 cn_utils.appendcr(code);
1478
1479 cn_utils.unindent(code, 3);
1480 cn_utils.appindcr(code, 'WHERE api.process_batch_id = x_proc_audit_id');
1481 --Added by Ashley for MOAC
1482 cn_utils.appindcr(code, 'AND api.org_id = '||x_org_id||';');
1483
1484 cn_utils.appendcr(code);
1485 cn_utils.appindcr(code, 'comm_lines_api_update_count := SQL%ROWCOUNT;');
1486
1487 cn_utils.appindcr(code, 'cn_message_pkg.debug(''' || procedure_name || ': For user DIRECT mappings, updated '' || comm_lines_api_update_count || '' records in CN_COMM_LINES_API.'');');
1488 cn_utils.appindcr(code, 'fnd_file.put_line(fnd_file.Log, ''' || procedure_name || ': For user DIRECT mappings, updated '' || comm_lines_api_update_count || '' records in CN_COMM_LINES_API.'');');
1489 cn_utils.appendcr(code);
1490 END IF;
1491
1492 EXCEPTION
1493 WHEN NO_DATA_FOUND THEN
1494 cn_debug.print_msg('insert_comm_lines: in exception handler for NO_DATA_FOUND', 1);
1495 fnd_file.put_line(fnd_file.Log, 'insert_comm_lines: in exception handler for NO_DATA_FOUND');
1499 END cn_collection_ar_gen;
1496 RETURN;
1497 END insert_comm_lines;
1498
1500