[Home] [Help]
PACKAGE BODY: APPS.IBY_VALIDATIONSETS_PUB
Source
1 PACKAGE BODY IBY_VALIDATIONSETS_PUB AS
2 /*$Header: ibyvallb.pls 120.91.12020000.8 2013/04/26 12:37:31 asarada ship $*/
3
4 --
5 -- Declaring Global variables
6 --
7 G_CURRENT_RUNTIME_LEVEL CONSTANT NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
8 G_LEVEL_STATEMENT CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
9 G_PKG_NAME CONSTANT VARCHAR2(30) := 'IBY_VALIDATIONSETS_PUB';
10
11 --
12 -- User Defined Exceptions
13 --
14 g_abort_program EXCEPTION;
15
16 --
17 -- List of rejection level system options that are possible for
18 -- this module (document validation flow).
19 --
20 REJ_LVL_REQUEST CONSTANT VARCHAR2(100) := 'REQUEST';
21 REJ_LVL_DOCUMENT CONSTANT VARCHAR2(100) := 'DOCUMENT';
22 REJ_LVL_NONE CONSTANT VARCHAR2(100) := 'NONE';
23 REJ_LVL_PAYEE CONSTANT VARCHAR2(100) := 'PAYEE';
24
25 --
26 -- List of document statuses that are used / set in this
27 -- module (document validation flow).
28 --
29 DOC_STATUS_RDY_FOR_VAL CONSTANT VARCHAR2(100) := 'READY_FOR_VALIDATION';
30 DOC_STATUS_REJECTED CONSTANT VARCHAR2(100) := 'REJECTED';
31 DOC_STATUS_FAIL_VALID CONSTANT VARCHAR2(100) := 'FAILED_VALIDATION';
32 DOC_STATUS_VALIDATED CONSTANT VARCHAR2(100) := 'VALIDATED';
33 DOC_STATUS_RELN_FAIL CONSTANT VARCHAR2(100) := 'FAILED_BY_RELATED_DOCUMENT';
34 DOC_STATUS_FAIL_BY_REJLVL CONSTANT VARCHAR2(100)
35 := 'FAILED_BY_REJECTION_LEVEL';
36 DOC_STATUS_FAIL_BY_CA CONSTANT VARCHAR2(100)
37 := 'FAILED_BY_CALLING_APP';
38 DOC_STATUS_REMOVED CONSTANT VARCHAR2(100) := 'REMOVED';
39
40 --
41 -- List of payment statuses that are used / set in this
42 -- module (payment creation flow).
43 --
44 PAY_STATUS_INS_CRTD CONSTANT VARCHAR2(100) := 'INSTRUCTION_CREATED';
45
46 --
47 -- List of payment request statuses that are set in this
48 -- module (document validation flow).
49 --
50 REQ_STATUS_FAIL_VAL CONSTANT VARCHAR2(100) := 'VALIDATION_FAILED';
51 REQ_STATUS_VALIDATED CONSTANT VARCHAR2(100) := 'DOCUMENTS_VALIDATED';
52 REQ_STATUS_USER_REVW_ERR CONSTANT VARCHAR2(100) :=
53 'PENDING_REVIEW_DOC_VAL_ERRORS';
54
55 -- Transaction type (for inserting into IBY_TRANSACTION_ERRORS table)
56 TRXN_TYPE_DOC CONSTANT VARCHAR2(100) := 'DOCUMENT_PAYABLE';
57
58 -- Dummy record
59 l_dummy_err_token_tab trxnErrTokenTabType;
60 /* holds list of default format for each payee */
61 l_payee_format_tab payeeFormatTabType;
62
63 /* holds list of format linked to each profile */
64 l_profile_format_tab profileFormatTabType;
65
66 TYPE externalBankAcctType IS RECORD (
67 external_bank_account_id IBY_EXT_BANK_ACCOUNTS_V.ext_bank_account_id%TYPE,
68 country_code IBY_EXT_BANK_ACCOUNTS_V.country_code%TYPE,
69 end_date IBY_EXT_BANK_ACCOUNTS_V.end_date%TYPE,
70 foreign_pmts_ok_flag IBY_EXT_BANK_ACCOUNTS_V.foreign_payment_use_flag%TYPE
71 );
72 --
73 TYPE externalBankAcctTabType IS TABLE OF externalBankAcctType
74 INDEX BY BINARY_INTEGER;
75
76 ext_bank_acct_tbl externalBankAcctTabType;
77
78 TYPE internalBankAcctType IS RECORD (
79 internal_bank_account_id CE_BANK_ACCOUNTS.bank_account_id%TYPE,
80 bank_home_country CE_BANK_BRANCHES_V.bank_home_country%TYPE,
81 country CE_BANK_BRANCHES_V.country%TYPE
82 );
83 --
84 TYPE internalBankAcctTabType IS TABLE OF internalBankAcctType
85 INDEX BY BINARY_INTEGER;
86
87 int_bank_acct_tbl internalBankAcctTabType;
88 /*Begin of Bug 8322794*/
89
90 TYPE l_int_bank_accts_tbl_type IS TABLE OF BOOLEAN INDEX BY VARCHAR2(2000);
91 l_int_bank_accts_tbl l_int_bank_accts_tbl_type;
92
93 l_internal_bank_accts_index varchar2(2000);
94
95 TYPE payeeTabType is TABLE OF
96 IBY_DOCS_PAYABLE_ALL.calling_app_doc_ref_number%TYPE
97 INDEX BY BINARY_INTEGER;
98
99 l_storedAwtPayees payeeTabType; --Enh 16296267
100
101 /*End of Bug 8322794*/
102
103 /*--------------------------------------------------------------------
104 | NAME:
105 | print_debuginfo
106 |
107 | PURPOSE:
108 | This procedure prints the debug message to the concurrent manager
109 | log file.
110 |
111 | PARAMETERS:
112 | IN
113 | p_debug_text - The debug message to be printed
114 |
115 | OUT
116 |
117 |
118 | RETURNS:
119 |
120 | NOTES:
121 |
122 *---------------------------------------------------------------------*/
123 PROCEDURE print_debuginfo(p_module IN VARCHAR2,
124 p_debug_text IN VARCHAR2,
125 p_debug_level IN VARCHAR2 DEFAULT
126 FND_LOG.LEVEL_STATEMENT
127 )
128 IS
129 l_default_debug_level VARCHAR2(200) := FND_LOG.LEVEL_STATEMENT;
130 BEGIN
131
132 /*
133 * Set the debug level to the value passed in
134 * (provided this value is not null).
135 */
136 IF (p_debug_level IS NOT NULL) THEN
137 l_default_debug_level := p_debug_level;
138 END IF;
139
140 /*
141 * Write the debug message to the concurrent manager log file.
142 */
143
144 /*
145 * Fix for bug 5578607:
146 *
147 * Call the underlying routine only if the current debug
148 * level exceeds the runtime debug level.
149 */
150 --IF (l_default_debug_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
151
152 iby_build_utils_pkg.print_debuginfo(p_module, p_module||':'||p_debug_text,
153 p_debug_level);
154
155 --END IF;
156
157 END print_debuginfo;
158
159 /*--------------------------------------------------------------------
160 | NAME:
161 | performDBUpdates
162 |
163 | PURPOSE:
164 | Updates the status of the payment request and documents of the
165 | payment request.
166 |
167 | PARAMETERS:
168 | IN
169 |
170 |
171 | OUT
172 |
173 |
174 | RETURNS:
175 |
176 | NOTES:
177 |
178 *---------------------------------------------------------------------*/
179 PROCEDURE performDBUpdates(
180 p_pay_service_request_id
181 IN IBY_PAY_SERVICE_REQUESTS.
182 payment_service_request_id%type,
183 p_allDocsTab IN docPayTabType,
184 x_errorDocsTab IN OUT NOCOPY docStatusTabType,
185 p_allDocsSuccessFlag IN BOOLEAN,
186 p_allDocsFailedFlag IN BOOLEAN,
187 p_rejectionLevel IN VARCHAR2,
188 x_txnErrorsTab IN OUT NOCOPY docErrorTabType,
189 x_errTokenTab IN OUT NOCOPY trxnErrTokenTabType,
190 x_return_status IN OUT NOCOPY VARCHAR2
191 )
192 IS
193
194 l_request_status VARCHAR2(200);
195 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.performDBUpdates';
196 l_flag VARCHAR2(1) := 'N';
197 l_empty_table docStatusTabType;
198
199 BEGIN
200
201 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
202 print_debuginfo(l_module_name, 'ENTER');
203
204 END IF;
205 /*
206 * Get the rejection level system option
207 */
208 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
209 print_debuginfo(l_module_name, 'Rejection level system option set to: '
210 || p_rejectionLevel);
211
212
213 END IF;
214 /*-----------START DEBUG---------------*/
215
216 IF (x_errorDocsTab.COUNT <> 0) THEN
217
218 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
219 print_debuginfo(l_module_name, 'Printing list of error documents: ');
220
221 END IF;
222 FOR i IN x_errorDocsTab.FIRST .. x_errorDocsTab.LAST LOOP
223
224 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
225 print_debuginfo(l_module_name, 'doc id: '
226 || x_errorDocsTab(i).doc_id
227 || ', doc status: '
228 || x_errorDocsTab(i).doc_status);
229
230 END IF;
231 END LOOP;
232
233 ELSE
234
235 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
236 print_debuginfo(l_module_name, 'list of error documents is empty');
237
238 END IF;
239 END IF;
240
241 /*-----------END DEBUG---------------*/
242
243 /*
244 * Log the states of important flags
245 */
246 IF (p_allDocsFailedFlag = TRUE) THEN
247 l_flag := 'Y';
248 END IF;
249 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
250 print_debuginfo(l_module_name, 'All docs failed flag: ' || l_flag);
251
252 END IF;
253 l_flag := 'N';
254 IF (p_allDocsSuccessFlag = TRUE) THEN
255 l_flag := 'Y';
256 END IF;
257 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
258 print_debuginfo(l_module_name, 'All docs success flag: ' || l_flag);
259
260
261 END IF;
262 IF (p_rejectionLevel = REJ_LVL_REQUEST) THEN
263
264 /*
265 * For request level rejections, even if one document
266 * in the request has failed validation, set the status
267 * of the request to 'failed validation'.
268 */
269 IF (p_allDocsSuccessFlag = TRUE) THEN
270 l_request_status := REQ_STATUS_VALIDATED;
271 ELSE
272 l_request_status := REQ_STATUS_FAIL_VAL;
273 END IF;
274
275 /*
276 * If all docs have not passed validations, it
277 * means that at least one doc is in error.
278 *
279 * In such a case, all documents in the request
280 * have to be failed.
281 */
282 IF (p_allDocsSuccessFlag <> TRUE) THEN
283 failAllDocsForRequest(p_allDocsTab, x_errorDocsTab,
284 x_txnErrorsTab, x_errTokenTab);
285 END IF;
286
287 ELSIF (p_rejectionLevel = REJ_LVL_DOCUMENT) THEN
288
289 /*
290 * If all documents have failed validation for this
291 * payment request, set the status of the request
292 * to 'failed validation'; Otherwise, set the status
293 * of the request as 'validated'.
294 */
295 IF (p_allDocsFailedFlag = TRUE) THEN
296 l_request_status := REQ_STATUS_FAIL_VAL;
297 ELSE
298 l_request_status := REQ_STATUS_VALIDATED;
299 END IF;
300
301 ELSIF (p_rejectionLevel = REJ_LVL_PAYEE) THEN
302
303 /*
304 * Payee rejection level is similar to the
305 * document rejection level, the difference
306 * being that all documents for a particular
307 * payee must be failed if any documents for that
308 * payee has failed. This cascade failure
309 * has already happened before this method is called.
310 */
311 IF (p_allDocsFailedFlag = TRUE) THEN
312 l_request_status := REQ_STATUS_FAIL_VAL;
313 ELSE
314 l_request_status := REQ_STATUS_VALIDATED;
315 END IF;
316
317 ELSIF (p_rejectionLevel = REJ_LVL_NONE) THEN
318
319 /*
320 * For rejection level 'none', set request status
321 * to 'validated' if all documents were successfully
322 * validated, else, set request status to 'user
323 * review'.
324 */
325 IF (p_allDocsSuccessFlag = TRUE) THEN
326 l_request_status := REQ_STATUS_VALIDATED;
327 ELSE
328 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
329 print_debuginfo(l_module_name, 'At least one doc '
330 || 'has failed. Setting request status to '
331 || REQ_STATUS_USER_REVW_ERR
332 );
333 END IF;
334 l_request_status := REQ_STATUS_USER_REVW_ERR;
335
336 /*
337 * Special handling of failed documents:
338 *
339 * In the nomal scenario, when a document fails
340 * validation, it's status is set to 'REJECTED'
341 * and the document is kicked back to the calling
342 * app via a business event. This is the end of
343 * the lifecycle for these failed documents.
344 *
345 * In the case of rejection level 'NONE', if a
346 * document fails validation, it is not kicked back
347 * to the calling app. Instead, it sits in IBY
348 * and waits for the user to take corrective action
349 * via the IBY UI. Therefore, these documents that
350 * are failed but not kicked back, should have a
351 * special status to indicate that though failed,
352 * these documents are still 'alive' in IBY.
353 *
354 * Therefore, we use a special status 'FAILED_VALIDATION'
355 * to differentiate between documents that have failed
356 * but not have been kicked back, and documents
357 * that have failed and have been kicked back
358 * (those that have been kicked back will have
359 * status 'REJECTED').
360 */
361 FOR i in x_errorDocsTab.FIRST .. x_errorDocsTab.LAST LOOP
362 x_errorDocsTab(i).doc_status := DOC_STATUS_FAIL_VALID;
363 END LOOP;
364
365 END IF;
366
367 ELSE
368
369
370 print_debuginfo(l_module_name, 'Unknown rejection level: '
371 || p_rejectionLevel
372 || '. Aborting document validation ..',
373 FND_LOG.LEVEL_UNEXPECTED
374 );
375
376
377 APP_EXCEPTION.RAISE_EXCEPTION;
378
379 END IF;
380
381 /*
382 * Update the status of the invalid documents
383 */
384 IF (x_errorDocsTab.COUNT > 0) THEN
385
386 FOR i in x_errorDocsTab.FIRST..x_errorDocsTab.LAST LOOP
387
388 UPDATE
389 IBY_DOCS_PAYABLE_ALL
390 SET
391 document_status = x_errorDocsTab(i).doc_status,
392
393 /*
394 * Fix for bug 4405981:
395 *
396 * The straight through flag should be set to 'N',
397 * if the document was rejected / required manual
398 * intervention.
399 */
400 straight_through_flag =
401 DECODE(
402 x_errorDocsTab(i).doc_status,
403 DOC_STATUS_REJECTED, 'N',
404 DOC_STATUS_RELN_FAIL, 'N',
405 DOC_STATUS_FAIL_BY_REJLVL, 'N',
406 DOC_STATUS_FAIL_BY_CA, 'N',
407 DOC_STATUS_REMOVED, 'N',
408 'Y'
409 )
410 WHERE
411 document_payable_id = x_errorDocsTab(i).doc_id
412 AND
413 payment_service_request_id = p_pay_service_request_id;
414
415 END LOOP;
416
417 END IF;
418
419 /*
420 * All documents that haven't failed validation must have been
421 * successfully validated. Set the status of these docs to
422 * validated.
423 */
424 /* Update the status of the valid documents */
425 UPDATE
426 IBY_DOCS_PAYABLE_ALL
427 SET
428 document_status = DOC_STATUS_VALIDATED
429 WHERE
430 document_status NOT IN
431 (
432 DOC_STATUS_REJECTED,
433 DOC_STATUS_RELN_FAIL,
434 DOC_STATUS_FAIL_BY_REJLVL,
435 DOC_STATUS_FAIL_VALID,
436 DOC_STATUS_FAIL_BY_CA,
437 DOC_STATUS_REMOVED
438 ) AND
439 payment_service_request_id = p_pay_service_request_id;
440
441 /*
442 * We have collected all the error messages against the failed
443 * documents in a PLSQL table. Use this to update the
444 * IBY_TRANSACTION_ERRORS table.
445 */
446 insert_transaction_errors('N', x_txnErrorsTab, x_errTokenTab);
447
448 /*
449 * Finally, update the status of the payment request.
450 */
451 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
452 print_debuginfo(l_module_name, 'Updating status of payment request '
453 || p_pay_service_request_id || ' to ' || l_request_status || '.');
454
455 END IF;
456 UPDATE
457 IBY_PAY_SERVICE_REQUESTS
458 SET
459 payment_service_request_status = l_request_status
460 WHERE
461 payment_service_request_id = p_pay_service_request_id;
462
463 /*
464 * Pass back the request status to the caller.
465 */
466 x_return_status := l_request_status;
467
468 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
469 print_debuginfo(l_module_name, 'EXIT');
470
471 END IF;
472 EXCEPTION
473 WHEN OTHERS THEN
474
475 print_debuginfo(l_module_name, 'Fatal: Exception when updating '
476 || 'payment request/document status after document '
477 || 'validation. All changes will be rolled back. Payment request '
478 || 'id is ' || p_pay_service_request_id,
479 FND_LOG.LEVEL_UNEXPECTED
480 );
481 print_debuginfo(l_module_name, 'SQL code: ' || SQLCODE,
482 FND_LOG.LEVEL_UNEXPECTED);
483 print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
484 FND_LOG.LEVEL_UNEXPECTED);
485
486
487 /*
488 * Propogate exception to caller.
489 */
490 RAISE;
491
492 END performDBUpdates;
493
494 /*--------------------------------------------------------------------
495 | NAME:
496 | validate_CH_EST
497 |
498 | PURPOSE:
499 | This function is to validate Switzerland ESR reference number.
500 |
501 |
502 | PARAMETERS:
503 | IN
504 |
505 |
506 | OUT
507 |
508 |
509 | RETURNS:
510 |
511 | NOTES:
512 |
513 *---------------------------------------------------------------------*/
514 FUNCTION validate_CH_EST ( p_esr_number IN VARCHAR2
515 ) RETURN BOOLEAN IS
516
517 l_check_string VARCHAR2(20) := '9468271350946827135';
518
519 l_number_carried NUMBER;
520 l_esr_length NUMBER;
521 l_esr_check_digit NUMBER(1);
522 l_esr_digit VARCHAR(1);
523 l_calculated_check_digit VARCHAR(10);
524 l_number_to_check NUMBER;
525
526 BEGIN
527 l_number_carried := 0;
528
529 l_esr_length := nvl(length(p_esr_number), 0);
530
531 -- Take the check digit
532 l_esr_check_digit := substr(p_esr_number, l_esr_length, 1);
533
534 FOR l_esr_position in 1..l_esr_length-1
535 LOOP
536 l_esr_digit := substr(p_esr_number, l_esr_position, 1);
537 l_number_to_check := l_number_carried + to_number(l_esr_digit);
538 IF (l_number_to_check = 0) THEN
539 l_number_carried := 0;
540 ELSE
541 l_number_carried := substr(l_check_string, l_number_to_check, 1);
542 END IF;
543
544 END LOOP;
545
546 IF (l_number_carried = 0) THEN
547 l_calculated_check_digit := 0;
548 ELSE
549 l_calculated_check_digit := to_char(10 - l_number_carried);
550 END IF;
551
552 IF l_calculated_check_digit <> l_esr_check_digit THEN
553 return (FALSE);
554 ELSE
555 return (TRUE);
556 END IF;
557
558 END validate_CH_EST;
559
560
561 --
562 -- The following are public API's.
563 --
564
565 /*--------------------------------------------------------------------
566 | NAME:
567 | applyDocumentValidationSets
568 |
569 | PURPOSE:
570 | Picks up validation sets which are applicable to a document
571 | and validates each document in the payment request
572 |
573 | PARAMETERS:
574 | IN
575 |
576 |
577 | OUT
578 |
579 |
580 | RETURNS:
581 |
582 | NOTES: Added new validation to validate if the account attached to
583 | the document is valid for the payee.
584 | This was orginally always assumed to be true
585 |
586 *---------------------------------------------------------------------*/
587 PROCEDURE applyDocumentValidationSets(
588 p_pay_service_request_id IN IBY_PAY_SERVICE_REQUESTS.
589 payment_service_request_id%TYPE,
590 p_doc_rejection_level IN IBY_INTERNAL_PAYERS_ALL.
591 document_rejection_level_code%TYPE,
592 p_is_singpay_flag IN BOOLEAN,
593 x_return_status IN OUT NOCOPY VARCHAR2)
594 IS
595
596 l_stmt VARCHAR2(200);
597
598 /* 0 indicates success; non-zero indicates failure */
599 l_result NUMBER := 0;
600
601 /* holds list of all documents for a payment request */
602 l_docs_tab docPayTabType;
603
604 /* holds list of failed documents for a payment request */
605 l_invalid_docs_tab docStatusTabType;
606 l_invalid_doc_rec docStatusRecType;
607 l_doc_error_tab docErrorTabType;
608
609 /* holds list of validation sets applicable to a particular document */
610 l_val_set_index VARCHAR2(2000);
611 l_val_sets_tab valSetTabType;
612 l_val_sets_temp_tab valSetTabType;
613 l_val_sets_count NUMBER := 0;
614
615 l_all_docs_success_flag BOOLEAN := FALSE;
616 l_all_docs_failed_flag BOOLEAN := TRUE;
617 l_doc_failed_flag BOOLEAN := FALSE;
618 l_is_valid BOOLEAN := FALSE;
619 l_already_failed_flag BOOLEAN := FALSE;
620 l_valid_assoc varchar2(5);
621 /*Bug: 9311274
622 Replaced l_end_date_valid by l_account_found
623 We will now also validate if the account attached to
624 the document is valid for the payee.
625 This was orginally always assumed to be true
626 */
627 l_account_found BOOLEAN := TRUE;
628
629 l_rejection_level VARCHAR2(200);
630
631
632 /* variables for fields from payment request */
633 req_ca_payreq_cd iby_pay_service_requests.
634 call_app_pay_service_req_code%TYPE;
635 req_ca_id iby_pay_service_requests.calling_app_id%TYPE;
636
637 --l_bankAccountsArray CE_BANK_AND_ACCOUNT_UTIL.BankAcctIdTable;
638
639 l_print_var VARCHAR2(1) := '';
640 l_doc_err_rec IBY_TRANSACTION_ERRORS%ROWTYPE;
641 l_doc_token_tab trxnErrTokenTabType;
642 l_ext_bank_acct_id IBY_EXT_BANK_ACCOUNTS_V.ext_bank_account_id%TYPE;
643 l_end_date IBY_EXT_BANK_ACCOUNTS_V.end_date%TYPE;
644 l_country_code IBY_EXT_BANK_ACCOUNTS_V.country_code%TYPE;
645 l_foreign_pmts_ok_flag IBY_EXT_BANK_ACCOUNTS_V.foreign_payment_use_flag%TYPE;
646
647 l_int_bank_acct_id CE_BANK_ACCOUNTS.bank_account_id%TYPE;
648 l_country CE_BANK_BRANCHES_V.country%TYPE;
649 l_bank_home_country CE_BANK_BRANCHES_V.bank_home_country%TYPE;
650
651 l_payee_id IBY_DOCS_PAYABLE_ALL.ext_payee_id%TYPE;
652 l_payee_party_id IBY_DOCS_PAYABLE_ALL.payee_party_id%TYPE;
653
654 l_profile_id IBY_PAYMENT_PROFILES.payment_profile_id%TYPE;
655 l_payment_format_cd IBY_PAYMENT_PROFILES.payment_format_code%TYPE;
656 l_bepid IBY_PAYMENT_PROFILES.bepid%TYPE;
657 l_transmit_protocol_cd IBY_PAYMENT_PROFILES.transmit_protocol_code%TYPE;
658 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
659 '.applyDocumentValidationSets';
660
661 l_trx_doc_index BINARY_INTEGER; --Enh 16296267
662
663 /*
664 * Pick up all documents for the specified payment request
665 */
666
667 /*
668 * Pick up validated documents also in this cursor. Otherwise,
669 * if all invalid documents are dismissed by the user we will
670 * end up with a situation where no documents are picked up
671 * by this cursor, and the request will be left unprocessed
672 * during payment re-validation flow.
673 */
674 CURSOR c_docs_list(p_pay_service_request_id IBY_PAY_SERVICE_REQUESTS.
675 payment_service_request_id%TYPE)
676 IS
677 SELECT docs.document_payable_id,
678 docs.calling_app_doc_unique_ref1,
679 docs.calling_app_doc_unique_ref2,
680 docs.calling_app_doc_unique_ref3,
681 docs.calling_app_doc_unique_ref4,
682 docs.calling_app_doc_unique_ref5,
683 docs.calling_app_doc_ref_number,
684 docs.calling_app_id,
685 docs.pay_proc_trxn_type_code,
686 docs.payment_grouping_number,
687 docs.ext_payee_id,
688 docs.payment_profile_id,
689 docs.org_id,
690 docs.org_type,
691 docs.payment_method_code,
692 docs.payment_format_code,
693 docs.payment_currency_code,
694 docs.internal_bank_account_id,
695 docs.external_bank_account_id,
696 docs.payment_date,
697 docs.payee_party_id,
698 docs.supplier_site_id,
699 docs.party_site_id,
700 docs.payment_function,
701 docs.affects_rejection_level --AWT Enh 16296267
702 FROM
703 IBY_DOCS_PAYABLE_ALL docs
704 WHERE
705 docs.payment_service_request_id = p_pay_service_request_id
706 AND docs.document_status IN
707 (
708 DOC_STATUS_RDY_FOR_VAL,
709 DOC_STATUS_FAIL_VALID,
710 DOC_STATUS_FAIL_BY_REJLVL,
711 DOC_STATUS_RELN_FAIL,
712 DOC_STATUS_VALIDATED
713 );
714
715 /*
716 * Pick up all validation sets applicable to the
717 * specified document
718 */
719 CURSOR c_validation_sets(p_document_payable_id IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE,
720 p_payment_grouping_number IBY_DOCS_PAYABLE_ALL.payment_grouping_number%TYPE,
721 p_ext_payee_id IBY_DOCS_PAYABLE_ALL.ext_payee_id%TYPE,
722 p_payment_method_code IBY_DOCS_PAYABLE_ALL.payment_method_code%TYPE,
723 p_int_bank_acct_id IBY_DOCS_PAYABLE_ALL.internal_bank_account_id%TYPE,
724 p_payment_format_code IBY_PAYMENT_PROFILES.payment_format_code%TYPE,
725 p_bepid IBY_PAYMENT_PROFILES.bepid%TYPE,
726 p_transmit_protocol_code IBY_PAYMENT_PROFILES.transmit_protocol_code%TYPE,
727 p_country CE_BANK_BRANCHES_V.country%TYPE
728 )
729 IS
730 SELECT DISTINCT
731 p_document_payable_id,
732 p_payment_grouping_number,
733 p_ext_payee_id,
734 val.validation_set_code,
735 val.validation_code_package,
736 val.validation_code_entry_point,
737 val_options.validation_assignment_id,
738 val_options.val_assignment_entity_type,
739 val.validation_set_display_name
740 FROM
741 IBY_VALIDATION_SETS_VL val,
742 IBY_VAL_ASSIGNMENTS val_options
743 WHERE
744 val.validation_set_code = val_options.validation_set_code
745 AND val.validation_level_code = 'DOCUMENT'
746 AND (val_options.val_assignment_entity_type = 'METHOD'
747 AND val_options.assignment_entity_id =
748 p_payment_method_code
749 OR val_options.val_assignment_entity_type = 'INTBANKACCOUNT'
750 AND val_options.assignment_entity_id =
751 to_char(p_int_bank_acct_id)
752 OR val_options.val_assignment_entity_type = 'FORMAT'
753 AND val_options.assignment_entity_id =
754 p_payment_format_code
755 OR val_options.val_assignment_entity_type = 'BANK'
756 AND val_options.assignment_entity_id =
757 to_char(p_bepid)
758 OR val_options.val_assignment_entity_type = 'TRANSPROTOCOL'
759 AND val_options.assignment_entity_id =
760 p_transmit_protocol_code
761 )
762 AND NVL(val_options.inactive_date, sysdate+1) > sysdate
763
764 /*
765 * Fix for bug 4997133:
766 *
767 * Select validation sets that have the same payment method
768 * code as the document, or have payment method code as null.
769 *
770 * Payment method code null implies that the validation
771 * set is applicable to all payment methods.
772 */
773 AND (NVL(p_payment_method_code, '0') =
774 NVL(val_options.payment_method_code, '0') OR
775 val_options.payment_method_code IS NULL
776 )
777
778 /*
779 * Fix for bug 4997133:
780 *
781 * Select validation sets that have the same country code
782 * code as the document, or have country code as null.
783 *
784 * Country code null implies that the validation
785 * set is applicable to all countries.
786 */
787 AND (p_country = val_options.territory_code OR
788 val_options.territory_code IS NULL
789 )
790 ;
791
792 BEGIN
793 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
794 print_debuginfo(l_module_name, 'ENTER');
795
796 print_debuginfo(l_module_name, 'Payment request id: '
797 || p_pay_service_request_id);
798
799 END IF;
800
801
802 /* Call initDocDataForPPR to insert Documents data
803 * to temporary table
804 */
805 initDocDataForPPR(p_pay_service_request_id);
806
807
808 /*
809 * Fetch all the documents for this payment request.
810 */
811 OPEN c_docs_list(p_pay_service_request_id);
812 FETCH c_docs_list BULK COLLECT INTO l_docs_tab;
813 CLOSE c_docs_list;
814
815 /*
816 * Exit if no documents were found.
817 */
818 IF (l_docs_tab.COUNT = 0) THEN
819 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
820 print_debuginfo(l_module_name, 'No documents payable were '
821 || 'retrieved from DB for payment request '
822 || p_pay_service_request_id
823 || '. Exiting document validation..');
824
825 print_debuginfo(l_module_name, 'EXIT');
826 END IF;
827 RETURN;
828 END IF;
829 /*
830 * Performance Fix:
831 *
832 * Instead of calling IBY_BUILD_UTILS_PKG.inactivateOldErrors(..)
833 * once per document, delete all the error messages linked
834 * to the failed documents of this PPR, and reset the document status
835 * of the failed documents in one shot.
836 */
837 IBY_BUILD_UTILS_PKG.resetDocumentErrors(p_pay_service_request_id);
838
839 /*
840 * Loop through all the documents, validating them one-by-one.
841 */
842 FOR i in l_docs_tab.FIRST .. l_docs_tab.LAST LOOP
843
844
845 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
846 print_debuginfo(l_module_name, 'Validating document id: '
847 || l_docs_tab(i).doc_id
848 );
849
850 print_debuginfo(l_module_name, 'document identifiers: '
851 || ' ('
852 || 'calling app doc unique id1: '
853 || l_docs_tab(i).ca_doc_id1
854 || ' calling app doc unique id2: '
855 || l_docs_tab(i).ca_doc_id2
856 || ' calling app doc unique id3: '
857 || l_docs_tab(i).ca_doc_id3
858 || ' calling app doc ref num: '
859 || l_docs_tab(i).ca_doc_ref_num
860 || ')'
861 );
862
863 END IF;
864 /*
865 * Fix for bug 5440434:
866 *
867 * Before doing any validations, set any
868 * existing validation error messages that
869 * exist against this document to 'inactive'
870 * status in the IBY_TRANSACTION_ERRORS table.
871 *
872 * Unless we do this, the old errors will
873 * continue to show up against this document
874 * in the IBY UI even if the document is validated
875 * successfully this time round.
876 */
877 --IBY_BUILD_UTILS_PKG.inactivateOldErrors(l_docs_tab(i).doc_id,
878 -- TRXN_TYPE_DOC);
879
880 /*
881 * STEP 1:
882 * Core build program validations
883 */
884
885 /*
886 * First validate that payment profile on the document
887 * is valid for (pmt method, org, pmt currency,
888 * int bank acct) on the document.
889 */
890 /* Initialize flag */
891 IF(l_docs_tab(i).ext_bank_acct_id is not null) THEN
892 IF (ext_bank_acct_tbl.EXISTS(l_docs_tab(i).ext_bank_acct_id)) THEN
893 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
894 print_debuginfo(l_module_name, 'Getting the data from Cache For Ext Bank Account Id: ' || l_docs_tab(i).ext_bank_acct_id);
895 END IF;
896 l_end_date := ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).end_date;
897 l_country_code := ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).country_code;
898 l_foreign_pmts_ok_flag := ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).foreign_pmts_ok_flag;
899 ELSE
900 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
901 print_debuginfo(l_module_name, 'Getting the data from DB For Ext Bank Account Id: ' || l_docs_tab(i).ext_bank_acct_id);
902 END IF;
903 BEGIN
904 -- Bug : 9248800 : Will reference base columns instead of view.
905 SELECT ieba.ext_bank_account_id,
906 ieba.country_code,
907 ieba.end_date,
908 ieba.foreign_payment_use_flag
909 INTO l_ext_bank_acct_id,
910 l_country_code,
911 l_end_date,
912 l_foreign_pmts_ok_flag
913 FROM IBY_EXT_BANK_ACCOUNTS ieba
914 WHERE ieba.ext_bank_account_id = l_docs_tab(i).ext_bank_acct_id;
915
916 EXCEPTION
917 WHEN NO_DATA_FOUND THEN
918
919 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
920 print_debuginfo(l_module_name, 'Exception No Data Found For Ext Bank Account Id: ' || l_docs_tab(i).ext_bank_acct_id);
921 END IF;
922 l_ext_bank_acct_id := null;
923 l_country_code := null;
924 l_end_date := null;
925 l_foreign_pmts_ok_flag := null;
926 END;
927 ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).external_bank_account_id := l_ext_bank_acct_id;
928 ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).end_date := l_end_date;
929 ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).country_code := l_country_code;
930 ext_bank_acct_tbl(l_docs_tab(i).ext_bank_acct_id).foreign_pmts_ok_flag := l_foreign_pmts_ok_flag;
931 END IF;
932 ELSE
933 l_ext_bank_acct_id := null;
934 l_country_code := null;
935 l_end_date := null;
936 l_foreign_pmts_ok_flag := null;
937 END IF;
938
939 IF(l_docs_tab(i).int_bank_acct_id is not null) THEN
940 IF (int_bank_acct_tbl.EXISTS(l_docs_tab(i).int_bank_acct_id)) THEN
941 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
942 print_debuginfo(l_module_name, 'Getting the data from Cache For Int Bank Account Id: ' || l_docs_tab(i).int_bank_acct_id);
943 END IF;
944 l_country := int_bank_acct_tbl(l_docs_tab(i).int_bank_acct_id).country;
945 l_bank_home_country := int_bank_acct_tbl(l_docs_tab(i).int_bank_acct_id).bank_home_country;
946
947 ELSE
948 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
949 print_debuginfo(l_module_name, 'Getting the data from DB For Int Bank Account Id: ' || l_docs_tab(i).int_bank_acct_id);
950 END IF;
951 BEGIN
952 SELECT cba.bank_account_id,
953 cb.country,
954 cb.bank_home_country
955 INTO l_int_bank_acct_id,
956 l_country,
957 l_bank_home_country
958 FROM CE_BANK_ACCOUNTS cba, CE_BANK_BRANCHES_V cb
959 WHERE cba.bank_branch_id = cb.branch_party_id
960 AND cba.bank_account_id = l_docs_tab(i).int_bank_acct_id;
961
962
963 EXCEPTION
964 WHEN NO_DATA_FOUND THEN
965
966 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
967 print_debuginfo(l_module_name, 'Exception No Data Found For Int Bank Account Id: ' || l_docs_tab(i).int_bank_acct_id);
968 END IF;
969 l_int_bank_acct_id := null;
970 l_country := null;
971 l_bank_home_country := null;
972 END;
973 int_bank_acct_tbl(l_docs_tab(i).int_bank_acct_id).internal_bank_account_id := l_int_bank_acct_id;
974 int_bank_acct_tbl(l_docs_tab(i).int_bank_acct_id).country := l_country;
975 int_bank_acct_tbl(l_docs_tab(i).int_bank_acct_id).bank_home_country := l_bank_home_country;
976 END IF;
977 ELSE
978 l_int_bank_acct_id := null;
979 l_country := null;
980 l_bank_home_country := null;
981 END IF;
982 l_is_valid := FALSE;
983
984 l_is_valid := validateProfileFromProfDrivers(
985 l_docs_tab(i).profile_id,
986 l_docs_tab(i).org_id,
987 l_docs_tab(i).org_type,
988 l_docs_tab(i).pmt_method_cd,
989 l_docs_tab(i).pmt_curr_code,
990 l_docs_tab(i).int_bank_acct_id
991 );
992
993 IF (l_is_valid = FALSE) THEN
994 /*
995 * If profile is not applicable,
996 * add doc to list of invalid documents.
997 */
998 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
999 print_debuginfo(l_module_name, 'Failing document id: '
1000 || l_docs_tab(i).doc_id
1001 || ' because payment profile is invalid');
1002
1003 END IF;
1004 l_invalid_doc_rec.doc_id := l_docs_tab(i).doc_id;
1005 l_invalid_doc_rec.pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1006 l_invalid_doc_rec.payee_id := l_docs_tab(i).payee_id;
1007 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1008 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; --AWT Enh 16296267
1009
1010 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1011 l_invalid_doc_rec;
1012
1013 l_doc_failed_flag := TRUE;
1014
1015 /* AWT Enh 16296267 */
1016 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1017 l_trx_doc_index := l_docs_tab(i).payee_id;
1018 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1019 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1020 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1021 END IF;
1022 ELSE
1023 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1024 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1025 ' to Invalid Payee Awt List');
1026 END IF;
1027 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1028 END IF;
1029 END IF;
1030
1031 /*
1032 * Once we fail a doc, we must add a corresponding
1033 * error message to the error table.
1034 */
1035 IBY_BUILD_UTILS_PKG.createErrorRecord(
1036 TRXN_TYPE_DOC,
1037 l_docs_tab(i).doc_id,
1038 l_invalid_doc_rec.doc_status,
1039 l_docs_tab(i).ca_id,
1040 l_docs_tab(i).ca_doc_id1,
1041 l_docs_tab(i).ca_doc_id2,
1042 l_docs_tab(i).ca_doc_id3,
1043 l_docs_tab(i).ca_doc_id4,
1044 l_docs_tab(i).ca_doc_id5,
1045 l_docs_tab(i).pp_tt_cd,
1046 l_doc_err_rec,
1047 l_doc_token_tab,
1048 NULL,
1049 'IBY_DOC_INVALID_PROFILE'
1050 );
1051
1052 insertIntoErrorTable(l_doc_err_rec, l_doc_error_tab,
1053 l_doc_token_tab);
1054
1055 ELSE
1056
1057 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1058 print_debuginfo(l_module_name, 'Payment profile is valid for '
1059 || 'document id: '
1060 || l_docs_tab(i).doc_id);
1061
1062 END IF;
1063 END IF;
1064
1065 /*
1066 * Validate that the profile on the document
1067 * is compatible with the format on the document
1068 * payee.
1069 */
1070
1071 /* Initialize flag */
1072 l_is_valid := FALSE;
1073
1074 l_is_valid := checkProfileFormatCompat(
1075 l_docs_tab(i).doc_id,
1076 l_docs_tab(i).payee_id,
1077 l_docs_tab(i).profile_id
1078 );
1079
1080 IF (l_is_valid = FALSE) THEN
1081 /*
1082 * If profile is not compatible with format,
1083 * add doc to list of invalid documents.
1084 */
1085 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1086 print_debuginfo(l_module_name, 'Failing document id: '
1087 || l_docs_tab(i).doc_id
1088 || ' because payment profile is not compatible '
1089 || ' with payment format.'
1090 );
1091
1092 END IF;
1093 l_invalid_doc_rec.doc_id := l_docs_tab(i).doc_id;
1094 l_invalid_doc_rec.pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1095 l_invalid_doc_rec.payee_id := l_docs_tab(i).payee_id;
1096 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1097 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; --AWT Enh 16296267
1098
1099 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1100 l_invalid_doc_rec;
1101
1102 l_doc_failed_flag := TRUE;
1103
1104 /* AWT Enh 16296267 */
1105 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1106 l_trx_doc_index := l_docs_tab(i).payee_id;
1107 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1108 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1109 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1110 END IF;
1111 ELSE
1112 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1113 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1114 ' to Invalid Payee Awt List');
1115 END IF;
1116 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1117 END IF;
1118 END IF;
1119 /*
1120 * Once we fail a doc, we must add a corresponding
1121 * error message to the error table.
1122 */
1123 IBY_BUILD_UTILS_PKG.createErrorRecord(
1124 TRXN_TYPE_DOC,
1125 l_docs_tab(i).doc_id,
1126 l_invalid_doc_rec.doc_status,
1127 l_docs_tab(i).ca_id,
1128 l_docs_tab(i).ca_doc_id1,
1129 l_docs_tab(i).ca_doc_id2,
1130 l_docs_tab(i).ca_doc_id3,
1131 l_docs_tab(i).ca_doc_id4,
1132 l_docs_tab(i).ca_doc_id5,
1133 l_docs_tab(i).pp_tt_cd,
1134 l_doc_err_rec,
1135 l_doc_token_tab,
1136 NULL,
1137 'IBY_DOC_INV_PROFILE_FORMAT'
1138 );
1139
1140 insertIntoErrorTable(l_doc_err_rec, l_doc_error_tab,
1141 l_doc_token_tab);
1142
1143 ELSE
1144
1145 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1146 print_debuginfo(l_module_name, 'Payment profile is compatible '
1147 || 'with payment format for '
1148 || 'document id: '
1149 || l_docs_tab(i).doc_id);
1150
1151 END IF;
1152 END IF;
1153
1154 /* Validating external/supplier bank account */
1155 /* Initialize flag */
1156 l_is_valid := FALSE;
1157
1158 IF(nvl(l_end_date,sysdate+1) > sysdate) THEN
1159 l_is_valid := TRUE;
1160 END IF;
1161
1162 IF(l_is_valid = TRUE) THEN
1163 print_debuginfo(l_module_name, 'Ext Bank Acct Id field is: '
1164 || l_docs_tab(i).ext_bank_acct_id
1165 || ' for the assignments '
1166 );
1167 print_debuginfo(l_module_name, 'Payee Party Id field is: '
1168 || l_docs_tab(i).payee_party_id
1169 || ' for the assignments '
1170 );
1171 print_debuginfo(l_module_name, 'Supplier Site Id field is: '
1172 || l_docs_tab(i).supplier_site_id
1173 || ' for the assignments '
1174 );
1175 print_debuginfo(l_module_name, 'Party Site Id field is: '
1176 || l_docs_tab(i).party_site_id
1177 || ' for the assignments '
1178 );
1179 print_debuginfo(l_module_name, 'Org Id field is: '
1180 || l_docs_tab(i).org_id
1181 || ' for the assignments '
1182 );
1183 print_debuginfo(l_module_name, 'Org Type field is: '
1184 || l_docs_tab(i).org_type
1185 || ' for the assignments '
1186 );
1187 IF(l_docs_tab(i).ext_bank_acct_id is not null ) THEN
1188 -- Set this to false only if bank account exists, We do not validate if
1189 -- no bank account exists.
1190
1191 BEGIN
1192 select 'TRUE' into l_valid_assoc from dual where exists(
1193 SELECT 'valid_assoc' FROM iby_pmt_instr_uses_all
1194 WHERE instrument_type = 'BANKACCOUNT'
1195 AND INSTRUMENT_ID = l_docs_tab(i).ext_bank_acct_id
1196 AND payment_flow = 'DISBURSEMENTS'
1197 AND EXT_PMT_PARTY_ID IN (
1198 SELECT EXT_PAYEE_ID FROM IBY_EXTERNAL_PAYEES_ALL
1199 WHERE PAYEE_PARTY_ID = l_docs_tab(i).payee_party_id
1200 AND(
1201 (supplier_site_id = l_docs_tab(i).supplier_site_id AND nvl(party_site_id,-99) = nvl(l_docs_tab(i).party_site_id,-99)
1202 AND org_id = l_docs_tab(i).org_id AND org_type = l_docs_tab(i).org_type)
1203 OR (supplier_site_id IS NULL AND party_site_id = l_docs_tab(i).party_site_id
1204 AND org_id = l_docs_tab(i).org_id AND org_type = l_docs_tab(i).org_type)
1205 OR (supplier_site_id IS NULL AND party_site_id = l_docs_tab(i).party_site_id AND org_id IS NULL AND org_type IS NULL)
1206 OR (supplier_site_id IS NULL AND party_site_id IS NULL AND org_id IS NULL AND org_type IS NULL)
1207 /* This condition is for Cash Payments (CE). Payee might be created for Legal Entity*/
1208 OR (supplier_site_id IS NULL AND party_site_id IS NULL AND org_id = l_docs_tab(i).org_id AND org_type = l_docs_tab(i).org_type)
1209 )
1210 )
1211 AND Nvl(END_DATE, SYSDATE+10) > SYSDATE
1212 );
1213 l_is_valid := TRUE;
1214 EXCEPTION
1215 WHEN NO_DATA_FOUND THEN
1216 l_is_valid := FALSE;
1217 print_debuginfo(l_module_name, 'Account attached to supplier is not valid in this context!');
1218 WHEN OTHERS THEN
1219 print_debuginfo(l_module_name, 'Sql Query returns OTHER exception');
1220 RAISE;
1221 END;
1222
1223 END IF;
1224 END IF;
1225
1226 IF (l_is_valid = FALSE) THEN
1227 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1228 print_debuginfo(l_module_name, 'Failing document id: '
1229 || l_docs_tab(i).doc_id
1230 || ' Supplier / External Bankaccount is attached is NOT valid '
1231 );
1232
1233 END IF;
1234 l_invalid_doc_rec.doc_id := l_docs_tab(i).doc_id;
1235 l_invalid_doc_rec.pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1236 l_invalid_doc_rec.payee_id := l_docs_tab(i).payee_id;
1237 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1238 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; --AWT Enh 16296267
1239
1240 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1241 l_invalid_doc_rec;
1242 l_doc_failed_flag := TRUE;
1243
1244 /* AWT Enh 16296267 */
1245 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1246 l_trx_doc_index := l_docs_tab(i).payee_id;
1247 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1248 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1249 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1250 END IF;
1251 ELSE
1252 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1253 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1254 ' to Invalid Payee Awt List');
1255 END IF;
1256 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1257 END IF;
1258 END IF;
1259 /*
1260 * Once we fail a doc, we must add a corresponding
1261 * error message to the error table.
1262 */
1263 IBY_BUILD_UTILS_PKG.createErrorRecord(
1264 TRXN_TYPE_DOC,
1265 l_docs_tab(i).doc_id,
1266 l_invalid_doc_rec.doc_status,
1267 l_docs_tab(i).ca_id,
1268 l_docs_tab(i).ca_doc_id1,
1269 l_docs_tab(i).ca_doc_id2,
1270 l_docs_tab(i).ca_doc_id3,
1271 l_docs_tab(i).ca_doc_id4,
1272 l_docs_tab(i).ca_doc_id5,
1273 l_docs_tab(i).pp_tt_cd,
1274 l_doc_err_rec,
1275 l_doc_token_tab,
1276 NULL,
1277 'IBY_DOC_INV_BANK_ACCOUNT'
1278 );
1279 insertIntoErrorTable(l_doc_err_rec, l_doc_error_tab,
1280 l_doc_token_tab);
1281 ELSE
1282 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1283 print_debuginfo(l_module_name, 'Supplier / External Bankaccount is attached is valid for '
1284 || 'document id: '
1285 || l_docs_tab(i).doc_id);
1286 END IF;
1287 END IF;
1288 /*
1289 * Next, validate that internal bank account on doc is
1290 * valid for (org, currency) on document.
1291 */
1292
1293 /*
1294 * Call CE API
1295 */
1296 /* Initialize flag */
1297
1298
1299 l_is_valid := FALSE;
1300
1301 /* Commented for bug # 8322794
1302 CE_BANK_AND_ACCOUNT_UTIL.get_internal_bank_accts(
1303 l_docs_tab(i).pmt_curr_code,
1304 l_docs_tab(i).org_type,
1305 l_docs_tab(i).org_id,
1306 l_docs_tab(i).pmt_date,
1307 l_docs_tab(i).int_bank_acct_id,
1308 l_is_valid
1309 );
1310 */
1311
1312 /*Begin of Bug 8322794*/
1313
1314 l_internal_bank_accts_index := l_docs_tab(i).pmt_curr_code||'$'||l_docs_tab(i).org_type||'$'||l_docs_tab(i).org_id||'$'||l_docs_tab(i).pmt_date||'$'||l_docs_tab(i).int_bank_acct_id;
1315 IF(l_internal_bank_accts_index is not null) THEN
1316 IF(l_int_bank_accts_tbl.EXISTS(l_internal_bank_accts_index)) THEN
1317 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1318 print_debuginfo(l_module_name, 'Fetching the value from Cache Structure l_int_bank_accts_tbl ' || l_internal_bank_accts_index);
1319 END IF;
1320 l_is_valid := l_int_bank_accts_tbl(l_internal_bank_accts_index);
1321 ELSE
1322 print_debuginfo(l_module_name, 'Fetching the value from the DB for l_int_bank_accts_tbl ' || l_internal_bank_accts_index);
1323 CE_BANK_AND_ACCOUNT_UTIL.get_internal_bank_accts(
1324 l_docs_tab(i).pmt_curr_code,
1325 l_docs_tab(i).org_type,
1326 l_docs_tab(i).org_id,
1327 l_docs_tab(i).pmt_date,
1328 l_docs_tab(i).int_bank_acct_id,
1329 l_is_valid
1330 );
1331
1332 l_int_bank_accts_tbl(l_internal_bank_accts_index) := l_is_valid;
1333 END IF;
1334 END IF;
1335
1336 /*End of Bug 8322794*/
1337
1338
1339 IF (l_is_valid = FALSE) THEN
1340
1341 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1342 print_debuginfo(l_module_name, 'Internal bank account '
1343 || l_docs_tab(i).int_bank_acct_id
1344 || ' is not applicable for org '
1345 || l_docs_tab(i).org_id
1346 || ', currency '
1347 || l_docs_tab(i).pmt_curr_code
1348 || ' and payment date '
1349 || l_docs_tab(i).pmt_date
1350 || ' combination');
1351
1352 END IF;
1353 /*
1354 * If int bank account is not applicable,
1355 * add doc to list of invalid documents.
1356 */
1357 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1358 print_debuginfo(l_module_name, 'Failing document id: '
1359 || l_docs_tab(i).doc_id
1360 || ' because internal bank account is invalid');
1361
1362 END IF;
1363 l_already_failed_flag :=
1364 checkIfDocFailed(l_docs_tab(i).doc_id,
1365 l_invalid_docs_tab);
1366
1367 /*
1368 * Add this doc to the list of invalid documents
1369 * only if it is not already present in the
1370 * invalid docs list.
1371 */
1372 IF (l_already_failed_flag = FALSE) THEN
1373
1374 l_invalid_doc_rec.doc_id := l_docs_tab(i).doc_id;
1375 l_invalid_doc_rec.pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1376 l_invalid_doc_rec.payee_id := l_docs_tab(i).payee_id;
1377 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1378 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; --AWT Enh 16296267
1379
1380 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1381 l_invalid_doc_rec;
1382
1383 l_doc_failed_flag := TRUE;
1384
1385 /* AWT Enh 16296267 */
1386 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1387 l_trx_doc_index := l_docs_tab(i).payee_id;
1388 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1389 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1390 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1391 END IF;
1392 ELSE
1393 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1394 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1395 ' to Invalid Payee Awt List');
1396 END IF;
1397 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1398 END IF;
1399 END IF;
1400 /*
1401 * Once we fail a doc, we must add a corresponding
1402 * error message to the error table.
1403 */
1404 IBY_BUILD_UTILS_PKG.createErrorRecord(
1405 TRXN_TYPE_DOC,
1406 l_docs_tab(i).doc_id,
1407 l_invalid_doc_rec.doc_status,
1408 l_docs_tab(i).ca_id,
1409 l_docs_tab(i).ca_doc_id1,
1410 l_docs_tab(i).ca_doc_id2,
1411 l_docs_tab(i).ca_doc_id3,
1412 l_docs_tab(i).ca_doc_id4,
1413 l_docs_tab(i).ca_doc_id5,
1414 l_docs_tab(i).pp_tt_cd,
1415 l_doc_err_rec,
1416 l_doc_token_tab,
1417 NULL,
1418 'IBY_DOC_INV_INTBANKACCT'
1419 );
1420
1421 insertIntoErrorTable(l_doc_err_rec, l_doc_error_tab,
1422 l_doc_token_tab);
1423
1424 END IF;
1425
1426 ELSE
1427
1428 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1429 print_debuginfo(l_module_name, 'Internal bank acct is valid for '
1430 || 'document id: '
1431 || l_docs_tab(i).doc_id);
1432
1433 END IF;
1434 END IF; -- if internal bank acct is invalid
1435
1436 /*
1437 * Next, validate that external payee id on the doc is
1438 * valid (not -1). The ext payee id on the document
1439 * is derived from the payee context on the document;
1440 * these are fields such as payee id, payee party id,
1441 * payee party site id etc.
1442 *
1443 * The external party id is derived when the document
1444 * in inserted into the IBY tables. If the logic to
1445 * derive the ext payee id, could not find a matching
1446 * ext payee id for the document, then the ext payee id
1447 * would be set to -1 for that document.
1448 *
1449 * Fail all document that have the ext payee id set to
1450 * -1. The user is expected to seed the IBY_EXTERNAL_PAYEES_ALL
1451 * table such that the ext payee id is always available for
1452 * payee context on the document (otherwise, the
1453 * document cannot be paid!).
1454 */
1455
1456 /* Initialize flag */
1457 l_is_valid := FALSE;
1458
1459 IF (l_docs_tab(i).payee_id = -1) THEN
1460 l_is_valid := FALSE;
1461 ELSE
1462 l_is_valid := TRUE;
1463 END IF;
1464
1465 IF (l_is_valid = FALSE) THEN
1466
1467 /*
1468 * If ext payee id is not available,
1469 * add doc to list of invalid documents.
1470 */
1471 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1472 print_debuginfo(l_module_name, 'Failing document id: '
1473 || l_docs_tab(i).doc_id
1474 || ' because external payee id is not '
1475 || 'available for this document'
1476 );
1477
1478 END IF;
1479 l_already_failed_flag :=
1480 checkIfDocFailed(l_docs_tab(i).doc_id,
1481 l_invalid_docs_tab);
1482
1483 /*
1484 * Add this doc to the list of invalid documents
1485 * only if it is not already present in the
1486 * invalid docs list.
1487 */
1488 IF (l_already_failed_flag = FALSE) THEN
1489
1490 l_invalid_doc_rec.doc_id := l_docs_tab(i).doc_id;
1491 l_invalid_doc_rec.pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1492 l_invalid_doc_rec.payee_id := l_docs_tab(i).payee_id;
1493 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1494 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; --AWT Enh 16296267
1495
1496 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1497 l_invalid_doc_rec;
1498
1499 l_doc_failed_flag := TRUE;
1500
1501 /* AWT Enh 16296267 */
1502 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1503 l_trx_doc_index := l_docs_tab(i).payee_id;
1504 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1505 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1506 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1507 END IF;
1508 ELSE
1509 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1510 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1511 ' to Invalid Payee Awt List');
1512 END IF;
1513 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1514 END IF;
1515 END IF;
1516 /*
1517 * Once we fail a doc, we must add a corresponding
1518 * error message to the error table.
1519 */
1520 IBY_BUILD_UTILS_PKG.createErrorRecord(
1521 TRXN_TYPE_DOC,
1522 l_docs_tab(i).doc_id,
1523 l_invalid_doc_rec.doc_status,
1524 l_docs_tab(i).ca_id,
1525 l_docs_tab(i).ca_doc_id1,
1526 l_docs_tab(i).ca_doc_id2,
1527 l_docs_tab(i).ca_doc_id3,
1528 l_docs_tab(i).ca_doc_id4,
1529 l_docs_tab(i).ca_doc_id5,
1530 l_docs_tab(i).pp_tt_cd,
1531 l_doc_err_rec,
1532 l_doc_token_tab,
1533 NULL,
1534 'IBY_DOC_INVALID_EXT_PAYEE'
1535 );
1536
1537 insertIntoErrorTable(l_doc_err_rec, l_doc_error_tab,
1538 l_doc_token_tab);
1539
1540 END IF;
1541
1542 ELSE
1543
1544 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1545 print_debuginfo(l_module_name, 'External payee id is valid for '
1546 || 'document id: '
1547 || l_docs_tab(i).doc_id);
1548
1549 END IF;
1550 END IF; -- if external payee id is invalid
1551
1552 /*
1553 * Validate that the external bank account can be used
1554 * for cross border payments (if the internal bank account
1555 * and external bank accounts belong to different countries).
1556 */
1557
1558 /* Initialize flag */
1559 l_is_valid := FALSE;
1560
1561 IF (l_country IS NOT NULL AND
1562 l_country_code IS NOT NULL) THEN
1563
1564 IF (l_country <>
1565 l_country_code) THEN
1566
1567 /*
1568 * This is a cross border payment.
1569 */
1570 IF (UPPER(l_foreign_pmts_ok_flag) = 'Y') THEN
1571
1572 l_is_valid := TRUE;
1573
1574 ELSE
1575
1576 /*
1577 * Fail document because cross-border
1578 * payments are not allowed to this external
1579 * bank account.
1580 */
1581 l_is_valid := FALSE;
1582
1583 END IF;
1584
1585 ELSE
1586
1587 /*
1588 * This is a domestic payment. Skip this
1589 * validation.
1590 */
1591 l_is_valid := TRUE;
1592
1593 END IF;
1594
1595 ELSE
1596
1597 /*
1598 * If either internal bank account country is null
1599 * or external bank account country is null, assume
1600 * that the payment is domestic, and skip the validation.
1601 */
1602 l_is_valid := TRUE;
1603
1604 END IF;
1605
1606
1607 IF (l_is_valid = FALSE) THEN
1608
1609 /*
1610 * If cross border payment has been failed,
1611 * add doc to list of invalid documents.
1612 */
1613
1614 -- Changed the error message for bug 5442800 (Panaraya)
1615 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1616 print_debuginfo(l_module_name, 'Failing document id: '
1617 || l_docs_tab(i).doc_id
1618 || 'The payee bank account is set up to allow '
1619 || 'domestic payments only. The internal bank '
1620 || 'account used to pay this document will result '
1621 || 'in an international payment to this payee bank '
1622 || 'account.'
1623 );
1624
1625 END IF;
1626 l_already_failed_flag :=
1627 checkIfDocFailed(l_docs_tab(i).doc_id,
1628 l_invalid_docs_tab);
1629
1630 /*
1631 * Add this doc to the list of invalid documents
1632 * only if it is not already present in the
1633 * invalid docs list.
1634 */
1635 IF (l_already_failed_flag = FALSE) THEN
1636
1637 l_invalid_doc_rec.doc_id := l_docs_tab(i).doc_id;
1638 l_invalid_doc_rec.pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1639 l_invalid_doc_rec.payee_id := l_docs_tab(i).payee_id;
1640 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1641 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; --AWT Enh 16296267
1642
1643 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1644 l_invalid_doc_rec;
1645
1646 l_doc_failed_flag := TRUE;
1647
1648 /* AWT Enh 16296267 */
1649 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1650 l_trx_doc_index := l_docs_tab(i).payee_id;
1651 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1652 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1653 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1654 END IF;
1655 ELSE
1656 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1657 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1658 ' to Invalid Payee Awt List');
1659 END IF;
1660 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1661 END IF;
1662 END IF;
1663 /*
1664 * Once we fail a doc, we must add a corresponding
1665 * error message to the error table.
1666 */
1667 IBY_BUILD_UTILS_PKG.createErrorRecord(
1668 TRXN_TYPE_DOC,
1669 l_docs_tab(i).doc_id,
1670 l_invalid_doc_rec.doc_status,
1671 l_docs_tab(i).ca_id,
1672 l_docs_tab(i).ca_doc_id1,
1673 l_docs_tab(i).ca_doc_id2,
1674 l_docs_tab(i).ca_doc_id3,
1675 l_docs_tab(i).ca_doc_id4,
1676 l_docs_tab(i).ca_doc_id5,
1677 l_docs_tab(i).pp_tt_cd,
1678 l_doc_err_rec,
1679 l_doc_token_tab,
1680 NULL,
1681 'IBY_DOC_INV_CROSSBORDER_PMT'
1682 );
1683
1684 insertIntoErrorTable(l_doc_err_rec, l_doc_error_tab,
1685 l_doc_token_tab);
1686
1687 END IF;
1688
1689 END IF; -- if external payee id is invalid
1690
1691 /*
1692 * STEP 2:
1693 * Dynamic validations via validation sets
1694 */
1695
1696 /*
1697 * Fetch all applicable validation sets for this document.
1698 */
1699 IF (l_profile_format_tab.EXISTS(l_docs_tab(i).profile_id) ) THEN
1700 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1701 print_debuginfo(l_module_name, 'Getting Data from Cache For Profile Id: ' || l_docs_tab(i).profile_id);
1702 END IF;
1703 l_payment_format_cd := l_profile_format_tab(l_docs_tab(i).profile_id).payment_format_cd;
1704 l_bepid := l_profile_format_tab(l_docs_tab(i).profile_id).bepid;
1705 l_transmit_protocol_cd := l_profile_format_tab(l_docs_tab(i).profile_id).transmit_protocol_cd;
1706
1707 ELSE
1708 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1709 print_debuginfo(l_module_name, 'Getting Data from DB For Profile Id: ' || l_docs_tab(i).profile_id);
1710 END IF;
1711 BEGIN
1712 SELECT ipp.payment_profile_id,
1713 ipp.payment_format_code, ipp.bepid, ipp.transmit_protocol_code
1714 INTO l_profile_id,l_payment_format_cd,l_bepid,l_transmit_protocol_cd
1715 FROM IBY_PAYMENT_PROFILES ipp
1716 WHERE ipp.payment_profile_id = l_docs_tab(i).profile_id ;
1717
1718 EXCEPTION
1719 WHEN NO_DATA_FOUND THEN
1720
1721 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1722 print_debuginfo(l_module_name, 'Exception No Data Found Occured For Profile Id: ' || l_docs_tab(i).profile_id);
1723 END IF;
1724 l_profile_id := null;
1725 l_payment_format_cd := null;
1726 l_bepid := null;
1727 l_transmit_protocol_cd := null;
1728 END;
1729 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1730 print_debuginfo(l_module_name, 'Assigning the values in Cache For Profile Id: ' || l_docs_tab(i).profile_id);
1731 END IF;
1732 l_profile_format_tab(l_docs_tab(i).profile_id).profile_id := l_profile_id;
1733 l_profile_format_tab(l_docs_tab(i).profile_id).payment_format_cd := l_payment_format_cd;
1734 l_profile_format_tab(l_docs_tab(i).profile_id).bepid := l_bepid;
1735 l_profile_format_tab(l_docs_tab(i).profile_id).transmit_protocol_cd := l_transmit_protocol_cd;
1736
1737 END IF;
1738 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1739 print_debuginfo(l_module_name, 'Before doing a bulk insert to the cursor');
1740 print_debuginfo(l_module_name, 'Before doing a bulk insert doc_id is ' || l_docs_tab(i).doc_id);
1741 print_debuginfo(l_module_name, 'Before doing a bulk insert pmt_grp_num is ' || l_docs_tab(i).pmt_grp_num);
1742 print_debuginfo(l_module_name, 'Before doing a bulk insert payee_id is ' || l_docs_tab(i).payee_id);
1743 print_debuginfo(l_module_name, 'Before doing a bulk insert pmt_method_cd is ' || l_docs_tab(i).pmt_method_cd);
1744 print_debuginfo(l_module_name, 'Before doing a bulk insert int_bank_acct_id is ' || l_docs_tab(i).int_bank_acct_id);
1745 print_debuginfo(l_module_name, 'Before doing a bulk insert l_payment_format_cd is ' || l_payment_format_cd);
1746 print_debuginfo(l_module_name, 'Before doing a bulk insert l_bepid is ' || l_bepid);
1747 print_debuginfo(l_module_name, 'Before doing a bulk insert l_transmit_protocol_cd is ' || l_transmit_protocol_cd);
1748 print_debuginfo(l_module_name, 'Before doing a bulk insert l_country is ' || l_country);
1749
1750 END IF;
1751 --l_val_set_index = 'DOCUMENT'||'$'||p_payment_method_code||'$'||p_int_bank_acct_id||'$'||p_payment_format_code||'$'||p_bepid||'$'||p_transmit_protocol_code||'$'||p_country;
1752 l_val_set_index := 'DOCUMENT'||'$'||l_docs_tab(i).pmt_method_cd||'$'||To_Char(l_docs_tab(i).int_bank_acct_id)||'$'||l_payment_format_cd||'$'||To_Char(l_bepid)||'$'||l_transmit_protocol_cd||'$'||l_country;
1753 IF (val_set_outer_tbl.EXISTS(l_val_set_index)) THEN
1754 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1755 print_debuginfo(l_module_name, 'The data for the index already exists');
1756
1757
1758 END IF;
1759 l_val_sets_temp_tab := val_set_outer_tbl(l_val_set_index).val_set_tbl;
1760 IF (l_val_sets_temp_tab.count <> 0) THEN
1761 FOR k in l_val_sets_temp_tab.FIRST .. l_val_sets_temp_tab.LAST LOOP
1762 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1763 print_debuginfo(l_module_name, 'Before doing a bulk insert to the cursor and in If loop');
1764 END IF;
1765 l_val_sets_tab(k).doc_id := l_docs_tab(i).doc_id;
1766 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1767 print_debuginfo(l_module_name, 'Before doing a bulk insert doc_id is ' || l_val_sets_tab(k).doc_id);
1768 END IF;
1769 l_val_sets_tab(k).pmt_grp_num := l_docs_tab(i).pmt_grp_num;
1770 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1771 print_debuginfo(l_module_name, 'Before doing a bulk insert pmt_grp_num is ' || l_val_sets_tab(k).pmt_grp_num);
1772 END IF;
1773 l_val_sets_tab(k).payee_id := l_docs_tab(i).payee_id;
1774 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1775 print_debuginfo(l_module_name, 'Before doing a bulk insert payee_id is ' || l_val_sets_tab(k).payee_id);
1776 END IF;
1777 l_val_sets_tab(k).val_set_code := val_set_outer_tbl(l_val_set_index).val_set_tbl(k).val_set_code;
1778 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1779 print_debuginfo(l_module_name, 'Before doing a bulk insert val_set_code is ' || l_val_sets_tab(k).val_set_code);
1780 END IF;
1781 l_val_sets_tab(k).val_code_pkg := val_set_outer_tbl(l_val_set_index).val_set_tbl(k).val_code_pkg;
1782 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1783 print_debuginfo(l_module_name, 'Before doing a bulk insert val_code_pkg is ' || l_val_sets_tab(k).val_code_pkg);
1784 END IF;
1785 l_val_sets_tab(k).val_code_entry_point := val_set_outer_tbl(l_val_set_index).val_set_tbl(k).val_code_entry_point;
1786 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1787 print_debuginfo(l_module_name, 'Before doing a bulk insert val_code_entry_point is ' || l_val_sets_tab(k).val_code_entry_point);
1788 END IF;
1789 l_val_sets_tab(k).val_assign_id := val_set_outer_tbl(l_val_set_index).val_set_tbl(k).val_assign_id;
1790 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1791 print_debuginfo(l_module_name, 'Before doing a bulk insert val_assign_id is ' || l_val_sets_tab(k).val_assign_id);
1792 END IF;
1793 l_val_sets_tab(k).val_assign_entity_type := val_set_outer_tbl(l_val_set_index).val_set_tbl(k).val_assign_entity_type;
1794 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1795 print_debuginfo(l_module_name, 'Before doing a bulk insert val_assign_entity_type is ' || l_val_sets_tab(k).val_assign_entity_type);
1796 END IF;
1797 l_val_sets_tab(k).val_set_name := val_set_outer_tbl(l_val_set_index).val_set_tbl(k).val_set_name;
1798 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1799 print_debuginfo(l_module_name, 'Before doing a bulk insert val_set_name is ' || l_val_sets_tab(k).val_set_name);
1800 END IF;
1801 END LOOP;
1802 ELSE
1803 l_val_sets_tab := val_set_outer_tbl(l_val_set_index).val_set_tbl;
1804 END IF;
1805 l_val_sets_count := val_set_outer_tbl(l_val_set_index).val_set_count;
1806 ELSE
1807 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1808 print_debuginfo(l_module_name, 'Need to query DB again');
1809
1810
1811 END IF;
1812 OPEN c_validation_sets(l_docs_tab(i).doc_id, l_docs_tab(i).pmt_grp_num, l_docs_tab(i).payee_id,
1813 l_docs_tab(i).pmt_method_cd, l_docs_tab(i).int_bank_acct_id, l_payment_format_cd,l_bepid,l_transmit_protocol_cd,l_country);
1814 FETCH c_validation_sets BULK COLLECT INTO l_val_sets_tab;
1815 CLOSE c_validation_sets;
1816 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1817 print_debuginfo(l_module_name, 'After fetching values from the cursor');
1818
1819 END IF;
1820 val_set_outer_tbl(l_val_set_index).val_set_tbl := l_val_sets_tab;
1821 val_set_outer_tbl(l_val_set_index).val_set_count := l_val_sets_tab.count;
1822 l_val_sets_count := l_val_sets_tab.count;
1823 END IF;
1824
1825 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1826 print_debuginfo(l_module_name, 'After doing a bulk insert to the cursor');
1827 print_debuginfo(l_module_name, 'The cursor return count is' || l_val_sets_count);
1828 END IF;
1829 /*
1830 * Exit if no validation sets applicable to this doc were found.
1831 */
1832 IF (l_val_sets_count = 0) THEN
1833
1834 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1835 print_debuginfo(l_module_name, 'No validation sets applicable '
1836 || 'to document payable id '
1837 || l_docs_tab(i).doc_id
1838 || ' were found. Skipping validations for this doc..');
1839
1840 print_debuginfo(l_module_name, '+-------------------------+');
1841
1842 END IF;
1843 ELSE
1844
1845 /*
1846 * Loop through all the applicable validation sets
1847 * for each document
1848 */
1849 FOR j in l_val_sets_tab.FIRST .. l_val_sets_tab.LAST LOOP
1850
1851 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1852 print_debuginfo(l_module_name, 'Applicable validation set ('
1853 || l_val_sets_tab(j).val_assign_entity_type
1854 || ') : '
1855 || l_val_sets_tab(j).val_set_name
1856 );
1857
1858 END IF;
1859 /*
1860 * Dynamically call the corresponding validation code
1861 * entry point.
1862 */
1863 l_stmt := 'CALL '
1864 || l_val_sets_tab(j).val_code_pkg
1865 || '.'
1866 || l_val_sets_tab(j).val_code_entry_point
1867 || '(:1,:2,:3,:4,:5)';
1868
1869 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1870 print_debuginfo(l_module_name, 'Executing ' || l_stmt);
1871
1872 END IF;
1873 EXECUTE IMMEDIATE (l_stmt) USING
1874 IN l_val_sets_tab(j).val_assign_id,
1875 IN l_val_sets_tab(j).val_set_code,
1876 IN l_val_sets_tab(j).doc_id,
1877 IN 'N',
1878 OUT l_result;
1879
1880 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1881 print_debuginfo(l_module_name, 'Finished executing '
1882 || l_stmt);
1883
1884 print_debuginfo(l_module_name, 'Result: '
1885 || l_result);
1886
1887 END IF;
1888 IF (l_result <> 0) THEN
1889 /*
1890 * If document has failed validation, add it to
1891 * list of invalid documents.
1892 */
1893
1894 l_already_failed_flag :=
1895 checkIfDocFailed(l_val_sets_tab(j).doc_id,
1896 l_invalid_docs_tab);
1897
1898 /*
1899 * Add this doc to the list of invalid documents
1900 * only if it is not already present in the
1901 * invalid docs list.
1902 */
1903 IF (l_already_failed_flag = FALSE) THEN
1904
1905 l_invalid_doc_rec.doc_id := l_val_sets_tab(j).doc_id;
1906 l_invalid_doc_rec.pmt_grp_num :=
1907 l_val_sets_tab(j).pmt_grp_num;
1908 l_invalid_doc_rec.payee_id :=
1909 l_val_sets_tab(j).payee_id;
1910 l_invalid_doc_rec.doc_status := DOC_STATUS_REJECTED;
1911 l_invalid_doc_rec.ca_doc_ref_num := l_docs_tab(i).ca_doc_ref_num; -- AWT Enh 16296267
1912
1913 l_invalid_docs_tab(l_invalid_docs_tab.COUNT + 1) :=
1914 l_invalid_doc_rec;
1915
1916 l_doc_failed_flag := TRUE;
1917
1918 /* AWT Enh 16296267 */
1919 IF (l_docs_tab(i).affects_rejection_level = 'Y' ) THEN
1920 l_trx_doc_index := l_docs_tab(i).payee_id;
1921 IF (l_storedAwtPayees.EXISTS(l_trx_doc_index)) then
1922 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1923 print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
1924 END IF;
1925 ELSE
1926 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1927 print_debuginfo(l_module_name, 'Adding Payee:'||l_trx_doc_index||
1928 ' to Invalid Payee Awt List');
1929 END IF;
1930 l_storedAwtPayees(l_trx_doc_index) := l_docs_tab(i).ca_doc_ref_num;
1931 END IF;
1932 END IF;
1933 /*
1934 * Validations sets handle the error messages
1935 * themselves. Therefore, no need to populate
1936 * the error record here.
1937 */
1938
1939 END IF;
1940
1941 ELSE
1942 l_doc_failed_flag := FALSE;
1943
1944 END IF; -- if result <> 0
1945
1946 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1947 print_debuginfo(l_module_name, '+-------------------------+');
1948
1949 END IF;
1950 END LOOP; -- for each validation set
1951
1952 END IF; -- if count of val sets <> 0
1953
1954 /*
1955 * At least one document in the payment request has
1956 * been validated successfully. Keep track of this
1957 * fact; it will be used in updating the status
1958 * of the payment request.
1959 */
1960 IF (l_doc_failed_flag = FALSE) THEN
1961 l_all_docs_failed_flag := FALSE;
1962 END IF;
1963
1964 END LOOP; -- for each document
1965
1966 /*
1967 * Documents within a payment request may be related to each
1968 * other by the 'payment grouping number'. If any document is
1969 * failed, then all it's related documents must also be failed.
1970 *
1971 * If any documents have been failed due to validation
1972 * then make sure to fail it's sister docs.
1973 */
1974 IF (l_invalid_docs_tab.COUNT > 0) THEN
1975 failRelatedDocs(l_docs_tab, l_invalid_docs_tab, l_doc_error_tab,
1976 l_doc_token_tab);
1977 END IF;
1978
1979 /*
1980 * Check if at least one document has failed. This
1981 * information is used when updating the payment
1982 * request status.
1983 */
1984 IF (l_invalid_docs_tab.COUNT > 0) THEN
1985 l_all_docs_success_flag := FALSE;
1986 ELSE
1987 l_all_docs_success_flag := TRUE;
1988 END IF;
1989
1990 /*
1991 * Get the rejection level system option
1992 */
1993 IF (p_doc_rejection_level IS NOT NULL) THEN
1994
1995 /*
1996 * Use the document rejection level passed in
1997 * with the payment service request (if available).
1998 */
1999 l_rejection_level := p_doc_rejection_level;
2000
2001 ELSE
2002
2003 /*
2004 * If the document rejection level is not passed
2005 * in with the payment service request, derive
2006 * the document rejection level setting at the
2007 * enterprise level.
2008 */
2009 l_rejection_level := getDocRejLevelSysOption();
2010
2011 END IF;
2012
2013 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2014 print_debuginfo(l_module_name, 'Rejection level system option: '
2015 || l_rejection_level);
2016
2017 END IF;
2018 /*
2019 * If the rejection level is 'payee', then fail all
2020 * documents for this payee even if a single document
2021 * for this payee has failed.
2022 */
2023 IF (l_all_docs_success_flag = FALSE) THEN
2024
2025 IF (l_rejection_level = REJ_LVL_PAYEE) THEN
2026
2027 failAllDocsForPayee(l_docs_tab, l_invalid_docs_tab,
2028 l_doc_error_tab, l_doc_token_tab);
2029
2030 /*
2031 * Since docs related by payee id have been failed,
2032 * it is possible that some new payment grouping
2033 * no's have been failed as part of this process.
2034 *
2035 * Therefore, again scan all documents and fail
2036 * those that are related by orig doc id.
2037 */
2038 IF (l_invalid_docs_tab.COUNT > 0) THEN
2039 failRelatedDocs(l_docs_tab, l_invalid_docs_tab,
2040 l_doc_error_tab, l_doc_token_tab);
2041 END IF;
2042
2043 END IF;
2044
2045 IF (l_rejection_level = REJ_LVL_DOCUMENT) THEN --AWT Enh 16296267
2046 IF (l_storedAwtPayees.count > 0) THEN
2047 failAllAwtDocs(l_docs_tab, l_invalid_docs_tab,
2048 l_doc_error_tab, l_doc_token_tab);
2049 END IF;
2050 END IF;
2051 END IF;
2052
2053 /*
2054 * All docs of payment request may have been failed because of
2055 * cascaded failures.
2056 *
2057 * Compare the docs in the payment request with the docs in the
2058 * error docs list to see if all have failed or not.
2059 */
2060 l_all_docs_failed_flag := checkIfAllDocsFailed(l_docs_tab,
2061 l_invalid_docs_tab);
2062
2063 /*
2064 * Update the status of the documents and the payment
2065 * request.
2066 */
2067 performDBUpdates(
2068 p_pay_service_request_id,
2069 l_docs_tab,
2070 l_invalid_docs_tab,
2071 l_all_docs_success_flag,
2072 l_all_docs_failed_flag,
2073 l_rejection_level,
2074 l_doc_error_tab,
2075 l_doc_token_tab,
2076 x_return_status
2077 );
2078
2079 /*
2080 * Get attributes from the payment request like
2081 * calling app payred id, calling app id etc.
2082 * These are required to raise business events.
2083 */
2084 getRequestAttributes(p_pay_service_request_id, req_ca_payreq_cd,
2085 req_ca_id);
2086
2087 /*
2088 * Finally, raise business events to inform the calling app
2089 * if any documents have failed.
2090 *
2091 * Note: this should be the last call after database records
2092 * have been inserted / updated. This is because you cannot
2093 * 'rollback' a business event once raised.
2094 */
2095 IF (p_is_singpay_flag = FALSE) THEN
2096
2097 raiseBizEvents(p_pay_service_request_id, req_ca_payreq_cd, req_ca_id,
2098 l_all_docs_success_flag, l_rejection_level);
2099
2100 ELSE
2101
2102 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2103 print_debuginfo(l_module_name, 'Not invoking raiseBizEvents() '
2104 || 'because the request '
2105 || p_pay_service_request_id
2106 || ' is a single payment.'
2107 );
2108
2109 END IF;
2110 END IF;
2111
2112 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2113 print_debuginfo(l_module_name, 'Completed validations for payment '
2114 || 'request :'
2115 || p_pay_service_request_id);
2116
2117 print_debuginfo(l_module_name, 'EXIT');
2118
2119 END IF;
2120 EXCEPTION
2121 WHEN OTHERS THEN
2122 FND_MESSAGE.SET_NAME('IBY', '');
2123 FND_MESSAGE.SET_TOKEN('SQLERR','applyDocumentValidationSets: '
2124 || substr(SQLERRM, 1, 300));
2125 FND_MSG_PUB.Add;
2126
2127 print_debuginfo(l_module_name,substr(SQLERRM, 1, 300),
2128 FND_LOG.LEVEL_UNEXPECTED);
2129
2130 RAISE g_abort_program;
2131
2132 END applyDocumentValidationSets;
2133
2134 /*--------------------------------------------------------------------
2135 | NAME:
2136 | performOnlineValidations
2137 |
2138 | PURPOSE:
2139 | Perform online/immediate validations. Immediate validations
2140 | invoke the same validation sets as deferred validations, but
2141 | errors are returned as warnings and status of the documents
2142 | are not affected.
2143 |
2144 | Online validations are performed on documents individually.
2145 | At the time when online validations are invoked the
2146 | payment request is not yet formed in the calling app.
2147 |
2148 | So this method is invoked for one document at a time by the
2149 | calling app.
2150 |
2151 | PARAMETERS:
2152 | IN
2153 | p_document_id
2154 | the id of the given document.
2155 |
2156 | OUT
2157 | x_return_status
2158 | -1 indicates that the given document has failed
2159 | at least one validation.
2160 | 0 indicates that the given document has passed
2161 | all validations.
2162 |
2163 | RETURNS:
2164 |
2165 | NOTES:
2166 |
2167 *---------------------------------------------------------------------*/
2168 PROCEDURE performOnlineValidations(
2169 p_document_id IN IBY_DOCS_PAYABLE_ALL.document_payable_id%type,
2170 x_return_status IN OUT NOCOPY NUMBER)
2171 IS
2172 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
2173 '.performOnlineValidations';
2174 l_stmt VARCHAR2(200);
2175 l_result NUMBER := 0;
2176 l_validation_failed BOOLEAN := FALSE;
2177
2178 /*
2179 * Pick up validation sets based on method, internal bank
2180 * account and format attributes on the given document.
2181 *
2182 * At the time of online validations, the payment profile
2183 * is not expected to be available. This means that we
2184 * cannot perform online validations based on bank or
2185 * transmission protocol (since these are derived from
2186 * the payment profile).
2187 */
2188
2189 /*
2190 * Fix for bug 5548886:
2191 *
2192 * Add index hint to improve performance.
2193 */
2194 CURSOR
2195 c_val_sets(p_document_payable_id VARCHAR2)
2196 IS
2197 SELECT /*+ INDEX(docs IBY_DOCS_PAYABLE_GT_N1) NO_EXPAND */
2198 docs.document_payable_id,
2199 val.validation_set_code,
2200 val.validation_code_package,
2201 val.validation_code_entry_point,
2202 val_options.validation_assignment_id,
2203 val_options.val_assignment_entity_type,
2204 val.validation_set_display_name
2205 FROM
2206 IBY_VALIDATION_SETS_VL val,
2207 IBY_VAL_ASSIGNMENTS val_options,
2208 IBY_DOCS_PAYABLE_GT docs,
2209 IBY_VALIDATION_VALUES vld_val
2210 WHERE
2211 docs.document_payable_id = p_document_payable_id
2212 AND
2213 val.validation_set_code = val_options.validation_set_code
2214 AND
2215 val.validation_level_code = 'DOCUMENT'
2216 AND (val_options.val_assignment_entity_type = 'METHOD'
2217 AND val_options.assignment_entity_id = docs.payment_method_code
2218 OR val_options.val_assignment_entity_type = 'INTBANKACCOUNT'
2219 AND val_options.assignment_entity_id = docs.internal_bank_account_id
2220 OR val_options.val_assignment_entity_type = 'FORMAT'
2221 AND val_options.assignment_entity_id = docs.payment_format_code
2222 )
2223 AND NVL(val_options.inactive_date, sysdate+1) >= sysdate
2224 AND val_options.validation_assignment_id = vld_val.validation_assignment_id (+)
2225 AND vld_val.validation_parameter_code(+) = 'P_FIELD_NAME'
2226 AND nvl(substr(vld_val.val_param_varchar2_value,1,8),'-1') <> 'INT_BANK'
2227 ;
2228
2229 BEGIN
2230
2231 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2232 print_debuginfo(l_module_name, 'ENTER');
2233
2234 print_debuginfo(l_module_name, 'Document id: '
2235 || p_document_id);
2236
2237 END IF;
2238 /*
2239 * Loop through all applicable validation sets for this
2240 * document.
2241 *
2242 * Validation sets will be picked up based on provided
2243 * document attributes. Almost all the document attributes
2244 * are optional at the time of online validations, so
2245 * it is possible that few/none of the validation sets
2246 * are picked up.
2247 */
2248 FOR valset_rec in c_val_sets(p_document_id) LOOP
2249
2250 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2251 print_debuginfo(l_module_name, 'Applicable validation set ('
2252 || valset_rec.val_assignment_entity_type
2253 || ') : '
2254 || valset_rec.validation_set_display_name
2255 );
2256
2257 END IF;
2258 /*
2259 * Dynamically execute the validation
2260 */
2261 l_stmt := 'CALL '
2262 || valset_rec.validation_code_package
2263 || '.'
2264 || valset_rec.validation_code_entry_point
2265 || '(:1,:2,:3,:4,:5)';
2266
2267 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2268 print_debuginfo(l_module_name, 'Executing '|| l_stmt);
2269
2270 END IF;
2271 EXECUTE IMMEDIATE (l_stmt) USING
2272 IN valset_rec.validation_assignment_id,
2273 IN valset_rec.validation_set_code,
2274 IN valset_rec.document_payable_id,
2275 IN 'Y',
2276 OUT l_result;
2277
2278 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2279 print_debuginfo(l_module_name, 'result: '|| l_result);
2280
2281 END IF;
2282 IF (l_result <> 0) THEN
2283
2284 /*
2285 * If document has failed validation, set the
2286 * validation failed flag. This will be used
2287 * to determine the return status.
2288 */
2289 l_validation_failed := TRUE;
2290
2291 END IF;
2292
2293 END LOOP;
2294
2295 /*
2296 * If even a single validation has failed for this
2297 * document , set the return status to indicate
2298 * validation failure.
2299 */
2300 IF (l_validation_failed = TRUE) THEN
2301 x_return_status := -1;
2302 ELSE
2303 x_return_status := 0;
2304 END IF;
2305
2306 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2307 print_debuginfo(l_module_name, 'Return status before exiting: '
2308 || x_return_status
2309 );
2310
2311 print_debuginfo(l_module_name, 'EXIT');
2312
2313 END IF;
2314 EXCEPTION
2315 WHEN OTHERS THEN
2316 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2317 print_debuginfo(l_module_name, 'Exception occured when attempting '
2318 || 'online validation.'
2319 );
2320 print_debuginfo(l_module_name, 'SQLCODE: ' || SQLCODE);
2321 print_debuginfo(l_module_name, 'SQLERRM: ' || SQLERRM);
2322
2323 END IF;
2324 /*
2325 * Since online validations are really validation warnings,
2326 * set the return status to -1 and exit gracefully.
2327 */
2328 x_return_status := -1;
2329
2330 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2331 print_debuginfo(l_module_name, 'Return status before exiting: '
2332 || x_return_status
2333 );
2334
2335 print_debuginfo(l_module_name, 'EXIT');
2336
2337 END IF;
2338 END performOnlineValidations;
2339
2340 /*--------------------------------------------------------------------
2341 | NAME:
2342 | initDocumentData
2343 |
2344 | PURPOSE:
2345 | Initializes the document record from Oracle Payment's tables.
2346 | All the related fields of a document are picked up including
2347 | Payer/Payee/Payer Bank/Payee Bank.
2348 |
2349 | These fields are populated into the document record and passed
2350 | to the caller (validation sets) as an output parameter.
2351 |
2352 | PARAMETERS:
2353 | IN
2354 |
2355 |
2356 | OUT
2357 |
2358 |
2359 | RETURNS:
2360 |
2361 | NOTES:
2362 |
2363 *---------------------------------------------------------------------*/
2364 PROCEDURE initDocumentData(
2365 p_document_id IN IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE,
2366 x_document_rec IN OUT NOCOPY documentRecType,
2367 p_isOnline IN VARCHAR2
2368 )
2369 IS
2370
2371 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.initDocumentData';
2372
2373 /*
2374 * Cursor for deferred validation.
2375 *
2376 * Pick up all the document fields which need to be validated.
2377 *
2378 * Note: If you modify the fields in the query below, please
2379 * modify the fields in the 'documentRecType' record in the spec
2380 * as well.
2381 */
2382 CURSOR c_documentInfo (p_doc_id
2383 IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE)
2384 RETURN documentRecType
2385 IS
2386 SELECT
2387 docs.calling_app_id ,
2388 docs.calling_app_doc_id1 ,
2389 docs.calling_app_doc_id2 ,
2390 docs.calling_app_doc_id3 ,
2391 docs.calling_app_doc_id4 ,
2392 docs.calling_app_doc_id5 ,
2393 docs.pay_proc_trxn_type_cd ,
2394 docs.document_id ,
2395 docs.document_amount ,
2396 docs.document_pay_currency ,
2397 docs.exclusive_payment_flag ,
2398 docs.delivery_channel_code ,
2399 docs.delivery_chn_format_val ,
2400 docs.unique_remit_id_code ,
2401 docs.payment_reason_comments ,
2402 docs.settlement_priority ,
2403 docs.remittance_message1 ,
2404 docs.remittance_message2 ,
2405 docs.remittance_message3 ,
2406 docs.uri_check_digit ,
2407 docs.external_bank_account_id ,
2408 docs.int_bank_num ,
2409 docs.int_bank_name ,
2410 docs.int_bank_name_alt ,
2411 docs.int_bank_branch_num ,
2412 docs.int_bank_branch_name ,
2413 docs.int_bank_branch_name_alt ,
2414 docs.int_bank_branch_type , -- bug 16007784
2415 docs.int_bank_acc_num ,
2416 docs.int_bank_acc_name ,
2417 docs.int_bank_acc_name_alt ,
2418 docs.int_bank_acc_type ,
2419 docs.int_bank_acc_iban ,
2420 docs.int_bank_acc_curr ,
2421 docs.int_bank_assigned_id1 ,
2422 docs.int_bank_assigned_id2 ,
2423 docs.int_eft_user_number ,
2424 docs.int_bank_acc_chk_dgts ,
2425 docs.int_eft_req_identifier ,
2426 docs.int_bank_acc_short_name ,
2427 docs.int_bank_acc_holder_name ,
2428 docs.int_bank_acc_holder_name_alt ,
2429 docs.payer_le_name ,
2430 docs.payer_le_country ,
2431 docs.payer_phone ,
2432 docs.payer_registration_number ,
2433 docs.payer_tax_registration_number ,
2434 docs.ext_bank_num ,
2435 docs.ext_bank_name ,
2436 docs.ext_bank_name_alt ,
2437 docs.ext_bank_branch_num ,
2438 docs.ext_bank_branch_name ,
2439 docs.ext_bank_branch_name_alt ,
2440 docs.ext_bank_branch_type , -- bug 16007784
2441 docs.ext_bank_country ,
2442 docs.ext_bank_branch_addr1 ,
2443 docs.ext_bank_branch_country ,
2444 docs.ext_bank_acc_num ,
2445 docs.ext_bank_acc_name ,
2446 docs.ext_bank_acc_name_alt ,
2447 docs.ext_bank_acc_type ,
2448 docs.ext_bank_acc_iban ,
2449 docs.ext_bank_acc_chk_dgts ,
2450 docs.ext_bank_acc_short_name ,
2451 docs.ext_bank_acc_holder_name ,
2452 docs.ext_bank_acc_holder_name_alt ,
2453 docs.ext_bank_acc_BIC ,
2454 docs.payee_party_name ,
2455 docs.payee_party_addr1 ,
2456 docs.payee_party_addr2 ,
2457 docs.payee_party_addr3 ,
2458 docs.payee_party_city ,
2459 docs.payee_party_state ,
2460 docs.payee_party_province ,
2461 docs.payee_party_county ,
2462 docs.payee_party_postal ,
2463 docs.payee_party_country ,
2464 docs.bank_charge_bearer ,
2465 docs.payment_reason_code ,
2466 docs.payment_method_cd ,
2467 docs.payee_payment_format_cd ,
2468 docs.payee_party_site_name
2469 FROM
2470 IBY_DOCS_PAYABLE_VAL_GT docs
2471 WHERE
2472 docs.document_id = p_doc_id;
2473
2474
2475 /*
2476 * The cursor for online validation (i.e, immediate validation)
2477 * is similar to the cursor for deferred validation.
2478 * However, only document id is guaranteed to be available.
2479 * Other fields like payer id, payee id, internal bank account id,
2480 * external bank acount id etc. may or may not be provided.
2481 * Therefore, perform an outer join with all entities other than
2482 * the IBY_DOCS_PAYABLE_GT.
2483 */
2484 CURSOR c_onlineDocumentInfo(p_doc_id
2485 IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE)
2486 RETURN documentRecType
2487 IS
2488 SELECT
2489 docs.calling_app_id calling_app_id,
2490 docs.calling_app_doc_unique_ref1 calling_app_doc_id1,
2491 docs.calling_app_doc_unique_ref2 calling_app_doc_id2,
2492 docs.calling_app_doc_unique_ref3 calling_app_doc_id3,
2493 docs.calling_app_doc_unique_ref4 calling_app_doc_id4,
2494 docs.calling_app_doc_unique_ref5 calling_app_doc_id5,
2495 docs.pay_proc_trxn_type_code pay_proc_trxn_type_cd,
2496 docs.document_payable_id document_id,
2497 docs.payment_amount document_amount,
2498 docs.payment_currency_code document_pay_currency,
2499 docs.exclusive_payment_flag exclusive_payment_flag,
2500 docs.delivery_channel_code delivery_channel_code,
2501 del_chn.format_value delivery_chn_format_val,
2502 docs.unique_remittance_identifier unique_remit_id_code,
2503 docs.payment_reason_comments payment_reason_comments,
2504 docs.settlement_priority settlement_priority,
2505 docs.remittance_message1 remittance_message1,
2506 docs.remittance_message2 remittance_message2,
2507 docs.remittance_message3 remittance_message3,
2508 docs.uri_check_digit uri_check_digit,
2509 docs.external_bank_account_id external_bank_account_id,
2510
2511
2512 iba_bnk_branch.bank_number int_bank_num,
2513 iba_bnk_branch.bank_name int_bank_name,
2514 iba_bnk_branch.bank_name_alt int_bank_name_alt,
2515 iba_bnk_branch.branch_number int_bank_branch_num,
2516 iba_bnk_branch.bank_branch_name int_bank_branch_name,
2517 iba_bnk_branch.bank_branch_name_alt int_bank_branch_name_alt,
2518 iba_bnk_branch.bank_branch_type int_bank_branch_type, -- bug 16007784
2519
2520 iba.bank_account_num int_bank_acc_num,
2521 iba.bank_account_name int_bank_acc_name,
2522 iba.bank_account_name_alt int_bank_acc_name_alt,
2523 iba.bank_account_type int_bank_acc_type,
2524 iba.iban_number int_bank_acc_iban,
2525 iba.currency_code int_bank_acc_curr,
2526 '' int_bank_assigned_id1,
2527 '' int_bank_assigned_id2,
2528 iba.eft_user_num int_eft_user_number,
2529 iba.check_digits int_bank_acc_chk_dgts,
2530 iba.eft_requester_identifier int_eft_req_identifier,
2531 iba.short_account_name int_bank_acc_short_name,
2532 iba.account_holder_name int_bank_acc_holder_name,
2533 iba.account_holder_name_alt int_bank_acc_holder_name_alt,
2534
2535 payer.party_legal_name payer_le_name,
2536 payer.party_address_country payer_le_country,
2537 payer.party_phone payer_phone,
2538 payer.party_registration_number payer_registration_number, --added by asarada (SEPA Credit Transfer 3.3)
2539 IBY_FD_EXTRACT_GEN_PVT.
2540 Get_FP_TaxRegistration
2541 (docs.legal_entity_id) payer_tax_registration_number, -- added by asarada (SEPA Credit Transfer 3.3 Changes)
2542
2543 eba.bank_number ext_bank_num,
2544 eba.bank_name ext_bank_name,
2545 eba_bank_branch.bank_name_alt ext_bank_name_alt, --Bug 10133698 - Corrected from NULL fetch
2546 eba.branch_number ext_bank_branch_num,
2547 eba.bank_branch_name ext_bank_branch_name,
2548 eba_bank_branch.bank_branch_name_alt ext_bank_branch_name_alt,
2549 eba_bank_branch.bank_branch_type ext_bank_branch_type, -- bug 16007784
2550 eba.country_code ext_bank_country,
2551 eba_bank_branch.address_line1 ext_bank_branch_addr1,
2552 nvl(eba_bank_branch.country,eba_bank_branch.bank_home_country) ext_bank_branch_country,
2553
2554 eba.bank_account_number ext_bank_acc_num,
2555 eba.bank_account_name ext_bank_acc_name,
2556 eba.alternate_account_name ext_bank_acc_name_alt,
2557 eba.bank_account_type ext_bank_acc_type,
2558 eba.iban_number ext_bank_acc_iban,
2559 eba.check_digits ext_bank_acc_chk_dgts,
2560 eba.short_acct_name ext_bank_acc_short_name,
2561 eba.primary_acct_owner_name ext_bank_acc_holder_name,
2562 '' ext_bank_acc_holder_name_alt,
2563 eba.eft_swift_code ext_eft_swift_code, -- The documentRecType in the ibyvalls.pls was modified
2564 payee.party_name payee_party_name,
2565
2566 /*
2567 * Note regarding bugfix for bug 5997016:
2568 *
2569 * Normally, this cursor c_onlineDocumentInfo, and the cursor
2570 * above c_documentInfo are in sync. This means that both
2571 * cursors pick up the same data except that the
2572 * online document cursor picks up the document attributes
2573 * from IBY_DOCS_PAYABLE_GT whereas the offline
2574 * document validation cursor picks up the document
2575 * attributes from IBY_DOCS_PAYABLE_ALL table.
2576 *
2577 * In fix for bug 5997016, we made the offline doc validation
2578 * cursor pick up the address data dynamically from
2579 * HR or TCA tables depending on the address source column.
2580 *
2581 * In the online validation cursor, we will not propagate
2582 * the same logic. There are some reasons for this -
2583 *
2584 * 1. Some columns that are present in IBY_DOCS_PAYABLE_ALL
2585 * table are not present in IBY_DOCS_PAYABLE_GT table.
2586 * E.g., address_source is not available in the GT table.
2587 * Therefore, to support the dynamic payee address
2588 * functionality we would need to make a data model change.
2589 *
2590 * 2. The online validation API is meant to provide a
2591 * a quick response to the user as the validation is
2592 * called syncronously by the user. By adding complex
2593 * joins, we will be adding a performance penalty to
2594 * online validation.
2595 *
2596 * 3. The intent of online validations is to catch basic
2597 * errors in the document. The payee address validation
2598 * on the document is a corner case, and it is not
2599 * necessary to do this as part of online validation.
2600 *
2601 * The offline validation / batch validation will catch
2602 * these errors. The online validation is meant to be
2603 * simple and quick that targets the basic errors on the
2604 * document.
2605 *
2606 * We will continue to pick up the payee address from
2607 * HZ_LOCATIONS. In the case of employee type payees
2608 * the payee address fields will be null. This is
2609 * fine. The offline validation will catch these
2610 * errors anyway.
2611 */
2612 payee_loc.address1 payee_party_addr1,
2613 payee_loc.address2 payee_party_addr2,
2614 payee_loc.address3 payee_party_addr3,
2615 payee_loc.city payee_party_city,
2616 payee_loc.state payee_party_state,
2617 payee_loc.province payee_party_province,
2618 payee_loc.county payee_party_county,
2619 payee_loc.postal_code payee_party_postal,
2620 payee_loc.country payee_party_country,
2621
2622 docs.bank_charge_bearer bank_charge_bearer,
2623 docs.payment_reason_code payment_reason_code,
2624 docs.payment_method_code payment_method_cd,
2625 docs.payment_format_code payee_payment_format_cd,
2626 payeesite.party_site_name payee_party_site_name
2627
2628 FROM
2629 IBY_DOCS_PAYABLE_GT docs,
2630 IBY_PP_FIRST_PARTY_V payer,
2631 HZ_PARTIES payee,
2632 HZ_PARTY_SITES payeesite,
2633 HZ_LOCATIONS payee_loc,
2634 CE_BANK_ACCOUNTS iba,
2635 CE_BANK_BRANCHES_V iba_bnk_branch,
2636 IBY_EXT_BANK_ACCOUNTS_INT_V eba,
2637 CE_BANK_BRANCHES_V eba_bank_branch,
2638 IBY_DELIVERY_CHANNELS_B del_chn
2639 WHERE
2640 docs.document_payable_id = p_doc_id
2641 AND docs.legal_entity_id = payer.party_legal_id
2642 AND docs.payee_party_id = payee.party_id
2643 AND docs.payee_party_site_id = payeesite.party_site_id (+)
2644 AND payeesite.location_id = payee_loc.location_id(+)
2645 AND docs.internal_bank_account_id = iba.bank_account_id (+)
2646 AND iba_bnk_branch.branch_party_id (+) = iba.bank_branch_id
2647 AND docs.external_bank_account_id = eba.ext_bank_account_id(+)
2648 AND eba.bank_party_id = eba_bank_branch.bank_party_id(+)
2649 AND eba.branch_party_id = eba_bank_branch.branch_party_id(+)
2650 AND docs.delivery_channel_code = del_chn.delivery_channel_code(+)
2651 ;
2652
2653 -- bug 5230187 - Added outer joins to iba and iba_bnk_branch in cursor c_onlineDocumentInfo
2654 /*
2655 * If the c_documentInfo cursor returns no rows, then
2656 * use this cursor to pick up the identifying fields
2657 * of the document. This document will surely fail
2658 * validation, and we need to provide the identifying fields
2659 * to the validation sets.
2660 */
2661 CURSOR c_basicDocumentInfo (p_doc_id
2662 IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE)
2663 RETURN basicDocRecType
2664 IS
2665 SELECT
2666 docs.calling_app_id calling_app_id,
2667 docs.calling_app_doc_unique_ref1 calling_app_doc_id1,
2668 docs.calling_app_doc_unique_ref2 calling_app_doc_id2,
2669 docs.calling_app_doc_unique_ref3 calling_app_doc_id3,
2670 docs.calling_app_doc_unique_ref4 calling_app_doc_id4,
2671 docs.calling_app_doc_unique_ref5 calling_app_doc_id5,
2672 docs.pay_proc_trxn_type_code pay_proc_trxn_type_cd,
2673 docs.document_payable_id document_id
2674 FROM
2675 IBY_DOCS_PAYABLE_ALL docs
2676 WHERE
2677 docs.document_payable_id = p_doc_id
2678 ;
2679
2680 /*
2681 * If the c_onlineDocumentInfo cursor returns no rows, then
2682 * use this cursor to pick up the identifying fields
2683 * of the document. This document will surely fail
2684 * validation, and we need to provide the identifying fields
2685 * to the validation sets.
2686 */
2687 CURSOR c_basicOnlineDocumentInfo (p_doc_id
2688 IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE)
2689 RETURN basicDocRecType
2690 IS
2691 SELECT
2692 docs.calling_app_id calling_app_id,
2693 docs.calling_app_doc_unique_ref1 calling_app_doc_id1,
2694 docs.calling_app_doc_unique_ref2 calling_app_doc_id2,
2695 docs.calling_app_doc_unique_ref3 calling_app_doc_id3,
2696 docs.calling_app_doc_unique_ref4 calling_app_doc_id4,
2697 docs.calling_app_doc_unique_ref5 calling_app_doc_id5,
2698 docs.pay_proc_trxn_type_code pay_proc_trxn_type_cd,
2699 docs.document_payable_id document_id
2700 FROM
2701 IBY_DOCS_PAYABLE_GT docs
2702 WHERE
2703 docs.document_payable_id = p_doc_id
2704 ;
2705
2706 l_no_rows_flag BOOLEAN := FALSE;
2707 basic_doc_rec basicDocRecType;
2708
2709 BEGIN
2710
2711 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2712 print_debuginfo(l_module_name, 'ENTER');
2713 print_debuginfo(l_module_name, 'Picking up document data for: '
2714 || p_document_id);
2715 print_debuginfo(l_module_name, 'p_isOnline: '
2716 || p_isOnline);
2717
2718 END IF;
2719 /*
2720 * If the caller wants to perform an online validation
2721 * pick up the fields of the given document only.
2722 *
2723 * Otherwise, pick up the fields from the document, payer,
2724 * payer bank, payee and payee bank as well.
2725 */
2726 IF (UPPER(p_isOnline) = 'Y') THEN
2727
2728 OPEN c_onlineDocumentInfo(p_document_id);
2729 FETCH c_onlineDocumentInfo INTO x_document_rec;
2730 CLOSE c_onlineDocumentInfo;
2731
2732 /*
2733 * If the fetched doc id is null, it implies
2734 * no rows were found by the cursor.
2735 */
2736 IF (x_document_rec.document_id IS NULL) THEN
2737 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2738 print_debuginfo(l_module_name, 'No rows for online doc');
2739 END IF;
2740 l_no_rows_flag := TRUE;
2741 ELSE
2742 l_no_rows_flag := FALSE;
2743 END IF;
2744
2745 ELSE
2746
2747 OPEN c_documentInfo(p_document_id);
2748 FETCH c_documentInfo INTO x_document_rec;
2749 CLOSE c_documentInfo;
2750
2751 /*
2752 * If the fetched doc id is null, it implies
2753 * no rows were found by the cursor.
2754 */
2755 IF (x_document_rec.document_id IS NULL) THEN
2756 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2757 print_debuginfo(l_module_name, 'No rows for offline doc');
2758 END IF;
2759 l_no_rows_flag := TRUE;
2760 ELSE
2761 l_no_rows_flag := FALSE;
2762 END IF;
2763
2764 END IF;
2765
2766 /*
2767 * We try to get all the document fields required for validation
2768 * by joining with the payee/payer/int bank and ext bank
2769 * tables. If this join fails for some reason, then no
2770 * doc fields will be fetched. This will lead to an empty
2771 * document being returned which causes the program to abort.
2772 *
2773 * In such a case, pick up only the document fields from
2774 * IBY_DOCS_PAYABLE_ALL and pass it back. This document
2775 * will surely fail validation because of the missing fields.
2776 * Since we passed back the basic doc fields, this document
2777 * can be failed in a graceful manner.
2778 */
2779 IF (l_no_rows_flag = TRUE) THEN
2780
2781 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2782 print_debuginfo(l_module_name, 'Unable to find related fields '
2783 || 'for document '
2784 || p_document_id
2785 || '. Only basic document fields will be returned.'
2786 );
2787
2788 END IF;
2789 IF (UPPER(p_isOnline) = 'Y') THEN
2790
2791 OPEN c_basicOnlineDocumentInfo(p_document_id);
2792 FETCH c_basicOnlineDocumentInfo INTO basic_doc_rec;
2793 CLOSE c_basicOnlineDocumentInfo;
2794
2795 ELSE
2796
2797 OPEN c_basicDocumentInfo(p_document_id);
2798 FETCH c_basicDocumentInfo INTO basic_doc_rec;
2799 CLOSE c_basicDocumentInfo;
2800
2801 END IF;
2802
2803 /*
2804 * Copy the basic fields of the doc back into the
2805 * out param record which will be passed to the
2806 * validation sets
2807 */
2808 x_document_rec.calling_app_id := basic_doc_rec.calling_app_id;
2809
2810 x_document_rec.calling_app_doc_id1 :=
2811 basic_doc_rec.calling_app_doc_id1;
2812 x_document_rec.calling_app_doc_id2 :=
2813 basic_doc_rec.calling_app_doc_id2;
2814 x_document_rec.calling_app_doc_id3 :=
2815 basic_doc_rec.calling_app_doc_id3;
2816 x_document_rec.calling_app_doc_id4 :=
2817 basic_doc_rec.calling_app_doc_id4;
2818 x_document_rec.calling_app_doc_id5 :=
2819 basic_doc_rec.calling_app_doc_id5;
2820
2821 x_document_rec.pay_proc_trxn_type_cd :=
2822 basic_doc_rec.pay_proc_trxn_type_cd;
2823 x_document_rec.document_id := basic_doc_rec.document_id;
2824
2825 END IF;
2826
2827 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2828 print_debuginfo(l_module_name, 'EXIT');
2829
2830 END IF;
2831 EXCEPTION
2832 WHEN OTHERS THEN
2833 FND_MESSAGE.SET_NAME('IBY', '');
2834 FND_MESSAGE.SET_TOKEN('SQLERR','initDocumentData : '||
2835 substr(SQLERRM, 1, 300));
2836 FND_MSG_PUB.Add;
2837
2838 print_debuginfo(l_module_name,' '||
2839 substr(SQLERRM, 1, 300), FND_LOG.LEVEL_UNEXPECTED);
2840
2841 RAISE g_abort_program;
2842
2843
2844 END initDocumentData;
2845
2846 /*--------------------------------------------------------------------
2847 | NAME:
2848 | initCharValData
2849 |
2850 | PURPOSE:
2851 | Initializes the character validation record with data from
2852 | Oracle Payment's tables.
2853 |
2854 | Character validation checks if any invalid characters are
2855 | present in the document. So mostly VARCHAR fields are picked
2856 | up (it is not necessary to validate numeric fields for invalid
2857 | characters).
2858 |
2859 | Usually document lines are not sent to the bank, so these are
2860 | not picked up for validation.
2861 |
2862 | PARAMETERS:
2863 | IN
2864 |
2865 |
2866 | OUT
2867 |
2868 |
2869 | RETURNS:
2870 |
2871 | NOTES:
2872 |
2873 *---------------------------------------------------------------------*/
2874 PROCEDURE initCharValData(
2875 p_document_id IN IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE,
2876 x_charval_rec IN OUT NOCOPY charValRecType
2877 )
2878 IS
2879
2880 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.initCharValData';
2881
2882 CURSOR c_charval_fields (p_doc_id IBY_DOCS_PAYABLE_ALL.
2883 document_payable_id%TYPE)
2884 IS
2885 SELECT
2886
2887 /* DOCUMENT RELATED */
2888 doc.document_payable_id,
2889 doc.calling_app_id,
2890 doc.calling_app_doc_unique_ref1,
2891 doc.calling_app_doc_unique_ref2,
2892 doc.calling_app_doc_unique_ref3,
2893 doc.calling_app_doc_unique_ref4,
2894 doc.calling_app_doc_unique_ref5,
2895 doc.pay_proc_trxn_type_code,
2896 doc.calling_app_doc_ref_number,
2897 doc.unique_remittance_identifier,
2898 doc.uri_check_digit,
2899 doc.po_number,
2900 doc.document_description,
2901 doc.bank_assigned_ref_code,
2902 doc.payment_reason_comments,
2903 doc.remittance_message1,
2904 doc.remittance_message2,
2905 doc.remittance_message3,
2906 dlv.format_value,
2907 pmt_reason.format_value,
2908 lines.calling_app_document_line_code,
2909 lines.line_type,
2910 lines.line_name,
2911 lines.description,
2912 lines.unit_of_measure,
2913 lines.po_number,
2914
2915 /* PAYER */
2916 payer.party_number, -- payer number
2917 payer.party_name, -- payer name
2918 payer.party_legal_name, -- payer legal name
2919 payer.party_tax_id, -- payer tax id
2920 payer.party_address_line1, -- payer add line 1
2921 payer.party_address_line2, -- payer add line 2,
2922 payer.party_address_line3, -- payer add line 3
2923 payer.party_address_city, -- payer city
2924 payer.party_address_county , -- payer county
2925 payer.party_address_state, -- payer state
2926 payer.party_address_country, -- payer country
2927 payer.party_address_postal_code, -- payer postal code
2928
2929 /* PAYER BANK */
2930 iba_bnk_branch.bank_name, -- payer bank name
2931 iba_bnk_branch.bank_number, -- payer bank number
2932 iba_bnk_branch.branch_number, -- payer bank branch number
2933 iba_bnk_branch.bank_branch_name, -- payer bank branch name
2934 iba_bnk_branch.eft_swift_code, -- payer bank swift code
2935 iba_bnk_branch.address_line1, -- payer bank add line 1
2936 iba_bnk_branch.address_line2, -- payer bank add line 2
2937 iba_bnk_branch.address_line3, -- payer bank add line 3
2938 iba_bnk_branch.city, -- payer bank city
2939 iba_bnk_branch.province, -- payer bank county
2940 iba_bnk_branch.state, -- payer bank state
2941 nvl(iba_bnk_branch.country,iba_bnk_branch.bank_home_country), -- payer bank country
2942 iba_bnk_branch.zip, -- payer bank postal code
2943 iba_bnk_branch.bank_name_alt, -- payer bank name alt
2944 iba_bnk_branch.bank_branch_name_alt, -- payer bank branch name alt
2945
2946 iba.bank_account_name_alt, -- payer bank acct name alt
2947 iba.bank_account_type, -- payer bank acct type
2948 '', -- payer bank assigned id1
2949 '', -- payer bank assigned id2
2950 iba.eft_user_num, -- payer eft user number
2951 iba.eft_requester_identifier, -- payer eft req identifier
2952 iba.short_account_name, -- payer bank acct short name
2953 iba.account_holder_name_alt, -- payer bank acct holder name alt
2954 iba.account_holder_name, -- payer bank account holder name
2955 iba.bank_account_num, -- payer bank account num
2956 iba.bank_account_name, -- payer bank account name
2957 iba.iban_number, -- payer bank acct iban number
2958 iba.check_digits, -- payer bank acct check digits
2959
2960 /* PAYEE */
2961 payee.party_number, -- payee number
2962 payee.party_name, -- payee name
2963 payee.tax_reference, -- payee tax number
2964 payee_loc.address1, -- payee add line1
2965 payee_loc.address2, -- payee add line2
2966 payee_loc.address3, -- payee add line3
2967 payee_loc.city, -- payee city
2968 payee_loc.county, -- payee county
2969 payee_loc.province, -- payee province
2970 payee_loc.state, -- payee state
2971 payee_loc.country, -- payee country
2972 payee_loc.postal_code, -- payee postal code
2973
2974 /* PAYEE BANK */
2975 eba.bank_name, -- payee bank name
2976 eba.bank_number, -- payee bank number
2977 eba.branch_number, -- payee bank branch number
2978 eba.bank_branch_name, -- payee bank branch name
2979 eba.primary_acct_owner_name, -- payee bank account holder name
2980 eba.bank_account_number, -- payee bank account number
2981 eba.bank_account_name, -- payee bank account name
2982 eba.iban_number, -- payee bank account IBAN
2983 eba.eft_swift_code, -- payee bank swift code
2984 eba.check_digits, -- payee bank account check digits
2985 '', -- payee bank add line 1
2986 '', -- payee bank add line 2
2987 '', -- payee bank add line 3
2988 '', -- payee bank city
2989 '', -- payee bank county
2990 '', -- payee bank state
2991 '', -- payee bank country
2992 '', -- payee bank postal code
2993 '', -- payee bank name alternate
2994 '', -- payee bank branch name alternate
2995 eba.country_code, -- payee bank country code
2996 eba.alternate_account_name, -- payee bank account name alternate
2997 eba.bank_account_type, -- payee bank account type
2998 eba.short_acct_name, -- payee bank account short name
2999 '' -- payee bank acct holder name alt
3000 FROM
3001 /* Document related */
3002 IBY_DOCS_PAYABLE_ALL doc,
3003 IBY_PAYMENT_REASONS_VL pmt_reason,
3004 IBY_DELIVERY_CHANNELS_VL dlv,
3005 IBY_DOCUMENT_LINES lines,
3006 /* Payer */
3007 IBY_PP_FIRST_PARTY_V payer,
3008 /* Payer bank */
3009 CE_BANK_ACCOUNTS iba,
3010 CE_BANK_BRANCHES_V iba_bnk_branch,
3011 /* Payee */
3012 HZ_PARTIES payee,
3013 HZ_LOCATIONS payee_loc,
3014 /* Payee bank */
3015 IBY_EXT_BANK_ACCOUNTS_V eba
3016 WHERE
3017 /* document related */
3018 doc.document_payable_id = p_doc_id
3019 AND doc.payment_reason_code = pmt_reason.payment_reason_code(+)
3020 AND doc.delivery_channel_code = dlv.delivery_channel_code(+)
3021 AND doc.document_payable_id = lines.document_payable_id(+)
3022 /* payer */
3023 AND doc.legal_entity_id = payer.party_legal_id
3024 /* payer bank */
3025 AND doc.internal_bank_account_id = iba.bank_account_id
3026 AND iba_bnk_branch.branch_party_id = iba.bank_branch_id
3027 /* payee */
3028 AND doc.payee_party_id = payee.party_id
3029 AND doc.remit_to_location_id = payee_loc.location_id(+)
3030 /* payee bank */
3031 AND doc.external_bank_account_id = eba.ext_bank_account_id(+)
3032 ;
3033
3034 BEGIN
3035
3036 --
3037 -- Fetching fields from character validation cursor
3038 --
3039 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3040 print_debuginfo(l_module_name, 'Picking up character '
3041 || 'validation fields for: '
3042 || p_document_id);
3043
3044 END IF;
3045 OPEN c_charval_fields(p_document_id);
3046 FETCH c_charval_fields INTO x_charval_rec;
3047 CLOSE c_charval_fields;
3048
3049 EXCEPTION
3050 WHEN OTHERS THEN
3051 FND_MESSAGE.SET_NAME('IBY', '');
3052 FND_MESSAGE.SET_TOKEN('SQLERR','initCharValData: '
3053 || substr(SQLERRM, 1, 300));
3054 FND_MSG_PUB.Add;
3055
3056 print_debuginfo(l_module_name,' '
3057 || substr(SQLERRM, 1, 300), FND_LOG.LEVEL_UNEXPECTED);
3058
3059 RAISE g_abort_program;
3060
3061 END initCharValData;
3062
3063 /*--------------------------------------------------------------------
3064 | NAME:
3065 | initPaymentData
3066 |
3067 | PURPOSE:
3068 | Initializes the payment record from Oracle Payment's tables.
3069 |
3070 | Fields of the payment are picked up and populated into a
3071 | payment record. The validation sets will validate the
3072 | various payment fields.
3073 |
3074 |
3075 | PARAMETERS:
3076 | IN
3077 |
3078 |
3079 | OUT
3080 |
3081 |
3082 | RETURNS:
3083 |
3084 | NOTES:
3085 |
3086 *---------------------------------------------------------------------*/
3087 PROCEDURE initPaymentData(
3088 p_payment_id IN IBY_PAYMENTS_ALL.payment_id%type,
3089 x_payment_rec IN OUT NOCOPY paymentRecType
3090 )
3091 IS
3092
3093 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.initPaymentData';
3094
3095 /*
3096 * Pick up all the Payment fields which need to be validated.
3097 * Note: If any field is modified in the query below, the same
3098 * field in 'paymentRecType' record in the spec should be
3099 * modified accordingly.
3100 */
3101 CURSOR c_payment_rec (p_pay_id IBY_PAYMENTS_ALL.payment_id%TYPE)
3102 RETURN paymentRecType IS
3103 SELECT
3104 pay.payment_id pmt_id,
3105 pay.payment_amount pmt_amount,
3106 pay.payment_currency_code pmt_currency,
3107 pay.delivery_channel_code pmt_delivery_channel_code,
3108 payer.party_address_country pmt_payer_le_country,
3109 pay.payment_details pmt_detail,
3110 0 pmt_payment_reason_count,
3111 pay.int_bank_account_iban int_bank_account_iban,
3112 pay.payer_tax_registration_num payer_tax_registration_num,
3113 pay.payer_le_registration_num payer_le_registration_num,
3114 payer.party_address_line1,
3115 payer.party_address_city,
3116 payer.party_address_postal_code,
3117 payer_bank_acc.currency_code
3118
3119 FROM
3120 IBY_PAYMENTS_ALL pay,
3121 IBY_PP_FIRST_PARTY_V payer,
3122 CE_BANK_ACCOUNTS payer_bank_acc
3123 WHERE
3124 pay.payment_id = p_pay_id
3125 AND
3126 pay.legal_entity_id = payer.party_legal_id
3127 AND
3128 pay.internal_bank_account_id = payer_bank_acc.bank_account_id;
3129
3130 BEGIN
3131
3132 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3133 print_debuginfo(l_module_name, 'Picking up payment data for: '
3134 || p_payment_id);
3135
3136 END IF;
3137 /*
3138 * Fetch the payment related fields
3139 */
3140 OPEN c_payment_rec(p_payment_id);
3141 FETCH c_payment_rec INTO x_payment_rec;
3142
3143 -- Get payment_reason_count (for Belgium)
3144 SELECT count(distinct payment_reason_code)
3145 INTO x_payment_rec.pmt_payment_reason_count
3146 FROM iby_docs_payable_all
3147 WHERE payment_id = p_payment_id;
3148
3149 CLOSE c_payment_rec;
3150
3151 EXCEPTION
3152 WHEN OTHERS THEN
3153 FND_MESSAGE.SET_NAME('IBY', '');
3154 FND_MESSAGE.SET_TOKEN('SQLERR','initPaymentData : '||
3155 substr(SQLERRM, 1, 300));
3156 FND_MSG_PUB.Add;
3157
3158 print_debuginfo(l_module_name,' '||
3159 substr(SQLERRM, 1, 300), FND_LOG.LEVEL_UNEXPECTED);
3160
3161 RAISE g_abort_program;
3162
3163 END initPaymentData;
3164
3165 /*--------------------------------------------------------------------
3166 | NAME:
3167 | initInstructionData
3168 |
3169 | PURPOSE:
3170 | Initializes the instruction record from Oracle Payment's tables.
3171 |
3172 | Fields related to a payment instruction are picked up and
3173 | populated into an instruction record. The validation sets will
3174 | validate individual fields of this record.
3175 |
3176 | PARAMETERS:
3177 | IN
3178 |
3179 |
3180 | OUT
3181 |
3182 |
3183 | RETURNS:
3184 |
3185 | NOTES:
3186 |
3187 *---------------------------------------------------------------------*/
3188 PROCEDURE initInstructionData (
3189 p_instruction_id IN IBY_PAY_INSTRUCTIONS_ALL.
3190 payment_instruction_id%type,
3191 x_instruction_rec IN OUT NOCOPY instructionRecType
3192 )
3193 IS
3194
3195 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.initInstructionData';
3196
3197 /*
3198 * Picking up all the instruction fields which need to be validated.
3199 * Note: If any field is to be modified in the query below, the same
3200 * field in 'instructionRecType' in the spec should be changed accordingly.
3201 */
3202 CURSOR c_instruction_rec (p_instr_id IBY_PAY_INSTRUCTIONS_ALL.
3203 payment_instruction_id%type)
3204 RETURN instructionRecType
3205 IS
3206 SELECT
3207 instr.payment_instruction_id ins_id,
3208 0 ins_amount,
3209 0 ins_document_count
3210 FROM
3211 IBY_PAY_INSTRUCTIONS_ALL instr
3212 WHERE
3213 instr.payment_instruction_id = p_instr_id;
3214
3215 BEGIN
3216
3217 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3218 print_debuginfo(l_module_name, 'Picking up instruction data for: '
3219 || p_instruction_id);
3220
3221 END IF;
3222 /*
3223 * Fetching fields from Payment cursor
3224 */
3225 OPEN c_instruction_rec(p_instruction_id);
3226 FETCH c_instruction_rec INTO x_instruction_rec;
3227
3228 -- Get instruction_amount and document_count
3229 select sum(d.document_amount),
3230 count(d.document_payable_id)
3231 into x_instruction_rec.ins_amount,
3232 x_instruction_rec.ins_document_count
3233 from iby_docs_payable_all d, iby_payments_all p
3234 where p.payment_instruction_id = p_instruction_id
3235 and p.payment_id = d.payment_id
3236
3237 /*
3238 * Fix for bug 5672789:
3239 *
3240 * When calculating payment count for an instruction,
3241 * only pick up payments that are in
3242 * 'INSTRUCTION_CREATED' status.
3243 */
3244 and p.payment_status IN (PAY_STATUS_INS_CRTD)
3245 ;
3246
3247 CLOSE c_instruction_rec;
3248
3249 EXCEPTION
3250 WHEN OTHERS THEN
3251 FND_MESSAGE.SET_NAME('IBY', '');
3252 FND_MESSAGE.SET_TOKEN('SQLERR','initInstructionData : '||
3253 substr(SQLERRM, 1, 300));
3254 FND_MSG_PUB.Add;
3255
3256 print_debuginfo(l_module_name,' '||
3257 substr(SQLERRM, 1, 300), FND_LOG.LEVEL_UNEXPECTED);
3258
3259 RAISE g_abort_program;
3260
3261 END initInstructionData;
3262
3263 /*--------------------------------------------------------------------
3264 | NAME:
3265 | insert_transaction_errors
3266 |
3267 | PURPOSE:
3268 | Inserts the error messages into the errors table. For
3269 | online validations, the error messages are inserted into
3270 | IBY_TRANSACTION_ERRORS_GT; for deferred validations, the
3271 | error messages are inserted into IBY_TRANSACTION_ERRORS
3272 | table.
3273 |
3274 | Validation sets populate the transaction errors into a PLSQL
3275 | table. This method performs a bulk insert of the given records
3276 | into the transaction errors table.
3277 |
3278 | PARAMETERS:
3279 | IN
3280 |
3281 |
3282 | OUT
3283 |
3284 |
3285 | RETURNS:
3286 |
3287 | NOTES:
3288 |
3289 *---------------------------------------------------------------------*/
3290 PROCEDURE insert_transaction_errors(
3291 p_isOnlineVal IN VARCHAR2,
3292 x_docErrorTab IN OUT NOCOPY docErrorTabType,
3293 x_trxnErrTokenTab IN OUT NOCOPY trxnErrTokenTabType
3294 )
3295 IS
3296 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
3297 '.insert_transaction_errors';
3298
3299 /*
3300 * Column types for insertion into IBY_TRANSACTION_ERRORS table.
3301 */
3302 TYPE t_transaction_error_id IS TABLE OF
3303 IBY_TRANSACTION_ERRORS.transaction_error_id%TYPE
3304 INDEX BY BINARY_INTEGER;
3305 TYPE t_transaction_type IS TABLE OF
3306 IBY_TRANSACTION_ERRORS.transaction_type%TYPE
3307 INDEX BY BINARY_INTEGER;
3308 TYPE t_transaction_id IS TABLE OF
3309 IBY_TRANSACTION_ERRORS.transaction_id%TYPE
3310 INDEX BY BINARY_INTEGER;
3311 TYPE t_error_code IS TABLE OF
3312 IBY_TRANSACTION_ERRORS.error_code%TYPE
3313 INDEX BY BINARY_INTEGER;
3314 TYPE t_error_date IS TABLE OF
3315 IBY_TRANSACTION_ERRORS.error_date%TYPE
3316 INDEX BY BINARY_INTEGER;
3317 TYPE t_error_status IS TABLE OF
3318 IBY_TRANSACTION_ERRORS.error_status%TYPE
3319 INDEX BY BINARY_INTEGER;
3320 TYPE t_calling_app_doc_unique_ref1 IS TABLE OF
3321 IBY_TRANSACTION_ERRORS.calling_app_doc_unique_ref1%TYPE
3322 INDEX BY BINARY_INTEGER;
3323 TYPE t_ovrride_allowed_on_err_flg IS TABLE OF
3324 IBY_TRANSACTION_ERRORS.override_allowed_on_error_flag%TYPE
3325 INDEX BY BINARY_INTEGER;
3326 TYPE t_do_not_apply_error_flag IS TABLE OF
3327 IBY_TRANSACTION_ERRORS.do_not_apply_error_flag%TYPE
3328 INDEX BY BINARY_INTEGER;
3329 TYPE t_created_by IS TABLE OF
3330 IBY_TRANSACTION_ERRORS.created_by%TYPE
3331 INDEX BY BINARY_INTEGER;
3332 TYPE t_creation_date IS TABLE OF
3333 IBY_TRANSACTION_ERRORS.creation_date%TYPE
3334 INDEX BY BINARY_INTEGER;
3335 TYPE t_last_updated_by IS TABLE OF
3336 IBY_TRANSACTION_ERRORS.last_updated_by%TYPE
3337 INDEX BY BINARY_INTEGER;
3338 TYPE t_last_update_date IS TABLE OF
3339 IBY_TRANSACTION_ERRORS.last_update_date%TYPE
3340 INDEX BY BINARY_INTEGER;
3341 TYPE t_object_version_number IS TABLE OF
3342 IBY_TRANSACTION_ERRORS.object_version_number%TYPE
3343 INDEX BY BINARY_INTEGER;
3344 TYPE t_last_update_login IS TABLE OF
3345 IBY_TRANSACTION_ERRORS.last_update_login%TYPE
3346 INDEX BY BINARY_INTEGER;
3347 TYPE t_calling_app_id IS TABLE OF
3348 IBY_TRANSACTION_ERRORS.calling_app_id%TYPE
3349 INDEX BY BINARY_INTEGER;
3350 TYPE t_pay_proc_trxn_type_code IS TABLE OF
3351 IBY_TRANSACTION_ERRORS.pay_proc_trxn_type_code%TYPE
3352 INDEX BY BINARY_INTEGER;
3353 TYPE t_calling_app_doc_unique_ref2 IS TABLE OF
3354 IBY_TRANSACTION_ERRORS.calling_app_doc_unique_ref2%TYPE
3355 INDEX BY BINARY_INTEGER;
3356 TYPE t_calling_app_doc_unique_ref3 IS TABLE OF
3357 IBY_TRANSACTION_ERRORS.calling_app_doc_unique_ref3%TYPE
3358 INDEX BY BINARY_INTEGER;
3359 TYPE t_calling_app_doc_unique_ref4 IS TABLE OF
3360 IBY_TRANSACTION_ERRORS.calling_app_doc_unique_ref4%TYPE
3361 INDEX BY BINARY_INTEGER;
3362 TYPE t_calling_app_doc_unique_ref5 IS TABLE OF
3363 IBY_TRANSACTION_ERRORS.calling_app_doc_unique_ref5%TYPE
3364 INDEX BY BINARY_INTEGER;
3365 TYPE t_error_type IS TABLE OF
3366 IBY_TRANSACTION_ERRORS.error_type%TYPE
3367 INDEX BY BINARY_INTEGER;
3368 TYPE t_error_message IS TABLE OF
3369 IBY_TRANSACTION_ERRORS.error_message%TYPE
3370 INDEX BY BINARY_INTEGER;
3371 TYPE t_validation_set_code IS TABLE OF
3372 IBY_TRANSACTION_ERRORS.validation_set_code%TYPE
3373 INDEX BY BINARY_INTEGER;
3374 TYPE t_pass_date IS TABLE OF
3375 IBY_TRANSACTION_ERRORS.pass_date%TYPE
3376 INDEX BY BINARY_INTEGER;
3377 TYPE t_override_justification IS TABLE OF
3378 IBY_TRANSACTION_ERRORS.override_justification%TYPE
3379 INDEX BY BINARY_INTEGER;
3380 TYPE t_override_date IS TABLE OF
3381 IBY_TRANSACTION_ERRORS.override_date%TYPE
3382 INDEX BY BINARY_INTEGER;
3383
3384 l_transaction_error_id t_transaction_error_id;
3385 l_transaction_type t_transaction_type;
3386 l_transaction_id t_transaction_id;
3387 l_error_code t_error_code;
3388 l_error_date t_error_date;
3389 l_error_status t_error_status;
3390 l_calling_app_doc_unique_ref1 t_calling_app_doc_unique_ref1;
3391 l_ovrride_allowed_on_err_flg t_ovrride_allowed_on_err_flg;
3392 l_do_not_apply_error_flag t_do_not_apply_error_flag;
3393 l_created_by t_created_by;
3394 l_creation_date t_creation_date;
3395 l_last_updated_by t_last_updated_by;
3396 l_last_update_date t_last_update_date;
3397 l_object_version_number t_object_version_number;
3398 l_last_update_login t_last_update_login;
3399 l_calling_app_id t_calling_app_id;
3400 l_pay_proc_trxn_type_code t_pay_proc_trxn_type_code;
3401 l_calling_app_doc_unique_ref2 t_calling_app_doc_unique_ref2;
3402 l_calling_app_doc_unique_ref3 t_calling_app_doc_unique_ref3;
3403 l_calling_app_doc_unique_ref4 t_calling_app_doc_unique_ref4;
3404 l_calling_app_doc_unique_ref5 t_calling_app_doc_unique_ref5;
3405 l_error_type t_error_type;
3406 l_error_message t_error_message;
3407 l_validation_set_code t_validation_set_code;
3408 l_pass_date t_pass_date;
3409 l_override_justification t_override_justification;
3410 l_override_date t_override_date;
3411
3412 /*
3413 * Column types for insertion into IBY_TRXN_ERROR_TOKENS table.
3414 */
3415 TYPE t_trxn_error_id IS TABLE OF
3416 IBY_TRXN_ERROR_TOKENS.transaction_error_id%TYPE
3417 INDEX BY BINARY_INTEGER;
3418 TYPE t_token_name IS TABLE OF
3419 IBY_TRXN_ERROR_TOKENS.token_name%TYPE
3420 INDEX BY BINARY_INTEGER;
3421 TYPE t_crtd_by IS TABLE OF
3422 IBY_TRXN_ERROR_TOKENS.created_by%TYPE
3423 INDEX BY BINARY_INTEGER;
3424 TYPE t_crt_date IS TABLE OF
3425 IBY_TRXN_ERROR_TOKENS.creation_date%TYPE
3426 INDEX BY BINARY_INTEGER;
3427 TYPE t_last_updt_by IS TABLE OF
3428 IBY_TRXN_ERROR_TOKENS.last_updated_by%TYPE
3429 INDEX BY BINARY_INTEGER;
3430 TYPE t_last_updt_date IS TABLE OF
3431 IBY_TRXN_ERROR_TOKENS.last_update_date%TYPE
3432 INDEX BY BINARY_INTEGER;
3433 TYPE t_object_ver_number IS TABLE OF
3434 IBY_TRXN_ERROR_TOKENS.object_version_number%TYPE
3435 INDEX BY BINARY_INTEGER;
3436 TYPE t_token_value IS TABLE OF
3437 IBY_TRXN_ERROR_TOKENS.token_value%TYPE
3438 INDEX BY BINARY_INTEGER;
3439 TYPE t_lookup_type_source IS TABLE OF
3440 IBY_TRXN_ERROR_TOKENS.lookup_type_source%TYPE
3441 INDEX BY BINARY_INTEGER;
3442 TYPE t_last_updt_login IS TABLE OF
3443 IBY_TRXN_ERROR_TOKENS.last_update_login%TYPE
3444 INDEX BY BINARY_INTEGER;
3445
3446 l_trxn_error_id t_trxn_error_id;
3447 l_token_name t_token_name;
3448 l_crtd_by t_crtd_by;
3449 l_crt_date t_crt_date;
3450 l_last_updtd_by t_last_updt_by;
3451 l_last_updt_date t_last_updt_date;
3452 l_object_ver_number t_object_ver_number;
3453 l_token_value t_token_value;
3454 l_lookup_type_source t_lookup_type_source;
3455 l_last_updt_login t_last_updt_login;
3456
3457
3458 BEGIN
3459
3460 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3461 print_debuginfo(l_module_name, 'ENTER');
3462
3463 print_debuginfo(l_module_name, 'Online flag: ' || p_isOnlineVal);
3464
3465 END IF;
3466 IF (x_docErrorTab.COUNT > 0) THEN
3467
3468 /*
3469 * Create an array of values for each column. These arrays
3470 * will be used in the bulk insert.
3471 */
3472 FOR i in x_docErrorTab.FIRST..x_docErrorTab.LAST LOOP
3473
3474 l_transaction_error_id(i)
3475 := x_docErrorTab(i).transaction_error_id;
3476 l_transaction_type(i)
3477 := x_docErrorTab(i).transaction_type;
3478 l_transaction_id(i)
3479 := x_docErrorTab(i).transaction_id;
3480 l_error_code(i)
3481 := x_docErrorTab(i).error_code;
3482 l_error_date(i)
3483 := NVL(x_docErrorTab(i).error_date, sysdate);
3484 l_error_status(i)
3485 := NVL(x_docErrorTab(i).error_status, 'ACTIVE');
3486 l_calling_app_doc_unique_ref1(i)
3487 := x_docErrorTab(i).calling_app_doc_unique_ref1;
3488
3489 /*
3490 * Fix for bug 5206309:
3491 *
3492 * For payment instructions, the override
3493 * allowed flag needs to be defaulted to Y
3494 * for the time being.
3495 */
3496 IF (x_docErrorTab(i).transaction_type =
3497 'PAYMENT_INSTRUCTION') THEN
3498
3499 l_ovrride_allowed_on_err_flg(i)
3500 := NVL(x_docErrorTab(i).
3501 override_allowed_on_error_flag,
3502 'Y');
3503
3504 ELSE
3505
3506 l_ovrride_allowed_on_err_flg(i)
3507 := NVL(x_docErrorTab(i).
3508 override_allowed_on_error_flag,
3509 'N');
3510
3511 END IF;
3512
3513 l_do_not_apply_error_flag(i)
3514 := NVL(x_docErrorTab(i).do_not_apply_error_flag, 'N');
3515 l_created_by(i)
3516 := NVL(x_docErrorTab(i).created_by, fnd_global.user_id);
3517 l_creation_date(i)
3518 := NVL(x_docErrorTab(i).creation_date, sysdate);
3519 l_last_updated_by(i)
3520 := NVL(x_docErrorTab(i).last_updated_by,
3521 fnd_global.user_id);
3522 l_last_update_date(i)
3523 := NVL(x_docErrorTab(i).last_update_date, sysdate);
3524 l_object_version_number(i)
3525 := NVL(x_docErrorTab(i).object_version_number, 1);
3526 l_last_update_login(i)
3527 := NVL(x_docErrorTab(i).last_update_login,
3528 fnd_global.user_id);
3529 l_calling_app_id(i)
3530 := x_docErrorTab(i).calling_app_id;
3531 l_pay_proc_trxn_type_code(i)
3532 := x_docErrorTab(i).pay_proc_trxn_type_code;
3533 l_calling_app_doc_unique_ref2(i)
3534 := x_docErrorTab(i).calling_app_doc_unique_ref2;
3535 l_calling_app_doc_unique_ref3(i)
3536 := x_docErrorTab(i).calling_app_doc_unique_ref3;
3537 l_calling_app_doc_unique_ref4(i)
3538 := x_docErrorTab(i).calling_app_doc_unique_ref4;
3539 l_calling_app_doc_unique_ref5(i)
3540 := x_docErrorTab(i).calling_app_doc_unique_ref5;
3541 l_error_type(i)
3542 := NVL(x_docErrorTab(i).error_type, 'VALIDATION');
3543 l_error_message(i)
3544 := x_docErrorTab(i).error_message;
3545 l_validation_set_code(i)
3546 := x_docErrorTab(i).validation_set_code;
3547 l_pass_date(i)
3548 := x_docErrorTab(i).pass_date;
3549 l_override_justification(i)
3550 := x_docErrorTab(i).override_justification;
3551 l_override_date(i)
3552 := x_docErrorTab(i).override_date;
3553
3554 END LOOP;
3555
3556 END IF;
3557
3558 IF (UPPER(p_isOnlineVal) = 'N') THEN
3559
3560 /*
3561 * Insert error messages into IBY_TRANSACTION_ERRORS table.
3562 */
3563
3564 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3565 print_debuginfo(l_module_name, 'Bulk inserting errors into '
3566 || 'IBY_TRANSACTION_ERRORS.');
3567
3568 END IF;
3569 --FORALL i in x_docErrorTab.FIRST..x_docErrorTab.LAST
3570 -- INSERT INTO IBY_TRANSACTION_ERRORS VALUES x_docErrorTab(i);
3571
3572
3573 /*
3574 * Use named columns in bulk insert syntax to avoid any
3575 * dependencies on the order of the columns in the table.
3576 */
3577 FORALL i in x_docErrorTab.FIRST..x_docErrorTab.LAST
3578 INSERT INTO IBY_TRANSACTION_ERRORS
3579 (
3580 transaction_error_id,
3581 transaction_type,
3582 transaction_id,
3583 error_code,
3584 error_date,
3585 error_status,
3586 calling_app_doc_unique_ref1,
3587 override_allowed_on_error_flag,
3588 do_not_apply_error_flag,
3589 created_by,
3590 creation_date,
3591 last_updated_by,
3592 last_update_date,
3593 object_version_number,
3594 last_update_login,
3595 calling_app_id,
3596 pay_proc_trxn_type_code,
3597 calling_app_doc_unique_ref2,
3598 calling_app_doc_unique_ref3,
3599 calling_app_doc_unique_ref4,
3600 calling_app_doc_unique_ref5,
3601 error_type,
3602 error_message,
3603 validation_set_code,
3604 pass_date,
3605 override_justification,
3606 override_date
3607 )
3608 VALUES
3609 (
3610 l_transaction_error_id(i),
3611 l_transaction_type(i),
3612 l_transaction_id(i),
3613 l_error_code(i),
3614 l_error_date(i),
3615 l_error_status(i),
3616 l_calling_app_doc_unique_ref1(i),
3617 l_ovrride_allowed_on_err_flg(i),
3618 l_do_not_apply_error_flag(i),
3619 l_created_by(i),
3620 l_creation_date(i),
3621 l_last_updated_by(i),
3622 l_last_update_date(i),
3623 l_object_version_number(i),
3624 l_last_update_login(i),
3625 l_calling_app_id(i),
3626 l_pay_proc_trxn_type_code(i),
3627 l_calling_app_doc_unique_ref2(i),
3628 l_calling_app_doc_unique_ref3(i),
3629 l_calling_app_doc_unique_ref4(i),
3630 l_calling_app_doc_unique_ref5(i),
3631 l_error_type(i),
3632 l_error_message(i),
3633 l_validation_set_code(i),
3634 l_pass_date(i),
3635 l_override_justification(i),
3636 l_override_date(i)
3637 )
3638 ;
3639
3640 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3641 print_debuginfo(l_module_name, 'Finished populating '
3642 || 'IBY_TRANSACTION_ERRORS.');
3643
3644
3645 END IF;
3646 ELSE
3647
3648 /*
3649 * Insert error messages into IBY_TRANSACTION_ERRORS_GT table.
3650 */
3651
3652 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3653 print_debuginfo(l_module_name, 'Bulk Inserting errors into '
3654 || 'IBY_TRANSACTION_ERRORS_GT.');
3655
3656 END IF;
3657 --FORALL i in x_docErrorTab.FIRST..x_docErrorTab.LAST
3658 -- INSERT INTO IBY_TRANSACTION_ERRORS_GT VALUES x_docErrorTab(i);
3659
3660 /*
3661 * Use named columns in bulk insert syntax to avoid any
3662 * dependencies on the order of the columns in the table.
3663 */
3664 FORALL i in x_docErrorTab.FIRST..x_docErrorTab.LAST
3665 INSERT INTO IBY_TRANSACTION_ERRORS_GT
3666 (
3667 transaction_error_id,
3668 transaction_type,
3669 transaction_id,
3670 error_code,
3671 error_date,
3672 error_status,
3673 calling_app_doc_unique_ref1,
3674 override_allowed_on_error_flag,
3675 do_not_apply_error_flag,
3676 created_by,
3677 creation_date,
3678 last_updated_by,
3679 last_update_date,
3680 object_version_number,
3681 last_update_login,
3682 calling_app_id,
3683 pay_proc_trxn_type_code,
3684 calling_app_doc_unique_ref2,
3685 calling_app_doc_unique_ref3,
3686 calling_app_doc_unique_ref4,
3687 calling_app_doc_unique_ref5,
3688 error_type,
3689 error_message,
3690 validation_set_code,
3691 pass_date,
3692 override_justification,
3693 override_date
3694 )
3695 VALUES
3696 (
3697 l_transaction_error_id(i),
3698 l_transaction_type(i),
3699 l_transaction_id(i),
3700 l_error_code(i),
3701 l_error_date(i),
3702 l_error_status(i),
3703 l_calling_app_doc_unique_ref1(i),
3704 l_ovrride_allowed_on_err_flg(i),
3705 l_do_not_apply_error_flag(i),
3706 l_created_by(i),
3707 l_creation_date(i),
3708 l_last_updated_by(i),
3709 l_last_update_date(i),
3710 l_object_version_number(i),
3711 l_last_update_login(i),
3712 l_calling_app_id(i),
3713 l_pay_proc_trxn_type_code(i),
3714 l_calling_app_doc_unique_ref2(i),
3715 l_calling_app_doc_unique_ref3(i),
3716 l_calling_app_doc_unique_ref4(i),
3717 l_calling_app_doc_unique_ref5(i),
3718 l_error_type(i),
3719 l_error_message(i),
3720 l_validation_set_code(i),
3721 l_pass_date(i),
3722 l_override_justification(i),
3723 l_override_date(i)
3724 )
3725 ;
3726
3727 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3728 print_debuginfo(l_module_name, 'Finished populating '
3729 || 'IBY_TRANSACTION_ERRORS_GT.');
3730
3731
3732 END IF;
3733 END IF; -- p_isOnlineVal = 'N'
3734
3735 /*
3736 * For both online validations and deferred validations,
3737 * error tokens are always inserted into the IBY_TRXN_ERROR_TOKENS
3738 * table.
3739 */
3740
3741 IF (x_trxnErrTokenTab.COUNT > 0) THEN
3742
3743 /*
3744 * Create an array of values for each column. These arrays
3745 * will be used in the bulk insert.
3746 */
3747 FOR j in x_trxnErrTokenTab.FIRST..x_trxnErrTokenTab.LAST LOOP
3748
3749 l_trxn_error_id(j) := x_trxnErrTokenTab(j).
3750 transaction_error_id;
3751 l_token_name(j) := x_trxnErrTokenTab(j).
3752 token_name;
3753 l_crtd_by(j) := NVL(x_trxnErrTokenTab(j).
3754 created_by, fnd_global.user_id);
3755 l_crt_date(j) := NVL(x_trxnErrTokenTab(j).
3756 creation_date, sysdate);
3757 l_last_updtd_by(j) := NVL(x_trxnErrTokenTab(j).
3758 last_updated_by,
3759 fnd_global.user_id);
3760 l_last_updt_date(j) := NVL(x_trxnErrTokenTab(j).
3761 last_update_date, sysdate);
3762 l_object_ver_number(j) := NVL(x_trxnErrTokenTab(j).
3763 object_version_number, 1);
3764 l_token_value(j) := x_trxnErrTokenTab(j).
3765 token_value;
3766 l_lookup_type_source(j) := x_trxnErrTokenTab(j).
3767 lookup_type_source;
3768 l_last_updt_login(j) := NVL(x_trxnErrTokenTab(j).
3769 last_update_login,
3770 fnd_global.user_id);
3771
3772 END LOOP;
3773
3774
3775 --FORALL j in x_trxnErrTokenTab.FIRST..x_trxnErrTokenTab.LAST
3776 -- INSERT INTO IBY_TRXN_ERROR_TOKENS VALUES x_trxnErrTokenTab(j);
3777
3778 FORALL j in x_trxnErrTokenTab.FIRST..x_trxnErrTokenTab.LAST
3779 INSERT INTO IBY_TRXN_ERROR_TOKENS
3780 (
3781 transaction_error_id,
3782 token_name,
3783 created_by,
3784 creation_date,
3785 last_updated_by,
3786 last_update_date,
3787 object_version_number,
3788 token_value,
3789 lookup_type_source,
3790 last_update_login
3791 )
3792 VALUES
3793 (
3794 l_trxn_error_id(j),
3795 l_token_name(j),
3796 l_crtd_by(j),
3797 l_crt_date(j),
3798 l_last_updtd_by(j),
3799 l_last_updt_date(j),
3800 l_object_ver_number(j),
3801 l_token_value(j),
3802 l_lookup_type_source(j),
3803 l_last_updt_login(j)
3804 )
3805 ;
3806
3807 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3808 print_debuginfo(l_module_name, 'Finished populating '
3809 || 'IBY_TRXN_ERROR_TOKENS.');
3810
3811 END IF;
3812 END IF;
3813
3814 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3815 print_debuginfo(l_module_name, 'EXIT');
3816
3817 END IF;
3818 --
3819 -- Need to raise Business Event here with error information
3820 --
3821 EXCEPTION
3822 WHEN OTHERS THEN
3823 FND_MESSAGE.SET_NAME('IBY', '');
3824 FND_MESSAGE.SET_TOKEN('SQLERR',
3825 'insert_transaction_errors : ' || SQLERRM);
3826 FND_MSG_PUB.Add;
3827
3828 print_debuginfo(l_module_name, SQLERRM, FND_LOG.LEVEL_UNEXPECTED);
3829
3830 RAISE g_abort_program;
3831
3832 END insert_transaction_errors;
3833
3834 /*--------------------------------------------------------------------
3835 | NAME:
3836 | insert_transaction_errors
3837 |
3838 | PURPOSE:
3839 | Original procedure that has been overloaded.
3840 |
3841 | PARAMETERS:
3842 | IN
3843 |
3844 |
3845 | OUT
3846 |
3847 |
3848 | RETURNS:
3849 |
3850 | NOTES:
3851 |
3852 *---------------------------------------------------------------------*/
3853 PROCEDURE insert_transaction_errors(
3854 p_isOnlineVal IN VARCHAR2,
3855 x_docErrorTab IN OUT NOCOPY docErrorTabType
3856 )
3857 IS
3858 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
3859 '.insert_transaction_errors';
3860
3861 BEGIN
3862
3863 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3864 print_debuginfo(l_module_name, 'Old Method - ENTER');
3865
3866 END IF;
3867 insert_transaction_errors(p_isOnlineVal, x_docErrorTab,
3868 l_dummy_err_token_tab);
3869
3870 END insert_transaction_errors;
3871
3872 /*--------------------------------------------------------------------
3873 | NAME:
3874 | insertIntoErrorTable
3875 |
3876 | PURPOSE:
3877 | Inserts the document validation errors into PLSQL Table
3878 |
3879 | PARAMETERS:
3880 | IN
3881 |
3882 |
3883 | OUT
3884 |
3885 |
3886 | RETURNS:
3887 |
3888 | NOTES:
3889 |
3890 *---------------------------------------------------------------------*/
3891 PROCEDURE insertIntoErrorTable(
3892 x_docErrorRec IN OUT NOCOPY IBY_TRANSACTION_ERRORS%ROWTYPE,
3893 x_docErrorTab IN OUT NOCOPY docErrorTabType,
3894 x_trxnErrTokenTab IN OUT NOCOPY trxnErrTokenTabType
3895 )
3896 IS
3897
3898 l_transaction_error_id IBY_TRANSACTION_ERRORS.transaction_error_id%TYPE;
3899 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.insertIntoErrorTable';
3900 l_index NUMBER;
3901
3902 BEGIN
3903
3904 print_debuginfo (l_module_name, 'Validation Failed: '
3905 || x_docErrorRec.error_message);
3906
3907 /* Get the next sequence value from IBY_TRANSACTION_ERRORS_S */
3908 IF x_docErrorRec.transaction_error_id IS NULL THEN
3909
3910 SELECT
3911 IBY_TRANSACTION_ERRORS_S.NEXTVAL
3912 INTO
3913 l_transaction_error_id
3914 FROM
3915 DUAL
3916 ;
3917
3918 x_docErrorRec.transaction_error_id := l_transaction_error_id;
3919
3920 ELSE
3921
3922 l_transaction_error_id := x_docErrorRec.transaction_error_id;
3923
3924 END IF;
3925
3926 IF (x_trxnErrTokenTab.COUNT > 0) THEN
3927
3928 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3929 print_debuginfo(l_module_name, 'Token SQL table will be populated.');
3930
3931 END IF;
3932 FOR i in x_trxnErrTokenTab.FIRST..x_trxnErrTokenTab.LAST
3933 LOOP
3934
3935 IF x_trxnErrTokenTab(i).transaction_error_id is NULL THEN
3936 x_trxnErrTokenTab(i).transaction_error_id :=
3937 l_transaction_error_id;
3938 END IF;
3939
3940 END LOOP;
3941
3942 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3943 print_debuginfo(l_module_name, 'Transaction_error_id in token '
3944 || 'SQL table is populated.');
3945
3946 END IF;
3947 END IF;
3948
3949 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3950 print_debuginfo(l_module_name, 'Finished populating the error table.');
3951
3952 END IF;
3953 l_index := x_docErrorTab.COUNT + 1;
3954 x_docErrorTab(l_index) := x_docErrorRec;
3955
3956 /*
3957 * Reset the transaction error id on the x_docErrorRec object.
3958 * The transaction error id is the primary key of the
3959 * IBY_TRANSACTION_ERRORS table and cannot be reused for a
3960 * new error message.
3961 *
3962 * Since it is the callers responsibility to initialize the
3963 * transaction error id (if need be) on x_docErrorRec, we
3964 * can safely reset the transaction error id here.
3965 */
3966 x_docErrorRec.transaction_error_id := null;
3967
3968 END insertIntoErrorTable;
3969
3970 /*
3971 * The original procedure is overloaded
3972 */
3973 PROCEDURE insertIntoErrorTable(
3974 x_docErrorRec IN OUT NOCOPY IBY_TRANSACTION_ERRORS%ROWTYPE,
3975 x_docErrorTab IN OUT NOCOPY docErrorTabType
3976 )
3977 IS
3978
3979 l_transaction_error_id IBY_TRANSACTION_ERRORS.transaction_error_id%TYPE;
3980 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.insertIntoErrorTable';
3981
3982 BEGIN
3983 print_debuginfo (l_module_name, 'Old Method - Validation Failed: '
3984 || x_docErrorRec.error_message);
3985
3986 insertIntoErrorTable(x_docErrorRec, x_docErrorTab, l_dummy_err_token_tab);
3987
3988 END insertIntoErrorTable;
3989
3990 /*--------------------------------------------------------------------
3991 | NAME:
3992 | retrieveErrorMSG
3993 |
3994 | PURPOSE:
3995 | Function to retrieve an error message according to an object
3996 | code and an error message number provided.
3997 |
3998 | PARAMETERS:
3999 | IN
4000 |
4001 |
4002 | OUT
4003 |
4004 |
4005 | RETURNS:
4006 |
4007 | NOTES:
4008 |
4009 *---------------------------------------------------------------------*/
4010 PROCEDURE retrieveErrorMSG (
4011 p_object_code IN fnd_lookups.lookup_code%TYPE,
4012 p_msg_name IN fnd_new_messages.message_name%TYPE,
4013 p_message IN OUT NOCOPY fnd_new_messages.message_text%TYPE
4014 ) IS
4015
4016 l_msg_token fnd_lookups.meaning%TYPE;
4017
4018 BEGIN
4019
4020 -- Retrieve the message token
4021 SELECT meaning
4022 INTO l_msg_token
4023 FROM fnd_lookups
4024 WHERE lookup_type = 'IBY_VALIDATION_FIELDS'
4025 AND lookup_code = p_object_code;
4026
4027 FND_MESSAGE.SET_NAME('IBY', p_msg_name);
4028 FND_MESSAGE.SET_TOKEN('ERR_OBJECT', l_msg_token, false);
4029 p_message := fnd_message.get;
4030
4031 EXCEPTION
4032 WHEN OTHERS THEN
4033 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4034 print_debuginfo(G_PKG_NAME || '.retrieveErrorMSG',
4035 'Fatal: Exception when retrieving a validation error message.');
4036 print_debuginfo(G_PKG_NAME || '.retrieveErrorMSG',
4037 'SQL code: ' || SQLCODE);
4038 print_debuginfo(G_PKG_NAME || '.retrieveErrorMSG',
4039 'SQL err msg: '|| SQLERRM);
4040
4041 END IF;
4042 END retrieveErrorMSG;
4043
4044 /*--------------------------------------------------------------------
4045 | NAME:
4046 | evaluateCondition
4047 |
4048 | PURPOSE:
4049 | Procedure to evaluate a specific condition for a
4050 | particular field on the basis of a token. This will
4051 | minimize code in the Validation entry point procedures.
4052 |
4053 | The possible token values are:
4054 | EQUALSTO, NOTEQUALSTO, NOTNULL, LENGTH, MAXLENGTH,
4055 | MINLENGTH, MIN, MAX, MASK, LIKE, SET, CUSTOM, ASSIGN,
4056 | TYPE.
4057 |
4058 | For token 'CUSTOM', this makes a dynamic PLSQL call to
4059 | a procedure specified in the parameter 'p_value'.
4060 |
4061 | PARAMETERS:
4062 | IN
4063 |
4064 |
4065 | OUT
4066 |
4067 |
4068 | RETURNS:
4069 |
4070 | NOTES:
4071 |
4072 *---------------------------------------------------------------------*/
4073 PROCEDURE evaluateCondition(
4074 p_fieldName IN VARCHAR2,
4075 p_fieldValue IN VARCHAR2,
4076 p_token IN VARCHAR2,
4077 p_char_value IN VARCHAR2,
4078 p_num_value IN NUMBER,
4079 x_valResult OUT NOCOPY BOOLEAN,
4080 x_docErrorRec IN OUT NOCOPY IBY_TRANSACTION_ERRORS%ROWTYPE
4081 )
4082 IS
4083
4084 l_stmt VARCHAR2(200);
4085 l_cnt NUMBER;
4086 l_chr VARCHAR2(1);
4087 l_deliv_cnt NUMBER;
4088 l_temp_num NUMBER;
4089 l_num_flag VARCHAR2(1);
4090 l_lookup_code_cnt NUMBER;
4091 l_error_msg VARCHAR2(2000);
4092 l_transaction_error_id IBY_TRANSACTION_ERRORS.transaction_error_id%TYPE;
4093
4094 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.evaluateCondition';
4095
4096 BEGIN
4097 x_valResult := TRUE;
4098 x_docErrorRec.error_message :='';
4099
4100 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4101 print_debuginfo(l_module_name, 'ENTER');
4102
4103 print_debuginfo(l_module_name, 'Evaluating '
4104 || p_fieldName || ',' || p_fieldValue || ','
4105 || p_token || ',' || p_char_value || ','
4106 || p_num_value);
4107
4108 END IF;
4109 /*
4110 * Fix for bugs 5661094 and 5663530:
4111 *
4112 * Null fields need to be handled correctly. For example,
4113 * when checking whether a value has max length of 140,
4114 * if the value is null, then it must be treated as a
4115 * success.
4116 *
4117 * Most of the validation conditions using length checks
4118 * below will automatically get skipped if the value is null.
4119 *
4120 * The only special case is numeric values. Numeric values
4121 * should be treated as failed if the value is null.
4122 *
4123 * operator data type
4124 * --------- ---------
4125 * EQUALTO - char
4126 * NOTEQUALTO - char
4127 * GRTTHAN - char
4128 * GRTEQUAL - char
4129 * LESSTHAN - char
4130 * LESSEQUAL - char
4131 * ISNULL - any
4132 * NOTNULL - any
4133 * STRIS - char
4134 * STRISNOT - char
4135 * NUMERIC - num
4136 * STARTWITH - char
4137 * NOTSTARTWITH - char
4138 * INSET - char
4139 * INLOOKUPTYPE - char
4140 * DIGITSONLY - char
4141 * NOTINSET - char
4142 * INDELIV - char
4143 * VALID_CH_ESR - char
4144 * MAXLENGTH - char
4145 * MINLENGTH - char
4146 * EXACTLENGTH - char
4147 * MASK - char
4148 * LIKE - char
4149 * CUSTOM - char
4150 *
4151 * In the first if condition below, we treat numeric values
4152 * different from the rest of the data types.
4153 */
4154
4155 --
4156 -- Applying each condition as per the token
4157 --
4158
4159 IF (p_fieldvalue IS NULL and p_token = 'NUMERIC') THEN
4160 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4161 x_docErrorRec.error_message := l_error_msg;
4162 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4163 x_valResult := FALSE;
4164 ELSIF (p_token = 'MAXLENGTH' AND length(p_fieldValue) > p_num_value) THEN
4165 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INC_LENGTH', l_error_msg);
4166 x_docErrorRec.error_message := l_error_msg;
4167 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INC_LENGTH';
4168 x_valResult := FALSE;
4169 ELSIF (p_token = 'MINLENGTH' AND length(p_fieldValue) < p_num_value) THEN
4170 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INC_LENGTH', l_error_msg);
4171 x_docErrorRec.error_message := l_error_msg;
4172 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INC_LENGTH';
4173 x_valResult := FALSE;
4174 ELSIF (p_token = 'EXACTLENGTH' AND length(p_fieldValue) <> p_num_value) THEN
4175 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INC_LENGTH', l_error_msg);
4176 x_docErrorRec.error_message := l_error_msg;
4177 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INC_LENGTH';
4178 x_valResult := FALSE;
4179 ELSIF (p_token = 'EQUALTO' AND to_number(p_fieldValue) <> p_num_value) THEN
4180 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4181 x_docErrorRec.error_message := l_error_msg;
4182 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4183 x_valResult := FALSE;
4184 ELSIF (p_token = 'NOTEQUALTO' AND to_number(p_fieldValue) = p_num_value) THEN
4185 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4186 x_docErrorRec.error_message := l_error_msg;
4187 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4188 x_valResult := FALSE;
4189 ELSIF (p_token = 'GRTTHAN' AND
4190 to_number(p_fieldValue) <= p_num_value) THEN
4191 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4192 x_docErrorRec.error_message := l_error_msg;
4193 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4194 x_valResult := FALSE;
4195 ELSIF (p_token = 'GRTEQUAL' AND
4196 to_number(p_fieldValue) < p_num_value) THEN
4197 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4198 x_docErrorRec.error_message := l_error_msg;
4199 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4200 x_valResult := FALSE;
4201 ELSIF (p_token = 'LESSTHAN' AND
4202 to_number(p_fieldValue) >= p_num_value) THEN
4203 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4204 x_docErrorRec.error_message := l_error_msg;
4205 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4206 x_valResult := FALSE;
4207 ELSIF (p_token = 'LESSEQUAL' AND
4208 to_number(p_fieldValue) > p_num_value) THEN
4209 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_EXCEED_MAX', l_error_msg);
4210 x_docErrorRec.error_message := l_error_msg;
4211 x_docErrorRec.error_code := 'IBY_VALID_OBJ_EXCEED_MAX';
4212 x_valResult := FALSE;
4213 ELSIF (p_token = 'ISNULL' AND p_fieldValue is not NULL) THEN
4214 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_NULL', l_error_msg);
4215 x_docErrorRec.error_message := l_error_msg;
4216 x_docErrorRec.error_code := 'IBY_VALID_OBJ_NULL';
4217 x_valResult := FALSE;
4218 ELSIF (p_token = 'NOTNULL' AND p_fieldValue is NULL) THEN
4219 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_REQUIRED', l_error_msg);
4220 x_docErrorRec.error_message := l_error_msg;
4221 x_docErrorRec.error_code := 'IBY_VALID_OBJ_REQUIRED';
4222 x_valResult := FALSE;
4223 ELSIF (p_token = 'STRIS' AND p_fieldValue <> p_char_value ) THEN
4224 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4225 x_docErrorRec.error_message := l_error_msg;
4226 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4227 x_valResult := FALSE;
4228 ELSIF (p_token = 'STRISNOT' AND p_fieldValue = p_char_value ) THEN
4229 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4230 x_docErrorRec.error_message := l_error_msg;
4231 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4232 x_valResult := FALSE;
4233 ELSIF (p_token = 'NUMERIC') THEN
4234 begin
4235 l_temp_num := to_number(p_fieldValue);
4236 l_num_flag := 'Y';
4237 exception
4238 when others then
4239 l_num_flag := 'N';
4240 end;
4241
4242 IF l_num_flag = 'N' THEN
4243 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_NUM_VALUE', l_error_msg);
4244 x_docErrorRec.error_message := l_error_msg;
4245 x_docErrorRec.error_code := 'IBY_VALID_OBJ_NUM_VALUE';
4246 x_valResult := FALSE;
4247 END IF;
4248 ELSIF (p_token = 'STARTWITH' AND substr(p_fieldValue,1,length(p_char_value)) <> p_char_value ) THEN
4249 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4250 x_docErrorRec.error_message := l_error_msg;
4251 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4252 x_valResult := FALSE;
4253 ELSIF (p_token = 'NOTSTARTWITH' AND substr(p_fieldValue,1,length(p_char_value)) = p_char_value ) THEN
4254 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INCORRECT', l_error_msg);
4255 x_docErrorRec.error_message := l_error_msg;
4256 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INCORRECT';
4257 x_valResult := FALSE;
4258 ELSIF (p_token = 'INSET' AND instr(p_char_value, p_fieldValue) = 0) THEN
4259 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4260 x_docErrorRec.error_message := l_error_msg;
4261 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4262 x_valResult := FALSE;
4263 ELSIF (p_token = 'NOTINSET' AND instr(p_char_value, p_fieldValue) <> 0) THEN
4264 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4265 x_docErrorRec.error_message := l_error_msg;
4266 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4267 x_valResult := FALSE;
4268 ELSIF p_token = 'INDELIV' THEN
4269 select count(*)
4270 into l_deliv_cnt
4271 from iby_delivery_channels_vl
4272 where territory_code = p_char_value
4273 and delivery_channel_code = p_fieldValue
4274 -- and enabled_flag = 'Y'
4275 ;
4276
4277 IF l_deliv_cnt = 0 THEN
4278 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4279 x_docErrorRec.error_message := l_error_msg;
4280 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4281 x_valResult := FALSE;
4282 END IF;
4283 ELSIF (p_token = 'INLOOKUPTYPE') THEN
4284 select count(*)
4285 into l_lookup_code_cnt
4286 from fnd_lookups
4287 where lookup_type = p_char_value
4288 and lookup_code = p_fieldValue;
4289
4290 IF l_lookup_code_cnt = 0 THEN
4291 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4292 x_docErrorRec.error_message := l_error_msg;
4293 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4294 x_valResult := FALSE;
4295 END IF;
4296 ELSIF (p_token = 'DIGITSONLY' and translate(trim(p_fieldValue),'0123456789',' ') <>
4297 rpad(' ', length(trim(p_fieldValue)), ' ') ) THEN
4298 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_NUM_ONLY', l_error_msg);
4299 x_docErrorRec.error_message := l_error_msg;
4300 x_docErrorRec.error_code := 'IBY_VALID_OBJ_NUM_ONLY';
4301 x_valResult := FALSE;
4302 ELSIF (p_token = 'VALID_CH_ESR') THEN
4303 if not validate_CH_EST(p_fieldValue) then
4304 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4305 x_docErrorRec.error_message := l_error_msg;
4306 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4307 x_valResult := FALSE;
4308 end if;
4309 ELSIF (p_token = 'MASK' AND
4310 LENGTH(TRIM(TRANSLATE(p_fieldValue,p_char_value,' ')))=0) THEN
4311 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4312 x_docErrorRec.error_message := l_error_msg;
4313 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4314 x_valResult := FALSE;
4315 ELSIF (p_token = 'CUSTOM') THEN
4316 l_stmt := 'BEGIN '||p_char_value||'(:1,:2,:3); END;';
4317
4318 EXECUTE IMMEDIATE (l_stmt) USING
4319 IN p_fieldName,
4320 IN p_fieldValue,
4321 OUT l_chr;
4322
4323 IF (l_chr <> '0') THEN
4324 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4325 x_docErrorRec.error_message := l_error_msg;
4326 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4327 x_valResult := FALSE;
4328 END IF;
4329 -- the following ELSE is dummy
4330 ELSE
4331 retrieveErrorMSG (p_fieldName, 'IBY_VALID_OBJ_INVALID', l_error_msg);
4332 x_docErrorRec.error_message := l_error_msg;
4333 x_docErrorRec.error_code := 'IBY_VALID_OBJ_INVALID';
4334 END IF;
4335
4336 IF NOT x_valResult THEN
4337
4338 SELECT
4339 IBY_TRANSACTION_ERRORS_S.NEXTVAL
4340 INTO
4341 l_transaction_error_id
4342 FROM
4343 DUAL
4344 ;
4345
4346 x_docErrorRec.transaction_error_id := l_transaction_error_id;
4347
4348 INSERT INTO IBY_TRXN_ERROR_TOKENS
4349 (TRANSACTION_ERROR_ID, TOKEN_NAME, TOKEN_VALUE, LOOKUP_TYPE_SOURCE,
4350 CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE,
4351 LAST_UPDATE_LOGIN, OBJECT_VERSION_NUMBER)
4352 VALUES
4353 (l_transaction_error_id, 'ERR_OBJECT', p_fieldName, 'IBY_VALIDATION_FIELDS',
4354 fnd_global.user_id, sysdate, fnd_global.user_id, sysdate,
4355 fnd_global.user_id, 1);
4356
4357 END IF;
4358
4359 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4360 print_debuginfo(l_module_name, 'EXIT');
4361
4362 END IF;
4363 RETURN;
4364
4365 EXCEPTION
4366 WHEN OTHERS THEN
4367 FND_MESSAGE.SET_NAME('IBY', '');
4368 FND_MESSAGE.SET_TOKEN('SQLERR','evaluateCondition : '||
4369 substr(SQLERRM, 1, 300));
4370 FND_MSG_PUB.Add;
4371
4372 print_debuginfo(l_module_name,' '||
4373 substr(SQLERRM, 1, 300), FND_LOG.LEVEL_UNEXPECTED);
4374
4375 RAISE g_abort_program;
4376
4377 END evaluateCondition;
4378
4379 -- Utility procedures
4380 /*--------------------------------------------------------------------
4381 | NAME:
4382 | getParamValue
4383 |
4384 | PURPOSE:
4385 |
4386 |
4387 | PARAMETERS:
4388 | IN
4389 |
4390 |
4391 | OUT
4392 |
4393 |
4394 | RETURNS:
4395 |
4396 | NOTES:
4397 |
4398 *---------------------------------------------------------------------*/
4399 PROCEDURE getParamValue (
4400 p_validation_assign_id IN IBY_VAL_ASSIGNMENTS.
4401 validation_assignment_id%TYPE,
4402 p_validation_set_code IN IBY_VALIDATION_SETS_VL.
4403 validation_set_code%TYPE,
4404 p_validation_param_code IN IBY_VALIDATION_PARAMS_B.
4405 validation_parameter_code%TYPE,
4406 p_value OUT NOCOPY VARCHAR2)
4407
4408 IS
4409
4410 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.getParamValue';
4411
4412 BEGIN
4413
4414 select decode(vp.validation_parameter_type,
4415 'VARCHAR2', val_param_varchar2_value,
4416 'NUMBER', val_param_number_value,
4417 'DATE', val_param_date_value)
4418 into p_value
4419 from iby_val_assignments va,
4420 iby_validation_values vv,
4421 iby_validation_params_vl vp
4422 where va.validation_set_code = p_validation_set_code
4423 and va.validation_assignment_id = p_validation_assign_id
4424 and va.validation_set_code = vv.validation_set_code
4425 and va.validation_assignment_id = vv.validation_assignment_id
4426 and vv.validation_parameter_code = p_validation_param_code
4427 and vp.validation_set_code = va.validation_set_code
4428 and vp.validation_parameter_code = vv.validation_parameter_code;
4429
4430 /*
4431 * Fix for bug 5262536:
4432 *
4433 * The code below should only be applicable to field names.
4434 * Otherwise, it nulls out the limit value attached to
4435 * a validation set.
4436 *
4437 * Therefore, add an if condition for the block below
4438 * checking for the validation param code P_FIELD_NAME.
4439 */
4440 IF (p_validation_param_code = 'P_FIELD_NAME') THEN
4441 if substr(p_validation_set_code,1,8) = 'RULE_INS' and
4442 substr(p_value,1,4) <> 'INS_' then
4443 p_value := null;
4444 elsif substr(p_validation_set_code,1,8) = 'RULE_PMT' and
4445 substr(p_value,1,4) <> 'PMT_' then
4446 p_value := null;
4447 elsif substr(p_validation_set_code,1,8) = 'RULE_DOC' and
4448 substr(p_value,1,4) in ('INS_', 'PMT_') then
4449 p_value := null;
4450 end if;
4451 END IF;
4452
4453 EXCEPTION
4454 WHEN OTHERS THEN
4455 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4456 print_debuginfo(l_module_name, 'SQLCODE: ' || SQLCODE);
4457 print_debuginfo(l_module_name, 'SQLERRM: ' || SQLERRM);
4458 END IF;
4459 p_value := null;
4460
4461 END getParamValue;
4462
4463 /*--------------------------------------------------------------------
4464 | NAME:
4465 | getDocumentFieldValue
4466 |
4467 | PURPOSE:
4468 |
4469 |
4470 | PARAMETERS:
4471 | IN
4472 |
4473 |
4474 | OUT
4475 |
4476 |
4477 | RETURNS:
4478 |
4479 | NOTES:
4480 |
4481 *---------------------------------------------------------------------*/
4482 PROCEDURE getDocumentFieldValue (
4483 p_field_name IN VARCHAR2,
4484 p_document_rec IN documentRecType,
4485 p_field_value OUT NOCOPY VARCHAR2)
4486 IS
4487
4488 BEGIN
4489 if p_field_name = 'DOCUMENT_ID' then
4490 p_field_value := p_document_rec.document_id;
4491 elsif p_field_name = 'DOCUMENT_AMOUNT' then
4492 p_field_value := p_document_rec.document_amount;
4493 elsif p_field_name = 'DOCUMENT_PAY_CURRENCY' then
4494 p_field_value := p_document_rec.document_pay_currency;
4495 elsif p_field_name = 'EXCLUSIVE_PAYMENT_FLAG' then
4496 p_field_value := p_document_rec.exclusive_payment_flag;
4497 elsif p_field_name = 'DELIVERY_CHANNEL_CODE' then
4498 p_field_value := p_document_rec.delivery_channel_code;
4499 elsif p_field_name = 'UNIQUE_REMIT_ID_CODE' then
4500 p_field_value := p_document_rec.unique_remit_id_code;
4501 elsif p_field_name = 'INT_BANK_NUM' then
4502 p_field_value := p_document_rec.int_bank_num;
4503 elsif p_field_name = 'INT_BANK_NAME' then
4504 p_field_value := p_document_rec.int_bank_name;
4505 elsif p_field_name = 'INT_BANK_NAME_ALT' then
4506 p_field_value := p_document_rec.int_bank_name_alt;
4507 elsif p_field_name = 'INT_BANK_BRANCH_NUM' then
4508 p_field_value := p_document_rec.int_bank_branch_num;
4509 elsif p_field_name = 'INT_BANK_BRANCH_NAME' then
4510 p_field_value := p_document_rec.int_bank_branch_name;
4511 elsif p_field_name = 'INT_BANK_BRANCH_NAME_ALT' then
4512 p_field_value := p_document_rec.int_bank_branch_name_alt;
4513 elsif p_field_name = 'INT_BANK_BRANCH_TYPE' then
4514 p_field_value := p_document_rec.int_bank_branch_type; -- bug 16007784
4515 elsif p_field_name = 'INT_BANK_ACC_NUM' then
4516 p_field_value := p_document_rec.int_bank_acc_num;
4517 elsif p_field_name = 'INT_BANK_ACC_NAME' then
4518 p_field_value := p_document_rec.int_bank_acc_name;
4519 elsif p_field_name = 'INT_BANK_ACC_NAME_ALT' then
4520 p_field_value := p_document_rec.int_bank_acc_name_alt;
4521 elsif p_field_name = 'INT_BANK_ACC_TYPE' then
4522 p_field_value := p_document_rec.int_bank_acc_type;
4523 elsif p_field_name = 'INT_BANK_ACC_IBAN' then
4524 p_field_value := p_document_rec.int_bank_acc_iban;
4525 elsif p_field_name = 'INT_BANK_ACCT_CURR' then
4526 p_field_value := p_document_rec.int_bank_acc_curr;
4527 elsif p_field_name = 'INT_BANK_ASSIGNED_ID1' then
4528 p_field_value := p_document_rec.int_bank_assigned_id1;
4529 elsif p_field_name = 'INT_BANK_ASSIGNED_ID2' then
4530 p_field_value := p_document_rec.int_bank_assigned_id2;
4531 elsif p_field_name = 'INT_EFT_USER_NUMBER' then
4532 p_field_value := p_document_rec.int_eft_user_number;
4533 elsif p_field_name = 'PAYER_LE_NAME' then
4534 p_field_value := p_document_rec.payer_le_name;
4535 elsif p_field_name = 'PAYER_LE_COUNTRY' then
4536 p_field_value := p_document_rec.payer_le_country;
4537 elsif p_field_name = 'PAYER_PHONE' then
4538 p_field_value := p_document_rec.payer_phone;
4539 elsif p_field_name = 'EXT_BANK_NUM' then
4540 p_field_value := p_document_rec.ext_bank_num;
4541 elsif p_field_name = 'EXT_BANK_NAME' then
4542 p_field_value := p_document_rec.ext_bank_name;
4543 elsif p_field_name = 'EXT_BANK_NAME_ALT' then
4544 p_field_value := p_document_rec.ext_bank_name_alt;
4545 elsif p_field_name = 'EXT_BANK_BRANCH_NUM' then
4546 p_field_value := p_document_rec.ext_bank_branch_num;
4547 elsif p_field_name = 'EXT_BANK_BRANCH_NAME' then
4548 p_field_value := p_document_rec.ext_bank_branch_name;
4549 elsif p_field_name = 'EXT_BANK_BRANCH_NAME_ALT' then
4550 p_field_value := p_document_rec.ext_bank_branch_name_alt;
4551 elsif p_field_name = 'EXT_BANK_BRANCH_TYPE' then
4552 p_field_value := p_document_rec.ext_bank_branch_type; -- bug 16007784
4553 elsif p_field_name = 'EXT_BANK_COUNTRY' then
4554 p_field_value := p_document_rec.ext_bank_country;
4555 elsif p_field_name = 'EXT_BANK_BRANCH_COUNTRY' then
4556 p_field_value := p_document_rec.ext_bank_branch_country;
4557 elsif p_field_name = 'EXT_BANK_BRANCH_ADDR1' then
4558 p_field_value := p_document_rec.ext_bank_branch_addr1;
4559 elsif p_field_name = 'EXT_BANK_ACC_NUM' then
4560 p_field_value := p_document_rec.ext_bank_acc_num;
4561 elsif p_field_name = 'EXT_BANK_ACC_NAME' then
4562 p_field_value := p_document_rec.ext_bank_acc_name;
4563 elsif p_field_name = 'EXT_BANK_ACC_NAME_ALT' then
4564 p_field_value := p_document_rec.ext_bank_acc_name_alt;
4565 elsif p_field_name = 'EXT_BANK_ACC_TYPE' then
4566 p_field_value := p_document_rec.ext_bank_acc_type;
4567 elsif p_field_name = 'EXT_BANK_ACC_IBAN' then
4568 p_field_value := p_document_rec.ext_bank_acc_iban;
4569 elsif p_field_name = 'EXT_BANK_ACC_CHK_DGTS' then
4570 p_field_value := p_document_rec.ext_bank_acc_chk_dgts;
4571 elsif p_field_name = 'PAYEE_PARTY_NAME' then
4572 p_field_value := p_document_rec.payee_party_name;
4573 elsif p_field_name = 'PAYEE_PARTY_SITE_ADDR1' then
4574 p_field_value := p_document_rec.payee_party_addr1;
4575 elsif p_field_name = 'EXTERNAL_BANK_ACCOUNT_ID' then
4576 p_field_value := p_document_rec.external_bank_account_id;
4577
4578 /*
4579 * Update by Ramesh:
4580 *
4581 * Change some of the payee address related field names
4582 * because of the way the names are seeded in
4583 * the IBY_VALIDATION_FIELDS lookup.
4584 *
4585 * For example, here the field name is PAYEE_PARTY_CITY
4586 * but in the lookup, it is seeded as PAYEE_PARTY_SITE_CITY.
4587 *
4588 * Because of the mismatch, the field value is returned as
4589 * null and the validation always fails. It is simpler
4590 * to rename the field names here that in the lookup.
4591 *
4592 * Hence changing the payee addredd related field names
4593 * here.
4594 */
4595 elsif p_field_name = 'PAYEE_PARTY_SITE_CITY' then
4596 p_field_value := p_document_rec.payee_party_city;
4597 elsif p_field_name = 'PAYEE_PARTY_SITE_POSTAL' then
4598 p_field_value := p_document_rec. payee_party_postal;
4599 elsif p_field_name = 'PAYEE_PARTY_SITE_COUNTRY' then
4600 p_field_value := p_document_rec.payee_party_country;
4601 elsif p_field_name = 'BANK_CHARGE_BEARER' then
4602 p_field_value := p_document_rec.bank_charge_bearer;
4603 elsif p_field_name = 'PAYMENT_REASON_CODE' then
4604 p_field_value := p_document_rec.payment_reason_code;
4605 elsif p_field_name = 'PAYMENT_METHOD_ID' then
4606 p_field_value := p_document_rec.payment_method_cd;
4607 elsif p_field_name = 'PAYMENT_FORMAT_ID' then
4608 p_field_value := p_document_rec.payment_format_cd;
4609 elsif p_field_name = 'PAYMENT_REASON_COMMENTS' then
4610 p_field_value := p_document_rec.PAYMENT_REASON_COMMENTS;
4611 elsif p_field_name = 'SETTLEMENT_PRIORITY' then
4612 p_field_value := p_document_rec.SETTLEMENT_PRIORITY;
4613 elsif p_field_name = 'REMITTANCE_MESSAGE1' then
4614 p_field_value := p_document_rec.REMITTANCE_MESSAGE1;
4615 elsif p_field_name = 'REMITTANCE_MESSAGE2' then
4616 p_field_value := p_document_rec.REMITTANCE_MESSAGE2;
4617 elsif p_field_name = 'REMITTANCE_MESSAGE3' then
4618 p_field_value := p_document_rec.REMITTANCE_MESSAGE3;
4619 elsif p_field_name = 'URI_CHECK_DIGIT' then
4620 p_field_value := p_document_rec.URI_CHECK_DIGIT;
4621
4622 /*
4623 * Updated by sodash
4624 * for Payee BIC validation
4625 */
4626 elsif p_field_name = 'EXT_EFT_SWIFT_CODE' then
4627 p_field_value := p_document_rec.ext_eft_swift_code;
4628
4629 /*Start of Bug 9704929*/
4630 elsif p_field_name = 'PAYEE_PARTY_SITE_NAME' then
4631 p_field_value := p_document_rec.payee_party_site_name;
4632 /*End of Bug 9704929*/
4633 else
4634 null;
4635 end if;
4636
4637 END getDocumentFieldValue;
4638
4639 /*--------------------------------------------------------------------
4640 | NAME:
4641 | getPaymentFieldValue
4642 |
4643 | PURPOSE:
4644 |
4645 |
4646 | PARAMETERS:
4647 | IN
4648 |
4649 |
4650 | OUT
4651 |
4652 |
4653 | RETURNS:
4654 |
4655 | NOTES:
4656 |
4657 *---------------------------------------------------------------------*/
4658 PROCEDURE getPaymentFieldValue (
4659 p_field_name IN VARCHAR2,
4660 p_payment_rec IN paymentRecType,
4661 p_field_value OUT NOCOPY VARCHAR2)
4662 IS
4663
4664 BEGIN
4665 if p_field_name = 'PMT_ID' then
4666 p_field_value := p_payment_rec.pmt_id;
4667 elsif p_field_name = 'PMT_AMOUNT' then
4668 p_field_value := p_payment_rec.pmt_amount;
4669 elsif p_field_name = 'PMT_CURRENCY' then
4670 p_field_value := p_payment_rec.pmt_currency;
4671 elsif p_field_name = 'PMT_DETAIL' then
4672 p_field_value := p_payment_rec.pmt_detail;
4673 elsif p_field_name = 'PMT_DELIVERY_CHANNEL_CODE' then
4674 p_field_value := p_payment_rec.pmt_delivery_channel_code;
4675 elsif p_field_name = 'PMT_PAYER_LE_COUNTRY' then
4676 p_field_value := p_payment_rec.pmt_payer_le_country;
4677 elsif p_field_name = 'PMT_PAYMENT_REASON_COUNT' then
4678 p_field_value := p_payment_rec.pmt_payment_reason_count;
4679
4680 /*
4681 * Updated by sodash
4682 * Payer IBAN and Payer Address Validations
4683 */
4684 elsif p_field_name = 'INT_BANK_ACC_IBAN' then
4685 p_field_value := p_payment_rec.int_bank_account_iban;
4686 elsif p_field_name = 'PARTY_ADDRESS_LINE1' then
4687 p_field_value := p_payment_rec.party_address_line1;
4688 elsif p_field_name = 'PARTY_ADDRESS_CITY' then
4689 p_field_value := p_payment_rec.party_address_city;
4690 elsif p_field_name = 'PARTY_ADDRESS_POSTAL_CODE' then
4691 p_field_value := p_payment_rec.party_address_postal_code;
4692
4693 else
4694 null;
4695 end if;
4696
4697 END getPaymentFieldValue;
4698
4699 /*--------------------------------------------------------------------
4700 | NAME:
4701 | getInstructionFieldValue
4702 |
4703 | PURPOSE:
4704 |
4705 |
4706 | PARAMETERS:
4707 | IN
4708 |
4709 |
4710 | OUT
4711 |
4712 |
4713 | RETURNS:
4714 |
4715 | NOTES:
4716 |
4717 *---------------------------------------------------------------------*/
4718 PROCEDURE getInstructionFieldValue (
4719 p_field_name IN VARCHAR2,
4720 p_instruction_rec IN instructionRecType,
4721 p_field_value OUT NOCOPY VARCHAR2)
4722 IS
4723
4724 BEGIN
4725 if p_field_name = 'INS_ID' then
4726 p_field_value := p_instruction_rec.ins_id;
4727 elsif p_field_name = 'INS_AMOUNT' then
4728 p_field_value := p_instruction_rec.ins_amount;
4729 elsif p_field_name = 'INS_DOCUMENT_COUNT' then
4730 p_field_value := p_instruction_rec.ins_document_count;
4731 else
4732 null;
4733 end if;
4734
4735 END getInstructionFieldValue;
4736
4737 /*--------------------------------------------------------------------
4738 | NAME:
4739 | getRequestAttributes
4740 |
4741 | PURPOSE:
4742 | Gets the calling app payment service request id, and the
4743 | calling app id for the given payment service request.
4744 |
4745 | PARAMETERS:
4746 | IN
4747 |
4748 | OUT
4749 |
4750 |
4751 | RETURNS:
4752 |
4753 | NOTES:
4754 |
4755 *---------------------------------------------------------------------*/
4756 PROCEDURE getRequestAttributes(
4757 p_payReqId IN IBY_PAY_SERVICE_REQUESTS.payment_service_request_id%TYPE,
4758 x_caPayReqCd IN OUT NOCOPY
4759 IBY_PAY_SERVICE_REQUESTS.call_app_pay_service_req_code%TYPE,
4760 x_caId IN OUT NOCOPY
4761 IBY_PAY_SERVICE_REQUESTS.calling_app_id%TYPE
4762 )
4763 IS
4764 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.getRequestAttributes';
4765 BEGIN
4766
4767 SELECT
4768 call_app_pay_service_req_code,
4769 calling_app_id
4770 INTO
4771 x_caPayReqCd,
4772 x_caId
4773 FROM
4774 IBY_PAY_SERVICE_REQUESTS
4775 WHERE
4776 payment_service_request_id = p_payReqId;
4777
4778 END getRequestAttributes;
4779
4780 /*--------------------------------------------------------------------
4781 | NAME:
4782 | raiseBizEvents
4783 |
4784 | PURPOSE:
4785 | Raises business events to inform the calling app of a change
4786 | in document/payment request status.
4787 |
4788 | The payload for the business event will be an XML clob that
4789 | contains a list of failed documents (or the payment request id
4790 | if the entire request has failed).
4791 |
4792 | PARAMETERS:
4793 | IN
4794 |
4795 | OUT
4796 |
4797 |
4798 | RETURNS:
4799 |
4800 | NOTES:
4801 |
4802 *---------------------------------------------------------------------*/
4803 PROCEDURE raiseBizEvents(
4804 p_payreq_id IN VARCHAR2,
4805 p_cap_payreq_id IN VARCHAR2,
4806 p_cap_id IN NUMBER,
4807 x_allDocsSuccessFlag IN OUT NOCOPY BOOLEAN,
4808 p_rejectionLevel IN VARCHAR2
4809 )
4810 IS
4811
4812 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.raiseBizEvents';
4813 l_xml_clob CLOB;
4814 l_event_name VARCHAR2(200);
4815 l_event_key NUMBER;
4816 l_param_names JTF_VARCHAR2_TABLE_300;
4817 l_param_vals JTF_VARCHAR2_TABLE_300;
4818
4819 l_rej_doc_id_list IBY_DISBURSE_UI_API_PUB_PKG.docPayIDTab;
4820 l_rej_doc_status_list IBY_DISBURSE_UI_API_PUB_PKG.docPayStatusTab;
4821
4822 l_return_status VARCHAR2(500);
4823
4824 BEGIN
4825
4826 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4827 print_debuginfo(l_module_name, 'ENTER');
4828
4829 print_debuginfo(l_module_name, 'Payreq id: '
4830 || p_payreq_id);
4831
4832 END IF;
4833 /*
4834 * Get the rejection level system option
4835 */
4836 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4837 print_debuginfo(l_module_name, 'Rejection level system option: '
4838 || p_rejectionLevel);
4839
4840 END IF;
4841 /*
4842 * These tables are used to pass event keys
4843 * to the business event.
4844 */
4845 l_param_names := JTF_VARCHAR2_TABLE_300();
4846 l_param_vals := JTF_VARCHAR2_TABLE_300();
4847
4848 /*
4849 * The event key uniquely identifies a specific
4850 * occurance of an event. Therefore, it should be
4851 * a sequence number.
4852 */
4853 SELECT IBY_EVENT_KEY_S.nextval INTO l_event_key
4854 FROM DUAL;
4855
4856 IF (p_rejectionLevel = REJ_LVL_REQUEST) THEN
4857
4858 /*
4859 * For request level rejections, even if one
4860 * payment within the request fails, then the
4861 * entire payment request should be failed.
4862 */
4863 IF (x_allDocsSuccessFlag <> TRUE) THEN
4864
4865 /*
4866 * Invoke the callout API with the payment request id.
4867 * This API should trigger the calling application to
4868 * fail the payment request and all it's associated
4869 * docs.
4870 */
4871 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4872 print_debuginfo(l_module_name, 'Going to invoke API call '
4873 || 'remove_payment_request()');
4874
4875 END IF;
4876 /*
4877 * Invoke API to inform calling application
4878 * about the rejected payment request. This API
4879 * will remove all the documents payable in this
4880 * payment request from the processing cycle and
4881 * inform the calling application about this fact.
4882 */
4883 IBY_DISBURSE_UI_API_PUB_PKG.remove_payment_request (
4884 p_payreq_id,
4885 l_return_status
4886 );
4887
4888 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4889 print_debuginfo(l_module_name, 'Return status of '
4890 || 'remove_payment_request() API call: '
4891 || l_return_status,
4892 FND_LOG.LEVEL_UNEXPECTED
4893 );
4894
4895 END IF;
4896 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
4897
4898
4899 print_debuginfo(l_module_name, 'API call did not succeed. '
4900 || 'Aborting build program .. ',
4901 FND_LOG.LEVEL_UNEXPECTED
4902 );
4903
4904
4905 APP_EXCEPTION.RAISE_EXCEPTION;
4906
4907 END IF;
4908
4909 ELSE
4910
4911 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4912 print_debuginfo(l_module_name, 'Not invoking API. '
4913 || ' Reason: All documents were valid.'
4914 );
4915
4916 END IF;
4917 END IF;
4918
4919 ELSIF (p_rejectionLevel = REJ_LVL_DOCUMENT OR
4920 p_rejectionLevel = REJ_LVL_PAYEE) THEN
4921 /*
4922 * Invoke an API call with the list of failed
4923 * documents. This API call should trigger the
4924 * calling app to fail these docs.
4925 */
4926
4927 /*
4928 * Select all docs that:
4929 * 1. Have the given pay req id
4930 * 2. Are not in 'validated' status
4931 */
4932 getRejectedDocs(p_payreq_id, l_rej_doc_id_list,
4933 l_rej_doc_status_list);
4934
4935 IF (l_rej_doc_id_list.COUNT = 0) THEN
4936
4937 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4938 print_debuginfo(l_module_name, 'Not invoking API '
4939 || ' because all documents were '
4940 || ' successfully validated. So no failed documents '
4941 || ' to notify.'
4942 );
4943
4944 END IF;
4945 ELSE
4946
4947 print_debuginfo(l_module_name, 'Printing list of failed '
4948 || 'documents');
4949
4950 FOR i IN l_rej_doc_id_list.FIRST .. l_rej_doc_id_list.LAST LOOP
4951
4952 print_debuginfo(l_module_name, 'Doc id: '
4953 || l_rej_doc_id_list(i)
4954 || ', doc status: '
4955 || l_rej_doc_status_list(i)
4956 );
4957
4958 END LOOP;
4959
4960 /*
4961 * Invoke API to inform calling application
4962 * about the rejected documents.
4963 */
4964 IBY_DISBURSE_UI_API_PUB_PKG.remove_documents_payable (
4965 l_rej_doc_id_list,
4966 l_rej_doc_status_list,
4967 l_return_status
4968 );
4969
4970 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4971 print_debuginfo(l_module_name, 'Return status of '
4972 || 'remove_documents_payable() API call: '
4973 || l_return_status,
4974 FND_LOG.LEVEL_UNEXPECTED
4975 );
4976
4977 END IF;
4978 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
4979
4980
4981 print_debuginfo(l_module_name, 'API call did not succeed. '
4982 || 'Aborting build program .. ',
4983 FND_LOG.LEVEL_UNEXPECTED
4984 );
4985
4986
4987 APP_EXCEPTION.RAISE_EXCEPTION;
4988
4989 END IF;
4990
4991 END IF;
4992
4993 ELSIF (p_rejectionLevel = REJ_LVL_NONE) THEN
4994
4995 /*
4996 * Rejection level NONE means that manual intervention
4997 * is required in case any documents in the payment
4998 * service request have failed.
4999 *
5000 * Therefore, raise a business event for this rejection level
5001 * only if at least one document payable has failed in the
5002 * request.
5003 */
5004
5005 l_event_name :=
5006 'oracle.apps.iby.buildprogram.validation.notify_user_error';
5007
5008 IF (x_allDocsSuccessFlag <> TRUE) THEN
5009
5010 /*
5011 * Raise a business event with the payment request id.
5012 * This business event should inform the user that
5013 * at least some documents payable have failed. This
5014 * should cause the user to manually review the failed
5015 * documents via the UI and take corrective action.
5016 */
5017 l_param_names.EXTEND;
5018 l_param_vals.EXTEND;
5019 l_param_names(1) := 'calling_app_id';
5020 l_param_vals(1) := p_cap_id;
5021
5022 l_param_names.EXTEND;
5023 l_param_vals.EXTEND;
5024 l_param_names(1) := 'pay_service_request_id';
5025 l_param_vals(1) := p_cap_payreq_id;
5026
5027 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5028 print_debuginfo(l_module_name, 'Going to raise biz event '
5029 || l_event_name);
5030
5031 END IF;
5032 iby_workflow_pvt.raise_biz_event(l_event_name, l_event_key,
5033 l_param_names, l_param_vals);
5034
5035 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5036 print_debuginfo(l_module_name, 'Raised biz event '
5037 || l_event_name || ' with key '
5038 || l_event_key || '.');
5039
5040 END IF;
5041 ELSE
5042
5043 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5044 print_debuginfo(l_module_name, 'Not raising biz event '
5045 || l_event_name || '. Reason: All documents '
5046 || 'were valid.');
5047
5048 END IF;
5049 END IF;
5050
5051 ELSE
5052
5053
5054 print_debuginfo(l_module_name, 'Unknown rejection level: '
5055 || p_rejectionLevel
5056 || '. Aborting payment creation ..',
5057 FND_LOG.LEVEL_UNEXPECTED
5058 );
5059
5060
5061 APP_EXCEPTION.RAISE_EXCEPTION;
5062
5063 END IF;
5064
5065 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5066 print_debuginfo(l_module_name, 'EXIT');
5067
5068 END IF;
5069 EXCEPTION
5070 WHEN OTHERS THEN
5071
5072 print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
5073 || 'to raise business event.', FND_LOG.LEVEL_UNEXPECTED);
5074 print_debuginfo(l_module_name, 'SQL code: ' || SQLCODE,
5075 FND_LOG.LEVEL_UNEXPECTED);
5076 print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
5077 FND_LOG.LEVEL_UNEXPECTED);
5078
5079
5080 /*
5081 * Propogate exception to caller.
5082 */
5083 RAISE;
5084
5085 END raiseBizEvents;
5086
5087 /*--------------------------------------------------------------------
5088 | NAME:
5089 | failRelatedDocs
5090 |
5091 | PURPOSE:
5092 | Fail all documents related to an already rejected document.
5093 | Documents are related to each other by the 'payment grouping number'
5094 | field.
5095 |
5096 | PARAMETERS:
5097 | IN
5098 | p_allDocsTab List of all documents within this payment request
5099 |
5100 | IN/OUT
5101 | x_failedDocsTab List of documents from this payment request that
5102 | have failed validation. When this procedure
5103 | completes, all documents that are related to
5104 | the documents in this list will also be marked
5105 | as failed and added to this list
5106 |
5107 | RETURNS:
5108 |
5109 | NOTES:
5110 |
5111 *---------------------------------------------------------------------*/
5112 PROCEDURE failRelatedDocs(
5113 p_allDocsTab IN docPayTabType,
5114 x_failedDocsTab IN OUT NOCOPY docStatusTabType,
5115 x_docErrorTab IN OUT NOCOPY docErrorTabType,
5116 x_errTokenTab IN OUT NOCOPY trxnErrTokenTabType
5117 )
5118 IS
5119
5120 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
5121 '.failRelatedDocs';
5122
5123 l_newlyFailedDocsTab docStatusTabType;
5124 l_invalidDocRec docStatusRecType;
5125 --l_doc_err_rec docErrorRecType;
5126 l_doc_err_rec IBY_TRANSACTION_ERRORS%ROWTYPE;
5127
5128 TYPE pmtGrpNumTabType is TABLE OF
5129 IBY_DOCS_PAYABLE_ALL.payment_grouping_number%TYPE
5130 INDEX BY BINARY_INTEGER;
5131
5132 l_storedPmtGrpNumTab pmtGrpNumTabType;
5133 l_already_processed_flag BOOLEAN := FALSE;
5134 l_already_failed_flag BOOLEAN := FALSE;
5135
5136 BEGIN
5137
5138 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5139 print_debuginfo(l_module_name, 'ENTER');
5140
5141 END IF;
5142 FOR i in x_failedDocsTab.FIRST .. x_failedDocsTab.LAST LOOP
5143
5144 IF (x_failedDocsTab(i).doc_status <> DOC_STATUS_RELN_FAIL) THEN
5145
5146 /*
5147 * First check, if we have already processed this payment
5148 * grouping number. If yes, then skip to the next document.
5149 */
5150 l_already_processed_flag := FALSE;
5151 IF (l_storedPmtGrpNumTab.COUNT <> 0) THEN
5152 FOR k in l_storedPmtGrpNumTab.FIRST .. l_storedPmtGrpNumTab.LAST
5153 LOOP
5154
5155 IF (x_failedDocsTab(i).pmt_grp_num =
5156 l_storedPmtGrpNumTab(k)) THEN
5157 l_already_processed_flag := TRUE;
5158 EXIT;
5159 END IF;
5160
5161 END LOOP;
5162 END IF;
5163
5164 IF (l_already_processed_flag <> TRUE) THEN
5165
5166 /*
5167 * Loop through all the documents for this request,
5168 * failing any documents that have the same orig
5169 * doc id of the failed doc.
5170 */
5171 FOR j in p_allDocsTab.FIRST .. p_allDocsTab.LAST LOOP
5172
5173 IF (x_failedDocsTab(i).doc_id <> p_allDocsTab(j).doc_id)
5174 THEN
5175
5176 IF (x_failedDocsTab(i).pmt_grp_num =
5177 p_allDocsTab(j).pmt_grp_num) THEN
5178
5179 /*
5180 * Check if this doc has already failed and
5181 * been stored in the error docs list. If
5182 * it has already been failed, skip it.
5183 */
5184 l_already_failed_flag :=
5185 checkIfDocFailed(p_allDocsTab(j).doc_id,
5186 x_failedDocsTab);
5187
5188 IF (l_already_failed_flag = FALSE) THEN
5189
5190 /*
5191 * Add this document to list of docs
5192 * failed by relation
5193 */
5194 l_invalidDocRec.doc_id
5195 := p_allDocsTab(j).doc_id;
5196 l_invalidDocRec.pmt_grp_num :=
5197 p_allDocsTab(j).pmt_grp_num;
5198 l_invalidDocRec.payee_id :=
5199 p_allDocsTab(j).payee_id;
5200 l_invalidDocRec.doc_status :=
5201 DOC_STATUS_RELN_FAIL;
5202 l_invalidDocRec.ca_doc_ref_num :=
5203 p_allDocsTab(i).ca_doc_ref_num; --AWT Enh 16296267
5204
5205 l_newlyFailedDocsTab(
5206 l_newlyFailedDocsTab.COUNT + 1) :=
5207 l_invalidDocRec;
5208
5209 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5210 print_debuginfo(l_module_name, 'Cascaded doc '
5211 || 'failure: '
5212 || x_failedDocsTab(i).doc_id
5213 || ' -> '
5214 || p_allDocsTab(j).doc_id
5215 || '. Related by '
5216 || x_failedDocsTab(i).pmt_grp_num
5217 || '.'
5218 );
5219
5220 END IF;
5221 /*
5222 * Once we fail a doc, we must add a
5223 * corresponding error message to the
5224 * error table.
5225 */
5226 IBY_BUILD_UTILS_PKG.createErrorRecord(
5227 TRXN_TYPE_DOC,
5228 p_allDocsTab(j).doc_id,
5229 l_invalidDocRec.doc_status,
5230 p_allDocsTab(j).ca_id,
5231 p_allDocsTab(j).ca_doc_id1,
5232 p_allDocsTab(j).ca_doc_id2,
5233 p_allDocsTab(j).ca_doc_id3,
5234 p_allDocsTab(j).ca_doc_id4,
5235 p_allDocsTab(j).ca_doc_id5,
5236 p_allDocsTab(j).pp_tt_cd,
5237 l_doc_err_rec,
5238 x_errTokenTab,
5239 x_failedDocsTab(i).ca_doc_ref_num
5240 );
5241
5242 insertIntoErrorTable(l_doc_err_rec,
5243 x_docErrorTab, x_errTokenTab);
5244
5245 END IF; -- not already failed
5246
5247 END IF;
5248
5249 END IF;
5250
5251 END LOOP; -- for each doc in request
5252
5253 /*
5254 * Once we have processed all documents which have this
5255 * orig doc id, we must not re-process them if there is
5256 * another error doc with the same orig doc id.
5257 *
5258 * Therefore, store the processed orig doc id. We will
5259 * skip any future error docs that have the same orig
5260 * doc id.
5261 */
5262 l_storedPmtGrpNumTab(l_storedPmtGrpNumTab.COUNT + 1) :=
5263 x_failedDocsTab(i).pmt_grp_num;
5264
5265 END IF; -- not already processed
5266
5267 END IF;
5268
5269 END LOOP; -- for all failed documents
5270
5271 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5272 print_debuginfo(l_module_name, 'Total # related docs failed: '
5273 || l_newlyFailedDocsTab.COUNT);
5274
5275 END IF;
5276 /*
5277 * Copy all the newly failed documents back into the
5278 * original failed documents table. The original failed
5279 * docs table will be used to update the database.
5280 */
5281 IF (l_newlyFailedDocsTab.COUNT <> 0) THEN
5282 FOR i in l_newlyFailedDocsTab.FIRST .. l_newlyFailedDocsTab.LAST LOOP
5283 x_failedDocsTab(x_failedDocsTab.COUNT + 1) :=
5284 l_newlyFailedDocsTab(i);
5285 END LOOP;
5286 END IF;
5287
5288 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5289 print_debuginfo(l_module_name, 'EXIT');
5290
5291 END IF;
5292 END failRelatedDocs;
5293
5294 /*--------------------------------------------------------------------
5295 | NAME:
5296 | failAllDocsForPayee
5297 |
5298 | PURPOSE:
5299 | Fail all documents that have the same payee id of an already
5300 | rejected document. This is needed for 'payee level rejections'.
5301 |
5302 |
5303 | PARAMETERS:
5304 | IN
5305 | p_allDocsTab List of all documents within this payment request
5306 |
5307 | IN/OUT
5308 | x_failedDocsTab List of documents from this payment request that
5309 | have failed validation. When this procedure
5310 | completes, all documents that are related to
5311 | the documents in this list by payee id will also
5312 | be marked as failed and added to this list
5313 |
5314 | RETURNS:
5315 |
5316 | NOTES:
5317 |
5318 *---------------------------------------------------------------------*/
5319 PROCEDURE failAllDocsForPayee(
5320 p_allDocsTab IN docPayTabType,
5321 x_failedDocsTab IN OUT NOCOPY docStatusTabType,
5322 x_docErrorTab IN OUT NOCOPY docErrorTabType,
5323 x_errTokenTab IN OUT NOCOPY trxnErrTokenTabType
5324 )
5325 IS
5326
5327 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
5328 '.failAllDocsForPayee';
5329
5330 l_newlyFailedDocsTab docStatusTabType;
5331 l_invalidDocRec docStatusRecType;
5332 l_doc_err_rec IBY_TRANSACTION_ERRORS%ROWTYPE;
5333 l_doc_token_tab trxnErrTokenTabType;
5334
5335 TYPE payeeTabType is TABLE OF
5336 IBY_DOCS_PAYABLE_ALL.ext_payee_id%TYPE
5337 INDEX BY BINARY_INTEGER;
5338
5339 l_storedPayeesTab payeeTabType;
5340 l_already_processed_flag BOOLEAN := FALSE;
5341 l_already_failed_flag BOOLEAN := FALSE;
5342 l_print_var VARCHAR2(1) := '';
5343
5344 BEGIN
5345
5346 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5347 print_debuginfo(l_module_name, 'ENTER');
5348
5349 END IF;
5350 IF (x_failedDocsTab.COUNT = 0) THEN
5351
5352 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5353 print_debuginfo(l_module_name, 'Exiting because error docs list '
5354 || 'is empty');
5355
5356 print_debuginfo(l_module_name, 'EXIT');
5357 END IF;
5358 RETURN;
5359
5360 END IF;
5361
5362
5363 FOR i in x_failedDocsTab.FIRST .. x_failedDocsTab.LAST LOOP
5364
5365 IF (x_failedDocsTab(i).doc_status <> DOC_STATUS_FAIL_BY_REJLVL) THEN
5366
5367 /*
5368 * First check, if we have already processed this payee
5369 * id. If yes, then skip to the next document.
5370 */
5371 l_already_processed_flag := FALSE;
5372 IF (l_storedPayeesTab.COUNT <> 0) THEN
5373
5374 FOR k in l_storedPayeesTab.FIRST .. l_storedPayeesTab.LAST
5375 LOOP
5376
5377 IF (x_failedDocsTab(i).payee_id =
5378 l_storedPayeesTab(k)) THEN
5379 l_already_processed_flag := TRUE;
5380 EXIT;
5381 END IF;
5382
5383 END LOOP;
5384
5385 END IF;
5386
5387 IF (l_already_processed_flag <> TRUE) THEN
5388
5389 /*
5390 * Loop through all the documents for this request,
5391 * failing any documents that have the same payee id
5392 * as the failed doc.
5393 */
5394 FOR j in p_allDocsTab.FIRST .. p_allDocsTab.LAST LOOP
5395
5396 IF (x_failedDocsTab(i).doc_id <> p_allDocsTab(j).doc_id)
5397 THEN
5398
5399 IF (x_failedDocsTab(i).payee_id =
5400 p_allDocsTab(j).payee_id) THEN
5401
5402 /*
5403 * Check if this doc has already failed and
5404 * been stored in the error docs list. If
5405 * it has already been failed, skip it.
5406 */
5407 l_already_failed_flag :=
5408 checkIfDocFailed(p_allDocsTab(j).doc_id,
5409 x_failedDocsTab);
5410
5411 IF (l_already_failed_flag = FALSE) THEN
5412 /*
5413 * Add this document to list of docs
5414 * failed because of same payee
5415 */
5416 l_invalidDocRec.doc_id :=
5417 p_allDocsTab(j).doc_id;
5418 l_invalidDocRec.pmt_grp_num :=
5419 p_allDocsTab(j).pmt_grp_num;
5420 l_invalidDocRec.payee_id :=
5421 p_allDocsTab(j).payee_id;
5422 l_invalidDocRec.doc_status :=
5423 DOC_STATUS_FAIL_BY_REJLVL;
5424 l_invalidDocRec.ca_doc_ref_num :=
5425 p_allDocsTab(i).ca_doc_ref_num; --AWT Enh 16296267
5426
5427 l_newlyFailedDocsTab(
5428 l_newlyFailedDocsTab.COUNT + 1) :=
5429 l_invalidDocRec;
5430
5431 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5432 print_debuginfo(l_module_name, 'Cascaded doc '
5433 || 'failure: '
5434 || x_failedDocsTab(i).doc_id
5435 || ' -> '
5436 || p_allDocsTab(j).doc_id
5437 || '. Related by payee '
5438 || x_failedDocsTab(i).payee_id
5439 || '.'
5440 );
5441
5442 END IF;
5443 /*
5444 * Once we fail a doc, we must add a
5445 * corresponding error message to the
5446 * error table.
5447 */
5448 IBY_BUILD_UTILS_PKG.createErrorRecord(
5449 TRXN_TYPE_DOC,
5450 p_allDocsTab(j).doc_id,
5451 l_invalidDocRec.doc_status,
5452 p_allDocsTab(j).ca_id,
5453 p_allDocsTab(j).ca_doc_id1,
5454 p_allDocsTab(j).ca_doc_id2,
5455 p_allDocsTab(j).ca_doc_id3,
5456 p_allDocsTab(j).ca_doc_id4,
5457 p_allDocsTab(j).ca_doc_id5,
5458 p_allDocsTab(j).pp_tt_cd,
5459 l_doc_err_rec,
5460 x_errTokenTab,
5461 x_failedDocsTab(i).ca_doc_ref_num
5462 );
5463
5464 insertIntoErrorTable(l_doc_err_rec,
5465 x_docErrorTab, x_errTokenTab);
5466
5467 END IF; -- not already failed
5468
5469 END IF;
5470
5471 END IF;
5472
5473 END LOOP; -- for each doc in request
5474
5475 /*
5476 * Once we have processed all documents which have this
5477 * orig doc id, we must not re-process them if there is
5478 * another error doc with the same orig doc id.
5479 *
5480 * Therefore, store the processed orig doc id. We will
5481 * skip any future error docs that have the same orig
5482 * doc id.
5483 */
5484 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5485 print_debuginfo(l_module_name, 'Adding payee id: '
5486 || x_failedDocsTab(i).payee_id
5487 || ' to stored payees tab'
5488 );
5489 END IF;
5490 l_storedPayeesTab(l_storedPayeesTab.COUNT + 1) :=
5491 x_failedDocsTab(i).payee_id;
5492
5493 END IF; -- not already processed
5494
5495 END IF;
5496
5497 END LOOP; -- for all failed documents
5498
5499 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5500 print_debuginfo(l_module_name, 'Total # payee related docs failed: '
5501 || l_newlyFailedDocsTab.COUNT);
5502
5503 END IF;
5504 /*
5505 * Copy all the newly failed documents back into the
5506 * original failed documents table. The original failed
5507 * docs table will be used to update the database.
5508 */
5509 IF (l_newlyFailedDocsTab.COUNT <> 0) THEN
5510 FOR i in l_newlyFailedDocsTab.FIRST .. l_newlyFailedDocsTab.LAST LOOP
5511 x_failedDocsTab(x_failedDocsTab.COUNT + 1) :=
5512 l_newlyFailedDocsTab(i);
5513 END LOOP;
5514 END IF;
5515
5516 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5517 print_debuginfo(l_module_name, 'EXIT');
5518
5519 END IF;
5520 END failAllDocsForPayee;
5521
5522 /*--------------------------------------------------------------------
5523 | NAME:
5524 | failAllDocsForRequest
5525 |
5526 | PURPOSE:
5527 | Fail all documents in the payment request. All documents that
5528 | are present in the error docs list will already be failed with
5529 | status REJECTED. Add any non-failed docs present in the
5530 | payment request to the error docs list, and status set the
5531 | status of such added docs to FAILED_BY_REJ_LEVEL.
5532 | This is needed for 'request level rejections'.
5533 |
5534 |
5535 | PARAMETERS:
5536 | IN
5537 | p_allDocsTab List of all documents within this payment request
5538 |
5539 | IN/OUT
5540 | x_failedDocsTab List of documents from this payment request that
5541 | have failed validation. When this procedure
5542 | completes, all documents in this request will
5543 | be marked as failed and added to this list
5544 |
5545 | RETURNS:
5546 |
5547 | NOTES:
5548 |
5549 *---------------------------------------------------------------------*/
5550 PROCEDURE failAllDocsForRequest(
5551 p_allDocsTab IN docPayTabType,
5552 x_failedDocsTab IN OUT NOCOPY docStatusTabType,
5553 x_docErrorTab IN OUT NOCOPY docErrorTabType,
5554 x_errTokenTab IN OUT NOCOPY trxnErrTokenTabType
5555 )
5556 IS
5557
5558 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
5559 '.failAllDocsForRequest';
5560
5561 l_invalidDocRec docStatusRecType;
5562 l_already_failed_flag BOOLEAN := FALSE;
5563 l_print_var VARCHAR2(1) := '';
5564 l_doc_err_rec IBY_TRANSACTION_ERRORS%ROWTYPE;
5565 l_doc_token_tab trxnErrTokenTabType;
5566 l_index NUMBER := 0;
5567 l_triggering_doc IBY_DOCS_PAYABLE_ALL.calling_app_doc_ref_number%TYPE;
5568
5569 BEGIN
5570
5571 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5572 print_debuginfo(l_module_name, 'ENTER');
5573
5574 END IF;
5575 /*
5576 * We will be failing all successful documents in the
5577 * request because at least one document in the request
5578 * has failed, and the rejection level is set to 'REQUEST'.
5579 *
5580 * When failing the successful docs, we need to refer to
5581 * the triggering doc in the error message. The triggering
5582 * doc can be any failed document in the failed documents
5583 * list.
5584 */
5585 IF (x_failedDocsTab.COUNT <> 0) THEN
5586
5587 l_index := x_failedDocsTab.FIRST;
5588 l_triggering_doc := x_failedDocsTab(l_index).ca_doc_ref_num;
5589 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5590 print_debuginfo(l_module_name, 'Triggering doc id: '
5591 || l_triggering_doc);
5592
5593 END IF;
5594 END IF;
5595
5596 /*
5597 * Loop through all the documents for this request,
5598 * failing any documents that have not been already
5599 * failed.
5600 */
5601 FOR j in p_allDocsTab.FIRST .. p_allDocsTab.LAST LOOP
5602
5603 /*
5604 * Check if this doc has already failed and
5605 * been stored in the error docs list. If
5606 * it has already been failed, skip it.
5607 */
5608 l_already_failed_flag :=
5609 checkIfDocFailed(p_allDocsTab(j).doc_id,
5610 x_failedDocsTab);
5611
5612 IF (l_already_failed_flag = FALSE) THEN
5613 /*
5614 * Add this document to list of docs
5615 * failed because of same payee
5616 */
5617 l_invalidDocRec.doc_id :=
5618 p_allDocsTab(j).doc_id;
5619 l_invalidDocRec.pmt_grp_num :=
5620 p_allDocsTab(j).pmt_grp_num;
5621 l_invalidDocRec.payee_id :=
5622 p_allDocsTab(j).payee_id;
5623 l_invalidDocRec.doc_status :=
5624 DOC_STATUS_FAIL_BY_REJLVL;
5625 l_invalidDocRec.ca_doc_ref_num :=
5626 p_allDocsTab(j).ca_doc_ref_num; --AWT Enh 16296267
5627
5628 x_failedDocsTab(
5629 x_failedDocsTab.COUNT + 1) :=
5630 l_invalidDocRec;
5631
5632 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5633 print_debuginfo(l_module_name, 'Failing doc '
5634 || p_allDocsTab(j).doc_id
5635 || ' because all docs in request must be failed.'
5636 );
5637
5638 END IF;
5639 /*
5640 * Once we fail a doc, we must add a corresponding
5641 * error message to the error table.
5642 */
5643 IBY_BUILD_UTILS_PKG.createErrorRecord(
5644 TRXN_TYPE_DOC,
5645 p_allDocsTab(j).doc_id,
5646 l_invalidDocRec.doc_status,
5647 p_allDocsTab(j).ca_id,
5648 p_allDocsTab(j).ca_doc_id1,
5649 p_allDocsTab(j).ca_doc_id2,
5650 p_allDocsTab(j).ca_doc_id3,
5651 p_allDocsTab(j).ca_doc_id4,
5652 p_allDocsTab(j).ca_doc_id5,
5653 p_allDocsTab(j).pp_tt_cd,
5654 l_doc_err_rec,
5655 x_errTokenTab,
5656 l_triggering_doc
5657 );
5658
5659 insertIntoErrorTable(l_doc_err_rec, x_docErrorTab,
5660 x_errTokenTab);
5661
5662 END IF; -- not already failed
5663
5664 END LOOP; -- for each doc in request
5665
5666 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5667 print_debuginfo(l_module_name, 'EXIT');
5668
5669 END IF;
5670 END failAllDocsForRequest;
5671
5672 /*--------------------------------------------------------------------
5673 | NAME:
5674 | failAllAwtDocs
5675 |
5676 | PURPOSE:
5677 | This will fail all documents of Payee for which there
5678 | is range based AWT calculation. When there is range based
5679 | AWT and when the rejection level is document only the
5680 | docs that have payee with range based AWT should be
5681 | removed and not all the docs for that payee.
5682 | This is introduced as part of Bug 16296267.
5683 |
5684 |
5685 | PARAMETERS:
5686 | IN
5687 | p_allDocsTab List of all documents within this payment request
5688 |
5689 | IN/OUT
5690 | x_failedDocsTab List of documents from this payment request that
5691 | have failed validation. When this procedure
5692 | completes, all documents in this request will
5693 | be marked as failed and added to this list
5694 |
5695 | RETURNS:
5696 |
5697 | NOTES:
5698 |
5699 *---------------------------------------------------------------------*/
5700
5701 --AWT Enh 16296267
5702 PROCEDURE failAllAwtDocs(
5703 p_allDocsTab IN docPayTabType,
5704 x_failedDocsTab IN OUT NOCOPY docStatusTabType,
5705 x_docErrorTab IN OUT NOCOPY docErrorTabType,
5706 x_errTokenTab IN OUT NOCOPY trxnErrTokenTabType
5707 )
5708 IS
5709 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
5710 '.failAllAwtDocs';
5711
5712 l_newlyFailedDocsTab docStatusTabType;
5713 l_invalidDocRec docStatusRecType;
5714 l_doc_err_rec IBY_TRANSACTION_ERRORS%ROWTYPE;
5715 l_doc_token_tab trxnErrTokenTabType;
5716 l_already_processed_flag BOOLEAN := FALSE;
5717 l_already_failed_flag BOOLEAN := FALSE;
5718 l_print_var VARCHAR2(1) := '';
5719
5720 BEGIN
5721
5722 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5723 print_debuginfo(l_module_name, 'ENTER');
5724
5725 END IF;
5726 IF (x_failedDocsTab.COUNT = 0) THEN
5727
5728 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5729 print_debuginfo(l_module_name, 'Exiting because error docs list '
5730 || 'is empty');
5731
5732 print_debuginfo(l_module_name, 'EXIT');
5733 END IF;
5734 RETURN;
5735
5736 END IF;
5737
5738 /*
5739 * Loop through all the documents for this request,
5740 * failing any documents that have the same orig
5741 * doc id of the failed doc.
5742 */
5743 FOR i in p_allDocsTab.FIRST .. p_allDocsTab.LAST LOOP
5744 IF (l_storedAwtPayees.EXISTS(p_allDocsTab(i).payee_id)) AND
5745 (p_allDocsTab(i).affects_rejection_level = 'Y') THEN
5746 /*
5747 * Check if this doc has already failed and
5748 * been stored in the error docs list. If
5749 * it has already been failed, skip it.
5750 */
5751 l_already_failed_flag :=
5752 checkIfDocFailed(p_allDocsTab(i).doc_id,
5753 x_failedDocsTab);
5754
5755 IF (l_already_failed_flag = FALSE) THEN
5756
5757 /*
5758 * Add this document to list of docs
5759 * failed by relation
5760 */
5761 l_invalidDocRec.doc_id
5762 := p_allDocsTab(i).doc_id;
5763 l_invalidDocRec.pmt_grp_num :=
5764 p_allDocsTab(i).pmt_grp_num;
5765 l_invalidDocRec.payee_id :=
5766 p_allDocsTab(i).payee_id;
5767 l_invalidDocRec.doc_status :=
5768 DOC_STATUS_RELN_FAIL;
5769 l_invalidDocRec.ca_doc_ref_num :=
5770 p_allDocsTab(i).ca_doc_ref_num; --AWT Enh 16296267
5771
5772 l_newlyFailedDocsTab(
5773 l_newlyFailedDocsTab.COUNT + 1) :=
5774 l_invalidDocRec;
5775
5776 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5777 print_debuginfo(l_module_name, 'Cascaded doc '
5778 || 'failure: '
5779 || l_storedAwtPayees(p_allDocsTab(i).payee_id)
5780 || ' -> '
5781 || p_allDocsTab(i).doc_id
5782 || '. Related by Payee with range based AWT'
5783 || p_allDocsTab(i).payee_id
5784 || '.'
5785 );
5786
5787 END IF;
5788 /*
5789 * Once we fail a doc, we must add a
5790 * corresponding error message to the
5791 * error table.
5792 */
5793 IBY_BUILD_UTILS_PKG.createErrorRecord(
5794 TRXN_TYPE_DOC,
5795 p_allDocsTab(i).doc_id,
5796 l_invalidDocRec.doc_status,
5797 p_allDocsTab(i).ca_id,
5798 p_allDocsTab(i).ca_doc_id1,
5799 p_allDocsTab(i).ca_doc_id2,
5800 p_allDocsTab(i).ca_doc_id3,
5801 p_allDocsTab(i).ca_doc_id4,
5802 p_allDocsTab(i).ca_doc_id5,
5803 p_allDocsTab(i).pp_tt_cd,
5804 l_doc_err_rec,
5805 x_errTokenTab,
5806 l_storedAwtPayees(p_allDocsTab(i).payee_id)
5807 );
5808
5809 insertIntoErrorTable(l_doc_err_rec,
5810 x_docErrorTab, x_errTokenTab);
5811
5812
5813 END IF;
5814
5815 END IF;
5816
5817 END LOOP; -- for each doc in request
5818
5819 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5820 print_debuginfo(l_module_name, 'Total # Payee with AWT related docs failed: '
5821 || l_newlyFailedDocsTab.COUNT);
5822
5823 END IF;
5824 /*
5825 * Copy all the newly failed documents back into the
5826 * original failed documents table. The original failed
5827 * docs table will be used to update the database.
5828 */
5829 IF (l_newlyFailedDocsTab.COUNT <> 0) THEN
5830 FOR i in l_newlyFailedDocsTab.FIRST .. l_newlyFailedDocsTab.LAST LOOP
5831 x_failedDocsTab(x_failedDocsTab.COUNT + 1) :=
5832 l_newlyFailedDocsTab(i);
5833 END LOOP;
5834 END IF;
5835
5836 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5837 print_debuginfo(l_module_name, 'EXIT');
5838
5839 END IF;
5840
5841 l_storedAwtPayees.DELETE;
5842 END failAllAwtDocs;
5843
5844 /*--------------------------------------------------------------------
5845 | NAME:
5846 | getXMLClob
5847 |
5848 | PURPOSE:
5849 | Performs a database query to get all failed documents for
5850 | the given payment request. These failed documents are put
5851 | into a XML structure and returned to the caller as a CLOB.
5852 |
5853 |
5854 | PARAMETERS:
5855 | IN
5856 |
5857 | OUT
5858 |
5859 |
5860 | RETURNS:
5861 |
5862 | NOTES:
5863 |
5864 |
5865 *---------------------------------------------------------------------*/
5866 FUNCTION getXMLClob(
5867 p_payreq_id IN VARCHAR2
5868 )
5869 RETURN CLOB
5870 IS
5871 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.getXMLClob';
5872 l_xml_clob CLOB := NULL;
5873
5874 l_ctx DBMS_XMLQuery.ctxType;
5875 l_sql VARCHAR2(2000);
5876 l_sqlcode NUMBER;
5877 l_sqlerrm VARCHAR2(300);
5878
5879 BEGIN
5880
5881 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5882 print_debuginfo(l_module_name, 'ENTER');
5883 END IF;
5884 /*
5885 * Select all docs that:
5886 * 1. Have the given pay req id
5887 * 2. Are not in 'documents_validated' status
5888 * 3. Were updated in the process of payment creation
5889 * (some docs might have failed earlier in document
5890 * validation flow. We don't want to pick them up).
5891 */
5892 l_sql := 'SELECT calling_app_id, '
5893 || 'calling_app_doc_unique_ref1, '
5894 || 'calling_app_doc_unique_ref2, '
5895 || 'calling_app_doc_unique_ref3, '
5896 || 'calling_app_doc_unique_ref4, '
5897 || 'calling_app_doc_unique_ref5, '
5898 || 'pay_proc_trxn_type_code '
5899 || 'FROM iby_docs_payable_all '
5900 || 'WHERE payment_service_request_id = :payreq_id '
5901 || 'AND document_status <> :doc_status';
5902
5903 l_ctx := DBMS_XMLQuery.newContext(l_sql);
5904 DBMS_XMLQuery.setBindValue(l_ctx, 'payreq_id', p_payreq_id);
5905 DBMS_XMLQuery.setBindValue(l_ctx, 'doc_status', DOC_STATUS_VALIDATED);
5906 DBMS_XMLQuery.useNullAttributeIndicator(l_ctx, TRUE);
5907
5908 /* raise an exception if no rows were found */
5909 DBMS_XMLQuery.setRaiseException(l_ctx, TRUE);
5910 DBMS_XMLQuery.setRaiseNoRowsException(l_ctx, TRUE);
5911 DBMS_XMLQuery.propagateOriginalException(l_ctx, TRUE);
5912
5913 l_xml_clob := DBMS_XMLQuery.getXML(l_ctx);
5914 DBMS_XMLQuery.closeContext(l_ctx);
5915
5916 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5917 print_debuginfo(l_module_name, 'EXIT');
5918
5919 END IF;
5920 RETURN l_xml_clob;
5921
5922 EXCEPTION
5923
5924 WHEN OTHERS THEN
5925 DBMS_XMLQuery.getExceptionContent(l_ctx, l_sqlcode, l_sqlerrm);
5926 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5927 print_debuginfo(l_module_name, 'SQL code: ' || l_sqlcode);
5928 print_debuginfo(l_module_name, 'SQL err msg: '|| l_sqlerrm);
5929
5930 END IF;
5931 /*
5932 * Do not raise exception if no rows found.
5933 * It means all docs are valid.
5934 * Return NULL clob to caller.
5935 *
5936 * 1403 = NO_DATA_FOUND
5937 *
5938 * Note: We are unable to explicitly catch the
5939 * NO_DATA_FOUND exception here because the caller
5940 * raises some other exception. So we have to check
5941 * value of the original error code instead.
5942 */
5943 IF (l_sqlcode = 1403) THEN
5944 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5945 print_debuginfo(l_module_name, 'No rows were returned for query;'
5946 || ' Returning null xml clob.');
5947 END IF;
5948 RETURN NULL;
5949 END IF;
5950
5951
5952 print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
5953 || 'to raise business event.', FND_LOG.LEVEL_UNEXPECTED);
5954 print_debuginfo(l_module_name, 'SQL code: ' || SQLCODE,
5955 FND_LOG.LEVEL_UNEXPECTED);
5956 print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
5957 FND_LOG.LEVEL_UNEXPECTED);
5958
5959
5960 /*
5961 * Propogate exception to caller.
5962 */
5963 RAISE;
5964
5965 END getXMLClob;
5966
5967 /*--------------------------------------------------------------------
5968 | NAME:
5969 | getRejectedDocs
5970 |
5971 | PURPOSE:
5972 | Performs a database query to get all failed documents for
5973 | the given payment request. These failed documents are put
5974 | into data structure and returned to the caller.
5975 |
5976 |
5977 | PARAMETERS:
5978 | IN
5979 |
5980 | OUT
5981 |
5982 |
5983 | RETURNS:
5984 |
5985 | NOTES:
5986 |
5987 |
5988 *---------------------------------------------------------------------*/
5989 PROCEDURE getRejectedDocs(
5990 p_payreq_id IN VARCHAR2,
5991 x_docIDTab IN OUT NOCOPY IBY_DISBURSE_UI_API_PUB_PKG.docPayIDTab,
5992 x_docStatusTab IN OUT NOCOPY IBY_DISBURSE_UI_API_PUB_PKG.docPayStatusTab
5993 )
5994 IS
5995 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.getRejectedDocs';
5996 l_rej_docs_list rejectedDocTabType;
5997
5998 /*
5999 * Cursor to get list of failed documents for a payment service
6000 * request.
6001 */
6002 CURSOR c_rejected_docs (p_payreq_id IBY_PAY_SERVICE_REQUESTS.
6003 payment_service_request_id%TYPE)
6004 IS
6005 SELECT
6006 doc.document_payable_id,
6007 doc.document_status
6008 FROM
6009 IBY_DOCS_PAYABLE_ALL doc
6010 WHERE
6011 doc.payment_service_request_id = p_payreq_id AND
6012 doc.document_status <> DOC_STATUS_VALIDATED
6013 ;
6014
6015 BEGIN
6016
6017 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6018 print_debuginfo(l_module_name, 'ENTER');
6019
6020 END IF;
6021 /*
6022 * Pick up all rejected documents for this payment request.
6023 */
6024 OPEN c_rejected_docs(p_payreq_id);
6025 FETCH c_rejected_docs BULK COLLECT INTO l_rej_docs_list;
6026 CLOSE c_rejected_docs;
6027
6028 /*
6029 * Separate out the document ids and the document statuses.
6030 * This is because the rejection API expects these as
6031 * separate arrays.
6032 */
6033 IF (l_rej_docs_list.COUNT > 0) THEN
6034
6035 FOR i IN l_rej_docs_list.FIRST .. l_rej_docs_list.LAST LOOP
6036 x_docIDTab(i) := l_rej_docs_list(i).doc_id;
6037 END LOOP;
6038
6039 FOR i IN l_rej_docs_list.FIRST .. l_rej_docs_list.LAST LOOP
6040 x_docStatusTab(i) := l_rej_docs_list(i).doc_status;
6041 END LOOP;
6042
6043 END IF;
6044
6045 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6046 print_debuginfo(l_module_name, 'EXIT');
6047
6048 END IF;
6049 END getRejectedDocs;
6050
6051 /*--------------------------------------------------------------------
6052 | NAME:
6053 | checkIfDocFailed
6054 |
6055 | PURPOSE:
6056 | Checks if a given document exists within a list of given
6057 | failed documents.
6058 |
6059 | PARAMETERS:
6060 | IN
6061 |
6062 | OUT
6063 |
6064 |
6065 | RETURNS:
6066 |
6067 | NOTES:
6068 |
6069 |
6070 *---------------------------------------------------------------------*/
6071 FUNCTION checkIfDocFailed(
6072 p_doc_id IN IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE,
6073 p_failedDocsTab IN docStatusTabType
6074 )
6075 RETURN BOOLEAN
6076 IS
6077 l_return_flag BOOLEAN := FALSE;
6078 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.checkIfDocFailed';
6079 l_print_var VARCHAR2(50) := 'false';
6080
6081 BEGIN
6082
6083 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6084 print_debuginfo(l_module_name, 'ENTER');
6085
6086 END IF;
6087 /*
6088 * If error documents table is empty, return false
6089 */
6090 IF (p_failedDocsTab.COUNT = 0) THEN
6091
6092 l_return_flag := FALSE;
6093
6094 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6095 print_debuginfo(l_module_name, 'Returning false as '
6096 || 'error docs list is empty');
6097 print_debuginfo(l_module_name, 'EXIT');
6098
6099 END IF;
6100 return l_return_flag;
6101
6102 END IF;
6103
6104 /*
6105 * If the given document exists in the list of
6106 * failed documents, it means that this document
6107 * has been failed.
6108 */
6109 FOR i in p_failedDocsTab.FIRST .. p_failedDocsTab.LAST LOOP
6110
6111 IF (p_failedDocsTab(i).doc_id = p_doc_id) THEN
6112 l_return_flag := TRUE;
6113 EXIT;
6114 END IF;
6115
6116 END LOOP;
6117
6118 IF (l_return_flag = TRUE) THEN
6119 l_print_var := 'true';
6120 END IF;
6121
6122 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6123 print_debuginfo(l_module_name, 'Returning flag as '
6124 || l_print_var
6125 || ' for document '
6126 || p_doc_id);
6127
6128 print_debuginfo(l_module_name, 'EXIT');
6129
6130 END IF;
6131 return l_return_flag;
6132
6133 END checkIfDocFailed;
6134
6135 /*--------------------------------------------------------------------
6136 | NAME:
6137 | checkIfAllDocsFailed
6138 |
6139 | PURPOSE:
6140 | Checks if all documents of the payment request have failed.
6141 | All documents have failed if each and every document within
6142 | the payment request is found to exist in the list of invalid
6143 | documents.
6144 |
6145 | PARAMETERS:
6146 | IN
6147 |
6148 | OUT
6149 |
6150 |
6151 | RETURNS:
6152 |
6153 | NOTES:
6154 |
6155 |
6156 *---------------------------------------------------------------------*/
6157 FUNCTION checkIfAllDocsFailed(
6158 p_allDocsTab IN docPayTabType,
6159 p_failedDocsTab IN docStatusTabType
6160 )
6161 RETURN BOOLEAN
6162 IS
6163 l_return_flag BOOLEAN := TRUE;
6164 l_check_flag BOOLEAN := FALSE;
6165 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.checkIfAllDocsFailed';
6166 l_print_var VARCHAR2(50) := 'false';
6167
6168 BEGIN
6169
6170 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6171 print_debuginfo(l_module_name, 'ENTER');
6172
6173 END IF;
6174 /*
6175 * If error documents table is empty, return false
6176 */
6177 IF (p_failedDocsTab.COUNT = 0) THEN
6178
6179 l_return_flag := FALSE;
6180
6181 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6182 print_debuginfo(l_module_name, 'Returning false as '
6183 || ' error docs list is empty');
6184 print_debuginfo(l_module_name, 'EXIT');
6185
6186 END IF;
6187 return l_return_flag;
6188
6189 END IF;
6190
6191 /*
6192 * If provided documents table is empty, return true
6193 */
6194 IF (p_allDocsTab.COUNT = 0) THEN
6195
6196 l_return_flag := TRUE;
6197
6198 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6199 print_debuginfo(l_module_name, 'Returning true as '
6200 || ' empty docs list has been provided');
6201 print_debuginfo(l_module_name, 'EXIT');
6202
6203 END IF;
6204 return l_return_flag;
6205
6206 END IF;
6207
6208 /*
6209 * Loop through all the documents in the request, checking
6210 * if doc has failed. If even a single doc has not failed,
6211 * we can return immediately that not all docs have failed
6212 */
6213 FOR i in p_allDocsTab.FIRST .. p_allDocsTab.LAST LOOP
6214
6215 l_check_flag := checkIfDocFailed(p_allDocsTab(i).doc_id,
6216 p_failedDocsTab);
6217
6218 IF (l_check_flag = FALSE) THEN
6219 l_return_flag := FALSE;
6220 EXIT;
6221 END IF;
6222
6223 END LOOP;
6224
6225 IF (l_return_flag = TRUE) THEN
6226 l_print_var := 'true';
6227 END IF;
6228
6229 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6230 print_debuginfo(l_module_name, 'Returning flag as '
6231 || l_print_var);
6232
6233 print_debuginfo(l_module_name, 'EXIT');
6234
6235 END IF;
6236 return l_return_flag;
6237
6238 END checkIfAllDocsFailed;
6239
6240 /*--------------------------------------------------------------------
6241 | NAME:
6242 | getDocRejLevelSysOption
6243 |
6244 | PURPOSE:
6245 | Gets the document rejection level system option.
6246 |
6247 | Possible values are:
6248 | REQUEST | DOCUMENT | PAYEE | NONE
6249 |
6250 | The handling of document validation failures is dependent
6251 | upon the rejection level setting.
6252 |
6253 | PARAMETERS:
6254 | IN
6255 |
6256 |
6257 | OUT
6258 |
6259 |
6260 | RETURNS:
6261 |
6262 | NOTES:
6263 |
6264 *---------------------------------------------------------------------*/
6265 FUNCTION getDocRejLevelSysOption RETURN VARCHAR2
6266 IS
6267 l_rejLevel VARCHAR2(200);
6268 l_sys_options_tab sysOptionsTabType;
6269 l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
6270 '.getDocRejLevelSysOption';
6271 l_print_var NUMBER := -1;
6272
6273 CURSOR c_sys_options
6274 IS
6275 SELECT
6276 sysoptions.document_rejection_level_code
6277 FROM
6278 IBY_INTERNAL_PAYERS_ALL sysoptions
6279 WHERE
6280 sysoptions.org_id IS NULL
6281 ;
6282
6283 BEGIN
6284
6285 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6286 print_debuginfo(l_module_name, 'ENTER');
6287
6288 END IF;
6289 /*
6290 * Fetch the system options for the given org
6291 */
6292 OPEN c_sys_options;
6293 FETCH c_sys_options BULK COLLECT INTO l_sys_options_tab;
6294 CLOSE c_sys_options;
6295
6296 IF (l_sys_options_tab.COUNT = 0) THEN
6297
6298 /*
6299 * This means that the document rejection level
6300 * is not set at the enterprise level.
6301 *
6302 * Enterprise level rejection levels (i.e., with org
6303 * id set to null) are expected to be seeded.
6304 *
6305 * Raise an exception and abort processing.
6306 */
6307
6308 print_debuginfo(l_module_name, 'Document rejection level '
6309 || 'system option is not set at '
6310 || 'enterprise level. It is mandatory to '
6311 || 'setup rejection levels at enterprise level. '
6312 || 'Raising exception.. ',
6313 FND_LOG.LEVEL_UNEXPECTED
6314 );
6315
6316
6317 APP_EXCEPTION.RAISE_EXCEPTION;
6318
6319 ELSIF (l_sys_options_tab.COUNT <> 1) THEN
6320
6321 /*
6322 * This means that there are multiple document
6323 * rejection levels set at the enterprise level.
6324 * We don't know which one to use.
6325 *
6326 * Raise an exception and abort processing.
6327 */
6328
6329 print_debuginfo(l_module_name, 'Multiple document rejection '
6330 || 'level system options are set at '
6331 || 'enterprise level. It is mandatory to '
6332 || 'setup only one document rejection level '
6333 || 'at enterprise level. '
6334 || 'Raising exception.. ',
6335 FND_LOG.LEVEL_UNEXPECTED
6336 );
6337
6338
6339 APP_EXCEPTION.RAISE_EXCEPTION;
6340
6341 ELSE
6342
6343 /*
6344 * Return the retrieved enterprise level
6345 * document rejection level system option.
6346 */
6347 l_rejLevel := l_sys_options_tab(1).rej_level;
6348
6349 END IF; -- if l_sys_options_tab.COUNT = 0
6350
6351 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6352 print_debuginfo(l_module_name, 'Returning rejection level: '
6353 || l_rejLevel);
6354
6355 print_debuginfo(l_module_name, 'EXIT');
6356
6357 END IF;
6358 RETURN l_rejLevel;
6359
6360 EXCEPTION
6361 WHEN OTHERS THEN
6362
6363 /*
6364 * In case of an exception, return NULL
6365 */
6366 l_rejLevel := NULL;
6367 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6368 print_debuginfo(l_module_name, 'No document rejection level '
6369 || 'set up at enterprise level. '
6370 || 'Returning NULL.');
6371
6372 print_debuginfo(l_module_name, 'EXIT');
6373 END IF;
6374 RETURN l_rejLevel;
6375
6376 END getDocRejLevelSysOption;
6377
6378 /*--------------------------------------------------------------------
6379 | NAME:
6380 | validateProfileFromProfDrivers
6381 |
6382 | PURPOSE:
6383 | Checks if the given payment profile is valid for the given
6384 | (payment method, org, payment currency, internal
6385 | bank account) combination on the document.
6386 |
6387 | PARAMETERS:
6388 | IN
6389 |
6390 | OUT
6391 |
6392 |
6393 | RETURNS:
6394 |
6395 | NOTES:
6396 |
6397 |
6398 *---------------------------------------------------------------------*/
6399 FUNCTION validateProfileFromProfDrivers(
6400 p_profile_id IN IBY_DOCS_PAYABLE_ALL.payment_profile_id%TYPE,
6401 p_org_id IN IBY_DOCS_PAYABLE_ALL.org_id%TYPE,
6402 p_org_type IN IBY_DOCS_PAYABLE_ALL.org_type%TYPE,
6403 p_pmt_method_cd IN IBY_DOCS_PAYABLE_ALL.payment_method_code%TYPE,
6404 p_pmt_currency IN IBY_DOCS_PAYABLE_ALL.payment_currency_code%TYPE,
6405 p_int_bank_acct_id IN IBY_DOCS_PAYABLE_ALL.internal_bank_account_id%TYPE
6406 )
6407 RETURN BOOLEAN
6408 IS
6409 l_return_flag BOOLEAN := FALSE;
6410 l_module_name CONSTANT VARCHAR2(200)
6411 := G_PKG_NAME ||
6412 '.validateProfileFromProfDrivers';
6413
6414 l_valid_flag VARCHAR2(1);
6415 l_profile_id IBY_DOCS_PAYABLE_ALL.payment_profile_id%TYPE;
6416
6417 BEGIN
6418
6419 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6420 print_debuginfo(l_module_name, 'ENTER');
6421
6422 print_debuginfo(l_module_name, 'Provided parameters are: '
6423 || 'Profile id: '
6424 || p_profile_id
6425 || ', org id: '
6426 || p_org_id
6427 || ', org type: '
6428 || p_org_type
6429 || ', payment method: '
6430 || p_pmt_method_cd
6431 || ', payment currency: '
6432 || p_pmt_currency
6433 || ', int bank acct id: '
6434 || p_int_bank_acct_id
6435 );
6436
6437 END IF;
6438 /*
6439 * Get the list of all payment profiles that
6440 * match the given list of profile drivers.
6441 */
6442 l_profile_id := p_profile_id;
6443 IBY_BUILD_UTILS_PKG.getProfListFromProfileDrivers(
6444 p_pmt_method_cd,
6445 p_org_id,
6446 p_org_type,
6447 p_pmt_currency,
6448 p_int_bank_acct_id,
6449 l_profile_id,
6450 l_valid_flag);
6451
6452 /*
6453 * If count is non-zero it means that at least one
6454 * profile matches the given set of drivers.
6455 *
6456 * Otherwise, it means that no profile matches the
6457 * given set of drivers; implying that the profile
6458 * on the document is invalid (so return FALSE).
6459 */
6460 IF (l_valid_flag = 'N') THEN
6461
6462 l_return_flag := FALSE;
6463
6464 ELSE
6465
6466 l_return_flag := TRUE;
6467
6468 END IF;
6469
6470 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6471 print_debuginfo(l_module_name, 'EXIT');
6472
6473 END IF;
6474 RETURN l_return_flag;
6475
6476 END validateProfileFromProfDrivers;
6477
6478 /*--------------------------------------------------------------------
6479 | NAME:
6480 | checkProfileFormatCompat
6481 |
6482 | PURPOSE:
6483 |
6484 |
6485 | PARAMETERS:
6486 | IN
6487 |
6488 |
6489 | OUT
6490 |
6491 |
6492 | RETURNS:
6493 |
6494 | NOTES:
6495 |
6496 *---------------------------------------------------------------------*/
6497 FUNCTION checkProfileFormatCompat(
6498 p_doc_id IN IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE,
6499 p_payee_id IN IBY_DOCS_PAYABLE_ALL.ext_payee_id%TYPE,
6500 p_profile_id IN IBY_DOCS_PAYABLE_ALL.payment_profile_id%TYPE
6501 ) RETURN BOOLEAN
6502 IS
6503 l_return_flag BOOLEAN;
6504 l_module_name CONSTANT VARCHAR2(200)
6505 := G_PKG_NAME || '.checkProfileFormatCompat';
6506
6507 l_payee_id IBY_EXTERNAL_PAYEES_ALL.ext_payee_id%TYPE;
6508 l_payee_format_cd IBY_EXTERNAL_PAYEES_ALL.payment_format_code%TYPE;
6509
6510 l_payment_profile_id IBY_PAYMENT_PROFILES.payment_profile_id%TYPE;
6511 l_prof_pmt_format_cd IBY_PAYMENT_PROFILES.payment_format_code%TYPE;
6512 l_bepid IBY_PAYMENT_PROFILES.bepid%TYPE;
6513 l_transmit_protocol_cd IBY_PAYMENT_PROFILES.transmit_protocol_code%TYPE;
6514
6515
6516 BEGIN
6517
6518 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6519 print_debuginfo(l_module_name, 'ENTER');
6520
6521 END IF;
6522 l_return_flag := FALSE;
6523
6524 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6525 print_debuginfo(l_module_name, 'Validating profile-format '
6526 || 'compatibility for document '
6527 || p_doc_id
6528 );
6529
6530
6531 END IF;
6532 IF (p_profile_id IS NULL OR p_profile_id = -1) THEN
6533
6534 l_return_flag := TRUE;
6535
6536 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6537 print_debuginfo(l_module_name, 'Profile id not '
6538 || 'available. Cannot validate. Returning success.'
6539 );
6540
6541 print_debuginfo(l_module_name, 'EXIT');
6542
6543 END IF;
6544 RETURN l_return_flag;
6545
6546 END IF;
6547
6548
6549 IF (p_payee_id IS NULL OR p_payee_id = -1) THEN
6550
6551 l_return_flag := TRUE;
6552
6553 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6554 print_debuginfo(l_module_name, 'Payee id not '
6555 || 'available. Cannot validate. Returning success.'
6556 );
6557
6558 print_debuginfo(l_module_name, 'EXIT');
6559
6560 END IF;
6561 RETURN l_return_flag;
6562
6563 END IF;
6564
6565 /*
6566 * Pick up the default format for the payee on the
6567 * document.
6568 */
6569 /* Initialize */
6570 l_payee_format_cd := NULL;
6571
6572 IF (l_payee_format_tab.EXISTS(p_payee_id)) THEN
6573 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6574 print_debuginfo(l_module_name, 'Getting the data from Cache For Payee Id: ' || p_payee_id);
6575 END IF;
6576 l_payee_format_cd := l_payee_format_tab(p_payee_id).payment_format_cd;
6577 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6578 print_debuginfo(l_module_name, 'Format: '
6579 || l_payee_format_cd
6580 || ' linked to payee '
6581 || p_payee_id);
6582 END IF;
6583 ELSE
6584 BEGIN
6585 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6586 print_debuginfo(l_module_name, 'Getting the data from DB For Payee Id: ' || p_payee_id);
6587 END IF;
6588 SELECT payee.ext_payee_id, payee.payment_format_code
6589 INTO l_payee_id, l_payee_format_cd
6590 FROM IBY_EXTERNAL_PAYEES_ALL payee
6591 WHERE payee.ext_payee_id = p_payee_id;
6592
6593
6594 EXCEPTION
6595 WHEN NO_DATA_FOUND THEN
6596
6597 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6598 print_debuginfo(l_module_name, 'Exception No Data Found For Payee Id: ' || p_payee_id);
6599 END IF;
6600 l_payee_id := null;
6601 l_payee_format_cd := null;
6602 END;
6603 l_payee_format_tab(p_payee_id).payee_id := l_payee_id;
6604 l_payee_format_tab(p_payee_id).payment_format_cd := l_payee_format_cd;
6605 END IF;
6606
6607
6608 IF (l_payee_format_cd IS NULL) THEN
6609
6610 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6611 print_debuginfo(l_module_name, 'No format was found '
6612 || 'linked to payee '
6613 || p_payee_id
6614 );
6615
6616 END IF;
6617 l_return_flag := TRUE;
6618
6619 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6620 print_debuginfo(l_module_name, 'Format cd not '
6621 || 'available. Cannot validate. Returning success.'
6622 );
6623
6624 print_debuginfo(l_module_name, 'EXIT');
6625
6626 END IF;
6627 RETURN l_return_flag;
6628
6629 END IF;
6630
6631 /*
6632 * Check if the format on the payee matches the format
6633 * on the profiles that are set up.
6634 */
6635 l_return_flag := FALSE;
6636
6637 IF (l_profile_format_tab.EXISTS(p_profile_id) ) THEN
6638 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6639 print_debuginfo(l_module_name, 'Getting the value from Cache Structure for profile id: ' || p_profile_id);
6640 END IF;
6641 IF (l_profile_format_tab(p_profile_id).payment_format_cd = l_payee_format_cd)
6642 THEN
6643 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6644 print_debuginfo(l_module_name, 'Profile: '
6645 || p_profile_id
6646 || ' is compatible with format '
6647 || l_payee_format_cd);
6648
6649 END IF;
6650 l_return_flag := TRUE;
6651
6652 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6653 print_debuginfo(l_module_name, 'EXIT');
6654 END IF;
6655 END IF;
6656 RETURN l_return_flag;
6657
6658 ELSE
6659
6660 BEGIN
6661 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6662 print_debuginfo(l_module_name, 'Getting the value from DB for profile id: ' || p_profile_id);
6663 END IF;
6664 SELECT
6665 ipp.payment_profile_id, ipp.payment_format_code,ipp.bepid, ipp.transmit_protocol_code
6666 INTO l_payment_profile_id,l_prof_pmt_format_cd,l_bepid,l_transmit_protocol_cd
6667 FROM IBY_PAYMENT_PROFILES ipp
6668 WHERE ipp.payment_profile_id = p_profile_id ;
6669
6670 EXCEPTION
6671 WHEN NO_DATA_FOUND THEN
6672
6673 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6674 print_debuginfo(l_module_name, 'Exception No Data Found For Profile Id: ' || p_profile_id);
6675 END IF;
6676 l_payment_profile_id := null;
6677 l_prof_pmt_format_cd := null;
6678 l_bepid := null;
6679 l_transmit_protocol_cd := null;
6680 END;
6681 l_profile_format_tab(p_profile_id).profile_id := l_payment_profile_id;
6682 l_profile_format_tab(p_profile_id).payment_format_cd := l_prof_pmt_format_cd;
6683 l_profile_format_tab(p_profile_id).bepid := l_bepid;
6684 l_profile_format_tab(p_profile_id).transmit_protocol_cd := l_transmit_protocol_cd;
6685
6686 IF (l_profile_format_tab(p_profile_id).payment_format_cd = l_payee_format_cd)
6687 THEN
6688 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6689 print_debuginfo(l_module_name, 'Profile: '
6690 || p_profile_id
6691 || ' is compatible with format '
6692 || l_payee_format_cd);
6693
6694 END IF;
6695 l_return_flag := TRUE;
6696
6697 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6698 print_debuginfo(l_module_name, 'EXIT');
6699 END IF;
6700 END IF;
6701
6702 RETURN l_return_flag;
6703 END IF;
6704
6705 /*
6706 * If we reached here, it means that no profile was
6707 * found matching the given format. This is an error.
6708 * Return validation failure result.
6709 */
6710 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6711 print_debuginfo(l_module_name, 'No profiles matched format '
6712 || l_payee_format_cd
6713 || ' for document '
6714 || p_doc_id
6715 || '. Profile '
6716 || p_profile_id
6717 || ' and format '
6718 || l_payee_format_cd
6719 || ' are not compatible.'
6720 );
6721
6722 END IF;
6723 l_return_flag := TRUE;
6724 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6725 print_debuginfo(l_module_name, 'EXIT');
6726
6727 END IF;
6728 RETURN l_return_flag;
6729
6730 END checkProfileFormatCompat;
6731
6732
6733
6734
6735 /*--------------------------------------------------------------------
6736 | NAME:
6737 | initDocDataForPPR
6738 |
6739 | PURPOSE:
6740 | Picks up Document Data for all Document payables of Request
6741 | and inserts them in to a GT table (IBY_DOCS_PAYABLE_VAL_GT).
6742 |
6743 | PARAMETERS:
6744 | IN
6745 |
6746 |
6747 | OUT
6748 |
6749 |
6750 | RETURNS:
6751 |
6752 | NOTES:
6753 |
6754 *---------------------------------------------------------------------*/
6755 PROCEDURE initDocDataForPPR(
6756 p_pay_service_request_id IN IBY_PAY_SERVICE_REQUESTS.
6757 payment_service_request_id%TYPE
6758 )
6759
6760 IS
6761 l_module_name CONSTANT VARCHAR2(200)
6762 := G_PKG_NAME || '.initDocDataForPPR';
6763 l_process_type IBY_PAY_SERVICE_REQUESTS.PROCESS_TYPE%TYPE; --Bug 16679530
6764
6765 BEGIN
6766
6767 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6768
6769 print_debuginfo(l_module_name, 'Enter initDocDataForPPR');
6770 END IF;
6771
6772 SELECT PROCESS_TYPE
6773 INTO l_process_type
6774 FROM iby_pay_service_requests
6775 WHERE payment_service_request_id = p_pay_service_request_id; --Bug 16679530
6776
6777 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6778 print_debuginfo(l_module_name, 'Process Type is:'||l_process_type); --Bug 16679530
6779 END IF;
6780
6781 INSERT INTO IBY_DOCS_PAYABLE_VAL_GT(calling_app_id,
6782 calling_app_doc_id1 ,
6783 calling_app_doc_id2 ,
6784 calling_app_doc_id3 ,
6785 calling_app_doc_id4 ,
6786 calling_app_doc_id5 ,
6787 pay_proc_trxn_type_cd ,
6788 document_id ,
6789 document_amount ,
6790 document_pay_currency ,
6791 exclusive_payment_flag ,
6792 delivery_channel_code ,
6793 delivery_chn_format_val ,
6794 unique_remit_id_code ,
6795 payment_reason_comments ,
6796 settlement_priority ,
6797 remittance_message1 ,
6798 remittance_message2 ,
6799 remittance_message3 ,
6800 uri_check_digit ,
6801 external_bank_account_id ,
6802 int_bank_num ,
6803 int_bank_name ,
6804 int_bank_name_alt ,
6805 int_bank_branch_num ,
6806 int_bank_branch_name ,
6807 int_bank_branch_name_alt ,
6808 int_bank_branch_type ,
6809 int_bank_acc_num ,
6810 int_bank_acc_name ,
6811 int_bank_acc_name_alt ,
6812 int_bank_acc_type , -- bug 16007784
6813 int_bank_acc_iban ,
6814 int_bank_acc_curr ,
6815 int_bank_assigned_id1 ,
6816 int_bank_assigned_id2 ,
6817 int_eft_user_number ,
6818 int_bank_acc_chk_dgts ,
6819 int_eft_req_identifier ,
6820 int_bank_acc_short_name ,
6821 int_bank_acc_holder_name ,
6822 int_bank_acc_holder_name_alt ,
6823 payer_le_name ,
6824 payer_le_country ,
6825 payer_phone ,
6826 payer_registration_number ,
6827 payer_tax_registration_number ,
6828 ext_bank_num ,
6829 ext_bank_name ,
6830 ext_bank_name_alt ,
6831 ext_bank_branch_num ,
6832 ext_bank_branch_name ,
6833 ext_bank_branch_name_alt ,
6834 ext_bank_branch_type , -- bug 16007784
6835 ext_bank_country ,
6836 ext_bank_branch_addr1 ,
6837 ext_bank_branch_country ,
6838 ext_bank_acc_num ,
6839 ext_bank_acc_name ,
6840 ext_bank_acc_name_alt ,
6841 ext_bank_acc_type ,
6842 ext_bank_acc_iban ,
6843 ext_bank_acc_chk_dgts ,
6844 ext_bank_acc_short_name ,
6845 ext_bank_acc_holder_name ,
6846 ext_bank_acc_holder_name_alt ,
6847 ext_bank_acc_BIC ,
6848 payee_party_name ,
6849 payee_party_addr1 ,
6850 payee_party_addr2 ,
6851 payee_party_addr3 ,
6852 payee_party_city ,
6853 payee_party_state ,
6854 payee_party_province ,
6855 payee_party_county ,
6856 payee_party_postal ,
6857 payee_party_country ,
6858 bank_charge_bearer ,
6859 payment_reason_code ,
6860 payment_method_cd ,
6861 payee_payment_format_cd ,
6862 payee_party_site_name
6863 )
6864 SELECT
6865 docs.calling_app_id calling_app_id,
6866 docs.calling_app_doc_unique_ref1 calling_app_doc_id1,
6867 docs.calling_app_doc_unique_ref2 calling_app_doc_id2,
6868 docs.calling_app_doc_unique_ref3 calling_app_doc_id3,
6869 docs.calling_app_doc_unique_ref4 calling_app_doc_id4,
6870 docs.calling_app_doc_unique_ref5 calling_app_doc_id5,
6871 docs.pay_proc_trxn_type_code pay_proc_trxn_type_cd,
6872 docs.document_payable_id document_id,
6873 docs.payment_amount document_amount,
6874 docs.payment_currency_code document_pay_currency,
6875 docs.exclusive_payment_flag exclusive_payment_flag,
6876 docs.delivery_channel_code delivery_channel_code,
6877 del_chn.format_value delivery_chn_format_val,
6878 docs.unique_remittance_identifier unique_remit_id_code,
6879 docs.payment_reason_comments payment_reason_comments,
6880 docs.settlement_priority settlement_priority,
6881 docs.remittance_message1 remittance_message1,
6882 docs.remittance_message2 remittance_message2,
6883 docs.remittance_message3 remittance_message3,
6884 docs.uri_check_digit uri_check_digit,
6885 docs.external_bank_account_id external_bank_account_id,
6886 iba_bnk_branch.bank_number int_bank_num,
6887 iba_bnk_branch.bank_name int_bank_name,
6888 iba_bnk_branch.bank_name_alt int_bank_name_alt,
6889 iba_bnk_branch.branch_number int_bank_branch_num,
6890 iba_bnk_branch.bank_branch_name int_bank_branch_name,
6891 iba_bnk_branch.bank_branch_name_alt int_bank_branch_name_alt,
6892 iba_bnk_branch.bank_branch_type int_bank_branch_type, -- bug 16007784
6893 iba.bank_account_num int_bank_acc_num,
6894 iba.bank_account_name int_bank_acc_name,
6895 iba.bank_account_name_alt int_bank_acc_name_alt,
6896 iba.bank_account_type int_bank_acc_type,
6897 iba.iban_number int_bank_acc_iban,
6898 iba.currency_code int_bank_acc_curr,
6899 '' int_bank_assigned_id1,
6900 '' int_bank_assigned_id2,
6901 iba.eft_user_num int_eft_user_number,
6902 iba.check_digits int_bank_acc_chk_dgts,
6903 iba.eft_requester_identifier int_eft_req_identifier,
6904 iba.short_account_name int_bank_acc_short_name,
6905 iba.account_holder_name int_bank_acc_holder_name,
6906 iba.account_holder_name_alt int_bank_acc_holder_name_alt,
6907 payer.party_legal_name payer_le_name,
6908 payer.party_address_country payer_le_country,
6909 payer.party_phone payer_phone,
6910 payer.party_registration_number payer_registration_number,
6911 IBY_FD_EXTRACT_GEN_PVT.
6912 Get_FP_TaxRegistration
6913 (docs.legal_entity_id) payer_tax_registration_number,
6914 eba_bank_branch.bank_number ext_bank_num,
6915 eba_bank_branch.bank_name ext_bank_name,
6916 eba_bank_branch.bank_name_alt ext_bank_name_alt,
6917 eba_bank_branch.branch_number ext_bank_branch_num,
6918 eba_bank_branch.bank_branch_name ext_bank_branch_name,
6919 eba_bank_branch.bank_branch_name_alt ext_bank_branch_name_alt,
6920 eba_bank_branch.bank_branch_type ext_bank_branch_type, -- bug 16007784
6921 eba.country_code ext_bank_country,
6922 eba_bank_branch.address_line1 ext_bank_branch_addr1,
6923 nvl(eba_bank_branch.country,
6924 eba_bank_branch.bank_home_country) ext_bank_branch_country,
6925 DECODE (l_process_type,
6926 'STANDARD', iby_ext_bankacct_pub.Uncipher_Bank_Number (eba.bank_account_num,
6927 eba.ba_num_sec_segment_id,
6928 iby_utility_pvt.get_view_param('SYS_KEY'),
6929 baek.subkey_cipher_text,
6930 baes.segment_cipher_text,
6931 baes.encoding_scheme,
6932 eba.ba_mask_setting,
6933 eba.ba_unmask_length),
6934 eba.ba_num_sec_segment_id) ext_bank_acc_num, --Bug 16679530
6935 eba.bank_account_name ext_bank_acc_name,
6936 eba.bank_account_name_alt ext_bank_acc_name_alt,
6937 eba.bank_account_type ext_bank_acc_type,
6938 DECODE(l_process_type,
6939 'STANDARD', iby_ext_bankacct_pub.Uncipher_Bank_Number (eba.iban,
6940 eba.iban_sec_segment_id,
6941 iby_utility_pvt.get_view_param('SYS_KEY'),
6942 baik.subkey_cipher_text,
6943 bais.segment_cipher_text,
6944 bais.encoding_scheme,
6945 eba.ba_mask_setting,
6946 eba.ba_unmask_length),
6947 eba.iban) ext_bank_acc_iban, --Bug 16679530
6948 eba.check_digits ext_bank_acc_chk_dgts,
6949 eba.short_acct_name ext_bank_acc_short_name,
6950 op.party_name ext_bank_acc_holder_name,
6951 '' ext_bank_acc_holder_name_alt,
6952 eba_bank_branch.eft_swift_code ext_bank_acc_BIC,
6953 payee.party_name payee_party_name,
6954 payee_addr.add_line1 payee_party_addr1,
6955 payee_addr.add_line2 payee_party_addr2,
6956 payee_addr.add_line3 payee_party_addr3,
6957 payee_addr.city payee_party_city,
6958 payee_addr.state payee_party_state,
6959 payee_addr.province payee_party_province,
6960 payee_addr.county payee_party_county,
6961 payee_addr.postal_code payee_party_postal,
6962 payee_addr.country payee_party_country,
6963 docs.bank_charge_bearer bank_charge_bearer,
6964 docs.payment_reason_code payment_reason_code,
6965 docs.payment_method_code payment_method_cd,
6966 docs.payment_format_code payee_payment_format_cd,
6967 payeesite.party_site_name payee_party_site_name
6968 FROM
6969 IBY_DOCS_PAYABLE_ALL docs,
6970 IBY_PP_FIRST_PARTY_V payer,
6971 HZ_PARTIES payee,
6972 HZ_PARTY_SITES payeesite,
6973 CE_BANK_ACCOUNTS iba,
6974 CE_BANK_BRANCHES_V iba_bnk_branch,
6975 IBY_EXT_BANK_ACCOUNTS eba,
6976 IBY_ACCOUNT_OWNERS ow,
6977 HZ_PARTIES op,
6978 IBY_SYS_SECURITY_SUBKEYS baek,
6979 IBY_SECURITY_SEGMENTS baes,
6980 IBY_SYS_SECURITY_SUBKEYS baik,
6981 IBY_SECURITY_SEGMENTS bais,
6982 CE_BANK_BRANCHES_V eba_bank_branch,
6983 IBY_DELIVERY_CHANNELS_B del_chn,
6984
6985 /*
6986 * Fix for bug 5997016:
6987 *
6988 * The payee address cannot be always assumed to be stored in
6989 * HZ_LOCATIONS table (TCA).
6990 *
6991 * For employee type payees, the address is stored in
6992 * per_addresses (HR).
6993 *
6994 * The 'address source' column on the document payable identifies
6995 * the source of the address information -
6996 * TCA = address is stored in HZ_LOCATIONS
6997 * HR = address is stored in PER_ADDRESSES
6998 *
6999 * Therefore, we need to dynamically pick up the payee address
7000 * fields from the correct table. The SELECT statement below is
7001 * used to dynamically form the address table based on the
7002 * address source. This dynamic table is aliased as payee_addr.
7003 *
7004 * There is a dynamic address tabled formed in a similar manner
7005 * during the payment creation process as well [see method
7006 * IBY_PAYGROUP_PUB.auditPaymentData(..)].
7007 */
7008
7009 /*13728551 - Added a join to fecth the provisional site addresses as well.
7010 */
7011 (
7012 SELECT
7013
7014 /* payee add line1 */
7015 DECODE(
7016 doc.address_source,
7017
7018 -- supplier address line 1
7019 'TCA', payee_loc.address1,
7020
7021 -- employee add line 1
7022 DECODE
7023 (
7024 doc.employee_address_code,
7025
7026 -- employee home addr line 1
7027 'HOME', per_addr.address_line1,
7028
7029 -- employee office addr line 1
7030 'OFFICE',per_loc.address_line_1,
7031
7032 -- employee provisional site addressline1
7033 'PROVISIONAL',per_addr_prov.address_line1 ,
7034
7035 --address code not specified
7036 DECODE (per_addr.address_id,
7037 NULL, per_loc.address_line_1,
7038 per_addr.address_line1)
7039 )
7040
7041 ) add_line1,
7042
7043 /* payee add line2 */
7044 DECODE(
7045 doc.address_source,
7046
7047 -- supplier address line 2
7048 'TCA', payee_loc.address2,
7049
7050 -- employee add line 2
7051 DECODE
7052 (
7053 doc.employee_address_code,
7054
7055 -- employee home addr line 2
7056 'HOME', per_addr.address_line2,
7057
7058 -- employee office addr line 2
7059 'OFFICE',per_loc.address_line_2,
7060
7061 -- employee provisional site addressline1
7062 'PROVISIONAL',per_addr_prov.address_line2 ,
7063
7064 --address code not specified
7065 DECODE (per_addr.address_id,
7066 NULL, per_loc.address_line_2,
7067 per_addr.address_line2)
7068 )
7069 ) add_line2,
7070
7071
7072 /* payee add line3 */
7073 DECODE(
7074 doc.address_source,
7075
7076 -- supplier address line 3
7077 'TCA', payee_loc.address3,
7078
7079 -- employee add line 3
7080 DECODE
7081 (
7082 doc.employee_address_code,
7083
7084 -- employee home addr line 3
7085 'HOME', per_addr.address_line3,
7086
7087 -- employee office addr line 3
7088 'OFFICE',per_loc.address_line_3,
7089
7090 -- employee provisional site addressline1
7091 'PROVISIONAL',per_addr_prov.address_line3 ,
7092
7093 --address code not specified
7094 DECODE (per_addr.address_id,
7095 NULL, per_loc.address_line_3,
7096 per_addr.address_line3)
7097 )
7098
7099 ) add_line3,
7100
7101
7102 /* payee add line4 */
7103 DECODE(
7104 doc.address_source,
7105
7106 -- supplier address line 4
7107 'TCA', payee_loc.address4,
7108
7109 -- employee home/office/provisional addr line 4 (not available)
7110 null
7111
7112 ) add_line4,
7113
7114 /* payee city */
7115 DECODE(
7116 doc.address_source,
7117
7118 -- supplier city
7119 'TCA', payee_loc.city,
7120
7121 -- employee city
7122 DECODE
7123 (
7124 doc.employee_address_code,
7125
7126 -- employee home city
7127 'HOME', per_addr.town_or_city,
7128
7129 -- employee office city
7130 'OFFICE', per_loc.town_or_city,
7131
7132 -- employee provisional city
7133 'PROVISIONAL',per_addr_prov.town_or_city,
7134
7135 -- address code not specified
7136 DECODE (per_addr.address_id,
7137 NULL, per_loc.town_or_city,
7138 per_addr.town_or_city)
7139 )
7140
7141 ) city,
7142
7143
7144 /* payee county */
7145 DECODE(
7146 doc.address_source,
7147
7148 -- supplier county
7149 'TCA', payee_loc.county,
7150
7151 -- employee county
7152 (
7153 DECODE(
7154 doc.employee_address_code,
7155
7156 -- employee home county
7157 'HOME',
7158 DECODE(
7159 per_addr.style,
7160 'US', NVL(per_addr.region_1, ''),
7161 'US_GLB', NVL(per_addr.region_1, ''),
7162 'IE', NVL(ap_web_db_expline_pkg.
7163 getcountyprovince(
7164 per_addr.style,
7165 per_addr.region_1),
7166 ''),
7167 'IE_GLB', NVL(ap_web_db_expline_pkg.
7168 getcountyprovince(
7169 per_addr.style,
7170 per_addr.region_1),
7171 ''),
7172 'GB', NVL(ap_web_db_expline_pkg.
7173 getcountyprovince(
7174 per_addr.style,
7175 per_addr.region_1),
7176 ''),
7177 ''),
7178
7179 -- employee office county
7180 'OFFICE',
7181 DECODE(
7182 per_loc.style,
7183 'US', NVL(per_loc.region_1, ''),
7184 'US_GLB', NVL(per_loc.region_1, ''),
7185 'IE', NVL(ap_web_db_expline_pkg.
7186 getcountyprovince(
7187 per_loc.style,
7188 per_loc.region_1),
7189 ''),
7190 'IE_GLB', NVL(ap_web_db_expline_pkg.
7191 getcountyprovince(
7192 per_loc.style,
7193 per_loc.region_1),
7194 ''),
7195 'GB', NVL(ap_web_db_expline_pkg.
7196 getcountyprovince(
7197 per_loc.style,
7198 per_loc.region_1),
7199 ''),
7200 ''),
7201
7202 -- employee provisional county
7203 'PROVISIONAL',
7204 DECODE(
7205 per_addr_prov.style,
7206 'US', NVL(per_addr_prov.region_1, ''),
7207 'US_GLB', NVL(per_addr_prov.region_1, ''),
7208 'IE', NVL(ap_web_db_expline_pkg.
7209 getcountyprovince(
7210 per_addr_prov.style,
7211 per_addr_prov.region_1),
7212 ''),
7213 'IE_GLB', NVL(ap_web_db_expline_pkg.
7214 getcountyprovince(
7215 per_addr_prov.style,
7216 per_addr_prov.region_1),
7217 ''),
7218 'GB', NVL(ap_web_db_expline_pkg.
7219 getcountyprovince(
7220 per_addr_prov.style,
7221 per_addr_prov.region_1),
7222 ''),
7223 ''),
7224 --address code not specified
7225 decode(per_addr.address_id,
7226 NULL,DECODE(
7227 per_loc.style,
7228 'US', NVL(per_loc.region_1, ''),
7229 'US_GLB', NVL(per_loc.region_1, ''),
7230 'IE', NVL(ap_web_db_expline_pkg.
7231 getcountyprovince(
7232 per_loc.style,
7233 per_loc.region_1),
7234 ''),
7235 'IE_GLB', NVL(ap_web_db_expline_pkg.
7236 getcountyprovince(
7237 per_loc.style,
7238 per_loc.region_1),
7239 ''),
7240 'GB', NVL(ap_web_db_expline_pkg.
7241 getcountyprovince(
7242 per_loc.style,
7243 per_loc.region_1),
7244 ''),
7245 ''),
7246 DECODE(
7247 per_addr.style,
7248 'US', NVL(per_addr.region_1, ''),
7249 'US_GLB', NVL(per_addr.region_1, ''),
7250 'IE', NVL(ap_web_db_expline_pkg.
7251 getcountyprovince(
7252 per_addr.style,
7253 per_addr.region_1),
7254 ''),
7255 'IE_GLB', NVL(ap_web_db_expline_pkg.
7256 getcountyprovince(
7257 per_addr.style,
7258 per_addr.region_1),
7259 ''),
7260 'GB', NVL(ap_web_db_expline_pkg.
7261 getcountyprovince(
7262 per_addr.style,
7263 per_addr.region_1),
7264 ''),
7265 ''))
7266 )
7267 )
7268 ) county,
7269
7270 /* payee province */
7271 DECODE(
7272 doc.address_source,
7273
7274 -- supplier province
7275 'TCA', payee_loc.province,
7276
7277 -- employee province
7278 (
7279 DECODE(
7280
7281 doc.employee_address_code,
7282
7283 -- employee home province
7284 'HOME',
7285 DECODE(per_addr.style,
7286 'US', '',
7287 'US_GLB', '',
7288 'IE', '',
7289 'IE_GLB', '',
7290 'GB', '',
7291 'CA', NVL(per_addr.region_1, ''),
7292 'CA_GLB', NVL(per_addr.region_1, ''),
7293 'JP', NVL(per_addr.region_1, ''),
7294 NVL(ap_web_db_expline_pkg.
7295 getcountyprovince(
7296 per_addr.style,
7297 per_addr.region_1),
7298 '')
7299 ),
7300
7301 -- employee office province
7302 'OFFICE',
7303 DECODE(per_loc.style,
7304 'US', '',
7305 'US_GLB', '',
7306 'IE', '',
7307 'IE_GLB', '',
7308 'GB', '',
7309 'CA', NVL(per_loc.region_1, ''),
7310 'CA_GLB', NVL(per_loc.region_1, ''),
7311 'JP', NVL(per_loc.region_1, ''),
7312 NVL(ap_web_db_expline_pkg.
7313 getcountyprovince(
7314 per_loc.style,
7315 per_loc.region_1),
7316 '')
7317 ),
7318 -- employee provisional province
7319 'PROVISIONAL',
7320 DECODE(per_addr_prov.style,
7321 'US', '',
7322 'US_GLB', '',
7323 'IE', '',
7324 'IE_GLB', '',
7325 'GB', '',
7326 'CA', NVL(per_addr_prov.region_1, ''),
7327 'CA_GLB', NVL(per_addr_prov.region_1, ''),
7328 'JP', NVL(per_addr_prov.region_1, ''),
7329 NVL(ap_web_db_expline_pkg.
7330 getcountyprovince(
7331 per_addr_prov.style,
7332 per_addr_prov.region_1),
7333 '')
7334 ),
7335
7336 --address code not specified
7337 decode(per_addr.address_id,
7338 NULL,DECODE(per_loc.style,
7339 'US', '',
7340 'US_GLB', '',
7341 'IE', '',
7342 'IE_GLB', '',
7343 'GB', '',
7344 'CA', NVL(per_loc.region_1, ''),
7345 'CA_GLB', NVL(per_loc.region_1, ''),
7346 'JP', NVL(per_loc.region_1, ''),
7347 NVL(ap_web_db_expline_pkg.
7348 getcountyprovince(
7349 per_loc.style,
7350 per_loc.region_1),
7351 '')
7352 ),
7353 DECODE(per_addr.style,
7354 'US', '',
7355 'US_GLB', '',
7356 'IE', '',
7357 'IE_GLB', '',
7358 'GB', '',
7359 'CA', NVL(per_addr.region_1, ''),
7360 'CA_GLB', NVL(per_addr.region_1, ''),
7361 'JP', NVL(per_addr.region_1, ''),
7362 NVL(ap_web_db_expline_pkg.
7363 getcountyprovince(
7364 per_addr.style,
7365 per_addr.region_1),
7366 '')
7367 ))
7368 )
7369 )
7370 ) province,
7371
7372 /* payee state */
7373 DECODE(
7374 doc.address_source,
7375
7376 -- supplier state
7377 'TCA', payee_loc.state,
7378
7379 -- employee state
7380 (
7381 DECODE(
7382 doc.employee_address_code,
7383
7384 -- employee home state
7385 'HOME',
7386 DECODE(per_addr.style,
7387 'CA', '',
7388 'CA_GLB', '',
7389 NVL(per_addr.region_2, '')),
7390
7391 -- employee office state
7392 'OFFICE',
7393 DECODE(per_loc.style,
7394 'CA', '',
7395 'CA_GLB', '',
7396 NVL(per_loc.region_2, '')),
7397
7398 -- employee provisional state
7399 'PROVISIONAL',
7400 DECODE(per_addr_prov.style,
7401 'CA', '',
7402 'CA_GLB', '',
7403 NVL(per_addr_prov.region_2, '')),
7404
7405 --address code not specified
7406 decode(per_addr.address_id,
7407 NULL,DECODE(per_loc.style,
7408 'CA', '',
7409 'CA_GLB', '',
7410 NVL(per_loc.region_2, '')),
7411 DECODE(per_addr.style,
7412 'CA', '',
7413 'CA_GLB', '',
7414 NVL(per_addr.region_2, '')))
7415 )
7416 )
7417 ) state,
7418
7419 /* payee country */
7420 DECODE(
7421 doc.address_source,
7422
7423 -- supplier country
7424 'TCA', payee_loc.country,
7425
7426 -- employee country
7427 (
7428 DECODE(
7429 doc.employee_address_code,
7430
7431 -- employee home country
7432 'HOME', per_addr.country,
7433
7434 -- employee office country
7435 'OFFICE',per_loc.country,
7436 -- employee provisional country
7437 'PROVISIONAL',per_addr_prov.country,
7438
7439 --address code not specified
7440 DECODE (per_addr.address_id,
7441 NULL, per_loc.country,
7442 per_addr.country
7443 )
7444 )
7445 )
7446 ) country,
7447
7448 /* payee postal code */
7449 DECODE(
7450 doc.address_source,
7451
7452 -- supplier postal code
7453 'TCA', payee_loc.postal_code,
7454
7455 -- employee postal code
7456 (
7457 DECODE(
7458 doc.employee_address_code,
7459
7460 -- employee home postal code
7461 'HOME', per_addr.postal_code,
7462
7463 -- employee office postal code
7464 'OFFICE',per_loc.postal_code,
7465
7466 -- employee provisional postal code
7467 'PROVISIONAL',per_addr_prov.postal_code,
7468
7469 --address code not specified
7470 DECODE (per_addr.address_id,
7471 NULL, per_loc.postal_code,
7472 per_addr.postal_code
7473 )
7474 )
7475 )
7476 ) postal_code,
7477
7478
7479 /* payee address concat */
7480 DECODE(
7481 doc.address_source,
7482
7483 -- supplier address concat
7484 'TCA',
7485 payee_loc.address1
7486 || ', '
7487 || payee_loc.address2
7488 || ', '
7489 || payee_loc.address3
7490 || ', '
7491 || payee_loc.city
7492 || ', '
7493 || payee_loc.state
7494 || ', '
7495 || payee_loc.country
7496 || ', '
7497 || payee_loc.postal_code,
7498
7499 -- employee address concat
7500 (
7501 DECODE(
7502 doc.employee_address_code,
7503
7504 -- employee home address concat
7505 'HOME',
7506 per_addr.address_line1
7507 || ', '
7508 || per_addr.address_line2
7509 || ', '
7510 || per_addr.address_line3
7511 || ', '
7512 || per_addr.town_or_city
7513 || ', '
7514 || DECODE(
7515 per_addr.style,
7516 'CA', '',
7517 'CA_GLB', '',
7518 NVL(per_addr.region_2, '')
7519 )
7520 || ', '
7521 || per_addr.country
7522 || ', '
7523 || per_addr.postal_code,
7524
7525 -- employee office address concat
7526 'OFFICE',
7527 per_loc.address_line_1
7528 || ', '
7529 || per_loc.address_line_2
7530 || ', '
7531 || per_loc.address_line_3
7532 || ', '
7533 || per_loc.town_or_city
7534 || ', '
7535 || DECODE(
7536 per_loc.style,
7537 'CA', '',
7538 'CA_GLB', '',
7539 NVL(per_loc.region_2, '')
7540 )
7541 || ', '
7542 || per_loc.country
7543 || ', '
7544 || per_loc.postal_code,
7545
7546 -- employee provisional address concat
7547 'PROVISIONAL',
7548 per_addr_prov.address_line1
7549 || ', '
7550 || per_addr_prov.address_line2
7551 || ', '
7552 || per_addr_prov.address_line3
7553 || ', '
7554 || per_addr_prov.town_or_city
7555 || ', '
7556 || DECODE(
7557 per_addr_prov.style,
7558 'CA', '',
7559 'CA_GLB', '',
7560 NVL(per_addr_prov.region_2, '')
7561 )
7562 || ', '
7563 || per_addr_prov.country
7564 || ', '
7565 || per_addr_prov.postal_code,
7566
7567 -- address code not specified
7568 DECODE (per_addr.address_id,
7569 NULL, per_loc.address_line_1
7570 || ', '
7571 || per_loc.address_line_2
7572 || ', '
7573 || per_loc.address_line_3
7574 || ', '
7575 || per_loc.town_or_city
7576 || ', '
7577 || DECODE(
7578 per_loc.style,
7579 'CA', '',
7580 'CA_GLB', '',
7581 NVL(per_loc.region_2, '')
7582 )
7583 || ', '
7584 || per_loc.country
7585 || ', '
7586 || per_loc.postal_code,
7587
7588 per_addr.address_line1
7589 || ', '
7590 || per_addr.address_line2
7591 || ', '
7592 || per_addr.address_line3
7593 || ', '
7594 || per_addr.town_or_city
7595 || ', '
7596 || DECODE(
7597 per_addr.style,
7598 'CA', '',
7599 'CA_GLB', '',
7600 NVL(per_addr.region_2, '')
7601 )
7602 || ', '
7603 || per_addr.country
7604 || ', '
7605 || per_addr.postal_code)
7606 )
7607 )
7608 ) add_concat,
7609 doc.document_payable_id document_payable_id
7610
7611 FROM
7612 IBY_DOCS_PAYABLE_ALL doc,
7613
7614 /* Employee address related */
7615 HR_LOCATIONS per_loc,
7616 PER_ADDRESSES per_addr,
7617 PER_ADDRESSES per_addr_prov,
7618 PER_ALL_ASSIGNMENTS_F per_assgn,
7619
7620 /* Supplier address related */
7621 HZ_LOCATIONS payee_loc
7622 WHERE
7623 doc.payment_service_request_id = p_pay_service_request_id
7624 AND doc.employee_person_id = per_addr.person_id(+)
7625 AND per_addr.primary_flag(+) = 'Y'
7626 AND SYSDATE BETWEEN
7627 per_addr.date_from(+)
7628 AND NVL(per_addr.date_to(+), SYSDATE+1)
7629 AND doc.employee_person_id = per_assgn.person_id(+)
7630 AND per_assgn.location_id = per_loc.location_id(+)
7631 AND per_assgn.primary_flag(+) = 'Y'
7632 AND per_assgn.assignment_type(+) = 'E'
7633 AND (TRUNC(SYSDATE) BETWEEN
7634 per_assgn.effective_start_date(+)
7635 AND per_assgn.effective_end_date(+)
7636 )
7637 AND doc.remit_to_location_id = payee_loc.location_id(+)
7638 AND doc.employee_person_id = per_addr_prov.person_id(+)
7639 AND per_addr_prov.address_type(+) = 'M'
7640 AND SYSDATE BETWEEN
7641 per_addr_prov.date_from(+)
7642 AND NVL(per_addr_prov.date_to(+), SYSDATE+1)
7643 ) payee_addr
7644
7645 WHERE
7646 docs.payment_service_request_id = p_pay_service_request_id
7647 AND docs.document_payable_id = payee_addr.document_payable_id
7648 AND docs.legal_entity_id = payer.party_legal_id
7649 AND docs.payee_party_id = payee.party_id
7650 AND docs.party_site_id = payeesite.party_site_id (+)
7651 AND docs.internal_bank_account_id = iba.bank_account_id
7652 AND iba_bnk_branch.branch_party_id = iba.bank_branch_id
7653 AND docs.external_bank_account_id = eba.ext_bank_account_id(+)
7654 AND eba.bank_id = eba_bank_branch.bank_party_id(+)
7655 AND eba.branch_id = eba_bank_branch.branch_party_id(+)
7656 AND eba.ext_bank_account_id = ow.ext_bank_account_id(+)
7657 AND ow.primary_flag(+) = 'Y'
7658 AND nvl(ow.end_date, sysdate + 10) > sysdate
7659 AND ow.account_owner_party_id = op.party_id(+)
7660 AND eba.ba_num_sec_segment_id = baes.sec_segment_id(+)
7661 AND baes.sec_subkey_id = baek.sec_subkey_id(+)
7662 AND eba.iban_sec_segment_id = bais.sec_segment_id(+)
7663 AND bais.sec_subkey_id = baik.sec_subkey_id(+)
7664 AND docs.delivery_channel_code = del_chn.delivery_channel_code(+)
7665 ;
7666
7667 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7668
7669 print_debuginfo(l_module_name, 'Exit initDocDataForPPR');
7670 END IF;
7671
7672
7673 EXCEPTION
7674 WHEN OTHERS THEN
7675
7676 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7677
7678 print_debuginfo(l_module_name, 'Exit initDocDataForPPR',
7679 FND_LOG.LEVEL_UNEXPECTED);
7680 print_debuginfo(l_module_name, 'SQL code: ' || SQLCODE,
7681 FND_LOG.LEVEL_UNEXPECTED);
7682 print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
7683 FND_LOG.LEVEL_UNEXPECTED);
7684
7685 END IF;
7686
7687 /* Bug: 14837647 - Start
7688 Added the following lines to raise the unhandle exception.
7689 */
7690 -- ROLLBACK;
7691 RAISE;
7692 /* Bug: 14837647 - End */
7693
7694 END initDocDataForPPR;
7695
7696 END IBY_VALIDATIONSETS_PUB;