[Home] [Help]
PACKAGE BODY: APPS.POS_BATCH_IMPORT_PKG
Source
1 PACKAGE BODY POS_BATCH_IMPORT_PKG AS
2 /* $Header: POSSUPIMPB.pls 120.10.12020000.4 2013/04/10 18:26:05 jinlong ship $ */
3
4 g_current_runtime_level CONSTANT NUMBER := fnd_log.g_current_runtime_level;
5 g_level_procedure CONSTANT NUMBER := fnd_log.level_procedure;
6 g_module_name CONSTANT VARCHAR2(100) := 'AP.PLSQL.POS_BATCH_IMPORT_PKG';
7
8 g_source VARCHAR2(30) := 'IMPORT';
9 g_user_id NUMBER(15) := fnd_global.user_id;
10 g_login_id NUMBER(15) := fnd_global.login_id;
11
12 l_error_msg_tbl error_handler.error_tbl_type;
13
14 --Function: Insert_Rejections
15 --This function is called whenever the process needs to insert a
16 --rejection into new supplier interface rejection table.
17
18 FUNCTION insert_rejections
19 (
20 p_batch_id IN NUMBER,
21 p_import_request_id IN NUMBER,
22 p_parent_table IN VARCHAR2,
23 p_parent_id IN NUMBER,
24 p_reject_code IN VARCHAR2,
25 p_last_updated_by IN NUMBER,
26 p_last_update_login IN NUMBER,
27 p_calling_sequence IN VARCHAR2
28 ) RETURN BOOLEAN IS
29
30 l_current_calling_sequence VARCHAR2(2000);
31 l_debug_info VARCHAR2(500);
32 l_api_name CONSTANT VARCHAR2(100) := 'INSERT_REJECTIONS';
33
34 BEGIN
35 -- Update the calling sequence
36 l_current_calling_sequence := 'POS_BATCH_IMPORT_PKG.Insert_rejections<-' ||
37 p_calling_sequence;
38
39 IF (g_level_procedure >= g_current_runtime_level) THEN
40 fnd_log.string(g_level_procedure,
41 g_module_name || l_api_name,
42 'Parameters: ' || ' p_parent_table: ' ||
43 p_parent_table || ', p_parent_id: ' ||
44 to_char(p_parent_id) || ', p_reject_code: ' ||
45 p_reject_code);
46 END IF;
47
48 INSERT INTO pos_supplier_int_rejections
49 (batch_id,
50 import_request_id,
51 parent_table,
52 parent_id,
53 reject_lookup_code,
54 last_updated_by,
55 last_update_date,
56 last_update_login,
57 created_by,
58 creation_date)
59 VALUES
60 (p_batch_id,
61 p_import_request_id,
62 p_parent_table,
63 p_parent_id,
64 p_reject_code,
65 p_last_updated_by,
66 SYSDATE,
67 p_last_update_login,
68 p_last_updated_by,
69 SYSDATE);
70
71 RETURN(TRUE);
72
73 EXCEPTION
74 WHEN OTHERS THEN
75 IF (SQLCODE <> -20001) THEN
76 fnd_message.set_name('SQLAP', 'AP_DEBUG');
77 fnd_message.set_token('ERROR', SQLERRM);
78 fnd_message.set_token('CALLING_SEQUENCE',
79 l_current_calling_sequence);
80 fnd_message.set_token('DEBUG_INFO', l_debug_info);
81 END IF;
82
83 IF (g_level_procedure >= g_current_runtime_level) THEN
84 fnd_log.string(g_level_procedure,
85 g_module_name || l_api_name,
86 SQLERRM);
87 END IF;
88
89 fnd_file.put_line(fnd_file.log,
90 ' Inside INSERT_REJECTIONS EXCEPTION ' ||
91 ' Message: ' || SQLCODE || ' ' || SQLERRM);
92
93 RETURN(FALSE);
94
95 END insert_rejections;
96
97 -- Function to get the Party Id based on
98 -- the Source System information passed to it
99 --
100 FUNCTION get_party_id
101 (
102 p_orig_system IN VARCHAR2,
103 p_orig_system_reference IN VARCHAR2
104 ) RETURN NUMBER AS
105 l_party_id NUMBER;
106 BEGIN
107 SELECT owner_table_id
108 INTO l_party_id
109 FROM hz_orig_sys_references hr
110 WHERE hr.owner_table_name = 'HZ_PARTIES'
111 AND hr.orig_system = p_orig_system
112 AND hr.orig_system_reference = p_orig_system_reference
113 AND hr.status = 'A'
114 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE;
115
116 RETURN l_party_id;
117
118 EXCEPTION
119 WHEN OTHERS THEN
120 fnd_file.put_line(fnd_file.log,
121 ' Inside get_party_id EXCEPTION ' || ' Message: ' ||
122 SQLCODE || ' ' || SQLERRM);
123 RETURN 0;
124 END get_party_id;
125
126 PROCEDURE check_party_exist
127 (
128 p_batch_id IN NUMBER,
129 x_return_status OUT NOCOPY VARCHAR2,
130 x_msg_count OUT NOCOPY NUMBER,
131 x_msg_data OUT NOCOPY VARCHAR2
132 ) IS
133 l_insert_count NUMBER(10);
134
135 BEGIN
136 -- Initialize API return status to success
137 x_return_status := fnd_api.g_ret_sts_success;
138
139 -- Check if party is present for the perticular batch id,
140 -- source id, source reference in cross reference table and update the ap_suppliers_int table
141 UPDATE ap_suppliers_int supp
142 SET party_id =
143 (SELECT party_id
144 FROM hz_orig_sys_references hr
145 WHERE hr.owner_table_name = 'HZ_PARTIES'
146 AND hr.orig_system = supp.party_orig_system
147 AND hr.orig_system_reference =
148 supp.party_orig_system_reference
149 AND hr.status = 'A'
150 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE)
151 WHERE party_id IS NULL
152 AND sdh_batch_id = p_batch_id
153 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
154
155 -- If the party record is not present insert data into
156 -- HZ_IMP_PARTIES_INT table using AP_SUPPLIERS_INT.
157 INSERT INTO hz_imp_parties_int
158 (batch_id,
159 party_orig_system,
160 party_orig_system_reference,
161 created_by_module,
162 --application_id,
163 party_type,
164 organization_name,
165 organization_name_phonetic,
166 jgzz_fiscal_code,
167 tax_reference,
168 ceo_name,
169 ceo_title)
170 SELECT sdh_batch_id,
171 party_orig_system,
172 party_orig_system_reference,
173 'AP_SUPPLIERS_API',
174 --200,
175 'ORGANIZATION',
176 vendor_name,
177 vendor_name_alt,
178 num_1099,
179 vat_registration_num,
180 ceo_name,
181 ceo_title
182 FROM ap_suppliers_int supp
183 WHERE /* party_id IS NULL AND */
184 sdh_batch_id = p_batch_id
185 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
186 AND NOT EXISTS (SELECT *
187 FROM hz_imp_parties_int hp
188 WHERE hp.batch_id = supp.sdh_batch_id
189 AND hp.party_orig_system = supp.party_orig_system
190 AND hp.party_orig_system_reference =
191 supp.party_orig_system_reference);
192
193 l_insert_count := SQL%ROWCOUNT;
194
195 fnd_file.put_line(fnd_file.log,
196 ' Message: Inside PROCEDURE check_party_exist' ||
197 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
198 ' Rows inserted in hz_imp_parties_int: ' ||
199 l_insert_count);
200
201 IF (l_insert_count > 0) THEN
202 -- Update hz_imp_batch_summary with the count of the records inserted into interface table.
203 UPDATE hz_imp_batch_summary
204 SET total_batch_records = total_batch_records + l_insert_count,
205 total_records_for_import = total_records_for_import +
206 l_insert_count,
207 parties_in_batch = parties_in_batch + l_insert_count
208 WHERE batch_id = p_batch_id;
209 END IF;
210
211 EXCEPTION
212 WHEN OTHERS THEN
213 x_return_status := fnd_api.g_ret_sts_unexp_error;
214 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
215 fnd_msg_pub.add;
216 fnd_msg_pub.count_and_get(p_count => x_msg_count,
217 p_data => x_msg_data);
218 fnd_file.put_line(fnd_file.log,
219 ' Inside check_party_exist EXCEPTION ' ||
220 ' Message: ' || SQLCODE || ' ' || SQLERRM);
221 END check_party_exist;
222
223 PROCEDURE check_party_site_exist
224 (
225 p_batch_id IN NUMBER,
226 x_return_status OUT NOCOPY VARCHAR2,
227 x_msg_count OUT NOCOPY NUMBER,
228 x_msg_data OUT NOCOPY VARCHAR2
229 ) IS
230 l_insert_count NUMBER(10);
231
232 BEGIN
233 -- Initialize API return status to success
234 x_return_status := fnd_api.g_ret_sts_success;
235
236 -- Check for the existence of the site and location from the hz cross ref table
237 -- and update the ap_supplier_sites_in table using below query
238
239 UPDATE ap_supplier_sites_int supp
240 SET party_site_id =
241 (SELECT owner_table_id
242 FROM hz_orig_sys_references hr
243 WHERE hr.owner_table_name = 'HZ_PARTY_SITES'
244 AND hr.party_id = supp.party_id -- Bug 14772702: Same site orig reference can exist under different suppliers
245 AND hr.orig_system = supp.party_site_orig_system
246 AND hr.orig_system_reference =
247 supp.party_site_orig_sys_reference
248 AND hr.status = 'A'
249 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE)
250 WHERE party_site_id IS NULL
251 AND sdh_batch_id = p_batch_id
252 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
253
254 --Bug 13086851 language code issue: The input language that we get from ap_supplier_sites_int will be NLS_LANGUAGE(varchar 30)
255 --and will not be language code((varchar 4). So it needs to be converted to language_code before inserting to hz_imp_addresses_int .
256
257 --bug 12689121 missing address_line4, county, language during insert to interface
258
259 --Bug 14772702: party_id should be populated into hz_imp_address_int as it is part of unique index
260 --Same site orig reference can exist under different suppliers
261 INSERT INTO hz_imp_addresses_int
262 (batch_id,
263 party_orig_system,
264 party_orig_system_reference,
265 site_orig_system,
266 site_orig_system_reference,
267 party_site_name,
268 address1,
269 address_lines_phonetic,
270 address2,
271 address3,
272 address4,
273 city,
274 state,
275 country,
276 province,
277 county,
278 postal_code,
279 created_by,
280 creation_date,
281 last_updated_by,
282 last_update_date,
283 last_update_login,
284 language,
285 party_id,
286 correct_move_indicator) --BUG 16200981 Specify correct mode when doing update
287 SELECT sdh_batch_id,
288 party_orig_system,
289 party_orig_system_reference,
290 party_site_orig_system,
291 party_site_orig_sys_reference,
292 NVL(party_site_name, vendor_site_code), -- Bug 14088081: should populate party_site_name to TCA table as we already have such column.
293 address_line1,
294 address_lines_alt,
295 address_line2,
296 address_line3,
297 address_line4,
298 city,
299 state,
300 country,
301 province,
302 county,
303 zip,
304 created_by,
305 creation_date,
306 last_updated_by,
307 last_update_date,
308 last_update_login,
309 language_code,
310 party_id,
311 'C' --BUG 16200981 Specify correct mode when doing update
312 FROM (SELECT sdh_batch_id,
313 party_orig_system,
314 party_orig_system_reference,
315 party_site_orig_system,
316 party_site_orig_sys_reference,
317 /*nvl(party_site_orig_system, supplier_site_orig_system) party_site_orig_system,
318 nvl(party_site_orig_sys_reference,
319 sup_site_orig_system_reference) party_site_orig_sys_reference,*/
320 vendor_site_code,
321 party_site_name,
322 address_line1,
323 address_lines_alt,
324 address_line2,
325 address_line3,
326 address_line4,
327 city,
328 state,
329 country,
330 province,
331 county,
332 zip,
333 hz_utility_v2pub.created_by,
334 hz_utility_v2pub.creation_date,
335 hz_utility_v2pub.last_updated_by,
336 hz_utility_v2pub.last_update_date,
337 hz_utility_v2pub.last_update_login,
338 LANG.LANGUAGE_CODE,
339 party_id,
340 dense_rank() over(PARTITION BY sdh_batch_id, party_site_orig_system, party_site_orig_sys_reference, party_id ORDER BY SUPP.ROWID) rnk
341 FROM ap_supplier_sites_int supp, FND_LANGUAGES LANG
342 WHERE /* party_site_id IS NULL AND */
343 sdh_batch_id = p_batch_id AND supp.language = lang.nls_language(+)
344 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
345 AND NOT EXISTS
346 (SELECT *
347 FROM hz_imp_addresses_int hp
348 WHERE hp.batch_id = supp.sdh_batch_id
349 AND hp.party_orig_system = supp.party_orig_system
350 AND hp.party_orig_system_reference =
351 supp.party_orig_system_reference
352 AND hp.site_orig_system = supp.party_site_orig_system
353 AND hp.site_orig_system_reference =
354 supp.party_site_orig_sys_reference))
355 WHERE rnk = 1;
356
357 l_insert_count := SQL%ROWCOUNT;
358
359 fnd_file.put_line(fnd_file.log,
360 ' Message: Inside PROCEDURE check_party_site_exist' ||
361 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
362 ' Rows inserted in hz_imp_addresses_int: ' ||
363 l_insert_count);
364
365 IF (l_insert_count > 0) THEN
366 -- Update hz_imp_batch_summary with the count of the records inserted into interface table.
367 UPDATE hz_imp_batch_summary
368 SET total_batch_records = total_batch_records + l_insert_count,
369 total_records_for_import = total_records_for_import +
370 l_insert_count,
371 addresses_in_batch = addresses_in_batch + l_insert_count
372 WHERE batch_id = p_batch_id;
373 END IF;
374
375 EXCEPTION
376 WHEN OTHERS THEN
377 x_return_status := fnd_api.g_ret_sts_unexp_error;
378 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY_SITE');
379 fnd_msg_pub.add;
380 fnd_msg_pub.count_and_get(p_count => x_msg_count,
381 p_data => x_msg_data);
382 fnd_file.put_line(fnd_file.log,
383 ' Inside check_party_site_exist EXCEPTION ' ||
384 ' Message: ' || SQLCODE || ' ' || SQLERRM);
385 END check_party_site_exist;
386
387 PROCEDURE check_party_contact_exist
388 (
389 p_batch_id IN NUMBER,
390 x_return_status OUT NOCOPY VARCHAR2,
391 x_msg_count OUT NOCOPY NUMBER,
392 x_msg_data OUT NOCOPY VARCHAR2
393 ) IS
394 -- l_party_id NUMBER;
395 l_insert_count NUMBER;
396 BEGIN
397
398 -- Initialize API return status to success
399 x_return_status := fnd_api.g_ret_sts_success;
400
401 UPDATE ap_sup_site_contact_int supp
402 SET per_party_id =
403 (SELECT party_id
404 FROM hz_orig_sys_references hr
405 WHERE hr.owner_table_name = 'HZ_PARTIES'
406 AND hr.orig_system = supp.contact_orig_system
407 AND hr.orig_system_reference =
408 supp.contact_orig_system_reference
409 AND hr.status = 'A'
410 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE)
411 WHERE per_party_id IS NULL
412 AND sdh_batch_id = p_batch_id
413 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
414
415 -- If the party record is not present insert data into
416 -- HZ_IMP_PARTIES_INT table using AP_SUPPLIERS_INT.
417 INSERT INTO hz_imp_parties_int
418 (batch_id,
419 party_orig_system,
420 party_orig_system_reference,
421 created_by_module,
422 --application_id,
423 party_type,
424 organization_name,
425 organization_name_phonetic,
426 person_first_name,
427 person_last_name,
428 --Bug 13392627
429 person_middle_name,
430 person_pre_name_adjunct
431 --person_title
432 --jgzz_fiscal_code,
433 --tax_reference
434 )
435 SELECT sdh_batch_id,
436 contact_orig_system,
437 contact_orig_system_reference,
438 'AP_SUPPLIERS_API',
439 'PERSON',
440 org_name,
441 org_name_alt,
442 first_name,
443 last_name,
444 middle_name,
445 prefix
446 FROM (SELECT sdh_batch_id,
447 contact_orig_system,
448 contact_orig_system_reference,
449 'AP_SUPPLIERS_API',
450 --200,
451 'PERSON',
452 supp.first_name || ' ' || supp.last_name org_name,
453 supp.first_name_alt || ' ' || supp.last_name_alt org_name_alt,
454 supp.first_name,
455 supp.last_name,
456 supp.middle_name,
457 supp.prefix,
458 dense_rank() over(PARTITION BY sdh_batch_id, contact_orig_system, contact_orig_system_reference, party_id ORDER BY ROWID) rnk
459 --num_1099,
460 --vat_registration_num
461 FROM ap_sup_site_contact_int supp
462 WHERE /* per_party_id IS NULL AND */
463 sdh_batch_id = p_batch_id
464 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
465 AND NOT EXISTS
466 (SELECT *
467 FROM hz_imp_parties_int hp
468 WHERE hp.batch_id = supp.sdh_batch_id
469 AND hp.party_orig_system = supp.contact_orig_system
470 AND hp.party_orig_system_reference =
471 supp.contact_orig_system_reference))
472 WHERE rnk = 1;
473
474 l_insert_count := SQL%ROWCOUNT;
475
476 fnd_file.put_line(fnd_file.log,
477 ' Message: Inside PROCEDURE check_party_contact_exist' ||
478 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
479 ' Rows inserted in hz_imp_parties_int: ' ||
480 l_insert_count);
481
482 IF (l_insert_count > 0) THEN
483 -- Update hz_imp_batch_summary with the count of the records inserted into interface table.
484 UPDATE hz_imp_batch_summary
485 SET total_batch_records = total_batch_records + l_insert_count,
486 total_records_for_import = total_records_for_import +
487 l_insert_count,
488 parties_in_batch = parties_in_batch + l_insert_count
489 WHERE batch_id = p_batch_id;
490 END IF;
491
492 l_insert_count := 0;
493
494 INSERT INTO hz_imp_contacts_int
495 (batch_id,
496 contact_orig_system,
497 contact_orig_system_reference,
498 sub_orig_system,
499 sub_orig_system_reference,
500 obj_orig_system,
501 obj_orig_system_reference,
502 start_date,
503 created_by_module,
504 contact_number,
505 relationship_type,
506 relationship_code,
507 creation_date,
508 insert_update_flag,
509 department, --Bug 13392627
510 JOB_TITLE
511 )
512
513 SELECT sdh_batch_id,
514 contact_orig_system,
515 contact_orig_system_reference,
516 contact_orig_system,
517 contact_orig_system_reference,
518 party_orig_system,
519 party_orig_system_reference,
520 SYSDATE,
521 'AP_SUPPLIERS_API',
522 supp.first_name || ' ' || supp.last_name,
523 'CONTACT',
524 'CONTACT_OF',
525 SYSDATE,
526 'I',
527 department,
528 title
529 FROM ap_sup_site_contact_int supp
530 WHERE per_party_id IS NULL
531 AND sdh_batch_id = p_batch_id
532 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
533 AND NOT EXISTS
534 (SELECT *
535 FROM hz_imp_contacts_int hp
536 WHERE hp.batch_id = supp.sdh_batch_id
537 AND hp.contact_orig_system = supp.contact_orig_system
538 AND hp.contact_orig_system_reference =
539 supp.contact_orig_system_reference)
540 UNION
541 SELECT sdh_batch_id,
542 contact_orig_system,
543 contact_orig_system_reference,
544 contact_orig_system,
545 contact_orig_system_reference,
546 party_orig_system,
547 party_orig_system_reference,
548 SYSDATE,
549 'AP_SUPPLIERS_API',
550 supp.first_name || ' ' || supp.last_name,
551 'CONTACT',
552 'CONTACT_OF',
553 SYSDATE,
554 'U',
555 department,
556 title
557 FROM ap_sup_site_contact_int supp
558 WHERE per_party_id IS NOT NULL
559 AND sdh_batch_id = p_batch_id
560 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
561 AND NOT EXISTS
562 (SELECT *
563 FROM hz_imp_contacts_int hp
564 WHERE hp.batch_id = supp.sdh_batch_id
565 AND hp.contact_orig_system = supp.contact_orig_system
566 AND hp.contact_orig_system_reference =
567 supp.contact_orig_system_reference);
568
569 l_insert_count := SQL%ROWCOUNT;
570
571 fnd_file.put_line(fnd_file.log,
572 ' Message: Inside PROCEDURE check_party_contact_exist' ||
573 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
574 ' Rows inserted in hz_imp_contacts_int: ' ||
575 l_insert_count);
576
577 IF (l_insert_count > 0) THEN
578 -- Update hz_imp_batch_summary with the count of the records inserted into interface table.
579 UPDATE hz_imp_batch_summary
580 SET total_batch_records = total_batch_records + l_insert_count,
581 total_records_for_import = total_records_for_import +
582 l_insert_count,
583 contacts_in_batch = contacts_in_batch + l_insert_count
584 WHERE batch_id = p_batch_id;
585 END IF;
586
587 EXCEPTION
588 WHEN OTHERS THEN
589 x_return_status := fnd_api.g_ret_sts_unexp_error;
590
591 fnd_msg_pub.count_and_get(p_count => x_msg_count,
592 p_data => x_msg_data);
593
594 fnd_file.put_line(fnd_file.log,
595 ' Inside check_party_contact_exist EXCEPTION ' ||
596 ' Message: ' || SQLCODE || ' ' || SQLERRM);
597 END check_party_contact_exist;
598
599 PROCEDURE validate_vendor
600 (
601 p_batch_id IN NUMBER,
602 x_return_status OUT NOCOPY VARCHAR2,
603 x_msg_count OUT NOCOPY NUMBER,
604 x_msg_data OUT NOCOPY VARCHAR2
605 ) IS
606 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_VENDOR';
607 l_request_id NUMBER := fnd_global.conc_request_id;
608
609 l_return_status VARCHAR2(2000);
610 l_msg_count NUMBER;
611 l_msg_data VARCHAR2(2000);
612 l_vendor_id NUMBER;
613 l_party_id NUMBER;
614 l_error_id NUMBER;
615
616 l_party_valid VARCHAR2(1);
617 l_payee_valid VARCHAR2(1);
618
619 vendor_rec ap_vendor_pub_pkg.r_vendor_rec_type;
620
621 CURSOR party_int_cur IS
622 SELECT ROWID,
623 organization_name,
624 organization_name_phonetic,
625 attribute_category,
626 attribute1,
627 attribute2,
628 attribute3,
629 attribute4,
630 attribute5,
631 attribute6,
632 attribute7,
633 attribute8,
634 attribute9,
635 attribute10,
636 attribute11,
637 attribute12,
638 attribute13,
639 attribute14,
640 attribute15,
641 party_id,
642 party_orig_system,
643 party_orig_system_reference,
644 insert_update_flag
645 FROM hz_imp_parties_int hp
646 WHERE batch_id = p_batch_id
647 /* Status for the data should not be E or C
648 i.e. Errored out or Completed */
649 AND interface_status IS NULL
650 AND party_type = 'ORGANIZATION'
651 AND NOT EXISTS
652 (SELECT *
653 FROM ap_suppliers_int supp
654 WHERE hp.batch_id = supp.sdh_batch_id
655 AND hp.party_orig_system = supp.party_orig_system
656 AND hp.party_orig_system_reference =
657 supp.party_orig_system_reference);
658
659 party_int_rec party_int_cur%ROWTYPE;
660
661 l_vendor_num_code financials_system_parameters.user_defined_vendor_num_code%TYPE;
662
663 CURSOR check_vendor_exsists(cp_party_id IN NUMBER) IS
664 SELECT 1,
665 vendor_id
666 FROM ap_suppliers
667 WHERE party_id = cp_party_id;
668
669 l_vendor_exists NUMBER := 0;
670 BEGIN
671 -- Initialize API return status to success
672 x_return_status := fnd_api.g_ret_sts_success;
673
674 DELETE ap_supplier_int_rejections
675 WHERE parent_table = 'AP_SUPPLIERS_INT';
676
677 fnd_file.put_line(fnd_file.log,
678 ' Validating vendor record before the party is created. ');
679 OPEN party_int_cur;
680
681 LOOP
682 FETCH party_int_cur
683 INTO party_int_rec;
684
685 EXIT WHEN party_int_cur%NOTFOUND;
686
687 vendor_rec.vendor_name := party_int_rec.organization_name;
688 vendor_rec.vendor_name_alt := party_int_rec.organization_name_phonetic;
689 vendor_rec.attribute_category := party_int_rec.attribute_category;
690 vendor_rec.attribute1 := party_int_rec.attribute1;
691 vendor_rec.attribute2 := party_int_rec.attribute2;
692 vendor_rec.attribute3 := party_int_rec.attribute3;
693 vendor_rec.attribute4 := party_int_rec.attribute4;
694 vendor_rec.attribute5 := party_int_rec.attribute5;
695 vendor_rec.attribute6 := party_int_rec.attribute6;
696 vendor_rec.attribute7 := party_int_rec.attribute7;
697 vendor_rec.attribute8 := party_int_rec.attribute8;
698 vendor_rec.attribute9 := party_int_rec.attribute9;
699 vendor_rec.attribute10 := party_int_rec.attribute10;
700 vendor_rec.attribute11 := party_int_rec.attribute11;
701 vendor_rec.attribute12 := party_int_rec.attribute12;
702 vendor_rec.attribute13 := party_int_rec.attribute13;
703 vendor_rec.attribute14 := party_int_rec.attribute14;
704 vendor_rec.attribute15 := party_int_rec.attribute15;
705
706 vendor_rec.ext_payee_rec.payment_function := 'PAYABLES_DISB';
707 vendor_rec.ext_payee_rec.payer_org_type := 'OPERATING_UNIT';
708
709 /* Get the party id for orig system and orig system reference combination */
710
711 vendor_rec.party_id := get_party_id(party_int_rec.party_orig_system,
712 party_int_rec.party_orig_system_reference);
713
714 IF (vendor_rec.party_id = 0) THEN
715 vendor_rec.party_id := NULL;
716 END IF;
717
718 fnd_file.put_line(fnd_file.log,
719 ' Message: Inside PROCEDURE validate_vendor' ||
720 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
721 ' Party id : ' || vendor_rec.party_id ||
722 ' from get_party_id');
723
724 -- Check if the Vendor number is AutoNumbered.
725 -- If the method is set to Manual then the vendor
726 -- number would be mapped to the Orig System reference.
727 --
728 l_vendor_num_code := chk_vendor_num_nmbering_method();
729
730 IF (l_vendor_num_code = 'MANUAL') THEN
731 vendor_rec.segment1 := party_int_rec.party_orig_system_reference;
732 END IF;
733
734 -- Setting the vendor source as IMPORT so that the
735 -- errors are logged in the rejections table
736 --
737 ap_vendor_pub_pkg.g_source := 'IMPORT';
738
739 -- Check if the vendor already exists
740 OPEN check_vendor_exsists(vendor_rec.party_id);
741 FETCH check_vendor_exsists
742 INTO l_vendor_exists,
743 l_vendor_id;
744 CLOSE check_vendor_exsists;
745
746 -- If the vendor exists then Sync it with the party information
747 IF l_vendor_exists <> 0 THEN
748 l_vendor_exists := 0;
749
750 /* Call validate vendor in update mode */
751 ap_vendor_pub_pkg.validate_vendor(p_api_version => 1.0,
752 p_init_msg_list => fnd_api.g_false,
753 p_commit => fnd_api.g_false,
754 x_return_status => l_return_status,
755 x_msg_count => l_msg_count,
756 x_msg_data => l_msg_data,
757 p_vendor_rec => vendor_rec,
758 p_mode => 'U',
759 p_calling_prog => 'NOT ISETUP',
760 x_party_valid => l_party_valid,
761 x_payee_valid => l_payee_valid,
762 p_vendor_id => l_vendor_id);
763 ELSE
764 /* Call validate vendor in insert mode */
765 ap_vendor_pub_pkg.validate_vendor(p_api_version => 1.0,
766 p_init_msg_list => fnd_api.g_false,
767 p_commit => fnd_api.g_false,
768 x_return_status => l_return_status,
769 x_msg_count => l_msg_count,
770 x_msg_data => l_msg_data,
771 p_vendor_rec => vendor_rec,
772 p_mode => 'I',
773 p_calling_prog => 'NOT ISETUP',
774 x_party_valid => l_party_valid,
775 x_payee_valid => l_payee_valid,
776 p_vendor_id => l_vendor_id);
777 END IF;
778
779 IF (l_return_status <> fnd_api.g_ret_sts_success /*OR l_party_valid <> 'Y'*/
780 ) THEN
781 INSERT INTO pos_supplier_int_rejections
782 (batch_id,
783 import_request_id,
784 parent_table,
785 parent_id,
786 reject_lookup_code,
787 last_updated_by,
788 last_update_date,
789 last_update_login,
790 created_by,
791 creation_date)
792 SELECT p_batch_id,
793 l_request_id,
794 parent_table,
795 parent_id,
796 reject_lookup_code,
797 last_updated_by,
798 last_update_date,
799 last_update_login,
800 created_by,
801 creation_date
802 FROM ap_supplier_int_rejections
803 WHERE parent_table = 'AP_SUPPLIERS_INT';
804
805 IF (g_level_procedure >= g_current_runtime_level) THEN
806 fnd_log.string(g_level_procedure,
807 g_module_name || l_api_name,
808 ' No. of Messages from validate_vendor API: ' ||
809 l_msg_count ||
810 ', Message From validate_vendor API: ' ||
811 l_msg_data);
812 END IF;
813
814 INSERT INTO hz_imp_errors
815 (creation_date,
816 created_by,
817 last_update_date,
818 last_updated_by,
819 last_update_login,
820 program_application_id,
821 program_id,
822 program_update_date,
823 error_id,
824 batch_id,
825 request_id,
826 interface_table_name,
827 message_name,
828 token1_name,
829 token1_value)
830 VALUES
831 (SYSDATE,
832 g_user_id,
833 SYSDATE,
834 g_user_id,
835 g_user_id,
836 NULL,
837 NULL,
838 SYSDATE,
839 hz_imp_errors_s.nextval,
840 p_batch_id,
841 NULL,
842 'HZ_IMP_PARTIES_INT',
843 'AR_ALL_DUP_NAME',
844 'ORGANIZATION_NAME',
845 party_int_rec.organization_name)
846 RETURNING error_id INTO l_error_id;
847
848 UPDATE hz_imp_parties_int
849 SET interface_status = 'E',
850 error_id = l_error_id
851 WHERE ROWID = party_int_rec.rowid;
852
853 fnd_file.put_line(fnd_file.log,
854 'Error Message Count: ' || x_msg_count ||
855 ' Error Message Data: ' || x_msg_data ||
856 ' From ap_vendor_pub_pkg.validate_vendor API for party id: ' ||
857 vendor_rec.party_id ||
858 ' or for party_orig_system_reference: ' ||
859 party_int_rec.party_orig_system_reference);
860
861 x_return_status := l_return_status;
862 x_msg_count := l_msg_count;
863 x_msg_data := l_msg_data;
864 END IF;
865
866 END LOOP;
867
868 CLOSE party_int_cur;
869
870 EXCEPTION
871 WHEN OTHERS THEN
872 x_return_status := fnd_api.g_ret_sts_unexp_error;
873 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
874 fnd_msg_pub.add;
875 fnd_msg_pub.count_and_get(p_count => x_msg_count,
876 p_data => x_msg_data);
877
878 fnd_file.put_line(fnd_file.log,
879 ' Inside validate_vendor EXCEPTION ' ||
880 ' Message: ' || SQLCODE || ' ' || SQLERRM);
881 END validate_vendor;
882
883 PROCEDURE update_contact_dtls
884 (
885 p_batch_id IN NUMBER,
886 x_return_status OUT NOCOPY VARCHAR2,
887 x_msg_count OUT NOCOPY NUMBER,
888 x_msg_data OUT NOCOPY VARCHAR2
889 ) IS
890
891 l_per_party_id NUMBER(15);
892 l_org_party_id NUMBER(15);
893 l_relationship_id NUMBER(15);
894 l_rel_party_id NUMBER(15);
895 l_org_contact_id NUMBER(15);
896
897 CURSOR supp_contact_int_cur IS
898 SELECT *
899 FROM ap_sup_site_contact_int supp
900 WHERE sdh_batch_id = p_batch_id
901 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
902 AND NOT EXISTS
903 (SELECT 1
904 FROM hz_imp_contacts_int party
905 WHERE batch_id = p_batch_id
906 AND supp.sdh_batch_id = party.batch_id
907 AND supp.party_orig_system = party.obj_orig_system
908 AND supp.party_orig_system_reference =
909 party.obj_orig_system_reference
910 AND supp.contact_orig_system = party.contact_orig_system
911 AND supp.contact_orig_system_reference =
912 party.contact_orig_system_reference
913 AND party.interface_status = 'R');
914
915 supp_contact_int_rec supp_contact_int_cur%ROWTYPE;
916
917 BEGIN
918
919 -- Initialize API return status to success
920 x_return_status := fnd_api.g_ret_sts_success;
921
922 OPEN supp_contact_int_cur;
923 LOOP
924 FETCH supp_contact_int_cur
925 INTO supp_contact_int_rec;
926
927 EXIT WHEN supp_contact_int_cur%NOTFOUND;
928
929 IF (supp_contact_int_rec.party_id IS NULL) THEN
930 l_org_party_id := get_party_id(supp_contact_int_rec.party_orig_system,
931 supp_contact_int_rec.party_orig_system_reference);
932
933 UPDATE ap_sup_site_contact_int
934 SET party_id = l_org_party_id
935 WHERE vendor_contact_interface_id =
936 supp_contact_int_rec.vendor_contact_interface_id
937 AND sdh_batch_id = p_batch_id;
938 ELSE
939 l_org_party_id := supp_contact_int_rec.party_id;
940 END IF;
941
942 -- Using the Contact first name and last name execute the
943 -- following SQL to yield the per_party_id
944 IF (supp_contact_int_rec.per_party_id IS NULL) THEN
945 l_per_party_id := get_party_id(supp_contact_int_rec.contact_orig_system,
946 supp_contact_int_rec.contact_orig_system_reference);
947 IF (l_per_party_id = 0) THEN
948 SELECT party_id
949 INTO l_per_party_id
950 FROM hz_parties
951 WHERE party_name = supp_contact_int_rec.first_name || ' ' ||
952 supp_contact_int_rec.last_name
953 AND party_type = 'PERSON';
954 /*AND orig_system_reference =
955 supp_contact_int_rec.party_orig_system_reference*/
956
957 END IF;
958
959 UPDATE ap_sup_site_contact_int
960 SET per_party_id = l_per_party_id
961 WHERE vendor_contact_interface_id =
962 supp_contact_int_rec.vendor_contact_interface_id
963 AND sdh_batch_id = p_batch_id;
964 ELSE
965 l_per_party_id := supp_contact_int_rec.per_party_id;
966 END IF;
967
968 IF (supp_contact_int_rec.relationship_id IS NULL OR
969 supp_contact_int_rec.rel_party_id IS NULL) THEN
970
971 SELECT relationship_id,
972 party_id
973 INTO l_relationship_id,
974 l_rel_party_id
975 FROM hz_relationships
976 WHERE subject_id = l_org_party_id
977 AND subject_type = 'ORGANIZATION'
978 AND object_id = l_per_party_id
979 AND object_type = 'PERSON';
980
981 UPDATE ap_sup_site_contact_int
982 SET relationship_id = l_relationship_id,
983 rel_party_id = l_rel_party_id
984 WHERE vendor_contact_interface_id =
985 supp_contact_int_rec.vendor_contact_interface_id
986 AND sdh_batch_id = p_batch_id;
987 ELSE
988 l_relationship_id := supp_contact_int_rec.relationship_id;
989 l_rel_party_id := supp_contact_int_rec.rel_party_id;
990 END IF;
991
992 IF (supp_contact_int_rec.org_contact_id IS NULL) THEN
993
994 SELECT org_contact_id
995 INTO l_org_contact_id
996 FROM hz_org_contacts
997 WHERE party_relationship_id = l_relationship_id;
998
999 UPDATE ap_sup_site_contact_int
1000 SET org_contact_id = l_org_contact_id
1001 WHERE vendor_contact_interface_id =
1002 supp_contact_int_rec.vendor_contact_interface_id
1003 AND sdh_batch_id = p_batch_id;
1004 END IF;
1005 END LOOP;
1006
1007 fnd_file.put_line(fnd_file.log,
1008 ' Message: Inside PROCEDURE update_contact_dtls' ||
1009 ' Updated details for vendor_contact_interface_id: ' ||
1010 supp_contact_int_rec.vendor_contact_interface_id ||
1011 ' party_id: ' || l_org_party_id || ' per_party_id: ' ||
1012 l_per_party_id || ' relationship_id: ' ||
1013 l_relationship_id || ' rel_party_id: ' ||
1014 l_rel_party_id || ' org_contact_id: ' ||
1015 l_org_contact_id);
1016
1017 COMMIT;
1018
1019 EXCEPTION
1020 WHEN OTHERS THEN
1021 x_return_status := fnd_api.g_ret_sts_unexp_error;
1022 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
1023 fnd_msg_pub.add;
1024 fnd_msg_pub.count_and_get(p_count => x_msg_count,
1025 p_data => x_msg_data);
1026
1027 fnd_file.put_line(fnd_file.log,
1028 ' Inside update_contact_dtls EXCEPTION ' ||
1029 ' Message: ' || SQLCODE || ' ' || SQLERRM);
1030 END update_contact_dtls;
1031
1032 PROCEDURE update_party_id
1033 (
1034 p_batch_id IN NUMBER,
1035 x_return_status OUT NOCOPY VARCHAR2,
1036 x_msg_count OUT NOCOPY NUMBER,
1037 x_msg_data OUT NOCOPY VARCHAR2
1038 ) IS
1039
1040 BEGIN
1041
1042 -- Initialize API return status to success
1043 x_return_status := fnd_api.g_ret_sts_success;
1044
1045 UPDATE ap_suppliers_int supp
1046 SET supp.party_id =
1047 (SELECT party_id
1048 FROM hz_orig_sys_references hr
1049 WHERE hr.owner_table_name = 'HZ_PARTIES'
1050 AND hr.orig_system = supp.party_orig_system
1051 AND hr.orig_system_reference =
1052 supp.party_orig_system_reference
1053 AND hr.status = 'A'
1054 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE)
1055 WHERE supp.party_id IS NULL
1056 AND supp.sdh_batch_id = p_batch_id;
1057
1058 COMMIT;
1059
1060 EXCEPTION
1061 WHEN OTHERS THEN
1062 x_return_status := fnd_api.g_ret_sts_unexp_error;
1063 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
1064 fnd_msg_pub.add;
1065 fnd_msg_pub.count_and_get(p_count => x_msg_count,
1066 p_data => x_msg_data);
1067
1068 fnd_file.put_line(fnd_file.log,
1069 ' Inside update_party_id EXCEPTION ' ||
1070 ' Message: ' || SQLCODE || ' ' || SQLERRM);
1071 END update_party_id;
1072
1073 PROCEDURE update_party_site_id
1074 (
1075 p_batch_id IN NUMBER,
1076 x_return_status OUT NOCOPY VARCHAR2,
1077 x_msg_count OUT NOCOPY NUMBER,
1078 x_msg_data OUT NOCOPY VARCHAR2
1079 ) IS
1080
1081 BEGIN
1082
1083 -- Initialize API return status to success
1084 x_return_status := fnd_api.g_ret_sts_success;
1085
1086 UPDATE ap_supplier_sites_int supp
1087 SET supp.party_id =
1088 (SELECT party_id
1089 FROM hz_orig_sys_references hr
1090 WHERE hr.owner_table_name = 'HZ_PARTIES'
1091 AND hr.orig_system = supp.party_orig_system
1092 AND hr.orig_system_reference =
1093 supp.party_orig_system_reference
1094 AND hr.status = 'A'
1095 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE)
1096 WHERE supp.party_id IS NULL
1097 AND supp.sdh_batch_id = p_batch_id;
1098
1099 UPDATE ap_supplier_sites_int supp
1100 SET party_site_id =
1101 (SELECT owner_table_id
1102 FROM hz_orig_sys_references hr
1103 WHERE hr.owner_table_name = 'HZ_PARTY_SITES'
1104 AND hr.orig_system = supp.party_site_orig_system
1105 AND hr.orig_system_reference =
1106 supp.party_site_orig_sys_reference
1107 AND hr.status = 'A'
1108 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE)
1109 WHERE supp.party_site_id IS NULL
1110 AND supp.sdh_batch_id = p_batch_id;
1111
1112 COMMIT;
1113
1114 EXCEPTION
1115 WHEN OTHERS THEN
1116 x_return_status := fnd_api.g_ret_sts_unexp_error;
1117 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
1118 fnd_msg_pub.add;
1119 fnd_msg_pub.count_and_get(p_count => x_msg_count,
1120 p_data => x_msg_data);
1121
1122 fnd_file.put_line(fnd_file.log,
1123 ' Inside update_party_site_id EXCEPTION ' ||
1124 ' Message: ' || SQLCODE || ' ' || SQLERRM);
1125 END update_party_site_id;
1126
1127 --
1128 -- Function to get the Vendor Number
1129 -- NUmbering technique
1130 --
1131 FUNCTION chk_vendor_num_nmbering_method RETURN VARCHAR2 IS
1132
1133 l_ven_num_code financials_system_parameters.user_defined_vendor_num_code%TYPE;
1134
1135 BEGIN
1136 SELECT supplier_numbering_method
1137 INTO l_ven_num_code
1138 FROM ap_product_setup;
1139
1140 RETURN l_ven_num_code;
1141
1142 END chk_vendor_num_nmbering_method;
1143
1144 PROCEDURE pre_processing
1145 (
1146 p_batch_id IN NUMBER,
1147 x_return_status OUT NOCOPY VARCHAR2,
1148 x_msg_count OUT NOCOPY NUMBER,
1149 x_msg_data OUT NOCOPY VARCHAR2
1150 ) IS
1151 l_api_name CONSTANT VARCHAR2(30) := 'PRE_PROCESSING';
1152 l_msg_count NUMBER;
1153
1154 BEGIN
1155 -- Initialize API return status to success
1156 x_return_status := fnd_api.g_ret_sts_success;
1157
1158 -- Check if the party exist for the supplier to be imported by
1159 -- using cross reference table
1160 /* AP to HZ started */
1161 check_party_exist(p_batch_id => p_batch_id,
1162 x_return_status => x_return_status,
1163 x_msg_count => x_msg_count,
1164 x_msg_data => x_msg_data);
1165
1166 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1167 fnd_file.put_line(fnd_file.log,
1168 'Error Message Count: ' || x_msg_count ||
1169 ' Error Message Data: ' || x_msg_data ||
1170 ' From check_party_exist API.');
1171 RETURN;
1172 END IF;
1173
1174 check_party_site_exist(p_batch_id => p_batch_id,
1175 x_return_status => x_return_status,
1176 x_msg_count => x_msg_count,
1177 x_msg_data => x_msg_data);
1178
1179 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1180 fnd_file.put_line(fnd_file.log,
1181 'Error Message Count: ' || x_msg_count ||
1182 ' Error Message Data: ' || x_msg_data ||
1183 ' From check_party_site_exist API.');
1184 RETURN;
1185 END IF;
1186
1187 check_party_contact_exist(p_batch_id => p_batch_id,
1188 x_return_status => x_return_status,
1189 x_msg_count => x_msg_count,
1190 x_msg_data => x_msg_data);
1191
1192 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1193 fnd_file.put_line(fnd_file.log,
1194 'Error Message Count: ' || x_msg_count ||
1195 ' Error Message Data: ' || x_msg_data ||
1196 ' From check_party_contact_exist API.');
1197 RETURN;
1198 END IF;
1199
1200 /* AP to HZ ended */
1201
1202 -- If party or sites or contacts are not present then above APIs will
1203 -- Bulk insert data in party interface tables from supplier interface tables
1204
1205 EXCEPTION
1206 WHEN OTHERS THEN
1207 x_return_status := fnd_api.g_ret_sts_unexp_error;
1208 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
1209 fnd_msg_pub.add;
1210 fnd_msg_pub.count_and_get(p_count => x_msg_count,
1211 p_data => x_msg_data);
1212
1213 fnd_file.put_line(fnd_file.log,
1214 ' Inside pre_processing EXCEPTION ' || ' Message: ' ||
1215 SQLCODE || ' ' || SQLERRM);
1216 END pre_processing;
1217
1218 -- This procedure would enable the successfully
1219 -- imported parties in a batch as Suppliers
1220 --
1221 PROCEDURE enable_party_as_supplier
1222 (
1223 p_batch_id IN NUMBER,
1224 x_return_status OUT NOCOPY VARCHAR2,
1225 x_msg_count OUT NOCOPY NUMBER,
1226 x_msg_data OUT NOCOPY VARCHAR2
1227 ) IS
1228 l_api_name CONSTANT VARCHAR2(30) := 'ENABLE_PARTY_AS_SUPPLIER';
1229 l_request_id NUMBER := fnd_global.conc_request_id;
1230
1231 l_return_status VARCHAR2(2000);
1232 l_msg_count NUMBER;
1233 l_msg_data VARCHAR2(2000);
1234 l_vendor_id NUMBER;
1235 l_party_id NUMBER;
1236
1237 vendor_rec ap_vendor_pub_pkg.r_vendor_rec_type;
1238
1239 CURSOR party_int_cur IS
1240 SELECT organization_name,
1241 organization_name_phonetic,
1242 attribute_category,
1243 attribute1,
1244 attribute2,
1245 attribute3,
1246 attribute4,
1247 attribute5,
1248 attribute6,
1249 attribute7,
1250 attribute8,
1251 attribute9,
1252 attribute10,
1253 attribute11,
1254 attribute12,
1255 attribute13,
1256 attribute14,
1257 attribute15,
1258 party_id,
1259 party_orig_system,
1260 party_orig_system_reference,
1261 insert_update_flag
1262 FROM hz_imp_parties_int hp
1263 WHERE batch_id = p_batch_id
1264 /* Status for the data should not be E or C
1265 i.e. Errored out or Completed */
1266 AND interface_status IS NULL
1267 AND party_type = 'ORGANIZATION'
1268 AND NOT EXISTS
1269 (SELECT *
1270 FROM ap_suppliers_int supp
1271 WHERE hp.batch_id = supp.sdh_batch_id
1272 AND hp.party_orig_system = supp.party_orig_system
1273 AND hp.party_orig_system_reference =
1274 supp.party_orig_system_reference);
1275
1276 party_int_rec party_int_cur%ROWTYPE;
1277
1278 l_vendor_num_code financials_system_parameters.user_defined_vendor_num_code%TYPE;
1279
1280 -- Added Sync Party Related return variables
1281 --
1282 l_sync_return_status VARCHAR2(50);
1283 l_sync_msg_count NUMBER;
1284 l_sync_msg_data VARCHAR2(1000);
1285
1286 --
1287 -- bug 9049391
1288 -- Check if the supplier exists for the party
1289 --
1290 CURSOR check_vendor_exsists(cp_party_id IN NUMBER) IS
1291 SELECT 1 FROM ap_suppliers WHERE party_id = cp_party_id;
1292
1293 l_vendor_exists NUMBER := 0;
1294 BEGIN
1295 -- Initialize API return status to success
1296 x_return_status := fnd_api.g_ret_sts_success;
1297
1298 DELETE ap_supplier_int_rejections
1299 WHERE parent_table = 'AP_SUPPLIERS_INT';
1300
1301 OPEN party_int_cur;
1302
1303 LOOP
1304 FETCH party_int_cur
1305 INTO party_int_rec;
1306
1307 EXIT WHEN party_int_cur%NOTFOUND;
1308
1309 vendor_rec.vendor_name := party_int_rec.organization_name;
1310 vendor_rec.vendor_name_alt := party_int_rec.organization_name_phonetic;
1311 vendor_rec.attribute_category := party_int_rec.attribute_category;
1312 vendor_rec.attribute1 := party_int_rec.attribute1;
1313 vendor_rec.attribute2 := party_int_rec.attribute2;
1314 vendor_rec.attribute3 := party_int_rec.attribute3;
1315 vendor_rec.attribute4 := party_int_rec.attribute4;
1316 vendor_rec.attribute5 := party_int_rec.attribute5;
1317 vendor_rec.attribute6 := party_int_rec.attribute6;
1318 vendor_rec.attribute7 := party_int_rec.attribute7;
1319 vendor_rec.attribute8 := party_int_rec.attribute8;
1320 vendor_rec.attribute9 := party_int_rec.attribute9;
1321 vendor_rec.attribute10 := party_int_rec.attribute10;
1322 vendor_rec.attribute11 := party_int_rec.attribute11;
1323 vendor_rec.attribute12 := party_int_rec.attribute12;
1324 vendor_rec.attribute13 := party_int_rec.attribute13;
1325 vendor_rec.attribute14 := party_int_rec.attribute14;
1326 vendor_rec.attribute15 := party_int_rec.attribute15;
1327
1328 /*vendor_rec.ext_payee_rec.payment_function := 'PAYABLES_DISB';
1329 vendor_rec.ext_payee_rec.payer_org_type := 'OPERATING_UNIT';*/
1330
1331 /* Get the party id for orig system and orig system reference combination */
1332
1333 vendor_rec.party_id := get_party_id(party_int_rec.party_orig_system,
1334 party_int_rec.party_orig_system_reference);
1335
1336 fnd_file.put_line(fnd_file.log,
1337 ' Message: Inside PROCEDURE enable_party_as_supplier' ||
1338 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
1339 ' Party id : ' || vendor_rec.party_id ||
1340 ' from get_party_id');
1341
1342 -- Check if the Vendor number is AutoNumbered.
1343 -- If the method is set to Manual then the vendor
1344 -- number would be mapped to the Orig System reference.
1345 --
1346 l_vendor_num_code := chk_vendor_num_nmbering_method();
1347
1348 IF (l_vendor_num_code = 'MANUAL') THEN
1349 vendor_rec.segment1 := party_int_rec.party_orig_system_reference;
1350 END IF;
1351
1352 -- Setting the vendor source as IMPORT so that the
1353 -- errors are logged in the rejections table
1354 --
1355 ap_vendor_pub_pkg.g_source := 'IMPORT';
1356
1357 -- bug 9049391
1358 -- If the record is being updated in that case the AP suppliers data
1359 -- has to be synchronized with the TCA repository. This is done by making
1360 -- a call to the TCA Sync API
1361 --
1362 /*IF (nvl(party_int_rec.insert_update_flag, 'I') = 'U') THEN*/
1363 IF party_int_rec.insert_update_flag IS NULL THEN
1364 -- Check if the vendor already exists
1365 OPEN check_vendor_exsists(vendor_rec.party_id);
1366 FETCH check_vendor_exsists
1367 INTO l_vendor_exists;
1368 CLOSE check_vendor_exsists;
1369
1370 -- If the vendor exists then Sync it with the party information
1371 IF l_vendor_exists <> 0 THEN
1372 l_vendor_exists := 0;
1373 ap_tca_supplier_sync_pkg.sync_supplier(l_sync_return_status,
1374 l_sync_msg_count,
1375 l_sync_msg_data,
1376 vendor_rec.party_id);
1377 IF l_sync_return_status = fnd_api.g_ret_sts_success THEN
1378 ap_vendor_pub_pkg.raise_supplier_event(i_vendor_id => l_vendor_id);
1379 x_return_status := fnd_api.g_ret_sts_success;
1380 ELSE
1381 x_return_status := l_sync_return_status;
1382 x_msg_count := l_sync_msg_count;
1383 x_msg_data := l_sync_msg_data;
1384 END IF;
1385 ELSE
1386 /* Call create vendor API to create a supplier */
1387 ap_vendor_pub_pkg.create_vendor(p_api_version => 1.0,
1388 p_init_msg_list => fnd_api.g_true,
1389 p_commit => fnd_api.g_false,
1390 p_validation_level => fnd_api.g_valid_level_full,
1391 x_return_status => l_return_status,
1392 x_msg_count => l_msg_count,
1393 x_msg_data => l_msg_data,
1394 p_vendor_rec => vendor_rec,
1395 x_vendor_id => l_vendor_id,
1396 x_party_id => l_party_id);
1397
1398 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1399 INSERT INTO pos_supplier_int_rejections
1400 (batch_id,
1401 import_request_id,
1402 parent_table,
1403 parent_id,
1404 reject_lookup_code,
1405 last_updated_by,
1406 last_update_date,
1407 last_update_login,
1408 created_by,
1409 creation_date)
1410 SELECT p_batch_id,
1411 l_request_id,
1412 parent_table,
1413 parent_id,
1414 reject_lookup_code,
1415 last_updated_by,
1416 last_update_date,
1417 last_update_login,
1418 created_by,
1419 creation_date
1420 FROM ap_supplier_int_rejections
1421 WHERE parent_table = 'AP_SUPPLIERS_INT';
1422
1423 IF (g_level_procedure >= g_current_runtime_level) THEN
1424 fnd_log.string(g_level_procedure,
1425 g_module_name || l_api_name,
1426 ' No. of Messages from Create_Vendor API: ' ||
1427 l_msg_count ||
1428 ', Message From Create_Vendor API: ' ||
1429 l_msg_data);
1430 END IF;
1431
1432 fnd_file.put_line(fnd_file.log, 'Failed in validating vendor.');
1433
1434 fnd_file.put_line(fnd_file.log,
1435 'Error Message Count: ' || x_msg_count ||
1436 ' Error Message Data: ' || x_msg_data ||
1437 ' From ap_vendor_pub_pkg.create_vendor API for party id: ' ||
1438 vendor_rec.party_id);
1439
1440 x_return_status := l_return_status;
1441 x_msg_count := l_msg_count;
1442 x_msg_data := l_msg_data;
1443 END IF;
1444
1445 END IF;
1446 ELSIF party_int_rec.insert_update_flag = 'I' THEN
1447 /* Call create vendor API to create a supplier */
1448 ap_vendor_pub_pkg.create_vendor(p_api_version => 1.0,
1449 p_init_msg_list => fnd_api.g_true,
1450 p_commit => fnd_api.g_false,
1451 p_validation_level => fnd_api.g_valid_level_full,
1452 x_return_status => l_return_status,
1453 x_msg_count => l_msg_count,
1454 x_msg_data => l_msg_data,
1455 p_vendor_rec => vendor_rec,
1456 x_vendor_id => l_vendor_id,
1457 x_party_id => l_party_id);
1458
1459 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1460 INSERT INTO pos_supplier_int_rejections
1461 (batch_id,
1462 import_request_id,
1463 parent_table,
1464 parent_id,
1465 reject_lookup_code,
1466 last_updated_by,
1467 last_update_date,
1468 last_update_login,
1469 created_by,
1470 creation_date)
1471 SELECT p_batch_id,
1472 l_request_id,
1473 parent_table,
1474 parent_id,
1475 reject_lookup_code,
1476 last_updated_by,
1477 last_update_date,
1478 last_update_login,
1479 created_by,
1480 creation_date
1481 FROM ap_supplier_int_rejections
1482 WHERE parent_table = 'AP_SUPPLIERS_INT';
1483
1484 IF (g_level_procedure >= g_current_runtime_level) THEN
1485 fnd_log.string(g_level_procedure,
1486 g_module_name || l_api_name,
1487 ' No. of Messages from Create_Vendor API: ' ||
1488 l_msg_count ||
1489 ', Message From Create_Vendor API: ' ||
1490 l_msg_data);
1491 END IF;
1492
1493 fnd_file.put_line(fnd_file.log,
1494 'Error Message Count: ' || x_msg_count ||
1495 ' Error Message Data: ' || x_msg_data ||
1496 ' From ap_vendor_pub_pkg.create_vendor API for party id: ' ||
1497 vendor_rec.party_id);
1498 x_return_status := l_return_status;
1499 x_msg_count := l_msg_count;
1500 x_msg_data := l_msg_data;
1501 END IF;
1502 ELSIF party_int_rec.insert_update_flag = 'U' THEN
1503 ap_tca_supplier_sync_pkg.sync_supplier(l_sync_return_status,
1504 l_sync_msg_count,
1505 l_sync_msg_data,
1506 vendor_rec.party_id);
1507 IF l_sync_return_status = fnd_api.g_ret_sts_success THEN
1508 ap_vendor_pub_pkg.raise_supplier_event(i_vendor_id => l_vendor_id);
1509 x_return_status := fnd_api.g_ret_sts_success;
1510 ELSE
1511 x_return_status := l_sync_return_status;
1512 x_msg_count := l_sync_msg_count;
1513 x_msg_data := l_sync_msg_data;
1514 END IF;
1515 END IF;
1516 END LOOP;
1517
1518 CLOSE party_int_cur;
1519
1520 EXCEPTION
1521 WHEN OTHERS THEN
1522 x_return_status := fnd_api.g_ret_sts_unexp_error;
1523 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY');
1524 fnd_msg_pub.add;
1525 fnd_msg_pub.count_and_get(p_count => x_msg_count,
1526 p_data => x_msg_data);
1527
1528 fnd_file.put_line(fnd_file.log,
1529 ' Inside enable_party_as_supplier EXCEPTION ' ||
1530 ' Message: ' || SQLCODE || ' ' || SQLERRM);
1531 END enable_party_as_supplier;
1532
1533 -- This procedure would enable the successfully imported
1534 -- Party contacts in an import batch as supplier contacts
1535 --
1536 PROCEDURE enable_partycont_as_suppcont
1537 (
1538 p_batch_id IN NUMBER,
1539 x_return_status OUT NOCOPY VARCHAR2,
1540 x_msg_count OUT NOCOPY NUMBER,
1541 x_msg_data OUT NOCOPY VARCHAR2
1542 ) IS
1543
1544 l_return_status VARCHAR2(2000);
1545 l_msg_count NUMBER;
1546 l_msg_data VARCHAR2(2000);
1547 l_party_id NUMBER;
1548
1549 CURSOR contact_int_cur IS
1550 SELECT contact_orig_system,
1551 contact_orig_system_reference
1552 FROM hz_imp_contacts_int hz
1553 WHERE batch_id = p_batch_id
1554 /* Status for the data should not be E or C
1555 i.e. Errored out or Completed */
1556 AND interface_status IS NULL
1557 AND relationship_type = 'CONTACT'
1558 AND relationship_code = 'CONTACT_OF';
1559
1560 contact_int_rec contact_int_cur%ROWTYPE;
1561
1562 l_party_usg_rec hz_party_usg_assignment_pvt.party_usg_assignment_rec_type;
1563 l_party_usg_validation_level NUMBER;
1564 BEGIN
1565
1566 -- Initialize API return status to success
1567 x_return_status := fnd_api.g_ret_sts_success;
1568
1569 OPEN contact_int_cur;
1570
1571 LOOP
1572 FETCH contact_int_cur
1573 INTO contact_int_rec;
1574
1575 EXIT WHEN contact_int_cur%NOTFOUND;
1576
1577 /* Get the party id for orig system and
1578 orig system reference combination */
1579 l_party_id := get_party_id(contact_int_rec.contact_orig_system,
1580 contact_int_rec.contact_orig_system_reference);
1581
1582 fnd_file.put_line(fnd_file.log,
1583 ' Message: Inside PROCEDURE enable_partycont_as_suppcont' ||
1584 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
1585 ' Party id : ' || l_party_id ||
1586 ' from get_party_id');
1587
1588 l_party_usg_validation_level := hz_party_usg_assignment_pvt.g_valid_level_none;
1589 l_party_usg_rec.party_id := l_party_id;
1590 l_party_usg_rec.party_usage_code := 'SUPPLIER_CONTACT';
1591 l_party_usg_rec.created_by_module := 'AP_SUPPLIERS_API';
1592
1593 /* Enable party contact as supplier contact by
1594 setting usage code as SUPPLIER_CONTACT */
1595 hz_party_usg_assignment_pvt.assign_party_usage(p_validation_level => l_party_usg_validation_level,
1596 p_party_usg_assignment_rec => l_party_usg_rec,
1597 x_return_status => l_return_status,
1598 x_msg_count => l_msg_count,
1599 x_msg_data => l_msg_data);
1600
1601 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1602 error_handler.get_message_list(l_error_msg_tbl);
1603 IF l_error_msg_tbl.first IS NOT NULL THEN
1604 l_msg_count := l_error_msg_tbl.first;
1605 WHILE l_msg_count IS NOT NULL LOOP
1606 fnd_file.put_line(fnd_file.log,
1607 'Error Message: ' || l_error_msg_tbl(l_msg_count)
1608 .message_text ||
1609 ' From hz_party_usg_assignment_pvt.assign_party_usage API for party id ' ||
1610 l_party_id);
1611 l_msg_count := l_error_msg_tbl.next(l_msg_count);
1612 END LOOP;
1613 END IF;
1614 fnd_file.put_line(fnd_file.log,
1615 'Error in hz_party_usg_assignment_pvt.assign_party_usage API for party id ' ||
1616 l_party_id);
1617 x_return_status := l_return_status;
1618 x_msg_count := l_msg_count;
1619 x_msg_data := l_msg_data;
1620 END IF;
1621
1622 END LOOP;
1623
1624 CLOSE contact_int_cur;
1625
1626 EXCEPTION
1627 WHEN OTHERS THEN
1628 x_return_status := fnd_api.g_ret_sts_unexp_error;
1629 fnd_message.set_name('SQLAP', 'AP_INVALID_PARTY_CONTACT');
1630 fnd_msg_pub.add;
1631 fnd_msg_pub.count_and_get(p_count => x_msg_count,
1632 p_data => x_msg_data);
1633
1634 fnd_file.put_line(fnd_file.log,
1635 ' Inside enable_partycont_as_suppcont EXCEPTION ' ||
1636 ' Message: ' || SQLCODE || ' ' || SQLERRM);
1637 END enable_partycont_as_suppcont;
1638
1639 PROCEDURE create_vendor
1640 (
1641 p_batch_id IN NUMBER,
1642 p_vendor_rec IN ap_vendor_pub_pkg.r_vendor_rec_type,
1643 ext_payee_rec IN OUT NOCOPY iby_disbursement_setup_pub.external_payee_rec_type,
1644 x_return_status OUT NOCOPY VARCHAR2,
1645 x_msg_count OUT NOCOPY NUMBER,
1646 x_msg_data OUT NOCOPY VARCHAR2
1647 ) IS
1648 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_VENDOR';
1649 l_request_id NUMBER := fnd_global.conc_request_id;
1650
1651 l_return_status VARCHAR2(2000);
1652 l_msg_count NUMBER;
1653 l_msg_data VARCHAR2(2000);
1654 l_vendor_id NUMBER;
1655 l_party_id NUMBER;
1656
1657 CURSOR iby_ext_accts_cur(p_unique_ref IN NUMBER) IS
1658 SELECT temp_ext_bank_acct_id
1659 FROM iby_temp_ext_bank_accts
1660 WHERE calling_app_unique_ref1 = p_unique_ref
1661 AND status <> 'PROCESSED';
1662
1663 ext_payee_tab iby_disbursement_setup_pub.external_payee_tab_type;
1664 ext_payee_id_tab iby_disbursement_setup_pub.ext_payee_id_tab_type;
1665 ext_payee_create_tab iby_disbursement_setup_pub.ext_payee_create_tab_type;
1666
1667 l_temp_ext_acct_id NUMBER;
1668 ext_response_rec iby_fndcpt_common_pub.result_rec_type;
1669
1670 l_ext_payee_id NUMBER;
1671 l_bank_acct_id NUMBER;
1672 BEGIN
1673 x_return_status := fnd_api.g_ret_sts_success;
1674
1675 fnd_file.put_line(fnd_file.log,
1676 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1677 ' Parameters party_id: ' || p_vendor_rec.party_id ||
1678 ' vendor_id: ' || p_vendor_rec.vendor_id ||
1679 ' vendor_interface_id: ' ||
1680 p_vendor_rec.vendor_interface_id);
1681
1682 ap_vendor_pub_pkg.create_vendor(p_api_version => 1.0,
1683 p_init_msg_list => fnd_api.g_true,
1684 p_commit => fnd_api.g_false,
1685 p_validation_level => fnd_api.g_valid_level_full,
1686 x_return_status => l_return_status,
1687 x_msg_count => l_msg_count,
1688 x_msg_data => l_msg_data,
1689 p_vendor_rec => p_vendor_rec,
1690 x_vendor_id => l_vendor_id,
1691 x_party_id => l_party_id);
1692
1693 IF l_return_status = fnd_api.g_ret_sts_success THEN
1694
1695 UPDATE ap_suppliers_int
1696 SET status = 'PROCESSED'
1697 WHERE vendor_interface_id = p_vendor_rec.vendor_interface_id
1698 AND sdh_batch_id = p_batch_id;
1699
1700 UPDATE pos_imp_batch_summary
1701 SET total_records_imported = total_records_imported + 1,
1702 total_inserts = total_inserts + 1,
1703 suppliers_inserted = suppliers_inserted + 1,
1704 suppliers_imported = suppliers_imported + 1
1705 WHERE batch_id = p_batch_id;
1706
1707 UPDATE ap_supplier_sites_int
1708 SET vendor_id = l_vendor_id
1709 WHERE vendor_interface_id = p_vendor_rec.vendor_interface_id
1710 AND sdh_batch_id = p_batch_id;
1711
1712 UPDATE ap_sup_site_contact_int
1713 SET vendor_id = l_vendor_id
1714 WHERE vendor_interface_id = p_vendor_rec.vendor_interface_id
1715 AND sdh_batch_id = p_batch_id;
1716
1717 UPDATE pos_business_class_int
1718 SET vendor_id = l_vendor_id
1719 WHERE vendor_interface_id = p_vendor_rec.vendor_interface_id
1720 AND sdh_batch_id = p_batch_id;
1721
1722 UPDATE pos_product_service_int
1723 SET vendor_id = l_vendor_id
1724 WHERE vendor_interface_id = p_vendor_rec.vendor_interface_id
1725 AND sdh_batch_id = p_batch_id;
1726
1727 fnd_file.put_line(fnd_file.log,
1728 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1729 ' party_id: ' || p_vendor_rec.party_id ||
1730 ' l_party_id: ' || l_party_id);
1731
1732 ext_payee_rec.payee_party_id := nvl(l_party_id, p_vendor_rec.party_id);
1733
1734 /* Calling IBY Payee Validation API */
1735 iby_disbursement_setup_pub.validate_external_payee(p_api_version => 1.0,
1736 p_init_msg_list => fnd_api.g_true,
1737 p_ext_payee_rec => ext_payee_rec,
1738 x_return_status => l_return_status,
1739 x_msg_count => l_msg_count,
1740 x_msg_data => l_msg_data);
1741
1742 fnd_file.put_line(fnd_file.log,
1743 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1744 ' from iby_disbursement_setup_pub.validate_external_payee' ||
1745 ' l_return_status: ' || l_return_status);
1746
1747 IF l_return_status = fnd_api.g_ret_sts_success THEN
1748
1749 ext_payee_tab(1) := ext_payee_rec;
1750
1751 /*Calling IBY Payee Creation API */
1752 iby_disbursement_setup_pub.create_external_payee(p_api_version => 1.0,
1753 p_init_msg_list => fnd_api.g_true,
1754 p_ext_payee_tab => ext_payee_tab,
1755 x_return_status => l_return_status,
1756 x_msg_count => l_msg_count,
1757 x_msg_data => l_msg_data,
1758 x_ext_payee_id_tab => ext_payee_id_tab,
1759 x_ext_payee_status_tab => ext_payee_create_tab);
1760
1761 fnd_file.put_line(fnd_file.log,
1762 'Payee_Creation_Msg: ' || ext_payee_create_tab(1)
1763 .payee_creation_msg);
1764
1765 IF l_return_status = fnd_api.g_ret_sts_success THEN
1766 l_ext_payee_id := ext_payee_id_tab(1).ext_payee_id;
1767
1768 UPDATE iby_temp_ext_bank_accts
1769 SET ext_payee_id = l_ext_payee_id,
1770 account_owner_party_id = l_party_id
1771 WHERE calling_app_unique_ref1 = p_vendor_rec.vendor_interface_id;
1772
1773 -- Cursor processing for iby temp bank account record
1774 OPEN iby_ext_accts_cur(p_vendor_rec.vendor_interface_id);
1775 LOOP
1776
1777 FETCH iby_ext_accts_cur
1778 INTO l_temp_ext_acct_id;
1779 EXIT WHEN iby_ext_accts_cur%NOTFOUND;
1780
1781 /* Calling IBY Bank Account Validation API */
1782 iby_disbursement_setup_pub.validate_temp_ext_bank_acct(p_api_version => 1.0,
1783 p_init_msg_list => fnd_api.g_true,
1784 x_return_status => l_return_status,
1785 x_msg_count => l_msg_count,
1786 x_msg_data => l_msg_data,
1787 p_temp_ext_acct_id => l_temp_ext_acct_id);
1788
1789 IF l_return_status = fnd_api.g_ret_sts_success THEN
1790 /* Calling IBY Bank Account Creation API */
1791 iby_disbursement_setup_pub.create_temp_ext_bank_acct(p_api_version => 1.0,
1792 p_init_msg_list => fnd_api.g_true,
1793 x_return_status => l_return_status,
1794 x_msg_count => l_msg_count,
1795 x_msg_data => l_msg_data,
1796 p_temp_ext_acct_id => l_temp_ext_acct_id,
1797 p_association_level => 'S',
1798 p_supplier_site_id => NULL,
1799 p_party_site_id => NULL,
1800 p_org_id => NULL,
1801 p_org_type => NULL,
1802 x_bank_acc_id => l_bank_acct_id,
1803 x_response => ext_response_rec);
1804
1805 IF l_return_status = fnd_api.g_ret_sts_success THEN
1806 UPDATE iby_temp_ext_bank_accts
1807 SET status = 'PROCESSED'
1808 WHERE temp_ext_bank_acct_id = l_temp_ext_acct_id;
1809
1810 ELSE
1811 UPDATE iby_temp_ext_bank_accts
1812 SET status = 'REJECTED'
1813 WHERE temp_ext_bank_acct_id = l_temp_ext_acct_id;
1814
1815 IF (insert_rejections(p_batch_id,
1816 l_request_id,
1817 'IBY_TEMP_EXT_BANK_ACCTS',
1818 p_vendor_rec.vendor_interface_id,
1819 'AP_BANK_ACCT_CREATION',
1820 g_user_id,
1821 g_login_id,
1822 'Import_Vendor') <> TRUE) THEN
1823
1824 IF (g_level_procedure >= g_current_runtime_level) THEN
1825 fnd_msg_pub.count_and_get(p_count => l_msg_count,
1826 p_data => l_msg_data);
1827 fnd_log.string(g_level_procedure,
1828 g_module_name || l_api_name,
1829 'Parameters: ' ||
1830 ' Vendor_Interface_Id: ' ||
1831 p_vendor_rec.vendor_interface_id ||
1832 ' Acct Validation Msg: ' || l_msg_data);
1833 END IF;
1834 END IF;
1835
1836 fnd_message.set_name('SQLAP', 'AP_BANK_ACCT_CREATION');
1837 fnd_msg_pub.add;
1838
1839 fnd_file.put_line(fnd_file.log,
1840 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1841 ' failed in iby_disbursement_setup_pub.create_temp_ext_bank_acct ' ||
1842 ' vendor_interface_id: ' ||
1843 p_vendor_rec.vendor_interface_id ||
1844 ' temp_ext_bank_acct_id: ' ||
1845 l_temp_ext_acct_id);
1846
1847 END IF; -- Bank Account Creation API
1848
1849 ELSE
1850 UPDATE iby_temp_ext_bank_accts
1851 SET status = 'REJECTED'
1852 WHERE temp_ext_bank_acct_id = l_temp_ext_acct_id;
1853
1854 IF (insert_rejections(p_batch_id,
1855 l_request_id,
1856 'IBY_TEMP_EXT_BANK_ACCTS',
1857 p_vendor_rec.vendor_interface_id,
1858 'AP_INVALID_BANK_ACCT_INFO',
1859 g_user_id,
1860 g_login_id,
1861 'Import_Vendor') <> TRUE) THEN
1862
1863 IF (g_level_procedure >= g_current_runtime_level) THEN
1864 fnd_msg_pub.count_and_get(p_count => l_msg_count,
1865 p_data => l_msg_data);
1866 fnd_log.string(g_level_procedure,
1867 g_module_name || l_api_name,
1868 'Parameters: ' || ' Vendor_Interface_Id: ' ||
1869 p_vendor_rec.vendor_interface_id ||
1870 ' Acct Validation Msg: ' || l_msg_data);
1871 END IF;
1872 END IF;
1873
1874 fnd_message.set_name('SQLAP', 'AP_INVALID_BANK_ACCT_INFO');
1875 fnd_msg_pub.add;
1876
1877 fnd_file.put_line(fnd_file.log,
1878 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1879 ' failed in iby_disbursement_setup_pub.validate_temp_ext_bank_acct ' ||
1880 ' vendor_interface_id: ' ||
1881 p_vendor_rec.vendor_interface_id ||
1882 ' temp_ext_bank_acct_id: ' ||
1883 l_temp_ext_acct_id);
1884
1885 END IF; -- Bank Account Validation API
1886
1887 END LOOP;
1888 CLOSE iby_ext_accts_cur;
1889
1890 ELSE
1891 IF (insert_rejections(p_batch_id,
1892 l_request_id,
1893 'AP_SUPPLIERS_INT',
1894 p_vendor_rec.vendor_interface_id,
1895 'AP_PAYEE_CREATION',
1896 g_user_id,
1897 g_login_id,
1898 'Import_Vendor') <> TRUE) THEN
1899
1900 IF (g_level_procedure >= g_current_runtime_level) THEN
1901 fnd_msg_pub.count_and_get(p_count => l_msg_count,
1902 p_data => l_msg_data);
1903 fnd_log.string(g_level_procedure,
1904 g_module_name || l_api_name,
1905 'Parameters: ' || ' Vendor_Interface_Id: ' ||
1906 p_vendor_rec.vendor_interface_id ||
1907 ' Payee Validation Msg: ' || l_msg_data);
1908 END IF;
1909 END IF;
1910
1911 fnd_message.set_name('SQLAP', 'AP_PAYEE_CREATION');
1912 fnd_msg_pub.add;
1913
1914 fnd_file.put_line(fnd_file.log,
1915 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1916 ' failed in iby_disbursement_setup_pub.create_external_payee ' ||
1917 ' vendor_interface_id: ' ||
1918 p_vendor_rec.vendor_interface_id ||
1919 ' temp_ext_bank_acct_id: ' ||
1920 l_temp_ext_acct_id);
1921
1922 END IF; -- Payee Creation API
1923
1924 ELSE
1925 IF (insert_rejections(p_batch_id,
1926 l_request_id,
1927 'AP_SUPPLIERS_INT',
1928 p_vendor_rec.vendor_interface_id,
1929 'AP_INVALID_PAYEE',
1930 g_user_id,
1931 g_login_id,
1932 'Import_Vendor') <> TRUE) THEN
1933
1934 IF (g_level_procedure >= g_current_runtime_level) THEN
1935 fnd_msg_pub.count_and_get(p_count => l_msg_count,
1936 p_data => l_msg_data);
1937 fnd_log.string(g_level_procedure,
1938 g_module_name || l_api_name,
1939 'Parameters: ' || ' Vendor_Interface_Id: ' ||
1940 p_vendor_rec.vendor_interface_id ||
1941 ' Payee Validation Msg: ' || l_msg_data);
1942 END IF;
1943 END IF;
1944
1945 fnd_message.set_name('SQLAP', 'AP_INVALID_PAYEE');
1946 fnd_msg_pub.add;
1947
1948 fnd_file.put_line(fnd_file.log,
1949 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
1950 ' failed in iby_disbursement_setup_pub.validate_external_payee ' ||
1951 ' vendor_interface_id: ' ||
1952 p_vendor_rec.vendor_interface_id ||
1953 ' temp_ext_bank_acct_id: ' || l_temp_ext_acct_id);
1954
1955 END IF; -- Payee Validation API
1956
1957 ELSE
1958
1959 UPDATE ap_suppliers_int
1960 SET status = 'REJECTED'
1961 WHERE vendor_interface_id = p_vendor_rec.vendor_interface_id
1962 AND sdh_batch_id = p_batch_id;
1963
1964 INSERT INTO pos_supplier_int_rejections
1965 (batch_id,
1966 import_request_id,
1967 parent_table,
1968 parent_id,
1969 reject_lookup_code,
1970 last_updated_by,
1971 last_update_date,
1972 last_update_login,
1973 created_by,
1974 creation_date)
1975 SELECT p_batch_id,
1976 l_request_id,
1977 parent_table,
1978 parent_id,
1979 reject_lookup_code,
1980 last_updated_by,
1981 last_update_date,
1982 last_update_login,
1983 created_by,
1984 creation_date
1985 FROM ap_supplier_int_rejections
1986 WHERE parent_table = 'AP_SUPPLIERS_INT'
1987 AND parent_id = p_vendor_rec.vendor_interface_id;
1988
1989 IF (g_level_procedure >= g_current_runtime_level) THEN
1990 fnd_log.string(g_level_procedure,
1991 g_module_name || l_api_name,
1992 ' Rejected Vendor_Interface_Id: ' ||
1993 p_vendor_rec.vendor_interface_id ||
1994 ', No. of Messages from Create_Vendor API: ' ||
1995 l_msg_count || ', Message From Create_Vendor API: ' ||
1996 l_msg_data);
1997 END IF;
1998
1999 error_handler.get_message_list(l_error_msg_tbl);
2000 IF l_error_msg_tbl.first IS NOT NULL THEN
2001 l_msg_count := l_error_msg_tbl.first;
2002 WHILE l_msg_count IS NOT NULL LOOP
2003 fnd_file.put_line(fnd_file.log,
2004 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
2005 ' failed in ap_vendor_pub_pkg.create_vendor ' ||
2006 ' vendor_interface_id: ' ||
2007 p_vendor_rec.vendor_interface_id ||
2008 ', No. of Messages: ' || l_msg_count ||
2009 ', Message: ' || l_error_msg_tbl(l_msg_count)
2010 .message_text);
2011 l_msg_count := l_error_msg_tbl.next(l_msg_count);
2012 END LOOP;
2013 ELSE
2014 fnd_file.put_line(fnd_file.log,
2015 ' Message: Inside PROCEDURE CREATE_VENDOR' ||
2016 ' failed in ap_vendor_pub_pkg.create_vendor ' ||
2017 ' vendor_interface_id: ' ||
2018 p_vendor_rec.vendor_interface_id);
2019 END IF;
2020 x_return_status := l_return_status;
2021 x_msg_count := l_msg_count;
2022 x_msg_data := l_msg_data;
2023
2024 END IF; -- Supplier Creation API
2025 EXCEPTION
2026 WHEN OTHERS THEN
2027 x_return_status := fnd_api.g_ret_sts_unexp_error;
2028
2029 fnd_msg_pub.count_and_get(p_count => x_msg_count,
2030 p_data => x_msg_data);
2031
2032 fnd_file.put_line(fnd_file.log,
2033 ' Inside create_vendor EXCEPTION ' || ' Message: ' ||
2034 SQLCODE || ' ' || SQLERRM);
2035 END create_vendor;
2036
2037 PROCEDURE import_vendors
2038 (
2039 p_batch_id IN NUMBER,
2040 x_return_status OUT NOCOPY VARCHAR2,
2041 x_msg_count OUT NOCOPY NUMBER,
2042 x_msg_data OUT NOCOPY VARCHAR2
2043 ) IS
2044
2045 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDORS';
2046 l_request_id NUMBER := fnd_global.conc_request_id;
2047
2048 l_return_status VARCHAR2(2000);
2049 l_msg_count NUMBER;
2050 l_msg_data VARCHAR2(2000);
2051 l_vendor_id NUMBER;
2052
2053 CURSOR vendor_int_cur IS
2054 SELECT *
2055 FROM ap_suppliers_int supp
2056 WHERE import_request_id = l_request_id
2057 AND vendor_interface_id IS NOT NULL
2058 AND sdh_batch_id = p_batch_id
2059 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
2060 AND NOT EXISTS
2061 (SELECT 1
2062 FROM hz_imp_parties_int party
2063 WHERE batch_id = p_batch_id
2064 AND supp.sdh_batch_id = party.batch_id
2065 AND supp.party_orig_system = party.party_orig_system
2066 AND supp.party_orig_system_reference =
2067 party.party_orig_system_reference
2068 AND party.interface_status = 'R')
2069 ORDER BY segment1;
2070
2071 vendor_int_rec vendor_int_cur%ROWTYPE;
2072 vendor_rec ap_vendor_pub_pkg.r_vendor_rec_type;
2073
2074 l_vendor_num_code financials_system_parameters.user_defined_vendor_num_code%TYPE;
2075 l_insert_update_flag VARCHAR2(1);
2076
2077 /* Variable Declaration for IBY */
2078 ext_payee_rec iby_disbursement_setup_pub.external_payee_rec_type;
2079
2080 CURSOR check_vendor_exsists(cp_party_id IN NUMBER) IS
2081 SELECT 1,
2082 vendor_id
2083 FROM ap_suppliers
2084 WHERE party_id = cp_party_id;
2085
2086 l_vendor_exists NUMBER := 0;
2087
2088 BEGIN
2089 -- Initialize API return status to success
2090 x_return_status := fnd_api.g_ret_sts_success;
2091
2092 -- Standard Start of API savepoint
2093 SAVEPOINT import_vendor_pub;
2094
2095 DELETE ap_supplier_int_rejections
2096 WHERE parent_table = 'AP_SUPPLIERS_INT';
2097
2098 -- API body
2099
2100 -- This update statement resets the unprocessed rows so
2101 -- that they get picked in the current run.
2102 UPDATE ap_suppliers_int api
2103 SET import_request_id = NULL
2104 WHERE import_request_id IS NOT NULL
2105 AND sdh_batch_id = p_batch_id
2106 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
2107 AND EXISTS (SELECT 'Request Completed'
2108 FROM fnd_concurrent_requests fcr
2109 WHERE fcr.request_id = api.import_request_id
2110 AND fcr.phase_code = 'C');
2111
2112 -- Updating Interface Record with request id
2113 UPDATE ap_suppliers_int
2114 SET import_request_id = l_request_id
2115 WHERE import_request_id IS NULL
2116 AND sdh_batch_id = p_batch_id
2117 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED');
2118
2119 UPDATE ap_suppliers_int supp
2120 SET status = 'REMOVED',
2121 import_request_id = l_request_id
2122 WHERE sdh_batch_id = p_batch_id
2123 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
2124 AND EXISTS
2125 (SELECT 1
2126 FROM hz_imp_parties_int party
2127 WHERE batch_id = p_batch_id
2128 AND supp.sdh_batch_id = party.batch_id
2129 AND supp.party_orig_system = party.party_orig_system
2130 AND supp.party_orig_system_reference =
2131 party.party_orig_system_reference
2132 AND party.interface_status = 'R');
2133
2134 fnd_file.put_line(fnd_file.log,
2135 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2136 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
2137 ' records. Reason interface_status in hz_imp_parties_int = R');
2138
2139 INSERT INTO pos_supplier_int_rejections
2140 (SELECT p_batch_id,
2141 l_request_id,
2142 'AP_SUPPLIERS_INT',
2143 vendor_interface_id,
2144 'POS_INVALID_PARTY_ORIG_SYSTEM',
2145 g_user_id,
2146 SYSDATE,
2147 g_login_id,
2148 g_user_id,
2149 SYSDATE
2150 FROM ap_suppliers_int
2151 WHERE status = 'REMOVED'
2152 AND import_request_id = l_request_id
2153 AND sdh_batch_id = p_batch_id);
2154
2155 fnd_file.put_line(fnd_file.log,
2156 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2157 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
2158 ' request_id: ' || l_request_id);
2159
2160 COMMIT;
2161
2162 SAVEPOINT import_vendor_pub;
2163 ap_vendor_pub_pkg.g_source := 'IMPORT';
2164
2165 -- Cursor processing for vendor interface record
2166 OPEN vendor_int_cur;
2167 LOOP
2168
2169 FETCH vendor_int_cur
2170 INTO vendor_int_rec;
2171 EXIT WHEN vendor_int_cur%NOTFOUND;
2172
2173 vendor_rec.vendor_interface_id := vendor_int_rec.vendor_interface_id;
2174 vendor_rec.vendor_name := vendor_int_rec.vendor_name;
2175 vendor_rec.segment1 := vendor_int_rec.segment1;
2176 vendor_rec.vendor_name_alt := vendor_int_rec.vendor_name_alt;
2177 vendor_rec.summary_flag := vendor_int_rec.summary_flag;
2178 vendor_rec.enabled_flag := vendor_int_rec.enabled_flag;
2179 vendor_rec.employee_id := vendor_int_rec.employee_id;
2180 vendor_rec.vendor_type_lookup_code := vendor_int_rec.vendor_type_lookup_code;
2181 vendor_rec.customer_num := vendor_int_rec.customer_num;
2182 vendor_rec.one_time_flag := vendor_int_rec.one_time_flag;
2183 vendor_rec.min_order_amount := vendor_int_rec.min_order_amount;
2184 vendor_rec.terms_id := vendor_int_rec.terms_id;
2185 vendor_rec.terms_name := vendor_int_rec.terms_name;
2186 vendor_rec.set_of_books_id := vendor_int_rec.set_of_books_id;
2187 vendor_rec.always_take_disc_flag := vendor_int_rec.always_take_disc_flag;
2188 vendor_rec.pay_date_basis_lookup_code := vendor_int_rec.pay_date_basis_lookup_code;
2189 vendor_rec.pay_group_lookup_code := vendor_int_rec.pay_group_lookup_code;
2190 vendor_rec.payment_priority := vendor_int_rec.payment_priority;
2191 vendor_rec.invoice_currency_code := vendor_int_rec.invoice_currency_code;
2192 vendor_rec.payment_currency_code := vendor_int_rec.payment_currency_code;
2193 vendor_rec.invoice_amount_limit := vendor_int_rec.invoice_amount_limit;
2194 vendor_rec.hold_all_payments_flag := vendor_int_rec.hold_all_payments_flag;
2195 vendor_rec.hold_future_payments_flag := vendor_int_rec.hold_future_payments_flag;
2196 vendor_rec.hold_reason := vendor_int_rec.hold_reason;
2197
2198 IF length(vendor_int_rec.num_1099) > 20 THEN
2199
2200 UPDATE ap_suppliers_int
2201 SET status = 'REJECTED'
2202 WHERE vendor_interface_id = vendor_int_rec.vendor_interface_id
2203 AND sdh_batch_id = p_batch_id;
2204
2205 IF (insert_rejections(p_batch_id,
2206 l_request_id,
2207 'AP_SUPPLIERS_INT',
2208 vendor_rec.vendor_interface_id,
2209 'AP_INVALID_NUM_1099',
2210 g_user_id,
2211 g_login_id,
2212 'IMPORT_VENDORS') <> TRUE) THEN
2213
2214 IF (g_level_procedure >= g_current_runtime_level) THEN
2215 fnd_msg_pub.count_and_get(p_count => l_msg_count,
2216 p_data => l_msg_data);
2217 fnd_log.string(g_level_procedure,
2218 g_module_name || l_api_name,
2219 ' Rejected Vendor_Interface_Id: ' ||
2220 vendor_int_rec.vendor_interface_id ||
2221 'as length of num_1099 > 20 ');
2222 END IF;
2223 END IF;
2224 x_return_status := fnd_api.g_ret_sts_error;
2225 fnd_file.put_line(fnd_file.log,
2226 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2227 ' failed for vendor_interface_id: ' ||
2228 vendor_int_rec.vendor_interface_id ||
2229 'as length of num_1099 > 20 ');
2230
2231 GOTO continue_next_record;
2232 END IF; /* length > 20 check */
2233
2234 vendor_rec.jgzz_fiscal_code := vendor_int_rec.num_1099;
2235 vendor_rec.type_1099 := vendor_int_rec.type_1099;
2236 vendor_rec.organization_type_lookup_code := vendor_int_rec.organization_type_lookup_code;
2237 vendor_rec.start_date_active := vendor_int_rec.start_date_active;
2238 vendor_rec.end_date_active := vendor_int_rec.end_date_active;
2239 vendor_rec.minority_group_lookup_code := vendor_int_rec.minority_group_lookup_code;
2240 vendor_rec.women_owned_flag := vendor_int_rec.women_owned_flag;
2241 vendor_rec.small_business_flag := vendor_int_rec.small_business_flag;
2242 vendor_rec.sic_code := vendor_int_rec.standard_industry_class;
2243 vendor_rec.hold_flag := vendor_int_rec.hold_flag;
2244 vendor_rec.purchasing_hold_reason := vendor_int_rec.purchasing_hold_reason;
2245 vendor_rec.hold_by := vendor_int_rec.hold_by;
2246 vendor_rec.hold_date := vendor_int_rec.hold_date;
2247 vendor_rec.terms_date_basis := vendor_int_rec.terms_date_basis;
2248 vendor_rec.inspection_required_flag := vendor_int_rec.inspection_required_flag;
2249 vendor_rec.receipt_required_flag := vendor_int_rec.receipt_required_flag;
2250 vendor_rec.qty_rcv_tolerance := vendor_int_rec.qty_rcv_tolerance;
2251 vendor_rec.qty_rcv_exception_code := vendor_int_rec.qty_rcv_exception_code;
2252 vendor_rec.enforce_ship_to_location_code := vendor_int_rec.enforce_ship_to_location_code;
2253 vendor_rec.days_early_receipt_allowed := vendor_int_rec.days_early_receipt_allowed;
2254 vendor_rec.days_late_receipt_allowed := vendor_int_rec.days_late_receipt_allowed;
2255 vendor_rec.receipt_days_exception_code := vendor_int_rec.receipt_days_exception_code;
2256 vendor_rec.receiving_routing_id := vendor_int_rec.receiving_routing_id;
2257 vendor_rec.allow_substitute_receipts_flag := vendor_int_rec.allow_substitute_receipts_flag;
2258 vendor_rec.allow_unordered_receipts_flag := vendor_int_rec.allow_unordered_receipts_flag;
2259 vendor_rec.hold_unmatched_invoices_flag := vendor_int_rec.hold_unmatched_invoices_flag;
2260 vendor_rec.tax_verification_date := vendor_int_rec.tax_verification_date;
2261 vendor_rec.name_control := vendor_int_rec.name_control;
2262 vendor_rec.state_reportable_flag := vendor_int_rec.state_reportable_flag;
2263 vendor_rec.federal_reportable_flag := vendor_int_rec.federal_reportable_flag;
2264 vendor_rec.attribute_category := vendor_int_rec.attribute_category;
2265 vendor_rec.attribute1 := vendor_int_rec.attribute1;
2266 vendor_rec.attribute2 := vendor_int_rec.attribute2;
2267 vendor_rec.attribute3 := vendor_int_rec.attribute3;
2268 vendor_rec.attribute4 := vendor_int_rec.attribute4;
2269 vendor_rec.attribute5 := vendor_int_rec.attribute5;
2270 vendor_rec.attribute6 := vendor_int_rec.attribute6;
2271 vendor_rec.attribute7 := vendor_int_rec.attribute7;
2272 vendor_rec.attribute8 := vendor_int_rec.attribute8;
2273 vendor_rec.attribute9 := vendor_int_rec.attribute9;
2274 vendor_rec.attribute10 := vendor_int_rec.attribute10;
2275 vendor_rec.attribute11 := vendor_int_rec.attribute11;
2276 vendor_rec.attribute12 := vendor_int_rec.attribute12;
2277 vendor_rec.attribute13 := vendor_int_rec.attribute13;
2278 vendor_rec.attribute14 := vendor_int_rec.attribute14;
2279 vendor_rec.attribute15 := vendor_int_rec.attribute15;
2280 vendor_rec.auto_calculate_interest_flag := vendor_int_rec.auto_calculate_interest_flag;
2281 vendor_rec.exclude_freight_from_discount := vendor_int_rec.exclude_freight_from_discount;
2282 vendor_rec.tax_reporting_name := vendor_int_rec.tax_reporting_name;
2283 vendor_rec.allow_awt_flag := vendor_int_rec.allow_awt_flag;
2284 vendor_rec.awt_group_id := vendor_int_rec.awt_group_id;
2285 vendor_rec.awt_group_name := vendor_int_rec.awt_group_name;
2286 vendor_rec.pay_awt_group_id := vendor_int_rec.pay_awt_group_id;
2287 vendor_rec.pay_awt_group_name := vendor_int_rec.pay_awt_group_name;
2288 vendor_rec.global_attribute1 := vendor_int_rec.global_attribute1;
2289 vendor_rec.global_attribute2 := vendor_int_rec.global_attribute2;
2290 vendor_rec.global_attribute3 := vendor_int_rec.global_attribute3;
2291 vendor_rec.global_attribute4 := vendor_int_rec.global_attribute4;
2292 vendor_rec.global_attribute5 := vendor_int_rec.global_attribute5;
2293 vendor_rec.global_attribute6 := vendor_int_rec.global_attribute6;
2294 vendor_rec.global_attribute7 := vendor_int_rec.global_attribute7;
2295 vendor_rec.global_attribute8 := vendor_int_rec.global_attribute8;
2296 vendor_rec.global_attribute9 := vendor_int_rec.global_attribute9;
2297 vendor_rec.global_attribute10 := vendor_int_rec.global_attribute10;
2298 vendor_rec.global_attribute11 := vendor_int_rec.global_attribute11;
2299 vendor_rec.global_attribute12 := vendor_int_rec.global_attribute12;
2300 vendor_rec.global_attribute13 := vendor_int_rec.global_attribute13;
2301 vendor_rec.global_attribute14 := vendor_int_rec.global_attribute14;
2302 vendor_rec.global_attribute15 := vendor_int_rec.global_attribute15;
2303 vendor_rec.global_attribute16 := vendor_int_rec.global_attribute16;
2304 vendor_rec.global_attribute17 := vendor_int_rec.global_attribute17;
2305 vendor_rec.global_attribute18 := vendor_int_rec.global_attribute18;
2306 vendor_rec.global_attribute19 := vendor_int_rec.global_attribute19;
2307 vendor_rec.global_attribute20 := vendor_int_rec.global_attribute20;
2308 vendor_rec.global_attribute_category := vendor_int_rec.global_attribute_category;
2309 vendor_rec.bank_charge_bearer := vendor_int_rec.bank_charge_bearer;
2310 vendor_rec.match_option := vendor_int_rec.match_option;
2311 vendor_rec.create_debit_memo_flag := vendor_int_rec.create_debit_memo_flag;
2312 vendor_rec.tax_reference := vendor_int_rec.vat_registration_num;
2313
2314 /* Populating IBY Records and Table */
2315
2316 ext_payee_rec.payment_function := 'PAYABLES_DISB';
2317 /* Commented by Suchita for the bug7583123
2318 ext_payee_rec.payer_org_type := 'OPERATING_UNIT'; */
2319 ext_payee_rec.exclusive_pay_flag := nvl(vendor_int_rec.exclusive_payment_flag,
2320 'N');
2321
2322 ext_payee_rec.default_pmt_method := vendor_int_rec.payment_method_lookup_code;
2323 ext_payee_rec.ece_tp_loc_code := vendor_int_rec.ece_tp_location_code;
2324 ext_payee_rec.bank_charge_bearer := vendor_int_rec.iby_bank_charge_bearer;
2325 ext_payee_rec.bank_instr1_code := vendor_int_rec.bank_instruction1_code;
2326 ext_payee_rec.bank_instr2_code := vendor_int_rec.bank_instruction2_code;
2327 ext_payee_rec.bank_instr_detail := vendor_int_rec.bank_instruction_details;
2328 ext_payee_rec.pay_reason_code := vendor_int_rec.payment_reason_code;
2329 ext_payee_rec.pay_reason_com := vendor_int_rec.payment_reason_comments;
2330 ext_payee_rec.pay_message1 := vendor_int_rec.payment_text_message1;
2331 ext_payee_rec.pay_message2 := vendor_int_rec.payment_text_message2;
2332 ext_payee_rec.pay_message3 := vendor_int_rec.payment_text_message3;
2333 ext_payee_rec.delivery_channel := vendor_int_rec.delivery_channel_code;
2334 ext_payee_rec.pmt_format := vendor_int_rec.payment_format_code;
2335 ext_payee_rec.settlement_priority := vendor_int_rec.settlement_priority;
2336
2337 -- Populating the ext_payee_rec of Vendor_rec
2338 ext_payee_rec.edi_payment_format := vendor_int_rec.edi_payment_format;
2339 ext_payee_rec.edi_transaction_handling := vendor_int_rec.edi_transaction_handling;
2340 ext_payee_rec.edi_payment_method := vendor_int_rec.edi_payment_method;
2341 ext_payee_rec.edi_remittance_method := vendor_int_rec.edi_remittance_method;
2342 ext_payee_rec.edi_remittance_instruction := vendor_int_rec.edi_remittance_instruction;
2343
2344 vendor_rec.ext_payee_rec.default_pmt_method := vendor_int_rec.payment_method_lookup_code;
2345 vendor_rec.ext_payee_rec.payment_function := 'PAYABLES_DISB';
2346 vendor_rec.ext_payee_rec.payer_org_type := 'OPERATING_UNIT';
2347 vendor_rec.ext_payee_rec.exclusive_pay_flag := nvl(vendor_int_rec.exclusive_payment_flag,
2348 'N');
2349 vendor_rec.ext_payee_rec.default_pmt_method := vendor_int_rec.payment_method_lookup_code;
2350 vendor_rec.ext_payee_rec.ece_tp_loc_code := vendor_int_rec.ece_tp_location_code;
2351 vendor_rec.ext_payee_rec.bank_charge_bearer := vendor_int_rec.iby_bank_charge_bearer;
2352 vendor_rec.ext_payee_rec.bank_instr1_code := vendor_int_rec.bank_instruction1_code;
2353 vendor_rec.ext_payee_rec.bank_instr2_code := vendor_int_rec.bank_instruction2_code;
2354 vendor_rec.ext_payee_rec.bank_instr_detail := vendor_int_rec.bank_instruction_details;
2355 vendor_rec.ext_payee_rec.pay_reason_code := vendor_int_rec.payment_reason_code;
2356 vendor_rec.ext_payee_rec.pay_reason_com := vendor_int_rec.payment_reason_comments;
2357 vendor_rec.ext_payee_rec.pay_message1 := vendor_int_rec.payment_text_message1;
2358 vendor_rec.ext_payee_rec.pay_message2 := vendor_int_rec.payment_text_message2;
2359 vendor_rec.ext_payee_rec.pay_message3 := vendor_int_rec.payment_text_message3;
2360 vendor_rec.ext_payee_rec.delivery_channel := vendor_int_rec.delivery_channel_code;
2361 vendor_rec.ext_payee_rec.pmt_format := vendor_int_rec.payment_format_code;
2362 vendor_rec.ext_payee_rec.settlement_priority := vendor_int_rec.settlement_priority;
2363
2364 fnd_file.put_line(fnd_file.log,
2365 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2366 ' vendor_interface_id: ' ||
2367 vendor_rec.vendor_interface_id || ' party_id: ' ||
2368 vendor_int_rec.party_id);
2369
2370 IF (vendor_int_rec.party_id IS NULL) THEN
2371 vendor_rec.party_id := get_party_id(vendor_int_rec.party_orig_system,
2372 vendor_int_rec.party_orig_system_reference);
2373 ELSE
2374 vendor_rec.party_id := vendor_int_rec.party_id;
2375 END IF;
2376
2377 IF (vendor_rec.party_id IS NULL OR vendor_rec.party_id = 0) THEN
2378 UPDATE ap_suppliers_int
2379 SET status = 'REJECTED'
2380 WHERE vendor_interface_id = vendor_rec.vendor_interface_id
2381 AND sdh_batch_id = p_batch_id;
2382
2383 IF (insert_rejections(p_batch_id,
2384 l_request_id,
2385 'AP_SUPPLIERS_INT',
2386 vendor_rec.vendor_interface_id,
2387 'POS_INVALID_PARTY_ORIG_SYSTEM',
2388 g_user_id,
2389 g_login_id,
2390 'IMPORT_VENDORS') <> TRUE) THEN
2391
2392 IF (g_level_procedure >= g_current_runtime_level) THEN
2393 fnd_msg_pub.count_and_get(p_count => l_msg_count,
2394 p_data => l_msg_data);
2395 fnd_log.string(g_level_procedure,
2396 g_module_name || l_api_name,
2397 ' Rejected vendor_interface_id: ' ||
2398 vendor_rec.vendor_interface_id ||
2399 ', No. of Messages: ' || l_msg_count ||
2400 ', Message: ' || l_msg_data);
2401 END IF;
2402 END IF;
2403 x_return_status := fnd_api.g_ret_sts_error;
2404 fnd_file.put_line(fnd_file.log,
2405 ' Invalid Orig System Combination for: ' ||
2406 ' vendor_interface_id: ' ||
2407 vendor_rec.vendor_interface_id);
2408 GOTO continue_next_record;
2409 END IF;
2410
2411 fnd_file.put_line(fnd_file.log,
2412 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2413 ' vendor_interface_id: ' ||
2414 vendor_rec.vendor_interface_id || ' party_id: ' ||
2415 vendor_rec.party_id);
2416
2417 l_vendor_num_code := chk_vendor_num_nmbering_method();
2418
2419 IF (l_vendor_num_code = 'MANUAL') THEN
2420 vendor_rec.segment1 := nvl(vendor_int_rec.segment1,
2421 vendor_int_rec.party_orig_system_reference);
2422 END IF;
2423
2424 BEGIN
2425 SELECT insert_update_flag
2426 INTO l_insert_update_flag
2427 FROM hz_imp_parties_int
2428 WHERE batch_id = p_batch_id
2429 AND party_orig_system = vendor_int_rec.party_orig_system
2430 AND party_orig_system_reference =
2431 vendor_int_rec.party_orig_system_reference;
2432
2433 EXCEPTION
2434 WHEN OTHERS THEN
2435 l_insert_update_flag := 'O';
2436 END;
2437
2438 IF (l_insert_update_flag = 'I') THEN
2439 fnd_file.put_line(fnd_file.log,
2440 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2441 ' Calling create_vendor insert_update_flag = I');
2442
2443 create_vendor(p_batch_id => p_batch_id,
2444 p_vendor_rec => vendor_rec,
2445 ext_payee_rec => ext_payee_rec,
2446 x_return_status => x_return_status,
2447 x_msg_count => x_msg_count,
2448 x_msg_data => x_msg_data);
2449
2450 ELSE
2451 -- Check if the vendor already exists
2452 OPEN check_vendor_exsists(vendor_rec.party_id);
2453 FETCH check_vendor_exsists
2454 INTO l_vendor_exists,
2455 l_vendor_id;
2456 CLOSE check_vendor_exsists;
2457
2458 -- If the vendor exists then upodate it
2459 IF l_vendor_exists <> 0 THEN
2460 l_vendor_exists := 0;
2461
2462 fnd_file.put_line(fnd_file.log,
2463 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2464 ' As vendor exists calling ap_vendor_pub_pkg.update_vendor for vendor id : ' ||
2465 l_vendor_id);
2466
2467 ap_vendor_pub_pkg.update_vendor(1.0,
2468 fnd_api.g_false,
2469 fnd_api.g_false,
2470 fnd_api.g_valid_level_full,
2471 l_return_status,
2472 l_msg_count,
2473 l_msg_data,
2474 vendor_rec,
2475 l_vendor_id);
2476
2477 IF l_return_status = fnd_api.g_ret_sts_success THEN
2478
2479 UPDATE ap_suppliers_int
2480 SET status = 'PROCESSED'
2481 WHERE vendor_interface_id = vendor_rec.vendor_interface_id
2482 AND sdh_batch_id = p_batch_id;
2483
2484 UPDATE pos_imp_batch_summary
2485 SET total_records_imported = total_records_imported + 1,
2486 total_updates = total_updates + 1,
2487 suppliers_updated = suppliers_updated + 1,
2488 suppliers_imported = suppliers_imported + 1
2489 WHERE batch_id = p_batch_id;
2490 ELSE
2491 UPDATE ap_suppliers_int
2492 SET status = 'REJECTED'
2493 WHERE vendor_interface_id = vendor_rec.vendor_interface_id
2494 AND sdh_batch_id = p_batch_id;
2495
2496 INSERT INTO pos_supplier_int_rejections
2497 (batch_id,
2498 import_request_id,
2499 parent_table,
2500 parent_id,
2501 reject_lookup_code,
2502 last_updated_by,
2503 last_update_date,
2504 last_update_login,
2505 created_by,
2506 creation_date)
2507 SELECT p_batch_id,
2508 l_request_id,
2509 parent_table,
2510 parent_id,
2511 reject_lookup_code,
2512 last_updated_by,
2513 last_update_date,
2514 last_update_login,
2515 created_by,
2516 creation_date
2517 FROM ap_supplier_int_rejections
2518 WHERE parent_table = 'AP_SUPPLIERS_INT'
2519 AND parent_id = vendor_rec.vendor_interface_id;
2520
2521 IF (g_level_procedure >= g_current_runtime_level) THEN
2522 fnd_log.string(g_level_procedure,
2523 g_module_name || l_api_name,
2524 ' Rejected Vendor_Interface_Id: ' ||
2525 vendor_rec.vendor_interface_id ||
2526 ', No. of Messages from update_vendor API: ' ||
2527 l_msg_count ||
2528 ', Message From update_vendor API: ' ||
2529 l_msg_data);
2530 END IF;
2531
2532 fnd_file.put_line(fnd_file.log,
2533 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2534 ' failed in ap_vendor_pub_pkg.update_vendor ' ||
2535 ' vendor_interface_id: ' ||
2536 vendor_rec.vendor_interface_id ||
2537 ', No. of Messages: ' || l_msg_count ||
2538 ', Message: ' || l_msg_data ||
2539 ', return status: ' || l_return_status);
2540
2541 x_return_status := l_return_status;
2542 x_msg_count := l_msg_count;
2543 x_msg_data := l_msg_data;
2544 END IF;
2545 ELSE
2546 fnd_file.put_line(fnd_file.log,
2547 ' Message: Inside PROCEDURE IMPORT_VENDORS' ||
2548 ' Calling create_vendor insert_update_flag = U');
2549
2550 create_vendor(p_batch_id => p_batch_id,
2551 p_vendor_rec => vendor_rec,
2552 ext_payee_rec => ext_payee_rec,
2553 x_return_status => x_return_status,
2554 x_msg_count => x_msg_count,
2555 x_msg_data => x_msg_data);
2556 END IF;
2557
2558 END IF;
2559 <<continue_next_record>>
2560 NULL;
2561 END LOOP;
2562
2563 CLOSE vendor_int_cur;
2564
2565 COMMIT WORK;
2566
2567 -- Standard call to get message count and if count is 1,
2568 -- get message info.
2569 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
2570 EXCEPTION
2571 WHEN fnd_api.g_exc_error THEN
2572 ROLLBACK TO import_vendor_pub;
2573 x_return_status := fnd_api.g_ret_sts_error;
2574 fnd_msg_pub.count_and_get(p_count => x_msg_count,
2575 p_data => x_msg_data);
2576 fnd_file.put_line(fnd_file.log,
2577 ' Inside import_vendors EXCEPTION ' || ' Message: ' ||
2578 SQLCODE || ' ' || SQLERRM);
2579 WHEN fnd_api.g_exc_unexpected_error THEN
2580 ROLLBACK TO import_vendor_pub;
2581 x_return_status := fnd_api.g_ret_sts_unexp_error;
2582 fnd_msg_pub.count_and_get(p_count => x_msg_count,
2583 p_data => x_msg_data);
2584 fnd_file.put_line(fnd_file.log,
2585 ' Inside import_vendors unexcepted EXCEPTION ' ||
2586 ' Message: ' || SQLCODE || ' ' || SQLERRM);
2587 WHEN OTHERS THEN
2588 ROLLBACK TO import_vendor_pub;
2589 x_return_status := fnd_api.g_ret_sts_unexp_error;
2590
2591 fnd_msg_pub.count_and_get(p_count => x_msg_count,
2592 p_data => x_msg_data);
2593 fnd_file.put_line(fnd_file.log,
2594 ' Inside import_vendors others EXCEPTION ' ||
2595 ' Message: ' || SQLCODE || ' ' || SQLERRM);
2596 END import_vendors;
2597
2598 PROCEDURE create_vendor_site
2599 (
2600 p_batch_id IN NUMBER,
2601 p_site_rec IN ap_vendor_pub_pkg.r_vendor_site_rec_type,
2602 ext_payee_rec IN OUT NOCOPY iby_disbursement_setup_pub.external_payee_rec_type,
2603 x_return_status OUT NOCOPY VARCHAR2,
2604 x_msg_count OUT NOCOPY NUMBER,
2605 x_msg_data OUT NOCOPY VARCHAR2
2606 ) IS
2607 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_VENDOR_SITE';
2608 l_request_id NUMBER := fnd_global.conc_request_id;
2609
2610 l_return_status VARCHAR2(2000);
2611 l_msg_count NUMBER;
2612 l_msg_data VARCHAR2(2000);
2613 l_vendor_site_id NUMBER;
2614 l_party_site_id NUMBER;
2615 l_location_id NUMBER;
2616
2617 /* Variable Declaration for IBY */
2618
2619 ext_payee_tab iby_disbursement_setup_pub.external_payee_tab_type;
2620
2621 ext_payee_id_tab iby_disbursement_setup_pub.ext_payee_id_tab_type;
2622
2623 ext_payee_create_tab iby_disbursement_setup_pub.ext_payee_create_tab_type;
2624 l_temp_ext_acct_id NUMBER;
2625 ext_response_rec iby_fndcpt_common_pub.result_rec_type;
2626
2627 l_ext_payee_id NUMBER;
2628 l_bank_acct_id NUMBER;
2629
2630 CURSOR iby_ext_accts_cur(p_unique_ref IN NUMBER) IS
2631 SELECT temp_ext_bank_acct_id
2632 FROM iby_temp_ext_bank_accts
2633 WHERE calling_app_unique_ref2 = p_unique_ref
2634 AND nvl(status, 'NEW') <> 'PROCESSED';
2635
2636 l_debug_info VARCHAR2(500);
2637 l_rollback_vendor_site VARCHAR2(1) := 'N';
2638 l_payee_msg_count NUMBER;
2639 l_payee_msg_data VARCHAR2(4000);
2640 l_error_code VARCHAR2(4000);
2641
2642 BEGIN
2643 x_return_status := fnd_api.g_ret_sts_success;
2644
2645 fnd_file.put_line(fnd_file.log,
2646 ' Message: Inside PROCEDURE CREATE_VENDOR_SITE' ||
2647 ' Parameters vendor_id: ' || p_site_rec.vendor_id ||
2648 ' vendor_site_interface_id: ' ||
2649 p_site_rec.vendor_site_interface_id);
2650
2651 SAVEPOINT import_vendor_sites_pub2;
2652
2653 ap_vendor_pub_pkg.create_vendor_site(p_api_version => 1.0,
2654 p_init_msg_list => fnd_api.g_true,
2655 p_commit => fnd_api.g_false,
2656 p_validation_level => fnd_api.g_valid_level_full,
2657 x_return_status => l_return_status,
2658 x_msg_count => l_msg_count,
2659 x_msg_data => l_msg_data,
2660 p_vendor_site_rec => p_site_rec,
2661 x_vendor_site_id => l_vendor_site_id,
2662 x_party_site_id => l_party_site_id,
2663 x_location_id => l_location_id);
2664
2665 IF l_return_status = fnd_api.g_ret_sts_success THEN
2666
2667 UPDATE ap_supplier_sites_int
2668 SET status = 'PROCESSED'
2669 WHERE vendor_site_interface_id = p_site_rec.vendor_site_interface_id
2670 AND sdh_batch_id = p_batch_id;
2671
2672 UPDATE pos_imp_batch_summary
2673 SET total_records_imported = total_records_imported + 1,
2674 total_inserts = total_inserts + 1,
2675 sites_inserted = sites_inserted + 1,
2676 sites_imported = sites_imported + 1
2677 WHERE batch_id = p_batch_id;
2678
2679 UPDATE ap_sup_site_contact_int
2680 SET vendor_site_id = l_vendor_site_id
2681 WHERE vendor_id = p_site_rec.vendor_id
2682 AND vendor_site_code = p_site_rec.vendor_site_code
2683 AND (org_id = p_site_rec.org_id OR
2684 operating_unit_name = p_site_rec.org_name)
2685 AND sdh_batch_id = p_batch_id;
2686
2687 ext_payee_rec.supplier_site_id := l_vendor_site_id;
2688 ext_payee_rec.payee_party_site_id := l_party_site_id;
2689
2690 SELECT org_id
2691 INTO ext_payee_rec.payer_org_id
2692 FROM po_vendor_sites_all
2693 WHERE vendor_site_id = l_vendor_site_id;
2694
2695 SELECT party_id,
2696 'PAYABLES_DISB'
2697 INTO ext_payee_rec.payee_party_id,
2698 ext_payee_rec.payment_function
2699 FROM po_vendors
2700 WHERE vendor_id = p_site_rec.vendor_id;
2701
2702 fnd_msg_pub.count_and_get(p_count => l_payee_msg_count,
2703 p_data => l_payee_msg_data);
2704
2705 /* Calling IBY Payee Validation API */
2706 iby_disbursement_setup_pub.validate_external_payee(p_api_version => 1.0,
2707 p_init_msg_list => fnd_api.g_true,
2708 p_ext_payee_rec => ext_payee_rec,
2709 x_return_status => l_return_status,
2710 x_msg_count => l_msg_count,
2711 x_msg_data => l_msg_data);
2712
2713 IF l_return_status = fnd_api.g_ret_sts_success THEN
2714 ext_payee_tab(1) := ext_payee_rec;
2715
2716 /* Calling IBY Payee Creation API */
2717 iby_disbursement_setup_pub.create_external_payee(p_api_version => 1.0,
2718 p_init_msg_list => fnd_api.g_true,
2719 p_ext_payee_tab => ext_payee_tab,
2720 x_return_status => l_return_status,
2721 x_msg_count => l_msg_count,
2722 x_msg_data => l_msg_data,
2723 x_ext_payee_id_tab => ext_payee_id_tab,
2724 x_ext_payee_status_tab => ext_payee_create_tab);
2725
2726 IF l_return_status = fnd_api.g_ret_sts_success THEN
2727 l_ext_payee_id := ext_payee_id_tab(1).ext_payee_id;
2728
2729 UPDATE iby_temp_ext_bank_accts
2730 SET ext_payee_id = l_ext_payee_id,
2731 account_owner_party_id = ext_payee_rec.payee_party_id --bug 6753331
2732 WHERE calling_app_unique_ref2 =
2733 p_site_rec.vendor_site_interface_id;
2734
2735 -- Cursor processing for iby temp bank account record
2736 OPEN iby_ext_accts_cur(p_site_rec.vendor_site_interface_id);
2737 LOOP
2738
2739 FETCH iby_ext_accts_cur
2740 INTO l_temp_ext_acct_id;
2741 EXIT WHEN iby_ext_accts_cur%NOTFOUND;
2742
2743 /* Calling IBY Bank Account Validation API */
2744 iby_disbursement_setup_pub.validate_temp_ext_bank_acct(p_api_version => 1.0,
2745 p_init_msg_list => fnd_api.g_true,
2746 x_return_status => l_return_status,
2747 x_msg_count => l_msg_count,
2748 x_msg_data => l_msg_data,
2749 p_temp_ext_acct_id => l_temp_ext_acct_id);
2750
2751 IF l_return_status = fnd_api.g_ret_sts_success THEN
2752 /* Calling IBY Bank Account Creation API */
2753
2754 iby_disbursement_setup_pub.create_temp_ext_bank_acct(p_api_version => 1.0,
2755 p_init_msg_list => fnd_api.g_true,
2756 x_return_status => l_return_status,
2757 x_msg_count => l_msg_count,
2758 x_msg_data => l_msg_data,
2759 p_temp_ext_acct_id => l_temp_ext_acct_id,
2760 p_association_level => 'SS',
2761 p_supplier_site_id => l_vendor_site_id,
2762 p_party_site_id => ext_payee_rec.payee_party_site_id,
2763 p_org_id => ext_payee_rec.payer_org_id,
2764 p_org_type => 'OPERATING_UNIT',
2765 x_bank_acc_id => l_bank_acct_id,
2766 x_response => ext_response_rec);
2767
2768 IF l_return_status = fnd_api.g_ret_sts_success THEN
2769 UPDATE iby_temp_ext_bank_accts
2770 SET status = 'PROCESSED'
2771 WHERE temp_ext_bank_acct_id = l_temp_ext_acct_id;
2772
2773 ELSE
2774 l_rollback_vendor_site := 'Y';
2775
2776 fnd_message.set_name('SQLAP', 'AP_BANK_ACCT_CREATION');
2777 fnd_msg_pub.add;
2778
2779 END IF; -- Bank Account Creation API
2780
2781 ELSE
2782 l_rollback_vendor_site := 'Y';
2783
2784 fnd_message.set_name('SQLAP', 'AP_INVALID_BANK_ACCT_INFO');
2785 fnd_msg_pub.add;
2786
2787 END IF; -- Bank Account Validation API
2788
2789 END LOOP;
2790 CLOSE iby_ext_accts_cur;
2791
2792 /*Rollback if bank account creation fails*/
2793 IF l_rollback_vendor_site = 'Y' THEN
2794
2795 ROLLBACK TO import_vendor_sites_pub2;
2796
2797 UPDATE ap_supplier_sites_int
2798 SET status = 'REJECTED'
2799 WHERE vendor_site_interface_id =
2800 p_site_rec.vendor_site_interface_id
2801 AND sdh_batch_id = p_batch_id;
2802
2803 UPDATE iby_temp_ext_bank_accts
2804 SET status = 'REJECTED'
2805 WHERE temp_ext_bank_acct_id = l_temp_ext_acct_id;
2806
2807 IF (insert_rejections(p_batch_id,
2808 l_request_id,
2809 'AP_SUPPLIER_SITES_INT',
2810 p_site_rec.vendor_site_interface_id,
2811 'AP_INVALID_BANK_ACCT_INFO',
2812 g_user_id,
2813 g_login_id,
2814 'Create_Vendor_Site') <> TRUE) THEN
2815
2816 IF (g_level_procedure >= g_current_runtime_level) THEN
2817 fnd_msg_pub.count_and_get(p_count => l_msg_count,
2818 p_data => l_msg_data);
2819 fnd_log.string(g_level_procedure,
2820 g_module_name || l_api_name,
2821 'Parameters: ' ||
2822 ' Vendor_Site_Interface_Id: ' ||
2823 p_site_rec.vendor_site_interface_id ||
2824 ' Acct Validation Msg: ' || l_msg_data);
2825 END IF;
2826 END IF;
2827
2828 fnd_file.put_line(fnd_file.log,
2829 ' Message: Inside PROCEDURE CREATE_VENDOR_SITE' ||
2830 ' failed in bank account creation ' ||
2831 ' vendor_site_interface_id: ' ||
2832 p_site_rec.vendor_site_interface_id ||
2833 ' temp_ext_bank_acct_id: ' ||
2834 l_temp_ext_acct_id);
2835
2836 l_rollback_vendor_site := 'N'; --resetting the value to initial
2837 END IF;
2838
2839 ELSE
2840 -- Payee Creation API
2841 IF (insert_rejections(p_batch_id,
2842 l_request_id,
2843 'AP_SUPPLIER_SITES_INT',
2844 p_site_rec.vendor_site_interface_id,
2845 'AP_PAYEE_CREATION',
2846 g_user_id,
2847 g_login_id,
2848 'Create_Vendor_Site') <> TRUE) THEN
2849
2850 IF (g_level_procedure >= g_current_runtime_level) THEN
2851 fnd_msg_pub.count_and_get(p_count => l_msg_count,
2852 p_data => l_msg_data);
2853 fnd_log.string(g_level_procedure,
2854 g_module_name || l_api_name,
2855 'Parameters: ' ||
2856 ' Vendor_Site_Interface_Id: ' ||
2857 p_site_rec.vendor_site_interface_id ||
2858 ' Payee Validation Msg: ' || l_msg_data);
2859 END IF;
2860 END IF;
2861
2862 fnd_message.set_name('SQLAP', 'AP_PAYEE_CREATION');
2863 fnd_msg_pub.add;
2864
2865 fnd_file.put_line(fnd_file.log,
2866 ' Message: Inside PROCEDURE CREATE_VENDOR_SITE' ||
2867 ' failed in payee creation ' ||
2868 ' vendor_site_interface_id: ' ||
2869 p_site_rec.vendor_site_interface_id);
2870
2871 END IF; -- Payee Creation API
2872
2873 ELSE
2874 -- Payee Validation API
2875 IF (insert_rejections(p_batch_id,
2876 l_request_id,
2877 'AP_SUPPLIER_SITES_INT',
2878 p_site_rec.vendor_site_interface_id,
2879 'AP_INVALID_PAYEE_INFO',
2880 g_user_id,
2881 g_login_id,
2882 'Create_Vendor_Site') <> TRUE) THEN
2883
2884 IF (g_level_procedure >= g_current_runtime_level) THEN
2885 fnd_msg_pub.count_and_get(p_count => l_msg_count,
2886 p_data => l_msg_data);
2887 fnd_log.string(g_level_procedure,
2888 g_module_name || l_api_name,
2889 'Parameters: ' || ' Vendor_Site_Interface_Id: ' ||
2890 p_site_rec.vendor_site_interface_id ||
2891 ' Payee Validation Msg: ' || l_msg_data);
2892 END IF;
2893 END IF;
2894
2895 l_debug_info := 'Calling IBY Payee Validation API in import site';
2896 IF (l_msg_data IS NOT NULL) THEN
2897 -- Print the error returned from the IBY service even if the debug
2898 -- mode is off
2899 ap_import_utilities_pkg.print('Y',
2900 '4)Error in ' || l_debug_info ||
2901 '---------------------->' ||
2902 l_msg_data);
2903
2904 ELSE
2905 -- If the l_msg_data is null then the IBY service returned
2906 -- more than one error. The calling module will need to get
2907 -- them from the message stack
2908 FOR i IN l_payee_msg_count .. l_msg_count LOOP
2909 l_error_code := fnd_msg_pub.get(p_msg_index => i,
2910 p_encoded => 'F');
2911
2912 IF i = l_payee_msg_count THEN
2913 l_error_code := '4)Error in ' || l_debug_info ||
2914 '---------------------->' || l_error_code;
2915 END IF;
2916
2917 ap_import_utilities_pkg.print('Y', l_error_code);
2918
2919 END LOOP;
2920
2921 END IF;
2922
2923 fnd_message.set_name('SQLAP', 'AP_INVALID_PAYEE_INFO');
2924 fnd_msg_pub.add;
2925
2926 fnd_file.put_line(fnd_file.log,
2927 ' Message: Inside PROCEDURE CREATE_VENDOR_SITE' ||
2928 ' failed in payee validation ' ||
2929 ' vendor_site_interface_id: ' ||
2930 p_site_rec.vendor_site_interface_id);
2931
2932 END IF; -- Payee Validation API
2933
2934 ELSE
2935 -- Supplier Site Creation API
2936 UPDATE ap_supplier_sites_int
2937 SET status = 'REJECTED'
2938 WHERE vendor_site_interface_id = p_site_rec.vendor_site_interface_id
2939 AND sdh_batch_id = p_batch_id;
2940
2941 INSERT INTO pos_supplier_int_rejections
2942 (batch_id,
2943 import_request_id,
2944 parent_table,
2945 parent_id,
2946 reject_lookup_code,
2947 last_updated_by,
2948 last_update_date,
2949 last_update_login,
2950 created_by,
2951 creation_date)
2952 SELECT p_batch_id,
2953 l_request_id,
2954 parent_table,
2955 parent_id,
2956 decode(reject_lookup_code,
2957 'AP_INCONSISTENT_ADDRESS',
2958 'POS_INCONSISTENT_ADDRESS',
2959 reject_lookup_code),
2960 last_updated_by,
2961 last_update_date,
2962 last_update_login,
2963 created_by,
2964 creation_date
2965 FROM ap_supplier_int_rejections
2966 WHERE parent_table = 'AP_SUPPLIER_SITES_INT'
2967 AND parent_id = p_site_rec.vendor_site_interface_id;
2968
2969 IF (g_level_procedure >= g_current_runtime_level) THEN
2970 fnd_log.string(g_level_procedure,
2971 g_module_name || l_api_name,
2972 ' Rejected Vendor_Site_Interface_Id: ' ||
2973 p_site_rec.vendor_site_interface_id ||
2974 ', No. of Messages from Create_Vendor_Site API: ' ||
2975 l_msg_count ||
2976 ', Message From Create_Vendor_Site API: ' ||
2977 l_msg_data);
2978 END IF;
2979
2980 error_handler.get_message_list(l_error_msg_tbl);
2981 IF l_error_msg_tbl.first IS NOT NULL THEN
2982 l_msg_count := l_error_msg_tbl.first;
2983 WHILE l_msg_count IS NOT NULL LOOP
2984 fnd_file.put_line(fnd_file.log,
2985 ' Message: Inside PROCEDURE CREATE_VENDOR_SITE' ||
2986 ' failed in ap_vendor_pub_pkg.create_vendor_site ' ||
2987 ' vendor_site_interface_id: ' ||
2988 p_site_rec.vendor_site_interface_id ||
2989 ', No. of Messages: ' || l_msg_count ||
2990 ', Message: ' || l_error_msg_tbl(l_msg_count)
2991 .message_text);
2992 l_msg_count := l_error_msg_tbl.next(l_msg_count);
2993 END LOOP;
2994 ELSE
2995 fnd_file.put_line(fnd_file.log,
2996 ' Message: Inside PROCEDURE CREATE_VENDOR_SITE' ||
2997 ' failed in ap_vendor_pub_pkg.create_vendor_site ' ||
2998 ' vendor_site_interface_id: ' ||
2999 p_site_rec.vendor_site_interface_id);
3000 END IF;
3001 x_return_status := l_return_status;
3002 x_msg_count := l_msg_count;
3003 x_msg_data := l_msg_data;
3004
3005 END IF; -- Supplier Site Creation API
3006 EXCEPTION
3007 WHEN OTHERS THEN
3008 x_return_status := fnd_api.g_ret_sts_unexp_error;
3009
3010 fnd_msg_pub.count_and_get(p_count => x_msg_count,
3011 p_data => x_msg_data);
3012 fnd_file.put_line(fnd_file.log,
3013 ' Inside create_vendor_site EXCEPTION ' ||
3014 ' Message: ' || SQLCODE || ' ' || SQLERRM);
3015 END create_vendor_site;
3016
3017 PROCEDURE import_vendor_sites
3018 (
3019 p_batch_id IN NUMBER,
3020 x_return_status OUT NOCOPY VARCHAR2,
3021 x_msg_count OUT NOCOPY NUMBER,
3022 x_msg_data OUT NOCOPY VARCHAR2
3023 ) IS
3024 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDOR_SITES';
3025 l_request_id NUMBER := fnd_global.conc_request_id;
3026
3027 l_return_status VARCHAR2(2000);
3028 l_msg_count NUMBER;
3029 l_msg_data VARCHAR2(2000);
3030 l_insert_update_flag VARCHAR2(1);
3031 l_vendor_site_id NUMBER;
3032 l_party_id NUMBER;
3033
3034 CURSOR site_int_cur IS
3035 SELECT *
3036 FROM ap_supplier_sites_int supp
3037 WHERE import_request_id = l_request_id
3038 AND (org_id IS NOT NULL OR operating_unit_name IS NOT NULL)
3039 AND sdh_batch_id = p_batch_id
3040 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
3041 AND NOT EXISTS
3042 (SELECT 1
3043 FROM hz_imp_addresses_int party
3044 WHERE batch_id = p_batch_id
3045 AND supp.sdh_batch_id = party.batch_id
3046 AND supp.party_orig_system = party.party_orig_system
3047 AND supp.party_orig_system_reference =
3048 party.party_orig_system_reference
3049 AND supp.party_site_orig_system = party.site_orig_system
3050 AND supp.party_site_orig_sys_reference =
3051 party.site_orig_system_reference
3052 AND party.interface_status = 'R');
3053
3054 site_int_rec site_int_cur%ROWTYPE;
3055 site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;
3056
3057 /* Variable Declaration for IBY */
3058 ext_payee_rec iby_disbursement_setup_pub.external_payee_rec_type;
3059
3060 CURSOR check_vendor_site_exsists
3061 (
3062 cp_vendor_id IN NUMBER,
3063 cp_vendor_site_code IN VARCHAR2,
3064 cp_operating_unit IN VARCHAR2,
3065 cp_org_id IN NUMBER
3066 ) IS
3067 SELECT 1,
3068 vendor_site_id
3069 FROM ap_supplier_sites_all site
3070 WHERE vendor_id = cp_vendor_id
3071 AND vendor_site_code = cp_vendor_site_code;
3072 --Bug 14400745 Remove below condition since it will not allow user update any inactive sites
3073 --AND (site.inactive_date > SYSDATE OR site.inactive_date IS NULL);
3074
3075 l_vendor_site_exists NUMBER := 0;
3076 BEGIN
3077
3078 -- Standard Start of API savepoint
3079 SAVEPOINT import_vendor_sites_pub;
3080
3081 -- fnd_msg_pub.initialize;
3082
3083 -- Initialize API return status to success
3084 x_return_status := fnd_api.g_ret_sts_success;
3085
3086 DELETE ap_supplier_int_rejections
3087 WHERE parent_table = 'AP_SUPPLIER_SITES_INT';
3088
3089 -- API body
3090
3091 -- This update statement resets the unprocessed rows so
3092 -- that they get picked in the current run.
3093 UPDATE ap_supplier_sites_int api
3094 SET import_request_id = NULL
3095 WHERE import_request_id IS NOT NULL
3096 AND sdh_batch_id = p_batch_id
3097 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
3098 AND EXISTS (SELECT 'Request Completed'
3099 FROM fnd_concurrent_requests fcr
3100 WHERE fcr.request_id = api.import_request_id
3101 AND fcr.phase_code = 'C');
3102
3103 -- Updating Interface Record with request id
3104
3105 UPDATE ap_supplier_sites_int
3106 SET import_request_id = l_request_id
3107 WHERE import_request_id IS NULL
3108 AND sdh_batch_id = p_batch_id
3109 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
3110
3111 UPDATE ap_supplier_sites_int
3112 SET status = 'REJECTED',
3113 import_request_id = l_request_id
3114 WHERE (operating_unit_name IS NULL AND org_id IS NULL)
3115 AND sdh_batch_id = p_batch_id
3116 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
3117
3118 INSERT INTO pos_supplier_int_rejections
3119 (SELECT p_batch_id,
3120 l_request_id,
3121 'AP_SUPPLIER_SITES_INT',
3122 vendor_site_interface_id,
3123 'AP_ORG_INFO_NULL',
3124 g_user_id,
3125 SYSDATE,
3126 g_login_id,
3127 g_user_id,
3128 SYSDATE
3129 FROM ap_supplier_sites_int
3130 WHERE status = 'REJECTED'
3131 AND import_request_id = l_request_id
3132 AND (operating_unit_name IS NULL AND org_id IS NULL)
3133 AND sdh_batch_id = p_batch_id);
3134
3135 UPDATE ap_supplier_sites_int supp
3136 SET status = 'REMOVED',
3137 import_request_id = l_request_id
3138 WHERE sdh_batch_id = p_batch_id
3139 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
3140 AND EXISTS
3141 (SELECT 1
3142 FROM hz_imp_addresses_int party
3143 WHERE batch_id = p_batch_id
3144 AND supp.sdh_batch_id = party.batch_id
3145 AND supp.party_orig_system = party.party_orig_system
3146 AND supp.party_orig_system_reference =
3147 party.party_orig_system_reference
3148 AND supp.party_site_orig_system = party.site_orig_system
3149 AND supp.party_site_orig_sys_reference =
3150 party.site_orig_system_reference
3151 AND party.interface_status = 'R');
3152
3153 fnd_file.put_line(fnd_file.log,
3154 ' Message: Inside PROCEDURE IMPORT_VENDOR_SITES' ||
3155 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
3156 ' records. Reason interface_status in hz_imp_addresses_int = R');
3157
3158 INSERT INTO pos_supplier_int_rejections
3159 (SELECT p_batch_id,
3160 l_request_id,
3161 'AP_SUPPLIER_SITES_INT',
3162 vendor_site_interface_id,
3163 'POS_INVALID_PARTY_ORIG_SYSTEM',
3164 g_user_id,
3165 SYSDATE,
3166 g_login_id,
3167 g_user_id,
3168 SYSDATE
3169 FROM ap_supplier_sites_int
3170 WHERE status = 'REMOVED'
3171 AND import_request_id = l_request_id
3172 AND sdh_batch_id = p_batch_id);
3173
3174 fnd_file.put_line(fnd_file.log,
3175 ' Message: Inside PROCEDURE IMPORT_VENDOR_SITES' ||
3176 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
3177 ' request_id: ' || l_request_id);
3178 COMMIT;
3179
3180 SAVEPOINT import_vendor_sites_pub; --Incase there is an unexpected error in loop below,
3181 --the rollback in exception can happen to this savepoint, since
3182 --after commit the savepoint set at the begining would be lost.
3183
3184 ap_vendor_pub_pkg.g_source := 'IMPORT';
3185
3186 -- Cursor processing for vendor site interface record
3187 OPEN site_int_cur;
3188 LOOP
3189
3190 FETCH site_int_cur
3191 INTO site_int_rec;
3192 EXIT WHEN site_int_cur%NOTFOUND;
3193
3194 site_rec.vendor_site_interface_id := site_int_rec.vendor_site_interface_id;
3195 site_rec.vendor_interface_id := site_int_rec.vendor_interface_id;
3196
3197 IF (site_int_rec.vendor_id IS NULL) THEN
3198 IF (site_int_rec.party_id IS NULL) THEN
3199 l_party_id := get_party_id(site_int_rec.party_orig_system,
3200 site_int_rec.party_orig_system_reference);
3201 ELSE
3202 l_party_id := site_int_rec.party_id;
3203 END IF;
3204
3205 BEGIN
3206 SELECT vendor_id
3207 INTO site_rec.vendor_id
3208 FROM ap_suppliers supp
3209 WHERE supp.party_id = l_party_id;
3210
3211 EXCEPTION
3212 WHEN OTHERS THEN
3213 UPDATE ap_supplier_sites_int
3214 SET status = 'REJECTED'
3215 WHERE vendor_site_interface_id =
3216 site_int_rec.vendor_site_interface_id
3217 AND sdh_batch_id = p_batch_id;
3218
3219 IF (insert_rejections(p_batch_id,
3220 l_request_id,
3221 'AP_SUPPLIER_SITES_INT',
3222 site_int_rec.vendor_site_interface_id,
3223 'AP_VENDOR_ID_NULL',
3224 g_user_id,
3225 g_login_id,
3226 'IMPORT_VENDOR_SITES') <> TRUE) THEN
3227
3228 IF (g_level_procedure >= g_current_runtime_level) THEN
3229 fnd_msg_pub.count_and_get(p_count => l_msg_count,
3230 p_data => l_msg_data);
3231 fnd_log.string(g_level_procedure,
3232 g_module_name || l_api_name,
3233 ' Rejected vendor_site_interface_id: ' ||
3234 site_int_rec.vendor_site_interface_id ||
3235 ', No. of Messages: ' || l_msg_count ||
3236 ', Message: ' || l_msg_data);
3237 END IF;
3238 END IF;
3239 x_return_status := fnd_api.g_ret_sts_error;
3240 fnd_file.put_line(fnd_file.log,
3241 ' Vendor ID is null for: ' ||
3242 ' vendor_site_interface_id: ' ||
3243 site_int_rec.vendor_site_interface_id ||
3244 ' party_id: ' || l_party_id);
3245 GOTO continue_next_record;
3246 END;
3247 ELSE
3248 site_rec.vendor_id := site_int_rec.vendor_id;
3249 END IF;
3250
3251 fnd_file.put_line(fnd_file.log,
3252 ' Message: Inside PROCEDURE IMPORT_VENDOR_SITES' ||
3253 ' vendor_site_interface_id: ' ||
3254 site_rec.vendor_site_interface_id || ' party_id: ' ||
3255 l_party_id || ' vendor_id: ' || site_rec.vendor_id);
3256
3257 site_rec.vendor_site_code := site_int_rec.vendor_site_code;
3258 site_rec.vendor_site_code_alt := site_int_rec.vendor_site_code_alt;
3259 site_rec.purchasing_site_flag := site_int_rec.purchasing_site_flag;
3260 site_rec.rfq_only_site_flag := site_int_rec.rfq_only_site_flag;
3261 site_rec.pay_site_flag := site_int_rec.pay_site_flag;
3262 site_rec.attention_ar_flag := site_int_rec.attention_ar_flag;
3263
3264 site_rec.address_line1 := rtrim(site_int_rec.address_line1);
3265 site_rec.address_lines_alt := rtrim(site_int_rec.address_lines_alt);
3266 site_rec.address_line2 := rtrim(site_int_rec.address_line2);
3267 site_rec.address_line3 := rtrim(site_int_rec.address_line3);
3268 site_rec.city := rtrim(site_int_rec.city);
3269 site_rec.state := rtrim(site_int_rec.state);
3270 site_rec.zip := site_int_rec.zip;
3271 site_rec.province := site_int_rec.province;
3272 site_rec.country := site_int_rec.country;
3273 site_rec.phone := site_int_rec.phone;
3274 site_rec.area_code := site_int_rec.area_code;
3275 site_rec.customer_num := site_int_rec.customer_num;
3276 site_rec.ship_to_location_id := site_int_rec.ship_to_location_id;
3277 site_rec.ship_to_location_code := site_int_rec.ship_to_location_code;
3278 site_rec.bill_to_location_id := site_int_rec.bill_to_location_id;
3279 site_rec.bill_to_location_code := site_int_rec.bill_to_location_code;
3280 site_rec.ship_via_lookup_code := site_int_rec.ship_via_lookup_code;
3281 site_rec.freight_terms_lookup_code := site_int_rec.freight_terms_lookup_code;
3282 site_rec.fob_lookup_code := site_int_rec.fob_lookup_code;
3283 site_rec.inactive_date := site_int_rec.inactive_date;
3284 site_rec.fax := site_int_rec.fax;
3285 site_rec.fax_area_code := site_int_rec.fax_area_code;
3286 site_rec.telex := site_int_rec.telex;
3287 site_rec.terms_date_basis := site_int_rec.terms_date_basis;
3288 site_rec.distribution_set_id := site_int_rec.distribution_set_id;
3289 site_rec.distribution_set_name := site_int_rec.distribution_set_name;
3290 site_rec.accts_pay_code_combination_id := site_int_rec.accts_pay_code_combination_id;
3291 site_rec.prepay_code_combination_id := site_int_rec.prepay_code_combination_id;
3292 site_rec.pay_group_lookup_code := site_int_rec.pay_group_lookup_code;
3293 site_rec.payment_priority := site_int_rec.payment_priority;
3294 site_rec.terms_id := site_int_rec.terms_id;
3295 site_rec.terms_name := site_int_rec.terms_name;
3296
3297 site_rec.tolerance_id := site_int_rec.tolerance_id;
3298 site_rec.tolerance_name := site_int_rec.tolerance_name;
3299
3300 site_rec.invoice_amount_limit := site_int_rec.invoice_amount_limit;
3301 site_rec.pay_date_basis_lookup_code := site_int_rec.pay_date_basis_lookup_code;
3302 site_rec.always_take_disc_flag := site_int_rec.always_take_disc_flag;
3303 site_rec.invoice_currency_code := site_int_rec.invoice_currency_code;
3304 site_rec.payment_currency_code := site_int_rec.payment_currency_code;
3305 site_rec.hold_all_payments_flag := site_int_rec.hold_all_payments_flag;
3306 site_rec.hold_future_payments_flag := site_int_rec.hold_future_payments_flag;
3307 site_rec.hold_reason := site_int_rec.hold_reason;
3308 site_rec.hold_unmatched_invoices_flag := site_int_rec.hold_unmatched_invoices_flag;
3309 site_rec.tax_reporting_site_flag := site_int_rec.tax_reporting_site_flag;
3310 site_rec.attribute_category := site_int_rec.attribute_category;
3311 site_rec.attribute1 := site_int_rec.attribute1;
3312 site_rec.attribute2 := site_int_rec.attribute2;
3313 site_rec.attribute3 := site_int_rec.attribute3;
3314 site_rec.attribute4 := site_int_rec.attribute4;
3315 site_rec.attribute5 := site_int_rec.attribute5;
3316 site_rec.attribute6 := site_int_rec.attribute6;
3317 site_rec.attribute7 := site_int_rec.attribute7;
3318 site_rec.attribute8 := site_int_rec.attribute8;
3319 site_rec.attribute9 := site_int_rec.attribute9;
3320 site_rec.attribute10 := site_int_rec.attribute10;
3321 site_rec.attribute11 := site_int_rec.attribute11;
3322 site_rec.attribute12 := site_int_rec.attribute12;
3323 site_rec.attribute13 := site_int_rec.attribute13;
3324 site_rec.attribute14 := site_int_rec.attribute14;
3325 site_rec.attribute15 := site_int_rec.attribute15;
3326 site_rec.exclude_freight_from_discount := site_int_rec.exclude_freight_from_discount;
3327 site_rec.org_id := site_int_rec.org_id;
3328 site_rec.org_name := site_int_rec.operating_unit_name;
3329 site_rec.address_line4 := rtrim(site_int_rec.address_line4);
3330 site_rec.county := site_int_rec.county;
3331 site_rec.address_style := site_int_rec.address_style;
3332 site_rec.language := site_int_rec.language;
3333 site_rec.allow_awt_flag := site_int_rec.allow_awt_flag;
3334 site_rec.awt_group_id := site_int_rec.awt_group_id;
3335 site_rec.awt_group_name := site_int_rec.awt_group_name;
3336 site_rec.global_attribute1 := site_int_rec.global_attribute1;
3337 site_rec.global_attribute2 := site_int_rec.global_attribute2;
3338 site_rec.global_attribute3 := site_int_rec.global_attribute3;
3339 site_rec.global_attribute4 := site_int_rec.global_attribute4;
3340 site_rec.global_attribute5 := site_int_rec.global_attribute5;
3341 site_rec.global_attribute6 := site_int_rec.global_attribute6;
3342 site_rec.global_attribute7 := site_int_rec.global_attribute7;
3343 site_rec.global_attribute8 := site_int_rec.global_attribute8;
3344 site_rec.global_attribute9 := site_int_rec.global_attribute9;
3345 site_rec.global_attribute10 := site_int_rec.global_attribute10;
3346 site_rec.global_attribute11 := site_int_rec.global_attribute11;
3347 site_rec.global_attribute12 := site_int_rec.global_attribute12;
3348 site_rec.global_attribute13 := site_int_rec.global_attribute13;
3349 site_rec.global_attribute14 := site_int_rec.global_attribute14;
3350 site_rec.global_attribute15 := site_int_rec.global_attribute15;
3351 site_rec.global_attribute16 := site_int_rec.global_attribute16;
3352 site_rec.global_attribute17 := site_int_rec.global_attribute17;
3353 site_rec.global_attribute18 := site_int_rec.global_attribute18;
3354 site_rec.global_attribute19 := site_int_rec.global_attribute19;
3355 site_rec.global_attribute20 := site_int_rec.global_attribute20;
3356 site_rec.global_attribute_category := site_int_rec.global_attribute_category;
3357 site_rec.bank_charge_bearer := site_int_rec.bank_charge_bearer;
3358 site_rec.pay_on_code := site_int_rec.pay_on_code;
3359 site_rec.pay_on_receipt_summary_code := site_int_rec.pay_on_receipt_summary_code;
3360 site_rec.default_pay_site_id := site_int_rec.default_pay_site_id;
3361 site_rec.tp_header_id := site_int_rec.tp_header_id;
3362 site_rec.ece_tp_location_code := site_int_rec.ece_tp_location_code;
3363 site_rec.pcard_site_flag := site_int_rec.pcard_site_flag;
3364 site_rec.match_option := site_int_rec.match_option;
3365 site_rec.country_of_origin_code := site_int_rec.country_of_origin_code;
3366 site_rec.future_dated_payment_ccid := site_int_rec.future_dated_payment_ccid;
3367 site_rec.create_debit_memo_flag := site_int_rec.create_debit_memo_flag;
3368 site_rec.supplier_notif_method := site_int_rec.supplier_notif_method;
3369 site_rec.email_address := site_int_rec.email_address;
3370 site_rec.primary_pay_site_flag := site_int_rec.primary_pay_site_flag;
3371 site_rec.shipping_control := site_int_rec.shipping_control;
3372 site_rec.duns_number := site_int_rec.duns_number;
3373 site_rec.retainage_rate := site_int_rec.retainage_rate;
3374 site_rec.vat_code := site_int_rec.vat_code;
3375
3376 site_rec.vat_registration_num := site_int_rec.vat_registration_num;
3377 site_rec.edi_id_number := site_int_rec.edi_id_number;
3378 /* Commented Suchita */
3379 -- site_rec.remit_advice_delivery_method := site_int_rec.remit_advice_delivery_method;
3380
3381 ext_payee_rec.payer_org_type := 'OPERATING_UNIT';
3382 ext_payee_rec.exclusive_pay_flag := nvl(site_int_rec.exclusive_payment_flag,
3383 'N');
3384
3385 ext_payee_rec.default_pmt_method := site_int_rec.payment_method_lookup_code;
3386 ext_payee_rec.ece_tp_loc_code := site_int_rec.ece_tp_location_code;
3387
3388 ext_payee_rec.bank_charge_bearer := site_int_rec.iby_bank_charge_bearer;
3389 ext_payee_rec.bank_instr1_code := site_int_rec.bank_instruction1_code;
3390 ext_payee_rec.bank_instr2_code := site_int_rec.bank_instruction2_code;
3391 ext_payee_rec.bank_instr_detail := site_int_rec.bank_instruction_details;
3392 ext_payee_rec.pay_reason_code := site_int_rec.payment_reason_code;
3393 ext_payee_rec.pay_reason_com := site_int_rec.payment_reason_comments;
3394 ext_payee_rec.pay_message1 := site_int_rec.payment_text_message1;
3395 ext_payee_rec.pay_message2 := site_int_rec.payment_text_message2;
3396 ext_payee_rec.pay_message3 := site_int_rec.payment_text_message3;
3397 ext_payee_rec.delivery_channel := site_int_rec.delivery_channel_code;
3398 ext_payee_rec.pmt_format := site_int_rec.payment_format_code;
3399 ext_payee_rec.settlement_priority := site_int_rec.settlement_priority;
3400
3401 -- Note that we must populate these EDI related fields only to ext_payee_rec
3402 -- Because only this record is passed for call to IBY in case of import.
3403 -- There is no need to populate site_rec.ext_payee_rec.
3404 -- Even if we pass it wont be used.
3405 ext_payee_rec.edi_payment_format := site_int_rec.edi_payment_format;
3406 ext_payee_rec.edi_transaction_handling := site_int_rec.edi_transaction_handling;
3407 ext_payee_rec.edi_payment_method := site_int_rec.edi_payment_method;
3408 ext_payee_rec.edi_remittance_method := site_int_rec.edi_remittance_method;
3409 ext_payee_rec.edi_remittance_instruction := site_int_rec.edi_remittance_instruction;
3410
3411 site_rec.ext_payee_rec.payer_org_type := 'OPERATING_UNIT';
3412 site_rec.ext_payee_rec.payment_function := 'PAYABLES_DISB';
3413 site_rec.ext_payee_rec.exclusive_pay_flag := nvl(site_int_rec.exclusive_payment_flag,
3414 'N');
3415 site_rec.ext_payee_rec.default_pmt_method := site_int_rec.payment_method_lookup_code;
3416 site_rec.ext_payee_rec.ece_tp_loc_code := site_int_rec.ece_tp_location_code;
3417 site_rec.ext_payee_rec.bank_charge_bearer := site_int_rec.iby_bank_charge_bearer;
3418 site_rec.ext_payee_rec.bank_instr1_code := site_int_rec.bank_instruction1_code;
3419 site_rec.ext_payee_rec.bank_instr2_code := site_int_rec.bank_instruction2_code;
3420 site_rec.ext_payee_rec.bank_instr_detail := site_int_rec.bank_instruction_details;
3421 site_rec.ext_payee_rec.pay_reason_code := site_int_rec.payment_reason_code;
3422 site_rec.ext_payee_rec.pay_reason_com := site_int_rec.payment_reason_comments;
3423 site_rec.ext_payee_rec.pay_message1 := site_int_rec.payment_text_message1;
3424 site_rec.ext_payee_rec.pay_message2 := site_int_rec.payment_text_message2;
3425 site_rec.ext_payee_rec.pay_message3 := site_int_rec.payment_text_message3;
3426 site_rec.ext_payee_rec.delivery_channel := site_int_rec.delivery_channel_code;
3427 site_rec.ext_payee_rec.pmt_format := site_int_rec.payment_format_code;
3428 site_rec.ext_payee_rec.settlement_priority := site_int_rec.settlement_priority;
3429
3430 site_rec.supplier_notif_method := site_int_rec.supplier_notif_method;
3431 site_rec.email_address := site_int_rec.email_address;
3432 /* Commented Suchita */
3433 /*site_rec.remittance_email := site_int_rec.remittance_email;
3434 site_rec.ext_payee_rec.remit_advice_delivery_method := site_int_rec.remit_advice_delivery_method;*/
3435 site_rec.ext_payee_rec.remit_advice_email := site_int_rec.remittance_email;
3436
3437 site_rec.party_site_id := site_int_rec.party_site_id;
3438 site_rec.party_site_name := site_int_rec.party_site_name;
3439
3440 site_rec.auto_tax_calc_flag := site_int_rec.auto_tax_calc_flag;
3441 site_rec.offset_tax_flag := site_int_rec.offset_tax_flag;
3442
3443 BEGIN
3444 SELECT insert_update_flag
3445 INTO l_insert_update_flag
3446 FROM hz_imp_addresses_int
3447 WHERE batch_id = p_batch_id
3448 AND party_orig_system = site_int_rec.party_orig_system
3449 AND party_orig_system_reference =
3450 site_int_rec.party_orig_system_reference
3451 AND site_orig_system = site_int_rec.party_site_orig_system
3452 AND site_orig_system_reference =
3453 site_int_rec.party_site_orig_sys_reference;
3454
3455 EXCEPTION
3456 WHEN OTHERS THEN
3457 l_insert_update_flag := 'O';
3458 END;
3459
3460 fnd_file.put_line(fnd_file.log,
3461 ' Message: Inside PROCEDURE IMPORT_VENDOR_SITES' ||
3462 ' Parameters insert_update_flag: ' ||
3463 l_insert_update_flag ||
3464 ' for vendor_site_interface_id: ' ||
3465 site_rec.vendor_site_interface_id);
3466
3467 IF (l_insert_update_flag = 'I') THEN
3468 create_vendor_site(p_batch_id => p_batch_id,
3469 p_site_rec => site_rec,
3470 ext_payee_rec => ext_payee_rec,
3471 x_return_status => x_return_status,
3472 x_msg_count => x_msg_count,
3473 x_msg_data => x_msg_data);
3474 ELSE
3475 /* Check whether supplier site exist */
3476 OPEN check_vendor_site_exsists(site_rec.vendor_id,
3477 site_rec.vendor_site_code,
3478 site_rec.org_name,
3479 site_rec.org_id);
3480 FETCH check_vendor_site_exsists
3481 INTO l_vendor_site_exists,
3482 l_vendor_site_id;
3483 CLOSE check_vendor_site_exsists;
3484
3485 -- If the vendor exists then update it
3486 IF l_vendor_site_exists <> 0 THEN
3487 l_vendor_site_exists := 0;
3488
3489 fnd_file.put_line(fnd_file.log,
3490 ' Message: Inside PROCEDURE IMPORT_VENDOR_SITES' ||
3491 ' As vendor site exists calling' ||
3492 ' ap_vendor_pub_pkg.update_vendor_site for vendor_site_id: ' ||
3493 l_vendor_site_id);
3494
3495 site_rec.vendor_site_code := null; --Bug 16441477 avoid duplicate supplier site checking
3496
3497 ap_vendor_pub_pkg.update_vendor_site(1.0,
3498 fnd_api.g_false,
3499 fnd_api.g_false,
3500 fnd_api.g_valid_level_full,
3501 l_return_status,
3502 l_msg_count,
3503 l_msg_data,
3504 site_rec,
3505 l_vendor_site_id);
3506
3507 IF l_return_status = fnd_api.g_ret_sts_success THEN
3508
3509 UPDATE ap_supplier_sites_int
3510 SET status = 'PROCESSED'
3511 WHERE vendor_site_interface_id =
3512 site_rec.vendor_site_interface_id
3513 AND sdh_batch_id = p_batch_id;
3514
3515 UPDATE pos_imp_batch_summary
3516 SET total_records_imported = total_records_imported + 1,
3517 total_updates = total_updates + 1,
3518 sites_updated = sites_updated + 1,
3519 sites_imported = sites_imported + 1
3520 WHERE batch_id = p_batch_id;
3521 ELSE
3522 UPDATE ap_supplier_sites_int
3523 SET status = 'REJECTED'
3524 WHERE vendor_site_interface_id =
3525 site_rec.vendor_site_interface_id
3526 AND sdh_batch_id = p_batch_id;
3527
3528 INSERT INTO pos_supplier_int_rejections
3529 (batch_id,
3530 import_request_id,
3531 parent_table,
3532 parent_id,
3533 reject_lookup_code,
3534 last_updated_by,
3535 last_update_date,
3536 last_update_login,
3537 created_by,
3538 creation_date)
3539 SELECT p_batch_id,
3540 l_request_id,
3541 parent_table,
3542 parent_id,
3543 reject_lookup_code,
3544 last_updated_by,
3545 last_update_date,
3546 last_update_login,
3547 created_by,
3548 creation_date
3549 FROM ap_supplier_int_rejections
3550 WHERE parent_table = 'AP_SUPPLIER_SITES_INT'
3551 AND parent_id = site_rec.vendor_site_interface_id;
3552
3553 IF (g_level_procedure >= g_current_runtime_level) THEN
3554 fnd_log.string(g_level_procedure,
3555 g_module_name || l_api_name,
3556 ' Rejected vendor_site_interface_id: ' ||
3557 site_rec.vendor_site_interface_id ||
3558 ', No. of Messages from update_vendor_site API: ' ||
3559 l_msg_count ||
3560 ', Message From update_vendor_site API: ' ||
3561 l_msg_data);
3562 END IF;
3563
3564 fnd_file.put_line(fnd_file.log,
3565 ' Message: Inside PROCEDURE IMPORT_VENDOR_SITES' ||
3566 ' failed in ap_vendor_pub_pkg.update_vendor_site ' ||
3567 ' vendor_site_interface_id: ' ||
3568 site_rec.vendor_site_interface_id ||
3569 ', No. of Messages: ' || l_msg_count ||
3570 ', Message: ' || l_msg_data ||
3571 ', Return Status: ' || l_return_status);
3572
3573 x_return_status := l_return_status;
3574 x_msg_count := l_msg_count;
3575 x_msg_data := l_msg_data;
3576
3577 END IF;
3578 ELSE
3579 create_vendor_site(p_batch_id => p_batch_id,
3580 p_site_rec => site_rec,
3581 ext_payee_rec => ext_payee_rec,
3582 x_return_status => x_return_status,
3583 x_msg_count => x_msg_count,
3584 x_msg_data => x_msg_data);
3585 END IF;
3586 END IF;
3587 <<continue_next_record>>
3588 NULL;
3589 END LOOP;
3590
3591 CLOSE site_int_cur;
3592
3593 -- End of API body.
3594
3595 -- Standard check of p_commit.
3596 COMMIT WORK;
3597
3598 -- Standard call to get message count and if count is 1,
3599 -- get message info.
3600 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
3601
3602 EXCEPTION
3603 WHEN fnd_api.g_exc_error THEN
3604 ROLLBACK TO import_vendor_sites_pub;
3605 x_return_status := fnd_api.g_ret_sts_error;
3606 fnd_msg_pub.count_and_get(p_count => x_msg_count,
3607 p_data => x_msg_data);
3608 fnd_file.put_line(fnd_file.log,
3609 ' Inside import_vendor_sites EXCEPTION ' ||
3610 ' Message: ' || SQLCODE || ' ' || SQLERRM);
3611 WHEN fnd_api.g_exc_unexpected_error THEN
3612 ROLLBACK TO import_vendor_sites_pub;
3613 x_return_status := fnd_api.g_ret_sts_unexp_error;
3614 fnd_msg_pub.count_and_get(p_count => x_msg_count,
3615 p_data => x_msg_data);
3616 fnd_file.put_line(fnd_file.log,
3617 ' Inside import_vendor_sites unexcepted EXCEPTION ' ||
3618 ' Message: ' || SQLCODE || ' ' || SQLERRM);
3619 WHEN OTHERS THEN
3620 ROLLBACK TO import_vendor_sites_pub;
3621 x_return_status := fnd_api.g_ret_sts_unexp_error;
3622
3623 fnd_msg_pub.count_and_get(p_count => x_msg_count,
3624 p_data => x_msg_data);
3625 fnd_file.put_line(fnd_file.log,
3626 ' Inside import_vendor_sites others EXCEPTION ' ||
3627 ' Message: ' || SQLCODE || ' ' || SQLERRM);
3628 END import_vendor_sites;
3629
3630 PROCEDURE create_vendor_contact
3631 (
3632 p_batch_id IN NUMBER,
3633 x_return_status OUT NOCOPY VARCHAR2,
3634 x_msg_count OUT NOCOPY NUMBER,
3635 x_msg_data OUT NOCOPY VARCHAR2,
3636 p_vendor_contact_rec IN ap_vendor_pub_pkg.r_vendor_contact_rec_type
3637 ) IS
3638 l_api_name CONSTANT VARCHAR2(30) := 'CREATE_VENDOR_CONTACT';
3639 l_request_id NUMBER := fnd_global.conc_request_id;
3640
3641 l_return_status VARCHAR2(2000);
3642 l_msg_count NUMBER;
3643 l_msg_data VARCHAR2(2000);
3644 l_vendor_contact_id NUMBER;
3645 l_per_party_id NUMBER;
3646 l_rel_party_id NUMBER;
3647 l_rel_id NUMBER;
3648 l_org_contact_id NUMBER;
3649 l_party_site_id NUMBER;
3650
3651 CURSOR l_cur IS
3652 SELECT 1
3653 FROM ap_supplier_contacts
3654 WHERE org_party_site_id = p_vendor_contact_rec.org_party_site_id
3655 AND per_party_id = p_vendor_contact_rec.per_party_id
3656 AND (inactive_date IS NULL OR inactive_date >= SYSDATE)
3657 AND rownum = 1;
3658
3659 l_number NUMBER;
3660 BEGIN
3661 x_return_status := fnd_api.g_ret_sts_success;
3662
3663 fnd_file.put_line(fnd_file.log,
3664 ' Message: Inside PROCEDURE CREATE_VENDOR_CONTACT' ||
3665 ' Parameters vendor_id: ' ||
3666 p_vendor_contact_rec.vendor_id ||
3667 ' vendor_contact_interface_id: ' ||
3668 p_vendor_contact_rec.vendor_contact_interface_id);
3669
3670 OPEN l_cur;
3671 FETCH l_cur
3672 INTO l_number;
3673 IF l_cur%FOUND THEN
3674 -- already has such assignment
3675 CLOSE l_cur;
3676 l_return_status := fnd_api.g_ret_sts_success;
3677 ELSE
3678 ap_vendor_pub_pkg.create_vendor_contact(p_api_version => 1.0,
3679 p_init_msg_list => fnd_api.g_true,
3680 p_commit => fnd_api.g_false,
3681 p_validation_level => fnd_api.g_valid_level_full,
3682 x_return_status => l_return_status,
3683 x_msg_count => l_msg_count,
3684 x_msg_data => l_msg_data,
3685 p_vendor_contact_rec => p_vendor_contact_rec,
3686 x_vendor_contact_id => l_vendor_contact_id,
3687 x_per_party_id => l_per_party_id,
3688 x_rel_party_id => l_rel_party_id,
3689 x_rel_id => l_rel_id,
3690 x_org_contact_id => l_org_contact_id,
3691 x_party_site_id => l_party_site_id);
3692
3693 END IF;
3694
3695 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3696
3697 IF (g_level_procedure >= g_current_runtime_level) THEN
3698 fnd_log.string(g_level_procedure,
3699 g_module_name || l_api_name,
3700 ' Rejected Vendor_Contact_Interface_Id: ' ||
3701 p_vendor_contact_rec.vendor_contact_interface_id ||
3702 ', No. of Messages from Create_Vendor_Contact API: ' ||
3703 l_msg_count ||
3704 ', Message From Create_Vendor_Contact API: ' ||
3705 l_msg_data);
3706 END IF;
3707
3708 fnd_file.put_line(fnd_file.log,
3709 ' Rejected Vendor_Contact_Interface_Id: ' ||
3710 p_vendor_contact_rec.vendor_contact_interface_id ||
3711 ', No. of Messages from Create_Vendor_Contact API: ' ||
3712 l_msg_count ||
3713 ', Message From Create_Vendor_Contact API: ' ||
3714 l_msg_data);
3715 END IF;
3716 x_return_status := l_return_status;
3717 x_msg_count := l_msg_count;
3718 x_msg_data := l_msg_data;
3719
3720 EXCEPTION
3721 WHEN OTHERS THEN
3722 x_return_status := fnd_api.g_ret_sts_unexp_error;
3723
3724 fnd_msg_pub.count_and_get(p_count => x_msg_count,
3725 p_data => x_msg_data);
3726 fnd_file.put_line(fnd_file.log,
3727 ' Inside create_vendor_contact EXCEPTION ' ||
3728 ' Message: ' || SQLCODE || ' ' || SQLERRM);
3729 END create_vendor_contact;
3730
3731 PROCEDURE import_vendor_contacts
3732 (
3733 p_batch_id IN NUMBER,
3734 x_return_status OUT NOCOPY VARCHAR2,
3735 x_msg_count OUT NOCOPY NUMBER,
3736 x_msg_data OUT NOCOPY VARCHAR2
3737 ) IS
3738 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDOR_CONTACTS';
3739
3740 l_request_id NUMBER := fnd_global.conc_request_id;
3741 l_insert_update_flag VARCHAR2(1);
3742 l_return_status VARCHAR2(2000);
3743 l_msg_count NUMBER;
3744 l_msg_data VARCHAR2(2000);
3745 l_per_party_id NUMBER;
3746 l_count NUMBER;
3747
3748 CURSOR contact_int_cur IS
3749 SELECT *
3750 FROM ap_sup_site_contact_int supp
3751 WHERE import_request_id = l_request_id
3752 AND (org_id IS NOT NULL OR operating_unit_name IS NOT NULL)
3753 AND last_name IS NOT NULL
3754 AND sdh_batch_id = p_batch_id
3755 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
3756 AND NOT EXISTS
3757 (SELECT 1
3758 FROM hz_imp_contacts_int party
3759 WHERE batch_id = p_batch_id
3760 AND supp.sdh_batch_id = party.batch_id
3761 AND supp.party_orig_system = party.obj_orig_system
3762 AND supp.party_orig_system_reference =
3763 party.obj_orig_system_reference
3764 AND supp.contact_orig_system = party.contact_orig_system
3765 AND supp.contact_orig_system_reference =
3766 party.contact_orig_system_reference
3767 AND party.interface_status = 'R');
3768
3769 contact_int_rec contact_int_cur%ROWTYPE;
3770 vendor_contact_rec ap_vendor_pub_pkg.r_vendor_contact_rec_type;
3771
3772 BEGIN
3773 -- Initialize API return status to success
3774 x_return_status := fnd_api.g_ret_sts_success;
3775
3776 DELETE ap_supplier_int_rejections
3777 WHERE parent_table = 'AP_SUP_SITE_CONTACT_INT';
3778
3779 -- API body
3780
3781 -- This update statement resets the unprocessed rows so
3782 -- that they get picked in the current run.
3783 UPDATE ap_sup_site_contact_int api
3784 SET import_request_id = NULL
3785 WHERE import_request_id IS NOT NULL
3786 AND sdh_batch_id = p_batch_id
3787 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
3788 AND EXISTS (SELECT 'Request Completed'
3789 FROM fnd_concurrent_requests fcr
3790 WHERE fcr.request_id = api.import_request_id
3791 AND fcr.phase_code = 'C');
3792
3793 -- Updating Interface Record with request id
3794
3795 UPDATE ap_sup_site_contact_int
3796 SET import_request_id = l_request_id
3797 WHERE import_request_id IS NULL
3798 AND sdh_batch_id = p_batch_id
3799 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
3800
3801 UPDATE ap_sup_site_contact_int
3802 SET status = 'REJECTED',
3803 import_request_id = l_request_id
3804 WHERE ((operating_unit_name IS NULL AND org_id IS NULL) OR
3805 (last_name IS NULL))
3806 AND sdh_batch_id = p_batch_id;
3807
3808 INSERT INTO pos_supplier_int_rejections
3809 (SELECT p_batch_id,
3810 l_request_id,
3811 'AP_SUP_SITE_CONTACT_INT',
3812 vendor_contact_interface_id,
3813 'AP_ORG_INFO_NULL',
3814 g_user_id,
3815 SYSDATE,
3816 g_login_id,
3817 g_user_id,
3818 SYSDATE
3819 FROM ap_sup_site_contact_int
3820 WHERE status = 'REJECTED'
3821 AND import_request_id = l_request_id
3822 AND sdh_batch_id = p_batch_id
3823 AND (operating_unit_name IS NULL AND org_id IS NULL)) UNION
3824 (SELECT p_batch_id,
3825 l_request_id,
3826 'AP_SUP_SITE_CONTACT_INT',
3827 vendor_contact_interface_id,
3828 'AP_LAST_NAME_NULL',
3829 g_user_id,
3830 SYSDATE,
3831 g_login_id,
3832 g_user_id,
3833 SYSDATE
3834 FROM ap_sup_site_contact_int
3835 WHERE status = 'REJECTED'
3836 AND import_request_id = l_request_id
3837 AND sdh_batch_id = p_batch_id
3838 AND last_name IS NULL);
3839
3840 UPDATE ap_sup_site_contact_int supp
3841 SET status = 'REMOVED',
3842 import_request_id = l_request_id
3843 WHERE sdh_batch_id = p_batch_id
3844 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
3845 AND EXISTS
3846 (SELECT 1
3847 FROM hz_imp_contacts_int party
3848 WHERE batch_id = p_batch_id
3849 AND supp.sdh_batch_id = party.batch_id
3850 AND supp.party_orig_system = party.obj_orig_system
3851 AND supp.party_orig_system_reference =
3852 party.obj_orig_system_reference
3853 AND supp.contact_orig_system = party.contact_orig_system
3854 AND supp.contact_orig_system_reference =
3855 party.contact_orig_system_reference
3856 AND party.interface_status = 'R');
3857
3858 fnd_file.put_line(fnd_file.log,
3859 ' Message: Inside PROCEDURE IMPORT_VENDOR_CONTACTS' ||
3860 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
3861 ' records. Reason interface_status in hz_imp_contacts_int = R');
3862
3863 INSERT INTO pos_supplier_int_rejections
3864 (SELECT p_batch_id,
3865 l_request_id,
3866 'AP_SUP_SITE_CONTACT_INT',
3867 vendor_contact_interface_id,
3868 'POS_INVALID_PARTY_ORIG_SYSTEM',
3869 g_user_id,
3870 SYSDATE,
3871 g_login_id,
3872 g_user_id,
3873 SYSDATE
3874 FROM ap_sup_site_contact_int
3875 WHERE status = 'REMOVED'
3876 AND import_request_id = l_request_id
3877 AND sdh_batch_id = p_batch_id);
3878
3879 fnd_file.put_line(fnd_file.log,
3880 ' Message: Inside PROCEDURE IMPORT_VENDOR_CONTACTS' ||
3881 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
3882 ' request_id: ' || l_request_id);
3883 COMMIT;
3884
3885 SAVEPOINT import_vendor_contact_pub;
3886
3887 ap_vendor_pub_pkg.g_source := 'IMPORT';
3888
3889 -- Cursor processing for vendor contact interface record
3890 OPEN contact_int_cur;
3891 LOOP
3892
3893 FETCH contact_int_cur
3894 INTO contact_int_rec;
3895 EXIT WHEN contact_int_cur%NOTFOUND;
3896
3897 vendor_contact_rec.vendor_contact_interface_id := contact_int_rec.vendor_contact_interface_id;
3898 vendor_contact_rec.vendor_site_id := contact_int_rec.vendor_site_id;
3899 vendor_contact_rec.person_first_name := contact_int_rec.first_name;
3900 vendor_contact_rec.person_middle_name := contact_int_rec.middle_name;
3901 vendor_contact_rec.person_last_name := contact_int_rec.last_name;
3902 vendor_contact_rec.person_title := contact_int_rec.title;
3903 vendor_contact_rec.person_first_name_phonetic := contact_int_rec.first_name_alt;
3904 vendor_contact_rec.person_last_name_phonetic := contact_int_rec.last_name_alt;
3905 vendor_contact_rec.contact_name_phonetic := contact_int_rec.contact_name_alt;
3906 vendor_contact_rec.prefix := contact_int_rec.prefix;
3907 vendor_contact_rec.inactive_date := contact_int_rec.inactive_date;
3908 vendor_contact_rec.department := contact_int_rec.department;
3909 vendor_contact_rec.mail_stop := contact_int_rec.mail_stop;
3910 vendor_contact_rec.area_code := contact_int_rec.area_code;
3911 vendor_contact_rec.phone := contact_int_rec.phone;
3912 vendor_contact_rec.alt_area_code := contact_int_rec.alt_area_code;
3913 vendor_contact_rec.alt_phone := contact_int_rec.alt_phone;
3914 vendor_contact_rec.fax_area_code := contact_int_rec.fax_area_code;
3915 vendor_contact_rec.fax_phone := contact_int_rec.fax;
3916 vendor_contact_rec.email_address := contact_int_rec.email_address;
3917 vendor_contact_rec.url := contact_int_rec.url;
3918 vendor_contact_rec.vendor_site_code := contact_int_rec.vendor_site_code;
3919 vendor_contact_rec.org_id := contact_int_rec.org_id;
3920 vendor_contact_rec.operating_unit_name := contact_int_rec.operating_unit_name;
3921 vendor_contact_rec.vendor_interface_id := contact_int_rec.vendor_interface_id;
3922
3923 IF (contact_int_rec.vendor_id IS NULL) THEN
3924 BEGIN
3925 SELECT vendor_id
3926 INTO vendor_contact_rec.vendor_id
3927 FROM ap_suppliers supp
3928 WHERE supp.party_id = contact_int_rec.party_id;
3929
3930 EXCEPTION
3931 WHEN OTHERS THEN
3932 UPDATE ap_sup_site_contact_int
3933 SET status = 'REJECTED'
3934 WHERE vendor_contact_interface_id =
3935 contact_int_rec.vendor_contact_interface_id
3936 AND sdh_batch_id = p_batch_id;
3937
3938 IF (insert_rejections(p_batch_id,
3939 l_request_id,
3940 'AP_SUP_SITE_CONTACT_INT',
3941 vendor_contact_rec.vendor_contact_interface_id,
3942 'AP_VENDOR_ID_NULL',
3943 g_user_id,
3944 g_login_id,
3945 'IMPORT_VENDOR_CONTACTS') <> TRUE) THEN
3946
3947 IF (g_level_procedure >= g_current_runtime_level) THEN
3948 fnd_msg_pub.count_and_get(p_count => l_msg_count,
3949 p_data => l_msg_data);
3950 fnd_log.string(g_level_procedure,
3951 g_module_name || l_api_name,
3952 ' Rejected vendor_contact_interface_id: ' ||
3953 vendor_contact_rec.vendor_contact_interface_id ||
3954 ', No. of Messages: ' || l_msg_count ||
3955 ', Message : ' || l_msg_data);
3956 END IF;
3957 END IF;
3958 x_return_status := fnd_api.g_ret_sts_error;
3959 fnd_file.put_line(fnd_file.log,
3960 ' Vendor ID is null for: ' ||
3961 ' vendor_contact_interface_id: ' ||
3962 vendor_contact_rec.vendor_contact_interface_id ||
3963 ' party_id: ' || contact_int_rec.party_id);
3964 GOTO continue_next_record;
3965 END;
3966 ELSE
3967 vendor_contact_rec.vendor_id := contact_int_rec.vendor_id;
3968 END IF;
3969
3970 fnd_file.put_line(fnd_file.log,
3971 ' Message: Inside PROCEDURE IMPORT_VENDOR_CONTACTS' ||
3972 ' vendor_contact_interface_id: ' ||
3973 vendor_contact_rec.vendor_contact_interface_id ||
3974 ' party_id: ' || contact_int_rec.party_id ||
3975 ' vendor_id: ' || vendor_contact_rec.vendor_id);
3976
3977 IF (contact_int_rec.party_site_id IS NOT NULL) THEN
3978 vendor_contact_rec.org_party_site_id := contact_int_rec.party_site_id;
3979 ELSE
3980 IF (contact_int_rec.party_site_orig_system IS NOT NULL AND
3981 contact_int_rec.party_site_orig_sys_reference IS NOT NULL) THEN
3982
3983 BEGIN
3984 SELECT owner_table_id
3985 INTO vendor_contact_rec.org_party_site_id
3986 FROM hz_orig_sys_references hr
3987 WHERE hr.owner_table_name = 'HZ_PARTY_SITES'
3988 AND hr.orig_system = contact_int_rec.party_site_orig_system
3989 AND hr.orig_system_reference =
3990 contact_int_rec.party_site_orig_sys_reference
3991 AND hr.status = 'A'
3992 AND nvl(hr.end_date_active, SYSDATE) >= SYSDATE;
3993
3994 EXCEPTION
3995 WHEN OTHERS THEN
3996 UPDATE ap_sup_site_contact_int
3997 SET status = 'REJECTED'
3998 WHERE vendor_contact_interface_id =
3999 contact_int_rec.vendor_contact_interface_id
4000 AND sdh_batch_id = p_batch_id;
4001
4002 IF (insert_rejections(p_batch_id,
4003 l_request_id,
4004 'AP_SUP_SITE_CONTACT_INT',
4005 vendor_contact_rec.vendor_contact_interface_id,
4006 'POS_INV_PARTY_SITE_ORIG_SYS',
4007 g_user_id,
4008 g_login_id,
4009 'IMPORT_VENDOR_CONTACTS') <> TRUE) THEN
4010
4011 IF (g_level_procedure >= g_current_runtime_level) THEN
4012 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4013 p_data => l_msg_data);
4014 fnd_log.string(g_level_procedure,
4015 g_module_name || l_api_name,
4016 ' Rejected vendor_contact_interface_id: ' ||
4017 vendor_contact_rec.vendor_contact_interface_id ||
4018 ', No. of Messages: ' || l_msg_count ||
4019 ', Message : ' || l_msg_data);
4020 END IF;
4021 END IF;
4022 x_return_status := fnd_api.g_ret_sts_error;
4023 fnd_file.put_line(fnd_file.log,
4024 ' Invalide party site orig sys and ref for: ' ||
4025 ' vendor_contact_interface_id: ' ||
4026 vendor_contact_rec.vendor_contact_interface_id);
4027 GOTO continue_next_record;
4028 END;
4029 END IF;
4030 END IF;
4031
4032 fnd_file.put_line(fnd_file.log,
4033 ' vendor_contact_rec.org_party_site_id: ' ||
4034 vendor_contact_rec.org_party_site_id ||
4035 ' for vendor_contact_interface_id: ' ||
4036 vendor_contact_rec.vendor_contact_interface_id);
4037
4038 vendor_contact_rec.party_site_name := contact_int_rec.party_site_name;
4039
4040 vendor_contact_rec.per_party_id := contact_int_rec.per_party_id;
4041 vendor_contact_rec.relationship_id := contact_int_rec.relationship_id;
4042 vendor_contact_rec.rel_party_id := contact_int_rec.rel_party_id;
4043 vendor_contact_rec.org_contact_id := contact_int_rec.org_contact_id;
4044
4045 vendor_contact_rec.vendor_site_id := NULL;
4046
4047 pos_supp_contact_pkg.update_supplier_contact(p_contact_party_id => vendor_contact_rec.per_party_id,
4048 p_vendor_party_id => contact_int_rec.party_id,
4049 p_first_name => vendor_contact_rec.person_first_name,
4050 p_last_name => vendor_contact_rec.person_last_name,
4051 p_middle_name => vendor_contact_rec.person_middle_name,
4052 p_contact_title => vendor_contact_rec.person_title,
4053 p_job_title => NULL,
4054 p_phone_area_code => vendor_contact_rec.area_code,
4055 p_phone_number => vendor_contact_rec.phone,
4056 p_phone_extension => NULL,
4057 p_fax_area_code => vendor_contact_rec.fax_area_code,
4058 p_fax_number => vendor_contact_rec.fax_phone,
4059 p_email_address => vendor_contact_rec.email_address,
4060 p_inactive_date => vendor_contact_rec.inactive_date,
4061 x_return_status => l_return_status,
4062 x_msg_count => l_msg_count,
4063 x_msg_data => l_msg_data,
4064 p_department => vendor_contact_rec.department);
4065
4066 fnd_file.put_line(fnd_file.log,
4067 'Before calling pos_supplier_address_pkg.assign_address_to_contact' ||
4068 ' vendor_contact_rec.per_party_id: ' ||
4069 vendor_contact_rec.per_party_id ||
4070 ' vendor_contact_rec.org_party_site_id: ' ||
4071 vendor_contact_rec.org_party_site_id ||
4072 ' vendor_contact_rec.vendor_id: ' ||
4073 vendor_contact_rec.vendor_id ||
4074 ' for vendor_contact_interface_id: ' ||
4075 vendor_contact_rec.vendor_contact_interface_id);
4076
4077 BEGIN
4078 SELECT 1
4079 INTO l_count
4080 FROM ap_suppliers pv,
4081 hz_relationships hzr,
4082 hz_org_contacts hoc
4083 WHERE pv.vendor_id = vendor_contact_rec.vendor_id
4084 AND hzr.relationship_type = 'CONTACT'
4085 AND hzr.relationship_code = 'CONTACT_OF'
4086 AND hzr.subject_id = vendor_contact_rec.per_party_id
4087 AND hzr.subject_type = 'PERSON'
4088 AND hzr.subject_table_name = 'HZ_PARTIES'
4089 AND hzr.object_type = 'ORGANIZATION'
4090 AND hzr.object_table_name = 'HZ_PARTIES'
4091 AND hzr.object_id = pv.party_id
4092 AND hzr.status = 'A'
4093 AND trunc(SYSDATE) BETWEEN trunc(hzr.start_date) AND
4094 nvl(trunc(hzr.end_date), trunc(SYSDATE + 1))
4095 AND hzr.relationship_id = hoc.party_relationship_id;
4096
4097 EXCEPTION
4098 WHEN OTHERS THEN
4099 UPDATE ap_sup_site_contact_int
4100 SET status = 'REJECTED'
4101 WHERE vendor_contact_interface_id =
4102 contact_int_rec.vendor_contact_interface_id
4103 AND sdh_batch_id = p_batch_id;
4104
4105 IF (insert_rejections(p_batch_id,
4106 l_request_id,
4107 'AP_SUP_SITE_CONTACT_INT',
4108 vendor_contact_rec.vendor_contact_interface_id,
4109 'POS_INVALID_PERSON_PARTY_REL',
4110 g_user_id,
4111 g_login_id,
4112 'IMPORT_VENDOR_CONTACTS') <> TRUE) THEN
4113
4114 IF (g_level_procedure >= g_current_runtime_level) THEN
4115 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4116 p_data => l_msg_data);
4117 fnd_log.string(g_level_procedure,
4118 g_module_name || l_api_name,
4119 ' Rejected vendor_contact_interface_id: ' ||
4120 vendor_contact_rec.vendor_contact_interface_id ||
4121 ', No. of Messages: ' || l_msg_count ||
4122 ', Message : ' || l_msg_data);
4123 END IF;
4124 END IF;
4125 x_return_status := fnd_api.g_ret_sts_error;
4126 fnd_file.put_line(fnd_file.log,
4127 ' Invalide person party id for: ' ||
4128 ' vendor_contact_interface_id: ' ||
4129 vendor_contact_rec.vendor_contact_interface_id);
4130 GOTO continue_next_record;
4131 END;
4132
4133 IF (vendor_contact_rec.org_party_site_id IS NOT NULL) THEN
4134 create_vendor_contact(p_batch_id => p_batch_id,
4135 x_return_status => l_return_status,
4136 x_msg_count => l_msg_count,
4137 x_msg_data => l_msg_data,
4138 p_vendor_contact_rec => vendor_contact_rec);
4139 /* pos_supplier_address_pkg.assign_address_to_contact(p_contact_party_id => vendor_contact_rec.per_party_id,
4140 p_org_party_site_id => vendor_contact_rec.org_party_site_id,
4141 p_vendor_id => vendor_contact_rec.vendor_id,
4142 x_return_status => l_return_status,
4143 x_msg_count => l_msg_count,
4144 x_msg_data => l_msg_data);*/
4145 ELSIF (vendor_contact_rec.party_site_name IS NOT NULL) THEN
4146 BEGIN
4147 SELECT party_site_id
4148 INTO vendor_contact_rec.org_party_site_id
4149 FROM hz_party_sites
4150 WHERE party_id = contact_int_rec.party_id
4151 AND party_site_name = vendor_contact_rec.party_site_name;
4152
4153 EXCEPTION
4154 WHEN OTHERS THEN
4155 UPDATE ap_sup_site_contact_int
4156 SET status = 'REJECTED'
4157 WHERE vendor_contact_interface_id =
4158 contact_int_rec.vendor_contact_interface_id
4159 AND sdh_batch_id = p_batch_id;
4160
4161 IF (insert_rejections(p_batch_id,
4162 l_request_id,
4163 'AP_SUP_SITE_CONTACT_INT',
4164 vendor_contact_rec.vendor_contact_interface_id,
4165 'POS_INVALID_PARTY_SITE_NAME',
4166 g_user_id,
4167 g_login_id,
4168 'IMPORT_VENDOR_CONTACTS') <> TRUE) THEN
4169
4170 IF (g_level_procedure >= g_current_runtime_level) THEN
4171 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4172 p_data => l_msg_data);
4173 fnd_log.string(g_level_procedure,
4174 g_module_name || l_api_name,
4175 ' Rejected vendor_contact_interface_id: ' ||
4176 vendor_contact_rec.vendor_contact_interface_id ||
4177 ', No. of Messages: ' || l_msg_count ||
4178 ', Message : ' || l_msg_data);
4179 END IF;
4180 END IF;
4181 x_return_status := fnd_api.g_ret_sts_error;
4182 fnd_file.put_line(fnd_file.log,
4183 ' Invalide party site name for: ' ||
4184 ' vendor_contact_interface_id: ' ||
4185 vendor_contact_rec.vendor_contact_interface_id);
4186 GOTO continue_next_record;
4187 END;
4188
4189 create_vendor_contact(p_batch_id => p_batch_id,
4190 x_return_status => l_return_status,
4191 x_msg_count => l_msg_count,
4192 x_msg_data => l_msg_data,
4193 p_vendor_contact_rec => vendor_contact_rec);
4194 END IF;
4195
4196 IF l_return_status = fnd_api.g_ret_sts_success THEN
4197 UPDATE ap_sup_site_contact_int
4198 SET status = 'PROCESSED'
4199 WHERE vendor_contact_interface_id =
4200 vendor_contact_rec.vendor_contact_interface_id
4201 AND sdh_batch_id = p_batch_id;
4202
4203 BEGIN
4204 SELECT nvl(insert_update_flag, 'U')
4205 INTO l_insert_update_flag
4206 FROM hz_imp_contacts_int
4207 WHERE batch_id = p_batch_id
4208 AND obj_orig_system = contact_int_rec.party_orig_system
4209 AND obj_orig_system_reference =
4210 contact_int_rec.party_orig_system_reference
4211 AND contact_orig_system = contact_int_rec.contact_orig_system
4212 AND contact_orig_system_reference =
4213 contact_int_rec.contact_orig_system_reference;
4214
4215 EXCEPTION
4216 WHEN OTHERS THEN
4217 l_insert_update_flag := 'U';
4218 END;
4219
4220 IF (l_insert_update_flag = 'I') THEN
4221 UPDATE pos_imp_batch_summary
4222 SET total_records_imported = total_records_imported + 1,
4223 total_inserts = total_inserts + 1,
4224 contacts_inserted = contacts_inserted + 1,
4225 contacts_imported = contacts_imported + 1
4226 WHERE batch_id = p_batch_id;
4227 ELSE
4228 UPDATE pos_imp_batch_summary
4229 SET total_records_imported = total_records_imported + 1,
4230 total_updates = total_updates + 1,
4231 contacts_updated = contacts_updated + 1,
4232 contacts_imported = contacts_imported + 1
4233 WHERE batch_id = p_batch_id;
4234 END IF;
4235 ELSE
4236 fnd_file.put_line(fnd_file.log,
4237 'Record Rejected :' ||
4238 vendor_contact_rec.vendor_contact_interface_id);
4239 UPDATE ap_sup_site_contact_int
4240 SET status = 'REJECTED'
4241 WHERE vendor_contact_interface_id =
4242 vendor_contact_rec.vendor_contact_interface_id
4243 AND sdh_batch_id = p_batch_id;
4244
4245 INSERT INTO pos_supplier_int_rejections
4246 (batch_id,
4247 import_request_id,
4248 parent_table,
4249 parent_id,
4250 reject_lookup_code,
4251 last_updated_by,
4252 last_update_date,
4253 last_update_login,
4254 created_by,
4255 creation_date)
4256 SELECT p_batch_id,
4257 l_request_id,
4258 parent_table,
4259 parent_id,
4260 reject_lookup_code,
4261 last_updated_by,
4262 last_update_date,
4263 last_update_login,
4264 created_by,
4265 creation_date
4266 FROM ap_supplier_int_rejections
4267 WHERE parent_table = 'AP_SUP_SITE_CONTACT_INT'
4268 AND parent_id = vendor_contact_rec.vendor_contact_interface_id;
4269 END IF;
4270 x_return_status := l_return_status;
4271 x_msg_count := l_msg_count;
4272 x_msg_data := l_msg_data;
4273 <<continue_next_record>>
4274 NULL;
4275 END LOOP;
4276
4277 CLOSE contact_int_cur;
4278
4279 -- End of API body.
4280
4281 COMMIT WORK;
4282
4283 -- Standard call to get message count and if count is 1,
4284 -- get message info.
4285 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
4286
4287 EXCEPTION
4288 WHEN fnd_api.g_exc_error THEN
4289 ROLLBACK TO import_vendor_contact_pub;
4290 x_return_status := fnd_api.g_ret_sts_error;
4291 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4292 p_data => x_msg_data);
4293 fnd_file.put_line(fnd_file.log,
4294 ' Inside import_vendor_contacts EXCEPTION ' ||
4295 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4296 WHEN fnd_api.g_exc_unexpected_error THEN
4297 ROLLBACK TO import_vendor_contact_pub;
4298 x_return_status := fnd_api.g_ret_sts_unexp_error;
4299 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4300 p_data => x_msg_data);
4301 fnd_file.put_line(fnd_file.log,
4302 ' Inside import_vendor_contacts unexpected EXCEPTION ' ||
4303 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4304 WHEN OTHERS THEN
4305 ROLLBACK TO import_vendor_contact_pub;
4306 x_return_status := fnd_api.g_ret_sts_unexp_error;
4307
4308 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4309 p_data => x_msg_data);
4310 fnd_file.put_line(fnd_file.log,
4311 ' Inside import_vendor_contacts others EXCEPTION ' ||
4312 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4313 END import_vendor_contacts;
4314
4315 PROCEDURE validate_vendor_prods_services
4316 (
4317 p_batch_id IN NUMBER,
4318 p_vendor_prodsrv_rec IN pos_product_service_int%ROWTYPE,
4319 p_party_id IN hz_parties.party_id%TYPE,
4320 x_return_status OUT NOCOPY VARCHAR2,
4321 x_msg_count OUT NOCOPY NUMBER,
4322 x_msg_data OUT NOCOPY VARCHAR2,
4323 x_prod_valid OUT NOCOPY VARCHAR2,
4324 x_segment_code OUT NOCOPY VARCHAR2
4325 ) IS
4326 TYPE cursor_ref_type IS REF CURSOR;
4327 l_product_segment_definition VARCHAR2(2000);
4328 l_product_segment_count NUMBER;
4329 l_default_po_category_set_id NUMBER;
4330 l_delimiter VARCHAR2(10);
4331 l_status VARCHAR(2000);
4332 l_error_message VARCHAR(4000);
4333
4334 l_msg_count NUMBER;
4335 l_msg_data VARCHAR2(2000);
4336 l_api_name CONSTANT VARCHAR2(50) := 'VALIDATE_VENDOR_PRODS_SERVICES';
4337 l_request_id NUMBER := fnd_global.conc_request_id;
4338
4339 l_pscur cursor_ref_type;
4340 l_sql VARCHAR2(4000) := NULL;
4341 l_seg_def fnd_profile_option_values.profile_option_value%TYPE;
4342
4343 l_start_pos NUMBER := 0;
4344 l_index NUMBER := 0;
4345 l_segment_code VARCHAR2(4000) := NULL;
4346 l_segment_count NUMBER;
4347 l_segment_concat VARCHAR2(4000) := NULL;
4348 l_concatenated_segments VARCHAR2(4000) := NULL;
4349 l_category_id VARCHAR2(10);
4350 BEGIN
4351 -- Initialize API return status to success
4352 x_return_status := fnd_api.g_ret_sts_success;
4353 x_prod_valid := 'Y';
4354
4355 fnd_file.put_line(fnd_file.log,
4356 ' Message: Inside PROCEDURE VALIDATE_VENDOR_PRODS_SERVICES' ||
4357 ' Parameters: ' || ' batch_id: ' || p_batch_id ||
4358 ' party_id: ' || p_party_id);
4359
4360 -- Below API would give the delimiter and the segment definition to be inserted
4361 pos_product_service_utl_pkg.initialize(x_status => l_status,
4362 x_error_message => l_error_message);
4363
4364 pos_product_service_utl_pkg.get_product_meta_data(x_product_segment_definition => l_product_segment_definition,
4365 x_product_segment_count => l_product_segment_count,
4366 x_default_po_category_set_id => l_default_po_category_set_id,
4367 x_delimiter => l_delimiter);
4368
4369 fnd_file.put_line(fnd_file.log,
4370 ' Output from pos_product_service_utl_pkg.get_product_meta_data: ' ||
4371 ' product_segment_definition: ' ||
4372 l_product_segment_definition ||
4373 ' product_segment_count: ' || l_product_segment_count);
4374
4375 -- Check if the number of segments into which the data has been
4376 -- inserted is equal to the product segment count
4377 IF (p_vendor_prodsrv_rec.segment_definition <>
4378 l_product_segment_definition) THEN
4379 x_prod_valid := 'N';
4380 x_return_status := fnd_api.g_ret_sts_error;
4381 x_msg_data := 'POS_INVALID_SEGMENT_DEF';
4382 IF (insert_rejections(p_batch_id,
4383 l_request_id,
4384 'POS_PRODUCT_SERVICE_INT',
4385 p_vendor_prodsrv_rec.ps_interface_id,
4386 'POS_INVALID_SEGMENT_DEF',
4387 g_user_id,
4388 g_login_id,
4389 'validate_vendor_prods_services') <> TRUE) THEN
4390
4391 IF (g_level_procedure >= g_current_runtime_level) THEN
4392 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4393 p_data => l_msg_data);
4394 fnd_log.string(g_level_procedure,
4395 g_module_name || l_api_name,
4396 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
4397 p_vendor_prodsrv_rec.ps_interface_id ||
4398 ' Acct Validation Msg: ' || l_msg_data);
4399 END IF;
4400 END IF;
4401 fnd_file.put_line(fnd_file.log,
4402 ' Invalid Segment definition for: ' ||
4403 ' ps_interface_id: ' ||
4404 p_vendor_prodsrv_rec.ps_interface_id ||
4405 ', segment_definition: ' ||
4406 p_vendor_prodsrv_rec.segment_definition);
4407 RETURN;
4408 END IF;
4409
4410 l_seg_def := p_vendor_prodsrv_rec.segment_definition;
4411
4412 WHILE (length(l_seg_def)) > l_start_pos LOOP
4413 l_index := instr(l_seg_def, '.', l_start_pos + 1); --Bug 13399285
4414 IF (l_index = 0) THEN
4415 EXIT;
4416 END IF;
4417 l_segment_code := l_segment_code || 'segment' ||
4418 substr(l_seg_def,
4419 l_start_pos + 1,
4420 (l_index - l_start_pos - 1)) || '||' || '''' ||
4421 l_delimiter || '''' || '||';
4422 l_start_pos := l_index;
4423 END LOOP;
4424
4425 l_segment_code := l_segment_code || 'segment' ||
4426 substr(l_seg_def, l_start_pos + 1);
4427
4428 --Bug 13399285 - ora-00923 error, need to replace the '.' to global flexfield setup l_delimiter
4429 SELECT nvl2(p_vendor_prodsrv_rec.segment1,
4430 p_vendor_prodsrv_rec.segment1 || l_delimiter,
4431 p_vendor_prodsrv_rec.segment1) ||
4432 nvl2(p_vendor_prodsrv_rec.segment2,
4433 p_vendor_prodsrv_rec.segment2 || l_delimiter,
4434 p_vendor_prodsrv_rec.segment2) ||
4435 nvl2(p_vendor_prodsrv_rec.segment3,
4436 p_vendor_prodsrv_rec.segment3 || l_delimiter,
4437 p_vendor_prodsrv_rec.segment3) ||
4438 nvl2(p_vendor_prodsrv_rec.segment4,
4439 p_vendor_prodsrv_rec.segment4 || l_delimiter,
4440 p_vendor_prodsrv_rec.segment4) ||
4441 nvl2(p_vendor_prodsrv_rec.segment5,
4442 p_vendor_prodsrv_rec.segment5 || l_delimiter,
4443 p_vendor_prodsrv_rec.segment5) ||
4444 nvl2(p_vendor_prodsrv_rec.segment6,
4445 p_vendor_prodsrv_rec.segment6 || l_delimiter,
4446 p_vendor_prodsrv_rec.segment6) ||
4447 nvl2(p_vendor_prodsrv_rec.segment7,
4448 p_vendor_prodsrv_rec.segment7 || l_delimiter,
4449 p_vendor_prodsrv_rec.segment7) ||
4450 nvl2(p_vendor_prodsrv_rec.segment8,
4451 p_vendor_prodsrv_rec.segment8 || l_delimiter,
4452 p_vendor_prodsrv_rec.segment8) ||
4453 nvl2(p_vendor_prodsrv_rec.segment9,
4454 p_vendor_prodsrv_rec.segment9 || l_delimiter,
4455 p_vendor_prodsrv_rec.segment9) ||
4456 nvl2(p_vendor_prodsrv_rec.segment10,
4457 p_vendor_prodsrv_rec.segment10 || l_delimiter,
4458 p_vendor_prodsrv_rec.segment10) ||
4459 nvl2(p_vendor_prodsrv_rec.segment11,
4460 p_vendor_prodsrv_rec.segment11 || l_delimiter,
4461 p_vendor_prodsrv_rec.segment11) ||
4462 nvl2(p_vendor_prodsrv_rec.segment12,
4463 p_vendor_prodsrv_rec.segment12 || l_delimiter,
4464 p_vendor_prodsrv_rec.segment12) ||
4465 nvl2(p_vendor_prodsrv_rec.segment13,
4466 p_vendor_prodsrv_rec.segment13 || l_delimiter,
4467 p_vendor_prodsrv_rec.segment13) ||
4468 nvl2(p_vendor_prodsrv_rec.segment14,
4469 p_vendor_prodsrv_rec.segment14 || l_delimiter,
4470 p_vendor_prodsrv_rec.segment14) ||
4471 nvl2(p_vendor_prodsrv_rec.segment15,
4472 p_vendor_prodsrv_rec.segment15 || l_delimiter,
4473 p_vendor_prodsrv_rec.segment15) ||
4474 nvl2(p_vendor_prodsrv_rec.segment16,
4475 p_vendor_prodsrv_rec.segment16 || l_delimiter,
4476 p_vendor_prodsrv_rec.segment16) ||
4477 nvl2(p_vendor_prodsrv_rec.segment17,
4478 p_vendor_prodsrv_rec.segment17 || l_delimiter,
4479 p_vendor_prodsrv_rec.segment17) ||
4480 nvl2(p_vendor_prodsrv_rec.segment18,
4481 p_vendor_prodsrv_rec.segment18 || l_delimiter,
4482 p_vendor_prodsrv_rec.segment18) ||
4483 nvl2(p_vendor_prodsrv_rec.segment19,
4484 p_vendor_prodsrv_rec.segment19 || l_delimiter,
4485 p_vendor_prodsrv_rec.segment19) ||
4486 nvl2(p_vendor_prodsrv_rec.segment20,
4487 p_vendor_prodsrv_rec.segment20 || l_delimiter,
4488 p_vendor_prodsrv_rec.segment20)
4489 INTO l_segment_concat
4490 FROM dual;
4491
4492 l_segment_count := (length(l_segment_concat) -
4493 length(REPLACE(l_segment_concat, l_delimiter, '')));
4494
4495 IF (l_segment_count <> l_product_segment_count) THEN
4496 x_prod_valid := 'N';
4497 x_return_status := fnd_api.g_ret_sts_error;
4498 x_msg_data := 'POS_INVALID_SEGMENT_COUNT';
4499 IF (insert_rejections(p_batch_id,
4500 l_request_id,
4501 'POS_PRODUCT_SERVICE_INT',
4502 p_vendor_prodsrv_rec.ps_interface_id,
4503 'POS_INVALID_SEGMENT_COUNT',
4504 g_user_id,
4505 g_login_id,
4506 'validate_vendor_prods_services') <> TRUE) THEN
4507
4508 IF (g_level_procedure >= g_current_runtime_level) THEN
4509 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4510 p_data => l_msg_data);
4511 fnd_log.string(g_level_procedure,
4512 g_module_name || l_api_name,
4513 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
4514 p_vendor_prodsrv_rec.ps_interface_id ||
4515 ' Acct Validation Msg: ' || l_msg_data);
4516 END IF;
4517 END IF;
4518 fnd_file.put_line(fnd_file.log,
4519 ' Invalid Segment count for: ' ||
4520 ' ps_interface_id: ' ||
4521 p_vendor_prodsrv_rec.ps_interface_id ||
4522 ', segment_concat: ' || l_segment_concat);
4523 RETURN;
4524 END IF;
4525
4526 -- If the above is true then concatenate the segments using the delimiter
4527 l_sql := 'SELECT ' || l_segment_code || '
4528 FROM POS_PRODUCT_SERVICE_INT
4529 WHERE PS_INTERFACE_ID = ' ||
4530 p_vendor_prodsrv_rec.ps_interface_id;
4531
4532 OPEN l_pscur FOR l_sql;
4533 FETCH l_pscur
4534 INTO l_concatenated_segments;
4535 CLOSE l_pscur;
4536
4537 BEGIN
4538 SELECT nvl(category_id, 0)
4539 INTO l_category_id
4540 FROM mtl_categories_kfv
4541 WHERE category_id IN
4542 (SELECT DISTINCT category_id
4543 FROM mtl_category_set_valid_cats
4544 WHERE category_set_id = l_default_po_category_set_id)
4545 AND concatenated_segments = l_concatenated_segments;
4546
4547 EXCEPTION
4548 WHEN no_data_found THEN
4549 x_prod_valid := 'N';
4550 x_return_status := fnd_api.g_ret_sts_error;
4551 x_msg_data := 'POS_INVALID_CATEGORY_ID';
4552 IF (insert_rejections(p_batch_id,
4553 l_request_id,
4554 'POS_PRODUCT_SERVICE_INT',
4555 p_vendor_prodsrv_rec.ps_interface_id,
4556 'POS_INVALID_CATEGORY_ID',
4557 g_user_id,
4558 g_login_id,
4559 'validate_vendor_prods_services') <> TRUE) THEN
4560
4561 IF (g_level_procedure >= g_current_runtime_level) THEN
4562 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4563 p_data => l_msg_data);
4564 fnd_log.string(g_level_procedure,
4565 g_module_name || l_api_name,
4566 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
4567 p_vendor_prodsrv_rec.ps_interface_id ||
4568 ' Acct Validation Msg: ' || l_msg_data);
4569 END IF;
4570 END IF;
4571 fnd_file.put_line(fnd_file.log,
4572 ' Invalid category id for: ' ||
4573 ' ps_interface_id: ' ||
4574 p_vendor_prodsrv_rec.ps_interface_id ||
4575 ', concatenated_segments: ' ||
4576 l_concatenated_segments);
4577 RETURN;
4578 END;
4579
4580 IF (l_category_id = 0) THEN
4581 x_prod_valid := 'N';
4582 x_return_status := fnd_api.g_ret_sts_error;
4583 x_msg_data := 'POS_INVALID_CATEGORY_ID';
4584 IF (insert_rejections(p_batch_id,
4585 l_request_id,
4586 'POS_PRODUCT_SERVICE_INT',
4587 p_vendor_prodsrv_rec.ps_interface_id,
4588 'POS_INVALID_CATEGORY_ID',
4589 g_user_id,
4590 g_login_id,
4591 'validate_vendor_prods_services') <> TRUE) THEN
4592
4593 IF (g_level_procedure >= g_current_runtime_level) THEN
4594 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4595 p_data => l_msg_data);
4596 fnd_log.string(g_level_procedure,
4597 g_module_name || l_api_name,
4598 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
4599 p_vendor_prodsrv_rec.ps_interface_id ||
4600 ' Acct Validation Msg: ' || l_msg_data);
4601 END IF;
4602 END IF;
4603 fnd_file.put_line(fnd_file.log,
4604 ' Invalid category id for: ' ||
4605 ' ps_interface_id: ' ||
4606 p_vendor_prodsrv_rec.ps_interface_id ||
4607 ', category_id: ' || l_category_id);
4608 RETURN;
4609 ELSE
4610 -- x_prod_valid := 'Y';
4611 x_segment_code := l_concatenated_segments;
4612 END IF;
4613
4614 EXCEPTION
4615 WHEN OTHERS THEN
4616 x_prod_valid := 'N';
4617 x_return_status := fnd_api.g_ret_sts_unexp_error;
4618
4619 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4620 p_data => x_msg_data);
4621 fnd_file.put_line(fnd_file.log,
4622 ' Inside validate_vendor_prods_services EXCEPTION ' ||
4623 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4624 END validate_vendor_prods_services;
4625
4626 PROCEDURE create_vendor_prods_services
4627 (
4628 p_batch_id IN NUMBER,
4629 p_vendor_prodsrv_rec IN pos_product_service_int%ROWTYPE,
4630 p_party_id IN hz_parties.party_id%TYPE,
4631 x_return_status OUT NOCOPY VARCHAR2,
4632 x_msg_count OUT NOCOPY NUMBER,
4633 x_msg_data OUT NOCOPY VARCHAR2
4634 ) IS
4635 l_return_status VARCHAR2(100);
4636 l_msg_count NUMBER;
4637 l_msg_data VARCHAR2(100);
4638 l_prod_valid VARCHAR2(1);
4639
4640 l_mapping_id NUMBER;
4641 l_segment_code VARCHAR2(4000) := NULL;
4642 l_req_id NUMBER;
4643 l_status VARCHAR(2000);
4644 l_error_message VARCHAR(4000);
4645 BEGIN
4646 x_return_status := fnd_api.g_ret_sts_success;
4647
4648 fnd_file.put_line(fnd_file.log,
4649 ' Message: Inside PROCEDURE CREATE_VENDOR_PRODS_SERVICES' ||
4650 ' Parameters: ' || ' batch_id: ' || p_batch_id ||
4651 ' party_id: ' || p_party_id);
4652
4653 -- Call Validate_Vendor_Prods_Services to validate the Products and Services data
4654 validate_vendor_prods_services(p_batch_id => p_batch_id,
4655 p_vendor_prodsrv_rec => p_vendor_prodsrv_rec,
4656 p_party_id => p_party_id,
4657 x_return_status => l_return_status,
4658 x_msg_count => l_msg_count,
4659 x_msg_data => l_msg_data,
4660 x_prod_valid => l_prod_valid,
4661 x_segment_code => l_segment_code);
4662
4663 IF (l_prod_valid = 'Y') THEN
4664 -- Insert the data into the pos_product_service_requests table using the follwing API
4665 pos_product_service_utl_pkg.add_new_ps_req(p_vendor_id => p_vendor_prodsrv_rec.vendor_id,
4666 p_segment1 => p_vendor_prodsrv_rec.segment1,
4667 p_segment2 => p_vendor_prodsrv_rec.segment2,
4668 p_segment3 => p_vendor_prodsrv_rec.segment3,
4669 p_segment4 => p_vendor_prodsrv_rec.segment4,
4670 p_segment5 => p_vendor_prodsrv_rec.segment5,
4671 p_segment6 => p_vendor_prodsrv_rec.segment6,
4672 p_segment7 => p_vendor_prodsrv_rec.segment7,
4673 p_segment8 => p_vendor_prodsrv_rec.segment8,
4674 p_segment9 => p_vendor_prodsrv_rec.segment9,
4675 p_segment10 => p_vendor_prodsrv_rec.segment10,
4676 p_segment11 => p_vendor_prodsrv_rec.segment11,
4677 p_segment12 => p_vendor_prodsrv_rec.segment12,
4678 p_segment13 => p_vendor_prodsrv_rec.segment13,
4679 p_segment14 => p_vendor_prodsrv_rec.segment14,
4680 p_segment15 => p_vendor_prodsrv_rec.segment15,
4681 p_segment16 => p_vendor_prodsrv_rec.segment16,
4682 p_segment17 => p_vendor_prodsrv_rec.segment17,
4683 p_segment18 => p_vendor_prodsrv_rec.segment18,
4684 p_segment19 => p_vendor_prodsrv_rec.segment19,
4685 p_segment20 => p_vendor_prodsrv_rec.segment20,
4686 p_segment_definition => p_vendor_prodsrv_rec.segment_definition,
4687 x_return_status => l_return_status,
4688 x_msg_count => l_msg_count,
4689 x_msg_data => l_msg_data);
4690
4691 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
4692 x_return_status := l_return_status;
4693 x_msg_count := l_msg_count;
4694 x_msg_data := l_msg_data;
4695 RETURN;
4696 ELSE
4697 -- If the request_status is "APPROVED" then do the following
4698 IF (p_vendor_prodsrv_rec.request_status = 'APPROVED') THEN
4699
4700 -- Get the mapping_id using the following SQLL
4701 SELECT mapping_id
4702 INTO l_mapping_id
4703 FROM pos_supplier_mappings
4704 WHERE vendor_id = p_vendor_prodsrv_rec.vendor_id
4705 AND party_id = p_party_id;
4706
4707 fnd_file.put_line(fnd_file.log,
4708 ' Message: Inside PROCEDURE CREATE_VENDOR_PRODS_SERVICES' ||
4709 ' request_status: ' ||
4710 p_vendor_prodsrv_rec.request_status ||
4711 ' mapping_id: ' || l_mapping_id ||
4712 ' segment_code: ' || l_segment_code);
4713
4714 pos_product_service_utl_pkg.initialize(x_status => l_status,
4715 x_error_message => l_error_message);
4716
4717 -- Using the mapping_id make a call to the following API
4718 l_req_id := pos_product_service_utl_pkg.get_requestid(x_segment_code => l_segment_code,
4719 x_mapp_id => l_mapping_id);
4720
4721 -- Using the request_id make a call to the following Api to approve the data and insert it into the
4722 -- pos_sup_products_services table
4723 pos_profile_change_request_pkg.approve_ps_req(p_request_id => l_req_id,
4724 x_return_status => l_return_status,
4725 x_msg_count => l_msg_count,
4726 x_msg_data => l_msg_data);
4727
4728 x_return_status := l_return_status;
4729 x_msg_count := l_msg_count;
4730 x_msg_data := l_msg_data;
4731
4732 END IF;
4733 END IF;
4734 ELSE
4735 x_return_status := l_return_status;
4736 x_msg_count := l_msg_count;
4737 x_msg_data := l_msg_data;
4738 RETURN;
4739 END IF;
4740 EXCEPTION
4741 WHEN fnd_api.g_exc_error THEN
4742 x_return_status := fnd_api.g_ret_sts_error;
4743 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4744 p_data => x_msg_data);
4745 fnd_file.put_line(fnd_file.log,
4746 ' Inside create_vendor_prods_services EXCEPTION ' ||
4747 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4748 WHEN fnd_api.g_exc_unexpected_error THEN
4749 x_return_status := fnd_api.g_ret_sts_unexp_error;
4750 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4751 p_data => x_msg_data);
4752 fnd_file.put_line(fnd_file.log,
4753 ' Inside create_vendor_prods_services unexpected EXCEPTION ' ||
4754 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4755 WHEN OTHERS THEN
4756 x_return_status := fnd_api.g_ret_sts_unexp_error;
4757
4758 fnd_msg_pub.count_and_get(p_count => x_msg_count,
4759 p_data => x_msg_data);
4760 fnd_file.put_line(fnd_file.log,
4761 ' Inside create_vendor_prods_services others EXCEPTION ' ||
4762 ' Message: ' || SQLCODE || ' ' || SQLERRM);
4763 END create_vendor_prods_services;
4764
4765 PROCEDURE import_vendor_prods_services
4766 (
4767 p_batch_id IN NUMBER,
4768 x_return_status OUT NOCOPY VARCHAR2,
4769 x_msg_count OUT NOCOPY NUMBER,
4770 x_msg_data OUT NOCOPY VARCHAR2
4771 ) IS
4772 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDOR_PRODS_SERVICES';
4773 l_request_id NUMBER := fnd_global.conc_request_id;
4774
4775 l_return_status VARCHAR2(2000);
4776 l_msg_count NUMBER;
4777 l_msg_data VARCHAR2(2000);
4778
4779 l_party_id NUMBER;
4780
4781 CURSOR vendor_int_prod_srv_cur IS
4782 SELECT *
4783 FROM pos_product_service_int supp
4784 WHERE import_request_id = l_request_id
4785 AND ps_interface_id IS NOT NULL
4786 AND sdh_batch_id = p_batch_id
4787 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
4788 AND NOT EXISTS
4789 (SELECT 1
4790 FROM hz_imp_parties_int party
4791 WHERE batch_id = p_batch_id
4792 AND supp.sdh_batch_id = party.batch_id
4793 AND supp.source_system = party.party_orig_system
4794 AND supp.source_system_reference =
4795 party.party_orig_system_reference
4796 AND party.interface_status = 'R');
4797
4798 vendor_int_prod_srv_rec vendor_int_prod_srv_cur%ROWTYPE;
4799 vendor_prod_srv_rec pos_product_service_int%ROWTYPE;
4800
4801 l_product_segment_definition VARCHAR2(2000);
4802 l_product_segment_count NUMBER;
4803 l_default_po_category_set_id NUMBER;
4804 l_delimiter VARCHAR2(10);
4805 l_status VARCHAR(2000);
4806 l_error_message VARCHAR(4000);
4807 l_segment_concat VARCHAR2(4000) := NULL;
4808
4809 l_mapping_id NUMBER;
4810 l_req_id NUMBER := 0;
4811 l_class_id NUMBER := 0;
4812
4813 l_ret_status VARCHAR2(100);
4814 l_req_id_tab po_tbl_number := po_tbl_number();
4815
4816 BEGIN
4817 -- Initialize API return status to success
4818 x_return_status := fnd_api.g_ret_sts_success;
4819
4820 fnd_file.put_line(fnd_file.log,
4821 ' Message: Inside PROCEDURE IMPORT_VENDOR_PRODS_SERVICES' ||
4822 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
4823 ' request_id: ' || l_request_id);
4824
4825 -- This update statement resets the unprocessed rows so
4826 -- that they get picked in the current run.
4827 UPDATE pos_product_service_int api
4828 SET import_request_id = NULL
4829 WHERE import_request_id IS NOT NULL
4830 AND sdh_batch_id = p_batch_id
4831 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
4832 AND EXISTS (SELECT 'Request Completed'
4833 FROM fnd_concurrent_requests fcr
4834 WHERE fcr.request_id = api.import_request_id
4835 AND fcr.phase_code = 'C');
4836
4837 -- Updating Interface Record with request id
4838
4839 UPDATE pos_product_service_int
4840 SET import_request_id = l_request_id
4841 WHERE import_request_id IS NULL
4842 AND sdh_batch_id = p_batch_id
4843 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
4844
4845 UPDATE pos_product_service_int supp
4846 SET status = 'REMOVED',
4847 import_request_id = l_request_id
4848 WHERE sdh_batch_id = p_batch_id
4849 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
4850 AND EXISTS (SELECT 1
4851 FROM hz_imp_parties_int party
4852 WHERE batch_id = p_batch_id
4853 AND supp.sdh_batch_id = party.batch_id
4854 AND supp.source_system = party.party_orig_system
4855 AND supp.source_system_reference =
4856 party.party_orig_system_reference
4857 AND party.interface_status = 'R');
4858
4859 fnd_file.put_line(fnd_file.log,
4860 ' Message: Inside PROCEDURE IMPORT_VENDOR_PRODS_SERVICES' ||
4861 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
4862 ' records. Reason interface_status in hz_imp_parties_int = R');
4863
4864 INSERT INTO pos_supplier_int_rejections
4865 (SELECT p_batch_id,
4866 l_request_id,
4867 'POS_PRODUCT_SERVICE_INT',
4868 ps_interface_id,
4869 'POS_INVALID_PARTY_ORIG_SYSTEM',
4870 g_user_id,
4871 SYSDATE,
4872 g_login_id,
4873 g_user_id,
4874 SYSDATE
4875 FROM pos_product_service_int
4876 WHERE status = 'REMOVED'
4877 AND import_request_id = l_request_id
4878 AND sdh_batch_id = p_batch_id);
4879
4880 -- Cursor processing for vendor business clasiification record
4881 OPEN vendor_int_prod_srv_cur;
4882 LOOP
4883
4884 FETCH vendor_int_prod_srv_cur
4885 INTO vendor_int_prod_srv_rec;
4886 EXIT WHEN vendor_int_prod_srv_cur%NOTFOUND;
4887
4888 vendor_prod_srv_rec.sdh_batch_id := vendor_int_prod_srv_rec.sdh_batch_id;
4889 vendor_prod_srv_rec.source_system := vendor_int_prod_srv_rec.source_system;
4890 vendor_prod_srv_rec.source_system_reference := vendor_int_prod_srv_rec.source_system_reference;
4891 vendor_prod_srv_rec.vendor_interface_id := vendor_int_prod_srv_rec.vendor_interface_id;
4892 vendor_prod_srv_rec.ps_interface_id := vendor_int_prod_srv_rec.ps_interface_id;
4893
4894 --vendor_prod_srv_rec.request_id := vendor_int_prod_srv_rec.request_id;
4895
4896 --vendor_prod_srv_rec.ps_request_id := vendor_int_prod_srv_rec.ps_request_id;
4897 vendor_prod_srv_rec.mapping_id := vendor_int_prod_srv_rec.mapping_id;
4898 vendor_prod_srv_rec.request_status := vendor_int_prod_srv_rec.request_status;
4899 vendor_prod_srv_rec.request_type := vendor_int_prod_srv_rec.request_type;
4900 vendor_prod_srv_rec.segment1 := vendor_int_prod_srv_rec.segment1;
4901 vendor_prod_srv_rec.segment2 := vendor_int_prod_srv_rec.segment2;
4902 vendor_prod_srv_rec.segment3 := vendor_int_prod_srv_rec.segment3;
4903 vendor_prod_srv_rec.segment4 := vendor_int_prod_srv_rec.segment4;
4904 vendor_prod_srv_rec.segment5 := vendor_int_prod_srv_rec.segment5;
4905 vendor_prod_srv_rec.segment6 := vendor_int_prod_srv_rec.segment6;
4906 vendor_prod_srv_rec.segment7 := vendor_int_prod_srv_rec.segment7;
4907 vendor_prod_srv_rec.segment8 := vendor_int_prod_srv_rec.segment8;
4908 vendor_prod_srv_rec.segment9 := vendor_int_prod_srv_rec.segment9;
4909 vendor_prod_srv_rec.segment10 := vendor_int_prod_srv_rec.segment10;
4910 vendor_prod_srv_rec.segment11 := vendor_int_prod_srv_rec.segment11;
4911 vendor_prod_srv_rec.segment12 := vendor_int_prod_srv_rec.segment12;
4912 vendor_prod_srv_rec.segment13 := vendor_int_prod_srv_rec.segment13;
4913 vendor_prod_srv_rec.segment14 := vendor_int_prod_srv_rec.segment14;
4914 vendor_prod_srv_rec.segment15 := vendor_int_prod_srv_rec.segment15;
4915 vendor_prod_srv_rec.segment16 := vendor_int_prod_srv_rec.segment16;
4916 vendor_prod_srv_rec.segment17 := vendor_int_prod_srv_rec.segment17;
4917 vendor_prod_srv_rec.segment18 := vendor_int_prod_srv_rec.segment18;
4918 vendor_prod_srv_rec.segment19 := vendor_int_prod_srv_rec.segment19;
4919 vendor_prod_srv_rec.segment20 := vendor_int_prod_srv_rec.segment20;
4920 vendor_prod_srv_rec.segment_definition := vendor_int_prod_srv_rec.segment_definition;
4921
4922 /* Get the party id for orig system and
4923 orig system reference combination */
4924 IF (vendor_int_prod_srv_rec.party_id IS NULL) THEN
4925 l_party_id := get_party_id(vendor_int_prod_srv_rec.source_system,
4926 vendor_int_prod_srv_rec.source_system_reference);
4927 ELSE
4928 l_party_id := vendor_int_prod_srv_rec.party_id;
4929 END IF;
4930
4931 IF (vendor_int_prod_srv_rec.vendor_id IS NULL) THEN
4932 BEGIN
4933 SELECT vendor_id
4934 INTO vendor_prod_srv_rec.vendor_id
4935 FROM ap_suppliers supp
4936 WHERE supp.party_id = l_party_id;
4937
4938 EXCEPTION
4939 WHEN OTHERS THEN
4940 UPDATE pos_product_service_int
4941 SET status = 'REJECTED'
4942 WHERE ps_interface_id =
4943 vendor_int_prod_srv_rec.ps_interface_id
4944 AND sdh_batch_id = p_batch_id;
4945
4946 IF (insert_rejections(p_batch_id,
4947 l_request_id,
4948 'POS_PRODUCT_SERVICE_INT',
4949 vendor_int_prod_srv_rec.ps_interface_id,
4950 'AP_VENDOR_ID_NULL',
4951 g_user_id,
4952 g_login_id,
4953 'import_vendor_prods_services') <> TRUE) THEN
4954
4955 IF (g_level_procedure >= g_current_runtime_level) THEN
4956 fnd_msg_pub.count_and_get(p_count => l_msg_count,
4957 p_data => l_msg_data);
4958 fnd_log.string(g_level_procedure,
4959 g_module_name || l_api_name,
4960 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
4961 vendor_int_prod_srv_rec.ps_interface_id ||
4962 ' Product and Services Validation Msg: ' ||
4963 l_msg_data);
4964 END IF;
4965 END IF;
4966 x_return_status := fnd_api.g_ret_sts_error;
4967 fnd_file.put_line(fnd_file.log,
4968 ' Vendor ID is null for: ' ||
4969 ' PS_INTERFACE_ID: ' ||
4970 vendor_int_prod_srv_rec.ps_interface_id);
4971 GOTO continue_next_record;
4972 END;
4973 ELSE
4974 vendor_prod_srv_rec.vendor_id := vendor_int_prod_srv_rec.vendor_id;
4975 END IF;
4976
4977 fnd_file.put_line(fnd_file.log,
4978 ' Message: Inside PROCEDURE IMPORT_VENDOR_PRODS_SERVICES' ||
4979 ' ps_interface_id: ' ||
4980 vendor_prod_srv_rec.ps_interface_id ||
4981 ' party_id: ' || l_party_id || ' vendor_id: ' ||
4982 vendor_prod_srv_rec.vendor_id);
4983
4984 BEGIN
4985 SELECT mapping_id
4986 INTO l_mapping_id
4987 FROM pos_supplier_mappings
4988 WHERE vendor_id = vendor_prod_srv_rec.vendor_id
4989 AND party_id = l_party_id;
4990
4991 --Bug 13399285 - ora-00923 error, need to replace the '.' to global flexfield setup l_delimiter
4992 fnd_file.put_line(fnd_file.log, 'l_mapping_id: ' || l_mapping_id);
4993 --Bug 13704624 - update status for products and services not working, need to get l_delimiter value first
4994 pos_product_service_utl_pkg.initialize(x_status => l_status,
4995 x_error_message => l_error_message);
4996
4997 pos_product_service_utl_pkg.get_product_meta_data(x_product_segment_definition => l_product_segment_definition,
4998 x_product_segment_count => l_product_segment_count,
4999 x_default_po_category_set_id => l_default_po_category_set_id,
5000 x_delimiter => l_delimiter);
5001
5002 SELECT rtrim(nvl2(vendor_prod_srv_rec.segment1,
5003 vendor_prod_srv_rec.segment1 || l_delimiter,
5004 vendor_prod_srv_rec.segment1) ||
5005 nvl2(vendor_prod_srv_rec.segment2,
5006 vendor_prod_srv_rec.segment2 || l_delimiter,
5007 vendor_prod_srv_rec.segment2) ||
5008 nvl2(vendor_prod_srv_rec.segment3,
5009 vendor_prod_srv_rec.segment3 || l_delimiter,
5010 vendor_prod_srv_rec.segment3) ||
5011 nvl2(vendor_prod_srv_rec.segment4,
5012 vendor_prod_srv_rec.segment4 || l_delimiter,
5013 vendor_prod_srv_rec.segment4) ||
5014 nvl2(vendor_prod_srv_rec.segment5,
5015 vendor_prod_srv_rec.segment5 || l_delimiter,
5016 vendor_prod_srv_rec.segment5) ||
5017 nvl2(vendor_prod_srv_rec.segment6,
5018 vendor_prod_srv_rec.segment6 || l_delimiter,
5019 vendor_prod_srv_rec.segment6) ||
5020 nvl2(vendor_prod_srv_rec.segment7,
5021 vendor_prod_srv_rec.segment7 || l_delimiter,
5022 vendor_prod_srv_rec.segment7) ||
5023 nvl2(vendor_prod_srv_rec.segment8,
5024 vendor_prod_srv_rec.segment8 || l_delimiter,
5025 vendor_prod_srv_rec.segment8) ||
5026 nvl2(vendor_prod_srv_rec.segment9,
5027 vendor_prod_srv_rec.segment9 || l_delimiter,
5028 vendor_prod_srv_rec.segment9) ||
5029 nvl2(vendor_prod_srv_rec.segment10,
5030 vendor_prod_srv_rec.segment10 || l_delimiter,
5031 vendor_prod_srv_rec.segment10) ||
5032 nvl2(vendor_prod_srv_rec.segment11,
5033 vendor_prod_srv_rec.segment11 || l_delimiter,
5034 vendor_prod_srv_rec.segment11) ||
5035 nvl2(vendor_prod_srv_rec.segment12,
5036 vendor_prod_srv_rec.segment12 || l_delimiter,
5037 vendor_prod_srv_rec.segment12) ||
5038 nvl2(vendor_prod_srv_rec.segment13,
5039 vendor_prod_srv_rec.segment13 || l_delimiter,
5040 vendor_prod_srv_rec.segment13) ||
5041 nvl2(vendor_prod_srv_rec.segment14,
5042 vendor_prod_srv_rec.segment14 || l_delimiter,
5043 vendor_prod_srv_rec.segment14) ||
5044 nvl2(vendor_prod_srv_rec.segment15,
5045 vendor_prod_srv_rec.segment15 || l_delimiter,
5046 vendor_prod_srv_rec.segment15) ||
5047 nvl2(vendor_prod_srv_rec.segment16,
5048 vendor_prod_srv_rec.segment16 || l_delimiter,
5049 vendor_prod_srv_rec.segment16) ||
5050 nvl2(vendor_prod_srv_rec.segment17,
5051 vendor_prod_srv_rec.segment17 || l_delimiter,
5052 vendor_prod_srv_rec.segment17) ||
5053 nvl2(vendor_prod_srv_rec.segment18,
5054 vendor_prod_srv_rec.segment18 || l_delimiter,
5055 vendor_prod_srv_rec.segment18) ||
5056 nvl2(vendor_prod_srv_rec.segment19,
5057 vendor_prod_srv_rec.segment19 || l_delimiter,
5058 vendor_prod_srv_rec.segment19) ||
5059 nvl2(vendor_prod_srv_rec.segment20,
5060 vendor_prod_srv_rec.segment20 || l_delimiter,
5061 vendor_prod_srv_rec.segment20),
5062 l_delimiter)
5063 INTO l_segment_concat
5064 FROM dual;
5065
5066 fnd_file.put_line(fnd_file.log,
5067 'l_segment_concat: ' || l_segment_concat);
5068 fnd_file.put_line(fnd_file.log,
5069 'l_delimiter: ' || l_delimiter);
5070
5071 l_req_id := pos_product_service_utl_pkg.get_requestid(x_segment_code => l_segment_concat,
5072 x_mapp_id => l_mapping_id);
5073 fnd_file.put_line(fnd_file.log,
5074 'l_req_id: ' || l_req_id);
5075
5076 EXCEPTION
5077 WHEN OTHERS THEN
5078 l_req_id := 0;
5079 END;
5080
5081 BEGIN
5082 l_class_id := pos_product_service_utl_pkg.get_classid(x_segment_code => l_segment_concat,
5083 x_vendor_id => vendor_prod_srv_rec.vendor_id);
5084 fnd_file.put_line(fnd_file.log,
5085 'l_class_id: ' || l_class_id);
5086 EXCEPTION
5087 WHEN OTHERS THEN
5088 l_class_id := 0;
5089 END;
5090
5091 IF (l_class_id = 0 AND l_req_id = 0) THEN
5092 vendor_int_prod_srv_rec.insert_update_flag := nvl(vendor_int_prod_srv_rec.insert_update_flag,
5093 'I');
5094 ELSE
5095 vendor_int_prod_srv_rec.insert_update_flag := nvl(vendor_int_prod_srv_rec.insert_update_flag,
5096 'U');
5097 END IF;
5098
5099 fnd_file.put_line(fnd_file.log,
5100 ' Message: Inside PROCEDURE IMPORT_VENDOR_PRODS_SERVICES' ||
5101 ' ps_interface_id: ' ||
5102 vendor_prod_srv_rec.ps_interface_id ||
5103 ' classification_id: ' || l_class_id ||
5104 ' mapping_id: ' || l_mapping_id || ' req_id: ' ||
5105 l_req_id ||
5106 ' vendor_int_prod_srv_rec.insert_update_flag: ' ||
5107 vendor_int_prod_srv_rec.insert_update_flag);
5108
5109 IF (vendor_int_prod_srv_rec.insert_update_flag = 'I') THEN
5110 create_vendor_prods_services(p_batch_id => p_batch_id,
5111 p_vendor_prodsrv_rec => vendor_prod_srv_rec,
5112 p_party_id => l_party_id,
5113 x_return_status => l_return_status,
5114 x_msg_count => l_msg_count,
5115 x_msg_data => l_msg_data);
5116
5117 IF l_return_status = fnd_api.g_ret_sts_success THEN
5118 UPDATE pos_product_service_int
5119 SET status = 'PROCESSED'
5120 WHERE ps_interface_id = vendor_int_prod_srv_rec.ps_interface_id
5121 AND sdh_batch_id = p_batch_id;
5122
5123 UPDATE pos_imp_batch_summary
5124 SET total_records_imported = total_records_imported + 1,
5125 total_inserts = total_inserts + 1,
5126 prod_serv_inserted = prod_serv_inserted + 1,
5127 prod_serv_imported = prod_serv_imported + 1
5128 WHERE batch_id = vendor_int_prod_srv_rec.sdh_batch_id;
5129 ELSE
5130 UPDATE pos_product_service_int
5131 SET status = 'REJECTED'
5132 WHERE ps_interface_id = vendor_int_prod_srv_rec.ps_interface_id
5133 AND sdh_batch_id = p_batch_id;
5134
5135 x_return_status := l_return_status;
5136
5137 IF (insert_rejections(p_batch_id,
5138 l_request_id,
5139 'POS_PRODUCT_SERVICE_INT',
5140 vendor_int_prod_srv_rec.ps_interface_id,
5141 'POS_PROD_SERVICES_CREATION',
5142 g_user_id,
5143 g_login_id,
5144 'import_vendor_prods_services') <> TRUE) THEN
5145
5146 IF (g_level_procedure >= g_current_runtime_level) THEN
5147 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5148 p_data => l_msg_data);
5149 fnd_log.string(g_level_procedure,
5150 g_module_name || l_api_name,
5151 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
5152 vendor_int_prod_srv_rec.ps_interface_id ||
5153 ' Product and Services Validation Msg: ' ||
5154 l_msg_data);
5155 END IF;
5156 END IF;
5157
5158 END IF;
5159 ELSE
5160 --Bug 14233640 - pos_product_service_int import flow change(if l_req_id is 0, POS_PRODUCT_SERVICE_REQUESTS no record)
5161 IF (vendor_int_prod_srv_rec.request_status = 'REJECTED') THEN
5162 IF (l_req_id <> 0) THEN
5163 pos_profile_change_request_pkg.reject_ps_req(p_request_id => l_req_id,
5164 x_return_status => l_ret_status,
5165 x_msg_count => l_msg_count,
5166 x_msg_data => l_msg_data);
5167 IF (l_class_id <>0) THEN
5168 l_req_id_tab.extend;
5169 l_req_id_tab(1) := l_class_id;
5170 pos_product_service_utl_pkg.update_main_ps_req(p_req_id_tbl => l_req_id_tab,
5171 p_status => 'R',
5172 x_return_status => l_ret_status,
5173 x_msg_count => l_msg_count,
5174 x_msg_data => l_msg_data);
5175 END IF;
5176 ELSE
5177 IF (l_class_id <>0) THEN
5178 l_req_id_tab.extend;
5179 l_req_id_tab(1) := l_class_id;
5180 pos_product_service_utl_pkg.update_main_ps_req(p_req_id_tbl => l_req_id_tab,
5181 p_status => 'R',
5182 x_return_status => l_ret_status,
5183 x_msg_count => l_msg_count,
5184 x_msg_data => l_msg_data);
5185 END IF;
5186
5187 END IF;
5188 ELSIF (vendor_int_prod_srv_rec.request_status) = 'APPROVED' THEN
5189 IF (l_req_id <> 0) THEN
5190 pos_profile_change_request_pkg.approve_ps_req(p_request_id => l_req_id,
5191 x_return_status => l_ret_status,
5192 x_msg_count => l_msg_count,
5193 x_msg_data => l_msg_data);
5194 IF (l_class_id <>0) THEN
5195 l_req_id_tab.extend;
5196 l_req_id_tab(1) := l_class_id;
5197 pos_product_service_utl_pkg.update_main_ps_req(p_req_id_tbl => l_req_id_tab,
5198 p_status => 'A',
5199 x_return_status => l_ret_status,
5200 x_msg_count => l_msg_count,
5201 x_msg_data => l_msg_data);
5202 END IF;
5203 ELSE
5204 IF (l_class_id <>0) THEN
5205 l_req_id_tab.extend;
5206 l_req_id_tab(1) := l_class_id;
5207 pos_product_service_utl_pkg.update_main_ps_req(p_req_id_tbl => l_req_id_tab,
5208 p_status => 'A',
5209 x_return_status => l_ret_status,
5210 x_msg_count => l_msg_count,
5211 x_msg_data => l_msg_data);
5212 END IF;
5213
5214 END IF;
5215 ELSIF (vendor_int_prod_srv_rec.request_status) = 'REMOVED' THEN
5216 fnd_file.put_line(fnd_file.log,
5217 'l_req_id for removed: ' || l_req_id);
5218 fnd_file.put_line(fnd_file.log,
5219 'l_class_id for removed: ' || l_class_id);
5220 IF (l_req_id <> 0) THEN
5221 l_req_id_tab.extend;
5222 l_req_id_tab(1) := l_req_id;
5223
5224 pos_product_service_utl_pkg.remove_mult_ps_reqs(p_req_id_tbl => l_req_id_tab,
5225 x_return_status => l_ret_status,
5226 x_msg_count => l_msg_count,
5227 x_msg_data => l_msg_data);
5228 IF (l_class_id <>0) THEN
5229 l_req_id_tab.extend;
5230 l_req_id_tab(1) := l_class_id;
5231 pos_product_service_utl_pkg.update_main_ps_req(p_req_id_tbl => l_req_id_tab,
5232 p_status => 'X',
5233 x_return_status => l_ret_status,
5234 x_msg_count => l_msg_count,
5235 x_msg_data => l_msg_data);
5236 END IF;
5237 ELSE
5238 fnd_file.put_line(fnd_file.log,'l_req_id for removed(l_req_id =0 flow): ' || l_req_id);
5239 fnd_file.put_line(fnd_file.log, 'l_class_id for removed(l_req_id =0 flow): ' || l_class_id);
5240 IF (l_class_id <>0) THEN
5241 l_req_id_tab.extend;
5242 l_req_id_tab(1) := l_class_id;
5243 pos_product_service_utl_pkg.update_main_ps_req(p_req_id_tbl => l_req_id_tab,
5244 p_status => 'X',
5245 x_return_status => l_ret_status,
5246 x_msg_count => l_msg_count,
5247 x_msg_data => l_msg_data);
5248 END IF;
5249 END IF;
5250 END IF;
5251 IF l_ret_status = fnd_api.g_ret_sts_success THEN
5252 UPDATE pos_product_service_int
5253 SET status = 'PROCESSED'
5254 WHERE ps_interface_id = vendor_int_prod_srv_rec.ps_interface_id
5255 AND sdh_batch_id = p_batch_id;
5256
5257 UPDATE pos_imp_batch_summary
5258 SET total_records_imported = total_records_imported + 1,
5259 total_updates = total_updates + 1,
5260 prod_serv_updated = prod_serv_updated + 1,
5261 prod_serv_imported = prod_serv_imported + 1
5262 WHERE batch_id = vendor_int_prod_srv_rec.sdh_batch_id;
5263 ELSE
5264 UPDATE pos_product_service_int
5265 SET status = 'REJECTED'
5266 WHERE ps_interface_id = vendor_int_prod_srv_rec.ps_interface_id
5267 AND sdh_batch_id = p_batch_id;
5268
5269 x_return_status := l_ret_status;
5270
5271 IF (insert_rejections(p_batch_id,
5272 l_request_id,
5273 'POS_PRODUCT_SERVICE_INT',
5274 vendor_int_prod_srv_rec.ps_interface_id,
5275 'POS_PROD_SERVICES_UPDATION',
5276 g_user_id,
5277 g_login_id,
5278 'import_vendor_prods_services') <> TRUE) THEN
5279
5280 IF (g_level_procedure >= g_current_runtime_level) THEN
5281 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5282 p_data => l_msg_data);
5283 fnd_log.string(g_level_procedure,
5284 g_module_name || l_api_name,
5285 'Parameters: ' || ' PS_INTERFACE_ID: ' ||
5286 vendor_int_prod_srv_rec.ps_interface_id ||
5287 ' Product and Services Validation Msg: ' ||
5288 l_msg_data);
5289 END IF;
5290 END IF;
5291
5292 END IF;
5293 END IF;
5294 <<continue_next_record>>
5295 NULL;
5296 END LOOP;
5297
5298 CLOSE vendor_int_prod_srv_cur;
5299 EXCEPTION
5300 WHEN fnd_api.g_exc_error THEN
5301 x_return_status := fnd_api.g_ret_sts_error;
5302 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5303 p_data => x_msg_data);
5304 fnd_file.put_line(fnd_file.log,
5305 ' Inside import_vendor_prods_services EXCEPTION ' ||
5306 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5307 WHEN fnd_api.g_exc_unexpected_error THEN
5308 x_return_status := fnd_api.g_ret_sts_unexp_error;
5309 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5310 p_data => x_msg_data);
5311 fnd_file.put_line(fnd_file.log,
5312 ' Inside import_vendor_prods_services unexpected EXCEPTION ' ||
5313 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5314 WHEN OTHERS THEN
5315 x_return_status := fnd_api.g_ret_sts_unexp_error;
5316
5317 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5318 p_data => x_msg_data);
5319 fnd_file.put_line(fnd_file.log,
5320 ' Inside import_vendor_prods_services others EXCEPTION ' ||
5321 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5322 END import_vendor_prods_services;
5323
5324 PROCEDURE validate_vendor_buss_class
5325 (
5326 p_batch_id IN NUMBER,
5327 p_vendor_buss_class_rec IN pos_business_class_int%ROWTYPE,
5328 p_party_id IN hz_parties.party_id%TYPE,
5329 x_return_status OUT NOCOPY VARCHAR2,
5330 x_msg_count OUT NOCOPY NUMBER,
5331 x_msg_data OUT NOCOPY VARCHAR2,
5332 x_buss_valid OUT NOCOPY VARCHAR2
5333 ) IS
5334 l_dummy_lookup VARCHAR2(30);
5335
5336 l_msg_count NUMBER;
5337 l_msg_data VARCHAR2(2000);
5338 l_api_name CONSTANT VARCHAR2(30) := 'VALIDATE_VENDOR_BUSS_CLASS';
5339 l_request_id NUMBER := fnd_global.conc_request_id;
5340 BEGIN
5341 -- Initialize API return status to success
5342 x_return_status := fnd_api.g_ret_sts_success;
5343
5344 x_buss_valid := 'Y';
5345
5346 fnd_file.put_line(fnd_file.log,
5347 ' Message: Inside PROCEDURE VALIDATE_VENDOR_BUSS_CLASS' ||
5348 ' Parameters: ' || ' batch_id: ' || p_batch_id ||
5349 ' party_id: ' || p_party_id || ' lookup_type: ' ||
5350 p_vendor_buss_class_rec.lookup_type ||
5351 ' lookup_code: ' ||
5352 p_vendor_buss_class_rec.lookup_code ||
5353 ' ext_attr_1: ' || p_vendor_buss_class_rec.ext_attr_1);
5354
5355 -- Validate the classifcation using the following query
5356 BEGIN
5357 SELECT lookup_code
5358 INTO l_dummy_lookup
5359 FROM fnd_lookup_values
5360 WHERE lookup_type = p_vendor_buss_class_rec.lookup_type
5361 AND lookup_code = p_vendor_buss_class_rec.lookup_code
5362 AND enabled_flag = 'Y'
5363 AND nvl(end_date_active, SYSDATE + 1) > SYSDATE
5364 AND LANGUAGE = 'US';
5365
5366 EXCEPTION
5367 WHEN OTHERS THEN
5368 x_buss_valid := 'N';
5369 x_return_status := fnd_api.g_ret_sts_error;
5370 x_msg_data := 'POS_INVALID_LOOKUP_CODE';
5371 IF (insert_rejections(p_batch_id,
5372 l_request_id,
5373 'POS_BUSINESS_CLASS_INT',
5374 p_vendor_buss_class_rec.business_class_interface_id,
5375 'POS_INVALID_LOOKUP_CODE',
5376 g_user_id,
5377 g_login_id,
5378 'Validate_Vendor_Buss_Class') <> TRUE) THEN
5379
5380 IF (g_level_procedure >= g_current_runtime_level) THEN
5381 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5382 p_data => l_msg_data);
5383 fnd_log.string(g_level_procedure,
5384 g_module_name || l_api_name,
5385 'Parameters: ' ||
5386 ' business_class_interface_id: ' ||
5387 p_vendor_buss_class_rec.business_class_interface_id ||
5388 ' Acct Validation Msg: ' || l_msg_data);
5389 END IF;
5390 END IF;
5391 fnd_file.put_line(fnd_file.log,
5392 ' Invalid Lookup Code for: ' ||
5393 ' business_class_interface_id: ' ||
5394 p_vendor_buss_class_rec.business_class_interface_id ||
5395 ' lookup_code: ' ||
5396 p_vendor_buss_class_rec.lookup_code);
5397 RETURN;
5398 END;
5399
5400 -- if the lookup_code is "MINORITY_OWNED" validate the minority_type using the following query
5401 IF (p_vendor_buss_class_rec.lookup_code = 'MINORITY_OWNED') THEN
5402 BEGIN
5403 SELECT lookup_code
5404 INTO l_dummy_lookup
5405 FROM fnd_lookup_values_vl
5406 WHERE lookup_type = 'MINORITY GROUP'
5407 AND lookup_code = p_vendor_buss_class_rec.ext_attr_1
5408 AND enabled_flag = 'Y'
5409 AND nvl(end_date_active, SYSDATE + 1) > SYSDATE;
5410
5411 EXCEPTION
5412 WHEN OTHERS THEN
5413 x_buss_valid := 'N';
5414 x_return_status := fnd_api.g_ret_sts_error;
5415 x_msg_data := 'POS_INVALID_MINOR_LOOKUP_CODE';
5416 IF (insert_rejections(p_batch_id,
5417 l_request_id,
5418 'POS_BUSINESS_CLASS_INT',
5419 p_vendor_buss_class_rec.business_class_interface_id,
5420 'POS_INVALID_MINOR_LOOKUP_CODE',
5421 g_user_id,
5422 g_login_id,
5423 'Validate_Vendor_Buss_Class') <> TRUE) THEN
5424
5425 IF (g_level_procedure >= g_current_runtime_level) THEN
5426 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5427 p_data => l_msg_data);
5428 fnd_log.string(g_level_procedure,
5429 g_module_name || l_api_name,
5430 'Parameters: ' ||
5431 ' BUSINESS_CLASS_INTERFACE_ID: ' ||
5432 p_vendor_buss_class_rec.business_class_interface_id ||
5433 ' Acct Validation Msg: ' || l_msg_data);
5434 END IF;
5435 END IF;
5436 fnd_file.put_line(fnd_file.log,
5437 ' Invalid Lookup Code for MINORITY_OWNED : ' ||
5438 ' business_class_interface_id: ' ||
5439 p_vendor_buss_class_rec.business_class_interface_id);
5440 RETURN;
5441 END;
5442 END IF;
5443 EXCEPTION
5444 WHEN OTHERS THEN
5445 x_buss_valid := 'N';
5446 x_return_status := fnd_api.g_ret_sts_unexp_error;
5447
5448 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5449 p_data => x_msg_data);
5450 fnd_file.put_line(fnd_file.log,
5451 ' Inside validate_vendor_buss_class EXCEPTION ' ||
5452 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5453 END validate_vendor_buss_class;
5454
5455 PROCEDURE create_vendor_buss_class
5456 (
5457 p_batch_id IN NUMBER,
5458 p_vendor_buss_class_rec IN pos_business_class_int%ROWTYPE,
5459 p_party_id IN hz_parties.party_id%TYPE,
5460 x_return_status OUT NOCOPY VARCHAR2,
5461 x_msg_count OUT NOCOPY NUMBER,
5462 x_msg_data OUT NOCOPY VARCHAR2
5463 ) IS
5464 l_return_status VARCHAR2(100);
5465 l_msg_count NUMBER;
5466 l_msg_data VARCHAR2(100);
5467 l_buss_valid VARCHAR2(1);
5468
5469 l_classification_id NUMBER;
5470 l_status VARCHAR2(100);
5471 l_exception_msg VARCHAR2(100);
5472 BEGIN
5473 -- Initialize API return status to success
5474 x_return_status := fnd_api.g_ret_sts_success;
5475
5476 -- Call Validate_Vendor_Buss_Class to validate the Business Classification data
5477 BEGIN
5478
5479 validate_vendor_buss_class(p_batch_id => p_batch_id,
5480 p_vendor_buss_class_rec => p_vendor_buss_class_rec,
5481 p_party_id => p_party_id,
5482 x_return_status => l_return_status,
5483 x_msg_count => l_msg_count,
5484 x_msg_data => l_msg_data,
5485 x_buss_valid => l_buss_valid);
5486 END;
5487
5488 IF (l_buss_valid = 'Y') THEN
5489 --Insert the data using the follwing API
5490 BEGIN
5491 pos_supp_classification_pkg.add_bus_class_attr(p_party_id,
5492 p_vendor_buss_class_rec.vendor_id,
5493 p_vendor_buss_class_rec.lookup_code,
5494 p_vendor_buss_class_rec.expiration_date,
5495 p_vendor_buss_class_rec.certificate_number,
5496 p_vendor_buss_class_rec.certifying_agency,
5497 p_vendor_buss_class_rec.ext_attr_1,
5498 p_vendor_buss_class_rec.class_status,
5499 '',
5500 l_classification_id,
5501 l_status,
5502 l_exception_msg);
5503 END;
5504
5505 -- Call the API to syncronise data with TCA pasing party_id and vendor_id
5506 BEGIN
5507 fnd_file.put_line(fnd_file.log,
5508 'API to syncronise data with TCA pasing party_id and vendor_id');
5509 pos_supp_classification_pkg.synchronize_class_tca_to_po(p_party_id,
5510 p_vendor_buss_class_rec.vendor_id);
5511 END;
5512 ELSE
5513 x_return_status := l_return_status;
5514 x_msg_count := l_msg_count;
5515 x_msg_data := l_msg_data;
5516 RETURN;
5517 END IF;
5518 EXCEPTION
5519 WHEN fnd_api.g_exc_error THEN
5520 x_return_status := fnd_api.g_ret_sts_error;
5521 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5522 p_data => x_msg_data);
5523 fnd_file.put_line(fnd_file.log,
5524 ' Inside create_vendor_buss_class EXCEPTION ' ||
5525 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5526 WHEN fnd_api.g_exc_unexpected_error THEN
5527 x_return_status := fnd_api.g_ret_sts_unexp_error;
5528 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5529 p_data => x_msg_data);
5530 fnd_file.put_line(fnd_file.log,
5531 ' Inside create_vendor_buss_class unexpected EXCEPTION ' ||
5532 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5533 WHEN OTHERS THEN
5534 x_return_status := fnd_api.g_ret_sts_unexp_error;
5535
5536 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5537 p_data => x_msg_data);
5538 fnd_file.put_line(fnd_file.log,
5539 ' Inside create_vendor_buss_class others EXCEPTION ' ||
5540 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5541 END create_vendor_buss_class;
5542
5543 PROCEDURE import_vendor_buss_class
5544 (
5545 p_batch_id IN NUMBER,
5546 x_return_status OUT NOCOPY VARCHAR2,
5547 x_msg_count OUT NOCOPY NUMBER,
5548 x_msg_data OUT NOCOPY VARCHAR2
5549 ) IS
5550 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDOR_BUSS_CLASS';
5551 l_request_id NUMBER := fnd_global.conc_request_id;
5552
5553 l_return_status VARCHAR2(2000);
5554 l_msg_count NUMBER;
5555 l_msg_data VARCHAR2(2000);
5556
5557 l_party_id NUMBER;
5558 l_classification_id NUMBER;
5559 l_mapping_id NUMBER;
5560 l_buss_class_req_id NUMBER;
5561
5562 l_out_classification_id NUMBER;
5563 l_out_buss_class_req_id NUMBER;
5564
5565 CURSOR vendor_int_buss_class_cur IS
5566 SELECT *
5567 FROM pos_business_class_int supp
5568 WHERE import_request_id = l_request_id
5569 AND business_class_interface_id IS NOT NULL
5570 AND sdh_batch_id = p_batch_id
5571 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
5572 AND NOT EXISTS
5573 (SELECT 1
5574 FROM hz_imp_parties_int party
5575 WHERE batch_id = p_batch_id
5576 AND supp.sdh_batch_id = party.batch_id
5577 AND supp.source_system = party.party_orig_system
5578 AND supp.source_system_reference =
5579 party.party_orig_system_reference
5580 AND party.interface_status = 'R');
5581
5582 vendor_int_buss_class_rec vendor_int_buss_class_cur%ROWTYPE;
5583 vendor_buss_class_rec pos_business_class_int%ROWTYPE;
5584 BEGIN
5585 -- Initialize API return status to success
5586 x_return_status := fnd_api.g_ret_sts_success;
5587
5588 fnd_file.put_line(fnd_file.log,
5589 ' Message: Inside PROCEDURE IMPORT_VENDOR_BUSS_CLASS' ||
5590 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
5591 ' request_id: ' || l_request_id);
5592
5593 -- This update statement resets the unprocessed rows so
5594 -- that they get picked in the current run.
5595 UPDATE pos_business_class_int api
5596 SET import_request_id = NULL
5597 WHERE import_request_id IS NOT NULL
5598 AND sdh_batch_id = p_batch_id
5599 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
5600 AND EXISTS (SELECT 'Request Completed'
5601 FROM fnd_concurrent_requests fcr
5602 WHERE fcr.request_id = api.import_request_id
5603 AND fcr.phase_code = 'C');
5604
5605 -- Updating Interface Record with request id
5606
5607 UPDATE pos_business_class_int
5608 SET import_request_id = l_request_id
5609 WHERE import_request_id IS NULL
5610 AND sdh_batch_id = p_batch_id
5611 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
5612
5613 UPDATE pos_business_class_int supp
5614 SET status = 'REMOVED',
5615 import_request_id = l_request_id
5616 WHERE sdh_batch_id = p_batch_id
5617 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
5618 AND EXISTS (SELECT 1
5619 FROM hz_imp_parties_int party
5620 WHERE batch_id = p_batch_id
5621 AND supp.sdh_batch_id = party.batch_id
5622 AND supp.source_system = party.party_orig_system
5623 AND supp.source_system_reference =
5624 party.party_orig_system_reference
5625 AND party.interface_status = 'R');
5626
5627 fnd_file.put_line(fnd_file.log,
5628 ' Message: Inside PROCEDURE IMPORT_VENDOR_BUSS_CLASS' ||
5629 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
5630 ' records. Reason interface_status in hz_imp_parties_int = R');
5631
5632 INSERT INTO pos_supplier_int_rejections
5633 (SELECT p_batch_id,
5634 l_request_id,
5635 'POS_BUSINESS_CLASS_INT',
5636 business_class_interface_id,
5637 'POS_INVALID_PARTY_ORIG_SYSTEM',
5638 g_user_id,
5639 SYSDATE,
5640 g_login_id,
5641 g_user_id,
5642 SYSDATE
5643 FROM pos_business_class_int
5644 WHERE status = 'REMOVED'
5645 AND import_request_id = l_request_id
5646 AND sdh_batch_id = p_batch_id);
5647
5648 -- Cursor processing for vendor business classification record
5649 OPEN vendor_int_buss_class_cur;
5650 LOOP
5651
5652 FETCH vendor_int_buss_class_cur
5653 INTO vendor_int_buss_class_rec;
5654 EXIT WHEN vendor_int_buss_class_cur%NOTFOUND;
5655
5656 vendor_buss_class_rec.sdh_batch_id := vendor_int_buss_class_rec.sdh_batch_id;
5657 vendor_buss_class_rec.source_system := vendor_int_buss_class_rec.source_system;
5658 vendor_buss_class_rec.source_system_reference := vendor_int_buss_class_rec.source_system_reference;
5659 vendor_buss_class_rec.vendor_interface_id := vendor_int_buss_class_rec.vendor_interface_id;
5660 vendor_buss_class_rec.business_class_interface_id := vendor_int_buss_class_rec.business_class_interface_id;
5661 --vendor_buss_class_rec.request_id := vendor_int_buss_class_rec.request_id;
5662 vendor_buss_class_rec.classification_id := vendor_int_buss_class_rec.classification_id;
5663
5664 vendor_buss_class_rec.lookup_type := vendor_int_buss_class_rec.lookup_type;
5665 vendor_buss_class_rec.lookup_code := vendor_int_buss_class_rec.lookup_code;
5666 vendor_buss_class_rec.start_date_active := vendor_int_buss_class_rec.start_date_active;
5667 vendor_buss_class_rec.end_date_active := vendor_int_buss_class_rec.end_date_active;
5668 vendor_buss_class_rec.status := vendor_int_buss_class_rec.status;
5669 vendor_buss_class_rec.ext_attr_1 := vendor_int_buss_class_rec.ext_attr_1;
5670 vendor_buss_class_rec.expiration_date := vendor_int_buss_class_rec.expiration_date;
5671 vendor_buss_class_rec.certificate_number := vendor_int_buss_class_rec.certificate_number;
5672 vendor_buss_class_rec.certifying_agency := vendor_int_buss_class_rec.certifying_agency;
5673 vendor_buss_class_rec.class_status := vendor_int_buss_class_rec.class_status;
5674 vendor_buss_class_rec.attribute1 := vendor_int_buss_class_rec.attribute1;
5675 vendor_buss_class_rec.attribute2 := vendor_int_buss_class_rec.attribute2;
5676 vendor_buss_class_rec.attribute3 := vendor_int_buss_class_rec.attribute3;
5677 vendor_buss_class_rec.attribute4 := vendor_int_buss_class_rec.attribute4;
5678 vendor_buss_class_rec.attribute5 := vendor_int_buss_class_rec.attribute5;
5679
5680 /* Get the party id for orig system and
5681 orig system reference combination */
5682 IF (vendor_int_buss_class_rec.party_id IS NULL) THEN
5683 l_party_id := get_party_id(vendor_int_buss_class_rec.source_system,
5684 vendor_int_buss_class_rec.source_system_reference);
5685 ELSE
5686 l_party_id := vendor_int_buss_class_rec.party_id;
5687 END IF;
5688
5689 IF (vendor_int_buss_class_rec.vendor_id IS NULL) THEN
5690 BEGIN
5691 SELECT vendor_id
5692 INTO vendor_buss_class_rec.vendor_id
5693 FROM ap_suppliers supp
5694 WHERE supp.party_id = l_party_id;
5695
5696 EXCEPTION
5697 WHEN OTHERS THEN
5698 UPDATE pos_business_class_int
5699 SET status = 'REJECTED'
5700 WHERE business_class_interface_id =
5701 vendor_int_buss_class_rec.business_class_interface_id
5702 AND sdh_batch_id = p_batch_id;
5703
5704 IF (insert_rejections(p_batch_id,
5705 l_request_id,
5706 'POS_BUSINESS_CLASS_INT',
5707 vendor_int_buss_class_rec.business_class_interface_id,
5708 'AP_VENDOR_ID_NULL',
5709 g_user_id,
5710 g_login_id,
5711 'import_vendor_buss_class') <> TRUE) THEN
5712
5713 IF (g_level_procedure >= g_current_runtime_level) THEN
5714 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5715 p_data => l_msg_data);
5716 fnd_log.string(g_level_procedure,
5717 g_module_name || l_api_name,
5718 'Parameters: ' ||
5719 ' BUSINESS_CLASS_INTERFACE_ID: ' ||
5720 vendor_int_buss_class_rec.business_class_interface_id ||
5721 ' Buss and classification Validation Msg: ' ||
5722 l_msg_data);
5723 END IF;
5724 END IF;
5725 x_return_status := fnd_api.g_ret_sts_error;
5726 fnd_file.put_line(fnd_file.log,
5727 ' Vendor ID is null for: ' ||
5728 ' BUSINESS_CLASS_INTERFACE_ID: ' ||
5729 vendor_int_buss_class_rec.business_class_interface_id);
5730 GOTO continue_next_record;
5731 END;
5732 ELSE
5733 vendor_buss_class_rec.vendor_id := vendor_int_buss_class_rec.vendor_id;
5734 END IF;
5735
5736 fnd_file.put_line(fnd_file.log,
5737 ' Message: Inside PROCEDURE IMPORT_VENDOR_BUSS_CLASS' ||
5738 ' business_class_interface_id: ' ||
5739 vendor_buss_class_rec.business_class_interface_id ||
5740 ' party_id: ' || l_party_id || ' vendor_id: ' ||
5741 vendor_buss_class_rec.vendor_id);
5742
5743 BEGIN
5744 SELECT classification_id
5745 INTO l_classification_id
5746 FROM pos_bus_class_attr
5747 WHERE party_id = l_party_id
5748 AND vendor_id = vendor_buss_class_rec.vendor_id
5749 AND lookup_code = vendor_buss_class_rec.lookup_code;
5750
5751 EXCEPTION
5752 WHEN no_data_found THEN
5753 l_classification_id := 0;
5754 END;
5755
5756 BEGIN
5757 SELECT mapping_id
5758 INTO l_mapping_id
5759 FROM pos_supplier_mappings
5760 WHERE party_id = l_party_id
5761 AND vendor_id = vendor_buss_class_rec.vendor_id;
5762
5763 SELECT bus_class_request_id
5764 INTO l_buss_class_req_id
5765 FROM pos_bus_class_reqs
5766 WHERE mapping_id = l_mapping_id
5767 AND lookup_code = vendor_buss_class_rec.lookup_code;
5768
5769 EXCEPTION
5770 WHEN no_data_found THEN
5771 l_buss_class_req_id := 0;
5772 END;
5773
5774 IF (l_classification_id = 0 AND l_buss_class_req_id = 0) THEN
5775 vendor_int_buss_class_rec.insert_update_flag := nvl(vendor_int_buss_class_rec.insert_update_flag,
5776 'I');
5777 ELSE
5778 vendor_int_buss_class_rec.insert_update_flag := nvl(vendor_int_buss_class_rec.insert_update_flag,
5779 'U');
5780 END IF;
5781
5782 fnd_file.put_line(fnd_file.log,
5783 ' Message: Inside PROCEDURE IMPORT_VENDOR_BUSS_CLASS' ||
5784 ' business_class_interface_id: ' ||
5785 vendor_buss_class_rec.business_class_interface_id ||
5786 ' classification_id: ' || l_classification_id ||
5787 ' mapping_id: ' || l_mapping_id ||
5788 ' buss_class_req_id: ' || l_buss_class_req_id ||
5789 ' insert_update_flag: ' ||
5790 vendor_int_buss_class_rec.insert_update_flag);
5791
5792 IF (vendor_int_buss_class_rec.insert_update_flag = 'I') THEN
5793 create_vendor_buss_class(p_batch_id => p_batch_id,
5794 p_vendor_buss_class_rec => vendor_buss_class_rec,
5795 p_party_id => l_party_id,
5796 x_return_status => l_return_status,
5797 x_msg_count => l_msg_count,
5798 x_msg_data => l_msg_data);
5799
5800 IF l_return_status = fnd_api.g_ret_sts_success THEN
5801 UPDATE pos_business_class_int
5802 SET status = 'PROCESSED'
5803 WHERE business_class_interface_id =
5804 vendor_int_buss_class_rec.business_class_interface_id
5805 AND sdh_batch_id = p_batch_id;
5806
5807 UPDATE pos_imp_batch_summary
5808 SET total_records_imported = total_records_imported + 1,
5809 total_inserts = total_inserts + 1,
5810 buss_class_inserted = buss_class_inserted + 1,
5811 buss_class_imported = buss_class_imported + 1
5812 WHERE batch_id = p_batch_id;
5813
5814 ELSE
5815 UPDATE pos_business_class_int
5816 SET status = 'REJECTED'
5817 WHERE business_class_interface_id =
5818 vendor_int_buss_class_rec.business_class_interface_id
5819 AND sdh_batch_id = p_batch_id;
5820
5821 x_return_status := l_return_status;
5822
5823 IF (insert_rejections(p_batch_id,
5824 l_request_id,
5825 'POS_BUSINESS_CLASS_INT',
5826 vendor_int_buss_class_rec.business_class_interface_id,
5827 'POS_BUSS_CLASS_CREATION',
5828 g_user_id,
5829 g_login_id,
5830 'import_vendor_buss_class') <> TRUE) THEN
5831
5832 IF (g_level_procedure >= g_current_runtime_level) THEN
5833 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5834 p_data => l_msg_data);
5835 fnd_log.string(g_level_procedure,
5836 g_module_name || l_api_name,
5837 'Parameters: ' ||
5838 ' BUSINESS_CLASS_INTERFACE_ID: ' ||
5839 vendor_int_buss_class_rec.business_class_interface_id ||
5840 ' Buss and classification Validation Msg: ' ||
5841 l_msg_data);
5842 END IF;
5843 END IF;
5844 -- Insert the rejected records into table using Insert_Rejections API
5845
5846 END IF;
5847
5848 ELSE
5849 -- Update the details
5850 pos_supp_classification_pkg.update_bus_class_attr(p_party_id => l_party_id,
5851 p_vendor_id => vendor_buss_class_rec.vendor_id,
5852 p_selected => '',
5853 p_classification_id => l_classification_id,
5854 p_request_id => l_buss_class_req_id,
5855 p_lookup_code => vendor_int_buss_class_rec.lookup_code,
5856 p_exp_date => vendor_int_buss_class_rec.expiration_date,
5857 p_cert_num => vendor_int_buss_class_rec.certificate_number,
5858 p_cert_agency => vendor_int_buss_class_rec.certifying_agency,
5859 p_ext_attr_1 => vendor_int_buss_class_rec.ext_attr_1,
5860 p_class_status => vendor_int_buss_class_rec.class_status,
5861 x_classification_id => l_out_classification_id,
5862 x_request_id => l_out_buss_class_req_id,
5863 x_status => l_return_status,
5864 x_exception_msg => l_msg_data);
5865
5866 BEGIN
5867 fnd_file.put_line(fnd_file.log,
5868 'API to syncronise data with TCA pasing party_id and vendor_id');
5869 pos_supp_classification_pkg.synchronize_class_tca_to_po(l_party_id,
5870 vendor_buss_class_rec.vendor_id);
5871 END;
5872
5873 IF l_return_status = fnd_api.g_ret_sts_success THEN
5874 UPDATE pos_business_class_int
5875 SET status = 'PROCESSED'
5876 WHERE business_class_interface_id =
5877 vendor_int_buss_class_rec.business_class_interface_id
5878 AND sdh_batch_id = p_batch_id;
5879
5880 UPDATE pos_imp_batch_summary
5881 SET total_records_imported = total_records_imported + 1,
5882 total_updates = total_updates + 1,
5883 buss_class_updated = buss_class_updated + 1,
5884 buss_class_imported = buss_class_imported + 1
5885 WHERE batch_id = p_batch_id;
5886
5887 ELSE
5888 UPDATE pos_business_class_int
5889 SET status = 'REJECTED'
5890 WHERE business_class_interface_id =
5891 vendor_int_buss_class_rec.business_class_interface_id
5892 AND sdh_batch_id = p_batch_id;
5893
5894 x_return_status := l_return_status;
5895
5896 IF (insert_rejections(p_batch_id,
5897 l_request_id,
5898 'POS_BUSINESS_CLASS_INT',
5899 vendor_int_buss_class_rec.business_class_interface_id,
5900 'POS_BUSS_CLASS_UPDATION',
5901 g_user_id,
5902 g_login_id,
5903 'import_vendor_buss_class') <> TRUE) THEN
5904
5905 IF (g_level_procedure >= g_current_runtime_level) THEN
5906 fnd_msg_pub.count_and_get(p_count => l_msg_count,
5907 p_data => l_msg_data);
5908 fnd_log.string(g_level_procedure,
5909 g_module_name || l_api_name,
5910 'Parameters: ' ||
5911 ' BUSINESS_CLASS_INTERFACE_ID: ' ||
5912 vendor_int_buss_class_rec.business_class_interface_id ||
5913 ' Buss and classification Validation Msg: ' ||
5914 l_msg_data);
5915 END IF;
5916 END IF;
5917
5918 -- Insert the rejected records into table using Insert_Rejections API
5919 END IF;
5920
5921 END IF;
5922
5923 <<continue_next_record>>
5924 NULL;
5925 END LOOP;
5926
5927 CLOSE vendor_int_buss_class_cur;
5928 COMMIT;
5929
5930 -- Standard call to get message count and if count is 1,
5931 -- get message info.
5932 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
5933
5934 EXCEPTION
5935 WHEN fnd_api.g_exc_error THEN
5936 x_return_status := fnd_api.g_ret_sts_error;
5937 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5938 p_data => x_msg_data);
5939 fnd_file.put_line(fnd_file.log,
5940 ' Inside import_vendor_buss_class EXCEPTION ' ||
5941 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5942 WHEN fnd_api.g_exc_unexpected_error THEN
5943 x_return_status := fnd_api.g_ret_sts_unexp_error;
5944 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5945 p_data => x_msg_data);
5946 fnd_file.put_line(fnd_file.log,
5947 ' Inside import_vendor_buss_class unexpected EXCEPTION ' ||
5948 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5949 WHEN OTHERS THEN
5950 x_return_status := fnd_api.g_ret_sts_unexp_error;
5951
5952 fnd_msg_pub.count_and_get(p_count => x_msg_count,
5953 p_data => x_msg_data);
5954 fnd_file.put_line(fnd_file.log,
5955 ' Inside import_vendor_buss_class others EXCEPTION ' ||
5956 ' Message: ' || SQLCODE || ' ' || SQLERRM);
5957 END import_vendor_buss_class;
5958
5959 PROCEDURE validate_tax_profile
5960 (
5961 p_batch_id IN NUMBER,
5962 p_tax_profile_rec IN pos_party_tax_profile_int%ROWTYPE,
5963 x_return_status OUT NOCOPY VARCHAR2,
5964 x_msg_count OUT NOCOPY NUMBER,
5965 x_msg_data OUT NOCOPY VARCHAR2,
5966 x_tax_prof_valid OUT NOCOPY VARCHAR2,
5967 x_party_tax_profile_id OUT NOCOPY NUMBER,
5968 x_country_code OUT NOCOPY VARCHAR2
5969 ) IS
5970 l_dummy_lookup VARCHAR2(30);
5971 l_request_id NUMBER := fnd_global.conc_request_id;
5972
5973 l_msg_count NUMBER;
5974 l_msg_data VARCHAR2(2000);
5975 l_api_name CONSTANT VARCHAR2(50) := 'VALIDATE_VENDOR_PRODS_SERVICES';
5976 BEGIN
5977 fnd_file.put_line(fnd_file.log, ' Inside validate_tax_profile');
5978 -- Initialize API return status to success
5979 x_return_status := fnd_api.g_ret_sts_success;
5980
5981 x_tax_prof_valid := 'Y';
5982
5983 -- Check if the Tax Profile Id exists
5984 BEGIN
5985 SELECT party_tax_profile_id
5986 INTO x_party_tax_profile_id
5987 FROM zx_party_tax_profile
5988 WHERE party_id = p_tax_profile_rec.party_id
5989 AND party_type_code = 'THIRD_PARTY';
5990
5991 RETURN;
5992
5993 EXCEPTION
5994 WHEN no_data_found THEN
5995 NULL;
5996 END;
5997
5998 -- Validate the rounding Level using the following query
5999 IF (p_tax_profile_rec.rounding_level_code IS NOT NULL) THEN
6000 fnd_file.put_line(fnd_file.log, ' Validating rounding level');
6001 BEGIN
6002 SELECT fndlookup.lookup_code
6003 INTO l_dummy_lookup
6004 FROM fnd_lookups fndlookup
6005 WHERE fndlookup.lookup_type LIKE 'ZX_ROUNDING_LEVEL'
6006 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6007 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6008 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6009 AND lookup_code = p_tax_profile_rec.rounding_level_code
6010 ORDER BY fndlookup.lookup_code;
6011
6012 EXCEPTION
6013 WHEN OTHERS THEN
6014 x_tax_prof_valid := 'N';
6015 x_return_status := fnd_api.g_ret_sts_error;
6016 x_msg_data := 'POS_INVALID_ROUNDING_LEVEL';
6017 IF (insert_rejections(p_batch_id,
6018 l_request_id,
6019 'POS_PARTY_TAX_PROFILE_INT',
6020 p_tax_profile_rec.rounding_level_code,
6021 'POS_INVALID_ROUNDING_LEVEL',
6022 g_user_id,
6023 g_login_id,
6024 ' Validate_Tax_Profile ') <> TRUE) THEN
6025
6026 IF (g_level_procedure >= g_current_runtime_level) THEN
6027 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6028 p_data => l_msg_data);
6029 fnd_log.string(g_level_procedure,
6030 g_module_name || l_api_name,
6031 ' Acct Validation Msg: ' || l_msg_data);
6032 END IF;
6033 END IF;
6034 fnd_file.put_line(fnd_file.log,
6035 ' Invalid rounding level for: ' ||
6036 ' p_tax_profile_rec.rounding_level_code: ' ||
6037 p_tax_profile_rec.rounding_level_code);
6038 RETURN;
6039 END;
6040 END IF;
6041
6042 IF (p_tax_profile_rec.rounding_rule_code IS NOT NULL) THEN
6043 -- Validate the rounding Rule using the following query
6044 fnd_file.put_line(fnd_file.log, ' Validating rounding rule');
6045 BEGIN
6046 SELECT fndlookup.lookup_code
6047 INTO l_dummy_lookup
6048 FROM fnd_lookups fndlookup
6049 WHERE fndlookup.lookup_type LIKE 'ZX_ROUNDING_RULE'
6050 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6051 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6052 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6053 AND lookup_code = p_tax_profile_rec.rounding_rule_code
6054 ORDER BY fndlookup.lookup_code;
6055
6056 EXCEPTION
6057 WHEN OTHERS THEN
6058 x_tax_prof_valid := 'N';
6059 x_return_status := fnd_api.g_ret_sts_error;
6060 x_msg_data := 'POS_INVALID_ROUNDING_RULE';
6061 IF (insert_rejections(p_batch_id,
6062 l_request_id,
6063 'POS_PARTY_TAX_PROFILE_INT',
6064 p_tax_profile_rec.rounding_rule_code,
6065 'POS_INVALID_ROUNDING_RULE',
6066 g_user_id,
6067 g_login_id,
6068 ' Validate_Tax_Profile ') <> TRUE) THEN
6069
6070 IF (g_level_procedure >= g_current_runtime_level) THEN
6071 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6072 p_data => l_msg_data);
6073 fnd_log.string(g_level_procedure,
6074 g_module_name || l_api_name,
6075 'Msg: ' || l_msg_data);
6076 END IF;
6077 END IF;
6078 fnd_file.put_line(fnd_file.log,
6079 ' Invalid rounding rule for: ' ||
6080 ' p_tax_profile_rec.rounding_rule_code: ' ||
6081 p_tax_profile_rec.rounding_rule_code);
6082 RETURN;
6083 END;
6084 END IF;
6085
6086 IF (p_tax_profile_rec.country_name IS NOT NULL) THEN
6087 -- Validate the Country Name using the following query
6088 fnd_file.put_line(fnd_file.log, ' Validating Country name');
6089 BEGIN
6090 SELECT territory_code
6091 INTO x_country_code
6092 FROM fnd_territories_vl
6093 WHERE territory_short_name = p_tax_profile_rec.country_name;
6094
6095 -- Update the Interface table with the country code obtained in the prev SQL since the country code would be saved.
6096 EXCEPTION
6097 WHEN OTHERS THEN
6098 x_tax_prof_valid := 'N';
6099 x_return_status := fnd_api.g_ret_sts_error;
6100 x_msg_data := 'POS_INVALID_COUNTRY_NAME';
6101 IF (insert_rejections(p_batch_id,
6102 l_request_id,
6103 ' POS_PARTY_TAX_PROFILE_INT',
6104 p_tax_profile_rec.country_name,
6105 'POS_INVALID_COUNTRY_NAME',
6106 g_user_id,
6107 g_login_id,
6108 ' Validate_Tax_Profile ') <> TRUE) THEN
6109
6110 IF (g_level_procedure >= g_current_runtime_level) THEN
6111 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6112 p_data => l_msg_data);
6113 fnd_log.string(g_level_procedure,
6114 g_module_name || l_api_name,
6115 'Msg: ' || l_msg_data);
6116 END IF;
6117 END IF;
6118 fnd_file.put_line(fnd_file.log,
6119 ' Invalid country name for: ' ||
6120 ' p_tax_profile_rec.country_name: ' ||
6121 p_tax_profile_rec.country_name);
6122 RETURN;
6123 END;
6124 END IF;
6125
6126 IF (p_tax_profile_rec.registration_type_code IS NOT NULL) THEN
6127 -- Validate the Registration Type Code using the following query
6128 fnd_file.put_line(fnd_file.log, ' Validating registration type');
6129 BEGIN
6130 SELECT fndlookup.lookup_code
6131 INTO l_dummy_lookup
6132 FROM fnd_lookups fndlookup
6133 WHERE fndlookup.lookup_type LIKE 'ZX_REGISTRATIONS_TYPE'
6134 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6135 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6136 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6137 AND lookup_code = p_tax_profile_rec.registration_type_code
6138 ORDER BY fndlookup.lookup_code;
6139
6140 EXCEPTION
6141 WHEN OTHERS THEN
6142 x_tax_prof_valid := 'N';
6143 x_return_status := fnd_api.g_ret_sts_error;
6144 x_msg_data := 'POS_INVALID_REGI_TYPE_CODE';
6145 IF (insert_rejections(p_batch_id,
6146 l_request_id,
6147 'POS_PARTY_TAX_PROFILE_INT',
6148 p_tax_profile_rec.registration_type_code,
6149 'POS_INVALID_REGI_TYPE_CODE',
6150 g_user_id,
6151 g_login_id,
6152 ' Validate_Tax_Profile ') <> TRUE) THEN
6153
6154 IF (g_level_procedure >= g_current_runtime_level) THEN
6155 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6156 p_data => l_msg_data);
6157 fnd_log.string(g_level_procedure,
6158 g_module_name || l_api_name,
6159 'Msg: ' || l_msg_data);
6160 END IF;
6161 END IF;
6162 fnd_file.put_line(fnd_file.log,
6163 ' Invalid Registration Type Code for: ' ||
6164 ' p_tax_profile_rec.registration_type_code: ' ||
6165 p_tax_profile_rec.registration_type_code);
6166 RETURN;
6167 END;
6168 END IF;
6169
6170 EXCEPTION
6171 WHEN OTHERS THEN
6172 x_tax_prof_valid := 'N';
6173 x_return_status := fnd_api.g_ret_sts_error;
6174 fnd_msg_pub.count_and_get(p_count => x_msg_count,
6175 p_data => x_msg_data);
6176 fnd_file.put_line(fnd_file.log,
6177 ' Inside validate_tax_profile EXCEPTION ' ||
6178 ' Message: ' || SQLCODE || ' ' || SQLERRM);
6179 END validate_tax_profile;
6180
6181 PROCEDURE create_tax_profile
6182 (
6183 p_batch_id IN NUMBER,
6184 p_tax_profile_rec IN pos_party_tax_profile_int%ROWTYPE,
6185 x_return_status OUT NOCOPY VARCHAR2,
6186 x_msg_count OUT NOCOPY NUMBER,
6187 x_msg_data OUT NOCOPY VARCHAR2,
6188 x_tax_profile_id OUT NOCOPY NUMBER
6189 ) IS
6190 l_tax_prof_valid VARCHAR2(10);
6191 l_party_tax_profile_id NUMBER;
6192 l_country_code VARCHAR2(40);
6193 l_return_status VARCHAR2(100);
6194 l_msg_count NUMBER;
6195 l_msg_data VARCHAR2(4000);
6196
6197 BEGIN
6198 x_return_status := fnd_api.g_ret_sts_success;
6199
6200 -- Call Validate_Tax_profile to validate the Tax Profiledata
6201 validate_tax_profile(p_batch_id => p_batch_id,
6202 p_tax_profile_rec => p_tax_profile_rec,
6203 x_return_status => l_return_status,
6204 x_msg_count => l_msg_count,
6205 x_msg_data => l_msg_data,
6206 x_tax_prof_valid => l_tax_prof_valid,
6207 x_party_tax_profile_id => l_party_tax_profile_id,
6208 x_country_code => l_country_code);
6209
6210 fnd_file.put_line(fnd_file.log,
6211 ' p_rounding_level_code: ' ||
6212 p_tax_profile_rec.rounding_level_code ||
6213 ' p_rounding_rule_code: ' ||
6214 p_tax_profile_rec.rounding_rule_code);
6215
6216 IF (l_tax_prof_valid = 'Y') THEN
6217
6218 IF (p_tax_profile_rec.insert_update_flag = 'U') THEN
6219 fnd_file.put_line(fnd_file.log, ' Updating Tax profile');
6220 zx_party_tax_profile_pkg.update_row(p_party_tax_profile_id => l_party_tax_profile_id,
6221 p_collecting_authority_flag => NULL,
6222 p_provider_type_code => NULL,
6223 p_create_awt_dists_type_code => NULL,
6224 p_create_awt_invoices_type_cod => NULL,
6225 p_tax_classification_code => NULL,
6226 p_self_assess_flag => NULL,
6227 p_allow_offset_tax_flag => NULL,
6228 p_rep_registration_number => p_tax_profile_rec.rep_registration_number,
6229 p_effective_from_use_le => NULL,
6230 p_record_type_code => NULL,
6231 p_request_id => NULL,
6232 p_attribute1 => NULL,
6233 p_attribute2 => NULL,
6234 p_attribute3 => NULL,
6235 p_attribute4 => NULL,
6236 p_attribute5 => NULL,
6237 p_attribute6 => NULL,
6238 p_attribute7 => NULL,
6239 p_attribute8 => NULL,
6240 p_attribute9 => NULL,
6241 p_attribute10 => NULL,
6242 p_attribute11 => NULL,
6243 p_attribute12 => NULL,
6244 p_attribute13 => NULL,
6245 p_attribute14 => NULL,
6246 p_attribute15 => NULL,
6247 p_attribute_category => NULL,
6248 p_party_id => p_tax_profile_rec.party_id,
6249 p_program_login_id => NULL,
6250 p_party_type_code => 'THIRD_PARTY',
6251 p_supplier_flag => NULL,
6252 p_customer_flag => NULL,
6253 p_site_flag => NULL,
6254 p_process_for_applicability_fl => NULL,
6255 p_rounding_level_code => p_tax_profile_rec.rounding_level_code,
6256 p_rounding_rule_code => p_tax_profile_rec.rounding_rule_code,
6257 p_withholding_start_date => NULL,
6258 p_inclusive_tax_flag => p_tax_profile_rec.inclusive_tax_flag,
6259 p_allow_awt_flag => NULL,
6260 p_use_le_as_subscriber_flag => NULL,
6261 p_legal_establishment_flag => NULL,
6262 p_first_party_le_flag => NULL,
6263 p_reporting_authority_flag => NULL,
6264 x_return_status => l_return_status,
6265 p_registration_type_code => p_tax_profile_rec.registration_type_code,
6266 p_country_code => l_country_code);
6267
6268 x_tax_profile_id := l_party_tax_profile_id;
6269 ELSE
6270 -- Insert
6271 fnd_file.put_line(fnd_file.log, ' Creating Tax profile');
6272 zx_party_tax_profile_pkg.insert_row(p_collecting_authority_flag => NULL,
6273 p_provider_type_code => NULL,
6274 p_create_awt_dists_type_code => NULL,
6275 p_create_awt_invoices_type_cod => NULL,
6276 p_tax_classification_code => NULL,
6277 p_self_assess_flag => NULL,
6278 p_allow_offset_tax_flag => NULL,
6279 p_rep_registration_number => p_tax_profile_rec.rep_registration_number,
6280 p_effective_from_use_le => NULL,
6281 p_record_type_code => NULL,
6282 p_request_id => NULL,
6283 p_attribute1 => NULL,
6284 p_attribute2 => NULL,
6285 p_attribute3 => NULL,
6286 p_attribute4 => NULL,
6287 p_attribute5 => NULL,
6288 p_attribute6 => NULL,
6289 p_attribute7 => NULL,
6290 p_attribute8 => NULL,
6291 p_attribute9 => NULL,
6292 p_attribute10 => NULL,
6293 p_attribute11 => NULL,
6294 p_attribute12 => NULL,
6295 p_attribute13 => NULL,
6296 p_attribute14 => NULL,
6297 p_attribute15 => NULL,
6298 p_attribute_category => NULL,
6299 p_party_id => p_tax_profile_rec.party_id,
6300 p_program_login_id => NULL,
6301 p_party_type_code => 'THIRD_PARTY',
6302 p_supplier_flag => NULL,
6303 p_customer_flag => NULL,
6304 p_site_flag => NULL,
6305 p_process_for_applicability_fl => NULL,
6306 p_rounding_level_code => p_tax_profile_rec.rounding_level_code,
6307 p_rounding_rule_code => p_tax_profile_rec.rounding_rule_code,
6308 p_withholding_start_date => NULL,
6309 p_inclusive_tax_flag => p_tax_profile_rec.inclusive_tax_flag,
6310 p_allow_awt_flag => NULL,
6311 p_use_le_as_subscriber_flag => NULL,
6312 p_legal_establishment_flag => NULL,
6313 p_first_party_le_flag => NULL,
6314 p_reporting_authority_flag => NULL,
6315 x_return_status => l_return_status,
6316 p_registration_type_code => p_tax_profile_rec.registration_type_code,
6317 p_country_code => l_country_code);
6318
6319 -- The ZX API doesn't return the Tax Profile Id that has been created
6320 -- So re-querying the Tax profile Id using the party Id and the party Type
6321 --
6322 IF (l_return_status = 'S') THEN
6323 SELECT party_tax_profile_id
6324 INTO l_party_tax_profile_id
6325 FROM zx_party_tax_profile
6326 WHERE party_id = p_tax_profile_rec.party_id
6327 AND party_type_code = 'THIRD_PARTY';
6328
6329 x_tax_profile_id := l_party_tax_profile_id;
6330 END IF;
6331 END IF;
6332 ELSE
6333 x_return_status := l_return_status;
6334 x_msg_data := l_msg_data;
6335 x_msg_count := l_msg_count;
6336 fnd_file.put_line(fnd_file.log,
6337 ' Tax profile validation failed for: ' ||
6338 ' tax_profile_interface_id: ' ||
6339 p_tax_profile_rec.tax_profile_interface_id);
6340 END IF;
6341
6342 EXCEPTION
6343 WHEN OTHERS THEN
6344 x_return_status := fnd_api.g_ret_sts_unexp_error;
6345
6346 fnd_msg_pub.count_and_get(p_count => x_msg_count,
6347 p_data => x_msg_data);
6348 fnd_file.put_line(fnd_file.log,
6349 ' Inside create_tax_profile EXCEPTION ' ||
6350 ' Message: ' || SQLCODE || ' ' || SQLERRM);
6351 END create_tax_profile;
6352
6353 /*
6354 TAX REGISTRATIONS
6355 */
6356
6357 PROCEDURE validate_tax_registration
6358 (
6359 p_batch_id IN NUMBER,
6360 p_tax_reg_rec IN pos_party_tax_reg_int%ROWTYPE,
6361 x_return_status OUT NOCOPY VARCHAR2,
6362 x_msg_count OUT NOCOPY NUMBER,
6363 x_msg_data OUT NOCOPY VARCHAR2,
6364 x_tax_reg_valid OUT NOCOPY VARCHAR2,
6365 x_registration_loc_id OUT NOCOPY NUMBER,
6366 x_tax_authority_party_id OUT NOCOPY NUMBER
6367 ) IS
6368 l_dummy_lookup VARCHAR2(30);
6369 l_dummy_location NUMBER;
6370 l_tax_authority_party_id NUMBER;
6371
6372 l_request_id NUMBER := fnd_global.conc_request_id;
6373
6374 l_msg_count NUMBER;
6375 l_msg_data VARCHAR2(2000);
6376 l_api_name CONSTANT VARCHAR2(50) := 'VALIDATE_VENDOR_PRODS_SERVICES';
6377 BEGIN
6378 fnd_file.put_line(fnd_file.log, ' Inside validate_tax_registration');
6379 -- Initialize API return status to success
6380 x_return_status := fnd_api.g_ret_sts_success;
6381
6382 x_tax_reg_valid := 'Y';
6383
6384 -- Validate the Tax Registration Type using the following query
6385 IF (p_tax_reg_rec.registration_type_code IS NOT NULL) THEN
6386 BEGIN
6387 fnd_file.put_line(fnd_file.log,
6388 ' Validating tax registration type');
6389 SELECT fndlookup.lookup_code
6390 INTO l_dummy_lookup
6391 FROM fnd_lookups fndlookup
6392 WHERE fndlookup.lookup_type LIKE 'ZX_REGISTRATIONS_TYPE'
6393 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6394 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6395 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6396 AND lookup_code = p_tax_reg_rec.registration_type_code
6397 ORDER BY fndlookup.lookup_code;
6398
6399 EXCEPTION
6400 WHEN OTHERS THEN
6401 x_tax_reg_valid := 'N';
6402 x_return_status := fnd_api.g_ret_sts_error;
6403 x_msg_data := 'POS_INVALID_REGI_TYPE_CODE';
6404 IF (insert_rejections(p_batch_id,
6405 l_request_id,
6406 'POS_PARTY_TAX_REG_INT',
6407 p_tax_reg_rec.registration_type_code,
6408 'POS_INVALID_REGI_TYPE_CODE',
6409 g_user_id,
6410 g_login_id,
6411 ' Validate_Tax_Registration ') <> TRUE) THEN
6412
6413 IF (g_level_procedure >= g_current_runtime_level) THEN
6414 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6415 p_data => l_msg_data);
6416 fnd_log.string(g_level_procedure,
6417 g_module_name || l_api_name,
6418 'Msg: ' || l_msg_data);
6419 END IF;
6420 END IF;
6421 fnd_file.put_line(fnd_file.log,
6422 ' Invalid Tax Registration Type for: ' ||
6423 ' p_tax_reg_rec.registration_type_code: ' ||
6424 p_tax_reg_rec.registration_type_code);
6425 RETURN;
6426 END;
6427 END IF;
6428
6429 -- Validate the Tax Registration Status using the following query
6430 IF (p_tax_reg_rec.registration_status_code IS NOT NULL) THEN
6431 fnd_file.put_line(fnd_file.log,
6432 ' Validating tax registration status');
6433 BEGIN
6434 SELECT fndlookup.lookup_code
6435 INTO l_dummy_lookup
6436 FROM fnd_lookups fndlookup
6437 WHERE fndlookup.lookup_type LIKE 'ZX_REGISTRATIONS_STATUS'
6438 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6439 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6440 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6441 AND lookup_code = p_tax_reg_rec.registration_status_code
6442 ORDER BY fndlookup.lookup_code;
6443
6444 EXCEPTION
6445 WHEN OTHERS THEN
6446 x_tax_reg_valid := 'N';
6447 x_return_status := fnd_api.g_ret_sts_error;
6448 x_msg_data := 'POS_INVALID_REG_STATUS_CODE';
6449 IF (insert_rejections(p_batch_id,
6450 l_request_id,
6451 'POS_PARTY_TAX_REG_INT',
6452 p_tax_reg_rec.registration_status_code,
6453 'POS_INVALID_REG_STATUS_CODE',
6454 g_user_id,
6455 g_login_id,
6456 ' Validate_Tax_Registration ') <> TRUE) THEN
6457
6458 IF (g_level_procedure >= g_current_runtime_level) THEN
6459 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6460 p_data => l_msg_data);
6461 fnd_log.string(g_level_procedure,
6462 g_module_name || l_api_name,
6463 'Msg: ' || l_msg_data);
6464 END IF;
6465 END IF;
6466 fnd_file.put_line(fnd_file.log,
6467 ' Invalid Tax Registration Status for: ' ||
6468 ' p_tax_reg_rec.registration_status_code: ' ||
6469 p_tax_reg_rec.registration_status_code);
6470 RETURN;
6471 END;
6472 END IF;
6473
6474 IF (p_tax_reg_rec.registration_address IS NOT NULL) THEN
6475 -- Validate the Local Reg Address using the following query
6476 fnd_file.put_line(fnd_file.log,
6477 ' Validating Tax registration address');
6478 BEGIN
6479 SELECT loc.location_id
6480 INTO l_dummy_location
6481 FROM hr_locations loc
6482 WHERE loc.location_code || ':' || ' ' || loc.address_line_1 || ' ' ||
6483 loc.town_or_city || ' ' || loc.region_1 =
6484 p_tax_reg_rec.registration_address
6485 AND legal_address_flag = 'Y'
6486 AND SYSDATE < nvl(inactive_date, SYSDATE + 1);
6487
6488 x_registration_loc_id := l_dummy_location;
6489
6490 EXCEPTION
6491 WHEN OTHERS THEN
6492 x_tax_reg_valid := 'N';
6493 x_return_status := fnd_api.g_ret_sts_error;
6494 x_msg_data := 'POS_INVALID_REG_ADDRESS';
6495 IF (insert_rejections(p_batch_id,
6496 l_request_id,
6497 'POS_PARTY_TAX_REG_INT',
6498 p_tax_reg_rec.registration_address,
6499 'POS_INVALID_REG_ADDRESS',
6500 g_user_id,
6501 g_login_id,
6502 ' Validate_Tax_Registration ') <> TRUE) THEN
6503
6504 IF (g_level_procedure >= g_current_runtime_level) THEN
6505 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6506 p_data => l_msg_data);
6507 fnd_log.string(g_level_procedure,
6508 g_module_name || l_api_name,
6509 'Msg: ' || l_msg_data);
6510 END IF;
6511 END IF;
6512 fnd_file.put_line(fnd_file.log,
6513 ' Invalid Local Reg Address for: ' ||
6514 ' p_tax_reg_rec.registration_address: ' ||
6515 p_tax_reg_rec.registration_address);
6516 RETURN;
6517 END;
6518 END IF;
6519
6520 IF (p_tax_reg_rec.registration_reason_code IS NOT NULL) THEN
6521 -- Validate the Tax Registration Reason using the following query
6522 fnd_file.put_line(fnd_file.log,
6523 ' Validating tax registration reason code');
6524 BEGIN
6525 SELECT fndlookup.lookup_code
6526 INTO l_dummy_lookup
6527 FROM fnd_lookups fndlookup
6528 WHERE fndlookup.lookup_type LIKE 'ZX_REGISTRATIONS_REASON'
6529 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6530 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6531 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6532 AND lookup_code = p_tax_reg_rec.registration_reason_code
6533 ORDER BY fndlookup.lookup_code;
6534
6535 EXCEPTION
6536 WHEN OTHERS THEN
6537 x_tax_reg_valid := 'N';
6538 x_return_status := fnd_api.g_ret_sts_error;
6539 x_msg_data := 'POS_INVALID_REG_REASON_CODE';
6540 IF (insert_rejections(p_batch_id,
6541 l_request_id,
6542 'POS_PARTY_TAX_REG_INT',
6543 p_tax_reg_rec.registration_reason_code,
6544 'POS_INVALID_REG_REASON_CODE',
6545 g_user_id,
6546 g_login_id,
6547 ' Validate_Tax_Registration ') <> TRUE) THEN
6548
6549 IF (g_level_procedure >= g_current_runtime_level) THEN
6550 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6551 p_data => l_msg_data);
6552 fnd_log.string(g_level_procedure,
6553 g_module_name || l_api_name,
6554 'Msg: ' || l_msg_data);
6555 END IF;
6556 END IF;
6557 fnd_file.put_line(fnd_file.log,
6558 ' Invalid Tax Registration Reason for: ' ||
6559 ' p_tax_reg_rec.registration_reason_code: ' ||
6560 p_tax_reg_rec.registration_reason_code);
6561 RETURN;
6562 END;
6563 END IF;
6564
6565 IF (p_tax_reg_rec.registration_source_code IS NOT NULL) THEN
6566 -- Validate the Tax Registration Source using the following query
6567 fnd_file.put_line(fnd_file.log,
6568 ' Validating tax registration source code');
6569 BEGIN
6570 SELECT fndlookup.lookup_code
6571 INTO l_dummy_lookup
6572 FROM fnd_lookups fndlookup
6573 WHERE fndlookup.lookup_type LIKE 'ZX_REGISTRATIONS_SOURCE'
6574 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6575 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6576 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6577 AND lookup_code = p_tax_reg_rec.registration_source_code
6578 ORDER BY fndlookup.lookup_code;
6579
6580 EXCEPTION
6581 WHEN OTHERS THEN
6582 x_tax_reg_valid := 'N';
6583 x_return_status := fnd_api.g_ret_sts_error;
6584 x_msg_data := 'POS_INVALID_REG_SOURCE_CODE';
6585 IF (insert_rejections(p_batch_id,
6586 l_request_id,
6587 'POS_PARTY_TAX_REG_INT',
6588 p_tax_reg_rec.registration_source_code,
6589 'POS_INVALID_REG_SOURCE_CODE',
6590 g_user_id,
6591 g_login_id,
6592 ' Validate_Tax_Registration ') <> TRUE) THEN
6593
6594 IF (g_level_procedure >= g_current_runtime_level) THEN
6595 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6596 p_data => l_msg_data);
6597 fnd_log.string(g_level_procedure,
6598 g_module_name || l_api_name,
6599 'Msg: ' || l_msg_data);
6600 END IF;
6601 END IF;
6602 fnd_file.put_line(fnd_file.log,
6603 ' Invalid Tax Registration Source for: ' ||
6604 ' p_tax_reg_rec.registration_source_code: ' ||
6605 p_tax_reg_rec.registration_source_code);
6606 RETURN;
6607 END;
6608 END IF;
6609
6610 IF (p_tax_reg_rec.rounding_rule_code IS NOT NULL) THEN
6611 -- Validate the Tax Registration Rounding rule using the following query
6612 fnd_file.put_line(fnd_file.log,
6613 ' Validating tax registration rounding rule code');
6614 BEGIN
6615 SELECT fndlookup.lookup_code
6616 INTO l_dummy_lookup
6617 FROM fnd_lookups fndlookup
6618 WHERE fndlookup.lookup_type LIKE 'ZX_ROUNDING_RULE'
6619 AND nvl(fndlookup.start_date_active, SYSDATE) <= SYSDATE
6620 AND nvl(fndlookup.end_date_active, SYSDATE) >= SYSDATE
6621 AND nvl(fndlookup.enabled_flag, 'N') = 'Y'
6622 AND lookup_code = p_tax_reg_rec.rounding_rule_code
6623 ORDER BY fndlookup.lookup_code;
6624
6625 EXCEPTION
6626 WHEN OTHERS THEN
6627 x_tax_reg_valid := 'N';
6628 x_return_status := fnd_api.g_ret_sts_error;
6629 x_msg_data := 'POS_INVALID_ROUND_RULE_CODE';
6630 IF (insert_rejections(p_batch_id,
6631 l_request_id,
6632 'POS_PARTY_TAX_REG_INT',
6633 p_tax_reg_rec.rounding_rule_code,
6634 'POS_INVALID_ROUND_RULE_CODE',
6635 g_user_id,
6636 g_login_id,
6637 ' Validate_Tax_Registration ') <> TRUE) THEN
6638
6639 IF (g_level_procedure >= g_current_runtime_level) THEN
6640 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6641 p_data => l_msg_data);
6642 fnd_log.string(g_level_procedure,
6643 g_module_name || l_api_name,
6644 'Msg: ' || l_msg_data);
6645 END IF;
6646 END IF;
6647 fnd_file.put_line(fnd_file.log,
6648 ' Invalid Tax Registration Rounding rule for: ' ||
6649 ' p_tax_reg_rec.rounding_rule_code: ' ||
6650 p_tax_reg_rec.rounding_rule_code);
6651 RETURN;
6652 END;
6653 END IF;
6654
6655 -- get TAX_AUTHORITY party id
6656 IF (p_tax_reg_rec.tax_authority_party_id IS NULL AND
6657 p_tax_reg_rec.tax_authority_name IS NOT NULL) THEN
6658 fnd_file.put_line(fnd_file.log, ' Getting tax authority party id');
6659 BEGIN
6660 SELECT prof.party_id
6661 INTO l_tax_authority_party_id
6662 FROM zx_party_tax_profile prof,
6663 hz_parties hp
6664 WHERE hp.party_id = prof.party_id
6665 AND prof.party_type_code = 'TAX_AUTHORITY'
6666 AND hp.party_name = p_tax_reg_rec.tax_authority_name;
6667
6668 x_tax_authority_party_id := l_tax_authority_party_id;
6669
6670 EXCEPTION
6671 WHEN OTHERS THEN
6672 x_tax_reg_valid := 'N';
6673 x_return_status := fnd_api.g_ret_sts_error;
6674 x_msg_data := 'POS_INVALID_TAX_AUTHORITY';
6675 IF (insert_rejections(p_batch_id,
6676 l_request_id,
6677 'POS_PARTY_TAX_REG_INT',
6678 p_tax_reg_rec.rounding_rule_code,
6679 'POS_INVALID_TAX_AUTHORITY',
6680 g_user_id,
6681 g_login_id,
6682 ' Validate_Tax_Registration ') <> TRUE) THEN
6683
6684 IF (g_level_procedure >= g_current_runtime_level) THEN
6685 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6686 p_data => l_msg_data);
6687 fnd_log.string(g_level_procedure,
6688 g_module_name || l_api_name,
6689 'Msg: ' || l_msg_data);
6690 END IF;
6691 END IF;
6692 fnd_file.put_line(fnd_file.log,
6693 ' Invalid Tax Authority Name rule for: ' ||
6694 ' p_tax_reg_rec.tax_authority_name: ' ||
6695 p_tax_reg_rec.tax_authority_name);
6696 RETURN;
6697 END;
6698
6699 END IF;
6700 EXCEPTION
6701 WHEN OTHERS THEN
6702 x_tax_reg_valid := 'N';
6703 x_return_status := fnd_api.g_ret_sts_error;
6704 fnd_msg_pub.count_and_get(p_count => x_msg_count,
6705 p_data => x_msg_data);
6706 fnd_file.put_line(fnd_file.log,
6707 ' Inside validate_tax_registration EXCEPTION ' ||
6708 ' Message: ' || SQLCODE || ' ' || SQLERRM);
6709 END validate_tax_registration;
6710
6711 PROCEDURE create_tax_registration
6712 (
6713 p_batch_id IN NUMBER,
6714 p_tax_registration_rec IN pos_party_tax_reg_int%ROWTYPE,
6715 x_return_status OUT NOCOPY VARCHAR2,
6716 x_msg_count OUT NOCOPY NUMBER,
6717 x_msg_data OUT NOCOPY VARCHAR2
6718 ) IS
6719 l_location_id NUMBER;
6720 l_return_status VARCHAR2(100);
6721 l_creation_status VARCHAR2(100);
6722 l_msg_count NUMBER;
6723 l_msg_data VARCHAR2(4000);
6724 l_valid VARCHAR2(100);
6725 l_tax_authority_party_id NUMBER;
6726 l_request_id NUMBER := fnd_global.conc_request_id;
6727 BEGIN
6728 fnd_file.put_line(fnd_file.log, ' Inside create_tax_registration');
6729 x_return_status := fnd_api.g_ret_sts_success;
6730
6731 validate_tax_registration(p_batch_id => p_batch_id,
6732 p_tax_reg_rec => p_tax_registration_rec,
6733 x_return_status => l_return_status,
6734 x_msg_count => l_msg_count,
6735 x_msg_data => l_msg_data,
6736 x_tax_reg_valid => l_valid,
6737 x_registration_loc_id => l_location_id,
6738 x_tax_authority_party_id => l_tax_authority_party_id);
6739
6740 IF (l_valid = 'Y') THEN
6741 fnd_file.put_line(fnd_file.log,
6742 ' Calling zx_registrations_pkg.insert_row');
6743
6744 zx_registrations_pkg.insert_row(p_request_id => NULL,
6745 p_attribute1 => NULL,
6746 p_attribute2 => NULL,
6747 p_attribute3 => NULL,
6748 p_attribute4 => NULL,
6749 p_attribute5 => NULL,
6750 p_attribute6 => NULL,
6751 p_validation_rule => NULL,
6752 p_rounding_rule_code => p_tax_registration_rec.rounding_rule_code,
6753 p_tax_jurisdiction_code => p_tax_registration_rec.tax_jurisdiction_code,
6754 p_self_assess_flag => NULL,
6755 p_registration_status_code => p_tax_registration_rec.registration_status_code,
6756 p_registration_source_code => p_tax_registration_rec.registration_source_code,
6757 p_registration_reason_code => p_tax_registration_rec.registration_reason_code,
6758 p_tax => p_tax_registration_rec.tax,
6759 p_tax_regime_code => p_tax_registration_rec.tax_regime_code,
6760 p_inclusive_tax_flag => p_tax_registration_rec.inclusive_tax_flag,
6761 p_effective_from => p_tax_registration_rec.effective_from,
6762 p_effective_to => p_tax_registration_rec.effective_to,
6763 p_rep_party_tax_name => p_tax_registration_rec.rep_party_tax_name,
6764 p_default_registration_flag => p_tax_registration_rec.default_registration_flag,
6765 p_bank_account_num => NULL,
6766 p_record_type_code => NULL,
6767 p_legal_location_id => l_location_id,
6768 p_tax_authority_id => l_tax_authority_party_id,
6769 p_rep_tax_authority_id => NULL,
6770 p_coll_tax_authority_id => NULL,
6771 p_registration_type_code => p_tax_registration_rec.registration_type_code,
6772 p_registration_number => p_tax_registration_rec.registration_number,
6773 p_party_tax_profile_id => p_tax_registration_rec.tax_profile_id,
6774 p_legal_registration_id => NULL,
6775 p_bank_id => NULL,
6776 p_bank_branch_id => NULL,
6777 p_account_site_id => NULL,
6778 p_attribute14 => NULL,
6779 p_attribute15 => NULL,
6780 p_attribute_category => NULL,
6781 p_program_login_id => NULL,
6782 p_account_id => NULL,
6783 p_tax_classification_code => NULL,
6784 p_attribute7 => NULL,
6785 p_attribute8 => NULL,
6786 p_attribute9 => NULL,
6787 p_attribute10 => NULL,
6788 p_attribute11 => NULL,
6789 p_attribute12 => NULL,
6790 p_attribute13 => NULL,
6791 x_return_status => l_creation_status);
6792
6793 x_return_status := l_creation_status;
6794 x_msg_count := l_msg_count;
6795 x_msg_data := l_msg_data;
6796
6797 ELSE
6798 x_return_status := l_return_status;
6799 x_msg_count := l_msg_count;
6800 x_msg_data := l_msg_data;
6801 END IF;
6802
6803 IF x_return_status = fnd_api.g_ret_sts_error THEN
6804 -- Read the Error buffer returned from the API
6805 -- Add the error buffer message to supplier rejections
6806 -- table
6807 IF (insert_rejections(p_batch_id,
6808 l_request_id,
6809 'POS_PARTY_TAX_REG_INT',
6810 p_tax_registration_rec.registration_type_code,
6811 'POS_INVALID_TAX_REG_INS',
6812 g_user_id,
6813 g_login_id,
6814 ' Create_Tax_Registration ') <> TRUE) THEN
6815
6816 IF (g_level_procedure >= g_current_runtime_level) THEN
6817 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6818 p_data => l_msg_data);
6819 fnd_log.string(g_level_procedure,
6820 g_module_name || 'Create_Tax_Registration',
6821 'Msg: ' || l_msg_data);
6822 END IF;
6823 END IF;
6824 fnd_file.put_line(fnd_file.log,
6825 ' Tax Registration validation/creation failed for: ' ||
6826 ' tax_reg_interface_id: ' ||
6827 p_tax_registration_rec.tax_reg_interface_id);
6828 END IF;
6829 EXCEPTION
6830 WHEN OTHERS THEN
6831 x_return_status := fnd_api.g_ret_sts_error;
6832 fnd_msg_pub.count_and_get(p_count => x_msg_count,
6833 p_data => x_msg_data);
6834 fnd_file.put_line(fnd_file.log,
6835 ' Inside create_tax_registration EXCEPTION ' ||
6836 ' Message: ' || SQLCODE || ' ' || SQLERRM);
6837 END create_tax_registration;
6838
6839 PROCEDURE update_tax_registration
6840 (
6841 p_batch_id IN NUMBER,
6842 p_registration_id IN NUMBER,
6843 p_tax_registration_rec IN pos_party_tax_reg_int%ROWTYPE,
6844 x_return_status OUT NOCOPY VARCHAR2,
6845 x_msg_count OUT NOCOPY NUMBER,
6846 x_msg_data OUT NOCOPY VARCHAR2
6847 ) IS
6848 l_location_id NUMBER;
6849 l_return_status VARCHAR2(100);
6850 l_creation_status VARCHAR2(100);
6851 l_msg_count NUMBER;
6852 l_msg_data VARCHAR2(4000);
6853 l_valid VARCHAR2(100);
6854 l_tax_authority_party_id NUMBER;
6855 l_request_id NUMBER := fnd_global.conc_request_id;
6856 BEGIN
6857 fnd_file.put_line(fnd_file.log, ' Inside update_tax_registration');
6858 -- Initialize API return status to success
6859 x_return_status := fnd_api.g_ret_sts_success;
6860
6861 validate_tax_registration(p_batch_id => p_batch_id,
6862 p_tax_reg_rec => p_tax_registration_rec,
6863 x_return_status => l_return_status,
6864 x_msg_count => l_msg_count,
6865 x_msg_data => l_msg_data,
6866 x_tax_reg_valid => l_valid,
6867 x_registration_loc_id => l_location_id,
6868 x_tax_authority_party_id => l_tax_authority_party_id);
6869
6870 IF (l_valid = 'Y') THEN
6871 fnd_file.put_line(fnd_file.log,
6872 ' Calling zx_registrations_pkg.update_row');
6873
6874 zx_registrations_pkg.update_row(p_registration_id => p_registration_id,
6875 p_request_id => NULL,
6876 p_attribute1 => NULL,
6877 p_attribute2 => NULL,
6878 p_attribute3 => NULL,
6879 p_attribute4 => NULL,
6880 p_attribute5 => NULL,
6881 p_attribute6 => NULL,
6882 p_validation_rule => NULL,
6883 p_rounding_rule_code => p_tax_registration_rec.rounding_rule_code,
6884 p_tax_jurisdiction_code => p_tax_registration_rec.tax_jurisdiction_code,
6885 p_self_assess_flag => NULL,
6886 p_registration_status_code => p_tax_registration_rec.registration_status_code,
6887 p_registration_source_code => p_tax_registration_rec.registration_source_code,
6888 p_registration_reason_code => p_tax_registration_rec.registration_reason_code,
6889 p_tax => p_tax_registration_rec.tax,
6890 p_tax_regime_code => p_tax_registration_rec.tax_regime_code,
6891 p_inclusive_tax_flag => p_tax_registration_rec.inclusive_tax_flag,
6892 p_effective_from => p_tax_registration_rec.effective_from,
6893 p_effective_to => p_tax_registration_rec.effective_to,
6894 p_rep_party_tax_name => p_tax_registration_rec.rep_party_tax_name,
6895 p_default_registration_flag => p_tax_registration_rec.default_registration_flag,
6896 p_bank_account_num => NULL,
6897 p_record_type_code => NULL,
6898 p_legal_location_id => l_location_id,
6899 p_tax_authority_id => l_tax_authority_party_id,
6900 p_rep_tax_authority_id => NULL,
6901 p_coll_tax_authority_id => NULL,
6902 p_registration_type_code => p_tax_registration_rec.registration_type_code,
6903 p_registration_number => p_tax_registration_rec.registration_number,
6904 p_party_tax_profile_id => p_tax_registration_rec.tax_profile_id,
6905 p_legal_registration_id => NULL,
6906 p_bank_id => NULL,
6907 p_bank_branch_id => NULL,
6908 p_account_site_id => NULL,
6909 p_attribute14 => NULL,
6910 p_attribute15 => NULL,
6911 p_attribute_category => NULL,
6912 p_program_login_id => NULL,
6913 p_account_id => NULL,
6914 p_tax_classification_code => NULL,
6915 p_attribute7 => NULL,
6916 p_attribute8 => NULL,
6917 p_attribute9 => NULL,
6918 p_attribute10 => NULL,
6919 p_attribute11 => NULL,
6920 p_attribute12 => NULL,
6921 p_attribute13 => NULL,
6922 x_return_status => l_creation_status);
6923
6924 x_return_status := l_creation_status;
6925 x_msg_count := l_msg_count;
6926 x_msg_data := l_msg_data;
6927
6928 ELSE
6929 x_return_status := l_return_status;
6930 x_msg_count := l_msg_count;
6931 x_msg_data := l_msg_data;
6932 END IF;
6933
6934 IF x_return_status = fnd_api.g_ret_sts_error THEN
6935 IF (insert_rejections(p_batch_id,
6936 l_request_id,
6937 'POS_PARTY_TAX_REG_INT',
6938 p_tax_registration_rec.registration_type_code,
6939 'POS_INVALID_TAX_REG_UPD',
6940 g_user_id,
6941 g_login_id,
6942 ' UPDATE_TAX_REGISTRATION ') <> TRUE) THEN
6943
6944 IF (g_level_procedure >= g_current_runtime_level) THEN
6945 fnd_msg_pub.count_and_get(p_count => l_msg_count,
6946 p_data => l_msg_data);
6947 fnd_log.string(g_level_procedure,
6948 g_module_name || 'UPDATE_TAX_REGISTRATION',
6949 'Msg: ' || l_msg_data);
6950 END IF;
6951 END IF;
6952 fnd_file.put_line(fnd_file.log,
6953 ' Tax Registration validation/updation failed for: ' ||
6954 ' tax_reg_interface_id: ' ||
6955 p_tax_registration_rec.tax_reg_interface_id);
6956 END IF;
6957
6958 EXCEPTION
6959 WHEN OTHERS THEN
6960 x_return_status := fnd_api.g_ret_sts_error;
6961 fnd_msg_pub.count_and_get(p_count => x_msg_count,
6962 p_data => x_msg_data);
6963 fnd_file.put_line(fnd_file.log,
6964 ' Inside update_tax_registration EXCEPTION ' ||
6965 ' Message: ' || SQLCODE || ' ' || SQLERRM);
6966 END update_tax_registration;
6967
6968 /* FISCAL CLASSIFICATION */
6969
6970 PROCEDURE validate_fiscal_classification
6971 (
6972 p_batch_id IN NUMBER,
6973 p_fiscal_class_rec IN pos_fiscal_class_int%ROWTYPE,
6974 x_return_status OUT NOCOPY VARCHAR2,
6975 x_msg_count OUT NOCOPY NUMBER,
6976 x_msg_data OUT NOCOPY VARCHAR2,
6977 x_valid OUT NOCOPY VARCHAR2,
6978 x_classification_type OUT NOCOPY VARCHAR2,
6979 x_classification_code OUT NOCOPY VARCHAR2
6980 ) IS
6981
6982 l_classification_code VARCHAR2(50);
6983 l_classification_type VARCHAR2(50);
6984
6985 l_request_id NUMBER := fnd_global.conc_request_id;
6986
6987 l_msg_count NUMBER;
6988 l_msg_data VARCHAR2(2000);
6989 l_api_name CONSTANT VARCHAR2(50) := 'VALIDATE_VENDOR_PRODS_SERVICES';
6990 BEGIN
6991 fnd_file.put_line(fnd_file.log,
6992 ' Inside validate_fiscal_classification');
6993 -- Initialize API return status to success
6994 x_return_status := fnd_api.g_ret_sts_success;
6995
6996 x_valid := 'Y';
6997
6998 -- Validate the Fiscal Classification Type using the following query
6999 BEGIN
7000 SELECT owner_id_char
7001 INTO l_classification_type
7002 FROM zx_fc_types_vl
7003 WHERE classification_type_categ_code = 'PARTY_FISCAL_CLASS'
7004 AND SYSDATE BETWEEN nvl(effective_from, SYSDATE) AND
7005 nvl(effective_to, SYSDATE)
7006 AND classification_type_code =
7007 p_fiscal_class_rec.classification_type_code_name;
7008
7009 x_classification_type := l_classification_type;
7010
7011 EXCEPTION
7012 WHEN OTHERS THEN
7013 x_valid := 'N';
7014 x_return_status := fnd_api.g_ret_sts_error;
7015 x_msg_data := 'POS_INVALID_FISCAL_CLASS_TYPE';
7016 IF (insert_rejections(p_batch_id,
7017 l_request_id,
7018 'POS_FISCAL_CLASS_INT',
7019 p_fiscal_class_rec.classification_type_code_name,
7020 'POS_INVALID_FISCAL_CLASS_TYPE',
7021 g_user_id,
7022 g_login_id,
7023 ' Validate_fiscal_classification ') <> TRUE) THEN
7024
7025 IF (g_level_procedure >= g_current_runtime_level) THEN
7026 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7027 p_data => l_msg_data);
7028 fnd_log.string(g_level_procedure,
7029 g_module_name || l_api_name,
7030 'Parameters: ' ||
7031 p_fiscal_class_rec.classification_type_code_name ||
7032 ' Acct Validation Msg: ' || l_msg_data);
7033 END IF;
7034 END IF;
7035 fnd_file.put_line(fnd_file.log,
7036 ' Invalid Fiscal Classification Type for: ' ||
7037 ' p_fiscal_class_rec.classification_type_code_name: ' ||
7038 p_fiscal_class_rec.classification_type_code_name);
7039 RETURN;
7040 END;
7041
7042 -- Validate the Fiscal Classification Code using the following query
7043 BEGIN
7044 SELECT class_code
7045 INTO l_classification_code
7046 FROM hz_class_code_denorm
7047 WHERE SYSDATE BETWEEN nvl(start_date_active, SYSDATE) AND
7048 nvl(end_date_active, SYSDATE)
7049 AND LANGUAGE = userenv('LANG')
7050 AND class_code_meaning = p_fiscal_class_rec.class_code_name
7051 AND class_category = l_classification_type;
7052
7053 x_classification_code := l_classification_code;
7054
7055 EXCEPTION
7056 WHEN OTHERS THEN
7057 x_valid := 'N';
7058 x_return_status := fnd_api.g_ret_sts_error;
7059 x_msg_data := 'POS_INVALID_FISCAL_CLASS_NAME';
7060 IF (insert_rejections(p_batch_id,
7061 l_request_id,
7062 'POS_FISCAL_CLASS_INT',
7063 p_fiscal_class_rec.classification_type_code_name,
7064 'POS_INVALID_FISCAL_CLASS_NAME',
7065 g_user_id,
7066 g_login_id,
7067 ' Validate_fiscal_classification ') <> TRUE) THEN
7068
7069 IF (g_level_procedure >= g_current_runtime_level) THEN
7070 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7071 p_data => l_msg_data);
7072 fnd_log.string(g_level_procedure,
7073 g_module_name || l_api_name,
7074 'Parameters: ' ||
7075 p_fiscal_class_rec.classification_type_code_name ||
7076 ' Acct Validation Msg: ' || l_msg_data);
7077 END IF;
7078 END IF;
7079 fnd_file.put_line(fnd_file.log,
7080 ' Invalid Fiscal Classification Code for: ' ||
7081 ' p_fiscal_class_rec.classification_type_code_name: ' ||
7082 p_fiscal_class_rec.classification_type_code_name);
7083 RETURN;
7084 END;
7085 EXCEPTION
7086 WHEN OTHERS THEN
7087 x_return_status := fnd_api.g_ret_sts_error;
7088 fnd_msg_pub.count_and_get(p_count => x_msg_count,
7089 p_data => x_msg_data);
7090 fnd_file.put_line(fnd_file.log,
7091 ' Inside validate_fiscal_classification EXCEPTION ' ||
7092 ' Message: ' || SQLCODE || ' ' || SQLERRM);
7093 END validate_fiscal_classification;
7094
7095 PROCEDURE create_fiscal_classification
7096 (
7097 p_batch_id IN NUMBER,
7098 p_fiscal_class_rec IN pos_fiscal_class_int%ROWTYPE,
7099 x_return_status OUT NOCOPY VARCHAR2,
7100 x_msg_count OUT NOCOPY NUMBER,
7101 x_msg_data OUT NOCOPY VARCHAR2
7102 ) IS
7103 l_valid VARCHAR2(100);
7104 l_classification_type VARCHAR2(100);
7105 l_classification_code VARCHAR2(100);
7106 l_return_status VARCHAR2(10);
7107 l_msg_count NUMBER;
7108 l_msg_data VARCHAR2(1000);
7109 l_code_assignment_id NUMBER;
7110 BEGIN
7111 fnd_file.put_line(fnd_file.log, ' Inside create_fiscal_classification');
7112
7113 x_return_status := fnd_api.g_ret_sts_success;
7114
7115 validate_fiscal_classification(p_batch_id => p_batch_id,
7116 p_fiscal_class_rec => p_fiscal_class_rec,
7117 x_return_status => l_return_status,
7118 x_msg_count => l_msg_count,
7119 x_msg_data => l_msg_data,
7120 x_valid => l_valid,
7121 x_classification_type => l_classification_type,
7122 x_classification_code => l_classification_code);
7123
7124 fnd_file.put_line(fnd_file.log,
7125 'validate_fiscal_classification l_valid: ' || l_valid ||
7126 'l_return_status' || l_return_status);
7127
7128 IF (l_valid = 'Y') THEN
7129
7130 hz_code_assignments_pkg.insert_row(x_code_assignment_id => l_code_assignment_id,
7131 x_owner_table_name => 'ZX_PARTY_TAX_PROFILE',
7132 x_owner_table_id => p_fiscal_class_rec.tax_profile_id,
7133 x_owner_table_key_1 => NULL,
7134 x_owner_table_key_2 => NULL,
7135 x_owner_table_key_3 => NULL,
7136 x_owner_table_key_4 => NULL,
7137 x_owner_table_key_5 => NULL,
7138 x_class_category => l_classification_type,
7139 x_class_code => l_classification_code,
7140 x_primary_flag => 'N',
7141 x_content_source_type => NULL,
7142 x_start_date_active => p_fiscal_class_rec.effective_from,
7143 x_end_date_active => p_fiscal_class_rec.effective_to,
7144 x_status => NULL,
7145 x_object_version_number => NULL,
7146 x_created_by_module => NULL,
7147 x_rank => NULL,
7148 x_application_id => NULL,
7149 x_actual_content_source => NULL);
7150
7151 -- The HZ code is so designed that if the status is passed as NULL
7152 -- then it is set as 'A' and the VO that shows the data for Fiscal
7153 -- Classifications on the Supplier Profile page ignores these records
7154 -- So updating the status to NULL
7155 UPDATE hz_code_assignments
7156 SET status = NULL
7157 WHERE code_assignment_id = l_code_assignment_id;
7158
7159 ELSE
7160 x_return_status := l_return_status;
7161 x_msg_data := l_msg_data;
7162 x_msg_count := l_msg_count;
7163 END IF;
7164
7165 IF x_return_status = fnd_api.g_ret_sts_error THEN
7166 -- Read the Error buffer returned from the API
7167 -- Add the error buffer message to supplier rejections
7168 -- table
7169 /*IF (insert_rejections(p_batch_id,
7170 l_request_id,
7171 'POS_FISCAL_CLASS_INT',
7172 p_tax_registration_rec.registration_type_code,
7173 'AP_INVALID_TAX_REG_INS',
7174 g_user_id,
7175 g_login_id,
7176 ' Create_Tax_Registration ') <> TRUE) THEN
7177
7178 IF (g_level_procedure >= g_current_runtime_level) THEN
7179 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7180 p_data => l_msg_data);
7181 fnd_log.string(g_level_procedure,
7182 g_module_name || 'Create_Tax_Registration',
7183 'Msg: ' || l_msg_data);
7184 END IF;
7185 END IF;*/
7186 fnd_file.put_line(fnd_file.log,
7187 ' Fiscal Classification validation/creation failed for: ' ||
7188 ' fiscal_class_interface_id: ' ||
7189 p_fiscal_class_rec.fiscal_class_interface_id);
7190 END IF;
7191 EXCEPTION
7192 WHEN OTHERS THEN
7193 x_return_status := fnd_api.g_ret_sts_error;
7194 fnd_msg_pub.count_and_get(p_count => x_msg_count,
7195 p_data => x_msg_data);
7196 fnd_file.put_line(fnd_file.log,
7197 ' Inside create_fiscal_classification EXCEPTION ' ||
7198 ' Message: ' || SQLCODE || ' ' || SQLERRM);
7199 END create_fiscal_classification;
7200
7201 PROCEDURE update_fiscal_classification
7202 (
7203 p_batch_id IN NUMBER,
7204 p_fiscal_class_rec IN pos_fiscal_class_int%ROWTYPE,
7205 x_return_status OUT NOCOPY VARCHAR2,
7206 x_msg_count OUT NOCOPY NUMBER,
7207 x_msg_data OUT NOCOPY VARCHAR2
7208 ) IS
7209 l_valid VARCHAR2(100);
7210 l_classification_type VARCHAR2(100);
7211 l_classification_code VARCHAR2(100);
7212 l_return_status VARCHAR2(10);
7213 l_msg_count NUMBER;
7214 l_msg_data VARCHAR2(1000);
7215 l_code_assignment_id NUMBER;
7216 l_rowid VARCHAR2(100);
7217 BEGIN
7218 fnd_file.put_line(fnd_file.log, ' Inside update_fiscal_classification');
7219 -- Initialize API return status to success
7220 x_return_status := fnd_api.g_ret_sts_success;
7221
7222 validate_fiscal_classification(p_batch_id => p_batch_id,
7223 p_fiscal_class_rec => p_fiscal_class_rec,
7224 x_return_status => l_return_status,
7225 x_msg_count => l_msg_count,
7226 x_msg_data => l_msg_data,
7227 x_valid => l_valid,
7228 x_classification_type => l_classification_type,
7229 x_classification_code => l_classification_code);
7230
7231 IF (l_valid = 'Y') THEN
7232 BEGIN
7233 SELECT code_assignment_id,
7234 ROWID
7235 INTO l_code_assignment_id,
7236 l_rowid
7237 FROM hz_code_assignments
7238 WHERE owner_table_name = 'ZX_PARTY_TAX_PROFILE'
7239 AND owner_table_id = p_fiscal_class_rec.tax_profile_id
7240 AND class_category = l_classification_type;
7241
7242 EXCEPTION
7243 WHEN no_data_found THEN
7244 x_return_status := fnd_api.g_ret_sts_error;
7245 x_msg_data := 'POS_INVALID_FISCAL_CLASS';
7246 RETURN;
7247 END;
7248
7249 hz_code_assignments_pkg.update_row(x_rowid => l_rowid,
7250 x_code_assignment_id => l_code_assignment_id,
7251 x_owner_table_name => 'ZX_PARTY_TAX_PROFILE',
7252 x_owner_table_id => p_fiscal_class_rec.tax_profile_id,
7253 x_owner_table_key_1 => NULL,
7254 x_owner_table_key_2 => NULL,
7255 x_owner_table_key_3 => NULL,
7256 x_owner_table_key_4 => NULL,
7257 x_owner_table_key_5 => NULL,
7258 x_class_category => l_classification_type,
7259 x_class_code => l_classification_code,
7260 x_primary_flag => 'N',
7261 x_content_source_type => NULL,
7262 x_start_date_active => p_fiscal_class_rec.effective_from,
7263 x_end_date_active => p_fiscal_class_rec.effective_to,
7264 x_status => NULL,
7265 x_object_version_number => NULL,
7266 x_created_by_module => NULL,
7267 x_rank => NULL,
7268 x_application_id => NULL,
7269 x_actual_content_source => NULL);
7270
7271 -- The HZ code is so designed that if the status is passed as NULL
7272 -- then it is set as 'A' and the VO that shows the data for Fiscal
7273 -- Classifications on the Supplier Profile page ignores these records
7274 -- So updating the status to NULL
7275 UPDATE hz_code_assignments
7276 SET status = NULL
7277 WHERE code_assignment_id = l_code_assignment_id;
7278
7279 ELSE
7280 x_return_status := l_return_status;
7281 x_msg_data := l_msg_data;
7282 x_msg_count := l_msg_count;
7283 END IF;
7284
7285 IF x_return_status = fnd_api.g_ret_sts_error THEN
7286 -- Read the Error buffer returned from the API
7287 -- Add the error buffer message to supplier rejections
7288 -- table
7289 /*IF (insert_rejections(p_batch_id,
7290 l_request_id,
7291 'POS_FISCAL_CLASS_INT',
7292 p_tax_registration_rec.registration_type_code,
7293 'AP_INVALID_TAX_REG_INS',
7294 g_user_id,
7295 g_login_id,
7296 ' Create_Tax_Registration ') <> TRUE) THEN
7297
7298 IF (g_level_procedure >= g_current_runtime_level) THEN
7299 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7300 p_data => l_msg_data);
7301 fnd_log.string(g_level_procedure,
7302 g_module_name || 'Create_Tax_Registration',
7303 'Msg: ' || l_msg_data);
7304 END IF;
7305 END IF;*/
7306 fnd_file.put_line(fnd_file.log,
7307 ' Fiscal Classification validation/updation failed for: ' ||
7308 ' fiscal_class_interface_id: ' ||
7309 p_fiscal_class_rec.fiscal_class_interface_id);
7310 END IF;
7311
7312 EXCEPTION
7313 WHEN OTHERS THEN
7314 x_return_status := fnd_api.g_ret_sts_error;
7315 fnd_msg_pub.count_and_get(p_count => x_msg_count,
7316 p_data => x_msg_data);
7317 fnd_file.put_line(fnd_file.log,
7318 ' Inside update_fiscal_classification EXCEPTION ' ||
7319 ' Message: ' || SQLCODE || ' ' || SQLERRM);
7320 END update_fiscal_classification;
7321
7322 PROCEDURE import_vendor_tax_dtls
7323 (
7324 p_batch_id IN NUMBER,
7325 x_return_status OUT NOCOPY VARCHAR2,
7326 x_msg_count OUT NOCOPY NUMBER,
7327 x_msg_data OUT NOCOPY VARCHAR2
7328 ) AS
7329 l_request_id NUMBER := fnd_global.conc_request_id;
7330 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDOR_TAX_DTLS';
7331 l_effective_from_date DATE;
7332
7333 l_msg_count NUMBER;
7334 l_msg_data VARCHAR2(2000);
7335
7336 CURSOR tax_profile_cur IS
7337 SELECT *
7338 FROM pos_party_tax_profile_int supp
7339 WHERE batch_id = p_batch_id
7340 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
7341 AND NOT EXISTS
7342 (SELECT 1
7343 FROM hz_imp_parties_int party
7344 WHERE batch_id = p_batch_id
7345 AND supp.batch_id = party.batch_id
7346 AND supp.source_system = party.party_orig_system
7347 AND supp.source_system_reference =
7348 party.party_orig_system_reference
7349 AND party.interface_status = 'R');
7350
7351 CURSOR tax_reg_cur IS
7352 SELECT *
7353 FROM pos_party_tax_reg_int supp
7354 WHERE batch_id = p_batch_id
7355 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
7356 AND NOT EXISTS
7357 (SELECT 1
7358 FROM hz_imp_parties_int party
7359 WHERE batch_id = p_batch_id
7360 AND supp.batch_id = party.batch_id
7361 AND supp.source_system = party.party_orig_system
7362 AND supp.source_system_reference =
7363 party.party_orig_system_reference
7364 AND party.interface_status = 'R');
7365
7366 CURSOR fiscal_class_cur IS
7367 SELECT *
7368 FROM pos_fiscal_class_int supp
7369 WHERE batch_id = p_batch_id
7370 AND nvl(status, 'ACTIVE') NOT IN ('PROCESSED', 'REMOVED')
7371 AND NOT EXISTS
7372 (SELECT 1
7373 FROM hz_imp_parties_int party
7374 WHERE batch_id = p_batch_id
7375 AND supp.batch_id = party.batch_id
7376 AND supp.source_system = party.party_orig_system
7377 AND supp.source_system_reference =
7378 party.party_orig_system_reference
7379 AND party.interface_status = 'R');
7380
7381 l_party_id NUMBER;
7382 l_tax_profile_id NUMBER;
7383 l_tax_reg_id NUMBER;
7384 l_party_tax_profile_id NUMBER;
7385 l_classification_type VARCHAR2(50);
7386
7387 TYPE l_tax_profile_rec_tab_typ IS TABLE OF pos_party_tax_profile_int%ROWTYPE;
7388 l_tax_profile_rec_tab l_tax_profile_rec_tab_typ;
7389
7390 TYPE l_tax_reg_rec_tab_typ IS TABLE OF pos_party_tax_reg_int%ROWTYPE;
7391 l_tax_reg_rec_tab l_tax_reg_rec_tab_typ;
7392
7393 TYPE l_fiscal_class_rec_tab_typ IS TABLE OF pos_fiscal_class_int%ROWTYPE;
7394 l_fiscal_class_rec_tab l_fiscal_class_rec_tab_typ;
7395
7396 BEGIN
7397 x_return_status := fnd_api.g_ret_sts_success;
7398
7399 fnd_file.put_line(fnd_file.log,
7400 ' Message: Inside PROCEDURE IMPORT_VENDOR_TAX_DTLS' ||
7401 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
7402 ' request_id: ' || l_request_id);
7403
7404 -- This update statement resets the unprocessed rows so
7405 -- that they get picked in the current run.
7406 UPDATE pos_party_tax_profile_int api
7407 SET request_id = NULL
7408 WHERE request_id IS NOT NULL
7409 AND batch_id = p_batch_id
7410 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
7411 AND EXISTS (SELECT 'Request Completed'
7412 FROM fnd_concurrent_requests fcr
7413 WHERE fcr.request_id = api.request_id
7414 AND fcr.phase_code = 'C');
7415
7416 UPDATE pos_party_tax_reg_int api
7417 SET request_id = NULL
7418 WHERE request_id IS NOT NULL
7419 AND batch_id = p_batch_id
7420 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
7421 AND EXISTS (SELECT 'Request Completed'
7422 FROM fnd_concurrent_requests fcr
7423 WHERE fcr.request_id = api.request_id
7424 AND fcr.phase_code = 'C');
7425
7426 UPDATE pos_fiscal_class_int api
7427 SET request_id = NULL
7428 WHERE request_id IS NOT NULL
7429 AND batch_id = p_batch_id
7430 AND nvl(status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
7431 AND EXISTS (SELECT 'Request Completed'
7432 FROM fnd_concurrent_requests fcr
7433 WHERE fcr.request_id = api.request_id
7434 AND fcr.phase_code = 'C');
7435
7436 -- Updating Interface Record with request id
7437
7438 UPDATE pos_party_tax_profile_int
7439 SET request_id = l_request_id
7440 WHERE request_id IS NULL
7441 AND batch_id = p_batch_id
7442 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
7443
7444 UPDATE pos_party_tax_reg_int
7445 SET request_id = l_request_id
7446 WHERE request_id IS NULL
7447 AND batch_id = p_batch_id
7448 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
7449
7450 UPDATE pos_fiscal_class_int
7451 SET request_id = l_request_id
7452 WHERE request_id IS NULL
7453 AND batch_id = p_batch_id
7454 AND nvl(status, 'ACTIVE') <> 'PROCESSED';
7455
7456 UPDATE pos_party_tax_profile_int supp
7457 SET status = 'REMOVED',
7458 request_id = l_request_id
7459 WHERE batch_id = p_batch_id
7460 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
7461 AND EXISTS (SELECT 1
7462 FROM hz_imp_parties_int party
7463 WHERE batch_id = p_batch_id
7464 AND supp.batch_id = party.batch_id
7465 AND supp.source_system = party.party_orig_system
7466 AND supp.source_system_reference =
7467 party.party_orig_system_reference
7468 AND party.interface_status = 'R');
7469
7470 fnd_file.put_line(fnd_file.log,
7471 ' Message: Inside PROCEDURE IMPORT_VENDOR_TAX_DTLS' ||
7472 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
7473 ' records from table pos_party_tax_profile_int. Reason interface_status in hz_imp_parties_int = R');
7474
7475 INSERT INTO pos_supplier_int_rejections
7476 (SELECT p_batch_id,
7477 l_request_id,
7478 'POS_PRODUCT_SERVICE_INT',
7479 tax_profile_interface_id,
7480 'POS_INVALID_PARTY_ORIG_SYSTEM',
7481 g_user_id,
7482 SYSDATE,
7483 g_login_id,
7484 g_user_id,
7485 SYSDATE
7486 FROM pos_party_tax_profile_int
7487 WHERE status = 'REMOVED'
7488 AND request_id = l_request_id
7489 AND batch_id = p_batch_id);
7490
7491 UPDATE pos_party_tax_reg_int supp
7492 SET status = 'REMOVED',
7493 request_id = l_request_id
7494 WHERE batch_id = p_batch_id
7495 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
7496 AND EXISTS (SELECT 1
7497 FROM hz_imp_parties_int party
7498 WHERE batch_id = p_batch_id
7499 AND supp.batch_id = party.batch_id
7500 AND supp.source_system = party.party_orig_system
7501 AND supp.source_system_reference =
7502 party.party_orig_system_reference
7503 AND party.interface_status = 'R');
7504
7505 fnd_file.put_line(fnd_file.log,
7506 ' Message: Inside PROCEDURE IMPORT_VENDOR_TAX_DTLS' ||
7507 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
7508 ' records from table pos_party_tax_reg_int. Reason interface_status in hz_imp_parties_int = R');
7509
7510 INSERT INTO pos_supplier_int_rejections
7511 (SELECT p_batch_id,
7512 l_request_id,
7513 'POS_PRODUCT_SERVICE_INT',
7514 tax_reg_interface_id,
7515 'POS_INVALID_PARTY_ORIG_SYSTEM',
7516 g_user_id,
7517 SYSDATE,
7518 g_login_id,
7519 g_user_id,
7520 SYSDATE
7521 FROM pos_party_tax_reg_int
7522 WHERE status = 'REMOVED'
7523 AND request_id = l_request_id
7524 AND batch_id = p_batch_id);
7525
7526 UPDATE pos_fiscal_class_int supp
7527 SET status = 'REMOVED',
7528 request_id = l_request_id
7529 WHERE batch_id = p_batch_id
7530 AND nvl(status, 'ACTIVE') <> 'PROCESSED'
7531 AND EXISTS (SELECT 1
7532 FROM hz_imp_parties_int party
7533 WHERE batch_id = p_batch_id
7534 AND supp.batch_id = party.batch_id
7535 AND supp.source_system = party.party_orig_system
7536 AND supp.source_system_reference =
7537 party.party_orig_system_reference
7538 AND party.interface_status = 'R');
7539
7540 fnd_file.put_line(fnd_file.log,
7541 ' Message: Inside PROCEDURE IMPORT_VENDOR_TAX_DTLS' ||
7542 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
7543 ' records from table pos_fiscal_class_int. Reason interface_status in hz_imp_parties_int = R');
7544
7545 INSERT INTO pos_supplier_int_rejections
7546 (SELECT p_batch_id,
7547 l_request_id,
7548 'POS_PRODUCT_SERVICE_INT',
7549 fiscal_class_interface_id,
7550 'POS_INVALID_PARTY_ORIG_SYSTEM',
7551 g_user_id,
7552 SYSDATE,
7553 g_login_id,
7554 g_user_id,
7555 SYSDATE
7556 FROM pos_fiscal_class_int
7557 WHERE status = 'REMOVED'
7558 AND request_id = l_request_id
7559 AND batch_id = p_batch_id);
7560
7561 -- Process Tax Profile
7562 OPEN tax_profile_cur;
7563 FETCH tax_profile_cur BULK COLLECT
7564 INTO l_tax_profile_rec_tab;
7565 CLOSE tax_profile_cur;
7566
7567 FOR cntr IN 1 .. l_tax_profile_rec_tab.count LOOP
7568 IF (l_tax_profile_rec_tab(cntr).party_id IS NULL) THEN
7569 l_party_id := get_party_id(l_tax_profile_rec_tab(cntr).source_system,
7570 l_tax_profile_rec_tab(cntr)
7571 .source_system_reference);
7572
7573 l_tax_profile_rec_tab(cntr).party_id := l_party_id;
7574 END IF;
7575
7576 IF (l_tax_profile_rec_tab(cntr).insert_update_flag IS NULL) THEN
7577 BEGIN
7578 SELECT 'U'
7579 INTO l_tax_profile_rec_tab(cntr).insert_update_flag
7580 FROM zx_party_tax_profile
7581 WHERE party_id = l_tax_profile_rec_tab(cntr).party_id
7582 AND party_type_code = 'THIRD_PARTY';
7583
7584 EXCEPTION
7585 WHEN no_data_found THEN
7586 l_tax_profile_rec_tab(cntr).insert_update_flag := 'I';
7587 END;
7588 END IF;
7589
7590 fnd_file.put_line(fnd_file.log,
7591 ' l_tax_profile_rec_tab(cntr).insert_update_flag: ' || l_tax_profile_rec_tab(cntr)
7592 .insert_update_flag);
7593
7594 create_tax_profile(p_batch_id => p_batch_id,
7595 p_tax_profile_rec => l_tax_profile_rec_tab(cntr),
7596 x_return_status => x_return_status,
7597 x_msg_count => x_msg_count,
7598 x_msg_data => x_msg_data,
7599 x_tax_profile_id => l_tax_profile_id);
7600
7601 fnd_file.put_line(fnd_file.log,
7602 ' Message: Inside PROCEDURE import_vendor_tax_dtls' ||
7603 ' l_tax_profile_id: ' || l_tax_profile_id ||
7604 ' for tax_profile_interface_id: ' || l_tax_profile_rec_tab(cntr)
7605 .tax_profile_interface_id || ' x_return_status: ' ||
7606 x_return_status);
7607
7608 -- Tax Profile Id in the Tax Registrations Interface table
7609 UPDATE pos_party_tax_reg_int
7610 SET tax_profile_id = l_tax_profile_id
7611 WHERE tax_profile_interface_id = l_tax_profile_rec_tab(cntr)
7612 .tax_profile_interface_id
7613 AND batch_id = p_batch_id;
7614
7615 -- Tax Profile Id in the Fiscal Classifications Interface table
7616 UPDATE pos_fiscal_class_int
7617 SET tax_profile_id = l_tax_profile_id
7618 WHERE tax_profile_interface_id = l_tax_profile_rec_tab(cntr)
7619 .tax_profile_interface_id
7620 AND batch_id = p_batch_id;
7621
7622 IF (x_return_status = 'S') THEN
7623 UPDATE pos_party_tax_profile_int
7624 SET status = 'PROCESSED'
7625 WHERE tax_profile_interface_id = l_tax_profile_rec_tab(cntr)
7626 .tax_profile_interface_id
7627 AND batch_id = p_batch_id;
7628
7629 IF (l_tax_profile_rec_tab(cntr).insert_update_flag = 'I') THEN
7630 UPDATE pos_imp_batch_summary
7631 SET total_records_imported = total_records_imported + 1,
7632 total_inserts = total_inserts + 1,
7633 tax_dtls_inserted = tax_dtls_inserted + 1,
7634 tax_dtls_imported = tax_dtls_imported + 1
7635 WHERE batch_id = p_batch_id;
7636 ELSE
7637 UPDATE pos_imp_batch_summary
7638 SET total_records_imported = total_records_imported + 1,
7639 total_updates = total_updates + 1,
7640 tax_dtls_updated = tax_dtls_updated + 1,
7641 tax_dtls_imported = tax_dtls_imported + 1
7642 WHERE batch_id = p_batch_id;
7643 END IF;
7644
7645 ELSE
7646 UPDATE pos_party_tax_profile_int
7647 SET status = 'REJECTED'
7648 WHERE tax_profile_interface_id = l_tax_profile_rec_tab(cntr)
7649 .tax_profile_interface_id
7650 AND batch_id = p_batch_id;
7651
7652 x_return_status := fnd_api.g_ret_sts_error;
7653
7654 IF (insert_rejections(p_batch_id,
7655 l_request_id,
7656 'POS_PARTY_TAX_PROFILE_INT',
7657 l_tax_profile_rec_tab(cntr)
7658 .tax_profile_interface_id,
7659 'POS_TAX_PROFILE_CREATION',
7660 g_user_id,
7661 g_login_id,
7662 'import_vendor_tax_dtls') <> TRUE) THEN
7663
7664 IF (g_level_procedure >= g_current_runtime_level) THEN
7665 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7666 p_data => l_msg_data);
7667 fnd_log.string(g_level_procedure,
7668 g_module_name || l_api_name,
7669 'Parameters: ' || ' Vendor_Interface_Id: ' || l_tax_profile_rec_tab(cntr)
7670 .tax_profile_interface_id ||
7671 ' Tax Profile Creation Msg: ' || l_msg_data);
7672 END IF;
7673 END IF;
7674
7675 END IF;
7676 END LOOP;
7677
7678 -- Process Tax registration
7679 OPEN tax_reg_cur;
7680 FETCH tax_reg_cur BULK COLLECT
7681 INTO l_tax_reg_rec_tab;
7682 CLOSE tax_reg_cur;
7683
7684 FOR cntr IN 1 .. l_tax_reg_rec_tab.count LOOP
7685 IF (l_tax_reg_rec_tab(cntr).party_id IS NULL) THEN
7686 l_party_id := get_party_id(l_tax_reg_rec_tab(cntr).source_system,
7687 l_tax_reg_rec_tab(cntr)
7688 .source_system_reference);
7689
7690 l_tax_reg_rec_tab(cntr).party_id := l_party_id;
7691 ELSE
7692 l_party_id := l_tax_reg_rec_tab(cntr).party_id;
7693 END IF;
7694
7695 fnd_file.put_line(fnd_file.log,
7696 ' l_tax_reg_rec_tab(cntr).party_id : ' || l_tax_reg_rec_tab(cntr)
7697 .party_id);
7698
7699 IF (l_tax_reg_rec_tab(cntr).tax_profile_id IS NULL) THEN
7700 BEGIN
7701 SELECT party_tax_profile_id
7702 INTO l_tax_profile_id
7703 FROM zx_party_tax_profile
7704 WHERE party_id = l_party_id
7705 AND party_type_code = 'THIRD_PARTY';
7706
7707 l_tax_reg_rec_tab(cntr).tax_profile_id := l_tax_profile_id;
7708
7709 fnd_file.put_line(fnd_file.log,
7710 ' l_tax_reg_rec_tab(cntr).tax_profile_id : ' || l_tax_reg_rec_tab(cntr)
7711 .tax_profile_id);
7712
7713 EXCEPTION
7714 WHEN no_data_found THEN
7715 x_return_status := fnd_api.g_ret_sts_error;
7716 x_msg_data := 'POS_INVALID_TAX_PROFILE';
7717 fnd_file.put_line(fnd_file.log, ' POS_INVALID_TAX_PROFILE ');
7718
7719 GOTO continue_next_record;
7720 END;
7721 END IF;
7722
7723 IF (l_tax_reg_rec_tab(cntr).insert_update_flag IS NULL) THEN
7724 BEGIN
7725 -- get the registration id
7726 SELECT 'U'
7727 INTO l_tax_reg_rec_tab(cntr).insert_update_flag
7728 FROM zx_registrations
7729 WHERE party_tax_profile_id = l_tax_profile_id
7730 AND tax_regime_code = l_tax_reg_rec_tab(cntr).tax_regime_code
7731 AND SYSDATE BETWEEN effective_from AND
7732 nvl(effective_to, SYSDATE);
7733
7734 EXCEPTION
7735 WHEN no_data_found THEN
7736 l_tax_reg_rec_tab(cntr).insert_update_flag := 'I';
7737 END;
7738 END IF;
7739
7740 fnd_file.put_line(fnd_file.log,
7741 ' l_tax_reg_rec_tab(cntr).insert_update_flag: ' || l_tax_reg_rec_tab(cntr)
7742 .insert_update_flag);
7743
7744 IF (l_tax_reg_rec_tab(cntr).insert_update_flag = 'U') THEN
7745 BEGIN
7746 -- get the registration id
7747 SELECT registration_id,
7748 effective_from
7749 INTO l_tax_reg_id,
7750 l_effective_from_date
7751 FROM zx_registrations
7752 WHERE party_tax_profile_id = l_tax_profile_id
7753 AND tax_regime_code = l_tax_reg_rec_tab(cntr).tax_regime_code
7754 AND SYSDATE BETWEEN effective_from AND
7755 nvl(effective_to, SYSDATE);
7756
7757 EXCEPTION
7758 WHEN no_data_found THEN
7759 x_return_status := fnd_api.g_ret_sts_error;
7760 x_msg_data := 'POS_INVALID_TAX_REG';
7761
7762 GOTO continue_next_record;
7763 END;
7764
7765 -- Setting the default from date
7766 IF (l_tax_reg_rec_tab(cntr).effective_from IS NULL) THEN
7767 l_tax_reg_rec_tab(cntr).effective_from := l_effective_from_date;
7768 END IF;
7769
7770 update_tax_registration(p_batch_id => p_batch_id,
7771 p_registration_id => l_tax_reg_id,
7772 p_tax_registration_rec => l_tax_reg_rec_tab(cntr),
7773 x_return_status => x_return_status,
7774 x_msg_count => x_msg_count,
7775 x_msg_data => x_msg_data);
7776 IF (x_return_status = 'S') THEN
7777
7778 UPDATE pos_party_tax_reg_int
7779 SET status = 'PROCESSED'
7780 WHERE tax_reg_interface_id = l_tax_reg_rec_tab(cntr)
7781 .tax_reg_interface_id
7782 AND batch_id = p_batch_id;
7783
7784 UPDATE pos_imp_batch_summary
7785 SET total_records_imported = total_records_imported + 1,
7786 total_updates = total_updates + 1,
7787 tax_dtls_updated = tax_dtls_updated + 1,
7788 tax_dtls_imported = tax_dtls_imported + 1
7789 WHERE batch_id = p_batch_id;
7790 END IF;
7791 ELSE
7792 create_tax_registration(p_batch_id => p_batch_id,
7793 p_tax_registration_rec => l_tax_reg_rec_tab(cntr),
7794 x_return_status => x_return_status,
7795 x_msg_count => x_msg_count,
7796 x_msg_data => x_msg_data);
7797 fnd_file.put_line(fnd_file.log,
7798 ' create_tax_registration x_return_status: ' ||
7799 x_return_status);
7800
7801 IF (x_return_status = 'S') THEN
7802
7803 UPDATE pos_party_tax_reg_int
7804 SET status = 'PROCESSED'
7805 WHERE tax_reg_interface_id = l_tax_reg_rec_tab(cntr)
7806 .tax_reg_interface_id
7807 AND batch_id = p_batch_id;
7808
7809 UPDATE pos_imp_batch_summary
7810 SET total_records_imported = total_records_imported + 1,
7811 total_inserts = total_inserts + 1,
7812 tax_dtls_inserted = tax_dtls_inserted + 1,
7813 tax_dtls_imported = tax_dtls_imported + 1
7814 WHERE batch_id = p_batch_id;
7815 END IF;
7816 END IF;
7817
7818 IF (x_return_status <> 'S') THEN
7819
7820 UPDATE pos_party_tax_reg_int
7821 SET status = 'REJECTED'
7822 WHERE tax_reg_interface_id = l_tax_reg_rec_tab(cntr)
7823 .tax_reg_interface_id
7824 AND batch_id = p_batch_id;
7825
7826 x_return_status := fnd_api.g_ret_sts_error;
7827
7828 IF (insert_rejections(p_batch_id,
7829 l_request_id,
7830 'POS_PARTY_TAX_REG_INT',
7831 l_tax_reg_rec_tab(cntr).tax_reg_interface_id,
7832 'POS_TAX_REGISTRATION_CREATION',
7833 g_user_id,
7834 g_login_id,
7835 'import_vendor_tax_dtls') <> TRUE) THEN
7836
7837 IF (g_level_procedure >= g_current_runtime_level) THEN
7838 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7839 p_data => l_msg_data);
7840 fnd_log.string(g_level_procedure,
7841 g_module_name || l_api_name,
7842 'Parameters: ' || ' Vendor_Interface_Id: ' || l_tax_reg_rec_tab(cntr)
7843 .tax_reg_interface_id ||
7844 ' Tax Registration Creation Msg: ' || l_msg_data);
7845 END IF;
7846 END IF;
7847 END IF;
7848 <<continue_next_record>>
7849 NULL;
7850 END LOOP;
7851
7852 -- Process Fiscal Classification
7853 OPEN fiscal_class_cur;
7854 FETCH fiscal_class_cur BULK COLLECT
7855 INTO l_fiscal_class_rec_tab;
7856 CLOSE fiscal_class_cur;
7857
7858 FOR cntr IN 1 .. l_fiscal_class_rec_tab.count LOOP
7859 IF (l_fiscal_class_rec_tab(cntr).party_id IS NULL) THEN
7860 l_party_id := get_party_id(l_fiscal_class_rec_tab(cntr)
7861 .source_system,
7862 l_fiscal_class_rec_tab(cntr)
7863 .source_system_reference);
7864
7865 l_fiscal_class_rec_tab(cntr).party_id := l_party_id;
7866 ELSE
7867 l_party_id := l_fiscal_class_rec_tab(cntr).party_id;
7868 END IF;
7869
7870 IF (l_fiscal_class_rec_tab(cntr).tax_profile_id IS NULL) THEN
7871 BEGIN
7872 SELECT party_tax_profile_id
7873 INTO l_tax_profile_id
7874 FROM zx_party_tax_profile
7875 WHERE party_id = l_party_id
7876 AND party_type_code = 'THIRD_PARTY';
7877
7878 l_fiscal_class_rec_tab(cntr).tax_profile_id := l_tax_profile_id;
7879 EXCEPTION
7880 WHEN no_data_found THEN
7881 UPDATE pos_fiscal_class_int
7882 SET status = 'REJECTED'
7883 WHERE fiscal_class_interface_id = l_fiscal_class_rec_tab(cntr)
7884 .fiscal_class_interface_id
7885 AND batch_id = p_batch_id;
7886
7887 IF (insert_rejections(p_batch_id,
7888 l_request_id,
7889 'POS_FISCAL_CLASS_INT',
7890 l_fiscal_class_rec_tab(cntr)
7891 .fiscal_class_interface_id,
7892 'POS_INVALID_TAX_PROFILE',
7893 g_user_id,
7894 g_login_id,
7895 'import_vendor_tax_dtls') <> TRUE) THEN
7896
7897 IF (g_level_procedure >= g_current_runtime_level) THEN
7898 fnd_msg_pub.count_and_get(p_count => l_msg_count,
7899 p_data => l_msg_data);
7900 fnd_log.string(g_level_procedure,
7901 g_module_name || l_api_name,
7902 'Parameters: ' || ' Vendor_Interface_Id: ' || l_fiscal_class_rec_tab(cntr)
7903 .fiscal_class_interface_id ||
7904 ' Fiscal Classification Creation Msg: ' ||
7905 l_msg_data);
7906 END IF;
7907 END IF;
7908
7909 x_return_status := fnd_api.g_ret_sts_error;
7910 x_msg_data := 'POS_INVALID_TAX_PROFILE';
7911
7912 GOTO continue_next_fiscal_class;
7913 END;
7914 END IF;
7915
7916 IF (l_fiscal_class_rec_tab(cntr).insert_update_flag IS NULL) THEN
7917 BEGIN
7918
7919 SELECT owner_id_char
7920 INTO l_classification_type
7921 FROM zx_fc_types_vl
7922 WHERE classification_type_categ_code = 'PARTY_FISCAL_CLASS'
7923 AND SYSDATE BETWEEN nvl(effective_from, SYSDATE) AND
7924 nvl(effective_to, SYSDATE)
7925 AND classification_type_code = l_fiscal_class_rec_tab(cntr)
7926 .classification_type_code_name;
7927
7928 SELECT 'U'
7929 INTO l_fiscal_class_rec_tab(cntr).insert_update_flag
7930 FROM hz_code_assignments
7931 WHERE owner_table_name = 'ZX_PARTY_TAX_PROFILE'
7932 AND owner_table_id = l_fiscal_class_rec_tab(cntr)
7933 .tax_profile_id
7934 AND class_category = l_classification_type;
7935
7936 EXCEPTION
7937 WHEN OTHERS THEN
7938 l_fiscal_class_rec_tab(cntr).insert_update_flag := 'I';
7939 END;
7940 END IF;
7941
7942 fnd_file.put_line(fnd_file.log,
7943 ' l_fiscal_class_rec_tab(cntr).insert_update_flag: ' || l_fiscal_class_rec_tab(cntr)
7944 .insert_update_flag);
7945
7946 IF (l_fiscal_class_rec_tab(cntr).insert_update_flag = 'I') THEN
7947
7948 create_fiscal_classification(p_batch_id => p_batch_id,
7949 p_fiscal_class_rec => l_fiscal_class_rec_tab(cntr),
7950 x_return_status => x_return_status,
7951 x_msg_count => x_msg_count,
7952 x_msg_data => x_msg_data);
7953
7954 IF (x_return_status = 'S') THEN
7955 UPDATE pos_fiscal_class_int
7956 SET status = 'PROCESSED'
7957 WHERE fiscal_class_interface_id = l_fiscal_class_rec_tab(cntr)
7958 .fiscal_class_interface_id
7959 AND batch_id = p_batch_id;
7960
7961 UPDATE pos_imp_batch_summary
7962 SET total_records_imported = total_records_imported + 1,
7963 total_inserts = total_inserts + 1,
7964 tax_dtls_inserted = tax_dtls_inserted + 1,
7965 tax_dtls_imported = tax_dtls_imported + 1
7966 WHERE batch_id = p_batch_id;
7967 END IF;
7968 ELSE
7969 update_fiscal_classification(p_batch_id => p_batch_id,
7970 p_fiscal_class_rec => l_fiscal_class_rec_tab(cntr),
7971 x_return_status => x_return_status,
7972 x_msg_count => x_msg_count,
7973 x_msg_data => x_msg_data);
7974 IF (x_return_status = 'S') THEN
7975 UPDATE pos_fiscal_class_int
7976 SET status = 'PROCESSED'
7977 WHERE fiscal_class_interface_id = l_fiscal_class_rec_tab(cntr)
7978 .fiscal_class_interface_id
7979 AND batch_id = p_batch_id;
7980
7981 UPDATE pos_imp_batch_summary
7982 SET total_records_imported = total_records_imported + 1,
7983 total_updates = total_updates + 1,
7984 tax_dtls_updated = tax_dtls_updated + 1,
7985 tax_dtls_imported = tax_dtls_imported + 1
7986 WHERE batch_id = p_batch_id;
7987 END IF;
7988
7989 END IF;
7990
7991 IF (x_return_status <> 'S') THEN
7992 UPDATE pos_fiscal_class_int
7993 SET status = 'REJECTED'
7994 WHERE fiscal_class_interface_id = l_fiscal_class_rec_tab(cntr)
7995 .fiscal_class_interface_id
7996 AND batch_id = p_batch_id;
7997
7998 x_return_status := fnd_api.g_ret_sts_error;
7999
8000 IF (insert_rejections(p_batch_id,
8001 l_request_id,
8002 'POS_FISCAL_CLASS_INT',
8003 l_fiscal_class_rec_tab(cntr)
8004 .fiscal_class_interface_id,
8005 'POS_FISCAL_CLASS_CREATION',
8006 g_user_id,
8007 g_login_id,
8008 'import_vendor_tax_dtls') <> TRUE) THEN
8009
8010 IF (g_level_procedure >= g_current_runtime_level) THEN
8011 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8012 p_data => l_msg_data);
8013 fnd_log.string(g_level_procedure,
8014 g_module_name || l_api_name,
8015 'Parameters: ' || ' Vendor_Interface_Id: ' || l_fiscal_class_rec_tab(cntr)
8016 .fiscal_class_interface_id ||
8017 ' Fiscal Classification Creation Msg: ' ||
8018 l_msg_data);
8019 END IF;
8020 END IF;
8021 END IF;
8022 <<continue_next_fiscal_class>>
8023 NULL;
8024 END LOOP;
8025
8026 EXCEPTION
8027 WHEN OTHERS THEN
8028 x_return_status := fnd_api.g_ret_sts_unexp_error;
8029
8030 fnd_msg_pub.count_and_get(p_count => x_msg_count,
8031 p_data => x_msg_data);
8032 fnd_file.put_line(fnd_file.log,
8033 ' Inside import_vendor_tax_dtls EXCEPTION ' ||
8034 ' Message: ' || SQLCODE || ' ' || SQLERRM);
8035 END import_vendor_tax_dtls;
8036
8037 PROCEDURE import_vendor_bank_dtls
8038 (
8039 p_batch_id IN NUMBER,
8040 x_return_status OUT NOCOPY VARCHAR2,
8041 x_msg_count OUT NOCOPY NUMBER,
8042 x_msg_data OUT NOCOPY VARCHAR2
8043 ) IS
8044 CURSOR bank_account_dtls_cur IS
8045 SELECT *
8046 FROM pos_bank_account_det_int supp
8047 WHERE batch_id = p_batch_id
8048 AND nvl(interface_status, 'ACTIVE') NOT IN
8049 ('PROCESSED', 'REMOVED')
8050 AND NOT EXISTS
8051 (SELECT 1
8052 FROM hz_imp_parties_int party
8053 WHERE batch_id = p_batch_id
8054 AND supp.batch_id = party.batch_id
8055 AND supp.source_system = party.party_orig_system
8056 AND supp.source_system_reference =
8057 party.party_orig_system_reference
8058 AND party.interface_status = 'R');
8059
8060 CURSOR account_owners_cur IS
8061 SELECT *
8062 FROM pos_bank_accnt_owners_int supp
8063 WHERE batch_id = p_batch_id
8064 AND nvl(interface_status, 'ACTIVE') NOT IN
8065 ('PROCESSED', 'REMOVED')
8066 AND NOT EXISTS
8067 (SELECT 1
8068 FROM hz_imp_parties_int party
8069 WHERE batch_id = p_batch_id
8070 AND supp.batch_id = party.batch_id
8071 AND supp.source_system = party.party_orig_system
8072 AND supp.source_system_reference =
8073 party.party_orig_system_reference
8074 AND party.interface_status = 'R');
8075
8076 bank_account_dtls_rec bank_account_dtls_cur%ROWTYPE;
8077 account_owners_rec pos_bank_accnt_owners_int%ROWTYPE;
8078 l_party_id NUMBER;
8079
8080 l_ret_status VARCHAR2(40);
8081 l_msg_count NUMBER;
8082 l_msg_data VARCHAR2(2000);
8083
8084 ---Bug 11819545
8085 l_assign_id NUMBER;
8086 l_payee_context_rec IBY_DISBURSEMENT_SETUP_PUB.PayeeContext_rec_type;
8087 l_assign IBY_FNDCPT_SETUP_PUB.PmtInstrAssignment_rec_type;
8088 l_payment_function CONSTANT VARCHAR2(30) := 'PAYABLES_DISB';
8089 l_instrument_type CONSTANT VARCHAR2(30) := 'BANKACCOUNT';
8090
8091 l_supp_site_id NUMBER;
8092 l_org_id NUMBER;
8093 L_PARTY_SITE_STATUS VARCHAR2(1);
8094 ---Bug 11819545
8095
8096 l_bank_id NUMBER;
8097 l_branch_id NUMBER;
8098 l_account_id NUMBER;
8099 l_intermediary1_acct_id NUMBER;
8100 l_intermediary2_acct_id NUMBER;
8101 l_account_owner_id NUMBER;
8102 l_joint_account_owner_id NUMBER;
8103 l_obj_version NUMBER;
8104 l_party_site_id NUMBER;
8105 l_vendor_site_id NUMBER;
8106 l_org_type VARCHAR2(100);
8107
8108 l_bank_end_date DATE;
8109 l_branch_end_date DATE;
8110 l_account_start_date DATE;
8111 l_account_end_date DATE;
8112
8113 l_bank_rowid VARCHAR2(100);
8114 l_branch_rowid VARCHAR2(100);
8115
8116 l_check_bank_resp iby_fndcpt_common_pub.result_rec_type;
8117 l_check_branch_resp iby_fndcpt_common_pub.result_rec_type;
8118 l_check_account_resp iby_fndcpt_common_pub.result_rec_type;
8119
8120 l_create_bank_resp iby_fndcpt_common_pub.result_rec_type;
8121 l_create_branch_resp iby_fndcpt_common_pub.result_rec_type;
8122 l_create_account_resp iby_fndcpt_common_pub.result_rec_type;
8123 l_set_bank_end_date_resp iby_fndcpt_common_pub.result_rec_type;
8124 l_set_branch_end_date_resp iby_fndcpt_common_pub.result_rec_type;
8125 l_add_intermed_account1_resp iby_fndcpt_common_pub.result_rec_type;
8126
8127 l_add_account_owner_resp iby_fndcpt_common_pub.result_rec_type;
8128 l_set_end_date_resp iby_fndcpt_common_pub.result_rec_type;
8129 l_set_primary_flag_resp iby_fndcpt_common_pub.result_rec_type;
8130
8131 l_new_bank_rec iby_ext_bankacct_pub.extbank_rec_type;
8132 l_new_branch_rec iby_ext_bankacct_pub.extbankbranch_rec_type;
8133 l_new_account_rec iby_ext_bankacct_pub.extbankacct_rec_type;
8134 l_new_intermed_acct1_rec iby_ext_bankacct_pub.intermediaryacct_rec_type;
8135 l_new_intermed_acct2_rec iby_ext_bankacct_pub.intermediaryacct_rec_type;
8136
8137 l_association_level VARCHAR2(10);
8138
8139 l_request_id NUMBER := fnd_global.conc_request_id;
8140 l_api_name CONSTANT VARCHAR2(30) := 'IMPORT_VENDOR_BANK_DTLS';
8141 BEGIN
8142 x_return_status := fnd_api.g_ret_sts_success;
8143
8144 fnd_file.put_line(fnd_file.log,
8145 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8146 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
8147 ' request_id: ' || l_request_id);
8148
8149 -- This update statement resets the unprocessed rows so
8150 -- that they get picked in the current run.
8151 UPDATE pos_bank_account_det_int api
8152 SET request_id = NULL
8153 WHERE request_id IS NOT NULL
8154 AND batch_id = p_batch_id
8155 AND nvl(interface_status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
8156 AND EXISTS (SELECT 'Request Completed'
8157 FROM fnd_concurrent_requests fcr
8158 WHERE fcr.request_id = api.request_id
8159 AND fcr.phase_code = 'C');
8160
8161 UPDATE pos_bank_accnt_owners_int api
8162 SET request_id = NULL
8163 WHERE request_id IS NOT NULL
8164 AND batch_id = p_batch_id
8165 AND nvl(interface_status, 'ACTIVE') IN ('ACTIVE', 'REJECTED')
8166 AND EXISTS (SELECT 'Request Completed'
8167 FROM fnd_concurrent_requests fcr
8168 WHERE fcr.request_id = api.request_id
8169 AND fcr.phase_code = 'C');
8170
8171 -- Updating Interface Record with request id
8172
8173 UPDATE pos_bank_account_det_int
8174 SET request_id = l_request_id
8175 WHERE request_id IS NULL
8176 AND batch_id = p_batch_id
8177 AND nvl(interface_status, 'ACTIVE') <> 'PROCESSED';
8178
8179 UPDATE pos_bank_accnt_owners_int
8180 SET request_id = l_request_id
8181 WHERE request_id IS NULL
8182 AND batch_id = p_batch_id
8183 AND nvl(interface_status, 'ACTIVE') <> 'PROCESSED';
8184
8185 UPDATE pos_bank_account_det_int supp
8186 SET interface_status = 'REMOVED',
8187 request_id = l_request_id
8188 WHERE batch_id = p_batch_id
8189 AND nvl(interface_status, 'ACTIVE') <> 'PROCESSED'
8190 AND EXISTS (SELECT 1
8191 FROM hz_imp_parties_int party
8192 WHERE batch_id = p_batch_id
8193 AND supp.batch_id = party.batch_id
8194 AND supp.source_system = party.party_orig_system
8195 AND supp.source_system_reference =
8196 party.party_orig_system_reference
8197 AND party.interface_status = 'R');
8198
8199 fnd_file.put_line(fnd_file.log,
8200 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8201 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
8202 ' records from table pos_bank_account_det_int. Reason interface_status in hz_imp_parties_int = R');
8203
8204 INSERT INTO pos_supplier_int_rejections
8205 (SELECT p_batch_id,
8206 l_request_id,
8207 'POS_BANK_ACCOUNT_DET_INT',
8208 bank_account_interface_id,
8209 'POS_INVALID_PARTY_ORIG_SYSTEM',
8210 g_user_id,
8211 SYSDATE,
8212 g_login_id,
8213 g_user_id,
8214 SYSDATE
8215 FROM pos_bank_account_det_int
8216 WHERE interface_status = 'REMOVED'
8217 AND request_id = l_request_id
8218 AND batch_id = p_batch_id);
8219
8220 UPDATE pos_bank_accnt_owners_int supp
8221 SET interface_status = 'REMOVED',
8222 request_id = l_request_id
8223 WHERE batch_id = p_batch_id
8224 AND nvl(interface_status, 'ACTIVE') <> 'PROCESSED'
8225 AND EXISTS (SELECT 1
8226 FROM hz_imp_parties_int party
8227 WHERE batch_id = p_batch_id
8228 AND supp.batch_id = party.batch_id
8229 AND supp.source_system = party.party_orig_system
8230 AND supp.source_system_reference =
8231 party.party_orig_system_reference
8232 AND party.interface_status = 'R');
8233
8234 fnd_file.put_line(fnd_file.log,
8235 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8236 ' Not imported(marked REMOVED) : ' || SQL%ROWCOUNT ||
8237 ' records from table pos_bank_accnt_owners_int. Reason interface_status in hz_imp_parties_int = R');
8238
8239 INSERT INTO pos_supplier_int_rejections
8240 (SELECT p_batch_id,
8241 l_request_id,
8242 'POS_BANK_ACCNT_OWNERS_INT',
8243 bank_acct_owner_interface_id,
8244 'POS_INVALID_PARTY_ORIG_SYSTEM',
8245 g_user_id,
8246 SYSDATE,
8247 g_login_id,
8248 g_user_id,
8249 SYSDATE
8250 FROM pos_bank_accnt_owners_int
8251 WHERE interface_status = 'REMOVED'
8252 AND request_id = l_request_id
8253 AND batch_id = p_batch_id);
8254
8255 OPEN bank_account_dtls_cur;
8256 LOOP
8257 -- Fetch the cursor data into a record
8258 FETCH bank_account_dtls_cur
8259 INTO bank_account_dtls_rec;
8260 EXIT WHEN bank_account_dtls_cur%NOTFOUND;
8261
8262 -- Initializing the local variables
8263 fnd_file.put_line(fnd_file.log,
8264 ' Message: Inside import_vendor_bank_dtls initializing local variables ');
8265
8266 l_bank_id := NULL;
8267 l_branch_id := NULL;
8268 l_account_id := NULL;
8269 l_intermediary1_acct_id := NULL;
8270 l_intermediary2_acct_id := NULL;
8271 l_account_owner_id := NULL;
8272 l_joint_account_owner_id := NULL;
8273 l_obj_version := NULL;
8274 l_party_site_id := NULL;
8275 l_vendor_site_id := NULL;
8276 l_org_type := NULL;
8277 l_association_level := NULL;
8278 l_bank_end_date := NULL;
8279 l_branch_end_date := NULL;
8280 l_account_start_date := NULL;
8281 l_account_end_date := NULL;
8282 l_bank_rowid := NULL;
8283 l_branch_rowid := NULL;
8284
8285 -- fetch the party id
8286 IF (bank_account_dtls_rec.party_id IS NULL) THEN
8287 l_party_id := get_party_id(bank_account_dtls_rec.source_system,
8288 bank_account_dtls_rec.source_system_reference);
8289 ELSE
8290 l_party_id := bank_account_dtls_rec.party_id;
8291 END IF;
8292
8293 -- Check if the bank exists
8294 -- This API would return the bank_id
8295 -- an OUT param
8296 iby_ext_bankacct_pub.check_bank_exist(p_api_version => 1,
8297 p_init_msg_list => fnd_api.g_true,
8298 p_country_code => bank_account_dtls_rec.country_code,
8299 p_bank_name => bank_account_dtls_rec.bank_name,
8300 p_bank_number => bank_account_dtls_rec.bank_number,
8301 x_return_status => l_ret_status,
8302 x_msg_count => l_msg_count,
8303 x_msg_data => l_msg_data,
8304 x_bank_id => l_bank_id,
8305 x_end_date => l_bank_end_date,
8306 x_response => l_check_bank_resp);
8307
8308 x_return_status := l_ret_status;
8309 x_msg_count := l_msg_count;
8310 x_msg_data := l_msg_data;
8311
8312 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
8313 UPDATE pos_bank_account_det_int
8314 SET interface_status = 'REJECTED'
8315 WHERE bank_account_interface_id =
8316 bank_account_dtls_rec.bank_account_interface_id
8317 AND batch_id = p_batch_id;
8318
8319 IF (insert_rejections(p_batch_id,
8320 l_request_id,
8321 'POS_BANK_ACCOUNT_DET_INT',
8322 bank_account_dtls_rec.bank_account_interface_id,
8323 'POS_INVALID_BANK_INFO',
8324 g_user_id,
8325 g_login_id,
8326 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
8327
8328 IF (g_level_procedure >= g_current_runtime_level) THEN
8329 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8330 p_data => l_msg_data);
8331 fnd_log.string(g_level_procedure,
8332 g_module_name || l_api_name,
8333 'Parameters: ' || ' Interface_Id: ' ||
8334 bank_account_dtls_rec.bank_account_interface_id ||
8335 ' Check if the bank exists Msg: ' || l_msg_data);
8336 END IF;
8337 END IF;
8338 fnd_file.put_line(fnd_file.log,
8339 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8340 ' failed in iby_ext_bankacct_pub.check_bank_exist ' ||
8341 ' Interface_Id: ' ||
8342 bank_account_dtls_rec.bank_account_interface_id ||
8343 ', No. of Messages: ' || l_msg_count ||
8344 ', Message: ' || l_msg_data);
8345 GOTO continue_next_record;
8346 END IF;
8347
8348 l_new_bank_rec.bank_name := bank_account_dtls_rec.bank_name;
8349 l_new_bank_rec.bank_number := bank_account_dtls_rec.bank_number;
8350 l_new_bank_rec.institution_type := bank_account_dtls_rec.bank_inst_type;
8351 l_new_bank_rec.country_code := bank_account_dtls_rec.country_code;
8352 l_new_bank_rec.bank_alt_name := bank_account_dtls_rec.alt_bank_name;
8353 l_new_bank_rec.description := bank_account_dtls_rec.bank_description;
8354
8355 fnd_file.put_line(fnd_file.log,
8356 ' Message: After check_bank_exist' || ' Bank Id :' ||
8357 l_bank_id);
8358
8359 IF (l_bank_id IS NULL) THEN
8360 -- bank doesn't exist so CREATE
8361 fnd_file.put_line(fnd_file.log, ' Going for bank creation');
8362 iby_ext_bankacct_pub. create_ext_bank(p_api_version => 1,
8363 p_init_msg_list => fnd_api.g_true,
8364 p_ext_bank_rec => l_new_bank_rec,
8365 x_bank_id => l_bank_id,
8366 x_return_status => l_ret_status,
8367 x_msg_count => l_msg_count,
8368 x_msg_data => l_msg_data,
8369 x_response => l_create_bank_resp);
8370
8371 x_return_status := l_ret_status;
8372 x_msg_count := l_msg_count;
8373 x_msg_data := l_msg_data;
8374 ELSIF (l_bank_id IS NOT NULL) THEN
8375 -- Update
8376 fnd_file.put_line(fnd_file.log, ' Going for bank update');
8377 l_new_bank_rec.bank_id := l_bank_id;
8378
8379 --getting the object version number
8380 SELECT object_version_number
8381 INTO l_new_bank_rec.object_version_number
8382 FROM hz_parties
8383 WHERE party_id = l_bank_id;
8384
8385 iby_ext_bankacct_pub.update_ext_bank(p_api_version => 1,
8386 p_init_msg_list => fnd_api.g_true,
8387 p_ext_bank_rec => l_new_bank_rec,
8388 x_return_status => l_ret_status,
8389 x_msg_count => l_msg_count,
8390 x_msg_data => l_msg_data,
8391 x_response => l_create_bank_resp);
8392
8393 x_return_status := l_ret_status;
8394 x_msg_count := l_msg_count;
8395 x_msg_data := l_msg_data;
8396 ELSE
8397 l_ret_status := fnd_api.g_ret_sts_error;
8398
8399 fnd_file.put_line(fnd_file.log,
8400 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8401 ' failed in iby_ext_bankacct_pub.create/update_ext_bank' ||
8402 ' Interface_Id: ' ||
8403 bank_account_dtls_rec.bank_account_interface_id ||
8404 ', No. of Messages: ' || l_msg_count ||
8405 ', Message: Bank doesnt exist');
8406 END IF;
8407
8408 -- this would also return the generated bank_id.
8409 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
8410 UPDATE pos_bank_account_det_int
8411 SET interface_status = 'REJECTED'
8412 WHERE bank_account_interface_id =
8413 bank_account_dtls_rec.bank_account_interface_id
8414 AND batch_id = p_batch_id;
8415
8416 IF (insert_rejections(p_batch_id,
8417 l_request_id,
8418 'POS_BANK_ACCOUNT_DET_INT',
8419 bank_account_dtls_rec.bank_account_interface_id,
8420 'POS_INVALID_BANK_INFO',
8421 g_user_id,
8422 g_login_id,
8423 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
8424
8425 IF (g_level_procedure >= g_current_runtime_level) THEN
8426 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8427 p_data => l_msg_data);
8428 fnd_log.string(g_level_procedure,
8429 g_module_name || l_api_name,
8430 'Parameters: ' || ' Interface_Id: ' ||
8431 bank_account_dtls_rec.bank_account_interface_id ||
8432 ' bank creation Msg: ' || l_msg_data);
8433 END IF;
8434 END IF;
8435 fnd_file.put_line(fnd_file.log,
8436 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8437 ' failed in iby_ext_bankacct_pub.create/update_ext_bank ' ||
8438 ' Interface_Id: ' ||
8439 bank_account_dtls_rec.bank_account_interface_id ||
8440 ', No. of Messages: ' || l_msg_count ||
8441 ', Message: ' || l_msg_data);
8442 GOTO continue_next_record;
8443 END IF;
8444
8445 IF l_bank_id IS NOT NULL THEN
8446 fnd_file.put_line(fnd_file.log, ' Message: Bank Id :' || l_bank_id);
8447 -- Update the interface table with the
8448 -- bank_id that is obtained
8449 UPDATE pos_bank_account_det_int
8450 SET bank_id = l_bank_id
8451 WHERE bank_account_interface_id =
8452 bank_account_dtls_rec.bank_account_interface_id
8453 AND batch_id = p_batch_id;
8454
8455 SELECT ROWID
8456 INTO l_bank_rowid
8457 FROM hz_parties
8458 WHERE party_id = l_bank_id;
8459
8460 -- Update the other bank details
8461 hz_parties_pkg.update_row(x_rowid => l_bank_rowid,
8462 x_party_id => l_bank_id,
8463 x_party_number => NULL,
8464 x_party_name => NULL,
8465 x_party_type => NULL,
8466 x_validated_flag => NULL,
8467 x_attribute_category => NULL,
8468 x_attribute1 => NULL,
8469 x_attribute2 => NULL,
8470 x_attribute3 => NULL,
8471 x_attribute4 => NULL,
8472 x_attribute5 => NULL,
8473 x_attribute6 => NULL,
8474 x_attribute7 => NULL,
8475 x_attribute8 => NULL,
8476 x_attribute9 => NULL,
8477 x_attribute10 => NULL,
8478 x_attribute11 => NULL,
8479 x_attribute12 => NULL,
8480 x_attribute13 => NULL,
8481 x_attribute14 => NULL,
8482 x_attribute15 => NULL,
8483 x_attribute16 => NULL,
8484 x_attribute17 => NULL,
8485 x_attribute18 => NULL,
8486 x_attribute19 => NULL,
8487 x_attribute20 => NULL,
8488 x_attribute21 => NULL,
8489 x_attribute22 => NULL,
8490 x_attribute23 => NULL,
8491 x_attribute24 => NULL,
8492 x_orig_system_reference => NULL,
8493 x_sic_code => NULL,
8494 x_hq_branch_ind => NULL,
8495 x_customer_key => NULL,
8496 x_tax_reference => NULL,
8497 x_jgzz_fiscal_code => NULL,
8498 x_person_pre_name_adjunct => NULL,
8499 x_person_first_name => NULL,
8500 x_person_middle_name => NULL,
8501 x_person_last_name => NULL,
8502 x_person_name_suffix => NULL,
8503 x_person_title => NULL,
8504 x_person_academic_title => NULL,
8505 x_person_previous_last_name => NULL,
8506 x_known_as => NULL,
8507 x_person_iden_type => NULL,
8508 x_person_identifier => NULL,
8509 x_group_type => NULL,
8510 x_country => NULL,
8511 x_address1 => bank_account_dtls_rec.bank_address_line1,
8512 x_address2 => bank_account_dtls_rec.bank_address_line2,
8513 x_address3 => bank_account_dtls_rec.bank_address_line3,
8514 x_address4 => NULL,
8515 x_city => bank_account_dtls_rec.bank_city,
8516 x_postal_code => bank_account_dtls_rec.bank_zip,
8517 x_state => bank_account_dtls_rec.bank_state,
8518 x_province => NULL,
8519 x_status => NULL,
8520 x_county => NULL,
8521 x_sic_code_type => NULL,
8522 x_url => NULL,
8523 x_email_address => NULL,
8524 x_analysis_fy => NULL,
8525 x_fiscal_yearend_month => NULL,
8526 x_employees_total => NULL,
8527 x_curr_fy_potential_revenue => NULL,
8528 x_next_fy_potential_revenue => NULL,
8529 x_year_established => NULL,
8530 x_gsa_indicator_flag => NULL,
8531 x_mission_statement => NULL,
8532 x_organization_name_phonetic => NULL,
8533 x_person_first_name_phonetic => NULL,
8534 x_person_last_name_phonetic => NULL,
8535 x_language_name => NULL,
8536 x_category_code => NULL,
8537 x_salutation => NULL,
8538 x_known_as2 => NULL,
8539 x_known_as3 => NULL,
8540 x_known_as4 => NULL,
8541 x_known_as5 => NULL,
8542 x_object_version_number => NULL,
8543 x_duns_number_c => NULL,
8544 x_created_by_module => NULL,
8545 x_application_id => NULL);
8546
8547 -- Update bank end date
8548 IF (bank_account_dtls_rec.bank_end_date IS NOT NULL) THEN
8549 iby_ext_bankacct_pub.set_bank_end_date(p_api_version => 1.0,
8550 p_init_msg_list => fnd_api.g_true,
8551 p_bank_id => l_bank_id,
8552 p_end_date => bank_account_dtls_rec.bank_end_date,
8553 x_return_status => l_ret_status,
8554 x_msg_count => l_msg_count,
8555 x_msg_data => l_msg_data,
8556 x_response => l_set_bank_end_date_resp);
8557
8558 x_return_status := l_ret_status;
8559 x_msg_count := l_msg_count;
8560 x_msg_data := l_msg_data;
8561
8562 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
8563 UPDATE pos_bank_account_det_int
8564 SET interface_status = 'REJECTED'
8565 WHERE bank_account_interface_id =
8566 bank_account_dtls_rec.bank_account_interface_id
8567 AND batch_id = p_batch_id;
8568
8569 IF (insert_rejections(p_batch_id,
8570 l_request_id,
8571 'POS_BANK_ACCOUNT_DET_INT',
8572 bank_account_dtls_rec.bank_account_interface_id,
8573 'POS_FAILED_BANK_END_DATE',
8574 g_user_id,
8575 g_login_id,
8576 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
8577
8578 IF (g_level_procedure >= g_current_runtime_level) THEN
8579 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8580 p_data => l_msg_data);
8581 fnd_log.string(g_level_procedure,
8582 g_module_name || l_api_name,
8583 'Parameters: ' || ' Interface_Id: ' ||
8584 bank_account_dtls_rec.bank_account_interface_id ||
8585 ' Update bank end date: ' || l_msg_data);
8586 END IF;
8587 END IF;
8588 fnd_file.put_line(fnd_file.log,
8589 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8590 ' failed in iby_ext_bankacct_pub.set_bank_end_date ' ||
8591 ' Interface_Id: ' ||
8592 bank_account_dtls_rec.bank_account_interface_id ||
8593 ', No. of Messages: ' || l_msg_count ||
8594 ', Message: ' || l_msg_data);
8595 GOTO continue_next_record;
8596 END IF;
8597
8598 END IF;
8599 END IF;
8600
8601 -- Check if the branch exists
8602 -- This API would return the branch_id an OUT param
8603 iby_ext_bankacct_pub.check_ext_bank_branch_exist(p_api_version => 1,
8604 p_init_msg_list => fnd_api.g_true,
8605 p_bank_id => l_bank_id,
8606 p_branch_name => bank_account_dtls_rec.branch_name,
8607 p_branch_number => bank_account_dtls_rec.branch_number,
8608 x_return_status => l_ret_status,
8609 x_msg_count => l_msg_count,
8610 x_msg_data => l_msg_data,
8611 x_branch_id => l_branch_id,
8612 x_end_date => l_branch_end_date,
8613 x_response => l_check_branch_resp);
8614
8615 x_return_status := l_ret_status;
8616 x_msg_count := l_msg_count;
8617 x_msg_data := l_msg_data;
8618
8619 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
8620 UPDATE pos_bank_account_det_int
8621 SET interface_status = 'REJECTED'
8622 WHERE bank_account_interface_id =
8623 bank_account_dtls_rec.bank_account_interface_id
8624 AND batch_id = p_batch_id;
8625
8626 IF (insert_rejections(p_batch_id,
8627 l_request_id,
8628 'POS_BANK_ACCOUNT_DET_INT',
8629 bank_account_dtls_rec.bank_account_interface_id,
8630 'POS_INVALID_BRANCH_INFO',
8631 g_user_id,
8632 g_login_id,
8633 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
8634
8635 IF (g_level_procedure >= g_current_runtime_level) THEN
8636 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8637 p_data => l_msg_data);
8638 fnd_log.string(g_level_procedure,
8639 g_module_name || l_api_name,
8640 'Parameters: ' || ' Interface_Id: ' ||
8641 bank_account_dtls_rec.bank_account_interface_id ||
8642 ' Update bank end date: ' || l_msg_data);
8643 END IF;
8644 END IF;
8645 fnd_file.put_line(fnd_file.log,
8646 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8647 ' failed in iby_ext_bankacct_pub.check_ext_bank_branch_exist' ||
8648 ' Interface_Id: ' ||
8649 bank_account_dtls_rec.bank_account_interface_id ||
8650 ', No. of Messages: ' || l_msg_count ||
8651 ', Message: ' || l_msg_data);
8652 GOTO continue_next_record;
8653 END IF;
8654
8655 l_new_branch_rec.branch_name := bank_account_dtls_rec.branch_name;
8656 l_new_branch_rec.branch_number := bank_account_dtls_rec.branch_number;
8657 l_new_branch_rec.bank_party_id := l_bank_id;
8658 l_new_branch_rec.branch_type := bank_account_dtls_rec.branch_type;
8659 l_new_branch_rec.alternate_branch_name := bank_account_dtls_rec.alt_branch_name;
8660 l_new_branch_rec.description := bank_account_dtls_rec.branch_description;
8661 l_new_branch_rec.bic := bank_account_dtls_rec.bic;
8662 l_new_branch_rec.rfc_identifier := bank_account_dtls_rec.branch_rfc_identifier;
8663
8664 fnd_file.put_line(fnd_file.log,
8665 ' Message: After check_branch_exist' ||
8666 ' Branch Id :' || l_branch_id);
8667
8668 IF (l_branch_id IS NULL) THEN
8669 -- branch doesn't exist so CREATE
8670 fnd_file.put_line(fnd_file.log,
8671 ' Message: Going for branch creation');
8672 iby_ext_bankacct_pub.create_ext_bank_branch(p_api_version => 1,
8673 p_init_msg_list => fnd_api.g_true,
8674 p_ext_bank_branch_rec => l_new_branch_rec,
8675 x_branch_id => l_branch_id,
8676 x_return_status => l_ret_status,
8677 x_msg_count => l_msg_count,
8678 x_msg_data => l_msg_data,
8679 x_response => l_create_branch_resp);
8680
8681 x_return_status := l_ret_status;
8682 x_msg_count := l_msg_count;
8683 x_msg_data := l_msg_data;
8684 ELSIF (l_branch_id IS NOT NULL) THEN
8685 l_new_branch_rec.branch_party_id := l_branch_id;
8686
8687 fnd_file.put_line(fnd_file.log,
8688 ' Message: Going for branch update');
8689
8690 --getting the object version number
8691 /*SELECT object_version_number
8692 INTO l_new_branch_rec.bch_object_version_number
8693 FROM iby_ext_bank_branches_v
8694 WHERE branch_party_id = l_branch_id;*/
8695
8696 SELECT object_version_number
8697 INTO l_new_branch_rec.bch_object_version_number
8698 FROM hz_parties
8699 WHERE party_id = l_branch_id;
8700
8701 --Getting Bank Branch Type Object Version Number
8702 BEGIN
8703 SELECT hca.object_version_number
8704 INTO l_new_branch_rec.typ_object_version_number
8705 FROM hz_code_assignments hca
8706 WHERE hca.class_category = 'BANK_BRANCH_TYPE'
8707 AND hca.owner_table_name = 'HZ_PARTIES'
8708 AND hca.owner_table_id = l_branch_id
8709 --AND hca.primary_flag='Y'
8710 AND SYSDATE BETWEEN start_date_active AND
8711 nvl(end_date_active, SYSDATE + 1)
8712 AND hca.status = 'A';
8713
8714 EXCEPTION
8715 WHEN no_data_found THEN
8716 l_new_branch_rec.typ_object_version_number := 1;
8717 END;
8718
8719 fnd_file.put_line(fnd_file.log,
8720 ' l_new_branch_rec.typ_object_version_number: ' ||
8721 l_new_branch_rec.typ_object_version_number);
8722
8723 fnd_file.put_line(fnd_file.log,
8724 ' l_new_branch_rec.bch_object_version_number: ' ||
8725 l_new_branch_rec.bch_object_version_number);
8726
8727 iby_ext_bankacct_pub.update_ext_bank_branch(p_api_version => 1,
8728 p_init_msg_list => fnd_api.g_true,
8729 p_ext_bank_branch_rec => l_new_branch_rec,
8730 x_return_status => l_ret_status,
8731 x_msg_count => l_msg_count,
8732 x_msg_data => l_msg_data,
8733 x_response => l_create_branch_resp);
8734
8735 x_return_status := l_ret_status;
8736 x_msg_count := l_msg_count;
8737 x_msg_data := l_msg_data;
8738 ELSE
8739 l_ret_status := fnd_api.g_ret_sts_error;
8740
8741 fnd_file.put_line(fnd_file.log,
8742 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8743 ' failed in iby_ext_bankacct_pub.create/update_ext_bank_branch' ||
8744 ' Interface_Id: ' ||
8745 bank_account_dtls_rec.bank_account_interface_id ||
8746 ', No. of Messages: ' || l_msg_count ||
8747 ', Message: Branch doesnt exist');
8748 END IF;
8749 -- this would also return the generated branch_id.
8750
8751 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
8752 UPDATE pos_bank_account_det_int
8753 SET interface_status = 'REJECTED'
8754 WHERE bank_account_interface_id =
8755 bank_account_dtls_rec.bank_account_interface_id
8756 AND batch_id = p_batch_id;
8757
8758 IF (insert_rejections(p_batch_id,
8759 l_request_id,
8760 'POS_BANK_ACCOUNT_DET_INT',
8761 bank_account_dtls_rec.bank_account_interface_id,
8762 'POS_INVALID_BRANCH_INFO',
8763 g_user_id,
8764 g_login_id,
8765 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
8766
8767 IF (g_level_procedure >= g_current_runtime_level) THEN
8768 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8769 p_data => l_msg_data);
8770 fnd_log.string(g_level_procedure,
8771 g_module_name || l_api_name,
8772 'Parameters: ' || ' Interface_Id: ' ||
8773 bank_account_dtls_rec.bank_account_interface_id ||
8774 ' Update bank end date: ' || l_msg_data);
8775 END IF;
8776 END IF;
8777
8778 fnd_file.put_line(fnd_file.log,
8779 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8780 ' failed in iby_ext_bankacct_pub.create/update_ext_bank_branch' ||
8781 ' Interface_Id: ' ||
8782 bank_account_dtls_rec.bank_account_interface_id ||
8783 ', No. of Messages: ' || l_msg_count ||
8784 ', Message: ' || l_msg_data);
8785 GOTO continue_next_record;
8786 END IF;
8787
8788 IF (l_branch_id IS NOT NULL) THEN
8789 fnd_file.put_line(fnd_file.log,
8790 ' Message: Updating branch id ' || ' Branch Id :' ||
8791 l_branch_id);
8792 -- Update the interface table with the branch_id that is obtained
8793 UPDATE pos_bank_account_det_int
8794 SET branch_id = l_branch_id
8795 WHERE bank_account_interface_id =
8796 bank_account_dtls_rec.bank_account_interface_id
8797 AND batch_id = p_batch_id;
8798
8799 SELECT ROWID
8800 INTO l_branch_rowid
8801 FROM hz_parties
8802 WHERE party_id = l_branch_id;
8803
8804 -- Update the other branch details
8805 hz_parties_pkg.update_row(x_rowid => l_branch_rowid,
8806 x_party_id => l_branch_id,
8807 x_party_number => NULL,
8808 x_party_name => NULL,
8809 x_party_type => NULL,
8810 x_validated_flag => NULL,
8811 x_attribute_category => NULL,
8812 x_attribute1 => NULL,
8813 x_attribute2 => NULL,
8814 x_attribute3 => NULL,
8815 x_attribute4 => NULL,
8816 x_attribute5 => NULL,
8817 x_attribute6 => NULL,
8818 x_attribute7 => NULL,
8819 x_attribute8 => NULL,
8820 x_attribute9 => NULL,
8821 x_attribute10 => NULL,
8822 x_attribute11 => NULL,
8823 x_attribute12 => NULL,
8824 x_attribute13 => NULL,
8825 x_attribute14 => NULL,
8826 x_attribute15 => NULL,
8827 x_attribute16 => NULL,
8828 x_attribute17 => NULL,
8829 x_attribute18 => NULL,
8830 x_attribute19 => NULL,
8831 x_attribute20 => NULL,
8832 x_attribute21 => NULL,
8833 x_attribute22 => NULL,
8834 x_attribute23 => NULL,
8835 x_attribute24 => NULL,
8836 x_orig_system_reference => NULL,
8837 x_sic_code => NULL,
8838 x_hq_branch_ind => NULL,
8839 x_customer_key => NULL,
8840 x_tax_reference => NULL,
8841 x_jgzz_fiscal_code => NULL,
8842 x_person_pre_name_adjunct => NULL,
8843 x_person_first_name => NULL,
8844 x_person_middle_name => NULL,
8845 x_person_last_name => NULL,
8846 x_person_name_suffix => NULL,
8847 x_person_title => NULL,
8848 x_person_academic_title => NULL,
8849 x_person_previous_last_name => NULL,
8850 x_known_as => NULL,
8851 x_person_iden_type => NULL,
8852 x_person_identifier => NULL,
8853 x_group_type => NULL,
8854 x_country => NULL,
8855 x_address1 => bank_account_dtls_rec.branch_address_line1,
8856 x_address2 => bank_account_dtls_rec.branch_address_line2,
8857 x_address3 => bank_account_dtls_rec.branch_address_line3,
8858 x_address4 => NULL,
8859 x_city => bank_account_dtls_rec.branch_city,
8860 x_postal_code => bank_account_dtls_rec.branch_zip,
8861 x_state => bank_account_dtls_rec.branch_state,
8862 x_province => NULL,
8863 x_status => NULL,
8864 x_county => NULL,
8865 x_sic_code_type => NULL,
8866 x_url => NULL,
8867 x_email_address => NULL,
8868 x_analysis_fy => NULL,
8869 x_fiscal_yearend_month => NULL,
8870 x_employees_total => NULL,
8871 x_curr_fy_potential_revenue => NULL,
8872 x_next_fy_potential_revenue => NULL,
8873 x_year_established => NULL,
8874 x_gsa_indicator_flag => NULL,
8875 x_mission_statement => NULL,
8876 x_organization_name_phonetic => NULL,
8877 x_person_first_name_phonetic => NULL,
8878 x_person_last_name_phonetic => NULL,
8879 x_language_name => NULL,
8880 x_category_code => NULL,
8881 x_salutation => NULL,
8882 x_known_as2 => NULL,
8883 x_known_as3 => NULL,
8884 x_known_as4 => NULL,
8885 x_known_as5 => NULL,
8886 x_object_version_number => NULL,
8887 x_duns_number_c => NULL,
8888 x_created_by_module => NULL,
8889 x_application_id => NULL);
8890
8891 -- Update branch end date
8892 IF (bank_account_dtls_rec.branch_end_date IS NOT NULL) THEN
8893 iby_ext_bankacct_pub.set_ext_bank_branch_end_date(p_api_version => 1.0,
8894 p_init_msg_list => fnd_api.g_true,
8895 p_branch_id => l_branch_id,
8896 p_end_date => bank_account_dtls_rec.branch_end_date,
8897 x_return_status => l_ret_status,
8898 x_msg_count => l_msg_count,
8899 x_msg_data => l_msg_data,
8900 x_response => l_set_branch_end_date_resp);
8901
8902 x_return_status := l_ret_status;
8903 x_msg_count := l_msg_count;
8904 x_msg_data := l_msg_data;
8905
8906 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
8907 UPDATE pos_bank_account_det_int
8908 SET interface_status = 'REJECTED'
8909 WHERE bank_account_interface_id =
8910 bank_account_dtls_rec.bank_account_interface_id
8911 AND batch_id = p_batch_id;
8912
8913 IF (insert_rejections(p_batch_id,
8914 l_request_id,
8915 'POS_BANK_ACCOUNT_DET_INT',
8916 bank_account_dtls_rec.bank_account_interface_id,
8917 'POS_FAILED_BRANCH_END_DATE',
8918 g_user_id,
8919 g_login_id,
8920 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
8921
8922 IF (g_level_procedure >= g_current_runtime_level) THEN
8923 fnd_msg_pub.count_and_get(p_count => l_msg_count,
8924 p_data => l_msg_data);
8925 fnd_log.string(g_level_procedure,
8926 g_module_name || l_api_name,
8927 'Parameters: ' || ' Interface_Id: ' ||
8928 bank_account_dtls_rec.bank_account_interface_id ||
8929 ' Update bank end date: ' || l_msg_data);
8930 END IF;
8931 END IF;
8932 fnd_file.put_line(fnd_file.log,
8933 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
8934 ' failed in iby_ext_bankacct_pub.set_ext_bank_branch_end_date' ||
8935 ' Interface_Id: ' ||
8936 bank_account_dtls_rec.bank_account_interface_id ||
8937 ', No. of Messages: ' || l_msg_count ||
8938 ', Message: ' || l_msg_data);
8939 GOTO continue_next_record;
8940 END IF;
8941
8942 END IF;
8943 END IF;
8944
8945 -- Check if the account exists
8946 -- This API would return the account_id an OUT param
8947 iby_ext_bankacct_pub.check_ext_acct_exist(p_api_version => 1,
8948 p_init_msg_list => fnd_api.g_true,
8949 p_bank_id => l_bank_id,
8950 p_branch_id => l_branch_id,
8951 p_acct_number => bank_account_dtls_rec.bank_account_number,
8952 p_acct_name => bank_account_dtls_rec.account_name,
8953 p_currency => bank_account_dtls_rec.account_currency_code,
8954 p_country_code => bank_account_dtls_rec.country_code,
8955 x_acct_id => l_account_id,
8956 x_start_date => l_account_start_date,
8957 x_end_date => l_account_end_date,
8958 x_return_status => l_ret_status,
8959 x_msg_count => l_msg_count,
8960 x_msg_data => l_msg_data,
8961 x_response => l_check_account_resp);
8962
8963 fnd_file.put_line(fnd_file.log,
8964 ' Message: After check_account_exist' ||
8965 ' Account Id :' || l_account_id);
8966
8967 -- Process account
8968
8969 -- p_association_level should be 'A', 'SS', 'AO', 'S;' depending on the
8970 -- level for which the account is being created
8971 -- A is for the Party site level in which case the party_site_id has to be NOT NULL
8972 -- AO Addres-Operating unit level. Party_site_id not null and Org_id not null
8973 -- SS is for Supplier Site level. So Supplier_site_id, Party_site_id and Org_id have to be
8974 -- NOT NULL
8975 -- S is for the supplier level
8976
8977 IF ((bank_account_dtls_rec.party_site_orig_sys IS NOT NULL AND
8978 bank_account_dtls_rec.party_site_orig_sys_ref IS NOT NULL) OR
8979 (bank_account_dtls_rec.party_site_name IS NOT NULL)) THEN
8980 IF (bank_account_dtls_rec.party_site_orig_sys IS NOT NULL AND
8981 bank_account_dtls_rec.party_site_orig_sys_ref IS NOT NULL) THEN
8982
8983 fnd_file.put_line(fnd_file.log,
8984 ' Message: orig_system' ||
8985 bank_account_dtls_rec.party_site_orig_sys ||
8986 ' orig_system_reference :' ||
8987 bank_account_dtls_rec.party_site_orig_sys_ref);
8988
8989 -- Get the party site id
8990 SELECT owner_table_id
8991 INTO l_party_site_id
8992 FROM hz_orig_sys_references
8993 WHERE orig_system = bank_account_dtls_rec.party_site_orig_sys
8994 AND orig_system_reference =
8995 bank_account_dtls_rec.party_site_orig_sys_ref
8996 AND owner_table_name = 'HZ_PARTY_SITES'
8997 AND nvl(end_date_active, SYSDATE) >= SYSDATE;
8998 END IF;
8999
9000 fnd_file.put_line(fnd_file.log,
9001 ' Message: Get the party site id' ||
9002 ' party_site_id :' || l_party_site_id);
9003
9004 IF (l_party_site_id IS NULL OR l_party_site_id = 0) THEN
9005 SELECT hps.party_site_id
9006 /*, hps.party_site_name, hzl.address1, hzl.address2, hzl.address3, hzl.address4,
9007 hzl.state, hzl.province, hzl.county, hzl.country, fvl.territory_short_name as country_name
9008 , hzl.city , hzl.postal_code*/
9009 INTO l_party_site_id
9010 FROM hz_party_sites hps,
9011 hz_locations hzl,
9012 fnd_territories_vl fvl
9013 WHERE hps.party_id = l_party_id
9014 AND hzl.location_id = hps.location_id
9015 AND hps.status = 'A'
9016 AND fvl.territory_code = hzl.country
9017 AND hps.party_site_name =
9018 bank_account_dtls_rec.party_site_name;
9019 END IF;
9020 END IF;
9021
9022 fnd_file.put_line(fnd_file.log,
9023 ' Message: Get the party site id from hz_locations' ||
9024 ' party_site_id :' || l_party_site_id ||
9025 ' l_party_id : ' || l_party_id ||
9026 ' vendor_site_code : ' ||
9027 bank_account_dtls_rec.vendor_site_code ||
9028 ' org_id : ' || bank_account_dtls_rec.org_id);
9029
9030 -- Bug 12842286: Bank Account Creation/Update Loop Aborted if one record errors out.
9031 -- Need to handle the exception when vendor_site_id is not found (Failing to create supplier site will cause this issue)
9032 BEGIN
9033 IF (bank_account_dtls_rec.vendor_site_code IS NOT NULL) THEN
9034 SELECT vendor_site_id,
9035 party_site_id
9036 INTO l_vendor_site_id,
9037 l_party_site_id
9038 FROM ap_supplier_sites_all site,
9039 ap_suppliers vendor
9040 WHERE vendor.vendor_id = site.vendor_id
9041 AND (site.inactive_date > SYSDATE OR site.inactive_date IS NULL)
9042 AND vendor.party_id = l_party_id
9043 AND site.vendor_site_code =
9044 bank_account_dtls_rec.vendor_site_code
9045 AND site.org_id = bank_account_dtls_rec.org_id;
9046 END IF;
9047
9048 fnd_file.put_line(fnd_file.log,
9049 ' Message: vendor_site_id :' || l_vendor_site_id);
9050
9051 IF (l_vendor_site_id IS NOT NULL AND l_party_site_id IS NOT NULL AND
9052 l_party_site_id <> 0 AND bank_account_dtls_rec.org_id IS NOT NULL) THEN
9053 l_association_level := 'SS';
9054 l_org_type := 'OPERATING_UNIT';
9055
9056 ELSIF (l_party_site_id IS NOT NULL AND l_party_site_id <> 0 AND
9057 bank_account_dtls_rec.org_id IS NOT NULL) THEN
9058 l_association_level := 'AO';
9059 l_org_type := 'OPERATING_UNIT';
9060
9061 ELSIF (l_party_site_id IS NOT NULL AND l_party_site_id <> 0) THEN
9062 l_association_level := 'A';
9063
9064 ELSE
9065 l_association_level := 'S';
9066 END IF;
9067
9068 fnd_file.put_line(fnd_file.log,
9069 ' Message: Account association level :' ||
9070 l_association_level);
9071
9072 EXCEPTION
9073 WHEN OTHERS THEN
9074 UPDATE pos_bank_account_det_int
9075 SET interface_status = 'REJECTED'
9076 WHERE bank_account_interface_id =
9077 bank_account_dtls_rec.bank_account_interface_id
9078 AND batch_id = p_batch_id;
9079
9080 IF (insert_rejections(p_batch_id,
9081 l_request_id,
9082 'POS_BANK_ACCOUNT_DET_INT',
9083 bank_account_dtls_rec.bank_account_interface_id,
9084 'AP_INVALID_BANK_ACCT_INFO',
9085 g_user_id,
9086 g_login_id,
9087 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
9088
9089 IF (g_level_procedure >= g_current_runtime_level) THEN
9090 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9091 p_data => l_msg_data);
9092 fnd_log.string(g_level_procedure,
9093 g_module_name || l_api_name,
9094 'Parameters: ' || ' Interface_Id: ' ||
9095 bank_account_dtls_rec.bank_account_interface_id ||
9096 ' Update bank end date: ' || l_msg_data);
9097 END IF;
9098 END IF;
9099 fnd_file.put_line(fnd_file.log,
9100 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9101 ' failed to find site id' ||
9102 ' Interface_Id: ' ||
9103 bank_account_dtls_rec.bank_account_interface_id ||
9104 ', No. of Messages: ' || l_msg_count ||
9105 ', Message: ' || l_msg_data);
9106
9107 GOTO continue_next_record;
9108 END;
9109 -- End Bug 12842286
9110
9111 l_new_account_rec.payment_factor_flag := l_new_account_rec.payment_factor_flag;
9112 l_new_account_rec.country_code := bank_account_dtls_rec.country_code;
9113 l_new_account_rec.branch_id := l_branch_id;
9114 l_new_account_rec.bank_id := l_bank_id;
9115 l_new_account_rec.acct_owner_party_id := l_party_id;
9116 l_new_account_rec.bank_account_name := bank_account_dtls_rec.account_name;
9117 l_new_account_rec.bank_account_num := bank_account_dtls_rec.bank_account_number;
9118 l_new_account_rec.currency := bank_account_dtls_rec.account_currency_code;
9119 l_new_account_rec.iban := bank_account_dtls_rec.iban;
9120 l_new_account_rec.check_digits := bank_account_dtls_rec.check_digits;
9121 l_new_account_rec.alternate_acct_name := bank_account_dtls_rec.alt_account_name;
9122 l_new_account_rec.acct_type := bank_account_dtls_rec.account_type;
9123 l_new_account_rec.acct_suffix := bank_account_dtls_rec.account_suffix;
9124 l_new_account_rec.description := bank_account_dtls_rec.account_description;
9125 l_new_account_rec.agency_location_code := bank_account_dtls_rec.agency_location_code;
9126 l_new_account_rec.foreign_payment_use_flag := bank_account_dtls_rec.foreign_payment_use_flag;
9127 l_new_account_rec.exchange_rate_agreement_num := bank_account_dtls_rec.exchange_rate_agreement_num;
9128 l_new_account_rec.exchange_rate_agreement_type := bank_account_dtls_rec.exchange_rate_agreement_type;
9129 l_new_account_rec.exchange_rate := bank_account_dtls_rec.exchange_rate;
9130 l_new_account_rec.end_date := bank_account_dtls_rec.account_end_date;
9131 l_new_account_rec.start_date := bank_account_dtls_rec.account_start_date;
9132
9133 IF (l_account_id IS NULL) THEN
9134 bank_account_dtls_rec.insert_update_flag := nvl(bank_account_dtls_rec.insert_update_flag,
9135 'I');
9136 ELSE
9137 bank_account_dtls_rec.insert_update_flag := nvl(bank_account_dtls_rec.insert_update_flag,
9138 'U');
9139 END IF;
9140
9141 fnd_file.put_line(fnd_file.log,
9142 ' bank_account_dtls_rec.insert_update_flag: ' ||
9143 bank_account_dtls_rec.insert_update_flag ||
9144 ' l_new_account_rec.alternate_acct_name : ' ||
9145 l_new_account_rec.alternate_acct_name);
9146
9147 IF (l_account_id IS NULL AND
9148 bank_account_dtls_rec.insert_update_flag = 'I') THEN
9149 iby_ext_bankacct_pub.create_ext_bank_acct(p_api_version => 1,
9150 p_init_msg_list => fnd_api.g_true,
9151 p_ext_bank_acct_rec => l_new_account_rec,
9152 p_association_level => l_association_level,
9153 p_supplier_site_id => l_vendor_site_id,
9154 p_party_site_id => l_party_site_id,
9155 p_org_id => bank_account_dtls_rec.org_id,
9156 p_org_type => l_org_type,
9157 x_acct_id => l_account_id,
9158 x_return_status => l_ret_status,
9159 x_msg_count => l_msg_count,
9160 x_msg_data => l_msg_data,
9161 x_response => l_create_account_resp);
9162
9163 x_return_status := l_ret_status;
9164 x_msg_count := l_msg_count;
9165 x_msg_data := l_msg_data;
9166 ELSE
9167 IF (l_account_id IS NOT NULL AND
9168 bank_account_dtls_rec.insert_update_flag = 'U') THEN
9169
9170 ---Bug 11819545
9171 --l_new_account_rec.bank_account_id := l_account_id;
9172
9173 IF(l_association_level='SS')THEN
9174 IF(l_vendor_site_id IS NOT NULL) THEN
9175 l_payee_context_rec.Party_Site_id :=l_party_site_id;
9176 l_payee_context_rec.Supplier_Site_id:=l_vendor_site_id;
9177 l_payee_context_rec.Org_Id:=bank_account_dtls_rec.org_id;
9178 l_payee_context_rec.Org_Type:=l_org_type;
9179 END IF;
9180 fnd_file.put_line(fnd_file.log,
9181 ' Message: l_association_level SS and l_vendor_site_id : ' ||
9182 l_association_level||l_vendor_site_id);
9183 ELSIF(l_association_level='A') THEN
9184 IF(l_party_site_id IS NOT NULL) THEN
9185 l_payee_context_rec.Party_Site_id :=l_party_site_id;
9186 l_payee_context_rec.Supplier_Site_id:=NULL;
9187 l_payee_context_rec.Org_Id:=NULL;
9188 l_payee_context_rec.Org_Type:=NULL;
9189 END IF;
9190 fnd_file.put_line(fnd_file.log,
9191 ' Message: l_association_level A and l_party_site_id : ' ||
9192 l_association_level||l_party_site_id);
9193 ELSIF(l_association_level='AO') THEN
9194 IF(l_party_site_id IS NOT NULL AND bank_account_dtls_rec.org_id IS NOT NULL) THEN
9195 fnd_file.put_line(fnd_file.log,
9196 ' Message: l_association_level AO: Party site id, org id is not null' ||
9197 l_association_level);
9198
9199 END IF;
9200 l_payee_context_rec.Party_Site_id :=l_party_site_id;
9201 l_payee_context_rec.Org_Id:= bank_account_dtls_rec.org_id;
9202 l_payee_context_rec.Org_Type:= l_org_type;
9203 l_payee_context_rec.Supplier_Site_id:=NULL;
9204 fnd_file.put_line(fnd_file.log,
9205 ' Message: l_association_level AO, org_id and l_party_site_id : ' ||
9206 l_association_level||bank_account_dtls_rec.org_id||l_party_site_id);
9207 ELSIF(l_association_level='S') THEN
9208 l_payee_context_rec.Party_Site_id :=NULL;
9209 l_payee_context_rec.Org_Id:= NULL;
9210 l_payee_context_rec.Org_Type:= NULL;
9211 l_payee_context_rec.Supplier_Site_id:=NULL;
9212 fnd_file.put_line(fnd_file.log,
9213 ' Message: l_association_level S : ' ||
9214 l_association_level);
9215 END IF;
9216
9217 fnd_file.put_line(fnd_file.log,
9218 ' Message: orgid: ' ||
9219 l_payee_context_rec.Org_Id);
9220 fnd_file.put_line(fnd_file.log,
9221 ' Message: org type : ' ||
9222 l_payee_context_rec.Org_Type);
9223 fnd_file.put_line(fnd_file.log,
9224 ' Message: party_site_id : ' ||
9225 l_payee_context_rec.Party_Site_id);
9226 fnd_file.put_line(fnd_file.log,
9227 ' Message: Supplier_site_id : ' ||
9228 l_payee_context_rec.Supplier_Site_id);
9229
9230 l_payee_context_rec.Payment_Function :=l_payment_function;
9231 l_payee_context_rec.Party_Id :=l_party_id;
9232 l_assign.Instrument.Instrument_Type := l_instrument_type;
9233 L_ASSIGN.INSTRUMENT.INSTRUMENT_ID := L_ACCOUNT_ID;
9234 l_joint_account_owner_id := NULL;
9235
9236 iby_ext_bankacct_pub.add_joint_account_owner(p_api_version => 1.0,
9237 p_init_msg_list => fnd_api.g_true,
9238 p_bank_account_id => l_account_id,
9239 P_ACCT_OWNER_PARTY_ID => L_PARTY_ID,
9240 x_joint_acct_owner_id => l_joint_account_owner_id,
9241 x_return_status => l_ret_status,
9242 x_msg_count => l_msg_count,
9243 X_MSG_DATA => L_MSG_DATA,
9244 x_response => l_add_account_owner_resp);
9245
9246 IBY_DISBURSEMENT_SETUP_PUB.Set_Payee_Instr_Assignment(
9247 p_api_version => 1,
9248 p_init_msg_list => NULL,
9249 p_commit => NULL,
9250 x_return_status => l_ret_status,
9251 x_msg_count => l_msg_count,
9252 x_msg_data => l_msg_data,
9253 p_payee => l_payee_context_rec,
9254 p_assignment_attribs => l_assign,
9255 x_assign_id => l_assign_id,
9256 x_response => l_create_account_resp);
9257
9258 x_return_status := l_ret_status;
9259 x_msg_count := l_msg_count;
9260 x_msg_data := l_msg_data;
9261 --END IF;
9262
9263 ELSIF (l_account_id IS NOT NULL AND
9264 bank_account_dtls_rec.insert_update_flag = 'E') THEN
9265
9266 l_new_account_rec.bank_account_id := l_account_id;
9267 ---End Bug 11819545
9268
9269 --getting the object version number
9270 SELECT object_version_number
9271 INTO l_new_account_rec.object_version_number
9272 FROM iby_ext_bank_accounts_v
9273 WHERE branch_party_id = l_branch_id
9274 AND bank_party_id = l_bank_id
9275 AND ext_bank_account_id = l_account_id;
9276
9277 iby_ext_bankacct_pub.update_ext_bank_acct(p_api_version => 1,
9278 p_init_msg_list => fnd_api.g_true,
9279 p_ext_bank_acct_rec => l_new_account_rec,
9280 x_return_status => l_ret_status,
9281 x_msg_count => l_msg_count,
9282 x_msg_data => l_msg_data,
9283 x_response => l_create_account_resp);
9284
9285 x_return_status := l_ret_status;
9286 x_msg_count := l_msg_count;
9287 x_msg_data := l_msg_data;
9288 ELSE
9289 IF (l_account_id IS NULL AND
9290 bank_account_dtls_rec.insert_update_flag = 'U') THEN
9291 -- Account doesnt exist
9292 l_ret_status := fnd_api.g_ret_sts_error;
9293
9294 fnd_file.put_line(fnd_file.log,
9295 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9296 ' failed in iby_ext_bankacct_pub.create_ext_bank_acct' ||
9297 ' Interface_Id: ' ||
9298 bank_account_dtls_rec.bank_account_interface_id ||
9299 ', No. of Messages: ' || l_msg_count ||
9300 ', Message: Account to be updated, doesnt exist');
9301 END IF;
9302 END IF;
9303 END IF;
9304 -- this would also return the generated account_id.
9305
9306 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
9307 UPDATE pos_bank_account_det_int
9308 SET interface_status = 'REJECTED'
9309 WHERE bank_account_interface_id =
9310 bank_account_dtls_rec.bank_account_interface_id
9311 AND batch_id = p_batch_id;
9312
9313 IF (insert_rejections(p_batch_id,
9314 l_request_id,
9315 'POS_BANK_ACCOUNT_DET_INT',
9316 bank_account_dtls_rec.bank_account_interface_id,
9317 'AP_INVALID_BANK_ACCT_INFO',
9318 g_user_id,
9319 g_login_id,
9320 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
9321
9322 IF (g_level_procedure >= g_current_runtime_level) THEN
9323 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9324 p_data => l_msg_data);
9325 fnd_log.string(g_level_procedure,
9326 g_module_name || l_api_name,
9327 'Parameters: ' || ' Interface_Id: ' ||
9328 bank_account_dtls_rec.bank_account_interface_id ||
9329 ' Update bank end date: ' || l_msg_data);
9330 END IF;
9331 END IF;
9332 fnd_file.put_line(fnd_file.log,
9333 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9334 ' failed in iby_ext_bankacct_pub.create_ext_bank_acct' ||
9335 ' Interface_Id: ' ||
9336 bank_account_dtls_rec.bank_account_interface_id ||
9337 ', No. of Messages: ' || l_msg_count ||
9338 ', Message: ' || l_msg_data);
9339 GOTO continue_next_record;
9340 END IF;
9341
9342 -- END IF;
9343
9344 fnd_file.put_line(fnd_file.log,
9345 ' Message: Updating account id :' || l_account_id);
9346 -- Update the interface table with the
9347 -- account_id that is obtained
9348 UPDATE pos_bank_account_det_int
9349 SET bank_account_id = l_account_id
9350 WHERE bank_account_interface_id =
9351 bank_account_dtls_rec.bank_account_interface_id
9352 AND batch_id = p_batch_id;
9353
9354 -- Update the interface table with the bank_id and branch_id that are obtained
9355 UPDATE pos_bank_accnt_owners_int
9356 SET bank_id = l_bank_id,
9357 branch_id = l_branch_id,
9358 account_id = l_account_id
9359 WHERE bank_account_interface_id =
9360 bank_account_dtls_rec.bank_account_interface_id
9361 AND batch_id = p_batch_id;
9362
9363 -- Create the intermediary accounts
9364 IF (bank_account_dtls_rec.inter_account1_country_code IS NOT NULL OR
9365 bank_account_dtls_rec.inter_account1_bank_name IS NOT NULL OR
9366 bank_account_dtls_rec.inter_account1_city IS NOT NULL OR
9367 bank_account_dtls_rec.inter_account1_bank_code IS NOT NULL OR
9368 bank_account_dtls_rec.inter_account1_branch_number IS NOT NULL OR
9369 bank_account_dtls_rec.inter_account1_bic IS NOT NULL OR
9370 bank_account_dtls_rec.inter_account1_number IS NOT NULL OR
9371 bank_account_dtls_rec.inter_account1_check_digits IS NOT NULL OR
9372 bank_account_dtls_rec.inter_account1_iban IS NOT NULL OR
9373 bank_account_dtls_rec.inter_account1_comments IS NOT NULL) THEN
9374
9375 l_new_intermed_acct1_rec.bank_account_id := l_account_id;
9376 l_new_intermed_acct1_rec.country_code := bank_account_dtls_rec.inter_account1_country_code;
9377 l_new_intermed_acct1_rec.bank_name := bank_account_dtls_rec.inter_account1_bank_name;
9378 l_new_intermed_acct1_rec.city := bank_account_dtls_rec.inter_account1_city;
9379 l_new_intermed_acct1_rec.bank_code := bank_account_dtls_rec.inter_account1_bank_code;
9380 l_new_intermed_acct1_rec.branch_number := bank_account_dtls_rec.inter_account1_branch_number;
9381 l_new_intermed_acct1_rec.bic := bank_account_dtls_rec.inter_account1_bic;
9382 l_new_intermed_acct1_rec.account_number := bank_account_dtls_rec.inter_account1_number;
9383 l_new_intermed_acct1_rec.check_digits := bank_account_dtls_rec.inter_account1_check_digits;
9384 l_new_intermed_acct1_rec.iban := bank_account_dtls_rec.inter_account1_iban;
9385 l_new_intermed_acct1_rec.comments := bank_account_dtls_rec.inter_account1_comments;
9386
9387 BEGIN
9388 -- Get the id of the intermediary account 1
9389 SELECT intermediary_acct_id,
9390 country_code,
9391 bank_name,
9392 city,
9393 bank_code,
9394 branch_number,
9395 bic,
9396 account_number,
9397 check_digits,
9398 iban,
9399 object_version_number
9400 INTO l_new_intermed_acct1_rec.intermediary_acct_id,
9401 l_new_intermed_acct1_rec.country_code,
9402 l_new_intermed_acct1_rec.bank_name,
9403 l_new_intermed_acct1_rec.city,
9404 l_new_intermed_acct1_rec.bank_code,
9405 l_new_intermed_acct1_rec.branch_number,
9406 l_new_intermed_acct1_rec.bic,
9407 l_new_intermed_acct1_rec.account_number,
9408 l_new_intermed_acct1_rec.check_digits,
9409 l_new_intermed_acct1_rec.iban,
9410 l_new_intermed_acct1_rec.object_version_number
9411 FROM (SELECT intermediary_acct_id intermediary_acct_id,
9412 nvl(l_new_intermed_acct1_rec.country_code,
9413 country_code) country_code,
9414 nvl(l_new_intermed_acct1_rec.bank_name, bank_name) bank_name,
9415 nvl(l_new_intermed_acct1_rec.city, city) city,
9416 nvl(l_new_intermed_acct1_rec.bank_code, bank_code) bank_code,
9417 nvl(l_new_intermed_acct1_rec.branch_number,
9418 branch_number) branch_number,
9419 nvl(l_new_intermed_acct1_rec.bic, bic) bic,
9420 nvl(l_new_intermed_acct1_rec.account_number,
9421 account_number) account_number,
9422 nvl(l_new_intermed_acct1_rec.check_digits,
9423 check_digits) check_digits,
9424 nvl(l_new_intermed_acct1_rec.iban, iban) iban,
9425 object_version_number,
9426 dense_rank() over(ORDER BY intermediary_acct_id) rnk
9427 FROM iby_intermediary_accts
9428 WHERE bank_acct_id = l_account_id)
9429 WHERE rnk = 1;
9430
9431 EXCEPTION
9432 WHEN OTHERS THEN
9433 l_new_intermed_acct1_rec.intermediary_acct_id := NULL;
9434 END;
9435
9436 fnd_file.put_line(fnd_file.log,
9437 ' Message: Intermediary account id : ' ||
9438 l_new_intermed_acct1_rec.intermediary_acct_id ||
9439 ' l_new_intermed_acct1_rec.city : ' ||
9440 l_new_intermed_acct1_rec.city);
9441
9442 IF (l_new_intermed_acct1_rec.intermediary_acct_id IS NULL) THEN
9443 fnd_file.put_line(fnd_file.log,
9444 ' Message: Going for intermediary account1 creation ');
9445 iby_ext_bankacct_pub.create_intermediary_acct(p_api_version => 1.0,
9446 p_init_msg_list => fnd_api.g_true,
9447 p_intermed_acct_rec => l_new_intermed_acct1_rec,
9448 x_intermediary_acct_id => l_intermediary1_acct_id,
9449 x_return_status => l_ret_status,
9450 x_msg_count => l_msg_count,
9451 x_msg_data => l_msg_data,
9452 x_response => l_add_intermed_account1_resp);
9453
9454 x_return_status := l_ret_status;
9455 x_msg_count := l_msg_count;
9456 x_msg_data := l_msg_data;
9457 ELSE
9458 fnd_file.put_line(fnd_file.log,
9459 ' Message: Going for intermediary account1 update ');
9460
9461 iby_ext_bankacct_pub.update_intermediary_acct(p_api_version => 1.0,
9462 p_init_msg_list => fnd_api.g_true,
9463 p_intermed_acct_rec => l_new_intermed_acct1_rec,
9464 x_return_status => l_ret_status,
9465 x_msg_count => l_msg_count,
9466 x_msg_data => l_msg_data,
9467 x_response => l_add_intermed_account1_resp);
9468
9469 x_return_status := l_ret_status;
9470 x_msg_count := l_msg_count;
9471 x_msg_data := l_msg_data;
9472 END IF;
9473
9474 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
9475 UPDATE pos_bank_account_det_int
9476 SET interface_status = 'REJECTED'
9477 WHERE bank_account_interface_id =
9478 bank_account_dtls_rec.bank_account_interface_id
9479 AND batch_id = p_batch_id;
9480
9481 IF (insert_rejections(p_batch_id,
9482 l_request_id,
9483 'POS_BANK_ACCOUNT_DET_INT',
9484 bank_account_dtls_rec.bank_account_interface_id,
9485 'POS_FAILED_INTERMEDIARY_ACCT',
9486 g_user_id,
9487 g_login_id,
9488 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
9489
9490 IF (g_level_procedure >= g_current_runtime_level) THEN
9491 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9492 p_data => l_msg_data);
9493 fnd_log.string(g_level_procedure,
9494 g_module_name || l_api_name,
9495 'Parameters: ' || ' Interface_Id: ' ||
9496 bank_account_dtls_rec.bank_account_interface_id ||
9497 ' Update bank end date: ' || l_msg_data);
9498 END IF;
9499 END IF;
9500 fnd_file.put_line(fnd_file.log,
9501 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9502 ' failed in iby_ext_bankacct_pub.create/update_intermediary_acct 1' ||
9503 ' Interface_Id: ' ||
9504 bank_account_dtls_rec.bank_account_interface_id ||
9505 ', No. of Messages: ' || l_msg_count ||
9506 ', Message: ' || l_msg_data);
9507 GOTO continue_next_record;
9508 END IF;
9509 END IF;
9510
9511 IF (bank_account_dtls_rec.inter_account2_country_code IS NOT NULL OR
9512 bank_account_dtls_rec.inter_account2_bank_name IS NOT NULL OR
9513 bank_account_dtls_rec.inter_account2_city IS NOT NULL OR
9514 bank_account_dtls_rec.inter_account2_bank_code IS NOT NULL OR
9515 bank_account_dtls_rec.inter_account2_branch_number IS NOT NULL OR
9516 bank_account_dtls_rec.inter_account2_bic IS NOT NULL OR
9517 bank_account_dtls_rec.inter_account2_number IS NOT NULL OR
9518 bank_account_dtls_rec.inter_account2_check_digits IS NOT NULL OR
9519 bank_account_dtls_rec.inter_account2_iban IS NOT NULL OR
9520 bank_account_dtls_rec.inter_account2_comments IS NOT NULL) THEN
9521
9522 l_new_intermed_acct2_rec.bank_account_id := l_account_id;
9523 l_new_intermed_acct2_rec.country_code := bank_account_dtls_rec.inter_account2_country_code;
9524 l_new_intermed_acct2_rec.bank_name := bank_account_dtls_rec.inter_account2_bank_name;
9525 l_new_intermed_acct2_rec.city := bank_account_dtls_rec.inter_account2_city;
9526 l_new_intermed_acct2_rec.bank_code := bank_account_dtls_rec.inter_account2_bank_code;
9527 l_new_intermed_acct2_rec.branch_number := bank_account_dtls_rec.inter_account2_branch_number;
9528 l_new_intermed_acct2_rec.bic := bank_account_dtls_rec.inter_account2_bic;
9529 l_new_intermed_acct2_rec.account_number := bank_account_dtls_rec.inter_account2_number;
9530 l_new_intermed_acct2_rec.check_digits := bank_account_dtls_rec.inter_account2_check_digits;
9531 l_new_intermed_acct2_rec.iban := bank_account_dtls_rec.inter_account2_iban;
9532 l_new_intermed_acct2_rec.comments := bank_account_dtls_rec.inter_account2_comments;
9533
9534 BEGIN
9535 -- Get the id of the intermediary account 2
9536 SELECT intermediary_acct_id,
9537 country_code,
9538 bank_name,
9539 city,
9540 bank_code,
9541 branch_number,
9542 bic,
9543 account_number,
9544 check_digits,
9545 iban,
9546 object_version_number
9547 INTO l_new_intermed_acct2_rec.intermediary_acct_id,
9548 l_new_intermed_acct2_rec.country_code,
9549 l_new_intermed_acct2_rec.bank_name,
9550 l_new_intermed_acct2_rec.city,
9551 l_new_intermed_acct2_rec.bank_code,
9552 l_new_intermed_acct2_rec.branch_number,
9553 l_new_intermed_acct2_rec.bic,
9554 l_new_intermed_acct2_rec.account_number,
9555 l_new_intermed_acct2_rec.check_digits,
9556 l_new_intermed_acct2_rec.iban,
9557 l_new_intermed_acct2_rec.object_version_number
9558 FROM (SELECT intermediary_acct_id intermediary_acct_id,
9559 nvl(l_new_intermed_acct2_rec.country_code,
9560 country_code) country_code,
9561 nvl(l_new_intermed_acct2_rec.bank_name, bank_name) bank_name,
9562 nvl(l_new_intermed_acct2_rec.city, city) city,
9563 nvl(l_new_intermed_acct2_rec.bank_code, bank_code) bank_code,
9564 nvl(l_new_intermed_acct2_rec.branch_number,
9565 branch_number) branch_number,
9566 nvl(l_new_intermed_acct2_rec.bic, bic) bic,
9567 nvl(l_new_intermed_acct2_rec.account_number,
9568 account_number) account_number,
9569 nvl(l_new_intermed_acct2_rec.check_digits,
9570 check_digits) check_digits,
9571 nvl(l_new_intermed_acct2_rec.iban, iban) iban,
9572 object_version_number,
9573 dense_rank() over(ORDER BY intermediary_acct_id) rnk
9574 FROM iby_intermediary_accts
9575 WHERE bank_acct_id = l_account_id)
9576 WHERE rnk = 2;
9577
9578 EXCEPTION
9579 WHEN OTHERS THEN
9580 l_new_intermed_acct2_rec.intermediary_acct_id := NULL;
9581 END;
9582 fnd_file.put_line(fnd_file.log,
9583 ' Message: Intermediary account id : ' ||
9584 l_new_intermed_acct2_rec.intermediary_acct_id);
9585
9586 IF (l_new_intermed_acct2_rec.intermediary_acct_id IS NULL) THEN
9587 fnd_file.put_line(fnd_file.log,
9588 ' Message: Going for intermediary account2 creation ');
9589 iby_ext_bankacct_pub.create_intermediary_acct(p_api_version => 1.0,
9590 p_init_msg_list => fnd_api.g_true,
9591 p_intermed_acct_rec => l_new_intermed_acct2_rec,
9592 x_intermediary_acct_id => l_intermediary2_acct_id,
9593 x_return_status => l_ret_status,
9594 x_msg_count => l_msg_count,
9595 x_msg_data => l_msg_data,
9596 x_response => l_add_intermed_account1_resp);
9597
9598 x_return_status := l_ret_status;
9599 x_msg_count := l_msg_count;
9600 x_msg_data := l_msg_data;
9601 ELSE
9602 fnd_file.put_line(fnd_file.log,
9603 ' Message: Going for intermediary account2 update ');
9604
9605 iby_ext_bankacct_pub.update_intermediary_acct(p_api_version => 1.0,
9606 p_init_msg_list => fnd_api.g_true,
9607 p_intermed_acct_rec => l_new_intermed_acct2_rec,
9608 x_return_status => l_ret_status,
9609 x_msg_count => l_msg_count,
9610 x_msg_data => l_msg_data,
9611 x_response => l_add_intermed_account1_resp);
9612
9613 x_return_status := l_ret_status;
9614 x_msg_count := l_msg_count;
9615 x_msg_data := l_msg_data;
9616 END IF;
9617
9618 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
9619 UPDATE pos_bank_account_det_int
9620 SET interface_status = 'REJECTED'
9621 WHERE bank_account_interface_id =
9622 bank_account_dtls_rec.bank_account_interface_id
9623 AND batch_id = p_batch_id;
9624
9625 IF (insert_rejections(p_batch_id,
9626 l_request_id,
9627 'POS_BANK_ACCOUNT_DET_INT',
9628 bank_account_dtls_rec.bank_account_interface_id,
9629 'POS_FAILED_INTERMEDIARY_ACCT2',
9630 g_user_id,
9631 g_login_id,
9632 'IMPORT_VENDOR_BANK_DTLS') <> TRUE) THEN
9633
9634 IF (g_level_procedure >= g_current_runtime_level) THEN
9635 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9636 p_data => l_msg_data);
9637 fnd_log.string(g_level_procedure,
9638 g_module_name || l_api_name,
9639 'Parameters: ' || ' Interface_Id: ' ||
9640 bank_account_dtls_rec.bank_account_interface_id ||
9641 ' Update bank end date: ' || l_msg_data);
9642 END IF;
9643 END IF;
9644 fnd_file.put_line(fnd_file.log,
9645 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9646 ' failed in iby_ext_bankacct_pub.create/update_intermediary_acct 2' ||
9647 ' Interface_Id: ' ||
9648 bank_account_dtls_rec.bank_account_interface_id ||
9649 ', No. of Messages: ' || l_msg_count ||
9650 ', Message: ' || l_msg_data);
9651 GOTO continue_next_record;
9652 END IF;
9653 END IF;
9654
9655 UPDATE pos_bank_account_det_int
9656 SET interface_status = 'PROCESSED'
9657 WHERE bank_account_interface_id =
9658 bank_account_dtls_rec.bank_account_interface_id
9659 AND batch_id = p_batch_id;
9660
9661 IF (bank_account_dtls_rec.insert_update_flag = 'I') THEN
9662 UPDATE pos_imp_batch_summary
9663 SET total_records_imported = total_records_imported + 1,
9664 total_inserts = total_inserts + 1,
9665 bank_detls_inserted = bank_detls_inserted + 1,
9666 bank_detls_imported = bank_detls_imported + 1
9667 WHERE batch_id = p_batch_id;
9668 ELSE
9669 UPDATE pos_imp_batch_summary
9670 SET total_records_imported = total_records_imported + 1,
9671 total_updates = total_updates + 1,
9672 bank_detls_updated = bank_detls_updated + 1,
9673 bank_detls_imported = bank_detls_imported + 1
9674 WHERE batch_id = p_batch_id;
9675 END IF;
9676
9677 <<continue_next_record>>
9678 NULL;
9679 END LOOP;
9680
9681 CLOSE bank_account_dtls_cur;
9682
9683 -- now process the account owners
9684 fnd_file.put_line(fnd_file.log, ' Message: Processing Account owners ');
9685
9686 OPEN account_owners_cur;
9687 LOOP
9688 -- Fetch the cursor data into a record
9689 FETCH account_owners_cur
9690 INTO account_owners_rec;
9691 EXIT WHEN account_owners_cur%NOTFOUND;
9692
9693 -- Initializing
9694 fnd_file.put_line(fnd_file.log,
9695 ' Message: Initializing local variables ');
9696 fnd_file.put_line(fnd_file.log,
9697 ' account_owners_rec.account_owner_name: ' ||
9698 account_owners_rec.account_owner_name);
9699 l_account_owner_id := NULL;
9700 l_account_id := NULL;
9701 l_joint_account_owner_id := NULL;
9702
9703 IF account_owners_rec.account_owner_party_id IS NULL THEN
9704 IF account_owners_rec.account_owner_name IS NOT NULL THEN
9705 SELECT party_id
9706 INTO l_account_owner_id
9707 FROM hz_parties
9708 WHERE party_name = account_owners_rec.account_owner_name
9709 AND rownum = 1;
9710 ELSE
9711 l_account_owner_id := get_party_id(account_owners_rec.source_system,
9712 account_owners_rec.source_system_reference);
9713 END IF;
9714 ELSE
9715 l_account_owner_id := account_owners_rec.account_owner_party_id;
9716 END IF;
9717
9718 fnd_file.put_line(fnd_file.log,
9719 ' l_account_owner_id: ' || l_account_owner_id);
9720
9721 -- Bug 12842286: Handle the exception if acount id is not found. Failing to create a bank account will cause this issue.
9722 BEGIN
9723 IF (account_owners_rec.account_id IS NULL) THEN
9724 SELECT ext_bank_account_id
9725 INTO l_account_id
9726 FROM iby_ext_bank_accounts_v
9727 WHERE country_code = account_owners_rec.bank_country_code
9728 AND bank_name = account_owners_rec.bank_name
9729 AND (bank_number = account_owners_rec.bank_number OR
9730 account_owners_rec.bank_number IS NULL)
9731 AND bank_branch_name = account_owners_rec.branch_name
9732 AND (branch_number = account_owners_rec.branch_number OR
9733 account_owners_rec.branch_number IS NULL)
9734 AND bank_account_num_electronic =
9735 account_owners_rec.account_number;
9736 ELSE
9737 l_account_id := account_owners_rec.account_id;
9738 END IF;
9739
9740 fnd_file.put_line(fnd_file.log, ' l_account_id: ' || l_account_id);
9741
9742 EXCEPTION
9743 WHEN OTHERS THEN
9744 UPDATE pos_bank_accnt_owners_int
9745 SET interface_status = 'REJECTED'
9746 WHERE bank_acct_owner_interface_id =
9747 account_owners_rec.bank_acct_owner_interface_id
9748 AND batch_id = p_batch_id;
9749
9750 IF (insert_rejections(p_batch_id,
9751 l_request_id,
9752 'POS_BANK_ACCNT_OWNERS_INT',
9753 bank_account_dtls_rec.bank_account_interface_id,
9754 'POS_ADD_ACCT_OWNER',
9755 g_user_id,
9756 g_login_id,
9757 'import_vendor_bank_dtls') <> TRUE) THEN
9758
9759 IF (g_level_procedure >= g_current_runtime_level) THEN
9760 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9761 p_data => l_msg_data);
9762 fnd_log.string(g_level_procedure,
9763 g_module_name || l_api_name,
9764 'Parameters: ' || ' Interface_Id: ' ||
9765 bank_account_dtls_rec.bank_account_interface_id ||
9766 ' get account owner id Msg: ' || l_msg_data);
9767 END IF;
9768 END IF;
9769 fnd_file.put_line(fnd_file.log,
9770 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9771 ' failed to find account id' ||
9772 ' bank_acct_owner_interface_id: ' ||
9773 account_owners_rec.bank_acct_owner_interface_id ||
9774 ', No. of Messages: ' || l_msg_count ||
9775 ', Message: ' || l_msg_data);
9776 --fnd_file.put_line(fnd_file.log, ' l_account_id: ' || SQLCODE || ' ' || SQLERRM );
9777 GOTO continue_next_owner;
9778 END;
9779 -- End Bug 12842286
9780
9781 -- Call the add account owner API
9782 iby_ext_bankacct_pub.add_joint_account_owner(p_api_version => 1.0,
9783 p_init_msg_list => fnd_api.g_true,
9784 p_bank_account_id => l_account_id,
9785 p_acct_owner_party_id => l_account_owner_id,
9786 x_joint_acct_owner_id => l_joint_account_owner_id,
9787 x_return_status => l_ret_status,
9788 x_msg_count => l_msg_count,
9789 x_msg_data => l_msg_data,
9790 x_response => l_add_account_owner_resp);
9791
9792 x_return_status := l_ret_status;
9793 x_msg_count := l_msg_count;
9794 x_msg_data := l_msg_data;
9795
9796 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
9797
9798 UPDATE pos_bank_accnt_owners_int
9799 SET interface_status = 'REJECTED'
9800 WHERE bank_acct_owner_interface_id =
9801 account_owners_rec.bank_acct_owner_interface_id
9802 AND batch_id = p_batch_id;
9803
9804 IF (insert_rejections(p_batch_id,
9805 l_request_id,
9806 'POS_BANK_ACCNT_OWNERS_INT',
9807 bank_account_dtls_rec.bank_account_interface_id,
9808 'POS_ADD_ACCT_OWNER',
9809 g_user_id,
9810 g_login_id,
9811 'import_vendor_bank_dtls') <> TRUE) THEN
9812
9813 IF (g_level_procedure >= g_current_runtime_level) THEN
9814 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9815 p_data => l_msg_data);
9816 fnd_log.string(g_level_procedure,
9817 g_module_name || l_api_name,
9818 'Parameters: ' || ' Interface_Id: ' ||
9819 bank_account_dtls_rec.bank_account_interface_id ||
9820 ' add account owner Msg: ' || l_msg_data);
9821 END IF;
9822 END IF;
9823 fnd_file.put_line(fnd_file.log,
9824 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9825 ' failed in iby_ext_bankacct_pub.add_joint_account_owner' ||
9826 ' bank_acct_owner_interface_id: ' ||
9827 account_owners_rec.bank_acct_owner_interface_id ||
9828 ', No. of Messages: ' || l_msg_count ||
9829 ', Message: ' || l_msg_data);
9830 GOTO continue_next_owner;
9831 END IF;
9832
9833 -- Set the end date if entered
9834 IF account_owners_rec.end_date IS NOT NULL THEN
9835
9836 IF l_joint_account_owner_id IS NULL THEN
9837 -- get the account owner id
9838 SELECT account_owner_id,
9839 object_version_number
9840 INTO l_joint_account_owner_id,
9841 l_obj_version
9842 FROM iby_account_owners
9843 WHERE ext_bank_account_id = l_account_id
9844 AND account_owner_party_id = l_account_owner_id;
9845 ELSE
9846 SELECT object_version_number
9847 INTO l_obj_version
9848 FROM iby_account_owners
9849 WHERE ext_bank_account_id = l_account_id
9850 AND account_owner_party_id = l_account_owner_id;
9851 END IF;
9852
9853 iby_ext_bankacct_pub.set_joint_acct_owner_end_date(p_api_version => 1.0,
9854 p_init_msg_list => fnd_api.g_true,
9855 p_acct_owner_id => l_joint_account_owner_id,
9856 p_end_date => account_owners_rec.end_date,
9857 p_object_version_number => l_obj_version,
9858 x_return_status => l_ret_status,
9859 x_msg_count => l_msg_count,
9860 x_msg_data => l_msg_data,
9861 x_response => l_set_end_date_resp);
9862
9863 x_return_status := l_ret_status;
9864 x_msg_count := l_msg_count;
9865 x_msg_data := l_msg_data;
9866
9867 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
9868
9869 UPDATE pos_bank_accnt_owners_int
9870 SET interface_status = 'REJECTED'
9871 WHERE bank_acct_owner_interface_id =
9872 account_owners_rec.bank_acct_owner_interface_id
9873 AND batch_id = p_batch_id;
9874
9875 IF (insert_rejections(p_batch_id,
9876 l_request_id,
9877 'POS_BANK_ACCNT_OWNERS_INT',
9878 bank_account_dtls_rec.bank_account_interface_id,
9879 'POS_ADD_ACCT_OWNER',
9880 g_user_id,
9881 g_login_id,
9882 'import_vendor_bank_dtls') <> TRUE) THEN
9883
9884 IF (g_level_procedure >= g_current_runtime_level) THEN
9885 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9886 p_data => l_msg_data);
9887 fnd_log.string(g_level_procedure,
9888 g_module_name || l_api_name,
9889 'Parameters: ' || ' Interface_Id: ' ||
9890 bank_account_dtls_rec.bank_account_interface_id ||
9891 ' get account owner id Msg: ' || l_msg_data);
9892 END IF;
9893 END IF;
9894 fnd_file.put_line(fnd_file.log,
9895 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9896 ' failed in iby_ext_bankacct_pub.set_joint_acct_owner_end_date' ||
9897 ' bank_acct_owner_interface_id: ' ||
9898 account_owners_rec.bank_acct_owner_interface_id ||
9899 ', No. of Messages: ' || l_msg_count ||
9900 ', Message: ' || l_msg_data);
9901 GOTO continue_next_owner;
9902 END IF;
9903 END IF;
9904
9905 -- Set the primary flag
9906 IF (account_owners_rec.primary_flag IS NOT NULL) THEN
9907 iby_ext_bankacct_pub.change_primary_acct_owner(p_api_version => 1.0,
9908 p_init_msg_list => fnd_api.g_true,
9909 p_bank_acct_id => l_account_id,
9910 p_acct_owner_party_id => l_account_owner_id,
9911 x_return_status => l_ret_status,
9912 x_msg_count => l_msg_count,
9913 x_msg_data => l_msg_data,
9914 x_response => l_set_primary_flag_resp);
9915
9916 x_return_status := l_ret_status;
9917 x_msg_count := l_msg_count;
9918 x_msg_data := l_msg_data;
9919
9920 IF l_ret_status <> fnd_api.g_ret_sts_success THEN
9921
9922 UPDATE pos_bank_accnt_owners_int
9923 SET interface_status = 'REJECTED'
9924 WHERE bank_acct_owner_interface_id =
9925 account_owners_rec.bank_acct_owner_interface_id
9926 AND batch_id = p_batch_id;
9927
9928 IF (insert_rejections(p_batch_id,
9929 l_request_id,
9930 'POS_BANK_ACCNT_OWNERS_INT',
9931 bank_account_dtls_rec.bank_account_interface_id,
9932 'POS_PRIMARY_FLAG_NOTSET',
9933 g_user_id,
9934 g_login_id,
9935 'import_vendor_bank_dtls') <> TRUE) THEN
9936
9937 IF (g_level_procedure >= g_current_runtime_level) THEN
9938 fnd_msg_pub.count_and_get(p_count => l_msg_count,
9939 p_data => l_msg_data);
9940 fnd_log.string(g_level_procedure,
9941 g_module_name || l_api_name,
9942 'Parameters: ' || ' Interface_Id: ' ||
9943 bank_account_dtls_rec.bank_account_interface_id ||
9944 ' Set primary flag Msg: ' || l_msg_data);
9945 END IF;
9946 END IF;
9947 fnd_file.put_line(fnd_file.log,
9948 ' Message: Inside PROCEDURE IMPORT_VENDOR_BANK_DTLS' ||
9949 ' failed in iby_ext_bankacct_pub.change_primary_acct_owner' ||
9950 ' bank_acct_owner_interface_id: ' ||
9951 account_owners_rec.bank_acct_owner_interface_id ||
9952 ', No. of Messages: ' || l_msg_count ||
9953 ', Message: ' || l_msg_data);
9954 GOTO continue_next_owner;
9955 END IF;
9956
9957 END IF;
9958
9959 UPDATE pos_bank_accnt_owners_int
9960 SET interface_status = 'PROCESSED'
9961 WHERE bank_acct_owner_interface_id =
9962 account_owners_rec.bank_acct_owner_interface_id
9963 AND batch_id = p_batch_id;
9964
9965 UPDATE pos_imp_batch_summary
9966 SET total_records_imported = total_records_imported + 1,
9967 total_inserts = total_inserts + 1,
9968 bank_detls_inserted = bank_detls_inserted + 1,
9969 bank_detls_imported = bank_detls_imported + 1
9970 WHERE batch_id = p_batch_id;
9971
9972 <<continue_next_owner>>
9973 NULL;
9974 END LOOP;
9975
9976 CLOSE account_owners_cur;
9977
9978 EXCEPTION
9979 WHEN OTHERS THEN
9980 x_return_status := fnd_api.g_ret_sts_unexp_error;
9981
9982 fnd_msg_pub.count_and_get(p_count => x_msg_count,
9983 p_data => x_msg_data);
9984 fnd_file.put_line(fnd_file.log,
9985 ' Inside import_vendor_bank_dtls EXCEPTION ' ||
9986 ' Message: ' || SQLCODE || ' ' || SQLERRM);
9987 END import_vendor_bank_dtls;
9988
9989 PROCEDURE import_batch
9990 (
9991 errbuf OUT NOCOPY VARCHAR2,
9992 retcode OUT NOCOPY VARCHAR2,
9993 p_batch_id IN NUMBER,
9994 p_import_run_option IN VARCHAR2,
9995 p_run_batch_dedup IN VARCHAR2,
9996 p_batch_dedup_rule_id IN NUMBER,
9997 p_batch_dedup_action IN VARCHAR2,
9998 p_run_addr_val IN VARCHAR2,
9999 p_run_registry_dedup IN VARCHAR2,
10000 p_registry_dedup_rule_id IN NUMBER,
10001 p_run_automerge IN VARCHAR2 := 'N',
10002 p_generate_fuzzy_key IN VARCHAR2 := 'Y',
10003 p_import_uda_only IN VARCHAR2 := 'N' --Bug 12747017
10004 ) AS
10005 l_request_id NUMBER := fnd_global.conc_request_id;
10006
10007 l_errbuf VARCHAR2(4000);
10008 l_retcode VARCHAR2(10);
10009 l_batch_status hz_imp_batch_summary.batch_status%TYPE;
10010 l_import_status hz_imp_batch_summary.import_status%TYPE;
10011 l_main_conc_status hz_imp_batch_summary.main_conc_status%TYPE;
10012 l_import_run_option VARCHAR2(20);
10013 l_what_if_flag VARCHAR2(10);
10014
10015 l_return_status VARCHAR2(2000);
10016 l_msg_count NUMBER;
10017 l_msg_data VARCHAR2(2000);
10018
10019 l_error_count NUMBER := 0;
10020 l_tot_err_count NUMBER := 0;
10021 ---UDA Import
10022 l_uda_imported_count NUMBER := 0;
10023
10024 BEGIN
10025 fnd_msg_pub.initialize;
10026
10027 fnd_file.put_line(fnd_file.log,
10028 ' Message: Inside PROCEDURE IMPORT_BATCH' ||
10029 ' Parameters: ' || ' p_batch_id: ' || p_batch_id ||
10030 ' p_import_run_option: ' || p_import_run_option ||
10031 ' p_run_batch_dedup: ' || p_run_batch_dedup ||
10032 ' p_run_registry_dedup: ' || p_run_registry_dedup);
10033
10034 IF (g_level_procedure >= g_current_runtime_level) THEN
10035 fnd_log.string(g_level_procedure,
10036 g_module_name || 'IMPORT_BATCH',
10037 'Parameters: ' || ' p_batch_id: ' || p_batch_id ||
10038 ' Message: Inside PROCEDURE import_batch');
10039 END IF;
10040
10041 --Bug 12747017
10042 IF (p_import_uda_only = 'N') THEN
10043
10044 /*IF (p_import_run_option <> 'CONTINUE') THEN*/
10045 -- set the processing status appropriately
10046 UPDATE pos_imp_batch_summary
10047 SET import_status = 'PROCESSING',
10048 main_conc_status = 'PROCESSING',
10049 batch_status = 'PROCESSING',
10050 import_req_id = l_request_id
10051 /*,main_conc_req_id = l_request_id*/
10052 WHERE batch_id = p_batch_id;
10053
10054 pre_processing(p_batch_id => p_batch_id,
10055 x_return_status => l_return_status,
10056 x_msg_count => l_msg_count,
10057 x_msg_data => l_msg_data);
10058
10059 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10060 fnd_file.put_line(fnd_file.log,
10061 'UIC***** No. of Messages: ' || l_msg_count ||
10062 ', Message: ' || l_msg_data ||
10063 ' From pre_processing API.');
10064 errbuf := 'WARNING****** Unexpected error occured in pre_processing.';
10065 retcode := 1;
10066
10067 UPDATE pos_imp_batch_summary
10068 SET import_status = 'COMPL_ERRORS',
10069 main_conc_status = 'COMPLETED',
10070 batch_status = 'ACTION_REQUIRED'
10071 WHERE batch_id = p_batch_id;
10072
10073 UPDATE hz_imp_batch_summary
10074 SET what_if_flag = decode(p_import_run_option, 'WHAT_IF', 'Y', 'N')
10075 WHERE batch_id = p_batch_id;
10076
10077 RETURN;
10078 END IF;
10079 /*ELSE
10080 fnd_file.put_line(fnd_file.log,
10081 ' Message: Inside PROCEDURE IMPORT_BATCH' ||
10082 ' p_import_run_option = CONTINUE');
10083
10084 UPDATE pos_imp_batch_summary
10085 SET import_status = 'PENDING',
10086 main_conc_status = 'PENDING',
10087 batch_status = 'PROCESSING',
10088 import_req_id = l_request_id
10089 WHERE batch_id = p_batch_id;
10090 END IF;*/
10091
10092 IF (p_run_batch_dedup = 'N' AND p_run_registry_dedup = 'N') THEN
10093 fnd_file.put_line(fnd_file.log,
10094 'After pre_processing Validate Supplier before party is created');
10095
10096 /* Validate Supplier before party is created */
10097 validate_vendor(p_batch_id => p_batch_id,
10098 x_return_status => l_return_status,
10099 x_msg_count => l_msg_count,
10100 x_msg_data => l_msg_data);
10101
10102 IF l_return_status <> fnd_api.g_ret_sts_success THEN
10103 fnd_file.put_line(fnd_file.log,
10104 'Error Message Count: ' || l_msg_count ||
10105 ' Error Message Data: ' || l_msg_data ||
10106 ' From validate_vendor API.');
10107
10108 UPDATE pos_imp_batch_summary
10109 SET import_status = 'PENDING',
10110 main_conc_status = 'COMPLETED',
10111 batch_status = 'PENDING'
10112 WHERE batch_id = p_batch_id;
10113
10114 UPDATE hz_imp_batch_summary
10115 SET import_status = 'COMPL_ERRORS',
10116 main_conc_status = 'COMPLETED',
10117 batch_status = 'ACTION_REQUIRED'
10118 WHERE batch_id = p_batch_id;
10119
10120 RETURN;
10121 END IF;
10122
10123 fnd_file.put_line(fnd_file.log, 'After Validate Supplier');
10124 ELSE
10125 fnd_file.put_line(fnd_file.log, 'After pre_processing');
10126 END IF;
10127
10128 BEGIN
10129 SELECT batch_status,
10130 import_status,
10131 what_if_flag
10132 INTO l_batch_status,
10133 l_import_status,
10134 l_what_if_flag
10135 FROM hz_imp_batch_summary
10136 WHERE batch_id = p_batch_id;
10137
10138 EXCEPTION
10139 WHEN no_data_found THEN
10140 l_batch_status := 'COMPLETED';
10141 END;
10142
10143 fnd_file.put_line(fnd_file.log,
10144 'l_batch_status : ' || l_batch_status ||
10145 ' l_import_status : ' || l_import_status);
10146
10147 IF (l_batch_status <> 'COMPLETED') THEN
10148 UPDATE pos_imp_batch_summary
10149 SET import_status = 'PENDING',
10150 main_conc_status = 'PENDING',
10151 batch_status = 'PROCESSING',
10152 import_req_id = l_request_id
10153 WHERE batch_id = p_batch_id;
10154
10155 /* If failed because of preprocessing and resubmitted then
10156 run option should go as COMPLETE */
10157 IF p_import_run_option = 'CONTINUE' THEN
10158 IF NOT (nvl(l_import_status, 'X') IN
10159 ('ACTION_REQUIRED', 'COMPL_ERROR_LIMIT', 'COMPL_ERRORS')) THEN
10160 IF (l_what_if_flag = 'N') THEN
10161 l_import_run_option := 'COMPLETE';
10162 ELSE
10163 l_import_run_option := 'WHAT_IF';
10164 END IF;
10165 ELSE
10166 l_import_run_option := p_import_run_option;
10167 END IF;
10168 ELSE
10169 l_import_run_option := p_import_run_option;
10170 END IF;
10171
10172 fnd_file.put_line(fnd_file.log,
10173 'l_import_run_option : ' || l_import_run_option);
10174
10175 /* Call HZ import API to import a party */
10176 hz_batch_import_pkg.import_batch(l_errbuf,
10177 l_retcode,
10178 p_batch_id,
10179 l_import_run_option,
10180 p_run_batch_dedup,
10181 p_batch_dedup_rule_id,
10182 p_batch_dedup_action,
10183 p_run_addr_val,
10184 p_run_registry_dedup,
10185 p_registry_dedup_rule_id,
10186 p_run_automerge,
10187 p_generate_fuzzy_key);
10188 errbuf := l_errbuf;
10189 retcode := l_retcode;
10190
10191 fnd_file.put_line(fnd_file.log,
10192 ' Message: Inside PROCEDURE IMPORT_BATCH' ||
10193 ' output parameters from hz_batch_import_pkg errbuf : ' ||
10194 errbuf || ' retcode : ' || retcode);
10195 END IF;
10196
10197 BEGIN
10198 SELECT batch_status,
10199 import_status,
10200 main_conc_status
10201 INTO l_batch_status,
10202 l_import_status,
10203 l_main_conc_status
10204 FROM hz_imp_batch_summary
10205 WHERE batch_id = p_batch_id;
10206
10207 EXCEPTION
10208 WHEN no_data_found THEN
10209 l_batch_status := 'NOT COMPLETED';
10210 END;
10211
10212 fnd_file.put_line(fnd_file.log, 'l_batch_status2 : ' || l_batch_status);
10213
10214 /*After the party import is completed enable the party
10215 as supplier and party contact as supplier contact*/
10216
10217 IF (l_batch_status = 'COMPLETED') THEN
10218 UPDATE hz_imp_batch_summary
10219 SET total_inserts = parties_inserted + addresses_inserted +
10220 addressuses_inserted + contactpoints_inserted +
10221 contacts_inserted + contactroles_inserted +
10222 codeassigns_inserted + relationships_inserted +
10223 creditratings_inserted + finreports_inserted +
10224 finnumbers_inserted,
10225 total_updates = parties_updated + addresses_updated +
10226 addressuses_updated + contactpoints_updated +
10227 contacts_updated + contactroles_updated +
10228 codeassigns_updated + relationships_updated +
10229 creditratings_updated + finreports_updated +
10230 finnumbers_updated
10231 WHERE batch_id = p_batch_id;
10232
10233 -- Set the processing status appropriately
10234 UPDATE pos_imp_batch_summary
10235 SET import_status = 'PROCESSING',
10236 main_conc_status = 'PROCESSING',
10237 batch_status = 'PROCESSING'
10238 WHERE batch_id = p_batch_id;
10239
10240 enable_party_as_supplier(p_batch_id => p_batch_id,
10241 x_return_status => l_return_status,
10242 x_msg_count => l_msg_count,
10243 x_msg_data => l_msg_data);
10244
10245 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10246 fnd_file.put_line(fnd_file.log,
10247 'UIC***** No. of Messages: ' || l_msg_count ||
10248 ', Message: ' || l_msg_data ||
10249 ' From enable_party_as_supplier API.');
10250 errbuf := 'WARNING****** Unexpected error occured in enabling party as supplier program.';
10251 retcode := 1;
10252
10253 UPDATE pos_imp_batch_summary
10254 SET import_status = 'COMPL_ERRORS',
10255 main_conc_status = 'COMPLETED',
10256 batch_status = 'ACTION_REQUIRED'
10257 WHERE batch_id = p_batch_id;
10258
10259 RETURN;
10260 END IF;
10261
10262 enable_partycont_as_suppcont(p_batch_id => p_batch_id,
10263 x_return_status => l_return_status,
10264 x_msg_count => l_msg_count,
10265 x_msg_data => l_msg_data);
10266
10267 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10268 fnd_file.put_line(fnd_file.log,
10269 'UIC***** No. of Messages: ' || l_msg_count ||
10270 ', Message: ' || l_msg_data ||
10271 ' From enable_partycont_as_suppcont API.');
10272 errbuf := 'WARNING****** Unexpected error occured in enabling party contact as supplier contact program.';
10273 retcode := 1;
10274 END IF;
10275
10276 update_party_id(p_batch_id => p_batch_id,
10277 x_return_status => l_return_status,
10278 x_msg_count => l_msg_count,
10279 x_msg_data => l_msg_data);
10280
10281 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10282 fnd_file.put_line(fnd_file.log,
10283 'UIC***** No. of Messages: ' || l_msg_count ||
10284 ', Message: ' || l_msg_data ||
10285 ' From update_party_id API.');
10286 errbuf := 'WARNING****** Unexpected error occured in update party id program.';
10287 retcode := 1;
10288 END IF;
10289
10290 import_vendors(p_batch_id => p_batch_id,
10291 x_return_status => l_return_status,
10292 x_msg_count => l_msg_count,
10293 x_msg_data => l_msg_data);
10294
10295 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10296 l_tot_err_count := l_tot_err_count + 1;
10297 fnd_file.put_line(fnd_file.log,
10298 'UIC***** No. of Messages: ' || l_msg_count ||
10299 ', Message: ' || l_msg_data ||
10300 ' From import_vendors API.');
10301 errbuf := 'WARNING****** Unexpected error occured in import vendors program.';
10302 retcode := 1;
10303 ELSE
10304 SELECT COUNT(1)
10305 INTO l_error_count
10306 FROM ap_suppliers_int
10307 WHERE sdh_batch_id = p_batch_id
10308 AND nvl(status, 'ACTIVE') = 'REJECTED'
10309 AND rownum = 1;
10310
10311 l_tot_err_count := l_tot_err_count + l_error_count;
10312 END IF;
10313
10314 update_party_site_id(p_batch_id => p_batch_id,
10315 x_return_status => l_return_status,
10316 x_msg_count => l_msg_count,
10317 x_msg_data => l_msg_data);
10318
10319 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10320 fnd_file.put_line(fnd_file.log,
10321 'UIC***** No. of Messages: ' || l_msg_count ||
10322 ', Message: ' || l_msg_data ||
10323 ' From update_party_id API.');
10324 errbuf := 'WARNING****** Unexpected error occured in update party id program.';
10325 retcode := 1;
10326 END IF;
10327
10328 import_vendor_sites(p_batch_id => p_batch_id,
10329 x_return_status => l_return_status,
10330 x_msg_count => l_msg_count,
10331 x_msg_data => l_msg_data);
10332
10333 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10334 l_tot_err_count := l_tot_err_count + 1;
10335 fnd_file.put_line(fnd_file.log,
10336 'UIC***** No. of Messages: ' || l_msg_count ||
10337 ', Message: ' || l_msg_data ||
10338 ' From import_vendor_sites API.');
10339 errbuf := 'WARNING****** Unexpected error occured in import vendor sites program.';
10340 retcode := 1;
10341 ELSE
10342 SELECT COUNT(1)
10343 INTO l_error_count
10344 FROM ap_supplier_sites_int
10345 WHERE sdh_batch_id = p_batch_id
10346 AND nvl(status, 'ACTIVE') = 'REJECTED'
10347 AND rownum = 1;
10348
10349 l_tot_err_count := l_tot_err_count + l_error_count;
10350 END IF;
10351
10352 update_contact_dtls(p_batch_id => p_batch_id,
10353 x_return_status => l_return_status,
10354 x_msg_count => l_msg_count,
10355 x_msg_data => l_msg_data);
10356
10357 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10358 fnd_file.put_line(fnd_file.log,
10359 'UIC***** No. of Messages: ' || l_msg_count ||
10360 ', Message: ' || l_msg_data ||
10361 ' From update_contact_dtls API.');
10362 errbuf := 'WARNING****** Unexpected error occured in update contact details program.';
10363 retcode := 1;
10364 END IF;
10365
10366 import_vendor_contacts(p_batch_id => p_batch_id,
10367 x_return_status => l_return_status,
10368 x_msg_count => l_msg_count,
10369 x_msg_data => l_msg_data);
10370
10371 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10372 l_tot_err_count := l_tot_err_count + 1;
10373 fnd_file.put_line(fnd_file.log,
10374 'UIC***** No. of Messages: ' || l_msg_count ||
10375 ', Message: ' || l_msg_data ||
10376 ' From import_vendor_contacts API.');
10377 errbuf := 'WARNING****** Unexpected error occured in import vendor contacts program.';
10378 retcode := 1;
10379 ELSE
10380 SELECT COUNT(1)
10381 INTO l_error_count
10382 FROM ap_sup_site_contact_int
10383 WHERE sdh_batch_id = p_batch_id
10384 AND nvl(status, 'ACTIVE') = 'REJECTED'
10385 AND rownum = 1;
10386
10387 l_tot_err_count := l_tot_err_count + l_error_count;
10388 END IF;
10389
10390 import_vendor_prods_services(p_batch_id => p_batch_id,
10391 x_return_status => l_return_status,
10392 x_msg_count => l_msg_count,
10393 x_msg_data => l_msg_data);
10394
10395 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10396 l_tot_err_count := l_tot_err_count + 1;
10397 fnd_file.put_line(fnd_file.log,
10398 'UIC***** No. of Messages: ' || l_msg_count ||
10399 ', Message: ' || l_msg_data ||
10400 ' From import_vendor_prods_services API.');
10401 errbuf := 'WARNING****** Unexpected error occured in import vendor contacts program.';
10402 retcode := 1;
10403 ELSE
10404 SELECT COUNT(1)
10405 INTO l_error_count
10406 FROM pos_product_service_int
10407 WHERE sdh_batch_id = p_batch_id
10408 AND nvl(status, 'ACTIVE') = 'REJECTED'
10409 AND rownum = 1;
10410
10411 l_tot_err_count := l_tot_err_count + l_error_count;
10412 END IF;
10413
10414 import_vendor_buss_class(p_batch_id => p_batch_id,
10415 x_return_status => l_return_status,
10416 x_msg_count => l_msg_count,
10417 x_msg_data => l_msg_data);
10418
10419 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10420 l_tot_err_count := l_tot_err_count + 1;
10421 fnd_file.put_line(fnd_file.log,
10422 'UIC***** No. of Messages: ' || l_msg_count ||
10423 ', Message: ' || l_msg_data ||
10424 ' From import_vendor_buss_class API.');
10425 errbuf := 'WARNING****** Unexpected error occured in import vendor contacts program.';
10426 retcode := 1;
10427 ELSE
10428 SELECT COUNT(1)
10429 INTO l_error_count
10430 FROM pos_business_class_int
10431 WHERE sdh_batch_id = p_batch_id
10432 AND nvl(status, 'ACTIVE') = 'REJECTED'
10433 AND rownum = 1;
10434
10435 l_tot_err_count := l_tot_err_count + l_error_count;
10436 END IF;
10437
10438 import_vendor_tax_dtls(p_batch_id => p_batch_id,
10439 x_return_status => l_return_status,
10440 x_msg_count => l_msg_count,
10441 x_msg_data => l_msg_data);
10442
10443 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10444 l_tot_err_count := l_tot_err_count + 1;
10445 fnd_file.put_line(fnd_file.log,
10446 'UIC***** No. of Messages: ' || l_msg_count ||
10447 ', Message: ' || l_msg_data ||
10448 ' From import_vendor_tax_dtls API.');
10449 errbuf := 'WARNING****** Unexpected error occured in import vendor contacts program.';
10450 retcode := 1;
10451 ELSE
10452 SELECT COUNT(1)
10453 INTO l_error_count
10454 FROM pos_party_tax_profile_int
10455 WHERE batch_id = p_batch_id
10456 AND nvl(status, 'ACTIVE') = 'REJECTED'
10457 AND rownum = 1;
10458
10459 l_tot_err_count := l_tot_err_count + l_error_count;
10460
10461 SELECT COUNT(1)
10462 INTO l_error_count
10463 FROM pos_party_tax_reg_int
10464 WHERE batch_id = p_batch_id
10465 AND nvl(status, 'ACTIVE') = 'REJECTED'
10466 AND rownum = 1;
10467
10468 l_tot_err_count := l_tot_err_count + l_error_count;
10469
10470 SELECT COUNT(1)
10471 INTO l_error_count
10472 FROM pos_fiscal_class_int
10473 WHERE batch_id = p_batch_id
10474 AND nvl(status, 'ACTIVE') = 'REJECTED'
10475 AND rownum = 1;
10476
10477 l_tot_err_count := l_tot_err_count + l_error_count;
10478 END IF;
10479
10480 import_vendor_bank_dtls(p_batch_id => p_batch_id,
10481 x_return_status => l_return_status,
10482 x_msg_count => l_msg_count,
10483 x_msg_data => l_msg_data);
10484
10485 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
10486 l_tot_err_count := l_tot_err_count + 1;
10487 fnd_file.put_line(fnd_file.log,
10488 'UIC***** No. of Messages: ' || l_msg_count ||
10489 ', Message: ' || l_msg_data ||
10490 ' From import_vendor_bank_dtls API.');
10491 errbuf := 'WARNING****** Unexpected error occured in import vendor contacts program.';
10492 retcode := 1;
10493 ELSE
10494 SELECT COUNT(1)
10495 INTO l_error_count
10496 FROM pos_bank_account_det_int
10497 WHERE batch_id = p_batch_id
10498 AND nvl(interface_status, 'ACTIVE') = 'REJECTED'
10499 AND rownum = 1;
10500
10501 l_tot_err_count := l_tot_err_count + l_error_count;
10502
10503 SELECT COUNT(1)
10504 INTO l_error_count
10505 FROM pos_bank_accnt_owners_int
10506 WHERE batch_id = p_batch_id
10507 AND nvl(interface_status, 'ACTIVE') = 'REJECTED'
10508 AND rownum = 1;
10509
10510 l_tot_err_count := l_tot_err_count + l_error_count;
10511 END IF;
10512
10513 ------UDA import
10514 POS_BULKLOAD_ENTITIES.PROCESS_USER_ATTRS_DATA(p_data_set_id => p_batch_id,
10515 ERRBUF => l_errbuf,
10516 RETCODE => L_RETCODE,
10517 P_PURGE_SUCCESSFUL_LINES => FND_API.G_FALSE);
10518
10519 IF (L_RETCODE <> FND_API.G_RET_STS_SUCCESS) THEN
10520 l_tot_err_count := l_tot_err_count + 1;
10521 fnd_file.put_line(fnd_file.log,
10522 'UIC***** No. of Messages: ' || L_RETCODE ||
10523 ', Message: ' || l_errbuf ||
10524 ' From POS_BULKLOAD_ENTITIES.PROCESS_USER_ATTRS_DATA API.');
10525 errbuf := 'WARNING****** Unexpected error occured in import UDA program.';
10526 retcode := 1;
10527 ELSE
10528 SELECT COUNT(1)
10529 INTO l_error_count
10530 FROM POS_SUPP_PROF_EXT_INTF
10531 WHERE BATCH_ID = P_BATCH_ID
10532 AND nvl(PROCESS_STATUS, 1) = 3;
10533
10534 SELECT COUNT(1)
10535 INTO l_uda_imported_count
10536 FROM POS_SUPP_PROF_EXT_INTF
10537 WHERE BATCH_ID = P_BATCH_ID
10538 AND NVL(PROCESS_STATUS, 1) = 4;
10539
10540 l_tot_err_count := l_tot_err_count + l_error_count;
10541 END IF;
10542 ----UDA Import
10543
10544
10545 fnd_file.put_line(fnd_file.log,
10546 'Total error count is : ' || l_tot_err_count);
10547
10548 -- Set the processing status appropriately
10549 IF (l_tot_err_count = 0) THEN
10550 UPDATE pos_imp_batch_summary
10551 SET import_status = 'COMPLETED',
10552 main_conc_status = 'COMPLETED',
10553 batch_status = 'COMPLETED',
10554 total_records_imported = total_records_imported + l_uda_imported_count
10555 WHERE batch_id = p_batch_id;
10556 ELSE
10557 UPDATE pos_imp_batch_summary
10558 SET import_status = 'COMPL_ERRORS',
10559 main_conc_status = 'COMPLETED',
10560 batch_status = 'ACTION_REQUIRED',
10561 total_records_imported = total_records_imported + l_uda_imported_count
10562 WHERE batch_id = p_batch_id;
10563 END IF;
10564
10565 ELSIF (l_batch_status = 'PROCESSING') THEN
10566 UPDATE pos_imp_batch_summary
10567 SET import_status = 'PENDING',
10568 main_conc_status = 'PENDING',
10569 batch_status = 'PROCESSING',
10570 total_records_imported = total_records_imported + l_uda_imported_count
10571 WHERE batch_id = p_batch_id;
10572
10573 RETURN;
10574 ELSIF (l_batch_status = 'ACTION_REQUIRED') THEN
10575
10576 UPDATE pos_imp_batch_summary
10577 SET import_status = 'PENDING',
10578 main_conc_status = 'PENDING',
10579 batch_status = 'PENDING',
10580 total_records_imported = total_records_imported + l_uda_imported_count
10581 WHERE batch_id = p_batch_id;
10582
10583 END IF;
10584
10585 ELSE --IF (p_import_uda_only = 'Y')
10586
10587 ------UDA import
10588 POS_BULKLOAD_ENTITIES.PROCESS_USER_ATTRS_DATA(p_data_set_id => p_batch_id,
10589 ERRBUF => l_errbuf,
10590 RETCODE => L_RETCODE,
10591 P_PURGE_SUCCESSFUL_LINES => FND_API.G_FALSE);
10592
10593 IF (L_RETCODE <> FND_API.G_RET_STS_SUCCESS) THEN
10594 l_tot_err_count := l_tot_err_count + 1;
10595 fnd_file.put_line(fnd_file.log,
10596 'UIC***** No. of Messages: ' || L_RETCODE ||
10597 ', Message: ' || l_errbuf ||
10598 ' From POS_BULKLOAD_ENTITIES.PROCESS_USER_ATTRS_DATA API.');
10599 errbuf := 'WARNING****** Unexpected error occured in import UDA program.';
10600 retcode := 1;
10601 ELSE
10602
10603 SELECT COUNT(1)
10604 INTO l_error_count
10605 FROM POS_SUPP_PROF_EXT_INTF
10606 WHERE BATCH_ID = P_BATCH_ID
10607 AND nvl(PROCESS_STATUS, 1) = 3;
10608
10609 SELECT COUNT(1)
10610 INTO l_uda_imported_count
10611 FROM POS_SUPP_PROF_EXT_INTF
10612 WHERE BATCH_ID = P_BATCH_ID
10613 AND NVL(PROCESS_STATUS, 1) = 4;
10614
10615 l_tot_err_count := l_tot_err_count + l_error_count;
10616 END IF;
10617 ----UDA Import
10618
10619
10620 fnd_file.put_line(fnd_file.log,
10621 'Total Supplier UDA Import error count is : ' || l_tot_err_count);
10622
10623
10624 END IF; ---IF (p_import_uda_only = 'N') THEN
10625
10626
10627 EXCEPTION
10628 WHEN OTHERS THEN
10629 errbuf := fnd_message.get || ' ' || SQLERRM;
10630 retcode := 2;
10631 fnd_file.put_line(fnd_file.log,
10632 ' Inside import_batch EXCEPTION ' || ' Message: ' ||
10633 SQLCODE || ' ' || SQLERRM);
10634 END import_batch;
10635
10636 END pos_batch_import_pkg;