DBA Data[Home] [Help]

PACKAGE BODY: APPS.OZF_CLAIM_TAX_PVT

Source


1 PACKAGE BODY OZF_CLAIM_TAX_PVT AS
2 /* $Header: ozfvtaxb.pls 120.10 2006/05/02 00:40:49 sshivali ship $ */
3 
4 G_PKG_NAME	     CONSTANT VARCHAR2(30) := 'OZF_CLAIM_TAX_PVT';
5 G_FILE_NAME	     CONSTANT VARCHAR2(12) := 'ozfvtaxb.pls';
6 
7 OZF_DEBUG_HIGH_ON    CONSTANT BOOLEAN	   := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_high);
8 OZF_DEBUG_LOW_ON     CONSTANT BOOLEAN	   := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_low);
9 
10 /*=======================================================================*
11  | PROCEDURE
12  |   Validate_Claim_For_Tax
13  |
14  | NOTES
15  |    This API default claim line recored against different settlement method.
16  |
17  | HISTORY
18  *=======================================================================*/
19 PROCEDURE Validate_Claim_For_Tax(
20     p_api_version	    IN	NUMBER
21    ,p_init_msg_list	    IN	VARCHAR2 := FND_API.g_false
22    ,p_validation_level	    IN	NUMBER	 := FND_API.g_valid_level_full
23 
24    ,x_return_status	  OUT NOCOPY VARCHAR2
25    ,x_msg_data		  OUT NOCOPY VARCHAR2
26    ,x_msg_count		  OUT NOCOPY NUMBER
27 
28    ,p_claim_rec		   IN  OZF_CLAIM_PVT.claim_rec_type
29 )  IS
30 l_api_version	       CONSTANT	NUMBER	     :=	1.0;
31 l_api_name	       CONSTANT	VARCHAR2(30) :=	'Validate_Claim_For_Tax';
32 l_full_name	       CONSTANT	VARCHAR2(60) :=	g_pkg_name ||'.'|| l_api_name;
33 
34 BEGIN
35    IF OZF_DEBUG_HIGH_ON	THEN
36       OZF_Utility_PVT.debug_message(l_full_name||' : start');
37    END IF;
38 
39    -- Initialize API return status to sucess
40    x_return_status := FND_API.g_ret_sts_success;
41 
42    --  Do Header Level Validation
43    IF p_claim_rec.payment_method  IN ( 'EFT','WIRE','CHECK','AP_DEBIT',	'AP_DEFAULT')  AND
44        p_claim_rec.vendor_id IS	NULL AND p_claim_rec.vendor_site_id IS NULL THEN
45 	   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
46 	      FND_MESSAGE.set_name('OZF', 'OZF_VENDOR_INFO_MISSING');
47 	      FND_MSG_PUB.add;
48 	   END IF;
49 	   RAISE FND_API.g_exc_error;
50    END IF;
51 
52    IF OZF_DEBUG_HIGH_ON	THEN
53       OZF_Utility_PVT.debug_message(l_full_name||' : end');
54    END IF;
55 
56 EXCEPTION
57    WHEN	FND_API.G_EXC_ERROR THEN
58       x_return_status := FND_API.G_RET_STS_ERROR;
59    WHEN	FND_API.G_EXC_UNEXPECTED_ERROR THEN
60       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
61    WHEN	OTHERS THEN
62      x_return_status :=	FND_API.g_ret_sts_unexp_error;
63      IF	FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
64 	 FND_MSG_PUB.add_exc_msg(g_pkg_name, l_api_name);
65      END IF;
66 
67 END Validate_Claim_For_Tax;
68 
69 
70 
71 /*=======================================================================*
72  | PROCEDURE
73  |    Calculate_Claim_Line_Tax
74  |
75  | NOTES
76  |    This API default claim line recored against different settlement method.
77  |
78  | HISTORY
79  |    14-NOV-2002  mchang  Create.
80  *=======================================================================*/
81 PROCEDURE Calculate_Claim_Line_Tax(
82     p_api_version	    IN	NUMBER
83    ,p_init_msg_list	    IN	VARCHAR2 := FND_API.g_false
84    ,p_validation_level	    IN	NUMBER	 := FND_API.g_valid_level_full
85 
86    ,x_return_status	    OUT	NOCOPY VARCHAR2
87    ,x_msg_data		    OUT	NOCOPY VARCHAR2
88    ,x_msg_count		    OUT	NOCOPY NUMBER
89 
90    ,p_x_claim_line_rec	    IN OUT NOCOPY OZF_CLAIM_LINE_PVT.claim_line_rec_type
91 )
92 IS
93 l_api_version	       CONSTANT	NUMBER	     :=	1.0;
94 l_api_name	       CONSTANT	VARCHAR2(30) :=	'Calculate_Claim_Line_Tax';
95 l_full_name	       CONSTANT	VARCHAR2(60) :=	g_pkg_name ||'.'|| l_api_name;
96 l_return_status			VARCHAR2(1);
97 ---
98 
99 CURSOR csr_claim(cv_claim_id IN	NUMBER)	IS
100   SELECT
101 	 oc.set_of_books_id
102   ,	 oc.claim_class
103   ,	 oc.currency_code
104   ,	 fc.precision
105   ,	 oc.payment_method
106   ,	 oc.exchange_rate_type
107   ,	 oc.exchange_rate_date
108   ,	 oc.exchange_rate
109   ,	 oc.org_id
110   FROM ozf_claims oc
111   ,    fnd_currencies fc
112   WHERE	oc.currency_code = fc.currency_code
113   AND	  oc.claim_id	   = cv_claim_id;
114 l_claim_header	     OZF_CLAIM_PVT.claim_rec_type;
115 
116 CURSOR	csr_stlmnt_tax_type(p_claim_id IN NUMBER) IS
117  SELECT	 tax_for
118    FROM	  ozf_claim_sttlmnt_methods_all	 ssm
119 	     , ozf_claims_all oc
120 WHERE	ssm.settlement_method =	oc.payment_method
121     AND	   ssm.claim_class = oc.claim_class
122     AND	   NVL(ssm.source_object_class,	'_NULL_') = NVL(oc.source_object_class,	'_NULL_')
123     AND	   ssm.org_id =	oc.org_id
124     AND	   oc.claim_id	= p_claim_id;
125 l_tax_type   VARCHAR2(30);
126 
127 -- fix for bug 5042046
128 CURSOR csr_function_currency IS
129   SELECT  gs.currency_code
130   FROM	   gl_sets_of_books gs
131   ,		ozf_sys_parameters org
132   WHERE	 org.set_of_books_id = gs.set_of_books_id
133   AND	 org.org_id = MO_GLOBAL.GET_CURRENT_ORG_ID();
134 
135 l_function_currency    VARCHAR2(15);
136 
137 CURSOR	 csr_curr_details(p_curr_code IN VARCHAR2)  IS
138   SELECT  minimum_accountable_unit,
139 		precision
140     FROM  fnd_currencies
141   WHERE	currency_code =	p_curr_code
142       AND  NVL(enabled_flag,'N') = 'Y';
143 
144 CURSOR	  csr_cm_dm_trx_id(p_claim_type_id IN NUMBER) IS
145    SELECT  cm_trx_type_id,
146 		 dm_trx_type_id
147       FROM  ozf_claim_types_all_b
148     WHERE  claim_type_id = p_claim_type_id;
149  l_cm_trx_type_id   NUMBER;
150  l_dm_trx_type_id   NUMBER;
151 
152 
153  CURSOR	 csr_cust_party_details(p_cust_acct_site_use_id	IN NUMBER) IS
154     SELECT  party_site.party_site_id,
155 		  party_site.location_id
156       FROM   hz_cust_site_uses_all   cust_site_use,
157 		  hz_cust_acct_sites_all  cust_site,
158 		  hz_party_sites	  party_site
159     WHERE  site_use_id = p_cust_acct_site_use_id
160 	AND   cust_site.cust_acct_site_id = cust_site_use.cust_acct_site_id
161 	AND   cust_site.party_site_id	  = party_site.party_site_id;
162 
163 CURSOR	  csr_vendor_site_details(p_vendor_site_id IN NUMBER) IS
164    SELECT  party_site_id,
165 		 location_id
166      FROM   po_vendor_sites
167   WHERE	   vendor_site_id = p_vendor_site_id;
168 
169 CURSOR	csr_ap_ship_to_location	IS
170  SELECT	 ship_to_location_id
171     FROM  ap_supplier_sites_all
172   WHERE	 vendor_site_id	= l_claim_header.vendor_site_id;
173 
174 l_transaction_rec  zx_api_pub.transaction_rec_type;
175 
176 --bug 5138121
177 CURSOR csr_zx_tax_details(p_org_id IN NUMBER, p_application_id IN NUMBER,
178                           p_entity_code IN VARCHAR2, p_event_class_code IN VARCHAR2,
179                           p_claim_id IN	NUMBER, p_claim_line_id IN NUMBER) IS
180  SELECT	 SUM(DECODE(tax_amt_included_flag, 'Y',0, tax_amt_tax_curr)),
181 	       SUM(DECODE(tax_amt_included_flag, 'Y',0,	tax_amt_funcl_curr))
182    FROM	  zx_detail_tax_lines_gt
183   WHERE	 internal_organization_id = p_org_id
184     AND	 application_id	= p_application_id
185     AND	 entity_code = p_entity_code
186     AND	 event_class_code = p_event_class_code
187     AND	 trx_id	= p_claim_id
188     AND	 trx_line_id = p_claim_line_id;
189 
190 l_tax_amount	      NUMBER;
191 l_tax_acctd_amount    NUMBER;
192 
193 l_return_exc_rate      NUMBER;
194 
195 l_dummy	  VARCHAR2(30);
196 l_calc_tax_rate	 NUMBER;
197 l_calc_incl_tax_amt  NUMBER;
198 BEGIN
199    IF OZF_DEBUG_HIGH_ON	THEN
200       OZF_Utility_PVT.debug_message(l_full_name||' : start');
201    END IF;
202 
203    -- Initialize API return status to sucess
204    x_return_status := FND_API.g_ret_sts_success;
205 
206    ------------------------ start -------------------------
207    OZF_AR_PAYMENT_PVT.Query_Claim(
208 	  p_claim_id	 =>  p_x_claim_line_rec.claim_id
209 	  ,x_claim_rec	 =>  l_claim_header
210 	  ,x_return_status    => l_return_status);
211    IF l_return_status =	FND_API.g_ret_sts_error	THEN
212 	  RAISE	FND_API.g_exc_error;
213    ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
214 	 RAISE FND_API.g_exc_unexpected_error;
215    END IF;
216 
217 
218    --  Step 1: Validate	(Stage 1)---------------------------------------
219    IF l_claim_header.payment_method = 'RMA' THEN
220 	IF p_x_claim_line_rec.item_id IS NULL OR p_x_claim_line_rec.quantity IS	NULL OR
221 		  p_x_claim_line_rec.rate IS NULL
222        THEN
223 	   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
224 	      FND_MESSAGE.set_name('OZF', 'OZF_PROD_QTY_PRICE_MISSING');
225 	      FND_MSG_PUB.add;
226 	   END IF;
227 	   RAISE FND_API.g_exc_error;
228 	END IF;
229    END IF;
230 
231    IF l_claim_header.payment_method = 'REG_CREDIT_MEMO'	THEN
232 	IF p_x_claim_line_rec.source_object_class IS NULL OR p_x_claim_line_rec.source_object_id IS NULL
233 	    AND	p_x_claim_line_rec.source_object_id NOT	IN ( 'INVOICE',	'CB', 'DM' ) THEN
234 		 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
235 		      FND_MESSAGE.set_name('OZF', 'OZF_INV_INFO_MISSING');
236 		      FND_MSG_PUB.add;
237 		 END IF;
238 		 RAISE FND_API.g_exc_error;
239 	 END IF;
240 	IF p_x_claim_line_rec. credit_to IS NOT	NULL OR	p_x_claim_line_rec. source_object_line_id IS NULL THEN
241 		 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
242 		      FND_MESSAGE.set_name('OZF', 'OZF_REGCM_TAXCALC_ERR');
243 		      FND_MSG_PUB.add;
244 		 END IF;
245 		 RAISE FND_API.g_exc_error;
246 	END IF;
247   END IF;
248 
249  -- Step2: Init	and Populate the global	stucture
250    IF OZF_DEBUG_HIGH_ON	THEN
251       OZF_Utility_PVT.debug_message(l_full_name||' : Populating	the Global Structure');
252    END IF;
253 
254    zx_global_structures_pkg.init_trx_line_dist_tbl(1);
255 
256     -- Populate	the common values in the structure
257     zx_global_structures_pkg.trx_line_dist_tbl.internal_organization_id(1) := l_claim_header.org_id;
258     zx_global_structures_pkg.trx_line_dist_tbl.trx_id(1)		   := l_claim_header.claim_id;
259     zx_global_structures_pkg.trx_line_dist_tbl.trx_date(1)		 := NVL(l_claim_header.effective_date, SYSDATE);
260     zx_global_structures_pkg.trx_line_dist_tbl.trx_line_date(1)	       := NVL(l_claim_header.effective_date, SYSDATE);
261     zx_global_structures_pkg.trx_line_dist_tbl.ledger_id(1)		  := l_claim_header.set_of_books_id;
262     zx_global_structures_pkg.trx_line_dist_tbl.trx_currency_code(1)  :=	 l_claim_header.currency_code;
263     zx_global_structures_pkg.trx_line_dist_tbl.legal_entity_id(1)	  :=  l_claim_header.legal_entity_id;
264     zx_global_structures_pkg.trx_line_dist_tbl.trx_level_type(1)	  := 'LINE';
265     zx_global_structures_pkg.trx_line_dist_tbl.line_level_action(1)	  := 'CREATE';
266     zx_global_structures_pkg.trx_line_dist_tbl.quote_flag(1)		    := 'Y';
267 
268     OPEN    csr_curr_details(l_claim_header.currency_code);
269     FETCH  csr_curr_details  INTO zx_global_structures_pkg.trx_line_dist_tbl.minimum_accountable_unit(1)
270 						    , zx_global_structures_pkg.trx_line_dist_tbl.precision(1);
271     CLOSE  csr_curr_details;
272 
273    zx_global_structures_pkg.trx_line_dist_tbl.line_amt_includes_tax_flag(1) := 'N';
274 
275 
276   OPEN	    csr_stlmnt_tax_type(l_claim_header.claim_id);
277   FETCH	   csr_stlmnt_tax_type	INTO l_tax_type;
278   CLOSE	   csr_stlmnt_tax_type;
279 
280   IF  l_tax_type = 'AP'	THEN
281 
282       zx_global_structures_pkg.trx_line_dist_tbl.application_id(1)		       := 200;
283       zx_global_structures_pkg.trx_line_dist_tbl.entity_code(1)				:= 'AP_INVOICES';
284       zx_global_structures_pkg.trx_line_dist_tbl.event_class_code(1)		    := 'STANDARD INVOICES';
285       zx_global_structures_pkg.trx_line_dist_tbl.source_application_id(1)	   := 682;
286       zx_global_structures_pkg.trx_line_dist_tbl.source_entity_code(1)		   := 'OZF_CLAIMS';
287       zx_global_structures_pkg.trx_line_dist_tbl.source_event_class_code(1)    := 'TRADE_MGT_PAYABLES';
288       zx_global_structures_pkg.trx_line_dist_tbl.event_type_code(1)		    := 'STANDARD CREATED';
289 
290 	-- Ship	From Information. Bill From Info not Required
291 	OPEN	csr_vendor_site_details(l_claim_header.vendor_site_id);
292 	FETCH  csr_vendor_site_details	INTO  zx_global_structures_pkg.trx_line_dist_tbl.ship_from_party_site_id(1),
293 								      zx_global_structures_pkg.trx_line_dist_tbl.ship_from_location_id(1);
294 	CLOSE  csr_vendor_site_details;
295 
296 	-- Bill	To Information?
297 	-- zx_global_structures_pkg.trx_line_dist_tbl.bill_to_location_id(1)	:=  ??
298 
299        -- Ship To Information
300        OPEN csr_ap_ship_to_location;
301        FETCH csr_ap_ship_to_location INTO zx_global_structures_pkg.trx_line_dist_tbl.ship_to_location_id(1);
302        CLOSE csr_ap_ship_to_location;
303 
304    ELSE
305 
306       zx_global_structures_pkg.trx_line_dist_tbl.application_id(1)	     :=	222;
307       zx_global_structures_pkg.trx_line_dist_tbl.entity_code(1)		     :=	'TRANSACTIONS';
308 
309       IF  l_claim_header.payment_method = 'RMA' THEN
310 	 zx_global_structures_pkg.trx_line_dist_tbl.event_class_code(1)	 := 'SALES_TRANSACTION_TAX_QUOTE';
311 	 zx_global_structures_pkg.trx_line_dist_tbl.event_type_code(1)	 := 'CREATE';
312 
313       ELSIF l_claim_header.payment_method = 'REG_CREDIT_MEMO' THEN
314 	 zx_global_structures_pkg.trx_line_dist_tbl.event_class_code(1)	 := 'CREDIT_MEMO';
315 	 zx_global_structures_pkg.trx_line_dist_tbl.event_type_code(1)	 := 'CM_CREATE';
316 
317       ELSE
318 	IF l_claim_header.payment_method =	'CREDIT_MEMO' THEN
319 	     zx_global_structures_pkg.trx_line_dist_tbl.event_class_code(1)  :=	'CREDIT_MEMO';
320 	     zx_global_structures_pkg.trx_line_dist_tbl.event_type_code(1)   :=	'CM_CREATE';
321 	 ELSIF l_claim_header.payment_method = 'DEBIT_MEMO' THEN
322 	     zx_global_structures_pkg.trx_line_dist_tbl.event_class_code(1)  :=	'DEBIT_MEMO';
323 	     zx_global_structures_pkg.trx_line_dist_tbl.event_type_code(1)   :=	'DM_CREATE';
324 	 END IF;
325 
326 	 zx_global_structures_pkg.trx_line_dist_tbl.source_application_id(1)	       := 682;
327 	 zx_global_structures_pkg.trx_line_dist_tbl.source_entity_code(1)	       := 'OZF_CLAIMS';
328 	 zx_global_structures_pkg.trx_line_dist_tbl.source_event_class_code(1)	:= 'TRADE_MGT_RECEIVABLES';
329 
330       END IF;
331 
332       --  Ship From Information	? Bill From Info not required.
333       --   zx_global_structures_pkg.trx_line_dist_tbl.ship_from_party_id(1) :=	??;
334       --  zx_global_structures_pkg.trx_line_dist_tbl.ship_from_location_id(1)	 := ??
335       --  zx_global_structures_pkg.trx_line_dist_tbl.bill_from_party_id(1) :=  ??;
336       --  zx_global_structures_pkg.trx_line_dist_tbl.bill_from_location_id(1)	 := ??
337 
338 
339        -- Bill To Information
340       zx_global_structures_pkg.trx_line_dist_tbl.bill_to_cust_acct_site_use_id(1) := NVL(l_claim_header.related_site_use_id,  l_claim_header.cust_billto_acct_site_id);
341       OPEN    csr_cust_party_details(zx_global_structures_pkg.trx_line_dist_tbl.bill_to_cust_acct_site_use_id(1));
342       FETCH  csr_cust_party_details INTO zx_global_structures_pkg.trx_line_dist_tbl.bill_to_party_site_id(1),
343 								   zx_global_structures_pkg.trx_line_dist_tbl.bill_to_location_id(1);
344        CLOSE  csr_cust_party_details ;
345 
346 	-- Ship	To Information
347 	IF l_claim_header.cust_shipto_acct_site_id IS NOT NULL THEN
348 	       zx_global_structures_pkg.trx_line_dist_tbl.ship_to_cust_acct_site_use_id(1) := l_claim_header.cust_shipto_acct_site_id;
349 	       OPEN    csr_cust_party_details(l_claim_header.cust_shipto_acct_site_id);
350 	       FETCH  csr_cust_party_details INTO zx_global_structures_pkg.trx_line_dist_tbl.ship_to_party_site_id(1),
351 									  zx_global_structures_pkg.trx_line_dist_tbl.ship_to_location_id(1);
352 	       CLOSE  csr_cust_party_details ;
353 	END IF;
354 
355   END IF;
356 
357   IF l_claim_header.payment_method  IN ( 'CREDIT_MEMO',	'DEBIT_MEMO') THEN
358       OPEN    csr_cm_dm_trx_id(l_claim_header.claim_type_id);
359       FETCH  csr_cm_dm_trx_id  INTO l_cm_trx_type_id, l_dm_trx_type_id;
360       CLOSE  csr_cm_dm_trx_id;
361 
362       IF l_claim_header.payment_method	=  'CREDIT_MEMO' THEN
363 	    zx_global_structures_pkg.trx_line_dist_tbl.receivables_trx_type_id(1) := l_cm_trx_type_id;
364       ELSE
365 	    zx_global_structures_pkg.trx_line_dist_tbl.receivables_trx_type_id(1) :=  l_dm_trx_type_id;
366       END IF;
367    END IF;
368 
369    OPEN    csr_function_currency;
370    FETCH csr_function_currency INTO l_function_currency;
371    CLOSE csr_function_currency;
372 
373    IF l_claim_header.currency_code <> l_function_currency THEN
374       zx_global_structures_pkg.trx_line_dist_tbl.currency_conversion_date(1) :=	l_claim_header.exchange_rate_date;
375       zx_global_structures_pkg.trx_line_dist_tbl.currency_conversion_rate(1) :=	l_claim_header.exchange_rate;
376       zx_global_structures_pkg.trx_line_dist_tbl.currency_conversion_type(1) :=	l_claim_header.exchange_rate_type;
377    END IF;
378 
379 
380  zx_global_structures_pkg.trx_line_dist_tbl.input_tax_classification_code(1)   := NULL;
381  zx_global_structures_pkg.trx_line_dist_tbl.output_tax_classification_code(1)  := NULL;
382  zx_global_structures_pkg.trx_line_dist_tbl.product_id(1)		       := NULL;
383  zx_global_structures_pkg.trx_line_dist_tbl.uom_code(1)			       := NULL;
384  zx_global_structures_pkg.trx_line_dist_tbl.product_type(1)		       := NULL;
385  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_application_id(1)     := NULL;
386  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_entity_code(1)	       := NULL;
387  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_event_class_code(1)   := NULL;
388  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_trx_id(1)	       := NULL;
389  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_trx_level_type(1)     := NULL;
390  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_line_id(1)	       := NULL;
391  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_number(1)	       := NULL;
392  zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_date(1)	       := NULL;
393 
394  zx_global_structures_pkg.trx_line_dist_tbl.trx_line_id(1)     := p_x_claim_line_rec.claim_line_id;
395 
396   OPEN	    csr_stlmnt_tax_type(p_x_claim_line_rec.claim_id);
397   FETCH	   csr_stlmnt_tax_type	INTO l_tax_type;
398   CLOSE	   csr_stlmnt_tax_type;
399 
400   -- Switch Signs
401   IF  l_tax_type = 'AP'	THEN
402     zx_global_structures_pkg.trx_line_dist_tbl.input_tax_classification_code(1)
403 				      := p_x_claim_line_rec.tax_code;
404    IF l_claim_header.payment_method = 'AP_DEBIT'  AND  l_claim_header.claim_class = 'CLAIM' THEN
405        zx_global_structures_pkg.trx_line_dist_tbl.line_amt(1)  := p_x_claim_line_rec.amount * -1 ;
406    ELSE
407        zx_global_structures_pkg.trx_line_dist_tbl.line_amt(1)  := p_x_claim_line_rec.amount ;
408    END IF;
409 
410  ELSE
411    zx_global_structures_pkg.trx_line_dist_tbl.output_tax_classification_code(1)
412 				       := p_x_claim_line_rec.tax_code;
413    zx_global_structures_pkg.trx_line_dist_tbl.line_amt(1)  := p_x_claim_line_rec.amount	* -1 ;
414 
415  END IF;
416 
417 
418  IF  l_tax_type	= 'AR'	AND  p_x_claim_line_rec.item_id	IS NOT NULL THEN
419        IF p_x_claim_line_rec. item_type	= 'PRODUCT' THEN
420 		 zx_global_structures_pkg.trx_line_dist_tbl.product_id(1)    :=	p_x_claim_line_rec.item_id;
421 		 zx_global_structures_pkg.trx_line_dist_tbl.uom_code(1)	     :=	p_x_claim_line_rec.quantity_uom;
422 		 --bug5193067
423 		 --zx_global_structures_pkg.trx_line_dist_tbl.product_type(1)  :=	'GOOD';
424        ELSIF p_x_claim_line_rec. item_type = 'MEMO_LINE' THEN
425 		 zx_global_structures_pkg.trx_line_dist_tbl.product_id(1)    :=	p_x_claim_line_rec.item_id;
426 		 zx_global_structures_pkg.trx_line_dist_tbl.uom_code(1)	     :=	p_x_claim_line_rec.quantity_uom;
427 		 --bug5193067
428 		 --zx_global_structures_pkg.trx_line_dist_tbl.product_type(1)  :=	'MEMO';
429        END IF;
430  END IF;
431 
432  IF  l_claim_header.payment_method IN ('REG_CREDIT_MEMO','RMA')	AND
433       p_x_claim_line_rec.source_object_id IS NOT NULL
434  THEN
435        IF  p_x_claim_line_rec.source_object_class = 'ORDER' THEN
436 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_application_id(1)     := 660;
437 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_entity_code(1)	       := 'OE_ORDER_HEADERS_ALL';
438 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_event_class_code(1)   := 'SALES_TRANSACTION_TAX_QUOTE';
439 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_trx_id(1)	       := p_x_claim_line_rec.source_object_id;
440 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_line_id(1)	       := p_x_claim_line_rec.source_object_line_id;
441 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_trx_level_type(1) := 'LINE';
442      ELSE
443 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_application_id(1)     := 222;
444 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_entity_code(1)	       :=  'TRANSACTIONS';
445 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_event_class_code(1)   := 'INVOICE';
446 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_trx_id(1)	       := p_x_claim_line_rec.source_object_id;
447 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_line_id(1)	       := p_x_claim_line_rec.source_object_line_id;
448 		 zx_global_structures_pkg.trx_line_dist_tbl.adjusted_doc_trx_level_type(1) := 'LINE';
449      END IF;
450 END IF;
451 
452  -- Step 3: Make Call to Calculate Tax
453    IF OZF_DEBUG_HIGH_ON	THEN
454       OZF_Utility_PVT.debug_message(l_full_name||' : Calling the tax engine');
455    END IF;
456 
457  l_transaction_rec.internal_organization_id := zx_global_structures_pkg.trx_line_dist_tbl.internal_organization_id(1);
458  l_transaction_rec.application_id	    := zx_global_structures_pkg.trx_line_dist_tbl.application_id(1);
459  l_transaction_rec.entity_code		    := zx_global_structures_pkg.trx_line_dist_tbl.entity_code(1);
460  l_transaction_rec.event_class_code	    := zx_global_structures_pkg.trx_line_dist_tbl.event_class_code(1);
461  l_transaction_rec.event_type_code	    := zx_global_structures_pkg.trx_line_dist_tbl.event_type_code(1);
462  l_transaction_rec.trx_id		    := zx_global_structures_pkg.trx_line_dist_tbl.trx_id(1);
463 
464 
465  ZX_API_PUB.calculate_tax(  p_api_version    =>	 1.0,
466 			    p_init_msg_list  =>	 p_init_msg_list,
467 			    p_commit	     =>	  FND_API.g_false,
468 			    p_validation_level	=> p_validation_level,
469 			    x_return_status	=> l_return_status,
470 			    x_msg_count		=> x_msg_count,
471 			    x_msg_data		=> x_msg_data,
472 			    p_transaction_rec	=>  l_transaction_rec,
473 			    p_quote_flag	=>  'Y',
474 			    p_data_transfer_mode     =>	 'PLS',
475 			    x_doc_level_recalc_flag  =>	l_dummy
476 					   );
477    IF l_return_status =	FND_API.g_ret_sts_error	THEN
478       RAISE FND_API.g_exc_error;
479    ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
480       RAISE FND_API.g_exc_unexpected_error;
481    END IF;
482 
483   -- Step 4:  Retrieve Data from eTax
484   OPEN	 csr_zx_tax_details(l_claim_header.org_id, l_transaction_rec.application_id,
485                             l_transaction_rec.entity_code, l_transaction_rec.event_class_code,
486                             p_x_claim_line_rec.claim_id,  p_x_claim_line_rec.claim_line_id);
487   FETCH	 csr_zx_tax_details  INTO l_tax_amount,	l_tax_acctd_amount;
488   CLOSE	 csr_zx_tax_details;
489 
490     IF OZF_DEBUG_HIGH_ON THEN
491       OZF_Utility_PVT.debug_message(l_full_name||' : Retrieving	Tax Details');
492       ozf_utility_pvt.debug_message('tax Amount' || l_tax_amount);
493    END IF;
494 
495 
496    -- Step 5: Populate into Claim Line Rec
497    -- Switch Signs Again
498   l_tax_amount := NVL(l_tax_amount,0);
499   l_tax_acctd_amount :=	NVL(l_tax_acctd_amount,0);
500   IF  l_tax_type = 'AP'	THEN
501    IF l_claim_header.payment_method = 'AP_DEBIT'  AND  l_claim_header.claim_class = 'CLAIM' THEN
502        l_tax_amount := l_tax_amount  * -1 ;
503        l_tax_acctd_amount := l_tax_acctd_amount	 * -1 ;
504    ELSE
505 	NULL;
506    END IF;
507 
508  ELSE
509        l_tax_amount := l_tax_amount  * -1 ;
510        l_tax_acctd_amount := l_tax_acctd_amount	 * -1 ;
511  END IF;
512 
513 
514    p_x_claim_line_rec.claim_curr_tax_amount := l_tax_amount ;
515    p_x_claim_line_rec.acctd_tax_amount := l_tax_acctd_amount ;
516 
517    IF	p_x_claim_line_rec.tax_action =	'TAX_ADJ_LINE' AND l_tax_amount	<> 0  THEN
518 
519       -- Calculate the approx tax rate for inclusive tax calculation
520       l_calc_tax_rate :=  ROUND( p_x_claim_line_rec.claim_curr_tax_amount / p_x_claim_line_rec.claim_currency_amount, 2);
521       l_calc_incl_tax_amt  :=	(p_x_claim_line_rec.claim_currency_amount * l_calc_tax_rate) / ( 1 + l_calc_tax_rate);
522 
523       p_x_claim_line_rec.claim_curr_tax_amount := OZF_UTILITY_PVT.CurrRound(l_calc_incl_tax_amt,  l_claim_header.currency_code);
524       p_x_claim_line_rec.claim_currency_amount	:=  p_x_claim_line_rec.claim_currency_amount  -	p_x_claim_line_rec.claim_curr_tax_amount;
525 
526       -- Convert ACCTD_AMOUNT
527       OZF_UTILITY_PVT.Convert_Currency(
528 	   P_SET_OF_BOOKS_ID  => l_claim_header.set_of_books_id,
529 	   P_FROM_CURRENCY    => l_claim_header.currency_code,
530 	   P_CONVERSION_DATE  => l_claim_header.exchange_rate_date,
531 	   P_CONVERSION_TYPE  => l_claim_header.exchange_rate_type,
532 	   P_CONVERSION_RATE  => l_claim_header.exchange_rate,
533 	   P_AMOUNT	      => p_x_claim_line_rec.claim_currency_amount,
534 	   X_RETURN_STATUS    => l_return_status,
535 	   X_ACC_AMOUNT	      => p_x_claim_line_rec.acctd_amount,
536 	   X_RATE	      => l_return_exc_rate
537 	    );
538 	IF l_return_status = FND_API.g_ret_sts_error THEN
539 	      RAISE FND_API.g_exc_error;
540 	ELSIF l_return_status =	FND_API.g_ret_sts_unexp_error THEN
541 	      RAISE FND_API.g_exc_unexpected_error;
542 	END IF;
543 
544       OZF_UTILITY_PVT.Convert_Currency(
545 	   P_SET_OF_BOOKS_ID  => l_claim_header.set_of_books_id,
546 	   P_FROM_CURRENCY    => l_claim_header.currency_code,
547 	   P_CONVERSION_DATE  => l_claim_header.exchange_rate_date,
548 	   P_CONVERSION_TYPE  => l_claim_header.exchange_rate_type,
549 	   P_CONVERSION_RATE  => l_claim_header.exchange_rate,
550 	   P_AMOUNT	      =>  p_x_claim_line_rec.claim_curr_tax_amount,
551 	   X_RETURN_STATUS    => l_return_status,
552 	   X_ACC_AMOUNT	      => p_x_claim_line_rec.acctd_tax_amount,
553 	   X_RATE	      => l_return_exc_rate
554 	    );
555 	IF l_return_status = FND_API.g_ret_sts_error THEN
556 	      RAISE FND_API.g_exc_error;
557 	ELSIF l_return_status =	FND_API.g_ret_sts_unexp_error THEN
558 	      RAISE FND_API.g_exc_unexpected_error;
559 	END IF;
560 
561    END IF;
562 
563 
564    IF l_claim_header.currency_code = p_x_claim_line_rec.currency_code
565    THEN
566 
567       p_x_claim_line_rec.tax_amount := p_x_claim_line_rec.claim_curr_tax_amount;
568 
569      IF	p_x_claim_line_rec.tax_action =	'TAX_ADJ_LINE'	THEN
570        p_x_claim_line_rec.amount := p_x_claim_line_rec.claim_currency_amount;
571      END IF;
572 
573    ELSE
574 
575       -- Convert Acctd Tax Amount into Line Currency Tax Amount
576       OZF_UTILITY_PVT.Convert_Currency(
577 	 p_from_currency  => l_function_currency
578 	,p_to_currency	  => p_x_claim_line_rec.currency_code
579 	,p_conv_type	  => p_x_claim_line_rec.exchange_rate_type
580 	,p_conv_rate	  => p_x_claim_line_rec.exchange_rate
581 	,p_conv_date	  => p_x_claim_line_rec.exchange_rate_date
582 	,p_from_amount	  => p_x_claim_line_rec.acctd_tax_amount
583 	,x_return_status  => l_return_status
584 	,x_to_amount	  => p_x_claim_line_rec.tax_amount
585 	,x_rate		  => l_return_exc_rate
586 	);
587       IF l_return_status = FND_API.g_ret_sts_error THEN
588 	  RAISE	FND_API.g_exc_error;
589       ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
590 	  RAISE	FND_API.g_exc_unexpected_error;
591       END IF;
592 
593      --	Convert	Acctd Amount into Line Currency	Amount
594      IF	p_x_claim_line_rec.tax_action =	'TAX_ADJ_LINE'	 THEN
595 	      OZF_UTILITY_PVT.Convert_Currency(
596 		 p_from_currency   => l_function_currency
597 		,p_to_currency	   => p_x_claim_line_rec.currency_code
598 		,p_conv_type	   => p_x_claim_line_rec.exchange_rate_type
599 		,p_conv_rate	   => p_x_claim_line_rec.exchange_rate
600 		,p_conv_date	   => p_x_claim_line_rec.exchange_rate_date
601 		,p_from_amount	   => p_x_claim_line_rec.acctd_amount
602 		,x_return_status   => l_return_status
603 		,x_to_amount	   => p_x_claim_line_rec.amount
604 		,x_rate		   => l_return_exc_rate
605 		);
606 	      IF l_return_status = FND_API.g_ret_sts_error THEN
607 		  RAISE	FND_API.g_exc_error;
608 	      ELSIF l_return_status = FND_API.g_ret_sts_unexp_error THEN
609 		  RAISE	FND_API.g_exc_unexpected_error;
610 	      END IF;
611       END IF;
612 
613    END IF;
614 
615   -- Step 6:  Validate (Stage 2)
616   IF p_x_claim_line_rec.tax_action = 'TAX_ADJ_LINE' AND	l_tax_amount <>	0 THEN
617 	IF p_x_claim_line_rec.earnings_associated_flag = 'T'  OR
618 	    (  p_x_claim_line_rec.quantity IS NOT NULL AND  p_x_claim_line_rec.rate IS NOT NULL)
619        THEN
620 	   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
621 	      FND_MESSAGE.set_name('OZF', 'OZF_ADJLINE_ERR');
622 	      FND_MESSAGE.set_token('LINE_AMOUNT' , p_x_claim_line_rec.claim_currency_amount );
623 	      FND_MSG_PUB.add;
624 	   END IF;
625 	   RAISE FND_API.g_exc_error;
626 	END IF;
627    END IF;
628 
629    ------------------------ finish ------------------------
630 
631    IF OZF_DEBUG_HIGH_ON	THEN
632       OZF_Utility_PVT.debug_message(l_full_name||' : end');
633    END IF;
634 
635 EXCEPTION
636    WHEN	FND_API.G_EXC_ERROR THEN
637       FND_MSG_PUB.count_and_get(
638 	 p_encoded => FND_API.g_false,
639 	 p_count   => x_msg_count,
640 	 p_data	   => x_msg_data
641    );
642       x_return_status := FND_API.G_RET_STS_ERROR;
643    WHEN	FND_API.G_EXC_UNEXPECTED_ERROR THEN
644       FND_MSG_PUB.count_and_get(
645 	 p_encoded => FND_API.g_false,
646 	 p_count   => x_msg_count,
647 	 p_data	   => x_msg_data
648    );
649       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
650    WHEN	OTHERS THEN
651        IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_unexp_error) THEN
652 	 FND_MSG_PUB.add_exc_msg(g_pkg_name, l_api_name);
653      END IF;
654       FND_MSG_PUB.count_and_get(
655 	 p_encoded => FND_API.g_false,
656 	 p_count   => x_msg_count,
657 	 p_data	   => x_msg_data
658    );
659      x_return_status :=	FND_API.g_ret_sts_unexp_error;
660 
661 
662 END Calculate_Claim_Line_Tax;
663 
664 
665 END OZF_CLAIM_TAX_PVT;