DBA Data[Home] [Help]

PACKAGE BODY: APPS.ZX_AP_TAX_CLASSIFICATN_DEF_PKG

Source


1 package body ZX_AP_TAX_CLASSIFICATN_DEF_PKG as
2 /* $Header: zxaptxclsdefpkgb.pls 120.23.12020000.2 2012/08/27 09:46:33 ssanka ship $ */
3 
4 -- Declare Public Procedure
5 -- Initialize
6 
7 g_current_runtime_level     NUMBER;
8 g_level_statement           CONSTANT  NUMBER   := FND_LOG.LEVEL_STATEMENT;
9 g_level_procedure           CONSTANT  NUMBER   := FND_LOG.LEVEL_PROCEDURE;
10 g_level_unexpected          CONSTANT  NUMBER   := FND_LOG.LEVEL_UNEXPECTED;
11 
12 
13   result                boolean;
14   statement             varchar2(2000);
15   search_for_ap_tax     boolean;
16   search_for_po_tax     boolean;
17   search_for_cc_tax     boolean; -- Bug 6510307
18   search_ap_def_hier    boolean;
19   search_po_def_hier    boolean;
20   search_cc_def_hier    boolean; -- Bug 6510307
21   debug_loc             VARCHAR2(30);
22   curr_calling_sequence VARCHAR2(2000);
23 
24 PROCEDURE Initialize;
25 PROCEDURE pop_ap_def_option_hier(p_org_id           IN    NUMBER,
26                                  p_application_id   IN    NUMBER,
27                                  p_event_class_code IN    VARCHAR2,
28                                  p_return_status    OUT NOCOPY VARCHAR2);
29 
30 PROCEDURE pop_po_def_option_hier(p_org_id           IN    NUMBER,
31                                  p_application_id   IN    NUMBER,
32                                  p_return_status    OUT NOCOPY VARCHAR2);
33 --CC Change
34 PROCEDURE pop_cc_def_option_hier(p_org_id           IN    NUMBER,
35                                  p_application_id   IN    NUMBER,
36                                  p_return_status    OUT NOCOPY VARCHAR2);
37 
38 -- Bug#5066122
39 PROCEDURE validate_tax_classif_code(
40               p_tax_classification_code   IN  VARCHAR2,
41               p_count                     OUT NOCOPY NUMBER);
42 
43 -- Bug#4090842- change and split initialize to pop_ap_def_option_hier
44 -- and pop_po_def_option_hier
45 -------------------------------------------------------------------
46 --
47 -- PRIVATE PROCEDURE
48 -- Initialize
49 --
50 -- DESCRIPTION
51 -- This procedure gets chart_of_accounts_id from gl_sets_of_books
52 -- and initializes org_id stored in sysinfo to NULL
53 --
54 
55 PROCEDURE Initialize
56 IS
57   l_set_of_books_id    gl_sets_of_books.set_of_books_id%TYPE;
58   l_chart_of_accounts_id    gl_sets_of_books.chart_of_accounts_id%TYPE;
59 
60   -- Bug#4090842- no need to get org_id here, it is passed in from products
61   CURSOR c_financial_params IS
62   SELECT sob.set_of_books_id,sob.chart_of_accounts_id
63     FROM gl_sets_of_books sob,
64          financials_system_parameters fsp
65    WHERE fsp.set_of_books_id = sob.set_of_books_id;
66 BEGIN
67   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
68 
69   IF (g_level_statement >= g_current_runtime_level ) THEN
70     FND_LOG.STRING(g_level_statement,
71                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Initialize.BEGIN',
72                    'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: initialize(+)' );
73   END IF;
74 
75   open c_financial_params;
76      -- Bug#4090842- no need to fetch org_id
77      -- fetch c_financial_params into chart_of_accounts_id, org_id;
78   fetch c_financial_params into l_set_of_books_id,l_chart_of_accounts_id;
79   close c_financial_params;
80 
81   IF (g_level_statement >= g_current_runtime_level ) THEN
82       FND_LOG.STRING(g_level_statement,
83                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.initialize',
84                      'set_of_books_id  =='||to_char(l_set_of_books_id));
85 
86       FND_LOG.STRING(g_level_statement,
87                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.initialize',
88                      'chart_of_accounts_id  =='||to_char(l_chart_of_accounts_id));
89      END IF;
90 
91   sysinfo.set_of_books_id       := l_set_of_books_id;
92   sysinfo.chart_of_accounts_id  := l_chart_of_accounts_id;
93 
94   --
95   -- init org_id to NULL
96   --
97   sysinfo.ap_info.org_id := NULL;
98   sysinfo.po_info.org_id := NULL;
99   sysinfo.cc_info.org_id := NULL; -- Bug 6510307
100 
101   IF (g_level_statement >= g_current_runtime_level ) THEN
102     FND_LOG.STRING(g_level_statement,
103                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Initialize.END',
104                    'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: initialize(-)' );
105   END IF;
106 
107 EXCEPTION
108   WHEN OTHERS THEN
109     IF c_financial_params%ISOPEN THEN
110       CLOSE c_financial_params;
111     END IF;
112     FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
113     FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'initialize- '||
114                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
115     FND_MSG_PUB.Add;
116 
117     IF (g_level_unexpected >= g_current_runtime_level ) THEN
118       FND_LOG.STRING(g_level_unexpected,
119                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.initialize',
120                       sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
121     END IF;
122 END Initialize;
123 
124 -----------------------------------------------------------------------
125 --  PUBLIC PROCEDURE
126 --  get_default_tax_classification
127 --
128 --  DESCRIPTION
129 --
130 --  The procedure is passed a variety of parameters which may determine
131 --  the tax code that is to be used in Purchasing or in Payables, on
132 --  documents or document templates.
133 --
134 --  Given the parameters passed in the procedure will return a valid
135 --  tax classification code.
136 --  This API replaces get_default_tax_code of 11i
137 --
138 --  Current defaulting sources for the tax code in AP are:
139 --
140 --  Purchase Order Shipment
141 --  Supplier Site
142 --  Supplier
143 --  Natural Account
144 --  Financial Options
145 --  Invoice Header
146 --  Document Template
147 --
148 --  Current defaulting sources for the tax code in PO are:
149 --
150 --  Ship-to Location
151 --  Item
152 --  Supplier Site
153 --  Supplier
154 --  Financial Options
155 --
156 --  Current defaulting sources for the tax code in IGC are:
157 --
158 --  Supplier Site
159 --  Supplier
160 --  Financial Options
161 --
162 --  When the procedure is called from the transaction workbenches, the tax code
163 --  should be retrieved for the tax date (e.g. invoice date in AP)
164 --  When the API is called from setup screens, the tax code should be
165 --  retrieved for the system date.
166 --
167 --  The func_short_name parameter is for the purpose of future
168 --  application-specific defaulting enhancements.  The only current use
169 --  is to detect when a distribution set is in use on a form or process,
170 --  to determine which tax code to return when using document templates.
171 --
172 --
173 --  If the user-specified tax codes on
174 --  a document template is  required, it is  passed in to
175 --  the procedure
176 --  and may be returned as the defaulted tax code, if the procedure establishes
177 --  that that is the required tax code.
178 --
179 --  PARAMETERS
180 --  p_ref_doc_application_id            IN
181 --  p_ref_doc_entity_code               IN
182 --  p_ref_doc_event_class_code          IN
183 --  p_ref_doc_trx_id                    IN
184 --  p_ref_doc_line_id                   IN
185 --  p_ref_doc_trx_level_type            IN
186 --  p_vendor_id				IN
187 --  p_vendor_site_id 			IN
188 --  p_code_combination_id  		IN
189 --  p_concatenated_segments		IN
190 --  p_templ_tax_classification_cd       IN
191 --  p_ship_to_location_id		IN
192 --  p_ship_to_loc_org_id   		IN
193 --  p_inventory_item_id   		IN
194 --  p_item_org_id   			IN
195 --  p_tax_classification_code		IN  OUT NOCOPY
196 --  p_allow_tax_code_override_flag          OUT NOCOPY
197 --  p_tax_user_override_flag     	IN
198 --  p_user_tax_name              	IN
199 --  APPL_SHORT_NAME			IN
200 --  FUNC_SHORT_NAME			IN
201 --  p_calling_sequence			IN
202 --  p_event_class_code                  IN
203 --  p_entity_code                       IN
204 --  p_application_id                    IN
205 --  p_internal_organization_id          IN
206 
207 --  CALLED BY
208 --  Payables and Purchasing workbenches, setup forms and programs
209 --
210 --  HISTORY
211 --  14-JUL-97	Fiona Purves	Created based on AR Tax Defaulting API.
212 --  18-NOV-97   Fiona Purves    Created overloaded package, adding two extra
213 --				parameters, p_user_tax_name and p_user_tax_override_flag.
214 --				These parameters are used to detect and return a user-
215 --				defined tax code, if the defaulted one has been explicitly
216 --				overidden.
217 --  31-DEC-98   Fiona Purves    Added changes for effective tax date handling.
218 --  24-Jun-04   Sudhir Sekuri   Bugfix 3611046. 11ix uptake for EBusiness Tax
219 --  10-May-05   Phong La        Bugfix4310278. Remove p_line_location_id and
220 --                              use ref_doc columns instead
221 ---------------------------------------------------------------------------------
222 
223 PROCEDURE  get_default_tax_classification(
224 
225  -- p_line_location_id		IN  po_line_locations.line_location_id%TYPE,
226  p_ref_doc_application_id       IN  zx_lines_det_factors.ref_doc_application_id%TYPE,
227  p_ref_doc_entity_code          IN  zx_lines_det_factors.ref_doc_entity_code%TYPE,
228  p_ref_doc_event_class_code     IN  zx_lines_det_factors.ref_doc_event_class_code%TYPE,
229  p_ref_doc_trx_id               IN  zx_lines_det_factors.ref_doc_trx_id%TYPE,
230  p_ref_doc_line_id              IN  zx_lines_det_factors.ref_doc_line_id%TYPE,
231  p_ref_doc_trx_level_type       IN  zx_lines_det_factors.ref_doc_trx_level_type%TYPE,
232  p_vendor_id			IN  po_vendors.vendor_id%TYPE,
233  p_vendor_site_id 		IN  po_vendor_sites.vendor_site_id%TYPE,
234  p_code_combination_id  	IN  gl_code_combinations.code_combination_id%TYPE,
235  p_concatenated_segments	IN  varchar2,
236  p_templ_tax_classification_cd  IN  varchar2,
237  p_ship_to_location_id		IN  hr_locations_all.location_id%TYPE,
238  p_ship_to_loc_org_id   	IN  mtl_system_items.organization_id%TYPE,
239  p_inventory_item_id   		IN  mtl_system_items.inventory_item_id%TYPE,
240  p_item_org_id   		IN  mtl_system_items.organization_id%TYPE,
241  p_tax_classification_code	IN  OUT NOCOPY VARCHAR2,
242  p_allow_tax_code_override_flag     OUT NOCOPY zx_acct_tx_cls_defs.allow_tax_code_override_flag%TYPE,
243  p_legal_entity_id              IN  zx_lines.legal_entity_id%TYPE,
244  APPL_SHORT_NAME		IN  fnd_application.application_short_name%TYPE,
245  FUNC_SHORT_NAME		IN  VARCHAR2,
246  p_calling_sequence		IN  VARCHAR2,
247  p_event_class_code             IN  VARCHAR2,
248  p_entity_code                  IN  VARCHAR2,
249  p_application_id               IN  NUMBER,
250  p_internal_organization_id     IN  NUMBER) IS
251 
252 BEGIN
253 
254   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
255 
256    IF (g_level_statement >= g_current_runtime_level ) THEN
257       FND_LOG.STRING(g_level_statement,
258                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.BEGIN',
259 
260                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (+)');
261    END IF;
262 
263    --
264    -- set default value
265    --
266   Initialize; --Bug 5712279
267 
268    ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification(
269                                            -- p_line_location_id,
270                                            p_ref_doc_application_id,
271                                            p_ref_doc_entity_code,
272                                            p_ref_doc_event_class_code,
273                                            p_ref_doc_trx_id,
274                                            p_ref_doc_line_id,
275                                            p_ref_doc_trx_level_type,
276 					   p_vendor_id,
277 					   p_vendor_site_id,
278 					   p_code_combination_id,
279 				   	   p_concatenated_segments,
280                                            p_templ_tax_classification_cd,
281 					   p_ship_to_location_id,
282 					   p_ship_to_loc_org_id,
283 					   p_inventory_item_id,
284 					   p_item_org_id ,
285 					   p_tax_classification_code,
286 					   p_allow_tax_code_override_flag,
287 					   'N',
288 					   null,
289                                            p_legal_entity_id,
290 					   APPL_SHORT_NAME,
291 					   FUNC_SHORT_NAME,
292 					   p_calling_sequence,
293                                            p_event_class_code,
294                                            p_entity_code,
295                                            p_application_id,
296                                            p_internal_organization_id);
297    IF (g_level_statement >= g_current_runtime_level ) THEN
298       FND_LOG.STRING(g_level_statement,
299                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.END',
300 
301                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (-)');
302    END IF;
303 
304 END get_default_tax_classification;
305 
306 ----------------------------------------------------------
307 --
308 -- bug#4891362- overloaded version
309 --
310 
311 PROCEDURE  get_default_tax_classification(
312  p_ref_doc_application_id       IN  zx_lines_det_factors.ref_doc_application_id%TYPE,
313  p_ref_doc_entity_code          IN  zx_lines_det_factors.ref_doc_entity_code%TYPE,
314  p_ref_doc_event_class_code     IN  zx_lines_det_factors.ref_doc_event_class_code%TYPE,
315  p_ref_doc_trx_id               IN  zx_lines_det_factors.ref_doc_trx_id%TYPE,
316  p_ref_doc_line_id              IN  zx_lines_det_factors.ref_doc_line_id%TYPE,
317  p_ref_doc_trx_level_type       IN  zx_lines_det_factors.ref_doc_trx_level_type%TYPE,
318  p_vendor_id			IN  po_vendors.vendor_id%TYPE,
319  p_vendor_site_id 		IN  po_vendor_sites.vendor_site_id%TYPE,
320  p_code_combination_id  	IN  gl_code_combinations.code_combination_id%TYPE,
321  p_concatenated_segments	IN  varchar2,
322  p_templ_tax_classification_cd  IN  varchar2,
323  p_ship_to_location_id		IN  hr_locations_all.location_id%TYPE,
324  p_ship_to_loc_org_id   	IN  mtl_system_items.organization_id%TYPE,
325  p_inventory_item_id   		IN  mtl_system_items.inventory_item_id%TYPE,
326  p_item_org_id   		IN  mtl_system_items.organization_id%TYPE,
327  p_tax_classification_code	IN  OUT NOCOPY VARCHAR2,
328  p_allow_tax_code_override_flag     OUT NOCOPY zx_acct_tx_cls_defs.allow_tax_code_override_flag%TYPE,
329  APPL_SHORT_NAME		IN  fnd_application.application_short_name%TYPE,
330  FUNC_SHORT_NAME		IN  VARCHAR2,
331  p_calling_sequence		IN  VARCHAR2,
332  p_event_class_code             IN  VARCHAR2,
333  p_entity_code                  IN  VARCHAR2,
334  p_application_id               IN  NUMBER,
335  p_internal_organization_id     IN  NUMBER) IS
336 
337 BEGIN
338 
339   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
340 
341    IF (g_level_statement >= g_current_runtime_level ) THEN
342       FND_LOG.STRING(g_level_statement,
343                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.BEGIN',
344 
345                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (+)');
346       FND_LOG.STRING(g_level_statement,
347                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
348 
349                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: overloaded version 1');
350 
351    END IF;
352 
353    --
354    -- set default value
355    --
356 
357    Initialize; --Bug 5712279
358 
359    ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification(
360                                            p_ref_doc_application_id,
361                                            p_ref_doc_entity_code,
362                                            p_ref_doc_event_class_code,
363                                            p_ref_doc_trx_id,
364                                            p_ref_doc_line_id,
365                                            p_ref_doc_trx_level_type,
366 					   p_vendor_id,
367 					   p_vendor_site_id,
368 					   p_code_combination_id,
369 				   	   p_concatenated_segments,
370                                            p_templ_tax_classification_cd,
371 					   p_ship_to_location_id,
372 					   p_ship_to_loc_org_id,
373 					   p_inventory_item_id,
374 					   p_item_org_id ,
375 					   p_tax_classification_code,
376 					   p_allow_tax_code_override_flag,
377 					   'N',
378 					   null,
379                                            null, --p_legal_entity_id,
380 					   APPL_SHORT_NAME,
381 					   FUNC_SHORT_NAME,
382 					   p_calling_sequence,
383                                            p_event_class_code,
384                                            p_entity_code,
385                                            p_application_id,
386                                            p_internal_organization_id);
387    IF (g_level_statement >= g_current_runtime_level ) THEN
388       FND_LOG.STRING(g_level_statement,
389                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.END',
390 
391                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (-)');
392    END IF;
393 
394 END get_default_tax_classification;
395 
396 --------------------------------------------------------------
397 -- The API get_default_tax_classification replaces 11i API get_default_tax_code
398 PROCEDURE  get_default_tax_classification(
399    -- p_line_location_id			IN  po_line_locations.line_location_id%TYPE,
400    p_ref_doc_application_id             IN  zx_lines_det_factors.ref_doc_application_id%TYPE,
401    p_ref_doc_entity_code                IN  zx_lines_det_factors.ref_doc_entity_code%TYPE,
402    p_ref_doc_event_class_code           IN  zx_lines_det_factors.ref_doc_event_class_code%TYPE,
403    p_ref_doc_trx_id                     IN  zx_lines_det_factors.ref_doc_trx_id%TYPE,
404    p_ref_doc_line_id                    IN  zx_lines_det_factors.ref_doc_line_id%TYPE,
405    p_ref_doc_trx_level_type             IN  zx_lines_det_factors.ref_doc_trx_level_type%TYPE,
406    p_vendor_id				IN  po_vendors.vendor_id%TYPE,
407    p_vendor_site_id 			IN  po_vendor_sites.vendor_site_id%TYPE,
408    p_code_combination_id  		IN  gl_code_combinations.code_combination_id%TYPE,
409    p_concatenated_segments		IN  varchar2,
410    p_templ_tax_classification_cd        IN  varchar2,
411    p_ship_to_location_id		IN  hr_locations_all.location_id%TYPE,
412    p_ship_to_loc_org_id   		IN  mtl_system_items.organization_id%TYPE,
413    p_inventory_item_id   		IN  mtl_system_items.inventory_item_id%TYPE,
414    p_item_org_id   			IN  mtl_system_items.organization_id%TYPE,
415    p_tax_classification_code		IN  OUT NOCOPY VARCHAR2,
416    p_allow_tax_code_override_flag           OUT NOCOPY zx_acct_tx_cls_defs.allow_tax_code_override_flag%TYPE,
417    p_tax_user_override_flag		IN  VARCHAR2,
418    p_user_tax_name	       		IN  VARCHAR2,
419    p_legal_entity_id                    IN  zx_lines.legal_entity_id%TYPE,
420    APPL_SHORT_NAME			IN  fnd_application.application_short_name%TYPE,
421    FUNC_SHORT_NAME			IN  VARCHAR2,
422    p_calling_sequence			IN  VARCHAR2,
423    p_event_class_code                   IN  VARCHAR2,
424    p_entity_code                        IN  VARCHAR2,
425    p_application_id                     IN  NUMBER,
426    p_internal_organization_id           IN  NUMBER) IS
427 
428  l_tax_classification_code      VARCHAR2(30);
429  l_enforce_tax_from_acct_flag   VARCHAR2(1);
430  l_enforce_tax_from_refdoc_flag VARCHAR2(1);
431  l_enforced_tax_found	 	boolean := FALSE;
432  l_tax_classification_found	boolean := FALSE;
433  l_found                        boolean := FALSE;
434  l_curr_calling_sequence 	VARCHAR2(2000);
435  l_item_taxable_flag            VARCHAR2(1);
436  -- Added the following variable as part of the fix for the bug 2608697 by zmohiudd.
437  l_shipment_taxable_flag        VARCHAR2(1);
438  l_count                        NUMBER;
439  l_return_status                VARCHAR2(80);
440 
441 CURSOR sel_item_taxable_flag
442          (c_inventory_item_id   mtl_system_items_b.inventory_item_id%TYPE,
443           c_item_org_id         mtl_system_items_b.organization_id%TYPE,
444           c_ship_to_loc_org_id  mtl_system_items_b.organization_id%TYPE) IS
445 
446  SELECT taxable_flag
447    FROM mtl_system_items si
448   WHERE si.inventory_item_id = c_inventory_item_id
449     AND si.organization_id = nvl(c_ship_to_loc_org_id, c_item_org_id);
450 
451   CURSOR c_evnt_cls_options (c_org_id           NUMBER,
452                              c_application_id   NUMBER,
453                              c_entity_code      VARCHAR2,
454                              c_event_class_code VARCHAR2) IS
455   select enforce_tax_from_acct_flag,
456          enforce_tax_from_ref_doc_flag
457     from zx_evnt_cls_options
458    where application_id = c_application_id
459      and entity_code = c_entity_code
460      and event_class_code = c_event_class_code
461      and first_pty_org_id = (Select party_tax_profile_id
462                                From zx_party_tax_profile
463                               where party_id = c_org_id
464                                 and party_type_code = 'OU')
465      and sysdate >= effective_from
466      and sysdate <= nvl(effective_to,sysdate)
467      and enabled_flag = 'Y';
468 
469 BEGIN
470 
471   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
472 
473   IF (g_level_statement >= g_current_runtime_level ) THEN
474   	FND_LOG.STRING(g_level_statement,
475                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.BEGIN',
476                        'Get_Default_Tax_Classification(+) ');
477 --  	FND_LOG.STRING(g_level_statement,
478 --                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
479 --                       'p_line_location_id  == >'||to_char(p_line_location_id ));
480         FND_LOG.STRING(g_level_statement,
481                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
482                        'p_ref_doc_application_id == >'||TO_CHAR(p_ref_doc_application_id));
483         FND_LOG.STRING(g_level_statement,
484                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
485                        'p_ref_doc_entity_code == >'||p_ref_doc_entity_code);
486         FND_LOG.STRING(g_level_statement,
487                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
488                        'p_ref_doc_event_class_code == >'||p_ref_doc_event_class_code);
489         FND_LOG.STRING(g_level_statement,
490                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
491                        'p_ref_doc_trx_id == >'||TO_CHAR(p_ref_doc_trx_id));
492         FND_LOG.STRING(g_level_statement,
493                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
494                        'p_ref_doc_line_id == >'||TO_CHAR(p_ref_doc_line_id));
495         FND_LOG.STRING(g_level_statement,
496                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
497                        'p_ref_doc_trx_level_type == >'||p_ref_doc_trx_level_type);
498   	FND_LOG.STRING(g_level_statement,
499                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
500                        'p_vendor_id  == >'       ||to_char(p_vendor_id ));
501   	FND_LOG.STRING(g_level_statement,
502                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
503                        'p_vendor_site_id  == >'  ||to_char(p_vendor_site_id ));
504   	FND_LOG.STRING(g_level_statement,
505                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
506                        'p_code_combination_id = >'||to_char(p_code_combination_id) );
507   	FND_LOG.STRING(g_level_statement,
508                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
509                        'p_concatenated_segments== >'||p_concatenated_segments );
510         FND_LOG.STRING(g_level_statement,
511                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
512                        'p_templ_tax_classification_cd == >'||
513                         p_templ_tax_classification_cd);
514   	FND_LOG.STRING(g_level_statement,
515                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
516                        'p_ship_to_location_id == >'||to_char(p_ship_to_location_id) );
517   	FND_LOG.STRING(g_level_statement,
518                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
519                        'p_ship_to_loc_org_id  == >'||to_char(p_ship_to_loc_org_id) );
520   	FND_LOG.STRING(g_level_statement,
521                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
522                        'p_inventory_item_id  == >'||to_char(p_inventory_item_id) );
523   	FND_LOG.STRING(g_level_statement,
524                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
525                        'p_item_org_id  == >'     ||to_char( p_item_org_id));
526   	FND_LOG.STRING(g_level_statement,
527                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
528                        'p_tax_classification_code  == >' ||p_tax_classification_code);
529         FND_LOG.STRING(g_level_statement,
530                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
531                        'p_allow_tax_code_override_flag ==>'|| p_allow_tax_code_override_flag);
532   	FND_LOG.STRING(g_level_statement,
533                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
534                        'p_tax_user_override_flag  ==>'||p_tax_user_override_flag);
535   	FND_LOG.STRING(g_level_statement,
536                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
537                        'p_user_tax_name  ==>'||p_user_tax_name);
538         FND_LOG.STRING(g_level_statement,
539                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
540                        'p_legal_entity_id ==>'||TO_CHAR(p_legal_entity_id));
541 
542   	FND_LOG.STRING(g_level_statement,
543                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
544                        'APPL_SHORT_NAME  == >'||APPL_SHORT_NAME );
545   	FND_LOG.STRING(g_level_statement,
546                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
547                        'FUNC_SHORT_NAME   == >'||FUNC_SHORT_NAME );
548   	FND_LOG.STRING(g_level_statement,
549                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
550                        'p_calling_sequence  == >'||p_calling_sequence );
551   	FND_LOG.STRING(g_level_statement,
552                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
553                        'p_event_class_code  == >'||p_event_class_code );
554   	FND_LOG.STRING(g_level_statement,
555                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
556                        'p_entity_code  == >'||p_entity_code );
557         FND_LOG.STRING(g_level_statement,
558                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
559                        'p_application_id == >'||TO_CHAR(p_application_id));
560         FND_LOG.STRING(g_level_statement,
561                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
562                        'p_internal_organization_id == >'||TO_CHAR(p_internal_organization_id));
563 
564   END IF;
565 
566   -- Bug#4090842- call populate ap/po default options here
567   -- Initialize;
568 
569   --
570   -- check if need to repopulate AP/PO/IGC default options
571   --
572   IF APPL_SHORT_NAME = 'SQLAP' THEN
573     IF (sysinfo.ap_info.org_id IS NULL OR
574         (sysinfo.ap_info.org_id <> p_internal_organization_id)) THEN
575       pop_ap_def_option_hier(
576                     p_internal_organization_id,
577                     p_application_id,
578                     p_event_class_code,
579                     l_return_status);
580 
581       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
582         RETURN;
583       END IF;
584     END IF;
585   ELSIF APPL_SHORT_NAME = 'PO' THEN
586     IF (sysinfo.po_info.org_id IS NULL OR
587         (sysinfo.po_info.org_id <> p_internal_organization_id)) THEN
588       pop_po_def_option_hier(
589                     p_internal_organization_id,
590                     p_application_id,
591                     l_return_status);
592       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
593         RETURN;
594       END IF;
595     END IF;
596   ELSIF APPL_SHORT_NAME = 'IGC' THEN -- Bug 6510307
597     IF (sysinfo.cc_info.org_id IS NULL OR
598         (sysinfo.cc_info.org_id <> p_internal_organization_id)) THEN
599       pop_cc_def_option_hier(
600                     p_internal_organization_id,
601                     p_application_id,
602                     l_return_status);
603       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
604         RETURN;
605       END IF;
606     END IF;
607   END IF;
608 
609   l_tax_classification_found := FALSE;
610 
611   debug_loc := 'Get_Default_Tax_Classification';
612 
613   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
614 
615   --
616   -- Get Payables/Purchasing default tax code.
617   -- Hierarchy for PO:  Ship-to Location, Item, Vendor, Vendor Site and System.
618   -- Hierarchy for AP:  Purchase Order Shipment, Vendor, Vendor Site, Natural Account, System,
619   -- and Template.
620   -- Hierarchy for CC:  Vendor Site, Vendor and System.
621   -- The search ends when a tax code is found.
622   --
623 
624   --
625   -- if use_tax_classification_flag is no, set tax_classification_code
626   -- to NULL and return, no need to search the default hierachy
627   --
628 
629   IF (APPL_SHORT_NAME = 'SQLAP' AND
630       NOT search_for_ap_tax) THEN
631     p_tax_classification_code := NULL;
632     RETURN;
633   ELSIF (APPL_SHORT_NAME = 'PO' AND
634       NOT search_for_po_tax) THEN
635 
636     IF (p_tax_user_override_flag = 'Y') THEN
637       p_tax_classification_code := p_user_tax_name;
638       l_tax_classification_found := TRUE;
639     ELSE
640       p_tax_classification_code := NULL;
641     END IF;
642     RETURN;
643   ELSIF (APPL_SHORT_NAME = 'IGC' AND -- Bug 6510307
644       NOT search_for_cc_tax) THEN
645      p_tax_classification_code := NULL;
646      RETURN;
647   END IF;
648 
649   IF (p_tax_user_override_flag = 'Y') THEN
650      -- User has overridden tax code and the user tax code should be used.
651      -- If tax name is null, then this is an explicit request for a null
652      -- tax name and null should be returned.
653 
654      p_tax_classification_code := p_user_tax_name;
655      l_tax_classification_found := TRUE;
656   END IF;
657 
658   -- Following statement is to deal with the following problem:
659   -- User has overridden default tax code with a user-specified one.
660   -- User has committed the shipment and re-queried it, losing the
661   -- tax_user_override_flag information, which is only available in the form.
662   -- User has then changed the ship-to location code.
663   -- Tax will be re-defaulted under these circumstances, which is incorrect
664   -- if tax is not set up to re-default from the ship-to location.
665   -- Real fix is to add the tax_user_override_flag as a database field.
666 
667   IF (search_po_def_hier) THEN
668     IF (NVL(func_short_name, 'NONE')  = 'SHIP_TO_LOC') Then
669        FOR i in 1..7
670        Loop
671           If potaxtab(i) = 'SHIP_TO_LOCATION' OR potaxtab(i) = 'ITEM' Then
672              l_found := TRUE;
673              exit;
674           End If;
675        End Loop;
676        If NOT l_found Then
677           l_tax_classification_code := p_user_tax_name;
678           l_tax_classification_found := TRUE;
679        End If;
680     END IF;
681   END IF;
682 
683   IF (g_level_statement >= g_current_runtime_level ) THEN
684      FND_LOG.STRING(g_level_statement,
685                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
686                     'l_tax_classification_code is found  =='||l_tax_classification_code);
687   END IF;
688 
689   IF (l_tax_classification_found = FALSE) THEN
690      IF (APPL_SHORT_NAME = 'SQLAP') THEN
691         IF (search_ap_def_hier = TRUE) THEN
692 
693            IF (g_level_statement >= g_current_runtime_level ) THEN
694               FND_LOG.STRING(g_level_statement,
695                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
696                              'Getting Event Class Options');
697            END IF;
698 
699 --           open c_evnt_cls_options (to_number(substrb(userenv('CLIENT_INFO'),1,10)),
700              open c_evnt_cls_options (
701                                     p_internal_organization_id,
702                                     200,
703                                     p_entity_code,
704                                     p_event_class_code);
705            fetch c_evnt_cls_options into l_enforce_tax_from_acct_flag,
706                                          l_enforce_tax_from_refdoc_flag;
707            close c_evnt_cls_options;
708 
709            IF (g_level_statement >= g_current_runtime_level ) THEN
710               FND_LOG.STRING(g_level_statement,
711                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
712                              'Entity Code:' || p_entity_code);
713               FND_LOG.STRING(g_level_statement,
714                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
715                              'Event Class Code:' || p_event_class_code);
716               FND_LOG.STRING(g_level_statement,
717                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
718                              'Enforce Tax From Account  =='
719                               || l_enforce_tax_from_acct_flag);
720 
721   	      FND_LOG.STRING(g_level_statement,
722                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
723                              'Getting tax code for AP ');
724            END IF;
725 
726            IF (l_enforce_tax_from_refdoc_flag = 'Y') THEN
727 	      -- Tax code from the PO shipment is enforced
728 	      -- If a tax code exists for shipment then there is
729 	      -- no need to search any further, as this takes
730 	      -- precedence over the rest of the hierarchy.
731 
732               IF (g_level_statement >= g_current_runtime_level ) THEN
733                  FND_LOG.STRING(g_level_statement,
734                                 'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
735                                 'Matching is enforced');
736               END IF;
737 
738               /*
739                * comment out for bug#4310278
740                * need to confirm with Helen
741                *
742                --start  of code fix added for the bug 2608697 by  zmohiudd
743                If p_line_location_id is not null then
744 	          select taxable_flag
745 	            into l_shipment_taxable_flag
746 	            from po_line_locations
747 	           where line_location_id = p_line_location_id ;
748 
749                   IF (g_level_statement >= g_current_runtime_level ) THEN
750            	    FND_LOG.STRING(g_level_statement,
751                                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
752                                     ' l_shipment_taxable_flag is ' || l_shipment_taxable_flag );
753                   END IF;
754  	         If (l_shipment_taxable_flag = 'Y' ) then
755  		    IF (g_level_statement >= g_current_runtime_level ) THEN
756  		       FND_LOG.STRING(g_level_statement,
757                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
758                                        'Calling get_po_shipment tax ' );
759  		    END IF;
760  		    l_tax_classification_code := get_input_tax_classif_code (p_line_location_id,
761                                                                        l_curr_calling_sequence);
762  	         else
763  		    l_enforced_tax_found := TRUE;
764     	         end if;
765                else
766       	         l_tax_classification_code := get_input_tax_classif_code (p_line_location_id,
767  					                           l_curr_calling_sequence);
768                end if;
769                -- End of the code fix added for the bug 2608697 by  zmohiudd
770               *
771               *
772               */
773               --
774               -- bug#4310278
775               --
776               l_tax_classification_code := get_input_tax_classif_code (
777                                              p_ref_doc_application_id,
778                                              p_ref_doc_entity_code,
779                                              p_ref_doc_event_class_code,
780                                              p_ref_doc_trx_id,
781                                              p_ref_doc_line_id,
782                                              p_ref_doc_trx_level_type,
783                                              l_curr_calling_sequence);
784 
785               IF (l_tax_classification_code is not NULL) THEN
786 	         -- Tax found on PO shipment, do not search further
787                  l_enforced_tax_found := TRUE;
788                  IF (g_level_statement >= g_current_runtime_level ) THEN
789             	    FND_LOG.STRING(g_level_statement,
790                                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
791                                    'l_tax_classification_code =='||l_tax_classification_code );
792                  END IF;
793               END IF;
794            ELSIF (l_enforce_tax_from_acct_flag = 'Y') THEN
795                  -- Tax code from the account is enforced
796                  -- If a tax code exists for this account and
797                  -- override of the tax code is not allowed then
798                  -- no need to search any further, as the non-overridable accounts take
799                  -- precedence over the rest of the tax defaulting hierarchy
800                  -- This includes both Input and Non-taxable accounts.
801 
802                  IF (g_level_statement >= g_current_runtime_level ) THEN
803                     FND_LOG.STRING(g_level_statement,
804                                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
805                                    'Tax from account is enforced');
806                     FND_LOG.STRING(g_level_statement,
807                                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
808                                    ' Calling get_account_tax ');
809                  END IF;
810                  get_account_tax (p_code_combination_id,
811 		          	  p_concatenated_segments,
812           			  p_tax_classification_code,
813           			  p_allow_tax_code_override_flag,
814           			  l_tax_classification_found,
815           			  l_curr_calling_sequence);
816                  l_tax_classification_code := p_tax_classification_code;
817                  IF (g_level_statement >= g_current_runtime_level ) THEN
818                     FND_LOG.STRING(g_level_statement,
819                                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
820                                    'l_tax_classification_code =='||l_tax_classification_code);
821                  END IF;
822                  IF (p_allow_tax_code_override_flag = 'N') THEN
823           	    -- Override is not allowed, do not search further
824                     l_enforced_tax_found := TRUE;
825                  END IF;
826            END IF; -- ap_match_on_tax_flag
827 
828            IF (l_enforced_tax_found = FALSE ) THEN
829               -- If tax is not enforced from the account, or is enforced but
830               -- the tax code is overrideable, then continue the search
831 
832               l_count := aptaxtab.COUNT;
833 
834               <<Ap_Tax_Loop>>
835               FOR i in 1..l_count  LOOP
836                   IF (aptaxtab (i) is NULL) THEN
837                      --
838                      -- default hierachy options from 1 to 7 can not
839                      -- have gap, if the current one is NULL, the
840                      -- rest would be NULL, there is no need to
841                      -- continue looping
842                      --
843 
844                      exit Ap_Tax_Loop;
845                    ELSE
846                    --  aptaxtab (i) is not NULL
847 
848    	             IF (aptaxtab (i) = 'REFERENCE_DOCUMENT') THEN
849                         IF (g_level_statement >= g_current_runtime_level ) THEN
850          	           FND_LOG.STRING(g_level_statement,
851                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
852                                           'Getting tax code from shipment');
853          	           FND_LOG.STRING(g_level_statement,
854                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
855                                           'Calling get_input_tax_classif_code ');
856                         END IF;
857       	                l_tax_classification_code := get_input_tax_classif_code (
858                                              p_ref_doc_application_id,
859                                              p_ref_doc_entity_code,
860                                              p_ref_doc_event_class_code,
861                                              p_ref_doc_trx_id,
862                                              p_ref_doc_line_id,
863                                              p_ref_doc_trx_level_type,
864                                              l_curr_calling_sequence);
865 
866                         IF (l_tax_classification_code is not NULL) THEN
867                            l_tax_classification_found := TRUE;
868                            IF (g_level_statement >= g_current_runtime_level ) THEN
869                               FND_LOG.STRING(g_level_statement,
870                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
871                                              'l_tax_classification_code =='
872                                               ||l_tax_classification_code);
873                            END IF;
874                            exit Ap_Tax_Loop;
875                         END IF;
876                      END IF;
877 
878                      IF (aptaxtab (i) = 'SHIP_FROM_PARTY_SITE') THEN
879                         IF (g_level_statement >= g_current_runtime_level ) THEN
880          	           FND_LOG.STRING(g_level_statement,
881                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
882                                           'Getting tax code from supplier site');
883                         END IF;
884                         l_tax_classification_code := get_site_tax (
885                                                         p_vendor_site_id,
886 					                l_curr_calling_sequence);
887                         IF (l_tax_classification_code is not NULL) THEN
888                            l_tax_classification_found := TRUE;
889                            IF (g_level_statement >= g_current_runtime_level ) THEN
890                               FND_LOG.STRING(g_level_statement,
891                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
892                                              'l_tax_classification_code =='
893                                               ||l_tax_classification_code);
894                            END IF;
895                            exit Ap_Tax_Loop;
896                         END IF;
897                      END IF;
898 
899                      IF (aptaxtab (i) = 'SHIP_FROM_PARTY') THEN
900                         IF (g_level_statement >= g_current_runtime_level ) THEN
901                 	    FND_LOG.STRING(g_level_statement,
902                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
903                                            'Getting tax code from supplier');
904                         END IF;
905                         l_tax_classification_code := get_vendor_tax (
906                                                         p_vendor_id,
907        					                l_curr_calling_sequence);
908                         IF (l_tax_classification_code is not NULL) THEN
909                            l_tax_classification_found := TRUE;
910                            IF (g_level_statement >= g_current_runtime_level ) THEN
911                               FND_LOG.STRING(g_level_statement,
912                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
913                                              'l_tax_classification_code =='
914                                                  ||l_tax_classification_code);
915                            END IF;
916                            exit Ap_Tax_Loop;
917                         END IF;
918                      END IF;
919 
920                      IF (aptaxtab (i) = 'NATURAL_ACCOUNT') THEN
921                         IF (g_level_statement >= g_current_runtime_level ) THEN
922          	            FND_LOG.STRING(g_level_statement,
923                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
924                                            'Getting tax code from account');
925                         END IF;
926                         get_account_tax (p_code_combination_id,
927 	       			         p_concatenated_segments,
928 			         	 p_tax_classification_code,
929 				         p_allow_tax_code_override_flag,
930 				         l_tax_classification_found,
931 			              	 l_curr_calling_sequence);
932                         l_tax_classification_code := p_tax_classification_code;
933                         IF (g_level_statement >= g_current_runtime_level ) THEN
934          	            FND_LOG.STRING(g_level_statement,
935                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
936                                            'l_tax_classification_code =='
937                                             ||l_tax_classification_code);
938                         END IF;
939        	                IF (l_tax_classification_found = TRUE) THEN
940                            IF (g_level_statement >= g_current_runtime_level ) THEN
941                               FND_LOG.STRING(g_level_statement,
942                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
943                                              'l_tax_classification_code is Found =='
944                                               ||l_tax_classification_code);
945                            END IF;
946                            exit Ap_Tax_Loop;
947                         END IF;
948                      END IF;
949 
950                      IF (aptaxtab (i) = 'FINANCIAL_OPTIONS') THEN
951                         IF (g_level_statement >= g_current_runtime_level ) THEN
952          	            FND_LOG.STRING(g_level_statement,
953                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
954                                            'Getting tax code from financial system parameters');
955          	            FND_LOG.STRING(g_level_statement,
956                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
957                                            'sysinfo.vat_code =='
958                                             ||sysinfo.ap_info.tax_classification_code );
959                         END IF;
960                         l_tax_classification_code := sysinfo.ap_info.tax_classification_code;
961                         IF (l_tax_classification_code is not NULL) THEN
962                            l_tax_classification_found := TRUE;
963                            IF (g_level_statement >= g_current_runtime_level ) THEN
964                               FND_LOG.STRING(g_level_statement,
965                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
966                                              'l_tax_classification_code =='
967                                               ||l_tax_classification_code);
968                            END IF;
969                            exit Ap_Tax_Loop;
970                         END IF;
971                      END IF;
972 
973                      IF (aptaxtab (i) = 'TEMPLATE') THEN
974                         IF (g_level_statement >= g_current_runtime_level ) THEN
975                             FND_LOG.STRING(g_level_statement,
976                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
977                                            'Getting tax code from template');
978                         END IF;
979                         -- If the API has been called from a form or process
980                         -- where a template is being used, then we should always
981                         -- return the tax code on the template item, even if it
982                         -- is null.  This is because a null tax code on a template
983                         -- is considered as an explicit request for a non-taxable
984                         -- item.  See bug #558756.
985                         --
986                         -- We use the func_short_name to determine if the
987                         -- API is being called anywhere where a distribution set
988                         -- is in use, and use the calling_sequence to determine
989                         -- whether we are being called from the Expense Reports form
990                         -- (and are by implication using an expense report template).
991 
992                         -- 2544633 fbreslin: Add APXXXDER to list of forms that uses this code.
993                         IF (p_calling_sequence IN ('APXXXEER', 'APXXXDER') OR
994                             func_short_name = 'AP_INSERT_FROM_DSET') THEN
995                            l_tax_classification_code := p_templ_tax_classification_cd;
996                            l_tax_classification_found := TRUE;
997                            IF (g_level_statement >= g_current_runtime_level ) THEN
998                              FND_LOG.STRING(g_level_statement,
999                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1000                                            'l_tax_classification_code =='
1001                                             ||l_tax_classification_code);
1002                            END IF;
1003                            exit Ap_Tax_Loop;
1004                         END IF;
1005                     END IF;
1006                   END IF;
1007               END LOOP Ap_Tax_Loop;
1008            END IF; -- l_enforced_tax_found
1009         END IF; -- search_for_ap_tax
1010      ELSIF (APPL_SHORT_NAME = 'PO') THEN -- Bug 6510307
1011         --  APPL_SHORT_NAME is PO
1012         IF (search_po_def_hier = TRUE) THEN
1013 
1014            IF (g_level_statement >= g_current_runtime_level ) THEN
1015               FND_LOG.STRING(g_level_statement,
1016                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1017                              'Getting tax code for PO');
1018            END IF;
1019 
1020            l_count := potaxtab.COUNT;
1021 
1022            <<Po_Tax_Loop>>
1023            FOR i in 1..l_count  LOOP
1024                IF (potaxtab (i) is  NULL) THEN
1025                   --
1026                   -- default hierachy options from 1 to 7 can not
1027                   -- have gap, if the current one is NULL, the
1028                   -- rest would be NULL, there is no need to
1029                   -- continue looping
1030                   --
1031                  exit Po_Tax_Loop;
1032                ELSE
1033                  --  potaxtab (i) is not NULL
1034                   IF (potaxtab (i) = 'SHIP_TO_LOCATION') THEN
1035                      IF (g_level_statement >= g_current_runtime_level ) THEN
1036                	        FND_LOG.STRING(g_level_statement,
1037                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1038                                        ' Calling get_ship_to_location_tax ');
1039                      END IF;
1040 
1041 	             l_tax_classification_code :=
1042                          get_ship_to_location_tax (p_ship_to_location_id,
1043 		   				   p_ship_to_loc_org_id,
1044                                                    p_legal_entity_id,
1045    						   l_curr_calling_sequence);
1046                      IF (l_tax_classification_code is not NULL) THEN
1047                         l_tax_classification_found := TRUE;
1048                         IF (g_level_statement >= g_current_runtime_level ) THEN
1049                   	   FND_LOG.STRING(g_level_statement,
1050                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1051                                           'l_tax_classification_code =='
1052                                           ||l_tax_classification_code);
1053                         END IF;
1054                         exit Po_Tax_Loop;
1055                      END IF;
1056                   END IF;
1057 
1058                   IF (potaxtab (i) = 'ITEM') THEN
1059                      IF (g_level_statement >= g_current_runtime_level ) THEN
1060      	                FND_LOG.STRING(g_level_statement,
1061                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1062                                        'Getting tax code from item');
1063      	                FND_LOG.STRING(g_level_statement,
1064                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1065                                        'Calling get_item_tax ');
1066                      END IF;
1067    	             l_tax_classification_code := get_item_tax (p_inventory_item_id,
1068    		   			                        p_ship_to_loc_org_id,
1069    					                        p_item_org_id,
1070    					                        l_curr_calling_sequence);
1071                      -- Fixed bug 1753904: Tax code is defaultin
1072                      -- in PO documents for non-taxable item.
1073 
1074                      OPEN sel_item_taxable_flag (p_inventory_item_id,
1075                                                  p_item_org_id,
1076                                                  p_ship_to_loc_org_id);
1077                      FETCH sel_item_taxable_flag INTO l_item_taxable_flag;
1078                      CLOSE sel_item_taxable_flag;
1079 
1080                      --If the item's taxable flag is not set to 'Y',
1081                      --the tax code defaulting PKG should not look further to the next hierarchy
1082                      --even a null tax code is returned.
1083                      IF (g_level_statement >= g_current_runtime_level ) THEN
1084                   	FND_LOG.STRING(g_level_statement,
1085                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1086                                        'l_item_taxable_flag =  ' || l_item_taxable_flag );
1087                      END IF;
1088 
1089                      IF (l_item_taxable_flag  = 'N' or l_tax_classification_code is not null) THEN
1090                         l_tax_classification_found := TRUE;
1091                         IF (g_level_statement >= g_current_runtime_level ) THEN
1092                	           FND_LOG.STRING(g_level_statement,
1093                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1094                                           'l_tax_classification_code =='||l_tax_classification_code);
1095                         END IF;
1096                         exit Po_Tax_Loop;
1097                      END IF;
1098                   END IF;
1099 
1100                   IF (potaxtab (i) = 'SHIP_FROM_PARTY_SITE') THEN
1101                      IF (g_level_statement >= g_current_runtime_level ) THEN
1102      	                FND_LOG.STRING(g_level_statement,
1103                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1104                                        'Getting tax code from supplier site');
1105      	                FND_LOG.STRING(g_level_statement,
1106                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1107                                        'Calling get_site_tax ');
1108                      END IF;
1109                      l_tax_classification_code := get_site_tax (
1110                                                      p_vendor_site_id,
1111    					             l_curr_calling_sequence);
1112                      IF (l_tax_classification_code is not NULL) THEN
1113                         l_tax_classification_found := TRUE;
1114                         IF (g_level_statement >= g_current_runtime_level ) THEN
1115                   	   FND_LOG.STRING(g_level_statement,
1116                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1117                                           'l_tax_classification_code =='||l_tax_classification_code);
1118                         END IF;
1119                         exit Po_Tax_Loop;
1120                      END IF;
1121                   END IF;
1122 
1123                   IF (potaxtab (i) = 'SHIP_FROM_PARTY') THEN
1124                      IF (g_level_statement >= g_current_runtime_level ) THEN
1125   	                FND_LOG.STRING(g_level_statement,
1126                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1127                                        'Getting tax code from supplier');
1128   	                FND_LOG.STRING(g_level_statement,
1129                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1130                                        'Calling get_vendor_tax ');
1131                      END IF;
1132                      l_tax_classification_code := get_vendor_tax (
1133                                                      p_vendor_id,
1134 					             l_curr_calling_sequence);
1135                      IF (l_tax_classification_code is not NULL) THEN
1136                         l_tax_classification_found := TRUE;
1137                         IF (g_level_statement >= g_current_runtime_level ) THEN
1138                   	   FND_LOG.STRING(g_level_statement,
1139                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1140                                           'l_tax_classification_code =='||l_tax_classification_code);
1141                         END IF;
1142                         exit Po_Tax_Loop;
1143                      END IF;
1144                   END IF;
1145 
1146                   IF (potaxtab (i) = 'FINANCIAL_OPTIONS') THEN
1147                      IF (g_level_statement >= g_current_runtime_level ) THEN
1148   	                FND_LOG.STRING(g_level_statement,
1149                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1150                                        'Getting tax code from financial system parameters');
1151   	                FND_LOG.STRING(g_level_statement,
1152                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1153                                        'sysinfo.po_info.tax_classification_code  =='
1154                                            ||sysinfo.po_info.tax_classification_code);
1155                      END IF;
1156                      l_tax_classification_code := sysinfo.po_info.tax_classification_code;
1157                      IF (l_tax_classification_code is not NULL) THEN
1158                         l_tax_classification_found := TRUE;
1159                         IF (g_level_statement >= g_current_runtime_level ) THEN
1160                	           FND_LOG.STRING(g_level_statement,
1161                                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1162                                        'l_tax_classification_code =='||l_tax_classification_code);
1163                         END IF;
1164                         exit Po_Tax_Loop;
1165                      END IF;
1166                   END IF;
1167 
1168                END IF;
1169            END LOOP Po_Tax_Loop;
1170         END IF; -- search_for_po_tax
1171     ELSIF (APPL_SHORT_NAME = 'IGC') THEN -- Bug 6510307
1172 
1173 	IF (search_cc_def_hier = TRUE) THEN
1174 
1175            IF (g_level_statement >= g_current_runtime_level ) THEN
1176               FND_LOG.STRING(g_level_statement,
1177                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1178                              'Getting tax code for CC');
1179            END IF;
1180 
1181            l_count := cctaxtab.COUNT;
1182 
1183            <<Cc_Tax_Loop>>
1184            FOR i in 1..l_count  LOOP
1185                IF (cctaxtab (i) is  NULL) THEN
1186                   --
1187                   -- default hierachy options from 1 to 7 can not
1188                   -- have gap, if the current one is NULL, the
1189                   -- rest would be NULL, there is no need to
1190                   -- continue looping
1191                   --
1192                  exit Cc_Tax_Loop;
1193                ELSE
1194                  --  cctaxtab (i) is not NULL
1195                     IF (cctaxtab (i) = 'SHIP_FROM_PARTY_SITE') THEN
1196                         IF (g_level_statement >= g_current_runtime_level ) THEN
1197          	           FND_LOG.STRING(g_level_statement,
1198                                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1199                                           'Getting tax code from supplier site');
1200                         END IF;
1201                         l_tax_classification_code := get_site_tax (
1202                                                         p_vendor_site_id,
1203 					                l_curr_calling_sequence);
1204                         IF (l_tax_classification_code is not NULL) THEN
1205                            l_tax_classification_found := TRUE;
1206                            IF (g_level_statement >= g_current_runtime_level ) THEN
1207                               FND_LOG.STRING(g_level_statement,
1208                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1209                                              'l_tax_classification_code =='
1210                                               ||l_tax_classification_code);
1211                            END IF;
1212                            exit Cc_Tax_Loop;
1213                         END IF;
1214                      END IF;
1215 
1216 		      IF (cctaxtab (i) = 'SHIP_FROM_PARTY') THEN
1217                         IF (g_level_statement >= g_current_runtime_level ) THEN
1218                 	    FND_LOG.STRING(g_level_statement,
1219                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1220                                            'Getting tax code from supplier');
1221                         END IF;
1222                         l_tax_classification_code := get_vendor_tax (
1223                                                         p_vendor_id,
1224        					                l_curr_calling_sequence);
1225                         IF (l_tax_classification_code is not NULL) THEN
1226                            l_tax_classification_found := TRUE;
1227                            IF (g_level_statement >= g_current_runtime_level ) THEN
1228                               FND_LOG.STRING(g_level_statement,
1229                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1230                                              'l_tax_classification_code =='
1231                                                  ||l_tax_classification_code);
1232                            END IF;
1233                            exit Cc_Tax_Loop;
1234                         END IF;
1235                      END IF;
1236 
1237 		       IF (cctaxtab (i) = 'FINANCIAL_OPTIONS') THEN
1238                         IF (g_level_statement >= g_current_runtime_level ) THEN
1239          	            FND_LOG.STRING(g_level_statement,
1240                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1241                                            'Getting tax code from financial system parameters');
1242          	            FND_LOG.STRING(g_level_statement,
1243                                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1244                                            'sysinfo.vat_code =='
1245                                             ||sysinfo.cc_info.tax_classification_code );
1246                         END IF;
1247                         l_tax_classification_code := sysinfo.cc_info.tax_classification_code;
1248                         IF (l_tax_classification_code is not NULL) THEN
1249                            l_tax_classification_found := TRUE;
1250                            IF (g_level_statement >= g_current_runtime_level ) THEN
1251                               FND_LOG.STRING(g_level_statement,
1252                                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1253                                              'l_tax_classification_code =='
1254                                               ||l_tax_classification_code);
1255                            END IF;
1256                            exit Cc_Tax_Loop;
1257                         END IF;
1258                      END IF;
1259                END IF;
1260            END LOOP cc_Tax_Loop;
1261         END IF; -- search_for_cc_tax
1262 
1263      END IF; -- appl_short_name
1264    END IF; -- tax_code_found
1265 
1266    IF (g_level_statement >= g_current_runtime_level ) THEN
1267       FND_LOG.STRING(g_level_statement,
1268                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1269                      'After Po_Tax_Loop ,l_tax_classification_code  =='
1270                       ||l_tax_classification_code);
1271    END IF;
1272 
1273    IF (nvl (p_tax_user_override_flag, 'N') <> 'Y') THEN
1274       IF (g_level_statement >= g_current_runtime_level ) THEN
1275       	 FND_LOG.STRING(g_level_statement,
1276                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1277                         'p_tax_user_override_flag =='||p_tax_user_override_flag);
1278    	 FND_LOG.STRING(g_level_statement,
1279                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1280                         'l_tax_classification_code =='||l_tax_classification_code);
1281       END IF;
1282       IF (l_tax_classification_code is not null) THEN
1283    	 p_tax_classification_code := l_tax_classification_code;
1284       END IF;
1285    END IF;
1286    IF (g_level_statement >= g_current_runtime_level ) THEN
1287    	FND_LOG.STRING(g_level_statement,
1288                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1289                        'p_tax_classification_code  =='||p_tax_classification_code);
1290    	FND_LOG.STRING(g_level_statement,
1291                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.END',
1292                         'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (-)');
1293    END IF;
1294 
1295 EXCEPTION
1296   WHEN NO_DATA_FOUND THEN
1297        IF (g_level_unexpected >= g_current_runtime_level ) THEN
1298   	  FND_LOG.STRING(g_level_unexpected,
1299                          'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1300                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80) );
1301        END IF;
1302        IF (l_tax_classification_found = FALSE ) THEN
1303 	  RAISE NO_DATA_FOUND;
1304        END IF;
1305   WHEN OTHERS THEN
1306        IF (SQLCODE <> -20001) THEN
1307          IF (g_level_unexpected >= g_current_runtime_level ) THEN
1308           FND_LOG.STRING(g_level_unexpected,
1309                          'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1310                          sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80) );
1311          END IF;
1312           IF (appl_short_name = 'SQLAP') THEN
1313              FND_MESSAGE.SET_NAME('SQLAP', 'AP_DEBUG');
1314              FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1315              FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
1316              FND_MESSAGE.SET_TOKEN('PARAMETERS',
1317 	          ' p_ref_doc_application_id = '|| to_char (p_ref_doc_application_id) ||
1318                  ', p_ref_doc_entity_code = '||p_ref_doc_entity_code ||
1319                  ',p_ref_doc_event_class_code = '||p_ref_doc_event_class_code ||
1320                  ',p_ref_doc_trx_id = '||TO_CHAR(p_ref_doc_trx_id) ||
1321                  ',p_ref_doc_line_id = '||TO_CHAR(p_ref_doc_line_id) ||
1322                  ',p_ref_doc_trx_level_type = '||p_ref_doc_trx_level_type ||
1323 	         ', p_vendor_id = '|| to_char (p_vendor_id) ||
1324 	         ', p_vendor_site_id = '|| to_char (p_vendor_site_id) ||
1325 	         ', p_code_combination_id = '|| to_char (p_code_combination_id) ||
1326 	         ', p_concatenated_segments = '||p_concatenated_segments ||
1327                  ', p_templ_tax_classification_cd = '||p_templ_tax_classification_cd||
1328 	         ', p_tax_classification_code = '||p_tax_classification_code ||
1329                  ', p_allow_tax_code_override_flag = '||p_allow_tax_code_override_flag ||
1330      	         ', APPL_SHORT_NAME = '||APPL_SHORT_NAME ||
1331 	         ', FUNC_SHORT_NAME = '||FUNC_SHORT_NAME ||
1332 	         ', p_calling_sequence = '||p_calling_sequence);
1333 
1334           ELSIF (appl_short_name = 'PO') THEN --Bug 6510307
1335              FND_MESSAGE.SET_NAME('PO', 'PO_DEBUG');
1336              FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1337              FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
1338              FND_MESSAGE.SET_TOKEN('PARAMETERS',
1339 	         'p_ship_to_location_id = '||to_char (p_ship_to_location_id) ||
1340 	         ', p_ship_to_loc_org_id = '||to_char (p_ship_to_loc_org_id) ||
1341 	         ', p_inventory_item_id = '||to_char (p_inventory_item_id) ||
1342 	         ', p_item_org_id = '||to_char (p_item_org_id) ||
1343 	         ', p_vendor_id = '|| to_char (p_vendor_id) ||
1344 	         ', p_vendor_site_id = '|| to_char (p_vendor_site_id) ||
1345 	         ', p_tax_classification_code = '||p_tax_classification_code ||
1346 	         ', APPL_SHORT_NAME = '||APPL_SHORT_NAME ||
1347 	         ', FUNC_SHORT_NAME = '||FUNC_SHORT_NAME ||
1348 	         ', p_calling_sequence = '||p_calling_sequence);
1349 
1350 	   ELSE --Bug 6510307
1351 	     FND_MESSAGE.SET_NAME('IGC', 'IGC_DEBUG');
1352              FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1353              FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
1354              FND_MESSAGE.SET_TOKEN('PARAMETERS',
1355 	          ' p_ref_doc_application_id = '|| to_char (p_ref_doc_application_id) ||
1356                  ', p_ref_doc_entity_code = '||p_ref_doc_entity_code ||
1357                  ',p_ref_doc_event_class_code = '||p_ref_doc_event_class_code ||
1358                  ',p_ref_doc_trx_id = '||TO_CHAR(p_ref_doc_trx_id) ||
1359                  ',p_ref_doc_line_id = '||TO_CHAR(p_ref_doc_line_id) ||
1360                  ',p_ref_doc_trx_level_type = '||p_ref_doc_trx_level_type ||
1361 	         ', p_vendor_id = '|| to_char (p_vendor_id) ||
1362 	         ', p_vendor_site_id = '|| to_char (p_vendor_site_id) ||
1363 	         ', p_code_combination_id = '|| to_char (p_code_combination_id) ||
1364 	         ', p_concatenated_segments = '||p_concatenated_segments ||
1365                  ', p_templ_tax_classification_cd = '||p_templ_tax_classification_cd||
1366 	         ', p_tax_classification_code = '||p_tax_classification_code ||
1367                  ', p_allow_tax_code_override_flag = '||p_allow_tax_code_override_flag ||
1368      	         ', APPL_SHORT_NAME = '||APPL_SHORT_NAME ||
1369 	         ', FUNC_SHORT_NAME = '||FUNC_SHORT_NAME ||
1370 	         ', p_calling_sequence = '||p_calling_sequence);
1371 
1372 
1373           END IF;
1374        END IF;
1375        APP_EXCEPTION.RAISE_EXCEPTION;
1376 END get_default_tax_classification;
1377 
1378 
1379 ------------------------------------------------------------------
1380 --
1381 -- bug#4891362- overloaded version
1382 --
1383 
1384 PROCEDURE  get_default_tax_classification(
1385    p_ref_doc_application_id             IN  zx_lines_det_factors.ref_doc_application_id%TYPE,
1386    p_ref_doc_entity_code                IN  zx_lines_det_factors.ref_doc_entity_code%TYPE,
1387    p_ref_doc_event_class_code           IN  zx_lines_det_factors.ref_doc_event_class_code%TYPE,
1388    p_ref_doc_trx_id                     IN  zx_lines_det_factors.ref_doc_trx_id%TYPE,
1389    p_ref_doc_line_id                    IN  zx_lines_det_factors.ref_doc_line_id%TYPE,
1390    p_ref_doc_trx_level_type             IN  zx_lines_det_factors.ref_doc_trx_level_type%TYPE,
1391    p_vendor_id				IN  po_vendors.vendor_id%TYPE,
1392    p_vendor_site_id 			IN  po_vendor_sites.vendor_site_id%TYPE,
1393    p_code_combination_id  		IN  gl_code_combinations.code_combination_id%TYPE,
1394    p_concatenated_segments		IN  varchar2,
1395    p_templ_tax_classification_cd        IN  varchar2,
1396    p_ship_to_location_id		IN  hr_locations_all.location_id%TYPE,
1397    p_ship_to_loc_org_id   		IN  mtl_system_items.organization_id%TYPE,
1398    p_inventory_item_id   		IN  mtl_system_items.inventory_item_id%TYPE,
1399    p_item_org_id   			IN  mtl_system_items.organization_id%TYPE,
1400    p_tax_classification_code		IN  OUT NOCOPY VARCHAR2,
1401    p_allow_tax_code_override_flag           OUT NOCOPY zx_acct_tx_cls_defs.allow_tax_code_override_flag%TYPE,
1402    p_tax_user_override_flag		IN  VARCHAR2,
1403    p_user_tax_name	       		IN  VARCHAR2,
1404    --p_legal_entity_id                    IN  zx_lines.legal_entity_id%TYPE,
1405    APPL_SHORT_NAME			IN  fnd_application.application_short_name%TYPE,
1406    FUNC_SHORT_NAME			IN  VARCHAR2,
1407    p_calling_sequence			IN  VARCHAR2,
1408    p_event_class_code                   IN  VARCHAR2,
1409    p_entity_code                        IN  VARCHAR2,
1410    p_application_id                     IN  NUMBER,
1411    p_internal_organization_id           IN  NUMBER) IS
1412 
1413 BEGIN
1414 
1415   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
1416 
1417    IF (g_level_statement >= g_current_runtime_level ) THEN
1418       FND_LOG.STRING(g_level_statement,
1419                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.BEGIN',
1420 
1421                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (+)');
1422       FND_LOG.STRING(g_level_statement,
1423                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification',
1424 
1425                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: overloaded version 2');
1426 
1427    END IF;
1428    Initialize; --Bug 5712279
1429    --
1430    -- set default value
1431    --
1432 
1433    ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification(
1434                                            p_ref_doc_application_id,
1435                                            p_ref_doc_entity_code,
1436                                            p_ref_doc_event_class_code,
1437                                            p_ref_doc_trx_id,
1438                                            p_ref_doc_line_id,
1439                                            p_ref_doc_trx_level_type,
1440 					   p_vendor_id,
1441 					   p_vendor_site_id,
1442 					   p_code_combination_id,
1443 				   	   p_concatenated_segments,
1444                                            p_templ_tax_classification_cd,
1445 					   p_ship_to_location_id,
1446 					   p_ship_to_loc_org_id,
1447 					   p_inventory_item_id,
1448 					   p_item_org_id ,
1449 					   p_tax_classification_code,
1450 					   p_allow_tax_code_override_flag,
1451 					   p_tax_user_override_flag,  --'N',
1452 					   p_user_tax_name,    --null,
1453                                            null, --p_legal_entity_id,
1454 					   APPL_SHORT_NAME,
1455 					   FUNC_SHORT_NAME,
1456 					   p_calling_sequence,
1457                                            p_event_class_code,
1458                                            p_entity_code,
1459                                            p_application_id,
1460                                            p_internal_organization_id);
1461    IF (g_level_statement >= g_current_runtime_level ) THEN
1462       FND_LOG.STRING(g_level_statement,
1463                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_default_tax_classification.END',
1464 
1465                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_default_tax_classification (-)');
1466    END IF;
1467 
1468 END get_default_tax_classification;
1469 
1470 -------------------------------------------------------------------------------
1471 --
1472 -- PRIVATE FUNCTION
1473 -- get_input_tax_classif_code
1474 --
1475 -- DESCRIPTION
1476 -- This function will look for the tax code that is specified at the
1477 -- po shipment level, if the system options specify that tax is defaulted
1478 -- from this level. It will return the tax code if one is found for the
1479 -- po shipment and the given date. It returns null if a valid tax code is
1480 -- not found.
1481 --
1482 -- RETURNS
1483 -- Tax code if one is found at the shipment level.
1484 -- Null if a valid tax code is not found.
1485 --
1486 -- CALLED FROM
1487 -- get_default_tax_classification()
1488 --
1489 -- HISTORY
1490 -- 15-JUL-97  Fiona Purves created based on AR API.
1491 -- 11-MAY-05  Phong La     modified for bug#4310278, po_line_locations
1492 --                         will no longer carry tax columns, need to
1493 --                         get input_tax_classification_code from
1494 --                         zx_lines_det_factors
1495 -------------------------------------------------------------------------------
1496 
1497 FUNCTION  get_input_tax_classif_code (
1498   --p_line_location_id	IN  po_line_locations.line_location_id%TYPE,
1499   p_ref_doc_application_id   IN  zx_lines_det_factors.ref_doc_application_id%TYPE,
1500   p_ref_doc_entity_code      IN  zx_lines_det_factors.ref_doc_entity_code%TYPE,
1501   p_ref_doc_event_class_code IN  zx_lines_det_factors.ref_doc_event_class_code%TYPE,
1502   p_ref_doc_trx_id           IN  zx_lines_det_factors.ref_doc_trx_id%TYPE,
1503   p_ref_doc_line_id          IN  zx_lines_det_factors.ref_doc_line_id%TYPE,
1504   p_ref_doc_trx_level_type   IN  zx_lines_det_factors.ref_doc_trx_level_type%TYPE,
1505   p_calling_sequence	   IN varchar2) RETURN VARCHAR2 IS
1506 
1507   l_curr_calling_sequence 	VARCHAR2(2000);
1508   l_tax_classification_code	VARCHAR2(30);
1509 
1510 -- NOTE: TAX_CODE_ID column in PO_LINE_LOCATIONS should be replaced
1511 --       with tax classification code and the following query needs
1512 --       to replace tax_code_id with right column
1513 /*
1514  * bug#4310278 get input_tax_classification_code from
1515  * zx_lines_det_factors
1516   CURSOR sel_input_tax_cls_cd IS
1517   SELECT tc.lookup_code
1518     FROM fnd_lookups tc,
1519 	 po_line_locations ll
1520    WHERE ll.line_location_id = p_line_location_id
1521      AND tc.lookup_code = ll.tax_code_id -- replace with classification_code
1522      AND tc.lookup_type = 'ZX_INPUT_CLASSIFICATIONS'
1523      AND nvl(tc.enabled_flag,'Y') = 'Y';
1524 */
1525 
1526   CURSOR sel_input_tax_cls_cd
1527     (c_ref_doc_application_id    ZX_LINES_DET_FACTORS.application_id%TYPE,
1528      c_ref_doc_entity_code       ZX_LINES_DET_FACTORS.entity_code%TYPE,
1529      c_ref_doc_event_class_code  ZX_LINES_DET_FACTORS.event_class_code%TYPE,
1530      c_ref_doc_trx_id            ZX_LINES_DET_FACTORS.trx_id%TYPE,
1531      c_ref_doc_line_id           ZX_LINES_DET_FACTORS.trx_line_id%TYPE,
1532      c_ref_doc_trx_level_type    ZX_LINES_DET_FACTORS.trx_level_type%TYPE)
1533    IS
1534     SELECT input_tax_classification_code
1535       FROM zx_lines_det_factors
1536       WHERE application_id   = c_ref_doc_application_id
1537         AND entity_code      = c_ref_doc_entity_code
1538         AND event_class_code = c_ref_doc_event_class_code
1539         AND trx_id           = c_ref_doc_trx_id
1540         AND trx_line_id      = c_ref_doc_line_id
1541         AND trx_level_type   = c_ref_doc_trx_level_type;
1542 
1543 BEGIN
1544 
1545   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
1546 
1547   IF (g_level_statement >= g_current_runtime_level ) THEN
1548      FND_LOG.STRING(g_level_statement,
1549                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_input_tax_classif_code.BEGIN',
1550                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_input_tax_classif_code (+)');
1551      FND_LOG.STRING(g_level_statement,
1552                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_input_tax_classif_code',
1553 
1554                     'p_calling_sequence == >'||p_calling_sequence);
1555   END IF;
1556 
1557   debug_loc := 'get_input_tax_classif_code';
1558   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
1559 
1560   l_tax_classification_code := NULL;
1561 
1562   OPEN sel_input_tax_cls_cd
1563              (p_ref_doc_application_id,
1564               p_ref_doc_entity_code,
1565               p_ref_doc_event_class_code,
1566               p_ref_doc_trx_id,
1567               p_ref_doc_line_id,
1568               p_ref_doc_trx_level_type);
1569   FETCH sel_input_tax_cls_cd INTO l_tax_classification_code;
1570   CLOSE sel_input_tax_cls_cd;
1571 
1572   IF (g_level_statement >= g_current_runtime_level ) THEN
1573      FND_LOG.STRING(g_level_statement,
1574                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_input_tax_classif_code',
1575 
1576                     'l_tax_classification_code  =='||l_tax_classification_code);
1577      FND_LOG.STRING(g_level_statement,
1578                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_input_tax_classif_code.END',
1579                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_input_tax_classif_code (-)');
1580   END IF;
1581 
1582   RETURN (l_tax_classification_code);
1583 
1584   EXCEPTION
1585     WHEN OTHERS THEN
1586       FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
1587       FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'get_input_tax_classif_code- '||
1588                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
1589       FND_MSG_PUB.Add;
1590       IF (g_level_unexpected >= g_current_runtime_level ) THEN
1591         FND_LOG.STRING(g_level_unexpected,
1592                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_input_tax_classif_code',
1593                         sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
1594       END IF;
1595       IF (sel_input_tax_cls_cd%ISOPEN ) THEN
1596          CLOSE sel_input_tax_cls_cd;
1597       END IF;
1598       RAISE;
1599 END get_input_tax_classif_code;
1600 
1601 
1602 -------------------------------------------------------------------------------
1603 --
1604 -- PRIVATE FUNCTION
1605 -- get_site_tax
1606 --
1607 -- DESCRIPTION
1608 -- This function will look for the tax code that is specified at the
1609 -- supplier site level, if the system options specify that tax is defaulted
1610 -- from this level. It will return the tax code if one is found for the
1611 -- supplier site and the given date. It returns null if a valid tax code is
1612 -- not found.
1613 --
1614 -- RETURNS
1615 -- Tax code if one is found at the supplier site level
1616 -- Null if a valid tax code is not found.
1617 --
1618 -- CALLED FROM
1619 -- get_default_tax_classification()
1620 --
1621 -- HISTORY
1622 -- 15-JUL-97  Fiona Purves created based on AR API.
1623 -- 07-DEC-05  Phong La     bug#4868489- changed party_type_code
1624 --                         to THIRD_PARTY_SITE
1625 -------------------------------------------------------------------------------
1626 
1627 FUNCTION  get_site_tax (
1628   p_vendor_site_id	     IN  po_vendor_sites.vendor_site_id%TYPE,
1629   p_calling_sequence	     IN  varchar2) RETURN VARCHAR2 IS
1630 
1631   l_curr_calling_sequence 	VARCHAR2(2000);
1632   l_tax_classification_code	VARCHAR2(30);
1633 
1634   -- Bug#5066122
1635   l_party_site_id               NUMBER;
1636   l_count                       NUMBER;
1637 
1638   CURSOR sel_site_tax_sup_site
1639     (c_vendor_site_id   NUMBER)
1640   IS
1641   SELECT vat_code, party_site_id
1642     FROM ap_supplier_sites
1643    WHERE vendor_site_id = c_vendor_site_id;
1644 
1645   CURSOR sel_site_tax_ptp
1646     (c_party_site_id   NUMBER)
1647   IS
1648   SELECT vs.tax_classification_code
1649     FROM zx_party_tax_profile vs,
1650          zx_input_classifications_v tc
1651    WHERE vs.party_id = c_party_site_id
1652      AND vs.party_type_code = 'THIRD_PARTY_SITE'
1653      AND vs.tax_classification_code = tc.lookup_code
1654      AND tc.lookup_type = 'ZX_INPUT_CLASSIFICATIONS'
1655      AND nvl(tc.enabled_flag,'Y') = 'Y'
1656      AND tc.org_id in (sysinfo.org_id,-99);
1657 
1658 BEGIN
1659 
1660   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
1661 
1662   IF (g_level_statement >= g_current_runtime_level ) THEN
1663      FND_LOG.STRING(g_level_statement,
1664                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax.BEGIN',
1665                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_site_tax (+)');
1666      FND_LOG.STRING(g_level_statement,
1667                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax',
1668                     'p_vendor_site_id == >'||to_char(p_vendor_site_id));
1669      FND_LOG.STRING(g_level_statement,
1670                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax',
1671                     'p_calling_sequence == >'||p_calling_sequence);
1672   END IF;
1673   debug_loc := 'Get_Site_Tax';
1674   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
1675   IF (g_level_statement >= g_current_runtime_level ) THEN
1676   	FND_LOG.STRING(g_level_statement,
1677                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax',
1678                         'p_calling_sequence  =='||p_calling_sequence);
1679   END IF;
1680 
1681   l_tax_classification_code := NULL;
1682   l_party_site_id           := NULL;
1683 
1684   -- Bug#5066122
1685 
1686   IF p_vendor_site_id IS NOT NULL THEN
1687     OPEN sel_site_tax_sup_site(p_vendor_site_id);
1688     FETCH sel_site_tax_sup_site INTO
1689               l_tax_classification_code,
1690               l_party_site_id;
1691     CLOSE sel_site_tax_sup_site;
1692   END IF;
1693 
1694   IF l_tax_classification_code IS NOT NULL THEN
1695     --
1696     -- check if tax_classification_code is valid in fnd_lookups
1697     --
1698     validate_tax_classif_code(l_tax_classification_code,
1699                               l_count);
1700 
1701     IF l_count =  0 THEN
1702       --
1703       -- l_tax_classification_code is no longer valid
1704       -- need to get it from zx_party_tax_profiles
1705       l_tax_classification_code := NULL;
1706     END IF;
1707   END IF;
1708 
1709   IF (l_tax_classification_code IS NULL AND
1710       l_party_site_id IS NOT NULL) THEN
1711     OPEN sel_site_tax_ptp(l_party_site_id);
1712     FETCH sel_site_tax_ptp INTO l_tax_classification_code;
1713     CLOSE sel_site_tax_ptp;
1714   END IF;
1715 
1716   IF (g_level_statement >= g_current_runtime_level ) THEN
1717      FND_LOG.STRING(g_level_statement,
1718                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.G
1719 et_Vendor_Tax',
1720                     'l_party_site_id == >'||to_char(l_party_site_id));
1721      FND_LOG.STRING(g_level_statement,
1722                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax',
1723                     'l_tax_classification_code  =='||l_tax_classification_code);
1724      FND_LOG.STRING(g_level_statement,
1725                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax.END',
1726                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_site_tax (-)');
1727   END IF;
1728 
1729   RETURN (l_tax_classification_code);
1730 
1731   EXCEPTION
1732     WHEN OTHERS THEN
1733       FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
1734       FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'Get_site_tax- '||
1735                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
1736       FND_MSG_PUB.Add;
1737       IF (g_level_unexpected >= g_current_runtime_level ) THEN
1738         FND_LOG.STRING(g_level_unexpected,
1739                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_site_tax',
1740                         sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
1741       END IF;
1742       IF (sel_site_tax_sup_site%ISOPEN ) THEN
1743         CLOSE sel_site_tax_sup_site;
1744       END IF;
1745       IF (sel_site_tax_ptp%ISOPEN ) THEN
1746         CLOSE sel_site_tax_ptp;
1747       END IF;
1748       RAISE;
1749 END get_site_tax;
1750 
1751 -------------------------------------------------------------------------------
1752 --
1753 -- PRIVATE FUNCTION
1754 -- get_vendor_tax
1755 --
1756 -- DESCRIPTION
1757 -- This function will look for the tax code that is specified at the
1758 -- supplier level, if the system options specify that tax is defaulted
1759 -- from this level. It will return the tax code if one is found for the
1760 -- supplier and the given date. It returns null if a valid tax code is
1761 -- not found.
1762 --
1763 -- RETURNS
1764 -- Tax code if one is found at the supplier level and valid for the
1765 -- given date.  Null if a valid tax code is not found.
1766 --
1767 -- CALLED FROM
1768 -- get_default_tax_classification()
1769 --
1770 -- HISTORY
1771 -- 15-JUL-97  Fiona Purves created based on AR API.
1772 -- 07-DEC-05  Phong La     Bug#4868489- changed party_type_code
1773 --                         to THIRD_PARTY
1774 -------------------------------------------------------------------------------
1775 
1776 FUNCTION  get_vendor_tax (
1777     p_vendor_id		 IN  po_vendors.vendor_id%TYPE,
1778     p_calling_sequence	 IN  varchar2)
1779 
1780 RETURN VARCHAR2 IS
1781 
1782   l_curr_calling_sequence 	VARCHAR2(2000);
1783   l_tax_classification_code	VARCHAR2(30);
1784 
1785   -- Bug#5066122
1786   l_party_id                    NUMBER;
1787   l_count                       NUMBER;
1788 
1789   CURSOR sel_vendor_tax_sup
1790     (c_vendor_id       NUMBER)
1791   IS
1792   SELECT vat_code, party_id
1793     FROM ap_suppliers
1794    WHERE vendor_id = c_vendor_id;
1795 
1796   CURSOR sel_vendor_tax_ptp
1797     (c_party_id  NUMBER)
1798   IS
1799   SELECT v.tax_classification_code
1800     FROM zx_party_tax_profile v,
1801          zx_input_classifications_v tc
1802    WHERE v.party_id = c_party_id
1803      AND v.party_type_code = 'THIRD_PARTY'
1804      AND v.tax_classification_code = tc.lookup_code
1805      AND tc.lookup_type = 'ZX_INPUT_CLASSIFICATIONS'
1806      AND nvl(tc.enabled_flag,'Y') = 'Y'
1807      AND tc.org_id in (sysinfo.org_id,-99);
1808 
1809 BEGIN
1810   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
1811 
1812   IF (g_level_statement >= g_current_runtime_level ) THEN
1813      FND_LOG.STRING(g_level_statement,
1814                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_vendor_tax.BEGIN',
1815                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Vendor_Tax (+)');
1816      FND_LOG.STRING(g_level_statement,
1817                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax',
1818                     'p_vendor_id == >'||to_char(p_vendor_id));
1819      FND_LOG.STRING(g_level_statement,
1820                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax',
1821                     'p_calling_sequence == >'||p_calling_sequence);
1822   END IF;
1823   debug_loc := 'Get_Vendor_Tax';
1824   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
1825   IF (g_level_statement >= g_current_runtime_level ) THEN
1826      FND_LOG.STRING(g_level_statement,
1827                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax',
1828                     'l_curr_calling_sequence =='||l_curr_calling_sequence );
1829   END IF;
1830 
1831   l_tax_classification_code := NULL;
1832   l_party_id                := NULL;
1833 
1834   -- Bug#5066122
1835 
1836   IF p_vendor_id IS NOT NULL THEN
1837     OPEN sel_vendor_tax_sup(p_vendor_id);
1838     FETCH sel_vendor_tax_sup INTO
1839              l_tax_classification_code,
1840              l_party_id;
1841     CLOSE sel_vendor_tax_sup;
1842   END IF;
1843 
1844   IF l_tax_classification_code IS NOT NULL THEN
1845     --
1846     -- check if tax_classification_code is valid in fnd_lookups
1847     --
1848     validate_tax_classif_code(l_tax_classification_code,
1849                               l_count);
1850 
1851     IF l_count =  0 THEN
1852       --
1853       -- l_tax_classification_code is no longer valid
1854       -- need to get it from zx_party_tax_profiles
1855       l_tax_classification_code := NULL;
1856     END IF;
1857   END IF;
1858 
1859   IF (l_tax_classification_code IS NULL AND
1860       l_party_id IS NOT NULL) THEN
1861     OPEN sel_vendor_tax_ptp(l_party_id);
1862     FETCH sel_vendor_tax_ptp INTO l_tax_classification_code;
1863     CLOSE sel_vendor_tax_ptp;
1864   END IF;
1865 
1866   IF (g_level_statement >= g_current_runtime_level ) THEN
1867      FND_LOG.STRING(g_level_statement,
1868                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax',
1869                     'l_party_id == >'||to_char(l_party_id));
1870      FND_LOG.STRING(g_level_statement,
1871                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax',
1872                     'From get_vendor_tax ,l_tax_classification_code  =='
1873                      ||l_tax_classification_code);
1874      FND_LOG.STRING(g_level_statement,
1875                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax.END',
1876                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Vendor_Tax (-)');
1877   END IF;
1878 
1879   RETURN (l_tax_classification_code);
1880 
1881   EXCEPTION
1882     WHEN OTHERS THEN
1883       FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
1884       FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'Get_Vendor_Tax- '||
1885                             sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
1886       FND_MSG_PUB.Add;
1887       IF (g_level_unexpected >= g_current_runtime_level ) THEN
1888         FND_LOG.STRING(g_level_unexpected,
1889                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Vendor_Tax',
1890                         sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
1891       END IF;
1892       IF (sel_vendor_tax_sup%ISOPEN) THEN
1893         CLOSE sel_vendor_tax_sup;
1894       END IF;
1895       IF (sel_vendor_tax_ptp%ISOPEN) THEN
1896         CLOSE sel_vendor_tax_ptp;
1897       END IF;
1898 
1899       RAISE;
1900 END get_vendor_tax;
1901 
1902 -------------------------------------------------------------------------------
1903 --
1904 -- PRIVATE FUNCTION
1905 -- get_ship_to_location_tax
1906 --
1907 -- DESCRIPTION
1908 -- This function will look for the tax code that is specified at the
1909 -- ship-to location level, if the system options specify that tax is defaulted
1910 -- from this level. It will return the tax code if one is found for the
1911 -- ship-to location and the given date. It returns null if a valid tax code is
1912 -- not found.
1913 --
1914 -- The SELECT statement that retrieved the tax name was different in the
1915 -- workbenches and the server-side code, as follows:
1916 --
1917 -- In the Enter Purchase Orders and Enter Releases forms, the tax name
1918 -- was retrieved where the location_id matched the given location_id, and the
1919 -- inventory_organization_id matched the given ship_to_organization_id,
1920 -- or was null.
1921 -- In the AutoCreate and the Create Releases programs, the tax name was
1922 -- retrieved using the location_id only.
1923 -- The API will manage cases where a ship-to organization is passed or not.
1924 --
1925 -- RETURNS
1926 -- Tax code if one is found at the ship-to location level and valid for the
1927 -- given date.  Null if a valid tax code is not found.
1928 --
1929 -- CALLED FROM
1930 -- get_default_tax_classification()
1931 --
1932 -- HISTORY
1933 -- 15-JUL-97  Fiona Purves created based on AR API.
1934 -- 07-DEC-05  Phong La     bug#4868489- modified to get ptp_id from TCM api
1935 -------------------------------------------------------------------------------
1936 
1937 FUNCTION  get_ship_to_location_tax (
1938   p_ship_to_loc_id	IN  hr_locations_all.location_id%TYPE,
1939   p_ship_to_loc_org_id	IN  hr_locations_all.inventory_organization_id%TYPE,
1940   p_legal_entity_id     IN  zx_lines.legal_entity_id%TYPE,
1941   p_calling_sequence	IN  varchar2 )
1942 
1943 RETURN VARCHAR2 IS
1944   l_curr_calling_sequence 	VARCHAR2(2000);
1945   l_tax_classification_code	VARCHAR2(30);
1946   l_party_type_code             VARCHAR2(30);
1947   l_return_status               VARCHAR2(30);
1948   l_ptp_id                      ZX_PARTY_TAX_PROFILE.party_tax_profile_id%TYPE;
1949 
1950   CURSOR sel_ship_to_loc_tax
1951     (c_ptp_id    ZX_PARTY_TAX_PROFILE.party_tax_profile_id%TYPE)
1952   IS
1953   SELECT ptp.tax_classification_code
1954     FROM zx_party_tax_profile ptp,
1955          zx_input_classifications_v tc
1956    WHERE ptp.party_tax_profile_id = c_ptp_id
1957      AND ptp.tax_classification_code = tc.lookup_code
1958      AND tc.lookup_type = 'ZX_INPUT_CLASSIFICATIONS'
1959      AND nvl(tc.enabled_flag,'Y') = 'Y'
1960      AND tc.org_id in (sysinfo.org_id,-99);
1961 
1962   CURSOR get_ship_to_tax
1963     (c_ship_to_loc_id    HR_LOCATIONS_ALL.location_id%TYPE)
1964   IS
1965   SELECT hr.tax_name
1966     FROM hr_locations_all hr,
1967          zx_input_classifications_v tc
1968    WHERE hr.location_id = c_ship_to_loc_id
1969      AND hr.tax_name = tc.lookup_code
1970      AND tc.lookup_type IN ('ZX_INPUT_CLASSIFICATIONS', 'ZX_WEB_EXP_TAX_CLASSIFICATIONS')
1971      AND nvl(tc.enabled_flag,'Y') = 'Y'
1972      AND tc.org_id in (sysinfo.org_id,-99);
1973 
1974 BEGIN
1975 
1976   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
1977 
1978   IF (g_level_statement >= g_current_runtime_level ) THEN
1979      FND_LOG.STRING(g_level_statement,
1980                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax.BEGIN',
1981                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Ship_To_Location_Tax (+)');
1982   END IF;
1983   debug_loc := 'Get_Ship_To_Location_Tax';
1984   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
1985   IF (g_level_statement >= g_current_runtime_level ) THEN
1986      FND_LOG.STRING(g_level_statement,
1987                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
1988                     'Getting tax classification code from ship-to location');
1989      FND_LOG.STRING(g_level_statement,
1990                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
1991                     'p_ship_to_loc_id == > '||to_char(p_ship_to_loc_id ));
1992      FND_LOG.STRING(g_level_statement,
1993                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
1994                     'p_ship_to_loc_org_id   == >'||to_char(p_ship_to_loc_org_id ));
1995      FND_LOG.STRING(g_level_statement,
1996                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
1997                     'p_calling_sequence == > '|| p_calling_sequence );
1998   END IF;
1999 
2000   l_tax_classification_code := NULL;
2001   l_return_status := FND_API.G_RET_STS_SUCCESS;
2002 
2003   --
2004   -- get ptp id
2005   --
2006 
2007   l_party_type_code   := 'LEGAL_ESTABLISHMENT';
2008 
2009   ZX_TCM_PTP_PKG.get_ptp(
2010            p_party_id          => p_ship_to_loc_org_id, --Inventory Org Id
2011            p_Party_Type_Code   => l_party_type_code,    --Legal Establishment
2012            p_le_id             => p_legal_entity_id,    --Legal Entity ID
2013            p_inventory_loc     => p_ship_to_loc_id,     --Inventory Location ID
2014            p_ptp_id            => l_ptp_id,             -- ptp id
2015            p_return_status     => l_return_status);
2016 
2017   IF (g_level_statement >= g_current_runtime_level ) THEN
2018     FND_LOG.STRING(g_level_statement,
2019                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
2020                    'l_ptp_id = ' || TO_CHAR(l_ptp_id));
2021     FND_LOG.STRING(g_level_statement,
2022                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
2023                    'l_return_status = ' || l_return_status);
2024   END IF;
2025 
2026   IF (l_return_status <> FND_API.G_RET_STS_SUCCESS )THEN
2027       -- return NULL to caller
2028       RETURN l_tax_classification_code;
2029   END IF;
2030 
2031   OPEN sel_ship_to_loc_tax(l_ptp_id);
2032   FETCH sel_ship_to_loc_tax INTO l_tax_classification_code;
2033   CLOSE sel_ship_to_loc_tax;
2034 
2035   IF l_tax_classification_code IS NULL THEN
2036     OPEN get_ship_to_tax(p_ship_to_loc_id);
2037     FETCH get_ship_to_tax INTO l_tax_classification_code;
2038     CLOSE get_ship_to_tax;
2039   END IF;
2040 
2041   IF (g_level_statement >= g_current_runtime_level ) THEN
2042      FND_LOG.STRING(g_level_statement,
2043                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
2044                     'l_tax_classification_code  =='||l_tax_classification_code );
2045      FND_LOG.STRING(g_level_statement,
2046                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax.END',
2047                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Ship_To_Location_Tax (-)');
2048   END IF;
2049 
2050   RETURN (l_tax_classification_code);
2051 
2052 EXCEPTION
2053   WHEN OTHERS THEN
2054     FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
2055     FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'Get_Ship_To_Location_Tax- '||
2056                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
2057     FND_MSG_PUB.Add;
2058     IF (g_level_unexpected >= g_current_runtime_level ) THEN
2059       FND_LOG.STRING(g_level_unexpected,
2060                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_ship_to_location_tax',
2061                       sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
2062     END IF;
2063     IF (sel_ship_to_loc_tax%ISOPEN) THEN
2064       CLOSE sel_ship_to_loc_tax;
2065     END IF;
2066     RAISE;
2067 END get_ship_to_location_tax;
2068 
2069 -----------------------------------------------------------------------------
2070 --
2071 -- bug#4891362-  overloaded version
2072 --
2073 
2074 FUNCTION  get_ship_to_location_tax (
2075   p_ship_to_loc_id	IN  hr_locations_all.location_id%TYPE,
2076   p_ship_to_loc_org_id	IN  hr_locations_all.inventory_organization_id%TYPE,
2077   --p_legal_entity_id     IN  zx_lines.legal_entity_id%TYPE,
2078   p_calling_sequence	IN  varchar2 )
2079 
2080 RETURN VARCHAR2 IS
2081 
2082   l_tax_classification_code     VARCHAR2(30);
2083 
2084 BEGIN
2085 
2086   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
2087 
2088   IF (g_level_statement >= g_current_runtime_level ) THEN
2089      FND_LOG.STRING(g_level_statement,
2090                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax.BEGIN',
2091                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Ship_To_Location_Tax (+)');
2092      FND_LOG.STRING(g_level_statement,
2093                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax',
2094                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Ship_To_Location_Tax overloaded version');
2095 
2096   END IF;
2097 
2098   l_tax_classification_code := NULL;
2099 
2100   l_tax_classification_code := get_ship_to_location_tax(
2101                                     p_ship_to_loc_id,
2102                                     p_ship_to_loc_org_id,
2103                                     null,    --p_legal_entity_id,
2104                                     p_calling_sequence);
2105 
2106 
2107   IF (g_level_statement >= g_current_runtime_level ) THEN
2108      FND_LOG.STRING(g_level_statement,
2109                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Ship_To_Location_Tax.END',
2110                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Ship_To_Location_Tax (-)');
2111   END IF;
2112 
2113   RETURN (l_tax_classification_code);
2114 
2115 END get_ship_to_location_tax;
2116 
2117 --------------------------------------------------------------
2118 --
2119 -- bug#8717533
2120 --
2121 PROCEDURE  get_def_tax_classif_from_acc(
2122    p_ref_doc_application_id             IN  zx_lines_det_factors.ref_doc_application_id%TYPE,
2123    p_ref_doc_entity_code                IN  zx_lines_det_factors.ref_doc_entity_code%TYPE,
2124    p_ref_doc_event_class_code           IN  zx_lines_det_factors.ref_doc_event_class_code%TYPE,
2125    p_ref_doc_trx_id                     IN  zx_lines_det_factors.ref_doc_trx_id%TYPE,
2126    p_ref_doc_line_id                    IN  zx_lines_det_factors.ref_doc_line_id%TYPE,
2127    p_ref_doc_trx_level_type             IN  zx_lines_det_factors.ref_doc_trx_level_type%TYPE,
2128    p_vendor_id				                  IN  po_vendors.vendor_id%TYPE,
2129    p_vendor_site_id 		              	IN  po_vendor_sites.vendor_site_id%TYPE,
2130    p_code_combination_id  		          IN  gl_code_combinations.code_combination_id%TYPE,
2131    p_concatenated_segments		          IN  varchar2,
2132    p_templ_tax_classification_cd        IN  varchar2,
2133    p_ship_to_location_id		            IN  hr_locations_all.location_id%TYPE,
2134    p_ship_to_loc_org_id   		          IN  mtl_system_items.organization_id%TYPE,
2135    p_inventory_item_id   		            IN  mtl_system_items.inventory_item_id%TYPE,
2136    p_item_org_id   			                IN  mtl_system_items.organization_id%TYPE,
2137    p_tax_classification_code		        IN  OUT NOCOPY VARCHAR2,
2138    p_allow_tax_code_override_flag           OUT NOCOPY zx_acct_tx_cls_defs.allow_tax_code_override_flag%TYPE,
2139    p_tax_user_override_flag		          IN  VARCHAR2 DEFAULT 'N',
2140    p_user_tax_name	       		          IN  VARCHAR2 DEFAULT NULL,
2141    p_legal_entity_id                    IN  zx_lines.legal_entity_id%TYPE DEFAULT NULL,
2142    APPL_SHORT_NAME			                IN  fnd_application.application_short_name%TYPE,
2143    FUNC_SHORT_NAME			                IN  VARCHAR2,
2144    p_calling_sequence		              	IN  VARCHAR2,
2145    p_event_class_code                   IN  VARCHAR2,
2146    p_entity_code                        IN  VARCHAR2,
2147    p_application_id                     IN  NUMBER,
2148    p_internal_organization_id           IN  NUMBER,
2149    p_default_hierarchy                      OUT NOCOPY BOOLEAN) IS
2150 
2151  l_tax_classification_code      VARCHAR2(30);
2152  l_enforce_tax_from_acct_flag   VARCHAR2(1);
2153  l_enforce_tax_from_refdoc_flag VARCHAR2(1);
2154  l_enforced_tax_found	 	boolean := FALSE;
2155  l_tax_classification_found	boolean := FALSE;
2156  l_found                        boolean := FALSE;
2157  l_curr_calling_sequence 	VARCHAR2(2000);
2158  l_item_taxable_flag            VARCHAR2(1);
2159  -- Added the following variable as part of the fix for the bug 2608697 by zmohiudd.
2160  l_shipment_taxable_flag        VARCHAR2(1);
2161  l_count                        NUMBER;
2162  l_return_status                VARCHAR2(80);
2163 
2164 CURSOR sel_item_taxable_flag
2165          (c_inventory_item_id   mtl_system_items_b.inventory_item_id%TYPE,
2166           c_item_org_id         mtl_system_items_b.organization_id%TYPE,
2167           c_ship_to_loc_org_id  mtl_system_items_b.organization_id%TYPE) IS
2168 
2169  SELECT taxable_flag
2170    FROM mtl_system_items si
2171   WHERE si.inventory_item_id = c_inventory_item_id
2172     AND si.organization_id = nvl(c_ship_to_loc_org_id, c_item_org_id);
2173 
2174   CURSOR c_evnt_cls_options (c_org_id           NUMBER,
2175                              c_application_id   NUMBER,
2176                              c_entity_code      VARCHAR2,
2177                              c_event_class_code VARCHAR2) IS
2178   select enforce_tax_from_acct_flag,
2179          enforce_tax_from_ref_doc_flag
2180     from zx_evnt_cls_options
2181    where application_id = c_application_id
2182      and entity_code = c_entity_code
2183      and event_class_code = c_event_class_code
2184      and first_pty_org_id = (Select party_tax_profile_id
2185                                From zx_party_tax_profile
2186                               where party_id = c_org_id
2187                                 and party_type_code = 'OU')
2188      and sysdate >= effective_from
2189      and sysdate <= nvl(effective_to,sysdate)
2190      and enabled_flag = 'Y';
2191 
2192 BEGIN
2193 
2194   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
2195 
2196   IF (g_level_statement >= g_current_runtime_level ) THEN
2197   	FND_LOG.STRING(g_level_statement,
2198                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc.BEGIN',
2199                        'get_def_tax_classif_from_acc(+) ');
2200         FND_LOG.STRING(g_level_statement,
2201                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2202                        'p_ref_doc_application_id == >'||TO_CHAR(p_ref_doc_application_id));
2203         FND_LOG.STRING(g_level_statement,
2204                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2205                        'p_ref_doc_entity_code == >'||p_ref_doc_entity_code);
2206         FND_LOG.STRING(g_level_statement,
2207                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2208                        'p_ref_doc_event_class_code == >'||p_ref_doc_event_class_code);
2209         FND_LOG.STRING(g_level_statement,
2210                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2211                        'p_ref_doc_trx_id == >'||TO_CHAR(p_ref_doc_trx_id));
2212         FND_LOG.STRING(g_level_statement,
2213                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2214                        'p_ref_doc_line_id == >'||TO_CHAR(p_ref_doc_line_id));
2215         FND_LOG.STRING(g_level_statement,
2216                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2217                        'p_ref_doc_trx_level_type == >'||p_ref_doc_trx_level_type);
2218       	FND_LOG.STRING(g_level_statement,
2219                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2220                        'p_vendor_id  == >'       ||to_char(p_vendor_id ));
2221   	    FND_LOG.STRING(g_level_statement,
2222                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2223                        'p_vendor_site_id  == >'  ||to_char(p_vendor_site_id ));
2224   	    FND_LOG.STRING(g_level_statement,
2225                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2226                        'p_code_combination_id = >'||to_char(p_code_combination_id) );
2227   	    FND_LOG.STRING(g_level_statement,
2228                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2229                        'p_concatenated_segments== >'||p_concatenated_segments );
2230         FND_LOG.STRING(g_level_statement,
2231                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2232                        'p_templ_tax_classification_cd == >'||p_templ_tax_classification_cd);
2233   	    FND_LOG.STRING(g_level_statement,
2234                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2235                        'p_ship_to_location_id == >'||to_char(p_ship_to_location_id) );
2236   	    FND_LOG.STRING(g_level_statement,
2237                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2238                        'p_ship_to_loc_org_id  == >'||to_char(p_ship_to_loc_org_id) );
2239   	    FND_LOG.STRING(g_level_statement,
2240                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2241                        'p_inventory_item_id  == >'||to_char(p_inventory_item_id) );
2242   	    FND_LOG.STRING(g_level_statement,
2243                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2244                        'p_item_org_id  == >'     ||to_char( p_item_org_id));
2245   	    FND_LOG.STRING(g_level_statement,
2246                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2247                        'p_tax_classification_code  == >' ||p_tax_classification_code);
2248         FND_LOG.STRING(g_level_statement,
2249                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2250                        'p_allow_tax_code_override_flag ==>'|| p_allow_tax_code_override_flag);
2251   	    FND_LOG.STRING(g_level_statement,
2252                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2253                        'p_tax_user_override_flag  ==>'||p_tax_user_override_flag);
2254   	    FND_LOG.STRING(g_level_statement,
2255                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2256                        'p_user_tax_name  ==>'||p_user_tax_name);
2257         FND_LOG.STRING(g_level_statement,
2258                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2259                        'p_legal_entity_id ==>'||TO_CHAR(p_legal_entity_id));
2260   	    FND_LOG.STRING(g_level_statement,
2261                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2262                        'APPL_SHORT_NAME  == >'||APPL_SHORT_NAME );
2263   	    FND_LOG.STRING(g_level_statement,
2264                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2265                        'FUNC_SHORT_NAME   == >'||FUNC_SHORT_NAME );
2266   	    FND_LOG.STRING(g_level_statement,
2267                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2268                        'p_calling_sequence  == >'||p_calling_sequence );
2269   	    FND_LOG.STRING(g_level_statement,
2270                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2271                        'p_event_class_code  == >'||p_event_class_code );
2272   	    FND_LOG.STRING(g_level_statement,
2273                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2274                        'p_entity_code  == >'||p_entity_code );
2275         FND_LOG.STRING(g_level_statement,
2276                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2277                        'p_application_id == >'||TO_CHAR(p_application_id));
2278         FND_LOG.STRING(g_level_statement,
2279                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2280                        'p_internal_organization_id == >'||TO_CHAR(p_internal_organization_id));
2281 
2282   END IF;
2283 
2284   -- Bug#4090842- call populate ap/po default options here
2285   -- Initialize;
2286 
2287   --
2288   -- check if need to repopulate AP/PO/IGC default options
2289   --
2290   IF APPL_SHORT_NAME = 'SQLAP' THEN
2291     IF (sysinfo.ap_info.org_id IS NULL OR
2292         (sysinfo.ap_info.org_id <> p_internal_organization_id)) THEN
2293       pop_ap_def_option_hier(
2294                     p_internal_organization_id,
2295                     p_application_id,
2296                     p_event_class_code,
2297                     l_return_status);
2298 
2299       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2300         RETURN;
2301       END IF;
2302     END IF;
2303    END IF;
2304 
2305   l_tax_classification_found := FALSE;
2306 
2307   debug_loc := 'get_def_tax_classif_from_acc';
2308 
2309   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
2310 
2311   --
2312   -- Get Payables/Purchasing default tax code.
2313   -- Hierarchy for PO:  Ship-to Location, Item, Vendor, Vendor Site and System.
2314   -- Hierarchy for AP:  Purchase Order Shipment, Vendor, Vendor Site, Natural Account, System,
2315   -- and Template.
2316   -- Hierarchy for CC:  Vendor Site, Vendor and System.
2317   -- The search ends when a tax code is found.
2318   --
2319 
2320   --
2321   -- if use_tax_classification_flag is no, set tax_classification_code
2322   -- to NULL and return, no need to search the default hierachy
2323   --
2324 
2325   IF (APPL_SHORT_NAME = 'SQLAP' AND
2326       NOT search_for_ap_tax) THEN
2327     p_tax_classification_code := NULL;
2328     p_default_hierarchy := FALSE;
2329     RETURN;
2330   END IF;
2331 
2332   IF (p_tax_user_override_flag = 'Y') THEN
2333      -- User has overridden tax code and the user tax code should be used.
2334      -- If tax name is null, then this is an explicit request for a null
2335      -- tax name and null should be returned.
2336 
2337      p_tax_classification_code := p_user_tax_name;
2338      l_tax_classification_found := TRUE;
2339      p_default_hierarchy := FALSE;
2340   END IF;
2341 
2342   IF (g_level_statement >= g_current_runtime_level ) THEN
2343      FND_LOG.STRING(g_level_statement,
2344                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2345                     'l_tax_classification_code is found  =='||l_tax_classification_code);
2346   END IF;
2347 
2348   IF (l_tax_classification_found = FALSE) THEN
2349     IF (APPL_SHORT_NAME = 'SQLAP') THEN
2350       IF (search_ap_def_hier = TRUE) THEN
2351         IF (g_level_statement >= g_current_runtime_level ) THEN
2352               FND_LOG.STRING(g_level_statement,
2353                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2354                              'Getting Event Class Options');
2355         END IF;
2356         open c_evnt_cls_options (p_internal_organization_id,
2357                                  200,
2358                                  p_entity_code,
2359                                  p_event_class_code);
2360         fetch c_evnt_cls_options into l_enforce_tax_from_acct_flag,
2361                                       l_enforce_tax_from_refdoc_flag;
2362         close c_evnt_cls_options;
2363 
2364         IF (g_level_statement >= g_current_runtime_level ) THEN
2365               FND_LOG.STRING(g_level_statement,
2366                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2367                              'Entity Code:' || p_entity_code);
2368               FND_LOG.STRING(g_level_statement,
2369                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2370                              'Event Class Code:' || p_event_class_code);
2371               FND_LOG.STRING(g_level_statement,
2372                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2373                              'Enforce Tax From Account  ==' || l_enforce_tax_from_acct_flag);
2374        	      FND_LOG.STRING(g_level_statement,
2375                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2376                              'Getting tax code for AP ');
2377         END IF;
2378 
2379         IF (l_enforce_tax_from_refdoc_flag = 'Y') THEN
2380 	        -- Tax code from the PO shipment is enforced
2381 	        -- If a tax code exists for shipment then there is
2382 	        -- no need to search any further, as this takes
2383 	        -- precedence over the rest of the hierarchy.
2384 
2385           l_tax_classification_code := get_input_tax_classif_code (
2386                                              p_ref_doc_application_id,
2387                                              p_ref_doc_entity_code,
2388                                              p_ref_doc_event_class_code,
2389                                              p_ref_doc_trx_id,
2390                                              p_ref_doc_line_id,
2391                                              p_ref_doc_trx_level_type,
2392                                              l_curr_calling_sequence);
2393 
2394           IF (l_tax_classification_code is not NULL) THEN
2395 	          -- Tax found on PO shipment, do not search further
2396             l_enforced_tax_found := TRUE;
2397             p_default_hierarchy := FALSE;
2398             IF (g_level_statement >= g_current_runtime_level ) THEN
2399             	    FND_LOG.STRING(g_level_statement,
2400                                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2401                                    'l_tax_classification_code =='||l_tax_classification_code );
2402             END IF;
2403           END IF;
2404         ELSIF (l_enforce_tax_from_acct_flag = 'Y') THEN
2405           -- Tax code from the account is enforced
2406           -- If a tax code exists for this account and
2407           -- override of the tax code is not allowed then
2408           -- no need to search any further, as the non-overridable accounts take
2409           -- precedence over the rest of the tax defaulting hierarchy
2410           -- This includes both Input and Non-taxable accounts.
2411 
2412           IF (g_level_statement >= g_current_runtime_level ) THEN
2413                FND_LOG.STRING(g_level_statement,
2414                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2415                    'Tax from account is enforced');
2416                FND_LOG.STRING(g_level_statement,
2417                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2418                    ' Calling get_account_tax ');
2419           END IF;
2420           get_account_tax (p_code_combination_id,
2421 		                    	 p_concatenated_segments,
2422           			           p_tax_classification_code,
2423           			           p_allow_tax_code_override_flag,
2424           			           l_tax_classification_found,
2425           			           l_curr_calling_sequence);
2426           l_tax_classification_code := p_tax_classification_code;
2427           IF (g_level_statement >= g_current_runtime_level ) THEN
2428                FND_LOG.STRING(g_level_statement,
2429                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2430                    'l_tax_classification_code =='||l_tax_classification_code);
2431           END IF;
2432           IF (p_allow_tax_code_override_flag = 'N') THEN
2433             -- Override is not allowed, do not search further
2434             l_enforced_tax_found := TRUE;
2435             p_default_hierarchy := TRUE;
2436           END IF;
2437         END IF; -- ap_match_on_tax_flag
2438 
2439         IF (l_enforced_tax_found = FALSE ) THEN
2440           p_default_hierarchy := FALSE;
2441           l_count := aptaxtab.COUNT;
2442           <<Ap_Tax_Loop1>>
2443           FOR i in 1..l_count  LOOP
2444             IF (aptaxtab (i) = 'NATURAL_ACCOUNT') THEN
2445               p_default_hierarchy := TRUE;
2446               exit Ap_Tax_Loop1;
2447             END IF;
2448           END LOOP Ap_Tax_Loop1;
2449           IF NOT p_default_hierarchy THEN
2450             RETURN;
2451           END IF;
2452         END IF;
2453 
2454         IF (l_enforced_tax_found = FALSE ) THEN
2455           -- If tax is not enforced from the account, or is enforced but
2456           -- the tax code is overrideable, then continue the search
2457 
2458           l_count := aptaxtab.COUNT;
2459           <<Ap_Tax_Loop>>
2460           FOR i in 1..l_count  LOOP
2461             IF (aptaxtab (i) is NULL) THEN
2462               --
2463               -- default hierachy options from 1 to 7 can not
2464               -- have gap, if the current one is NULL, the
2465               -- rest would be NULL, there is no need to
2466               -- continue looping
2467               --
2468               p_default_hierarchy := FALSE;
2469               exit Ap_Tax_Loop;
2470             ELSE
2471               --  aptaxtab (i) is not NULL
2472 
2473    	          IF (aptaxtab (i) = 'REFERENCE_DOCUMENT') THEN
2474                 IF (g_level_statement >= g_current_runtime_level ) THEN
2475          	           FND_LOG.STRING(g_level_statement,
2476                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2477                         'Getting tax code from shipment');
2478          	           FND_LOG.STRING(g_level_statement,
2479                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2480                         'Calling get_input_tax_classif_code ');
2481                 END IF;
2482       	        l_tax_classification_code := get_input_tax_classif_code (
2483                                              p_ref_doc_application_id,
2484                                              p_ref_doc_entity_code,
2485                                              p_ref_doc_event_class_code,
2486                                              p_ref_doc_trx_id,
2487                                              p_ref_doc_line_id,
2488                                              p_ref_doc_trx_level_type,
2489                                              l_curr_calling_sequence);
2490 
2491                 IF (l_tax_classification_code IS NOT NULL) THEN
2492                   l_tax_classification_found := TRUE;
2493                   p_default_hierarchy := FALSE;
2494                   IF (g_level_statement >= g_current_runtime_level ) THEN
2495                       FND_LOG.STRING(g_level_statement,
2496                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2497                           'l_tax_classification_code ==' ||l_tax_classification_code);
2498                   END IF;
2499                   exit Ap_Tax_Loop;
2500                 END IF;
2501               END IF;
2502 
2503               IF (aptaxtab (i) = 'SHIP_FROM_PARTY_SITE') THEN
2504                 IF (g_level_statement >= g_current_runtime_level ) THEN
2505          	        FND_LOG.STRING(g_level_statement,
2506                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2507                      'Getting tax code from supplier site');
2508                 END IF;
2509                 l_tax_classification_code := get_site_tax (
2510                                                         p_vendor_site_id,
2511 					                                              l_curr_calling_sequence);
2512                 IF (l_tax_classification_code IS NOT NULL) THEN
2513                   l_tax_classification_found := TRUE;
2514                   p_default_hierarchy := FALSE;
2515                   IF (g_level_statement >= g_current_runtime_level ) THEN
2516                      FND_LOG.STRING(g_level_statement,
2517                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2518                        'l_tax_classification_code ==' ||l_tax_classification_code);
2519                   END IF;
2520                   exit Ap_Tax_Loop;
2521                 END IF;
2522               END IF;
2523 
2524               IF (aptaxtab (i) = 'SHIP_FROM_PARTY') THEN
2525                 IF (g_level_statement >= g_current_runtime_level ) THEN
2526              	    FND_LOG.STRING(g_level_statement,
2527                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2528                       'Getting tax code from supplier');
2529                 END IF;
2530                 l_tax_classification_code := get_vendor_tax (
2531                                                         p_vendor_id,
2532        					                                        l_curr_calling_sequence);
2533                 IF (l_tax_classification_code IS NOT NULL) THEN
2534                   l_tax_classification_found := TRUE;
2535                   p_default_hierarchy := FALSE;
2536                   IF (g_level_statement >= g_current_runtime_level ) THEN
2537                     FND_LOG.STRING(g_level_statement,
2538                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2539                       'l_tax_classification_code ==' ||l_tax_classification_code);
2540                   END IF;
2541                   exit Ap_Tax_Loop;
2542                 END IF;
2543               END IF;
2544 
2545               IF (aptaxtab (i) = 'NATURAL_ACCOUNT') THEN
2546                 IF (g_level_statement >= g_current_runtime_level ) THEN
2547          	        FND_LOG.STRING(g_level_statement,
2548                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2549                     'Getting tax code from account');
2550                   END IF;
2551                   get_account_tax (p_code_combination_id,
2552 	       			                     p_concatenated_segments,
2553 			         	                   p_tax_classification_code,
2554 				                           p_allow_tax_code_override_flag,
2555 				                           l_tax_classification_found,
2556 			              	             l_curr_calling_sequence);
2557                   l_tax_classification_code := p_tax_classification_code;
2558                   IF (g_level_statement >= g_current_runtime_level ) THEN
2559          	          FND_LOG.STRING(g_level_statement,
2560                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2561                       'l_tax_classification_code ==' ||l_tax_classification_code);
2562                   END IF;
2563        	          IF (l_tax_classification_found = TRUE) THEN
2564                     p_default_hierarchy := TRUE;
2565                     IF (g_level_statement >= g_current_runtime_level ) THEN
2566                       FND_LOG.STRING(g_level_statement,
2567                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2568                         'l_tax_classification_code is Found ==' ||l_tax_classification_code);
2569                     END IF;
2570                     exit Ap_Tax_Loop;
2571                   END IF;
2572                 END IF;
2573 
2574                 IF (aptaxtab (i) = 'FINANCIAL_OPTIONS') THEN
2575                   IF (g_level_statement >= g_current_runtime_level ) THEN
2576          	          FND_LOG.STRING(g_level_statement,
2577                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2578                       'Getting tax code from financial system parameters');
2579          	          FND_LOG.STRING(g_level_statement,
2580                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2581                       'sysinfo.vat_code ==' ||sysinfo.ap_info.tax_classification_code );
2582                   END IF;
2583                   l_tax_classification_code := sysinfo.ap_info.tax_classification_code;
2584                   IF (l_tax_classification_code IS NOT NULL) THEN
2585                     l_tax_classification_found := TRUE;
2586                     p_default_hierarchy := FALSE;
2587                     IF (g_level_statement >= g_current_runtime_level ) THEN
2588                       FND_LOG.STRING(g_level_statement,
2589                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2590                         'l_tax_classification_code ==' ||l_tax_classification_code);
2591                     END IF;
2592                     exit Ap_Tax_Loop;
2593                   END IF;
2594                 END IF;
2595 
2596                 IF (aptaxtab (i) = 'TEMPLATE') THEN
2597                   IF (g_level_statement >= g_current_runtime_level ) THEN
2598                     FND_LOG.STRING(g_level_statement,
2599                       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2600                       'Getting tax code from template');
2601                   END IF;
2602                   -- If the API has been called from a form or process
2603                   -- where a template is being used, then we should always
2604                   -- return the tax code on the template item, even if it
2605                   -- is null.  This is because a null tax code on a template
2606                   -- is considered as an explicit request for a non-taxable
2607                   -- item.  See bug #558756.
2608                   --
2609                   -- We use the func_short_name to determine if the
2610                   -- API is being called anywhere where a distribution set
2611                   -- is in use, and use the calling_sequence to determine
2612                   -- whether we are being called from the Expense Reports form
2613                   -- (and are by implication using an expense report template).
2614                   -- 2544633 fbreslin: Add APXXXDER to list of forms that uses this code.
2615                   IF (p_calling_sequence IN ('APXXXEER', 'APXXXDER') OR
2616                       func_short_name = 'AP_INSERT_FROM_DSET') THEN
2617                     l_tax_classification_code := p_templ_tax_classification_cd;
2618                     l_tax_classification_found := TRUE;
2619                     p_default_hierarchy := FALSE;
2620                     IF (g_level_statement >= g_current_runtime_level ) THEN
2621                       FND_LOG.STRING(g_level_statement,
2622                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2623                         'l_tax_classification_code ==' ||l_tax_classification_code);
2624                     END IF;
2625                     exit Ap_Tax_Loop;
2626                   END IF;
2627                 END IF;
2628               END IF;
2629             END LOOP Ap_Tax_Loop;
2630           END IF; -- l_enforced_tax_found
2631         END IF; -- search_for_ap_tax
2632     END IF; -- appl_short_name
2633   END IF; -- tax_code_found
2634 
2635   IF (nvl (p_tax_user_override_flag, 'N') <> 'Y') THEN
2636     IF (g_level_statement >= g_current_runtime_level ) THEN
2637     	FND_LOG.STRING(g_level_statement,
2638         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2639         'p_tax_user_override_flag =='||p_tax_user_override_flag);
2640    	  FND_LOG.STRING(g_level_statement,
2641         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2642         'l_tax_classification_code =='||l_tax_classification_code);
2643     END IF;
2644   END IF;
2645   IF (g_level_statement >= g_current_runtime_level ) THEN
2646   	FND_LOG.STRING(g_level_statement,
2647       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2648       'p_tax_classification_code  =='||p_tax_classification_code);
2649     FND_LOG.STRING(g_level_statement,
2650       'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc.END',
2651       'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: get_def_tax_classif_from_acc (-)');
2652   END IF;
2653 
2654 EXCEPTION
2655   WHEN NO_DATA_FOUND THEN
2656     IF (g_level_unexpected >= g_current_runtime_level ) THEN
2657   	  FND_LOG.STRING(g_level_unexpected,
2658         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2659          sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80) );
2660     END IF;
2661     IF (l_tax_classification_found = FALSE ) THEN
2662 	    RAISE NO_DATA_FOUND;
2663     END IF;
2664   WHEN OTHERS THEN
2665     IF (SQLCODE <> -20001) THEN
2666       IF (g_level_unexpected >= g_current_runtime_level ) THEN
2667         FND_LOG.STRING(g_level_unexpected,
2668           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_def_tax_classif_from_acc',
2669            sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80) );
2670       END IF;
2671       IF (appl_short_name = 'SQLAP') THEN
2672         FND_MESSAGE.SET_NAME('SQLAP', 'AP_DEBUG');
2673         FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
2674         FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
2675         FND_MESSAGE.SET_TOKEN('PARAMETERS',
2676 	      ' p_ref_doc_application_id = '|| to_char (p_ref_doc_application_id) ||
2677         ',p_ref_doc_entity_code = '||p_ref_doc_entity_code ||
2678         ',p_ref_doc_event_class_code = '||p_ref_doc_event_class_code ||
2679         ',p_ref_doc_trx_id = '||TO_CHAR(p_ref_doc_trx_id) ||
2680         ',p_ref_doc_line_id = '||TO_CHAR(p_ref_doc_line_id) ||
2681         ',p_ref_doc_trx_level_type = '||p_ref_doc_trx_level_type ||
2682 	      ',p_vendor_id = '|| to_char (p_vendor_id) ||
2683 	      ',p_vendor_site_id = '|| to_char (p_vendor_site_id) ||
2684 	      ',p_code_combination_id = '|| to_char (p_code_combination_id) ||
2685 	      ',p_concatenated_segments = '||p_concatenated_segments ||
2686         ',p_templ_tax_classification_cd = '||p_templ_tax_classification_cd||
2687 	      ',p_tax_classification_code = '||p_tax_classification_code ||
2688         ',p_allow_tax_code_override_flag = '||p_allow_tax_code_override_flag ||
2689      	  ',APPL_SHORT_NAME = '||APPL_SHORT_NAME ||
2690 	      ',FUNC_SHORT_NAME = '||FUNC_SHORT_NAME ||
2691 	      ',p_calling_sequence = '||p_calling_sequence);
2692       END IF;
2693     END IF;
2694     APP_EXCEPTION.RAISE_EXCEPTION;
2695 END get_def_tax_classif_from_acc;
2696 
2697 -------------------------------------------------------------------------------
2698 --
2699 -- PRIVATE FUNCTION
2700 -- get_item_tax
2701 --
2702 -- DESCRIPTION
2703 -- This function will look for the tax code that is specified at the
2704 -- item level, if the system options specify that tax is defaulted
2705 -- from this level. It will return the tax code if one is found for the
2706 -- item and the given date. It returns null if a valid tax code is
2707 -- not found.
2708 --
2709 -- If the ship-to organization ID is passed in, use that, else use the
2710 -- item organization ID.  This is in keeping with the existing
2711 -- defaulting rules used for the taxable flag in Purchasing.
2712 
2713 -- RETURNS
2714 -- Tax code if one is found at the shipment level and valid for the
2715 -- given date.  Null if a valid tax code is not found.
2716 --
2717 -- CALLED FROM
2718 -- get_default_tax_classification()
2719 --
2720 -- HISTORY
2721 -- 15-JUL-97  Fiona Purves created based on AR API.
2722 --
2723 -------------------------------------------------------------------------------
2724 
2725 
2726 FUNCTION  get_item_tax (
2727   p_item_id		IN  mtl_system_items.inventory_item_id%TYPE,
2728   p_ship_to_loc_org_id	IN  mtl_system_items.organization_id%TYPE,
2729   p_item_org_id		IN  mtl_system_items.organization_id%TYPE,
2730   p_calling_sequence	IN  varchar2 )
2731 
2732   RETURN VARCHAR2 IS
2733   l_curr_calling_sequence 	VARCHAR2(2000);
2734   l_tax_classification_code	VARCHAR2(30);
2735 
2736   CURSOR sel_item_tax IS
2737   SELECT si.purchasing_tax_code
2738     FROM fnd_lookups tc,
2739          mtl_system_items si
2740    WHERE si.inventory_item_id = p_item_id
2741      AND si.organization_id = nvl(p_ship_to_loc_org_id, p_item_org_id)
2742      AND tc.lookup_code = si.purchasing_tax_code
2743      AND tc.lookup_type = 'ZX_INPUT_CLASSIFICATIONS'
2744      AND nvl(tc.enabled_flag,'Y') = 'Y';
2745 
2746 BEGIN
2747   g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
2748 
2749   IF (g_level_statement >= g_current_runtime_level ) THEN
2750      FND_LOG.STRING(g_level_statement,
2751                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax.BEGIN',
2752                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Item_Tax (+)');
2753      FND_LOG.STRING(g_level_statement,
2754                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax',
2755                     'p_item_id == > '||to_char(p_item_id ));
2756      FND_LOG.STRING(g_level_statement,
2757                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax',
2758                     'p_ship_to_loc_org_id == > '||to_char(p_ship_to_loc_org_id ));
2759      FND_LOG.STRING(g_level_statement,
2760                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax',
2761                     'p_item_org_id == > '||to_char(p_item_org_id ));
2762      FND_LOG.STRING(g_level_statement,
2763                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax',
2764                     'p_calling_sequence == >'||p_calling_sequence);
2765   END IF;
2766   debug_loc := 'Get_Item_Tax';
2767   l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
2768 
2769   OPEN sel_item_tax;
2770   FETCH sel_item_tax INTO l_tax_classification_code;
2771   CLOSE sel_item_tax;
2772 
2773   IF (g_level_statement >= g_current_runtime_level ) THEN
2774      FND_LOG.STRING(g_level_statement,
2775                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax',
2776                     'l_tax_classification_code  =='||l_tax_classification_code);
2777      FND_LOG.STRING(g_level_statement,
2778                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax.END',
2779                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Item_Tax (-)');
2780   END IF;
2781 
2782   RETURN (l_tax_classification_code);
2783 
2784   EXCEPTION
2785     WHEN OTHERS THEN
2786       FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
2787       FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','Get_Item_Tax- '||
2788                            sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
2789       FND_MSG_PUB.Add;
2790 
2791       IF (g_level_unexpected >= g_current_runtime_level ) THEN
2792         FND_LOG.STRING(g_level_unexpected,
2793                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Item_Tax',
2794                       sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
2795       END IF;
2796 	 IF (sel_item_tax%ISOPEN) THEN
2797 	    CLOSE sel_item_tax;
2798 	 END IF;
2799          RAISE;
2800 END get_item_tax;
2801 
2802 -------------------------------------------------------------------------------
2803 --
2804 -- PRIVATE FUNCTION
2805 -- get_account_tax
2806 --
2807 -- DESCRIPTION
2808 -- This function will look for the tax code that is specified at the
2809 -- account level, if the system options specify that tax is defaulted
2810 -- from this level. It will return the tax code if one is found for the
2811 -- account and the given date. It returns null if a valid tax code is
2812 -- not found.
2813 --
2814 -- The function will search for the tax code on the account using
2815 --
2816 --     a)  The code combination ID
2817 --     b)  The concatenated segment string
2818 --
2819 -- depending on which parameter is passed.
2820 --
2821 -- The function searches for the account where the tax type is 'Input'
2822 -- or 'Non-taxable'.  If the tax type is 'Input', then the tax code is
2823 -- returned.  If non-taxable, the function explicitly returns a null
2824 -- tax code, and the search for tax code is considered finished.
2825 -- This is a different result to not finding a tax code for an account.
2826 --
2827 -- Note that this function currently only caters for Accounts Payable, where
2828 -- there is no distinction between line and accounting distribution.
2829 -- It is sufficient in this case to pass the code combination ID from the
2830 -- AP accounting distribution.
2831 
2832 -- When defaulting tax code from natural account in Purchasing is implemented,
2833 -- this function will need to be changed, to deal with the PO
2834 -- which does have shipments and distributions.   The tax defaulting API
2835 -- in AR already does this, and passes the transaction line ID to the
2836 -- function.  See ARP_TAX.get_natural_account_tax.
2837 --
2838 -- RETURNS
2839 --
2840 -- Tax code if one is found at the account level and valid for the
2841 -- given date.  It also returns a flag to indicate whether the user
2842 -- may override the tax code for the given account.
2843 --
2844 -- CALLED FROM
2845 -- get_default_tax_classification()
2846 --
2847 -- HISTORY
2848 -- 15-JUL-97  Fiona Purves created based on AR API.
2849 --
2850 -------------------------------------------------------------------------------
2851 
2852 
2853 
2854 
2855 PROCEDURE  get_account_tax (
2856   p_code_combination_id 	  IN gl_code_combinations.code_combination_id%TYPE,
2857   p_concatenated_segments	  IN varchar2,
2858   p_tax_classification_code	  IN OUT NOCOPY varchar2,
2859   p_allow_tax_code_override_flag  OUT NOCOPY zx_acct_tx_cls_defs.allow_tax_code_override_flag%TYPE,
2860   p_tax_classification_found      IN OUT NOCOPY boolean,
2861   p_calling_sequence		  IN varchar2) IS
2862 
2863   l_curr_calling_sequence 		VARCHAR2(2000);
2864   l_bind_org_id				financials_system_parameters.org_id%TYPE;
2865   l_app_column_name			fnd_id_flex_segments.application_column_name%TYPE;
2866   l_account_seg_value			gl_code_combinations.segment1%TYPE;
2867 --  l_tax_type_code			gl_tax_option_accounts.tax_type_code%TYPE;
2868   l_tax_type_code                       zx_acct_tx_cls_defs.tax_class%TYPE;
2869   l_delimiter				varchar2(5) := NULL;
2870   l_result				number;
2871   l_flexsegtab				fnd_flex_ext.SegmentArray;
2872   l_account_seg_num			number;
2873   l_tax_classification_code             varchar2(30);
2874 
2875   TYPE   taxcurtype  IS REF CURSOR  ;
2876   l_def_tax_cur      taxcurtype;
2877 
2878 
2879   BEGIN
2880 
2881     g_current_runtime_level := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
2882 
2883      IF (g_level_statement >= g_current_runtime_level ) THEN
2884   	FND_LOG.STRING(g_level_statement,
2885                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax.BEGIN',
2886                        'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Account_Tax (+)');
2887   	FND_LOG.STRING(g_level_statement,
2888                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2889                        'p_code_combination_id ==>'||to_char(p_code_combination_id));
2890   	FND_LOG.STRING(g_level_statement,
2891                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2892                        'p_concatenated_segments ==>'||p_concatenated_segments);
2893   	FND_LOG.STRING(g_level_statement,
2894                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2895                        'p_tax_classification_code ==>'|| p_tax_classification_code );
2896   	FND_LOG.STRING(g_level_statement,
2897                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2898                        'p_allow_tax_code_override_flag ==>'||p_allow_tax_code_override_flag);
2899 
2900   	FND_LOG.STRING(g_level_statement,
2901                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2902                        'p_calling_sequence ==>'||p_calling_sequence );
2903      END IF;
2904 
2905      debug_loc := 'Get_Account_Tax';
2906      l_curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.'||debug_loc||'<-'||p_calling_sequence;
2907 
2908      IF (p_code_combination_id is not NULL and p_code_combination_id <> -1) THEN
2909 	--  Get the column name that holds the account segment in GL_CODE_COMBINATIONS
2910         IF (g_level_statement >= g_current_runtime_level ) THEN
2911   	   FND_LOG.STRING(g_level_statement,
2912                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2913                        'Getting tax code using code combination ID');
2914   	   FND_LOG.STRING(g_level_statement,
2915                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2916                        'p_code_combination_id is not Null =='||to_char(p_code_combination_id));
2917         END IF;
2918 
2919         result := fnd_flex_apis.get_segment_column (101,
2920 					    	    'GL#',
2921 						    sysinfo.chart_of_accounts_id,
2922 						    'GL_ACCOUNT',
2923 						    l_app_column_name);
2924         --Bug Fix 1064036
2925 	statement := 'SELECT ' || l_app_column_name ||
2926 	             ' FROM gl_code_combinations cc' ||
2927 		     ' WHERE cc.code_combination_id = ' || p_code_combination_id;
2928 
2929         execute immediate statement into l_account_seg_value ;
2930         IF (g_level_statement >= g_current_runtime_level ) THEN
2931            FND_LOG.STRING(g_level_statement,
2932                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2933                           'l_account_seg_value =='||l_account_seg_value);
2934         END IF;
2935      ELSE
2936        IF (p_concatenated_segments is not NULL) THEN
2937           IF (g_level_statement >= g_current_runtime_level ) THEN
2938              FND_LOG.STRING(g_level_statement,
2939                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2940                             'p_concatenated_segments is not Null =='||p_concatenated_segments);
2941           END IF;
2942 	  --  Get account segment from the concatenated string
2943           IF (g_level_statement >= g_current_runtime_level ) THEN
2944   	     FND_LOG.STRING(g_level_statement,
2945                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2946                             'Getting tax code using concatenated segments');
2947           END IF;
2948 	  l_delimiter := fnd_flex_ext.get_delimiter ('SQLGL',
2949                                                      'GL#',
2950                                                      sysinfo.chart_of_accounts_id);
2951 	  l_result := fnd_flex_ext.breakup_segments (p_concatenated_segments,
2952                                                      l_delimiter,
2953                                                      l_flexsegtab);
2954 	  result := fnd_flex_apis.get_qualifier_segnum (101,
2955 							'GL#',
2956 							sysinfo.chart_of_accounts_id,
2957 							'GL_ACCOUNT',
2958 							 l_account_seg_num);
2959 	  l_account_seg_value := l_flexsegtab(l_account_seg_num);
2960 
2961           IF (g_level_statement >= g_current_runtime_level ) THEN
2962              FND_LOG.STRING(g_level_statement,
2963                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2964                             'l_account_seg_value =='|| l_account_seg_value);
2965              FND_LOG.STRING(g_level_statement,
2966                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2967                             'l_delimiter =='||l_delimiter );
2968              FND_LOG.STRING(g_level_statement,
2969                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2970                             'l_result =='||to_char(l_result));
2971           END IF;
2972        END IF;
2973      END IF;
2974 
2975      IF (l_account_seg_value is not NULL) THEN
2976         IF (g_level_statement >= g_current_runtime_level ) THEN
2977            FND_LOG.STRING(g_level_statement,
2978                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
2979                           'l_account_seg_value is not null =='||l_account_seg_value);
2980         END IF;
2981         BEGIN
2982            --1064036
2983            -- 1952304. Added an extra condition toa.org_id = -1 in both the select clauses.
2984            -- This would ensure that the tax code is defaulted even in a single org instance.
2985 	   statement := 'SELECT	toa.allow_tax_code_override_flag, ' ||
2986 				'toa.tax_classification_code, ' ||
2987 				'toa.tax_class  ' ||
2988 		        'FROM	zx_acct_tx_cls_defs_all toa, ' ||
2989 				'zx_input_classifications_v tc ' ||
2990 		        'WHERE	toa.account_segment_value = :l_account_seg_value ' ||
2991 		        'AND  toa.ledger_id = :l_bind_set_of_books_id ' || -- Bug 8353620
2992 		        'AND	(toa.org_id = :l_bind_org_id or toa.org_id = -1)' ||
2993 		        'AND	toa.tax_class  = ''INPUT'' ' ||
2994 		        'AND	tc.lookup_code = toa.tax_classification_code ' ||
2995 		        'AND	tc.lookup_type = ''ZX_INPUT_CLASSIFICATIONS'' ' ||
2996 		        'AND 	nvl(tc.enabled_flag,''Y'') = ''Y'' ' ||
2997 		        'AND    tc.org_id in (:l_bind_org_id,-99) '||
2998 		        'UNION	' ||
2999 		        'SELECT	toa.allow_tax_code_override_flag, ' ||
3000 				'toa.tax_classification_code, ' ||
3001 				'toa.tax_class ' ||
3002 		        'FROM	zx_acct_tx_cls_defs_all toa ' ||
3003 		        'WHERE	toa.account_segment_value = :l_account_seg_value ' ||
3004 		        'AND	( toa.org_id = :l_bind_org_id or toa.org_id = -1 )' ||
3005 		        'AND	toa.tax_class  = ''N'' ';
3006            IF (g_level_statement >= g_current_runtime_level ) THEN
3007               FND_LOG.STRING(g_level_statement,
3008                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3009                              'statement='||statement);
3010       	      FND_LOG.STRING(g_level_statement,
3011                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3012                              'Executing Dynamic SQL statement  ');
3013            END IF;
3014            execute immediate statement into p_allow_tax_code_override_flag,
3015                                             p_tax_classification_code,
3016                                             l_tax_type_code
3017                                       using l_account_seg_value,
3018                                             sysinfo.set_of_books_id,
3019                                             sysinfo.org_id,
3020                                             sysinfo.org_id,
3021                                             l_account_seg_value,
3022                                             sysinfo.org_id;
3023            IF (g_level_statement >= g_current_runtime_level ) THEN
3024 	      FND_LOG.STRING(g_level_statement,
3025                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3026                              'statement  =='||substr(statement,1,700));
3027               FND_LOG.STRING(g_level_statement,
3028                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3029                              'sysinfo.org_id  =='||to_char(sysinfo.org_id));
3030               FND_LOG.STRING(g_level_statement,
3031                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3032                              'p_allow_tax_code_override_flag  =='||p_allow_tax_code_override_flag );
3033               FND_LOG.STRING(g_level_statement,
3034                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3035                              ' p_tax_classification_code  =='|| p_tax_classification_code );
3036               FND_LOG.STRING(g_level_statement,
3037                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3038                              'l_tax_type_code  =='||l_tax_type_code );
3039               FND_LOG.STRING(g_level_statement,
3040                             'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3041                              'l_account_seg_value  =='||l_account_seg_value );
3042 
3043               FND_LOG.STRING(g_level_statement,
3044                              'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax.END',
3045                              'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: Get_Account_Tax (-)');
3046            END IF;
3047 
3048           EXCEPTION
3049             WHEN no_data_found THEN
3050               IF (g_level_unexpected >= g_current_runtime_level ) THEN
3051                 FND_LOG.STRING(g_level_unexpected,
3052                                'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.Get_Account_Tax',
3053                                 sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3054                END IF;
3055 
3056             WHEN  others THEN
3057               FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
3058               FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'get_account_tax- '||
3059                                      sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3060               FND_MSG_PUB.Add;
3061 
3062               IF (g_level_unexpected >= g_current_runtime_level ) THEN
3063                 FND_LOG.STRING(g_level_unexpected,
3064                                'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.get_account_tax',
3065                                 sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3066               END IF;
3067                    RAISE;
3068         END;
3069 
3070         IF (p_tax_classification_code is not NULL OR l_tax_type_code = 'N') THEN
3071            p_tax_classification_found := TRUE;
3072 	END IF;
3073      END IF;
3074 
3075 END get_account_tax;
3076 
3077 -- Bug#4090842- new procedure
3078 -----------------------------------------------------------------------
3079 --  PRIVATE PROCEDURE
3080 --  pop_ap_def_option_hier
3081 --
3082 --  DESCRIPTION
3083 --
3084 --  This procedure populates tax default option hierachies for products
3085 --  using 'AP'
3086 --
3087 
3088 PROCEDURE pop_ap_def_option_hier(p_org_id           IN   NUMBER,
3089                                  p_application_id   IN   NUMBER,
3090                                  p_event_class_code IN   VARCHAR2,
3091                                  p_return_status    OUT NOCOPY VARCHAR2)
3092 IS
3093   l_event_class_mapping_id       NUMBER;
3094 
3095   CURSOR c_ap_default_options (c_org_id         NUMBER,
3096                                c_application_id NUMBER) IS
3097     SELECT org_id,
3098            use_tax_classification_flag,
3099            tax_classification_code,
3100            def_option_hier_1_code,
3101            def_option_hier_2_code,
3102            def_option_hier_3_code,
3103            def_option_hier_4_code,
3104            def_option_hier_5_code,
3105            def_option_hier_6_code,
3106            def_option_hier_7_code
3107      FROM  zx_product_options_all
3108      WHERE org_id         = c_org_id
3109        AND application_id = c_application_id
3110        AND event_class_mapping_id IS NULL;
3111 
3112   --
3113   -- Bug#4102742- handle Internet Expense
3114   -- only IOE has event_class_mapping_id not NULL
3115   -- in zx_product_options_all
3116   --
3117   CURSOR c_get_event_class_mapping_id (
3118               c_event_class_code      VARCHAR2,
3119               c_application_id        NUMBER,
3120               c_entity_code           VARCHAR2)  IS
3121     SELECT event_class_mapping_id
3122       FROM zx_evnt_cls_mappings
3123       WHERE event_class_code = c_event_class_code
3124         AND application_id   = c_application_id
3125         AND entity_code      = c_entity_code;
3126 
3127   CURSOR c_ioe_default_options (c_org_id                 NUMBER,
3128                                 c_application_id         NUMBER,
3129                                 c_event_class_mapping_id NUMBER) IS
3130     SELECT org_id,
3131            use_tax_classification_flag,
3132            tax_classification_code,
3133            def_option_hier_1_code,
3134            def_option_hier_2_code,
3135            def_option_hier_3_code,
3136            def_option_hier_4_code,
3137            def_option_hier_5_code,
3138            def_option_hier_6_code,
3139            def_option_hier_7_code
3140      FROM  zx_product_options_all
3141      WHERE org_id                 = c_org_id
3142        AND application_id         = c_application_id
3143        AND event_class_mapping_id = c_event_class_mapping_id;
3144 BEGIN
3145 
3146   IF (g_level_statement >= g_current_runtime_level ) THEN
3147     FND_LOG.STRING(g_level_statement,
3148                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier.BEGIN',
3149                    'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: pop_ap_def_option_hier(+)' );
3150     FND_LOG.STRING(g_level_statement,
3151                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3152                    'p_event_class_code : ' || p_event_class_code);
3153     FND_LOG.STRING(g_level_statement,
3154                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3155                    'Getting default options ');
3156   END IF;
3157 
3158   -- init return status
3159   p_return_status := FND_API.G_RET_STS_SUCCESS;
3160 
3161   -- init search for ap tax to FALSE
3162   search_for_ap_tax  := FALSE;
3163   search_ap_def_hier := FALSE;
3164 
3165   --
3166   -- determine if it is Internet Expense
3167   --
3168   IF p_event_class_code = 'EXPENSE REPORTS' THEN
3169     --
3170     -- Bug#4102742- Internet expense case, get event_class_mapping_id
3171     --
3172     OPEN c_get_event_class_mapping_id(p_event_class_code,
3173                                       200,
3174                                       'AP_INVOICES');
3175     FETCH c_get_event_class_mapping_id INTO
3176             l_event_class_mapping_id;
3177     CLOSE c_get_event_class_mapping_id;
3178 
3179     IF l_event_class_mapping_id IS NULL THEN
3180       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3181       IF (g_level_statement >= g_current_runtime_level ) THEN
3182         FND_LOG.STRING(g_level_statement,
3183                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3184                        'event_class_mapping_id not found for Internet expense');
3185       END IF;
3186       RETURN;
3187     END IF;
3188 
3189     OPEN c_ioe_default_options(p_org_id, 200, l_event_class_mapping_id);
3190     FETCH c_ioe_default_options INTO
3191            ap_info.org_id,
3192            ap_info.use_tax_classification_flag,
3193            ap_info.tax_classification_code,
3194            ap_info.def_option_hier_1_code,
3195            ap_info.def_option_hier_2_code,
3196            ap_info.def_option_hier_3_code,
3197            ap_info.def_option_hier_4_code,
3198            ap_info.def_option_hier_5_code,
3199            ap_info.def_option_hier_6_code,
3200            ap_info.def_option_hier_7_code;
3201     CLOSE c_ioe_default_options;
3202   ELSE
3203     -- non Internet expense case
3204     -- Bug#4090842- use org_id passed in
3205     -- open c_default_options(to_number(substrb(userenv('CLIENT_INFO'),1,10)),
3206     --                        200);
3207     OPEN c_ap_default_options(p_org_id, 200);
3208     FETCH c_ap_default_options INTO
3209            ap_info.org_id,
3210            ap_info.use_tax_classification_flag,
3211            ap_info.tax_classification_code,
3212            ap_info.def_option_hier_1_code,
3213            ap_info.def_option_hier_2_code,
3214            ap_info.def_option_hier_3_code,
3215            ap_info.def_option_hier_4_code,
3216            ap_info.def_option_hier_5_code,
3217            ap_info.def_option_hier_6_code,
3218            ap_info.def_option_hier_7_code;
3219     CLOSE c_ap_default_options;
3220   END IF;
3221 
3222   IF NVL(ap_info.use_tax_classification_flag, 'N') = 'Y' THEN
3223     search_for_ap_tax := TRUE;
3224   END IF;
3225 
3226   IF (g_level_statement >= g_current_runtime_level ) THEN
3227         FND_LOG.STRING(g_level_statement,
3228                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3229                        'Use Tax Classification: '|| NVL(ap_info.use_tax_classification_flag,'N'));
3230         FND_LOG.STRING(g_level_statement,
3231                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3232                        'Hierarchy Level 1: ' ||ap_info.def_option_hier_1_code );
3233         FND_LOG.STRING(g_level_statement,
3234                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3235                        'Hierarchy Level 2: ' ||ap_info.def_option_hier_2_code );
3236         FND_LOG.STRING(g_level_statement,
3237                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3238                        'Hierarchy Level 3: ' ||ap_info.def_option_hier_3_code );
3239         FND_LOG.STRING(g_level_statement,
3240                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3241                        'Hierarchy Level 4: ' ||ap_info.def_option_hier_4_code );
3242         FND_LOG.STRING(g_level_statement,
3243                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3244                        'Hierarchy Level 5: ' ||ap_info.def_option_hier_5_code );
3245         FND_LOG.STRING(g_level_statement,
3246                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3247                        'Hierarchy Level 6: ' ||ap_info.def_option_hier_6_code );
3248         FND_LOG.STRING(g_level_statement,
3249                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3250                        'Hierarchy Level 7: ' ||ap_info.def_option_hier_7_code );
3251 
3252   END IF;
3253 
3254   sysinfo.ap_info               := ap_info;
3255   sysinfo.org_id                := p_org_id;
3256 
3257   IF search_for_ap_tax THEN
3258     IF (sysinfo.ap_info.def_option_hier_1_code IS NOT NULL
3259            OR sysinfo.ap_info.def_option_hier_2_code IS NOT NULL
3260            OR sysinfo.ap_info.def_option_hier_3_code IS NOT NULL
3261            OR sysinfo.ap_info.def_option_hier_4_code IS NOT NULL
3262            OR sysinfo.ap_info.def_option_hier_5_code IS NOT NULL
3263            OR sysinfo.ap_info.def_option_hier_6_code IS NOT NULL
3264            OR sysinfo.ap_info.def_option_hier_7_code IS NOT NULL) THEN
3265 
3266       IF (g_level_statement >= g_current_runtime_level ) THEN
3267           FND_LOG.STRING(g_level_statement,
3268                         'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3269                         'Initializing AP defaulting information');
3270       END IF;
3271 
3272       aptaxtab(1) := sysinfo.ap_info.def_option_hier_1_code;
3273       aptaxtab(2) := sysinfo.ap_info.def_option_hier_2_code;
3274       aptaxtab(3) := sysinfo.ap_info.def_option_hier_3_code;
3275       aptaxtab(4) := sysinfo.ap_info.def_option_hier_4_code;
3276       aptaxtab(5) := sysinfo.ap_info.def_option_hier_5_code;
3277       aptaxtab(6) := sysinfo.ap_info.def_option_hier_6_code;
3278       aptaxtab(7) := sysinfo.ap_info.def_option_hier_7_code;
3279 
3280       search_ap_def_hier := TRUE;
3281     END IF;
3282 
3283   END IF;
3284 
3285   IF (g_level_statement >= g_current_runtime_level ) THEN
3286      FND_LOG.STRING(g_level_statement,
3287                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier.END',
3288                    'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: pop_ap_def_option_hier(-)' );
3289   END IF;
3290 
3291 EXCEPTION
3292   WHEN OTHERS THEN
3293     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3294     IF c_ap_default_options%ISOPEN THEN
3295       CLOSE c_ap_default_options;
3296     END IF;
3297     IF c_ioe_default_options%ISOPEN THEN
3298       CLOSE c_ioe_default_options;
3299     END IF;
3300     FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
3301     FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'pop_ap_def_option_hier- '||
3302                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3303     FND_MSG_PUB.Add;
3304 
3305     IF (g_level_unexpected >= g_current_runtime_level ) THEN
3306       FND_LOG.STRING(g_level_unexpected,
3307                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_ap_def_option_hier',
3308                       sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3309     END IF;
3310 
3311 END pop_ap_def_option_hier;
3312 
3313 -- Bug#4090842- new procedure
3314 -----------------------------------------------------------------------
3315 --  PRIVATE PROCEDURE
3316 --  pop_po_def_option_hier
3317 --
3318 --  DESCRIPTION
3319 --
3320 --  This procedure populates tax default option hierachies for products
3321 --  using 'PO'
3322 --
3323 
3324 PROCEDURE pop_po_def_option_hier(p_org_id            IN  NUMBER,
3325                                  p_application_id    IN  NUMBER,
3326                                  p_return_status    OUT NOCOPY VARCHAR2)
3327 IS
3328   status_flag fnd_product_installations.status%TYPE;
3329 
3330   CURSOR  get_status_flag_csr(c_application_id    NUMBER) IS
3331     SELECT   status
3332       FROM   fnd_product_installations
3333       WHERE  application_id = c_application_id;
3334 
3335   CURSOR c_po_default_options (c_org_id         NUMBER,
3336                                c_application_id NUMBER) IS
3337     SELECT org_id,
3338            use_tax_classification_flag,
3339            tax_classification_code,
3340            def_option_hier_1_code,
3341            def_option_hier_2_code,
3342            def_option_hier_3_code,
3343            def_option_hier_4_code,
3344            def_option_hier_5_code,
3345            def_option_hier_6_code,
3346            def_option_hier_7_code
3347     FROM  zx_product_options_all
3348     WHERE org_id = c_org_id
3349       AND application_id = c_application_id
3350       AND event_class_mapping_id IS NULL;
3351 
3352 BEGIN
3353 
3354   IF (g_level_statement >= g_current_runtime_level ) THEN
3355       FND_LOG.STRING(g_level_statement,
3356                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier.BEGIN',
3357                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: pop_po_def_option_hier(+)' );
3358   END IF;
3359 
3360   -- init return status
3361   p_return_status := FND_API.G_RET_STS_SUCCESS;
3362 
3363   -- init search for po tax to FALSE
3364   search_for_po_tax  := FALSE;
3365   search_po_def_hier := FALSE;
3366 
3367   -- This variable is declared and pop_po_def_option_hierd for the bug 2836810 by zmohiudd..
3368   status_flag := 'N';
3369 
3370   --  The following select statement and if condition are added for the bug 2836810 by zmohiudd..
3371   OPEN  get_status_flag_csr(201);
3372   FETCH get_status_flag_csr INTO status_flag;
3373   CLOSE get_status_flag_csr;
3374 
3375   IF nvl(status_flag,'N') in ('I','S') THEN
3376     IF (g_level_statement >= g_current_runtime_level ) THEN
3377         FND_LOG.STRING(g_level_statement,
3378                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3379                        'Getting PO default options');
3380     END IF;
3381 
3382         -- Bug#4090842- use org_id passed in
3383         -- open c_default_options(to_number(substrb(userenv('CLIENT_INFO'),1,10)),
3384         --                        201);
3385     OPEN c_po_default_options(p_org_id, 201);
3386     FETCH c_po_default_options INTO
3387              po_info.org_id,
3388              po_info.use_tax_classification_flag,
3389              po_info.tax_classification_code,
3390              po_info.def_option_hier_1_code,
3391              po_info.def_option_hier_2_code,
3392              po_info.def_option_hier_3_code,
3393              po_info.def_option_hier_4_code,
3394              po_info.def_option_hier_5_code,
3395              po_info.def_option_hier_6_code,
3396              po_info.def_option_hier_7_code;
3397     CLOSE c_po_default_options;
3398 
3399     IF NVL(po_info.use_tax_classification_flag, 'N') = 'Y' THEN
3400       search_for_po_tax := TRUE;
3401     END IF;
3402 
3403     IF (g_level_statement >= g_current_runtime_level ) THEN
3404            FND_LOG.STRING(g_level_statement,
3405                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3406                           'PO Use Tax Classification: '|| NVL(po_info.use_tax_classification_flag,'N'));
3407            FND_LOG.STRING(g_level_statement,
3408                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3409                           'PO Hierarchy Level 1: ' ||po_info.def_option_hier_1_code );
3410            FND_LOG.STRING(g_level_statement,
3411                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3412                           'PO Hierarchy Level 2: ' ||po_info.def_option_hier_2_code );
3413            FND_LOG.STRING(g_level_statement,
3414                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3415                           'PO Hierarchy Level 3: ' ||po_info.def_option_hier_3_code );
3416            FND_LOG.STRING(g_level_statement,
3417                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3418                           'PO Hierarchy Level 4: ' ||po_info.def_option_hier_4_code );
3419            FND_LOG.STRING(g_level_statement,
3420                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3421                           'PO Hierarchy Level 5: ' ||po_info.def_option_hier_5_code );
3422            FND_LOG.STRING(g_level_statement,
3423                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3424                           'PO Hierarchy Level 6: ' ||po_info.def_option_hier_6_code );
3425            FND_LOG.STRING(g_level_statement,
3426                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3427                           'PO Hierarchy Level 7: ' ||po_info.def_option_hier_7_code );
3428     END IF;
3429 
3430     sysinfo.po_info               := po_info;
3431     sysinfo.org_id                := p_org_id;
3432 
3433     IF search_for_po_tax  THEN
3434       IF (sysinfo.po_info.def_option_hier_1_code IS NOT NULL
3435             OR sysinfo.po_info.def_option_hier_2_code IS NOT NULL
3436             OR sysinfo.po_info.def_option_hier_3_code IS NOT NULL
3437             OR sysinfo.po_info.def_option_hier_4_code IS NOT NULL
3438             OR sysinfo.po_info.def_option_hier_5_code IS NOT NULL
3439             OR sysinfo.po_info.def_option_hier_6_code IS NOT NULL
3440             OR sysinfo.po_info.def_option_hier_7_code IS NOT NULL) THEN
3441 
3442         IF (g_level_statement >= g_current_runtime_level ) THEN
3443             FND_LOG.STRING(g_level_statement,
3444                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3445                            'Initializing PO information');
3446         END IF;
3447 
3448         potaxtab(1) := sysinfo.po_info.def_option_hier_1_code;
3449         potaxtab(2) := sysinfo.po_info.def_option_hier_2_code;
3450         potaxtab(3) := sysinfo.po_info.def_option_hier_3_code;
3451         potaxtab(4) := sysinfo.po_info.def_option_hier_4_code;
3452         potaxtab(5) := sysinfo.po_info.def_option_hier_5_code;
3453         potaxtab(6) := sysinfo.po_info.def_option_hier_6_code;
3454         potaxtab(7) := sysinfo.po_info.def_option_hier_7_code;
3455 
3456         search_po_def_hier := TRUE;
3457       END IF;
3458     END IF;
3459 
3460   END IF;
3461 
3462   IF (g_level_statement >= g_current_runtime_level ) THEN
3463       FND_LOG.STRING(g_level_statement,
3464                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier.END',
3465                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: pop_po_def_option_hier(-)' );
3466   END IF;
3467 
3468 EXCEPTION
3469   WHEN OTHERS THEN
3470     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3471     IF c_po_default_options%ISOPEN THEN
3472       CLOSE c_po_default_options;
3473     END IF;
3474     FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
3475     FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'pop_po_def_option_hier- '||
3476                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3477     FND_MSG_PUB.Add;
3478 
3479     IF (g_level_unexpected >= g_current_runtime_level ) THEN
3480       FND_LOG.STRING(g_level_unexpected,
3481                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_po_def_option_hier',
3482                       sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3483     END IF;
3484 END pop_po_def_option_hier;
3485 
3486 -- Bug 6510307
3487 -----------------------------------------------------------------------
3488 --  PRIVATE PROCEDURE
3489 --  pop_cc_def_option_hier
3490 --
3491 --  DESCRIPTION
3492 --
3493 --  This procedure populates tax default option hierachies for product
3494 --  'CC'
3495 --
3496 
3497 PROCEDURE pop_cc_def_option_hier(p_org_id            IN  NUMBER,
3498                                  p_application_id    IN  NUMBER,
3499                                  p_return_status    OUT NOCOPY VARCHAR2)
3500 IS
3501 
3502     CURSOR c_cc_default_options (c_org_id         NUMBER,
3503                                c_application_id NUMBER) IS
3504     SELECT org_id,
3505            use_tax_classification_flag,
3506            tax_classification_code,
3507            def_option_hier_1_code,
3508            def_option_hier_2_code,
3509            def_option_hier_3_code,
3510            def_option_hier_4_code,
3511            def_option_hier_5_code,
3512            def_option_hier_6_code,
3513            def_option_hier_7_code
3514     FROM  zx_product_options_all
3515     WHERE org_id = c_org_id
3516       AND application_id = c_application_id
3517       AND event_class_mapping_id IS NULL;
3518 
3519 BEGIN
3520 
3521   IF (g_level_statement >= g_current_runtime_level ) THEN
3522       FND_LOG.STRING(g_level_statement,
3523                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier.BEGIN',
3524                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: pop_cc_def_option_hier(+)' );
3525   END IF;
3526 
3527   -- init return status
3528   p_return_status := FND_API.G_RET_STS_SUCCESS;
3529 
3530   -- init search for cc tax to FALSE
3531   search_for_cc_tax  := FALSE;
3532   search_cc_def_hier := FALSE;
3533 
3534    IF (g_level_statement >= g_current_runtime_level ) THEN
3535         FND_LOG.STRING(g_level_statement,
3536                        'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3537                        'Getting CC default options');
3538     END IF;
3539 
3540     OPEN c_cc_default_options(p_org_id, 8407);
3541     FETCH c_cc_default_options INTO
3542              cc_info.org_id,
3543              cc_info.use_tax_classification_flag,
3544              cc_info.tax_classification_code,
3545              cc_info.def_option_hier_1_code,
3546              cc_info.def_option_hier_2_code,
3547              cc_info.def_option_hier_3_code,
3548              cc_info.def_option_hier_4_code,
3549              cc_info.def_option_hier_5_code,
3550              cc_info.def_option_hier_6_code,
3551              cc_info.def_option_hier_7_code;
3552     CLOSE c_cc_default_options;
3553 
3554     IF NVL(cc_info.use_tax_classification_flag, 'N') = 'Y' THEN
3555       search_for_cc_tax := TRUE;
3556     END IF;
3557 
3558     IF (g_level_statement >= g_current_runtime_level ) THEN
3559            FND_LOG.STRING(g_level_statement,
3560                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3561                           'CC Use Tax Classification: '|| NVL(cc_info.use_tax_classification_flag,'N'));
3562            FND_LOG.STRING(g_level_statement,
3563                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3564                           'CC Hierarchy Level 1: ' ||cc_info.def_option_hier_1_code );
3565            FND_LOG.STRING(g_level_statement,
3566                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3567                           'CC Hierarchy Level 2: ' ||cc_info.def_option_hier_2_code );
3568            FND_LOG.STRING(g_level_statement,
3569                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3570                           'CC Hierarchy Level 3: ' ||cc_info.def_option_hier_3_code );
3571            FND_LOG.STRING(g_level_statement,
3572                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3573                           'CC Hierarchy Level 4: ' ||cc_info.def_option_hier_4_code );
3574            FND_LOG.STRING(g_level_statement,
3575                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3576                           'CC Hierarchy Level 5: ' ||cc_info.def_option_hier_5_code );
3577            FND_LOG.STRING(g_level_statement,
3578                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3579                           'CC Hierarchy Level 6: ' ||cc_info.def_option_hier_6_code );
3580            FND_LOG.STRING(g_level_statement,
3581                           'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3582                           'CC Hierarchy Level 7: ' ||cc_info.def_option_hier_7_code );
3583     END IF;
3584 
3585     sysinfo.cc_info               := cc_info;
3586     sysinfo.org_id                := p_org_id;
3587 
3588     IF search_for_cc_tax  THEN
3589       IF (sysinfo.cc_info.def_option_hier_1_code IS NOT NULL
3590             OR sysinfo.cc_info.def_option_hier_2_code IS NOT NULL
3591             OR sysinfo.cc_info.def_option_hier_3_code IS NOT NULL
3592             OR sysinfo.cc_info.def_option_hier_4_code IS NOT NULL
3593             OR sysinfo.cc_info.def_option_hier_5_code IS NOT NULL
3594             OR sysinfo.cc_info.def_option_hier_6_code IS NOT NULL
3595             OR sysinfo.cc_info.def_option_hier_7_code IS NOT NULL) THEN
3596 
3597         IF (g_level_statement >= g_current_runtime_level ) THEN
3598             FND_LOG.STRING(g_level_statement,
3599                            'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3600                            'Initializing CC information');
3601         END IF;
3602 
3603         cctaxtab(1) := sysinfo.cc_info.def_option_hier_1_code;
3604         cctaxtab(2) := sysinfo.cc_info.def_option_hier_2_code;
3605         cctaxtab(3) := sysinfo.cc_info.def_option_hier_3_code;
3606         cctaxtab(4) := sysinfo.cc_info.def_option_hier_4_code;
3607         cctaxtab(5) := sysinfo.cc_info.def_option_hier_5_code;
3608         cctaxtab(6) := sysinfo.cc_info.def_option_hier_6_code;
3609         cctaxtab(7) := sysinfo.cc_info.def_option_hier_7_code;
3610 
3611         search_cc_def_hier := TRUE;
3612       END IF;
3613     END IF;
3614 
3615   IF (g_level_statement >= g_current_runtime_level ) THEN
3616       FND_LOG.STRING(g_level_statement,
3617                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier.END',
3618                      'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: pop_cc_def_option_hier(-)' );
3619   END IF;
3620 
3621 EXCEPTION
3622   WHEN OTHERS THEN
3623     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3624     IF c_cc_default_options%ISOPEN THEN
3625       CLOSE c_cc_default_options;
3626     END IF;
3627     FND_MESSAGE.SET_NAME('ZX','GENERIC_MESSAGE');
3628     FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', 'pop_cc_def_option_hier- '||
3629                           sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3630     FND_MSG_PUB.Add;
3631 
3632     IF (g_level_unexpected >= g_current_runtime_level ) THEN
3633       FND_LOG.STRING(g_level_unexpected,
3634                      'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.pop_cc_def_option_hier',
3635                       sqlcode || ': ' || SUBSTR(SQLERRM, 1, 80));
3636     END IF;
3637 END pop_cc_def_option_hier;
3638 
3639 -- Bug#5066122- new procedure
3640 -----------------------------------------------------------------------
3641 --  PRIVATE PROCEDURE
3642 --  validate_tax_classif_code
3643 --
3644 --  DESCRIPTION
3645 --
3646 --  This procedure  checks if the tax classification code is
3647 --  still valid
3648 --
3649 
3650 PROCEDURE validate_tax_classif_code(
3651               p_tax_classification_code   IN  VARCHAR2,
3652               p_count                     OUT NOCOPY NUMBER)
3653 IS
3654 
3655   CURSOR chk_tax_classification_code
3656     (c_tax_classification_code    VARCHAR2)
3657   IS
3658   SELECT  count(1)
3659     FROM  fnd_lookups
3660     WHERE lookup_code = c_tax_classification_code
3661       AND lookup_type = 'ZX_INPUT_CLASSIFICATIONS'
3662       AND nvl(enabled_flag,'Y') = 'Y';
3663 
3664 BEGIN
3665 
3666   IF (g_level_statement >= g_current_runtime_level ) THEN
3667     FND_LOG.STRING(g_level_statement,
3668                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.validate_tax_classif_code.BEGIN',
3669                    'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: validate_tax_classif_code(+)');
3670 
3671     FND_LOG.STRING(g_level_statement,
3672                     'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.validate_tax_classif_code',
3673                     'p_tax_classification_code  =='
3674                      ||p_tax_classification_code);
3675 
3676   END IF;
3677 
3678   OPEN  chk_tax_classification_code(p_tax_classification_code);
3679   FETCH chk_tax_classification_code INTO p_count;
3680   CLOSE chk_tax_classification_code;
3681 
3682   IF (g_level_statement >= g_current_runtime_level ) THEN
3683     FND_LOG.STRING(g_level_statement,
3684                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.validate_tax_classif_code',
3685                    'p_count  == >'||to_char(p_count));
3686     FND_LOG.STRING(g_level_statement,
3687                    'ZX.PLSQL.ZX_AP_TAX_CLASSIFICATN_DEF_PKG.validate_tax_classif_code.END',
3688                     'ZX_AP_TAX_CLASSIFICATN_DEF_PKG: validate_tax_classif_code(-)');
3689   END IF;
3690 
3691 END validate_tax_classif_code;
3692 
3693 -------------------------------------------------------------------------------
3694 --
3695 --   get_system_tax_defaults
3696 --
3697 -------------------------------------------------------------------------------
3698 
3699 BEGIN
3700 
3701   curr_calling_sequence := 'ZX_AP_TAX_CLASSIFICATN_DEF_PKG.';
3702   Initialize;
3703 
3704 END ZX_AP_TAX_CLASSIFICATN_DEF_PKG;