[Home] [Help]
PACKAGE BODY: APPS.AR_CMGT_DATA_POINTS_PKG
Source
1 Package BODY AR_CMGT_DATA_POINTS_PKG AS
2 /* $Header: ARCMGDPB.pls 120.31.12010000.2 2008/09/24 15:08:43 mraymond ship $ */
3
4 pg_wf_debug VARCHAR2(1) := ar_cmgt_util.get_wf_debug_flag;
5
6 PROCEDURE build_case_folder_details(
7 p_case_folder_id IN NUMBER,
8 p_data_point_id IN NUMBER,
9 p_data_point_value IN VARCHAR2 default NULL,
10 p_mode IN VARCHAR2 default 'CREATE',
11 p_error_msg OUT nocopy VARCHAR2,
12 p_resultout OUT nocopy VARCHAR2) AS
13
14 l_included_in_check_list VARCHAR2(1) := 'N';
15 l_cnt NUMBER;
16 l_errmsg VARCHAR2(4000);
17 l_resultout VARCHAR2(1);
18 BEGIN
19 IF pg_wf_debug = 'Y'
20 THEN
21 -- ar_cmgt_util.wf_debug(p_case_folder_id,
22 -- 'ar_cmgt_data_points_pkg.build_case_folder_details()+');
23 ar_cmgt_util.wf_debug(p_case_folder_id,
24 'DP:' || p_data_point_id || ' = ' || p_data_point_value);
25 END IF;
26
27 p_resultout := 0;
28
29 -- this will generate case folder details of type 'CASE'
30 IF p_mode = 'CREATE'
31 THEN
32 AR_CMGT_CONTROLS.populate_case_folder_details(
33 p_case_folder_id => p_case_folder_id,
34 p_data_point_id => p_data_point_id,
35 p_data_point_value => p_data_point_value,
36 p_included_in_check_list => l_included_in_check_list,
37 p_errmsg => l_errmsg,
38 p_resultout => l_resultout);
39
40 -- this will generate case folder details of type 'DATA'
41 IF g_data_case_folder_exists = 'Y'
42 THEN
43 AR_CMGT_CONTROLS.UPDATE_CASE_FOLDER_DETAILS (
44 p_case_folder_id => g_data_case_folder_id,
45 p_data_point_id => p_data_point_id,
46 p_data_point_value => p_data_point_value,
47 p_score => NULL,
48 p_errmsg => l_errmsg,
49 p_resultout => l_resultout);
50 ELSIF g_data_case_folder_exists = 'N'
51 THEN
52 AR_CMGT_CONTROLS.populate_case_folder_details(
53 p_case_folder_id => g_data_case_folder_id,
54 p_data_point_id => p_data_point_id,
55 p_data_point_value => p_data_point_value,
56 p_included_in_check_list => l_included_in_check_list,
57 p_errmsg => l_errmsg,
58 p_resultout => l_resultout);
59 END IF;
60 ELSIF p_mode = 'REFRESH'
61 THEN
62 AR_CMGT_CONTROLS.UPDATE_CASE_FOLDER_DETAILS (
63 p_case_folder_id => p_case_folder_id,
64 p_data_point_id => p_data_point_id,
65 p_data_point_value => p_data_point_value,
66 p_score => NULL,
67 p_errmsg => l_errmsg,
68 p_resultout => l_resultout);
69 END IF;
70
71 -- IF pg_wf_debug = 'Y'
72 -- THEN
73 -- ar_cmgt_util.wf_debug(p_case_folder_id,
74 -- 'ar_cmgt_data_points_pkg.build_case_folder_details()-');
75 -- END IF;
76
77 EXCEPTION
78 WHEN OTHERS THEN
79 p_resultout := 1;
80 p_error_msg := 'Unable to create/Update records in AR_CMGT_CF_DTLS for Data Point Id: '||p_data_point_id;
81 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
82 END build_case_folder_details;
83
84 PROCEDURE build_case_folder_adp_details(
85 p_case_folder_detail_id IN NUMBER,
86 p_case_folder_id IN NUMBER,
87 p_data_point_id IN NUMBER,
88 p_sequence_number IN NUMBER,
89 p_parent_data_point_id IN NUMBER,
90 p_parent_cf_detail_id IN NUMBER,
91 p_data_point_value IN VARCHAR2 default NULL,
92 p_mode IN VARCHAR2 default 'CREATE',
93 x_error_msg OUT nocopy VARCHAR2,
94 x_resultout OUT nocopy VARCHAR2)
95 AS
96 l_included_in_check_list VARCHAR2(1) := 'N';
97 l_cnt NUMBER;
98 l_errmsg VARCHAR2(4000);
99 l_resultout VARCHAR2(1);
100 BEGIN
101 IF pg_wf_debug = 'Y'
102 THEN
103 ar_cmgt_util.wf_debug(p_case_folder_id,
104 'ar_cmgt_data_points_pkg.build_case_folder_adp_details()+');
105 -- ar_cmgt_util.wf_debug(p_case_folder_id,
106 -- p_data_point_id || '=' || p_data_point_value);
107 END IF;
108
109 x_resultout := 0;
110
111 -- this will generate case folder details of type 'CASE'
112 IF p_mode = 'CREATE'
113 THEN
114 AR_CMGT_CONTROLS.populate_case_folder_details(
115 p_case_folder_id => p_case_folder_id,
116 p_data_point_id => p_data_point_id,
117 p_data_point_value => p_data_point_value,
118 p_included_in_check_list => l_included_in_check_list,
119 p_errmsg => x_error_msg,
120 p_resultout => x_resultout);
121
122 -- this will generate case folder details of type 'DATA'
123 IF g_data_case_folder_exists = 'Y'
124 THEN
125 AR_CMGT_CONTROLS.UPDATE_CASE_FOLDER_DETAILS (
126 p_case_folder_id => g_data_case_folder_id,
127 p_data_point_id => p_data_point_id,
128 p_data_point_value => p_data_point_value,
129 p_score => NULL,
130 p_errmsg => x_error_msg,
131 p_resultout => x_resultout);
132 ELSIF g_data_case_folder_exists = 'N'
133 THEN
134 AR_CMGT_CONTROLS.populate_case_folder_details(
135 p_case_folder_id => g_data_case_folder_id,
136 p_data_point_id => p_data_point_id,
137 p_data_point_value => p_data_point_value,
138 p_included_in_check_list => l_included_in_check_list,
139 p_errmsg => x_error_msg,
140 p_resultout => x_resultout);
141 END IF;
142 ELSIF p_mode = 'REFRESH'
143 THEN
144 AR_CMGT_CONTROLS.UPDATE_CASE_FOLDER_DETAILS (
145 p_case_folder_id => p_case_folder_id,
146 p_data_point_id => p_data_point_id,
147 p_data_point_value => p_data_point_value,
148 p_score => NULL,
149 p_errmsg => x_error_msg,
150 p_resultout => x_resultout);
151 END IF;
152
153 IF pg_wf_debug = 'Y'
154 THEN
155 ar_cmgt_util.wf_debug(p_case_folder_id,
156 'ar_cmgt_data_points_pkg.build_case_folder_adp_details()-');
157 -- ar_cmgt_util.wf_debug(p_case_folder_id,
158 -- p_data_point_id || '=' || p_data_point_value);
159 END IF;
160 EXCEPTION
161 WHEN OTHERS THEN
162 x_resultout := 1;
163 x_error_msg := 'Unable to create/Update records in AR_CMGT_CF_DTLS for Data Point Id: '||p_data_point_id;
164 ar_cmgt_util.wf_debug(p_case_folder_id, x_error_msg);
165 END build_case_folder_adp_details;
166
167 PROCEDURE GetDeductionDataPoints ( -- bug 3691676
168 p_credit_request_id IN NUMBER,
169 p_case_folder_id IN NUMBER,
170 p_period IN NUMBER,
171 p_party_id IN NUMBER,
172 p_cust_account_id IN NUMBER,
173 p_site_use_id IN NUMBER,
174 p_analysis_level IN VARCHAR2,
175 p_org_id IN NUMBER,
176 p_mode IN VARCHAR2 default 'CREATE',
177 p_limit_currency IN VARCHAR2,
178 p_exchange_rate_type IN VARCHAR2,
179 p_global_exposure_flag IN VARCHAR2,
180 p_error_msg OUT NOCOPY VARCHAR2,
181 p_resultout OUT NOCOPY VARCHAR2 ) IS
182
183 l_deduction_amount NUMBER;
184 l_deduction_count NUMBER;
185 BEGIN
186 IF pg_wf_debug = 'Y'
187 THEN
188 ar_cmgt_util.wf_debug(p_case_folder_id,
189 'ar_cmgt_data_points_pkg.get_deduction_data_points()+');
190 END IF;
191 -- first get the deduction amount
192 p_resultout := 0;
193 IF p_analysis_level = 'P'
194 THEN
195 BEGIN
196 SELECT sum(amount_settled), sum(ded_count)
197 INTO l_deduction_amount, l_deduction_count
198 FROM (
199 SELECT round(gl_currency_api.convert_amount(currency_code,
200 p_limit_currency, sysdate,
201 p_exchange_rate_type,
202 sum(amount_settled)),2) amount_settled,
203 count(*) ded_count
204 FROM ozf_claims_all
205 WHERE status_code = 'CLOSED'
206 AND claim_class = 'DEDUCTION'
207 AND settled_date >= ADD_MONTHS(sysdate,(-p_period))
208 AND cust_account_id IN (
209 select cust_account_id
210 FROM hz_cust_accounts
211 WHERE party_id in
212 ( SELECT child_id
213 from hz_hierarchy_nodes
214 where parent_object_type = 'ORGANIZATION'
215 and parent_table_name = 'HZ_PARTIES'
216 and child_object_type = 'ORGANIZATION'
217 and parent_id = p_party_id
218 and effective_start_date <= sysdate
219 and effective_end_date >= sysdate
220 and hierarchy_type =
221 FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
222 and g_source_name <> 'LNS'
223 UNION
224 select p_party_id from dual
225 UNION
226 select hz_party_id
227 from LNS_LOAN_PARTICIPANTS_V
228 where loan_id = g_source_id
229 and participant_type_code = 'COBORROWER'
230 and g_source_name = 'LNS'
231 and (end_date_active is null OR
232 (sysdate between start_date_active and end_date_active)
233 )
234 ))
235 AND currency_code IN ( SELECT CURRENCY FROM
236 ar_cmgt_curr_usage_gt
237 WHERE nvl(credit_request_id,p_credit_request_id)
238 = p_credit_request_id)
239 group by currency_code);
240 EXCEPTION
241 WHEN NO_DATA_FOUND
242 THEN
243 l_deduction_amount := null;
244 l_deduction_count := null;
245 WHEN OTHERS THEN
246 p_error_msg := 'Error While getting Deduction for Party, SqlError: '||sqlerrm;
247 p_resultout := 1;
248 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
249 return;
250 END;
251 ELSIF p_analysis_level = 'A'
252 THEN
253 BEGIN
254 SELECT sum(amount_settled), sum(ded_count)
255 INTO l_deduction_amount, l_deduction_count
256 FROM (
257 SELECT round(gl_currency_api.convert_amount(currency_code,
258 p_limit_currency, sysdate,
259 p_exchange_rate_type,
260 sum(amount_settled)),2) amount_settled,
261 count(*) ded_count
262 FROM ozf_claims_all
263 WHERE status_code = 'CLOSED'
264 AND claim_class = 'DEDUCTION'
265 AND cust_account_id = p_cust_account_id
266 AND org_id = decode(p_global_exposure_flag,'Y', org_id, 'N',
267 decode(p_org_id,null, org_id, p_org_id), null,
268 decode(p_org_id,null, org_id, p_org_id))
269 AND currency_code IN ( SELECT CURRENCY FROM
270 ar_cmgt_curr_usage_gt
271 WHERE nvl(credit_request_id,p_credit_request_id)
272 = p_credit_request_id)
273 AND settled_date >= ADD_MONTHS(sysdate,(-p_period))
274 group by currency_code );
275 EXCEPTION
276 WHEN NO_DATA_FOUND
277 THEN
278 l_deduction_amount := null;
279 l_deduction_count := null;
280 WHEN OTHERS THEN
281 p_error_msg := 'Error While getting Deduction for Account, SqlError: '||sqlerrm;
282 p_resultout := 1;
283 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
284 return;
285 END;
286 ELSIF p_analysis_level = 'S'
287 THEN
288 BEGIN
289 SELECT sum(amount_settled), sum(ded_count)
290 INTO l_deduction_amount, l_deduction_count
291 FROM (
292 SELECT round(gl_currency_api.convert_amount(currency_code,
293 p_limit_currency, sysdate,
294 p_exchange_rate_type,
295 sum(amount_settled)),2) amount_settled,
296 count(*) ded_count
297 FROM ozf_claims_all
298 WHERE status_code = 'CLOSED'
299 AND claim_class = 'DEDUCTION'
300 AND settled_date >= ADD_MONTHS(sysdate,(-p_period))
301 AND cust_account_id = p_cust_account_id
302 AND cust_billto_acct_site_id = p_site_use_id
303 AND currency_code IN ( SELECT CURRENCY FROM
304 ar_cmgt_curr_usage_gt
305 WHERE nvl(credit_request_id,p_credit_request_id)
306 = p_credit_request_id)
307 group by currency_code );
308 EXCEPTION
309 WHEN NO_DATA_FOUND
310 THEN
311 l_deduction_amount := null;
312 l_deduction_count := null;
313 WHEN OTHERS THEN
314 p_error_msg := 'Error While getting Deduction for Site, SqlError: '||sqlerrm;
315 p_resultout := 1;
316 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
317 return;
318 END;
319 END IF;
320 -- Now call build case folder to insert into case folder details
321 build_case_folder_details(
322 p_case_folder_id => p_case_folder_id,
323 p_data_point_id => 211, -- deduction amount
324 p_data_point_value => fnd_number.number_to_canonical(l_deduction_amount),
325 p_mode => p_mode,
326 p_error_msg => p_error_msg,
327 p_resultout => p_resultout);
328 IF p_resultout <> 0
329 THEN
330 return;
331 END IF;
332 build_case_folder_details(
333 p_case_folder_id => p_case_folder_id,
334 p_data_point_id => 212, -- deduction count
335 p_data_point_value => l_deduction_count,
336 p_mode => p_mode,
337 p_error_msg => p_error_msg,
338 p_resultout => p_resultout);
339 IF p_resultout <> 0
340 THEN
341 return;
342 END IF;
343 IF pg_wf_debug = 'Y'
344 THEN
345 ar_cmgt_util.wf_debug(p_case_folder_id,
346 'ar_cmgt_data_points_pkg.get_deduction_data_points()-');
347 END IF;
348
349 END;
350
351
352 PROCEDURE GetManualDataPoints(
353 p_credit_request_id IN NUMBER,
354 p_case_folder_id IN NUMBER,
355 p_check_list_id IN NUMBER,
356 p_mode IN VARCHAR2 default 'CREATE',
357 x_error_msg OUT NOCOPY VARCHAR2,
358 x_resultout OUT NOCOPY VARCHAR2) IS
359
360
361 BEGIN
362 IF pg_wf_debug = 'Y'
363 THEN
364 ar_cmgt_util.wf_debug(p_case_folder_id,
365 'ar_cmgt_data_points_pkg.getmanualdatapoints()+');
366 END IF;
367
368 x_resultout := 0;
369 ocm_add_data_points.getadditionalDataPoints (
370 p_credit_request_id => p_credit_request_id,
371 p_case_folder_id => p_case_folder_id,
372 p_mode => p_mode,
373 p_error_msg => x_error_msg,
374 p_resultout => x_resultout );
375
376 IF pg_wf_debug = 'Y'
377 THEN
378 ar_cmgt_util.wf_debug(p_case_folder_id,
379 'ar_cmgt_data_points_pkg.getmanualdatapoints()-');
380 END IF;
381 END GetManualDataPoints;
382
383
384 PROCEDURE GetAnalyticalData (
385 p_credit_request_id IN NUMBER,
386 p_party_id IN NUMBER,
387 p_cust_account_id IN NUMBER,
388 p_site_use_id IN NUMBER,
389 p_case_folder_id IN NUMBER,
390 p_analysis_level IN VARCHAR2,
391 p_org_id IN NUMBER,
392 p_period IN NUMBER,
393 p_global_exposure_flag IN VARCHAR2,
394 p_limit_currency IN VARCHAR2,
395 p_exchange_rate_type IN VARCHAR2,
396 p_mode IN VARCHAR2 default 'CREATE',
397 p_errormsg out nocopy VARCHAR2,
398 p_resultout out nocopy VARCHAR2) IS
399
400 CURSOR c_currency IS
401 SELECT currency from ar_cmgt_curr_usage_gt;
402
403 l_largest_inv_date ar_trx_summary.largest_inv_date%type;
404 l_largest_inv_amount ar_trx_summary.largest_inv_amount%type;
405 l_final_inv_amount ar_trx_summary.largest_inv_amount%type;
406 l_final_inv_date ar_trx_summary.largest_inv_date%type;
407 l_high_watermark_date ar_trx_summary.op_bal_high_watermark_date%type;
408 l_high_watermark ar_trx_summary.op_bal_high_watermark%type;
409 l_final_high_watermark ar_trx_summary.op_bal_high_watermark%type;
410 l_final_high_watermark_date ar_trx_summary.as_of_date%type;
411 l_last_payment_amount ar_trx_bal_summary.last_payment_amount%type;
412 l_last_payment_date ar_trx_bal_summary.last_payment_date%type;
413 l_last_payment_number ar_trx_bal_summary.last_payment_number%type;
414 l_last_payment_currency ar_trx_bal_summary.currency%type;
415 l_last_payment_amount_conv ar_trx_bal_summary.last_payment_amount%type;
416
417 l_result VARCHAR2(150); -- 6513911
418
419 l_party_sql VARCHAR2(4000) :='select LARGEST_INV_DATE,
420 largest_inv_amount
421 from ( select as_of_date LARGEST_INV_DATE,
422 gl_currency_api.convert_amount(currency,
423 :1,sysdate,
424 :2,
425 largest_inv_amount)largest_inv_amount,
426 RANK() OVER (PARTITION BY currency
427 ORDER BY largest_inv_amount desc,
428 largest_inv_cust_trx_id desc) rank_amount
429 FROM AR_TRX_SUMMARY
430 where cust_account_id in (
431 select cust_account_id
432 FROM hz_cust_accounts
433 WHERE party_id in
434 ( SELECT child_id
435 from hz_hierarchy_nodes
436 where parent_object_type = ''ORGANIZATION''
437 and parent_table_name = ''HZ_PARTIES''
438 and child_object_type = ''ORGANIZATION''
439 and parent_id = :3
440 and effective_start_date <= sysdate
441 and effective_end_date >= sysdate
442 and hierarchy_type =
443 FND_PROFILE.VALUE(''AR_CMGT_HIERARCHY_TYPE'')
444 and :4 <> ''LNS''
445 union select :5 from dual
446 union
447 select hz_party_id
448 from LNS_LOAN_PARTICIPANTS_V
449 where loan_id = :6
450 and participant_type_code = ''COBORROWER''
451 and :7 = ''LNS''
452 and (end_date_active is null OR
453 (sysdate between start_date_active and end_date_active)
454 )
455 ))
456 and currency = :8
457 and largest_inv_cust_trx_id is not null
458 and as_of_date >= ADD_MONTHS(sysdate,(-:9)) )
459 Where rank_amount = 1 ';
460
461 l_account_sql VARCHAR2(4000) :='select LARGEST_INV_DATE,
462 largest_inv_amount
463 from ( select as_of_date LARGEST_INV_DATE,
464 gl_currency_api.convert_amount(currency,
465 :1,sysdate,
466 :2,
467 largest_inv_amount)largest_inv_amount,
468 RANK() OVER (PARTITION BY cust_account_id,currency
469 ORDER BY largest_inv_amount desc,
470 largest_inv_cust_trx_id desc) rank_amount
471 FROM AR_TRX_SUMMARY
472 where cust_account_id = :3
473 and org_id = decode(:4,''Y'', org_id, ''N'',
474 decode(:5,null, org_id, :6), null,
475 decode(:7,null, org_id, :8))
476 and currency = :9
477 and largest_inv_cust_trx_id is not null
478 and as_of_date >= ADD_MONTHS(sysdate,(-:10)) )
479 Where rank_amount = 1';
480
481 l_site_sql VARCHAR2(4000) :='select LARGEST_INV_DATE,
482 largest_inv_amount
483 from ( select as_of_date LARGEST_INV_DATE,
484 gl_currency_api.convert_amount(currency,
485 :1,sysdate,
486 :2,
487 largest_inv_amount)largest_inv_amount,
488 RANK() OVER (PARTITION BY cust_account_id, site_use_id,currency
489 ORDER BY largest_inv_amount desc,
490 largest_inv_cust_trx_id desc) rank_amount
491 FROM AR_TRX_SUMMARY
492 where cust_account_id = :3
493 and site_use_id = :4
494 and currency = :5
495 and largest_inv_cust_trx_id is not null
496 and as_of_date >= ADD_MONTHS(sysdate,(-:6)) )
497 Where rank_amount = 1 ';
498
499 /* Not using Analytical function to derive high credit amount as
500 part of bug fix 3557539
501 l_high_credit_party_sql VARCHAR2(4000) :='select op_bal_high_watermark_date,
502 op_bal_high_watermark
503 from ( select as_of_date op_bal_high_watermark_date,
504 gl_currency_api.convert_amount(currency,
505 :1,sysdate,
506 :2,
507 op_bal_high_watermark)op_bal_high_watermark,
508 RANK() OVER (PARTITION BY currency
509 ORDER BY op_bal_high_watermark desc,
510 largest_inv_cust_trx_id desc) high_amount
511 FROM AR_TRX_SUMMARY
512 where cust_account_id in (
513 select cust_account_id
514 FROM hz_cust_accounts
515 WHERE party_id in
516 ( SELECT child_id
517 from hz_hierarchy_nodes
518 where parent_object_type = ''ORGANIZATION''
519 and parent_table_name = ''HZ_PARTIES''
520 and child_object_type = ''ORGANIZATION''
521 and parent_id = :3
522 and effective_start_date <= sysdate
523 and effective_end_date >= sysdate
524 and hierarchy_type =
525 FND_PROFILE.VALUE(''AR_CMGT_HIERARCHY_TYPE'')
526 union select :4 from dual
527 ))
528 and currency = :5
529 and largest_inv_cust_trx_id is not null
530 and as_of_date >= ADD_MONTHS(sysdate,(-:6)) )
531 Where high_amount = 1';
532
533 l_high_credit_account_sql VARCHAR2(4000) :='select op_bal_high_watermark_date,
534 op_bal_high_watermark
535 from ( select as_of_date op_bal_high_watermark_date,
536 gl_currency_api.convert_amount(currency,
537 :1,sysdate,
538 :2,
539 op_bal_high_watermark)op_bal_high_watermark,
540 RANK() OVER (PARTITION BY cust_account_id,currency,org_id
541 ORDER BY op_bal_high_watermark desc,
542 largest_inv_cust_trx_id desc) high_amount
543 FROM AR_TRX_SUMMARY
544 where cust_account_id = :3
545 and org_id = decode(:4,''Y'', org_id, ''N'',
546 decode(:5,null, org_id, :6), null,
547 decode(:7,null, org_id, :8))
548 and currency = :9
549 and largest_inv_cust_trx_id is not null
550 and as_of_date >= ADD_MONTHS(sysdate,(-:10)) )
551 Where high_amount = 1';
552
553 l_high_credit_site_sql VARCHAR2(4000) :='select op_bal_high_watermark_date,
554 op_bal_high_watermark
555 from ( select as_of_date op_bal_high_watermark_date,
556 gl_currency_api.convert_amount(currency,
557 :1,sysdate,
558 :2,
559 op_bal_high_watermark)op_bal_high_watermark,
560 RANK() OVER (PARTITION BY cust_account_id, site_use_id,currency
561 ORDER BY op_bal_high_watermark desc,
562 largest_inv_cust_trx_id desc) high_amount
563 FROM AR_TRX_SUMMARY
564 where cust_account_id = :3
565 and site_use_id = :4
566 and currency = :5
567 and largest_inv_cust_trx_id is not null
568 and as_of_date >= ADD_MONTHS(sysdate,(-:6)) )
569 Where high_amount = 1';
570
571 ************************************************************************************/
572
573 BEGIN
574 IF pg_wf_debug = 'Y'
575 THEN
576 ar_cmgt_util.wf_debug(p_case_folder_id,
577 'ar_cmgt_data_points_pkg.getanalyticaldata()+');
578 END IF;
579
580 p_resultout := 0;
581 -- get largest in amount
582 FOR c_currency_rec IN c_currency
583 LOOP
584 BEGIN
585 IF p_analysis_level = 'P'
586 THEN
587 EXECUTE IMMEDIATE l_party_sql INTO
588 l_largest_inv_date,
589 l_largest_inv_amount
590 USING p_limit_currency,p_exchange_rate_type,
591 p_party_id, g_source_name, p_party_id, g_source_id,
592 g_source_name, c_currency_rec.currency, p_period;
593
594 ELSIF p_analysis_level = 'A'
595 THEN
596 EXECUTE IMMEDIATE l_account_sql INTO
597 l_largest_inv_date,
598 l_largest_inv_amount
599 USING p_limit_currency,p_exchange_rate_type,
600 p_cust_account_id,p_global_exposure_flag,p_org_id,
601 p_org_id, p_org_id, p_org_id,
602 c_currency_rec.currency, p_period;
603 ELSIF p_analysis_level = 'S'
604 THEN
605 EXECUTE IMMEDIATE l_site_sql INTO
606 l_largest_inv_date,
607 l_largest_inv_amount
608 USING p_limit_currency,p_exchange_rate_type,
609 p_cust_account_id,p_site_use_id,
610 c_currency_rec.currency, p_period;
611 END IF;
612 EXCEPTION
613 WHEN NO_DATA_FOUND THEN
614 l_largest_inv_date := null;
615 l_largest_inv_amount := null;
616
617 END;
618 IF l_largest_inv_date IS NOT NULL AND l_largest_inv_amount IS NOT NULL
619 THEN
620 IF nvl(l_final_inv_amount,0) < l_largest_inv_amount
621 THEN
622 l_final_inv_amount := l_largest_inv_amount;
623 l_final_inv_date := l_largest_inv_date;
624 END IF;
625 END IF;
626
627 END LOOP;
628
629 /*-- repaet the same process for High water mark
630 FOR c_currency_rec IN c_currency
631 LOOP
632 BEGIN
633 IF p_analysis_level = 'P'
634 THEN
635
636 EXECUTE IMMEDIATE l_high_credit_party_sql INTO
637 l_high_watermark_date,
638 l_high_watermark
639 USING p_limit_currency,p_exchange_rate_type,
640 p_party_id, p_party_id,c_currency_rec.currency, p_period;
641
642 ELSIF p_analysis_level = 'A'
643 THEN
644 EXECUTE IMMEDIATE l_high_credit_account_sql INTO
645 l_high_watermark_date,
646 l_high_watermark
647 USING p_limit_currency,p_exchange_rate_type,
648 p_cust_account_id,p_global_exposure_flag,p_org_id,
649 p_org_id, p_org_id, p_org_id,
650 c_currency_rec.currency, p_period;
651
652 ELSIF p_analysis_level = 'S'
653 THEN
654 EXECUTE IMMEDIATE l_high_credit_site_sql INTO
655 l_high_watermark_date,
656 l_high_watermark
657 USING p_limit_currency,p_exchange_rate_type,
658 p_cust_account_id,p_site_use_id,
659 c_currency_rec.currency, p_period;
660 END IF;
661 EXCEPTION
662 WHEN NO_DATA_FOUND THEN
663 l_high_watermark_date := null;
664 l_high_watermark := null;
665
666 END;
667 IF l_high_watermark_date IS NOT NULL AND l_high_watermark IS NOT NULL
668 THEN
669 IF l_final_high_watermark < l_high_watermark
670 THEN
671 l_final_high_watermark := l_high_watermark;
672 l_final_high_watermark_date := l_high_watermark_date;
673 END IF;
674 END IF;
675
676 END LOOP; */
677 -- Get the High Watermark and date (Bug fix 3557539)
678 -- Not using the above analytical select statement
679 IF p_analysis_level = 'P'
680 THEN
681 BEGIN
682
683 /* 6513911 - revised sql to not require all currencies
684 This code now selects the converted amount and date
685 (max) at one time, then substr them out to individual
686 fields for the datapoint(s). Incidentally, the original
687 logic returned the raw amount (in AR_TRX_SUMMARY currency)
688 rather than the converted amount -- I considered this a bug
689 and now return the converted amount (to CF currency) */
690 SELECT max(ltrim(
691 to_char( gl_currency_api.convert_amount(currency,
692 p_limit_currency,sysdate,
693 p_exchange_rate_type,
694 op_bal_high_watermark),
695 '0999999999999999999D00')) || '~' ||
696 to_char(as_of_date, 'YYYYMMDD'))
697 INTO l_result
698 FROM ar_trx_summary
699 WHERE op_bal_high_watermark IS NOT NULL
700 AND as_of_date >= ADD_MONTHS(sysdate,(-p_period))
701 AND cust_account_id IN (
702 SELECT cust_account_id
703 FROM hz_cust_accounts
704 WHERE party_id in
705 ( SELECT child_id
706 FROM hz_hierarchy_nodes
707 WHERE parent_object_type = 'ORGANIZATION'
708 AND parent_table_name = 'HZ_PARTIES'
709 AND child_object_type = 'ORGANIZATION'
710 AND parent_id = p_party_id
711 AND effective_start_date <= sysdate
712 AND effective_end_date >= sysdate
713 AND hierarchy_type =
714 FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
715 AND g_source_name <> 'LNS'
716 UNION
717 SELECT p_party_id FROM DUAL
718 UNION
719 SELECT hz_party_id
720 FROM LNS_LOAN_PARTICIPANTS_V
721 WHERE loan_id = g_source_id
722 AND participant_type_code = 'COBORROWER'
723 AND g_source_name = 'LNS'
724 AND (end_date_active is null OR
725 (sysdate between start_date_active
726 and end_date_active))))
727 AND currency IN ( SELECT CURRENCY
728 FROM ar_cmgt_curr_usage_gt
729 WHERE nvl(credit_request_id,p_credit_request_id)
730 = p_credit_request_id);
731
732 /* Now extract results, '~' is separator */
733 l_final_high_watermark := to_number(substr(l_result,0,instr(l_result,'~')-1));
734 l_final_high_watermark_date := to_date(substr(l_result,instr(l_result,'~')+1),'YYYYMMDD');
735
736 EXCEPTION
737 WHEN NO_DATA_FOUND THEN
738 l_final_high_watermark := NULL;
739 l_final_high_watermark_date := NULL;
740 when others THEN
741 p_errormsg := 'Error While getting High Credit Amount for Party, SqlError: <'||l_result||'>'|| sqlerrm;
742 p_resultout := 1;
743 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
744 return;
745
746 END;
747 ELSE -- p_analysis_level A or S (both)
748 BEGIN
749 SELECT max(ltrim(
750 to_char( gl_currency_api.convert_amount(currency,
751 p_limit_currency,sysdate,
752 p_exchange_rate_type,
753 op_bal_high_watermark),
754 '0999999999999999999D00')) || '~' ||
755 to_char(as_of_date, 'YYYYMMDD'))
756 INTO l_result
757 FROM ar_trx_summary
758 WHERE op_bal_high_watermark IS NOT NULL
759 AND as_of_date >= ADD_MONTHS(sysdate,(-p_period))
760 AND cust_account_id = p_cust_account_id
761 AND site_use_id = DECODE(p_analysis_level, 'S', p_site_use_id,
762 site_use_id)
763 AND org_id = decode(p_global_exposure_flag,'Y', org_id, 'N',
764 decode(p_org_id,null, org_id, p_org_id), null,
765 decode(p_org_id,null, org_id, p_org_id))
766 AND currency IN ( SELECT CURRENCY
767 FROM ar_cmgt_curr_usage_gt
768 WHERE nvl(credit_request_id,p_credit_request_id)
769 = p_credit_request_id);
770
771 /* Now extract results, '~' is separator */
772 l_final_high_watermark := to_number(substr(l_result,0,instr(l_result,'~')-1));
773 l_final_high_watermark_date := to_date(substr(l_result,instr(l_result,'~')+1),'YYYYMMDD');
774
775 EXCEPTION
776 WHEN no_data_found then
777 l_final_high_watermark := NULL;
778 l_final_high_watermark_date := NULL;
779 when others then
780 p_errormsg := 'Error While getting High Credit Amount for Account/Site, SqlError: <'||l_result||'>'|| sqlerrm;
781 p_resultout := 1;
782 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
783 return;
784
785
786 END;
787 END IF;
788
789 build_case_folder_details(
790 p_case_folder_id => p_case_folder_id,
791 p_data_point_id => 19,
792 p_data_point_value => fnd_number.number_to_canonical(l_final_inv_amount),
793 p_mode => p_mode,
794 p_error_msg => p_errormsg ,
795 p_resultout => p_resultout);
796 build_case_folder_details(
797 p_case_folder_id => p_case_folder_id,
798 p_data_point_id => 20,
799 p_data_point_value => l_final_inv_date,
800 p_mode => p_mode,
801 p_error_msg => p_errormsg ,
802 p_resultout => p_resultout);
803 build_case_folder_details(
804 p_case_folder_id => p_case_folder_id,
805 p_data_point_id => 6,
806 p_data_point_value => fnd_number.number_to_canonical(l_final_high_watermark),
807 p_mode => p_mode,
808 p_error_msg => p_errormsg ,
809 p_resultout => p_resultout);
810 build_case_folder_details(
811 p_case_folder_id => p_case_folder_id,
812 p_data_point_id => 7,
813 p_data_point_value => l_final_high_watermark_date,
814 p_mode => p_mode,
815 p_error_msg => p_errormsg ,
816 p_resultout => p_resultout);
817 -- Get the last payment Info.
818 BEGIN
819 IF p_analysis_level = 'P'
820 THEN
821 SELECT last_payment_amount, last_payment_date,
822 last_payment_number, currency
823 INTO l_last_payment_amount, l_last_payment_date,
824 l_last_payment_number, l_last_payment_currency
825 FROM AR_TRX_BAL_SUMMARY
826 WHERE cust_account_id in (select cust_account_id
827 FROM hz_cust_accounts
828 WHERE party_id in
829 ( SELECT child_id
830 from hz_hierarchy_nodes
831 where parent_object_type = 'ORGANIZATION'
832 and parent_table_name = 'HZ_PARTIES'
833 and child_object_type = 'ORGANIZATION'
834 and parent_id = p_party_id
835 and effective_start_date <= sysdate
836 and effective_end_date >= sysdate
837 and hierarchy_type = FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
838 and g_source_name <> 'LNS'
839 union select p_party_id from dual
840 UNION
841 select hz_party_id
842 from LNS_LOAN_PARTICIPANTS_V
843 where loan_id = g_source_id
844 and participant_type_code = 'COBORROWER'
845 and g_source_name = 'LNS'
846 and (end_date_active is null OR
847 (sysdate between start_date_active and end_date_active)
848 )
849 ))
850 and CURRENCY IN ( SELECT CURRENCY FROM
851 ar_cmgt_curr_usage_gt
852 WHERE nvl(credit_request_id,p_credit_request_id)
853 = p_credit_request_id)
854 and last_payment_number IS NOT NULL
855 and last_payment_date IS NOT NULL
856 and last_payment_date = ( select max(last_payment_date) from
857 ar_trx_bal_summary
858 where cust_account_id in
859 (select cust_account_id
860 FROM hz_cust_accounts
861 WHERE party_id in
862 ( SELECT child_id
863 from hz_hierarchy_nodes
864 where parent_object_type = 'ORGANIZATION'
865 and parent_table_name = 'HZ_PARTIES'
866 and child_object_type = 'ORGANIZATION'
867 and parent_id = p_party_id
868 and effective_start_date <= sysdate
869 and effective_end_date >= sysdate
870 and hierarchy_type = FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
871 and g_source_name <> 'LNS'
872 union select p_party_id from dual
873 UNION
874 select hz_party_id
875 from LNS_LOAN_PARTICIPANTS_V
876 where loan_id = g_source_id
877 and participant_type_code = 'COBORROWER'
878 and g_source_name = 'LNS'
879 and (end_date_active is null OR
880 (sysdate between start_date_active and end_date_active)
881 )
882 ))
883 and CURRENCY IN ( SELECT CURRENCY FROM
884 ar_cmgt_curr_usage_gt
885 WHERE nvl(credit_request_id,p_credit_request_id) =
886 p_credit_request_id)
887 and last_payment_date is not null
888 and last_payment_number is not null)
889 and rownum = 1;
890 ELSIF p_analysis_level = 'A'
891 THEN
892 SELECT last_payment_amount, last_payment_date,
893 last_payment_number, currency
894 INTO l_last_payment_amount, l_last_payment_date,
895 l_last_payment_number, l_last_payment_currency
896 FROM AR_TRX_BAL_SUMMARY
897 where cust_account_id = p_cust_account_id
898 and last_payment_date IS NOT NULL
899 and last_payment_number IS NOT NULL
900 and org_id = decode(p_global_exposure_flag,'Y', org_id, 'N',
901 decode(p_org_id,null, p_org_id, p_org_id), null,
902 decode(p_org_id,null, org_id, p_org_id))
903 and currency in ( SELECT CURRENCY FROM
904 ar_cmgt_curr_usage_gt
905 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
906 and last_payment_date = ( select max(last_payment_date) from
907 ar_trx_bal_summary
908 where cust_account_id = p_cust_account_id
909 and last_payment_date IS NOT NULL
910 and last_payment_number IS NOT NULL
911 and currency in ( SELECT CURRENCY FROM
912 ar_cmgt_curr_usage_gt
913 WHERE nvl(credit_request_id,p_credit_request_id) =
914 p_credit_request_id))
915 and rownum = 1;
916 ELSIF p_analysis_level = 'S'
917 THEN
918 SELECT last_payment_amount, last_payment_date,
919 last_payment_number, currency
920 INTO l_last_payment_amount, l_last_payment_date,
921 l_last_payment_number, l_last_payment_currency
922 FROM AR_TRX_BAL_SUMMARY
923 where cust_account_id = p_cust_account_id
924 and site_use_id = p_site_use_id
925 and last_payment_date IS NOT NULL
926 and last_payment_number IS NOT NULL
927 and currency in ( SELECT CURRENCY FROM
928 ar_cmgt_curr_usage_gt
929 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
930 and last_payment_date = ( select max(last_payment_date) from
931 ar_trx_bal_summary
932 where cust_account_id = p_cust_account_id
933 and site_use_id = p_site_use_id
934 and last_payment_date IS NOT NULL
935 and last_payment_number IS NOT NULL
936 and currency in ( SELECT CURRENCY FROM
937 ar_cmgt_curr_usage_gt
938 WHERE nvl(credit_request_id,p_credit_request_id) =
939 p_credit_request_id))
940 and rownum = 1;
941 END IF;
942
943 EXCEPTION
944 WHEN no_data_found then
945 l_last_payment_number := null;
946 l_last_payment_date := null;
947 l_last_payment_amount := null;
948 when others then
949 p_errormsg := 'Error While getting Last payment info., SqlError: '||sqlerrm;
950 p_resultout := 1;
951 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
952 return;
953 END;
954 BEGIN
955 -- if everything is ok then create record in case folder tables
956 -- convert last payment amount to limit currency amount
957 IF l_last_payment_currency IS NOT NULL THEN
958 l_last_payment_amount_conv := gl_currency_api.convert_amount
959 (l_last_payment_currency,
960 p_limit_currency,sysdate,
961 p_exchange_rate_type,
962 l_last_payment_amount);
963 END IF;
964 build_case_folder_details(
965 p_case_folder_id => p_case_folder_id,
966 p_data_point_id => 11,
967 p_data_point_value => fnd_number.number_to_canonical(l_last_payment_amount_conv),
968 p_mode => p_mode,
969 p_error_msg => p_errormsg ,
970 p_resultout => p_resultout);
971 build_case_folder_details(
972 p_case_folder_id => p_case_folder_id,
973 p_data_point_id => 207,
974 p_data_point_value => fnd_number.number_to_canonical(l_last_payment_amount),
975 p_mode => p_mode,
976 p_error_msg => p_errormsg ,
977 p_resultout => p_resultout);
978 build_case_folder_details(
979 p_case_folder_id => p_case_folder_id,
980 p_data_point_id => 12,
981 p_data_point_value => l_last_payment_date,
982 p_mode => p_mode,
983 p_error_msg => p_errormsg ,
984 p_resultout => p_resultout);
985 build_case_folder_details(
986 p_case_folder_id => p_case_folder_id,
987 p_data_point_id => 205,
988 p_data_point_value => l_last_payment_number,
989 p_mode => p_mode,
990 p_error_msg => p_errormsg ,
991 p_resultout => p_resultout);
992 build_case_folder_details(
993 p_case_folder_id => p_case_folder_id,
994 p_data_point_id => 206,
995 p_data_point_value => l_last_payment_currency,
996 p_mode => p_mode,
997 p_error_msg => p_errormsg ,
998 p_resultout => p_resultout);
999 EXCEPTION
1000 when others then
1001 p_errormsg := 'Error While inserting Last payment info., SqlError: '||sqlerrm;
1002 p_resultout := 1;
1003 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
1004 return;
1005 END;
1006
1007 IF pg_wf_debug = 'Y'
1008 THEN
1009 ar_cmgt_util.wf_debug(p_case_folder_id,
1010 'ar_cmgt_data_points_pkg.getanalyticaldata()-');
1011 END IF;
1012
1013 EXCEPTION
1014 WHEN OTHERS THEN
1015 p_errormsg := 'Error While getting Largest Invvoice and High Credit Amount, SqlError: '||sqlerrm;
1016 p_resultout := 1;
1017 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
1018 END;
1019
1020
1021 PROCEDURE GetDunning(
1022 p_credit_request_id IN NUMBER,
1023 p_party_id IN NUMBER,
1024 p_cust_account_id IN NUMBER,
1025 p_site_use_id IN NUMBER,
1026 p_org_id IN NUMBER,
1027 p_case_folder_id IN NUMBER,
1028 p_period IN NUMBER,
1029 p_analysis_level IN VARCHAR2,
1030 p_global_exposure_flag IN VARCHAR2,
1031 p_mode IN VARCHAR2 default 'CREATE',
1032 p_errormsg OUT nocopy VARCHAR2,
1033 p_resultout out nocopy VARCHAR2) IS
1034
1035 l_correspondence_date ar_correspondences_all.correspondence_date%type;
1036 l_dunning_count NUMBER;
1037 BEGIN
1038 IF pg_wf_debug = 'Y'
1039 THEN
1040 ar_cmgt_util.wf_debug(p_case_folder_id,
1041 'ar_cmgt_data_points_pkg.getdunning()+');
1042 END IF;
1043
1044 p_resultout := 0;
1045 IF p_analysis_level = 'A'
1046 THEN
1047 BEGIN
1048 SELECT max(correspondence_date), count(*)
1049 INTO l_correspondence_date, l_dunning_count
1050 FROM ar_correspondences_all
1051 WHERE correspondence_type = 'DUNNING'
1052 AND customer_id = p_cust_account_id
1053 AND org_id = decode(p_global_exposure_flag,'Y', org_id, 'N',
1054 decode(p_org_id,null, org_id, p_org_id), null,
1055 decode(p_org_id,null, org_id, p_org_id))
1056 AND correspondence_date >= ADD_MONTHS(sysdate,(-p_period));
1057 END;
1058 ELSIF p_analysis_level = 'S'
1059 THEN
1060 BEGIN
1061 SELECT max(correspondence_date), count(*)
1062 INTO l_correspondence_date, l_dunning_count
1063 FROM ar_correspondences_all
1064 WHERE correspondence_type = 'DUNNING'
1065 AND customer_id = p_cust_account_id
1066 AND site_use_id = p_site_use_id
1067 AND correspondence_date >= ADD_MONTHS(sysdate,(-p_period));
1068 END;
1069 ELSIF p_analysis_level = 'P'
1070 THEN
1071 BEGIN
1072 SELECT max(correspondence_date), count(*)
1073 INTO l_correspondence_date, l_dunning_count
1074 FROM ar_correspondences_all
1075 WHERE correspondence_type = 'DUNNING'
1076 AND customer_id in (
1077 select cust_account_id
1078 FROM hz_cust_accounts
1079 WHERE party_id in
1080 ( SELECT child_id
1081 from hz_hierarchy_nodes
1082 where parent_object_type = 'ORGANIZATION'
1083 and parent_table_name = 'HZ_PARTIES'
1084 and child_object_type = 'ORGANIZATION'
1085 and parent_id = p_party_id
1086 and effective_start_date <= sysdate
1087 and effective_end_date >= sysdate
1088 and hierarchy_type =
1089 FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
1090 and g_source_name <> 'LNS'
1091 union select p_party_id from dual
1092 UNION
1093 select hz_party_id
1094 from LNS_LOAN_PARTICIPANTS_V
1095 where loan_id = g_source_id
1096 and participant_type_code = 'COBORROWER'
1097 and g_source_name = 'LNS'
1098 and (end_date_active is null OR
1099 (sysdate between start_date_active and end_date_active)
1100 )
1101 ))
1102 AND correspondence_date >= ADD_MONTHS(sysdate,(-p_period));
1103 END;
1104 END IF;
1105 build_case_folder_details(
1106 p_case_folder_id => p_case_folder_id,
1107 p_data_point_id => 57,
1108 p_data_point_value => to_char(l_correspondence_date),
1109 p_mode => p_mode,
1110 p_error_msg => p_errormsg ,
1111 p_resultout => p_resultout);
1112 IF p_resultout <> 0
1113 THEN
1114 return;
1115 END IF;
1116 build_case_folder_details(
1117 p_case_folder_id => p_case_folder_id,
1118 p_data_point_id => 59,
1119 p_data_point_value => l_dunning_count,
1120 p_mode => p_mode,
1121 p_error_msg => p_errormsg ,
1122 p_resultout => p_resultout);
1123 IF p_resultout <> 0
1124 THEN
1125 return;
1126 END IF;
1127
1128 IF pg_wf_debug = 'Y'
1129 THEN
1130 ar_cmgt_util.wf_debug(p_case_folder_id,
1131 'ar_cmgt_data_points_pkg.getdunning()-');
1132 END IF;
1133
1134 EXCEPTION
1135 WHEN OTHERS THEN
1136 p_resultout := 1;
1137 p_errormsg := 'Error While getting Dunning Letter Count, Sql Error:'||sqlerrm;
1138 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
1139 END;
1140
1141
1142 PROCEDURE GetOMDataPoints(
1143 p_credit_request_id IN NUMBER,
1144 p_party_id IN NUMBER,
1145 p_cust_account_id IN NUMBER,
1146 p_site_use_id IN NUMBER,
1147 p_case_folder_id IN NUMBER,
1148 p_analysis_level IN VARCHAR2,
1149 p_limit_currency_code IN VARCHAR2,
1150 p_mode IN VARCHAR2 default 'CREATE',
1151 p_errormsg OUT nocopy VARCHAR2,
1152 p_resultout OUT nocopy VARCHAR2) IS
1153
1154 l_status varchar2(1) ;
1155 l_industry VARCHAR2(1) ;
1156 l_return BOOLEAN ;
1157 l_application_id NUMBER;
1158 l_credit_check_rule_id NUMBER;
1159 l_total_exposure NUMBER;
1160 l_order_hold_amount NUMBER;
1161 l_order_amount NUMBER;
1162 l_ar_cmount NUMBER;
1163 l_external_amount NUMBER;
1164 l_return_status VARCHAR2(1);
1165 l_errmsg VARCHAR2(2000);
1166 l_resultout VARCHAR2(1);
1167 l_om_installed_flag VARCHAR2(1) := 'Y';
1168 l_om_exposure NUMBER;
1169 l_credit_exposure NUMBER;
1170 l_rec_bal NUMBER;
1171
1172 CURSOR RecBalC IS
1173 SELECT data_point_value
1174 FROM ar_cmgt_cf_dtls
1175 WHERE case_folder_id = p_case_folder_id
1176 AND data_point_id = 34; -- receivable balance
1177 BEGIN
1178 IF pg_wf_debug = 'Y'
1179 THEN
1180 ar_cmgt_util.wf_debug(p_case_folder_id,
1181 'ar_cmgt_data_points_pkg.getomdatapoints()+');
1182 END IF;
1183
1184 -- first check if OM is installed, if OM is installed then get oM data points
1185 p_resultout := 0;
1186
1187 BEGIN
1188 select application_id
1189 into l_application_id
1190 from fnd_application
1191 where application_short_name = 'ONT' ;
1192
1193 IF fnd_installation.get(l_application_id,l_application_id
1194 ,l_status,l_industry) then
1195
1196 IF l_status NOT IN ('I','S')
1197 THEN
1198 l_om_installed_flag := 'N';
1199 END IF;
1200
1201 ELSE
1202 l_om_installed_flag := 'N';
1203 END IF;
1204 EXCEPTION
1205 WHEN NO_DATA_FOUND THEN
1206 l_om_installed_flag := 'N';
1207 WHEN OTHERS THEN
1208 p_resultout := 1;
1209 p_errormsg := 'Error While Checking if ONT is installed or not, Sqlerror '||sqlerrm;
1210 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
1211 return;
1212 END;
1213 BEGIN
1214 -- Now if OM is installed get credit_check_rule_id
1215 SELECT credit_check_rule_id
1216 INTO l_credit_check_rule_id
1217 FROM ar_cmgt_credit_requests
1218 WHERE credit_request_id = p_credit_request_id;
1219
1220 IF l_credit_check_rule_id IS NULL
1221 THEN
1222 l_credit_check_rule_id := -999; -- use seeded credit check rule id
1223 END IF;
1224 EXCEPTION
1225 WHEN NO_DATA_FOUND THEN
1226 l_om_installed_flag := 'N';
1227 WHEN OTHERS THEN
1228 p_resultout := 1;
1229 p_errormsg := 'Error While getting Credit Check rule Id, Sqlerror '||sqlerrm;
1230 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
1231 return;
1232 END;
1233 IF l_om_installed_flag = 'N'
1234 THEN
1235 build_case_folder_details(
1236 p_case_folder_id => p_case_folder_id,
1237 p_data_point_id => 15,
1238 p_data_point_value => null,
1239 p_mode => p_mode,
1240 p_error_msg => l_errmsg,
1241 p_resultout => l_resultout);
1242
1243 build_case_folder_details(
1244 p_case_folder_id => p_case_folder_id,
1245 p_data_point_id => 26,
1246 p_mode => p_mode,
1247 p_data_point_value => null,
1248 p_error_msg => l_errmsg,
1249 p_resultout => l_resultout);
1250 return; -- no need to continue if OM is not installed
1251 END IF;
1252 -- check what is the analysis level
1253 IF p_analysis_level in ('P')
1254 THEN
1255 OE_Credit_Exposure_PUB.Get_customer_exposure
1256 ( p_party_id => p_party_id,
1257 p_customer_id => NULL,
1258 p_site_id => NULL,
1259 p_limit_curr_code => p_limit_currency_code,
1260 p_credit_check_rule_id => l_credit_check_rule_id,
1261 x_total_exposure => l_total_exposure,
1262 x_order_hold_amount => l_order_hold_amount,
1263 x_order_amount => l_order_amount,
1264 x_ar_amount => l_ar_cmount,
1265 x_external_amount => l_external_amount,
1266 x_return_status => l_return_status);
1267 ELSIF p_analysis_level in ('A')
1268 THEN
1269 OE_Credit_Exposure_PUB.Get_customer_exposure
1270 ( p_party_id => p_party_id,
1271 p_customer_id => p_cust_account_id,
1272 p_site_id => NULL,
1273 p_limit_curr_code => p_limit_currency_code,
1274 p_credit_check_rule_id => l_credit_check_rule_id,
1275 x_total_exposure => l_total_exposure,
1276 x_order_hold_amount => l_order_hold_amount,
1277 x_order_amount => l_order_amount,
1278 x_ar_amount => l_ar_cmount,
1279 x_external_amount => l_external_amount,
1280 x_return_status => l_return_status);
1281
1282 ELSIF p_analysis_level = 'S'
1283 THEN
1284 OE_Credit_Exposure_PUB.Get_customer_exposure
1285 ( p_party_id => p_party_id,
1286 p_customer_id => p_cust_account_id,
1287 p_site_id => p_site_use_id,
1288 p_limit_curr_code => p_limit_currency_code,
1289 p_credit_check_rule_id => l_credit_check_rule_id,
1290 x_total_exposure => l_total_exposure,
1291 x_order_hold_amount => l_order_hold_amount,
1292 x_order_amount => l_order_amount,
1293 x_ar_amount => l_ar_cmount,
1294 x_external_amount => l_external_amount,
1295 x_return_status => l_return_status);
1296
1297
1298 END IF;
1299 IF l_return_status = FND_API.G_RET_STS_SUCCESS
1300 THEN
1301 build_case_folder_details(
1302 p_case_folder_id => p_case_folder_id,
1303 p_data_point_id => 15,
1304 p_data_point_value => fnd_number.number_to_canonical((l_total_exposure - l_ar_cmount)),
1305 p_mode => p_mode,
1306 p_error_msg => l_errmsg,
1307 p_resultout => l_resultout);
1308
1309 build_case_folder_details(
1310 p_case_folder_id => p_case_folder_id,
1311 p_data_point_id => 26,
1312 p_data_point_value => fnd_number.number_to_canonical(l_order_hold_amount),
1313 p_mode => p_mode,
1314 p_error_msg => l_errmsg,
1315 p_resultout => l_resultout);
1316
1317 -- Now Populate Credit exposure
1318 FOR RecBalRec IN RecBalC
1319 LOOP
1320 l_Rec_Bal := fnd_number.canonical_to_number(RecBalRec.data_point_value);
1321 END LOOP;
1322 l_credit_exposure :=
1323 nvl(l_Rec_bal,0) + (nvl(l_total_exposure,0) - nvl(l_ar_cmount,0)) +
1324 nvl(l_order_hold_amount,0);
1325
1326 build_case_folder_details(
1327 p_case_folder_id => p_case_folder_id,
1328 p_data_point_id => 213,
1329 p_data_point_value => fnd_number.number_to_canonical(l_credit_exposure),
1330 p_mode => p_mode,
1331 p_error_msg => l_errmsg,
1332 p_resultout => l_resultout);
1333 ELSE
1334 p_resultout := 1;
1335 p_errormsg := 'Error While getting OM Exposure, Sqlerror '||sqlerrm;
1336 ar_cmgt_util.wf_debug(p_case_folder_id, p_errormsg);
1337 return;
1338 END IF;
1339
1340 IF pg_wf_debug = 'Y'
1341 THEN
1342 ar_cmgt_util.wf_debug(p_case_folder_id,
1343 'ar_cmgt_data_points_pkg.getomdatapoints()-');
1344 END IF;
1345
1346 END;
1347
1348 /* 6335440 - this procedure did not work prior to this bug.
1349 The reason was that the financial data (ar_cmgt_financial_data)
1350 had cust_acct_site_id in the site_use_id field. Additionally,
1351 prior to this bug, the procedure relied on completely un-indexed
1352 joins and multiple reads of the ar_cmgt_financial_data table
1353 which (for production data) would bave performed awful.
1354
1355 To correct these issues, we did the following:
1356
1357 o revised initial select to fetch cust_acct_site_id
1358 instead of site_use_id. This is used to correctly
1359 join to the errant ar_cmgt_financial_data table.
1360
1361 o revised second select to only join to
1362 ar_cmgt_financial_data once (was joining twice)
1363
1364 o Added index ar_cmgt_financial_data_n2 that contains following:
1365 1) party_id
1366 2) reporting_currency
1367 3) cust_account_id
1368 4) site_use_id
1369
1370 The reason the index is in this particular order is that party_id
1371 and currency are guaranteed. cust and/or site are optional and
1372 may be provided as cust or cust + site.
1373
1374 */
1375
1376 PROCEDURE GetFinancialData (
1377 p_credit_request_id IN NUMBER,
1378 p_case_folder_id IN NUMBER,
1379 p_mode IN VARCHAR2,
1380 p_resultout OUT NOCOPY VARCHAR2,
1381 p_errmsg OUT NOCOPY VARCHAR2) IS
1382
1383 l_reporting_currency ar_cmgt_financial_data.reporting_currency%type;
1384 l_monetary_unit ar_cmgt_financial_data.monetary_unit%type;
1385 l_curr_fin_st_date ar_cmgt_financial_data.curr_fin_st_date%type;
1386 l_reporting_period ar_cmgt_financial_data.reporting_period%type;
1387 l_cash ar_cmgt_financial_data.cash%type;
1388 l_net_receivables ar_cmgt_financial_data.net_receivables%type;
1389 l_inventories ar_cmgt_financial_data.inventories%type;
1390 l_other_cur_assets ar_cmgt_financial_data.other_cur_assets%type;
1391 l_total_cur_assets ar_cmgt_financial_data.total_cur_assets%type;
1392 l_net_fixed_assets ar_cmgt_financial_data.net_fixed_assets%type;
1393 l_other_non_cur_assets ar_cmgt_financial_data.net_fixed_assets%type;
1394 l_total_assets ar_cmgt_financial_data.total_assets%type;
1395 l_accounts_payable ar_cmgt_financial_data.accounts_payable%type;
1396 l_short_term_debt ar_cmgt_financial_data.short_term_debt%type;
1397 l_other_cur_liabilities ar_cmgt_financial_data.other_cur_liabilities%type;
1398 l_total_cur_liabilities ar_cmgt_financial_data.total_cur_liabilities%type;
1399 l_long_term_debt ar_cmgt_financial_data.long_term_debt%type;
1400 l_other_non_cur_liabilities ar_cmgt_financial_data.other_non_cur_liabilities%type;
1401 l_total_liabilities ar_cmgt_financial_data.total_liabilities%type;
1402 l_stockholder_equity ar_cmgt_financial_data.stockholder_equity%type;
1403 l_total_liabilities_equity ar_cmgt_financial_data.total_liabilities_equity%type;
1404 l_revenue ar_cmgt_financial_data.revenue%type;
1405 l_cost_of_goods_sold ar_cmgt_financial_data.cost_of_goods_sold%type;
1406 l_sga_expenses ar_cmgt_financial_data.sga_expenses%type;
1407 l_operating_income ar_cmgt_financial_data.operating_income%type;
1408 l_operating_margin ar_cmgt_financial_data.operating_margin%type;
1409 l_non_operating_income ar_cmgt_financial_data.non_operating_income%type;
1410 l_non_operating_expenses ar_cmgt_financial_data.non_operating_expenses%type;
1411 l_pre_tax_net_income ar_cmgt_financial_data.pre_tax_net_income%type;
1412 l_income_taxes ar_cmgt_financial_data.income_taxes%type;
1413 l_net_income ar_cmgt_financial_data.net_income%type;
1414 l_earnings_per_share ar_cmgt_financial_data.earnings_per_share%type;
1415 l_financial_data_id ar_cmgt_financial_data.financial_data_id%type;
1416 l_party_id ar_cmgt_case_folders.party_id%type;
1417 l_cust_account_id ar_cmgt_case_folders.cust_account_id%type;
1418 l_site_use_id ar_cmgt_case_folders.site_use_id%type;
1419 l_limit_currency ar_cmgt_case_folders.limit_currency%type;
1420
1421 BEGIN
1422 IF pg_wf_debug = 'Y'
1423 THEN
1424 ar_cmgt_util.wf_debug(p_case_folder_id,
1425 'ar_cmgt_data_points_pkg.getfinancialdata()+');
1426 END IF;
1427
1428 p_resultout := 0;
1429 BEGIN
1430 BEGIN
1431 -- first get the maximum data for a party
1432 /* 6335440 - modified to fetch correct site for fin data */
1433 SELECT cmcf.party_id,
1434 cmcf.cust_account_id,
1435 nvl(hzs.cust_acct_site_id,cmcf.site_use_id),
1436 cmcf.limit_currency
1437 INTO l_party_id, l_cust_account_id, l_site_use_id, l_limit_currency
1438 FROM ar_cmgt_case_folders cmcf,
1439 hz_cust_site_uses_all hzs
1440 WHERE cmcf.case_folder_id = p_case_folder_id
1441 AND cmcf.site_use_id = hzs.site_use_id (+);
1442
1443 EXCEPTION
1444 WHEN OTHERS THEN
1445 p_resultout := 1;
1446 p_errmsg := 'Error while getting party information from ar_cmgt_case_folders'||
1447 ' SqlError '|| sqlerrm;
1448 ar_cmgt_util.wf_debug(p_case_folder_id, p_errmsg);
1449 return;
1450 END;
1451
1452
1453 BEGIN
1454 /* 6335440 - restructured this sql to use a trick
1455 that ultimately distills down to the maximum
1456 financial_data_id on the maximum date that matches
1457 the parameters (currency,party,customer,site).
1458
1459 This sql has same result as predecessor only it
1460 reduces the number of reads on ar_cmgt_financial_data
1461 to a single read */
1462
1463 SELECT to_number(
1464 substr(
1465 max(to_char(curr_fin_st_date, 'YYYYMMDD') ||
1466 ltrim(to_char(financial_data_id,
1467 '0999999999999999999999')))
1468 ,9))
1469 INTO l_financial_data_id
1470 FROM ar_cmgt_financial_data
1471 WHERE reporting_currency = l_limit_currency
1472 AND party_id = l_party_id
1473 AND cust_account_id = l_cust_account_id
1474 AND site_use_id = l_site_use_id;
1475
1476 EXCEPTION
1477 WHEN NO_DATA_FOUND THEN
1478 NULL;
1479 WHEN TOO_MANY_ROWS THEN
1480 NULL;
1481 WHEN OTHERS THEN
1482 p_resultout := 1;
1483 p_errmsg := 'Error while getting max data from ar_cmgt_financial_data '||
1484 ' SqlError '|| sqlerrm;
1485 ar_cmgt_util.wf_debug(p_case_folder_id, p_errmsg);
1486 return;
1487
1488 END;
1489
1490 SELECT reporting_currency,
1491 monetary_unit,
1492 curr_fin_st_date,
1493 reporting_period,
1494 cash,
1495 net_receivables,
1496 inventories,
1497 other_cur_assets,
1498 total_cur_assets,
1499 net_fixed_assets,
1500 other_non_cur_assets,
1501 total_assets,
1502 accounts_payable,
1503 short_term_debt,
1504 other_cur_liabilities,
1505 total_cur_liabilities,
1506 long_term_debt,
1507 other_non_cur_liabilities,
1508 total_liabilities,
1509 stockholder_equity,
1510 total_liabilities_equity,
1511 revenue,
1512 cost_of_goods_sold,
1513 sga_expenses,
1514 operating_income,
1515 operating_margin,
1516 non_operating_income,
1517 non_operating_expenses,
1518 pre_tax_net_income,
1519 income_taxes,
1520 net_income,
1521 earnings_per_share
1522 INTO
1523 l_reporting_currency,
1524 l_monetary_unit ,
1525 l_curr_fin_st_date ,
1526 l_reporting_period ,
1527 l_cash ,
1528 l_net_receivables ,
1529 l_inventories ,
1530 l_other_cur_assets ,
1531 l_total_cur_assets,
1532 l_net_fixed_assets,
1533 l_other_non_cur_assets,
1534 l_total_assets ,
1535 l_accounts_payable ,
1536 l_short_term_debt ,
1537 l_other_cur_liabilities,
1538 l_total_cur_liabilities ,
1539 l_long_term_debt ,
1540 l_other_non_cur_liabilities,
1541 l_total_liabilities ,
1542 l_stockholder_equity ,
1543 l_total_liabilities_equity ,
1544 l_revenue ,
1545 l_cost_of_goods_sold ,
1546 l_sga_expenses ,
1547 l_operating_income ,
1548 l_operating_margin ,
1549 l_non_operating_income ,
1550 l_non_operating_expenses ,
1551 l_pre_tax_net_income ,
1552 l_income_taxes ,
1553 l_net_income ,
1554 l_earnings_per_share
1555 FROM ar_cmgt_financial_data
1556 WHERE financial_data_id = l_financial_data_id;
1557
1558 EXCEPTION
1559 WHEN NO_DATA_FOUND THEN
1560 NULL;
1561 WHEN TOO_MANY_ROWS THEN
1562 NULL;
1563 WHEN OTHERS THEN
1564 p_resultout := 1;
1565 p_errmsg := 'Error while getting records from ar_cmgt_financial_data '||
1566 ' SqlError '|| sqlerrm;
1567 ar_cmgt_util.wf_debug(p_case_folder_id, p_errmsg);
1568 return;
1569
1570 END;
1571 build_case_folder_details(
1572 p_case_folder_id => p_case_folder_id,
1573 p_data_point_id => 111,
1574 p_data_point_value => l_curr_fin_st_date,
1575 p_mode => p_mode,
1576 p_error_msg => p_errmsg,
1577 p_resultout => p_resultout);
1578 build_case_folder_details(
1579 p_case_folder_id => p_case_folder_id,
1580 p_data_point_id => 110,
1581 p_data_point_value => l_monetary_unit,
1582 p_mode => p_mode,
1583 p_error_msg => p_errmsg,
1584 p_resultout => p_resultout);
1585 build_case_folder_details(
1586 p_case_folder_id => p_case_folder_id,
1587 p_data_point_id => 109,
1588 p_data_point_value => l_reporting_currency,
1589 p_mode => p_mode,
1590 p_error_msg => p_errmsg,
1591 p_resultout => p_resultout);
1592 build_case_folder_details(
1593 p_case_folder_id => p_case_folder_id,
1594 p_data_point_id => 112,
1595 p_data_point_value => l_reporting_period,
1596 p_mode => p_mode,
1597 p_error_msg => p_errmsg,
1598 p_resultout => p_resultout);
1599 build_case_folder_details(
1600 p_case_folder_id => p_case_folder_id,
1601 p_data_point_id => 113,
1602 p_data_point_value => fnd_number.number_to_canonical(l_cash),
1603 p_mode => p_mode,
1604 p_error_msg => p_errmsg,
1605 p_resultout => p_resultout);
1606 build_case_folder_details(
1607 p_case_folder_id => p_case_folder_id,
1608 p_data_point_id => 114,
1609 p_data_point_value => fnd_number.number_to_canonical(l_net_receivables),
1610 p_mode => p_mode,
1611 p_error_msg => p_errmsg,
1612 p_resultout => p_resultout);
1613 build_case_folder_details(
1614 p_case_folder_id => p_case_folder_id,
1615 p_data_point_id => 115,
1616 p_data_point_value => fnd_number.number_to_canonical(l_inventories),
1617 p_mode => p_mode,
1618 p_error_msg => p_errmsg,
1619 p_resultout => p_resultout);
1620 build_case_folder_details(
1621 p_case_folder_id => p_case_folder_id,
1622 p_data_point_id => 116,
1623 p_data_point_value => fnd_number.number_to_canonical(l_other_cur_assets),
1624 p_mode => p_mode,
1625 p_error_msg => p_errmsg,
1626 p_resultout => p_resultout);
1627 build_case_folder_details(
1628 p_case_folder_id => p_case_folder_id,
1629 p_data_point_id => 117,
1630 p_data_point_value => fnd_number.number_to_canonical(l_total_cur_assets),
1631 p_mode => p_mode,
1632 p_error_msg => p_errmsg,
1633 p_resultout => p_resultout);
1634 build_case_folder_details(
1635 p_case_folder_id => p_case_folder_id,
1636 p_data_point_id => 118,
1637 p_data_point_value => fnd_number.number_to_canonical(l_net_fixed_assets),
1638 p_mode => p_mode,
1639 p_error_msg => p_errmsg,
1640 p_resultout => p_resultout);
1641 build_case_folder_details(
1642 p_case_folder_id => p_case_folder_id,
1643 p_data_point_id => 119,
1644 p_data_point_value => fnd_number.number_to_canonical(l_other_non_cur_assets),
1645 p_mode => p_mode,
1646 p_error_msg => p_errmsg,
1647 p_resultout => p_resultout);
1648 build_case_folder_details(
1649 p_case_folder_id => p_case_folder_id,
1650 p_data_point_id => 120,
1651 p_data_point_value => fnd_number.number_to_canonical(l_total_assets),
1652 p_mode => p_mode,
1653 p_error_msg => p_errmsg,
1654 p_resultout => p_resultout);
1655 build_case_folder_details(
1656 p_case_folder_id => p_case_folder_id,
1657 p_data_point_id => 121,
1658 p_data_point_value => fnd_number.number_to_canonical(l_accounts_payable),
1659 p_mode => p_mode,
1660 p_error_msg => p_errmsg,
1661 p_resultout => p_resultout);
1662 build_case_folder_details(
1663 p_case_folder_id => p_case_folder_id,
1664 p_data_point_id => 122,
1665 p_data_point_value => fnd_number.number_to_canonical(l_short_term_debt),
1666 p_mode => p_mode,
1667 p_error_msg => p_errmsg,
1668 p_resultout => p_resultout);
1669 build_case_folder_details(
1670 p_case_folder_id => p_case_folder_id,
1671 p_data_point_id => 123,
1672 p_data_point_value => fnd_number.number_to_canonical(l_other_cur_liabilities),
1673 p_mode => p_mode,
1674 p_error_msg => p_errmsg,
1675 p_resultout => p_resultout);
1676 build_case_folder_details(
1677 p_case_folder_id => p_case_folder_id,
1678 p_data_point_id => 124,
1679 p_data_point_value => fnd_number.number_to_canonical(l_total_cur_liabilities),
1680 p_mode => p_mode,
1681 p_error_msg => p_errmsg,
1682 p_resultout => p_resultout);
1683 build_case_folder_details(
1684 p_case_folder_id => p_case_folder_id,
1685 p_data_point_id => 125,
1686 p_data_point_value => fnd_number.number_to_canonical(l_long_term_debt),
1687 p_mode => p_mode,
1688 p_error_msg => p_errmsg,
1689 p_resultout => p_resultout);
1690 build_case_folder_details(
1691 p_case_folder_id => p_case_folder_id,
1692 p_data_point_id => 126,
1693 p_data_point_value => fnd_number.number_to_canonical(l_other_non_cur_liabilities),
1694 p_mode => p_mode,
1695 p_error_msg => p_errmsg,
1696 p_resultout => p_resultout);
1697 build_case_folder_details(
1698 p_case_folder_id => p_case_folder_id,
1699 p_data_point_id => 127,
1700 p_data_point_value => fnd_number.number_to_canonical(l_total_liabilities),
1701 p_mode => p_mode,
1702 p_error_msg => p_errmsg,
1703 p_resultout => p_resultout);
1704 build_case_folder_details(
1705 p_case_folder_id => p_case_folder_id,
1706 p_data_point_id => 128,
1707 p_data_point_value => fnd_number.number_to_canonical(l_stockholder_equity),
1708 p_mode => p_mode,
1709 p_error_msg => p_errmsg,
1710 p_resultout => p_resultout);
1711 build_case_folder_details(
1712 p_case_folder_id => p_case_folder_id,
1713 p_data_point_id => 129,
1714 p_data_point_value => fnd_number.number_to_canonical(l_total_liabilities_equity),
1715 p_mode => p_mode,
1716 p_error_msg => p_errmsg,
1717 p_resultout => p_resultout);
1718 build_case_folder_details(
1719 p_case_folder_id => p_case_folder_id,
1720 p_data_point_id => 130,
1721 p_data_point_value => fnd_number.number_to_canonical(l_revenue),
1722 p_mode => p_mode,
1723 p_error_msg => p_errmsg,
1724 p_resultout => p_resultout);
1725 build_case_folder_details(
1726 p_case_folder_id => p_case_folder_id,
1727 p_data_point_id => 131,
1728 p_data_point_value => fnd_number.number_to_canonical(l_cost_of_goods_sold),
1729 p_mode => p_mode,
1730 p_error_msg => p_errmsg,
1731 p_resultout => p_resultout);
1732 build_case_folder_details(
1733 p_case_folder_id => p_case_folder_id,
1734 p_data_point_id => 132,
1735 p_data_point_value => fnd_number.number_to_canonical(l_sga_expenses),
1736 p_mode => p_mode,
1737 p_error_msg => p_errmsg,
1738 p_resultout => p_resultout);
1739 build_case_folder_details(
1740 p_case_folder_id => p_case_folder_id,
1741 p_data_point_id => 133,
1742 p_data_point_value => fnd_number.number_to_canonical(l_operating_income),
1743 p_mode => p_mode,
1744 p_error_msg => p_errmsg,
1745 p_resultout => p_resultout);
1746 build_case_folder_details(
1747 p_case_folder_id => p_case_folder_id,
1748 p_data_point_id => 134,
1749 p_data_point_value => fnd_number.number_to_canonical(l_operating_margin),
1750 p_mode => p_mode,
1751 p_error_msg => p_errmsg,
1752 p_resultout => p_resultout);
1753 build_case_folder_details(
1754 p_case_folder_id => p_case_folder_id,
1755 p_data_point_id => 135,
1756 p_data_point_value => fnd_number.number_to_canonical(l_non_operating_income),
1757 p_mode => p_mode,
1758 p_error_msg => p_errmsg,
1759 p_resultout => p_resultout);
1760 build_case_folder_details(
1761 p_case_folder_id => p_case_folder_id,
1762 p_data_point_id => 136,
1763 p_data_point_value => fnd_number.number_to_canonical(l_non_operating_expenses),
1764 p_mode => p_mode,
1765 p_error_msg => p_errmsg,
1766 p_resultout => p_resultout);
1767 build_case_folder_details(
1768 p_case_folder_id => p_case_folder_id,
1769 p_data_point_id => 137,
1770 p_data_point_value => fnd_number.number_to_canonical(l_pre_tax_net_income),
1771 p_mode => p_mode,
1772 p_error_msg => p_errmsg,
1773 p_resultout => p_resultout);
1774 build_case_folder_details(
1775 p_case_folder_id => p_case_folder_id,
1776 p_data_point_id => 138,
1777 p_data_point_value => fnd_number.number_to_canonical(l_income_taxes),
1778 p_mode => p_mode,
1779 p_error_msg => p_errmsg,
1780 p_resultout => p_resultout);
1781 build_case_folder_details(
1782 p_case_folder_id => p_case_folder_id,
1783 p_data_point_id => 139,
1784 p_data_point_value => fnd_number.number_to_canonical(l_net_income),
1785 p_mode => p_mode,
1786 p_error_msg => p_errmsg,
1787 p_resultout => p_resultout);
1788 build_case_folder_details(
1789 p_case_folder_id => p_case_folder_id,
1790 p_data_point_id => 140,
1791 p_data_point_value => fnd_number.number_to_canonical(l_earnings_per_share),
1792 p_mode => p_mode,
1793 p_error_msg => p_errmsg,
1794 p_resultout => p_resultout);
1795 IF pg_wf_debug = 'Y'
1796 THEN
1797 ar_cmgt_util.wf_debug(p_case_folder_id,
1798 'ar_cmgt_data_points_pkg.getfinancialdata()-');
1799 END IF;
1800
1801 END;
1802
1803
1804
1805 PROCEDURE GetOtherDataPoints (
1806 p_credit_request_id IN NUMBER,
1807 p_party_id IN NUMBER,
1808 p_cust_account_id IN NUMBER,
1809 p_site_use_id IN NUMBER,
1810 p_cust_acct_profile_amt_id IN NUMBER,
1811 p_case_folder_id IN NUMBER ,
1812 p_mode IN VARCHAR2 default 'CREATE') IS
1813
1814 l_case_folder_id NUMBER;
1815 l_errmsg VARCHAR2(2000);
1816 l_resultout VARCHAR2(1);
1817
1818 CURSOR c_hz_cust_prof_amts IS
1819 SELECT trx_credit_limit, overall_credit_limit
1820 FROM hz_cust_profile_amts
1821 WHERE cust_acct_profile_amt_id = p_cust_acct_profile_amt_id;
1822
1823 CURSOR c_hz_parties IS
1824 SELECT tax_name, year_established,
1825 sic_code, -- industrial code
1826 sic_code_type, -- industrial code type
1827 url,
1828 employees_total,
1829 duns_number
1830 FROM hz_parties
1831 WHERE party_id = p_party_id;
1832
1833
1834 CURSOR c_credit_requests IS
1835 SELECT bond_rating,
1836 pending_litigations,
1837 entity_type,
1838 stock_exchange,
1839 current_stock_price,
1840 market_capitalization,
1841 nvl(limit_amount, trx_amount) requested_amount,
1842 market_cap_monetary_unit,
1843 legal_entity_name
1844 FROM ar_cmgt_credit_requests
1845 WHERE credit_request_id = p_credit_request_id;
1846
1847 CURSOR c_case_folder IS
1848 SELECT last_updated, -- last_credit_review_date
1849 case_folder_number,
1850 status,
1851 check_list_id
1852 FROM ar_cmgt_case_folders
1853 WHERE party_id = p_party_id
1854 AND cust_account_id = p_cust_account_id
1855 AND site_use_id = p_site_use_id
1856 AND type = 'DATA';
1857
1858 CURSOR c_case_folder_score IS
1859 SELECT SUM(b.score) score
1860 FROM ar_cmgt_case_folders a, ar_cmgt_cf_dtls b
1861 WHERE a.party_id = p_party_id
1862 AND a.cust_account_id = p_cust_account_id
1863 AND a.site_use_id = p_site_use_id
1864 AND a.type = 'DATA'
1865 AND a.case_folder_id = b.case_folder_id;
1866
1867
1868 BEGIN
1869 IF pg_wf_debug = 'Y'
1870 THEN
1871 ar_cmgt_util.wf_debug(p_case_folder_id,
1872 'ar_cmgt_data_points_pkg.getotherdatapoints()+');
1873 END IF;
1874
1875 FOR c_hz_cust_prof_amts_rec IN c_hz_cust_prof_amts
1876 LOOP
1877 build_case_folder_details(
1878 p_case_folder_id => p_case_folder_id,
1879 p_data_point_id => 95,
1880 p_data_point_value => fnd_number.number_to_canonical(c_hz_cust_prof_amts_rec.trx_credit_limit),
1881 p_mode => p_mode,
1882 p_error_msg => l_errmsg,
1883 p_resultout => l_resultout);
1884
1885 build_case_folder_details(
1886 p_case_folder_id => p_case_folder_id,
1887 p_data_point_id => 96,
1888 p_data_point_value => fnd_number.number_to_canonical(c_hz_cust_prof_amts_rec.overall_credit_limit),
1889 p_mode => p_mode,
1890 p_error_msg => l_errmsg,
1891 p_resultout => l_resultout);
1892 exit;
1893 END LOOP;
1894
1895 FOR c_hz_parties_rec IN c_hz_parties
1896 LOOP
1897
1898 build_case_folder_details(
1899 p_case_folder_id => p_case_folder_id,
1900 p_data_point_id => 89,
1901 p_data_point_value => c_hz_parties_rec.tax_name,
1902 p_mode => p_mode,
1903 p_error_msg => l_errmsg,
1904 p_resultout => l_resultout);
1905
1906 build_case_folder_details(
1907 p_case_folder_id => p_case_folder_id,
1908 p_data_point_id => 93,
1909 p_data_point_value => c_hz_parties_rec.sic_code_type,
1910 p_mode => p_mode,
1911 p_error_msg => l_errmsg,
1912 p_resultout => l_resultout);
1913 build_case_folder_details(
1914 p_case_folder_id => p_case_folder_id,
1915 p_data_point_id => 92,
1916 p_data_point_value => c_hz_parties_rec.sic_code,
1917 p_mode => p_mode,
1918 p_error_msg => l_errmsg,
1919 p_resultout => l_resultout);
1920 build_case_folder_details(
1921 p_case_folder_id => p_case_folder_id,
1922 p_data_point_id => 100,
1923 p_data_point_value => c_hz_parties_rec.url,
1924 p_mode => p_mode,
1925 p_error_msg => l_errmsg,
1926 p_resultout => l_resultout);
1927 build_case_folder_details(
1928 p_case_folder_id => p_case_folder_id,
1929 p_data_point_id => 101,
1930 p_data_point_value => c_hz_parties_rec.employees_total,
1931 p_mode => p_mode,
1932 p_error_msg => l_errmsg,
1933 p_resultout => l_resultout);
1934 build_case_folder_details(
1935 p_case_folder_id => p_case_folder_id,
1936 p_data_point_id => 183,
1937 p_data_point_value => c_hz_parties_rec.duns_number,
1938 p_mode => p_mode,
1939 p_error_msg => l_errmsg,
1940 p_resultout => l_resultout);
1941 exit;
1942 END LOOP;
1943
1944 FOR c_credit_requests_rec IN c_credit_requests
1945 LOOP
1946 build_case_folder_details(
1947 p_case_folder_id => p_case_folder_id,
1948 p_data_point_id => 103,
1949 p_data_point_value => c_credit_requests_rec.bond_rating,
1950 p_mode => p_mode,
1951 p_error_msg => l_errmsg,
1952 p_resultout => l_resultout);
1953 build_case_folder_details(
1954 p_case_folder_id => p_case_folder_id,
1955 p_data_point_id => 94,
1956 p_data_point_value => c_credit_requests_rec.pending_litigations,
1957 p_mode => p_mode,
1958 p_error_msg => l_errmsg,
1959 p_resultout => l_resultout);
1960 build_case_folder_details(
1961 p_case_folder_id => p_case_folder_id,
1962 p_data_point_id => 90,
1963 p_data_point_value => c_credit_requests_rec.entity_type,
1964 p_mode => p_mode,
1965 p_error_msg => l_errmsg,
1966 p_resultout => l_resultout);
1967 build_case_folder_details(
1968 p_case_folder_id => p_case_folder_id,
1969 p_data_point_id => 155,
1970 p_data_point_value => c_credit_requests_rec.stock_exchange,
1971 p_mode => p_mode,
1972 p_error_msg => l_errmsg,
1973 p_resultout => l_resultout);
1974 build_case_folder_details(
1975 p_case_folder_id => p_case_folder_id,
1976 p_data_point_id => 98,
1977 p_data_point_value => fnd_number.number_to_canonical(c_credit_requests_rec.current_stock_price),
1978 p_mode => p_mode,
1979 p_error_msg => l_errmsg,
1980 p_resultout => l_resultout);
1981 build_case_folder_details(
1982 p_case_folder_id => p_case_folder_id,
1983 p_data_point_id => 99,
1984 p_data_point_value => fnd_number.number_to_canonical(c_credit_requests_rec.market_capitalization),
1985 p_mode => p_mode,
1986 p_error_msg => l_errmsg,
1987 p_resultout => l_resultout);
1988 build_case_folder_details(
1989 p_case_folder_id => p_case_folder_id,
1990 p_data_point_id => 108,
1991 p_data_point_value => fnd_number.number_to_canonical(c_credit_requests_rec.requested_amount),
1992 p_mode => p_mode,
1993 p_error_msg => l_errmsg,
1994 p_resultout => l_resultout);
1995 build_case_folder_details(
1996 p_case_folder_id => p_case_folder_id,
1997 p_data_point_id => 208,
1998 p_data_point_value => c_credit_requests_rec.legal_entity_name,
1999 p_mode => p_mode,
2000 p_error_msg => l_errmsg,
2001 p_resultout => l_resultout);
2002 exit;
2003 END LOOP;
2004
2005
2006 FOR c_case_folder_rec IN c_case_folder
2007 LOOP
2008 build_case_folder_details(
2009 p_case_folder_id => p_case_folder_id,
2010 p_data_point_id => 105, -- last credit review date
2011 p_data_point_value => c_case_folder_rec.last_updated,
2012 p_mode => p_mode,
2013 p_error_msg => l_errmsg,
2014 p_resultout => l_resultout);
2015 build_case_folder_details(
2016 p_case_folder_id => p_case_folder_id,
2017 p_data_point_id => 106, -- last check list used
2018 p_data_point_value => c_case_folder_rec.check_list_id,
2019 p_mode => p_mode,
2020 p_error_msg => l_errmsg,
2021 p_resultout => l_resultout);
2022 build_case_folder_details(
2023 p_case_folder_id => p_case_folder_id,
2024 p_data_point_id => 107, -- last case folder
2025 p_data_point_value => c_case_folder_rec.case_folder_number,
2026 p_mode => p_mode,
2027 p_error_msg => l_errmsg,
2028 p_resultout => l_resultout);
2029 exit;
2030 END LOOP;
2031 FOR c_case_folder_score_rec IN c_case_folder_score
2032 LOOP
2033 build_case_folder_details(
2034 p_case_folder_id => p_case_folder_id,
2035 p_data_point_id => 30, -- last calculated credit score
2036 p_data_point_value => fnd_number.number_to_canonical(c_case_folder_score_rec.score),
2037 p_mode => p_mode,
2038 p_error_msg => l_errmsg,
2039 p_resultout => l_resultout);
2040 exit;
2041 END LOOP;
2042 IF pg_wf_debug = 'Y'
2043 THEN
2044 ar_cmgt_util.wf_debug(p_case_folder_id,
2045 'ar_cmgt_data_points_pkg.getotherdatapoints()-');
2046 END IF;
2047 END;
2048
2049
2050 PROCEDURE populate_aging_data
2051 (p_case_folder_id IN NUMBER,
2052 p_mode IN VARCHAR2 default 'CREATE',
2053 p_error_msg OUT NOCOPY VARCHAR2,
2054 p_resultout OUT NOCOPY VARCHAR2) IS
2055
2056 CURSOR aging_cur IS
2057 SELECT age.aging_bucket_id,age.aging_bucket_line_id
2058 FROM AR_CMGT_SETUP_OPTIONS sys,
2059 ar_aging_bucket_lines age
2060 WHERE sys.aging_bucket_id = age.aging_bucket_id;
2061
2062 l_outstanding_balance NUMBER;
2063 l_dispute_amount NUMBER;
2064 l_customer_id number;
2065 l_party_id number;
2066 l_cust_account_id number;
2067 l_customer_site_use_id number;
2068 l_as_of_date date;
2069 l_currency_code fnd_currencies.currency_code%TYPE;
2070 l_format_currency varchar2(15);
2071 l_credit_option varchar2(16);
2072 l_invoice_type_low ra_cust_trx_types.name%TYPE;
2073 l_invoice_type_high ra_cust_trx_types.name%TYPE;
2074 l_bucket_name ar_aging_buckets.bucket_name%TYPE;
2075 l_bucket_titletop_0 ar_aging_bucket_lines.report_heading1%TYPE;
2076 l_bucket_titlebottom_0 ar_aging_bucket_lines.report_heading2%TYPE;
2077 l_bucket_amount_0 number;
2078 l_bucket_titletop_1 ar_aging_bucket_lines.report_heading1%TYPE;
2079 l_bucket_titlebottom_1 ar_aging_bucket_lines.report_heading2%TYPE;
2080 l_bucket_amount_1 number;
2081 l_bucket_titletop_2 ar_aging_bucket_lines.report_heading1%TYPE;
2082 l_bucket_titlebottom_2 ar_aging_bucket_lines.report_heading2%TYPE;
2083 l_bucket_amount_2 number;
2084 l_bucket_titletop_3 ar_aging_bucket_lines.report_heading1%TYPE;
2085 l_bucket_titlebottom_3 ar_aging_bucket_lines.report_heading2%TYPE;
2086 l_bucket_amount_3 number;
2087 l_bucket_titletop_4 ar_aging_bucket_lines.report_heading1%TYPE;
2088 l_bucket_titlebottom_4 ar_aging_bucket_lines.report_heading2%TYPE;
2089 l_bucket_amount_4 number;
2090 l_bucket_titletop_5 ar_aging_bucket_lines.report_heading1%TYPE;
2091 l_bucket_titlebottom_5 ar_aging_bucket_lines.report_heading2%TYPE;
2092 l_bucket_amount_5 number;
2093 l_bucket_titletop_6 ar_aging_bucket_lines.report_heading1%TYPE;
2094 l_bucket_titlebottom_6 ar_aging_bucket_lines.report_heading2%TYPE;
2095 l_bucket_amount_6 number;
2096 l_outstanding_amount number;
2097
2098 l_check_flag VARCHAR2(1);
2099 l_counter NUMBER;
2100
2101 l_credit_request_id NUMBER;
2102 l_exchange_rate_type VARCHAR2(50);
2103
2104 BEGIN
2105 IF pg_wf_debug = 'Y'
2106 THEN
2107 ar_cmgt_util.wf_debug(p_case_folder_id,
2108 'ar_cmgt_data_points_pkg.populate_aging_data()+');
2109 END IF;
2110
2111 l_check_flag := 'Y';
2112
2113 BEGIN
2114 SELECT DECODE(party_id,-99,NULL,party_id),
2115 DECODE(cust_account_id,-99,NULL,cust_account_id),
2116 DECODE(site_use_id,-99,NULL,site_use_id),
2117 limit_currency,
2118 credit_request_id
2119 INTO l_party_id,
2120 l_cust_account_id,
2121 l_customer_site_use_id,
2122 l_currency_code,
2123 l_credit_request_id
2124 FROM ar_cmgt_case_folders
2125 WHERE case_folder_id = p_case_folder_id;
2126 EXCEPTION
2127 WHEN others THEN
2128 l_check_flag := 'N';
2129 END;
2130
2131 BEGIN
2132 SELECT age.bucket_name,
2133 default_exchange_rate_type
2134 INTO l_bucket_name,
2135 l_exchange_rate_type
2136 FROM AR_CMGT_SETUP_OPTIONS sys,
2137 ar_aging_buckets age
2138 WHERE sys.aging_bucket_id = age.aging_bucket_id;
2139 EXCEPTION
2140 WHEN others THEN
2141 l_check_flag := 'N';
2142 END;
2143
2144 IF l_check_flag = 'Y' THEN
2145 AR_CMGT_AGING.calc_aging_buckets (
2146 p_party_id => l_party_id,
2147 p_customer_id => l_cust_account_id,
2148 p_site_use_id => l_customer_site_use_id,
2149 p_currency_code => l_currency_code,
2150 p_credit_option => 'AGE',
2151 p_bucket_name => l_bucket_name,
2152 p_org_id => NULL,
2153 p_exchange_rate_type => l_exchange_rate_type,
2154 p_outstanding_balance => l_outstanding_balance,
2155 p_bucket_titletop_0 => l_bucket_titletop_0,
2156 p_bucket_titlebottom_0 => l_bucket_titlebottom_0,
2157 p_bucket_amount_0 => l_bucket_amount_0,
2158 p_bucket_titletop_1 => l_bucket_titletop_1,
2159 p_bucket_titlebottom_1 => l_bucket_titlebottom_1,
2160 p_bucket_amount_1 => l_bucket_amount_1,
2161 p_bucket_titletop_2 => l_bucket_titletop_2,
2162 p_bucket_titlebottom_2 => l_bucket_titlebottom_2,
2163 p_bucket_amount_2 => l_bucket_amount_2,
2164 p_bucket_titletop_3 => l_bucket_titletop_3,
2165 p_bucket_titlebottom_3 => l_bucket_titlebottom_3,
2166 p_bucket_amount_3 => l_bucket_amount_3,
2167 p_bucket_titletop_4 => l_bucket_titletop_4,
2168 p_bucket_titlebottom_4 => l_bucket_titlebottom_4,
2169 p_bucket_amount_4 => l_bucket_amount_4,
2170 p_bucket_titletop_5 => l_bucket_titletop_5,
2171 p_bucket_titlebottom_5 => l_bucket_titlebottom_5,
2172 p_bucket_amount_5 => l_bucket_amount_5,
2173 p_bucket_titletop_6 => l_bucket_titletop_6,
2174 p_bucket_titlebottom_6 => l_bucket_titlebottom_6,
2175 p_bucket_amount_6 => l_bucket_amount_6
2176 );
2177 l_counter := 0;
2178
2179 FOR aging_rec IN aging_cur LOOP
2180
2181 IF l_counter = 0 THEN
2182 IF p_mode = 'CREATE'
2183 THEN
2184 ar_cmgt_controls.populate_aging_dtls
2185 (p_case_folder_id => p_case_folder_id,
2186 p_aging_bucket_id => aging_rec.aging_bucket_id,
2187 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2188 p_amount => l_bucket_amount_0,
2189 p_error_msg => p_error_msg,
2190 p_resultout => p_resultout);
2191 IF p_resultout <> 0
2192 THEN
2193 return;
2194 END IF;
2195 IF g_data_case_folder_exists = 'Y' -- for data record
2196 THEN
2197 ar_cmgt_controls.update_aging_dtls
2198 (p_case_folder_id => g_data_case_folder_id,
2199 p_aging_bucket_id => aging_rec.aging_bucket_id,
2200 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2201 p_amount => l_bucket_amount_0,
2202 p_error_msg => p_error_msg,
2203 p_resultout => p_resultout);
2204 ELSIF g_data_case_folder_exists = 'N'
2205 THEN
2206 ar_cmgt_controls.populate_aging_dtls
2207 (p_case_folder_id => g_data_case_folder_id,
2208 p_aging_bucket_id => aging_rec.aging_bucket_id,
2209 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2210 p_amount => l_bucket_amount_0,
2211 p_error_msg => p_error_msg,
2212 p_resultout => p_resultout);
2213 END IF;
2214 IF p_resultout <> 0
2215 THEN
2216 return;
2217 END IF;
2218 ELSIF p_mode = 'REFRESH'
2219 THEN
2220 ar_cmgt_controls.update_aging_dtls
2221 (p_case_folder_id => p_case_folder_id,
2222 p_aging_bucket_id => aging_rec.aging_bucket_id,
2223 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2224 p_amount => l_bucket_amount_0,
2225 p_error_msg => p_error_msg,
2226 p_resultout => p_resultout);
2227
2228 IF p_resultout <> 0
2229 THEN
2230 return;
2231 END IF;
2232
2233 END IF; -- end of p_mode if
2234 END IF;
2235 IF l_counter = 1 THEN
2236 IF p_mode = 'CREATE'
2237 THEN
2238 ar_cmgt_controls.populate_aging_dtls
2239 (p_case_folder_id => p_case_folder_id,
2240 p_aging_bucket_id => aging_rec.aging_bucket_id,
2241 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2242 p_amount => l_bucket_amount_1,
2243 p_error_msg => p_error_msg,
2244 p_resultout => p_resultout);
2245 IF p_resultout <> 0
2246 THEN
2247 return;
2248 END IF;
2249 IF g_data_case_folder_exists = 'Y' -- for data record
2250 THEN
2251 ar_cmgt_controls.update_aging_dtls
2252 (p_case_folder_id => g_data_case_folder_id,
2253 p_aging_bucket_id => aging_rec.aging_bucket_id,
2254 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2255 p_amount => l_bucket_amount_1,
2256 p_error_msg => p_error_msg,
2257 p_resultout => p_resultout);
2258 ELSIF g_data_case_folder_exists = 'N'
2259 THEN
2260 ar_cmgt_controls.populate_aging_dtls
2261 (p_case_folder_id => g_data_case_folder_id,
2262 p_aging_bucket_id => aging_rec.aging_bucket_id,
2263 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2264 p_amount => l_bucket_amount_1,
2265 p_error_msg => p_error_msg,
2266 p_resultout => p_resultout);
2267 END IF;
2268 IF p_resultout <> 0
2269 THEN
2270 return;
2271 END IF;
2272 ELSIF p_mode = 'REFRESH'
2273 THEN
2274 ar_cmgt_controls.update_aging_dtls
2275 (p_case_folder_id => p_case_folder_id,
2276 p_aging_bucket_id => aging_rec.aging_bucket_id,
2277 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2278 p_amount => l_bucket_amount_1,
2279 p_error_msg => p_error_msg,
2280 p_resultout => p_resultout);
2281
2282 IF p_resultout <> 0
2283 THEN
2284 return;
2285 END IF;
2286
2287 END IF; -- end of p_mode if
2288 END IF;
2289 IF l_counter = 2 THEN
2290 IF p_mode = 'CREATE'
2291 THEN
2292 ar_cmgt_controls.populate_aging_dtls
2293 (p_case_folder_id => p_case_folder_id,
2294 p_aging_bucket_id => aging_rec.aging_bucket_id,
2295 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2296 p_amount => l_bucket_amount_2,
2297 p_error_msg => p_error_msg,
2298 p_resultout => p_resultout);
2299 IF p_resultout <> 0
2300 THEN
2301 return;
2302 END IF;
2303 IF g_data_case_folder_exists = 'Y' -- for data record
2304 THEN
2305 ar_cmgt_controls.update_aging_dtls
2306 (p_case_folder_id => g_data_case_folder_id,
2307 p_aging_bucket_id => aging_rec.aging_bucket_id,
2308 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2309 p_amount => l_bucket_amount_2,
2310 p_error_msg => p_error_msg,
2311 p_resultout => p_resultout);
2312 ELSIF g_data_case_folder_exists = 'N'
2313 THEN
2314 ar_cmgt_controls.populate_aging_dtls
2315 (p_case_folder_id => g_data_case_folder_id,
2316 p_aging_bucket_id => aging_rec.aging_bucket_id,
2317 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2318 p_amount => l_bucket_amount_2,
2319 p_error_msg => p_error_msg,
2320 p_resultout => p_resultout);
2321 END IF;
2322 IF p_resultout <> 0
2323 THEN
2324 return;
2325 END IF;
2326 ELSIF p_mode = 'REFRESH'
2327 THEN
2328 ar_cmgt_controls.update_aging_dtls
2329 (p_case_folder_id => p_case_folder_id,
2330 p_aging_bucket_id => aging_rec.aging_bucket_id,
2331 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2332 p_amount => l_bucket_amount_2,
2333 p_error_msg => p_error_msg,
2334 p_resultout => p_resultout);
2335
2336 IF p_resultout <> 0
2337 THEN
2338 return;
2339 END IF;
2340
2341 END IF; -- end of p_mode if
2342 END IF;
2343 IF l_counter = 3 THEN
2344 IF p_mode = 'CREATE'
2345 THEN
2346 ar_cmgt_controls.populate_aging_dtls
2347 (p_case_folder_id => p_case_folder_id,
2348 p_aging_bucket_id => aging_rec.aging_bucket_id,
2349 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2350 p_amount => l_bucket_amount_3,
2351 p_error_msg => p_error_msg,
2352 p_resultout => p_resultout);
2353 IF p_resultout <> 0
2354 THEN
2355 return;
2356 END IF;
2357 IF g_data_case_folder_exists = 'Y' -- for data record
2358 THEN
2359 ar_cmgt_controls.update_aging_dtls
2360 (p_case_folder_id => g_data_case_folder_id,
2361 p_aging_bucket_id => aging_rec.aging_bucket_id,
2362 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2363 p_amount => l_bucket_amount_3,
2364 p_error_msg => p_error_msg,
2365 p_resultout => p_resultout);
2366 ELSIF g_data_case_folder_exists = 'N'
2367 THEN
2368 ar_cmgt_controls.populate_aging_dtls
2369 (p_case_folder_id => g_data_case_folder_id,
2370 p_aging_bucket_id => aging_rec.aging_bucket_id,
2371 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2372 p_amount => l_bucket_amount_3,
2373 p_error_msg => p_error_msg,
2374 p_resultout => p_resultout);
2375 END IF;
2376 IF p_resultout <> 0
2377 THEN
2378 return;
2379 END IF;
2380 ELSIF p_mode = 'REFRESH'
2381 THEN
2382 ar_cmgt_controls.update_aging_dtls
2383 (p_case_folder_id => p_case_folder_id,
2384 p_aging_bucket_id => aging_rec.aging_bucket_id,
2385 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2386 p_amount => l_bucket_amount_3,
2387 p_error_msg => p_error_msg,
2388 p_resultout => p_resultout);
2389
2390 IF p_resultout <> 0
2391 THEN
2392 return;
2393 END IF;
2394
2395 END IF; -- end of p_mode if
2396 END IF;
2397 IF l_counter = 4 THEN
2398 IF p_mode = 'CREATE'
2399 THEN
2400 ar_cmgt_controls.populate_aging_dtls
2401 (p_case_folder_id => p_case_folder_id,
2402 p_aging_bucket_id => aging_rec.aging_bucket_id,
2403 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2404 p_amount => l_bucket_amount_4,
2405 p_error_msg => p_error_msg,
2406 p_resultout => p_resultout);
2407 IF p_resultout <> 0
2408 THEN
2409 return;
2410 END IF;
2411 IF g_data_case_folder_exists = 'Y' -- for data record
2412 THEN
2413 ar_cmgt_controls.update_aging_dtls
2414 (p_case_folder_id => g_data_case_folder_id,
2415 p_aging_bucket_id => aging_rec.aging_bucket_id,
2416 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2417 p_amount => l_bucket_amount_4,
2418 p_error_msg => p_error_msg,
2419 p_resultout => p_resultout);
2420 ELSIF g_data_case_folder_exists = 'N'
2421 THEN
2422 ar_cmgt_controls.populate_aging_dtls
2423 (p_case_folder_id => g_data_case_folder_id,
2424 p_aging_bucket_id => aging_rec.aging_bucket_id,
2425 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2426 p_amount => l_bucket_amount_4,
2427 p_error_msg => p_error_msg,
2428 p_resultout => p_resultout);
2429 END IF;
2430 IF p_resultout <> 0
2431 THEN
2432 return;
2433 END IF;
2434 ELSIF p_mode = 'REFRESH'
2435 THEN
2436 ar_cmgt_controls.update_aging_dtls
2437 (p_case_folder_id => p_case_folder_id,
2438 p_aging_bucket_id => aging_rec.aging_bucket_id,
2439 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2440 p_amount => l_bucket_amount_4,
2441 p_error_msg => p_error_msg,
2442 p_resultout => p_resultout);
2443
2444 IF p_resultout <> 0
2445 THEN
2446 return;
2447 END IF;
2448
2449 END IF; -- end of p_mode if
2450 END IF;
2451 IF l_counter = 5 THEN
2452 IF p_mode = 'CREATE'
2453 THEN
2454 ar_cmgt_controls.populate_aging_dtls
2455 (p_case_folder_id => p_case_folder_id,
2456 p_aging_bucket_id => aging_rec.aging_bucket_id,
2457 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2458 p_amount => l_bucket_amount_5,
2459 p_error_msg => p_error_msg,
2460 p_resultout => p_resultout);
2461 IF p_resultout <> 0
2462 THEN
2463 return;
2464 END IF;
2465 IF g_data_case_folder_exists = 'Y' -- for data record
2466 THEN
2467 ar_cmgt_controls.update_aging_dtls
2468 (p_case_folder_id => g_data_case_folder_id,
2469 p_aging_bucket_id => aging_rec.aging_bucket_id,
2470 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2471 p_amount => l_bucket_amount_5,
2472 p_error_msg => p_error_msg,
2473 p_resultout => p_resultout);
2474 ELSIF g_data_case_folder_exists = 'N'
2475 THEN
2476 ar_cmgt_controls.populate_aging_dtls
2477 (p_case_folder_id => g_data_case_folder_id,
2478 p_aging_bucket_id => aging_rec.aging_bucket_id,
2479 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2480 p_amount => l_bucket_amount_5,
2481 p_error_msg => p_error_msg,
2482 p_resultout => p_resultout);
2483 END IF;
2484 IF p_resultout <> 0
2485 THEN
2486 return;
2487 END IF;
2488 ELSIF p_mode = 'REFRESH'
2489 THEN
2490 ar_cmgt_controls.update_aging_dtls
2491 (p_case_folder_id => p_case_folder_id,
2492 p_aging_bucket_id => aging_rec.aging_bucket_id,
2493 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2494 p_amount => l_bucket_amount_5,
2495 p_error_msg => p_error_msg,
2496 p_resultout => p_resultout);
2497
2498 IF p_resultout <> 0
2499 THEN
2500 return;
2501 END IF;
2502
2503 END IF; -- end of p_mode if
2504 END IF;
2505 IF l_counter = 6 THEN
2506 IF p_mode = 'CREATE'
2507 THEN
2508 ar_cmgt_controls.populate_aging_dtls
2509 (p_case_folder_id => p_case_folder_id,
2510 p_aging_bucket_id => aging_rec.aging_bucket_id,
2511 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2512 p_amount => l_bucket_amount_6,
2513 p_error_msg => p_error_msg,
2514 p_resultout => p_resultout);
2515 IF p_resultout <> 0
2516 THEN
2517 return;
2518 END IF;
2519 IF g_data_case_folder_exists = 'Y' -- for data record
2520 THEN
2521 ar_cmgt_controls.update_aging_dtls
2522 (p_case_folder_id => g_data_case_folder_id,
2523 p_aging_bucket_id => aging_rec.aging_bucket_id,
2524 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2525 p_amount => l_bucket_amount_6,
2526 p_error_msg => p_error_msg,
2527 p_resultout => p_resultout);
2528 ELSIF g_data_case_folder_exists = 'N'
2529 THEN
2530 ar_cmgt_controls.populate_aging_dtls
2531 (p_case_folder_id => g_data_case_folder_id,
2532 p_aging_bucket_id => aging_rec.aging_bucket_id,
2533 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2534 p_amount => l_bucket_amount_6,
2535 p_error_msg => p_error_msg,
2536 p_resultout => p_resultout);
2537 END IF;
2538 IF p_resultout <> 0
2539 THEN
2540 return;
2541 END IF;
2542 ELSIF p_mode = 'REFRESH'
2543 THEN
2544 ar_cmgt_controls.update_aging_dtls
2545 (p_case_folder_id => p_case_folder_id,
2546 p_aging_bucket_id => aging_rec.aging_bucket_id,
2547 p_aging_bucket_line_id => aging_rec.aging_bucket_line_id,
2548 p_amount => l_bucket_amount_6,
2549 p_error_msg => p_error_msg,
2550 p_resultout => p_resultout);
2551
2552 IF p_resultout <> 0
2553 THEN
2554 return;
2555 END IF;
2556
2557 END IF; -- end of p_mode if
2558 END IF;
2559 l_counter := l_counter + 1;
2560 END LOOP;
2561 END IF;
2562
2563 IF pg_wf_debug = 'Y'
2564 THEN
2565 ar_cmgt_util.wf_debug(p_case_folder_id,
2566 'ar_cmgt_data_points_pkg.populate_aging_data()-');
2567 END IF;
2568 end populate_aging_data;
2569
2570
2571 PROCEDURE populate_dnb_data(
2572 p_case_folder_id IN NUMBER,
2573 p_source_table_name IN VARCHAR2,
2574 p_source_key IN VARCHAR2,
2575 p_source_key_column_name IN VARCHAR2,
2576 p_mode IN VARCHAR2 default 'CREATE',
2577 p_source_key_type IN VARCHAR2 default NULL,
2578 p_source_key_column_type IN VARCHAR2 default NULL) IS
2579
2580 l_errmsg VARCHAR2(4000);
2581 l_resultout VARCHAR2(1);
2582
2583 BEGIN
2584 IF pg_wf_debug = 'Y'
2585 THEN
2586 ar_cmgt_util.wf_debug(p_case_folder_id,
2587 'ar_cmgt_data_points_pkg.populate_dnb_data()+');
2588 END IF;
2589
2590 -- call table handler to insert into ar_cmgt_cf_dnb_dtls.
2591 IF p_mode = 'CREATE'
2592 THEN
2593 AR_CMGT_CONTROLS.populate_dnb_data(
2594 p_case_folder_id => p_case_folder_id,
2595 p_source_table_name => p_source_table_name,
2596 p_source_key => p_source_key,
2597 p_source_key_type => p_source_key_type,
2598 p_source_key_column_name => p_source_key_column_name,
2599 p_source_key_column_type => p_source_key_column_type,
2600 p_errmsg => l_errmsg,
2601 p_resultout => l_resultout);
2602
2603 ELSIF p_mode = 'REFRESH'
2604 THEN
2605 UPDATE ar_cmgt_cf_dnb_dtls
2606 SET source_key = p_source_key,
2607 last_updated_by = fnd_global.user_id,
2608 last_update_date = sysdate,
2609 last_update_login = fnd_global.login_id
2610 WHERE case_folder_id = p_case_folder_id
2611 AND source_table_name = p_source_table_name
2612 AND nvl(source_key,'X') = nvl(p_source_key,'X')
2613 AND nvl(source_key_type,'X') = nvl(p_source_key_type,'X')
2614 AND nvl(source_key_column_name,'X') = nvl(p_source_key_column_name,'X')
2615 AND nvl(source_key_column_type_name,'X') = nvl(p_source_key_column_type,'X');
2616 -- Bug fix for 3566584
2617 -- Dnb data won't be updated if it was not created
2618 -- as part of case folder generation. So if user
2619 -- purchased dnb data leter on then it will not be updated.
2620 IF ( SQL%NOTFOUND )
2621 THEN
2622 AR_CMGT_CONTROLS.populate_dnb_data(
2623 p_case_folder_id => p_case_folder_id,
2624 p_source_table_name => p_source_table_name,
2625 p_source_key => p_source_key,
2626 p_source_key_type => p_source_key_type,
2627 p_source_key_column_name => p_source_key_column_name,
2628 p_source_key_column_type => p_source_key_column_type,
2629 p_errmsg => l_errmsg,
2630 p_resultout => l_resultout);
2631 END IF;
2632
2633
2634 END IF;
2635 IF pg_wf_debug = 'Y'
2636 THEN
2637 ar_cmgt_util.wf_debug(p_case_folder_id,
2638 'ar_cmgt_data_points_pkg.populate_dnb_data()-');
2639 END IF;
2640 END;
2641
2642
2643 PROCEDURE build_case_folder
2644 (p_party_id IN NUMBER,
2645 p_cust_account_id IN NUMBER,
2646 p_cust_acct_site_id IN NUMBER,
2647 p_limit_currency IN VARCHAR2,
2648 p_exchange_rate_type IN VARCHAR2,
2649 p_check_list_id IN NUMBER default NULL,
2650 p_credit_request_id IN NUMBER default NULL,
2651 p_score_model_id IN NUMBER default NULL,
2652 p_credit_classification IN VARCHAR2 default NULL,
2653 p_review_type IN VARCHAR2 default NULL,
2654 p_case_folder_number IN VARCHAR2 default NULL,
2655 p_case_folder_id OUT nocopy NUMBER,
2656 p_error_msg OUT nocopy VARCHAR2,
2657 p_resultout OUT nocopy VARCHAR2) AS
2658
2659 l_case_folder_number ar_cmgt_case_folders.case_folder_number%TYPE;
2660 l_case_folder_id ar_cmgt_case_folders.case_folder_id%TYPE;
2661 BEGIN
2662 p_resultout := 0;
2663 g_data_case_folder_exists := 'N';
2664 -- Get id from sequence
2665 SELECT ar_cmgt_case_folders_s.nextval
2666 INTO p_case_folder_id
2667 FROM dual;
2668
2669 IF pg_wf_debug = 'Y'
2670 THEN
2671 ar_cmgt_util.wf_debug(p_case_folder_id,
2672 'ar_cmgt_data_points_pkg.build_case_folder()+');
2673 END IF;
2674
2675 -- check if case folder number is passed by calling program
2676 IF p_case_folder_number IS NULL
2677 THEN
2678 SELECT ar_cmgt_case_folder_number_s.nextval
2679 INTO l_case_folder_number
2680 FROM dual;
2681 ELSE
2682 l_case_folder_number := p_case_folder_number;
2683 END IF;
2684 -- insert into case_folder table
2685 AR_CMGT_CONTROLS.populate_case_folder (
2686 p_case_folder_id => p_case_folder_id,
2687 p_case_folder_number => l_case_folder_number,
2688 p_credit_request_id => p_credit_request_id,
2689 p_check_list_id => p_check_list_id,
2690 p_status => 'O',
2691 p_cust_account_id => nvl(p_cust_account_id,-99),
2692 p_party_id => p_party_id,
2693 p_cust_acct_site_id => nvl(p_cust_acct_site_id,-99),
2694 p_score_model_id => p_score_model_id,
2695 p_credit_classification => p_credit_classification,
2696 p_review_type => p_review_type,
2697 p_limit_currency => p_limit_currency,
2698 p_exchange_rate_type => p_exchange_rate_type,
2699 p_type => 'CASE',
2700 p_errmsg => p_error_msg,
2701 p_resultout => p_resultout);
2702 IF p_resultout <> 0
2703 THEN
2704 return;
2705 END IF;
2706 -- check whether there are any 'DATA' records for the party,account and site
2707 -- combination. If not exist insert a new record.
2708
2709 BEGIN
2710 SELECT case_folder_id
2711 INTO g_data_case_folder_id
2712 FROM ar_cmgt_case_folders
2713 WHERE party_id = p_party_id
2714 AND cust_account_id = p_cust_account_id
2715 AND site_use_id = p_cust_acct_site_id
2716 -- AND limit_currency = p_limit_currency
2717 AND type = 'DATA';
2718
2719 g_data_case_folder_exists := 'Y';
2720 -- update case folder number in case data exists
2721
2722 UPDATE ar_cmgt_case_folders
2723 set case_folder_number = l_case_folder_number,
2724 check_list_id = p_check_list_id,
2725 score_model_id = p_score_model_id,
2726 limit_currency = p_limit_currency,
2727 exchange_rate_type = p_exchange_rate_type,
2728 credit_classification = p_credit_classification,
2729 last_update_date = SYSDATE,
2730 last_updated_by = fnd_global.user_id,
2731 last_update_login = fnd_global.login_id,
2732 last_updated = sysdate,
2733 credit_request_id = p_credit_request_id
2734 WHERE party_id = p_party_id
2735 AND cust_account_id = p_cust_account_id
2736 AND site_use_id = p_cust_acct_site_id
2737 AND type = 'DATA';
2738
2739 g_data_case_folder_exists := 'Y';
2740 EXCEPTION
2741 WHEN NO_DATA_FOUND THEN
2742 BEGIN
2743 SELECT ar_cmgt_case_folders_s.nextval
2744 INTO g_data_case_folder_id
2745 FROM dual;
2746 g_data_case_folder_exists := 'N';
2747 AR_CMGT_CONTROLS.populate_case_folder (
2748 p_case_folder_id => g_data_case_folder_id,
2749 p_case_folder_number => l_case_folder_number,
2750 p_credit_request_id => p_credit_request_id,
2751 p_check_list_id => p_check_list_id,
2752 p_party_id => p_party_id,
2753 p_cust_account_id => p_cust_account_id,
2754 p_cust_acct_site_id => p_cust_acct_site_id,
2755 p_score_model_id => p_score_model_id,
2756 p_credit_classification => p_credit_classification,
2757 p_type => 'DATA',
2758 p_limit_currency => p_limit_currency,
2759 p_exchange_rate_type => p_exchange_rate_type,
2760 p_errmsg => p_error_msg,
2761 p_resultout => p_resultout);
2762
2763
2764 IF p_resultout <> 0
2765 THEN
2766 return;
2767 END IF;
2768 END;
2769 WHEN OTHERS THEN
2770 p_error_msg := 'Unable to create case folder DATA records for' ||
2771 'party id '|| to_char(p_party_id) ||' Cust Account Id '||
2772 to_char(p_cust_account_id)||' Cust Account Site Use Id '||
2773 to_char(p_cust_acct_site_id) ||'Sql Error '||sqlerrm;
2774 p_resultout := '1';
2775 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
2776 END;
2777
2778 IF pg_wf_debug = 'Y'
2779 THEN
2780 ar_cmgt_util.wf_debug(p_case_folder_id,
2781 'CR:' || p_credit_request_id || ' => CF:' ||
2782 p_case_folder_id);
2783 ar_cmgt_util.wf_debug(p_case_folder_id,
2784 'ar_cmgt_data_points_pkg.build_case_folder()-');
2785 END IF;
2786
2787 END build_case_folder;
2788
2789 PROCEDURE BUILD_DNB_SCORABLE_FIN_DATA (
2790 p_case_folder_id IN NUMBER,
2791 p_mode IN VARCHAR2 default 'CREATE',
2792 p_financial_report_id IN NUMBER,
2793 p_financial_report_type IN VARCHAR2,
2794 p_error_msg OUT nocopy VARCHAR2,
2795 p_resultout OUT nocopy VARCHAR2) IS
2796
2797 CURSOR cFinancialReports IS
2798 SELECT ESTIMATED_IND,
2799 CONSOLIDATED_IND,
2800 REPORT_START_DATE,
2801 REPORT_END_DATE,
2802 DATE_REPORT_ISSUED,
2803 AUDIT_IND,
2804 FORECAST_IND,
2805 FISCAL_IND,
2806 FINAL_IND,
2807 SIGNED_BY_PRINCIPALS_IND,
2808 RESTATED_IND,
2809 UNBALANCED_IND,
2810 QUALIFIED_IND,
2811 OPENING_IND,
2812 PROFORMA_IND,
2813 TRIAL_BALANCE_IND
2814 FROM hz_financial_reports
2815 WHERE financial_report_id = p_financial_report_id;
2816
2817 l_ESTIMATED_IND hz_financial_reports.ESTIMATED_IND%type;
2818 l_CONSOLIDATED_IND hz_financial_reports.CONSOLIDATED_IND%type;
2819 l_REPORT_START_DATE hz_financial_reports.REPORT_START_DATE%type;
2820 l_REPORT_END_DATE hz_financial_reports.REPORT_END_DATE%type;
2821 l_DATE_REPORT_ISSUED hz_financial_reports.DATE_REPORT_ISSUED%type;
2822 l_AUDIT_IND hz_financial_reports.AUDIT_IND%type;
2823 l_FORECAST_IND hz_financial_reports.FORECAST_IND%type;
2824 l_FISCAL_IND hz_financial_reports.FISCAL_IND%type;
2825 l_FINAL_IND hz_financial_reports.FINAL_IND%type;
2826 l_SIGNED_BY_PRINCIPALS_IND hz_financial_reports.SIGNED_BY_PRINCIPALS_IND%type;
2827 l_RESTATED_IND hz_financial_reports.RESTATED_IND%type;
2828 l_UNBALANCED_IND hz_financial_reports.UNBALANCED_IND%type;
2829 l_QUALIFIED_IND hz_financial_reports.QUALIFIED_IND%type;
2830 l_OPENING_IND hz_financial_reports.OPENING_IND%type;
2831 l_PROFORMA_IND hz_financial_reports.PROFORMA_IND%type;
2832 l_TRIAL_BALANCE_IND hz_financial_reports.TRIAL_BALANCE_IND%type;
2833
2834 BEGIN
2835 IF pg_wf_debug = 'Y'
2836 THEN
2837 ar_cmgt_util.wf_debug(p_case_folder_id,
2838 'ar_cmgt_data_points_pkg.build_dnb_scorable_fin_data()+');
2839 END IF;
2840
2841 FOR cFinancialReportsRec IN cFinancialReports
2842 LOOP
2843 l_ESTIMATED_IND := cFinancialReportsRec.ESTIMATED_IND;
2844 l_CONSOLIDATED_IND := cFinancialReportsRec.CONSOLIDATED_IND;
2845 l_REPORT_START_DATE := cFinancialReportsRec.REPORT_START_DATE;
2846 l_REPORT_END_DATE := cFinancialReportsRec.REPORT_END_DATE;
2847 l_DATE_REPORT_ISSUED := cFinancialReportsRec.DATE_REPORT_ISSUED;
2848 l_AUDIT_IND := cFinancialReportsRec.AUDIT_IND;
2849 l_FORECAST_IND := cFinancialReportsRec.FORECAST_IND;
2850 l_FISCAL_IND := cFinancialReportsRec.FISCAL_IND;
2851 l_FINAL_IND := cFinancialReportsRec.FINAL_IND;
2852 l_SIGNED_BY_PRINCIPALS_IND := cFinancialReportsRec.SIGNED_BY_PRINCIPALS_IND;
2853 l_RESTATED_IND := cFinancialReportsRec.RESTATED_IND;
2854 l_UNBALANCED_IND := cFinancialReportsRec.UNBALANCED_IND;
2855 l_QUALIFIED_IND := cFinancialReportsRec.QUALIFIED_IND;
2856 l_OPENING_IND := cFinancialReportsRec.OPENING_IND;
2857 l_PROFORMA_IND := cFinancialReportsRec.PROFORMA_IND;
2858 l_TRIAL_BALANCE_IND := cFinancialReportsRec.TRIAL_BALANCE_IND;
2859 END LOOP;
2860
2861 IF p_financial_report_type = 'BALANCE_SHEET'
2862 THEN
2863 build_case_folder_details(
2864 p_case_folder_id => p_case_folder_id,
2865 p_data_point_id => 11099,
2866 p_data_point_value => l_AUDIT_IND,
2867 p_mode => p_mode,
2868 p_error_msg => p_error_msg,
2869 p_resultout => p_resultout);
2870
2871 build_case_folder_details(
2872 p_case_folder_id => p_case_folder_id,
2873 p_data_point_id => 11100,
2874 p_data_point_value => l_CONSOLIDATED_IND,
2875 p_mode => p_mode,
2876 p_error_msg => p_error_msg,
2877 p_resultout => p_resultout);
2878
2879 build_case_folder_details(
2880 p_case_folder_id => p_case_folder_id,
2881 p_data_point_id => 11101,
2882 p_data_point_value => l_ESTIMATED_IND,
2883 p_mode => p_mode,
2884 p_error_msg => p_error_msg,
2885 p_resultout => p_resultout);
2886
2887 build_case_folder_details(
2888 p_case_folder_id => p_case_folder_id,
2889 p_data_point_id => 11103,
2890 p_data_point_value => l_FISCAL_IND,
2891 p_mode => p_mode,
2892 p_error_msg => p_error_msg,
2893 p_resultout => p_resultout);
2894
2895 build_case_folder_details(
2896 p_case_folder_id => p_case_folder_id,
2897 p_data_point_id => 11102,
2898 p_data_point_value => l_FORECAST_IND,
2899 p_mode => p_mode,
2900 p_error_msg => p_error_msg,
2901 p_resultout => p_resultout);
2902
2903 build_case_folder_details(
2904 p_case_folder_id => p_case_folder_id,
2905 p_data_point_id => 11109,
2906 p_data_point_value => l_OPENING_IND,
2907 p_mode => p_mode,
2908 p_error_msg => p_error_msg,
2909 p_resultout => p_resultout);
2910
2911 build_case_folder_details(
2912 p_case_folder_id => p_case_folder_id,
2913 p_data_point_id => 11110,
2914 p_data_point_value => l_PROFORMA_IND,
2915 p_mode => p_mode,
2916 p_error_msg => p_error_msg,
2917 p_resultout => p_resultout);
2918
2919 build_case_folder_details(
2920 p_case_folder_id => p_case_folder_id,
2921 p_data_point_id => 11108,
2922 p_data_point_value => l_QUALIFIED_IND,
2923 p_mode => p_mode,
2924 p_error_msg => p_error_msg,
2925 p_resultout => p_resultout);
2926
2927 build_case_folder_details(
2928 p_case_folder_id => p_case_folder_id,
2929 p_data_point_id => 11106,
2930 p_data_point_value => l_RESTATED_IND,
2931 p_mode => p_mode,
2932 p_error_msg => p_error_msg,
2933 p_resultout => p_resultout);
2934
2935 build_case_folder_details(
2936 p_case_folder_id => p_case_folder_id,
2937 p_data_point_id => 11105,
2938 p_data_point_value => l_SIGNED_BY_PRINCIPALS_IND,
2939 p_mode => p_mode,
2940 p_error_msg => p_error_msg,
2941 p_resultout => p_resultout);
2942
2943 build_case_folder_details(
2944 p_case_folder_id => p_case_folder_id,
2945 p_data_point_id => 11111,
2946 p_data_point_value => l_TRIAL_BALANCE_IND,
2947 p_mode => p_mode,
2948 p_error_msg => p_error_msg,
2949 p_resultout => p_resultout);
2950
2951 build_case_folder_details(
2952 p_case_folder_id => p_case_folder_id,
2953 p_data_point_id => 11107,
2954 p_data_point_value => l_UNBALANCED_IND,
2955 p_mode => p_mode,
2956 p_error_msg => p_error_msg,
2957 p_resultout => p_resultout);
2958 ELSIF p_financial_report_type = 'INCOME'
2959 THEN
2960 build_case_folder_details(
2961 p_case_folder_id => p_case_folder_id,
2962 p_data_point_id => 11096,
2963 p_data_point_value => l_DATE_REPORT_ISSUED,
2964 p_mode => p_mode,
2965 p_error_msg => p_error_msg,
2966 p_resultout => p_resultout);
2967
2968 build_case_folder_details(
2969 p_case_folder_id => p_case_folder_id,
2970 p_data_point_id => 11094,
2971 p_data_point_value => l_REPORT_START_DATE,
2972 p_mode => p_mode,
2973 p_error_msg => p_error_msg,
2974 p_resultout => p_resultout);
2975
2976 build_case_folder_details(
2977 p_case_folder_id => p_case_folder_id,
2978 p_data_point_id => 11095,
2979 p_data_point_value => l_REPORT_END_DATE,
2980 p_mode => p_mode,
2981 p_error_msg => p_error_msg,
2982 p_resultout => p_resultout);
2983 ELSIF p_financial_report_type = 'ANNUAL_SALES'
2984 THEN
2985 build_case_folder_details(
2986 p_case_folder_id => p_case_folder_id,
2987 p_data_point_id => 11087,
2988 p_data_point_value => l_CONSOLIDATED_IND,
2989 p_mode => p_mode,
2990 p_error_msg => p_error_msg,
2991 p_resultout => p_resultout);
2992
2993 build_case_folder_details(
2994 p_case_folder_id => p_case_folder_id,
2995 p_data_point_id => 11086,
2996 p_data_point_value => l_ESTIMATED_IND,
2997 p_mode => p_mode,
2998 p_error_msg => p_error_msg,
2999 p_resultout => p_resultout);
3000
3001 ELSIF p_financial_report_type = 'TANGIBLE'
3002 THEN
3003 build_case_folder_details(
3004 p_case_folder_id => p_case_folder_id,
3005 p_data_point_id => 11080,
3006 p_data_point_value => l_ESTIMATED_IND,
3007 p_mode => p_mode,
3008 p_error_msg => p_error_msg,
3009 p_resultout => p_resultout);
3010
3011 END IF;
3012 IF pg_wf_debug = 'Y'
3013 THEN
3014 ar_cmgt_util.wf_debug(p_case_folder_id,
3015 'ar_cmgt_data_points_pkg.build_dnb_scorable_fin_data()-');
3016 END IF;
3017 END;
3018
3019 PROCEDURE BUILD_DNB_SCOREABLE_DATA (
3020 p_case_folder_id IN NUMBER,
3021 p_mode IN VARCHAR2 default 'CREATE',
3022 p_org_profile_id IN NUMBER,
3023 p_credit_rating_id IN NUMBER,
3024 p_location_id IN NUMBER,
3025 p_balance_sheet_id IN NUMBER,
3026 p_income_statement_id IN NUMBER,
3027 p_tangible_net_worth_id IN NUMBER,
3028 p_annual_sales_volume_id IN NUMBER,
3029 p_resultout OUT nocopy VARCHAR2,
3030 p_error_msg OUT nocopy VARCHAR2) IS
3031
3032 l_control_yr hz_organization_profiles.control_yr%type;
3033 l_incorp_year hz_organization_profiles.incorp_year%type;
3034 l_year_established hz_organization_profiles.year_established%type;
3035 l_employees_total hz_organization_profiles.employees_total%type;
3036 l_total_payments hz_organization_profiles.total_payments%type;
3037 l_maximum_credit_reco hz_organization_profiles.maximum_credit_recommendation%type;
3038 l_oob_ind hz_organization_profiles.oob_ind%type;
3039 l_TOTAL_EMPLOYEES_IND hz_organization_profiles.TOTAL_EMPLOYEES_IND%type;
3040 l_SIC_CODE hz_organization_profiles.SIC_CODE%type;
3041 l_RENT_OWN_IND hz_organization_profiles.RENT_OWN_IND%type;
3042 l_REGISTRATION_TYPE hz_organization_profiles.REGISTRATION_TYPE%type;
3043 l_LEGAL_STATUS hz_organization_profiles.LEGAL_STATUS%type;
3044 l_HQ_BRANCH_IND hz_organization_profiles.HQ_BRANCH_IND%type;
3045 l_BRANCH_FLAG hz_organization_profiles.BRANCH_FLAG%type;
3046 l_LOCAL_ACTIVITY_CODE_TYPE hz_organization_profiles.LOCAL_ACTIVITY_CODE_TYPE%type;
3047 l_LOCAL_ACTIVITY_CODE hz_organization_profiles.LOCAL_ACTIVITY_CODE%type;
3048 l_SIC_CODE_TYPE hz_organization_profiles.SIC_CODE_TYPE%type;
3049 l_GLOBAL_FAILURE_SCORE hz_organization_profiles.GLOBAL_FAILURE_SCORE%type;
3050 l_IMPORT_IND hz_organization_profiles.IMPORT_IND%type;
3051 l_DUNS_NUMBER_C hz_organization_profiles.DUNS_NUMBER_C%type;
3052 l_PARENT_SUB_IND hz_organization_profiles.PARENT_SUB_IND%type;
3053 l_FAILURE_SCORE hz_organization_profiles.FAILURE_SCORE%type;
3054 l_FAILURE_SCORE_COMMENTARY hz_organization_profiles.FAILURE_SCORE_COMMENTARY%type;
3055 l_TOTAL_EMP_EST_IND hz_organization_profiles.TOTAL_EMP_EST_IND%type;
3056
3057 l_PAYDEX_SCORE Number;
3058 l_PAYDEX_THREE_MONTHS_AGO Number;
3059 l_AVG_HIGH_CREDIT HZ_CREDIT_RATINGS.AVG_HIGH_CREDIT%type;
3060 l_HIGH_CREDIT HZ_CREDIT_RATINGS.HIGH_CREDIT%type;
3061 l_CREDIT_SCORE_CLASS HZ_CREDIT_RATINGS.CREDIT_SCORE_CLASS%type;
3062 l_CREDIT_SCORE_NATL_PERCENTILE HZ_CREDIT_RATINGS.CREDIT_SCORE_NATL_PERCENTILE%type;
3063 l_CREDIT_SCORE_INCD_DEFAULT HZ_CREDIT_RATINGS.CREDIT_SCORE_INCD_DEFAULT%type;
3064 l_CREDIT_SCORE_AGE HZ_CREDIT_RATINGS.CREDIT_SCORE_AGE%type;
3065 l_FAILURE_SCORE_CLASS HZ_CREDIT_RATINGS.FAILURE_SCORE_CLASS%type;
3066 l_FAILURE_SCORE_NATNL_PERCENT HZ_CREDIT_RATINGS.FAILURE_SCORE_NATNL_PERCENTILE%type;
3067 l_FAILURE_SCORE_INCD_DEFAULT HZ_CREDIT_RATINGS.FAILURE_SCORE_INCD_DEFAULT%type;
3068 l_FAILURE_SCORE_AGE HZ_CREDIT_RATINGS.FAILURE_SCORE_AGE%type;
3069 l_LOW_RNG_DELQ_SCR HZ_CREDIT_RATINGS.LOW_RNG_DELQ_SCR%type;
3070 l_HIGH_RNG_DELQ_SCR HZ_CREDIT_RATINGS.HIGH_RNG_DELQ_SCR%type;
3071 l_DELQ_PMT_RNG_PRCNT HZ_CREDIT_RATINGS.DELQ_PMT_RNG_PRCNT%type;
3072 l_DELQ_PMT_PCTG_FOR_ALL_FIRMS HZ_CREDIT_RATINGS.DELQ_PMT_PCTG_FOR_ALL_FIRMS%type;
3073 l_NUM_TRADE_EXPERIENCES HZ_CREDIT_RATINGS.NUM_TRADE_EXPERIENCES%type;
3074 l_DEBARMENTS_COUNT HZ_CREDIT_RATINGS.NUM_SPCL_EVENT%type;
3075 l_BANKRUPTCY_IND HZ_CREDIT_RATINGS.BANKRUPTCY_IND%type;
3076 l_DEBARMENT_IND HZ_CREDIT_RATINGS.DEBARMENT_IND%type;
3077 l_BUSINESS_DISCONTINUED HZ_CREDIT_RATINGS.BUSINESS_DISCONTINUED%type;
3078 l_NUM_SPCL_EVENT HZ_CREDIT_RATINGS.NUM_SPCL_EVENT%type;
3079 l_MAXIMUM_CREDIT_CURRENCY_CODE HZ_CREDIT_RATINGS.MAXIMUM_CREDIT_CURRENCY_CODE%type;
3080 l_CREDIT_SCORE HZ_CREDIT_RATINGS.CREDIT_SCORE%type;
3081 l_CREDIT_SCORE_OVERRIDE_CODE HZ_CREDIT_RATINGS.CREDIT_SCORE_OVERRIDE_CODE%type;
3082 l_PRNT_BKCY_CHAPTER_CONV HZ_CREDIT_RATINGS.PRNT_BKCY_CHAPTER_CONV%type;
3083 l_NUM_PRNT_BKCY_CONVS HZ_CREDIT_RATINGS.NUM_PRNT_BKCY_CONVS%type;
3084 l_PRNT_BKCY_FILG_CHAPTER HZ_CREDIT_RATINGS.PRNT_BKCY_FILG_CHAPTER%type;
3085 l_PRNT_BKCY_FILG_TYPE HZ_CREDIT_RATINGS.PRNT_BKCY_FILG_TYPE%type;
3086 l_NUM_PRNT_BKCY_FILING HZ_CREDIT_RATINGS.NUM_PRNT_BKCY_FILING%type;
3087 l_NO_TRADE_IND HZ_CREDIT_RATINGS.NO_TRADE_IND%type;
3088 l_JUDGEMENT_IND HZ_CREDIT_RATINGS.JUDGEMENT_IND%type;
3089 l_LIEN_IND HZ_CREDIT_RATINGS.LIEN_IND%type;
3090 l_SUIT_IND HZ_CREDIT_RATINGS.SUIT_IND%type;
3091 l_PAYDEX_INDUSTRY_DAYS HZ_CREDIT_RATINGS.PAYDEX_INDUSTRY_DAYS%type;
3092 l_FINCL_LGL_EVENT_IND HZ_CREDIT_RATINGS.FINCL_LGL_EVENT_IND%type;
3093 l_DISASTER_IND HZ_CREDIT_RATINGS.DISASTER_IND%type;
3094 l_CRIMINAL_PROCEEDING_IND HZ_CREDIT_RATINGS.CRIMINAL_PROCEEDING_IND%type;
3095 l_FINCL_EMBT_IND HZ_CREDIT_RATINGS.FINCL_EMBT_IND%type;
3096 l_PAYDEX_NORM HZ_CREDIT_RATINGS.PAYDEX_NORM%type;
3097 l_RATING HZ_CREDIT_RATINGS.RATING%type;
3098 l_SECURED_FLNG_IND HZ_CREDIT_RATINGS.SECURED_FLNG_IND%type;
3099 l_CLAIMS_IND HZ_CREDIT_RATINGS.CLAIMS_IND%type;
3100 l_SUIT_JUDGE_IND HZ_CREDIT_RATINGS.SUIT_JUDGE_IND%type;
3101 l_DET_HISTORY_IND HZ_CREDIT_RATINGS.DET_HISTORY_IND%type;
3102 l_OTHER_SPEC_EVNT_IND HZ_CREDIT_RATINGS.OTHER_SPEC_EVNT_IND%type;
3103 l_OPRG_SPEC_EVNT_IND HZ_CREDIT_RATINGS.OPRG_SPEC_EVNT_IND%type;
3104 l_CREDIT_SCORE_COMMENTARY HZ_CREDIT_RATINGS.CREDIT_SCORE_COMMENTARY%type;
3105 l_country hz_locations.country%type;
3106
3107
3108 l_cash_liqu_asset NUMBER;
3109 l_ar NUMBER;
3110 l_ap NUMBER;
3111 l_an_sales_vol NUMBER;
3112 l_auth_cap NUMBER;
3113 l_cost_of_sales NUMBER;
3114 l_current_ratio NUMBER;
3115 l_dividends NUMBER;
3116 l_fixed_assets NUMBER;
3117 l_gross_inc NUMBER;
3118 l_intg_asset NUMBER;
3119 l_inventory NUMBER;
3120 l_iss_capital NUMBER;
3121 l_long_debt NUMBER;
3122 l_net_income NUMBER;
3123 l_net_worth NUMBER;
3124 l_nom_capital NUMBER;
3125 l_paid_in_capital NUMBER;
3126 l_prev_sales NUMBER;
3127 l_prev_net_worth NUMBER;
3128 l_prev_work_cap NUMBER;
3129 l_profit_bef_tax NUMBER;
3130 l_quick_ratio NUMBER;
3131 l_ret_earnings NUMBER;
3132 l_sales NUMBER;
3133 l_tang_net_worth NUMBER;
3134 l_tot_assets NUmBER;
3135 l_tot_curr_assets NUMBER;
3136 l_tot_curr_liab NUMBER;
3137 l_tot_liab NUMBER;
3138 l_tot_liab_equ NUMBER;
3139 l_tot_long_liab NUMBER;
3140
3141
3142 CURSOR cDNBSore IS
3143 SELECT data_element_id, source_table_name, source_column_name
3144 FROM ar_cmgt_dnb_elements_vl
3145 WHERE scorable_flag = 'Y';
3146
3147 CURSOR cOrgProf IS
3148 SELECT control_yr,
3149 incorp_year,
3150 year_established,
3151 employees_total,
3152 total_payments,
3153 maximum_credit_recommendation,
3154 oob_ind,
3155 TOTAL_EMP_EST_IND
3156 TOTAL_EMPLOYEES_IND,
3157 SIC_CODE,
3158 RENT_OWN_IND,
3159 REGISTRATION_TYPE,
3160 LEGAL_STATUS,
3161 HQ_BRANCH_IND,
3162 BRANCH_FLAG,
3163 LOCAL_ACTIVITY_CODE_TYPE,
3164 LOCAL_ACTIVITY_CODE,
3165 SIC_CODE_TYPE,
3166 GLOBAL_FAILURE_SCORE,
3167 IMPORT_IND,
3168 DUNS_NUMBER_C,
3169 TOTAL_EMP_EST_IND,
3170 PARENT_SUB_IND,
3171 FAILURE_SCORE,
3172 FAILURE_SCORE_COMMENTARY
3173
3174 FROM hz_organization_profiles
3175 WHERE organization_profile_id = p_org_profile_id;
3176
3177 CURSOR cCrRatings IS
3178 SELECT decode(PAYDEX_SCORE,'UN', null, paydex_score ) paydex_score,
3179 decode(paydex_three_months_ago, 'UN', null, paydex_three_months_ago ) paydex_three_months_ago,
3180 AVG_HIGH_CREDIT,
3181 HIGH_CREDIT,
3182 CREDIT_SCORE_NATL_PERCENTILE,
3183 CREDIT_SCORE_INCD_DEFAULT,
3184 CREDIT_SCORE_AGE,
3185 FAILURE_SCORE_CLASS,
3186 FAILURE_SCORE_NATNL_PERCENTILE,
3187 FAILURE_SCORE_INCD_DEFAULT,
3188 FAILURE_SCORE_AGE,
3189 LOW_RNG_DELQ_SCR,
3190 HIGH_RNG_DELQ_SCR,
3191 DELQ_PMT_RNG_PRCNT,
3192 DELQ_PMT_PCTG_FOR_ALL_FIRMS,
3193 NUM_TRADE_EXPERIENCES,
3194 DEBARMENTS_COUNT,
3195 BANKRUPTCY_IND,
3196 DEBARMENT_IND,
3197 BUSINESS_DISCONTINUED,
3198 NUM_SPCL_EVENT,
3199 MAXIMUM_CREDIT_CURRENCY_CODE,
3200 CREDIT_SCORE,
3201 CREDIT_SCORE_CLASS,
3202 CREDIT_SCORE_OVERRIDE_CODE,
3203 PRNT_BKCY_CHAPTER_CONV,
3204 NUM_PRNT_BKCY_CONVS,
3205 PRNT_BKCY_FILG_CHAPTER,
3206 PRNT_BKCY_FILG_TYPE,
3207 NUM_PRNT_BKCY_FILING,
3208 NO_TRADE_IND,
3209 JUDGEMENT_IND,
3210 LIEN_IND,
3211 SUIT_IND,
3212 PAYDEX_INDUSTRY_DAYS,
3213 FINCL_LGL_EVENT_IND,
3214 DISASTER_IND,
3215 CRIMINAL_PROCEEDING_IND,
3216 FINCL_EMBT_IND,
3217 PAYDEX_NORM,
3218 RATING,
3219 SECURED_FLNG_IND,
3220 CLAIMS_IND,
3221 SUIT_JUDGE_IND,
3222 DET_HISTORY_IND,
3223 OTHER_SPEC_EVNT_IND,
3224 OPRG_SPEC_EVNT_IND,
3225 CREDIT_SCORE_COMMENTARY
3226 FROM HZ_CREDIT_RATINGS
3227 WHERE credit_rating_id = p_credit_rating_id;
3228
3229 CURSOR cFinNum IS
3230 SELECT FINANCIAL_number, financial_number_name
3231 FROM hz_financial_numbers
3232 WHERE financial_report_id in ( SELECT source_key
3233 from ar_cmgt_cf_dnb_dtls
3234 WHERE source_table_name = 'HZ_FINANCIAL_REPORTS'
3235 and case_folder_id = p_case_folder_id);
3236
3237 CURSOR cGetLocation IS
3238 SELECT COUNTRY
3239 FROM hz_locations
3240 where location_id = p_location_id;
3241
3242 BEGIN
3243 IF pg_wf_debug = 'Y'
3244 THEN
3245 ar_cmgt_util.wf_debug(p_case_folder_id,
3246 'ar_cmgt_data_points_pkg.build_dnb_scorable_data()+');
3247 END IF;
3248
3249 FOR cOrgProfRec IN cOrgProf
3250 LOOP
3251 l_control_yr := cOrgProfRec.control_yr;
3252 l_incorp_year := cOrgProfRec.incorp_year;
3253 l_year_established := cOrgProfRec.year_established;
3254 l_employees_total := cOrgProfRec.employees_total;
3255 l_total_payments := cOrgProfRec.total_payments;
3256 l_maximum_credit_reco := cOrgProfRec.maximum_credit_recommendation;
3257 l_oob_ind := cOrgProfRec.oob_ind;
3258
3259
3260 l_TOTAL_EMPLOYEES_IND := cOrgProfRec.TOTAL_EMPLOYEES_IND;
3261 l_SIC_CODE := cOrgProfRec.SIC_CODE;
3262 l_RENT_OWN_IND := cOrgProfRec.RENT_OWN_IND;
3263 l_REGISTRATION_TYPE := cOrgProfRec.REGISTRATION_TYPE;
3264 l_LEGAL_STATUS := cOrgProfRec.LEGAL_STATUS;
3265 l_HQ_BRANCH_IND := cOrgProfRec.HQ_BRANCH_IND;
3266 l_BRANCH_FLAG := cOrgProfRec.BRANCH_FLAG;
3267 l_LOCAL_ACTIVITY_CODE_TYPE := cOrgProfRec.LOCAL_ACTIVITY_CODE_TYPE;
3268 l_LOCAL_ACTIVITY_CODE := cOrgProfRec.LOCAL_ACTIVITY_CODE;
3269 l_SIC_CODE_TYPE := cOrgProfRec.SIC_CODE_TYPE;
3270 l_GLOBAL_FAILURE_SCORE := cOrgProfRec.GLOBAL_FAILURE_SCORE;
3271 l_IMPORT_IND := cOrgProfRec.IMPORT_IND;
3272 l_DUNS_NUMBER_C := cOrgProfRec.DUNS_NUMBER_C;
3273 l_PARENT_SUB_IND := cOrgProfRec.PARENT_SUB_IND;
3274 l_FAILURE_SCORE := cOrgProfRec.FAILURE_SCORE;
3275 l_FAILURE_SCORE_COMMENTARY := cOrgProfRec.FAILURE_SCORE_COMMENTARY;
3276 l_TOTAL_EMP_EST_IND := cOrgProfRec.TOTAL_EMP_EST_IND;
3277
3278 END LOOP;
3279
3280 build_case_folder_details(
3281 p_case_folder_id => p_case_folder_id,
3282 p_data_point_id => 11022,
3283 p_data_point_value => l_TOTAL_EMPLOYEES_IND,
3284 p_mode => p_mode,
3285 p_error_msg => p_error_msg,
3286 p_resultout => p_resultout);
3287
3288 build_case_folder_details(
3289 p_case_folder_id => p_case_folder_id,
3290 p_data_point_id => 11029,
3291 p_data_point_value => l_SIC_CODE,
3292 p_mode => p_mode,
3293 p_error_msg => p_error_msg,
3294 p_resultout => p_resultout);
3295
3296 build_case_folder_details(
3297 p_case_folder_id => p_case_folder_id,
3298 p_data_point_id => 11038,
3299 p_data_point_value => l_RENT_OWN_IND,
3300 p_mode => p_mode,
3301 p_error_msg => p_error_msg,
3302 p_resultout => p_resultout);
3303
3304 build_case_folder_details(
3305 p_case_folder_id => p_case_folder_id,
3306 p_data_point_id => 11037,
3307 p_data_point_value => l_REGISTRATION_TYPE,
3308 p_mode => p_mode,
3309 p_error_msg => p_error_msg,
3310 p_resultout => p_resultout);
3311
3312 build_case_folder_details(
3313 p_case_folder_id => p_case_folder_id,
3314 p_data_point_id => 11036,
3315 p_data_point_value => l_LEGAL_STATUS,
3316 p_mode => p_mode,
3317 p_error_msg => p_error_msg,
3318 p_resultout => p_resultout);
3319
3320 build_case_folder_details(
3321 p_case_folder_id => p_case_folder_id,
3322 p_data_point_id => 11035,
3323 p_data_point_value => l_HQ_BRANCH_IND,
3324 p_mode => p_mode,
3325 p_error_msg => p_error_msg,
3326 p_resultout => p_resultout);
3327
3328 build_case_folder_details(
3329 p_case_folder_id => p_case_folder_id,
3330 p_data_point_id => 11034,
3331 p_data_point_value => l_BRANCH_FLAG,
3332 p_mode => p_mode,
3333 p_error_msg => p_error_msg,
3334 p_resultout => p_resultout);
3335
3336 build_case_folder_details(
3337 p_case_folder_id => p_case_folder_id,
3338 p_data_point_id => 11032,
3339 p_data_point_value => l_LOCAL_ACTIVITY_CODE_TYPE,
3340 p_mode => p_mode,
3341 p_error_msg => p_error_msg,
3342 p_resultout => p_resultout);
3343
3344 build_case_folder_details(
3345 p_case_folder_id => p_case_folder_id,
3346 p_data_point_id => 11031,
3347 p_data_point_value => l_LOCAL_ACTIVITY_CODE,
3348 p_mode => p_mode,
3349 p_error_msg => p_error_msg,
3350 p_resultout => p_resultout);
3351
3352 build_case_folder_details(
3353 p_case_folder_id => p_case_folder_id,
3354 p_data_point_id => 11030,
3355 p_data_point_value => l_SIC_CODE_TYPE,
3356 p_mode => p_mode,
3357 p_error_msg => p_error_msg,
3358 p_resultout => p_resultout);
3359
3360 build_case_folder_details(
3361 p_case_folder_id => p_case_folder_id,
3362 p_data_point_id => 11117,
3363 p_data_point_value => l_GLOBAL_FAILURE_SCORE,
3364 p_mode => p_mode,
3365 p_error_msg => p_error_msg,
3366 p_resultout => p_resultout);
3367
3368 build_case_folder_details(
3369 p_case_folder_id => p_case_folder_id,
3370 p_data_point_id => 11114,
3371 p_data_point_value => l_IMPORT_IND,
3372 p_mode => p_mode,
3373 p_error_msg => p_error_msg,
3374 p_resultout => p_resultout);
3375
3376 build_case_folder_details(
3377 p_case_folder_id => p_case_folder_id,
3378 p_data_point_id => 11001,
3379 p_data_point_value => l_DUNS_NUMBER_C,
3380 p_mode => p_mode,
3381 p_error_msg => p_error_msg,
3382 p_resultout => p_resultout);
3383
3384 build_case_folder_details(
3385 p_case_folder_id => p_case_folder_id,
3386 p_data_point_id => 11131,
3387 p_data_point_value => l_PARENT_SUB_IND,
3388 p_mode => p_mode,
3389 p_error_msg => p_error_msg,
3390 p_resultout => p_resultout);
3391
3392 build_case_folder_details(
3393 p_case_folder_id => p_case_folder_id,
3394 p_data_point_id => 11152,
3395 p_data_point_value => l_FAILURE_SCORE,
3396 p_mode => p_mode,
3397 p_error_msg => p_error_msg,
3398 p_resultout => p_resultout);
3399
3400 build_case_folder_details(
3401 p_case_folder_id => p_case_folder_id,
3402 p_data_point_id => 11153,
3403 p_data_point_value => l_FAILURE_SCORE_COMMENTARY,
3404 p_mode => p_mode,
3405 p_error_msg => p_error_msg,
3406 p_resultout => p_resultout);
3407
3408 build_case_folder_details(
3409 p_case_folder_id => p_case_folder_id,
3410 p_data_point_id => 11023,
3411 p_data_point_value => l_TOTAL_EMP_EST_IND,
3412 p_mode => p_mode,
3413 p_error_msg => p_error_msg,
3414 p_resultout => p_resultout);
3415
3416 /* Noticed this weird logic. probably a bug
3417 if there are multiple countries */
3418 FOR cGetLocationRec in cGetLocation
3419 LOOP
3420 l_country := cGetLocationRec.country;
3421
3422 END LOOP;
3423 build_case_folder_details(
3424 p_case_folder_id => p_case_folder_id,
3425 p_data_point_id => 11010,
3426 p_data_point_value => l_country,
3427 p_mode => p_mode,
3428 p_error_msg => p_error_msg,
3429 p_resultout => p_resultout);
3430
3431 FOR cCrRatingsRec IN cCrRatings
3432 LOOP
3433 l_PAYDEX_SCORE := cCrRatingsRec.PAYDEX_SCORE;
3434 l_PAYDEX_THREE_MONTHS_AGO := cCrRatingsRec.PAYDEX_THREE_MONTHS_AGO;
3435 l_AVG_HIGH_CREDIT := cCrRatingsRec.AVG_HIGH_CREDIT;
3436 l_HIGH_CREDIT := cCrRatingsRec.HIGH_CREDIT;
3437 l_CREDIT_SCORE_CLASS := cCrRatingsRec.CREDIT_SCORE_CLASS;
3438 l_CREDIT_SCORE_NATL_PERCENTILE := cCrRatingsRec.CREDIT_SCORE_NATL_PERCENTILE;
3439 l_CREDIT_SCORE_INCD_DEFAULT := cCrRatingsRec.CREDIT_SCORE_INCD_DEFAULT;
3440 l_CREDIT_SCORE_AGE := cCrRatingsRec.CREDIT_SCORE_AGE;
3441 l_FAILURE_SCORE_CLASS := cCrRatingsRec.FAILURE_SCORE_CLASS;
3442 l_FAILURE_SCORE_NATNL_PERCENT := cCrRatingsRec.FAILURE_SCORE_NATNL_PERCENTILE;
3443 l_FAILURE_SCORE_INCD_DEFAULT := cCrRatingsRec.FAILURE_SCORE_INCD_DEFAULT;
3444 l_FAILURE_SCORE_AGE := cCrRatingsRec.FAILURE_SCORE_AGE;
3445 l_LOW_RNG_DELQ_SCR := cCrRatingsRec.LOW_RNG_DELQ_SCR;
3446 l_HIGH_RNG_DELQ_SCR := cCrRatingsRec.HIGH_RNG_DELQ_SCR;
3447 l_DELQ_PMT_RNG_PRCNT := cCrRatingsRec.DELQ_PMT_RNG_PRCNT;
3448 l_DELQ_PMT_PCTG_FOR_ALL_FIRMS := cCrRatingsRec.DELQ_PMT_PCTG_FOR_ALL_FIRMS;
3449 l_NUM_TRADE_EXPERIENCES := cCrRatingsRec.NUM_TRADE_EXPERIENCES;
3450 l_NUM_PRNT_BKCY_FILING := cCrRatingsRec.NUM_PRNT_BKCY_FILING;
3451 l_DEBARMENTS_COUNT := cCrRatingsRec.DEBARMENTS_COUNT;
3452 l_BANKRUPTCY_IND := cCrRatingsRec.BANKRUPTCY_IND;
3453 l_DEBARMENT_IND := cCrRatingsRec.DEBARMENT_IND;
3454 l_BUSINESS_DISCONTINUED := cCrRatingsRec.BUSINESS_DISCONTINUED;
3455 l_NUM_SPCL_EVENT := cCrRatingsRec.NUM_SPCL_EVENT;
3456 l_MAXIMUM_CREDIT_CURRENCY_CODE := cCrRatingsRec.MAXIMUM_CREDIT_CURRENCY_CODE;
3457 l_CREDIT_SCORE := cCrRatingsRec.CREDIT_SCORE;
3458 l_CREDIT_SCORE_OVERRIDE_CODE := cCrRatingsRec.CREDIT_SCORE_OVERRIDE_CODE;
3459 l_PRNT_BKCY_CHAPTER_CONV := cCrRatingsRec.PRNT_BKCY_CHAPTER_CONV;
3460 l_NUM_PRNT_BKCY_CONVS := cCrRatingsRec.NUM_PRNT_BKCY_CONVS;
3461 l_PRNT_BKCY_FILG_CHAPTER := cCrRatingsRec.PRNT_BKCY_FILG_CHAPTER;
3462 l_PRNT_BKCY_FILG_TYPE := cCrRatingsRec.PRNT_BKCY_FILG_TYPE;
3463 l_NO_TRADE_IND := cCrRatingsRec.NO_TRADE_IND;
3464 l_JUDGEMENT_IND := cCrRatingsRec.JUDGEMENT_IND;
3465 l_LIEN_IND := cCrRatingsRec.LIEN_IND;
3466 l_SUIT_IND := cCrRatingsRec.SUIT_IND;
3467 l_PAYDEX_INDUSTRY_DAYS := cCrRatingsRec.PAYDEX_INDUSTRY_DAYS;
3468 l_FINCL_LGL_EVENT_IND := cCrRatingsRec.FINCL_LGL_EVENT_IND;
3469 l_DISASTER_IND := cCrRatingsRec.DISASTER_IND;
3470 l_CRIMINAL_PROCEEDING_IND := cCrRatingsRec.CRIMINAL_PROCEEDING_IND;
3471 l_FINCL_EMBT_IND := cCrRatingsRec.FINCL_EMBT_IND;
3472 l_PAYDEX_NORM := cCrRatingsRec.PAYDEX_NORM;
3473 l_RATING := cCrRatingsRec.RATING;
3474 l_SECURED_FLNG_IND := cCrRatingsRec.SECURED_FLNG_IND;
3475 l_CLAIMS_IND := cCrRatingsRec.CLAIMS_IND;
3476 l_SUIT_JUDGE_IND := cCrRatingsRec.SUIT_JUDGE_IND;
3477 l_DET_HISTORY_IND := cCrRatingsRec.DET_HISTORY_IND;
3478 l_OTHER_SPEC_EVNT_IND := cCrRatingsRec.OTHER_SPEC_EVNT_IND;
3479 l_OPRG_SPEC_EVNT_IND := cCrRatingsRec.OPRG_SPEC_EVNT_IND;
3480 l_CREDIT_SCORE_COMMENTARY := cCrRatingsRec.CREDIT_SCORE_COMMENTARY;
3481
3482 END LOOP;
3483
3484 -- Now populate the case folder
3485 build_case_folder_details(
3486 p_case_folder_id => p_case_folder_id,
3487 p_data_point_id => 11017,
3488 p_data_point_value => l_control_yr,
3489 p_mode => p_mode,
3490 p_error_msg => p_error_msg,
3491 p_resultout => p_resultout);
3492
3493 build_case_folder_details(
3494 p_case_folder_id => p_case_folder_id,
3495 p_data_point_id => 11018,
3496 p_data_point_value => l_incorp_year,
3497 p_mode => p_mode,
3498 p_error_msg => p_error_msg,
3499 p_resultout => p_resultout);
3500
3501 build_case_folder_details(
3502 p_case_folder_id => p_case_folder_id,
3503 p_data_point_id => 11019,
3504 p_data_point_value => l_year_established,
3505 p_mode => p_mode,
3506 p_error_msg => p_error_msg,
3507 p_resultout => p_resultout);
3508
3509 build_case_folder_details(
3510 p_case_folder_id => p_case_folder_id,
3511 p_data_point_id => 11020,
3512 p_data_point_value => l_employees_total ,
3513 p_mode => p_mode,
3514 p_error_msg => p_error_msg,
3515 p_resultout => p_resultout);
3516
3517 build_case_folder_details(
3518 p_case_folder_id => p_case_folder_id,
3519 p_data_point_id => 11048,
3520 p_data_point_value => l_total_payments,
3521 p_mode => p_mode,
3522 p_error_msg => p_error_msg,
3523 p_resultout => p_resultout);
3524
3525 build_case_folder_details(
3526 p_case_folder_id => p_case_folder_id,
3527 p_data_point_id => 11118,
3528 p_data_point_value => l_maximum_credit_reco,
3529 p_mode => p_mode,
3530 p_error_msg => p_error_msg,
3531 p_resultout => p_resultout);
3532
3533 build_case_folder_details(
3534 p_case_folder_id => p_case_folder_id,
3535 p_data_point_id => 11043,
3536 p_data_point_value => l_PAYDEX_SCORE,
3537 p_mode => p_mode,
3538 p_error_msg => p_error_msg,
3539 p_resultout => p_resultout);
3540
3541 build_case_folder_details(
3542 p_case_folder_id => p_case_folder_id,
3543 p_data_point_id => 11044,
3544 p_data_point_value => l_PAYDEX_THREE_MONTHS_AGO,
3545 p_mode => p_mode,
3546 p_error_msg => p_error_msg,
3547 p_resultout => p_resultout);
3548
3549 build_case_folder_details(
3550 p_case_folder_id => p_case_folder_id,
3551 p_data_point_id => 11046,
3552 p_data_point_value => l_AVG_HIGH_CREDIT,
3553 p_mode => p_mode,
3554 p_error_msg => p_error_msg,
3555 p_resultout => p_resultout);
3556
3557 build_case_folder_details(
3558 p_case_folder_id => p_case_folder_id,
3559 p_data_point_id => 11047,
3560 p_data_point_value => l_HIGH_CREDIT,
3561 p_mode => p_mode,
3562 p_error_msg => p_error_msg,
3563 p_resultout => p_resultout);
3564
3565 build_case_folder_details(
3566 p_case_folder_id => p_case_folder_id,
3567 p_data_point_id => 11143,
3568 p_data_point_value => l_CREDIT_SCORE_CLASS,
3569 p_mode => p_mode,
3570 p_error_msg => p_error_msg,
3571 p_resultout => p_resultout);
3572
3573 build_case_folder_details(
3574 p_case_folder_id => p_case_folder_id,
3575 p_data_point_id => 11144,
3576 p_data_point_value => l_CREDIT_SCORE_NATL_PERCENTILE,
3577 p_mode => p_mode,
3578 p_error_msg => p_error_msg,
3579 p_resultout => p_resultout);
3580
3581 build_case_folder_details(
3582 p_case_folder_id => p_case_folder_id,
3583 p_data_point_id => 11145,
3584 p_data_point_value => l_CREDIT_SCORE_INCD_DEFAULT,
3585 p_mode => p_mode,
3586 p_error_msg => p_error_msg,
3587 p_resultout => p_resultout);
3588 build_case_folder_details(
3589 p_case_folder_id => p_case_folder_id,
3590 p_data_point_id => 11146,
3591 p_data_point_value => l_CREDIT_SCORE_AGE,
3592 p_mode => p_mode,
3593 p_error_msg => p_error_msg,
3594 p_resultout => p_resultout);
3595
3596 build_case_folder_details(
3597 p_case_folder_id => p_case_folder_id,
3598 p_data_point_id => 11154,
3599 p_data_point_value => l_FAILURE_SCORE_CLASS,
3600 p_mode => p_mode,
3601 p_error_msg => p_error_msg,
3602 p_resultout => p_resultout);
3603
3604 build_case_folder_details(
3605 p_case_folder_id => p_case_folder_id,
3606 p_data_point_id => 11155,
3607 p_data_point_value => l_FAILURE_SCORE_NATNL_PERCENT,
3608 p_mode => p_mode,
3609 p_error_msg => p_error_msg,
3610 p_resultout => p_resultout);
3611
3612 build_case_folder_details(
3613 p_case_folder_id => p_case_folder_id,
3614 p_data_point_id => 11156,
3615 p_data_point_value => l_FAILURE_SCORE_INCD_DEFAULT,
3616 p_mode => p_mode,
3617 p_error_msg => p_error_msg,
3618 p_resultout => p_resultout);
3619
3620 build_case_folder_details(
3621 p_case_folder_id => p_case_folder_id,
3622 p_data_point_id => 11157,
3623 p_data_point_value => l_FAILURE_SCORE_AGE,
3624 p_mode => p_mode,
3625 p_error_msg => p_error_msg,
3626 p_resultout => p_resultout);
3627
3628 build_case_folder_details(
3629 p_case_folder_id => p_case_folder_id,
3630 p_data_point_id => 11162,
3631 p_data_point_value => l_LOW_RNG_DELQ_SCR,
3632 p_mode => p_mode,
3633 p_error_msg => p_error_msg,
3634 p_resultout => p_resultout);
3635
3636 build_case_folder_details(
3637 p_case_folder_id => p_case_folder_id,
3638 p_data_point_id => 11163,
3639 p_data_point_value => l_HIGH_RNG_DELQ_SCR ,
3640 p_mode => p_mode,
3641 p_error_msg => p_error_msg,
3642 p_resultout => p_resultout);
3643
3644 build_case_folder_details(
3645 p_case_folder_id => p_case_folder_id,
3646 p_data_point_id => 11164,
3647 p_data_point_value => l_DELQ_PMT_RNG_PRCNT ,
3648 p_mode => p_mode,
3649 p_error_msg => p_error_msg,
3650 p_resultout => p_resultout);
3651
3652 build_case_folder_details(
3653 p_case_folder_id => p_case_folder_id,
3654 p_data_point_id => 11165,
3655 p_data_point_value => l_DELQ_PMT_PCTG_FOR_ALL_FIRMS ,
3656 p_mode => p_mode,
3657 p_error_msg => p_error_msg,
3658 p_resultout => p_resultout);
3659
3660 build_case_folder_details(
3661 p_case_folder_id => p_case_folder_id,
3662 p_data_point_id => 11166,
3663 p_data_point_value => l_NUM_TRADE_EXPERIENCES ,
3664 p_mode => p_mode,
3665 p_error_msg => p_error_msg,
3666 p_resultout => p_resultout);
3667
3668
3669 build_case_folder_details(
3670 p_case_folder_id => p_case_folder_id,
3671 p_data_point_id => 11195,
3672 p_data_point_value => l_DEBARMENTS_COUNT,
3673 p_mode => p_mode,
3674 p_error_msg => p_error_msg,
3675 p_resultout => p_resultout);
3676
3677 build_case_folder_details(
3678 p_case_folder_id => p_case_folder_id,
3679 p_data_point_id => 11175,
3680 p_data_point_value => l_BANKRUPTCY_IND,
3681 p_mode => p_mode,
3682 p_error_msg => p_error_msg,
3683 p_resultout => p_resultout);
3684
3685 build_case_folder_details(
3686 p_case_folder_id => p_case_folder_id,
3687 p_data_point_id => 11194,
3688 p_data_point_value => l_DEBARMENT_IND,
3689 p_mode => p_mode,
3690 p_error_msg => p_error_msg,
3691 p_resultout => p_resultout);
3692
3693 build_case_folder_details(
3694 p_case_folder_id => p_case_folder_id,
3695 p_data_point_id => 11050,
3696 p_data_point_value => l_oob_IND,
3697 p_mode => p_mode,
3698 p_error_msg => p_error_msg,
3699 p_resultout => p_resultout);
3700 ------------------------
3701 build_case_folder_details(
3702 p_case_folder_id => p_case_folder_id,
3703 p_data_point_id => 11188,
3704 p_data_point_value => l_BUSINESS_DISCONTINUED,
3705 p_mode => p_mode,
3706 p_error_msg => p_error_msg,
3707 p_resultout => p_resultout);
3708
3709 build_case_folder_details(
3710 p_case_folder_id => p_case_folder_id,
3711 p_data_point_id => 11190,
3712 p_data_point_value => l_NUM_SPCL_EVENT,
3713 p_mode => p_mode,
3714 p_error_msg => p_error_msg,
3715 p_resultout => p_resultout);
3716
3717 build_case_folder_details(
3718 p_case_folder_id => p_case_folder_id,
3719 p_data_point_id => 11119,
3720 p_data_point_value => l_MAXIMUM_CREDIT_CURRENCY_CODE,
3721 p_mode => p_mode,
3722 p_error_msg => p_error_msg,
3723 p_resultout => p_resultout);
3724
3725 build_case_folder_details(
3726 p_case_folder_id => p_case_folder_id,
3727 p_data_point_id => 11141,
3728 p_data_point_value => l_CREDIT_SCORE,
3729 p_mode => p_mode,
3730 p_error_msg => p_error_msg,
3731 p_resultout => p_resultout);
3732
3733
3734 build_case_folder_details(
3735 p_case_folder_id => p_case_folder_id,
3736 p_data_point_id => 11160,
3737 p_data_point_value => l_CREDIT_SCORE_OVERRIDE_CODE,
3738 p_mode => p_mode,
3739 p_error_msg => p_error_msg,
3740 p_resultout => p_resultout);
3741
3742 build_case_folder_details(
3743 p_case_folder_id => p_case_folder_id,
3744 p_data_point_id => 11184,
3745 p_data_point_value => l_PRNT_BKCY_CHAPTER_CONV,
3746 p_mode => p_mode,
3747 p_error_msg => p_error_msg,
3748 p_resultout => p_resultout);
3749
3750 build_case_folder_details(
3751 p_case_folder_id => p_case_folder_id,
3752 p_data_point_id => 11182,
3753 p_data_point_value => l_NUM_PRNT_BKCY_CONVS,
3754 p_mode => p_mode,
3755 p_error_msg => p_error_msg,
3756 p_resultout => p_resultout);
3757
3758 build_case_folder_details(
3759 p_case_folder_id => p_case_folder_id,
3760 p_data_point_id => 11180,
3761 p_data_point_value => l_PRNT_BKCY_FILG_CHAPTER,
3762 p_mode => p_mode,
3763 p_error_msg => p_error_msg,
3764 p_resultout => p_resultout);
3765
3766 build_case_folder_details(
3767 p_case_folder_id => p_case_folder_id,
3768 p_data_point_id => 11179,
3769 p_data_point_value => l_PRNT_BKCY_FILG_TYPE,
3770 p_mode => p_mode,
3771 p_error_msg => p_error_msg,
3772 p_resultout => p_resultout);
3773
3774 build_case_folder_details(
3775 p_case_folder_id => p_case_folder_id,
3776 p_data_point_id => 11178,
3777 p_data_point_value => l_NUM_PRNT_BKCY_FILING,
3778 p_mode => p_mode,
3779 p_error_msg => p_error_msg,
3780 p_resultout => p_resultout);
3781
3782 build_case_folder_details(
3783 p_case_folder_id => p_case_folder_id,
3784 p_data_point_id => 11176,
3785 p_data_point_value => l_NO_TRADE_IND,
3786 p_mode => p_mode,
3787 p_error_msg => p_error_msg,
3788 p_resultout => p_resultout);
3789
3790 build_case_folder_details(
3791 p_case_folder_id => p_case_folder_id,
3792 p_data_point_id => 11174,
3793 p_data_point_value => l_JUDGEMENT_IND,
3794 p_mode => p_mode,
3795 p_error_msg => p_error_msg,
3796 p_resultout => p_resultout);
3797
3798 build_case_folder_details(
3799 p_case_folder_id => p_case_folder_id,
3800 p_data_point_id => 11173,
3801 p_data_point_value => l_LIEN_IND,
3802 p_mode => p_mode,
3803 p_error_msg => p_error_msg,
3804 p_resultout => p_resultout);
3805
3806 build_case_folder_details(
3807 p_case_folder_id => p_case_folder_id,
3808 p_data_point_id => 11172,
3809 p_data_point_value => l_SUIT_IND,
3810 p_mode => p_mode,
3811 p_error_msg => p_error_msg,
3812 p_resultout => p_resultout);
3813
3814 build_case_folder_details(
3815 p_case_folder_id => p_case_folder_id,
3816 p_data_point_id => 11169,
3817 p_data_point_value => l_PAYDEX_INDUSTRY_DAYS,
3818 p_mode => p_mode,
3819 p_error_msg => p_error_msg,
3820 p_resultout => p_resultout);
3821
3822 build_case_folder_details(
3823 p_case_folder_id => p_case_folder_id,
3824 p_data_point_id => 11054,
3825 p_data_point_value => l_FINCL_LGL_EVENT_IND,
3826 p_mode => p_mode,
3827 p_error_msg => p_error_msg,
3828 p_resultout => p_resultout);
3829
3830 build_case_folder_details(
3831 p_case_folder_id => p_case_folder_id,
3832 p_data_point_id => 11052,
3833 p_data_point_value => l_DISASTER_IND,
3834 p_mode => p_mode,
3835 p_error_msg => p_error_msg,
3836 p_resultout => p_resultout);
3837
3838 build_case_folder_details(
3839 p_case_folder_id => p_case_folder_id,
3840 p_data_point_id => 11051,
3841 p_data_point_value => l_CRIMINAL_PROCEEDING_IND,
3842 p_mode => p_mode,
3843 p_error_msg => p_error_msg,
3844 p_resultout => p_resultout);
3845
3846 build_case_folder_details(
3847 p_case_folder_id => p_case_folder_id,
3848 p_data_point_id => 11049,
3849 p_data_point_value => l_FINCL_EMBT_IND,
3850 p_mode => p_mode,
3851 p_error_msg => p_error_msg,
3852 p_resultout => p_resultout);
3853
3854 build_case_folder_details(
3855 p_case_folder_id => p_case_folder_id,
3856 p_data_point_id => 11045,
3857 p_data_point_value => l_PAYDEX_NORM,
3858 p_mode => p_mode,
3859 p_error_msg => p_error_msg,
3860 p_resultout => p_resultout);
3861
3862 build_case_folder_details(
3863 p_case_folder_id => p_case_folder_id,
3864 p_data_point_id => 11116,
3865 p_data_point_value => l_RATING,
3866 p_mode => p_mode,
3867 p_error_msg => p_error_msg,
3868 p_resultout => p_resultout);
3869
3870 build_case_folder_details(
3871 p_case_folder_id => p_case_folder_id,
3872 p_data_point_id => 11060,
3873 p_data_point_value => l_SECURED_FLNG_IND,
3874 p_mode => p_mode,
3875 p_error_msg => p_error_msg,
3876 p_resultout => p_resultout);
3877
3878 build_case_folder_details(
3879 p_case_folder_id => p_case_folder_id,
3880 p_data_point_id => 11059,
3881 p_data_point_value => l_CLAIMS_IND,
3882 p_mode => p_mode,
3883 p_error_msg => p_error_msg,
3884 p_resultout => p_resultout);
3885
3886 build_case_folder_details(
3887 p_case_folder_id => p_case_folder_id,
3888 p_data_point_id => 11058,
3889 p_data_point_value => l_SUIT_JUDGE_IND,
3890 p_mode => p_mode,
3891 p_error_msg => p_error_msg,
3892 p_resultout => p_resultout);
3893
3894 build_case_folder_details(
3895 p_case_folder_id => p_case_folder_id,
3896 p_data_point_id => 11057,
3897 p_data_point_value => l_DET_HISTORY_IND,
3898 p_mode => p_mode,
3899 p_error_msg => p_error_msg,
3900 p_resultout => p_resultout);
3901
3902 build_case_folder_details(
3903 p_case_folder_id => p_case_folder_id,
3904 p_data_point_id => 11056,
3905 p_data_point_value => l_OTHER_SPEC_EVNT_IND,
3906 p_mode => p_mode,
3907 p_error_msg => p_error_msg,
3908 p_resultout => p_resultout);
3909
3910 build_case_folder_details(
3911 p_case_folder_id => p_case_folder_id,
3912 p_data_point_id => 11055,
3913 p_data_point_value => l_OPRG_SPEC_EVNT_IND,
3914 p_mode => p_mode,
3915 p_error_msg => p_error_msg,
3916 p_resultout => p_resultout);
3917
3918 build_case_folder_details(
3919 p_case_folder_id => p_case_folder_id,
3920 p_data_point_id => 11142,
3921 p_data_point_value => l_CREDIT_SCORE_COMMENTARY,
3922 p_mode => p_mode,
3923 p_error_msg => p_error_msg,
3924 p_resultout => p_resultout);
3925
3926
3927 FOR cFinNumRec IN cFinNum
3928 LOOP
3929 IF cFinNumRec.financial_number_name = 'CASH_LIQ_ASSETS'
3930 THEN
3931 l_cash_liqu_asset := cFinNumRec.financial_number;
3932 ELSIF cFinNumRec.financial_number_name = 'ACCOUNTS_RECEIVABLE'
3933 THEN
3934 l_ar := cFinNumRec.financial_number;
3935 ELSIF cFinNumRec.financial_number_name = 'ACCOUNTS_PAYABLE'
3936 THEN
3937 l_ap := cFinNumRec.financial_number;
3938 ELSIF cFinNumRec.financial_number_name = 'ANNUAL_SALES_VOLUME'
3939 THEN
3940 l_an_sales_vol := cFinNumRec.financial_number;
3941 ELSIF cFinNumRec.financial_number_name = 'AUTHORIZED_CAPITAL'
3942 THEN
3943 l_auth_cap := cFinNumRec.financial_number;
3944 ELSIF cFinNumRec.financial_number_name = 'COST_OF_SALES'
3945 THEN
3946 l_cost_of_sales := cFinNumRec.financial_number;
3947 ELSIF cFinNumRec.financial_number_name = 'CURRENT_RATIO'
3948 THEN
3949 l_current_ratio := cFinNumRec.financial_number;
3950 ELSIF cFinNumRec.financial_number_name = 'DIVIDENDS'
3951 THEN
3952 l_dividends := cFinNumRec.financial_number;
3953 ELSIF cFinNumRec.financial_number_name = 'FIXED_ASSETS'
3954 THEN
3955 l_fixed_assets := cFinNumRec.financial_number;
3956 ELSIF cFinNumRec.financial_number_name = 'GROSS_INCOME'
3957 THEN
3958 l_gross_inc := cFinNumRec.financial_number;
3959 ELSIF cFinNumRec.financial_number_name = 'INTANGIBLE_ASSETS'
3960 THEN
3961 l_intg_asset := cFinNumRec.financial_number;
3962 ELSIF cFinNumRec.financial_number_name = 'INVENTORY'
3963 THEN
3964 l_inventory := cFinNumRec.financial_number;
3965 ELSIF cFinNumRec.financial_number_name = 'ISSUED_CAPITAL'
3966 THEN
3967 l_iss_capital := cFinNumRec.financial_number;
3968 ELSIF cFinNumRec.financial_number_name = 'LONG_TERM_DEBT'
3969 THEN
3970 l_long_debt := cFinNumRec.financial_number;
3971 ELSIF cFinNumRec.financial_number_name = 'NET_INCOME'
3972 THEN
3973 l_net_income := cFinNumRec.financial_number;
3974 ELSIF cFinNumRec.financial_number_name = 'NET_WORTH'
3975 THEN
3976 l_net_worth := cFinNumRec.financial_number;
3977 ELSIF cFinNumRec.financial_number_name = 'NOMINAL_CAPITAL'
3978 THEN
3979 l_nom_capital := cFinNumRec.financial_number;
3980 ELSIF cFinNumRec.financial_number_name = 'PAID_IN_CAPITAL'
3981 THEN
3982 l_paid_in_capital := cFinNumRec.financial_number;
3983 ELSIF cFinNumRec.financial_number_name = 'PREVIOUS_SALES'
3984 THEN
3985 l_prev_sales := cFinNumRec.financial_number;
3986 ELSIF cFinNumRec.financial_number_name = 'PREV_NET_WORTH'
3987 THEN
3988 l_prev_net_worth := cFinNumRec.financial_number;
3989 ELSIF cFinNumRec.financial_number_name = 'PREV_WORKING_CAPITAL'
3990 THEN
3991 l_prev_work_cap := cFinNumRec.financial_number;
3992 ELSIF cFinNumRec.financial_number_name = 'PROFIT_BEFORE_TAX'
3993 THEN
3994 l_profit_bef_tax := cFinNumRec.financial_number;
3995 ELSIF cFinNumRec.financial_number_name = 'QUICK_RATIO'
3996 THEN
3997 l_quick_ratio := cFinNumRec.financial_number;
3998 ELSIF cFinNumRec.financial_number_name = 'RETAINED_EARNINGS'
3999 THEN
4000 l_ret_earnings := cFinNumRec.financial_number;
4001 ELSIF cFinNumRec.financial_number_name = 'SALES'
4002 THEN
4003 l_sales := cFinNumRec.financial_number;
4004 ELSIF cFinNumRec.financial_number_name = 'TANGIBLE_NET_WORTH'
4005 THEN
4006 l_tang_net_worth := cFinNumRec.financial_number;
4007 ELSIF cFinNumRec.financial_number_name = 'TOTAL_ASSETS'
4008 THEN
4009 l_tot_assets := cFinNumRec.financial_number;
4010 ELSIF cFinNumRec.financial_number_name = 'TOTAL_CURRENT_ASSETS'
4011 THEN
4012 l_tot_curr_assets := cFinNumRec.financial_number;
4013 ELSIF cFinNumRec.financial_number_name = 'TOTAL_CURR_LIABILITIES'
4014 THEN
4015 l_tot_curr_liab := cFinNumRec.financial_number;
4016 ELSIF cFinNumRec.financial_number_name = 'TOTAL_LIABILITIES'
4017 THEN
4018 l_tot_liab := cFinNumRec.financial_number;
4019 ELSIF cFinNumRec.financial_number_name = 'TOTAL_LIAB_EQUITY'
4020 THEN
4021 l_tot_liab_equ := cFinNumRec.financial_number;
4022 ELSIF cFinNumRec.financial_number_name = 'TOT_LONG_TERM_LIAB'
4023 THEN
4024 l_tot_long_liab := cFinNumRec.financial_number;
4025 END IF;
4026 END LOOP;
4027 build_case_folder_details(
4028 p_case_folder_id => p_case_folder_id,
4029 p_data_point_id => 11061,
4030 p_data_point_value => l_cash_liqu_asset,
4031 p_mode => p_mode,
4032 p_error_msg => p_error_msg,
4033 p_resultout => p_resultout);
4034 build_case_folder_details(
4035 p_case_folder_id => p_case_folder_id,
4036 p_data_point_id => 11062,
4037 p_data_point_value => l_ar,
4038 p_mode => p_mode,
4039 p_error_msg => p_error_msg,
4040 p_resultout => p_resultout);
4041 build_case_folder_details(
4042 p_case_folder_id => p_case_folder_id,
4043 p_data_point_id => 11063,
4044 p_data_point_value => l_ap,
4045 p_mode => p_mode,
4046 p_error_msg => p_error_msg,
4047 p_resultout => p_resultout);
4048 build_case_folder_details(
4049 p_case_folder_id => p_case_folder_id,
4050 p_data_point_id => 11067,
4051 p_data_point_value => l_inventory,
4052 p_mode => p_mode,
4053 p_error_msg => p_error_msg,
4054 p_resultout => p_resultout);
4055 build_case_folder_details(
4056 p_case_folder_id => p_case_folder_id,
4057 p_data_point_id => 11068,
4058 p_data_point_value => l_fixed_assets,
4059 p_mode => p_mode,
4060 p_error_msg => p_error_msg,
4061 p_resultout => p_resultout);
4062 build_case_folder_details(
4063 p_case_folder_id => p_case_folder_id,
4064 p_data_point_id => 11069,
4065 p_data_point_value => l_tot_curr_assets,
4066 p_mode => p_mode,
4067 p_error_msg => p_error_msg,
4068 p_resultout => p_resultout);
4069 build_case_folder_details(
4070 p_case_folder_id => p_case_folder_id,
4071 p_data_point_id => 11070,
4072 p_data_point_value => l_tot_curr_liab,
4073 p_mode => p_mode,
4074 p_error_msg => p_error_msg,
4075 p_resultout => p_resultout);
4076 build_case_folder_details(
4077 p_case_folder_id => p_case_folder_id,
4078 p_data_point_id => 11071,
4079 p_data_point_value => l_tot_assets,
4080 p_mode => p_mode,
4081 p_error_msg => p_error_msg,
4082 p_resultout => p_resultout);
4083 build_case_folder_details(
4084 p_case_folder_id => p_case_folder_id,
4085 p_data_point_id => 11072,
4086 p_data_point_value => l_intg_asset,
4087 p_mode => p_mode,
4088 p_error_msg => p_error_msg,
4089 p_resultout => p_resultout);
4090 build_case_folder_details(
4091 p_case_folder_id => p_case_folder_id,
4092 p_data_point_id => 11073,
4093 p_data_point_value => l_long_debt,
4094 p_mode => p_mode,
4095 p_error_msg => p_error_msg,
4096 p_resultout => p_resultout);
4097 build_case_folder_details(
4098 p_case_folder_id => p_case_folder_id,
4099 p_data_point_id => 11074,
4100 p_data_point_value => l_tot_long_liab,
4101 p_mode => p_mode,
4102 p_error_msg => p_error_msg,
4103 p_resultout => p_resultout);
4104 build_case_folder_details(
4105 p_case_folder_id => p_case_folder_id,
4106 p_data_point_id => 11075,
4107 p_data_point_value => l_tot_liab,
4108 p_mode => p_mode,
4109 p_error_msg => p_error_msg,
4110 p_resultout => p_resultout);
4111 build_case_folder_details(
4112 p_case_folder_id => p_case_folder_id,
4113 p_data_point_id => 11076,
4114 p_data_point_value => l_ret_earnings,
4115 p_mode => p_mode,
4116 p_error_msg => p_error_msg,
4117 p_resultout => p_resultout);
4118 build_case_folder_details(
4119 p_case_folder_id => p_case_folder_id,
4120 p_data_point_id => 11077,
4121 p_data_point_value => l_dividends,
4122 p_mode => p_mode,
4123 p_error_msg => p_error_msg,
4124 p_resultout => p_resultout);
4125 build_case_folder_details(
4126 p_case_folder_id => p_case_folder_id,
4127 p_data_point_id => 11078,
4128 p_data_point_value => l_net_worth,
4129 p_mode => p_mode,
4130 p_error_msg => p_error_msg,
4131 p_resultout => p_resultout);
4132 build_case_folder_details(
4133 p_case_folder_id => p_case_folder_id,
4134 p_data_point_id => 11079,
4135 p_data_point_value => l_tang_net_worth,
4136 p_mode => p_mode,
4137 p_error_msg => p_error_msg,
4138 p_resultout => p_resultout);
4139 build_case_folder_details(
4140 p_case_folder_id => p_case_folder_id,
4141 p_data_point_id => 11082,
4142 p_data_point_value =>l_prev_net_worth ,
4143 p_mode => p_mode,
4144 p_error_msg => p_error_msg,
4145 p_resultout => p_resultout);
4146 build_case_folder_details(
4147 p_case_folder_id => p_case_folder_id,
4148 p_data_point_id => 11083,
4149 p_data_point_value => l_tot_liab_equ,
4150 p_mode => p_mode,
4151 p_error_msg => p_error_msg,
4152 p_resultout => p_resultout);
4153 build_case_folder_details(
4154 p_case_folder_id => p_case_folder_id,
4155 p_data_point_id => 11084,
4156 p_data_point_value => l_sales,
4157 p_mode => p_mode,
4158 p_error_msg => p_error_msg,
4159 p_resultout => p_resultout);
4160 build_case_folder_details(
4161 p_case_folder_id => p_case_folder_id,
4162 p_data_point_id => 11085,
4163 p_data_point_value => l_an_sales_vol,
4164 p_mode => p_mode,
4165 p_error_msg => p_error_msg,
4166 p_resultout => p_resultout);
4167 build_case_folder_details(
4168 p_case_folder_id => p_case_folder_id,
4169 p_data_point_id => 11089,
4170 p_data_point_value => l_prev_sales,
4171 p_mode => p_mode,
4172 p_error_msg => p_error_msg,
4173 p_resultout => p_resultout);
4174 build_case_folder_details(
4175 p_case_folder_id => p_case_folder_id,
4176 p_data_point_id => 11090,
4177 p_data_point_value => l_cost_of_sales,
4178 p_mode => p_mode,
4179 p_error_msg => p_error_msg,
4180 p_resultout => p_resultout);
4181 build_case_folder_details(
4182 p_case_folder_id => p_case_folder_id,
4183 p_data_point_id => 11091,
4184 p_data_point_value => l_gross_inc,
4185 p_mode => p_mode,
4186 p_error_msg => p_error_msg,
4187 p_resultout => p_resultout);
4188 build_case_folder_details(
4189 p_case_folder_id => p_case_folder_id,
4190 p_data_point_id => 11092,
4191 p_data_point_value => l_net_income,
4192 p_mode => p_mode,
4193 p_error_msg => p_error_msg,
4194 p_resultout => p_resultout);
4195 build_case_folder_details(
4196 p_case_folder_id => p_case_folder_id,
4197 p_data_point_id => 11112,
4198 p_data_point_value => l_current_ratio,
4199 p_mode => p_mode,
4200 p_error_msg => p_error_msg,
4201 p_resultout => p_resultout);
4202 build_case_folder_details(
4203 p_case_folder_id => p_case_folder_id,
4204 p_data_point_id => 11113,
4205 p_data_point_value => l_quick_ratio,
4206 p_mode => p_mode,
4207 p_error_msg => p_error_msg,
4208 p_resultout => p_resultout);
4209
4210 -- populate all financial report releated data
4211 BUILD_DNB_SCORABLE_FIN_DATA (
4212 p_case_folder_id => p_case_folder_id,
4213 p_mode => p_mode,
4214 p_financial_report_id => p_balance_sheet_id,
4215 p_financial_report_type => 'BALANCE_SHEET' ,
4216 p_error_msg => p_error_msg,
4217 p_resultout => p_resultout);
4218
4219 BUILD_DNB_SCORABLE_FIN_DATA (
4220 p_case_folder_id => p_case_folder_id,
4221 p_mode => p_mode,
4222 p_financial_report_id => p_income_statement_id,
4223 p_financial_report_type => 'INCOME' ,
4224 p_error_msg => p_error_msg,
4225 p_resultout => p_resultout);
4226
4227 BUILD_DNB_SCORABLE_FIN_DATA (
4228 p_case_folder_id => p_case_folder_id,
4229 p_mode => p_mode,
4230 p_financial_report_id => p_tangible_net_worth_id,
4231 p_financial_report_type => 'TANGIBLE' ,
4232 p_error_msg => p_error_msg,
4233 p_resultout => p_resultout);
4234
4235 BUILD_DNB_SCORABLE_FIN_DATA (
4236 p_case_folder_id => p_case_folder_id,
4237 p_mode => p_mode,
4238 p_financial_report_id => p_annual_sales_volume_id,
4239 p_financial_report_type => 'ANNUAL_SALES' ,
4240 p_error_msg => p_error_msg,
4241 p_resultout => p_resultout);
4242
4243 IF pg_wf_debug = 'Y'
4244 THEN
4245 ar_cmgt_util.wf_debug(p_case_folder_id,
4246 'ar_cmgt_data_points_pkg.build_dnb_scorable_data()-');
4247 END IF;
4248 END BUILD_DNB_SCOREABLE_DATA;
4249
4250
4251 PROCEDURE BUILD_DNB_CASE_FOLDER(
4252 p_party_id IN NUMBER,
4253 p_check_list_id IN NUMBER,
4254 p_case_folder_id IN NUMBER,
4255 p_mode IN VARCHAR2 default 'CREATE',
4256 p_resultout OUT nocopy VARCHAR2,
4257 p_error_msg OUT nocopy VARCHAR2) IS
4258
4259 l_organization_profile_id hz_organization_profiles.organization_profile_id%TYPE;
4260 l_location_id hz_locations.location_id%TYPE;
4261 l_contact_point_id hz_contact_points.contact_point_id%TYPE;
4262 l_relationship_id hz_relationships.relationship_id%TYPE;
4263 l_report_type hz_financial_reports.type_of_financial_report%TYPE := 'BALANCE_SHEET';
4264 l_credit_rating_id NUMBER;
4265 l_financial_report_id NUMBER;
4266 l_hq_branch_ind hz_parties.hq_branch_ind%type;
4267 l_balance_sheet_id NUMBER;
4268 l_income_statement_id NUMBER;
4269 l_tangible_net_worth_id NUMBER;
4270 l_annual_sales_volume_id NUMBER;
4271
4272 CURSOR c_relationships IS
4273 SELECT rel.relationship_id, rel.relationship_code
4274 FROM hz_relationships rel
4275 WHERE rel.object_id = p_party_id
4276 AND rel.relationship_code in ('HEADQUARTERS_OF','PARENT_OF',
4277 'DOMESTIC_ULTIMATE_OF','GLOBAL_ULTIMATE_OF')
4278 AND rel.actual_content_source = 'DNB'
4279 AND rel.start_date <= sysdate
4280 AND NVL(rel.end_date, to_date('12/31/4712','MM/DD/YYYY')) > sysdate
4281 AND rel.subject_table_name = 'HZ_PARTIES'
4282 AND rel.object_table_name = 'HZ_PARTIES';
4283
4284 CURSOR c_contact_point IS
4285 SELECT contact_point_id, phone_line_type
4286 FROM hz_contact_points
4287 WHERE owner_table_name = 'HZ_PARTIES'
4288 AND owner_table_id = p_party_id
4289 AND contact_point_type = 'PHONE'
4290 AND actual_content_source = 'DNB'
4291 AND phone_line_type in ('FAX','GEN')
4292 AND status = 'A';
4293
4294 CURSOR c_dnb_data_point IS
4295 SELECT data_point_id
4296 FROM ar_cmgt_data_points_vl
4297 WHERE data_point_category = 'DNB';
4298
4299
4300
4301 BEGIN
4302 IF pg_wf_debug = 'Y'
4303 THEN
4304 ar_cmgt_util.wf_debug(p_case_folder_id,
4305 'ar_cmgt_data_points_pkg.build_dnb_case_folder()+');
4306 END IF;
4307 p_resultout := 0;
4308 -- build the case folder details table for DNB data. In case of
4309 -- dnb data datpoint value will be null.
4310 FOR c_dnb_data_point_rec IN c_dnb_data_point
4311 LOOP
4312 build_case_folder_details(
4313 p_case_folder_id => p_case_folder_id,
4314 p_data_point_id => c_dnb_data_point_rec.data_point_id,
4315 p_data_point_value => NULL,
4316 p_mode => p_mode,
4317 p_error_msg => p_error_msg,
4318 p_resultout => p_resultout);
4319 IF p_resultout <> 0
4320 THEN
4321 p_error_msg := 'Error while populating DNB data, Data Points Id: '||
4322 c_dnb_data_point_rec.data_point_id;
4323 return;
4324 END IF;
4325
4326 END LOOP;
4327
4328 -- disable the policy function in hz tables
4329 -- so that Enable the visibility of DNB data
4330 hz_common_pub.disable_cont_source_security;
4331 -- Get all primary keys from HZ table for DNB reports
4332
4333 -- Get information from hz_party
4334 BEGIN
4335 SELECT hq_branch_ind
4336 INTO l_hq_branch_ind
4337 FROM hz_parties
4338 WHERE party_id = p_party_id;
4339
4340 populate_dnb_data(
4341 p_case_folder_id => p_case_folder_id,
4342 p_source_table_name => 'HZ_PARTIES',
4343 p_source_key => p_party_id,
4344 p_source_key_column_name => 'PARTY_ID',
4345 p_mode => p_mode);
4346 EXCEPTION
4347 WHEN NO_DATA_FOUND THEN
4348 NULL;
4349 WHEN OTHERS THEN
4350 p_resultout := 1;
4351 p_error_msg := 'SqlError While retrieving Data from HZ_PARTIES '||sqlerrm;
4352 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
4353 return;
4354 END;
4355
4356 -- Get organization profile ID
4357
4358 BEGIN
4359 SELECT ORGANIZATION_PROFILE_ID
4360 INTO l_organization_profile_id
4361 FROM HZ_ORGANIZATION_PROFILES
4362 WHERE party_id = p_party_id
4363 AND effective_end_date IS NULL
4364 AND ACTUAL_CONTENT_SOURCE = 'DNB';
4365
4366 populate_dnb_data(
4367 p_case_folder_id => p_case_folder_id,
4368 p_source_table_name => 'HZ_ORGANIZATION_PROFILES',
4369 p_source_key => l_organization_profile_id,
4370 p_source_key_column_name => 'ORGANIZATION_PROFILE_ID',
4371 p_mode => p_mode);
4372 EXCEPTION
4373 WHEN NO_DATA_FOUND THEN
4374 NULL;
4375 WHEN OTHERS THEN
4376 p_resultout := 1;
4377 p_error_msg := 'SqlError While retrieving Data from HZ_ORGANIZATION_PROFILES '||sqlerrm;
4378 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
4379 return;
4380 END;
4381 -- Get location id
4382 l_location_id := hz_dnbui_pvt.get_location_id(p_party_id, 'DNB');
4383 IF ( l_location_id IS NOT NULL )
4384 THEN
4385
4386 populate_dnb_data(
4387 p_case_folder_id => p_case_folder_id,
4388 p_source_table_name => 'HZ_LOCATIONS',
4389 p_source_key => l_location_id,
4390 p_source_key_column_name => 'LOCATION_ID',
4391 p_mode => p_mode);
4392 END IF;
4393
4394 -- Get contact point id for phone line type 'GEN'
4395
4396 FOR c_contact_point_rec IN c_contact_point
4397 LOOP
4398
4399 populate_dnb_data(
4400 p_case_folder_id => p_case_folder_id,
4401 p_source_table_name => 'HZ_CONTACT_POINTS',
4402 p_source_key => c_contact_point_rec.contact_point_id,
4403 p_source_key_column_name => 'CONTACT_POINT_ID',
4404 p_mode => p_mode,
4405 p_source_key_type => c_contact_point_rec.phone_line_type,
4406 p_source_key_column_type => 'CONTACT_POINT_TYPE');
4407 END LOOP;
4408
4409 -- get credit ratings
4410 l_credit_rating_id := hz_dnbui_pvt.get_max_credit_rating_id(p_party_id, 'DNB');
4411
4412 IF l_credit_rating_id IS NOT NULL
4413 THEN
4414 populate_dnb_data(
4415 p_case_folder_id => p_case_folder_id,
4416 p_source_table_name => 'HZ_CREDIT_RATINGS',
4417 p_source_key => l_credit_rating_id,
4418 p_source_key_column_name => 'CREDIT_RATING_ID',
4419 p_mode => p_mode
4420 );
4421 END IF;
4422 -- get financial report id for Balance Sheet
4423 l_financial_report_id :=
4424 hz_dnbui_pvt.get_max_financial_report_id(p_party_id,'BALANCE_SHEET','DNB');
4425 l_balance_sheet_id := l_financial_report_id;
4426 IF l_financial_report_id IS NOT NULL
4427 THEN
4428 populate_dnb_data(
4429 p_case_folder_id => p_case_folder_id,
4430 p_source_table_name => 'HZ_FINANCIAL_REPORTS',
4431 p_source_key => l_financial_report_id,
4432 p_source_key_column_name => 'FINANCIAL_REPORT_ID',
4433 p_mode => p_mode,
4434 p_source_key_type => 'BALANCE_SHEET',
4435 p_source_key_column_type => 'TYPE_OF_FINANCIAL_REPORT');
4436
4437 END IF;
4438
4439 l_financial_report_id :=
4440 hz_dnbui_pvt.get_max_financial_report_id(p_party_id,'INCOME_STATEMENT','DNB');
4441 l_income_statement_id := l_financial_report_id;
4442 IF l_financial_report_id IS NOT NULL
4443 THEN
4444 populate_dnb_data(
4445 p_case_folder_id => p_case_folder_id,
4446 p_source_table_name => 'HZ_FINANCIAL_REPORTS',
4447 p_source_key => l_financial_report_id,
4448 p_source_key_column_name => 'FINANCIAL_REPORT_ID',
4449 p_mode => p_mode,
4450 p_source_key_type => 'INCOME_STATEMENT',
4451 p_source_key_column_type => 'TYPE_OF_FINANCIAL_REPORT');
4452
4453 END IF;
4454
4455 l_financial_report_id :=
4456 hz_dnbui_pvt.get_max_financial_report_id(p_party_id,'TANGIBLE_NET_WORTH','DNB');
4457 l_tangible_net_worth_id := l_financial_report_id;
4458
4459 IF l_financial_report_id IS NOT NULL
4460 THEN
4461 populate_dnb_data(
4462 p_case_folder_id => p_case_folder_id,
4463 p_source_table_name => 'HZ_FINANCIAL_REPORTS',
4464 p_source_key => l_financial_report_id,
4465 p_source_key_column_name => 'FINANCIAL_REPORT_ID',
4466 p_mode => p_mode,
4467 p_source_key_type => 'TANGIBLE_NET_WORTH',
4468 p_source_key_column_type => 'TYPE_OF_FINANCIAL_REPORT');
4469
4470 END IF;
4471
4472 -- Build all the scorable data points which is releated to Tangible_net_worth
4473
4474
4475 l_financial_report_id :=
4476 hz_dnbui_pvt.get_max_financial_report_id(p_party_id,'ANNUAL_SALES_VOLUME','DNB');
4477 l_annual_sales_volume_id := l_financial_report_id;
4478 IF l_financial_report_id IS NOT NULL
4479 THEN
4480 populate_dnb_data(
4481 p_case_folder_id => p_case_folder_id,
4482 p_source_table_name => 'HZ_FINANCIAL_REPORTS',
4483 p_source_key => l_financial_report_id,
4484 p_source_key_column_name => 'FINANCIAL_REPORT_ID',
4485 p_mode => p_mode,
4486 p_source_key_type => 'ANNUAL_SALES_VOLUME',
4487 p_source_key_column_type => 'TYPE_OF_FINANCIAL_REPORT');
4488
4489 END IF;
4490
4491
4492 /* -- populate relationship model
4493 FOR c_relationship_rec IN c_relationships
4494 LOOP
4495 populate_dnb_data(
4496 p_case_folder_id => p_case_folder_id,
4497 p_source_table_name => 'HZ_RELATIONSHIPS',
4498 p_source_key => c_relationship_rec.relationship_id,
4499 p_source_key_column_name => 'RELATIONSHIP_ID',
4500 p_mode => p_mode,
4501 p_source_key_type => c_relationship_rec.relationship_code,
4502 p_source_key_column_type => 'RELATIONSHIP_CODE'
4503 );
4504 END LOOP;
4505 */
4506 -- Now create the scorable data into case folder table
4507
4508 BUILD_DNB_SCOREABLE_DATA
4509 (p_case_folder_id => p_case_folder_id,
4510 p_mode => p_mode,
4511 p_org_profile_id => l_organization_profile_id,
4512 p_credit_rating_id => l_credit_rating_id,
4513 p_location_id => l_location_id,
4514 p_balance_sheet_id => l_balance_sheet_id,
4515 p_income_statement_id => l_income_statement_id,
4516 p_tangible_net_worth_id => l_tangible_net_worth_id,
4517 p_annual_sales_volume_id => l_annual_sales_volume_id,
4518 p_resultout => p_resultout,
4519 p_error_msg => p_error_msg );
4520
4521 -- disable the visibility of DNB data
4522 hz_common_pub.enable_cont_source_security;
4523 IF pg_wf_debug = 'Y'
4524 THEN
4525 ar_cmgt_util.wf_debug(p_case_folder_id,
4526 'ar_cmgt_data_points_pkg.build_dnb_case_folder()-');
4527 END IF;
4528
4529 EXCEPTION
4530 WHEN OTHERS THEN
4531 p_resultout := 1;
4532 p_error_msg := 'Error while populating DNB data '||sqlerrm;
4533 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
4534 END;
4535
4536
4537 FUNCTION get_conversion_type( p_credit_request_id IN NUMBER)
4538 return VARCHAR2 IS
4539
4540 CURSOR getCreditRequestDetails (p_cr_req_id IN NUMBER)
4541 IS
4542 select credit_check_rule_id,
4543 source_name
4544 from ar_cmgt_credit_requests
4545 where credit_request_id = p_cr_req_id;
4546
4547
4548 CURSOR getRateTYpeFromCreditChkRule(p_cr_chk_rule_id IN NUMBER) IS
4549 select conversion_type
4550 from oe_credit_check_rules
4551 where credit_check_rule_id = p_cr_chk_rule_id;
4552
4553 CURSOR getRateTypeFromSetup
4554 IS
4555 SELECT default_exchange_rate_type
4556 FROM ar_cmgt_setup_options;
4557
4558 l_rule_id NUMBER;
4559 l_source_name VARCHAR2(50);
4560 l_exchange_rate_type VARCHAR2(50);
4561
4562 begin
4563
4564 IF (p_credit_request_id IS NOT NULL )
4565 THEN
4566
4567 OPEN getCreditRequestDetails(p_credit_request_id );
4568
4569 FETCH getCreditRequestDetails INTO l_rule_id, l_source_name;
4570 IF NVL(l_source_name,'X') = 'OM' AND
4571 (l_rule_id IS NOT NULL) THEN
4572
4573 OPEN getRateTYpeFromCreditChkRule(l_rule_id);
4574 FETCH getRateTYpeFromCreditChkRule INTO l_exchange_rate_type;
4575 CLOSE getRateTYpeFromCreditChkRule;
4576 END IF;
4577
4578 IF l_exchange_rate_type IS NULL THEN
4579
4580 OPEN getRateTypeFromSetup;
4581 FETCH getRateTypeFromSetup INTO l_exchange_rate_type;
4582
4583 CLOSE getRateTypeFromSetup;
4584 END IF;
4585
4586 END IF;
4587
4588 RETURN l_exchange_rate_type;
4589
4590 END;
4591 /* kosrinv ..Changing The procedure to store the data point values in a proper format ..
4592 bug 5525814 ...............*/
4593 PROCEDURE GATHER_DATA_POINTS(
4594 p_party_id IN NUMBER,
4595 p_cust_account_id IN NUMBER,
4596 p_cust_acct_site_id IN NUMBER,
4597 p_trx_currency IN VARCHAR2,
4598 p_org_id IN NUMBER,
4599 p_check_list_id IN NUMBER,
4600 p_credit_request_id IN NUMBER,
4601 p_score_model_id IN NUMBER,
4602 p_credit_classification IN VARCHAR2,
4603 p_review_type IN VARCHAR2,
4604 p_case_folder_number IN VARCHAR2,
4605 p_mode IN VARCHAR2,
4606 p_limit_currency OUT nocopy VARCHAR2,
4607 p_case_folder_id IN OUT nocopy NUMBER,
4608 p_error_msg OUT nocopy VARCHAR2,
4609 p_resultout OUT nocopy VARCHAR2) IS
4610
4611
4612
4613 l_curr_array_list curr_array_type;
4614 l_check_list_id ar_cmgt_check_lists.check_list_id%type;
4615 summary_rec_str VARCHAR2(4000);
4616 l_certified_dso_days ar_cmgt_setup_options.cer_dso_days%type;
4617 l_data_point_id NUMBER;
4618 l_data_point_name ar_cmgt_data_points_vl.data_point_name%type;
4619 l_case_folder_id NUMBER;
4620 l_error_msg VARCHAR2(4000);
4621 l_resultout VARCHAR2(2000);
4622 l_period ar_cmgt_setup_options.period%type;
4623 l_data_point_value ar_cmgt_cf_dtls.data_point_value%type;
4624 l_start_pos NUMBER;
4625 l_end_pos NUMBER;
4626 l_combo_string VARCHAR2(100);
4627 l_data_point_id_end_pos NUMBER;
4628 l_global_exposure_flag hz_credit_usage_rule_sets_b.global_exposure_flag%type;
4629 l_analysis_level VARCHAR2(1);
4630 l_trx_limit NUMBER;
4631 l_limit_currency VARCHAR2(30);
4632 l_include_all_flag VARCHAR2(1);
4633 l_curr_tbl HZ_CREDIT_USAGES_PKG.curr_tbl_type;
4634 l_excl_curr_list VARCHAR2(2000);
4635 l_exchange_rate_type ar_cmgt_setup_options.default_exchange_rate_type%type;
4636 l_overall_limit NUMBER;
4637 l_cust_acct_profile_amt_id NUMBER;
4638 l_case_folder_id_1 number;
4639 l_dso number;
4640 l_ddso number;
4641 l_deno_dso number := 1;
4642 l_deno_ddso number := 1;
4643 l_numerator_dso number;
4644 l_numerator_ddso number;
4645 l_party_number hz_parties.party_number%type;
4646 l_score number;
4647
4648
4649
4650 -- No. of coulmns in each cursor. if select columns in any of the cursor we need to
4651 -- change these numberes.
4652 summary_rec_col_count NUMBER := 30;
4653 bal_summary_rec_col_count NUMBER := 23;
4654
4655
4656 /*********** CAUTIONS **********************************************
4657 -- if you are adding/removing an column in this cursor please
4658 -- update the summary_rec_col_count varibale with proper number.
4659 -- case receipts amount (156) is stored in summary tables as -ve
4660 -- So we are multiplying to -1 to show the opposite value as part of
4661 -- bug fixes 2824382.
4662 ********************************************************************/
4663 CURSOR c_party_summary IS
4664 SELECT '4'||'^'||fnd_number.number_to_canonical(SUM(avg_pmt_days)) avg_pmt_days,
4665 '5'||'^'||fnd_number.number_to_canonical(SUM(weight_avg_days_late)) weight_avg_days_late,
4666 '8'||'^'||fnd_number.number_to_canonical(SUM(days_credit_granted)) days_credit_granted,
4667 '13'||'^'||fnd_number.number_to_canonical(SUM(nsf_payment_count)) nsf_payment_count,
4668 '14'||'^'||fnd_number.number_to_canonical(SUM(nsf_payment_amount)) nsf_payment_amount,
4669 '17'||'^'||fnd_number.number_to_canonical(SUM(credit_memo_value)) credit_memo_value,
4670 '18'||'^'||fnd_number.number_to_canonical(SUM(credit_memo_count)) credit_memo_count,
4671 '21'||'^'||fnd_number.number_to_canonical(SUM(per_inv_paid_promptly)) per_inv_paid_promptly,
4672 '22'||'^'||fnd_number.number_to_canonical(SUM(per_inv_paid_late)) per_inv_paid_late,
4673 '23'||'^'||fnd_number.number_to_canonical(SUM(per_inv_with_discount)) per_inv_with_discount,
4674 '41'||'^'||fnd_number.number_to_canonical(SUM(inv_paid_amount)) inv_paid_amount,
4675 '42'||'^'||fnd_number.number_to_canonical(SUM(inv_paid_count)) inv_paid_count,
4676 '43'||'^'||fnd_number.number_to_canonical(SUM(earned_disc_value)) earned_disc_value,
4677 '44'||'^'||fnd_number.number_to_canonical(SUM(earned_disc_count)) earned_disc_count,
4678 '45'||'^'||fnd_number.number_to_canonical(SUM(unearned_disc_value)) unearned_disc_value,
4679 '46'||'^'||fnd_number.number_to_canonical(SUM(unearned_disc_count)) unearned_disc_count,
4680 '156'||'^'||fnd_number.number_to_canonical(SUM(total_cash_receipts_value)) total_cash_receipts_value,
4681 '157'||'^'||fnd_number.number_to_canonical(SUM(total_cash_receipts_count)) total_cash_receipts_count,
4682 '158'||'^'||fnd_number.number_to_canonical(SUM(total_invoices_value)) total_invoices_value,
4683 '159'||'^'||fnd_number.number_to_canonical(SUM(total_invoices_count)) total_invoices_count,
4684 '160'||'^'||fnd_number.number_to_canonical(SUM(total_bills_receivables_value)) total_bills_receivables_value,
4685 '161'||'^'||fnd_number.number_to_canonical(SUM(total_bills_receivables_count)) total_bills_receivables_count,
4686 '162'||'^'||fnd_number.number_to_canonical(SUM(total_debit_memos_value)) total_debit_memos_value,
4687 '163'||'^'||fnd_number.number_to_canonical(SUM(total_debit_memos_count)) total_debit_memos_count,
4688 '164'||'^'||fnd_number.number_to_canonical(SUM(total_chargeback_value)) total_chargeback_value,
4689 '165'||'^'||fnd_number.number_to_canonical(SUM(total_chargeback_count)) total_chargeback_count,
4690 '166'||'^'||fnd_number.number_to_canonical(SUM(total_adjustments_value)) total_adjustments_value,
4691 '167'||'^'||fnd_number.number_to_canonical(SUM(total_adjustments_count)) total_adjustments_count,
4692 '168'||'^'||fnd_number.number_to_canonical(SUM(total_deposits_value)) total_deposits_value,
4693 '169'||'^'||fnd_number.number_to_canonical(SUM(total_deposits_count)) total_deposits_count
4694 FROM ( SELECT
4695 round(gl_currency_api.convert_amount(CURRENCY,
4696 l_limit_currency,sysdate,
4697 l_exchange_rate_type,
4698 (SUM(INV_INST_PMT_DAYS_SUM)
4699 /decode(SUM(SUM_APP_AMT),0,1,
4700 SUM(SUM_APP_AMT)))),2) avg_pmt_days, -- weighted Average Payment Days
4701 round(gl_currency_api.convert_amount(currency,
4702 l_limit_currency,sysdate,
4703 l_exchange_rate_type,
4704 (SUM(SUM_APP_AMT_DAYS_LATE)
4705 /decode(SUM(SUM_APP_AMT),0,1,SUM(SUM_APP_AMT)))),2) weight_avg_days_late, -- Weighted Average Days Late
4706 round(SUM(DAYS_CREDIT_GRANTED_SUM)/
4707 decode(SUM(TOTAL_INVOICES_VALUE),0,1,
4708 SUM(TOTAL_INVOICES_VALUE)),2) days_credit_granted, -- days credit granted
4709 SUM(NSF_STOP_PAYMENT_COUNT) nsf_payment_count, -- NSF/Stop Payment Count
4710 round(gl_currency_api.convert_amount(currency,
4711 l_limit_currency,sysdate,
4712 l_exchange_rate_type,
4713 SUM(NSF_STOP_PAYMENT_AMOUNT)),2) nsf_payment_amount, -- NSF/Stop Payment Amount
4714 round(gl_currency_api.convert_amount(currency,
4715 l_limit_currency,sysdate,
4716 l_exchange_rate_type,
4717 SUM(TOTAL_CREDIT_MEMOS_VALUE)),2) credit_memo_value, -- Credit memos value
4718 SUM(TOTAL_CREDIT_MEMOS_COUNT) credit_memo_count, -- Credit memos count
4719 round(gl_currency_api.convert_amount(currency,
4720 l_limit_currency,sysdate,
4721 l_exchange_rate_type,
4722 ((SUM(count_of_tot_inv_inst_paid)-
4723 SUM(count_of_inv_inst_paid_late))*100)/
4724 decode(SUM(count_of_tot_inv_inst_paid),0,1,
4725 SUM(count_of_tot_inv_inst_paid))),2) per_inv_paid_promptly, -- % of invoice paid promptly
4726 round(gl_currency_api.convert_amount(currency,
4727 l_limit_currency,sysdate,
4728 l_exchange_rate_type,
4729 ((SUM(count_of_inv_inst_paid_late)*100)/
4730 decode(SUM(count_of_tot_inv_inst_paid),0,1,
4731 SUM(count_of_tot_inv_inst_paid)))),2) per_inv_paid_late, -- % of invoice paid late
4732 round(gl_currency_api.convert_amount(currency,
4733 l_limit_currency,sysdate,
4734 l_exchange_rate_type,
4735 ((SUM(count_of_disc_inv_inst)*100)/
4736 decode(SUM(count_of_tot_inv_inst_paid),0,1,
4737 SUM(count_of_tot_inv_inst_paid)))),2) per_inv_with_discount, -- % of invoice with discount taken
4738 round(gl_currency_api.convert_amount(currency,
4739 l_limit_currency,sysdate,
4740 l_exchange_rate_type,
4741 SUM(INV_PAID_AMOUNT)),2) inv_paid_amount, -- invoices paid amount
4742 SUM(count_of_tot_inv_inst_paid) inv_paid_count, -- invoices paid count
4743 round(gl_currency_api.convert_amount(currency,
4744 l_limit_currency,sysdate,
4745 l_exchange_rate_type,
4746 SUM(TOTAL_EARNED_DISC_VALUE)),2) earned_disc_value, -- Earned Dscount Value
4747 SUM(TOTAL_EARNED_DISC_COUNT) earned_disc_count, -- Earned Dscount count
4748 round(gl_currency_api.convert_amount(currency,
4749 l_limit_currency,sysdate,
4750 l_exchange_rate_type,
4751 SUM(TOTAL_UNEARNED_DISC_VALUE)),2) unearned_disc_value, -- UnEarned Dscount Value
4752 SUM(TOTAL_UNEARNED_DISC_COUNT) unearned_disc_count, -- UnEarned Dscount count
4753 (round(gl_currency_api.convert_amount(currency,
4754 l_limit_currency,sysdate,
4755 l_exchange_rate_type,
4756 SUM(TOTAL_CASH_RECEIPTS_VALUE)),2) * -1) total_cash_receipts_value, -- see the comment above
4757 SUM(TOTAL_CASH_RECEIPTS_COUNT) total_cash_receipts_count,
4758 round(gl_currency_api.convert_amount(currency,
4759 l_limit_currency,sysdate,
4760 l_exchange_rate_type,
4761 SUM(TOTAL_INVOICES_VALUE)),2) total_invoices_value,
4762 SUM(TOTAL_INVOICES_COUNT) total_invoices_count,
4763 round(gl_currency_api.convert_amount(currency,
4764 l_limit_currency,sysdate,
4765 l_exchange_rate_type,
4766 SUM(TOTAL_BILLS_RECEIVABLES_VALUE)),2) total_bills_receivables_value,
4767 SUM(TOTAL_BILLS_RECEIVABLES_COUNT) TOTAL_BILLS_RECEIVABLES_count,
4768 round(gl_currency_api.convert_amount(currency,
4769 l_limit_currency,sysdate,
4770 l_exchange_rate_type,
4771 SUM(TOTAL_DEBIT_MEMOS_VALUE)),2) total_debit_memos_value,
4772 SUM(TOTAL_DEBIT_MEMOS_COUNT) TOTAL_debit_memos_count,
4773 round(gl_currency_api.convert_amount(currency,
4774 l_limit_currency,sysdate,
4775 l_exchange_rate_type,
4776 SUM(TOTAL_CHARGEBACK_VALUE)),2) total_chargeback_value,
4777 SUM(TOTAL_chargeback_COUNT) TOTAL_chargeback_count ,
4778 round(gl_currency_api.convert_amount(currency,
4779 l_limit_currency,sysdate,
4780 l_exchange_rate_type,
4781 SUM(TOTAL_ADJUSTMENTS_VALUE)),2) total_adjustments_value,
4782 SUM(TOTAL_adjustments_COUNT) TOTAL_adjustments_count ,
4783 round(gl_currency_api.convert_amount(currency,
4784 l_limit_currency,sysdate,
4785 l_exchange_rate_type,
4786 SUM(TOTAL_DEPOSITS_VALUE)),2) total_deposits_value,
4787 SUM(TOTAL_deposits_COUNT) TOTAL_deposits_count
4788 FROM AR_TRX_SUMMARY
4789 WHERE CUST_ACCOUNT_ID in (select cust_account_id
4790 FROM hz_cust_accounts
4791 WHERE party_id in
4792 ( SELECT child_id
4793 from hz_hierarchy_nodes
4794 where parent_object_type = 'ORGANIZATION'
4795 and parent_table_name = 'HZ_PARTIES'
4796 and child_object_type = 'ORGANIZATION'
4797 and parent_id = p_party_id
4798 and effective_start_date <= sysdate
4799 and effective_end_date >= sysdate
4800 and hierarchy_type = FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
4801 and g_source_name <> 'LNS'
4802 union select p_party_id from dual
4803 UNION
4804 select hz_party_id
4805 from LNS_LOAN_PARTICIPANTS_V
4806 where loan_id = g_source_id
4807 and participant_type_code = 'COBORROWER'
4808 and g_source_name = 'LNS'
4809 and (end_date_active is null OR
4810 (sysdate between start_date_active and end_date_active)
4811 )
4812 ))
4813 and CURRENCY IN ( SELECT CURRENCY FROM
4814 ar_cmgt_curr_usage_gt
4815 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
4816 /*( SELECT * FROM
4817 TABLE(CAST(l_curr_array_list AS curr_array_type))) */
4818 and as_of_date >= ADD_MONTHS(sysdate,(-l_period))
4819 group by currency );
4820
4821
4822 CURSOR c_account_summary IS
4823 SELECT '4'||'^'||fnd_number.number_to_canonical(SUM(avg_pmt_days)) avg_pmt_days,
4824 '5'||'^'||fnd_number.number_to_canonical(SUM(weight_avg_days_late)) weight_avg_days_late,
4825 '8'||'^'||fnd_number.number_to_canonical(SUM(days_credit_granted)) days_credit_granted,
4826 '13'||'^'||fnd_number.number_to_canonical(SUM(nsf_payment_count)) nsf_payment_count,
4827 '14'||'^'||fnd_number.number_to_canonical(SUM(nsf_payment_amount)) nsf_payment_amount,
4828 '17'||'^'||fnd_number.number_to_canonical(SUM(credit_memo_value)) credit_memo_value,
4829 '18'||'^'||fnd_number.number_to_canonical(SUM(credit_memo_count)) credit_memo_count,
4830 '21'||'^'||fnd_number.number_to_canonical(SUM(per_inv_paid_promptly)) per_inv_paid_promptly,
4831 '22'||'^'||fnd_number.number_to_canonical(SUM(per_inv_paid_late)) per_inv_paid_late,
4832 '23'||'^'||fnd_number.number_to_canonical(SUM(per_inv_with_discount)) per_inv_with_discount,
4833 '41'||'^'||fnd_number.number_to_canonical(SUM(inv_paid_amount)) inv_paid_amount,
4834 '42'||'^'||fnd_number.number_to_canonical(SUM(inv_paid_count)) inv_paid_count,
4835 '43'||'^'||fnd_number.number_to_canonical(SUM(earned_disc_value)) earned_disc_value,
4836 '44'||'^'||fnd_number.number_to_canonical(SUM(earned_disc_count)) earned_disc_count,
4837 '45'||'^'||fnd_number.number_to_canonical(SUM(unearned_disc_value)) unearned_disc_value,
4838 '46'||'^'||fnd_number.number_to_canonical(SUM(unearned_disc_count)) unearned_disc_count,
4839 '156'||'^'||fnd_number.number_to_canonical(SUM(total_cash_receipts_value)) total_cash_receipts_value,
4840 '157'||'^'||fnd_number.number_to_canonical(SUM(total_cash_receipts_count)) total_cash_receipts_count,
4841 '158'||'^'||fnd_number.number_to_canonical(SUM(total_invoices_value)) total_invoices_value,
4842 '159'||'^'||fnd_number.number_to_canonical(SUM(total_invoices_count)) total_invoices_count,
4843 '160'||'^'||fnd_number.number_to_canonical(SUM(total_bills_receivables_value)) total_bills_receivables_value,
4844 '161'||'^'||fnd_number.number_to_canonical(SUM(total_bills_receivables_count)) total_bills_receivables_count,
4845 '162'||'^'||fnd_number.number_to_canonical(SUM(total_debit_memos_value)) total_debit_memos_value,
4846 '163'||'^'||fnd_number.number_to_canonical(SUM(total_debit_memos_count)) total_debit_memos_count,
4847 '164'||'^'||fnd_number.number_to_canonical(SUM(total_chargeback_value)) total_chargeback_value,
4848 '165'||'^'||fnd_number.number_to_canonical(SUM(total_chargeback_count)) total_chargeback_count,
4849 '166'||'^'||fnd_number.number_to_canonical(SUM(total_adjustments_value)) total_adjustments_value,
4850 '167'||'^'||fnd_number.number_to_canonical(SUM(total_adjustments_count)) total_adjustments_count,
4851 '168'||'^'||fnd_number.number_to_canonical(SUM(total_deposits_value)) total_deposits_value,
4852 '169'||'^'||fnd_number.number_to_canonical(SUM(total_deposits_count)) total_deposits_count
4853 FROM ( SELECT
4854 round(gl_currency_api.convert_amount(currency,
4855 l_limit_currency,sysdate,
4856 l_exchange_rate_type,
4857 (SUM(INV_INST_PMT_DAYS_SUM)
4858 /decode(SUM(SUM_APP_AMT),0,1,
4859 SUM(SUM_APP_AMT)))),2) avg_pmt_days, -- weighted Average Payment Days
4860 round(gl_currency_api.convert_amount(currency,
4861 l_limit_currency,sysdate,
4862 l_exchange_rate_type,
4863 (SUM(SUM_APP_AMT_DAYS_LATE)
4864 /decode(SUM(SUM_APP_AMT),0,1,SUM(SUM_APP_AMT)))),2) weight_avg_days_late, -- Weighted Average Days Late
4865 round(SUM(DAYS_CREDIT_GRANTED_SUM)/
4866 decode(SUM(TOTAL_INVOICES_VALUE),0,1,
4867 SUM(TOTAL_INVOICES_VALUE)),2) days_credit_granted, -- days credit granted
4868 SUM(NSF_STOP_PAYMENT_COUNT) nsf_payment_count, -- NSF/Stop Payment Count
4869 round(gl_currency_api.convert_amount(currency,
4870 l_limit_currency,sysdate,
4871 l_exchange_rate_type,
4872 SUM(NSF_STOP_PAYMENT_AMOUNT)),2) nsf_payment_amount, -- NSF/Stop Payment Amount
4873 round(gl_currency_api.convert_amount(currency,
4874 l_limit_currency,sysdate,
4875 l_exchange_rate_type,
4876 SUM(TOTAL_CREDIT_MEMOS_VALUE)),2) credit_memo_value, -- Credit memos value
4877 SUM(TOTAL_CREDIT_MEMOS_COUNT) credit_memo_count, -- Credit memos count
4878 round(gl_currency_api.convert_amount(currency,
4879 l_limit_currency,sysdate,
4880 l_exchange_rate_type,
4881 ((SUM(count_of_tot_inv_inst_paid)-
4882 SUM(count_of_inv_inst_paid_late))*100)/
4883 decode(SUM(count_of_tot_inv_inst_paid),0,1,
4884 SUM(count_of_tot_inv_inst_paid))),2) per_inv_paid_promptly, -- % of invoice paid promptly
4885 round(gl_currency_api.convert_amount(currency,
4886 l_limit_currency,sysdate,
4887 l_exchange_rate_type,
4888 ((SUM(count_of_inv_inst_paid_late)*100)/
4889 decode(SUM(count_of_tot_inv_inst_paid),0,1,
4890 SUM(count_of_tot_inv_inst_paid)))),2) per_inv_paid_late, -- % of invoice paid late
4891 round(gl_currency_api.convert_amount(currency,
4892 l_limit_currency,sysdate,
4893 l_exchange_rate_type,
4894 ((SUM(count_of_disc_inv_inst)*100)/
4895 decode(SUM(count_of_tot_inv_inst_paid),0,1,
4896 SUM(count_of_tot_inv_inst_paid)))),2) per_inv_with_discount, -- % of invoice with discount taken
4897 round(gl_currency_api.convert_amount(currency,
4898 l_limit_currency,sysdate,
4899 l_exchange_rate_type,
4900 SUM(INV_PAID_AMOUNT)),2) inv_paid_amount, -- invoices paid amount
4901 SUM(count_of_tot_inv_inst_paid) inv_paid_count, -- invoices paid count
4902 round(gl_currency_api.convert_amount(currency,
4903 l_limit_currency,sysdate,
4904 l_exchange_rate_type,
4905 SUM(TOTAL_EARNED_DISC_VALUE)),2) earned_disc_value, -- Earned Dscount Value
4906 SUM(TOTAL_EARNED_DISC_COUNT) earned_disc_count, -- Earned Dscount count
4907 round(gl_currency_api.convert_amount(currency,
4908 l_limit_currency,sysdate,
4909 l_exchange_rate_type,
4910 SUM(TOTAL_UNEARNED_DISC_VALUE)),2) unearned_disc_value, -- UnEarned Dscount Value
4911 SUM(TOTAL_UNEARNED_DISC_COUNT) unearned_disc_count, -- UnEarned Dscount count
4912 (round(gl_currency_api.convert_amount(currency,
4913 l_limit_currency,sysdate,
4914 l_exchange_rate_type,
4915 SUM(TOTAL_CASH_RECEIPTS_VALUE)),2) * -1) total_cash_receipts_value, -- see the comments above
4916 SUM(TOTAL_CASH_RECEIPTS_COUNT) total_cash_receipts_count,
4917 round(gl_currency_api.convert_amount(currency,
4918 l_limit_currency,sysdate,
4919 l_exchange_rate_type,
4920 SUM(TOTAL_INVOICES_VALUE)),2) total_invoices_value,
4921 SUM(TOTAL_INVOICES_COUNT) total_invoices_count,
4922 round(gl_currency_api.convert_amount(currency,
4923 l_limit_currency,sysdate,
4924 l_exchange_rate_type,
4925 SUM(TOTAL_BILLS_RECEIVABLES_VALUE)),2) total_bills_receivables_value,
4926 SUM(TOTAL_BILLS_RECEIVABLES_COUNT) TOTAL_BILLS_RECEIVABLES_count,
4927 round(gl_currency_api.convert_amount(currency,
4928 l_limit_currency,sysdate,
4929 l_exchange_rate_type,
4930 SUM(TOTAL_DEBIT_MEMOS_VALUE)),2) total_debit_memos_value,
4931 SUM(TOTAL_DEBIT_MEMOS_COUNT) TOTAL_debit_memos_count,
4932 round(gl_currency_api.convert_amount(currency,
4933 l_limit_currency,sysdate,
4934 l_exchange_rate_type,
4935 SUM(TOTAL_CHARGEBACK_VALUE)),2) total_chargeback_value,
4936 SUM(TOTAL_chargeback_COUNT) TOTAL_chargeback_count ,
4937 round(gl_currency_api.convert_amount(currency,
4938 l_limit_currency,sysdate,
4939 l_exchange_rate_type,
4940 SUM(TOTAL_ADJUSTMENTS_VALUE)),2) total_adjustments_value,
4941 SUM(TOTAL_adjustments_COUNT) TOTAL_adjustments_count ,
4942 round(gl_currency_api.convert_amount(currency,
4943 l_limit_currency,sysdate,
4944 l_exchange_rate_type,
4945 SUM(TOTAL_DEPOSITS_VALUE)),2) total_deposits_value,
4946 SUM(TOTAL_deposits_COUNT) TOTAL_deposits_count
4947 FROM AR_TRX_SUMMARY
4948 WHERE org_id = decode(l_global_exposure_flag,'Y', org_id, 'N',
4949 decode(p_org_id,null, org_id, p_org_id), null,
4950 decode(p_org_id,null, org_id, p_org_id))
4951 and CUST_ACCOUNT_ID = p_cust_account_id
4952 and CURRENCY IN ( SELECT CURRENCY FROM
4953 ar_cmgt_curr_usage_gt
4954 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
4955 and as_of_date >= ADD_MONTHS(sysdate,(-l_period))
4956 group by currency );
4957
4958 CURSOR c_site_summary IS
4959 SELECT '4'||'^'||fnd_number.number_to_canonical(SUM(avg_pmt_days)) avg_pmt_days,
4960 '5'||'^'||fnd_number.number_to_canonical(SUM(weight_avg_days_late)) weight_avg_days_late,
4961 '8'||'^'||fnd_number.number_to_canonical(SUM(days_credit_granted)) days_credit_granted,
4962 '13'||'^'||fnd_number.number_to_canonical(SUM(nsf_payment_count)) nsf_payment_count,
4963 '14'||'^'||fnd_number.number_to_canonical(SUM(nsf_payment_amount)) nsf_payment_amount,
4964 '17'||'^'||fnd_number.number_to_canonical(SUM(credit_memo_value)) credit_memo_value,
4965 '18'||'^'||fnd_number.number_to_canonical(SUM(credit_memo_count)) credit_memo_count,
4966 '21'||'^'||fnd_number.number_to_canonical(SUM(per_inv_paid_promptly)) per_inv_paid_promptly,
4967 '22'||'^'||fnd_number.number_to_canonical(SUM(per_inv_paid_late)) per_inv_paid_late,
4968 '23'||'^'||fnd_number.number_to_canonical(SUM(per_inv_with_discount)) per_inv_with_discount,
4969 '41'||'^'||fnd_number.number_to_canonical(SUM(inv_paid_amount)) inv_paid_amount,
4970 '42'||'^'||fnd_number.number_to_canonical(SUM(inv_paid_count)) inv_paid_count,
4971 '43'||'^'||fnd_number.number_to_canonical(SUM(earned_disc_value)) earned_disc_value,
4972 '44'||'^'||fnd_number.number_to_canonical(SUM(earned_disc_count)) earned_disc_count,
4973 '45'||'^'||fnd_number.number_to_canonical(SUM(unearned_disc_value)) unearned_disc_value,
4974 '46'||'^'||fnd_number.number_to_canonical(SUM(unearned_disc_count)) unearned_disc_count,
4975 '156'||'^'||fnd_number.number_to_canonical(SUM(total_cash_receipts_value)) total_cash_receipts_value,
4976 '157'||'^'||fnd_number.number_to_canonical(SUM(total_cash_receipts_count)) total_cash_receipts_count,
4977 '158'||'^'||fnd_number.number_to_canonical(SUM(total_invoices_value)) total_invoices_value,
4978 '159'||'^'||fnd_number.number_to_canonical(SUM(total_invoices_count)) total_invoices_count,
4979 '160'||'^'||fnd_number.number_to_canonical(SUM(total_bills_receivables_value)) total_bills_receivables_value,
4980 '161'||'^'||fnd_number.number_to_canonical(SUM(total_bills_receivables_count)) total_bills_receivables_count,
4981 '162'||'^'||fnd_number.number_to_canonical(SUM(total_debit_memos_value)) total_debit_memos_value,
4982 '163'||'^'||fnd_number.number_to_canonical(SUM(total_debit_memos_count)) total_debit_memos_count,
4983 '164'||'^'||fnd_number.number_to_canonical(SUM(total_chargeback_value)) total_chargeback_value,
4984 '165'||'^'||fnd_number.number_to_canonical(SUM(total_chargeback_count)) total_chargeback_count,
4985 '166'||'^'||fnd_number.number_to_canonical(SUM(total_adjustments_value)) total_adjustments_value,
4986 '167'||'^'||fnd_number.number_to_canonical(SUM(total_adjustments_count)) total_adjustments_count,
4987 '168'||'^'||fnd_number.number_to_canonical(SUM(total_deposits_value)) total_deposits_value,
4988 '169'||'^'||fnd_number.number_to_canonical(SUM(total_deposits_count)) total_deposits_count
4989 FROM ( SELECT
4990 round(gl_currency_api.convert_amount(currency,
4991 l_limit_currency,sysdate,
4992 l_exchange_rate_type,
4993 (SUM(INV_INST_PMT_DAYS_SUM)
4994 /decode(SUM(SUM_APP_AMT),0,1,
4995 SUM(SUM_APP_AMT)))),2) avg_pmt_days, -- weighted Average Payment Days
4996 round(gl_currency_api.convert_amount(currency,
4997 l_limit_currency,sysdate,
4998 l_exchange_rate_type,
4999 (SUM(SUM_APP_AMT_DAYS_LATE)
5000 /decode(SUM(SUM_APP_AMT),0,1,SUM(SUM_APP_AMT)))),2) weight_avg_days_late, -- Weighted Average Days Late
5001 round(SUM(DAYS_CREDIT_GRANTED_SUM)/
5002 decode(SUM(TOTAL_INVOICES_VALUE),0,1,
5003 SUM(TOTAL_INVOICES_VALUE)),2) days_credit_granted, -- days credit granted
5004 SUM(NSF_STOP_PAYMENT_COUNT) nsf_payment_count, -- NSF/Stop Payment Count
5005 round(gl_currency_api.convert_amount(currency,
5006 l_limit_currency,sysdate,
5007 l_exchange_rate_type,
5008 SUM(NSF_STOP_PAYMENT_AMOUNT)),2) nsf_payment_amount, -- NSF/Stop Payment Amount
5009 round(gl_currency_api.convert_amount(currency,
5010 l_limit_currency,sysdate,
5011 l_exchange_rate_type,
5012 SUM(TOTAL_CREDIT_MEMOS_VALUE)),2) credit_memo_value, -- Credit memos value
5013 SUM(TOTAL_CREDIT_MEMOS_COUNT) credit_memo_count, -- Credit memos count
5014 round(gl_currency_api.convert_amount(currency,
5015 l_limit_currency,sysdate,
5016 l_exchange_rate_type,
5017 ((SUM(count_of_tot_inv_inst_paid)-
5018 SUM(count_of_inv_inst_paid_late))*100)/
5019 decode(SUM(count_of_tot_inv_inst_paid),0,1,
5020 SUM(count_of_tot_inv_inst_paid))),2) per_inv_paid_promptly, -- % of invoice paid promptly
5021 round(gl_currency_api.convert_amount(currency,
5022 l_limit_currency,sysdate,
5023 l_exchange_rate_type,
5024 ((SUM(count_of_inv_inst_paid_late)*100)/
5025 decode(SUM(count_of_tot_inv_inst_paid),0,1,
5026 SUM(count_of_tot_inv_inst_paid)))),2) per_inv_paid_late, -- % of invoice paid late
5027 round(gl_currency_api.convert_amount(currency,
5028 l_limit_currency,sysdate,
5029 l_exchange_rate_type,
5030 ((SUM(count_of_disc_inv_inst)*100)/
5031 decode(SUM(count_of_tot_inv_inst_paid),0,1,
5032 SUM(count_of_tot_inv_inst_paid)))),2) per_inv_with_discount, -- % of invoice with discount taken
5033 round(gl_currency_api.convert_amount(currency,
5034 l_limit_currency,sysdate,
5035 l_exchange_rate_type,
5036 SUM(INV_PAID_AMOUNT)),2) inv_paid_amount, -- invoices paid amount
5037 SUM(count_of_tot_inv_inst_paid) inv_paid_count, -- invoices paid count
5038 round(gl_currency_api.convert_amount(currency,
5039 l_limit_currency,sysdate,
5040 l_exchange_rate_type,
5041 SUM(TOTAL_EARNED_DISC_VALUE)),2) earned_disc_value, -- Earned Dscount Value
5042 SUM(TOTAL_EARNED_DISC_COUNT) earned_disc_count, -- Earned Dscount count
5043 round(gl_currency_api.convert_amount(currency,
5044 l_limit_currency,sysdate,
5045 l_exchange_rate_type,
5046 SUM(TOTAL_UNEARNED_DISC_VALUE)),2) unearned_disc_value, -- UnEarned Dscount Value
5047 SUM(TOTAL_UNEARNED_DISC_COUNT) unearned_disc_count, -- UnEarned Dscount count
5048 (round(gl_currency_api.convert_amount(currency,
5049 l_limit_currency,sysdate,
5050 l_exchange_rate_type,
5051 SUM(TOTAL_CASH_RECEIPTS_VALUE)),2) * -1) total_cash_receipts_value, -- see the comments above
5052 SUM(TOTAL_CASH_RECEIPTS_COUNT) total_cash_receipts_count,
5053 round(gl_currency_api.convert_amount(currency,
5054 l_limit_currency,sysdate,
5055 l_exchange_rate_type,
5056 SUM(TOTAL_INVOICES_VALUE)),2) total_invoices_value,
5057 SUM(TOTAL_INVOICES_COUNT) total_invoices_count,
5058 round(gl_currency_api.convert_amount(currency,
5059 l_limit_currency,sysdate,
5060 l_exchange_rate_type,
5061 SUM(TOTAL_BILLS_RECEIVABLES_VALUE)),2) total_bills_receivables_value,
5062 SUM(TOTAL_BILLS_RECEIVABLES_COUNT) TOTAL_BILLS_RECEIVABLES_count,
5063 round(gl_currency_api.convert_amount(currency,
5064 l_limit_currency,sysdate,
5065 l_exchange_rate_type,
5066 SUM(TOTAL_DEBIT_MEMOS_VALUE)),2) total_debit_memos_value,
5067 SUM(TOTAL_DEBIT_MEMOS_COUNT) TOTAL_debit_memos_count,
5068 round(gl_currency_api.convert_amount(currency,
5069 l_limit_currency,sysdate,
5070 l_exchange_rate_type,
5071 SUM(TOTAL_CHARGEBACK_VALUE)),2) total_chargeback_value,
5072 SUM(TOTAL_chargeback_COUNT) TOTAL_chargeback_count ,
5073 round(gl_currency_api.convert_amount(currency,
5074 l_limit_currency,sysdate,
5075 l_exchange_rate_type,
5076 SUM(TOTAL_ADJUSTMENTS_VALUE)),2) total_adjustments_value,
5077 SUM(TOTAL_adjustments_COUNT) TOTAL_adjustments_count ,
5078 round(gl_currency_api.convert_amount(currency,
5079 l_limit_currency,sysdate,
5080 l_exchange_rate_type,
5081 SUM(TOTAL_DEPOSITS_VALUE)),2) total_deposits_value,
5082 SUM(TOTAL_deposits_COUNT) TOTAL_deposits_count
5083 FROM AR_TRX_SUMMARY
5084 WHERE CUST_ACCOUNT_ID = p_cust_account_id
5085 and CURRENCY IN ( SELECT a.CURRENCY FROM
5086 ar_cmgt_curr_usage_gt a
5087 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5088 and as_of_date >= ADD_MONTHS(sysdate,(-l_period))
5089 and site_use_id = p_cust_acct_site_id
5090 group by currency );
5091
5092
5093
5094
5095 /*********** CAUTIONS **********************************************
5096 -- if you are adding/removing an column in this cursor please
5097 -- update the bal_summary_rec_col_count varibale with proper number.
5098 ********************************************************************/
5099 CURSOR c_party_bal_summary IS
5100 SELECT '34'||'^'||fnd_number.number_to_canonical(SUM(current_receivable_balance)) current_receivable_balance,
5101 '9'||'^'|| fnd_number.number_to_canonical(SUM(unapplied_cash_amount)) unapplied_cash_amount, -- unapplied case amount
5102 '10'||'^'||fnd_number.number_to_canonical(SUM(unapplied_cash_count)) unapplied_cash_count, -- unapplied cash count
5103 '48'||'^'||fnd_number.number_to_canonical(SUM(past_due_inv_value)) past_due_inv_value,
5104 '49'||'^'||fnd_number.number_to_canonical(SUM(past_due_inv_inst_count)) past_due_inv_inst_count,
5105 '50'||'^'||fnd_number.number_to_canonical(SUM(inv_amt_in_dispute)) inv_amt_in_dispute,
5106 '51'||'^'||fnd_number.number_to_canonical(SUM(disputed_inv_count)) disputed_inv_count,
5107 '56'||'^'||fnd_number.number_to_canonical(SUM(pending_adj_value)) pending_adj_value,
5108 '58'||'^'||fnd_number.number_to_canonical(SUM(total_receipts_at_risk_value)) total_receipts_at_risk_value,
5109 '170'||'^'||fnd_number.number_to_canonical(SUM(op_invoices_value)) op_invoices_value,
5110 '171'||'^'||fnd_number.number_to_canonical(SUM(op_invoices_count)) op_invoices_count,
5111 '172'||'^'||fnd_number.number_to_canonical(SUM(op_debit_memos_value)) op_debit_memos_value,
5112 '173'||'^'||fnd_number.number_to_canonical(SUM(op_debit_memos_count)) op_debit_memos_count,
5113 '174'||'^'||fnd_number.number_to_canonical(SUM(op_deposits_value)) op_deposits_value,
5114 '175'||'^'||fnd_number.number_to_canonical(SUM(op_deposits_count)) op_deposits_count,
5115 '176'||'^'||fnd_number.number_to_canonical(SUM(op_bills_receivables_value)) op_bills_receivables_value,
5116 '177'||'^'||fnd_number.number_to_canonical(SUM(op_bills_receivables_count)) op_bills_receivables_count,
5117 '178'||'^'||fnd_number.number_to_canonical(SUM(op_chargeback_value)) op_chargeback_value,
5118 '179'||'^'||fnd_number.number_to_canonical(SUM(op_chargeback_count)) op_chargeback_count,
5119 '180'||'^'||fnd_number.number_to_canonical(SUM(op_credit_memos_value)) op_credit_memos_value,
5120 '181'||'^'||fnd_number.number_to_canonical(SUM(op_credit_memos_count)) op_credit_memos_count,
5121 '209'||'^'||fnd_number.number_to_canonical(SUM(current_invoice_value)) current_invoice_value,
5122 '210'||'^'||fnd_number.number_to_canonical(SUM(current_invoice_count)) current_invoice_count
5123 FROM (
5124 SELECT
5125 gl_currency_api.convert_amount(currency,
5126 l_limit_currency,sysdate,
5127 l_exchange_rate_type,
5128 SUM((nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5129 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5130 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0) +
5131 nvl(UNRESOLVED_CASH_VALUE,0) ))) current_receivable_balance, -- Current Receivables Balance (Opening balance)
5132 gl_currency_api.convert_amount(currency,
5133 l_limit_currency,sysdate,
5134 l_exchange_rate_type,
5135 SUM(UNRESOLVED_CASH_VALUE)) unapplied_cash_amount, -- unapplied case amount
5136 SUM(UNRESOLVED_CASH_COUNT) unapplied_cash_count, -- unapplied cash count
5137 gl_currency_api.convert_amount(currency,
5138 l_limit_currency,sysdate,
5139 l_exchange_rate_type,
5140 SUM(past_due_inv_value)) past_due_inv_value,
5141 SUM(past_due_inv_inst_count) past_due_inv_inst_count,
5142 gl_currency_api.convert_amount(currency,
5143 l_limit_currency,sysdate,
5144 l_exchange_rate_type,
5145 SUM(inv_amt_in_dispute)) inv_amt_in_dispute,
5146 SUM(disputed_inv_count) disputed_inv_count,
5147 gl_currency_api.convert_amount(currency,
5148 l_limit_currency,sysdate,
5149 l_exchange_rate_type,
5150 SUM(pending_adj_value)) pending_adj_value,
5151 gl_currency_api.convert_amount(currency,
5152 l_limit_currency,sysdate,
5153 l_exchange_rate_type,
5154 SUM(receipts_at_risk_value)) total_receipts_at_risk_value,
5155 gl_currency_api.convert_amount(currency,
5156 l_limit_currency,sysdate,
5157 l_exchange_rate_type,
5158 SUM(op_invoices_value)) op_invoices_value,
5159 SUM(op_invoices_count) op_invoices_count,
5160 gl_currency_api.convert_amount(currency,
5161 l_limit_currency,sysdate,
5162 l_exchange_rate_type,
5163 SUM(op_debit_memos_value)) op_debit_memos_value,
5164 SUM(op_debit_memos_count) op_debit_memos_count,
5165 gl_currency_api.convert_amount(currency,
5166 l_limit_currency,sysdate,
5167 l_exchange_rate_type,
5168 SUM(op_deposits_value)) op_deposits_value,
5169 SUM(op_deposits_count) op_deposits_count,
5170 gl_currency_api.convert_amount(currency,
5171 l_limit_currency,sysdate,
5172 l_exchange_rate_type,
5173 SUM(op_bills_receivables_value)) op_bills_receivables_value,
5174 SUM(op_bills_receivables_count) op_bills_receivables_count,
5175 gl_currency_api.convert_amount(currency,
5176 l_limit_currency,sysdate,
5177 l_exchange_rate_type,
5178 SUM(op_chargeback_value)) op_chargeback_value,
5179 SUM(op_chargeback_count) op_chargeback_count,
5180 gl_currency_api.convert_amount(currency,
5181 l_limit_currency,sysdate,
5182 l_exchange_rate_type,
5183 SUM(op_credit_memos_value)) op_credit_memos_value,
5184 SUM(op_credit_memos_count) op_credit_memos_count,
5185 gl_currency_api.convert_amount(currency,
5186 l_limit_currency,sysdate,
5187 l_exchange_rate_type,
5188 SUM(nvl(op_invoices_value,0) - nvl(past_due_inv_value,0))) current_invoice_value,
5189 SUM(nvl(op_invoices_count,0) - nvl(past_due_inv_inst_count,0)) current_invoice_count
5190 FROM AR_TRX_BAL_SUMMARY
5191 WHERE cust_account_id in (select cust_account_id
5192 FROM hz_cust_accounts
5193 WHERE party_id in
5194 ( SELECT child_id
5195 from hz_hierarchy_nodes
5196 where parent_object_type = 'ORGANIZATION'
5197 and parent_table_name = 'HZ_PARTIES'
5198 and child_object_type = 'ORGANIZATION'
5199 and parent_id = p_party_id
5200 and effective_start_date <= sysdate
5201 and effective_end_date >= sysdate
5202 and hierarchy_type = FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
5203 and g_source_name <> 'LNS'
5204 union select p_party_id from dual
5205 UNION
5206 select hz_party_id
5207 from LNS_LOAN_PARTICIPANTS_V
5208 where loan_id = g_source_id
5209 and participant_type_code = 'COBORROWER'
5210 and g_source_name = 'LNS'
5211 and (end_date_active is null OR
5212 (sysdate between start_date_active and end_date_active)
5213 )
5214 ))
5215 and CURRENCY IN ( SELECT CURRENCY FROM
5216 ar_cmgt_curr_usage_gt
5217 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5218 group by currency);
5219
5220
5221 CURSOR c_account_bal_summary IS
5222 SELECT '34'||'^'||fnd_number.number_to_canonical(SUM(current_receivable_balance)) current_receivable_balance,
5223 '9'||'^'|| fnd_number.number_to_canonical(SUM(unapplied_cash_amount)) unapplied_cash_amount, -- unapplied case amount
5224 '10'||'^'||fnd_number.number_to_canonical(SUM(unapplied_cash_count)) unapplied_cash_count, -- unapplied cash count
5225 '48'||'^'||fnd_number.number_to_canonical(SUM(past_due_inv_value)) past_due_inv_value,
5226 '49'||'^'||fnd_number.number_to_canonical(SUM(past_due_inv_inst_count)) past_due_inv_inst_count,
5227 '50'||'^'||fnd_number.number_to_canonical(SUM(inv_amt_in_dispute)) inv_amt_in_dispute,
5228 '51'||'^'||fnd_number.number_to_canonical(SUM(disputed_inv_count)) disputed_inv_count,
5229 '56'||'^'||fnd_number.number_to_canonical(SUM(pending_adj_value)) pending_adj_value,
5230 '58'||'^'||fnd_number.number_to_canonical(SUM(total_receipts_at_risk_value)) total_receipts_at_risk_value,
5231 '170'||'^'||fnd_number.number_to_canonical(SUM(op_invoices_value)) op_invoices_value,
5232 '171'||'^'||fnd_number.number_to_canonical(SUM(op_invoices_count)) op_invoices_count,
5233 '172'||'^'||fnd_number.number_to_canonical(SUM(op_debit_memos_value)) op_debit_memos_value,
5234 '173'||'^'||fnd_number.number_to_canonical(SUM(op_debit_memos_count)) op_debit_memos_count,
5235 '174'||'^'||fnd_number.number_to_canonical(SUM(op_deposits_value)) op_deposits_value,
5236 '175'||'^'||fnd_number.number_to_canonical(SUM(op_deposits_count)) op_deposits_count,
5237 '176'||'^'||fnd_number.number_to_canonical(SUM(op_bills_receivables_value)) op_bills_receivables_value,
5238 '177'||'^'||fnd_number.number_to_canonical(SUM(op_bills_receivables_count)) op_bills_receivables_count,
5239 '178'||'^'||fnd_number.number_to_canonical(SUM(op_chargeback_value)) op_chargeback_value,
5240 '179'||'^'||fnd_number.number_to_canonical(SUM(op_chargeback_count)) op_chargeback_count,
5241 '180'||'^'||fnd_number.number_to_canonical(SUM(op_credit_memos_value)) op_credit_memos_value,
5242 '181'||'^'||fnd_number.number_to_canonical(SUM(op_credit_memos_count)) op_credit_memos_count,
5243 '209'||'^'||fnd_number.number_to_canonical(SUM(current_invoice_value)) current_invoice_value,
5244 '210'||'^'||fnd_number.number_to_canonical(SUM(current_invoice_count)) current_invoice_count
5245 FROM (
5246 SELECT
5247 gl_currency_api.convert_amount(currency,
5248 l_limit_currency,sysdate,
5249 l_exchange_rate_type,
5250 SUM((nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5251 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5252 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0) +
5253 nvl(UNRESOLVED_CASH_VALUE,0) ))) current_receivable_balance, -- Current Receivables Balance (Opening balance)
5254 gl_currency_api.convert_amount(currency,
5255 l_limit_currency,sysdate,
5256 l_exchange_rate_type,
5257 SUM(UNRESOLVED_CASH_VALUE)) unapplied_cash_amount, -- unapplied case amount
5258 SUM(UNRESOLVED_CASH_COUNT) unapplied_cash_count, -- unapplied cash count
5259 gl_currency_api.convert_amount(currency,
5260 l_limit_currency,sysdate,
5261 l_exchange_rate_type,
5262 SUM(past_due_inv_value)) past_due_inv_value,
5263 SUM(past_due_inv_inst_count) past_due_inv_inst_count,
5264 gl_currency_api.convert_amount(currency,
5265 l_limit_currency,sysdate,
5266 l_exchange_rate_type,
5267 SUM(inv_amt_in_dispute)) inv_amt_in_dispute,
5268 SUM(disputed_inv_count) disputed_inv_count,
5269 gl_currency_api.convert_amount(currency,
5270 l_limit_currency,sysdate,
5271 l_exchange_rate_type,
5272 SUM(pending_adj_value)) pending_adj_value,
5273 gl_currency_api.convert_amount(currency,
5274 l_limit_currency,sysdate,
5275 l_exchange_rate_type,
5276 SUM(receipts_at_risk_value)) total_receipts_at_risk_value,
5277 gl_currency_api.convert_amount(currency,
5278 l_limit_currency,sysdate,
5279 l_exchange_rate_type,
5280 SUM(op_invoices_value)) op_invoices_value,
5281 SUM(op_invoices_count) op_invoices_count,
5282 gl_currency_api.convert_amount(currency,
5283 l_limit_currency,sysdate,
5284 l_exchange_rate_type,
5285 SUM(op_debit_memos_value)) op_debit_memos_value,
5286 SUM(op_debit_memos_count) op_debit_memos_count,
5287 gl_currency_api.convert_amount(currency,
5288 l_limit_currency,sysdate,
5289 l_exchange_rate_type,
5290 SUM(op_deposits_value)) op_deposits_value,
5291 SUM(op_deposits_count) op_deposits_count,
5292 gl_currency_api.convert_amount(currency,
5293 l_limit_currency,sysdate,
5294 l_exchange_rate_type,
5295 SUM(op_bills_receivables_value)) op_bills_receivables_value,
5296 SUM(op_bills_receivables_count) op_bills_receivables_count,
5297 gl_currency_api.convert_amount(currency,
5298 l_limit_currency,sysdate,
5299 l_exchange_rate_type,
5300 SUM(op_chargeback_value)) op_chargeback_value,
5301 SUM(op_chargeback_count) op_chargeback_count,
5302 gl_currency_api.convert_amount(currency,
5303 l_limit_currency,sysdate,
5304 l_exchange_rate_type,
5305 SUM(op_credit_memos_value)) op_credit_memos_value,
5306 SUM(op_credit_memos_count) op_credit_memos_count,
5307 gl_currency_api.convert_amount(currency,
5308 l_limit_currency,sysdate,
5309 l_exchange_rate_type,
5310 SUM(nvl(op_invoices_value,0) - nvl(past_due_inv_value,0))) current_invoice_value,
5311 SUM(nvl(op_invoices_count,0) - nvl(past_due_inv_inst_count,0)) current_invoice_count
5312 FROM AR_TRX_BAL_SUMMARY
5313 WHERE org_id = decode(l_global_exposure_flag,'Y', org_id, 'N',
5314 decode(p_org_id,null, org_id, p_org_id), null,
5315 decode(p_org_id,null, org_id, p_org_id))
5316 and cust_account_id = p_cust_account_id
5317 and CURRENCY IN ( SELECT CURRENCY FROM
5318 ar_cmgt_curr_usage_gt
5319 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5320 /* ( SELECT * FROM
5321 TABLE(CAST(l_curr_array_list AS curr_array_type))) */
5322 --and site_use_id = decode(l_analysis_level,'S',p_cust_acct_site_id,site_use_id)
5323 group by currency);
5324
5325 CURSOR c_site_bal_summary IS
5326 SELECT '34'||'^'||fnd_number.number_to_canonical(SUM(current_receivable_balance)) current_receivable_balance,
5327 '9'||'^'|| fnd_number.number_to_canonical(SUM(unapplied_cash_amount)) unapplied_cash_amount, -- unapplied case amount
5328 '10'||'^'||fnd_number.number_to_canonical(SUM(unapplied_cash_count)) unapplied_cash_count, -- unapplied cash count
5329 '48'||'^'||fnd_number.number_to_canonical(SUM(past_due_inv_value)) past_due_inv_value,
5330 '49'||'^'||fnd_number.number_to_canonical(SUM(past_due_inv_inst_count)) past_due_inv_inst_count,
5331 '50'||'^'||fnd_number.number_to_canonical(SUM(inv_amt_in_dispute)) inv_amt_in_dispute,
5332 '51'||'^'||fnd_number.number_to_canonical(SUM(disputed_inv_count)) disputed_inv_count,
5333 '56'||'^'||fnd_number.number_to_canonical(SUM(pending_adj_value)) pending_adj_value,
5334 '58'||'^'||fnd_number.number_to_canonical(SUM(total_receipts_at_risk_value)) total_receipts_at_risk_value,
5335 '170'||'^'||fnd_number.number_to_canonical(SUM(op_invoices_value)) op_invoices_value,
5336 '171'||'^'||fnd_number.number_to_canonical(SUM(op_invoices_count)) op_invoices_count,
5337 '172'||'^'||fnd_number.number_to_canonical(SUM(op_debit_memos_value)) op_debit_memos_value,
5338 '173'||'^'||fnd_number.number_to_canonical(SUM(op_debit_memos_count)) op_debit_memos_count,
5339 '174'||'^'||fnd_number.number_to_canonical(SUM(op_deposits_value)) op_deposits_value,
5340 '175'||'^'||fnd_number.number_to_canonical(SUM(op_deposits_count)) op_deposits_count,
5341 '176'||'^'||fnd_number.number_to_canonical(SUM(op_bills_receivables_value)) op_bills_receivables_value,
5342 '177'||'^'||fnd_number.number_to_canonical(SUM(op_bills_receivables_count)) op_bills_receivables_count,
5343 '178'||'^'||fnd_number.number_to_canonical(SUM(op_chargeback_value)) op_chargeback_value,
5344 '179'||'^'||fnd_number.number_to_canonical(SUM(op_chargeback_count)) op_chargeback_count,
5345 '180'||'^'||fnd_number.number_to_canonical(SUM(op_credit_memos_value)) op_credit_memos_value,
5346 '181'||'^'||fnd_number.number_to_canonical(SUM(op_credit_memos_count)) op_credit_memos_count,
5347 '209'||'^'||fnd_number.number_to_canonical(SUM(current_invoice_value)) current_invoice_value,
5348 '210'||'^'||fnd_number.number_to_canonical(SUM(current_invoice_count)) current_invoice_count
5349 FROM (
5350 SELECT
5351 gl_currency_api.convert_amount(currency,
5352 l_limit_currency,sysdate,
5353 l_exchange_rate_type,
5354 SUM((nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5355 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5356 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0) +
5357 nvl(UNRESOLVED_CASH_VALUE,0) ))) current_receivable_balance, -- Current Receivables Balance (Opening balance)
5358 gl_currency_api.convert_amount(currency,
5359 l_limit_currency,sysdate,
5360 l_exchange_rate_type,
5361 SUM(UNRESOLVED_CASH_VALUE)) unapplied_cash_amount, -- unapplied case amount
5362 SUM(UNRESOLVED_CASH_COUNT) unapplied_cash_count, -- unapplied cash count
5363 gl_currency_api.convert_amount(currency,
5364 l_limit_currency,sysdate,
5365 l_exchange_rate_type,
5366 SUM(past_due_inv_value)) past_due_inv_value,
5367 SUM(past_due_inv_inst_count) past_due_inv_inst_count,
5368 gl_currency_api.convert_amount(currency,
5369 l_limit_currency,sysdate,
5370 l_exchange_rate_type,
5371 SUM(inv_amt_in_dispute)) inv_amt_in_dispute,
5372 SUM(disputed_inv_count) disputed_inv_count,
5373 gl_currency_api.convert_amount(currency,
5374 l_limit_currency,sysdate,
5375 l_exchange_rate_type,
5376 SUM(pending_adj_value)) pending_adj_value,
5377 gl_currency_api.convert_amount(currency,
5378 l_limit_currency,sysdate,
5379 l_exchange_rate_type,
5380 SUM(receipts_at_risk_value)) total_receipts_at_risk_value,
5381 gl_currency_api.convert_amount(currency,
5382 l_limit_currency,sysdate,
5383 l_exchange_rate_type,
5384 SUM(op_invoices_value)) op_invoices_value,
5385 SUM(op_invoices_count) op_invoices_count,
5386 gl_currency_api.convert_amount(currency,
5387 l_limit_currency,sysdate,
5388 l_exchange_rate_type,
5389 SUM(op_debit_memos_value)) op_debit_memos_value,
5390 SUM(op_debit_memos_count) op_debit_memos_count,
5391 gl_currency_api.convert_amount(currency,
5392 l_limit_currency,sysdate,
5393 l_exchange_rate_type,
5394 SUM(op_deposits_value)) op_deposits_value,
5395 SUM(op_deposits_count) op_deposits_count,
5396 gl_currency_api.convert_amount(currency,
5397 l_limit_currency,sysdate,
5398 l_exchange_rate_type,
5399 SUM(op_bills_receivables_value)) op_bills_receivables_value,
5400 SUM(op_bills_receivables_count) op_bills_receivables_count,
5401 gl_currency_api.convert_amount(currency,
5402 l_limit_currency,sysdate,
5403 l_exchange_rate_type,
5404 SUM(op_chargeback_value)) op_chargeback_value,
5405 SUM(op_chargeback_count) op_chargeback_count,
5406 gl_currency_api.convert_amount(currency,
5407 l_limit_currency,sysdate,
5408 l_exchange_rate_type,
5409 SUM(op_credit_memos_value)) op_credit_memos_value,
5410 SUM(op_credit_memos_count) op_credit_memos_count,
5411 gl_currency_api.convert_amount(currency,
5412 l_limit_currency,sysdate,
5413 l_exchange_rate_type,
5414 SUM(nvl(op_invoices_value,0) - nvl(past_due_inv_value,0))) current_invoice_value,
5415 SUM(nvl(op_invoices_count,0) - nvl(past_due_inv_inst_count,0)) current_invoice_count
5416 FROM AR_TRX_BAL_SUMMARY
5417 WHERE cust_account_id = p_cust_account_id
5418 and CURRENCY IN ( SELECT CURRENCY FROM
5419 ar_cmgt_curr_usage_gt
5420 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5421 /* ( SELECT * FROM
5422 TABLE(CAST(l_curr_array_list AS curr_array_type))) */
5423 and site_use_id = p_cust_acct_site_id
5424 group by currency);
5425
5426 CURSOR c_party_numerator_dso IS
5427 SELECT SUM(dso) dso,
5428 SUM(delinquent_dso) delinquent_dso
5429 FROM (
5430 SELECT gl_currency_api.convert_amount(currency,
5431 l_limit_currency,sysdate,
5432 l_exchange_rate_type,
5433 (SUM(nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5434 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5435 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0)
5436 )*l_certified_dso_days)) dso,
5437 gl_currency_api.convert_amount(currency,
5438 l_limit_currency,sysdate,
5439 l_exchange_rate_type,
5440 (SUM(nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5441 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5442 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0)
5443 - nvl(BEST_CURRENT_RECEIVABLES,0))*l_certified_dso_days)) delinquent_dso
5444 FROM ar_trx_bal_summary
5445 WHERE cust_account_id in (select cust_account_id
5446 FROM hz_cust_accounts
5447 WHERE party_id in
5448 ( SELECT child_id
5449 from hz_hierarchy_nodes
5450 where parent_object_type = 'ORGANIZATION'
5451 and parent_table_name = 'HZ_PARTIES'
5452 and child_object_type = 'ORGANIZATION'
5453 and parent_id = p_party_id
5454 and effective_start_date <= sysdate
5455 and effective_end_date >= sysdate
5456 and hierarchy_type = FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
5457 and g_source_name <> 'LNS'
5458 union select p_party_id from dual
5459 UNION
5460 select hz_party_id
5461 from LNS_LOAN_PARTICIPANTS_V
5462 where loan_id = g_source_id
5463 and participant_type_code = 'COBORROWER'
5464 and g_source_name = 'LNS'
5465 and (end_date_active is null OR
5466 (sysdate between start_date_active and end_date_active)
5467 )
5468 ))
5469 and CURRENCY IN ( SELECT CURRENCY FROM
5470 ar_cmgt_curr_usage_gt
5471 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5472 group by currency);
5473
5474 CURSOR c_account_numerator_dso IS
5475 SELECT SUM(dso) dso,
5476 SUM(delinquent_dso) delinquent_dso
5477 FROM (
5478 SELECT gl_currency_api.convert_amount (currency,
5479 l_limit_currency,sysdate,
5480 l_exchange_rate_type,
5481 (SUM(nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5482 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5483 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0)
5484 )*l_certified_dso_days)) dso,
5485 gl_currency_api.convert_amount(currency,
5486 l_limit_currency,sysdate,
5487 l_exchange_rate_type,
5488 (SUM(nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5489 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5490 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0)
5491 - nvl(BEST_CURRENT_RECEIVABLES,0))*l_certified_dso_days)) delinquent_dso
5492 FROM ar_trx_bal_summary
5493 WHERE cust_account_id = p_cust_account_id
5494 and org_id = decode(l_global_exposure_flag,'Y', org_id, 'N',
5495 decode(p_org_id,null, org_id, p_org_id), null,
5496 decode(p_org_id,null, org_id, p_org_id))
5497 and CURRENCY IN ( SELECT CURRENCY FROM
5498 ar_cmgt_curr_usage_gt
5499 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5500 group by currency);
5501
5502 CURSOR c_site_numerator_dso IS
5503 SELECT SUM(dso) dso,
5504 SUM(delinquent_dso) delinquent_dso
5505 FROM (
5506 SELECT gl_currency_api.convert_amount(currency,
5507 l_limit_currency,sysdate,
5508 l_exchange_rate_type,
5509 (SUM(nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5510 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5511 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0) +
5512 nvl(UNRESOLVED_CASH_VALUE,0) )*l_certified_dso_days)) dso,
5513 gl_currency_api.convert_amount(currency,
5514 l_limit_currency,sysdate,
5515 l_exchange_rate_type,
5516 (SUM(nvl(OP_INVOICES_VALUE,0) + nvl(OP_DEBIT_MEMOS_VALUE,0) +
5517 nvl(OP_DEPOSITS_VALUE,0) + nvl(OP_BILLS_RECEIVABLES_VALUE,0) +
5518 nvl(OP_CHARGEBACK_VALUE,0) + nvl(OP_CREDIT_MEMOS_VALUE,0)
5519 - nvl(BEST_CURRENT_RECEIVABLES,0))*l_certified_dso_days)) delinquent_dso
5520 FROM ar_trx_bal_summary
5521 WHERE cust_account_id = p_cust_account_id
5522 and site_use_id = p_cust_acct_site_id
5523 and CURRENCY IN ( SELECT CURRENCY FROM
5524 ar_cmgt_curr_usage_gt
5525 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5526 group by currency);
5527
5528 CURSOR c_party_deno_dso IS
5529 SELECT SUM(dso) dso,
5530 SUM(delinquent_dso) delinquent_dso
5531 FROM (
5532 SELECT gl_currency_api.convert_amount(currency,
5533 l_limit_currency,sysdate,
5534 l_exchange_rate_type,
5535 (SUM(nvl(TOTAL_INVOICES_VALUE,0) + nvl(TOTAL_DEBIT_MEMOS_VALUE,0) +
5536 nvl(TOTAL_DEPOSITS_VALUE,0) + nvl(TOTAL_BILLS_RECEIVABLES_VALUE,0) +
5537 nvl(TOTAL_CHARGEBACK_VALUE,0) + nvl(TOTAL_CREDIT_MEMOS_VALUE,0) +
5538 nvl(TOTAL_ADJUSTMENTS_VALUE,0))
5539 )) dso,
5540 gl_currency_api.convert_amount(currency,
5541 l_limit_currency,sysdate,
5542 l_exchange_rate_type,
5543 ((SUM(nvl(TOTAL_INVOICES_VALUE,0) + nvl(TOTAL_DEBIT_MEMOS_VALUE,0) +
5544 nvl(TOTAL_DEPOSITS_VALUE,0) + nvl(TOTAL_BILLS_RECEIVABLES_VALUE,0) +
5545 nvl(TOTAL_CHARGEBACK_VALUE,0) + nvl(TOTAL_CREDIT_MEMOS_VALUE,0) +
5546 nvl(TOTAL_ADJUSTMENTS_VALUE,0)
5547 )))) delinquent_dso
5548 FROM ar_trx_summary
5549 WHERE cust_account_id in (select cust_account_id
5550 FROM hz_cust_accounts
5551 WHERE party_id in
5552 ( SELECT child_id
5553 from hz_hierarchy_nodes
5554 where parent_object_type = 'ORGANIZATION'
5555 and parent_table_name = 'HZ_PARTIES'
5556 and child_object_type = 'ORGANIZATION'
5557 and parent_id = p_party_id
5558 and effective_start_date <= sysdate
5559 and effective_end_date >= sysdate
5560 and hierarchy_type = FND_PROFILE.VALUE('AR_CMGT_HIERARCHY_TYPE')
5561 and g_source_name <> 'LNS'
5562 union select p_party_id from dual
5563 UNION
5564 select hz_party_id
5565 from LNS_LOAN_PARTICIPANTS_V
5566 where loan_id = g_source_id
5567 and participant_type_code = 'COBORROWER'
5568 and g_source_name = 'LNS'
5569 and (end_date_active is null OR
5570 (sysdate between start_date_active and end_date_active)
5571 )
5572 ))
5573 and CURRENCY IN ( SELECT CURRENCY FROM
5574 ar_cmgt_curr_usage_gt
5575 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5576 and as_of_date >= (sysdate -l_certified_dso_days)
5577 group by currency);
5578
5579 CURSOR c_account_deno_dso IS
5580 SELECT SUM(dso) dso,
5581 SUM(delinquent_dso) delinquent_dso
5582 FROM (
5583 SELECT gl_currency_api.convert_amount(currency,
5584 l_limit_currency,sysdate,
5585 l_exchange_rate_type,
5586 (SUM(nvl(TOTAL_INVOICES_VALUE,0) + nvl(TOTAL_DEBIT_MEMOS_VALUE,0) +
5587 nvl(TOTAL_DEPOSITS_VALUE,0) + nvl(TOTAL_BILLS_RECEIVABLES_VALUE,0) +
5588 nvl(TOTAL_CHARGEBACK_VALUE,0) + nvl(TOTAL_CREDIT_MEMOS_VALUE,0) +
5589 nvl(TOTAL_ADJUSTMENTS_VALUE,0))
5590 )) dso,
5591 gl_currency_api.convert_amount(currency,
5592 l_limit_currency,sysdate,
5593 l_exchange_rate_type,
5594 (SUM(nvl(TOTAL_INVOICES_VALUE,0) + nvl(TOTAL_DEBIT_MEMOS_VALUE,0) +
5595 nvl(TOTAL_DEPOSITS_VALUE,0) + nvl(TOTAL_BILLS_RECEIVABLES_VALUE,0) +
5596 nvl(TOTAL_CHARGEBACK_VALUE,0) + nvl(TOTAL_CREDIT_MEMOS_VALUE,0) +
5597 nvl(TOTAL_ADJUSTMENTS_VALUE,0)
5598 ))) delinquent_dso
5599 FROM ar_trx_summary
5600 WHERE cust_account_id = p_cust_account_id
5601 and CURRENCY IN ( SELECT CURRENCY FROM
5602 ar_cmgt_curr_usage_gt
5603 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5604 and org_id = decode(l_global_exposure_flag,'Y', org_id, 'N',
5605 decode(p_org_id,null, org_id, p_org_id), null,
5606 decode(p_org_id,null, org_id, p_org_id))
5607 and as_of_date >= (sysdate -l_certified_dso_days)
5608 group by currency);
5609
5610 CURSOR c_site_deno_dso IS
5611 SELECT SUM(dso) dso,
5612 SUM(delinquent_dso) delinquent_dso
5613 FROM (
5614 SELECT gl_currency_api.convert_amount(currency,
5615 l_limit_currency,sysdate,
5616 l_exchange_rate_type,
5617 (SUM(nvl(TOTAL_INVOICES_VALUE,0) + nvl(TOTAL_DEBIT_MEMOS_VALUE,0) +
5618 nvl(TOTAL_DEPOSITS_VALUE,0) + nvl(TOTAL_BILLS_RECEIVABLES_VALUE,0) +
5619 nvl(TOTAL_CHARGEBACK_VALUE,0) + nvl(TOTAL_CREDIT_MEMOS_VALUE,0) +
5620 nvl(TOTAL_ADJUSTMENTS_VALUE,0))
5621 )) dso,
5622 gl_currency_api.convert_amount(currency,
5623 l_limit_currency,sysdate,
5624 l_exchange_rate_type,
5625 (SUM(nvl(TOTAL_INVOICES_VALUE,0) + nvl(TOTAL_DEBIT_MEMOS_VALUE,0) +
5626 nvl(TOTAL_DEPOSITS_VALUE,0) + nvl(TOTAL_BILLS_RECEIVABLES_VALUE,0) +
5627 nvl(TOTAL_CHARGEBACK_VALUE,0) + nvl(TOTAL_CREDIT_MEMOS_VALUE,0) +
5628 nvl(TOTAL_ADJUSTMENTS_VALUE,0)
5629 ))) delinquent_dso
5630 FROM ar_trx_summary
5631 WHERE cust_account_id = p_cust_account_id
5632 and CURRENCY IN ( SELECT CURRENCY FROM
5633 ar_cmgt_curr_usage_gt
5634 WHERE nvl(credit_request_id,p_credit_request_id) = p_credit_request_id)
5635 and site_use_id = p_cust_acct_site_id
5636 and as_of_date >= (sysdate -l_certified_dso_days)
5637 group by currency);
5638
5639 l_tag VARCHAR2(50);
5640
5641 BEGIN
5642 IF pg_wf_debug = 'Y'
5643 THEN
5644 IF p_case_folder_id IS NULL
5645 THEN
5646 l_tag := 'CR:' || p_credit_request_id;
5647 ELSE
5648 l_tag := 'CF:' || p_case_folder_id;
5649 END IF;
5650 ar_cmgt_util.wf_debug(l_tag,
5651 'ar_cmgt_data_points_pkg.gather_data_points()+');
5652 ar_cmgt_util.wf_debug(l_tag,
5653 ' p_mode = ' || p_mode);
5654 ar_cmgt_util.wf_debug(l_tag,
5655 ' p_party_id = ' || p_party_id);
5656 ar_cmgt_util.wf_debug(l_tag,
5657 ' p_cust_account_id = ' || p_cust_account_id);
5658 ar_cmgt_util.wf_debug(l_tag,
5659 ' p_cust_acct_site_id = ' || p_cust_acct_site_id);
5660 ar_cmgt_util.wf_debug(l_tag,
5661 ' p_trx_currency = ' || p_trx_currency);
5662 ar_cmgt_util.wf_debug(l_tag,
5663 ' p_org_id = ' || p_org_id);
5664 ar_cmgt_util.wf_debug(l_tag,
5665 ' p_check_list_id = ' || p_check_list_id);
5666 ar_cmgt_util.wf_debug(l_tag,
5667 ' p_credit_request_id = ' || p_credit_request_id);
5668 ar_cmgt_util.wf_debug(l_tag,
5669 ' p_score_model_id = ' || p_score_model_id);
5670 ar_cmgt_util.wf_debug(l_tag,
5671 ' p_credit_classification = ' || p_credit_classification);
5672 ar_cmgt_util.wf_debug(l_tag,
5673 ' p_review_type = ' || p_review_type);
5674 ar_cmgt_util.wf_debug(l_tag,
5675 ' p_case_folder_number = ' || p_case_folder_number);
5676 END IF;
5677
5678 -- dbms_session.set_sql_trace(true);
5679 p_resultout := 0;
5680
5681
5682 -- p_case_folder_is is required in case of mode = 'REFRESH'
5683
5684 IF p_mode = 'REFRESH' and p_case_folder_id IS NULL
5685 THEN
5686 p_resultout := 1;
5687 p_error_msg := 'Case Folder Id is required for Refresh Operation';
5688 return;
5689 END IF;
5690
5691 -- Get values from system parameters
5692 BEGIN
5693 SELECT period, cer_dso_days
5694 INTO l_period, l_certified_dso_days
5695 FROM ar_cmgt_setup_options;
5696
5697 EXCEPTION
5698 WHEN OTHERS
5699 THEN
5700 p_resultout := 2;
5701 p_error_msg := 'Please go to the System Options Page and setup system parameters '||sqlerrm;
5702 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
5703 return;
5704
5705 END;
5706 BEGIN
5707 -- Get source_information
5708 SELECT nvl(source_name, 'OCM'), nvl(source_column1, -99)
5709 INTO g_source_name, g_source_id
5710 FROM ar_cmgt_credit_requests
5711 WHERE credit_request_id = p_credit_request_id;
5712
5713 EXCEPTION
5714 WHEN OTHERS THEN
5715 p_resultout := 2;
5716 p_error_msg := 'Unable to get the credit request record '||sqlerrm;
5717 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg);
5718 return;
5719 END;
5720
5721 -- check which level we need to do analysis
5722 l_analysis_level := AR_CMGT_UTIL.find_analysis_level(p_party_id, p_cust_account_id, p_cust_acct_site_id);
5723
5724 AR_CMGT_UTIL.get_limit_currency(
5725 p_party_id => p_party_id,
5726 p_cust_account_id => p_cust_account_id,
5727 p_cust_acct_site_id => p_cust_acct_site_id,
5728 p_trx_currency_code => p_trx_currency,
5729 p_limit_curr_code => l_limit_currency,
5730 p_trx_limit => l_trx_limit,
5731 p_overall_limit => l_overall_limit,
5732 p_cust_acct_profile_amt_id => l_cust_acct_profile_amt_id,
5733 p_global_exposure_flag => l_global_exposure_flag,
5734 p_include_all_flag => l_include_all_flag,
5735 p_usage_curr_tbl => l_curr_tbl,
5736 p_excl_curr_list => l_excl_curr_list);
5737
5738 -- get the conversion type
5739 l_exchange_rate_type := get_conversion_type( p_credit_request_id);
5740
5741 IF l_exchange_rate_type IS NULL
5742 THEN
5743 p_resultout := 2;
5744 p_error_msg := 'Please define an exchange rate before processing this application.';
5745 return;
5746 END IF;
5747
5748
5749 IF pg_wf_debug = 'Y'
5750 THEN
5751 ar_cmgt_util.wf_debug(l_tag,
5752 ' l_include_all_flag = ' || l_include_all_flag);
5753 ar_cmgt_util.wf_debug(l_tag,
5754 ' l_global_exposure_flag = ' || l_global_exposure_flag);
5755 ar_cmgt_util.wf_debug(l_tag,
5756 ' l_analysis_level = ' || l_analysis_level);
5757 ar_cmgt_util.wf_debug(l_tag,
5758 ' l_limit_currency = ' || l_limit_currency);
5759 ar_cmgt_util.wf_debug(l_tag,
5760 ' l_exchange_rate_type = ' || l_exchange_rate_type);
5761 ar_cmgt_util.wf_debug(l_tag,
5762 ' included currencies:');
5763 END IF;
5764
5765 IF ( nvl(l_include_all_flag,'N') = 'N' )
5766 THEN
5767 for i in 1..l_curr_tbl.COUNT
5768 LOOP
5769 IF pg_wf_debug = 'Y'
5770 THEN
5771 IF gl_currency_api.rate_exists(
5772 l_limit_currency,
5773 l_curr_tbl(i).usage_curr_code,
5774 sysdate,
5775 l_exchange_rate_type) = 'Y'
5776 THEN
5777 ar_cmgt_util.wf_debug(l_tag,
5778 l_curr_tbl(i).usage_curr_code);
5779 ELSE
5780 ar_cmgt_util.wf_debug(l_tag,
5781 l_curr_tbl(i).usage_curr_code || ' MISSING RATE');
5782 END IF;
5783 END IF;
5784
5785 INSERT INTO ar_cmgt_curr_usage_gt ( credit_request_id, currency) values
5786 ( p_credit_request_id, l_curr_tbl(i).usage_curr_code);
5787 END LOOP;
5788 ELSE
5789 -- populate temp table with all currency. may not be a good soulution
5790 -- to take this approach. Would be better to have another cursor.
5791 INSERT INTO ar_cmgt_curr_usage_gt(currency)
5792 ( select distinct currency from ar_trx_bal_summary);
5793 IF pg_wf_debug = 'Y'
5794 THEN
5795 ar_cmgt_util.wf_debug(l_tag,
5796 ' ALL currencies from ar_trx_bal_summary');
5797 END IF;
5798 END IF;
5799
5800 p_limit_currency := l_limit_currency;
5801 IF l_limit_currency IS NULL
5802 THEN
5803 p_resultout := 2;
5804 p_error_msg := 'Credit Usage Rule has not been setup';
5805 return;
5806 END IF;
5807
5808 IF l_analysis_level in ( 'P','A')
5809 THEN
5810 IF nvl(l_global_exposure_flag,'N') = 'N'
5811 THEN
5812 p_resultout := 2;
5813 p_error_msg := 'Global Exposure Flag must be set to Y for Party and Account Level Analysis';
5814 return;
5815 END IF;
5816 END IF;
5817
5818 -- update credit request with the limit currency
5819 update ar_cmgt_credit_requests
5820 set limit_currency = l_limit_currency,
5821 LAST_UPDATE_DATE = sysdate,
5822 LAST_UPDATED_BY = FND_GLOBAL.user_id,
5823 LAST_UPDATE_LOGIN = FND_GLOBAL.login_id
5824 WHERE credit_request_id = p_credit_request_id;
5825 --AND limit_currency IS NULL;
5826
5827
5828 IF p_mode = 'CREATE'
5829 THEN
5830 build_case_folder(p_party_id,
5831 p_cust_account_id,
5832 p_cust_acct_site_id,
5833 p_limit_currency,
5834 l_exchange_rate_type,
5835 p_check_list_id,
5836 p_credit_request_id,
5837 p_score_model_id,
5838 p_credit_classification,
5839 p_review_type,
5840 p_case_folder_number,
5841 p_case_folder_id,
5842 l_error_msg,
5843 l_resultout);
5844
5845 IF l_resultout <> 0
5846 THEN
5847 p_resultout := l_resultout;
5848 p_error_msg := l_error_msg;
5849 return;
5850 END IF;
5851 ELSIF p_mode = 'REFRESH'
5852 THEN
5853 -- Referesh case
5854 UPDATE ar_cmgt_case_folders
5855 set last_updated = SYSDATE,
5856 last_update_date = SYSDATE,
5857 last_updated_by = fnd_global.user_id,
5858 last_update_login = fnd_global.login_id
5859 WHERE case_folder_id = p_case_folder_id;
5860 END IF;
5861
5862
5863
5864
5865 BEGIN
5866 IF l_analysis_level = 'P'
5867 THEN
5868 FOR c_summary_rec IN c_party_summary
5869 LOOP
5870 summary_rec_str := summary_rec_str||'{'||
5871 c_summary_rec.avg_pmt_days||'{'||
5872 c_summary_rec.weight_avg_days_late||'{'||
5873 c_summary_rec.days_credit_granted||'{'||
5874 c_summary_rec.nsf_payment_count||'{'||
5875 c_summary_rec.nsf_payment_amount||'{'||
5876 c_summary_rec.credit_memo_value||'{'||
5877 c_summary_rec.credit_memo_count||'{'||
5878 c_summary_rec.per_inv_paid_promptly||'{'||
5879 c_summary_rec.per_inv_paid_late||'{'||
5880 c_summary_rec.per_inv_with_discount||'{'||
5881 c_summary_rec.inv_paid_amount||'{'||
5882 c_summary_rec.inv_paid_count||'{'||
5883 c_summary_rec.earned_disc_value||'{'||
5884 c_summary_rec.earned_disc_count||'{'||
5885 c_summary_rec.unearned_disc_value||'{'||
5886 c_summary_rec.unearned_disc_count||'{'||
5887 c_summary_rec.total_cash_receipts_value||'{'||
5888 c_summary_rec.total_cash_receipts_count||'{'||
5889 c_summary_rec.total_invoices_value||'{'||
5890 c_summary_rec.total_invoices_count||'{'||
5891 c_summary_rec.total_bills_receivables_value||'{'||
5892 c_summary_rec.total_bills_receivables_count||'{'||
5893 c_summary_rec.total_debit_memos_value||'{'||
5894 c_summary_rec.total_debit_memos_count||'{'||
5895 c_summary_rec.total_chargeback_value||'{'||
5896 c_summary_rec.total_chargeback_count||'{'||
5897 c_summary_rec.total_adjustments_value||'{'||
5898 c_summary_rec.total_adjustments_count||'{'||
5899 c_summary_rec.total_deposits_value||'{'||
5900 c_summary_rec.total_deposits_count;
5901
5902 END LOOP;
5903 ELSIF l_analysis_level = 'A'
5904 THEN
5905 FOR c_summary_rec IN c_account_summary
5906 LOOP
5907 summary_rec_str := summary_rec_str||'{'||
5908 c_summary_rec.avg_pmt_days||'{'||
5909 c_summary_rec.weight_avg_days_late||'{'||
5910 c_summary_rec.days_credit_granted||'{'||
5911 c_summary_rec.nsf_payment_count||'{'||
5912 c_summary_rec.nsf_payment_amount||'{'||
5913 c_summary_rec.credit_memo_value||'{'||
5914 c_summary_rec.credit_memo_count||'{'||
5915 c_summary_rec.per_inv_paid_promptly||'{'||
5916 c_summary_rec.per_inv_paid_late||'{'||
5917 c_summary_rec.per_inv_with_discount||'{'||
5918 c_summary_rec.inv_paid_amount||'{'||
5919 c_summary_rec.inv_paid_count||'{'||
5920 c_summary_rec.earned_disc_value||'{'||
5921 c_summary_rec.earned_disc_count||'{'||
5922 c_summary_rec.unearned_disc_value||'{'||
5923 c_summary_rec.unearned_disc_count||'{'||
5924 c_summary_rec.total_cash_receipts_value||'{'||
5925 c_summary_rec.total_cash_receipts_count||'{'||
5926 c_summary_rec.total_invoices_value||'{'||
5927 c_summary_rec.total_invoices_count||'{'||
5928 c_summary_rec.total_bills_receivables_value||'{'||
5929 c_summary_rec.total_bills_receivables_count||'{'||
5930 c_summary_rec.total_debit_memos_value||'{'||
5931 c_summary_rec.total_debit_memos_count||'{'||
5932 c_summary_rec.total_chargeback_value||'{'||
5933 c_summary_rec.total_chargeback_count||'{'||
5934 c_summary_rec.total_adjustments_value||'{'||
5935 c_summary_rec.total_adjustments_count||'{'||
5936 c_summary_rec.total_deposits_value||'{'||
5937 c_summary_rec.total_deposits_count;
5938
5939 END LOOP;
5940 ELSIF l_analysis_level = 'S'
5941 THEN
5942 FOR c_summary_rec IN c_site_summary
5943 LOOP
5944 summary_rec_str := summary_rec_str||'{'||
5945 c_summary_rec.avg_pmt_days||'{'||
5946 c_summary_rec.weight_avg_days_late||'{'||
5947 c_summary_rec.days_credit_granted||'{'||
5948 c_summary_rec.nsf_payment_count||'{'||
5949 c_summary_rec.nsf_payment_amount||'{'||
5950 c_summary_rec.credit_memo_value||'{'||
5951 c_summary_rec.credit_memo_count||'{'||
5952 c_summary_rec.per_inv_paid_promptly||'{'||
5953 c_summary_rec.per_inv_paid_late||'{'||
5954 c_summary_rec.per_inv_with_discount||'{'||
5955 c_summary_rec.inv_paid_amount||'{'||
5956 c_summary_rec.inv_paid_count||'{'||
5957 c_summary_rec.earned_disc_value||'{'||
5958 c_summary_rec.earned_disc_count||'{'||
5959 c_summary_rec.unearned_disc_value||'{'||
5960 c_summary_rec.unearned_disc_count||'{'||
5961 c_summary_rec.total_cash_receipts_value||'{'||
5962 c_summary_rec.total_cash_receipts_count||'{'||
5963 c_summary_rec.total_invoices_value||'{'||
5964 c_summary_rec.total_invoices_count||'{'||
5965 c_summary_rec.total_bills_receivables_value||'{'||
5966 c_summary_rec.total_bills_receivables_count||'{'||
5967 c_summary_rec.total_debit_memos_value||'{'||
5968 c_summary_rec.total_debit_memos_count||'{'||
5969 c_summary_rec.total_chargeback_value||'{'||
5970 c_summary_rec.total_chargeback_count||'{'||
5971 c_summary_rec.total_adjustments_value||'{'||
5972 c_summary_rec.total_adjustments_count||'{'||
5973 c_summary_rec.total_deposits_value||'{'||
5974 c_summary_rec.total_deposits_count;
5975
5976 END LOOP;
5977 END IF;
5978 EXCEPTION
5979 WHEN OTHERS THEN
5980 p_error_msg := 'Error While Getting Data from AR_TRX_SUMMARY, Probably exchange rate'||
5981 ' is not set correctly '||'Sql Error:'||sqlerrm;
5982 p_resultout := 1;
5983 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg || '1');
5984 return;
5985 END;
5986 summary_rec_str := summary_rec_str||'{'; -- adding for instrb call to make life easier
5987 -- Assign the number of columns fetched in the cursor
5988
5989 for i IN 1..summary_rec_col_count
5990 LOOP
5991 l_start_pos := instrb(summary_rec_str,'{',1,i);
5992 l_end_pos := instrb(summary_rec_str,'{',1,i+1);
5993 l_combo_string := substrb(summary_rec_str,l_start_pos+1,
5994 l_end_pos-(l_start_pos+1));
5995 l_data_point_id_end_pos := instrb(l_combo_string,'^',1,1);
5996
5997 l_data_point_id := substrb(l_combo_string,1,l_data_point_id_end_pos-1);
5998 l_data_point_value := substrb(l_combo_string,l_data_point_id_end_pos+1,20);
5999
6000
6001 build_case_folder_details(
6002 p_case_folder_id,
6003 l_data_point_id,
6004 l_data_point_value,
6005 p_mode,
6006 p_error_msg,
6007 p_resultout);
6008 IF p_resultout <> 0
6009 THEN
6010 return;
6011 END IF;
6012 END LOOP;
6013 summary_rec_str := NULL;
6014 BEGIN
6015 IF l_analysis_level = 'P'
6016 THEN
6017 FOR c_bal_summary_rec IN c_party_bal_summary
6018 LOOP
6019 summary_rec_str := summary_rec_str||'{'||
6020 c_bal_summary_rec.current_receivable_balance||'{'||
6021 c_bal_summary_rec.unapplied_cash_amount||'{'||
6022 c_bal_summary_rec.unapplied_cash_count||'{'||
6023 c_bal_summary_rec.past_due_inv_value||'{'||
6024 c_bal_summary_rec.past_due_inv_inst_count||'{'||
6025 c_bal_summary_rec.inv_amt_in_dispute||'{'||
6026 c_bal_summary_rec.disputed_inv_count||'{'||
6027 c_bal_summary_rec.pending_adj_value||'{'||
6028 c_bal_summary_rec.total_receipts_at_risk_value||'{'||
6029 c_bal_summary_rec.op_invoices_value||'{'||
6030 c_bal_summary_rec.op_invoices_count||'{'||
6031 c_bal_summary_rec.op_debit_memos_value||'{'||
6032 c_bal_summary_rec.op_debit_memos_count||'{'||
6033 c_bal_summary_rec.op_deposits_value||'{'||
6034 c_bal_summary_rec.op_deposits_count||'{'||
6035 c_bal_summary_rec.op_bills_receivables_value||'{'||
6036 c_bal_summary_rec.op_bills_receivables_count||'{'||
6037 c_bal_summary_rec.op_chargeback_value||'{'||
6038 c_bal_summary_rec.op_chargeback_count||'{'||
6039 c_bal_summary_rec.op_credit_memos_value||'{'||
6040 c_bal_summary_rec.op_credit_memos_count||'{'||
6041 c_bal_summary_rec.current_invoice_value||'{'||
6042 c_bal_summary_rec.current_invoice_count;
6043 END LOOP;
6044 ELSIF l_analysis_level = 'A'
6045 THEN
6046 FOR c_bal_summary_rec IN c_account_bal_summary
6047 LOOP
6048 summary_rec_str := summary_rec_str||'{'||
6049 c_bal_summary_rec.current_receivable_balance||'{'||
6050 c_bal_summary_rec.unapplied_cash_amount||'{'||
6051 c_bal_summary_rec.unapplied_cash_count||'{'||
6052 c_bal_summary_rec.past_due_inv_value||'{'||
6053 c_bal_summary_rec.past_due_inv_inst_count||'{'||
6054 c_bal_summary_rec.inv_amt_in_dispute||'{'||
6055 c_bal_summary_rec.disputed_inv_count||'{'||
6056 c_bal_summary_rec.pending_adj_value||'{'||
6057 c_bal_summary_rec.total_receipts_at_risk_value||'{'||
6058 c_bal_summary_rec.op_invoices_value||'{'||
6059 c_bal_summary_rec.op_invoices_count||'{'||
6060 c_bal_summary_rec.op_debit_memos_value||'{'||
6061 c_bal_summary_rec.op_debit_memos_count||'{'||
6062 c_bal_summary_rec.op_deposits_value||'{'||
6063 c_bal_summary_rec.op_deposits_count||'{'||
6064 c_bal_summary_rec.op_bills_receivables_value||'{'||
6065 c_bal_summary_rec.op_bills_receivables_count||'{'||
6066 c_bal_summary_rec.op_chargeback_value||'{'||
6067 c_bal_summary_rec.op_chargeback_count||'{'||
6068 c_bal_summary_rec.op_credit_memos_value||'{'||
6069 c_bal_summary_rec.op_credit_memos_count||'{'||
6070 c_bal_summary_rec.current_invoice_value||'{'||
6071 c_bal_summary_rec.current_invoice_count;
6072 END LOOP;
6073 ELSIF l_analysis_level = 'S'
6074 THEN
6075 FOR c_bal_summary_rec IN c_site_bal_summary
6076 LOOP
6077 summary_rec_str := summary_rec_str||'{'||
6078 c_bal_summary_rec.current_receivable_balance||'{'||
6079 c_bal_summary_rec.unapplied_cash_amount||'{'||
6080 c_bal_summary_rec.unapplied_cash_count||'{'||
6081 c_bal_summary_rec.past_due_inv_value||'{'||
6082 c_bal_summary_rec.past_due_inv_inst_count||'{'||
6083 c_bal_summary_rec.inv_amt_in_dispute||'{'||
6084 c_bal_summary_rec.disputed_inv_count||'{'||
6085 c_bal_summary_rec.pending_adj_value||'{'||
6086 c_bal_summary_rec.total_receipts_at_risk_value||'{'||
6087 c_bal_summary_rec.op_invoices_value||'{'||
6088 c_bal_summary_rec.op_invoices_count||'{'||
6089 c_bal_summary_rec.op_debit_memos_value||'{'||
6090 c_bal_summary_rec.op_debit_memos_count||'{'||
6091 c_bal_summary_rec.op_deposits_value||'{'||
6092 c_bal_summary_rec.op_deposits_count||'{'||
6093 c_bal_summary_rec.op_bills_receivables_value||'{'||
6094 c_bal_summary_rec.op_bills_receivables_count||'{'||
6095 c_bal_summary_rec.op_chargeback_value||'{'||
6096 c_bal_summary_rec.op_chargeback_count||'{'||
6097 c_bal_summary_rec.op_credit_memos_value||'{'||
6098 c_bal_summary_rec.op_credit_memos_count||'{'||
6099 c_bal_summary_rec.current_invoice_value||'{'||
6100 c_bal_summary_rec.current_invoice_count;
6101 END LOOP;
6102 END IF;
6103 EXCEPTION
6104 WHEN OTHERS THEN
6105 p_error_msg := 'Error While Getting Data from AR_TRX_BAL_SUMMARY, Probably exchange rate '
6106 ||'is not set correctly '||'Sql Error:'||sqlerrm;
6107 p_resultout := 1;
6108 ar_cmgt_util.wf_debug(p_case_folder_id, p_error_msg || '2');
6109 return;
6110 END;
6111 summary_rec_str := summary_rec_str||'{'; -- adding for instrb call to make life easier
6112
6113 -- Assign the number of columns fetched in the cursor
6114 for i IN 1..bal_summary_rec_col_count
6115 LOOP
6116 l_start_pos := instrb(summary_rec_str,'{',1,i);
6117 l_end_pos := instrb(summary_rec_str,'{',1,i+1);
6118 l_combo_string := substrb(summary_rec_str,l_start_pos+1,
6119 l_end_pos-(l_start_pos+1));
6120 l_data_point_id_end_pos := instrb(l_combo_string,'^',1,1);
6121
6122 l_data_point_id := substrb(l_combo_string,1,l_data_point_id_end_pos-1);
6123 l_data_point_value := substrb(l_combo_string,l_data_point_id_end_pos+1,20);
6124
6125 build_case_folder_details(
6126 p_case_folder_id,
6127 l_data_point_id,
6128 l_data_point_value,
6129 p_mode,
6130 p_error_msg,
6131 p_resultout);
6132 IF p_resultout <> 0
6133 THEN
6134 return;
6135 END IF;
6136 END LOOP;
6137 summary_rec_str := NULL;
6138 -- Calculate DSO
6139 IF l_analysis_level = 'P'
6140 THEN
6141 -- the cursor will always return one row
6142 FOR c_party_numerator_dso_rec IN c_party_numerator_dso
6143 LOOP
6144 l_numerator_dso := c_party_numerator_dso_rec.dso;
6145 l_numerator_ddso := c_party_numerator_dso_rec.delinquent_dso;
6146 END LOOP;
6147 FOR c_party_deno_dso_rec IN c_party_deno_dso
6148 LOOP
6149 l_deno_dso := c_party_deno_dso_rec.dso;
6150 l_deno_ddso := c_party_deno_dso_rec.delinquent_dso;
6151 END LOOP;
6152 IF ( l_deno_dso IS NULL or l_deno_dso = 0 )
6153 THEN
6154 l_deno_dso := 1;
6155 END IF;
6156 IF ( l_deno_ddso IS NULL or l_deno_ddso = 0 )
6157 THEN
6158 l_deno_ddso := 1;
6159 END IF;
6160 l_dso := round((l_numerator_dso/l_deno_dso),2);
6161 l_ddso := round((l_numerator_ddso/l_deno_ddso),2);
6162 ELSIF l_analysis_level = 'A'
6163 THEN
6164 -- the cursor will always return one row
6165 FOR c_account_numerator_dso_rec IN c_account_numerator_dso
6166 LOOP
6167 l_numerator_dso := c_account_numerator_dso_rec.dso;
6168 l_numerator_ddso := c_account_numerator_dso_rec.delinquent_dso;
6169 END LOOP;
6170
6171 FOR c_account_deno_dso_rec IN c_account_deno_dso
6172 LOOP
6173 l_deno_dso := NVL(c_account_deno_dso_rec.dso,1);
6174 l_deno_ddso := NVL(c_account_deno_dso_rec.delinquent_dso,0);
6175
6176 END LOOP;
6177
6178
6179 IF ( l_deno_dso IS NULL or l_deno_dso = 0 )
6180 THEN
6181 l_deno_dso := 1;
6182 END IF;
6183
6184 IF ( l_deno_ddso IS NULL or l_deno_ddso = 0 )
6185 THEN
6186 l_deno_ddso := 1;
6187 END IF;
6188 l_dso := round((l_numerator_dso/l_deno_dso),2);
6189 l_ddso := round((l_numerator_ddso/l_deno_dso),2);
6190 ELSIF l_analysis_level = 'S'
6191 THEN
6192 -- the cursor will always return one row
6193 FOR c_site_numerator_dso_rec IN c_site_numerator_dso
6194 LOOP
6195 l_numerator_dso := c_site_numerator_dso_rec.dso;
6196 l_numerator_ddso := c_site_numerator_dso_rec.delinquent_dso;
6197 END LOOP;
6198 FOR c_site_deno_dso_rec IN c_site_deno_dso
6199 LOOP
6200 l_deno_dso := c_site_deno_dso_rec.dso;
6201 l_deno_ddso := c_site_deno_dso_rec.delinquent_dso;
6202 END LOOP;
6203 IF ( l_deno_dso IS NULL or l_deno_dso = 0 )
6204 THEN
6205 l_deno_dso := 1;
6206 END IF;
6207 IF ( l_deno_ddso IS NULL or l_deno_ddso = 0 )
6208 THEN
6209 l_deno_ddso := 1;
6210 END IF;
6211 l_dso := round((l_numerator_dso/l_deno_dso),2);
6212 l_ddso := round((l_numerator_ddso/l_deno_dso),2);
6213 END IF;
6214
6215 build_case_folder_details(
6216 p_case_folder_id,
6217 2, --dso
6218 fnd_number.number_to_canonical(l_dso),
6219 p_mode,
6220 p_error_msg,
6221 p_resultout);
6222 IF p_resultout <> 0
6223 THEN
6224 return;
6225 END IF;
6226 build_case_folder_details(
6227 p_case_folder_id,
6228 3, -- deliquent dso
6229 fnd_number.number_to_canonical(l_ddso),
6230 p_mode,
6231 p_error_msg,
6232 p_resultout);
6233 IF p_resultout <> 0
6234 THEN
6235 return;
6236 END IF;
6237 --kosriniv number format needs to be handled in GetAnalytical Data for invoice Amounts..
6238 -- get analytic data
6239 GetAnalyticalData (
6240 p_credit_request_id => p_credit_request_id,
6241 p_party_id => p_party_id,
6242 p_cust_account_id => p_cust_account_id,
6243 p_site_use_id => p_cust_acct_site_id,
6244 p_case_folder_id => p_case_folder_id,
6245 p_analysis_level => l_analysis_level,
6246 p_org_id => p_org_id,
6247 p_period => l_period,
6248 p_global_exposure_flag => l_global_exposure_flag,
6249 p_limit_currency => l_limit_currency,
6250 p_exchange_rate_type => l_exchange_rate_type,
6251 p_mode => p_mode,
6252 p_errormsg => p_error_msg,
6253 p_resultout => p_resultout);
6254 IF ( p_resultout <> 0 )
6255 THEN
6256 return;
6257 END IF;
6258 -- kosriniv ... Dunning only includes the dunning count and last dunning date.
6259 GetDunning(
6260 p_credit_request_id => p_credit_request_id,
6261 p_party_id => p_party_id,
6262 p_cust_account_id => p_cust_account_id,
6263 p_site_use_id => p_cust_acct_site_id,
6264 p_org_id => p_org_id,
6265 p_case_folder_id => p_case_folder_id,
6266 p_period => l_period,
6267 p_analysis_level => l_analysis_level,
6268 p_global_exposure_flag => l_global_exposure_flag,
6269 p_mode => p_mode,
6270 p_errormsg => p_error_msg,
6271 p_resultout => p_resultout);
6272 IF p_resultout <> 0
6273 THEN
6274 return;
6275 END IF;
6276 -- kosriniv...Change the Number format of 95,96,98,99,108,30.
6277 -- this procedure will populate all data points which is not in summary tables.
6278 GetOtherDataPoints (
6279 p_credit_request_id => p_credit_request_id,
6280 p_party_id => p_party_id,
6281 p_cust_account_id => p_cust_account_id,
6282 p_site_use_id => p_cust_acct_site_id,
6283 p_cust_acct_profile_amt_id => l_cust_acct_profile_amt_id,
6284 p_case_folder_id => p_case_folder_id,
6285 p_mode => p_mode);
6286 -- kosriniv .. Change the Number format of 15,26,213
6287 GetOMDataPoints(
6288 p_credit_request_id => p_credit_request_id,
6289 p_party_id => p_party_id,
6290 p_cust_account_id => p_cust_account_id,
6291 p_site_use_id => p_cust_acct_site_id,
6292 p_case_folder_id => p_case_folder_id,
6293 p_analysis_level => l_analysis_level,
6294 p_limit_currency_code => p_limit_currency,
6295 p_mode => p_mode,
6296 p_errormsg => p_error_msg,
6297 p_resultout => p_resultout);
6298 IF (p_resultout <> 0)
6299 THEN
6300 return;
6301 END IF;
6302 -- ko Need to Look into this further...
6303 BUILD_DNB_CASE_FOLDER(
6304 p_party_id,
6305 p_check_list_id,
6306 p_case_folder_id,
6307 p_mode,
6308 l_error_msg,
6309 l_resultout);
6310
6311
6312
6313 --kosriniv .. No need of changing the Number format.. The stored data type Number only.
6314 populate_aging_data(
6315 p_case_folder_id => p_case_folder_id,
6316 p_mode => p_mode,
6317 p_error_msg => p_error_msg,
6318 p_resultout => p_resultout);
6319 IF ( p_resultout <> 0 )
6320 THEN
6321 return;
6322 END IF;
6323
6324 -- ko Need to Look into this further...
6325 GetManualDataPoints(
6326 p_credit_request_id => p_credit_request_id,
6327 p_case_folder_id => p_case_folder_id,
6328 p_check_list_id => p_check_list_id,
6329 p_mode => p_mode,
6330 x_error_msg => p_error_msg,
6331 x_resultout => p_resultout);
6332 IF p_resultout <> 0
6333 THEN
6334 return;
6335 END IF;
6336
6337 -- kosriniv .. Change Number format of data points ..113 ..140.
6338 GetFinancialData (
6339 p_credit_request_id => p_credit_request_id,
6340 p_case_folder_id => p_case_folder_id,
6341 p_mode => p_mode,
6342 p_resultout => p_resultout,
6343 p_errmsg => p_error_msg);
6344 IF p_resultout <> 0
6345 THEN
6346 return;
6347 END IF;
6348
6349 -- kosriniv .. Change Numebr For Data points 211.
6350 -- call deduction procedure to populate deduction data points
6351 GetDeductionDataPoints ( -- bug 3691676
6352 p_credit_request_id => p_credit_request_id,
6353 p_case_folder_id => p_case_folder_id,
6354 p_period => l_period,
6355 p_party_id => p_party_id,
6356 p_cust_account_id => p_cust_account_id,
6357 p_site_use_id => p_cust_acct_site_id,
6358 p_analysis_level => l_analysis_level,
6359 p_org_id => p_org_id,
6360 p_mode => p_mode,
6361 p_limit_currency => l_limit_currency,
6362 p_exchange_rate_type => l_exchange_rate_type,
6363 p_global_exposure_flag => l_global_exposure_flag,
6364 p_error_msg => p_error_msg,
6365 p_resultout => p_resultout );
6366
6367 IF p_resultout <> 0
6368 THEN
6369 return;
6370 END IF;
6371 -- in case of Refresh update the status back to save in case folder.
6372 IF p_mode = 'REFRESH'
6373 THEN
6374 -- since case folder got refreshed, need to refresh the score too
6375 -- call scoring engine
6376 ar_cmgt_scoring_engine.generate_score(
6377 p_case_folder_id => p_case_folder_id,
6378 p_score => l_score,
6379 p_error_msg => p_error_msg,
6380 p_resultout => p_resultout);
6381 IF p_resultout <> 0
6382 THEN
6383 -- error in generating the score, so update the score to null
6384 p_resultout := 0;
6385 UPDATE ar_cmgt_cf_dtls
6386 SET score = null,
6387 last_updated_by = fnd_global.user_id,
6388 last_update_date = sysdate,
6389 last_update_login = fnd_global.login_id
6390 WHERE case_folder_id = p_case_folder_id;
6391 END IF;
6392 UPDATE ar_cmgt_case_folders
6393 SET status = 'SAVED',
6394 last_updated = SYSDATE,
6395 last_update_date = SYSDATE,
6396 last_updated_by = fnd_global.user_id,
6397 last_update_login = fnd_global.login_id
6398 WHERE case_folder_id = p_case_folder_id
6399 AND type = 'CASE';
6400
6401
6402 END IF;
6403
6404 -- update all data points value in case folder details which is included in
6405 -- checklist for type 'CASE'.
6406 IF ( p_check_list_id IS NOT NULL )
6407 THEN
6408 UPDATE ar_cmgt_cf_dtls
6409 set included_in_checklist = 'Y'
6410 WHERE case_folder_id = p_case_folder_id
6411 AND data_point_id in (
6412 SELECT data_point_id
6413 FROM ar_cmgt_check_list_dtls
6414 WHERE check_list_id = p_check_list_id);
6415 END IF;
6416 IF pg_wf_debug = 'Y'
6417 THEN
6418 ar_cmgt_util.wf_debug(l_tag,
6419 'ar_cmgt_data_points_pkg.gather_data_points()-');
6420 END IF;
6421 END GATHER_DATA_POINTS;
6422
6423
6424 END AR_CMGT_DATA_POINTS_PKG;