DBA Data[Home] [Help]

PACKAGE BODY: APPS.IBY_PAYGROUP_PUB

Source


1 PACKAGE BODY iby_paygroup_pub AS
2 /*$Header: ibypaygb.pls 120.177.12020000.12 2013/04/09 12:40:00 kchavali ship $*/
3 
4  --
5  -- Declare global variables
6  --
7  G_PKG_NAME CONSTANT VARCHAR2(30) := 'IBY_PAYGROUP_PUB';
8 
9 
10  --
11  -- List of document statuses that are used / set in this
12  -- module (payment creation flow).
13  --
14  DOC_STATUS_VALIDATED    CONSTANT VARCHAR2(100) := 'VALIDATED';
15  DOC_STATUS_PAY_CREATED  CONSTANT VARCHAR2(100) := 'PAYMENT_CREATED';
16  DOC_STATUS_CA_FAILED    CONSTANT VARCHAR2(100) := 'FAILED_BY_CALLING_APP';
17  DOC_STATUS_RELN_FAIL    CONSTANT VARCHAR2(100) := 'FAILED_BY_RELATED_DOCUMENT';
18  DOC_STATUS_PAY_VAL_FAIL CONSTANT VARCHAR2(100) := 'PAYMENT_FAILED_VALIDATION';
19  DOC_STATUS_FAIL_BY_REJLVL CONSTANT VARCHAR2(100)
20                                                 := 'FAILED_BY_REJECTION_LEVEL';
21 
22  --
23  -- List of payment statuses that are used / set in this
24  -- module (payment creation flow).
25  --
26  PAY_STATUS_REJECTED       CONSTANT VARCHAR2(100) := 'REJECTED';
27  PAY_STATUS_FAIL_VALID     CONSTANT VARCHAR2(100) := 'FAILED_VALIDATION';
28  PAY_STATUS_CREATED        CONSTANT VARCHAR2(100) := 'CREATED';
29  PAY_STATUS_CA_FAILED      CONSTANT VARCHAR2(100) := 'FAILED_BY_CALLING_APP';
30  PAY_STATUS_FAIL_BY_REJLVL CONSTANT VARCHAR2(100)
31                                                 := 'FAILED_BY_REJECTION_LEVEL';
32  PAY_STATUS_MODIFIED       CONSTANT VARCHAR2(100) := 'MODIFIED';
33  PAY_STATUS_REMOVED        CONSTANT VARCHAR2(100) := 'REMOVED';
34  --
35  -- List of payment request statuses that are set in this
36  -- module (payment creation flow).
37  --
38  REQ_STATUS_PAY_CRTD      CONSTANT VARCHAR2(100) := 'PAYMENTS_CREATED';
39  REQ_STATUS_FAIL_PAY_CR   CONSTANT VARCHAR2(100) := 'FAILED_PAYMENT_VALIDATION';
40  REQ_STATUS_USER_REVW     CONSTANT VARCHAR2(100) := 'PENDING_REVIEW';
41  REQ_STATUS_USER_REVW_ERR CONSTANT VARCHAR2(100) :=
42                                        'PENDING_REVIEW_PMT_VAL_ERRORS';
43  REQ_STATUS_RETRY_PMT_CREAT CONSTANT VARCHAR2(100)
44                                                  := 'RETRY_PAYMENT_CREATION';
45 
46  --
47  -- List of rejection level system options  that are possible for
48  -- this module (payment creation flow).
49  --
50  REJ_LVL_REQUEST  CONSTANT VARCHAR2(100) := 'REQUEST';
51  REJ_LVL_PAYMENT  CONSTANT VARCHAR2(100) := 'PAYMENT';
52  REJ_LVL_PAYEE    CONSTANT VARCHAR2(100) := 'PAYEE';
53  REJ_LVL_NONE     CONSTANT VARCHAR2(100) := 'NONE';
54 
55  -- Transaction types (for inserting into IBY_TRANSACTION_ERRORS table)
56  TRXN_TYPE_DOC   CONSTANT VARCHAR2(100) := 'DOCUMENT_PAYABLE';
57  TRXN_TYPE_PMT   CONSTANT VARCHAR2(100) := 'PAYMENT';
58  l_DocsInPmtCount  NUMBER;
59 
60 
61  l_trx_pmt_index      BINARY_INTEGER :=0;
62  l_calling_app_procedure    VARCHAR2(255);
63  TYPE getSDAPTabType IS TABLE OF IBY_DOCS_PAYABLE_ALL.document_status%TYPE INDEX BY BINARY_INTEGER;
64 
65  sdap_tbl  getSDAPTabType;
66 
67   TYPE getMaturityDateTabType IS TABLE OF VARCHAR2(30) INDEX BY VARCHAR2(30);
68 
69  maturity_date_tbl  getMaturityDateTabType;
70 
71  l_fail_dop_tbl failDocsOfPaymentTabType;
72  l_fail_docs_tbl failDocsTabType;
73 
74   pmt_id  IBY_PAYMENTS_ALL.PAYMENT_ID%TYPE;
75  pmt_amt  IBY_PAYMENTS_ALL.PAYMENT_AMOUNT%TYPE;
76 
77 
78   TYPE resetErrtblType IS TABLE OF IBY_PAYMENTS_ALL.PAYMENT_SERVICE_REQUEST_ID%TYPE INDEX BY BINARY_INTEGER;
79 
80   resetErrtbl  resetErrtblType;
81 
82 
83 
84  /* DS for auditPayment Data caching */
85 
86 
87 
88  	TYPE l_payer_info_rec IS RECORD(
89 		payer_party_number IBY_PAYMENTS_ALL.PAYER_PARTY_NUMBER%TYPE,
90 		payer_party_site_name IBY_PAYMENTS_ALL.PAYER_PARTY_SITE_NAME%TYPE,
91 		payer_legal_entity_name IBY_PAYMENTS_ALL.PAYER_LEGAL_ENTITY_NAME%TYPE,
92 		payer_tax_registration_num IBY_PAYMENTS_ALL.PAYER_TAX_REGISTRATION_NUM%TYPE,
93 		payer_le_registration_num IBY_PAYMENTS_ALL.PAYER_LE_REGISTRATION_NUM%TYPE,
94 		payer_party_id IBY_PAYMENTS_ALL.PAYER_PARTY_ID%TYPE,
95 		payer_location_id IBY_PAYMENTS_ALL.PAYER_LOCATION_ID%TYPE,
96 		payer_party_attr_category IBY_PAYMENTS_ALL.PAYER_PARTY_ATTR_CATEGORY%TYPE,
97 		payer_le_attr_category    IBY_PAYMENTS_ALL.PAYER_LE_ATTR_CATEGORY%TYPE,
98 		payer_abbreviated_agency_code IBY_PAYMENTS_ALL.PAYER_ABBREVIATED_AGENCY_CODE%TYPE,
99 		payer_federal_us_employer_id IBY_PAYMENTS_ALL.PAYER_FEDERAL_US_EMPLOYER_ID%TYPE
100 	);
101 
102 	 TYPE l_payer_info_tbl_type IS TABLE OF l_payer_info_rec INDEX BY BINARY_INTEGER;
103       	 l_payer_info_tbl  l_payer_info_tbl_type;
104 
105 
106 
107 	TYPE l_payer_acct_info_rec IS RECORD(
108 
109  	int_bank_name               IBY_PAYMENTS_ALL.INT_BANK_NAME%TYPE,
110 	int_bank_number             IBY_PAYMENTS_ALL.INT_BANK_NUMBER%TYPE,
111 	int_bank_branch_number       IBY_PAYMENTS_ALL.INT_BANK_BRANCH_NUMBER%TYPE,
112 	int_bank_branch_name         IBY_PAYMENTS_ALL.INT_BANK_BRANCH_NAME%TYPE,
113 	int_eft_swift_code            IBY_PAYMENTS_ALL.INT_EFT_SWIFT_CODE%TYPE,
114 	int_bank_account_number       IBY_PAYMENTS_ALL.INT_BANK_ACCOUNT_NUMBER%TYPE,
115 	int_bank_account_name         IBY_PAYMENTS_ALL.INT_BANK_ACCOUNT_NAME%TYPE,
116 	int_bank_account_iban          IBY_PAYMENTS_ALL.INT_BANK_ACCOUNT_IBAN%TYPE,
117 	int_bank_acct_agency_loc_code  IBY_PAYMENTS_ALL.INT_BANK_ACCT_AGENCY_LOC_CODE%TYPE,
118 	int_bank_branch_party_id      IBY_PAYMENTS_ALL.INT_BANK_BRANCH_PARTY_ID%TYPE,
119 	int_bank_alt_name	      IBY_PAYMENTS_ALL.INT_BANK_ALT_NAME%TYPE,
120 	int_bank_branch_alt_name      IBY_PAYMENTS_ALL.INT_BANK_BRANCH_ALT_NAME%TYPE,
121 	int_bank_account_alt_name      IBY_PAYMENTS_ALL.INT_BANK_ACCOUNT_ALT_NAME%TYPE,
122 	int_bank_account_num_elec      IBY_PAYMENTS_ALL.INT_BANK_ACCOUNT_NUM_ELEC%TYPE,
123 	int_bank_branch_location_id    IBY_PAYMENTS_ALL.INT_BANK_BRANCH_LOCATION_ID%TYPE,
124 	int_bank_branch_eft_user_num   IBY_PAYMENTS_ALL.INT_BANK_BRANCH_EFT_USER_NUM%TYPE,
125 	int_bank_branch_rfc_identifier  IBY_PAYMENTS_ALL.INT_BANK_BRANCH_RFC_IDENTIFIER%TYPE
126 	);
127 
128 	 TYPE l_payer_acct_info_tbl_type IS TABLE OF l_payer_acct_info_rec INDEX BY BINARY_INTEGER;
129       	 l_payer_acct_info_tbl  l_payer_acct_info_tbl_type;
130 
131 
132 
133 	TYPE l_vendor_info_rec IS RECORD(
134      	payee_site_alternate_name    IBY_PAYMENTS_ALL.PAYEE_SITE_ALTERNATE_NAME%TYPE,
135 	payee_supplier_number	     IBY_PAYMENTS_ALL.PAYEE_SUPPLIER_NUMBER%TYPE,
136 	payee_first_party_reference  IBY_PAYMENTS_ALL.PAYEE_FIRST_PARTY_REFERENCE%TYPE,
137 	payee_supplier_attr_category IBY_PAYMENTS_ALL.payee_supplier_attr_category%TYPE,
138 	payee_supplier_id            IBY_PAYMENTS_ALL.payee_supplier_id%TYPE,
139 	payee_le_registration_num         IBY_PAYMENTS_ALL.payee_le_registration_num%TYPE,
140 	payee_supplier_site_name      IBY_PAYMENTS_ALL.payee_supplier_site_name%TYPE,
141 	payee_spplr_site_attr_category      IBY_PAYMENTS_ALL.payee_spplr_site_attr_category%TYPE
142 	);
143 
144         TYPE l_vendor_info_tbl_type IS TABLE OF l_vendor_info_rec INDEX BY VARCHAR2(4000);
145 	 l_vendor_info_tbl  l_vendor_info_tbl_type;
146 
147   TYPE l_vendor_tax_reg_info_rec IS RECORD(
148 	    payee_tax_registration_num   IBY_PAYMENTS_ALL.payee_tax_registration_num%TYPE
149 	);
150 
151   type l_vendor_tax_reg_info_tbl_type is table of l_vendor_tax_reg_info_rec index by varchar2(4000);
152      l_vendor_tax_reg_info_tbl  l_vendor_tax_reg_info_tbl_type;
153 
154 	TYPE l_payee_info_rec IS RECORD(
155 	payee_party_number      IBY_PAYMENTS_ALL.payee_party_number%TYPE,
156 	payee_party_name        IBY_PAYMENTS_ALL.payee_party_name%TYPE,
157 	payee_name		IBY_PAYMENTS_ALL.payee_name%TYPE,
158 	payee_alt_name          IBY_PAYMENTS_ALL.PAYEE_ALTERNATE_NAME%TYPE,
159   payee_party_atr_cat  IBY_PAYMENTS_ALL.payee_party_attr_category%TYPE,
160   beneficiary_name IBY_PAYMENTS_ALL.BENEFICIARY_name%TYPE
161 
162 );
163 
164 	 TYPE l_payee_info_tbl_type IS TABLE OF l_payee_info_rec INDEX BY BINARY_INTEGER;
165 	 l_payee_info_tbl  l_payee_info_tbl_type;
166 
167 
168 	TYPE l_payee_site_rec IS RECORD(
169 	payee_spplr_site_attr_category      IBY_PAYMENTS_ALL.payee_spplr_site_attr_category%TYPE,
170 	payee_party_site_name      IBY_PAYMENTS_ALL.payee_party_site_name%TYPE,
171         payee_addressee               IBY_PAYMENTS_ALL.payee_addressee%TYPE
172 	);
173 
174 	 TYPE l_payee_site_tbl_type IS TABLE OF l_payee_site_rec INDEX BY BINARY_INTEGER;
175 	 l_payee_site_tbl  l_payee_site_tbl_type;
176 
177 	TYPE l_payee_addr_rec IS RECORD(
178  	payee_address1	     IBY_PAYMENTS_ALL.payee_address1%TYPE,
179 	payee_address2     IBY_PAYMENTS_ALL.payee_address2%TYPE,
180 	payee_address3     IBY_PAYMENTS_ALL.payee_address3%TYPE,
181 	payee_address4     IBY_PAYMENTS_ALL.payee_address4%TYPE,
182 	payee_city     IBY_PAYMENTS_ALL.payee_city%TYPE,
183 	payee_county      IBY_PAYMENTS_ALL.payee_county%TYPE,
184 	payee_province       IBY_PAYMENTS_ALL.payee_province%TYPE,
185 	payee_state        IBY_PAYMENTS_ALL.payee_state%TYPE,
186 	payee_country      IBY_PAYMENTS_ALL.payee_country%TYPE,
187 	payee_postal_code  IBY_PAYMENTS_ALL.payee_postal_code%TYPE,
188 	payee_address_concat  IBY_PAYMENTS_ALL.inv_payee_address_concat%TYPE
189 	);
190 
191 	TYPE l_payee_addr_tbl_type IS TABLE OF l_payee_addr_rec INDEX BY VARCHAR2(200);
192 	l_payee_addr_tbl  l_payee_addr_tbl_type;
193 
194 
195 	TYPE l_payee_acct_rec IS RECORD(
196 	ext_bank_name      IBY_PAYMENTS_ALL.ext_bank_name%TYPE,
197 	ext_bank_number      IBY_PAYMENTS_ALL.ext_bank_number%TYPE,
198 	ext_branch_number      IBY_PAYMENTS_ALL.ext_branch_number%TYPE,
199 	ext_bank_branch_name      IBY_PAYMENTS_ALL.ext_bank_branch_name%TYPE,
200 	ext_bank_account_number      IBY_PAYMENTS_ALL.ext_bank_account_number%TYPE,
201 	ext_bank_account_name      IBY_PAYMENTS_ALL.ext_bank_account_name%TYPE,
202 	ext_bank_account_iban_number      IBY_PAYMENTS_ALL.ext_bank_account_iban_number%TYPE,
203 	ext_eft_swift_code      IBY_PAYMENTS_ALL.ext_eft_swift_code%TYPE,
204 	ext_bank_account_type      IBY_PAYMENTS_ALL.ext_bank_account_type%TYPE,
205 	ext_bank_acct_pmt_factor_flag      IBY_PAYMENTS_ALL.ext_bank_acct_pmt_factor_flag%TYPE,
206 	ext_bank_acct_owner_party_id      IBY_PAYMENTS_ALL.ext_bank_acct_owner_party_id%TYPE,
207 	ext_bank_branch_party_id      IBY_PAYMENTS_ALL.ext_bank_branch_party_id%TYPE,
208 	ext_bank_alt_name      IBY_PAYMENTS_ALL.ext_bank_alt_name%TYPE,
209 	ext_bank_branch_alt_name      IBY_PAYMENTS_ALL.ext_bank_branch_alt_name%TYPE,
210 	ext_bank_account_alt_name      IBY_PAYMENTS_ALL.ext_bank_account_alt_name%TYPE,
211 	ext_bank_account_num_elec      IBY_PAYMENTS_ALL.ext_bank_account_num_elec%TYPE,
212 	ext_bank_branch_location_id      IBY_PAYMENTS_ALL.ext_bank_branch_location_id%TYPE,
213 	ext_bank_acct_owner_party_name      IBY_PAYMENTS_ALL.ext_bank_acct_owner_party_name%TYPE
214 	);
215 
216 	TYPE l_payee_acct_tbl_type IS TABLE OF l_payee_acct_rec INDEX BY BINARY_INTEGER;
217 	l_payee_acct_tbl  l_payee_acct_tbl_type;
218 
219 	TYPE l_remit_rec IS RECORD(
220 	remit_advice_delivery_method      IBY_PAYMENTS_ALL.remit_advice_delivery_method%TYPE,
221 	remit_advice_email         IBY_PAYMENTS_ALL.remit_advice_email%TYPE,
222 	remit_advice_fax        IBY_PAYMENTS_ALL.remit_advice_fax%TYPE,
223 	declaration_exch_rate_type       IBY_PAYMENTS_ALL.declaration_exch_rate_type%TYPE,
224 	declaration_format       IBY_PAYMENTS_ALL.declaration_format%TYPE,
225 	bank_instruction1_format_value      IBY_PAYMENTS_ALL.bank_instruction1_format_value%TYPE,
226 	bank_instruction2_format_value      IBY_PAYMENTS_ALL.bank_instruction2_format_value%TYPE,
227 	payment_profile_acct_name       IBY_PAYMENTS_ALL.payment_profile_acct_name%TYPE,
228 	payment_profile_sys_name     IBY_PAYMENTS_ALL.payment_profile_sys_name%TYPE
229 	);
230 
231 	TYPE l_remit_tbl_type IS TABLE OF l_remit_rec INDEX BY BINARY_INTEGER;
232 	l_remit_tbl  l_remit_tbl_type;
233 
234 	TYPE l_ppr_rec IS RECORD(
235 	payment_process_request_name    IBY_PAYMENTS_ALL.payment_process_request_name%TYPE,
236 	source_product                  IBY_PAYMENTS_ALL.source_product%TYPE
237 	);
238 
239 	TYPE l_ppr_tbl_type IS TABLE OF l_ppr_rec INDEX BY BINARY_INTEGER;
240 	l_ppr_tbl  l_ppr_tbl_type;
241 
242 	TYPE l_del_rec IS RECORD(
243 	delivery_channel_format_value      IBY_PAYMENTS_ALL.DELIVERY_CHANNEL_FORMAT_VALUE%TYPE
244 	);
245 
246 
247 	TYPE l_del_tbl_type IS TABLE OF l_del_rec INDEX BY VARCHAR2(300);
248 	l_del_tbl  l_del_tbl_type;
249 
250 	TYPE l_org_rec IS RECORD(
251 	org_name      IBY_PAYMENTS_ALL.org_name%TYPE
252 	);
253 
254 
255 	TYPE l_org_tbl_type IS TABLE OF l_org_rec INDEX BY BINARY_INTEGER;
256 	l_org_tbl  l_org_tbl_type;
257 
258 
259 	TYPE l_pmt_reason_rec IS RECORD(
260         payment_reason_format_value      IBY_PAYMENTS_ALL.payment_reason_format_value%TYPE
261 	);
262 
263 
264 	TYPE l_pmt_reason_tbl_type IS TABLE OF l_pmt_reason_rec INDEX BY VARCHAR2(300);
265 	l_pmt_reason_tbl  l_pmt_reason_tbl_type;
266 
267 
268  /* DS for audit payment data caching */
269 
270 /*Bug 8209474 Type is being created to hold payee id for Invalid Payees*/
271 
272 TYPE l_payee_tbl_type IS TABLE OF IBY_PAYMENTS_ALL.ext_payee_id%TYPE  index by binary_integer;
273 l_payeeTab l_payee_tbl_type; --To Hold Validation Failed payment's Payee information
274 l_invalid_payee_index BINARY_INTEGER;
275 /*Type is being created to hold payeedid for Invalid Payees*/
276 
277 --AWT Enh 16296267
278 TYPE l_payee_tbl_type_awt IS TABLE OF IBY_PAYMENTS_ALL.payment_reference_number%TYPE  index by binary_integer;
279 l_payeeAwt l_payee_tbl_type_awt; --To Hold Validation Failed payment's Payee information that has range based awt
280 l_invalid_payee_awt_index BINARY_INTEGER;
281 
282 
283  CURSOR check_hook_pmt
284  IS
285  select
286  payment_id,
287  payment_amount
288  from
289  IBY_HOOK_PAYMENTS_T
290  ;
291 
292 
293   G_CURRENT_RUNTIME_LEVEL      CONSTANT NUMBER       := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
294   G_LEVEL_UNEXPECTED           CONSTANT NUMBER       := FND_LOG.LEVEL_UNEXPECTED;
295   G_LEVEL_ERROR                CONSTANT NUMBER       := FND_LOG.LEVEL_ERROR;
296   G_LEVEL_EXCEPTION            CONSTANT NUMBER       := FND_LOG.LEVEL_EXCEPTION;
297   G_LEVEL_EVENT                CONSTANT NUMBER       := FND_LOG.LEVEL_EVENT;
298   G_LEVEL_PROCEDURE            CONSTANT NUMBER       := FND_LOG.LEVEL_PROCEDURE;
299   G_LEVEL_STATEMENT            CONSTANT NUMBER       := FND_LOG.LEVEL_STATEMENT;
300 
301  --
302  -- Forward declarations
303  --
304  PROCEDURE print_debuginfo(
305               p_module     IN VARCHAR2,
306               p_debug_text IN VARCHAR2,
307               p_debug_level IN VARCHAR2  DEFAULT FND_LOG.LEVEL_STATEMENT
308               );
309 
310  -- Get Employee Full Name from HR tables
311 
312  FUNCTION Get_Employee_Full_Name(p_person_id IN NUMBER,p_party_id IN NUMBER,p_party_name IN VARCHAR2)
313  RETURN VARCHAR2
314  IS
315      l_module_name           CONSTANT VARCHAR2(200) := G_PKG_NAME || '.Get_Employee_Full_Name';
316      p_emp_full_name VARCHAR2(500);
317  BEGIN
318      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
319  print_debuginfo(l_module_name, 'Fetching employee full name from HR for party_id ' || p_party_id || ' person_id ' || p_person_id);
320 
321 
322      END IF;
323 
324      SELECT per.full_name
325      INTO p_emp_full_name
326      FROM per_all_people_f per
327      WHERE per.person_id = p_person_id
328       AND per.party_id = p_party_id
329       AND sysdate BETWEEN per.effective_start_date
330       AND per.effective_end_date;
331 
332      RETURN p_emp_full_name;
333 
334  EXCEPTION
335   WHEN OTHERS THEN
336      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
337  print_debuginfo(l_module_name, 'EXCEPTION : Unable to fetch employee full name from HR');
338      END IF;
339 
340      RETURN p_party_name;
341 
342  END Get_Employee_Full_Name;
343 
344 
345 /*--------------------------------------------------------------------
346  | NAME:
347  |     updateCommonAttribues
348  |
349  | PURPOSE:
350  |
351  |
352  |
353  | PARAMETERS:
354  |     IN
355  |
356  |
357  |     OUT
358  |
359  |
360  | RETURNS:
361  |
362  | NOTES:
363  |
364  |     Implementing only for Delivery Channel.
365  |
366  *---------------------------------------------------------------------*/
367  PROCEDURE updateCommonAttribues(
368      l_trx_audit_index IN BINARY_INTEGER
369      )
370  IS
371  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||'.updateCommonAttribues';
372  l_settlement_pr    iby_payments_all.SETTLEMENT_PRIORITY%type;
373 
374  BEGIN
375   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
376      print_debuginfo(l_module_name, 'ENTER');
377 	 END IF;
378 	     if IBY_PAYGROUP_PUB.pmtTable.settlement_priority(l_trx_audit_index) IS NULL then
379 	        BEGIN
380 			SELECT DISTINCT(SETTLEMENT_PRIORITY)
381 			INTO
382 			l_settlement_pr
383 			FROM IBY_DOCS_PAYABLE_ALL
384 			WHERE
385 			PAYMENT_ID = IBY_PAYGROUP_PUB.pmtTable.PAYMENT_ID(l_trx_audit_index);
386 		EXCEPTION
387 		  WHEN TOO_MANY_ROWS THEN
388 		      l_settlement_pr :=NULL;
389 		END;
390 
391                 IBY_PAYGROUP_PUB.pmtTable.settlement_priority(l_trx_audit_index):=l_settlement_pr;
392 
393 	     end if;
394 		  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
395      print_debuginfo(l_module_name, 'EXIT');
396 	 END IF;
397 
398  END updateCommonAttribues;
399 
400 
401 /*--------------------------------------------------------------------
402  | NAME:
403  |     createPayments
404  |
405  | PURPOSE:
406  |     Entry point for payment creation (F6) flow. All payment grouping
407  |     rules are handled within this method.
408  |
409  |
410  | PARAMETERS:
411  |     IN
412  |
413  |
414  |     OUT
415  |
416  |
417  | RETURNS:
418  |
419  | NOTES:
420  |
421  *---------------------------------------------------------------------*/
422  PROCEDURE createPayments(
423      p_payment_request_id         IN IBY_PAY_SERVICE_REQUESTS.
424                                          payment_service_request_id%TYPE,
425      p_pmt_rejection_level        IN IBY_INTERNAL_PAYERS_ALL.
426                                          payment_rejection_level_code%TYPE,
427      p_review_proposed_pmts_flag  IN IBY_INTERNAL_PAYERS_ALL.
428                                          require_prop_pmts_review_flag%TYPE,
429      p_override_complete_point    IN VARCHAR2,
430      p_bill_payable_flag          IN         VARCHAR2,
431      p_maturity_date              IN         DATE,
432      p_calling_procedure          IN         VARCHAR2,
433      x_return_status      IN OUT NOCOPY VARCHAR2)
434  IS
435 
436  l_module_name           CONSTANT VARCHAR2(200) := G_PKG_NAME ||
437                                                        '.createPayments';
438 
439  l_ca_payreq_cd            VARCHAR2(255) := '';
440  l_ca_id                   NUMBER(15)    := 0;
441  l_all_pmts_success_flag   BOOLEAN       := FALSE;
442  l_all_pmts_failed_flag    BOOLEAN       := FALSE;
443 
444  /* rejection level system options */
445  l_rejection_level         VARCHAR2(200);
446  l_review_pmts_flag        VARCHAR2(1)   := 'N';
447 
448  l_paymentTab        IBY_PAYGROUP_PUB.paymentTabType;
449  l_docsInPmtTab      IBY_PAYGROUP_PUB.docsInPaymentTabType;
450 
451  /* these two are passed to calling app via hook */
452  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
453  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
454 
455  /* payment request imposed limits on payments */
456  l_payReqCriteria    IBY_PAYGROUP_PUB.payReqImposedCriteria;
457 
458  /* central bank reporting requirements imposed on each payment */
459  --l_cbrTab            IBY_PAYGROUP_PUB.centralBankReportTabType;
460 
461  /* holds the error messages against failed documents */
462  l_docErrorTab       IBY_VALIDATIONSETS_PUB.docErrorTabType;
463  l_docTokenTab       IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType;
464  l_DocsInPmtCount    NUMBER;
465 
466  p_trx_pmt_line_index BINARY_INTEGER;
467 
468  l_payreq_status     VARCHAR2(500);
469  l_prehook_cnt       NUMBER;
470 
471  l_calc_jp_bank_charges    VARCHAR2(500);
472  l_call_ap_awt_callout    VARCHAR2(500);
473 
474  l_antcptd_val_date DATE;
475 
476  CURSOR c_pmtIdStatus(p_pmt_service_req_id NUMBER) is
477  SELECT
478  payment_id,
479  payment_status
480  FROM
481  iby_payments_all
482  WHERE payment_service_request_id = p_pmt_service_req_id
483  ;
484 
485  BEGIN
486 
487      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
488      print_debuginfo(l_module_name, 'ENTER');
489 
490      print_debuginfo(l_module_name, 'Payment request id : '
491          || p_payment_request_id);
492      END IF;
493 
494      l_payreq_status := get_payreq_status(p_payment_request_id);
495 
496      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
497 	print_debuginfo(l_module_name, 'Payment request status: '
498          || l_payreq_status);
499 
500      END IF;
501 
502 
503 
504      /*
505       * Reset Payments Table Data Structure for each call
506       * to Create Payments procedure.
507       * Fix for bug 13614825.
508       */
509      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
510 	print_debuginfo(l_module_name, 'Resetting the Payments Table Data structure used for Cache.'
511          || l_payreq_status);
512 
513      END IF;
514 	 l_trx_pmt_index := 0;
515 	 delete_pmtTable;
516 
517 
518      /*
519       * Do not perform grouping if the payments are being
520       * re-built.
521       *
522       * Fix for bug 4946181.
523       */
524 
525      /*
526       * Fix for bug 5331527:
527       *
528       * PPRs in REQ_STATUS_PEN_REV_PMT_VAL need to be
529       * rebuilt.
530       *
531       * Therefore, call rebuildPayments(..) for such PPRs.
532       */
533       l_calling_app_procedure := '';
534      IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
535         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
536              print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so calling performDocumentGrouping Directly');
537         END IF;
538           /*
539           * Group the documents of the payment request into payments.
540           */
541          l_calling_app_procedure := 'IBY_DISBURSE_SINGLE_PMT_PKG';
542          performDocumentGrouping(p_payment_request_id,
543 	 --l_paymentTab,
544          l_ca_id, l_ca_payreq_cd, l_payReqCriteria
545 --          ,l_cbrTab
546             );
547 
548 
549 
550      /*
551       * Bug Number:8813346
552       * IMPORTANT CHECK FOR SINGLE PAYMENTS:
553       *
554       * After hardcoded grouping not more than one payment should be
555       * created from the given documents for the single payment flow.
556       *
557       * This is because the calling app is expected to have performed
558       * the hardcoded grouping before the single payment API is invoked.
559       *
560       * If we have created more than one payment from the given document,
561       * it is an error and return failure.
562       */
563      IF (IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT <> 1) THEN
564 
565          print_debuginfo(l_module_name, 'Application of hardcoded '
566              || 'grouping rules did not generate exactly one payment. '
567              || 'Only one payment can be created for single payments. '
568              || 'Payment creation failed.'
569              );
570 
571          x_return_status := FND_API.G_RET_STS_ERROR;
572 
573          APP_EXCEPTION.RAISE_EXCEPTION;
574 
575      END IF;
576 
577 
578 
579 
580          updateDocsWithPaymentID;   -- new approach , without GT needs to be overridden
581      ELSE
582         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
583              print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so verifying the l_payreq_status before calling performDocumentGrouping');
584         END IF;
585          IF (l_payreq_status <> REQ_STATUS_RETRY_PMT_CREAT AND
586              l_payreq_status <> REQ_STATUS_USER_REVW_ERR)  THEN
587 
588              /*
589               * Group the documents of the payment request into payments.
590               */
591              performDocumentGrouping(p_payment_request_id,
592              --l_paymentTab,
593              l_ca_id, l_ca_payreq_cd, l_payReqCriteria
594     --          ,l_cbrTab
595                 );
596 
597              updateDocsWithPaymentID;   -- new approach , without GT needs to be overridden
598 
599              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
600              print_debuginfo(l_module_name, 'After grouping '
601                  || IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT   || ' payment(s) were created from '
602                  || ' document(s) for payment request '
603                  || p_payment_request_id || '.');
604               END IF;
605          ELSE
606 
607              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
608              print_debuginfo(l_module_name, 'Not performing grouping '
609                  || 'for payment request '
610                  || p_payment_request_id
611                  || ' as payments are being re-built ..');
612              END IF;
613 
614              rebuildPayments(p_payment_request_id, l_paymentTab,
615                  l_ca_id, l_ca_payreq_cd, l_payReqCriteria
616     --         , l_cbrTab
617                );
618 
619               populatepmtTable(p_payment_request_id);
620 
621          END IF;
622       END IF;
623      /*
624       * Fix for bug 5357948:
625       *
626       * Search for common attributes of the documents
627       * of each payment, and set the corresponding
628       * attribute on the parent payment itself if
629       * such a common attribute is found.
630       */
631        /* commenting out the code to pull out common values [due date, delivery channel, uri]
632  	* and moving the logic to insertDocIntoPayment API.
633  	* This code was called even if grouping rules for these 3 attributes were not
634  	* set - to get common attributes to be used later */
635 
636       --sweepCommonPmtAttributes(l_paymentTab, l_docsInPmtTab);
637 
638      /*
639       * Set the default attributes for the created payments.
640       */
641 
642       /* Build pmts perf issue -
643        * Move the code to initializePmts to insertDocIntoPayment - when
644        * creating a new payment */
645 
646   --   initializePmts(l_paymentTab);
647 
648      /*
649       * Handle credit memos
650       */
651 
652      /*
653       * Update: Credit memo handling is now performed at the calling
654       * application itself.
655       * - rameshsh, 3/29/2005
656       */
657      --printDocsInPmtTab(l_docsInPmtTab);
658      --performCreditMemoHandling(l_paymentTab, l_docsInPmtTab);
659      --printDocsInPmtTab(l_docsInPmtTab);
660 
661      /*
662       * Maturity date calculation
663       *
664       * For bills payable
665       *   a.k.a promissory notes
666       *   a.k.a future dated payments
667       */
668      --performMaturityDateCalculation(l_paymentTab, l_docsInPmtTab);
669      --performMaturityDateCalculation(l_paymentTab);
670 
671      /*
672       * Fix for bug 5935493:
673       *
674       * Payment validations are dependent upon finding the
675       * payments in the IBY_PAYMENTS_ALL table. Therefore, insert
676       * the payments from the PLSQL table into the
677       * IBY_PAYMENTS_ALL table.
678       *
679       * Central bank reporting could be implemented via a hook
680       * that is expecting payments to be populated in
681       * IBY_PAYMENTS_ALL table. Therefore, payments need to
682       * inserted before performing central bank reporting as well.
683       */
684 
685         /* not needed now as updateDocsWithPaymentID is moved up and we are not inserting
686        * into IBY_PAYMENTS_ALL table now
687        */
688 
689 	/*
690 
691      IF (l_payreq_status <> REQ_STATUS_RETRY_PMT_CREAT AND
692          l_payreq_status <> REQ_STATUS_USER_REVW_ERR)  THEN
693 
694          insertPayments(l_paymentTab);
695 	  */
696 
697 
698          /*
699           * Fix for bug 5972585:
700           *
701           * Update the documents payable that are part of the created
702           * payments with payment ids.
703           *
704           * This is normally done in performDBUpdates(..) call at
705           * the end of this method. However, some customers might
706           * want to do custom validations on documents that are
707           * part of the created payments. Therefore, update the
708           * documents with payment ids before the payment validation
709           * call.
710           *
711           * We do this even before central bank reporting because
712           * again the customer could potentially want to retrieve
713           * documents that are part of the created payments in the
714           * central bank reporting hook.
715           */
716          /*
717 	 updateDocsWithPaymentID(l_docsInPmtTab);
718          updateDocsWithPaymentID;
719      END IF;
720 
721      */
722 
723      FOR p_trx_pmt_line_index IN nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99)
724      LOOP
725       IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
726         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
727              print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so not calling performMaturityDateCalculation');
728         END IF;
729         IF (UPPER(p_bill_payable_flag) = 'Y') THEN
730 
731          /*
732           * We can use index 1 to access the payment because
733           * only one payment is expected to be created
734           * (this being a single payment).
735           */
736          IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_pmt_line_index) := p_maturity_date;
737 	 l_antcptd_val_date := NULL;
738 
739 	 /*
740                   * Bug :: 8994772
741                    If Maturity Date is set
742 		   anticipated_value_date = maturity_date +float_days.
743   	 */
744 	 BEGIN
745   	     SELECT nvl(anticipated_float,0) + IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_pmt_line_index)
746 	     INTO l_antcptd_val_date
747 	     FROM iby_payment_methods_b
748 	     WHERE payment_method_code = IBY_PAYGROUP_PUB.pmtTable.payment_method_code(p_trx_pmt_line_index);
749            EXCEPTION
750 	     WHEN OTHERS THEN
751 	       --If no value is found then anticipated value date is not set.
752                l_antcptd_val_date := NULL;
753 	   END;
754 
755           IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(p_trx_pmt_line_index) :=l_antcptd_val_date;
756          /* End of 8994772*/
757 
758          /*
759           * Fix for bug 5334222:
760           *
761           * Set the bills payable flag to 'Y' whenever the
762           * maturity date is set.
763           */
764          IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(p_trx_pmt_line_index) := 'Y';
765 
766                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
767        print_debuginfo(l_module_name, 'Payment '
768                        || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
769                        || ' is not a future dated payment'
770                        );
771               END IF;
772 
773          ELSE
774      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
775              print_debuginfo(l_module_name, 'Not setting maturity '
776                  || 'date for payment '
777                  || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
778                  || ' as it is not a bill payable.'
779                  );
780      END IF;
781 
782 	 /*  FOR SINGLE PAYMENTS:: If maturity Date is not set then
783 	 Anticipated Value Date = payment_date+ float_date.
784   	 */
785 	 BEGIN
786   	     SELECT nvl(anticipated_float,0) + IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_pmt_line_index)
787 	     INTO l_antcptd_val_date
788 	     FROM iby_payment_methods_b
789 	     WHERE payment_method_code = IBY_PAYGROUP_PUB.pmtTable.payment_method_code(p_trx_pmt_line_index);
790            EXCEPTION
791 	     WHEN OTHERS THEN
792 	       --If no value is found then anticipated value date is not set.
793                l_antcptd_val_date := NULL;
794 	   END;
795 
796           IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(p_trx_pmt_line_index) :=l_antcptd_val_date;
797          /* End of 8994772*/
798 
799          END IF;
800       ELSE
801         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
802              print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so calling performMaturityDateCalculation');
803         END IF;
804        performMaturityDateCalculation(p_trx_pmt_line_index);
805 
806         --Set anticipated_value_date Calculation once we calculate maturity_date
807 	 /*
808                   * Bug :: 8994772
809  	  	  * Populating Anticipated Value Date.
810  	  	  * Anticipated Value Date is usually set as anticipated
811 	  	  * Float (in Payment Methods) + Payment Date
812  	  	  * There are two exceptions to the given rule ::
813                   * 1. FUTURE DATED PAYMENT :: If payment is bills payable :: Anticipated_float + maturity_date
814      	          * 2. IMMEDIATE :: Take the greatest of iby_docs_payable_all
815      	          * and this will be anticipated_value_date. In this case
816      	          * immediate payments is associated with single payments
817      	          * hence payment_date = anticipated_value_date.
818   	 */
819 	 l_antcptd_val_date := NULL;
820         IF (IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(p_trx_pmt_line_index) = 'Y' )
821         THEN
822 
823 	 --The Maturity date should exist.
824 	 BEGIN
825   	     SELECT nvl(anticipated_float,0) + IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_pmt_line_index)
826 	     INTO l_antcptd_val_date
827 	     FROM iby_payment_methods_b
828 	     WHERE payment_method_code = IBY_PAYGROUP_PUB.pmtTable.payment_method_code(p_trx_pmt_line_index);
829            EXCEPTION
830 	     WHEN OTHERS THEN
831 	       --If no value is found then anticipated value date is  set to payment date.
832                l_antcptd_val_date := IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_pmt_line_index);
833 	   END;
834 
835           IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(p_trx_pmt_line_index) :=l_antcptd_val_date;
836 	 ELSE
837             BEGIN
838   	     SELECT nvl(anticipated_float,0) + IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_pmt_line_index)
839 	     INTO l_antcptd_val_date
840 	     FROM iby_payment_methods_b
841 	     WHERE payment_method_code = IBY_PAYGROUP_PUB.pmtTable.payment_method_code(p_trx_pmt_line_index);
842            EXCEPTION
843 	     WHEN OTHERS THEN
844 	       --If no value is found then anticipated value date is  set to payment date.
845                l_antcptd_val_date := IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_pmt_line_index);
846 	   END;
847 
848           IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(p_trx_pmt_line_index) :=l_antcptd_val_date;
849          END IF;
850          /* End of 8994772*/
851 
852       END IF;
853 
854        /* Bug: 10109218 - Update attributes which were missed due to payment grouping number*/
855        updateCommonAttribues(p_trx_pmt_line_index);
856        auditPaymentData(p_trx_pmt_line_index);
857        performCentralBankReporting(p_trx_pmt_line_index);
858 --       applyPaymentValidationSets(p_payment_request_id, p_trx_pmt_line_index ,l_docErrorTab, l_docTokenTab);
859   --     performPayReqBasedValidations(l_payReqCriteria, p_trx_pmt_line_index, l_docErrorTab, l_docTokenTab);
860 
861      END LOOP;
862 
863     IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
864         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
865              print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so calling insertPayments Directly');
866         END IF;
867         insertPayments;
868     ELSE
869         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
870              print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so verifying the l_payreq_status before calling insertPayments');
871         END IF;
872             IF (l_payreq_status <> REQ_STATUS_RETRY_PMT_CREAT AND
873                l_payreq_status <> REQ_STATUS_USER_REVW_ERR)  THEN
874 
875             insertPayments;
876 
877             ELSE
878 
879             updatePayments;
880 
881             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
882             print_debuginfo(l_module_name, 'Empty')	;
883     END IF;
884             END IF;
885     END IF;
886 
887      FOR p_trx_pmt_line_index IN nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99)
888       LOOP
889 
890       applyPaymentValidationSets(p_payment_request_id, p_trx_pmt_line_index ,l_docErrorTab, l_docTokenTab);
891       negativePmtAmountCheck(p_trx_pmt_line_index, l_docErrorTab, l_docTokenTab);
892       IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
893         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
894              print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so not calling performPayReqBasedValidations');
895         END IF;
896       ELSE
897         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
898              print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so calling performPayReqBasedValidations');
899         END IF;
900       performPayReqBasedValidations(l_payReqCriteria, p_trx_pmt_line_index, l_docErrorTab, l_docTokenTab);
901       END IF;
902      END LOOP;
903 
904      adjustSisterDocsAndPmts(l_docErrorTab,
905          l_docTokenTab);
906 
907      -- to update the changes done in adjustSisDocs
908 
909      updatePayments;
910 
911      /*
912       * Call post-payment creation hook. This hook will pass
913       * the created payments to the calling application for
914       * approval/adjustment.
915       *
916       * The adjusted payments are read back and inserted into
917       * IBY_PAYMENTS_LL table.
918       *
919       * This is a general hook that is called for all other
920       * products except AP. For AP special hooks are called
921       * below.
922       */
923 
924      IF (l_ca_id <> 200) THEN
925 
926          /*
927           * Only successful payments are passed to be passed to
928           * to the calling application via the hook / callout.
929           *
930           * From the existing list of all payments, create new data
931           * structures that only store successful payments. This
932           * 'success only' list of payments will be passed to the
933           * calling application.
934           *
935           * This method writes the payment data to global temp tables.
936           */
937          /*performPreHookProcess(l_ca_payreq_cd, l_ca_id, l_paymentTab,
938              l_docsInPmtTab, l_hookPaymentTab, l_hookDocsInPmtTab);*/
939 
940          performPreHookProcess(l_ca_payreq_cd, p_payment_request_id, l_prehook_cnt, l_ca_id
941 	   --l_paymentTab,
942            --l_hookPaymentTab
943 	   );
944 
945          IF(l_prehook_cnt <> 0) THEN
946 
947          /*
948           * Hook to call external application for implementation of the
949           * following functionality:
950           *
951           * 1. Bank charge calculation
952           * 2. Tax withtholding
953           *
954           * Any other miscellaneous correction of payment/document data
955           * is also allowed in the hook.
956           */
957          callHook(p_payment_request_id);
958 
959          /*
960           * The external app may decide not to pay a document(s)
961           * within a payment, or may decide not to make a payment(s).
962           * In such cases, the external app will set the 'don't pay flag'
963           * and provide a 'don't pay reason' at the document / payment
964           * level (as appropriate) in the provided data structures.
965           *
966           * If a document(s) is marked as don't pay, then we must
967           * adjust the payment amount appropriately.
968           *
969           * Also, some documents are related via 'payment grouping number'.
970           * All documents that are related must be failed and their
971           * constituent payment amounts must be adjusted
972           *
973           * This method reads the payment data from global temp tables.
974           */
975          /*performPostHookProcess(l_paymentTab, l_docsInPmtTab, l_hookPaymentTab,
976              l_hookDocsInPmtTab, l_docErrorTab, l_docTokenTab); */
977 
978          performPostHookProcess(
979 	   --  l_paymentTab,
980 	   --  l_hookPaymentTab,
981              l_ca_payreq_cd,
982 	     l_prehook_cnt,
983              l_docErrorTab,
984 	     l_docTokenTab);
985 
986        ELSE
987             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
988                  print_debuginfo(l_module_name, 'Value of l_prehook_cnt is:' || l_prehook_cnt || 'so not calling any hook');
989             END IF;
990        END IF;
991      END IF; -- if calling product <> AP
992 
993      /*
994       * SPECIAL HOOKS FOR AP:
995       *
996       * + Perform special handling for Japanese bank charges.
997       * + Invoke extended witholdings procedure (AWT)
998       */
999      IF (l_ca_id = 200) THEN
1000 
1001          /*handleJapaneseBankCharges(l_ca_payreq_cd, l_ca_id,
1002              l_paymentTab, l_docsInPmtTab, l_docErrorTab, l_docTokenTab);
1003 
1004          performExtendedWitholding(
1005 	 l_ca_payreq_cd, l_ca_id,
1006              l_paymentTab, l_docsInPmtTab, l_docErrorTab, l_docTokenTab);*/
1007 
1008        IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
1009             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1010                  print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so not calling any hook');
1011             END IF;
1012        ELSE
1013             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1014                  print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so calling hooks');
1015             END IF;
1016 
1017             l_calc_jp_bank_charges := 'N';
1018 
1019             BEGIN
1020             SELECT  'Y'
1021             INTO l_calc_jp_bank_charges
1022             FROM dual
1023             WHERE    EXISTS (SELECT 1
1024                                    FROM ap_system_parameters_all asp
1025                                              , IBY_PAYMENTS_ALL pmt
1026                                  WHERE pmt.PAYMENT_SERVICE_REQUEST_ID = p_payment_request_id
1027                                       AND pmt.org_id = asp.org_id
1028                                        AND nvl(asp.use_bank_charge_flag,'N') = 'Y');
1029             EXCEPTION
1030               WHEN NO_DATA_FOUND THEN
1031                 l_calc_jp_bank_charges := 'N';
1032 				 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1033                 print_debuginfo(l_module_name, 'No Data Found Exception Occured for the Query');
1034 				END IF;
1035               WHEN OTHERS THEN
1036                l_calc_jp_bank_charges := 'N';
1037 			    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1038                print_debuginfo(l_module_name, 'Exception Occured for the Query');
1039 			   END IF;
1040            END;
1041              IF(l_calc_jp_bank_charges = 'Y') THEN
1042                  handleJapaneseBankCharges(
1043                  l_ca_payreq_cd,
1044                  p_payment_request_id,
1045                  l_ca_id,
1046                  --l_paymentTab,
1047                    l_docErrorTab,
1048                    l_docTokenTab);
1049              END IF;
1050          BEGIN
1051             SELECT	'Y'
1052               INTO l_call_ap_awt_callout
1053               FROM dual
1054               WHERE	 EXISTS (SELECT 1
1055                                           FROM ap_system_parameters_all asp,
1056                                           IBY_PAYMENTS_ALL pmt
1057                                           WHERE pmt.PAYMENT_SERVICE_REQUEST_ID = p_payment_request_id
1058                                                     AND pmt.org_id = asp.org_id
1059                                                      AND nvl(asp.allow_awt_flag,'N') = 'Y');
1060         EXCEPTION
1061            WHEN NO_DATA_FOUND THEN
1062                   l_call_ap_awt_callout := 'N';
1063 				   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1064                   print_debuginfo(l_module_name, 'No Data Found Exception Occured for the Query');
1065 				  END IF;
1066            WHEN OTHERS THEN
1067                  l_call_ap_awt_callout := 'N';
1068 				  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1069                  print_debuginfo(l_module_name, 'Exception Occured for the Query');
1070 				 END IF;
1071         END;
1072          IF(l_call_ap_awt_callout = 'Y') THEN
1073              performExtendedWitholding(l_ca_payreq_cd,
1074                                      p_payment_request_id,
1075                                     l_ca_id,
1076                                  --l_paymentTab,
1077                                  l_docErrorTab,
1078                                  l_docTokenTab);
1079          END IF;
1080     END IF;
1081   END IF;
1082 
1083      /*
1084       * Flag payments that require separate remittance
1085       * advice.
1086       */
1087      --flagSeparateRemitAdvicePmts(l_paymentTab);
1088 
1089      -- calling the API without any parameters, as IBY PAYMENTS ALL table is used to fetch data */
1090 
1091      flagSeparateRemitAdvicePmts(l_ca_payreq_cd, p_payment_request_id);
1092 
1093      /*
1094       * Get the rejection level system option and pass
1095       * it to subsequent methods.
1096       */
1097 
1098      /*
1099       * Fix for bug 5302318:
1100       *
1101       * Request level system option overrides enterprise
1102       * level setting.
1103       */
1104 
1105      /*
1106       * If the user has provided the pmt rejection level on
1107       * the request use it.
1108       *
1109       * If not, get the rejection level system option at the
1110       * enterprose level.
1111       */
1112       IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
1113             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1114                  print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so assigning the default values');
1115             END IF;
1116             /*
1117                 * Get the rejection level system option and pass
1118                 * it to subsequent methods.
1119                 */
1120 
1121                /*
1122                 * For single payments, there is no concept of
1123                 * payment rejection level system option. In the
1124                 * single payments flow, only one payment will be
1125                 * created, so if the payment fails, the request
1126                 * fails.
1127                 *
1128                 * So for single payments, the payment rejection
1129                 * level is implictly 'REQUEST'.
1130                 */
1131                l_rejection_level := 'REQUEST';
1132 
1133                /*
1134                 * There is no question of reviewing the payment for
1135                 * single payments. Review payments flag is only
1136                 * applicable to standard payments built by the
1137                 * Build Program.
1138                 *
1139                 * Hardcode the review payments flag to 'N' for single
1140                 * payments.
1141                 */
1142                l_review_pmts_flag := 'N';
1143        ELSE
1144             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1145                  print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so calling raiseBizEvents');
1146             END IF;
1147            IF (p_pmt_rejection_level IS NOT NULL) THEN
1148 
1149                /*
1150                 * Use the payment rejection level passed in
1151                 * with the payment service request (if available).
1152                 */
1153                l_rejection_level := p_pmt_rejection_level;
1154                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1155        print_debuginfo(l_module_name, 'Using payment rejection '
1156                    || 'level [request-level setting]: '
1157                    || l_rejection_level
1158                    );
1159                END IF;
1160            ELSE
1161 
1162                /*
1163                 * If the payment rejection level is not passed
1164                 * in with the payment service request, derive
1165                 * the payment rejection level setting at the
1166                 * enterprise level.
1167                 */
1168                l_rejection_level := getPmtRejLevelSysOption();
1169                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1170        print_debuginfo(l_module_name, 'Using payment rejection '
1171                    || 'level [neterprise-level setting]: '
1172                    || l_rejection_level
1173                    );
1174                 END IF;
1175            END IF;
1176 
1177            /*
1178             * Get the review payments flag system option at
1179             * the enterprise level. This may be overridden if
1180             * request level review pmts flag is populated.
1181             */
1182            l_review_pmts_flag := getReviewPmtsSysOption();
1183 
1184            /*
1185             * Adjust the review payments flag based on the request level
1186             * parameter. If the request level parameter (if provided)
1187             * will override the system level setting.
1188             */
1189            IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1190                print_debuginfo(l_module_name, 'Review payments flag '
1191                || '[enterprise-level setting]: '
1192                || l_review_pmts_flag
1193                );
1194            END IF;
1195            /*
1196             * Fix for bug 5021996:
1197             *
1198             * There are two flags related to review of proposed payments -
1199             * a. enterprise level setting (use by default).
1200             * b. request level parameter (overrides default).
1201             *
1202             * If user has not provided this flag as a request level
1203             * parameter, use the enterprise wide setting for this flag.
1204             *
1205             * Possible values for request level review proposed payment flag:
1206             * 1. Y - Stop payments for review
1207             * 2. N - Do not stop payments for review
1208             * 3. X - User has not provided a value, use enterprise setting.
1209             */
1210            IF (UPPER(p_review_proposed_pmts_flag) = 'Y'  OR
1211                UPPER(p_review_proposed_pmts_flag) = 'N') THEN
1212 
1213                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1214        print_debuginfo(l_module_name, 'Review payments flag '
1215                    || '[request-level setting]: '
1216                    || p_review_proposed_pmts_flag
1217                    || ' (this will override enterprise level setting)'
1218                    );
1219 
1220            END IF;
1221 
1222                l_review_pmts_flag := p_review_proposed_pmts_flag;
1223 
1224            END IF;
1225 
1226            IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1227        print_debuginfo(l_module_name, 'Final review payments flag '
1228                || 'setting: '
1229                || l_review_pmts_flag
1230                );
1231            END IF;
1232      /*
1233       * All payments for this payment request have been
1234       * created and stored in a PLSQL table. Now write these
1235       * payments to the database.
1236       *
1237       * Similarly, update the documents table by providing a
1238       * payment id to each document.
1239       */
1240 
1241      /*
1242       * Pass in the current ppr status. This is used
1243       * to determine the next status in some cases.
1244       */
1245      x_return_status := l_payreq_status;
1246      -- deleting the pmtTable DS and repopulating with just payment status from iby_payments_all
1247 
1248 
1249      /*OPEN  c_pmtIdStatus(p_payment_request_id);
1250      FETCH c_pmtIdStatus BULK COLLECT INTO
1251            IBY_PAYGROUP_PUB.pmtTable.payment_id,
1252            IBY_PAYGROUP_PUB.pmtTable.payment_status;
1253      CLOSE c_pmtIdStatus;*/
1254      END IF;
1255 
1256      performDBUpdates(p_payment_request_id, l_rejection_level,
1257          l_review_pmts_flag,
1258 	 --l_paymentTab,
1259          l_all_pmts_success_flag,
1260          l_all_pmts_failed_flag, x_return_status,
1261          l_docErrorTab, l_docTokenTab
1262          );
1263 
1264 
1265      /*
1266       * Finally, raise business events to inform the calling app
1267       * if any payments have failed.
1268       *
1269       * Note: this should be the last call after database records
1270       * have been inserted / updated. This is because you cannot
1271       * 'rollback' a business event once raised.
1272       */
1273      IF(p_calling_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
1274             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1275                  print_debuginfo(l_module_name, 'Call has come from IBY_SINGPAY_PUB API so not calling raiseBizEvents');
1276             END IF;
1277        ELSE
1278             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1279                  print_debuginfo(l_module_name, 'Call has come from IBY_DISBURSE_SUBMIT_PUB_PKG API so calling raiseBizEvents');
1280             END IF;
1281          raiseBizEvents(p_payment_request_id, l_ca_payreq_cd, l_ca_id,
1282              l_rejection_level, l_review_pmts_flag,
1283              l_all_pmts_success_flag, l_all_pmts_failed_flag);
1284      END IF;
1285      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1286 	 print_debuginfo(l_module_name, 'EXIT');
1287      END IF;
1288  EXCEPTION
1289  WHEN OTHERS THEN
1290    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
1291                  FND_LOG.LEVEL_UNEXPECTED);
1292              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
1293                  FND_LOG.LEVEL_UNEXPECTED);
1294    print_debuginfo(l_module_name, l_module_name||':Exception while creating payments');
1295    RAISE;
1296  END createPayments;
1297 
1298 /*--------------------------------------------------------------------
1299  | NAME:
1300  |     performDocumentGrouping
1301  |
1302  | PURPOSE:
1303  |
1304  |
1305  |
1306  | PARAMETERS:
1307  |     IN
1308  |
1309  |
1310  |     OUT
1311  |
1312  |
1313  | RETURNS:
1314  |
1315  | NOTES:
1316  |
1317  *---------------------------------------------------------------------*/
1318  PROCEDURE performDocumentGrouping(
1319      p_payment_request_id   IN IBY_PAY_SERVICE_REQUESTS.
1320                                          payment_service_request_id%TYPE,
1321      x_paymentTab           IN OUT NOCOPY IBY_PAYGROUP_PUB.paymentTabType,
1322      x_docsInPmtTab         IN OUT NOCOPY IBY_PAYGROUP_PUB.docsInPaymentTabType,
1323      x_ca_id                IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
1324                                               calling_app_id%TYPE,
1325      x_ca_payreq_cd         IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
1326                                               call_app_pay_service_req_code
1327                                               %TYPE,
1328      x_payReqCriteria       IN OUT NOCOPY IBY_PAYGROUP_PUB.
1329                                               payReqImposedCriteria
1330 
1331 -- , x_cbrTab               IN OUT NOCOPY IBY_PAYGROUP_PUB.
1332 --                                             centralBankReportTabType
1333      )
1334  IS
1335  l_module_name           CONSTANT VARCHAR2(200) := G_PKG_NAME ||
1336                                                    '.performDocumentGrouping';
1337  l_first_record          VARCHAR2(1)   := 'Y';
1338  l_payment_id            NUMBER(15)    := 0;
1339  l_payment_total         NUMBER(15)    := 0;
1340  l_payment_docs_cnt      NUMBER(10)    := 0;
1341  l_sup_msg_flag          VARCHAR2(1)   := 'N';
1342  l_bnk_chg_brer_flag     VARCHAR2(1)   := 'N';
1343  l_delv_chnl_flag        VARCHAR2(1)   := 'N';
1344  l_express_pmt_flag      VARCHAR2(1)   := 'N';
1345  l_pmt_details_flag      VARCHAR2(1)   := 'N';
1346  l_pmt_details_len       NUMBER(15)    := 0;
1347  l_pmt_det_formula       VARCHAR2(2000):= 0;
1348  l_max_docs_flag         VARCHAR2(1)   := 'N';
1349  l_max_docs_limit        NUMBER(15)    := 0;
1350  l_docs_in_pmt_count     NUMBER(15)    := 0;
1351  l_unique_remit_id_flag  VARCHAR2(1)   := 'N';
1352  l_pmt_reason_flag       VARCHAR2(1)   := 'N';
1353  l_due_date_flag         VARCHAR2(1)   := 'N';
1354  l_prom_note_flag        VARCHAR2(1)   := 'N';
1355 
1356  l_profile_id            IBY_PAYMENT_PROFILES.payment_profile_id%type;
1357 
1358  /*
1359   * Used to substitute null values in date comparisons.
1360   * It is assumed that year 5100 = doomsday.
1361   */
1362  l_impossible_date       DATE := TO_DATE('01/01/5100 10:25:55',
1363                                      'MM/DD/YYYY HH24:MI:SS');
1364 
1365  l_bank_inst1_code       IBY_PAYMENTS_ALL.bank_instruction1_code%TYPE;
1366  l_bank_inst2_code       IBY_PAYMENTS_ALL.bank_instruction1_code%TYPE;
1367  l_pmt_txt_msg1          IBY_PAYMENTS_ALL.payment_text_message1%TYPE;
1368  l_pmt_txt_msg2          IBY_PAYMENTS_ALL.payment_text_message2%TYPE;
1369  l_pmt_txt_msg3          IBY_PAYMENTS_ALL.payment_text_message3%TYPE;
1370 
1371  l_processing_type       VARCHAR2(100);  -- CHECK | ELECTRONIC
1372  l_calc_doc_detail       VARCHAR2(1000); -- Stores details for a single doc
1373 
1374  /* these are related to central bank reporting */
1375  l_decl_option             VARCHAR2(100) := '';
1376  l_decl_only_fx_flag       VARCHAR2(1)   := '';
1377  l_decl_curr_fx_rate_type  VARCHAR2(255) := '';
1378  l_decl_curr_code          VARCHAR2(10)  := '';
1379  l_decl_threshold_amount   NUMBER(15)    := 0;
1380 /*
1381  l_cbrRec                  IBY_PAYGROUP_PUB.centralBankReportRecType;
1382  l_cbrTab                  IBY_PAYGROUP_PUB.centralBankReportTabType;
1383  l_cbr_rec_exists          BOOLEAN       := FALSE;
1384 */
1385 
1386  l_ca_payreq_cd            VARCHAR2(255) := '';
1387  l_ca_id                   NUMBER(15)    := 0;
1388  l_all_pmts_success_flag   BOOLEAN       := FALSE;
1389  l_all_pmts_failed_flag    BOOLEAN       := FALSE;
1390  l_le_id                   NUMBER(15)    := 0;
1391 
1392  /* rejection level system options */
1393  l_rejection_level         VARCHAR2(200);
1394  l_review_pmts_flag        VARCHAR2(1)   := 'N';
1395 
1396  l_paymentRec        IBY_PAYMENTS_ALL%ROWTYPE;
1397  l_docsInPmtRec      IBY_PAYGROUP_PUB.docsInPaymentRecType;
1398 
1399 
1400  /*
1401   * These two are related data structures. Each row in paymentTabType
1402   * PLSQL table is used in inserting a row into the IBY_PAYMENTS_ALL
1403   * table.
1404   *
1405   * Since the IBY_PAYMENTS_ALL table does not contain a document id, a
1406   * separate data structure is needed to keep track of the documents
1407   * that are part of a payment. This information is tracked in the
1408   * docsInPaymentTabType table. The rows in docsInPaymentTabType are
1409   * used to update the rows in IBY_DOCS_PAYABLE_ALL table with
1410   * payment ids.
1411   *
1412   *            x_paymentTab                        x_docsInPmtTab
1413   *       (insert into IBY_PAYMENTS_ALL)          (update IBY_DOCS_PAYABLE)
1414   * /-------------------------------------\       /------------\
1415   * |Payment|Payment|..|Payment|Docs   |..|       |Payment|Doc |
1416   * |Id     |Profile|..|Amount |Payable|..|       |Id     |Id  |
1417   * |       |Id     |..|       |Count  |..|       |       |    |
1418   * |-------------------------------------|       |------------|
1419   * |   4000|     10|  |    550|      3|  |       |   4000| 501|
1420   * |       |       |  |       |       |  |       |   4000| 504|
1421   * |       |       |  |       |       |  |       |   4000| 505|
1422   * |-------|-------|--|-------|-------|--|       |-------|----|
1423   * |   4001|     10|  |1063.70|     19|  |       |   4001| 502|
1424   * |       |       |  |       |       |  |       |   4001| 509|
1425   * |       |       |  |       |       |  |       |   4001| 511|
1426   * |       |       |  |       |       |  |       |   4001| 523|
1427   * |       |       |  |       |       |  |       |     : |  : |
1428   * |-------|-------|--|-------|-------|--|       |-------|----|
1429   * |    :  |     : |  |    :  |     : |  |       |     : |  : |
1430   * \_______|_______|__|_______|_______|__/       \_______|____/
1431   *
1432   * Combining these two structures into one structure is messy
1433   * because you cannot directly use the combined data structure for
1434   * bulk updates.
1435   */
1436 
1437  /* these two are passed to calling app via hook */
1438  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
1439  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
1440 
1441  /* holds the error messages against failed documents */
1442  l_docErrorTab       IBY_VALIDATIONSETS_PUB.docErrorTabType;
1443 
1444  /* holds list of internal bank accounts with corresponding legal entity id */
1445  l_bankAcctLETab     bankAccountLETabType;
1446 
1447  l_commonAttributes commonAttributesTabType;
1448 
1449  /* previous document attributes */
1450  prev_doc_id                 iby_docs_payable_all.document_payable_id%TYPE;
1451  prev_ca_id                  iby_docs_payable_all.calling_app_id%TYPE;
1452  prev_ca_doc_id1             iby_docs_payable_all.
1453                                  calling_app_doc_unique_ref1%TYPE;
1454  prev_ca_doc_id2             iby_docs_payable_all.
1455                                  calling_app_doc_unique_ref2%TYPE;
1456  prev_ca_doc_id3             iby_docs_payable_all.
1457                                  calling_app_doc_unique_ref3%TYPE;
1458  prev_ca_doc_id4             iby_docs_payable_all.
1459                                  calling_app_doc_unique_ref4%TYPE;
1460  prev_ca_doc_id5             iby_docs_payable_all.
1461                                  calling_app_doc_unique_ref5%TYPE;
1462  prev_pp_tt_cd               iby_docs_payable_all.pay_proc_trxn_type_code%TYPE;
1463  prev_pmt_grp_num            iby_docs_payable_all.payment_grouping_number%TYPE;
1464  prev_pmt_method_cd          iby_docs_payable_all.payment_method_code%TYPE;
1465  prev_doc_pmt_currency       iby_docs_payable_all.payment_currency_code%TYPE;
1466  prev_doc_pmt_amount         iby_docs_payable_all.payment_amount%TYPE;
1467  prev_int_bank_acct_id       iby_docs_payable_all.
1468                                  internal_bank_account_id%TYPE;
1469  prev_ext_bank_acct_id       iby_docs_payable_all.
1470                                  external_bank_account_id%TYPE;
1471  prev_payee_id               iby_docs_payable_all.payee_party_id%TYPE;
1472  prev_payee_site_id          iby_docs_payable_all.party_site_id%TYPE;
1473  prev_supplier_site_id       iby_docs_payable_all.supplier_site_id%TYPE;
1474  prev_remit_loc_id           iby_docs_payable_all.remit_to_location_id%TYPE;
1475  prev_ext_payee_id           iby_docs_payable_all.ext_payee_id%TYPE;
1476  prev_org_id                 iby_docs_payable_all.org_id%TYPE;
1477  prev_org_type               iby_docs_payable_all.org_type%TYPE;
1478  prev_profile_id             iby_docs_payable_all.payment_profile_id%TYPE;
1479  prev_pay_alone_flag         iby_docs_payable_all.exclusive_payment_flag%TYPE;
1480  prev_supplier_msg1          iby_docs_payable_all.remittance_message1%TYPE;
1481  prev_supplier_msg2          iby_docs_payable_all.remittance_message2%TYPE;
1482  prev_supplier_msg3          iby_docs_payable_all.remittance_message3%TYPE;
1483  prev_bnk_chg_bearer         iby_docs_payable_all.bank_charge_bearer%TYPE;
1484  prev_delivery_channel       iby_docs_payable_all.delivery_channel_code%TYPE;
1485  prev_settle_priority        iby_docs_payable_all.settlement_priority%TYPE;
1486  prev_uri                    iby_docs_payable_all.
1487                                  unique_remittance_identifier%TYPE;
1488  prev_uri_checkdigits        iby_docs_payable_all.uri_check_digit%TYPE;
1489  prev_pmt_reason_code        iby_docs_payable_all.payment_reason_code%TYPE;
1490  prev_pmt_reason_commts      iby_docs_payable_all.payment_reason_comments%TYPE;
1491  prev_pmt_function           iby_docs_payable_all.payment_function%TYPE;
1492  prev_pmt_date               iby_docs_payable_all.payment_date%TYPE;
1493  prev_pmt_due_date           iby_docs_payable_all.payment_due_date%TYPE;
1494  prev_benef_party            iby_docs_payable_all.beneficiary_party%TYPE;
1495 
1496  /* payee (employee) address related fields */
1497  prev_address_source         iby_docs_payable_all.address_source%TYPE;
1498  prev_emp_add_code           iby_docs_payable_all.employee_address_code%TYPE;
1499  prev_emp_person_id          iby_docs_payable_all.employee_person_id%TYPE;
1500  prev_emp_addr_id            iby_docs_payable_all.employee_address_id%TYPE;
1501 
1502  prev_emp_pmt_flag           iby_docs_payable_all.employee_payment_flag%TYPE;
1503 
1504  /*TPP-Start*/
1505  prev_inv_payee_party_id         iby_docs_payable_all.inv_payee_party_id%TYPE;
1506  prev_inv_party_site_id          iby_docs_payable_all.inv_party_site_id%TYPE;
1507  prev_inv_supplier_site_id       iby_docs_payable_all.inv_supplier_site_id%TYPE;
1508  prev_ext_inv_payee_id           iby_docs_payable_all.ext_inv_payee_id%TYPE;
1509  prev_inv_beneficiary_party            iby_docs_payable_all.inv_beneficiary_party%TYPE;
1510 
1511  curr_inv_payee_party_id         iby_docs_payable_all.inv_payee_party_id%TYPE;
1512  curr_inv_party_site_id          iby_docs_payable_all.inv_party_site_id%TYPE;
1513  curr_inv_supplier_site_id       iby_docs_payable_all.inv_supplier_site_id%TYPE;
1514  curr_ext_inv_payee_id           iby_docs_payable_all.ext_inv_payee_id%TYPE;
1515  curr_inv_beneficiary_party            iby_docs_payable_all.inv_beneficiary_party%TYPE;
1516  /*TPP-End*/
1517 
1518 
1519  /* current document attributes */
1520  curr_doc_id                 iby_docs_payable_all.document_payable_id%TYPE;
1521  curr_ca_id                  iby_docs_payable_all.calling_app_id%TYPE;
1522  curr_ca_doc_id1             iby_docs_payable_all.
1523                                  calling_app_doc_unique_ref1%TYPE;
1524  curr_ca_doc_id2             iby_docs_payable_all.
1525                                  calling_app_doc_unique_ref2%TYPE;
1526  curr_ca_doc_id3             iby_docs_payable_all.
1527                                  calling_app_doc_unique_ref3%TYPE;
1528  curr_ca_doc_id4             iby_docs_payable_all.
1529                                  calling_app_doc_unique_ref4%TYPE;
1530  curr_ca_doc_id5             iby_docs_payable_all.
1531                                  calling_app_doc_unique_ref5%TYPE;
1532  curr_pp_tt_cd               iby_docs_payable_all.pay_proc_trxn_type_code%TYPE;
1533  curr_pmt_grp_num            iby_docs_payable_all.payment_grouping_number%TYPE;
1534  curr_pmt_method_cd          iby_docs_payable_all.payment_method_code%TYPE;
1535  curr_doc_pmt_currency       iby_docs_payable_all.payment_currency_code%TYPE;
1536  curr_doc_pmt_amount         iby_docs_payable_all.payment_amount%TYPE;
1537  curr_int_bank_acct_id       iby_docs_payable_all.
1538                                  internal_bank_account_id%TYPE;
1539  curr_ext_bank_acct_id       iby_docs_payable_all.
1540                                  external_bank_account_id%TYPE;
1541  curr_org_id                 iby_docs_payable_all.org_id%TYPE;
1542  curr_org_type               iby_docs_payable_all.org_type%TYPE;
1543  curr_payee_id               iby_docs_payable_all.payee_party_id%TYPE;
1544  curr_payee_site_id          iby_docs_payable_all.party_site_id%TYPE;
1545  curr_supplier_site_id       iby_docs_payable_all.supplier_site_id%TYPE;
1546  curr_remit_loc_id           iby_docs_payable_all.remit_to_location_id%TYPE;
1547  curr_ext_payee_id           iby_docs_payable_all.ext_payee_id%TYPE;
1548  curr_profile_id             iby_docs_payable_all.payment_profile_id%TYPE;
1549  curr_pay_alone_flag         iby_docs_payable_all.exclusive_payment_flag%TYPE;
1550  curr_supplier_msg1          iby_docs_payable_all.remittance_message1%TYPE;
1551  curr_supplier_msg2          iby_docs_payable_all.remittance_message2%TYPE;
1552  curr_supplier_msg3          iby_docs_payable_all.remittance_message3%TYPE;
1553  curr_bnk_chg_bearer         iby_docs_payable_all.bank_charge_bearer%TYPE;
1554  curr_delivery_channel       iby_docs_payable_all.delivery_channel_code%TYPE;
1555  curr_settle_priority        iby_docs_payable_all.settlement_priority%TYPE;
1556  curr_uri                    iby_docs_payable_all.
1557                                  unique_remittance_identifier%TYPE;
1558  curr_uri_checkdigits        iby_docs_payable_all.uri_check_digit%TYPE;
1559  curr_pmt_reason_code        iby_docs_payable_all.payment_reason_code%TYPE;
1560  curr_pmt_reason_commts      iby_docs_payable_all.payment_reason_comments%TYPE;
1561  curr_pmt_function           iby_docs_payable_all.payment_function%TYPE;
1562  curr_pmt_date               iby_docs_payable_all.payment_date%TYPE;
1563  curr_pmt_due_date           iby_docs_payable_all.payment_due_date%TYPE;
1564  curr_benef_party            iby_docs_payable_all.beneficiary_party%TYPE;
1565 
1566  /* payee (employee) address related fields */
1567  curr_address_source         iby_docs_payable_all.address_source%TYPE;
1568  curr_emp_add_code           iby_docs_payable_all.employee_address_code%TYPE;
1569  curr_emp_person_id          iby_docs_payable_all.employee_person_id%TYPE;
1570  curr_emp_addr_id            iby_docs_payable_all.employee_address_id%TYPE;
1571 
1572  curr_emp_pmt_flag           iby_docs_payable_all.employee_payment_flag%TYPE;
1573 
1574  /* these two are passed to the external application hook */
1575  l_amount_withheld           iby_docs_payable_all.amount_withheld%TYPE;
1576 
1577  /* used for maturity date calculation */
1578  l_discount_date             iby_docs_payable_all.discount_date%TYPE;
1579 
1580  /* passed to hook */
1581  l_discount_amount           iby_docs_payable_all.payment_curr_discount_taken
1582                                                       %TYPE;
1583  l_trx_line_index            BINARY_INTEGER;
1584  l_no_rec_in_ppr             BOOLEAN;
1585  G_LINES_PER_FETCH           CONSTANT  NUMBER:= 100;
1586 -- G_LINES_PER_FETCH           CONSTANT  NUMBER:= 3;
1587 
1588  /*
1589   * This cursor up will pick up all valid documents for the specified
1590   * payment request. The select statement will order the documents
1591   * based on grouping criteria.
1592   *
1593   * As the grouping is operation is commutative, there is no
1594   * need to group the documents by any particular order (in
1595   * other words, grouping 1 followed by grouping 2, will lead
1596   * to the same results as grouping 2 followed by grouping 1).
1597   *
1598   * Important Note:
1599   * Always ensure that there is a corresponding order by
1600   * clause for each grouping criterion that you wish to use.
1601   * This is required in order to create minimum possible
1602   * payments from a given set of documents.
1603   *
1604   *
1605   * Populate legal entity ids for each of the created payments.
1606   * The legal entity id on the payment is a special attribute.
1607   * It is not a grouping rule, instead it has to be derived
1608   * from the internal bank account and populated.
1609   *
1610   */
1611  CURSOR c_documents(p_payment_request_id VARCHAR2)
1612  IS
1613  SELECT prq.call_app_pay_service_req_code,   -- Callers pay req id
1614         docs.document_payable_id,            -- Unique doc id asgn by IBY
1615         docs.calling_app_id,                 --| The caller
1616         docs.calling_app_doc_unique_ref1,    --| uses these
1617         docs.calling_app_doc_unique_ref2,    --| seven fields
1618         docs.calling_app_doc_unique_ref3,    --| to uniquely
1619         docs.calling_app_doc_unique_ref4,    --| identify
1620         docs.calling_app_doc_unique_ref5,    --| a document
1621         docs.pay_proc_trxn_type_code,        --| payable
1622         docs.payment_grouping_number,        -- Identifies related docs
1623         docs.payment_method_code,            -- Payment method
1624         docs.internal_bank_account_id,       -- Internal bank account id
1625         docs.external_bank_account_id,       -- External bank account id
1626         docs.payment_profile_id,             -- Payment profile id
1627         docs.org_id,
1628         docs.org_type,
1629         docs.payment_function,
1630         docs.ext_payee_id,                   -- Ext payee id (payee context)
1631         docs.payee_party_id,
1632         docs.party_site_id,
1633         docs.supplier_site_id,
1634         docs.remit_to_location_id,
1635         docs.amount_withheld,                -- Passed to hook for adjustmt
1636         ext_payee.bank_instruction1_code,    --|
1637         ext_payee.bank_instruction2_code,    --| These fields are
1638         ext_payee.payment_text_message1,     --| derived from the
1639         ext_payee.payment_text_message2,     --| payee.
1640         ext_payee.payment_text_message3,     --|
1641         docs.payment_currency_code,
1642         docs.payment_amount,
1643         docs.payment_date,
1644         docs.exclusive_payment_flag,
1645         docs.bank_charge_bearer,             -- Bank charge bearer
1646         docs.delivery_channel_code,          -- Delivery channel
1647         docs.settlement_priority,
1648         docs.remittance_message1,            -- Supplier message 1
1649         docs.remittance_message2,            -- Supplier message 2
1650         docs.remittance_message3,            -- Supplier message 3
1651         docs.unique_remittance_identifier,
1652         docs.uri_check_digit,
1653         docs.payment_reason_code,
1654         docs.payment_reason_comments,
1655         docs.payment_due_date,
1656         docs.discount_date,
1657         docs.payment_curr_discount_taken,
1658         docs.beneficiary_party,
1659         docs.address_source,                 --
1660         docs.employee_address_code,          -- Employee address
1661         docs.employee_person_id,             -- related fields
1662         docs.employee_address_id,            --
1663         docs.employee_payment_flag,
1664         pcr.group_by_remittance_message,
1665         pcr.group_by_bank_charge_bearer,
1666         pcr.group_by_delivery_channel,
1667         pcr.group_by_settle_priority_flag,
1668         pcr.group_by_payment_details_flag,
1669         DECODE(pcr.payment_details_length_limit, NULL,
1670             -1, pcr.payment_details_length_limit),
1671         pcr.payment_details_formula,
1672         pcr.group_by_max_documents_flag,     -- Max documents per payment flag
1673         pcr.max_documents_per_payment,       -- Max documents per payment value
1674         pcr.group_by_unique_remit_id_flag,
1675         pcr.group_by_payment_reason,
1676         pcr.group_by_due_date_flag,
1677         ppf.processing_type,
1678         ppf.declaration_option,
1679         ppf.dcl_only_foreign_curr_pmt_flag,
1680         ppf.declaration_curr_fx_rate_type,
1681         ppf.declaration_currency_code,
1682         ppf.declaration_threshold_amount,
1683         DECODE(prq.maximum_payment_amount, NULL, -1,
1684             prq.maximum_payment_amount),
1685         DECODE(prq.minimum_payment_amount, NULL, -1,
1686             prq.minimum_payment_amount),
1687         prq.allow_zero_payments_flag,
1688         pmt_mthd.support_bills_payable_flag,
1689         iba.account_owner_org_id,
1690 	/*TPP-Start*/
1691         docs.inv_payee_party_id,
1692         docs.inv_party_site_id,
1693         docs.inv_supplier_site_id,
1694         docs.inv_beneficiary_party,
1695         docs.ext_inv_payee_id
1696 	/*TPP-Start*/
1697  FROM IBY_DOCS_PAYABLE_ALL       docs,
1698       IBY_PMT_CREATION_RULES     pcr,
1699       IBY_PAYMENT_PROFILES       ppf,
1700       IBY_PAY_SERVICE_REQUESTS   prq,
1701       IBY_EXTERNAL_PAYEES_ALL    ext_payee,
1702       IBY_PAYMENT_METHODS_B      pmt_mthd,
1703       CE_BANK_ACCOUNTS           iba
1704  WHERE  prq.payment_service_request_id  = p_payment_request_id
1705  AND    docs.payment_service_request_id = prq.payment_service_request_id
1706  AND    docs.payment_profile_id         = ppf.payment_profile_id
1707  AND    ppf.system_profile_code         = pcr.system_profile_code(+)
1708  AND    docs.document_status            = DOC_STATUS_VALIDATED
1709  AND    docs.ext_payee_id               = ext_payee.ext_payee_id
1710  AND    docs.payment_method_code        = pmt_mthd.payment_method_code
1711  AND    docs.internal_bank_account_id   = iba.bank_account_id
1712  ORDER BY
1713         docs.exclusive_payment_flag,
1714         docs.org_id,
1715         docs.org_type,
1716         ext_payee.ext_payee_id,        -- \
1717         docs.payment_currency_code,    -- |
1718         docs.payment_method_code,      -- |
1719         docs.payment_profile_id,       -- |
1720         docs.payment_grouping_number,  -- |
1721         docs.internal_bank_account_id, -- | Ensure that the grouping
1722         docs.external_bank_account_id, -- | rules below follow the same
1723         docs.payment_function,         -- | ordering as this order by
1724         docs.payment_date,             -- | clause.
1725         docs.remit_to_location_id,     -- |
1726         docs.beneficiary_party,        -- |
1727         docs.address_source,           -- |
1728         docs.employee_address_code,    -- |
1729         docs.employee_person_id,       -- |
1730         docs.employee_address_id,      -- |
1731         docs.employee_payment_flag,    -- |
1732         docs.bank_charge_bearer,       -- |
1733         docs.delivery_channel_code,    -- | This order must be followed
1734         docs.settlement_priority,      -- | for creating minimum number
1735         docs.remittance_message1,      -- | of payments.
1736         docs.remittance_message2,      -- |
1737         docs.remittance_message3,      -- /
1738         docs.unique_remittance_identifier,
1739         docs.uri_check_digit,
1740         docs.payment_reason_code,
1741         docs.payment_reason_comments,
1742         docs.payment_due_date,
1743         docs.calling_app_doc_ref_number
1744         ;
1745 
1746  /*
1747   * Cursor to pick up all possible internal bank accounts
1748   * along with their corresponding legal entity ids.
1749   *
1750  CURSOR c_bank_acct_le_list
1751  IS
1752  SELECT
1753      iba.bank_account_id       int_bank_account,
1754      iba.account_owner_org_id  legal_entity_id
1755  FROM
1756      CE_BANK_ACCOUNTS iba
1757  ;
1758   */
1759 
1760  BEGIN
1761 
1762 
1763 
1764 
1765      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1766 	 print_debuginfo(l_module_name, 'ENTER');
1767 
1768      print_debuginfo(l_module_name, 'Payment Request Id : '||
1769          p_payment_request_id);
1770 
1771      END IF;
1772 
1773      l_no_rec_in_ppr := TRUE;
1774      /*
1775       * Pick up all the documents of the payment request.
1776       */
1777      OPEN  c_documents(p_payment_request_id);
1778      LOOP
1779         iby_disburse_submit_pub_pkg.delete_docspayTab;
1780         FETCH c_documents BULK COLLECT INTO
1781            iby_disburse_submit_pub_pkg.docspayTab.call_app_pay_service_req_code,
1782            iby_disburse_submit_pub_pkg.docspayTab.document_payable_id,
1783            iby_disburse_submit_pub_pkg.docspayTab.calling_app_id,
1784            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1,
1785            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2,
1786            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3,
1787            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4,
1788            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5,
1789            iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code,
1790            iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number,
1791            iby_disburse_submit_pub_pkg.docspayTab.payment_method_code,
1792            iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id,
1793            iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id,
1794            iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id,
1795            iby_disburse_submit_pub_pkg.docspayTab.org_id,
1796            iby_disburse_submit_pub_pkg.docspayTab.org_type,
1797            iby_disburse_submit_pub_pkg.docspayTab.payment_function,
1798            iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id,
1799            iby_disburse_submit_pub_pkg.docspayTab.payee_party_id,
1800            iby_disburse_submit_pub_pkg.docspayTab.party_site_id,
1801            iby_disburse_submit_pub_pkg.docspayTab.supplier_site_id,
1802            iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id,
1803            iby_disburse_submit_pub_pkg.docspayTab.amount_withheld,
1804            iby_disburse_submit_pub_pkg.docspayTab.bank_instruction1_code,
1805            iby_disburse_submit_pub_pkg.docspayTab.bank_instruction2_code,
1806            iby_disburse_submit_pub_pkg.docspayTab.payment_text_message1,
1807            iby_disburse_submit_pub_pkg.docspayTab.payment_text_message2,
1808            iby_disburse_submit_pub_pkg.docspayTab.payment_text_message3,
1809            iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code,
1810            iby_disburse_submit_pub_pkg.docspayTab.payment_amount,
1811            iby_disburse_submit_pub_pkg.docspayTab.payment_date,
1812            iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag,
1813            iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer,
1814            iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code,
1815            iby_disburse_submit_pub_pkg.docspayTab.settlement_priority,
1816            iby_disburse_submit_pub_pkg.docspayTab.remittance_message1,
1817            iby_disburse_submit_pub_pkg.docspayTab.remittance_message2,
1818            iby_disburse_submit_pub_pkg.docspayTab.remittance_message3,
1819            iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier,
1820            iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit,
1821            iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code,
1822            iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments,
1823            iby_disburse_submit_pub_pkg.docspayTab.payment_due_date,
1824            iby_disburse_submit_pub_pkg.docspayTab.discount_date,
1825            iby_disburse_submit_pub_pkg.docspayTab.payment_curr_discount_taken,
1826            iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party,
1827            iby_disburse_submit_pub_pkg.docspayTab.address_source,
1828            iby_disburse_submit_pub_pkg.docspayTab.employee_address_code,
1829            iby_disburse_submit_pub_pkg.docspayTab.employee_person_id,
1830            iby_disburse_submit_pub_pkg.docspayTab.employee_address_id,
1831            iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag,
1832            iby_disburse_submit_pub_pkg.docspayTab.group_by_remittance_message,
1833            iby_disburse_submit_pub_pkg.docspayTab.group_by_bank_charge_bearer,
1834            iby_disburse_submit_pub_pkg.docspayTab.group_by_delivery_channel,
1835            iby_disburse_submit_pub_pkg.docspayTab.group_by_settle_priority_flag,
1836            iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_details_flag,
1837            iby_disburse_submit_pub_pkg.docspayTab.payment_details_length_limit,
1838            iby_disburse_submit_pub_pkg.docspayTab.payment_details_formula,
1839            iby_disburse_submit_pub_pkg.docspayTab.group_by_max_documents_flag,
1840            iby_disburse_submit_pub_pkg.docspayTab.max_documents_per_payment,
1841            iby_disburse_submit_pub_pkg.docspayTab.group_by_unique_remit_id_flag,
1842            iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_reason,
1843            iby_disburse_submit_pub_pkg.docspayTab.group_by_due_date_flag,
1844            iby_disburse_submit_pub_pkg.docspayTab.processing_type,
1845            iby_disburse_submit_pub_pkg.docspayTab.declaration_option,
1846            iby_disburse_submit_pub_pkg.docspayTab.dcl_only_foreign_curr_pmt_flag,
1847            iby_disburse_submit_pub_pkg.docspayTab.declaration_curr_fx_rate_type,
1848            iby_disburse_submit_pub_pkg.docspayTab.declaration_currency_code,
1849            iby_disburse_submit_pub_pkg.docspayTab.declaration_threshold_amount,
1850            iby_disburse_submit_pub_pkg.docspayTab.maximum_payment_amount,
1851            iby_disburse_submit_pub_pkg.docspayTab.minimum_payment_amount,
1852            iby_disburse_submit_pub_pkg.docspayTab.allow_zero_payments_flag,
1853            iby_disburse_submit_pub_pkg.docspayTab.support_bills_payable_flag,
1854            iby_disburse_submit_pub_pkg.docspayTab.iba_legal_entity_id,
1855            iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id,
1856            iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id,
1857            iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id,
1858            iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party,
1859            iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id
1860         LIMIT G_LINES_PER_FETCH;
1861 
1862      /*
1863       * Loop through all the fetched documents, grouping them
1864       * into payments.
1865       */
1866         FOR l_trx_line_index IN nvl(iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code.FIRST,0) .. nvl(iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code.LAST,-99)
1867         LOOP
1868            l_no_rec_in_ppr := FALSE;
1869 
1870            IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1871 	 print_debuginfo(l_module_name, 'Processed document payable id: '
1872             || to_char(iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index)));
1873            END IF;
1874 
1875 
1876          /* these two used in raising biz events */
1877          /* they will not vary within a request */
1878          l_ca_id                := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
1879          l_ca_payreq_cd         := iby_disburse_submit_pub_pkg.docspayTab.call_app_pay_service_req_code(l_trx_line_index);
1880          l_delv_chnl_flag       := iby_disburse_submit_pub_pkg.docspayTab.group_by_delivery_channel(l_trx_line_index);
1881          l_express_pmt_flag     := iby_disburse_submit_pub_pkg.docspayTab.group_by_settle_priority_flag(l_trx_line_index);
1882          l_bnk_chg_brer_flag    := iby_disburse_submit_pub_pkg.docspayTab.group_by_bank_charge_bearer(l_trx_line_index);
1883          l_sup_msg_flag         := iby_disburse_submit_pub_pkg.docspayTab.group_by_remittance_message(l_trx_line_index);
1884          l_pmt_details_flag     := iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_details_flag(l_trx_line_index);
1885          l_pmt_details_len      := iby_disburse_submit_pub_pkg.docspayTab.payment_details_length_limit(l_trx_line_index);
1886          l_pmt_det_formula      := iby_disburse_submit_pub_pkg.docspayTab.payment_details_formula(l_trx_line_index);
1887          l_processing_type      := iby_disburse_submit_pub_pkg.docspayTab.processing_type(l_trx_line_index);
1888 
1889          l_max_docs_flag        := iby_disburse_submit_pub_pkg.docspayTab.group_by_max_documents_flag(l_trx_line_index);
1890          l_max_docs_limit       := iby_disburse_submit_pub_pkg.docspayTab.max_documents_per_payment(l_trx_line_index);
1891          l_unique_remit_id_flag := iby_disburse_submit_pub_pkg.docspayTab.group_by_unique_remit_id_flag(l_trx_line_index);
1892          l_pmt_reason_flag      := iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_reason(l_trx_line_index);
1893          l_due_date_flag        := iby_disburse_submit_pub_pkg.docspayTab.group_by_due_date_flag(l_trx_line_index);
1894          l_prom_note_flag       := iby_disburse_submit_pub_pkg.docspayTab.support_bills_payable_flag(l_trx_line_index);
1895 
1896          l_decl_option            := iby_disburse_submit_pub_pkg.docspayTab.declaration_option(l_trx_line_index);
1897          l_decl_only_fx_flag      := iby_disburse_submit_pub_pkg.docspayTab.dcl_only_foreign_curr_pmt_flag(l_trx_line_index);
1898          l_decl_curr_fx_rate_type := iby_disburse_submit_pub_pkg.docspayTab.declaration_curr_fx_rate_type(l_trx_line_index);
1899          l_decl_curr_code         := iby_disburse_submit_pub_pkg.docspayTab.declaration_currency_code(l_trx_line_index);
1900          l_decl_threshold_amount  := iby_disburse_submit_pub_pkg.docspayTab.declaration_threshold_amount(l_trx_line_index);
1901 
1902          l_commonAttributes.curr_pmt_due_date   := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
1903          l_commonAttributes.curr_delivery_channel   :=  iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
1904          l_commonAttributes.curr_uri   :=    iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
1905          l_commonAttributes.curr_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
1906 
1907          /*
1908           * Store the payment request imposed limits in the output
1909           * parameter. These will be used for validation on the
1910           * created payments.
1911           */
1912          x_payReqCriteria.max_pmt_amt_limit    :=
1913                                      iby_disburse_submit_pub_pkg.docspayTab.maximum_payment_amount(l_trx_line_index);
1914          x_payReqCriteria.min_pmt_amt_limit    :=
1915                                      iby_disburse_submit_pub_pkg.docspayTab.minimum_payment_amount(l_trx_line_index);
1916          x_payReqCriteria.allow_zero_pmts_flag :=
1917                                      iby_disburse_submit_pub_pkg.docspayTab.allow_zero_payments_flag(l_trx_line_index);
1918 
1919          /*
1920           * Store the central bank reporting related fields in
1921           * the CBR record.
1922          l_cbrRec.decl_option            := l_decl_option;
1923          l_cbrRec.decl_only_fx_flag      := l_decl_only_fx_flag;
1924          l_cbrRec.decl_curr_fx_rate_type := l_decl_curr_fx_rate_type;
1925          l_cbrRec.decl_curr_code         := l_decl_curr_code;
1926          l_cbrRec.decl_threshold_amount  := l_decl_threshold_amount;
1927           */
1928 
1929          /* these are payee related fields */
1930          l_bank_inst1_code := iby_disburse_submit_pub_pkg.docspayTab.bank_instruction1_code(l_trx_line_index);
1931          l_bank_inst2_code := iby_disburse_submit_pub_pkg.docspayTab.bank_instruction2_code(l_trx_line_index);
1932          l_pmt_txt_msg1    := iby_disburse_submit_pub_pkg.docspayTab.payment_text_message1(l_trx_line_index);
1933          l_pmt_txt_msg2    := iby_disburse_submit_pub_pkg.docspayTab.payment_text_message2(l_trx_line_index);
1934          l_pmt_txt_msg3    := iby_disburse_submit_pub_pkg.docspayTab.payment_text_message3(l_trx_line_index);
1935 
1936          /* these are passed onto the hook for adjustment by ext app */
1937          l_amount_withheld    := NVL(iby_disburse_submit_pub_pkg.docspayTab.amount_withheld(l_trx_line_index), 0 );
1938 
1939          /* used for maturity date calculation */
1940          l_discount_date    := iby_disburse_submit_pub_pkg.docspayTab.discount_date(l_trx_line_index);
1941 
1942          l_discount_amount  := iby_disburse_submit_pub_pkg.docspayTab.payment_curr_discount_taken(l_trx_line_index);
1943 
1944          /*
1945           * Log all the fetched document fields
1946           *
1947          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1948 	 print_debuginfo(l_module_name,
1949              'Fetched document data for document:' || curr_doc_id
1950              || ', calling app id: '        || curr_ca_id
1951              || ', calling app doc id1: '   || curr_ca_doc_id1
1952              || ', calling app doc id2: '   || curr_ca_doc_id2
1953              || ', calling app doc id3: '   || curr_ca_doc_id3
1954              || ', calling app doc id4: '   || curr_ca_doc_id4
1955              || ', calling app doc id5: '   || curr_ca_doc_id5
1956              || ', calling app trxn type: ' || curr_pp_tt_cd
1957              || ', payment grp number: '    || curr_pmt_grp_num
1958              || ', payment method: '        || curr_pmt_method_cd
1959              || ', internal bank account: ' || curr_int_bank_acct_id
1960              || ', external bank account: ' || curr_ext_bank_acct_id
1961              || ', profile: '               || curr_profile_id
1962              || ', payee: '                 || curr_payee_id
1963              || ', payee site: '            || curr_payee_site_id
1964              || ', supplier site: '         || curr_supplier_site_id
1965              || ', remit loc id: '          || curr_remit_loc_id
1966              || ', ext payee: '             || curr_ext_payee_id
1967              || ', org: '                   || curr_org_id
1968              || ', org type: '              || curr_org_type
1969              );
1970 
1971          print_debuginfo(l_module_name,
1972              'Fetched document data for document:' || curr_doc_id
1973              || ', payment currency: '      || curr_doc_pmt_currency
1974              || ', payment amount: '        || curr_doc_pmt_amount
1975              || ', pay alone flag: '        || iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index)
1976              || ', bank charge bearer: '    || curr_bnk_chg_bearer
1977              || ', delivery channel: '      || curr_delivery_channel
1978              || ', supplier message 1: '    || curr_supplier_msg1
1979              || ', supplier message 2: '    || curr_supplier_msg2
1980              || ', supplier message 3: '    || curr_supplier_msg3
1981              || ', uri: '                   || curr_uri
1982              || ', uri checkdigits: '       || curr_uri_checkdigits
1983              || ', pmt reason code: '       || curr_pmt_reason_code
1984              || ', pmt reason comments: '   || curr_pmt_reason_commts
1985              || ', pmt function: '          || curr_pmt_function
1986              || ', pmt date: '              || curr_pmt_date
1987              || ', pmt due date: '          || curr_pmt_due_date
1988              || ', benef party: '           || curr_benef_party
1989              );
1990 
1991          print_debuginfo(l_module_name,
1992              'Fetched document data for document:' || curr_doc_id
1993              || ', address source: '        || curr_address_source
1994              || ', emp addr code: '         || curr_emp_add_code
1995              || ', emp person id: '         || curr_emp_person_id
1996              || ', emp addr id: '           || curr_emp_addr_id
1997              || ', emp pmt flag: '          || curr_emp_pmt_flag
1998              );
1999 
2000          print_debuginfo(l_module_name,
2001              'Fetched flags for document:'  || curr_doc_id
2002              || ', pmt details flag: '      || l_pmt_details_flag
2003              || ', pmt details length: '    || l_pmt_details_len
2004              || ', pmt details formula: '   || l_pmt_det_formula
2005              || ', max docs flag: '         || l_max_docs_flag
2006              || ', max docs limit: '        || l_max_docs_limit
2007              || ', uri flag: '              || l_unique_remit_id_flag
2008              || ', pmt reason flag: '       || l_pmt_reason_flag
2009              || ', express pmt flag: '      || l_express_pmt_flag
2010              || ', delv channel flag: '     || l_delv_chnl_flag
2011              || ', pmt due date flag: '     || l_due_date_flag
2012              || ', prom note flag: '        || l_prom_note_flag
2013              );
2014 
2015           END IF;
2016           */
2017 
2018          IF (l_first_record = 'Y') THEN
2019             prev_doc_id            := iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index);
2020             prev_ca_id             := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
2021             prev_ca_doc_id1        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index);
2022             prev_ca_doc_id2        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index);
2023             prev_ca_doc_id3        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index);
2024             prev_ca_doc_id4        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index);
2025             prev_ca_doc_id5        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index);
2026             prev_pp_tt_cd          := iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index);
2027             prev_pmt_grp_num       := iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index);
2028             prev_pmt_method_cd     := iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index);
2029             prev_int_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
2030             prev_ext_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
2031             prev_profile_id        := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
2032             prev_org_id            := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
2033             prev_org_type          := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
2034             prev_payee_id          := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
2035             prev_payee_site_id     := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
2036             prev_remit_loc_id      := iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index);
2037             prev_ext_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
2038             prev_doc_pmt_currency  := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
2039             prev_doc_pmt_amount    := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index);
2040             prev_pay_alone_flag    := iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index);
2041             prev_bnk_chg_bearer    := iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index);
2042             prev_delivery_channel  := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
2043             prev_settle_priority   := iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index);
2044             prev_supplier_msg1     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index);
2045             prev_supplier_msg2     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index);
2046             prev_supplier_msg3     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index);
2047             prev_uri               := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
2048             prev_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
2049             prev_pmt_reason_code   := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index);
2050             prev_pmt_reason_commts := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index);
2051             prev_pmt_function      := iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index);
2052             prev_pmt_date          := iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index);
2053             prev_pmt_due_date      := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
2054             prev_benef_party       := iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index);
2055             prev_address_source    := iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index);
2056             prev_emp_add_code      := iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index);
2057             prev_emp_person_id     := iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index);
2058             prev_emp_addr_id       := iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index);
2059             prev_emp_pmt_flag      := iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index);
2060  prev_inv_payee_party_id      := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
2061  prev_inv_party_site_id      := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
2062  prev_inv_supplier_site_id      := iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id(l_trx_line_index);
2063  prev_inv_beneficiary_party      := iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party(l_trx_line_index);
2064  prev_ext_inv_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
2065 
2066            /* code to replace sweepCommonPmtAttributes() code */
2067 
2068            l_commonAttributes.prev_pmt_due_date   := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
2069            l_commonAttributes.prev_delivery_channel   :=  iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
2070            l_commonAttributes.prev_uri   :=    iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
2071            l_commonAttributes.prev_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
2072          END IF;
2073 
2074          /*
2075           * We have just fetched a new document for this payment request.
2076           * We will either insert this document into a new payment or
2077           * we will be inserting this document into the currently running
2078           * payment.
2079           *
2080           * In either case, we need to insert this doc into a payment.
2081           * So pre-populate the payment record with attributes of
2082           * this document. This is because the payment takes on the
2083           * attributes of it's constituent documents.
2084           *
2085           * Note: For user defined grouping rules, we will
2086           * have to populate the payment attribute only if
2087           * the user has turned on grouping by that attribute.
2088           */
2089 
2090          /* Only pre-fill hardcoded grouping rule attributes */
2091          l_paymentRec.payment_profile_id       := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
2092          l_paymentRec.payment_service_request_id
2093                                                := p_payment_request_id;
2094          l_paymentRec.internal_bank_account_id := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
2095          l_paymentRec.ext_payee_id             := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
2096          l_paymentRec.payee_party_id           := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
2097          l_paymentRec.party_site_id            := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
2098          l_paymentRec.supplier_site_id         := iby_disburse_submit_pub_pkg.docspayTab.supplier_site_id(l_trx_line_index);
2099 
2100 	 l_paymentRec.ext_inv_payee_id             := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
2101          l_paymentRec.inv_payee_party_id           := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
2102          l_paymentRec.inv_party_site_id            := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
2103          l_paymentRec.inv_supplier_site_id         := iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id(l_trx_line_index);
2104          l_paymentRec.inv_beneficiary_party         := iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party(l_trx_line_index);
2105 
2106          l_paymentRec.remit_to_location_id     := iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index);
2107          l_paymentRec.payment_currency_code    := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
2108          l_paymentRec.org_id                   := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
2109          l_paymentRec.org_type                 := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
2110          l_paymentRec.payment_method_code      := iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index);
2111          l_paymentRec.payment_function         := iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index);
2112          l_paymentRec.payment_date             := iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index);
2113          l_paymentRec.beneficiary_party        := iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index);
2114          l_paymentRec.address_source           := iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index);
2115          l_paymentRec.employee_address_code    := iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index);
2116          l_paymentRec.employee_person_id       := iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index);
2117          l_paymentRec.employee_address_id      := iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index);
2118          l_paymentRec.employee_payment_flag    := iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index);
2119          l_paymentRec.legal_entity_id          := iby_disburse_submit_pub_pkg.docspayTab.iba_legal_entity_id(l_trx_line_index);
2120 
2121          /*
2122           * Fix for bug 5524116:
2123           *
2124           * Group by external bank account needs to be made a
2125           * hardcoded grouping rule regardless of processing type.
2126           *
2127           * This is because is some obscure formats e.g., Italy Wire
2128           * payments, the payment is actually sent to the bank as
2129           * a printed payment letter even though the payment method
2130           * is wire.
2131           */
2132          l_paymentRec.external_bank_account_id := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
2133 
2134          /*
2135           * Fix for bug 5334177:
2136           *
2137           * Setting the bills payable flag on the payment is not
2138           * related to user-defined grouping rules.
2139           *
2140           * Set this flag here along with other hardcoded
2141           * grouping rules.
2142           */
2143 
2144          /*
2145           * Set the promissory note flag for this payment
2146           * if the payment method of this payment supports
2147           * promissory notes.
2148           *
2149           * The promissory note flag indicates that this
2150           * payment is (possibly) a future dated payment.
2151           */
2152          IF (l_prom_note_flag = 'Y') THEN
2153 
2154              l_paymentRec.bill_payable_flag := 'Y';
2155 
2156          ELSE
2157 
2158              /*
2159               * Fix for bug 5442899
2160               *
2161               * Explicitly set bill payable flag to 'N'
2162               * in case payment method does not
2163               * support bills payable.
2164               */
2165              l_paymentRec.bill_payable_flag := 'N';
2166 
2167          END IF;
2168 
2169          /*
2170           * If a document has the payment grouping number attribute
2171           * set, then it is a part of a pre-grouped payment (document
2172           * grouped into payment at the calling app itself).
2173           *
2174           * Grouping by payment grouping number is a hardcoded grouping
2175           * rule below. Therefore, it is guaranteed that a payment will
2176           * only contain documents with the same payment grouping number.
2177           *
2178           * For, such payments set the 'pregrouped payment flag' to 'Y'.
2179           */
2180          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NOT NULL) THEN
2181 
2182              l_paymentRec.pregrouped_payment_flag := 'Y';
2183 
2184          ELSE
2185 
2186              /*
2187               * Fix for bug 5529924:
2188               *
2189               * Explicitly set the pregrouped payment flag to 'N'
2190               * in case the grouping number on the document
2191               * is null.
2192               */
2193              l_paymentRec.pregrouped_payment_flag := 'N';
2194 
2195          END IF;
2196 
2197          /* payee related fields */
2198          /* grouping by payee context is a hardcoded grouping rule */
2199          l_paymentRec.bank_instruction1_code   := l_bank_inst1_code;
2200          l_paymentRec.bank_instruction2_code   := l_bank_inst2_code;
2201          l_paymentRec.payment_text_message1    := l_pmt_txt_msg1;
2202          l_paymentRec.payment_text_message2    := l_pmt_txt_msg2;
2203          l_paymentRec.payment_text_message3    := l_pmt_txt_msg3;
2204 
2205          /*
2206           * Pre-fill grouping rule attributes for user defined
2207           * grouping rules (that are enabled by the user).
2208           *
2209           * It is necessary to pre-fill user defined grouping
2210           * attributes before the grouping rules are triggered
2211           * because we don't know which user defined grouping rules
2212           * are going to get triggered first, and once a rule is
2213           * triggered all rules below it are skipped. So it is too
2214           * late to populate grouping attributes within the grouping
2215           * rule itself.
2216           */
2217 
2218          /*
2219           * We pre-fill the user-defined attributes only when the
2220           * 'payment grouping number' attribute is null. This is
2221           * because the user-defined grouping rules are never triggered
2222           * if the 'payment grouping number' attribute is not null.
2223           */
2224 
2225          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
2226 
2227              /*-----------------------------------------------------
2228              IF (l_payee_add_eft_flag = 'Y') THEN
2229                  IF (l_processing_type = 'ELECTRONIC') THEN
2230 
2231                      --
2232                      -- RAMESH:
2233                      -- Temporarily commented out. Current data model
2234                      -- does not support grouping by payee party id and payee
2235                      -- party site as separate grouping rules because of
2236                      -- calling app constraints.
2237                      --
2238                      -- At the moment, the grouping is at the level of
2239                      -- payee context which includes (payee party id, payee
2240                      -- party site id, supplier site id, org id, org type)
2241                      -- etc.
2242                      --
2243                      -- In the future when more fine grained grouping
2244                      -- can be supported, uncomment this code.
2245                      --
2246 
2247                      --l_paymentRec.payee_party_site_id := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
2248                      --l_paymentRec.payee_id := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
2249 
2250                  END IF;
2251              END IF;
2252              -----------------------------------------------------*/
2253 
2254              IF (l_bnk_chg_brer_flag = 'Y') THEN
2255                  l_paymentRec.bank_charge_bearer := iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index);
2256              END IF;
2257 
2258              IF (l_delv_chnl_flag = 'Y') THEN
2259                  l_paymentRec.delivery_channel_code := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
2260              END IF;
2261 
2262              IF (l_express_pmt_flag = 'Y') THEN
2263                  l_paymentRec.settlement_priority := iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index);
2264              END IF;
2265 
2266              IF (l_sup_msg_flag = 'Y') THEN
2267 
2268                  /*
2269                   * Fix for bug 5534537:
2270                   *
2271                   * Assign correct remittance messages to the
2272                   * payment.
2273                   */
2274                  l_paymentRec.remittance_message1 := iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index);
2275                  l_paymentRec.remittance_message2 := iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index);
2276                  l_paymentRec.remittance_message3 := iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index);
2277 
2278              END IF;
2279 
2280              IF (l_unique_remit_id_flag = 'Y') THEN
2281                  l_paymentRec.unique_remittance_identifier := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
2282                  l_paymentRec.uri_check_digit := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
2283              END IF;
2284 
2285              IF (l_due_date_flag = 'Y') THEN
2286                  l_paymentRec.payment_due_date := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
2287              END IF;
2288 
2289              IF (l_pmt_reason_flag = 'Y') THEN
2290                  l_paymentRec.payment_reason_code     := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index);
2291                  l_paymentRec.payment_reason_comments := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index);
2292              END IF;
2293 
2294          END IF; -- if payment_grouping_number(l_trx_line_index) IS NULL
2295 
2296          /*
2297           * Pre-fill the document record with the details
2298           * of the current document.
2299           */
2300          l_docsInPmtRec.document_id         := iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index);
2301          l_docsInPmtRec.document_amount     := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index);
2302          l_docsInPmtRec.document_currency   := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
2303          l_docsInPmtRec.payment_grp_num     := iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index);
2304          l_docsInPmtRec.calling_app_id      := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
2305          l_docsInPmtRec.calling_app_doc_id1 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index);
2306          l_docsInPmtRec.calling_app_doc_id2 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index);
2307          l_docsInPmtRec.calling_app_doc_id3 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index);
2308          l_docsInPmtRec.calling_app_doc_id4 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index);
2309          l_docsInPmtRec.calling_app_doc_id5 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index);
2310          l_docsInPmtRec.pay_proc_ttype_cd   := iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index);
2311 
2312          /* these to are passed onto the hook for adjustment by ext app */
2313          l_docsInPmtRec.amount_withheld     := l_amount_withheld;
2314 
2315          /* used for maturity date calculation */
2316          l_docsInPmtRec.discount_date       := l_discount_date;
2317          l_docsInPmtRec.pmt_due_date        := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
2318 
2319          /* used in common attribute sweep */
2320          l_docsInPmtRec.delivery_channel    := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
2321          l_docsInPmtRec.unique_remit_id     := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
2322          l_docsInPmtRec.uri_ckdigits        := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
2323 
2324          l_docsInPmtRec.int_bank_acct_id    := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
2325          l_docsInPmtRec.ext_payee_id        := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
2326          l_docsInPmtRec.payee_id            := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
2327          l_docsInPmtRec.payee_site_id       := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
2328          l_docsInPmtRec.supplier_site_id    := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
2329 
2330          l_docsInPmtRec.ext_inv_payee_id        := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
2331          l_docsInPmtRec.inv_payee_party_id            := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
2332          l_docsInPmtRec.inv_party_site_id       := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
2333          l_docsInPmtRec.inv_supplier_site_id    := iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id(l_trx_line_index);
2334 
2335 	 l_docsInPmtRec.org_id              := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
2336          l_docsInPmtRec.org_type            := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
2337          l_docsInPmtRec.ext_bank_acct_id    := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
2338          l_docsInPmtRec.pmt_curr_discount   := l_discount_amount;
2339 
2340          /*
2341           * Calculate payment details from the document based on
2342           * the user defined formula. This will be used in a
2343           * user-defined grouping rule below.
2344           */
2345          IF (l_pmt_details_flag = 'Y') THEN
2346              l_calc_doc_detail := getDocDetails(iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index),
2347                                       l_pmt_det_formula);
2348 
2349              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2350 		 print_debuginfo(l_module_name, 'Calculated doc detail for '
2351                  || 'doc id '
2352                  || curr_doc_id
2353                  || ': '
2354                  || l_calc_doc_detail
2355                  );
2356 
2357 	     END IF;
2358 
2359          ELSE
2360              l_calc_doc_detail := null;
2361          END IF;
2362 
2363          /*
2364           * The length of the payment details field in IBY_PAYMENTS_ALL
2365           * table is 240 chars. This imposes a hard limit for the
2366           * length of payment details that can be stored against a
2367           * payment.
2368           *
2369           * If the user has specified a field length (for payment
2370           * details) greater than the column width, reset the field
2371           * length to the column limit.
2372           */
2373          IF (l_pmt_details_flag = 'Y') THEN
2374              IF (l_pmt_details_len > 240) THEN
2375 
2376                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2377 		 print_debuginfo(l_module_name, 'User specified payment '
2378                      || 'details field length = '
2379                      || l_pmt_details_len
2380                      || '. This is greater than the max column length '
2381                      || '(currently 240 chars). Payment details will be '
2382                      || 'filled to the maximum column length.'
2383                      );
2384                  END IF;
2385 
2386                  l_pmt_details_len := 240;
2387 
2388              /*
2389               * If user has not specified any value at all,
2390               * default the payment details field length.
2391               */
2392              ELSIF (l_pmt_details_len = -1) THEN
2393 
2394                  /*
2395                   * Fix for bug 5362662:
2396                   *
2397                   * If user has not specified a length for the payment
2398                   * details field, but has turned on grouping by
2399                   * payment details, then limit the payment details
2400                   * field to the max allowed column length.
2401                   */
2402                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2403 		 print_debuginfo(l_module_name, 'User specified payment '
2404                      || 'details field length is null. '
2405                      || 'Payment details will be filled to the maximum '
2406                      || 'column length (currently 240 chars).'
2407                      );
2408                  END IF;
2409 
2410                  l_pmt_details_len := 240;
2411 
2412              END IF;
2413          END IF;
2414 
2415          /*-- HARDCODED GROUPING RULES START HERE --*/
2416 
2417          /*
2418           * Grouping Step 1: Pay Alone Flag (these are exclusive
2419           * payments where one document is paid by one payment).
2420           */
2421          IF (UPPER(iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index)) = 'Y') THEN
2422 
2423              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2424 		 print_debuginfo(l_module_name, 'Grouping by pay alone flag '
2425                  || 'triggered for document '
2426                  || curr_doc_id);
2427              END IF;
2428              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2429                  l_calc_doc_detail, true, l_payment_id,
2430                  x_docsInPmtTab, l_docsInPmtRec,
2431                   l_docs_in_pmt_count,l_commonAttributes);
2432 
2433              GOTO label_finish_iteration;
2434 
2435          END IF;
2436 
2437          /*
2438           * Grouping Step 2: Organization ID And Organization Type
2439           */
2440          IF (prev_org_id <> iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index))     OR
2441             (NVL(prev_org_type, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index), 0)) THEN
2442 
2443              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2444 	 print_debuginfo(l_module_name, 'Grouping by organization '
2445                  || 'id/type triggered for document '
2446                  || curr_doc_id);
2447 
2448              END IF;
2449 
2450              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2451                  l_calc_doc_detail, true, l_payment_id,
2452                  x_docsInPmtTab, l_docsInPmtRec,
2453                   l_docs_in_pmt_count,l_commonAttributes);
2454 
2455              GOTO label_finish_iteration;
2456 
2457          END IF;
2458 
2459 	 /*
2460           * Grouping Step 2.5: Group By Inv Payee Context (external inv payee id)
2461           */
2462          IF (prev_ext_inv_payee_id <> iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index)) THEN
2463 
2464              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2465 	 print_debuginfo(l_module_name, 'Grouping by payee context '
2466                  || 'triggered for document '
2467                  || curr_doc_id);
2468 
2469      END IF;
2470 
2471              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2472                  l_calc_doc_detail, true, l_payment_id,
2473                  x_docsInPmtTab, l_docsInPmtRec,
2474                   l_docs_in_pmt_count,l_commonAttributes);
2475 
2476              GOTO label_finish_iteration;
2477 
2478          END IF;
2479 
2480          /*
2481           * Grouping Step 3: Group By Payee Context (external payee id)
2482           */
2483          IF (prev_ext_payee_id <> iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index)) THEN
2484 
2485              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2486 	 print_debuginfo(l_module_name, 'Grouping by payee context '
2487                  || 'triggered for document '
2488                  || curr_doc_id);
2489 
2490      END IF;
2491 
2492              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2493                  l_calc_doc_detail, true, l_payment_id,
2494                  x_docsInPmtTab, l_docsInPmtRec,
2495                   l_docs_in_pmt_count,l_commonAttributes);
2496 
2497              GOTO label_finish_iteration;
2498 
2499          END IF;
2500 
2501          /*
2502           * Grouping Step 4: Payment Currency
2503           */
2504          IF (prev_doc_pmt_currency <> iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index)) THEN
2505 
2506              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2507 	 print_debuginfo(l_module_name, 'Grouping by payment '
2508                  || 'currency triggered for document '
2509                  || curr_doc_id);
2510 
2511      END IF;
2512 
2513              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2514                  l_calc_doc_detail, true, l_payment_id,
2515                  x_docsInPmtTab, l_docsInPmtRec,
2516                   l_docs_in_pmt_count,l_commonAttributes);
2517 
2518              GOTO label_finish_iteration;
2519 
2520          END IF;
2521 
2522          /*
2523           * Grouping Step 5: Payment Method
2524           */
2525          IF (prev_pmt_method_cd <> iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index)) THEN
2526 
2527              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2528 		 print_debuginfo(l_module_name, 'Grouping by payment '
2529                  || 'method triggered for document '
2530                  || curr_doc_id);
2531 
2532      END IF;
2533 
2534              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2535                  l_calc_doc_detail, true, l_payment_id,
2536                  x_docsInPmtTab, l_docsInPmtRec,
2537                   l_docs_in_pmt_count,l_commonAttributes);
2538 
2539              GOTO label_finish_iteration;
2540 
2541          END IF;
2542 
2543          /*
2544           * Grouping Step 6: Payment Profile ID
2545           */
2546          IF (prev_profile_id <> iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index)) THEN
2547 
2548              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2549 	 print_debuginfo(l_module_name, 'Grouping by payment '
2550                  || 'profile triggered for document '
2551                  || curr_doc_id);
2552 
2553      END IF;
2554 
2555              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2556                  l_calc_doc_detail, true, l_payment_id,
2557                  x_docsInPmtTab, l_docsInPmtRec,
2558                   l_docs_in_pmt_count,l_commonAttributes);
2559 
2560              GOTO label_finish_iteration;
2561 
2562          END IF;
2563 
2564          /*
2565           * NOTE:
2566           * Grouping by payment grouping number is a special type
2567           * of hardcoded grouping rule. All documents payable that
2568           * have the same payment grouping number must always be
2569           * grouped into the same payment.
2570           *
2571           * In order to achive this, two things have to happen:
2572           * a. None of the hardcoded grouping rules should
2573           *    be triggered when a document payable has a non-null
2574           *    value for payment grouping number.
2575           *
2576           * b. None of the user defined grouping rules must be applied
2577           *    for a document payable with a non-null value for
2578           *    payment grouping number.
2579           *
2580           * It is guaranteed by the calling application that all
2581           * documents that have a non-null value for the payment
2582           * grouping number will have the same values for all the
2583           * hardcoded grouping attributes. This will satisfy (a).
2584           *
2585           * The grouping logic below will not apply any user-defined
2586           * grouping rules if a document payable has a non-null value
2587           * for the payment grouping number. This will satisfy (b).
2588           */
2589 
2590          /*
2591           * Grouping Step 7: Payment Grouping Number
2592           */
2593          IF (NVL(prev_pmt_grp_num, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index), 0)) THEN
2594 
2595              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2596 	 print_debuginfo(l_module_name, 'Grouping by payment '
2597                  || 'grouping number triggered for document '
2598                  || curr_doc_id);
2599 
2600      END IF;
2601 
2602              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2603                  l_calc_doc_detail, true, l_payment_id,
2604                  x_docsInPmtTab, l_docsInPmtRec,
2605                   l_docs_in_pmt_count,l_commonAttributes);
2606 
2607              GOTO label_finish_iteration;
2608 
2609          END IF;
2610 
2611          /*
2612           * Grouping Step 8: Internal Bank Account ID
2613           */
2614          IF (prev_int_bank_acct_id <> iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index)) THEN
2615 
2616              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2617 		 print_debuginfo(l_module_name, 'Grouping by internal bank '
2618                  || 'account triggered for document '
2619                  || curr_doc_id);
2620 
2621      END IF;
2622 
2623              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2624                  l_calc_doc_detail, true, l_payment_id,
2625                  x_docsInPmtTab, l_docsInPmtRec,
2626                   l_docs_in_pmt_count,l_commonAttributes);
2627 
2628              GOTO label_finish_iteration;
2629 
2630          END IF;
2631 
2632          /*
2633           * Grouping Step 9: External Bank Account ID
2634           *
2635           * Fix for bug 5524116:
2636           *
2637           * Grouping by ext bank account now made a hardcoded
2638           * grouping rule regardless of processing type.
2639           */
2640          IF (NVL(prev_ext_bank_acct_id, 0) <>
2641              NVL(iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index), 0)) THEN
2642 
2643              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2644 	 print_debuginfo(l_module_name, 'Grouping by external '
2645                  || 'bank account triggered for document '
2646                  || curr_doc_id);
2647 
2648      END IF;
2649              l_paymentRec.external_bank_account_id := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
2650 
2651              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2652                  l_calc_doc_detail, true, l_payment_id,
2653                  x_docsInPmtTab, l_docsInPmtRec,
2654                   l_docs_in_pmt_count,l_commonAttributes);
2655 
2656              GOTO label_finish_iteration;
2657 
2658          END IF;
2659 
2660          /*
2661           * Grouping Step 10: Group By Payee Address (check only)
2662           *
2663           * One payee site can only have one address. Therefore, it is
2664           * sufficient to group by payee sites in order to group by
2665           * payee addresses.
2666           */
2667 
2668          /*-----------------------------------------------------
2669          IF (l_processing_type = 'PRINTED') THEN
2670              IF (prev_payee_site_id <> iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index)) THEN
2671 
2672                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2673 	 print_debuginfo(l_module_name, 'Grouping by payee '
2674                      || 'address (check) triggered for document '
2675                      || curr_doc_id);
2676 		 END IF;
2677                  --
2678                  -- RAMESH:
2679                  -- Temporarily commented out. Current data model
2680                  -- does not support grouping by payee party id and payee
2681                  -- party site as separate grouping rules because of
2682                  -- calling app constraints.
2683                  --
2684                  -- At the moment, the grouping is at the level of
2685                  -- payee context which includes (payee party id, payee
2686                  -- party site id, supplier site id, org id, org type)
2687                  -- etc.
2688                  --
2689                  -- In the future when more fine grained grouping
2690                  -- can be supported, uncomment this code.
2691                  --
2692 
2693                  --l_paymentRec.payee_party_site_id := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
2694 
2695                  insertDocIntoPayment(l_paymentRec, x_paymentTab,
2696                      l_calc_doc_detail, true, l_payment_id,
2697                      x_docsInPmtTab, l_docsInPmtRec,
2698                       l_docs_in_pmt_count,l_commonAttributes);
2699 
2700                  GOTO label_finish_iteration;
2701              END IF;
2702          END IF;
2703          -----------------------------------------------------*/
2704 
2705          /*
2706           * Grouping Step 11: Payment Function
2707           */
2708          IF (prev_pmt_function <> iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index)) THEN
2709 
2710              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2711 		 print_debuginfo(l_module_name, 'Grouping by payment '
2712                  || 'function triggered for document '
2713                  || curr_doc_id);
2714 
2715      END IF;
2716 
2717              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2718                  l_calc_doc_detail, true, l_payment_id,
2719                  x_docsInPmtTab, l_docsInPmtRec,
2720                   l_docs_in_pmt_count,l_commonAttributes);
2721 
2722              GOTO label_finish_iteration;
2723 
2724          END IF;
2725 
2726          /*
2727           * Grouping Step 12: Payment Date
2728           */
2729          IF (prev_pmt_date <> iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index)) THEN
2730 
2731              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2732 		 print_debuginfo(l_module_name, 'Grouping by payment '
2733                  || 'date triggered for document '
2734                  || curr_doc_id);
2735 
2736      END IF;
2737 
2738              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2739                  l_calc_doc_detail, true, l_payment_id,
2740                  x_docsInPmtTab, l_docsInPmtRec,
2741                   l_docs_in_pmt_count,l_commonAttributes);
2742 
2743              GOTO label_finish_iteration;
2744 
2745          END IF;
2746 
2747          /*
2748           * Grouping Step 13: Remit To Location Id
2749           */
2750          IF (NVL(prev_remit_loc_id, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index), '0')) THEN
2751 
2752              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2753 	 print_debuginfo(l_module_name, 'Grouping by remit to '
2754                  || 'location id triggered for document '
2755                  || curr_doc_id);
2756 
2757      END IF;
2758 
2759              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2760                  l_calc_doc_detail, true, l_payment_id,
2761                  x_docsInPmtTab, l_docsInPmtRec,
2762                   l_docs_in_pmt_count,l_commonAttributes);
2763 
2764              GOTO label_finish_iteration;
2765 
2766          END IF;
2767 
2768          /*
2769           * Grouping Step 14: Beneficiary Party
2770           */
2771          IF (NVL(prev_benef_party, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index), '0')) THEN
2772 
2773              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2774 	 print_debuginfo(l_module_name, 'Grouping by beneficiary '
2775                  || 'party triggered for document '
2776                  || curr_doc_id);
2777 
2778      END IF;
2779 
2780              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2781                  l_calc_doc_detail, true, l_payment_id,
2782                  x_docsInPmtTab, l_docsInPmtRec,
2783                   l_docs_in_pmt_count,l_commonAttributes);
2784 
2785              GOTO label_finish_iteration;
2786 
2787          END IF;
2788 
2789          /*
2790           * Grouping Step 15: Group By Space Left On Stub (check only)
2791           *
2792           * This will be handled in the payment creation flow (F8) because
2793           * the check related details are picked up in that flow.
2794           */
2795 
2796          /*
2797           * Grouping Step 16: Payee Address (Employee Address)
2798           *
2799           * TECHNICALLY REQUIRED, FUNCTIONALLY NOT REQUIRED -
2800           * Grouping by payee address is really not necessary because
2801           * we do grouping by payee context (which implicitly groups
2802           * by payee address as well assuming a 1:1 relationship between
2803           * a payee and his address).
2804           *
2805           * The reason we have this grouping rule here is to populate
2806           * these columns on the payment. These columns are used by
2807           * the extract / format.
2808           */
2809          IF (NVL(prev_address_source, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index), '0') OR
2810              NVL(prev_emp_add_code,   '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index),   '0') OR
2811              NVL(prev_emp_person_id,  '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index),  '0') OR
2812              NVL(prev_emp_addr_id,    '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index),    '0'))
2813              THEN
2814 
2815              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2816 	 print_debuginfo(l_module_name, 'Grouping by payee (employee) '
2817                  || 'address triggered for document '
2818                  || curr_doc_id);
2819 
2820      END IF;
2821 
2822              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2823                  l_calc_doc_detail, true, l_payment_id,
2824                  x_docsInPmtTab, l_docsInPmtRec,
2825                   l_docs_in_pmt_count,l_commonAttributes);
2826 
2827              GOTO label_finish_iteration;
2828 
2829          END IF;
2830 
2831          /*
2832           * Grouping Step 17: Employee Payment Flag
2833           *
2834           * TECHINICALLY REQUIRED, FUNCTIONALLY NOT REQUIRED -
2835           * The reason we have this grouping rule here is to populate
2836           * the employee payment flag on the payment.
2837           */
2838          IF (NVL(prev_emp_pmt_flag, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index), '0'))
2839              THEN
2840 
2841              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2842 		 print_debuginfo(l_module_name, 'Grouping by employee '
2843                  || 'payment flag triggered for document '
2844                  || curr_doc_id);
2845 
2846      END IF;
2847 
2848              insertDocIntoPayment(l_paymentRec, x_paymentTab,
2849                  l_calc_doc_detail, true, l_payment_id,
2850                  x_docsInPmtTab, l_docsInPmtRec,
2851                   l_docs_in_pmt_count,l_commonAttributes);
2852 
2853              GOTO label_finish_iteration;
2854 
2855          END IF;
2856 
2857          /*-- USER DEFINED GROUPING RULES START HERE --*/
2858 
2859          /*
2860           * NOTE:
2861           * None of the user defined grouping rules should be
2862           * applied to a document if it has a payment grouping
2863           * number attribute set.
2864           *
2865           * This is because all documents with the same payment
2866           * grouping number must always be grouped into the
2867           * same payment.
2868           */
2869 
2870          /*
2871           * Grouping Step 18: Payee Address (electronic)
2872           *
2873           * These are payments where the payment between
2874           * Oracle Payments and the bank is done electronically,
2875           * but the delivery channel from the bank to the
2876           * payee is by check.
2877           */
2878 
2879          /*-----------------------------------------
2880          IF (l_payee_add_eft_flag = 'Y') THEN
2881              IF (l_processing_type = 'ELECTRONIC') THEN
2882 
2883                  IF (NVL(prev_payee_site_id, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index), 0))
2884                      THEN
2885 
2886                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2887 			 print_debuginfo(l_module_name, 'Grouping by payee '
2888                          || 'address (electronic) triggered for document '
2889                          || curr_doc_id);
2890 
2891      END IF;
2892 
2893                      --
2894                      -- RAMESH:
2895                      -- Temporarily commented out. Current data model
2896                      -- does not support grouping by payee party id and payee
2897                      -- party site as separate grouping rules because of
2898                      -- calling app constraints.
2899                      --
2900                      -- At the moment, the grouping is at the level of
2901                      -- payee context which includes (payee party id, payee
2902                      -- party site id, supplier site id, org id, org type)
2903                      -- etc.
2904                      --
2905                      -- In the future when more fine grained grouping
2906                      -- can be supported, uncomment this code.
2907                      --
2908 
2909                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
2910                          l_calc_doc_detail, true, l_payment_id,
2911                          x_docsInPmtTab, l_docsInPmtRec,
2912                           l_docs_in_pmt_count,l_commonAttributes);
2913 
2914                      GOTO label_finish_iteration;
2915                  END IF;
2916              END IF;
2917          END IF;
2918          -------------------------------------------*/
2919 
2920          /*
2921           * Grouping Step 19: Bank Charge Bearer
2922           */
2923          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
2924 
2925              IF (l_bnk_chg_brer_flag = 'Y') THEN
2926 
2927                  IF (NVL(prev_bnk_chg_bearer, 0) <>
2928                      NVL(iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index), 0)) THEN
2929 
2930                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2931 			 print_debuginfo(l_module_name, 'Grouping by bank '
2932                          || 'charge bearer triggered for document '
2933                          || curr_doc_id);
2934 
2935      END IF;
2936 
2937                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
2938                          l_calc_doc_detail, true, l_payment_id,
2939                          x_docsInPmtTab, l_docsInPmtRec,
2940                           l_docs_in_pmt_count,l_commonAttributes);
2941 
2942                      GOTO label_finish_iteration;
2943 
2944                  END IF;
2945 
2946              END IF;
2947 
2948          END IF;
2949 
2950          /*
2951           * Grouping Step 20: Delivery Channel
2952           */
2953          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
2954 
2955              IF (l_delv_chnl_flag = 'Y') THEN
2956 
2957                  IF (NVL(prev_delivery_channel, 0) <>
2958                      NVL(iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index), 0)) THEN
2959 
2960                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2961 		 print_debuginfo(l_module_name, 'Grouping by '
2962                          || 'delivery channel triggered for document '
2963                          || curr_doc_id);
2964 
2965      END IF;
2966 
2967                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
2968                          l_calc_doc_detail, true, l_payment_id,
2969                          x_docsInPmtTab, l_docsInPmtRec,
2970                           l_docs_in_pmt_count,l_commonAttributes);
2971 
2972                      GOTO label_finish_iteration;
2973 
2974                  END IF;
2975 
2976              END IF;
2977 
2978          END IF;
2979 
2980          /*
2981           * Grouping Step 21: Express Payment
2982           */
2983          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
2984 
2985              IF (l_express_pmt_flag = 'Y') THEN
2986 
2987                  IF (NVL(prev_settle_priority, 0) <>
2988                      NVL(iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index), 0)) THEN
2989 
2990                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2991 			 print_debuginfo(l_module_name, 'Grouping by '
2992                          || 'express payment triggered for document '
2993                          || curr_doc_id);
2994 
2995      END IF;
2996 
2997                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
2998                          l_calc_doc_detail, true, l_payment_id,
2999                          x_docsInPmtTab, l_docsInPmtRec,
3000                           l_docs_in_pmt_count,l_commonAttributes);
3001 
3002                      GOTO label_finish_iteration;
3003 
3004                  END IF;
3005 
3006              END IF;
3007 
3008          END IF;
3009 
3010          /*
3011           * Grouping Step 22: Supplier Message
3012           */
3013          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
3014 
3015              IF (l_sup_msg_flag = 'Y') THEN
3016 
3017                  IF (NVL(prev_supplier_msg1, 0) <>
3018                          NVL(iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index), 0) OR
3019                      NVL(prev_supplier_msg2, 0) <>
3020                          NVL(iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index), 0) OR
3021                      NVL(prev_supplier_msg3, 0) <>
3022                          NVL(iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index), 0)) THEN
3023 
3024                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3025 			 print_debuginfo(l_module_name, 'Grouping by '
3026                          || 'supplier message triggered for document '
3027                          || curr_doc_id);
3028 
3029      END IF;
3030 
3031                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
3032                          l_calc_doc_detail, true, l_payment_id,
3033                          x_docsInPmtTab, l_docsInPmtRec,
3034                           l_docs_in_pmt_count,l_commonAttributes);
3035 
3036                      GOTO label_finish_iteration;
3037 
3038                  END IF;
3039 
3040              END IF;
3041 
3042          END IF;
3043 
3044          /*
3045           * Grouping Step 23: Unique Remittance Identifier
3046           *
3047           * Note: It is sufficient to check if the unique remittance
3048           * identifiers (uri's) are different between two documents.
3049           * No need to check if the uri checkdigits are different.
3050           * Grouping is on the basis of uri's only.
3051           */
3052          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
3053 
3054              IF (l_unique_remit_id_flag = 'Y') THEN
3055 
3056                  IF (NVL(prev_uri, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index), 0) OR
3057                      NVL(prev_uri_checkdigits, 0) <>
3058                          NVL(iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index), 0)) THEN
3059 
3060                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3061 		 print_debuginfo(l_module_name, 'Grouping by '
3062                          || 'unique remit id triggered for document '
3063                          || curr_doc_id);
3064 
3065      END IF;
3066 
3067                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
3068                          l_calc_doc_detail, true, l_payment_id,
3069                          x_docsInPmtTab, l_docsInPmtRec,
3070                           l_docs_in_pmt_count,l_commonAttributes);
3071 
3072                      GOTO label_finish_iteration;
3073 
3074                  END IF;
3075 
3076              END IF;
3077 
3078          END IF;
3079 
3080          /*
3081           * Grouping Step 24: Payment Reason Code / Payment Reason Comments
3082           */
3083          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
3084 
3085              IF (l_pmt_reason_flag = 'Y') THEN
3086 
3087                  IF (NVL(prev_pmt_reason_code, 0)   <>
3088                          NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index), 0)  OR
3089                      NVL(prev_pmt_reason_commts, 0) <>
3090                          NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index), 0)) THEN
3091 
3092                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3093 		 print_debuginfo(l_module_name, 'Grouping by '
3094                          || 'payment reason code / comments triggered '
3095                          || 'for document '
3096                          || curr_doc_id);
3097 
3098      END IF;
3099 
3100                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
3101                          l_calc_doc_detail, true, l_payment_id,
3102                          x_docsInPmtTab, l_docsInPmtRec,
3103                           l_docs_in_pmt_count,l_commonAttributes);
3104 
3105                      GOTO label_finish_iteration;
3106 
3107                  END IF;
3108 
3109              END IF;
3110 
3111          END IF;
3112 
3113          /*
3114           * Grouping Step 25: Payment Due Date
3115           */
3116          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
3117 
3118              IF (l_due_date_flag = 'Y') THEN
3119 
3120                  IF (NVL(prev_pmt_due_date, l_impossible_date) <>
3121                      NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index), l_impossible_date)) THEN
3122 
3123                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3124 		 print_debuginfo(l_module_name, 'Grouping by '
3125                          || 'payment due date triggered for document '
3126                          || curr_doc_id);
3127 
3128      END IF;
3129 
3130                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
3131                          l_calc_doc_detail, true, l_payment_id,
3132                          x_docsInPmtTab, l_docsInPmtRec,
3133                           l_docs_in_pmt_count,l_commonAttributes);
3134 
3135                      GOTO label_finish_iteration;
3136 
3137                  END IF;
3138 
3139              END IF;
3140 
3141          END IF;
3142 
3143          /*
3144           * Grouping Step 26: Max Documents Per Payment
3145           */
3146          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
3147 
3148              IF (l_max_docs_flag = 'Y') THEN
3149 
3150                  IF (l_docs_in_pmt_count = l_max_docs_limit) THEN
3151 
3152                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3153 			 print_debuginfo(l_module_name, 'Grouping by '
3154                          || 'max docs per payment triggered for document '
3155                          || curr_doc_id);
3156 
3157      END IF;
3158 
3159                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
3160                          l_calc_doc_detail, true, l_payment_id,
3161                          x_docsInPmtTab, l_docsInPmtRec,
3162                           l_docs_in_pmt_count,l_commonAttributes);
3163 
3164                      GOTO label_finish_iteration;
3165 
3166                  END IF;
3167 
3168              END IF;
3169 
3170          END IF;
3171 
3172          /*
3173           * Grouping Step 27: Break Payments According To Payment Details
3174           *                   Field Length
3175           */
3176          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
3177 
3178              IF (l_pmt_details_flag = 'Y') THEN
3179 
3180                  IF (LENGTH(l_paymentRec.payment_details || l_calc_doc_detail)
3181                      > l_pmt_details_len) THEN
3182 
3183                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3184 			 print_debuginfo(l_module_name, 'Grouping by '
3185                          || 'payment details length triggered for document '
3186                          || curr_doc_id);
3187 
3188      END IF;
3189 
3190                      insertDocIntoPayment(l_paymentRec, x_paymentTab,
3191                          l_calc_doc_detail, true, l_payment_id,
3192                          x_docsInPmtTab, l_docsInPmtRec,
3193                           l_docs_in_pmt_count,l_commonAttributes);
3194 
3195                      GOTO label_finish_iteration;
3196 
3197                  END IF;
3198 
3199              END IF;
3200 
3201          END IF;
3202 
3203          /*
3204           * End Of Grouping:
3205           * If a document reaches here, it means that this document
3206           * is similar to the previous document as far a grouping
3207           * criteria is concerned.
3208           *
3209           * Add this document to the currently running payment.
3210           */
3211          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN  --vid- start here
3212 	  print_debuginfo(l_module_name, 'No grouping rules '
3213              || 'were triggered for document '
3214              || curr_doc_id);
3215 
3216 
3217          END IF;
3218          insertDocIntoPayment(l_paymentRec, x_paymentTab,
3219              l_calc_doc_detail, false, l_payment_id,
3220              x_docsInPmtTab, l_docsInPmtRec,
3221               l_docs_in_pmt_count,l_commonAttributes);
3222 
3223          <<label_finish_iteration>>
3224 
3225          /*
3226           * CBR Handling:
3227           *
3228           * For each payment, store the central bank reporting
3229           * related fields along with the payment id in the
3230           * CBR table.
3231           *
3232           * This table will be passed as an output param to
3233           * the routine that sets the 'declare payment flag'
3234           * on the payment based on the CBR fields.
3235           *
3236           * We just created a payment. If this payment
3237           * does not already exist in the CBR list, add
3238           * it to the list.
3239           */
3240           l_profile_id := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
3241 /*  Bug 5709596 */
3242           IF NOT(iby_disburse_submit_pub_pkg.paymentProfilesTab.exists(l_profile_id)) THEN
3243              iby_disburse_submit_pub_pkg.set_profile_attribs(l_profile_id);
3244           END IF;
3245 
3246          /*
3247           * Lastly, before going into the next iteration
3248           * of the loop copy all the current grouping criteria
3249           * into 'prev' fields so that we can compare these
3250           * fields with the next record.
3251           *
3252           * No need to copy the current values into the previous ones for
3253           * the first record because we have already done it at the beginning.
3254           *
3255           *
3256           * Fix for bug 5463733:
3257           *
3258           * Reset the prev pmt grouping number here, else
3259           * the next document may incorrectly be grouped
3260           * into another payment.
3261           */
3262 
3263          IF (l_first_record <> 'Y') THEN
3264             prev_doc_id            := iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index);
3265             prev_ca_id             := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
3266             prev_ca_doc_id1        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index);
3267             prev_ca_doc_id2        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index);
3268             prev_ca_doc_id3        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index);
3269             prev_ca_doc_id4        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index);
3270             prev_ca_doc_id5        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index);
3271             prev_pp_tt_cd          := iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index);
3272             prev_pmt_grp_num       := iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index);
3273             prev_pmt_method_cd     := iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index);
3274             prev_int_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
3275             prev_ext_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
3276             prev_profile_id        := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
3277             prev_org_id            := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
3278             prev_org_type          := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
3279             prev_payee_id          := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
3280             prev_payee_site_id     := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
3281             prev_remit_loc_id      := iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index);
3282             prev_ext_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
3283             prev_doc_pmt_currency  := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
3284             prev_doc_pmt_amount    := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index);
3285             prev_pay_alone_flag    := iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index);
3286             prev_bnk_chg_bearer    := iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index);
3287             prev_delivery_channel  := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
3288             prev_settle_priority   := iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index);
3289             prev_supplier_msg1     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index);
3290             prev_supplier_msg2     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index);
3291             prev_supplier_msg3     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index);
3292             prev_uri               := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
3293             prev_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
3294             prev_pmt_reason_code   := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index);
3295             prev_pmt_reason_commts := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index);
3296             prev_pmt_function      := iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index);
3297             prev_pmt_date          := iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index);
3298             prev_pmt_due_date      := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
3299             prev_benef_party       := iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index);
3300             prev_address_source    := iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index);
3301             prev_emp_add_code      := iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index);
3302             prev_emp_person_id     := iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index);
3303             prev_emp_addr_id       := iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index);
3304             prev_emp_pmt_flag      := iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index);
3305 
3306             prev_inv_payee_party_id          := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
3307             prev_inv_party_site_id     := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
3308             prev_inv_beneficiary_party      := iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party(l_trx_line_index);
3309             prev_ext_inv_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
3310 
3311          END IF;
3312 
3313          /*
3314           *  Remember to reset the first record flag before going
3315           *  into the next iteration.
3316           */
3317          IF (l_first_record = 'Y') THEN
3318              l_first_record := 'N';
3319          END IF;
3320 
3321          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3322  print_debuginfo(l_module_name, '+----------------------------------+');
3323          END IF;
3324 
3325         END LOOP; -- for documents cursor
3326 
3327         EXIT WHEN c_documents%NOTFOUND;
3328 
3329      END LOOP; -- for documents cursor
3330 
3331      iby_disburse_submit_pub_pkg.delete_docspayTab;
3332 
3333      CLOSE c_documents;
3334 
3335      /*
3336       * Exit if no documents were found.
3337       */
3338      IF (l_no_rec_in_ppr) THEN
3339          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3340 	 print_debuginfo(l_module_name, 'No documents payable were '
3341              || 'retrieved from DB for payment request '
3342              || p_payment_request_id
3343              || '. Exiting document grouping ..');
3344 
3345 
3346 	 print_debuginfo(l_module_name, 'EXIT');
3347 
3348          END IF;
3349          RETURN;
3350      END IF;
3351 
3352 
3353      /*
3354       * Populate legal entity ids for each of the created payments.
3355       *
3356       * The legal entity id on the payment is a special attribute.
3357       * It is not a grouping rule, instead it has to be derived
3358       * from the internal bank account and populated.
3359       */
3360 
3361      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3362 	 print_debuginfo(l_module_name, 'Created '
3363          || x_paymentTab.COUNT   || ' payment(s) from '
3364          || x_docsInPmtTab.COUNT || ' document(s) for payment request '
3365          || p_payment_request_id || '.');
3366      END IF;
3367      /*
3368       * Finally, return the payments created by grouping to the caller.
3369       */
3370      x_ca_id        := l_ca_id;
3371      x_ca_payreq_cd := l_ca_payreq_cd;
3372 
3373      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3374 	 print_debuginfo(l_module_name, 'EXIT');
3375      END IF;
3376  END performDocumentGrouping;
3377 
3378 /*--------------------------------------------------------------------
3379  | NAME:
3380  |     performDocumentGrouping
3381  |
3382  | PURPOSE:
3383  |
3384  |
3385  |
3386  | PARAMETERS:
3387  |     IN
3388  |
3389  |
3390  |     OUT
3391  |
3392  |
3393  | RETURNS:
3394  |
3395  | NOTES:
3396  |
3397  *---------------------------------------------------------------------*/
3398  PROCEDURE performDocumentGrouping(
3399      p_payment_request_id   IN IBY_PAY_SERVICE_REQUESTS.
3400                                          payment_service_request_id%TYPE,
3401      --x_paymentTab           IN OUT NOCOPY IBY_PAYGROUP_PUB.paymentTabType,
3402      x_ca_id                IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
3403                                               calling_app_id%TYPE,
3404      x_ca_payreq_cd         IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
3405                                               call_app_pay_service_req_code
3406                                               %TYPE,
3407      x_payReqCriteria       IN OUT NOCOPY IBY_PAYGROUP_PUB.
3408                                               payReqImposedCriteria
3409 
3410 -- , x_cbrTab               IN OUT NOCOPY IBY_PAYGROUP_PUB.
3411 --                                             centralBankReportTabType
3412      )
3413  IS
3414  l_module_name           CONSTANT VARCHAR2(200) := G_PKG_NAME ||
3415                                                    '.performDocumentGrouping';
3416  l_default_debug_level VARCHAR2(200) := FND_LOG.LEVEL_STATEMENT;
3417  l_first_record          VARCHAR2(1)   := 'Y';
3418  l_payment_id            NUMBER(15)    := 0;
3419  l_payment_total         NUMBER(15)    := 0;
3420  l_payment_docs_cnt      NUMBER(10)    := 0;
3421  l_sup_msg_flag          VARCHAR2(1)   := 'N';
3422  l_bnk_chg_brer_flag     VARCHAR2(1)   := 'N';
3423  l_delv_chnl_flag        VARCHAR2(1)   := 'N';
3424  l_express_pmt_flag      VARCHAR2(1)   := 'N';
3425  l_pmt_details_flag      VARCHAR2(1)   := 'N';
3426  l_pmt_details_len       NUMBER(15)    := 0;
3427  l_pmt_det_formula       VARCHAR2(2000):= 0;
3428  l_max_docs_flag         VARCHAR2(1)   := 'N';
3429  l_max_docs_limit        NUMBER(15)    := 0;
3430  l_docs_in_pmt_count     NUMBER(15)    := 0;
3431  l_unique_remit_id_flag  VARCHAR2(1)   := 'N';
3432  l_pmt_reason_flag       VARCHAR2(1)   := 'N';
3433  l_due_date_flag         VARCHAR2(1)   := 'N';
3434  l_prom_note_flag        VARCHAR2(1)   := 'N';
3435 
3436  l_profile_id            IBY_PAYMENT_PROFILES.payment_profile_id%type;
3437 
3438  /*
3439   * Used to substitute null values in date comparisons.
3440   * It is assumed that year 5100 = doomsday.
3441   */
3442  l_impossible_date       DATE := TO_DATE('01/01/5100 10:25:55',
3443                                      'MM/DD/YYYY HH24:MI:SS');
3444 
3445  l_bank_inst1_code       IBY_PAYMENTS_ALL.bank_instruction1_code%TYPE;
3446  l_bank_inst2_code       IBY_PAYMENTS_ALL.bank_instruction1_code%TYPE;
3447  l_pmt_txt_msg1          IBY_PAYMENTS_ALL.payment_text_message1%TYPE;
3448  l_pmt_txt_msg2          IBY_PAYMENTS_ALL.payment_text_message2%TYPE;
3449  l_pmt_txt_msg3          IBY_PAYMENTS_ALL.payment_text_message3%TYPE;
3450 
3451  l_processing_type       VARCHAR2(100);  -- CHECK | ELECTRONIC
3452  l_calc_doc_detail       VARCHAR2(1000); -- Stores details for a single doc
3453 
3454  /* these are related to central bank reporting */
3455  l_decl_option             VARCHAR2(100) := '';
3456  l_decl_only_fx_flag       VARCHAR2(1)   := '';
3457  l_decl_curr_fx_rate_type  VARCHAR2(255) := '';
3458  l_decl_curr_code          VARCHAR2(10)  := '';
3459  l_decl_threshold_amount   NUMBER(15)    := 0;
3460 /*
3461  l_cbrRec                  IBY_PAYGROUP_PUB.centralBankReportRecType;
3462  l_cbrTab                  IBY_PAYGROUP_PUB.centralBankReportTabType;
3463  l_cbr_rec_exists          BOOLEAN       := FALSE;
3464 */
3465 
3466  l_ca_payreq_cd            VARCHAR2(255) := '';
3467  l_ca_id                   NUMBER(15)    := 0;
3468  l_all_pmts_success_flag   BOOLEAN       := FALSE;
3469  l_all_pmts_failed_flag    BOOLEAN       := FALSE;
3470  l_le_id                   NUMBER(15)    := 0;
3471 
3472  /* rejection level system options */
3473  l_rejection_level         VARCHAR2(200);
3474  l_review_pmts_flag        VARCHAR2(1)   := 'N';
3475 
3476  l_paymentRec        IBY_PAYMENTS_ALL%ROWTYPE;
3477  l_docsInPmtRec      IBY_PAYGROUP_PUB.docsInPaymentRecType;
3478 
3479  /*
3480   * These two are related data structures. Each row in paymentTabType
3481   * PLSQL table is used in inserting a row into the IBY_PAYMENTS_ALL
3482   * table.
3483   *
3484   * Since the IBY_PAYMENTS_ALL table does not contain a document id, a
3485   * separate data structure is needed to keep track of the documents
3486   * that are part of a payment. This information is tracked in the
3487   * docsInPaymentTabType table. The rows in docsInPaymentTabType are
3488   * used to update the rows in IBY_DOCS_PAYABLE_ALL table with
3489   * payment ids.
3490   *
3491   *            x_paymentTab                        x_docsInPmtTab
3492   *       (insert into IBY_PAYMENTS_ALL)          (update IBY_DOCS_PAYABLE)
3493   * /-------------------------------------\       /------------\
3494   * |Payment|Payment|..|Payment|Docs   |..|       |Payment|Doc |
3495   * |Id     |Profile|..|Amount |Payable|..|       |Id     |Id  |
3496   * |       |Id     |..|       |Count  |..|       |       |    |
3497   * |-------------------------------------|       |------------|
3498   * |   4000|     10|  |    550|      3|  |       |   4000| 501|
3499   * |       |       |  |       |       |  |       |   4000| 504|
3500   * |       |       |  |       |       |  |       |   4000| 505|
3501   * |-------|-------|--|-------|-------|--|       |-------|----|
3502   * |   4001|     10|  |1063.70|     19|  |       |   4001| 502|
3503   * |       |       |  |       |       |  |       |   4001| 509|
3504   * |       |       |  |       |       |  |       |   4001| 511|
3505   * |       |       |  |       |       |  |       |   4001| 523|
3506   * |       |       |  |       |       |  |       |     : |  : |
3507   * |-------|-------|--|-------|-------|--|       |-------|----|
3508   * |    :  |     : |  |    :  |     : |  |       |     : |  : |
3509   * \_______|_______|__|_______|_______|__/       \_______|____/
3510   *
3511   * Combining these two structures into one structure is messy
3512   * because you cannot directly use the combined data structure for
3513   * bulk updates.
3514   */
3515 
3516  /* these two are passed to calling app via hook */
3517  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
3518  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
3519 
3520  /* holds the error messages against failed documents */
3521  l_docErrorTab       IBY_VALIDATIONSETS_PUB.docErrorTabType;
3522 
3523  /* holds list of internal bank accounts with corresponding legal entity id */
3524  l_bankAcctLETab     bankAccountLETabType;
3525 
3526  l_commonAttributes commonAttributesTabType;
3527 
3528  /* previous document attributes */
3529  prev_doc_id                 iby_docs_payable_all.document_payable_id%TYPE;
3530  prev_ca_id                  iby_docs_payable_all.calling_app_id%TYPE;
3531  prev_ca_doc_id1             iby_docs_payable_all.
3532                                  calling_app_doc_unique_ref1%TYPE;
3533  prev_ca_doc_id2             iby_docs_payable_all.
3534                                  calling_app_doc_unique_ref2%TYPE;
3535  prev_ca_doc_id3             iby_docs_payable_all.
3536                                  calling_app_doc_unique_ref3%TYPE;
3537  prev_ca_doc_id4             iby_docs_payable_all.
3538                                  calling_app_doc_unique_ref4%TYPE;
3539  prev_ca_doc_id5             iby_docs_payable_all.
3540                                  calling_app_doc_unique_ref5%TYPE;
3541  prev_pp_tt_cd               iby_docs_payable_all.pay_proc_trxn_type_code%TYPE;
3542  prev_pmt_grp_num            iby_docs_payable_all.payment_grouping_number%TYPE;
3543  prev_pmt_method_cd          iby_docs_payable_all.payment_method_code%TYPE;
3544  prev_doc_pmt_currency       iby_docs_payable_all.payment_currency_code%TYPE;
3545  prev_doc_pmt_amount         iby_docs_payable_all.payment_amount%TYPE;
3546  prev_int_bank_acct_id       iby_docs_payable_all.
3547                                  internal_bank_account_id%TYPE;
3548  prev_ext_bank_acct_id       iby_docs_payable_all.
3549                                  external_bank_account_id%TYPE;
3550  prev_payee_id               iby_docs_payable_all.payee_party_id%TYPE;
3551  prev_payee_site_id          iby_docs_payable_all.party_site_id%TYPE;
3552  prev_supplier_site_id       iby_docs_payable_all.supplier_site_id%TYPE;
3553  prev_remit_loc_id           iby_docs_payable_all.remit_to_location_id%TYPE;
3554  prev_ext_payee_id           iby_docs_payable_all.ext_payee_id%TYPE;
3555  prev_org_id                 iby_docs_payable_all.org_id%TYPE;
3556  prev_org_type               iby_docs_payable_all.org_type%TYPE;
3557  prev_profile_id             iby_docs_payable_all.payment_profile_id%TYPE;
3558  prev_pay_alone_flag         iby_docs_payable_all.exclusive_payment_flag%TYPE;
3559  prev_supplier_msg1          iby_docs_payable_all.remittance_message1%TYPE;
3560  prev_supplier_msg2          iby_docs_payable_all.remittance_message2%TYPE;
3561  prev_supplier_msg3          iby_docs_payable_all.remittance_message3%TYPE;
3562  prev_bnk_chg_bearer         iby_docs_payable_all.bank_charge_bearer%TYPE;
3563  prev_delivery_channel       iby_docs_payable_all.delivery_channel_code%TYPE;
3564  prev_settle_priority        iby_docs_payable_all.settlement_priority%TYPE;
3565  prev_uri                    iby_docs_payable_all.
3566                                  unique_remittance_identifier%TYPE;
3567  prev_uri_checkdigits        iby_docs_payable_all.uri_check_digit%TYPE;
3568  prev_pmt_reason_code        iby_docs_payable_all.payment_reason_code%TYPE;
3569  prev_pmt_reason_commts      iby_docs_payable_all.payment_reason_comments%TYPE;
3570  prev_pmt_function           iby_docs_payable_all.payment_function%TYPE;
3571  prev_pmt_date               iby_docs_payable_all.payment_date%TYPE;
3572  prev_pmt_due_date           iby_docs_payable_all.payment_due_date%TYPE;
3573  prev_benef_party            iby_docs_payable_all.beneficiary_party%TYPE;
3574 
3575  /* payee (employee) address related fields */
3576  prev_address_source         iby_docs_payable_all.address_source%TYPE;
3577  prev_emp_add_code           iby_docs_payable_all.employee_address_code%TYPE;
3578  prev_emp_person_id          iby_docs_payable_all.employee_person_id%TYPE;
3579  prev_emp_addr_id            iby_docs_payable_all.employee_address_id%TYPE;
3580 
3581  prev_emp_pmt_flag           iby_docs_payable_all.employee_payment_flag%TYPE;
3582 
3583  /*TPP-Start*/
3584  prev_inv_payee_party_id         iby_docs_payable_all.inv_payee_party_id%TYPE;
3585  prev_inv_party_site_id          iby_docs_payable_all.inv_party_site_id%TYPE;
3586  prev_inv_supplier_site_id       iby_docs_payable_all.inv_supplier_site_id%TYPE;
3587  prev_ext_inv_payee_id           iby_docs_payable_all.ext_inv_payee_id%TYPE;
3588  prev_inv_beneficiary_party            iby_docs_payable_all.inv_beneficiary_party%TYPE;
3589 
3590  curr_inv_payee_party_id         iby_docs_payable_all.inv_payee_party_id%TYPE;
3591  curr_inv_party_site_id          iby_docs_payable_all.inv_party_site_id%TYPE;
3592  curr_inv_supplier_site_id       iby_docs_payable_all.inv_supplier_site_id%TYPE;
3593  curr_ext_inv_payee_id           iby_docs_payable_all.ext_inv_payee_id%TYPE;
3594  curr_inv_beneficiary_party            iby_docs_payable_all.inv_beneficiary_party%TYPE;
3595  /*TPP-End*/
3596 
3597 
3598  /* current document attributes */
3599  curr_doc_id                 iby_docs_payable_all.document_payable_id%TYPE;
3600  curr_ca_id                  iby_docs_payable_all.calling_app_id%TYPE;
3601  curr_ca_doc_id1             iby_docs_payable_all.
3602                                  calling_app_doc_unique_ref1%TYPE;
3603  curr_ca_doc_id2             iby_docs_payable_all.
3604                                  calling_app_doc_unique_ref2%TYPE;
3605  curr_ca_doc_id3             iby_docs_payable_all.
3606                                  calling_app_doc_unique_ref3%TYPE;
3607  curr_ca_doc_id4             iby_docs_payable_all.
3608                                  calling_app_doc_unique_ref4%TYPE;
3609  curr_ca_doc_id5             iby_docs_payable_all.
3610                                  calling_app_doc_unique_ref5%TYPE;
3611  curr_pp_tt_cd               iby_docs_payable_all.pay_proc_trxn_type_code%TYPE;
3612  curr_pmt_grp_num            iby_docs_payable_all.payment_grouping_number%TYPE;
3613  curr_pmt_method_cd          iby_docs_payable_all.payment_method_code%TYPE;
3614  curr_doc_pmt_currency       iby_docs_payable_all.payment_currency_code%TYPE;
3615  curr_doc_pmt_amount         iby_docs_payable_all.payment_amount%TYPE;
3616  curr_int_bank_acct_id       iby_docs_payable_all.
3617                                  internal_bank_account_id%TYPE;
3618  curr_ext_bank_acct_id       iby_docs_payable_all.
3619                                  external_bank_account_id%TYPE;
3620  curr_org_id                 iby_docs_payable_all.org_id%TYPE;
3621  curr_org_type               iby_docs_payable_all.org_type%TYPE;
3622  curr_payee_id               iby_docs_payable_all.payee_party_id%TYPE;
3623  curr_payee_site_id          iby_docs_payable_all.party_site_id%TYPE;
3624  curr_supplier_site_id       iby_docs_payable_all.supplier_site_id%TYPE;
3625  curr_remit_loc_id           iby_docs_payable_all.remit_to_location_id%TYPE;
3626  curr_ext_payee_id           iby_docs_payable_all.ext_payee_id%TYPE;
3627  curr_profile_id             iby_docs_payable_all.payment_profile_id%TYPE;
3628  curr_pay_alone_flag         iby_docs_payable_all.exclusive_payment_flag%TYPE;
3629  curr_supplier_msg1          iby_docs_payable_all.remittance_message1%TYPE;
3630  curr_supplier_msg2          iby_docs_payable_all.remittance_message2%TYPE;
3631  curr_supplier_msg3          iby_docs_payable_all.remittance_message3%TYPE;
3632  curr_bnk_chg_bearer         iby_docs_payable_all.bank_charge_bearer%TYPE;
3633  curr_delivery_channel       iby_docs_payable_all.delivery_channel_code%TYPE;
3634  curr_settle_priority        iby_docs_payable_all.settlement_priority%TYPE;
3635  curr_uri                    iby_docs_payable_all.
3636                                  unique_remittance_identifier%TYPE;
3637  curr_uri_checkdigits        iby_docs_payable_all.uri_check_digit%TYPE;
3638  curr_pmt_reason_code        iby_docs_payable_all.payment_reason_code%TYPE;
3639  curr_pmt_reason_commts      iby_docs_payable_all.payment_reason_comments%TYPE;
3640  curr_pmt_function           iby_docs_payable_all.payment_function%TYPE;
3641  curr_pmt_date               iby_docs_payable_all.payment_date%TYPE;
3642  curr_pmt_due_date           iby_docs_payable_all.payment_due_date%TYPE;
3643  curr_benef_party            iby_docs_payable_all.beneficiary_party%TYPE;
3644 
3645  /* payee (employee) address related fields */
3646  curr_address_source         iby_docs_payable_all.address_source%TYPE;
3647  curr_emp_add_code           iby_docs_payable_all.employee_address_code%TYPE;
3648  curr_emp_person_id          iby_docs_payable_all.employee_person_id%TYPE;
3649  curr_emp_addr_id            iby_docs_payable_all.employee_address_id%TYPE;
3650 
3651  curr_emp_pmt_flag           iby_docs_payable_all.employee_payment_flag%TYPE;
3652 
3653  /* these two are passed to the external application hook */
3654  l_amount_withheld           iby_docs_payable_all.amount_withheld%TYPE;
3655 
3656  /* used for maturity date calculation */
3657  l_discount_date             iby_docs_payable_all.discount_date%TYPE;
3658 
3659  /* passed to hook */
3660  l_discount_amount           iby_docs_payable_all.payment_curr_discount_taken
3661                                                       %TYPE;
3662  l_trx_line_index            BINARY_INTEGER;
3663  l_no_rec_in_ppr             BOOLEAN;
3664  G_LINES_PER_FETCH           CONSTANT  NUMBER:= 1000;
3665 -- G_LINES_PER_FETCH           CONSTANT  NUMBER:= 3;
3666 
3667  /*
3668   * This cursor up will pick up all valid documents for the specified
3669   * payment request. The select statement will order the documents
3670   * based on grouping criteria.
3671   *
3672   * As the grouping is operation is commutative, there is no
3673   * need to group the documents by any particular order (in
3674   * other words, grouping 1 followed by grouping 2, will lead
3675   * to the same results as grouping 2 followed by grouping 1).
3676   *
3677   * Important Note:
3678   * Always ensure that there is a corresponding order by
3679   * clause for each grouping criterion that you wish to use.
3680   * This is required in order to create minimum possible
3681   * payments from a given set of documents.
3682   *
3683   *
3684   * Populate legal entity ids for each of the created payments.
3685   * The legal entity id on the payment is a special attribute.
3686   * It is not a grouping rule, instead it has to be derived
3687   * from the internal bank account and populated.
3688   *
3689   */
3690  CURSOR c_documents(p_payment_request_id VARCHAR2)
3691  IS
3692  SELECT prq.call_app_pay_service_req_code,   -- Callers pay req id
3693         docs.document_payable_id,            -- Unique doc id asgn by IBY
3694 	docs.calling_app_id,                 --| The caller
3695         docs.calling_app_doc_unique_ref1,    --| uses these
3696         docs.calling_app_doc_unique_ref2,    --| seven fields
3697         docs.calling_app_doc_unique_ref3,    --| to uniquely
3698         docs.calling_app_doc_unique_ref4,    --| identify
3699         docs.calling_app_doc_unique_ref5,    --| a document
3700         docs.pay_proc_trxn_type_code,        --| payable
3701         docs.payment_grouping_number,        -- Identifies related docs
3702         docs.payment_method_code,            -- Payment method
3703         docs.internal_bank_account_id,       -- Internal bank account id
3704         docs.external_bank_account_id,       -- External bank account id
3705         docs.payment_profile_id,             -- Payment profile id
3706         docs.org_id,
3707         docs.org_type,
3708         docs.payment_function,
3709         docs.ext_payee_id,                   -- Ext payee id (payee context)
3710         docs.payee_party_id,
3711         docs.party_site_id,
3712         docs.supplier_site_id,
3713         docs.remit_to_location_id,
3714         docs.amount_withheld,                -- Passed to hook for adjustmt
3715         ext_payee.bank_instruction1_code,    --|
3716         ext_payee.bank_instruction2_code,    --| These fields are
3717         ext_payee.payment_text_message1,     --| derived from the
3718         ext_payee.payment_text_message2,     --| payee.
3719         ext_payee.payment_text_message3,     --|
3720         docs.payment_currency_code,
3721         docs.payment_amount,
3722         docs.payment_date,
3723         docs.exclusive_payment_flag,
3724         docs.bank_charge_bearer,             -- Bank charge bearer
3725         docs.delivery_channel_code,          -- Delivery channel
3726         docs.settlement_priority,
3727         docs.remittance_message1,            -- Supplier message 1
3728         docs.remittance_message2,            -- Supplier message 2
3729         docs.remittance_message3,            -- Supplier message 3
3730         docs.unique_remittance_identifier,
3731         docs.uri_check_digit,
3732         docs.payment_reason_code,
3733         docs.payment_reason_comments,
3734         docs.payment_due_date,
3735         docs.discount_date,
3736         docs.payment_curr_discount_taken,
3737         docs.beneficiary_party,
3738         docs.address_source,                 --
3739         docs.employee_address_code,          -- Employee address
3740         docs.employee_person_id,             -- related fields
3741         docs.employee_address_id,            --
3742         docs.employee_payment_flag,
3743         pcr.group_by_remittance_message,
3744         pcr.group_by_bank_charge_bearer,
3745         pcr.group_by_delivery_channel,
3746         pcr.group_by_settle_priority_flag,
3747         pcr.group_by_payment_details_flag,
3748         DECODE(pcr.payment_details_length_limit, NULL,
3749             -1, pcr.payment_details_length_limit),
3750         pcr.payment_details_formula,
3751         pcr.group_by_max_documents_flag,     -- Max documents per payment flag
3752         pcr.max_documents_per_payment,       -- Max documents per payment value
3753         pcr.group_by_unique_remit_id_flag,
3754         pcr.group_by_payment_reason,
3755         pcr.group_by_due_date_flag,
3756         ppf.processing_type,
3757         ppf.declaration_option,
3758         ppf.dcl_only_foreign_curr_pmt_flag,
3759         ppf.declaration_curr_fx_rate_type,
3760         ppf.declaration_currency_code,
3761         ppf.declaration_threshold_amount,
3762         DECODE(prq.maximum_payment_amount, NULL, -1,
3763             prq.maximum_payment_amount),
3764         DECODE(prq.minimum_payment_amount, NULL, -1,
3765             prq.minimum_payment_amount),
3766         prq.allow_zero_payments_flag,
3767         pmt_mthd.support_bills_payable_flag,
3768         iba.account_owner_org_id,
3769 	/*TPP-Start*/
3770         docs.inv_payee_party_id,
3771         docs.inv_party_site_id,
3772         docs.inv_supplier_site_id,
3773         docs.inv_beneficiary_party,
3774         docs.ext_inv_payee_id,
3775 	/*TPP-Start*/
3776 	    docs.affects_rejection_level  --AWT Enh 16296267
3777  FROM IBY_DOCS_PAYABLE_ALL       docs,
3778       IBY_PMT_CREATION_RULES     pcr,
3779       IBY_PAYMENT_PROFILES       ppf,
3780       IBY_PAY_SERVICE_REQUESTS   prq,
3781       IBY_EXTERNAL_PAYEES_ALL    ext_payee,
3782       IBY_PAYMENT_METHODS_B      pmt_mthd,
3783       CE_BANK_ACCOUNTS           iba
3784  WHERE  prq.payment_service_request_id  = p_payment_request_id
3785  AND    docs.payment_service_request_id = prq.payment_service_request_id
3786  AND    docs.payment_profile_id         = ppf.payment_profile_id
3787  AND    ppf.system_profile_code         = pcr.system_profile_code(+)
3788  AND    docs.document_status            = DOC_STATUS_VALIDATED
3789  AND    docs.ext_payee_id               = ext_payee.ext_payee_id
3790  AND    docs.payment_method_code        = pmt_mthd.payment_method_code
3791  AND    docs.internal_bank_account_id   = iba.bank_account_id
3792  ORDER BY
3793         docs.exclusive_payment_flag,
3794         docs.org_id,
3795         docs.org_type,
3796         ext_payee.ext_payee_id,        -- \
3797         docs.payment_currency_code,    -- |
3798         docs.payment_method_code,      -- |
3799         docs.payment_profile_id,       -- |
3800         docs.payment_grouping_number,  -- |
3801         docs.internal_bank_account_id, -- | Ensure that the grouping
3802         docs.external_bank_account_id, -- | rules below follow the same
3803         docs.payment_function,         -- | ordering as this order by
3804         docs.payment_date,             -- | clause.
3805         docs.remit_to_location_id,     -- |
3806         docs.beneficiary_party,        -- |
3807         docs.address_source,           -- |
3808         docs.employee_address_code,    -- |
3809         docs.employee_person_id,       -- |
3810         docs.employee_address_id,      -- |
3811         docs.employee_payment_flag,    -- |
3812         docs.bank_charge_bearer,       -- |
3813         docs.delivery_channel_code,    -- | This order must be followed
3814         docs.settlement_priority,      -- | for creating minimum number
3815         docs.remittance_message1,      -- | of payments.
3816         docs.remittance_message2,      -- |
3817         docs.remittance_message3,      -- /
3818         docs.unique_remittance_identifier,
3819         docs.uri_check_digit,
3820         docs.payment_reason_code,
3821         docs.payment_reason_comments,
3822         docs.payment_due_date,
3823         docs.calling_app_doc_ref_number
3824         ;
3825 
3826  /*
3827   * Cursor to pick up all possible internal bank accounts
3828   * along with their corresponding legal entity ids.
3829   *
3830  CURSOR c_bank_acct_le_list
3831  IS
3832  SELECT
3833      iba.bank_account_id       int_bank_account,
3834      iba.account_owner_org_id  legal_entity_id
3835  FROM
3836      CE_BANK_ACCOUNTS iba
3837  ;
3838   */
3839 
3840   l_length number(15):=0;
3841 
3842  BEGIN
3843 
3844      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3845 	 print_debuginfo(l_module_name, 'ENTER');
3846 
3847      print_debuginfo(l_module_name, 'Payment Request Id : '||
3848          p_payment_request_id);
3849 
3850      END IF;
3851 
3852      l_no_rec_in_ppr := TRUE;
3853      /*
3854       * Pick up all the documents of the payment request.
3855       */
3856      OPEN  c_documents(p_payment_request_id);
3857      LOOP
3858         iby_disburse_submit_pub_pkg.delete_docspayTab;
3859         FETCH c_documents BULK COLLECT INTO
3860            iby_disburse_submit_pub_pkg.docspayTab.call_app_pay_service_req_code,
3861            iby_disburse_submit_pub_pkg.docspayTab.document_payable_id,
3862            iby_disburse_submit_pub_pkg.docspayTab.calling_app_id,
3863            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1,
3864            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2,
3865            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3,
3866            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4,
3867            iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5,
3868            iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code,
3869            iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number,
3870            iby_disburse_submit_pub_pkg.docspayTab.payment_method_code,
3871            iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id,
3872            iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id,
3873            iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id,
3874            iby_disburse_submit_pub_pkg.docspayTab.org_id,
3875            iby_disburse_submit_pub_pkg.docspayTab.org_type,
3876            iby_disburse_submit_pub_pkg.docspayTab.payment_function,
3877            iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id,
3878            iby_disburse_submit_pub_pkg.docspayTab.payee_party_id,
3879            iby_disburse_submit_pub_pkg.docspayTab.party_site_id,
3880            iby_disburse_submit_pub_pkg.docspayTab.supplier_site_id,
3881            iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id,
3882            iby_disburse_submit_pub_pkg.docspayTab.amount_withheld,
3883            iby_disburse_submit_pub_pkg.docspayTab.bank_instruction1_code,
3884            iby_disburse_submit_pub_pkg.docspayTab.bank_instruction2_code,
3885            iby_disburse_submit_pub_pkg.docspayTab.payment_text_message1,
3886            iby_disburse_submit_pub_pkg.docspayTab.payment_text_message2,
3887            iby_disburse_submit_pub_pkg.docspayTab.payment_text_message3,
3888            iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code,
3889            iby_disburse_submit_pub_pkg.docspayTab.payment_amount,
3890            iby_disburse_submit_pub_pkg.docspayTab.payment_date,
3891            iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag,
3892            iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer,
3893            iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code,
3894            iby_disburse_submit_pub_pkg.docspayTab.settlement_priority,
3895            iby_disburse_submit_pub_pkg.docspayTab.remittance_message1,
3896            iby_disburse_submit_pub_pkg.docspayTab.remittance_message2,
3897            iby_disburse_submit_pub_pkg.docspayTab.remittance_message3,
3898            iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier,
3899            iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit,
3900            iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code,
3901            iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments,
3902            iby_disburse_submit_pub_pkg.docspayTab.payment_due_date,
3903            iby_disburse_submit_pub_pkg.docspayTab.discount_date,
3904            iby_disburse_submit_pub_pkg.docspayTab.payment_curr_discount_taken,
3905            iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party,
3906            iby_disburse_submit_pub_pkg.docspayTab.address_source,
3907            iby_disburse_submit_pub_pkg.docspayTab.employee_address_code,
3908            iby_disburse_submit_pub_pkg.docspayTab.employee_person_id,
3909            iby_disburse_submit_pub_pkg.docspayTab.employee_address_id,
3910            iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag,
3911            iby_disburse_submit_pub_pkg.docspayTab.group_by_remittance_message,
3912            iby_disburse_submit_pub_pkg.docspayTab.group_by_bank_charge_bearer,
3913            iby_disburse_submit_pub_pkg.docspayTab.group_by_delivery_channel,
3914            iby_disburse_submit_pub_pkg.docspayTab.group_by_settle_priority_flag,
3915            iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_details_flag,
3916            iby_disburse_submit_pub_pkg.docspayTab.payment_details_length_limit,
3917            iby_disburse_submit_pub_pkg.docspayTab.payment_details_formula,
3918            iby_disburse_submit_pub_pkg.docspayTab.group_by_max_documents_flag,
3919            iby_disburse_submit_pub_pkg.docspayTab.max_documents_per_payment,
3920            iby_disburse_submit_pub_pkg.docspayTab.group_by_unique_remit_id_flag,
3921            iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_reason,
3922            iby_disburse_submit_pub_pkg.docspayTab.group_by_due_date_flag,
3923            iby_disburse_submit_pub_pkg.docspayTab.processing_type,
3924            iby_disburse_submit_pub_pkg.docspayTab.declaration_option,
3925            iby_disburse_submit_pub_pkg.docspayTab.dcl_only_foreign_curr_pmt_flag,
3926            iby_disburse_submit_pub_pkg.docspayTab.declaration_curr_fx_rate_type,
3927            iby_disburse_submit_pub_pkg.docspayTab.declaration_currency_code,
3928            iby_disburse_submit_pub_pkg.docspayTab.declaration_threshold_amount,
3929            iby_disburse_submit_pub_pkg.docspayTab.maximum_payment_amount,
3930            iby_disburse_submit_pub_pkg.docspayTab.minimum_payment_amount,
3931            iby_disburse_submit_pub_pkg.docspayTab.allow_zero_payments_flag,
3932            iby_disburse_submit_pub_pkg.docspayTab.support_bills_payable_flag,
3933            iby_disburse_submit_pub_pkg.docspayTab.iba_legal_entity_id,
3934            iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id,
3935            iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id,
3936            iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id,
3937            iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party,
3938            iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id,
3939 		   iby_disburse_submit_pub_pkg.docspayTab.affects_rejection_level  --AWT Enh 16296267
3940         LIMIT G_LINES_PER_FETCH;
3941 
3942      /*
3943       * Loop through all the fetched documents, grouping them
3944       * into payments.
3945       */
3946         FOR l_trx_line_index IN nvl(iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code.FIRST,0) .. nvl(iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code.LAST,-99)
3947         LOOP
3948            l_no_rec_in_ppr := FALSE;
3949 
3950            IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3951 	 print_debuginfo(l_module_name, 'Processed document payable id: '
3952             || to_char(iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index)));
3953            print_debuginfo(l_module_name, 'Assigning Defaults values dor dont_pay_flag,dont_pay_reason_code, dont_pay_description ');
3954            END IF;
3955          iby_disburse_submit_pub_pkg.docspayTab.dont_pay_flag(l_trx_line_index) := 'N';
3956          iby_disburse_submit_pub_pkg.docspayTab.dont_pay_reason_code(l_trx_line_index) := null;
3957          iby_disburse_submit_pub_pkg.docspayTab.dont_pay_description(l_trx_line_index) := null;
3958          iby_disburse_submit_pub_pkg.docspayTab.document_status(l_trx_line_index) := DOC_STATUS_PAY_CREATED;
3959 	 iby_disburse_submit_pub_pkg.docspayTab.created_by(l_trx_line_index)      := fnd_global.user_id;
3960          iby_disburse_submit_pub_pkg.docspayTab.creation_date(l_trx_line_index)   := sysdate;
3961          iby_disburse_submit_pub_pkg.docspayTab.last_updated_by(l_trx_line_index) := fnd_global.user_id;
3962          iby_disburse_submit_pub_pkg.docspayTab.last_update_date(l_trx_line_index)  := sysdate;
3963          iby_disburse_submit_pub_pkg.docspayTab.last_update_login(l_trx_line_index) := fnd_global.login_id;
3964          iby_disburse_submit_pub_pkg.docspayTab.object_version_number(l_trx_line_index) := 1;
3965 
3966 
3967          /* these two used in raising biz events */
3968          /* they will not vary within a request */
3969          l_ca_id                := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
3970          l_ca_payreq_cd         := iby_disburse_submit_pub_pkg.docspayTab.call_app_pay_service_req_code(l_trx_line_index);
3971          l_delv_chnl_flag       := iby_disburse_submit_pub_pkg.docspayTab.group_by_delivery_channel(l_trx_line_index);
3972          l_express_pmt_flag     := iby_disburse_submit_pub_pkg.docspayTab.group_by_settle_priority_flag(l_trx_line_index);
3973          l_bnk_chg_brer_flag    := iby_disburse_submit_pub_pkg.docspayTab.group_by_bank_charge_bearer(l_trx_line_index);
3974          l_sup_msg_flag         := iby_disburse_submit_pub_pkg.docspayTab.group_by_remittance_message(l_trx_line_index);
3975          l_pmt_details_flag     := iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_details_flag(l_trx_line_index);
3976          l_pmt_details_len      := iby_disburse_submit_pub_pkg.docspayTab.payment_details_length_limit(l_trx_line_index);
3977          l_pmt_det_formula      := iby_disburse_submit_pub_pkg.docspayTab.payment_details_formula(l_trx_line_index);
3978          l_processing_type      := iby_disburse_submit_pub_pkg.docspayTab.processing_type(l_trx_line_index);
3979 
3980          l_max_docs_flag        := iby_disburse_submit_pub_pkg.docspayTab.group_by_max_documents_flag(l_trx_line_index);
3981          l_max_docs_limit       := iby_disburse_submit_pub_pkg.docspayTab.max_documents_per_payment(l_trx_line_index);
3982          l_unique_remit_id_flag := iby_disburse_submit_pub_pkg.docspayTab.group_by_unique_remit_id_flag(l_trx_line_index);
3983          l_pmt_reason_flag      := iby_disburse_submit_pub_pkg.docspayTab.group_by_payment_reason(l_trx_line_index);
3984          l_due_date_flag        := iby_disburse_submit_pub_pkg.docspayTab.group_by_due_date_flag(l_trx_line_index);
3985          l_prom_note_flag       := iby_disburse_submit_pub_pkg.docspayTab.support_bills_payable_flag(l_trx_line_index);
3986 
3987          l_decl_option            := iby_disburse_submit_pub_pkg.docspayTab.declaration_option(l_trx_line_index);
3988          l_decl_only_fx_flag      := iby_disburse_submit_pub_pkg.docspayTab.dcl_only_foreign_curr_pmt_flag(l_trx_line_index);
3989          l_decl_curr_fx_rate_type := iby_disburse_submit_pub_pkg.docspayTab.declaration_curr_fx_rate_type(l_trx_line_index);
3990          l_decl_curr_code         := iby_disburse_submit_pub_pkg.docspayTab.declaration_currency_code(l_trx_line_index);
3991          l_decl_threshold_amount  := iby_disburse_submit_pub_pkg.docspayTab.declaration_threshold_amount(l_trx_line_index);
3992 
3993          l_commonAttributes.curr_pmt_due_date   := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
3994          l_commonAttributes.curr_delivery_channel   :=  iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
3995          l_commonAttributes.curr_uri   :=    iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
3996          l_commonAttributes.curr_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
3997 
3998          /*
3999           * Store the payment request imposed limits in the output
4000           * parameter. These will be used for validation on the
4001           * created payments.
4002           */
4003          x_payReqCriteria.max_pmt_amt_limit    :=
4004                                      iby_disburse_submit_pub_pkg.docspayTab.maximum_payment_amount(l_trx_line_index);
4005          x_payReqCriteria.min_pmt_amt_limit    :=
4006                                      iby_disburse_submit_pub_pkg.docspayTab.minimum_payment_amount(l_trx_line_index);
4007          x_payReqCriteria.allow_zero_pmts_flag :=
4008                                      iby_disburse_submit_pub_pkg.docspayTab.allow_zero_payments_flag(l_trx_line_index);
4009 
4010          /*
4011           * Store the central bank reporting related fields in
4012           * the CBR record.
4013          l_cbrRec.decl_option            := l_decl_option;
4014          l_cbrRec.decl_only_fx_flag      := l_decl_only_fx_flag;
4015          l_cbrRec.decl_curr_fx_rate_type := l_decl_curr_fx_rate_type;
4016          l_cbrRec.decl_curr_code         := l_decl_curr_code;
4017          l_cbrRec.decl_threshold_amount  := l_decl_threshold_amount;
4018           */
4019 
4020          /* these are payee related fields */
4021          l_bank_inst1_code := iby_disburse_submit_pub_pkg.docspayTab.bank_instruction1_code(l_trx_line_index);
4022          l_bank_inst2_code := iby_disburse_submit_pub_pkg.docspayTab.bank_instruction2_code(l_trx_line_index);
4023          l_pmt_txt_msg1    := iby_disburse_submit_pub_pkg.docspayTab.payment_text_message1(l_trx_line_index);
4024          l_pmt_txt_msg2    := iby_disburse_submit_pub_pkg.docspayTab.payment_text_message2(l_trx_line_index);
4025          l_pmt_txt_msg3    := iby_disburse_submit_pub_pkg.docspayTab.payment_text_message3(l_trx_line_index);
4026 
4027          /* these are passed onto the hook for adjustment by ext app */
4028          l_amount_withheld    := iby_disburse_submit_pub_pkg.docspayTab.amount_withheld(l_trx_line_index);
4029 
4030          /* used for maturity date calculation */
4031          l_discount_date    := iby_disburse_submit_pub_pkg.docspayTab.discount_date(l_trx_line_index);
4032 
4033          l_discount_amount  := iby_disburse_submit_pub_pkg.docspayTab.payment_curr_discount_taken(l_trx_line_index);
4034 
4035          /*
4036           * Log all the fetched document fields
4037           *
4038          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4039 	 print_debuginfo(l_module_name,
4040              'Fetched document data for document:' || curr_doc_id
4041              || ', calling app id: '        || curr_ca_id
4042              || ', calling app doc id1: '   || curr_ca_doc_id1
4043              || ', calling app doc id2: '   || curr_ca_doc_id2
4044              || ', calling app doc id3: '   || curr_ca_doc_id3
4045              || ', calling app doc id4: '   || curr_ca_doc_id4
4046              || ', calling app doc id5: '   || curr_ca_doc_id5
4047              || ', calling app trxn type: ' || curr_pp_tt_cd
4048              || ', payment grp number: '    || curr_pmt_grp_num
4049              || ', payment method: '        || curr_pmt_method_cd
4050              || ', internal bank account: ' || curr_int_bank_acct_id
4051              || ', external bank account: ' || curr_ext_bank_acct_id
4052              || ', profile: '               || curr_profile_id
4053              || ', payee: '                 || curr_payee_id
4054              || ', payee site: '            || curr_payee_site_id
4055              || ', supplier site: '         || curr_supplier_site_id
4056              || ', remit loc id: '          || curr_remit_loc_id
4057              || ', ext payee: '             || curr_ext_payee_id
4058              || ', org: '                   || curr_org_id
4059              || ', org type: '              || curr_org_type
4060              );
4061 
4062          print_debuginfo(l_module_name,
4063              'Fetched document data for document:' || curr_doc_id
4064              || ', payment currency: '      || curr_doc_pmt_currency
4065              || ', payment amount: '        || curr_doc_pmt_amount
4066              || ', pay alone flag: '        || iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index)
4067              || ', bank charge bearer: '    || curr_bnk_chg_bearer
4068              || ', delivery channel: '      || curr_delivery_channel
4069              || ', supplier message 1: '    || curr_supplier_msg1
4070              || ', supplier message 2: '    || curr_supplier_msg2
4071              || ', supplier message 3: '    || curr_supplier_msg3
4072              || ', uri: '                   || curr_uri
4073              || ', uri checkdigits: '       || curr_uri_checkdigits
4074              || ', pmt reason code: '       || curr_pmt_reason_code
4075              || ', pmt reason comments: '   || curr_pmt_reason_commts
4076              || ', pmt function: '          || curr_pmt_function
4077              || ', pmt date: '              || curr_pmt_date
4078              || ', pmt due date: '          || curr_pmt_due_date
4079              || ', benef party: '           || curr_benef_party
4080              );
4081 
4082          print_debuginfo(l_module_name,
4083              'Fetched document data for document:' || curr_doc_id
4084              || ', address source: '        || curr_address_source
4085              || ', emp addr code: '         || curr_emp_add_code
4086              || ', emp person id: '         || curr_emp_person_id
4087              || ', emp addr id: '           || curr_emp_addr_id
4088              || ', emp pmt flag: '          || curr_emp_pmt_flag
4089              );
4090 
4091          print_debuginfo(l_module_name,
4092              'Fetched flags for document:'  || curr_doc_id
4093              || ', pmt details flag: '      || l_pmt_details_flag
4094              || ', pmt details length: '    || l_pmt_details_len
4095              || ', pmt details formula: '   || l_pmt_det_formula
4096              || ', max docs flag: '         || l_max_docs_flag
4097              || ', max docs limit: '        || l_max_docs_limit
4098              || ', uri flag: '              || l_unique_remit_id_flag
4099              || ', pmt reason flag: '       || l_pmt_reason_flag
4100              || ', express pmt flag: '      || l_express_pmt_flag
4101              || ', delv channel flag: '     || l_delv_chnl_flag
4102              || ', pmt due date flag: '     || l_due_date_flag
4103              || ', prom note flag: '        || l_prom_note_flag
4104              );
4105 
4106           END IF;
4107           */
4108 
4109          IF (l_first_record = 'Y') THEN
4110             prev_doc_id            := iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index);
4111             prev_ca_id             := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
4112             prev_ca_doc_id1        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index);
4113             prev_ca_doc_id2        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index);
4114             prev_ca_doc_id3        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index);
4115             prev_ca_doc_id4        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index);
4116             prev_ca_doc_id5        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index);
4117             prev_pp_tt_cd          := iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index);
4118             prev_pmt_grp_num       := iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index);
4119             prev_pmt_method_cd     := iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index);
4120             prev_int_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
4121             prev_ext_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
4122             prev_profile_id        := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
4123             prev_org_id            := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
4124             prev_org_type          := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
4125             prev_payee_id          := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
4126             prev_payee_site_id     := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
4127             prev_remit_loc_id      := iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index);
4128             prev_ext_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
4129             prev_doc_pmt_currency  := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
4130             prev_doc_pmt_amount    := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index);
4131             prev_pay_alone_flag    := iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index);
4132             prev_bnk_chg_bearer    := iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index);
4133             prev_delivery_channel  := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
4134             prev_settle_priority   := iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index);
4135             prev_supplier_msg1     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index);
4136             prev_supplier_msg2     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index);
4137             prev_supplier_msg3     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index);
4138             prev_uri               := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
4139             prev_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
4140             prev_pmt_reason_code   := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index);
4141             prev_pmt_reason_commts := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index);
4142             prev_pmt_function      := iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index);
4143             prev_pmt_date          := iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index);
4144             prev_pmt_due_date      := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
4145             prev_benef_party       := iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index);
4146             prev_address_source    := iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index);
4147             prev_emp_add_code      := iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index);
4148             prev_emp_person_id     := iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index);
4149             prev_emp_addr_id       := iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index);
4150             prev_emp_pmt_flag      := iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index);
4151  prev_inv_payee_party_id      := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
4152  prev_inv_party_site_id      := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
4153  prev_inv_supplier_site_id      := iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id(l_trx_line_index);
4154  prev_inv_beneficiary_party      := iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party(l_trx_line_index);
4155  prev_ext_inv_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
4156 
4157            /* code to replace sweepCommonPmtAttributes() code */
4158 
4159            l_commonAttributes.prev_pmt_due_date   := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
4160            l_commonAttributes.prev_delivery_channel   :=  iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
4161            l_commonAttributes.prev_uri   :=    iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
4162            l_commonAttributes.prev_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
4163          END IF;
4164 
4165          /*
4166           * We have just fetched a new document for this payment request.
4167           * We will either insert this document into a new payment or
4168           * we will be inserting this document into the currently running
4169           * payment.
4170           *
4171           * In either case, we need to insert this doc into a payment.
4172           * So pre-populate the payment record with attributes of
4173           * this document. This is because the payment takes on the
4174           * attributes of it's constituent documents.
4175           *
4176           * Note: For user defined grouping rules, we will
4177           * have to populate the payment attribute only if
4178           * the user has turned on grouping by that attribute.
4179           */
4180 
4181          /* Only pre-fill hardcoded grouping rule attributes */
4182          l_paymentRec.payment_profile_id       := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
4183          l_paymentRec.payment_service_request_id
4184                                                := p_payment_request_id;
4185          l_paymentRec.internal_bank_account_id := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
4186          l_paymentRec.ext_payee_id             := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
4187          l_paymentRec.payee_party_id           := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
4188          l_paymentRec.party_site_id            := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
4189          l_paymentRec.supplier_site_id         := iby_disburse_submit_pub_pkg.docspayTab.supplier_site_id(l_trx_line_index);
4190 
4191 	     l_paymentRec.ext_inv_payee_id             := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
4192          l_paymentRec.inv_payee_party_id           := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
4193          l_paymentRec.inv_party_site_id            := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
4194          l_paymentRec.inv_supplier_site_id         := iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id(l_trx_line_index);
4195          l_paymentRec.inv_beneficiary_party         := iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party(l_trx_line_index);
4196 
4197          l_paymentRec.remit_to_location_id     := iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index);
4198          l_paymentRec.payment_currency_code    := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
4199          l_paymentRec.org_id                   := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
4200          l_paymentRec.org_type                 := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
4201          l_paymentRec.payment_method_code      := iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index);
4202          l_paymentRec.payment_function         := iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index);
4203          l_paymentRec.payment_date             := iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index);
4204          l_paymentRec.beneficiary_party        := iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index);
4205          l_paymentRec.address_source           := iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index);
4206          l_paymentRec.employee_address_code    := iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index);
4207          l_paymentRec.employee_person_id       := iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index);
4208          l_paymentRec.employee_address_id      := iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index);
4209          l_paymentRec.employee_payment_flag    := iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index);
4210          l_paymentRec.legal_entity_id          := iby_disburse_submit_pub_pkg.docspayTab.iba_legal_entity_id(l_trx_line_index);
4211          l_paymentRec.affects_rejection_level := iby_disburse_submit_pub_pkg.docspayTab.affects_rejection_level(l_trx_line_index); -- AWT Enh 16296267
4212 
4213 
4214 		 /*
4215           * Fix for bug 5524116:
4216           *
4217           * Group by external bank account needs to be made a
4218           * hardcoded grouping rule regardless of processing type.
4219           *
4220           * This is because is some obscure formats e.g., Italy Wire
4221           * payments, the payment is actually sent to the bank as
4222           * a printed payment letter even though the payment method
4223           * is wire.
4224           */
4225          l_paymentRec.external_bank_account_id := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
4226 
4227          /*
4228           * Fix for bug 5334177:
4229           *
4230           * Setting the bills payable flag on the payment is not
4231           * related to user-defined grouping rules.
4232           *
4233           * Set this flag here along with other hardcoded
4234           * grouping rules.
4235           */
4236 
4237          /*
4238           * Set the promissory note flag for this payment
4239           * if the payment method of this payment supports
4240           * promissory notes.
4241           *
4242           * The promissory note flag indicates that this
4243           * payment is (possibly) a future dated payment.
4244           */
4245          IF (l_prom_note_flag = 'Y') THEN
4246 
4247              l_paymentRec.bill_payable_flag := 'Y';
4248 
4249          ELSE
4250 
4251              /*
4252               * Fix for bug 5442899
4253               *
4254               * Explicitly set bill payable flag to 'N'
4255               * in case payment method does not
4256               * support bills payable.
4257               */
4258              l_paymentRec.bill_payable_flag := 'N';
4259 
4260          END IF;
4261 
4262          /*
4263           * If a document has the payment grouping number attribute
4264           * set, then it is a part of a pre-grouped payment (document
4265           * grouped into payment at the calling app itself).
4266           *
4267           * Grouping by payment grouping number is a hardcoded grouping
4268           * rule below. Therefore, it is guaranteed that a payment will
4269           * only contain documents with the same payment grouping number.
4270           *
4271           * For, such payments set the 'pregrouped payment flag' to 'Y'.
4272           */
4273          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NOT NULL) THEN
4274 
4275              l_paymentRec.pregrouped_payment_flag := 'Y';
4276 
4277          ELSE
4278 
4279              /*
4280               * Fix for bug 5529924:
4281               *
4282               * Explicitly set the pregrouped payment flag to 'N'
4283               * in case the grouping number on the document
4284               * is null.
4285               */
4286              l_paymentRec.pregrouped_payment_flag := 'N';
4287 
4288          END IF;
4289 
4290          /* payee related fields */
4291          /* grouping by payee context is a hardcoded grouping rule */
4292          l_paymentRec.bank_instruction1_code   := l_bank_inst1_code;
4293          l_paymentRec.bank_instruction2_code   := l_bank_inst2_code;
4294          l_paymentRec.payment_text_message1    := l_pmt_txt_msg1;
4295          l_paymentRec.payment_text_message2    := l_pmt_txt_msg2;
4296          l_paymentRec.payment_text_message3    := l_pmt_txt_msg3;
4297 
4298          /*
4299           * Pre-fill grouping rule attributes for user defined
4300           * grouping rules (that are enabled by the user).
4301           *
4302           * It is necessary to pre-fill user defined grouping
4303           * attributes before the grouping rules are triggered
4304           * because we don't know which user defined grouping rules
4305           * are going to get triggered first, and once a rule is
4306           * triggered all rules below it are skipped. So it is too
4307           * late to populate grouping attributes within the grouping
4308           * rule itself.
4309           */
4310 
4311          /*
4312           * We pre-fill the user-defined attributes only when the
4313           * 'payment grouping number' attribute is null. This is
4314           * because the user-defined grouping rules are never triggered
4315           * if the 'payment grouping number' attribute is not null.
4316           */
4317 
4318 		 -- Bug 14837472
4319          --IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
4320 
4321              /*-----------------------------------------------------
4322              IF (l_payee_add_eft_flag = 'Y') THEN
4323                  IF (l_processing_type = 'ELECTRONIC') THEN
4324 
4325                      --
4326                      -- RAMESH:
4327                      -- Temporarily commented out. Current data model
4328                      -- does not support grouping by payee party id and payee
4329                      -- party site as separate grouping rules because of
4330                      -- calling app constraints.
4331                      --
4332                      -- At the moment, the grouping is at the level of
4333                      -- payee context which includes (payee party id, payee
4334                      -- party site id, supplier site id, org id, org type)
4335                      -- etc.
4336                      --
4337                      -- In the future when more fine grained grouping
4338                      -- can be supported, uncomment this code.
4339                      --
4340 
4341                      --l_paymentRec.payee_party_site_id := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
4342                      --l_paymentRec.payee_id := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
4343 
4344                  END IF;
4345              END IF;
4346              -----------------------------------------------------*/
4347 
4348             IF (l_bnk_chg_brer_flag = 'Y') THEN
4349                  l_paymentRec.bank_charge_bearer := iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index);
4350 		      else  --Bug 14836472
4351                  l_paymentRec.bank_charge_bearer := null;
4352            END IF;
4353 
4354              IF (l_delv_chnl_flag = 'Y') THEN
4355                  l_paymentRec.delivery_channel_code := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
4356              ELSE  --Bug 14836472
4357                  l_paymentrec.delivery_channel_code := null;
4358              END IF;
4359 
4360              IF (l_express_pmt_flag = 'Y') THEN
4361                  l_paymentRec.settlement_priority := iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index);
4362 		       else  --Bug 14836472
4363 		           l_paymentRec.settlement_priority := NULL;
4364              end if;
4365 
4366              IF (l_sup_msg_flag = 'Y') THEN
4367 
4368                  /*
4369                   * Fix for bug 5534537:
4370                   *
4371                   * Assign correct remittance messages to the
4372                   * payment.
4373                   */
4374                  l_paymentRec.remittance_message1 := iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index);
4375                  l_paymentRec.remittance_message2 := iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index);
4376                  l_paymentRec.remittance_message3 := iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index);
4377             ELSE --Bug 14836472
4378                     l_paymentRec.remittance_message1 := null;
4379 			        l_paymentRec.remittance_message2 := null;
4380 					l_paymentRec.remittance_message3 := null;
4381           end if;
4382 
4383              IF (l_unique_remit_id_flag = 'Y') THEN
4384                  l_paymentRec.unique_remittance_identifier := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
4385                  l_paymentRec.uri_check_digit := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
4386              ELSE --Bug 14836472
4387 				 l_paymentRec.unique_remittance_identifier := NULL;
4388                  l_paymentRec.uri_check_digit := NULL;
4389              end if;
4390 
4391              IF (l_due_date_flag = 'Y') THEN
4392                  l_paymentrec.payment_due_date := iby_disburse_submit_pub_pkg.docspaytab.payment_due_date(l_trx_line_index);
4393 			       ELSE --Bug 14836472
4394 			            l_paymentRec.payment_due_date := NULL;
4395             END IF;
4396 
4397              IF (l_pmt_reason_flag = 'Y') THEN
4398                  l_paymentRec.payment_reason_code     := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index);
4399                  l_paymentRec.payment_reason_comments := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index);
4400 			       ELSE --Bug 14836472
4401   				         l_paymentRec.payment_reason_code     := NULL;
4402                    l_paymentrec.payment_reason_comments := null;
4403              END IF;
4404 
4405          --END IF; -- if payment_grouping_number(l_trx_line_index) IS NULL --Bug 14836472
4406 
4407           IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4408          print_debuginfo(l_module_name, 'Value of inv_payee_party_id in ibydocsoaytab'
4409                  || 'is '
4410                  || iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index)
4411                  );
4412 
4413          print_debuginfo(l_module_name, 'Value of inv_payee_party_id in record group'
4414                  || 'is '
4415                  || l_paymentRec.inv_payee_party_id
4416                  );
4417 				 END IF;
4418 
4419          /*
4420           * Pre-fill the document record with the details
4421           * of the current document.
4422           */
4423          l_docsInPmtRec.document_id         := iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index);
4424          l_docsInPmtRec.document_amount     := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index);
4425          l_docsInPmtRec.document_currency   := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
4426          l_docsInPmtRec.payment_grp_num     := iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index);
4427          l_docsInPmtRec.calling_app_id      := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
4428          l_docsInPmtRec.calling_app_doc_id1 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index);
4429          l_docsInPmtRec.calling_app_doc_id2 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index);
4430          l_docsInPmtRec.calling_app_doc_id3 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index);
4431          l_docsInPmtRec.calling_app_doc_id4 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index);
4432          l_docsInPmtRec.calling_app_doc_id5 := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index);
4433          l_docsInPmtRec.pay_proc_ttype_cd   := iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index);
4434 
4435          /* these to are passed onto the hook for adjustment by ext app */
4436          l_docsInPmtRec.amount_withheld     := l_amount_withheld;
4437 
4438          /* used for maturity date calculation */
4439          l_docsInPmtRec.discount_date       := l_discount_date;
4440          l_docsInPmtRec.pmt_due_date        := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
4441 
4442          /* used in common attribute sweep */
4443          l_docsInPmtRec.delivery_channel    := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
4444          l_docsInPmtRec.unique_remit_id     := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
4445          l_docsInPmtRec.uri_ckdigits        := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
4446 
4447          l_docsInPmtRec.int_bank_acct_id    := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
4448          l_docsInPmtRec.ext_payee_id        := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
4449          l_docsInPmtRec.payee_id            := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
4450          l_docsInPmtRec.payee_site_id       := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
4451          l_docsInPmtRec.supplier_site_id    := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
4452 
4453          l_docsInPmtRec.ext_inv_payee_id        := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
4454          l_docsInPmtRec.inv_payee_party_id            := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
4455          l_docsInPmtRec.inv_party_site_id       := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
4456          l_docsInPmtRec.inv_supplier_site_id    := iby_disburse_submit_pub_pkg.docspayTab.inv_supplier_site_id(l_trx_line_index);
4457 
4458 	     l_docsInPmtRec.org_id              := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
4459          l_docsInPmtRec.org_type            := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
4460          l_docsInPmtRec.ext_bank_acct_id    := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
4461          l_docsInPmtRec.pmt_curr_discount   := l_discount_amount;
4462 
4463          /*
4464           * Calculate payment details from the document based on
4465           * the user defined formula. This will be used in a
4466           * user-defined grouping rule below.
4467           */
4468          IF (l_pmt_details_flag = 'Y') THEN
4469              l_calc_doc_detail := getDocDetails(iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index),
4470                                       l_pmt_det_formula);
4471 
4472              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4473 		 print_debuginfo(l_module_name, 'Calculated doc detail for '
4474                  || 'doc id '
4475                  || curr_doc_id
4476                  || ': '
4477                  || l_calc_doc_detail
4478                  );
4479 
4480 	     END IF;
4481 
4482          ELSE
4483              l_calc_doc_detail := null;
4484          END IF;
4485 
4486          /*
4487           * The length of the payment details field in IBY_PAYMENTS_ALL
4488           * table is 240 chars. This imposes a hard limit for the
4489           * length of payment details that can be stored against a
4490           * payment.
4491           *
4492           * If the user has specified a field length (for payment
4493           * details) greater than the column width, reset the field
4494           * length to the column limit.
4495           */
4496          IF (l_pmt_details_flag = 'Y') THEN
4497              IF (l_pmt_details_len > 240) THEN
4498 
4499                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4500 		 print_debuginfo(l_module_name, 'User specified payment '
4501                      || 'details field length = '
4502                      || l_pmt_details_len
4503                      || '. This is greater than the max column length '
4504                      || '(currently 240 chars). Payment details will be '
4505                      || 'filled to the maximum column length.'
4506                      );
4507 		 END IF;
4508                  l_pmt_details_len := 240;
4509 
4510              /*
4511               * If user has not specified any value at all,
4512               * default the payment details field length.
4513               */
4514              ELSIF (l_pmt_details_len = -1) THEN
4515 
4516                  /*
4517                   * Fix for bug 5362662:
4518                   *
4519                   * If user has not specified a length for the payment
4520                   * details field, but has turned on grouping by
4521                   * payment details, then limit the payment details
4522                   * field to the max allowed column length.
4523                   */
4524                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4525 		 print_debuginfo(l_module_name, 'User specified payment '
4526                      || 'details field length is null. '
4527                      || 'Payment details will be filled to the maximum '
4528                      || 'column length (currently 240 chars).'
4529                      );
4530                  END IF;
4531 
4532                  l_pmt_details_len := 240;
4533 
4534              END IF;
4535          END IF;
4536 
4537          /*-- HARDCODED GROUPING RULES START HERE --*/
4538 
4539          /*
4540           * Grouping Step 1: Pay Alone Flag (these are exclusive
4541           * payments where one document is paid by one payment).
4542           */
4543           IF (UPPER(iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index)) = 'Y') THEN
4544 
4545              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4546 		 print_debuginfo(l_module_name, 'Grouping by pay alone flag '
4547                  || 'triggered for document '
4548                  || curr_doc_id);
4549              END IF;
4550 
4551              insertDocIntoPayment(l_paymentRec,-- x_paymentTab,
4552                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4553 
4554              GOTO label_finish_iteration;
4555 
4556          END IF;
4557 
4558          /*
4559           * Grouping Step 2: Organization ID And Organization Type
4560           */
4561          IF (prev_org_id <> iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index))     OR
4562             (NVL(prev_org_type, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index), 0)) THEN
4563 
4564              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4565 	 print_debuginfo(l_module_name, 'Grouping by organization '
4566                  || 'id/type triggered for document '
4567                  || curr_doc_id);
4568 
4569      END IF;
4570 
4571              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4572                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4573 
4574              GOTO label_finish_iteration;
4575 
4576          END IF;
4577 
4578 	 /*
4579           * Grouping Step 2.5: Group By Inv Payee Context (external inv payee id)
4580           */
4581          IF (prev_ext_inv_payee_id <> iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index)) THEN
4582 
4583              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4584 	 print_debuginfo(l_module_name, 'Grouping by payee context '
4585                  || 'triggered for document '
4586                  || curr_doc_id);
4587 
4588      END IF;
4589 
4590              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4591                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4592 
4593              GOTO label_finish_iteration;
4594 
4595          END IF;
4596 
4597          /*
4598           * Grouping Step 3: Group By Payee Context (external payee id)
4599           */
4600          IF (prev_ext_payee_id <> iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index)) THEN
4601 
4602              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4603 	 print_debuginfo(l_module_name, 'Grouping by payee context '
4604                  || 'triggered for document '
4605                  || curr_doc_id);
4606 
4607      END IF;
4608 
4609              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4610                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4611 
4612              GOTO label_finish_iteration;
4613 
4614          END IF;
4615 
4616          /*
4617           * Grouping Step 4: Payment Currency
4618           */
4619          IF (prev_doc_pmt_currency <> iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index)) THEN
4620 
4621              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4622 	 print_debuginfo(l_module_name, 'Grouping by payment '
4623                  || 'currency triggered for document '
4624                  || curr_doc_id);
4625 
4626      END IF;
4627 
4628              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4629                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4630 
4631              GOTO label_finish_iteration;
4632 
4633          END IF;
4634 
4635          /*
4636           * Grouping Step 5: Payment Method
4637           */
4638          IF (prev_pmt_method_cd <> iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index)) THEN
4639 
4640              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4641 		 print_debuginfo(l_module_name, 'Grouping by payment '
4642                  || 'method triggered for document '
4643                  || curr_doc_id);
4644 
4645      END IF;
4646 
4647              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4648                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4649 
4650              GOTO label_finish_iteration;
4651 
4652          END IF;
4653 
4654          /*
4655           * Grouping Step 6: Payment Profile ID
4656           */
4657          IF (prev_profile_id <> iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index)) THEN
4658 
4659              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4660 	 print_debuginfo(l_module_name, 'Grouping by payment '
4661                  || 'profile triggered for document '
4662                  || curr_doc_id);
4663 
4664      END IF;
4665 
4666              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4667                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4668 
4669              GOTO label_finish_iteration;
4670 
4671          END IF;
4672 
4673          /*
4674           * NOTE:
4675           * Grouping by payment grouping number is a special type
4676           * of hardcoded grouping rule. All documents payable that
4677           * have the same payment grouping number must always be
4678           * grouped into the same payment.
4679           *
4680           * In order to achive this, two things have to happen:
4681           * a. None of the hardcoded grouping rules should
4682           *    be triggered when a document payable has a non-null
4683           *    value for payment grouping number.
4684           *
4685           * b. None of the user defined grouping rules must be applied
4686           *    for a document payable with a non-null value for
4687           *    payment grouping number.
4688           *
4689           * It is guaranteed by the calling application that all
4690           * documents that have a non-null value for the payment
4691           * grouping number will have the same values for all the
4692           * hardcoded grouping attributes. This will satisfy (a).
4693           *
4694           * The grouping logic below will not apply any user-defined
4695           * grouping rules if a document payable has a non-null value
4696           * for the payment grouping number. This will satisfy (b).
4697           */
4698 
4699          /*
4700           * Grouping Step 7: Payment Grouping Number
4701           */
4702          IF (NVL(prev_pmt_grp_num, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index), 0)) THEN
4703 
4704              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4705 	 print_debuginfo(l_module_name, 'Grouping by payment '
4706                  || 'grouping number triggered for document '
4707                  || curr_doc_id);
4708 
4709      END IF;
4710 
4711              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4712                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4713 
4714              GOTO label_finish_iteration;
4715 
4716          END IF;
4717 
4718          /*
4719           * Grouping Step 8: Internal Bank Account ID
4720           */
4721          IF (prev_int_bank_acct_id <> iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index)) THEN
4722 
4723              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4724 		 print_debuginfo(l_module_name, 'Grouping by internal bank '
4725                  || 'account triggered for document '
4726                  || curr_doc_id);
4727 
4728      END IF;
4729 
4730              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4731                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4732 
4733              GOTO label_finish_iteration;
4734 
4735          END IF;
4736 
4737          /*
4738           * Grouping Step 9: External Bank Account ID
4739           *
4740           * Fix for bug 5524116:
4741           *
4742           * Grouping by ext bank account now made a hardcoded
4743           * grouping rule regardless of processing type.
4744           */
4745          IF (NVL(prev_ext_bank_acct_id, 0) <>
4746              NVL(iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index), 0)) THEN
4747 
4748              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4749 	 print_debuginfo(l_module_name, 'Grouping by external '
4750                  || 'bank account triggered for document '
4751                  || curr_doc_id);
4752 
4753      END IF;
4754              l_paymentRec.external_bank_account_id := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
4755 
4756              insertDocIntoPayment(l_paymentRec,
4757 	        --x_paymentTab,
4758                  l_calc_doc_detail,
4759 		 true,
4760 		 l_payment_id,
4761 		 l_docs_in_pmt_count,
4762 		 l_commonAttributes,
4763 		 l_trx_line_index);
4764 
4765              GOTO label_finish_iteration;
4766 
4767          END IF;
4768 
4769          /*
4770           * Grouping Step 10: Group By Payee Address (check only)
4771           *
4772           * One payee site can only have one address. Therefore, it is
4773           * sufficient to group by payee sites in order to group by
4774           * payee addresses.
4775           */
4776 
4777          /*-----------------------------------------------------
4778          IF (l_processing_type = 'PRINTED') THEN
4779              IF (prev_payee_site_id <> iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index)) THEN
4780 
4781                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4782 	 print_debuginfo(l_module_name, 'Grouping by payee '
4783                      || 'address (check) triggered for document '
4784                      || curr_doc_id);
4785 		 END IF;
4786                  --
4787                  -- RAMESH:
4788                  -- Temporarily commented out. Current data model
4789                  -- does not support grouping by payee party id and payee
4790                  -- party site as separate grouping rules because of
4791                  -- calling app constraints.
4792                  --
4793                  -- At the moment, the grouping is at the level of
4794                  -- payee context which includes (payee party id, payee
4795                  -- party site id, supplier site id, org id, org type)
4796                  -- etc.
4797                  --
4798                  -- In the future when more fine grained grouping
4799                  -- can be supported, uncomment this code.
4800                  --
4801 
4802                  --l_paymentRec.payee_party_site_id := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
4803 
4804                  insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4805                      l_calc_doc_detail, true, l_payment_id,
4806                      x_docsInPmtTab, l_docsInPmtRec,
4807                       l_docs_in_pmt_count,l_commonAttributes);
4808 
4809                  GOTO label_finish_iteration;
4810              END IF;
4811          END IF;
4812          -----------------------------------------------------*/
4813 
4814          /*
4815           * Grouping Step 11: Payment Function
4816           */
4817          IF (prev_pmt_function <> iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index)) THEN
4818 
4819              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4820 		 print_debuginfo(l_module_name, 'Grouping by payment '
4821                  || 'function triggered for document '
4822                  || curr_doc_id);
4823 
4824      END IF;
4825 
4826              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4827                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4828 
4829              GOTO label_finish_iteration;
4830 
4831          END IF;
4832 
4833          /*
4834           * Grouping Step 12: Payment Date
4835           */
4836          IF (prev_pmt_date <> iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index)) THEN
4837 
4838              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4839 		 print_debuginfo(l_module_name, 'Grouping by payment '
4840                  || 'date triggered for document '
4841                  || curr_doc_id);
4842 
4843      END IF;
4844 
4845              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4846                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4847 
4848              GOTO label_finish_iteration;
4849 
4850          END IF;
4851 
4852          /*
4853           * Grouping Step 13: Remit To Location Id
4854           */
4855          IF (NVL(prev_remit_loc_id, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index), '0')) THEN
4856 
4857              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4858 	 print_debuginfo(l_module_name, 'Grouping by remit to '
4859                  || 'location id triggered for document '
4860                  || curr_doc_id);
4861 
4862      END IF;
4863 
4864              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4865                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4866 
4867              GOTO label_finish_iteration;
4868 
4869          END IF;
4870 
4871          /*
4872           * Grouping Step 14: Beneficiary Party
4873           */
4874          IF (NVL(prev_benef_party, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index), '0')) THEN
4875 
4876              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4877 	 print_debuginfo(l_module_name, 'Grouping by beneficiary '
4878                  || 'party triggered for document '
4879                  || curr_doc_id);
4880 
4881      END IF;
4882 
4883              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4884                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4885 
4886              GOTO label_finish_iteration;
4887 
4888          END IF;
4889 
4890          /*
4891           * Grouping Step 15: Group By Space Left On Stub (check only)
4892           *
4893           * This will be handled in the payment creation flow (F8) because
4894           * the check related details are picked up in that flow.
4895           */
4896 
4897          /*
4898           * Grouping Step 16: Payee Address (Employee Address)
4899           *
4900           * TECHNICALLY REQUIRED, FUNCTIONALLY NOT REQUIRED -
4901           * Grouping by payee address is really not necessary because
4902           * we do grouping by payee context (which implicitly groups
4903           * by payee address as well assuming a 1:1 relationship between
4904           * a payee and his address).
4905           *
4906           * The reason we have this grouping rule here is to populate
4907           * these columns on the payment. These columns are used by
4908           * the extract / format.
4909           */
4910          IF (NVL(prev_address_source, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index), '0') OR
4911              NVL(prev_emp_add_code,   '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index),   '0') OR
4912              NVL(prev_emp_person_id,  '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index),  '0') OR
4913              NVL(prev_emp_addr_id,    '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index),    '0'))
4914              THEN
4915 
4916              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4917 	 print_debuginfo(l_module_name, 'Grouping by payee (employee) '
4918                  || 'address triggered for document '
4919                  || curr_doc_id);
4920 
4921      END IF;
4922 
4923              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4924                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4925 
4926              GOTO label_finish_iteration;
4927 
4928          END IF;
4929 
4930          /*
4931           * Grouping Step 17: Employee Payment Flag
4932           *
4933           * TECHINICALLY REQUIRED, FUNCTIONALLY NOT REQUIRED -
4934           * The reason we have this grouping rule here is to populate
4935           * the employee payment flag on the payment.
4936           */
4937          IF (NVL(prev_emp_pmt_flag, '0') <> NVL(iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index), '0'))
4938              THEN
4939 
4940              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4941 		 print_debuginfo(l_module_name, 'Grouping by employee '
4942                  || 'payment flag triggered for document '
4943                  || curr_doc_id);
4944 
4945      END IF;
4946 
4947              insertDocIntoPayment(l_paymentRec, --x_paymentTab,
4948                  l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
4949 
4950              GOTO label_finish_iteration;
4951 
4952          END IF;
4953 
4954          /*-- USER DEFINED GROUPING RULES START HERE --*/
4955 
4956          /*
4957           * NOTE:
4958           * None of the user defined grouping rules should be
4959           * applied to a document if it has a payment grouping
4960           * number attribute set.
4961           *
4962           * This is because all documents with the same payment
4963           * grouping number must always be grouped into the
4964           * same payment.
4965           */
4966 
4967          /*
4968           * Grouping Step 18: Payee Address (electronic)
4969           *
4970           * These are payments where the payment between
4971           * Oracle Payments and the bank is done electronically,
4972           * but the delivery channel from the bank to the
4973           * payee is by check.
4974           */
4975 
4976          /*-----------------------------------------
4977          IF (l_payee_add_eft_flag = 'Y') THEN
4978              IF (l_processing_type = 'ELECTRONIC') THEN
4979 
4980                  IF (NVL(prev_payee_site_id, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index), 0))
4981                      THEN
4982 
4983                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4984 			 print_debuginfo(l_module_name, 'Grouping by payee '
4985                          || 'address (electronic) triggered for document '
4986                          || curr_doc_id);
4987 
4988      END IF;
4989 
4990                      --
4991                      -- RAMESH:
4992                      -- Temporarily commented out. Current data model
4993                      -- does not support grouping by payee party id and payee
4994                      -- party site as separate grouping rules because of
4995                      -- calling app constraints.
4996                      --
4997                      -- At the moment, the grouping is at the level of
4998                      -- payee context which includes (payee party id, payee
4999                      -- party site id, supplier site id, org id, org type)
5000                      -- etc.
5001                      --
5002                      -- In the future when more fine grained grouping
5003                      -- can be supported, uncomment this code.
5004                      --
5005 
5006                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5007                          l_calc_doc_detail, true, l_payment_id,
5008                          x_docsInPmtTab, l_docsInPmtRec,
5009                           l_docs_in_pmt_count,l_commonAttributes);
5010 
5011                      GOTO label_finish_iteration;
5012                  END IF;
5013              END IF;
5014          END IF;
5015          -------------------------------------------*/
5016 
5017          /*
5018           * Grouping Step 19: Bank Charge Bearer
5019           */
5020          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5021 
5022              IF (l_bnk_chg_brer_flag = 'Y') THEN
5023 
5024                  IF (NVL(prev_bnk_chg_bearer, 0) <>
5025                      NVL(iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index), 0)) THEN
5026 
5027                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5028 			 print_debuginfo(l_module_name, 'Grouping by bank '
5029                          || 'charge bearer triggered for document '
5030                          || curr_doc_id);
5031 
5032      END IF;
5033 
5034                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5035                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5036 
5037                      GOTO label_finish_iteration;
5038 
5039                  END IF;
5040 
5041              END IF;
5042 
5043          END IF;
5044 
5045          /*
5046           * Grouping Step 20: Delivery Channel
5047           */
5048          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5049 
5050              IF (l_delv_chnl_flag = 'Y') THEN
5051 
5052                  IF (NVL(prev_delivery_channel, 0) <>
5053                      NVL(iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index), 0)) THEN
5054 
5055                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5056 		 print_debuginfo(l_module_name, 'Grouping by '
5057                          || 'delivery channel triggered for document '
5058                          || curr_doc_id);
5059 
5060      END IF;
5061 
5062                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5063                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5064 
5065                      GOTO label_finish_iteration;
5066 
5067                  END IF;
5068 
5069              END IF;
5070 
5071          END IF;
5072 
5073          /*
5074           * Grouping Step 21: Express Payment
5075           */
5076          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5077 
5078              IF (l_express_pmt_flag = 'Y') THEN
5079 
5080                  IF (NVL(prev_settle_priority, 0) <>
5081                      NVL(iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index), 0)) THEN
5082 
5083                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5084 			 print_debuginfo(l_module_name, 'Grouping by '
5085                          || 'express payment triggered for document '
5086                          || curr_doc_id);
5087 
5088      END IF;
5089 
5090                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5091                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5092 
5093                      GOTO label_finish_iteration;
5094 
5095                  END IF;
5096 
5097              END IF;
5098 
5099          END IF;
5100 
5101          /*
5102           * Grouping Step 22: Supplier Message
5103           */
5104          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5105 
5106              IF (l_sup_msg_flag = 'Y') THEN
5107 
5108                  IF (NVL(prev_supplier_msg1, 0) <>
5109                          NVL(iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index), 0) OR
5110                      NVL(prev_supplier_msg2, 0) <>
5111                          NVL(iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index), 0) OR
5112                      NVL(prev_supplier_msg3, 0) <>
5113                          NVL(iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index), 0)) THEN
5114 
5115                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5116 			 print_debuginfo(l_module_name, 'Grouping by '
5117                          || 'supplier message triggered for document '
5118                          || curr_doc_id);
5119 
5120      END IF;
5121 
5122                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5123                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5124 
5125                      GOTO label_finish_iteration;
5126 
5127                  END IF;
5128 
5129              END IF;
5130 
5131          END IF;
5132 
5133          /*
5134           * Grouping Step 23: Unique Remittance Identifier
5135           *
5136           * Note: It is sufficient to check if the unique remittance
5137           * identifiers (uri's) are different between two documents.
5138           * No need to check if the uri checkdigits are different.
5139           * Grouping is on the basis of uri's only.
5140           */
5141          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5142 
5143              IF (l_unique_remit_id_flag = 'Y') THEN
5144 
5145                  IF (NVL(prev_uri, 0) <> NVL(iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index), 0) OR
5146                      NVL(prev_uri_checkdigits, 0) <>
5147                          NVL(iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index), 0)) THEN
5148 
5149                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5150 		 print_debuginfo(l_module_name, 'Grouping by '
5151                          || 'unique remit id triggered for document '
5152                          || curr_doc_id);
5153 
5154      END IF;
5155 
5156                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5157                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5158 
5159                      GOTO label_finish_iteration;
5160 
5161                  END IF;
5162 
5163              END IF;
5164 
5165          END IF;
5166 
5167          /*
5168           * Grouping Step 24: Payment Reason Code / Payment Reason Comments
5169           */
5170          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5171 
5172              IF (l_pmt_reason_flag = 'Y') THEN
5173 
5174                  IF (NVL(prev_pmt_reason_code, 0)   <>
5175                          NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index), 0)  OR
5176                      NVL(prev_pmt_reason_commts, 0) <>
5177                          NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index), 0)) THEN
5178 
5179                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5180 		 print_debuginfo(l_module_name, 'Grouping by '
5181                          || 'payment reason code / comments triggered '
5182                          || 'for document '
5183                          || curr_doc_id);
5184 
5185      END IF;
5186 
5187                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5188                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5189 
5190                      GOTO label_finish_iteration;
5191 
5192                  END IF;
5193 
5194              END IF;
5195 
5196          END IF;
5197 
5198          /*
5199           * Grouping Step 25: Payment Due Date
5200           */
5201          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5202 
5203              IF (l_due_date_flag = 'Y') THEN
5204 
5205                  IF (NVL(prev_pmt_due_date, l_impossible_date) <>
5206                      NVL(iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index), l_impossible_date)) THEN
5207 
5208                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5209 		 print_debuginfo(l_module_name, 'Grouping by '
5210                          || 'payment due date triggered for document '
5211                          || curr_doc_id);
5212 
5213      END IF;
5214 
5215                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5216                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5217 
5218                      GOTO label_finish_iteration;
5219 
5220                  END IF;
5221 
5222              END IF;
5223 
5224          END IF;
5225 
5226          /*
5227           * Grouping Step 26: Max Documents Per Payment
5228           */
5229          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5230 
5231              IF (l_max_docs_flag = 'Y') THEN
5232 
5233                  IF (l_docs_in_pmt_count = l_max_docs_limit) THEN
5234 
5235                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5236 			 print_debuginfo(l_module_name, 'Grouping by '
5237                          || 'max docs per payment triggered for document '
5238                          || curr_doc_id);
5239 
5240      END IF;
5241 
5242                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5243                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5244 
5245                      GOTO label_finish_iteration;
5246 
5247                  END IF;
5248 
5249              END IF;
5250 
5251          END IF;
5252 
5253          /*
5254           * Grouping Step 27: Break Payments According To Payment Details
5255           *                   Field Length
5256           */
5257          IF (iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index) IS NULL) THEN
5258 
5259              if l_trx_pmt_index >0
5260              then
5261                l_length := length(IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index) || l_calc_doc_detail );
5262              else
5263                l_length :=LENGTH(l_calc_doc_detail);
5264              end if;
5265 	     --bug 13254730
5266 
5267              IF (l_pmt_details_flag = 'Y') THEN
5268 
5269                  IF (l_length > l_pmt_details_len) THEN
5270 		-- Bug 13254730 IF (LENGTH(l_paymentRec.payment_details || l_calc_doc_detail) > l_pmt_details_len) THEN
5271                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5272 			 print_debuginfo(l_module_name, 'Grouping by '
5273                          || 'payment details length triggered for document '
5274                          || curr_doc_id);
5275 
5276 		      END IF;
5277 
5278                      insertDocIntoPayment(l_paymentRec, --x_paymentTab,
5279                          l_calc_doc_detail, true, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5280 
5281                      GOTO label_finish_iteration;
5282 
5283                  END IF;
5284 
5285              END IF;
5286 
5287          END IF;
5288 
5289          /*
5290           * End Of Grouping:
5291           * If a document reaches here, it means that this document
5292           * is similar to the previous document as far a grouping
5293           * criteria is concerned.
5294           *
5295           * Add this document to the currently running payment.
5296           */
5297          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN  --vid- start here
5298 	  print_debuginfo(l_module_name, 'No grouping rules '
5299              || 'were triggered for document '
5300              || curr_doc_id);
5301 
5302 
5303          END IF;
5304 
5305          insertDocIntoPayment(l_paymentRec,-- x_paymentTab,
5306              l_calc_doc_detail, false, l_payment_id, l_docs_in_pmt_count, l_commonAttributes, l_trx_line_index);
5307 
5308          <<label_finish_iteration>>
5309 
5310          /*
5311           * CBR Handling:
5312           *
5313           * For each payment, store the central bank reporting
5314           * related fields along with the payment id in the
5315           * CBR table.
5316           *
5317           * This table will be passed as an output param to
5318           * the routine that sets the 'declare payment flag'
5319           * on the payment based on the CBR fields.
5320           *
5321           * We just created a payment. If this payment
5322           * does not already exist in the CBR list, add
5323           * it to the list.
5324           */
5325           l_profile_id := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
5326 /*  Bug 5709596 */
5327           IF NOT(iby_disburse_submit_pub_pkg.paymentProfilesTab.exists(l_profile_id)) THEN
5328              iby_disburse_submit_pub_pkg.set_profile_attribs(l_profile_id);
5329           END IF;
5330 
5331          /*
5332           * Lastly, before going into the next iteration
5333           * of the loop copy all the current grouping criteria
5334           * into 'prev' fields so that we can compare these
5335           * fields with the next record.
5336           *
5337           * No need to copy the current values into the previous ones for
5338           * the first record because we have already done it at the beginning.
5339           *
5340           *
5341           * Fix for bug 5463733:
5342           *
5343           * Reset the prev pmt grouping number here, else
5344           * the next document may incorrectly be grouped
5345           * into another payment.
5346           */
5347 
5348          IF (l_first_record <> 'Y') THEN
5349             prev_doc_id            := iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index);
5350             prev_ca_id             := iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index);
5351             prev_ca_doc_id1        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index);
5352             prev_ca_doc_id2        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index);
5353             prev_ca_doc_id3        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index);
5354             prev_ca_doc_id4        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index);
5355             prev_ca_doc_id5        := iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index);
5356             prev_pp_tt_cd          := iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index);
5357             prev_pmt_grp_num       := iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index);
5358             prev_pmt_method_cd     := iby_disburse_submit_pub_pkg.docspayTab.payment_method_code(l_trx_line_index);
5359             prev_int_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index);
5360             prev_ext_bank_acct_id  := iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index);
5361             prev_profile_id        := iby_disburse_submit_pub_pkg.docspayTab.payment_profile_id(l_trx_line_index);
5362             prev_org_id            := iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index);
5363             prev_org_type          := iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index);
5364             prev_payee_id          := iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index);
5365             prev_payee_site_id     := iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index);
5366             prev_remit_loc_id      := iby_disburse_submit_pub_pkg.docspayTab.remit_to_location_id(l_trx_line_index);
5367             prev_ext_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index);
5368             prev_doc_pmt_currency  := iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index);
5369             prev_doc_pmt_amount    := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index);
5370             prev_pay_alone_flag    := iby_disburse_submit_pub_pkg.docspayTab.exclusive_payment_flag(l_trx_line_index);
5371             prev_bnk_chg_bearer    := iby_disburse_submit_pub_pkg.docspayTab.bank_charge_bearer(l_trx_line_index);
5372             prev_delivery_channel  := iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index);
5373             prev_settle_priority   := iby_disburse_submit_pub_pkg.docspayTab.settlement_priority(l_trx_line_index);
5374             prev_supplier_msg1     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message1(l_trx_line_index);
5375             prev_supplier_msg2     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message2(l_trx_line_index);
5376             prev_supplier_msg3     := iby_disburse_submit_pub_pkg.docspayTab.remittance_message3(l_trx_line_index);
5377             prev_uri               := iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index);
5378             prev_uri_checkdigits   := iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index);
5379             prev_pmt_reason_code   := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_code(l_trx_line_index);
5380             prev_pmt_reason_commts := iby_disburse_submit_pub_pkg.docspayTab.payment_reason_comments(l_trx_line_index);
5381             prev_pmt_function      := iby_disburse_submit_pub_pkg.docspayTab.payment_function(l_trx_line_index);
5382             prev_pmt_date          := iby_disburse_submit_pub_pkg.docspayTab.payment_date(l_trx_line_index);
5383             prev_pmt_due_date      := iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index);
5384             prev_benef_party       := iby_disburse_submit_pub_pkg.docspayTab.beneficiary_party(l_trx_line_index);
5385             prev_address_source    := iby_disburse_submit_pub_pkg.docspayTab.address_source(l_trx_line_index);
5386             prev_emp_add_code      := iby_disburse_submit_pub_pkg.docspayTab.employee_address_code(l_trx_line_index);
5387             prev_emp_person_id     := iby_disburse_submit_pub_pkg.docspayTab.employee_person_id(l_trx_line_index);
5388             prev_emp_addr_id       := iby_disburse_submit_pub_pkg.docspayTab.employee_address_id(l_trx_line_index);
5389             prev_emp_pmt_flag      := iby_disburse_submit_pub_pkg.docspayTab.employee_payment_flag(l_trx_line_index);
5390 
5391             prev_inv_payee_party_id          := iby_disburse_submit_pub_pkg.docspayTab.inv_payee_party_id(l_trx_line_index);
5392             prev_inv_party_site_id     := iby_disburse_submit_pub_pkg.docspayTab.inv_party_site_id(l_trx_line_index);
5393             prev_inv_beneficiary_party      := iby_disburse_submit_pub_pkg.docspayTab.inv_beneficiary_party(l_trx_line_index);
5394             prev_ext_inv_payee_id      := iby_disburse_submit_pub_pkg.docspayTab.ext_inv_payee_id(l_trx_line_index);
5395 
5396          END IF;
5397 
5398          /*
5399           *  Remember to reset the first record flag before going
5400           *  into the next iteration.
5401           */
5402          IF (l_first_record = 'Y') THEN
5403              l_first_record := 'N';
5404          END IF;
5405 
5406          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5407 	print_debuginfo(l_module_name, '+----------------------------------+');
5408          END IF;
5409 
5410         END LOOP; -- for documents cursor
5411         FORALL l_trx_line_index IN nvl(iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code.FIRST,0) .. nvl(iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code.LAST,-99)
5412          INSERT INTO iby_docs_in_pmt_gt
5413              (
5414              pay_proc_trxn_type_code,
5415              calling_app_id,
5416              document_payable_id,
5417              document_status,
5418              document_currency_code,
5419              document_amount,
5420              ext_payee_id,
5421              payee_party_id,
5422              org_id,
5423              created_by,
5424              creation_date,
5425              last_updated_by,
5426              last_update_date,
5427              object_version_number,
5428              calling_app_doc_unique_ref1,
5429              calling_app_doc_unique_ref2,
5430              calling_app_doc_unique_ref3,
5431              calling_app_doc_unique_ref4,
5432              calling_app_doc_unique_ref5,
5433              last_update_login,
5434              party_site_id,
5435              supplier_site_id,
5436              org_type,
5437              amount_withheld,
5438              payment_curr_discount_taken,
5439              discount_date,
5440              payment_due_date,
5441              payment_id,
5442              internal_bank_account_id,
5443              external_bank_account_id,
5444              payment_grouping_number,
5445              unique_remittance_identifier,
5446              uri_check_digit,
5447              delivery_channel_code,
5448              dont_pay_flag,
5449              dont_pay_reason_code,
5450              dont_pay_description
5451              )
5452          VALUES
5453              (
5454              iby_disburse_submit_pub_pkg.docspayTab.pay_proc_trxn_type_code(l_trx_line_index),
5455              iby_disburse_submit_pub_pkg.docspayTab.calling_app_id(l_trx_line_index),
5456              iby_disburse_submit_pub_pkg.docspayTab.document_payable_id(l_trx_line_index),
5457              iby_disburse_submit_pub_pkg.docspayTab.document_status(l_trx_line_index),
5458              iby_disburse_submit_pub_pkg.docspayTab.payment_currency_code(l_trx_line_index),
5459              iby_disburse_submit_pub_pkg.docspayTab.payment_amount(l_trx_line_index),
5460              iby_disburse_submit_pub_pkg.docspayTab.ext_payee_id(l_trx_line_index),
5461              iby_disburse_submit_pub_pkg.docspayTab.payee_party_id(l_trx_line_index),
5462              iby_disburse_submit_pub_pkg.docspayTab.org_id(l_trx_line_index),
5463              iby_disburse_submit_pub_pkg.docspayTab.created_by(l_trx_line_index),
5464              iby_disburse_submit_pub_pkg.docspayTab.creation_date(l_trx_line_index),
5465              iby_disburse_submit_pub_pkg.docspayTab.last_updated_by(l_trx_line_index),
5466              iby_disburse_submit_pub_pkg.docspayTab.last_update_date(l_trx_line_index),
5467              iby_disburse_submit_pub_pkg.docspayTab.object_version_number(l_trx_line_index),
5468              iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref1(l_trx_line_index),
5469              iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref2(l_trx_line_index),
5470              iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref3(l_trx_line_index),
5471              iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref4(l_trx_line_index),
5472              iby_disburse_submit_pub_pkg.docspayTab.calling_app_doc_unique_ref5(l_trx_line_index),
5473              iby_disburse_submit_pub_pkg.docspayTab.last_update_login(l_trx_line_index),
5474              iby_disburse_submit_pub_pkg.docspayTab.party_site_id(l_trx_line_index),
5475              iby_disburse_submit_pub_pkg.docspayTab.supplier_site_id(l_trx_line_index),
5476              iby_disburse_submit_pub_pkg.docspayTab.org_type(l_trx_line_index),
5477              iby_disburse_submit_pub_pkg.docspayTab.amount_withheld(l_trx_line_index),
5478              iby_disburse_submit_pub_pkg.docspayTab.payment_curr_discount_taken(l_trx_line_index),
5479              iby_disburse_submit_pub_pkg.docspayTab.discount_date(l_trx_line_index),
5480              iby_disburse_submit_pub_pkg.docspayTab.payment_due_date(l_trx_line_index),
5481              iby_disburse_submit_pub_pkg.docspayTab.payment_id(l_trx_line_index),
5482              iby_disburse_submit_pub_pkg.docspayTab.internal_bank_account_id(l_trx_line_index),
5483              iby_disburse_submit_pub_pkg.docspayTab.external_bank_account_id(l_trx_line_index),
5484              iby_disburse_submit_pub_pkg.docspayTab.payment_grouping_number(l_trx_line_index),
5485              iby_disburse_submit_pub_pkg.docspayTab.unique_remittance_identifier(l_trx_line_index),
5486              iby_disburse_submit_pub_pkg.docspayTab.uri_check_digit(l_trx_line_index),
5487              iby_disburse_submit_pub_pkg.docspayTab.delivery_channel_code(l_trx_line_index),
5488              iby_disburse_submit_pub_pkg.docspayTab.dont_pay_flag(l_trx_line_index),
5489              iby_disburse_submit_pub_pkg.docspayTab.dont_pay_reason_code(l_trx_line_index),
5490              iby_disburse_submit_pub_pkg.docspayTab.dont_pay_description(l_trx_line_index)
5491              );
5492 
5493         EXIT WHEN c_documents%NOTFOUND;
5494 
5495      END LOOP; -- for documents cursor
5496 
5497      iby_disburse_submit_pub_pkg.delete_docspayTab;
5498 
5499      CLOSE c_documents;
5500 	  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5501      print_debuginfo(l_module_name, 'Finished processing of all pmts');
5502 	 END IF;
5503      /*
5504       * Exit if no documents were found.
5505       */
5506      IF (l_no_rec_in_ppr) THEN
5507          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5508 	 print_debuginfo(l_module_name, 'No documents payable were '
5509              || 'retrieved from DB for payment request '
5510              || p_payment_request_id
5511              || '. Exiting document grouping ..');
5512 
5513 
5514 	 print_debuginfo(l_module_name, 'EXIT');
5515 
5516          END IF;
5517          RETURN;
5518      END IF;
5519 
5520 
5521      /*
5522       * Populate legal entity ids for each of the created payments.
5523       *
5524       * The legal entity id on the payment is a special attribute.
5525       * It is not a grouping rule, instead it has to be derived
5526       * from the internal bank account and populated.
5527       */
5528 
5529      /*
5530       * Finally, return the payments created by grouping to the caller.
5531       */
5532      x_ca_id        := l_ca_id;
5533      x_ca_payreq_cd := l_ca_payreq_cd;
5534 
5535      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5536  print_debuginfo(l_module_name, 'Created '
5537          || IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT   || ' payment(s) from '
5538          || ' document(s) for payment request '
5539          || p_payment_request_id || '.');
5540 	 print_debuginfo(l_module_name, 'EXIT');
5541      END IF;
5542   EXCEPTION
5543   WHEN OTHERS THEN
5544    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
5545                  FND_LOG.LEVEL_UNEXPECTED);
5546              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
5547                  FND_LOG.LEVEL_UNEXPECTED);
5548    print_debuginfo(l_module_name, l_module_name||':Exception when Performing'
5549          || 'Document Grpuping.');
5550    RAISE;
5551  END performDocumentGrouping;
5552 
5553 
5554 /*--------------------------------------------------------------------
5555  | NAME:
5556  |     insertDocIntoPayment
5557  |
5558  | PURPOSE:
5559  |     Inserts a given document into a currently running payment
5560  |     or into a new payment as per given flag.
5561  |
5562  |     This method is called by every grouping rule to add
5563  |     a given document into a current payment/new payment.
5564  |
5565  | PARAMETERS:
5566  |     IN
5567  |
5568  |
5569  |     OUT
5570  |
5571  |
5572  | RETURNS:
5573  |
5574  | NOTES:
5575  |
5576  *---------------------------------------------------------------------*/
5577  PROCEDURE insertDocIntoPayment(
5578      x_paymentRec            IN OUT NOCOPY IBY_PAYMENTS_ALL%ROWTYPE,
5579      x_paymentTab            IN OUT NOCOPY paymentTabType,
5580      p_calcDocInfo           IN            VARCHAR2,
5581      p_newPaymentFlag        IN            BOOLEAN,
5582      x_currentPaymentId      IN OUT NOCOPY IBY_PAYMENTS_ALL.payment_id%TYPE,
5583      x_docsInPmtTab          IN OUT NOCOPY docsInPaymentTabType,
5584      x_docsInPmtRec          IN OUT NOCOPY docsInPaymentRecType,
5585      x_docsInPmtCount        IN OUT NOCOPY NUMBER
5586      )
5587  IS
5588  l_module_name    CONSTANT VARCHAR2(200) := G_PKG_NAME ||
5589                                                 '.insertDocIntoPayment';
5590 
5591  BEGIN
5592 
5593 
5594      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5595 	print_debuginfo(l_module_name, 'ENTER');
5596      END IF;
5597 
5598      /*
5599       * GROUPING LOGIC IS IN IF-ELSE BLOCK BELOW:
5600       *
5601       * Irrespective of whether this document is part of
5602       * an existing payment or whether it should be part
5603       * of a new payment, ensure that the PLSQL payments
5604       * table is updated with the details of this document
5605       * within this if-else block.
5606       *
5607       * We need to do this each time we enter this procedure
5608       * because this might well be the last document in
5609       * in the payment request, and this procedure may
5610       * not be called again for this payment request. So
5611       * the PLSQL payments table should always be up-to-date
5612       * when it exits this procedure.
5613       */
5614      IF (p_newPaymentFlag = true) THEN
5615 
5616          /*
5617           * This is a new payment; Get an id for this payment
5618           */
5619          getNextPaymentID(x_currentPaymentID);
5620 
5621          /*
5622           * Create a new payment record using the incoming
5623           * document as a constituent, and insert this record
5624           * into the PLSQL payments table.
5625           */
5626          x_paymentRec.payment_id              :=  x_currentPaymentId;
5627 
5628          x_docsInPmtCount                     := 1;
5629 
5630          x_paymentRec.payment_amount          := x_docsInPmtRec.document_amount;
5631 
5632          x_paymentRec.discount_amount_taken   := x_docsInPmtRec.
5633                                                      pmt_curr_discount;
5634 
5635          x_paymentRec.payment_details         := p_calcDocInfo;
5636 
5637          x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
5638 
5639          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5640 	print_debuginfo(l_module_name,' Inserted document : '
5641              || x_docsInPmtRec.document_id || ' into new payment: '
5642              || x_currentPaymentId);
5643 
5644          END IF;
5645          /*
5646           * Assign the payment id of the new payment to this
5647           * doc, and insert the doc into the docs array.
5648           */
5649          x_docsInPmtRec.payment_id            := x_paymentRec.payment_id;
5650          x_docsInPmtTab(x_docsInPmtTab.COUNT + 1) := x_docsInPmtRec;
5651 
5652      ELSE
5653 
5654          /*
5655           * This means we need to add the incoming document to
5656           * the current  payment.
5657           */
5658 
5659          /*
5660           * First check special case: Payments PLSQL table is empty
5661           *
5662           * If the PLSQL table for payments is empty, we have to
5663           * initialize it by inserting a dummy record. This dummy
5664           * record will get overwritten below.
5665           */
5666          IF (x_paymentTab.COUNT = 0) THEN
5667 
5668              getNextPaymentID(x_currentPaymentID);
5669 
5670              x_paymentRec.payment_id              := x_currentPaymentId;
5671 
5672              x_docsInPmtCount                     := 0;
5673 
5674              x_paymentRec.payment_amount          := 0;
5675              x_paymentRec.discount_amount_taken   :=  0;
5676              x_paymentRec.payment_details         := '';
5677 
5678              /*
5679               * Insert the first record into the table. This
5680               * is a dummy record.
5681               */
5682              x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
5683 
5684              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5685 		print_debuginfo(l_module_name, 'Created a new payment: '
5686                  || x_currentPaymentId);
5687 	     END IF;
5688 
5689          END IF;
5690 
5691          /*
5692           * The incoming document should be part of the current payment.
5693           * So add the document amount to the current payment
5694           * record and increment the document count for the current
5695           * payment record.
5696           */
5697          x_paymentRec.payment_id     :=  x_currentPaymentId;
5698 
5699          x_docsInPmtCount            := x_docsInPmtCount + 1;
5700 
5701          x_paymentRec.payment_amount :=
5702              x_paymentRec.payment_amount + x_docsInPmtRec.document_amount;
5703 
5704          x_paymentRec.discount_amount_taken   :=
5705              x_paymentRec.discount_amount_taken
5706                  + x_docsInPmtRec.pmt_curr_discount;
5707 
5708          /*
5709           * The payment details information is passed in by the caller.
5710           * If this value is null, it means that the caller does not
5711           * wish to use the grouping rule 'break payments according to
5712           * space available under payment details'. In such a case, do not
5713           * append the payment details from each document into the payment.
5714           */
5715          IF (p_calcDocInfo IS NOT NULL) THEN
5716 
5717              x_paymentRec.payment_details :=
5718                  x_paymentRec.payment_details || p_calcDocInfo;
5719 
5720          END IF;
5721 
5722          /*
5723           * Overwrite the current payment record in the
5724           * PLSQL payments table with the updated record.
5725           */
5726          x_paymentTab(x_paymentTab.COUNT) := x_paymentRec;
5727 
5728          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5729 		print_debuginfo(l_module_name, 'Inserted document : '
5730              || x_docsInPmtRec.document_id || ' into existing payment: '
5731              || x_currentPaymentId);
5732 
5733          END IF;
5734          /*
5735           * Assign the payment id of the current payment to this
5736           * doc, and insert the doc into the docs array.
5737           */
5738          x_docsInPmtRec.payment_id        := x_paymentRec.payment_id;
5739          x_docsInPmtTab(x_docsInPmtTab.COUNT + 1) := x_docsInPmtRec;
5740 
5741      END IF;
5742 
5743      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5744 	print_debuginfo(l_module_name, 'EXIT');
5745       END IF;
5746 
5747  END insertDocIntoPayment;
5748 
5749 
5750 
5751 
5752 
5753 
5754 
5755 /*--------------------------------------------------------------------
5756  | NAME:
5757  |     insertDocIntoPayment
5758  |
5759  | PURPOSE:
5760  |     Inserts a given document into a currently running payment
5761  |     or into a new payment as per given flag.
5762  |
5763  |     This method is called by every grouping rule to add
5764  |     a given document into a current payment/new payment.
5765  |
5766  | PARAMETERS:
5767  |     IN
5768  |
5769  |
5770  |     OUT
5771  |
5772  |
5773  | RETURNS:
5774  |
5775  | NOTES:
5776  |
5777  *---------------------------------------------------------------------*/
5778  PROCEDURE insertDocIntoPayment(
5779      x_paymentRec            IN OUT NOCOPY IBY_PAYMENTS_ALL%ROWTYPE,
5780      x_paymentTab            IN OUT NOCOPY paymentTabType,
5781      p_calcDocInfo           IN            VARCHAR2,
5782      p_newPaymentFlag        IN            BOOLEAN,
5783      x_currentPaymentId      IN OUT NOCOPY IBY_PAYMENTS_ALL.payment_id%TYPE,
5784      x_docsInPmtTab          IN OUT NOCOPY docsInPaymentTabType,
5785      x_docsInPmtRec          IN OUT NOCOPY docsInPaymentRecType,
5786      x_docsInPmtCount        IN OUT NOCOPY NUMBER,
5787      x_commonAttributes      IN OUT NOCOPY commonAttributesTabType
5788      )
5789  IS
5790  l_module_name    CONSTANT VARCHAR2(200) := G_PKG_NAME ||
5791                                                 '.insertDocIntoPayment';
5792   l_impossible_date       DATE := TO_DATE('01/01/5100 10:25:55',
5793                                      'MM/DD/YYYY HH24:MI:SS');
5794 
5795  BEGIN
5796 
5797      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5798  print_debuginfo(l_module_name, 'ENTER');
5799       END IF;
5800 
5801      /*
5802       * GROUPING LOGIC IS IN IF-ELSE BLOCK BELOW:
5803       *
5804       * Irrespective of whether this document is part of
5805       * an existing payment or whether it should be part
5806       * of a new payment, ensure that the PLSQL payments
5807       * table is updated with the details of this document
5808       * within this if-else block.
5809       *
5810       * We need to do this each time we enter this procedure
5811       * because this might well be the last document in
5812       * in the payment request, and this procedure may
5813       * not be called again for this payment request. So
5814       * the PLSQL payments table should always be up-to-date
5815       * when it exits this procedure.
5816       */
5817      IF (p_newPaymentFlag = true) THEN
5818 
5819          /*
5820           * This is a new payment; Get an id for this payment
5821           */
5822          getNextPaymentID(x_currentPaymentID);
5823 
5824          /* Assume that this NEW payment has 3 attributes common across all documents */
5825 
5826          x_commonAttributes.due_date_common_flag  := 'Y';
5827          x_commonAttributes.delv_chnl_common_flag := 'Y';
5828          x_commonAttributes.uri_common_flag       := 'Y';
5829 
5830          x_paymentRec.payment_due_date      :=  x_commonAttributes.curr_pmt_due_date;
5831          x_paymentRec.delivery_channel_code   := x_commonAttributes.curr_delivery_channel    ;
5832          x_paymentRec.unique_remittance_identifier := x_commonAttributes.curr_uri;
5833          x_paymentRec.uri_check_digit  := x_commonAttributes.curr_uri_checkdigits;
5834          /*
5835           * Create a new payment record using the incoming
5836           * document as a constituent, and insert this record
5837           * into the PLSQL payments table.
5838           */
5839          x_paymentRec.payment_id              :=  x_currentPaymentId;
5840 
5841          x_docsInPmtCount                     := 1;
5842 
5843          x_paymentRec.payment_amount          := x_docsInPmtRec.document_amount;
5844 
5845          x_paymentRec.discount_amount_taken   := x_docsInPmtRec.
5846                                                      pmt_curr_discount;
5847 
5848          x_paymentRec.payment_details         := p_calcDocInfo;
5849 
5850         /* Move record assignment down after initializing payments */
5851 
5852         -- x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
5853 
5854          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5855 	 print_debuginfo(l_module_name,' Inserted document : '
5856              || x_docsInPmtRec.document_id || ' into new payment: '
5857              || x_currentPaymentId);
5858          END IF;
5859 
5860          /*
5861           * Assign the payment id of the new payment to this
5862           * doc, and insert the doc into the docs array.
5863           */
5864          x_docsInPmtRec.payment_id            := x_paymentRec.payment_id;
5865          x_docsInPmtTab(x_docsInPmtTab.COUNT + 1) := x_docsInPmtRec;
5866 
5867 
5868 	 /* moving the initalizePmts logic to this block, to avoid unnecessary looping through payments */
5869 
5870          x_paymentRec.payment_status                 := 'CREATED';
5871          x_paymentRec.process_type                   := 'STANDARD';
5872 
5873          /*
5874           * Fix for bug 5115270:
5875           *
5876           * For all flags, take care not to overwite the flag
5877           * already set.
5878           */
5879          x_paymentRec.payments_complete_flag         :=
5880              NVL(x_paymentRec.payments_complete_flag,         'N');
5881          x_paymentRec.bill_payable_flag              :=
5882              NVL(x_paymentRec.bill_payable_flag,              'N');
5883          x_paymentRec.exclusive_payment_flag         :=
5884              NVL(x_paymentRec.exclusive_payment_flag,         'N');
5885          x_paymentRec.separate_remit_advice_req_flag :=
5886              NVL(x_paymentRec.separate_remit_advice_req_flag, 'N');
5887          x_paymentRec.declare_payment_flag           :=
5888              NVL(x_paymentRec.declare_payment_flag,           'N');
5889          x_paymentRec.pregrouped_payment_flag        :=
5890              NVL(x_paymentRec.pregrouped_payment_flag,        'N');
5891          x_paymentRec.stop_confirmed_flag            :=
5892              NVL(x_paymentRec.stop_confirmed_flag,            'N');
5893          x_paymentRec.stop_released_flag             :=
5894              NVL(x_paymentRec.stop_released_flag,             'N');
5895          x_paymentRec.stop_request_placed_flag       :=
5896              NVL(x_paymentRec.stop_request_placed_flag,       'N');
5897 
5898          x_paymentRec.created_by                     := fnd_global.user_id;
5899          x_paymentRec.creation_date                  := sysdate;
5900          x_paymentRec.last_updated_by                := fnd_global.user_id;
5901          x_paymentRec.last_update_login              := fnd_global.user_id;
5902          x_paymentRec.last_update_date               := sysdate;
5903          x_paymentRec.object_version_number          := 1;
5904 
5905    /* moving the paymentrecord to x_paymentTab after initializing the values */
5906 
5907          x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
5908 
5909 
5910 
5911 
5912      ELSE
5913 
5914          /*
5915           * This means we need to add the incoming document to
5916           * the current  payment.
5917           */
5918 
5919          /*
5920           * First check special case: Payments PLSQL table is empty
5921           *
5922           * If the PLSQL table for payments is empty, we have to
5923           * initialize it by inserting a dummy record. This dummy
5924           * record will get overwritten below.
5925           */
5926          IF (x_paymentTab.COUNT = 0) THEN
5927 
5928              getNextPaymentID(x_currentPaymentID);
5929 
5930 
5931 
5932 
5933              x_paymentRec.payment_id              := x_currentPaymentId;
5934 
5935              x_docsInPmtCount                     := 0;
5936 
5937              x_paymentRec.payment_amount          := 0;
5938              x_paymentRec.discount_amount_taken   :=  0;
5939              x_paymentRec.payment_details         := '';
5940 
5941              /*
5942               * Insert the first record into the table. This
5943               * is a dummy record.
5944               */
5945              x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
5946 
5947              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
5948 		print_debuginfo(l_module_name, 'Created a new payment: '
5949                  || x_currentPaymentId);
5950              END IF;
5951 
5952          END IF;
5953 
5954 
5955 
5956          /*
5957           * The incoming document should be part of the current payment.
5958           * So add the document amount to the current payment
5959           * record and increment the document count for the current
5960           * payment record.
5961           */
5962 
5963 
5964          If (x_commonAttributes.due_date_common_flag = 'Y') THEN
5965 
5966             If (NVL(x_commonAttributes.prev_pmt_due_date,l_impossible_date) <> NVL(x_commonAttributes.curr_pmt_due_date, l_impossible_date))  THEN
5967 
5968                     x_commonAttributes.due_date_common_flag  := 'N';
5969                     x_paymentRec.payment_due_date            :=  '';
5970 
5971             ELSE
5972                     x_paymentRec.payment_due_date        := x_commonAttributes.curr_pmt_due_date;
5973             END IF;
5974 
5975          END IF;
5976 
5977          If (x_commonAttributes.delv_chnl_common_flag = 'Y') THEN
5978             If (NVL(x_commonAttributes.prev_delivery_channel,0) <> NVL(x_commonAttributes.curr_delivery_channel, 0))  THEN
5979 
5980                          x_commonAttributes.delv_chnl_common_flag := 'N';
5981                          x_paymentRec.delivery_channel_code   := '';
5982 
5983             ELSE
5984                         x_paymentRec.delivery_channel_code   := x_commonAttributes.curr_delivery_channel;
5985             END IF;
5986          END IF;
5987 
5988          If (x_commonAttributes.uri_common_flag = 'Y') THEN
5989 
5990              IF (NVL(x_commonAttributes.prev_uri, 0) <> NVL(x_commonAttributes.prev_uri, 0) OR
5991                      NVL(x_commonAttributes.prev_uri_checkdigits, 0) <>
5992                          NVL(x_commonAttributes.curr_uri_checkdigits, 0)) THEN
5993 
5994                         x_commonAttributes.uri_common_flag       := 'N';
5995                  x_paymentRec.unique_remittance_identifier := '';
5996              ELSE
5997 
5998                  x_paymentRec.unique_remittance_identifier := x_commonAttributes.curr_uri;
5999                  x_paymentRec.uri_check_digit              := x_commonAttributes.curr_uri_checkdigits;
6000             END IF;
6001          END IF;
6002 
6003 
6004          x_paymentRec.payment_id     :=  x_currentPaymentId;
6005 
6006          x_docsInPmtCount            := x_docsInPmtCount + 1;
6007 
6008          x_paymentRec.payment_amount :=
6009              x_paymentRec.payment_amount + x_docsInPmtRec.document_amount;
6010 
6011          x_paymentRec.discount_amount_taken   :=
6012              x_paymentRec.discount_amount_taken
6013                  + x_docsInPmtRec.pmt_curr_discount;
6014 
6015          /*
6016           * The payment details information is passed in by the caller.
6017           * If this value is null, it means that the caller does not
6018           * wish to use the grouping rule 'break payments according to
6019           * space available under payment details'. In such a case, do not
6020           * append the payment details from each document into the payment.
6021           */
6022          IF (p_calcDocInfo IS NOT NULL) THEN
6023 
6024              x_paymentRec.payment_details :=
6025                  x_paymentRec.payment_details || p_calcDocInfo;
6026 
6027          END IF;
6028 
6029          /*
6030           * Overwrite the current payment record in the
6031           * PLSQL payments table with the updated record.
6032           */
6033          x_paymentTab(x_paymentTab.COUNT) := x_paymentRec;
6034 
6035          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6036 	 print_debuginfo(l_module_name, 'Inserted document : '
6037              || x_docsInPmtRec.document_id || ' into existing payment: '
6038              || x_currentPaymentId);
6039          END IF;
6040 
6041          /*
6042           * Assign the payment id of the current payment to this
6043           * doc, and insert the doc into the docs array.
6044           */
6045          x_docsInPmtRec.payment_id        := x_paymentRec.payment_id;
6046          x_docsInPmtTab(x_docsInPmtTab.COUNT + 1) := x_docsInPmtRec;
6047 
6048      END IF;
6049 
6050      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6051 	print_debuginfo(l_module_name, 'EXIT');
6052       END IF;
6053 
6054  END insertDocIntoPayment;
6055 
6056 /*--------------------------------------------------------------------
6057  | NAME:
6058  |     insertDocIntoPayment
6059  |
6060  | PURPOSE:
6061  |     Inserts a given document into a currently running payment
6062  |     or into a new payment as per given flag.
6063  |
6064  |     This method is called by every grouping rule to add
6065  |     a given document into a current payment/new payment.
6066  |
6067  | PARAMETERS:
6068  |     IN
6069  |
6070  |
6071  |     OUT
6072  |
6073  |
6074  | RETURNS:
6075  |
6076  | NOTES:
6077  |
6078  *---------------------------------------------------------------------*/
6079  PROCEDURE insertDocIntoPayment(
6080      x_paymentRec            IN OUT NOCOPY IBY_PAYMENTS_ALL%ROWTYPE,
6081      --x_paymentTab            IN OUT NOCOPY paymentTabType,
6082      p_calcDocInfo           IN            VARCHAR2,
6083      p_newPaymentFlag        IN            BOOLEAN,
6084      x_currentPaymentId      IN OUT NOCOPY IBY_PAYMENTS_ALL.payment_id%TYPE,
6085      x_docsInPmtCount        IN OUT NOCOPY NUMBER,
6086      x_commonAttributes      IN OUT NOCOPY commonAttributesTabType,
6087      p_trx_line_index        IN            BINARY_INTEGER
6088      )
6089  IS
6090   l_module_name    CONSTANT VARCHAR2(200) := G_PKG_NAME ||
6091                                                 '.insertDocIntoPayment';
6092   l_impossible_date       DATE := TO_DATE('01/01/5100 10:25:55',
6093                                      'MM/DD/YYYY HH24:MI:SS');
6094   l_antcptd_val_date DATE;
6095 
6096  BEGIN
6097 
6098      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6099  print_debuginfo(l_module_name, 'ENTER: overloaded method with p_trx_line_index ');
6100       END IF;
6101 
6102      /*
6103       * GROUPING LOGIC IS IN IF-ELSE BLOCK BELOW:
6104       *
6105       * Irrespective of whether this document is part of
6106       * an existing payment or whether it should be part
6107       * of a new payment, ensure that the PLSQL payments
6108       * table is updated with the details of this document
6109       * within this if-else block.
6110       *
6111       * We need to do this each time we enter this procedure
6112       * because this might well be the last document in
6113       * in the payment request, and this procedure may
6114       * not be called again for this payment request. So
6115       * the PLSQL payments table should always be up-to-date
6116       * when it exits this procedure.
6117       */
6118 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6119        print_debuginfo(l_module_name, 'Before checking the new pmt flag');
6120 	   END IF;
6121      IF (p_newPaymentFlag = true) THEN
6122 
6123          /*
6124           * This is a new payment; Get an id for this payment
6125           */
6126          getNextPaymentID(x_currentPaymentID);
6127 
6128          /* Assume that this NEW payment has 3 attributes common across all documents */
6129 
6130 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6131 	 print_debuginfo(l_module_name, 'Before initializing x_CommonAttr ');
6132 	 END IF;
6133 
6134          x_commonAttributes.due_date_common_flag  := 'Y';
6135          x_commonAttributes.delv_chnl_common_flag := 'Y';
6136          x_commonAttributes.uri_common_flag       := 'Y';
6137    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6138 	 print_debuginfo(l_module_name, 'B4 incrementing l_trx_pmt_index - '||l_trx_pmt_index);
6139 	 print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT - '||IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT);
6140  	 --print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index) - '|| IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index));
6141    END IF;
6142 	 l_trx_pmt_index := l_trx_pmt_index + 1 ;
6143 
6144    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6145 	 print_debuginfo(l_module_name, 'After incrementing l_trx_pmt_index - '||l_trx_pmt_index);
6146 	 print_debuginfo(l_module_name, 'Before assigning the values to pmtTable ');
6147    END IF;
6148           initialize_pmt_table(l_trx_pmt_index);
6149 	 /* Only pre-fill hardcoded grouping rule attributes */
6150          IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_pmt_index) :=x_paymentRec.payment_profile_id;
6151          IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(l_trx_pmt_index) :=x_paymentRec.payment_service_request_id;
6152 	 IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(l_trx_pmt_index) :=x_paymentRec.internal_bank_account_id;
6153          IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_pmt_index) :=x_paymentRec.ext_payee_id;
6154          IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_pmt_index) :=x_paymentRec.payee_party_id;
6155           IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_pmt_index) :=x_paymentRec.party_site_id;
6156          IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_pmt_index) :=x_paymentRec.supplier_site_id;
6157 	 IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(l_trx_pmt_index) :=x_paymentRec.ext_inv_payee_id;
6158          IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(l_trx_pmt_index) :=x_paymentRec.inv_payee_party_id;
6159          IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(l_trx_pmt_index) := x_paymentRec.inv_party_site_id;
6160          IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(l_trx_pmt_index) := x_paymentRec.inv_supplier_site_id;
6161          IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(l_trx_pmt_index) := x_paymentRec.inv_beneficiary_party;
6162          IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id (l_trx_pmt_index) :=x_paymentRec.remit_to_location_id;
6163          IBY_PAYGROUP_PUB.pmtTable.payment_currency_code (l_trx_pmt_index) :=x_paymentRec.payment_currency_code;
6164          IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_pmt_index) :=x_paymentRec.org_id;
6165          IBY_PAYGROUP_PUB.pmtTable.org_type(l_trx_pmt_index) :=x_paymentRec.org_type;
6166          IBY_PAYGROUP_PUB.pmtTable.payment_method_code(l_trx_pmt_index) :=x_paymentRec.payment_method_code;
6167          IBY_PAYGROUP_PUB.pmtTable.payment_function(l_trx_pmt_index) :=x_paymentRec.payment_function;
6168          IBY_PAYGROUP_PUB.pmtTable.payment_date(l_trx_pmt_index) :=x_paymentRec.payment_date;
6169          IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(l_trx_pmt_index) :=x_paymentRec.beneficiary_party;
6170          IBY_PAYGROUP_PUB.pmtTable.address_source(l_trx_pmt_index) :=x_paymentRec.address_source;
6171          IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_pmt_index) :=x_paymentRec.employee_address_code;
6172          IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_pmt_index) :=x_paymentRec.employee_person_id;
6173          IBY_PAYGROUP_PUB.pmtTable.employee_address_id(l_trx_pmt_index) :=x_paymentRec.employee_address_id;
6174          IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(l_trx_pmt_index) :=x_paymentRec.employee_payment_flag;
6175          IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_pmt_index) :=x_paymentRec.legal_entity_id;
6176 	 IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_pmt_index) :=NULL;
6177 
6178          IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_pmt_index) :=x_paymentRec.external_bank_account_id;
6179 
6180 
6181 
6182          IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(l_trx_pmt_index) :=x_paymentRec.bill_payable_flag;
6183 
6184 
6185 
6186          IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(l_trx_pmt_index) :=x_paymentRec.pregrouped_payment_flag;
6187 
6188 
6189 
6190          IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(l_trx_pmt_index) :=x_paymentRec.bank_instruction1_code;
6191          IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(l_trx_pmt_index) :=x_paymentRec.bank_instruction2_code;
6192          IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(l_trx_pmt_index) :=x_paymentRec.payment_text_message1;
6193          IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(l_trx_pmt_index) :=x_paymentRec.payment_text_message2;
6194          IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(l_trx_pmt_index) :=x_paymentRec.payment_text_message3;
6195 
6196 
6197 
6198 
6199 
6200 
6201          IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(l_trx_pmt_index) :=x_paymentRec.bank_charge_bearer;
6202 
6203 
6204 
6205          IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index) :=x_paymentRec.delivery_channel_code;
6206 
6207 
6208 
6209          IBY_PAYGROUP_PUB.pmtTable.settlement_priority(l_trx_pmt_index) :=x_paymentRec.settlement_priority;
6210 
6211 
6212          IBY_PAYGROUP_PUB.pmtTable.remittance_message1(l_trx_pmt_index) :=x_paymentRec.remittance_message1;
6213          IBY_PAYGROUP_PUB.pmtTable.remittance_message2(l_trx_pmt_index) :=x_paymentRec.remittance_message2;
6214          IBY_PAYGROUP_PUB.pmtTable.remittance_message3(l_trx_pmt_index) :=x_paymentRec.remittance_message3;
6215 
6216 
6217 
6218 
6219 --	 IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index) :=x_paymentRec.unique_remittance_identifier;
6220 	 IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index) :=x_paymentRec.uri_check_digit;
6221 
6222 
6223 	 IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index) :=x_paymentRec.payment_due_date;
6224 
6225 
6226 	 IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(l_trx_pmt_index) :=x_paymentRec.payment_reason_code;
6227 	 IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(l_trx_pmt_index) :=x_paymentRec.payment_reason_comments;
6228 
6229 	 --AWT Enh 16296267
6230 	 IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_pmt_index) :=x_paymentRec.affects_rejection_level;
6231 
6232 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6233          print_debuginfo(l_module_name, 'After assigning the basic values to pmtTable ');
6234         END IF;
6235 /* Replaced following code to fix Bug 10623927 */
6236    x_commonAttributes.prev_pmt_due_date := IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index);
6237    x_commonAttributes.prev_delivery_channel:=IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index);
6238    x_commonAttributes.prev_uri:=IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index);
6239    x_commonAttributes.prev_uri_checkdigits:= IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index);
6240 
6241      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6242 	 print_debuginfo(l_module_name, 'After assigning the values to pmtTable ');
6243 	END IF;
6244          /*
6245           * Create a new payment record using the incoming
6246           * document as a constituent, and insert this record
6247           * into the PLSQL payments table.
6248           */
6249          /*
6250 
6251 	 x_paymentRec.payment_id              :=  x_currentPaymentId;
6252 
6253          x_docsInPmtCount                     := 1;
6254 
6255          x_paymentRec.payment_amount          := iby_disburse_submit_pub_pkg.docspayTab.payment_amount(p_trx_line_index);
6256 
6257          x_paymentRec.discount_amount_taken   := iby_disburse_submit_pub_pkg.docspayTab.
6258                                                      payment_curr_discount_taken(p_trx_line_index);
6259 
6260          x_paymentRec.payment_details         := p_calcDocInfo;
6261 
6262 	*/
6263 
6264 	 x_docsInPmtCount                     := 1;
6265 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6266         print_debuginfo(l_module_name, 'Before assigning pmt id, pmt amt');
6267 		END IF;
6268  	IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index)             := x_currentPaymentId;
6269 	IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_pmt_index)         :=  iby_disburse_submit_pub_pkg.docspayTab.payment_amount(p_trx_line_index);
6270 	IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_pmt_index)  := iby_disburse_submit_pub_pkg.docspayTab.
6271 									     payment_curr_discount_taken(p_trx_line_index);
6272         IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index)        := p_calcDocInfo;
6273 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6274         print_debuginfo(l_module_name, 'Before assigning pmt id, pmt amt');
6275 		END IF;
6276         iby_disburse_submit_pub_pkg.docspayTab.payment_id(p_trx_line_index) := x_currentPaymentId;
6277 
6278 
6279 	 /* moving the initalizePmts logic to this block, to avoid unnecessary looping through payments */
6280 
6281         /*
6282 	 x_paymentRec.payment_status                 := 'CREATED';
6283          x_paymentRec.process_type                   := 'STANDARD';
6284 	*/
6285 
6286 
6287 	 IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_pmt_index)         :='CREATED';
6288 	IF(l_calling_app_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
6289         IBY_PAYGROUP_PUB.pmtTable.process_type(l_trx_pmt_index)		  := 'IMMEDIATE';
6290         ELSE
6291 	IBY_PAYGROUP_PUB.pmtTable.process_type(l_trx_pmt_index)		  := 'STANDARD';
6292         END IF;
6293 	IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(l_trx_pmt_index) := 'N';
6294 	IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(l_trx_pmt_index)	  :=nvl(iby_disburse_submit_pub_pkg.docspayTab.support_bills_payable_flag(p_trx_line_index),'N');
6295 
6296 	IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(l_trx_pmt_index)	  :='N';
6297 	IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(l_trx_pmt_index)	  :='N';
6298 
6299 --	IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index)	  :='N';
6300 
6301 --       	IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(l_trx_pmt_index)	  :=NULL;
6302 	IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(l_trx_pmt_index)         :=NULL;
6303 	IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(l_trx_pmt_index)         :=NULL;
6304         IBY_PAYGROUP_PUB.pmtTable.declaration_amount(l_trx_pmt_index)             :=0;
6305 
6306 	--IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(l_trx_pmt_index)	   :='N';
6307 	IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(l_trx_pmt_index)		   :='N';
6308 	IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(l_trx_pmt_index)		   :='N';
6309 	IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(l_trx_pmt_index)	   :='N';
6310 	 IBY_PAYGROUP_PUB.pmtTable.created_by(l_trx_pmt_index)                     := fnd_global.user_id;
6311          IBY_PAYGROUP_PUB.pmtTable.creation_date(l_trx_pmt_index)                  := sysdate;
6312          IBY_PAYGROUP_PUB.pmtTable.last_updated_by(l_trx_pmt_index)                := fnd_global.user_id;
6313          IBY_PAYGROUP_PUB.pmtTable.last_update_login(l_trx_pmt_index)              := fnd_global.user_id;
6314          IBY_PAYGROUP_PUB.pmtTable.last_update_date(l_trx_pmt_index)               := sysdate;
6315          IBY_PAYGROUP_PUB.pmtTable.object_version_number(l_trx_pmt_index)          := 1;
6316 
6317         /* special fields which need to be handled for pmtTable - record of table */
6318 
6319 	IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index) := 'N';
6320 
6321 
6322 
6323 
6324 
6325 	IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(l_trx_pmt_index) := NULL;
6326 
6327 	IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(l_trx_pmt_index) :=0;
6328 	--[ actually changed in postHook, bt b4 that insert happens]
6329 
6330 	IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(l_trx_pmt_index) :=NULL;
6331 	IBY_PAYGROUP_PUB.pmtTable.paper_document_number(l_trx_pmt_index)    :=NULL;
6332 
6333 	IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(l_trx_pmt_index)   := NULL;
6334 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(l_trx_pmt_index) := NULL;
6335 	IBY_PAYGROUP_PUB.pmtTable.maturity_date(l_trx_pmt_index)	    := NULL;
6336 
6337 	--[ calculated in performMatDateCalc, but conditionally]
6338 	IBY_PAYGROUP_PUB.pmtTable.document_category_code(l_trx_pmt_index)   :=NULL;
6339 	IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(l_trx_pmt_index)	    :=NULL;
6340 	IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(l_trx_pmt_index):= NULL;
6341 
6342 	IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(l_trx_pmt_index):= NULL;
6343 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(l_trx_pmt_index):= NULL;
6344 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(l_trx_pmt_index):= NULL;
6345 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(l_trx_pmt_index):= NULL;
6346 	IBY_PAYGROUP_PUB.pmtTable.stop_released_by(l_trx_pmt_index):= NULL;
6347 	IBY_PAYGROUP_PUB.pmtTable.stop_release_date(l_trx_pmt_index):= NULL;
6348 	IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(l_trx_pmt_index):= NULL;
6349 	IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(l_trx_pmt_index):= NULL;
6350 	IBY_PAYGROUP_PUB.pmtTable.stop_request_date(l_trx_pmt_index):= NULL;
6351 	IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by(l_trx_pmt_index):= NULL;
6352 	IBY_PAYGROUP_PUB.pmtTable.stop_request_reason(l_trx_pmt_index):= NULL;
6353 	IBY_PAYGROUP_PUB.pmtTable.stop_request_reference(l_trx_pmt_index):= NULL;
6354 	IBY_PAYGROUP_PUB.pmtTable.voided_by(l_trx_pmt_index):= NULL;
6355 	IBY_PAYGROUP_PUB.pmtTable.void_date(l_trx_pmt_index):= NULL;
6356 	IBY_PAYGROUP_PUB.pmtTable.void_reason(l_trx_pmt_index):= NULL;
6357 	IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(l_trx_pmt_index):= NULL;
6358 	IBY_PAYGROUP_PUB.pmtTable.attribute_category(l_trx_pmt_index):= NULL;
6359 	IBY_PAYGROUP_PUB.pmtTable.attribute1(l_trx_pmt_index):= NULL;
6360 	IBY_PAYGROUP_PUB.pmtTable.attribute2(l_trx_pmt_index):= NULL;
6361 	IBY_PAYGROUP_PUB.pmtTable.attribute3(l_trx_pmt_index):= NULL;
6362 	IBY_PAYGROUP_PUB.pmtTable.attribute4(l_trx_pmt_index):= NULL;
6363 	IBY_PAYGROUP_PUB.pmtTable.attribute5(l_trx_pmt_index):= NULL;
6364 	IBY_PAYGROUP_PUB.pmtTable.attribute6(l_trx_pmt_index):= NULL;
6365 	IBY_PAYGROUP_PUB.pmtTable.attribute7(l_trx_pmt_index):= NULL;
6366 	IBY_PAYGROUP_PUB.pmtTable.attribute8(l_trx_pmt_index):= NULL;
6367 	IBY_PAYGROUP_PUB.pmtTable.attribute9(l_trx_pmt_index):= NULL;
6368 	IBY_PAYGROUP_PUB.pmtTable.attribute10(l_trx_pmt_index):= NULL;
6369 	IBY_PAYGROUP_PUB.pmtTable.attribute11(l_trx_pmt_index):= NULL;
6370 	IBY_PAYGROUP_PUB.pmtTable.attribute12(l_trx_pmt_index):= NULL;
6371 	IBY_PAYGROUP_PUB.pmtTable.attribute13(l_trx_pmt_index):= NULL;
6372 	IBY_PAYGROUP_PUB.pmtTable.attribute14(l_trx_pmt_index):= NULL;
6373 	IBY_PAYGROUP_PUB.pmtTable.attribute15(l_trx_pmt_index):= NULL;
6374 
6375   -- better option to initialize the payee address details here rather in GET_PAYEE_ADDRESS_INFO
6376  	IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_pmt_index) := NULL;
6377 	IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_pmt_index) := NULL;
6378 	IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_pmt_index) := NULL;
6379 	IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_pmt_index) := NULL;
6380 	IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_pmt_index) := NULL;
6381 	IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_pmt_index) := NULL;
6382 	IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_pmt_index) := NULL;
6383 	IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_pmt_index) := NULL;
6384 	IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_pmt_index) := NULL;
6385 	IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_pmt_index) := NULL;
6386 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_pmt_index) := NULL;
6387 
6388    -- better option to initialize the payee address details here rather in GET_VENDOR_INFO
6389   IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_pmt_index):= NULL;
6390 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_pmt_index):= NULL;
6391 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_pmt_index)	:= NULL;
6392 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_pmt_index):= NULL;
6393 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_pmt_index):= NULL;
6394 	IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(l_trx_pmt_index):= NULL;
6395 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_pmt_index) := NULL;
6396 
6397 
6398 
6399          /*
6400           * Fix for bug 5115270:
6401           *
6402           * For all flags, take care not to overwite the flag
6403           * already set.
6404           */
6405 	 /*
6406 
6407          x_paymentRec.payments_complete_flag         :=
6408              NVL(x_paymentRec.payments_complete_flag,         'N');
6409          x_paymentRec.bill_payable_flag              :=
6410              NVL(x_paymentRec.bill_payable_flag,              'N');
6411          x_paymentRec.exclusive_payment_flag         :=
6412              NVL(x_paymentRec.exclusive_payment_flag,         'N');
6413          x_paymentRec.separate_remit_advice_req_flag :=
6414              NVL(x_paymentRec.separate_remit_advice_req_flag, 'N');
6415          x_paymentRec.declare_payment_flag           :=
6416              NVL(x_paymentRec.declare_payment_flag,           'N');
6417          x_paymentRec.pregrouped_payment_flag        :=
6418              NVL(x_paymentRec.pregrouped_payment_flag,        'N');
6419          x_paymentRec.stop_confirmed_flag            :=
6420              NVL(x_paymentRec.stop_confirmed_flag,            'N');
6421          x_paymentRec.stop_released_flag             :=
6422              NVL(x_paymentRec.stop_released_flag,             'N');
6423          x_paymentRec.stop_request_placed_flag       :=
6424              NVL(x_paymentRec.stop_request_placed_flag,       'N');
6425 
6426          x_paymentRec.created_by                     := fnd_global.user_id;
6427          x_paymentRec.creation_date                  := sysdate;
6428          x_paymentRec.last_updated_by                := fnd_global.user_id;
6429          x_paymentRec.last_update_login              := fnd_global.user_id;
6430          x_paymentRec.last_update_date               := sysdate;
6431          x_paymentRec.object_version_number          := 1;
6432 
6433 	 */
6434 
6435 
6436    /* moving the paymentrecord to x_paymentTab after initializing the values */
6437 
6438         -- x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
6439 
6440 
6441 
6442 
6443      ELSE
6444 
6445          /*
6446           * This means we need to add the incoming document to
6447           * the current  payment.
6448           */
6449 
6450          /*
6451           * First check special case: Payments PLSQL table is empty
6452           *
6453           * If the PLSQL table for payments is empty, we have to
6454           * initialize it by inserting a dummy record. This dummy
6455           * record will get overwritten below.
6456           */
6457        --  IF (x_paymentTab.COUNT = 0) THEN
6458        IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6459 	  print_debuginfo(l_module_name, 'Before checking for NULL value in pmtTable ');
6460           print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.payment_id(1) -  '|| IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT);
6461      END IF;
6462 	  IF (IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT = 0) THEN
6463 
6464              getNextPaymentID(x_currentPaymentID);
6465 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6466 	     print_debuginfo(l_module_name, 'Before incrementing - '||l_trx_pmt_index);
6467 		 END IF;
6468 	     l_trx_pmt_index := l_trx_pmt_index +1;
6469 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6470 	     print_debuginfo(l_module_name, 'Before initializing,l_trx_index  -  '|| l_trx_pmt_index);
6471 		 END IF;
6472              initialize_pmt_table(l_trx_pmt_index);
6473 
6474 	     IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index)              := x_currentPaymentId;
6475              x_docsInPmtCount                     := 0;
6476 
6477              IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_pmt_index)          := 0;
6478              IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_pmt_index)   :=  0;
6479              IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index)         := '';
6480 
6481 --        IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(l_trx_pmt_index)	  :=NULL;
6482 	IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(l_trx_pmt_index)         :=NULL;
6483 	-- Bug:8994772 :: The anticipated value date will be calculated later.
6484 	--IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(l_trx_pmt_index)         :=NULL;
6485 	IBY_PAYGROUP_PUB.pmtTable.declaration_amount(l_trx_pmt_index)             :=0;
6486 
6487        /* special fields which need to be handled for pmtTable - record of table */
6488 
6489 	IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index) := 'N' ;
6490 
6491 
6492 
6493 
6494 
6495 	IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(l_trx_pmt_index) := NULL;
6496 
6497 	IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(l_trx_pmt_index) :=0;
6498 	--[ actually changed in postHook, bt b4 that insert happens]
6499 
6500 	IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(l_trx_pmt_index) :=NULL;
6501 	IBY_PAYGROUP_PUB.pmtTable.paper_document_number(l_trx_pmt_index)    :=NULL;
6502 
6503 	IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(l_trx_pmt_index)   := NULL;
6504 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(l_trx_pmt_index) := NULL;
6505 	IBY_PAYGROUP_PUB.pmtTable.maturity_date(l_trx_pmt_index)	    := NULL;
6506 
6507 	--[ calculated in performMatDateCalc, but conditionally]
6508 	IBY_PAYGROUP_PUB.pmtTable.document_category_code(l_trx_pmt_index)   :=NULL;
6509 	IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(l_trx_pmt_index)	    :=NULL;
6510 	IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(l_trx_pmt_index):= NULL;
6511 
6512 	IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(l_trx_pmt_index):= NULL;
6513 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(l_trx_pmt_index):= NULL;
6514 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(l_trx_pmt_index):= NULL;
6515 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(l_trx_pmt_index):= NULL;
6516 	IBY_PAYGROUP_PUB.pmtTable.stop_released_by(l_trx_pmt_index):= NULL;
6517 	IBY_PAYGROUP_PUB.pmtTable.stop_release_date(l_trx_pmt_index):= NULL;
6518 	IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(l_trx_pmt_index):= NULL;
6519 	IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(l_trx_pmt_index):= NULL;
6520 	IBY_PAYGROUP_PUB.pmtTable.stop_request_date(l_trx_pmt_index):= NULL;
6521 	IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by(l_trx_pmt_index):= NULL;
6522 	IBY_PAYGROUP_PUB.pmtTable.stop_request_reason(l_trx_pmt_index):= NULL;
6523 	IBY_PAYGROUP_PUB.pmtTable.stop_request_reference(l_trx_pmt_index):= NULL;
6524 	IBY_PAYGROUP_PUB.pmtTable.voided_by(l_trx_pmt_index):= NULL;
6525 	IBY_PAYGROUP_PUB.pmtTable.void_date(l_trx_pmt_index):= NULL;
6526 	IBY_PAYGROUP_PUB.pmtTable.void_reason(l_trx_pmt_index):= NULL;
6527 	IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(l_trx_pmt_index):= NULL;
6528 
6529 
6530 	IBY_PAYGROUP_PUB.pmtTable.attribute_category(l_trx_pmt_index):= NULL;
6531 	IBY_PAYGROUP_PUB.pmtTable.attribute1(l_trx_pmt_index):= NULL;
6532 	IBY_PAYGROUP_PUB.pmtTable.attribute2(l_trx_pmt_index):= NULL;
6533 	IBY_PAYGROUP_PUB.pmtTable.attribute3(l_trx_pmt_index):= NULL;
6534 	IBY_PAYGROUP_PUB.pmtTable.attribute4(l_trx_pmt_index):= NULL;
6535 	IBY_PAYGROUP_PUB.pmtTable.attribute5(l_trx_pmt_index):= NULL;
6536 	IBY_PAYGROUP_PUB.pmtTable.attribute6(l_trx_pmt_index):= NULL;
6537 	IBY_PAYGROUP_PUB.pmtTable.attribute7(l_trx_pmt_index):= NULL;
6538 	IBY_PAYGROUP_PUB.pmtTable.attribute8(l_trx_pmt_index):= NULL;
6539 	IBY_PAYGROUP_PUB.pmtTable.attribute9(l_trx_pmt_index):= NULL;
6540 	IBY_PAYGROUP_PUB.pmtTable.attribute10(l_trx_pmt_index):= NULL;
6541 	IBY_PAYGROUP_PUB.pmtTable.attribute11(l_trx_pmt_index):= NULL;
6542 	IBY_PAYGROUP_PUB.pmtTable.attribute12(l_trx_pmt_index):= NULL;
6543 	IBY_PAYGROUP_PUB.pmtTable.attribute13(l_trx_pmt_index):= NULL;
6544 	IBY_PAYGROUP_PUB.pmtTable.attribute14(l_trx_pmt_index):= NULL;
6545 	IBY_PAYGROUP_PUB.pmtTable.attribute15(l_trx_pmt_index):= NULL;
6546 
6547 
6548   -- better option to initialize the payee address details here rather in GET_PAYEE_ADDRESS_INFO
6549  	IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_pmt_index) := NULL;
6550 	IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_pmt_index) := NULL;
6551 	IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_pmt_index) := NULL;
6552 	IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_pmt_index) := NULL;
6553 	IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_pmt_index) := NULL;
6554 	IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_pmt_index) := NULL;
6555 	IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_pmt_index) := NULL;
6556 	IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_pmt_index) := NULL;
6557 	IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_pmt_index) := NULL;
6558 	IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_pmt_index) := NULL;
6559 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_pmt_index) := NULL;
6560 
6561    -- better option to initialize the payee address details here rather in GET_VENDOR_INFO
6562   IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_pmt_index):= NULL;
6563 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_pmt_index):= NULL;
6564 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_pmt_index)	:= NULL;
6565 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_pmt_index):= NULL;
6566 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_pmt_index):= NULL;
6567 	IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(l_trx_pmt_index):= NULL;
6568 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_pmt_index) := NULL;
6569 
6570 
6571 
6572 
6573 
6574 	 /* moving the initalizePmts logic to this block, to avoid unnecessary looping through payments */
6575 
6576 	 IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_pmt_index)                 := 'CREATED';
6577 	 IF(l_calling_app_procedure = 'IBY_DISBURSE_SINGLE_PMT_PKG') THEN
6578         IBY_PAYGROUP_PUB.pmtTable.process_type(l_trx_pmt_index)		  := 'IMMEDIATE';
6579         ELSE
6580 	IBY_PAYGROUP_PUB.pmtTable.process_type(l_trx_pmt_index)		  := 'STANDARD';
6581         END IF;
6582 
6583 	 /*
6584           * Fix for bug 5115270:
6585           *
6586           * For all flags, take care not to overwite the flag
6587           * already set.
6588           */
6589 		  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6590        print_debuginfo(l_module_name, 'Before checking for NVL at 5722');
6591 	   END IF;
6592   	 IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(l_trx_pmt_index)         := 'N';
6593 
6594 
6595 	 IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(l_trx_pmt_index)              := 'N';
6596 	 IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(l_trx_pmt_index)         := 'N';
6597 	 IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(l_trx_pmt_index) := 'N';
6598 	 IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index)           := 'N';
6599 	 IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(l_trx_pmt_index)        := 'N';
6600 	 IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(l_trx_pmt_index)            := 'N';
6601 	 IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(l_trx_pmt_index)             := 'N';
6602 	 IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(l_trx_pmt_index)       := 'N';
6603 
6604 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6605 	 print_debuginfo(l_module_name, 'Before initializing at 5742');
6606 	 END IF;
6607 
6608 	 IBY_PAYGROUP_PUB.pmtTable.created_by(l_trx_pmt_index)                     := fnd_global.user_id;
6609 	 IBY_PAYGROUP_PUB.pmtTable.creation_date(l_trx_pmt_index)                  := sysdate;
6610 	 IBY_PAYGROUP_PUB.pmtTable.last_updated_by(l_trx_pmt_index)                := fnd_global.user_id;
6611 	 IBY_PAYGROUP_PUB.pmtTable.last_update_login(l_trx_pmt_index)              := fnd_global.user_id;
6612 	 IBY_PAYGROUP_PUB.pmtTable.last_update_date(l_trx_pmt_index)               := sysdate;
6613 	 IBY_PAYGROUP_PUB.pmtTable.object_version_number(l_trx_pmt_index)          := 1;
6614 
6615 
6616              /*
6617               * Insert the first record into the table. This
6618               * is a dummy record.
6619               */
6620            --  x_paymentTab(x_paymentTab.COUNT + 1) := x_paymentRec;
6621 
6622 	     	 /* Only pre-fill hardcoded grouping rule attributes */
6623          IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_pmt_index) :=x_paymentRec.payment_profile_id;
6624          IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(l_trx_pmt_index) :=x_paymentRec.payment_service_request_id;
6625 	 IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(l_trx_pmt_index) :=x_paymentRec.internal_bank_account_id;
6626          IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_pmt_index) :=x_paymentRec.ext_payee_id;
6627          IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_pmt_index) :=x_paymentRec.payee_party_id;
6628           IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_pmt_index) :=x_paymentRec.party_site_id;
6629          IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_pmt_index) :=x_paymentRec.supplier_site_id;
6630 	 IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(l_trx_pmt_index) :=x_paymentRec.ext_inv_payee_id;
6631          IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(l_trx_pmt_index) :=x_paymentRec.inv_payee_party_id;
6632          IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(l_trx_pmt_index) := x_paymentRec.inv_party_site_id;
6633          IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(l_trx_pmt_index) := x_paymentRec.inv_supplier_site_id;
6634          IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(l_trx_pmt_index) := x_paymentRec.inv_beneficiary_party;
6635          IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id (l_trx_pmt_index) :=x_paymentRec.remit_to_location_id;
6636          IBY_PAYGROUP_PUB.pmtTable.payment_currency_code (l_trx_pmt_index) :=x_paymentRec.payment_currency_code;
6637          IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_pmt_index) :=x_paymentRec.org_id;
6638          IBY_PAYGROUP_PUB.pmtTable.org_type(l_trx_pmt_index) :=x_paymentRec.org_type;
6639          IBY_PAYGROUP_PUB.pmtTable.payment_method_code(l_trx_pmt_index) :=x_paymentRec.payment_method_code;
6640          IBY_PAYGROUP_PUB.pmtTable.payment_function(l_trx_pmt_index) :=x_paymentRec.payment_function;
6641          IBY_PAYGROUP_PUB.pmtTable.payment_date(l_trx_pmt_index) :=x_paymentRec.payment_date;
6642          IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(l_trx_pmt_index) :=x_paymentRec.beneficiary_party;
6643          IBY_PAYGROUP_PUB.pmtTable.address_source(l_trx_pmt_index) :=x_paymentRec.address_source;
6644          IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_pmt_index) :=x_paymentRec.employee_address_code;
6645          IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_pmt_index) :=x_paymentRec.employee_person_id;
6646          IBY_PAYGROUP_PUB.pmtTable.employee_address_id(l_trx_pmt_index) :=x_paymentRec.employee_address_id;
6647          IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(l_trx_pmt_index) :=x_paymentRec.employee_payment_flag;
6648          IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_pmt_index) :=x_paymentRec.legal_entity_id;
6649        	 IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_pmt_index) :=NULL;
6650        	 IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(l_trx_pmt_index) :=NULL;
6651 
6652          IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_pmt_index) :=x_paymentRec.external_bank_account_id;
6653 
6654 
6655 
6656          IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(l_trx_pmt_index) :=x_paymentRec.bill_payable_flag;
6657 
6658 
6659 
6660          IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(l_trx_pmt_index) :=x_paymentRec.pregrouped_payment_flag;
6661 
6662 
6663 
6664          IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(l_trx_pmt_index) :=x_paymentRec.bank_instruction1_code;
6665          IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(l_trx_pmt_index) :=x_paymentRec.bank_instruction2_code;
6666          IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(l_trx_pmt_index) :=x_paymentRec.payment_text_message1;
6667          IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(l_trx_pmt_index) :=x_paymentRec.payment_text_message2;
6668          IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(l_trx_pmt_index) :=x_paymentRec.payment_text_message3;
6669 
6670 
6671 
6672 
6673 
6674 
6675          IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(l_trx_pmt_index) :=x_paymentRec.bank_charge_bearer;
6676 
6677 
6678 
6679          IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index) :=x_paymentRec.delivery_channel_code;
6680 
6681 
6682 
6683          IBY_PAYGROUP_PUB.pmtTable.settlement_priority(l_trx_pmt_index) :=x_paymentRec.settlement_priority;
6684 
6685 
6686          IBY_PAYGROUP_PUB.pmtTable.remittance_message1(l_trx_pmt_index) :=x_paymentRec.remittance_message1;
6687          IBY_PAYGROUP_PUB.pmtTable.remittance_message2(l_trx_pmt_index) :=x_paymentRec.remittance_message2;
6688          IBY_PAYGROUP_PUB.pmtTable.remittance_message3(l_trx_pmt_index) :=x_paymentRec.remittance_message3;
6689 
6690 
6691 
6692 
6693 	 IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index) :=x_paymentRec.unique_remittance_identifier;
6694 	 IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index) :=x_paymentRec.uri_check_digit;
6695 
6696 
6697 	 IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index) :=x_paymentRec.payment_due_date;
6698 
6699 
6700 	 IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(l_trx_pmt_index) :=x_paymentRec.payment_reason_code;
6701 	 IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(l_trx_pmt_index) :=x_paymentRec.payment_reason_comments;
6702 
6703 	 IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_pmt_index) :=x_paymentRec.affects_rejection_level;    --AWT Enh 16296267
6704 
6705 
6706 
6707 
6708 
6709 
6710              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6711 		print_debuginfo(l_module_name, 'Created a new payment: '
6712                  || x_currentPaymentId);
6713              END IF;
6714 
6715          END IF;	 -- pmtTable.payment_id.COUNT = 0
6716          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6717          print_debuginfo(l_module_name, 'Value of inv_payee_party_id in record group'
6718                  || 'is '
6719                  || x_paymentRec.inv_payee_party_id
6720                  );
6721          print_debuginfo(l_module_name, 'Value of inv_payee_party_id in pmt table'
6722                  || 'is '
6723                  || IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(l_trx_pmt_index)
6724                  );
6725 		END IF;
6726 
6727 
6728 	 --AWT Enh 16296267
6729 	 IF ((IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_pmt_index) <> 'Y') AND
6730 	    (x_paymentRec.affects_rejection_level = 'Y')) THEN
6731 		IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_pmt_index) := 'Y';
6732 	 END IF;
6733 
6734          /*
6735           * The incoming document should be part of the current payment.
6736           * So add the document amount to the current payment
6737           * record and increment the document count for the current
6738           * payment record.
6739           */
6740 
6741 
6742          If (x_commonAttributes.due_date_common_flag = 'Y') THEN
6743 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6744             print_debuginfo(l_module_name, 'due_date_common_flag is Y');
6745 			END IF;
6746             If (NVL(x_commonAttributes.prev_pmt_due_date,l_impossible_date) <> NVL(x_commonAttributes.curr_pmt_due_date, l_impossible_date))  THEN
6747                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6748                print_debuginfo(l_module_name, 'The values are different for due date');
6749 			   END IF;
6750                     x_commonAttributes.due_date_common_flag  := 'N';
6751                     IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index)            :=  '';
6752 
6753             ELSE
6754 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6755                     print_debuginfo(l_module_name, 'The values are not different for due date');
6756 					END IF;
6757                     IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index)        := x_commonAttributes.curr_pmt_due_date;
6758             END IF;
6759 
6760          END IF;
6761 
6762          If (x_commonAttributes.delv_chnl_common_flag = 'Y') THEN
6763 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6764             print_debuginfo(l_module_name, 'delv_chnl_common_flag is Y');
6765 			END IF;
6766             If (NVL(x_commonAttributes.prev_delivery_channel,0) <> NVL(x_commonAttributes.curr_delivery_channel, 0))  THEN
6767 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6768                          print_debuginfo(l_module_name, 'The values are different for delv_chnl');
6769 						 END IF;
6770                          x_commonAttributes.delv_chnl_common_flag := 'N';
6771                          IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index)   := '';
6772 
6773             ELSE
6774 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6775                         print_debuginfo(l_module_name, 'The values are not different for delv_chnl');
6776 						END IF;
6777                         IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index)   := x_commonAttributes.curr_delivery_channel;
6778             END IF;
6779          END IF;
6780 
6781          If (x_commonAttributes.uri_common_flag = 'Y') THEN
6782 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6783                print_debuginfo(l_module_name, 'uri_common_flag is Y');
6784 			   END IF;
6785              IF (NVL(x_commonAttributes.prev_uri, 0) <> NVL(x_commonAttributes.prev_uri, 0) OR
6786                      NVL(x_commonAttributes.prev_uri_checkdigits, 0) <>
6787                          NVL(x_commonAttributes.curr_uri_checkdigits, 0)) THEN
6788 						 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6789                         print_debuginfo(l_module_name, 'The values are different for URI');
6790 						END IF;
6791                         x_commonAttributes.uri_common_flag       := 'N';
6792                  IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index) := '';
6793 		 IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index)		 := '';
6794              ELSE
6795 			 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6796                  print_debuginfo(l_module_name, 'The values are not different for URI');
6797 				 END IF;
6798 	         IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index) := x_commonAttributes.curr_uri;
6799                  IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index)              := x_commonAttributes.curr_uri_checkdigits;
6800 
6801 		 END IF;
6802          END IF;
6803 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6804          print_debuginfo(l_module_name, 'Outside the replacement code of sweepcommonattr');
6805 		 END IF;
6806 
6807 
6808  	 IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index)     :=  x_currentPaymentId;
6809 
6810          x_docsInPmtCount            := x_docsInPmtCount + 1;
6811 
6812          IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_pmt_index) :=
6813              IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_pmt_index) + iby_disburse_submit_pub_pkg.docspayTab.payment_amount(p_trx_line_index);
6814 
6815          IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_pmt_index)   :=
6816              IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_pmt_index)
6817                  + iby_disburse_submit_pub_pkg.docspayTab.payment_curr_discount_taken(p_trx_line_index);
6818 
6819          /*
6820           * The payment details information is passed in by the caller.
6821           * If this value is null, it means that the caller does not
6822           * wish to use the grouping rule 'break payments according to
6823           * space available under payment details'. In such a case, do not
6824           * append the payment details from each document into the payment.
6825           */
6826 
6827          IF (p_calcDocInfo IS NOT NULL) THEN
6828 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6829           print_debuginfo(l_module_name, 'Inside p_calcDocInfo is not null');
6830 		  END IF;
6831 
6832             IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index)   :=
6833              IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index)
6834                  || p_calcDocInfo;
6835 
6836          END IF;
6837 
6838 
6839          /*
6840           * Overwrite the current payment record in the
6841           * PLSQL payments table with the updated record.
6842           */
6843 
6844         iby_disburse_submit_pub_pkg.docspayTab.payment_id(p_trx_line_index) := x_currentPaymentId;
6845 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6846         print_debuginfo(l_module_name, 'After assigning the current pmt id to the cache');
6847 
6848         print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_pmt_index)'|| IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_pmt_index));
6849 		END IF;
6850      END IF;
6851 
6852      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6853 	print_debuginfo(l_module_name, 'EXIT');
6854       END IF;
6855   EXCEPTION
6856    WHEN OTHERS THEN
6857    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
6858                  FND_LOG.LEVEL_UNEXPECTED);
6859              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
6860                  FND_LOG.LEVEL_UNEXPECTED);
6861    print_debuginfo(l_module_name, l_module_name||':Exception while inserting Doc into Payment');
6862    RAISE;
6863  END insertDocIntoPayment;
6864 
6865 
6866 
6867 /*--------------------------------------------------------------------
6868  | NAME:
6869  |     insertPayments
6870  |
6871  | PURPOSE:
6872  |     Performs a bulk insert of all created payments from PLSQL
6873  |     table into IBY_PAYMENTS_ALL table.
6874  |
6875  | PARAMETERS:
6876  |     IN
6877  |
6878  |
6879  |     OUT
6880  |
6881  |
6882  | RETURNS:
6883  |
6884  | NOTES:
6885  |
6886  *---------------------------------------------------------------------*/
6887   PROCEDURE insertPayments(
6888      p_paymentTab    IN paymentTabType
6889      )
6890  IS
6891  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.insertPayments';
6892  TYPE tax_regis_num IS TABLE OF iby_payments_all.payee_tax_registration_num%TYPE INDEX BY BINARY_INTEGER;
6893  l_tax_registration_num tax_regis_num;
6894 
6895  BEGIN
6896 
6897      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6898 	 print_debuginfo(l_module_name, 'ENTER');
6899 
6900      END IF;
6901 
6902      /* Normally, this shouldn't happen */
6903      IF (p_paymentTab.COUNT = 0) THEN
6904          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
6905 	 print_debuginfo(l_module_name, 'After grouping, no payments'
6906              || ' were found to insert into IBY_PAYMENTS_ALL table.'
6907              || ' Possible data corruption issue.');
6908 
6909          END IF;
6910          RETURN;
6911      END IF;
6912 
6913      /*
6914       * Copy values for each column into its corresponding column
6915       * array. These column arrays will be used in the bulk insert.
6916       */
6917      FOR i in p_paymentTab.FIRST..p_paymentTab.LAST LOOP
6918 
6919          paymentTab.payment_id(i)
6920              := p_paymentTab(i).payment_id;
6921          paymentTab.payment_method_code(i)
6922              := p_paymentTab(i).payment_method_code;
6923          paymentTab.payment_service_request_id(i)
6924              := p_paymentTab(i).payment_service_request_id;
6925          paymentTab.process_type(i)
6926              := NVL(p_paymentTab(i).process_type, 'STANDARD');
6927          paymentTab.payment_status(i)
6928              := NVL(p_paymentTab(i).payment_status, 'CREATED');
6929          paymentTab.payments_complete_flag(i)
6930              := NVL(p_paymentTab(i).payments_complete_flag, 'N');
6931          paymentTab.payment_function(i)
6932              := p_paymentTab(i).payment_function;
6933          paymentTab.payment_amount(i)
6934              := p_paymentTab(i).payment_amount;
6935          paymentTab.payment_currency_code(i)
6936              := p_paymentTab(i).payment_currency_code;
6937          paymentTab.bill_payable_flag(i)
6938              := NVL(p_paymentTab(i).bill_payable_flag, 'N');
6939          paymentTab.exclusive_payment_flag(i)
6940              := NVL(p_paymentTab(i).exclusive_payment_flag, 'N');
6941          paymentTab.sep_remit_advice_req_flag(i)
6942              := NVL(p_paymentTab(i).separate_remit_advice_req_flag, 'N');
6943          paymentTab.internal_bank_account_id(i)
6944              := p_paymentTab(i).internal_bank_account_id;
6945          paymentTab.org_id(i)
6946              := p_paymentTab(i).org_id;
6947          paymentTab.org_type(i)
6948              := p_paymentTab(i).org_type;
6949          paymentTab.legal_entity_id(i)
6950              := p_paymentTab(i).legal_entity_id;
6951          paymentTab.declare_payment_flag(i)
6952              := NVL(p_paymentTab(i).declare_payment_flag, 'N');
6953          paymentTab.delivery_channel_code(i)
6954              := p_paymentTab(i).delivery_channel_code;
6955          paymentTab.ext_payee_id(i)
6956              := p_paymentTab(i).ext_payee_id;
6957          paymentTab.payment_instruction_id(i)
6958              := p_paymentTab(i).payment_instruction_id;
6959          paymentTab.payment_profile_id(i)
6960              := p_paymentTab(i).payment_profile_id;
6961          paymentTab.pregrouped_payment_flag(i)
6962              := NVL(p_paymentTab(i).pregrouped_payment_flag, 'N');
6963          paymentTab.stop_confirmed_flag(i)
6964              := NVL(p_paymentTab(i).stop_confirmed_flag, 'N');
6965          paymentTab.stop_released_flag(i)
6966              := NVL(p_paymentTab(i).stop_released_flag, 'N');
6967          paymentTab.stop_request_placed_flag(i)
6968              := NVL(p_paymentTab(i).stop_request_placed_flag, 'N');
6969          paymentTab.created_by(i)
6970              := NVL(p_paymentTab(i).created_by, fnd_global.user_id);
6971          paymentTab.creation_date(i)
6972              := NVL(p_paymentTab(i).creation_date, sysdate);
6973          paymentTab.last_updated_by(i)
6974              := NVL(p_paymentTab(i).last_updated_by, fnd_global.user_id);
6975          paymentTab.last_update_login(i)
6976              := NVL(p_paymentTab(i).last_update_login, fnd_global.user_id);
6977          paymentTab.last_update_date(i)
6978              := NVL(p_paymentTab(i).last_update_date, sysdate);
6979          paymentTab.object_version_number(i)
6980              := NVL(p_paymentTab(i).object_version_number, 1);
6981          paymentTab.payee_party_id(i)
6982              := p_paymentTab(i).payee_party_id;
6983          paymentTab.party_site_id(i)
6984              := p_paymentTab(i).party_site_id;
6985          paymentTab.supplier_site_id(i)
6986              := p_paymentTab(i).supplier_site_id;
6987          paymentTab.payment_reason_code(i)
6988              := p_paymentTab(i).payment_reason_code;
6989          paymentTab.payment_reason_comments(i)
6990              := p_paymentTab(i).payment_reason_comments;
6991          paymentTab.payment_date(i)
6992              := p_paymentTab(i).payment_date;
6993          paymentTab.anticipated_value_date(i)
6994              := p_paymentTab(i).anticipated_value_date;
6995          paymentTab.declaration_amount(i)
6996              := p_paymentTab(i).declaration_amount;
6997          paymentTab.declaration_currency_code(i)
6998              := p_paymentTab(i).declaration_currency_code;
6999          paymentTab.discount_amount_taken(i)
7000              := p_paymentTab(i).discount_amount_taken;
7001          paymentTab.payment_details(i)
7002              := p_paymentTab(i).payment_details;
7003          paymentTab.bank_charge_bearer(i)
7004              := p_paymentTab(i).bank_charge_bearer;
7005          paymentTab.bank_charge_amount(i)
7006              := p_paymentTab(i).bank_charge_amount;
7007          paymentTab.settlement_priority(i)
7008              := p_paymentTab(i).settlement_priority;
7009          paymentTab.remittance_message1(i)
7010              := p_paymentTab(i).remittance_message1;
7011          paymentTab.remittance_message2(i)
7012              := p_paymentTab(i).remittance_message2;
7013          paymentTab.remittance_message3(i)
7014              := p_paymentTab(i).remittance_message3;
7015          paymentTab.payment_reference_number(i)
7016              := p_paymentTab(i).payment_reference_number;
7017          paymentTab.paper_document_number(i)
7018              := p_paymentTab(i).paper_document_number;
7019          paymentTab.bank_assigned_ref_code(i)
7020              := p_paymentTab(i).bank_assigned_ref_code;
7021          paymentTab.external_bank_account_id(i)
7022              := p_paymentTab(i).external_bank_account_id;
7023          paymentTab.unique_remittance_identifier(i)
7024              := p_paymentTab(i).unique_remittance_identifier;
7025          paymentTab.uri_check_digit(i)
7026              := p_paymentTab(i).uri_check_digit;
7027          paymentTab.bank_instruction1_code(i)
7028              := p_paymentTab(i).bank_instruction1_code;
7029          paymentTab.bank_instruction2_code(i)
7030              := p_paymentTab(i).bank_instruction2_code;
7031          paymentTab.bank_instruction_details(i)
7032              := p_paymentTab(i).bank_instruction_details;
7033          paymentTab.payment_text_message1(i)
7034              := p_paymentTab(i).payment_text_message1;
7035          paymentTab.payment_text_message2(i)
7036              := p_paymentTab(i).payment_text_message2;
7037          paymentTab.payment_text_message3(i)
7038              := p_paymentTab(i).payment_text_message3;
7039          paymentTab.maturity_date(i)
7040              := p_paymentTab(i).maturity_date;
7041          paymentTab.payment_due_date(i)
7042              := p_paymentTab(i).payment_due_date;
7043          paymentTab.document_category_code(i)
7044              := p_paymentTab(i).document_category_code;
7045          paymentTab.document_sequence_id(i)
7046              := p_paymentTab(i).document_sequence_id;
7047          paymentTab.document_sequence_value(i)
7048              := p_paymentTab(i).document_sequence_value;
7049          paymentTab.beneficiary_party(i)
7050              := p_paymentTab(i).beneficiary_party;
7051          paymentTab.stop_confirmed_by(i)
7052              := p_paymentTab(i).stop_confirmed_by;
7053          paymentTab.stop_confirm_date(i)
7054              := p_paymentTab(i).stop_confirm_date;
7055          paymentTab.stop_confirm_reason(i)
7056              := p_paymentTab(i).stop_confirm_reason;
7057          paymentTab.stop_confirm_reference(i)
7058              := p_paymentTab(i).stop_confirm_reference;
7059          paymentTab.stop_released_by(i)
7060              := p_paymentTab(i).stop_released_by;
7061          paymentTab.stop_release_date(i)
7062              := p_paymentTab(i).stop_release_date;
7063          paymentTab.stop_release_reason(i)
7064              := p_paymentTab(i).stop_release_reason;
7065          paymentTab.stop_release_reference(i)
7066              := p_paymentTab(i).stop_release_reference;
7067          paymentTab.stop_request_date(i)
7068              := p_paymentTab(i).stop_request_date;
7069          paymentTab.stop_request_placed_by(i)
7070              := p_paymentTab(i).stop_request_placed_by;
7071          paymentTab.stop_request_reason(i)
7072              := p_paymentTab(i).stop_request_reason;
7073          paymentTab.stop_request_reference(i)
7074              := p_paymentTab(i).stop_request_reference;
7075          paymentTab.voided_by(i)
7076              := p_paymentTab(i).voided_by;
7077          paymentTab.void_date(i)
7078              := p_paymentTab(i).void_date;
7079          paymentTab.void_reason(i)
7080              := p_paymentTab(i).void_reason;
7081          paymentTab.remit_to_location_id(i)
7082              := p_paymentTab(i).remit_to_location_id;
7083          paymentTab.completed_pmts_group_id(i)
7084              := p_paymentTab(i).completed_pmts_group_id;
7085          paymentTab.attribute_category(i)
7086              := p_paymentTab(i).attribute_category;
7087          paymentTab.attribute1(i)
7088              := p_paymentTab(i).attribute1;
7089          paymentTab.attribute2(i)
7090              := p_paymentTab(i).attribute2;
7091          paymentTab.attribute3(i)
7092              := p_paymentTab(i).attribute3;
7093          paymentTab.attribute4(i)
7094              := p_paymentTab(i).attribute4;
7095          paymentTab.attribute5(i)
7096              := p_paymentTab(i).attribute5;
7097          paymentTab.attribute6(i)
7098              := p_paymentTab(i).attribute6;
7099          paymentTab.attribute7(i)
7100              := p_paymentTab(i).attribute7;
7101          paymentTab.attribute8(i)
7102              := p_paymentTab(i).attribute8;
7103          paymentTab.attribute9(i)
7104              := p_paymentTab(i).attribute9;
7105          paymentTab.attribute10(i)
7106              := p_paymentTab(i).attribute10;
7107          paymentTab.attribute11(i)
7108              := p_paymentTab(i).attribute11;
7109          paymentTab.attribute12(i)
7110              := p_paymentTab(i).attribute12;
7111          paymentTab.attribute13(i)
7112              := p_paymentTab(i).attribute13;
7113          paymentTab.attribute14(i)
7114              := p_paymentTab(i).attribute14;
7115          paymentTab.attribute15(i)
7116              := p_paymentTab(i).attribute15;
7117          paymentTab.ext_branch_number(i)
7118              := p_paymentTab(i).ext_branch_number;
7119          paymentTab.ext_bank_number(i)
7120              := p_paymentTab(i).ext_bank_number;
7121          paymentTab.ext_bank_account_name(i)
7122              := p_paymentTab(i).ext_bank_account_name;
7123          paymentTab.ext_bank_account_number(i)
7124              := p_paymentTab(i).ext_bank_account_number;
7125          paymentTab.ext_bank_account_type(i)
7126              := p_paymentTab(i).ext_bank_account_type;
7127          paymentTab.ext_bank_account_iban_number(i)
7128              := p_paymentTab(i).ext_bank_account_iban_number;
7129          paymentTab.payee_name(i)
7130              := p_paymentTab(i).payee_name;
7131          paymentTab.payee_address1(i)
7132              := p_paymentTab(i).payee_address1;
7133          paymentTab.payee_address2(i)
7134              := p_paymentTab(i).payee_address2;
7135          paymentTab.payee_address3(i)
7136              := p_paymentTab(i).payee_address3;
7137          paymentTab.payee_address4(i)
7138              := p_paymentTab(i).payee_address4;
7139          paymentTab.payee_city(i)
7140              := p_paymentTab(i).payee_city;
7141          paymentTab.payee_postal_code(i)
7142              := p_paymentTab(i).payee_postal_code;
7143          paymentTab.payee_state(i)
7144              := p_paymentTab(i).payee_state;
7145          paymentTab.payee_province(i)
7146              := p_paymentTab(i).payee_province;
7147          paymentTab.payee_county(i)
7148              := p_paymentTab(i).payee_county;
7149          paymentTab.payee_country(i)
7150              := p_paymentTab(i).payee_country;
7151          paymentTab.remit_advice_delivery_method(i)
7152              := p_paymentTab(i).remit_advice_delivery_method;
7153          paymentTab.remit_advice_email(i)
7154              := p_paymentTab(i).remit_advice_email;
7155          paymentTab.remit_advice_fax(i)
7156              := p_paymentTab(i).remit_advice_fax;
7157          paymentTab.address_source(i)
7158              := p_paymentTab(i).address_source;
7159          paymentTab.employee_address_code(i)
7160              := p_paymentTab(i).employee_address_code;
7161          paymentTab.employee_person_id(i)
7162              := p_paymentTab(i).employee_person_id;
7163          paymentTab.employee_address_id(i)
7164              := p_paymentTab(i).employee_address_id;
7165          paymentTab.employee_payment_flag(i)
7166              := p_paymentTab(i).employee_payment_flag;
7167 
7168 paymentTab.ext_inv_payee_id(i)
7169              := p_paymentTab(i).ext_inv_payee_id;
7170 paymentTab.inv_payee_party_id(i)
7171              := p_paymentTab(i).inv_payee_party_id;
7172 paymentTab.inv_party_site_id(i)
7173              := p_paymentTab(i).inv_party_site_id;
7174 paymentTab.inv_supplier_site_id(i)
7175              := p_paymentTab(i).inv_supplier_site_id;
7176 paymentTab.inv_beneficiary_party(i)
7177              := p_paymentTab(i).inv_beneficiary_party;
7178 paymentTab.inv_payee_name(i)
7179              := p_paymentTab(i).inv_payee_name;
7180 paymentTab.inv_payee_address1(i)
7181              := p_paymentTab(i).inv_payee_address1;
7182 paymentTab.inv_payee_address2(i)
7183              := p_paymentTab(i).inv_payee_address2;
7184 paymentTab.inv_payee_address3(i)
7185              := p_paymentTab(i).inv_payee_address3;
7186 paymentTab.inv_payee_address4(i)
7187              := p_paymentTab(i).inv_payee_address4;
7188 paymentTab.inv_payee_city(i)
7189              := p_paymentTab(i).inv_payee_city;
7190 paymentTab.inv_payee_postal_code(i)
7191              := p_paymentTab(i).inv_payee_postal_code;
7192 paymentTab.inv_payee_state(i)
7193              := p_paymentTab(i).inv_payee_state;
7194 paymentTab.inv_payee_province(i)
7195              := p_paymentTab(i).inv_payee_province;
7196 paymentTab.inv_payee_county(i)
7197              := p_paymentTab(i).inv_payee_county;
7198 paymentTab.inv_payee_country(i)
7199              := p_paymentTab(i).inv_payee_country;
7200 paymentTab.inv_payee_party_name(i)
7201              := p_paymentTab(i).inv_payee_party_name;
7202 paymentTab.inv_payee_le_reg_num(i)
7203              := p_paymentTab(i).inv_payee_le_reg_num;
7204 paymentTab.inv_payee_tax_reg_num(i)
7205              := p_paymentTab(i).inv_payee_tax_reg_num;
7206 paymentTab.inv_payee_address_concat(i)
7207              := p_paymentTab(i).inv_payee_address_concat;
7208 paymentTab.inv_beneficiary_name(i)
7209              := p_paymentTab(i).inv_beneficiary_name;
7210 paymentTab.inv_payee_party_number(i)
7211              := p_paymentTab(i).inv_payee_party_number;
7212 paymentTab.inv_payee_alternate_name(i)
7213              := p_paymentTab(i).inv_payee_alternate_name;
7214 paymentTab.inv_payee_site_alt_name(i)
7215              := p_paymentTab(i).inv_payee_site_alt_name;
7216 paymentTab.inv_payee_supplier_number(i)
7217              := p_paymentTab(i).inv_payee_supplier_number;
7218 paymentTab.inv_payee_first_party_ref(i)
7219              := p_paymentTab(i).inv_payee_first_party_ref;
7220 paymentTab.ext_bnk_acct_ownr_inv_prty_id(i)
7221              := p_paymentTab(i).ext_bnk_acct_ownr_inv_prty_id;
7222 paymentTab.ext_bnk_branch_inv_prty_id(i)
7223              := p_paymentTab(i).ext_bnk_branch_inv_prty_id;
7224 paymentTab.ext_bnk_acct_ownr_inv_prty_nme(i)
7225              := p_paymentTab(i).ext_bnk_acct_ownr_inv_prty_nme;
7226 paymentTab.inv_payee_party_attr_cat(i)
7227              := p_paymentTab(i).inv_payee_party_attr_cat;
7228 paymentTab.inv_payee_supplier_attr_cat(i)
7229              := p_paymentTab(i).inv_payee_supplier_attr_cat;
7230 paymentTab.inv_payee_spplr_site_attr_cat(i)
7231              := p_paymentTab(i).inv_payee_spplr_site_attr_cat;
7232 paymentTab.inv_payee_supplier_site_name(i)
7233              := p_paymentTab(i).inv_payee_supplier_site_name;
7234 paymenttab.inv_payee_spplr_site_alt_name(i)
7235              := p_paymenttab(i).inv_payee_spplr_site_alt_name;
7236 paymenttab.inv_payee_supplier_id(i)
7237              := p_paymenttab(i).inv_payee_supplier_id;
7238 
7239 
7240        IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7241 	 print_debuginfo(l_module_name, 'for loop value of i::'||i);
7242 
7243        END IF;
7244 
7245 	 l_tax_registration_num(i) := NULL;
7246           --Bug 7215055
7247 	  IF p_paymentTab(i).supplier_site_id IS NOT NULL
7248 	  THEN
7249 	    BEGIN
7250               SELECT vat_registration_num
7251               INTO l_tax_registration_num(i)
7252               FROM ap_supplier_sites_all
7253               WHERE vendor_site_id = p_paymentTab(i).supplier_site_id;
7254 
7255 	    EXCEPTION
7256 	      WHEN NO_DATA_FOUND
7257 		THEN
7258 		 BEGIN
7259                   SELECT asup.vat_registration_num
7260                   INTO l_tax_registration_num(i)
7261                   FROM ap_suppliers asup
7262 	          ,    ap_supplier_sites_all asups
7263                   WHERE asups.vendor_site_id = p_paymentTab(i).supplier_site_id
7264 	          AND   asup.vendor_id = asups.vendor_id;
7265 		 EXCEPTION
7266 		   WHEN OTHERS THEN
7267                    l_tax_registration_num(i) := NULL;
7268 		   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7269 			 print_debuginfo(l_module_name, 'VAT_EXCEPTION::'||sqlerrm);
7270                   END IF;
7271 		 END;
7272 	      WHEN OTHERS THEN
7273                 l_tax_registration_num(i) := NULL;
7274 		       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7275 			 print_debuginfo(l_module_name, 'VAT_EXCEPTION::'||sqlerrm);
7276 	               END IF;
7277 	    END;
7278 	  END IF;
7279 
7280      END LOOP;
7281 
7282 
7283      /*
7284       * Bulk insert into IBY_PAYMENTS_ALL table using the
7285       * named columns syntax. This avoids any dependencies on
7286       * column order.
7287       */
7288      FORALL i in nvl(paymentTab.payment_id.FIRST,0) .. nvl(paymentTab.payment_id.LAST,-99)
7289      INSERT INTO IBY_PAYMENTS_ALL
7290              (
7291              payment_id,
7292              payment_method_code,
7293              payment_service_request_id,
7294              process_type,
7295              payment_status,
7296              payments_complete_flag,
7297              payment_function,
7298              payment_amount,
7299              payment_currency_code,
7300              bill_payable_flag,
7301              exclusive_payment_flag,
7302              separate_remit_advice_req_flag,
7303              internal_bank_account_id,
7304              org_id,
7305              org_type,
7306              legal_entity_id,
7307              declare_payment_flag,
7308              delivery_channel_code,
7309              ext_payee_id,
7310              payment_instruction_id,
7311              payment_profile_id,
7312              pregrouped_payment_flag,
7313              stop_confirmed_flag,
7314              stop_released_flag,
7315              stop_request_placed_flag,
7316              created_by,
7317              creation_date,
7318              last_updated_by,
7319              last_update_login,
7320              last_update_date,
7321              object_version_number,
7322              payee_party_id,
7323              party_site_id,
7324              supplier_site_id,
7325              payment_reason_code,
7326              payment_reason_comments,
7327              payment_date,
7328              anticipated_value_date,
7329              declaration_amount,
7330              declaration_currency_code,
7331              discount_amount_taken,
7332              payment_details,
7333              bank_charge_bearer,
7334              bank_charge_amount,
7335              settlement_priority,
7336              remittance_message1,
7337              remittance_message2,
7338              remittance_message3,
7339              payment_reference_number,
7340              paper_document_number,
7341              bank_assigned_ref_code,
7342              external_bank_account_id,
7343              unique_remittance_identifier,
7344              uri_check_digit,
7345              bank_instruction1_code,
7346              bank_instruction2_code,
7347              bank_instruction_details,
7348              payment_text_message1,
7349              payment_text_message2,
7350              payment_text_message3,
7351              maturity_date,
7352              payment_due_date,
7353              document_category_code,
7354              document_sequence_id,
7355              document_sequence_value,
7356              beneficiary_party,
7357              stop_confirmed_by,
7358              stop_confirm_date,
7359              stop_confirm_reason,
7360              stop_confirm_reference,
7361              stop_released_by,
7362              stop_release_date,
7363              stop_release_reason,
7364              stop_release_reference,
7365              stop_request_date,
7366              stop_request_placed_by,
7367              stop_request_reason,
7368              stop_request_reference,
7369              voided_by,
7370              void_date,
7371              void_reason,
7372              remit_to_location_id,
7373              completed_pmts_group_id,
7374              attribute_category,
7375              attribute1,
7376              attribute2,
7377              attribute3,
7378              attribute4,
7379              attribute5,
7380              attribute6,
7381              attribute7,
7382              attribute8,
7383              attribute9,
7384              attribute10,
7385              attribute11,
7386              attribute12,
7387              attribute13,
7388              attribute14,
7389              attribute15,
7390              ext_branch_number,
7391              ext_bank_number,
7392              ext_bank_account_name,
7393              ext_bank_account_number,
7394              ext_bank_account_type,
7395              ext_bank_account_iban_number,
7396              payee_name,
7397              payee_address1,
7398              payee_address2,
7399              payee_address3,
7400              payee_address4,
7401              payee_city,
7402              payee_postal_code,
7403              payee_state,
7404              payee_province,
7405              payee_county,
7406              payee_country,
7407              remit_advice_delivery_method,
7408              remit_advice_email,
7409              remit_advice_fax,
7410              address_source,
7411              employee_address_code,
7412              employee_person_id,
7413              employee_address_id,
7414              employee_payment_flag,
7415 	     payee_tax_registration_num,
7416 		ext_inv_payee_id ,
7417 		inv_payee_party_id ,
7418 		inv_party_site_id ,
7419 		inv_supplier_site_id ,
7420 		inv_beneficiary_party ,
7421 		inv_payee_name ,
7422 		inv_payee_address1 ,
7423 		inv_payee_address2 ,
7424 		inv_payee_address3 ,
7425 		inv_payee_address4 ,
7426 		inv_payee_city ,
7427 		inv_payee_postal_code ,
7428 		inv_payee_state ,
7429 		inv_payee_province ,
7430 		inv_payee_county ,
7431 		inv_payee_country ,
7432 		inv_payee_party_name ,
7433 		inv_payee_le_reg_num,
7434 		inv_payee_tax_reg_num,
7435 		inv_payee_address_concat ,
7436 		inv_beneficiary_name ,
7437 		inv_payee_party_number ,
7438 		inv_payee_alternate_name ,
7439 		inv_payee_site_alt_name,
7440 		inv_payee_supplier_number ,
7441 		inv_payee_first_party_ref,
7442 		ext_bnk_acct_ownr_inv_prty_id,
7443 		ext_bnk_branch_inv_prty_id,
7444 		ext_bnk_acct_ownr_inv_prty_nme,
7445 		inv_payee_party_attr_cat,
7446 		inv_payee_supplier_attr_cat,
7447 		inv_payee_spplr_site_attr_cat,
7448 		inv_payee_supplier_site_name ,
7449 		inv_payee_spplr_site_alt_name,
7450 		inv_payee_supplier_id
7451              )
7452          VALUES
7453              (
7454              paymentTab.payment_id(i),
7455              paymentTab.payment_method_code(i),
7456              paymentTab.payment_service_request_id(i),
7457              paymentTab.process_type(i),
7458              paymentTab.payment_status(i),
7459              paymentTab.payments_complete_flag(i),
7460              paymentTab.payment_function(i),
7461              paymentTab.payment_amount(i),
7462              paymentTab.payment_currency_code(i),
7463              paymentTab.bill_payable_flag(i),
7464              paymentTab.exclusive_payment_flag(i),
7465              paymentTab.sep_remit_advice_req_flag(i),
7466              paymentTab.internal_bank_account_id(i),
7467              paymentTab.org_id(i),
7468              paymentTab.org_type(i),
7469              paymentTab.legal_entity_id(i),
7470              paymentTab.declare_payment_flag(i),
7471              paymentTab.delivery_channel_code(i),
7472              paymentTab.ext_payee_id(i),
7473              paymentTab.payment_instruction_id(i),
7474              paymentTab.payment_profile_id(i),
7475              paymentTab.pregrouped_payment_flag(i),
7476              paymentTab.stop_confirmed_flag(i),
7477              paymentTab.stop_released_flag(i),
7478              paymentTab.stop_request_placed_flag(i),
7479              paymentTab.created_by(i),
7480              paymentTab.creation_date(i),
7481              paymentTab.last_updated_by(i),
7482              paymentTab.last_update_login(i),
7483              paymentTab.last_update_date(i),
7484              paymentTab.object_version_number(i),
7485              paymentTab.payee_party_id(i),
7486              paymentTab.party_site_id(i),
7487              paymentTab.supplier_site_id(i),
7488              paymentTab.payment_reason_code(i),
7489              paymentTab.payment_reason_comments(i),
7490              paymentTab.payment_date(i),
7491              paymentTab.anticipated_value_date(i),
7492              paymentTab.declaration_amount(i),
7493              paymentTab.declaration_currency_code(i),
7494              paymentTab.discount_amount_taken(i),
7495              paymentTab.payment_details(i),
7496              paymentTab.bank_charge_bearer(i),
7497              paymentTab.bank_charge_amount(i),
7498              paymentTab.settlement_priority(i),
7499              paymentTab.remittance_message1(i),
7500              paymentTab.remittance_message2(i),
7501              paymentTab.remittance_message3(i),
7502              paymentTab.payment_reference_number(i),
7503              paymentTab.paper_document_number(i),
7504              paymentTab.bank_assigned_ref_code(i),
7505              paymentTab.external_bank_account_id(i),
7506              paymentTab.unique_remittance_identifier(i),
7507              paymentTab.uri_check_digit(i),
7508              paymentTab.bank_instruction1_code(i),
7509              paymentTab.bank_instruction2_code(i),
7510              paymentTab.bank_instruction_details(i),
7511              paymentTab.payment_text_message1(i),
7512              paymentTab.payment_text_message2(i),
7513              paymentTab.payment_text_message3(i),
7514              paymentTab.maturity_date(i),
7515              paymentTab.payment_due_date(i),
7516              paymentTab.document_category_code(i),
7517              paymentTab.document_sequence_id(i),
7518              paymentTab.document_sequence_value(i),
7519              paymentTab.beneficiary_party(i),
7520              paymentTab.stop_confirmed_by(i),
7521              paymentTab.stop_confirm_date(i),
7522              paymentTab.stop_confirm_reason(i),
7523              paymentTab.stop_confirm_reference(i),
7524              paymentTab.stop_released_by(i),
7525              paymentTab.stop_release_date(i),
7526              paymentTab.stop_release_reason(i),
7527              paymentTab.stop_release_reference(i),
7528              paymentTab.stop_request_date(i),
7529              paymentTab.stop_request_placed_by(i),
7530              paymentTab.stop_request_reason(i),
7531              paymentTab.stop_request_reference(i),
7532              paymentTab.voided_by(i),
7533              paymentTab.void_date(i),
7534              paymentTab.void_reason(i),
7535              paymentTab.remit_to_location_id(i),
7536              paymentTab.completed_pmts_group_id(i),
7537              paymentTab.attribute_category(i),
7538              paymentTab.attribute1(i),
7539              paymentTab.attribute2(i),
7540              paymentTab.attribute3(i),
7541              paymentTab.attribute4(i),
7542              paymentTab.attribute5(i),
7543              paymentTab.attribute6(i),
7544              paymentTab.attribute7(i),
7545              paymentTab.attribute8(i),
7546              paymentTab.attribute9(i),
7547              paymentTab.attribute10(i),
7548              paymentTab.attribute11(i),
7549              paymentTab.attribute12(i),
7550              paymentTab.attribute13(i),
7551              paymentTab.attribute14(i),
7552              paymentTab.attribute15(i),
7553              paymentTab.ext_branch_number(i),
7554              paymentTab.ext_bank_number(i),
7555              paymentTab.ext_bank_account_name(i),
7556              paymentTab.ext_bank_account_number(i),
7557              paymentTab.ext_bank_account_type(i),
7558              paymentTab.ext_bank_account_iban_number(i),
7559              paymentTab.payee_name(i),
7560              paymentTab.payee_address1(i),
7561              paymentTab.payee_address2(i),
7562              paymentTab.payee_address3(i),
7563              paymentTab.payee_address4(i),
7564              paymentTab.payee_city(i),
7565              paymentTab.payee_postal_code(i),
7566              paymentTab.payee_state(i),
7567              paymentTab.payee_province(i),
7568              paymentTab.payee_county(i),
7569              paymentTab.payee_country(i),
7570              paymentTab.remit_advice_delivery_method(i),
7571              paymentTab.remit_advice_email(i),
7572              paymentTab.remit_advice_fax(i),
7573              paymentTab.address_source(i),
7574              paymentTab.employee_address_code(i),
7575              paymentTab.employee_person_id(i),
7576              paymentTab.employee_address_id(i),
7577              paymentTab.employee_payment_flag(i),
7578 	     l_tax_registration_num(i),
7579 paymentTab.ext_inv_payee_id(i),
7580 paymentTab.inv_payee_party_id(i),
7581 paymentTab.inv_party_site_id(i),
7582 paymentTab.inv_supplier_site_id(i),
7583 paymentTab.inv_beneficiary_party(i),
7584 paymentTab.inv_payee_name(i),
7585 paymentTab.inv_payee_address1(i),
7586 paymentTab.inv_payee_address2(i),
7587 paymentTab.inv_payee_address3(i),
7588 paymentTab.inv_payee_address4(i),
7589 paymentTab.inv_payee_city(i),
7590 paymentTab.inv_payee_postal_code(i),
7591 paymentTab.inv_payee_state(i),
7592 paymentTab.inv_payee_province(i),
7593 paymentTab.inv_payee_county(i),
7594 paymentTab.inv_payee_country(i),
7595 paymentTab.inv_payee_party_name(i),
7596 paymentTab.inv_payee_le_reg_num(i),
7597 paymentTab.inv_payee_tax_reg_num(i),
7598 paymentTab.inv_payee_address_concat(i),
7599 paymentTab.inv_beneficiary_name(i),
7600 paymentTab.inv_payee_party_number(i),
7601 paymentTab.inv_payee_alternate_name(i),
7602 paymentTab.inv_payee_site_alt_name(i),
7603 paymentTab.inv_payee_supplier_number(i),
7604 paymentTab.inv_payee_first_party_ref(i),
7605 paymentTab.ext_bnk_acct_ownr_inv_prty_id(i),
7606 paymentTab.ext_bnk_branch_inv_prty_id(i),
7607 paymentTab.ext_bnk_acct_ownr_inv_prty_nme(i),
7608 paymentTab.inv_payee_party_attr_cat(i),
7609 paymentTab.inv_payee_supplier_attr_cat(i),
7610 paymentTab.inv_payee_spplr_site_attr_cat(i),
7611 paymentTab.inv_payee_supplier_site_name(i),
7612 paymenttab.inv_payee_spplr_site_alt_name(i),
7613 paymenttab.inv_payee_supplier_id(i)
7614 
7615              );
7616 
7617              delete_paymentTab;
7618 
7619      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7620 	 print_debuginfo(l_module_name, 'EXIT');
7621      END IF;
7622  END insertPayments;
7623 
7624 
7625 
7626 
7627 /*--------------------------------------------------------------------
7628  | NAME:
7629  |     insertPayments
7630  |
7631  | PURPOSE:
7632  |     Performs a bulk insert of all created payments from PLSQL
7633  |     table into IBY_PAYMENTS_ALL table.
7634  |
7635  | PARAMETERS:
7636  |     IN
7637  |
7638  |
7639  |     OUT
7640  |
7641  |
7642  | RETURNS:
7643  |
7644  | NOTES:
7645  |
7646  *---------------------------------------------------------------------*/
7647   PROCEDURE insertPayments
7648  IS
7649  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.insertPayments';
7650  TYPE tax_regis_num IS TABLE OF iby_payments_all.payee_tax_registration_num%TYPE INDEX BY BINARY_INTEGER;
7651  l_tax_registration_num tax_regis_num;
7652 
7653 /* CHANGE FOR BUG : 14348326 - START */
7654 errors                     NUMBER;
7655 ERR_IND                    NUMBER;
7656 ERR_CODE                   VARCHAR2(100);
7657 dml_errors                 EXCEPTION;
7658 PRAGMA exception_init(dml_errors, -24381);
7659 /* CHANGE FOR BUG : 14348326 - END */
7660  BEGIN
7661 
7662      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7663  print_debuginfo(l_module_name, 'ENTER');
7664       END IF;
7665 
7666      /* Normally, this shouldn't happen */
7667     /*
7668     IF (p_paymentTab.COUNT = 0) THEN
7669          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7670  print_debuginfo(l_module_name, 'After grouping, no payments'
7671              || ' were found to insert into IBY_PAYMENTS_ALL table.'
7672              || ' Possible data corruption issue.');
7673 
7674          END IF;
7675          RETURN;
7676      END IF;
7677      */
7678 
7679 
7680      /*
7681       * Copy values for each column into its corresponding column
7682       * array. These column arrays will be used in the bulk insert.
7683       */
7684     /* Removing the code to copy data into paymentTab, as we
7685      * already have record of table to directly copy into
7686      * IBY_PAYMENTS_ALL table */
7687 
7688 
7689 
7690      /*
7691       * Bulk insert into IBY_PAYMENTS_ALL table using the
7692       * named columns syntax. This avoids any dependencies on
7693       * column order.
7694       */
7695      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
7696          FOR i in nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99) LOOP
7697 
7698                 /*
7699                  print_debuginfo(l_module_name, IBY_PAYGROUP_PUB.pmtTable.payment_id(i));
7700                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_method_code(i));
7701                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(i));
7702                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.process_type(i));
7703                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_status(i));
7704                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(i));
7705                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_function(i));
7706                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_amount(i));
7707                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(i));
7708                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(i));
7709                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(i));
7710                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(i));
7711                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(i));
7712                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.org_id(i));
7713                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.org_type(i));
7714                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(i));
7715                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(i));
7716                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(i));
7717                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i));
7718                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(i));
7719                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(i));
7720                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(i));
7721                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(i));
7722                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(i));
7723                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(i));
7724                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.created_by(i));
7725                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.creation_date(i));
7726                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.last_updated_by(i));
7727                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.last_update_login(i));
7728                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.last_update_date(i));
7729                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.object_version_number(i));
7730                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_party_id(i));
7731                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.party_site_id(i));
7732                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(i));
7733                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(i));
7734                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(i));
7735                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_date(i));
7736                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(i));
7737                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.declaration_amount(i));
7738                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(i));
7739                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(i));
7740                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_details(i));
7741                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(i));
7742                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(i));
7743                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.settlement_priority(i));
7744                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remittance_message1(i));
7745                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remittance_message2(i));
7746                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remittance_message3(i));
7747                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(i));
7748                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.paper_document_number(i));
7749                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(i));
7750                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(i));
7751                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(i));
7752                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(i));
7753                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(i));
7754                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(i));
7755                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(i));
7756                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(i));
7757                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(i));
7758                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(i));
7759                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.maturity_date(i));
7760                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_due_date(i));
7761                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.document_category_code(i));
7762                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(i));
7763                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(i));
7764                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(i));
7765                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(i));
7766                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(i));
7767                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(i));
7768                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(i));
7769                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_released_by(i));
7770                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_release_date(i));
7771                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(i));
7772                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i));
7773                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_request_date(i));
7774                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by(i));
7775                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_request_reason(i));
7776                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.stop_request_reference(i));
7777                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.voided_by(i));
7778                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.void_date(i));
7779                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.void_reason(i));
7780                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(i));
7781                 print_debuginfo(l_module_name, IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(i));
7782                  print_debuginfo(l_module_name,'7083'||IBY_PAYGROUP_PUB.pmtTable.attribute_category(i));
7783                  print_debuginfo(l_module_name,'7084'||IBY_PAYGROUP_PUB.pmtTable.attribute1(i));
7784                  print_debuginfo(l_module_name,'7085'||IBY_PAYGROUP_PUB.pmtTable.attribute2(i));
7785                  print_debuginfo(l_module_name,'7086'||IBY_PAYGROUP_PUB.pmtTable.attribute3(i));
7786                  print_debuginfo(l_module_name,'7087'||IBY_PAYGROUP_PUB.pmtTable.attribute4(i));
7787                  print_debuginfo(l_module_name,'7088'||IBY_PAYGROUP_PUB.pmtTable.attribute5(i));
7788                  print_debuginfo(l_module_name,'7089'||IBY_PAYGROUP_PUB.pmtTable.attribute6(i));
7789                  print_debuginfo(l_module_name,'7090'||IBY_PAYGROUP_PUB.pmtTable.attribute7(i));
7790                  print_debuginfo(l_module_name,'7091'||IBY_PAYGROUP_PUB.pmtTable.attribute8(i));
7791                  print_debuginfo(l_module_name,'7092'||IBY_PAYGROUP_PUB.pmtTable.attribute9(i));
7792                  print_debuginfo(l_module_name,'7093'||IBY_PAYGROUP_PUB.pmtTable.attribute10(i));
7793                  print_debuginfo(l_module_name,'7094'||IBY_PAYGROUP_PUB.pmtTable.attribute11(i));
7794                  print_debuginfo(l_module_name,'7095'||IBY_PAYGROUP_PUB.pmtTable.attribute12(i));
7795                  print_debuginfo(l_module_name,'7096'||IBY_PAYGROUP_PUB.pmtTable.attribute13(i));
7796                  print_debuginfo(l_module_name,'7097'||IBY_PAYGROUP_PUB.pmtTable.attribute14(i));
7797                  print_debuginfo(l_module_name,'7098'||IBY_PAYGROUP_PUB.pmtTable.attribute15(i));
7798 
7799 
7800                  print_debuginfo(l_module_name,'7103'||IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(i));
7801                  print_debuginfo(l_module_name,'7104'||IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(i));
7802                  print_debuginfo(l_module_name,'7105'||IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(i));
7803                  print_debuginfo(l_module_name,'7106'||IBY_PAYGROUP_PUB.pmtTable.payee_name(i));
7804                  print_debuginfo(l_module_name,'7107'||IBY_PAYGROUP_PUB.pmtTable.payee_address1(i));
7805                  print_debuginfo(l_module_name,'7108'||IBY_PAYGROUP_PUB.pmtTable.payee_address2(i));
7806                  print_debuginfo(l_module_name,'7109'||IBY_PAYGROUP_PUB.pmtTable.payee_address3(i));
7807                  print_debuginfo(l_module_name,'7110'||IBY_PAYGROUP_PUB.pmtTable.payee_address4(i));
7808                  print_debuginfo(l_module_name,'7111'||IBY_PAYGROUP_PUB.pmtTable.payee_city(i));
7809                  print_debuginfo(l_module_name,'7112'||IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(i));
7810                  print_debuginfo(l_module_name,'7113'||IBY_PAYGROUP_PUB.pmtTable.payee_state(i));
7811                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_province(i));
7812                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_county(i));
7813                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_country(i));
7814                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(i));
7815                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(i));
7816                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(i));
7817                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.address_source(i));
7818                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.employee_address_code(i));
7819                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.employee_person_id(i));
7820                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.employee_address_id(i));
7821                  print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(i));
7822                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(i));
7823                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(i));
7824                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(i));
7825                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(i));
7826                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_name(i));
7827                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_address1(i));
7828                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_address2(i));
7829                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_address3(i));
7830                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_address4(i));
7831                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_city(i));
7832                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_postal_code(i));
7833                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_state(i));
7834                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_province(i));
7835                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_county(i));
7836                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_country(i));
7837                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_name(i));
7838                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_le_reg_num(i));
7839                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_tax_reg_num(i));
7840                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_address_concat(i));
7841                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_name(i));
7842                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_number(i));
7843                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_alternate_name(i));
7844                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_site_alt_name(i));
7845                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_number(i));
7846                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(i));
7847                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_id(i));
7848                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bnk_branch_inv_prty_id(i));
7849                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_nme(i));
7850                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_attr_cat(i));
7851                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_attr_cat(i));
7852                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_attr_cat(i));
7853                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_site_name(i));
7854                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_alt_name(i));
7855                     print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_id(i));*/
7856             print_debuginfo(l_module_name, IBY_PAYGROUP_PUB.pmtTable.payment_id(i));
7857             print_debuginfo(l_module_name,'InvPayeePartyId is '||IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(i));
7858             print_debuginfo(l_module_name,'11672'||IBY_PAYGROUP_PUB.pmtTable.payer_party_number(i));
7859             print_debuginfo(l_module_name,'11673'||IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(i));
7860             print_debuginfo(l_module_name,'11674'||IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(i));
7861             print_debuginfo(l_module_name,'11675'||IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(i));
7862             print_debuginfo(l_module_name,'11676'||IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(i));
7863             print_debuginfo(l_module_name,'11677'||IBY_PAYGROUP_PUB.pmtTable.payer_party_id(i));
7864             print_debuginfo(l_module_name,'11678'||IBY_PAYGROUP_PUB.pmtTable.payer_location_id(i));
7865             print_debuginfo(l_module_name,'11679'||IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(i));
7866             print_debuginfo(l_module_name,'11680'||IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(i));
7867             print_debuginfo(l_module_name,'11681'||IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(i));
7868             print_debuginfo(l_module_name,'11682'||IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(i));
7869             print_debuginfo(l_module_name,'11683'||IBY_PAYGROUP_PUB.pmtTable.int_bank_name(i));
7870             print_debuginfo(l_module_name,'11684'||IBY_PAYGROUP_PUB.pmtTable.int_bank_number(i));
7871             print_debuginfo(l_module_name,'11685'||IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(i));
7872             print_debuginfo(l_module_name,'11686'||IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(i));
7873             print_debuginfo(l_module_name,'11687'||IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(i));
7874             print_debuginfo(l_module_name,'11688'||IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(i));
7875             print_debuginfo(l_module_name,'11689'||IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(i));
7876             print_debuginfo(l_module_name,'11690'||IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(i));
7877             print_debuginfo(l_module_name,'11691'||IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(i));
7878             print_debuginfo(l_module_name,'11692'||IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(i));
7879             print_debuginfo(l_module_name,'11693'||IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(i));
7880             print_debuginfo(l_module_name,'11694'||IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(i));
7881             print_debuginfo(l_module_name,'11695'||IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(i));
7882             print_debuginfo(l_module_name,'11696'||IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(i));
7883             print_debuginfo(l_module_name,'11697'||IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(i));
7884             print_debuginfo(l_module_name,'11698'||IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(i));
7885             print_debuginfo(l_module_name,'11699'||IBY_PAYGROUP_PUB.pmtTable.payee_party_number(i));
7886             print_debuginfo(l_module_name,'11700'||IBY_PAYGROUP_PUB.pmtTable.payee_party_name(i));
7887             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(i)); -- Bug 6175102
7888             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(i));
7889             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(i));
7890             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(i));
7891             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(i));
7892             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(i));
7893             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(i));
7894             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_addressee(i));
7895             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(i));
7896             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(i));
7897             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(i));
7898             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(i));
7899             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(i));
7900             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(i));
7901             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(i));
7902             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(i));
7903             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(i));
7904             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(i));
7905             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(i));
7906             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(i));
7907             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(i));
7908             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(i));
7909             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(i));
7910             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(i));
7911             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(i));
7912             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(i));
7913             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(i));
7914             --print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(i));
7915             --print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(i));
7916             --print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(i));
7917             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(i));
7918             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(i));
7919             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.declaration_format(i));
7920             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(i));
7921             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(i));
7922             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(i));
7923             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(i));
7924             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(i));
7925             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.org_name(i));
7926             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(i));
7927             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(i));
7928             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.source_product(i));
7929             print_debuginfo(l_module_name,IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(i));  --AWT Enh 16296267
7930 
7931          END LOOP;
7932      END IF;
7933      /* CHANGE FOR BUG : 14348326 - START */
7934      FORALL i in nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99) SAVE EXCEPTIONS
7935       /* CHANGE FOR BUG : 14348326 - END */
7936      INSERT INTO IBY_PAYMENTS_ALL
7937              (
7938              payment_id,
7939              payment_method_code,
7940              payment_service_request_id,
7941              process_type,
7942              payment_status,
7943              payments_complete_flag,
7944              payment_function,
7945              payment_amount,
7946              payment_currency_code,
7947              bill_payable_flag,
7948              exclusive_payment_flag,
7949              separate_remit_advice_req_flag,
7950              internal_bank_account_id,
7951              org_id,
7952              org_type,
7953              legal_entity_id,
7954              declare_payment_flag,
7955              delivery_channel_code,
7956              ext_payee_id,
7957              payment_instruction_id,
7958              payment_profile_id,
7959              pregrouped_payment_flag,
7960              stop_confirmed_flag,
7961              stop_released_flag,
7962              stop_request_placed_flag,
7963              created_by,
7964              creation_date,
7965              last_updated_by,
7966              last_update_login,
7967              last_update_date,
7968              object_version_number,
7969              payee_party_id,
7970              party_site_id,
7971              supplier_site_id,
7972              payment_reason_code,
7973              payment_reason_comments,
7974              payment_date,
7975              anticipated_value_date,
7976              declaration_amount,
7977              declaration_currency_code,
7978              discount_amount_taken,
7979              payment_details,
7980              bank_charge_bearer,
7981              bank_charge_amount,
7982              settlement_priority,
7983              remittance_message1,
7984              remittance_message2,
7985              remittance_message3,
7986              payment_reference_number,
7987              paper_document_number,
7988              bank_assigned_ref_code,
7989              external_bank_account_id,
7990              unique_remittance_identifier,
7991              uri_check_digit,
7992              bank_instruction1_code,
7993              bank_instruction2_code,
7994              bank_instruction_details,
7995              payment_text_message1,
7996              payment_text_message2,
7997              payment_text_message3,
7998              maturity_date,
7999              payment_due_date,
8000              document_category_code,
8001              document_sequence_id,
8002              document_sequence_value,
8003              beneficiary_party,
8004              stop_confirmed_by,
8005              stop_confirm_date,
8006              stop_confirm_reason,
8007              stop_confirm_reference,
8008              stop_released_by,
8009              stop_release_date,
8010              stop_release_reason,
8011              stop_release_reference,
8012              stop_request_date,
8013              stop_request_placed_by,
8014              stop_request_reason,
8015              stop_request_reference,
8016              voided_by,
8017              void_date,
8018              void_reason,
8019              remit_to_location_id,
8020              completed_pmts_group_id,
8021              attribute_category,
8022              attribute1,
8023              attribute2,
8024              attribute3,
8025              attribute4,
8026              attribute5,
8027              attribute6,
8028              attribute7,
8029              attribute8,
8030              attribute9,
8031              attribute10,
8032              attribute11,
8033              attribute12,
8034              attribute13,
8035              attribute14,
8036              attribute15,
8037              ext_branch_number,
8038              ext_bank_number,
8039              ext_bank_account_name,
8040              ext_bank_account_number,
8041              ext_bank_account_type,
8042              ext_bank_account_iban_number,
8043              payee_name,
8044              payee_address1,
8045              payee_address2,
8046              payee_address3,
8047              payee_address4,
8048              payee_city,
8049              payee_postal_code,
8050              payee_state,
8051              payee_province,
8052              payee_county,
8053              payee_country,
8054              remit_advice_delivery_method,
8055              remit_advice_email,
8056              remit_advice_fax,
8057              address_source,
8058              employee_address_code,
8059              employee_person_id,
8060              employee_address_id,
8061              employee_payment_flag,
8062 		ext_inv_payee_id ,
8063 		inv_payee_party_id ,
8064 		inv_party_site_id ,
8065 		inv_supplier_site_id ,
8066 		inv_beneficiary_party ,
8067 		inv_payee_name ,
8068 		inv_payee_address1 ,
8069 		inv_payee_address2 ,
8070 		inv_payee_address3 ,
8071 		inv_payee_address4 ,
8072 		inv_payee_city ,
8073 		inv_payee_postal_code ,
8074 		inv_payee_state ,
8075 		inv_payee_province ,
8076 		inv_payee_county ,
8077 		inv_payee_country ,
8078 		inv_payee_party_name ,
8079 		inv_payee_le_reg_num,
8080 		inv_payee_tax_reg_num,
8081 		inv_payee_address_concat ,
8082 		inv_beneficiary_name ,
8083 		inv_payee_party_number ,
8084 		inv_payee_alternate_name ,
8085 		inv_payee_site_alt_name,
8086 		inv_payee_supplier_number ,
8087 		inv_payee_first_party_ref,
8088 		ext_bnk_acct_ownr_inv_prty_id,
8089 		ext_bnk_branch_inv_prty_id,
8090 		ext_bnk_acct_ownr_inv_prty_nme,
8091 		inv_payee_party_attr_cat,
8092 		inv_payee_supplier_attr_cat,
8093 		inv_payee_spplr_site_attr_cat,
8094 		inv_payee_supplier_site_name ,
8095 		inv_payee_spplr_site_alt_name,
8096 		inv_payee_supplier_id,
8097              payer_party_number             	,
8098              payer_party_site_name          	,
8099              payer_legal_entity_name        	,
8100              payer_tax_registration_num     	,
8101              payer_le_registration_num      	,
8102              payer_party_id                 	,
8103              payer_location_id              	,
8104              payer_party_attr_category      	,
8105              payer_le_attr_category         	,
8106              payer_abbreviated_agency_code  	,
8107              payer_federal_us_employer_id   	,
8108              int_bank_name                  	,
8109              int_bank_number                	,
8110              int_bank_branch_number         	,
8111              int_bank_branch_name           	,
8112              int_eft_swift_code             	,
8113              int_bank_account_number        	,
8114              int_bank_account_name          	,
8115              int_bank_account_iban          	,
8116              int_bank_acct_agency_loc_code  	,
8117              int_bank_branch_party_id       	,
8118              int_bank_alt_name              	,
8119              int_bank_branch_alt_name       	,
8120              int_bank_account_alt_name      	,
8121              int_bank_account_num_elec      	,
8122              int_bank_branch_location_id    	,
8123              int_bank_branch_eft_user_num   	,
8124              payee_party_number             	,
8125              payee_party_name               	,
8126              payee_alternate_name           	,
8127              payee_address_concat           	,
8128              beneficiary_name               	,
8129              payee_party_attr_category      	,
8130              payee_spplr_site_attr_category 	,
8131              payee_supplier_site_name       	,
8132              payee_party_site_name       	,
8133              payee_addressee                	,
8134              payee_site_alternate_name      	,
8135              payee_supplier_number          	,
8136              payee_first_party_reference    	,
8137              payee_supplier_attr_category   	,
8138              payee_supplier_id              	,
8139              payee_tax_registration_num ,
8140              payee_le_registration_num  ,
8141              ext_bank_name,
8142               ext_bank_branch_name           	,
8143               ext_eft_swift_code             	,
8144               ext_bank_acct_pmt_factor_flag  	,
8145               ext_bank_acct_owner_party_id   	,
8146               ext_bank_branch_party_id       	,
8147               ext_bank_alt_name              	,
8148               ext_bank_branch_alt_name       	,
8149               ext_bank_account_alt_name      	,
8150               ext_bank_account_num_elec      	,
8151              ext_bank_branch_location_id    	,
8152              ext_bank_acct_owner_party_name 	,
8153              --remit_advice_delivery_method   	,
8154              --remit_advice_email             	,
8155              --remit_advice_fax               	,
8156              delivery_channel_format_value  	,
8157              declaration_exch_rate_type     	,
8158              declaration_format             	,
8159              payment_profile_acct_name      	,
8160              payment_profile_sys_name       	,
8161              payment_reason_format_value    	,
8162              bank_instruction1_format_value 	,
8163              bank_instruction2_format_value 	,
8164              org_name                       	,
8165              int_bank_branch_rfc_identifier     ,
8166              payment_process_request_name       ,
8167              source_product                     ,
8168 			 affects_rejection_level -- AWT Enh 16296267
8169 
8170 	     )
8171          VALUES
8172              (
8173              IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
8174              IBY_PAYGROUP_PUB.pmtTable.payment_method_code(i),
8175              IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(i),
8176              IBY_PAYGROUP_PUB.pmtTable.process_type(i),
8177              IBY_PAYGROUP_PUB.pmtTable.payment_status(i),
8178              IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(i),
8179              IBY_PAYGROUP_PUB.pmtTable.payment_function(i),
8180              IBY_PAYGROUP_PUB.pmtTable.payment_amount(i),
8181              IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(i),
8182              IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(i),
8183              IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(i),
8184              IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(i),
8185              IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(i),
8186              IBY_PAYGROUP_PUB.pmtTable.org_id(i),
8187              IBY_PAYGROUP_PUB.pmtTable.org_type(i),
8188              IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(i),
8189              IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(i),
8190              IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(i),
8191              IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i),
8192              IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(i),
8193              IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(i),
8194              IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(i),
8195              IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(i),
8196              IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(i),
8197              IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(i),
8198              IBY_PAYGROUP_PUB.pmtTable.created_by(i),
8199              IBY_PAYGROUP_PUB.pmtTable.creation_date(i),
8200              IBY_PAYGROUP_PUB.pmtTable.last_updated_by(i),
8201              IBY_PAYGROUP_PUB.pmtTable.last_update_login(i),
8202              IBY_PAYGROUP_PUB.pmtTable.last_update_date(i),
8203              IBY_PAYGROUP_PUB.pmtTable.object_version_number(i),
8204              IBY_PAYGROUP_PUB.pmtTable.payee_party_id(i),
8205              IBY_PAYGROUP_PUB.pmtTable.party_site_id(i),
8206              IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(i),
8207              IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(i),
8208              IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(i),
8209              IBY_PAYGROUP_PUB.pmtTable.payment_date(i),
8210              IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(i),
8211              IBY_PAYGROUP_PUB.pmtTable.declaration_amount(i),
8212              IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(i),
8213              IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(i),
8214              IBY_PAYGROUP_PUB.pmtTable.payment_details(i),
8215              IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(i),
8216              IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(i),
8217              IBY_PAYGROUP_PUB.pmtTable.settlement_priority(i),
8218              IBY_PAYGROUP_PUB.pmtTable.remittance_message1(i),
8219              IBY_PAYGROUP_PUB.pmtTable.remittance_message2(i),
8220              IBY_PAYGROUP_PUB.pmtTable.remittance_message3(i),
8221              IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(i),
8222              IBY_PAYGROUP_PUB.pmtTable.paper_document_number(i),
8223              IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(i),
8224              IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(i),
8225              IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(i),
8226              IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(i),
8227              IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(i),
8228              IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(i),
8229              IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(i),
8230              IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(i),
8231              IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(i),
8232              IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(i),
8233              IBY_PAYGROUP_PUB.pmtTable.maturity_date(i),
8234              IBY_PAYGROUP_PUB.pmtTable.payment_due_date(i),
8235              IBY_PAYGROUP_PUB.pmtTable.document_category_code(i),
8236              IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(i),
8237              IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(i),
8238              IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(i),
8239              IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(i),
8240              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(i),
8241              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(i),
8242              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(i),
8243              IBY_PAYGROUP_PUB.pmtTable.stop_released_by(i),
8244              IBY_PAYGROUP_PUB.pmtTable.stop_release_date(i),
8245              IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(i),
8246              IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i),
8247              IBY_PAYGROUP_PUB.pmtTable.stop_request_date(i),
8248              IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by(i),
8249              IBY_PAYGROUP_PUB.pmtTable.stop_request_reason(i),
8250              IBY_PAYGROUP_PUB.pmtTable.stop_request_reference(i),
8251              IBY_PAYGROUP_PUB.pmtTable.voided_by(i),
8252              IBY_PAYGROUP_PUB.pmtTable.void_date(i),
8253              IBY_PAYGROUP_PUB.pmtTable.void_reason(i),
8254              IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(i),
8255              IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(i),
8256              IBY_PAYGROUP_PUB.pmtTable.attribute_category(i),
8257              IBY_PAYGROUP_PUB.pmtTable.attribute1(i),
8258              IBY_PAYGROUP_PUB.pmtTable.attribute2(i),
8259              IBY_PAYGROUP_PUB.pmtTable.attribute3(i),
8260              IBY_PAYGROUP_PUB.pmtTable.attribute4(i),
8261              IBY_PAYGROUP_PUB.pmtTable.attribute5(i),
8262              IBY_PAYGROUP_PUB.pmtTable.attribute6(i),
8263              IBY_PAYGROUP_PUB.pmtTable.attribute7(i),
8264              IBY_PAYGROUP_PUB.pmtTable.attribute8(i),
8265              IBY_PAYGROUP_PUB.pmtTable.attribute9(i),
8266              IBY_PAYGROUP_PUB.pmtTable.attribute10(i),
8267              IBY_PAYGROUP_PUB.pmtTable.attribute11(i),
8268              IBY_PAYGROUP_PUB.pmtTable.attribute12(i),
8269              IBY_PAYGROUP_PUB.pmtTable.attribute13(i),
8270              IBY_PAYGROUP_PUB.pmtTable.attribute14(i),
8271              IBY_PAYGROUP_PUB.pmtTable.attribute15(i),
8272              IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(i),
8273              IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(i),
8274              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(i),
8275              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(i),
8276              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(i),
8277              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(i),
8278              IBY_PAYGROUP_PUB.pmtTable.payee_name(i),
8279              IBY_PAYGROUP_PUB.pmtTable.payee_address1(i),
8280              IBY_PAYGROUP_PUB.pmtTable.payee_address2(i),
8281              IBY_PAYGROUP_PUB.pmtTable.payee_address3(i),
8282              IBY_PAYGROUP_PUB.pmtTable.payee_address4(i),
8283              IBY_PAYGROUP_PUB.pmtTable.payee_city(i),
8284              IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(i),
8285              IBY_PAYGROUP_PUB.pmtTable.payee_state(i),
8286              IBY_PAYGROUP_PUB.pmtTable.payee_province(i),
8287              IBY_PAYGROUP_PUB.pmtTable.payee_county(i),
8288              IBY_PAYGROUP_PUB.pmtTable.payee_country(i),
8289              IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(i),
8290              IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(i),
8291              IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(i),
8292              IBY_PAYGROUP_PUB.pmtTable.address_source(i),
8293              IBY_PAYGROUP_PUB.pmtTable.employee_address_code(i),
8294              IBY_PAYGROUP_PUB.pmtTable.employee_person_id(i),
8295              IBY_PAYGROUP_PUB.pmtTable.employee_address_id(i),
8296              IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(i),
8297 	     	IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(i),
8298 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(i),
8299 		IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(i),
8300 		IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(i),
8301 		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(i),
8302 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_name(i),
8303 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address1(i),
8304 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address2(i),
8305 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address3(i),
8306 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address4(i),
8307 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_city(i),
8308 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_postal_code(i),
8309 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_state(i),
8310 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_province(i),
8311 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_county(i),
8312 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_country(i),
8313 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_name(i),
8314 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_le_reg_num(i),
8315 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_tax_reg_num(i),
8316 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address_concat(i),
8317 		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_name(i),
8318 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_number(i),
8319 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_alternate_name(i),
8320 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_site_alt_name(i),
8321 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_number(i),
8322 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(i),
8323 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_id(i),
8324 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_branch_inv_prty_id(i),
8325 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_nme(i),
8326 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_attr_cat(i),
8327 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_attr_cat(i),
8328 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_attr_cat(i),
8329 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_site_name(i),
8330 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_alt_name(i),
8331 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_id(i),
8332 		IBY_PAYGROUP_PUB.pmtTable.payer_party_number(i),
8333 	IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(i),
8334 	IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(i),
8335 	IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(i),
8336 	IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(i),
8337 	IBY_PAYGROUP_PUB.pmtTable.payer_party_id(i),
8338 	IBY_PAYGROUP_PUB.pmtTable.payer_location_id(i),
8339 	IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(i),
8340 	IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(i),
8341 	IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(i),
8342 	IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(i),
8343 	IBY_PAYGROUP_PUB.pmtTable.int_bank_name(i),
8344 	IBY_PAYGROUP_PUB.pmtTable.int_bank_number(i),
8345 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(i),
8346 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(i),
8347 	IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(i),
8348 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(i),
8349 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(i),
8350 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(i),
8351 	IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(i),
8352 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(i),
8353 	IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(i),
8354 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(i),
8355 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(i),
8356 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(i),
8357 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(i),
8358 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(i),
8359 	IBY_PAYGROUP_PUB.pmtTable.payee_party_number(i),
8360 	IBY_PAYGROUP_PUB.pmtTable.payee_party_name(i),
8361 	IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(i), -- Bug 6175102
8362 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(i),
8363 	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(i),
8364 	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(i),
8365 	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(i),
8366 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(i),
8367 	IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(i),
8368 	IBY_PAYGROUP_PUB.pmtTable.payee_addressee(i),
8369 	IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(i),
8370 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(i),
8371 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(i),
8372 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(i),
8373 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(i),
8374 	IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(i),
8375 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(i),
8376 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(i),
8377 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(i),
8378 	IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(i),
8379 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(i),
8380 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(i),
8381 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(i),
8382 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(i),
8383 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(i),
8384 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(i),
8385 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(i),
8386 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(i),
8387 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(i),
8388 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(i),
8389 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(i),
8390 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(i),
8391 	IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(i),
8392 	IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(i),
8393 	IBY_PAYGROUP_PUB.pmtTable.declaration_format(i),
8394 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(i),
8395 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(i),
8396 	IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(i),
8397 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(i),
8398 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(i),
8399 	IBY_PAYGROUP_PUB.pmtTable.org_name(i),
8400 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(i),
8401 	IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(i),
8402 	IBY_PAYGROUP_PUB.pmtTable.source_product(i),
8403 	IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(i) -- AWT Enh 16296267
8404              );
8405 
8406             -- delete_paymentTab;
8407 
8408      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8409  print_debuginfo(l_module_name, 'EXIT');
8410       END IF;
8411 
8412  EXCEPTION
8413   /* CHANGE FOR BUG : 14348326 - START */
8414    WHEN dml_errors THEN
8415       errors := SQL%BULK_EXCEPTIONS.COUNT;
8416       FOR i IN 1..errors LOOP
8417        ERR_IND:= SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
8418        ERR_CODE:= SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE);
8419       print_debuginfo(l_module_name, l_module_name||':'||'SQLCODE: ' || SQLCODE, FND_LOG.LEVEL_UNEXPECTED);
8420        print_debuginfo(l_module_name, l_module_name||':'||'SQLERRM: ' || SQLERRM, FND_LOG.LEVEL_UNEXPECTED);
8421 	   print_debuginfo(l_module_name, l_module_name||':'|| ' While inserting payment with following context : ',FND_LOG.LEVEL_UNEXPECTED );
8422 	   print_debuginfo(l_module_name, ' Payee Name : ' || IBY_PAYGROUP_PUB.pmtTable.payee_name(ERR_IND) ||
8423 	   ' Payee Party Id : ' || IBY_PAYGROUP_PUB.pmtTable.payee_party_id(ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
8424 	   print_debuginfo(l_module_name, ' Party Site Id : ' || IBY_PAYGROUP_PUB.pmtTable.party_site_id (ERR_IND) ||
8425 	   ' Supplier Site Id : ' || IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
8426 	   print_debuginfo(l_module_name, ' Org ID : ' || IBY_PAYGROUP_PUB.pmtTable.org_id (ERR_IND) ||
8427 	   ' Org Type : ' || IBY_PAYGROUP_PUB.pmtTable.org_type (ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
8428 	   print_debuginfo(l_module_name, ' Payment Function : ' || IBY_PAYGROUP_PUB.pmtTable.payment_function (ERR_IND) ||
8429 	   ' External Bank Account ID : ' || IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id (ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
8430 
8431   END LOOP;
8432 
8433    /*
8434           * Propogate exception to caller.
8435           */
8436          RAISE;
8437    /* CHANGE FOR BUG : 14348326 - END */
8438    WHEN OTHERS THEN
8439    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
8440                  FND_LOG.LEVEL_UNEXPECTED);
8441              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
8442                  FND_LOG.LEVEL_UNEXPECTED);
8443    print_debuginfo(l_module_name, l_module_name||':Exception while inserting Payments');
8444    RAISE;
8445  END insertPayments;
8446 
8447 
8448 /*--------------------------------------------------------------------
8449  | NAME:
8450  |
8451  | PURPOSE:
8452  |     This procedure is used to free up the memory used by
8453  |     global memory structure
8454  |
8455  | PARAMETERS:
8456  |
8457  |     NONE
8458  |
8459  | RETURNS:
8460  |
8461  | NOTES:
8462  |
8463  *---------------------------------------------------------------------*/
8464  PROCEDURE delete_paymentTab IS
8465  l_module_name     CONSTANT VARCHAR2(200) := G_PKG_NAME ||
8466                                        '.delete_paymentTab';
8467 
8468 
8469   BEGIN
8470 
8471      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8472  print_debuginfo(l_module_name, 'ENTER');
8473      END IF;
8474              paymentTab.payment_id.delete;
8475              paymentTab.payment_method_code.delete;
8476              paymentTab.payment_service_request_id.delete;
8477              paymentTab.process_type.delete;
8478              paymentTab.payment_status.delete;
8479              paymentTab.payments_complete_flag.delete;
8480              paymentTab.payment_function.delete;
8481              paymentTab.payment_amount.delete;
8482              paymentTab.payment_currency_code.delete;
8483              paymentTab.bill_payable_flag.delete;
8484              paymentTab.exclusive_payment_flag.delete;
8485              paymentTab.sep_remit_advice_req_flag.delete;
8486              paymentTab.internal_bank_account_id.delete;
8487              paymentTab.org_id.delete;
8488              paymentTab.org_type.delete;
8489              paymentTab.legal_entity_id.delete;
8490              paymentTab.declare_payment_flag.delete;
8491              paymentTab.delivery_channel_code.delete;
8492              paymentTab.ext_payee_id.delete;
8493              paymentTab.payment_instruction_id.delete;
8494              paymentTab.payment_profile_id.delete;
8495              paymentTab.pregrouped_payment_flag.delete;
8496              paymentTab.stop_confirmed_flag.delete;
8497              paymentTab.stop_released_flag.delete;
8498              paymentTab.stop_request_placed_flag.delete;
8499              paymentTab.created_by.delete;
8500              paymentTab.creation_date.delete;
8501              paymentTab.last_updated_by.delete;
8502              paymentTab.last_update_login.delete;
8503              paymentTab.last_update_date.delete;
8504              paymentTab.object_version_number.delete;
8505              paymentTab.payee_party_id.delete;
8506              paymentTab.party_site_id.delete;
8507              paymentTab.supplier_site_id.delete;
8508              paymentTab.payment_reason_code.delete;
8509              paymentTab.payment_reason_comments.delete;
8510              paymentTab.payment_date.delete;
8511              paymentTab.anticipated_value_date.delete;
8512              paymentTab.declaration_amount.delete;
8513              paymentTab.declaration_currency_code.delete;
8514              paymentTab.discount_amount_taken.delete;
8515              paymentTab.payment_details.delete;
8516              paymentTab.bank_charge_bearer.delete;
8517              paymentTab.bank_charge_amount.delete;
8518              paymentTab.settlement_priority.delete;
8519              paymentTab.remittance_message1.delete;
8520              paymentTab.remittance_message2.delete;
8521              paymentTab.remittance_message3.delete;
8522              paymentTab.payment_reference_number.delete;
8523              paymentTab.paper_document_number.delete;
8524              paymentTab.bank_assigned_ref_code.delete;
8525              paymentTab.external_bank_account_id.delete;
8526              paymentTab.unique_remittance_identifier.delete;
8527              paymentTab.uri_check_digit.delete;
8528              paymentTab.bank_instruction1_code.delete;
8529              paymentTab.bank_instruction2_code.delete;
8530              paymentTab.bank_instruction_details.delete;
8531              paymentTab.payment_text_message1.delete;
8532              paymentTab.payment_text_message2.delete;
8533              paymentTab.payment_text_message3.delete;
8534              paymentTab.maturity_date.delete;
8535              paymentTab.payment_due_date.delete;
8536              paymentTab.document_category_code.delete;
8537              paymentTab.document_sequence_id.delete;
8538              paymentTab.document_sequence_value.delete;
8539              paymentTab.beneficiary_party.delete;
8540              paymentTab.stop_confirmed_by.delete;
8541              paymentTab.stop_confirm_date.delete;
8542              paymentTab.stop_confirm_reason.delete;
8543              paymentTab.stop_confirm_reference.delete;
8544              paymentTab.stop_released_by.delete;
8545              paymentTab.stop_release_date.delete;
8546              paymentTab.stop_release_reason.delete;
8547              paymentTab.stop_release_reference.delete;
8548              paymentTab.stop_request_date.delete;
8549              paymentTab.stop_request_placed_by.delete;
8550              paymentTab.stop_request_reason.delete;
8551              paymentTab.stop_request_reference.delete;
8552              paymentTab.voided_by.delete;
8553              paymentTab.void_date.delete;
8554              paymentTab.void_reason.delete;
8555              paymentTab.remit_to_location_id.delete;
8556              paymentTab.completed_pmts_group_id.delete;
8557              paymentTab.attribute_category.delete;
8558              paymentTab.attribute1.delete;
8559              paymentTab.attribute2.delete;
8560              paymentTab.attribute3.delete;
8561              paymentTab.attribute4.delete;
8562              paymentTab.attribute5.delete;
8563              paymentTab.attribute6.delete;
8564              paymentTab.attribute7.delete;
8565              paymentTab.attribute8.delete;
8566              paymentTab.attribute9.delete;
8567              paymentTab.attribute10.delete;
8568              paymentTab.attribute11.delete;
8569              paymentTab.attribute12.delete;
8570              paymentTab.attribute13.delete;
8571              paymentTab.attribute14.delete;
8572              paymentTab.attribute15.delete;
8573              paymentTab.ext_branch_number.delete;
8574              paymentTab.ext_bank_number.delete;
8575              paymentTab.ext_bank_account_name.delete;
8576              paymentTab.ext_bank_account_number.delete;
8577              paymentTab.ext_bank_account_type.delete;
8578              paymentTab.ext_bank_account_iban_number.delete;
8579              paymentTab.payee_name.delete;
8580              paymentTab.payee_address1.delete;
8581              paymentTab.payee_address2.delete;
8582              paymentTab.payee_address3.delete;
8583              paymentTab.payee_address4.delete;
8584              paymentTab.payee_city.delete;
8585              paymentTab.payee_postal_code.delete;
8586              paymentTab.payee_state.delete;
8587              paymentTab.payee_province.delete;
8588              paymentTab.payee_county.delete;
8589              paymentTab.payee_country.delete;
8590              paymentTab.remit_advice_delivery_method.delete;
8591              paymentTab.remit_advice_email.delete;
8592              paymentTab.remit_advice_fax.delete;
8593              paymentTab.address_source.delete;
8594              paymentTab.employee_address_code.delete;
8595              paymentTab.employee_person_id.delete;
8596              paymentTab.employee_address_id.delete;
8597              paymentTab.employee_payment_flag.delete;
8598 	        paymentTab.inv_payee_party_id.delete;
8599                 paymentTab.inv_party_site_id.delete;
8600                 paymentTab.inv_supplier_site_id.delete;
8601                 paymentTab.inv_beneficiary_party.delete;
8602                 paymentTab.ext_inv_payee_id.delete;
8603 		paymentTab.inv_payee_name.delete;
8604 		paymentTab.inv_payee_address1.delete;
8605 		paymentTab.inv_payee_address2.delete;
8606 		paymentTab.inv_payee_address3.delete;
8607 		paymentTab.inv_payee_address4.delete;
8608 		paymentTab.inv_payee_city.delete;
8609 		paymentTab.inv_payee_postal_code.delete;
8610 		paymentTab.inv_payee_state.delete;
8611 		paymentTab.inv_payee_province.delete;
8612 		paymentTab.inv_payee_county.delete;
8613 		paymentTab.inv_payee_country.delete;
8614 		paymentTab.inv_payee_party_name.delete;
8615 		paymentTab.inv_payee_le_reg_num.delete;
8616 		paymentTab.inv_payee_tax_reg_num.delete;
8617 		paymentTab.inv_payee_address_concat.delete;
8618 		paymentTab.inv_beneficiary_name.delete;
8619 		paymentTab.inv_payee_party_number.delete;
8620 		paymentTab.inv_payee_alternate_name.delete;
8621 		paymentTab.inv_payee_site_alt_name.delete;
8622 		paymentTab.inv_payee_supplier_number.delete;
8623 		paymentTab.inv_payee_first_party_ref.delete;
8624 		paymentTab.ext_bnk_acct_ownr_inv_prty_id.delete;
8625 		paymentTab.ext_bnk_branch_inv_prty_id.delete;
8626 		paymentTab.ext_bnk_acct_ownr_inv_prty_nme.delete;
8627 		paymentTab.inv_payee_party_attr_cat.delete;
8628 		paymentTab.inv_payee_supplier_attr_cat.delete;
8629 		paymentTab.inv_payee_spplr_site_attr_cat.delete;
8630 		paymentTab.inv_payee_supplier_site_name.delete;
8631 		paymentTab.inv_payee_spplr_site_alt_name.delete;
8632 		paymentTab.inv_payee_supplier_id.delete;
8633 
8634      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8635 	 print_debuginfo(l_module_name, 'EXIT');
8636       END IF;
8637 
8638  END delete_paymentTab;
8639 
8640 
8641  /*--------------------------------------------------------------------
8642  | NAME:
8643  |
8644  | PURPOSE:
8645  |     This procedure is used to free up the memory used by
8646  |     global memory structure [pmtTable]
8647  |
8648  | PARAMETERS:
8649  |
8650  |     NONE
8651  |
8652  | RETURNS:
8653  |
8654  | NOTES:
8655  |
8656  *---------------------------------------------------------------------*/
8657  PROCEDURE delete_pmtTable IS
8658  l_module_name     CONSTANT VARCHAR2(200) := G_PKG_NAME ||
8659                                        '.delete_pmtTable';
8660   BEGIN
8661 
8662      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8663  print_debuginfo(l_module_name, 'ENTER');
8664      END IF;
8665              pmtTable.payment_id.delete;
8666              pmtTable.payment_method_code.delete;
8667              pmtTable.payment_service_request_id.delete;
8668              pmtTable.process_type.delete;
8669              pmtTable.payment_status.delete;
8670              pmtTable.payments_complete_flag.delete;
8671              pmtTable.payment_function.delete;
8672              pmtTable.payment_amount.delete;
8673              pmtTable.payment_currency_code.delete;
8674              pmtTable.bill_payable_flag.delete;
8675              pmtTable.exclusive_payment_flag.delete;
8676              pmtTable.sep_remit_advice_req_flag.delete;
8677              pmtTable.internal_bank_account_id.delete;
8678              pmtTable.org_id.delete;
8679              pmtTable.org_type.delete;
8680              pmtTable.legal_entity_id.delete;
8681              pmtTable.declare_payment_flag.delete;
8682              pmtTable.delivery_channel_code.delete;
8683              pmtTable.ext_payee_id.delete;
8684              pmtTable.payment_instruction_id.delete;
8685              pmtTable.payment_profile_id.delete;
8686              pmtTable.pregrouped_payment_flag.delete;
8687              pmtTable.stop_confirmed_flag.delete;
8688              pmtTable.stop_released_flag.delete;
8689              pmtTable.stop_request_placed_flag.delete;
8690              pmtTable.created_by.delete;
8691              pmtTable.creation_date.delete;
8692              pmtTable.last_updated_by.delete;
8693              pmtTable.last_update_login.delete;
8694              pmtTable.last_update_date.delete;
8695              pmtTable.object_version_number.delete;
8696              pmtTable.payee_party_id.delete;
8697              pmtTable.party_site_id.delete;
8698              pmtTable.supplier_site_id.delete;
8699              pmtTable.payment_reason_code.delete;
8700              pmtTable.payment_reason_comments.delete;
8701              pmtTable.payment_date.delete;
8702              pmtTable.anticipated_value_date.delete;
8703              pmtTable.declaration_amount.delete;
8704              pmtTable.declaration_currency_code.delete;
8705              pmtTable.discount_amount_taken.delete;
8706              pmtTable.payment_details.delete;
8707              pmtTable.bank_charge_bearer.delete;
8708              pmtTable.bank_charge_amount.delete;
8709              pmtTable.settlement_priority.delete;
8710              pmtTable.remittance_message1.delete;
8711              pmtTable.remittance_message2.delete;
8712              pmtTable.remittance_message3.delete;
8713              pmtTable.payment_reference_number.delete;
8714              pmtTable.paper_document_number.delete;
8715              pmtTable.bank_assigned_ref_code.delete;
8716              pmtTable.external_bank_account_id.delete;
8717              pmtTable.unique_remittance_identifier.delete;
8718              pmtTable.uri_check_digit.delete;
8719              pmtTable.bank_instruction1_code.delete;
8720              pmtTable.bank_instruction2_code.delete;
8721              pmtTable.bank_instruction_details.delete;
8722              pmtTable.payment_text_message1.delete;
8723              pmtTable.payment_text_message2.delete;
8724              pmtTable.payment_text_message3.delete;
8725              pmtTable.maturity_date.delete;
8726              pmtTable.payment_due_date.delete;
8727              pmtTable.document_category_code.delete;
8728              pmtTable.document_sequence_id.delete;
8729              pmtTable.document_sequence_value.delete;
8730              pmtTable.beneficiary_party.delete;
8731              pmtTable.stop_confirmed_by.delete;
8732              pmtTable.stop_confirm_date.delete;
8733              pmtTable.stop_confirm_reason.delete;
8734              pmtTable.stop_confirm_reference.delete;
8735              pmtTable.stop_released_by.delete;
8736              pmtTable.stop_release_date.delete;
8737              pmtTable.stop_release_reason.delete;
8738              pmtTable.stop_release_reference.delete;
8739              pmtTable.stop_request_date.delete;
8740              pmtTable.stop_request_placed_by.delete;
8741              pmtTable.stop_request_reason.delete;
8742              pmtTable.stop_request_reference.delete;
8743              pmtTable.voided_by.delete;
8744              pmtTable.void_date.delete;
8745              pmtTable.void_reason.delete;
8746              pmtTable.remit_to_location_id.delete;
8747              pmtTable.completed_pmts_group_id.delete;
8748              pmtTable.attribute_category.delete;
8749              pmtTable.attribute1.delete;
8750              pmtTable.attribute2.delete;
8751              pmtTable.attribute3.delete;
8752              pmtTable.attribute4.delete;
8753              pmtTable.attribute5.delete;
8754              pmtTable.attribute6.delete;
8755              pmtTable.attribute7.delete;
8756              pmtTable.attribute8.delete;
8757              pmtTable.attribute9.delete;
8758              pmtTable.attribute10.delete;
8759              pmtTable.attribute11.delete;
8760              pmtTable.attribute12.delete;
8761              pmtTable.attribute13.delete;
8762              pmtTable.attribute14.delete;
8763              pmtTable.attribute15.delete;
8764              pmtTable.ext_branch_number.delete;
8765              pmtTable.ext_bank_number.delete;
8766              pmtTable.ext_bank_account_name.delete;
8767              pmtTable.ext_bank_account_number.delete;
8768              pmtTable.ext_bank_account_type.delete;
8769              pmtTable.ext_bank_account_iban_number.delete;
8770              pmtTable.payee_name.delete;
8771              pmtTable.payee_address1.delete;
8772              pmtTable.payee_address2.delete;
8773              pmtTable.payee_address3.delete;
8774              pmtTable.payee_address4.delete;
8775              pmtTable.payee_city.delete;
8776              pmtTable.payee_postal_code.delete;
8777              pmtTable.payee_state.delete;
8778              pmtTable.payee_province.delete;
8779              pmtTable.payee_county.delete;
8780              pmtTable.payee_country.delete;
8781 --	     pmtTable.separate_remit_advice_req_flag.delete;
8782              pmtTable.remit_advice_delivery_method.delete;
8783              pmtTable.remit_advice_email.delete;
8784              pmtTable.remit_advice_fax.delete;
8785              pmtTable.address_source.delete;
8786              pmtTable.employee_address_code.delete;
8787              pmtTable.employee_person_id.delete;
8788              pmtTable.employee_address_id.delete;
8789              pmtTable.employee_payment_flag.delete;
8790 
8791 	  pmtTable.payer_party_number.delete;
8792 	  pmtTable.payer_party_site_name.delete;
8793 	  pmtTable.payer_legal_entity_name.delete;
8794 	  pmtTable.payer_tax_registration_num.delete;
8795 	  pmtTable.payer_le_registration_num.delete;
8796 	  pmtTable.payer_party_id.delete;
8797 	  pmtTable.payer_location_id.delete;
8798 	  pmtTable.payer_party_attr_category.delete;
8799 	  pmtTable.payer_le_attr_category.delete;
8800 	  pmtTable.payer_abbreviated_agency_code.delete;
8801 	  pmtTable.payer_federal_us_employer_id.delete;
8802 	  pmtTable.int_bank_name.delete;
8803 	  pmtTable.int_bank_number.delete;
8804 	  pmtTable.int_bank_branch_number.delete;
8805 	  pmtTable.int_bank_branch_name.delete;
8806 	  pmtTable.int_eft_swift_code.delete;
8807 	  pmtTable.int_bank_account_number.delete;
8808 	  pmtTable.int_bank_account_name.delete;
8809 	  pmtTable.int_bank_account_iban.delete;
8810 	  pmtTable.int_bank_acct_agency_loc_code.delete;
8811 	  pmtTable.int_bank_branch_party_id.delete;
8812 	  pmtTable.int_bank_alt_name.delete;
8813 	  pmtTable.int_bank_branch_alt_name.delete;
8814 	  pmtTable.int_bank_account_alt_name.delete;
8815 	  pmtTable.int_bank_account_num_elec.delete;
8816 	  pmtTable.int_bank_branch_location_id.delete;
8817 	  pmtTable.int_bank_branch_eft_user_num.delete;
8818 	  pmtTable.int_bank_branch_rfc_identifier.delete;
8819 
8820   pmtTable.payee_site_alternate_name.delete;
8821   pmtTable.payee_supplier_number.delete;
8822   pmtTable.payee_first_party_reference.delete;
8823   pmtTable.payee_supplier_attr_category.delete;
8824   pmtTable.payee_supplier_id.delete;
8825   pmtTable.payee_tax_registration_num.delete;
8826   pmtTable.payee_le_registration_num.delete;
8827 
8828   pmtTable.payee_spplr_site_attr_category.delete;
8829   pmtTable.payee_supplier_site_name.delete;
8830 
8831   pmtTable.ext_bank_name.delete;
8832   pmtTable.ext_bank_branch_name.delete;
8833   pmtTable.ext_eft_swift_code.delete;
8834   pmtTable.ext_bank_acct_pmt_factor_flag.delete;
8835   pmtTable.ext_bank_acct_owner_party_id.delete;
8836   pmtTable.ext_bank_branch_party_id.delete;
8837   pmtTable.ext_bank_alt_name.delete;
8838   pmtTable.ext_bank_branch_alt_name.delete;
8839   pmtTable.ext_bank_account_alt_name.delete;
8840   pmtTable.ext_bank_account_num_elec.delete;
8841   pmtTable.ext_bank_branch_location_id.delete;
8842   pmtTable.ext_bank_acct_owner_party_name.delete;
8843   pmtTable.payee_address_concat.delete;
8844 
8845  pmtTable.declaration_exch_rate_type.delete;
8846  pmtTable.declaration_format.delete;
8847  pmtTable.bank_instruction1_format_value.delete;
8848  pmtTable.bank_instruction2_format_value.delete;
8849  pmtTable.payment_profile_acct_name.delete;
8850  pmtTable.payment_profile_sys_name.delete;
8851 pmtTable.payment_reason_format_value.delete;
8852 pmtTable.delivery_channel_format_value.delete;
8853 pmtTable.payment_process_request_name.delete;
8854 pmtTable.source_product.delete;
8855 pmtTable.org_name.delete;
8856 pmtTable.calling_app_id.delete;
8857   pmtTable.call_app_pay_service_req_cd.delete;
8858   pmtTable.dont_pay_flg.delete;
8859   pmtTable.dont_pay_reason_cd.delete;
8860   pmtTable.dont_pay_desc.delete;
8861 	pmtTable.inv_payee_party_id.delete;
8862 	pmtTable.inv_party_site_id.delete;
8863 	pmtTable.inv_supplier_site_id.delete;
8864 	pmtTable.inv_beneficiary_party.delete;
8865 	pmtTable.ext_inv_payee_id.delete;
8866 	pmtTable.inv_payee_name.delete;
8867 	pmtTable.inv_payee_address1.delete;
8868 	pmtTable.inv_payee_address2.delete;
8869 	pmtTable.inv_payee_address3.delete;
8870 	pmtTable.inv_payee_address4.delete;
8871 	pmtTable.inv_payee_city.delete;
8872 	pmtTable.inv_payee_postal_code.delete;
8873 	pmtTable.inv_payee_state.delete;
8874 	pmtTable.inv_payee_province.delete;
8875 	pmtTable.inv_payee_county.delete;
8876 	pmtTable.inv_payee_country.delete;
8877 	pmtTable.inv_payee_party_name.delete;
8878 	pmtTable.inv_payee_le_reg_num.delete;
8879 	pmtTable.inv_payee_tax_reg_num.delete;
8880 	pmtTable.inv_payee_address_concat.delete;
8881 	pmtTable.inv_beneficiary_name.delete;
8882 	pmtTable.inv_payee_party_number.delete;
8883 	pmtTable.inv_payee_alternate_name.delete;
8884 	pmtTable.inv_payee_site_alt_name.delete;
8885 	pmtTable.inv_payee_supplier_number.delete;
8886 	pmtTable.inv_payee_first_party_ref.delete;
8887 	pmtTable.ext_bnk_acct_ownr_inv_prty_id.delete;
8888 	pmtTable.ext_bnk_branch_inv_prty_id.delete;
8889 	pmtTable.ext_bnk_acct_ownr_inv_prty_nme.delete;
8890 	pmtTable.inv_payee_party_attr_cat.delete;
8891 	pmtTable.inv_payee_supplier_attr_cat.delete;
8892 	pmtTable.inv_payee_spplr_site_attr_cat.delete;
8893 	pmtTable.inv_payee_supplier_site_name.delete;
8894 	pmtTable.inv_payee_spplr_site_alt_name.delete;
8895 	pmtTable.inv_payee_supplier_id.delete;
8896 
8897      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8898 	 print_debuginfo(l_module_name, 'EXIT');
8899       END IF;
8900 
8901  END delete_pmtTable;
8902 
8903 /*--------------------------------------------------------------------
8904  | NAME:
8905  |     updatePayments
8906  |
8907  | PURPOSE:
8908  |     Performs an update of all created payments from PLSQL
8909  |     table into IBY_PAYMENTS_ALL table.
8910  |
8911  |     The created payments have already been inserted into
8912  |     IBY_PAYMENTS_ALL after grouping. So we only need to update
8913  |     certain fields of the payment that have been changed
8914  |     after the grouping was performed.
8915  |
8916  | PARAMETERS:
8917  |     IN
8918  |
8919  |
8920  |     OUT
8921  |
8922  |
8923  | RETURNS:
8924  |
8925  | NOTES:
8926  |
8927  *---------------------------------------------------------------------*/
8928  PROCEDURE updatePayments(
8929      p_paymentTab    IN paymentTabType
8930      )
8931  IS
8932  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.updatePayments';
8933 
8934  BEGIN
8935 
8936      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8937 	 print_debuginfo(l_module_name, 'ENTER');
8938      END IF;
8939      /* Normally, this shouldn't happen */
8940      IF (p_paymentTab.COUNT = 0) THEN
8941          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8942 		 print_debuginfo(l_module_name, 'No payments'
8943              || ' were found to update IBY_PAYMENTS_ALL table.');
8944          END IF;
8945 
8946          RETURN;
8947      END IF;
8948 
8949      FOR i in p_paymentTab.FIRST..p_paymentTab.LAST LOOP
8950 
8951          UPDATE
8952              IBY_PAYMENTS_ALL
8953          SET
8954              payment_status       = p_paymentTab(i).payment_status,
8955              payment_amount       = p_paymentTab(i).payment_amount,
8956 	     discount_amount_taken = p_paymentTab(i).discount_amount_taken,
8957              declare_payment_flag = p_paymentTab(i).declare_payment_flag,
8958              declaration_amount   = p_paymentTab(i).declaration_amount,
8959              bank_charge_amount   = p_paymentTab(i).bank_charge_amount,
8960              separate_remit_advice_req_flag
8961                                   = p_paymentTab(i).
8962                                         separate_remit_advice_req_flag
8963          WHERE
8964              payment_id = p_paymentTab(i).payment_id
8965          ;
8966 
8967      END LOOP;
8968 
8969      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
8970 	 print_debuginfo(l_module_name, 'EXIT');
8971      END IF;
8972 
8973  END updatePayments;
8974 
8975 
8976 
8977 
8978 
8979 /*--------------------------------------------------------------------
8980  | NAME:
8981  |     updatePayments
8982  |
8983  | PURPOSE:
8984  |     Performs an update of all created payments from PLSQL
8985  |     table into IBY_PAYMENTS_ALL table.
8986  |
8987  |     The created payments have already been inserted into
8988  |     IBY_PAYMENTS_ALL after grouping. So we only need to update
8989  |     certain fields of the payment that have been changed
8990  |     after the grouping was performed.
8991  |
8992  | PARAMETERS:
8993  |     IN
8994  |
8995  |
8996  |     OUT
8997  |
8998  |
8999  | RETURNS:
9000  |
9001  | NOTES:
9002  |
9003  *---------------------------------------------------------------------*/
9004  PROCEDURE updatePayments
9005  IS
9006  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.updatePayments';
9007  auditcntr      integer;
9008  /* CHANGE FOR BUG : 14348326 - START */
9009 errors                     NUMBER;
9010 ERR_IND                    NUMBER;
9011 ERR_CODE                   VARCHAR2(100);
9012 dml_errors                 EXCEPTION;
9013 PRAGMA exception_init(dml_errors, -24381);
9014 /* CHANGE FOR BUG : 14348326 - END */
9015 
9016 
9017  BEGIN
9018 
9019      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9020  print_debuginfo(l_module_name, 'ENTER');
9021       END IF;
9022 
9023 
9024   /*   FOR i in p_paymentTab.FIRST..p_paymentTab.LAST LOOP
9025 
9026          UPDATE
9027              IBY_PAYMENTS_ALL
9028          SET
9029              payment_status       = p_paymentTab(i).payment_status,
9030              payment_amount       = p_paymentTab(i).payment_amount,
9031 	     discount_amount_taken = p_paymentTab(i).discount_amount_taken,
9032              declare_payment_flag = p_paymentTab(i).declare_payment_flag,
9033              declaration_amount   = p_paymentTab(i).declaration_amount,
9034              bank_charge_amount   = p_paymentTab(i).bank_charge_amount,
9035              separate_remit_advice_req_flag
9036                                   = p_paymentTab(i).
9037                                         separate_remit_advice_req_flag
9038          WHERE
9039              payment_id = p_paymentTab(i).payment_id
9040          ;
9041 
9042      END LOOP;
9043    */
9044 
9045      /* CHANGE FOR BUG : 14348326 - START */
9046      FORALL i in nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99) SAVE EXCEPTIONS
9047      /* CHANGE FOR BUG : 14348326 - END */
9048      UPDATE IBY_PAYMENTS_ALL
9049      SET
9050              payment_id=            IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
9051              payment_method_code=             IBY_PAYGROUP_PUB.pmtTable.payment_method_code(i),
9052              payment_service_request_id=            IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(i),
9053              process_type=            IBY_PAYGROUP_PUB.pmtTable.process_type(i),
9054              payment_status=            IBY_PAYGROUP_PUB.pmtTable.payment_status(i),
9055              payments_complete_flag=            IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(i),
9056              payment_function=            IBY_PAYGROUP_PUB.pmtTable.payment_function(i),
9057              payment_amount=IBY_PAYGROUP_PUB.pmtTable.payment_amount(i),
9058              payment_currency_code =IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(i),
9059              bill_payable_flag= IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(i),
9060              exclusive_payment_flag =IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(i),
9061              --separate_remit_advice_req_flag=IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(i),
9062              internal_bank_account_id=  IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(i),
9063              org_id =IBY_PAYGROUP_PUB.pmtTable.org_id(i),
9064              org_type=IBY_PAYGROUP_PUB.pmtTable.org_type(i),
9065              legal_entity_id=            IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(i),
9066              declare_payment_flag=            IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(i),
9067              delivery_channel_code=            IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(i),
9068              ext_payee_id=IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i),
9069              payment_instruction_id =IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(i),
9070              payment_profile_id=            IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(i),
9071              pregrouped_payment_flag=IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(i),
9072              stop_confirmed_flag=IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(i),
9073              stop_released_flag =IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(i),
9074              stop_request_placed_flag =IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(i),
9075              created_by=IBY_PAYGROUP_PUB.pmtTable.created_by(i),
9076              creation_date =IBY_PAYGROUP_PUB.pmtTable.creation_date(i),
9077              last_updated_by =IBY_PAYGROUP_PUB.pmtTable.last_updated_by(i),
9078              last_update_login =IBY_PAYGROUP_PUB.pmtTable.last_update_login(i),
9079              last_update_date= IBY_PAYGROUP_PUB.pmtTable.last_update_date(i),
9080              object_version_number =IBY_PAYGROUP_PUB.pmtTable.object_version_number(i),
9081              payee_party_id =IBY_PAYGROUP_PUB.pmtTable.payee_party_id(i),
9082              party_site_id =IBY_PAYGROUP_PUB.pmtTable.party_site_id(i),
9083              supplier_site_id =IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(i),
9084              payment_reason_code =IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(i),
9085              payment_reason_comments =IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(i),
9086              payment_date =IBY_PAYGROUP_PUB.pmtTable.payment_date(i),
9087              anticipated_value_date=            IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(i),
9088              declaration_amount=            IBY_PAYGROUP_PUB.pmtTable.declaration_amount(i),
9089             declaration_currency_code=             IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(i),
9090              discount_amount_taken=            IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(i),
9091              payment_details=            IBY_PAYGROUP_PUB.pmtTable.payment_details(i),
9092              bank_charge_bearer=            IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(i),
9093              bank_charge_amount=IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(i),
9094              settlement_priority=            IBY_PAYGROUP_PUB.pmtTable.settlement_priority(i),
9095              remittance_message1=            IBY_PAYGROUP_PUB.pmtTable.remittance_message1(i),
9096              remittance_message2=IBY_PAYGROUP_PUB.pmtTable.remittance_message2(i),
9097              remittance_message3=IBY_PAYGROUP_PUB.pmtTable.remittance_message3(i),
9098              payment_reference_number=IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(i),
9099              paper_document_number=IBY_PAYGROUP_PUB.pmtTable.paper_document_number(i),
9100              bank_assigned_ref_code=            IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(i),
9101              external_bank_account_id=            IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(i),
9102              unique_remittance_identifier=            IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(i),
9103              uri_check_digit=            IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(i),
9104              bank_instruction1_code=            IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(i),
9105              bank_instruction2_code=            IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(i),
9106              bank_instruction_details=            IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(i),
9107              payment_text_message1=    IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(i),
9108              payment_text_message2=IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(i),
9109              payment_text_message3=IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(i),
9110              maturity_date=IBY_PAYGROUP_PUB.pmtTable.maturity_date(i),
9111              payment_due_date=IBY_PAYGROUP_PUB.pmtTable.payment_due_date(i),
9112              document_category_code=IBY_PAYGROUP_PUB.pmtTable.document_category_code(i),
9113              document_sequence_id=IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(i),
9114              document_sequence_value=IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(i),
9115              beneficiary_party=IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(i),
9116              stop_confirmed_by=IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(i),
9117              stop_confirm_date=IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(i),
9118              stop_confirm_reason=IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(i),
9119              stop_confirm_reference=IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(i),
9120              stop_released_by=IBY_PAYGROUP_PUB.pmtTable.stop_released_by(i),
9121              stop_release_date=IBY_PAYGROUP_PUB.pmtTable.stop_release_date(i),
9122              stop_release_reason=IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(i),
9123              stop_release_reference=IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i),
9124              stop_request_date=IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i),
9125              stop_request_placed_by=IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i),
9126              stop_request_reason=IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i),
9127              stop_request_reference=IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(i),
9128              voided_by=IBY_PAYGROUP_PUB.pmtTable.voided_by(i),
9129              void_date=IBY_PAYGROUP_PUB.pmtTable.void_date(i),
9130              void_reason=IBY_PAYGROUP_PUB.pmtTable.void_reason(i),
9131              remit_to_location_id=IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(i),
9132              completed_pmts_group_id=IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(i),
9133              attribute_category=IBY_PAYGROUP_PUB.pmtTable.attribute_category(i),
9134              attribute1=IBY_PAYGROUP_PUB.pmtTable.attribute1(i),
9135              attribute2=IBY_PAYGROUP_PUB.pmtTable.attribute2(i),
9136              attribute3=IBY_PAYGROUP_PUB.pmtTable.attribute3(i),
9137              attribute4=IBY_PAYGROUP_PUB.pmtTable.attribute4(i),
9138              attribute5=IBY_PAYGROUP_PUB.pmtTable.attribute5(i),
9139              attribute6=IBY_PAYGROUP_PUB.pmtTable.attribute6(i),
9140              attribute7=IBY_PAYGROUP_PUB.pmtTable.attribute7(i),
9141              attribute8=IBY_PAYGROUP_PUB.pmtTable.attribute8(i),
9142              attribute9=IBY_PAYGROUP_PUB.pmtTable.attribute9(i),
9143              attribute10=IBY_PAYGROUP_PUB.pmtTable.attribute10(i),
9144              attribute11=IBY_PAYGROUP_PUB.pmtTable.attribute11(i),
9145              attribute12=IBY_PAYGROUP_PUB.pmtTable.attribute12(i),
9146              attribute13=IBY_PAYGROUP_PUB.pmtTable.attribute13(i),
9147              attribute14=IBY_PAYGROUP_PUB.pmtTable.attribute14(i),
9148              attribute15=IBY_PAYGROUP_PUB.pmtTable.attribute15(i),
9149              ext_branch_number=            IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(i),
9150              ext_bank_number=            IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(i),
9151              ext_bank_account_name=            IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(i),
9152              ext_bank_account_number=            IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(i),
9153              ext_bank_account_type=            IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(i),
9154              ext_bank_account_iban_number=            IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(i),
9155              payee_name=            IBY_PAYGROUP_PUB.pmtTable.payee_name(i),
9156              payee_address1=            IBY_PAYGROUP_PUB.pmtTable.payee_address1(i),
9157              payee_address2=            IBY_PAYGROUP_PUB.pmtTable.payee_address2(i),
9158              payee_address3=            IBY_PAYGROUP_PUB.pmtTable.payee_address3(i),
9159              payee_address4=            IBY_PAYGROUP_PUB.pmtTable.payee_address4(i),
9160              payee_city=            IBY_PAYGROUP_PUB.pmtTable.payee_city(i),
9161              payee_postal_code=            IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(i),
9162              payee_state=            IBY_PAYGROUP_PUB.pmtTable.payee_state(i),
9163              payee_province=            IBY_PAYGROUP_PUB.pmtTable.payee_province(i),
9164              payee_county=            IBY_PAYGROUP_PUB.pmtTable.payee_county(i),
9165              payee_country=            IBY_PAYGROUP_PUB.pmtTable.payee_country(i),
9166              remit_advice_delivery_method=            IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(i),
9167              remit_advice_email=            IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(i),
9168              remit_advice_fax=            IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(i),
9169              address_source=            IBY_PAYGROUP_PUB.pmtTable.address_source(i),
9170              employee_address_code=            IBY_PAYGROUP_PUB.pmtTable.employee_address_code(i),
9171              employee_person_id=            IBY_PAYGROUP_PUB.pmtTable.employee_person_id(i),
9172              employee_address_id=            IBY_PAYGROUP_PUB.pmtTable.employee_address_id(i),
9173              employee_payment_flag=            IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(i),
9174 		ext_inv_payee_id  =	     	IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(i),
9175 		inv_payee_party_id  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(i),
9176 		inv_party_site_id  =		IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(i),
9177 		inv_supplier_site_id  =		IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(i),
9178 		inv_beneficiary_party  =		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(i),
9179 		inv_payee_name  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_name(i),
9180 		inv_payee_address1  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address1(i),
9181 		inv_payee_address2  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address2(i),
9182 		inv_payee_address3  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address3(i),
9183 		inv_payee_address4  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address4(i),
9184 		inv_payee_city  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_city(i),
9185 		inv_payee_postal_code  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_postal_code(i),
9186 		inv_payee_state  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_state(i),
9187 		inv_payee_province  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_province(i),
9188 		inv_payee_county  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_county(i),
9189 		inv_payee_country  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_country(i),
9190 		inv_payee_party_name  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_name(i),
9191 		inv_payee_le_reg_num =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_le_reg_num(i),
9192 		inv_payee_tax_reg_num =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_tax_reg_num(i),
9193 		inv_payee_address_concat  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address_concat(i),
9194 		inv_beneficiary_name  =		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_name(i),
9195 		inv_payee_party_number  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_number(i),
9196 		inv_payee_alternate_name  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_alternate_name(i),
9197 		inv_payee_site_alt_name =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_site_alt_name(i),
9198 		inv_payee_supplier_number  =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_number(i),
9199 		inv_payee_first_party_ref =		IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(i),
9200 		ext_bnk_acct_ownr_inv_prty_id =IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_id(i),
9201 		ext_bnk_branch_inv_prty_id =IBY_PAYGROUP_PUB.pmtTable.ext_bnk_branch_inv_prty_id(i),
9202 		ext_bnk_acct_ownr_inv_prty_nme =IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_nme(i),
9203 		inv_payee_party_attr_cat =IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_attr_cat(i),
9204 		inv_payee_supplier_attr_cat =IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_attr_cat(i),
9205 		inv_payee_spplr_site_attr_cat =IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_attr_cat(i),
9206 		inv_payee_supplier_site_name  =IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_site_name(i),
9207 		inv_payee_spplr_site_alt_name =IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_alt_name(i),
9208 		inv_payee_supplier_id =IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_id(i),
9209              payer_party_number             	 =IBY_PAYGROUP_PUB.pmtTable.payer_party_number(i),
9210              payer_party_site_name          	 =IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(i),
9211              payer_legal_entity_name        	 =IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(i),
9212              payer_tax_registration_num     	 =IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(i),
9213              payer_le_registration_num      	 =IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(i),
9214              payer_party_id                 	 =IBY_PAYGROUP_PUB.pmtTable.payer_party_id(i),
9215              payer_location_id              	 =IBY_PAYGROUP_PUB.pmtTable.payer_location_id(i),
9216              payer_party_attr_category      	 =IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(i),
9217              payer_le_attr_category         	 =IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(i),
9218              payer_abbreviated_agency_code  	 =IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(i),
9219              payer_federal_us_employer_id   	 =IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(i),
9220              int_bank_name                  	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_name(i),
9221              int_bank_number                	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_number(i),
9222              int_bank_branch_number         	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(i),
9223              int_bank_branch_name           	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(i),
9224              int_eft_swift_code             	 =IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(i),
9225              int_bank_account_number        	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(i),
9226              int_bank_account_name          	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(i),
9227              int_bank_account_iban          	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(i),
9228              int_bank_acct_agency_loc_code  	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(i),
9229              int_bank_branch_party_id       	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(i),
9230              int_bank_alt_name              	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(i),
9231              int_bank_branch_alt_name       	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(i),
9232              int_bank_account_alt_name      	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(i),
9233              int_bank_account_num_elec      	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(i),
9234              int_bank_branch_location_id    	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(i),
9235              int_bank_branch_eft_user_num   	 =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(i),
9236              payee_party_number             	 =IBY_PAYGROUP_PUB.pmtTable.payee_party_number(i),
9237              payee_party_name               	 =IBY_PAYGROUP_PUB.pmtTable.payee_party_name(i),
9238              payee_alternate_name           	 =IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(i),
9239              payee_address_concat           	 =IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(i),
9240              beneficiary_name               	 =IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(i),
9241              payee_party_attr_category      	 =IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(i),
9242              payee_spplr_site_attr_category 	 =IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(i),
9243              payee_supplier_site_name       	 =IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(i),
9244              payee_party_site_name       	 =IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(i),
9245              payee_addressee                	 =IBY_PAYGROUP_PUB.pmtTable.payee_addressee(i),
9246              payee_site_alternate_name      	 =IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(i),
9247              payee_supplier_number          	 =IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(i),
9248              payee_first_party_reference    	 =IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(i),
9249              payee_supplier_attr_category   	 =IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(i),
9250              payee_supplier_id              	 =IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(i),
9251              payee_tax_registration_num  =IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(i),
9252              payee_le_registration_num   =IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(i),
9253              ext_bank_name =IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(i),
9254               ext_bank_branch_name           	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(i),
9255               ext_eft_swift_code             	 =IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(i),
9256               ext_bank_acct_pmt_factor_flag  	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(i),
9257               ext_bank_acct_owner_party_id   	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(i),
9258               ext_bank_branch_party_id       	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(i),
9259               ext_bank_alt_name              	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(i),
9260               ext_bank_branch_alt_name       	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(i),
9261               ext_bank_account_alt_name      	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(i),
9262               ext_bank_account_num_elec      	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(i),
9263              ext_bank_branch_location_id    	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(i),
9264              ext_bank_acct_owner_party_name 	 =IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(i),
9265              --remit_advice_delivery_method   	 =IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(i),
9266              --remit_advice_email             	 =IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(i),
9267              --remit_advice_fax               	 =IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(i),
9268              delivery_channel_format_value  	 =IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(i),
9269              declaration_exch_rate_type     	 =IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(i),
9270              declaration_format             	 =IBY_PAYGROUP_PUB.pmtTable.declaration_format(i),
9271              payment_profile_acct_name      	 =IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(i),
9272              payment_profile_sys_name       	 =IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(i),
9273              payment_reason_format_value    	 =IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(i),
9274              bank_instruction1_format_value 	 =IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(i),
9275              bank_instruction2_format_value 	 =IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(i),
9276              org_name                       	 =IBY_PAYGROUP_PUB.pmtTable.org_name(i),
9277              int_bank_branch_rfc_identifier  =IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(i),
9278              payment_process_request_name    =IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(i),
9279              source_product=IBY_PAYGROUP_PUB.pmtTable.source_product(i)
9280 	     where payment_id = IBY_PAYGROUP_PUB.pmtTable.payment_id(i);
9281 
9282 
9283      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9284  print_debuginfo(l_module_name, 'EXIT');
9285      END IF;
9286  EXCEPTION
9287  /* CHANGE FOR BUG : 14348326 - START */
9288    WHEN dml_errors THEN
9289       errors := SQL%BULK_EXCEPTIONS.COUNT;
9290       FOR i IN 1..errors LOOP
9291        ERR_IND:= SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
9292        ERR_CODE:= SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE);
9293       print_debuginfo(l_module_name, l_module_name||':'||'SQLCODE: ' || SQLCODE, FND_LOG.LEVEL_UNEXPECTED);
9294        print_debuginfo(l_module_name, l_module_name||':'||'SQLERRM: ' || SQLERRM, FND_LOG.LEVEL_UNEXPECTED);
9295 	   print_debuginfo(l_module_name, l_module_name||':'|| ' While updating payments with following context : ',FND_LOG.LEVEL_UNEXPECTED );
9296 	   print_debuginfo(l_module_name, ' Payee Name : ' || IBY_PAYGROUP_PUB.pmtTable.payee_name(ERR_IND) ||
9297 	   ' Payee Party Id : ' || IBY_PAYGROUP_PUB.pmtTable.payee_party_id(ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
9298 	   print_debuginfo(l_module_name, ' Party Site Id : ' || IBY_PAYGROUP_PUB.pmtTable.party_site_id (ERR_IND) ||
9299 	   ' Supplier Site Id : ' || IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
9300 	   print_debuginfo(l_module_name, ' Org ID : ' || IBY_PAYGROUP_PUB.pmtTable.org_id (ERR_IND) ||
9301 	   ' Org Type : ' || IBY_PAYGROUP_PUB.pmtTable.org_type (ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
9302 	   print_debuginfo(l_module_name, ' Payment Function : ' || IBY_PAYGROUP_PUB.pmtTable.payment_function (ERR_IND) ||
9303 	   ' External Bank Account ID : ' || IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id (ERR_IND),FND_LOG.LEVEL_UNEXPECTED);
9304 
9305   END LOOP;
9306 
9307    /*
9308           * Propogate exception to caller.
9309           */
9310          RAISE;
9311 
9312    /* CHANGE FOR BUG : 14348326 - END */
9313    WHEN OTHERS THEN
9314    print_debuginfo(l_module_name, l_module_name||':'|| 'SQL code: '   || SQLCODE,
9315                  FND_LOG.LEVEL_UNEXPECTED);
9316              print_debuginfo(l_module_name, l_module_name||':'|| 'SQL err msg: '|| SQLERRM,
9317                  FND_LOG.LEVEL_UNEXPECTED);
9318    print_debuginfo(l_module_name, l_module_name||' : Exception while updating payments');
9319    RAISE;
9320  END updatePayments;
9321 
9322 
9323 
9324 
9325 /*--------------------------------------------------------------------
9326  | NAME:
9327  |     getNextPaymentID
9328  |
9329  | PURPOSE:
9330  |     Returns the next payment id from a sequence. These ids are
9331  |     used to uniquely number payments.
9332  |
9333  | PARAMETERS:
9334  |     IN
9335  |
9336  |
9337  |     OUT
9338  |
9339  |
9340  | RETURNS:
9341  |
9342  | NOTES:
9343  |
9344  *---------------------------------------------------------------------*/
9345  PROCEDURE getNextPaymentID(
9346      x_paymentID IN OUT NOCOPY IBY_PAYMENTS_ALL.payment_id%TYPE
9347      )
9348  IS
9349 
9350  BEGIN
9351 
9352      SELECT IBY_PAYMENTS_ALL_S.nextval INTO x_paymentID
9353          FROM DUAL;
9354 
9355  END getNextPaymentID;
9356 
9357 /*--------------------------------------------------------------------
9358  | NAME:
9359  |     updateDocsWithPaymentID
9360  |
9361  | PURPOSE:
9362  |     Updates individual documents in IBY_DOCS_PAYABLE_ALL table
9363  |     with payment ids from given PLSQL table.
9364  |
9365  | PARAMETERS:
9366  |     IN
9367  |     p_docsInPmtTab -
9368  |
9369  |     OUT
9370  |
9371  |
9372  | RETURNS:
9373  |
9374  | NOTES:
9375  |
9376  *---------------------------------------------------------------------*/
9377  PROCEDURE updateDocsWithPaymentID(
9378      p_docsInPmtTab  IN docsInPaymentTabType
9379      )
9380  IS
9381  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
9382                                              '.updateDocsWithPaymentID';
9383 
9384  BEGIN
9385 
9386      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9387  print_debuginfo(l_module_name, 'ENTER');
9388      END IF;
9389      /* Normally, this should not happen */
9390      IF (p_docsInPmtTab.COUNT = 0) THEN
9391          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9392  print_debuginfo(l_module_name, 'After grouping, no '
9393              || 'payments/documents provided to update '
9394              || 'IBY_DOCS_PAYABLE_ALL table. Possible data '
9395              || 'corruption issue.');
9396          END IF;
9397 
9398          RETURN;
9399      END IF;
9400 
9401      /*
9402       * Update the documents. We cannot use bulk update here
9403       * because the bulk update syntax does not allow us to
9404       * reference individual fields of the PL/SQL record.
9405       *
9406       * By default, set the formatting payment it for a
9407       * document same as it's payment id; the payment
9408       * instruction creation program will update the
9409       * formatting payment id for overflow documents.
9410       *
9411       * TBD: Is there any way to optimize this update?
9412       */
9413      FOR i in p_docsInPmtTab.FIRST..p_docsInPmtTab.LAST LOOP
9414 
9415          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9416 		 print_debuginfo(l_module_name, 'Payment: '
9417              || p_docsInPmtTab(i).payment_id || ', document: '
9418              || p_docsInPmtTab(i).document_id);
9419 
9420          END IF;
9421 
9422          UPDATE
9423              IBY_DOCS_PAYABLE_ALL
9424          SET
9425              payment_id            = p_docsInPmtTab(i).payment_id,
9426              formatting_payment_id = p_docsInPmtTab(i).payment_id,
9427              document_status       = p_docsInPmtTab(i).document_status,
9428 
9429              /*
9430               * Document payment amount might have gotten
9431               * changed during credit memo handling. So we
9432               * need to update document amount from PLSQL
9433               * table.
9434               */
9435              payment_amount       = p_docsInPmtTab(i).document_amount,
9436 	     payment_curr_discount_taken = p_docsInPmtTab(i).pmt_curr_discount,
9437 
9438              /*
9439               * Bank charge amount and amount withheld might have
9440               * been supplied by external hook.
9441               */
9442              amount_withheld       = p_docsInPmtTab(i).amount_withheld,
9443 
9444              /*
9445               * Fix for bug 4405981:
9446               *
9447               * The straight through flag should be set to 'N',
9448               * if the document was rejected / required manual
9449               * intervention.
9450               */
9451              straight_through_flag =
9452                     DECODE(
9453                            p_docsInPmtTab(i).document_status,
9454                            DOC_STATUS_CA_FAILED,      'N',
9455                            DOC_STATUS_RELN_FAIL,      'N',
9456                            DOC_STATUS_FAIL_BY_REJLVL, 'N',
9457                            DOC_STATUS_PAY_VAL_FAIL,   'N',
9458                            'Y'
9459                            )
9460          WHERE
9461              document_payable_id   = p_docsInPmtTab(i).document_id
9462          ;
9463 
9464      END LOOP;
9465 
9466      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9467 	 print_debuginfo(l_module_name, 'EXIT');
9468      END IF;
9469 
9470  END updateDocsWithPaymentID;
9471 
9472 /*--------------------------------------------------------------------
9473  | NAME:
9474  |     updateDocsWithPaymentID
9475  |
9476  | PURPOSE:
9477  |     Updates individual documents in IBY_DOCS_PAYABLE_ALL table
9478  |     with payment ids from given PLSQL table.
9479  |
9480  | PARAMETERS:
9481  |     IN
9482  |     p_docsInPmtTab -
9483  |
9484  |     OUT
9485  |
9486  |
9487  | RETURNS:
9488  |
9489  | NOTES:
9490  |
9491  *---------------------------------------------------------------------*/
9492  PROCEDURE updateDocsWithPaymentID
9493  IS
9494  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
9495                                              '.updateDocsWithPaymentID';
9496 
9497  BEGIN
9498 
9499      /*
9500       * Update the documents. We cannot use bulk update here
9501       * because the bulk update syntax does not allow us to
9502       * reference individual fields of the PL/SQL record.
9503       *
9504       * By default, set the formatting payment it for a
9505       * document same as it's payment id; the payment
9506       * instruction creation program will update the
9507       * formatting payment id for overflow documents.
9508       *
9509       * TBD: Is there any way to optimize this update?
9510       */
9511      MERGE
9512      INTO iby_docs_payable_all idpa
9513  /* Oracle 10gR2 doesn't require WHEN NOT MATCHED */
9514      USING iby_docs_in_pmt_gt idpt ON(idpt.document_payable_id = idpa.document_payable_id)
9515      WHEN MATCHED THEN UPDATE
9516      SET idpa.payment_id = idpt.payment_id,
9517       idpa.formatting_payment_id = idpt.payment_id,
9518       idpa.document_status = idpt.document_status,
9519       idpa.payment_amount       = idpt.document_amount,
9520       idpa.payment_curr_discount_taken = idpt.payment_curr_discount_taken,
9521       idpa.amount_withheld       = idpt.amount_withheld,
9522       idpa.straight_through_flag = DECODE(
9523                            idpt.document_status,
9524                            DOC_STATUS_CA_FAILED,      'N',
9525                            DOC_STATUS_RELN_FAIL,      'N',
9526                            DOC_STATUS_FAIL_BY_REJLVL, 'N',
9527                            DOC_STATUS_PAY_VAL_FAIL,   'N',
9528                            'Y'
9529                            );
9530 
9531      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9532 	 print_debuginfo(l_module_name, 'EXIT');
9533      END IF;
9534  EXCEPTION
9535    WHEN OTHERS THEN
9536    print_debuginfo(l_module_name, l_module_name||':'||'SQL code: '   || SQLCODE,
9537                  FND_LOG.LEVEL_UNEXPECTED);
9538              print_debuginfo(l_module_name, l_module_name||':'||'SQL err msg: '|| SQLERRM,
9539                  FND_LOG.LEVEL_UNEXPECTED);
9540    print_debuginfo(l_module_name, l_module_name||':Exception while updating Docs with Payment Id');
9541    RAISE;
9542  END updateDocsWithPaymentID;
9543 
9544 /*--------------------------------------------------------------------
9545  | NAME:
9546  |     performCentralBankReporting
9547  |
9548  | PURPOSE:
9549  |     Checks if a payment needs to be reported to the central bank.
9550  |     If central bank reporting is needed, this method will set the
9551  |     'declare payment flag' on the payment.
9552  |
9553  | PARAMETERS:
9554  |     IN
9555  |
9556  |     OUT
9557  |
9558  |
9559  | RETURNS:
9560  |
9561  | NOTES:
9562  |
9563  *---------------------------------------------------------------------*/
9564  PROCEDURE performCentralBankReporting(
9565      x_paymentTab             IN OUT NOCOPY paymentTabType,
9566      x_docsInPmtTab           IN OUT NOCOPY docsInPaymentTabType
9567 --  ,     p_cbrTab                 IN            centralBankReportTabType
9568      )
9569  IS
9570 
9571  l_module_name    CONSTANT VARCHAR2(200) := G_PKG_NAME
9572                                              || '.performCentralBankReporting';
9573  l_pmt_fx_amount  iby_payments_all.payment_amount%TYPE := -1;
9574  l_return_status  VARCHAR2(200);
9575  l_declare_flag   VARCHAR2(1);
9576  l_profile_id     IBY_PAYMENT_PROFILES.payment_profile_id%type;
9577 
9578  BEGIN
9579 
9580      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9581  print_debuginfo(l_module_name, 'ENTER');
9582      END IF;
9583 
9584 
9585      /* for each payment */
9586      FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
9587 
9588         l_profile_id :=  x_paymentTab(i).payment_profile_id;
9589         IF NOT(iby_disburse_submit_pub_pkg.paymentProfilesTab.exists(l_profile_id)) THEN
9590            iby_disburse_submit_pub_pkg.set_profile_attribs(l_profile_id);
9591         END IF;
9592 
9593            /*
9594             * Check if the payment needs to be declared to the
9595             * central bank.
9596             */
9597         IF (iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_option =
9598                      'DECLARE_DIRECT_TO_CENTRAL_BANK') THEN
9599 
9600               /*
9601                * Perform central bank reporting only for non-failed
9602                * payments.
9603                */
9604                IF (x_paymentTab(i).payment_status <>
9605                    PAY_STATUS_REJECTED) THEN
9606 
9607                   /*
9608                    * Fix for bug 5221692:
9609                    *
9610                    * User can customize the logic to determine
9611                    * whether central bank reporting is required
9612                    * by implementing the default stub function
9613                    * IBY_EXTENSIBILITY_CALLOUTS_PUB.
9614                    *     isCentralBankReportingRequired(..).
9615                    *
9616                    * If this stub is implemented use the value
9617                    * returned by the stub, else use the declaration
9618                    * threshold amount to determine whether to report
9619                    * payment to central bank.
9620                    */
9621                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9622 			print_debuginfo(l_module_name, 'Attempting to '
9623                              || 'invoke customizable function '
9624                              || 'IBY_EXTENSIBILITY_CALLOUTS_PUB.'
9625                              || 'isCentralBankReportingRequired(..) for '
9626                              || 'payment '
9627                              || x_paymentTab(i).payment_id
9628                              );
9629 
9630 	          END IF;
9631                   l_declare_flag := IBY_EXTENSIBILITY_CALLOUTS_PUB.
9632                                          isCentralBankReportingRequired(
9633                                             x_paymentTab(i).payment_id,
9634                                             l_return_status
9635                                             );
9636 
9637                   IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9638 
9639 
9640 			print_debuginfo(l_module_name, 'Callout '
9641                                  || 'IBY_EXTENSIBILITY_CALLOUTS_PUB.'
9642                                  || 'isCentralBankReportingRequired(..) for '
9643                                  || 'payment '
9644                                  || x_paymentTab(i).payment_id
9645                                  || 'returned: '
9646                                  || l_return_status
9647                                  || '. Raising exception ..',
9648                                  FND_LOG.LEVEL_UNEXPECTED
9649                                  );
9650 
9651 
9652                      /*
9653                       * This should never happen. Raise an
9654                       * exception.
9655                       */
9656                      APP_EXCEPTION.RAISE_EXCEPTION;
9657 
9658                   ELSE
9659 
9660                      /*
9661                       * If callout returns 'Y' / 'N', use the return
9662                       * value. Else consider that the callout has
9663                       * not been implemented and use the threshold
9664                       * amount to determine whether to declare the
9665                       * payment.
9666                       */
9667                      IF (l_declare_flag = 'Y' OR
9668                          l_declare_flag = 'N') THEN
9669 
9670                         /*
9671                          * Set the declare flag specified by the
9672                          * callout.
9673                          */
9674                         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9675                         print_debuginfo(l_module_name,
9676                                      'Flag returned by '
9677                                      || 'callout: '
9678                                      || l_declare_flag
9679                                      );
9680 			END IF;
9681                         x_paymentTab(i).declare_payment_flag :=
9682                                      l_declare_flag;
9683 
9684                      ELSE
9685 
9686                         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9687 			 print_debuginfo(l_module_name,  'Stubbed '
9688                                      || 'customizable function '
9689                                      || 'IBY_EXTENSIBILITY_CALLOUTS_PUB.'
9690                                      || 'isCentralBankReportingRequired(..) '
9691                                      || 'not implemented. Checking whether '
9692                                      || 'payment amount exceeds declaration '
9693                                      || 'threshold ..'
9694                                      );
9695 		          END IF;
9696 
9697                         /*
9698                          * If we reached here, it means user has
9699                          * not implemented custom logic for
9700                          * determining whether central bank
9701                          * reporting is needed.
9702                          *
9703                          * We will determine whether central
9704                          * bank reporting is needed by checking
9705                          * if the payment exceeds user specified
9706                          * amount threshold.
9707                          */
9708 
9709                          /*
9710                          * Step 2:
9711                          * Calculate the reporting amount at the
9712                          * payment level. Reporting amount is the
9713                          * payment amount converted to reporting
9714                          * currency.
9715                          *
9716                          * NOTE: We call a GL API to perform the
9717                          * currency conversion.
9718                          */
9719 
9720        --
9721        -- Use the dummy call for testing purposes.
9722        --
9723        --
9724        --dummyGLAPI(
9725        --    sysdate,                         /* IN:  exchange rate date */
9726        --    x_paymentTab(i).payment_amount,  /* IN:  source amount */
9727        --    x_paymentTab(i).payment_currency,/* IN:  source currency */
9728        --    p_cbrTab(j).decl_curr_code,      /* IN:  target currency */
9729        --    p_cbrTab(j).decl_curr_fx_rate_type, /* IN:  exchange rate type */
9730        --    l_pmt_fx_amount               /* OUT: amt in target currency */
9731        --    );
9732 
9733                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9734 				print_debuginfo(l_module_name,
9735                                      'Payment #: '
9736                                      || i
9737                                      || ', payment amount: '
9738                                      || x_paymentTab(i).payment_amount
9739                                      || ', payment currency: '
9740                                      || x_paymentTab(i).payment_currency_code
9741                                      || ', declaration currency: '
9742                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_currency_code
9743                                      || ', exchange rate type: '
9744                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_curr_fx_rate_type
9745                                      );
9746 
9747 		         END IF;
9748                                  /* OUT: target amount */
9749                          l_pmt_fx_amount := getFxAmount(
9750 
9751                                      /* IN:  source currency */
9752                                      x_paymentTab(i).payment_currency_code,
9753 
9754                                      /* IN:  target currency */
9755                                      iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_currency_code,
9756 
9757                                      /* IN:  exchange rate date */
9758                                      sysdate,
9759 
9760                                      /* IN:  exchange rate type */
9761                                      iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_curr_fx_rate_type,
9762 
9763                                      /* IN:  source amount */
9764                                      x_paymentTab(i).payment_amount
9765                                      );
9766 
9767                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9768 			 print_debuginfo(l_module_name,
9769                                      'Declaration amount '
9770                                      || 'in reporting currency '
9771                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_currency_code
9772                                      || ' derived from calling from GL API: '
9773                                      || l_pmt_fx_amount
9774                                      );
9775 
9776 			 print_debuginfo(l_module_name,
9777                                      'Declaration amount '
9778                                      || 'threshold in reporting currency: '
9779                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_threshold_amount
9780                                      );
9781 
9782 			  END IF;
9783                          IF (l_pmt_fx_amount = -1) THEN
9784 
9785                             /*
9786                              * Error occurred in call to GL API
9787                              * to convert amount. Raise exception.
9788                              */
9789 
9790 				print_debuginfo(l_module_name, 'Reporting '
9791                                          || 'amount is -1. '
9792                                          || 'Raising exception.',
9793                                          FND_LOG.LEVEL_UNEXPECTED
9794                                          );
9795 
9796 
9797                              APP_EXCEPTION.RAISE_EXCEPTION;
9798 
9799                          ELSE
9800 
9801                              x_paymentTab(i).declaration_amount :=
9802                                          l_pmt_fx_amount;
9803 
9804                          END IF;
9805 
9806                          /*
9807                           * Step 3:
9808                           * If the reporting amount on the payment is
9809                           * greater than the reporting threshold, set
9810                           * the 'report payment flag' on the payment.
9811                           */
9812 
9813                          /*
9814                           * Set the declare flag based on amount
9815                           * threshold.
9816                           */
9817 
9818                          IF (l_pmt_fx_amount >
9819                              iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_threshold_amount) THEN
9820 
9821                             x_paymentTab(i).declare_payment_flag := 'Y';
9822 
9823                          ELSE
9824 
9825                             x_paymentTab(i).declare_payment_flag := 'N';
9826 
9827                          END IF;
9828 
9829                      END IF; -- if declare flag = Y / N
9830 
9831                   END IF; -- if return status <> SUCCESS
9832 
9833                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9834 			print_debuginfo(l_module_name, 'Payment #: '
9835                              || i
9836                              || ', declaration flag: '
9837                              || x_paymentTab(i).declare_payment_flag
9838                              );
9839 
9840 		  END IF;  -- if statement level debugging is enabled
9841 
9842                END IF; -- if payment has not failed validation
9843 
9844         END IF; -- if declaration option is set
9845 
9846      END LOOP; -- for each payment
9847 
9848      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9849 	 print_debuginfo(l_module_name, 'EXIT');
9850      END IF;
9851 
9852      EXCEPTION
9853 
9854          WHEN OTHERS THEN
9855 
9856 	     print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
9857                  || 'to call GL API ''gl_currency_api.convert_amount()''.',
9858                  FND_LOG.LEVEL_UNEXPECTED
9859                  );
9860 
9861              print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
9862                  FND_LOG.LEVEL_UNEXPECTED);
9863              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
9864                  FND_LOG.LEVEL_UNEXPECTED);
9865 
9866 
9867 
9868              /*
9869               * Propogate exception to caller.
9870               */
9871              RAISE;
9872 
9873  END performCentralBankReporting;
9874 
9875 /*--------------------------------------------------------------------
9876  | NAME:
9877  |     performCentralBankReporting
9878  |
9879  | PURPOSE:
9880  |     Checks if a payment needs to be reported to the central bank.
9881  |     If central bank reporting is needed, this method will set the
9882  |     'declare payment flag' on the payment.
9883  |
9884  | PARAMETERS:
9885  |     IN
9886  |
9887  |     OUT
9888  |
9889  |
9890  | RETURNS:
9891  |
9892  | NOTES:
9893  |
9894  *---------------------------------------------------------------------*/
9895  PROCEDURE performCentralBankReporting(
9896     l_trx_cbr_index		IN BINARY_INTEGER
9897 --     x_paymentTab             IN OUT NOCOPY paymentTabType
9898 --     x_docsInPmtTab           IN OUT NOCOPY docsInPaymentTabType
9899 --  ,     p_cbrTab                 IN            centralBankReportTabType
9900      )
9901  IS
9902 
9903  l_module_name    CONSTANT VARCHAR2(200) := G_PKG_NAME
9904                                              || '.performCentralBankReporting';
9905  l_pmt_fx_amount  iby_payments_all.payment_amount%TYPE := -1;
9906  l_return_status  VARCHAR2(200);
9907  l_declare_flag   VARCHAR2(1);
9908  l_profile_id     IBY_PAYMENT_PROFILES.payment_profile_id%type;
9909 
9910  BEGIN
9911 
9912      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9913  print_debuginfo(l_module_name, 'ENTER');
9914      END IF;
9915 
9916 
9917      /* for each payment */
9918      --FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
9919 
9920         l_profile_id := IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_cbr_index);
9921         IF NOT(iby_disburse_submit_pub_pkg.paymentProfilesTab.exists(l_profile_id)) THEN
9922            iby_disburse_submit_pub_pkg.set_profile_attribs(l_profile_id);
9923         END IF;
9924 
9925            /*
9926             * Check if the payment needs to be declared to the
9927             * central bank.
9928             */
9929         IF (iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_option =
9930                      'DECLARE_DIRECT_TO_CENTRAL_BANK') THEN
9931 
9932               /*
9933                * Perform central bank reporting only for non-failed
9934                * payments.
9935                */
9936                IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_cbr_index) <>
9937                    PAY_STATUS_REJECTED) THEN
9938 
9939                   /*
9940                    * Fix for bug 5221692:
9941                    *
9942                    * User can customize the logic to determine
9943                    * whether central bank reporting is required
9944                    * by implementing the default stub function
9945                    * IBY_EXTENSIBILITY_CALLOUTS_PUB.
9946                    *     isCentralBankReportingRequired(..).
9947                    *
9948                    * If this stub is implemented use the value
9949                    * returned by the stub, else use the declaration
9950                    * threshold amount to determine whether to report
9951                    * payment to central bank.
9952                    */
9953                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
9954 			print_debuginfo(l_module_name, 'Attempting to '
9955                              || 'invoke customizable function '
9956                              || 'IBY_EXTENSIBILITY_CALLOUTS_PUB.'
9957                              || 'isCentralBankReportingRequired(..) for '
9958                              || 'payment '
9959                              ||IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index)
9960                              );
9961 
9962 	          END IF;
9963                   l_declare_flag := IBY_EXTENSIBILITY_CALLOUTS_PUB.
9964                                          isCentralBankReportingRequired(
9965                                            IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index),
9966 					    l_trx_cbr_index,
9967                                             l_return_status
9968                                             );
9969 
9970                   IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9971 
9972 
9973 			print_debuginfo(l_module_name, 'Callout '
9974                                  || 'IBY_EXTENSIBILITY_CALLOUTS_PUB.'
9975                                  || 'isCentralBankReportingRequired(..) for '
9976                                  || 'payment '
9977                                  ||IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index)
9978                                  || 'returned: '
9979                                  || l_return_status
9980                                  || '. Raising exception ..',
9981                                  FND_LOG.LEVEL_UNEXPECTED
9982                                  );
9983 
9984 
9985                      /*
9986                       * This should never happen. Raise an
9987                       * exception.
9988                       */
9989                      APP_EXCEPTION.RAISE_EXCEPTION;
9990 
9991                   ELSE
9992 
9993                      /*
9994                       * If callout returns 'Y' / 'N', use the return
9995                       * value. Else consider that the callout has
9996                       * not been implemented and use the threshold
9997                       * amount to determine whether to declare the
9998                       * payment.
9999                       */
10000                      IF (l_declare_flag = 'Y' OR
10001                          l_declare_flag = 'N') THEN
10002 
10003                         /*
10004                          * Set the declare flag specified by the
10005                          * callout.
10006                          */
10007                         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10008                         print_debuginfo(l_module_name,
10009                                      'Flag returned by '
10010                                      || 'callout: '
10011                                      || l_declare_flag
10012                                      );
10013 			END IF;
10014                        IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_cbr_index) :=
10015                                      l_declare_flag;
10016 
10017                      ELSE
10018 
10019                         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10020 			 print_debuginfo(l_module_name,  'Stubbed '
10021                                      || 'customizable function '
10022                                      || 'IBY_EXTENSIBILITY_CALLOUTS_PUB.'
10023                                      || 'isCentralBankReportingRequired(..) '
10024                                      || 'not implemented. Checking whether '
10025                                      || 'payment amount exceeds declaration '
10026                                      || 'threshold ..'
10027                                      );
10028 		          END IF;
10029 
10030                         /*
10031                          * If we reached here, it means user has
10032                          * not implemented custom logic for
10033                          * determining whether central bank
10034                          * reporting is needed.
10035                          *
10036                          * We will determine whether central
10037                          * bank reporting is needed by checking
10038                          * if the payment exceeds user specified
10039                          * amount threshold.
10040                          */
10041 
10042                          /*
10043                          * Step 2:
10044                          * Calculate the reporting amount at the
10045                          * payment level. Reporting amount is the
10046                          * payment amount converted to reporting
10047                          * currency.
10048                          *
10049                          * NOTE: We call a GL API to perform the
10050                          * currency conversion.
10051                          */
10052 
10053        --
10054        -- Use the dummy call for testing purposes.
10055        --
10056        --
10057        --dummyGLAPI(
10058        --    sysdate,                         /* IN:  exchange rate date */
10059        --   IBY_PAYGROUP_PUB.pmtTable.payment_amount,  /* IN:  source amount */
10060        --   IBY_PAYGROUP_PUB.pmtTable.payment_currency,/* IN:  source currency */
10061        --    p_cbrTab(j).decl_curr_code,      /* IN:  target currency */
10062        --    p_cbrTab(j).decl_curr_fx_rate_type, /* IN:  exchange rate type */
10063        --    l_pmt_fx_amount               /* OUT: amt in target currency */
10064        --    );
10065 
10066                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10067 				print_debuginfo(l_module_name,
10068                                      'Payment #: '
10069                                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index)
10070                                      || ', payment amount: '
10071                                      ||IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_cbr_index)
10072                                      || ', payment currency: '
10073                                      ||IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(l_trx_cbr_index)
10074                                      || ', declaration currency: '
10075                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_currency_code
10076                                      || ', exchange rate type: '
10077                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_curr_fx_rate_type
10078                                      );
10079 
10080 		         END IF;
10081                                  /* OUT: target amount */
10082                          l_pmt_fx_amount := getFxAmount(
10083 
10084                                      /* IN:  source currency */
10085                                     IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(l_trx_cbr_index),
10086 
10087                                      /* IN:  target currency */
10088                                      iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_currency_code,
10089 
10090                                      /* IN:  exchange rate date */
10091                                      sysdate,
10092 
10093                                      /* IN:  exchange rate type */
10094                                      iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_curr_fx_rate_type,
10095 
10096                                      /* IN:  source amount */
10097                                     IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_cbr_index)
10098                                      );
10099 
10100                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10101 			 print_debuginfo(l_module_name,
10102                                      'Declaration amount '
10103                                      || 'in reporting currency '
10104                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_currency_code
10105                                      || ' derived from calling from GL API: '
10106                                      || l_pmt_fx_amount
10107                                      );
10108 
10109 			 print_debuginfo(l_module_name,
10110                                      'Declaration amount '
10111                                      || 'threshold in reporting currency: '
10112                                      || iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_threshold_amount
10113                                      );
10114 
10115 			  END IF;
10116                          IF (l_pmt_fx_amount = -1) THEN
10117 
10118                             /*
10119                              * Error occurred in call to GL API
10120                              * to convert amount. Raise exception.
10121                              */
10122 
10123 				print_debuginfo(l_module_name, 'Reporting '
10124                                          || 'amount is -1. '
10125                                          || 'Raising exception.',
10126                                          FND_LOG.LEVEL_UNEXPECTED
10127                                          );
10128 
10129 
10130                              APP_EXCEPTION.RAISE_EXCEPTION;
10131 
10132                          ELSE
10133 
10134                             IBY_PAYGROUP_PUB.pmtTable.declaration_amount(l_trx_cbr_index) :=
10135                                          l_pmt_fx_amount;
10136 
10137                          END IF;
10138 
10139                          /*
10140                           * Step 3:
10141                           * If the reporting amount on the payment is
10142                           * greater than the reporting threshold, set
10143                           * the 'report payment flag' on the payment.
10144                           */
10145 
10146                          /*
10147                           * Set the declare flag based on amount
10148                           * threshold.
10149                           */
10150 
10151                          IF (l_pmt_fx_amount >
10152                              iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).declaration_threshold_amount) THEN
10153 
10154                            IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_cbr_index) := 'Y';
10155 
10156                          ELSE
10157 
10158                            IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_cbr_index) := 'N';
10159 
10160                          END IF;
10161 
10162                      END IF; -- if declare flag = Y / N
10163 
10164                   END IF; -- if return status <> SUCCESS
10165 
10166                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10167 			print_debuginfo(l_module_name, 'Payment #: '
10168                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index)
10169                              || ', declaration flag: '
10170                              ||IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_cbr_index)
10171                              );
10172 
10173 		  END IF;  -- if statement level debugging is enabled
10174 
10175                END IF; -- if payment has not failed validation
10176 
10177       --ELSE
10178 
10179       --IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_cbr_index) =NULL;
10180 
10181         END IF; -- if declaration option is set
10182 
10183 --     END LOOP; -- for each payment
10184 
10185      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10186 	 print_debuginfo(l_module_name, 'EXIT');
10187      END IF;
10188 
10189      EXCEPTION
10190 
10191          WHEN OTHERS THEN
10192 
10193 	     print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
10194                  || 'to call GL API ''gl_currency_api.convert_amount()''.',
10195                  FND_LOG.LEVEL_UNEXPECTED
10196                  );
10197 
10198              print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
10199                  FND_LOG.LEVEL_UNEXPECTED);
10200              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
10201                  FND_LOG.LEVEL_UNEXPECTED);
10202 
10203 
10204 
10205              /*
10206               * Propogate exception to caller.
10207               */
10208              RAISE;
10209 
10210  END performCentralBankReporting;
10211 
10212 /*--------------------------------------------------------------------
10213  | NAME:
10214  |     getFxAmount
10215  |
10216  | PURPOSE:
10217  |     Calls a GL API to convert a payment amount to the given
10218  |     currency.
10219  |
10220  | PARAMETERS:
10221  |     IN
10222  |
10223  |
10224  |     OUT
10225  |
10226  |
10227  | RETURNS:
10228  |
10229  | NOTES:
10230  |     No exception will be raised in this function if the call to
10231  |     GL API to convert the amount fails; Instead '-1' will be
10232  |     for the amount. The caller should recognize this and raise
10233  |     an exception.
10234  |
10235  *---------------------------------------------------------------------*/
10236  FUNCTION getFxAmount(
10237      p_source_currency   IN VARCHAR2,
10238      p_target_currency   IN VARCHAR2,
10239      p_exch_rate_date    IN DATE,
10240      p_exch_rate_type    IN VARCHAR2,
10241      p_source_amount     IN NUMBER
10242      ) RETURN NUMBER
10243 
10244  IS
10245  l_module_name  CONSTANT VARCHAR2(200)  := G_PKG_NAME || '.getFxAmount';
10246  l_fx_amount    NUMBER(15);
10247 
10248  BEGIN
10249 
10250     /*
10251      * Cannot log anywhere within this function because that
10252      * violates pragma restrict_references!
10253      */
10254 
10255     l_fx_amount := gl_currency_api.convert_amount(
10256                        p_source_currency,
10257                        p_target_currency,
10258                        p_exch_rate_date,
10259                        p_exch_rate_type,
10260                        p_source_amount
10261                        );
10262 
10263     RETURN l_fx_amount;
10264 
10265     EXCEPTION
10266 
10267         WHEN OTHERS THEN
10268              /*
10269               * The GL convert_amount() API enforces pragma
10270               * restrict_references. So we cannot raise an
10271               * exception here.
10272               *
10273               * Instead log the exception and pass -1 as the
10274               * amount. The caller should recognize that -1
10275               * indicates an exception occured.
10276               */
10277              l_fx_amount := -1;
10278 
10279              RETURN l_fx_amount;
10280 
10281  END getFxAmount;
10282 
10283 /*--------------------------------------------------------------------
10284  | NAME:
10285  |     performPaymentValidations
10286  |
10287  | PURPOSE:
10288  |     A wrapper method to call payment validation sets.
10289  |
10290  | PARAMETERS:
10291  |     IN
10292  |
10293  |     OUT
10294  |
10295  |
10296  | RETURNS:
10297  |
10298  | NOTES:
10299  |
10300  *---------------------------------------------------------------------*/
10301  PROCEDURE performPaymentValidations(
10302      p_payment_request_id   IN IBY_PAY_SERVICE_REQUESTS.
10303  	                                    payment_service_request_id%TYPE,
10304      x_paymentTab    IN OUT NOCOPY paymentTabType,
10305      x_docErrorTab   IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
10306      x_errTokenTab   IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
10307      )
10308  IS
10309 
10310  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME
10311                                              || '.performPaymentValidation';
10312 
10313  BEGIN
10314 
10315      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10316 	print_debuginfo(l_module_name, 'ENTER');
10317 
10318      END IF;
10319 --     applyPaymentValidationSets(p_payment_request_id, x_paymentTab,x_docErrorTab, x_errTokenTab);
10320 
10321      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10322 	print_debuginfo(l_module_name, 'EXIT');
10323 
10324      END IF;
10325 
10326  EXCEPTION
10327    WHEN OTHERS THEN
10328    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
10329                  FND_LOG.LEVEL_UNEXPECTED);
10330              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
10331                  FND_LOG.LEVEL_UNEXPECTED);
10332    print_debuginfo(l_module_name, l_module_name||':Exception while Performing Payment Validations');
10333    RAISE;
10334  END performPaymentValidations;
10335 
10336 /*--------------------------------------------------------------------
10337  | NAME:
10338  |     performPayReqBasedValidations
10339  |
10340  | PURPOSE:
10341  |     Validates created payments using payment request imposed
10342  |     criteria. These validations can be considered 'core' payment
10343  |     validations because they will always be applied.
10344  |
10345  |     The validations linked to the validation sets will be applied
10346  |     in addition to these core validations.
10347  |
10348  | PARAMETERS:
10349  |     IN
10350  |
10351  |     OUT
10352  |
10353  |
10354  | RETURNS:
10355  |
10356  | NOTES:
10357  |
10358  *---------------------------------------------------------------------*/
10359  PROCEDURE performPayReqBasedValidations(
10360      p_payReqCriteria  IN            payReqImposedCriteria,
10361      p_trx_pmt_line_index IN BINARY_INTEGER,
10362      x_docErrorTab     IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
10363      x_errTokenTab     IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
10364      )
10365  IS
10366 
10367  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
10368                                              '.performPayReqBasedValidations';
10369  l_max_pmt_limit         NUMBER(15);
10370  l_min_pmt_limit         NUMBER(15);
10371  l_allow_zero_pmts_flag  VARCHAR2(1) := 'N';
10372  l_pmt_failed_flag       VARCHAR2(1) := 'N';
10373 
10374  l_ce_currency_code      VARCHAR2(15);
10375  l_ce_min_pmt_ctrl       NUMBER(15);
10376  l_ce_max_pmt_ctrl       NUMBER(15);
10377 
10378  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
10379 
10380  l_error_code    VARCHAR2(100);
10381  l_error_msg     VARCHAR2(500);
10382  l_token_rec     IBY_TRXN_ERROR_TOKENS%ROWTYPE;
10383 
10384  l_profile_id    IBY_PAYMENT_PROFILES.payment_profile_id%type;
10385  l_disabled_ppp  VARCHAR2(1) := 'N';
10386 
10387  BEGIN
10388 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10389      print_debuginfo(l_module_name, 'ENTER');
10390 	 END IF;
10391 
10392      l_max_pmt_limit        := p_payReqCriteria.max_pmt_amt_limit;
10393      l_min_pmt_limit        := p_payReqCriteria.min_pmt_amt_limit;
10394      l_allow_zero_pmts_flag := p_payReqCriteria.allow_zero_pmts_flag;
10395 
10396      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10397         print_debuginfo(l_module_name, 'Max payment amount limit: '
10398             || l_max_pmt_limit);
10399         print_debuginfo(l_module_name, 'Min payment amount limit: '
10400             || l_min_pmt_limit);
10401         print_debuginfo(l_module_name, 'Zero payments flag: '
10402             || l_allow_zero_pmts_flag);
10403      END IF;
10404 
10405          IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index) = PAY_STATUS_CREATED) THEN
10406 
10407 /*  Bug 5997589
10408     Ensuring that payments with disabled payment profiles are failed.
10409 */
10410 /*  Bug 5709596 */
10411             l_profile_id := IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(p_trx_pmt_line_index);
10412             IF NOT(iby_disburse_submit_pub_pkg.paymentProfilesTab.exists(l_profile_id)) THEN
10413                iby_disburse_submit_pub_pkg.set_profile_attribs(l_profile_id);
10414             END IF;
10415 
10416             IF (iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).inactive_date
10417                 IS NOT NULL
10418                AND
10419                 iby_disburse_submit_pub_pkg.paymentProfilesTab(l_profile_id).inactive_date
10420                 <= sysdate) THEN
10421                l_disabled_ppp := 'Y';
10422             ELSE
10423                l_disabled_ppp := 'N';
10424             END IF;
10425 
10426             IF (l_disabled_ppp = 'Y') THEN
10427                 IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index)
10428                      := PAY_STATUS_REJECTED;
10429 
10430                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10431  print_debuginfo(l_module_name, 'Failed payment '
10432                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10433                      || ' because disabled PPP '
10434                      || IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(p_trx_pmt_line_index)
10435                      || ' is associate with it.'
10436                      );
10437 	       END IF;
10438 
10439 			  /* AWT Enh 16296267 */
10440 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(p_trx_pmt_line_index) = 'Y' ) THEN
10441 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(p_trx_pmt_line_index);
10442                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) THEN
10443                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10444                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
10445                    END IF;
10446                 ELSE
10447                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10448                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
10449                      ' to Invalid Payee  Awt List');
10450                    END IF;
10451                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(p_trx_pmt_line_index);
10452                 END IF;
10453             END IF;
10454 
10455                l_error_code := 'IBY_PMT_INVALID_PROFILE';
10456                FND_MESSAGE.set_name('IBY', l_error_code);
10457 
10458                FND_MESSAGE.SET_TOKEN('PMT_NUMBER',
10459                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10460                      FALSE);
10461 
10462                l_token_rec.token_name  := 'PMT_NUMBER';
10463                l_token_rec.token_value := IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index);
10464                x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10465 
10466                  /*
10467                   * Once we fail a payment, we need to create
10468                   * an error record and insert this record
10469                   * into the errors table.
10470                   */
10471                IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
10472                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10473                      IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
10474                      l_error_code,
10475                      FND_MESSAGE.get,
10476                      l_doc_err_rec
10477                      );
10478 
10479                IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
10480                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
10481 
10482                  /* fail the docs of this payment */
10483  		 If (l_pmt_failed_flag = 'N') THEN
10484                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10485                      DOC_STATUS_PAY_VAL_FAIL,
10486                      x_docErrorTab, x_errTokenTab);
10487 		 l_pmt_failed_flag := 'Y';
10488 		 END IF;
10489 
10490             END IF;  -- l_disabled_ppp
10491 
10492             IF (l_max_pmt_limit <> -1 AND
10493                  IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index) > l_max_pmt_limit) THEN
10494 
10495                  IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index)
10496                      := PAY_STATUS_REJECTED;
10497 
10498                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10499  print_debuginfo(l_module_name, 'Failed payment '
10500                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10501                      || ' because payment amount '
10502                      || IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index)
10503                      || ' exceeds limit '
10504                      || l_max_pmt_limit
10505                      || ' imposed by payment request.'
10506                      );
10507 	     END IF;
10508 
10509 			  /* AWT Enh 16296267 */
10510 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(p_trx_pmt_line_index) = 'Y' ) THEN
10511 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(p_trx_pmt_line_index);
10512                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) THEN
10513                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10514                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
10515                    END IF;
10516                 ELSE
10517                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10518                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
10519                      ' to Invalid Payee  Awt List');
10520                    END IF;
10521                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(p_trx_pmt_line_index);
10522                 END IF;
10523             END IF;
10524 
10525                  l_error_code := 'IBY_PMT_ABOVE_LIMIT';
10526                  FND_MESSAGE.set_name('IBY', l_error_code);
10527 
10528                  FND_MESSAGE.SET_TOKEN('PMT_AMOUNT',
10529                      IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index),
10530                      FALSE);
10531 
10532                  l_token_rec.token_name  := 'PMT_AMOUNT';
10533                  l_token_rec.token_value := IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index);
10534                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10535 
10536                  FND_MESSAGE.SET_TOKEN('UPPER_LIMIT',
10537                      l_max_pmt_limit,
10538                      FALSE);
10539 
10540                  l_token_rec.token_name  := 'UPPER_LIMIT';
10541                  l_token_rec.token_value := l_max_pmt_limit;
10542                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10543 
10544                  /*
10545                   * Once we fail a payment, we need to create
10546                   * an error record and insert this record
10547                   * into the errors table.
10548                   */
10549                  IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
10550                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10551                      IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
10552                      l_error_code,
10553                      FND_MESSAGE.get,
10554                      l_doc_err_rec
10555                      );
10556 
10557                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
10558                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
10559 
10560                  /* fail the docs of this payment */
10561 		  If (l_pmt_failed_flag = 'N') THEN
10562                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10563                      DOC_STATUS_PAY_VAL_FAIL,
10564                      x_docErrorTab, x_errTokenTab);
10565      		 l_pmt_failed_flag := 'Y';
10566 		 END IF;
10567 
10568 
10569              END IF;
10570 
10571              IF (l_min_pmt_limit <> -1 AND
10572                  IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index) < l_min_pmt_limit) THEN
10573 
10574                  IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index)
10575                      := PAY_STATUS_REJECTED;
10576 
10577                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10578  print_debuginfo(l_module_name, 'Failed payment '
10579                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10580                      || ' because payment amount '
10581                      || IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index)
10582                      || ' is lower than limit '
10583                      || l_min_pmt_limit
10584                      || ' imposed by payment request.'
10585                      );
10586 		 END IF;
10587 
10588 			  /* AWT Enh 16296267 */
10589 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(p_trx_pmt_line_index) = 'Y' ) THEN
10590 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(p_trx_pmt_line_index);
10591                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) THEN
10592                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10593                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
10594                    END IF;
10595                 ELSE
10596                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10597                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
10598                      ' to Invalid Payee  Awt List');
10599                    END IF;
10600                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(p_trx_pmt_line_index);
10601                 END IF;
10602             END IF;
10603 
10604                  l_error_code := 'IBY_PMT_BELOW_LIMIT';
10605                  FND_MESSAGE.set_name('IBY', l_error_code);
10606 
10607                  FND_MESSAGE.SET_TOKEN('PMT_AMOUNT',
10608                      IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index),
10609                      FALSE);
10610 
10611                  l_token_rec.token_name  := 'PMT_AMOUNT';
10612                  l_token_rec.token_value := IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index);
10613                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10614 
10615                  FND_MESSAGE.SET_TOKEN('LOWER_LIMIT',
10616                      l_min_pmt_limit,
10617                      FALSE);
10618 
10619                  l_token_rec.token_name  := 'LOWER_LIMIT';
10620                  l_token_rec.token_value := l_min_pmt_limit;
10621                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10622 
10623                  /*
10624                   * Once we fail a payment, we need to create
10625                   * an error record and insert this record
10626                   * into the errors table.
10627                   */
10628                  IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
10629                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10630                      IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
10631                      l_error_code,
10632                      FND_MESSAGE.get,
10633                      l_doc_err_rec
10634                      );
10635 
10636                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
10637                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
10638 
10639                  /* fail the docs of this payment */
10640 		  If (l_pmt_failed_flag = 'N') THEN
10641                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10642                      DOC_STATUS_PAY_VAL_FAIL,
10643                      x_docErrorTab, x_errTokenTab);
10644 
10645      		 l_pmt_failed_flag := 'Y';
10646 		 END IF;
10647 
10648 
10649              END IF;
10650 
10651              IF (UPPER(l_allow_zero_pmts_flag) <> 'Y' AND
10652                  IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index) = 0) THEN
10653 
10654                  IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index)
10655                      := PAY_STATUS_REJECTED;
10656 
10657                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10658  print_debuginfo(l_module_name, 'Failed payment '
10659                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10660                      || ' because payment amount '
10661                      || IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index)
10662                      || ' is zero. Zero payments not'
10663                      || ' allowed by this payment request.'
10664                      );
10665 		 END IF;
10666 
10667 			  /* AWT Enh 16296267 */
10668 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(p_trx_pmt_line_index) = 'Y' ) THEN
10669 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(p_trx_pmt_line_index);
10670                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) THEN
10671                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10672                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
10673                    END IF;
10674                 ELSE
10675                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10676                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
10677                      ' to Invalid Payee  Awt List');
10678                    END IF;
10679                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(p_trx_pmt_line_index);
10680                 END IF;
10681             END IF;
10682 
10683                  l_error_code := 'IBY_ZERO_PMT_NOT_ALLOWED';
10684                  FND_MESSAGE.set_name('IBY', l_error_code);
10685 
10686                  /*
10687                   * Once we fail a payment, we need to create
10688                   * an error record and insert this record
10689                   * into the errors table.
10690                   */
10691                  IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
10692                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10693                      IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
10694                      l_error_code,
10695                      FND_MESSAGE.get,
10696                      l_doc_err_rec
10697                      );
10698 
10699                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
10700                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
10701 
10702                  /* fail the docs of this payment */
10703  		 If (l_pmt_failed_flag = 'N') THEN
10704 
10705                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10706                      DOC_STATUS_PAY_VAL_FAIL,
10707                      x_docErrorTab, x_errTokenTab);
10708      		 l_pmt_failed_flag := 'Y';
10709 		 END IF;
10710 
10711 
10712              END IF;
10713 
10714 
10715              /*
10716               * Fix for bug 5760241:
10717               *
10718               * Validate the payment for maximum and minimum
10719               * payment amounts based on the internal bank
10720               * account payment controls set in CE.
10721               */
10722 
10723              /*
10724               * First, get the minimum and maximum payment
10725               * control amount values from CE for the int
10726               * bank account on the payment.
10727               */
10728              SELECT
10729 			     CURRENCY_CODE,
10730                  min_check_amount,
10731                  max_check_amount
10732              INTO
10733 			     l_ce_currency_code,
10734                  l_ce_min_pmt_ctrl,
10735                  l_ce_max_pmt_ctrl
10736              FROM
10737                  CE_BANK_ACCOUNTS
10738              WHERE
10739                  bank_account_id =  IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(p_trx_pmt_line_index)
10740              ;
10741 
10742              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10743  print_debuginfo(l_module_name, 'Payment id: '
10744                  || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10745                  || ', int bank account id: '
10746                  || IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(p_trx_pmt_line_index)
10747                  || ', CE min pmt amount control: '
10748                  || l_ce_min_pmt_ctrl
10749                  || ', CE max pmt amount control: '
10750                  || l_ce_max_pmt_ctrl
10751                  );
10752 	     END IF;
10753              /*
10754               * Next, validate payment against minimum
10755               * payment amount control.
10756               */
10757              IF (l_ce_min_pmt_ctrl IS NOT NULL AND l_ce_currency_code IS NOT NULL
10758 			     AND l_ce_currency_code = IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(p_trx_pmt_line_index) AND
10759                  IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index) < l_ce_min_pmt_ctrl) THEN
10760 
10761                  IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index)
10762                      := PAY_STATUS_REJECTED;
10763 
10764                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10765  print_debuginfo(l_module_name, 'Failed payment '
10766                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10767                      || ' because payment amount '
10768                      || IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index)
10769                      || ' is lower than limit '
10770                      || l_ce_min_pmt_ctrl
10771                      || ' imposed by Cash Management (CE).'
10772                      );
10773 		         END IF;
10774 
10775 			  /* AWT Enh 16296267 */
10776 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(p_trx_pmt_line_index) = 'Y' ) THEN
10777 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(p_trx_pmt_line_index);
10778                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) THEN
10779                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10780                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
10781                    END IF;
10782                 ELSE
10783                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10784                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
10785                      ' to Invalid Payee  Awt List');
10786                    END IF;
10787                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(p_trx_pmt_line_index);
10788                 END IF;
10789             END IF;
10790 
10791                  l_error_code := 'IBY_PMT_BELOW_CE_LIMIT';
10792                  FND_MESSAGE.set_name('IBY', l_error_code);
10793 
10794                  FND_MESSAGE.SET_TOKEN('PMT_AMOUNT',
10795                      IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index),
10796                      FALSE);
10797 
10798                  l_token_rec.token_name  := 'PMT_AMOUNT';
10799                  l_token_rec.token_value := IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index);
10800                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10801 
10802                  FND_MESSAGE.SET_TOKEN('LOWER_LIMIT',
10803                      l_ce_min_pmt_ctrl,
10804                      FALSE);
10805 
10806                  l_token_rec.token_name  := 'LOWER_LIMIT';
10807                  l_token_rec.token_value := l_ce_min_pmt_ctrl;
10808                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10809 
10810                  /*
10811                   * Once we fail a payment, we need to create
10812                   * an error record and insert this record
10813                   * into the errors table.
10814                   */
10815                  IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
10816                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10817                      IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
10818                      l_error_code,
10819                      FND_MESSAGE.get,
10820                      l_doc_err_rec
10821                      );
10822 
10823                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
10824                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
10825 
10826                  /* fail the docs of this payment */
10827  		 If (l_pmt_failed_flag = 'N') THEN
10828 
10829                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10830                      DOC_STATUS_PAY_VAL_FAIL,
10831                      x_docErrorTab, x_errTokenTab);
10832 		 l_pmt_failed_flag := 'Y';
10833 		 END IF;
10834 
10835              END IF;
10836 
10837              /*
10838               * Next, validate payment against maximum
10839               * payment amount control.
10840               */
10841              IF (l_ce_max_pmt_ctrl IS NOT NULL AND l_ce_currency_code IS NOT NULL
10842 			     AND l_ce_currency_code = IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(p_trx_pmt_line_index) AND
10843                  IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index) > l_ce_max_pmt_ctrl) THEN
10844 
10845                  IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index)
10846                      := PAY_STATUS_REJECTED;
10847 
10848                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10849  print_debuginfo(l_module_name, 'Failed payment '
10850                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
10851                      || ' because payment amount '
10852                      || IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index)
10853                      || ' is greater than limit '
10854                      || l_ce_max_pmt_ctrl
10855                      || ' imposed by Cash Management (CE).'
10856                      );
10857 		         END IF;
10858 
10859 			  /* AWT Enh 16296267 */
10860 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(p_trx_pmt_line_index) = 'Y' ) THEN
10861 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(p_trx_pmt_line_index);
10862                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) THEN
10863                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10864                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
10865                    END IF;
10866                 ELSE
10867                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10868                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
10869                      ' to Invalid Payee  Awt List');
10870                    END IF;
10871                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(p_trx_pmt_line_index);
10872                 END IF;
10873             END IF;
10874 
10875                  l_error_code := 'IBY_PMT_ABOVE_CE_LIMIT';
10876                  FND_MESSAGE.set_name('IBY', l_error_code);
10877 
10878                  FND_MESSAGE.SET_TOKEN('PMT_AMOUNT',
10879                      IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index),
10880                      FALSE);
10881 
10882                  l_token_rec.token_name  := 'PMT_AMOUNT';
10883                  l_token_rec.token_value := IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index);
10884                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10885 
10886                  FND_MESSAGE.SET_TOKEN('UPPER_LIMIT',
10887                      l_ce_max_pmt_ctrl,
10888                      FALSE);
10889 
10890                  l_token_rec.token_name  := 'UPPER_LIMIT';
10891                  l_token_rec.token_value := l_ce_max_pmt_ctrl;
10892                  x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
10893 
10894                  /*
10895                   * Once we fail a payment, we need to create
10896                   * an error record and insert this record
10897                   * into the errors table.
10898                   */
10899                  IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
10900                      IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10901                      IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
10902                      l_error_code,
10903                      FND_MESSAGE.get,
10904                      l_doc_err_rec
10905                      );
10906 
10907                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
10908                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
10909 
10910                  /* fail the docs of this payment */
10911  		 If (l_pmt_failed_flag = 'N') THEN
10912 
10913                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
10914                      DOC_STATUS_PAY_VAL_FAIL,
10915                      x_docErrorTab, x_errTokenTab);
10916      		 l_pmt_failed_flag := 'Y';
10917 		 END IF;
10918 
10919 
10920              END IF;
10921 
10922          END IF; -- if pmt status = CREATED
10923 
10924     -- END LOOP;
10925 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10926      print_debuginfo(l_module_name, 'EXIT');
10927 	 END IF;
10928  EXCEPTION
10929    WHEN OTHERS THEN
10930    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
10931                  FND_LOG.LEVEL_UNEXPECTED);
10932              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
10933                  FND_LOG.LEVEL_UNEXPECTED);
10934    print_debuginfo(l_module_name, l_module_name||':Exception while performing pay Req based Valdiations');
10935    RAISE;
10936  END performPayReqBasedValidations;
10937 
10938 /*--------------------------------------------------------------------
10939  | NAME:
10940  |     performPmtGrpNumberValidation
10941  |
10942  | PURPOSE:
10943  |
10944  |
10945  |
10946  | PARAMETERS:
10947  |     IN
10948  |
10949  |     OUT
10950  |
10951  |
10952  | RETURNS:
10953  |
10954  | NOTES:
10955  |
10956  *---------------------------------------------------------------------*/
10957  PROCEDURE performPmtGrpNumberValidation(
10958      x_paymentTab     IN OUT NOCOPY paymentTabType,
10959      x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
10960      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
10961      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
10962      )
10963  IS
10964 
10965  l_orig_pmt_id       IBY_PAYMENTS_ALL.payment_id%TYPE;
10966  l_orig_doc_id       IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE;
10967  l_orig_pmt_grp_num  IBY_DOCS_PAYABLE_ALL.payment_grouping_number%TYPE;
10968 
10969  l_compare_pmt_id    IBY_PAYMENTS_ALL.payment_id%TYPE;
10970  l_compare_doc_id    IBY_DOCS_PAYABLE_ALL.document_payable_id%TYPE;
10971 
10972  l_doc_err_rec       IBY_TRANSACTION_ERRORS%ROWTYPE;
10973 
10974  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
10975                                              '.performPmtGrpNumberValidation';
10976 
10977  BEGIN
10978 
10979      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
10980 	print_debuginfo(l_module_name, 'ENTER');
10981 
10982      END IF;
10983      /*
10984       * All documents payable with the same payment grouping number
10985       * must be part of a single payment.
10986       *
10987       * When grouping documents into payments, if multiple payments
10988       * have documents with the same payment grouping number, it means
10989       * that documents with the same payment grouping number have been
10990       * distributed across payments. This is not allowed; In this
10991       * situation, fail all the payments that have documents with the
10992       * same payment grouping number, and fail their constituent documents
10993       * as well.
10994       */
10995 
10996      /* for each created payment in request */
10997      FOR i in x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
10998 
10999          /*
11000           * Use only non-failed payments for checking the
11001           * payment grouping number.
11002           */
11003          IF (x_paymentTab(i).payment_status = PAY_STATUS_CREATED) THEN
11004 
11005              l_orig_pmt_id := x_paymentTab(i).payment_id;
11006 
11007              /*
11008               * Scan through all available documents to find documents
11009               * that are part of this non-failed payment
11010               */
11011              IF (x_docsInPmtTab.COUNT > 0) THEN
11012              FOR j in x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
11013 
11014                  /* if we found a document of this payment */
11015                  IF (x_paymentTab(i).payment_id =
11016                      x_docsInPmtTab(j).payment_id) THEN
11017 
11018                      /*
11019                       * Store this document id and the payment grouping
11020                       * number of this document for comparison with
11021                       * the documents of other payments.
11022                       */
11023                      l_orig_doc_id      := x_docsInPmtTab(j).document_id;
11024                      l_orig_pmt_grp_num := x_docsInPmtTab(j).payment_grp_num;
11025 
11026                      /*
11027                       * From the list of created payments, find the next
11028                       * payment that is different from the payment that
11029                       * we began with.
11030                       */
11031                      FOR k in x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
11032 
11033                          /*
11034                           * If we found a payment different from the original
11035                           * one make sure that it is non-failed payment.
11036                           */
11037                          IF (x_paymentTab(k).payment_id <> l_orig_pmt_id AND
11038                              x_paymentTab(k).payment_status =
11039                                  PAY_STATUS_CREATED) THEN
11040 
11041                              /* this means we got a new non-failed payment */
11042                              /* get the documents of this payment */
11043 
11044                              FOR m in x_docsInPmtTab.FIRST ..
11045                                  x_docsInPmtTab.LAST LOOP
11046 
11047                                  /*
11048                                   * We found a document of this new
11049                                   * non-failed payment
11050                                   */
11051                                  IF (x_docsInPmtTab(m).payment_id =
11052                                      x_paymentTab(k).payment_id) THEN
11053 
11054                                      /*
11055                                       * Check if the document of this
11056                                       * payment has the same payment grouping
11057                                       * number as the document of the
11058                                       * original payment
11059                                       */
11060                                      IF (x_docsInPmtTab(m).payment_grp_num =
11061                                          l_orig_pmt_grp_num) THEN
11062 
11063                                          /*
11064                                           * If so, we found documents across
11065                                           * payments sharing the same payment
11066                                           * grouping number. This is an error.
11067                                           * Log all the details.
11068                                           */
11069                                          l_compare_pmt_id :=
11070                                              x_paymentTab(k).payment_id;
11071 
11072                                          l_compare_doc_id := x_docsInPmtTab(m).
11073                                                                  document_id;
11074 
11075                                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11076 					 print_debuginfo(l_module_name,
11077                                              'Document '
11078                                              || l_compare_doc_id
11079                                              || ' of payment '
11080                                              || l_compare_pmt_id
11081                                              || ' has the same payment '
11082                                              || 'grouping number '
11083                                              || l_orig_pmt_grp_num
11084                                              || ', as document '
11085                                              || l_orig_doc_id
11086                                              || ' of payment '
11087                                              || l_orig_pmt_id
11088                                              || '. This means that two '
11089                                              || 'documents with the same '
11090                                              || 'payment grouping '
11091                                              || 'number are grouped in '
11092                                              || 'different payments. '
11093                                              || 'Both payments '
11094                                              || 'will be failed.'
11095                                              );
11096 				          END IF;
11097 
11098                                          /*
11099                                           * Fail both payments
11100                                           */
11101 
11102                                          /* 1: fail the new payment */
11103                                          x_paymentTab(k).payment_status :=
11104                                              PAY_STATUS_REJECTED;
11105 
11106                                          /*
11107                                           * Once we fail a payment, we need
11108                                           * to create an error record and
11109                                           * insert this record into
11110                                           * the errors table.
11111                                           */
11112                                          IBY_BUILD_UTILS_PKG.createErrorRecord(
11113                                              TRXN_TYPE_PMT,
11114                                              x_paymentTab(k).payment_id,
11115                                              x_paymentTab(k).payment_status,
11116                                              NULL,
11117                                              x_paymentTab(k).payment_id,
11118                                              NULL,
11119                                              NULL,
11120                                              NULL,
11121                                              NULL,
11122                                              NULL,
11123                                              l_doc_err_rec,
11124                                              x_errTokenTab
11125                                              );
11126 
11127                                          IBY_VALIDATIONSETS_PUB.
11128                                              insertIntoErrorTable(
11129                                                  l_doc_err_rec, x_docErrorTab,
11130                                                  x_errTokenTab);
11131 
11132                                          /* fail the docs of this payment */
11133                                          failDocsOfPayment(
11134                                              x_paymentTab(k).payment_id,
11135                                              DOC_STATUS_PAY_VAL_FAIL,
11136                                              x_docsInPmtTab,
11137                                              x_docErrorTab,
11138                                              x_errTokenTab);
11139 
11140                                          /* 2: fail the original payment */
11141                                          x_paymentTab(i).payment_status :=
11142                                              PAY_STATUS_REJECTED;
11143 
11144                                          /*
11145                                           * Once we fail a payment, we need
11146                                           * to create an error record and
11147                                           * insert this record into
11148                                           * the errors table.
11149                                           */
11150                                          IBY_BUILD_UTILS_PKG.createErrorRecord(
11151                                              TRXN_TYPE_PMT,
11152                                              x_paymentTab(i).payment_id,
11153                                              x_paymentTab(i).payment_status,
11154                                              NULL,
11155                                              x_paymentTab(i).payment_id,
11156                                              NULL,
11157                                              NULL,
11158                                              NULL,
11159                                              NULL,
11160                                              NULL,
11161                                              l_doc_err_rec,
11162                                              x_errTokenTab
11163                                              );
11164 
11165                                          IBY_VALIDATIONSETS_PUB.
11166                                              insertIntoErrorTable(
11167                                                  l_doc_err_rec, x_docErrorTab,
11168                                                  x_errTokenTab);
11169 
11170                                          /* fail the docs of this payment */
11171                                          failDocsOfPayment(
11172                                              x_paymentTab(i).payment_id,
11173                                              DOC_STATUS_PAY_VAL_FAIL,
11174                                              x_docsInPmtTab,
11175                                              x_docErrorTab,
11176                                              x_errTokenTab);
11177 
11178                                      END IF; -- if payment grp num matched
11179 
11180                                  END IF; -- if doc belongs to this payment
11181 
11182                              END LOOP; -- loop through all documents
11183 
11184                          END IF; -- if this is a new payment
11185 
11186                      END LOOP; -- loop through all payments
11187 
11188                  END IF; -- if document has the same payment id
11189 
11190              END LOOP; -- loop through all documents
11191              END IF; -- if documents count > 0
11192 
11193          END IF; -- if payment is not in failed status
11194 
11195      END LOOP; -- for each payment in request
11196 
11197      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11198 	 print_debuginfo(l_module_name, 'EXIT');
11199 
11200     END IF;
11201  END performPmtGrpNumberValidation;
11202 
11203 /*--------------------------------------------------------------------
11204  | NAME:
11205  |     performPreHookProcess
11206  |
11207  | PURPOSE:
11208  |     Inserts all successfuly validated payments into
11209  |     IBY_HOOK_PAYMENTS_TEMP. This is a temporary table that the
11210  |     calling app can access to see what payments have been
11211  |     created. The calling app can also update the payments / fail
11212  |     the payments in the temporary table, and the payment creation
11213  |     program will update it's payments accordingly.
11214  |
11215  | PARAMETERS:
11216  |     IN
11217  |
11218  |     OUT
11219  |
11220  |
11221  | RETURNS:
11222  |
11223  | NOTES:
11224  |
11225  *---------------------------------------------------------------------*/
11226  PROCEDURE performPreHookProcess(
11227      p_cap_payreq_cd     IN            VARCHAR2,
11228      p_cap_id            IN            NUMBER,
11229      x_paymentTab        IN OUT NOCOPY paymentTabType,
11230      x_docsInPmtTab      IN OUT NOCOPY docsInPaymentTabType,
11231      x_hookPaymentTab    IN OUT NOCOPY hookPaymentTabType,
11232      x_hookDocsInPmtTab  IN OUT NOCOPY hookDocsInPaymentTabType
11233      )
11234  IS
11235 
11236  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.performPreHookProcess';
11237  l_succPayIndx NUMBER := 1;
11238  l_succDocIndx NUMBER := 1;
11239 
11240 /*
11241  l_calling_app_ids                 t_calling_app_id;
11242  l_call_app_pay_service_req_cds    t_call_app_pay_service_req_cd;
11243  l_payment_service_request_ids     t_payment_service_request_id;
11244  l_payment_ids                     t_payment_id;
11245  l_payment_amounts                 t_payment_amount;
11246  l_payment_currency_codes          t_payment_currency_code;
11247  l_dont_pay_flags                  t_dont_pay_flag;
11248  l_dont_pay_reason_codes           t_dont_pay_reason_code;
11249  l_dont_pay_descriptions           t_dont_pay_description;
11250  l_internal_bank_account_ids       t_internal_bank_account_id;
11251  l_ext_payee_ids                   t_ext_payee_id;
11252  l_payee_party_ids                 t_payee_party_id;
11253  l_party_site_ids                  t_party_site_id;
11254  l_supplier_site_ids               t_supplier_site_id;
11255  l_org_ids                         t_org_id;
11256  l_org_types                       t_org_type;
11257  l_external_bank_account_ids       t_external_bank_account_id;
11258  l_discount_amount_takens          t_discount_amount_taken;
11259  l_payment_dates                   t_payment_date;
11260  l_bank_charge_amounts             t_bank_charge_amount;
11261  l_created_bys                     t_created_by;
11262  l_creation_dates                  t_creation_date;
11263  l_last_updated_bys                t_last_updated_by;
11264  l_last_update_dates               t_last_update_date;
11265  l_last_update_logins              t_last_update_login;
11266  l_object_version_numbers          t_object_version_number;
11267 */
11268 
11269  TYPE t_pmt_id IS TABLE OF
11270      IBY_HOOK_DOCS_IN_PMT_T.payment_id%TYPE
11271      INDEX BY BINARY_INTEGER;
11272  TYPE t_document_payable_id IS TABLE OF
11273      IBY_HOOK_DOCS_IN_PMT_T.document_payable_id%TYPE
11274      INDEX BY BINARY_INTEGER;
11275  TYPE t_call_app_id IS TABLE OF
11276      IBY_HOOK_DOCS_IN_PMT_T.calling_app_id%TYPE
11277      INDEX BY BINARY_INTEGER;
11278  TYPE t_calling_app_doc_unique_ref1 IS TABLE OF
11279      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref1%TYPE
11280      INDEX BY BINARY_INTEGER;
11281  TYPE t_calling_app_doc_unique_ref2 IS TABLE OF
11282      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref2%TYPE
11283      INDEX BY BINARY_INTEGER;
11284  TYPE t_calling_app_doc_unique_ref3 IS TABLE OF
11285      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref3%TYPE
11286      INDEX BY BINARY_INTEGER;
11287  TYPE t_calling_app_doc_unique_ref4 IS TABLE OF
11288      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref4%TYPE
11289      INDEX BY BINARY_INTEGER;
11290  TYPE t_calling_app_doc_unique_ref5 IS TABLE OF
11291      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref5%TYPE
11292      INDEX BY BINARY_INTEGER;
11293  TYPE t_document_amount IS TABLE OF
11294      IBY_HOOK_DOCS_IN_PMT_T.document_amount%TYPE
11295      INDEX BY BINARY_INTEGER;
11296  TYPE t_document_currency_code IS TABLE OF
11297      IBY_HOOK_DOCS_IN_PMT_T.document_currency_code%TYPE
11298      INDEX BY BINARY_INTEGER;
11299  TYPE t_amount_withheld IS TABLE OF
11300      IBY_HOOK_DOCS_IN_PMT_T.amount_withheld%TYPE
11301      INDEX BY BINARY_INTEGER;
11302  TYPE t_dont_pay_flg IS TABLE OF
11303      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_flag%TYPE
11304      INDEX BY BINARY_INTEGER;
11305  TYPE t_dont_pay_reason_cd IS TABLE OF
11306      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_reason_code%TYPE
11307      INDEX BY BINARY_INTEGER;
11308  TYPE t_dont_pay_desc IS TABLE OF
11309      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_description%TYPE
11310      INDEX BY BINARY_INTEGER;
11311  TYPE t_pay_proc_trxn_type_code IS TABLE OF
11312      IBY_HOOK_DOCS_IN_PMT_T.pay_proc_trxn_type_code%TYPE
11313      INDEX BY BINARY_INTEGER;
11314  TYPE t_int_bank_account_id IS TABLE OF
11315      IBY_HOOK_DOCS_IN_PMT_T.internal_bank_account_id%TYPE
11316      INDEX BY BINARY_INTEGER;
11317  TYPE t_external_payee_id IS TABLE OF
11318      IBY_HOOK_DOCS_IN_PMT_T.ext_payee_id%TYPE
11319      INDEX BY BINARY_INTEGER;
11320  TYPE t_payeeparty_id IS TABLE OF
11321      IBY_HOOK_DOCS_IN_PMT_T.payee_party_id%TYPE
11322      INDEX BY BINARY_INTEGER;
11323  TYPE t_partysite_id IS TABLE OF
11324      IBY_HOOK_DOCS_IN_PMT_T.party_site_id%TYPE
11325      INDEX BY BINARY_INTEGER;
11326  TYPE t_suppliersite_id IS TABLE OF
11327      IBY_HOOK_DOCS_IN_PMT_T.supplier_site_id%TYPE
11328      INDEX BY BINARY_INTEGER;
11329  TYPE t_orgid IS TABLE OF
11330      IBY_HOOK_DOCS_IN_PMT_T.org_id%TYPE
11331      INDEX BY BINARY_INTEGER;
11332  TYPE t_orgtype IS TABLE OF
11333      IBY_HOOK_DOCS_IN_PMT_T.org_type%TYPE
11334      INDEX BY BINARY_INTEGER;
11335  TYPE t_ext_bank_account_id IS TABLE OF
11336      IBY_HOOK_DOCS_IN_PMT_T.external_bank_account_id%TYPE
11337      INDEX BY BINARY_INTEGER;
11338  TYPE t_payment_curr_discount_taken IS TABLE OF
11339      IBY_HOOK_DOCS_IN_PMT_T.payment_curr_discount_taken%TYPE
11340      INDEX BY BINARY_INTEGER;
11341  TYPE t_crtd_by IS TABLE OF
11342      IBY_HOOK_DOCS_IN_PMT_T.created_by%TYPE
11343      INDEX BY BINARY_INTEGER;
11344  TYPE t_crt_date IS TABLE OF
11345      IBY_HOOK_DOCS_IN_PMT_T.creation_date%TYPE
11346      INDEX BY BINARY_INTEGER;
11347  TYPE t_last_updt_by IS TABLE OF
11348      IBY_HOOK_DOCS_IN_PMT_T.last_updated_by%TYPE
11349      INDEX BY BINARY_INTEGER;
11350  TYPE t_last_updt_date IS TABLE OF
11351      IBY_HOOK_DOCS_IN_PMT_T.last_update_date%TYPE
11352      INDEX BY BINARY_INTEGER;
11353  TYPE t_last_updt_login IS TABLE OF
11354      IBY_HOOK_DOCS_IN_PMT_T.last_update_login%TYPE
11355      INDEX BY BINARY_INTEGER;
11356  TYPE t_object_ver_number IS TABLE OF
11357      IBY_HOOK_DOCS_IN_PMT_T.object_version_number%TYPE
11358      INDEX BY BINARY_INTEGER;
11359 
11360  l_payment_id                       t_pmt_id;
11361  l_document_payable_id              t_document_payable_id;
11362  l_calling_app_id                   t_call_app_id;
11363  l_calling_app_doc_unique_ref1      t_calling_app_doc_unique_ref1;
11364  l_calling_app_doc_unique_ref2      t_calling_app_doc_unique_ref2;
11365  l_calling_app_doc_unique_ref3      t_calling_app_doc_unique_ref3;
11366  l_calling_app_doc_unique_ref4      t_calling_app_doc_unique_ref4;
11367  l_calling_app_doc_unique_ref5      t_calling_app_doc_unique_ref5;
11368  l_document_amount                  t_document_amount;
11369  l_document_currency_code           t_document_currency_code;
11370  l_amount_withheld                  t_amount_withheld;
11371  l_dont_pay_flag                    t_dont_pay_flg;
11372  l_dont_pay_reason_code             t_dont_pay_reason_cd;
11373  l_dont_pay_description             t_dont_pay_desc;
11374  l_pay_proc_trxn_type_code          t_pay_proc_trxn_type_code;
11375  l_internal_bank_account_id         t_int_bank_account_id;
11376  l_ext_payee_id                     t_external_payee_id;
11377  l_payee_party_id                   t_payeeparty_id;
11378  l_party_site_id                    t_partysite_id;
11379  l_supplier_site_id                 t_suppliersite_id;
11380  l_org_id                           t_orgid;
11381  l_org_type                         t_orgtype;
11382  l_external_bank_account_id         t_external_bank_account_id;
11383  l_payment_curr_discount_taken      t_payment_curr_discount_taken;
11384  l_created_by                       t_crtd_by;
11385  l_creation_date                    t_crt_date;
11386  l_last_updated_by                  t_last_updt_by;
11387  l_last_update_date                 t_last_updt_date;
11388  l_last_update_login                t_last_updt_login;
11389  l_object_version_number            t_object_ver_number;
11390 
11391 
11392  BEGIN
11393 
11394      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11395 	print_debuginfo(l_module_name, 'ENTER');
11396 
11397      END IF;
11398      /*
11399       * Only successful payments need to be sent to the hook. The
11400       * loop below filters the failed payments/documents.
11401       */
11402      delete_paymentTab;
11403 
11404      FOR i in x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
11405 
11406          IF (x_paymentTab(i).payment_status <> PAY_STATUS_REJECTED) THEN
11407 
11408              /*
11409               * Copy successful payments into 'hook payments' array.
11410               */
11411              paymentTab.calling_app_id(l_succPayIndx) :=
11412                  p_cap_id;
11413              paymentTab.call_app_pay_service_req_cd(l_succPayIndx) :=
11414                  p_cap_payreq_cd;
11415              paymentTab.payment_service_request_id(l_succPayIndx) :=
11416                  x_paymentTab(i).payment_service_request_id;
11417              paymentTab.payment_id(l_succPayIndx) :=
11418                  x_paymentTab(i).payment_id;
11419              paymentTab.payment_amount(l_succPayIndx) :=
11420                  x_paymentTab(i).payment_amount;
11421              paymentTab.payment_currency_code(l_succPayIndx) :=
11422                  x_paymentTab(i).payment_currency_code;
11423              paymentTab.dont_pay_flg(l_succPayIndx) := 'N';
11424              paymentTab.dont_pay_reason_cd(l_succPayIndx) := null;
11425              paymentTab.dont_pay_desc(l_succPayIndx) := null;
11426              paymentTab.internal_bank_account_id(l_succPayIndx) :=
11427                  x_paymentTab(i).internal_bank_account_id;
11428              paymentTab.external_bank_account_id(l_succPayIndx) :=
11429                  x_paymentTab(i).external_bank_account_id;
11430              paymentTab.ext_payee_id(l_succPayIndx) :=
11431                  x_paymentTab(i).ext_payee_id;
11432              paymentTab.payee_party_id(l_succPayIndx) :=
11433                  x_paymentTab(i).payee_party_id;
11434              paymentTab.party_site_id(l_succPayIndx) :=
11435                  x_paymentTab(i).party_site_id;
11436              paymentTab.supplier_site_id(l_succPayIndx) :=
11437                  x_paymentTab(i).supplier_site_id;
11438              paymentTab.org_id(l_succPayIndx) :=
11439                  x_paymentTab(i).org_id;
11440              paymentTab.org_type(l_succPayIndx) :=
11441                  x_paymentTab(i).org_type;
11442              paymentTab.discount_amount_taken(l_succPayIndx) :=
11443                  x_paymentTab(i).discount_amount_taken;
11444              paymentTab.payment_date(l_succPayIndx) :=
11445                  x_paymentTab(i).payment_date;
11446              paymentTab.bank_charge_amount(l_succPayIndx) :=
11447                  x_paymentTab(i).bank_charge_amount;
11448              paymentTab.created_by(l_succPayIndx) :=
11449                  x_paymentTab(i).created_by;
11450              paymentTab.creation_date(l_succPayIndx) :=
11451                  x_paymentTab(i).creation_date;
11452              paymentTab.last_updated_by(l_succPayIndx) :=
11453                  x_paymentTab(i).last_updated_by;
11454              paymentTab.last_update_date(l_succPayIndx) :=
11455                  x_paymentTab(i).last_update_date;
11456              paymentTab.last_update_login(l_succPayIndx) :=
11457                  x_paymentTab(i).last_update_login;
11458              paymentTab.object_version_number(l_succPayIndx) :=
11459                  x_paymentTab(i).object_version_number;
11460 
11461              IF (x_docsInPmtTab.COUNT > 0) THEN
11462              FOR j in  x_docsInPmtTab.FIRST ..  x_docsInPmtTab.LAST LOOP
11463 
11464                  /*
11465                   * Some payments may contain failed documents (example,
11466                   * documents that have been failed by cascade because
11467                   * some related document has failed).
11468                   *
11469                   * Make sure that the hook only gets successful payments
11470                   * and successful documents within that payment.
11471                   */
11472                  IF (x_docsInPmtTab(j).payment_id =
11473                      x_paymentTab(i).payment_id AND
11474                          x_docsInPmtTab(j).document_status
11475                              = DOC_STATUS_PAY_CREATED) THEN
11476                      /*
11477                       * Copy documents of successful payment into
11478                       * 'hook documents' array.
11479                       */
11480                      x_hookDocsInPmtTab(l_succDocIndx).payment_id
11481                          := x_docsInPmtTab(j).payment_id;
11482                      x_hookDocsInPmtTab(l_succDocIndx).document_payable_id
11483                          := x_docsInPmtTab(j).document_id;
11484                      x_hookDocsInPmtTab(l_succDocIndx).calling_app_id
11485                          := x_docsInPmtTab(j).calling_app_id;
11486                      x_hookDocsInPmtTab(l_succDocIndx).
11487                          calling_app_doc_unique_ref1
11488                              := x_docsInPmtTab(j).calling_app_doc_id1;
11489                      x_hookDocsInPmtTab(l_succDocIndx).
11490                          calling_app_doc_unique_ref2
11491                              := x_docsInPmtTab(j).calling_app_doc_id2;
11492                      x_hookDocsInPmtTab(l_succDocIndx).
11493                          calling_app_doc_unique_ref3
11494                              := x_docsInPmtTab(j).calling_app_doc_id3;
11495                      x_hookDocsInPmtTab(l_succDocIndx).
11496                          calling_app_doc_unique_ref4
11497                              := x_docsInPmtTab(j).calling_app_doc_id4;
11498                      x_hookDocsInPmtTab(l_succDocIndx).
11499                          calling_app_doc_unique_ref5
11500                              := x_docsInPmtTab(j).calling_app_doc_id5;
11501                      x_hookDocsInPmtTab(l_succDocIndx).document_amount
11502                          := x_docsInPmtTab(j).document_amount;
11503                      x_hookDocsInPmtTab(l_succDocIndx).document_currency_code
11504                          := x_docsInPmtTab(j).document_currency;
11505                      x_hookDocsInPmtTab(l_succDocIndx).amount_withheld
11506                          := x_docsInPmtTab(j).amount_withheld;
11507                      x_hookDocsInPmtTab(l_succDocIndx).pay_proc_trxn_type_code
11508                          := x_docsInPmtTab(j).pay_proc_ttype_cd;
11509 
11510                      x_hookDocsInPmtTab(l_succDocIndx).internal_bank_account_id
11511                          := x_docsInPmtTab(j).int_bank_acct_id;
11512                      x_hookDocsInPmtTab(l_succDocIndx).ext_payee_id
11513                          := x_docsInPmtTab(j).ext_payee_id;
11514                      x_hookDocsInPmtTab(l_succDocIndx).payee_party_id
11515                          := x_docsInPmtTab(j).payee_id;
11516                      x_hookDocsInPmtTab(l_succDocIndx).party_site_id
11517                          := x_docsInPmtTab(j).payee_site_id;
11518                      x_hookDocsInPmtTab(l_succDocIndx).supplier_site_id
11519                          := x_docsInPmtTab(j).supplier_site_id;
11520                      x_hookDocsInPmtTab(l_succDocIndx).org_id
11521                          := x_docsInPmtTab(j).org_id;
11522                      x_hookDocsInPmtTab(l_succDocIndx).org_type
11523                          := x_docsInPmtTab(j).org_type;
11524                      x_hookDocsInPmtTab(l_succDocIndx).external_bank_account_id
11525                          := x_docsInPmtTab(j).ext_bank_acct_id;
11526                      x_hookDocsInPmtTab(l_succDocIndx).
11527                          payment_curr_discount_taken
11528                              := x_docsInPmtTab(j).pmt_curr_discount;
11529 
11530 
11531                      /*
11532                       * If we copied a document, increment document
11533                       * counter before next iteration.
11534                       */
11535                      l_succDocIndx := l_succDocIndx + 1;
11536 
11537                  END IF;
11538 
11539              END LOOP;
11540              END IF; -- if document count > 0
11541 
11542              /*
11543               * If we copied a payment, increment payment
11544               * counter before next iteration.
11545               */
11546              l_succPayIndx := l_succPayIndx + 1;
11547 
11548          END IF;
11549 
11550      END LOOP;
11551 
11552      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11553 	print_debuginfo(l_module_name, '# orig pmts: '
11554          || x_paymentTab.COUNT || ', # hook pmts: '
11555          || paymentTab.calling_app_id.COUNT);
11556 
11557     END IF;
11558 
11559      /*
11560       * The hook data is passed to the external app via global
11561       * temp tables IBY_HOOK_PAYMENTS_TEMP and IBY_HOOK_DOCS_IN_PMT_TEMP.
11562       * Populate these temp tables with data from our hook data
11563       * structures.
11564       */
11565      IF (paymentTab.calling_app_id.COUNT > 0) THEN
11566          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11567 		print_debuginfo(l_module_name, 'Populating global temp tables with'
11568              || ' hook data.');
11569          END IF;
11570 
11571      ELSE
11572          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11573 	 print_debuginfo(l_module_name, 'No payments to pass to hook. '
11574              || 'Exiting ..');
11575          print_debuginfo(l_module_name, 'EXIT');
11576          END IF;
11577          RETURN;
11578      END IF;
11579 
11580      /*
11581       * First delete any existing records in these
11582       * temp tables so that they do not interfere with
11583       * our processing.
11584       */
11585      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11586 	 print_debuginfo(l_module_name, 'Deleting existing records in '
11587          || 'hook tables .. ');
11588      END IF;
11589 
11590      DELETE IBY_HOOK_DOCS_IN_PMT_T;
11591      DELETE IBY_HOOK_PAYMENTS_T;
11592      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11593 	 print_debuginfo(l_module_name, 'Finished deleting records from '
11594          || 'hook tables .. ');
11595      END IF;
11596 
11597      /*
11598       * Create arrays for each column of the IBY_HOOK_PAYMENTS_T table.
11599       * These arrays will be used in the bulk insert.
11600       */
11601      IF (x_hookDocsInPmtTab.COUNT > 0) THEN
11602      FOR i in x_hookDocsInPmtTab.FIRST..x_hookDocsInPmtTab.LAST LOOP
11603 
11604          l_payment_id(i)
11605              := x_hookDocsInPmtTab(i).payment_id;
11606          l_document_payable_id(i)
11607              := x_hookDocsInPmtTab(i).document_payable_id;
11608          l_calling_app_id(i)
11609              := x_hookDocsInPmtTab(i).calling_app_id;
11610          l_calling_app_doc_unique_ref1(i)
11611              := x_hookDocsInPmtTab(i).calling_app_doc_unique_ref1;
11612          l_calling_app_doc_unique_ref2(i)
11613              := x_hookDocsInPmtTab(i).calling_app_doc_unique_ref2;
11614          l_calling_app_doc_unique_ref3(i)
11615              := x_hookDocsInPmtTab(i).calling_app_doc_unique_ref3;
11616          l_calling_app_doc_unique_ref4(i)
11617              := x_hookDocsInPmtTab(i).calling_app_doc_unique_ref4;
11618          l_calling_app_doc_unique_ref5(i)
11619              := x_hookDocsInPmtTab(i).calling_app_doc_unique_ref5;
11620          l_document_amount(i)
11621              := x_hookDocsInPmtTab(i).document_amount;
11622          l_document_currency_code(i)
11623              := x_hookDocsInPmtTab(i).document_currency_code;
11624          l_amount_withheld(i)
11625              := NVL(x_hookDocsInPmtTab(i).amount_withheld, 0);
11626          l_dont_pay_flag(i)
11627              := NVL(x_hookDocsInPmtTab(i).dont_pay_flag, 'N');
11628          l_dont_pay_reason_code(i)
11629              := x_hookDocsInPmtTab(i).dont_pay_reason_code;
11630          l_dont_pay_description(i)
11631              := x_hookDocsInPmtTab(i).dont_pay_description;
11632          l_pay_proc_trxn_type_code(i)
11633              := x_hookDocsInPmtTab(i).pay_proc_trxn_type_code;
11634          l_internal_bank_account_id(i)
11635              := x_hookDocsInPmtTab(i).internal_bank_account_id;
11636          l_ext_payee_id(i)
11637              := x_hookDocsInPmtTab(i).ext_payee_id;
11638          l_payee_party_id(i)
11639              := x_hookDocsInPmtTab(i).payee_party_id;
11640          l_party_site_id(i)
11641              := x_hookDocsInPmtTab(i).party_site_id;
11642          l_supplier_site_id(i)
11643              := x_hookDocsInPmtTab(i).supplier_site_id;
11644          l_org_id(i)
11645              := x_hookDocsInPmtTab(i).org_id;
11646          l_org_type(i)
11647              := x_hookDocsInPmtTab(i).org_type;
11648          l_external_bank_account_id(i)
11649              := x_hookDocsInPmtTab(i).external_bank_account_id;
11650          l_payment_curr_discount_taken(i)
11651              := x_hookDocsInPmtTab(i).payment_curr_discount_taken;
11652          l_created_by(i)
11653              := NVL(x_hookDocsInPmtTab(i).created_by, fnd_global.user_id);
11654          l_creation_date(i)
11655              := NVL(x_hookDocsInPmtTab(i).creation_date, sysdate);
11656          l_last_updated_by(i)
11657              := NVL(x_hookDocsInPmtTab(i).last_updated_by, fnd_global.user_id);
11658          l_last_update_date(i)
11659              := NVL(x_hookDocsInPmtTab(i).last_update_date, sysdate);
11660          l_last_update_login(i)
11661              := NVL(x_hookDocsInPmtTab(i).last_update_login,
11662                     fnd_global.user_id);
11663          l_object_version_number(i)
11664              := NVL(x_hookDocsInPmtTab(i).object_version_number, 1);
11665 
11666      END LOOP;
11667      END IF; -- if document count > 0
11668 
11669 
11670      /* insert documents */
11671      /*
11672       * Bulk insert records into IBY_HOOK_DOCS_IN_PMT_T using named
11673       * columns. This will avoid any dependency in column order.
11674       */
11675      IF (x_hookDocsInPmtTab.COUNT > 0) THEN
11676      FORALL i in x_hookDocsInPmtTab.FIRST..x_hookDocsInPmtTab.LAST
11677          INSERT INTO IBY_HOOK_DOCS_IN_PMT_T
11678              (
11679              payment_id,
11680              document_payable_id,
11681              calling_app_id,
11682              calling_app_doc_unique_ref1,
11683              calling_app_doc_unique_ref2,
11684              calling_app_doc_unique_ref3,
11685              calling_app_doc_unique_ref4,
11686              calling_app_doc_unique_ref5,
11687              document_amount,
11688              document_currency_code,
11689              amount_withheld,
11690              dont_pay_flag,
11691              dont_pay_reason_code,
11692              dont_pay_description,
11693              pay_proc_trxn_type_code,
11694              internal_bank_account_id,
11695              ext_payee_id,
11696              payee_party_id,
11697              party_site_id,
11698              supplier_site_id,
11699              org_id,
11700              org_type,
11701              external_bank_account_id,
11702              payment_curr_discount_taken,
11703              created_by,
11704              creation_date,
11705              last_updated_by,
11706              last_update_date,
11707              last_update_login,
11708              object_version_number
11709              )
11710          VALUES
11711              (
11712              l_payment_id(i),
11713              l_document_payable_id(i),
11714              l_calling_app_id(i),
11715              l_calling_app_doc_unique_ref1(i),
11716              l_calling_app_doc_unique_ref2(i),
11717              l_calling_app_doc_unique_ref3(i),
11718              l_calling_app_doc_unique_ref4(i),
11719              l_calling_app_doc_unique_ref5(i),
11720              l_document_amount(i),
11721              l_document_currency_code(i),
11722              l_amount_withheld(i),
11723              l_dont_pay_flag(i),
11724              l_dont_pay_reason_code(i),
11725              l_dont_pay_description(i),
11726              l_pay_proc_trxn_type_code(i),
11727              l_internal_bank_account_id(i),
11728              l_ext_payee_id(i),
11729              l_payee_party_id(i),
11730              l_party_site_id(i),
11731              l_supplier_site_id(i),
11732              l_org_id(i),
11733              l_org_type(i),
11734              l_external_bank_account_id(i),
11735              l_payment_curr_discount_taken(i),
11736              l_created_by(i),
11737              l_creation_date(i),
11738              l_last_updated_by(i),
11739              l_last_update_date(i),
11740              l_last_update_login(i),
11741              l_object_version_number(i)
11742              )
11743              ;
11744      END IF; -- if hook document count > 0
11745 
11746      /*
11747       * Bulk insert records into IBY_HOOK_PAYMENTS_T using named
11748       * columns. This will avoid any dependency in column order.
11749       */
11750 
11751 --     FOR i in paymentTab.calling_app_id.FIRST .. paymentTab.calling_app_id.LAST
11752 
11753      FORALL i in paymentTab.calling_app_id.FIRST .. paymentTab.calling_app_id.LAST
11754          INSERT INTO IBY_HOOK_PAYMENTS_T
11755              (
11756              calling_app_id,
11757              call_app_pay_service_req_code,
11758              payment_service_request_id,
11759              payment_id,
11760              payment_amount,
11761              payment_currency_code,
11762              dont_pay_flag,
11763              dont_pay_reason_code,
11764              dont_pay_description,
11765              internal_bank_account_id,
11766              ext_payee_id,
11767              payee_party_id,
11768              party_site_id,
11769              supplier_site_id,
11770              org_id,
11771              org_type,
11772              external_bank_account_id,
11773              discount_amount_taken,
11774              payment_date,
11775              bank_charge_amount,
11776              created_by,
11777              creation_date,
11778              last_updated_by,
11779              last_update_date,
11780              last_update_login,
11781              object_version_number
11782              )
11783              VALUES
11784              (
11785              paymentTab.calling_app_id(i),
11786              paymentTab.call_app_pay_service_req_cd(i),
11787              paymentTab.payment_service_request_id(i),
11788              paymentTab.payment_id(i),
11789              paymentTab.payment_amount(i),
11790              paymentTab.payment_currency_code(i),
11791              paymentTab.dont_pay_flg(i),
11792              paymentTab.dont_pay_reason_cd(i),
11793              paymentTab.dont_pay_desc(i),
11794              paymentTab.internal_bank_account_id(i),
11795              paymentTab.ext_payee_id(i),
11796              paymentTab.payee_party_id(i),
11797              paymentTab.party_site_id(i),
11798              paymentTab.supplier_site_id(i),
11799              paymentTab.org_id(i),
11800              paymentTab.org_type(i),
11801              paymentTab.external_bank_account_id(i),
11802              paymentTab.discount_amount_taken(i),
11803              paymentTab.payment_date(i),
11804              paymentTab.bank_charge_amount(i),
11805              paymentTab.created_by(i),
11806              paymentTab.creation_date(i),
11807              paymentTab.last_updated_by(i),
11808              paymentTab.last_update_date(i),
11809              paymentTab.last_update_login(i),
11810              paymentTab.object_version_number(i)
11811              );
11812 
11813      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11814 	 print_debuginfo(l_module_name, 'Finished populating global temp tables.');
11815      END IF;
11816 
11817 --     delete_paymentTab;
11818 
11819      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11820 	 print_debuginfo(l_module_name, 'Global temp tables were'
11821          || ' populated with '
11822          || x_hookDocsInPmtTab.COUNT || ' docs and '
11823          || paymentTab.calling_app_id.COUNT   || ' payments.');
11824 
11825      /* log the data that we pass to the hook */
11826          print_debuginfo(l_module_name, 'List of docs/pmts passed to hook: ');
11827 
11828      IF (x_hookDocsInPmtTab.COUNT > 0) THEN
11829      FOR i in x_hookDocsInPmtTab.FIRST..x_hookDocsInPmtTab.LAST LOOP
11830          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11831          print_debuginfo(l_module_name, 'Payment: '
11832              || x_hookDocsInPmtTab(i).payment_id
11833              || ', document: '
11834              || x_hookDocsInPmtTab(i).document_payable_id
11835              || ', document amt: '
11836              || x_hookDocsInPmtTab(i).document_amount
11837              || ', document curr: '
11838              || x_hookDocsInPmtTab(i).document_currency_code
11839              );
11840           END IF;
11841      END LOOP;
11842      END IF;
11843 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
11844      print_debuginfo(l_module_name, x_hookDocsInPmtTab.COUNT
11845          || ' docs and '
11846          || paymentTab.calling_app_id.COUNT || ' payments'
11847          || ' were inserted into global temp tables.'
11848          );
11849 
11850      print_debuginfo(l_module_name, 'EXIT');
11851 
11852 END IF;
11853      END IF; -- if stmt level logging
11854  END performPreHookProcess;
11855 
11856 /*--------------------------------------------------------------------
11857  | NAME:
11858  |     performPreHookProcess
11859  |
11860  | PURPOSE:
11861  |     Inserts all successfuly validated payments into
11862  |     IBY_HOOK_PAYMENTS_TEMP. This is a temporary table that the
11863  |     calling app can access to see what payments have been
11864  |     created. The calling app can also update the payments / fail
11865  |     the payments in the temporary table, and the payment creation
11866  |     program will update it's payments accordingly.
11867  |
11868  | PARAMETERS:
11869  |     IN
11870  |
11871  |     OUT
11872  |
11873  |
11874  | RETURNS:
11875  |
11876  | NOTES:
11877  |
11878  *---------------------------------------------------------------------*/
11879  PROCEDURE performPreHookProcess(
11880      p_cap_payreq_cd     IN            VARCHAR2,
11881      p_ppr_id	         IN	       NUMBER,
11882      l_prehook_cnt       OUT     NOCOPY      NUMBER,
11883      p_cap_id            IN            NUMBER
11884  --    x_paymentTab        IN OUT NOCOPY paymentTabType,
11885  --     x_docsInPmtTab      IN OUT NOCOPY docsInPaymentTabType,
11886  --    x_hookPaymentTab    IN OUT NOCOPY hookPaymentTabType
11887      )
11888  IS
11889 
11890  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.performPreHookProcess';
11891  l_succPayIndx NUMBER := 1;
11892  l_succDocIndx NUMBER := 1;
11893 
11894 /*
11895  l_calling_app_ids                 t_calling_app_id;
11896  l_call_app_pay_service_req_cds    t_call_app_pay_service_req_cd;
11897  l_payment_service_request_ids     t_payment_service_request_id;
11898  l_payment_ids                     t_payment_id;
11899  l_payment_amounts                 t_payment_amount;
11900  l_payment_currency_codes          t_payment_currency_code;
11901  l_dont_pay_flags                  t_dont_pay_flag;
11902  l_dont_pay_reason_codes           t_dont_pay_reason_code;
11903  l_dont_pay_descriptions           t_dont_pay_description;
11904  l_internal_bank_account_ids       t_internal_bank_account_id;
11905  l_ext_payee_ids                   t_ext_payee_id;
11906  l_payee_party_ids                 t_payee_party_id;
11907  l_party_site_ids                  t_party_site_id;
11908  l_supplier_site_ids               t_supplier_site_id;
11909  l_org_ids                         t_org_id;
11910  l_org_types                       t_org_type;
11911  l_external_bank_account_ids       t_external_bank_account_id;
11912  l_discount_amount_takens          t_discount_amount_taken;
11913  l_payment_dates                   t_payment_date;
11914  l_bank_charge_amounts             t_bank_charge_amount;
11915  l_created_bys                     t_created_by;
11916  l_creation_dates                  t_creation_date;
11917  l_last_updated_bys                t_last_updated_by;
11918  l_last_update_dates               t_last_update_date;
11919  l_last_update_logins              t_last_update_login;
11920  l_object_version_numbers          t_object_version_number;
11921 */
11922 
11923  TYPE t_pmt_id IS TABLE OF
11924      IBY_HOOK_DOCS_IN_PMT_T.payment_id%TYPE
11925      INDEX BY BINARY_INTEGER;
11926  TYPE t_document_payable_id IS TABLE OF
11927      IBY_HOOK_DOCS_IN_PMT_T.document_payable_id%TYPE
11928      INDEX BY BINARY_INTEGER;
11929  TYPE t_call_app_id IS TABLE OF
11930      IBY_HOOK_DOCS_IN_PMT_T.calling_app_id%TYPE
11931      INDEX BY BINARY_INTEGER;
11932  TYPE t_calling_app_doc_unique_ref1 IS TABLE OF
11933      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref1%TYPE
11934      INDEX BY BINARY_INTEGER;
11935  TYPE t_calling_app_doc_unique_ref2 IS TABLE OF
11936      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref2%TYPE
11937      INDEX BY BINARY_INTEGER;
11938  TYPE t_calling_app_doc_unique_ref3 IS TABLE OF
11939      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref3%TYPE
11940      INDEX BY BINARY_INTEGER;
11941  TYPE t_calling_app_doc_unique_ref4 IS TABLE OF
11942      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref4%TYPE
11943      INDEX BY BINARY_INTEGER;
11944  TYPE t_calling_app_doc_unique_ref5 IS TABLE OF
11945      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref5%TYPE
11946      INDEX BY BINARY_INTEGER;
11947  TYPE t_document_amount IS TABLE OF
11948      IBY_HOOK_DOCS_IN_PMT_T.document_amount%TYPE
11949      INDEX BY BINARY_INTEGER;
11950  TYPE t_document_currency_code IS TABLE OF
11951      IBY_HOOK_DOCS_IN_PMT_T.document_currency_code%TYPE
11952      INDEX BY BINARY_INTEGER;
11953  TYPE t_amount_withheld IS TABLE OF
11954      IBY_HOOK_DOCS_IN_PMT_T.amount_withheld%TYPE
11955      INDEX BY BINARY_INTEGER;
11956  TYPE t_dont_pay_flg IS TABLE OF
11957      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_flag%TYPE
11958      INDEX BY BINARY_INTEGER;
11959  TYPE t_dont_pay_reason_cd IS TABLE OF
11960      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_reason_code%TYPE
11961      INDEX BY BINARY_INTEGER;
11962  TYPE t_dont_pay_desc IS TABLE OF
11963      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_description%TYPE
11964      INDEX BY BINARY_INTEGER;
11965  TYPE t_pay_proc_trxn_type_code IS TABLE OF
11966      IBY_HOOK_DOCS_IN_PMT_T.pay_proc_trxn_type_code%TYPE
11967      INDEX BY BINARY_INTEGER;
11968  TYPE t_int_bank_account_id IS TABLE OF
11969      IBY_HOOK_DOCS_IN_PMT_T.internal_bank_account_id%TYPE
11970      INDEX BY BINARY_INTEGER;
11971  TYPE t_external_payee_id IS TABLE OF
11972      IBY_HOOK_DOCS_IN_PMT_T.ext_payee_id%TYPE
11973      INDEX BY BINARY_INTEGER;
11974  TYPE t_payeeparty_id IS TABLE OF
11975      IBY_HOOK_DOCS_IN_PMT_T.payee_party_id%TYPE
11976      INDEX BY BINARY_INTEGER;
11977  TYPE t_partysite_id IS TABLE OF
11978      IBY_HOOK_DOCS_IN_PMT_T.party_site_id%TYPE
11979      INDEX BY BINARY_INTEGER;
11980  TYPE t_suppliersite_id IS TABLE OF
11981      IBY_HOOK_DOCS_IN_PMT_T.supplier_site_id%TYPE
11982      INDEX BY BINARY_INTEGER;
11983  TYPE t_orgid IS TABLE OF
11984      IBY_HOOK_DOCS_IN_PMT_T.org_id%TYPE
11985      INDEX BY BINARY_INTEGER;
11986  TYPE t_orgtype IS TABLE OF
11987      IBY_HOOK_DOCS_IN_PMT_T.org_type%TYPE
11988      INDEX BY BINARY_INTEGER;
11989  TYPE t_ext_bank_account_id IS TABLE OF
11990      IBY_HOOK_DOCS_IN_PMT_T.external_bank_account_id%TYPE
11991      INDEX BY BINARY_INTEGER;
11992  TYPE t_payment_curr_discount_taken IS TABLE OF
11993      IBY_HOOK_DOCS_IN_PMT_T.payment_curr_discount_taken%TYPE
11994      INDEX BY BINARY_INTEGER;
11995  TYPE t_crtd_by IS TABLE OF
11996      IBY_HOOK_DOCS_IN_PMT_T.created_by%TYPE
11997      INDEX BY BINARY_INTEGER;
11998  TYPE t_crt_date IS TABLE OF
11999      IBY_HOOK_DOCS_IN_PMT_T.creation_date%TYPE
12000      INDEX BY BINARY_INTEGER;
12001  TYPE t_last_updt_by IS TABLE OF
12002      IBY_HOOK_DOCS_IN_PMT_T.last_updated_by%TYPE
12003      INDEX BY BINARY_INTEGER;
12004  TYPE t_last_updt_date IS TABLE OF
12005      IBY_HOOK_DOCS_IN_PMT_T.last_update_date%TYPE
12006      INDEX BY BINARY_INTEGER;
12007  TYPE t_last_updt_login IS TABLE OF
12008      IBY_HOOK_DOCS_IN_PMT_T.last_update_login%TYPE
12009      INDEX BY BINARY_INTEGER;
12010  TYPE t_object_ver_number IS TABLE OF
12011      IBY_HOOK_DOCS_IN_PMT_T.object_version_number%TYPE
12012      INDEX BY BINARY_INTEGER;
12013 
12014  l_payment_id                       t_pmt_id;
12015  l_document_payable_id              t_document_payable_id;
12016  l_calling_app_id                   t_call_app_id;
12017  l_calling_app_doc_unique_ref1      t_calling_app_doc_unique_ref1;
12018  l_calling_app_doc_unique_ref2      t_calling_app_doc_unique_ref2;
12019  l_calling_app_doc_unique_ref3      t_calling_app_doc_unique_ref3;
12020  l_calling_app_doc_unique_ref4      t_calling_app_doc_unique_ref4;
12021  l_calling_app_doc_unique_ref5      t_calling_app_doc_unique_ref5;
12022  l_document_amount                  t_document_amount;
12023  l_document_currency_code           t_document_currency_code;
12024  l_amount_withheld                  t_amount_withheld;
12025  l_dont_pay_flag                    t_dont_pay_flg;
12026  l_dont_pay_reason_code             t_dont_pay_reason_cd;
12027  l_dont_pay_description             t_dont_pay_desc;
12028  l_pay_proc_trxn_type_code          t_pay_proc_trxn_type_code;
12029  l_internal_bank_account_id         t_int_bank_account_id;
12030  l_ext_payee_id                     t_external_payee_id;
12031  l_payee_party_id                   t_payeeparty_id;
12032  l_party_site_id                    t_partysite_id;
12033  l_supplier_site_id                 t_suppliersite_id;
12034  l_org_id                           t_orgid;
12035  l_org_type                         t_orgtype;
12036  l_external_bank_account_id         t_external_bank_account_id;
12037  l_payment_curr_discount_taken      t_payment_curr_discount_taken;
12038  l_created_by                       t_crtd_by;
12039  l_creation_date                    t_crt_date;
12040  l_last_updated_by                  t_last_updt_by;
12041  l_last_update_date                 t_last_updt_date;
12042  l_last_update_login                t_last_updt_login;
12043  l_object_version_number            t_object_ver_number;
12044 
12045 
12046 
12047  BEGIN
12048 
12049      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12050 	print_debuginfo(l_module_name, 'ENTER- overloaded prehook');
12051 
12052      END IF;
12053      /*
12054       * Only successful payments need to be sent to the hook. The
12055       * loop below filters the failed payments/documents.
12056       */
12057    --  delete_paymentTab;
12058    /*
12059 
12060      FOR i in x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
12061 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12062 print_debuginfo(l_module_name,'Status of pmt id'||x_paymentTab(i).payment_id||'-'||x_paymentTab(i).payment_status);
12063 END IF;
12064          IF (x_paymentTab(i).payment_status <> PAY_STATUS_REJECTED) THEN
12065 
12066 
12067              paymentTab.calling_app_id(l_succPayIndx) :=
12068                  p_cap_id;
12069              paymentTab.call_app_pay_service_req_cd(l_succPayIndx) :=
12070                  p_cap_payreq_cd;
12071              paymentTab.payment_service_request_id(l_succPayIndx) :=
12072                  x_paymentTab(i).payment_service_request_id;
12073              paymentTab.payment_id(l_succPayIndx) :=
12074                  x_paymentTab(i).payment_id;
12075              paymentTab.payment_amount(l_succPayIndx) :=
12076                  x_paymentTab(i).payment_amount;
12077              paymentTab.payment_currency_code(l_succPayIndx) :=
12078                  x_paymentTab(i).payment_currency_code;
12079              paymentTab.dont_pay_flg(l_succPayIndx) := 'N';
12080              paymentTab.dont_pay_reason_cd(l_succPayIndx) := null;
12081              paymentTab.dont_pay_desc(l_succPayIndx) := null;
12082              paymentTab.internal_bank_account_id(l_succPayIndx) :=
12083                  x_paymentTab(i).internal_bank_account_id;
12084              paymentTab.external_bank_account_id(l_succPayIndx) :=
12085                  x_paymentTab(i).external_bank_account_id;
12086              paymentTab.ext_payee_id(l_succPayIndx) :=
12087                  x_paymentTab(i).ext_payee_id;
12088              paymentTab.payee_party_id(l_succPayIndx) :=
12089                  x_paymentTab(i).payee_party_id;
12090              paymentTab.party_site_id(l_succPayIndx) :=
12091                  x_paymentTab(i).party_site_id;
12092              paymentTab.supplier_site_id(l_succPayIndx) :=
12093                  x_paymentTab(i).supplier_site_id;
12094              paymentTab.org_id(l_succPayIndx) :=
12095                  x_paymentTab(i).org_id;
12096              paymentTab.org_type(l_succPayIndx) :=
12097                  x_paymentTab(i).org_type;
12098              paymentTab.discount_amount_taken(l_succPayIndx) :=
12099                  x_paymentTab(i).discount_amount_taken;
12100              paymentTab.payment_date(l_succPayIndx) :=
12101                  x_paymentTab(i).payment_date;
12102              paymentTab.bank_charge_amount(l_succPayIndx) :=
12103                  x_paymentTab(i).bank_charge_amount;
12104              paymentTab.created_by(l_succPayIndx) :=
12105                  x_paymentTab(i).created_by;
12106              paymentTab.creation_date(l_succPayIndx) :=
12107                  x_paymentTab(i).creation_date;
12108              paymentTab.last_updated_by(l_succPayIndx) :=
12109                  x_paymentTab(i).last_updated_by;
12110              paymentTab.last_update_date(l_succPayIndx) :=
12111                  x_paymentTab(i).last_update_date;
12112              paymentTab.last_update_login(l_succPayIndx) :=
12113                  x_paymentTab(i).last_update_login;
12114              paymentTab.object_version_number(l_succPayIndx) :=
12115                  x_paymentTab(i).object_version_number;
12116 
12117              l_succPayIndx := l_succPayIndx + 1;
12118 
12119         END IF;
12120 
12121      END LOOP;
12122 
12123      */
12124 
12125 
12126 
12127      /*
12128       * The hook data is passed to the external app via global
12129       * temp tables IBY_HOOK_PAYMENTS_TEMP and IBY_HOOK_DOCS_IN_PMT_TEMP.
12130       * Populate these temp tables with data from our hook data
12131       * structures.
12132       */
12133      IF (IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT > 0) THEN
12134          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12135 		print_debuginfo(l_module_name, 'Populating global temp tables with'
12136              || ' hook data.');
12137          END IF;
12138 
12139      ELSE
12140          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12141 	 print_debuginfo(l_module_name, 'No payments to pass to hook. '
12142              || 'Exiting ..');
12143          print_debuginfo(l_module_name, 'EXIT');
12144          END IF;
12145          RETURN;
12146      END IF;
12147 
12148      /*
12149       * First delete any existing records in these
12150       * temp tables so that they do not interfere with
12151       * our processing.
12152       */
12153      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12154 	 print_debuginfo(l_module_name, 'Deleting existing records in '
12155          || 'hook tables .. ');
12156      END IF;
12157 
12158      DELETE IBY_HOOK_DOCS_IN_PMT_T;
12159      DELETE IBY_HOOK_PAYMENTS_T;
12160      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12161 	 print_debuginfo(l_module_name, 'Finished deleting records from '
12162          || 'hook tables .. ');
12163      END IF;
12164 
12165     /*
12166 
12167      /*
12168       * Bulk insert records into IBY_HOOK_PAYMENTS_T using named
12169       * columns. This will avoid any dependency in column order.
12170       */
12171 
12172 --     FOR i in paymentTab.calling_app_id.FIRST .. paymentTab.calling_app_id.LAST
12173 
12174 --    FORALL i in paymentTab.payment_id.FIRST .. paymentTab.payment_id.LAST
12175          INSERT INTO IBY_HOOK_PAYMENTS_T
12176              (
12177              calling_app_id,
12178              call_app_pay_service_req_code,
12179              payment_service_request_id,
12180              payment_id,
12181              payment_amount,
12182              payment_currency_code,
12183              dont_pay_flag,
12184              dont_pay_reason_code,
12185              dont_pay_description,
12186              internal_bank_account_id,
12187              ext_payee_id,
12188              payee_party_id,
12189              party_site_id,
12190              supplier_site_id,
12191              org_id,
12192              org_type,
12193              external_bank_account_id,
12194              discount_amount_taken,
12195              payment_date,
12196              bank_charge_amount,
12197              created_by,
12198              creation_date,
12199              last_updated_by,
12200              last_update_date,
12201              last_update_login,
12202              object_version_number
12203              )
12204              (
12205 	     SELECT
12206              p_cap_id,
12207              p_cap_payreq_cd,
12208              payment_service_request_id,
12209              payment_id,
12210              payment_amount,
12211              payment_currency_code,
12212              'N',
12213              null,
12214 	     null,
12215              internal_bank_account_id,
12216              ext_payee_id,
12217              payee_party_id,
12218              party_site_id,
12219              supplier_site_id,
12220              org_id,
12221              org_type,
12222              external_bank_account_id,
12223              discount_amount_taken,
12224              payment_date,
12225              bank_charge_amount,
12226              created_by,
12227              creation_date,
12228              last_updated_by,
12229              last_update_date,
12230              last_update_login,
12231              object_version_number
12232 	     FROM
12233 	     IBY_PAYMENTS_ALL
12234 	     where
12235 	     payment_status <> PAY_STATUS_REJECTED AND
12236 	     PAYMENT_SERVICE_REQUEST_ID = p_ppr_id
12237 	     );
12238     l_prehook_cnt := SQL%ROWCOUNT;
12239 
12240 
12241 	/*
12242 	OPEN check_hook_pmt;
12243 	  LOOP
12244 	    FETCH check_hook_pmt INTO pmt_id, pmt_amt;
12245 	    EXIT WHEN check_hook_pmt%NOTFOUND;
12246 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12247     	    print_debuginfo(l_module_name, 'pmt_id-'|| pmt_id || 'pmt_amt-'|| pmt_amt);
12248 			END IF;
12249 	  END LOOP;
12250 	  CLOSE check_hook_pmt;
12251 	*/
12252 
12253   INSERT INTO iby_hook_docs_in_pmt_t(
12254              PAYMENT_ID,
12255               DOCUMENT_PAYABLE_ID,
12256               CALLING_APP_ID,
12257               CALLING_APP_DOC_UNIQUE_REF1,
12258               CALLING_APP_DOC_UNIQUE_REF2,
12259               CALLING_APP_DOC_UNIQUE_REF3,
12260               CALLING_APP_DOC_UNIQUE_REF4,
12261               CALLING_APP_DOC_UNIQUE_REF5,
12262               DOCUMENT_AMOUNT,
12263               DOCUMENT_CURRENCY_CODE,
12264               AMOUNT_WITHHELD,
12265               DONT_PAY_FLAG,
12266               DONT_PAY_REASON_CODE,
12267               DONT_PAY_DESCRIPTION,
12268               PAY_PROC_TRXN_TYPE_CODE,
12269               INTERNAL_BANK_ACCOUNT_ID,
12270               EXT_PAYEE_ID,
12271               PAYEE_PARTY_ID,
12272               PARTY_SITE_ID,
12273               SUPPLIER_SITE_ID,
12274               ORG_ID,
12275               ORG_TYPE,
12276               EXTERNAL_BANK_ACCOUNT_ID,
12277               PAYMENT_CURR_DISCOUNT_TAKEN,
12278               CREATED_BY,
12279               CREATION_DATE,
12280               LAST_UPDATED_BY,
12281               LAST_UPDATE_DATE,
12282               LAST_UPDATE_LOGIN,
12283               OBJECT_VERSION_NUMBER
12284              )
12285  SELECT
12286         src.PAYMENT_ID,
12287               src.DOCUMENT_PAYABLE_ID,
12288               src.CALLING_APP_ID,
12289               src.CALLING_APP_DOC_UNIQUE_REF1,
12290               src.CALLING_APP_DOC_UNIQUE_REF2,
12291               src.CALLING_APP_DOC_UNIQUE_REF3,
12292               src.CALLING_APP_DOC_UNIQUE_REF4,
12293               src.CALLING_APP_DOC_UNIQUE_REF5,
12294               src.DOCUMENT_AMOUNT,
12295               src.DOCUMENT_CURRENCY_CODE,
12296               src.AMOUNT_WITHHELD,
12297               src.DONT_PAY_FLAG,
12298               src.DONT_PAY_REASON_CODE,
12299               src.DONT_PAY_DESCRIPTION,
12300               src.PAY_PROC_TRXN_TYPE_CODE,
12301               src.INTERNAL_BANK_ACCOUNT_ID,
12302               src.EXT_PAYEE_ID,
12303               src.PAYEE_PARTY_ID,
12304               src.PARTY_SITE_ID,
12305               src.SUPPLIER_SITE_ID,
12306               src.ORG_ID,
12307               src.ORG_TYPE,
12308               src.EXTERNAL_BANK_ACCOUNT_ID,
12309               src.PAYMENT_CURR_DISCOUNT_TAKEN,
12310               src.CREATED_BY,
12311               src.CREATION_DATE,
12312               src.LAST_UPDATED_BY,
12313               src.LAST_UPDATE_DATE,
12314               src.LAST_UPDATE_LOGIN,
12315               src.OBJECT_VERSION_NUMBER
12316  FROM iby_docs_in_pmt_gt src, iby_hook_payments_t ihpt
12317  WHERE src.payment_id = ihpt.payment_id
12318  AND src.document_status = DOC_STATUS_PAY_CREATED;
12319 
12320  l_DocsInPmtCount := SQL%ROWCOUNT;
12321 
12322  --Select count(*) into l_DocsInPmtCount
12323  --from iby_hook_docs_in_pmt_t;
12324 
12325      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12326      print_debuginfo(l_module_name, 'Finished populating global temp tables.');
12327 
12328 --     delete_paymentTab;
12329 
12330      print_debuginfo(l_module_name, 'Global temp tables were'
12331          || ' populated with '
12332          || l_DocsInPmtCount || ' docs and '
12333          || l_prehook_cnt || ' payments');
12334 
12335         IF(l_prehook_cnt = 0) THEN
12336 
12337              print_debuginfo(l_module_name, 'Fatal error - Payment '
12338                  || 'count has come in the Payments GT Table as: '
12339                  || l_prehook_cnt
12340                  --,FND_LOG.LEVEL_UNEXPECTED
12341                  );
12342 
12343            /*  print_debuginfo(l_module_name, 'Aborting program ..',
12344                  FND_LOG.LEVEL_UNEXPECTED);
12345 
12346              APP_EXCEPTION.RAISE_EXCEPTION;   */
12347 
12348         END IF;
12349 
12350      print_debuginfo(l_module_name, 'EXIT');
12351      END IF;
12352   EXCEPTION
12353    WHEN OTHERS THEN
12354    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
12355                  FND_LOG.LEVEL_UNEXPECTED);
12356              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
12357                  FND_LOG.LEVEL_UNEXPECTED);
12358    print_debuginfo(l_module_name, l_module_name||':Exception while performing performPreHookProcess');
12359    RAISE;
12360  END performPreHookProcess;
12361 
12362 /*--------------------------------------------------------------------
12363  | NAME:
12364  |     performPostHookProcess
12365  |
12366  | PURPOSE:
12367  |     Copies back the payments from the IBY_HOOK_PAYMENTS_TEMP temporary
12368  |     table back to the created payments PLSQL table.
12369  |
12370  |
12371  | PARAMETERS:
12372  |     IN
12373  |
12374  |     OUT
12375  |
12376  |
12377  | RETURNS:
12378  |
12379  | NOTES:
12380  |
12381  *---------------------------------------------------------------------*/
12382  PROCEDURE performPostHookProcess(
12383      x_paymentTab        IN OUT NOCOPY paymentTabType,
12384      x_docsInPmtTab      IN OUT NOCOPY docsInPaymentTabType,
12385      x_hookPaymentTab    IN OUT NOCOPY hookPaymentTabType,
12386      x_hookDocsInPmtTab  IN OUT NOCOPY hookDocsInPaymentTabType,
12387      x_docErrorTab       IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
12388      x_errTokenTab       IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.
12389                                            trxnErrTokenTabType
12390      )
12391  IS
12392 
12393  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
12394                                              '.performPostHookProcess';
12395  l_succPayIndx NUMBER := 1;
12396  l_succDocIndx NUMBER := 1;
12397  l_preHookPaymentTab   hookPaymentTabType;
12398  l_preHook_cntr        integer;
12399  l_preHookDocsInPmtTab hookDocsInPaymentTabType;
12400  l_str         VARCHAR2(2000);
12401 
12402  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
12403 
12404  BEGIN
12405 
12406      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12407 	print_debuginfo(l_module_name, 'ENTER');
12408 
12409 END IF;
12410 
12411      IF (paymentTab.calling_app_id.COUNT = 0) THEN
12412          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12413 	 print_debuginfo(l_module_name, 'No payments were retrieved '
12414              || 'from hook. Exiting ..');
12415          print_debuginfo(l_module_name, 'EXIT');
12416 
12417 	 END IF;
12418 
12419 	 RETURN;
12420      END IF;
12421 
12422      /*
12423       * Copy all the data that we passed to the hook into a
12424       * backup data structure. We will diff this backup
12425       * structure with the data struct that returns from
12426       * the hook and log all the differences as 'payment
12427       * changes made by hook'.
12428       */
12429 /*    Bug 6347886
12430      FOR i in x_hookPaymentTab.FIRST .. x_hookPaymentTab.LAST LOOP
12431          l_preHookPaymentTab(l_preHookPaymentTab.COUNT + 1)
12432              := x_hookPaymentTab(i);
12433      END LOOP;
12434 */
12435      l_preHook_cntr := 1;
12436      FOR i in paymentTab.calling_app_id.FIRST .. paymentTab.calling_app_id.LAST
12437 LOOP
12438          l_preHookPaymentTab(l_preHook_cntr).calling_app_id
12439          := PaymentTab.calling_app_id(i);
12440          l_preHookPaymentTab(l_preHook_cntr).call_app_pay_service_req_code
12441          := PaymentTab.call_app_pay_service_req_cd(i);
12442          l_preHookPaymentTab(l_preHook_cntr).payment_service_request_id
12443          := PaymentTab.payment_service_request_id(i);
12444          l_preHookPaymentTab(l_preHook_cntr).payment_id
12445          := PaymentTab.payment_id(i);
12446          l_preHookPaymentTab(l_preHook_cntr).payment_amount
12447          := PaymentTab.payment_amount(i);
12448          l_preHookPaymentTab(l_preHook_cntr).payment_currency_code
12449          := PaymentTab.payment_currency_code(i);
12450          l_preHookPaymentTab(l_preHook_cntr).dont_pay_flag
12451          := PaymentTab.dont_pay_flg(i);
12452          l_preHookPaymentTab(l_preHook_cntr).dont_pay_reason_code
12453          := PaymentTab.dont_pay_reason_cd(i);
12454          l_preHookPaymentTab(l_preHook_cntr).dont_pay_description
12455          := PaymentTab.dont_pay_desc(i);
12456          l_preHookPaymentTab(l_preHook_cntr).internal_bank_account_id
12457          := PaymentTab.internal_bank_account_id(i);
12458          l_preHookPaymentTab(l_preHook_cntr).ext_payee_id
12459          := PaymentTab.ext_payee_id(i);
12460          l_preHookPaymentTab(l_preHook_cntr).payee_party_id
12461          := PaymentTab.payee_party_id(i);
12462          l_preHookPaymentTab(l_preHook_cntr).party_site_id
12463          := PaymentTab.party_site_id(i);
12464          l_preHookPaymentTab(l_preHook_cntr).supplier_site_id
12465          := PaymentTab.supplier_site_id(i);
12466          l_preHookPaymentTab(l_preHook_cntr).org_id
12467          := PaymentTab.org_id(i);
12468          l_preHookPaymentTab(l_preHook_cntr).org_type
12469          := PaymentTab.org_type(i);
12470          l_preHookPaymentTab(l_preHook_cntr).external_bank_account_id
12471          := PaymentTab.external_bank_account_id(i);
12472          l_preHookPaymentTab(l_preHook_cntr).discount_amount_taken
12473          := PaymentTab.discount_amount_taken(i);
12474          l_preHookPaymentTab(l_preHook_cntr).payment_date
12475          := PaymentTab.payment_date(i);
12476          l_preHookPaymentTab(l_preHook_cntr).bank_charge_amount
12477          := PaymentTab.bank_charge_amount(i);
12478          l_preHookPaymentTab(l_preHook_cntr).created_by
12479          := PaymentTab.created_by(i);
12480          l_preHookPaymentTab(l_preHook_cntr).creation_date
12481          := PaymentTab.creation_date(i);
12482          l_preHookPaymentTab(l_preHook_cntr).last_updated_by
12483          := PaymentTab.last_updated_by(i);
12484          l_preHookPaymentTab(l_preHook_cntr).last_update_date
12485          := PaymentTab.last_update_date(i);
12486          l_preHookPaymentTab(l_preHook_cntr).last_update_login
12487          := PaymentTab.last_update_login(i);
12488          l_preHookPaymentTab(l_preHook_cntr).object_version_number
12489          := PaymentTab.object_version_number(i);
12490          l_preHook_cntr := l_preHook_cntr + 1;
12491      END LOOP;
12492 
12493 /* Bug 6347886 */
12494 
12495      IF (x_hookDocsInPmtTab.COUNT > 0) THEN
12496      FOR i in x_hookDocsInPmtTab.FIRST .. x_hookDocsInPmtTab.LAST LOOP
12497          l_preHookDocsInPmtTab(l_preHookDocsInPmtTab.COUNT + 1)
12498              := x_hookDocsInPmtTab(i);
12499      END LOOP;
12500      END IF;
12501 
12502      /*
12503       * Read the documents and payments from the global temp
12504       * tables. The calling app might have updated them.
12505       */
12506      getAdjustedPaymentData(x_hookPaymentTab, x_hookDocsInPmtTab);
12507 
12508      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12509 	print_debuginfo(l_module_name, x_hookDocsInPmtTab.COUNT
12510          || ' docs and '
12511          || x_hookPaymentTab.COUNT || ' payments'
12512          || ' were read from global temp tables.'
12513          );
12514 
12515 END IF;
12516 
12517      /*
12518       * The external hook can change document and payment
12519       * amounts, or change document and payment statuses.
12520       *
12521       * However, the external hook should not 'add to' or
12522       * 'remove from', the documents and payments that were
12523       * passed to the hook.
12524       *
12525       * Check the document and payment count. If the hook
12526       * has made any changes, the abort the program as it
12527       * a fatal error.
12528       */
12529 
12530      IF (x_hookPaymentTab.COUNT <> l_preHookPaymentTab.COUNT) THEN
12531 
12532 
12533 	 print_debuginfo(l_module_name, 'Fatal error - Payment '
12534              || 'count mismatch after hook operation. '
12535              || '# payments passed to hook: '
12536              || l_preHookPaymentTab.COUNT
12537              || ', # payments returning from hook: '
12538              || x_hookPaymentTab.COUNT,
12539              FND_LOG.LEVEL_UNEXPECTED
12540              );
12541 
12542          print_debuginfo(l_module_name, 'Aborting program ..',
12543              FND_LOG.LEVEL_UNEXPECTED);
12544 
12545 
12546 
12547 
12548          APP_EXCEPTION.RAISE_EXCEPTION;
12549 
12550      END IF;
12551 
12552      IF (x_hookDocsInPmtTab.COUNT <> l_preHookDocsInPmtTab.COUNT) THEN
12553 
12554 
12555 	 print_debuginfo(l_module_name, 'Fatal error - Document '
12556              || 'count mismatch after hook operation. '
12557              || '# documents passed to hook: '
12558              || l_preHookDocsInPmtTab.COUNT
12559              || ', # documents returning from hook: '
12560              || x_hookDocsInPmtTab.COUNT,
12561              FND_LOG.LEVEL_UNEXPECTED
12562              );
12563 
12564          print_debuginfo(l_module_name, 'Aborting program ..',
12565              FND_LOG.LEVEL_UNEXPECTED);
12566 
12567 
12568 
12569          APP_EXCEPTION.RAISE_EXCEPTION;
12570 
12571      END IF;
12572 
12573      /*
12574       * Diff the pre-hook and post-hook structures and log
12575       * the values that were changed by the hook.
12576       */
12577      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12578 	print_debuginfo(l_module_name, 'List of changes made by the hook: ');
12579 
12580      /* Diff of payments */
12581      FOR i in x_hookPaymentTab.FIRST .. x_hookPaymentTab.LAST LOOP
12582 
12583          l_str := NULL;
12584 
12585          IF (x_hookPaymentTab(i).payment_amount <>
12586              l_preHookPaymentTab(i).payment_amount ) THEN
12587              l_str := 'Pmt amount: ' || x_hookPaymentTab(i).payment_amount;
12588          END IF;
12589 
12590          IF (x_hookPaymentTab(i).dont_pay_flag <>
12591              l_preHookPaymentTab(i).dont_pay_flag) THEN
12592              l_str := l_str || ' Dont pay flag: '
12593                           || x_hookPaymentTab(i).dont_pay_flag;
12594          END IF;
12595 
12596          IF (l_str IS NOT NULL) THEN
12597              l_str := 'Pmt Id: ' || x_hookPaymentTab(i).payment_id
12598                           || ' ' || l_str;
12599              print_debuginfo(l_module_name, l_str);
12600          END IF;
12601 
12602      END LOOP;
12603 
12604      /* Diff of documents */
12605      IF (x_hookDocsInPmtTab.COUNT > 0) THEN
12606      FOR i in x_hookDocsInPmtTab.FIRST .. x_hookDocsInPmtTab.LAST LOOP
12607 
12608          l_str := NULL;
12609 
12610          IF (x_hookDocsInPmtTab(i).document_amount <>
12611              l_preHookDocsInPmtTab(i).document_amount) THEN
12612              l_str := 'Doc amount: ' || x_hookDocsInPmtTab(i).document_amount;
12613          END IF;
12614 
12615          IF (x_hookDocsInPmtTab(i).amount_withheld <>
12616              l_preHookDocsInPmtTab(i).amount_withheld) THEN
12617              l_str := l_str || ', Amount withheld: '
12618                           || x_hookDocsInPmtTab(i).amount_withheld;
12619          END IF;
12620 
12621          IF (x_hookDocsInPmtTab(i).dont_pay_flag <>
12622              l_preHookDocsInPmtTab(i).dont_pay_flag) THEN
12623              l_str := l_str || ', Dont pay flag: '
12624                           || x_hookDocsInPmtTab(i).dont_pay_flag;
12625          END IF;
12626 
12627          IF (l_str IS NOT NULL) THEN
12628              l_str := 'Doc Id: ' || x_hookDocsInPmtTab(i).document_payable_id
12629                           || ' ' || l_str;
12630              print_debuginfo(l_module_name, l_str);
12631          END IF;
12632 
12633      END LOOP;
12634      END IF; -- if hook docs count > 0
12635 
12636    END IF; -- IF STATEMENT LEVEL LOGGING
12637 
12638      /*
12639       * Ideally, when the calling app sets the 'dont pay flag'
12640       * for a payment, it should also do the following:
12641       *
12642       * 1. Set payment amount to zero.
12643       *
12644       * 2. Set 'dont pay flag' for all docs that were part of
12645       *    this payment.
12646       *
12647       * But the calling app does not do (1) and (2). Instead these
12648       * steps are handled by the build program (to make life simpler
12649       * for the calling app).
12650       *
12651       * The loop below handles these steps.
12652       */
12653      FOR i in x_hookPaymentTab.FIRST ..  x_hookPaymentTab.LAST LOOP
12654 
12655          IF (UPPER(x_hookPaymentTab(i).dont_pay_flag) = 'Y') THEN
12656 
12657              /*
12658               * Since the payment has failed, all docs in this
12659               * payment also need to be failed.
12660               *
12661               * Set the 'dont pay flag' to true for all docs
12662               * that were part of this payment.
12663               */
12664              IF (x_hookDocsInPmtTab.COUNT > 0) THEN
12665              FOR j in x_hookDocsInPmtTab.FIRST .. x_hookDocsInPmtTab.LAST LOOP
12666 
12667                  IF (x_hookDocsInPmtTab(j).payment_id =
12668                      x_hookPaymentTab(i).payment_id) THEN
12669 
12670                      x_hookDocsInPmtTab(j).dont_pay_flag := 'Y';
12671 
12672                  END IF;
12673 
12674              END LOOP;
12675              END IF;
12676 
12677              /*
12678               * Set the payment amount to zero.
12679               *
12680               * Remember, Payment Amount =
12681               *               SUM (successful document amounts)
12682               */
12683              x_hookPaymentTab(i).payment_amount := 0;
12684 
12685          END IF;
12686 
12687      END LOOP;
12688 
12689      /*
12690       * STEP 1:
12691       *
12692       * Update our existing payments and documents data structures
12693       * with the values from the hook - the external app may have adjusted
12694       * some payment amounts for bank charges, tax withholding etc.
12695       *
12696       * These must be reflected into our existing data structures before
12697       * we update the documents and payments tables with them.
12698       */
12699 
12700      /* update payments */
12701      FOR i in x_hookPaymentTab.FIRST ..  x_hookPaymentTab.LAST LOOP
12702 
12703          FOR j in x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
12704 
12705              IF (x_hookPaymentTab(i).payment_id = x_paymentTab(j).payment_id)
12706                  THEN
12707 
12708                  /*
12709                   * Copy from 'hook payments' array to original
12710                   * payments array.
12711                   */
12712                  IF (x_paymentTab(j).payment_amount <>
12713                      x_hookPaymentTab(i).payment_amount) THEN
12714 
12715                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12716                      print_debuginfo(l_module_name, 'Amount for payment '
12717                          || x_hookPaymentTab(i).payment_id
12718                          || ' was changed by calling app'
12719                          || ' from '  || x_paymentTab(j).payment_amount
12720                          || ' to ' || x_hookPaymentTab(i).payment_amount
12721                          );
12722 		     END IF;
12723                      x_paymentTab(j).payment_amount :=
12724                          x_hookPaymentTab(i).payment_amount;
12725 
12726                  END IF;
12727 
12728                  /*
12729                   * If the external app has populated the bank charge
12730                   * amount via the hook, update the bank charge
12731                   * amount attribute on the payment to reflect this.
12732                   */
12733                  IF (x_paymentTab(j).bank_charge_amount <>
12734                      x_hookPaymentTab(i).bank_charge_amount) THEN
12735 
12736                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12737                      print_debuginfo(l_module_name, 'Bank charge amount '
12738                          || 'for payment '
12739                          || x_hookPaymentTab(i).payment_id
12740                          || ' was changed by calling app'
12741                          || ' from '  || x_paymentTab(j).bank_charge_amount
12742                          || ' to ' || x_hookPaymentTab(i).bank_charge_amount
12743                          );
12744 		     END IF;
12745                      x_paymentTab(j).bank_charge_amount :=
12746                          x_hookPaymentTab(i).bank_charge_amount;
12747 
12748                  END IF;
12749 
12750 		 /*
12751 		  * If the external app has populated the discount
12752 		  * amount via the hook, update the discount
12753 		  * amount attribute on the payment to reflect this.
12754 		  */
12755 		 IF (x_paymentTab(j).discount_amount_taken <>
12756 		     x_hookPaymentTab(i).discount_amount_taken) THEN
12757 
12758 		     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12759 		     print_debuginfo(l_module_name, 'Discount Amount Taken '
12760 		 	  || 'for payment '
12761 		 	  || x_hookPaymentTab(i).payment_id
12762 		 	  || ' was changed by calling app'
12763 		 	  || ' from '  || x_paymentTab(j).discount_amount_taken
12764 		 	  || ' to ' || x_hookPaymentTab(i).discount_amount_taken
12765 		 	  );
12766 		      END IF;
12767 		     x_paymentTab(j).discount_amount_taken :=
12768 		 	  x_hookPaymentTab(i).discount_amount_taken;
12769 
12770 		 END IF;
12771 
12772                  /*
12773                   * Adjust payment status if necessary.
12774                   */
12775                  IF (UPPER(x_hookPaymentTab(i).dont_pay_flag) = 'Y') THEN
12776 
12777                      x_paymentTab(j).payment_status := PAY_STATUS_CA_FAILED;
12778 
12779                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12780                      print_debuginfo(l_module_name, 'Payment '
12781                          || x_paymentTab(j).payment_id
12782                          || ' was failed by calling app.');
12783 		     END IF;
12784                      /*
12785                       * Once we fail a payment, we need to create
12786                       * an error record and insert this record
12787                       * into the errors table.
12788                       */
12789                      IBY_BUILD_UTILS_PKG.createErrorRecord(
12790                          TRXN_TYPE_PMT,
12791                          x_paymentTab(j).payment_id,
12792                          x_paymentTab(j).payment_status,
12793                          NULL,
12794                          x_paymentTab(j).payment_id,
12795                          NULL,
12796                          NULL,
12797                          NULL,
12798                          NULL,
12799                          NULL,
12800                          l_doc_err_rec,
12801                          x_errTokenTab
12802                          );
12803 
12804                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
12805                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
12806 
12807                  /* fail the docs of this payment */
12808                  failDocsOfPayment(x_paymentTab(j).payment_id,
12809                      DOC_STATUS_PAY_VAL_FAIL, x_docsInPmtTab,
12810                      x_docErrorTab, x_errTokenTab);
12811 
12812 
12813                  END IF;
12814 
12815              END IF;
12816 
12817          END LOOP;
12818 
12819      END LOOP;
12820 
12821      /* update documents */
12822      IF (x_hookDocsInPmtTab.COUNT > 0) THEN
12823      FOR i in x_hookDocsInPmtTab.FIRST ..  x_hookDocsInPmtTab.LAST LOOP
12824 
12825          FOR j in x_docsInPmtTab.FIRST ..  x_docsInPmtTab.LAST LOOP
12826 
12827              IF (x_hookDocsInPmtTab(i).document_payable_id =
12828                  x_docsInPmtTab(j).document_id)
12829                  THEN
12830 
12831                  /*
12832                   * Copy from 'hook documents' array to original
12833                   * documents array.
12834                   */
12835                  IF (x_docsInPmtTab(j).document_amount <>
12836                      x_hookDocsInPmtTab(i).document_amount) THEN
12837 
12838                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12839                      print_debuginfo(l_module_name, 'Amount for document '
12840                          || x_hookDocsInPmtTab(i).document_payable_id
12841                          || ' was changed by calling app'
12842                          || ' from ' || x_docsInPmtTab(j).document_amount
12843                          ||  ' to '  || x_hookDocsInPmtTab(i).document_amount
12844                          );
12845 		     END IF;
12846                      x_docsInPmtTab(j).document_amount :=
12847                          x_hookDocsInPmtTab(i).document_amount;
12848 
12849                      x_docsInPmtTab(j).amount_withheld :=
12850                          x_hookDocsInPmtTab(i).amount_withheld;
12851 
12852                  END IF;
12853 
12854                  /*
12855                   * Copy from 'hook documents' array to original
12856                   * documents array.
12857                   */
12858                  IF (x_docsInPmtTab(j).pmt_curr_discount <>
12859                      x_hookDocsInPmtTab(i).payment_curr_discount_taken) THEN
12860 
12861                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12862                      print_debuginfo(l_module_name, 'Discount for document '
12863                 	  || x_hookDocsInPmtTab(i).document_payable_id
12864                 	  || ' was changed by calling app'
12865                 	  || ' from ' || x_docsInPmtTab(j).pmt_curr_discount
12866                 	  ||  ' to '  || x_hookDocsInPmtTab(i).payment_curr_discount_taken
12867                 	  );
12868                       END IF;
12869                      x_docsInPmtTab(j).pmt_curr_discount :=
12870                 	  x_hookDocsInPmtTab(i).payment_curr_discount_taken;
12871 
12872                  END IF;
12873 
12874                  /*
12875                   * Adjust document status if necessary.
12876                   */
12877                  IF (UPPER(x_hookDocsInPmtTab(i).dont_pay_flag) = 'Y') THEN
12878 
12879                      x_docsInPmtTab(j).document_status := DOC_STATUS_CA_FAILED;
12880 
12881                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12882                      print_debuginfo(l_module_name, 'Document '
12883                          || x_hookDocsInPmtTab(i).document_payable_id
12884                          || ' was failed by calling app.');
12885 		     END IF;
12886 
12887                      /*
12888                       * Once we fail a doc, we must add a corresponding
12889                       * error message to the error table.
12890                       */
12891                      IBY_BUILD_UTILS_PKG.createErrorRecord(
12892                          TRXN_TYPE_DOC,
12893                          x_docsInPmtTab(j).document_id,
12894                          x_docsInPmtTab(j).document_status,
12895                          x_docsInPmtTab(j).calling_app_id,
12896                          x_docsInPmtTab(j).calling_app_doc_id1,
12897                          x_docsInPmtTab(j).calling_app_doc_id2,
12898                          x_docsInPmtTab(j).calling_app_doc_id3,
12899                          x_docsInPmtTab(j).calling_app_doc_id4,
12900                          x_docsInPmtTab(j).calling_app_doc_id5,
12901                          x_docsInPmtTab(j).pay_proc_ttype_cd,
12902                          l_doc_err_rec,
12903                          x_errTokenTab
12904                          );
12905 
12906                      IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
12907                          l_doc_err_rec, x_docErrorTab, x_errTokenTab);
12908 
12909                  END IF;
12910 
12911              END IF;
12912 
12913          END LOOP;
12914 
12915      END LOOP;
12916      END IF;
12917 
12918      /*
12919       * STEP 2:
12920       *
12921       * The external app may not wish to pay certain documents.
12922       * For such cases, make sure to fail the sister docs that are
12923       * related to this document via the 'payment grouping number'.
12924       * Each time a sister doc is failed, adjust the payment amount
12925       * of the payment that contains this document to reflect this.
12926       */
12927      adjustSisterDocsAndPmts(x_paymentTab, x_docsInPmtTab,
12928          x_docErrorTab, x_errTokenTab);
12929 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
12930      print_debuginfo(l_module_name, 'EXIT');
12931 	 END IF;
12932 
12933  END performPostHookProcess;
12934 
12935 
12936 /*--------------------------------------------------------------------
12937  | NAME:
12938  |     performPostHookProcess
12939  |
12940  | PURPOSE:
12941  |     Copies back the payments from the IBY_HOOK_PAYMENTS_TEMP temporary
12942  |     table back to the created payments PLSQL table.
12943  |
12944  |
12945  | PARAMETERS:
12946  |     IN
12947  |
12948  |     OUT
12949  |
12950  |
12951  | RETURNS:
12952  |
12953  | NOTES:
12954  |
12955  *---------------------------------------------------------------------*/
12956  PROCEDURE performPostHookProcess(
12957  --    x_paymentTab        IN OUT NOCOPY paymentTabType,
12958  --     x_docsInPmtTab      IN OUT NOCOPY docsInPaymentTabType,
12959  --    x_hookPaymentTab    IN OUT NOCOPY hookPaymentTabType,
12960  --    x_hookDocsInPmtTab  IN OUT NOCOPY hookDocsInPaymentTabType,
12961      p_cap_payreq_cd	 IN VARCHAR2,
12962      l_prehook_count     IN NUMBER,
12963      x_docErrorTab       IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
12964      x_errTokenTab       IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.
12965                                            trxnErrTokenTabType
12966      )
12967  IS
12968 
12969  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
12970                                              '.performPostHookProcess';
12971  l_succPayIndx NUMBER := 1;
12972  l_succDocIndx NUMBER := 1;
12973  l_preHookPaymentTab   hookPaymentTabType;
12974  l_preHook_cntr        integer;
12975  l_preHookDocsInPmtTab hookDocsInPaymentTabType;
12976  l_str         VARCHAR2(2000);
12977 
12978  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
12979  l_docsingt_count NUMBER;
12980 
12981  l_pmts_tab_count    NUMBER;
12982  l_posthook_count   NUMBER;
12983  hookPmtsTab hookPaymentTabType;
12984 
12985  l_hook_pmt_amt iby_payments_all.payment_amount%type;
12986  l_pmt_amt      iby_payments_all.payment_amount%type;
12987  l_trx_cbr_index  BINARY_INTEGER;
12988 
12989  CURSOR c_fail_docs_of_payment
12990  IS
12991  SELECT idpt.payment_id,
12992    idpt.document_payable_id,
12993    idpt.document_status,
12994    idpt.calling_app_id,
12995    idpt.calling_app_doc_unique_ref1,
12996    idpt.calling_app_doc_unique_ref2,
12997    idpt.calling_app_doc_unique_ref3,
12998    idpt.calling_app_doc_unique_ref4,
12999    idpt.calling_app_doc_unique_ref5,
13000    idpt.pay_proc_trxn_type_code,
13001    idpt.document_amount,
13002    idpt.payment_grouping_number
13003  FROM iby_docs_in_pmt_gt idpt
13004  WHERE idpt.document_payable_id in (SELECT idpa.document_payable_id from iby_hook_docs_in_pmt_t idpa
13005                                     WHERE idpa.dont_pay_flag = 'Y');
13006  CURSOR c_failed_documents
13007  IS
13008  SELECT ihdp.document_payable_id,
13009  ihdp.document_amount,
13010  ihdp.amount_withheld,
13011  ihdp.dont_pay_flag
13012  FROM iby_hook_docs_in_pmt_t ihdp, iby_docs_in_pmt_gt idip
13013  WHERE ihdp.document_payable_id = idip.document_payable_id
13014  AND (ihdp.document_amount <> idip.document_amount
13015  OR ihdp.amount_withheld <> idip.amount_withheld
13016  OR ihdp.dont_pay_flag <> idip.dont_pay_flag);
13017 
13018   CURSOR check_pmt_tab
13019  IS
13020  select
13021  payment_id,
13022  payment_amount
13023  from
13024  iby_payments_all A
13025  where payment_amount =
13026  (select B.payment_amount from IBY_HOOK_PAYMENTS_T B where A.payment_id = B.payment_id
13027   AND A.payment_service_request_id = B.payment_service_request_id)
13028  ;
13029 
13030 
13031   CURSOR c_hook_pmts
13032  IS
13033  SELECT
13034   calling_app_id   ,
13035   call_app_pay_service_req_code ,
13036   payment_service_request_id ,
13037   payment_id   ,
13038   payment_amount   ,
13039   payment_currency_code  ,
13040   dont_pay_flag   ,
13041   dont_pay_reason_code  ,
13042   dont_pay_description  ,
13043   internal_bank_account_id  ,
13044   ext_payee_id   ,
13045   payee_party_id   ,
13046   party_site_id   ,
13047   supplier_site_id   ,
13048   org_id    ,
13049   org_type    ,
13050   external_bank_account_id  ,
13051   discount_amount_taken  ,
13052   payment_date   ,
13053   bank_charge_amount  ,
13054   created_by   ,
13055   creation_date   ,
13056   last_updated_by   ,
13057   last_update_date   ,
13058   last_update_login   ,
13059   object_version_number
13060  FROM
13061  IBY_HOOK_PAYMENTS_T
13062  WHERE
13063  call_app_pay_service_req_code=
13064  p_cap_payreq_cd
13065  ;
13066 
13067 
13068  BEGIN
13069 
13070      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13071 	print_debuginfo(l_module_name, 'ENTER - overloaded postHookprocess');
13072 
13073 END IF;
13074 
13075      IF (IBY_PAYGROUP_PUB.pmtTable.payment_id.COUNT = 0) THEN
13076          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13077 	 print_debuginfo(l_module_name, 'No payments were retrieved '
13078              || 'from hook. Exiting ..');
13079          print_debuginfo(l_module_name, 'EXIT');
13080 
13081 	 END IF;
13082 
13083 	 RETURN;
13084      END IF;
13085 
13086 
13087      	 /*
13088 	 OPEN check_hook_pmt;
13089 	  LOOP
13090 	    FETCH check_hook_pmt INTO pmt_id, pmt_amt;
13091 
13092 	    EXIT WHEN check_hook_pmt%NOTFOUND;
13093 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13094 	    print_debuginfo(l_module_name, 'pmt_id-'|| pmt_id || 'pmt_amt-'|| pmt_amt);
13095 		END IF;
13096 
13097 	  END LOOP;
13098 	  CLOSE check_hook_pmt;
13099 
13100 	*/
13101 
13102 
13103      	 /*
13104 	 OPEN check_pmt_tab;
13105 	  LOOP
13106 	    FETCH check_pmt_tab INTO pmt_id, pmt_amt;
13107 
13108 	    EXIT WHEN check_pmt_tab%NOTFOUND;
13109 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13110 	    print_debuginfo(l_module_name, 'pmt_id-'|| pmt_id || 'pmt_amt-'|| pmt_amt);
13111 		END IF;
13112 
13113 	  END LOOP;
13114 	  CLOSE check_pmt_tab;
13115 
13116 	 */
13117 
13118 
13119      /*
13120       * Copy all the data that we passed to the hook into a
13121       * backup data structure. We will diff this backup
13122       * structure with the data struct that returns from
13123       * the hook and log all the differences as 'payment
13124       * changes made by hook'.
13125       */
13126 /*    Bug 6347886
13127      FOR i in x_hookPaymentTab.FIRST .. x_hookPaymentTab.LAST LOOP
13128          l_preHookPaymentTab(l_preHookPaymentTab.COUNT + 1)
13129              := x_hookPaymentTab(i);
13130      END LOOP;
13131 */
13132 
13133 /*
13134 
13135      l_preHook_cntr := 1;
13136      FOR i in paymentTab.calling_app_id.FIRST .. paymentTab.calling_app_id.LAST
13137 LOOP
13138          l_preHookPaymentTab(l_preHook_cntr).calling_app_id
13139          := PaymentTab.calling_app_id(i);
13140          l_preHookPaymentTab(l_preHook_cntr).call_app_pay_service_req_code
13141          := PaymentTab.call_app_pay_service_req_cd(i);
13142          l_preHookPaymentTab(l_preHook_cntr).payment_service_request_id
13143          := PaymentTab.payment_service_request_id(i);
13144          l_preHookPaymentTab(l_preHook_cntr).payment_id
13145          := PaymentTab.payment_id(i);
13146          l_preHookPaymentTab(l_preHook_cntr).payment_amount
13147          := PaymentTab.payment_amount(i);
13148          l_preHookPaymentTab(l_preHook_cntr).payment_currency_code
13149          := PaymentTab.payment_currency_code(i);
13150          l_preHookPaymentTab(l_preHook_cntr).dont_pay_flag
13151          := PaymentTab.dont_pay_flg(i);
13152          l_preHookPaymentTab(l_preHook_cntr).dont_pay_reason_code
13153          := PaymentTab.dont_pay_reason_cd(i);
13154          l_preHookPaymentTab(l_preHook_cntr).dont_pay_description
13155          := PaymentTab.dont_pay_desc(i);
13156          l_preHookPaymentTab(l_preHook_cntr).internal_bank_account_id
13157          := PaymentTab.internal_bank_account_id(i);
13158          l_preHookPaymentTab(l_preHook_cntr).ext_payee_id
13159          := PaymentTab.ext_payee_id(i);
13160          l_preHookPaymentTab(l_preHook_cntr).payee_party_id
13161          := PaymentTab.payee_party_id(i);
13162          l_preHookPaymentTab(l_preHook_cntr).party_site_id
13163          := PaymentTab.party_site_id(i);
13164          l_preHookPaymentTab(l_preHook_cntr).supplier_site_id
13165          := PaymentTab.supplier_site_id(i);
13166          l_preHookPaymentTab(l_preHook_cntr).org_id
13167          := PaymentTab.org_id(i);
13168          l_preHookPaymentTab(l_preHook_cntr).org_type
13169          := PaymentTab.org_type(i);
13170          l_preHookPaymentTab(l_preHook_cntr).external_bank_account_id
13171          := PaymentTab.external_bank_account_id(i);
13172          l_preHookPaymentTab(l_preHook_cntr).discount_amount_taken
13173          := PaymentTab.discount_amount_taken(i);
13174          l_preHookPaymentTab(l_preHook_cntr).payment_date
13175          := PaymentTab.payment_date(i);
13176          l_preHookPaymentTab(l_preHook_cntr).bank_charge_amount
13177          := PaymentTab.bank_charge_amount(i);
13178          l_preHookPaymentTab(l_preHook_cntr).created_by
13179          := PaymentTab.created_by(i);
13180          l_preHookPaymentTab(l_preHook_cntr).creation_date
13181          := PaymentTab.creation_date(i);
13182          l_preHookPaymentTab(l_preHook_cntr).last_updated_by
13183          := PaymentTab.last_updated_by(i);
13184          l_preHookPaymentTab(l_preHook_cntr).last_update_date
13185          := PaymentTab.last_update_date(i);
13186          l_preHookPaymentTab(l_preHook_cntr).last_update_login
13187          := PaymentTab.last_update_login(i);
13188          l_preHookPaymentTab(l_preHook_cntr).object_version_number
13189          := PaymentTab.object_version_number(i);
13190          l_preHook_cntr := l_preHook_cntr + 1;
13191      END LOOP;
13192 
13193 */
13194 
13195 
13196      UPDATE iby_hook_payments_t
13197      SET payment_amount = 0
13198      WHERE dont_pay_flag = 'Y';
13199 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13200     print_debuginfo(l_module_name, 'After updating iby_hooks table for pmt amt');
13201 	END IF;
13202 
13203      	 /*
13204 	 OPEN check_hook_pmt;
13205 	  LOOP
13206 	    FETCH check_hook_pmt INTO pmt_id, pmt_amt;
13207 
13208 	    EXIT WHEN check_hook_pmt%NOTFOUND;
13209 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13210 	    print_debuginfo(l_module_name, 'pmt_id-'|| pmt_id || 'pmt_amt-'|| pmt_amt);
13211 		END IF;
13212 
13213 	  END LOOP;
13214 	  CLOSE check_hook_pmt;
13215 	 */
13216 
13217      /*
13218       * Read the documents and payments from the global temp
13219       * tables. The calling app might have updated them.
13220       */
13221   --   getAdjustedPaymentData(x_hookPaymentTab);
13222 
13223      /*IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13224  print_debuginfo(l_module_name, x_hookDocsInPmtTab.COUNT
13225          || ' docs and '
13226          || x_hookPaymentTab.COUNT || ' payments'
13227          || ' were read from global temp tables.'
13228          );
13229      END IF;*/
13230      /*
13231       * The external hook can change document and payment
13232       * amounts, or change document and payment statuses.
13233       *
13234       * However, the external hook should not 'add to' or
13235       * 'remove from', the documents and payments that were
13236       * passed to the hook.
13237       *
13238       * Check the document and payment count. If the hook
13239       * has made any changes, the abort the program as it
13240       * a fatal error.
13241       */
13242 
13243 
13244      SELECT COUNT(PAYMENT_ID)
13245       INTO l_posthook_count
13246      FROM IBY_HOOK_PAYMENTS_T
13247      WHERE
13248      payment_service_request_id  =
13249      (select payment_service_request_id
13250      from iby_pay_service_requests where
13251      call_app_pay_service_req_code =p_cap_payreq_cd
13252      );
13253 
13254 
13255       IF ( l_posthook_count <> l_prehook_count ) THEN
13256 
13257 
13258 	 print_debuginfo(l_module_name, 'Fatal error - Payment '
13259              || 'count mismatch after hook operation. '
13260              || '# payments passed to hook: '
13261              || l_prehook_count
13262              || ', # payments returning from hook: '
13263              ||  l_posthook_count,
13264              FND_LOG.LEVEL_UNEXPECTED
13265              );
13266 
13267          print_debuginfo(l_module_name, 'Aborting program ..',
13268              FND_LOG.LEVEL_UNEXPECTED);
13269 
13270 
13271 
13272 
13273          APP_EXCEPTION.RAISE_EXCEPTION;
13274 
13275      END IF;
13276 
13277      l_docsingt_count :=0;
13278      SELECT COUNT(*)
13279      INTO l_docsingt_count
13280      FROM iby_docs_in_pmt_gt
13281      WHERE document_status = DOC_STATUS_PAY_CREATED;
13282      IF (l_DocsInPmtCount <> l_docsingt_count) THEN
13283 
13284 
13285  print_debuginfo(l_module_name, 'Fatal error - Document '
13286              || 'count mismatch after hook operation. '
13287              || '# documents passed to hook: '
13288              || l_DocsInPmtCount
13289              || ', # documents returning from hook: '
13290              || l_docsingt_count,
13291              FND_LOG.LEVEL_UNEXPECTED
13292              );
13293 
13294          print_debuginfo(l_module_name, 'Aborting program ..',
13295              FND_LOG.LEVEL_UNEXPECTED);
13296 
13297 
13298 
13299          APP_EXCEPTION.RAISE_EXCEPTION;
13300 
13301      END IF;
13302 
13303      /*
13304       * Diff the pre-hook and post-hook structures and log
13305       * the values that were changed by the hook.
13306       */
13307 
13308      /*
13309       * Ideally, when the calling app sets the 'dont pay flag'
13310       * for a payment, it should also do the following:
13311       *
13312       * 1. Set payment amount to zero.
13313       *
13314       * 2. Set 'dont pay flag' for all docs that were part of
13315       *    this payment.
13316       *
13317       * But the calling app does not do (1) and (2). Instead these
13318       * steps are handled by the build program (to make life simpler
13319       * for the calling app).
13320       *
13321       * The loop below handles these steps.
13322       */
13323 
13324       UPDATE iby_hook_docs_in_pmt_t
13325       SET dont_pay_flag = 'Y'
13326       WHERE payment_id IN (select payment_id from iby_hook_payments_t where dont_pay_flag  = 'Y');
13327 
13328 
13329 
13330 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13331       print_debuginfo(l_module_name, 'After updating iby_hook_docs_in_pmt' );
13332 END IF;
13333 
13334 	 /*
13335 	 OPEN check_hook_pmt;
13336 	  LOOP
13337 	    FETCH check_hook_pmt INTO pmt_id, pmt_amt;
13338 
13339 	    EXIT WHEN check_hook_pmt%NOTFOUND;
13340 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13341 	    print_debuginfo(l_module_name, 'pmt_id-'|| pmt_id || 'pmt_amt-'|| pmt_amt);
13342 END IF;
13343 	  END LOOP;
13344 	  CLOSE check_hook_pmt;
13345 	 */
13346 
13347 
13348          /* Copy all the data changed by calling app into IBY_PAYMENTS_ALL table */
13349 
13350 	/*
13351 	UPDATE IBY_PAYMENTS_ALL A
13352 	SET (PAYMENT_AMOUNT, DISCOUNT_AMOUNT_TAKEN, bank_charge_amount)
13353 	=
13354 	(SELECT NVL(B.PAYMENT_AMOUNT,PAYMENT_AMOUNT),B.DISCOUNT_AMOUNT_TAKEN,B.bank_charge_amount
13355 	from IBY_HOOK_PAYMENTS_T B
13356 	where A.PAYMENT_ID= B.PAYMENT_ID)
13357 	;*/
13358 
13359 
13360 	/*
13361 
13362 	UPDATE IBY_PAYMENTS_ALL A
13363 	SET PAYMENT_AMOUNT = (SELECT B.PAYMENT_AMOUNT
13364 	from IBY_HOOK_PAYMENTS_T B
13365 	where A.PAYMENT_ID= B.PAYMENT_ID);
13366 	*/
13367 
13368 	/*
13369 	UPDATE IBY_PAYMENTS_ALL A
13370 	SET
13371 	DISCOUNT_AMOUNT_TAKEN= 	(SELECT B.DISCOUNT_AMOUNT_TAKEN
13372 	from IBY_HOOK_PAYMENTS_T B
13373 	where A.PAYMENT_ID= B.PAYMENT_ID),
13374 	bank_charge_amount =  (SELECT B.bank_charge_amount
13375 	from IBY_HOOK_PAYMENTS_T B
13376 	where A.PAYMENT_ID= B.PAYMENT_ID)
13377 	; */
13378 
13379 	    MERGE /*+ leading(ihp) */
13380 	    INTO IBY_PAYMENTS_ALL ibpa
13381 	    USING IBY_HOOK_PAYMENTS_T ihp ON(ibpa.payment_id = ihp.payment_id
13382 	    AND ibpa.payment_service_request_id = ihp.payment_service_request_id)
13383 	    WHEN MATCHED THEN UPDATE
13384 	    SET ibpa.PAYMENT_AMOUNT = ihp.PAYMENT_AMOUNT,
13385 	    ibpa.DISCOUNT_AMOUNT_TAKEN = ihp.DISCOUNT_AMOUNT_TAKEN,
13386 	    ibpa.bank_charge_amount = ihp.bank_charge_amount;
13387 
13388 
13389 	/*
13390 	UPDATE IBY_PAYMENTS_ALL A
13391         SET PAYMENT_STATUS =
13392 	(SELECT PAY_STATUS_CA_FAILED FROM
13393 	IBY_HOOK_PAYMENTS_T B
13394 	WHERE A.PAYMENT_ID= B.PAYMENT_ID AND
13395         B.DONT_PAY_FLAG ='Y')
13396 	;
13397         */
13398 
13399       	MERGE /*+ leading(ihp)*/
13400         INTO IBY_PAYMENTS_ALL ibpa
13401         USING IBY_HOOK_PAYMENTS_T ihp ON(ibpa.payment_id = ihp.payment_id
13402         AND ibpa.payment_service_request_id = ihp.payment_service_request_id
13403 	AND ihp.DONT_PAY_FLAG ='Y')
13404         WHEN MATCHED THEN UPDATE
13405 	SET ibpa.PAYMENT_STATUS = PAY_STATUS_CA_FAILED
13406         ;
13407 
13408 
13409 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13410 	print_debuginfo(l_module_name, 'After updating payments_all for payment_status' );
13411 	END IF;
13412 	OPEN  c_hook_pmts;
13413 	FETCH c_hook_pmts BULK COLLECT INTO hookPmtsTab;
13414 	CLOSE c_hook_pmts;
13415 
13416 
13417         FOR j in hookPmtsTab.FIRST .. hookPmtsTab.LAST LOOP
13418 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13419       print_debuginfo(l_module_name, 'Inside loop' );
13420 	  END IF;
13421 
13422           select payment_amount
13423           into l_hook_pmt_amt
13424           from iby_hook_payments_t
13425           where payment_id = hookPmtsTab(j).payment_id;
13426           IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13427                     print_debuginfo(l_module_name, 'Hook Payment Amount: '
13428                              || l_hook_pmt_amt
13429                              || ' has been retrieved in PostHook Process');
13430           END IF;
13431           select payment_amount
13432           into l_pmt_amt
13433           from iby_payments_all
13434           where payment_id = hookPmtsTab(j).payment_id;
13435           IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13436                     print_debuginfo(l_module_name, 'Payment Amount: '
13437                              || l_hook_pmt_amt
13438                              || ' has been retrieved in PostHook Process');
13439           END IF;
13440 
13441           FOR p_trx_cbr_index IN nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99)
13442           LOOP
13443               IF(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_cbr_index) = hookPmtsTab(j).payment_id) THEN
13444               l_trx_cbr_index := p_trx_cbr_index;
13445               END IF;
13446           END LOOP;
13447 
13448           IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13449                                                     print_debuginfo(l_module_name,
13450                                                        'For payment id '
13451                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index)
13452                                                        || ', orig payment amount: '
13453                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_cbr_index));
13454           END IF;
13455 
13456           IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_cbr_index) := hookPmtsTab(j).payment_amount;
13457 	  IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_cbr_index) := hookPmtsTab(j).discount_amount_taken;
13458 	  IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(l_trx_cbr_index) := hookPmtsTab(j).bank_charge_amount;
13459 
13460           IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13461                                                     print_debuginfo(l_module_name,
13462                                                        'For payment id '
13463                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_cbr_index)
13464                                                        || ', Updated payment amount: '
13465                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_cbr_index));
13466           END IF;
13467             /*
13468                   * Adjust payment status if necessary.
13469                   */
13470                  IF (UPPER(hookPmtsTab(j).dont_pay_flag) = 'Y') THEN
13471 
13472                    IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_cbr_index) := PAY_STATUS_CA_FAILED;
13473 
13474 		 /*
13475 		 UPDATE IBY_PAYMENTS_ALL
13476 		 SET PAYMENT_STATUS = PAY_STATUS_CA_FAILED
13477 		 WHERE PAYMENT_ID = hookPmtsTab(j).payment_id;
13478 		 */
13479 
13480 
13481                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13482 		print_debuginfo(l_module_name, 'Payment '
13483                          || hookPmtsTab(j).payment_id
13484                          || ' was failed by calling app.');
13485 		     END IF;
13486                      /*
13487                       * Once we fail a payment, we need to create
13488                       * an error record and insert this record
13489                       * into the errors table.
13490                       */
13491                      IBY_BUILD_UTILS_PKG.createErrorRecord(
13492                          TRXN_TYPE_PMT,
13493                          hookPmtsTab(j).payment_id,
13494                          PAY_STATUS_CA_FAILED,
13495                          NULL,
13496                          hookPmtsTab(j).payment_id,
13497                          NULL,
13498                          NULL,
13499                          NULL,
13500                          NULL,
13501                          NULL,
13502                          l_doc_err_rec,
13503                          x_errTokenTab
13504                          );
13505 
13506                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
13507                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
13508 
13509                  /* fail the docs of this payment */
13510                  failDocsOfPayment(hookPmtsTab(j).payment_id,
13511                      DOC_STATUS_PAY_VAL_FAIL,
13512                      x_docErrorTab, x_errTokenTab);
13513 
13514                  END IF;
13515 
13516 
13517 	END LOOP;
13518 
13519 
13520 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13521      print_debuginfo(l_module_name, 'Before merge.. ' );
13522 END IF;
13523     MERGE
13524     INTO iby_docs_in_pmt_gt idpa
13525     USING iby_hook_docs_in_pmt_t idpt ON(idpt.document_payable_id = idpa.document_payable_id)
13526     WHEN MATCHED THEN UPDATE
13527     SET idpa.document_amount = idpt.document_amount,
13528     idpa.amount_withheld = idpt.amount_withheld,
13529     idpa.payment_curr_discount_taken = idpt.payment_curr_discount_taken;
13530 
13531      OPEN c_fail_docs_of_payment;
13532      FETCH c_fail_docs_of_payment BULK COLLECT INTO l_fail_dop_tbl;
13533      CLOSE c_fail_docs_of_payment;
13534      /*
13535       * Loop through docs, failing the ones that have the
13536       * have given payment id.
13537       */
13538 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13539       print_debuginfo(l_module_name, 'Before updating the GT table' );
13540 END IF;
13541       UPDATE iby_docs_in_pmt_gt idpa
13542          SET idpa.document_status = DOC_STATUS_CA_FAILED
13543          WHERE idpa.document_payable_id IN (SELECT document_payable_id from iby_hook_docs_in_pmt_t idpt
13544                                        WHERE idpt.dont_pay_flag = 'Y');
13545 
13546      IF (l_fail_dop_tbl.COUNT > 0 ) THEN
13547 
13548      FOR j in  l_fail_dop_tbl.FIRST ..  l_fail_dop_tbl.LAST LOOP
13549 
13550                      /*
13551                       * Once we fail a doc, we must add a corresponding
13552                       * error message to the error table.
13553                       */
13554                      IBY_BUILD_UTILS_PKG.createErrorRecord(
13555                          TRXN_TYPE_DOC,
13556                          l_fail_dop_tbl(j).document_payable_id,
13557                          l_fail_dop_tbl(j).document_status,
13558                          l_fail_dop_tbl(j).calling_app_id,
13559                          l_fail_dop_tbl(j).calling_app_doc_unique_ref1,
13560                          l_fail_dop_tbl(j).calling_app_doc_unique_ref2,
13561                          l_fail_dop_tbl(j).calling_app_doc_unique_ref3,
13562                          l_fail_dop_tbl(j).calling_app_doc_unique_ref4,
13563                          l_fail_dop_tbl(j).calling_app_doc_unique_ref5,
13564                          l_fail_dop_tbl(j).pay_proc_trxn_type_code,
13565                          l_doc_err_rec,
13566                          x_errTokenTab
13567                          );
13568 
13569                      IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
13570                          l_doc_err_rec, x_docErrorTab, x_errTokenTab);
13571 
13572      END LOOP;
13573    END IF; -- IF (l_fail_dop_tbl.COUNT > 0 )
13574      /*
13575       * STEP 2:
13576       *
13577       * The external app may not wish to pay certain documents.
13578       * For such cases, make sure to fail the sister docs that are
13579       * related to this document via the 'payment grouping number'.
13580       * Each time a sister doc is failed, adjust the payment amount
13581       * of the payment that contains this document to reflect this.
13582       */
13583     adjustSisterDocsAndPmtsPost(
13584 	 --x_paymentTab,
13585          x_docErrorTab,
13586 	 x_errTokenTab);
13587 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13588      print_debuginfo(l_module_name, 'EXIT');
13589 END IF;
13590 EXCEPTION
13591    WHEN OTHERS THEN
13592    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
13593                  FND_LOG.LEVEL_UNEXPECTED);
13594              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
13595                  FND_LOG.LEVEL_UNEXPECTED);
13596    print_debuginfo(l_module_name, l_module_name||':Exception while performing performPostHookProcess');
13597    RAISE;
13598  END performPostHookProcess;
13599 
13600 /*--------------------------------------------------------------------
13601  | NAME:
13602  |     adjustSisterDocsAndPmts
13603  |
13604  | PURPOSE:
13605  |     If payment fails validation, then all it's constituent documents
13606  |     must also be failed. This is done in the validation flow itself.
13607  |
13608  |     However, one document may be related to another document by the
13609  |     payment grouping number. All related documents must be failed together.
13610  |     Therefore, if a document is failed in a payment, we must scan
13611  |     all payments for it's related documents and fail them also.
13612  |     Further, when a document is failed, the amount on the payment
13613  |     must be reduced accordingly.
13614  |
13615  |     This method handles such cascade failures.
13616  |
13617  | PARAMETERS:
13618  |     IN
13619  |
13620  |     OUT
13621  |
13622  |
13623  | RETURNS:
13624  |
13625  | NOTES:
13626  |
13627  *---------------------------------------------------------------------*/
13628  PROCEDURE adjustSisterDocsAndPmts(
13629      x_paymentTab     IN OUT NOCOPY paymentTabType,
13630      x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
13631      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
13632      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
13633      )
13634  IS
13635 
13636  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
13637 
13638  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
13639                                              '.adjustSisterDocsAndPmts';
13640 
13641  BEGIN
13642 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13643      print_debuginfo(l_module_name, 'ENTER');
13644 END IF;
13645      IF (x_docsInPmtTab.COUNT > 0) THEN
13646      FOR i in x_docsInPmtTab.FIRST ..  x_docsInPmtTab.LAST LOOP
13647 
13648          /*
13649           * The loop below implements logic for cascade failure of documents.
13650           * Cascade failure occurs when one doc is failed for some reason,
13651           * and so, it's related docs must also be failed.
13652           *
13653           * We enter this loop looking for documents that are:
13654           * a. Failed for some reason
13655           * b. Not already failed by cascade failure
13656           *
13657           * Condition (b) is important otherwise, a doc that has been failed
13658           * by cascade earlier will continue to trigger off another round
13659           * of cascade failures. This cyclic effect is prevented by (b).
13660           */
13661          IF (x_docsInPmtTab(i).document_status <> DOC_STATUS_PAY_CREATED AND
13662              x_docsInPmtTab(i).document_status <> DOC_STATUS_RELN_FAIL  AND
13663 	     x_docsInPmtTab(i).payment_grp_num IS NOT NULL)
13664              THEN
13665 
13666              FOR j in x_docsInPmtTab.FIRST ..  x_docsInPmtTab.LAST LOOP
13667 
13668                  /*
13669                   * For all documents which share this 'payment grouping
13670                   * number' do:
13671                   *
13672                   * a. Set the doc to 'failed' status
13673                   *
13674                   * b. Adjust the payment total on the
13675                   *    payment which contained this
13676                   *    document.
13677                   *
13678                   * Note: Take care to skip the triggering doc itself
13679                   * from this loop because this doc is already in
13680                   * failed status and the payment amount already adjusted.
13681                   */
13682 
13683                  /* skip the triggering doc */
13684                  IF (x_docsInPmtTab(i).document_id <>
13685                      x_docsInPmtTab(j).document_id) THEN
13686 
13687                      /*
13688                       * skip docs that we have already failed in an
13689                       * earlier iteration of this loop
13690                       */
13691                      IF (x_docsInPmtTab(j).document_status <>
13692                          DOC_STATUS_RELN_FAIL) THEN
13693 
13694                          IF (x_docsInPmtTab(i).payment_grp_num =
13695                              x_docsInPmtTab(j).payment_grp_num) THEN
13696 
13697                              /* a. fail document */
13698                              x_docsInPmtTab(j).document_status
13699                                  := DOC_STATUS_RELN_FAIL;
13700 
13701                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13702  print_debuginfo(l_module_name, 'Cascaded doc '
13703                                  || 'failure: '
13704                                  || x_docsInPmtTab(i).document_id
13705                                  || ' -> '
13706                                  || x_docsInPmtTab(j).document_id
13707                                  || '. Related by '
13708                                  || x_docsInPmtTab(i).payment_grp_num
13709                                  || '.'
13710                                  );
13711 			     END IF;
13712                              /*
13713                               * Once we fail a doc, we must add a corresponding
13714                               * error message to the error table.
13715                               */
13716                              IBY_BUILD_UTILS_PKG.createErrorRecord(
13717                                  TRXN_TYPE_DOC,
13718                                  x_docsInPmtTab(j).document_id,
13719                                  x_docsInPmtTab(j).document_status,
13720                                  x_docsInPmtTab(j).calling_app_id,
13721                                  x_docsInPmtTab(j).calling_app_doc_id1,
13722                                  x_docsInPmtTab(j).calling_app_doc_id2,
13723                                  x_docsInPmtTab(j).calling_app_doc_id3,
13724                                  x_docsInPmtTab(j).calling_app_doc_id4,
13725                                  x_docsInPmtTab(j).calling_app_doc_id5,
13726                                  x_docsInPmtTab(j).pay_proc_ttype_cd,
13727                                  l_doc_err_rec,
13728                                  x_errTokenTab
13729                                  );
13730 
13731                              IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
13732                                  l_doc_err_rec, x_docErrorTab, x_errTokenTab);
13733 
13734                              /* b. adjust payment amount */
13735                              FOR k in x_paymentTab.FIRST ..  x_paymentTab.LAST
13736                                  LOOP
13737 
13738                                  IF (x_paymentTab(k).payment_id =
13739                                      x_docsInPmtTab(j).payment_id) THEN
13740 
13741                                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13742  print_debuginfo(l_module_name,
13743                                          'For payment id '
13744                                          || x_paymentTab(k).payment_id
13745                                          || ', orig payment amount: '
13746                                          || x_paymentTab(k).payment_amount);
13747 				     END IF;
13748 
13749                                      x_paymentTab(k).payment_amount :=
13750                                          x_paymentTab(k).payment_amount
13751                                              - x_docsInPmtTab(j).
13752                                                    document_amount;
13753 
13754                                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13755  print_debuginfo(l_module_name, 'Payment'
13756                                          || ' amount reduced by '
13757                                          || x_docsInPmtTab(j).document_amount
13758                                          || '. New payment amount: '
13759                                          || x_paymentTab(k).payment_amount);
13760 				     END IF;
13761                                      /*
13762                                       * If we have adjusted the payment amount
13763                                       * in the if-condition we can exit the
13764                                       * loop.
13765                                       */
13766                                      EXIT WHEN (1=1);
13767 
13768                                  END IF;
13769 
13770                              END LOOP; -- loop for adjusting payment amount
13771 
13772                          END IF;
13773 
13774                      END IF;
13775 
13776                  END IF;
13777 
13778              END LOOP; -- loop for scanning sister documents
13779 
13780          END IF;
13781 
13782      END LOOP; -- loop through all documents looking for failed docs
13783      END IF; -- if document count > 0
13784 
13785      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13786  print_debuginfo(l_module_name, 'EXIT');
13787      end if;
13788  END adjustSisterDocsAndPmts;
13789 
13790 
13791 /*--------------------------------------------------------------------
13792  | NAME:
13793  |     adjustSisterDocsAndPmts
13794  |
13795  | PURPOSE:
13796  |     If payment fails validation, then all it's constituent documents
13797  |     must also be failed. This is done in the validation flow itself.
13798  |
13799  |     However, one document may be related to another document by the
13800  |     payment grouping number. All related documents must be failed together.
13801  |     Therefore, if a document is failed in a payment, we must scan
13802  |     all payments for it's related documents and fail them also.
13803  |     Further, when a document is failed, the amount on the payment
13804  |     must be reduced accordingly.
13805  |
13806  |     This method handles such cascade failures.
13807  |
13808  | PARAMETERS:
13809  |     IN
13810  |
13811  |     OUT
13812  |
13813  |
13814  | RETURNS:
13815  |
13816  | NOTES:
13817  |
13818  *---------------------------------------------------------------------*/
13819  PROCEDURE adjustSisterDocsAndPmts(
13820 --     x_paymentTab     IN OUT NOCOPY paymentTabType,
13821 --     x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
13822      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
13823      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
13824      )
13825  IS
13826 
13827  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
13828 
13829  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
13830                                              '.adjustSisterDocsAndPmts';
13831 
13832  l_document_amount IBY_DOCS_PAYABLE_ALL.document_amount%TYPE;
13833 
13834  l_payment_id_indx IBY_DOCS_PAYABLE_ALL.payment_id%TYPE;
13835 
13836  l_prev_payment_grp_num     IBY_DOCS_PAYABLE_ALL.payment_grouping_number%TYPE;
13837 
13838 
13839 
13840 CURSOR c_adjust_sdap IS
13841 SELECT idpt.payment_id,
13842    idpt.document_payable_id,
13843    idpt.document_status,
13844    idpt.calling_app_id,
13845    idpt.calling_app_doc_unique_ref1,
13846    idpt.calling_app_doc_unique_ref2,
13847    idpt.calling_app_doc_unique_ref3,
13848    idpt.calling_app_doc_unique_ref4,
13849    idpt.calling_app_doc_unique_ref5,
13850    idpt.pay_proc_trxn_type_code,
13851    idpt.document_amount,
13852    idpt.payment_grouping_number
13853 FROM iby_docs_in_pmt_gt idpt
13854 WHERE idpt.payment_grouping_number  IS NOT NULL
13855     AND idpt.document_status <> DOC_STATUS_RELN_FAIL
13856     AND EXISTS (SELECT 1 FROM iby_docs_in_pmt_gt idpit WHERE idpit.payment_grouping_number  IS NOT NULL
13857                 AND idpit.payment_grouping_number = idpt.payment_grouping_number
13858                 AND idpit.document_status <> DOC_STATUS_PAY_CREATED
13859                 AND idpit.document_status <> DOC_STATUS_RELN_FAIL)
13860 ORDER BY idpt.payment_grouping_number, idpt.payment_id;
13861 
13862  BEGIN
13863 
13864      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13865  print_debuginfo(l_module_name, 'ENTER');
13866      END IF;
13867 
13868      OPEN c_adjust_sdap;
13869      FETCH c_adjust_sdap BULK COLLECT INTO l_fail_dop_tbl;
13870      CLOSE c_adjust_sdap;
13871 
13872 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13873      print_debuginfo(l_module_name, 'After fetching the data from GTT into l_fail_dop_tbl');
13874 END IF;
13875      /*
13876       * Loop through docs, failing the ones that have the
13877       * have given payment id.
13878       */
13879      l_prev_payment_grp_num := null;
13880      l_document_amount := null;
13881 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13882       print_debuginfo(l_module_name, 'After assigning null values');
13883      -- print_debuginfo(l_module_name,' count of x_paymentTab' || x_paymentTab.COUNT);
13884       print_debuginfo(l_module_name,' count of l_fail_dop_tbl' || l_fail_dop_tbl.COUNT);
13885 END IF;
13886 
13887      IF ( l_fail_dop_tbl.COUNT > 0 ) THEN
13888 
13889      FOR j in l_fail_dop_tbl.FIRST .. l_fail_dop_tbl.LAST LOOP
13890 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13891           print_debuginfo(l_module_name, 'l_fail_dop_tbl(j).payment_id -'||l_fail_dop_tbl(j).payment_id);
13892 END IF;
13893 	  IF(l_fail_dop_tbl(j).payment_id IS NOT NULL) THEN
13894 	  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13895                    print_debuginfo(l_module_name, 'inside if payment_id is not null');
13896 				   END IF;
13897               l_payment_id_indx := l_fail_dop_tbl(j).payment_id;
13898 
13899             IF(sdap_tbl.EXISTS(l_payment_id_indx)) THEN
13900 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13901                    print_debuginfo(l_module_name, 'inside if sdap_tbl exists(index)');
13902 				   END IF;
13903 
13904                 IF(l_fail_dop_tbl(j).document_status = DOC_STATUS_PAY_CREATED) THEN
13905                    --l_document_amount = l_fail_dop_tbl(j).document_amount;
13906 				   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13907                   print_debuginfo(l_module_name, 'inside if l_fail_dop_tbl(j) status - created');
13908 				  END IF;
13909                   sdap_tbl(l_fail_dop_tbl(j).payment_id) := sdap_tbl(l_fail_dop_tbl(j).payment_id) + l_fail_dop_tbl(j).document_amount;
13910                 END IF;
13911 
13912                 IF(l_fail_dop_tbl(j).payment_grouping_number <> l_prev_payment_grp_num) THEN
13913 
13914                      UPDATE iby_docs_in_pmt_gt idipt
13915                      SET idipt.document_status = DOC_STATUS_RELN_FAIL
13916                      WHERE idipt.payment_grouping_number = l_fail_dop_tbl(j).payment_grouping_number
13917                      AND idipt.document_status = DOC_STATUS_PAY_CREATED;
13918 					 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13919                 print_debuginfo(l_module_name, 'after updation of the GTT with reln_fail');
13920 				END IF;
13921                 END IF;
13922 
13923                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13924                      print_debuginfo(l_module_name, 'Updated docs '
13925                                          || 'failure: '
13926                                          || '. Related by '
13927                                          || l_fail_dop_tbl(j).payment_grouping_number
13928                                          || '.'
13929                                          );
13930                     END IF;
13931 
13932                              /*
13933                               * Once we fail a doc, we must add a corresponding
13934                               * error message to the error table.
13935                               */
13936                              IBY_BUILD_UTILS_PKG.createErrorRecord(
13937                              TRXN_TYPE_DOC,
13938                              l_fail_dop_tbl(j).document_payable_id,
13939                              l_fail_dop_tbl(j).document_status,
13940                              l_fail_dop_tbl(j).calling_app_id,
13941                              l_fail_dop_tbl(j).calling_app_doc_unique_ref1,
13942                              l_fail_dop_tbl(j).calling_app_doc_unique_ref2,
13943                              l_fail_dop_tbl(j).calling_app_doc_unique_ref3,
13944                              l_fail_dop_tbl(j).calling_app_doc_unique_ref4,
13945                              l_fail_dop_tbl(j).calling_app_doc_unique_ref5,
13946                              l_fail_dop_tbl(j).pay_proc_trxn_type_code,
13947                              l_doc_err_rec,
13948                              x_errTokenTab
13949                              );
13950 
13951                              IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
13952                                  l_doc_err_rec, x_docErrorTab, x_errTokenTab);
13953 
13954 
13955 
13956                      --sdap_tbl.(l_fail_dop_tbl(j).payment_id) := l_fail_dop_tbl(j).payment_id;
13957                      --sdap_tbl.(l_payment_id_indx) = l_fail_dop_tbl(j).payment_id;
13958              END IF;
13959 
13960         END IF;
13961 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13962         print_debuginfo(l_module_name, 'After end if for checking if pmt id is not null' );
13963 		END IF;
13964 
13965                     l_prev_payment_grp_num := l_fail_dop_tbl(j).payment_grouping_number;
13966 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13967 	 print_debuginfo(l_module_name, 'After assigning the pmt grp number to l_prev_pmt_grp');
13968 	 END IF;
13969 
13970      END LOOP;
13971 
13972      END IF; -- end of check if count > 0
13973 
13974 
13975      /* b. adjust payment amount */
13976 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13977      print_debuginfo(l_module_name, 'After the loop, before iterating through pmts table');
13978 	 END IF;
13979 
13980                         --     FOR k in x_paymentTab.FIRST ..  x_paymentTab.LAST
13981                                FOR k IN nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99)
13982                                  LOOP
13983 								 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13984                                  print_debuginfo(l_module_name, 'Inside the loop - x_PaymentTab');
13985 								 END IF;
13986                                     IF(sdap_tbl.EXISTS(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))) THEN
13987 
13988                                                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
13989                                                     print_debuginfo(l_module_name,
13990                                                        'For payment id '
13991                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_id(k)
13992                                                        || ', orig payment amount: '
13993                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_amount(k));
13994                                                    END IF;
13995 
13996                                                IBY_PAYGROUP_PUB.pmtTable.payment_amount(k) :=
13997                                                    IBY_PAYGROUP_PUB.pmtTable.payment_amount(k)
13998                                                        - sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k));
13999                                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14000 			        print_debuginfo(l_module_name, 'After changing the payment amount');
14001 					END IF;
14002                                                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14003                                                 print_debuginfo(l_module_name, 'Payment'
14004                                                    || ' amount reduced by '
14005                                                    || sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))
14006                                                    || '. New payment amount: '
14007                                                    || IBY_PAYGROUP_PUB.pmtTable.payment_amount(k));
14008                                                END IF;
14009                                      END IF;
14010 
14011                              END LOOP; -- loop for adjusting payment amount
14012 
14013      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14014  print_debuginfo(l_module_name, 'EXIT');
14015      end if;
14016  END adjustSisterDocsAndPmts;
14017 
14018 
14019    /*--------------------------------------------------------------------
14020  | NAME:
14021  |     adjustSisterDocsAndPmtsPost
14022  |
14023  | PURPOSE:
14024  |     To be called from PostHookProcess
14025  |     If payment fails validation, then all it's constituent documents
14026  |     must also be failed. This is done in the validation flow itself.
14027  |
14028  |     However, one document may be related to another document by the
14029  |     payment grouping number. All related documents must be failed together.
14030  |     Therefore, if a document is failed in a payment, we must scan
14031  |     all payments for it's related documents and fail them also.
14032  |     Further, when a document is failed, the amount on the payment
14033  |     must be reduced accordingly.
14034  |
14035  |     This method handles such cascade failures.
14036  |
14037  | PARAMETERS:
14038  |     IN
14039  |
14040  |     OUT
14041  |
14042  |
14043  | RETURNS:
14044  |
14045  | NOTES:
14046  |
14047  *---------------------------------------------------------------------*/
14048  PROCEDURE adjustSisterDocsAndPmtsPost(
14049 --     x_paymentTab     IN OUT NOCOPY paymentTabType,
14050 --     x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
14051      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
14052      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
14053      )
14054  IS
14055 
14056  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
14057 
14058  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
14059                                              '.adjustSisterDocsAndPmtsPost';
14060 
14061  l_document_amount IBY_DOCS_PAYABLE_ALL.document_amount%TYPE;
14062 
14063  l_payment_id_indx IBY_DOCS_PAYABLE_ALL.payment_id%TYPE;
14064 
14065  l_prev_payment_grp_num     IBY_DOCS_PAYABLE_ALL.payment_grouping_number%TYPE;
14066 
14067 
14068 
14069 CURSOR c_adjust_sdap IS
14070 SELECT idpt.payment_id,
14071    idpt.document_payable_id,
14072    idpt.document_status,
14073    idpt.calling_app_id,
14074    idpt.calling_app_doc_unique_ref1,
14075    idpt.calling_app_doc_unique_ref2,
14076    idpt.calling_app_doc_unique_ref3,
14077    idpt.calling_app_doc_unique_ref4,
14078    idpt.calling_app_doc_unique_ref5,
14079    idpt.pay_proc_trxn_type_code,
14080    idpt.document_amount,
14081    idpt.payment_grouping_number
14082 FROM iby_docs_in_pmt_gt idpt
14083 WHERE idpt.payment_grouping_number  IS NOT NULL
14084     AND idpt.document_status <> DOC_STATUS_RELN_FAIL
14085     AND EXISTS (SELECT 1 FROM iby_docs_in_pmt_gt idpit WHERE idpit.payment_grouping_number  IS NOT NULL
14086                 AND idpit.payment_grouping_number = idpt.payment_grouping_number
14087                 AND idpit.document_status <> DOC_STATUS_PAY_CREATED
14088                 AND idpit.document_status <> DOC_STATUS_RELN_FAIL)
14089 ORDER BY idpt.payment_grouping_number, idpt.payment_id;
14090 
14091 
14092  BEGIN
14093 
14094      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14095  print_debuginfo(l_module_name, 'ENTER');
14096      END IF;
14097 
14098      OPEN c_adjust_sdap;
14099      FETCH c_adjust_sdap BULK COLLECT INTO l_fail_dop_tbl;
14100      CLOSE c_adjust_sdap;
14101      /*
14102       * Loop through docs, failing the ones that have the
14103       * have given payment id.
14104       */
14105      l_prev_payment_grp_num := null;
14106      l_document_amount := null;
14107 
14108   IF ( l_fail_dop_tbl.COUNT > 0 ) THEN
14109 
14110      FOR j in  l_fail_dop_tbl.FIRST ..  l_fail_dop_tbl.LAST LOOP
14111 
14112           IF(l_fail_dop_tbl(j).payment_id IS NOT NULL) THEN
14113 
14114               l_payment_id_indx := l_fail_dop_tbl(j).payment_id;
14115 
14116             IF(sdap_tbl.EXISTS(l_payment_id_indx)) THEN
14117 
14118                 IF(l_fail_dop_tbl(j).document_status = DOC_STATUS_PAY_CREATED) THEN
14119                    --l_document_amount = l_fail_dop_tbl(j).document_amount;
14120                   sdap_tbl(l_fail_dop_tbl(j).payment_id) := sdap_tbl(l_fail_dop_tbl(j).payment_id) + l_fail_dop_tbl(j).document_amount;
14121                 END IF;
14122 
14123                 IF(l_fail_dop_tbl(j).payment_grouping_number <> l_prev_payment_grp_num) THEN
14124 
14125                      UPDATE iby_docs_in_pmt_gt idipt
14126                      SET idipt.document_status = DOC_STATUS_RELN_FAIL
14127                      WHERE idipt.payment_grouping_number = l_fail_dop_tbl(j).payment_grouping_number
14128                      AND idipt.document_status = DOC_STATUS_PAY_CREATED;
14129 
14130                 END IF;
14131 
14132                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14133                      print_debuginfo(l_module_name, 'Updated docs '
14134                                          || 'failure: '
14135                                          || '. Related by '
14136                                          || l_fail_dop_tbl(j).payment_grouping_number
14137                                          || '.'
14138                                          );
14139                     END IF;
14140 
14141                              /*
14142                               * Once we fail a doc, we must add a corresponding
14143                               * error message to the error table.
14144                               */
14145                              IBY_BUILD_UTILS_PKG.createErrorRecord(
14146                              TRXN_TYPE_DOC,
14147                              l_fail_dop_tbl(j).document_payable_id,
14148                              l_fail_dop_tbl(j).document_status,
14149                              l_fail_dop_tbl(j).calling_app_id,
14150                              l_fail_dop_tbl(j).calling_app_doc_unique_ref1,
14151                              l_fail_dop_tbl(j).calling_app_doc_unique_ref2,
14152                              l_fail_dop_tbl(j).calling_app_doc_unique_ref3,
14153                              l_fail_dop_tbl(j).calling_app_doc_unique_ref4,
14154                              l_fail_dop_tbl(j).calling_app_doc_unique_ref5,
14155                              l_fail_dop_tbl(j).pay_proc_trxn_type_code,
14156                              l_doc_err_rec,
14157                              x_errTokenTab
14158                              );
14159 
14160                              IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
14161                                  l_doc_err_rec, x_docErrorTab, x_errTokenTab);
14162 
14163 
14164 
14165                      --sdap_tbl.(l_fail_dop_tbl(j).payment_id) := l_fail_dop_tbl(j).payment_id;
14166                      --sdap_tbl.(l_payment_id_indx) = l_fail_dop_tbl(j).payment_id;
14167              END IF;
14168 
14169         END IF;
14170 
14171                     l_prev_payment_grp_num := l_fail_dop_tbl(j).payment_grouping_number;
14172 
14173      END LOOP; -- loop through all documents looking for failed docs
14174 
14175  END IF; -- end of check if count > 0
14176 
14177 
14178      /* b. adjust payment amount */
14179                              --FOR k in x_paymentTab.FIRST ..  x_paymentTab.LAST
14180 			  /*
14181 			  FOR k IN nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99)
14182                                  LOOP
14183 
14184                                     IF(sdap_tbl.EXISTS(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))) THEN
14185 
14186                                                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14187                                                     print_debuginfo(l_module_name,
14188                                                        'For payment id '
14189                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_id(k)
14190                                                        || ', orig payment amount: '
14191                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_amount(k));
14192                                                    END IF;
14193 
14194                                                IBY_PAYGROUP_PUB.pmtTable.payment_amount(k) :=
14195                                                    IBY_PAYGROUP_PUB.pmtTable.payment_amount(k)
14196                                                        - sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k));
14197 
14198                                                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14199                                                 print_debuginfo(l_module_name, 'Payment'
14200                                                    || ' amount reduced by '
14201                                                    || sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))
14202                                                    || '. New payment amount: '
14203                                                    || IBY_PAYGROUP_PUB.pmtTable.payment_amount(k));
14204                                                END IF;
14205                                      END IF;
14206 
14207                              END LOOP; -- loop for adjusting payment amount
14208 
14209 			     */
14210 
14211 
14212 			  FOR k IN nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST,0) .. nvl(IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST,-99)
14213                                  LOOP
14214 
14215                                     IF(sdap_tbl.EXISTS(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))) THEN
14216 
14217                                                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14218                                                     print_debuginfo(l_module_name,
14219                                                        'For payment id '
14220                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_id(k)
14221                                                        || ', orig payment amount: '
14222                                                        || IBY_PAYGROUP_PUB.pmtTable.payment_amount(k));
14223                                                    END IF;
14224 
14225                                              /*  IBY_PAYGROUP_PUB.pmtTable.payment_amount(k) :=
14226                                                    IBY_PAYGROUP_PUB.pmtTable.payment_amount(k)
14227                                                        - sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k));
14228 					      */
14229 
14230 					      UPDATE IBY_PAYMENTS_ALL
14231 					      SET PAYMENT_AMOUNT = PAYMENT_AMOUNT -
14232 					       sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))
14233 					      WHERE
14234 					       PAYMENT_ID = IBY_PAYGROUP_PUB.pmtTable.payment_id(k);
14235 
14236                                                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14237                                                 print_debuginfo(l_module_name, 'Payment'
14238                                                    || ' amount reduced by '
14239                                                    || sdap_tbl(IBY_PAYGROUP_PUB.pmtTable.payment_id(k))
14240                                                    || '. New payment amount: '
14241                                                    || IBY_PAYGROUP_PUB.pmtTable.payment_amount(k));
14242                                                END IF;
14243                                      END IF;
14244 
14245                              END LOOP; -- loop for adjusting payment amount
14246 
14247      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14248  print_debuginfo(l_module_name, 'EXIT');
14249      end if;
14250  END adjustSisterDocsAndPmtsPost;
14251 
14252 /*--------------------------------------------------------------------
14253  | NAME:
14254  |     getDocDetails
14255  |
14256  | PURPOSE:
14257  |     Returns the payment details calculated as per given formula on
14258  |     a given document.
14259  |
14260  |     The formula should be a SQL expression involving the attributes
14261  |     of the document - e.g., 'doc id || doc date'.
14262  |
14263  | PARAMETERS:
14264  |     IN
14265  |
14266  |     OUT
14267  |
14268  |
14269  | RETURNS:
14270  |
14271  | NOTES:
14272  |
14273  *---------------------------------------------------------------------*/
14274  FUNCTION getDocDetails(
14275      p_documentID         IN NUMBER,
14276      p_pmtDetailsFormula  IN VARCHAR2
14277      )
14278      RETURN VARCHAR2
14279  IS
14280  l_module_name      CONSTANT VARCHAR2(200)  := G_PKG_NAME || '.getDocDetails';
14281  l_calc_doc_details VARCHAR2(2000) := '';
14282  l_sql_string       VARCHAR2(4000) := '';
14283 
14284  BEGIN
14285 
14286      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14287 	print_debuginfo(l_module_name, 'ENTER');
14288 
14289      END IF;
14290 
14291      l_sql_string := 'SELECT ' || p_pmtDetailsFormula || ' FROM '
14292                          || 'IBY_DOCS_PAYABLE_ALL WHERE '
14293                          || 'document_payable_id = :bind_var';
14294 
14295      EXECUTE IMMEDIATE l_sql_string INTO l_calc_doc_details USING p_documentID;
14296 
14297      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14298 	print_debuginfo(l_module_name, 'EXIT');
14299 
14300      END IF;
14301 
14302      RETURN l_calc_doc_details;
14303 
14304  END getDocDetails;
14305 
14306 /*--------------------------------------------------------------------
14307  | NAME:
14308  |     callHook
14309  |
14310  | PURPOSE:
14311  |     Makes a call to the calling app specific hook. The calling
14312  |     app is expected to implement the hook using the naming
14313  |     convention <Application Short Name>_paymentsAdjustHook().
14314  |
14315  |
14316  | PARAMETERS:
14317  |     IN
14318  |
14319  |     OUT
14320  |
14321  |
14322  | RETURNS:
14323  |
14324  | NOTES:
14325  |
14326  *---------------------------------------------------------------------*/
14327  PROCEDURE callHook(
14328      p_payreq_id       IN IBY_PAY_SERVICE_REQUESTS.
14329                               payment_service_request_id%type
14330      )
14331  IS
14332 
14333  l_module_name      CONSTANT VARCHAR2(200)  := G_PKG_NAME || '.callHook';
14334  l_app_short_name   VARCHAR2(200);
14335 
14336  l_pkg_prefix       VARCHAR2(100);
14337  l_pkg_suffix       VARCHAR2(100) := '_PMT_CALLOUT_PKG';
14338  l_pkg_name         VARCHAR2(200);
14339 
14340  l_hook_name        VARCHAR2(500);
14341  l_stmt             VARCHAR2(1000);
14342 
14343  /*
14344   * Implementing the hook is optional for the calling app.
14345   * If the calling app does not implement the hook, then
14346   * the call to the hook will result in ORA-06576 error.
14347   *
14348   * There is no exception name associated with this code, so
14349   * we create one called 'PROCEDURE_NOT_IMPLEMENTED'. If this
14350   * exception occurs, it is not fatal: we log the error and
14351   * proceed.
14352   *
14353   * If, on the other hand, the calling app implements the
14354   * hook, but the hook throws an exception, it is fatal
14355   * and we must abort the program (this will be caught
14356   * in WHEN OTHERS block).
14357   */
14358  PROCEDURE_NOT_IMPLEMENTED EXCEPTION;
14359  PRAGMA EXCEPTION_INIT(PROCEDURE_NOT_IMPLEMENTED, -6576);
14360 
14361  BEGIN
14362 
14363      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14364 	print_debuginfo(l_module_name, 'ENTER');
14365         print_debuginfo(l_module_name, 'Provided payment request id: '
14366          || p_payreq_id);
14367 
14368  END IF;
14369      /*
14370       * The hook method implemented by the calling app will
14371       * of the form:
14372       * <Application Short Name>_paymentsAdjustHook()
14373       *
14374       * First, get the application short name from the calling
14375       * application id.
14376       */
14377      BEGIN
14378 
14379          SELECT
14380              fnd.application_short_name
14381          INTO
14382              l_app_short_name
14383          FROM
14384              FND_APPLICATION fnd,
14385              IBY_PAY_SERVICE_REQUESTS req
14386          WHERE
14387              fnd.application_id             = req.calling_app_id AND
14388              req.payment_service_request_id = p_payreq_id
14389          ;
14390 
14391      EXCEPTION
14392          WHEN OTHERS THEN
14393 
14394 		print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
14395                  || 'to get calling application short name. Provided payment '
14396                  || 'request id: ' || p_payreq_id, FND_LOG.LEVEL_UNEXPECTED);
14397                 print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
14398                  FND_LOG.LEVEL_UNEXPECTED);
14399                 print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
14400                  FND_LOG.LEVEL_UNEXPECTED);
14401 
14402 
14403              /*
14404               * Propogate exception to caller.
14405               */
14406              RAISE;
14407      END;
14408 
14409      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14410 	print_debuginfo(l_module_name, 'Retrieved app short name: '
14411          || l_app_short_name);
14412 
14413  END IF;
14414 
14415      /*
14416       * When we invoke the hook procedure in the external app,
14417       * we must use the hook signature as <package name>.<procedure name>.
14418       *
14419       * For some applications, the application short name cannot
14420       * be directly used in forming the package name.
14421       *
14422       * Example, for AP, the application short name is 'SQLAP',
14423       * but the AP packages begin as 'AP_XXXX'. Therefore,
14424       * we will convert the application short names into package
14425       * prefixes here.
14426       */
14427      CASE l_app_short_name
14428          WHEN 'SQLAP' THEN
14429              l_pkg_prefix := 'AP';
14430          ELSE
14431              l_pkg_prefix := l_app_short_name;
14432      END CASE;
14433 
14434      l_pkg_name := l_pkg_prefix || l_pkg_suffix;
14435 
14436      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14437 	print_debuginfo(l_module_name, 'Constructed package name: '
14438          || l_pkg_name);
14439 
14440      END IF;
14441 
14442      /*
14443       * Now try to call the external app's implementation of the hook.
14444       * The calling app may or may not have implemented the hook, so
14445       * it's not fatal if the implementation does not exist.
14446       */
14447      l_hook_name := l_pkg_name || '.' || 'paymentsAdjustHook';
14448 
14449      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14450 	print_debuginfo(l_module_name, 'Attempting to call hook: '
14451          || l_hook_name);
14452 
14453  END IF;
14454      l_stmt := 'CALL '|| l_hook_name || '()';
14455 
14456      BEGIN
14457 
14458          EXECUTE IMMEDIATE (l_stmt);
14459 
14460      EXCEPTION
14461 
14462          WHEN PROCEDURE_NOT_IMPLEMENTED THEN
14463              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14464 		print_debuginfo(l_module_name, 'Hook "' || l_hook_name
14465                  || '" not implemented by calling app '
14466                  || l_app_short_name || '.');
14467 
14468                 print_debuginfo(l_module_name, 'Skipping hook call.');
14469 
14470  END IF;
14471          WHEN OTHERS THEN
14472 
14473 	     print_debuginfo(l_module_name, 'Fatal: External app hook '''
14474                  || l_hook_name  || ''', generated exception. Please '
14475                  || ' contact implementor of hook in product '
14476                  || l_app_short_name || ' for fix.',
14477                  FND_LOG.LEVEL_UNEXPECTED);
14478 
14479              print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
14480                  FND_LOG.LEVEL_UNEXPECTED);
14481              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
14482                  FND_LOG.LEVEL_UNEXPECTED);
14483 
14484 
14485              /*
14486               * Propogate exception to caller.
14487               */
14488              RAISE;
14489      END;
14490 
14491      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14492 	print_debuginfo(l_module_name, 'EXIT');
14493 
14494  END IF;
14495  END callHook;
14496 
14497 /*--------------------------------------------------------------------
14498  | NAME:
14499  |     getAdjustedPaymentData
14500  |
14501  | PURPOSE:
14502  |     Reads the data updated in the global temp tables by the calling app.
14503  |     The calling app would have updated the data when the external
14504  |     application hook was called. This method reads in the updated
14505  |     data.
14506  |
14507  | PARAMETERS:
14508  |     IN
14509  |
14510  |     OUT
14511  |
14512  |
14513  | RETURNS:
14514  |
14515  | NOTES:
14516  |
14517  *---------------------------------------------------------------------*/
14518  PROCEDURE getAdjustedPaymentData(
14519      x_hookPaymentTab      IN OUT NOCOPY hookPaymentTabType,
14520      x_hookDocsInPmtTab    IN OUT NOCOPY hookDocsInPaymentTabType
14521      )
14522  IS
14523 
14524  l_module_name  CONSTANT VARCHAR2(200) := G_PKG_NAME ||
14525                                               '.getAdjustedPaymentData';
14526 
14527      TYPE t_calling_app_id IS TABLE OF
14528      IBY_HOOK_PAYMENTS_T.calling_app_id%TYPE
14529      INDEX BY BINARY_INTEGER;
14530      TYPE t_call_app_pay_srv_req_code IS TABLE OF
14531      IBY_HOOK_PAYMENTS_T.call_app_pay_service_req_code%TYPE
14532      INDEX BY BINARY_INTEGER;
14533      TYPE t_payment_service_request_id IS TABLE OF
14534      IBY_HOOK_PAYMENTS_T.payment_service_request_id%TYPE
14535      INDEX BY BINARY_INTEGER;
14536      TYPE t_payment_id IS TABLE OF
14537      IBY_HOOK_PAYMENTS_T.payment_id%TYPE
14538      INDEX BY BINARY_INTEGER;
14539      TYPE t_payment_amount IS TABLE OF
14540      IBY_HOOK_PAYMENTS_T.payment_amount%TYPE
14541      INDEX BY BINARY_INTEGER;
14542      TYPE t_payment_currency_code IS TABLE OF
14543      IBY_HOOK_PAYMENTS_T.payment_currency_code%TYPE
14544      INDEX BY BINARY_INTEGER;
14545      TYPE t_dont_pay_flag IS TABLE OF
14546      IBY_HOOK_PAYMENTS_T.dont_pay_flag%TYPE
14547      INDEX BY BINARY_INTEGER;
14548      TYPE t_dont_pay_reason_code IS TABLE OF
14549      IBY_HOOK_PAYMENTS_T.dont_pay_reason_code%TYPE
14550      INDEX BY BINARY_INTEGER;
14551      TYPE t_dont_pay_description IS TABLE OF
14552      IBY_HOOK_PAYMENTS_T.dont_pay_description%TYPE
14553      INDEX BY BINARY_INTEGER;
14554      TYPE t_internal_bank_account_id IS TABLE OF
14555      IBY_HOOK_PAYMENTS_T.internal_bank_account_id%TYPE
14556      INDEX BY BINARY_INTEGER;
14557      TYPE t_ext_payee_id IS TABLE OF
14558      IBY_HOOK_PAYMENTS_T.ext_payee_id%TYPE
14559      INDEX BY BINARY_INTEGER;
14560      TYPE t_payee_party_id IS TABLE OF
14561      IBY_HOOK_PAYMENTS_T.payee_party_id%TYPE
14562      INDEX BY BINARY_INTEGER;
14563      TYPE t_party_site_id IS TABLE OF
14564      IBY_HOOK_PAYMENTS_T.party_site_id%TYPE
14565      INDEX BY BINARY_INTEGER;
14566      TYPE t_supplier_site_id IS TABLE OF
14567      IBY_HOOK_PAYMENTS_T.supplier_site_id%TYPE
14568      INDEX BY BINARY_INTEGER;
14569      TYPE t_org_id IS TABLE OF
14570      IBY_HOOK_PAYMENTS_T.org_id%TYPE
14571      INDEX BY BINARY_INTEGER;
14572      TYPE t_org_type IS TABLE OF
14573      IBY_HOOK_PAYMENTS_T.org_type%TYPE
14574      INDEX BY BINARY_INTEGER;
14575      TYPE t_external_bank_account_id IS TABLE OF
14576      IBY_HOOK_PAYMENTS_T.external_bank_account_id%TYPE
14577      INDEX BY BINARY_INTEGER;
14578      TYPE t_discount_amount_taken IS TABLE OF
14579      IBY_HOOK_PAYMENTS_T.discount_amount_taken%TYPE
14580      INDEX BY BINARY_INTEGER;
14581      TYPE t_payment_date IS TABLE OF
14582      IBY_HOOK_PAYMENTS_T.payment_date%TYPE
14583      INDEX BY BINARY_INTEGER;
14584      TYPE t_bank_charge_amount IS TABLE OF
14585      IBY_HOOK_PAYMENTS_T.bank_charge_amount%TYPE
14586      INDEX BY BINARY_INTEGER;
14587      TYPE t_created_by IS TABLE OF
14588      IBY_HOOK_PAYMENTS_T.created_by%TYPE
14589      INDEX BY BINARY_INTEGER;
14590      TYPE t_creation_date IS TABLE OF
14591      IBY_HOOK_PAYMENTS_T.creation_date%TYPE
14592      INDEX BY BINARY_INTEGER;
14593      TYPE t_last_updated_by IS TABLE OF
14594      IBY_HOOK_PAYMENTS_T.last_updated_by%TYPE
14595      INDEX BY BINARY_INTEGER;
14596      TYPE t_last_update_date IS TABLE OF
14597      IBY_HOOK_PAYMENTS_T.last_update_date%TYPE
14598      INDEX BY BINARY_INTEGER;
14599      TYPE t_last_update_login IS TABLE OF
14600      IBY_HOOK_PAYMENTS_T.last_update_login%TYPE
14601      INDEX BY BINARY_INTEGER;
14602      TYPE t_object_version_number IS TABLE OF
14603      IBY_HOOK_PAYMENTS_T.object_version_number%TYPE
14604      INDEX BY BINARY_INTEGER;
14605 
14606     l_calling_app_id                          t_calling_app_id;
14607     l_call_app_pay_srv_req_code               t_call_app_pay_srv_req_code;
14608     l_payment_service_request_id              t_payment_service_request_id;
14609     l_payment_id                              t_payment_id;
14610     l_payment_amount                          t_payment_amount;
14611     l_payment_currency_code                   t_payment_currency_code;
14612     l_dont_pay_flag                           t_dont_pay_flag;
14613     l_dont_pay_reason_code                    t_dont_pay_reason_code;
14614     l_dont_pay_description                    t_dont_pay_description;
14615     l_internal_bank_account_id                t_internal_bank_account_id;
14616     l_ext_payee_id                            t_ext_payee_id;
14617     l_payee_party_id                          t_payee_party_id;
14618     l_party_site_id                           t_party_site_id;
14619     l_supplier_site_id                        t_supplier_site_id;
14620     l_org_id                                  t_org_id;
14621     l_org_type                                t_org_type;
14622     l_external_bank_account_id                t_external_bank_account_id;
14623     l_discount_amount_taken                   t_discount_amount_taken;
14624     l_payment_date                            t_payment_date;
14625     l_bank_charge_amount                      t_bank_charge_amount;
14626     l_created_by                              t_created_by;
14627     l_creation_date                           t_creation_date;
14628     l_last_updated_by                         t_last_updated_by;
14629     l_last_update_date                        t_last_update_date;
14630     l_last_update_login                       t_last_update_login;
14631     l_object_version_number                   t_object_version_number;
14632 
14633 
14634  /* payments cursor */
14635  CURSOR c_payment_data
14636  IS
14637  SELECT
14638      calling_app_id,
14639      call_app_pay_service_req_code,
14640      payment_service_request_id,
14641      payment_id,
14642      payment_amount,
14643      payment_currency_code,
14644      dont_pay_flag,
14645      dont_pay_reason_code,
14646      dont_pay_description,
14647      internal_bank_account_id,
14648      ext_payee_id,
14649      payee_party_id,
14650      party_site_id,
14651      supplier_site_id,
14652      org_id,
14653      org_type,
14654      external_bank_account_id,
14655      discount_amount_taken,
14656      payment_date,
14657      bank_charge_amount,
14658      created_by,
14659      creation_date,
14660      last_updated_by,
14661      last_update_date,
14662      last_update_login,
14663      object_version_number
14664  FROM IBY_HOOK_PAYMENTS_T;
14665 
14666      TYPE ty_payment_id IS TABLE OF
14667      IBY_HOOK_DOCS_IN_PMT_T.payment_id%TYPE
14668      INDEX BY BINARY_INTEGER;
14669      TYPE ty_document_payable_id IS TABLE OF
14670      IBY_HOOK_DOCS_IN_PMT_T.document_payable_id%TYPE
14671      INDEX BY BINARY_INTEGER;
14672      TYPE ty_calling_app_id IS TABLE OF
14673      IBY_HOOK_DOCS_IN_PMT_T.calling_app_id%TYPE
14674      INDEX BY BINARY_INTEGER;
14675      TYPE ty_calling_app_doc_unique_ref1 IS TABLE OF
14676      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref1%TYPE
14677      INDEX BY BINARY_INTEGER;
14678      TYPE ty_calling_app_doc_unique_ref2 IS TABLE OF
14679      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref2%TYPE
14680      INDEX BY BINARY_INTEGER;
14681      TYPE ty_calling_app_doc_unique_ref3 IS TABLE OF
14682      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref3%TYPE
14683      INDEX BY BINARY_INTEGER;
14684      TYPE ty_calling_app_doc_unique_ref4 IS TABLE OF
14685      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref4%TYPE
14686      INDEX BY BINARY_INTEGER;
14687      TYPE ty_calling_app_doc_unique_ref5 IS TABLE OF
14688      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref5%TYPE
14689      INDEX BY BINARY_INTEGER;
14690      TYPE ty_document_amount IS TABLE OF
14691      IBY_HOOK_DOCS_IN_PMT_T.document_amount%TYPE
14692      INDEX BY BINARY_INTEGER;
14693      TYPE ty_document_currency_code IS TABLE OF
14694      IBY_HOOK_DOCS_IN_PMT_T.document_currency_code%TYPE
14695      INDEX BY BINARY_INTEGER;
14696      TYPE ty_amount_withheld IS TABLE OF
14697      IBY_HOOK_DOCS_IN_PMT_T.amount_withheld%TYPE
14698      INDEX BY BINARY_INTEGER;
14699      TYPE ty_dont_pay_flag IS TABLE OF
14700      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_flag%TYPE
14701      INDEX BY BINARY_INTEGER;
14702      TYPE ty_dont_pay_reason_code IS TABLE OF
14703      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_reason_code%TYPE
14704      INDEX BY BINARY_INTEGER;
14705      TYPE ty_dont_pay_description IS TABLE OF
14706      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_description%TYPE
14707      INDEX BY BINARY_INTEGER;
14708      TYPE ty_pay_proc_trxn_type_code IS TABLE OF
14709      IBY_HOOK_DOCS_IN_PMT_T.pay_proc_trxn_type_code%TYPE
14710      INDEX BY BINARY_INTEGER;
14711      TYPE ty_internal_bank_account_id IS TABLE OF
14712      IBY_HOOK_DOCS_IN_PMT_T.internal_bank_account_id%TYPE
14713      INDEX BY BINARY_INTEGER;
14714      TYPE ty_ext_payee_id IS TABLE OF
14715      IBY_HOOK_DOCS_IN_PMT_T.ext_payee_id%TYPE
14716      INDEX BY BINARY_INTEGER;
14717      TYPE ty_payee_party_id IS TABLE OF
14718      IBY_HOOK_DOCS_IN_PMT_T.payee_party_id%TYPE
14719      INDEX BY BINARY_INTEGER;
14720      TYPE ty_party_site_id IS TABLE OF
14721      IBY_HOOK_DOCS_IN_PMT_T.party_site_id%TYPE
14722      INDEX BY BINARY_INTEGER;
14723      TYPE ty_supplier_site_id IS TABLE OF
14724      IBY_HOOK_DOCS_IN_PMT_T.supplier_site_id%TYPE
14725      INDEX BY BINARY_INTEGER;
14726      TYPE ty_org_id IS TABLE OF
14727      IBY_HOOK_DOCS_IN_PMT_T.org_id%TYPE
14728      INDEX BY BINARY_INTEGER;
14729      TYPE ty_org_type IS TABLE OF
14730      IBY_HOOK_DOCS_IN_PMT_T.org_type%TYPE
14731      INDEX BY BINARY_INTEGER;
14732      TYPE ty_external_bank_account_id IS TABLE OF
14733      IBY_HOOK_DOCS_IN_PMT_T.external_bank_account_id%TYPE
14734      INDEX BY BINARY_INTEGER;
14735      TYPE ty_payment_curr_discount_taken IS TABLE OF
14736      IBY_HOOK_DOCS_IN_PMT_T.payment_curr_discount_taken%TYPE
14737      INDEX BY BINARY_INTEGER;
14738      TYPE ty_created_by IS TABLE OF
14739      IBY_HOOK_DOCS_IN_PMT_T.created_by%TYPE
14740      INDEX BY BINARY_INTEGER;
14741      TYPE ty_creation_date IS TABLE OF
14742      IBY_HOOK_DOCS_IN_PMT_T.creation_date%TYPE
14743      INDEX BY BINARY_INTEGER;
14744      TYPE ty_last_updated_by IS TABLE OF
14745      IBY_HOOK_DOCS_IN_PMT_T.last_updated_by%TYPE
14746      INDEX BY BINARY_INTEGER;
14747      TYPE ty_last_update_date IS TABLE OF
14748      IBY_HOOK_DOCS_IN_PMT_T.last_update_date%TYPE
14749      INDEX BY BINARY_INTEGER;
14750      TYPE ty_last_update_login IS TABLE OF
14751      IBY_HOOK_DOCS_IN_PMT_T.last_update_login%TYPE
14752      INDEX BY BINARY_INTEGER;
14753      TYPE ty_object_version_number IS TABLE OF
14754      IBY_HOOK_DOCS_IN_PMT_T.object_version_number%TYPE
14755      INDEX BY BINARY_INTEGER;
14756 
14757 
14758     ll_payment_id                           ty_payment_id;
14759     ll_document_payable_id                  ty_document_payable_id;
14760     ll_calling_app_id                       ty_calling_app_id;
14761     ll_calling_app_doc_unique_ref1          ty_calling_app_doc_unique_ref1;
14762     ll_calling_app_doc_unique_ref2          ty_calling_app_doc_unique_ref2;
14763     ll_calling_app_doc_unique_ref3          ty_calling_app_doc_unique_ref3;
14764     ll_calling_app_doc_unique_ref4          ty_calling_app_doc_unique_ref4;
14765     ll_calling_app_doc_unique_ref5          ty_calling_app_doc_unique_ref5;
14766     ll_document_amount                      ty_document_amount;
14767     ll_document_currency_code               ty_document_currency_code;
14768     ll_amount_withheld                      ty_amount_withheld;
14769     ll_dont_pay_flag                        ty_dont_pay_flag;
14770     ll_dont_pay_reason_code                 ty_dont_pay_reason_code;
14771     ll_dont_pay_description                 ty_dont_pay_description;
14772     ll_pay_proc_trxn_type_code              ty_pay_proc_trxn_type_code;
14773     ll_internal_bank_account_id             ty_internal_bank_account_id;
14774     ll_ext_payee_id                         ty_ext_payee_id;
14775     ll_payee_party_id                       ty_payee_party_id;
14776     ll_party_site_id                        ty_party_site_id;
14777     ll_supplier_site_id                     ty_supplier_site_id;
14778     ll_org_id                               ty_org_id;
14779     ll_org_type                             ty_org_type;
14780     ll_external_bank_account_id             ty_external_bank_account_id;
14781     ll_payment_curr_discount_taken          ty_payment_curr_discount_taken;
14782     ll_created_by                           ty_created_by;
14783     ll_creation_date                        ty_creation_date;
14784     ll_last_updated_by                      ty_last_updated_by;
14785     ll_last_update_date                     ty_last_update_date;
14786     ll_last_update_login                    ty_last_update_login;
14787     ll_object_version_number                ty_object_version_number;
14788 
14789 
14790  /* documents cursor */
14791  CURSOR c_document_data
14792  IS
14793  SELECT
14794      payment_id,
14795      document_payable_id,
14796      calling_app_id,
14797      calling_app_doc_unique_ref1,
14798      calling_app_doc_unique_ref2,
14799      calling_app_doc_unique_ref3,
14800      calling_app_doc_unique_ref4,
14801      calling_app_doc_unique_ref5,
14802      document_amount,
14803      document_currency_code,
14804      amount_withheld,
14805      dont_pay_flag,
14806      dont_pay_reason_code,
14807      dont_pay_description,
14808      pay_proc_trxn_type_code,
14809      internal_bank_account_id,
14810      ext_payee_id,
14811      payee_party_id,
14812      party_site_id,
14813      supplier_site_id,
14814      org_id,
14815      org_type,
14816      external_bank_account_id,
14817      payment_curr_discount_taken,
14818      created_by,
14819      creation_date,
14820      last_updated_by,
14821      last_update_date,
14822      last_update_login,
14823      object_version_number
14824  FROM IBY_HOOK_DOCS_IN_PMT_T
14825  ORDER BY document_payable_id;
14826 
14827  BEGIN
14828 
14829      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
14830 	 print_debuginfo(l_module_name, 'Fetching data '
14831          || 'from global temp tables');
14832 
14833      END IF;
14834      /*
14835       * Read in the payments and documents from the global
14836       * temp tables and store them into data structures.
14837       */
14838      OPEN  c_payment_data;
14839      FETCH c_payment_data BULK COLLECT INTO
14840          l_calling_app_id,
14841          l_call_app_pay_srv_req_code,
14842          l_payment_service_request_id,
14843          l_payment_id,
14844          l_payment_amount,
14845          l_payment_currency_code,
14846          l_dont_pay_flag,
14847          l_dont_pay_reason_code,
14848          l_dont_pay_description,
14849          l_internal_bank_account_id,
14850          l_ext_payee_id,
14851          l_payee_party_id,
14852          l_party_site_id,
14853          l_supplier_site_id,
14854          l_org_id,
14855          l_org_type,
14856          l_external_bank_account_id,
14857          l_discount_amount_taken,
14858          l_payment_date,
14859          l_bank_charge_amount,
14860          l_created_by,
14861          l_creation_date,
14862          l_last_updated_by,
14863          l_last_update_date,
14864          l_last_update_login,
14865          l_object_version_number
14866          ;
14867      CLOSE c_payment_data;
14868 
14869      IF (l_calling_app_id.COUNT <> 0) THEN
14870          FOR i IN l_calling_app_id.FIRST .. l_calling_app_id.LAST LOOP
14871              x_hookPaymentTab(i).calling_app_id :=
14872                  l_calling_app_id(i);
14873              x_hookPaymentTab(i).call_app_pay_service_req_code :=
14874                  l_call_app_pay_srv_req_code(i);
14875              x_hookPaymentTab(i).payment_service_request_id :=
14876                  l_payment_service_request_id(i);
14877              x_hookPaymentTab(i).payment_id :=
14878                  l_payment_id(i);
14879              x_hookPaymentTab(i).payment_amount :=
14880                  l_payment_amount(i);
14881              x_hookPaymentTab(i).payment_currency_code :=
14882                  l_payment_currency_code(i);
14883              x_hookPaymentTab(i).dont_pay_flag :=
14884                  l_dont_pay_flag(i);
14885              x_hookPaymentTab(i).dont_pay_reason_code :=
14886                  l_dont_pay_reason_code(i);
14887              x_hookPaymentTab(i).dont_pay_description :=
14888                  l_dont_pay_description(i);
14889              x_hookPaymentTab(i).internal_bank_account_id :=
14890                  l_internal_bank_account_id(i);
14891              x_hookPaymentTab(i).ext_payee_id :=
14892                  l_ext_payee_id(i);
14893              x_hookPaymentTab(i).payee_party_id :=
14894                  l_payee_party_id(i);
14895              x_hookPaymentTab(i).party_site_id :=
14896                  l_party_site_id(i);
14897              x_hookPaymentTab(i).supplier_site_id :=
14898                  l_supplier_site_id(i);
14899              x_hookPaymentTab(i).org_id :=
14900                  l_org_id(i);
14901              x_hookPaymentTab(i).org_type :=
14902                  l_org_type(i);
14903              x_hookPaymentTab(i).external_bank_account_id :=
14904                  l_external_bank_account_id(i);
14905              x_hookPaymentTab(i).discount_amount_taken :=
14906                  l_discount_amount_taken(i);
14907              x_hookPaymentTab(i).payment_date :=
14908                  l_payment_date(i);
14909              x_hookPaymentTab(i).bank_charge_amount :=
14910                  l_bank_charge_amount(i);
14911              x_hookPaymentTab(i).created_by :=
14912                  l_created_by(i);
14913              x_hookPaymentTab(i).creation_date :=
14914                  l_creation_date(i);
14915              x_hookPaymentTab(i).last_updated_by :=
14916                  l_last_updated_by(i);
14917              x_hookPaymentTab(i).last_update_date :=
14918                  l_last_update_date(i);
14919              x_hookPaymentTab(i).last_update_login :=
14920                  l_last_update_login(i);
14921              x_hookPaymentTab(i).object_version_number :=
14922                  l_object_version_number(i);
14923          END LOOP;
14924      END IF;
14925 
14926      OPEN  c_document_data;
14927      FETCH c_document_data BULK COLLECT INTO
14928          ll_payment_id,
14929          ll_document_payable_id,
14930          ll_calling_app_id,
14931          ll_calling_app_doc_unique_ref1,
14932          ll_calling_app_doc_unique_ref2,
14933          ll_calling_app_doc_unique_ref3,
14934          ll_calling_app_doc_unique_ref4,
14935          ll_calling_app_doc_unique_ref5,
14936          ll_document_amount,
14937          ll_document_currency_code,
14938          ll_amount_withheld,
14939          ll_dont_pay_flag,
14940          ll_dont_pay_reason_code,
14941          ll_dont_pay_description,
14942          ll_pay_proc_trxn_type_code,
14943          ll_internal_bank_account_id,
14944          ll_ext_payee_id,
14945          ll_payee_party_id,
14946          ll_party_site_id,
14947          ll_supplier_site_id,
14948          ll_org_id,
14949          ll_org_type,
14950          ll_external_bank_account_id,
14951          ll_payment_curr_discount_taken,
14952          ll_created_by,
14953          ll_creation_date,
14954          ll_last_updated_by,
14955          ll_last_update_date,
14956          ll_last_update_login,
14957          ll_object_version_number
14958          ;
14959      CLOSE c_document_data;
14960 
14961      IF (ll_payment_id.COUNT <> 0) THEN
14962          FOR i IN ll_payment_id.FIRST .. ll_payment_id.LAST LOOP
14963          x_hookDocsInPmtTab(i).payment_id :=
14964              ll_payment_id(i);
14965          x_hookDocsInPmtTab(i).document_payable_id :=
14966              ll_document_payable_id(i);
14967          x_hookDocsInPmtTab(i).calling_app_id :=
14968              ll_calling_app_id(i);
14969          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref1 :=
14970              ll_calling_app_doc_unique_ref1(i);
14971          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref2 :=
14972              ll_calling_app_doc_unique_ref2(i);
14973          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref3 :=
14974              ll_calling_app_doc_unique_ref3(i);
14975          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref4 :=
14976              ll_calling_app_doc_unique_ref4(i);
14977          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref5 :=
14978              ll_calling_app_doc_unique_ref5(i);
14979          x_hookDocsInPmtTab(i).document_amount :=
14980              ll_document_amount(i);
14981          x_hookDocsInPmtTab(i).document_currency_code :=
14982              ll_document_currency_code(i);
14983          x_hookDocsInPmtTab(i).amount_withheld :=
14984              ll_amount_withheld(i);
14985          x_hookDocsInPmtTab(i).dont_pay_flag :=
14986              ll_dont_pay_flag(i);
14987          x_hookDocsInPmtTab(i).dont_pay_reason_code :=
14988              ll_dont_pay_reason_code(i);
14989          x_hookDocsInPmtTab(i).dont_pay_description :=
14990              ll_dont_pay_description(i);
14991          x_hookDocsInPmtTab(i).pay_proc_trxn_type_code :=
14992              ll_pay_proc_trxn_type_code(i);
14993          x_hookDocsInPmtTab(i).internal_bank_account_id :=
14994              ll_internal_bank_account_id(i);
14995          x_hookDocsInPmtTab(i).ext_payee_id :=
14996              ll_ext_payee_id(i);
14997          x_hookDocsInPmtTab(i).payee_party_id :=
14998              ll_payee_party_id(i);
14999          x_hookDocsInPmtTab(i).party_site_id :=
15000              ll_party_site_id(i);
15001          x_hookDocsInPmtTab(i).supplier_site_id :=
15002              ll_supplier_site_id(i);
15003          x_hookDocsInPmtTab(i).org_id :=
15004              ll_org_id(i);
15005          x_hookDocsInPmtTab(i).org_type :=
15006              ll_org_type(i);
15007          x_hookDocsInPmtTab(i).external_bank_account_id :=
15008              ll_external_bank_account_id(i);
15009          x_hookDocsInPmtTab(i).payment_curr_discount_taken :=
15010              ll_payment_curr_discount_taken(i);
15011          x_hookDocsInPmtTab(i).created_by :=
15012              ll_created_by(i);
15013          x_hookDocsInPmtTab(i).creation_date :=
15014              ll_creation_date(i);
15015          x_hookDocsInPmtTab(i).last_updated_by :=
15016              ll_last_updated_by(i);
15017          x_hookDocsInPmtTab(i).last_update_date :=
15018              ll_last_update_date(i);
15019          x_hookDocsInPmtTab(i).last_update_login :=
15020              ll_last_update_login(i);
15021          x_hookDocsInPmtTab(i).object_version_number :=
15022              ll_object_version_number(i);
15023          END LOOP;
15024      END IF;
15025 
15026      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15027       print_debuginfo(l_module_name, 'Finished fetching docs and '
15028          || 'payments from global temp tables.');
15029 
15030      END IF;
15031  END getAdjustedPaymentData;
15032 
15033 /*--------------------------------------------------------------------
15034  | NAME:
15035  |     getAdjustedPaymentData
15036  |
15037  | PURPOSE:
15038  |     Reads the data updated in the global temp tables by the calling app.
15039  |     The calling app would have updated the data when the external
15040  |     application hook was called. This method reads in the updated
15041  |     data.
15042  |
15043  | PARAMETERS:
15044  |     IN
15045  |
15046  |     OUT
15047  |
15048  |
15049  | RETURNS:
15050  |
15051  | NOTES:
15052  |
15053  *---------------------------------------------------------------------*/
15054  PROCEDURE getAdjustedPaymentData(
15055      x_hookPaymentTab      IN OUT NOCOPY hookPaymentTabType
15056  --     x_hookDocsInPmtTab    IN OUT NOCOPY hookDocsInPaymentTabType
15057      )
15058  IS
15059 
15060  l_module_name  CONSTANT VARCHAR2(200) := G_PKG_NAME ||
15061                                               '.getAdjustedPaymentData';
15062 
15063      TYPE t_calling_app_id IS TABLE OF
15064      IBY_HOOK_PAYMENTS_T.calling_app_id%TYPE
15065      INDEX BY BINARY_INTEGER;
15066      TYPE t_call_app_pay_srv_req_code IS TABLE OF
15067      IBY_HOOK_PAYMENTS_T.call_app_pay_service_req_code%TYPE
15068      INDEX BY BINARY_INTEGER;
15069      TYPE t_payment_service_request_id IS TABLE OF
15070      IBY_HOOK_PAYMENTS_T.payment_service_request_id%TYPE
15071      INDEX BY BINARY_INTEGER;
15072      TYPE t_payment_id IS TABLE OF
15073      IBY_HOOK_PAYMENTS_T.payment_id%TYPE
15074      INDEX BY BINARY_INTEGER;
15075      TYPE t_payment_amount IS TABLE OF
15076      IBY_HOOK_PAYMENTS_T.payment_amount%TYPE
15077      INDEX BY BINARY_INTEGER;
15078      TYPE t_payment_currency_code IS TABLE OF
15079      IBY_HOOK_PAYMENTS_T.payment_currency_code%TYPE
15080      INDEX BY BINARY_INTEGER;
15081      TYPE t_dont_pay_flag IS TABLE OF
15082      IBY_HOOK_PAYMENTS_T.dont_pay_flag%TYPE
15083      INDEX BY BINARY_INTEGER;
15084      TYPE t_dont_pay_reason_code IS TABLE OF
15085      IBY_HOOK_PAYMENTS_T.dont_pay_reason_code%TYPE
15086      INDEX BY BINARY_INTEGER;
15087      TYPE t_dont_pay_description IS TABLE OF
15088      IBY_HOOK_PAYMENTS_T.dont_pay_description%TYPE
15089      INDEX BY BINARY_INTEGER;
15090      TYPE t_internal_bank_account_id IS TABLE OF
15091      IBY_HOOK_PAYMENTS_T.internal_bank_account_id%TYPE
15092      INDEX BY BINARY_INTEGER;
15093      TYPE t_ext_payee_id IS TABLE OF
15094      IBY_HOOK_PAYMENTS_T.ext_payee_id%TYPE
15095      INDEX BY BINARY_INTEGER;
15096      TYPE t_payee_party_id IS TABLE OF
15097      IBY_HOOK_PAYMENTS_T.payee_party_id%TYPE
15098      INDEX BY BINARY_INTEGER;
15099      TYPE t_party_site_id IS TABLE OF
15100      IBY_HOOK_PAYMENTS_T.party_site_id%TYPE
15101      INDEX BY BINARY_INTEGER;
15102      TYPE t_supplier_site_id IS TABLE OF
15103      IBY_HOOK_PAYMENTS_T.supplier_site_id%TYPE
15104      INDEX BY BINARY_INTEGER;
15105      TYPE t_org_id IS TABLE OF
15106      IBY_HOOK_PAYMENTS_T.org_id%TYPE
15107      INDEX BY BINARY_INTEGER;
15108      TYPE t_org_type IS TABLE OF
15109      IBY_HOOK_PAYMENTS_T.org_type%TYPE
15110      INDEX BY BINARY_INTEGER;
15111      TYPE t_external_bank_account_id IS TABLE OF
15112      IBY_HOOK_PAYMENTS_T.external_bank_account_id%TYPE
15113      INDEX BY BINARY_INTEGER;
15114      TYPE t_discount_amount_taken IS TABLE OF
15115      IBY_HOOK_PAYMENTS_T.discount_amount_taken%TYPE
15116      INDEX BY BINARY_INTEGER;
15117      TYPE t_payment_date IS TABLE OF
15118      IBY_HOOK_PAYMENTS_T.payment_date%TYPE
15119      INDEX BY BINARY_INTEGER;
15120      TYPE t_bank_charge_amount IS TABLE OF
15121      IBY_HOOK_PAYMENTS_T.bank_charge_amount%TYPE
15122      INDEX BY BINARY_INTEGER;
15123      TYPE t_created_by IS TABLE OF
15124      IBY_HOOK_PAYMENTS_T.created_by%TYPE
15125      INDEX BY BINARY_INTEGER;
15126      TYPE t_creation_date IS TABLE OF
15127      IBY_HOOK_PAYMENTS_T.creation_date%TYPE
15128      INDEX BY BINARY_INTEGER;
15129      TYPE t_last_updated_by IS TABLE OF
15130      IBY_HOOK_PAYMENTS_T.last_updated_by%TYPE
15131      INDEX BY BINARY_INTEGER;
15132      TYPE t_last_update_date IS TABLE OF
15133      IBY_HOOK_PAYMENTS_T.last_update_date%TYPE
15134      INDEX BY BINARY_INTEGER;
15135      TYPE t_last_update_login IS TABLE OF
15136      IBY_HOOK_PAYMENTS_T.last_update_login%TYPE
15137      INDEX BY BINARY_INTEGER;
15138      TYPE t_object_version_number IS TABLE OF
15139      IBY_HOOK_PAYMENTS_T.object_version_number%TYPE
15140      INDEX BY BINARY_INTEGER;
15141 
15142     l_calling_app_id                          t_calling_app_id;
15143     l_call_app_pay_srv_req_code               t_call_app_pay_srv_req_code;
15144     l_payment_service_request_id              t_payment_service_request_id;
15145     l_payment_id                              t_payment_id;
15146     l_payment_amount                          t_payment_amount;
15147     l_payment_currency_code                   t_payment_currency_code;
15148     l_dont_pay_flag                           t_dont_pay_flag;
15149     l_dont_pay_reason_code                    t_dont_pay_reason_code;
15150     l_dont_pay_description                    t_dont_pay_description;
15151     l_internal_bank_account_id                t_internal_bank_account_id;
15152     l_ext_payee_id                            t_ext_payee_id;
15153     l_payee_party_id                          t_payee_party_id;
15154     l_party_site_id                           t_party_site_id;
15155     l_supplier_site_id                        t_supplier_site_id;
15156     l_org_id                                  t_org_id;
15157     l_org_type                                t_org_type;
15158     l_external_bank_account_id                t_external_bank_account_id;
15159     l_discount_amount_taken                   t_discount_amount_taken;
15160     l_payment_date                            t_payment_date;
15161     l_bank_charge_amount                      t_bank_charge_amount;
15162     l_created_by                              t_created_by;
15163     l_creation_date                           t_creation_date;
15164     l_last_updated_by                         t_last_updated_by;
15165     l_last_update_date                        t_last_update_date;
15166     l_last_update_login                       t_last_update_login;
15167     l_object_version_number                   t_object_version_number;
15168 
15169 
15170  /* payments cursor */
15171  CURSOR c_payment_data
15172  IS
15173  SELECT
15174      calling_app_id,
15175      call_app_pay_service_req_code,
15176      payment_service_request_id,
15177      payment_id,
15178      payment_amount,
15179      payment_currency_code,
15180      dont_pay_flag,
15181      dont_pay_reason_code,
15182      dont_pay_description,
15183      internal_bank_account_id,
15184      ext_payee_id,
15185      payee_party_id,
15186      party_site_id,
15187      supplier_site_id,
15188      org_id,
15189      org_type,
15190      external_bank_account_id,
15191      discount_amount_taken,
15192      payment_date,
15193      bank_charge_amount,
15194      created_by,
15195      creation_date,
15196      last_updated_by,
15197      last_update_date,
15198      last_update_login,
15199      object_version_number
15200  FROM IBY_HOOK_PAYMENTS_T;
15201 
15202      TYPE ty_payment_id IS TABLE OF
15203      IBY_HOOK_DOCS_IN_PMT_T.payment_id%TYPE
15204      INDEX BY BINARY_INTEGER;
15205      TYPE ty_document_payable_id IS TABLE OF
15206      IBY_HOOK_DOCS_IN_PMT_T.document_payable_id%TYPE
15207      INDEX BY BINARY_INTEGER;
15208      TYPE ty_calling_app_id IS TABLE OF
15209      IBY_HOOK_DOCS_IN_PMT_T.calling_app_id%TYPE
15210      INDEX BY BINARY_INTEGER;
15211      TYPE ty_calling_app_doc_unique_ref1 IS TABLE OF
15212      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref1%TYPE
15213      INDEX BY BINARY_INTEGER;
15214      TYPE ty_calling_app_doc_unique_ref2 IS TABLE OF
15215      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref2%TYPE
15216      INDEX BY BINARY_INTEGER;
15217      TYPE ty_calling_app_doc_unique_ref3 IS TABLE OF
15218      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref3%TYPE
15219      INDEX BY BINARY_INTEGER;
15220      TYPE ty_calling_app_doc_unique_ref4 IS TABLE OF
15221      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref4%TYPE
15222      INDEX BY BINARY_INTEGER;
15223      TYPE ty_calling_app_doc_unique_ref5 IS TABLE OF
15224      IBY_HOOK_DOCS_IN_PMT_T.calling_app_doc_unique_ref5%TYPE
15225      INDEX BY BINARY_INTEGER;
15226      TYPE ty_document_amount IS TABLE OF
15227      IBY_HOOK_DOCS_IN_PMT_T.document_amount%TYPE
15228      INDEX BY BINARY_INTEGER;
15229      TYPE ty_document_currency_code IS TABLE OF
15230      IBY_HOOK_DOCS_IN_PMT_T.document_currency_code%TYPE
15231      INDEX BY BINARY_INTEGER;
15232      TYPE ty_amount_withheld IS TABLE OF
15233      IBY_HOOK_DOCS_IN_PMT_T.amount_withheld%TYPE
15234      INDEX BY BINARY_INTEGER;
15235      TYPE ty_dont_pay_flag IS TABLE OF
15236      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_flag%TYPE
15237      INDEX BY BINARY_INTEGER;
15238      TYPE ty_dont_pay_reason_code IS TABLE OF
15239      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_reason_code%TYPE
15240      INDEX BY BINARY_INTEGER;
15241      TYPE ty_dont_pay_description IS TABLE OF
15242      IBY_HOOK_DOCS_IN_PMT_T.dont_pay_description%TYPE
15243      INDEX BY BINARY_INTEGER;
15244      TYPE ty_pay_proc_trxn_type_code IS TABLE OF
15245      IBY_HOOK_DOCS_IN_PMT_T.pay_proc_trxn_type_code%TYPE
15246      INDEX BY BINARY_INTEGER;
15247      TYPE ty_internal_bank_account_id IS TABLE OF
15248      IBY_HOOK_DOCS_IN_PMT_T.internal_bank_account_id%TYPE
15249      INDEX BY BINARY_INTEGER;
15250      TYPE ty_ext_payee_id IS TABLE OF
15251      IBY_HOOK_DOCS_IN_PMT_T.ext_payee_id%TYPE
15252      INDEX BY BINARY_INTEGER;
15253      TYPE ty_payee_party_id IS TABLE OF
15254      IBY_HOOK_DOCS_IN_PMT_T.payee_party_id%TYPE
15255      INDEX BY BINARY_INTEGER;
15256      TYPE ty_party_site_id IS TABLE OF
15257      IBY_HOOK_DOCS_IN_PMT_T.party_site_id%TYPE
15258      INDEX BY BINARY_INTEGER;
15259      TYPE ty_supplier_site_id IS TABLE OF
15260      IBY_HOOK_DOCS_IN_PMT_T.supplier_site_id%TYPE
15261      INDEX BY BINARY_INTEGER;
15262      TYPE ty_org_id IS TABLE OF
15263      IBY_HOOK_DOCS_IN_PMT_T.org_id%TYPE
15264      INDEX BY BINARY_INTEGER;
15265      TYPE ty_org_type IS TABLE OF
15266      IBY_HOOK_DOCS_IN_PMT_T.org_type%TYPE
15267      INDEX BY BINARY_INTEGER;
15268      TYPE ty_external_bank_account_id IS TABLE OF
15269      IBY_HOOK_DOCS_IN_PMT_T.external_bank_account_id%TYPE
15270      INDEX BY BINARY_INTEGER;
15271      TYPE ty_payment_curr_discount_taken IS TABLE OF
15272      IBY_HOOK_DOCS_IN_PMT_T.payment_curr_discount_taken%TYPE
15273      INDEX BY BINARY_INTEGER;
15274      TYPE ty_created_by IS TABLE OF
15275      IBY_HOOK_DOCS_IN_PMT_T.created_by%TYPE
15276      INDEX BY BINARY_INTEGER;
15277      TYPE ty_creation_date IS TABLE OF
15278      IBY_HOOK_DOCS_IN_PMT_T.creation_date%TYPE
15279      INDEX BY BINARY_INTEGER;
15280      TYPE ty_last_updated_by IS TABLE OF
15281      IBY_HOOK_DOCS_IN_PMT_T.last_updated_by%TYPE
15282      INDEX BY BINARY_INTEGER;
15283      TYPE ty_last_update_date IS TABLE OF
15284      IBY_HOOK_DOCS_IN_PMT_T.last_update_date%TYPE
15285      INDEX BY BINARY_INTEGER;
15286      TYPE ty_last_update_login IS TABLE OF
15287      IBY_HOOK_DOCS_IN_PMT_T.last_update_login%TYPE
15288      INDEX BY BINARY_INTEGER;
15289      TYPE ty_object_version_number IS TABLE OF
15290      IBY_HOOK_DOCS_IN_PMT_T.object_version_number%TYPE
15291      INDEX BY BINARY_INTEGER;
15292 
15293 
15294     ll_payment_id                           ty_payment_id;
15295     ll_document_payable_id                  ty_document_payable_id;
15296     ll_calling_app_id                       ty_calling_app_id;
15297     ll_calling_app_doc_unique_ref1          ty_calling_app_doc_unique_ref1;
15298     ll_calling_app_doc_unique_ref2          ty_calling_app_doc_unique_ref2;
15299     ll_calling_app_doc_unique_ref3          ty_calling_app_doc_unique_ref3;
15300     ll_calling_app_doc_unique_ref4          ty_calling_app_doc_unique_ref4;
15301     ll_calling_app_doc_unique_ref5          ty_calling_app_doc_unique_ref5;
15302     ll_document_amount                      ty_document_amount;
15303     ll_document_currency_code               ty_document_currency_code;
15304     ll_amount_withheld                      ty_amount_withheld;
15305     ll_dont_pay_flag                        ty_dont_pay_flag;
15306     ll_dont_pay_reason_code                 ty_dont_pay_reason_code;
15307     ll_dont_pay_description                 ty_dont_pay_description;
15308     ll_pay_proc_trxn_type_code              ty_pay_proc_trxn_type_code;
15309     ll_internal_bank_account_id             ty_internal_bank_account_id;
15310     ll_ext_payee_id                         ty_ext_payee_id;
15311     ll_payee_party_id                       ty_payee_party_id;
15312     ll_party_site_id                        ty_party_site_id;
15313     ll_supplier_site_id                     ty_supplier_site_id;
15314     ll_org_id                               ty_org_id;
15315     ll_org_type                             ty_org_type;
15316     ll_external_bank_account_id             ty_external_bank_account_id;
15317     ll_payment_curr_discount_taken          ty_payment_curr_discount_taken;
15318     ll_created_by                           ty_created_by;
15319     ll_creation_date                        ty_creation_date;
15320     ll_last_updated_by                      ty_last_updated_by;
15321     ll_last_update_date                     ty_last_update_date;
15322     ll_last_update_login                    ty_last_update_login;
15323     ll_object_version_number                ty_object_version_number;
15324 
15325 
15326  /* documents cursor */
15327  /*CURSOR c_document_data
15328  IS
15329  SELECT
15330      payment_id,
15331      document_payable_id,
15332      calling_app_id,
15333      calling_app_doc_unique_ref1,
15334      calling_app_doc_unique_ref2,
15335      calling_app_doc_unique_ref3,
15336      calling_app_doc_unique_ref4,
15337      calling_app_doc_unique_ref5,
15338      document_amount,
15339      document_currency_code,
15340      amount_withheld,
15341      dont_pay_flag,
15342      dont_pay_reason_code,
15343      dont_pay_description,
15344      pay_proc_trxn_type_code,
15345      internal_bank_account_id,
15346      ext_payee_id,
15347      payee_party_id,
15348      party_site_id,
15349      supplier_site_id,
15350      org_id,
15351      org_type,
15352      external_bank_account_id,
15353      payment_curr_discount_taken,
15354      created_by,
15355      creation_date,
15356      last_updated_by,
15357      last_update_date,
15358      last_update_login,
15359      object_version_number
15360  FROM IBY_HOOK_DOCS_IN_PMT_T
15361  ORDER BY document_payable_id;*/
15362 
15363  BEGIN
15364 
15365      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15366 	 print_debuginfo(l_module_name, 'Fetching data '
15367          || 'from global temp tables');
15368 
15369      END IF;
15370      /*
15371       * Read in the payments and documents from the global
15372       * temp tables and store them into data structures.
15373       */
15374      OPEN  c_payment_data;
15375      FETCH c_payment_data BULK COLLECT INTO
15376          l_calling_app_id,
15377          l_call_app_pay_srv_req_code,
15378          l_payment_service_request_id,
15379          l_payment_id,
15380          l_payment_amount,
15381          l_payment_currency_code,
15382          l_dont_pay_flag,
15383          l_dont_pay_reason_code,
15384          l_dont_pay_description,
15385          l_internal_bank_account_id,
15386          l_ext_payee_id,
15387          l_payee_party_id,
15388          l_party_site_id,
15389          l_supplier_site_id,
15390          l_org_id,
15391          l_org_type,
15392          l_external_bank_account_id,
15393          l_discount_amount_taken,
15394          l_payment_date,
15395          l_bank_charge_amount,
15396          l_created_by,
15397          l_creation_date,
15398          l_last_updated_by,
15399          l_last_update_date,
15400          l_last_update_login,
15401          l_object_version_number
15402          ;
15403      CLOSE c_payment_data;
15404 
15405      IF (l_calling_app_id.COUNT <> 0) THEN
15406          FOR i IN l_calling_app_id.FIRST .. l_calling_app_id.LAST LOOP
15407              x_hookPaymentTab(i).calling_app_id :=
15408                  l_calling_app_id(i);
15409              x_hookPaymentTab(i).call_app_pay_service_req_code :=
15410                  l_call_app_pay_srv_req_code(i);
15411              x_hookPaymentTab(i).payment_service_request_id :=
15412                  l_payment_service_request_id(i);
15413              x_hookPaymentTab(i).payment_id :=
15414                  l_payment_id(i);
15415              x_hookPaymentTab(i).payment_amount :=
15416                  l_payment_amount(i);
15417              x_hookPaymentTab(i).payment_currency_code :=
15418                  l_payment_currency_code(i);
15419              x_hookPaymentTab(i).dont_pay_flag :=
15420                  l_dont_pay_flag(i);
15421              x_hookPaymentTab(i).dont_pay_reason_code :=
15422                  l_dont_pay_reason_code(i);
15423              x_hookPaymentTab(i).dont_pay_description :=
15424                  l_dont_pay_description(i);
15425              x_hookPaymentTab(i).internal_bank_account_id :=
15426                  l_internal_bank_account_id(i);
15427              x_hookPaymentTab(i).ext_payee_id :=
15428                  l_ext_payee_id(i);
15429              x_hookPaymentTab(i).payee_party_id :=
15430                  l_payee_party_id(i);
15431              x_hookPaymentTab(i).party_site_id :=
15432                  l_party_site_id(i);
15433              x_hookPaymentTab(i).supplier_site_id :=
15434                  l_supplier_site_id(i);
15435              x_hookPaymentTab(i).org_id :=
15436                  l_org_id(i);
15437              x_hookPaymentTab(i).org_type :=
15438                  l_org_type(i);
15439              x_hookPaymentTab(i).external_bank_account_id :=
15440                  l_external_bank_account_id(i);
15441              x_hookPaymentTab(i).discount_amount_taken :=
15442                  l_discount_amount_taken(i);
15443              x_hookPaymentTab(i).payment_date :=
15444                  l_payment_date(i);
15445              x_hookPaymentTab(i).bank_charge_amount :=
15446                  l_bank_charge_amount(i);
15447              x_hookPaymentTab(i).created_by :=
15448                  l_created_by(i);
15449              x_hookPaymentTab(i).creation_date :=
15450                  l_creation_date(i);
15451              x_hookPaymentTab(i).last_updated_by :=
15452                  l_last_updated_by(i);
15453              x_hookPaymentTab(i).last_update_date :=
15454                  l_last_update_date(i);
15455              x_hookPaymentTab(i).last_update_login :=
15456                  l_last_update_login(i);
15457              x_hookPaymentTab(i).object_version_number :=
15458                  l_object_version_number(i);
15459          END LOOP;
15460      END IF;
15461 
15462      /*OPEN  c_document_data;
15463      FETCH c_document_data BULK COLLECT INTO
15464          ll_payment_id,
15465          ll_document_payable_id,
15466          ll_calling_app_id,
15467          ll_calling_app_doc_unique_ref1,
15468          ll_calling_app_doc_unique_ref2,
15469          ll_calling_app_doc_unique_ref3,
15470          ll_calling_app_doc_unique_ref4,
15471          ll_calling_app_doc_unique_ref5,
15472          ll_document_amount,
15473          ll_document_currency_code,
15474          ll_amount_withheld,
15475          ll_dont_pay_flag,
15476          ll_dont_pay_reason_code,
15477          ll_dont_pay_description,
15478          ll_pay_proc_trxn_type_code,
15479          ll_internal_bank_account_id,
15480          ll_ext_payee_id,
15481          ll_payee_party_id,
15482          ll_party_site_id,
15483          ll_supplier_site_id,
15484          ll_org_id,
15485          ll_org_type,
15486          ll_external_bank_account_id,
15487          ll_payment_curr_discount_taken,
15488          ll_created_by,
15489          ll_creation_date,
15490          ll_last_updated_by,
15491          ll_last_update_date,
15492          ll_last_update_login,
15493          ll_object_version_number
15494          ;
15495      CLOSE c_document_data;*/
15496 
15497      /*IF (ll_payment_id.COUNT <> 0) THEN
15498          FOR i IN ll_payment_id.FIRST .. ll_payment_id.LAST LOOP
15499          x_hookDocsInPmtTab(i).payment_id :=
15500              ll_payment_id(i);
15501          x_hookDocsInPmtTab(i).document_payable_id :=
15502              ll_document_payable_id(i);
15503          x_hookDocsInPmtTab(i).calling_app_id :=
15504              ll_calling_app_id(i);
15505          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref1 :=
15506              ll_calling_app_doc_unique_ref1(i);
15507          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref2 :=
15508              ll_calling_app_doc_unique_ref2(i);
15509          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref3 :=
15510              ll_calling_app_doc_unique_ref3(i);
15511          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref4 :=
15512              ll_calling_app_doc_unique_ref4(i);
15513          x_hookDocsInPmtTab(i).calling_app_doc_unique_ref5 :=
15514              ll_calling_app_doc_unique_ref5(i);
15515          x_hookDocsInPmtTab(i).document_amount :=
15516              ll_document_amount(i);
15517          x_hookDocsInPmtTab(i).document_currency_code :=
15518              ll_document_currency_code(i);
15519          x_hookDocsInPmtTab(i).amount_withheld :=
15520              ll_amount_withheld(i);
15521          x_hookDocsInPmtTab(i).dont_pay_flag :=
15522              ll_dont_pay_flag(i);
15523          x_hookDocsInPmtTab(i).dont_pay_reason_code :=
15524              ll_dont_pay_reason_code(i);
15525          x_hookDocsInPmtTab(i).dont_pay_description :=
15526              ll_dont_pay_description(i);
15527          x_hookDocsInPmtTab(i).pay_proc_trxn_type_code :=
15528              ll_pay_proc_trxn_type_code(i);
15529          x_hookDocsInPmtTab(i).internal_bank_account_id :=
15530              ll_internal_bank_account_id(i);
15531          x_hookDocsInPmtTab(i).ext_payee_id :=
15532              ll_ext_payee_id(i);
15533          x_hookDocsInPmtTab(i).payee_party_id :=
15534              ll_payee_party_id(i);
15535          x_hookDocsInPmtTab(i).party_site_id :=
15536              ll_party_site_id(i);
15537          x_hookDocsInPmtTab(i).supplier_site_id :=
15538              ll_supplier_site_id(i);
15539          x_hookDocsInPmtTab(i).org_id :=
15540              ll_org_id(i);
15541          x_hookDocsInPmtTab(i).org_type :=
15542              ll_org_type(i);
15543          x_hookDocsInPmtTab(i).external_bank_account_id :=
15544              ll_external_bank_account_id(i);
15545          x_hookDocsInPmtTab(i).payment_curr_discount_taken :=
15546              ll_payment_curr_discount_taken(i);
15547          x_hookDocsInPmtTab(i).created_by :=
15548              ll_created_by(i);
15549          x_hookDocsInPmtTab(i).creation_date :=
15550              ll_creation_date(i);
15551          x_hookDocsInPmtTab(i).last_updated_by :=
15552              ll_last_updated_by(i);
15553          x_hookDocsInPmtTab(i).last_update_date :=
15554              ll_last_update_date(i);
15555          x_hookDocsInPmtTab(i).last_update_login :=
15556              ll_last_update_login(i);
15557          x_hookDocsInPmtTab(i).object_version_number :=
15558              ll_object_version_number(i);
15559          END LOOP;
15560      END IF;*/
15561 
15562      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15563  print_debuginfo(l_module_name, 'Finished fetching'
15564          || 'payments from global temp table.');
15565 
15566      END IF;
15567  END getAdjustedPaymentData;
15568 
15569 
15570 /*--------------------------------------------------------------------
15571  | NAME:
15572  |     failDocsOfPayment
15573  |
15574  | PURPOSE:
15575  |     For a given payment id, this method sets all the documents of
15576  |     that payment to 'failed' status in the PLSQL table of documents.
15577  |     The actual failure status to set for the document is passed
15578  |     in as an input parameter.
15579  |
15580  | PARAMETERS:
15581  |     IN
15582  |
15583  |     OUT
15584  |
15585  |
15586  | RETURNS:
15587  |
15588  | NOTES:
15589  |
15590  *---------------------------------------------------------------------*/
15591  PROCEDURE failDocsOfPayment(
15592      p_paymentId      IN            IBY_PAYMENTS_ALL.payment_id%TYPE,
15593      p_docStatus      IN            IBY_DOCS_PAYABLE_ALL.
15594                                           document_status%TYPE,
15595      x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
15596      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
15597      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
15598      )
15599  IS
15600  l_module_name      CONSTANT VARCHAR2(200)  := G_PKG_NAME ||
15601                                                    '.failDocsOfPayment';
15602  l_calc_doc_details VARCHAR2(2000) := '';
15603  l_sql_string       VARCHAR2(4000) := '';
15604 
15605  l_doc_err_rec      IBY_TRANSACTION_ERRORS%ROWTYPE;
15606 
15607  BEGIN
15608 
15609      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15610 	print_debuginfo(l_module_name, 'ENTER');
15611 
15612      END IF;
15613      /*
15614       * Loop through docs, failing the ones that have the
15615       * have given payment id.
15616       */
15617      FOR j in  x_docsInPmtTab.FIRST ..  x_docsInPmtTab.LAST LOOP
15618 
15619          IF (x_docsInPmtTab(j).payment_id =
15620              p_paymentId) THEN
15621 
15622              x_docsInPmtTab(j).document_status
15623                  := p_docStatus;
15624 
15625              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15626 		print_debuginfo(l_module_name, 'Failed document '
15627                  || x_docsInPmtTab(j).document_id
15628                  || ' because payment '
15629                  || p_paymentId
15630                  || ' has failed.');
15631 
15632 	     END IF;
15633              /*
15634               * Once we fail a doc, we must add a corresponding
15635               * error message to the error table.
15636               */
15637              IBY_BUILD_UTILS_PKG.createErrorRecord(
15638                  TRXN_TYPE_DOC,
15639                  x_docsInPmtTab(j).document_id,
15640                  p_docStatus,
15641                  x_docsInPmtTab(j).calling_app_id,
15642                  x_docsInPmtTab(j).calling_app_doc_id1,
15643                  x_docsInPmtTab(j).calling_app_doc_id2,
15644                  x_docsInPmtTab(j).calling_app_doc_id3,
15645                  x_docsInPmtTab(j).calling_app_doc_id4,
15646                  x_docsInPmtTab(j).calling_app_doc_id5,
15647                  x_docsInPmtTab(j).pay_proc_ttype_cd,
15648                  l_doc_err_rec,
15649                  x_errTokenTab
15650                  );
15651 
15652              /*
15653               * Add error record to errors table.
15654               */
15655              IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
15656                  l_doc_err_rec, x_docErrorTab, x_errTokenTab);
15657 
15658          END IF;
15659 
15660      END LOOP;
15661 
15662      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15663 	print_debuginfo(l_module_name, 'EXIT');
15664 
15665      END IF;
15666  END failDocsOfPayment;
15667 
15668 /*--------------------------------------------------------------------
15669  | NAME:
15670  |     failDocsOfPayment
15671  |
15672  | PURPOSE:
15673  |     For a given payment id, this method sets all the documents of
15674  |     that payment to 'failed' status in the PLSQL table of documents.
15675  |     The actual failure status to set for the document is passed
15676  |     in as an input parameter.
15677  |
15678  | PARAMETERS:
15679  |     IN
15680  |
15681  |     OUT
15682  |
15683  |
15684  | RETURNS:
15685  |
15686  | NOTES:
15687  |
15688  *---------------------------------------------------------------------*/
15689  PROCEDURE failDocsOfPayment(
15690      p_paymentId      IN            IBY_PAYMENTS_ALL.payment_id%TYPE,
15691      p_docStatus      IN            IBY_DOCS_PAYABLE_ALL.
15692                                           document_status%TYPE,
15693      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
15694      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
15695      )
15696  IS
15697  l_module_name      CONSTANT VARCHAR2(200)  := G_PKG_NAME ||
15698                                                    '.failDocsOfPayment';
15699  l_calc_doc_details VARCHAR2(2000) := '';
15700  l_sql_string       VARCHAR2(4000) := '';
15701 
15702  l_doc_err_rec      IBY_TRANSACTION_ERRORS%ROWTYPE;
15703 
15704  CURSOR c_fail_docs_of_payment(p_paymentId IBY_PAYMENTS_ALL.payment_id%TYPE)
15705  IS
15706  SELECT idpt.payment_id,
15707    idpt.document_payable_id,
15708    idpt.document_status,
15709    idpt.calling_app_id,
15710    idpt.calling_app_doc_unique_ref1,
15711    idpt.calling_app_doc_unique_ref2,
15712    idpt.calling_app_doc_unique_ref3,
15713    idpt.calling_app_doc_unique_ref4,
15714    idpt.calling_app_doc_unique_ref5,
15715    idpt.pay_proc_trxn_type_code,
15716    idpt.document_amount,
15717    idpt.payment_grouping_number
15718  FROM iby_docs_in_pmt_gt idpt
15719  WHERE idpt.payment_id = p_paymentId;
15720 
15721  BEGIN
15722 
15723      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15724 	print_debuginfo(l_module_name, 'ENTER');
15725 
15726      END IF;
15727      OPEN c_fail_docs_of_payment(p_paymentId);
15728      FETCH c_fail_docs_of_payment BULK COLLECT INTO l_fail_dop_tbl;
15729      CLOSE c_fail_docs_of_payment;
15730 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15731      print_debuginfo(l_module_name, 'After cursor fetch');
15732 	 END IF;
15733      /*
15734       * Loop through docs, failing the ones that have the
15735       * have given payment id.
15736       */
15737 
15738      IF (l_fail_dop_tbl.COUNT >0) THEN
15739 
15740      FOR j in  l_fail_dop_tbl.FIRST ..  l_fail_dop_tbl.LAST LOOP
15741 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15742      print_debuginfo(l_module_name, 'Inside the for loop');
15743 	 END IF;
15744 
15745 	 IF (l_fail_dop_tbl(j).payment_id = p_paymentId) THEN
15746 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15747 	     print_debuginfo(l_module_name, 'Condition satisfied');
15748 		 END IF;
15749 
15750              UPDATE iby_docs_in_pmt_gt
15751              SET document_status = p_docStatus
15752              WHERE document_payable_id  = l_fail_dop_tbl(j).document_payable_id;
15753 
15754              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15755 		 print_debuginfo(l_module_name, 'Failed document '
15756                  || l_fail_dop_tbl(j).document_payable_id
15757                  || ' because payment '
15758                  || p_paymentId
15759                  || ' has failed.');
15760 	     END IF;
15761              /*
15762               * Once we fail a doc, we must add a corresponding
15763               * error message to the error table.
15764               */
15765              IBY_BUILD_UTILS_PKG.createErrorRecord(
15766                  TRXN_TYPE_DOC,
15767                  l_fail_dop_tbl(j).document_payable_id,
15768                  p_docStatus,
15769                  l_fail_dop_tbl(j).calling_app_id,
15770                  l_fail_dop_tbl(j).calling_app_doc_unique_ref1,
15771                  l_fail_dop_tbl(j).calling_app_doc_unique_ref2,
15772                  l_fail_dop_tbl(j).calling_app_doc_unique_ref3,
15773                  l_fail_dop_tbl(j).calling_app_doc_unique_ref4,
15774                  l_fail_dop_tbl(j).calling_app_doc_unique_ref5,
15775                  l_fail_dop_tbl(j).pay_proc_trxn_type_code,
15776                  l_doc_err_rec,
15777                  x_errTokenTab
15778                  );
15779 
15780              /*
15781               * Add error record to errors table.
15782               */
15783              IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
15784                  l_doc_err_rec, x_docErrorTab, x_errTokenTab);
15785 
15786          END IF;
15787 
15788      END LOOP;
15789 
15790      ELSE
15791 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15792 	print_debuginfo(l_module_name, 'No documents found for this payment');
15793 	END IF;
15794      END IF;
15795      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15796 	print_debuginfo(l_module_name, 'EXIT');
15797 
15798      END IF;
15799  EXCEPTION
15800    WHEN OTHERS THEN
15801    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
15802                  FND_LOG.LEVEL_UNEXPECTED);
15803              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
15804                  FND_LOG.LEVEL_UNEXPECTED);
15805    print_debuginfo(l_module_name, l_module_name||':Exception while performing failDocsOfPayment');
15806    RAISE;
15807 END failDocsOfPayment;
15808 
15809 /*--------------------------------------------------------------------
15810  | NAME:
15811  |     flagSeparateRemitAdvicePmts
15812  |
15813  | PURPOSE:
15814  |     Determines whether a separate remittance advice is required
15815  |     for a payment. If so, this method will set the 'separate remit
15816  |     advice flag' on the payment.
15817  |
15818  | PARAMETERS:
15819  |     IN
15820  |
15821  |
15822  |     OUT
15823  |
15824  |
15825  | RETURNS:
15826  |
15827  | NOTES:
15828  |
15829  *---------------------------------------------------------------------*/
15830  PROCEDURE flagSeparateRemitAdvicePmts(
15831      x_paymentTab    IN OUT NOCOPY paymentTabType,
15832      p_docsInPmtTab  IN            docsInPaymentTabType
15833      )
15834  IS
15835  l_module_name VARCHAR2(200) := G_PKG_NAME || '.flagSeparateRemitAdvicePmts';
15836 
15837  l_doc_count_limit          NUMBER(15);
15838  l_pmt_details_length_limit NUMBER(15);
15839  l_remitAdvicesSetupTab     remitAdviceRecTab;
15840  l_successDocCountTab       successDocsCountPerPmtTab;
15841 
15842  /* maps profile ids to system profile codes */
15843  l_profile_map        IBY_BUILD_UTILS_PKG.profileIdToCodeMapTabType;
15844  l_profile_code       IBY_PAYMENT_PROFILES.system_profile_code%TYPE;
15845 
15846  /*
15847   * Remittance advices cursor --  Only pick those
15848   * records that have the format attched... there
15849   * will be records in this table even if no format
15850   * is attached from the UI (the defaults are just accepted)
15851   */
15852  CURSOR c_remit_advices
15853  IS
15854  SELECT
15855      advice.system_profile_code,
15856      DECODE(advice.document_count_limit, NULL, -1,
15857          advice.document_count_limit),
15858      DECODE(advice.payment_details_length_limit, NULL, -1,
15859          advice.payment_details_length_limit)
15860  FROM
15861      IBY_REMIT_ADVICE_SETUP advice
15862  WHERE
15863      remittance_advice_format_code IS NOT NULL;
15864 
15865  BEGIN
15866 
15867      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15868 	 print_debuginfo(l_module_name, 'ENTER');
15869 
15870      END IF;
15871      /*
15872       * Read in the payments and documents from the global
15873       * temp tables and store them into data structures.
15874       */
15875     -- OPEN  c_remit_advices;
15876     -- FETCH c_remit_advices BULK COLLECT INTO l_remitAdvicesSetupTab;
15877     -- CLOSE c_remit_advices;
15878 
15879      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15880 	print_debuginfo(l_module_name, 'Fetched '
15881          || l_remitAdvicesSetupTab.COUNT
15882          || ' records from the remittance advice setup table.');
15883 
15884      END IF;
15885      IF (l_remitAdvicesSetupTab.COUNT = 0) THEN
15886          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15887 	 print_debuginfo(l_module_name, 'No remittance advice information '
15888              || 'has been setup. Separate remittance advice will '
15889              || 'not be generated for any payment in this request. '
15890              || 'Exiting ..'
15891              );
15892          print_debuginfo(l_module_name, 'EXIT');
15893 
15894 	 END IF;
15895 
15896          RETURN;
15897      END IF;
15898 
15899      /*
15900       * For each payment, get the count of successful documents.
15901       * This is required to determine whether a separate remittance
15902       * needs to be flagged for that payment.
15903       */
15904      getNumSuccessDocsPerPayment(x_paymentTab, p_docsInPmtTab,
15905          l_successDocCountTab);
15906 
15907      /*
15908       * Get the mapping between profile ids and system profile codes.
15909       *
15910       * Individual payments contain the profile id
15911       * as an attribute. However, the config tables like
15912       * reit advice setup etc. contain settings
15913       * based on system profile codes.
15914       *
15915       * Therefore, we need this mapping for operations that
15916       * take place below.
15917       */
15918      IBY_BUILD_UTILS_PKG.getProfileMap(l_profile_map);
15919 
15920      /*
15921       * Loop through all the created payments, flagging any payments
15922       * that require a separate remittance advice.
15923       */
15924      FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
15925 
15926          IF (x_paymentTab(i).payment_status = PAY_STATUS_CREATED) THEN
15927 
15928              l_profile_code := IBY_BUILD_UTILS_PKG.getProfileCodeFromId(
15929                                    x_paymentTab(i).payment_profile_id,
15930                                    l_profile_map
15931                                    );
15932 
15933              FOR j in l_remitAdvicesSetupTab.FIRST ..
15934                           l_remitAdvicesSetupTab.LAST LOOP
15935 
15936                  IF (l_profile_code =
15937                          l_remitAdvicesSetupTab(j).payment_profile_cd) THEN
15938 
15939                      /*
15940                       * Check if this payment meets any of the remittance
15941                       * conditions. If yes, set the separate remittance
15942                       * advice flag to 'Y' for this payment.
15943                       */
15944 
15945                      /* max documents count limit condition */
15946                      IF (l_remitAdvicesSetupTab(j).doc_count_limit <> -1) THEN
15947 
15948                          /*
15949                           * The l_successDocCountTab table and the
15950                           * x_paymentTab table will have the exact same
15951                           * number of records, with the payment ids
15952                           * stored in the same order.
15953                           *
15954                           * Therefore, as far as payment ids are concerned
15955                           * we can use these tables interchangeably.
15956                           * Hence, we can directly pick up the count of
15957                           * successful docs for payment x_paymentTab(i)
15958                           * from l_successDocCountTab(i).
15959                           */
15960                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15961 			 print_debuginfo(l_module_name, 'For payment '
15962                              || x_paymentTab(i).payment_id
15963                              || ' # success docs: '
15964                              || l_successDocCountTab(i).success_docs_count
15965                              || ', remittance advice doc limit: '
15966                              || l_remitAdvicesSetupTab(j).doc_count_limit
15967                              );
15968 
15969 			 END IF;
15970                          IF (l_successDocCountTab(i).success_docs_count
15971                              > l_remitAdvicesSetupTab(j).
15972                                    doc_count_limit) THEN
15973                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15974 				print_debuginfo(l_module_name, 'Setting '
15975                                  || ' separate remittance advice flag '
15976                                  || ' for payment '
15977                                  || x_paymentTab(i).payment_id
15978                                  );
15979                              END IF;
15980 
15981                              x_paymentTab(i).separate_remit_advice_req_flag
15982                                  := 'Y';
15983                          END IF;
15984 
15985                      END IF;
15986 
15987                      /* payment details length limit comndition */
15988                      IF (l_remitAdvicesSetupTab(j).
15989                                 pmt_details_len_limit <> -1) THEN
15990 
15991                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
15992 			 print_debuginfo(l_module_name, 'For payment '
15993                              || x_paymentTab(i).payment_id
15994                              || ' pmt details length: '
15995                              || LENGTH(x_paymentTab(i).payment_details)
15996                              || ', length limit as per remit advc setup: '
15997                              || l_remitAdvicesSetupTab(j).
15998                                     pmt_details_len_limit
15999                              );
16000 
16001 			 END IF;
16002                          IF (LENGTH(x_paymentTab(i).payment_details)
16003                              > l_remitAdvicesSetupTab(j).
16004                                    pmt_details_len_limit) THEN
16005                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16006 				print_debuginfo(l_module_name, 'Setting '
16007                                  || 'separate remittance advice flag '
16008                                  || 'for payment '
16009                                  || x_paymentTab(i).payment_id
16010                                  );
16011                              END IF;
16012 
16013                              x_paymentTab(i).separate_remit_advice_req_flag
16014                                  := 'Y';
16015                          END IF;
16016 
16017                      END IF;
16018 
16019                      /* both conditions unmet */
16020                      IF (l_remitAdvicesSetupTab(j).doc_count_limit = -1 AND
16021                          l_remitAdvicesSetupTab(j).pmt_details_len_limit = -1)
16022                          THEN
16023                          /*
16024                           * No remittance conditions have been set up
16025                           * for this profile, even though there is a
16026                           * remittance advice setup record. This means
16027                           * that remittance advice needs to be generated
16028                           * unconditionally for this payment.
16029                           */
16030                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16031 			 print_debuginfo(l_module_name, 'Unconditionally '
16032                              || 'setting separate remittance advice flag '
16033                              || 'for payment '
16034                              || x_paymentTab(i).payment_id
16035                              );
16036 			 END IF;
16037 
16038 			 x_paymentTab(i).separate_remit_advice_req_flag
16039                              := 'Y';
16040                      END IF;
16041 
16042                      /* Log if we are going to set set the remit flag */
16043                      IF (UPPER(x_paymentTab(i).separate_remit_advice_req_flag)
16044                          <> 'Y') THEN
16045                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16046 			 print_debuginfo(l_module_name, 'Not setting '
16047                              || 'separate remittance advice flag '
16048                              || 'for payment '
16049                              || x_paymentTab(i).payment_id
16050                              );
16051                          END IF; -- if stmt level logging
16052                      END IF;
16053 
16054                  END IF; -- payment profile matches remit advc setup
16055 
16056              END LOOP; -- for each remittance advice setup
16057 
16058          END IF; -- if payment status = created
16059 
16060      END LOOP; -- for each payment
16061 
16062      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16063 	print_debuginfo(l_module_name, 'EXIT');
16064 
16065      END IF;  --
16066  END flagSeparateRemitAdvicePmts;
16067 
16068 /*--------------------------------------------------------------------
16069  | NAME:
16070  |     flagSeparateRemitAdvicePmts
16071  |
16072  | PURPOSE:
16073  |     Determines whether a separate remittance advice is required
16074  |     for a payment. If so, this method will set the 'separate remit
16075  |     advice flag' on the payment.
16076  |
16077  | PARAMETERS:
16078  |     IN
16079  |
16080  |
16081  |     OUT
16082  |
16083  |
16084  | RETURNS:
16085  |
16086  | NOTES:
16087  |
16088  *---------------------------------------------------------------------*/
16089  PROCEDURE flagSeparateRemitAdvicePmts(
16090        l_ca_payreq_cd  IN VARCHAR2,
16091        ppr_id          IN IBY_PAY_SERVICE_REQUESTS.payment_service_request_id%TYPE
16092 --     x_paymentTab    IN OUT NOCOPY paymentTabType
16093 --     p_docsInPmtTab  IN            docsInPaymentTabType
16094      )
16095  IS
16096  l_module_name VARCHAR2(200) := G_PKG_NAME || '.flagSeparateRemitAdvicePmts';
16097 
16098  l_doc_count_limit          NUMBER(15);
16099  l_pmt_details_length_limit NUMBER(15);
16100  l_remitAdvicesSetupTab     remitAdviceRecTab;
16101  l_successDocCountTab       successDocsCountPerPmtTab;
16102 
16103  /* maps profile ids to system profile codes */
16104  l_profile_map        IBY_BUILD_UTILS_PKG.profileIdToCodeMapTabType;
16105  l_profile_code       IBY_PAYMENT_PROFILES.system_profile_code%TYPE;
16106 
16107  /*
16108   * Remittance advices cursor --  Only pick those
16109   * records that have the format attched... there
16110   * will be records in this table even if no format
16111   * is attached from the UI (the defaults are just accepted)
16112   */
16113  CURSOR c_remit_advices
16114  IS
16115  SELECT
16116      advice.system_profile_code,
16117      DECODE(advice.document_count_limit, NULL, -1,
16118          advice.document_count_limit),
16119      DECODE(advice.payment_details_length_limit, NULL, -1,
16120          advice.payment_details_length_limit),
16121      pmt.payment_details,
16122      pmt.payment_id,
16123      COUNT(document_payable_id)
16124 
16125  FROM
16126      IBY_REMIT_ADVICE_SETUP advice,
16127      IBY_PAYMENT_PROFILES   ppp,
16128      IBY_PAYMENTS_ALL       pmt,
16129      IBY_DOCS_PAYABLE_ALL   docs
16130 
16131  WHERE
16132      remittance_advice_format_code IS NOT NULL
16133      AND advice.SYSTEM_PROFILE_CODE = ppp.SYSTEM_PROFILE_CODE
16134      AND ppp.PAYMENT_PROFILE_ID     = pmt.PAYMENT_PROFILE_ID
16135      AND docs.payment_id            = pmt.payment_id
16136      AND pmt.payment_status         = PAY_STATUS_CREATED
16137      AND pmt.payment_service_request_id = ppr_id
16138  GROUP BY
16139      advice.system_profile_code,
16140      advice.document_count_limit,
16141      advice.payment_details_length_limit,
16142      pmt.payment_details,
16143      pmt.payment_id
16144      ;
16145 
16146  BEGIN
16147 
16148      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16149 	 print_debuginfo(l_module_name, 'ENTER');
16150 
16151      END IF;
16152      /*
16153       * Read in the payments and documents from the global
16154       * temp tables and store them into data structures.
16155       */
16156     -- OPEN  c_remit_advices;
16157     -- FETCH c_remit_advices BULK COLLECT INTO l_remitAdvicesSetupTab;
16158     -- CLOSE c_remit_advices;
16159 
16160     /*
16161     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16162 	print_debuginfo(l_module_name, 'Fetched '
16163          || l_remitAdvicesSetupTab.COUNT
16164          || ' records from the remittance advice setup table.');
16165 
16166      END IF;
16167      IF (l_remitAdvicesSetupTab.COUNT = 0) THEN
16168          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16169 	 print_debuginfo(l_module_name, 'No remittance advice information '
16170              || 'has been setup. Separate remittance advice will '
16171              || 'not be generated for any payment in this request. '
16172              || 'Exiting ..'
16173              );
16174          print_debuginfo(l_module_name, 'EXIT');
16175 
16176 	 END IF;
16177 
16178          RETURN;
16179      END IF;
16180      */
16181 
16182 
16183      /*
16184       * For each payment, get the count of successful documents.
16185       * This is required to determine whether a separate remittance
16186       * needs to be flagged for that payment.
16187       */
16188 
16189      /* commenting out the call to get document count for all payments at one short */
16190 
16191    --  getNumSuccessDocsPerPayment(x_paymentTab,
16192    --      l_successDocCountTab);
16193 
16194      /*
16195       * Get the mapping between profile ids and system profile codes.
16196       *
16197       * Individual payments contain the profile id
16198       * as an attribute. However, the config tables like
16199       * reit advice setup etc. contain settings
16200       * based on system profile codes.
16201       *
16202       * Therefore, we need this mapping for operations that
16203       * take place below.
16204       */
16205     -- IBY_BUILD_UTILS_PKG.getProfileMap(l_profile_map);
16206 
16207      /*
16208       * Loop through all the created payments, flagging any payments
16209       * that require a separate remittance advice.
16210       */
16211 --     FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
16212 
16213 
16214 
16215 
16216              /*
16217 	     l_profile_code := IBY_BUILD_UTILS_PKG.getProfileCodeFromId(
16218                                    x_paymentTab(i).payment_profile_id,
16219                                    l_profile_map
16220                                    );
16221 	      */
16222 
16223 
16224 	  OPEN  c_remit_advices;
16225 	  FETCH c_remit_advices BULK COLLECT INTO l_remitAdvicesSetupTab;
16226 	  CLOSE c_remit_advices;
16227 	  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16228 	 print_debuginfo(l_module_name, 'After fetching the values from cursor');
16229 	 END IF;
16230            IF (l_remitAdvicesSetupTab.COUNT > 0) THEN
16231 	      FOR j in l_remitAdvicesSetupTab.FIRST ..
16232 	      l_remitAdvicesSetupTab.LAST LOOP
16233 
16234 
16235                 -- IF (l_profile_code = l_remitAdvicesSetupTab(j).payment_profile_cd) THEN
16236 
16237 
16238 	             /*
16239                       * Check if this payment meets any of the remittance
16240                       * conditions. If yes, set the separate remittance
16241                       * advice flag to 'Y' for this payment.
16242                       */
16243 					  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16244 	      print_debuginfo(l_module_name, 'l_remitAdvicesSetupTab(j).doc_count_limit-'||l_remitAdvicesSetupTab(j).doc_count_limit);
16245 		  END IF;
16246 
16247                      /* max documents count limit condition */
16248                      IF (l_remitAdvicesSetupTab(j).doc_count_limit <> -1) THEN
16249 					 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16250 	      print_debuginfo(l_module_name, 'Inside the if condition.. ');
16251 		  END IF;
16252 
16253                          /*
16254                           * The l_successDocCountTab table and the
16255                           * x_paymentTab table will have the exact same
16256                           * number of records, with the payment ids
16257                           * stored in the same order.
16258                           *
16259                           * Therefore, as far as payment ids are concerned
16260                           * we can use these tables interchangeably.
16261                           * Hence, we can directly pick up the count of
16262                           * successful docs for payment x_paymentTab(i)
16263                           * from l_successDocCountTab(i).
16264                           */
16265                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16266 			 print_debuginfo(l_module_name, 'For payment '
16267                              || l_remitAdvicesSetupTab(j).payment_id
16268                              || ' # success docs: '
16269                              || l_remitAdvicesSetupTab(j).document_count
16270                              || ', remittance advice doc limit: '
16271                              || l_remitAdvicesSetupTab(j).doc_count_limit
16272                              );
16273 
16274 			 END IF;
16275                          IF (l_remitAdvicesSetupTab(j).document_count
16276                              > l_remitAdvicesSetupTab(j).
16277                                    doc_count_limit) THEN
16278                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16279 				print_debuginfo(l_module_name, 'Setting '
16280                                  || ' separate remittance advice flag '
16281                                  || ' for payment '
16282                                  || l_remitAdvicesSetupTab(j).payment_id
16283                                  );
16284                              END IF;
16285 
16286                              --x_paymentTab(i).separate_remit_advice_req_flag
16287                              --    := 'Y';
16288 
16289 			     UPDATE IBY_PAYMENTS_ALL
16290 			     SET separate_remit_advice_req_flag = 'Y'
16291 			     WHERE
16292 			     PAYMENT_ID =l_remitAdvicesSetupTab(j).payment_id;
16293 
16294                          END IF;
16295 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16296          	      print_debuginfo(l_module_name, 'Inside the if condition-at the end.. ');
16297 				  END IF;
16298 
16299                      END IF;
16300 
16301                      /* payment details length limit comndition */
16302                      IF (l_remitAdvicesSetupTab(j).
16303                                 pmt_details_len_limit <> -1) THEN
16304 
16305                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16306 			 print_debuginfo(l_module_name, 'For payment '
16307                              || l_remitAdvicesSetupTab(j).payment_id
16308                              || ' pmt details length: '
16309                              || LENGTH(l_remitAdvicesSetupTab(j).payment_details)
16310                              || ', length limit as per remit advc setup: '
16311                              || l_remitAdvicesSetupTab(j).
16312                                     pmt_details_len_limit
16313                              );
16314 
16315 			 END IF;
16316                          IF (LENGTH(l_remitAdvicesSetupTab(j).payment_details)
16317                              > l_remitAdvicesSetupTab(j).
16318                                    pmt_details_len_limit) THEN
16319                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16320 				print_debuginfo(l_module_name, 'Setting '
16321                                  || 'separate remittance advice flag '
16322                                  || 'for payment '
16323                                  || l_remitAdvicesSetupTab(j).payment_id
16324                                  );
16325                              END IF;
16326 
16327                             -- x_paymentTab(i).separate_remit_advice_req_flag
16328                             --     := 'Y';
16329 
16330 			     UPDATE IBY_PAYMENTS_ALL
16331 			     SET separate_remit_advice_req_flag = 'Y'
16332 			     WHERE
16333 			     PAYMENT_ID = l_remitAdvicesSetupTab(j).payment_id;
16334 
16335                          END IF;
16336 
16337                      END IF;
16338 
16339                      /* both conditions unmet */
16340                      IF (l_remitAdvicesSetupTab(j).doc_count_limit = -1 AND
16341                          l_remitAdvicesSetupTab(j).pmt_details_len_limit = -1)
16342                          THEN
16343                          /*
16344                           * No remittance conditions have been set up
16345                           * for this profile, even though there is a
16346                           * remittance advice setup record. This means
16347                           * that remittance advice needs to be generated
16348                           * unconditionally for this payment.
16349                           */
16350                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16351 			 print_debuginfo(l_module_name, 'Unconditionally '
16352                              || 'setting separate remittance advice flag '
16353                              || 'for payment '
16354                              || l_remitAdvicesSetupTab(j).payment_id
16355                              );
16356 			 END IF;
16357 
16358 			 --x_paymentTab(i).separate_remit_advice_req_flag
16359                          --    := 'Y';
16360 			     UPDATE IBY_PAYMENTS_ALL
16361 			     SET separate_remit_advice_req_flag = 'Y'
16362 			     WHERE
16363 			     PAYMENT_ID = l_remitAdvicesSetupTab(j).payment_id;
16364 
16365 
16366                      END IF;
16367 
16368                      /* Log if we are going to set set the remit flag */
16369                  /*
16370 		 IF (UPPER(x_paymentTab(i).separate_remit_advice_req_flag)
16371                          <> 'Y') THEN
16372                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16373 			 print_debuginfo(l_module_name, 'Not setting '
16374                              || 'separate remittance advice flag '
16375                              || 'for payment '
16376                              || x_paymentTab(i).payment_id
16377                              );
16378                          END IF; -- if stmt level logging
16379                      END IF;
16380 
16381 		   */
16382 
16383 
16384                --  END IF; -- payment profile matches remit advc setup
16385 
16386           --    END LOOP; -- for each remittance advice setup
16387 
16388       --   END IF; -- if payment status = created
16389 
16390      END LOOP; -- for each payment
16391 
16392    END IF;
16393 
16394      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16395 	print_debuginfo(l_module_name, 'EXIT');
16396 
16397      END IF;  --
16398  END flagSeparateRemitAdvicePmts;
16399 
16400 /*--------------------------------------------------------------------
16401  | NAME:
16402  |     getCountOfSuccessDocsPerPayment
16403  |
16404  | PURPOSE:
16405  |     Gets the count of successful documents for each payment.
16406  |
16407  | PARAMETERS:
16408  |     IN
16409  |
16410  |
16411  |     OUT
16412  |
16413  |
16414  | RETURNS:
16415  |
16416  | NOTES:
16417  |
16418  *---------------------------------------------------------------------*/
16419  PROCEDURE getNumSuccessDocsPerPayment(
16420      x_paymentTab          IN OUT NOCOPY paymentTabType,
16421      p_docsInPmtTab        IN            docsInPaymentTabType,
16422      x_successDocCountTab  IN OUT NOCOPY successDocsCountPerPmtTab
16423      )
16424  IS
16425  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
16426                                              '.getNumSuccessDocsPerPayment';
16427  l_successDocCountRec successDocsCountPerPmtRec;
16428 
16429  BEGIN
16430 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16431      print_debuginfo(l_module_name, 'ENTER');
16432 	 END IF;
16433  --
16434      -- vid start here for debug logic
16435 
16436      FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
16437 
16438          /*
16439           * Initialize the success docs count record with the
16440           * given payment id.
16441           */
16442          l_successDocCountRec.payment_id := x_paymentTab(i).payment_id;
16443          l_successDocCountRec.success_docs_count := 0;
16444 
16445          IF (p_docsInPmtTab.COUNT > 0) THEN
16446          FOR j in p_docsInPmtTab.FIRST .. p_docsInPmtTab.LAST LOOP
16447 
16448              IF (x_paymentTab(i).payment_id = p_docsInPmtTab(j).payment_id)
16449                  THEN
16450 
16451                  /*
16452                   * For each successful document for a particular
16453                   * payment, increment the success count.
16454                   *
16455                   * Successful documents will have their status set
16456                   * to 'PAYMENT_CREATED'.
16457                   */
16458                  IF (p_docsInPmtTab(j).document_status = DOC_STATUS_PAY_CREATED)
16459                      THEN
16460 
16461                      l_successDocCountRec.success_docs_count :=
16462                          l_successDocCountRec.success_docs_count + 1;
16463 
16464                  END IF;
16465 
16466              END IF;
16467 
16468          END LOOP; -- for all docs in payment
16469          END IF;
16470 
16471          /*
16472           * Add success docs count record to table and
16473           * do the same process for next payment.
16474           */
16475          x_successDocCountTab(x_successDocCountTab.COUNT + 1) :=
16476              l_successDocCountRec;
16477 
16478      END LOOP;  -- for all payments
16479 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16480      print_debuginfo(l_module_name, 'EXIT');
16481 	 END IF;
16482 
16483  END getNumSuccessDocsPerPayment;
16484 
16485 /*--------------------------------------------------------------------
16486  | NAME:
16487  |     getCountOfSuccessDocsPerPayment
16488  |
16489  | PURPOSE:
16490  |     Gets the count of successful documents for each payment.
16491  |
16492  | PARAMETERS:
16493  |     IN
16494  |
16495  |
16496  |     OUT
16497  |
16498  |
16499  | RETURNS:
16500  |
16501  | NOTES:
16502  |
16503  *---------------------------------------------------------------------*/
16504  PROCEDURE getNumSuccessDocsPerPayment(
16505      x_paymentTab          IN OUT NOCOPY paymentTabType,
16506 --     p_docsInPmtTab        IN            docsInPaymentTabType,
16507      x_successDocCountTab  IN OUT NOCOPY successDocsCountPerPmtTab
16508      )
16509  IS
16510  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
16511                                              '.getNumSuccessDocsPerPayment';
16512  l_successDocCountRec successDocsCountPerPmtRec;
16513 
16514  BEGIN
16515 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16516      print_debuginfo(l_module_name, 'ENTER');
16517 	 END IF;
16518  --
16519      -- vid start here for debug logic
16520 
16521      FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
16522 
16523          /*
16524           * Initialize the success docs count record with the
16525           * given payment id.
16526           */
16527          l_successDocCountRec.payment_id := x_paymentTab(i).payment_id;
16528          l_successDocCountRec.success_docs_count := 0;
16529 
16530          SELECT count(*)
16531          INTO l_successDocCountRec.success_docs_count
16532          FROM iby_docs_in_pmt_gt
16533          WHERE payment_id = x_paymentTab(i).payment_id
16534          AND document_status = DOC_STATUS_PAY_CREATED;
16535 
16536          /*
16537           * Add success docs count record to table and
16538           * do the same process for next payment.
16539           */
16540          x_successDocCountTab(x_successDocCountTab.COUNT + 1) :=
16541              l_successDocCountRec;
16542 
16543      END LOOP;  -- for all payments
16544 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16545      print_debuginfo(l_module_name, 'EXIT');
16546 	 END IF;
16547 
16548  END getNumSuccessDocsPerPayment;
16549 
16550 /*--------------------------------------------------------------------
16551  | NAME:
16552  |     performDBUpdates
16553  |
16554  | PURPOSE:
16555  |     This is the top level method that is called by the
16556  |     payment creation program to:
16557  |         1. insert payments to DB
16558  |         2. update documents with payment id
16559  |         3. update status of payment request
16560  |
16561  |     This method will read the 'rejection level' system option
16562  |     and do updates accordingly.
16563  |
16564  | PARAMETERS:
16565  |     IN
16566  |
16567  |
16568  |     OUT
16569  |
16570  |
16571  | RETURNS:
16572  |
16573  |
16574  | NOTES:
16575  |
16576  *---------------------------------------------------------------------*/
16577  PROCEDURE performDBUpdates(
16578      p_payreq_id          IN            IBY_PAY_SERVICE_REQUESTS.
16579                                           payment_service_request_id%type,
16580      p_rej_level          IN            VARCHAR2,
16581      p_review_pmts_flag   IN            VARCHAR2,
16582      x_paymentTab         IN OUT NOCOPY paymentTabType,
16583      x_docsInPmtTab       IN OUT NOCOPY docsInPaymentTabType,
16584      x_allPmtsSuccessFlag IN OUT NOCOPY BOOLEAN,
16585      x_allPmtsFailedFlag  IN OUT NOCOPY BOOLEAN,
16586      x_return_status      IN OUT NOCOPY VARCHAR2,
16587      x_docErrorTab        IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
16588      x_errTokenTab        IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.
16589                                             trxnErrTokenTabType
16590      )
16591  IS
16592  l_module_name       CONSTANT VARCHAR2(200) := G_PKG_NAME ||
16593                                                    '.performDBUpdates';
16594  l_allsuccess_flag   BOOLEAN := TRUE;
16595  l_allfailed_flag    BOOLEAN := TRUE;
16596  l_request_status    VARCHAR2(200);
16597  l_orig_req_status   VARCHAR2(200);
16598 
16599  l_doc_err_rec       IBY_TRANSACTION_ERRORS%ROWTYPE;
16600  l_triggering_pmt_id IBY_PAYMENTS_ALL.payment_id%TYPE;
16601 
16602  BEGIN
16603 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16604      print_debuginfo(l_module_name, 'ENTER');
16605 	 END IF;
16606 
16607      /*
16608       * Store the original ppr status as it is useful in
16609       * determining the next status in some cases.
16610       */
16611      l_orig_req_status := x_return_status;
16612      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16613      print_debuginfo(l_module_name, 'Original request status = '
16614          || l_orig_req_status
16615          );
16616      END IF;
16617      /*
16618       * Print the rejection level system option
16619       */
16620      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16621      print_debuginfo(l_module_name, 'Rejection level system option set to: '
16622          || p_rej_level);
16623      END IF;
16624      /*
16625       * Find out whether all the payments within this
16626       * payment request have 'success' status. This
16627       * information is used below.
16628       */
16629      FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
16630          IF (x_paymentTab(i).payment_status <> PAY_STATUS_CREATED) THEN
16631              l_triggering_pmt_id := x_paymentTab(i).payment_id;
16632              l_allsuccess_flag := FALSE;
16633              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16634              print_debuginfo(l_module_name, 'At least one payment has '
16635                  || 'failed validation.');
16636              END IF;
16637              EXIT WHEN (1=1);
16638          END IF;
16639      END LOOP;
16640 
16641      /*
16642       * Check if all payments have failed for this
16643       * payment request. This information is used below.
16644       */
16645      FOR i in  x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
16646          IF (x_paymentTab(i).payment_status = PAY_STATUS_CREATED) THEN
16647              l_allfailed_flag := FALSE;
16648              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16649              print_debuginfo(l_module_name, 'At least one payment has '
16650                  || 'has been successfully validated.');
16651              END IF;
16652              EXIT WHEN (1=1);
16653          END IF;
16654      END LOOP;
16655 
16656      /*
16657       * Update the status of the payments/documents
16658       * as per the rejection level (if necessary).
16659       */
16660      IF (p_rej_level = REJ_LVL_REQUEST) THEN
16661 
16662          IF (l_allsuccess_flag = FALSE) THEN
16663              /*
16664               * This means that at least one payment in this
16665               * payment request has failed.
16666               *
16667               * For 'request' rejection level:
16668               * If any payment in the request fails validation,
16669               * the entire payment request should be rejected;
16670               * So fail all payments in this payment request.
16671               */
16672              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16673              print_debuginfo(l_module_name, 'Failing all payments and '
16674                      || 'documents for payment request '
16675                      || p_payreq_id);
16676              END IF;
16677              FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
16678 
16679                  IF (x_paymentTab(i).payment_status = PAY_STATUS_CREATED) THEN
16680 
16681                      x_paymentTab(i).payment_status :=
16682                          PAY_STATUS_FAIL_BY_REJLVL;
16683 
16684                      /*
16685                       * Once we fail a payment, we need to create
16686                       * an error record and insert this record
16687                       * into the errors table.
16688                       */
16689                      IBY_BUILD_UTILS_PKG.createErrorRecord(
16690                          TRXN_TYPE_PMT,
16691                          x_paymentTab(i).payment_id,
16692                          x_paymentTab(i).payment_status,
16693                          NULL,
16694                          x_paymentTab(i).payment_id,
16695                          NULL,
16696                          NULL,
16697                          NULL,
16698                          NULL,
16699                          NULL,
16700                          l_doc_err_rec,
16701                          x_errTokenTab,
16702                          NULL
16703                          );
16704 
16705                      IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
16706                          l_doc_err_rec, x_docErrorTab, x_errTokenTab);
16707 
16708                      failDocsOfPayment(x_paymentTab(i).payment_id,
16709                          DOC_STATUS_PAY_VAL_FAIL,
16710                          x_docsInPmtTab, x_docErrorTab,
16711                          x_errTokenTab);
16712 
16713                  END IF;
16714 
16715              END LOOP;
16716 
16717              /* set the status of the payment request to failed */
16718              l_request_status := REQ_STATUS_FAIL_PAY_CR;
16719 
16720          ELSE
16721 
16722              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
16723 
16724                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
16725 
16726                      /*
16727                       * Fix for bug 5209530:
16728                       *
16729                       * If the pmts of a payment request have already
16730                       * been reviewed and the payment request has
16731                       * re-entered the pmt creation flow, then the pmts
16732                       * will again been validated.
16733                       *
16734                       * If all pmts are successful, do not again ask the
16735                       * user to review the payments, instead allow
16736                       * the ppr to proceed formward.
16737                       *
16738                       * For example, when documents of a pmt(s) are
16739                       * dismissed and the pmts have been re-validated,
16740                       * and there are no errors allow the ppr to
16741                       * proceed forward instead of setting it for
16742                       * user review again.
16743                       */
16744                      l_request_status := REQ_STATUS_PAY_CRTD;
16745 
16746                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16747                      print_debuginfo(l_module_name, 'Payment request is '
16748                          || 're-entering payment creation and all payments '
16749                          || 'are valid. User need not review pmts again.'
16750                          );
16751 
16752                      print_debuginfo(l_module_name, 'Setting payment '
16753                          || 'request status to '
16754                          || l_request_status
16755                          || '.'
16756                          );
16757 		      END IF;
16758 
16759                  ELSE
16760 
16761 
16762                      /*
16763                       * If review proposed payments flag is set, then
16764                       * move successful payment requests also to
16765                       * 'pending review' status.
16766                       */
16767                      l_request_status := REQ_STATUS_USER_REVW;
16768                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16769                      print_debuginfo(l_module_name, 'Review proposed payments '
16770                          || 'flag has been set. Setting status of successful '
16771                          || 'request to pending review.');
16772 		     END IF;
16773                  END IF;
16774 
16775              ELSE
16776 
16777                  /* set the status of the payment request to pmts created */
16778                  l_request_status := REQ_STATUS_PAY_CRTD;
16779 
16780              END IF;
16781 
16782          END IF;
16783 
16784      ELSIF (p_rej_level = REJ_LVL_PAYMENT) THEN
16785 
16786          /*
16787           * Check if all payments in the request have failed.
16788           */
16789          IF (l_allfailed_flag = TRUE) THEN
16790 
16791              l_request_status := REQ_STATUS_FAIL_PAY_CR;
16792 
16793          ELSE
16794 
16795              /*
16796               * At least one payment in the request was
16797               * successful.
16798               */
16799              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
16800 
16801                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
16802 
16803                      /*
16804                       * Fix for bug 5209530:
16805                       *
16806                       * If the pmts of a payment request have already
16807                       * been reviewed and the payment request has
16808                       * re-entered the pmt creation flow, then the pmts
16809                       * will again been validated.
16810                       *
16811                       * If all pmts are successful, do not again ask the
16812                       * user to review the payments, instead allow
16813                       * the ppr to proceed formward.
16814                       *
16815                       * For example, when documents of a pmt(s) are
16816                       * dismissed and the pmts have been re-validated,
16817                       * and there are no errors allow the ppr to
16818                       * proceed forward instead of setting it for
16819                       * user review again.
16820                       */
16821                      l_request_status := REQ_STATUS_PAY_CRTD;
16822 
16823                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16824                      print_debuginfo(l_module_name, 'Payment request is '
16825                          || 're-entering payment creation and all payments '
16826                          || 'are valid. User need not review pmts again.'
16827                          );
16828 
16829                      print_debuginfo(l_module_name, 'Setting payment '
16830                          || 'request status to '
16831                          || l_request_status
16832                          || '.'
16833                          );
16834 		      END IF;
16835 
16836                  ELSE
16837 
16838                      /*
16839                       * If review proposed payments flag is set, then
16840                       * move successful payment requests also to
16841                       * 'pending review' status.
16842                       */
16843                      l_request_status := REQ_STATUS_USER_REVW;
16844 
16845                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16846                      print_debuginfo(l_module_name, 'Review proposed payments '
16847                          || 'flag has been set. Setting status of successful '
16848                          || 'request to pending review.');
16849 		     END IF;
16850                  END IF;
16851 
16852              ELSE
16853 
16854                  /* set the status of the payment request to pmts created */
16855                  l_request_status := REQ_STATUS_PAY_CRTD;
16856 
16857                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16858                  print_debuginfo(l_module_name, 'Review proposed payments '
16859                      || 'flag has not been set. Setting status of successful '
16860                      || 'request to created.');
16861                  END IF;
16862 
16863              END IF;
16864 
16865          END IF;
16866 
16867      /* Bug 8209474 */
16868      ELSIF (p_rej_level = REJ_LVL_PAYEE) THEN
16869               IF (l_allsuccess_flag = FALSE) THEN
16870              /*
16871               * This means that at least one payment in this
16872               * payment request has failed.
16873               *
16874               * For 'request' rejection level:
16875               * If any payment in the request fails validation,
16876               * the entire payment request should be rejected;
16877               * So fail all payments in this payment request.
16878               */
16879 
16880 	     FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
16881 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16882                 print_debuginfo(l_module_name, 'Failing all payments and '
16883                 || 'documents for Payee ' || x_paymentTab(i).ext_payee_id || 'ANIL');
16884 				END IF;
16885 
16886 		 IF (l_payeeTab.EXISTS (x_paymentTab(i).ext_payee_id)) THEN
16887 
16888                      x_paymentTab(i).payment_status :=
16889                          PAY_STATUS_FAIL_BY_REJLVL;
16890 
16891                      /*
16892                       * Once we fail a payment, we need to create
16893                       * an error record and insert this record
16894                       * into the errors table.
16895                       */
16896                      IBY_BUILD_UTILS_PKG.createErrorRecord(
16897                          TRXN_TYPE_PMT,
16898                          x_paymentTab(i).payment_id,
16899                          x_paymentTab(i).payment_status,
16900                          NULL,
16901                          x_paymentTab(i).payment_id,
16902                          NULL,
16903                          NULL,
16904                          NULL,
16905                          NULL,
16906                          NULL,
16907                          l_doc_err_rec,
16908                          x_errTokenTab,
16909                          NULL
16910                          );
16911 
16912                      IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
16913                          l_doc_err_rec, x_docErrorTab, x_errTokenTab);
16914 
16915                      failDocsOfPayment(x_paymentTab(i).payment_id,
16916                          DOC_STATUS_PAY_VAL_FAIL,
16917                          x_docsInPmtTab, x_docErrorTab,
16918                          x_errTokenTab);
16919 
16920                  END IF;
16921 
16922              END LOOP; --Payment Loop
16923 	    /* set the status of the payment request to failed */
16924              l_request_status := REQ_STATUS_FAIL_PAY_CR;
16925 
16926          ELSE
16927 
16928              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
16929 
16930                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
16931 
16932                      /*
16933                       * Fix for bug 5209530:
16934                       *
16935                       * If the pmts of a payment request have already
16936                       * been reviewed and the payment request has
16937                       * re-entered the pmt creation flow, then the pmts
16938                       * will again been validated.
16939                       *
16940                       * If all pmts are successful, do not again ask the
16941                       * user to review the payments, instead allow
16942                       * the ppr to proceed formward.
16943                       *
16944                       * For example, when documents of a pmt(s) are
16945                       * dismissed and the pmts have been re-validated,
16946                       * and there are no errors allow the ppr to
16947                       * proceed forward instead of setting it for
16948                       * user review again.
16949                       */
16950                      l_request_status := REQ_STATUS_PAY_CRTD;
16951 
16952                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16953                      print_debuginfo(l_module_name, 'Payment request is '
16954                          || 're-entering payment creation and all payments '
16955                          || 'are valid. User need not review pmts again.'
16956                          );
16957 
16958                      print_debuginfo(l_module_name, 'Setting payment '
16959                          || 'request status to '
16960                          || l_request_status
16961                          || '.'
16962                          );
16963 		      END IF;
16964 
16965                  ELSE
16966 
16967 
16968                      /*
16969                       * If review proposed payments flag is set, then
16970                       * move successful payment requests also to
16971                       * 'pending review' status.
16972                       */
16973                      l_request_status := REQ_STATUS_USER_REVW;
16974                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
16975                      print_debuginfo(l_module_name, 'Review proposed payments '
16976                          || 'flag has been set. Setting status of successful '
16977                          || 'request to pending review.');
16978 		     END IF;
16979                  END IF;
16980 
16981              ELSE
16982 
16983                  /* set the status of the payment request to pmts created */
16984                  l_request_status := REQ_STATUS_PAY_CRTD;
16985 
16986              END IF;
16987 
16988          END IF;
16989 
16990      ELSIF (p_rej_level = REJ_LVL_NONE) THEN
16991 
16992          IF (l_allsuccess_flag = TRUE) THEN
16993 
16994              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
16995 
16996                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
16997 
16998                      /*
16999                       * Fix for bug 5209530:
17000                       *
17001                       * If the pmts of a payment request have already
17002                       * been reviewed and the payment request has
17003                       * re-entered the pmt creation flow, then the pmts
17004                       * will again been validated.
17005                       *
17006                       * If all pmts are successful, do not again ask the
17007                       * user to review the payments, instead allow
17008                       * the ppr to proceed formward.
17009                       *
17010                       * For example, when documents of a pmt(s) are
17011                       * dismissed and the pmts have been re-validated,
17012                       * and there are no errors allow the ppr to
17013                       * proceed forward instead of setting it for
17014                       * user review again.
17015                       */
17016                      l_request_status := REQ_STATUS_PAY_CRTD;
17017 
17018                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17019                      print_debuginfo(l_module_name, 'Payment request is '
17020                          || 're-entering payment creation and all payments '
17021                          || 'are valid. User need not review pmts again.'
17022                          );
17023 
17024                      print_debuginfo(l_module_name, 'Setting payment '
17025                          || 'request status to '
17026                          || l_request_status
17027                          || '.'
17028                          );
17029 		      END IF;
17030 
17031                  ELSE
17032 
17033                      l_request_status := REQ_STATUS_USER_REVW;
17034 
17035                  END IF;
17036 
17037              ELSE
17038 
17039                  l_request_status := REQ_STATUS_PAY_CRTD;
17040 
17041              END IF;
17042 
17043          ELSE
17044 
17045              /*
17046               * If control come here, it means that there
17047               * are some payments that failed validation
17048               * and the rejecttion level is set to 'NONE'.
17049               *
17050               * This means that we should not kick back
17051               * the underlying documents back to AP. Instead,
17052               * we should set the PPR status to
17053               * REQ_STATUS_USER_REVW_ERR. This will allow
17054               * the user to review the failed payments
17055               * in the UI and take corrective action.
17056               */
17057              l_request_status := REQ_STATUS_USER_REVW_ERR;
17058 
17059              /*
17060               * Fix for bug 6709700:
17061               *
17062               * By default, when a payment fails validation
17063               * it is set to PAY_STATUS_REJECTED status. This indicates
17064               * a hard failure and the constituent documents of the
17065               * payment will be kicked back to the calling app.
17066               *
17067               * However, when th rejection level is set to NONE,
17068               * the user wishes to review the failed payments.
17069               * Therefore, we should soft-fail the payments
17070               * that fail validation and not kick back the
17071               * underlying documents back to the calling app.
17072               *
17073               * For the soft failure of the ayment, we use
17074               * a separate status - PAY_STATUS_FAIL_VALID.
17075               *
17076               * Update all the payments that are in PAY_STATUS_REJECTED
17077               * status to PAY_STATUS_FAIL_VALID.
17078               */
17079              FOR j in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
17080 
17081                  IF (x_paymentTab(j).payment_status = PAY_STATUS_REJECTED) THEN
17082 
17083                      x_paymentTab(j).payment_status :=
17084                          PAY_STATUS_FAIL_VALID;
17085 
17086                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17087                      print_debuginfo(l_module_name, 'Updating payment '
17088                          || x_paymentTab(j).payment_id
17089                          || ' to soft failure status.'
17090                          );
17091                      END IF;
17092                  END IF;
17093 
17094              END LOOP;
17095 
17096          END IF; -- if all success == true
17097 
17098      ELSE
17099 
17100 
17101          print_debuginfo(l_module_name, 'Unknown rejection level: '
17102              || p_rej_level
17103              || '. Aborting payment creation ..',
17104              FND_LOG.LEVEL_UNEXPECTED
17105              );
17106 
17107 
17108          APP_EXCEPTION.RAISE_EXCEPTION;
17109 
17110      END IF;
17111 
17112      /*
17113       * All payments for this payment request have been
17114       * created and stored in a PLSQL table. Now write these
17115       * payments to the database.
17116       */
17117      /* not needed in here as all updates have happened */
17118     -- updatePayments(x_paymentTab);
17119 
17120      /*
17121       * Update the documents table by providing a payment id to
17122       * each document.
17123       */
17124      updateDocsWithPaymentID(x_docsInPmtTab);
17125 
17126      /*
17127       * If any payments/documents were failed, the IBY_TRANSACTION_
17128       * ERRORS table must be populated with the corresponding error
17129       * messages.
17130       */
17131      IBY_VALIDATIONSETS_PUB.insert_transaction_errors('N', x_docErrorTab,
17132          x_errTokenTab);
17133 
17134      /*
17135       * Update the status of the payment request.
17136       */
17137      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17138      print_debuginfo(l_module_name, 'Updating status of payment request '
17139          || p_payreq_id || ' to ' || l_request_status || '.');
17140      END IF;
17141 
17142      UPDATE
17143          iby_pay_service_requests
17144      SET
17145          payment_service_request_status = l_request_status
17146      WHERE
17147          payment_service_request_id = p_payreq_id
17148      ;
17149 
17150      /* Pass back the request status to the caller */
17151      x_return_status := l_request_status;
17152 
17153      /*
17154       * Pass the 'all payments success' and 'all payments
17155       * failed' flags back to the caller.
17156       *
17157       * These flag will be used in raising business events.
17158       */
17159      x_allPmtsSuccessFlag := l_allsuccess_flag;
17160      x_allPmtsFailedFlag  := l_allfailed_flag;
17161 
17162      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17163      print_debuginfo(l_module_name, 'EXIT');
17164       END IF;
17165 
17166  EXCEPTION
17167 
17168      WHEN OTHERS THEN
17169 
17170          print_debuginfo(l_module_name, 'Fatal: Exception when updating '
17171              || 'payment request/payment/document status after payment '
17172              || 'creation. All changes will be rolled back. Payment request '
17173              || 'id is ' || p_payreq_id, FND_LOG.LEVEL_UNEXPECTED);
17174          print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
17175              FND_LOG.LEVEL_UNEXPECTED);
17176          print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
17177              FND_LOG.LEVEL_UNEXPECTED);
17178 
17179 
17180          /*
17181           * Propogate exception to caller.
17182           */
17183          RAISE;
17184 
17185  END performDBUpdates;
17186 
17187 /*--------------------------------------------------------------------
17188  | NAME:
17189  |     performDBUpdates
17190  |
17191  | PURPOSE:
17192  |     This is the top level method that is called by the
17193  |     payment creation program to:
17194  |         1. insert payments to DB
17195  |         2. update documents with payment id
17196  |         3. update status of payment request
17197  |
17198  |     This method will read the 'rejection level' system option
17199  |     and do updates accordingly.
17200  |
17201  | PARAMETERS:
17202  |     IN
17203  |
17204  |
17205  |     OUT
17206  |
17207  |
17208  | RETURNS:
17209  |
17210  |
17211  | NOTES:
17212  |
17213  *---------------------------------------------------------------------*/
17214  PROCEDURE performDBUpdates(
17215      p_payreq_id          IN            IBY_PAY_SERVICE_REQUESTS.
17216                                           payment_service_request_id%type,
17217      p_rej_level          IN            VARCHAR2,
17218      p_review_pmts_flag   IN            VARCHAR2,
17219  --    x_paymentTab         IN OUT NOCOPY paymentTabType,
17220  --     x_docsInPmtTab       IN OUT NOCOPY docsInPaymentTabType,
17221      x_allPmtsSuccessFlag IN OUT NOCOPY BOOLEAN,
17222      x_allPmtsFailedFlag  IN OUT NOCOPY BOOLEAN,
17223      x_return_status      IN OUT NOCOPY VARCHAR2,
17224      x_docErrorTab        IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
17225      x_errTokenTab        IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.
17226                                             trxnErrTokenTabType
17227      )
17228  IS
17229  l_module_name       CONSTANT VARCHAR2(200) := G_PKG_NAME ||
17230                                                    '.performDBUpdates';
17231  l_allsuccess_flag   VARCHAR2(1) := 'Y';
17232  l_allfailed_flag    VARCHAR2(1) := 'Y';
17233  l_request_status    VARCHAR2(200);
17234  l_orig_req_status   VARCHAR2(200);
17235 
17236  l_pmt_count	     NUMBER;
17237  l_doc_err_rec       IBY_TRANSACTION_ERRORS%ROWTYPE;
17238  l_triggering_pmt_id IBY_PAYMENTS_ALL.payment_reference_number%TYPE;
17239 
17240  l_validpayment_flag   VARCHAR2(1) := 'N';	--bug 13854619
17241 
17242  l_error_code    VARCHAR2(100);  -- AWT Enh 16296267
17243  l_error_msg     VARCHAR2(500);
17244  l_token_rec     IBY_TRXN_ERROR_TOKENS%ROWTYPE;
17245 
17246  l_validawt_flag VARCHAR2(1) := 'Y';
17247 
17248 
17249  BEGIN
17250 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17251      print_debuginfo(l_module_name, 'ENTER');
17252 	 END IF;
17253 
17254      /*
17255       * Store the original ppr status as it is useful in
17256       * determining the next status in some cases.
17257       */
17258      l_orig_req_status := x_return_status;
17259      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17260      print_debuginfo(l_module_name, 'Original request status = '
17261          || l_orig_req_status
17262          );
17263      END IF;
17264      /*
17265       * Print the rejection level system option
17266       */
17267      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17268      print_debuginfo(l_module_name, 'Rejection level system option set to: '
17269          || p_rej_level);
17270      END IF;
17271      /*
17272       * Find out whether all the payments within this
17273       * payment request have 'success' status. This
17274       * information is used below.
17275       */
17276      /*
17277      FOR i in  x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
17278          IF (x_paymentTab(i).payment_status <> PAY_STATUS_CREATED) THEN
17279              l_triggering_pmt_id := x_paymentTab(i).payment_id;
17280              l_allsuccess_flag := FALSE;
17281              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17282              print_debuginfo(l_module_name, 'At least one payment has '
17283                  || 'failed validation.');
17284              END IF;
17285              EXIT WHEN (1=1);
17286          END IF;
17287      END LOOP;
17288      */
17289 
17290 
17291      Begin
17292      SELECT 'N'
17293      INTO l_allsuccess_flag
17294      from DUAL
17295      WHERE EXISTS
17296      (SELECT 1 FROM IBY_PAYMENTS_ALL
17297       WHERE PAYMENT_STATUS NOT IN (PAY_STATUS_CREATED, PAY_STATUS_REMOVED)
17298       AND payment_service_request_id =p_payreq_id
17299      );
17300      EXCEPTION
17301      WHEN No_Data_Found THEN
17302 
17303      l_allsuccess_flag := 'Y';
17304      END;
17305 
17306      select count(payment_id)
17307      into l_pmt_count
17308      from iby_payments_all
17309      where payment_service_request_id = p_payreq_id
17310      AND payment_status <> PAY_STATUS_CREATED
17311      ;
17312 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17313     print_debuginfo(l_module_name, 'l_pmt_count -' || l_pmt_count);
17314     print_debuginfo(l_module_name, 'l_allsuccess_flag -' || l_allsuccess_flag);
17315 	END IF;
17316 
17317      /*
17318       * Check if all payments have failed for this
17319       * payment request. This information is used below.
17320       */
17321      /*
17322      FOR i in  x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
17323          IF (x_paymentTab(i).payment_status = PAY_STATUS_CREATED) THEN
17324              l_allfailed_flag := FALSE;
17325              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17326              print_debuginfo(l_module_name, 'At least one payment has '
17327                  || 'has been successfully validated.');
17328              END IF;
17329              EXIT WHEN (1=1);
17330          END IF;
17331      END LOOP;
17332      */
17333 
17334      begin
17335      SELECT 'N'
17336      INTO l_allfailed_flag
17337      from DUAL
17338      WHERE EXISTS
17339      (SELECT 1 FROM IBY_PAYMENTS_ALL
17340       WHERE PAYMENT_STATUS = PAY_STATUS_CREATED
17341       AND payment_service_request_id =p_payreq_id
17342      );
17343 
17344      EXCEPTION
17345      WHEN No_Data_Found THEN
17346       l_allfailed_flag := 'Y';
17347      END;
17348 	 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17349     print_debuginfo(l_module_name, 'l_allfailed_flag -' || l_allfailed_flag);
17350 	END IF;
17351      /*
17352       * Update the status of the payments/documents
17353       * as per the rejection level (if necessary).
17354       */
17355      IF (p_rej_level = REJ_LVL_REQUEST) THEN
17356 
17357          IF (l_allsuccess_flag = 'N') THEN
17358              /*
17359               * This means that at least one payment in this
17360               * payment request has failed.
17361               *
17362               * For 'request' rejection level:
17363               * If any payment in the request fails validation,
17364               * the entire payment request should be rejected;
17365               * So fail all payments in this payment request.
17366               */
17367              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17368              print_debuginfo(l_module_name, 'Failing all payments and '
17369                      || 'documents for payment request '
17370                      || p_payreq_id);
17371              END IF;
17372 
17373 
17374              FOR i in  IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST ..  IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST LOOP
17375 
17376 			 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17377 	  print_debuginfo(l_module_name,'IBY_PAYGROUP_PUB.pmtTable.payment_id(i) ' || IBY_PAYGROUP_PUB.pmtTable.payment_id(i));
17378 	  END IF;
17379 
17380 
17381                  IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(i) = PAY_STATUS_CREATED) THEN
17382 
17383 
17384 
17385 		    IBY_PAYGROUP_PUB.pmtTable.payment_status(i) :=
17386                          PAY_STATUS_FAIL_BY_REJLVL;
17387 
17388 
17389                      /*
17390                       * Once we fail a payment, we need to create
17391                       * an error record and insert this record
17392                       * into the errors table.
17393                       */
17394                      IBY_BUILD_UTILS_PKG.createErrorRecord(
17395                          TRXN_TYPE_PMT,
17396                          IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17397                          IBY_PAYGROUP_PUB.pmtTable.payment_status(i),
17398                          NULL,
17399                          IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17400                          NULL,
17401                          NULL,
17402                          NULL,
17403                          NULL,
17404                          NULL,
17405                          l_doc_err_rec,
17406                          x_errTokenTab,
17407                          l_triggering_pmt_id
17408                          );
17409 
17410                      IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
17411                          l_doc_err_rec, x_docErrorTab, x_errTokenTab);
17412 
17413                      failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17414                          DOC_STATUS_PAY_VAL_FAIL,
17415                          x_docErrorTab,
17416                          x_errTokenTab);
17417 
17418                  END IF;
17419 
17420              END LOOP;
17421 
17422              /* set the status of the payment request to failed */
17423              l_request_status := REQ_STATUS_FAIL_PAY_CR;
17424 
17425          ELSE
17426 
17427              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
17428 
17429                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
17430 
17431                      /*
17432                       * Fix for bug 5209530:
17433                       *
17434                       * If the pmts of a payment request have already
17435                       * been reviewed and the payment request has
17436                       * re-entered the pmt creation flow, then the pmts
17437                       * will again been validated.
17438                       *
17439                       * If all pmts are successful, do not again ask the
17440                       * user to review the payments, instead allow
17441                       * the ppr to proceed formward.
17442                       *
17443                       * For example, when documents of a pmt(s) are
17444                       * dismissed and the pmts have been re-validated,
17445                       * and there are no errors allow the ppr to
17446                       * proceed forward instead of setting it for
17447                       * user review again.
17448                       */
17449                      l_request_status := REQ_STATUS_PAY_CRTD;
17450 
17451                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17452                      print_debuginfo(l_module_name, 'Payment request is '
17453                          || 're-entering payment creation and all payments '
17454                          || 'are valid. User need not review pmts again.'
17455                          );
17456 
17457                      print_debuginfo(l_module_name, 'Setting payment '
17458                          || 'request status to '
17459                          || l_request_status
17460                          || '.'
17461                          );
17462 		      END IF;
17463 
17464                  ELSE
17465 
17466 
17467                      /*
17468                       * If review proposed payments flag is set, then
17469                       * move successful payment requests also to
17470                       * 'pending review' status.
17471                       */
17472                      l_request_status := REQ_STATUS_USER_REVW;
17473                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17474                      print_debuginfo(l_module_name, 'Review proposed payments '
17475                          || 'flag has been set. Setting status of successful '
17476                          || 'request to pending review.');
17477 		     END IF;
17478                  END IF;
17479 
17480              ELSE
17481 
17482                  /* set the status of the payment request to pmts created */
17483                  l_request_status := REQ_STATUS_PAY_CRTD;
17484 
17485              END IF;
17486 
17487          END IF;
17488 
17489      ELSIF (p_rej_level = REJ_LVL_PAYMENT) THEN
17490 
17491 		IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17492             print_debuginfo(l_module_name,'Inside the rejection level chk -if payments');
17493 	    END IF;
17494 
17495 		  /* AWT Enhancement 16296267 */
17496 		IF (l_payeeAwt.COUNT > 0 AND l_allfailed_flag = 'N') THEN
17497 	        l_validawt_flag := 'N';
17498             FOR i in  IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST ..  IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST LOOP
17499 
17500 		      	IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17501 	                print_debuginfo(l_module_name,'IBY_PAYGROUP_PUB.pmtTable.payment_id(i) ' || IBY_PAYGROUP_PUB.pmtTable.payment_id(i));
17502 	            END IF;
17503 
17504 	             IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(i) = PAY_STATUS_CREATED) THEN  --BUG 13519802
17505 
17506                     IF (l_payeeAwt.EXISTS(IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i)) AND
17507 		      		    IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(i) = 'Y') THEN
17508                           IBY_PAYGROUP_PUB.pmtTable.payment_status(i) :=
17509                                PAY_STATUS_FAIL_BY_REJLVL;
17510 
17511 
17512                         l_error_code := 'IBY_PMT_FAILED_BY_RELATED_PMT';
17513                         FND_MESSAGE.set_name('IBY', l_error_code);
17514 
17515                         FND_MESSAGE.SET_TOKEN('PAYMENT_REFERENCE_NUMBER',
17516                             l_payeeAwt(IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i)),
17517                             FALSE);
17518 
17519                         l_token_rec.token_name  := 'PAYMENT_REFERENCE_NUMBER';
17520                         l_token_rec.token_value := l_payeeAwt(IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i));
17521                         x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
17522 
17523 
17524 
17525 
17526 		      			 /*
17527                             * Once we fail a payment, we need to create
17528                             * an error record and insert this record
17529                             * into the errors table.
17530                             */
17531 
17532                         IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
17533                             IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17534                             IBY_PAYGROUP_PUB.pmtTable.payment_status(i),
17535                             l_error_code,
17536                             FND_MESSAGE.get,
17537                             l_doc_err_rec
17538                             );
17539 
17540 
17541 		      		    IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
17542                             l_doc_err_rec, x_docErrorTab, x_errTokenTab);
17543 
17544                         failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17545                             DOC_STATUS_PAY_VAL_FAIL,
17546                             x_docErrorTab,
17547                             x_errTokenTab);
17548 	                ELSE
17549 		                IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17550                             print_debuginfo(l_module_name, 'Set valid payment flag to Y '
17551                                 || 'when there is atleast one valid payment for the ppr.'
17552                                 );
17553 		                END IF;
17554                         l_validawt_flag := 'Y';
17555                     END IF;
17556 		        END IF;
17557             END LOOP;
17558 	        l_payeeAwt.DELETE;
17559 	    END IF;
17560 		  /* End of AWT Enh 16296267*/
17561 
17562         IF ((l_allfailed_flag = 'Y') OR
17563 	        (l_validawt_flag = 'N' AND l_allfailed_flag = 'N'))
17564 	    THEN
17565             l_request_status := REQ_STATUS_FAIL_PAY_CR;
17566         ELSE
17567 	        IF (UPPER(p_review_pmts_flag) = 'Y') THEN
17568 
17569                 IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
17570 
17571                     /*
17572                      * Fix for bug 5209530:
17573                      *
17574                      * If the pmts of a payment request have already
17575                      * been reviewed and the payment request has
17576                      * re-entered the pmt creation flow, then the pmts
17577                      * will again been validated.
17578                      *
17579                      * If all pmts are successful, do not again ask the
17580                      * user to review the payments, instead allow
17581                      * the ppr to proceed formward.
17582                      *
17583                      * For example, when documents of a pmt(s) are
17584                      * dismissed and the pmts have been re-validated,
17585                      * and there are no errors allow the ppr to
17586                      * proceed forward instead of setting it for
17587                      * user review again.
17588                      */
17589                     l_request_status := REQ_STATUS_PAY_CRTD;
17590 
17591                     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17592                        print_debuginfo(l_module_name, 'Payment request is '
17593                            || 're-entering payment creation and all payments '
17594                            || 'are valid. User need not review pmts again.'
17595                            );
17596 
17597                        print_debuginfo(l_module_name, 'Setting payment '
17598                            || 'request status to '
17599                            || l_request_status
17600                            || '.'
17601                            );
17602 	    	        END IF;
17603                 ELSE
17604 
17605                     /*
17606                      * If review proposed payments flag is set, then
17607                      * move successful payment requests also to
17608                      * 'pending review' status.
17609                      */
17610                     l_request_status := REQ_STATUS_USER_REVW;
17611 
17612                     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17613                     print_debuginfo(l_module_name, 'Review proposed payments '
17614                         || 'flag has been set. Setting status of successful '
17615                         || 'request to pending review.');
17616 	    	         END IF;
17617 
17618 	    		END IF;
17619             ELSE
17620 
17621                  /* set the status of the payment request to pmts created */
17622                  l_request_status := REQ_STATUS_PAY_CRTD;
17623 
17624                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17625                  print_debuginfo(l_module_name, 'Review proposed payments '
17626                      || 'flag has not been set. Setting status of successful '
17627                      || 'request to created.');
17628                  END IF;
17629 
17630 	        END IF;
17631 	    END IF;
17632 /* Bug 8209474 */
17633      ELSIF (p_rej_level = REJ_LVL_PAYEE) THEN
17634 
17635          IF (l_allsuccess_flag = 'N') THEN
17636              /*
17637               * This means that at least one payment in this
17638               * payment request has failed.
17639               *
17640               * For 'request' rejection level:
17641               * If any payment in the request fails validation,
17642               * the entire payment request should be rejected;
17643               * So fail all payments in this payment request.
17644               */
17645 
17646 
17647              FOR i in  IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST ..  IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST LOOP
17648 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17649 	  print_debuginfo(l_module_name,'IBY_PAYGROUP_PUB.pmtTable.payment_id(i) ' || IBY_PAYGROUP_PUB.pmtTable.payment_id(i));
17650 	  END IF;
17651 
17652 	       IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(i) = PAY_STATUS_CREATED) THEN  --BUG 13519802
17653 
17654                  IF (l_payeeTab.EXISTS(IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(i))) THEN
17655 		    IBY_PAYGROUP_PUB.pmtTable.payment_status(i) :=
17656                          PAY_STATUS_FAIL_BY_REJLVL;
17657 
17658 
17659                      /*
17660                       * Once we fail a payment, we need to create
17661                       * an error record and insert this record
17662                       * into the errors table.
17663                       */
17664                      IBY_BUILD_UTILS_PKG.createErrorRecord(
17665                          TRXN_TYPE_PMT,
17666                          IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17667                          IBY_PAYGROUP_PUB.pmtTable.payment_status(i),
17668                          NULL,
17669                          IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17670                          NULL,
17671                          NULL,
17672                          NULL,
17673                          NULL,
17674                          NULL,
17675                          l_doc_err_rec,
17676                          x_errTokenTab,
17677                          l_triggering_pmt_id
17678                          );
17679 
17680                      IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
17681                          l_doc_err_rec, x_docErrorTab, x_errTokenTab);
17682 
17683                      failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(i),
17684                          DOC_STATUS_PAY_VAL_FAIL,
17685                          x_docErrorTab,
17686                          x_errTokenTab);
17687 
17688 	         --bug 13854619
17689 	         ELSE
17690 		    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17691                      print_debuginfo(l_module_name, 'Set valid payment flag to Y '
17692                          || 'when there is atleast one valid payment for the ppr.'
17693                          );
17694 		      END IF;
17695 
17696 		    l_validpayment_flag := 'Y';
17697 
17698                  END IF;
17699 
17700 	       END IF;
17701 
17702              END LOOP;
17703              /* set the status of the payment request */
17704              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
17705 
17706                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
17707 
17708                      /*
17709                       * Fix for bug 5209530:
17710                       *
17711                       * If the pmts of a payment request have already
17712                       * been reviewed and the payment request has
17713                       * re-entered the pmt creation flow, then the pmts
17714                       * will again been validated.
17715                       *
17716                       * If all pmts are successful, do not again ask the
17717                       * user to review the payments, instead allow
17718                       * the ppr to proceed formward.
17719                       *
17720                       * For example, when documents of a pmt(s) are
17721                       * dismissed and the pmts have been re-validated,
17722                       * and there are no errors allow the ppr to
17723                       * proceed forward instead of setting it for
17724                       * user review again.
17725                       */
17726                      l_request_status := REQ_STATUS_PAY_CRTD;
17727 
17728                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17729                      print_debuginfo(l_module_name, 'Payment request is '
17730                          || 're-entering payment creation and all payments '
17731                          || 'are valid. User need not review pmts again.'
17732                          );
17733 
17734                      print_debuginfo(l_module_name, 'Setting payment '
17735                          || 'request status to '
17736                          || l_request_status
17737                          || '.'
17738                          );
17739 		      END IF;
17740 
17741                  ELSE
17742 
17743 
17744                      /*
17745                       * If review proposed payments flag is set, then
17746                       * move successful payment requests also to
17747                       * 'pending review' status.
17748                       */
17749                      l_request_status := REQ_STATUS_USER_REVW;
17750                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17751                      print_debuginfo(l_module_name, 'Review proposed payments '
17752                          || 'flag has been set. Setting status of successful '
17753                          || 'request to pending review.');
17754 		     END IF;
17755                  END IF;
17756 
17757              ELSE
17758 
17759                  /* set the status of the payment request to pmts created */
17760                  l_request_status := REQ_STATUS_PAY_CRTD;
17761 
17762              END IF;
17763 
17764 	     --bug 13854619
17765 		 /*
17766 		  * Update the status of the payment request.
17767 		  */
17768 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17769 		 print_debuginfo(l_module_name, 'Updating status of payment request '
17770 		    || p_payreq_id || ' to ' || l_request_status || '.');
17771 		 print_debuginfo(l_module_name, 'valid payment flag for the payments in the ppr: '
17772 		     || p_payreq_id || ' is ' || l_validpayment_flag);
17773 		END IF;
17774 
17775 		IF (l_validpayment_flag = 'N') THEN
17776 
17777 		   l_request_status := REQ_STATUS_FAIL_PAY_CR;
17778 		   l_allfailed_flag :='Y';
17779 
17780 		END IF;
17781 
17782          ELSE
17783 
17784              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
17785 
17786                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
17787 
17788                      /*
17789                       * Fix for bug 5209530:
17790                       *
17791                       * If the pmts of a payment request have already
17792                       * been reviewed and the payment request has
17793                       * re-entered the pmt creation flow, then the pmts
17794                       * will again been validated.
17795                       *
17796                       * If all pmts are successful, do not again ask the
17797                       * user to review the payments, instead allow
17798                       * the ppr to proceed formward.
17799                       *
17800                       * For example, when documents of a pmt(s) are
17801                       * dismissed and the pmts have been re-validated,
17802                       * and there are no errors allow the ppr to
17803                       * proceed forward instead of setting it for
17804                       * user review again.
17805                       */
17806                      l_request_status := REQ_STATUS_PAY_CRTD;
17807 
17808                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17809                      print_debuginfo(l_module_name, 'Payment request is '
17810                          || 're-entering payment creation and all payments '
17811                          || 'are valid. User need not review pmts again.'
17812                          );
17813 
17814                      print_debuginfo(l_module_name, 'Setting payment '
17815                          || 'request status to '
17816                          || l_request_status
17817                          || '.'
17818                          );
17819 		      END IF;
17820 
17821                  ELSE
17822 
17823 
17824                      /*
17825                       * If review proposed payments flag is set, then
17826                       * move successful payment requests also to
17827                       * 'pending review' status.
17828                       */
17829                      l_request_status := REQ_STATUS_USER_REVW;
17830                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17831                      print_debuginfo(l_module_name, 'Review proposed payments '
17832                          || 'flag has been set. Setting status of successful '
17833                          || 'request to pending review.');
17834 		     END IF;
17835                  END IF;
17836 
17837              ELSE
17838 
17839                  /* set the status of the payment request to pmts created */
17840                  l_request_status := REQ_STATUS_PAY_CRTD;
17841 
17842              END IF;
17843 
17844          END IF;
17845      ELSIF (p_rej_level = REJ_LVL_NONE) THEN
17846 
17847          IF (l_allsuccess_flag = 'Y') THEN
17848 
17849              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
17850 
17851                  IF (l_orig_req_status = 'RETRY_PAYMENT_CREATION') THEN
17852 
17853                      /*
17854                       * Fix for bug 5209530:
17855                       *
17856                       * If the pmts of a payment request have already
17857                       * been reviewed and the payment request has
17858                       * re-entered the pmt creation flow, then the pmts
17859                       * will again been validated.
17860                       *
17861                       * If all pmts are successful, do not again ask the
17862                       * user to review the payments, instead allow
17863                       * the ppr to proceed formward.
17864                       *
17865                       * For example, when documents of a pmt(s) are
17866                       * dismissed and the pmts have been re-validated,
17867                       * and there are no errors allow the ppr to
17868                       * proceed forward instead of setting it for
17869                       * user review again.
17870                       */
17871                      l_request_status := REQ_STATUS_PAY_CRTD;
17872 
17873                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17874                      print_debuginfo(l_module_name, 'Payment request is '
17875                          || 're-entering payment creation and all payments '
17876                          || 'are valid. User need not review pmts again.'
17877                          );
17878 
17879                      print_debuginfo(l_module_name, 'Setting payment '
17880                          || 'request status to '
17881                          || l_request_status
17882                          || '.'
17883                          );
17884 		      END IF;
17885 
17886                  ELSE
17887 
17888                      l_request_status := REQ_STATUS_USER_REVW;
17889 
17890                  END IF;
17891 
17892              ELSE
17893 
17894                  l_request_status := REQ_STATUS_PAY_CRTD;
17895 
17896              END IF;
17897 
17898          ELSE
17899 
17900              /*
17901               * If control come here, it means that there
17902               * are some payments that failed validation
17903               * and the rejecttion level is set to 'NONE'.
17904               *
17905               * This means that we should not kick back
17906               * the underlying documents back to AP. Instead,
17907               * we should set the PPR status to
17908               * REQ_STATUS_USER_REVW_ERR. This will allow
17909               * the user to review the failed payments
17910               * in the UI and take corrective action.
17911               */
17912              l_request_status := REQ_STATUS_USER_REVW_ERR;
17913 
17914              /*
17915               * Fix for bug 6709700:
17916               *
17917               * By default, when a payment fails validation
17918               * it is set to PAY_STATUS_REJECTED status. This indicates
17919               * a hard failure and the constituent documents of the
17920               * payment will be kicked back to the calling app.
17921               *
17922               * However, when th rejection level is set to NONE,
17923               * the user wishes to review the failed payments.
17924               * Therefore, we should soft-fail the payments
17925               * that fail validation and not kick back the
17926               * underlying documents back to the calling app.
17927               *
17928               * For the soft failure of the ayment, we use
17929               * a separate status - PAY_STATUS_FAIL_VALID.
17930               *
17931               * Update all the payments that are in PAY_STATUS_REJECTED
17932               * status to PAY_STATUS_FAIL_VALID.
17933               */
17934              FOR j in  IBY_PAYGROUP_PUB.pmtTable.payment_id.FIRST ..  IBY_PAYGROUP_PUB.pmtTable.payment_id.LAST LOOP
17935 
17936                  IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(j) = PAY_STATUS_REJECTED) THEN
17937 
17938                      IBY_PAYGROUP_PUB.pmtTable.payment_status(j) :=
17939                          PAY_STATUS_FAIL_VALID;
17940 
17941                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17942                      print_debuginfo(l_module_name, 'Updating payment '
17943                          || IBY_PAYGROUP_PUB.pmtTable.payment_id(j)
17944                          || ' to soft failure status.'
17945                          );
17946                      END IF;
17947                  END IF;
17948 
17949              END LOOP;
17950 
17951          END IF; -- if all success == true
17952 
17953      ELSE
17954 
17955 
17956          print_debuginfo(l_module_name, 'Unknown rejection level: '
17957              || p_rej_level
17958              || '. Aborting payment creation ..',
17959              FND_LOG.LEVEL_UNEXPECTED
17960              );
17961 
17962 
17963          APP_EXCEPTION.RAISE_EXCEPTION;
17964 
17965      END IF;
17966 
17967      /*
17968       * All payments for this payment request have been
17969       * created and stored in a PLSQL table. Now write these
17970       * payments to the database.
17971       */
17972    --  updatePayments(x_paymentTab);
17973      updatePayments;
17974 
17975      /*
17976       * Update the documents table by providing a payment id to
17977       * each document.
17978       */
17979      updateDocsWithPaymentID;
17980 
17981      /*
17982       * If any payments/documents were failed, the IBY_TRANSACTION_
17983       * ERRORS table must be populated with the corresponding error
17984       * messages.
17985       */
17986      IBY_VALIDATIONSETS_PUB.insert_transaction_errors('N', x_docErrorTab,
17987          x_errTokenTab);
17988 
17989 
17990      /*
17991       * Update the status of the payment request.
17992       */
17993      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
17994      print_debuginfo(l_module_name, 'Updating status of payment request '
17995          || p_payreq_id || ' to ' || l_request_status || '.');
17996      END IF;
17997 
17998      UPDATE
17999          iby_pay_service_requests
18000      SET
18001          payment_service_request_status = l_request_status
18002      WHERE
18003          payment_service_request_id = p_payreq_id
18004      ;
18005 
18006      /* Pass back the request status to the caller */
18007      x_return_status := l_request_status;
18008 
18009      /*
18010       * Pass the 'all payments success' and 'all payments
18011       * failed' flags back to the caller.
18012       *
18013       * These flag will be used in raising business events.
18014       */
18015       -- re-written because dataype of flag is changed
18016 
18017      IF (l_allsuccess_flag ='Y') THEN
18018      x_allPmtsSuccessFlag := TRUE;
18019      ELSE
18020      x_allPmtsSuccessFlag := FALSE;
18021      END IF;
18022 
18023 
18024      IF (l_allfailed_flag ='Y') THEN
18025      x_allPmtsFailedFlag := TRUE;
18026      ELSE
18027      x_allPmtsFailedFlag := FALSE;
18028      END IF;
18029 
18030     -- x_allPmtsFailedFlag  := l_allfailed_flag;
18031 
18032      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18033      print_debuginfo(l_module_name, 'EXIT');
18034       END IF;
18035 
18036  EXCEPTION
18037 
18038      WHEN OTHERS THEN
18039 
18040          print_debuginfo(l_module_name, 'Fatal: Exception when updating '
18041              || 'payment request/payment/document status after payment '
18042              || 'creation. All changes will be rolled back. Payment request '
18043              || 'id is ' || p_payreq_id, FND_LOG.LEVEL_UNEXPECTED);
18044          print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
18045              FND_LOG.LEVEL_UNEXPECTED);
18046          print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
18047              FND_LOG.LEVEL_UNEXPECTED);
18048 
18049 
18050          /*
18051           * Propogate exception to caller.
18052           */
18053          RAISE;
18054 
18055  END performDBUpdates;
18056 
18057 /*--------------------------------------------------------------------
18058  | NAME:
18059  |     applyPaymentValidationSets
18060  |
18061  | PURPOSE:
18062  |     Invokes the validation sets applicable to every payment. The
18063  |     status of the payment will be set to 'validation failed' if
18064  |     the payment fails any invoked validation.
18065  |
18066  |
18067  | PARAMETERS:
18068  |     IN
18069  |
18070  |     OUT
18071  |
18072  |
18073  | RETURNS:
18074  |
18075  | NOTES:
18076  |
18077  *---------------------------------------------------------------------*/
18078  PROCEDURE applyPaymentValidationSets(
18079      p_payment_request_id   IN IBY_PAY_SERVICE_REQUESTS.
18080                                    payment_service_request_id%TYPE,
18081 
18082      l_trx_valid_index  IN BINARY_INTEGER,
18083      x_docErrorTab   IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
18084      x_errTokenTab   IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
18085      )
18086  IS
18087 
18088  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
18089                                              '.applyPaymentValidationSets';
18090  l_valSetsTab            paymentValSetsTab;
18091  l_val_set_index         VARCHAR2(4000);
18092  l_val_sets_count        NUMBER := 0;
18093  l_stmt        VARCHAR2(200);
18094  l_result      NUMBER := 0;
18095  l_check_val   BOOLEAN := FALSE;
18096  l_error_code    VARCHAR2(100);
18097  l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
18098 
18099 
18100 
18101 
18102  int_bnk_index      VARCHAR2(2000);
18103  l_int_bank_acct_id               CE_BANK_ACCOUNTS.bank_account_id%TYPE;
18104  l_country                        CE_BANK_BRANCHES_V.country%TYPE;
18105  l_bank_home_country              CE_BANK_BRANCHES_V.bank_home_country%TYPE;
18106  l_allow_zero_pmt_flag            CE_BANK_ACCOUNTS.zero_amount_allowed%TYPE;
18107 
18108  l_profile_id                     IBY_PAYMENT_PROFILES.payment_profile_id%TYPE;
18109  l_payment_format_cd              IBY_PAYMENT_PROFILES.payment_format_code%TYPE;
18110  l_bepid                          IBY_PAYMENT_PROFILES.bepid%TYPE;
18111  l_transmit_protocol_cd           IBY_PAYMENT_PROFILES.transmit_protocol_code%TYPE;
18112 
18113  /*
18114   * Pick up all validation sets applicable to a particular payment.
18115   */
18116 
18117      CURSOR  c_pmt_val_sets(p_payment_id IBY_PAYMENTS_ALL.payment_id%TYPE,
18118 		      p_payment_method_code               IBY_PAYMENTS_ALL.payment_method_code%TYPE,
18119  	              p_int_bank_acct_id                  IBY_PAYMENTS_ALL.internal_bank_account_id%TYPE,
18120 		      p_payment_format_code               IBY_PAYMENT_PROFILES.payment_format_code%TYPE,
18121  	              p_bepid                             IBY_PAYMENT_PROFILES.bepid%TYPE,
18122  	              p_transmit_protocol_code            IBY_PAYMENT_PROFILES.transmit_protocol_code%TYPE,
18123  	              p_country                           CE_BANK_BRANCHES_V.country%TYPE)
18124  IS
18125  SELECT DISTINCT
18126      val_asgn.validation_assignment_id,
18127      val_asgn.val_assignment_entity_type,
18128      val.validation_set_display_name,
18129      val.validation_set_code,
18130      val.validation_code_package,
18131      val.validation_code_entry_point
18132  FROM
18133      IBY_VALIDATION_SETS_VL    val,
18134      IBY_VAL_ASSIGNMENTS       val_asgn
18135 
18136  WHERE
18137      val.validation_set_code   = val_asgn.validation_set_code
18138      AND val.validation_level_code = 'PAYMENT'
18139      AND (val_asgn.val_assignment_entity_type    = 'METHOD'
18140               AND val_asgn.assignment_entity_id  =
18141                       p_payment_method_code
18142           OR val_asgn.val_assignment_entity_type = 'INTBANKACCOUNT'
18143               AND val_asgn.assignment_entity_id  =
18144                   to_char(p_int_bank_acct_id)
18145           OR val_asgn.val_assignment_entity_type = 'FORMAT'
18146               AND val_asgn.assignment_entity_id  =
18147                   p_payment_format_code
18148           OR val_asgn.val_assignment_entity_type = 'BANK'
18149               AND val_asgn.assignment_entity_id  =
18150                   to_char(p_bepid)
18151           OR val_asgn.val_assignment_entity_type = 'TRANSPROTOCOL'
18152               AND val_asgn.assignment_entity_id  =
18153                  p_transmit_protocol_code
18154           )
18155      AND NVL(val_asgn.inactive_date, sysdate+1) > sysdate
18156 
18157      /*
18158       * Fix for bug 4997133:
18159       *
18160       * Pick up all applicable validation sets that match
18161       * the payment method and country code on this payment.
18162       * (if payment method /country code on validation
18163       * set is null, it means that the validation set is
18164       * applicable to all payment methods / countries).
18165       */
18166      AND (NVL(p_payment_method_code, '0') =
18167              NVL(val_asgn.payment_method_code, '0') OR
18168              val_asgn.payment_method_code IS NULL
18169          )
18170      AND (p_country= val_asgn.territory_code OR
18171          val_asgn.territory_code IS NULL
18172          )
18173      ;
18174 
18175 
18176  BEGIN
18177 
18178      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18179  print_debuginfo(l_module_name, 'ENTER');
18180      END IF;
18181 
18182 
18183      /*
18184       * Performance Fix:
18185       *
18186       * Instead of calling IBY_BUILD_UTILS_PKG.inactivateOldErrors(..)
18187       * once per payment, delete all the error messages linked
18188       * to the payments of this PPR, and reset the payment status
18189       * of the failed payments in one shot.
18190       */
18191 
18192       IF(resetErrtbl.EXISTS(p_payment_request_id))  THEN
18193 	  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18194        print_debuginfo(l_module_name, 'ResetPaymentErrors API is already called for this PPR');
18195 	   END IF;
18196 
18197       ELSE
18198 
18199        IBY_BUILD_UTILS_PKG.resetPaymentErrors(p_payment_request_id);
18200 
18201        /* cache the call */
18202        resetErrtbl(p_payment_request_id) := p_payment_request_id;
18203 
18204       END IF;
18205 
18206 
18207          /*
18208           * Pick up the validation sets applicable to this
18209           * payment.
18210           */
18211 
18212     int_bnk_index := Nvl(IBY_PAYGROUP_PUB.pmtTable.INTERNAL_BANK_ACCOUNT_ID(l_trx_valid_index),-999)||'$';
18213 	IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18214     print_debuginfo(l_module_name, 'int_bnk_index-'||int_bnk_index);
18215 	END IF;
18216 
18217 		IF (int_bank_acct_tbl.EXISTS(int_bnk_index)) THEN
18218 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18219  		print_debuginfo(l_module_name, 'Getting Data from Cache For Int bank acct Id: ' || int_bnk_index);
18220 		END IF;
18221 
18222                 l_country		 :=  int_bank_acct_tbl(int_bnk_index).country;
18223  	        l_bank_home_country	 :=  int_bank_acct_tbl(int_bnk_index).bank_home_country;
18224                 l_allow_zero_pmt_flag    :=  int_bank_acct_tbl(int_bnk_index).allow_zero_pmt_flag;
18225 
18226  	        ELSE
18227 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18228           print_debuginfo(l_module_name ,'Data not found in cache, hitting DB again');
18229 		  END IF;
18230 
18231                 BEGIN
18232                     SELECT cba.bank_account_id,
18233                      cb.country,
18234                      cb.bank_home_country,
18235 		             cba.zero_amount_allowed
18236                      INTO l_int_bank_acct_id,
18237                      l_country,
18238                      l_bank_home_country,
18239 		     l_allow_zero_pmt_flag
18240                      FROM CE_BANK_ACCOUNTS cba, CE_BANK_BRANCHES_V cb
18241                      WHERE cba.bank_branch_id = cb.branch_party_id
18242                      AND  cba.bank_account_id = IBY_PAYGROUP_PUB.pmtTable.INTERNAL_BANK_ACCOUNT_ID(l_trx_valid_index);
18243 
18244 
18245                 EXCEPTION
18246                 WHEN NO_DATA_FOUND THEN
18247 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18248                 print_debuginfo(l_module_name, 'Exception No Data Found For Int Bank Account Id: ' ||int_bnk_index);
18249 				END IF;
18250                             l_int_bank_acct_id := null;
18251                             l_country := null;
18252                             l_bank_home_country := null;
18253 			    l_allow_zero_pmt_flag := null;
18254                 END;
18255                 int_bank_acct_tbl(int_bnk_index).internal_bank_account_id := l_int_bank_acct_id;
18256                 int_bank_acct_tbl(int_bnk_index).country 		     := l_country;
18257                 int_bank_acct_tbl(int_bnk_index).bank_home_country 	     := l_bank_home_country;
18258 				int_bank_acct_tbl(int_bnk_index).allow_zero_pmt_flag :=l_allow_zero_pmt_flag; --Bug 14519049
18259 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18260                 print_debuginfo(l_module_name, 'After caching the data for int bank id -'||int_bnk_index);
18261                 print_debuginfo(l_module_name, 'Data from cache -'||int_bank_acct_tbl(int_bnk_index).internal_bank_account_id);
18262                 print_debuginfo(l_module_name, 'Country -'||int_bank_acct_tbl(int_bnk_index).country);
18263                 print_debuginfo(l_module_name, 'After caching the data -'||int_bank_acct_tbl(int_bnk_index).bank_home_country );
18264 				print_debuginfo(l_module_name, 'Allow zero payments flag -'||int_bank_acct_tbl(int_bnk_index).allow_zero_pmt_flag ); --Bug 14519049
18265 END IF;
18266 
18267 		END IF;
18268 
18269 
18270 /* Bug: 9452724*/
18271              IF (UPPER(l_allow_zero_pmt_flag) <> 'Y' AND
18272                 IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index) <> PAY_STATUS_REMOVED AND
18273                 IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_valid_index) = 0 ) THEN
18274 
18275                  IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index)
18276                      := PAY_STATUS_REJECTED;
18277 
18278                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18279 		 print_debuginfo(l_module_name, 'Failed payment '
18280                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index)
18281                      || ' because payment amount '
18282                      || IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_valid_index)
18283                      || ' is zero. Zero payments not'
18284                      || ' allowed for the bank account'
18285                      );
18286 
18287 		 END IF;
18288 
18289                  l_error_code := 'IBY_ACCT_ZERO_PMT_NOT_ALLD';
18290                  FND_MESSAGE.set_name('IBY', l_error_code);
18291 
18292 			  /* AWT Enh 16296267 */
18293 			IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_valid_index) = 'Y' ) THEN
18294 			  l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_valid_index);
18295                 IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) then
18296                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18297                     print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
18298                    END IF;
18299                 ELSE
18300                   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18301                     print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
18302                      ' to Invalid Payee  Awt List');
18303                    END IF;
18304                   l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(l_trx_valid_index);
18305                 END IF;
18306             END IF;
18307 
18308                  /*
18309                   * Once we fail a payment, we need to create
18310                   * an error record and insert this record
18311                   * into the errors table.
18312                   */
18313                  IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
18314                      IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index),
18315                      IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index),
18316                      l_error_code,
18317                      FND_MESSAGE.get,
18318                      l_doc_err_rec
18319                      );
18320 
18321                  IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
18322                      l_doc_err_rec, x_docErrorTab, x_errTokenTab);
18323 
18324                  /* fail the docs of this payment */
18325                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index),
18326                              DOC_STATUS_PAY_VAL_FAIL,
18327                              x_docErrorTab, x_errTokenTab);
18328 
18329              END IF;
18330 
18331 
18332 /* Bug: 9452724**/
18333 
18334 
18335 		IF (l_profile_format_tab.EXISTS(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index) ) ) THEN
18336 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18337 		  print_debuginfo(l_module_name, 'Getting Data from Cache For Profile Id: ' || IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index));
18338 		  END IF;
18339 
18340                   l_payment_format_cd    :=   l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).payment_format_cd;
18341  	          l_bepid                :=   l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).bepid;
18342  	          l_transmit_protocol_cd :=   l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).transmit_protocol_cd;
18343 
18344  	        ELSE
18345 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18346  	        print_debuginfo(l_module_name, 'Getting Data from DB For Profile Id: ' || IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index));
18347 			END IF;
18348  	            BEGIN
18349  	                 SELECT ipp.payment_profile_id,
18350  	                    ipp.payment_format_code, ipp.bepid, ipp.transmit_protocol_code
18351  	                 INTO l_profile_id,l_payment_format_cd,l_bepid,l_transmit_protocol_cd
18352  	                 FROM IBY_PAYMENT_PROFILES ipp
18353  	                 WHERE ipp.payment_profile_id = IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index) ;
18354 
18355  	            EXCEPTION
18356  	                       WHEN NO_DATA_FOUND THEN
18357 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18358  	                   print_debuginfo(l_module_name, 'Exception No Data Found Occured For Profile Id: ' || IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index));
18359 					   END IF;
18360  	                         l_profile_id := null;
18361  	                         l_payment_format_cd    := null;
18362  	                         l_bepid := null;
18363  	                         l_transmit_protocol_cd := null;
18364  	            END;
18365 				IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18366  	            print_debuginfo(l_module_name, 'Assigning the values in Cache For Profile Id: ' || IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index));
18367 				END IF;
18368  	            l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).profile_id           := l_profile_id;
18369  	            l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).payment_format_cd    := l_payment_format_cd;
18370  	            l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).bepid                := l_bepid;
18371  	            l_profile_format_tab(IBY_PAYGROUP_PUB.pmtTable.PAYMENT_PROFILE_ID(l_trx_valid_index)).transmit_protocol_cd := l_transmit_protocol_cd;
18372 
18373  	        END IF;
18374 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18375  	           print_debuginfo(l_module_name, 'Before doing a bulk insert to the cursor');
18376  	          -- print_debuginfo(l_module_name, 'Before doing a bulk insert pmt_method_cd is ' 	 || l_docs_tab(i).pmt_method_cd);
18377  	           print_debuginfo(l_module_name, 'Before doing a bulk insert int_bank_acct_id is ' 	 ||IBY_PAYGROUP_PUB.pmtTable.INTERNAL_BANK_ACCOUNT_ID(l_trx_valid_index));
18378  	           print_debuginfo(l_module_name, 'Before doing a bulk insert l_payment_format_cd is '||Nvl(l_payment_format_cd,0));
18379  	           print_debuginfo(l_module_name, 'Before doing a bulk insert l_bepid is'||Nvl(l_bepid,0));
18380  	           print_debuginfo(l_module_name, 'Before doing a bulk insert l_transmit_protocol_cd is'||l_transmit_protocol_cd);
18381  	           print_debuginfo(l_module_name, 'Before doing a bulk insert l_country is'||l_country);
18382             print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.PAYMENT_METHOD_CODE(l_trx_valid_index):'||IBY_PAYGROUP_PUB.pmtTable.PAYMENT_METHOD_CODE(l_trx_valid_index));
18383 			END IF;
18384 
18385         l_val_set_index := 'PAYMENT'||'$'||IBY_PAYGROUP_PUB.pmtTable.PAYMENT_METHOD_CODE(l_trx_valid_index)||'$'||IBY_PAYGROUP_PUB.pmtTable.INTERNAL_BANK_ACCOUNT_ID(l_trx_valid_index)||'$'||l_payment_format_cd||'$'||l_bepid;
18386         l_val_set_index := l_val_set_index||'$'||l_transmit_protocol_cd||'$'||l_country;
18387         IF (val_sets_outer_tbl.EXISTS(l_val_set_index)) THEN
18388         l_valSetsTab := val_sets_outer_tbl(l_val_set_index).val_sets_tbl;
18389         l_val_sets_count := val_sets_outer_tbl(l_val_set_index).val_set_count;
18390         ELSE
18391 	 OPEN  c_pmt_val_sets(IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index),
18392 			      IBY_PAYGROUP_PUB.pmtTable.PAYMENT_METHOD_CODE(l_trx_valid_index),
18393 			      IBY_PAYGROUP_PUB.pmtTable.INTERNAL_BANK_ACCOUNT_ID(l_trx_valid_index),
18394 			      l_payment_format_cd,
18395 			      l_bepid,
18396 			      l_transmit_protocol_cd,
18397 			      l_country);
18398 
18399          FETCH c_pmt_val_sets BULK COLLECT INTO l_valSetsTab;
18400          CLOSE c_pmt_val_sets;
18401 
18402              val_sets_outer_tbl(l_val_set_index).val_sets_tbl := l_valSetsTab;
18403              val_sets_outer_tbl(l_val_set_index).val_set_count := l_val_sets_count;
18404         END IF;
18405 
18406 
18407 
18408          IF (l_valSetsTab.COUNT = 0 OR IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index) = PAY_STATUS_REMOVED) THEN
18409 
18410              /*
18411               * Fix for bug 5742548:
18412               *
18413               * If no validation sets are applicable this
18414               * time round, then this payment will pass
18415               * validation.
18416               *
18417               * But it is possible that this payment has
18418               * failed validation earlier, in which cas
18419               * the old errors will still be active against
18420               * this payment.
18421               *
18422               * Inactivate the old errors so that the UI
18423               * correctly shows that there are no active
18424               * validation errors against this payment
18425               * at this time.
18426               */
18427              --IBY_BUILD_UTILS_PKG.inactivateOldErrors(
18428              --    x_paymentTab(i).payment_id,
18429              --    TRXN_TYPE_PMT
18430              --    );
18431 
18432              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18433 		print_debuginfo(l_module_name, 'No validation sets were '
18434                  || 'linked or the payment is removed already '
18435                  || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index)
18436                  || 'so skipping payment '
18437                  || 'validations for this payment..');
18438 
18439              print_debuginfo(l_module_name, '+-------------------------+');
18440 	     END IF;
18441 
18442          ELSE
18443 
18444              FOR j in l_valSetsTab.FIRST .. l_valSetsTab.LAST LOOP
18445 
18446                  /*
18447                   * Fix for bug 5440434:
18448                   *
18449                   * Before doing any validations, set any
18450                   * existing validation error messages that
18451                   * exist against this payment to 'inactive'
18452                   * status in the IBY_TRANSACTION_ERRORS table.
18453                   *
18454                   * Unless we do this, the old errors will
18455                   * continue to show up against this payment
18456                   * in the IBY UI even if the payment is validated
18457                   * successfully this time round.
18458                   */
18459                  --IBY_BUILD_UTILS_PKG.inactivateOldErrors(
18460                  --    x_paymentTab(i).payment_id,
18461                  --    TRXN_TYPE_PMT
18462                  --    );
18463 
18464                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18465  print_debuginfo(l_module_name, 'Applicable validation set ('
18466                      || l_valSetsTab(j).val_assign_entity_type
18467                      || ') : '
18468                      || l_valSetsTab(j).val_set_name
18469                      );
18470 	        END IF;
18471                  /*
18472                   * Dynamically call the validation set applicable
18473                   * to the current payment.
18474                   */
18475                  l_stmt := 'CALL '
18476                                || l_valSetsTab(j).val_code_pkg
18477                                || '.'
18478                                || l_valSetsTab(j).val_code_entry_pt
18479                                || '(:1,:2,:3,:4,:5)';
18480 
18481                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18482 			print_debuginfo(l_module_name, 'Calling ' || l_stmt);
18483 		 END IF;
18484 
18485                  EXECUTE IMMEDIATE (l_stmt) USING
18486                      IN l_valSetsTab(j).val_assign_id,
18487                      IN l_valSetsTab(j).val_set_code,
18488                      IN IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index),
18489                      IN 'N',
18490                      OUT l_result;
18491 
18492                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18493  print_debuginfo(l_module_name, 'Finished executing '
18494                      || l_stmt);
18495 
18496                  print_debuginfo(l_module_name, 'Result: '
18497                      || l_result);
18498                  END IF;
18499                  /*
18500                   * If payment fails validation, then:
18501                   * 1. Set the status of the payment to failed
18502                   * 2. Fail all docs of this payment
18503                   */
18504                  IF (l_result <> 0) THEN
18505 
18506 
18507                      /*
18508                       * If a payment has not been failed before,
18509                       * fail the payment and its child documents.
18510                       *
18511                       * Otherwise, skip this step.
18512                       */
18513                      IF (IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index) <> PAY_STATUS_REJECTED) THEN
18514 
18515                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18516  print_debuginfo(l_module_name, 'Payment '
18517                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index)
18518                              || ' failed validation.');
18519                          END IF;
18520                          IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index)
18521                              := PAY_STATUS_REJECTED;
18522                           l_invalid_payee_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_valid_index);
18523 
18524                           IF (l_payeeTab.EXISTS(l_invalid_payee_index)) then
18525                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18526                               print_debuginfo(l_module_name, 'Payee already in invalid payee list');
18527                              END IF;
18528                           ELSE
18529                             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18530                               print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_index||
18531                                ' to Invalid Payee List');
18532                              END IF;
18533                             l_payeeTab(l_invalid_payee_index) := IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index);
18534                           END IF;
18535 
18536 						  /* AWT Enh 16296267 */
18537 						IF (IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_valid_index) = 'Y' ) THEN
18538 			              l_invalid_payee_awt_index:= IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_valid_index);
18539                           IF (l_payeeAwt.EXISTS(l_invalid_payee_awt_index)) then
18540                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18541                               print_debuginfo(l_module_name, 'Payee already in invalid payee Awt list');
18542                              END IF;
18543                           ELSE
18544                             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18545                               print_debuginfo(l_module_name, 'Adding Payee:'||l_invalid_payee_awt_index||
18546                                ' to Invalid Payee  Awt List');
18547                              END IF;
18548                             l_payeeAwt(l_invalid_payee_awt_index) := IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(l_trx_valid_index);
18549                           END IF;
18550                         END IF;
18551 
18552                          /*
18553                           * Validation error messages against the payment
18554                           * will be handled by the validation set itself.
18555                           * So no need to create an error record for the
18556                           * payment here.
18557                           */
18558 
18559                          /*
18560                           * For the failed payment, set the status of its
18561                           * child documents to failed as well.
18562                           */
18563 
18564                          failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index),
18565                              DOC_STATUS_PAY_VAL_FAIL,
18566                              x_docErrorTab, x_errTokenTab);
18567 
18568                      ELSE
18569 
18570                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18571  print_debuginfo(l_module_name, 'Payment '||  IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_valid_index)
18572                              || ' has already failed validation.'
18573                              || '. No need to fail this payment and '
18574                              || 'its child documents again.'
18575                              );
18576 			END IF;
18577                      END IF; -- if l_check_val = FALSE
18578 
18579                 --Bug 10252231- Due to below code, failed payment status is reverted back if it passes
18580 		-- subsequent validation.
18581                /*  ELSE
18582                  IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_valid_index) := PAY_STATUS_CREATED; */
18583                  END IF; -- result <> 0
18584 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18585                  print_debuginfo(l_module_name, '+-------------------------+');
18586 				 END IF;
18587 
18588              END LOOP; -- for each val set applicable to this payment
18589 
18590          END IF; -- if count of val sets <> 0
18591 
18592 
18593 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18594      print_debuginfo(l_module_name, 'EXIT');
18595 	 END IF;
18596  EXCEPTION
18597    WHEN OTHERS THEN
18598    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
18599                  FND_LOG.LEVEL_UNEXPECTED);
18600              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
18601                  FND_LOG.LEVEL_UNEXPECTED);
18602    print_debuginfo(l_module_name, l_module_name||':Exception while performing applyPaymentValidationSets');
18603    RAISE;
18604 END applyPaymentValidationSets;
18605 
18606 /*--------------------------------------------------------------------
18607  | NAME:
18608  |     raiseBizEvents
18609  |
18610  | PURPOSE:
18611  |     Raises business events (if necessary) to inform the calling
18612  |     app of failed documents (which were failed because their payments
18613  |     were failed).
18614  |
18615  | PARAMETERS:
18616  |     IN
18617  |
18618  |     OUT
18619  |
18620  |
18621  | RETURNS:
18622  |
18623  | NOTES:
18624  |
18625  *---------------------------------------------------------------------*/
18626  PROCEDURE raiseBizEvents(
18627      p_payreq_id          IN            VARCHAR2,
18628      p_cap_payreq_cd      IN            VARCHAR2,
18629      p_cap_id             IN            NUMBER,
18630      p_rej_level          IN            VARCHAR2,
18631      p_review_pmts_flag   IN            VARCHAR2,
18632      p_allPmtsSuccessFlag IN            BOOLEAN,
18633      p_allPmtsFailedFlag  IN            BOOLEAN
18634      )
18635  IS
18636 
18637  l_module_name   CONSTANT VARCHAR2(200) := G_PKG_NAME || '.raiseBizEvents';
18638  l_xml_clob      CLOB;
18639  l_event_name    VARCHAR2(200);
18640  l_event_key     NUMBER;
18641  l_param_names   JTF_VARCHAR2_TABLE_300;
18642  l_param_vals    JTF_VARCHAR2_TABLE_300;
18643 
18644  l_return_status  VARCHAR2(500);
18645  l_rej_doc_id_list     IBY_DISBURSE_UI_API_PUB_PKG.docPayIDTab;
18646  l_rej_doc_status_list IBY_DISBURSE_UI_API_PUB_PKG.docPayStatusTab;
18647 
18648  BEGIN
18649 
18650      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18651      print_debuginfo(l_module_name, 'ENTER');
18652      print_debuginfo(l_module_name, 'Payreq id: '
18653          || p_payreq_id);
18654      END IF;
18655      /*
18656       * Print the rejection level system option
18657       */
18658      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18659      print_debuginfo(l_module_name, 'Rejection level system option: '
18660          || p_rej_level);
18661      END IF;
18662      /*
18663       * These tables are used to pass event keys
18664       * to the business event.
18665       */
18666      l_param_names := JTF_VARCHAR2_TABLE_300();
18667      l_param_vals  := JTF_VARCHAR2_TABLE_300();
18668 
18669      /*
18670       * The event key uniquely identifies a specific
18671       * occurance of an event. Therefore, it should be
18672       * a sequence number.
18673       */
18674      SELECT IBY_EVENT_KEY_S.nextval INTO l_event_key
18675      FROM DUAL;
18676 
18677      IF (p_rej_level = REJ_LVL_REQUEST) THEN
18678 
18679          /*
18680           * For request level rejections, even if one
18681           * payment within the request fails, then the
18682           * entire payment request should be failed.
18683           */
18684 
18685          IF (p_allPmtsSuccessFlag <> TRUE) THEN
18686 
18687              /*
18688               * Invoke the callout API with the payment request id.
18689               * This API should trigger the calling application to
18690               * fail the payment request and all it's associated
18691               * docs.
18692               */
18693              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18694              print_debuginfo(l_module_name, 'Going to invoke API call '
18695                  || 'remove_payment_request()');
18696 	     END IF;
18697              /*
18698               * Invoke API to inform calling application
18699               * about the rejected payment request. This API
18700               * will remove all the payments and documents payable
18701               * in this payment request from the processing cycle
18702               * and inform the calling application about this fact.
18703               */
18704              IBY_DISBURSE_UI_API_PUB_PKG.remove_payment_request (
18705                  p_payreq_id,
18706                  l_return_status
18707                  );
18708 
18709              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18710              print_debuginfo(l_module_name, 'Return status of '
18711                  || 'remove_payment_request() API call: '
18712                  || l_return_status
18713                  );
18714 	     END IF;
18715 
18716              IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
18717 
18718 
18719                  print_debuginfo(l_module_name, 'API call did not succeed. '
18720                      || 'Aborting build program .. ',
18721                      FND_LOG.LEVEL_UNEXPECTED
18722                      );
18723 
18724                  APP_EXCEPTION.RAISE_EXCEPTION;
18725 
18726              END IF;
18727 
18728 
18729          ELSE
18730 
18731              /*
18732               * This means all payments were successfully
18733               * created for this payment service request.
18734               *
18735               * Notify the user only of 'review proposed
18736               * payments flag' has been set.
18737               */
18738 
18739              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
18740 
18741                  /*
18742                   * Raise a business event with the payment request id.
18743                   * This business event should trigger the calling app
18744                   * to launch a workflow for the user to review the
18745                   * proposed payments.
18746                   */
18747                  l_event_name :=
18748                      'oracle.apps.iby.buildprogram.validation.notify_user';
18749 
18750                  l_param_names.EXTEND;
18751                  l_param_vals.EXTEND;
18752                  l_param_names(1) := 'calling_app_id';
18753                  l_param_vals(1)  := p_cap_id;
18754 
18755                  l_param_names.EXTEND;
18756                  l_param_vals.EXTEND;
18757                  l_param_names(1) := 'pay_service_request_id';
18758                  l_param_vals(1)  := p_cap_payreq_cd;
18759 
18760                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18761                  print_debuginfo(l_module_name, 'Going to raise biz event '
18762                      || l_event_name);
18763      END IF;
18764                  iby_workflow_pvt.raise_biz_event(l_event_name, l_event_key,
18765                      l_param_names, l_param_vals);
18766 
18767                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18768                  print_debuginfo(l_module_name, 'Raised biz event '
18769                      || l_event_name || ' with key '
18770                      || l_event_key  || '.');
18771      END IF;
18772              ELSE
18773 
18774                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18775                  print_debuginfo(l_module_name, 'Not raising biz event '
18776                      || l_event_name || '. Reason: All payments '
18777                      || 'were valid.');
18778 		     END IF;
18779              END IF;
18780 
18781          END IF;
18782 /* Bug 8209474 */
18783      ELSIF (p_rej_level = REJ_LVL_PAYMENT OR p_rej_level = REJ_LVL_PAYEE) THEN
18784 
18785          /*
18786           * Check if all payments in the request have failed;
18787           * in that case, fail the request and invoke a callout
18788           * API to inform the calling app that all payments (and
18789           * so documents) in the request have been failed.
18790           *
18791           * The calling app should use this information to unlock
18792           * those documents and re-submit them in a new request
18793           * after making suitable changed after making suitable
18794           * changes.
18795           */
18796          IF (p_allPmtsFailedFlag = TRUE) THEN
18797 
18798              /*
18799               * Invoke the callout API with the payment request id.
18800               * This API should trigger the calling application to
18801               * fail the payment request and all it's associated
18802               * docs.
18803               */
18804              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18805              print_debuginfo(l_module_name, 'Going to invoke API call '
18806                  || 'remove_payment_request()');
18807 		      END IF;
18808 
18809              /*
18810               * Invoke API to inform calling application
18811               * about the rejected payment request. This API
18812               * will remove all the documents payable in this
18813               * payment request from the processing cycle and
18814               * inform the calling application about this fact.
18815               */
18816              IBY_DISBURSE_UI_API_PUB_PKG.remove_payment_request (
18817                  p_payreq_id,
18818                  l_return_status
18819                  );
18820 
18821              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18822              print_debuginfo(l_module_name, 'Return status of '
18823                  || 'remove_payment_request() API call: '
18824                  || l_return_status
18825                  );
18826 		      END IF;
18827 
18828              IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
18829 
18830 
18831                  print_debuginfo(l_module_name, 'API call did not succeed. '
18832                      || 'Aborting build program .. ',
18833                      FND_LOG.LEVEL_UNEXPECTED
18834                      );
18835 
18836                  APP_EXCEPTION.RAISE_EXCEPTION;
18837 
18838              END IF;
18839 
18840          ELSE
18841 
18842              /*
18843               * If at lease one payment has succeeded and the
18844               * 'review proposed payments' flag is set to 'Y',
18845               * then, we must raise the notify user business
18846               * event.
18847               */
18848              l_event_name :=
18849                  'oracle.apps.iby.buildprogram.validation.notify_user';
18850 
18851              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18852              print_debuginfo(l_module_name, 'Going to raise biz event '
18853                  || l_event_name);
18854              END IF;
18855 
18856              /*
18857               * Raise this business event only if the 'review
18858               * proposed payments' flag is set to 'Y'.
18859               */
18860              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
18861 
18862                  /*
18863                   * Raise a business event with the payment request id.
18864                   * This business event should trigger the calling app
18865                   * to launch a workflow for the user to review the
18866                   * proposed payments.
18867                   */
18868                  l_event_name :=
18869                      'oracle.apps.iby.buildprogram.validation.notify_user';
18870 
18871                  l_param_names.EXTEND;
18872                  l_param_vals.EXTEND;
18873                  l_param_names(1) := 'calling_app_id';
18874                  l_param_vals(1)  := p_cap_id;
18875 
18876                  l_param_names.EXTEND;
18877                  l_param_vals.EXTEND;
18878                  l_param_names(1) := 'pay_service_request_id';
18879                  l_param_vals(1)  := p_cap_payreq_cd;
18880 
18881                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18882                  print_debuginfo(l_module_name, 'Going to raise biz event '
18883                      || l_event_name);
18884      END IF;
18885                  iby_workflow_pvt.raise_biz_event(l_event_name, l_event_key,
18886                      l_param_names, l_param_vals);
18887 
18888                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18889                  print_debuginfo(l_module_name, 'Raised biz event '
18890                      || l_event_name || ' with key '
18891                      || l_event_key  || '.');
18892      END IF;
18893              END IF; -- review payments flag == 'Y'
18894 
18895                  /*
18896                   * Invoke a callout API with the list of failed
18897                   * documents (derived from the payments). This
18898                   * API call should trigger the calling app
18899                   * to fail these docs.
18900                   */
18901                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18902                  print_debuginfo(l_module_name, 'Going to invoke API '
18903                      || 'remove_documents_payable()');
18904      END IF;
18905                  /*
18906                   * Select all docs that:
18907                   * 1. Have the given pay req id
18908                   * 2. Are not in 'payments_created' status
18909                   * 3. Were updated in the process of payment creation
18910                   *    (some docs might have failed earlier in document
18911                   *    validation flow. We don't want to pick them up)
18912                   */
18913                  getRejectedDocs(p_payreq_id, l_rej_doc_id_list,
18914                      l_rej_doc_status_list);
18915 
18916                  IF (l_rej_doc_id_list.COUNT = 0) THEN
18917 
18918                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18919                      print_debuginfo(l_module_name, 'Not invoking API '
18920                          || 'remove_documents_payable() because all '
18921                          || 'payments were successfully '
18922                          || 'created. So no failed documents '
18923                          || 'to notify.'
18924                          );
18925 		     END IF;
18926                  ELSE
18927 
18928                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18929                      print_debuginfo(l_module_name, 'Printing list of failed '
18930                          || 'documents');
18931 		     END IF;
18932                      FOR i IN l_rej_doc_id_list.FIRST ..
18933                          l_rej_doc_id_list.LAST LOOP
18934 
18935                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18936                          print_debuginfo(l_module_name, 'Doc id: '
18937                              || l_rej_doc_id_list(i)
18938                              || ', doc status: '
18939                              || l_rej_doc_status_list(i)
18940                              );
18941                         END IF;
18942                      END LOOP;
18943 
18944                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18945                      print_debuginfo(l_module_name, 'Going to invoke '
18946                          || 'remove_documents_payable() API'
18947                          );
18948 		     END IF;
18949                      /*
18950                       * Invoke API to inform calling application
18951                       * about the rejected documents.
18952                       */
18953                      IBY_DISBURSE_UI_API_PUB_PKG.remove_documents_payable (
18954                          l_rej_doc_id_list,
18955                          l_rej_doc_status_list,
18956                          l_return_status
18957                          );
18958 
18959                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
18960                      print_debuginfo(l_module_name, 'Return status of '
18961                          || 'remove_documents_payable() API call: '
18962                          || l_return_status
18963                          );
18964 		     END IF;
18965                      IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
18966 
18967 
18968                          print_debuginfo(l_module_name, 'API call did not '
18969                              || 'succeed. Aborting build program .. ',
18970                              FND_LOG.LEVEL_UNEXPECTED
18971                              );
18972 
18973 
18974                          APP_EXCEPTION.RAISE_EXCEPTION;
18975 
18976                      END IF;
18977 
18978                  END IF; -- if rejected doc count != 0
18979 
18980          END IF; -- all payments failed flag = TRUE
18981 
18982      ELSIF (p_rej_level = REJ_LVL_NONE) THEN
18983 
18984          IF (p_allPmtsSuccessFlag <> TRUE) THEN
18985 
18986              /*
18987               * Raise a business event with the payment request id.
18988               * This business event should trigger the calling app
18989               * to launch a workflow for the user to review the
18990               * proposed payments.
18991               */
18992              l_event_name :=
18993                  'oracle.apps.iby.buildprogram.validation.notify_user_error';
18994 
18995              l_param_names.EXTEND;
18996              l_param_vals.EXTEND;
18997              l_param_names(1) := 'calling_app_id';
18998              l_param_vals(1)  := p_cap_id;
18999 
19000              l_param_names.EXTEND;
19001              l_param_vals.EXTEND;
19002              l_param_names(1) := 'pay_service_request_id';
19003              l_param_vals(1)  := p_cap_payreq_cd;
19004 
19005              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19006              print_debuginfo(l_module_name, 'Going to raise biz event '
19007                  || l_event_name);
19008 	     END IF;
19009              iby_workflow_pvt.raise_biz_event(l_event_name, l_event_key,
19010                  l_param_names, l_param_vals);
19011 
19012              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19013              print_debuginfo(l_module_name, 'Raised biz event '
19014                  || l_event_name || ' with key '
19015                  || l_event_key  || '.');
19016 	     END IF;
19017          ELSE
19018 
19019              /*
19020               * This means that all payments were successfully
19021               * created for this payment service request.
19022               */
19023 
19024              IF (UPPER(p_review_pmts_flag) = 'Y') THEN
19025 
19026                  /*
19027                   * Raise a business event with the payment request id.
19028                   * This business event should trigger the calling app
19029                   * to launch a workflow for the user to review the
19030                   * proposed payments.
19031                   */
19032 
19033                  l_event_name :=
19034                      'oracle.apps.iby.buildprogram.validation.notify_user';
19035 
19036                  l_param_names.EXTEND;
19037                  l_param_vals.EXTEND;
19038                  l_param_names(1) := 'calling_app_id';
19039                  l_param_vals(1)  := p_cap_id;
19040 
19041                  l_param_names.EXTEND;
19042                  l_param_vals.EXTEND;
19043                  l_param_names(1) := 'pay_service_request_id';
19044                  l_param_vals(1)  := p_cap_payreq_cd;
19045 
19046                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19047                  print_debuginfo(l_module_name, 'Going to raise biz event '
19048                      || l_event_name);
19049 		 END IF;
19050                  iby_workflow_pvt.raise_biz_event(l_event_name, l_event_key,
19051                      l_param_names, l_param_vals);
19052 
19053                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19054                  print_debuginfo(l_module_name, 'Raised biz event '
19055                      || l_event_name || ' with key '
19056                      || l_event_key  || '.');
19057 		 END IF;
19058              ELSE
19059 
19060                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19061                  print_debuginfo(l_module_name, 'Not raising biz event '
19062                      || l_event_name || ' because all payments were '
19063                      || 'successfully created. So no failed documents '
19064                      || 'to notify.'
19065                      );
19066 		     END IF;
19067              END IF;
19068 
19069          END IF;
19070 
19071      ELSE
19072 
19073 
19074          print_debuginfo(l_module_name, 'Unknown rejection level: '
19075              || p_rej_level
19076              || '. Aborting payment creation ..',
19077              FND_LOG.LEVEL_UNEXPECTED
19078              );
19079 
19080          APP_EXCEPTION.RAISE_EXCEPTION;
19081 
19082      END IF;
19083 
19084      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19085      print_debuginfo(l_module_name, 'EXIT');
19086       END IF;
19087 
19088  EXCEPTION
19089      WHEN OTHERS THEN
19090 
19091          print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
19092              || 'to raise business event.', FND_LOG.LEVEL_UNEXPECTED);
19093          print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
19094              FND_LOG.LEVEL_UNEXPECTED);
19095          print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
19096              FND_LOG.LEVEL_UNEXPECTED);
19097 
19098          /*
19099           * Propogate exception to caller.
19100           */
19101          RAISE;
19102 
19103  END raiseBizEvents;
19104 
19105 /*--------------------------------------------------------------------
19106  | NAME:
19107  |     checkIfPmtAlreadyFailed
19108  |
19109  | PURPOSE:
19110  |     Checks if a payment has already failed validation. If yes, this
19111  |     method returns TRUE; else, it return FALSE.
19112  |
19113  | PARAMETERS:
19114  |     IN
19115  |
19116  |     OUT
19117  |
19118  |
19119  | RETURNS:
19120  |
19121  | NOTES:
19122  |
19123  *---------------------------------------------------------------------*/
19124  FUNCTION checkIfPmtAlreadyFailed(
19125      p_paymentId   IN   IBY_PAYMENTS_ALL.payment_id%TYPE,
19126      p_paymentTab  IN   paymentTabType
19127      )
19128  RETURN BOOLEAN
19129  IS
19130  l_ret_val BOOLEAN := FALSE;
19131  BEGIN
19132 
19133      FOR i IN p_paymentTab.FIRST .. p_paymentTab.LAST LOOP
19134 
19135          IF (p_paymentTab(i).payment_id = p_paymentId) THEN
19136 
19137              IF (p_paymentTab(i).payment_status = PAY_STATUS_REJECTED) THEN
19138 
19139                  l_ret_val := TRUE;
19140                  EXIT;
19141 
19142              END IF;
19143 
19144          END IF;
19145 
19146      END LOOP;
19147 
19148      RETURN l_ret_val;
19149 
19150  END checkIfPmtAlreadyFailed;
19151 
19152 /*--------------------------------------------------------------------
19153  | NAME:
19154  |     checkIfPmtAlreadyAdded
19155  |
19156  | PURPOSE:
19157  |     Checks if a payment has already been added to the list of
19158  |     negative amount payments that qualify for credit memo adjustment.
19159  |     If yes, this method returns TRUE; else, it return FALSE.
19160  |
19161  | PARAMETERS:
19162  |     IN
19163  |
19164  |     OUT
19165  |
19166  |
19167  | RETURNS:
19168  |
19169  | NOTES:
19170  |
19171  *---------------------------------------------------------------------*/
19172  FUNCTION checkIfPmtAlreadyAdded(
19173      p_paymentId   IN   IBY_PAYMENTS_ALL.payment_id%TYPE,
19174      p_paymentTab  IN   pmtIdsTab
19175      )
19176  RETURN BOOLEAN
19177  IS
19178  l_ret_val BOOLEAN := FALSE;
19179  BEGIN
19180 
19181      /* return false if no records in negative payments array */
19182      IF (p_paymentTab.COUNT = 0) THEN
19183 
19184          l_ret_val := FALSE;
19185 
19186          RETURN l_ret_val;
19187 
19188      END IF;
19189 
19190      /*
19191       * Loop through negative payments list, scanning for
19192       * given payment id
19193       */
19194      FOR i IN p_paymentTab.FIRST .. p_paymentTab.LAST LOOP
19195 
19196          IF (p_paymentTab(i) = p_paymentId) THEN
19197 
19198              l_ret_val := TRUE;
19199              EXIT;
19200 
19201          END IF;
19202 
19203      END LOOP;
19204 
19205      RETURN l_ret_val;
19206 
19207  END checkIfPmtAlreadyAdded;
19208 
19209 /*--------------------------------------------------------------------
19210  | NAME:
19211  |     getXMLClob
19212  |
19213  | PURPOSE:
19214  |     Returns an XML clob with the list of documents that satisfy
19215  |     the executed select condition.
19216  |
19217  | PARAMETERS:
19218  |     IN
19219  |
19220  |     OUT
19221  |
19222  |
19223  | RETURNS:
19224  |
19225  | NOTES:
19226  |
19227  |     XML generation from PLSQL is evolving rapidly.
19228  |
19229  |     The code below uses DBMS_XMLQuery() to generate XML
19230  |     from a SELECT statement.
19231  |
19232  |     DBMS_XMLQuery() uses Java code internally, and is slow.
19233  |
19234  |     Better ways to generate XML are:
19235  |     1. DBMS_XMLGEN
19236  |        DBMS_XMLGEN is a built-in package in C. It is fast. However,
19237  |        it is supported only in Oracle 9i and above.
19238  |
19239  |     2. SQLX
19240  |        This is the new emerging standard for SQL -> XML.
19241  |        It is both fast and easy. However, only Oracle 9i and
19242  |        above.
19243  |
19244  *---------------------------------------------------------------------*/
19245  FUNCTION getXMLClob(
19246      p_payreq_id     IN VARCHAR2
19247      )
19248      RETURN CLOB
19249  IS
19250  l_module_name  CONSTANT VARCHAR2(200)  := G_PKG_NAME || '.getXMLClob';
19251  l_xml_clob     CLOB := NULL;
19252 
19253  l_ctx          DBMS_XMLQuery.ctxType;
19254  l_sql          VARCHAR2(2000);
19255  l_sqlcode      NUMBER;
19256  l_sqlerrm      VARCHAR2(300);
19257 
19258  BEGIN
19259 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19260      print_debuginfo(l_module_name, 'ENTER');
19261 	 END IF;
19262 
19263      /*
19264       * Note:
19265       *
19266       * Replace DBMS_XMLQuery with DBMS_XMLGEN or SQLX
19267       * when Oracle 9i is minimum requirement in tech
19268       * stack (see notes above).
19269       */
19270 
19271      /*
19272       * Select all docs that:
19273       * 1. Have the given pay req id
19274       * 2. Are not in 'payments_created' status
19275       * 3. Were updated in the process of payment creation
19276       *    (some docs might have failed earlier in document
19277       *    validation flow. We don't want to pick them up).
19278       */
19279      l_sql := 'SELECT calling_app_id, '
19280                   || 'calling_app_doc_unique_ref1'
19281                   || 'calling_app_doc_unique_ref2'
19282                   || 'calling_app_doc_unique_ref3'
19283                   || 'calling_app_doc_unique_ref4'
19284                   || 'calling_app_doc_unique_ref5'
19285                   || 'pay_proc_trxn_type_id '
19286                   || 'FROM IBY_DOCS_PAYABLE_ALL '
19287                   || 'WHERE payment_service_request_id = :payreq_id '
19288                   || 'AND  document_status <> :doc_status '
19289                   || 'AND  payment_id IS NOT NULL';
19290 
19291      l_ctx := DBMS_XMLQuery.newContext(l_sql);
19292      DBMS_XMLQuery.setBindValue(l_ctx, 'payreq_id', p_payreq_id);
19293      DBMS_XMLQuery.setBindValue(l_ctx, 'doc_status', DOC_STATUS_PAY_CREATED);
19294      DBMS_XMLQuery.useNullAttributeIndicator(l_ctx, TRUE);
19295 
19296      /* raise an exception if no rows were found */
19297      DBMS_XMLQuery.setRaiseException(l_ctx, TRUE);
19298      DBMS_XMLQuery.setRaiseNoRowsException(l_ctx, TRUE);
19299      DBMS_XMLQuery.propagateOriginalException(l_ctx, TRUE);
19300 
19301      l_xml_clob := DBMS_XMLQuery.getXML(l_ctx);
19302      DBMS_XMLQuery.closeContext(l_ctx);
19303 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19304      print_debuginfo(l_module_name, 'EXIT');
19305 	 END IF;
19306 
19307      RETURN l_xml_clob;
19308 
19309  EXCEPTION
19310 
19311      WHEN OTHERS THEN
19312 
19313          DBMS_XMLQuery.getExceptionContent(l_ctx, l_sqlcode, l_sqlerrm);
19314 		 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19315          print_debuginfo(l_module_name, 'SQL code: '   || l_sqlcode);
19316          print_debuginfo(l_module_name, 'SQL err msg: '|| l_sqlerrm);
19317 		END IF;
19318          /*
19319           * Do not raise exception if no rows found.
19320           * It means all payments were successful.
19321           * return NULL clob to caller.
19322           *
19323           * 1403 = NO_DATA_FOUND
19324           *
19325           * Note: We are unable to explicitly catch the
19326           * NO_DATA_FOUND exception here because the caller
19327           * raises some other exception. So we have to check
19328           * value of the original error code instead.
19329           */
19330          IF (l_sqlcode = 1403) THEN
19331              print_debuginfo(l_module_name, 'No rows were returned for query;'
19332                  || ' Returning null xml clob.');
19333              RETURN NULL;
19334          END IF;
19335 
19336 
19337          print_debuginfo(l_module_name, 'Fatal: Exception when attempting '
19338              || 'to raise business event.', FND_LOG.LEVEL_UNEXPECTED);
19339          print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
19340              FND_LOG.LEVEL_UNEXPECTED);
19341          print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
19342              FND_LOG.LEVEL_UNEXPECTED);
19343 
19344          /*
19345           * Propogate exception to caller.
19346           */
19347          RAISE;
19348 
19349  END getXMLClob;
19350 
19351 /*--------------------------------------------------------------------
19352  | NAME:
19353  |     getRejectedDocs
19354  |
19355  | PURPOSE:
19356  |     Performs a database query to get all failed documents which
19357  |     are part of payments created for the given payment request.
19358  |     These failed documents are put into data structure and
19359  |     returned to the caller.
19360  |
19361  |
19362  | PARAMETERS:
19363  |     IN
19364  |
19365  |     OUT
19366  |
19367  |
19368  | RETURNS:
19369  |
19370  | NOTES:
19371  |
19372  |
19373  *---------------------------------------------------------------------*/
19374  PROCEDURE getRejectedDocs(
19375      p_payreq_id    IN VARCHAR2,
19376      x_docIDTab     IN OUT NOCOPY IBY_DISBURSE_UI_API_PUB_PKG.docPayIDTab,
19377      x_docStatusTab IN OUT NOCOPY IBY_DISBURSE_UI_API_PUB_PKG.docPayStatusTab
19378      )
19379  IS
19380  l_module_name  CONSTANT VARCHAR2(200) := G_PKG_NAME || '.getRejectedDocs';
19381  l_rej_docs_list IBY_VALIDATIONSETS_PUB.rejectedDocTabType;
19382 
19383  /*
19384   * Cursor to get list of failed documents which are part of payments
19385   * created for the given payment service request.
19386   */
19387  CURSOR c_rejected_docs (p_payreq_id IBY_PAY_SERVICE_REQUESTS.
19388                                          payment_service_request_id%TYPE)
19389  IS
19390  SELECT
19391      doc.document_payable_id,
19392      doc.document_status
19393  FROM
19394      IBY_DOCS_PAYABLE_ALL doc
19395  WHERE
19396      doc.payment_service_request_id = p_payreq_id AND
19397      doc.document_status <> DOC_STATUS_PAY_CREATED AND
19398      doc.payment_id IS NOT NULL
19399  ;
19400 
19401  BEGIN
19402 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19403      print_debuginfo(l_module_name, 'ENTER');
19404 END IF;
19405      /*
19406       * Pick up all rejected documents for this payment request.
19407       */
19408      OPEN  c_rejected_docs(p_payreq_id);
19409      FETCH c_rejected_docs BULK COLLECT INTO l_rej_docs_list;
19410      CLOSE c_rejected_docs;
19411 
19412      /*
19413       * Separate out the document ids and the document statuses.
19414       * This is because the rejection API expects these as
19415       * separate arrays.
19416       */
19417      IF (l_rej_docs_list.COUNT <> 0) THEN
19418          FOR i IN l_rej_docs_list.FIRST .. l_rej_docs_list.LAST LOOP
19419              x_docIDTab(i) := l_rej_docs_list(i).doc_id;
19420          END LOOP;
19421 
19422          FOR i IN l_rej_docs_list.FIRST .. l_rej_docs_list.LAST LOOP
19423              x_docStatusTab(i) := l_rej_docs_list(i).doc_status;
19424          END LOOP;
19425      END IF;
19426 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19427      print_debuginfo(l_module_name, 'EXIT');
19428 	 END IF;
19429 
19430  END getRejectedDocs;
19431 
19432 /*--------------------------------------------------------------------
19433  | NAME:
19434  |     dummyGLAPI
19435  |
19436  | PURPOSE:
19437  |     Dummy method; to be used for testing purposes. Used to simulate
19438  |     GL API for currency conversion.
19439  |
19440  | PARAMETERS:
19441  |     IN
19442  |
19443  |     OUT
19444  |
19445  |
19446  | RETURNS:
19447  |
19448  | NOTES:
19449  |
19450  *---------------------------------------------------------------------*/
19451  PROCEDURE dummyGLAPI(
19452      p_exch_date          IN         DATE,
19453      p_source_amount      IN         NUMBER,
19454      p_source_curr        IN         VARCHAR2,
19455      p_decl_curr          IN         VARCHAR2,
19456      p_decl_fx_rate_type  IN         VARCHAR2,
19457      x_decl_amount        OUT NOCOPY NUMBER)
19458  IS
19459 
19460  BEGIN
19461 
19462      x_decl_amount := p_source_amount * 2;
19463 
19464  END dummyGLAPI;
19465 
19466 /*--------------------------------------------------------------------
19467  | NAME:
19468  |     dummy_paymentsAdjustHook
19469  |
19470  | PURPOSE:
19471  |     Dummy method; to be used for testing purposes. Used to simulate
19472  |     calling app hook.
19473  |
19474  | PARAMETERS:
19475  |     IN
19476  |
19477  |     OUT
19478  |
19479  |
19480  | RETURNS:
19481  |
19482  | NOTES:
19483  |
19484  *---------------------------------------------------------------------*/
19485  PROCEDURE dummy_paymentsAdjustHook(
19486      x_paymentTab      IN OUT NOCOPY hookPaymentTabType,
19487      x_docsInPmtTab    IN OUT NOCOPY hookDocsInPaymentTabType
19488      )
19489  IS
19490 
19491  BEGIN
19492 
19493      x_docsInPmtTab(5).dont_pay_flag        := 'Y';
19494      x_docsInPmtTab(5).dont_pay_reason_code := 'chumma failed';
19495 
19496      /*
19497       * If we fail a doc, make sure to adjust the payment amount
19498       */
19499      FOR i in x_paymentTab.FIRST ..  x_paymentTab.LAST LOOP
19500 
19501          IF (x_docsInPmtTab(5).payment_id =
19502              x_paymentTab(i).payment_id) THEN
19503 
19504              x_paymentTab(i).payment_amount :=
19505                  x_paymentTab(i).payment_amount
19506                      - x_docsInPmtTab(5).document_amount;
19507 
19508          END IF;
19509 
19510      END LOOP;
19511 
19512  END dummy_paymentsAdjustHook;
19513 
19514 /*--------------------------------------------------------------------
19515  | NAME:
19516  |     dummy_ruleFunction
19517  |
19518  | PURPOSE:
19519  |     Dummy method; to be used for testing purposes.
19520  |     You will need to register this function with an event
19521  |     subscription for this function to be called.
19522  |
19523  |     Used to simulate calling app's business event handler.
19524  |
19525  | PARAMETERS:
19526  |     IN
19527  |
19528  |     OUT
19529  |
19530  |
19531  | RETURNS:
19532  |
19533  | NOTES:
19534  |
19535  *---------------------------------------------------------------------*/
19536  FUNCTION dummy_ruleFunction(
19537      p_subscription IN            RAW,
19538      p_event        IN OUT NOCOPY WF_EVENT_T
19539      )
19540      RETURN VARCHAR2
19541  IS
19542 
19543  l_module_name     CONSTANT VARCHAR2(200) := G_PKG_NAME ||
19544                                                  '.dummy_ruleFunction';
19545  l_parameter_list  wf_parameter_list_t := wf_parameter_list_t();
19546  l_parameter_t     wf_parameter_t:= wf_parameter_t(NULL, NULL);
19547  l_parameter_name  l_parameter_t.name%TYPE;
19548  l_parameter_value l_parameter_t.value%TYPE;
19549  l_clob            CLOB;
19550  i                 PLS_INTEGER;
19551 
19552  BEGIN
19553 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19554      print_debuginfo(l_module_name, 'ENTER');
19555 	 END IF;
19556 
19557      l_parameter_list := p_event.getParameterList();
19558 
19559      IF (l_parameter_list IS NOT NULL) THEN
19560          i := l_parameter_list.FIRST;
19561          WHILE (i <= l_parameter_list.LAST) LOOP
19562              l_parameter_name  := NULL;
19563              l_parameter_value := NULL;
19564 
19565              l_parameter_name  := l_parameter_list(i).getName();
19566              l_parameter_value := l_parameter_list(i).getValue();
19567 
19568              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19569              print_debuginfo(l_module_name, 'Param Name: '
19570                  || l_parameter_name || ', Param Value: '
19571                  || l_parameter_value
19572                  );
19573      END IF;
19574              i := l_parameter_list.NEXT(i);
19575          END LOOP;
19576      END IF;
19577 
19578      l_clob := p_event.getEventData();
19579 
19580      IF (l_clob IS NOT NULL) THEN
19581          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19582          print_debuginfo(l_module_name, 'Clob is not null');
19583       END IF;
19584          IBY_BUILD_UTILS_PKG.printXMLClob(l_clob);
19585      END IF;
19586 
19587      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19588      print_debuginfo(l_module_name, 'EXIT');
19589      END IF;
19590      RETURN 'SUCCESS';
19591 
19592  END dummy_ruleFunction;
19593 
19594 /*--------------------------------------------------------------------
19595  | NAME:
19596  |     getReviewPmtsSysOption
19597  |
19598  | PURPOSE:
19599  |     Gets the review payment flag system option.
19600  |
19601  | PARAMETERS:
19602  |     IN
19603  |
19604  |
19605  |     OUT
19606  |
19607  |
19608  | RETURNS:
19609  |
19610  | NOTES:
19611  |
19612  *---------------------------------------------------------------------*/
19613  FUNCTION getReviewPmtsSysOption RETURN VARCHAR2
19614  IS
19615  l_revw_pmt_sys_option VARCHAR2(200);
19616 
19617  l_sys_options_tab sysOptionsTabType;
19618  l_print_var       NUMBER        := -1;
19619 
19620  l_module_name     CONSTANT VARCHAR2(200) := G_PKG_NAME ||
19621                                                  '.getReviewPmtsSysOption';
19622 
19623  CURSOR c_sys_options
19624  IS
19625  SELECT
19626      NULL,
19627      sysoptions.require_prop_pmts_review_flag
19628  FROM
19629      IBY_INTERNAL_PAYERS_ALL sysoptions
19630  WHERE
19631      sysoptions.org_id IS NULL
19632  ;
19633 
19634  BEGIN
19635 
19636      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19637      print_debuginfo(l_module_name, 'ENTER');
19638      END IF;
19639      /*
19640       * The 'review proposed payments' flag indicates whether
19641       * all payments (including successful ones) require
19642       *  user review.
19643       */
19644 
19645      /*
19646       * Fetch the system options for the given org
19647       */
19648      OPEN  c_sys_options;
19649      FETCH c_sys_options BULK COLLECT INTO l_sys_options_tab;
19650      CLOSE c_sys_options;
19651 
19652      IF (l_sys_options_tab.COUNT = 0) THEN
19653 
19654          /*
19655           * This means that the review payment flag
19656           * is not set at the enterprise level.
19657           *
19658           * Enterprise level review payment flag (i.e., with org
19659           * id set to null) is expected to be seeded.
19660           *
19661           * Raise an exception and abort processing.
19662           */
19663 
19664          print_debuginfo(l_module_name, 'Review pmts flag '
19665              || 'system option is not set at enterprise level. '
19666              || 'It is mandatory to '
19667              || 'setup review pmts flag at enterprise level '
19668              || 'Raising exception.. ',
19669              FND_LOG.LEVEL_UNEXPECTED
19670              );
19671 
19672          APP_EXCEPTION.RAISE_EXCEPTION;
19673 
19674      ELSIF (l_sys_options_tab.COUNT <> 1) THEN
19675 
19676          /*
19677           * This means that there are multiple review payment
19678           * flags set at the enterprise level.
19679           * We don't know which one to use.
19680           *
19681           * Raise an exception and abort processing.
19682           */
19683 
19684          print_debuginfo(l_module_name, 'Multiple review payment flag '
19685              || 'system options are set at '
19686              || 'enterprise level. It is mandatory to '
19687              || 'setup only one review payment flag sys option '
19688              || 'at enterprise level. '
19689              || 'Raising exception.. ',
19690              FND_LOG.LEVEL_UNEXPECTED
19691              );
19692 
19693          APP_EXCEPTION.RAISE_EXCEPTION;
19694 
19695      ELSE
19696 
19697          /*
19698           * Return the retrieved enterprise level
19699           * review payment flag system option.
19700           */
19701          l_revw_pmt_sys_option  := l_sys_options_tab(1).revw_flag;
19702 
19703      END IF; -- if l_sys_options_tab.COUNT = 0
19704 
19705      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19706      print_debuginfo(l_module_name, 'Returning payment rejection '
19707          || 'level: '
19708          || l_revw_pmt_sys_option
19709          );
19710 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19711      print_debuginfo(l_module_name, 'EXIT');
19712 	 END IF;
19713      END IF;
19714      RETURN l_revw_pmt_sys_option ;
19715 
19716      EXCEPTION
19717          WHEN OTHERS THEN
19718 
19719              /*
19720               * In case of an exception, return NULL.
19721               */
19722              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19723              print_debuginfo(l_module_name, 'Exception thrown '
19724                  || 'when attempting to get review payment flag '
19725                  || 'at enterprise level. Returning NULL.'
19726                  );
19727 
19728             print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE);
19729             print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM);
19730 	     END IF;
19731             l_revw_pmt_sys_option := NULL;
19732 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19733             print_debuginfo(l_module_name, 'EXIT');
19734 			END IF;
19735 
19736             RETURN l_revw_pmt_sys_option ;
19737 
19738  END getReviewPmtsSysOption;
19739 
19740 /*--------------------------------------------------------------------
19741  | NAME:
19742  |     getPmtRejLevelSysOption
19743  |
19744  | PURPOSE:
19745  |     Gets the payment rejection level system option.
19746  |
19747  |     The handling of payment validation failures is dependent
19748  |     upon the rejection level setting.
19749  |
19750  | PARAMETERS:
19751  |     IN
19752  |
19753  |
19754  |     OUT
19755  |
19756  |
19757  | RETURNS:
19758  |
19759  | NOTES:
19760  |
19761  *---------------------------------------------------------------------*/
19762  FUNCTION getPmtRejLevelSysOption RETURN VARCHAR2
19763  IS
19764  l_rej_level_sys_option VARCHAR2(200);
19765 
19766  l_sys_options_tab sysOptionsTabType;
19767  l_print_var       NUMBER        := -1;
19768 
19769  l_module_name     CONSTANT VARCHAR2(200) := G_PKG_NAME ||
19770                                                  '.getPmtRejLevelSysOption';
19771 
19772  CURSOR c_sys_options
19773  IS
19774  SELECT
19775      sysoptions.payment_rejection_level_code,
19776      NULL
19777  FROM
19778      IBY_INTERNAL_PAYERS_ALL sysoptions
19779  WHERE
19780      sysoptions.org_id IS NULL
19781  ;
19782 
19783  BEGIN
19784 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19785      print_debuginfo(l_module_name, 'ENTER');
19786 	 END IF;
19787 
19788      /*
19789       * The rejection level system option specifies
19790       * what is to be rejected if a payment fails
19791       * validation.
19792       */
19793 
19794      /*
19795       * Fetch the system options for the given org
19796       */
19797      OPEN  c_sys_options;
19798      FETCH c_sys_options BULK COLLECT INTO l_sys_options_tab;
19799      CLOSE c_sys_options;
19800 
19801      IF (l_sys_options_tab.COUNT = 0) THEN
19802 
19803          /*
19804           * This means that the payment rejection level
19805           * is not set at the enterprise level.
19806           *
19807           * Enterprise level rejection levels (i.e., with org
19808           * id set to null) are expected to be seeded.
19809           *
19810           * Raise an exception and abort processing.
19811           */
19812 
19813          print_debuginfo(l_module_name, 'Payment rejection level '
19814              || 'system option is not set at enterprise level. '
19815              || 'It is mandatory to '
19816              || 'setup rejection levels at enterprise level '
19817              || 'Raising exception.. ',
19818              FND_LOG.LEVEL_UNEXPECTED
19819              );
19820 
19821 
19822          APP_EXCEPTION.RAISE_EXCEPTION;
19823 
19824      ELSIF (l_sys_options_tab.COUNT <> 1) THEN
19825 
19826          /*
19827           * This means that there are multiple payment
19828           * rejection levels set at the enterprise level.
19829           * We don't know which one to use.
19830           *
19831           * Raise an exception and abort processing.
19832           */
19833 
19834          print_debuginfo(l_module_name, 'Multiple payment rejection '
19835              || 'level system options are set at '
19836              || 'enterprise level. It is mandatory to '
19837              || 'setup only one payment rejection level '
19838              || 'at enterprise level. '
19839              || 'Raising exception.. ',
19840              FND_LOG.LEVEL_UNEXPECTED
19841              );
19842 
19843          APP_EXCEPTION.RAISE_EXCEPTION;
19844 
19845      ELSE
19846 
19847          /*
19848           * Return the retrieved enterprise level
19849           * payment rejection level system option.
19850           */
19851          l_rej_level_sys_option := l_sys_options_tab(1).rej_level;
19852 
19853      END IF; -- if l_sys_options_tab.COUNT = 0
19854 
19855      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19856      print_debuginfo(l_module_name, 'Returning payment rejection '
19857          || 'level: '
19858          || l_rej_level_sys_option
19859          );
19860 
19861      print_debuginfo(l_module_name, 'EXIT');
19862      END IF;
19863      RETURN l_rej_level_sys_option;
19864 
19865      EXCEPTION
19866          WHEN OTHERS THEN
19867 
19868              /*
19869               * In case of an exception, return NULL.
19870               */
19871              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19872              print_debuginfo(l_module_name, 'Exception thrown '
19873                  || 'when attempting to get payment rejection '
19874                  || 'level. Returning NULL.'
19875                  );
19876 
19877             print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE);
19878             print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM);
19879 
19880 	    END IF;
19881 
19882             l_rej_level_sys_option := NULL;
19883 			IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19884             print_debuginfo(l_module_name, 'EXIT');
19885 			END IF;
19886 
19887             RETURN l_rej_level_sys_option;
19888 
19889  END getPmtRejLevelSysOption;
19890 
19891 /*--------------------------------------------------------------------
19892  | NAME:
19893  |     performCreditMemoHandling
19894  |
19895  | PURPOSE:
19896  |
19897  |
19898  |
19899  | PARAMETERS:
19900  |     IN
19901  |
19902  |     OUT
19903  |
19904  |
19905  | RETURNS:
19906  |
19907  | NOTES:
19908  |
19909  *---------------------------------------------------------------------*/
19910  PROCEDURE performCreditMemoHandling(
19911      x_paymentTab    IN OUT NOCOPY paymentTabType,
19912      x_docsInPmtTab  IN OUT NOCOPY docsInPaymentTabType
19913      )
19914  IS
19915  l_module_name         CONSTANT VARCHAR2(200) := G_PKG_NAME ||
19916                                                  '.performCreditMemoHandling';
19917  l_negative_pmts_tab   pmtIdsTab;
19918  BEGIN
19919 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19920      print_debuginfo(l_module_name, 'ENTER');
19921 	 END IF;
19922 
19923      /*
19924       * A payment qualifies for credit memo adjustments
19925       * if it satisfies the following criteria:
19926       *
19927       * a. Payment amount is negative
19928       * b. Payment contains at least one positive
19929       *    document payable
19930       *
19931       * a. and b. together imply that the payment is not
19932       * payalone, so this condition need not be explicitly
19933       * checked.
19934       *
19935       * Form the payment request, get a list of payments
19936       * that qualify for credit memo adjustments.
19937       */
19938      getListOfQualifyingNegPmts(l_negative_pmts_tab,
19939          x_paymentTab, x_docsInPmtTab);
19940 
19941      IF (l_negative_pmts_tab.COUNT = 0) THEN
19942 
19943          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19944          print_debuginfo(l_module_name, 'No payments qualified for '
19945              || 'credit memo adjustment in this request. '
19946              || 'Skipping credit memo handling .. '
19947              );
19948 
19949          print_debuginfo(l_module_name, 'EXIT');
19950 	 END IF;
19951 
19952          RETURN;
19953 
19954      END IF;
19955 
19956      /*
19957       * Attempt to bring negative payments to zero by adjusting
19958       * credit memo amounts.
19959       */
19960      adjustCreditMemosWithinPmt(l_negative_pmts_tab, x_paymentTab,
19961          x_docsInPmtTab);
19962 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
19963      print_debuginfo(l_module_name, 'EXIT');
19964 	 END IF;
19965   EXCEPTION
19966    WHEN OTHERS THEN
19967    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
19968                  FND_LOG.LEVEL_UNEXPECTED);
19969              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
19970                  FND_LOG.LEVEL_UNEXPECTED);
19971    print_debuginfo(l_module_name, l_module_name||':Exception while performing performCreditMemoHandling');
19972    RAISE;
19973  END performCreditMemoHandling;
19974 
19975 /*--------------------------------------------------------------------
19976  | NAME:
19977  |     adjustCreditMemosWithinPmt
19978  |
19979  | PURPOSE:
19980  |
19981  |
19982  |
19983  | PARAMETERS:
19984  |     IN
19985  |
19986  |     OUT
19987  |
19988  |
19989  | RETURNS:
19990  |
19991  | NOTES:
19992  |
19993  *---------------------------------------------------------------------*/
19994  PROCEDURE adjustCreditMemosWithinPmt(
19995      p_qualifyingPmtsTab  IN pmtIdsTab,
19996      x_paymentTab         IN OUT NOCOPY paymentTabType,
19997      x_docsInPmtTab       IN OUT NOCOPY docsInPaymentTabType
19998      )
19999  IS
20000 
20001  l_module_name     CONSTANT VARCHAR2(200) := G_PKG_NAME ||
20002                                                  '.adjustCreditMemosWithinPmt';
20003 
20004  l_pos_docs_array  docsInPaymentTabType;
20005  l_neg_docs_array  docsInPaymentTabType;
20006  l_running_total   NUMBER := 0;
20007 
20008  BEGIN
20009 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20010      print_debuginfo(l_module_name, 'ENTER');
20011 	 END IF;
20012 
20013      /*
20014       * For each payment that qualifies for credit memo
20015       * adjustment, separate out the positive and negative
20016       * documents payable of that payment into two distinct
20017       * arrays.
20018       */
20019      FOR i IN p_qualifyingPmtsTab.FIRST .. p_qualifyingPmtsTab.LAST LOOP
20020 
20021          FOR j IN x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
20022 
20023              IF (x_docsInPmtTab(j).payment_id =
20024                  p_qualifyingPmtsTab(i)) THEN
20025 
20026                  IF (x_docsInPmtTab(j).document_amount < 0) THEN
20027 
20028                      /* array of negative documents */
20029                      l_neg_docs_array(l_neg_docs_array.COUNT + 1) :=
20030                          x_docsInPmtTab(j);
20031 
20032                  ELSE
20033 
20034                      /* array of positive documents */
20035                      l_pos_docs_array(l_pos_docs_array.COUNT + 1) :=
20036                          x_docsInPmtTab(j);
20037 
20038                  END IF;
20039 
20040              END IF;
20041 
20042          END LOOP;
20043 
20044      END LOOP;
20045 
20046      /* uncomment for debugging purposes */
20047      /*-------------------------------------------
20048      FOR i IN l_neg_docs_array.FIRST .. l_neg_docs_array.LAST LOOP
20049          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20050          print_debuginfo(l_module_name, 'Payment id: '
20051              || l_neg_docs_array(i).payment_id
20052              || ', neg doc id: '
20053              || l_neg_docs_array(i).document_id
20054              || ', neg doc amount: '
20055              || l_neg_docs_array(i).document_amount
20056              );
20057 	          END IF;
20058      END LOOP;
20059 
20060      FOR i IN l_pos_docs_array.FIRST .. l_pos_docs_array.LAST LOOP
20061          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20062          print_debuginfo(l_module_name, 'Payment id: '
20063              || l_pos_docs_array(i).payment_id
20064              || ', pos doc id: '
20065              || l_pos_docs_array(i).document_id
20066              || ', pos doc amount: '
20067              || l_pos_docs_array(i).document_amount
20068              );
20069 	          END IF;
20070      END LOOP;
20071      ---------------------------------------------*/
20072 
20073      /*
20074       * For each qualifying payment, perform credit memo
20075       * adjustment.
20076       */
20077      FOR i IN p_qualifyingPmtsTab.FIRST .. p_qualifyingPmtsTab.LAST LOOP
20078 
20079          /* initialize running total for this payment */
20080          l_running_total := 0;
20081 
20082          /*
20083           * Sum up all the positive documents of this payment
20084           * and store the total in l_running_total.
20085           */
20086          FOR j IN l_pos_docs_array.FIRST .. l_pos_docs_array.LAST LOOP
20087 
20088              IF (l_pos_docs_array(j).payment_id =
20089                  p_qualifyingPmtsTab(i)) THEN
20090 
20091                  l_running_total := l_running_total +
20092                                         l_pos_docs_array(j).document_amount;
20093 
20094              END IF;
20095 
20096          END LOOP;
20097 
20098          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20099          print_debuginfo(l_module_name, 'Running total of positive docs '
20100              || 'for payment '
20101              || p_qualifyingPmtsTab(i)
20102              || ' is: '
20103              || l_running_total
20104              );
20105 	          END IF;
20106 
20107          /*
20108           * We now have the running total of all positive documents
20109           * within this payment stored in l_running_total.
20110           */
20111 
20112          /*
20113           * Start adjusting negative documents (credit memos)
20114           * one-by-one for this payment.
20115           */
20116          FOR k in l_neg_docs_array.FIRST .. l_neg_docs_array.LAST LOOP
20117 
20118              IF (l_neg_docs_array(k).payment_id =
20119                  p_qualifyingPmtsTab(i)) THEN
20120 
20121                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20122                  print_debuginfo(l_module_name, 'Adding neg doc id: '
20123                      || l_neg_docs_array(k).document_id
20124                      || ' with amount '
20125                      || l_neg_docs_array(k).document_amount
20126                      || ' to running total.'
20127                      );
20128      END IF;
20129                  l_running_total := l_running_total +
20130                                         l_neg_docs_array(k).document_amount;
20131 
20132                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20133                  print_debuginfo(l_module_name, 'Now running total : '
20134                      || l_running_total
20135                      );
20136      END IF;
20137                  IF (l_running_total < 0) THEN
20138 
20139                      /* Running total  negative implies that
20140                       * the last added negative amount document,
20141                       * has exceeded the sum of all available
20142                       * positive documents.
20143                       *
20144                       * Adjust the last added negative
20145                       * document payment amount such that
20146                       * adding this negative amount will bring
20147                       * the running total exactly to zero.
20148                       */
20149 
20150                      l_neg_docs_array(k).document_amount :=
20151                          l_neg_docs_array(k).document_amount
20152                              - l_running_total;
20153 
20154                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20155                      print_debuginfo(l_module_name, 'Adusting neg doc id '
20156                          || l_neg_docs_array(k).document_id
20157                          || ' to amount '
20158                          || l_neg_docs_array(k).document_amount
20159                          );
20160      END IF;
20161                      /*
20162                       * Zero out all remaining negative documents
20163                       * for this payment.
20164                       */
20165                      FOR m in k+1 .. l_neg_docs_array.LAST
20166                          LOOP
20167 
20168                          IF (l_neg_docs_array(m).payment_id =
20169                              p_qualifyingPmtsTab(i)) THEN
20170 
20171                              l_neg_docs_array(m).document_amount := 0;
20172 
20173                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20174  print_debuginfo(l_module_name, 'Zeroing out '
20175                                  || ' document id '
20176                                  || l_neg_docs_array(m).document_id
20177                                  || ' of payment '
20178                                  || l_neg_docs_array(m).payment_id
20179                                  );
20180      END IF;
20181                          END IF;
20182 
20183                      END LOOP;
20184 
20185                      /*
20186                       * If running total has gone negative,
20187                       * and we have finished zeroing out the
20188                       * rest of the negative documents for
20189                       * this payment, it means that credit
20190                       * memo adjustment for this payment is
20191                       * complete. Exit the loop and continue
20192                       * with the next payment.
20193                       */
20194                      EXIT;
20195 
20196                  END IF; -- if running total has gone negative
20197 
20198              END IF; -- if payment id of this document matches
20199 
20200          END LOOP; -- for each negative doc for this payment
20201 
20202          /*
20203           * Reflect the document and payment amount adjustments
20204           * that were made during credit memo handling for
20205           * this payment back to the original documents and
20206           * payments array -  x_paymentTab and x_docsInPmtTab
20207           */
20208          refreshDocAndPmtAmounts(p_qualifyingPmtsTab(i),
20209              l_neg_docs_array, x_paymentTab, x_docsInPmtTab);
20210 
20211      END LOOP; -- for each negative payment
20212 
20213      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20214      print_debuginfo(l_module_name, 'EXIT');
20215      END IF;
20216  END adjustCreditMemosWithinPmt;
20217 
20218 /*--------------------------------------------------------------------
20219  | NAME:
20220  |     performMaturityDateCalculation
20221  |
20222  | PURPOSE:
20223  |
20224  |
20225  |
20226  | PARAMETERS:
20227  |     IN
20228  |
20229  |     OUT
20230  |
20231  |
20232  | RETURNS:
20233  |
20234  | NOTES:
20235  |
20236  *---------------------------------------------------------------------*/
20237  PROCEDURE performMaturityDateCalculation(
20238      x_paymentTab    IN OUT NOCOPY paymentTabType,
20239      p_docsInPmtTab  IN            docsInPaymentTabType
20240      )
20241  IS
20242  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
20243                                              '.performMaturityDateCalculation';
20244  l_maturity_days_tab      pmtMethodMaturityDaysTab;
20245  l_maturity_days_offset   IBY_PAYMENT_METHODS_VL.maturity_date_offset_days%TYPE;
20246  l_maturity_date_set_flag BOOLEAN := FALSE;
20247  l_temp_discount_date     DATE := NULL;
20248  l_temp_due_date          DATE := NULL;
20249 
20250  BEGIN
20251 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20252      print_debuginfo(l_module_name, 'ENTER');
20253 	 END IF;
20254 
20255      /*
20256       * Load up all the payment methods that support future
20257       * dated payments along with their maturity offset days.
20258       * We will be adding the offset days (if available) to the
20259       * payment date to arrive at the maturity date.
20260       */
20261      loadPmtMethodMaturityDays(l_maturity_days_tab);
20262 
20263      IF (l_maturity_days_tab.COUNT = 0) THEN
20264 
20265          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20266          print_debuginfo(l_module_name, 'None of the seeded payment '
20267              || 'methods support bills payable (future dated payments). '
20268              || 'Skipping maturity date calculation .. '
20269              );
20270 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20271          print_debuginfo(l_module_name, 'EXIT');
20272 		 END IF;
20273      END IF;
20274          RETURN;
20275 
20276      END IF; -- if maturity days tab count == 0
20277 
20278      /*
20279       * Loop through all the payments, setting maturity dates
20280       * for each future dated payment.
20281       */
20282      FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
20283 
20284          /* initialize flag before each iteration */
20285          l_maturity_date_set_flag := FALSE;
20286 
20287          /*
20288           * For each payment that is a future dated payment
20289           * determine the maturity date.
20290           */
20291          IF (x_paymentTab(i).bill_payable_flag = 'Y') THEN
20292 
20293              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20294              print_debuginfo(l_module_name, 'Payment '
20295                  || x_paymentTab(i).payment_id
20296                  || ' is a future dated payment'
20297                  );
20298      END IF;
20299              /*
20300               * ATTEMPT 1:
20301               *
20302               * Try to get the maturity date offset days from the
20303               * payment method and add this to the payment date on
20304               * the payment to arrive at the maturity date.
20305               */
20306              l_maturity_days_offset := getMaturityDaysForPmtMethod(
20307                                            x_paymentTab(i).payment_method_code,
20308                                            l_maturity_days_tab
20309                                            );
20310 
20311              IF (l_maturity_days_offset <> -1) THEN
20312 
20313                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20314                  print_debuginfo(l_module_name, 'Adding '
20315                      || l_maturity_days_offset
20316                      || ' offset days to payment date to arrive at '
20317                      || 'maturity date.'
20318                      );
20319      END IF;
20320                  x_paymentTab(i).maturity_date :=
20321                      x_paymentTab(i).payment_date + l_maturity_days_offset;
20322 
20323                  l_maturity_date_set_flag := TRUE;
20324 
20325              ELSE
20326 
20327                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20328                  print_debuginfo(l_module_name, 'Maturity date offset not '
20329                      || 'set on payment method '
20330                      || x_paymentTab(i).payment_method_code
20331                      || ' (so maturity date needs to be calculated).'
20332                      );
20333      END IF;
20334                  l_maturity_date_set_flag := FALSE;
20335 
20336              END IF;
20337 
20338              /*
20339               * ATTEMPT II:
20340               *
20341               * Set the maturity date based on the earliest
20342               * available discount date from the documents
20343               * on the payment.
20344               *
20345               * Note: Maturity date is also calculated from
20346               * the payment due date in ATTEMPT III below.
20347               *
20348               * The value set of the maturity date will be
20349               * the earliest of (discount date, payment due date).
20350               */
20351 
20352              /* initialize before each iteration */
20353              l_temp_discount_date := NULL;
20354 
20355              IF (l_maturity_date_set_flag = FALSE) THEN
20356 
20357                  /*
20358                   * In this loop, we attempt to find the first available
20359                   * discount date after the payment date for the
20360                   * current payment.
20361                   */
20362                  FOR j IN p_docsInPmtTab.FIRST .. p_docsInPmtTab.LAST LOOP
20363 
20364                      IF (x_paymentTab(i).payment_id =
20365                          p_docsInPmtTab(j).payment_id) THEN
20366 
20367                          IF (p_docsInPmtTab(j).discount_date IS NOT NULL AND
20368                              p_docsInPmtTab(j).discount_date >=
20369                                  x_paymentTab(i).payment_date) THEN
20370 
20371                              IF (l_temp_discount_date IS NULL) THEN
20372 
20373                                  /*
20374                                   * if 'l_temp_discount_date' is not yet
20375                                   * initialized, set it to the first available
20376                                   * discount date value.
20377                                   */
20378                                  l_temp_discount_date :=
20379                                      p_docsInPmtTab(j).discount_date;
20380 
20381                              ELSE
20382 
20383                                  /*
20384                                   * We already have a value for
20385                                   * 'l_temp_discount_date'; Update the value of
20386                                   * 'l_temp_discount_date' only if the new
20387                                   * discount date occurs earlier.
20388                                   */
20389 
20390                                  IF (p_docsInPmtTab(j).discount_date <
20391                                      l_temp_discount_date) THEN
20392 
20393                                      l_temp_discount_date :=
20394                                          p_docsInPmtTab(j).discount_date;
20395 
20396                                  END IF;
20397 
20398                              END IF; -- if temp discount date is not set
20399 
20400                          END IF; -- if discount date is available
20401 
20402                      END IF; -- if document belongs to the current payment
20403 
20404                  END LOOP; -- for each document
20405 
20406                  /*
20407                   * The earliest available discount date is one
20408                   * candidate for the maturity date.
20409                   */
20410                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20411                  print_debuginfo(l_module_name, 'Earliest available '
20412                      || 'discount date for payment '
20413                      || x_paymentTab(i).payment_id
20414                      || ' is '
20415                      || l_temp_discount_date
20416                      );
20417      END IF;
20418              END IF; -- if maturity date is not set for this payment
20419 
20420              /*
20421               * ATTEMPT III:
20422               *
20423               * Set the maturity date based on the earliest
20424               * available payment due date from the documents
20425               * on the payment.
20426               */
20427 
20428              /* initialize before each iteration */
20429              l_temp_due_date := NULL;
20430 
20431              IF (l_maturity_date_set_flag = FALSE) THEN
20432 
20433                  /*
20434                   * In this loop, we attempt to find the first available
20435                   * due date after the payment date for the current
20436                   * payment.
20437                   */
20438                  FOR j IN p_docsInPmtTab.FIRST .. p_docsInPmtTab.LAST LOOP
20439 
20440                      IF (x_paymentTab(i).payment_id =
20441                          p_docsInPmtTab(j).payment_id) THEN
20442 
20443                          IF (p_docsInPmtTab(j).pmt_due_date IS NOT NULL AND
20444                              p_docsInPmtTab(j).pmt_due_date >=
20445                                  x_paymentTab(i).payment_date) THEN
20446 
20447                              IF (l_temp_due_date IS NULL) THEN
20448 
20449                                  /*
20450                                   * if 'l_temp_due_date' is not yet initialized,
20451                                   * set it to the first available due
20452                                   * date value.
20453                                   */
20454                                  l_temp_due_date := p_docsInPmtTab(j).
20455                                                         pmt_due_date;
20456 
20457                              ELSE
20458 
20459                                  /*
20460                                   * We already have a value for
20461                                   * 'l_temp_due_date';
20462                                   * Update the value of 'l_temp_due_date'
20463                                   * only if the new due date occurs
20464                                   * earlier.
20465                                   */
20466 
20467                                  IF (p_docsInPmtTab(j).pmt_due_date <
20468                                      l_temp_due_date) THEN
20469 
20470                                      l_temp_due_date := p_docsInPmtTab(j).
20471                                                             pmt_due_date;
20472 
20473                                  END IF;
20474 
20475                              END IF; -- if temp due date is not set
20476 
20477                          END IF; -- if due date is available
20478 
20479                      END IF; -- if document belongs to the current payment
20480 
20481                  END LOOP; -- for each document
20482 
20483                  /*
20484                   * The earliest available due date is the
20485                   * other candidate for the maturity date.
20486                   */
20487                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20488                  print_debuginfo(l_module_name, 'Earliest available '
20489                      || 'due date for payment '
20490                      || x_paymentTab(i).payment_id
20491                      || ' is '
20492                      || l_temp_due_date
20493                      );
20494      END IF;
20495                  /*
20496                   * Fix for bug 5334177:
20497                   *
20498                   * Maturity Date = EARLIEST (ATTEMPT II, ATTEMPT III)
20499                   *
20500                   * Set the calculated maturity date on the
20501                   * payment as follows:
20502                   *
20503                   * 1. Maturity date is earliest of
20504                   *    (discount date, due date).
20505                   *
20506                   * 2. If either value is not available
20507                   *    use the other.
20508                   *
20509                   * 3. If both values are not available
20510                   *    use the payment date on the
20511                   *    payment as the maturity date.
20512                   */
20513 
20514                  IF (l_temp_discount_date IS NOT NULL AND
20515                      l_temp_due_date      IS NOT NULL) THEN
20516 
20517                      IF (l_temp_discount_date <= l_temp_due_date) THEN
20518 
20519                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20520                          print_debuginfo(l_module_name, 'Setting '
20521                              || 'maturity date to discount date '
20522                              || l_temp_discount_date
20523                              || ' for payment '
20524                              || x_paymentTab(i).payment_id
20525                              || ' because it is earlier '
20526                              || 'than due date '
20527                              || l_temp_due_date
20528                              );
20529      END IF;
20530                          x_paymentTab(i).maturity_date :=
20531                              l_temp_discount_date;
20532 
20533                          l_maturity_date_set_flag := TRUE;
20534 
20535                      ELSE
20536 
20537                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20538                          print_debuginfo(l_module_name, 'Setting '
20539                              || 'maturity date to due date '
20540                              || l_temp_due_date
20541                              || ' for payment '
20542                              || x_paymentTab(i).payment_id
20543                              || ' because it is earlier '
20544                              || 'than discount date '
20545                              || l_temp_discount_date
20546                              );
20547      END IF;
20548                          x_paymentTab(i).maturity_date := l_temp_due_date;
20549 
20550                          l_maturity_date_set_flag := TRUE;
20551 
20552                      END IF;
20553 
20554                  ELSIF (l_temp_discount_date IS NULL AND
20555                         l_temp_due_date      IS NULL) THEN
20556 
20557                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20558                          print_debuginfo(l_module_name, 'Defaulting '
20559                              || 'maturity date to payment date '
20560                              || x_paymentTab(i).payment_date
20561                              || ' for payment '
20562                              || x_paymentTab(i).payment_id
20563                              || ' because both discount and due '
20564                              || 'dates are not available.'
20565                              );
20566      END IF;
20567                          x_paymentTab(i).maturity_date :=
20568                              x_paymentTab(i).payment_date;
20569 
20570                          l_maturity_date_set_flag := TRUE;
20571 
20572                  ELSE
20573 
20574                      /*
20575                       * If we come here, it means that only
20576                       * one of the discount date or the due
20577                       * date is available.
20578                       */
20579                      IF (l_temp_discount_date IS NOT NULL) THEN
20580 
20581                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20582                          print_debuginfo(l_module_name, 'Setting '
20583                              || 'maturity date to discount date '
20584                              || l_temp_discount_date
20585                              || ' for payment '
20586                              || x_paymentTab(i).payment_id
20587                              || ' because no due date available.'
20588                              );
20589      END IF;
20590                          x_paymentTab(i).maturity_date :=
20591                              l_temp_discount_date;
20592 
20593                          l_maturity_date_set_flag := TRUE;
20594 
20595                      ELSE
20596 
20597                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20598                          print_debuginfo(l_module_name, 'Setting '
20599                              || 'maturity date to due date '
20600                              || l_temp_due_date
20601                              || ' for payment '
20602                              || x_paymentTab(i).payment_id
20603                              || ' because no discount date available.'
20604                              );
20605      END IF;
20606                          x_paymentTab(i).maturity_date := l_temp_due_date;
20607 
20608                          l_maturity_date_set_flag := TRUE;
20609 
20610                      END IF;
20611 
20612                  END IF; -- if discount date and due date are not null
20613 
20614              END IF; -- if maturity date is not set for this payment
20615 
20616              /*
20617               * If all our efforts to calculate maturity date for
20618               * this payment have failed, log it.
20619               */
20620              IF (l_maturity_date_set_flag = FALSE) THEN
20621 
20622                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20623                  print_debuginfo(l_module_name, 'Maturity date '
20624                      || 'could not be derived for payment '
20625                      || x_paymentTab(i).payment_id
20626                      );
20627      END IF;
20628                  /*
20629                   * This should never happen; raise an
20630                   * exception.
20631                   */
20632 
20633                  print_debuginfo(l_module_name, 'Maturity date is a must '
20634                      || 'for a bill payable. Aborting ..',
20635                      FND_LOG.LEVEL_UNEXPECTED
20636                      );
20637 
20638                  APP_EXCEPTION.RAISE_EXCEPTION;
20639 
20640              END IF;
20641 
20642          ELSE
20643 
20644              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20645              print_debuginfo(l_module_name, 'Payment '
20646                  || x_paymentTab(i).payment_id
20647                  || ' is not a future dated payment'
20648                  );
20649      END IF;
20650          END IF; -- if bills payable flag on pmt is 'Y'
20651 
20652      END LOOP; -- for each payment
20653 
20654      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20655      print_debuginfo(l_module_name, 'EXIT');
20656      END IF;
20657   EXCEPTION
20658    WHEN OTHERS THEN
20659    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
20660                  FND_LOG.LEVEL_UNEXPECTED);
20661              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
20662                  FND_LOG.LEVEL_UNEXPECTED);
20663    print_debuginfo(l_module_name, l_module_name||':Exception while performing performMaturityDateCalculation');
20664    RAISE;
20665  END performMaturityDateCalculation;
20666 
20667 /*--------------------------------------------------------------------
20668  | NAME:
20669  |     loadPmtMethodMaturityDays
20670  |
20671  | PURPOSE:
20672  |
20673  |
20674  |
20675  | PARAMETERS:
20676  |     IN
20677  |
20678  |     OUT
20679  |
20680  |
20681  | RETURNS:
20682  |
20683  | NOTES:
20684  |
20685  *---------------------------------------------------------------------*/
20686  PROCEDURE loadPmtMethodMaturityDays(
20687      x_maturityDaysTab    IN OUT NOCOPY pmtMethodMaturityDaysTab
20688      )
20689  IS
20690  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
20691                                              '.loadPmtMethodMaturityDays';
20692 
20693  CURSOR c_maturity_days
20694  IS
20695  SELECT
20696      payment_method_code,
20697      maturity_date_offset_days
20698  FROM
20699      IBY_PAYMENT_METHODS_VL
20700  WHERE
20701      support_bills_payable_flag = 'Y'
20702  ;
20703 
20704  BEGIN
20705 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20706      print_debuginfo(l_module_name, 'ENTER');
20707 	 END IF;
20708 
20709      OPEN  c_maturity_days;
20710      FETCH c_maturity_days BULK COLLECT INTO x_maturityDaysTab;
20711      CLOSE c_maturity_days;
20712 
20713      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20714      print_debuginfo(l_module_name, 'Fetched '
20715          || x_maturityDaysTab.COUNT
20716          || ' records.'
20717          );
20718 
20719      print_debuginfo(l_module_name, 'EXIT');
20720      END IF;
20721  END loadPmtMethodMaturityDays;
20722 
20723 
20724 
20725   /*--------------------------------------------------------------------
20726  | NAME:
20727  |     performMaturityDateCalculation
20728  |
20729  | PURPOSE:
20730  |
20731  |
20732  |
20733  | PARAMETERS:
20734  |     IN
20735  |
20736  |     OUT
20737  |
20738  |
20739  | RETURNS:
20740  |
20741  | NOTES:
20742  |
20743  *---------------------------------------------------------------------*/
20744  PROCEDURE performMaturityDateCalculation(
20745      --x_paymentTab    IN OUT NOCOPY paymentTabType
20746        p_trx_mat_index IN BINARY_INTEGER
20747      )
20748  IS
20749  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
20750                                              '.performMaturityDateCalculation';
20751  --l_maturity_days_tab      pmtMethodMaturityDaysTab;
20752  l_maturity_days_offset   IBY_PAYMENT_METHODS_VL.maturity_date_offset_days%TYPE;
20753  l_maturity_date_set_flag BOOLEAN := FALSE;
20754  l_temp_discount_date     DATE := NULL;
20755  l_temp_due_date          DATE := NULL;
20756 
20757  BEGIN
20758 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20759      print_debuginfo(l_module_name, 'ENTER');
20760 	 END IF;
20761 
20762      /*
20763       * Load up all the payment methods that support future
20764       * dated payments along with their maturity offset days.
20765       * We will be adding the offset days (if available) to the
20766       * payment date to arrive at the maturity date.
20767       */
20768      --loadPmtMethodMaturityDays(l_maturity_days_tab);
20769 
20770      /*
20771       * Loop through all the payments, setting maturity dates
20772       * for each future dated payment.
20773       */
20774      -- FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
20775 
20776          /* initialize flag before each iteration */
20777          l_maturity_date_set_flag := FALSE;
20778 
20779          /*
20780           * For each payment that is a future dated payment
20781           * determine the maturity date.
20782           */
20783          IF (IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(p_trx_mat_index) = 'Y') THEN
20784 
20785              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20786  print_debuginfo(l_module_name, 'Payment '
20787                  || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20788                  || ' is a future dated payment'
20789                  );
20790             END IF;
20791              /*
20792               * ATTEMPT 1:
20793               *
20794               * Try to get the maturity date offset days from the
20795               * payment method and add this to the payment date on
20796               * the payment to arrive at the maturity date.
20797               */
20798              l_maturity_days_offset := getMaturityDaysForPmtMethod(
20799                                            IBY_PAYGROUP_PUB.pmtTable.payment_method_code(p_trx_mat_index)
20800                                            );
20801 
20802              IF (l_maturity_days_offset <> -1) THEN
20803 
20804                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20805  print_debuginfo(l_module_name, 'Adding '
20806                      || l_maturity_days_offset
20807                      || ' offset days to payment date to arrive at '
20808                      || 'maturity date.'
20809                      );
20810      END IF;
20811                  IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_mat_index) :=
20812                      IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_mat_index) + l_maturity_days_offset;
20813 
20814                  l_maturity_date_set_flag := TRUE;
20815 
20816              ELSE
20817 
20818                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20819  print_debuginfo(l_module_name, 'Maturity date offset not '
20820                      || 'set on payment method '
20821                      || IBY_PAYGROUP_PUB.pmtTable.payment_method_code(p_trx_mat_index)
20822                      || ' (so maturity date needs to be calculated).'
20823                      );
20824      END IF;
20825                  l_maturity_date_set_flag := FALSE;
20826 
20827              END IF;
20828 
20829              /*
20830               * ATTEMPT II:
20831               *
20832               * Set the maturity date based on the earliest
20833               * available discount date from the documents
20834               * on the payment.
20835               *
20836               * Note: Maturity date is also calculated from
20837               * the payment due date in ATTEMPT III below.
20838               *
20839               * The value set of the maturity date will be
20840               * the earliest of (discount date, payment due date).
20841               */
20842 
20843              /* initialize before each iteration */
20844              l_temp_discount_date := NULL;
20845 
20846              IF (l_maturity_date_set_flag = FALSE) THEN
20847 
20848                  BEGIN
20849                  select min(discount_date)
20850                  into l_temp_discount_date
20851                  from iby_docs_in_pmt_gt
20852                  where payment_id = IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20853                  AND discount_date is not null
20854                  AND discount_date >= IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_mat_index);
20855                  EXCEPTION
20856                     WHEN NO_DATA_FOUND THEN
20857                     l_temp_discount_date := NULL;
20858                     WHEN OTHERS THEN
20859                         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20860                         print_debuginfo(l_module_name, 'The query throws OTHERS Exception');
20861                         END IF;
20862                     l_temp_discount_date := NULL;
20863                  END;
20864                  /*
20865                   * The earliest available discount date is one
20866                   * candidate for the maturity date.
20867                   */
20868                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20869  print_debuginfo(l_module_name, 'Earliest available '
20870                      || 'discount date for payment '
20871                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20872                      || ' is '
20873                      || l_temp_discount_date
20874                      );
20875                  END IF;
20876              END IF; -- if maturity date is not set for this payment
20877 
20878              /*
20879               * ATTEMPT III:
20880               *
20881               * Set the maturity date based on the earliest
20882               * available payment due date from the documents
20883               * on the payment.
20884               */
20885 
20886              /* initialize before each iteration */
20887              l_temp_due_date := NULL;
20888 
20889              IF (l_maturity_date_set_flag = FALSE) THEN
20890 
20891                BEGIN
20892                  select min(payment_due_date)
20893                  into l_temp_due_date from iby_docs_in_pmt_gt
20894                  where payment_id = IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20895                  AND payment_due_date is not null
20896                  AND payment_due_date >= IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_mat_index);
20897                  EXCEPTION
20898                     WHEN NO_DATA_FOUND THEN
20899                     l_temp_due_date := NULL;
20900                     WHEN OTHERS THEN
20901                         IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20902                         print_debuginfo(l_module_name, 'The query throws OTHERS Exception');
20903                         END IF;
20904                     l_temp_due_date := NULL;
20905                END;
20906 
20907                  /*
20908                   * The earliest available due date is the
20909                   * other candidate for the maturity date.
20910                   */
20911                  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20912                  print_debuginfo(l_module_name, 'Earliest available '
20913                      || 'due date for payment '
20914                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20915                      || ' is '
20916                      || l_temp_due_date
20917                      );
20918                  END IF;
20919                  /*
20920                   * Fix for bug 5334177:
20921                   *
20922                   * Maturity Date = EARLIEST (ATTEMPT II, ATTEMPT III)
20923                   *
20924                   * Set the calculated maturity date on the
20925                   * payment as follows:
20926                   *
20927                   * 1. Maturity date is earliest of
20928                   *    (discount date, due date).
20929                   *
20930                   * 2. If either value is not available
20931                   *    use the other.
20932                   *
20933                   * 3. If both values are not available
20934                   *    use the payment date on the
20935                   *    payment as the maturity date.
20936                   */
20937 
20938                  IF (l_temp_discount_date IS NOT NULL AND
20939                      l_temp_due_date      IS NOT NULL) THEN
20940 
20941                      IF (l_temp_discount_date <= l_temp_due_date) THEN
20942 
20943                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20944  print_debuginfo(l_module_name, 'Setting '
20945                              || 'maturity date to discount date '
20946                              || l_temp_discount_date
20947                              || ' for payment '
20948                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20949                              || ' because it is earlier '
20950                              || 'than due date '
20951                              || l_temp_due_date
20952                              );
20953      END IF;
20954                          IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_mat_index) :=
20955                              l_temp_discount_date;
20956 
20957                          l_maturity_date_set_flag := TRUE;
20958 
20959                      ELSE
20960 
20961                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20962  print_debuginfo(l_module_name, 'Setting '
20963                              || 'maturity date to due date '
20964                              || l_temp_due_date
20965                              || ' for payment '
20966                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20967                              || ' because it is earlier '
20968                              || 'than discount date '
20969                              || l_temp_discount_date
20970                              );
20971      END IF;
20972                          IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_mat_index) := l_temp_due_date;
20973 
20974                          l_maturity_date_set_flag := TRUE;
20975 
20976                      END IF;
20977 
20978                  ELSIF (l_temp_discount_date IS NULL AND
20979                         l_temp_due_date      IS NULL) THEN
20980 
20981                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
20982  print_debuginfo(l_module_name, 'Defaulting '
20983                              || 'maturity date to payment date '
20984                              || IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_mat_index)
20985                              || ' for payment '
20986                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
20987                              || ' because both discount and due '
20988                              || 'dates are not available.'
20989                              );
20990      END IF;
20991                          IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_mat_index) :=
20992                              IBY_PAYGROUP_PUB.pmtTable.payment_date(p_trx_mat_index);
20993 
20994                          l_maturity_date_set_flag := TRUE;
20995 
20996                  ELSE
20997 
20998                      /*
20999                       * If we come here, it means that only
21000                       * one of the discount date or the due
21001                       * date is available.
21002                       */
21003                      IF (l_temp_discount_date IS NOT NULL) THEN
21004 
21005                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21006  print_debuginfo(l_module_name, 'Setting '
21007                              || 'maturity date to discount date '
21008                              || l_temp_discount_date
21009                              || ' for payment '
21010                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
21011                              || ' because no due date available.'
21012                              );
21013      END IF;
21014                          IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_mat_index) :=
21015                              l_temp_discount_date;
21016 
21017                          l_maturity_date_set_flag := TRUE;
21018 
21019                      ELSE
21020 
21021                          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21022  print_debuginfo(l_module_name, 'Setting '
21023                              || 'maturity date to due date '
21024                              || l_temp_due_date
21025                              || ' for payment '
21026                              || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
21027                              || ' because no discount date available.'
21028                              );
21029      END IF;
21030                          IBY_PAYGROUP_PUB.pmtTable.maturity_date(p_trx_mat_index) := l_temp_due_date;
21031 
21032                          l_maturity_date_set_flag := TRUE;
21033 
21034                      END IF;
21035 
21036                  END IF; -- if discount date and due date are not null
21037 
21038              END IF; -- if maturity date is not set for this payment
21039 
21040              /*
21041               * If all our efforts to calculate maturity date for
21042               * this payment have failed, log it.
21043               */
21044              IF (l_maturity_date_set_flag = FALSE) THEN
21045 
21046 
21047  print_debuginfo(l_module_name, 'Maturity date '
21048                      || 'could not be derived for payment '
21049                      || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
21050                      );
21051 
21052                  /*
21053                   * This should never happen; raise an
21054                   * exception.
21055                   */
21056 
21057  print_debuginfo(l_module_name, 'Maturity date is a must '
21058                      || 'for a bill payable. Aborting ..',
21059                      FND_LOG.LEVEL_UNEXPECTED
21060                      );
21061 
21062                  APP_EXCEPTION.RAISE_EXCEPTION;
21063 
21064              END IF;
21065 
21066          ELSE
21067 
21068              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21069  print_debuginfo(l_module_name, 'Payment '
21070                  || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_mat_index)
21071                  || ' is not a future dated payment'
21072                  );
21073      END IF;
21074          END IF; -- if bills payable flag on pmt is 'Y'
21075 
21076     --     END LOOP; -- for each payment
21077 
21078      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21079  print_debuginfo(l_module_name, 'EXIT');
21080      END IF;
21081  EXCEPTION
21082    WHEN OTHERS THEN
21083    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
21084                  FND_LOG.LEVEL_UNEXPECTED);
21085              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
21086                  FND_LOG.LEVEL_UNEXPECTED);
21087    print_debuginfo(l_module_name, l_module_name||':Exception while performing performMaturityDateCalculation');
21088    RAISE;
21089  END performMaturityDateCalculation;
21090 
21091 
21092 
21093 /*--------------------------------------------------------------------
21094  | NAME:
21095  |     getMaturityDaysForPmtMethod
21096  |
21097  | PURPOSE:
21098  |
21099  |
21100  |
21101  | PARAMETERS:
21102  |     IN
21103  |
21104  |     OUT
21105  |
21106  |
21107  | RETURNS:
21108  |
21109  | NOTES:
21110  |
21111  *---------------------------------------------------------------------*/
21112  FUNCTION getMaturityDaysForPmtMethod(
21113      p_pmt_method_code    IN  IBY_PAYMENTS_ALL.payment_method_code%TYPE,
21114      p_maturityDaysTab    IN  pmtMethodMaturityDaysTab
21115      ) RETURN NUMBER
21116  IS
21117  l_maturity_days_offset IBY_PAYMENT_METHODS_VL.maturity_date_offset_days%TYPE
21118      := -1;
21119  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
21120                                              '.getMaturityDaysForPmtMethod';
21121  BEGIN
21122 
21123      IF (p_maturityDaysTab.COUNT = 0) THEN
21124 
21125          l_maturity_days_offset := -1;
21126          RETURN l_maturity_days_offset;
21127 
21128      END IF;
21129 
21130      FOR i IN p_maturityDaysTab.FIRST .. p_maturityDaysTab.LAST LOOP
21131 
21132          IF (p_pmt_method_code = p_maturityDaysTab(i).pmt_method_cd) THEN
21133 
21134              l_maturity_days_offset := p_maturityDaysTab(i).
21135                                            maturity_offset_days;
21136 
21137              RETURN l_maturity_days_offset;
21138 
21139          END IF;
21140 
21141      END LOOP;
21142 
21143      /*
21144       * Return -1 if we could not find the given
21145       * payment method.
21146       */
21147 
21148      l_maturity_days_offset := -1;
21149 
21150      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21151      print_debuginfo(l_module_name, 'Given payment method code '
21152          || p_pmt_method_code
21153          || ' was not found in list of payment methods which '
21154          || 'support future dated payments. Returning -1.'
21155          );
21156      END IF;
21157      RETURN l_maturity_days_offset;
21158 
21159  END getMaturityDaysForPmtMethod;
21160 
21161 /*--------------------------------------------------------------------
21162  | NAME:
21163  |     getMaturityDaysForPmtMethod
21164  |
21165  | PURPOSE:
21166  |
21167  |
21168  |
21169  | PARAMETERS:
21170  |     IN
21171  |
21172  |     OUT
21173  |
21174  |
21175  | RETURNS:
21176  |
21177  | NOTES:
21178  |
21179  *---------------------------------------------------------------------*/
21180  FUNCTION getMaturityDaysForPmtMethod(
21181      p_pmt_method_code    IN  IBY_PAYMENTS_ALL.payment_method_code%TYPE
21182  --    p_maturityDaysTab    IN  pmtMethodMaturityDaysTab
21183      ) RETURN NUMBER
21184  IS
21185  l_maturity_days_offset IBY_PAYMENT_METHODS_VL.maturity_date_offset_days%TYPE := -1;
21186  --l_payment_method_code IBY_PAYMENT_METHODS_VL.payment_method_code%TYPE;
21187  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
21188                                              '.getMaturityDaysForPmtMethod';
21189  BEGIN
21190   IF(maturity_date_tbl.EXISTS(p_pmt_method_code)) THEN
21191        IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21192         print_debuginfo(l_module_name, 'Getting the data from Cache For Payment Method Code ' || p_pmt_method_code);
21193        END IF;
21194         l_maturity_days_offset  := maturity_date_tbl(p_pmt_method_code);
21195   ELSE
21196     BEGIN
21197           IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21198           print_debuginfo(l_module_name, 'Getting the data from DB For Payment Method Code ' || p_pmt_method_code);
21199           END IF;
21200              SELECT maturity_date_offset_days
21201              INTO l_maturity_days_offset
21202              FROM IBY_PAYMENT_METHODS_VL
21203              WHERE support_bills_payable_flag = 'Y'
21204              AND payment_method_code = p_pmt_method_code;
21205     EXCEPTION
21206            WHEN NO_DATA_FOUND THEN
21207            --l_payment_method_code := null;
21208            l_maturity_days_offset := -1;
21209            WHEN OTHERS THEN
21210            --l_payment_method_code := null;
21211            l_maturity_days_offset := -1;
21212      END;
21213      --maturity_date_tbl(p_pmt_method_code).payment_method_code := l_payment_method_code;
21214      maturity_date_tbl(p_pmt_method_code) := l_maturity_days_offset;
21215   END IF;
21216      IF(l_maturity_days_offset = -1) THEN
21217              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21218                   print_debuginfo(l_module_name, 'Given payment method code '
21219                  || p_pmt_method_code
21220                  || ' was not found in list of payment methods which '
21221                  || 'support future dated payments. Returning -1.'
21222                  );
21223              END IF;
21224      ELSE
21225            IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21226                 print_debuginfo(l_module_name, 'Given payment method code '
21227                || p_pmt_method_code
21228                || ' is returning the l_maturity_days_offset as '
21229                || l_maturity_days_offset
21230                );
21231 
21232             END IF;
21233       END IF;
21234 
21235   RETURN l_maturity_days_offset;
21236 
21237  END getMaturityDaysForPmtMethod;
21238 
21239 
21240 /*--------------------------------------------------------------------
21241  | NAME:
21242  |     refreshDocAndPmtAmounts
21243  |
21244  | PURPOSE:
21245  |     This method is called once per payment after credit memo
21246  |     adjustments for that payment are complete. This method
21247  |     will refresh the document and payment amounts PLSQL tables
21248  |     to reflect the credit memo adjustments that were performed.
21249  |
21250  | PARAMETERS:
21251  |     IN
21252  |
21253  |     OUT
21254  |
21255  |
21256  | RETURNS:
21257  |
21258  | NOTES:
21259  |
21260  *---------------------------------------------------------------------*/
21261  PROCEDURE refreshDocAndPmtAmounts(
21262      p_adjustedPmtId      IN            IBY_PAYMENTS_ALL.payment_id%TYPE,
21263      p_adjustedNegDocsTab IN            docsInPaymentTabType,
21264      x_paymentTab         IN OUT NOCOPY paymentTabType,
21265      x_docsInPmtTab       IN OUT NOCOPY docsInPaymentTabType
21266      )
21267  IS
21268  BEGIN
21269 
21270      /*
21271       * We have just finished making credit memo adjustments
21272       * for a particular payment.
21273       *
21274       * Adjusted negative values would be stored in
21275       * l_neg_docs_array (Positive values are not touched
21276       * by the credit memo adjustment logic). Copy back
21277       * these adjusted values into x_docsInPmtTab and
21278       * x_paymentTab so that these changes are reflected
21279       * back to the caller.
21280       *
21281       * The adjusted values in x_docsInPmtTab and x_paymentTab
21282       * will be used in updating the database.
21283       */
21284      FOR n in p_adjustedNegDocsTab.FIRST .. p_adjustedNegDocsTab.LAST LOOP
21285 
21286          IF (p_adjustedNegDocsTab(n).payment_id = p_adjustedPmtId) THEN
21287 
21288              FOR p in x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
21289 
21290                  IF (x_docsInPmtTab(p).payment_id = p_adjustedPmtId) THEN
21291 
21292                      IF (p_adjustedNegDocsTab(n).document_id =
21293                          x_docsInPmtTab(p).document_id) THEN
21294 
21295                          /*
21296                           * Store back the adjusted amount value
21297                           * for this document.
21298                           */
21299                          x_docsInPmtTab(p).document_amount :=
21300                              p_adjustedNegDocsTab(n).document_amount;
21301 
21302                          /*
21303                           * Since there will only be one document with
21304                           * a particular document id in x_docsInPmtTab,
21305                           * we can exit the loop as soon as we find it.
21306                           */
21307                          EXIT;
21308 
21309                      END IF;
21310 
21311                  END IF;
21312 
21313              END LOOP; -- for each doc in x_docsInPmtTab
21314 
21315          END IF;
21316 
21317      END LOOP; -- for each doc in p_adjustedNegDocsTab
21318 
21319      /*
21320       * After adjusting the document amount, we must make sure
21321       * adjust the payment amount as well:
21322       *
21323       * payment amount = SUM (document amounts)
21324       */
21325      FOR q in x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
21326 
21327          IF (x_paymentTab(q).payment_id = p_adjustedPmtId) THEN
21328 
21329              /* reset payment amount to zero */
21330              x_paymentTab(q).payment_amount := 0;
21331 
21332              /*
21333               * Set payment amount to sum of all document amounts
21334               * that constitute this payment.
21335               */
21336              FOR r in x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
21337 
21338                  IF (x_docsInPmtTab(r).payment_id = p_adjustedPmtId) THEN
21339 
21340                      x_paymentTab(q).payment_amount :=
21341                          x_paymentTab(q).payment_amount
21342                              + x_docsInPmtTab(r).document_amount;
21343 
21344                  END IF;
21345 
21346              END LOOP;
21347 
21348              /*
21349               * Since there will only be one payment in x_paymentTab
21350               * we can exit the loop as soon as we find it.
21351               */
21352              EXIT;
21353 
21354          END IF;
21355 
21356      END LOOP;
21357 
21358  END refreshDocAndPmtAmounts;
21359 
21360 /*--------------------------------------------------------------------
21361  | NAME:
21362  |     getListOfQualifyingNegPmts
21363  |
21364  | PURPOSE:
21365  |
21366  |
21367  |
21368  | PARAMETERS:
21369  |     IN
21370  |
21371  |     OUT
21372  |
21373  |
21374  | RETURNS:
21375  |
21376  | NOTES:
21377  |
21378  *---------------------------------------------------------------------*/
21379  PROCEDURE getListOfQualifyingNegPmts(
21380      x_negPmtsTab    IN OUT NOCOPY pmtIdsTab,
21381      p_paymentTab    IN paymentTabType,
21382      p_docsInPmtTab  IN docsInPaymentTabType
21383      )
21384  IS
21385  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
21386                                              '.getListOfQualifyingNegPmts';
21387  l_already_added_flag BOOLEAN := FALSE;
21388  BEGIN
21389 
21390      /*
21391       * Find all payments that satisfy the following criteria:
21392       * 1. Payment amount must be negative
21393       * 2. Payment must contain at least one positive document
21394       *    payable.
21395       * 3. Payment must not be pay alone.
21396       *
21397       * 1. and 2. imply that the payment is not pay alone, so
21398       * condition 3. need not be explicitly checked.
21399       *
21400       * Payments that satisfy these criteria qualify for
21401       * credit memo adjustment.
21402       */
21403      FOR j IN p_paymentTab.FIRST .. p_paymentTab.LAST LOOP
21404 
21405          /* Payment amount is negative */
21406          IF (p_paymentTab(j).payment_amount < 0) THEN
21407 
21408              FOR k IN p_docsInPmtTab.FIRST .. p_docsInPmtTab.LAST LOOP
21409 
21410                  IF (p_docsInPmtTab(k).payment_id =
21411                      p_paymentTab(j).payment_id) THEN
21412 
21413                      /* Pmt contains a positive document */
21414                      IF (p_docsInPmtTab(k).document_amount > 0) THEN
21415 
21416                          /*
21417                           * This payment satisfies the criteria
21418                           * for credit memo adjustment.
21419                           */
21420 
21421                          /*
21422                           * Check if payment already in list
21423                           * of qualifying payments
21424                           */
21425                          l_already_added_flag := checkIfPmtAlreadyAdded(
21426                                                      p_paymentTab(j).
21427                                                          payment_id,
21428                                                      x_negPmtsTab);
21429 
21430                          /*
21431                           * If payment not already in qualifying
21432                           * list, add payment to the list.
21433                           */
21434                          IF (l_already_added_flag = FALSE) THEN
21435 
21436                              x_negPmtsTab(x_negPmtsTab.COUNT + 1)
21437                                  := p_paymentTab(j).payment_id;
21438 
21439                              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21440  print_debuginfo(l_module_name, 'Payment id '
21441                                  || p_paymentTab(j).payment_id
21442                                  || ' qualifies for '
21443                                  || 'credit memo adjustment.'
21444                                  );
21445 			     END IF;
21446                          END IF;
21447 
21448                      END IF; -- if doc amount greater than zero
21449 
21450                  END IF; -- if document matches the payment id
21451 
21452              END LOOP; -- loop through all documents of this payment
21453 
21454          END IF; -- if payment amount less than zero
21455 
21456      END LOOP; -- loop through all payments
21457 
21458  END getListOfQualifyingNegPmts;
21459 
21460 /*--------------------------------------------------------------------
21461  | NAME:
21462  |     populateLEsOnPmts
21463  |
21464  | PURPOSE:
21465  |
21466  |
21467  | PARAMETERS:
21468  |     IN
21469  |
21470  |
21471  |     OUT
21472  |
21473  |
21474  | RETURNS:
21475  |
21476  | NOTES:
21477  |
21478  *---------------------------------------------------------------------*/
21479  PROCEDURE populateLEsOnPmts(
21480      x_paymentTab      IN OUT NOCOPY paymentTabType,
21481      p_bankAccountLEs  IN            bankAccountLETabType
21482      )
21483  IS
21484  BEGIN
21485 
21486      IF (x_paymentTab.COUNT = 0 OR p_bankAccountLEs.COUNT = 0) THEN
21487          RETURN;
21488      END IF;
21489 
21490      /*
21491       * Loop through all the created payments, searching for
21492       * internal bank account ids. If we find a match, assign the
21493       * legal entity id on the internal bank account to the payment.
21494       */
21495      FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
21496 
21497          FOR j in p_bankAccountLEs.FIRST .. p_bankAccountLEs.LAST LOOP
21498 
21499              IF (x_paymentTab(i).internal_bank_account_id =
21500                  p_bankAccountLEs(j).int_bank_acct_id) THEN
21501 
21502                  x_paymentTab(i).legal_entity_id := p_bankAccountLEs(j).le_id;
21503 
21504              END IF;
21505 
21506          END LOOP;
21507 
21508      END LOOP;
21509 
21510  END populateLEsOnPmts;
21511 
21512 /*--------------------------------------------------------------------
21513  | NAME:
21514  |     printDocsInPmtTab
21515  |
21516  | PURPOSE:
21517  |     Prints out the documents and payments within the docsInPaymentTabType
21518  |     PLSQL table. To be used for debug purposes.
21519  |
21520  | PARAMETERS:
21521  |     IN
21522  |
21523  |     OUT
21524  |
21525  |
21526  | RETURNS:
21527  |
21528  | NOTES:
21529  |
21530  *---------------------------------------------------------------------*/
21531  PROCEDURE printDocsInPmtTab(
21532      p_docsInPmtTab    IN docsInPaymentTabType
21533      )
21534  IS
21535  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.printDocsInPmtTab';
21536  BEGIN
21537 
21538      IF (p_docsInPmtTab.COUNT = 0) THEN
21539          RETURN;
21540      END IF;
21541 
21542      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21543      print_debuginfo(l_module_name, 'List of docs/pmts: ');
21544      END IF;
21545      FOR i in p_docsInPmtTab.FIRST..p_docsInPmtTab.LAST LOOP
21546          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21547          print_debuginfo(l_module_name, 'Payment: '
21548              || p_docsInPmtTab(i).payment_id
21549              || ', document: '
21550              || p_docsInPmtTab(i).document_id
21551              || ', document amt: '
21552              || p_docsInPmtTab(i).document_amount
21553              || ', document curr: '
21554              || p_docsInPmtTab(i).document_currency
21555              );
21556          END IF;
21557      END LOOP;
21558 
21559  END printDocsInPmtTab;
21560 
21561 /*--------------------------------------------------------------------
21562  | NAME:
21563  |     handleJapaneseBankCharges
21564  |
21565  | PURPOSE:
21566  |
21567  |
21568  |
21569  | PARAMETERS:
21570  |     IN
21571  |
21572  |     OUT
21573  |
21574  |
21575  | RETURNS:
21576  |
21577  | NOTES:
21578  |
21579  *---------------------------------------------------------------------*/
21580  PROCEDURE handleJapaneseBankCharges(
21581      p_cap_payreq_cd  IN            VARCHAR2,
21582      p_cap_id         IN            NUMBER,
21583      x_paymentTab     IN OUT NOCOPY paymentTabType,
21584      x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
21585      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
21586      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
21587      )
21588  IS
21589 
21590  /* these two are passed to calling app via hook */
21591  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
21592  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
21593 
21594  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
21595                                              '.handleJapaneseBankCharges';
21596 
21597  l_hook_name        VARCHAR2(500);
21598  l_stmt             VARCHAR2(1000);
21599 
21600  /* used in invocation of callout procedure */
21601  l_api_version    CONSTANT NUMBER := 1.0;
21602  l_msg_count      NUMBER;
21603  l_msg_data       VARCHAR2(2000);
21604 
21605  l_return_status  VARCHAR2(500);
21606 
21607  /*
21608   * Package name can be hardcoded since we know that this hook
21609   * is only called by AP.
21610   */
21611  l_pkg_name    CONSTANT VARCHAR2(100) := 'AP_PMT_CALLOUT_PKG';
21612 
21613  /*
21614   * Implementing the hook is optional for the calling app.
21615   * If the calling app does not implement the hook, then
21616   * the call to the hook will result in ORA-06576 error.
21617   *
21618   * There is no exception name associated with this code, so
21619   * we create one called 'PROCEDURE_NOT_IMPLEMENTED'. If this
21620   * exception occurs, it is not fatal: we log the error and
21621   * proceed.
21622   *
21623   * If, on the other hand, the calling app implements the
21624   * hook, but the hook throws an exception, it is fatal
21625   * and we must abort the program (this will be caught
21626   * in WHEN OTHERS block).
21627   */
21628  PROCEDURE_NOT_IMPLEMENTED EXCEPTION;
21629  PRAGMA EXCEPTION_INIT(PROCEDURE_NOT_IMPLEMENTED, -6576);
21630 
21631  BEGIN
21632 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21633      print_debuginfo(l_module_name, 'ENTER');
21634 	 END IF;
21635 
21636      /*
21637       * Populate the hook tables with payment data.
21638       */
21639      performPreHookProcess(p_cap_payreq_cd, p_cap_id, x_paymentTab,
21640          x_docsInPmtTab, l_hookPaymentTab, l_hookDocsInPmtTab);
21641 
21642      /*
21643       * Now try to call the external app's implementation of the hook.
21644       * The calling app may or may not have implemented the hook, so
21645       * it's not fatal if the implementation does not exist.
21646       */
21647      l_hook_name := l_pkg_name || '.' || 'ap_JapanBankChargeHook';
21648 
21649      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21650      print_debuginfo(l_module_name, 'Attempting to call hook: '
21651          || l_hook_name);
21652        END IF;
21653      l_stmt := 'CALL '|| l_hook_name || '(:1, :2, :3, :4, :5, :6)';
21654 
21655      BEGIN
21656 
21657          EXECUTE IMMEDIATE
21658              (l_stmt)
21659          USING
21660              IN  l_api_version,
21661              IN  FND_API.G_FALSE,
21662              IN  FND_API.G_FALSE,
21663              OUT l_return_status,
21664              OUT l_msg_count,
21665              OUT l_msg_data
21666          ;
21667 
21668      EXCEPTION
21669 
21670          WHEN PROCEDURE_NOT_IMPLEMENTED THEN
21671              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21672              print_debuginfo(l_module_name, 'Japanese bank charge hook "'
21673                  || l_hook_name
21674                  || '" not implemented by external application.'
21675                  );
21676 
21677              print_debuginfo(l_module_name, 'Skipping hook call.');
21678 	     END IF;
21679          WHEN OTHERS THEN
21680 
21681              print_debuginfo(l_module_name, 'Fatal: Japanese bank charge '
21682                  || 'hook ''' || l_hook_name
21683                  || ''', generated exception.',
21684                  FND_LOG.LEVEL_UNEXPECTED
21685                  );
21686 
21687              print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
21688                  FND_LOG.LEVEL_UNEXPECTED);
21689              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
21690                  FND_LOG.LEVEL_UNEXPECTED);
21691 
21692              /*
21693               * Propogate exception to caller.
21694               */
21695              RAISE;
21696      END;
21697 
21698      /*
21699       * If Japanese bank charge hook returned an error response,
21700       * raise an exception.
21701       */
21702      IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
21703 
21704 
21705          print_debuginfo(l_module_name, 'Fatal: Japanese bank charge hook '''
21706              || l_hook_name  || ''' returned error status code: '
21707              || l_return_status,
21708              FND_LOG.LEVEL_UNEXPECTED
21709              );
21710 
21711          print_debuginfo(l_module_name, 'Raising exception .. ',
21712              FND_LOG.LEVEL_UNEXPECTED);
21713 
21714          APP_EXCEPTION.RAISE_EXCEPTION;
21715 
21716      END IF;
21717 
21718      /*
21719       * Read back the adjusted payment data.
21720       */
21721      performPostHookProcess(x_paymentTab, x_docsInPmtTab, l_hookPaymentTab,
21722          l_hookDocsInPmtTab, x_docErrorTab, x_errTokenTab);
21723 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21724      print_debuginfo(l_module_name, 'EXIT');
21725 	 END IF;
21726 
21727  END handleJapaneseBankCharges;
21728 
21729 
21730 /*--------------------------------------------------------------------
21731  | NAME:
21732  |     handleJapaneseBankCharges
21733  |
21734  | PURPOSE:
21735  |
21736  |
21737  |
21738  | PARAMETERS:
21739  |     IN
21740  |
21741  |     OUT
21742  |
21743  |
21744  | RETURNS:
21745  |
21746  | NOTES:
21747  |
21748  *---------------------------------------------------------------------*/
21749  PROCEDURE handleJapaneseBankCharges(
21750      p_cap_payreq_cd  IN            VARCHAR2,
21751      p_ppr_id	      IN            NUMBER,
21752      p_cap_id         IN            NUMBER,
21753  --    x_paymentTab     IN OUT NOCOPY paymentTabType,
21754  --     x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
21755      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
21756      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
21757      )
21758  IS
21759 
21760  /* these two are passed to calling app via hook */
21761  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
21762  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
21763 
21764  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
21765                                              '.handleJapaneseBankCharges';
21766 
21767  l_hook_name        VARCHAR2(500);
21768  l_stmt             VARCHAR2(1000);
21769 
21770  /* used in invocation of callout procedure */
21771  l_api_version    CONSTANT NUMBER := 1.0;
21772  l_msg_count      NUMBER;
21773  l_msg_data       VARCHAR2(2000);
21774 
21775  l_return_status  VARCHAR2(500);
21776  l_DocsInPmtCount NUMBER;
21777  l_prehook_count  NUMBER;
21778 
21779  /*
21780   * Package name can be hardcoded since we know that this hook
21781   * is only called by AP.
21782   */
21783  l_pkg_name    CONSTANT VARCHAR2(100) := 'AP_PMT_CALLOUT_PKG';
21784 
21785  /*
21786   * Implementing the hook is optional for the calling app.
21787   * If the calling app does not implement the hook, then
21788   * the call to the hook will result in ORA-06576 error.
21789   *
21790   * There is no exception name associated with this code, so
21791   * we create one called 'PROCEDURE_NOT_IMPLEMENTED'. If this
21792   * exception occurs, it is not fatal: we log the error and
21793   * proceed.
21794   *
21795   * If, on the other hand, the calling app implements the
21796   * hook, but the hook throws an exception, it is fatal
21797   * and we must abort the program (this will be caught
21798   * in WHEN OTHERS block).
21799   */
21800  PROCEDURE_NOT_IMPLEMENTED EXCEPTION;
21801  PRAGMA EXCEPTION_INIT(PROCEDURE_NOT_IMPLEMENTED, -6576);
21802 
21803  BEGIN
21804 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21805      print_debuginfo(l_module_name, 'ENTER');
21806 	 END IF;
21807 
21808      /*
21809       * Populate the hook tables with payment data.
21810       */
21811      /*performPreHookProcess(p_cap_payreq_cd, p_cap_id, x_paymentTab,
21812          x_docsInPmtTab, l_hookPaymentTab, l_hookDocsInPmtTab);*/
21813 
21814     -- print_debuginfo(l_module_name,'Count of x_paymentTab' ||x_paymentTab.COUNT);
21815      performPreHookProcess(p_cap_payreq_cd,p_ppr_id,l_prehook_count,p_cap_id
21816              --x_paymentTab,
21817              --l_hookPaymentTab
21818 	     );
21819 
21820   IF(l_prehook_count <> 0)  THEN
21821 
21822      /*
21823       * Now try to call the external app's implementation of the hook.
21824       * The calling app may or may not have implemented the hook, so
21825       * it's not fatal if the implementation does not exist.
21826       */
21827      l_hook_name := l_pkg_name || '.' || 'ap_JapanBankChargeHook';
21828 
21829      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21830      print_debuginfo(l_module_name, 'Attempting to call hook: '
21831          || l_hook_name);
21832        END IF;
21833      l_stmt := 'CALL '|| l_hook_name || '(:1, :2, :3, :4, :5, :6)';
21834 
21835      BEGIN
21836 
21837          EXECUTE IMMEDIATE
21838              (l_stmt)
21839          USING
21840              IN  l_api_version,
21841              IN  FND_API.G_FALSE,
21842              IN  FND_API.G_FALSE,
21843              OUT l_return_status,
21844              OUT l_msg_count,
21845              OUT l_msg_data
21846          ;
21847 
21848      EXCEPTION
21849 
21850          WHEN PROCEDURE_NOT_IMPLEMENTED THEN
21851              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21852              print_debuginfo(l_module_name, 'Japanese bank charge hook "'
21853                  || l_hook_name
21854                  || '" not implemented by external application.'
21855                  );
21856 
21857              print_debuginfo(l_module_name, 'Skipping hook call.');
21858 	     END IF;
21859          WHEN OTHERS THEN
21860 
21861              print_debuginfo(l_module_name, 'Fatal: Japanese bank charge '
21862                  || 'hook ''' || l_hook_name
21863                  || ''', generated exception.',
21864                  FND_LOG.LEVEL_UNEXPECTED
21865                  );
21866 
21867              print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
21868                  FND_LOG.LEVEL_UNEXPECTED);
21869              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
21870                  FND_LOG.LEVEL_UNEXPECTED);
21871 
21872              /*
21873               * Propogate exception to caller.
21874               */
21875              RAISE;
21876      END;
21877 
21878      /*
21879       * If Japanese bank charge hook returned an error response,
21880       * raise an exception.
21881       */
21882      IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
21883 
21884 
21885          print_debuginfo(l_module_name, 'Fatal: Japanese bank charge hook '''
21886              || l_hook_name  || ''' returned error status code: '
21887              || l_return_status,
21888              FND_LOG.LEVEL_UNEXPECTED
21889              );
21890 
21891          print_debuginfo(l_module_name, 'Raising exception .. ',
21892              FND_LOG.LEVEL_UNEXPECTED);
21893 
21894          APP_EXCEPTION.RAISE_EXCEPTION;
21895 
21896      END IF;
21897 
21898      /*
21899       * Read back the adjusted payment data.
21900       */
21901      performPostHookProcess(
21902          --x_paymentTab,
21903 	 --l_hookPaymentTab,
21904 	 p_cap_payreq_cd,
21905 	 l_prehook_count,
21906          x_docErrorTab, x_errTokenTab);
21907 
21908   ELSE
21909             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21910                  print_debuginfo(l_module_name, 'Value of l_prehook_count is:' || l_prehook_count || 'so not calling any hook');
21911             END IF;
21912   END IF;
21913   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21914      print_debuginfo(l_module_name, 'EXIT');
21915 	 END IF;
21916 
21917  END handleJapaneseBankCharges;
21918 
21919 /*--------------------------------------------------------------------
21920  | NAME:
21921  |     performExtendedWitholding
21922  |
21923  | PURPOSE:
21924  |
21925  |
21926  |
21927  | PARAMETERS:
21928  |     IN
21929  |
21930  |     OUT
21931  |
21932  |
21933  | RETURNS:
21934  |
21935  | NOTES:
21936  |
21937  *---------------------------------------------------------------------*/
21938  PROCEDURE performExtendedWitholding(
21939      p_cap_payreq_cd  IN            VARCHAR2,
21940      p_cap_id         IN            NUMBER,
21941      x_paymentTab     IN OUT NOCOPY paymentTabType,
21942      x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
21943      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
21944      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
21945      )
21946  IS
21947 
21948  /* these two are passed to calling app via hook */
21949  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
21950  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
21951 
21952  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
21953                                              '.performExtendedWitholding';
21954 
21955  l_hook_name        VARCHAR2(500);
21956  l_stmt             VARCHAR2(1000);
21957 
21958  /* used in invocation of callout procedure */
21959  l_api_version    CONSTANT NUMBER := 1.0;
21960  l_msg_count      NUMBER;
21961  l_msg_data       VARCHAR2(2000);
21962 
21963  l_return_status  VARCHAR2(500);
21964 
21965  /*
21966   * Package name can be hardcoded since we know that this hook
21967   * is only called by AP.
21968   */
21969  l_pkg_name    CONSTANT VARCHAR2(100) := 'AP_AWT_CALLOUT_PKG';
21970 
21971  /*
21972   * Implementing the hook is optional for the calling app.
21973   * If the calling app does not implement the hook, then
21974   * the call to the hook will result in ORA-06576 error.
21975   *
21976   * There is no exception name associated with this code, so
21977   * we create one called 'PROCEDURE_NOT_IMPLEMENTED'. If this
21978   * exception occurs, it is not fatal: we log the error and
21979   * proceed.
21980   *
21981   * If, on the other hand, the calling app implements the
21982   * hook, but the hook throws an exception, it is fatal
21983   * and we must abort the program (this will be caught
21984   * in WHEN OTHERS block).
21985   */
21986  PROCEDURE_NOT_IMPLEMENTED EXCEPTION;
21987  PRAGMA EXCEPTION_INIT(PROCEDURE_NOT_IMPLEMENTED, -6576);
21988 
21989  BEGIN
21990 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
21991      print_debuginfo(l_module_name, 'ENTER');
21992 END IF;
21993      /*
21994       * Populate the hook tables with payment data.
21995       */
21996      performPreHookProcess(p_cap_payreq_cd, p_cap_id, x_paymentTab,
21997          x_docsInPmtTab, l_hookPaymentTab, l_hookDocsInPmtTab);
21998 
21999      /*
22000       * Now try to call the external app's implementation of the hook.
22001       * The calling app may or may not have implemented the hook, so
22002       * it's not fatal if the implementation does not exist.
22003       */
22004      l_hook_name := l_pkg_name || '.' || 'zx_paymentsAdjustHook';
22005 
22006      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22007      print_debuginfo(l_module_name, 'Attempting to call hook: '
22008          || l_hook_name);
22009      END IF;
22010      l_stmt := 'CALL '|| l_hook_name || '(:1, :2, :3, :4, :5, :6)';
22011 
22012      BEGIN
22013 
22014          EXECUTE IMMEDIATE
22015              (l_stmt)
22016          USING
22017              IN  l_api_version,
22018              IN  FND_API.G_FALSE,
22019              IN  FND_API.G_FALSE,
22020              OUT l_return_status,
22021              OUT l_msg_count,
22022              OUT l_msg_data
22023          ;
22024 
22025      EXCEPTION
22026 
22027          WHEN PROCEDURE_NOT_IMPLEMENTED THEN
22028              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22029              print_debuginfo(l_module_name, 'Extended withholding hook "'
22030                  || l_hook_name
22031                  || '" not implemented by external application.'
22032                  );
22033 
22034              print_debuginfo(l_module_name, 'Skipping hook call.');
22035      END IF;
22036          WHEN OTHERS THEN
22037 
22038              print_debuginfo(l_module_name, 'Fatal: Extended witholding hook '''
22039                  || l_hook_name  || ''', generated exception. ',
22040                  FND_LOG.LEVEL_UNEXPECTED
22041                  );
22042 
22043              print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
22044                  FND_LOG.LEVEL_UNEXPECTED);
22045              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
22046                  FND_LOG.LEVEL_UNEXPECTED);
22047 
22048              /*
22049               * Propogate exception to caller.
22050               */
22051              RAISE;
22052      END;
22053 
22054      /*
22055       * If extended withholding hook returned an error response,
22056       * raise an exception.
22057       */
22058      IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
22059 
22060 
22061          print_debuginfo(l_module_name, 'Fatal: Extended witholding hook '''
22062              || l_hook_name  || ''' returned error status code: '
22063              || l_return_status,
22064              FND_LOG.LEVEL_UNEXPECTED
22065              );
22066 
22067          print_debuginfo(l_module_name, 'Raising exception .. ',
22068              FND_LOG.LEVEL_UNEXPECTED);
22069 
22070          APP_EXCEPTION.RAISE_EXCEPTION;
22071 
22072      END IF;
22073 
22074      /*
22075       * Read back the adjusted payment data.
22076       */
22077      performPostHookProcess(x_paymentTab, x_docsInPmtTab, l_hookPaymentTab,
22078          l_hookDocsInPmtTab, x_docErrorTab, x_errTokenTab);
22079 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22080      print_debuginfo(l_module_name, 'EXIT');
22081 	 END IF;
22082 
22083  END performExtendedWitholding;
22084 
22085 /*--------------------------------------------------------------------
22086  | NAME:
22087  |     performExtendedWitholding
22088  |
22089  | PURPOSE:
22090  |
22091  |
22092  |
22093  | PARAMETERS:
22094  |     IN
22095  |
22096  |     OUT
22097  |
22098  |
22099  | RETURNS:
22100  |
22101  | NOTES:
22102  |
22103  *---------------------------------------------------------------------*/
22104  PROCEDURE performExtendedWitholding(
22105      p_cap_payreq_cd  IN            VARCHAR2,
22106      p_ppr_id         IN            NUMBER,
22107      p_cap_id         IN            NUMBER,
22108  --    x_paymentTab     IN OUT NOCOPY paymentTabType,
22109  --     x_docsInPmtTab   IN OUT NOCOPY docsInPaymentTabType,
22110      x_docErrorTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
22111      x_errTokenTab    IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
22112      )
22113  IS
22114 
22115  /* these two are passed to calling app via hook */
22116  l_hookPaymentTab    IBY_PAYGROUP_PUB.hookPaymentTabType;
22117  l_hookDocsInPmtTab  IBY_PAYGROUP_PUB.hookDocsInPaymentTabType;
22118 
22119  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME ||
22120                                              '.performExtendedWitholding';
22121 
22122  l_hook_name        VARCHAR2(500);
22123  l_stmt             VARCHAR2(1000);
22124 
22125  /* used in invocation of callout procedure */
22126  l_api_version    CONSTANT NUMBER := 1.0;
22127  l_msg_count      NUMBER;
22128  l_msg_data       VARCHAR2(2000);
22129 
22130  l_return_status  VARCHAR2(500);
22131  l_prehook_count  NUMBER;
22132  l_DocsInPmtCount NUMBER;
22133 
22134  /*
22135   * Package name can be hardcoded since we know that this hook
22136   * is only called by AP.
22137   */
22138  l_pkg_name    CONSTANT VARCHAR2(100) := 'AP_AWT_CALLOUT_PKG';
22139 
22140  /*
22141   * Implementing the hook is optional for the calling app.
22142   * If the calling app does not implement the hook, then
22143   * the call to the hook will result in ORA-06576 error.
22144   *
22145   * There is no exception name associated with this code, so
22146   * we create one called 'PROCEDURE_NOT_IMPLEMENTED'. If this
22147   * exception occurs, it is not fatal: we log the error and
22148   * proceed.
22149   *
22150   * If, on the other hand, the calling app implements the
22151   * hook, but the hook throws an exception, it is fatal
22152   * and we must abort the program (this will be caught
22153   * in WHEN OTHERS block).
22154   */
22155  PROCEDURE_NOT_IMPLEMENTED EXCEPTION;
22156  PRAGMA EXCEPTION_INIT(PROCEDURE_NOT_IMPLEMENTED, -6576);
22157 
22158  BEGIN
22159 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22160      print_debuginfo(l_module_name, 'ENTER');
22161 END IF;
22162      /*
22163       * Populate the hook tables with payment data.
22164       */
22165      /*performPreHookProcess(p_cap_payreq_cd, p_cap_id, x_paymentTab,
22166          x_docsInPmtTab, l_hookPaymentTab, l_hookDocsInPmtTab);*/
22167 
22168     -- print_debuginfo(l_module_name, 'Count of x_paymentTab' ||x_paymentTab.COUNT);
22169      performPreHookProcess(p_cap_payreq_cd, p_ppr_id,l_prehook_count, p_cap_id
22170             --x_paymentTab,
22171             -- l_hookPaymentTab
22172 	    );
22173 
22174  IF(l_prehook_count <> 0)  THEN
22175      /*
22176       * Now try to call the external app's implementation of the hook.
22177       * The calling app may or may not have implemented the hook, so
22178       * it's not fatal if the implementation does not exist.
22179       */
22180 
22181            l_hook_name := l_pkg_name || '.' || 'zx_paymentsAdjustHook';
22182 
22183            IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22184            print_debuginfo(l_module_name, 'Attempting to call hook: '
22185                || l_hook_name);
22186            END IF;
22187            l_stmt := 'CALL '|| l_hook_name || '(:1, :2, :3, :4, :5, :6)';
22188 
22189            BEGIN
22190 
22191                EXECUTE IMMEDIATE
22192                    (l_stmt)
22193                USING
22194                    IN  l_api_version,
22195                    IN  FND_API.G_FALSE,
22196                    IN  FND_API.G_FALSE,
22197                    OUT l_return_status,
22198                    OUT l_msg_count,
22199                    OUT l_msg_data
22200                ;
22201 
22202            EXCEPTION
22203 
22204                WHEN PROCEDURE_NOT_IMPLEMENTED THEN
22205                    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22206                    print_debuginfo(l_module_name, 'Extended withholding hook "'
22207                        || l_hook_name
22208                        || '" not implemented by external application.'
22209                        );
22210 
22211                    print_debuginfo(l_module_name, 'Skipping hook call.');
22212            END IF;
22213                WHEN OTHERS THEN
22214 
22215                    print_debuginfo(l_module_name, 'Fatal: Extended witholding hook '''
22216                        || l_hook_name  || ''', generated exception. ',
22217                        FND_LOG.LEVEL_UNEXPECTED
22218                        );
22219 
22220                    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
22221                        FND_LOG.LEVEL_UNEXPECTED);
22222                    print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
22223                        FND_LOG.LEVEL_UNEXPECTED);
22224 
22225                    /*
22226                     * Propogate exception to caller.
22227                     */
22228                    RAISE;
22229            END;
22230 
22231      /*
22232       * If extended withholding hook returned an error response,
22233       * raise an exception.
22234       */
22235            IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
22236 
22237 
22238                print_debuginfo(l_module_name, 'Fatal: Extended witholding hook '''
22239                    || l_hook_name  || ''' returned error status code: '
22240                    || l_return_status,
22241                    FND_LOG.LEVEL_UNEXPECTED
22242                    );
22243 
22244                print_debuginfo(l_module_name, 'Raising exception .. ',
22245                    FND_LOG.LEVEL_UNEXPECTED);
22246 
22247                APP_EXCEPTION.RAISE_EXCEPTION;
22248 
22249            END IF;
22250 
22251      /*
22252       * Read back the adjusted payment data.
22253       */
22254      performPostHookProcess(
22255          --x_paymentTab, l_hookPaymentTab,
22256 	 p_cap_payreq_cd,
22257 	 l_prehook_count,
22258          x_docErrorTab,
22259 	 x_errTokenTab);
22260 
22261  ELSE
22262             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22263                  print_debuginfo(l_module_name, 'Value of l_prehook_count is:' || l_prehook_count || 'so not calling any hook');
22264             END IF;
22265  END IF;
22266  IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22267      print_debuginfo(l_module_name, 'EXIT');
22268 	 END IF;
22269 
22270  END performExtendedWitholding;
22271 
22272 /*--------------------------------------------------------------------
22273  | NAME:
22274  |     initializePmts
22275  |
22276  | PURPOSE:
22277  |     Sets the default attributes for a created payment such as
22278  |     payment status, process type etc.
22279  |
22280  | PARAMETERS:
22281  |     IN
22282  |
22283  |
22284  |     OUT
22285  |
22286  |
22287  | RETURNS:
22288  |
22289  | NOTES:
22290  |
22291  *---------------------------------------------------------------------*/
22292  PROCEDURE initializePmts(
22293      x_paymentTab      IN OUT NOCOPY paymentTabType
22294      )
22295  IS
22296  BEGIN
22297 
22298      IF (x_paymentTab.COUNT = 0) THEN
22299          RETURN;
22300      END IF;
22301 
22302      FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
22303 
22304          x_paymentTab(i).payment_status                 := 'CREATED';
22305          x_paymentTab(i).process_type                   := 'STANDARD';
22306 
22307          /*
22308           * Fix for bug 5115270:
22309           *
22310           * For all flags, take care not to overwite the flag
22311           * already set.
22312           */
22313          x_paymentTab(i).payments_complete_flag         :=
22314              NVL(x_paymentTab(i).payments_complete_flag,         'N');
22315          x_paymentTab(i).bill_payable_flag              :=
22316              NVL(x_paymentTab(i).bill_payable_flag,              'N');
22317          x_paymentTab(i).exclusive_payment_flag         :=
22318              NVL(x_paymentTab(i).exclusive_payment_flag,         'N');
22319          x_paymentTab(i).separate_remit_advice_req_flag :=
22320              NVL(x_paymentTab(i).separate_remit_advice_req_flag, 'N');
22321          x_paymentTab(i).declare_payment_flag           :=
22322              NVL(x_paymentTab(i).declare_payment_flag,           'N');
22323          x_paymentTab(i).pregrouped_payment_flag        :=
22324              NVL(x_paymentTab(i).pregrouped_payment_flag,        'N');
22325          x_paymentTab(i).stop_confirmed_flag            :=
22326              NVL(x_paymentTab(i).stop_confirmed_flag,            'N');
22327          x_paymentTab(i).stop_released_flag             :=
22328              NVL(x_paymentTab(i).stop_released_flag,             'N');
22329          x_paymentTab(i).stop_request_placed_flag       :=
22330              NVL(x_paymentTab(i).stop_request_placed_flag,       'N');
22331 
22332          x_paymentTab(i).created_by                     := fnd_global.user_id;
22333          x_paymentTab(i).creation_date                  := sysdate;
22334          x_paymentTab(i).last_updated_by                := fnd_global.user_id;
22335          x_paymentTab(i).last_update_login              := fnd_global.user_id;
22336          x_paymentTab(i).last_update_date               := sysdate;
22337          x_paymentTab(i).object_version_number          := 1;
22338 
22339      END LOOP;
22340 
22341  END initializePmts;
22342 
22343 /*--------------------------------------------------------------------
22344  | NAME:
22345  |     get_payreq_status
22346  |
22347  |
22348  | PURPOSE:
22349  |
22350  |
22351  | PARAMETERS:
22352  |     IN
22353  |
22354  |
22355  |     OUT
22356  |
22357  |
22358  | RETURNS:
22359  |
22360  | NOTES:
22361  |
22362  *---------------------------------------------------------------------*/
22363  FUNCTION get_payreq_status (
22364      l_payreq_id IN IBY_PAY_SERVICE_REQUESTS.payment_service_request_id%TYPE)
22365      RETURN VARCHAR2
22366  IS
22367 
22368  l_payreq_status     VARCHAR2(100);
22369  l_module_name       CONSTANT VARCHAR2(200) := G_PKG_NAME ||
22370                                                    '.get_payreq_status';
22371 
22372  BEGIN
22373 
22374      SELECT
22375          payment_service_request_status
22376      INTO
22377          l_payreq_status
22378      FROM
22379          IBY_PAY_SERVICE_REQUESTS
22380      WHERE
22381          payment_service_request_id = l_payreq_id;
22382 
22383      RETURN l_payreq_status;
22384 
22385  EXCEPTION
22386      WHEN OTHERS THEN
22387          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22388          print_debuginfo(l_module_name, 'Exception occured when '
22389              || 'retrieving payment request status for '
22390              || 'payment request '
22391              || l_payreq_id
22392              );
22393          print_debuginfo(l_module_name, 'SQLCODE: ' || SQLCODE);
22394          print_debuginfo(l_module_name, 'SQLERRM: ' || SQLERRM);
22395          print_debuginfo(l_module_name, 'Returning NULL for status');
22396 	 END IF;
22397          RETURN NULL;
22398 
22399  END get_payreq_status;
22400 
22401 /*--------------------------------------------------------------------
22402  | NAME:
22403  |     rebuildPayments
22404  |
22405  | PURPOSE:
22406  |
22407  |
22408  |
22409  | PARAMETERS:
22410  |     IN
22411  |
22412  |
22413  |     OUT
22414  |
22415  |
22416  | RETURNS:
22417  |
22418  | NOTES:
22419  |
22420  *---------------------------------------------------------------------*/
22421  PROCEDURE rebuildPayments(
22422      p_payment_request_id   IN IBY_PAY_SERVICE_REQUESTS.
22423                                          payment_service_request_id%TYPE,
22424      x_paymentTab           IN OUT NOCOPY IBY_PAYGROUP_PUB.paymentTabType,
22425      x_docsInPmtTab         IN OUT NOCOPY IBY_PAYGROUP_PUB.
22426                                               docsInPaymentTabType,
22427      x_ca_id                IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
22428                                               calling_app_id%TYPE,
22429      x_ca_payreq_cd         IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
22430                                               call_app_pay_service_req_code
22431                                               %TYPE,
22432      x_payReqCriteria       IN OUT NOCOPY IBY_PAYGROUP_PUB.
22433                                               payReqImposedCriteria
22434 --  ,x_cbrTab               IN OUT NOCOPY IBY_PAYGROUP_PUB.
22435 --                                             centralBankReportTabType
22436      )
22437  IS
22438  l_module_name           CONSTANT VARCHAR2(200) := G_PKG_NAME ||
22439                                                    '.rebuildPayments';
22440 
22441  l_ca_payreq_cd            VARCHAR2(255) := '';
22442  l_ca_id                   NUMBER(15)    := 0;
22443 
22444  l_paymentTab        IBY_PAYGROUP_PUB.paymentTabType;
22445 
22446  /*
22447   * Stores the documents payable for all pmts in request.
22448   */
22449  l_docsInPmtTab      IBY_PAYGROUP_PUB.docsInPaymentTabType;
22450 
22451  /*
22452   * Stores the documents payable for a single payment.
22453   */
22454  l_docsForPmtTab     IBY_PAYGROUP_PUB.docsInPaymentTabType;
22455 
22456  l_pmt_amount        IBY_PAYMENTS_ALL.payment_amount%TYPE;
22457 
22458  /*
22459   * For storing central bank reporting information related to
22460   * each payment.
22461   */
22462 -- l_cbrRec            IBY_PAYGROUP_PUB.centralBankReportRecType;
22463 -- l_cbrTab            IBY_PAYGROUP_PUB.centralBankReportTabType;
22464 
22465  /*
22466   * Cursor to pick up payments.
22467   */
22468  CURSOR c_payments(p_payment_request_id NUMBER)
22469  IS
22470  SELECT
22471      *
22472  FROM
22473      IBY_PAYMENTS_ALL
22474  WHERE
22475      payment_service_request_id = p_payment_request_id AND
22476 
22477      /*
22478       * For the rebuild:
22479       * Only select payments that are in non-failed
22480       * status, or payments that are soft failed
22481       * ('FAILED_VALIDATION') status here. Do not
22482       * select payments that are is 'REJECTED' status
22483       * here as the underlying documents of rejected
22484       * payments would have already been kicked back to AP.
22485       */
22486      payment_status IN
22487          (
22488          PAY_STATUS_CREATED,
22489          PAY_STATUS_MODIFIED,
22490          PAY_STATUS_FAIL_VALID
22491          )
22492      ;
22493 
22494  /*
22495   * Cursor to pick up documents.
22496   */
22497  CURSOR c_documents(p_payment_request_id NUMBER, p_payment_id NUMBER)
22498  IS
22499  SELECT
22500      payment_id,
22501      document_payable_id,
22502      calling_app_id,
22503      calling_app_doc_unique_ref1,
22504      calling_app_doc_unique_ref2,
22505      calling_app_doc_unique_ref3,
22506      calling_app_doc_unique_ref4,
22507      calling_app_doc_unique_ref5,
22508      pay_proc_trxn_type_code,
22509      payment_amount,
22510      payment_currency_code,
22511      payment_grouping_number,
22512      document_status,
22513      amount_withheld,
22514      payment_due_date,
22515      discount_date,
22516      internal_bank_account_id,
22517      ext_payee_id,
22518      payee_party_id,
22519      party_site_id,
22520      supplier_site_id,
22521      org_id,
22522      org_type,
22523      external_bank_account_id,
22524      payment_curr_discount_taken,
22525      delivery_channel_code,
22526      unique_remittance_identifier,
22527      uri_check_digit,
22528      inv_payee_party_id,
22529      inv_party_site_id,
22530      inv_supplier_site_id,
22531      inv_beneficiary_party,
22532      ext_inv_payee_id,
22533      relationship_id
22534  FROM
22535      IBY_DOCS_PAYABLE_ALL
22536  WHERE
22537      payment_service_request_id = p_payment_request_id    AND
22538      payment_id                 = p_payment_id            AND
22539      document_status IN
22540      (
22541      DOC_STATUS_PAY_CREATED,
22542      DOC_STATUS_PAY_VAL_FAIL
22543      )
22544      ;
22545 
22546  /*
22547   * Cursor to pick up central bank reporting
22548   * related information.
22549  CURSOR c_cbr(p_payment_id NUMBER)
22550  IS
22551  SELECT
22552      pmt.payment_id,
22553      prof.declaration_option,
22554      prof.dcl_only_foreign_curr_pmt_flag,
22555      prof.declaration_curr_fx_rate_type,
22556      prof.declaration_currency_code,
22557      prof.declaration_threshold_amount
22558  FROM
22559      IBY_PAYMENTS_ALL pmt,
22560      IBY_PAYMENT_PROFILES prof
22561  WHERE
22562      pmt.payment_id = p_payment_id AND
22563      pmt.payment_profile_id = prof.payment_profile_id
22564      ;
22565   */
22566 
22567  BEGIN
22568 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22569      print_debuginfo(l_module_name, 'ENTER');
22570 END IF;
22571      /*
22572       * Pick up all the payments of the payment request.
22573       */
22574      OPEN  c_payments(p_payment_request_id);
22575      FETCH c_payments BULK COLLECT INTO l_paymentTab;
22576      CLOSE c_payments;
22577 
22578      /*
22579       * Exit if no payments were found.
22580       */
22581      IF (l_paymentTab.COUNT = 0) THEN
22582 
22583          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22584          print_debuginfo(l_module_name, 'No payments were '
22585              || 'retrieved from DB for payment request '
22586              || p_payment_request_id
22587              || '. Exiting rebuild ..');
22588 
22589          print_debuginfo(l_module_name, 'EXIT');
22590 	 END IF;
22591 
22592          RETURN;
22593 
22594      ELSE
22595 
22596          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22597          print_debuginfo(l_module_name, '# valid payments '
22598              || 'retrieved from DB for payment request '
22599              || p_payment_request_id
22600              || ' = '
22601              || l_paymentTab.COUNT);
22602 	 END IF;
22603      END IF;
22604 
22605      /*
22606       * Pick up all the valid documents for the above payments.
22607       */
22608      FOR i IN l_paymentTab.FIRST .. l_paymentTab.LAST LOOP
22609 
22610          /*
22611           * Pick up all the documents of the payment request.
22612           */
22613          OPEN  c_documents(p_payment_request_id, l_paymentTab(i).payment_id);
22614          FETCH c_documents BULK COLLECT INTO l_docsForPmtTab;
22615          CLOSE c_documents;
22616 
22617          IF (l_docsForPmtTab.COUNT > 0) THEN
22618 
22619              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22620              print_debuginfo(l_module_name, 'Picked up '
22621                  || l_docsForPmtTab.COUNT
22622                  || ' documents for payment '
22623                  || l_paymentTab(i).payment_id
22624                  );
22625 	    END IF;
22626               /*
22627                * Sum up the payment amount from all the
22628                * document amounts.
22629                */
22630               l_pmt_amount := 0;
22631               FOR j IN l_docsForPmtTab.FIRST .. l_docsForPmtTab.LAST LOOP
22632 
22633                   l_pmt_amount := l_pmt_amount +
22634                                       l_docsForPmtTab(j).document_amount;
22635 
22636               END LOOP;
22637 
22638               IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22639               print_debuginfo(l_module_name, 'Adjusting payment amount '
22640                   || 'for payment '
22641                   || l_paymentTab(i).payment_id
22642                   || ' from '
22643                   || l_paymentTab(i).payment_amount
22644                   || ' to '
22645                   || l_pmt_amount
22646                   );
22647 		 END IF;
22648               l_paymentTab(i).payment_amount := l_pmt_amount;
22649 
22650               FOR q IN l_docsForPmtTab.FIRST .. l_docsForPmtTab.LAST LOOP
22651 
22652                   /*
22653                    * We are now assembling the payments that need to
22654                    * be re-built along with their child documents.
22655                    *
22656                    * These payments will be re-validated. If any
22657                    * payment fails validation, its child documents
22658                    * will be failed as well and the documents' status
22659                    * will be set to 'PAYMENT_FAILED_VALIDATION'.
22660                    *
22661                    * At this point, as we are assembling the
22662                    * documents payable, we need to re-initialize the
22663                    * status of these documents. By default, set the
22664                    * status of these documents to 'PAYMENT_CREATED'.
22665                    *
22666                    * These documents will be failed downstream if their
22667                    * parent payment fails validation for some reason.
22668                    */
22669                   l_docsForPmtTab(q).document_status := DOC_STATUS_PAY_CREATED;
22670 
22671               END LOOP;
22672 
22673               /*
22674                * If we reached here, it means that we were able to
22675                * find the documents payable associated with the
22676                * current payment.
22677                *
22678                * Store this payment and the corresponding documents
22679                * into the l_docsInPmtTab array.
22680                */
22681               FOR k IN l_docsForPmtTab.FIRST .. l_docsForPmtTab.LAST LOOP
22682 
22683                   l_docsInPmtTab(l_docsInPmtTab.COUNT + 1) :=
22684                       l_docsForPmtTab(k);
22685 
22686               END LOOP;
22687 
22688          ELSE
22689 
22690              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22691              print_debuginfo(l_module_name, 'No documents '
22692                  || 'were picked up for payment '
22693                  || l_paymentTab(i).payment_id
22694                  );
22695 
22696              print_debuginfo(l_module_name, 'All valid documents '
22697                  || 'of payment '
22698                  || l_paymentTab(i).payment_id
22699                  || ' have been removed. Setting payment '
22700                  || 'amount to zero.'
22701                  );
22702 		 END IF;
22703              l_paymentTab(i).payment_amount := 0;
22704 
22705          END IF;
22706 
22707      END LOOP;
22708 
22709      /*
22710       * Pick up details of this payment request.
22711       */
22712      SELECT
22713          calling_app_id,
22714          call_app_pay_service_req_code
22715      INTO
22716          l_ca_id,
22717          l_ca_payreq_cd
22718      FROM
22719          IBY_PAY_SERVICE_REQUESTS
22720      WHERE
22721          PAYMENT_SERVICE_REQUEST_ID = p_payment_request_id
22722      ;
22723      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22724      print_debuginfo(l_module_name, 'For payment request '
22725          || p_payment_request_id
22726          || ' calling app id is '
22727          || l_ca_id
22728          || ' and call app pay service req code is '
22729          || l_ca_payreq_cd
22730          );
22731  END IF;
22732     /*
22733      * Fix for bug 5587110:
22734      *
22735      * Fetch the central bank reporting related
22736      * data based on the profile of the retrieved
22737      * payments.
22738      *
22739      * Without this information we cannot perform
22740      * central bank reporting.
22741     FOR i IN l_paymentTab.FIRST .. l_paymentTab.LAST LOOP
22742 
22743         OPEN  c_cbr(l_paymentTab(i).payment_id);
22744         FETCH c_cbr INTO l_cbrRec;
22745         CLOSE c_cbr;
22746 
22747         l_cbrTab(l_cbrTab.COUNT + 1) := l_cbrRec;
22748 
22749     END LOOP;
22750      */
22751 
22752      /*
22753       * Finally, return the payments created by grouping to the caller.
22754       */
22755      x_paymentTab   := l_paymentTab;
22756      x_docsInPmtTab := l_docsInPmtTab;
22757      x_ca_id        := l_ca_id;
22758      x_ca_payreq_cd := l_ca_payreq_cd;
22759 --     x_cbrTab       := l_cbrTab;
22760 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22761      print_debuginfo(l_module_name, 'EXIT');
22762 	 END IF;
22763 
22764  END rebuildPayments;
22765 
22766 /*--------------------------------------------------------------------
22767  | NAME:
22768  |     rebuildPayments
22769  |
22770  | PURPOSE:
22771  |
22772  |
22773  |
22774  | PARAMETERS:
22775  |     IN
22776  |
22777  |
22778  |     OUT
22779  |
22780  |
22781  | RETURNS:
22782  |
22783  | NOTES:
22784  |
22785  *---------------------------------------------------------------------*/
22786  PROCEDURE rebuildPayments(
22787      p_payment_request_id   IN IBY_PAY_SERVICE_REQUESTS.
22788                                          payment_service_request_id%TYPE,
22789      x_paymentTab           IN OUT NOCOPY IBY_PAYGROUP_PUB.paymentTabType,
22790 --     x_docsInPmtTab         IN OUT NOCOPY IBY_PAYGROUP_PUB.
22791 --                                              docsInPaymentTabType,
22792      x_ca_id                IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
22793                                               calling_app_id%TYPE,
22794      x_ca_payreq_cd         IN OUT NOCOPY IBY_PAY_SERVICE_REQUESTS.
22795                                               call_app_pay_service_req_code
22796                                               %TYPE,
22797      x_payReqCriteria       IN OUT NOCOPY IBY_PAYGROUP_PUB.
22798                                               payReqImposedCriteria
22799 --  ,x_cbrTab               IN OUT NOCOPY IBY_PAYGROUP_PUB.
22800 --                                             centralBankReportTabType
22801      )
22802  IS
22803  l_module_name           CONSTANT VARCHAR2(200) := G_PKG_NAME ||
22804                                                    '.rebuildPayments';
22805 
22806  l_ca_payreq_cd            VARCHAR2(255) := '';
22807  l_ca_id                   NUMBER(15)    := 0;
22808 
22809  l_paymentTab        IBY_PAYGROUP_PUB.paymentTabType;
22810 
22811  /*
22812   * Stores the documents payable for all pmts in request.
22813   */
22814 -- l_docsInPmtTab      IBY_PAYGROUP_PUB.docsInPaymentTabType;
22815 
22816  /*
22817   * Stores the documents payable for a single payment.
22818   */
22819 -- l_docsForPmtTab     IBY_PAYGROUP_PUB.docsInPaymentTabType;
22820 
22821  l_pmt_amount        IBY_PAYMENTS_ALL.payment_amount%TYPE;
22822 
22823  /*
22824   * For storing central bank reporting information related to
22825   * each payment.
22826   */
22827 -- l_cbrRec            IBY_PAYGROUP_PUB.centralBankReportRecType;
22828 -- l_cbrTab            IBY_PAYGROUP_PUB.centralBankReportTabType;
22829 
22830  /*
22831   * Cursor to pick up payments.
22832   */
22833  CURSOR c_payments(p_payment_request_id NUMBER)
22834  IS
22835  SELECT
22836      *
22837  FROM
22838      IBY_PAYMENTS_ALL
22839  WHERE
22840      payment_service_request_id = p_payment_request_id AND
22841 
22842      /*
22843       * For the rebuild:
22844       * Only select payments that are in non-failed
22845       * status, or payments that are soft failed
22846       * ('FAILED_VALIDATION') status here. Do not
22847       * select payments that are is 'REJECTED' status
22848       * here as the underlying documents of rejected
22849       * payments would have already been kicked back to AP.
22850       */
22851      payment_status IN
22852          (
22853          PAY_STATUS_CREATED,
22854          PAY_STATUS_MODIFIED,
22855          PAY_STATUS_FAIL_VALID
22856          )
22857      ;
22858 
22859  /*
22860   * Cursor to pick up central bank reporting
22861   * related information.
22862  CURSOR c_cbr(p_payment_id NUMBER)
22863  IS
22864  SELECT
22865      pmt.payment_id,
22866      prof.declaration_option,
22867      prof.dcl_only_foreign_curr_pmt_flag,
22868      prof.declaration_curr_fx_rate_type,
22869      prof.declaration_currency_code,
22870      prof.declaration_threshold_amount
22871  FROM
22872      IBY_PAYMENTS_ALL pmt,
22873      IBY_PAYMENT_PROFILES prof
22874  WHERE
22875      pmt.payment_id = p_payment_id AND
22876      pmt.payment_profile_id = prof.payment_profile_id
22877      ;
22878   */
22879 
22880  BEGIN
22881   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22882      print_debuginfo(l_module_name, 'ENTER');
22883   END IF;
22884 
22885  INSERT INTO iby_docs_in_pmt_gt(
22886              payment_id,
22887      document_payable_id,
22888      calling_app_id,
22889      calling_app_doc_unique_ref1,
22890      calling_app_doc_unique_ref2,
22891      calling_app_doc_unique_ref3,
22892      calling_app_doc_unique_ref4,
22893      calling_app_doc_unique_ref5,
22894      pay_proc_trxn_type_code,
22895      document_amount,
22896      document_currency_code,
22897      payment_grouping_number,
22898      document_status,
22899      amount_withheld,
22900      payment_due_date,
22901      discount_date,
22902      internal_bank_account_id,
22903      ext_payee_id,
22904      payee_party_id,
22905      party_site_id,
22906      supplier_site_id,
22907      org_id,
22908      org_type,
22909      external_bank_account_id,
22910      payment_curr_discount_taken,
22911      delivery_channel_code,
22912      unique_remittance_identifier,
22913      uri_check_digit,
22914      created_by,
22915      creation_date,
22916      last_updated_by,
22917      Last_update_date,
22918      last_update_login,
22919      object_version_number,
22920              dont_pay_flag,
22921              dont_pay_reason_code,
22922              dont_pay_description
22923              )
22924  SELECT
22925         idpa.payment_id,
22926         idpa.document_payable_id,
22927         idpa.calling_app_id,
22928         idpa.calling_app_doc_unique_ref1,
22929         idpa.calling_app_doc_unique_ref2,
22930         idpa.calling_app_doc_unique_ref3,
22931         idpa.calling_app_doc_unique_ref4,
22932         idpa.calling_app_doc_unique_ref5,
22933         idpa.pay_proc_trxn_type_code,
22934         idpa.payment_amount,
22935         idpa.payment_currency_code,
22936         idpa.payment_grouping_number,
22937         DOC_STATUS_PAY_CREATED,
22938         idpa.amount_withheld,
22939         idpa.payment_due_date,
22940         idpa.discount_date,
22941         idpa.internal_bank_account_id,
22942         idpa.ext_payee_id,
22943         idpa.payee_party_id,
22944         idpa.party_site_id,
22945         idpa.supplier_site_id,
22946         idpa.org_id,
22947         idpa.org_type,
22948         idpa.external_bank_account_id,
22949         idpa.payment_curr_discount_taken,
22950         idpa.delivery_channel_code,
22951         idpa.unique_remittance_identifier,
22952         idpa.uri_check_digit,
22953         idpa.created_by,
22954         idpa.creation_date,
22955         idpa.last_updated_by,
22956         idpa.Last_update_date,
22957         idpa.last_update_login,
22958         idpa.object_version_number,
22959      'N',
22960      null,
22961      null
22962  FROM
22963      IBY_DOCS_PAYABLE_ALL idpa, IBY_PAYMENTS_ALL ibpa
22964  WHERE
22965      idpa.payment_service_request_id = p_payment_request_id
22966      AND idpa.payment_service_request_id = ibpa.payment_service_request_id
22967      AND idpa.payment_id = ibpa.payment_id
22968      AND idpa.document_status IN
22969      (
22970      DOC_STATUS_PAY_CREATED,
22971      DOC_STATUS_PAY_VAL_FAIL
22972      )
22973      AND ibpa.payment_status IN
22974          (
22975          PAY_STATUS_CREATED,
22976          PAY_STATUS_MODIFIED,
22977          PAY_STATUS_FAIL_VALID
22978          )
22979      ;
22980 
22981      /*
22982       * Pick up all the payments of the payment request.
22983       */
22984      OPEN  c_payments(p_payment_request_id);
22985      FETCH c_payments BULK COLLECT INTO l_paymentTab;
22986      CLOSE c_payments;
22987 
22988      /*
22989       * Exit if no payments were found.
22990       */
22991      IF (l_paymentTab.COUNT = 0) THEN
22992 
22993          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
22994          print_debuginfo(l_module_name, 'No payments were '
22995              || 'retrieved from DB for payment request '
22996              || p_payment_request_id
22997              || '. Exiting rebuild ..');
22998 
22999          print_debuginfo(l_module_name, 'EXIT');
23000 	 END IF;
23001 
23002          RETURN;
23003 
23004      ELSE
23005 
23006          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23007          print_debuginfo(l_module_name, '# valid payments '
23008              || 'retrieved from DB for payment request '
23009              || p_payment_request_id
23010              || ' = '
23011              || l_paymentTab.COUNT);
23012 	 END IF;
23013      END IF;
23014 
23015      /*
23016       * Pick up all the valid documents for the above payments.
23017       */
23018      FOR i IN l_paymentTab.FIRST .. l_paymentTab.LAST LOOP
23019 
23020 
23021               l_pmt_amount := 0;
23022               SELECT SUM(document_amount) into l_pmt_amount
23023               FROM iby_docs_in_pmt_gt
23024               WHERE payment_id = l_paymentTab(i).payment_id;
23025 
23026 
23027               IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23028               print_debuginfo(l_module_name, 'Adjusting payment amount '
23029                   || 'for payment '
23030                   || l_paymentTab(i).payment_id
23031                   || ' from '
23032                   || l_paymentTab(i).payment_amount
23033                   || ' to '
23034                   || l_pmt_amount
23035                   );
23036               END IF;
23037               l_paymentTab(i).payment_amount := l_pmt_amount;
23038 
23039               /* Bug : 9079624*/
23040 	      IF( l_paymentTab(i).payment_status = PAY_STATUS_MODIFIED) THEN
23041                   l_paymentTab(i).payment_status := PAY_STATUS_CREATED;
23042 	      END IF;
23043 
23044 	      update iby_payments_all set payment_amount = l_pmt_amount,
23045 	      payment_status = l_paymentTab(i).payment_status
23046               where payment_id = l_paymentTab(i).payment_id;
23047 
23048      END LOOP;
23049 
23050      /*
23051       * Pick up details of this payment request.
23052       */
23053      SELECT
23054          calling_app_id,
23055          call_app_pay_service_req_code
23056      INTO
23057          l_ca_id,
23058          l_ca_payreq_cd
23059      FROM
23060          IBY_PAY_SERVICE_REQUESTS
23061      WHERE
23062          PAYMENT_SERVICE_REQUEST_ID = p_payment_request_id
23063      ;
23064      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23065      print_debuginfo(l_module_name, 'For payment request '
23066          || p_payment_request_id
23067          || ' calling app id is '
23068          || l_ca_id
23069          || ' and call app pay service req code is '
23070          || l_ca_payreq_cd
23071          );
23072  END IF;
23073     /*
23074      * Fix for bug 5587110:
23075      *
23076      * Fetch the central bank reporting related
23077      * data based on the profile of the retrieved
23078      * payments.
23079      *
23080      * Without this information we cannot perform
23081      * central bank reporting.
23082     FOR i IN l_paymentTab.FIRST .. l_paymentTab.LAST LOOP
23083 
23084         OPEN  c_cbr(l_paymentTab(i).payment_id);
23085         FETCH c_cbr INTO l_cbrRec;
23086         CLOSE c_cbr;
23087 
23088         l_cbrTab(l_cbrTab.COUNT + 1) := l_cbrRec;
23089 
23090     END LOOP;
23091      */
23092 
23093      /*
23094       * Finally, return the payments created by grouping to the caller.
23095       */
23096      x_paymentTab   := l_paymentTab;
23097 --     x_docsInPmtTab := l_docsInPmtTab;
23098      x_ca_id        := l_ca_id;
23099      x_ca_payreq_cd := l_ca_payreq_cd;
23100 --     x_cbrTab       := l_cbrTab;
23101 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23102      print_debuginfo(l_module_name, 'EXIT');
23103 	 END IF;
23104 
23105  EXCEPTION
23106    WHEN OTHERS THEN
23107    print_debuginfo(l_module_name, 'SQL code: '   || SQLCODE,
23108                  FND_LOG.LEVEL_UNEXPECTED);
23109              print_debuginfo(l_module_name, 'SQL err msg: '|| SQLERRM,
23110                  FND_LOG.LEVEL_UNEXPECTED);
23111    print_debuginfo(l_module_name, l_module_name||':Exception while performing rebuildPayments');
23112    RAISE;
23113 END rebuildPayments;
23114 
23115 /*--------------------------------------------------------------------
23116  | NAME:
23117  |     auditPaymentData
23118  |
23119  | PURPOSE:
23120  |
23121  |
23122  |
23123  | PARAMETERS:
23124  |     IN
23125  |
23126  |
23127  |     OUT
23128  |
23129  |
23130  | RETURNS:
23131  |
23132  | NOTES:
23133  |
23134  |     See bug 5399951 for history behind some of the SQL joins
23135  |
23136  *---------------------------------------------------------------------*/
23137  PROCEDURE auditPaymentData(
23138      l_trx_audit_index IN BINARY_INTEGER
23139      )
23140  IS
23141  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
23142                                                   '.auditPaymentData';
23143 
23144  l_pmtAuditRec      IBY_PAYGROUP_PUB.paymentAuditRecType;
23145  l_pmtAuditTab      IBY_PAYGROUP_PUB.paymentAuditTabType;
23146 
23147  BEGIN
23148 
23149      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23150      print_debuginfo(l_module_name, 'ENTER');
23151      END IF;
23152 
23153      GET_PAYER_INFO(l_trx_audit_index);
23154      GET_PAYER_ACCT_INFO(l_trx_audit_index);
23155      GET_VENDOR_INFO(l_trx_audit_index);
23156      GET_PAYEE(l_trx_audit_index);
23157      GET_PAYEE_SITE_INFO(l_trx_audit_index);
23158      GET_PAYEE_ADDR_INFO(l_trx_audit_index);
23159      GET_PAYEE_BANK_INFO(l_trx_audit_index);
23160      GET_REMITTANCE_INFO(l_trx_audit_index);
23161      GET_PPR_INFO(l_trx_audit_index);
23162      GET_DELIVERY_INFO(l_trx_audit_index);
23163      GET_ORG_INFO(l_trx_audit_index);
23164      GET_PMTREASON_INFO(l_trx_audit_index);
23165 
23166 
23167      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23168      print_debuginfo(l_module_name, 'EXIT');
23169      END IF;
23170 
23171  END auditPaymentData;
23172 
23173 /*--------------------------------------------------------------------
23174  | NAME:
23175  |     insertAuditData
23176  |
23177  | PURPOSE:
23178  |
23179  |
23180  | PARAMETERS:
23181  |     IN
23182  |
23183  |
23184  |     OUT
23185  |
23186  |
23187  | RETURNS:
23188  |
23189  | NOTES:
23190  |
23191  *---------------------------------------------------------------------*/
23192  PROCEDURE insertAuditData(
23193      p_auditPmtTab    IN paymentAuditTabType
23194      )
23195  IS
23196 
23197  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.insertAuditData';
23198 
23199  BEGIN
23200 
23201      print_debuginfo(l_module_name, 'ENTER');
23202 
23203      /* Normally, this shouldn't happen */
23204      IF (p_auditPmtTab.COUNT = 0) THEN
23205 
23206          IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23207          print_debuginfo(l_module_name, 'No audit data '
23208              || 'was provided to update IBY_PAYMENTS_ALL table. '
23209              || 'Exiting ..'
23210              );
23211 
23212          print_debuginfo(l_module_name, 'EXIT');
23213  END IF;
23214          RETURN;
23215 
23216      END IF;
23217 
23218 
23219      FOR i IN p_auditPmtTab.FIRST .. p_auditPmtTab.LAST LOOP
23220 
23221          UPDATE
23222              IBY_PAYMENTS_ALL
23223          SET
23224              payer_party_number             = p_auditPmtTab(i).
23225                                                   payer_party_number,
23226              payer_party_site_name          = p_auditPmtTab(i).
23227                                                   payer_party_site_name,
23228              payer_legal_entity_name        = p_auditPmtTab(i).payer_legal_name,
23229              payer_tax_registration_num     = p_auditPmtTab(i).
23230                                                   payer_tax_reg_number,
23231              payer_le_registration_num      = p_auditPmtTab(i).
23232                                                   payer_le_reg_number,
23233              payer_party_id                 = p_auditPmtTab(i).
23234                                                   payer_party_id,
23235              payer_location_id              = p_auditPmtTab(i).
23236                                                   payer_location_id,
23237              payer_party_attr_category      = p_auditPmtTab(i).
23238                                                   payer_party_attr_cat,
23239              payer_le_attr_category         = p_auditPmtTab(i).
23240                                                   payer_le_attr_cat,
23241              payer_abbreviated_agency_code  = p_auditPmtTab(i).
23242                                                   payer_abbrev_agency_code,
23243              payer_federal_us_employer_id   = p_auditPmtTab(i).
23244                                                   payer_us_employer_id,
23245              int_bank_name                  = p_auditPmtTab(i).payer_bank_name,
23246              int_bank_number                = p_auditPmtTab(i).
23247                                                   payer_bank_number,
23248              int_bank_branch_number         = p_auditPmtTab(i).
23249                                                   payer_bank_branch_number,
23250              int_bank_branch_name           = p_auditPmtTab(i).
23251                                                   payer_bank_branch_name,
23252              int_eft_swift_code             = p_auditPmtTab(i).
23253                                                   payer_bank_swift_code,
23254              int_bank_account_number        = p_auditPmtTab(i).
23255                                                   payer_bank_acct_num,
23256              int_bank_account_name          = p_auditPmtTab(i).
23257                                                   payer_bank_acct_name,
23258              int_bank_account_iban          = p_auditPmtTab(i).
23259                                                   payer_bank_acct_iban,
23260              int_bank_acct_agency_loc_code  = p_auditPmtTab(i).
23261                                                   payer_bank_agency_loc_code,
23262              int_bank_branch_party_id       = p_auditPmtTab(i).
23263                                                   payer_bank_branch_party_id,
23264              int_bank_alt_name              = p_auditPmtTab(i).
23265                                                   payer_bank_alt_name,
23266              int_bank_branch_alt_name       = p_auditPmtTab(i).
23267                                                   payer_bank_branch_alt_name,
23268              int_bank_account_alt_name      = p_auditPmtTab(i).
23269                                                   payer_bank_alt_account_name,
23270              int_bank_account_num_elec      = p_auditPmtTab(i).
23271                                                   payer_bank_account_num_elec,
23272              int_bank_branch_location_id    = p_auditPmtTab(i).
23273                                                   payer_bank_branch_location_id,
23274              int_bank_branch_eft_user_num   = p_auditPmtTab(i).
23275                                               payer_bank_branch_eft_user_num,
23276              payee_party_number             = p_auditPmtTab(i).
23277                                                   payee_party_number,
23278              payee_party_name               = p_auditPmtTab(i).payee_party_name,
23279              payee_name                     = p_auditPmtTab(i).payee_name,
23280              payee_alternate_name           = p_auditPmtTab(i).payee_name_alternate,     -- Bug 6175102
23281              payee_address1                 = p_auditPmtTab(i).payee_add_line_1,
23282              payee_address2                 = p_auditPmtTab(i).payee_add_line_2,
23283              payee_address3                 = p_auditPmtTab(i).payee_add_line_3,
23284              payee_address4                 = p_auditPmtTab(i).payee_add_line_4,
23285              payee_city                     = p_auditPmtTab(i).payee_city,
23286              payee_county                   = p_auditPmtTab(i).payee_county,
23287              payee_province                 = p_auditPmtTab(i).payee_province,
23288              payee_state                    = p_auditPmtTab(i).payee_state,
23289              payee_country                  = p_auditPmtTab(i).payee_country,
23290              payee_postal_code              = p_auditPmtTab(i).
23291                                                   payee_postal_code,
23292              payee_address_concat           = p_auditPmtTab(i).
23293                                                   payee_address_concat,
23294              beneficiary_name               = p_auditPmtTab(i).
23295                                                   beneficiary_name,
23296              payee_party_attr_category      = p_auditPmtTab(i).
23297                                                   payee_party_attr_cat,
23298              payee_spplr_site_attr_category = p_auditPmtTab(i).
23299                                                   payee_supplier_site_attr_cat,
23300              payee_supplier_site_name       = p_auditPmtTab(i).
23301                                                   payee_supplier_site_name,
23302              payee_party_site_name       = p_auditPmtTab(i).
23303                                                   payee_party_site_name,
23304              payee_addressee                = p_auditPmtTab(i).
23305                                                   payee_addressee,
23306              payee_site_alternate_name      = p_auditPmtTab(i).
23307                                                   payee_site_name_alternate,
23308              payee_supplier_number          = p_auditPmtTab(i).
23309                                                   payee_supplier_number,
23310              payee_first_party_reference    = p_auditPmtTab(i).
23311                                                   payee_first_party_ref,
23312              payee_supplier_attr_category   = p_auditPmtTab(i).
23313                                                   payee_supplier_attr_cat,
23314              payee_supplier_id              = p_auditPmtTab(i).
23315                                                   payee_supplier_id,
23316              payee_tax_registration_num     = p_auditPmtTab(i).
23317                                                   payee_tax_reg_number,
23318              payee_le_registration_num      = p_auditPmtTab(i).
23319                                                   payee_le_reg_number,
23320              ext_bank_name                  = p_auditPmtTab(i).payee_bank_name,
23321              ext_bank_number                = p_auditPmtTab(i).
23322                                                   payee_bank_number,
23323              ext_branch_number              = p_auditPmtTab(i).
23324                                                   payee_bank_branch_number,
23325              ext_bank_branch_name           = p_auditPmtTab(i).
23326                                                   payee_bank_branch_name,
23327              ext_bank_account_number        = p_auditPmtTab(i).
23328                                                   payee_bank_acct_number,
23329              ext_bank_account_name          = p_auditPmtTab(i).
23330                                                   payee_bank_acct_name,
23331              ext_bank_account_iban_number   = p_auditPmtTab(i).
23332                                                   payee_bank_acct_iban,
23333              ext_eft_swift_code             = p_auditPmtTab(i).
23334                                                   payee_bank_swift_code,
23335              ext_bank_account_type          = p_auditPmtTab(i).
23336                                                   payee_bank_acct_type,
23337              ext_bank_acct_pmt_factor_flag  = p_auditPmtTab(i).
23338                                                  payee_bank_payment_factor_flag,
23339              ext_bank_acct_owner_party_id   = p_auditPmtTab(i).
23340                                                   payee_bank_owner_party_id,
23341              ext_bank_branch_party_id       = p_auditPmtTab(i).
23342                                                   payee_bank_branch_party_id,
23343              ext_bank_alt_name              = p_auditPmtTab(i).
23344                                                   payee_bank_name_alt,
23345              ext_bank_branch_alt_name       = p_auditPmtTab(i).
23346                                                   payee_bank_branch_name_alt,
23347              ext_bank_account_alt_name      = p_auditPmtTab(i).
23348                                                   payee_bank_alt_account_name,
23349              ext_bank_account_num_elec      = p_auditPmtTab(i).
23350                                               payee_bank_electronic_acct_num,
23351              ext_bank_branch_location_id    = p_auditPmtTab(i).
23352                                                   payee_bank_branch_location_id,
23353              ext_bank_acct_owner_party_name = p_auditPmtTab(i).
23354                                                   payee_bank_acct_owner_name,
23355              remit_advice_delivery_method   = p_auditPmtTab(i).
23356                                                   remit_advice_delivery_method,
23357              remit_advice_email             = p_auditPmtTab(i).
23358                                                   remit_advice_email,
23359              remit_advice_fax               = p_auditPmtTab(i).
23360                                                   remit_advice_fax,
23361 
23362              /*
23363               * Fix for bug 5522421:
23364               *
23365               * sra_delivery_method is the same as
23366               * remit_advice_delivery_method and is
23367               * being obsoleted.
23368               */
23369              --sra_delivery_method            = p_auditPmtTab(i).
23370              --                                     remit_advice_delv_method,
23371 
23372              delivery_channel_format_value  = p_auditPmtTab(i).
23373                                                   delivery_channel_format,
23374              declaration_exch_rate_type     = p_auditPmtTab(i).
23375                                                   decl_curr_fx_rate_type,
23376              declaration_format             = p_auditPmtTab(i).
23377                                                   declaration_format,
23378              payment_profile_acct_name      = p_auditPmtTab(i).
23379                                                   payment_acct_profile_name,
23380              payment_profile_sys_name       = p_auditPmtTab(i).
23381                                                   payment_sys_profile_name,
23382              payment_reason_format_value    = p_auditPmtTab(i).
23383                                                   payment_reason_format,
23384              bank_instruction1_format_value = p_auditPmtTab(i).
23385                                                   bank_instr1_format,
23386              bank_instruction2_format_value = p_auditPmtTab(i).
23387                                                   bank_instr2_format,
23388              org_name                       = p_auditPmtTab(i).org_name,
23389              int_bank_branch_rfc_identifier = p_auditPmtTab(i).
23390                                                   payer_bank_branch_rfc_id,
23391              payment_process_request_name   = p_auditPmtTab(i).ppr_name,
23392              source_product                 = p_auditPmtTab(i).source_product,
23393 
23394 /*TPP-Start*/
23395 inv_payee_name = p_auditPmtTab(i).inv_payee_name,
23396 inv_payee_address1 = p_auditPmtTab(i).inv_payee_address1,
23397 inv_payee_address2 = p_auditPmtTab(i).inv_payee_address2,
23398 inv_payee_address3 = p_auditPmtTab(i).inv_payee_address3,
23399 inv_payee_address4 = p_auditPmtTab(i).inv_payee_address4,
23400 inv_payee_city = p_auditPmtTab(i).inv_payee_city,
23401 inv_payee_postal_code = p_auditPmtTab(i).inv_payee_postal_code,
23402 inv_payee_state = p_auditPmtTab(i).inv_payee_state,
23403 inv_payee_province = p_auditPmtTab(i).inv_payee_province,
23404 inv_payee_county = p_auditPmtTab(i).inv_payee_county,
23405 inv_payee_country = p_auditPmtTab(i).inv_payee_country,
23406 inv_payee_party_name = p_auditPmtTab(i).inv_payee_party_name,
23407 inv_payee_le_reg_num = p_auditPmtTab(i).inv_payee_le_reg_num,
23408 inv_payee_tax_reg_num = p_auditPmtTab(i).inv_payee_tax_reg_num,
23409 inv_payee_address_concat = p_auditPmtTab(i).inv_payee_address_concat,
23410 inv_beneficiary_name = p_auditPmtTab(i).inv_beneficiary_name,
23411 inv_payee_party_number = p_auditPmtTab(i).inv_payee_party_number,
23412 inv_payee_alternate_name = p_auditPmtTab(i).inv_payee_alternate_name,
23413 inv_payee_site_alt_name = p_auditPmtTab(i).inv_payee_site_alt_name,
23414 inv_payee_supplier_number = p_auditPmtTab(i).inv_payee_supplier_number,
23415 inv_payee_first_party_ref = p_auditPmtTab(i).inv_payee_first_party_ref,
23416 ext_bnk_acct_ownr_inv_prty_id = p_auditPmtTab(i).ext_bnk_acct_ownr_inv_prty_id,
23417 ext_bnk_branch_inv_prty_id = p_auditPmtTab(i).ext_bnk_branch_inv_prty_id,
23418 ext_bnk_acct_ownr_inv_prty_nme = p_auditPmtTab(i).ext_bnk_acct_ownr_inv_prty_nme,
23419 inv_payee_party_attr_cat = p_auditPmtTab(i).inv_payee_party_attr_cat,
23420 inv_payee_supplier_attr_cat = p_auditPmtTab(i).inv_payee_supplier_attr_cat,
23421 inv_payee_spplr_site_attr_cat = p_auditPmtTab(i).inv_payee_spplr_site_attr_cat,
23422 inv_payee_supplier_site_name = p_auditPmtTab(i).inv_payee_supplier_site_name,
23423 inv_payee_spplr_site_alt_name = p_auditPmtTab(i).inv_payee_spplr_site_alt_name,
23424 inv_payee_supplier_id = p_auditPmtTab(i).inv_payee_supplier_id
23425 /*TPP-End*/
23426 
23427          WHERE
23428              payment_id                     = p_auditPmtTab(i).payment_id
23429          ;
23430 
23431      END LOOP;
23432 
23433      print_debuginfo(l_module_name, 'EXIT');
23434 
23435  END insertAuditData;
23436 
23437 /*--------------------------------------------------------------------
23438  | NAME:
23439  |     sweepCommonPmtAttributes
23440  |
23441  | PURPOSE:
23442  |     Scan all the documents of each payment for specific common
23443  |     attributes.
23444  |
23445  |     If such a common attribute is found, set the correspoding
23446  |     attribute on the parent payment to the same value.
23447  |
23448  | PARAMETERS:
23449  |     IN
23450  |
23451  |
23452  |     OUT
23453  |
23454  |
23455  | RETURNS:
23456  |
23457  | NOTES:
23458  |
23459  *---------------------------------------------------------------------*/
23460  PROCEDURE sweepCommonPmtAttributes (
23461      x_paymentTab      IN OUT NOCOPY IBY_PAYGROUP_PUB.paymentTabType,
23462      x_docsInPmtTab    IN OUT NOCOPY IBY_PAYGROUP_PUB.docsInPaymentTabType
23463      )
23464  IS
23465  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME
23466                                              || '.sweepCommonPmtAttributes';
23467  l_first_record           BOOLEAN     := TRUE;
23468 
23469  l_due_date_common_flag   BOOLEAN     := TRUE;
23470  l_temp_due_date          DATE        := NULL;
23471 
23472  l_delv_chnl_common_flag   BOOLEAN    := TRUE;
23473  l_temp_delv_chnl          VARCHAR2(200);
23474 
23475  l_uri_common_flag         BOOLEAN    := TRUE;
23476  l_temp_uri                VARCHAR2(200);
23477  l_temp_uri_ckdigits       VARCHAR2(200);
23478 
23479  BEGIN
23480 
23481      print_debuginfo(l_module_name, 'ENTER');
23482 
23483      /*
23484       * For each payment:
23485       *
23486       * Search if all the docs of this payment contain
23487       * the same attribute, then populate this
23488       * attribute on the payment itself.
23489       */
23490 
23491      /*
23492       * Sweep for payment due date.
23493       */
23494      FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
23495 
23496          /*
23497           * Initialize for each payment iteration.
23498           */
23499          l_due_date_common_flag := TRUE;
23500          l_temp_due_date        := NULL;
23501          l_first_record         := TRUE;
23502 
23503          /*
23504           * Only attempt to derive the payment due date if the
23505           * payment does not already have a due date set.
23506           */
23507          IF (x_paymentTab(i).payment_due_date IS NULL) THEN
23508 
23509              FOR j IN x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
23510 
23511                  IF (x_paymentTab(i).payment_id = x_docsInPmtTab(j).payment_id)
23512                  THEN
23513 
23514                      /*
23515                       * If this is the first document for the payment
23516                       * in consideration, initialize the temp due
23517                       * date with the due date on the current doc.
23518                       */
23519                      IF (l_first_record = TRUE) THEN
23520 
23521                          l_temp_due_date := x_docsInPmtTab(j).pmt_due_date;
23522 
23523                      ELSE
23524 
23525                          /*
23526                           * If the due date on the current document does not
23527                           * match the due date on the previously stored
23528                           * document, then the due date is not common across
23529                           * all docs of this payment.
23530                           */
23531                          IF (l_temp_due_date <> x_docsInPmtTab(j).pmt_due_date)
23532                          THEN
23533 
23534                              l_due_date_common_flag := FALSE;
23535 
23536                              /*
23537                               * Exit iteration for this payment.
23538                               */
23539                              EXIT;
23540 
23541                          END IF; -- if due date does not match
23542 
23543                      END IF; -- if first record
23544 
23545                  END IF; -- if doc is for current payment
23546 
23547                  /*
23548                   * Reset the first record flag.
23549                   */
23550                  /*
23551                   * Fix for bug 5529924:
23552                   *
23553                   * When checking for the first record, also
23554                   * check that that the due date variable
23555                   * is not null. Otherwise, we might be
23556                   * setting the first record flag based
23557                   * on some document unrelated to this payment.
23558                   */
23559                  IF (l_temp_due_date IS NOT NULL) THEN
23560                      IF (l_first_record = TRUE) THEN
23561                          l_first_record := FALSE;
23562                      END IF;
23563                  END IF;
23564 
23565              END LOOP; -- for all docs
23566 
23567              IF (l_due_date_common_flag = TRUE) THEN
23568 
23569                  /*
23570                   * This means that all the docs of this payment
23571                   * have the same due date.
23572                   *
23573                   * Set this value on the payment (if not null)
23574                   */
23575                  IF (l_temp_due_date IS NOT NULL) THEN
23576 
23577                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23578                      print_debuginfo(l_module_name, 'All documents of payment '
23579                          || x_paymentTab(i).payment_id
23580                          || ' have the same payment due date '
23581                          || l_temp_due_date
23582                          || '. Hence setting this attribute on the '
23583                          || 'payment itself.'
23584                          );
23585  END IF;
23586                      x_paymentTab(i).payment_due_date := l_temp_due_date;
23587 
23588                  ELSE
23589 
23590                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23591                      print_debuginfo(l_module_name, 'Not setting pmt due date '
23592                          || 'for pmt id: '
23593                          || x_paymentTab(i).payment_id
23594                          );
23595 		    END IF;
23596                  END IF; -- if due date is not null
23597 
23598              END IF; -- if due date common flag set to TRUE
23599 
23600          END IF; -- if pmt due date is null
23601 
23602      END LOOP; -- for all pmts
23603 
23604      /*
23605       * Fix for bug 5462976:
23606       *
23607       * Sweep for delivery channel.
23608       */
23609      FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
23610 
23611          /*
23612           * Initialize for each payment iteration.
23613           */
23614          l_delv_chnl_common_flag := TRUE;
23615          l_temp_delv_chnl        := NULL;
23616          l_first_record          := TRUE;
23617 
23618          /*
23619           * Only attempt to derive the delivery channel if the
23620           * payment does not already have a delivery channel set.
23621           */
23622          IF (x_paymentTab(i).delivery_channel_code IS NULL) THEN
23623 
23624              FOR j IN x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
23625 
23626                  IF (x_paymentTab(i).payment_id = x_docsInPmtTab(j).payment_id)
23627                  THEN
23628 
23629                      /*
23630                       * If this is the first document for the payment
23631                       * in consideration, initialize the temp delivery
23632                       * channel with the delv channel on the current doc.
23633                       */
23634                      IF (l_first_record = TRUE) THEN
23635 
23636                          l_temp_delv_chnl := x_docsInPmtTab(j).delivery_channel;
23637 
23638                      ELSE
23639 
23640                          /*
23641                           * If the delv chnl on the current document does not
23642                           * match the delv chnl on the previously stored
23643                           * document, then the delv chnl is not common across
23644                           * all docs of this payment.
23645                           */
23646                          IF (l_temp_delv_chnl <>
23647                              x_docsInPmtTab(j).delivery_channel) THEN
23648 
23649                              l_delv_chnl_common_flag := FALSE;
23650 
23651                              /*
23652                               * Exit iteration for this payment.
23653                               */
23654                              EXIT;
23655 
23656                          END IF; -- if delv chnl does not match
23657 
23658                      END IF; -- if first record
23659 
23660                  END IF; -- if doc is for current payment
23661 
23662                  /*
23663                   * Reset the first record flag.
23664                   */
23665                  /*
23666                   * Fix for bug 5529924:
23667                   *
23668                   * When checking for the first record, also
23669                   * check that that the delivery channel variable
23670                   * is not null. Otherwise, we might be
23671                   * setting the first record flag based
23672                   * on some document unrelated to this payment.
23673                   */
23674                  IF (l_temp_delv_chnl IS NOT NULL) THEN
23675                      IF (l_first_record = TRUE) THEN
23676                          l_first_record := FALSE;
23677                      END IF;
23678                  END IF;
23679 
23680              END LOOP; -- for all docs
23681 
23682              IF (l_delv_chnl_common_flag = TRUE) THEN
23683 
23684                  /*
23685                   * This means that all the docs of this payment
23686                   * have the same delivery channel.
23687                   *
23688                   * Set this value on the payment (if not null)
23689                   */
23690                  IF (l_temp_delv_chnl IS NOT NULL) THEN
23691 
23692                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23693                      print_debuginfo(l_module_name, 'All documents of payment '
23694                          || x_paymentTab(i).payment_id
23695                          || ' have the same delivery channel code '
23696                          || l_temp_delv_chnl
23697                          || '. Hence setting this attribute on the '
23698                          || 'payment itself.'
23699                          );
23700 		     END IF;
23701                      x_paymentTab(i).delivery_channel_code := l_temp_delv_chnl;
23702 
23703                  ELSE
23704 
23705                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23706                      print_debuginfo(l_module_name, 'Not setting delivery '
23707                          || 'channel for pmt id: '
23708                          || x_paymentTab(i).payment_id
23709                          );
23710 			 END IF;
23711                  END IF; -- if delv chnl is not null
23712 
23713              END IF; -- if delv chnl common flag set to TRUE
23714 
23715          END IF; -- if delv chnl is null
23716 
23717      END LOOP; -- for all pmts
23718 
23719      /*
23720       * Fix for bug 5586678:
23721       *
23722       * Sweep for unique remittance identifier.
23723       */
23724      FOR i IN x_paymentTab.FIRST .. x_paymentTab.LAST LOOP
23725 
23726          /*
23727           * Initialize for each payment iteration.
23728           */
23729          l_uri_common_flag       := TRUE;
23730          l_temp_uri              := NULL;
23731          l_temp_uri_ckdigits     := NULL;
23732          l_first_record          := TRUE;
23733 
23734          /*
23735           * Only attempt to derive the unique remit identifier if
23736           * the payment does not already have a unique remit id
23737           * set.
23738           */
23739          IF (x_paymentTab(i).unique_remittance_identifier IS NULL) THEN
23740 
23741              FOR j IN x_docsInPmtTab.FIRST .. x_docsInPmtTab.LAST LOOP
23742 
23743                  IF (x_paymentTab(i).payment_id = x_docsInPmtTab(j).payment_id)
23744                  THEN
23745 
23746                      /*
23747                       * If this is the first document for the payment
23748                       * in consideration, initialize the temp URI
23749                       * with the URI on the current doc.
23750                       */
23751                      IF (l_first_record = TRUE) THEN
23752 
23753                          l_temp_uri          := x_docsInPmtTab(j).
23754                                                     unique_remit_id;
23755 
23756                          l_temp_uri_ckdigits := x_docsInPmtTab(j).
23757                                                     uri_ckdigits;
23758 
23759                      ELSE
23760 
23761                          /*
23762                           * If the URI on the current document does not
23763                           * match the URI on the previously stored
23764                           * document, then the URI is not common across
23765                           * all docs of this payment.
23766                           */
23767 
23768                          IF (l_temp_uri <>
23769                              x_docsInPmtTab(j).unique_remit_id) THEN
23770 
23771                              l_uri_common_flag := FALSE;
23772 
23773                              /*
23774                               * Exit iteration for this payment.
23775                               */
23776                              EXIT;
23777 
23778                          END IF; -- if URI does not match
23779 
23780                      END IF; -- if first record
23781 
23782                  END IF; -- if doc is for current payment
23783 
23784                  /*
23785                   * Reset the first record flag.
23786                   */
23787                  /*
23788                   * When checking for the first record, also
23789                   * check that that the URI variable
23790                   * is not null. Otherwise, we might be
23791                   * setting the first record flag based
23792                   * on some document unrelated to this payment.
23793                   */
23794                  IF (l_temp_uri IS NOT NULL) THEN
23795                      IF (l_first_record = TRUE) THEN
23796                          l_first_record := FALSE;
23797                      END IF;
23798                  END IF;
23799 
23800              END LOOP; -- for all docs
23801 
23802              IF (l_uri_common_flag = TRUE) THEN
23803 
23804                  /*
23805                   * This means that all the docs of this payment
23806                   * have the same unique remit id.
23807                   *
23808                   * Set this value on the payment (if not null)
23809                   */
23810                  IF (l_temp_uri IS NOT NULL) THEN
23811 
23812                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23813                      print_debuginfo(l_module_name, 'All documents of payment '
23814                          || x_paymentTab(i).payment_id
23815                          || ' have the same unique remit id '
23816                          || l_temp_uri
23817                          || '. Hence setting this attribute on the '
23818                          || 'payment itself.'
23819                          );
23820  END IF;
23821                      x_paymentTab(i).unique_remittance_identifier :=
23822                          l_temp_uri;
23823                      x_paymentTab(i).uri_check_digit :=
23824                          l_temp_uri_ckdigits;
23825 
23826                  ELSE
23827 
23828                      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23829                      print_debuginfo(l_module_name, 'Not setting unique '
23830                          || 'remit id for pmt id: '
23831                          || x_paymentTab(i).payment_id
23832                          );
23833 		     END IF;
23834                  END IF; -- if unique remit id is not null
23835 
23836              END IF; -- if unique remit id common flag set to TRUE
23837 
23838          END IF; -- if unique remit id is null
23839 
23840      END LOOP; -- for all pmts
23841 
23842      print_debuginfo(l_module_name, 'EXIT');
23843 
23844  END sweepCommonPmtAttributes;
23845 
23846 
23847 
23848 /*--------------------------------------------------------------------
23849  | NAME:
23850  |     GET_PAYER_INFO
23851  |
23852  | PURPOSE:
23853  |
23854  |
23855  |
23856  | PARAMETERS:
23857  |     IN
23858  |
23859  |
23860  |     OUT
23861  |
23862  |
23863  | RETURNS:
23864  |
23865  | NOTES:
23866  |
23867  |
23868  |
23869  *---------------------------------------------------------------------*/
23870  PROCEDURE GET_PAYER_INFO(
23871 	l_trx_payer_index      IN BINARY_INTEGER
23872      )
23873  IS
23874  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
23875                                                   '.GET_PAYER_INFO';
23876  l_payer_info_index BINARY_INTEGER;
23877 
23878 	  CURSOR c_payer_info(l_trx_index BINARY_INTEGER) IS
23879 
23880 	  SELECT
23881 
23882 	  payer_party.party_number,            -- payer party number
23883 	  '',                                  -- payer party site name
23884 	  payer.name,                          -- payer name
23885 	  IBY_FD_EXTRACT_GEN_PVT.              -- payer tax reg number
23886 	      Get_FP_TaxRegistration
23887 		  (
23888 		  payer.legal_entity_id
23889 		  ),
23890 	  payer.registration_number,           -- payer le reg number
23891 	  payer.party_id,                      -- payer_party_id
23892 	  payer.location_id,                   -- payer_location_id
23893 	  payer_party.attribute_category,      -- payer party attr category
23894 	  payer.attribute_category,            -- payer LE attr category     -- 10
23895 	  '',                                  -- payer abbrev agency code
23896 	  ''                                  -- payer federal us employer id
23897 
23898 	  FROM
23899 	  XLE_FIRSTPARTY_INFORMATION_V  payer,
23900 	  HZ_PARTIES               payer_party
23901 
23902 	  WHERE
23903 
23904 	  /* payer */
23905 	  IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_index)  = payer.legal_entity_id
23906 	  AND payer.party_id                 = payer_party.party_id
23907 	  ;
23908 
23909 
23910  BEGIN
23911 
23912        IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23913        print_debuginfo(l_module_name, 'ENTER');
23914        END IF;
23915 
23916       -- print_debuginfo(l_module_name, 'l_trx_payer_index - '|| l_trx_payer_index);
23917 
23918       l_payer_info_index := IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_payer_index);
23919 
23920       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23921       print_debuginfo(l_module_name, 'l_payer_info_index - '|| l_payer_info_index);
23922       END IF;
23923 
23924       IF (l_payer_info_tbl.EXISTS(l_payer_info_index)) THEN
23925 
23926       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23927         print_debuginfo(l_module_name, 'Data exist in cache..');
23928       END IF;
23929 
23930         IBY_PAYGROUP_PUB.pmtTable.payer_party_number(l_trx_payer_index) := l_payer_info_tbl(l_payer_info_index).payer_party_number;
23931 	IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_party_site_name;
23932 	IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_legal_entity_name;
23933 	IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_tax_registration_num;
23934 	IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_le_registration_num;
23935 	IBY_PAYGROUP_PUB.pmtTable.payer_party_id(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_party_id;
23936 	IBY_PAYGROUP_PUB.pmtTable.payer_location_id(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_location_id;
23937 	IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_party_attr_category;
23938 	IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_le_attr_category;
23939 	IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_abbreviated_agency_code;
23940 	IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(l_trx_payer_index):= l_payer_info_tbl(l_payer_info_index).payer_federal_us_employer_id;
23941 
23942       ELSE
23943             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23944               print_debuginfo(l_module_name, 'Hitting DB again.');
23945             END IF;
23946 	      OPEN  c_payer_info(l_trx_payer_index);
23947 	      FETCH c_payer_info INTO
23948 		IBY_PAYGROUP_PUB.pmtTable.payer_party_number(l_trx_payer_index),
23949 		IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(l_trx_payer_index),
23950 		IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(l_trx_payer_index),
23951 		IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(l_trx_payer_index),
23952 		IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(l_trx_payer_index),
23953 		IBY_PAYGROUP_PUB.pmtTable.payer_party_id(l_trx_payer_index),
23954 		IBY_PAYGROUP_PUB.pmtTable.payer_location_id(l_trx_payer_index),
23955 		IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(l_trx_payer_index),
23956 		IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(l_trx_payer_index),
23957 		IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(l_trx_payer_index),
23958 		IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(l_trx_payer_index)
23959 		;
23960 	      CLOSE c_payer_info;
23961 	 l_payer_info_tbl(l_payer_info_index).payer_party_number := IBY_PAYGROUP_PUB.pmtTable.payer_party_number(l_trx_payer_index) ;
23962 	 l_payer_info_tbl(l_payer_info_index).payer_party_site_name :=	IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(l_trx_payer_index);
23963 	 l_payer_info_tbl(l_payer_info_index).payer_legal_entity_name :=	IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(l_trx_payer_index);
23964 	 l_payer_info_tbl(l_payer_info_index).payer_tax_registration_num := IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(l_trx_payer_index) ;
23965 	 l_payer_info_tbl(l_payer_info_index).payer_le_registration_num :=IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(l_trx_payer_index);
23966 	 l_payer_info_tbl(l_payer_info_index).payer_party_id :=IBY_PAYGROUP_PUB.pmtTable.payer_party_id(l_trx_payer_index);
23967 	 l_payer_info_tbl(l_payer_info_index).payer_location_id :=	IBY_PAYGROUP_PUB.pmtTable.payer_location_id(l_trx_payer_index);
23968 	 l_payer_info_tbl(l_payer_info_index).payer_party_attr_category :=	IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(l_trx_payer_index);
23969 	 l_payer_info_tbl(l_payer_info_index).payer_le_attr_category :=	IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(l_trx_payer_index);
23970 	 l_payer_info_tbl(l_payer_info_index).payer_abbreviated_agency_code :=	IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(l_trx_payer_index);
23971 	 l_payer_info_tbl(l_payer_info_index).payer_federal_us_employer_id :=	IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(l_trx_payer_index);
23972 
23973 
23974       END IF;
23975      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
23976      print_debuginfo(l_module_name, 'EXIT');
23977      END IF;
23978 
23979  END GET_PAYER_INFO;
23980 
23981  /*--------------------------------------------------------------------
23982  | NAME:
23983  |     GET_PAYER_ACCT_INFO
23984  |
23985  | PURPOSE:
23986  |
23987  |
23988  |
23989  | PARAMETERS:
23990  |     IN
23991  |
23992  |
23993  |     OUT
23994  |
23995  |
23996  | RETURNS:
23997  |
23998  | NOTES:
23999  |
24000  |
24001  |
24002  *---------------------------------------------------------------------*/
24003  PROCEDURE GET_PAYER_ACCT_INFO(
24004 	l_trx_acct_index      IN BINARY_INTEGER
24005      )
24006  IS
24007  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
24008                                                   '.GET_PAYER_ACCT_INFO';
24009 
24010 l_payer_acct_index   BINARY_INTEGER;
24011 	  CURSOR c_payer_acct_info(l_trx_index BINARY_INTEGER) IS
24012 
24013 	 SELECT
24014 
24015 	 /* PAYER BANK */
24016 	  iba_bnk_branch.bank_name,            -- payer bank name
24017 	  iba_bnk_branch.bank_number,          -- payer bank number
24018 	  iba_bnk_branch.branch_number,        -- payer bank branch number
24019 	  iba_bnk_branch.bank_branch_name,     -- payer bank branch name
24020 	  iba_bnk_branch.eft_swift_code,       -- payer bank swift code
24021 	  iba.bank_account_num,                -- payer bank account num
24022 	  iba.bank_account_name,               -- payer bank account name
24023 	  iba.iban_number,                     -- payer bank acct iban number -- 20
24024 	  iba.agency_location_code,            -- payer bank agency location code
24025 	  iba_bnk_branch.branch_party_id,      -- payer bank branch party id
24026 	  iba_bnk_branch.bank_name_alt,        -- payer bank alt name
24027 	  iba_bnk_branch.bank_branch_name_alt, -- payer bank branch alt name
24028 	  iba.bank_account_name_alt,           -- payer bank alt account name
24029 	  iba.bank_account_num_electronic,     -- payer bank account num electronic
24030 	  iba_branch_party_site.location_id,   -- payer bank branch location id
24031 	  iba_bnk_branch.eft_user_number,      -- payer bank branch eft user num
24032 	    /* RFC */
24033 	  rfc_ca.class_code
24034 
24035 
24036 	  FROM
24037 
24038 	   /* Payer bank */
24039 	  CE_BANK_ACCOUNTS         iba,
24040 	  CE_BANK_BRANCHES_V       iba_bnk_branch,
24041 	  HZ_PARTY_SITES           iba_branch_party_site,
24042 	    /* RFC */
24043 	  HZ_CODE_ASSIGNMENTS          rfc_ca
24044 
24045 	  WHERE
24046 	  /* payer bank */
24047 	  IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(l_trx_index) = iba.bank_account_id
24048 	  AND iba_bnk_branch.branch_party_id = iba.bank_branch_id
24049 
24050 	  /* payer bank location */
24051 	  AND iba_bnk_branch.branch_party_id = iba_branch_party_site.party_id(+)
24052 	  /* RFC related */
24053 	  AND rfc_ca.owner_table_name(+)     = 'HZ_PARTIES'
24054 	  AND rfc_ca.class_category(+)       = 'RFC_IDENTIFIER'
24055 	  AND rfc_ca.owner_table_id(+)       = iba.bank_branch_id
24056 	  ;
24057 
24058 
24059 
24060  BEGIN
24061      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24062      print_debuginfo(l_module_name, 'ENTER');
24063      END IF;
24064 
24065      l_payer_acct_index :=IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(l_trx_acct_index) ;
24066 
24067      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24068      print_debuginfo(l_module_name, 'l_payer_acct_index -'||l_payer_acct_index);
24069      END IF;
24070 
24071      IF (l_payer_acct_info_tbl.EXISTS(l_payer_acct_index)) THEN
24072 
24073       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24074 	print_debuginfo(l_module_name , 'Data exists in cache');
24075       END IF;
24076      	IBY_PAYGROUP_PUB.pmtTable.int_bank_name(l_trx_acct_index)                  	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_name;
24077 	IBY_PAYGROUP_PUB.pmtTable.int_bank_number(l_trx_acct_index)    := l_payer_acct_info_tbl(l_payer_acct_index).int_bank_number;
24078 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(l_trx_acct_index) := l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_number;
24079 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(l_trx_acct_index) := l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_name;
24080 
24081 	IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(l_trx_acct_index)  := l_payer_acct_info_tbl(l_payer_acct_index).int_eft_swift_code;
24082 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(l_trx_acct_index)        	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_number;
24083 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(l_trx_acct_index)          	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_name;
24084 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(l_trx_acct_index)          	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_iban;
24085 	IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(l_trx_acct_index)  	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_acct_agency_loc_code;
24086 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(l_trx_acct_index)       	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_party_id;
24087 	IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(l_trx_acct_index)              	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_alt_name;
24088 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(l_trx_acct_index)       	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_alt_name;
24089 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(l_trx_acct_index)      	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_alt_name;
24090 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(l_trx_acct_index)      	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_num_elec;
24091 
24092 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(l_trx_acct_index)    	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_location_id;
24093 
24094 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(l_trx_acct_index)   	:= l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_eft_user_num;
24095 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(l_trx_acct_index)      := l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_rfc_identifier;
24096 
24097 
24098      ELSE
24099 
24100       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24101       print_debuginfo(l_module_name , 'Data doesnt exist, hitting DB');
24102       END IF;
24103       OPEN  c_payer_acct_info(l_trx_acct_index);
24104       FETCH c_payer_acct_info INTO
24105 	IBY_PAYGROUP_PUB.pmtTable.int_bank_name(l_trx_acct_index)                  	,
24106 	IBY_PAYGROUP_PUB.pmtTable.int_bank_number(l_trx_acct_index)    ,
24107 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(l_trx_acct_index) ,
24108 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(l_trx_acct_index) ,
24109 
24110 	IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(l_trx_acct_index)  ,
24111 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(l_trx_acct_index)        	,
24112 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(l_trx_acct_index)          	,
24113 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(l_trx_acct_index)          	,
24114 	IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(l_trx_acct_index)  	,
24115 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(l_trx_acct_index)       	,
24116 	IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(l_trx_acct_index)              	,
24117 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(l_trx_acct_index)       	,
24118 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(l_trx_acct_index)      	,
24119 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(l_trx_acct_index)      	,
24120 
24121 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(l_trx_acct_index)    	,
24122 
24123 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(l_trx_acct_index)   	,
24124 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(l_trx_acct_index)
24125 	;
24126       CLOSE c_payer_acct_info;
24127          l_payer_acct_info_tbl(l_payer_acct_index).int_bank_name   :=    	IBY_PAYGROUP_PUB.pmtTable.int_bank_name(l_trx_acct_index);
24128 	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_number := IBY_PAYGROUP_PUB.pmtTable.int_bank_number(l_trx_acct_index);
24129          l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_number :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(l_trx_acct_index);
24130 	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_name := IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(l_trx_acct_index);
24131 
24132          l_payer_acct_info_tbl(l_payer_acct_index).int_eft_swift_code :=	IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(l_trx_acct_index);
24133     	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_number :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(l_trx_acct_index) ;
24134 	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_name :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(l_trx_acct_index);
24135          l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_iban := IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(l_trx_acct_index);
24136 	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_acct_agency_loc_code :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(l_trx_acct_index);
24137 	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_party_id :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(l_trx_acct_index);
24138 	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_alt_name :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(l_trx_acct_index);
24139        	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_alt_name :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(l_trx_acct_index);
24140      	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_alt_name :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(l_trx_acct_index);
24141      	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_account_num_elec :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(l_trx_acct_index);
24142 
24143    	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_location_id :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(l_trx_acct_index);
24144 
24145    	 l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_eft_user_num :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(l_trx_acct_index);
24146          l_payer_acct_info_tbl(l_payer_acct_index).int_bank_branch_rfc_identifier :=	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(l_trx_acct_index);
24147 
24148      END IF;
24149 
24150      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24151      print_debuginfo(l_module_name, 'EXIT');
24152      END IF;
24153 
24154  END GET_PAYER_ACCT_INFO;
24155 
24156 
24157  /*--------------------------------------------------------------------
24158  | NAME:
24159  |     GET_VENDOR_INFO
24160  |
24161  | PURPOSE:
24162  |
24163  |
24164  |
24165  | PARAMETERS:
24166  |     IN
24167  |
24168  |
24169  |     OUT
24170  |
24171  |
24172  | RETURNS:
24173  |
24174  | NOTES:
24175  |
24176  |
24177  |
24178  *---------------------------------------------------------------------*/
24179  PROCEDURE GET_VENDOR_INFO(
24180 	l_trx_vend_index      IN BINARY_INTEGER
24181      )
24182  IS
24183  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
24184                                                   '.GET_VENDOR_INFO';
24185 
24186  l_vendor_index   varchar2(4000);
24187  l_vendor_tax_reg_index   VARCHAR2(4000);
24188 
24189 	  CURSOR c_vendor_info(l_trx_index BINARY_INTEGER)
24190 	  IS
24191 	  SELECT
24192 	  /* VENDOR RELATED */
24193 	  vendor_site.vendor_site_code,    -- payee supplier site name
24194 	  vendor_site.vendor_site_code_alt,    -- payee site alternate name
24195 	  vendor.segment1,                     -- payee supplier number
24196 	  vendor.customer_num,                 -- payee first party reference  -- 50
24197 	  vendor.attribute_category,           -- payee supplier attr category
24198 	  vendor.vendor_id,                    -- payee supplier id
24199 
24200 	 decode(upper(vendor.vendor_type_lookup_code),
24201 		  'EMPLOYEE',null
24202 				,
24203 		  'CONTRACTOR',decode(vendor.organization_type_lookup_code,
24204 				      'INDIVIDUAL',vendor.individual_1099,
24205 				      'FOREIGN INDIVIDUAL',vendor.individual_1099,
24206 				      'PARTNERSHIP',vendor.individual_1099,
24207 				      'FOREIGN PARTNERSHIP',vendor.individual_1099,
24208 				      vendor.num_1099),
24209 		  vendor.num_1099),            -- payee Tax Identification Number
24210 	  vendor_site.attribute_category           -- vendor site attr category
24211 
24212 
24213 	  FROM
24214 	  /* Vendor related */
24215 	  AP_SUPPLIERS               vendor,
24216 	  AP_SUPPLIER_SITES_ALL      vendor_site
24217 	 -- PER_PEOPLE_X               per
24218 
24219 	  WHERE
24220 
24221 	  /* vendor related */
24222 	  IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_index)		  = vendor.party_id(+)
24223 	  AND IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_index)     = vendor_site.vendor_site_id(+)
24224 	  AND vendor.vendor_id						  = vendor_site.vendor_id
24225 	  --          AND IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index)   = per.person_id(+)
24226 	  ;
24227 
24228     CURSOR c_le_registration_num_info(l_trxn_index BINARY_INTEGER)
24229       IS
24230       SELECT hzp.jgzz_fiscal_code
24231       FROM HZ_PARTIES hzp
24232       WHERE
24233       IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trxn_index)		  = hzp.party_id;
24234 
24235  BEGIN
24236 
24237      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24238      print_debuginfo(l_module_name, 'ENTER');
24239 
24240      print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_vend_index)'|| IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_vend_index));
24241      print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_vend_index)'||IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_vend_index));
24242      print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_vend_index)'|| IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_vend_index));
24243      END IF;
24244 
24245      l_vendor_index := Nvl(IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_vend_index),-999)
24246                         ||'$'
24247                         || Nvl(IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_vend_index),-999)
24248 		                  	|| '$'
24249 			                  || Nvl(IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_vend_index),-999);
24250      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24251      print_debuginfo(l_module_name ,'l_vendor_index - '|| l_vendor_index);
24252      END IF;
24253 
24254       IF (l_vendor_info_tbl.EXISTS(l_vendor_index)) THEN
24255        IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24256        print_debuginfo(l_module_name ,'Data already exists in cache');
24257        END IF;
24258        	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(l_trx_vend_index)   := l_vendor_info_tbl(l_vendor_index).payee_supplier_site_name;
24259        	IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_vend_index)   := l_vendor_info_tbl(l_vendor_index).payee_site_alternate_name;
24260 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_vend_index)             := l_vendor_info_tbl(l_vendor_index).payee_supplier_number;
24261 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_vend_index)	      := l_vendor_info_tbl(l_vendor_index).payee_first_party_reference;
24262 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_vend_index)      := l_vendor_info_tbl(l_vendor_index).payee_supplier_attr_category;
24263 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_vend_index)                 := l_vendor_info_tbl(l_vendor_index).payee_supplier_id;
24264 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_vend_index)         := l_vendor_info_tbl(l_vendor_index).payee_le_registration_num;
24265 	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_vend_index)         := l_vendor_info_tbl(l_vendor_index).payee_spplr_site_attr_category;
24266 
24267       ELSE
24268       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24269       print_debuginfo(l_module_name ,'Need to query DB again');
24270       END IF;
24271 
24272       OPEN  c_vendor_info(l_trx_vend_index);
24273       FETCH c_vendor_info INTO
24274 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(l_trx_vend_index),
24275 	IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_vend_index),
24276 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_vend_index),
24277 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_vend_index)	,
24278 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_vend_index),
24279 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_vend_index),
24280 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_vend_index),
24281 	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_vend_index)
24282 	;
24283 
24284       CLOSE c_vendor_info;
24285 
24286   IF(NVL(IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_vend_index),-99)  <0) THEN
24287       OPEN c_le_registration_num_info(l_trx_vend_index);
24288       FETCH c_le_registration_num_info
24289       INTO IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_vend_index);
24290        print_debuginfo(l_module_name, 'Legal Enity Registration Number:' ||IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_vend_index));
24291       CLOSE c_le_registration_num_info;
24292   END IF;
24293    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24294  print_debuginfo(l_module_name, 'After fetching the value from the cursor');
24295    END IF;
24296   l_vendor_info_tbl(l_vendor_index).payee_supplier_site_name     :=IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(l_trx_vend_index) ;
24297   l_vendor_info_tbl(l_vendor_index).payee_site_alternate_name     :=IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_vend_index) ;
24298  l_vendor_info_tbl(l_vendor_index).payee_supplier_number         :=IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_vend_index);
24299  l_vendor_info_tbl(l_vendor_index).payee_first_party_reference   :=	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_vend_index);
24300  l_vendor_info_tbl(l_vendor_index).payee_supplier_attr_category  :=	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_vend_index);
24301  l_vendor_info_tbl(l_vendor_index).payee_supplier_id             :=	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_vend_index);
24302  l_vendor_info_tbl(l_vendor_index).payee_le_registration_num     :=	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_vend_index);
24303  l_vendor_info_tbl(l_vendor_index).payee_spplr_site_attr_category     :=	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_vend_index);
24304 
24305 
24306       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24307  print_debuginfo(l_module_name ,'After caching the values.. ');
24308       END IF;
24309       END IF;
24310 
24311   l_vendor_tax_reg_index := NVL(IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_vend_index),-999) ||'$' || NVL(IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_vend_index),-999);
24312   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24313   print_debuginfo(l_module_name ,'l_vendor_tax_reg_index - '|| l_vendor_tax_reg_index);
24314   END IF;
24315 
24316 
24317   IF (l_vendor_tax_reg_info_tbl.EXISTS(l_vendor_tax_reg_index)) THEN
24318    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24319    print_debuginfo(l_module_name ,'Tax Registration data already exists in cache');
24320    END IF;
24321    IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(l_trx_vend_index) := l_vendor_tax_reg_info_tbl(l_vendor_tax_reg_index).payee_tax_registration_num;
24322 
24323   ELSE
24324     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24325     print_debuginfo(l_module_name ,'Need to query DB again for Tax registration Number');
24326     END IF;
24327 
24328    iby_paygroup_pub.pmttable.payee_tax_registration_num(l_trx_vend_index) :=
24329           IBY_FD_EXTRACT_GEN_PVT.              -- payee tax registration number
24330 	          Get_Payee_TaxRegistration
24331 	          (
24332 	           IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_vend_index),IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_vend_index)
24333 	          );
24334 
24335     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24336     print_debuginfo(l_module_name, 'After fetching the tax registration number value');
24337     END IF;
24338    l_vendor_tax_reg_info_tbl(l_vendor_tax_reg_index).payee_tax_registration_num := iby_paygroup_pub.pmttable.payee_tax_registration_num(l_trx_vend_index);
24339 
24340   END IF;
24341      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24342      print_debuginfo(l_module_name, 'EXIT');
24343      END IF;
24344 
24345  END GET_VENDOR_INFO;
24346 
24347 
24348 
24349 PROCEDURE GET_PAYEE(
24350 	l_trx_payee_index      IN BINARY_INTEGER
24351      )
24352  IS
24353  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
24354                                                   '.GET_PAYEE';
24355 
24356  l_payee_index BINARY_INTEGER;
24357 
24358 	  CURSOR c_payee_info(l_trx_index BINARY_INTEGER) IS
24359 
24360 	  SELECT
24361 	  payee.party_number,                  -- payee party number
24362 
24363 	  DECODE(IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index),
24364    NULL,payee.party_name,
24365    Get_Employee_Full_Name(IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index),payee.party_id,payee.party_name)),                    -- payee party name           -- 30
24366 
24367 	  DECODE(IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index),
24368    NULL,payee.party_name,
24369    Get_Employee_Full_Name(IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index),payee.party_id,payee.party_name)),                    -- payee name
24370 
24371 	  DECODE(                              -- payee alternate name
24372 		payee.party_type,
24373 		'ORGANIZATION',
24374 		    payee.organization_name_phonetic,
24375 		'PERSON',
24376 		    payee.person_first_name_phonetic
24377 			|| ' '
24378 			|| payee.person_last_name_phonetic
24379 		),
24380 
24381           DECODE (IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(l_trx_index),
24382               NULL,
24383               payee.party_name,
24384               (SELECT
24385                    benef_party.party_name
24386                FROM
24387                    HZ_PARTIES benef_party
24388                WHERE
24389                    benef_party.party_id=IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(l_trx_index)
24390               )
24391            ),                          -- beneficiary name
24392 
24393 	  payee.attribute_category            -- payee party attr category
24394 
24395           FROM
24396 	  HZ_PARTIES               payee
24397 
24398 	  WHERE
24399 
24400 	  IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_index)             = payee.party_id
24401 		   ;
24402 
24403  BEGIN
24404 
24405      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24406      print_debuginfo(l_module_name, 'ENTER');
24407      END IF;
24408 
24409      l_payee_index := IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_payee_index);
24410 
24411 
24412 
24413      IF (l_payee_info_tbl.EXISTS(l_payee_index)) THEN
24414 	IBY_PAYGROUP_PUB.pmtTable.payee_party_number(l_trx_payee_index) := l_payee_info_tbl(l_payee_index).payee_party_number;
24415 	IBY_PAYGROUP_PUB.pmtTable.payee_party_name(l_trx_payee_index):= l_payee_info_tbl(l_payee_index).payee_party_name;
24416 	IBY_PAYGROUP_PUB.pmtTable.payee_name(l_trx_payee_index):= l_payee_info_tbl(l_payee_index).payee_name;
24417 	IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(l_trx_payee_index):= l_payee_info_tbl(l_payee_index).payee_alt_name;
24418 	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(l_trx_payee_index):= l_payee_info_tbl(l_payee_index).beneficiary_name;
24419 	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(l_trx_payee_index):= l_payee_info_tbl(l_payee_index).payee_party_atr_cat;
24420      ELSE
24421 
24422       OPEN  c_payee_info(l_trx_payee_index);
24423       FETCH c_payee_info INTO
24424 	IBY_PAYGROUP_PUB.pmtTable.payee_party_number(l_trx_payee_index),
24425 	IBY_PAYGROUP_PUB.pmtTable.payee_party_name(l_trx_payee_index),
24426 	IBY_PAYGROUP_PUB.pmtTable.payee_name(l_trx_payee_index),
24427 	IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(l_trx_payee_index),
24428 	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(l_trx_payee_index),
24429 	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(l_trx_payee_index)
24430 	;
24431 
24432       IF (c_payee_info%NOTFOUND  = TRUE) THEN
24433 
24434 	      IBY_PAYGROUP_PUB.pmtTable.payee_party_number(l_trx_payee_index):= NULL;
24435 	      IBY_PAYGROUP_PUB.pmtTable.payee_party_name(l_trx_payee_index):= NULL;
24436 	      IBY_PAYGROUP_PUB.pmtTable.payee_name(l_trx_payee_index):= NULL;
24437 	      IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(l_trx_payee_index):= NULL;
24438 	    	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(l_trx_payee_index) := NULL;
24439         	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(l_trx_payee_index):= NULL;
24440 
24441       END IF;
24442       CLOSE c_payee_info;
24443 
24444 	 l_payee_info_tbl(l_payee_index).payee_party_number :=	IBY_PAYGROUP_PUB.pmtTable.payee_party_number(l_trx_payee_index) ;
24445 	 l_payee_info_tbl(l_payee_index).payee_party_name   :=  IBY_PAYGROUP_PUB.pmtTable.payee_party_name(l_trx_payee_index);
24446 	 l_payee_info_tbl(l_payee_index).payee_name         :=  IBY_PAYGROUP_PUB.pmtTable.payee_name(l_trx_payee_index);
24447 	 l_payee_info_tbl(l_payee_index).payee_alt_name     :=  IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(l_trx_payee_index);
24448 
24449 	 l_payee_info_tbl(l_payee_index).beneficiary_name  :=	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(l_trx_payee_index);
24450         l_payee_info_tbl(l_payee_index).payee_party_atr_cat := 	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(l_trx_payee_index);
24451 
24452 
24453      END IF;
24454 
24455 
24456      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24457      print_debuginfo(l_module_name, 'EXIT');
24458      END IF;
24459 
24460  END GET_PAYEE;
24461 
24462 
24463    /*--------------------------------------------------------------------
24464  | NAME:
24465  |     GET_PAYEE_SITE_INFO
24466  |
24467  | PURPOSE:
24468  |
24469  |
24470  |
24471  | PARAMETERS:
24472  |     IN
24473  |
24474  |
24475  |     OUT
24476  |
24477  |
24478  | RETURNS:
24479  |
24480  | NOTES:
24481  |
24482  |
24483  |
24484  *---------------------------------------------------------------------*/
24485  PROCEDURE GET_PAYEE_SITE_INFO(
24486 	l_trx_payee_index      IN BINARY_INTEGER
24487      )
24488  IS
24489  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
24490                                                   '.GET_PAYEE_SITE_INFO';
24491 
24492  l_payee_index BINARY_INTEGER;
24493 
24494 	  CURSOR c_payee_site_info(l_trx_index BINARY_INTEGER) IS
24495 
24496 	  SELECT
24497 	   payee_site.attribute_category,       -- payee supplier site attr category
24498 	   payee_site.party_site_name,          -- payee party site name
24499 	   payee_site.addressee
24500 
24501 	  FROM
24502 
24503 	   HZ_PARTY_SITES           payee_site
24504  	  WHERE
24505 	   /* payment related */
24506 
24507 	   IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_index)    = payee_site.party_site_id(+)
24508 	   ;
24509 
24510  BEGIN
24511 
24512      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24513      print_debuginfo(l_module_name, 'ENTER');
24514      END IF;
24515 
24516 
24517   l_payee_index :=  IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_payee_index);
24518 
24519 
24520   IF (l_payee_site_tbl.EXISTS(l_payee_index)) THEN
24521 
24522      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24523      print_debuginfo(l_module_name, 'payee site table NOT empty');
24524      END IF;
24525 
24526    IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_payee_index) := NVL(IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_payee_index),l_payee_site_tbl(l_payee_index).payee_spplr_site_attr_category);
24527    IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(l_trx_payee_index) := l_payee_site_tbl(l_payee_index).payee_party_site_name;
24528    IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_payee_index) := l_payee_site_tbl(l_payee_index).payee_addressee;
24529 
24530   ELSE
24531 
24532       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24533       print_debuginfo(l_module_name, 'payee site table empty');
24534       END IF;
24535 
24536       OPEN  c_payee_site_info(l_trx_payee_index);
24537       FETCH c_payee_site_info INTO
24538 	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_payee_index),
24539 	IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(l_trx_payee_index),
24540 	IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_payee_index)
24541 	;
24542 
24543       IF(c_payee_site_info%NOTFOUND = TRUE) THEN
24544 
24545              IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24546               print_debuginfo(l_module_name, 'payee site info NOT FOUND');
24547              END IF;
24548 
24549 	      IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_payee_index) := NULL;
24550 	      IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(l_trx_payee_index) := NULL;
24551 	      IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_payee_index) := NULL;
24552 
24553       ELSE
24554 
24555               IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24556               print_debuginfo(l_module_name, 'payee site info FOUND');
24557               print_debuginfo(l_module_name, 'assigning payee_spplr_site_attr_category');
24558               END IF;
24559               l_payee_site_tbl(l_payee_index).payee_spplr_site_attr_category := IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_payee_index);
24560               IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24561               print_debuginfo(l_module_name, 'assigning payee_party_site_name');
24562               END IF;
24563               l_payee_site_tbl(l_payee_index).payee_party_site_name       := IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(l_trx_payee_index);
24564               IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24565               print_debuginfo(l_module_name, 'assigning payee_addressee');
24566               END IF;
24567               l_payee_site_tbl(l_payee_index).payee_addressee       := IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_payee_index);
24568 
24569 
24570       END IF;
24571       CLOSE c_payee_site_info;
24572 
24573  END IF;
24574      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
24575      print_debuginfo(l_module_name, 'EXIT');
24576      END IF;
24577 
24578  END GET_PAYEE_SITE_INFO;
24579 
24580 
24581 
24582 
24583 
24584  /*--------------------------------------------------------------------
24585  | NAME:
24586  |     GET_PAYEE_ADDR_INFO
24587  |
24588  | PURPOSE:
24589  |
24590  |
24591  |
24592  | PARAMETERS:
24593  |     IN
24594  |
24595  |
24596  |     OUT
24597  |
24598  |
24599  | RETURNS:
24600  |
24601  | NOTES:
24602  |
24603  |
24604  |
24605  *---------------------------------------------------------------------*/
24606  PROCEDURE GET_PAYEE_ADDR_INFO(
24607 	l_trx_paye_adr_index      IN BINARY_INTEGER
24608      )
24609  IS
24610  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
24611                                                   '.GET_PAYEE_ADDR_INFO';
24612 l_payee_adr_index	VARCHAR2(200);
24613 
24614 /*
24615    Bug :: 9000814
24616    Cursor to fetch address based on type of  address code
24617 */
24618 
24619  /* Emp PROV ADDRESSES*/
24620 	  CURSOR c_emp_provs_addr(l_trx_index BINARY_INTEGER) IS
24621 
24622 	       SELECT
24623 
24624 	      /* payee add line1 */
24625 		  per_addr_prov.address_line1 add_line1,
24626 	      /* payee add line2 */
24627 		per_addr_prov.address_line2 add_line2,
24628                /* payee add line3 */
24629 		per_addr_prov.address_line3 add_line3,
24630               /* payee add line4 */
24631 		null add_line4,
24632 	      /* payee city */
24633                 per_addr_prov.town_or_city city,
24634 	      /* payee county */
24635 	         (DECODE(
24636 		    per_addr_prov.style,
24637 		    'US',     NVL(per_addr_prov.region_1,   ''),
24638 		    'US_GLB', NVL(per_addr_prov.region_1,   ''),
24639 		    'IE',     NVL(ap_web_db_expline_pkg.
24640 				      getcountyprovince(
24641 					  per_addr_prov.style,
24642 					  per_addr_prov.region_1),
24643 				''),
24644 		    'IE_GLB', NVL(ap_web_db_expline_pkg.
24645 				      getcountyprovince(
24646 					  per_addr_prov.style,
24647 					  per_addr_prov.region_1),
24648 				''),
24649 		    'GB',     NVL(ap_web_db_expline_pkg.
24650 				      getcountyprovince(
24651 					  per_addr_prov.style,
24652 					  per_addr_prov.region_1),
24653 				''),
24654 		    '')) county,
24655 
24656 	      /* payee province */
24657 	    	(DECODE(per_addr_prov.style,
24658 		    'US',      '',
24659 		    'US_GLB',  '',
24660 		    'IE',      '',
24661 		    'IE_GLB',  '',
24662 		    'GB',      '',
24663 		    'CA',      NVL(per_addr_prov.region_1,   ''),
24664 		    'CA_GLB',  NVL(per_addr_prov.region_1,   ''),
24665 		    'JP',      NVL(per_addr_prov.region_1,   ''),
24666 		    NVL(ap_web_db_expline_pkg.
24667 			    getcountyprovince(
24668 				per_addr_prov.style,
24669 				per_addr_prov.region_1),
24670 		      '')
24671 		    ) )province,
24672 	      /* payee state */
24673 		 DECODE(per_addr_prov.style,
24674 		     'CA',     '',
24675 		     'CA_GLB', '',
24676 		     NVL(per_addr_prov.region_2,   '')) state,
24677 	     /* payee country */
24678 		per_addr_prov.country country,
24679 	      /* payee postal code */
24680 		per_addr_prov.postal_code postal_code,
24681 	      /* payee address concat */
24682 		(  per_addr_prov.address_line1
24683 		    || ', '
24684 		    || per_addr_prov.address_line2
24685 		    || ', '
24686 		    || per_addr_prov.address_line3
24687 		    || ', '
24688 		    || per_addr_prov.town_or_city
24689 		    || ', '
24690 		    || DECODE(
24691 			 per_addr_prov.style,
24692 			 'CA',     '',
24693 			 'CA_GLB', '',
24694 			 NVL(per_addr_prov.region_2, '')
24695 			 )
24696 		    || ', '
24697 		    || per_addr_prov.country
24698 		    || ', '
24699 		    || per_addr_prov.postal_code)
24700 	       add_concat
24701 	  FROM
24702 	      /* Employee address related */
24703 	      PER_ADDRESSES            per_addr_prov
24704           WHERE
24705             IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index)         = per_addr_prov.person_id
24706 	    AND per_addr_prov.address_type = 'M'
24707 	    AND SYSDATE BETWEEN
24708 		    per_addr_prov.date_from
24709 		    AND NVL(per_addr_prov.date_to, SYSDATE+1);
24710 /* End of Provisional Addresses */
24711 
24712 
24713 /* FOR OFFICE ADDRESS*/
24714 	  CURSOR c_emp_offc_addr(l_trx_index BINARY_INTEGER) IS
24715 
24716 	       SELECT
24717 	      /* payee add line1 */
24718 	      per_loc.address_line_1 add_line1,
24719 	      /* payee add line2 */
24720 	      per_loc.address_line_2 add_line2,
24721 	      /* payee add line3 */
24722 	      per_loc.address_line_3 add_line3,
24723 	      /* payee add line4 */
24724 		null add_line4,
24725            /* payee city */
24726 		per_loc.town_or_city city,
24727            /* payee county */
24728 		  DECODE(
24729 		    per_loc.style,
24730 		    'US',      NVL(per_loc.region_1,   ''),
24731 		    'US_GLB',  NVL(per_loc.region_1,   ''),
24732 		    'IE',      NVL(ap_web_db_expline_pkg.
24733 				       getcountyprovince(
24734 					   per_loc.style,
24735 					   per_loc.region_1),
24736 				 ''),
24737 		    'IE_GLB',  NVL(ap_web_db_expline_pkg.
24738 				       getcountyprovince(
24739 					   per_loc.style,
24740 					   per_loc.region_1),
24741 				 ''),
24742 		    'GB',      NVL(ap_web_db_expline_pkg.
24743 				       getcountyprovince(
24744 					   per_loc.style,
24745 					   per_loc.region_1),
24746 				 ''),
24747 		    '') county,
24748 
24749 	      	  DECODE(per_loc.style,
24750 		    'US',      '',
24751 		    'US_GLB',  '',
24752 		    'IE',      '',
24753 		    'IE_GLB',  '',
24754 		    'GB',      '',
24755 		    'CA',      NVL(per_loc.region_1,   ''),
24756 		    'CA_GLB',  NVL(per_loc.region_1,   ''),
24757 		    'JP',      NVL(per_loc.region_1,   ''),
24758 		    NVL(ap_web_db_expline_pkg.
24759 			    getcountyprovince(
24760 				per_loc.style,
24761 				per_loc.region_1),
24762 		      '')
24763 		      ) province,
24764 
24765 	      /* payee state */
24766 	     DECODE(per_loc.style,
24767 		     'CA',     '',
24768 		     'CA_GLB', '',
24769 		     NVL(per_loc.region_2, '')) state,
24770 	     /* payee country */
24771 		per_loc.country country,
24772 	      /* payee postal code */
24773 		per_loc.postal_code postal_code,
24774             /* payee address concat */
24775 		 (per_loc.address_line_1
24776 		    || ', '
24777 		    || per_loc.address_line_2
24778 		    || ', '
24779 		    || per_loc.address_line_3
24780 		    || ', '
24781 		    || per_loc.town_or_city
24782 		    || ', '
24783 		    || DECODE(
24784 			 per_loc.style,
24785 			 'CA',     '',
24786 			 'CA_GLB', '',
24787 			 NVL(per_loc.region_2, '')
24788 			 )
24789 		    || ', '
24790 		    || per_loc.country
24791 		    || ', '
24792 		    || per_loc.postal_code) add_concat
24793 
24794 	  FROM
24795 	      /* Employee address related */
24796 	      HR_LOCATIONS             per_loc,
24797 	      PER_ALL_ASSIGNMENTS_F    per_assgn
24798 	  WHERE
24799 	    IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index)         = per_assgn.person_id
24800 	    AND per_assgn.location_id          = per_loc.location_id
24801 	    AND per_assgn.primary_flag         = 'Y'
24802 	    AND per_assgn.assignment_type = 'E'
24803 	    AND (TRUNC(SYSDATE) BETWEEN
24804 		    per_assgn.effective_start_date
24805 		    AND per_assgn.effective_end_date
24806 		) ;
24807 /* END OF OFFICE ADDRESS*/
24808 
24809 /* FOR HOME ADDRESS*/
24810 	  CURSOR c_emp_home_addr(l_trx_index BINARY_INTEGER) IS
24811 
24812 	       SELECT
24813 	      /* payee add line1 */
24814 		 per_addr.address_line1 add_line1,
24815                /* payee add line2 */
24816 		 per_addr.address_line2 add_line2,
24817 	      /* payee add line3 */
24818 		 per_addr.address_line3 add_line3,
24819 	      /* payee add line4 */
24820 		null   add_line4,
24821 	      /* payee city */
24822 		per_addr.town_or_city city,
24823 	      /* payee county */
24824 	      DECODE(
24825 		    per_addr.style,
24826 		    'US',     NVL(per_addr.region_1,   ''),
24827 		    'US_GLB', NVL(per_addr.region_1,   ''),
24828 		    'IE',     NVL(ap_web_db_expline_pkg.
24829 				      getcountyprovince(
24830 					  per_addr.style,
24831 					  per_addr.region_1),
24832 				''),
24833 		    'IE_GLB', NVL(ap_web_db_expline_pkg.
24834 				      getcountyprovince(
24835 					  per_addr.style,
24836 					  per_addr.region_1),
24837 				''),
24838 		    'GB',     NVL(ap_web_db_expline_pkg.
24839 				      getcountyprovince(
24840 					  per_addr.style,
24841 					  per_addr.region_1),
24842 				''),
24843 		    '')  county,
24844 
24845 	      /* payee province */
24846 		 DECODE(per_addr.style,
24847 		    'US',      '',
24848 		    'US_GLB',  '',
24849 		    'IE',      '',
24850 		    'IE_GLB',  '',
24851 		    'GB',      '',
24852 		    'CA',      NVL(per_addr.region_1,   ''),
24853 		    'CA_GLB',  NVL(per_addr.region_1,   ''),
24854 		    'JP',      NVL(per_addr.region_1,   ''),
24855 		    NVL(ap_web_db_expline_pkg.
24856 			    getcountyprovince(
24857 				per_addr.style,
24858 				per_addr.region_1),
24859 		      '')
24860 		    ) province,
24861 
24862 	      /* payee state */
24863 		DECODE(per_addr.style,
24864 		     'CA',     '',
24865 		     'CA_GLB', '',
24866 		     NVL(per_addr.region_2,   '')) state,
24867 	     /* payee country */
24868 		per_addr.country country,
24869 	      /* payee postal code */
24870 		per_addr.postal_code postal_code,
24871               /* payee address concat */
24872 		  (per_addr.address_line1
24873 		    || ', '
24874 		    || per_addr.address_line2
24875 		    || ', '
24876 		    || per_addr.address_line3
24877 		    || ', '
24878 		    || per_addr.town_or_city
24879 		    || ', '
24880 		    || DECODE(
24881 			 per_addr.style,
24882 			 'CA',     '',
24883 			 'CA_GLB', '',
24884 			 NVL(per_addr.region_2, '')
24885 			 )
24886 		    || ', '
24887 		    || per_addr.country
24888 		    || ', '
24889 		    || per_addr.postal_code) add_concat
24890 
24891 	  FROM
24892 	      /* Employee address related */
24893 	      PER_ADDRESSES            per_addr
24894 	  WHERE
24895 	    IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index)         = per_addr.person_id
24896 	    AND per_addr.primary_flag = 'Y'
24897 	    AND SYSDATE BETWEEN per_addr.date_from AND NVL(per_addr.date_to, SYSDATE+1);
24898 	    /*END OF HOME ADDRESS*/
24899 
24900 	  CURSOR c_emp_other_addr(l_trx_index BINARY_INTEGER) IS
24901 
24902 	       SELECT
24903 
24904 	      /* payee add line1 */
24905 		  --address code not specified
24906 		  DECODE (per_addr.address_id,
24907 			 NULL, per_loc.address_line_1,
24908 			 per_addr.address_line1)
24909 		 add_line1,
24910 
24911 	      /* payee add line2 */
24912 		  --address code not specified
24913 		  DECODE (per_addr.address_id,
24914 			 NULL, per_loc.address_line_2,
24915 			 per_addr.address_line2)
24916 		 add_line2,
24917 
24918 	      /* payee add line3 */
24919 		  --address code not specified
24920 		  DECODE (per_addr.address_id,
24921 			 NULL, per_loc.address_line_3,
24922 			 per_addr.address_line3)
24923 		 add_line3,
24924 
24925 
24926 	      /* payee add line4 */
24927 		null
24928 		 add_line4,
24929 
24930 	      /* payee city */
24931 		  -- address code not specified
24932 		  DECODE (per_addr.address_id,
24933 			 NULL, per_loc.town_or_city,
24934 			 per_addr.town_or_city)
24935 		 city,
24936 
24937 
24938 	      /* payee county */
24939 		(
24940 		    --address code not specified
24941 		    decode(per_addr.address_id,
24942 		    NULL,DECODE(
24943 		    per_loc.style,
24944 		    'US',      NVL(per_loc.region_1,   ''),
24945 		    'US_GLB',  NVL(per_loc.region_1,   ''),
24946 		    'IE',      NVL(ap_web_db_expline_pkg.
24947 				       getcountyprovince(
24948 					   per_loc.style,
24949 					   per_loc.region_1),
24950 				 ''),
24951 		    'IE_GLB',  NVL(ap_web_db_expline_pkg.
24952 				       getcountyprovince(
24953 					   per_loc.style,
24954 					   per_loc.region_1),
24955 				 ''),
24956 		    'GB',      NVL(ap_web_db_expline_pkg.
24957 				       getcountyprovince(
24958 					   per_loc.style,
24959 					   per_loc.region_1),
24960 				 ''),
24961 		    ''),
24962 		     DECODE(
24963 		    per_addr.style,
24964 		    'US',     NVL(per_addr.region_1,   ''),
24965 		    'US_GLB', NVL(per_addr.region_1,   ''),
24966 		    'IE',     NVL(ap_web_db_expline_pkg.
24967 				      getcountyprovince(
24968 					  per_addr.style,
24969 					  per_addr.region_1),
24970 				''),
24971 		    'IE_GLB', NVL(ap_web_db_expline_pkg.
24972 				      getcountyprovince(
24973 					  per_addr.style,
24974 					  per_addr.region_1),
24975 				''),
24976 		    'GB',     NVL(ap_web_db_expline_pkg.
24977 				      getcountyprovince(
24978 					  per_addr.style,
24979 					  per_addr.region_1),
24980 				''),
24981 		    ''))
24982 		  )
24983 		 county,
24984 
24985 	      /* payee province */
24986 		(
24987 		    --address code not specified
24988 		    decode(per_addr.address_id,
24989 		    NULL,DECODE(per_loc.style,
24990 		    'US',      '',
24991 		    'US_GLB',  '',
24992 		    'IE',      '',
24993 		    'IE_GLB',  '',
24994 		    'GB',      '',
24995 		    'CA',      NVL(per_loc.region_1,   ''),
24996 		    'CA_GLB',  NVL(per_loc.region_1,   ''),
24997 		    'JP',      NVL(per_loc.region_1,   ''),
24998 		    NVL(ap_web_db_expline_pkg.
24999 			    getcountyprovince(
25000 				per_loc.style,
25001 				per_loc.region_1),
25002 		      '')
25003 		      ),
25004 		     DECODE(per_addr.style,
25005 		    'US',      '',
25006 		    'US_GLB',  '',
25007 		    'IE',      '',
25008 		    'IE_GLB',  '',
25009 		    'GB',      '',
25010 		    'CA',      NVL(per_addr.region_1,   ''),
25011 		    'CA_GLB',  NVL(per_addr.region_1,   ''),
25012 		    'JP',      NVL(per_addr.region_1,   ''),
25013 		    NVL(ap_web_db_expline_pkg.
25014 			    getcountyprovince(
25015 				per_addr.style,
25016 				per_addr.region_1),
25017 		      '')
25018 		    ))
25019 		  )
25020 		 province,
25021 
25022 	      /* payee state */
25023 		 (
25024 		   --address code not specified
25025 		   decode(per_addr.address_id,
25026 		   NULL,DECODE(per_loc.style,
25027 		     'CA',     '',
25028 		     'CA_GLB', '',
25029 		      NVL(per_loc.region_2, '')),
25030 		    DECODE(per_addr.style,
25031 		     'CA',     '',
25032 		     'CA_GLB', '',
25033 		      NVL(per_addr.region_2,   '')))
25034 		 )
25035 	        state,
25036 
25037 	     /* payee country */
25038 		(
25039 		  --address code not specified
25040 		  DECODE (per_addr.address_id,
25041 		       NULL, per_loc.country,
25042 		       per_addr.country
25043 		       )
25044 		)
25045 		 country,
25046 
25047 	      /* payee postal code */
25048 		(
25049 		  --address code not specified
25050 		  DECODE (per_addr.address_id,
25051 		       NULL, per_loc.postal_code,
25052 		       per_addr.postal_code
25053 		       )
25054 		)
25055 		 postal_code,
25056 
25057 
25058 	      /* payee address concat */
25059 		(
25060 		  -- address code not specified
25061 		  DECODE (per_addr.address_id,
25062 		       NULL, per_loc.address_line_1
25063 		    || ', '
25064 		    || per_loc.address_line_2
25065 		    || ', '
25066 		    || per_loc.address_line_3
25067 		    || ', '
25068 		    || per_loc.town_or_city
25069 		    || ', '
25070 		    || DECODE(
25071 			 per_loc.style,
25072 			 'CA',     '',
25073 			 'CA_GLB', '',
25074 			 NVL(per_loc.region_2, '')
25075 			 )
25076 		    || ', '
25077 		    || per_loc.country
25078 		    || ', '
25079 		    || per_loc.postal_code,
25080 
25081 		      per_addr.address_line1
25082 		    || ', '
25083 		    || per_addr.address_line2
25084 		    || ', '
25085 		    || per_addr.address_line3
25086 		    || ', '
25087 		    || per_addr.town_or_city
25088 		    || ', '
25089 		    || DECODE(
25090 			 per_addr.style,
25091 			 'CA',     '',
25092 			 'CA_GLB', '',
25093 			 NVL(per_addr.region_2, '')
25094 			 )
25095 		    || ', '
25096 		    || per_addr.country
25097 		    || ', '
25098 		    || per_addr.postal_code)
25099 		)
25100 	       add_concat
25101 
25102 	  FROM
25103 	      HR_LOCATIONS             per_loc,
25104 	      PER_ADDRESSES            per_addr,
25105 	      PER_ALL_ASSIGNMENTS_F    per_assgn
25106 
25107 	  WHERE
25108 	    IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index)         = per_addr.person_id(+)
25109 	    AND per_addr.primary_flag(+) = 'Y'
25110 	    AND SYSDATE BETWEEN
25111 		    per_addr.date_from(+)
25112 		    AND NVL(per_addr.date_to(+), SYSDATE+1)
25113 	    AND IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index)         = per_assgn.person_id(+)
25114 	    AND per_assgn.location_id          = per_loc.location_id(+)
25115 	    AND per_assgn.primary_flag(+)      = 'Y'
25116 	    AND per_assgn.assignment_type(+) = 'E'
25117 	    AND (TRUNC(SYSDATE) BETWEEN
25118 		    per_assgn.effective_start_date(+)
25119 		    AND per_assgn.effective_end_date(+)
25120 		)
25121 	  ;
25122 
25123         CURSOR c_supplier_addr(l_trx_index BINARY_INTEGER) IS
25124 
25125 	   SELECT
25126 
25127 	       ( payee_loc.address1
25128 
25129 		) add_line1,
25130 
25131 	      /* payee add line2 */
25132 	       ( payee_loc.address2
25133 		) add_line2,
25134 
25135 
25136 	      /* payee add line3 */
25137 		(payee_loc.address3
25138 		) add_line3,
25139 
25140 
25141 	      /* payee add line4 */
25142                 (payee_loc.address4
25143 		) add_line4,
25144 
25145 	      /* payee city */
25146 	       ( payee_loc.city
25147 
25148 		) city,
25149 
25150 
25151 	      /* payee county */
25152 	       ( payee_loc.county
25153 		) county,
25154 
25155 	      /* payee province */
25156 		(payee_loc.province
25157 		) province,
25158 
25159 	      /* payee state */
25160 		( payee_loc.state
25161 
25162 		 ) state,
25163 
25164 	     /* payee country */
25165 		(payee_loc.country
25166 
25167 			) country,
25168 
25169 	      /* payee postal code */
25170 		( payee_loc.postal_code
25171 
25172 			) postal_code,
25173 
25174 
25175 	      /* payee address concat */
25176 	     (
25177 		payee_loc.address1
25178 		  || ', '
25179 		  || payee_loc.address2
25180 		  || ', '
25181 		  || payee_loc.address3
25182 		  || ', '
25183 		  || payee_loc.city
25184 		  || ', '
25185 		  || payee_loc.state
25186 		  || ', '
25187 		  || payee_loc.country
25188 		  || ', '
25189 		  || payee_loc.postal_code
25190 
25191 		) add_concat
25192 
25193 	  FROM
25194 	      HZ_LOCATIONS             payee_loc
25195 	  WHERE
25196 	    IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(l_trx_index)       = payee_loc.location_id(+)
25197 	  ;
25198 
25199 
25200 
25201 
25202  BEGIN
25203 
25204      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25205      print_debuginfo(l_module_name, 'ENTER');
25206      print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_index) -'||IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_paye_adr_index));
25207      print_debuginfo(l_module_name, 'IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(l_trx_index) -'||IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(l_trx_paye_adr_index));
25208      END IF;
25209 
25210      l_payee_adr_index := Nvl(IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_paye_adr_index), -999) || '$'|| Nvl(IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(l_trx_paye_adr_index), -999);
25211 
25212      /*  Bug 12341563: EMPLOYEE PAYMENTS DEFAULTING TO 'HOME' PAYSITE
25213         FOr Employee suppliers, person id (not null) and remit to location (null) is same
25214 	for both the home and office address,
25215 	So identify them, caching index is appended with supplier site id.
25216      */
25217 
25218      l_payee_adr_index := l_payee_adr_index || '$'|| Nvl(IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_paye_adr_index), -999);
25219 
25220      /*  Bug 12341563: END */
25221      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25222      print_debuginfo(l_module_name, 'l_payee_adr_index -'|| l_payee_adr_index);
25223      END IF;
25224 
25225     IF (l_payee_addr_tbl.EXISTS(l_payee_adr_index)) THEN
25226 
25227 	IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index) := l_payee_addr_tbl(l_payee_adr_index).payee_address1;
25228 	IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_address2;
25229 	IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_address3;
25230 	IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_address4;
25231 	IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_city;
25232 	IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_county;
25233 	IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_province;
25234 	IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_state;
25235 	IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_country;
25236 	IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index):= l_payee_addr_tbl(l_payee_adr_index).payee_postal_code;
25237 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index) := l_payee_addr_tbl(l_payee_adr_index).payee_address_concat;
25238     ELSE
25239 
25240       IF(IBY_PAYGROUP_PUB.pmtTable.address_source(l_trx_paye_adr_index) = 'TCA') THEN
25241       OPEN  c_supplier_addr(l_trx_paye_adr_index);
25242 
25243       FETCH c_supplier_addr INTO
25244 	IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index),
25245 	IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index),
25246 	IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index),
25247 	IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index),
25248 	IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index),
25249 	IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index),
25250 	IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index),
25251 	IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index),
25252 	IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index),
25253 	IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index),
25254 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index)
25255 	;
25256      CLOSE c_supplier_addr;
25257 
25258       ELSE
25259          IF (IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_paye_adr_index) = 'HOME')
25260 	 THEN
25261 	   OPEN  c_emp_home_addr(l_trx_paye_adr_index);
25262            FETCH c_emp_home_addr INTO
25263 	   IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index),
25264 	   IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index),
25265 	   IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index),
25266 	   IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index),
25267 	   IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index),
25268 	   IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index),
25269 	   IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index),
25270 	   IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index),
25271 	   IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index),
25272 	   IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index),
25273 	   IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index);
25274            CLOSE c_emp_home_addr;
25275 
25276 	   ELSIF (IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_paye_adr_index) = 'OFFICE')
25277            THEN
25278            OPEN  c_emp_offc_addr(l_trx_paye_adr_index);
25279 
25280            FETCH c_emp_offc_addr INTO
25281 	   IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index),
25282 	   IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index),
25283 	   IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index),
25284 	   IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index),
25285 	   IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index),
25286 	   IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index),
25287 	   IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index),
25288 	   IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index),
25289 	   IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index),
25290 	   IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index),
25291 	   IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index);
25292            CLOSE c_emp_offc_addr;
25293 
25294           ELSIF (IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_paye_adr_index) = 'PROVISIONAL')
25295            THEN
25296            OPEN  c_emp_provs_addr(l_trx_paye_adr_index);
25297            FETCH c_emp_provs_addr INTO
25298 	   IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index),
25299 	   IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index),
25300 	   IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index),
25301 	   IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index),
25302 	   IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index),
25303 	   IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index),
25304 	   IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index),
25305 	   IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index),
25306 	   IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index),
25307 	   IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index),
25308 	   IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index);
25309            CLOSE c_emp_provs_addr;
25310 		   else
25311 		   OPEN  c_emp_other_addr(l_trx_paye_adr_index);
25312            FETCH c_emp_other_addr INTO
25313 	   IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index),
25314 	   IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index),
25315 	   IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index),
25316 	   IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index),
25317 	   IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index),
25318 	   IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index),
25319 	   IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index),
25320 	   IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index),
25321 	   IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index),
25322 	   IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index),
25323 	   IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index);
25324            CLOSE c_emp_other_addr;
25325 
25326          END IF ;
25327 
25328 
25329       END IF;
25330 
25331  l_payee_addr_tbl(l_payee_adr_index).payee_address1 :=	IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_paye_adr_index);
25332  l_payee_addr_tbl(l_payee_adr_index).payee_address2 :=	IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_paye_adr_index);
25333  l_payee_addr_tbl(l_payee_adr_index).payee_address3 :=	IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_paye_adr_index);
25334  l_payee_addr_tbl(l_payee_adr_index).payee_address4 :=	IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_paye_adr_index);
25335  l_payee_addr_tbl(l_payee_adr_index).payee_city     :=	IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_paye_adr_index);
25336  l_payee_addr_tbl(l_payee_adr_index).payee_county :=	IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_paye_adr_index);
25337  l_payee_addr_tbl(l_payee_adr_index).payee_province :=	IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_paye_adr_index);
25338 l_payee_addr_tbl(l_payee_adr_index).payee_state :=	IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_paye_adr_index);
25339  l_payee_addr_tbl(l_payee_adr_index).payee_country :=	IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_paye_adr_index);
25340  l_payee_addr_tbl(l_payee_adr_index).payee_postal_code :=	IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_paye_adr_index);
25341  l_payee_addr_tbl(l_payee_adr_index).payee_address_concat :=	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_paye_adr_index);
25342 
25343  END IF;
25344      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25345      print_debuginfo(l_module_name, 'EXIT');
25346      END IF;
25347 
25348  END GET_PAYEE_ADDR_INFO;
25349 
25350 
25351  /*--------------------------------------------------------------------
25352  | NAME:
25353  |     GET_PAYEE_BANK_INFO
25354  |
25355  | PURPOSE:
25356  |
25357  |
25358  |
25359  | PARAMETERS:
25360  |     IN
25361  |
25362  |
25363  |     OUT
25364  |
25365  |
25366  | RETURNS:
25367  |
25368  | NOTES:
25369  |
25370  |
25371  |
25372  *---------------------------------------------------------------------*/
25373  PROCEDURE GET_PAYEE_BANK_INFO(
25374 	l_trx_payee_bnk_index      IN BINARY_INTEGER
25375      )
25376  IS
25377  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
25378                                                   '.GET_PAYEE_BANK_INFO';
25379 
25380 l_payee_bnk_index BINARY_INTEGER;
25381 	  -- Cursor obsoleted to deal with performance bug 11696582
25382 	  CURSOR c_payee_bank_info_obsolete(l_trx_index BINARY_INTEGER) IS
25383 
25384 	  SELECT
25385 	  eba.bank_name,                       -- payee bank name
25386 	  eba.bank_number,                     -- payee bank number
25387 	  eba.branch_number,                   -- payee bank branch number
25388 	  eba.bank_branch_name,                -- payee bank branch name
25389 
25390 	  /*
25391 	   * Fix for bug 5586882:
25392 	   *
25393 	   * Populate the external bank account using
25394 	   * IBY_EXT_BANK_ACCOUNTS.bank_account_num
25395 	   * so that we show the unmasked bank account number
25396 	   */
25397 	  ext_ba_table.bank_account_num,       -- payee bank account number
25398 
25399 	  eba.bank_account_name,               -- payee bank account name    -- 60
25400 	  eba.iban_number,                     -- payee bank account IBAN
25401 	  eba.eft_swift_code,                  -- payee bank swift code
25402 	  eba.bank_account_type,               -- payee bank account type
25403 	  eba.payment_factor_flag,             -- payee bank payment factor flag
25404 	  eba.primary_acct_owner_party_id,     -- payee bank owner party id
25405 	  eba.branch_party_id,                 -- payee bank branch party id
25406 	  eba_bank_branch.bank_name_alt,       -- payee bank name alt
25407 	  eba_bank_branch.bank_branch_name_alt,-- payee bank branch name alt
25408 	  eba.alternate_account_name,          -- payee bank alt account name
25409 	  eba.bank_account_num_electronic,     -- payee bank electronic acct num -- 70
25410 	  eba.bank_branch_address_id,          -- payee bank branch location id
25411 	  eba.primary_acct_owner_name          -- payee bank primary acct owner name
25412 
25413 	  FROM
25414 	  /* Payee bank */
25415 	  IBY_EXT_BANK_ACCOUNTS_V  eba,
25416 	  IBY_EXT_BANK_ACCOUNTS    ext_ba_table,
25417 	  CE_BANK_BRANCHES_V       eba_bank_branch
25418 
25419 	  WHERE
25420 	  /* payee bank */
25421 	  IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_index) = eba.ext_bank_account_id(+)
25422 	  AND eba.bank_party_id						  = eba_bank_branch.bank_party_id(+)
25423 	  AND eba.branch_party_id					  = eba_bank_branch.branch_party_id(+)
25424 	  AND ext_ba_table.ext_bank_account_id(+)			  = eba.ext_bank_account_id
25425 	  ;
25426 
25427 	  -- Cursor replaced to deal with performance bug 11696582
25428 	  CURSOR c_payee_bank_info(l_trx_index BINARY_INTEGER) IS
25429 		SELECT EBA_BANK_BRANCH.BANK_NAME ,
25430 		   EBA_BANK_BRANCH.BANK_NUMBER ,
25431 		   EBA_BANK_BRANCH.BRANCH_NUMBER ,
25432 		   EBA_BANK_BRANCH.BANK_BRANCH_NAME ,
25433 		   EBA.BANK_ACCOUNT_NUM ,
25434 		   EBA.BANK_ACCOUNT_NAME ,
25435 		   EBA.IBAN IBAN_NUMBER,
25436 		   EBA_BANK_BRANCH.EFT_SWIFT_CODE,
25437 		   EBA.BANK_ACCOUNT_TYPE,
25438 		   EBA.PAYMENT_FACTOR_FLAG,
25439 		   ow.account_owner_party_id PRIMARY_ACCT_OWNER_PARTY_ID,
25440 		   EBA.BRANCH_ID BRANCH_PARTY_ID,
25441 		   EBA_BANK_BRANCH.BANK_NAME_ALT,
25442 		   EBA_BANK_BRANCH.BANK_BRANCH_NAME_ALT,
25443 		   EBA.BANK_ACCOUNT_NAME_ALT ALTERNATE_ACCOUNT_NAME,
25444 		   EBA.BANK_ACCOUNT_NUM_ELECTRONIC,
25445 		   hzps.LOCATION_ID BANK_BRANCH_ADDRESS_ID,
25446 		   hzp.party_name PRIMARY_ACCT_OWNER_NAME
25447 		 FROM IBY_EXT_BANK_ACCOUNTS EBA,
25448 		   CE_BANK_BRANCHES_V EBA_BANK_BRANCH,
25449 		   IBY_ACCOUNT_OWNERS OW,
25450 		   HZ_PARTIES hzp,
25451 		   HZ_PARTY_SITES hzps
25452 		 WHERE IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_index)			     = EBA.EXT_BANK_ACCOUNT_ID(+)
25453 		 AND EBA.BANK_ID 		     = EBA_BANK_BRANCH.BANK_PARTY_ID(+)
25454 		 AND EBA.BRANCH_ID		     = EBA_BANK_BRANCH.BRANCH_PARTY_ID(+)
25455 		 AND eba.ext_bank_account_id	     = ow.ext_bank_account_id(+)
25456 		 AND ow.account_owner_party_id	     = hzp.party_id(+)
25457 		 AND ow.primary_flag(+)		     = 'Y'
25458 		 AND NVL(ow.end_date,SYSDATE+10)      >SYSDATE
25459 		 AND EBA.BRANCH_ID		     = hzps.party_id(+)
25460 		 AND hzps.identifying_address_flag(+) = 'Y';
25461 
25462 
25463  BEGIN
25464 
25465      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25466      print_debuginfo(l_module_name, 'ENTER');
25467      print_debuginfo(l_module_name, 'Inside get_payee_bank info -IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_index) '|| IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_payee_bnk_index) );
25468      END IF;
25469      l_payee_bnk_index := Nvl(IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_payee_bnk_index),-999);
25470      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25471      print_debuginfo(l_module_name, 'l_payee_bnk_index -'||l_payee_bnk_index );
25472      END IF;
25473 
25474 
25475      IF (l_payee_acct_tbl.EXISTS(l_payee_bnk_index)) THEN
25476 
25477      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25478      print_debuginfo(l_module_name, 'The data already exists' );
25479      END IF;
25480      IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(l_trx_payee_bnk_index) := l_payee_acct_tbl(l_payee_bnk_index).ext_bank_name;
25481 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_number;
25482 	IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_branch_number;
25483 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_name;
25484 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_number;
25485 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_name;
25486 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(l_trx_payee_bnk_index)   	:= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_iban_number;
25487 	IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(l_trx_payee_bnk_index) := l_payee_acct_tbl(l_payee_bnk_index).ext_eft_swift_code;
25488 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_type;
25489 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_acct_pmt_factor_flag;
25490 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_acct_owner_party_id;
25491 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_party_id;
25492 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(l_trx_payee_bnk_index) := l_payee_acct_tbl(l_payee_bnk_index).ext_bank_alt_name;
25493 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(l_trx_payee_bnk_index) := l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_alt_name;
25494 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_alt_name;
25495 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(l_trx_payee_bnk_index)  := l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_num_elec;
25496 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_location_id;
25497 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(l_trx_payee_bnk_index):= l_payee_acct_tbl(l_payee_bnk_index).ext_bank_acct_owner_party_name;
25498 
25499      ELSE
25500     IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25501     print_debuginfo(l_module_name, 'The data doesnt exist, querying the DB' );
25502     END IF;
25503       OPEN  c_payee_bank_info(l_trx_payee_bnk_index);
25504       FETCH c_payee_bank_info INTO
25505 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(l_trx_payee_bnk_index),
25506 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(l_trx_payee_bnk_index),
25507 		IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(l_trx_payee_bnk_index),
25508 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(l_trx_payee_bnk_index),
25509 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_payee_bnk_index)        	,
25510 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(l_trx_payee_bnk_index)          	,
25511 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(l_trx_payee_bnk_index)   	,
25512 		IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(l_trx_payee_bnk_index)             	,
25513 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(l_trx_payee_bnk_index)          	,
25514 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(l_trx_payee_bnk_index)  	,
25515 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(l_trx_payee_bnk_index)   	,
25516 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(l_trx_payee_bnk_index)       	,
25517 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(l_trx_payee_bnk_index)              	,
25518 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(l_trx_payee_bnk_index)       	,
25519 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(l_trx_payee_bnk_index)      	,
25520 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(l_trx_payee_bnk_index)      	,
25521 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(l_trx_payee_bnk_index)    	,
25522 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(l_trx_payee_bnk_index)
25523 	;
25524       IF (c_payee_bank_info%NOTFOUND =TRUE) THEN
25525 
25526       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25527       print_debuginfo(l_module_name, 'DB hit did not fetch data, initializing to null');
25528       END IF;
25529       		IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(l_trx_payee_bnk_index) := NULL;
25530 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(l_trx_payee_bnk_index) := NULL;
25531 		IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(l_trx_payee_bnk_index) := NULL;
25532 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(l_trx_payee_bnk_index) := NULL;
25533 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_payee_bnk_index):= NULL;
25534 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(l_trx_payee_bnk_index):= NULL;
25535 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(l_trx_payee_bnk_index):= NULL;
25536 		IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(l_trx_payee_bnk_index):= NULL;
25537 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(l_trx_payee_bnk_index):= NULL;
25538 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(l_trx_payee_bnk_index):= NULL;
25539 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(l_trx_payee_bnk_index):= NULL;
25540 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(l_trx_payee_bnk_index):= NULL;
25541 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(l_trx_payee_bnk_index):= NULL;
25542 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(l_trx_payee_bnk_index):= NULL;
25543 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(l_trx_payee_bnk_index):= NULL;
25544 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(l_trx_payee_bnk_index):= NULL;
25545 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(l_trx_payee_bnk_index):= NULL;
25546 		IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(l_trx_payee_bnk_index):= NULL;
25547 
25548       END IF;
25549   IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25550   print_debuginfo(l_module_name, 'Before putting the data to cache' );
25551   END IF;
25552 
25553  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_name :=        IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(l_trx_payee_bnk_index);
25554  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_number :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(l_trx_payee_bnk_index);
25555  l_payee_acct_tbl(l_payee_bnk_index).ext_branch_number :=	IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(l_trx_payee_bnk_index);
25556  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_name :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(l_trx_payee_bnk_index);
25557  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_number :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_payee_bnk_index);
25558  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_name :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(l_trx_payee_bnk_index);
25559  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_iban_number :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(l_trx_payee_bnk_index);
25560  l_payee_acct_tbl(l_payee_bnk_index).ext_eft_swift_code :=	IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(l_trx_payee_bnk_index);
25561  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_type :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(l_trx_payee_bnk_index);
25562  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_acct_pmt_factor_flag :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(l_trx_payee_bnk_index);
25563  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_acct_owner_party_id :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(l_trx_payee_bnk_index);
25564  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_party_id :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(l_trx_payee_bnk_index);
25565  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_alt_name :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(l_trx_payee_bnk_index);
25566  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_alt_name :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(l_trx_payee_bnk_index);
25567  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_alt_name :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(l_trx_payee_bnk_index);
25568  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_account_num_elec :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(l_trx_payee_bnk_index);
25569  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_branch_location_id :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(l_trx_payee_bnk_index);
25570  l_payee_acct_tbl(l_payee_bnk_index).ext_bank_acct_owner_party_name :=	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(l_trx_payee_bnk_index);
25571 
25572       CLOSE c_payee_bank_info;
25573 
25574    END IF;
25575      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25576      print_debuginfo(l_module_name, 'Inside get_payee_bank info -IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_index) '|| IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_payee_bnk_index) );
25577 --     print_debuginfo(l_module_name, 'Inside get_payee_bank info -IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_payee_bnk_index)'||IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_payee_bnk_index));
25578      print_debuginfo(l_module_name, 'EXIT');
25579      END IF;
25580 
25581  END GET_PAYEE_BANK_INFO;
25582 
25583 
25584 
25585   /*--------------------------------------------------------------------
25586  | NAME:
25587  |     GET_REMITTANCE_INFO
25588  |
25589  | PURPOSE:
25590  |
25591  |
25592  |
25593  | PARAMETERS:
25594  |     IN
25595  |
25596  |
25597  |     OUT
25598  |
25599  |
25600  | RETURNS:
25601  |
25602  | NOTES:
25603  |
25604  |
25605  |
25606  *---------------------------------------------------------------------*/
25607  PROCEDURE GET_REMITTANCE_INFO(
25608 	l_trx_acct_index      IN BINARY_INTEGER
25609      )
25610  IS
25611  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
25612                                                   '.GET_REMITTANCE_INFO';
25613  l_remit_index BINARY_INTEGER;
25614 
25615 	  CURSOR c_remit_info(l_trx_index BINARY_INTEGER) IS
25616 
25617 	  SELECT
25618 
25619 	    /* REMITTANCE ADVICE RELATED */
25620 	   remit_advice.remit_advice_delivery_method,  -- remittance advice delv method
25621 	   '',                                  -- remittance advice email
25622 	   '',
25623 	     /* DECLARATION REPORT RELATED */
25624 	    prof.declaration_curr_fx_rate_type,
25625 	    '',                                  -- declaration format
25626 
25627 	  /* BANK INSTRUCTION */
25628 	  bank_instr1.format_value,
25629 	  bank_instr2.format_value,
25630 
25631 	   /* PROFILE RELATED */
25632 	  prof.payment_profile_name,           -- account profile name       -- 80
25633 	  prof.system_profile_name            -- system profile name
25634 
25635 
25636 
25637 	  FROM
25638 	   /* Profile related */
25639 	  IBY_PAYMENT_PROFILES     prof,
25640 	   /* Remit advice related */
25641 	  IBY_REMIT_ADVICE_SETUP   remit_advice,
25642 	   /* Bank instruction related */
25643 	  IBY_BANK_INSTRUCTIONS_VL bank_instr1,
25644 	  IBY_BANK_INSTRUCTIONS_VL bank_instr2
25645 
25646 	  WHERE
25647 	    /* profile and remit advice */
25648 	    IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_index) = prof.payment_profile_id
25649 	    AND prof.system_profile_code       = remit_advice.system_profile_code
25650 	    /* bank instruction */
25651 	    AND prof.bank_instruction1_code    = bank_instr1.bank_instruction_code(+)
25652 	    AND prof.bank_instruction2_code    = bank_instr2.bank_instruction_code(+);
25653 
25654 
25655 
25656 
25657  BEGIN
25658 
25659      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25660      print_debuginfo(l_module_name, 'ENTER');
25661      END IF;
25662 
25663      l_remit_index := IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_acct_index);
25664 
25665      IF (l_remit_tbl.EXISTS(l_remit_index)) THEN
25666 
25667 
25668 	IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(l_trx_acct_index)    := l_remit_tbl(l_remit_index).remit_advice_delivery_method;
25669 	IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(l_trx_acct_index)              :=	l_remit_tbl(l_remit_index).remit_advice_email;
25670 	IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(l_trx_acct_index)                :=	l_remit_tbl(l_remit_index).remit_advice_fax;
25671 
25672 	IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(l_trx_acct_index)     :=	l_remit_tbl(l_remit_index).declaration_exch_rate_type;
25673 	IBY_PAYGROUP_PUB.pmtTable.declaration_format(l_trx_acct_index)             :=	l_remit_tbl(l_remit_index).declaration_format;
25674 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(l_trx_acct_index) :=	l_remit_tbl(l_remit_index).bank_instruction1_format_value;
25675 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(l_trx_acct_index) :=	l_remit_tbl(l_remit_index).bank_instruction2_format_value;
25676 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(l_trx_acct_index)      :=	l_remit_tbl(l_remit_index).payment_profile_acct_name;
25677 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(l_trx_acct_index)	   :=l_remit_tbl(l_remit_index).payment_profile_sys_name;
25678 
25679      ELSE
25680       OPEN  c_remit_info(l_trx_acct_index);
25681       FETCH c_remit_info INTO
25682 		IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(l_trx_acct_index)   	,
25683 		IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(l_trx_acct_index)             	,
25684 		IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(l_trx_acct_index)               	,
25685 --		IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_acct_index)  	,
25686 		IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(l_trx_acct_index)     	,
25687 		IBY_PAYGROUP_PUB.pmtTable.declaration_format (l_trx_acct_index)            	,
25688 		IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(l_trx_acct_index) 	,
25689 		IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(l_trx_acct_index) 	,
25690 		IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(l_trx_acct_index)      	,
25691 		IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(l_trx_acct_index)
25692 
25693 	;
25694 
25695       IF (c_remit_info%NOTFOUND = TRUE) THEN
25696         IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(l_trx_acct_index)  :=NULL;
25697 		IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(l_trx_acct_index)             		:=NULL;
25698 		IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(l_trx_acct_index)               		:=NULL;
25699 --		IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_acct_index)  	,
25700 		IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(l_trx_acct_index)     		:=NULL;
25701 		IBY_PAYGROUP_PUB.pmtTable.declaration_format (l_trx_acct_index)            		:=NULL;
25702 		IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(l_trx_acct_index) 		:=NULL;
25703 		IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(l_trx_acct_index) 		:=NULL;
25704 		IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(l_trx_acct_index)      		:=NULL;
25705 		IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(l_trx_acct_index)          :=NULL;
25706 
25707 
25708       END IF;
25709 
25710       CLOSE c_remit_info;
25711 
25712 
25713         l_remit_tbl(l_remit_index).remit_advice_delivery_method :=      	IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(l_trx_acct_index)  ;
25714 	l_remit_tbl(l_remit_index).remit_advice_email := IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(l_trx_acct_index);
25715         l_remit_tbl(l_remit_index).remit_advice_fax :=	IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(l_trx_acct_index);
25716 
25717 	l_remit_tbl(l_remit_index).declaration_exch_rate_type :=	IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(l_trx_acct_index);
25718 	l_remit_tbl(l_remit_index).declaration_format :=	IBY_PAYGROUP_PUB.pmtTable.declaration_format(l_trx_acct_index);
25719 	l_remit_tbl(l_remit_index).bank_instruction1_format_value :=	IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(l_trx_acct_index);
25720 	l_remit_tbl(l_remit_index).bank_instruction2_format_value :=	IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(l_trx_acct_index);
25721 	l_remit_tbl(l_remit_index).payment_profile_acct_name :=	IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(l_trx_acct_index);
25722         l_remit_tbl(l_remit_index).payment_profile_sys_name :=	IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(l_trx_acct_index);
25723 
25724 
25725     END IF;
25726 
25727      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25728      print_debuginfo(l_module_name, 'EXIT');
25729      END IF;
25730 
25731  END GET_REMITTANCE_INFO;
25732 
25733 
25734    /*--------------------------------------------------------------------
25735  | NAME:
25736  |     GET_PPR_INFO
25737  |
25738  | PURPOSE:
25739  |
25740  |
25741  |
25742  | PARAMETERS:
25743  |     IN
25744  |
25745  |
25746  |     OUT
25747  |
25748  |
25749  | RETURNS:
25750  |
25751  | NOTES:
25752  |
25753  |
25754  |
25755  *---------------------------------------------------------------------*/
25756  PROCEDURE GET_PPR_INFO(
25757 	l_trx_ppr_index      IN BINARY_INTEGER
25758      )
25759  IS
25760  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
25761                                                   '.GET_PPR_INFO';
25762  l_ppr_index BINARY_INTEGER;
25763 
25764 	  CURSOR c_ppr_info(l_trx_index BINARY_INTEGER) IS
25765 
25766 	 SELECT
25767 	  /* REQUEST */
25768 	  payreq.call_app_pay_service_req_code,-- ppr name
25769 	  fnd_app.application_name             -- source product            -- 88
25770 	  FROM
25771 	   /* Payment service request related */
25772 	  IBY_PAY_SERVICE_REQUESTS payreq,
25773 	  FND_APPLICATION_ALL_VIEW fnd_app
25774 
25775 	  WHERE
25776 
25777 	    /* payment service request related */
25778 	  payreq.payment_service_request_id  = IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(l_trx_index)
25779 	  AND fnd_app.application_id         = payreq.calling_app_id
25780 	  ;
25781 
25782 
25783 
25784  BEGIN
25785 
25786      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25787      print_debuginfo(l_module_name, 'ENTER');
25788      END IF;
25789 
25790 	l_ppr_index :=IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(l_trx_ppr_index);
25791 
25792      IF (l_ppr_tbl.EXISTS(l_ppr_index)) THEN
25793      	IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(l_trx_ppr_index) := l_ppr_tbl(l_ppr_index).payment_process_request_name;
25794 	IBY_PAYGROUP_PUB.pmtTable.source_product(l_trx_ppr_index)               := l_ppr_tbl(l_ppr_index).source_product;
25795 
25796      ELSE
25797 
25798       OPEN  c_ppr_info(l_trx_ppr_index);
25799       FETCH c_ppr_info INTO
25800 		IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(l_trx_ppr_index),
25801 		IBY_PAYGROUP_PUB.pmtTable.source_product(l_trx_ppr_index)
25802 
25803 	;
25804       CLOSE c_ppr_info;
25805 
25806       l_ppr_tbl(l_ppr_index).payment_process_request_name :=     	IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(l_trx_ppr_index);
25807       l_ppr_tbl(l_ppr_index).source_product   :=	IBY_PAYGROUP_PUB.pmtTable.source_product(l_trx_ppr_index);
25808 
25809 
25810      END IF;
25811      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25812      print_debuginfo(l_module_name, 'EXIT');
25813      END IF;
25814 
25815  END GET_PPR_INFO;
25816 
25817 
25818 
25819   /*--------------------------------------------------------------------
25820  | NAME:
25821  |     GET_DELIVERY_INFO
25822  |
25823  | PURPOSE:
25824  |
25825  |
25826  |
25827  | PARAMETERS:
25828  |     IN
25829  |
25830  |
25831  |     OUT
25832  |
25833  |
25834  | RETURNS:
25835  |
25836  | NOTES:
25837  |
25838  |
25839  |
25840  *---------------------------------------------------------------------*/
25841  PROCEDURE GET_DELIVERY_INFO(
25842 	l_trx_delv_index      IN BINARY_INTEGER
25843      )
25844  IS
25845  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
25846                                                   '.GET_DELIVERY_INFO';
25847  l_del_index	 VARCHAR2(300);
25848 
25849 	  CURSOR c_deliv_info(l_trx_index BINARY_INTEGER) IS
25850 
25851 	 SELECT
25852 	  /* DELIVERY CHANNEL RELATED */
25853 	  deliv.format_value
25854 
25855 	  FROM
25856 
25857 	  /* Delivery channel related */
25858 	  IBY_DELIVERY_CHANNELS_VL deliv
25859 
25860 	  WHERE
25861 	  /* delivery channel related */
25862 	  IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_index) = deliv.delivery_channel_code(+)
25863 	  ;
25864 
25865 
25866 
25867  BEGIN
25868 
25869      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25870      print_debuginfo(l_module_name, 'ENTER');
25871      END IF;
25872 
25873      l_del_index := Nvl(IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_delv_index), -999);
25874 
25875      IF (l_del_tbl.EXISTS(l_del_index)) THEN
25876 
25877       IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_delv_index) :=l_del_tbl(l_del_index).delivery_channel_format_value;
25878 
25879      ELSE
25880 
25881       OPEN  c_deliv_info(l_trx_delv_index);
25882       FETCH c_deliv_info INTO
25883 		  IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_delv_index)
25884 	    ;
25885       IF (c_deliv_info%NOTFOUND = TRUE) THEN
25886 
25887        IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_delv_index) :=NULL;
25888 
25889       END IF;
25890       CLOSE c_deliv_info;
25891 
25892       l_del_tbl(l_del_index).delivery_channel_format_value := IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_delv_index);
25893     END IF;
25894      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25895      print_debuginfo(l_module_name, 'EXIT');
25896      END IF;
25897 
25898  END GET_DELIVERY_INFO;
25899 
25900 
25901 
25902   /*--------------------------------------------------------------------
25903  | NAME:
25904  |     GET_ORG_INFO
25905  |
25906  | PURPOSE:
25907  |
25908  |
25909  |
25910  | PARAMETERS:
25911  |     IN
25912  |
25913  |
25914  |     OUT
25915  |
25916  |
25917  | RETURNS:
25918  |
25919  | NOTES:
25920  |
25921  |
25922  |
25923  *---------------------------------------------------------------------*/
25924  PROCEDURE GET_ORG_INFO(
25925 	l_trx_org_index      IN BINARY_INTEGER
25926      )
25927  IS
25928  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
25929                                                   '.GET_ORG_INFO';
25930  l_org_index    BINARY_INTEGER;
25931  l_pmt_id   IBY_PAYMENTS_ALL.payment_id%TYPE;
25932  l_inv_payee_party_id  IBY_PAYMENTS_ALL.inv_payee_party_id%TYPE;
25933  l_inv_party_site_id   IBY_PAYMENTS_ALL.inv_party_site_id%TYPE;
25934  l_inv_supplier_site_id   IBY_PAYMENTS_ALL.inv_supplier_site_id%TYPE;
25935  l_inv_beneficiary_party  IBY_PAYMENTS_ALL.inv_beneficiary_party%TYPE;
25936 
25937 	  CURSOR c_org_info(l_trx_index BINARY_INTEGER) IS
25938 	  SELECT
25939 	  org.name
25940 	  FROM
25941 	  HR_ALL_ORGANIZATION_UNITS org
25942 	  where
25943 	  IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_index)            = org.organization_id;
25944 
25945 	  CURSOR c_ce_org_info(l_trx_index BINARY_INTEGER) IS
25946 	  SELECT
25947 	  le.name
25948 	  FROM
25949 	  xle_entity_profiles le
25950 	  where
25951 	  IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_index)            = le.legal_entity_id;
25952 
25953  BEGIN
25954 
25955      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25956       print_debuginfo(l_module_name, 'ENTER');
25957      END IF;
25958 
25959       l_org_index := IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_org_index);
25960       l_pmt_id := IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_org_index);
25961       l_inv_payee_party_id := IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(l_trx_org_index);
25962       l_inv_party_site_id := IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(l_trx_org_index);
25963       l_inv_supplier_site_id := IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(l_trx_org_index);
25964       l_inv_beneficiary_party := IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(l_trx_org_index);
25965 
25966       IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
25967       print_debuginfo(l_module_name, 'l_payment_id: ' || l_pmt_id);
25968       END IF;
25969 
25970       IF (l_org_tbl.EXISTS(l_trx_org_index)) THEN
25971 	     IBY_PAYGROUP_PUB.pmtTable.org_name(l_trx_org_index) := l_org_tbl(l_trx_org_index).org_name;
25972       ELSE
25973 
25974    --   OPEN  c_org_info(l_trx_org_index);
25975      -- FETCH c_org_info INTO
25976     	-- IBY_PAYGROUP_PUB.pmtTable.org_name(l_trx_org_index)
25977 
25978 
25979                IF(IBY_PAYGROUP_PUB.pmtTable.payment_function(l_trx_org_index)='CASH_PAYMENT') THEN
25980 
25981                              OPEN  c_ce_org_info(l_trx_org_index);
25982                              FETCH c_ce_org_info INTO IBY_PAYGROUP_PUB.pmtTable.org_name(l_trx_org_index);
25983                              CLOSE c_ce_org_info;
25984                      ELSE
25985                              OPEN  c_org_info(l_trx_org_index);
25986                              FETCH c_org_info INTO IBY_PAYGROUP_PUB.pmtTable.org_name(l_trx_org_index);
25987                              CLOSE c_org_info;
25988                END IF;
25989 
25990     	l_org_tbl(l_trx_org_index).org_name := IBY_PAYGROUP_PUB.pmtTable.org_name(l_trx_org_index);
25991 
25992       END IF;
25993 
25994 
25995 BEGIN
25996 SELECT
25997       /*TPP-Start*/
25998 invpayee.party_name 		inv_payee_name,
25999 
26000 invpayee.party_name 		inv_payee_party_name,
26001 --13777562: PAYEE/LEGALENTITYREGISTRATIONNUMBER FOR REFUNDS IS MISSING
26002 CASE
26003     WHEN (NVL(IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_org_index),-99)>0)
26004             THEN  (DECODE(upper(invvendor.vendor_type_lookup_code),
26005                               'CONTRACTOR',DECODE(invvendor.organization_type_lookup_code,
26006                               'INDIVIDUAL',invvendor.individual_1099,
26007                               'FOREIGN INDIVIDUAL',invvendor.individual_1099,
26008    		              'PARTNERSHIP',invvendor.individual_1099,
26009                               'FOREIGN PARTNERSHIP',invvendor.individual_1099,
26010                               invvendor.num_1099),
26011                                   invvendor.num_1099))
26012    ELSE            invpayee.jgzz_fiscal_code
26013 END inv_payee_le_reg_num,
26014 --13777562 Changes done
26015 /*Bug 13540717 Modifying the argument of Get_Payee_TaxRegistration*/
26016 IBY_FD_EXTRACT_GEN_PVT.
26017  Get_Payee_TaxRegistration
26018        (invpayee.party_id,invvendor_site.vendor_site_id)
26019 				inv_payee_tax_reg_num,
26020 DECODE (l_inv_beneficiary_party,
26021               NULL,
26022               invpayee.party_name,
26023               (SELECT
26024                    benef_party.party_name
26025                FROM
26026                    HZ_PARTIES benef_party
26027                WHERE
26028                    benef_party.party_id=l_inv_beneficiary_party
26029               )
26030            ) 			inv_beneficiary_name,
26031 
26032 invpayee.party_number 		inv_payee_party_number,
26033 invpayee.organization_name_phonetic	inv_payee_alternate_name,
26034 invvendor_site.vendor_site_code_alt	inv_payee_site_alt_name,
26035 invvendor.segment1			inv_payee_supplier_number,
26036 invvendor.customer_num			inv_payee_first_party_ref,
26037 
26038 invpayee.attribute_category		inv_payee_party_attr_cat,
26039 invvendor.attribute_category		inv_payee_supplier_attr_cat,
26040 NVL(invvendor_site.attribute_category,invpayee_site.attribute_category) inv_payee_spplr_site_attr_cat,
26041 invvendor_site.vendor_site_code		inv_payee_supplier_site_name,
26042 invvendor_site.vendor_site_code_alt	inv_payee_spplr_site_alt_name,
26043 invvendor.vendor_id			inv_payee_supplier_id
26044       /*TPP-End*/
26045  INTO
26046  	IBY_PAYGROUP_PUB.pmtTable.inv_payee_name(l_trx_org_index),
26047 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_name(l_trx_org_index),
26048 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_le_reg_num(l_trx_org_index),
26049 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_tax_reg_num(l_trx_org_index),
26050 	IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_name(l_trx_org_index),
26051 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_number(l_trx_org_index),
26052 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_alternate_name(l_trx_org_index),
26053 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_site_alt_name(l_trx_org_index),
26054 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_number(l_trx_org_index),
26055 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(l_trx_org_index),
26056 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_attr_cat(l_trx_org_index),
26057 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_attr_cat(l_trx_org_index),
26058 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_attr_cat(l_trx_org_index),
26059 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_site_name(l_trx_org_index),
26060 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_alt_name(l_trx_org_index),
26061 	IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_id(l_trx_org_index)
26062 
26063  FROM
26064 
26065   /* Payee */
26066   HZ_PARTIES               invpayee,
26067   HZ_PARTY_SITES           invpayee_site,
26068 
26069   AP_SUPPLIERS               invvendor,
26070   AP_SUPPLIER_SITES_ALL      invvendor_site
26071 
26072 
26073  WHERE
26074  /*Bug 13540717 --Start Modify*/
26075    /* inv payee */
26076   l_inv_payee_party_id	             		= invpayee.party_id
26077    /* inv payee site */
26078   AND invpayee.party_id 					= invpayee_site.party_id(+)
26079   AND nvl(l_inv_party_site_id,-999)        = invpayee_site.party_site_id(+)
26080   /* inv vendor related */
26081   AND invpayee.party_id  					= invvendor.party_id(+)
26082   AND nvl(invvendor.vendor_id,-999) 			= invvendor_site.vendor_id(+)
26083   AND nvl(l_inv_supplier_site_id, -999)     = invvendor_site.vendor_site_id(+);         /*Bug 7323072*/
26084   /*Bug 13540717 --End Modify*/
26085 
26086 
26087   EXCEPTION
26088               WHEN NO_DATA_FOUND THEN
26089                 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26090                 print_debuginfo(l_module_name, 'No Data Found Exception Occured for the Query');
26091                 END IF;
26092               WHEN OTHERS THEN
26093                 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26094                 print_debuginfo(l_module_name, 'Exception Occured for the Query');
26095                 END IF;
26096   END;
26097 
26098      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26099      print_debuginfo(l_module_name, 'EXIT');
26100      END IF;
26101 
26102  END GET_ORG_INFO;
26103 
26104 
26105 
26106 
26107   /*--------------------------------------------------------------------
26108  | NAME:
26109  |     GET_PMTREASON_INFO
26110  |
26111  | PURPOSE:
26112  |
26113  |
26114  |
26115  | PARAMETERS:
26116  |     IN
26117  |
26118  |
26119  |     OUT
26120  |
26121  |
26122  | RETURNS:
26123  |
26124  | NOTES:
26125  |
26126  |
26127  |
26128  *---------------------------------------------------------------------*/
26129  PROCEDURE GET_PMTREASON_INFO(
26130 	l_trx_pmtr_index      IN BINARY_INTEGER
26131      )
26132  IS
26133  l_module_name      CONSTANT VARCHAR2(200) := G_PKG_NAME ||
26134                                                   '.GET_PMTREASON_INFO';
26135 
26136  l_pmtr_index       VARCHAR2(2000);
26137 
26138 
26139 	  CURSOR c_pmtreason_info(l_trx_index BINARY_INTEGER) IS
26140 	  SELECT
26141 	  /* PAYMENT REASON */
26142 	  pmt_reason.format_value
26143 	  FROM
26144 	   /* Payment reason related */
26145 	  IBY_PAYMENT_REASONS_VL   pmt_reason
26146 
26147 	  WHERE
26148 	   /* payment reason */
26149 	  IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(l_trx_index) = pmt_reason.payment_reason_code(+)
26150 	  ;
26151 
26152 
26153  BEGIN
26154      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26155       print_debuginfo(l_module_name, 'ENTER');
26156      END IF;
26157 
26158      l_pmtr_index :=  Nvl(IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(l_trx_pmtr_index), -999);
26159 
26160 
26161      IF (l_pmt_reason_tbl.EXISTS(l_pmtr_index)) THEN
26162        IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(l_trx_pmtr_index) := l_pmt_reason_tbl(l_pmtr_index).payment_reason_format_value;
26163      ELSE
26164 
26165       OPEN  c_pmtreason_info(l_trx_pmtr_index);
26166       FETCH c_pmtreason_info INTO
26167 	IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(l_trx_pmtr_index)
26168 	;
26169       IF (c_pmtreason_info%NOTFOUND = TRUE) THEN
26170         IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(l_trx_pmtr_index) :=NULL;
26171       END IF;
26172       CLOSE c_pmtreason_info;
26173 
26174        l_pmt_reason_tbl(l_pmtr_index).payment_reason_format_value := IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(l_trx_pmtr_index);
26175 
26176      END IF;
26177 
26178      IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26179       print_debuginfo(l_module_name, 'EXIT');
26180      END IF;
26181 
26182  END GET_PMTREASON_INFO;
26183 
26184 
26185  PROCEDURE populatepmtTable(ppr_id IN IBY_PAYMENTS_ALL.PAYMENT_SERVICE_REQUEST_ID%type)
26186  IS
26187  l_module_name CONSTANT VARCHAR2(200) := G_PKG_NAME || '.populatePmtTable';
26188 
26189        CURSOR c_pmts_rebuild(ppr_id IBY_PAYMENTS_ALL.PAYMENT_SERVICE_REQUEST_ID%TYPE) IS
26190 	     SELECT
26191              payment_id,
26192              payment_method_code,
26193              payment_service_request_id,
26194              process_type,
26195              payment_status,
26196              payments_complete_flag,
26197              payment_function,
26198              payment_amount,
26199              payment_currency_code,
26200              bill_payable_flag,
26201              exclusive_payment_flag,
26202              separate_remit_advice_req_flag,
26203              internal_bank_account_id,
26204              org_id,
26205              org_type,
26206              legal_entity_id,
26207              declare_payment_flag,
26208              delivery_channel_code,
26209              ext_payee_id,
26210              payment_instruction_id,
26211              payment_profile_id,
26212              pregrouped_payment_flag,
26213              stop_confirmed_flag,
26214              stop_released_flag,
26215              stop_request_placed_flag,
26216              created_by,
26217              creation_date,
26218              last_updated_by,
26219              last_update_login,
26220              last_update_date,
26221              object_version_number,
26222              payee_party_id,
26223              party_site_id,
26224              supplier_site_id,
26225              payment_reason_code,
26226              payment_reason_comments,
26227              payment_date,
26228              anticipated_value_date,
26229              declaration_amount,
26230              declaration_currency_code,
26231              discount_amount_taken,
26232              payment_details,
26233              bank_charge_bearer,
26234              bank_charge_amount,
26235              settlement_priority,
26236              remittance_message1,
26237              remittance_message2,
26238              remittance_message3,
26239              payment_reference_number,
26240              paper_document_number,
26241              bank_assigned_ref_code,
26242              external_bank_account_id,
26243              unique_remittance_identifier,
26244              uri_check_digit,
26245              bank_instruction1_code,
26246              bank_instruction2_code,
26247              bank_instruction_details,
26248              payment_text_message1,
26249              payment_text_message2,
26250              payment_text_message3,
26251              maturity_date,
26252              payment_due_date,
26253              document_category_code,
26254              document_sequence_id,
26255              document_sequence_value,
26256              beneficiary_party,
26257              stop_confirmed_by,
26258              stop_confirm_date,
26259              stop_confirm_reason,
26260              stop_confirm_reference,
26261              stop_released_by,
26262              stop_release_date,
26263              stop_release_reason,
26264              stop_release_reference,
26265              stop_request_date,
26266              stop_request_placed_by,
26267              stop_request_reason,
26268              stop_request_reference,
26269              voided_by,
26270              void_date,
26271              void_reason,
26272              remit_to_location_id,
26273              completed_pmts_group_id,
26274              attribute_category,
26275              attribute1,
26276              attribute2,
26277              attribute3,
26278              attribute4,
26279              attribute5,
26280              attribute6,
26281              attribute7,
26282              attribute8,
26283              attribute9,
26284              attribute10,
26285              attribute11,
26286              attribute12,
26287              attribute13,
26288              attribute14,
26289              attribute15,
26290              ext_branch_number,
26291              ext_bank_number,
26292              ext_bank_account_name,
26293              ext_bank_account_number,
26294              ext_bank_account_type,
26295              ext_bank_account_iban_number,
26296              payee_name,
26297              payee_address1,
26298              payee_address2,
26299              payee_address3,
26300              payee_address4,
26301              payee_city,
26302              payee_postal_code,
26303              payee_state,
26304              payee_province,
26305              payee_county,
26306              payee_country,
26307              remit_advice_delivery_method,
26308              remit_advice_email,
26309              remit_advice_fax,
26310              address_source,
26311              employee_address_code,
26312              employee_person_id,
26313              employee_address_id,
26314              employee_payment_flag,
26315     		ext_inv_payee_id ,
26316 		inv_payee_party_id ,
26317 		inv_party_site_id ,
26318 		inv_supplier_site_id ,
26319 		inv_beneficiary_party ,
26320 		inv_payee_name ,
26321 		inv_payee_address1 ,
26322 		inv_payee_address2 ,
26323 		inv_payee_address3 ,
26324 		inv_payee_address4 ,
26325 		inv_payee_city ,
26326 		inv_payee_postal_code ,
26327 		inv_payee_state ,
26328 		inv_payee_province ,
26329 		inv_payee_county ,
26330 		inv_payee_country ,
26331 		inv_payee_party_name ,
26332 		inv_payee_le_reg_num,
26333 		inv_payee_tax_reg_num,
26334 		inv_payee_address_concat ,
26335 		inv_beneficiary_name ,
26336 		inv_payee_party_number ,
26337 		inv_payee_alternate_name ,
26338 		inv_payee_site_alt_name,
26339 		inv_payee_supplier_number ,
26340 		inv_payee_first_party_ref,
26341 		ext_bnk_acct_ownr_inv_prty_id,
26342 		ext_bnk_branch_inv_prty_id,
26343 		ext_bnk_acct_ownr_inv_prty_nme,
26344 		inv_payee_party_attr_cat,
26345 		inv_payee_supplier_attr_cat,
26346 		inv_payee_spplr_site_attr_cat,
26347 		inv_payee_supplier_site_name ,
26348 		inv_payee_spplr_site_alt_name,
26349 		inv_payee_supplier_id,
26350          -- start of auditPaymentData fields
26351              payer_party_number             	,
26352              payer_party_site_name          	,
26353              payer_legal_entity_name        	,
26354              payer_tax_registration_num     	,
26355              payer_le_registration_num      	,
26356              payer_party_id                 	,
26357              payer_location_id              	,
26358              payer_party_attr_category      	,
26359              payer_le_attr_category         	,
26360              payer_abbreviated_agency_code  	,
26361              payer_federal_us_employer_id   	,
26362              int_bank_name                  	,
26363              int_bank_number                	,
26364              int_bank_branch_number         	,
26365              int_bank_branch_name           	,
26366              int_eft_swift_code             	,
26367              int_bank_account_number        	,
26368              int_bank_account_name          	,
26369              int_bank_account_iban          	,
26370              int_bank_acct_agency_loc_code  	,
26371              int_bank_branch_party_id       	,
26372              int_bank_alt_name              	,
26373              int_bank_branch_alt_name       	,
26374              int_bank_account_alt_name      	,
26375              int_bank_account_num_elec      	,
26376              int_bank_branch_location_id    	,
26377              int_bank_branch_eft_user_num   	,
26378              payee_party_number             	,
26379              payee_party_name               	,
26380              payee_alternate_name           	,
26381              payee_address_concat           	,
26382              beneficiary_name               	,
26383              payee_party_attr_category      	,
26384              payee_spplr_site_attr_category 	,
26385              payee_supplier_site_name       	,
26386              payee_party_site_name       	,
26387              payee_addressee                	,
26388              payee_site_alternate_name      	,
26389              payee_supplier_number          	,
26390              payee_first_party_reference    	,
26391              payee_supplier_attr_category   	,
26392              payee_supplier_id              	,
26393              payee_tax_registration_num ,
26394              payee_le_registration_num  ,
26395              ext_bank_name,
26396               ext_bank_branch_name           	,
26397               ext_eft_swift_code             	,
26398               ext_bank_acct_pmt_factor_flag  	,
26399               ext_bank_acct_owner_party_id   	,
26400               ext_bank_branch_party_id       	,
26401               ext_bank_alt_name              	,
26402               ext_bank_branch_alt_name       	,
26403               ext_bank_account_alt_name      	,
26404               ext_bank_account_num_elec      	,
26405              ext_bank_branch_location_id    	,
26406              ext_bank_acct_owner_party_name 	,
26407              --remit_advice_delivery_method   	,
26408              --remit_advice_email             	,
26409              --remit_advice_fax               	,
26410              delivery_channel_format_value  	,
26411              declaration_exch_rate_type     	,
26412              declaration_format             	,
26413              payment_profile_acct_name      	,
26414              payment_profile_sys_name       	,
26415              payment_reason_format_value    	,
26416              bank_instruction1_format_value 	,
26417              bank_instruction2_format_value 	,
26418              org_name                       	,
26419              int_bank_branch_rfc_identifier ,
26420              payment_process_request_name   ,
26421              source_product
26422 
26423 	     FROM
26424 	     IBY_PAYMENTS_ALL
26425 	     where payment_service_request_id =ppr_id;
26426 
26427  BEGIN
26428 
26429       print_debuginfo(l_module_name, 'Enter');
26430 
26431  	    OPEN c_pmts_rebuild(ppr_id);
26432 	    FETCH c_pmts_rebuild BULK COLLECT INTO
26433              IBY_PAYGROUP_PUB.pmtTable.payment_id,
26434              IBY_PAYGROUP_PUB.pmtTable.payment_method_code,
26435              IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id,
26436              IBY_PAYGROUP_PUB.pmtTable.process_type,
26437              IBY_PAYGROUP_PUB.pmtTable.payment_status,
26438              IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag,
26439              IBY_PAYGROUP_PUB.pmtTable.payment_function,
26440              IBY_PAYGROUP_PUB.pmtTable.payment_amount,
26441              IBY_PAYGROUP_PUB.pmtTable.payment_currency_code,
26442              IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag,
26443              IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag,
26444              IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag,
26445              IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id,
26446              IBY_PAYGROUP_PUB.pmtTable.org_id,
26447              IBY_PAYGROUP_PUB.pmtTable.org_type,
26448              IBY_PAYGROUP_PUB.pmtTable.legal_entity_id,
26449              IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag,
26450              IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code,
26451              IBY_PAYGROUP_PUB.pmtTable.ext_payee_id,
26452              IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id,
26453              IBY_PAYGROUP_PUB.pmtTable.payment_profile_id,
26454              IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag,
26455              IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag,
26456              IBY_PAYGROUP_PUB.pmtTable.stop_released_flag,
26457              IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag,
26458              IBY_PAYGROUP_PUB.pmtTable.created_by,
26459              IBY_PAYGROUP_PUB.pmtTable.creation_date,
26460              IBY_PAYGROUP_PUB.pmtTable.last_updated_by,
26461              IBY_PAYGROUP_PUB.pmtTable.last_update_login,
26462              IBY_PAYGROUP_PUB.pmtTable.last_update_date,
26463              IBY_PAYGROUP_PUB.pmtTable.object_version_number,
26464              IBY_PAYGROUP_PUB.pmtTable.payee_party_id,
26465              IBY_PAYGROUP_PUB.pmtTable.party_site_id,
26466              IBY_PAYGROUP_PUB.pmtTable.supplier_site_id,
26467              IBY_PAYGROUP_PUB.pmtTable.payment_reason_code,
26468              IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments,
26469              IBY_PAYGROUP_PUB.pmtTable.payment_date,
26470              IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date,
26471              IBY_PAYGROUP_PUB.pmtTable.declaration_amount,
26472              IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code,
26473              IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken,
26474              IBY_PAYGROUP_PUB.pmtTable.payment_details,
26475              IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer,
26476              IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount,
26477              IBY_PAYGROUP_PUB.pmtTable.settlement_priority,
26478              IBY_PAYGROUP_PUB.pmtTable.remittance_message1,
26479              IBY_PAYGROUP_PUB.pmtTable.remittance_message2,
26480              IBY_PAYGROUP_PUB.pmtTable.remittance_message3,
26481              IBY_PAYGROUP_PUB.pmtTable.payment_reference_number,
26482              IBY_PAYGROUP_PUB.pmtTable.paper_document_number,
26483              IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code,
26484              IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id,
26485              IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier,
26486              IBY_PAYGROUP_PUB.pmtTable.uri_check_digit,
26487              IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code,
26488              IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code,
26489              IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details,
26490              IBY_PAYGROUP_PUB.pmtTable.payment_text_message1,
26491              IBY_PAYGROUP_PUB.pmtTable.payment_text_message2,
26492              IBY_PAYGROUP_PUB.pmtTable.payment_text_message3,
26493              IBY_PAYGROUP_PUB.pmtTable.maturity_date,
26494              IBY_PAYGROUP_PUB.pmtTable.payment_due_date,
26495              IBY_PAYGROUP_PUB.pmtTable.document_category_code,
26496              IBY_PAYGROUP_PUB.pmtTable.document_sequence_id,
26497              IBY_PAYGROUP_PUB.pmtTable.document_sequence_value,
26498              IBY_PAYGROUP_PUB.pmtTable.beneficiary_party,
26499              IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by,
26500              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date,
26501              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason,
26502              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference,
26503              IBY_PAYGROUP_PUB.pmtTable.stop_released_by,
26504              IBY_PAYGROUP_PUB.pmtTable.stop_release_date,
26505              IBY_PAYGROUP_PUB.pmtTable.stop_release_reason,
26506              IBY_PAYGROUP_PUB.pmtTable.stop_release_reference,
26507              IBY_PAYGROUP_PUB.pmtTable.stop_request_date,
26508              IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by,
26509              IBY_PAYGROUP_PUB.pmtTable.stop_request_reason,
26510              IBY_PAYGROUP_PUB.pmtTable.stop_request_reference,
26511              IBY_PAYGROUP_PUB.pmtTable.voided_by,
26512              IBY_PAYGROUP_PUB.pmtTable.void_date,
26513              IBY_PAYGROUP_PUB.pmtTable.void_reason,
26514              IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id,
26515              IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id,
26516              IBY_PAYGROUP_PUB.pmtTable.attribute_category,
26517              IBY_PAYGROUP_PUB.pmtTable.attribute1,
26518              IBY_PAYGROUP_PUB.pmtTable.attribute2,
26519              IBY_PAYGROUP_PUB.pmtTable.attribute3,
26520              IBY_PAYGROUP_PUB.pmtTable.attribute4,
26521              IBY_PAYGROUP_PUB.pmtTable.attribute5,
26522              IBY_PAYGROUP_PUB.pmtTable.attribute6,
26523              IBY_PAYGROUP_PUB.pmtTable.attribute7,
26524              IBY_PAYGROUP_PUB.pmtTable.attribute8,
26525              IBY_PAYGROUP_PUB.pmtTable.attribute9,
26526              IBY_PAYGROUP_PUB.pmtTable.attribute10,
26527              IBY_PAYGROUP_PUB.pmtTable.attribute11,
26528              IBY_PAYGROUP_PUB.pmtTable.attribute12,
26529              IBY_PAYGROUP_PUB.pmtTable.attribute13,
26530              IBY_PAYGROUP_PUB.pmtTable.attribute14,
26531              IBY_PAYGROUP_PUB.pmtTable.attribute15,
26532              IBY_PAYGROUP_PUB.pmtTable.ext_branch_number,
26533              IBY_PAYGROUP_PUB.pmtTable.ext_bank_number,
26534              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name,
26535              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number,
26536              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type,
26537              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number,
26538              IBY_PAYGROUP_PUB.pmtTable.payee_name,
26539              IBY_PAYGROUP_PUB.pmtTable.payee_address1,
26540              IBY_PAYGROUP_PUB.pmtTable.payee_address2,
26541              IBY_PAYGROUP_PUB.pmtTable.payee_address3,
26542              IBY_PAYGROUP_PUB.pmtTable.payee_address4,
26543              IBY_PAYGROUP_PUB.pmtTable.payee_city,
26544              IBY_PAYGROUP_PUB.pmtTable.payee_postal_code,
26545              IBY_PAYGROUP_PUB.pmtTable.payee_state,
26546              IBY_PAYGROUP_PUB.pmtTable.payee_province,
26547              IBY_PAYGROUP_PUB.pmtTable.payee_county,
26548              IBY_PAYGROUP_PUB.pmtTable.payee_country,
26549              IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method,
26550              IBY_PAYGROUP_PUB.pmtTable.remit_advice_email,
26551              IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax,
26552              IBY_PAYGROUP_PUB.pmtTable.address_source,
26553              IBY_PAYGROUP_PUB.pmtTable.employee_address_code,
26554              IBY_PAYGROUP_PUB.pmtTable.employee_person_id,
26555              IBY_PAYGROUP_PUB.pmtTable.employee_address_id,
26556              IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag,
26557 	     	IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id,
26558 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id,
26559 		IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id,
26560 		IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id,
26561 		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party,
26562 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_name,
26563 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address1,
26564 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address2,
26565 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address3,
26566 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address4,
26567 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_city,
26568 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_postal_code,
26569 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_state,
26570 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_province,
26571 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_county,
26572 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_country,
26573 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_name,
26574 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_le_reg_num,
26575 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_tax_reg_num,
26576 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address_concat,
26577 		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_name,
26578 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_number,
26579 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_alternate_name,
26580 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_site_alt_name,
26581 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_number,
26582 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref,
26583 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_id,
26584 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_branch_inv_prty_id,
26585 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_nme,
26586 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_attr_cat,
26587 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_attr_cat,
26588 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_attr_cat,
26589 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_site_name,
26590 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_alt_name,
26591 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_id,
26592 		-- start of auditPaymentdata fields
26593 		IBY_PAYGROUP_PUB.pmtTable.payer_party_number,
26594 	IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name,
26595 	IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name,
26596 	IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num,
26597 	IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num,
26598 	IBY_PAYGROUP_PUB.pmtTable.payer_party_id,
26599 	IBY_PAYGROUP_PUB.pmtTable.payer_location_id,
26600 	IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category,
26601 	IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category,
26602 	IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code,
26603 	IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id,
26604 	IBY_PAYGROUP_PUB.pmtTable.int_bank_name,
26605 	IBY_PAYGROUP_PUB.pmtTable.int_bank_number,
26606 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number,
26607 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name,
26608 	IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code,
26609 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number,
26610 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name,
26611 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban,
26612 	IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code,
26613 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id,
26614 	IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name,
26615 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name,
26616 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name,
26617 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec,
26618 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id,
26619 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num,
26620 	IBY_PAYGROUP_PUB.pmtTable.payee_party_number,
26621 	IBY_PAYGROUP_PUB.pmtTable.payee_party_name,
26622 	IBY_PAYGROUP_PUB.pmtTable.payee_alt_name, -- Bug 6175102
26623 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat,
26624 	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name,
26625 	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat,
26626 	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category,
26627 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name,
26628 	IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name,
26629 	IBY_PAYGROUP_PUB.pmtTable.payee_addressee,
26630 	IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name,
26631 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number,
26632 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference,
26633 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category,
26634 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id,
26635 	IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num,
26636 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num,
26637 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_name,
26638 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name,
26639 	IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code,
26640 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag,
26641 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id,
26642 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id,
26643 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name,
26644 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name,
26645 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name,
26646 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec,
26647 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id,
26648 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name,
26649 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method,
26650 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_email,
26651 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax,
26652 	IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value,
26653 	IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type,
26654 	IBY_PAYGROUP_PUB.pmtTable.declaration_format,
26655 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name,
26656 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name,
26657 	IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value,
26658 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value,
26659 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value,
26660 	IBY_PAYGROUP_PUB.pmtTable.org_name,
26661 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier,
26662 	IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name,
26663 	IBY_PAYGROUP_PUB.pmtTable.source_product
26664         ;
26665 
26666        CLOSE c_pmts_rebuild;
26667 
26668 
26669  END populatepmtTable;
26670 
26671  /*--------------------------------------------------------------------
26672  | NAME:
26673  |     negativePmtAmountCheck
26674  |
26675  | PURPOSE: Validation to check that payment amount is not a negative
26676  |value
26677  |
26678  | PARAMETERS:
26679  |     IN
26680  |
26681  |
26682  |     OUT
26683  |
26684  |
26685  | RETURNS:
26686  |
26687  | NOTES: Added for the bug 7344352
26688  |
26689  *---------------------------------------------------------------------*/
26690  PROCEDURE negativePmtAmountCheck(
26691      p_trx_pmt_line_index IN BINARY_INTEGER,
26692      x_docErrorTab   IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.docErrorTabType,
26693      x_errTokenTab   IN OUT NOCOPY IBY_VALIDATIONSETS_PUB.trxnErrTokenTabType
26694      )
26695  IS
26696   l_module_name   VARCHAR2(200)  := G_PKG_NAME || '.negativePmtAmountCheck';
26697   l_doc_err_rec   IBY_TRANSACTION_ERRORS%ROWTYPE;
26698   l_error_code    VARCHAR2(100);
26699   l_error_msg     VARCHAR2(500);
26700   l_token_rec     IBY_TRXN_ERROR_TOKENS%ROWTYPE;
26701  BEGIN
26702             IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26703              print_debuginfo(l_module_name, 'ENTER');
26704 	    END IF;
26705 
26706               IF (IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index) < 0
26707               AND IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index) = PAY_STATUS_CREATED) THEN
26708 
26709                   IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index) := PAY_STATUS_REJECTED;
26710 
26711                                 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26712                                   print_debuginfo(l_module_name, 'Failed payment '
26713 				     || IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index)
26714 				     || ' because payment amount '
26715 				     || IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index)
26716                                      ||' is less than zero'
26717 				     );
26718                                 END IF;
26719 
26720 
26721 				 l_error_code := 'IBY_PMT_NEGATIVE_AMT';
26722 				 FND_MESSAGE.set_name('IBY', l_error_code);
26723 
26724 				 FND_MESSAGE.SET_TOKEN('PMT_AMOUNT',
26725 				     IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index),
26726 				     FALSE);
26727 
26728 				 l_token_rec.token_name  := 'PMT_AMOUNT';
26729 				 l_token_rec.token_value := IBY_PAYGROUP_PUB.pmtTable.payment_amount(p_trx_pmt_line_index);
26730 				 x_errTokenTab(x_errTokenTab.COUNT + 1) := l_token_rec;
26731 
26732 				 /*
26733 				  * Once we fail a payment, we need to create
26734 				  * an error record and insert this record
26735 				  * into the errors table.
26736 				  */
26737 				 IBY_BUILD_UTILS_PKG.createPmtErrorRecord(
26738                                  IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
26739                                  IBY_PAYGROUP_PUB.pmtTable.payment_status(p_trx_pmt_line_index),
26740                                  l_error_code,
26741                                  FND_MESSAGE.get,
26742                                  l_doc_err_rec
26743                                  );
26744 
26745 				 IBY_VALIDATIONSETS_PUB.insertIntoErrorTable(
26746                                  l_doc_err_rec, x_docErrorTab, x_errTokenTab);
26747 
26748                                  failDocsOfPayment(IBY_PAYGROUP_PUB.pmtTable.payment_id(p_trx_pmt_line_index),
26749                                  DOC_STATUS_PAY_VAL_FAIL,
26750                                  x_docErrorTab, x_errTokenTab);
26751 
26752             END IF;
26753 
26754 	    IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
26755              print_debuginfo(l_module_name, 'EXIT');
26756             END IF;
26757  END negativePmtAmountCheck;
26758 
26759 
26760 /*--------------------------------------------------------------------
26761  | NAME:
26762  |     print_debuginfo
26763  |
26764  | PURPOSE:
26765  |     This procedure prints the debug message to the concurrent manager
26766  |     log file.
26767  |
26768  | PARAMETERS:
26769  |     IN
26770  |      p_debug_text - The debug message to be printed
26771  |
26772  |     OUT
26773  |
26774  |
26775  | RETURNS:
26776  |
26777  | NOTES:
26778  |
26779  *---------------------------------------------------------------------*/
26780  PROCEDURE print_debuginfo(
26781      p_module      IN VARCHAR2,
26782      p_debug_text  IN VARCHAR2,
26783      p_debug_level IN VARCHAR2  DEFAULT FND_LOG.LEVEL_STATEMENT
26784      )
26785  IS
26786  l_default_debug_level VARCHAR2(200) := FND_LOG.LEVEL_STATEMENT;
26787  BEGIN
26788 
26789      /*
26790       * Set the debug level to the value passed in
26791       * (provided this value is not null).
26792       */
26793      IF (p_debug_level IS NOT NULL) THEN
26794          l_default_debug_level := p_debug_level;
26795      END IF;
26796 
26797      /*
26798       * Write the debug message to the concurrent manager log file.
26799       */
26800      --IF (l_default_debug_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
26801          iby_debug_pub.log(debug_msg => p_module||':'||p_debug_text,debug_level => p_debug_level, module => p_module);
26802      --END IF;
26803 
26804  END print_debuginfo;
26805 
26806  /*--------------------------------------------------------------------
26807  | NAME:
26808  |     initialize_pmt_table
26809  |
26810  | PURPOSE:
26811  |
26812  |
26813  | PARAMETERS:
26814  |     IN
26815  |
26816  |
26817  |     OUT
26818  |
26819  |
26820  | RETURNS:
26821  |
26822  | NOTES:
26823  |
26824  *---------------------------------------------------------------------*/
26825 
26826  PROCEDURE initialize_pmt_table(l_trx_pmt_index IN BINARY_INTEGER)
26827  IS
26828 
26829  l_module_name    VARCHAR2(200) := G_PKG_NAME ||
26830                                        '.initialize_pmt_table';
26831  l_default_debug_level VARCHAR2(200) := FND_LOG.LEVEL_STATEMENT;
26832 
26833  BEGIN
26834 
26835         IF (l_default_debug_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
26836         print_debuginfo(l_module_name, 'ENTER');
26837         END IF;
26838 
26839          /*IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_pmt_index) := NULL;
26840          IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(l_trx_pmt_index) := NULL;
26841 	 IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(l_trx_pmt_index) := NULL;
26842          IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_pmt_index) := NULL;
26843          IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_pmt_index) := NULL;
26844          IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_pmt_index) := NULL;
26845          IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_pmt_index) := NULL;
26846 	 IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(l_trx_pmt_index) := NULL;
26847          IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(l_trx_pmt_index) := NULL;
26848          IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(l_trx_pmt_index) := NULL;
26849          IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(l_trx_pmt_index) := NULL;
26850          IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(l_trx_pmt_index) := NULL;
26851          IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(l_trx_pmt_index) := NULL;
26852          IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(l_trx_pmt_index) := NULL;
26853          IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_pmt_index) := NULL;
26854          IBY_PAYGROUP_PUB.pmtTable.org_type(l_trx_pmt_index) := NULL;
26855          IBY_PAYGROUP_PUB.pmtTable.payment_method_code(l_trx_pmt_index) := NULL;
26856          IBY_PAYGROUP_PUB.pmtTable.payment_function(l_trx_pmt_index) := NULL;
26857          IBY_PAYGROUP_PUB.pmtTable.payment_date(l_trx_pmt_index) := NULL;
26858          IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(l_trx_pmt_index) := NULL;
26859          IBY_PAYGROUP_PUB.pmtTable.address_source(l_trx_pmt_index) := NULL;
26860          IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_pmt_index) := NULL;
26861          IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_pmt_index) := NULL;
26862          IBY_PAYGROUP_PUB.pmtTable.employee_address_id(l_trx_pmt_index) := NULL;
26863          IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(l_trx_pmt_index) := NULL;
26864          IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_pmt_index) := NULL;
26865 	 IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_pmt_index) :=NULL;
26866          IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_pmt_index) := NULL;
26867          IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(l_trx_pmt_index) := NULL;
26868          IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(l_trx_pmt_index) := NULL;
26869          IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(l_trx_pmt_index) := NULL;
26870          IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(l_trx_pmt_index) := NULL;
26871          IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(l_trx_pmt_index) := NULL;
26872          IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(l_trx_pmt_index) := NULL;
26873          IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(l_trx_pmt_index) := NULL;
26874          IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(l_trx_pmt_index) := NULL;
26875          IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index) := NULL;
26876 	 IBY_PAYGROUP_PUB.pmtTable.settlement_priority(l_trx_pmt_index) := NULL;
26877          IBY_PAYGROUP_PUB.pmtTable.remittance_message1(l_trx_pmt_index) := NULL;
26878          IBY_PAYGROUP_PUB.pmtTable.remittance_message2(l_trx_pmt_index) := NULL;
26879          IBY_PAYGROUP_PUB.pmtTable.remittance_message3(l_trx_pmt_index) := NULL;
26880 	 IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index) := NULL;
26881 	 IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(l_trx_pmt_index) := NULL;
26882 	 IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(l_trx_pmt_index) := NULL;
26883 	 IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index) := NULL;
26884          IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index)  := NULL;
26885  	IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index)             := NULL;
26886 	IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index)        := NULL;
26887         IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_pmt_index)         :='CREATED';
26888 	IBY_PAYGROUP_PUB.pmtTable.process_type(l_trx_pmt_index)		  := 'STANDARD';
26889 	IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(l_trx_pmt_index) := 'N';
26890 	IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(l_trx_pmt_index)	  :='N';
26891 	IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index)	  :='N';
26892 	IBY_PAYGROUP_PUB.pmtTable.created_by(l_trx_pmt_index)                     := fnd_global.user_id;
26893          IBY_PAYGROUP_PUB.pmtTable.creation_date(l_trx_pmt_index)                  := sysdate;
26894          IBY_PAYGROUP_PUB.pmtTable.last_updated_by(l_trx_pmt_index)                := fnd_global.user_id;
26895          IBY_PAYGROUP_PUB.pmtTable.last_update_login(l_trx_pmt_index)              := fnd_global.user_id;
26896          IBY_PAYGROUP_PUB.pmtTable.last_update_date(l_trx_pmt_index)               := sysdate;
26897          IBY_PAYGROUP_PUB.pmtTable.object_version_number(l_trx_pmt_index)          := 1;
26898 	IBY_PAYGROUP_PUB.pmtTable.voided_by(l_trx_pmt_index):= NULL;
26899 	IBY_PAYGROUP_PUB.pmtTable.void_date(l_trx_pmt_index):= NULL;
26900 	IBY_PAYGROUP_PUB.pmtTable.void_reason(l_trx_pmt_index):= NULL;
26901 	IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_pmt_index) := NULL;
26902 	IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_pmt_index) := NULL;
26903 	IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_pmt_index) := NULL;
26904 	IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_pmt_index) := NULL;
26905 	IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_pmt_index) := NULL;
26906 	IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_pmt_index) := NULL;
26907 	IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_pmt_index) := NULL;
26908 	IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_pmt_index) := NULL;
26909 	IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_pmt_index) := NULL;
26910 	IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_pmt_index) := NULL;
26911 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_pmt_index) := NULL;
26912         IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_pmt_index):= NULL;
26913 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_pmt_index):= NULL;
26914 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_pmt_index)	:= NULL;
26915 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_pmt_index):= NULL;
26916 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_pmt_index):= NULL;
26917 	IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(l_trx_pmt_index):= NULL;
26918 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_pmt_index) := NULL;
26919 	IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_pmt_index)          := 0;
26920         IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_pmt_index)   :=  0;
26921         IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(l_trx_pmt_index)	  :=NULL;
26922 	IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(l_trx_pmt_index)         :=NULL;
26923 	IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(l_trx_pmt_index)         :=NULL;
26924 	IBY_PAYGROUP_PUB.pmtTable.declaration_amount(l_trx_pmt_index)             :=0;
26925 	IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(l_trx_pmt_index) := NULL;
26926 	IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(l_trx_pmt_index) :=0;
26927 	IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(l_trx_pmt_index) :=NULL;
26928 	IBY_PAYGROUP_PUB.pmtTable.paper_document_number(l_trx_pmt_index)    :=NULL;
26929 	IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(l_trx_pmt_index)   := NULL;
26930 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(l_trx_pmt_index) := NULL;
26931 	IBY_PAYGROUP_PUB.pmtTable.maturity_date(l_trx_pmt_index)	    := NULL;
26932 	IBY_PAYGROUP_PUB.pmtTable.document_category_code(l_trx_pmt_index)   :=NULL;
26933 	IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(l_trx_pmt_index)	    :=NULL;
26934 	IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(l_trx_pmt_index):= NULL;
26935 	IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(l_trx_pmt_index):= NULL;
26936 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(l_trx_pmt_index):= NULL;
26937 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(l_trx_pmt_index):= NULL;
26938 	IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(l_trx_pmt_index):= NULL;
26939 	IBY_PAYGROUP_PUB.pmtTable.stop_released_by(l_trx_pmt_index):= NULL;
26940 	IBY_PAYGROUP_PUB.pmtTable.stop_release_date(l_trx_pmt_index):= NULL;
26941 	IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(l_trx_pmt_index):= NULL;
26942 	IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(l_trx_pmt_index):= NULL;
26943 	IBY_PAYGROUP_PUB.pmtTable.stop_request_date(l_trx_pmt_index):= NULL;
26944 	IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by(l_trx_pmt_index):= NULL;
26945 	IBY_PAYGROUP_PUB.pmtTable.stop_request_reason(l_trx_pmt_index):= NULL;
26946 	IBY_PAYGROUP_PUB.pmtTable.stop_request_reference(l_trx_pmt_index):= NULL;
26947 	IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(l_trx_pmt_index):= NULL;
26948 	IBY_PAYGROUP_PUB.pmtTable.attribute_category(l_trx_pmt_index):= NULL;
26949 	IBY_PAYGROUP_PUB.pmtTable.attribute1(l_trx_pmt_index):= NULL;
26950 	IBY_PAYGROUP_PUB.pmtTable.attribute2(l_trx_pmt_index):= NULL;
26951 	IBY_PAYGROUP_PUB.pmtTable.attribute3(l_trx_pmt_index):= NULL;
26952 	IBY_PAYGROUP_PUB.pmtTable.attribute4(l_trx_pmt_index):= NULL;
26953 	IBY_PAYGROUP_PUB.pmtTable.attribute5(l_trx_pmt_index):= NULL;
26954 	IBY_PAYGROUP_PUB.pmtTable.attribute6(l_trx_pmt_index):= NULL;
26955 	IBY_PAYGROUP_PUB.pmtTable.attribute7(l_trx_pmt_index):= NULL;
26956 	IBY_PAYGROUP_PUB.pmtTable.attribute8(l_trx_pmt_index):= NULL;
26957 	IBY_PAYGROUP_PUB.pmtTable.attribute9(l_trx_pmt_index):= NULL;
26958 	IBY_PAYGROUP_PUB.pmtTable.attribute10(l_trx_pmt_index):= NULL;
26959 	IBY_PAYGROUP_PUB.pmtTable.attribute11(l_trx_pmt_index):= NULL;
26960 	IBY_PAYGROUP_PUB.pmtTable.attribute12(l_trx_pmt_index):= NULL;
26961 	IBY_PAYGROUP_PUB.pmtTable.attribute13(l_trx_pmt_index):= NULL;
26962 	IBY_PAYGROUP_PUB.pmtTable.attribute14(l_trx_pmt_index):= NULL;
26963 	IBY_PAYGROUP_PUB.pmtTable.attribute15(l_trx_pmt_index):= NULL;
26964         IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index)           := 'N';
26965 	IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(l_trx_pmt_index)            := 'N';
26966 	IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(l_trx_pmt_index)             := 'N';
26967 	IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(l_trx_pmt_index)       := 'N';
26968 	IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index) := NULL;
26969         IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index)            :=  '';*/
26970 
26971         IBY_PAYGROUP_PUB.pmtTable.payment_id(l_trx_pmt_index) := NULL;
26972              IBY_PAYGROUP_PUB.pmtTable.payment_method_code(l_trx_pmt_index) := NULL;
26973              IBY_PAYGROUP_PUB.pmtTable.payment_service_request_id(l_trx_pmt_index) := NULL;
26974              IBY_PAYGROUP_PUB.pmtTable.process_type(l_trx_pmt_index) := NULL;
26975              IBY_PAYGROUP_PUB.pmtTable.payment_status(l_trx_pmt_index) := NULL;
26976              IBY_PAYGROUP_PUB.pmtTable.payments_complete_flag(l_trx_pmt_index) := 'N';
26977              IBY_PAYGROUP_PUB.pmtTable.payment_function(l_trx_pmt_index) := NULL;
26978              IBY_PAYGROUP_PUB.pmtTable.payment_amount(l_trx_pmt_index) := NULL;
26979              IBY_PAYGROUP_PUB.pmtTable.payment_currency_code(l_trx_pmt_index) := NULL;
26980              IBY_PAYGROUP_PUB.pmtTable.bill_payable_flag(l_trx_pmt_index) := 'N';
26981              IBY_PAYGROUP_PUB.pmtTable.exclusive_payment_flag(l_trx_pmt_index) := 'N';
26982              IBY_PAYGROUP_PUB.pmtTable.sep_remit_advice_req_flag(l_trx_pmt_index) := 'N';
26983              IBY_PAYGROUP_PUB.pmtTable.internal_bank_account_id(l_trx_pmt_index) := NULL;
26984              IBY_PAYGROUP_PUB.pmtTable.org_id(l_trx_pmt_index) := NULL;
26985              IBY_PAYGROUP_PUB.pmtTable.org_type(l_trx_pmt_index) := NULL;
26986              IBY_PAYGROUP_PUB.pmtTable.legal_entity_id(l_trx_pmt_index) := NULL;
26987              IBY_PAYGROUP_PUB.pmtTable.declare_payment_flag(l_trx_pmt_index) := 'N';
26988              IBY_PAYGROUP_PUB.pmtTable.delivery_channel_code(l_trx_pmt_index) := NULL;
26989              IBY_PAYGROUP_PUB.pmtTable.ext_payee_id(l_trx_pmt_index) := NULL;
26990              IBY_PAYGROUP_PUB.pmtTable.payment_instruction_id(l_trx_pmt_index) := NULL;
26991              IBY_PAYGROUP_PUB.pmtTable.payment_profile_id(l_trx_pmt_index) := NULL;
26992              IBY_PAYGROUP_PUB.pmtTable.pregrouped_payment_flag(l_trx_pmt_index) := 'N';
26993              IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_flag(l_trx_pmt_index)            := 'N';
26994 	     IBY_PAYGROUP_PUB.pmtTable.stop_released_flag(l_trx_pmt_index)             := 'N';
26995 	     IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_flag(l_trx_pmt_index)       := 'N';
26996              IBY_PAYGROUP_PUB.pmtTable.created_by(l_trx_pmt_index)                     := fnd_global.user_id;
26997              IBY_PAYGROUP_PUB.pmtTable.creation_date(l_trx_pmt_index)                  := sysdate;
26998              IBY_PAYGROUP_PUB.pmtTable.last_updated_by(l_trx_pmt_index)                := fnd_global.user_id;
26999              IBY_PAYGROUP_PUB.pmtTable.last_update_login(l_trx_pmt_index)              := fnd_global.user_id;
27000              IBY_PAYGROUP_PUB.pmtTable.last_update_date(l_trx_pmt_index)               := sysdate;
27001              IBY_PAYGROUP_PUB.pmtTable.object_version_number(l_trx_pmt_index)          := 1;
27002              IBY_PAYGROUP_PUB.pmtTable.payee_party_id(l_trx_pmt_index) := NULL;
27003              IBY_PAYGROUP_PUB.pmtTable.party_site_id(l_trx_pmt_index) := NULL;
27004              IBY_PAYGROUP_PUB.pmtTable.supplier_site_id(l_trx_pmt_index) := NULL;
27005              IBY_PAYGROUP_PUB.pmtTable.payment_reason_code(l_trx_pmt_index) := NULL;
27006              IBY_PAYGROUP_PUB.pmtTable.payment_reason_comments(l_trx_pmt_index) := NULL;
27007              IBY_PAYGROUP_PUB.pmtTable.payment_date(l_trx_pmt_index) := NULL;
27008              IBY_PAYGROUP_PUB.pmtTable.anticipated_value_date(l_trx_pmt_index) := NULL;
27009              IBY_PAYGROUP_PUB.pmtTable.declaration_amount(l_trx_pmt_index) := NULL;
27010              IBY_PAYGROUP_PUB.pmtTable.declaration_currency_code(l_trx_pmt_index) := NULL;
27011              IBY_PAYGROUP_PUB.pmtTable.discount_amount_taken(l_trx_pmt_index) := NULL;
27012              IBY_PAYGROUP_PUB.pmtTable.payment_details(l_trx_pmt_index) := NULL;
27013              IBY_PAYGROUP_PUB.pmtTable.bank_charge_bearer(l_trx_pmt_index) := NULL;
27014              IBY_PAYGROUP_PUB.pmtTable.bank_charge_amount(l_trx_pmt_index) := NULL;
27015              IBY_PAYGROUP_PUB.pmtTable.settlement_priority(l_trx_pmt_index) := NULL;
27016              IBY_PAYGROUP_PUB.pmtTable.remittance_message1(l_trx_pmt_index) := NULL;
27017              IBY_PAYGROUP_PUB.pmtTable.remittance_message2(l_trx_pmt_index) := NULL;
27018              IBY_PAYGROUP_PUB.pmtTable.remittance_message3(l_trx_pmt_index) := NULL;
27019              IBY_PAYGROUP_PUB.pmtTable.payment_reference_number(l_trx_pmt_index) := NULL;
27020              IBY_PAYGROUP_PUB.pmtTable.paper_document_number(l_trx_pmt_index) := NULL;
27021              IBY_PAYGROUP_PUB.pmtTable.bank_assigned_ref_code(l_trx_pmt_index) := NULL;
27022              IBY_PAYGROUP_PUB.pmtTable.external_bank_account_id(l_trx_pmt_index) := NULL;
27023              IBY_PAYGROUP_PUB.pmtTable.unique_remittance_identifier(l_trx_pmt_index) := NULL;
27024              IBY_PAYGROUP_PUB.pmtTable.uri_check_digit(l_trx_pmt_index) := NULL;
27025              IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_code(l_trx_pmt_index) := NULL;
27026              IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_code(l_trx_pmt_index) := NULL;
27027              IBY_PAYGROUP_PUB.pmtTable.bank_instruction_details(l_trx_pmt_index) := NULL;
27028              IBY_PAYGROUP_PUB.pmtTable.payment_text_message1(l_trx_pmt_index) := NULL;
27029              IBY_PAYGROUP_PUB.pmtTable.payment_text_message2(l_trx_pmt_index) := NULL;
27030              IBY_PAYGROUP_PUB.pmtTable.payment_text_message3(l_trx_pmt_index) := NULL;
27031              IBY_PAYGROUP_PUB.pmtTable.maturity_date(l_trx_pmt_index) := NULL;
27032              IBY_PAYGROUP_PUB.pmtTable.payment_due_date(l_trx_pmt_index) := NULL;
27033              IBY_PAYGROUP_PUB.pmtTable.document_category_code(l_trx_pmt_index) := NULL;
27034              IBY_PAYGROUP_PUB.pmtTable.document_sequence_id(l_trx_pmt_index) := NULL;
27035              IBY_PAYGROUP_PUB.pmtTable.document_sequence_value(l_trx_pmt_index) := NULL;
27036              IBY_PAYGROUP_PUB.pmtTable.beneficiary_party(l_trx_pmt_index) := NULL;
27037              IBY_PAYGROUP_PUB.pmtTable.stop_confirmed_by(l_trx_pmt_index) := NULL;
27038              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_date(l_trx_pmt_index) := NULL;
27039              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reason(l_trx_pmt_index) := NULL;
27040              IBY_PAYGROUP_PUB.pmtTable.stop_confirm_reference(l_trx_pmt_index) := NULL;
27041              IBY_PAYGROUP_PUB.pmtTable.stop_released_by(l_trx_pmt_index) := NULL;
27042              IBY_PAYGROUP_PUB.pmtTable.stop_release_date(l_trx_pmt_index) := NULL;
27043              IBY_PAYGROUP_PUB.pmtTable.stop_release_reason(l_trx_pmt_index) := NULL;
27044              IBY_PAYGROUP_PUB.pmtTable.stop_release_reference(l_trx_pmt_index) := NULL;
27045              IBY_PAYGROUP_PUB.pmtTable.stop_request_date(l_trx_pmt_index) := NULL;
27046              IBY_PAYGROUP_PUB.pmtTable.stop_request_placed_by(l_trx_pmt_index) := NULL;
27047              IBY_PAYGROUP_PUB.pmtTable.stop_request_reason(l_trx_pmt_index) := NULL;
27048              IBY_PAYGROUP_PUB.pmtTable.stop_request_reference(l_trx_pmt_index) := NULL;
27049              IBY_PAYGROUP_PUB.pmtTable.voided_by(l_trx_pmt_index) := NULL;
27050              IBY_PAYGROUP_PUB.pmtTable.void_date(l_trx_pmt_index) := NULL;
27051              IBY_PAYGROUP_PUB.pmtTable.void_reason(l_trx_pmt_index) := NULL;
27052              IBY_PAYGROUP_PUB.pmtTable.remit_to_location_id(l_trx_pmt_index) := NULL;
27053              IBY_PAYGROUP_PUB.pmtTable.completed_pmts_group_id(l_trx_pmt_index) := NULL;
27054              IBY_PAYGROUP_PUB.pmtTable.attribute_category(l_trx_pmt_index) := NULL;
27055              IBY_PAYGROUP_PUB.pmtTable.attribute1(l_trx_pmt_index) := NULL;
27056              IBY_PAYGROUP_PUB.pmtTable.attribute2(l_trx_pmt_index) := NULL;
27057              IBY_PAYGROUP_PUB.pmtTable.attribute3(l_trx_pmt_index) := NULL;
27058              IBY_PAYGROUP_PUB.pmtTable.attribute4(l_trx_pmt_index) := NULL;
27059              IBY_PAYGROUP_PUB.pmtTable.attribute5(l_trx_pmt_index) := NULL;
27060              IBY_PAYGROUP_PUB.pmtTable.attribute6(l_trx_pmt_index) := NULL;
27061              IBY_PAYGROUP_PUB.pmtTable.attribute7(l_trx_pmt_index) := NULL;
27062              IBY_PAYGROUP_PUB.pmtTable.attribute8(l_trx_pmt_index) := NULL;
27063              IBY_PAYGROUP_PUB.pmtTable.attribute9(l_trx_pmt_index) := NULL;
27064              IBY_PAYGROUP_PUB.pmtTable.attribute10(l_trx_pmt_index) := NULL;
27065              IBY_PAYGROUP_PUB.pmtTable.attribute11(l_trx_pmt_index) := NULL;
27066              IBY_PAYGROUP_PUB.pmtTable.attribute12(l_trx_pmt_index) := NULL;
27067              IBY_PAYGROUP_PUB.pmtTable.attribute13(l_trx_pmt_index) := NULL;
27068              IBY_PAYGROUP_PUB.pmtTable.attribute14(l_trx_pmt_index) := NULL;
27069              IBY_PAYGROUP_PUB.pmtTable.attribute15(l_trx_pmt_index) := NULL;
27070              IBY_PAYGROUP_PUB.pmtTable.ext_branch_number(l_trx_pmt_index) := NULL;
27071              IBY_PAYGROUP_PUB.pmtTable.ext_bank_number(l_trx_pmt_index) := NULL;
27072              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_name(l_trx_pmt_index) := NULL;
27073              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_number(l_trx_pmt_index) := NULL;
27074              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_type(l_trx_pmt_index) := NULL;
27075              IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_iban_number(l_trx_pmt_index) := NULL;
27076              IBY_PAYGROUP_PUB.pmtTable.payee_name(l_trx_pmt_index) := NULL;
27077              IBY_PAYGROUP_PUB.pmtTable.payee_address1(l_trx_pmt_index) := NULL;
27078              IBY_PAYGROUP_PUB.pmtTable.payee_address2(l_trx_pmt_index) := NULL;
27079              IBY_PAYGROUP_PUB.pmtTable.payee_address3(l_trx_pmt_index) := NULL;
27080              IBY_PAYGROUP_PUB.pmtTable.payee_address4(l_trx_pmt_index) := NULL;
27081              IBY_PAYGROUP_PUB.pmtTable.payee_city(l_trx_pmt_index) := NULL;
27082              IBY_PAYGROUP_PUB.pmtTable.payee_postal_code(l_trx_pmt_index) := NULL;
27083              IBY_PAYGROUP_PUB.pmtTable.payee_state(l_trx_pmt_index) := NULL;
27084              IBY_PAYGROUP_PUB.pmtTable.payee_province(l_trx_pmt_index) := NULL;
27085              IBY_PAYGROUP_PUB.pmtTable.payee_county(l_trx_pmt_index) := NULL;
27086              IBY_PAYGROUP_PUB.pmtTable.payee_country(l_trx_pmt_index) := NULL;
27087              IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(l_trx_pmt_index) := NULL;
27088              IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(l_trx_pmt_index) := NULL;
27089              IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(l_trx_pmt_index) := NULL;
27090              IBY_PAYGROUP_PUB.pmtTable.address_source(l_trx_pmt_index) := NULL;
27091              IBY_PAYGROUP_PUB.pmtTable.employee_address_code(l_trx_pmt_index) := NULL;
27092              IBY_PAYGROUP_PUB.pmtTable.employee_person_id(l_trx_pmt_index) := NULL;
27093              IBY_PAYGROUP_PUB.pmtTable.employee_address_id(l_trx_pmt_index) := NULL;
27094              IBY_PAYGROUP_PUB.pmtTable.employee_payment_flag(l_trx_pmt_index) := 'N';
27095 	     	IBY_PAYGROUP_PUB.pmtTable.ext_inv_payee_id(l_trx_pmt_index) := NULL;
27096 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_id(l_trx_pmt_index) := NULL;
27097 		IBY_PAYGROUP_PUB.pmtTable.inv_party_site_id(l_trx_pmt_index) := NULL;
27098 		IBY_PAYGROUP_PUB.pmtTable.inv_supplier_site_id(l_trx_pmt_index) := NULL;
27099 		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_party(l_trx_pmt_index) := NULL;
27100 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_name(l_trx_pmt_index) := NULL;
27101 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address1(l_trx_pmt_index) := NULL;
27102 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address2(l_trx_pmt_index) := NULL;
27103 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address3(l_trx_pmt_index) := NULL;
27104 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address4(l_trx_pmt_index) := NULL;
27105 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_city(l_trx_pmt_index) := NULL;
27106 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_postal_code(l_trx_pmt_index) := NULL;
27107 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_state(l_trx_pmt_index) := NULL;
27108 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_province(l_trx_pmt_index) := NULL;
27109 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_county(l_trx_pmt_index) := NULL;
27110 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_country(l_trx_pmt_index) := NULL;
27111 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_name(l_trx_pmt_index) := NULL;
27112 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_le_reg_num(l_trx_pmt_index) := NULL;
27113 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_tax_reg_num(l_trx_pmt_index) := NULL;
27114 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_address_concat(l_trx_pmt_index) := NULL;
27115 		IBY_PAYGROUP_PUB.pmtTable.inv_beneficiary_name(l_trx_pmt_index) := NULL;
27116 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_number(l_trx_pmt_index) := NULL;
27117 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_alternate_name(l_trx_pmt_index) := NULL;
27118 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_site_alt_name(l_trx_pmt_index) := NULL;
27119 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_number(l_trx_pmt_index) := NULL;
27120 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_first_party_ref(l_trx_pmt_index) := NULL;
27121 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_id(l_trx_pmt_index) := NULL;
27122 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_branch_inv_prty_id(l_trx_pmt_index) := NULL;
27123 		IBY_PAYGROUP_PUB.pmtTable.ext_bnk_acct_ownr_inv_prty_nme(l_trx_pmt_index) := NULL;
27124 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_party_attr_cat(l_trx_pmt_index) := NULL;
27125 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_attr_cat(l_trx_pmt_index) := NULL;
27126 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_attr_cat(l_trx_pmt_index) := NULL;
27127 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_site_name(l_trx_pmt_index) := NULL;
27128 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_spplr_site_alt_name(l_trx_pmt_index) := NULL;
27129 		IBY_PAYGROUP_PUB.pmtTable.inv_payee_supplier_id(l_trx_pmt_index) := NULL;
27130         		-- start of auditPaymentdata fields
27131         IBY_PAYGROUP_PUB.pmtTable.payer_party_number(l_trx_pmt_index) := NULL;
27132 	IBY_PAYGROUP_PUB.pmtTable.payer_party_site_name(l_trx_pmt_index) := NULL;
27133 	IBY_PAYGROUP_PUB.pmtTable.payer_legal_entity_name(l_trx_pmt_index) := NULL;
27134 	IBY_PAYGROUP_PUB.pmtTable.payer_tax_registration_num(l_trx_pmt_index) := NULL;
27135 	IBY_PAYGROUP_PUB.pmtTable.payer_le_registration_num(l_trx_pmt_index) := NULL;
27136 	IBY_PAYGROUP_PUB.pmtTable.payer_party_id(l_trx_pmt_index) := NULL;
27137 	IBY_PAYGROUP_PUB.pmtTable.payer_location_id(l_trx_pmt_index) := NULL;
27138 	IBY_PAYGROUP_PUB.pmtTable.payer_party_attr_category(l_trx_pmt_index) := NULL;
27139 	IBY_PAYGROUP_PUB.pmtTable.payer_le_attr_category(l_trx_pmt_index) := NULL;
27140 	IBY_PAYGROUP_PUB.pmtTable.payer_abbreviated_agency_code(l_trx_pmt_index) := NULL;
27141 	IBY_PAYGROUP_PUB.pmtTable.payer_federal_us_employer_id(l_trx_pmt_index) := NULL;
27142 	IBY_PAYGROUP_PUB.pmtTable.int_bank_name(l_trx_pmt_index) := NULL;
27143 	IBY_PAYGROUP_PUB.pmtTable.int_bank_number(l_trx_pmt_index) := NULL;
27144 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_number(l_trx_pmt_index) := NULL;
27145 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_name(l_trx_pmt_index) := NULL;
27146 	IBY_PAYGROUP_PUB.pmtTable.int_eft_swift_code(l_trx_pmt_index) := NULL;
27147 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_number(l_trx_pmt_index) := NULL;
27148 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_name(l_trx_pmt_index) := NULL;
27149 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_iban(l_trx_pmt_index) := NULL;
27150 	IBY_PAYGROUP_PUB.pmtTable.int_bank_acct_agency_loc_code(l_trx_pmt_index) := NULL;
27151 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_party_id(l_trx_pmt_index) := NULL;
27152 	IBY_PAYGROUP_PUB.pmtTable.int_bank_alt_name(l_trx_pmt_index) := NULL;
27153 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_alt_name(l_trx_pmt_index) := NULL;
27154 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_alt_name(l_trx_pmt_index) := NULL;
27155 	IBY_PAYGROUP_PUB.pmtTable.int_bank_account_num_elec(l_trx_pmt_index) := NULL;
27156 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_location_id(l_trx_pmt_index) := NULL;
27157 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_eft_user_num(l_trx_pmt_index) := NULL;
27158 	IBY_PAYGROUP_PUB.pmtTable.payee_party_number(l_trx_pmt_index) := NULL;
27159 	IBY_PAYGROUP_PUB.pmtTable.payee_party_name(l_trx_pmt_index) := NULL;
27160 	IBY_PAYGROUP_PUB.pmtTable.payee_alt_name(l_trx_pmt_index) := NULL;  -- Bug 6175102
27161 	IBY_PAYGROUP_PUB.pmtTable.payee_address_concat(l_trx_pmt_index) := NULL;
27162 	IBY_PAYGROUP_PUB.pmtTable.beneficiary_name(l_trx_pmt_index) := NULL;
27163 	IBY_PAYGROUP_PUB.pmtTable.payee_party_atr_cat(l_trx_pmt_index) := NULL;
27164 	IBY_PAYGROUP_PUB.pmtTable.payee_spplr_site_attr_category(l_trx_pmt_index) := NULL;
27165 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_site_name(l_trx_pmt_index) := NULL;
27166 	IBY_PAYGROUP_PUB.pmtTable.payee_party_site_name(l_trx_pmt_index) := NULL;
27167 	IBY_PAYGROUP_PUB.pmtTable.payee_addressee(l_trx_pmt_index) := NULL;
27168 	IBY_PAYGROUP_PUB.pmtTable.payee_site_alternate_name(l_trx_pmt_index) := NULL;
27169 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_number(l_trx_pmt_index) := NULL;
27170 	IBY_PAYGROUP_PUB.pmtTable.payee_first_party_reference(l_trx_pmt_index) := NULL;
27171 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_attr_category(l_trx_pmt_index) := NULL;
27172 	IBY_PAYGROUP_PUB.pmtTable.payee_supplier_id(l_trx_pmt_index) := NULL;
27173 	IBY_PAYGROUP_PUB.pmtTable.payee_tax_registration_num(l_trx_pmt_index) := NULL;
27174 	IBY_PAYGROUP_PUB.pmtTable.payee_le_registration_num(l_trx_pmt_index) := NULL;
27175 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_name(l_trx_pmt_index) := NULL;
27176 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_name(l_trx_pmt_index) := NULL;
27177 	IBY_PAYGROUP_PUB.pmtTable.ext_eft_swift_code(l_trx_pmt_index) := NULL;
27178 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_pmt_factor_flag(l_trx_pmt_index) := 'N';
27179 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_id(l_trx_pmt_index) := NULL;
27180 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_party_id(l_trx_pmt_index) := NULL;
27181 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_alt_name(l_trx_pmt_index) := NULL;
27182 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_alt_name(l_trx_pmt_index) := NULL;
27183 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_alt_name(l_trx_pmt_index) := NULL;
27184 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_account_num_elec(l_trx_pmt_index) := NULL;
27185 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_branch_location_id(l_trx_pmt_index) := NULL;
27186 	IBY_PAYGROUP_PUB.pmtTable.ext_bank_acct_owner_party_name(l_trx_pmt_index) := NULL;
27187 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_delivery_method(l_trx_pmt_index) := NULL;
27188 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_email(l_trx_pmt_index) := NULL;
27189 	--IBY_PAYGROUP_PUB.pmtTable.remit_advice_fax(l_trx_pmt_index) := NULL;
27190 	IBY_PAYGROUP_PUB.pmtTable.delivery_channel_format_value(l_trx_pmt_index) := NULL;
27191 	IBY_PAYGROUP_PUB.pmtTable.declaration_exch_rate_type(l_trx_pmt_index) := NULL;
27192 	IBY_PAYGROUP_PUB.pmtTable.declaration_format(l_trx_pmt_index) := NULL;
27193 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_acct_name(l_trx_pmt_index) := NULL;
27194 	IBY_PAYGROUP_PUB.pmtTable.payment_profile_sys_name(l_trx_pmt_index) := NULL;
27195 	IBY_PAYGROUP_PUB.pmtTable.payment_reason_format_value(l_trx_pmt_index) := NULL;
27196 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction1_format_value(l_trx_pmt_index) := NULL;
27197 	IBY_PAYGROUP_PUB.pmtTable.bank_instruction2_format_value(l_trx_pmt_index) := NULL;
27198 	IBY_PAYGROUP_PUB.pmtTable.org_name(l_trx_pmt_index) := NULL;
27199 	IBY_PAYGROUP_PUB.pmtTable.int_bank_branch_rfc_identifier(l_trx_pmt_index) := NULL;
27200 	IBY_PAYGROUP_PUB.pmtTable.payment_process_request_name(l_trx_pmt_index) := NULL;
27201 	IBY_PAYGROUP_PUB.pmtTable.source_product(l_trx_pmt_index) := NULL;
27202 	IBY_PAYGROUP_PUB.pmtTable.affects_rejection_level(l_trx_pmt_index) := NULL; -- AWT Enh 16296267
27203 
27204     IF (l_default_debug_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
27205       print_debuginfo(l_module_name, 'EXIT');
27206     END IF;
27207 
27208  END initialize_pmt_table;
27209 
27210 
27211 END IBY_PAYGROUP_PUB;